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