2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Remove special case in SendFilesBox for an image.

This commit is contained in:
John Preston
2017-12-21 20:15:37 +04:00
parent ec515080b5
commit ff65daa9fe
14 changed files with 367 additions and 299 deletions

View File

@@ -26,7 +26,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "base/task_queue.h"
#include "messenger.h"
bool filedialogGetSaveFile(QString &file, const QString &caption, const QString &filter, const QString &initialPath) {
bool filedialogGetSaveFile(
QString &file,
const QString &caption,
const QString &filter,
const QString &initialPath) {
QStringList files;
QByteArray remoteContent;
bool result = Platform::FileDialog::Get(files, remoteContent, caption, filter, FileDialog::internal::Type::WriteFile, initialPath);
@@ -34,7 +38,12 @@ bool filedialogGetSaveFile(QString &file, const QString &caption, const QString
return result;
}
QString filedialogDefaultName(const QString &prefix, const QString &extension, const QString &path, bool skipExistance, int fileTime) {
QString filedialogDefaultName(
const QString &prefix,
const QString &extension,
const QString &path,
bool skipExistance,
int fileTime) {
auto directoryPath = path;
if (directoryPath.isEmpty()) {
if (cDialogLastPath().isEmpty()) {
@@ -69,7 +78,10 @@ QString filedialogDefaultName(const QString &prefix, const QString &extension, c
return name;
}
QString filedialogNextFilename(const QString &name, const QString &cur, const QString &path) {
QString filedialogNextFilename(
const QString &name,
const QString &cur,
const QString &path) {
QDir dir(path.isEmpty() ? cDialogLastPath() : path);
int32 extIndex = name.lastIndexOf('.');
QString prefix = name, extension;
@@ -130,19 +142,30 @@ void UnsafeLaunchDefault(const QString &filepath) {
namespace FileDialog {
void GetOpenPath(const QString &caption, const QString &filter, base::lambda<void(const OpenResult &result)> callback, base::lambda<void()> failed) {
base::TaskQueue::Main().Put([caption, filter, callback = std::move(callback), failed = std::move(failed)] {
void GetOpenPath(
const QString &caption,
const QString &filter,
base::lambda<void(OpenResult &&result)> callback,
base::lambda<void()> failed) {
base::TaskQueue::Main().Put([=] {
auto files = QStringList();
auto remoteContent = QByteArray();
if (Platform::FileDialog::Get(files, remoteContent, caption, filter, FileDialog::internal::Type::ReadFile)
&& ((!files.isEmpty() && !files[0].isEmpty()) || !remoteContent.isEmpty())) {
const auto success = Platform::FileDialog::Get(
files,
remoteContent,
caption,
filter,
FileDialog::internal::Type::ReadFile);
if (success
&& ((!files.isEmpty() && !files[0].isEmpty())
|| !remoteContent.isEmpty())) {
if (callback) {
auto result = OpenResult();
if (!files.isEmpty() && !files[0].isEmpty()) {
result.paths.push_back(files[0]);
}
result.remoteContent = remoteContent;
callback(result);
callback(std::move(result));
}
} else if (failed) {
failed();
@@ -150,17 +173,26 @@ void GetOpenPath(const QString &caption, const QString &filter, base::lambda<voi
});
}
void GetOpenPaths(const QString &caption, const QString &filter, base::lambda<void(const OpenResult &result)> callback, base::lambda<void()> failed) {
base::TaskQueue::Main().Put([caption, filter, callback = std::move(callback), failed = std::move(failed)] {
void GetOpenPaths(
const QString &caption,
const QString &filter,
base::lambda<void(OpenResult &&result)> callback,
base::lambda<void()> failed) {
base::TaskQueue::Main().Put([=] {
auto files = QStringList();
auto remoteContent = QByteArray();
if (Platform::FileDialog::Get(files, remoteContent, caption, filter, FileDialog::internal::Type::ReadFiles)
&& (!files.isEmpty() || !remoteContent.isEmpty())) {
const auto success = Platform::FileDialog::Get(
files,
remoteContent,
caption,
filter,
FileDialog::internal::Type::ReadFiles);
if (success && (!files.isEmpty() || !remoteContent.isEmpty())) {
if (callback) {
auto result = OpenResult();
result.paths = files;
result.remoteContent = remoteContent;
callback(result);
callback(std::move(result));
}
} else if (failed) {
failed();
@@ -168,12 +200,17 @@ void GetOpenPaths(const QString &caption, const QString &filter, base::lambda<vo
});
}
void GetWritePath(const QString &caption, const QString &filter, const QString &initialPath, base::lambda<void(const QString &result)> callback, base::lambda<void()> failed) {
base::TaskQueue::Main().Put([caption, filter, initialPath, callback = std::move(callback), failed = std::move(failed)] {
void GetWritePath(
const QString &caption,
const QString &filter,
const QString &initialPath,
base::lambda<void(QString &&result)> callback,
base::lambda<void()> failed) {
base::TaskQueue::Main().Put([=] {
auto file = QString();
if (filedialogGetSaveFile(file, caption, filter, initialPath)) {
if (callback) {
callback(file);
callback(std::move(file));
}
} else if (failed) {
failed();
@@ -181,14 +218,24 @@ void GetWritePath(const QString &caption, const QString &filter, const QString &
});
}
void GetFolder(const QString &caption, const QString &initialPath, base::lambda<void(const QString &result)> callback, base::lambda<void()> failed) {
base::TaskQueue::Main().Put([caption, initialPath, callback = std::move(callback), failed = std::move(failed)] {
void GetFolder(
const QString &caption,
const QString &initialPath,
base::lambda<void(QString &&result)> callback,
base::lambda<void()> failed) {
base::TaskQueue::Main().Put([=] {
auto files = QStringList();
auto remoteContent = QByteArray();
if (Platform::FileDialog::Get(files, remoteContent, caption, QString(), FileDialog::internal::Type::ReadFolder, initialPath)
&& !files.isEmpty() && !files[0].isEmpty()) {
const auto success = Platform::FileDialog::Get(
files,
remoteContent,
caption,
QString(),
FileDialog::internal::Type::ReadFolder,
initialPath);
if (success && !files.isEmpty() && !files[0].isEmpty()) {
if (callback) {
callback(files[0]);
callback(std::move(files[0]));
}
} else if (failed) {
failed();

View File

@@ -23,10 +23,22 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "base/observer.h"
// legacy
bool filedialogGetSaveFile(QString &file, const QString &caption, const QString &filter, const QString &initialPath);
bool filedialogGetSaveFile(
QString &file,
const QString &caption,
const QString &filter,
const QString &initialPath);
QString filedialogDefaultName(const QString &prefix, const QString &extension, const QString &path = QString(), bool skipExistance = false, int fileTime = 0);
QString filedialogNextFilename(const QString &name, const QString &cur, const QString &path = QString());
QString filedialogDefaultName(
const QString &prefix,
const QString &extension,
const QString &path = QString(),
bool skipExistance = false,
int fileTime = 0);
QString filedialogNextFilename(
const QString &name,
const QString &cur,
const QString &path = QString());
namespace File {
@@ -54,10 +66,27 @@ struct OpenResult {
QStringList paths;
QByteArray remoteContent;
};
void GetOpenPath(const QString &caption, const QString &filter, base::lambda<void(const OpenResult &result)> callback, base::lambda<void()> failed = base::lambda<void()>());
void GetOpenPaths(const QString &caption, const QString &filter, base::lambda<void(const OpenResult &result)> callback, base::lambda<void()> failed = base::lambda<void()>());
void GetWritePath(const QString &caption, const QString &filter, const QString &initialPath, base::lambda<void(const QString &result)> callback, base::lambda<void()> failed = base::lambda<void()>());
void GetFolder(const QString &caption, const QString &initialPath, base::lambda<void(const QString &result)> callback, base::lambda<void()> failed = base::lambda<void()>());
void GetOpenPath(
const QString &caption,
const QString &filter,
base::lambda<void(OpenResult &&result)> callback,
base::lambda<void()> failed = base::lambda<void()>());
void GetOpenPaths(
const QString &caption,
const QString &filter,
base::lambda<void(OpenResult &&result)> callback,
base::lambda<void()> failed = base::lambda<void()>());
void GetWritePath(
const QString &caption,
const QString &filter,
const QString &initialPath,
base::lambda<void(QString &&result)> callback,
base::lambda<void()> failed = base::lambda<void()>());
void GetFolder(
const QString &caption,
const QString &initialPath,
base::lambda<void(QString &&result)> callback,
base::lambda<void()> failed = base::lambda<void()>());
QString AllFilesFilter();
@@ -72,7 +101,13 @@ enum class Type {
void InitLastPathDefault();
bool GetDefault(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, ::FileDialog::internal::Type type, QString startFile);
bool GetDefault(
QStringList &files,
QByteArray &remoteContent,
const QString &caption,
const QString &filter,
::FileDialog::internal::Type type,
QString startFile);
} // namespace internal
} // namespace FileDialog