Commit a64df4a0 authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

Use QDesktopServices::StandardLocation for platform independent default paths...

Use QDesktopServices::StandardLocation for platform independent default paths that don't touch the application's own folder
parent cf4bc71d
......@@ -27,6 +27,7 @@
#include <QSettings>
#include <QIcon>
#include <QDir>
#include <QDesktopServices>
#include <stdio.h>
#include "main.h"
......@@ -99,15 +100,18 @@ int main(int argc, char *argv[])
qsrand(QDateTime::currentDateTime().toTime_t());
bool startMainProgram = true;
#ifdef Q_OS_MAC
const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
if (!db->getLoadSuccess())
if (db->loadCardDatabase(baseDir.absolutePath() + "/cards.xml"))
settingsCache->setCardDatabasePath(baseDir.absolutePath() + "/cards.xml");
if (!QDir(settingsCache->getDeckPath()).exists())
settingsCache->setDeckPath(baseDir.absolutePath() + "/decks");
if (!QDir(settingsCache->getPicsPath()).exists())
settingsCache->setPicsPath(baseDir.absolutePath() + "/pics");
#endif
if (db->loadCardDatabase(dataDir + "/cards.xml"))
settingsCache->setCardDatabasePath(dataDir + "/cards.xml");
if (!QDir(settingsCache->getDeckPath()).exists()) {
QDir().mkpath(dataDir + "/decks");
settingsCache->setDeckPath(dataDir + "/decks");
}
if (!QDir(settingsCache->getPicsPath()).exists()) {
QDir().mkpath(dataDir + "/pics");
settingsCache->setPicsPath(dataDir + "/pics");
}
if (!db->getLoadSuccess() || !QDir(settingsCache->getDeckPath()).exists() || settingsCache->getDeckPath().isEmpty() || settingsCache->getPicsPath().isEmpty() || !QDir(settingsCache->getPicsPath()).exists()) {
DlgSettings dlgSettings;
dlgSettings.show();
......
#include <QApplication>
#include <QTextCodec>
#include "oracleimporter.h"
#include "window_main.h"
#include "settingscache.h"
......@@ -11,7 +10,11 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QCoreApplication::setOrganizationName("Cockatrice");
QCoreApplication::setOrganizationDomain("cockatrice.de");
QCoreApplication::setApplicationName("Cockatrice");
settingsCache = new SettingsCache;
WindowMain wnd;
......
......@@ -235,6 +235,8 @@ QString OracleImporter::getPictureUrl(QString url, int cardId, QString name, con
int OracleImporter::startDownload()
{
clear();
setsToDownload.clear();
for (int i = 0; i < allSets.size(); ++i)
if (allSets[i].getImport())
......
#include <QtGui>
#include <QApplication>
#include <QMenu>
#include <QMenuBar>
#include <QStatusBar>
#include <QLineEdit>
#include <QFileDialog>
#include <QMessageBox>
#include <QScrollArea>
#include <QTextEdit>
#include <QInputDialog>
#include <QLabel>
#include <QPushButton>
#include <QCheckBox>
#include <QProgressBar>
#include <QVBoxLayout>
#include <QDesktopServices>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include "window_main.h"
......@@ -9,13 +24,7 @@ const QString WindowMain::defaultSetsUrl = QString("http://www.cockatrice.de/fil
WindowMain::WindowMain(QWidget *parent)
: QMainWindow(parent)
{
QDir dataDir(qApp->applicationDirPath());
#ifdef Q_OS_MAC
dataDir.cdUp();
dataDir.cdUp();
dataDir.cdUp();
#endif
importer = new OracleImporter(dataDir.absolutePath(), this);
importer = new OracleImporter(QDesktopServices::storageLocation(QDesktopServices::DataLocation), this);
nam = new QNetworkAccessManager(this);
checkBoxLayout = new QVBoxLayout;
......@@ -167,17 +176,23 @@ void WindowMain::updateTotalProgress(int cardsImported, int setIndex, const QStr
if (nextSetName.isEmpty()) {
QMessageBox::information(this, tr("Oracle importer"), tr("Import finished: %1 cards.").arg(importer->getCardList().size()));
bool ok = false;
QString savePath = importer->getDataDir() + "/cards.xml";
const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
QDir dir(dataDir);
if (!dir.exists())
dir.mkpath(dataDir);
QString savePath = dataDir + "/cards.xml";
do {
QString fileName;
if (savePath.isEmpty())
fileName = QFileDialog::getSaveFileName(this, tr("Save card database"), importer->getDataDir() + "/cards.xml", tr("XML card database (*.xml)"));
fileName = QFileDialog::getSaveFileName(this, tr("Save card database"), dataDir + "/cards.xml", tr("XML card database (*.xml)"));
else {
fileName = savePath;
savePath.clear();
}
if (fileName.isEmpty())
if (fileName.isEmpty()) {
qApp->quit();
return;
}
if (importer->saveToFile(fileName))
ok = true;
else
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment