summaryrefslogtreecommitdiffstats
path: root/kde/patch/ktorrent/ktorrent.taskmanager.diff
blob: bb7fe2547d570dd8d0426fc005ae4eb809de0578 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
From: Joris Guisson <joris.guisson@gmail.com>
Date: Wed, 23 Nov 2011 19:17:08 +0000
Subject: Use dbus to show ktorrent window from plasma applet. This removes the dependency on libtaskmanager.
X-Git-Tag: v4.2rc1
X-Git-Url: http://quickgit.kde.org/?p=ktorrent.git&amp;a=commitdiff&amp;h=6d4a6ae51692966862ccb20d17cb217717519d40
---
Use dbus to show ktorrent window from plasma applet. This removes the dependency on libtaskmanager.

BUG: 287309
---


--- a/plasma/applet/CMakeLists.txt
+++ b/plasma/applet/CMakeLists.txt
@@ -5,25 +5,15 @@ if(NOT QT_VERSION_OK)
 
 else(NOT QT_VERSION_OK)
 	
-	set(TASKMANAGER_FOUND FALSE)
-	FIND_PATH(TASKMANAGER_INCLUDE_DIR NAMES taskmanager.h  PATHS ${KDE4_INCLUDE_DIR}/taskmanager ${INCLUDE_INSTALL_DIR}/taskmanager.h)
-	FIND_LIBRARY(TASKMANAGER_LIBRARY NAMES taskmanager PATHS ${KDE4_LIB_DIR} ${LIB_INSTALL_DIR})
-
-	if(TASKMANAGER_INCLUDE_DIR AND TASKMANAGER_LIBRARY)
-		set(TASKMANAGER_FOUND TRUE)
-		message(STATUS "Found libtaskmanager: ${TASKMANAGER_LIBRARY} ")
-		include_directories(${TASKMANAGER_INCLUDE_DIR})
-		set(ktapplet_SRCS applet.cpp chunkbar.cpp fadingitem.cpp fadingnavigationwidget.cpp)
-		
-		kde4_add_ui_files(ktapplet_SRCS appletconfig.ui)
-		
-		kde4_add_plugin(plasma_applet_ktorrent ${ktapplet_SRCS})
-		target_link_libraries(plasma_applet_ktorrent  ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS} ${TASKMANAGER_LIBRARY} ${LIBKTORRENT_LIBRARIES} ktcore)
-		
-		install(TARGETS plasma_applet_ktorrent DESTINATION ${PLUGIN_INSTALL_DIR})
-		install(FILES plasma-applet-ktorrent.desktop DESTINATION ${SERVICES_INSTALL_DIR})
-	endif(TASKMANAGER_INCLUDE_DIR AND TASKMANAGER_LIBRARY)
-
-	macro_log_feature(TASKMANAGER_FOUND "libtaskmanager" "libtaskmanager library and header files" "http://www.kde.org/" FALSE "" "libtaskmanager is needed for KTorrent Plasmoid")
+	
+	set(ktapplet_SRCS applet.cpp chunkbar.cpp fadingitem.cpp fadingnavigationwidget.cpp)
+	
+	kde4_add_ui_files(ktapplet_SRCS appletconfig.ui)
+	
+	kde4_add_plugin(plasma_applet_ktorrent ${ktapplet_SRCS})
+	target_link_libraries(plasma_applet_ktorrent  ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS} ${LIBKTORRENT_LIBRARIES} ktcore)
+	
+	install(TARGETS plasma_applet_ktorrent DESTINATION ${PLUGIN_INSTALL_DIR})
+	install(FILES plasma-applet-ktorrent.desktop DESTINATION ${SERVICES_INSTALL_DIR})
 
 endif(NOT QT_VERSION_OK)

--- a/plasma/applet/applet.cpp
+++ b/plasma/applet/applet.cpp
@@ -21,6 +21,9 @@
 #include "applet.h"
 #include <QFile>
 #include <QGraphicsLinearLayout>
+#include <QDBusConnection>
+#include <QDBusConnectionInterface>
+#include <QDBusMessage>
 #include <KConfigDialog>
 #include <KLocale>
 #include <KRun>
@@ -31,12 +34,11 @@
 #include <Plasma/IconWidget>
 #endif
 #include <Plasma/Label>
-#include <taskmanager/taskmanager.h>
-#include <taskmanager/task.h>
 #include <util/functions.h>
 #include "chunkbar.h"
 #include "fadingnavigationwidget.h"
 
+
 using namespace bt;
 
 namespace ktplasma
@@ -174,7 +176,8 @@ namespace ktplasma
 		}
 	}
 
-	void Applet::updateNavigation() {
+	void Applet::updateNavigation() 
+	{
 		navigation->setEnabled(connected_to_app && !sources.empty()
 			&& (sources.count() > 1 || !sources.contains(current_source)));
 	}
@@ -193,12 +196,14 @@ namespace ktplasma
 		}
 	}
 	
-	void Applet::updateSources() {
+	void Applet::updateSources() 
+	{
 		sources = engine->sources();
 		sources.removeOne("core");
 	}
 
-	void Applet::setSource(QString source) {
+	void Applet::setSource(QString source) 
+	{
 		if (!current_source.isEmpty())
 			engine->disconnectSource(current_source,this);
 		clearData();
@@ -340,20 +345,39 @@ namespace ktplasma
 
 	void Applet::iconClicked()
 	{
-		TaskManager::TaskDict tasks = TaskManager::TaskManager::self()->tasks();
-		for (TaskManager::TaskDict::iterator i = tasks.begin();i != tasks.end();i ++)
+		QDBusConnection session_bus = QDBusConnection::sessionBus();
+		QDBusConnectionInterface* dbus_service = session_bus.interface();
+		if (!session_bus.isConnected() || !dbus_service || !dbus_service->isServiceRegistered("org.ktorrent.ktorrent"))
+		{
+			// can't find the window, try launching it
+			KUrl::List empty;
+			KRun::run("ktorrent", empty, 0);
+		}
+		else
 		{
-			if (i.value()->className() == "ktorrent")
-			{
-				KWindowSystem::activateWindow(i.key());
-				return;
-			}
+			QDBusMessage msg = QDBusMessage::createMethodCall("org.ktorrent.ktorrent", "/ktorrent/MainWindow_1", "org.kde.KMainWindow", "winId");
+			QDBusPendingCall call = session_bus.asyncCall(msg, 5000);
+			QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(call ,this);
+			connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(dbusCallFinished(QDBusPendingCallWatcher*)));
 		}
-
-		// can't find the window, try launching it
-		KUrl::List empty;
-		KRun::run("ktorrent", empty, 0);
 	}
+	
+	void Applet::dbusCallFinished(QDBusPendingCallWatcher* self)
+	{
+		if (self->isError())
+		{
+			// call failed, try launching it
+			KUrl::List empty;
+			KRun::run("ktorrent", empty, 0);
+		}
+		else
+		{
+			QDBusPendingReply<qlonglong> reply = *self;
+			KWindowSystem::activateWindow(reply.value());		
+		}
+		self->deleteLater();
+	}
+
 
 	void Applet::clearData()
 	{		

--- a/plasma/applet/applet.h
+++ b/plasma/applet/applet.h
@@ -27,6 +27,7 @@
 #include "fadingnavigationwidget.h"
 
 class QGraphicsLinearLayout;
+class QDBusPendingCallWatcher;
 
 namespace Plasma
 {
@@ -68,6 +69,7 @@ namespace ktplasma
 		void iconClicked();
 		void selectPrev();
 		void selectNext();
+		void dbusCallFinished(QDBusPendingCallWatcher* self);
 		
 	private:
 		void updateTorrentCombo();