From b78ea79d30808857b6c8be23a27d19c373de2934 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Tue, 17 Sep 2013 16:18:01 +0400 Subject: [PATCH] Bringing the AddNewTorrentDialog to the front. --- src/addnewtorrentdialog.cpp | 7 +++++++ src/addnewtorrentdialog.h | 3 +++ src/main.cpp | 7 +++++++ src/mainwindow.cpp | 22 ++++++++++------------ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/addnewtorrentdialog.cpp b/src/addnewtorrentdialog.cpp index 883e31032..8df66315d 100644 --- a/src/addnewtorrentdialog.cpp +++ b/src/addnewtorrentdialog.cpp @@ -140,6 +140,13 @@ void AddNewTorrentDialog::showMagnet(const QString& link) dlg.exec(); } +void AddNewTorrentDialog::showEvent(QShowEvent *event) { + QDialog::showEvent(event); + activateWindow(); + raise(); +} + + void AddNewTorrentDialog::showAdvancedSettings(bool show) { if (show) { diff --git a/src/addnewtorrentdialog.h b/src/addnewtorrentdialog.h index 9ce3d9791..dec472805 100644 --- a/src/addnewtorrentdialog.h +++ b/src/addnewtorrentdialog.h @@ -56,6 +56,9 @@ public: static void showTorrent(const QString& torrent_path, const QString& from_url = QString()); static void showMagnet(const QString& torrent_link); +protected: + void showEvent(QShowEvent *event); + private slots: void showAdvancedSettings(bool show); void displayContentTreeMenu(const QPoint&); diff --git a/src/main.cpp b/src/main.cpp index 637dd43bf..a1912fb48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -206,6 +206,13 @@ int main(int argc, char *argv[]) { if (app.isRunning()) { qDebug("qBittorrent is already running for this user."); // Read torrents given on command line +#ifdef Q_OS_WIN + DWORD pid = app.getRunningPid(); + if (pid > 0) { + BOOL b = AllowSetForegroundWindow(pid); + qDebug("AllowSetForegroundWindow() returns %s", b ? "TRUE" : "FALSE"); + } +#endif QStringList torrentCmdLine = app.arguments(); //Pass program parameters if any QString message; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 241ab69b0..7ad6a0b49 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -263,14 +263,8 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa // Load Window state and sizes readSettings(); - if (!ui_locked) { - if (pref.startMinimized() && systrayIcon) { - show(); - minimizeWindow(); - // XXX: Using showMinimized() makes it impossible to restore - // the window if "Minimize to systray" is enabled. - //showMinimized(); - } else { + if (systrayIcon) { + if (!(pref.startMinimized() || ui_locked)) { show(); activateWindow(); raise(); @@ -323,10 +317,14 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa #endif // Make sure the Window is visible if we don't have a tray icon - if (!systrayIcon && isHidden()) { - show(); - activateWindow(); - raise(); + if (!systrayIcon) { + if (pref.startMinimized()) { + showMinimized(); + } else { + show(); + activateWindow(); + raise(); + } } }