Commit b1c8eecf authored by Albert Astals Cid's avatar Albert Astals Cid

Remove use of KFileDialog KImageIO KMimeType and KUrl

parent 5060ee9e
...@@ -15,6 +15,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS ...@@ -15,6 +15,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
CoreAddons CoreAddons
Crash Crash
DBusAddons DBusAddons
DocTools
I18n I18n
KDELibs4Support #TODO eventually remove kdelibs4support KDELibs4Support #TODO eventually remove kdelibs4support
WidgetsAddons WidgetsAddons
......
...@@ -13,26 +13,26 @@ ...@@ -13,26 +13,26 @@
#include "toplevel.h" #include "toplevel.h"
#include <kmessagebox.h> #include <kmessagebox.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <KLocalizedString> #include <KLocalizedString>
#include <kio/netaccess.h>
#include <kstandardaction.h> #include <kstandardaction.h>
#include <kstandardshortcut.h> #include <kstandardshortcut.h>
#include <kstandardgameaction.h> #include <kstandardgameaction.h>
#include <kactioncollection.h> #include <kactioncollection.h>
#include <ktoggleaction.h> #include <ktoggleaction.h>
#include <ktogglefullscreenaction.h> #include <ktogglefullscreenaction.h>
#include <kimageio.h>
#include <kmimetype.h>
#include <kconfiggroup.h> #include <kconfiggroup.h>
#include <kcombobox.h> #include <kcombobox.h>
#include <ksharedconfig.h>
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QImageWriter>
#include <QMimeDatabase>
#include <QPrintDialog> #include <QPrintDialog>
#include <QPrinter> #include <QPrinter>
#include <QStandardPaths>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QWidgetAction> #include <QWidgetAction>
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
#include "soundfactory.h" #include "soundfactory.h"
#include "playgrounddelegate.h" #include "playgrounddelegate.h"
// TODO kdelibs4support REMOVE
#include <KLocale>
#include "kio/netaccess.h"
static const char *DEFAULT_THEME = "default_theme.theme"; static const char *DEFAULT_THEME = "default_theme.theme";
// Constructor // Constructor
...@@ -331,8 +335,8 @@ void TopLevel::fileNew() ...@@ -331,8 +335,8 @@ void TopLevel::fileNew()
// Load gameboard // Load gameboard
void TopLevel::fileOpen() void TopLevel::fileOpen()
{ {
QUrl url = KFileDialog::getOpenUrl(QUrl(QStringLiteral("kfiledialog:///<ktuberling>")), QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Load file"), QUrl(),
QStringLiteral("*.tuberling|%1\n*|%2").arg(i18n("KTuberling files"), i18n("All files"))); i18n("KTuberling files (%1)", QStringLiteral("*.tuberling")));
open(url); open(url);
} }
...@@ -368,9 +372,7 @@ void TopLevel::open(const QUrl &url) ...@@ -368,9 +372,7 @@ void TopLevel::open(const QUrl &url)
// Save gameboard // Save gameboard
void TopLevel::fileSave() void TopLevel::fileSave()
{ {
KUrl url = KFileDialog::getSaveUrl QUrl url = QFileDialog::getSaveFileUrl( this, QString(), QUrl(), i18n("KTuberling files (%1)", QStringLiteral("*.tuberling")) );
( KUrl("kfiledialog:///<ktuberling>"),
QStringLiteral("*.tuberling|%1").arg(i18n("KTuberling files")), this, QString(), KFileDialog::ConfirmOverwrite);
if (url.isEmpty()) if (url.isEmpty())
return; return;
...@@ -407,19 +409,34 @@ void TopLevel::fileSave() ...@@ -407,19 +409,34 @@ void TopLevel::fileSave()
// Save gameboard as picture // Save gameboard as picture
void TopLevel::filePicture() void TopLevel::filePicture()
{ {
const QString patternsString = KImageIO::pattern(KImageIO::Writing); const QMimeDatabase mimedb;
QStringList patterns = patternsString.split(QStringLiteral("\n")); const QList<QByteArray> imageWriterMimetypes = QImageWriter::supportedMimeTypes();
// Favor png QStringList patterns;
if (!patterns.isEmpty()) { for(auto mimeName : imageWriterMimetypes)
QString firstLine = patterns[0]; {
patterns.removeAt(0); const QMimeType mime = mimedb.mimeTypeForName(mimeName);
if (firstLine.contains(QStringLiteral(" *.png"))) { if (mime.isValid())
firstLine.remove(QStringLiteral(" *.png")); {
firstLine.prepend("*.png "); qDebug() << mimeName << mime.comment() << mime.suffixes();
QStringList suffixes;
for(const QString &suffix : mime.suffixes())
{
suffixes << QString("*.%1").arg(suffix);
}
// Favor png
const QString pattern = i18nc("%1 is mimetype and %2 is the file extensions", "%1 (%2)", mime.comment(), suffixes.join(' '));
if (mimeName == "image/png")
{
patterns.prepend(pattern);
}
else
{
patterns << pattern;
} }
patterns.prepend(firstLine); }
} }
const KUrl url = KFileDialog::getSaveUrl(KUrl(QStringLiteral("kfiledialog:///<ktuberling>")), patterns.join(QStringLiteral("\n")), this, QString(), KFileDialog::ConfirmOverwrite); const QUrl url = QFileDialog::getSaveFileUrl( this, QString(), QUrl(), patterns.join(";;") );
if( url.isEmpty() ) if( url.isEmpty() )
return; return;
...@@ -436,19 +453,9 @@ void TopLevel::filePicture() ...@@ -436,19 +453,9 @@ void TopLevel::filePicture()
name = url.path(); name = url.path();
} }
KMimeType::Ptr mime = KMimeType::findByUrl(url, 0, true, true);
if (!KImageIO::isSupported(mime->name(), KImageIO::Writing))
{
KMessageBox::error(this, i18n("Unknown picture format."));
return;
};
QStringList types = KImageIO::typeForMime(mime->name());
if (types.isEmpty()) return; // TODO error dialog?
QPixmap picture(playGround->getPicture()); QPixmap picture(playGround->getPicture());
if (!picture.save(name, types.at(0).toLatin1())) if (!picture.save(name))
{ {
KMessageBox::error KMessageBox::error
(this, i18n("Could not save file.")); (this, i18n("Could not save file."));
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#define _TOPLEVEL_H_ #define _TOPLEVEL_H_
#include <kxmlguiwindow.h> #include <kxmlguiwindow.h>
#include <kurl.h>
#include <kcombobox.h> #include <kcombobox.h>
class QActionGroup; class QActionGroup;
......
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