• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • plasma
  • engine
kgetengine.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU Library General Public License version 2 as
4  * published by the Free Software Foundation
5  *
6  * Copyright (C) 2007 by Javier Goday <jgoday@gmail.com>
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details
12  *
13  * You should have received a copy of the GNU Library General Public
14  * License along with this program; if not, write to the
15  * Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include "kgetengine.h"
20 #include "kget_interface.h"
21 
22 #include <QtDBus/QDBusConnectionInterface>
23 #include <KDebug>
24 
25 #include "plasma/datacontainer.h"
26 
27 const quint16 KGetEngine::MINIMUM_UPDATE_INTERVAL = 1000;
28 const QString KGetEngine::KGET_DBUS_SERVICE = "org.kde.kget";
29 const QString KGetEngine::KGET_DBUS_PATH = "/KGet";
30 
31 KGetEngine::KGetEngine(QObject* parent, const QVariantList& args)
32  : Plasma::DataEngine(parent),
33  m_kget(0)
34 {
35  Q_UNUSED(args)
36 
37  interface = QDBusConnection::sessionBus().interface();
38  setMinimumPollingInterval(MINIMUM_UPDATE_INTERVAL);
39 }
40 
41 KGetEngine::~KGetEngine()
42 {
43 }
44 
45 QStringList KGetEngine::sources() const
46 {
47  QStringList sources;
48  sources << "KGet";
49 
50  return sources;
51 }
52 
53 bool KGetEngine::sourceRequestEvent(const QString &name)
54 {
55  return updateSourceEvent(name);
56 }
57 
58 bool KGetEngine::updateSourceEvent(const QString &name)
59 {
60  kDebug();
61  if (name == "KGet") {
62  getKGetData(name);
63  }
64  return true;
65 }
66 
67 void KGetEngine::updateData()
68 {
69  updateSourceEvent("KGet");
70 }
71 
72 void KGetEngine::getKGetData(const QString &name)
73 {
74  removeAllData(name);
75 
76  if (isDBusServiceRegistered()) {
77  if (!m_kget) {
78  m_kget = new OrgKdeKgetMainInterface(KGET_DBUS_SERVICE, KGET_DBUS_PATH, QDBusConnection::sessionBus(), this);
79  connect(m_kget, SIGNAL(transfersAdded(QStringList,QStringList)), this, SLOT(slotTransfersAdded(QStringList,QStringList)));
80  connect(m_kget, SIGNAL(transfersRemoved(QStringList,QStringList)), this, SLOT(slotTransfersRemoved(QStringList,QStringList)));
81  }
82 
83  setData(name, "error", false);
84  setData(name, "transfers", m_kget->transfers().value());
85  } else {
86  setData(name, "error", true);
87  setData(name, "errorMessage", i18n("Is KGet up and running?"));
88  }
89 }
90 
91 void KGetEngine::transferAdded(const QString &url, const QString &dBusObjectPath)
92 {
93  const QString name = "KGet";
94  removeAllData(name);
95 
96  QVariantMap added;
97  added.insert(url, dBusObjectPath);
98 
99  setData(name, "error", false);
100  setData(name, "transfers", m_kget->transfers().value());
101  setData(name, "transferAdded", added);
102 }
103 
104 //TODO investigate if this should be improved for speed reasons
105 void KGetEngine::slotTransfersAdded(const QStringList &urls, const QStringList &dBusObjectPaths)
106 {
107  for (int i = 0; i < urls.count(); ++i) {
108  transferAdded(urls[i], dBusObjectPaths[i]);
109  }
110 }
111 
112 void KGetEngine::transferRemoved(const QString &url, const QString &dBusObjectPath)
113 {
114  const QString name = "KGet";
115  removeAllData(name);
116 
117  QVariantMap removed;
118  removed.insert(url, dBusObjectPath);
119 
120  setData(name, "error", false);
121  setData(name, "transfers", m_kget->transfers().value());
122  setData(name, "transferRemoved", removed);
123 }
124 
125 //TODO investigate if this should be improved for speed reasons
126 void KGetEngine::slotTransfersRemoved(const QStringList &urls, const QStringList &dBusObjectPaths)
127 {
128  for (int i = 0; i < urls.count(); ++i) {
129  transferRemoved(urls[i], dBusObjectPaths[i]);
130  }
131 }
132 
133 bool KGetEngine::isDBusServiceRegistered()
134 {
135  return interface->isServiceRegistered(KGET_DBUS_SERVICE);
136 }
137 
138 #include "kgetengine.moc"
KGetEngine::sources
QStringList sources() const
Definition: kgetengine.cpp:45
kgetengine.h
QObject
KGetEngine::KGetEngine
KGetEngine(QObject *parent, const QVariantList &args)
Definition: kgetengine.cpp:31
KGET_DBUS_PATH
const QString KGET_DBUS_PATH
Definition: kgetrunner.cpp:26
KGET_DBUS_SERVICE
const QString KGET_DBUS_SERVICE
Definition: kgetrunner.cpp:25
KGetEngine::updateSourceEvent
bool updateSourceEvent(const QString &source)
Definition: kgetengine.cpp:58
KGetEngine::~KGetEngine
~KGetEngine()
Definition: kgetengine.cpp:41
KGetEngine::sourceRequestEvent
bool sourceRequestEvent(const QString &name)
Definition: kgetengine.cpp:53
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

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

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal