From d277696acc88584c6eeb5f5490439ad12f590350 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 29 Apr 2016 17:25:15 +0800 Subject: [PATCH] Add global.h file --- src/base/CMakeLists.txt | 1 + src/base/base.pri | 3 ++- src/base/global.h | 30 ++++++++++++++++++++++++++++++ src/gui/mainwindow.cpp | 5 +++-- src/gui/torrentcreatordlg.cpp | 8 ++++---- 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 src/base/global.h diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index f8bf7f7c5..9ff9521ed 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -52,6 +52,7 @@ utils/string.h utils/version.h asyncfilestorage.h filesystemwatcher.h +global.h iconprovider.h indexrange.h logger.h diff --git a/src/base/base.pri b/src/base/base.pri index 041e2d4a3..b302c9436 100644 --- a/src/base/base.pri +++ b/src/base/base.pri @@ -63,7 +63,8 @@ HEADERS += \ $$PWD/torrentfileguard.h \ $$PWD/torrentfilter.h \ $$PWD/scanfoldersmodel.h \ - $$PWD/searchengine.h + $$PWD/searchengine.h \ + $$PWD/global.h SOURCES += \ $$PWD/asyncfilestorage.cpp \ diff --git a/src/base/global.h b/src/base/global.h new file mode 100644 index 000000000..2bfeda9cb --- /dev/null +++ b/src/base/global.h @@ -0,0 +1,30 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2016 Mike Tzou + * + * 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. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +const char C_TORRENT_FILE_EXTENSION[] = ".torrent"; + diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index d9303eb97..583f5380c 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -64,6 +64,7 @@ #include "base/bittorrent/session.h" #include "base/bittorrent/sessionstatus.h" #include "base/bittorrent/torrenthandle.h" +#include "base/global.h" #include "base/rss/rss_folder.h" #include "base/rss/rss_session.h" @@ -1152,7 +1153,7 @@ void MainWindow::dropEvent(QDropEvent *event) // differentiate ".torrent" files and others QStringList torrentFiles, otherFiles; foreach (const QString &file, files) { - if (file.endsWith(".torrent", Qt::CaseInsensitive)) + if (file.endsWith(C_TORRENT_FILE_EXTENSION, Qt::CaseInsensitive)) torrentFiles << file; else otherFiles << file; @@ -1203,7 +1204,7 @@ void MainWindow::on_actionOpen_triggered() // Note: it is possible to select more than one file const QStringList pathsList = QFileDialog::getOpenFileNames(this, tr("Open Torrent Files"), pref->getMainLastDir(), - tr("Torrent Files") + " (*.torrent)"); + tr("Torrent Files") + " (*" + C_TORRENT_FILE_EXTENSION + ')'); const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled(); if (!pathsList.isEmpty()) { diff --git a/src/gui/torrentcreatordlg.cpp b/src/gui/torrentcreatordlg.cpp index 87c2283b9..f14c3f65d 100644 --- a/src/gui/torrentcreatordlg.cpp +++ b/src/gui/torrentcreatordlg.cpp @@ -38,11 +38,11 @@ #include #include "base/bittorrent/session.h" -#include "base/bittorrent/torrentinfo.h" #include "base/bittorrent/torrentcreatorthread.h" +#include "base/bittorrent/torrentinfo.h" +#include "base/global.h" #include "base/settingsstorage.h" #include "base/utils/fs.h" -#include "guiiconprovider.h" #include "ui_torrentcreatordlg.h" @@ -161,8 +161,8 @@ void TorrentCreatorDlg::onCreateButtonClicked() QString destination = QFileDialog::getSaveFileName(this, tr("Select where to save the new torrent"), lastPath, tr("Torrent Files (*.torrent)")); if (destination.isEmpty()) return; - if (!destination.endsWith(".torrent", Qt::CaseInsensitive)) - destination += ".torrent"; + if (!destination.endsWith(C_TORRENT_FILE_EXTENSION, Qt::CaseInsensitive)) + destination += C_TORRENT_FILE_EXTENSION; storeLastSavePath = Utils::Fs::branchPath(destination); // Disable dialog & set busy cursor