• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

dbusjobprotocol.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 Rob Scheepmaker <r.scheepmaker@student.utwente.nl> *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU General Public License     *
00015  *   along with this program; if not, write to the                         *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00018  ***************************************************************************/
00019 
00020 #include "dbusjob.h"
00021 #include "dbusjobprotocol.h"
00022 
00023 
00024 #include <KConfigGroup>
00025 #include <KIcon>
00026 
00027 #include <plasma/dataenginemanager.h>
00028 #include <plasma/service.h>
00029 
00030 
00031 namespace SystemTray
00032 {
00033 
00034 static const char *engineName = "applicationjobs";
00035 
00036 DBusJobProtocol::DBusJobProtocol(QObject *parent)
00037     : Protocol(parent),
00038       m_engine(0)
00039 {
00040 }
00041 
00042 
00043 DBusJobProtocol::~DBusJobProtocol()
00044 {
00045     if (m_engine) {
00046         Plasma::DataEngineManager::self()->unloadEngine(engineName);
00047     }
00048 }
00049 
00050 
00051 void DBusJobProtocol::init()
00052 {
00053     m_engine = Plasma::DataEngineManager::self()->loadEngine(engineName);
00054 
00055     if (!m_engine->isValid()) {
00056         m_engine = 0;
00057         return;
00058     }
00059 
00060     connect(m_engine, SIGNAL(sourceAdded(const QString&)),
00061             this, SLOT(prepareJob(const QString&)));
00062     connect(m_engine, SIGNAL(sourceRemoved(const QString&)),
00063             this, SLOT(removeJob(const QString&)));
00064 }
00065 
00066 void DBusJobProtocol::prepareJob(const QString &source)
00067 {
00068     m_engine->connectSource(source, this);
00069 }
00070 
00071 
00072 void DBusJobProtocol::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
00073 {
00074     DBusJob *job = m_jobs.value(source, 0);
00075 
00076     if (!job) {
00077         job = new DBusJob(source, this);
00078         m_jobs.insert(source, job);
00079         connect(job, SIGNAL(jobDeleted(const QString&)),
00080                 this, SLOT(removeJob(const QString&)));
00081         connect(job, SIGNAL(suspend(const QString&)),
00082                 this, SLOT(suspend(const QString&)));
00083         connect(job, SIGNAL(resume(const QString&)),
00084                 this, SLOT(resume(const QString&)));
00085         connect(job, SIGNAL(stop(const QString&)),
00086                 this, SLOT(stop(const QString&)));
00087         connect(job, SIGNAL(ready(SystemTray::Job*)),
00088                 this, SIGNAL(jobCreated(SystemTray::Job*)));
00089     }
00090 
00091     job->setApplicationName(data.value("appName").toString());
00092     job->setApplicationIconName(data.value("appIconName").toString());
00093     job->setPercentage(data["percentage"].toUInt());
00094     job->setError(data["error"].toString());
00095     job->setMessage(data["infoMessage"].toString());
00096     job->setSuspendable(data["suspendable"].toBool());
00097     job->setKillable(data["killable"].toBool());
00098     job->setSpeed(data["speed"].toString());
00099 
00100     if (data["state"].toString() == "running") {
00101         job->setState(Job::Running);
00102     } else if (data["state"].toString() == "suspended") {
00103         job->setState(Job::Suspended);
00104     } else {
00105         job->setState(Job::Stopped);
00106     }
00107 
00108     int i = 0;
00109     QList<QPair<QString, QString> > labels;
00110     while (data.contains(QString("label%1").arg(i))) {
00111         QPair<QString, QString> label;
00112         label.first = data[QString("labelName%1").arg(i)].toString();
00113         label.second = data[QString("label%1").arg(i)].toString();
00114         labels << label;
00115         i++;
00116     }
00117     job->setLabels(labels);
00118 
00119     i = 0;
00120     QMap<QString, qlonglong> totalAmounts;
00121     while (data.contains(QString("totalUnit%1").arg(i))) {
00122         QString unit = data[QString("totalUnit%1").arg(i)].toString();
00123         qlonglong amount = data[QString("totalAmount%1").arg(i)].toLongLong();
00124         totalAmounts[unit] = amount;
00125         i++;
00126     }
00127     job->setTotalAmounts(totalAmounts);
00128 
00129     i = 0;
00130     QMap<QString, qlonglong> processedAmounts;
00131     while (data.contains(QString("processedUnit%1").arg(i))) {
00132         QString unit = data[QString("processedUnit%1").arg(i)].toString();
00133         qlonglong amount = data[QString("processedAmount%1").arg(i)].toLongLong();
00134         processedAmounts[unit] = amount;
00135         i++;
00136     }
00137 
00138     job->setProcessedAmounts(processedAmounts);
00139 }
00140 
00141 void DBusJobProtocol::removeJob(const QString &source)
00142 {
00143     if (m_jobs.contains(source)) {
00144         m_jobs[source]->setState(Job::Stopped);
00145         m_jobs.take(source)->destroy();
00146     }
00147 }
00148 
00149 void DBusJobProtocol::suspend(const QString &source)
00150 {
00151     Plasma::Service *service = m_engine->serviceForSource(source);
00152     KConfigGroup op = service->operationDescription("suspend");
00153     service->startOperationCall(op);
00154 }
00155 
00156 void DBusJobProtocol::resume(const QString &source)
00157 {
00158     Plasma::Service *service = m_engine->serviceForSource(source);
00159     KConfigGroup op = service->operationDescription("resume");
00160     service->startOperationCall(op);
00161 }
00162 
00163 void DBusJobProtocol::stop(const QString &source)
00164 {
00165     Plasma::Service *service = m_engine->serviceForSource(source);
00166     KConfigGroup op = service->operationDescription("stop");
00167     service->startOperationCall(op);
00168 }
00169 
00170 }
00171 
00172 #include "dbusjobprotocol.moc"

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal