1 #ifndef PSICLI_H
2 #define PSICLI_H
3 
4 #include "simplecli/simplecli.h"
5 #include "applicationinfo.h"
6 #include <QApplication>
7 #include <QMessageBox>
8 #include <QFileInfo>
9 
10 class PsiCli : public SimpleCli
11 {
12 	Q_OBJECT
13 public:
PsiCli()14 	PsiCli() {
15 		defineParam("profile", tr("PROFILE", "translate in UPPER_CASE with no spaces"),
16 			    tr("Activate program instance running specified profile. "
17 			       "Otherwise, open new instance using this profile "
18 			       "(unless used together with --remote).",
19 					"do not translate --remote"));
20 
21 		defineSwitch("remote",
22 			     tr("Force remote-control mode. "
23 				"If there is no running instance, "
24 				"or --profile was specified but there is no instance using it, "
25 				"exit without doing anything. "
26 				"Cannot be used with --choose-profile.",
27 					"do not translate --profile, --choose-profile"));
28 
29 		defineSwitch("choose-profile",
30 			     tr("Display Choose Profile dialog on startup. "
31 				"Cannot be used together with --remote.",
32 					"do not translate --remote"));
33 
34 		defineParam("uri", tr("URI", "translate in UPPER_CASE with no spaces"),
35 			    tr("Open XMPP URI. (e.g. xmpp:someone@example.org?chat) "
36 			       "For security reasons, this must be the last option."));
37 
38 		defineParam("status", tr("STATUS", "translate in UPPER_CASE with no spaces"),
39 			    tr("Set status. STATUS must be one of `online', `chat', `away', `xa', `dnd', `offline'.",
40 					"do not translate `online', `chat', etc; STATUS is the same as in previous string"));
41 
42 		defineParam("status-message", tr("MSG", "translate in UPPER_CASE with no spaces"),
43 			    tr("Set status message. Must be used together with --status.",
44 					"do not translate --status"));
45 
46 		defineSwitch("help", tr("Show this help message and exit."));
47 		defineAlias("h", "help");
48 		defineAlias("?", "help");
49 
50 		defineSwitch("version", tr("Show version information and exit."));
51 		defineAlias("v", "version");
52 	}
53 
54 	void showHelp(int textWidth = 78) {
55 		QString u1 = tr("Usage:") + " " + QFileInfo(QApplication::applicationFilePath()).fileName();
56 		QString u2 = "%1 [--profile=%2] [--remote|--choose-profile] [--status=%3\t[--status-message=%4]] [--uri=%5]";
57 		QString output = wrap(u2.arg(u1, tr("PROFILE"), tr("STATUS"), tr("MSG"), tr("URI")),
58 				      textWidth, u1.length() + 1, 0).replace('\t', ' '); // non-breakable space ;)
59 
60 		output += '\n';
61 		output += tr("Psi - The Cross-Platform XMPP Client For Power Users");
62 		output += "\n\n";
63 		output += tr("Options:");
64 		output += '\n';
65 		output += optionsHelp(textWidth);
66 		output += '\n';
67         output += tr("Go to <https://psi-im.org/> for more information about Psi.");
68 		show(output);
69 	}
70 
showVersion()71 	void showVersion() {
72 		show(QString("%1 %2\nQt %3\n")
73 			.arg(ApplicationInfo::name()).arg(ApplicationInfo::version())
74 			.arg(qVersion())
75 			+QString(tr("Compiled with Qt %1", "%1 will contain Qt version number"))
76 			.arg(QT_VERSION_STR));
77 	}
78 
show(const QString & text)79 	void show(const QString& text) {
80 #ifdef Q_OS_WIN
81 		QMessageBox::information(0, ApplicationInfo::name(), text);
82 #else
83 		puts(qPrintable(text));
84 #endif
85 	}
86 
~PsiCli()87 	virtual ~PsiCli() {}
88 };
89 
90 #endif
91