mirror of https://github.com/procxx/kepka.git
os x and linux dialog path remember through executions
This commit is contained in:
parent
b5d3580150
commit
489b151d49
|
@ -19,6 +19,7 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org
|
||||||
#include "gui/filedialog.h"
|
#include "gui/filedialog.h"
|
||||||
|
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
#include "localstorage.h"
|
||||||
|
|
||||||
void filedialogInit() {
|
void filedialogInit() {
|
||||||
if (cDialogLastPath().isEmpty()) {
|
if (cDialogLastPath().isEmpty()) {
|
||||||
|
@ -67,13 +68,22 @@ void filedialogInit() {
|
||||||
|
|
||||||
// multipleFiles: 1 - multi open, 0 - single open, -1 - single save, -2 - select dir
|
// multipleFiles: 1 - multi open, 0 - single open, -1 - single save, -2 - select dir
|
||||||
bool _filedialogGetFiles(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, int multipleFiles, QString startFile = QString()) {
|
bool _filedialogGetFiles(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, int multipleFiles, QString startFile = QString()) {
|
||||||
|
|
||||||
|
filedialogInit();
|
||||||
|
|
||||||
#if defined Q_OS_LINUX || defined Q_OS_MAC // use native
|
#if defined Q_OS_LINUX || defined Q_OS_MAC // use native
|
||||||
remoteContent = QByteArray();
|
remoteContent = QByteArray();
|
||||||
|
if (startFile.isEmpty() || startFile.at(0) != '/') {
|
||||||
|
startFile = cDialogLastPath() + '/' + startFile;
|
||||||
|
}
|
||||||
QString file;
|
QString file;
|
||||||
if (multipleFiles >= 0) {
|
if (multipleFiles >= 0) {
|
||||||
files = QFileDialog::getOpenFileNames(App::wnd() ? App::wnd()->filedialogParent() : 0, caption, startFile, filter);
|
files = QFileDialog::getOpenFileNames(App::wnd() ? App::wnd()->filedialogParent() : 0, caption, startFile, filter);
|
||||||
QString path = files.isEmpty() ? QString() : QFileInfo(files.back()).absoluteDir().absolutePath();
|
QString path = files.isEmpty() ? QString() : QFileInfo(files.back()).absoluteDir().absolutePath();
|
||||||
if (!path.isEmpty()) cSetDialogLastPath(path);
|
if (!path.isEmpty() && path != cDialogLastPath()) {
|
||||||
|
cSetDialogLastPath(path);
|
||||||
|
Local::writeUserSettings();
|
||||||
|
}
|
||||||
return !files.isEmpty();
|
return !files.isEmpty();
|
||||||
} else if (multipleFiles < -1) {
|
} else if (multipleFiles < -1) {
|
||||||
file = QFileDialog::getExistingDirectory(App::wnd() ? App::wnd()->filedialogParent() : 0, caption);
|
file = QFileDialog::getExistingDirectory(App::wnd() ? App::wnd()->filedialogParent() : 0, caption);
|
||||||
|
@ -87,14 +97,15 @@ bool _filedialogGetFiles(QStringList &files, QByteArray &remoteContent, const QS
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
QString path = QFileInfo(file).absoluteDir().absolutePath();
|
QString path = QFileInfo(file).absoluteDir().absolutePath();
|
||||||
if (!path.isEmpty()) cSetDialogLastPath(path);
|
if (!path.isEmpty() && path != cDialogLastPath()) {
|
||||||
|
cSetDialogLastPath(path);
|
||||||
|
Local::writeUserSettings();
|
||||||
|
}
|
||||||
files = QStringList(file);
|
files = QStringList(file);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
filedialogInit();
|
|
||||||
|
|
||||||
// hack for fast non-native dialog create
|
// hack for fast non-native dialog create
|
||||||
QFileDialog dialog(App::wnd() ? App::wnd()->filedialogParent() : 0, caption, cDialogHelperPathFinal(), filter);
|
QFileDialog dialog(App::wnd() ? App::wnd()->filedialogParent() : 0, caption, cDialogHelperPathFinal(), filter);
|
||||||
|
|
||||||
|
@ -130,7 +141,11 @@ bool _filedialogGetFiles(QStringList &files, QByteArray &remoteContent, const QS
|
||||||
|
|
||||||
int res = dialog.exec();
|
int res = dialog.exec();
|
||||||
|
|
||||||
cSetDialogLastPath(dialog.directory().absolutePath());
|
QString path = dialog.directory().absolutePath();
|
||||||
|
if (path != cDialogLastPath()) {
|
||||||
|
cSetDialogLastPath(path);
|
||||||
|
Local::writeUserSettings();
|
||||||
|
}
|
||||||
|
|
||||||
if (res == QDialog::Accepted) {
|
if (res == QDialog::Accepted) {
|
||||||
if (multipleFiles > 0) {
|
if (multipleFiles > 0) {
|
||||||
|
|
|
@ -431,7 +431,11 @@ QString saveFileName(const QString &title, const QString &filter, const QString
|
||||||
if (!name.isEmpty() && name.at(0) == QChar::fromLatin1('.')) {
|
if (!name.isEmpty() && name.at(0) == QChar::fromLatin1('.')) {
|
||||||
name = filedialogDefaultName(prefix, name);
|
name = filedialogDefaultName(prefix, name);
|
||||||
} else if (dir.path() != qsl(".")) {
|
} else if (dir.path() != qsl(".")) {
|
||||||
cSetDialogLastPath(dir.absolutePath());
|
QString path = dir.absolutePath();
|
||||||
|
if (path != cDialogLastPath()) {
|
||||||
|
cSetDialogLastPath(path);
|
||||||
|
Local::writeUserSettings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return filedialogGetSaveFile(name, title, filter, name) ? name : QString();
|
return filedialogGetSaveFile(name, title, filter, name) ? name : QString();
|
||||||
|
|
|
@ -920,6 +920,14 @@ namespace {
|
||||||
cSetRecentEmojisPreload(v);
|
cSetRecentEmojisPreload(v);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case dbiDialogLastPath: {
|
||||||
|
QString path;
|
||||||
|
stream >> path;
|
||||||
|
if (!_checkStreamStatus(stream)) return false;
|
||||||
|
|
||||||
|
cSetDialogLastPath(path);
|
||||||
|
} break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
LOG(("App Error: unknown blockId in _readSetting: %1").arg(blockId));
|
LOG(("App Error: unknown blockId in _readSetting: %1").arg(blockId));
|
||||||
return false;
|
return false;
|
||||||
|
@ -1130,6 +1138,7 @@ namespace {
|
||||||
uint32 size = 11 * (sizeof(quint32) + sizeof(qint32));
|
uint32 size = 11 * (sizeof(quint32) + sizeof(qint32));
|
||||||
size += sizeof(quint32) + _stringSize(cAskDownloadPath() ? QString() : cDownloadPath());
|
size += sizeof(quint32) + _stringSize(cAskDownloadPath() ? QString() : cDownloadPath());
|
||||||
size += sizeof(quint32) + sizeof(qint32) + cGetRecentEmojis().size() * (sizeof(uint32) + sizeof(ushort));
|
size += sizeof(quint32) + sizeof(qint32) + cGetRecentEmojis().size() * (sizeof(uint32) + sizeof(ushort));
|
||||||
|
size += sizeof(quint32) + _stringSize(cDialogLastPath());
|
||||||
|
|
||||||
EncryptedDescriptor data(size);
|
EncryptedDescriptor data(size);
|
||||||
data.stream << quint32(dbiSendKey) << qint32(cCtrlEnter() ? dbiskCtrlEnter : dbiskEnter);
|
data.stream << quint32(dbiSendKey) << qint32(cCtrlEnter() ? dbiskCtrlEnter : dbiskEnter);
|
||||||
|
@ -1144,6 +1153,7 @@ namespace {
|
||||||
data.stream << quint32(dbiDownloadPath) << (cAskDownloadPath() ? QString() : cDownloadPath());
|
data.stream << quint32(dbiDownloadPath) << (cAskDownloadPath() ? QString() : cDownloadPath());
|
||||||
data.stream << quint32(dbiCompressPastedImage) << qint32(cCompressPastedImage());
|
data.stream << quint32(dbiCompressPastedImage) << qint32(cCompressPastedImage());
|
||||||
data.stream << quint32(dbiEmojiTab) << qint32(cEmojiTab());
|
data.stream << quint32(dbiEmojiTab) << qint32(cEmojiTab());
|
||||||
|
data.stream << quint32(dbiDialogLastPath) << cDialogLastPath();
|
||||||
|
|
||||||
RecentEmojiPreload v;
|
RecentEmojiPreload v;
|
||||||
v.reserve(cGetRecentEmojis().size());
|
v.reserve(cGetRecentEmojis().size());
|
||||||
|
|
|
@ -259,6 +259,7 @@ enum DataBlockId {
|
||||||
dbiLangFile = 32,
|
dbiLangFile = 32,
|
||||||
dbiTileBackground = 33,
|
dbiTileBackground = 33,
|
||||||
dbiAutoLock = 34,
|
dbiAutoLock = 34,
|
||||||
|
dbiDialogLastPath = 35,
|
||||||
|
|
||||||
dbiEncryptedWithSalt = 333,
|
dbiEncryptedWithSalt = 333,
|
||||||
dbiEncrypted = 444,
|
dbiEncrypted = 444,
|
||||||
|
|
Loading…
Reference in New Issue