mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 05:27:15 +03:00
- Optimised GUI class a little
This commit is contained in:
parent
29a290264e
commit
c064e5877c
3 changed files with 33 additions and 39 deletions
32
src/GUI.cpp
32
src/GUI.cpp
|
@ -216,7 +216,7 @@ void GUI::writeSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when a torrent finished checking
|
// Called when a torrent finished checking
|
||||||
void GUI::torrentChecked(QString hash) {
|
void GUI::torrentChecked(QString hash) const {
|
||||||
// Check if the torrent was paused after checking
|
// Check if the torrent was paused after checking
|
||||||
if(BTSession->isPaused(hash)) {
|
if(BTSession->isPaused(hash)) {
|
||||||
// Was paused, change its icon/color
|
// Was paused, change its icon/color
|
||||||
|
@ -237,7 +237,7 @@ void GUI::torrentChecked(QString hash) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// called when a torrent has finished
|
// called when a torrent has finished
|
||||||
void GUI::finishedTorrent(QTorrentHandle& h) {
|
void GUI::finishedTorrent(QTorrentHandle& h) const {
|
||||||
qDebug("In GUI, a torrent has finished");
|
qDebug("In GUI, a torrent has finished");
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||||
bool show_msg = true;
|
bool show_msg = true;
|
||||||
|
@ -259,7 +259,7 @@ void GUI::finishedTorrent(QTorrentHandle& h) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notification when disk is full
|
// Notification when disk is full
|
||||||
void GUI::fullDiskError(QTorrentHandle& h) {
|
void GUI::fullDiskError(QTorrentHandle& h) const {
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||||
int useOSD = settings.value(QString::fromUtf8("Options/OSDEnabled"), 1).toInt();
|
int useOSD = settings.value(QString::fromUtf8("Options/OSDEnabled"), 1).toInt();
|
||||||
if(systrayIntegration && (useOSD == 1 || (useOSD == 2 && (isMinimized() || isHidden())))) {
|
if(systrayIntegration && (useOSD == 1 || (useOSD == 2 && (isMinimized() || isHidden())))) {
|
||||||
|
@ -303,19 +303,19 @@ void GUI::createKeyboardShortcuts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keyboard shortcuts slots
|
// Keyboard shortcuts slots
|
||||||
void GUI::displayDownTab() {
|
void GUI::displayDownTab() const {
|
||||||
tabs->setCurrentIndex(0);
|
tabs->setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::displayUpTab() {
|
void GUI::displayUpTab() const {
|
||||||
tabs->setCurrentIndex(1);
|
tabs->setCurrentIndex(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::displaySearchTab() {
|
void GUI::displaySearchTab() const {
|
||||||
tabs->setCurrentIndex(2);
|
tabs->setCurrentIndex(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::displayRSSTab() {
|
void GUI::displayRSSTab() const {
|
||||||
tabs->setCurrentIndex(3);
|
tabs->setCurrentIndex(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ void GUI::on_actionPreview_file_triggered() {
|
||||||
new previewSelect(this, h);
|
new previewSelect(this, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::cleanTempPreviewFile(int, QProcess::ExitStatus) {
|
void GUI::cleanTempPreviewFile(int, QProcess::ExitStatus) const {
|
||||||
if(!QFile::remove(QDir::tempPath()+QDir::separator()+QString::fromUtf8("qBT_preview.tmp"))) {
|
if(!QFile::remove(QDir::tempPath()+QDir::separator()+QString::fromUtf8("qBT_preview.tmp"))) {
|
||||||
std::cerr << "Couldn't remove temporary file: " << (QDir::tempPath()+QDir::separator()+QString::fromUtf8("qBT_preview.tmp")).toUtf8().data() << "\n";
|
std::cerr << "Couldn't remove temporary file: " << (QDir::tempPath()+QDir::separator()+QString::fromUtf8("qBT_preview.tmp")).toUtf8().data() << "\n";
|
||||||
}
|
}
|
||||||
|
@ -424,7 +424,7 @@ unsigned int GUI::getCurrentTabIndex() const{
|
||||||
return tabs->currentIndex();
|
return tabs->currentIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::setTabText(int index, QString text) {
|
void GUI::setTabText(int index, QString text) const {
|
||||||
tabs->setTabText(index, text);
|
tabs->setTabText(index, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,6 +534,7 @@ void GUI::dropEvent(QDropEvent *event) {
|
||||||
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Options/Misc/TorrentAdditionDialog/Enabled"), true).toBool();
|
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Options/Misc/TorrentAdditionDialog/Enabled"), true).toBool();
|
||||||
foreach(file, files) {
|
foreach(file, files) {
|
||||||
file = file.trimmed().replace(QString::fromUtf8("file://"), QString::fromUtf8(""));
|
file = file.trimmed().replace(QString::fromUtf8("file://"), QString::fromUtf8(""));
|
||||||
|
qDebug("Dropped file %s on download list", file.toUtf8().data());
|
||||||
if(file.startsWith(QString::fromUtf8("http://"), Qt::CaseInsensitive) || file.startsWith(QString::fromUtf8("ftp://"), Qt::CaseInsensitive) || file.startsWith(QString::fromUtf8("https://"), Qt::CaseInsensitive)) {
|
if(file.startsWith(QString::fromUtf8("http://"), Qt::CaseInsensitive) || file.startsWith(QString::fromUtf8("ftp://"), Qt::CaseInsensitive) || file.startsWith(QString::fromUtf8("https://"), Qt::CaseInsensitive)) {
|
||||||
BTSession->downloadFromUrl(file);
|
BTSession->downloadFromUrl(file);
|
||||||
continue;
|
continue;
|
||||||
|
@ -649,9 +650,6 @@ void GUI::on_actionDelete_triggered() {
|
||||||
QStringList hashes;
|
QStringList hashes;
|
||||||
bool inDownloadList = true;
|
bool inDownloadList = true;
|
||||||
switch(tabs->currentIndex()){
|
switch(tabs->currentIndex()){
|
||||||
case 3: //RSSImp
|
|
||||||
rssWidget->on_delStream_button_clicked();
|
|
||||||
return;
|
|
||||||
case 0: // DL
|
case 0: // DL
|
||||||
hashes = downloadingTorrentTab->getSelectedTorrents();
|
hashes = downloadingTorrentTab->getSelectedTorrents();
|
||||||
break;
|
break;
|
||||||
|
@ -659,6 +657,9 @@ void GUI::on_actionDelete_triggered() {
|
||||||
hashes = finishedTorrentTab->getSelectedTorrents();
|
hashes = finishedTorrentTab->getSelectedTorrents();
|
||||||
inDownloadList = false;
|
inDownloadList = false;
|
||||||
break;
|
break;
|
||||||
|
case 3: //RSSImp
|
||||||
|
rssWidget->on_delStream_button_clicked();
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -844,17 +845,18 @@ void GUI::configureSession(bool deleteOptions) {
|
||||||
// Apply Proxy settings
|
// Apply Proxy settings
|
||||||
if(options->isProxyEnabled()) {
|
if(options->isProxyEnabled()) {
|
||||||
switch(options->getProxyType()) {
|
switch(options->getProxyType()) {
|
||||||
|
case HTTP:
|
||||||
|
proxySettings.type = proxy_settings::http;
|
||||||
|
break;
|
||||||
case HTTP_PW:
|
case HTTP_PW:
|
||||||
proxySettings.type = proxy_settings::http_pw;
|
proxySettings.type = proxy_settings::http_pw;
|
||||||
break;
|
break;
|
||||||
case SOCKS5:
|
case SOCKS5:
|
||||||
proxySettings.type = proxy_settings::socks5;
|
proxySettings.type = proxy_settings::socks5;
|
||||||
break;
|
break;
|
||||||
case SOCKS5_PW:
|
default:
|
||||||
proxySettings.type = proxy_settings::socks5_pw;
|
proxySettings.type = proxy_settings::socks5_pw;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
proxySettings.type = proxy_settings::http;
|
|
||||||
}
|
}
|
||||||
proxySettings.hostname = options->getProxyIp().toStdString();
|
proxySettings.hostname = options->getProxyIp().toStdString();
|
||||||
proxySettings.port = options->getProxyPort();
|
proxySettings.port = options->getProxyPort();
|
||||||
|
|
18
src/GUI.h
18
src/GUI.h
|
@ -96,7 +96,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||||
void togglePausedState(QString hash);
|
void togglePausedState(QString hash);
|
||||||
void on_actionPreview_file_triggered();
|
void on_actionPreview_file_triggered();
|
||||||
void previewFile(QString filePath);
|
void previewFile(QString filePath);
|
||||||
void cleanTempPreviewFile(int, QProcess::ExitStatus);
|
void cleanTempPreviewFile(int, QProcess::ExitStatus) const;
|
||||||
void balloonClicked();
|
void balloonClicked();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
void readSettings();
|
void readSettings();
|
||||||
|
@ -104,14 +104,14 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||||
void createTrayIcon();
|
void createTrayIcon();
|
||||||
void updateUnfinishedTorrentNumber(unsigned int nb);
|
void updateUnfinishedTorrentNumber(unsigned int nb);
|
||||||
void updateFinishedTorrentNumber(unsigned int nb);
|
void updateFinishedTorrentNumber(unsigned int nb);
|
||||||
void fullDiskError(QTorrentHandle& h);
|
void fullDiskError(QTorrentHandle& h) const;
|
||||||
void handleDownloadFromUrlFailure(QString, QString) const;
|
void handleDownloadFromUrlFailure(QString, QString) const;
|
||||||
// Keyboard shortcuts
|
// Keyboard shortcuts
|
||||||
void createKeyboardShortcuts();
|
void createKeyboardShortcuts();
|
||||||
void displayDownTab();
|
void displayDownTab() const;
|
||||||
void displayUpTab();
|
void displayUpTab() const;
|
||||||
void displaySearchTab();
|
void displaySearchTab() const;
|
||||||
void displayRSSTab();
|
void displayRSSTab() const;
|
||||||
// Torrent actions
|
// Torrent actions
|
||||||
void on_actionTorrent_Properties_triggered();
|
void on_actionTorrent_Properties_triggered();
|
||||||
void on_actionPause_triggered();
|
void on_actionPause_triggered();
|
||||||
|
@ -131,8 +131,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||||
void processScannedFiles(const QStringList& params);
|
void processScannedFiles(const QStringList& params);
|
||||||
void processDownloadedFiles(QString path, QString url);
|
void processDownloadedFiles(QString path, QString url);
|
||||||
void downloadFromURLList(const QStringList& urls);
|
void downloadFromURLList(const QStringList& urls);
|
||||||
void finishedTorrent(QTorrentHandle& h);
|
void finishedTorrent(QTorrentHandle& h) const;
|
||||||
void torrentChecked(QString hash);
|
void torrentChecked(QString hash) const;
|
||||||
void updateLists();
|
void updateLists();
|
||||||
// Options slots
|
// Options slots
|
||||||
void on_actionOptions_triggered();
|
void on_actionOptions_triggered();
|
||||||
|
@ -143,7 +143,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void trackerAuthenticationRequired(QTorrentHandle& h);
|
void trackerAuthenticationRequired(QTorrentHandle& h);
|
||||||
void setTabText(int index, QString text);
|
void setTabText(int index, QString text) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
|
|
22
src/misc.h
22
src/misc.h
|
@ -116,29 +116,21 @@ class misc : public QObject{
|
||||||
const QString units[4] = {tr("B", "bytes"), tr("KiB", "kibibytes (1024 bytes)"), tr("MiB", "mebibytes (1024 kibibytes)"), tr("GiB", "gibibytes (1024 mibibytes)")};
|
const QString units[4] = {tr("B", "bytes"), tr("KiB", "kibibytes (1024 bytes)"), tr("MiB", "mebibytes (1024 kibibytes)"), tr("GiB", "gibibytes (1024 mibibytes)")};
|
||||||
for(unsigned int i=0; i<5; ++i) {
|
for(unsigned int i=0; i<5; ++i) {
|
||||||
if (val < 1024.) {
|
if (val < 1024.) {
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", val);
|
snprintf(tmp, MAX_CHAR_TMP, "%.1f ", val);
|
||||||
return QString::fromUtf8(tmp) + QString::fromUtf8(" ") + units[i];
|
return QString::fromUtf8(tmp) + units[i];
|
||||||
}
|
}
|
||||||
val /= 1024.;
|
val /= 1024.;
|
||||||
}
|
}
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", val);
|
snprintf(tmp, MAX_CHAR_TMP, "%.1f ", val);
|
||||||
return QString::fromUtf8(tmp) + QString::fromUtf8(" ") + tr("TiB", "tebibytes (1024 gibibytes)");
|
return QString::fromUtf8(tmp) + tr("TiB", "tebibytes (1024 gibibytes)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// return qBittorrent config path
|
// return qBittorrent config path
|
||||||
static QString qBittorrentPath() {
|
static QString qBittorrentPath() {
|
||||||
QString qBtPath = QDir::homePath();
|
QString qBtPath = QDir::cleanPath(QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator());
|
||||||
if(qBtPath.isNull()) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
if(qBtPath[qBtPath.length()-1] == QDir::separator()) {
|
|
||||||
qBtPath = qBtPath + QString::fromUtf8(".qbittorrent") + QDir::separator();
|
|
||||||
}else{
|
|
||||||
qBtPath = qBtPath + QDir::separator() + QString::fromUtf8(".qbittorrent") + QDir::separator();
|
|
||||||
}
|
|
||||||
// Create dir if it does not exist
|
// Create dir if it does not exist
|
||||||
QDir dir(qBtPath);
|
if(!QFile::exists(qBtPath)){
|
||||||
if(!dir.exists()) {
|
QDir dir(qBtPath);
|
||||||
dir.mkpath(qBtPath);
|
dir.mkpath(qBtPath);
|
||||||
}
|
}
|
||||||
return qBtPath;
|
return qBtPath;
|
||||||
|
|
Loading…
Reference in a new issue