1 /*************************************************************************** 2 * * 3 * This program is free software; you can redistribute it and/or modify * 4 * it under the terms of the GNU General Public License as published by * 5 * the Free Software Foundation; either version 3 of the License, or * 6 * (at your option) any later version. * 7 * * 8 ***************************************************************************/ 9 10 #pragma once 11 12 #include <QApplication> 13 #include <QWidget> 14 #include <QMainWindow> 15 #include <QList> 16 #include <QMenuBar> 17 #include <QMenu> 18 #include <QCloseEvent> 19 #include <QShowEvent> 20 #include <QTabBar> 21 #include <QToolBar> 22 #include <QHash> 23 #include <QSessionManager> 24 25 26 #include "dcpp/stdinc.h" 27 #include "dcpp/ConnectionManager.h" 28 #include "dcpp/DownloadManager.h" 29 #include "dcpp/LogManager.h" 30 #include "dcpp/QueueManager.h" 31 #include "dcpp/TimerManager.h" 32 #include "dcpp/UploadManager.h" 33 #include "dcpp/FavoriteManager.h" 34 #include "dcpp/ShareManager.h" 35 #include "dcpp/SettingsManager.h" 36 #include "dcpp/Download.h" 37 #include "dcpp/Util.h" 38 #include "dcpp/version.h" 39 40 #include "ArenaWidget.h" 41 #include "HistoryInterface.h" 42 #include "LineEdit.h" 43 #include "ShortcutManager.h" 44 45 #include "ui_UIAbout.h" 46 47 class FavoriteHubs; 48 class DownloadQueue; 49 class ToolBar; 50 class MainWindow; 51 class MultiLineToolBar; 52 #ifdef USE_JS 53 class ScriptConsole; 54 #endif 55 56 extern const char * const EISKALTDCPP_VERSION; 57 extern const char * const EISKALTDCPP_WND_TITLE; 58 extern const char * const EISKALTDCPP_VERSION_SFX; 59 60 class QProgressBar; 61 62 class About: 63 public QDialog, 64 public Ui::UIAbout 65 { 66 Q_OBJECT 67 68 public: QDialog(parent)69 About(QWidget *parent = NULL): QDialog(parent){ setupUi(this); } 70 printHelp()71 void printHelp() const { 72 QString msg = tr("Using:\n" 73 " eiskaltdcpp-qt <magnet link> <dchub://link> <adc(s)://link>\n" 74 " eiskaltdcpp-qt <Key>\n" 75 "EiskaltDC++ is a cross-platform program that uses the Direct Connect and ADC protocol.\n" 76 "\n" 77 "Keys:\n" 78 " -h, --help\t Show this message\n" 79 " -V, --version\t Show version string" 80 ); 81 82 printf("%s\n", msg.toUtf8().constData()); 83 } 84 printVersion()85 void printVersion() const { 86 printf("%s (%s)\n", EISKALTDCPP_VERSION, EISKALTDCPP_VERSION_SFX); 87 } 88 }; 89 90 class HashProgress; 91 class MainWindowPrivate; 92 93 class MainWindow: 94 public QMainWindow, 95 public dcpp::Singleton<MainWindow>, 96 private dcpp::LogManagerListener, 97 private dcpp::TimerManagerListener, 98 private dcpp::QueueManagerListener 99 { 100 Q_OBJECT 101 102 friend class dcpp::Singleton<MainWindow>; 103 104 public: 105 106 typedef QList<QAction*> ActionList; 107 108 Q_PROPERTY (QObject* ToolBar READ getToolBar); 109 Q_PROPERTY (QMenuBar* MenuBar READ menuBar); 110 111 void beginExit(); 112 113 /** */ 114 void newHubFrame(QString, QString); 115 116 /** */ 117 void browseOwnFiles(); 118 119 /** */ 120 void startSocket(bool changed); 121 /** */ 122 void showPortsError(const std::string& port); 123 /** */ 124 void autoconnect(); 125 /** */ 126 void retranslateUi(); 127 128 /** */ 129 void reloadSomeSettings(); 130 131 /** */ 132 void setUnload(bool b); 133 134 ArenaWidget *widgetForRole(ArenaWidget::Role) const; 135 136 Q_SIGNALS: 137 void redrawWidgetPanels(); 138 139 public Q_SLOTS: 140 QObject *getToolBar(); 141 142 /** */ 143 void addActionOnToolBar(QAction*); 144 /** */ 145 void remActionFromToolBar(QAction*); 146 147 /** */ 148 void toggleMainMenu(bool); 149 150 void slotChatClear(); 151 152 /** */ 153 void redrawToolPanel(); 154 155 /** */ 156 void setStatusMessage(QString); 157 158 /** */ 159 void show(); 160 161 /** */ 162 void parseCmdLine(const QStringList &); 163 /** */ 164 void parseInstanceLine(QString); 165 166 protected: 167 virtual void closeEvent(QCloseEvent*); 168 virtual void showEvent(QShowEvent *); 169 virtual void hideEvent(QHideEvent *); 170 virtual bool eventFilter(QObject *, QEvent *); 171 172 private Q_SLOTS: 173 /** Show widget on arena */ 174 void mapWidgetOnArena(ArenaWidget*); 175 void removeWidget(ArenaWidget *awgt); 176 void insertWidget(ArenaWidget *awgt); 177 void updated(ArenaWidget *awgt); 178 179 void slotOpenMagnet(); 180 void slotFileOpenLogFile(); 181 void slotFileOpenDownloadDirectory(); 182 void slotFileBrowseFilelist(); 183 void slotFileHasher(); 184 void slotFileBrowseOwnFilelist(); 185 void slotFileMatchAllList(); 186 void slotFileHashProgress(); 187 void slotFileRefreshShareHashProgress(); 188 void slotHubsReconnect(); 189 void slotHubsFavoriteHubs(); 190 void slotHubsPublicHubs(); 191 void slotHubsFavoriteUsers(); 192 void slotToolsDownloadQueue(); 193 void slotToolsQueuedUsers(); 194 void slotToolsHubManager(); 195 void slotToolsFinishedDownloads(); 196 void slotToolsFinishedUploads(); 197 void slotToolsSpy(); 198 void slotToolsAntiSpam(); 199 void slotToolsIPFilter(); 200 void slotToolsSwitchAway(); 201 void slotToolsAutoAway(); 202 void slotToolsSearch(); 203 void slotToolsADLS(); 204 void slotToolsCmdDebug(); 205 void slotToolsCopyWindowTitle(); 206 void slotToolsSettings(); 207 void slotToolsJS(); 208 void slotToolsJSConsole(); 209 void slotJSFileChanged(const QString&); 210 void slotToolsTransfer(bool); 211 void slotToolsSwitchSpeedLimit(); 212 void slotPanelMenuActionClicked(); 213 void slotWidgetsToggle(); 214 void slotQC(); 215 void slotHideMainMenu(); 216 void slotShowMainMenu(); 217 void slotHideWindow(); 218 void slotHideProgressSpace(); 219 void slotHideLastStatus(); 220 void slotHideUsersStatistics(); 221 void slotSideBarDockMenu(); 222 void slotExit(); 223 void slotToolbarCustomization(); 224 void slotToolbarCustomizerDone(const QList<QAction*> &enabled); 225 226 void slotCloseCurrentWidget(); 227 228 void slotUnixSignal(int); 229 230 void nextMsg(); 231 void prevMsg(); 232 233 void slotFind(); 234 void slotChatDisable(); 235 236 void slotAboutOpenUrl(); 237 void slotAboutClient(); 238 void slotAboutQt(); 239 240 void showShareBrowser(dcpp::UserPtr, const QString &, const QString&); 241 void updateStatus(const QMap<QString,QString> &); 242 243 void slotUpdateFavHubMenu(); 244 void slotConnectFavHub(QAction*); 245 246 // These slots are used only in Mac OS X. 247 // But due to bug in moc they cannot be placed in #ifdef block. 248 void slotShowSpeedLimits(); 249 void slotSuppressTxt(); 250 void slotSuppressSnd(); 251 // 252 253 Q_SIGNALS: 254 void coreLogMessage(const QString&); 255 void coreOpenShare(dcpp::UserPtr, const QString &, const QString&); 256 void coreUpdateStats(const QMap<QString, QString> &); 257 void notifyMessage(int, const QString&, const QString&); 258 259 private: 260 MainWindow (QWidget *parent=NULL); 261 virtual ~MainWindow(); 262 263 /** LogManagerListener */ 264 virtual void on(dcpp::LogManagerListener::Message, time_t t, const std::string&) noexcept; 265 /** TimerManagerListener */ 266 virtual void on(dcpp::TimerManagerListener::Second, uint64_t) noexcept; 267 /** QueueManagerListener */ 268 virtual void on(dcpp::QueueManagerListener::Finished, dcpp::QueueItem*, const std::string&, int64_t) noexcept; 269 270 // Interface setup functions 271 void init(); 272 void loadSettings(); 273 void saveSettings(); 274 void getWindowGeometry(); 275 276 void initActions(); 277 void initMenuBar(); 278 void initStatusBar(); 279 void initSearchBar(); 280 void initToolbar(); 281 void initSideBar(); 282 void initFavHubMenu(); 283 #if defined(Q_WS_MAC) 284 void initDockMenuBar(); 285 #endif 286 287 void toggleSingletonWidget(ArenaWidget *a); 288 289 void updateHashProgressStatus(); 290 291 Q_DECLARE_PRIVATE(MainWindow) 292 293 HashProgress *progress_dialog(); // Lazy initialization for _progress_dialog; 294 295 MainWindowPrivate *d_ptr; 296 }; 297 298 Q_DECLARE_METATYPE(MainWindow*) 299