diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 6a3148e5a..672847aa9 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -1254,21 +1254,23 @@ void MainWindow::doQuit() rApp->quit(); } -// This method parses arguments passed by another process. All arguments +// This method parses arguments passed by the operating system. All arguments // except -r, -f, -o and lists of rscollection files and rslinks are discarded. // void MainWindow::receiveNewArgs(QStringList args) { - QString arg, argl, value; - std::vector argv; + RsInfo() << "Received new arguments from operating system call."; + + std::string argstring = RsApplication::applicationFilePath().toStdString() ; + for(auto l:args) - argv.push_back((const char *)l.data()); + argstring += " " + l.toStdString(); // This class does all the job at once: validate arguments, and parses them. std::vector links_and_files; - argstream as(argv.size(),const_cast(argv.data())); + argstream as(argstring.c_str()); QString omValues = QString(";full;noturtle;gaming;minimal;"); std::string opModeStr; @@ -1291,6 +1293,8 @@ void MainWindow::receiveNewArgs(QStringList args) QString opmode = QString::fromStdString(opModeStr).toLower(); //RsApplication::setOpMode(opModeStr.toLower()); // Do we need this?? + RsInfo() << "Setting new operating mode to \"" << opmode.toStdString() << "\""; + if (opmode == "noturtle") opModeStatus->setCurrentIndex(static_cast::type>(RsOpMode::NOTURTLE) - 1); else if (opmode == "gaming") @@ -1704,6 +1708,12 @@ void MainWindow::openRsCollection(const QString &filename) if (qinfo.exists()) { if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { RsCollection collection; + + if(!collection.load(filename)) + { + RsErr() << "Could not open Rscollection file " << filename.toStdString(); + return; + } collection.downloadFiles(); //collection.openColl(qinfo.absoluteFilePath()); } diff --git a/retroshare-gui/src/gui/common/RsCollection.cpp b/retroshare-gui/src/gui/common/RsCollection.cpp index c49296503..5d4ba01ad 100644 --- a/retroshare-gui/src/gui/common/RsCollection.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -385,7 +385,7 @@ bool RsCollection::checkFile(const QString& fileName, bool showError) //std::cerr << "n==" << n <<" Checking string " << std::string(current,n+1) << " c = " << std::hex << (int)c << std::dec << std::endl; - for(uint i=0;i<html><head/><body><p>When checked, this retroshare instance will accept calls by your operating system to open Retroshare collection files, and download links.</p></body></html> - Use Local Server to get new arguments. + Accept operating systems calls true diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 630e10aa7..3bc8e3c76 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -145,6 +145,7 @@ static bool notifyRunningInstance() // Connect to the Local Server of the main process to notify it // that a new process had been started + RsInfo() << "Trying to contact running instance through socket \"" << TARGET << "\""; QLocalSocket localSocket; localSocket.connectToServer(QString(TARGET)); #ifdef DEBUG diff --git a/retroshare-gui/src/rshare.cpp b/retroshare-gui/src/rshare.cpp index 1f95d6997..a5ecbf17d 100644 --- a/retroshare-gui/src/rshare.cpp +++ b/retroshare-gui/src/rshare.cpp @@ -240,6 +240,17 @@ RsApplication::RsApplication(const RsGUIConfigOptions& conf) } #endif + // 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(); + + // clear out any old arguments (race condition?) + QSharedMemory newArgs; + newArgs.setKey(QString(TARGET) + "_newArgs"); + if(newArgs.attach(QSharedMemory::ReadWrite)) + newArgs.detach(); + #if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) qInstallMessageHandler(qt_msg_handler); #else @@ -344,22 +355,27 @@ void RsApplication::slotConnectionEstablished() socket->close(); delete socket; - QBuffer buffer; - QDataStream in(&buffer); - QStringList args; + if(newArgs.error()) + { + RsErr() << "Something when wrong in receiving arguments from operating system: " << newArgs.errorString().toStdString() ; + 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(); + 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()) - { + emit newArgsReceived(args); + while (!args.empty()) + { std::cerr << "RsApplication::slotConnectionEstablished args:" << QString(args.takeFirst()).toStdString() << std::endl; - } + } } QString RsApplication::retroshareVersion(bool) { return RS_HUMAN_READABLE_VERSION; }