1
1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2008 Ricardo Villalba <rvm@escomposlinux.org>
2
Copyright (C) 2006-2009 Ricardo Villalba <rvm@escomposlinux.org>
4
4
This program is free software; you can redistribute it and/or modify
5
5
it under the terms of the GNU General Public License as published by
49
55
rx_log.setPattern(".*");
52
QString line = "["+ QTime::currentTime().toString() + "] " +
53
QString::fromUtf8(msg);
60
orig_line = QString::fromUtf8(msg);
57
if (rx_log.indexIn(line) > -1) {
64
if (rx_log.indexIn(orig_line) > -1) {
58
65
#ifndef NO_DEBUG_ON_CONSOLE
59
fprintf( stderr, "Debug: %s\n", line.toLocal8Bit().data() );
66
fprintf( stderr, "Debug: %s\n", orig_line.toLocal8Bit().data() );
61
Helper::addLog( line );
65
72
#ifndef NO_DEBUG_ON_CONSOLE
66
fprintf( stderr, "Warning: %s\n", line.toLocal8Bit().data() );
73
fprintf( stderr, "Warning: %s\n", orig_line.toLocal8Bit().data() );
68
Helper::addLog( "WARNING: " + line );
75
line2 = "WARNING: " + orig_line;
71
78
#ifndef NO_DEBUG_ON_CONSOLE
72
fprintf( stderr, "Fatal: %s\n", line.toLocal8Bit().data() );
79
fprintf( stderr, "Fatal: %s\n", orig_line.toLocal8Bit().data() );
74
Helper::addLog( "FATAL: " + line );
81
line2 = "FATAL: " + orig_line;
75
82
abort(); // deliberately core dump
76
83
case QtCriticalMsg:
77
84
#ifndef NO_DEBUG_ON_CONSOLE
78
fprintf( stderr, "Critical: %s\n", line.toLocal8Bit().data() );
85
fprintf( stderr, "Critical: %s\n", orig_line.toLocal8Bit().data() );
80
Helper::addLog( "CRITICAL: " + line );
87
line2 = "CRITICAL: " + orig_line;
91
if (line2.isEmpty()) return;
93
line2 = "["+ QTime::currentTime().toString() +"] "+ line2;
95
if (basegui_instance) {
96
if (!saved_lines.isEmpty()) {
97
// Send saved lines first
98
for (int n=0; n < saved_lines.count(); n++) {
99
basegui_instance->recordSmplayerLog(saved_lines[n]);
103
basegui_instance->recordSmplayerLog(line2);
105
// GUI is not created yet, save lines for later
106
saved_lines.append(line2);
140
class MyApplication : public QApplication
143
MyApplication ( int & argc, char ** argv ) : QApplication(argc, argv) {};
144
virtual void commitData ( QSessionManager & /*manager*/ ) {
145
// Nothing to do, let the application to close
115
149
int main( int argc, char ** argv )
117
QApplication a( argc, argv );
151
MyApplication a( argc, argv );
152
a.setQuitOnLastWindowClosed(false);
118
153
//a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
155
// Sets the config path
159
config_path = a.applicationDirPath();
161
// If a smplayer.ini exists in the app path, will use that path
162
// for the config file by default
122
163
if (QFile::exists( a.applicationDirPath() + "/smplayer.ini" ) ) {
123
ini_path = a.applicationDirPath();
124
qDebug("main: using existing %s", QString(ini_path + "/smplayer.ini").toUtf8().data());
164
config_path = a.applicationDirPath();
165
qDebug("main: using existing %s", QString(config_path + "/smplayer.ini").toUtf8().data());
126
169
QStringList args = a.arguments();
127
int pos = args.indexOf("-ini-path");
170
int pos = args.indexOf("-config-path");
128
171
if ( pos != -1) {
129
172
if (pos+1 < args.count()) {
131
ini_path = args[pos];
174
config_path = args[pos];
132
175
// Delete from list
133
176
args.removeAt(pos);
134
177
args.removeAt(pos-1);
136
printf("Error: expected parameter for -ini-path\r\n");
179
printf("Error: expected parameter for -config-path\r\n");
137
180
return SMPlayer::ErrorArgument;
144
187
//setIniPath will be set later in global_init, but we need it here
145
Helper::setIniPath(ini_path);
188
if (!config_path.isEmpty()) Paths::setConfigPath(config_path);
147
QString lock_file = Helper::iniPath() + "/smplayer_init.lock";
190
QString lock_file = Paths::iniPath() + "/smplayer_init.lock";
148
191
qDebug("main: lock_file: %s", lock_file.toUtf8().data());
150
193
#if USE_QXT_LOCKS