1 /* 2 * Copyright © 2004-2008 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_SEARCH_HH 23 #define WULFOR_SEARCH_HH 24 25 #include <dcpp/stdinc.h> 26 #include <dcpp/DCPlusPlus.h> 27 #include <dcpp/ClientManager.h> 28 #include <dcpp/SearchManager.h> 29 #include <dcpp/SearchResult.h> 30 31 #include "bookentry.hh" 32 #include "treeview.hh" 33 34 class UserCommandMenu; 35 36 class Search: 37 public BookEntry, 38 public dcpp::SearchManagerListener, 39 public dcpp::ClientManagerListener 40 { 41 public: 42 Search(); 43 virtual ~Search(); 44 virtual void show(); 45 46 void putValue_gui(const std::string &str, int64_t size, dcpp::SearchManager::SizeModes mode, dcpp::SearchManager::TypeModes type); 47 48 private: 49 // Keep these and the items in .glade file in same order, otherwise it will break 50 typedef enum 51 { 52 NOGROUPING = 0, 53 FILENAME, 54 FILEPATH, 55 SIZE, 56 CONNECTION, 57 TTH, 58 USER, 59 HUB, 60 TYPE 61 } GroupType; 62 63 // GUI functions 64 void initHubs_gui(); 65 void addHub_gui(std::string name, std::string url); 66 void modifyHub_gui(std::string name, std::string url); 67 void removeHub_gui(std::string url); 68 void popupMenu_gui(); 69 void setStatus_gui(std::string statusBar, std::string text); 70 void updateStats_gui(); 71 void search_gui(); 72 void addResult_gui(const dcpp::SearchResultPtr result); 73 GtkTreeIter createParentRow_gui(GtkTreeIter *child, const std::string &groupStr, gint position = -1); 74 void updateParentRow_gui(GtkTreeIter *parent, GtkTreeIter *child = NULL); 75 void ungroup_gui(); 76 void regroup_gui(); 77 std::string getGroupingColumn(GroupType groupBy); 78 void download_gui(const std::string &target); 79 80 // GUI callbacks 81 static gboolean onFocusIn_gui(GtkWidget *widget, GdkEventFocus *event, gpointer data); 82 static gboolean onButtonPressed_gui(GtkWidget *widget, GdkEventButton *event, gpointer data); 83 static gboolean onButtonReleased_gui(GtkWidget *widget, GdkEventButton *event, gpointer data); 84 static gboolean onKeyReleased_gui(GtkWidget *widget, GdkEventKey *event, gpointer data); 85 static gboolean onSearchEntryKeyPressed_gui(GtkWidget *widget, GdkEventKey *event, gpointer data); 86 static gboolean searchFilterFunc_gui(GtkTreeModel *model, GtkTreeIter *iter, gpointer data); 87 static void onComboBoxChanged_gui(GtkWidget *widget, gpointer data); 88 static void onGroupByComboBoxChanged_gui(GtkWidget* widget, gpointer data); 89 static void onSearchButtonClicked_gui(GtkWidget *widget, gpointer data); 90 static void onFilterButtonToggled_gui(GtkToggleButton *button, gpointer data); 91 static void onSlotsButtonToggled_gui(GtkToggleButton *button, gpointer data); 92 static void onSharedButtonToggled_gui(GtkToggleButton *button, gpointer data); 93 static void onToggledClicked_gui(GtkCellRendererToggle *cell, gchar *path, gpointer data); 94 static void onDownloadClicked_gui(GtkMenuItem *item, gpointer data); 95 static void onDownloadFavoriteClicked_gui(GtkMenuItem *item, gpointer data); 96 static void onDownloadToClicked_gui(GtkMenuItem *item, gpointer data); 97 static void onDownloadToMatchClicked_gui(GtkMenuItem *item, gpointer data); 98 static void onDownloadDirClicked_gui(GtkMenuItem *item, gpointer data); 99 static void onDownloadFavoriteDirClicked_gui(GtkMenuItem *item, gpointer data); 100 static void onDownloadDirToClicked_gui(GtkMenuItem *item, gpointer data); 101 static void onSearchByTTHClicked_gui(GtkMenuItem *item, gpointer data); 102 static void onCopyMagnetClicked_gui(GtkMenuItem *item, gpointer data); 103 static void onGetFileListClicked_gui(GtkMenuItem *item, gpointer data); 104 static void onMatchQueueClicked_gui(GtkMenuItem *item, gpointer data); 105 static void onPrivateMessageClicked_gui(GtkMenuItem *item, gpointer data); 106 static void onAddFavoriteUserClicked_gui(GtkMenuItem *item, gpointer data); 107 static void onGrantExtraSlotClicked_gui(GtkMenuItem *item, gpointer data); 108 static void onRemoveUserFromQueueClicked_gui(GtkMenuItem *item, gpointer data); 109 static void onRemoveClicked_gui(GtkMenuItem *item, gpointer data); 110 111 // GUI functions 112 void parseSearchResult_gui(dcpp::SearchResultPtr result, dcpp::StringMap &resultMap); 113 114 // Client functions 115 void download_client(std::string target, std::string cid, std::string filename, int64_t size, std::string tth, std::string hubUrl); 116 void downloadDir_client(std::string target, std::string cid, std::string filename, std::string hubUrl); 117 void addSource_client(std::string source, std::string cid, int64_t size, std::string tth, std::string hubUrl); 118 void getFileList_client(std::string cid, std::string dir, bool match, std::string hubUrl); 119 void addFavUser_client(std::string cid); 120 void grantSlot_client(std::string cid, std::string hubUrl); 121 void removeSource_client(std::string cid); 122 123 // Client callbacks 124 virtual void on(dcpp::ClientManagerListener::ClientConnected, dcpp::Client *client) throw(); 125 virtual void on(dcpp::ClientManagerListener::ClientUpdated, dcpp::Client *client) throw(); 126 virtual void on(dcpp::ClientManagerListener::ClientDisconnected, dcpp::Client *client) throw(); 127 virtual void on(dcpp::SearchManagerListener::SR, const dcpp::SearchResultPtr &result) throw(); 128 129 TreeView hubView, resultView; 130 GtkListStore *hubStore; 131 GtkTreeStore *resultStore; 132 GtkTreeModel *searchFilterModel; 133 GtkTreeModel *sortedFilterModel; 134 GtkTreeSelection *selection; 135 GdkEventType oldEventType; 136 GtkWidget *searchEntry; 137 dcpp::TStringList searchlist; 138 static GtkTreeModel *searchEntriesModel; 139 int droppedResult; 140 int searchHits; 141 bool isHash; 142 bool onlyFree; 143 UserCommandMenu *userCommandMenu; 144 GroupType previousGrouping; 145 std::tr1::unordered_map<std::string, std::vector<dcpp::SearchResultPtr> > results; 146 }; 147 148 #else 149 class Search; 150 #endif 151