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/Client.h> 26 #include <dcpp/FavoriteManager.h> 27 #include <dcpp/QueueManager.h> 28 #include "bookentry.hh" 29 #include "treeview.hh" 30 #include "sound.hh" 31 #include "notify.hh" 32 #include "message.hh" 33 34 class UserCommandMenu; 35 class WulforSettingsManager; 36 class EmoticonsDialog; 37 38 class Hub: 39 public BookEntry, 40 public dcpp::ClientListener, 41 public dcpp::FavoriteManagerListener, 42 public dcpp::QueueManagerListener 43 { 44 public: 45 Hub(const std::string &address, const std::string &encoding); 46 virtual ~Hub(); 47 virtual void show(); 48 49 // Client functions 50 void reconnect_client(); 51 52 // GUI functions 53 void preferences_gui(); 54 55 private: 56 typedef enum 57 { 58 TAG_FIRST = 0, 59 TAG_GENERAL = TAG_FIRST, 60 TAG_MYOWN, 61 TAG_SYSTEM, 62 TAG_STATUS, 63 TAG_TIMESTAMP, 64 /*-*/ 65 TAG_MYNICK, 66 TAG_NICK, 67 TAG_OPERATOR, 68 TAG_FAVORITE, 69 TAG_URL, 70 TAG_LAST 71 } TypeTag; 72 73 typedef std::map<std::string, std::string> ParamMap; 74 typedef std::unordered_map<std::string, std::string> UserMap; 75 typedef std::unordered_map<std::string, GtkTreeIter> UserIters; 76 typedef std::unordered_map<GtkWidget*, std::string> ImageList; 77 typedef std::pair<std::string, GtkWidget*> ImageLoad; 78 79 // GUI functions 80 void setStatus_gui(std::string statusBar, std::string text); 81 bool findUser_gui(const std::string &cid, GtkTreeIter *iter); 82 bool findNick_gui(const std::string &nick, GtkTreeIter *iter); 83 void updateUser_gui(ParamMap id); 84 void removeUser_gui(std::string cid); 85 void removeTag_gui(const std::string &nick); 86 void clearNickList_gui(); 87 void popupNickMenu_gui(); 88 void getPassword_gui(); 89 void addMessage_gui(std::string cid, std::string message, Msg::TypeMsg typemsg); 90 void applyTags_gui(const std::string cid, const std::string &line); 91 void addStatusMessage_gui(std::string message, Msg::TypeMsg typemsg, Sound::TypeSound sound); 92 void applyEmoticons_gui(); 93 void updateCursor_gui(GtkWidget *widget); 94 void getSettingTag_gui(WulforSettingsManager *wsm, TypeTag type, std::string &fore, std::string &back, int &bold, int &italic); 95 GtkTextTag* createTag_gui(const std::string &tagname, TypeTag type); 96 void addStatusMessage_gui(std::string message, Msg::TypeMsg typemsg, Sound::TypeSound sound, Notify::TypeNotify notify); 97 void nickToChat_gui(const std::string &nick); 98 void addFavoriteUser_gui(ParamMap params); 99 void removeFavoriteUser_gui(ParamMap params); 100 void addPrivateMessage_gui(Msg::TypeMsg typemsg, std::string nick, std::string cid, std::string url, std::string message, bool useSetting); 101 void loadImage_gui(std::string target, std::string tth); 102 void openImage_gui(std::string target); 103 void insertBBcodeEntry_gui(std::string ch); 104 void disableChat(bool enable); 105 106 // GUI callbacks 107 static gboolean onFocusIn_gui(GtkWidget *widget, GdkEventFocus *event, gpointer data); 108 static gboolean onNickListButtonPress_gui(GtkWidget *widget, GdkEventButton *event, gpointer data); 109 static gboolean onNickListButtonRelease_gui(GtkWidget *widget, GdkEventButton *event, gpointer data); 110 static gboolean onNickListKeyRelease_gui(GtkWidget *widget, GdkEventKey *event, gpointer data); 111 static gboolean onNickListSearch_gui(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer data); 112 static gboolean onEntryKeyPress_gui(GtkWidget *widget, GdkEventKey *event, gpointer data); 113 static gboolean onNickTagEvent_gui(GtkTextTag *tag, GObject *textView, GdkEvent *event, GtkTextIter *iter, gpointer data); 114 static gboolean onLinkTagEvent_gui(GtkTextTag *tag, GObject *textView, GdkEvent *event, GtkTextIter *iter, gpointer data); 115 static gboolean onHubTagEvent_gui(GtkTextTag *tag, GObject *textView, GdkEvent *event, GtkTextIter *iter, gpointer data); 116 static gboolean onMagnetTagEvent_gui(GtkTextTag *tag, GObject *textView, GdkEvent *event, GtkTextIter *iter, gpointer data); 117 static gboolean onChatPointerMoved_gui(GtkWidget *widget, GdkEventMotion *event, gpointer data); 118 static gboolean onChatVisibilityChanged_gui(GtkWidget *widget, GdkEventVisibility *event, gpointer data); 119 static gboolean onEmotButtonRelease_gui(GtkWidget *widget, GdkEventButton *event, gpointer data); 120 static void onChatScroll_gui(GtkAdjustment *adjustment, gpointer data); 121 static void onChatResize_gui(GtkAdjustment *adjustment, gpointer data); 122 static void onSendMessage_gui(GtkEntry *entry, gpointer data); 123 static void onNickToChat_gui(GtkMenuItem *item, gpointer data); 124 static void onCopyNickItemClicked_gui(GtkMenuItem *item, gpointer data); 125 static void onBrowseItemClicked_gui(GtkMenuItem *item, gpointer data); 126 static void onMatchItemClicked_gui(GtkMenuItem *item, gpointer data); 127 static void onMsgItemClicked_gui(GtkMenuItem *item, gpointer data); 128 static void onGrantItemClicked_gui(GtkMenuItem *item, gpointer data); 129 static void onRemoveUserItemClicked_gui(GtkMenuItem *item, gpointer data); 130 static void onCopyURIClicked_gui(GtkMenuItem *item, gpointer data); 131 static void onOpenLinkClicked_gui(GtkMenuItem *item, gpointer data); 132 static void onOpenHubClicked_gui(GtkMenuItem *item, gpointer data); 133 static void onSearchMagnetClicked_gui(GtkMenuItem *item, gpointer data); 134 static void onMagnetPropertiesClicked_gui(GtkMenuItem *item, gpointer data); 135 static void onUserListToggled_gui(GtkWidget *widget, gpointer data); 136 static void onAddFavoriteUserClicked_gui(GtkMenuItem *item, gpointer data); 137 static void onRemoveFavoriteUserClicked_gui(GtkMenuItem *item, gpointer data); 138 static void onPasswordDialog(GtkWidget *dialog, gint response, gpointer data); 139 static void onDownloadToClicked_gui(GtkMenuItem *item, gpointer data); 140 static void onDownloadClicked_gui(GtkMenuItem *item, gpointer data); 141 static void onCommandClicked_gui(GtkWidget *widget, gpointer data); 142 static gboolean onChatCommandButtonRelease_gui(GtkWidget *widget, GdkEventButton *event, gpointer data); 143 static void onUseEmoticons_gui(GtkWidget *widget, gpointer data); 144 static void onImageDestroy_gui(GtkWidget *widget, gpointer data); 145 static void onDownloadImageClicked_gui(GtkMenuItem *item, gpointer data); 146 static void onRemoveImageClicked_gui(GtkMenuItem *item, gpointer data); 147 static void onOpenImageClicked_gui(GtkMenuItem *item, gpointer data); 148 static gboolean onImageEvent_gui(GtkWidget *widget, GdkEventButton *event, gpointer data); 149 static gboolean expose(GtkWidget *widget, GdkEventExpose *event, gpointer data); 150 static void onItalicButtonClicked_gui(GtkWidget *widget, gpointer data); 151 static void onBoldButtonClicked_gui(GtkWidget *widget, gpointer data); 152 static void onUnderlineButtonClicked_gui(GtkWidget *widget, gpointer data); 153 static void onDisableChatToggled_gui(GtkWidget *widget, gpointer data); 154 static void onPartialFileListOpen_gui(GtkMenuItem *item, gpointer data); 155 156 // Client functions 157 void addFavoriteUser_client(const std::string cid); 158 void removeFavoriteUser_client(const std::string cid); 159 void connectClient_client(std::string address, std::string encoding); 160 void disconnect_client(); 161 void setPassword_client(std::string password); 162 void sendMessage_client(std::string message, bool thirdPerson); 163 void getFileList_client(std::string cid, bool match, bool full); 164 void grantSlot_client(std::string cid); 165 void removeUserFromQueue_client(std::string cid); 166 void redirect_client(std::string address, bool follow); 167 void rebuildHashData_client(); 168 void refreshFileList_client(); 169 void addAsFavorite_client(); 170 void getParams_client(ParamMap &user, dcpp::Identity &id); 171 void download_client(std::string target, int64_t size, std::string tth, std::string cid); 172 std::string realFile_client(std::string tth); 173 void openImage_client(std::string tth); 174 175 // Favorite callbacks 176 virtual void on(dcpp::FavoriteManagerListener::UserAdded, const dcpp::FavoriteUser &user) noexcept; 177 virtual void on(dcpp::FavoriteManagerListener::UserRemoved, const dcpp::FavoriteUser &user) noexcept; 178 179 // Client callbacks 180 virtual void on(dcpp::ClientListener::Connecting, dcpp::Client *) noexcept; 181 virtual void on(dcpp::ClientListener::Connected, dcpp::Client *) noexcept; 182 virtual void on(dcpp::ClientListener::UserUpdated, dcpp::Client *, const dcpp::OnlineUser &user) noexcept; 183 virtual void on(dcpp::ClientListener::UsersUpdated, dcpp::Client *, const dcpp::OnlineUserList &list) noexcept; 184 virtual void on(dcpp::ClientListener::UserRemoved, dcpp::Client *, const dcpp::OnlineUser &user) noexcept; 185 virtual void on(dcpp::ClientListener::Redirect, dcpp::Client *, const std::string &address) noexcept; 186 virtual void on(dcpp::ClientListener::Failed, dcpp::Client *, const std::string &reason) noexcept; 187 virtual void on(dcpp::ClientListener::GetPassword, dcpp::Client *) noexcept; 188 virtual void on(dcpp::ClientListener::HubUpdated, dcpp::Client *) noexcept; 189 virtual void on(dcpp::ClientListener::Message, dcpp::Client*, const dcpp::ChatMessage& message) noexcept; 190 virtual void on(dcpp::ClientListener::StatusMessage, dcpp::Client *, const std::string &message, int flag) noexcept; 191 virtual void on(dcpp::ClientListener::NickTaken, dcpp::Client *) noexcept; 192 virtual void on(dcpp::ClientListener::SearchFlood, dcpp::Client *, const std::string &message) noexcept; 193 virtual void on(dcpp::QueueManagerListener::Finished, dcpp::QueueItem *item, const std::string& dir, int64_t avSpeed) noexcept; 194 195 UserMap userMap; 196 UserIters userIters; 197 UserMap userFavoriteMap; 198 ImageList imageList; 199 ImageLoad imageLoad; 200 dcpp::StringPair imageMagnet; 201 GtkTextTag *TagsMap[TAG_LAST]; 202 std::string completionKey; 203 dcpp::Client *client; 204 TreeView nickView; 205 GtkListStore *nickStore; 206 GtkTreeSelection *nickSelection; 207 GtkTextBuffer *chatBuffer; 208 GtkTextMark *chatMark, *start_mark, *end_mark, *tag_mark, *emot_mark; 209 gint oldType; 210 std::vector<std::string> history; 211 int historyIndex; 212 static const int maxLines = 1000; 213 static const int maxHistory = 20; 214 int64_t totalShared; 215 GdkCursor *handCursor; 216 GtkTextTag *selectedTag; 217 std::string selectedTagStr; 218 UserCommandMenu *userCommandMenu; 219 std::string address; 220 std::string encoding; 221 bool scrollToBottom; 222 static const std::string tagPrefix; 223 TypeTag tagMsg; 224 bool useEmoticons; 225 gint totalEmoticons; 226 EmoticonsDialog *emotdialog; 227 bool PasswordDialog; 228 bool WaitingPassword; 229 int ImgLimit; 230 GtkTextTag *BoldTag, *UnderlineTag, *ItalicTag; 231 bool enableChat; 232 }; 233