~ubuntu-branches/debian/squeeze/smplayer/squeeze

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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*  smplayer, GUI front-end for mplayer.
    Copyright (C) 2007 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
*/

#if KDE_SUPPORT
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#else
#include <qapplication.h>
#endif

#include <qcolor.h>
#include "defaultgui.h"
#include "helper.h"
#include "global.h"
#include "preferences.h"
#include "translator.h"
#include "version.h"

#include <qlocale.h>
#include <qtranslator.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qsettings.h>
#include <qregexp.h>

#include <stdio.h>
#include <stdlib.h>

#include <qmime.h>
#include <qurl.h>


static QRegExp rx_log;

void myMessageOutput( QtMsgType type, const char *msg ) {
	if ( (!pref) || (!pref->log_smplayer) ) return;

	rx_log.setPattern(pref->log_filter);

	QString line = QString::fromUtf8(msg);
	switch ( type ) {
		case QtDebugMsg:
			if (rx_log.search(line) > -1) {
				#ifndef NO_DEBUG_ON_CONSOLE
				fprintf( stderr, "Debug: %s\n", line.local8Bit().data() );
				#endif
				Helper::addLog( line );
			}
			break;
		case QtWarningMsg:
			#ifndef NO_DEBUG_ON_CONSOLE
			fprintf( stderr, "Warning: %s\n", line.local8Bit().data() );
			#endif
			Helper::addLog( "WARNING: " + line );
			break;
		case QtFatalMsg:
			#ifndef NO_DEBUG_ON_CONSOLE
			fprintf( stderr, "Fatal: %s\n", line.local8Bit().data() );
			#endif
			Helper::addLog( "FATAL: " + line );
			abort();                    // deliberately core dump
#if QT_VERSION >= 0x040000
		case QtCriticalMsg:
			#ifndef NO_DEBUG_ON_CONSOLE
			fprintf( stderr, "Critical: %s\n", line.local8Bit().data() );
			#endif
			Helper::addLog( "CRITICAL: " + line );
			break;
#endif
	}
}

void showInfo() {
	qDebug("This is smplayer v. " VERSION " running on "
#ifdef Q_OS_LINUX
           "Linux"
#else
#ifdef Q_OS_WIN
           "Windows"
#else
		   "Other OS"
#endif
#endif
		);
	qDebug("Qt v. " QT_VERSION_STR);

	qDebug(" * application path: '%s'", Helper::appPath().utf8().data());
	qDebug(" * data path: '%s'", Helper::dataPath().utf8().data());
	qDebug(" * translation path: '%s'", Helper::translationPath().utf8().data());
	qDebug(" * doc path: '%s'", Helper::docPath().utf8().data());
	qDebug(" * themes path: '%s'", Helper::themesPath().utf8().data());
	qDebug(" * shortcuts path: '%s'", Helper::shortcutsPath().utf8().data());
}


int main( int argc, char ** argv ) 
{
#if KDE_SUPPORT
	QMimeSourceFactory *sf = QMimeSourceFactory::defaultFactory();

	KAboutData *aboutdata = new KAboutData("smplayer", 
		"SMPlayer", VERSION, 
        QT_TR_NOOP("Front-end for mplayer"), KAboutData::License_GPL,
		"(c) 2006, 2007 Ricardo Villalba","",
		"http://smplayer.sourceforge.net");
	aboutdata->addAuthor("Ricardo Villalba",
		QT_TR_NOOP("Developer"),"rvm@escomposlinux.org");

	static const KCmdLineOptions options[] =
	{ 
     //{ "ini-path <dir>", "path for ini file", 0 },
     {"+[file]", QT_TR_NOOP("File to open"), 0 }, KCmdLineLastOption };

	KCmdLineArgs::init(argc, argv, aboutdata);
	KCmdLineArgs::addCmdLineOptions( options );

	KApplication a;
	QMimeSourceFactory * kdeFactory = QMimeSourceFactory::takeDefaultFactory();
	QMimeSourceFactory::setDefaultFactory( sf );
	if ( kdeFactory ) {
		QMimeSourceFactory::addFactory( kdeFactory );
	}
#else
	QApplication a( argc, argv );
#endif


	QString app_path = a.applicationDirPath();
	Helper::setAppPath(app_path);
	//qDebug( "main: application path: '%s'", app_path.utf8().data());


	QString ini_path="";
	QStringList files_to_play;

#if KDE_SUPPORT
	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
	int arg_init = 0;
	int arg_count = args->count();

	if ( arg_count > arg_init ) {
		for (int n=arg_init; n < arg_count; n++) {
			QString argument = QString::fromLocal8Bit( args->arg(n) );
			if (QFile::exists( argument )) {
				argument = QFileInfo(argument).absFilePath();
			}
			files_to_play.append( argument );
		}
	}

#else
	// Qt code
	int arg_init = 1;
	#if QT_VERSION >= 0x040100
	int arg_count = a.arguments().count();
	#else
	int arg_count = a.argc();
	#endif

	if ( arg_count > arg_init ) {
		for (int n=arg_init; n < arg_count; n++) {
			#if QT_VERSION >= 0x040100
			QString argument = a.arguments()[n];
			#else
			QString argument = QString::fromLocal8Bit( a.argv()[n] );
			#endif
			if (argument == "-ini-path") {
				//qDebug( "ini_path: %d %d", n+1, arg_count );
				ini_path = Helper::appPath();
				if (n+1 < arg_count) {
					n++;
					#if QT_VERSION >= 0x040100
					ini_path = a.arguments()[n];
					#else
					ini_path = QString::fromLocal8Bit( a.argv()[n] );
					#endif
				}
			}
			else {
				if (QFile::exists( argument )) {
					argument = QFileInfo(argument).absFilePath();
				}
				files_to_play.append( argument );
			}
		}
	}
#endif

	global_init(ini_path);

	qInstallMsgHandler( myMessageOutput );

	showInfo();
#if QT_VERSION >= 0x040000
	qDebug(" * ini path: '%s'", ini_path.utf8().data());
#endif

	// Translator
	translator->load( pref->language );
	a.installTranslator(translator->qtranslator());

	qDebug("main: files_to_play: count: %d", files_to_play.count() );
	for (int n=0; n < files_to_play.count(); n++) {
		qDebug("main: files_to_play[%d]: '%s'", n, files_to_play[n].utf8().data());
	}

	DefaultGui * w = new DefaultGui(files_to_play, 0, "gui");
	a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );

	int r = a.exec();
	delete w;

	a.removeTranslator( translator->qtranslator() );

	global_end();

	return r;
}