additional step in rewriting commandline parameter handling

This commit is contained in:
csoler 2024-02-11 22:16:50 +01:00
parent 4f56c7dd2f
commit c5aface2cb
21 changed files with 878 additions and 688 deletions

View file

@ -50,6 +50,7 @@
#include <lang/languagesupport.h>
#include <util/stringutil.h>
#include <util/argstream.h>
#include <retroshare/rsinit.h>
#include <retroshare/rsversion.h>
#include <retroshare/rsplugin.h>
@ -57,7 +58,7 @@
#include "rshare.h"
/* Available command-line arguments. */
#define ARG_RESET "reset" /**< Reset Rshare's saved settings. */
#define ARG_RESET "reset" /**< Reset RsApplication'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. */
@ -86,19 +87,22 @@ static const char* const forwardableArgs[] = {
};
/* Static member variables */
QMap<QString, QString> Rshare::_args; /**< List of command-line arguments. */
Log Rshare::_log; /**< Logs debugging messages to file or stdout. */
QString Rshare::_style; /**< The current GUI style. */
QString Rshare::_stylesheet; /**< The current GUI stylesheet. */
QString Rshare::_language; /**< The current language. */
QString Rshare::_dateformat; /**< The format of dates in feed items etc. */
QString Rshare::_opmode; /**< The operating mode passed by args. */
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;
QLocalServer* Rshare::localServer;
#ifdef TO_REMOVE
QMap<QString, QString> RsApplication::_args; /**< List of command-line arguments. */
QString RsApplication::_style; /**< The current GUI style. */
QString RsApplication::_stylesheet; /**< The current GUI stylesheet. */
QString RsApplication::_language; /**< The current language. */
QString RsApplication::_dateformat; /**< The format of dates in feed items etc. */
QString RsApplication::_opmode; /**< The operating mode passed by args. */
QStringList RsApplication::_links; /**< List of links passed by arguments. */
QStringList RsApplication::_files; /**< List of files passed by arguments. */
bool RsApplication::useConfigDir;
QString RsApplication::configDir;
#endif
Log RsApplication::log_output; /**< Logs debugging messages to file or stdout. */
RsGUIConfigOptions RsApplication::options;
QDateTime RsApplication::mStartupTime;
QLocalServer* RsApplication::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().
@ -133,194 +137,177 @@ void qt_msg_handler(QtMsgType type, const char *msg)
}
}
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));
#ifdef DEBUG
std::cerr << "Rshare::Rshare waitForConnected to other instance." << std::endl;
#endif
if( localSocket.waitForConnected(100) )
{
#ifdef DEBUG
std::cerr << "Rshare::Rshare Connection etablished. Waiting for disconnection." << std::endl;
#endif
localSocket.waitForDisconnected(1000);
return true;
}
else
{
#ifdef DEBUG
std::cerr << "Rshare::Rshare failed to connect to other instance." << std::endl;
#endif
return false;
}
}
/** Constructor. Parses the command-line arguments, resets Rshare's
/** Constructor. Parses the command-line arguments, resets RsApplication's
* configuration (if requested), and sets up the GUI style and language
* translation. */
Rshare::Rshare(QStringList args, int &argc, char **argv, const QString &dir)
: QApplication(argc, argv)
* translation.
* the const_cast below is truely horrible, but it allows to hide these unused argc/argv
* when initing RsApplication
*/
RsApplication::RsApplication(const RsGUIConfigOptions& conf)
: QApplication(const_cast<RsGUIConfigOptions*>(&conf)->argc,const_cast<RsGUIConfigOptions*>(&conf)->argv)
{
mStartupTime = QDateTime::currentDateTime();
localServer = NULL;
mStartupTime = QDateTime::currentDateTime();
localServer = NULL;
options = conf;
//Initialize connection to LocalServer to know if other process runs.
{
QString serverName = QString(TARGET);
// 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 iCurs = 0; iCurs < args.size(); ++iCurs)
#ifdef TO_REMOVE
//Initialize connection to LocalServer to know if other process runs.
{
const char* const* argit = forwardableArgs;
bool found = false;
while(*argit && iCurs < args.size())
{
if(args.value(iCurs) == "-"+QString(*argit) || args.value(iCurs) == "--"+QString(*argit))
{
found = true;
if(argNeedsValue(*argit))
iCurs++;
}
argit++;
}
if(!found)
QString serverName = QString(TARGET);
// 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 iCurs = 0; iCurs < args.size(); ++iCurs)
{
const char* const* argit = forwardableArgs;
bool found = false;
while(*argit && iCurs < args.size())
{
if(args.value(iCurs) == "-"+QString(*argit) || args.value(iCurs) == "--"+QString(*argit))
{
found = true;
if(argNeedsValue(*argit))
iCurs++;
}
argit++;
}
if(!found)
sendArgsToRunningInstance = false;
}
if (sendArgsToRunningInstance) {
// load into shared memory
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
QDataStream out(&buffer);
out << args;
int size = buffer.size();
if (sendArgsToRunningInstance) {
// 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();
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;
if (!newArgs.create(size)) {
std::cerr << "(EE) RsApplication::RsApplication 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.
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();
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;
if(notifyRunningInstance())
{
newArgs.detach();
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;
::exit(EXIT_SUCCESS); // Terminate the program using STDLib's exit function
}
else
std::cerr << "Rshare::Rshare failed to connect to other instance." << std::endl;
newArgs.detach();
}
std::cerr << "RsApplication::RsApplication waitForConnected to other instance." << std::endl;
if(notifyRunningInstance())
{
newArgs.detach();
std::cerr << "RsApplication::RsApplication Arguments was sended." << std::endl
<< " To disable it, in Options - General - Misc," << std::endl
<< " uncheck \"Use Local Server to get new Arguments\"." << std::endl;
::exit(EXIT_SUCCESS); // Terminate the program using STDLib's exit function
}
else
std::cerr << "RsApplication::RsApplication failed to connect to other instance." << std::endl;
newArgs.detach();
}
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();
// clear out any old arguments (race condition?)
QSharedMemory newArgs;
newArgs.setKey(QString(TARGET) + "_newArgs");
if(newArgs.attach(QSharedMemory::ReadWrite))
newArgs.detach();
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();
// clear out any old arguments (race condition?)
QSharedMemory newArgs;
newArgs.setKey(QString(TARGET) + "_newArgs");
if(newArgs.attach(QSharedMemory::ReadWrite))
newArgs.detach();
}
}
}
#endif
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
qInstallMessageHandler(qt_msg_handler);
qInstallMessageHandler(qt_msg_handler);
#else
qInstallMsgHandler(qt_msg_handler);
qInstallMsgHandler(qt_msg_handler);
#endif
#ifndef __APPLE__
/* set default window icon */
setWindowIcon(FilesDefs::getIconFromQtResourcePath(":/icons/logo_128.png"));
/* set default window icon */
setWindowIcon(FilesDefs::getIconFromQtResourcePath(":/icons/logo_128.png"));
#endif
mBlink = true;
QTimer *timer = new QTimer(this);
timer->setInterval(500);
connect(timer, SIGNAL(timeout()), this, SLOT(blinkTimer()));
timer->start();
mBlink = true;
QTimer *timer = new QTimer(this);
timer->setInterval(500);
connect(timer, SIGNAL(timeout()), this, SLOT(blinkTimer()));
timer->start();
timer = new QTimer(this);
timer->setInterval(60000);
connect(timer, SIGNAL(timeout()), this, SIGNAL(minuteTick()));
timer->start();
timer = new QTimer(this);
timer->setInterval(60000);
connect(timer, SIGNAL(timeout()), this, SIGNAL(minuteTick()));
timer->start();
/* Read in all our command-line arguments. */
parseArguments(args);
#ifdef TO_REMOVE
/* Read in all our command-line arguments. */
parseArguments(args);
#endif
/* Check if we're supposed to reset our config before proceeding. */
if (_args.contains(ARG_RESET)) {
Settings->reset();
}
/* 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);
/* Check if we're supposed to reset our config before proceeding. */
if (options.optResetParams)
{
RsInfo() << "Resetting Retroshare config parameters, as requested (option -R)";
Settings->reset();
}
/* config directory */
useConfigDir = false;
if (dir != "")
{
setConfigDirectory(dir);
}
/* Handle the -loglevel and -logfile options. */
if (options.logLevel != "Off")
{
if (!options.logFileName.isNull())
log_output.open(options.logFileName);
else
log_output.open(stdout);
/** Initialize support for language translations. */
//LanguageSupport::initialize();
log_output.setLogLevel(Log::stringToLogLevel(options.logLevel));
}
resetLanguageAndStyle();
#ifdef TO_REMOVE
/* config directory */
useConfigDir = false;
if (!conf.optBaseDir.empty())
setConfigDirectory(QString::fromStdString(conf.optBaseDir));
#endif
/* Switch off auto shutdown */
setQuitOnLastWindowClosed ( false );
/** Initialize support for language translations. */
//LanguageSupport::initialize();
/* Initialize GxsIdDetails */
GxsIdDetails::initialize();
resetLanguageAndStyle();
/* Switch off auto shutdown */
setQuitOnLastWindowClosed ( false );
/* Initialize GxsIdDetails */
GxsIdDetails::initialize();
}
/** Destructor */
Rshare::~Rshare()
RsApplication::~RsApplication()
{
/* Cleanup GxsIdDetails */
GxsIdDetails::cleanup();
@ -334,7 +321,7 @@ Rshare::~Rshare()
/**
* @brief Executed when new instance connect command is sent to LocalServer
*/
void Rshare::slotConnectionEstablished()
void RsApplication::slotConnectionEstablished()
{
QSharedMemory newArgs;
newArgs.setKey(QString(TARGET) + "_newArgs");
@ -346,7 +333,7 @@ void Rshare::slotConnectionEstablished()
/* 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."
std::cerr << "(EE) RsApplication::slotConnectionEstablished() Unable to attach to shared memory segment."
<< newArgs.errorString().toStdString() << std::endl;
*/
socket->close();
@ -371,22 +358,22 @@ void Rshare::slotConnectionEstablished()
emit newArgsReceived(args);
while (!args.empty())
{
std::cerr << "Rshare::slotConnectionEstablished args:" << QString(args.takeFirst()).toStdString() << std::endl;
std::cerr << "RsApplication::slotConnectionEstablished args:" << QString(args.takeFirst()).toStdString() << std::endl;
}
}
QString Rshare::retroshareVersion(bool) { return RS_HUMAN_READABLE_VERSION; }
QString RsApplication::retroshareVersion(bool) { return RS_HUMAN_READABLE_VERSION; }
/** 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()
RsApplication::run()
{
QTimer::singleShot(0, rApp, SLOT(onEventLoopStarted()));
return rApp->exec();
}
QDateTime Rshare::startupTime()
QDateTime RsApplication::startupTime()
{
return mStartupTime;
}
@ -395,14 +382,15 @@ QDateTime Rshare::startupTime()
* will emit the running() signal to indicate that the application's event
* loop is running. */
void
Rshare::onEventLoopStarted()
RsApplication::onEventLoopStarted()
{
emit running();
}
#ifdef TO_REMOVE
/** Display usage information regarding command-line arguments. */
/*void
Rshare::printUsage(QString errmsg)
RsApplication::printUsage(QString errmsg)
{
QTextStream out(stdout);*/
@ -417,18 +405,18 @@ Rshare::printUsage(QString errmsg)
/* And available options */
//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-"ARG_RESET"\t\tResets ALL stored RsApplication settings." << endl;
//out << "\t-"ARG_DATADIR"\tSets the directory RsApplication uses for data files"<< endl;
//out << "\t-"ARG_GUISTYLE"\t\tSets RsApplication's interface style." << endl;
//out << "\t-"ARG_GUISTYLESHEET"\t\tSets RsApplication's stylesheet." << endl;
//out << "\t\t\t[" << QStyleFactory::keys().join("|") << "]" << endl;
//out << "\t-"ARG_LANGUAGE"\t\tSets Rshare's language." << endl;
//out << "\t-"ARG_LANGUAGE"\t\tSets RsApplication's language." << endl;
//out << "\t\t\t[" << LanguageSupport::languageCodes().join("|") << "]" << endl;
//}
/** Displays usage information for command-line args. */
void
Rshare::showUsageMessageBox()
RsApplication::showUsageMessageBox()
{
QString usage;
QTextStream out(&usage);
@ -469,7 +457,7 @@ Rshare::showUsageMessageBox()
/** Returns true if the specified argument expects a value. */
bool
Rshare::argNeedsValue(const QString &argName)
RsApplication::argNeedsValue(const QString &argName)
{
return (
argName == ARG_DATADIR ||
@ -489,9 +477,12 @@ Rshare::argNeedsValue(const QString &argName)
/** Parses the list of command-line arguments for their argument names and
* values. */
void
Rshare::parseArguments(QStringList args, bool firstRun)
RsApplication::parseArguments(QStringList args, bool firstRun)
{
QString arg, argl, value;
std::vector<const char *> argv;
for(auto l:args)
argv.push_back((const char *)l.data());
/* Loop through all command-line args/values and put them in a map */
for (int iCurs = 0; iCurs < args.size(); ++iCurs) {
@ -539,11 +530,12 @@ Rshare::parseArguments(QStringList args, bool firstRun)
_args.insert(arg, value);
}
}
}
/** Verifies that all specified arguments were valid. */
bool
Rshare::validateArguments(QString &errmsg)
RsApplication::validateArguments(QString &errmsg)
{
/* Check for a writable log file */
if (_args.contains(ARG_LOGFILE) && !_log.isOpen()) {
@ -585,13 +577,14 @@ Rshare::validateArguments(QString &errmsg)
}
return true;
}
#endif
/** Sets the translation RetroShare will use. If one was specified on the
* 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)
RsApplication::setLanguage(QString languageCode)
{
/* If the language code is empty, use the previously-saved setting */
if (languageCode.isEmpty()) {
@ -599,7 +592,7 @@ Rshare::setLanguage(QString languageCode)
}
/* Translate into the desired language */
if (LanguageSupport::translate(languageCode)) {
_language = languageCode;
options.language = languageCode;
return true;
}
return false;
@ -610,7 +603,7 @@ Rshare::setLanguage(QString languageCode)
* saved previously. If not, we'll default to the system
* locale. */
bool
Rshare::setLocale(QString languageCode)
RsApplication::setLocale(QString languageCode)
{
bool retVal = false;
/* If the language code is empty, use the previously-saved setting */
@ -626,20 +619,20 @@ Rshare::setLocale(QString languageCode)
}
/** customize date format for feeds etc. */
void Rshare::customizeDateFormat()
void RsApplication::customizeDateFormat()
{
QLocale locale = QLocale(); // set to default locale
/* get long date format without weekday */
_dateformat = locale.dateFormat(QLocale::LongFormat);
_dateformat.replace(QRegExp("^dddd,*[^ ]* *('[^']+' )*"), "");
_dateformat.replace(QRegExp(",* *dddd"), "");
_dateformat = _dateformat.trimmed();
options.dateformat = locale.dateFormat(QLocale::LongFormat);
options.dateformat.replace(QRegExp("^dddd,*[^ ]* *('[^']+' )*"), "");
options.dateformat.replace(QRegExp(",* *dddd"), "");
options.dateformat = options.dateformat.trimmed();
}
/** Get custom date format (defaultlongformat) */
QString Rshare::customDateFormat()
QString RsApplication::customDateFormat()
{
return _dateformat;
return options.dateformat;
}
/** Sets the GUI style RetroShare will use. If one was specified on the
@ -647,49 +640,50 @@ QString Rshare::customDateFormat()
* saved previously. If not, we'll default to one appropriate for the
* operating system. */
bool
Rshare::setStyle(QString styleKey)
RsApplication::setStyle(QString styleKey)
{
/* If no style was specified, use the previously-saved setting */
if (styleKey.isEmpty()) {
styleKey = Settings->getInterfaceStyle();
}
/* Apply the specified GUI style */
if (QApplication::setStyle(styleKey)) {
_style = styleKey;
if (QApplication::setStyle(styleKey))
{
options.guiStyle = styleKey;
return true;
}
return false;
}
bool
Rshare::setSheet(QString sheet)
RsApplication::setSheet(QString sheet)
{
/* If no stylesheet was specified, use the previously-saved setting */
if (sheet.isEmpty()) {
sheet = Settings->getSheetName();
}
/* Apply the specified GUI stylesheet */
_stylesheet = sheet;
options.guiStyleSheetFile = sheet;
/* load the StyleSheet*/
loadStyleSheet(_stylesheet);
loadStyleSheet(options.guiStyleSheetFile);
return true;
}
void Rshare::resetLanguageAndStyle()
void RsApplication::resetLanguageAndStyle()
{
/** Translate the GUI to the appropriate language. */
setLanguage(_args.value(ARG_LANGUAGE));
setLanguage(options.language);
/** Set the locale appropriately. */
setLocale(_args.value(ARG_LANGUAGE));
setLocale(options.language);
/** Set the GUI style appropriately. */
setStyle(_args.value(ARG_GUISTYLE));
setStyle(options.guiStyle);
/** Set the GUI stylesheet appropriately. */
setSheet(_args.value(ARG_GUISTYLESHEET));
setSheet(options.guiStyleSheetFile);
}
// RetroShare:
@ -714,7 +708,7 @@ void Rshare::resetLanguageAndStyle()
// Language depended stylesheet
// <Internal|External>_<locale>.lqss
void Rshare::loadStyleSheet(const QString &sheetName)
void RsApplication::loadStyleSheet(const QString &sheetName)
{
QString locale = QLocale().name();
QString styleSheet;
@ -785,7 +779,7 @@ void Rshare::loadStyleSheet(const QString &sheetName)
}
/** get list of available stylesheets **/
void Rshare::getAvailableStyleSheets(QMap<QString, QString> &styleSheets)
void RsApplication::getAvailableStyleSheets(QMap<QString, QString> &styleSheets)
{
QFileInfoList fileInfoList = QDir(":/qss/stylesheet/").entryInfoList(QStringList("*.qss"));
QFileInfo fileInfo;
@ -813,7 +807,7 @@ void Rshare::getAvailableStyleSheets(QMap<QString, QString> &styleSheets)
}
}
void Rshare::refreshStyleSheet(QWidget *widget, bool processChildren)
void RsApplication::refreshStyleSheet(QWidget *widget, bool processChildren)
{
if (widget != NULL) {
// force widget to recalculate valid style
@ -839,40 +833,35 @@ void Rshare::refreshStyleSheet(QWidget *widget, bool processChildren)
}
/** Initialize plugins. */
void Rshare::initPlugins()
void RsApplication::initPlugins()
{
loadStyleSheet(_stylesheet);
LanguageSupport::translatePlugins(_language);
loadStyleSheet(options.guiStyleSheetFile);
LanguageSupport::translatePlugins(options.language);
}
/** Returns the directory RetroShare uses for its data files. */
QString
Rshare::dataDirectory()
QString RsApplication::dataDirectory()
{
if (useConfigDir)
{
return configDir;
}
else if (_args.contains(ARG_DATADIR)) {
return _args.value(ARG_DATADIR);
}
return defaultDataDirectory();
if(!options.optBaseDir.empty())
return QString::fromUtf8(options.optBaseDir.c_str());
else
return defaultDataDirectory();
}
/** Returns the default location of RetroShare's data directory. */
QString
Rshare::defaultDataDirectory()
RsApplication::defaultDataDirectory()
{
#if defined(Q_OS_WIN)
return (win32_app_data_folder() + "\\RetroShare");
#else
return (QDir::homePath() + "/.RetroShare");
return (QDir::homePath() + "/.retroshare");
#endif
}
/** Creates Rshare's data directory, if it doesn't already exist. */
/** Creates RsApplication's data directory, if it doesn't already exist. */
bool
Rshare::createDataDirectory(QString *errmsg)
RsApplication::createDataDirectory(QString *errmsg)
{
QDir datadir(dataDirectory());
if (!datadir.exists()) {
@ -885,33 +874,29 @@ Rshare::createDataDirectory(QString *errmsg)
return true;
}
/** Set Rshare's data directory - externally */
bool Rshare::setConfigDirectory(const QString& dir)
/** Set RsApplication's data directory - externally */
bool RsApplication::setConfigDirectory(const QString& dir)
{
useConfigDir = true;
configDir = dir;
options.optBaseDir = std::string(dir.toUtf8());
return true;
}
/** Writes <b>msg</b> with severity <b>level</b> to RetroShare's log. */
Log::LogMessage
Rshare::log(Log::LogLevel level, QString msg)
Log::LogMessage RsApplication::log(Log::LogLevel level, QString msg)
{
return _log.log(level, msg);
return log_output.log(level, msg);
}
/** 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)
void RsApplication::createShortcut(const QKeySequence &key, QWidget *sender, QWidget *receiver, const char *slot)
{
QShortcut *s = new QShortcut(key, sender);
connect(s, SIGNAL(activated()), receiver, slot);
}
#ifdef __APPLE__
bool Rshare::event(QEvent *event)
bool RsApplication::event(QEvent *event)
{
switch (event->type()) {
case QEvent::FileOpen:{
@ -933,7 +918,7 @@ bool Rshare::event(QEvent *event)
}
#endif
void Rshare::blinkTimer()
void RsApplication::blinkTimer()
{
mBlink = !mBlink;
emit blink(mBlink);
@ -944,7 +929,7 @@ void Rshare::blinkTimer()
}
}
bool Rshare::loadCertificate(const RsPeerId &accountId, bool autoLogin)
bool RsApplication::loadCertificate(const RsPeerId &accountId, bool autoLogin)
{
if (!RsAccounts::SelectAccount(accountId))
{
@ -985,14 +970,14 @@ bool Rshare::loadCertificate(const RsPeerId &accountId, bool autoLogin)
// QObject::tr("Login Failure"),
// QObject::tr("Maybe password is wrong") );
return false;
default: std::cerr << "Rshare::loadCertificate() unexpected switch value " << retVal << std::endl;
default: std::cerr << "RsApplication::loadCertificate() unexpected switch value " << retVal << std::endl;
return false;
}
return true;
}
bool Rshare::updateLocalServer()
bool RsApplication::updateLocalServer()
{
if (localServer) {
QString serverName = QString(TARGET);