removed dead code

This commit is contained in:
csoler 2024-03-04 23:22:03 +01:00
parent 398db7dfe8
commit 2a5698c9d3
2 changed files with 0 additions and 351 deletions

View File

@ -57,49 +57,6 @@
#include "rshare.h"
#ifdef TO_REMOVE
/* Available command-line arguments. */
#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. */
#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_S "o" /**< OpMode (Full, NoTurtle, Gaming, Minimal) */
#define ARG_OPMODE_L "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. */
#define ARG_RSFILE_L "rsfile" /**< Open RsFile with or without arg. */
//Other defined for server in /libretroshare/src/rsserver/rsinit.cc:351
// 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.
// For example, the user wants to start a second instance using --base-dir arg of libretroshare.
static const char* const forwardableArgs[] = {
ARG_OPMODE_S,
ARG_OPMODE_L,
ARG_RSLINK_S,
ARG_RSLINK_L,
ARG_RSFILE_S,
ARG_RSFILE_L,
NULL,
};
/* Static member variables */
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
#ifdef __APPLE__
QStringList RsApplication::_links; /**< List of links passed by arguments. */
QStringList RsApplication::_files; /**< List of files passed by arguments. */
@ -157,95 +114,6 @@ RsApplication::RsApplication(const RsGUIConfigOptions& conf)
localServer = NULL;
options = conf;
#ifdef TO_REMOVE
//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)
{
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();
QSharedMemory newArgs;
newArgs.setKey(serverName + "_newArgs");
if (newArgs.isAttached()) newArgs.detach();
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.
#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();
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();
}
}
#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()));
@ -281,11 +149,6 @@ RsApplication::RsApplication(const RsGUIConfigOptions& conf)
connect(timer, SIGNAL(timeout()), this, SIGNAL(minuteTick()));
timer->start();
#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 (options.optResetParams)
{
@ -304,13 +167,6 @@ RsApplication::RsApplication(const RsGUIConfigOptions& conf)
log_output.setLogLevel(Log::stringToLogLevel(options.logLevel));
}
#ifdef TO_REMOVE
/* config directory */
useConfigDir = false;
if (!conf.optBaseDir.empty())
setConfigDirectory(QString::fromStdString(conf.optBaseDir));
#endif
/** Initialize support for language translations. */
//LanguageSupport::initialize();
@ -409,198 +265,6 @@ RsApplication::onEventLoopStarted()
emit running();
}
#ifdef TO_REMOVE
/** Display usage information regarding command-line arguments. */
/*void
RsApplication::printUsage(QString errmsg)
{
QTextStream out(stdout);*/
/* If there was an error message, print it out. */
/*if (!errmsg.isEmpty()) {
out << "** " << errmsg << " **" << endl << endl;
}*/
/* Now print the application usage */
//out << "Usage: " << endl;
//out << "\t" << qApp->arguments().at(0) << " [options]" << endl;
/* And available options */
//out << endl << "Available Options:" << 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 RsApplication's language." << endl;
//out << "\t\t\t[" << LanguageSupport::languageCodes().join("|") << "]" << endl;
//}
/** Displays usage information for command-line args. */
void
RsApplication::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.")));
out << trow(tcol("-" ARG_RESET) +
tcol(tr("Resets ALL stored RetroShare settings.")));
out << trow(tcol("-" ARG_DATADIR" &lt;dir&gt;") +
tcol(tr("Sets the directory RetroShare uses for data files.")));
out << trow(tcol("-" ARG_LOGFILE" &lt;" + tr("filename") + "&gt;") +
tcol(tr("Sets the name and location of RetroShare's logfile.")));
out << trow(tcol("-" ARG_LOGLEVEL" &lt;" + tr("level") + "&gt;") +
tcol(tr("Sets the verbosity of RetroShare's logging.") +
"<br>[" + Log::logLevels().join("|") +"]"));
out << trow(tcol("-" ARG_GUISTYLE" &lt;" + tr("style") +"&gt;") +
tcol(tr("Sets RetroShare's interface style.") +
"<br>[" + QStyleFactory::keys().join("|") + "]"));
out << trow(tcol("-" ARG_GUISTYLESHEET" &lt;" + tr("stylesheet") + "&gt;") +
tcol(tr("Sets RetroShare's interface stylesheets.")));
out << trow(tcol("-" ARG_LANGUAGE" &lt;" + tr("language") + "&gt;") +
tcol(tr("Sets RetroShare's language.") +
"<br>[" + LanguageSupport::languageCodes().join("|") + "]"));
out << trow(tcol("--" ARG_OPMODE_L" &lt;" + tr("opmode") + "&gt;") +
tcol(tr("Sets RetroShare's operating mode.") +
"<br>[full|noturtle|gaming|minimal]"));
out << trow(tcol("-" ARG_RSLINK_L" &lt;" + tr("RsLinkURL") + "&gt;") +
tcol(tr("Open RsLink with protocol retroshare://")));
out << trow(tcol("-" ARG_RSFILE_L" &lt;" + tr("filename") + "&gt;") +
tcol(tr("Open RsFile with or without arg.")));
out << "</table>";
VMessageBox::information(0,
tr("RetroShare GUI Usage Information"), usage, VMessageBox::Ok);
}
/** Returns true if the specified argument expects a value. */
bool
RsApplication::argNeedsValue(const QString &argName)
{
return (
argName == ARG_DATADIR ||
argName == ARG_LOGFILE ||
argName == ARG_LOGLEVEL ||
argName == ARG_GUISTYLE ||
argName == ARG_GUISTYLESHEET ||
argName == ARG_LANGUAGE ||
argName == ARG_OPMODE_S ||
argName == ARG_OPMODE_L ||
argName == ARG_RSLINK_S ||
argName == ARG_RSLINK_L ||
argName == ARG_RSFILE_S ||
argName == ARG_RSFILE_L );
}
/** Parses the list of command-line arguments for their argument names and
* values. */
void
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) {
/* Get the argument name and set a blank value */
arg = args.at(iCurs);//.toLower(); Need Upper case for file name.
argl = arg.toLower();
if (argl == "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 (iCurs < args.size()-1 && argNeedsValue(arg)) {
value = args.at(++iCurs);
}
} else {
/* Check if links or files without arg */
if (argl.startsWith("retroshare://")) {
value = arg;
arg = ARG_RSLINK_L;
} else {
if (QFile(arg).exists()) {
value = arg;
arg = ARG_RSFILE_L;
}
}
}
/* 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_S || arg == ARG_OPMODE_L )
&& 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);
} 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);
}
}
}
/** Verifies that all specified arguments were valid. */
bool
RsApplication::validateArguments(QString &errmsg)
{
/* 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)
, _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 */
if (_args.contains(ARG_GUISTYLE) &&
!QStyleFactory::keys().contains(_args.value(ARG_GUISTYLE),
Qt::CaseInsensitive)) {
errmsg = tr("Invalid GUI style specified:")+" " + _args.value(ARG_GUISTYLE);
return false;
}
/* 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 an opmode that Retroshare recognizes. */
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);
return false;
}
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

View File

@ -81,21 +81,6 @@ public:
/** Return the version info */
static QString retroshareVersion(bool=true);
#ifdef TO_REMOVE
/** Return the map of command-line arguments and values. */
static QMap<QString, QString> arguments() { return _args; }
/** Parse the list of command-line arguments. */
static void parseArguments(QStringList args, bool firstRun = true);
/** Validates that all arguments were well-formed. */
bool validateArguments(QString &errmsg);
/** Prints usage information to the given text stream. */
//void printUsage(QString errmsg = QString());
/** Displays usage information for command-line args. */
static void showUsageMessageBox();
/** Returns true if the user wants to see usage information. */
static bool showUsage();
#endif
/** Sets the current language. */
static bool setLanguage(QString languageCode = QString());
/** Sets the current locale. */