1/*
2 * This file Copyright (C) Mnemosyne LLC
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 version 2
6 * as published by the Free Software Foundation.
7 *
8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9 *
10 * $Id: mainwin.h 13446 2012-08-19 00:01:54Z jordan $
11 */
12
13#ifndef MAIN_WINDOW_H
14#define MAIN_WINDOW_H
15
16#include <ctime>
17#include <QCheckBox>
18#include <QLineEdit>
19#include <QIcon>
20#include <QMainWindow>
21#include <QMap>
22#include <QPushButton>
23#include <QSet>
24#include <QSystemTrayIcon>
25#include <QTimer>
26#include <QWidgetList>
27
28extern "C" {
29    struct tr_benc;
30};
31
32#include "filters.h"
33#include "torrent-filter.h"
34#include "ui_mainwin.h"
35
36class ActionDelegator;
37class Prefs;
38class Details;
39class Session;
40class TorrentDelegate;
41class TorrentDelegateMin;
42class TorrentModel;
43class QAction;
44class QLabel;
45class QMenu;
46class QModelIndex;
47class QSortFilterProxyModel;
48class Filterbar;
49
50class TrMainWindow: public QMainWindow
51{
52        Q_OBJECT
53
54    private:
55        virtual void closeEvent( QCloseEvent * event );
56
57    private:
58        time_t myLastFullUpdateTime;
59        QDialog * mySessionDialog;
60        QDialog * myPrefsDialog;
61        QDialog * myAboutDialog;
62        QDialog * myStatsDialog;
63        Details * myDetailsDialog;
64        QCheckBox * myFileDialogOptionsCheck;
65        QSystemTrayIcon myTrayIcon;
66        TorrentFilter myFilterModel;
67        TorrentDelegate * myTorrentDelegate;
68        TorrentDelegateMin * myTorrentDelegateMin;
69        Session& mySession;
70        Prefs& myPrefs;
71        TorrentModel& myModel;
72        Ui_MainWindow ui;
73        QIcon mySpeedModeOffIcon;
74        QIcon mySpeedModeOnIcon;
75        time_t myLastSendTime;
76        time_t myLastReadTime;
77        QTimer myNetworkTimer;
78        QTimer myRefreshTrayIconTimer;
79        QTimer myRefreshActionSensitivityTimer;
80        QAction * myDlimitOffAction;
81        QAction * myDlimitOnAction;
82        QAction * myUlimitOffAction;
83        QAction * myUlimitOnAction;
84        QAction * myRatioOffAction;
85        QAction * myRatioOnAction;
86
87    private:
88        QIcon getStockIcon( const QString&, int fallback=-1 );
89
90    private:
91        QSet<int> getSelectedTorrents( ) const;
92        void updateNetworkIcon( );
93        QWidgetList myHidden;
94
95    public slots:
96        void openURL( QString );
97
98    private slots:
99        void onPrefsDestroyed( );
100        void openPreferences( );
101        void onDetailsDestroyed( );
102        void showTotalRatio( );
103        void showTotalTransfer( );
104        void showSessionRatio( );
105        void showSessionTransfer( );
106        void refreshVisibleCount( );
107        void refreshTitle( );
108        void refreshStatusBar( );
109        void refreshTrayIcon( );
110        void refreshTrayIconSoon( );
111        void openTorrent( );
112        void openURL( );
113        void newTorrent( );
114        void trayActivated( QSystemTrayIcon::ActivationReason );
115        void refreshPref( int key );
116        void addTorrents( const QStringList& filenames );
117        void removeTorrents( const bool deleteFiles );
118        void openDonate( );
119        void openHelp( );
120        void openFolder( );
121        void copyMagnetLinkToClipboard( );
122        void setLocation( );
123        void openProperties( );
124        void toggleSpeedMode( );
125        void dataReadProgress( );
126        void dataSendProgress( );
127        void toggleWindows( bool doShow );
128        void onSetPrefs( );
129        void onSetPrefs( bool );
130        void onSessionSourceChanged( );
131        void onModelReset( );
132
133    private slots:
134        void setSortPref             ( int );
135        void setSortAscendingPref    ( bool );
136        void onSortByActivityToggled ( bool );
137        void onSortByAgeToggled      ( bool );
138        void onSortByETAToggled      ( bool );
139        void onSortByNameToggled     ( bool );
140        void onSortByProgressToggled ( bool );
141        void onSortByQueueToggled    ( bool );
142        void onSortByRatioToggled    ( bool );
143        void onSortBySizeToggled     ( bool );
144        void onSortByStateToggled    ( bool );
145
146    private:
147        QWidget * myFilterBar;
148
149    private:
150        QMenu * createOptionsMenu( void );
151        QWidget * createStatusBar( void );
152        QWidget * myStatusBar;
153        QPushButton * myAltSpeedButton;
154        QAction * myAltSpeedAction;
155        QPushButton * myOptionsButton;
156        QLabel * myVisibleCountLabel;
157        QPushButton * myStatsModeButton;
158        QLabel * myStatsLabel;
159        QLabel * myDownloadSpeedLabel;
160        QLabel * myUploadSpeedLabel;
161        QLabel * myNetworkLabel;
162
163    public slots:
164        void startAll( );
165        void startSelected( );
166        void startSelectedNow( );
167        void pauseAll( );
168        void pauseSelected( );
169        void removeSelected( );
170        void deleteSelected( );
171        void verifySelected( );
172        void queueMoveTop( );
173        void queueMoveUp( );
174        void queueMoveDown( );
175        void queueMoveBottom( );
176        void reannounceSelected( );
177        void addTorrent( const QString& filename );
178        void onNetworkTimer( );
179
180    private:
181        void clearSelection( );
182
183    public slots:
184        void setToolbarVisible( bool );
185        void setFilterbarVisible( bool );
186        void setStatusbarVisible( bool );
187        void setCompactView( bool );
188        void refreshActionSensitivity( );
189        void refreshActionSensitivitySoon( );
190        void wrongAuthentication( );
191
192    public:
193        TrMainWindow( Session&, Prefs&, TorrentModel&, bool minized );
194        virtual ~TrMainWindow( );
195
196    protected:
197        virtual void contextMenuEvent( QContextMenuEvent * );
198        virtual void dragEnterEvent( QDragEnterEvent * );
199        virtual void dropEvent( QDropEvent * );
200};
201
202#endif
203