Skip to content

Commit

Permalink
FEATURE: Inhibit system sleep when torrents are active (Vladimir Golo…
Browse files Browse the repository at this point in the history
…vnev)

Remove visual style settings
  • Loading branch information
Christophe Dumez committed Feb 6, 2011
1 parent b45171b commit 0f1473e
Show file tree
Hide file tree
Showing 16 changed files with 573 additions and 182 deletions.
1 change: 1 addition & 0 deletions Changelog
Expand Up @@ -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)
Expand Down
127 changes: 54 additions & 73 deletions src/lang/qbittorrent_ru.ts

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions src/main.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -286,7 +277,6 @@ int main(int argc, char *argv[]){
}

#ifndef DISABLE_GUI
useStyle(pref.getStyle());
app.setStyleSheet("QStatusBar::item { border-width: 0; }");
#endif

Expand Down
31 changes: 30 additions & 1 deletion src/mainwindow.cpp
Expand Up @@ -43,6 +43,9 @@
#include <QCloseEvent>
#include <QShortcut>
#include <QScrollBar>
#ifdef Q_WS_X11
#include <QDBusInterface>
#endif

#include "mainwindow.h"
#include "transferlistwidget.h"
Expand Down Expand Up @@ -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

/*****************************************************
* *
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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()));
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 changes: 6 additions & 0 deletions src/mainwindow.h
Expand Up @@ -60,6 +60,7 @@ class HidableTabWidget;
class LineEdit;
class QFileSystemWatcher;
class ExecutionLog;
class PowerManagement;

class MainWindow : public QMainWindow, private Ui::MainWindow{
Q_OBJECT
Expand Down Expand Up @@ -182,6 +183,9 @@ protected slots:
QPointer<RSSImp> rssWidget;
// Execution Log
QPointer<ExecutionLog> m_executionLog;
// Power Management
PowerManagement *m_pwr;
QTimer *preventTimer;

private slots:
void on_actionSearch_engine_triggered();
Expand All @@ -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 changes: 90 additions & 0 deletions src/powermanagement/powermanagement.cpp
@@ -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 changes: 70 additions & 0 deletions src/powermanagement/powermanagement.h
@@ -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 changes: 9 additions & 0 deletions src/powermanagement/powermanagement.pri
@@ -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
}

0 comments on commit 0f1473e

Please sign in to comment.