1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "smplayer.h"
|
---|
20 | #include "global.h"
|
---|
21 | #include "paths.h"
|
---|
22 | #include "translator.h"
|
---|
23 | #include "version.h"
|
---|
24 | #include "config.h"
|
---|
25 | #include "clhelp.h"
|
---|
26 | #include "cleanconfig.h"
|
---|
27 | #include "myapplication.h"
|
---|
28 | #include "baseguiplus.h"
|
---|
29 |
|
---|
30 | #ifdef DEFAULTGUI
|
---|
31 | #include "defaultgui.h"
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #ifdef MINIGUI
|
---|
35 | #include "minigui.h"
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | #ifdef MPCGUI
|
---|
39 | #include "mpcgui.h"
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #ifdef SKINS
|
---|
43 | #include "skingui.h"
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | #include <QDir>
|
---|
47 | #include <QUrl>
|
---|
48 | #include <QTime>
|
---|
49 | #include <stdio.h>
|
---|
50 |
|
---|
51 | #ifdef Q_OS_WIN
|
---|
52 | #if USE_ASSOCIATIONS
|
---|
53 | #include "extensions.h"
|
---|
54 | #include "winfileassoc.h" //required for Uninstall
|
---|
55 | #endif
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #ifdef FONTCACHE_DIALOG
|
---|
59 | #include "fontcache.h"
|
---|
60 | #include "version.h"
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | using namespace Global;
|
---|
64 |
|
---|
65 | BaseGui * SMPlayer::main_window = 0;
|
---|
66 |
|
---|
67 | SMPlayer::SMPlayer(const QString & config_path, QObject * parent )
|
---|
68 | : QObject(parent)
|
---|
69 | {
|
---|
70 | #ifdef LOG_SMPLAYER
|
---|
71 | #if QT_VERSION >= 0x050000
|
---|
72 | qInstallMessageHandler( SMPlayer::myMessageOutput );
|
---|
73 | #else
|
---|
74 | qInstallMsgHandler( SMPlayer::myMessageOutput );
|
---|
75 | #endif
|
---|
76 | allow_to_send_log_to_gui = true;
|
---|
77 | #endif
|
---|
78 |
|
---|
79 | gui_to_use = "DefaultGUI";
|
---|
80 |
|
---|
81 | close_at_end = -1; // Not set
|
---|
82 | start_in_fullscreen = -1; // Not set
|
---|
83 |
|
---|
84 | move_gui = false;
|
---|
85 | resize_gui = false;
|
---|
86 |
|
---|
87 | Paths::setAppPath( qApp->applicationDirPath() );
|
---|
88 |
|
---|
89 | #ifndef PORTABLE_APP
|
---|
90 | if (config_path.isEmpty()) createConfigDirectory();
|
---|
91 | #endif
|
---|
92 | global_init(config_path);
|
---|
93 |
|
---|
94 | // Application translations
|
---|
95 | translator->load( pref->language );
|
---|
96 | showInfo();
|
---|
97 |
|
---|
98 | #ifdef FONTS_HACK
|
---|
99 | createFontFile();
|
---|
100 | #endif
|
---|
101 | }
|
---|
102 |
|
---|
103 | SMPlayer::~SMPlayer() {
|
---|
104 | if (main_window != 0) {
|
---|
105 | deleteGUI();
|
---|
106 | }
|
---|
107 | global_end();
|
---|
108 |
|
---|
109 | #ifdef LOG_SMPLAYER
|
---|
110 | if (output_log.isOpen()) output_log.close();
|
---|
111 | #endif
|
---|
112 | }
|
---|
113 |
|
---|
114 | BaseGui * SMPlayer::gui() {
|
---|
115 | if (main_window == 0) {
|
---|
116 | // Changes to app path, so smplayer can find a relative mplayer path
|
---|
117 | QDir::setCurrent(Paths::appPath());
|
---|
118 | qDebug("SMPlayer::gui: changed working directory to app path");
|
---|
119 | qDebug("SMPlayer::gui: current directory: %s", QDir::currentPath().toUtf8().data());
|
---|
120 |
|
---|
121 | #ifdef SKINS
|
---|
122 | if (gui_to_use == "SkinGUI") {
|
---|
123 | QString theme = pref->iconset;
|
---|
124 | if (theme.isEmpty()) theme = "Gonzo";
|
---|
125 | QString user_theme_dir = Paths::configPath() + "/themes/" + theme;
|
---|
126 | QString theme_dir = Paths::themesPath() + "/" + theme;
|
---|
127 | qDebug("SMPlayer::gui: user_theme_dir: %s", user_theme_dir.toUtf8().constData());
|
---|
128 | qDebug("SMPlayer::gui: theme_dir: %s", theme_dir.toUtf8().constData());
|
---|
129 | if ((QDir(theme_dir).exists()) || (QDir(user_theme_dir).exists())) {
|
---|
130 | if (pref->iconset.isEmpty()) pref->iconset = theme;
|
---|
131 | } else {
|
---|
132 | qDebug("SMPlayer::gui: skin folder doesn't exist. Falling back to default gui.");
|
---|
133 | gui_to_use = "DefaultGUI";
|
---|
134 | pref->iconset = "";
|
---|
135 | pref->gui = gui_to_use;
|
---|
136 | }
|
---|
137 | }
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | main_window = createGUI(gui_to_use);
|
---|
141 |
|
---|
142 | if (move_gui) {
|
---|
143 | qDebug("SMPlayer::gui: moving main window to %d %d", gui_position.x(), gui_position.y());
|
---|
144 | main_window->move(gui_position);
|
---|
145 | }
|
---|
146 | if (resize_gui) {
|
---|
147 | qDebug("SMPlayer::gui: resizing main window to %dx%d", gui_size.width(), gui_size.height());
|
---|
148 | main_window->resize(gui_size);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | return main_window;
|
---|
153 | }
|
---|
154 |
|
---|
155 | BaseGui * SMPlayer::createGUI(QString gui_name) {
|
---|
156 | BaseGui * gui = 0;
|
---|
157 |
|
---|
158 | #ifdef SKINS
|
---|
159 | if (gui_name.toLower() == "skingui")
|
---|
160 | gui = new SkinGui(0);
|
---|
161 | else
|
---|
162 | #endif
|
---|
163 | #ifdef MINIGUI
|
---|
164 | if (gui_name.toLower() == "minigui")
|
---|
165 | gui = new MiniGui(0);
|
---|
166 | else
|
---|
167 | #endif
|
---|
168 | #ifdef MPCGUI
|
---|
169 | if (gui_name.toLower() == "mpcgui")
|
---|
170 | gui = new MpcGui(0);
|
---|
171 | else
|
---|
172 | #endif
|
---|
173 | #ifdef DEFAULTGUI
|
---|
174 | if (gui_name.toLower() == "defaultgui")
|
---|
175 | gui = new DefaultGui(0);
|
---|
176 | else
|
---|
177 | #endif
|
---|
178 | {
|
---|
179 | // No GUI
|
---|
180 | qWarning() << "SMPlayer::createGUI: there's no GUI available!";
|
---|
181 | gui = new BaseGuiPlus(0);
|
---|
182 | }
|
---|
183 |
|
---|
184 | gui->setForceCloseOnFinish(close_at_end);
|
---|
185 | gui->setForceStartInFullscreen(start_in_fullscreen);
|
---|
186 | connect(gui, SIGNAL(quitSolicited()), qApp, SLOT(quit()));
|
---|
187 |
|
---|
188 | #ifdef GUI_CHANGE_ON_RUNTIME
|
---|
189 | connect(gui, SIGNAL(guiChanged(QString)), this, SLOT(changeGUI(QString)));
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | #if SINGLE_INSTANCE
|
---|
193 | MyApplication * app = MyApplication::instance();
|
---|
194 | connect(app, SIGNAL(messageReceived(const QString&)),
|
---|
195 | gui, SLOT(handleMessageFromOtherInstances(const QString&)));
|
---|
196 | app->setActivationWindow(gui);
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | return gui;
|
---|
200 | }
|
---|
201 |
|
---|
202 | void SMPlayer::deleteGUI() {
|
---|
203 | #ifdef LOG_SMPLAYER
|
---|
204 | allow_to_send_log_to_gui = false;
|
---|
205 | #endif
|
---|
206 |
|
---|
207 | delete main_window;
|
---|
208 | main_window = 0;
|
---|
209 |
|
---|
210 | #ifdef LOG_SMPLAYER
|
---|
211 | allow_to_send_log_to_gui = true;
|
---|
212 | #endif
|
---|
213 | }
|
---|
214 |
|
---|
215 | #ifdef GUI_CHANGE_ON_RUNTIME
|
---|
216 | void SMPlayer::changeGUI(QString new_gui) {
|
---|
217 | qDebug("SMPlayer::changeGUI: '%s'", new_gui.toLatin1().constData());
|
---|
218 |
|
---|
219 | deleteGUI();
|
---|
220 |
|
---|
221 | main_window = createGUI(new_gui);
|
---|
222 |
|
---|
223 | main_window->show();
|
---|
224 | }
|
---|
225 | #endif
|
---|
226 |
|
---|
227 | SMPlayer::ExitCode SMPlayer::processArgs(QStringList args) {
|
---|
228 | qDebug("SMPlayer::processArgs: arguments: %d", args.count());
|
---|
229 | for (int n = 0; n < args.count(); n++) {
|
---|
230 | qDebug("SMPlayer::processArgs: %d = %s", n, args[n].toUtf8().data());
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | QString action; // Action to be passed to running instance
|
---|
235 | bool show_help = false;
|
---|
236 |
|
---|
237 | if (!pref->gui.isEmpty()) gui_to_use = pref->gui;
|
---|
238 | bool add_to_playlist = false;
|
---|
239 |
|
---|
240 | #ifdef Q_OS_WIN
|
---|
241 | if (args.contains("-uninstall")) {
|
---|
242 | #if USE_ASSOCIATIONS
|
---|
243 | //Called by uninstaller. Will restore old associations.
|
---|
244 | WinFileAssoc RegAssoc;
|
---|
245 | Extensions exts;
|
---|
246 | QStringList regExts;
|
---|
247 | RegAssoc.GetRegisteredExtensions(exts.multimedia(), regExts);
|
---|
248 | RegAssoc.RestoreFileAssociations(regExts);
|
---|
249 | printf("Restored associations\n");
|
---|
250 | #endif
|
---|
251 | return NoError;
|
---|
252 | }
|
---|
253 | #endif
|
---|
254 |
|
---|
255 | if (args.contains("-delete-config")) {
|
---|
256 | CleanConfig::clean(Paths::configPath());
|
---|
257 | return NoError;
|
---|
258 | }
|
---|
259 |
|
---|
260 | for (int n = 1; n < args.count(); n++) {
|
---|
261 | QString argument = args[n];
|
---|
262 |
|
---|
263 | if (argument == "-send-action") {
|
---|
264 | if (n+1 < args.count()) {
|
---|
265 | n++;
|
---|
266 | action = args[n];
|
---|
267 | } else {
|
---|
268 | printf("Error: expected parameter for -send-action\r\n");
|
---|
269 | return ErrorArgument;
|
---|
270 | }
|
---|
271 | }
|
---|
272 | else
|
---|
273 | if (argument == "-actions") {
|
---|
274 | if (n+1 < args.count()) {
|
---|
275 | n++;
|
---|
276 | actions_list = args[n];
|
---|
277 | } else {
|
---|
278 | printf("Error: expected parameter for -actions\r\n");
|
---|
279 | return ErrorArgument;
|
---|
280 | }
|
---|
281 | }
|
---|
282 | else
|
---|
283 | if (argument == "-sub") {
|
---|
284 | if (n+1 < args.count()) {
|
---|
285 | n++;
|
---|
286 | QString file = args[n];
|
---|
287 | if (QFile::exists(file)) {
|
---|
288 | subtitle_file = QFileInfo(file).absoluteFilePath();
|
---|
289 | } else {
|
---|
290 | printf("Error: file '%s' doesn't exists\r\n", file.toUtf8().constData());
|
---|
291 | }
|
---|
292 | } else {
|
---|
293 | printf("Error: expected parameter for -sub\r\n");
|
---|
294 | return ErrorArgument;
|
---|
295 | }
|
---|
296 | }
|
---|
297 | else
|
---|
298 | if (argument == "-media-title") {
|
---|
299 | if (n+1 < args.count()) {
|
---|
300 | n++;
|
---|
301 | if (media_title.isEmpty()) media_title = args[n];
|
---|
302 | }
|
---|
303 | }
|
---|
304 | else
|
---|
305 | if (argument == "-pos") {
|
---|
306 | if (n+2 < args.count()) {
|
---|
307 | bool ok_x, ok_y;
|
---|
308 | n++;
|
---|
309 | gui_position.setX( args[n].toInt(&ok_x) );
|
---|
310 | n++;
|
---|
311 | gui_position.setY( args[n].toInt(&ok_y) );
|
---|
312 | if (ok_x && ok_y) move_gui = true;
|
---|
313 | } else {
|
---|
314 | printf("Error: expected parameter for -pos\r\n");
|
---|
315 | return ErrorArgument;
|
---|
316 | }
|
---|
317 | }
|
---|
318 | else
|
---|
319 | if (argument == "-size") {
|
---|
320 | if (n+2 < args.count()) {
|
---|
321 | bool ok_width, ok_height;
|
---|
322 | n++;
|
---|
323 | gui_size.setWidth( args[n].toInt(&ok_width) );
|
---|
324 | n++;
|
---|
325 | gui_size.setHeight( args[n].toInt(&ok_height) );
|
---|
326 | if (ok_width && ok_height) resize_gui = true;
|
---|
327 | } else {
|
---|
328 | printf("Error: expected parameter for -resize\r\n");
|
---|
329 | return ErrorArgument;
|
---|
330 | }
|
---|
331 | }
|
---|
332 | else
|
---|
333 | if ((argument == "--help") || (argument == "-help") ||
|
---|
334 | (argument == "-h") || (argument == "-?") )
|
---|
335 | {
|
---|
336 | show_help = true;
|
---|
337 | }
|
---|
338 | else
|
---|
339 | if (argument == "-close-at-end") {
|
---|
340 | close_at_end = 1;
|
---|
341 | }
|
---|
342 | else
|
---|
343 | if (argument == "-no-close-at-end") {
|
---|
344 | close_at_end = 0;
|
---|
345 | }
|
---|
346 | else
|
---|
347 | if (argument == "-fullscreen") {
|
---|
348 | start_in_fullscreen = 1;
|
---|
349 | }
|
---|
350 | else
|
---|
351 | if (argument == "-no-fullscreen") {
|
---|
352 | start_in_fullscreen = 0;
|
---|
353 | }
|
---|
354 | else
|
---|
355 | if (argument == "-add-to-playlist") {
|
---|
356 | add_to_playlist = true;
|
---|
357 | }
|
---|
358 | else
|
---|
359 | if (argument == "-mini" || argument == "-minigui") {
|
---|
360 | gui_to_use = "MiniGUI";
|
---|
361 | }
|
---|
362 | else
|
---|
363 | if (argument == "-mpcgui") {
|
---|
364 | gui_to_use = "MpcGUI";
|
---|
365 | }
|
---|
366 | else
|
---|
367 | if (argument == "-defaultgui") {
|
---|
368 | gui_to_use = "DefaultGUI";
|
---|
369 | }
|
---|
370 | else
|
---|
371 | if (argument == "-ontop") {
|
---|
372 | pref->stay_on_top = Preferences::AlwaysOnTop;
|
---|
373 | }
|
---|
374 | else
|
---|
375 | if (argument == "-no-ontop") {
|
---|
376 | pref->stay_on_top = Preferences::NeverOnTop;
|
---|
377 | }
|
---|
378 | #ifdef SKINS
|
---|
379 | else
|
---|
380 | if (argument == "-skingui") {
|
---|
381 | gui_to_use = "SkinGUI";
|
---|
382 | }
|
---|
383 | #endif
|
---|
384 | else {
|
---|
385 | // File
|
---|
386 | #if QT_VERSION >= 0x040600
|
---|
387 | QUrl fUrl = QUrl::fromUserInput(argument);
|
---|
388 | if (fUrl.isValid() && fUrl.scheme().toLower() == "file") {
|
---|
389 | argument = fUrl.toLocalFile();
|
---|
390 | }
|
---|
391 | #endif
|
---|
392 | if (QFile::exists( argument )) {
|
---|
393 | argument = QFileInfo(argument).absoluteFilePath();
|
---|
394 | }
|
---|
395 | files_to_play.append( argument );
|
---|
396 | }
|
---|
397 | }
|
---|
398 |
|
---|
399 | if (show_help) {
|
---|
400 | printf("%s\n", CLHelp::help().toLocal8Bit().data());
|
---|
401 | return NoError;
|
---|
402 | }
|
---|
403 |
|
---|
404 | qDebug("SMPlayer::processArgs: files_to_play: count: %d", files_to_play.count() );
|
---|
405 | for (int n=0; n < files_to_play.count(); n++) {
|
---|
406 | qDebug("SMPlayer::processArgs: files_to_play[%d]: '%s'", n, files_to_play[n].toUtf8().data());
|
---|
407 | }
|
---|
408 |
|
---|
409 | #ifdef SINGLE_INSTANCE
|
---|
410 | if (pref->use_single_instance) {
|
---|
411 | // Single instance
|
---|
412 | MyApplication * a = MyApplication::instance();
|
---|
413 | if (a->isRunning()) {
|
---|
414 | a->sendMessage("Hello");
|
---|
415 |
|
---|
416 | if (!action.isEmpty()) {
|
---|
417 | a->sendMessage("action " + action);
|
---|
418 | }
|
---|
419 | else {
|
---|
420 | if (!subtitle_file.isEmpty()) {
|
---|
421 | a->sendMessage("load_sub " + subtitle_file);
|
---|
422 | }
|
---|
423 |
|
---|
424 | if (!media_title.isEmpty()) {
|
---|
425 | a->sendMessage("media_title " + files_to_play[0] + " <<sep>> " + media_title);
|
---|
426 | }
|
---|
427 |
|
---|
428 | if (!files_to_play.isEmpty()) {
|
---|
429 | /* a->sendMessage("open_file " + files_to_play[0]); */
|
---|
430 | QString command = "open_files";
|
---|
431 | if (add_to_playlist) command = "add_to_playlist";
|
---|
432 | a->sendMessage(command +" "+ files_to_play.join(" <<sep>> "));
|
---|
433 | }
|
---|
434 | }
|
---|
435 |
|
---|
436 | return NoError;
|
---|
437 | }
|
---|
438 | }
|
---|
439 | #endif
|
---|
440 |
|
---|
441 | if (!pref->default_font.isEmpty()) {
|
---|
442 | QFont f;
|
---|
443 | f.fromString(pref->default_font);
|
---|
444 | qApp->setFont(f);
|
---|
445 | }
|
---|
446 |
|
---|
447 | return SMPlayer::NoExit;
|
---|
448 | }
|
---|
449 |
|
---|
450 | void SMPlayer::start() {
|
---|
451 | #ifdef FONTCACHE_DIALOG
|
---|
452 | #ifndef PORTABLE_APP
|
---|
453 | if (Version::with_revision() != pref->smplayer_version) {
|
---|
454 | FontCacheDialog d(0);
|
---|
455 | d.run(pref->mplayer_bin, "sample.avi");
|
---|
456 | pref->smplayer_version = Version::with_revision();
|
---|
457 | }
|
---|
458 | #endif
|
---|
459 | #endif
|
---|
460 |
|
---|
461 | if (!gui()->startHidden() || !files_to_play.isEmpty() ) gui()->show();
|
---|
462 | if (!files_to_play.isEmpty()) {
|
---|
463 | if (!subtitle_file.isEmpty()) gui()->setInitialSubtitle(subtitle_file);
|
---|
464 | if (!media_title.isEmpty()) gui()->getCore()->addForcedTitle(files_to_play[0], media_title);
|
---|
465 | gui()->openFiles(files_to_play);
|
---|
466 | }
|
---|
467 |
|
---|
468 | if (!actions_list.isEmpty()) {
|
---|
469 | if (files_to_play.isEmpty()) {
|
---|
470 | gui()->runActions(actions_list);
|
---|
471 | } else {
|
---|
472 | gui()->runActionsLater(actions_list);
|
---|
473 | }
|
---|
474 | }
|
---|
475 | }
|
---|
476 |
|
---|
477 | #ifndef PORTABLE_APP
|
---|
478 | void SMPlayer::createConfigDirectory() {
|
---|
479 | // Create smplayer config directory
|
---|
480 | if (!QFile::exists(Paths::configPath())) {
|
---|
481 | QDir d;
|
---|
482 | if (!d.mkdir(Paths::configPath())) {
|
---|
483 | qWarning("SMPlayer::createConfigDirectory: can't create %s", Paths::configPath().toUtf8().data());
|
---|
484 | }
|
---|
485 | // Screenshot folder already created in preferences.cpp if Qt >= 4.4
|
---|
486 | #if QT_VERSION < 0x040400
|
---|
487 | QString s = Paths::configPath() + "/screenshots";
|
---|
488 | if (!d.mkdir(s)) {
|
---|
489 | qWarning("SMPlayer::createHomeDirectory: can't create %s", s.toUtf8().data());
|
---|
490 | }
|
---|
491 | #endif
|
---|
492 | }
|
---|
493 | }
|
---|
494 | #endif
|
---|
495 |
|
---|
496 | #ifdef FONTS_HACK
|
---|
497 | void SMPlayer::createFontFile() {
|
---|
498 | qDebug("SMPlayer::createFontFile");
|
---|
499 | QString output = Paths::configPath() + "/fonts.conf";
|
---|
500 |
|
---|
501 | // Check if the file already exists with the modified path
|
---|
502 | if (QFile::exists(output)) {
|
---|
503 | QFile i(output);
|
---|
504 | if (i.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
---|
505 | QString text = i.readAll();
|
---|
506 | if (text.contains("<dir>" + Paths::fontPath() + "</dir>")) {
|
---|
507 | qDebug("SMPlayer::createFontFile: file %s already exists with font path. Doing nothing.", output.toUtf8().constData());
|
---|
508 | return;
|
---|
509 | }
|
---|
510 | }
|
---|
511 | }
|
---|
512 |
|
---|
513 | QString input = Paths::appPath() + "/mplayer/fonts/fonts.conf";
|
---|
514 | if (!QFile::exists(input)) {
|
---|
515 | qDebug("SMPlayer::createFontFile: %s doesn't exist", input.toUtf8().constData());
|
---|
516 | input = Paths::appPath() + "/mplayer/mpv/fonts.conf";
|
---|
517 | if (!QFile::exists(input)) {
|
---|
518 | qDebug("SMPlayer::createFontFile: %s doesn't exist", input.toUtf8().constData());
|
---|
519 | qWarning("SMPlayer::createFontFile: failed to create fonts.conf");
|
---|
520 | return;
|
---|
521 | }
|
---|
522 | }
|
---|
523 | qDebug("SMPlayer::createFontFile: input: %s", input.toUtf8().constData());
|
---|
524 | QFile infile(input);
|
---|
525 | if (infile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
---|
526 | QString text = infile.readAll();
|
---|
527 | text = text.replace("<!-- <dir>WINDOWSFONTDIR</dir> -->", "<dir>WINDOWSFONTDIR</dir>");
|
---|
528 | text = text.replace("<dir>WINDOWSFONTDIR</dir>", "<dir>" + Paths::fontPath() + "</dir>");
|
---|
529 | //qDebug("SMPlayer::createFontFile: %s", text.toUtf8().constData());
|
---|
530 |
|
---|
531 | qDebug("SMPlayer::createFontFile: saving %s", output.toUtf8().constData());
|
---|
532 | QFile outfile(output);
|
---|
533 | if (outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
---|
534 | outfile.write(text.toUtf8());
|
---|
535 | outfile.close();
|
---|
536 | }
|
---|
537 | }
|
---|
538 | }
|
---|
539 | #endif
|
---|
540 |
|
---|
541 | void SMPlayer::showInfo() {
|
---|
542 | #ifdef Q_OS_WIN
|
---|
543 | QString win_ver;
|
---|
544 | switch (QSysInfo::WindowsVersion) {
|
---|
545 | case QSysInfo::WV_2000: win_ver = "Windows 2000"; break;
|
---|
546 | case QSysInfo::WV_XP: win_ver = "Windows XP"; break;
|
---|
547 | case QSysInfo::WV_2003: win_ver = "Windows XP Professional x64/Server 2003"; break;
|
---|
548 | case QSysInfo::WV_VISTA: win_ver = "Windows Vista/Server 2008"; break;
|
---|
549 | #if QT_VERSION >= 0x040501
|
---|
550 | case QSysInfo::WV_WINDOWS7: win_ver = "Windows 7/Server 2008 R2"; break;
|
---|
551 | #endif
|
---|
552 | #if QT_VERSION >= 0x040803
|
---|
553 | case QSysInfo::WV_WINDOWS8: win_ver = "Windows 8/Server 2012"; break;
|
---|
554 | #endif
|
---|
555 | #if ((QT_VERSION >= 0x040806 && QT_VERSION < 0x050000) || (QT_VERSION >= 0x050200))
|
---|
556 | case QSysInfo::WV_WINDOWS8_1: win_ver = "Windows 8.1/Server 2012 R2"; break;
|
---|
557 | #endif
|
---|
558 | #if ((QT_VERSION >= 0x040807 && QT_VERSION < 0x050000) || (QT_VERSION >= 0x050500))
|
---|
559 | case QSysInfo::WV_WINDOWS10: win_ver = "Windows 10"; break;
|
---|
560 | #endif
|
---|
561 | case QSysInfo::WV_NT_based: win_ver = "NT-based Windows"; break;
|
---|
562 | default: win_ver = QString("Unknown/Unsupported Windows OS"); break;
|
---|
563 | }
|
---|
564 | #endif
|
---|
565 | QString s = QObject::tr("This is SMPlayer v. %1 running on %2")
|
---|
566 | .arg(Version::printable())
|
---|
567 | #ifdef Q_OS_LINUX
|
---|
568 | .arg("Linux")
|
---|
569 | #else
|
---|
570 | #ifdef Q_OS_WIN
|
---|
571 | .arg("Windows ("+win_ver+")")
|
---|
572 | #else
|
---|
573 | #ifdef Q_OS_OS2
|
---|
574 | .arg("eCS (OS/2)")
|
---|
575 | #else
|
---|
576 | .arg("Other OS")
|
---|
577 | #endif
|
---|
578 | #endif
|
---|
579 | #endif
|
---|
580 | ;
|
---|
581 |
|
---|
582 | printf("%s\n", s.toLocal8Bit().data() );
|
---|
583 | qDebug("%s", s.toUtf8().data() );
|
---|
584 | qDebug("Compiled with Qt v. %s, using %s", QT_VERSION_STR, qVersion());
|
---|
585 |
|
---|
586 | qDebug(" * application path: '%s'", Paths::appPath().toUtf8().data());
|
---|
587 | qDebug(" * data path: '%s'", Paths::dataPath().toUtf8().data());
|
---|
588 | qDebug(" * translation path: '%s'", Paths::translationPath().toUtf8().data());
|
---|
589 | qDebug(" * doc path: '%s'", Paths::docPath().toUtf8().data());
|
---|
590 | qDebug(" * themes path: '%s'", Paths::themesPath().toUtf8().data());
|
---|
591 | qDebug(" * shortcuts path: '%s'", Paths::shortcutsPath().toUtf8().data());
|
---|
592 | qDebug(" * config path: '%s'", Paths::configPath().toUtf8().data());
|
---|
593 | qDebug(" * ini path: '%s'", Paths::iniPath().toUtf8().data());
|
---|
594 | qDebug(" * file for subtitles' styles: '%s'", Paths::subtitleStyleFile().toUtf8().data());
|
---|
595 | qDebug(" * current path: '%s'", QDir::currentPath().toUtf8().data());
|
---|
596 | #ifdef FONTS_HACK
|
---|
597 | qDebug(" * font path: '%s'", Paths::fontPath().toUtf8().data());
|
---|
598 | #endif
|
---|
599 | }
|
---|
600 |
|
---|
601 | #ifdef LOG_SMPLAYER
|
---|
602 | QFile SMPlayer::output_log;
|
---|
603 | bool SMPlayer::allow_to_send_log_to_gui = false;
|
---|
604 |
|
---|
605 | #if QT_VERSION >= 0x050000
|
---|
606 | void SMPlayer::myMessageOutput( QtMsgType type, const QMessageLogContext &, const QString & msg ) {
|
---|
607 | #else
|
---|
608 | void SMPlayer::myMessageOutput( QtMsgType type, const char *msg ) {
|
---|
609 | #endif
|
---|
610 | static QStringList saved_lines;
|
---|
611 | static QString orig_line;
|
---|
612 | static QString line2;
|
---|
613 | static QRegExp rx_log;
|
---|
614 |
|
---|
615 | if (pref) {
|
---|
616 | if (!pref->log_smplayer) return;
|
---|
617 | rx_log.setPattern(pref->log_filter);
|
---|
618 | } else {
|
---|
619 | rx_log.setPattern(".*");
|
---|
620 | }
|
---|
621 |
|
---|
622 | line2.clear();
|
---|
623 |
|
---|
624 | #if QT_VERSION >= 0x050000
|
---|
625 | orig_line = msg;
|
---|
626 | #else
|
---|
627 | #ifdef Q_OS_WIN
|
---|
628 | orig_line = QString::fromLocal8Bit(msg);
|
---|
629 | #else
|
---|
630 | orig_line = QString::fromUtf8(msg);
|
---|
631 | #endif
|
---|
632 | #endif
|
---|
633 |
|
---|
634 | switch ( type ) {
|
---|
635 | case QtDebugMsg:
|
---|
636 | if (rx_log.indexIn(orig_line) > -1) {
|
---|
637 | #ifndef NO_DEBUG_ON_CONSOLE
|
---|
638 | fprintf( stderr, "Debug: %s\n", orig_line.toLocal8Bit().data() );
|
---|
639 | #endif
|
---|
640 | line2 = orig_line;
|
---|
641 | }
|
---|
642 | break;
|
---|
643 | case QtWarningMsg:
|
---|
644 | #ifndef NO_DEBUG_ON_CONSOLE
|
---|
645 | fprintf( stderr, "Warning: %s\n", orig_line.toLocal8Bit().data() );
|
---|
646 | #endif
|
---|
647 | line2 = "WARNING: " + orig_line;
|
---|
648 | break;
|
---|
649 | case QtFatalMsg:
|
---|
650 | #ifndef NO_DEBUG_ON_CONSOLE
|
---|
651 | fprintf( stderr, "Fatal: %s\n", orig_line.toLocal8Bit().data() );
|
---|
652 | #endif
|
---|
653 | line2 = "FATAL: " + orig_line;
|
---|
654 | abort(); // deliberately core dump
|
---|
655 | case QtCriticalMsg:
|
---|
656 | #ifndef NO_DEBUG_ON_CONSOLE
|
---|
657 | fprintf( stderr, "Critical: %s\n", orig_line.toLocal8Bit().data() );
|
---|
658 | #endif
|
---|
659 | line2 = "CRITICAL: " + orig_line;
|
---|
660 | break;
|
---|
661 | }
|
---|
662 |
|
---|
663 | if (line2.isEmpty()) return;
|
---|
664 |
|
---|
665 | line2 = "["+ QTime::currentTime().toString("hh:mm:ss:zzz") +"] "+ line2;
|
---|
666 |
|
---|
667 | if (allow_to_send_log_to_gui && main_window) {
|
---|
668 | if (!saved_lines.isEmpty()) {
|
---|
669 | // Send saved lines first
|
---|
670 | for (int n=0; n < saved_lines.count(); n++) {
|
---|
671 | main_window->recordSmplayerLog(saved_lines[n]);
|
---|
672 | }
|
---|
673 | saved_lines.clear();
|
---|
674 | }
|
---|
675 | main_window->recordSmplayerLog(line2);
|
---|
676 | } else {
|
---|
677 | // GUI is not created yet, save lines for later
|
---|
678 | saved_lines.append(line2);
|
---|
679 | /* printf("SMPlayer::myMessageOutput: no gui\n"); */
|
---|
680 | }
|
---|
681 |
|
---|
682 | if (pref) {
|
---|
683 | if (pref->save_smplayer_log) {
|
---|
684 | // Save log to file
|
---|
685 | if (!output_log.isOpen()) {
|
---|
686 | // FIXME: the config path may not be initialized if USE_LOCKS is not defined
|
---|
687 | output_log.setFileName( Paths::configPath() + "/smplayer_log.txt" );
|
---|
688 | output_log.open(QIODevice::WriteOnly);
|
---|
689 | }
|
---|
690 | if (output_log.isOpen()) {
|
---|
691 | QString l = line2 + "\r\n";
|
---|
692 | output_log.write(l.toUtf8().constData());
|
---|
693 | output_log.flush();
|
---|
694 | }
|
---|
695 | }
|
---|
696 | }
|
---|
697 | }
|
---|
698 | #endif
|
---|
699 |
|
---|
700 | /*
|
---|
701 | void myMessageOutput( QtMsgType type, const char *msg ) {
|
---|
702 | static QString orig_line;
|
---|
703 | orig_line = QString::fromUtf8(msg);
|
---|
704 |
|
---|
705 | switch ( type ) {
|
---|
706 | case QtDebugMsg:
|
---|
707 | #ifndef NO_DEBUG_ON_CONSOLE
|
---|
708 | fprintf( stderr, "Debug: %s\n", orig_line.toLocal8Bit().data() );
|
---|
709 | #endif
|
---|
710 | break;
|
---|
711 |
|
---|
712 | case QtWarningMsg:
|
---|
713 | #ifndef NO_DEBUG_ON_CONSOLE
|
---|
714 | fprintf( stderr, "Warning: %s\n", orig_line.toLocal8Bit().data() );
|
---|
715 | #endif
|
---|
716 | break;
|
---|
717 |
|
---|
718 | case QtCriticalMsg:
|
---|
719 | #ifndef NO_DEBUG_ON_CONSOLE
|
---|
720 | fprintf( stderr, "Critical: %s\n", orig_line.toLocal8Bit().data() );
|
---|
721 | #endif
|
---|
722 | break;
|
---|
723 |
|
---|
724 | case QtFatalMsg:
|
---|
725 | #ifndef NO_DEBUG_ON_CONSOLE
|
---|
726 | fprintf( stderr, "Fatal: %s\n", orig_line.toLocal8Bit().data() );
|
---|
727 | #endif
|
---|
728 | abort(); // deliberately core dump
|
---|
729 | }
|
---|
730 | }
|
---|
731 | */
|
---|
732 |
|
---|
733 | #include "moc_smplayer.cpp"
|
---|