Added build script of Debian
[qtrapids] / src / client / MainWindow.h
1 /***************************************************************************
2  *   Copyright (C) 2010 by Ixonos Plc   *
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; version 2 of the License.               *
7  *                                                                         *
8  *   This program is distributed in the hope that it will be useful,       *
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
11  *   GNU General Public License for more details.                          *
12  *                                                                         *
13  *   You should have received a copy of the GNU General Public License     *
14  *   along with this program; if not, write to the                         *
15  *   Free Software Foundation, Inc.,                                       *
16  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
17  ***************************************************************************/
18 #ifndef MAINWINDOW_H
19 #define MAINWINDOW_H
20
21 #include <QMainWindow>
22 #include <QSettings>
23
24 #include "PluginInterface.h"
25 #include "proxy.h"
26
27 class QTabWidget;
28 class DownloadView;
29 class PreferencesDialog;
30
31 namespace qtrapids
32 {
33
34 class SeedView;
35
36 /**
37    @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
38 */
39 class MainWindow : public QMainWindow, public PluginHostInterface 
40 {
41
42         Q_OBJECT;
43
44 public:
45
46         MainWindow();
47         virtual ~MainWindow();
48
49         // Implemented from PluginHostInterface
50         virtual bool setGui(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE, qtrapids::PluginInterface* plugin = NULL);
51         virtual void addPluginWidget(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
52         virtual void addToolbar(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
53         virtual void addToolItem(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
54         virtual void addMenu(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
55         virtual void addMenuItem(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE);
56         virtual bool eventRequest(QVariant param, PluginRequest req = UNKNOWN_REQUEST);
57         
58         void RestoreSettings();
59
60         void connectToServer() {
61                 qDBusRegisterMetaType<qtrapids::TorrentState>();
62                 qDBusRegisterMetaType<qtrapids::ParamsMap_t>();
63
64                 connect(&server_
65                         , SIGNAL(alert(qtrapids::TorrentState
66                                        , qtrapids::ParamsMap_t))
67                         , this
68                         , SLOT(on_alert(qtrapids::TorrentState
69                                      , qtrapids::ParamsMap_t)));
70                 // Request server state. 
71                 // NOTE: This call starts qtrapids-server automatically with the GUI, 
72                 // if the .service file is in /usr/share/dbus-1/services/
73                 server_.getState();
74         }
75
76 signals:
77         void itemSelected(bool enabled);
78
79 public slots:
80 private slots:
81         void on_openAction_clicked();
82         void on_removeAction_clicked();
83         void on_quitAction_clicked();
84         void on_startDaemonAction_clicked();
85         void on_stopDaemonAction_clicked();
86         void on_serverTerminated();
87         void on_columnsAction_clicked();
88         void on_preferencesAction_clicked();
89         void on_aboutAction_clicked();
90         void on_aboutQtAction_clicked();
91         void on_tabWidget_tabCloseRequested(int index);
92         void on_downloadItemSelectionChanged();
93         void on_seedItemSelectionChanged();
94         void handleToolBarAction(QAction* action);
95         void on_torrentFileSelected(QString file);
96         void on_alert(qtrapids::TorrentState, qtrapids::ParamsMap_t);
97
98         
99 private:
100         void LoadPlugins();
101         void StartTorrentFromBufferData(char const* data, int size);
102                 
103 private:
104         QTabWidget *tabWidget_;
105         DownloadView *dlView_;
106         SeedView *seedView_;
107         QWidget *searchWidget_;
108         QAction *startDaemonAction_, *stopDaemonAction_;
109         PreferencesDialog *preferencesDialog_;
110         QSettings settings_;
111         QList<QDir> pluginDirs_;
112         QStringList pluginFileNames_;
113
114
115         //std::vector< std::auto_ptr<QTorrentHandle> const > torrentHandles_;
116
117         QtRapidsServer server_;
118
119
120         //bool IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr);
121 };
122
123 } // namespace qtrapids
124
125 #endif