1 /*
2  * Copyright © 2009-2010 freedcpp, http://code.google.com/p/freedcpp
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 FAVORITE_USERS_HH
23 #define FAVORITE_USERS_HH
24 
25 #include <dcpp/stdinc.h>
26 #include <dcpp/DCPlusPlus.h>
27 #include <dcpp/FavoriteManager.h>
28 
29 #include "bookentry.hh"
30 #include "treeview.hh"
31 
32 class FavoriteUsers:
33 	public BookEntry,
34 	public dcpp::FavoriteManagerListener
35 {
36 	public:
37 		FavoriteUsers();
38 		virtual ~FavoriteUsers();
39 		virtual void show();
40 
41 	private:
42 		typedef std::map<std::string, std::string> ParamMap;
43 		typedef std::tr1::unordered_map<std::string, GtkTreeIter> UserIters;
44 
45 		// GUI functions
46 		bool findUser_gui(const std::string &cid, GtkTreeIter *iter);
47 		void updateFavoriteUser_gui(ParamMap params);
48 		void removeFavoriteUser_gui(const std::string cid);
49 		void setStatus_gui(const std::string text);
50 
51 		// GUI callbacks
52 		static void onBrowseItemClicked_gui(GtkMenuItem *item, gpointer data);
53 		static void onMatchQueueItemClicked_gui(GtkMenuItem *item, gpointer data);
54 		static void onSendPMItemClicked_gui(GtkMenuItem *item, gpointer data);
55 		static void onGrantSlotItemClicked_gui(GtkMenuItem *item, gpointer data);
56 		static void onConnectItemClicked_gui(GtkMenuItem *item, gpointer data);
57 		static void onRemoveFromQueueItemClicked_gui(GtkMenuItem *item, gpointer data);
58 		static void onDescriptionItemClicked_gui(GtkMenuItem *item, gpointer data);
59 		static void onRemoveItemClicked_gui(GtkMenuItem *item, gpointer data);
60 		static void onAutoGrantSlotToggled_gui(GtkCellRendererToggle *cell, gchar *path, gpointer data);
61 		static gboolean onKeyReleased_gui(GtkWidget *widget, GdkEventKey *event, gpointer data);
62 		static gboolean onButtonPressed_gui(GtkWidget *widget, GdkEventButton *event, gpointer data);
63 		static gboolean onButtonReleased_gui(GtkWidget *widget, GdkEventButton *event, gpointer data);
64 
65 		// Client functions
66 		void getFileList_client(const std::string cid, const std::string hubUrl, bool match);
67 		void grantSlot_client(const std::string cid, const std::string hubUrl);
68 		void removeUserFromQueue_client(const std::string cid);
69 		void removeFavoriteUser_client(const std::string cid);
70 		void setAutoGrantSlot_client(const std::string cid, bool grant);
71 		void setUserDescription_client(const std::string cid, const std::string description);
72 
73 		// Favorite callbacks
74 		virtual void on(dcpp::FavoriteManagerListener::UserAdded, const dcpp::FavoriteUser &user) throw();
75 		virtual void on(dcpp::FavoriteManagerListener::UserRemoved, const dcpp::FavoriteUser &user) throw();
76 		virtual void on(dcpp::FavoriteManagerListener::StatusChanged, const dcpp::UserPtr& user) throw();
77 
78 		UserIters userIters;
79 		GdkEventType previous;
80 		TreeView favoriteUserView;
81 		GtkListStore *favoriteUserStore;
82 		GtkTreeSelection *favoriteUserSelection;
83 };
84 
85 #else
86 class FavoriteUsers;
87 #endif
88