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

Engines

kuiserverengine.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright © 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 Library General Public License version 2 as
00006  *   published by the Free Software Foundation
00007  *
00008  *   This program is distributed in the hope that it will be useful,
00009  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *   GNU General Public License for more details
00012  *
00013  *   You should have received a copy of the GNU Library General Public
00014  *   License along with this program; if not, write to the
00015  *   Free Software Foundation, Inc.,
00016  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017  */
00018 
00019 #include "jobviewadaptor.h"
00020 #include "jobviewserveradaptor.h"
00021 #include "kuiserverengine.h"
00022 #include "jobcontrol.h"
00023 
00024 #include <QDBusConnection>
00025 
00026 #include <KJob>
00027 
00028 #include <Plasma/DataEngine>
00029 
00030 
00031 uint KuiserverEngine::s_jobId = 0;
00032 
00033 JobView::JobView(QObject* parent)
00034     : QObject(parent),
00035       m_percent(0), m_speed(0), m_state(Running)
00036 {
00037     m_objectPath.setPath(QString("/JobViewServer/JobView_%1").arg(++KuiserverEngine::s_jobId));
00038 
00039     new JobViewAdaptor(this);
00040     QDBusConnection::sessionBus().registerObject(m_objectPath.path(), this);
00041     m_jobId = KuiserverEngine::s_jobId;
00042 }
00043 
00044 void JobView::terminate(const QString &errorMessage)
00045 {
00046     m_error = errorMessage;
00047     m_state = Stopped;
00048     emit viewUpdated(this);
00049 }
00050 
00051 void JobView::setSuspended(bool suspended)
00052 {
00053     if (suspended) {
00054         m_state = Suspended;
00055     } else {
00056         m_state = Running;
00057     }
00058 
00059     emit viewUpdated(this);
00060 }
00061 
00062 void JobView::setTotalAmount(qlonglong amount, const QString &unit)
00063 {
00064     m_totalMap[unit] = amount;
00065     emit viewUpdated(this);
00066 }
00067 
00068 void JobView::setProcessedAmount(qlonglong amount, const QString &unit)
00069 {
00070     m_processedMap[unit] = amount;
00071     emit viewUpdated(this);
00072 }
00073 
00074 void JobView::setPercent(uint percent)
00075 {
00076     m_percent = percent;
00077     emit viewUpdated(this);
00078 }
00079 
00080 void JobView::setSpeed(qlonglong bytesPerSecond)
00081 {
00082     m_speed = bytesPerSecond;
00083     emit viewUpdated(this);
00084 }
00085 
00086 QString JobView::speedString() const
00087 {
00088     //FIXME: how to i18n this?
00089     return QString("%1/s").arg(KGlobal::locale()->formatByteSize(m_speed));
00090 }
00091 
00092 void JobView::setInfoMessage(const QString &infoMessage)
00093 {
00094     m_infoMessage = infoMessage;
00095     emit viewUpdated(this);
00096 }
00097 
00098 bool JobView::setDescriptionField(uint number, const QString &name, const QString &value)
00099 {
00100     m_labels[number] = value;
00101     m_labelNames[number] = name;
00102     emit viewUpdated(this);
00103     return true;
00104 }
00105 
00106 void JobView::clearDescriptionField(uint number)
00107 {
00108     m_labels.remove(number);
00109     m_labelNames.remove(number);
00110 }
00111 
00112 void JobView::setAppName(const QString &appName)
00113 {
00114     m_appName = appName;
00115 }
00116 
00117 void JobView::setAppIconName(const QString &appIconName)
00118 {
00119     m_appIconName = appIconName;
00120 }
00121 
00122 void JobView::setCapabilities(int capabilities)
00123 {
00124     m_capabilities = capabilities;
00125 }
00126 
00127 QString JobView::sourceName() const
00128 {
00129     return QString("Job %1").arg(m_jobId);
00130 }
00131 
00132 QDBusObjectPath JobView::objectPath() const
00133 {
00134     return m_objectPath;
00135 }
00136 
00137 KuiserverEngine::KuiserverEngine(QObject* parent, const QVariantList& args)
00138     : Plasma::DataEngine(parent, args)
00139 {
00140     new JobViewServerAdaptor(this);
00141 
00142     QDBusConnection::sessionBus().registerService(QLatin1String("org.kde.JobViewServer"));
00143     QDBusConnection::sessionBus().registerObject(QLatin1String("/JobViewServer"), this);
00144 
00145     setMinimumPollingInterval(500);
00146 }
00147 
00148 KuiserverEngine::~KuiserverEngine()
00149 {
00150     QDBusConnection::sessionBus().unregisterService("org.kde.JobViewServer");
00151     qDeleteAll(m_jobViews);
00152 }
00153 
00154 QDBusObjectPath KuiserverEngine::requestView(const QString &appName,
00155                                              const QString &appIconName, int capabilities)
00156 {
00157     JobView *jobView = new JobView();
00158     connect(jobView, SIGNAL(viewUpdated(JobView*)),
00159             this, SLOT(sourceUpdated(JobView*)));
00160 
00161     jobView->setAppName(appName);
00162     jobView->setAppIconName(appIconName);
00163     jobView->m_appName = appName;
00164     jobView->m_appIconName = appIconName;
00165     jobView->m_capabilities = capabilities;
00166 
00167     m_jobViews[jobView->sourceName()] = jobView;
00168     return jobView->objectPath();
00169 }
00170 
00171 Plasma::Service* KuiserverEngine::serviceForSource(const QString& source)
00172 {
00173     if (m_jobViews.contains(source)) {
00174         return new JobControl(this, m_jobViews[source]);
00175     } else {
00176         return DataEngine::serviceForSource(source);
00177     }
00178 }
00179 
00180 void KuiserverEngine::init()
00181 {
00182 }
00183 
00184 void KuiserverEngine::sourceUpdated(JobView *jobView)
00185 {
00186     QString sourceName = jobView->sourceName();
00187 
00188     Plasma::DataEngine::Data data;
00189     data["appName"] = jobView->m_appName;
00190     data["appIconName"] = jobView->m_appIconName;
00191     data["percentage"] = jobView->m_percent;
00192     data["suspendable"] = (jobView->m_capabilities & KJob::Suspendable);
00193     data["killable"] = (jobView->m_capabilities & KJob::Killable);
00194     data["infoMessage"] = jobView->m_infoMessage;
00195 
00196     if (!jobView->m_error.isEmpty()) {
00197         data["error"] = jobView->m_error;
00198     }
00199 
00200     if (jobView->m_state == JobView::Running) {
00201         data["speed"] = jobView->speedString();
00202     }
00203 
00204     for (int i = 0; i < jobView->m_labels.count(); i++) {
00205         data[QString("label%1").arg(i)] = jobView->m_labels[i];
00206         data[QString("labelName%1").arg(i)] = jobView->m_labelNames[i];
00207     }
00208 
00209     int i = 0;
00210     foreach (const QString &unit, jobView->m_totalMap.keys()) {
00211         data[QString("totalUnit%1").arg(i)] = unit;
00212         data[QString("totalAmount%1").arg(i++)] = jobView->m_totalMap[unit];
00213     }
00214 
00215     i = 0;
00216     foreach (const QString &unit, jobView->m_processedMap.keys()) {
00217         data[QString("processedUnit%1").arg(i)] = unit;
00218         data[QString("processedAmount%1").arg(i++)] = jobView->m_processedMap[unit];
00219     }
00220 
00221     switch (jobView->m_state) {
00222         case JobView::Running:
00223             data["state"] = "running";
00224             setData(sourceName, data);
00225             break;
00226         case JobView::Suspended:
00227             data["state"] = "suspended";
00228             setData(sourceName, data);
00229             break;
00230         case JobView::Stopped:
00231             data["state"] = "stopped";
00232             setData(sourceName, data);
00233             removeSource(sourceName);
00234             break;
00235     }
00236 
00237 }
00238 
00239 K_EXPORT_PLASMA_DATAENGINE(kuiserver, KuiserverEngine)
00240 
00241 #include "kuiserverengine.moc"
00242 

Engines

Skip menu "Engines"
  • 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