mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-19 13:23:55 -07:00
Use QDesktopServices::StandardLocation for platform independent default paths that don't touch the application's own folder
This commit is contained in:
parent
cf4bc71d57
commit
a64df4a0f5
4 changed files with 45 additions and 21 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
@ -99,15 +100,18 @@ int main(int argc, char *argv[])
|
||||||
qsrand(QDateTime::currentDateTime().toTime_t());
|
qsrand(QDateTime::currentDateTime().toTime_t());
|
||||||
|
|
||||||
bool startMainProgram = true;
|
bool startMainProgram = true;
|
||||||
#ifdef Q_OS_MAC
|
const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||||
if (!db->getLoadSuccess())
|
if (!db->getLoadSuccess())
|
||||||
if (db->loadCardDatabase(baseDir.absolutePath() + "/cards.xml"))
|
if (db->loadCardDatabase(dataDir + "/cards.xml"))
|
||||||
settingsCache->setCardDatabasePath(baseDir.absolutePath() + "/cards.xml");
|
settingsCache->setCardDatabasePath(dataDir + "/cards.xml");
|
||||||
if (!QDir(settingsCache->getDeckPath()).exists())
|
if (!QDir(settingsCache->getDeckPath()).exists()) {
|
||||||
settingsCache->setDeckPath(baseDir.absolutePath() + "/decks");
|
QDir().mkpath(dataDir + "/decks");
|
||||||
if (!QDir(settingsCache->getPicsPath()).exists())
|
settingsCache->setDeckPath(dataDir + "/decks");
|
||||||
settingsCache->setPicsPath(baseDir.absolutePath() + "/pics");
|
}
|
||||||
#endif
|
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()) {
|
if (!db->getLoadSuccess() || !QDir(settingsCache->getDeckPath()).exists() || settingsCache->getDeckPath().isEmpty() || settingsCache->getPicsPath().isEmpty() || !QDir(settingsCache->getPicsPath()).exists()) {
|
||||||
DlgSettings dlgSettings;
|
DlgSettings dlgSettings;
|
||||||
dlgSettings.show();
|
dlgSettings.show();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include "oracleimporter.h"
|
|
||||||
#include "window_main.h"
|
#include "window_main.h"
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
|
|
||||||
|
|
@ -12,6 +11,10 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
|
QCoreApplication::setOrganizationName("Cockatrice");
|
||||||
|
QCoreApplication::setOrganizationDomain("cockatrice.de");
|
||||||
|
QCoreApplication::setApplicationName("Cockatrice");
|
||||||
|
|
||||||
settingsCache = new SettingsCache;
|
settingsCache = new SettingsCache;
|
||||||
|
|
||||||
WindowMain wnd;
|
WindowMain wnd;
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,8 @@ QString OracleImporter::getPictureUrl(QString url, int cardId, QString name, con
|
||||||
|
|
||||||
int OracleImporter::startDownload()
|
int OracleImporter::startDownload()
|
||||||
{
|
{
|
||||||
|
clear();
|
||||||
|
|
||||||
setsToDownload.clear();
|
setsToDownload.clear();
|
||||||
for (int i = 0; i < allSets.size(); ++i)
|
for (int i = 0; i < allSets.size(); ++i)
|
||||||
if (allSets[i].getImport())
|
if (allSets[i].getImport())
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,19 @@
|
||||||
#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 <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include "window_main.h"
|
#include "window_main.h"
|
||||||
|
|
@ -9,13 +24,7 @@ const QString WindowMain::defaultSetsUrl = QString("http://www.cockatrice.de/fil
|
||||||
WindowMain::WindowMain(QWidget *parent)
|
WindowMain::WindowMain(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
{
|
{
|
||||||
QDir dataDir(qApp->applicationDirPath());
|
importer = new OracleImporter(QDesktopServices::storageLocation(QDesktopServices::DataLocation), this);
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
dataDir.cdUp();
|
|
||||||
dataDir.cdUp();
|
|
||||||
dataDir.cdUp();
|
|
||||||
#endif
|
|
||||||
importer = new OracleImporter(dataDir.absolutePath(), this);
|
|
||||||
nam = new QNetworkAccessManager(this);
|
nam = new QNetworkAccessManager(this);
|
||||||
|
|
||||||
checkBoxLayout = new QVBoxLayout;
|
checkBoxLayout = new QVBoxLayout;
|
||||||
|
|
@ -167,17 +176,23 @@ void WindowMain::updateTotalProgress(int cardsImported, int setIndex, const QStr
|
||||||
if (nextSetName.isEmpty()) {
|
if (nextSetName.isEmpty()) {
|
||||||
QMessageBox::information(this, tr("Oracle importer"), tr("Import finished: %1 cards.").arg(importer->getCardList().size()));
|
QMessageBox::information(this, tr("Oracle importer"), tr("Import finished: %1 cards.").arg(importer->getCardList().size()));
|
||||||
bool ok = false;
|
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 {
|
do {
|
||||||
QString fileName;
|
QString fileName;
|
||||||
if (savePath.isEmpty())
|
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 {
|
else {
|
||||||
fileName = savePath;
|
fileName = savePath;
|
||||||
savePath.clear();
|
savePath.clear();
|
||||||
}
|
}
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty()) {
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (importer->saveToFile(fileName))
|
if (importer->saveToFile(fileName))
|
||||||
ok = true;
|
ok = true;
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue