Browse Source

FEATURE: Inhibit system sleep when torrents are active (Vladimir Golovnev)

Remove visual style settings
adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
0f1473e212
  1. 1
      Changelog
  2. 127
      src/lang/qbittorrent_ru.ts
  3. 10
      src/main.cpp
  4. 31
      src/mainwindow.cpp
  5. 6
      src/mainwindow.h
  6. 90
      src/powermanagement/powermanagement.cpp
  7. 70
      src/powermanagement/powermanagement.h
  8. 9
      src/powermanagement/powermanagement.pri
  9. 185
      src/powermanagement/powermanagement_x11.cpp
  10. 69
      src/powermanagement/powermanagement_x11.h
  11. 2
      src/preferences/advancedsettings.h
  12. 105
      src/preferences/options.ui
  13. 28
      src/preferences/options_imp.cpp
  14. 4
      src/preferences/options_imp.h
  15. 17
      src/preferences/preferences.h
  16. 1
      src/src.pro

1
Changelog

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
- FEATURE: Added auto-shutdown confirmation dialog
- FEATURE: Added option to skip torrent deletion confirmation (Ville Kiiskinen)
- FEATURE: IP address reported to trackers is now customizable
- FEATURE: Inhibit system sleep when torrents are active (Vladimir Golovnev)
* Sun Jan 9 2011 - Christophe Dumez <chris@qbittorrent.org> - v2.6.0
- FEATURE: Use system icons (Linux, Qt >= 4.6)

127
src/lang/qbittorrent_ru.ts

@ -168,13 +168,9 @@ p, li { white-space: pre-wrap; } @@ -168,13 +168,9 @@ p, li { white-space: pre-wrap; }
<source>Use system icon theme</source>
<translation>Использовать системные иконки</translation>
</message>
<message>
<source>Confirm torrent deletion</source>
<translation>Подтверждать удаление торрента</translation>
</message>
<message>
<source>IP Address to report to trackers (requires restart)</source>
<translation type="unfinished"></translation>
<translation>IP адрес для сообщения трекерам (требуется перезапуск)</translation>
</message>
</context>
<context>
@ -593,95 +589,95 @@ You should get this information from your Web browser preferences.</source> @@ -593,95 +589,95 @@ You should get this information from your Web browser preferences.</source>
<name>DownloadThread</name>
<message>
<source>I/O Error</source>
<translation>Ошибка ввода/вывода</translation>
<translation type="obsolete">Ошибка ввода/вывода</translation>
</message>
<message>
<source>The remote host name was not found (invalid hostname)</source>
<translation>Удаленный хост не был найден (неправильное имя хоста)</translation>
<translation type="obsolete">Удаленный хост не был найден (неправильное имя хоста)</translation>
</message>
<message>
<source>The operation was canceled</source>
<translation>Операция была отменена</translation>
<translation type="obsolete">Операция была отменена</translation>
</message>
<message>
<source>The remote server closed the connection prematurely, before the entire reply was received and processed</source>
<translation>Удаленный сервер закрыл соединение, прежде чем весь ответ был принят и обработан</translation>
<translation type="obsolete">Удаленный сервер закрыл соединение, прежде чем весь ответ был принят и обработан</translation>
</message>
<message>
<source>The connection to the remote server timed out</source>
<translation>Время соединения с удаленным сервером вышло</translation>
<translation type="obsolete">Время соединения с удаленным сервером вышло</translation>
</message>
<message>
<source>SSL/TLS handshake failed</source>
<translation>Соединение SSL/TLS не удалось</translation>
<translation type="obsolete">Соединение SSL/TLS не удалось</translation>
</message>
<message>
<source>The remote server refused the connection</source>
<translation>Удаленный сервер отклонил соединение</translation>
<translation type="obsolete">Удаленный сервер отклонил соединение</translation>
</message>
<message>
<source>The connection to the proxy server was refused</source>
<translation>Прокси-сервер отклонил соединение</translation>
<translation type="obsolete">Прокси-сервер отклонил соединение</translation>
</message>
<message>
<source>The proxy server closed the connection prematurely</source>
<translation>Прокси-сервер преждевременно закрыл соединение</translation>
<translation type="obsolete">Прокси-сервер преждевременно закрыл соединение</translation>
</message>
<message>
<source>The proxy host name was not found</source>
<translation>Имя прокси-сервера не было найдено</translation>
<translation type="obsolete">Имя прокси-сервера не было найдено</translation>
</message>
<message>
<source>The connection to the proxy timed out or the proxy did not reply in time to the request sent</source>
<translation>Подключение к прокси-серверу истекло или прокси-сервер не ответил на запрос</translation>
<translation type="obsolete">Подключение к прокси-серверу истекло или прокси-сервер не ответил на запрос</translation>
</message>
<message>
<source>The proxy requires authentication in order to honour the request but did not accept any credentials offered</source>
<translation>Прокси-сервер требует аутентификации, но не принял указанные учетные данные</translation>
<translation type="obsolete">Прокси-сервер требует аутентификации, но не принял указанные учетные данные</translation>
</message>
<message>
<source>The access to the remote content was denied (401)</source>
<translation>В доступе к данным было отказано (401)</translation>
<translation type="obsolete">В доступе к данным было отказано (401)</translation>
</message>
<message>
<source>The operation requested on the remote content is not permitted</source>
<translation>В данной операции над данными отказано</translation>
<translation type="obsolete">В данной операции над данными отказано</translation>
</message>
<message>
<source>The remote content was not found at the server (404)</source>
<translation>Данные не были найдены на сервере (404)</translation>
<translation type="obsolete">Данные не были найдены на сервере (404)</translation>
</message>
<message>
<source>The remote server requires authentication to serve the content but the credentials provided were not accepted</source>
<translation>Удаленный сервер требует аутентификацию для отдачи данных, но указанные учетные данные не были приняты</translation>
<translation type="obsolete">Удаленный сервер требует аутентификацию для отдачи данных, но указанные учетные данные не были приняты</translation>
</message>
<message>
<source>The Network Access API cannot honor the request because the protocol is not known</source>
<translation>API сетевого доступа не может выполнить запрос, потому что протокол не известен</translation>
<translation type="obsolete">API сетевого доступа не может выполнить запрос, потому что протокол не известен</translation>
</message>
<message>
<source>The requested operation is invalid for this protocol</source>
<translation>Запрошенная операция не поддерживается данным протоколом</translation>
<translation type="obsolete">Запрошенная операция не поддерживается данным протоколом</translation>
</message>
<message>
<source>An unknown network-related error was detected</source>
<translation>Неизвестная сетевая ошибка</translation>
<translation type="obsolete">Неизвестная сетевая ошибка</translation>
</message>
<message>
<source>An unknown proxy-related error was detected</source>
<translation>Неизвестная ошибка прокси-сервера</translation>
<translation type="obsolete">Неизвестная ошибка прокси-сервера</translation>
</message>
<message>
<source>An unknown error related to the remote content was detected</source>
<translation>Неизвестная ошибка данных</translation>
<translation type="obsolete">Неизвестная ошибка данных</translation>
</message>
<message>
<source>A breakdown in protocol was detected</source>
<translation>Ошибка в протоколе</translation>
<translation type="obsolete">Ошибка в протоколе</translation>
</message>
<message>
<source>Unknown error</source>
<translation>Неизвестная ошибка</translation>
<translation type="obsolete">Неизвестная ошибка</translation>
</message>
</context>
<context>
@ -2615,6 +2611,10 @@ Would you like to update qBittorrent to version %1?</source> @@ -2615,6 +2611,10 @@ Would you like to update qBittorrent to version %1?</source>
<source>Reload the filter</source>
<translation>Перезагрузить фильтр</translation>
</message>
<message>
<source>Prevent system from suspend</source>
<translation>Предотвращать переход в спящий режим</translation>
</message>
</context>
<context>
<name>PreviewSelect</name>
@ -3190,19 +3190,7 @@ Would you like to update qBittorrent to version %1?</source> @@ -3190,19 +3190,7 @@ Would you like to update qBittorrent to version %1?</source>
</message>
<message>
<source>Reporting IP address %1 to trackers...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>The computer will now go to sleep mode unless you cancel within the next 15 seconds...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>The computer will now be switched off unless you cancel within the next 15 seconds...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>qBittorrent will now exit unless you cancel within the next 15 seconds...</source>
<translation type="unfinished"></translation>
<translation>Сообщаю IP адрес %1 трекерам...</translation>
</message>
</context>
<context>
@ -3643,13 +3631,6 @@ Do you want to install it now?</source> @@ -3643,13 +3631,6 @@ Do you want to install it now?</source>
<translation>Поисковый движок</translation>
</message>
</context>
<context>
<name>ShutdownConfirmDlg</name>
<message>
<source>Shutdown confirmation</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SpeedLimitDialog</name>
<message>
@ -4808,95 +4789,95 @@ Do you want to install it now?</source> @@ -4808,95 +4789,95 @@ Do you want to install it now?</source>
<name>downloadThread</name>
<message>
<source>I/O Error</source>
<translation type="obsolete">Ошибка ввода/вывода</translation>
<translation>Ошибка ввода/вывода</translation>
</message>
<message>
<source>The remote host name was not found (invalid hostname)</source>
<translation type="obsolete">Удаленный хост не был найден (неправильное имя хоста)</translation>
<translation>Имя удалённого хоста не было найдено (неправильное имя хоста)</translation>
</message>
<message>
<source>The operation was canceled</source>
<translation type="obsolete">Операция была отменена</translation>
<translation>Операция была отменена</translation>
</message>
<message>
<source>The remote server closed the connection prematurely, before the entire reply was received and processed</source>
<translation type="obsolete">Удаленный сервер закрыл соединение навсегда, прежде чем весь ответ был принят и обработан</translation>
<translation>Удаленный сервер преждевременно закрыл соединение, прежде чем весь ответ был принят и обработан</translation>
</message>
<message>
<source>The connection to the remote server timed out</source>
<translation type="obsolete">Время соединения с удаленным сервером вышло</translation>
<translation>Время соединения с удаленным сервером вышло</translation>
</message>
<message>
<source>SSL/TLS handshake failed</source>
<translation type="obsolete">Соединение SSL/TLS не удалось</translation>
<translation>Соединение SSL/TLS не удалось</translation>
</message>
<message>
<source>The remote server refused the connection</source>
<translation type="obsolete">Удаленный сервер отклонил соединение</translation>
<translation>Удаленный сервер отклонил соединение</translation>
</message>
<message>
<source>The connection to the proxy server was refused</source>
<translation type="obsolete">Прокси-сервер отклонил соединение</translation>
<translation>Соединение с прокси-сервером отклонено</translation>
</message>
<message>
<source>The proxy server closed the connection prematurely</source>
<translation type="obsolete">Прокси-сервер закрыл соединение навсегда</translation>
<translation>Прокси-сервер преждевременно закрыл соединение</translation>
</message>
<message>
<source>The proxy host name was not found</source>
<translation type="obsolete">Имя прокси-сервера не найдено</translation>
<translation>Имя прокси-сервера не было найдено</translation>
</message>
<message>
<source>The connection to the proxy timed out or the proxy did not reply in time to the request sent</source>
<translation type="obsolete">Подключение к прокси-серверу истекло или прокси-сервер не ответил на запрос</translation>
<translation>Подключение к прокси-серверу истекло или прокси-сервер не ответил на запрос</translation>
</message>
<message>
<source>The proxy requires authentication in order to honour the request but did not accept any credentials offered</source>
<translation type="obsolete">Прокси-сервер требует аутентификации но не принял указанные учетные данные</translation>
<translation>Прокси-сервер требует аутентификации, но не принял указанные учетные данные</translation>
</message>
<message>
<source>The access to the remote content was denied (401)</source>
<translation type="obsolete">В доступе к данным было отказано (401)</translation>
<translation>В доступе к данным было отказано (401)</translation>
</message>
<message>
<source>The operation requested on the remote content is not permitted</source>
<translation type="obsolete">В данной операции над данными отказано</translation>
<translation>Запрошенная операция над данными запрещена</translation>
</message>
<message>
<source>The remote content was not found at the server (404)</source>
<translation type="obsolete">Данные не были найдены на сервере (404)</translation>
<translation>Данные не были найдены на сервере (404)</translation>
</message>
<message>
<source>The remote server requires authentication to serve the content but the credentials provided were not accepted</source>
<translation type="obsolete">Удаленный сервер требует аутентификацию для отдачи данных, но указанные учетные данные не были приняты</translation>
<translation>Удаленный сервер требует аутентификацию для отдачи данных, но указанные учетные данные не были приняты</translation>
</message>
<message>
<source>The Network Access API cannot honor the request because the protocol is not known</source>
<translation type="obsolete">API сетевого доступа не может выполнить запрос потому что протокол не известен</translation>
<translation>API сетевого доступа не может выполнить запрос, потому что протокол не известен</translation>
</message>
<message>
<source>The requested operation is invalid for this protocol</source>
<translation type="obsolete">Запрошенная операция не поддерживается данным протоколом</translation>
<translation>Запрошенная операция не поддерживается данным протоколом</translation>
</message>
<message>
<source>An unknown network-related error was detected</source>
<translation type="obsolete">Неизвестная сетевая ошибка</translation>
<translation>Неизвестная сетевая ошибка</translation>
</message>
<message>
<source>An unknown proxy-related error was detected</source>
<translation type="obsolete">Неизвестная ошибка прокси-сервера</translation>
<translation>Неизвестная ошибка прокси-сервера</translation>
</message>
<message>
<source>An unknown error related to the remote content was detected</source>
<translation type="obsolete">Неизвестная ошибка данных</translation>
<translation>Неизвестная ошибка данных</translation>
</message>
<message>
<source>A breakdown in protocol was detected</source>
<translation type="obsolete">Ошибка в протоколе</translation>
<translation>Ошибка в протоколе</translation>
</message>
<message>
<source>Unknown error</source>
<translation type="obsolete">Неизвестная ошибка</translation>
<translation>Неизвестная ошибка</translation>
</message>
</context>
<context>
@ -5160,7 +5141,7 @@ However, those plugins were disabled.</source> @@ -5160,7 +5141,7 @@ However, those plugins were disabled.</source>
</message>
<message>
<source>Succesfully refreshed</source>
<translation type="obsolete">Успешно обновлен</translation>
<translation>Успешно обновлен</translation>
</message>
<message>
<source>Successfuly parsed the provided IP filter: %1 rules were applied.</source>
@ -5169,7 +5150,7 @@ However, those plugins were disabled.</source> @@ -5169,7 +5150,7 @@ However, those plugins were disabled.</source>
</message>
<message>
<source>Successfully refreshed</source>
<translation>Успешно обновлён</translation>
<translation type="obsolete">Успешно обновлён</translation>
</message>
</context>
<context>

10
src/main.cpp

@ -153,15 +153,6 @@ void sigabrtHandler(int) { @@ -153,15 +153,6 @@ void sigabrtHandler(int) {
}
#endif
#ifndef DISABLE_GUI
void useStyle(QString style){
if(!style.isEmpty()) {
QApplication::setStyle(QStyleFactory::create(style));
}
Preferences().setStyle(QApplication::style()->objectName());
}
#endif
// Main
int main(int argc, char *argv[]){
// Create Application
@ -286,7 +277,6 @@ int main(int argc, char *argv[]){ @@ -286,7 +277,6 @@ int main(int argc, char *argv[]){
}
#ifndef DISABLE_GUI
useStyle(pref.getStyle());
app.setStyleSheet("QStatusBar::item { border-width: 0; }");
#endif

31
src/mainwindow.cpp

@ -43,6 +43,9 @@ @@ -43,6 +43,9 @@
#include <QCloseEvent>
#include <QShortcut>
#include <QScrollBar>
#ifdef Q_WS_X11
#include <QDBusInterface>
#endif
#include "mainwindow.h"
#include "transferlistwidget.h"
@ -80,10 +83,12 @@ void qt_mac_set_dock_menu(QMenu *menu); @@ -80,10 +83,12 @@ void qt_mac_set_dock_menu(QMenu *menu);
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
#include "programupdater.h"
#endif
#include "powermanagement.h"
using namespace libtorrent;
#define TIME_TRAY_BALLOON 5000
#define PREVENT_SUSPEND_INTERVAL 60000
/*****************************************************
* *
@ -192,6 +197,10 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo @@ -192,6 +197,10 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo
connect(actionIncreasePriority, SIGNAL(triggered()), transferList, SLOT(increasePrioSelectedTorrents()));
connect(actionDecreasePriority, SIGNAL(triggered()), transferList, SLOT(decreasePrioSelectedTorrents()));
m_pwr = new PowerManagement(this);
preventTimer = new QTimer(this);
connect(preventTimer, SIGNAL(timeout()), SLOT(checkForActiveTorrents()));
// Configure BT session according to options
loadPreferences(false);
@ -290,13 +299,13 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo @@ -290,13 +299,13 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo
updater->checkForUpdates();
}
#endif
}
void MainWindow::deleteBTSession() {
guiUpdater->stop();
status_bar->stopTimer();
QBtSession::drop();
m_pwr->setActivityState(false);
QTimer::singleShot(0, this, SLOT(close()));
}
@ -985,6 +994,17 @@ void MainWindow::loadPreferences(bool configure_session) { @@ -985,6 +994,17 @@ void MainWindow::loadPreferences(bool configure_session) {
search_filter->clear();
toolBar->setVisible(false);
}
if(pref.preventFromSuspend())
{
preventTimer->start(PREVENT_SUSPEND_INTERVAL);
}
else
{
preventTimer->stop();
m_pwr->setActivityState(false);
}
const uint new_refreshInterval = pref.getRefreshInterval();
transferList->setRefreshInterval(new_refreshInterval);
transferList->setAlternatingRowColors(pref.useAlternatingRowColors());
@ -1313,3 +1333,12 @@ void MainWindow::on_actionAutoShutdown_system_toggled(bool enabled) @@ -1313,3 +1333,12 @@ void MainWindow::on_actionAutoShutdown_system_toggled(bool enabled)
qDebug() << Q_FUNC_INFO << enabled;
Preferences().setShutdownWhenDownloadsComplete(enabled);
}
void MainWindow::checkForActiveTorrents()
{
const TorrentStatusReport report = transferList->getSourceModel()->getTorrentStatusReport();
if(report.nb_active > 0) // Active torrents are present; prevent system from suspend
m_pwr->setActivityState(true);
else
m_pwr->setActivityState(false);
}

6
src/mainwindow.h

@ -60,6 +60,7 @@ class HidableTabWidget; @@ -60,6 +60,7 @@ class HidableTabWidget;
class LineEdit;
class QFileSystemWatcher;
class ExecutionLog;
class PowerManagement;
class MainWindow : public QMainWindow, private Ui::MainWindow{
Q_OBJECT
@ -182,6 +183,9 @@ private: @@ -182,6 +183,9 @@ private:
QPointer<RSSImp> rssWidget;
// Execution Log
QPointer<ExecutionLog> m_executionLog;
// Power Management
PowerManagement *m_pwr;
QTimer *preventTimer;
private slots:
void on_actionSearch_engine_triggered();
@ -194,6 +198,8 @@ private slots: @@ -194,6 +198,8 @@ private slots:
void on_actionAutoExit_qBittorrent_toggled(bool );
void on_actionAutoSuspend_system_toggled(bool );
void on_actionAutoShutdown_system_toggled(bool );
// Check for active torrents and set preventing from suspend state
void checkForActiveTorrents();
};
#endif

90
src/powermanagement/powermanagement.cpp

@ -0,0 +1,90 @@ @@ -0,0 +1,90 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
*
* 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.
*
* Contact : chris@qbittorrent.org
*/
#include <QtGlobal>
#ifdef Q_WS_X11
#include "powermanagement_x11.h"
#endif
#include "powermanagement.h"
#ifdef Q_WS_MAC
#include <IOKit/pwr_mgt/IOPMLib.h>
#endif
#ifdef Q_WS_WIN
#include <Windows.h>
#endif
PowerManagement::PowerManagement(QObject *parent) : QObject(parent), m_busy(false)
{
#ifdef Q_WS_X11
m_inhibitor = new PowerManagementInhibitor(this);
#endif
}
PowerManagement::~PowerManagement()
{
}
void PowerManagement::setActivityState(bool busy)
{
if(busy) setBusy();
else setIdle();
}
void PowerManagement::setBusy()
{
if(m_busy) return;
m_busy = true;
#ifdef Q_WS_WIN
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
#elif defined(Q_WS_X11)
m_inhibitor->RequestBusy();
#elif defined(Q_WS_MAC)
IOReturn success = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &m_assertionID);
if(success != kIOReturnSuccess) m_busy = false;
#endif
}
void PowerManagement::setIdle()
{
if(!m_busy) return;
m_busy = false;
#ifdef Q_WS_WIN
SetThreadExecutionState(ES_CONTINUOUS);
#elif defined(Q_WS_X11)
m_inhibitor->RequestIdle();
#elif defined(Q_WS_MAC)
IOPMAssertionRelease(m_assertionID);
#endif
}

70
src/powermanagement/powermanagement.h

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
*
* 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.
*
* Contact : chris@qbittorrent.org
*/
#ifndef POWERMANAGEMENT_H
#define POWERMANAGEMENT_H
#include <QObject>
#ifdef Q_WS_MAC
// Require Mac OS X >= 10.5
#include <IOKit/pwr_mgt/IOPMLib.h>
#endif
#ifdef Q_WS_X11
// Require DBus
class PowerManagementInhibitor;
#endif
class PowerManagement : public QObject
{
Q_OBJECT
public:
PowerManagement(QObject *parent = 0);
virtual ~PowerManagement();
void setActivityState(bool busy);
private:
bool m_busy;
void setBusy();
void setIdle();
#ifdef Q_WS_X11
PowerManagementInhibitor *m_inhibitor;
#endif
#ifdef Q_WS_MAC
IOPMAssertionID m_assertionID;
#endif
};
#endif // POWERMANAGEMENT_H

9
src/powermanagement/powermanagement.pri

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
INCLUDEPATH += $$PWD
HEADERS += $$PWD/powermanagement.h
SOURCES += $$PWD/powermanagement.cpp
unix:!macx {
HEADERS += $$PWD/powermanagement_x11.h
SOURCES += $$PWD/powermanagement_x11.cpp
}

185
src/powermanagement/powermanagement_x11.cpp

@ -0,0 +1,185 @@ @@ -0,0 +1,185 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
*
* 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.
*
* Contact : chris@qbittorrent.org
*/
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCall>
#include <QDBusPendingReply>
#include "powermanagement_x11.h"
PowerManagementInhibitor::PowerManagementInhibitor(QObject *parent) : QObject(parent)
{
if(!QDBusConnection::sessionBus().isConnected())
{
qDebug("D-Bus: Could not connect to session bus");
m_state = error;
}
else
{
m_state = idle;
}
m_intended_state = idle;
m_cookie = 0;
m_use_gsm = false;
}
PowerManagementInhibitor::~PowerManagementInhibitor()
{
}
void PowerManagementInhibitor::RequestIdle()
{
m_intended_state = idle;
if (m_state == error || m_state == idle || m_state == request_idle || m_state == request_busy)
return;
qDebug("D-Bus: PowerManagementInhibitor: Requesting idle");
QDBusMessage call;
if (!m_use_gsm)
call = QDBusMessage::createMethodCall(
"org.freedesktop.PowerManagement",
"/org/freedesktop/PowerManagement/Inhibit",
"org.freedesktop.PowerManagement.Inhibit",
"UnInhibit");
else
call = QDBusMessage::createMethodCall(
"org.gnome.SessionManager",
"/org/gnome/SessionManager",
"org.gnome.SessionManager",
"Uninhibit");
m_state = request_idle;
QList<QVariant> args;
args << m_cookie;
call.setArguments(args);
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
this, SLOT(OnAsyncReply(QDBusPendingCallWatcher*)));
}
void PowerManagementInhibitor::RequestBusy()
{
m_intended_state = busy;
if (m_state == error || m_state == busy || m_state == request_busy || m_state == request_idle)
return;
qDebug("D-Bus: PowerManagementInhibitor: Requesting busy");
QDBusMessage call;
if (!m_use_gsm)
call = QDBusMessage::createMethodCall(
"org.freedesktop.PowerManagement",
"/org/freedesktop/PowerManagement/Inhibit",
"org.freedesktop.PowerManagement.Inhibit",
"Inhibit");
else
call = QDBusMessage::createMethodCall(
"org.gnome.SessionManager",
"/org/gnome/SessionManager",
"org.gnome.SessionManager",
"Inhibit");
m_state = request_busy;
QList<QVariant> args;
args << "qBittorrent";
if (m_use_gsm) args << (uint)0;
args << "Active torrents are presented";
if (m_use_gsm) args << (uint)8;
call.setArguments(args);
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
this, SLOT(OnAsyncReply(QDBusPendingCallWatcher*)));
}
void PowerManagementInhibitor::OnAsyncReply(QDBusPendingCallWatcher *call)
{
if (m_state == request_idle)
{
QDBusPendingReply<> reply = *call;
if(reply.isError())
{
qDebug("D-Bus: Reply: Error: %s", qPrintable(reply.error().message()));
m_state = error;
}
else
{
m_state = idle;
qDebug("D-Bus: PowerManagementInhibitor: Request successful");
if (m_intended_state == busy) RequestBusy();
}
}
else if (m_state == request_busy)
{
QDBusPendingReply<uint> reply = *call;
if(reply.isError())
{
qDebug("D-Bus: Reply: Error: %s", qPrintable(reply.error().message()));
if (!m_use_gsm)
{
qDebug("D-Bus: Falling back to org.gnome.SessionManager");
m_use_gsm = true;
m_state = idle;
if (m_intended_state == busy)
RequestBusy();
}
else
{
m_state = error;
}
}
else
{
m_state = busy;
m_cookie = reply.value();
qDebug("D-Bus: PowerManagementInhibitor: Request successful, cookie is %d", m_cookie);
if (m_intended_state == idle) RequestIdle();
}
}
else
{
qDebug("D-Bus: Unexpected reply in state %d", m_state);
m_state = error;
}
call->deleteLater();
}

69
src/powermanagement/powermanagement_x11.h

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
*
* 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.
*
* Contact : chris@qbittorrent.org
*/
#ifndef POWERMANAGEMENTINHIBITOR_H
#define POWERMANAGEMENTINHIBITOR_H
#include <QObject>
class QDBusPendingCallWatcher;
class PowerManagementInhibitor : public QObject
{
Q_OBJECT
public:
PowerManagementInhibitor(QObject *parent = 0);
virtual ~PowerManagementInhibitor();
void RequestIdle();
void RequestBusy();
private slots:
void OnAsyncReply(QDBusPendingCallWatcher *call);
private:
enum _state
{
error,
idle,
request_busy,
busy,
request_idle
};
enum _state m_state;
enum _state m_intended_state;
unsigned int m_cookie;
bool m_use_gsm;
};
#endif // POWERMANAGEMENTINHIBITOR_H

2
src/preferences/advancedsettings.h

@ -241,7 +241,7 @@ protected slots: @@ -241,7 +241,7 @@ protected slots:
connect(txt_network_address, SIGNAL(textChanged(QString)), this, SLOT(emitSettingsChanged()));
setCellWidget(NETWORK_ADDRESS, VALUE, txt_network_address);
// Program notifications
setItem(PROGRAM_NOTIFICATIONS, PROPERTY, new QTableWidgetItem(tr("Display program notification balloons")));
setItem(PROGRAM_NOTIFICATIONS, PROPERTY, new QTableWidgetItem(tr("Display program on-screen notifications")));
cb_program_notifications = new QCheckBox();
connect(cb_program_notifications, SIGNAL(toggled(bool)), this, SLOT(emitSettingsChanged()));
cb_program_notifications->setChecked(pref.useProgramNotification());

105
src/preferences/options.ui

@ -40,16 +40,10 @@ @@ -40,16 +40,10 @@
</property>
<property name="iconSize">
<size>
<width>30</width>
<height>30</height>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
@ -59,24 +53,18 @@ @@ -59,24 +53,18 @@
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="layoutMode">
<enum>QListView::SinglePass</enum>
</property>
<property name="spacing">
<number>0</number>
<number>4</number>
</property>
<property name="gridSize">
<size>
<width>107</width>
<width>110</width>
<height>60</height>
</size>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
@ -88,10 +76,10 @@ @@ -88,10 +76,10 @@
</property>
<item>
<property name="text">
<string extracomment="User Interface">UI</string>
<string>Behavior</string>
</property>
<property name="toolTip">
<string>User Interface</string>
<string>Behavior</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
@ -126,6 +114,9 @@ @@ -126,6 +114,9 @@
<property name="text">
<string>Speed</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</item>
<item>
<property name="text">
@ -153,6 +144,9 @@ @@ -153,6 +144,9 @@
<property name="text">
<string>Advanced</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</item>
</widget>
<widget class="QStackedWidget" name="tabOption">
@ -176,16 +170,16 @@ @@ -176,16 +170,16 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>506</width>
<height>430</height>
<y>-45</y>
<width>499</width>
<height>459</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QGroupBox" name="UISettingsBox">
<property name="title">
<string>Visual Appearance</string>
<string>Language</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<property name="bottomMargin">
@ -193,13 +187,6 @@ @@ -193,13 +187,6 @@
</property>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="lblI18n">
<property name="text">
<string>Language:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboI18n">
<property name="minimumSize">
@ -247,33 +234,6 @@ @@ -247,33 +234,6 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="lblStyle">
<property name="text">
<string>Visual style:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboStyle"/>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@ -450,6 +410,22 @@ @@ -450,6 +410,22 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Power Management</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<widget class="QCheckBox" name="checkPreventFromSuspend">
<property name="text">
<string>Inhibit system sleep when torrents are active</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
@ -481,7 +457,7 @@ @@ -481,7 +457,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>506</width>
<width>440</width>
<height>698</height>
</rect>
</property>
@ -924,7 +900,7 @@ QGroupBox { @@ -924,7 +900,7 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>506</width>
<width>447</width>
<height>457</height>
</rect>
</property>
@ -1404,8 +1380,8 @@ QGroupBox { @@ -1404,8 +1380,8 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>524</width>
<height>414</height>
<width>404</width>
<height>334</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_33">
@ -1793,7 +1769,7 @@ QGroupBox { @@ -1793,7 +1769,7 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>581</width>
<width>542</width>
<height>422</height>
</rect>
</property>
@ -2176,7 +2152,7 @@ QGroupBox { @@ -2176,7 +2152,7 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>377</width>
<width>378</width>
<height>229</height>
</rect>
</property>
@ -2339,8 +2315,8 @@ QGroupBox { @@ -2339,8 +2315,8 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>98</width>
<height>28</height>
<width>80</width>
<height>18</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_36"/>
@ -2387,7 +2363,6 @@ QGroupBox { @@ -2387,7 +2363,6 @@ QGroupBox {
<tabstops>
<tabstop>tabOption</tabstop>
<tabstop>comboI18n</tabstop>
<tabstop>comboStyle</tabstop>
<tabstop>checkCloseToSystray</tabstop>
<tabstop>checkMinimizeToSysTray</tabstop>
<tabstop>textSavePath</tabstop>

28
src/preferences/options_imp.cpp

@ -36,7 +36,6 @@ @@ -36,7 +36,6 @@
#include <QDialogButtonBox>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QStyleFactory>
#include <QTranslator>
#include <libtorrent/version.hpp>
@ -88,7 +87,6 @@ options_imp::options_imp(QWidget *parent): @@ -88,7 +87,6 @@ options_imp::options_imp(QWidget *parent):
connect(scanFoldersView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(handleScanFolderViewSelectionChanged()));
connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(applySettings(QAbstractButton*)));
comboStyle->addItems(QStyleFactory::keys());
// Languages supported
initializeLanguageCombo();
@ -126,13 +124,13 @@ options_imp::options_imp(QWidget *parent): @@ -126,13 +124,13 @@ options_imp::options_imp(QWidget *parent):
// Apply button is activated when a value is changed
// General tab
connect(comboI18n, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(comboStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(checkAltRowColors, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkShowSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkCloseToSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkMinimizeToSysTray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkStartMinimized, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkShowSplash, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkPreventFromSuspend, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
// Downloads tab
connect(textSavePath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(textTempPath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
@ -251,10 +249,6 @@ void options_imp::changePage(QListWidgetItem *current, QListWidgetItem *previous @@ -251,10 +249,6 @@ void options_imp::changePage(QListWidgetItem *current, QListWidgetItem *previous
tabOption->setCurrentIndex(tabSelection->row(current));
}
void options_imp::useStyle() {
QApplication::setStyle(QStyleFactory::create(comboStyle->itemText(comboStyle->currentIndex())));
}
void options_imp::loadWindowState() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
resize(settings.value(QString::fromUtf8("Preferences/State/size"), sizeFittingScreen()).toSize());
@ -308,8 +302,6 @@ QSize options_imp::sizeFittingScreen() { @@ -308,8 +302,6 @@ QSize options_imp::sizeFittingScreen() {
void options_imp::saveOptions(){
applyButton->setEnabled(false);
Preferences pref;
// Apply style
useStyle();
// Load the translation
QString locale = getLocale();
if(pref.getLocale() != locale) {
@ -324,13 +316,13 @@ void options_imp::saveOptions(){ @@ -324,13 +316,13 @@ void options_imp::saveOptions(){
// General preferences
pref.setLocale(locale);
pref.setStyle(getStyle());
pref.setAlternatingRowColors(checkAltRowColors->isChecked());
pref.setSystrayIntegration(systrayIntegration());
pref.setCloseToTray(closeToTray());
pref.setMinimizeToTray(minimizeToTray());
pref.setStartMinimized(startMinimized());
pref.setSplashScreenDisabled(isSlashScreenDisabled());
pref.setPreventFromSuspend(preventFromSuspend());
// End General preferences
// Downloads preferences
@ -455,16 +447,6 @@ int options_imp::getProxyType() const{ @@ -455,16 +447,6 @@ int options_imp::getProxyType() const{
}
}
QString options_imp::getStyle() const{
return comboStyle->itemText(comboStyle->currentIndex());
}
void options_imp::setStyle(QString style) {
int index = comboStyle->findText(style, Qt::MatchFixedString);
if(index > 0)
comboStyle->setCurrentIndex(index);
}
void options_imp::loadOptions(){
int intValue;
qreal floatValue;
@ -472,7 +454,6 @@ void options_imp::loadOptions(){ @@ -472,7 +454,6 @@ void options_imp::loadOptions(){
// General preferences
const Preferences pref;
setLocale(pref.getLocale());
setStyle(pref.getStyle());
checkAltRowColors->setChecked(pref.useAlternatingRowColors());
checkShowSystray->setChecked(pref.systrayIntegration());
checkShowSplash->setChecked(!pref.isSlashScreenDisabled());
@ -484,6 +465,7 @@ void options_imp::loadOptions(){ @@ -484,6 +465,7 @@ void options_imp::loadOptions(){
checkMinimizeToSysTray->setChecked(pref.minimizeToTray());
checkStartMinimized->setChecked(pref.startMinimized());
}
checkPreventFromSuspend->setChecked(pref.preventFromSuspend());
// End General preferences
// Downloads preferences
QString save_path = pref.getSavePath();
@ -928,6 +910,10 @@ bool options_imp::isSlashScreenDisabled() const { @@ -928,6 +910,10 @@ bool options_imp::isSlashScreenDisabled() const {
return !checkShowSplash->isChecked();
}
bool options_imp::preventFromSuspend() const {
return checkPreventFromSuspend->isChecked();
}
bool options_imp::preAllocateAllFiles() const {
return checkPreallocateAll->isChecked();
}

4
src/preferences/options_imp.h

@ -60,7 +60,6 @@ protected slots: @@ -60,7 +60,6 @@ protected slots:
void enableMaxConnecsLimitPerTorrent(bool checked);
void enableMaxUploadsLimitPerTorrent(bool checked);
void enableMaxRatio(bool checked);
void setStyle(QString style);
void on_buttonBox_accepted();
void closeEvent(QCloseEvent *e);
void on_buttonBox_rejected();
@ -85,7 +84,6 @@ protected slots: @@ -85,7 +84,6 @@ protected slots:
public slots:
void setLocale(QString locale);
void useStyle();
void showConnectionTab();
signals:
@ -100,12 +98,12 @@ private: @@ -100,12 +98,12 @@ private:
static QString languageToLocalizedString(QLocale::Language language, const QString& country);
// General options
QString getLocale() const;
QString getStyle() const;
bool systrayIntegration() const;
bool minimizeToTray() const;
bool closeToTray() const;
bool startMinimized() const;
bool isSlashScreenDisabled() const;
bool preventFromSuspend() const;
// Downloads
QString getSavePath() const;
bool isTempPathEnabled() const;

17
src/preferences/preferences.h

@ -77,14 +77,6 @@ public: @@ -77,14 +77,6 @@ public:
setValue(QString::fromUtf8("Preferences/General/Locale"), locale);
}
QString getStyle() const {
return value(QString::fromUtf8("Preferences/General/Style"), "").toString();
}
void setStyle(const QString &style) {
setValue(QString::fromUtf8("Preferences/General/Style"), style);
}
bool useProgramNotification() const {
return value(QString::fromUtf8("Preferences/General/ProgramNotification"), true).toBool();
}
@ -173,6 +165,15 @@ public: @@ -173,6 +165,15 @@ public:
setValue("Preferences/General/NoSplashScreen", b);
}
// Preventing from system suspend while active torrents are presented.
bool preventFromSuspend() const {
return value(QString::fromUtf8("Preferences/General/PreventFromSuspend"), false).toBool();
}
void setPreventFromSuspend(bool b) {
setValue("Preferences/General/PreventFromSuspend", b);
}
// Downloads
QString getSavePath() const {
#ifdef Q_WS_WIN

1
src/src.pro

@ -87,6 +87,7 @@ include (preferences/preferences.pri) @@ -87,6 +87,7 @@ include (preferences/preferences.pri)
include(rss/rss.pri)
include(torrentcreator/torrentcreator.pri)
include(geoip/geoip.pri)
include(powermanagement/powermanagement.pri)
}
HEADERS += misc.h \

Loading…
Cancel
Save