1 /*
2  * Copyright © 2004-2009 Jens Oknelid, paskharen@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * In addition, as a special exception, compiling, linking, and/or
19  * using OpenSSL with this program is allowed.
20  */
21 
22 #ifndef WULFOR_TRANSFERS_HH
23 #define WULFOR_TRANSFERS_HH
24 
25 #include "IntlUtil.hh"
26 
27 #include <dcpp/stdinc.h>
28 #include <dcpp/DCPlusPlus.h>
29 #include <dcpp/ConnectionManager.h>
30 #include <dcpp/DownloadManager.h>
31 #include <dcpp/LogManager.h>
32 #include <dcpp/QueueManager.h>
33 #include <dcpp/UploadManager.h>
34 
35 #include "treeview.hh"
36 #include "entry.hh"
37 #include "UserCommandMenu.hh"
38 
39 class Transfers:
40 	public dcpp::ConnectionManagerListener,
41 	public dcpp::DownloadManagerListener,
42 	public dcpp::QueueManagerListener,
43 	public dcpp::UploadManagerListener,
44 	public Entry
45 {
46 	public:
47 		Transfers();
48 		~Transfers();
49 
getContainer()50 		GtkWidget *getContainer() { return getWidget("mainBox"); }
51 		virtual void show();
52 
53 	private:
54 		// GUI functions
55 		void addConnection_gui(dcpp::StringMap params, bool download);
56 		void removeConnection_gui(const std::string cid, bool download);
57 
58 		void initTransfer_gui(dcpp::StringMap params);
59 		void updateTransfer_gui(dcpp::StringMap params, bool download);
60 		void updateFilePosition_gui(const std::string cid, int64_t filePosition);
61 		void updateParent_gui(GtkTreeIter* iter);
62 		void finishParent_gui(const std::string target, const std::string status);
63 
64 		bool findParent_gui(const std::string& target, GtkTreeIter* iter);
65 		bool findTransfer_gui(const std::string& cid, bool download, GtkTreeIter* iter);
66 
67 		void popupTransferMenu_gui();
68 
69 		// GUI callbacks
70 		static gboolean onTransferButtonPressed_gui(GtkWidget *widget, GdkEventButton *event, gpointer data);
71 		static gboolean onTransferButtonReleased_gui(GtkWidget *widget, GdkEventButton *event, gpointer data);
72 		static void onGetFileListClicked_gui(GtkMenuItem *item, gpointer data);
73 		static void onMatchQueueClicked_gui(GtkMenuItem *item, gpointer data);
74 		static void onPrivateMessageClicked_gui(GtkMenuItem *item, gpointer data);
75 		static void onAddFavoriteUserClicked_gui(GtkMenuItem *item, gpointer data);
76 		static void onGrantExtraSlotClicked_gui(GtkMenuItem *item, gpointer data);
77 		static void onRemoveUserFromQueueClicked_gui(GtkMenuItem *item, gpointer data);
78 		static void onForceAttemptClicked_gui(GtkMenuItem *item, gpointer data);
79 		static void onCloseConnectionClicked_gui(GtkMenuItem *item, gpointer data);
80 
81 		// Client functions
82 		void getParams_client(dcpp::StringMap& params, dcpp::ConnectionQueueItem* cqi);
83 		void getParams_client(dcpp::StringMap& params, dcpp::Transfer* transfer);
84 		std::string getFileName_client(dcpp::Transfer *t);
85 		void getFileList_client(std::string cid, std::string hubUrl);
86 		void matchQueue_client(std::string cid, std::string hubUrl);
87 		void addFavoriteUser_client(std::string cid);
88 		void grantExtraSlot_client(std::string cid, std::string hubUrl);
89 		void removeUserFromQueue_client(std::string cid);
90 		void forceAttempt_client(std::string cid);
91 		void closeConnection_client(std::string cid, bool download);
92 
93 		// DownloadManager
94 		virtual void on(dcpp::DownloadManagerListener::Requesting, dcpp::Download* dl) throw();
95 		virtual void on(dcpp::DownloadManagerListener::Starting, dcpp::Download* dl) throw();
96 		virtual void on(dcpp::DownloadManagerListener::Tick, const dcpp::DownloadList& dls) throw();
97 		virtual void on(dcpp::DownloadManagerListener::Complete, dcpp::Download* dl) throw();
98 		virtual void on(dcpp::DownloadManagerListener::Failed, dcpp::Download* dl, const std::string& reason) throw();
99 		// ConnectionManager
100 		virtual void on(dcpp::ConnectionManagerListener::Added, dcpp::ConnectionQueueItem* cqi) throw();
101 		virtual void on(dcpp::ConnectionManagerListener::Connected, dcpp::ConnectionQueueItem* cqi) throw();
102 		virtual void on(dcpp::ConnectionManagerListener::Removed, dcpp::ConnectionQueueItem* cqi) throw();
103 		virtual void on(dcpp::ConnectionManagerListener::Failed, dcpp::ConnectionQueueItem* cqi, const std::string&) throw();
104 		virtual void on(dcpp::ConnectionManagerListener::StatusChanged, dcpp::ConnectionQueueItem* cqi) throw();
105 		// QueueManager
106 		virtual void on(dcpp::QueueManagerListener::Finished, dcpp::QueueItem* qi, const std::string&, int64_t size) throw();
107 		virtual void on(dcpp::QueueManagerListener::Removed, dcpp::QueueItem* qi) throw();
108 		// UploadManager
109 		virtual void on(dcpp::UploadManagerListener::Starting, dcpp::Upload* ul) throw();
110 		virtual void on(dcpp::UploadManagerListener::Tick, const dcpp::UploadList& uls) throw();
111 		virtual void on(dcpp::UploadManagerListener::Complete, dcpp::Upload* ul) throw();
112 		virtual void on(dcpp::UploadManagerListener::Failed, dcpp::Upload* ul, const std::string& reason) throw();
113 
114 		TreeView transferView;
115 		GtkTreeStore *transferStore;
116 		GtkTreeSelection *transferSelection;
117 		UserCommandMenu* userCommandMenu;
118 };
119 
120 #endif // WULFOR_TRANSFERS_HH
121 
122