summaryrefslogtreecommitdiff
path: root/src/clhelp.cpp
blob: 7f79f6280a95f800b753d33376b3e1b6e3fa9480 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*  smplayer, GUI front-end for mplayer.
    Copyright (C) 2006-2009 Ricardo Villalba <rvm@escomposlinux.org>

    This program 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 2 of the License, or
    (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "clhelp.h"
#include <QObject>
#include <QApplication>
#include <QFileInfo>

QString CLHelp::formatText(QString s, int col) {
	QString res = "";

	int last = 0;
	int pos;

	pos = s.indexOf(" ");
	while (pos != -1) {

		if (s.count() < col) {
			res = res + s;
			s = "";
			break;
		}

		while ((pos < col) && (pos != -1)) {
			last = pos;
			pos = s.indexOf(" ", pos+1);
		}

		res = res + s.left(last) + "\n";
		s = s.mid(last+1);

		last = 0;
		pos = s.indexOf(" ");

	}

	if (!s.isEmpty()) res = res + s;

	return res;
}

QString CLHelp::formatHelp(QString parameter, QString help, bool html) {
	if (html) {
		return "<tr><td><b>"+parameter+"</b></td><td>"+help+"</td></tr>";
	} else {
		int par_width = 20;
		int help_width = 80 - par_width;

		QString s;
		s = s.fill( ' ', par_width - (parameter.count()+2) );
		s = s + parameter + ": ";

		QString f;
		f = f.fill(' ', par_width);

		QString s2 = formatText(help, help_width);
		int pos = s2.indexOf('\n');
		while (pos != -1) {
			s2 = s2.insert(pos+1, f);
			pos = s2.indexOf('\n', pos+1);
		}

		return s + s2 + "\n";
	}
}


QString CLHelp::help(bool html) {
	QString app_name = QFileInfo(qApp->applicationFilePath()).baseName();

	QString options = QString("%1 [-minigui] [-defaultgui] [-mpcgui] [-config-path %2] "
                        "[-send-action %3] [-actions %4] "
                        "[-close-at-end] [-no-close-at-end] [-fullscreen] [-no-fullscreen] "
                        "[-sub %5] [-pos x y] [-size %6 %7] "
                        "[-add-to-playlist] [-help|--help|-h|-?] "
                        "[[-playlist] %8] [[-playlist] %8]...")
                        .arg(app_name)
                        .arg(QObject::tr("directory"))
                        .arg(QObject::tr("action_name"))
                        .arg(QObject::tr("action_list"))
                        .arg(QObject::tr("subtitle_file"))
                        .arg(QObject::tr("width")).arg(QObject::tr("height"))
                        .arg(QObject::tr("media"));

	QString s;

	if (html) {
		s = QObject::tr("Usage:") + " <b>" + options + "</b><br>";
		s += "<table>";
	} else {
		s = formatText(QObject::tr("Usage:") + " " + options, 80);
		s += "\n\n";
	}

#ifdef Q_OS_WIN	
	s += formatHelp( "-uninstall", QObject::tr(
		"Restores the old associations and cleans up the registry."), html );
#endif
	s += formatHelp( "-minigui", QObject::tr(
		"opens the mini gui instead of the default one."), html );

	s += formatHelp( "-mpcgui", QObject::tr(
		"opens the mpc gui."), html );

	s += formatHelp( "-defaultgui", QObject::tr(
		"opens the default gui."), html );

	s += formatHelp( "-config-path", QObject::tr(
		"specifies the directory where smplayer will store its configuration "
        "files (smplayer.ini, smplayer_files.ini...)"), html );

	s += formatHelp( "-send-action", QObject::tr(
		"tries to make a connection to another running instance "
        "and send to it the specified action. Example: -send-action pause "
        "The rest of options (if any) will be ignored and the "
        "application will exit. It will return 0 on success or -1 "
        "on failure."), html );

	s += formatHelp( "-actions", QObject::tr(
		"action_list is a list of actions separated by spaces. "
		"The actions will be executed just after loading the file (if any) "
		"in the same order you entered. For checkable actions you can pass "
		"true or false as parameter. Example: "
		"-actions \"fullscreen compact true\". Quotes are necessary in "
		"case you pass more than one action."), html );

	s += formatHelp( "-close-at-end", QObject::tr(
		"the main window will be closed when the file/playlist finishes."), html );

	s += formatHelp( "-no-close-at-end", QObject::tr(
		"the main window won't be closed when the file/playlist finishes."), html );

	s += formatHelp( "-fullscreen", QObject::tr(
		"the video will be played in fullscreen mode."), html );

	s += formatHelp( "-no-fullscreen", QObject::tr(
		"the video will be played in window mode."), html );

	s += formatHelp( "-sub", QObject::tr(
		"specifies the subtitle file to be loaded for the first video."), html );

	s += formatHelp( "-pos", QObject::tr(
		"specifies the coordinates where the main window will be displayed."), html );

	s += formatHelp( "-size", QObject::tr(
		"specifies the size of the main window."), html );

	s += formatHelp( "-help", QObject::tr(
		"will show this message and then will exit."), html );

	s += formatHelp( "-add-to-playlist", QObject::tr(
		"if there's another instance running, the media will be added "
        "to that instance's playlist. If there's no other instance, "
        "this option will be ignored and the "
        "files will be opened in a new instance."), html );

	s += formatHelp( QObject::tr("media"), QObject::tr(
		"'media' is any kind of file that SMPlayer can open. It can "
        "be a local file, a DVD (e.g. dvd://1), an Internet stream "
        "(e.g. mms://....) or a local playlist in format m3u or pls. "
        "If the -playlist option is used, that means that SMPlayer "
        "will pass the -playlist option to MPlayer, so MPlayer will "
        "handle the playlist, not SMPlayer."), html );

	if (html) s += "</table>";

	return s;
}