2019-09-14 13:03:34 -04:00
|
|
|
#include "info.h"
|
|
|
|
|
|
|
|
// This file is part of Cmdr.
|
|
|
|
|
|
|
|
// Cmdr is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Cmdr 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 General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Cmdr under the LICENSE.md file. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
About::About(QObject *parent) : Command(parent)
|
|
|
|
{
|
|
|
|
setObjectName("about");
|
|
|
|
|
|
|
|
Shared::clientCmds->insert(objectName(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void About::onStartup() {dataIn(QString());}
|
2020-03-30 12:23:21 -04:00
|
|
|
QString About::shortText() {return tr("display information about the client or a command.");}
|
2019-09-14 13:03:34 -04:00
|
|
|
QString About::ioText() {return tr("[{cmd_name}]/[text]");}
|
|
|
|
QString About::longText() {return TXT_About;}
|
|
|
|
|
2020-03-30 12:23:21 -04:00
|
|
|
ListCmds::ListCmds(QObject *parent) : Command(parent)
|
|
|
|
{
|
|
|
|
setObjectName("ls_cmds");
|
|
|
|
|
|
|
|
Shared::clientCmds->insert(objectName(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ListCmds::shortText() {return tr("display all available commands.");}
|
|
|
|
QString ListCmds::ioText() {return tr("[none]/[text]");}
|
|
|
|
QString ListCmds::longText() {return TXT_ListCmds;}
|
|
|
|
|
2019-11-23 14:37:41 -05:00
|
|
|
void About::dispInfo(Command *cmdObj)
|
|
|
|
{
|
|
|
|
QString txt;
|
|
|
|
QTextStream txtOut(&txt);
|
|
|
|
|
|
|
|
wordWrap("i/o: ", txtOut, cmdObj->ioText(), Shared::mainWidget);
|
|
|
|
txtOut << "" << endl;
|
|
|
|
wordWrap("library: ", txtOut, cmdObj->libText(), Shared::mainWidget);
|
|
|
|
txtOut << "" << endl;
|
|
|
|
wordWrap("usage: ", txtOut, cmdObj->longText(), Shared::mainWidget);
|
|
|
|
|
2019-12-04 22:01:52 -05:00
|
|
|
cacheTxt(TEXT, txt);
|
2019-11-23 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool About::dispClientCmd(const QString &cmdName)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (Shared::clientCmds->contains(cmdName))
|
|
|
|
{
|
|
|
|
dispInfo(Shared::clientCmds->value(cmdName));
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool About::dispHostCmd(const QString &cmdName)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (Shared::hostDocs->contains(cmdName))
|
|
|
|
{
|
|
|
|
dispInfo(Shared::hostDocs->value(cmdName));
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool About::dispInfo(const QString &cmdName)
|
|
|
|
{
|
|
|
|
if (dispClientCmd(cmdName))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (dispHostCmd(cmdName))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-14 13:03:34 -04:00
|
|
|
void About::dataIn(const QString &argsLine)
|
|
|
|
{
|
2020-03-30 12:23:21 -04:00
|
|
|
auto args = parseArgs(argsLine);
|
2019-09-14 13:03:34 -04:00
|
|
|
|
|
|
|
if (args.size() > 0)
|
|
|
|
{
|
2020-03-30 12:23:21 -04:00
|
|
|
auto cmdName = args[0].toLower().trimmed();
|
2019-09-14 13:03:34 -04:00
|
|
|
|
2019-11-23 14:37:41 -05:00
|
|
|
if (!dispInfo(cmdName))
|
2019-09-14 13:03:34 -04:00
|
|
|
{
|
2019-12-04 22:01:52 -05:00
|
|
|
cacheTxt(ERR, "err: No such command: '" + cmdName + "'\n");
|
2019-09-14 13:03:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString txt;
|
|
|
|
QTextStream txtOut(&txt);
|
|
|
|
|
2019-11-23 14:37:41 -05:00
|
|
|
txtOut << libText() << endl << endl;
|
|
|
|
txtOut << "Based on QT " << QT_VERSION_STR << " " << 8 * QT_POINTER_SIZE << "bit" << endl << endl;
|
|
|
|
txtOut << "The program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE" << endl;
|
|
|
|
txtOut << "WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE." << endl << endl;
|
2020-03-30 12:23:21 -04:00
|
|
|
txtOut << "run: 'ls_cmds' to see all available commands." << endl << endl;
|
|
|
|
txtOut << "for more detailed information about a command run: 'about <command>'" << endl << endl;
|
|
|
|
|
|
|
|
cacheTxt(TEXT, txt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void About::run()
|
|
|
|
{
|
|
|
|
dataIn(QString());
|
|
|
|
}
|
2019-11-23 14:37:41 -05:00
|
|
|
|
2020-03-30 12:23:21 -04:00
|
|
|
void ListCmds::ls(QHash<QString, Command *> *cmdObjs, QTextStream &txtOut, const QString &title)
|
|
|
|
{
|
|
|
|
if (!cmdObjs->isEmpty())
|
|
|
|
{
|
|
|
|
auto cmdNames = cmdObjs->keys();
|
|
|
|
auto largestCmd = 0;
|
2019-09-14 13:03:34 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < cmdNames.size(); ++i)
|
|
|
|
{
|
|
|
|
if (cmdNames[i].size() > largestCmd) largestCmd = cmdNames[i].size();
|
|
|
|
}
|
|
|
|
|
2020-03-30 12:23:21 -04:00
|
|
|
cmdNames.sort(Qt::CaseInsensitive);
|
2019-09-14 13:03:34 -04:00
|
|
|
|
2020-03-30 12:23:21 -04:00
|
|
|
txtOut << endl;
|
|
|
|
txtOut << title << endl << endl;
|
2019-09-14 13:03:34 -04:00
|
|
|
|
2020-03-30 12:23:21 -04:00
|
|
|
for (int i = 0; i < cmdNames.size(); ++i)
|
|
|
|
{
|
|
|
|
wordWrap(cmdNames[i].leftJustified(largestCmd, ' ') + " - ", txtOut, cmdObjs->value(cmdNames[i])->shortText(), Shared::mainWidget);
|
|
|
|
}
|
2019-09-14 13:03:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 12:23:21 -04:00
|
|
|
void ListCmds::dataIn(const QString &argsLine)
|
2019-09-14 13:03:34 -04:00
|
|
|
{
|
2020-03-30 12:23:21 -04:00
|
|
|
Q_UNUSED(argsLine)
|
|
|
|
|
|
|
|
QString txt;
|
|
|
|
QTextStream txtOut(&txt);
|
|
|
|
|
|
|
|
ls(Shared::clientCmds, txtOut, "Client Commands:");
|
|
|
|
ls(Shared::hostDocs, txtOut, "Host Commands:");
|
|
|
|
|
|
|
|
cacheTxt(TEXT, txt);
|
2019-09-14 13:03:34 -04:00
|
|
|
}
|