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_HUB_HH 23 #define WULFOR_HUB_HH 24 25 #include <dcpp/stdinc.h> 26 #include <dcpp/DCPlusPlus.h> 27 #include <dcpp/Client.h> 28 29 #include "bookentry.hh" 30 #include "treeview.hh" 31 32 class UserCommandMenu; 33 34 class Hub: 35 public BookEntry, 36 public dcpp::ClientListener 37 { 38 public: 39 Hub(const std::string &address, const std::string &encoding); 40 virtual ~Hub(); 41 virtual void show(); 42 43 // Client functions 44 void reconnect_client(); 45 46 private: 47 typedef std::map<std::string, std::string> ParamMap; 48 49 // GUI functions 50 void setStatus_gui(std::string statusBar, std::string text); 51 bool findUser_gui(const std::string &cid, GtkTreeIter *iter); 52 bool findNick_gui(const std::string &nick, GtkTreeIter *iter); 53 void updateStats_gui(); 54 void updateUser_gui(ParamMap id, bool showJoin); 55 void removeUser_gui(std::string cid); 56 void removeTag_gui(const std::string &nick); 57 void clearNickList_gui(); 58 void popupNickMenu_gui(); 59 void getPassword_gui(); 60 void addMessage_gui(std::string message); 61 void applyTags_gui(const std::string &line); 62 void addStatusMessage_gui(std::string message); 63 void updateCursor_gui(GtkWidget *widget); 64 65 // GUI callbacks 66 static gboolean onFocusIn_gui(GtkWidget *widget, GdkEventFocus *event, gpointer data); 67 static gboolean onNickListButtonPress_gui(GtkWidget *widget, GdkEventButton *event, gpointer data); 68 static gboolean onNickListButtonRelease_gui(GtkWidget *widget, GdkEventButton *event, gpointer data); 69 static gboolean onNickListKeyRelease_gui(GtkWidget *widget, GdkEventKey *event, gpointer data); 70 static gboolean onNickListSearch_gui(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer data); 71 static gboolean onEntryKeyPress_gui(GtkWidget *widget, GdkEventKey *event, gpointer data); 72 static gboolean onNickTagEvent_gui(GtkTextTag *tag, GObject *textView, GdkEvent *event, GtkTextIter *iter, gpointer data); 73 static gboolean onLinkTagEvent_gui(GtkTextTag *tag, GObject *textView, GdkEvent *event, GtkTextIter *iter, gpointer data); 74 static gboolean onHubTagEvent_gui(GtkTextTag *tag, GObject *textView, GdkEvent *event, GtkTextIter *iter, gpointer data); 75 static gboolean onMagnetTagEvent_gui(GtkTextTag *tag, GObject *textView, GdkEvent *event, GtkTextIter *iter, gpointer data); 76 static gboolean onChatPointerMoved_gui(GtkWidget *widget, GdkEventMotion *event, gpointer data); 77 static gboolean onChatVisibilityChanged_gui(GtkWidget *widget, GdkEventVisibility *event, gpointer data); 78 static void onChatScroll_gui(GtkAdjustment *adjustment, gpointer data); 79 static void onChatResize_gui(GtkAdjustment *adjustment, gpointer data); 80 static void onSendMessage_gui(GtkEntry *entry, gpointer data); 81 static void onCopyNickItemClicked_gui(GtkMenuItem *item, gpointer data); 82 static void onBrowseItemClicked_gui(GtkMenuItem *item, gpointer data); 83 static void onMatchItemClicked_gui(GtkMenuItem *item, gpointer data); 84 static void onMsgItemClicked_gui(GtkMenuItem *item, gpointer data); 85 static void onGrantItemClicked_gui(GtkMenuItem *item, gpointer data); 86 static void onRemoveUserItemClicked_gui(GtkMenuItem *item, gpointer data); 87 static void onCopyURIClicked_gui(GtkMenuItem *item, gpointer data); 88 static void onOpenLinkClicked_gui(GtkMenuItem *item, gpointer data); 89 static void onOpenHubClicked_gui(GtkMenuItem *item, gpointer data); 90 static void onSearchMagnetClicked_gui(GtkMenuItem *item, gpointer data); 91 static void onMagnetPropertiesClicked_gui(GtkMenuItem *item, gpointer data); 92 static void onAddFavoriteUserClicked_gui(GtkMenuItem *item, gpointer data); 93 94 // Client functions 95 void connectClient_client(std::string address, std::string encoding); 96 void disconnect_client(); 97 void setPassword_client(std::string password); 98 void sendMessage_client(std::string message, bool thirdPerson); 99 void getFileList_client(std::string cid, bool match); 100 void grantSlot_client(std::string cid); 101 void removeUserFromQueue_client(std::string cid); 102 void redirect_client(std::string address, bool follow); 103 void rebuildHashData_client(); 104 void refreshFileList_client(); 105 void addAsFavorite_client(); 106 void addFavoriteUser_client(const std::string cid); 107 void getParams_client(ParamMap ¶ms, const dcpp::Identity &id); 108 bool showJoins_client(const dcpp::UserPtr &user); 109 110 // Client callbacks 111 virtual void on(dcpp::ClientListener::Connecting, dcpp::Client *) throw(); 112 virtual void on(dcpp::ClientListener::Connected, dcpp::Client *) throw(); 113 virtual void on(dcpp::ClientListener::UserUpdated, dcpp::Client *, const dcpp::OnlineUser &user) throw(); 114 virtual void on(dcpp::ClientListener::UsersUpdated, dcpp::Client *, const dcpp::OnlineUserList &list) throw(); 115 virtual void on(dcpp::ClientListener::UserRemoved, dcpp::Client *, const dcpp::OnlineUser &user) throw(); 116 virtual void on(dcpp::ClientListener::Redirect, dcpp::Client *, const std::string &address) throw(); 117 virtual void on(dcpp::ClientListener::Failed, dcpp::Client *, const std::string &reason) throw(); 118 virtual void on(dcpp::ClientListener::GetPassword, dcpp::Client *) throw(); 119 virtual void on(dcpp::ClientListener::HubUpdated, dcpp::Client *) throw(); 120 virtual void on(dcpp::ClientListener::Message, dcpp::Client *, const dcpp::OnlineUser &user, const std::string &message, bool thirdPerson) throw(); 121 virtual void on(dcpp::ClientListener::StatusMessage, dcpp::Client *, const std::string &message, int flag) throw(); 122 virtual void on(dcpp::ClientListener::PrivateMessage, dcpp::Client *, const dcpp::OnlineUser &from, 123 const dcpp::OnlineUser &to, const dcpp::OnlineUser &replyTo, const std::string &message, bool thirdPerson) throw(); 124 virtual void on(dcpp::ClientListener::NickTaken, dcpp::Client *) throw(); 125 virtual void on(dcpp::ClientListener::SearchFlood, dcpp::Client *, const std::string &message) throw(); 126 127 std::tr1::unordered_map<std::string, std::string> userMap; 128 std::tr1::unordered_map<std::string, GtkTreeIter> userIters; 129 std::string completionKey; 130 dcpp::Client *client; 131 TreeView nickView; 132 GtkListStore *nickStore; 133 GtkTreeSelection *nickSelection; 134 GtkTextBuffer *chatBuffer; 135 GtkTextMark *chatMark; 136 gint oldType; 137 std::vector<std::string> history; 138 int historyIndex; 139 static const int maxLines = 1000; 140 static const int maxHistory = 20; 141 int64_t totalShared; 142 GdkCursor *handCursor; 143 GtkTextTag *selectedTag; 144 std::string selectedTagStr; 145 UserCommandMenu *userCommandMenu; 146 std::string address; 147 std::string encoding; 148 bool scrollToBottom; 149 }; 150 151 #else 152 class Hub; 153 #endif 154