Add the ability to change OpMode in command line.

So you can change OpMode while running via ssh to get more bandwidth.
Usage: RetroShare06 --opmode [full|noturtle|gaming|minimal]
This commit is contained in:
Phenom 2016-05-16 12:10:04 +02:00
parent 1491a051dc
commit 8563957591
4 changed files with 66 additions and 25 deletions

View File

@ -1492,6 +1492,23 @@ void MainWindow::processLastArgs()
/* Now use files from the command line, because no RetroShare was running */
openRsCollection(Rshare::files()->takeFirst());
}
/* Handle the -opmode options. */
if (opModeStatus) {
QString opmode = Rshare::opmode().toLower();
if (opmode == "noturtle") {
opModeStatus->setCurrentIndex(RS_OPMODE_NOTURTLE - 1);
} else if (opmode == "gaming") {
opModeStatus->setCurrentIndex(RS_OPMODE_GAMING - 1);
} else if (opmode == "minimal") {
opModeStatus->setCurrentIndex(RS_OPMODE_MINIMAL - 1);
} else {
opModeStatus->setCurrentIndex(RS_OPMODE_FULL - 1);
}
opModeStatus->setOpMode();
} else {
std::cerr << "ERR: MainWindow::processLastArgs opModeStatus is not initialized.";
}
}
void MainWindow::switchVisibilityStatus(StatusElement e,bool b)

View File

@ -46,7 +46,7 @@ public:
QColor getOpMode_Minimal_Color() const;
void setOpMode_Minimal_Color( QColor c );
private slots:
public slots:
void setOpMode();
private:

View File

@ -55,13 +55,14 @@
#include "rshare.h"
/* Available command-line arguments. */
#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_GUISTYLE "style" /**< Argument specfying GUI style. */
#define ARG_GUISTYLESHEET "stylesheet" /**< Argument specfying GUI style. */
#define ARG_LANGUAGE "lang" /**< Argument specifying language. */
#define ARG_OPMODE "opmode" /**< OpMode (Full, NoTurtle, Gaming, Minimal */
#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 */
@ -81,11 +82,12 @@ 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. */
Log Rshare::_log; /**< Logs debugging messages to file or stdout. */
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;
@ -438,6 +440,9 @@ Rshare::showUsageMessageBox()
out << trow(tcol("-" ARG_LANGUAGE" &lt;language&gt;") +
tcol(tr("Sets RetroShare's language.") +
"<br>[" + LanguageSupport::languageCodes().join("|") + "]"));
out << trow(tcol("-" ARG_OPMODE" &lt;opmode&gt;") +
tcol(tr("Sets RetroShare's opertating mode.") +
"<br>[full|noturtle|gaming|minimal]"));
out << "</table>";
VMessageBox::information(0,
@ -448,12 +453,14 @@ Rshare::showUsageMessageBox()
bool
Rshare::argNeedsValue(QString argName)
{
return (argName == ARG_GUISTYLE ||
argName == ARG_GUISTYLESHEET ||
argName == ARG_LANGUAGE ||
return (
argName == ARG_DATADIR ||
argName == ARG_LOGFILE ||
argName == ARG_LOGLEVEL ||
argName == ARG_LOGLEVEL ||
argName == ARG_GUISTYLE ||
argName == ARG_GUISTYLESHEET ||
argName == ARG_LANGUAGE ||
argName == ARG_OPMODE ||
argName == ARG_RSLINK_S ||
argName == ARG_RSLINK_L ||
argName == ARG_RSFILE_S ||
@ -494,6 +501,14 @@ Rshare::parseArguments(QStringList args, bool firstRun)
}
}
/* handle opmode that could be change while running.*/
QString omValue = QString(value).prepend(";").append(";").toLower();
QString omValues = QString(";full;noturtle;gaming;minimal;");
if ((arg == ARG_OPMODE ) &&
omValues.contains(omValue)) {
_opmode = value;
}
/* Don't send theses argument to _args map to allow multiple. */
if (arg == ARG_RSLINK_S || arg == ARG_RSLINK_L) {
_links.append(value);
@ -510,10 +525,17 @@ Rshare::parseArguments(QStringList args, bool firstRun)
bool
Rshare::validateArguments(QString &errmsg)
{
/* 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);
/* 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);
return false;
}
/* Check for a valid GUI style */
@ -523,17 +545,16 @@ Rshare::validateArguments(QString &errmsg)
errmsg = tr("Invalid GUI style specified:")+" " + _args.value(ARG_GUISTYLE);
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);
/* 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);
return false;
}
/* 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());
/* Check for an opmode that Retroshare recognizes. */
if (_args.contains(ARG_OPMODE) &&
!QString(";full;noturtle;gaming;minimal;").contains(QString(_args.value(ARG_OPMODE)).prepend(";").append(";").toLower())) {
errmsg = tr("Invalid language code specified:")+" " + _args.value(ARG_OPMODE);
return false;
}
return true;

View File

@ -107,12 +107,14 @@ public:
/** Initialize plugins. */
static void initPlugins();
/** Returns the current language. */
static QString language() { return _language; }
/** Returns the current GUI style. */
static QString style() { return _style; }
/** Returns the current GUI stylesheet. */
static QString stylesheet() { return _stylesheet; }
/** Returns the current language. */
static QString language() { return _language; }
/** Returns the operating mode. */
static QString opmode() { return _opmode; }
/** Returns links passed by arguments. */
static QStringList* links() { return &_links; }
/** Returns files passed by arguments. */
@ -181,11 +183,12 @@ private:
static bool argNeedsValue(QString argName);
static QMap<QString, QString> _args; /**< List of command-line arguments. */
static Log _log; /**< Logs debugging messages to file or stdout. */
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 QString _opmode; /**< The operating mode passed by args. */
static QStringList _links; /**< List of links passed by arguments. */
static QStringList _files; /**< List of files passed by arguments. */
static QDateTime mStartupTime; // startup time