Changeset 121 for smplayer/vendor/current/src/main.cpp
- Timestamp:
- Mar 15, 2012, 5:14:10 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/vendor/current/src/main.cpp
r118 r121 1 1 /* smplayer, GUI front-end for mplayer. 2 Copyright (C) 2006-201 1 Ricardo Villalba <rvm@escomposlinux.org>2 Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net> 3 3 4 4 This program is free software; you can redistribute it and/or modify … … 20 20 #include <QFile> 21 21 #include <QTime> 22 #include <QDir> 22 23 23 24 #include "smplayer.h" … … 28 29 #include <stdio.h> 29 30 31 #if USE_QTLOCKEDFILE 30 32 #define USE_LOCKS 1 31 33 #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 39 36 #endif 40 37 … … 126 123 } 127 124 128 #if USE_LOCKS129 #if USE_QXT_LOCKS130 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 #else149 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 #endif156 #endif157 125 158 126 class MyApplication : public QApplication … … 214 182 qDebug("main: lock_file: %s", lock_file.toUtf8().data()); 215 183 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 } 261 206 #endif // USE_LOCKS 262 207 … … 265 210 if (c != SMPlayer::NoExit) { 266 211 #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(); 272 213 #endif 273 214 return c; … … 279 220 280 221 #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); 286 224 #endif 287 225
Note:
See TracChangeset
for help on using the changeset viewer.