2006-09-30 20:02:39 +04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GUI_H
|
|
|
|
#define GUI_H
|
|
|
|
|
|
|
|
#include <QMainWindow>
|
2006-12-03 20:27:29 +03:00
|
|
|
#include <QHash>
|
2006-09-30 20:02:39 +04:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QTcpServer>
|
|
|
|
#include <QTcpSocket>
|
2006-10-18 23:53:54 +04:00
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QSystemTrayIcon>
|
2006-09-30 20:02:39 +04:00
|
|
|
|
|
|
|
#include <libtorrent/entry.hpp>
|
|
|
|
#include <libtorrent/bencode.hpp>
|
|
|
|
#include <libtorrent/session.hpp>
|
|
|
|
#include <libtorrent/fingerprint.hpp>
|
|
|
|
#include <libtorrent/session_settings.hpp>
|
|
|
|
#include <libtorrent/identify_client.hpp>
|
|
|
|
#include <libtorrent/alert_types.hpp>
|
|
|
|
|
|
|
|
#include "ui_MainWindow.h"
|
|
|
|
#include "options_imp.h"
|
|
|
|
#include "about_imp.h"
|
|
|
|
#include "previewSelect.h"
|
|
|
|
#include "trackerLogin.h"
|
|
|
|
|
2006-10-19 00:40:40 +04:00
|
|
|
#define TIME_TRAY_BALLOON 5000
|
|
|
|
|
2006-09-30 20:02:39 +04:00
|
|
|
class createtorrent;
|
|
|
|
class QTimer;
|
|
|
|
class DLListDelegate;
|
|
|
|
class SearchListDelegate;
|
|
|
|
class downloadThread;
|
|
|
|
class downloadFromURL;
|
|
|
|
|
|
|
|
using namespace libtorrent;
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
|
|
|
class GUI : public QMainWindow, private Ui::MainWindow{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Bittorrent
|
|
|
|
session *s;
|
|
|
|
std::pair<unsigned short, unsigned short> listenPorts;
|
2006-12-03 20:27:29 +03:00
|
|
|
QHash<QString, torrent_handle> handles;
|
2006-09-30 20:02:39 +04:00
|
|
|
QTimer *checkConnect;
|
|
|
|
QTimer *timerScan;
|
2006-12-03 20:27:29 +03:00
|
|
|
QHash<QString, QStringList> trackerErrors;
|
2006-09-30 20:02:39 +04:00
|
|
|
trackerLogin *tracker_login;
|
|
|
|
QList<QPair<torrent_handle,std::string> > unauthenticated_trackers;
|
|
|
|
downloadThread *downloader;
|
|
|
|
downloadFromURL *downloadFromURLDialog;
|
|
|
|
bool DHTEnabled;
|
|
|
|
// GUI related
|
|
|
|
options_imp *options;
|
|
|
|
createtorrent *createWindow;
|
|
|
|
QTimer *refresher;
|
2006-10-18 23:53:54 +04:00
|
|
|
QSystemTrayIcon *myTrayIcon;
|
2006-09-30 20:02:39 +04:00
|
|
|
QMenu *myTrayIconMenu;
|
|
|
|
about *aboutdlg;
|
|
|
|
QStandardItemModel *DLListModel;
|
|
|
|
DLListDelegate *DLDelegate;
|
|
|
|
QStandardItemModel *SearchListModel;
|
|
|
|
SearchListDelegate *SearchDelegate;
|
|
|
|
QStringList supported_preview_extensions;
|
2006-10-03 04:11:35 +04:00
|
|
|
unsigned int nbTorrents;
|
2006-10-23 00:13:35 +04:00
|
|
|
QLabel *connecStatusLblIcon;
|
2006-09-30 20:02:39 +04:00
|
|
|
// Preview
|
|
|
|
previewSelect *previewSelection;
|
|
|
|
QProcess *previewProcess;
|
|
|
|
// Search related
|
2006-12-03 20:27:29 +03:00
|
|
|
QHash<QString, QString> searchResultsUrls;
|
2006-09-30 20:02:39 +04:00
|
|
|
QProcess *searchProcess;
|
|
|
|
bool search_stopped;
|
|
|
|
bool no_search_results;
|
|
|
|
QByteArray search_result_line_truncated;
|
|
|
|
unsigned long nb_search_results;
|
2006-12-05 03:27:00 +03:00
|
|
|
QTcpServer tcpServer;
|
2006-09-30 20:02:39 +04:00
|
|
|
QTcpSocket *clientConnection;
|
|
|
|
|
|
|
|
protected slots:
|
|
|
|
// GUI related slots
|
|
|
|
void dropEvent(QDropEvent *event);
|
|
|
|
void dragEnterEvent(QDragEnterEvent *event);
|
2006-10-18 23:53:54 +04:00
|
|
|
void toggleVisibility(QSystemTrayIcon::ActivationReason e);
|
2006-09-30 20:02:39 +04:00
|
|
|
void showAbout();
|
|
|
|
void setInfoBar(const QString& info, const QString& color="black");
|
|
|
|
void updateDlList();
|
|
|
|
void showCreateWindow();
|
|
|
|
void clearLog();
|
2006-12-05 03:27:00 +03:00
|
|
|
void readParamsOnSocket();
|
|
|
|
void acceptConnection();
|
2006-09-30 20:02:39 +04:00
|
|
|
void saveCheckedSearchEngines(int) const;
|
|
|
|
void saveColWidthDLList() const;
|
|
|
|
void saveColWidthSearchList() const;
|
|
|
|
void loadCheckedSearchEngines();
|
|
|
|
bool loadColWidthDLList();
|
|
|
|
bool loadColWidthSearchList();
|
|
|
|
void sortDownloadList(int index);
|
|
|
|
void sortDownloadListFloat(int index, Qt::SortOrder sortOrder);
|
|
|
|
void sortDownloadListString(int index, Qt::SortOrder sortOrder);
|
|
|
|
void sortSearchList(int index);
|
|
|
|
void sortSearchListInt(int index, Qt::SortOrder sortOrder);
|
|
|
|
void sortSearchListString(int index, Qt::SortOrder sortOrder);
|
|
|
|
void displayDLListMenu(const QPoint& pos);
|
|
|
|
void selectGivenRow(const QModelIndex& index);
|
|
|
|
void togglePausedState(const QModelIndex& index);
|
|
|
|
void displayInfoBarMenu(const QPoint& pos);
|
|
|
|
void displayGUIMenu(const QPoint& pos);
|
|
|
|
void previewFileSelection();
|
|
|
|
void previewFile(const QString& filePath);
|
|
|
|
void cleanTempPreviewFile(int, QProcess::ExitStatus);
|
2006-10-19 00:40:40 +04:00
|
|
|
void balloonClicked();
|
2006-11-14 19:46:05 +03:00
|
|
|
void writeSettings();
|
|
|
|
void readSettings();
|
2006-09-30 20:02:39 +04:00
|
|
|
// Torrent actions
|
|
|
|
void showProperties(const QModelIndex &index);
|
|
|
|
void propertiesSelection();
|
2006-10-24 01:42:37 +04:00
|
|
|
void addTorrent(const QString& path, bool fromScanDir = false, const QString& from_url = QString());
|
2006-09-30 20:02:39 +04:00
|
|
|
void pauseAll();
|
|
|
|
void startAll();
|
|
|
|
void pauseSelection();
|
|
|
|
void startSelection();
|
|
|
|
void askForTorrents();
|
2006-10-29 13:17:53 +03:00
|
|
|
void deletePermanently();
|
2006-09-30 20:02:39 +04:00
|
|
|
void deleteSelection();
|
|
|
|
void resumeUnfinished();
|
|
|
|
void saveFastResumeData() const;
|
|
|
|
void checkConnectionStatus();
|
|
|
|
void scanDirectory();
|
|
|
|
void setGlobalRatio(float ratio);
|
|
|
|
void configureSession();
|
2006-10-24 01:42:37 +04:00
|
|
|
void processParams(const QStringList& params);
|
2006-09-30 20:02:39 +04:00
|
|
|
void addUnauthenticatedTracker(QPair<torrent_handle,std::string> tracker);
|
|
|
|
void processDownloadedFile(QString url, QString file_path, int return_code, QString errorBuffer);
|
|
|
|
void downloadFromURLList(const QStringList& url_list);
|
2006-10-08 05:01:34 +04:00
|
|
|
bool loadFilteredFiles(torrent_handle &h);
|
|
|
|
bool hasFilteredFiles(const QString& fileName);
|
2006-10-06 22:07:01 +04:00
|
|
|
void reloadTorrent(const torrent_handle &h, bool compact_mode = true);
|
2006-09-30 20:02:39 +04:00
|
|
|
// Search slots
|
|
|
|
void on_search_button_clicked();
|
|
|
|
void on_stop_search_button_clicked();
|
|
|
|
void on_clear_button_clicked();
|
|
|
|
void on_download_button_clicked();
|
|
|
|
void on_update_nova_button_clicked();
|
|
|
|
void appendSearchResult(const QString& line);
|
|
|
|
void searchFinished(int exitcode,QProcess::ExitStatus);
|
|
|
|
void readSearchOutput();
|
|
|
|
void searchStarted();
|
|
|
|
void downloadSelectedItem(const QModelIndex& index);
|
|
|
|
// Utils slots
|
|
|
|
void setRowColor(int row, const QString& color, bool inDLList=true);
|
|
|
|
// Options slots
|
|
|
|
void showOptions() const;
|
|
|
|
void OptionsSaved(const QString& info);
|
|
|
|
// HTTP slots
|
|
|
|
void downloadFromUrl(const QString& url);
|
|
|
|
void askForTorrentUrl();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void setLocale(QString locale);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void closeEvent(QCloseEvent *);
|
|
|
|
void hideEvent(QHideEvent *);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Construct / Destruct
|
|
|
|
GUI(QWidget *parent=0, QStringList torrentCmdLine=QStringList());
|
|
|
|
~GUI();
|
|
|
|
// Methods
|
|
|
|
int getRowFromName(const QString& name) const;
|
|
|
|
float getNovaVersion(const QString& novaPath) const;
|
|
|
|
QByteArray getNovaChangelog(const QString& novaPath) const;
|
|
|
|
void updateNova() const;
|
|
|
|
bool isFilePreviewPossible(const torrent_handle& h) const;
|
2006-10-24 01:42:37 +04:00
|
|
|
QString getSavePath(QString fileName);
|
2006-11-14 19:46:05 +03:00
|
|
|
QPoint screenCenter();
|
2006-09-30 20:02:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|