1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2009 Ricardo Villalba <rvm@escomposlinux.org>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include <QApplication>
30
#include <windows.h> // For the screensaver stuff
41
class Sleeper : public QThread
44
static void sleep(unsigned long secs) {QThread::sleep(secs);}
45
static void msleep(unsigned long msecs) {
46
//qDebug("sleeping...");
47
QThread::msleep(msecs);
50
static void usleep(unsigned long usecs) {QThread::usleep(usecs);}
55
QString Helper::dvdForPref(const QString & dvd_id, int title) {
56
return QString("DVD_%1_%2").arg(dvd_id).arg(title);
60
QString Helper::formatTime(int secs) {
62
int hours = (int) t / 3600;
64
int minutes = (int) t / 60;
69
return tf.sprintf("%02d:%02d:%02d",hours,minutes,seconds);
72
QString Helper::timeForJumps(int secs) {
73
int minutes = (int) secs / 60;
74
int seconds = secs % 60;
77
return QObject::tr("%1 second(s)", "", seconds).arg(seconds);
80
return QObject::tr("%1 minute(s)", "", minutes).arg(minutes);
82
QString m = QObject::tr("%1 minute(s)", "", minutes).arg(minutes);
83
QString s = QObject::tr("%1 second(s)", "", seconds).arg(seconds);
84
return QObject::tr("%1 and %2").arg(m).arg(s);
90
// This function has been copied (and modified a little bit) from Scribus (program under GPL license):
91
// http://docs.scribus.net/devel/util_8cpp-source.html#l00112
92
QString Helper::shortPathName(QString long_path) {
93
if ((QSysInfo::WindowsVersion >= QSysInfo::WV_NT) && (QFile::exists(long_path))) {
94
QString short_path = long_path;
96
const int max_path = 4096;
97
WCHAR shortName[max_path];
99
QString nativePath = QDir::convertSeparators(long_path);
100
int ret = GetShortPathNameW((LPCWSTR) nativePath.utf16(), shortName, max_path);
101
if (ret != ERROR_INVALID_PARAMETER && ret < MAX_PATH)
102
short_path = QString::fromUtf16((const ushort*) shortName);
111
void Helper::setScreensaverEnabled(bool b) {
112
qDebug("Helper::setScreensaverEnabled: %d", b);
115
// Activate screensaver
116
SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, true, 0, SPIF_SENDWININICHANGE);
117
SystemParametersInfo( SPI_SETLOWPOWERACTIVE, 1, NULL, 0);
118
SystemParametersInfo( SPI_SETPOWEROFFACTIVE, 1, NULL, 0);
120
SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, false, 0, SPIF_SENDWININICHANGE);
121
SystemParametersInfo( SPI_SETLOWPOWERACTIVE, 0, NULL, 0);
122
SystemParametersInfo( SPI_SETPOWEROFFACTIVE, 0, NULL, 0);
128
void Helper::msleep(int ms) {
130
//qDebug("Helper::msleep: %d (using usleep)", ms);
133
//qDebug("Helper::msleep: %d (using QThread::msleep)", ms);
134
Sleeper::msleep( ms );
138
QString Helper::changeSlashes(QString filename) {
139
// Only change if file exists (it's a local file)
140
if (QFileInfo(filename).exists())
141
return filename.replace('/', '\\');
146
bool Helper::directoryContainsDVD(QString directory) {
147
//qDebug("Helper::directoryContainsDVD: '%s'", directory.latin1());
150
QStringList l = dir.entryList();
152
for (int n=0; n < l.count(); n++) {
153
//qDebug(" * entry %d: '%s'", n, l[n].toUtf8().data());
154
if (l[n].toLower() == "video_ts") valid = TRUE;
160
int Helper::qtVersion() {
161
QRegExp rx("(\\d+)\\.(\\d+)\\.(\\d+)");
162
QString v(qVersion());
166
if (rx.indexIn(v) > -1) {
167
int n1 = rx.cap(1).toInt();
168
int n2 = rx.cap(2).toInt();
169
int n3 = rx.cap(3).toInt();
170
r = n1 * 1000 + n2 * 100 + n3;
173
qDebug("Helper::qtVersion: %d", r);
178
QString Helper::equalizerListToString(AudioEqualizerList values) {
179
double v0 = (double) values[0].toInt() / 10;
180
double v1 = (double) values[1].toInt() / 10;
181
double v2 = (double) values[2].toInt() / 10;
182
double v3 = (double) values[3].toInt() / 10;
183
double v4 = (double) values[4].toInt() / 10;
184
double v5 = (double) values[5].toInt() / 10;
185
double v6 = (double) values[6].toInt() / 10;
186
double v7 = (double) values[7].toInt() / 10;
187
double v8 = (double) values[8].toInt() / 10;
188
double v9 = (double) values[9].toInt() / 10;
189
QString s = QString::number(v0) + ":" + QString::number(v1) + ":" +
190
QString::number(v2) + ":" + QString::number(v3) + ":" +
191
QString::number(v4) + ":" + QString::number(v5) + ":" +
192
QString::number(v6) + ":" + QString::number(v7) + ":" +
193
QString::number(v8) + ":" + QString::number(v9);
198
QStringList Helper::searchForConsecutiveFiles(const QString & initial_file) {
199
qDebug("Helper::searchForConsecutiveFiles: initial_file: '%s'", initial_file.toUtf8().constData());
201
QStringList files_to_add;
203
QFileInfo fi(initial_file);
204
QString basename = fi.completeBaseName();
205
QString extension = fi.suffix();
206
QString path = fi.absolutePath();
208
QRegExp rx("^.*(\\d+)");
210
if ( rx.indexIn(basename) > -1) {
211
int digits = rx.cap(1).length();
212
int current_number = rx.cap(1).toInt();
214
//qDebug("Helper::searchForConsecutiveFiles: filename ends with a number (%s)", rx.cap(1).toUtf8().constData());
215
qDebug("Helper::searchForConsecutiveFiles: filename ends with a number (%d)", current_number);
216
qDebug("Helper::searchForConsecutiveFiles: trying to find consecutive files");
218
QString template_name = path + "/" + basename.left(basename.length() - digits);
219
//qDebug("BaseGui::newMediaLoaded: name without digits: '%s'", template_name.toUtf8().constData());
222
QString next_name = template_name + QString("%1").arg(current_number, digits, 10, QLatin1Char('0')) +"."+ extension;
223
qDebug("Helper::searchForConsecutiveFiles: looking for '%s'", next_name.toUtf8().constData());
225
while (QFile::exists(next_name)) {
226
qDebug("Helper::searchForConsecutiveFiles: '%s' exists, added to the list", next_name.toUtf8().constData());
227
files_to_add.append(next_name);
229
next_name = template_name + QString("%1").arg(current_number, digits, 10, QLatin1Char('0')) +"."+ extension;
230
qDebug("Helper::searchForConsecutiveFiles: looking for '%s'", next_name.toUtf8().constData());