1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
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"
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
54
use_control_server = true;
59
Paths::setAppPath( qApp->applicationDirPath() );
62
if (config_path.isEmpty()) createConfigDirectory();
64
global_init(config_path);
66
// Application translations
67
translator->load( pref->language );
71
SMPlayer::~SMPlayer() {
72
if (main_window != 0) delete main_window;
76
BaseGui * SMPlayer::gui() {
77
if (main_window == 0) {
78
// Changes to app path, so smplayer can find a relative mplayer path
79
QDir::setCurrent(Paths::appPath());
80
qDebug("SMPlayer::gui: changed working directory to app path");
81
qDebug("SMPlayer::gui: current directory: %s", QDir::currentPath().toUtf8().data());
83
if (gui_to_use.toLower() == "minigui")
84
main_window = new MiniGui(use_control_server, 0);
86
if (gui_to_use.toLower() == "mpcgui")
87
main_window = new MpcGui(use_control_server, 0);
89
main_window = new DefaultGui(use_control_server, 0);
92
qDebug("SMPlayer::gui: moving main window to %d %d", gui_position.x(), gui_position.y());
93
main_window->move(gui_position);
96
qDebug("SMPlayer::gui: resizing main window to %dx%d", gui_size.width(), gui_size.height());
97
main_window->resize(gui_size);
100
main_window->setForceCloseOnFinish(close_at_end);
101
main_window->setForceStartInFullscreen(start_in_fullscreen);
107
SMPlayer::ExitCode SMPlayer::processArgs(QStringList args) {
108
qDebug("SMPlayer::processArgs: arguments: %d", args.count());
109
for (int n = 0; n < args.count(); n++) {
110
qDebug("SMPlayer::processArgs: %d = %s", n, args[n].toUtf8().data());
114
QString action; // Action to be passed to running instance
115
bool show_help = false;
117
if (!pref->gui.isEmpty()) gui_to_use = pref->gui;
118
bool add_to_playlist = false;
121
if (args.contains("-uninstall")){
123
//Called by uninstaller. Will restore old associations.
124
WinFileAssoc RegAssoc;
127
RegAssoc.GetRegisteredExtensions(exts.multimedia(), regExts);
128
RegAssoc.RestoreFileAssociations(regExts);
129
printf("Restored associations\n");
135
for (int n = 1; n < args.count(); n++) {
136
QString argument = args[n];
138
if (argument == "-send-action") {
139
if (n+1 < args.count()) {
143
printf("Error: expected parameter for -send-action\r\n");
144
return ErrorArgument;
148
if (argument == "-actions") {
149
if (n+1 < args.count()) {
151
actions_list = args[n];
153
printf("Error: expected parameter for -actions\r\n");
154
return ErrorArgument;
158
if (argument == "-sub") {
159
if (n+1 < args.count()) {
161
QString file = args[n];
162
if (QFile::exists(file)) {
163
subtitle_file = QFileInfo(file).absoluteFilePath();
165
printf("Error: file '%s' doesn't exists\r\n", file.toUtf8().constData());
168
printf("Error: expected parameter for -sub\r\n");
169
return ErrorArgument;
173
if (argument == "-pos") {
174
if (n+2 < args.count()) {
177
gui_position.setX( args[n].toInt(&ok_x) );
179
gui_position.setY( args[n].toInt(&ok_y) );
180
if (ok_x && ok_y) move_gui = true;
182
printf("Error: expected parameter for -pos\r\n");
183
return ErrorArgument;
187
if (argument == "-size") {
188
if (n+2 < args.count()) {
189
bool ok_width, ok_height;
191
gui_size.setWidth( args[n].toInt(&ok_width) );
193
gui_size.setHeight( args[n].toInt(&ok_height) );
194
if (ok_width && ok_height) resize_gui = true;
196
printf("Error: expected parameter for -resize\r\n");
197
return ErrorArgument;
201
if ((argument == "--help") || (argument == "-help") ||
202
(argument == "-h") || (argument == "-?") )
207
if (argument == "-close-at-end") {
211
if (argument == "-no-close-at-end") {
215
if (argument == "-fullscreen") {
216
start_in_fullscreen = 1;
219
if (argument == "-no-fullscreen") {
220
start_in_fullscreen = 0;
223
if (argument == "-disable-server") {
224
use_control_server = false;
227
if (argument == "-add-to-playlist") {
228
add_to_playlist = true;
231
if (argument == "-mini" || argument == "-minigui") {
232
gui_to_use = "MiniGui";
235
if (argument == "-mpcgui") {
236
gui_to_use = "MpcGui";
239
if (argument == "-defaultgui") {
240
gui_to_use = "DefaultGui";
244
if (QFile::exists( argument )) {
245
argument = QFileInfo(argument).absoluteFilePath();
247
files_to_play.append( argument );
252
printf("%s\n", CLHelp::help().toLocal8Bit().data());
256
qDebug("SMPlayer::processArgs: files_to_play: count: %d", files_to_play.count() );
257
for (int n=0; n < files_to_play.count(); n++) {
258
qDebug("SMPlayer::processArgs: files_to_play[%d]: '%s'", n, files_to_play[n].toUtf8().data());
262
if (pref->use_single_instance) {
264
int port = pref->connection_port;
265
if (pref->use_autoport) port = pref->autoport;
267
MyClient *c = new MyClient(port);
268
//c->setTimeOut(1000);
269
qDebug("SMPlayer::processArgs: trying to connect to port %d", port);
271
if (c->openConnection()) {
272
qDebug("SMPlayer::processArgs: found another instance");
274
if (!action.isEmpty()) {
275
if (c->sendAction(action)) {
276
qDebug("SMPlayer::processArgs: action passed successfully to the running instance");
278
printf("Error: action couldn't be passed to the running instance");
283
if (!subtitle_file.isEmpty()) {
284
if (c->sendSubtitleFile(subtitle_file)) {
285
qDebug("SMPlayer::processArgs: subtitle file sent successfully to the running instance");
287
qDebug("SMPlayer::processArgs: subtitle file couldn't be sent to another instance");
291
if (!files_to_play.isEmpty()) {
292
if (c->sendFiles(files_to_play, add_to_playlist)) {
293
qDebug("SMPlayer::processArgs: files sent successfully to the running instance");
294
qDebug("SMPlayer::processArgs: exiting.");
296
qDebug("SMPlayer::processArgs: files couldn't be sent to another instance");
300
c->closeConnection();
303
if (!action.isEmpty()) {
304
printf("Error: no running instance found\r\n");
305
return NoRunningInstance;
310
if (!pref->default_font.isEmpty()) {
312
f.fromString(pref->default_font);
316
return SMPlayer::NoExit;
319
void SMPlayer::start() {
320
if (!gui()->startHidden() || !files_to_play.isEmpty() ) gui()->show();
321
if (!files_to_play.isEmpty()) {
322
if (!subtitle_file.isEmpty()) gui()->setInitialSubtitle(subtitle_file);
323
gui()->openFiles(files_to_play);
326
if (!actions_list.isEmpty()) {
327
if (files_to_play.isEmpty()) {
328
gui()->runActions(actions_list);
330
gui()->runActionsLater(actions_list);
336
void SMPlayer::createConfigDirectory() {
337
// Create smplayer config directory
338
if (!QFile::exists(Paths::configPath())) {
340
if (!d.mkdir(Paths::configPath())) {
341
qWarning("SMPlayer::createConfigDirectory: can't create %s", Paths::configPath().toUtf8().data());
343
QString s = Paths::configPath() + "/screenshots";
345
qWarning("SMPlayer::createHomeDirectory: can't create %s", s.toUtf8().data());
351
void SMPlayer::showInfo() {
354
switch (QSysInfo::WindowsVersion) {
355
case QSysInfo::WV_32s: win_ver = "Windows 3.1"; break;
356
case QSysInfo::WV_95: win_ver = "Windows 95"; break;
357
case QSysInfo::WV_98: win_ver = "Windows 98"; break;
358
case QSysInfo::WV_Me: win_ver = "Windows Me"; break;
359
case QSysInfo::WV_NT: win_ver = "Windows NT"; break;
360
case QSysInfo::WV_2000: win_ver = "Windows 2000"; break;
361
case QSysInfo::WV_XP: win_ver = "Windows XP"; break;
362
case QSysInfo::WV_2003: win_ver = "Windows Server 2003"; break;
363
case QSysInfo::WV_VISTA: win_ver = "Windows Vista"; break;
364
#if QT_VERSION >= 0x040501
365
case QSysInfo::WV_WINDOWS7: win_ver = "Windows 7"; break;
367
default: win_ver = QString("other: %1").arg(QSysInfo::WindowsVersion);
370
QString s = QObject::tr("This is SMPlayer v. %1 running on %2")
371
.arg(smplayerVersion())
376
.arg("Windows ("+win_ver+")")
387
printf("%s\n", s.toLocal8Bit().data() );
388
qDebug("%s", s.toUtf8().data() );
389
qDebug("Compiled with Qt v. %s, using %s", QT_VERSION_STR, qVersion());
391
qDebug(" * application path: '%s'", Paths::appPath().toUtf8().data());
392
qDebug(" * data path: '%s'", Paths::dataPath().toUtf8().data());
393
qDebug(" * translation path: '%s'", Paths::translationPath().toUtf8().data());
394
qDebug(" * doc path: '%s'", Paths::docPath().toUtf8().data());
395
qDebug(" * themes path: '%s'", Paths::themesPath().toUtf8().data());
396
qDebug(" * shortcuts path: '%s'", Paths::shortcutsPath().toUtf8().data());
397
qDebug(" * config path: '%s'", Paths::configPath().toUtf8().data());
398
qDebug(" * ini path: '%s'", Paths::iniPath().toUtf8().data());
399
qDebug(" * file for subtitles' styles: '%s'", Paths::subtitleStyleFile().toUtf8().data());
400
qDebug(" * current path: '%s'", QDir::currentPath().toUtf8().data());