1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2008 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"
24
#include "preferences.h"
25
#include "translator.h"
29
#include "constants.h"
33
#include "extensions.h"
34
#include "winfileassoc.h" //required for Uninstall
37
#include <QApplication>
39
#include <QTranslator>
48
using namespace Global;
50
static QRegExp rx_log;
52
void myMessageOutput( QtMsgType type, const char *msg ) {
53
if ( (!pref) || (!pref->log_smplayer) ) return;
55
rx_log.setPattern(pref->log_filter);
57
QString line = QString::fromUtf8(msg);
60
if (rx_log.indexIn(line) > -1) {
61
#ifndef NO_DEBUG_ON_CONSOLE
62
fprintf( stderr, "Debug: %s\n", line.toLocal8Bit().data() );
64
Helper::addLog( line );
68
#ifndef NO_DEBUG_ON_CONSOLE
69
fprintf( stderr, "Warning: %s\n", line.toLocal8Bit().data() );
71
Helper::addLog( "WARNING: " + line );
74
#ifndef NO_DEBUG_ON_CONSOLE
75
fprintf( stderr, "Fatal: %s\n", line.toLocal8Bit().data() );
77
Helper::addLog( "FATAL: " + line );
78
abort(); // deliberately core dump
80
#ifndef NO_DEBUG_ON_CONSOLE
81
fprintf( stderr, "Critical: %s\n", line.toLocal8Bit().data() );
83
Helper::addLog( "CRITICAL: " + line );
89
QString s = QObject::tr("This is SMPlayer v. %1 running on %2")
90
.arg(smplayerVersion())
102
printf("%s\n", s.toLocal8Bit().data() );
103
qDebug("%s", s.toUtf8().data() );
104
qDebug("Qt v. " QT_VERSION_STR);
106
qDebug(" * application path: '%s'", Helper::appPath().toUtf8().data());
107
qDebug(" * data path: '%s'", Helper::dataPath().toUtf8().data());
108
qDebug(" * translation path: '%s'", Helper::translationPath().toUtf8().data());
109
qDebug(" * doc path: '%s'", Helper::docPath().toUtf8().data());
110
qDebug(" * themes path: '%s'", Helper::themesPath().toUtf8().data());
111
qDebug(" * shortcuts path: '%s'", Helper::shortcutsPath().toUtf8().data());
112
qDebug(" * smplayer home path: '%s'", Helper::appHomePath().toUtf8().data());
113
qDebug(" * ini path: '%s'", Helper::iniPath().toUtf8().data());
114
qDebug(" * current path: '%s'", QDir::currentPath().toUtf8().data());
118
void createHomeDirectory() {
119
// Create smplayer home directories
120
if (!QFile::exists(Helper::appHomePath())) {
122
if (!d.mkdir(Helper::appHomePath())) {
123
qWarning("main: can't create %s", Helper::appHomePath().toUtf8().data());
125
QString s = Helper::appHomePath() + "/screenshots";
127
qWarning("main: can't create %s", s.toUtf8().data());
132
int main( int argc, char ** argv )
134
QApplication a( argc, argv );
137
if (a.arguments().contains("-uninstall")){
138
//Called by uninstaller. Will restore old associations.
139
WinFileAssoc RegAssoc;
142
RegAssoc.GetRegisteredExtensions(exts.multimedia(), regExts);
143
RegAssoc.RestoreFileAssociations(regExts);
144
printf("Restored associations\n");
151
QString app_path = a.applicationDirPath();
152
Helper::setAppPath(app_path);
153
//qDebug( "main: application path: '%s'", app_path.toUtf8().data());
156
QStringList files_to_play;
157
QString action; // Action to be passed to running instance
158
QString actions_list; // Actions to be run on startup
159
bool add_to_playlist = false;
161
QString app_name = QFileInfo(a.applicationFilePath()).baseName();
162
qDebug("main: app name: %s", app_name.toUtf8().data());
163
// If the name is smplayer_portable, activate the -ini_path by default
164
if (app_name.toLower() == "smplayer_portable") {
165
ini_path = Helper::appPath();
167
else if (QFile::exists( Helper::appPath() + "/smplayer.ini" ) ) {
168
ini_path = Helper::appPath();
169
qDebug("Using existing %s", QString(Helper::appPath() + "/smplayer.ini").toUtf8().data());
172
int close_at_end = -1; // -1 = not set, 1 = true, 0 false
173
int start_in_fullscreen = -1;
174
bool show_help = false;
176
bool use_minigui = false;
183
int arg_count = a.arguments().count();
185
bool is_playlist = false;
187
if ( arg_count > arg_init ) {
188
for (int n=arg_init; n < arg_count; n++) {
189
QString argument = a.arguments()[n];
190
if (argument == "-ini-path") {
191
//qDebug( "ini_path: %d %d", n+1, arg_count );
192
ini_path = Helper::appPath();
193
if (n+1 < arg_count) {
195
ini_path = a.arguments()[n];
197
printf("Error: expected parameter for -ini-path\r\n");
202
if (argument == "-send-action") {
203
if (n+1 < arg_count) {
205
action = a.arguments()[n];
207
printf("Error: expected parameter for -send-action\r\n");
212
if (argument == "-actions") {
213
if (n+1 < arg_count) {
215
actions_list = a.arguments()[n];
217
printf("Error: expected parameter for -actions\r\n");
222
if (argument == "-playlist") {
226
if ((argument == "--help") || (argument == "-help") ||
227
(argument == "-h") || (argument == "-?") ) {
231
if (argument == "-close-at-end") {
235
if (argument == "-no-close-at-end") {
239
if (argument == "-fullscreen") {
240
start_in_fullscreen = 1;
243
if (argument == "-no-fullscreen") {
244
start_in_fullscreen = 0;
247
if (argument == "-add-to-playlist") {
248
add_to_playlist = true;
251
if (argument == "-mini") {
256
if (QFile::exists( argument )) {
257
argument = QFileInfo(argument).absoluteFilePath();
260
argument = argument + IS_PLAYLIST_TAG;
263
files_to_play.append( argument );
268
if (ini_path.isEmpty()) createHomeDirectory();
270
global_init(ini_path);
272
qInstallMsgHandler( myMessageOutput );
274
// Application translations
275
translator->load( pref->language );
280
printf("%s\n", CLHelp::help().toLocal8Bit().data());
284
qDebug("main: files_to_play: count: %d", files_to_play.count() );
285
for (int n=0; n < files_to_play.count(); n++) {
286
qDebug("main: files_to_play[%d]: '%s'", n, files_to_play[n].toUtf8().data());
290
if (pref->use_single_instance) {
292
MyClient *c = new MyClient(pref->connection_port);
293
//c->setTimeOut(1000);
294
if (c->openConnection()) {
295
qDebug("main: found another instance");
297
if (!action.isEmpty()) {
298
if (c->sendAction(action)) {
299
qDebug("main: action passed successfully to the running instance");
301
printf("Error: action couldn't be passed to the running instance");
306
if (!files_to_play.isEmpty()) {
307
if (c->sendFiles(files_to_play, add_to_playlist)) {
308
qDebug("main: files sent successfully to the running instance");
309
qDebug("main: exiting.");
311
qDebug("main: files couldn't be sent to another instance");
318
if (!action.isEmpty()) {
319
printf("Error: no running instance found\r\n");
325
if (!pref->default_font.isEmpty()) {
327
f.fromString(pref->default_font);
331
if (close_at_end != -1) {
332
pref->close_on_finish = close_at_end;
335
if (start_in_fullscreen != -1) {
336
pref->start_in_fullscreen = start_in_fullscreen;
339
// Changes to app path, so smplayer can find a relative mplayer path
340
QDir::setCurrent(Helper::appPath());
341
qDebug("main: changed working directory to app path");
342
qDebug("main: current directory: %s", QDir::currentPath().toUtf8().data());
348
w = new DefaultGui(0);
350
if (!w->startHidden() || !files_to_play.isEmpty() ) w->show();
351
if (!files_to_play.isEmpty()) w->openFiles(files_to_play);
353
if (!actions_list.isEmpty()) w->runActions(actions_list);
355
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );