fixed handling of incoming rscollection files

This commit is contained in:
csoler 2024-02-16 13:28:55 +01:00
parent 142a8e2503
commit eccfc7ba71
5 changed files with 48 additions and 21 deletions

View file

@ -1254,21 +1254,23 @@ void MainWindow::doQuit()
rApp->quit(); 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. // except -r, -f, -o and lists of rscollection files and rslinks are discarded.
// //
void MainWindow::receiveNewArgs(QStringList args) void MainWindow::receiveNewArgs(QStringList args)
{ {
QString arg, argl, value; RsInfo() << "Received new arguments from operating system call.";
std::vector<const char *> argv;
std::string argstring = RsApplication::applicationFilePath().toStdString() ;
for(auto l:args) 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. // This class does all the job at once: validate arguments, and parses them.
std::vector<std::string> links_and_files; std::vector<std::string> links_and_files;
argstream as(argv.size(),const_cast<char **>(argv.data())); argstream as(argstring.c_str());
QString omValues = QString(";full;noturtle;gaming;minimal;"); QString omValues = QString(";full;noturtle;gaming;minimal;");
std::string opModeStr; std::string opModeStr;
@ -1291,6 +1293,8 @@ void MainWindow::receiveNewArgs(QStringList args)
QString opmode = QString::fromStdString(opModeStr).toLower(); QString opmode = QString::fromStdString(opModeStr).toLower();
//RsApplication::setOpMode(opModeStr.toLower()); // Do we need this?? //RsApplication::setOpMode(opModeStr.toLower()); // Do we need this??
RsInfo() << "Setting new operating mode to \"" << opmode.toStdString() << "\"";
if (opmode == "noturtle") if (opmode == "noturtle")
opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::NOTURTLE) - 1); opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::NOTURTLE) - 1);
else if (opmode == "gaming") else if (opmode == "gaming")
@ -1704,6 +1708,12 @@ void MainWindow::openRsCollection(const QString &filename)
if (qinfo.exists()) { if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
RsCollection collection; RsCollection collection;
if(!collection.load(filename))
{
RsErr() << "Could not open Rscollection file " << filename.toStdString();
return;
}
collection.downloadFiles(); collection.downloadFiles();
//collection.openColl(qinfo.absoluteFilePath()); //collection.openColl(qinfo.absoluteFilePath());
} }

View file

@ -149,7 +149,7 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;When checked, this retroshare instance will accept calls by your operating system to open Retroshare collection files, and download links.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;When checked, this retroshare instance will accept calls by your operating system to open Retroshare collection files, and download links.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="text"> <property name="text">
<string>Use Local Server to get new arguments.</string> <string>Accept operating systems calls</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>

View file

@ -145,6 +145,7 @@ static bool notifyRunningInstance()
// Connect to the Local Server of the main process to notify it // Connect to the Local Server of the main process to notify it
// that a new process had been started // that a new process had been started
RsInfo() << "Trying to contact running instance through socket \"" << TARGET << "\"";
QLocalSocket localSocket; QLocalSocket localSocket;
localSocket.connectToServer(QString(TARGET)); localSocket.connectToServer(QString(TARGET));
#ifdef DEBUG #ifdef DEBUG

View file

@ -240,6 +240,17 @@ RsApplication::RsApplication(const RsGUIConfigOptions& conf)
} }
#endif #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) #if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
qInstallMessageHandler(qt_msg_handler); qInstallMessageHandler(qt_msg_handler);
#else #else
@ -344,6 +355,11 @@ void RsApplication::slotConnectionEstablished()
socket->close(); socket->close();
delete socket; delete socket;
if(newArgs.error())
{
RsErr() << "Something when wrong in receiving arguments from operating system: " << newArgs.errorString().toStdString() ;
return ;
}
QBuffer buffer; QBuffer buffer;
QDataStream in(&buffer); QDataStream in(&buffer);
QStringList args; QStringList args;