Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit ebd26298 authored by Christian Ehrlicher's avatar Christian Ehrlicher

KF5 port: replace KStandardDirs with QStandardPaths

Summary: third patch to remove kdelibs4support from frameworks branch

Test Plan: Images/Puzzles and config is loaded from the correct location (also checked used paths with debugger)

Reviewers: #kde_games

Subscribers: #kde_games

Differential Revision: https://phabricator.kde.org/D7418
parent f0d0b987
......@@ -35,19 +35,19 @@
#include "../config/configdialog.h"
#include "settings.h"
#include <KUrl>
#include <QUrl>
#include <QStackedWidget>
#include <QPointer>
#include <QPropertyAnimation>
#include <QFutureWatcher>
#include <QtCore/qmath.h>
#include <QStandardPaths>
#include <QInputDialog>
#include <QAction>
#include <QFileDialog>
#include <KActionCollection>
#include <KLocalizedString>
#include <KMessageBox>
#include <KFileDialog>
#include <KStandardDirs>
// Use this because comma in type is not possible in foreach macro.
typedef QPair<int, int> DoubleIntPair;
......@@ -313,8 +313,11 @@ void Palapeli::GamePlay::actionDelete()
void Palapeli::GamePlay::actionImport()
{
const QString filter = i18nc("Filter for a file dialog", "*.puzzle|Palapeli puzzles (*.puzzle)");
const QStringList paths = KFileDialog::getOpenFileNames(KUrl("kfiledialog:///palapeli-import"), filter);
const QString filter = i18nc("Filter for a file dialog", "Palapeli puzzles (*.puzzle)");
const QStringList paths = QFileDialog::getOpenFileNames(m_mainWindow,
i18n("Import Palapeli puzzles"),
QString(),
filter);
Palapeli::Collection* coll = Palapeli::Collection::instance();
foreach (const QString& path, paths)
coll->importPuzzle(path);
......@@ -335,9 +338,12 @@ void Palapeli::GamePlay::actionExport()
if (!cmp)
continue;
//ask user for target file name
const QString startLoc = QString::fromLatin1("kfiledialog:///palapeli-export/%1.puzzle").arg(cmp->metadata.name);
const QString filter = i18nc("Filter for a file dialog", "*.puzzle|Palapeli puzzles (*.puzzle)");
const QString location = KFileDialog::getSaveFileName(KUrl(startLoc), filter);
const QString startLoc = QString::fromLatin1("%1.puzzle").arg(cmp->metadata.name);
const QString filter = i18nc("Filter for a file dialog", "Palapeli puzzles (*.puzzle)");
const QString location = QFileDialog::getSaveFileName(m_mainWindow,
i18n("Save Palapeli puzzles"),
startLoc,
filter);
if (location.isEmpty())
continue; //process aborted by user
//do export
......@@ -508,7 +514,7 @@ void Palapeli::GamePlay::restartPuzzle()
// Discard the *.save file.
static const QString pathTemplate =
QString::fromLatin1("collection/%1.save");
QFile(KStandardDirs::locateLocal("appdata",
QFile(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation,
pathTemplate.arg(m_puzzle->identifier()))).remove();
// Load the puzzle and re-shuffle the pieces.
loadPuzzle();
......@@ -726,7 +732,7 @@ void Palapeli::GamePlay::loadPuzzle()
// Is there a saved game?
static const QString pathTemplate =
QString::fromLatin1("collection/%1.save");
KConfig savedConfig(KStandardDirs::locateLocal("appdata",
KConfig savedConfig(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation,
pathTemplate.arg(m_puzzle->identifier())));
if (savedConfig.hasGroup(AppearanceSaveGroup)) {
// Get settings for background, shadows, etc. in this puzzle.
......@@ -827,7 +833,7 @@ void Palapeli::GamePlay::loadPiecePositions()
// Is there a saved game?
static const QString pathTemplate =
QString::fromLatin1("collection/%1.save");
KConfig savedConfig(KStandardDirs::locateLocal("appdata",
KConfig savedConfig(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation,
pathTemplate.arg(m_puzzle->identifier())));
bool oldFormat = false;
m_restoredGame = false;
......@@ -1192,7 +1198,7 @@ void Palapeli::GamePlay::updateSavedGame()
{
static const QString pathTemplate =
QString::fromLatin1("collection/%1.save");
KConfig savedConfig(KStandardDirs::locateLocal("appdata",
KConfig savedConfig(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation,
pathTemplate.arg(m_puzzle->identifier())));
savePuzzleSettings(&savedConfig);
......
......@@ -19,12 +19,11 @@
#include "texturehelper.h"
#include "settings.h"
#include <QFileInfo>
#include <QDir>
#include <QDirIterator>
#include <QGraphicsScene>
#include <QPainter>
#include <KGlobal>
#include <KLocalizedString>
#include <KStandardDirs>
#include <QSvgRenderer>
const QSize Palapeli::TextureHelper::DefaultThumbnailSize(32, 32);
......@@ -36,13 +35,12 @@ Palapeli::TextureHelper* Palapeli::TextureHelper::instance()
return &instance;
}
QPixmap Palapeli::TextureHelper::render(const QString& fileName)
QPixmap Palapeli::TextureHelper::render(const QString& filePath)
{
const QString path = KStandardDirs::locate("appdata", "backgrounds/" + fileName);
QPixmap pixmap;
if (fileName.contains(".svg"))
if (filePath.endsWith(QLatin1String(".svg")))
{
QSvgRenderer renderer(path);
QSvgRenderer renderer(filePath);
pixmap = QPixmap(DefaultPixmapSize);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
......@@ -50,7 +48,7 @@ QPixmap Palapeli::TextureHelper::render(const QString& fileName)
painter.end();
}
else
pixmap.load(path);
pixmap.load(filePath);
return pixmap;
}
......@@ -66,19 +64,27 @@ Palapeli::TextureHelper::TextureHelper()
colorItem->setData(i18nc("@item:inlistbox", "Single color"), Qt::DisplayRole);
appendRow(colorItem);
//fetch backgrounds, and create menu items
const QStringList backgroundFiles = KGlobal::dirs()->findAllResources("appdata", "backgrounds/*");
foreach (const QString& path, backgroundFiles)
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::AppLocalDataLocation,
"backgrounds",
QStandardPaths::LocateDirectory);
foreach (const QString& dir, dirs)
{
//get file name and find selected or default backgrounds
const QString fileName = QFileInfo(path).fileName();
//create item for this brush
const QPixmap pixmap = render(fileName);
QStandardItem* item = new QStandardItem;
item->setData(pixmap, BrushRole);
item->setData(fileName, IdentifierRole);
item->setData(pixmap.scaled(DefaultThumbnailSize, Qt::KeepAspectRatio), Qt::DecorationRole);
item->setData(fileName, Qt::DisplayRole);
appendRow(item);
QDirIterator dirIt(dir, QDir::Files);
while (dirIt.hasNext())
{
const QString filePath = dirIt.next();
const QString fileName = dirIt.fileName();
//create item for this brush
const QPixmap pixmap = render(filePath);
if (pixmap.isNull())
continue;
QStandardItem* item = new QStandardItem;
item->setData(pixmap, BrushRole);
item->setData(fileName, IdentifierRole);
item->setData(pixmap.scaled(DefaultThumbnailSize, Qt::KeepAspectRatio), Qt::DecorationRole);
item->setData(fileName, Qt::DisplayRole);
appendRow(item);
}
}
//select initial brush
readSettings();
......
......@@ -42,7 +42,7 @@ namespace Palapeli
void removeScene(QObject* object);
private:
TextureHelper();
static QPixmap render(const QString& fileName);
static QPixmap render(const QString& filePath);
QList<QGraphicsScene*> m_scenes;
int m_currentIndex;
......
......@@ -25,10 +25,10 @@
#include <QtCore/QFileInfo>
#include <QtCore/QFutureWatcher>
#include <QtCore/QUuid>
#include <QtCore/QStandardPaths>
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KStandardDirs>
//BEGIN Palapeli::Collection::Item
......@@ -82,9 +82,9 @@ static QString readPseudoUrl(const QString& path_, bool local = false)
QString path(path_);
path.remove(QRegExp("^palapeli:/*"));
if (local)
return KStandardDirs::locateLocal("appdata", path);
return QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, path);
else
return KStandardDirs::locate("appdata", path);
return QStandardPaths::locate(QStandardPaths::AppDataLocation, path);
}
else
return path_;
......@@ -150,7 +150,7 @@ void Palapeli::Collection::importPuzzle(Palapeli::Puzzle* puzzle)
//determine new location
const QString id = puzzle->identifier();
const QString fileName = QString::fromLatin1("collection/%1.puzzle").arg(id);
puzzle->setLocation(KStandardDirs::locateLocal("appdata", fileName));
puzzle->setLocation(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, fileName));
//store puzzle
puzzle->get(Palapeli::PuzzleComponent::ArchiveStorage).waitForFinished();
//create the config group for this puzzle (use pseudo-URL to avoid problems
......
Markdown is supported
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