2018-07-20 13:48:29 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* retroshare-gui/src/: main.cpp *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2006-2007 by Crypton <retroshare@lunamutt.com> *
|
|
|
|
* Copyright (c) 2006, Matt Edman, Justin Hipple *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2016-03-01 07:08:33 -05:00
|
|
|
#include <QBuffer>
|
|
|
|
#include <QDateTime>
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <QDir>
|
2016-03-01 07:08:33 -05:00
|
|
|
#include <QFileOpenEvent>
|
2012-11-10 13:59:58 -05:00
|
|
|
#include <QLocale>
|
2016-03-01 07:08:33 -05:00
|
|
|
#include <QLocalSocket>
|
2012-11-10 13:59:58 -05:00
|
|
|
#include <QRegExp>
|
2016-03-01 07:08:33 -05:00
|
|
|
#include <QSharedMemory>
|
|
|
|
#include <QShortcut>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QStyleFactory>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QTimer>
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <QUrl>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-08-19 13:18:58 -04:00
|
|
|
#include <gui/common/rshtml.h>
|
2016-03-01 07:08:33 -05:00
|
|
|
#include <gui/common/vmessagebox.h>
|
|
|
|
#include <gui/gxs/GxsIdDetails.h>
|
|
|
|
#include <gui/settings/rsharesettings.h>
|
|
|
|
#include <lang/languagesupport.h>
|
2008-08-15 13:49:57 -04:00
|
|
|
#include <util/stringutil.h>
|
|
|
|
|
2012-10-12 14:42:24 -04:00
|
|
|
#include <retroshare/rsinit.h>
|
2015-01-14 18:26:51 -05:00
|
|
|
#include <retroshare/rsversion.h>
|
2015-06-28 06:11:47 -04:00
|
|
|
#include <retroshare/rsplugin.h>
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
#include "rshare.h"
|
|
|
|
|
|
|
|
/* Available command-line arguments. */
|
2016-03-01 07:08:33 -05:00
|
|
|
#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. */
|
2016-05-16 06:10:04 -04:00
|
|
|
#define ARG_GUISTYLE "style" /**< Argument specfying GUI style. */
|
|
|
|
#define ARG_GUISTYLESHEET "stylesheet" /**< Argument specfying GUI style. */
|
|
|
|
#define ARG_LANGUAGE "lang" /**< Argument specifying language. */
|
2016-08-13 08:34:31 -04:00
|
|
|
#define ARG_OPMODE_S "o" /**< OpMode (Full, NoTurtle, Gaming, Minimal) */
|
|
|
|
#define ARG_OPMODE_L "opmode" /**< OpMode (Full, NoTurtle, Gaming, Minimal) */
|
2016-03-01 07:08:33 -05:00
|
|
|
#define ARG_RSLINK_S "r" /**< Open RsLink with protocol retroshare:// */
|
|
|
|
#define ARG_RSLINK_L "link" /**< Open RsLink with protocol retroshare:// */
|
2016-08-13 08:34:31 -04:00
|
|
|
#define ARG_RSFILE_S "f" /**< Open RsFile with or without arg. */
|
|
|
|
#define ARG_RSFILE_L "rsfile" /**< Open RsFile with or without arg. */
|
2016-03-01 07:08:33 -05:00
|
|
|
//Other defined for server in /libretroshare/src/rsserver/rsinit.cc:351
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2017-04-09 04:26:18 -04:00
|
|
|
// The arguments here can be send to a running instance.
|
|
|
|
// If the command line contains arguments not listed here, we have to start a new instance.
|
2016-08-13 08:34:31 -04:00
|
|
|
// For example, the user wants to start a second instance using --base-dir arg of libretroshare.
|
2017-04-09 04:26:18 -04:00
|
|
|
static const char* const forwardableArgs[] = {
|
2016-08-13 08:34:31 -04:00
|
|
|
ARG_OPMODE_S,
|
|
|
|
ARG_OPMODE_L,
|
2017-04-09 04:26:18 -04:00
|
|
|
ARG_RSLINK_S,
|
|
|
|
ARG_RSLINK_L,
|
|
|
|
ARG_RSFILE_S,
|
|
|
|
ARG_RSFILE_L,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* Static member variables */
|
|
|
|
QMap<QString, QString> Rshare::_args; /**< List of command-line arguments. */
|
2016-05-16 06:10:04 -04:00
|
|
|
Log Rshare::_log; /**< Logs debugging messages to file or stdout. */
|
2007-11-14 22:18:48 -05:00
|
|
|
QString Rshare::_style; /**< The current GUI style. */
|
2008-08-15 13:49:57 -04:00
|
|
|
QString Rshare::_stylesheet; /**< The current GUI stylesheet. */
|
2016-03-01 07:08:33 -05:00
|
|
|
QString Rshare::_language; /**< The current language. */
|
2012-11-15 16:35:37 -05:00
|
|
|
QString Rshare::_dateformat; /**< The format of dates in feed items etc. */
|
2016-05-16 06:10:04 -04:00
|
|
|
QString Rshare::_opmode; /**< The operating mode passed by args. */
|
2016-03-01 07:08:33 -05:00
|
|
|
QStringList Rshare::_links; /**< List of links passed by arguments. */
|
|
|
|
QStringList Rshare::_files; /**< List of files passed by arguments. */
|
2013-04-22 17:12:38 -04:00
|
|
|
QDateTime Rshare::mStartupTime;
|
2016-03-01 07:08:33 -05:00
|
|
|
bool Rshare::useConfigDir;
|
|
|
|
QString Rshare::configDir;
|
|
|
|
QLocalServer* Rshare::localServer;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-08-15 13:49:57 -04:00
|
|
|
/** 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().
|
|
|
|
*/
|
2013-10-19 19:41:23 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
|
|
|
void qt_msg_handler(QtMsgType type, const QMessageLogContext &, const QString &msg)
|
|
|
|
#else
|
|
|
|
void qt_msg_handler(QtMsgType type, const char *msg)
|
|
|
|
#endif
|
2008-08-15 13:49:57 -04:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case QtDebugMsg:
|
2013-10-19 19:41:23 -04:00
|
|
|
rDebug(QString("QtDebugMsg: %1").arg(msg));
|
2008-08-15 13:49:57 -04:00
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
2013-10-19 19:41:23 -04:00
|
|
|
rNotice(QString("QtWarningMsg: %1").arg(msg));
|
2008-08-15 13:49:57 -04:00
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
2013-10-19 19:41:23 -04:00
|
|
|
rWarn(QString("QtCriticalMsg: %1").arg(msg));
|
2008-08-15 13:49:57 -04:00
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
2013-10-19 19:41:23 -04:00
|
|
|
rError(QString("QtFatalMsg: %1").arg(msg));
|
2008-08-15 13:49:57 -04:00
|
|
|
break;
|
2016-03-01 07:08:33 -05:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK (5, 5, 0)
|
|
|
|
case QtInfoMsg:
|
|
|
|
break;
|
|
|
|
#endif
|
2008-08-15 13:49:57 -04:00
|
|
|
}
|
|
|
|
if (type == QtFatalMsg) {
|
|
|
|
rError("Fatal Qt error. Aborting.");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2017-04-09 04:26:18 -04:00
|
|
|
static bool notifyRunningInstance()
|
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Rshare::Rshare failed to connect to other instance." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/** Constructor. Parses the command-line arguments, resets Rshare's
|
|
|
|
* configuration (if requested), and sets up the GUI style and language
|
|
|
|
* translation. */
|
2012-09-01 07:40:54 -04:00
|
|
|
Rshare::Rshare(QStringList args, int &argc, char **argv, const QString &dir)
|
2007-11-14 22:18:48 -05:00
|
|
|
: QApplication(argc, argv)
|
|
|
|
{
|
2013-04-22 17:12:38 -04:00
|
|
|
mStartupTime = QDateTime::currentDateTime();
|
2016-03-01 07:08:33 -05:00
|
|
|
localServer = NULL;
|
|
|
|
|
|
|
|
//Initialize connection to LocalServer to know if other process runs.
|
|
|
|
{
|
|
|
|
QString serverName = QString(TARGET);
|
|
|
|
|
2017-04-09 04:26:18 -04:00
|
|
|
// check if another instance is running
|
|
|
|
bool haveRunningInstance = notifyRunningInstance();
|
|
|
|
|
|
|
|
bool sendArgsToRunningInstance = haveRunningInstance;
|
|
|
|
if(args.empty())
|
|
|
|
sendArgsToRunningInstance = false;
|
|
|
|
// if we find non-forwardable args, start a new instance
|
|
|
|
for(int i = 0; i < args.size(); ++i)
|
|
|
|
{
|
|
|
|
const char* const* argit = forwardableArgs;
|
|
|
|
bool found = false;
|
|
|
|
while(*argit && i < args.size())
|
|
|
|
{
|
|
|
|
if(args.value(i) == "-"+QString(*argit) || args.value(i) == "--"+QString(*argit))
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
if(argNeedsValue(*argit))
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
argit++;
|
|
|
|
}
|
|
|
|
if(!found)
|
|
|
|
sendArgsToRunningInstance = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendArgsToRunningInstance) {
|
2016-04-07 20:14:27 -04:00
|
|
|
// 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;
|
2016-03-01 07:08:33 -05:00
|
|
|
#ifdef Q_OS_UNIX
|
2016-04-07 20:14:27 -04:00
|
|
|
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.
|
2016-03-01 07:08:33 -05:00
|
|
|
#endif
|
2016-04-07 20:14:27 -04:00
|
|
|
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();
|
|
|
|
|
|
|
|
std::cerr << "Rshare::Rshare waitForConnected to other instance." << std::endl;
|
2017-04-09 04:26:18 -04:00
|
|
|
if(notifyRunningInstance())
|
2016-04-07 20:14:27 -04:00
|
|
|
{
|
|
|
|
newArgs.detach();
|
2016-06-14 09:10:15 -04:00
|
|
|
std::cerr << "Rshare::Rshare Arguments was sended." << std::endl
|
|
|
|
<< " To disable it, in Options - General - Misc," << std::endl
|
|
|
|
<< " uncheck \"Use Local Server to get new Arguments\"." << std::endl;
|
2016-04-07 20:14:27 -04:00
|
|
|
::exit(EXIT_SUCCESS); // Terminate the program using STDLib's exit function
|
|
|
|
}
|
2017-04-09 04:26:18 -04:00
|
|
|
else
|
|
|
|
std::cerr << "Rshare::Rshare failed to connect to other instance." << std::endl;
|
2016-03-01 07:08:33 -05:00
|
|
|
newArgs.detach();
|
|
|
|
}
|
2017-04-09 04:26:18 -04:00
|
|
|
|
|
|
|
if(!haveRunningInstance)
|
|
|
|
{
|
|
|
|
// No main process exists
|
|
|
|
// Or started without arguments
|
|
|
|
// 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();
|
2019-10-11 06:26:00 -04:00
|
|
|
// clear out any old arguments (race condition?)
|
|
|
|
QSharedMemory newArgs;
|
|
|
|
newArgs.setKey(QString(TARGET) + "_newArgs");
|
|
|
|
if(newArgs.attach(QSharedMemory::ReadWrite))
|
|
|
|
newArgs.detach();
|
2017-04-09 04:26:18 -04:00
|
|
|
}
|
2016-03-01 07:08:33 -05:00
|
|
|
}
|
2013-04-22 17:12:38 -04:00
|
|
|
|
2013-10-19 19:41:23 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
|
|
|
qInstallMessageHandler(qt_msg_handler);
|
|
|
|
#else
|
2008-08-15 13:49:57 -04:00
|
|
|
qInstallMsgHandler(qt_msg_handler);
|
2013-10-19 19:41:23 -04:00
|
|
|
#endif
|
2008-08-15 13:49:57 -04:00
|
|
|
|
2012-09-21 17:36:24 -04:00
|
|
|
#ifndef __APPLE__
|
|
|
|
|
2012-09-13 05:52:17 -04:00
|
|
|
/* set default window icon */
|
2015-06-29 12:08:17 -04:00
|
|
|
setWindowIcon(QIcon(":/icons/logo_128.png"));
|
2012-09-13 05:52:17 -04:00
|
|
|
|
2012-09-21 17:36:24 -04:00
|
|
|
#endif
|
|
|
|
|
2012-10-25 14:06:33 -04:00
|
|
|
mBlink = true;
|
|
|
|
QTimer *timer = new QTimer(this);
|
|
|
|
timer->setInterval(500);
|
|
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(blinkTimer()));
|
|
|
|
timer->start();
|
2012-09-21 17:36:24 -04:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
timer = new QTimer(this);
|
|
|
|
timer->setInterval(60000);
|
|
|
|
connect(timer, SIGNAL(timeout()), this, SIGNAL(minuteTick()));
|
|
|
|
timer->start();
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* Read in all our command-line arguments. */
|
|
|
|
parseArguments(args);
|
|
|
|
|
|
|
|
/* Check if we're supposed to reset our config before proceeding. */
|
|
|
|
if (_args.contains(ARG_RESET)) {
|
2010-05-20 17:53:27 -04:00
|
|
|
Settings->reset();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2008-08-15 13:49:57 -04:00
|
|
|
|
|
|
|
/* Handle the -loglevel and -logfile options. */
|
|
|
|
if (_args.contains(ARG_LOGFILE))
|
|
|
|
_log.open(_args.value(ARG_LOGFILE));
|
|
|
|
if (_args.contains(ARG_LOGLEVEL)) {
|
|
|
|
_log.setLogLevel(Log::stringToLogLevel(
|
|
|
|
_args.value(ARG_LOGLEVEL)));
|
|
|
|
if (!_args.contains(ARG_LOGFILE))
|
|
|
|
_log.open(stdout);
|
|
|
|
}
|
|
|
|
if (!_args.contains(ARG_LOGLEVEL) &&
|
|
|
|
!_args.contains(ARG_LOGFILE))
|
|
|
|
_log.setLogLevel(Log::Off);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* config directory */
|
|
|
|
useConfigDir = false;
|
|
|
|
if (dir != "")
|
|
|
|
{
|
|
|
|
setConfigDirectory(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Initialize support for language translations. */
|
2010-03-11 19:16:39 -05:00
|
|
|
//LanguageSupport::initialize();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-10-14 17:16:34 -04:00
|
|
|
resetLanguageAndStyle();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-04-03 09:02:27 -04:00
|
|
|
/* Switch off auto shutdown */
|
|
|
|
setQuitOnLastWindowClosed ( false );
|
2015-04-20 18:28:19 -04:00
|
|
|
|
|
|
|
/* Initialize GxsIdDetails */
|
|
|
|
GxsIdDetails::initialize();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Destructor */
|
|
|
|
Rshare::~Rshare()
|
|
|
|
{
|
2015-04-20 18:28:19 -04:00
|
|
|
/* Cleanup GxsIdDetails */
|
|
|
|
GxsIdDetails::cleanup();
|
2016-03-01 07:08:33 -05:00
|
|
|
if (localServer)
|
|
|
|
{
|
|
|
|
localServer->close();
|
|
|
|
delete localServer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Executed when new instance connect command is sent to LocalServer
|
|
|
|
*/
|
|
|
|
void Rshare::slotConnectionEstablished()
|
|
|
|
{
|
|
|
|
QSharedMemory newArgs;
|
|
|
|
newArgs.setKey(QString(TARGET) + "_newArgs");
|
|
|
|
|
2019-10-11 06:26:00 -04:00
|
|
|
QLocalSocket *socket = localServer->nextPendingConnection();
|
|
|
|
|
2016-03-01 07:08:33 -05:00
|
|
|
if (!newArgs.attach())
|
|
|
|
{
|
2019-10-11 06:26:00 -04:00
|
|
|
/* this is not an error. It just means we were notified to check
|
|
|
|
newArgs, but none had been set yet.
|
|
|
|
TODO: implement separate ping/take messages
|
|
|
|
std::cerr << "(EE) Rshare::slotConnectionEstablished() Unable to attach to shared memory segment."
|
|
|
|
<< newArgs.errorString().toStdString() << std::endl;
|
|
|
|
*/
|
|
|
|
socket->close();
|
|
|
|
delete socket;
|
2016-03-01 07:08:33 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-11 06:26:00 -04:00
|
|
|
socket->close();
|
|
|
|
delete socket;
|
|
|
|
|
2016-03-01 07:08:33 -05:00
|
|
|
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;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2018-09-11 18:33:29 -04:00
|
|
|
QString Rshare::retroshareVersion(bool) { return RS_HUMAN_READABLE_VERSION; }
|
2015-01-14 18:26:51 -05:00
|
|
|
|
2008-08-15 13:49:57 -04:00
|
|
|
/** Enters the main event loop and waits until exit() is called. The signal
|
|
|
|
* running() will be emitted when the event loop has started. */
|
|
|
|
int
|
|
|
|
Rshare::run()
|
|
|
|
{
|
|
|
|
QTimer::singleShot(0, rApp, SLOT(onEventLoopStarted()));
|
|
|
|
return rApp->exec();
|
|
|
|
}
|
|
|
|
|
2013-04-22 17:12:38 -04:00
|
|
|
QDateTime Rshare::startupTime()
|
|
|
|
{
|
|
|
|
return mStartupTime;
|
|
|
|
}
|
|
|
|
|
2008-08-15 13:49:57 -04:00
|
|
|
/** Called when the application's main event loop has started. This method
|
|
|
|
* will emit the running() signal to indicate that the application's event
|
|
|
|
* loop is running. */
|
|
|
|
void
|
|
|
|
Rshare::onEventLoopStarted()
|
|
|
|
{
|
|
|
|
emit running();
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/** Display usage information regarding command-line arguments. */
|
2008-08-15 13:49:57 -04:00
|
|
|
/*void
|
2007-11-14 22:18:48 -05:00
|
|
|
Rshare::printUsage(QString errmsg)
|
|
|
|
{
|
2008-08-15 13:49:57 -04:00
|
|
|
QTextStream out(stdout);*/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* If there was an error message, print it out. */
|
2008-08-15 13:49:57 -04:00
|
|
|
/*if (!errmsg.isEmpty()) {
|
2007-11-14 22:18:48 -05:00
|
|
|
out << "** " << errmsg << " **" << endl << endl;
|
2008-08-15 13:49:57 -04:00
|
|
|
}*/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* Now print the application usage */
|
2008-08-15 13:49:57 -04:00
|
|
|
//out << "Usage: " << endl;
|
|
|
|
//out << "\t" << qApp->arguments().at(0) << " [options]" << endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* And available options */
|
2008-08-15 13:49:57 -04:00
|
|
|
//out << endl << "Available Options:" << endl;
|
|
|
|
//out << "\t-"ARG_RESET"\t\tResets ALL stored Rshare settings." << endl;
|
|
|
|
//out << "\t-"ARG_DATADIR"\tSets the directory Rshare uses for data files"<< endl;
|
|
|
|
//out << "\t-"ARG_GUISTYLE"\t\tSets Rshare's interface style." << endl;
|
|
|
|
//out << "\t-"ARG_GUISTYLESHEET"\t\tSets Rshare's stylesheet." << endl;
|
|
|
|
//out << "\t\t\t[" << QStyleFactory::keys().join("|") << "]" << endl;
|
|
|
|
//out << "\t-"ARG_LANGUAGE"\t\tSets Rshare's language." << endl;
|
|
|
|
//out << "\t\t\t[" << LanguageSupport::languageCodes().join("|") << "]" << endl;
|
|
|
|
//}
|
|
|
|
|
|
|
|
/** Displays usage information for command-line args. */
|
|
|
|
void
|
|
|
|
Rshare::showUsageMessageBox()
|
|
|
|
{
|
|
|
|
QString usage;
|
|
|
|
QTextStream out(&usage);
|
|
|
|
|
|
|
|
out << "Available Options:" << endl;
|
|
|
|
out << "<table>";
|
|
|
|
//out << trow(tcol("-"ARG_HELP) +
|
|
|
|
// tcol(tr("Displays this usage message and exits.")));
|
2016-04-04 06:07:09 -04:00
|
|
|
out << trow(tcol("-" ARG_RESET) +
|
2008-08-15 13:49:57 -04:00
|
|
|
tcol(tr("Resets ALL stored RetroShare settings.")));
|
2016-04-04 06:07:09 -04:00
|
|
|
out << trow(tcol("-" ARG_DATADIR" <dir>") +
|
2008-08-15 13:49:57 -04:00
|
|
|
tcol(tr("Sets the directory RetroShare uses for data files.")));
|
2016-08-13 08:34:31 -04:00
|
|
|
out << trow(tcol("-" ARG_LOGFILE" <" + tr("filename") + ">") +
|
2008-08-15 13:49:57 -04:00
|
|
|
tcol(tr("Sets the name and location of RetroShare's logfile.")));
|
2016-08-13 08:34:31 -04:00
|
|
|
out << trow(tcol("-" ARG_LOGLEVEL" <" + tr("level") + ">") +
|
2010-09-13 16:05:55 -04:00
|
|
|
tcol(tr("Sets the verbosity of RetroShare's logging.") +
|
2008-08-15 13:49:57 -04:00
|
|
|
"<br>[" + Log::logLevels().join("|") +"]"));
|
2016-08-13 08:34:31 -04:00
|
|
|
out << trow(tcol("-" ARG_GUISTYLE" <" + tr("style") +">") +
|
2008-08-15 13:49:57 -04:00
|
|
|
tcol(tr("Sets RetroShare's interface style.") +
|
|
|
|
"<br>[" + QStyleFactory::keys().join("|") + "]"));
|
2016-08-13 08:34:31 -04:00
|
|
|
out << trow(tcol("-" ARG_GUISTYLESHEET" <" + tr("stylesheet") + ">") +
|
|
|
|
tcol(tr("Sets RetroShare's interface stylesheets.")));
|
|
|
|
out << trow(tcol("-" ARG_LANGUAGE" <" + tr("language") + ">") +
|
2008-08-15 13:49:57 -04:00
|
|
|
tcol(tr("Sets RetroShare's language.") +
|
|
|
|
"<br>[" + LanguageSupport::languageCodes().join("|") + "]"));
|
2016-08-13 08:34:31 -04:00
|
|
|
out << trow(tcol("--" ARG_OPMODE_L" <" + tr("opmode") + ">") +
|
|
|
|
tcol(tr("Sets RetroShare's operating mode.") +
|
2016-05-16 06:10:04 -04:00
|
|
|
"<br>[full|noturtle|gaming|minimal]"));
|
2016-08-13 08:34:31 -04:00
|
|
|
out << trow(tcol("-" ARG_RSLINK_L" <" + tr("RsLinkURL") + ">") +
|
|
|
|
tcol(tr("Open RsLink with protocol retroshare://")));
|
|
|
|
out << trow(tcol("-" ARG_RSFILE_L" <" + tr("filename") + ">") +
|
|
|
|
tcol(tr("Open RsFile with or without arg.")));
|
2008-08-15 13:49:57 -04:00
|
|
|
out << "</table>";
|
|
|
|
|
|
|
|
VMessageBox::information(0,
|
2016-08-13 08:34:31 -04:00
|
|
|
tr("RetroShare GUI Usage Information"), usage, VMessageBox::Ok);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns true if the specified argument expects a value. */
|
|
|
|
bool
|
|
|
|
Rshare::argNeedsValue(QString argName)
|
|
|
|
{
|
2016-05-16 06:10:04 -04:00
|
|
|
return (
|
2016-03-01 07:08:33 -05:00
|
|
|
argName == ARG_DATADIR ||
|
|
|
|
argName == ARG_LOGFILE ||
|
2016-05-16 06:10:04 -04:00
|
|
|
argName == ARG_LOGLEVEL ||
|
|
|
|
argName == ARG_GUISTYLE ||
|
|
|
|
argName == ARG_GUISTYLESHEET ||
|
|
|
|
argName == ARG_LANGUAGE ||
|
2016-08-13 08:34:31 -04:00
|
|
|
argName == ARG_OPMODE_S ||
|
|
|
|
argName == ARG_OPMODE_L ||
|
2016-03-01 07:08:33 -05:00
|
|
|
argName == ARG_RSLINK_S ||
|
|
|
|
argName == ARG_RSLINK_L ||
|
|
|
|
argName == ARG_RSFILE_S ||
|
|
|
|
argName == ARG_RSFILE_L );
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Parses the list of command-line arguments for their argument names and
|
|
|
|
* values. */
|
|
|
|
void
|
2016-03-01 07:08:33 -05:00
|
|
|
Rshare::parseArguments(QStringList args, bool firstRun)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2016-03-01 07:08:33 -05:00
|
|
|
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(); 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.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2016-05-16 06:10:04 -04:00
|
|
|
/* handle opmode that could be change while running.*/
|
|
|
|
QString omValue = QString(value).prepend(";").append(";").toLower();
|
|
|
|
QString omValues = QString(";full;noturtle;gaming;minimal;");
|
2016-08-13 08:34:31 -04:00
|
|
|
if ((arg == ARG_OPMODE_S || arg == ARG_OPMODE_L ) &&
|
2016-05-16 06:10:04 -04:00
|
|
|
omValues.contains(omValue)) {
|
|
|
|
_opmode = value;
|
|
|
|
}
|
|
|
|
|
2016-03-01 07:08:33 -05:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Verifies that all specified arguments were valid. */
|
|
|
|
bool
|
|
|
|
Rshare::validateArguments(QString &errmsg)
|
|
|
|
{
|
2016-05-16 06:10:04 -04:00
|
|
|
/* Check for a writable log file */
|
|
|
|
if (_args.contains(ARG_LOGFILE) && !_log.isOpen()) {
|
|
|
|
errmsg = tr("Unable to open log file '%1': %2")
|
|
|
|
.arg(_args.value(ARG_LOGFILE))
|
|
|
|
.arg(_log.errorString());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* Check for a valid log level */
|
|
|
|
if (_args.contains(ARG_LOGLEVEL) &&
|
|
|
|
!Log::logLevels().contains(_args.value(ARG_LOGLEVEL))) {
|
|
|
|
errmsg = tr("Invalid log level specified:")+" " + _args.value(ARG_LOGLEVEL);
|
2007-11-14 22:18:48 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* Check for a valid GUI style */
|
|
|
|
if (_args.contains(ARG_GUISTYLE) &&
|
|
|
|
!QStyleFactory::keys().contains(_args.value(ARG_GUISTYLE),
|
|
|
|
Qt::CaseInsensitive)) {
|
2015-06-12 04:27:26 -04:00
|
|
|
errmsg = tr("Invalid GUI style specified:")+" " + _args.value(ARG_GUISTYLE);
|
2007-11-14 22:18:48 -05:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 06:10:04 -04:00
|
|
|
/* Check for a language that Retroshare recognizes. */
|
|
|
|
if (_args.contains(ARG_LANGUAGE) &&
|
|
|
|
!LanguageSupport::isValidLanguageCode(_args.value(ARG_LANGUAGE))) {
|
|
|
|
errmsg = tr("Invalid language code specified:")+" " + _args.value(ARG_LANGUAGE);
|
2008-08-15 13:49:57 -04:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 06:10:04 -04:00
|
|
|
/* Check for an opmode that Retroshare recognizes. */
|
2016-08-13 08:34:31 -04:00
|
|
|
if (_args.contains(ARG_OPMODE_S) &&
|
|
|
|
!QString(";full;noturtle;gaming;minimal;").contains(QString(_args.value(ARG_OPMODE_S)).prepend(";").append(";").toLower())) {
|
|
|
|
errmsg = tr("Invalid operating mode specified:")+" " + _args.value(ARG_OPMODE_S);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* Check for an opmode that Retroshare recognizes. */
|
|
|
|
if (_args.contains(ARG_OPMODE_L) &&
|
|
|
|
!QString(";full;noturtle;gaming;minimal;").contains(QString(_args.value(ARG_OPMODE_L)).prepend(";").append(";").toLower())) {
|
|
|
|
errmsg = tr("Invalid operating mode specified:")+" " + _args.value(ARG_OPMODE_L);
|
2008-08-15 13:49:57 -04:00
|
|
|
return false;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-01-16 03:12:16 -05:00
|
|
|
/** Sets the translation RetroShare will use. If one was specified on the
|
2007-11-14 22:18:48 -05:00
|
|
|
* command-line, we will use that. Otherwise, we'll check to see if one was
|
|
|
|
* saved previously. If not, we'll default to one appropriate for the system
|
|
|
|
* locale. */
|
|
|
|
bool
|
|
|
|
Rshare::setLanguage(QString languageCode)
|
|
|
|
{
|
|
|
|
/* If the language code is empty, use the previously-saved setting */
|
|
|
|
if (languageCode.isEmpty()) {
|
2010-05-20 17:53:27 -04:00
|
|
|
languageCode = Settings->getLanguageCode();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2011-11-17 16:17:24 -05:00
|
|
|
/* Translate into the desired language */
|
2007-11-14 22:18:48 -05:00
|
|
|
if (LanguageSupport::translate(languageCode)) {
|
|
|
|
_language = languageCode;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-10 13:59:58 -05:00
|
|
|
/** Sets the locale RetroShare will use. If a language was specified on the
|
|
|
|
* command-line, we will use one according to that. Otherwise, we'll check to see if a language was
|
|
|
|
* saved previously. If not, we'll default to the system
|
|
|
|
* locale. */
|
|
|
|
bool
|
|
|
|
Rshare::setLocale(QString languageCode)
|
|
|
|
{
|
|
|
|
bool retVal = false;
|
|
|
|
/* If the language code is empty, use the previously-saved setting */
|
|
|
|
if (languageCode.isEmpty()) {
|
|
|
|
languageCode = Settings->getLanguageCode();
|
|
|
|
}
|
|
|
|
/* Set desired locale as default locale */
|
|
|
|
if (LanguageSupport::localize(languageCode)) {
|
|
|
|
retVal=true;
|
|
|
|
}
|
|
|
|
customizeDateFormat();
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** customize date format for feeds etc. */
|
|
|
|
void Rshare::customizeDateFormat()
|
|
|
|
{
|
2012-11-15 16:35:37 -05:00
|
|
|
QLocale locale = QLocale(); // set to default locale
|
2012-11-10 13:59:58 -05:00
|
|
|
/* get long date format without weekday */
|
2012-11-15 16:35:37 -05:00
|
|
|
_dateformat = locale.dateFormat(QLocale::LongFormat);
|
|
|
|
_dateformat.replace(QRegExp("^dddd,*[^ ]* *('[^']+' )*"), "");
|
|
|
|
_dateformat.replace(QRegExp(",* *dddd"), "");
|
|
|
|
_dateformat = _dateformat.trimmed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get custom date format (defaultlongformat) */
|
|
|
|
QString Rshare::customDateFormat()
|
|
|
|
{
|
|
|
|
return _dateformat;
|
2012-11-10 13:59:58 -05:00
|
|
|
}
|
|
|
|
|
2008-01-16 03:12:16 -05:00
|
|
|
/** Sets the GUI style RetroShare will use. If one was specified on the
|
2007-11-14 22:18:48 -05:00
|
|
|
* command-line, we will use that. Otherwise, we'll check to see if one was
|
|
|
|
* saved previously. If not, we'll default to one appropriate for the
|
|
|
|
* operating system. */
|
|
|
|
bool
|
|
|
|
Rshare::setStyle(QString styleKey)
|
|
|
|
{
|
|
|
|
/* If no style was specified, use the previously-saved setting */
|
|
|
|
if (styleKey.isEmpty()) {
|
2010-05-20 17:53:27 -04:00
|
|
|
styleKey = Settings->getInterfaceStyle();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
/* Apply the specified GUI style */
|
|
|
|
if (QApplication::setStyle(styleKey)) {
|
|
|
|
_style = styleKey;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-16 03:12:16 -05:00
|
|
|
bool
|
|
|
|
Rshare::setSheet(QString sheet)
|
|
|
|
{
|
|
|
|
/* If no stylesheet was specified, use the previously-saved setting */
|
|
|
|
if (sheet.isEmpty()) {
|
2010-05-20 17:53:27 -04:00
|
|
|
sheet = Settings->getSheetName();
|
2008-01-16 03:12:16 -05:00
|
|
|
}
|
|
|
|
/* Apply the specified GUI stylesheet */
|
|
|
|
_stylesheet = sheet;
|
2012-09-01 07:40:54 -04:00
|
|
|
|
|
|
|
/* load the StyleSheet*/
|
|
|
|
loadStyleSheet(_stylesheet);
|
|
|
|
|
2008-01-16 03:12:16 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-14 17:16:34 -04:00
|
|
|
void Rshare::resetLanguageAndStyle()
|
|
|
|
{
|
|
|
|
/** Translate the GUI to the appropriate language. */
|
|
|
|
setLanguage(_args.value(ARG_LANGUAGE));
|
|
|
|
|
2012-11-10 13:59:58 -05:00
|
|
|
/** Set the locale appropriately. */
|
|
|
|
setLocale(_args.value(ARG_LANGUAGE));
|
|
|
|
|
|
|
|
/** Set the GUI style appropriately. */
|
2011-10-14 17:16:34 -04:00
|
|
|
setStyle(_args.value(ARG_GUISTYLE));
|
|
|
|
|
|
|
|
/** Set the GUI stylesheet appropriately. */
|
|
|
|
setSheet(_args.value(ARG_GUISTYLESHEET));
|
|
|
|
}
|
|
|
|
|
2015-06-28 06:11:47 -04:00
|
|
|
// RetroShare:
|
|
|
|
// Default:
|
|
|
|
// :/qss/stylesheet/qss.default
|
|
|
|
// :/qss/stylesheet/qss.<locale>
|
|
|
|
// Internal:
|
|
|
|
// :/qss/stylesheet/<name>.qss
|
|
|
|
// External:
|
|
|
|
// <ConfigDirectory|DataDirectory>/qss/<name>.qss
|
|
|
|
// Language depended stylesheet
|
|
|
|
// <Internal|External>_<locale>.lqss
|
|
|
|
//
|
|
|
|
// Plugin:
|
|
|
|
// Default:
|
|
|
|
// :/qss/stylesheet/<plugin>/<plugin>_qss.default
|
|
|
|
// :/qss/stylesheet/<plugin>/<plugin>_qss.<locale>
|
|
|
|
// Internal:
|
|
|
|
// :/qss/stylesheet/<plugin>/<plugin>_<name>.qss
|
|
|
|
// External:
|
|
|
|
// <ConfigDirectory|DataDirectory>/qss/<plugin>/<plugin>_<name>.qss
|
|
|
|
// Language depended stylesheet
|
|
|
|
// <Internal|External>_<locale>.lqss
|
|
|
|
|
2012-05-02 16:19:51 -04:00
|
|
|
void Rshare::loadStyleSheet(const QString &sheetName)
|
|
|
|
{
|
2013-01-09 07:16:12 -05:00
|
|
|
QString locale = QLocale().name();
|
2012-05-02 16:19:51 -04:00
|
|
|
QString styleSheet;
|
|
|
|
|
2015-06-28 06:11:47 -04:00
|
|
|
QStringList names;
|
|
|
|
names.push_back(""); // RetroShare
|
|
|
|
|
|
|
|
/* Get stylesheet from plugins */
|
|
|
|
if (rsPlugins) {
|
|
|
|
int count = rsPlugins->nbPlugins();
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
RsPlugin* plugin = rsPlugins->plugin(i);
|
|
|
|
if (plugin) {
|
|
|
|
QString pluginStyleSheetName = QString::fromUtf8(plugin->qt_stylesheet().c_str());
|
|
|
|
if (!pluginStyleSheetName.isEmpty()) {
|
|
|
|
names.push_back(QString("%1/%1_").arg(pluginStyleSheetName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-09 07:16:12 -05:00
|
|
|
}
|
|
|
|
|
2015-06-28 06:11:47 -04:00
|
|
|
foreach (QString name, names) {
|
|
|
|
/* load the default stylesheet */
|
|
|
|
QFile file(QString(":/qss/stylesheet/%1qss.default").arg(name));
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
styleSheet += QLatin1String(file.readAll()) + "\n";
|
|
|
|
file.close();
|
2012-08-24 19:35:57 -04:00
|
|
|
}
|
2015-06-28 06:11:47 -04:00
|
|
|
|
|
|
|
/* load locale depended default stylesheet */
|
|
|
|
file.setFileName(QString(":/qss/stylesheet/%1qss.%2").arg(name, locale));
|
2012-05-02 16:19:51 -04:00
|
|
|
if (file.open(QFile::ReadOnly)) {
|
2013-01-09 07:16:12 -05:00
|
|
|
styleSheet += QLatin1String(file.readAll()) + "\n";
|
2012-05-02 16:19:51 -04:00
|
|
|
file.close();
|
2015-06-28 06:11:47 -04:00
|
|
|
}
|
2013-01-09 07:16:12 -05:00
|
|
|
|
2015-06-28 06:11:47 -04:00
|
|
|
if (!sheetName.isEmpty()) {
|
|
|
|
/* load stylesheet */
|
|
|
|
if (sheetName.left(1) == ":") {
|
|
|
|
/* internal stylesheet */
|
|
|
|
file.setFileName(QString(":/qss/stylesheet/%1%2.qss").arg(name, sheetName.mid(1)));
|
|
|
|
} else {
|
|
|
|
/* external stylesheet */
|
|
|
|
file.setFileName(QString("%1/qss/%2%3.qss").arg(QString::fromUtf8(RsAccounts::ConfigDirectory().c_str()), name, sheetName));
|
|
|
|
if (!file.exists()) {
|
2018-07-24 17:47:32 -04:00
|
|
|
file.setFileName(QString("%1/qss/%2%3.qss").arg(QString::fromUtf8(RsAccounts::systemDataDirectory().c_str()), name, sheetName));
|
2015-06-28 06:11:47 -04:00
|
|
|
}
|
|
|
|
}
|
2013-01-09 07:16:12 -05:00
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
styleSheet += QLatin1String(file.readAll()) + "\n";
|
|
|
|
file.close();
|
2015-06-28 06:11:47 -04:00
|
|
|
|
|
|
|
/* load language depended stylesheet */
|
|
|
|
QFileInfo fileInfo(file.fileName());
|
|
|
|
file.setFileName(fileInfo.path() + "/" + fileInfo.baseName() + "_" + locale + ".lqss");
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
styleSheet += QLatin1String(file.readAll()) + "\n";
|
|
|
|
file.close();
|
|
|
|
}
|
2019-04-14 07:55:27 -04:00
|
|
|
|
|
|
|
/* replace %THISPATH% by file path so url can get relative files */
|
|
|
|
styleSheet = styleSheet.replace("url(%THISPATH%",QString("url(%1").arg(fileInfo.absolutePath()));
|
2013-01-09 07:16:12 -05:00
|
|
|
}
|
2012-05-02 16:19:51 -04:00
|
|
|
}
|
|
|
|
}
|
2015-06-28 06:11:47 -04:00
|
|
|
|
2012-05-02 16:19:51 -04:00
|
|
|
qApp->setStyleSheet(styleSheet);
|
|
|
|
}
|
|
|
|
|
2012-08-24 19:35:57 -04:00
|
|
|
/** get list of available stylesheets **/
|
|
|
|
void Rshare::getAvailableStyleSheets(QMap<QString, QString> &styleSheets)
|
|
|
|
{
|
|
|
|
QFileInfoList fileInfoList = QDir(":/qss/stylesheet/").entryInfoList(QStringList("*.qss"));
|
|
|
|
QFileInfo fileInfo;
|
|
|
|
foreach (fileInfo, fileInfoList) {
|
|
|
|
if (fileInfo.isFile()) {
|
|
|
|
QString name = fileInfo.baseName();
|
|
|
|
styleSheets.insert(QString("%1 (%2)").arg(name, tr("built-in")), ":" + name);
|
|
|
|
}
|
|
|
|
}
|
2014-01-17 21:35:06 -05:00
|
|
|
fileInfoList = QDir(QString::fromUtf8(RsAccounts::ConfigDirectory().c_str()) + "/qss/").entryInfoList(QStringList("*.qss"));
|
2012-08-24 19:35:57 -04:00
|
|
|
foreach (fileInfo, fileInfoList) {
|
|
|
|
if (fileInfo.isFile()) {
|
|
|
|
QString name = fileInfo.baseName();
|
|
|
|
styleSheets.insert(name, name);
|
|
|
|
}
|
|
|
|
}
|
2018-07-24 17:47:32 -04:00
|
|
|
fileInfoList = QDir(QString::fromUtf8(RsAccounts::systemDataDirectory().c_str()) + "/qss/").entryInfoList(QStringList("*.qss"));
|
2012-10-12 14:42:24 -04:00
|
|
|
foreach (fileInfo, fileInfoList) {
|
|
|
|
if (fileInfo.isFile()) {
|
|
|
|
QString name = fileInfo.baseName();
|
|
|
|
if (!styleSheets.contains(name)) {
|
|
|
|
styleSheets.insert(name, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-24 19:35:57 -04:00
|
|
|
}
|
|
|
|
|
2012-05-19 18:18:15 -04:00
|
|
|
void Rshare::refreshStyleSheet(QWidget *widget, bool processChildren)
|
|
|
|
{
|
|
|
|
if (widget != NULL) {
|
|
|
|
// force widget to recalculate valid style
|
|
|
|
widget->style()->unpolish(widget);
|
|
|
|
widget->style()->polish(widget);
|
|
|
|
// widget might need to recalculate properties (like margins) depending on style
|
|
|
|
QEvent event(QEvent::StyleChange);
|
|
|
|
QApplication::sendEvent(widget, &event);
|
|
|
|
// repaint widget
|
|
|
|
widget->update();
|
|
|
|
|
|
|
|
if (processChildren == true) {
|
|
|
|
// process children recursively
|
|
|
|
QObjectList childList = widget->children ();
|
2014-10-21 18:33:02 -04:00
|
|
|
for (QObjectList::Iterator it = childList.begin(); it != childList.end(); ++it) {
|
2012-05-19 18:18:15 -04:00
|
|
|
QWidget *child = qobject_cast<QWidget*>(*it);
|
|
|
|
if (child != NULL) {
|
|
|
|
refreshStyleSheet(child, processChildren);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-17 16:17:24 -05:00
|
|
|
/** Initialize plugins. */
|
|
|
|
void Rshare::initPlugins()
|
|
|
|
{
|
2015-06-28 06:11:47 -04:00
|
|
|
loadStyleSheet(_stylesheet);
|
2011-11-17 16:17:24 -05:00
|
|
|
LanguageSupport::translatePlugins(_language);
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/** Returns the directory RetroShare uses for its data files. */
|
|
|
|
QString
|
|
|
|
Rshare::dataDirectory()
|
|
|
|
{
|
|
|
|
if (useConfigDir)
|
|
|
|
{
|
|
|
|
return configDir;
|
|
|
|
}
|
|
|
|
else if (_args.contains(ARG_DATADIR)) {
|
|
|
|
return _args.value(ARG_DATADIR);
|
|
|
|
}
|
|
|
|
return defaultDataDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns the default location of RetroShare's data directory. */
|
|
|
|
QString
|
|
|
|
Rshare::defaultDataDirectory()
|
|
|
|
{
|
2015-08-29 15:31:01 -04:00
|
|
|
#if defined(Q_OS_WIN)
|
2007-11-14 22:18:48 -05:00
|
|
|
return (win32_app_data_folder() + "\\RetroShare");
|
|
|
|
#else
|
|
|
|
return (QDir::homePath() + "/.RetroShare");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Creates Rshare's data directory, if it doesn't already exist. */
|
|
|
|
bool
|
|
|
|
Rshare::createDataDirectory(QString *errmsg)
|
|
|
|
{
|
|
|
|
QDir datadir(dataDirectory());
|
|
|
|
if (!datadir.exists()) {
|
|
|
|
QString path = datadir.absolutePath();
|
|
|
|
if (!datadir.mkpath(path)) {
|
|
|
|
return err(errmsg,
|
2014-07-10 14:37:21 -04:00
|
|
|
tr("Could not create data directory: %1").arg(path));
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set Rshare's data directory - externally */
|
|
|
|
bool Rshare::setConfigDirectory(QString dir)
|
|
|
|
{
|
|
|
|
useConfigDir = true;
|
|
|
|
configDir = dir;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-13 16:05:55 -04:00
|
|
|
/** Writes <b>msg</b> with severity <b>level</b> to RetroShare's log. */
|
2008-08-15 13:49:57 -04:00
|
|
|
Log::LogMessage
|
|
|
|
Rshare::log(Log::LogLevel level, QString msg)
|
|
|
|
{
|
|
|
|
return _log.log(level, msg);
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-08-15 16:07:54 -04:00
|
|
|
/** Creates and binds a shortcut such that when <b>key</b> is pressed in
|
|
|
|
* <b>sender</b>'s context, <b>receiver</b>'s <b>slot</b> will be called. */
|
|
|
|
void
|
|
|
|
Rshare::createShortcut(const QKeySequence &key, QWidget *sender,
|
|
|
|
QWidget *receiver, const char *slot)
|
|
|
|
{
|
|
|
|
QShortcut *s = new QShortcut(key, sender);
|
|
|
|
connect(s, SIGNAL(activated()), receiver, slot);
|
|
|
|
}
|
2012-10-25 14:06:33 -04:00
|
|
|
|
2016-03-01 07:08:33 -05:00
|
|
|
#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
|
|
|
|
|
2012-10-25 14:06:33 -04:00
|
|
|
void Rshare::blinkTimer()
|
|
|
|
{
|
|
|
|
mBlink = !mBlink;
|
|
|
|
emit blink(mBlink);
|
2013-03-17 12:31:30 -04:00
|
|
|
|
|
|
|
if (mBlink) {
|
|
|
|
/* Tick every second (create an own timer when needed) */
|
|
|
|
emit secondTick();
|
|
|
|
}
|
2012-10-25 14:06:33 -04:00
|
|
|
}
|
2012-10-31 21:07:36 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
bool Rshare::loadCertificate(const RsPeerId &accountId, bool autoLogin)
|
2012-10-31 21:07:36 -04:00
|
|
|
{
|
2014-01-17 21:35:06 -05:00
|
|
|
if (!RsAccounts::SelectAccount(accountId))
|
|
|
|
{
|
2012-10-31 21:07:36 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string lockFile;
|
|
|
|
int retVal = RsInit::LockAndLoadCertificates(autoLogin, lockFile);
|
|
|
|
switch (retVal) {
|
|
|
|
case 0: break;
|
|
|
|
case 1: QMessageBox::warning( 0,
|
|
|
|
QObject::tr("Multiple instances"),
|
|
|
|
QObject::tr("Another RetroShare using the same profile is "
|
|
|
|
"already running on your system. Please close "
|
|
|
|
"that instance first\n Lock file:\n") +
|
|
|
|
QString::fromUtf8(lockFile.c_str()));
|
|
|
|
return false;
|
|
|
|
case 2: QMessageBox::critical( 0,
|
|
|
|
QObject::tr("Multiple instances"),
|
|
|
|
QObject::tr("An unexpected error occurred when Retroshare "
|
|
|
|
"tried to acquire the single instance lock\n Lock file:\n") +
|
|
|
|
QString::fromUtf8(lockFile.c_str()));
|
2015-06-11 16:31:52 -04:00
|
|
|
return false;
|
|
|
|
case 3:
|
|
|
|
// case 3: QMessageBox::critical( 0,
|
|
|
|
// QObject::tr("Login Failure"),
|
|
|
|
// QObject::tr("Maybe password is wrong") );
|
2012-10-31 21:07:36 -04:00
|
|
|
return false;
|
|
|
|
default: std::cerr << "Rshare::loadCertificate() unexpected switch value " << retVal << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-01 07:08:33 -05:00
|
|
|
|
|
|
|
bool Rshare::updateLocalServer()
|
|
|
|
{
|
|
|
|
if (localServer) {
|
|
|
|
QString serverName = QString(TARGET);
|
|
|
|
if (Settings->getUseLocalServer()) {
|
|
|
|
localServer->removeServer(serverName);
|
|
|
|
localServer->listen(serverName);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
localServer->close();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|