~ubuntu-branches/debian/experimental/smplayer/experimental

« back to all changes in this revision

Viewing changes to src/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2009-01-03 17:08:06 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090103170806-eodntb2slv6g2pb6
Tags: 0.6.6-0ubuntu1
* The "just before FF" release.
* New upstream release.
* debian/control: Bumped Standards-Version to 3.8.0.
* debian/copyright: Changed (C) to © to fix Lintian warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 );
118
152
        //a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
119
153
 
120
 
        // Sets the ini_path
121
 
        QString ini_path;
 
154
        // Sets the config path
 
155
        QString config_path;
 
156
 
 
157
#ifdef PORTABLE_APP
 
158
        config_path = a.applicationDirPath();
 
159
#else
 
160
        // If a smplayer.ini exists in the app path, will use that path
 
161
        // for the config file by default
122
162
        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
 
    }
 
163
                config_path = a.applicationDirPath();
 
164
                qDebug("main: using existing %s", QString(config_path + "/smplayer.ini").toUtf8().data());
 
165
        }
 
166
#endif
 
167
 
126
168
        QStringList args = a.arguments();
127
 
        int pos = args.indexOf("-ini-path");
 
169
        int pos = args.indexOf("-config-path");
128
170
        if ( pos != -1) {
129
171
                if (pos+1 < args.count()) {
130
172
                        pos++;
131
 
                        ini_path = args[pos];
 
173
                        config_path = args[pos];
132
174
                        // Delete from list
133
175
                        args.removeAt(pos);
134
176
                        args.removeAt(pos-1);
135
177
                } else {
136
 
                        printf("Error: expected parameter for -ini-path\r\n");
 
178
                        printf("Error: expected parameter for -config-path\r\n");
137
179
                        return SMPlayer::ErrorArgument;
138
180
                }
139
181
        }
142
184
 
143
185
#if USE_LOCKS
144
186
        //setIniPath will be set later in global_init, but we need it here
145
 
        Helper::setIniPath(ini_path);
 
187
        if (!config_path.isEmpty()) Paths::setConfigPath(config_path);
146
188
 
147
 
        QString lock_file = Helper::iniPath() + "/smplayer_init.lock";
 
189
        QString lock_file = Paths::iniPath() + "/smplayer_init.lock";
148
190
        qDebug("main: lock_file: %s", lock_file.toUtf8().data());
149
191
 
150
192
#if USE_QXT_LOCKS
194
236
#endif // USE_QXT_LOCKS
195
237
#endif // USE_LOCKS
196
238
 
197
 
        SMPlayer * smplayer = new SMPlayer(ini_path);
 
239
        SMPlayer * smplayer = new SMPlayer(config_path);
198
240
        SMPlayer::ExitCode c = smplayer->processArgs( args );
199
241
        if (c != SMPlayer::NoExit) {
200
242
#if USE_LOCKS
207
249
                return c;
208
250
        }
209
251
 
 
252
        basegui_instance = smplayer->gui();
210
253
        a.connect(smplayer->gui(), SIGNAL(quitSolicited()), &a, SLOT(quit()));
211
254
        smplayer->start();
212
255
 
220
263
 
221
264
        int r = a.exec();
222
265
 
 
266
        basegui_instance = 0;
223
267
        delete smplayer;
224
268
 
225
269
        return r;