Ignore:
Timestamp:
Mar 15, 2012, 5:14:10 PM (13 years ago)
Author:
Silvan Scherrer
Message:

SMPlayer 0.7.1: vendor update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • smplayer/vendor/current/src/main.cpp

    r118 r121  
    11/*  smplayer, GUI front-end for mplayer.
    2     Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org>
     2    Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
    33
    44    This program is free software; you can redistribute it and/or modify
     
    2020#include <QFile>
    2121#include <QTime>
     22#include <QDir>
    2223
    2324#include "smplayer.h"
     
    2829#include <stdio.h>
    2930
     31#if USE_QTLOCKEDFILE
    3032#define USE_LOCKS 1
    3133#if USE_LOCKS
    32 #ifdef USE_QXT
    33 #define USE_QXT_LOCKS 1
    34 #endif // USE_QXT
    35 #endif // USE_LOCKS
    36 
    37 #if USE_LOCKS && USE_QXT_LOCKS
    38 #include <QxtFileLock>
     34#include "qtlockedfile/qtlockedfile.h"
     35#endif
    3936#endif
    4037
     
    126123}
    127124
    128 #if USE_LOCKS
    129 #if USE_QXT_LOCKS
    130 bool create_lock(QFile * f, QxtFileLock * lock) {
    131         bool success = false;
    132         if (f->open(QIODevice::ReadWrite)) {
    133                 if (lock->lock()) {
    134                         f->write("smplayer lock file");
    135                         success = true;
    136                 }
    137         }
    138         if (!success) f->close();
    139         return success;
    140 }
    141 
    142 void clean_lock(QFile * f, QxtFileLock * lock) {
    143         qDebug("main: clean_lock: %s", f->fileName().toUtf8().data());
    144         lock->unlock();
    145         f->close();
    146         f->remove();
    147 }
    148 #else
    149 void remove_lock(QString lock_file) {
    150         if (QFile::exists(lock_file)) {
    151                 qDebug("main: remove_lock: %s", lock_file.toUtf8().data());
    152                 QFile::remove(lock_file);
    153         }
    154 }
    155 #endif
    156 #endif
    157125
    158126class MyApplication : public QApplication
     
    214182        qDebug("main: lock_file: %s", lock_file.toUtf8().data());
    215183
    216 #if USE_QXT_LOCKS
    217         QFile f(lock_file);
    218         QxtFileLock write_lock(&f, 0x10, 30, QxtFileLock::WriteLock);
    219 
    220         bool lock_ok = create_lock(&f, &write_lock);
    221 
    222         if (!lock_ok) {
    223                 //lock failed
    224                 qDebug("main: lock failed");
    225 
    226                 // Wait 10 secs max.
    227                 int n = 100;
    228                 while ( n > 0) {
    229                         Helper::msleep(100); // wait 100 ms
    230                         //if (!QFile::exists(lock_file)) break;
    231                         if (create_lock(&f, &write_lock)) break;
    232                         n--;
    233                         if ((n % 10) == 0) qDebug("main: waiting %d...", n);
    234                 }
    235                 // Continue startup
    236         }
    237 #else
    238         if (QFile::exists(lock_file)) {
    239                 qDebug("main: %s exists, waiting...", lock_file.toUtf8().data());
    240                 // Wait 10 secs max.
    241                 int n = 100;
    242                 while ( n > 0) {
    243                         Helper::msleep(100); // wait 100 ms
    244                         if (!QFile::exists(lock_file)) break;
    245                         n--;
    246                         if ((n % 10) == 0) qDebug("main: waiting %d...", n);
    247                 }
    248                 remove_lock(lock_file);
    249         } else {
    250                 // Create lock file
    251                 QFile f(lock_file);
    252                 if (f.open(QIODevice::WriteOnly)) {
    253                         f.write("smplayer lock file");
    254                         f.close();
    255                 } else {
    256                         qWarning("main: can't open %s for writing", lock_file.toUtf8().data());
    257                 }
    258                
    259         }
    260 #endif // USE_QXT_LOCKS
     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 failed
     192                        qDebug("main: lock failed");
     193
     194                        // Wait 10 secs max.
     195                        int n = 100;
     196                        while ( n > 0) {
     197                                Helper::msleep(100); // wait 100 ms
     198
     199                                if (lk.lock(QtLockedFile::WriteLock, false)) break;
     200                                n--;
     201                                if ((n % 10) == 0) qDebug("main: waiting %d...", n);
     202                        }
     203                        // Continue startup
     204                }
     205        }
    261206#endif // USE_LOCKS
    262207
     
    265210        if (c != SMPlayer::NoExit) {
    266211#if USE_LOCKS
    267 #if USE_QXT_LOCKS
    268                 clean_lock(&f, &write_lock);
    269 #else
    270                 remove_lock(lock_file);
    271 #endif
     212                lk.unlock();
    272213#endif
    273214                return c;
     
    279220
    280221#if USE_LOCKS
    281 #if USE_QXT_LOCKS
    282         clean_lock(&f, &write_lock);
    283 #else
    284         remove_lock(lock_file);
    285 #endif
     222        bool success = lk.unlock();
     223        qDebug("Unlocking: %d", success);
    286224#endif
    287225
Note: See TracChangeset for help on using the changeset viewer.