• 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
  • dbus
dbuskgetwrapper.cpp
Go to the documentation of this file.
1 /**************************************************************************
2 * Copyright (C) 2006 - 2008 Urs Wolfer <uwolfer @ kde.org> *
3 * Copyright (C) 2006 Dario Massarin <nekkar@libero.it> *
4 * Copyright (C) 2008 - 2009 Lukas Appelhans <l.appelhans@gmx.de> *
5 * Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
21 ***************************************************************************/
22 
23 #include "dbuskgetwrapper.h"
24 
25 #include "core/kget.h"
26 #include "core/transferhandler.h"
27 #include "core/transfertreemodel.h"
28 #include "core/plugin/transferfactory.h"
29 #include "mainwindow.h"
30 #include "settings.h"
31 #include "ui/droptarget.h"
32 #include "ui/linkview/kget_linkview.h"
33 #include "ui/newtransferdialog.h"
34 
35 #include <KDebug>
36 
37 DBusKGetWrapper::DBusKGetWrapper(MainWindow *parent)
38  : QObject(parent),
39  m_mainWindow(parent)
40 {
41  foreach (TransferHandler *handler, KGet::allTransfers()) {
42  m_transfers[handler] = qMakePair(handler->source().pathOrUrl(), handler->dBusObjectPath());
43  }
44 
45  TransferTreeModel *model = KGet::model();
46 
47  connect(model, SIGNAL(transfersAddedEvent(QList<TransferHandler*>)), this, SLOT(slotTransfersAdded(QList<TransferHandler*>)));
48  connect(model, SIGNAL(transfersRemovedEvent(QList<TransferHandler*>)), this, SLOT(slotTransfersRemoved(QList<TransferHandler*>)));
49 }
50 
51 DBusKGetWrapper::~DBusKGetWrapper()
52 {
53 }
54 
55 QStringList DBusKGetWrapper::addTransfer(const QString& src, const QString& dest, bool start)
56 {
57  QStringList dBusPaths;
58 
59 
60  // split src for the case it is a QStringList (e.g. from konqueror plugin)
61  QList<TransferHandler*> addedTransfers = KGet::addTransfer(src.split(';'), dest, QString(), start);
62 
63  foreach (TransferHandler *handler, addedTransfers) {
64  dBusPaths.append(handler->dBusObjectPath());
65  }
66 
67  return dBusPaths;
68 }
69 
70 bool DBusKGetWrapper::delTransfer(const QString& dbusObjectPath)
71 {
72  kDebug(5001) << "deleting Transfer";
73 
74  Transfer *transfer = KGet::model()->findTransferByDBusObjectPath(dbusObjectPath);
75 
76  if (transfer) {
77  return KGet::delTransfer(transfer->handler());
78  }
79 
80  return false;
81 }
82 
83 void DBusKGetWrapper::showNewTransferDialog(const QStringList &urls)
84 {
85  NewTransferDialogHandler::showNewTransferDialog(urls);
86 }
87 
88 bool DBusKGetWrapper::dropTargetVisible() const
89 {
90  return m_mainWindow->m_drop->isVisible();
91 }
92 
93 void DBusKGetWrapper::setDropTargetVisible(bool setVisible)
94 {
95  if (setVisible != Settings::showDropTarget()) {
96  m_mainWindow->m_drop->setDropTargetVisible(setVisible);
97  }
98 }
99 
100 void DBusKGetWrapper::setOfflineMode(bool offline)
101 {
102  KGet::setSchedulerRunning(offline);
103 }
104 
105 bool DBusKGetWrapper::offlineMode() const
106 {
107  return !KGet::schedulerRunning();
108 }
109 
110 QVariantMap DBusKGetWrapper::transfers() const
111 {
112  const QList<QPair<QString, QString> > transfers = m_transfers.values();
113  QVariantMap result;
114  for (int i = 0; i < transfers.count(); ++i) {
115  result.insert(transfers[i].first, transfers[i].second);
116  }
117 
118  return result;
119 }
120 
121 void DBusKGetWrapper::slotTransfersAdded(const QList<TransferHandler*> &transfers)
122 {
123  QStringList urls;
124  QStringList objectPaths;
125  foreach (TransferHandler *transfer, transfers) {
126  const QString url = transfer->source().pathOrUrl();
127  const QString objectPath = transfer->dBusObjectPath();
128  urls << url;
129  objectPaths << objectPath;
130  m_transfers[transfer] = qMakePair(url, objectPath);
131  }
132 
133  emit transfersAdded(urls, objectPaths);
134 }
135 
136 void DBusKGetWrapper::slotTransfersRemoved(const QList<TransferHandler*> &transfers)
137 {
138  QStringList urls;
139  QStringList objectPaths;
140  foreach (TransferHandler *transfer, transfers) {
141  const QPair<QString, QString> removed = m_transfers[transfer];
142  urls << removed.first;
143  objectPaths << removed.second;
144  }
145 
146  emit transfersRemoved(urls, objectPaths);
147 }
148 
149 int DBusKGetWrapper::transfersSpeed() const
150 {
151  return 0;//FIXME
152  //return m_dbusModelObserver->transfersSpeed();
153 }
154 
155 void DBusKGetWrapper::importLinks(const QList <QString> &links)
156 {
157  KGetLinkView *link_view = new KGetLinkView(m_mainWindow);
158  link_view->setLinks(links);
159  link_view->show();
160 }
161 
162 bool DBusKGetWrapper::isSupported(const QString &url) const
163 {
164  foreach (TransferFactory * factory, KGet::factories()) {
165  kDebug() << "Check" << factory->objectName() << "for" << url << "it is?" << factory->isSupported(KUrl(url));
166  if (factory->isSupported(KUrl(url)))
167  return true;
168  }
169  return false;
170 }
171 
172 #include "dbuskgetwrapper.moc"
DBusKGetWrapper::~DBusKGetWrapper
~DBusKGetWrapper()
Definition: dbuskgetwrapper.cpp:51
kget_linkview.h
KGet::addTransfer
static TransferHandler * addTransfer(KUrl srcUrl, QString destDir=QString(), QString suggestedFileName=QString(), QString groupName=QString(), bool start=false)
Adds a new transfer to the KGet.
Definition: kget.cpp:179
TransferHandler
Class TransferHandler:
Definition: transferhandler.h:48
TransferTreeModel::findTransferByDBusObjectPath
Transfer * findTransferByDBusObjectPath(const QString &dbusObjectPath)
Definition: transfertreemodel.cpp:499
transfertreemodel.h
DBusKGetWrapper::DBusKGetWrapper
DBusKGetWrapper(MainWindow *parent)
Definition: dbuskgetwrapper.cpp:37
QObject
DBusKGetWrapper::setOfflineMode
void setOfflineMode(bool online)
Definition: dbuskgetwrapper.cpp:100
TransferTreeModel
Definition: transfertreemodel.h:108
DropTarget::setDropTargetVisible
void setDropTargetVisible(bool shown, bool internal=true)
Definition: droptarget.cpp:128
KGet::allTransfers
static QList< TransferHandler * > allTransfers()
Gets all transfers.
Definition: kget.cpp:657
transferfactory.h
DBusKGetWrapper::delTransfer
bool delTransfer(const QString &dbusObjectPath)
Definition: dbuskgetwrapper.cpp:70
DBusKGetWrapper::transfersRemoved
void transfersRemoved(const QStringList &urls, const QStringList &dbusObjectPaths)
KGet::model
static TransferTreeModel * model()
Definition: kget.cpp:487
KGetLinkView
Definition: kget_linkview.h:25
mainwindow.h
DBusKGetWrapper::addTransfer
QStringList addTransfer(const QString &src, const QString &destDir=QString(), bool start=false)
Definition: dbuskgetwrapper.cpp:55
newtransferdialog.h
DBusKGetWrapper::dropTargetVisible
bool dropTargetVisible() const
Definition: dbuskgetwrapper.cpp:88
TransferHandler::source
const KUrl & source() const
Definition: transferhandler.h:93
DBusKGetWrapper::importLinks
void importLinks(const QList< QString > &links)
Definition: dbuskgetwrapper.cpp:155
droptarget.h
TransferHandler::dBusObjectPath
QString dBusObjectPath()
Definition: transferhandler.h:262
DBusKGetWrapper::transfers
QVariantMap transfers() const
Definition: dbuskgetwrapper.cpp:110
DBusKGetWrapper::showNewTransferDialog
void showNewTransferDialog(const QStringList &urls)
Definition: dbuskgetwrapper.cpp:83
transferhandler.h
DBusKGetWrapper::transfersAdded
void transfersAdded(const QStringList &urls, const QStringList &dBusObjectPaths)
DBusKGetWrapper::setDropTargetVisible
void setDropTargetVisible(bool setVisible)
Definition: dbuskgetwrapper.cpp:93
settings.h
Transfer::handler
TransferHandler * handler()
Definition: transfer.cpp:217
NewTransferDialogHandler::showNewTransferDialog
static void showNewTransferDialog(const KUrl &url=KUrl())
Definition: newtransferdialog.cpp:493
DBusKGetWrapper::isSupported
bool isSupported(const QString &url) const
Definition: dbuskgetwrapper.cpp:162
DBusKGetWrapper::transfersSpeed
int transfersSpeed() const
Definition: dbuskgetwrapper.cpp:149
kget.h
Settings::showDropTarget
static bool showDropTarget()
Get ShowDropTarget.
Definition: settings.h:164
DBusKGetWrapper::offlineMode
bool offlineMode() const
Definition: dbuskgetwrapper.cpp:105
KGetLinkView::setLinks
void setLinks(const QStringList &links)
Definition: kget_linkview.cpp:150
dbuskgetwrapper.h
TransferFactory
TransferFactory.
Definition: transferfactory.h:52
KGet::factories
static QList< TransferFactory * > factories()
Definition: kget.cpp:621
KGet::setSchedulerRunning
static void setSchedulerRunning(bool running=true)
if running == true starts the scheduler if running == false stops the scheduler
Definition: kget.cpp:636
MainWindow
The main window of KGet.
Definition: mainwindow.h:41
KGet::delTransfer
static bool delTransfer(TransferHandler *transfer, DeleteMode mode=AutoDelete)
Removes a transfer from the KGet.
Definition: kget.cpp:362
TransferFactory::isSupported
virtual bool isSupported(const KUrl &url) const
Definition: transferfactory.cpp:72
KGet::schedulerRunning
static bool schedulerRunning()
Returns true if the scheduler has running jobs.
Definition: kget.cpp:647
Transfer
Definition: transfer.h:36
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