~ubuntu-branches/debian/sid/smplayer/sid

« back to all changes in this revision

Viewing changes to src/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2009-03-31 23:05:43 UTC
  • mto: (1.1.9 upstream) (3.1.2 squeeze)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090331230543-nsklbxenl2hf2n6h
Tags: upstream-0.6.7
ImportĀ upstreamĀ versionĀ 0.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
3
3
 
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
23
23
#include "smplayer.h"
24
24
#include "global.h"
25
25
#include "helper.h"
 
26
#include "paths.h"
26
27
 
27
28
#include <stdio.h>
28
29
 
39
40
 
40
41
using namespace Global;
41
42
 
 
43
BaseGui * basegui_instance = 0;
 
44
 
42
45
void myMessageOutput( QtMsgType type, const char *msg ) {
 
46
        static QStringList saved_lines;
 
47
        static QString orig_line;
 
48
        static QString line2;
43
49
        static QRegExp rx_log;
44
50
 
45
51
        if (pref) {
49
55
                rx_log.setPattern(".*");
50
56
        }
51
57
 
52
 
        QString line = "["+ QTime::currentTime().toString() + "] " + 
53
 
                   QString::fromUtf8(msg);
 
58
        line2.clear();
 
59
 
 
60
        orig_line = QString::fromUtf8(msg);
54
61
 
55
62
        switch ( type ) {
56
63
                case QtDebugMsg:
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() );
60
67
                                #endif
61
 
                                Helper::addLog( line );
 
68
                                line2 = orig_line;
62
69
                        }
63
70
                        break;
64
71
                case QtWarningMsg:
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() );
67
74
                        #endif
68
 
                        Helper::addLog( "WARNING: " + line );
 
75
                        line2 = "WARNING: " + orig_line;
69
76
                        break;
70
77
                case QtFatalMsg:
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() );
73
80
                        #endif
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() );
79
86
                        #endif
80
 
                        Helper::addLog( "CRITICAL: " + line );
 
87
                        line2 = "CRITICAL: " + orig_line;
81
88
                        break;
82
89
        }
 
90
 
 
91
        if (line2.isEmpty()) return;
 
92
 
 
93
        line2 = "["+ QTime::currentTime().toString() +"] "+ line2;
 
94
 
 
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]);
 
100
                        }
 
101
                        saved_lines.clear();
 
102
                }
 
103
                basegui_instance->recordSmplayerLog(line2);
 
104
        } else {
 
105
                // GUI is not created yet, save lines for later
 
106
                saved_lines.append(line2);
 
107
        }
83
108
}
84
109
 
85
110
#if USE_LOCKS
112
137
#endif
113
138
#endif
114
139
 
 
140
class MyApplication : public QApplication
 
141
{
 
142
public:
 
143
        MyApplication ( int & argc, char ** argv ) : QApplication(argc, argv) {};
 
144
        virtual void commitData ( QSessionManager & /*manager*/ ) {
 
145
                // Nothing to do, let the application to close
 
146
        }
 
147
};
 
148
 
115
149
int main( int argc, char ** argv ) 
116
150
{
117
 
        QApplication a( argc, argv );
 
151
        MyApplication a( argc, argv );
 
152
        a.setQuitOnLastWindowClosed(false);
118
153
        //a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
119
154
 
120
 
        // Sets the ini_path
121
 
        QString ini_path;
 
155
        // Sets the config path
 
156
        QString config_path;
 
157
 
 
158
#ifdef PORTABLE_APP
 
159
        config_path = a.applicationDirPath();
 
160
#else
 
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());
125
 
    }
 
164
                config_path = a.applicationDirPath();
 
165
                qDebug("main: using existing %s", QString(config_path + "/smplayer.ini").toUtf8().data());
 
166
        }
 
167
#endif
 
168
 
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()) {
130
173
                        pos++;
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);
135
178
                } else {
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;
138
181
                }
139
182
        }
142
185
 
143
186
#if USE_LOCKS
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);
146
189
 
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());
149
192
 
150
193
#if USE_QXT_LOCKS
194
237
#endif // USE_QXT_LOCKS
195
238
#endif // USE_LOCKS
196
239
 
197
 
        SMPlayer * smplayer = new SMPlayer(ini_path);
 
240
        SMPlayer * smplayer = new SMPlayer(config_path);
198
241
        SMPlayer::ExitCode c = smplayer->processArgs( args );
199
242
        if (c != SMPlayer::NoExit) {
200
243
#if USE_LOCKS
207
250
                return c;
208
251
        }
209
252
 
 
253
        basegui_instance = smplayer->gui();
210
254
        a.connect(smplayer->gui(), SIGNAL(quitSolicited()), &a, SLOT(quit()));
211
255
        smplayer->start();
212
256
 
220
264
 
221
265
        int r = a.exec();
222
266
 
 
267
        basegui_instance = 0;
223
268
        delete smplayer;
224
269
 
225
270
        return r;