src/ytchannel.h \
src/yt3.h \
src/paginatedvideosource.h \
- src/compatibility/qurlqueryhelper.h
+ src/compatibility/qurlqueryhelper.h \
+ src/compatibility/pathsservice.h
SOURCES += src/main.cpp \
src/searchlineedit.cpp \
src/urllineedit.cpp \
src/yt3listparser.cpp \
src/ytchannel.cpp \
src/yt3.cpp \
- src/paginatedvideosource.cpp
+ src/paginatedvideosource.cpp \
+ src/compatibility/pathsservice.cpp
RESOURCES += resources.qrc
DESTDIR = build/target/
OBJECTS_DIR = build/obj/
--- /dev/null
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2015, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube. If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
+#include "pathsservice.h"
+
+#include <QDesktopServices>
+
+namespace {
+
+#if QT_VERSION >= 0x050000
+typedef QStandardPaths PathProvider;
+
+#define getLocation writableLocation
+#else
+typedef QDesktopServices PathProvider;
+
+#define getLocation storageLocation
+#endif // QT_VERSION >= 0x050000
+
+} // namespace
+
+namespace Paths {
+QString getMoviesLocation() {
+ return PathProvider::getLocation(PathProvider::MoviesLocation);
+}
+
+QString getDesktopLocation() {
+ return PathProvider::getLocation(PathProvider::DesktopLocation);
+}
+
+QString getHomeLocation() {
+ return PathProvider::getLocation(PathProvider::HomeLocation);
+}
+
+QString getDataLocation() {
+ return PathProvider::getLocation(PathProvider::DataLocation);
+}
+
+QString getPicturesLocation() {
+ return PathProvider::getLocation(PathProvider::PicturesLocation);
+}
+
+QString getTempLocation() {
+ return PathProvider::getLocation(PathProvider::TempLocation);
+}
+}
--- /dev/null
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2015, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube. If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
+#ifndef PATHSSERVICE_H
+#define PATHSSERVICE_H
+
+#include <QtGlobal>
+
+namespace Paths {
+QString getMoviesLocation();
+QString getDesktopLocation();
+QString getHomeLocation();
+QString getDataLocation();
+QString getPicturesLocation();
+QString getTempLocation();
+}
+
+#endif // PATHSSERVICE_H
#include "database.h"
#include "constants.h"
-#include <QDesktopServices>
+#include "compatibility/pathsservice.h"
+#include <QtDebug>
static const int DATABASE_VERSION = 1;
static const QString dbName = QLatin1String(Constants::UNIX_NAME) + ".db";
static Database *databaseInstance = 0;
Database::Database() {
-#if QT_VERSION >= 0x050000
- QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
-#else
- QString dataLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
-#endif
+ QString dataLocation = Paths::getDataLocation();
- QDir().mkpath(dataLocation);
+ if (!QDir().mkpath(dataLocation)) {
+ qCritical() << "Failed to create directory " << dataLocation;
+ }
dbLocation = dataLocation + "/" + dbName;
QMutexLocker locker(&lock);
+ QString::number(DATABASE_VERSION) + ")", db);
}
+// static
QString Database::getDbLocation() {
-#if QT_VERSION >= 0x050000
- static const QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
-#else
- static const QString dataLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
-#endif
- return dataLocation + "/" + dbName;
+ return Paths::getDataLocation() + "/" + dbName;
}
+// static
bool Database::exists() {
static bool fileExists = false;
if (!fileExists)
return fileExists;
}
+// static
Database& Database::instance() {
static QMutex mutex;
QMutexLocker locker(&mutex);
#include "extra.h"
#endif
#include "datautils.h"
+#include "compatibility/pathsservice.h"
static DownloadManager *downloadManagerInstance = 0;
QString DownloadManager::defaultDownloadFolder() {
// download in the Movies system folder
-#if QT_VERSION >= 0x050000
- QString path = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
-#else
- QString path = QDesktopServices::storageLocation(QDesktopServices::MoviesLocation);
-#endif
+ QString path = Paths::getMoviesLocation();
- QDir moviesDir(path);
+ const QDir moviesDir(path);
if (!moviesDir.exists()) {
// fallback to Desktop
-#if QT_VERSION >= 0x050000
- path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
-#else
- path = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
-#endif
+ path = Paths::getDesktopLocation();
- QDir desktopDir(path);
+ const QDir desktopDir(path);
if (!desktopDir.exists()) {
// fallback to Home
-#if QT_VERSION >= 0x050000
- path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
-#else
- path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
-#endif
+ path = Paths::getHomeLocation();
}
}
return path;
#include "downloadsettings.h"
#include "downloadmanager.h"
#include "mainwindow.h"
+#include "compatibility/pathsservice.h"
DownloadSettings::DownloadSettings(QWidget *parent) : QWidget(parent) {
}
void DownloadSettings::changeFolder() {
- QString path;
+ const QString path = Paths::getHomeLocation();
#ifdef APP_MAC
QFileDialog* dialog = new QFileDialog(this);
dialog->setFileMode(QFileDialog::Directory);
dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
-#if QT_VERSION >= 0x050000
- path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
-#else
- path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
-#endif
dialog->setDirectory(path);
dialog->open(this, SLOT(folderChosen(const QString &)));
#else
-#if QT_VERSION >= 0x050000
- path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
-#else
- path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
-#endif
QString folder = QFileDialog::getExistingDirectory(window(), tr("Choose the download location"),
path,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
}
void DownloadSettings::updateMessage() {
- QString path = DownloadManager::instance()->currentDownloadFolder();
-#if QT_VERSION >= 0x050000
- QString home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
-#else
- QString home = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
-#endif
+ const QString path = DownloadManager::instance()->currentDownloadFolder();
+ const QString home = Paths::getHomeLocation();
QString displayPath = path;
displayPath = displayPath.remove(home + "/");
message->setText(
#include "jsfunctions.h"
#include "networkaccess.h"
-#include <QDesktopServices>
#include "constants.h"
#include "compatibility/qurlqueryhelper.h"
+#include "compatibility/pathsservice.h"
namespace The {
NetworkAccess* http();
}
QString JsFunctions::jsPath() {
- return QString(
- #if QT_VERSION >= 0x050000
- QStandardPaths::writableLocation(QStandardPaths::DataLocation)
- #else
- QDesktopServices::storageLocation(QDesktopServices::DataLocation)
- #endif
- + "/" + jsFilename());
+ return Paths::getDataLocation() + "/" + jsFilename();
}
void JsFunctions::loadJs() {
#include "snapshotsettings.h"
#include "mainwindow.h"
-#include <QDesktopServices>
#ifdef APP_MAC
#include "macutils.h"
#endif
#include "constants.h"
+#include "compatibility/pathsservice.h"
+#include <QDesktopServices>
SnapshotSettings::SnapshotSettings(QWidget *parent) : QWidget(parent) {
QBoxLayout *layout = new QHBoxLayout(this);
QSettings settings;
QString location = settings.value("snapshotsFolder").toString();
if (location.isEmpty() || !QFile::exists(location)) {
-#if QT_VERSION >= 0x050000
- location = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
-#else
- location = QDesktopServices::storageLocation(QDesktopServices::PicturesLocation);
-#endif
+ location = Paths::getPicturesLocation();
#ifdef APP_MAC_STORE
location += "/MinitubeforYouTube";
#endif
return QDir(path).dirName();
#endif
-#if QT_VERSION >= 0x050000
- QString home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
-#else
- QString home = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
-#endif
+ const QString home = Paths::getHomeLocation();
QString displayPath = path;
displayPath = displayPath.remove(home + "/");
return displayPath;
}
void SnapshotSettings::changeFolder() {
- QString path;
+ const QString path = Paths::getHomeLocation();
#ifdef APP_MAC
QFileDialog* dialog = new QFileDialog(this);
dialog->setFileMode(QFileDialog::Directory);
dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
-#if QT_VERSION >= 0x050000
- path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
-#else
- path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
-#endif
dialog->setDirectory(path);
dialog->open(this, SLOT(folderChosen(const QString &)));
#else
-
-#if QT_VERSION >= 0x050000
- path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
-#else
- path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
-#endif
QString folder = QFileDialog::getExistingDirectory(window(), QString(),
path,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
#include "temporary.h"
#include "constants.h"
+#include "compatibility/pathsservice.h"
static QList<QString> paths;
#ifdef Q_OS_LINUX
Temporary::Temporary() { }
QString Temporary::filename() {
-#if QT_VERSION >= 0x050000
- static const QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
-#else
- static const QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
-#endif
+ static const QString tempDir = Paths::getTempLocation();
QString tempFile = tempDir + "/" + Constants::UNIX_NAME + "-" + QString::number(qrand());
#include <QtScript>
#endif
#include "compatibility/qurlqueryhelper.h"
+#include "compatibility/pathsservice.h"
namespace The {
NetworkAccess* http();
}
const QString & YTChannel::getThumbnailDir() {
- static const QString thumbDir =
- #if QT_VERSION >= 0x050000
- QStandardPaths::writableLocation(QStandardPaths::DataLocation)
- #else
- QDesktopServices::storageLocation(QDesktopServices::DataLocation)
- #endif
- + "/channels/";
+ static const QString thumbDir = Paths::getDataLocation() + "/channels/";
return thumbDir;
}