From 099cc6c11c61c31c5d131fdbcff4d6a941b70080 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Thu, 14 Apr 2011 23:58:30 +0000 Subject: [PATCH] Adding a link from the browser now starts RetroShare when it is not running. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4157 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/MainWindow.h | 4 ++-- .../src/gui/settings/rsharesettings.cpp | 2 +- retroshare-gui/src/main.cpp | 20 +++++++++++++++---- retroshare-gui/src/util/EventReceiver.cpp | 9 --------- retroshare-gui/src/util/EventReceiver.h | 1 - 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/retroshare-gui/src/gui/MainWindow.h b/retroshare-gui/src/gui/MainWindow.h index 4ec7838a4..a9d6fa761 100644 --- a/retroshare-gui/src/gui/MainWindow.h +++ b/retroshare-gui/src/gui/MainWindow.h @@ -150,6 +150,8 @@ public slots: void updateTransfers(int count); void privateChatChanged(int list, int type); + void linkActivated(const QUrl &url); + protected: /** Default Constructor */ MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0); @@ -202,8 +204,6 @@ private slots: void on_actionQuick_Start_Wizard_activated(); - void linkActivated(const QUrl &url); - private: /** Create the actions on the tray menu or menubar */ diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index f13f2a182..b3c291a54 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -500,8 +500,8 @@ bool RshareSettings::getRetroShareProtocol() } #else /* Platforms other than windows aren't supported yet */ - return false; #endif + return false; } /** Register retroshare:// as protocl */ diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 4d1b6f1c5..705ff56ba 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -43,6 +43,7 @@ #include "idle/idle.h" #include "gui/common/Emoticons.h" #include "util/EventReceiver.h" +#include "gui/RetroShareLink.h" /*** WINDOWS DON'T LIKE THIS - REDEFINES VER numbers. #include @@ -108,12 +109,15 @@ int main(int argc, char *argv[]) Rshare rshare(args, argc, argv, QString::fromStdString(RsInit::RsConfigDirectory())); - std::string link = RsInit::getRetroShareLink(); - if (!link.empty()) { + std::string url = RsInit::getRetroShareLink(); + if (!url.empty()) { /* start with RetroShare link */ EventReceiver eventReceiver; - eventReceiver.sendRetroShareLink(QString::fromStdString(link)); - return 0; + if (eventReceiver.sendRetroShareLink(QString::fromStdString(url))) { + return 0; + } + + /* Start RetroShare */ } QSplashScreen splashScreen(QPixmap(":/images/splash.png")/* , Qt::WindowStaysOnTopHint*/); @@ -247,6 +251,14 @@ int main(int argc, char *argv[]) } } + if (!url.empty()) { + /* Now use link from the command line, because no RetroShare was running */ + RetroShareLink link(QString::fromStdString(url)); + if (link.valid()) { + w->linkActivated(link.toUrl()); + } + } + // I'm using a signal to transfer the hashing info to the mainwindow, because Qt schedules signals properly to // avoid clashes between infos from threads. // diff --git a/retroshare-gui/src/util/EventReceiver.cpp b/retroshare-gui/src/util/EventReceiver.cpp index 225ca32c5..3c16154ed 100644 --- a/retroshare-gui/src/util/EventReceiver.cpp +++ b/retroshare-gui/src/util/EventReceiver.cpp @@ -91,18 +91,10 @@ bool EventReceiver::start() return result; } -void EventReceiver::showNoRunningInstanceFound() -{ - QMessageBox mb(QMessageBox::Critical, "RetroShare", QObject::tr("No running instance of RetroShare found."), QMessageBox::Ok); - mb.setWindowIcon(QIcon(":/images/rstray3.png")); - mb.exec(); -} - bool EventReceiver::sendRetroShareLink(const QString& link) { if (!sharedMMemory.attach()) { /* No running instance found */ - showNoRunningInstanceFound(); return false; } @@ -122,7 +114,6 @@ bool EventReceiver::sendRetroShareLink(const QString& link) SendMessage((HWND) info->wid, WM_COPYDATA, (WPARAM) 0, (LPARAM) (PCOPYDATASTRUCT) &send); } else { - showNoRunningInstanceFound(); result = false; } #else diff --git a/retroshare-gui/src/util/EventReceiver.h b/retroshare-gui/src/util/EventReceiver.h index 410abba7a..a755b2a92 100644 --- a/retroshare-gui/src/util/EventReceiver.h +++ b/retroshare-gui/src/util/EventReceiver.h @@ -47,7 +47,6 @@ signals: void linkReceived(const QUrl& url); private: - void showNoRunningInstanceFound(); void received(const QString& url); #ifdef WINDOWS_SYS