StandardPaths class for Qt4, SyncFramework deleted for a future rewrite

This commit is contained in:
Rafael 2016-03-28 12:23:50 +02:00
parent b280ce1423
commit bfa84a5e99
8 changed files with 61 additions and 170 deletions

View file

@ -16,24 +16,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "StandardPaths.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#ifdef QT5_MODE
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif
CrewDatabase::CrewDatabase(QObject *parent) : QObject(parent) CrewDatabase::CrewDatabase(QObject *parent) : QObject(parent)
{ {
QDir dir; QDir dir;
#ifdef QT5_MODE dir.setPath(StandardPaths::writableLocation(StandardPaths::DataLocation));
dir.setPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
#else
dir.setPath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
#endif
dir.mkdir("../gta5sync"); dir.mkdir("../gta5sync");
QString dirPath = dir.absolutePath(); QString dirPath = dir.absolutePath();
QString defaultConfPath = dirPath + "/crews.ini"; QString defaultConfPath = dirPath + "/crews.ini";

View file

@ -19,6 +19,7 @@
#include "PictureDialog.h" #include "PictureDialog.h"
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "ui_PictureDialog.h" #include "ui_PictureDialog.h"
#include "StandardPaths.h"
#include <QJsonDocument> #include <QJsonDocument>
#include <QFileDialog> #include <QFileDialog>
@ -31,12 +32,6 @@
#include <QUrl> #include <QUrl>
#include <QDir> #include <QDir>
#if QT5_MODE
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif
PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) : PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) :
QDialog(parent), profileDB(profileDB), QDialog(parent), profileDB(profileDB),
ui(new Ui::PictureDialog) ui(new Ui::PictureDialog)
@ -164,13 +159,8 @@ void PictureDialog::on_cmdExport_clicked()
QDir dir; QDir dir;
// Get Documents + Desktop Location // Get Documents + Desktop Location
#ifdef QT5_MODE QString documentsLocation = StandardPaths::writableLocation(StandardPaths::DocumentsLocation);
QString documentsLocation = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); QString desktopLocation = StandardPaths::writableLocation(StandardPaths::DesktopLocation);
QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
#else
QString documentsLocation = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
QString desktopLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
#endif
// Add Desktop Location to Sidebar // Add Desktop Location to Sidebar
dir.setPath(desktopLocation); dir.setPath(desktopLocation);

View file

@ -17,23 +17,14 @@
*****************************************************************************/ *****************************************************************************/
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "StandardPaths.h"
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#ifdef QT5_MODE
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif
ProfileDatabase::ProfileDatabase(QObject *parent) : QObject(parent) ProfileDatabase::ProfileDatabase(QObject *parent) : QObject(parent)
{ {
QDir dir; QDir dir;
#ifdef QT5_MODE dir.setPath(StandardPaths::writableLocation(StandardPaths::DataLocation));
dir.setPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
#else
dir.setPath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
#endif
dir.mkdir("../gta5sync"); dir.mkdir("../gta5sync");
QString dirPath = dir.absolutePath(); QString dirPath = dir.absolutePath();
QString defaultConfPath = dirPath + "/players.ini"; QString defaultConfPath = dirPath + "/players.ini";

31
StandardPaths.cpp Executable file
View file

@ -0,0 +1,31 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "StandardPaths.h"
StandardPaths::StandardPaths()
{
}
#ifndef QT5_MODE
QString StandardPaths::writableLocation(QDesktopServices::StandardLocation standardLocation)
{
return QDesktopServices::storageLocation(standardLocation);
}
#endif

View file

@ -16,40 +16,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
// DONT USE THE SYNC FRAMEWORK NOW #ifndef STANDARDPATHS_H
#define STANDARDPATHS_H
#ifndef QT5_MODE
#ifndef SYNCFRAMEWORK_H
#define SYNCFRAMEWORK_H
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#include <QObject> #include <QObject>
#include <QString>
class SyncFramework : public QObject class StandardPaths : public QStandardPaths
{ {
Q_OBJECT
public: public:
explicit SyncFramework(QObject *parent = 0); StandardPaths();
void setPort(int port);
void setHost(QString hostname);
void setUsername(QString username);
void setPassword(QString password);
void setSyncFolder(QString folder);
void testServer();
private:
int serverPort;
QString serverHostname;
QString serverUsername;
QString serverPassword;
QString serverSyncFolder;
private slots:
void fileDownloaded(bool isDone);
void fileUploaded(bool isDone);
}; };
#else
#include <QDesktopServices>
#include <QObject>
class StandardPaths : public QDesktopServices
{
public:
StandardPaths();
static QString writableLocation(QDesktopServices::StandardLocation standardLocation);
};
#endif #endif
#endif // SYNCFRAMEWORK_H
#endif // STANDARDPATHS_H

View file

@ -1,90 +0,0 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
// DONT USE THE SYNC FRAMEWORK NOW
#ifndef QT5_MODE
#include "SyncFramework.h"
#include <QEventLoop>
#include <QFtp>
SyncFramework::SyncFramework(QObject *parent) : QObject(parent)
{
// INIT DEFAULT
serverPort = 21;
serverHostname = "";
serverUsername = "";
serverPassword = "";
serverSyncFolder = "gta5sync";
}
void SyncFramework::testServer()
{
QEventLoop ftpLoop;
QFtp *ftpConnection = new QFtp();
connect(ftpConnection, SIGNAL(done(bool)), &ftpLoop, SLOT(quit()));
ftpConnection->connectToHost(serverHostname, serverPort);
if (serverUsername != "")
{
ftpConnection->login(serverHostname, serverPassword);
}
else
{
ftpConnection->login();
}
ftpConnection->close();
ftpLoop.exec();
}
void SyncFramework::setPort(int port)
{
serverPort = port;
}
void SyncFramework::setHost(QString hostname)
{
serverHostname = hostname;
}
void SyncFramework::setUsername(QString username)
{
serverUsername = username;
}
void SyncFramework::setPassword(QString password)
{
serverPassword = password;
}
void SyncFramework::setSyncFolder(QString folder)
{
serverSyncFolder = folder;
}
void SyncFramework::fileDownloaded(bool isDone)
{
Q_UNUSED(isDone)
}
void SyncFramework::fileUploaded(bool isDone)
{
Q_UNUSED(isDone)
}
#endif

View file

@ -19,6 +19,7 @@
#include "UserInterface.h" #include "UserInterface.h"
#include "ui_UserInterface.h" #include "ui_UserInterface.h"
#include "ProfileInterface.h" #include "ProfileInterface.h"
#include "StandardPaths.h"
#include "AboutDialog.h" #include "AboutDialog.h"
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QSpacerItem> #include <QSpacerItem>
@ -31,12 +32,6 @@
#include <QDir> #include <QDir>
#include <QMap> #include <QMap>
#ifdef QT5_MODE
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif
UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) : UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) :
QMainWindow(parent), profileDB(profileDB), crewDB(crewDB), threadDB(threadDB), QMainWindow(parent), profileDB(profileDB), crewDB(crewDB), threadDB(threadDB),
ui(new Ui::UserInterface) ui(new Ui::UserInterface)
@ -52,11 +47,7 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D
bool forceDir = SyncSettings.value("force", false).toBool(); bool forceDir = SyncSettings.value("force", false).toBool();
// init folder // init folder
#ifdef QT5_MODE QString GTAV_defaultFolder = StandardPaths::writableLocation(StandardPaths::DocumentsLocation) + "/Rockstar Games/GTA V";
QString GTAV_defaultFolder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Rockstar Games/GTA V";
#else
QString GTAV_defaultFolder = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation) + "/Rockstar Games/GTA V";
#endif
QDir GTAV_Dir; QDir GTAV_Dir;
if (forceDir) if (forceDir)
{ {

View file

@ -19,7 +19,6 @@
QT += core gui network QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
isEqual(QT_MAJOR_VERSION, 5): DEFINES += QT5_MODE
TARGET = gta5sync TARGET = gta5sync
TEMPLATE = app TEMPLATE = app
@ -33,13 +32,13 @@ SOURCES += main.cpp \
CrewDatabase.cpp \ CrewDatabase.cpp \
SavegameData.cpp \ SavegameData.cpp \
SavegameDialog.cpp \ SavegameDialog.cpp \
SyncFramework.cpp \
UserInterface.cpp \ UserInterface.cpp \
ProfileInterface.cpp \ ProfileInterface.cpp \
SnapmaticWidget.cpp \ SnapmaticWidget.cpp \
SavegameWidget.cpp \ SavegameWidget.cpp \
ProfileLoader.cpp \ ProfileLoader.cpp \
AboutDialog.cpp AboutDialog.cpp \
StandardPaths.cpp
HEADERS += \ HEADERS += \
SnapmaticPicture.h \ SnapmaticPicture.h \
@ -49,13 +48,13 @@ HEADERS += \
CrewDatabase.h \ CrewDatabase.h \
SavegameData.h \ SavegameData.h \
SavegameDialog.h \ SavegameDialog.h \
SyncFramework.h \
UserInterface.h \ UserInterface.h \
ProfileInterface.h \ ProfileInterface.h \
SnapmaticWidget.h \ SnapmaticWidget.h \
SavegameWidget.h \ SavegameWidget.h \
ProfileLoader.h \ ProfileLoader.h \
AboutDialog.h AboutDialog.h \
StandardPaths.h
FORMS += \ FORMS += \
PictureDialog.ui \ PictureDialog.ui \