1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
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.
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.
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
20
#include "defaultgui.h"
25
#include "translator.h"
27
#include "constants.h"
32
#include <QApplication>
38
#include "extensions.h"
39
#include "winfileassoc.h" //required for Uninstall
44
using namespace Global;
46
SMPlayer::SMPlayer(const QString & config_path, QObject * parent )
50
gui_to_use = "DefaultGui";
52
close_at_end = -1; // Not set
53
start_in_fullscreen = -1; // Not set
58
Paths::setAppPath( qApp->applicationDirPath() );
61
if (config_path.isEmpty()) createConfigDirectory();
63
global_init(config_path);
65
// Application translations
66
translator->load( pref->language );
70
SMPlayer::~SMPlayer() {
71
if (main_window != 0) delete main_window;
75
BaseGui * SMPlayer::gui() {
76
if (main_window == 0) {
77
// Changes to app path, so smplayer can find a relative mplayer path
78
QDir::setCurrent(Paths::appPath());
79
qDebug("SMPlayer::gui: changed working directory to app path");
80
qDebug("SMPlayer::gui: current directory: %s", QDir::currentPath().toUtf8().data());
82
if (gui_to_use.toLower() == "minigui")
83
main_window = new MiniGui(0);
85
if (gui_to_use.toLower() == "mpcgui")
86
main_window = new MpcGui(0);
88
main_window = new DefaultGui(0);
91
qDebug("SMPlayer::gui: moving main window to %d %d", gui_position.x(), gui_position.y());
92
main_window->move(gui_position);
95
qDebug("SMPlayer::gui: resizing main window to %dx%d", gui_size.width(), gui_size.height());
96
main_window->resize(gui_size);
99
main_window->setForceCloseOnFinish(close_at_end);
100
main_window->setForceStartInFullscreen(start_in_fullscreen);
106
SMPlayer::ExitCode SMPlayer::processArgs(QStringList args) {
107
qDebug("SMPlayer::processArgs: arguments: %d", args.count());
108
for (int n = 0; n < args.count(); n++) {
109
qDebug("SMPlayer::processArgs: %d = %s", n, args[n].toUtf8().data());
113
QString action; // Action to be passed to running instance
114
bool show_help = false;
116
if (!pref->gui.isEmpty()) gui_to_use = pref->gui;
117
bool add_to_playlist = false;
119
bool is_playlist = false;
122
if (args.contains("-uninstall")){
124
//Called by uninstaller. Will restore old associations.
125
WinFileAssoc RegAssoc;
128
RegAssoc.GetRegisteredExtensions(exts.multimedia(), regExts);
129
RegAssoc.RestoreFileAssociations(regExts);
130
printf("Restored associations\n");
136
for (int n = 1; n < args.count(); n++) {
137
QString argument = args[n];
139
if (argument == "-send-action") {
140
if (n+1 < args.count()) {
144
printf("Error: expected parameter for -send-action\r\n");
145
return ErrorArgument;
149
if (argument == "-actions") {
150
if (n+1 < args.count()) {
152
actions_list = args[n];
154
printf("Error: expected parameter for -actions\r\n");
155
return ErrorArgument;
159
if (argument == "-sub") {
160
if (n+1 < args.count()) {
162
QString file = args[n];
163
if (QFile::exists(file)) {
164
subtitle_file = QFileInfo(file).absoluteFilePath();
166
printf("Error: file '%s' doesn't exists\r\n", file.toUtf8().constData());
169
printf("Error: expected parameter for -sub\r\n");
170
return ErrorArgument;
174
if (argument == "-pos") {
175
if (n+2 < args.count()) {
178
gui_position.setX( args[n].toInt(&ok_x) );
180
gui_position.setY( args[n].toInt(&ok_y) );
181
if (ok_x && ok_y) move_gui = true;
183
printf("Error: expected parameter for -pos\r\n");
184
return ErrorArgument;
188
if (argument == "-size") {
189
if (n+2 < args.count()) {
190
bool ok_width, ok_height;
192
gui_size.setWidth( args[n].toInt(&ok_width) );
194
gui_size.setHeight( args[n].toInt(&ok_height) );
195
if (ok_width && ok_height) resize_gui = true;
197
printf("Error: expected parameter for -resize\r\n");
198
return ErrorArgument;
202
if (argument == "-playlist") {
206
if ((argument == "--help") || (argument == "-help") ||
207
(argument == "-h") || (argument == "-?") )
212
if (argument == "-close-at-end") {
216
if (argument == "-no-close-at-end") {
220
if (argument == "-fullscreen") {
221
start_in_fullscreen = 1;
224
if (argument == "-no-fullscreen") {
225
start_in_fullscreen = 0;
228
if (argument == "-add-to-playlist") {
229
add_to_playlist = true;
232
if (argument == "-mini" || argument == "-minigui") {
233
gui_to_use = "MiniGui";
236
if (argument == "-mpcgui") {
237
gui_to_use = "MpcGui";
240
if (argument == "-defaultgui") {
241
gui_to_use = "DefaultGui";
245
if (QFile::exists( argument )) {
246
argument = QFileInfo(argument).absoluteFilePath();
249
argument = argument + IS_PLAYLIST_TAG;
252
files_to_play.append( argument );
257
printf("%s\n", CLHelp::help().toLocal8Bit().data());
261
qDebug("SMPlayer::processArgs: files_to_play: count: %d", files_to_play.count() );
262
for (int n=0; n < files_to_play.count(); n++) {
263
qDebug("SMPlayer::processArgs: files_to_play[%d]: '%s'", n, files_to_play[n].toUtf8().data());
267
if (pref->use_single_instance) {
269
int port = pref->connection_port;
270
if (pref->use_autoport) port = pref->autoport;
272
MyClient *c = new MyClient(port);
273
//c->setTimeOut(1000);
274
qDebug("SMPlayer::processArgs: trying to connect to port %d", port);
276
if (c->openConnection()) {
277
qDebug("SMPlayer::processArgs: found another instance");
279
if (!action.isEmpty()) {
280
if (c->sendAction(action)) {
281
qDebug("SMPlayer::processArgs: action passed successfully to the running instance");
283
printf("Error: action couldn't be passed to the running instance");
288
if (!subtitle_file.isEmpty()) {
289
if (c->sendSubtitleFile(subtitle_file)) {
290
qDebug("SMPlayer::processArgs: subtitle file sent successfully to the running instance");
292
qDebug("SMPlayer::processArgs: subtitle file couldn't be sent to another instance");
296
if (!files_to_play.isEmpty()) {
297
if (c->sendFiles(files_to_play, add_to_playlist)) {
298
qDebug("SMPlayer::processArgs: files sent successfully to the running instance");
299
qDebug("SMPlayer::processArgs: exiting.");
301
qDebug("SMPlayer::processArgs: files couldn't be sent to another instance");
305
c->closeConnection();
308
if (!action.isEmpty()) {
309
printf("Error: no running instance found\r\n");
310
return NoRunningInstance;
315
if (!pref->default_font.isEmpty()) {
317
f.fromString(pref->default_font);
321
return SMPlayer::NoExit;
324
void SMPlayer::start() {
325
if (!gui()->startHidden() || !files_to_play.isEmpty() ) gui()->show();
326
if (!files_to_play.isEmpty()) {
327
if (!subtitle_file.isEmpty()) gui()->setInitialSubtitle(subtitle_file);
328
gui()->openFiles(files_to_play);
331
if (!actions_list.isEmpty()) {
332
if (files_to_play.isEmpty()) {
333
gui()->runActions(actions_list);
335
gui()->runActionsLater(actions_list);
341
void SMPlayer::createConfigDirectory() {
342
// Create smplayer config directory
343
if (!QFile::exists(Paths::configPath())) {
345
if (!d.mkdir(Paths::configPath())) {
346
qWarning("SMPlayer::createConfigDirectory: can't create %s", Paths::configPath().toUtf8().data());
348
QString s = Paths::configPath() + "/screenshots";
350
qWarning("SMPlayer::createHomeDirectory: can't create %s", s.toUtf8().data());
356
void SMPlayer::showInfo() {
359
switch (QSysInfo::WindowsVersion) {
360
case QSysInfo::WV_32s: win_ver = "Windows 3.1"; break;
361
case QSysInfo::WV_95: win_ver = "Windows 95"; break;
362
case QSysInfo::WV_98: win_ver = "Windows 98"; break;
363
case QSysInfo::WV_Me: win_ver = "Windows Me"; break;
364
case QSysInfo::WV_NT: win_ver = "Windows NT"; break;
365
case QSysInfo::WV_2000: win_ver = "Windows 2000"; break;
366
case QSysInfo::WV_XP: win_ver = "Windows XP"; break;
367
case QSysInfo::WV_2003: win_ver = "Windows Server 2003"; break;
368
case QSysInfo::WV_VISTA: win_ver = "Windows Vista"; break;
369
#if QT_VERSION >= 0x040501
370
case QSysInfo::WV_WINDOWS7: win_ver = "Windows 7"; break;
372
default: win_ver = QString("other: %1").arg(QSysInfo::WindowsVersion);
375
QString s = QObject::tr("This is SMPlayer v. %1 running on %2")
376
.arg(smplayerVersion())
381
.arg("Windows ("+win_ver+")")
388
printf("%s\n", s.toLocal8Bit().data() );
389
qDebug("%s", s.toUtf8().data() );
390
qDebug("Compiled with Qt v. %s, using %s", QT_VERSION_STR, qVersion());
392
qDebug(" * application path: '%s'", Paths::appPath().toUtf8().data());
393
qDebug(" * data path: '%s'", Paths::dataPath().toUtf8().data());
394
qDebug(" * translation path: '%s'", Paths::translationPath().toUtf8().data());
395
qDebug(" * doc path: '%s'", Paths::docPath().toUtf8().data());
396
qDebug(" * themes path: '%s'", Paths::themesPath().toUtf8().data());
397
qDebug(" * shortcuts path: '%s'", Paths::shortcutsPath().toUtf8().data());
398
qDebug(" * config path: '%s'", Paths::configPath().toUtf8().data());
399
qDebug(" * ini path: '%s'", Paths::iniPath().toUtf8().data());
400
qDebug(" * file for subtitles' styles: '%s'", Paths::subtitleStyleFile().toUtf8().data());
401
qDebug(" * current path: '%s'", QDir::currentPath().toUtf8().data());