diff options
author | Maia Kozheva <sikon@ubuntu.com> | 2012-04-09 13:30:23 +0700 |
---|---|---|
committer | Maia Kozheva <sikon@ubuntu.com> | 2012-04-09 13:30:23 +0700 |
commit | 69d32924ffbfe2bb05d881a23af13b6070b9a9bd (patch) | |
tree | 15d9f808ef672e21bcf2da9b6c9fc8e48e157eff /src/main.cpp | |
parent | 65a64d260e05c7bf8d3bdf82e796637dc820e574 (diff) |
Imported Upstream version 0.8.0
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 167 |
1 files changed, 8 insertions, 159 deletions
diff --git a/src/main.cpp b/src/main.cpp index b9c64fb..e9c387e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,126 +16,20 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <QApplication> -#include <QFile> -#include <QTime> - +#include "myapplication.h" #include "smplayer.h" -#include "global.h" -#include "helper.h" -#include "paths.h" - -#include <stdio.h> - -#if USE_QTLOCKEDFILE -#define USE_LOCKS 1 -#if USE_LOCKS -#include "qtlockedfile/qtlockedfile.h" -#endif -#endif - -using namespace Global; - -BaseGui * basegui_instance = 0; - -QFile output_log; - -void myMessageOutput( QtMsgType type, const char *msg ) { - static QStringList saved_lines; - static QString orig_line; - static QString line2; - static QRegExp rx_log; - - if (pref) { - if (!pref->log_smplayer) return; - rx_log.setPattern(pref->log_filter); - } else { - rx_log.setPattern(".*"); - } - line2.clear(); - - orig_line = QString::fromUtf8(msg); - - switch ( type ) { - case QtDebugMsg: - if (rx_log.indexIn(orig_line) > -1) { - #ifndef NO_DEBUG_ON_CONSOLE - fprintf( stderr, "Debug: %s\n", orig_line.toLocal8Bit().data() ); - #endif - line2 = orig_line; - } - break; - case QtWarningMsg: - #ifndef NO_DEBUG_ON_CONSOLE - fprintf( stderr, "Warning: %s\n", orig_line.toLocal8Bit().data() ); - #endif - line2 = "WARNING: " + orig_line; - break; - case QtFatalMsg: - #ifndef NO_DEBUG_ON_CONSOLE - fprintf( stderr, "Fatal: %s\n", orig_line.toLocal8Bit().data() ); - #endif - line2 = "FATAL: " + orig_line; - abort(); // deliberately core dump - case QtCriticalMsg: - #ifndef NO_DEBUG_ON_CONSOLE - fprintf( stderr, "Critical: %s\n", orig_line.toLocal8Bit().data() ); - #endif - line2 = "CRITICAL: " + orig_line; - break; - } - - if (line2.isEmpty()) return; - - line2 = "["+ QTime::currentTime().toString("hh:mm:ss:zzz") +"] "+ line2; - - if (basegui_instance) { - if (!saved_lines.isEmpty()) { - // Send saved lines first - for (int n=0; n < saved_lines.count(); n++) { - basegui_instance->recordSmplayerLog(saved_lines[n]); - } - saved_lines.clear(); - } - basegui_instance->recordSmplayerLog(line2); - } else { - // GUI is not created yet, save lines for later - saved_lines.append(line2); - } - - if (pref) { - if (pref->save_smplayer_log) { - // Save log to file - if (!output_log.isOpen()) { - // FIXME: the config path may not be initialized if USE_LOCKS is not defined - output_log.setFileName( Paths::configPath() + "/smplayer_log.txt" ); - output_log.open(QIODevice::WriteOnly); - } - if (output_log.isOpen()) { - QString l = line2 + "\r\n"; - output_log.write(l.toUtf8().constData()); - output_log.flush(); - } - } - } -} - - -class MyApplication : public QApplication +int main( int argc, char ** argv ) { -public: - MyApplication ( int & argc, char ** argv ) : QApplication(argc, argv) {}; - virtual void commitData ( QSessionManager & /*manager*/ ) { - // Nothing to do, let the application to close + MyApplication a( "smplayer", argc, argv ); + /* + if (a.isRunning()) { + qDebug("Another instance is running. Exiting."); + return 0; } -}; + */ -int main( int argc, char ** argv ) -{ - MyApplication a( argc, argv ); a.setQuitOnLastWindowClosed(false); - //a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) ); #if QT_VERSION >= 0x040400 // Enable icons in menus @@ -171,62 +65,17 @@ int main( int argc, char ** argv ) } } - qInstallMsgHandler( myMessageOutput ); - -#if USE_LOCKS - //setIniPath will be set later in global_init, but we need it here - if (!config_path.isEmpty()) Paths::setConfigPath(config_path); - - QString lock_file = Paths::iniPath() + "/smplayer_init.lock"; - qDebug("main: lock_file: %s", lock_file.toUtf8().data()); - - QtLockedFile lk(lock_file); - lk.open(QFile::ReadWrite); - - bool lock_ok = lk.lock(QtLockedFile::WriteLock, false); - - if (!lock_ok) { - //lock failed - qDebug("main: lock failed"); - - // Wait 10 secs max. - int n = 100; - while ( n > 0) { - Helper::msleep(100); // wait 100 ms - - if (lk.lock(QtLockedFile::WriteLock, false)) break; - n--; - if ((n % 10) == 0) qDebug("main: waiting %d...", n); - } - // Continue startup - } -#endif // USE_LOCKS - SMPlayer * smplayer = new SMPlayer(config_path); SMPlayer::ExitCode c = smplayer->processArgs( args ); if (c != SMPlayer::NoExit) { -#if USE_LOCKS - lk.unlock(); -#endif return c; } - - basegui_instance = smplayer->gui(); - a.connect(smplayer->gui(), SIGNAL(quitSolicited()), &a, SLOT(quit())); smplayer->start(); -#if USE_LOCKS - bool success = lk.unlock(); - qDebug("Unlocking: %d", success); -#endif - int r = a.exec(); - basegui_instance = 0; delete smplayer; - if (output_log.isOpen()) output_log.close(); - return r; } |