mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Merge pull request #900 from glassez/btf
Bringing the AddNewTorrentDialog to the front.
This commit is contained in:
commit
2b03f2382a
@ -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) {
|
||||
|
@ -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&);
|
||||
|
11
src/main.cpp
11
src/main.cpp
@ -75,6 +75,10 @@ Q_IMPORT_PLUGIN(qico)
|
||||
#include "misc.h"
|
||||
#include "preferences.h"
|
||||
|
||||
#if defined(Q_OS_WIN) && !defined(QBT_HAS_GETCURRENTPID)
|
||||
#error You seem to have updated QtSingleApplication without porting our custom QtSingleApplication::getRunningPid() function. Please see previous version to understate how it works.
|
||||
#endif
|
||||
|
||||
class UsageDisplay: public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
@ -206,6 +210,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 = (DWORD)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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,8 +201,55 @@ void QtLocalPeer::receiveConnection()
|
||||
return;
|
||||
}
|
||||
QString message(QString::fromUtf8(uMsg));
|
||||
#ifdef Q_OS_WIN
|
||||
if (message == "qbt://pid") {
|
||||
qint64 pid = GetCurrentProcessId();
|
||||
socket->write((const char *)&pid, sizeof pid);
|
||||
} else {
|
||||
socket->write(ack, qstrlen(ack));
|
||||
}
|
||||
#else
|
||||
socket->write(ack, qstrlen(ack));
|
||||
#endif
|
||||
socket->waitForBytesWritten(1000);
|
||||
delete socket;
|
||||
#ifdef Q_OS_WIN
|
||||
if (message == "qbt://pid")
|
||||
return;
|
||||
#endif
|
||||
emit messageReceived(message); //### (might take a long time to return)
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
qint64 QtLocalPeer::getRunningPid() {
|
||||
if (!isClient())
|
||||
return 0;
|
||||
|
||||
QLocalSocket socket;
|
||||
bool connOk = false;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
// Try twice, in case the other instance is just starting up
|
||||
socket.connectToServer(socketName);
|
||||
connOk = socket.waitForConnected(5000/2);
|
||||
if (connOk || i)
|
||||
break;
|
||||
Sleep(250);
|
||||
}
|
||||
if (!connOk) return -1;
|
||||
|
||||
const char* msg = "qbt://pid";
|
||||
QDataStream ds(&socket);
|
||||
ds.writeBytes(msg, qstrlen(msg));
|
||||
bool res = socket.waitForBytesWritten(5000) && socket.waitForReadyRead(5000);
|
||||
if (!res) return -1;
|
||||
|
||||
DWORD pid;
|
||||
qint64 pid_size = sizeof pid;
|
||||
while (socket.bytesAvailable() < pid_size)
|
||||
socket.waitForReadyRead();
|
||||
if (socket.read((char *)&pid, pid_size) < pid_size)
|
||||
return -1;
|
||||
|
||||
return pid;
|
||||
}
|
||||
#endif
|
||||
|
@ -64,6 +64,9 @@ public:
|
||||
bool sendMessage(const QString &message, int timeout);
|
||||
QString applicationId() const
|
||||
{ return id; }
|
||||
#ifdef Q_OS_WIN
|
||||
qint64 getRunningPid();
|
||||
#endif
|
||||
|
||||
Q_SIGNALS:
|
||||
void messageReceived(const QString &message);
|
||||
|
@ -349,3 +349,9 @@ void QtSingleApplication::activateWindow()
|
||||
|
||||
\obsolete
|
||||
*/
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
qint64 QtSingleApplication::getRunningPid() {
|
||||
return peer->getRunningPid();
|
||||
}
|
||||
#endif
|
||||
|
@ -88,6 +88,10 @@ public:
|
||||
// Obsolete:
|
||||
void initialize(bool dummy = true)
|
||||
{ isRunning(); Q_UNUSED(dummy) }
|
||||
#ifdef Q_OS_WIN
|
||||
#define QBT_HAS_GETCURRENTPID
|
||||
qint64 getRunningPid();
|
||||
#endif
|
||||
|
||||
public Q_SLOTS:
|
||||
bool sendMessage(const QString &message, int timeout = 5000);
|
||||
|
Loading…
Reference in New Issue
Block a user