Changeset 128 for smplayer/trunk/src/main.cpp
- Timestamp:
- Mar 29, 2012, 4:53:15 PM (13 years ago)
- Location:
- smplayer/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/trunk
- Property svn:mergeinfo changed
/smplayer/vendor/current merged: 127
- Property svn:mergeinfo changed
-
smplayer/trunk/src/main.cpp
r124 r128 17 17 */ 18 18 19 #include <QApplication> 20 #include <QFile> 21 #include <QTime> 22 #include <QDir> 23 19 #include "myapplication.h" 24 20 #include "smplayer.h" 25 #include "global.h"26 #include "helper.h"27 #include "paths.h"28 29 #include <stdio.h>30 31 #if USE_QTLOCKEDFILE32 #define USE_LOCKS 133 #if USE_LOCKS34 #include "qtlockedfile/qtlockedfile.h"35 #endif36 #endif37 38 using namespace Global;39 40 BaseGui * basegui_instance = 0;41 42 QFile output_log;43 44 void myMessageOutput( QtMsgType type, const char *msg ) {45 static QStringList saved_lines;46 static QString orig_line;47 static QString line2;48 static QRegExp rx_log;49 50 if (pref) {51 if (!pref->log_smplayer) return;52 rx_log.setPattern(pref->log_filter);53 } else {54 rx_log.setPattern(".*");55 }56 57 line2.clear();58 59 orig_line = QString::fromUtf8(msg);60 61 switch ( type ) {62 case QtDebugMsg:63 if (rx_log.indexIn(orig_line) > -1) {64 #ifndef NO_DEBUG_ON_CONSOLE65 fprintf( stderr, "Debug: %s\n", orig_line.toLocal8Bit().data() );66 #endif67 line2 = orig_line;68 }69 break;70 case QtWarningMsg:71 #ifndef NO_DEBUG_ON_CONSOLE72 fprintf( stderr, "Warning: %s\n", orig_line.toLocal8Bit().data() );73 #endif74 line2 = "WARNING: " + orig_line;75 break;76 case QtFatalMsg:77 #ifndef NO_DEBUG_ON_CONSOLE78 fprintf( stderr, "Fatal: %s\n", orig_line.toLocal8Bit().data() );79 #endif80 line2 = "FATAL: " + orig_line;81 abort(); // deliberately core dump82 case QtCriticalMsg:83 #ifndef NO_DEBUG_ON_CONSOLE84 fprintf( stderr, "Critical: %s\n", orig_line.toLocal8Bit().data() );85 #endif86 line2 = "CRITICAL: " + orig_line;87 break;88 }89 90 if (line2.isEmpty()) return;91 92 line2 = "["+ QTime::currentTime().toString("hh:mm:ss:zzz") +"] "+ line2;93 94 if (basegui_instance) {95 if (!saved_lines.isEmpty()) {96 // Send saved lines first97 for (int n=0; n < saved_lines.count(); n++) {98 basegui_instance->recordSmplayerLog(saved_lines[n]);99 }100 saved_lines.clear();101 }102 basegui_instance->recordSmplayerLog(line2);103 } else {104 // GUI is not created yet, save lines for later105 saved_lines.append(line2);106 }107 108 if (pref) {109 if (pref->save_smplayer_log) {110 // Save log to file111 if (!output_log.isOpen()) {112 // FIXME: the config path may not be initialized if USE_LOCKS is not defined113 output_log.setFileName( Paths::configPath() + "/smplayer_log.txt" );114 output_log.open(QIODevice::WriteOnly);115 }116 if (output_log.isOpen()) {117 QString l = line2 + "\r\n";118 output_log.write(l.toUtf8().constData());119 output_log.flush();120 }121 }122 }123 }124 125 126 class MyApplication : public QApplication127 {128 public:129 MyApplication ( int & argc, char ** argv ) : QApplication(argc, argv) {};130 virtual void commitData ( QSessionManager & /*manager*/ ) {131 // Nothing to do, let the application to close132 }133 };134 21 135 22 int main( int argc, char ** argv ) 136 23 { 137 MyApplication a( argc, argv ); 24 MyApplication a( "smplayer", argc, argv ); 25 /* 26 if (a.isRunning()) { 27 qDebug("Another instance is running. Exiting."); 28 return 0; 29 } 30 */ 31 138 32 a.setQuitOnLastWindowClosed(false); 139 //a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );140 33 141 34 #if QT_VERSION >= 0x040400 … … 173 66 } 174 67 175 qInstallMsgHandler( myMessageOutput );176 177 #if USE_LOCKS178 //setIniPath will be set later in global_init, but we need it here179 if (!config_path.isEmpty()) Paths::setConfigPath(config_path);180 181 QString lock_file = Paths::iniPath() + "/smplayer_init.lock";182 qDebug("main: lock_file: %s", lock_file.toUtf8().data());183 184 QtLockedFile lk(lock_file);185 lk.open(QFile::ReadWrite);186 187 if (QDir().exists(Paths::iniPath())) {188 bool lock_ok = lk.lock(QtLockedFile::WriteLock, false);189 190 if (!lock_ok) {191 //lock failed192 qDebug("main: lock failed");193 194 // Wait 10 secs max.195 int n = 100;196 while ( n > 0) {197 Helper::msleep(100); // wait 100 ms198 199 if (lk.lock(QtLockedFile::WriteLock, false)) break;200 n--;201 if ((n % 10) == 0) qDebug("main: waiting %d...", n);202 }203 // Continue startup204 }205 }206 #endif // USE_LOCKS207 208 68 SMPlayer * smplayer = new SMPlayer(config_path); 209 69 SMPlayer::ExitCode c = smplayer->processArgs( args ); 210 70 if (c != SMPlayer::NoExit) { 211 #if USE_LOCKS212 lk.unlock();213 #endif214 71 return c; 215 72 } 216 217 basegui_instance = smplayer->gui();218 a.connect(smplayer->gui(), SIGNAL(quitSolicited()), &a, SLOT(quit()));219 73 smplayer->start(); 220 221 #if USE_LOCKS222 bool success = lk.unlock();223 qDebug("Unlocking: %d", success);224 #endif225 74 226 75 int r = a.exec(); 227 76 228 basegui_instance = 0;229 77 delete smplayer; 230 231 if (output_log.isOpen()) output_log.close();232 78 233 79 return r;
Note:
See TracChangeset
for help on using the changeset viewer.