mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-29 15:01:03 +00:00
Removed legacy FileDialog::query* methods.
Everything is done easier and better through the FileDialog::Get*.
This commit is contained in:
parent
f8318177b9
commit
12705c9065
@ -270,18 +270,35 @@ void GroupInfoBox::prepare() {
|
||||
addButton(lang(_creating == CreatingGroupChannel ? lng_create_group_create : lng_create_group_next), [this] { onNext(); });
|
||||
addButton(lang(_fromTypeChoose ? lng_create_group_back : lng_cancel), [this] { closeBox(); });
|
||||
|
||||
_photo->setClickedCallback(App::LambdaDelayed(st::defaultActiveButton.ripple.hideDuration, this, [this] {
|
||||
auto imgExtensions = cImgExtensions();
|
||||
auto filter = qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + filedialogAllFilesFilter();
|
||||
_setPhotoFileQueryId = FileDialog::queryReadFile(lang(lng_choose_image), filter);
|
||||
}));
|
||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
||||
notifyFileQueryUpdated(update);
|
||||
});
|
||||
setupPhotoButton();
|
||||
|
||||
updateMaxHeight();
|
||||
}
|
||||
|
||||
void GroupInfoBox::setupPhotoButton() {
|
||||
_photo->setClickedCallback(App::LambdaDelayed(st::defaultActiveButton.ripple.hideDuration, this, [this] {
|
||||
auto imgExtensions = cImgExtensions();
|
||||
auto filter = qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + FileDialog::AllFilesFilter();
|
||||
FileDialog::GetOpenPath(lang(lng_choose_image), filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
||||
if (result.remoteContent.isEmpty() && result.paths.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QImage img;
|
||||
if (!result.remoteContent.isEmpty()) {
|
||||
img = App::readImage(result.remoteContent);
|
||||
} else {
|
||||
img = App::readImage(result.paths.front());
|
||||
}
|
||||
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
|
||||
return;
|
||||
}
|
||||
auto box = Ui::show(Box<PhotoCropBox>(img, (_creating == CreatingGroupChannel) ? peerFromChannel(0) : peerFromChat(0)), KeepOtherLayers);
|
||||
connect(box, SIGNAL(ready(const QImage&)), this, SLOT(onPhotoReady(const QImage&)));
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
void GroupInfoBox::setInnerFocus() {
|
||||
_title->setFocusFast();
|
||||
}
|
||||
@ -394,28 +411,6 @@ void GroupInfoBox::updateMaxHeight() {
|
||||
setDimensions(st::boxWideWidth, newHeight);
|
||||
}
|
||||
|
||||
void GroupInfoBox::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
||||
if (_setPhotoFileQueryId != update.queryId) {
|
||||
return;
|
||||
}
|
||||
_setPhotoFileQueryId = 0;
|
||||
if (update.remoteContent.isEmpty() && update.filePaths.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QImage img;
|
||||
if (!update.remoteContent.isEmpty()) {
|
||||
img = App::readImage(update.remoteContent);
|
||||
} else {
|
||||
img = App::readImage(update.filePaths.front());
|
||||
}
|
||||
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
|
||||
return;
|
||||
}
|
||||
auto box = Ui::show(Box<PhotoCropBox>(img, (_creating == CreatingGroupChannel) ? peerFromChannel(0) : peerFromChat(0)), KeepOtherLayers);
|
||||
connect(box, SIGNAL(ready(const QImage&)), this, SLOT(onPhotoReady(const QImage&)));
|
||||
}
|
||||
|
||||
void GroupInfoBox::onPhotoReady(const QImage &img) {
|
||||
_photoImage = img;
|
||||
_photo->setImage(_photoImage);
|
||||
|
@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#pragma once
|
||||
|
||||
#include "boxes/abstractbox.h"
|
||||
#include "core/file_utilities.h"
|
||||
|
||||
class ConfirmBox;
|
||||
|
||||
@ -103,7 +102,7 @@ private slots:
|
||||
}
|
||||
|
||||
private:
|
||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
||||
void setupPhotoButton();
|
||||
|
||||
void creationDone(const MTPUpdates &updates);
|
||||
bool creationFail(const RPCError &e);
|
||||
@ -125,8 +124,6 @@ private:
|
||||
mtpRequestId _creationRequestId = 0;
|
||||
ChannelData *_createdChannel = nullptr;
|
||||
|
||||
FileDialog::QueryId _setPhotoFileQueryId = 0;
|
||||
|
||||
};
|
||||
|
||||
class SetupChannelBox : public BoxContent, public RPCSender {
|
||||
|
@ -26,7 +26,179 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "platform/platform_file_utilities.h"
|
||||
#include "core/task_queue.h"
|
||||
|
||||
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);
|
||||
file = files.isEmpty() ? QString() : files.at(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
QString filedialogDefaultName(const QString &prefix, const QString &extension, const QString &path, bool skipExistance) {
|
||||
auto directoryPath = path;
|
||||
if (directoryPath.isEmpty()) {
|
||||
if (cDialogLastPath().isEmpty()) {
|
||||
Platform::FileDialog::InitLastPath();
|
||||
}
|
||||
directoryPath = cDialogLastPath();
|
||||
}
|
||||
|
||||
time_t t = time(NULL);
|
||||
struct tm tm;
|
||||
mylocaltime(&tm, &t);
|
||||
|
||||
QChar zero('0');
|
||||
|
||||
QString name;
|
||||
QString base = prefix + qsl("_%1-%2-%3_%4-%5-%6").arg(tm.tm_year + 1900).arg(tm.tm_mon + 1, 2, 10, zero).arg(tm.tm_mday, 2, 10, zero).arg(tm.tm_hour, 2, 10, zero).arg(tm.tm_min, 2, 10, zero).arg(tm.tm_sec, 2, 10, zero);
|
||||
if (skipExistance) {
|
||||
name = base + extension;
|
||||
} else {
|
||||
QDir dir(directoryPath);
|
||||
QString nameBase = dir.absolutePath() + '/' + base;
|
||||
name = nameBase + extension;
|
||||
for (int i = 0; QFileInfo(name).exists(); ++i) {
|
||||
name = nameBase + qsl(" (%1)").arg(i + 2) + extension;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
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;
|
||||
if (extIndex >= 0) {
|
||||
extension = name.mid(extIndex);
|
||||
prefix = name.mid(0, extIndex);
|
||||
}
|
||||
QString nameBase = dir.absolutePath() + '/' + prefix, result = nameBase + extension;
|
||||
for (int i = 0; result.toLower() != cur.toLower() && QFileInfo(result).exists(); ++i) {
|
||||
result = nameBase + qsl(" (%1)").arg(i + 2) + extension;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace File {
|
||||
|
||||
void OpenEmailLink(const QString &email) {
|
||||
base::TaskQueue::Main().Put([email] {
|
||||
Platform::File::UnsafeOpenEmailLink(email);
|
||||
});
|
||||
}
|
||||
|
||||
void OpenWith(const QString &filepath, QPoint menuPosition) {
|
||||
base::TaskQueue::Main().Put([filepath, menuPosition] {
|
||||
if (!Platform::File::UnsafeShowOpenWithDropdown(filepath, menuPosition)) {
|
||||
if (!Platform::File::UnsafeShowOpenWith(filepath)) {
|
||||
Platform::File::UnsafeLaunch(filepath);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Launch(const QString &filepath) {
|
||||
base::TaskQueue::Main().Put([filepath] {
|
||||
Platform::File::UnsafeLaunch(filepath);
|
||||
});
|
||||
}
|
||||
|
||||
void ShowInFolder(const QString &filepath) {
|
||||
base::TaskQueue::Main().Put([filepath] {
|
||||
Platform::File::UnsafeShowInFolder(filepath);
|
||||
});
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
void UnsafeOpenEmailLinkDefault(const QString &email) {
|
||||
auto url = QUrl(qstr("mailto:") + email);
|
||||
QDesktopServices::openUrl(url);
|
||||
}
|
||||
|
||||
void UnsafeLaunchDefault(const QString &filepath) {
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace File
|
||||
|
||||
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)] {
|
||||
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())) {
|
||||
if (callback) {
|
||||
auto result = OpenResult();
|
||||
if (!files.isEmpty() && !files[0].isEmpty()) {
|
||||
result.paths.push_back(files[0]);
|
||||
}
|
||||
result.remoteContent = remoteContent;
|
||||
callback(result);
|
||||
}
|
||||
} else if (failed) {
|
||||
failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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)] {
|
||||
auto files = QStringList();
|
||||
auto remoteContent = QByteArray();
|
||||
if (Platform::FileDialog::Get(files, remoteContent, caption, filter, FileDialog::internal::Type::ReadFiles)
|
||||
&& (!files.isEmpty() || !remoteContent.isEmpty())) {
|
||||
if (callback) {
|
||||
auto result = OpenResult();
|
||||
result.paths = files;
|
||||
result.remoteContent = remoteContent;
|
||||
callback(result);
|
||||
}
|
||||
} else if (failed) {
|
||||
failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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)] {
|
||||
auto file = QString();
|
||||
if (filedialogGetSaveFile(file, caption, filter, initialPath)) {
|
||||
if (callback) {
|
||||
callback(file);
|
||||
}
|
||||
} else if (failed) {
|
||||
failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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)] {
|
||||
auto files = QStringList();
|
||||
auto remoteContent = QByteArray();
|
||||
if (Platform::FileDialog::Get(files, remoteContent, caption, QString(), FileDialog::internal::Type::ReadFolder, initialPath)
|
||||
&& !files.isEmpty() && !files[0].isEmpty()) {
|
||||
if (callback) {
|
||||
callback(files[0]);
|
||||
}
|
||||
} else if (failed) {
|
||||
failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
QString AllFilesFilter() {
|
||||
#ifdef Q_OS_WIN
|
||||
return qsl("All files (*.*)");
|
||||
#else // Q_OS_WIN
|
||||
return qsl("All files (*)");
|
||||
#endif // Q_OS_WIN
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
void InitLastPathDefault() {
|
||||
@ -76,318 +248,3 @@ bool GetDefault(QStringList &files, QByteArray &remoteContent, const QString &ca
|
||||
|
||||
} // namespace internal
|
||||
} // namespace FileDialog
|
||||
|
||||
bool filedialogGetOpenFiles(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter) {
|
||||
return Platform::FileDialog::Get(files, remoteContent, caption, filter, FileDialog::internal::Type::ReadFiles);
|
||||
}
|
||||
|
||||
bool filedialogGetOpenFile(QString &file, QByteArray &remoteContent, const QString &caption, const QString &filter) {
|
||||
QStringList files;
|
||||
bool result = Platform::FileDialog::Get(files, remoteContent, caption, filter, FileDialog::internal::Type::ReadFile);
|
||||
file = files.isEmpty() ? QString() : files.at(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
file = files.isEmpty() ? QString() : files.at(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool filedialogGetDir(QString &dir, const QString &caption, const QString &initialPath) {
|
||||
QStringList files;
|
||||
QByteArray remoteContent;
|
||||
bool result = Platform::FileDialog::Get(files, remoteContent, caption, QString(), FileDialog::internal::Type::ReadFolder, initialPath);
|
||||
dir = files.isEmpty() ? QString() : files.at(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
QString filedialogDefaultName(const QString &prefix, const QString &extension, const QString &path, bool skipExistance) {
|
||||
auto directoryPath = path;
|
||||
if (directoryPath.isEmpty()) {
|
||||
if (cDialogLastPath().isEmpty()) {
|
||||
Platform::FileDialog::InitLastPath();
|
||||
}
|
||||
directoryPath = cDialogLastPath();
|
||||
}
|
||||
|
||||
time_t t = time(NULL);
|
||||
struct tm tm;
|
||||
mylocaltime(&tm, &t);
|
||||
|
||||
QChar zero('0');
|
||||
|
||||
QString name;
|
||||
QString base = prefix + qsl("_%1-%2-%3_%4-%5-%6").arg(tm.tm_year + 1900).arg(tm.tm_mon + 1, 2, 10, zero).arg(tm.tm_mday, 2, 10, zero).arg(tm.tm_hour, 2, 10, zero).arg(tm.tm_min, 2, 10, zero).arg(tm.tm_sec, 2, 10, zero);
|
||||
if (skipExistance) {
|
||||
name = base + extension;
|
||||
} else {
|
||||
QDir dir(directoryPath);
|
||||
QString nameBase = dir.absolutePath() + '/' + base;
|
||||
name = nameBase + extension;
|
||||
for (int i = 0; QFileInfo(name).exists(); ++i) {
|
||||
name = nameBase + qsl(" (%1)").arg(i + 2) + extension;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
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;
|
||||
if (extIndex >= 0) {
|
||||
extension = name.mid(extIndex);
|
||||
prefix = name.mid(0, extIndex);
|
||||
}
|
||||
QString nameBase = dir.absolutePath() + '/' + prefix, result = nameBase + extension;
|
||||
for (int i = 0; result.toLower() != cur.toLower() && QFileInfo(result).exists(); ++i) {
|
||||
result = nameBase + qsl(" (%1)").arg(i + 2) + extension;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString filedialogAllFilesFilter() {
|
||||
#ifdef Q_OS_WIN
|
||||
return qsl("All files (*.*)");
|
||||
#else // Q_OS_WIN
|
||||
return qsl("All files (*)");
|
||||
#endif // Q_OS_WIN
|
||||
}
|
||||
|
||||
namespace File {
|
||||
|
||||
void OpenEmailLink(const QString &email) {
|
||||
base::TaskQueue::Main().Put([email] {
|
||||
Platform::File::UnsafeOpenEmailLink(email);
|
||||
});
|
||||
}
|
||||
|
||||
void OpenWith(const QString &filepath, QPoint menuPosition) {
|
||||
base::TaskQueue::Main().Put([filepath, menuPosition] {
|
||||
if (!Platform::File::UnsafeShowOpenWithDropdown(filepath, menuPosition)) {
|
||||
if (!Platform::File::UnsafeShowOpenWith(filepath)) {
|
||||
Platform::File::UnsafeLaunch(filepath);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Launch(const QString &filepath) {
|
||||
base::TaskQueue::Main().Put([filepath] {
|
||||
Platform::File::UnsafeLaunch(filepath);
|
||||
});
|
||||
}
|
||||
|
||||
void ShowInFolder(const QString &filepath) {
|
||||
base::TaskQueue::Main().Put([filepath] {
|
||||
Platform::File::UnsafeShowInFolder(filepath);
|
||||
});
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
void UnsafeOpenEmailLinkDefault(const QString &email) {
|
||||
auto url = QUrl(qstr("mailto:") + email);
|
||||
QDesktopServices::openUrl(url);
|
||||
}
|
||||
|
||||
void UnsafeLaunchDefault(const QString &filepath) {
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace File
|
||||
|
||||
namespace FileDialog {
|
||||
namespace {
|
||||
|
||||
base::Observable<QueryUpdate> QueryDoneObservable;
|
||||
|
||||
struct Query {
|
||||
enum class Type {
|
||||
ReadFile,
|
||||
ReadFiles,
|
||||
WriteFile,
|
||||
ReadFolder,
|
||||
};
|
||||
Query(Type type
|
||||
, const QString &caption = QString()
|
||||
, const QString &filter = QString()
|
||||
, const QString &filePath = QString()) : id(rand_value<QueryId>())
|
||||
, type(type)
|
||||
, caption(caption)
|
||||
, filter(filter)
|
||||
, filePath(filePath) {
|
||||
}
|
||||
QueryId id;
|
||||
Type type;
|
||||
QString caption, filter, filePath;
|
||||
};
|
||||
|
||||
using QueryList = QList<Query>;
|
||||
NeverFreedPointer<QueryList> Queries;
|
||||
|
||||
void StartCallback() {
|
||||
Queries.createIfNull();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
QueryId queryReadFile(const QString &caption, const QString &filter) {
|
||||
Queries.createIfNull();
|
||||
|
||||
Queries->push_back(Query(Query::Type::ReadFile, caption, filter));
|
||||
Global::RefHandleFileDialogQueue().call();
|
||||
return Queries->back().id;
|
||||
}
|
||||
|
||||
QueryId queryReadFiles(const QString &caption, const QString &filter) {
|
||||
Queries.createIfNull();
|
||||
|
||||
Queries->push_back(Query(Query::Type::ReadFiles, caption, filter));
|
||||
Global::RefHandleFileDialogQueue().call();
|
||||
return Queries->back().id;
|
||||
}
|
||||
|
||||
QueryId queryWriteFile(const QString &caption, const QString &filter, const QString &filePath) {
|
||||
Queries.createIfNull();
|
||||
|
||||
Queries->push_back(Query(Query::Type::WriteFile, caption, filter, filePath));
|
||||
Global::RefHandleFileDialogQueue().call();
|
||||
return Queries->back().id;
|
||||
}
|
||||
|
||||
QueryId queryReadFolder(const QString &caption) {
|
||||
Queries.createIfNull();
|
||||
|
||||
Queries->push_back(Query(Query::Type::ReadFolder, caption));
|
||||
Global::RefHandleFileDialogQueue().call();
|
||||
return Queries->back().id;
|
||||
}
|
||||
|
||||
bool processQuery() {
|
||||
if (!Queries || !Global::started() || Queries->isEmpty()) return false;
|
||||
|
||||
auto query = Queries->front();
|
||||
Queries->pop_front();
|
||||
|
||||
QueryUpdate update(query.id);
|
||||
|
||||
switch (query.type) {
|
||||
case Query::Type::ReadFile: {
|
||||
QString file;
|
||||
QByteArray remoteContent;
|
||||
if (filedialogGetOpenFile(file, remoteContent, query.caption, query.filter)) {
|
||||
if (!file.isEmpty()) {
|
||||
update.filePaths.push_back(file);
|
||||
}
|
||||
update.remoteContent = remoteContent;
|
||||
}
|
||||
} break;
|
||||
|
||||
case Query::Type::ReadFiles: {
|
||||
QStringList files;
|
||||
QByteArray remoteContent;
|
||||
if (filedialogGetOpenFiles(files, remoteContent, query.caption, query.filter)) {
|
||||
update.filePaths = files;
|
||||
update.remoteContent = remoteContent;
|
||||
}
|
||||
} break;
|
||||
|
||||
case Query::Type::WriteFile: {
|
||||
QString file;
|
||||
if (filedialogGetSaveFile(file, query.caption, query.filter, query.filePath)) {
|
||||
if (!file.isEmpty()) {
|
||||
update.filePaths.push_back(file);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case Query::Type::ReadFolder: {
|
||||
QString folder;
|
||||
if (filedialogGetDir(folder, query.caption, query.filePath)) {
|
||||
if (!folder.isEmpty()) {
|
||||
update.filePaths.push_back(folder);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
// No one knows what happened during filedialogGet*() call in the event loop.
|
||||
if (!Queries || !Global::started()) return false;
|
||||
|
||||
QueryDone().notify(std::move(update));
|
||||
return true;
|
||||
}
|
||||
|
||||
base::Observable<QueryUpdate> &QueryDone() {
|
||||
return QueryDoneObservable;
|
||||
}
|
||||
|
||||
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)] {
|
||||
auto file = QString();
|
||||
auto remoteContent = QByteArray();
|
||||
if (filedialogGetOpenFile(file, remoteContent, caption, filter) && (!file.isEmpty() || !remoteContent.isEmpty())) {
|
||||
if (callback) {
|
||||
auto result = OpenResult();
|
||||
if (!file.isEmpty()) {
|
||||
result.paths.push_back(file);
|
||||
}
|
||||
result.remoteContent = remoteContent;
|
||||
callback(result);
|
||||
}
|
||||
} else if (failed) {
|
||||
failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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)] {
|
||||
auto files = QStringList();
|
||||
auto remoteContent = QByteArray();
|
||||
if (filedialogGetOpenFiles(files, remoteContent, caption, filter) && (!files.isEmpty() || !remoteContent.isEmpty())) {
|
||||
if (callback) {
|
||||
auto result = OpenResult();
|
||||
result.paths = files;
|
||||
result.remoteContent = remoteContent;
|
||||
callback(result);
|
||||
}
|
||||
} else if (failed) {
|
||||
failed();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
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)] {
|
||||
auto file = QString();
|
||||
if (filedialogGetSaveFile(file, caption, filter, initialPath)) {
|
||||
if (callback) {
|
||||
callback(file);
|
||||
}
|
||||
} else if (failed) {
|
||||
failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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)] {
|
||||
auto folder = QString();
|
||||
if (filedialogGetDir(folder, caption, initialPath) && !folder.isEmpty()) {
|
||||
if (callback) {
|
||||
callback(folder);
|
||||
}
|
||||
} else if (failed) {
|
||||
failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace FileDialog
|
||||
|
@ -23,16 +23,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "core/observer.h"
|
||||
|
||||
// legacy
|
||||
bool filedialogGetOpenFiles(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter);
|
||||
bool filedialogGetOpenFile(QString &file, QByteArray &remoteContent, const QString &caption, const QString &filter);
|
||||
bool filedialogGetSaveFile(QString &file, const QString &caption, const QString &filter, const QString &initialPath);
|
||||
bool filedialogGetDir(QString &dir, const QString &caption, const QString &initialPath);
|
||||
|
||||
QString filedialogDefaultName(const QString &prefix, const QString &extension, const QString &path = QString(), bool skipExistance = false);
|
||||
QString filedialogNextFilename(const QString &name, const QString &cur, const QString &path = QString());
|
||||
|
||||
QString filedialogAllFilesFilter();
|
||||
|
||||
namespace File {
|
||||
|
||||
// Those functions are async wrappers to Platform::File::Unsafe* calls.
|
||||
@ -54,6 +49,18 @@ void UnsafeLaunchDefault(const QString &filepath);
|
||||
} // namespace File
|
||||
|
||||
namespace FileDialog {
|
||||
|
||||
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()>());
|
||||
|
||||
QString AllFilesFilter();
|
||||
|
||||
namespace internal {
|
||||
|
||||
enum class Type {
|
||||
@ -68,34 +75,4 @@ void InitLastPathDefault();
|
||||
bool GetDefault(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, ::FileDialog::internal::Type type, QString startFile);
|
||||
|
||||
} // namespace internal
|
||||
|
||||
using QueryId = uint64;
|
||||
struct QueryUpdate {
|
||||
QueryUpdate(QueryId id) : queryId(id) {
|
||||
}
|
||||
QueryId queryId;
|
||||
QStringList filePaths;
|
||||
QByteArray remoteContent;
|
||||
};
|
||||
|
||||
QueryId queryReadFile(const QString &caption, const QString &filter);
|
||||
QueryId queryReadFiles(const QString &caption, const QString &filter);
|
||||
QueryId queryWriteFile(const QString &caption, const QString &filter, const QString &filePath);
|
||||
QueryId queryReadFolder(const QString &caption);
|
||||
|
||||
// Returns false if no need to call it anymore right now.
|
||||
// NB! This function enters an event loop.
|
||||
bool processQuery();
|
||||
|
||||
base::Observable<QueryUpdate> &QueryDone();
|
||||
|
||||
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()>());
|
||||
|
||||
} // namespace FileDialog
|
||||
|
@ -615,7 +615,6 @@ struct Data {
|
||||
uint64 LaunchId = 0;
|
||||
SingleDelayedCall HandleHistoryUpdate = { App::app(), "call_handleHistoryUpdate" };
|
||||
SingleDelayedCall HandleUnreadCounterUpdate = { App::app(), "call_handleUnreadCounterUpdate" };
|
||||
SingleDelayedCall HandleFileDialogQueue = { App::app(), "call_handleFileDialogQueue" };
|
||||
SingleDelayedCall HandleDelayedPeerUpdates = { App::app(), "call_handleDelayedPeerUpdates" };
|
||||
SingleDelayedCall HandleObservables = { App::app(), "call_handleObservables" };
|
||||
|
||||
@ -737,7 +736,6 @@ void finish() {
|
||||
DefineReadOnlyVar(Global, uint64, LaunchId);
|
||||
DefineRefVar(Global, SingleDelayedCall, HandleHistoryUpdate);
|
||||
DefineRefVar(Global, SingleDelayedCall, HandleUnreadCounterUpdate);
|
||||
DefineRefVar(Global, SingleDelayedCall, HandleFileDialogQueue);
|
||||
DefineRefVar(Global, SingleDelayedCall, HandleDelayedPeerUpdates);
|
||||
DefineRefVar(Global, SingleDelayedCall, HandleObservables);
|
||||
|
||||
|
@ -317,7 +317,6 @@ void finish();
|
||||
DeclareReadOnlyVar(uint64, LaunchId);
|
||||
DeclareRefVar(SingleDelayedCall, HandleHistoryUpdate);
|
||||
DeclareRefVar(SingleDelayedCall, HandleUnreadCounterUpdate);
|
||||
DeclareRefVar(SingleDelayedCall, HandleFileDialogQueue);
|
||||
DeclareRefVar(SingleDelayedCall, HandleDelayedPeerUpdates);
|
||||
DeclareRefVar(SingleDelayedCall, HandleObservables);
|
||||
|
||||
|
@ -1489,13 +1489,12 @@ void HistoryInner::copyContextUrl() {
|
||||
void HistoryInner::savePhotoToFile(PhotoData *photo) {
|
||||
if (!photo || !photo->date || !photo->loaded()) return;
|
||||
|
||||
QString file;
|
||||
auto filter = qsl("JPEG Image (*.jpg);;") + filedialogAllFilesFilter();
|
||||
if (filedialogGetSaveFile(file, lang(lng_save_photo), filter, filedialogDefaultName(qsl("photo"), qsl(".jpg")))) {
|
||||
if (!file.isEmpty()) {
|
||||
photo->full->pix().toImage().save(file, "JPG");
|
||||
auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter();
|
||||
FileDialog::GetWritePath(lang(lng_save_photo), filter, filedialogDefaultName(qsl("photo"), qsl(".jpg")), base::lambda_guarded(this, [this, photo](const QString &result) {
|
||||
if (!result.isEmpty()) {
|
||||
photo->full->pix().toImage().save(result, "JPG");
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void HistoryInner::copyContextImage() {
|
||||
@ -3169,9 +3168,6 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent)
|
||||
_attachToggle->setClickedCallback(App::LambdaDelayed(st::historyAttach.ripple.hideDuration, this, [this] {
|
||||
chooseAttach();
|
||||
}));
|
||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
||||
notifyFileQueryUpdated(update);
|
||||
});
|
||||
|
||||
_updateHistoryItems.setSingleShot(true);
|
||||
connect(&_updateHistoryItems, SIGNAL(timeout()), this, SLOT(onUpdateHistoryItems()));
|
||||
@ -5594,40 +5590,33 @@ void HistoryWidget::step_recording(float64 ms, bool timer) {
|
||||
void HistoryWidget::chooseAttach() {
|
||||
if (!_history) return;
|
||||
|
||||
auto filter = filedialogAllFilesFilter() + qsl(";;Image files (*") + cImgExtensions().join(qsl(" *")) + qsl(")");
|
||||
auto filter = FileDialog::AllFilesFilter() + qsl(";;Image files (*") + cImgExtensions().join(qsl(" *")) + qsl(")");
|
||||
|
||||
_attachFilesQueryId = FileDialog::queryReadFiles(lang(lng_choose_files), filter);
|
||||
}
|
||||
|
||||
void HistoryWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
||||
if (_attachFilesQueryId != update.queryId) {
|
||||
return;
|
||||
}
|
||||
_attachFilesQueryId = 0;
|
||||
|
||||
if (update.filePaths.isEmpty() && update.remoteContent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!update.remoteContent.isEmpty()) {
|
||||
auto animated = false;
|
||||
auto image = App::readImage(update.remoteContent, nullptr, false, &animated);
|
||||
if (!image.isNull() && !animated) {
|
||||
confirmSendingFiles(image, update.remoteContent);
|
||||
} else {
|
||||
uploadFile(update.remoteContent, SendMediaType::File);
|
||||
FileDialog::GetOpenPaths(lang(lng_choose_files), filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
||||
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
auto lists = getSendingFilesLists(update.filePaths);
|
||||
if (lists.allFilesForCompress) {
|
||||
confirmSendingFiles(lists);
|
||||
|
||||
if (!result.remoteContent.isEmpty()) {
|
||||
auto animated = false;
|
||||
auto image = App::readImage(result.remoteContent, nullptr, false, &animated);
|
||||
if (!image.isNull() && !animated) {
|
||||
confirmSendingFiles(image, result.remoteContent);
|
||||
} else {
|
||||
uploadFile(result.remoteContent, SendMediaType::File);
|
||||
}
|
||||
} else {
|
||||
validateSendingFiles(lists, [this](const QStringList &files) {
|
||||
uploadFiles(files, SendMediaType::File);
|
||||
return true;
|
||||
});
|
||||
auto lists = getSendingFilesLists(result.paths);
|
||||
if (lists.allFilesForCompress) {
|
||||
confirmSendingFiles(lists);
|
||||
} else {
|
||||
validateSendingFiles(lists, [this](const QStringList &files) {
|
||||
uploadFiles(files, SendMediaType::File);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void HistoryWidget::sendButtonClicked() {
|
||||
|
@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#pragma once
|
||||
|
||||
#include "localimageloader.h"
|
||||
#include "core/file_utilities.h"
|
||||
#include "ui/widgets/tooltip.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
@ -849,7 +848,6 @@ private:
|
||||
void recordUpdateCallback(QPoint globalPos);
|
||||
void chooseAttach();
|
||||
void historyDownAnimationFinish();
|
||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
||||
void sendButtonClicked();
|
||||
struct SendingFilesLists {
|
||||
QList<QUrl> nonLocalUrls;
|
||||
@ -1139,8 +1137,6 @@ private:
|
||||
BasicAnimation _a_recording;
|
||||
anim::value a_recordingLevel;
|
||||
|
||||
FileDialog::QueryId _attachFilesQueryId = 0;
|
||||
|
||||
bool kbWasHidden() const;
|
||||
|
||||
bool _kbShown = false;
|
||||
|
@ -43,14 +43,7 @@ SignupWidget::SignupWidget(QWidget *parent, Widget::Data *data) : Step(parent, d
|
||||
, _checkRequest(this) {
|
||||
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
|
||||
|
||||
_photo->setClickedCallback(App::LambdaDelayed(st::defaultActiveButton.ripple.hideDuration, this, [this] {
|
||||
auto imgExtensions = cImgExtensions();
|
||||
auto filter = qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + filedialogAllFilesFilter();
|
||||
_readPhotoFileQueryId = FileDialog::queryReadFile(lang(lng_choose_image), filter);
|
||||
}));
|
||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
||||
notifyFileQueryUpdated(update);
|
||||
});
|
||||
setupPhotoButton();
|
||||
|
||||
if (_invertOrder) {
|
||||
setTabOrder(_last, _first);
|
||||
@ -62,28 +55,30 @@ SignupWidget::SignupWidget(QWidget *parent, Widget::Data *data) : Step(parent, d
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
void SignupWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
||||
if (_readPhotoFileQueryId != update.queryId) {
|
||||
return;
|
||||
}
|
||||
_readPhotoFileQueryId = 0;
|
||||
if (update.remoteContent.isEmpty() && update.filePaths.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
void SignupWidget::setupPhotoButton() {
|
||||
_photo->setClickedCallback(App::LambdaDelayed(st::defaultActiveButton.ripple.hideDuration, this, [this] {
|
||||
auto imgExtensions = cImgExtensions();
|
||||
auto filter = qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + FileDialog::AllFilesFilter();
|
||||
FileDialog::GetOpenPath(lang(lng_choose_image), filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
||||
if (result.remoteContent.isEmpty() && result.paths.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QImage img;
|
||||
if (!update.remoteContent.isEmpty()) {
|
||||
img = App::readImage(update.remoteContent);
|
||||
} else {
|
||||
img = App::readImage(update.filePaths.front());
|
||||
}
|
||||
QImage img;
|
||||
if (!result.remoteContent.isEmpty()) {
|
||||
img = App::readImage(result.remoteContent);
|
||||
} else {
|
||||
img = App::readImage(result.paths.front());
|
||||
}
|
||||
|
||||
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
|
||||
showError(lang(lng_bad_photo));
|
||||
return;
|
||||
}
|
||||
auto box = Ui::show(Box<PhotoCropBox>(img, PeerId(0)));
|
||||
connect(box, SIGNAL(ready(const QImage&)), this, SLOT(onPhotoReady(const QImage&)));
|
||||
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
|
||||
showError(lang(lng_bad_photo));
|
||||
return;
|
||||
}
|
||||
auto box = Ui::show(Box<PhotoCropBox>(img, PeerId(0)));
|
||||
connect(box, SIGNAL(ready(const QImage&)), this, SLOT(onPhotoReady(const QImage&)));
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
void SignupWidget::resizeEvent(QResizeEvent *e) {
|
||||
|
@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#pragma once
|
||||
|
||||
#include "intro/introwidget.h"
|
||||
#include "core/file_utilities.h"
|
||||
|
||||
namespace Ui {
|
||||
class RoundButton;
|
||||
@ -52,7 +51,7 @@ private slots:
|
||||
void onPhotoReady(const QImage &img);
|
||||
|
||||
private:
|
||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
||||
void setupPhotoButton();
|
||||
|
||||
void nameSubmitDone(const MTPauth_Authorization &result);
|
||||
bool nameSubmitFail(const RPCError &error);
|
||||
@ -67,8 +66,6 @@ private:
|
||||
QString _firstName, _lastName;
|
||||
mtpRequestId _sentRequest = 0;
|
||||
|
||||
FileDialog::QueryId _readPhotoFileQueryId = 0;
|
||||
|
||||
bool _invertOrder = false;
|
||||
|
||||
object_ptr<QTimer> _checkRequest;
|
||||
|
@ -62,6 +62,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "window/player_wrap_widget.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "mtproto/dc_options.h"
|
||||
#include "core/file_utilities.h"
|
||||
#include "auth_session.h"
|
||||
|
||||
StackItemSection::StackItemSection(std::unique_ptr<Window::SectionMemento> &&memento) : StackItem(nullptr)
|
||||
|
@ -741,7 +741,7 @@ void MediaView::onSaveAs() {
|
||||
if (pattern.isEmpty()) {
|
||||
filter = QString();
|
||||
} else {
|
||||
filter = mimeType.filterString() + qsl(";;") + filedialogAllFilesFilter();
|
||||
filter = mimeType.filterString() + qsl(";;") + FileDialog::AllFilesFilter();
|
||||
}
|
||||
|
||||
psBringToBack(this);
|
||||
@ -772,14 +772,15 @@ void MediaView::onSaveAs() {
|
||||
if (!_photo || !_photo->loaded()) return;
|
||||
|
||||
psBringToBack(this);
|
||||
auto filter = qsl("JPEG Image (*.jpg);;") + filedialogAllFilesFilter();
|
||||
auto gotName = filedialogGetSaveFile(file, lang(lng_save_photo), filter, filedialogDefaultName(qsl("photo"), qsl(".jpg")));
|
||||
psShowOverAll(this);
|
||||
if (gotName) {
|
||||
if (!file.isEmpty()) {
|
||||
_photo->full->pix().toImage().save(file, "JPG");
|
||||
auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter();
|
||||
FileDialog::GetWritePath(lang(lng_save_photo), filter, filedialogDefaultName(qsl("photo"), qsl(".jpg")), base::lambda_guarded(this, [this, photo = _photo](const QString &result) {
|
||||
if (!result.isEmpty() && _photo == photo && photo->loaded()) {
|
||||
photo->full->pix().toImage().save(result, "JPG");
|
||||
}
|
||||
}
|
||||
psShowOverAll(this);
|
||||
}), base::lambda_guarded(this, [this] {
|
||||
psShowOverAll(this);
|
||||
}));
|
||||
}
|
||||
activateWindow();
|
||||
Sandbox::setActiveWindow(this);
|
||||
|
@ -38,7 +38,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "history/history_location_manager.h"
|
||||
#include "ui/widgets/tooltip.h"
|
||||
#include "core/file_utilities.h"
|
||||
#include "serialize/serialize_common.h"
|
||||
|
||||
namespace {
|
||||
@ -498,14 +497,6 @@ void Messenger::call_handleUnreadCounterUpdate() {
|
||||
Global::RefUnreadCounterUpdate().notify(true);
|
||||
}
|
||||
|
||||
void Messenger::call_handleFileDialogQueue() {
|
||||
while (true) {
|
||||
if (!FileDialog::processQuery()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::call_handleDelayedPeerUpdates() {
|
||||
Notify::peerUpdatedSendDelayed();
|
||||
}
|
||||
|
@ -120,7 +120,6 @@ public slots:
|
||||
|
||||
void call_handleHistoryUpdate();
|
||||
void call_handleUnreadCounterUpdate();
|
||||
void call_handleFileDialogQueue();
|
||||
void call_handleDelayedPeerUpdates();
|
||||
void call_handleObservables();
|
||||
|
||||
|
@ -74,9 +74,6 @@ CoverWidget::CoverWidget(QWidget *parent, PeerData *peer) : TWidget(parent)
|
||||
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||
notifyPeerUpdated(update);
|
||||
}));
|
||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
||||
notifyFileQueryUpdated(update);
|
||||
});
|
||||
|
||||
connect(App::app(), SIGNAL(peerPhotoDone(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
||||
connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
||||
@ -488,33 +485,25 @@ void CoverWidget::onShareContact() {
|
||||
|
||||
void CoverWidget::onSetPhoto() {
|
||||
App::CallDelayed(st::profilePrimaryButton.ripple.hideDuration, this, [this] {
|
||||
QStringList imgExtensions(cImgExtensions());
|
||||
QString filter(qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + filedialogAllFilesFilter());
|
||||
auto imgExtensions = cImgExtensions();
|
||||
auto filter = qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + FileDialog::AllFilesFilter();
|
||||
FileDialog::GetOpenPath(lang(lng_choose_image), filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
||||
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_setPhotoFileQueryId = FileDialog::queryReadFile(lang(lng_choose_image), filter);
|
||||
QImage img;
|
||||
if (!result.remoteContent.isEmpty()) {
|
||||
img = App::readImage(result.remoteContent);
|
||||
} else {
|
||||
img = App::readImage(result.paths.front());
|
||||
}
|
||||
|
||||
showSetPhotoBox(img);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
void CoverWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
||||
if (_setPhotoFileQueryId != update.queryId) {
|
||||
return;
|
||||
}
|
||||
_setPhotoFileQueryId = 0;
|
||||
|
||||
if (update.filePaths.isEmpty() && update.remoteContent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QImage img;
|
||||
if (!update.remoteContent.isEmpty()) {
|
||||
img = App::readImage(update.remoteContent);
|
||||
} else {
|
||||
img = App::readImage(update.filePaths.front());
|
||||
}
|
||||
|
||||
showSetPhotoBox(img);
|
||||
}
|
||||
|
||||
void CoverWidget::showSetPhotoBox(const QImage &img) {
|
||||
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
|
||||
Ui::show(Box<InformBox>(lang(lng_bad_photo)));
|
||||
|
@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#pragma once
|
||||
|
||||
#include "core/observer.h"
|
||||
#include "core/file_utilities.h"
|
||||
|
||||
namespace style {
|
||||
struct RoundButton;
|
||||
@ -83,7 +82,6 @@ protected:
|
||||
private:
|
||||
// Observed notifications.
|
||||
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
||||
|
||||
// Counts userpic button left offset for a new widget width.
|
||||
int countPhotoLeft(int newWidth) const;
|
||||
@ -138,8 +136,6 @@ private:
|
||||
|
||||
int _onlineCount = 0;
|
||||
|
||||
FileDialog::QueryId _setPhotoFileQueryId = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Profile
|
||||
|
@ -32,6 +32,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "mainwindow.h"
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "window/themes/window_theme_editor.h"
|
||||
#include "core/file_utilities.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
@ -199,9 +200,6 @@ void BackgroundRow::updateImage() {
|
||||
BackgroundWidget::BackgroundWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_background)) {
|
||||
createControls();
|
||||
|
||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
||||
notifyFileQueryUpdated(update);
|
||||
});
|
||||
using Update = Window::Theme::BackgroundUpdate;
|
||||
subscribe(Window::Theme::Background(), [this](const Update &update) {
|
||||
if (update.type == Update::Type::New) {
|
||||
@ -248,9 +246,40 @@ void BackgroundWidget::needBackgroundUpdate(bool tile) {
|
||||
void BackgroundWidget::onChooseFromFile() {
|
||||
auto imgExtensions = cImgExtensions();
|
||||
auto filters = QStringList(qsl("Theme files (*.tdesktop-theme *.tdesktop-palette *") + imgExtensions.join(qsl(" *")) + qsl(")"));
|
||||
filters.push_back(filedialogAllFilesFilter());
|
||||
filters.push_back(FileDialog::AllFilesFilter());
|
||||
FileDialog::GetOpenPath(lang(lng_choose_image), filters.join(qsl(";;")), base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
||||
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_chooseFromFileQueryId = FileDialog::queryReadFile(lang(lng_choose_image), filters.join(qsl(";;")));
|
||||
if (!result.paths.isEmpty()) {
|
||||
auto filePath = result.paths.front();
|
||||
if (filePath.endsWith(qstr(".tdesktop-theme"), Qt::CaseInsensitive)
|
||||
|| filePath.endsWith(qstr(".tdesktop-palette"), Qt::CaseInsensitive)) {
|
||||
Window::Theme::Apply(filePath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QImage img;
|
||||
if (!result.remoteContent.isEmpty()) {
|
||||
img = App::readImage(result.remoteContent);
|
||||
} else {
|
||||
img = App::readImage(result.paths.front());
|
||||
}
|
||||
|
||||
if (img.isNull() || img.width() <= 0 || img.height() <= 0) return;
|
||||
|
||||
if (img.width() > 4096 * img.height()) {
|
||||
img = img.copy((img.width() - 4096 * img.height()) / 2, 0, 4096 * img.height(), img.height());
|
||||
} else if (img.height() > 4096 * img.width()) {
|
||||
img = img.copy(0, (img.height() - 4096 * img.width()) / 2, img.width(), 4096 * img.width());
|
||||
}
|
||||
|
||||
Window::Theme::Background()->setImage(Window::Theme::kCustomBackground, std::move(img));
|
||||
_tile->setChecked(false);
|
||||
_background->updateImage();
|
||||
}));
|
||||
}
|
||||
|
||||
void BackgroundWidget::onEditTheme() {
|
||||
@ -261,45 +290,6 @@ void BackgroundWidget::onUseDefaultTheme() {
|
||||
Window::Theme::ApplyDefault();
|
||||
}
|
||||
|
||||
void BackgroundWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
||||
if (_chooseFromFileQueryId != update.queryId) {
|
||||
return;
|
||||
}
|
||||
_chooseFromFileQueryId = 0;
|
||||
|
||||
if (update.filePaths.isEmpty() && update.remoteContent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!update.filePaths.isEmpty()) {
|
||||
auto filePath = update.filePaths.front();
|
||||
if (filePath.endsWith(qstr(".tdesktop-theme"), Qt::CaseInsensitive)
|
||||
|| filePath.endsWith(qstr(".tdesktop-palette"), Qt::CaseInsensitive)) {
|
||||
Window::Theme::Apply(filePath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QImage img;
|
||||
if (!update.remoteContent.isEmpty()) {
|
||||
img = App::readImage(update.remoteContent);
|
||||
} else {
|
||||
img = App::readImage(update.filePaths.front());
|
||||
}
|
||||
|
||||
if (img.isNull() || img.width() <= 0 || img.height() <= 0) return;
|
||||
|
||||
if (img.width() > 4096 * img.height()) {
|
||||
img = img.copy((img.width() - 4096 * img.height()) / 2, 0, 4096 * img.height(), img.height());
|
||||
} else if (img.height() > 4096 * img.width()) {
|
||||
img = img.copy(0, (img.height() - 4096 * img.width()) / 2, img.width(), 4096 * img.width());
|
||||
}
|
||||
|
||||
Window::Theme::Background()->setImage(Window::Theme::kCustomBackground, std::move(img));
|
||||
_tile->setChecked(false);
|
||||
_background->updateImage();
|
||||
}
|
||||
|
||||
void BackgroundWidget::onTile() {
|
||||
Window::Theme::Background()->setTile(_tile->checked());
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
|
||||
#include "settings/settings_block_widget.h"
|
||||
#include "ui/effects/radial_animation.h"
|
||||
#include "core/file_utilities.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
@ -82,14 +81,11 @@ private slots:
|
||||
private:
|
||||
void createControls();
|
||||
void needBackgroundUpdate(bool tile);
|
||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
||||
|
||||
object_ptr<BackgroundRow> _background = { nullptr };
|
||||
object_ptr<Ui::Checkbox> _tile = { nullptr };
|
||||
object_ptr<Ui::WidgetSlideWrap<Ui::Checkbox>> _adaptive = { nullptr };
|
||||
|
||||
FileDialog::QueryId _chooseFromFileQueryId = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Settings
|
||||
|
@ -59,9 +59,6 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent,
|
||||
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||
notifyPeerUpdated(update);
|
||||
}));
|
||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
||||
notifyFileQueryUpdated(update);
|
||||
});
|
||||
|
||||
connect(App::app(), SIGNAL(peerPhotoDone(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
||||
connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
||||
@ -303,35 +300,27 @@ void CoverWidget::refreshStatusText() {
|
||||
|
||||
void CoverWidget::onSetPhoto() {
|
||||
auto imageExtensions = cImgExtensions();
|
||||
auto filter = qsl("Image files (*") + imageExtensions.join(qsl(" *")) + qsl(");;") + filedialogAllFilesFilter();
|
||||
auto filter = qsl("Image files (*") + imageExtensions.join(qsl(" *")) + qsl(");;") + FileDialog::AllFilesFilter();
|
||||
FileDialog::GetOpenPath(lang(lng_choose_image), filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
||||
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_setPhotoFileQueryId = FileDialog::queryReadFile(lang(lng_choose_image), filter);
|
||||
QImage img;
|
||||
if (!result.remoteContent.isEmpty()) {
|
||||
img = App::readImage(result.remoteContent);
|
||||
} else {
|
||||
img = App::readImage(result.paths.front());
|
||||
}
|
||||
|
||||
showSetPhotoBox(img);
|
||||
}));
|
||||
}
|
||||
|
||||
void CoverWidget::onEditName() {
|
||||
Ui::show(Box<EditNameTitleBox>(self()));
|
||||
}
|
||||
|
||||
void CoverWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
||||
if (_setPhotoFileQueryId != update.queryId) {
|
||||
return;
|
||||
}
|
||||
_setPhotoFileQueryId = 0;
|
||||
|
||||
if (update.filePaths.isEmpty() && update.remoteContent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QImage img;
|
||||
if (!update.remoteContent.isEmpty()) {
|
||||
img = App::readImage(update.remoteContent);
|
||||
} else {
|
||||
img = App::readImage(update.filePaths.front());
|
||||
}
|
||||
|
||||
showSetPhotoBox(img);
|
||||
}
|
||||
|
||||
void CoverWidget::showSetPhotoBox(const QImage &img) {
|
||||
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
|
||||
Ui::show(Box<InformBox>(lang(lng_bad_photo)));
|
||||
|
@ -21,8 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#pragma once
|
||||
|
||||
#include "core/observer.h"
|
||||
#include "core/file_utilities.h"
|
||||
|
||||
#include "settings/settings_block_widget.h"
|
||||
|
||||
namespace Ui {
|
||||
@ -71,7 +69,6 @@ protected:
|
||||
private:
|
||||
// Observed notifications.
|
||||
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
||||
|
||||
PhotoData *validatePhoto() const;
|
||||
|
||||
@ -105,8 +102,6 @@ private:
|
||||
|
||||
int _dividerTop = 0;
|
||||
|
||||
FileDialog::QueryId _setPhotoFileQueryId = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Settings
|
||||
|
@ -160,9 +160,6 @@ GeneralWidget::GeneralWidget(QWidget *parent, UserData *self) : BlockWidget(pare
|
||||
, _changeLanguage(this, lang(lng_settings_change_lang), st::boxLinkButton) {
|
||||
connect(_changeLanguage, SIGNAL(clicked()), this, SLOT(onChangeLanguage()));
|
||||
subscribe(Global::RefChooseCustomLang(), [this]() { chooseCustomLang(); });
|
||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
||||
notifyFileQueryUpdated(update);
|
||||
});
|
||||
refreshControls();
|
||||
}
|
||||
|
||||
@ -210,36 +207,28 @@ void GeneralWidget::refreshControls() {
|
||||
void GeneralWidget::chooseCustomLang() {
|
||||
auto filter = qsl("Language files (*.strings)");
|
||||
auto title = qsl("Choose language .strings file");
|
||||
FileDialog::GetOpenPath(title, filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
||||
if (result.paths.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_chooseLangFileQueryId = FileDialog::queryReadFile(title, filter);
|
||||
}
|
||||
|
||||
void GeneralWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
||||
if (_chooseLangFileQueryId != update.queryId) {
|
||||
return;
|
||||
}
|
||||
_chooseLangFileQueryId = 0;
|
||||
|
||||
if (update.filePaths.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_testLanguage = QFileInfo(update.filePaths.front()).absoluteFilePath();
|
||||
LangLoaderPlain loader(_testLanguage, langLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok));
|
||||
if (loader.errors().isEmpty()) {
|
||||
LangLoaderResult result = loader.found();
|
||||
auto text = result.value(lng_sure_save_language, langOriginal(lng_sure_save_language)),
|
||||
save = result.value(lng_box_ok, langOriginal(lng_box_ok)),
|
||||
cancel = result.value(lng_cancel, langOriginal(lng_cancel));
|
||||
Ui::show(Box<ConfirmBox>(text, save, cancel, base::lambda_guarded(this, [this] {
|
||||
cSetLangFile(_testLanguage);
|
||||
cSetLang(languageTest);
|
||||
Local::writeSettings();
|
||||
onRestart();
|
||||
})));
|
||||
} else {
|
||||
Ui::show(Box<InformBox>("Custom lang failed :(\n\nError: " + loader.errors()));
|
||||
}
|
||||
_testLanguage = QFileInfo(result.paths.front()).absoluteFilePath();
|
||||
LangLoaderPlain loader(_testLanguage, langLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok));
|
||||
if (loader.errors().isEmpty()) {
|
||||
LangLoaderResult result = loader.found();
|
||||
auto text = result.value(lng_sure_save_language, langOriginal(lng_sure_save_language)),
|
||||
save = result.value(lng_box_ok, langOriginal(lng_box_ok)),
|
||||
cancel = result.value(lng_cancel, langOriginal(lng_cancel));
|
||||
Ui::show(Box<ConfirmBox>(text, save, cancel, base::lambda_guarded(this, [this] {
|
||||
cSetLangFile(_testLanguage);
|
||||
cSetLang(languageTest);
|
||||
Local::writeSettings();
|
||||
onRestart();
|
||||
})));
|
||||
} else {
|
||||
Ui::show(Box<InformBox>("Custom lang failed :(\n\nError: " + loader.errors()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void GeneralWidget::onChangeLanguage() {
|
||||
|
@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#pragma once
|
||||
|
||||
#include "settings/settings_block_widget.h"
|
||||
#include "core/file_utilities.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
@ -106,7 +105,6 @@ private:
|
||||
void refreshControls();
|
||||
void updateWorkmode();
|
||||
void chooseCustomLang();
|
||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
||||
|
||||
object_ptr<Ui::LinkButton> _changeLanguage;
|
||||
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
||||
@ -119,7 +117,6 @@ private:
|
||||
object_ptr<Ui::WidgetSlideWrap<Ui::Checkbox>> _startMinimized = { nullptr };
|
||||
object_ptr<Ui::Checkbox> _addInSendTo = { nullptr };
|
||||
|
||||
FileDialog::QueryId _chooseLangFileQueryId = 0;
|
||||
QString _testLanguage;
|
||||
|
||||
};
|
||||
|
@ -1118,12 +1118,12 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals
|
||||
bool mp3 = (data->mime == qstr("audio/mp3"));
|
||||
name = already.isEmpty() ? (mp3 ? qsl(".mp3") : qsl(".ogg")) : already;
|
||||
filter = mp3 ? qsl("MP3 Audio (*.mp3);;") : qsl("OGG Opus Audio (*.ogg);;");
|
||||
filter += filedialogAllFilesFilter();
|
||||
filter += FileDialog::AllFilesFilter();
|
||||
caption = lang(lng_save_audio);
|
||||
prefix = qsl("audio");
|
||||
} else if (data->isVideo()) {
|
||||
name = already.isEmpty() ? qsl(".mov") : already;
|
||||
filter = qsl("MOV Video (*.mov);;") + filedialogAllFilesFilter();
|
||||
filter = qsl("MOV Video (*.mov);;") + FileDialog::AllFilesFilter();
|
||||
caption = lang(lng_save_video);
|
||||
prefix = qsl("video");
|
||||
} else {
|
||||
@ -1134,7 +1134,7 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals
|
||||
if (pattern.isEmpty()) {
|
||||
filter = QString();
|
||||
} else {
|
||||
filter = mimeType.filterString() + qsl(";;") + filedialogAllFilesFilter();
|
||||
filter = mimeType.filterString() + qsl(";;") + FileDialog::AllFilesFilter();
|
||||
}
|
||||
caption = lang(data->song() ? lng_save_audio_file : lng_save_file);
|
||||
prefix = qsl("doc");
|
||||
|
Loading…
Reference in New Issue
Block a user