1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-10 14:57:52 +00:00

- Cleanup GUI class

This commit is contained in:
Christophe Dumez 2010-03-03 14:42:57 +00:00
parent f1b02c1280
commit 6b4f09d740
2 changed files with 53 additions and 38 deletions

View File

@ -219,8 +219,12 @@ GUI::~GUI() {
delete status_bar; delete status_bar;
delete transferList; delete transferList;
delete guiUpdater; delete guiUpdater;
if (console) if(createTorrentDlg)
delete createTorrentDlg;
if(console)
delete console; delete console;
if(aboutDlg)
delete aboutDlg;
if(options) if(options)
delete options; delete options;
if(rssWidget) if(rssWidget)
@ -310,8 +314,8 @@ void GUI::finishedTorrent(QTorrentHandle& h) const {
// Notification when disk is full // Notification when disk is full
void GUI::fullDiskError(QTorrentHandle& h, QString msg) const { void GUI::fullDiskError(QTorrentHandle& h, QString msg) const {
if(!h.is_valid()) return; showNotificationBaloon(tr("I/O Error", "i.e: Input/Output Error"), tr("An I/O error occured for torrent %1.\n Reason: %2", "e.g: An error occured for torrent xxx.avi.\n Reason: disk is full.").arg(h.name()).arg(msg)); if(!h.is_valid()) return;
showNotificationBaloon(tr("I/O Error", "i.e: Input/Output Error"), tr("An I/O error occured for torrent %1.\n Reason: %2", "e.g: An error occured for torrent xxx.avi.\n Reason: disk is full.").arg(h.name()).arg(msg));
} }
void GUI::createKeyboardShortcuts() { void GUI::createKeyboardShortcuts() {
@ -357,7 +361,7 @@ void GUI::readSettings() {
settings.beginGroup(QString::fromUtf8("MainWindow")); settings.beginGroup(QString::fromUtf8("MainWindow"));
resize(settings.value(QString::fromUtf8("size"), size()).toSize()); resize(settings.value(QString::fromUtf8("size"), size()).toSize());
move(settings.value(QString::fromUtf8("pos"), misc::screenCenter(this)).toPoint()); move(settings.value(QString::fromUtf8("pos"), misc::screenCenter(this)).toPoint());
QStringList sizes_str = settings.value("vSplitterSizes", QStringList()).toStringList(); const QStringList &sizes_str = settings.value("vSplitterSizes", QStringList()).toStringList();
// Splitter size // Splitter size
QList<int> sizes; QList<int> sizes;
if(sizes_str.size() == 2) { if(sizes_str.size() == 2) {
@ -392,9 +396,9 @@ void GUI::acceptConnection() {
void GUI::readParamsOnSocket() { void GUI::readParamsOnSocket() {
QLocalSocket *clientConnection = static_cast<QLocalSocket*>(sender()); QLocalSocket *clientConnection = static_cast<QLocalSocket*>(sender());
if(clientConnection) { if(clientConnection) {
QByteArray params = clientConnection->readAll(); const QByteArray &params = clientConnection->readAll();
if(!params.isEmpty()) { if(!params.isEmpty()) {
processParams(QString::fromUtf8(params.data()).split(QString::fromUtf8("\n"))); processParams(QString::fromLocal8Bit(params.constData()).split("\n"));
qDebug("Received parameters from another instance"); qDebug("Received parameters from another instance");
} }
clientConnection->deleteLater(); clientConnection->deleteLater();
@ -409,7 +413,7 @@ void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{
void GUI::on_actionSet_global_upload_limit_triggered() { void GUI::on_actionSet_global_upload_limit_triggered() {
qDebug("actionSet_global_upload_limit_triggered"); qDebug("actionSet_global_upload_limit_triggered");
bool ok; bool ok;
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), BTSession->getSession()->upload_rate_limit()); const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), BTSession->getSession()->upload_rate_limit());
if(ok) { if(ok) {
qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.); qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.);
BTSession->getSession()->set_upload_rate_limit(new_limit); BTSession->getSession()->set_upload_rate_limit(new_limit);
@ -431,7 +435,7 @@ void GUI::on_actionShow_console_triggered() {
void GUI::on_actionSet_global_download_limit_triggered() { void GUI::on_actionSet_global_download_limit_triggered() {
qDebug("actionSet_global_download_limit_triggered"); qDebug("actionSet_global_download_limit_triggered");
bool ok; bool ok;
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), BTSession->getSession()->download_rate_limit()); const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), BTSession->getSession()->download_rate_limit());
if(ok) { if(ok) {
qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.);
BTSession->getSession()->set_download_rate_limit(new_limit); BTSession->getSession()->set_download_rate_limit(new_limit);
@ -482,7 +486,11 @@ void GUI::toggleVisibility(QSystemTrayIcon::ActivationReason e) {
// Display About Dialog // Display About Dialog
void GUI::on_actionAbout_triggered() { void GUI::on_actionAbout_triggered() {
//About dialog //About dialog
new about(this); if(aboutDlg) {
aboutDlg->setFocus();
} else {
aboutDlg = new about(this);
}
} }
void GUI::showEvent(QShowEvent *e) { void GUI::showEvent(QShowEvent *e) {
@ -497,9 +505,8 @@ void GUI::showEvent(QShowEvent *e) {
// Called when we close the program // Called when we close the program
void GUI::closeEvent(QCloseEvent *e) { void GUI::closeEvent(QCloseEvent *e) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool goToSystrayOnExit = settings.value(QString::fromUtf8("Preferences/General/CloseToTray"), false).toBool(); const bool goToSystrayOnExit = settings.value(QString::fromUtf8("Preferences/General/CloseToTray"), false).toBool();
if(!force_exit && systrayIcon && goToSystrayOnExit && !this->isHidden()) { if(!force_exit && systrayIcon && goToSystrayOnExit && !this->isHidden()) {
hide(); hide();
//e->ignore(); //e->ignore();
@ -510,7 +517,7 @@ void GUI::closeEvent(QCloseEvent *e) {
show(); show();
if(!isMaximized()) if(!isMaximized())
showNormal(); showNormal();
if(e->spontaneous() == true || force_exit == true) { if(e->spontaneous() || force_exit) {
if(QMessageBox::question(this, if(QMessageBox::question(this,
tr("Are you sure you want to quit?")+QString::fromUtf8(" -- ")+tr("qBittorrent"), tr("Are you sure you want to quit?")+QString::fromUtf8(" -- ")+tr("qBittorrent"),
tr("Some files are currently transferring.\nAre you sure you want to quit qBittorrent?"), tr("Some files are currently transferring.\nAre you sure you want to quit qBittorrent?"),
@ -537,8 +544,12 @@ void GUI::closeEvent(QCloseEvent *e) {
// Display window to create a torrent // Display window to create a torrent
void GUI::on_actionCreate_torrent_triggered() { void GUI::on_actionCreate_torrent_triggered() {
createtorrent *ct = new createtorrent(this); if(createTorrentDlg) {
connect(ct, SIGNAL(torrent_to_seed(QString)), this, SLOT(addTorrent(QString))); createTorrentDlg->setFocus();
} else {
createTorrentDlg = new createtorrent(this);
connect(createTorrentDlg, SIGNAL(torrent_to_seed(QString)), this, SLOT(addTorrent(QString)));
}
} }
bool GUI::event(QEvent * e) { bool GUI::event(QEvent * e) {
@ -560,9 +571,9 @@ void GUI::dropEvent(QDropEvent *event) {
event->acceptProposedAction(); event->acceptProposedAction();
QStringList files; QStringList files;
if(event->mimeData()->hasUrls()) { if(event->mimeData()->hasUrls()) {
QList<QUrl> urls = event->mimeData()->urls(); const QList<QUrl> &urls = event->mimeData()->urls();
foreach(const QUrl &url, urls) { foreach(const QUrl &url, urls) {
QString tmp = url.toString().trimmed(); const QString tmp = url.toString().trimmed();
if(!tmp.isEmpty()) if(!tmp.isEmpty())
files << url.toString(); files << url.toString();
} }
@ -571,7 +582,7 @@ void GUI::dropEvent(QDropEvent *event) {
} }
// Add file to download list // Add file to download list
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool(); const bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
foreach(QString file, files) { foreach(QString file, files) {
file = file.trimmed().replace(QString::fromUtf8("file://"), QString::fromUtf8(""), Qt::CaseInsensitive); file = file.trimmed().replace(QString::fromUtf8("file://"), QString::fromUtf8(""), Qt::CaseInsensitive);
qDebug("Dropped file %s on download list", file.toLocal8Bit().data()); qDebug("Dropped file %s on download list", file.toLocal8Bit().data());
@ -615,13 +626,13 @@ void GUI::on_actionOpen_triggered() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
// Open File Open Dialog // Open File Open Dialog
// Note: it is possible to select more than one file // Note: it is possible to select more than one file
QStringList pathsList = QFileDialog::getOpenFileNames(0, const QStringList &pathsList = QFileDialog::getOpenFileNames(0,
tr("Open Torrent Files"), settings.value(QString::fromUtf8("MainWindowLastDir"), QDir::homePath()).toString(), tr("Open Torrent Files"), settings.value(QString::fromUtf8("MainWindowLastDir"), QDir::homePath()).toString(),
tr("Torrent Files")+QString::fromUtf8(" (*.torrent)")); tr("Torrent Files")+QString::fromUtf8(" (*.torrent)"));
if(!pathsList.empty()) { if(!pathsList.empty()) {
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool(); const bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
unsigned int listSize = pathsList.size(); const uint listSize = pathsList.size();
for(unsigned int i=0; i<listSize; ++i) { for(uint i=0; i<listSize; ++i) {
if(useTorrentAdditionDialog) { if(useTorrentAdditionDialog) {
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession); torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession);
dialog->showLoad(pathsList.at(i)); dialog->showLoad(pathsList.at(i));
@ -642,7 +653,7 @@ void GUI::on_actionOpen_triggered() {
// the parameter type. // the parameter type.
void GUI::processParams(const QStringList& params) { void GUI::processParams(const QStringList& params) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool(); const bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
foreach(QString param, params) { foreach(QString param, params) {
param = param.trimmed(); param = param.trimmed();
if(param.startsWith("--")) continue; if(param.startsWith("--")) continue;
@ -674,7 +685,7 @@ void GUI::addTorrent(QString path) {
void GUI::processDownloadedFiles(QString path, QString url) { void GUI::processDownloadedFiles(QString path, QString url) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool(); const bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
if(useTorrentAdditionDialog) { if(useTorrentAdditionDialog) {
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession); torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession);
dialog->showLoad(path, url); dialog->showLoad(path, url);
@ -690,7 +701,7 @@ void GUI::optionsSaved() {
// Load program preferences // Load program preferences
void GUI::loadPreferences(bool configure_session) { void GUI::loadPreferences(bool configure_session) {
BTSession->addConsoleMessage(tr("Options were saved successfully.")); BTSession->addConsoleMessage(tr("Options were saved successfully."));
bool newSystrayIntegration = Preferences::systrayIntegration(); const bool newSystrayIntegration = Preferences::systrayIntegration();
if(newSystrayIntegration != (systrayIcon!=0)) { if(newSystrayIntegration != (systrayIcon!=0)) {
if(newSystrayIntegration) { if(newSystrayIntegration) {
// create the trayicon // create the trayicon
@ -714,7 +725,7 @@ void GUI::loadPreferences(bool configure_session) {
} }
} }
// General // General
bool new_displaySpeedInTitle = Preferences::speedInTitleBar(); const bool new_displaySpeedInTitle = Preferences::speedInTitleBar();
if(!new_displaySpeedInTitle && new_displaySpeedInTitle != displaySpeedInTitle) { if(!new_displaySpeedInTitle && new_displaySpeedInTitle != displaySpeedInTitle) {
// Reset title // Reset title
setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent vx.x").arg(QString::fromUtf8(VERSION))); setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent vx.x").arg(QString::fromUtf8(VERSION)));
@ -726,7 +737,7 @@ void GUI::loadPreferences(bool configure_session) {
} else { } else {
toolBar->setVisible(false); toolBar->setVisible(false);
} }
unsigned int new_refreshInterval = Preferences::getRefreshInterval(); const uint new_refreshInterval = Preferences::getRefreshInterval();
transferList->setRefreshInterval(new_refreshInterval); transferList->setRefreshInterval(new_refreshInterval);
transferList->setAlternatingRowColors(Preferences::useAlternatingRowColors()); transferList->setAlternatingRowColors(Preferences::useAlternatingRowColors());
properties->getFilesList()->setAlternatingRowColors(Preferences::useAlternatingRowColors()); properties->getFilesList()->setAlternatingRowColors(Preferences::useAlternatingRowColors());
@ -770,7 +781,7 @@ void GUI::loadPreferences(bool configure_session) {
qDebug("GUI settings loaded"); qDebug("GUI settings loaded");
} }
void GUI::addUnauthenticatedTracker(QPair<QTorrentHandle,QString> tracker) { void GUI::addUnauthenticatedTracker(const QPair<QTorrentHandle,QString> &tracker) {
// Trackers whose authentication was cancelled // Trackers whose authentication was cancelled
if(unauthenticated_trackers.indexOf(tracker) < 0) { if(unauthenticated_trackers.indexOf(tracker) < 0) {
unauthenticated_trackers << tracker; unauthenticated_trackers << tracker;
@ -791,18 +802,18 @@ void GUI::updateGUI() {
if(systrayIcon) { if(systrayIcon) {
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
// Windows does not support html here // Windows does not support html here
QString html =tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString(QByteArray::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1))); QString html =tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1));
html += "\n"; html += "\n";
html += tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString(QByteArray::number(BTSession->getPayloadUploadRate()/1024., 'f', 1))); html += tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::number(BTSession->getPayloadUploadRate()/1024., 'f', 1));
#else #else
QString html = "<div style='background-color: #678db2; color: #fff;height: 18px; font-weight: bold; margin-bottom: 5px;'>"; QString html = "<div style='background-color: #678db2; color: #fff;height: 18px; font-weight: bold; margin-bottom: 5px;'>";
html += tr("qBittorrent"); html += tr("qBittorrent");
html += "</div>"; html += "</div>";
html += "<div style='vertical-align: baseline; height: 18px;'>"; html += "<div style='vertical-align: baseline; height: 18px;'>";
html += "<img src=':/Icons/skin/download.png'/>&nbsp;"+tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString(QByteArray::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1))); html += "<img src=':/Icons/skin/download.png'/>&nbsp;"+tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1));
html += "</div>"; html += "</div>";
html += "<div style='vertical-align: baseline; height: 18px;'>"; html += "<div style='vertical-align: baseline; height: 18px;'>";
html += "<img src=':/Icons/skin/seeding.png'/>&nbsp;"+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString(QByteArray::number(BTSession->getPayloadUploadRate()/1024., 'f', 1))); html += "<img src=':/Icons/skin/seeding.png'/>&nbsp;"+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::number(BTSession->getPayloadUploadRate()/1024., 'f', 1));
html += "</div>"; html += "</div>";
#endif #endif
systrayIcon->setToolTip(html); // tray icon systrayIcon->setToolTip(html); // tray icon
@ -840,8 +851,8 @@ void GUI::showNotificationBaloon(QString title, QString msg) const {
void GUI::downloadFromURLList(const QStringList& url_list) { void GUI::downloadFromURLList(const QStringList& url_list) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool(); const bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
foreach(const QString url, url_list) { foreach(const QString& url, url_list) {
if(url.startsWith("magnet:", Qt::CaseInsensitive)) { if(url.startsWith("magnet:", Qt::CaseInsensitive)) {
if(useTorrentAdditionDialog) { if(useTorrentAdditionDialog) {
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession); torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession);
@ -925,12 +936,12 @@ void GUI::createTrayIcon() {
// Display Program Options // Display Program Options
void GUI::on_actionOptions_triggered() { void GUI::on_actionOptions_triggered() {
if(!options) { if(options) {
options = new options_imp(this);
connect(options, SIGNAL(status_changed()), this, SLOT(optionsSaved()));
} else {
// Get focus // Get focus
options->setFocus(); options->setFocus();
} else {
options = new options_imp(this);
connect(options, SIGNAL(status_changed()), this, SLOT(optionsSaved()));
} }
} }

View File

@ -56,6 +56,8 @@ class QSplitter;
class PropertiesWidget; class PropertiesWidget;
class StatusBar; class StatusBar;
class consoleDlg; class consoleDlg;
class about;
class createtorrent;
class GUI : public QMainWindow, private Ui::MainWindow{ class GUI : public QMainWindow, private Ui::MainWindow{
Q_OBJECT Q_OBJECT
@ -70,6 +72,8 @@ private:
StatusBar *status_bar; StatusBar *status_bar;
QPointer<options_imp> options; QPointer<options_imp> options;
QPointer<consoleDlg> console; QPointer<consoleDlg> console;
QPointer<about> aboutDlg;
QPointer<createtorrent> createTorrentDlg;
QPointer<QSystemTrayIcon> systrayIcon; QPointer<QSystemTrayIcon> systrayIcon;
QPointer<QTimer> systrayCreator; QPointer<QTimer> systrayCreator;
QMenu *myTrayIconMenu; QMenu *myTrayIconMenu;
@ -130,7 +134,7 @@ protected slots:
void loadPreferences(bool configure_session=true); void loadPreferences(bool configure_session=true);
void processParams(const QStringList& params); void processParams(const QStringList& params);
void addTorrent(QString path); void addTorrent(QString path);
void addUnauthenticatedTracker(QPair<QTorrentHandle,QString> tracker); void addUnauthenticatedTracker(const QPair<QTorrentHandle,QString> &tracker);
void processDownloadedFiles(QString path, QString url); void processDownloadedFiles(QString path, QString url);
void finishedTorrent(QTorrentHandle& h) const; void finishedTorrent(QTorrentHandle& h) const;
// Options slots // Options slots