Merge pull request #297 from PhenomRetroShare/Add_AllowOnlyOneIntanceAndPassArg

Allow only one instance. If exists, pass to it arguments.
This commit is contained in:
Cyril Soler 2016-04-07 00:09:00 -04:00
commit c8cae4c33c
19 changed files with 547 additions and 426 deletions

View File

@ -2,8 +2,10 @@
Version=1.0
Name=RetroShare06
Comment=Securely share files with your friends
Exec=/usr/bin/RetroShare06
Exec=/usr/bin/RetroShare06 %U
Icon=/usr/share/pixmaps/retroshare06.xpm
Terminal=false
Type=Application
Categories=Network;P2P;
MimeType=x-scheme-handler/retroshare

View File

@ -3,9 +3,10 @@ Encoding=UTF-8
Version=1.0
Name=RetroShare06
Comment=Securely share files with your friends
Exec=/usr/bin/RetroShare06
Exec=/usr/bin/RetroShare06 %U
Icon=/usr/share/pixmaps/retroshare06.xpm
Terminal=false
Type=Application
Categories=Application;Network;
MimeType=x-scheme-handler/retroshare

View File

@ -98,8 +98,7 @@ class RsInit
* Post Login Options
*/
static bool getStartMinimised() ;
static std::string getRetroShareLink();
static bool getStartMinimised();
static int getSslPwdLen();
static bool getAutoLogin();

View File

@ -128,8 +128,6 @@ class RsInitConfig
std::string load_trustedpeer_file;
bool udpListenerOnly;
std::string RetroShareLink;
};
static RsInitConfig *rsInitConfig = NULL;
@ -363,7 +361,8 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck
>> parameter('p',"port" ,rsInitConfig->port ,"port", "Set listenning port to use." ,false)
>> parameter('c',"base-dir" ,opt_base_dir ,"directory", "Set base directory." ,false)
>> parameter('U',"user-id" ,prefUserString ,"ID", "[User Name/GPG id/SSL id] Sets Account to Use, Useful when Autologin is enabled",false)
>> parameter('r',"link" ,rsInitConfig->RetroShareLink ,"retroshare://...", "Use a given Retroshare Link" ,false)
// by rshare 'r' "link" "Link" "Open RsLink with protocol retroshare://"
// by rshare 'f' "rsfile" "RsFile" "Open RsFile like RsCollection"
#ifdef LOCALNET_TESTING
>> parameter('R',"restrict-port" ,portRestrictions ,"port1-port2","Apply port restriction" ,false)
#endif
@ -774,11 +773,6 @@ bool RsInit::getStartMinimised()
return rsInitConfig->startMinimised;
}
std::string RsInit::getRetroShareLink()
{
return rsInitConfig->RetroShareLink;
}
int RsInit::getSslPwdLen(){
return SSLPWD_LEN;
}

48
retroshare-gui/src/Info.plist Executable file
View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleIconFile</key>
<string>rsMacIcon</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleGetInfoString</key>
<string>RetroShare is a Free and Open Source cross-platform, Friend-2-Friends ans secure decentralised communication platform.</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleExecutable</key>
<string>RetroShare06</string>
<key>CFBundleIdentifier</key>
<string>com.RetroShare06</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>RetroShare Collection</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>rscollection</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
<key>NOTE</key>
<string>This file was generated by Qt/QMake.</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>RetroShare URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>retroshare</string>
</array>
</dict>
</array>
</dict>
</plist>

View File

@ -203,6 +203,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
}
setWindowTitle(tr("RetroShare %1 a secure decentralized communication platform").arg(Rshare::retroshareVersion(true)) + " - " + nameAndLocation);
connect(rApp, SIGNAL(newArgsReceived(QStringList)), this, SLOT(receiveNewArgs(QStringList)));
/* add url handler for RetroShare links */
QDesktopServices::setUrlHandler(RSLINK_SCHEME, this, "retroshareLinkActivated");
@ -1095,6 +1096,12 @@ void MainWindow::doQuit()
rApp->quit();
}
void MainWindow::receiveNewArgs(QStringList args)
{
Rshare::parseArguments(args, false);
processLastArgs();
}
void MainWindow::displayErrorMessage(int /*a*/,int /*b*/,const QString& error_msg)
{
QMessageBox::critical(NULL, tr("Internal Error"),error_msg) ;
@ -1433,6 +1440,33 @@ void MainWindow::retroshareLinkActivated(const QUrl &url)
RetroShareLink::process(links);
}
void MainWindow::openRsCollection(const QString &filename)
{
QFileInfo qinfo(filename);
if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) {
RsCollectionFile collection;
collection.openColl(qinfo.absoluteFilePath());
}
}
}
void MainWindow::processLastArgs()
{
while (!Rshare::links()->isEmpty()) {
std::cerr << "MainWindow::processLastArgs() : " << Rshare::links()->count() << std::endl;
/* Now use links from the command line, because no RetroShare was running */
RetroShareLink link(Rshare::links()->takeFirst());
if (link.valid()) {
retroshareLinkActivated(link.toUrl());
}
}
while (!Rshare::files()->isEmpty()) {
/* Now use files from the command line, because no RetroShare was running */
openRsCollection(Rshare::files()->takeFirst());
}
}
//void MainWindow::servicePermission()
//{
// ServicePermissionDialog::showYourself();

View File

@ -173,13 +173,16 @@ public:
SysTrayStatus *sysTrayStatusInstance();
public slots:
void receiveNewArgs(QStringList args);
void displayErrorMessage(int,int,const QString&) ;
void postModDirectories(bool update_local);
void displayDiskSpaceWarning(int loc,int size_limit_mb) ;
void checkAndSetIdle(int idleTime);
void retroshareLinkActivated(const QUrl &url);
void externalLinkActivated(const QUrl &url);
void retroshareLinkActivated(const QUrl &url);
void openRsCollection(const QString &filename);
void processLastArgs();
//! Go to a specific part of the control panel.
void setNewPage(int page);
void setCompactStatusMode(bool compact);

View File

@ -49,18 +49,31 @@ GeneralPage::GeneralPage(QWidget * parent, Qt::WindowFlags flags)
ui.chkRunRetroshareAtSystemStartupMinimized->setEnabled(false);
#endif
if (Settings->canSetRetroShareProtocol() == false) {
ui.enableRetroShareProtocol->setEnabled(false);
} else {
ui.adminLabel->setEnabled(false);
ui.adminLabel->setToolTip("");
}
#else
ui.chkRunRetroshareAtSystemStartup->setVisible(false);
ui.chkRunRetroshareAtSystemStartupMinimized->setVisible(false);
ui.enableRetroShareProtocol->setVisible(false);
ui.registerRetroShareProtocol->setVisible(false);
ui.adminLabel->setVisible(false);
#endif
if (Settings->canSetRetroShareProtocol()) {
ui.registerRetroShareProtocol->setEnabled(true);
#ifdef Q_OS_WIN
ui.adminLabel->setEnabled(true);
ui.adminLabel->setToolTip(tr("You have enough right."));
#else
ui.desktopFileMissingLabel->setVisible(false);
#endif
} else {
ui.registerRetroShareProtocol->setEnabled(false);
#ifdef Q_OS_WIN
ui.adminLabel->setEnabled(false);
ui.adminLabel->setToolTip(tr("You don't have enough right. Run RetroShare as Admin to change this setting."));
#else
ui.desktopFileMissingLabel->setVisible(true);
#endif
}
ui.useLocalServer->setEnabled(true);
}
/** Destructor */
@ -75,42 +88,44 @@ void GeneralPage::runStartWizard()
/** Saves the changes on this page */
bool GeneralPage::save(QString &/*errmsg*/)
{
Settings->setStartMinimized(ui.checkStartMinimized->isChecked());
Settings->setValue("doQuit", ui.checkQuit->isChecked());
Settings->setCloseToTray(ui.checkCloseToTray->isChecked());
#ifdef Q_OS_WIN
#ifndef QT_DEBUG
Settings->setRunRetroshareOnBoot(ui.chkRunRetroshareAtSystemStartup->isChecked(), ui.chkRunRetroshareAtSystemStartupMinimized->isChecked());
#endif
if (ui.enableRetroShareProtocol->isChecked() != Settings->getRetroShareProtocol()) {
if (Settings->setRetroShareProtocol(ui.enableRetroShareProtocol->isChecked()) == false) {
if (ui.enableRetroShareProtocol->isChecked()) {
QMessageBox::critical(this, tr("Error"), tr("Could not add retroshare:// as protocol."));
} else {
QMessageBox::critical(this, tr("Error"), tr("Could not remove retroshare:// protocol."));
}
}
}
#endif
Settings->setMaxTimeBeforeIdle(ui.spinBox->value());
RsInit::setAutoLogin(ui.autoLogin->isChecked());
Settings->setStartMinimized(ui.checkStartMinimized->isChecked());
if (ui.checkAdvanced->isChecked())
{
std::string opt("YES");
rsConfig->setConfigurationOption(RS_CONFIG_ADVANCED, opt);
std::string opt("YES");
rsConfig->setConfigurationOption(RS_CONFIG_ADVANCED, opt);
}
else
{
std::string opt("NO");
rsConfig->setConfigurationOption(RS_CONFIG_ADVANCED, opt);
std::string opt("NO");
rsConfig->setConfigurationOption(RS_CONFIG_ADVANCED, opt);
}
Settings->setValue("doQuit", ui.checkQuit->isChecked());
Settings->setCloseToTray(ui.checkCloseToTray->isChecked());
RsInit::setAutoLogin(ui.autoLogin->isChecked());
if (ui.registerRetroShareProtocol->isChecked() != Settings->getRetroShareProtocol()) {
QString error ="";
if (Settings->setRetroShareProtocol(ui.registerRetroShareProtocol->isChecked(), error) == false) {
if (ui.registerRetroShareProtocol->isChecked()) {
QMessageBox::critical(this, tr("Error"), tr("Could not add retroshare:// as protocol.").append("\n").append(error));
} else {
QMessageBox::critical(this, tr("Error"), tr("Could not remove retroshare:// protocol.").append("\n").append(error));
}
}
}
Settings->setUseLocalServer(ui.useLocalServer->isChecked());
Settings->setMaxTimeBeforeIdle(ui.idleSpinBox->value());
return true;
}
@ -121,25 +136,23 @@ void GeneralPage::load()
bool minimized;
ui.chkRunRetroshareAtSystemStartup->setChecked(Settings->runRetroshareOnBoot(minimized));
ui.chkRunRetroshareAtSystemStartupMinimized->setChecked(minimized);
ui.enableRetroShareProtocol->setChecked(Settings->getRetroShareProtocol());
#endif
ui.checkStartMinimized->setChecked(Settings->getStartMinimized());
ui.checkQuit->setChecked(Settings->value("doQuit", false).toBool());
ui.checkCloseToTray->setChecked(Settings->getCloseToTray());
ui.spinBox->setValue(Settings->getMaxTimeBeforeIdle());
ui.autoLogin->setChecked(RsInit::getAutoLogin());
bool advancedmode = false;
std::string advsetting;
if (rsConfig->getConfigurationOption(RS_CONFIG_ADVANCED, advsetting) && (advsetting == "YES"))
{
advancedmode = true;
advancedmode = true;
}
ui.checkAdvanced->setChecked(advancedmode);
ui.checkQuit->setChecked(Settings->value("doQuit", false).toBool());
ui.checkCloseToTray->setChecked(Settings->getCloseToTray());
ui.autoLogin->setChecked(RsInit::getAutoLogin());
ui.registerRetroShareProtocol->setChecked(Settings->getRetroShareProtocol());
ui.useLocalServer->setChecked(Settings->getUseLocalServer());
ui.idleSpinBox->setValue(Settings->getMaxTimeBeforeIdle());
}

View File

@ -10,13 +10,13 @@
<height>465</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout">
<item>
<widget class="QGroupBox" name="groupBox_2">
<widget class="QGroupBox" name="startupGBox">
<property name="title">
<string>Startup</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<layout class="QGridLayout" name="startupGBoxGLayout">
<property name="verticalSpacing">
<number>2</number>
</property>
@ -35,9 +35,9 @@
</widget>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="runRetroshareAtSystemStartupMinimizedHLayout">
<item>
<spacer name="horizontalSpacer">
<spacer name="runRetroshareAtSystemStartupMinimizedHSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -65,11 +65,11 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<widget class="QGroupBox" name="advGBox">
<property name="title">
<string>For Advanced Users </string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="advGBoxVLayout">
<item>
<widget class="QCheckBox" name="checkAdvanced">
<property name="text">
@ -81,11 +81,11 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="miscGBox">
<property name="title">
<string>Misc</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="miscGBoxGLayout">
<property name="verticalSpacing">
<number>2</number>
</property>
@ -111,9 +111,9 @@
</widget>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="retroshareProtocolHLayout">
<item>
<widget class="QCheckBox" name="enableRetroShareProtocol">
<widget class="QCheckBox" name="registerRetroShareProtocol">
<property name="minimumSize">
<size>
<width>0</width>
@ -121,7 +121,7 @@
</size>
</property>
<property name="text">
<string>Register retroshare:// as URL protocol (Restart required)</string>
<string>Register retroshare:// as URL protocol</string>
</property>
</widget>
</item>
@ -143,24 +143,53 @@
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="useLocalServer">
<property name="toolTip">
<string>When checked, this instance receives new parameters (like RsLink or RsFile) and avoid new one.</string>
</property>
<property name="text">
<string>Use Local Server to get new arguments.</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="desktopFileMissingLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Install RetroShare with a package installer to get&lt;/p&gt;&lt;p&gt;/usr/share/applications/retroshare06.desktop&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>!!!The RetroShare's desktop file is missing or wrong!!!</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<widget class="QGroupBox" name="idleGBox">
<property name="title">
<string>Idle</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="idleGBoxHLayout">
<item>
<widget class="QLabel" name="label">
<widget class="QLabel" name="idleLabel">
<property name="text">
<string>Idle Time</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox">
<widget class="QSpinBox" name="idleSpinBox">
<property name="suffix">
<string> seconds</string>
</property>
@ -176,7 +205,7 @@
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<spacer name="mainVSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>

View File

@ -741,31 +741,47 @@ RshareSettings::setRunRetroshareOnBoot(bool run, bool minimized)
#endif
}
#if defined(Q_OS_WIN)
static QString getAppPathForProtocol()
{
#if defined(Q_OS_WIN)
return "\"" + QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + "\" -r \"%1\"";
}
#elif defined(Q_OS_LINUX)
return QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + " %U";
#endif
}
/** Returns true if retroshare:// is registered as protocol */
bool RshareSettings::getRetroShareProtocol()
{
#if defined(Q_OS_WIN)
/* Check key */
QSettings retroshare("HKEY_CLASSES_ROOT\\retroshare", QSettings::NativeFormat);
QSettings retroshare("HKEY_CURRENT_USER\\Software\\Classes\\retroshare", QSettings::NativeFormat);
if (retroshare.contains("Default")) {
/* Check profile */
if (retroshare.value("Profile").toString().toStdString() == rsPeers->getOwnId().toStdString()) {
/* URL Protocol */
if (retroshare.contains("URL Protocol")) {
/* Check app path */
QSettings command("HKEY_CLASSES_ROOT\\retroshare\\shell\\open\\command", QSettings::NativeFormat);
QSettings command("HKEY_CURRENT_USER\\Software\\Classes\\retroshare\\shell\\open\\command", QSettings::NativeFormat);
if (command.value("Default").toString() == getAppPathForProtocol()) {
return true;
}
}
}
#elif defined(Q_OS_LINUX)
QFile desktop("/usr/share/applications/retroshare06.desktop");
if (desktop.exists()) {
desktop.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&desktop);
QStringList lines;
while(!in.atEnd()) {
lines << in.readLine();
}
desktop.close();
if (lines.contains("Exec=" + getAppPathForProtocol()))
if (lines.contains("MimeType=x-scheme-handler/retroshare"))
return true;
}
#else
/* Platforms other than windows aren't supported yet */
/* Platforms not supported yet */
#endif
return false;
}
@ -774,50 +790,72 @@ bool RshareSettings::getRetroShareProtocol()
bool RshareSettings::canSetRetroShareProtocol()
{
#if defined(Q_OS_WIN)
QSettings retroshare("HKEY_CLASSES_ROOT\\retroshare", QSettings::NativeFormat);
return retroshare.isWritable();
QSettings classRoot("HKEY_CURRENT_USER\\Software\\Classes", QSettings::NativeFormat);
return classRoot.isWritable();
#elif defined(Q_OS_LINUX)
return RshareSettings::getRetroShareProtocol();
#else
return false;
#endif
}
/** Register retroshare:// as protocol */
bool RshareSettings::setRetroShareProtocol(bool value)
bool RshareSettings::setRetroShareProtocol(bool value, QString &error)
{
error = "";
#if defined(Q_OS_WIN)
if (value) {
QSettings retroshare("HKEY_CLASSES_ROOT\\retroshare", QSettings::NativeFormat);
QSettings retroshare("HKEY_CURRENT_USER\\Software\\Classes\\retroshare", QSettings::NativeFormat);
retroshare.setValue("Default", "URL: RetroShare protocol");
QSettings::Status state = retroshare.status();
if (state == QSettings::AccessError) {
error = tr("Registry Access Error. Maybe you need Administrator right.");
return false;
}
retroshare.setValue("URL Protocol", "");
retroshare.setValue("Profile", QString::fromStdString(rsPeers->getOwnId().toStdString()));
QSettings command("HKEY_CLASSES_ROOT\\retroshare\\shell\\open\\command", QSettings::NativeFormat);
QSettings command("HKEY_CURRENT_USER\\Software\\Classes\\retroshare\\shell\\open\\command", QSettings::NativeFormat);
command.setValue("Default", getAppPathForProtocol());
state = command.status();
} else {
QSettings retroshare("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
retroshare.remove("retroshare");
QSettings classRoot("HKEY_CURRENT_USER\\Software\\Classes", QSettings::NativeFormat);
classRoot.remove("retroshare");
QSettings::Status state = retroshare.status();
QSettings::Status state = classRoot.status();
if (state == QSettings::AccessError) {
error = tr("Registry Access Error. Maybe you need Administrator right.");
return false;
}
}
return true;
#else
/* Platforms other than windows aren't supported yet */
#elif defined(Q_OS_LINUX)
/* RetroShare protocol is always activated for Linux */
Q_UNUSED(value);
return true;
#else
/* Platforms not supported yet */
Q_UNUSED(value);
return false;
#endif
}
/** Returns true if this instance have to run Local Server*/
bool RshareSettings::getUseLocalServer()
{
return value("UseLocalServer", true).toBool();
}
/** Sets whether to run Local Server */
void RshareSettings::setUseLocalServer(bool value)
{
if (value != getUseLocalServer()) {
setValue("UseLocalServer", value);
Rshare::updateLocalServer();
}
}
/** Saving Generic Widget Size / Location */
void RshareSettings::saveWidgetInformation(QWidget *widget)

View File

@ -155,8 +155,13 @@ public:
bool canSetRetroShareProtocol();
/** Returns true if retroshare:// is registered as protocol */
bool getRetroShareProtocol();
/** Register retroshare:// as protocl */
bool setRetroShareProtocol(bool value);
/** Register retroshare:// as protocol */
bool setRetroShareProtocol(bool value, QString &error);
/** Returns true if this instance have to run Local Server*/
bool getUseLocalServer();
/** Sets whether to run Local Server */
void setUseLocalServer(bool value);
/* Get the destination log file. */
QString getLogFile();

View File

@ -39,7 +39,6 @@
#include "gui/connect/ConfCertDialog.h"
#include "idle/idle.h"
#include "gui/common/Emoticons.h"
#include "util/EventReceiver.h"
#include "gui/RetroShareLink.h"
#include "gui/SoundManager.h"
#include "gui/NetworkView.h"
@ -239,19 +238,9 @@ int main(int argc, char *argv[])
/* Setup The GUI Stuff */
Rshare rshare(args, argc, argv,
QString::fromUtf8(RsAccounts::ConfigDirectory().c_str()));
std::string url = RsInit::getRetroShareLink();
if (!url.empty()) {
/* start with RetroShare link */
EventReceiver eventReceiver;
if (eventReceiver.sendRetroShareLink(QString::fromStdString(url))) {
return 0;
}
/* Start RetroShare */
}
QString::fromUtf8(RsAccounts::ConfigDirectory().c_str()));
/* Start RetroShare */
QSplashScreen splashScreen(QPixmap(":/images/logo/logo_splash.png")/* , Qt::WindowStaysOnTopHint*/);
switch (initResult) {
@ -358,22 +347,7 @@ int main(int argc, char *argv[])
MainWindow *w = MainWindow::Create ();
splashScreen.finish(w);
EventReceiver *eventReceiver = NULL;
if (Settings->getRetroShareProtocol()) {
/* Create event receiver */
eventReceiver = new EventReceiver;
if (eventReceiver->start()) {
QObject::connect(eventReceiver, SIGNAL(linkReceived(const QUrl&)), w, SLOT(retroshareLinkActivated(const QUrl&)));
}
}
if (!url.empty()) {
/* Now use link from the command line, because no RetroShare was running */
RetroShareLink link(QString::fromStdString(url));
if (link.valid()) {
w->retroshareLinkActivated(link.toUrl());
}
}
w->processLastArgs();
// 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.
@ -422,13 +396,7 @@ int main(int argc, char *argv[])
int ti = rshare.exec();
delete w ;
WebuiPage::checkShutdownWebui();
if (eventReceiver) {
/* Destroy event receiver */
delete eventReceiver;
eventReceiver = NULL;
}
WebuiPage::checkShutdownWebui();
/* cleanup */
ChatDialog::cleanupChat();

View File

@ -5,6 +5,7 @@ QT += network xml
CONFIG += qt gui uic qrc resources idle bitdht
CONFIG += link_prl
TARGET = RetroShare06
DEFINES += TARGET=\\\"$TARGET\\\"
# Plz never commit the .pro with these flags enabled.
# Use this flag when developping new features only.
@ -214,9 +215,13 @@ win32 {
##################################### MacOS ######################################
macx {
# ENABLE THIS OPTION FOR Univeral Binary BUILD.
#CONFIG += ppc x86
# ENABLE THIS OPTION FOR Univeral Binary BUILD.
#CONFIG += ppc x86
#QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4
QMAKE_INFO_PLIST = Info.plist
mac_icon.files = $$files($$PWD/rsMacIcon.icns)
mac_icon.path = Contents/Resources
QMAKE_BUNDLE_DATA += mac_icon
CONFIG += version_detail_bash_script
LIBS += -lssl -lcrypto -lz
@ -377,7 +382,6 @@ HEADERS += rshare.h \
util/PixmapMerging.h \
util/MouseEventFilter.h \
util/EventFilter.h \
util/EventReceiver.h \
util/Widget.h \
util/RsAction.h \
util/RsUserdata.h \
@ -727,7 +731,6 @@ SOURCES += main.cpp \
util/PixmapMerging.cpp \
util/MouseEventFilter.cpp \
util/EventFilter.cpp \
util/EventReceiver.cpp \
util/Widget.cpp \
util/RsAction.cpp \
util/printpreview.cpp \

BIN
retroshare-gui/src/rsMacIcon.icns Executable file

Binary file not shown.

View File

@ -20,51 +20,67 @@
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QDir>
#include <QTimer>
#include <QTextStream>
#include <QShortcut>
#include <QStyleFactory>
#include <QStyle>
#include <QString>
#include <QLocale>
#include <QRegExp>
#include <QBuffer>
#include <QDateTime>
#include <gui/common/vmessagebox.h>
#include <gui/common/html.h>
#include <util/stringutil.h>
#include <stdlib.h>
#include <QDir>
#include <QFileOpenEvent>
#include <QLocale>
#include <QLocalSocket>
#include <QRegExp>
#include <QSharedMemory>
#include <QShortcut>
#include <QString>
#include <QStyle>
#include <QStyleFactory>
#include <QTextStream>
#include <QTimer>
#ifdef __APPLE__
#include <QUrl>
#endif
#include <iostream>
#include <stdlib.h>
#include <gui/common/html.h>
#include <gui/common/vmessagebox.h>
#include <gui/gxs/GxsIdDetails.h>
#include <gui/settings/rsharesettings.h>
#include <lang/languagesupport.h>
#include <util/stringutil.h>
#include <retroshare/rsinit.h>
#include <retroshare/rsversion.h>
#include <retroshare/rsplugin.h>
#include <lang/languagesupport.h>
#include "gui/settings/rsharesettings.h"
#include "gui/gxs/GxsIdDetails.h"
#include "rshare.h"
/* Available command-line arguments. */
#define ARG_LANGUAGE "lang" /**< Argument specifying language. */
#define ARG_GUISTYLE "style" /**< Argument specfying GUI style. */
#define ARG_LANGUAGE "lang" /**< Argument specifying language. */
#define ARG_GUISTYLE "style" /**< Argument specfying GUI style. */
#define ARG_GUISTYLESHEET "stylesheet" /**< Argument specfying GUI style. */
#define ARG_RESET "reset" /**< Reset Rshare's saved settings. */
#define ARG_DATADIR "datadir" /**< Directory to use for data files. */
#define ARG_LOGFILE "logfile" /**< Location of our logfile. */
#define ARG_LOGLEVEL "loglevel" /**< Log verbosity. */
#define ARG_RESET "reset" /**< Reset Rshare's saved settings. */
#define ARG_DATADIR "datadir" /**< Directory to use for data files. */
#define ARG_LOGFILE "logfile" /**< Location of our logfile. */
#define ARG_LOGLEVEL "loglevel" /**< Log verbosity. */
#define ARG_RSLINK_S "r" /**< Open RsLink with protocol retroshare:// */
#define ARG_RSLINK_L "link" /**< Open RsLink with protocol retroshare:// */
#define ARG_RSFILE_S "f" /**< Open RsFile with or without arg */
#define ARG_RSFILE_L "rsfile" /**< Open RsFile with or without arg */
//Other defined for server in /libretroshare/src/rsserver/rsinit.cc:351
/* Static member variables */
QMap<QString, QString> Rshare::_args; /**< List of command-line arguments. */
QString Rshare::_style; /**< The current GUI style. */
QString Rshare::_language; /**< The current language. */
QString Rshare::_stylesheet; /**< The current GUI stylesheet. */
QString Rshare::_language; /**< The current language. */
QString Rshare::_dateformat; /**< The format of dates in feed items etc. */
Log Rshare::_log;
Log Rshare::_log; /**< Logs debugging messages to file or stdout. */
QStringList Rshare::_links; /**< List of links passed by arguments. */
QStringList Rshare::_files; /**< List of files passed by arguments. */
QDateTime Rshare::mStartupTime;
bool Rshare::useConfigDir;
QString Rshare::configDir;
QDateTime Rshare::mStartupTime;
QLocalServer* Rshare::localServer;
/** Catches debugging messages from Qt and sends them to RetroShare's logs. If Qt
* emits a QtFatalMsg, we will write the message to the log and then abort().
@ -88,6 +104,10 @@ void qt_msg_handler(QtMsgType type, const char *msg)
case QtFatalMsg:
rError(QString("QtFatalMsg: %1").arg(msg));
break;
#if QT_VERSION >= QT_VERSION_CHECK (5, 5, 0)
case QtInfoMsg:
break;
#endif
}
if (type == QtFatalMsg) {
rError("Fatal Qt error. Aborting.");
@ -102,6 +122,61 @@ Rshare::Rshare(QStringList args, int &argc, char **argv, const QString &dir)
: QApplication(argc, argv)
{
mStartupTime = QDateTime::currentDateTime();
localServer = NULL;
//Initialize connection to LocalServer to know if other process runs.
{
QString serverName = QString(TARGET);
if (args.isEmpty()) args.append("Empty");
// load into shared memory
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
QDataStream out(&buffer);
out << args;
int size = buffer.size();
QSharedMemory newArgs;
newArgs.setKey(serverName + "_newArgs");
if (newArgs.isAttached()) newArgs.detach();
if (!newArgs.create(size)) {
std::cerr << "(EE) Rshare::Rshare Unable to create shared memory segment of size:"
<< size << " error:" << newArgs.errorString().toStdString() << "." << std::endl;
#ifdef Q_OS_UNIX
std::cerr << "Look with `ipcs -m` for nattch==0 segment. And remove it with `ipcrm -m 'shmid'`." << std::endl;
//No need for windows, as it removes shared segment directly even when crash.
#endif
newArgs.detach();
::exit(EXIT_FAILURE);
}
newArgs.lock();
char *to = (char*)newArgs.data();
const char *from = buffer.data().data();
memcpy(to, from, qMin(newArgs.size(), size));
newArgs.unlock();
// Connect to the Local Server of the main process to notify it
// that a new process had been started
QLocalSocket localSocket;
localSocket.connectToServer(QString(TARGET));
std::cerr << "Rshare::Rshare waitForConnected to other instance." << std::endl;
if( localSocket.waitForConnected(100) )
{
std::cerr << "Rshare::Rshare Connection etablished. Waiting for disconnection." << std::endl;
localSocket.waitForDisconnected(1000);
newArgs.detach();
::exit(EXIT_SUCCESS); // Terminate the program using STDLib's exit function
} else {
newArgs.detach();
// No main process exists
// So we start a Local Server to listen for connections from new process
localServer= new QLocalServer();
QObject::connect(localServer, SIGNAL(newConnection()), this, SLOT(slotConnectionEstablished()));
updateLocalServer();
}
}
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
qInstallMessageHandler(qt_msg_handler);
@ -172,6 +247,48 @@ Rshare::~Rshare()
{
/* Cleanup GxsIdDetails */
GxsIdDetails::cleanup();
if (localServer)
{
localServer->close();
delete localServer;
}
}
/**
* @brief Executed when new instance connect command is sent to LocalServer
*/
void Rshare::slotConnectionEstablished()
{
QLocalSocket *socket = localServer->nextPendingConnection();
socket->close();
delete socket;
QSharedMemory newArgs;
newArgs.setKey(QString(TARGET) + "_newArgs");
if (!newArgs.attach())
{
std::cerr << "(EE) Rshare::slotConnectionEstablished() Unable to attach to shared memory segment."
<< newArgs.errorString().toStdString() << std::endl;
return;
}
QBuffer buffer;
QDataStream in(&buffer);
QStringList args;
newArgs.lock();
buffer.setData((char*)newArgs.constData(), newArgs.size());
buffer.open(QBuffer::ReadOnly);
in >> args;
newArgs.unlock();
newArgs.detach();
emit newArgsReceived(args);
while (!args.empty())
{
std::cerr << "Rshare::slotConnectionEstablished args:" << QString(args.takeFirst()).toStdString() << std::endl;
}
}
QString Rshare::retroshareVersion(bool withRevision)
@ -271,39 +388,62 @@ Rshare::showUsageMessageBox()
bool
Rshare::argNeedsValue(QString argName)
{
return (argName == ARG_GUISTYLE ||
argName == ARG_GUISTYLESHEET ||
argName == ARG_LANGUAGE ||
argName == ARG_DATADIR ||
argName == ARG_LOGFILE ||
argName == ARG_LOGLEVEL);
return (argName == ARG_GUISTYLE ||
argName == ARG_GUISTYLESHEET ||
argName == ARG_LANGUAGE ||
argName == ARG_DATADIR ||
argName == ARG_LOGFILE ||
argName == ARG_LOGLEVEL ||
argName == ARG_RSLINK_S ||
argName == ARG_RSLINK_L ||
argName == ARG_RSFILE_S ||
argName == ARG_RSFILE_L );
}
/** Parses the list of command-line arguments for their argument names and
* values. */
void
Rshare::parseArguments(QStringList args)
Rshare::parseArguments(QStringList args, bool firstRun)
{
QString arg, value;
QString arg, value;
/* Loop through all command-line args/values and put them in a map */
for (int i = 0; i < args.size(); ++i) {
/* Get the argument name and set a blank value */
arg = args.at(i).toLower();
value = "";
/* Loop through all command-line args/values and put them in a map */
for (int i = 0; i < args.size(); ++i) {
/* Get the argument name and set a blank value */
arg = args.at(i);//.toLower(); Need Upper case for file name.
if (arg.toLower() == "empty") continue;
value = "";
/* Check if it starts with a - or -- */
if (arg.startsWith("-")) {
arg = arg.mid((arg.startsWith("--") ? 2 : 1));
}
/* Check if it takes a value and there is one on the command-line */
if (i < args.size()-1 && argNeedsValue(arg)) {
value = args.at(++i);
}
/* Place this arg/value in the map */
_args.insert(arg, value);
}
/* Check if it starts with a - or -- */
if (arg.startsWith("-")) {
arg = arg.mid((arg.startsWith("--") ? 2 : 1));
/* Check if it takes a value and there is one on the command-line */
if (i < args.size()-1 && argNeedsValue(arg.toLower())) {
value = args.at(++i);
}
} else {
/* Check if links or files without arg */
if (arg.toLower().startsWith("retroshare://")) {
value = arg;
arg = ARG_RSLINK_L;
} else {
if (QFile(arg).exists()) {
value = arg;
arg = ARG_RSFILE_L;
}
}
}
/* Don't send theses argument to _args map to allow multiple. */
if (arg == ARG_RSLINK_S || arg == ARG_RSLINK_L) {
_links.append(value);
} else if (arg == ARG_RSFILE_S || arg == ARG_RSFILE_L) {
_files.append(value);
} else if (firstRun) {
/* Place this arg/value in the map only first time*/
_args.insert(arg, value);
}
}
}
/** Verifies that all specified arguments were valid. */
@ -660,6 +800,29 @@ Rshare::createShortcut(const QKeySequence &key, QWidget *sender,
connect(s, SIGNAL(activated()), receiver, slot);
}
#ifdef __APPLE__
bool Rshare::event(QEvent *event)
{
switch (event->type()) {
case QEvent::FileOpen:{
QFileOpenEvent* fileOE = static_cast<QFileOpenEvent *>(event);
QStringList args;
if (! fileOE->file().isEmpty()) {
_files.append(fileOE->file());
emit newArgsReceived(QStringList());
return true;
} else if (! fileOE->url().isEmpty()) {
_links.append(fileOE->url().toString());
emit newArgsReceived(QStringList());
return true;
}
}
default:
return QApplication::event(event);
}
}
#endif
void Rshare::blinkTimer()
{
mBlink = !mBlink;
@ -706,3 +869,17 @@ bool Rshare::loadCertificate(const RsPeerId &accountId, bool autoLogin)
return true;
}
bool Rshare::updateLocalServer()
{
if (localServer) {
QString serverName = QString(TARGET);
if (Settings->getUseLocalServer()) {
localServer->removeServer(serverName);
localServer->listen(serverName);
return true;
}
localServer->close();
}
return false;
}

View File

@ -31,11 +31,13 @@
#endif
#include <QApplication>
#include <QKeySequence>
#include <QLocalServer>
#include <QMap>
#include <QString>
#include <QKeySequence>
#include "util/log.h"
#include "retroshare/rstypes.h"
/** Pointer to this RetroShare application instance. */
@ -63,6 +65,8 @@ public:
/** Return the map of command-line arguments and values. */
static QMap<QString, QString> arguments() { return _args; }
/** Parse the list of command-line arguments. */
static void parseArguments(QStringList args, bool firstRun = true);
/** Validates that all arguments were well-formed. */
bool validateArguments(QString &errmsg);
/** Prints usage information to the given text stream. */
@ -89,8 +93,10 @@ public:
static void getAvailableStyleSheets(QMap<QString, QString> &styleSheets);
/** Recalculates matching stylesheet for widget **/
static void refreshStyleSheet(QWidget *widget, bool processChildren);
/** Load certificate */
static bool loadCertificate(const RsPeerId &accountId, bool autoLogin);
/** Start or Stop Local server to get new arguments depends setting */
static bool updateLocalServer();
/**
* Update Language, Style and StyleSheet.
@ -107,6 +113,10 @@ public:
static QString style() { return _style; }
/** Returns the current GUI stylesheet. */
static QString stylesheet() { return _stylesheet; }
/** Returns links passed by arguments. */
static QStringList* links() { return &_links; }
/** Returns files passed by arguments. */
static QStringList* files() {return &_files; }
/** Returns Rshare's application startup time. */
static QDateTime startupTime();
@ -132,6 +142,11 @@ public:
static void createShortcut(const QKeySequence &key, QWidget *sender,
QWidget *receiver, const char *slot);
#ifdef __APPLE__
/**To process event from Mac system */
bool event(QEvent *);
#endif
signals:
/** Emitted when the application is running and the main event loop has
* started. */
@ -144,6 +159,8 @@ signals:
void secondTick();
/** Global timer every minute */
void minuteTick();
/** Emitted when other process is connected */
void newArgsReceived(QStringList args);
private slots:
/** Called when the application's main event loop has started. This method
@ -151,27 +168,32 @@ private slots:
* loop is running. */
void onEventLoopStarted();
void blinkTimer();
/**
* @brief Called when accept new connection from new instance.
*/
void slotConnectionEstablished();
private:
/** customize the date format (defaultlongformat) */
static void customizeDateFormat();
/** Parse the list of command-line arguments. */
void parseArguments(QStringList args);
/** Returns true if the specified arguments wants a value. */
bool argNeedsValue(QString argName);
static bool argNeedsValue(QString argName);
static QMap<QString, QString> _args; /**< List of command-line arguments. */
static QString _style; /**< The current GUI style. */
static QString _stylesheet; /**< The current GUI stylesheet. */
static QString _language; /**< The current language. */
static QString _dateformat; /**< The format for dates in feed items etc. */
static Log _log; /**< Logs debugging messages to file or stdout. */
static Log _log; /**< Logs debugging messages to file or stdout. */
static QStringList _links; /**< List of links passed by arguments. */
static QStringList _files; /**< List of files passed by arguments. */
static QDateTime mStartupTime; // startup time
static bool useConfigDir;
static QString configDir;
bool mBlink;
static QLocalServer* localServer;
};
#endif

View File

@ -1,173 +0,0 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 2007 crypton
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QCoreApplication>
#include <QMessageBox>
#include <QIcon>
#include <iostream>
#include <retroshare/rsinit.h>
#include "EventReceiver.h"
#include "gui/MainWindow.h"
#include "gui/RetroShareLink.h"
#ifdef WINDOWS_SYS
#include <windows.h>
#define OP_RETROSHARELINK 12000
#endif
struct SharedMemoryInfo
{
#ifdef WINDOWS_SYS
/* Store handle of the event window */
WId wid;
#else
long dummy;
#endif
};
EventReceiver::EventReceiver()
{
#ifdef WINDOWS_SYS
setWindowTitle("RetroShare EventReceiver");
#endif
/* Build unique name for the running instance */
QString name = QString("RetroShare-%1::EventReceiver").arg(QCoreApplication::applicationDirPath());
sharedMemory.setKey(name);
}
EventReceiver::~EventReceiver()
{
sharedMemory.detach();
}
bool EventReceiver::start()
{
if (!sharedMemory.create(sizeof(SharedMemoryInfo))) {
std::cerr << "EventReceiver::start() Cannot create shared memory !" << sharedMemory.errorString().toStdString() << std::endl;
return false;
}
bool result = true;
if (sharedMemory.lock()) {
SharedMemoryInfo *info = (SharedMemoryInfo*) sharedMemory.data();
if (info) {
#ifdef WINDOWS_SYS
info->wid = winId();
#else
info->dummy = 0;
#endif
} else {
result = false;
std::cerr << "EventReceiver::start() Shared memory returns a NULL pointer!" << std::endl;
}
sharedMemory.unlock();
} else {
result = false;
std::cerr << "EventReceiver::start() Cannot lock shared memory !" << std::endl;
}
return result;
}
bool EventReceiver::sendRetroShareLink(const QString& link)
{
if (!sharedMemory.attach()) {
/* No running instance found */
return false;
}
bool result = true;
if (sharedMemory.lock()) {
SharedMemoryInfo *info = (SharedMemoryInfo*) sharedMemory.data();
if (info) {
#ifdef WINDOWS_SYS
if (info->wid) {
QByteArray linkData(link.toUtf8());
COPYDATASTRUCT send;
send.dwData = OP_RETROSHARELINK;
send.cbData = link.length() * sizeof(char);
send.lpData = (void*) linkData.constData();
SendMessage((HWND) info->wid, WM_COPYDATA, (WPARAM) 0, (LPARAM) (PCOPYDATASTRUCT) &send);
} else {
result = false;
}
#else
Q_UNUSED(link);
QMessageBox mb(QMessageBox::Critical, "RetroShare", QObject::tr("Start with a RetroShare link is only supported for Windows."), QMessageBox::Ok);
mb.exec();
result = false;
#endif
} else {
result = false;
std::cerr << "EventReceiver::sendRetroShareLink() Cannot lock shared memory !" << std::endl;
}
sharedMemory.unlock();
} else {
result = false;
std::cerr << "EventReceiver::start() Cannot lock shared memory !" << std::endl;
}
sharedMemory.detach();
return result;
}
#ifdef WINDOWS_SYS
bool EventReceiver::winEvent(MSG* message, long* result)
{
if (message->message == WM_COPYDATA ) {
/* Extract the struct from lParam */
COPYDATASTRUCT *data = (COPYDATASTRUCT*) message->lParam;
if (data && data->dwData == OP_RETROSHARELINK) {
received(QString::fromUtf8((const char*) data->lpData, data->cbData));
/* Keep the event from Qt */
*result = 0;
return true;
}
}
/* Give the event to Qt */
return false;
}
#endif
void EventReceiver::received(const QString &url)
{
RetroShareLink link(url);
if (link.valid()) {
MainWindow::raiseWindow();
emit linkReceived(link.toUrl());
}
}

View File

@ -1,60 +0,0 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,2007 crypton
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _EVENTRECEIVER_H
#define _EVENTRECEIVER_H
#include <QWidget>
#include <QSharedMemory>
class QUrl;
class EventReceiver : public
#ifdef WINDOWS_SYS
QWidget
#else
QObject
#endif
{
Q_OBJECT
public:
EventReceiver();
~EventReceiver();
bool start();
bool sendRetroShareLink(const QString& link);
signals:
void linkReceived(const QUrl& url);
private:
void received(const QString& url);
#ifdef WINDOWS_SYS
/* Extend QWidget with a class that will capture the WM_COPYDATA messages */
bool winEvent (MSG* message, long* result);
#endif // WINDOWS_SYS
QSharedMemory sharedMemory;
};
#endif

View File

@ -28,6 +28,11 @@
#include "stringutil.h"
//#define CHAR_ARRAY_TO_STRINGLIST_DEBUG
#ifdef CHAR_ARRAY_TO_STRINGLIST_DEBUG
#include <iostream>
#include <QFile>
#endif
/** Create a QStringList from the array of C-style strings. */
QStringList
@ -35,7 +40,20 @@ char_array_to_stringlist(char **arr, int len)
{
QStringList list;
for (int i = 0; i < len; i++) {
list << QString(arr[i]);
#ifdef WINDOWS_SYS
list << QString::fromLatin1(arr[i]);
#else
list << QString::fromUtf8(arr[i]);
#endif
#ifdef CHAR_ARRAY_TO_STRINGLIST_DEBUG
std::cerr << "arr[" << i << "]==" << arr[i] << std::endl;
if (QFile(arr[i]).exists()) std::cerr << "arr[i] File exists" << std::endl;
std::cerr << "QString UTF8==" << QString::fromUtf8(arr[i]).toStdString() << std::endl;
if (QFile(QString::fromUtf8(arr[i])).exists()) std::cerr << "QString UTF8 File exists" << std::endl;
std::cerr << "QString Latin1==" << QString::fromLatin1(arr[i]).toStdString() << std::endl;
if (QFile(QString::fromLatin1(arr[i])).exists()) std::cerr << "QString Latin1 File exists" << std::endl;
#endif
}
return list;
}