diff --git a/src/engine/gameplay.cpp b/src/engine/gameplay.cpp --- a/src/engine/gameplay.cpp +++ b/src/engine/gameplay.cpp @@ -35,19 +35,19 @@ #include "../config/configdialog.h" #include "settings.h" -#include +#include #include #include #include #include #include +#include #include #include +#include #include #include #include -#include -#include // Use this because comma in type is not possible in foreach macro. typedef QPair DoubleIntPair; @@ -313,8 +313,11 @@ 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 @@ 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 @@ // 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 @@ // 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 @@ // 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 @@ { 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); diff --git a/src/engine/texturehelper.h b/src/engine/texturehelper.h --- a/src/engine/texturehelper.h +++ b/src/engine/texturehelper.h @@ -42,7 +42,7 @@ void removeScene(QObject* object); private: TextureHelper(); - static QPixmap render(const QString& fileName); + static QPixmap render(const QString& filePath); QList m_scenes; int m_currentIndex; diff --git a/src/engine/texturehelper.cpp b/src/engine/texturehelper.cpp --- a/src/engine/texturehelper.cpp +++ b/src/engine/texturehelper.cpp @@ -19,12 +19,11 @@ #include "texturehelper.h" #include "settings.h" -#include +#include +#include #include #include -#include #include -#include #include const QSize Palapeli::TextureHelper::DefaultThumbnailSize(32, 32); @@ -36,21 +35,20 @@ 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); renderer.render(&painter); painter.end(); } else - pixmap.load(path); + pixmap.load(filePath); return pixmap; } @@ -66,19 +64,27 @@ 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(); diff --git a/src/file-io/collection.cpp b/src/file-io/collection.cpp --- a/src/file-io/collection.cpp +++ b/src/file-io/collection.cpp @@ -25,10 +25,10 @@ #include #include #include +#include #include #include #include -#include //BEGIN Palapeli::Collection::Item @@ -82,9 +82,9 @@ 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 @@ //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