Commit f5cee23c authored by Anna Medonosová's avatar Anna Medonosová

KoFileDialog automatically sets last used format for dialogName

KoFileDialogs preserves last used MIME type across restarts by saving it
alongside last used directory in kritarc. The MIME type is used to set
the default filter in the QFileDialog, if there is no default filter set
explicitely by the caller.
parent 3f0ff1a8
......@@ -18,7 +18,6 @@
*/
#include "KoFileDialog.h"
#include <QDebug>
#include <QFileDialog>
#include <QApplication>
#include <QImageReader>
......@@ -210,9 +209,16 @@ void KoFileDialog::createFileDialog()
break;
}
}
}
else if (!d->defaultFilter.isEmpty()) {
d->fileDialog->selectNameFilter(d->defaultFilter);
} else {
if (!d->defaultFilter.isEmpty()) {
d->fileDialog->selectNameFilter(d->defaultFilter);
} else {
QString defaultMime = getUsedMimeType(d->dialogName);
if (!defaultMime.isEmpty()) {
d->defaultFilter = getFilterStringListFromMime(QStringList(defaultMime)).first();
d->fileDialog->selectNameFilter(d->defaultFilter);
}
}
}
if (d->type == ImportDirectory ||
......@@ -265,7 +271,9 @@ QString KoFileDialog::filename()
d->mimeType = KisMimeDatabase::mimeTypeForFile(url, d->type == KoFileDialog::SaveFile ? false : true);
saveUsedDir(url, d->dialogName);
saveUsedMimeType(d->mimeType, d->dialogName);
}
return url;
}
......@@ -431,11 +439,26 @@ QString KoFileDialog::getUsedDir(const QString &dialogName)
void KoFileDialog::saveUsedDir(const QString &fileName,
const QString &dialogName)
{
if (dialogName.isEmpty()) return;
QFileInfo fileInfo(fileName);
KConfigGroup group = KSharedConfig::openConfig()->group("File Dialogs");
group.writeEntry(dialogName, fileInfo.absolutePath());
}
QString KoFileDialog::getUsedMimeType(const QString &dialogName)
{
if (dialogName.isEmpty()) return "";
KConfigGroup group = KSharedConfig::openConfig()->group("File Dialogs");
QString mime = group.readEntry(QString("%1_Mime").arg(dialogName), "");
return mime;
}
void KoFileDialog::saveUsedMimeType(const QString &mimeType, const QString &dialogName)
{
if (dialogName.isEmpty()) return;
KConfigGroup group = KSharedConfig::openConfig()->group("File Dialogs");
group.writeEntry(QString("%1_Mime").arg(dialogName), mimeType);
}
......@@ -119,6 +119,9 @@ private:
QString getUsedDir(const QString &dialogName);
void saveUsedDir(const QString &fileName, const QString &dialogName);
QString getUsedMimeType(const QString &dialogName);
void saveUsedMimeType(const QString &mimeType, const QString &dialogName);
const QStringList getFilterStringListFromMime(const QStringList &mimeList,
bool withAllSupportedEntry = false);
......
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