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