Browse Source

- Cleanup systray code

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
10c40c6485
  1. 78
      src/GUI.cpp
  2. 7
      src/GUI.h
  3. 5
      src/preferences.h
  4. 6
      src/searchEngine.cpp
  5. 5
      src/searchEngine.h

78
src/GUI.cpp

@ -80,23 +80,6 @@ enum TabIndex{TAB_TRANSFER, TAB_SEARCH, TAB_RSS};
GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), displaySpeedInTitle(false), force_exit(false) { GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), displaySpeedInTitle(false), force_exit(false) {
setupUi(this); setupUi(this);
setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION))); setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION)));
systrayIntegration = Preferences::systrayIntegration();
systrayCreator = 0;
// Create tray icon
if (QSystemTrayIcon::isSystemTrayAvailable()) {
if(systrayIntegration) {
createTrayIcon();
}
}else{
if(systrayIntegration) {
// May be system startup, check again later
systrayCreator = new QTimer(this);
connect(systrayCreator, SIGNAL(timeout()), this, SLOT(createSystrayDelayed()));
systrayCreator->start(1000);
}
systrayIntegration = false;
qDebug("Info: System tray unavailable");
}
// Setting icons // Setting icons
this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.png"))); this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.png")));
actionOpen->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/open.png"))); actionOpen->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/open.png")));
@ -161,7 +144,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
connect(actionDecreasePriority, SIGNAL(triggered()), transferList, SLOT(decreasePrioSelectedTorrents())); connect(actionDecreasePriority, SIGNAL(triggered()), transferList, SLOT(decreasePrioSelectedTorrents()));
// Search engine tab // Search engine tab
searchEngine = new SearchEngine(BTSession, myTrayIcon, systrayIntegration); searchEngine = new SearchEngine(BTSession, systrayIcon);
tabs->addTab(searchEngine, QIcon(QString::fromUtf8(":/Icons/oxygen/edit-find.png")), tr("Search")); tabs->addTab(searchEngine, QIcon(QString::fromUtf8(":/Icons/oxygen/edit-find.png")), tr("Search"));
// Configure BT session according to options // Configure BT session according to options
@ -225,8 +208,8 @@ GUI::~GUI() {
if(systrayCreator) { if(systrayCreator) {
delete systrayCreator; delete systrayCreator;
} }
if(systrayIntegration) { if(systrayIcon) {
delete myTrayIcon; delete systrayIcon;
delete myTrayIconMenu; delete myTrayIconMenu;
} }
qDebug("2"); qDebug("2");
@ -495,7 +478,7 @@ 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(); bool goToSystrayOnExit = settings.value(QString::fromUtf8("Preferences/General/CloseToTray"), false).toBool();
if(!force_exit && systrayIntegration && goToSystrayOnExit && !this->isHidden()) { if(!force_exit && systrayIcon && goToSystrayOnExit && !this->isHidden()) {
hide(); hide();
//e->ignore(); //e->ignore();
e->accept(); e->accept();
@ -518,9 +501,9 @@ void GUI::closeEvent(QCloseEvent *e) {
} }
} }
hide(); hide();
if(systrayIntegration) { if(systrayIcon) {
// Hide tray icon // Hide tray icon
myTrayIcon->hide(); systrayIcon->hide();
} }
// Save window size, columns size // Save window size, columns size
writeSettings(); writeSettings();
@ -542,7 +525,7 @@ bool GUI::event(QEvent * e) {
if(isMinimized()) { if(isMinimized()) {
qDebug("minimisation"); qDebug("minimisation");
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
if(systrayIntegration && settings.value(QString::fromUtf8("Preferences/General/MinimizeToTray"), false).toBool()) { if(systrayIcon && settings.value(QString::fromUtf8("Preferences/General/MinimizeToTray"), false).toBool()) {
hide(); hide();
} }
} }
@ -682,16 +665,27 @@ void GUI::optionsSaved() {
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(); bool newSystrayIntegration = Preferences::systrayIntegration();
if(newSystrayIntegration != systrayIntegration) { if(newSystrayIntegration != (systrayIcon!=0)) {
if(newSystrayIntegration) { if(newSystrayIntegration) {
// create the trayicon // create the trayicon
createTrayIcon(); if(!QSystemTrayIcon::isSystemTrayAvailable()) {
if(!configure_session) { // Program startup
systrayCreator = new QTimer(this);
connect(systrayCreator, SIGNAL(timeout()), this, SLOT(createSystrayDelayed()));
systrayCreator->setSingleShot(true);
systrayCreator->start(2000);
qDebug("Info: System tray is unavailable, trying again later.");
} else {
qDebug("Warning: System tray is unavailable.");
}
} else {
createTrayIcon();
}
} else { } else {
// Destroy trayicon // Destroy trayicon
delete myTrayIcon; delete systrayIcon;
delete myTrayIconMenu; delete myTrayIconMenu;
} }
systrayIntegration = newSystrayIntegration;
} }
// General // General
bool new_displaySpeedInTitle = Preferences::speedInTitleBar(); bool new_displaySpeedInTitle = Preferences::speedInTitleBar();
@ -765,7 +759,7 @@ void GUI::trackerAuthenticationRequired(QTorrentHandle& h) {
// Check connection status and display right icon // Check connection status and display right icon
void GUI::updateGUI() { void GUI::updateGUI() {
// update global informations // update global informations
if(systrayIntegration) { 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(QByteArray::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1)));
@ -782,7 +776,7 @@ void GUI::updateGUI() {
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(QByteArray::number(BTSession->getPayloadUploadRate()/1024., 'f', 1)));
html += "</div>"; html += "</div>";
#endif #endif
myTrayIcon->setToolTip(html); // tray icon systrayIcon->setToolTip(html); // tray icon
} }
if(displaySpeedInTitle) { if(displaySpeedInTitle) {
QString dl_rate = QByteArray::number(BTSession->getSessionStatus().payload_download_rate/1024, 'f', 1); QString dl_rate = QByteArray::number(BTSession->getSessionStatus().payload_download_rate/1024, 'f', 1);
@ -793,8 +787,8 @@ void GUI::updateGUI() {
void GUI::showNotificationBaloon(QString title, QString msg) const { void GUI::showNotificationBaloon(QString title, QString msg) const {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
if(systrayIntegration && settings.value(QString::fromUtf8("Preferences/General/NotificationBaloons"), true).toBool()) { if(systrayIcon && settings.value(QString::fromUtf8("Preferences/General/NotificationBaloons"), true).toBool()) {
myTrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, TIME_TRAY_BALLOON); systrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
} }
} }
@ -821,22 +815,24 @@ void GUI::downloadFromURLList(const QStringList& url_list) {
*****************************************************/ *****************************************************/
void GUI::createSystrayDelayed() { void GUI::createSystrayDelayed() {
static int timeout = 10; static int timeout = 20;
if(QSystemTrayIcon::isSystemTrayAvailable()) { if(QSystemTrayIcon::isSystemTrayAvailable()) {
// Ok, systray integration is now supported // Ok, systray integration is now supported
// Create systray icon // Create systray icon
createTrayIcon(); createTrayIcon();
systrayIntegration = true;
delete systrayCreator; delete systrayCreator;
} else { } else {
if(timeout) { if(timeout) {
// Retry a bit later // Retry a bit later
systrayCreator->start(1000); systrayCreator->start(2000);
--timeout; --timeout;
} else { } else {
// Timed out, apparently system really does not // Timed out, apparently system really does not
// support systray icon // support systray icon
delete systrayCreator; delete systrayCreator;
// Disable it in program preferences to
// avoid trying at earch startup
Preferences::setSystrayIntegration(false);
} }
} }
} }
@ -844,10 +840,10 @@ void GUI::createSystrayDelayed() {
void GUI::createTrayIcon() { void GUI::createTrayIcon() {
// Tray icon // Tray icon
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
myTrayIcon = new QSystemTrayIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent16.png")), this); systrayIcon = new QSystemTrayIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent16.png")), this);
#endif #endif
#ifndef Q_WS_WIN #ifndef Q_WS_WIN
myTrayIcon = new QSystemTrayIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent22.png")), this); systrayIcon = new QSystemTrayIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent22.png")), this);
#endif #endif
// Tray icon Menu // Tray icon Menu
myTrayIconMenu = new QMenu(this); myTrayIconMenu = new QMenu(this);
@ -861,11 +857,11 @@ void GUI::createTrayIcon() {
myTrayIconMenu->addAction(actionPause_All); myTrayIconMenu->addAction(actionPause_All);
myTrayIconMenu->addSeparator(); myTrayIconMenu->addSeparator();
myTrayIconMenu->addAction(actionExit); myTrayIconMenu->addAction(actionExit);
myTrayIcon->setContextMenu(myTrayIconMenu); systrayIcon->setContextMenu(myTrayIconMenu);
connect(myTrayIcon, SIGNAL(messageClicked()), this, SLOT(balloonClicked())); connect(systrayIcon, SIGNAL(messageClicked()), this, SLOT(balloonClicked()));
// End of Icon Menu // End of Icon Menu
connect(myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason))); connect(systrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason)));
myTrayIcon->show(); systrayIcon->show();
} }
// Display Program Options // Display Program Options

7
src/GUI.h

@ -66,13 +66,13 @@ class GUI : public QMainWindow, private Ui::MainWindow{
private: private:
// Bittorrent // Bittorrent
bittorrent *BTSession; bittorrent *BTSession;
QTimer *guiUpdater; QList<QPair<QTorrentHandle,QString> > unauthenticated_trackers; // Still needed?
QList<QPair<QTorrentHandle,QString> > unauthenticated_trackers;
// GUI related // GUI related
QTimer *guiUpdater;
QTabWidget *tabs; QTabWidget *tabs;
StatusBar *status_bar; StatusBar *status_bar;
QPointer<options_imp> options; QPointer<options_imp> options;
QSystemTrayIcon *myTrayIcon; QPointer<QSystemTrayIcon> systrayIcon;
QPointer<QTimer> systrayCreator; QPointer<QTimer> systrayCreator;
QMenu *myTrayIconMenu; QMenu *myTrayIconMenu;
TransferListWidget *transferList; TransferListWidget *transferList;
@ -80,7 +80,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
PropertiesWidget *properties; PropertiesWidget *properties;
QSplitter *hSplitter; QSplitter *hSplitter;
QSplitter *vSplitter; QSplitter *vSplitter;
bool systrayIntegration;
bool displaySpeedInTitle; bool displaySpeedInTitle;
bool force_exit; bool force_exit;
//unsigned int refreshInterval; //unsigned int refreshInterval;

5
src/preferences.h

@ -67,6 +67,11 @@ public:
return settings.value(QString::fromUtf8("Preferences/General/SystrayEnabled"), true).toBool(); return settings.value(QString::fromUtf8("Preferences/General/SystrayEnabled"), true).toBool();
} }
static void setSystrayIntegration(bool enabled) {
QSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/General/SystrayEnabled"), enabled);
}
static bool isToolbarDisplayed() { static bool isToolbarDisplayed() {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/General/ToolbarDisplayed"), true).toBool(); return settings.value(QString::fromUtf8("Preferences/General/ToolbarDisplayed"), true).toBool();

6
src/searchEngine.cpp

@ -53,7 +53,7 @@
#define SEARCHHISTORY_MAXSIZE 50 #define SEARCHHISTORY_MAXSIZE 50
/*SEARCH ENGINE START*/ /*SEARCH ENGINE START*/
SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, bool systrayIntegration) : QWidget(), BTSession(BTSession), myTrayIcon(myTrayIcon), systrayIntegration(systrayIntegration){ SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *systrayIcon) : QWidget(), BTSession(BTSession), systrayIcon(systrayIcon) {
setupUi(this); setupUi(this);
// new qCompleter to the search pattern // new qCompleter to the search pattern
startSearchHistory(); startSearchHistory();
@ -428,8 +428,8 @@ void SearchEngine::updateNova() {
void SearchEngine::searchFinished(int exitcode,QProcess::ExitStatus){ void SearchEngine::searchFinished(int exitcode,QProcess::ExitStatus){
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
bool useNotificationBalloons = settings.value("Preferences/General/NotificationBaloons", true).toBool(); bool useNotificationBalloons = settings.value("Preferences/General/NotificationBaloons", true).toBool();
if(systrayIntegration && useNotificationBalloons) { if(systrayIcon && useNotificationBalloons) {
myTrayIcon->showMessage(tr("Search Engine"), tr("Search has finished"), QSystemTrayIcon::Information, TIME_TRAY_BALLOON); systrayIcon->showMessage(tr("Search Engine"), tr("Search has finished"), QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
} }
if(exitcode){ if(exitcode){
search_status->setText(tr("An error occured during search...")); search_status->setText(tr("An error occured during search..."));

5
src/searchEngine.h

@ -63,8 +63,7 @@ private:
QPointer<QCompleter> searchCompleter; QPointer<QCompleter> searchCompleter;
QStringListModel searchHistory; QStringListModel searchHistory;
bittorrent *BTSession; bittorrent *BTSession;
QSystemTrayIcon *myTrayIcon; QSystemTrayIcon *systrayIcon;
bool systrayIntegration;
SupportedEngines *supported_engines; SupportedEngines *supported_engines;
QTimer *searchTimeout; QTimer *searchTimeout;
SearchTab *currentSearchTab; SearchTab *currentSearchTab;
@ -72,7 +71,7 @@ private:
QList<SearchTab*> all_tab; // To store all tabs QList<SearchTab*> all_tab; // To store all tabs
const SearchCategories full_cat_names; const SearchCategories full_cat_names;
public: public:
SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, bool systrayIntegration); SearchEngine(bittorrent *BTSession, QSystemTrayIcon *systrayIcon);
~SearchEngine(); ~SearchEngine();
float getPluginVersion(QString filePath) const; float getPluginVersion(QString filePath) const;
QString selectedCategory() const; QString selectedCategory() const;

Loading…
Cancel
Save