1 /* 2 SPDX-FileCopyrightText: 2007 Joris Guisson <joris.guisson@gmail.com> 3 SPDX-FileCopyrightText: 2007 Ivan Vasic <ivasic@gmail.com> 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #ifndef KT_GUI_HH 8 #define KT_GUI_HH 9 10 #include <KParts/MainWindow> 11 #include <KSharedConfig> 12 #include <QTimer> 13 14 #include <interfaces/guiinterface.h> 15 #include <util/constants.h> 16 17 class QAction; 18 class KToggleAction; 19 20 namespace kt 21 { 22 class Core; 23 class PrefDialog; 24 class StatusBar; 25 class TrayIcon; 26 class DBus; 27 class TorrentActivity; 28 class CentralWidget; 29 30 class GUI : public KParts::MainWindow, public GUIInterface 31 { 32 Q_OBJECT 33 public: 34 GUI(); 35 ~GUI() override; 36 getDBusInterface()37 DBus *getDBusInterface() 38 { 39 return dbus_iface; 40 } 41 42 // Stuff implemented from GUIInterface getMainWindow()43 KMainWindow *getMainWindow() override 44 { 45 return this; 46 } 47 void addPrefPage(PrefPageInterface *page) override; 48 void removePrefPage(PrefPageInterface *page) override; 49 void mergePluginGui(Plugin *p) override; 50 void removePluginGui(Plugin *p) override; 51 void errorMsg(const QString &err) override; 52 void errorMsg(KIO::Job *j) override; 53 void infoMsg(const QString &info) override; 54 StatusBarInterface *getStatusBar() override; 55 void addActivity(Activity *act) override; 56 void removeActivity(Activity *act) override; 57 TorrentActivityInterface *getTorrentActivity() override; 58 QSize sizeHint() const override; 59 60 bool event(QEvent *e) override; 61 62 /** 63 * Create a XML GUI container (menu or toolbar) 64 * @param name The name of the item 65 * @return The widget 66 */ 67 QWidget *container(const QString &name); 68 69 /// load a torrent 70 void load(const QUrl &url); 71 72 /// load a torrent silently 73 void loadSilently(const QUrl &url); 74 75 public Q_SLOTS: 76 /// Update all actions 77 void updateActions(); 78 79 /** 80 * Enable or disable the paste action 81 * @param on Set on 82 */ 83 void setPasteDisabled(bool on); 84 85 /// Set the current activity 86 void setCurrentActivity(Activity *act) override; 87 88 private Q_SLOTS: 89 void createTorrent(); 90 void openTorrent(bool silently = false); openTorrentSilently()91 void openTorrentSilently() 92 { 93 openTorrent(true); 94 } 95 void pasteURL(); 96 void paste(); 97 void showPrefDialog(); 98 void showIPFilter(); 99 void configureKeys(); 100 void configureToolbars() override; 101 void newToolBarConfig(); 102 void import(); 103 void update(); 104 /// apply gui specific settings 105 void applySettings(); 106 void showOrHide(); 107 void configureNotifications(); 108 void activePartChanged(KParts::Part *p); 109 void quit(); 110 111 private: 112 void setupActions(); 113 114 void loadState(KSharedConfigPtr cfg); 115 void saveState(KSharedConfigPtr cfg); 116 bool queryClose() override; 117 118 private: 119 Core *core; 120 QTimer timer; 121 kt::StatusBar *status_bar; 122 TrayIcon *tray_icon; 123 DBus *dbus_iface; 124 TorrentActivity *torrent_activity; 125 CentralWidget *central; 126 PrefDialog *pref_dlg; 127 KParts::PartManager *part_manager; 128 129 KToggleAction *show_status_bar_action; 130 KToggleAction *show_menu_bar_action; 131 QAction *open_silently_action; 132 133 QAction *paste_url_action; 134 QAction *ipfilter_action; 135 QAction *import_action; 136 QAction *show_kt_action; 137 QAction *paste_action; 138 }; 139 } 140 141 #endif 142