mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-27 06:54:20 +00:00
- Cleanup systray code
This commit is contained in:
parent
e93fab40fe
commit
10c40c6485
78
src/GUI.cpp
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) {
|
||||
setupUi(this);
|
||||
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
|
||||
this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.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()));
|
||||
|
||||
// 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"));
|
||||
|
||||
// Configure BT session according to options
|
||||
@ -225,8 +208,8 @@ GUI::~GUI() {
|
||||
if(systrayCreator) {
|
||||
delete systrayCreator;
|
||||
}
|
||||
if(systrayIntegration) {
|
||||
delete myTrayIcon;
|
||||
if(systrayIcon) {
|
||||
delete systrayIcon;
|
||||
delete myTrayIconMenu;
|
||||
}
|
||||
qDebug("2");
|
||||
@ -495,7 +478,7 @@ void GUI::closeEvent(QCloseEvent *e) {
|
||||
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
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();
|
||||
//e->ignore();
|
||||
e->accept();
|
||||
@ -518,9 +501,9 @@ void GUI::closeEvent(QCloseEvent *e) {
|
||||
}
|
||||
}
|
||||
hide();
|
||||
if(systrayIntegration) {
|
||||
if(systrayIcon) {
|
||||
// Hide tray icon
|
||||
myTrayIcon->hide();
|
||||
systrayIcon->hide();
|
||||
}
|
||||
// Save window size, columns size
|
||||
writeSettings();
|
||||
@ -542,7 +525,7 @@ bool GUI::event(QEvent * e) {
|
||||
if(isMinimized()) {
|
||||
qDebug("minimisation");
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -682,16 +665,27 @@ void GUI::optionsSaved() {
|
||||
void GUI::loadPreferences(bool configure_session) {
|
||||
BTSession->addConsoleMessage(tr("Options were saved successfully."));
|
||||
bool newSystrayIntegration = Preferences::systrayIntegration();
|
||||
if(newSystrayIntegration != systrayIntegration) {
|
||||
if(newSystrayIntegration != (systrayIcon!=0)) {
|
||||
if(newSystrayIntegration) {
|
||||
// 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 {
|
||||
// Destroy trayicon
|
||||
delete myTrayIcon;
|
||||
delete systrayIcon;
|
||||
delete myTrayIconMenu;
|
||||
}
|
||||
systrayIntegration = newSystrayIntegration;
|
||||
}
|
||||
// General
|
||||
bool new_displaySpeedInTitle = Preferences::speedInTitleBar();
|
||||
@ -765,7 +759,7 @@ void GUI::trackerAuthenticationRequired(QTorrentHandle& h) {
|
||||
// Check connection status and display right icon
|
||||
void GUI::updateGUI() {
|
||||
// update global informations
|
||||
if(systrayIntegration) {
|
||||
if(systrayIcon) {
|
||||
#ifdef Q_WS_WIN
|
||||
// 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)));
|
||||
@ -782,7 +776,7 @@ void GUI::updateGUI() {
|
||||
html += "<img src=':/Icons/skin/seeding.png'/> "+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString(QByteArray::number(BTSession->getPayloadUploadRate()/1024., 'f', 1)));
|
||||
html += "</div>";
|
||||
#endif
|
||||
myTrayIcon->setToolTip(html); // tray icon
|
||||
systrayIcon->setToolTip(html); // tray icon
|
||||
}
|
||||
if(displaySpeedInTitle) {
|
||||
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 {
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
if(systrayIntegration && settings.value(QString::fromUtf8("Preferences/General/NotificationBaloons"), true).toBool()) {
|
||||
myTrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
|
||||
if(systrayIcon && settings.value(QString::fromUtf8("Preferences/General/NotificationBaloons"), true).toBool()) {
|
||||
systrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
|
||||
}
|
||||
}
|
||||
|
||||
@ -821,22 +815,24 @@ void GUI::downloadFromURLList(const QStringList& url_list) {
|
||||
*****************************************************/
|
||||
|
||||
void GUI::createSystrayDelayed() {
|
||||
static int timeout = 10;
|
||||
static int timeout = 20;
|
||||
if(QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||
// Ok, systray integration is now supported
|
||||
// Create systray icon
|
||||
createTrayIcon();
|
||||
systrayIntegration = true;
|
||||
delete systrayCreator;
|
||||
} else {
|
||||
if(timeout) {
|
||||
// Retry a bit later
|
||||
systrayCreator->start(1000);
|
||||
systrayCreator->start(2000);
|
||||
--timeout;
|
||||
} else {
|
||||
// Timed out, apparently system really does not
|
||||
// support systray icon
|
||||
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() {
|
||||
// Tray icon
|
||||
#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
|
||||
#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
|
||||
// Tray icon Menu
|
||||
myTrayIconMenu = new QMenu(this);
|
||||
@ -861,11 +857,11 @@ void GUI::createTrayIcon() {
|
||||
myTrayIconMenu->addAction(actionPause_All);
|
||||
myTrayIconMenu->addSeparator();
|
||||
myTrayIconMenu->addAction(actionExit);
|
||||
myTrayIcon->setContextMenu(myTrayIconMenu);
|
||||
connect(myTrayIcon, SIGNAL(messageClicked()), this, SLOT(balloonClicked()));
|
||||
systrayIcon->setContextMenu(myTrayIconMenu);
|
||||
connect(systrayIcon, SIGNAL(messageClicked()), this, SLOT(balloonClicked()));
|
||||
// End of Icon Menu
|
||||
connect(myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason)));
|
||||
myTrayIcon->show();
|
||||
connect(systrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason)));
|
||||
systrayIcon->show();
|
||||
}
|
||||
|
||||
// Display Program Options
|
||||
|
@ -66,13 +66,13 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||
private:
|
||||
// Bittorrent
|
||||
bittorrent *BTSession;
|
||||
QTimer *guiUpdater;
|
||||
QList<QPair<QTorrentHandle,QString> > unauthenticated_trackers;
|
||||
QList<QPair<QTorrentHandle,QString> > unauthenticated_trackers; // Still needed?
|
||||
// GUI related
|
||||
QTimer *guiUpdater;
|
||||
QTabWidget *tabs;
|
||||
StatusBar *status_bar;
|
||||
QPointer<options_imp> options;
|
||||
QSystemTrayIcon *myTrayIcon;
|
||||
QPointer<QSystemTrayIcon> systrayIcon;
|
||||
QPointer<QTimer> systrayCreator;
|
||||
QMenu *myTrayIconMenu;
|
||||
TransferListWidget *transferList;
|
||||
@ -80,7 +80,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||
PropertiesWidget *properties;
|
||||
QSplitter *hSplitter;
|
||||
QSplitter *vSplitter;
|
||||
bool systrayIntegration;
|
||||
bool displaySpeedInTitle;
|
||||
bool force_exit;
|
||||
//unsigned int refreshInterval;
|
||||
|
@ -67,6 +67,11 @@ public:
|
||||
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() {
|
||||
QSettings settings("qBittorrent", "qBittorrent");
|
||||
return settings.value(QString::fromUtf8("Preferences/General/ToolbarDisplayed"), true).toBool();
|
||||
|
@ -53,7 +53,7 @@
|
||||
#define SEARCHHISTORY_MAXSIZE 50
|
||||
|
||||
/*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);
|
||||
// new qCompleter to the search pattern
|
||||
startSearchHistory();
|
||||
@ -428,8 +428,8 @@ void SearchEngine::updateNova() {
|
||||
void SearchEngine::searchFinished(int exitcode,QProcess::ExitStatus){
|
||||
QSettings settings("qBittorrent", "qBittorrent");
|
||||
bool useNotificationBalloons = settings.value("Preferences/General/NotificationBaloons", true).toBool();
|
||||
if(systrayIntegration && useNotificationBalloons) {
|
||||
myTrayIcon->showMessage(tr("Search Engine"), tr("Search has finished"), QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
|
||||
if(systrayIcon && useNotificationBalloons) {
|
||||
systrayIcon->showMessage(tr("Search Engine"), tr("Search has finished"), QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
|
||||
}
|
||||
if(exitcode){
|
||||
search_status->setText(tr("An error occured during search..."));
|
||||
|
@ -63,8 +63,7 @@ private:
|
||||
QPointer<QCompleter> searchCompleter;
|
||||
QStringListModel searchHistory;
|
||||
bittorrent *BTSession;
|
||||
QSystemTrayIcon *myTrayIcon;
|
||||
bool systrayIntegration;
|
||||
QSystemTrayIcon *systrayIcon;
|
||||
SupportedEngines *supported_engines;
|
||||
QTimer *searchTimeout;
|
||||
SearchTab *currentSearchTab;
|
||||
@ -72,7 +71,7 @@ private:
|
||||
QList<SearchTab*> all_tab; // To store all tabs
|
||||
const SearchCategories full_cat_names;
|
||||
public:
|
||||
SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, bool systrayIntegration);
|
||||
SearchEngine(bittorrent *BTSession, QSystemTrayIcon *systrayIcon);
|
||||
~SearchEngine();
|
||||
float getPluginVersion(QString filePath) const;
|
||||
QString selectedCategory() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user