mirror of https://github.com/procxx/kepka.git
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(_creating == CreatingGroupChannel ? lng_create_group_create : lng_create_group_next), [this] { onNext(); });
|
||||||
addButton(lang(_fromTypeChoose ? lng_create_group_back : lng_cancel), [this] { closeBox(); });
|
addButton(lang(_fromTypeChoose ? lng_create_group_back : lng_cancel), [this] { closeBox(); });
|
||||||
|
|
||||||
_photo->setClickedCallback(App::LambdaDelayed(st::defaultActiveButton.ripple.hideDuration, this, [this] {
|
setupPhotoButton();
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
updateMaxHeight();
|
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() {
|
void GroupInfoBox::setInnerFocus() {
|
||||||
_title->setFocusFast();
|
_title->setFocusFast();
|
||||||
}
|
}
|
||||||
|
@ -394,28 +411,6 @@ void GroupInfoBox::updateMaxHeight() {
|
||||||
setDimensions(st::boxWideWidth, newHeight);
|
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) {
|
void GroupInfoBox::onPhotoReady(const QImage &img) {
|
||||||
_photoImage = img;
|
_photoImage = img;
|
||||||
_photo->setImage(_photoImage);
|
_photo->setImage(_photoImage);
|
||||||
|
|
|
@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "boxes/abstractbox.h"
|
#include "boxes/abstractbox.h"
|
||||||
#include "core/file_utilities.h"
|
|
||||||
|
|
||||||
class ConfirmBox;
|
class ConfirmBox;
|
||||||
|
|
||||||
|
@ -103,7 +102,7 @@ private slots:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
void setupPhotoButton();
|
||||||
|
|
||||||
void creationDone(const MTPUpdates &updates);
|
void creationDone(const MTPUpdates &updates);
|
||||||
bool creationFail(const RPCError &e);
|
bool creationFail(const RPCError &e);
|
||||||
|
@ -125,8 +124,6 @@ private:
|
||||||
mtpRequestId _creationRequestId = 0;
|
mtpRequestId _creationRequestId = 0;
|
||||||
ChannelData *_createdChannel = nullptr;
|
ChannelData *_createdChannel = nullptr;
|
||||||
|
|
||||||
FileDialog::QueryId _setPhotoFileQueryId = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetupChannelBox : public BoxContent, public RPCSender {
|
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 "platform/platform_file_utilities.h"
|
||||||
#include "core/task_queue.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 {
|
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 {
|
namespace internal {
|
||||||
|
|
||||||
void InitLastPathDefault() {
|
void InitLastPathDefault() {
|
||||||
|
@ -76,318 +248,3 @@ bool GetDefault(QStringList &files, QByteArray &remoteContent, const QString &ca
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace FileDialog
|
} // 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"
|
#include "core/observer.h"
|
||||||
|
|
||||||
// legacy
|
// 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 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 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 filedialogNextFilename(const QString &name, const QString &cur, const QString &path = QString());
|
||||||
|
|
||||||
QString filedialogAllFilesFilter();
|
|
||||||
|
|
||||||
namespace File {
|
namespace File {
|
||||||
|
|
||||||
// Those functions are async wrappers to Platform::File::Unsafe* calls.
|
// Those functions are async wrappers to Platform::File::Unsafe* calls.
|
||||||
|
@ -54,6 +49,18 @@ void UnsafeLaunchDefault(const QString &filepath);
|
||||||
} // namespace File
|
} // namespace File
|
||||||
|
|
||||||
namespace FileDialog {
|
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 {
|
namespace internal {
|
||||||
|
|
||||||
enum class Type {
|
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);
|
bool GetDefault(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, ::FileDialog::internal::Type type, QString startFile);
|
||||||
|
|
||||||
} // namespace internal
|
} // 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
|
} // namespace FileDialog
|
||||||
|
|
|
@ -615,7 +615,6 @@ struct Data {
|
||||||
uint64 LaunchId = 0;
|
uint64 LaunchId = 0;
|
||||||
SingleDelayedCall HandleHistoryUpdate = { App::app(), "call_handleHistoryUpdate" };
|
SingleDelayedCall HandleHistoryUpdate = { App::app(), "call_handleHistoryUpdate" };
|
||||||
SingleDelayedCall HandleUnreadCounterUpdate = { App::app(), "call_handleUnreadCounterUpdate" };
|
SingleDelayedCall HandleUnreadCounterUpdate = { App::app(), "call_handleUnreadCounterUpdate" };
|
||||||
SingleDelayedCall HandleFileDialogQueue = { App::app(), "call_handleFileDialogQueue" };
|
|
||||||
SingleDelayedCall HandleDelayedPeerUpdates = { App::app(), "call_handleDelayedPeerUpdates" };
|
SingleDelayedCall HandleDelayedPeerUpdates = { App::app(), "call_handleDelayedPeerUpdates" };
|
||||||
SingleDelayedCall HandleObservables = { App::app(), "call_handleObservables" };
|
SingleDelayedCall HandleObservables = { App::app(), "call_handleObservables" };
|
||||||
|
|
||||||
|
@ -737,7 +736,6 @@ void finish() {
|
||||||
DefineReadOnlyVar(Global, uint64, LaunchId);
|
DefineReadOnlyVar(Global, uint64, LaunchId);
|
||||||
DefineRefVar(Global, SingleDelayedCall, HandleHistoryUpdate);
|
DefineRefVar(Global, SingleDelayedCall, HandleHistoryUpdate);
|
||||||
DefineRefVar(Global, SingleDelayedCall, HandleUnreadCounterUpdate);
|
DefineRefVar(Global, SingleDelayedCall, HandleUnreadCounterUpdate);
|
||||||
DefineRefVar(Global, SingleDelayedCall, HandleFileDialogQueue);
|
|
||||||
DefineRefVar(Global, SingleDelayedCall, HandleDelayedPeerUpdates);
|
DefineRefVar(Global, SingleDelayedCall, HandleDelayedPeerUpdates);
|
||||||
DefineRefVar(Global, SingleDelayedCall, HandleObservables);
|
DefineRefVar(Global, SingleDelayedCall, HandleObservables);
|
||||||
|
|
||||||
|
|
|
@ -317,7 +317,6 @@ void finish();
|
||||||
DeclareReadOnlyVar(uint64, LaunchId);
|
DeclareReadOnlyVar(uint64, LaunchId);
|
||||||
DeclareRefVar(SingleDelayedCall, HandleHistoryUpdate);
|
DeclareRefVar(SingleDelayedCall, HandleHistoryUpdate);
|
||||||
DeclareRefVar(SingleDelayedCall, HandleUnreadCounterUpdate);
|
DeclareRefVar(SingleDelayedCall, HandleUnreadCounterUpdate);
|
||||||
DeclareRefVar(SingleDelayedCall, HandleFileDialogQueue);
|
|
||||||
DeclareRefVar(SingleDelayedCall, HandleDelayedPeerUpdates);
|
DeclareRefVar(SingleDelayedCall, HandleDelayedPeerUpdates);
|
||||||
DeclareRefVar(SingleDelayedCall, HandleObservables);
|
DeclareRefVar(SingleDelayedCall, HandleObservables);
|
||||||
|
|
||||||
|
|
|
@ -1489,13 +1489,12 @@ void HistoryInner::copyContextUrl() {
|
||||||
void HistoryInner::savePhotoToFile(PhotoData *photo) {
|
void HistoryInner::savePhotoToFile(PhotoData *photo) {
|
||||||
if (!photo || !photo->date || !photo->loaded()) return;
|
if (!photo || !photo->date || !photo->loaded()) return;
|
||||||
|
|
||||||
QString file;
|
auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter();
|
||||||
auto filter = qsl("JPEG Image (*.jpg);;") + filedialogAllFilesFilter();
|
FileDialog::GetWritePath(lang(lng_save_photo), filter, filedialogDefaultName(qsl("photo"), qsl(".jpg")), base::lambda_guarded(this, [this, photo](const QString &result) {
|
||||||
if (filedialogGetSaveFile(file, lang(lng_save_photo), filter, filedialogDefaultName(qsl("photo"), qsl(".jpg")))) {
|
if (!result.isEmpty()) {
|
||||||
if (!file.isEmpty()) {
|
photo->full->pix().toImage().save(result, "JPG");
|
||||||
photo->full->pix().toImage().save(file, "JPG");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryInner::copyContextImage() {
|
void HistoryInner::copyContextImage() {
|
||||||
|
@ -3169,9 +3168,6 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent)
|
||||||
_attachToggle->setClickedCallback(App::LambdaDelayed(st::historyAttach.ripple.hideDuration, this, [this] {
|
_attachToggle->setClickedCallback(App::LambdaDelayed(st::historyAttach.ripple.hideDuration, this, [this] {
|
||||||
chooseAttach();
|
chooseAttach();
|
||||||
}));
|
}));
|
||||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
|
||||||
notifyFileQueryUpdated(update);
|
|
||||||
});
|
|
||||||
|
|
||||||
_updateHistoryItems.setSingleShot(true);
|
_updateHistoryItems.setSingleShot(true);
|
||||||
connect(&_updateHistoryItems, SIGNAL(timeout()), this, SLOT(onUpdateHistoryItems()));
|
connect(&_updateHistoryItems, SIGNAL(timeout()), this, SLOT(onUpdateHistoryItems()));
|
||||||
|
@ -5594,31 +5590,23 @@ void HistoryWidget::step_recording(float64 ms, bool timer) {
|
||||||
void HistoryWidget::chooseAttach() {
|
void HistoryWidget::chooseAttach() {
|
||||||
if (!_history) return;
|
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);
|
FileDialog::GetOpenPaths(lang(lng_choose_files), filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
||||||
}
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||||
|
|
||||||
void HistoryWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
|
||||||
if (_attachFilesQueryId != update.queryId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_attachFilesQueryId = 0;
|
|
||||||
|
|
||||||
if (update.filePaths.isEmpty() && update.remoteContent.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!update.remoteContent.isEmpty()) {
|
if (!result.remoteContent.isEmpty()) {
|
||||||
auto animated = false;
|
auto animated = false;
|
||||||
auto image = App::readImage(update.remoteContent, nullptr, false, &animated);
|
auto image = App::readImage(result.remoteContent, nullptr, false, &animated);
|
||||||
if (!image.isNull() && !animated) {
|
if (!image.isNull() && !animated) {
|
||||||
confirmSendingFiles(image, update.remoteContent);
|
confirmSendingFiles(image, result.remoteContent);
|
||||||
} else {
|
} else {
|
||||||
uploadFile(update.remoteContent, SendMediaType::File);
|
uploadFile(result.remoteContent, SendMediaType::File);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto lists = getSendingFilesLists(update.filePaths);
|
auto lists = getSendingFilesLists(result.paths);
|
||||||
if (lists.allFilesForCompress) {
|
if (lists.allFilesForCompress) {
|
||||||
confirmSendingFiles(lists);
|
confirmSendingFiles(lists);
|
||||||
} else {
|
} else {
|
||||||
|
@ -5628,6 +5616,7 @@ void HistoryWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::sendButtonClicked() {
|
void HistoryWidget::sendButtonClicked() {
|
||||||
|
|
|
@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "localimageloader.h"
|
#include "localimageloader.h"
|
||||||
#include "core/file_utilities.h"
|
|
||||||
#include "ui/widgets/tooltip.h"
|
#include "ui/widgets/tooltip.h"
|
||||||
#include "ui/widgets/input_fields.h"
|
#include "ui/widgets/input_fields.h"
|
||||||
#include "ui/widgets/scroll_area.h"
|
#include "ui/widgets/scroll_area.h"
|
||||||
|
@ -849,7 +848,6 @@ private:
|
||||||
void recordUpdateCallback(QPoint globalPos);
|
void recordUpdateCallback(QPoint globalPos);
|
||||||
void chooseAttach();
|
void chooseAttach();
|
||||||
void historyDownAnimationFinish();
|
void historyDownAnimationFinish();
|
||||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
|
||||||
void sendButtonClicked();
|
void sendButtonClicked();
|
||||||
struct SendingFilesLists {
|
struct SendingFilesLists {
|
||||||
QList<QUrl> nonLocalUrls;
|
QList<QUrl> nonLocalUrls;
|
||||||
|
@ -1139,8 +1137,6 @@ private:
|
||||||
BasicAnimation _a_recording;
|
BasicAnimation _a_recording;
|
||||||
anim::value a_recordingLevel;
|
anim::value a_recordingLevel;
|
||||||
|
|
||||||
FileDialog::QueryId _attachFilesQueryId = 0;
|
|
||||||
|
|
||||||
bool kbWasHidden() const;
|
bool kbWasHidden() const;
|
||||||
|
|
||||||
bool _kbShown = false;
|
bool _kbShown = false;
|
||||||
|
|
|
@ -43,14 +43,7 @@ SignupWidget::SignupWidget(QWidget *parent, Widget::Data *data) : Step(parent, d
|
||||||
, _checkRequest(this) {
|
, _checkRequest(this) {
|
||||||
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
|
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
|
||||||
|
|
||||||
_photo->setClickedCallback(App::LambdaDelayed(st::defaultActiveButton.ripple.hideDuration, this, [this] {
|
setupPhotoButton();
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (_invertOrder) {
|
if (_invertOrder) {
|
||||||
setTabOrder(_last, _first);
|
setTabOrder(_last, _first);
|
||||||
|
@ -62,20 +55,20 @@ SignupWidget::SignupWidget(QWidget *parent, Widget::Data *data) : Step(parent, d
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignupWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
void SignupWidget::setupPhotoButton() {
|
||||||
if (_readPhotoFileQueryId != update.queryId) {
|
_photo->setClickedCallback(App::LambdaDelayed(st::defaultActiveButton.ripple.hideDuration, this, [this] {
|
||||||
return;
|
auto imgExtensions = cImgExtensions();
|
||||||
}
|
auto filter = qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + FileDialog::AllFilesFilter();
|
||||||
_readPhotoFileQueryId = 0;
|
FileDialog::GetOpenPath(lang(lng_choose_image), filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
||||||
if (update.remoteContent.isEmpty() && update.filePaths.isEmpty()) {
|
if (result.remoteContent.isEmpty() && result.paths.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage img;
|
QImage img;
|
||||||
if (!update.remoteContent.isEmpty()) {
|
if (!result.remoteContent.isEmpty()) {
|
||||||
img = App::readImage(update.remoteContent);
|
img = App::readImage(result.remoteContent);
|
||||||
} else {
|
} else {
|
||||||
img = App::readImage(update.filePaths.front());
|
img = App::readImage(result.paths.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
|
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
|
||||||
|
@ -84,6 +77,8 @@ void SignupWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update)
|
||||||
}
|
}
|
||||||
auto box = Ui::show(Box<PhotoCropBox>(img, PeerId(0)));
|
auto box = Ui::show(Box<PhotoCropBox>(img, PeerId(0)));
|
||||||
connect(box, SIGNAL(ready(const QImage&)), this, SLOT(onPhotoReady(const QImage&)));
|
connect(box, SIGNAL(ready(const QImage&)), this, SLOT(onPhotoReady(const QImage&)));
|
||||||
|
}));
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignupWidget::resizeEvent(QResizeEvent *e) {
|
void SignupWidget::resizeEvent(QResizeEvent *e) {
|
||||||
|
|
|
@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "intro/introwidget.h"
|
#include "intro/introwidget.h"
|
||||||
#include "core/file_utilities.h"
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class RoundButton;
|
class RoundButton;
|
||||||
|
@ -52,7 +51,7 @@ private slots:
|
||||||
void onPhotoReady(const QImage &img);
|
void onPhotoReady(const QImage &img);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
void setupPhotoButton();
|
||||||
|
|
||||||
void nameSubmitDone(const MTPauth_Authorization &result);
|
void nameSubmitDone(const MTPauth_Authorization &result);
|
||||||
bool nameSubmitFail(const RPCError &error);
|
bool nameSubmitFail(const RPCError &error);
|
||||||
|
@ -67,8 +66,6 @@ private:
|
||||||
QString _firstName, _lastName;
|
QString _firstName, _lastName;
|
||||||
mtpRequestId _sentRequest = 0;
|
mtpRequestId _sentRequest = 0;
|
||||||
|
|
||||||
FileDialog::QueryId _readPhotoFileQueryId = 0;
|
|
||||||
|
|
||||||
bool _invertOrder = false;
|
bool _invertOrder = false;
|
||||||
|
|
||||||
object_ptr<QTimer> _checkRequest;
|
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 "window/player_wrap_widget.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "mtproto/dc_options.h"
|
#include "mtproto/dc_options.h"
|
||||||
|
#include "core/file_utilities.h"
|
||||||
#include "auth_session.h"
|
#include "auth_session.h"
|
||||||
|
|
||||||
StackItemSection::StackItemSection(std::unique_ptr<Window::SectionMemento> &&memento) : StackItem(nullptr)
|
StackItemSection::StackItemSection(std::unique_ptr<Window::SectionMemento> &&memento) : StackItem(nullptr)
|
||||||
|
|
|
@ -741,7 +741,7 @@ void MediaView::onSaveAs() {
|
||||||
if (pattern.isEmpty()) {
|
if (pattern.isEmpty()) {
|
||||||
filter = QString();
|
filter = QString();
|
||||||
} else {
|
} else {
|
||||||
filter = mimeType.filterString() + qsl(";;") + filedialogAllFilesFilter();
|
filter = mimeType.filterString() + qsl(";;") + FileDialog::AllFilesFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
psBringToBack(this);
|
psBringToBack(this);
|
||||||
|
@ -772,14 +772,15 @@ void MediaView::onSaveAs() {
|
||||||
if (!_photo || !_photo->loaded()) return;
|
if (!_photo || !_photo->loaded()) return;
|
||||||
|
|
||||||
psBringToBack(this);
|
psBringToBack(this);
|
||||||
auto filter = qsl("JPEG Image (*.jpg);;") + filedialogAllFilesFilter();
|
auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter();
|
||||||
auto gotName = filedialogGetSaveFile(file, lang(lng_save_photo), filter, filedialogDefaultName(qsl("photo"), qsl(".jpg")));
|
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);
|
psShowOverAll(this);
|
||||||
if (gotName) {
|
}), base::lambda_guarded(this, [this] {
|
||||||
if (!file.isEmpty()) {
|
psShowOverAll(this);
|
||||||
_photo->full->pix().toImage().save(file, "JPG");
|
}));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
activateWindow();
|
activateWindow();
|
||||||
Sandbox::setActiveWindow(this);
|
Sandbox::setActiveWindow(this);
|
||||||
|
|
|
@ -38,7 +38,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#include "window/themes/window_theme.h"
|
#include "window/themes/window_theme.h"
|
||||||
#include "history/history_location_manager.h"
|
#include "history/history_location_manager.h"
|
||||||
#include "ui/widgets/tooltip.h"
|
#include "ui/widgets/tooltip.h"
|
||||||
#include "core/file_utilities.h"
|
|
||||||
#include "serialize/serialize_common.h"
|
#include "serialize/serialize_common.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -498,14 +497,6 @@ void Messenger::call_handleUnreadCounterUpdate() {
|
||||||
Global::RefUnreadCounterUpdate().notify(true);
|
Global::RefUnreadCounterUpdate().notify(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Messenger::call_handleFileDialogQueue() {
|
|
||||||
while (true) {
|
|
||||||
if (!FileDialog::processQuery()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Messenger::call_handleDelayedPeerUpdates() {
|
void Messenger::call_handleDelayedPeerUpdates() {
|
||||||
Notify::peerUpdatedSendDelayed();
|
Notify::peerUpdatedSendDelayed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,6 @@ public slots:
|
||||||
|
|
||||||
void call_handleHistoryUpdate();
|
void call_handleHistoryUpdate();
|
||||||
void call_handleUnreadCounterUpdate();
|
void call_handleUnreadCounterUpdate();
|
||||||
void call_handleFileDialogQueue();
|
|
||||||
void call_handleDelayedPeerUpdates();
|
void call_handleDelayedPeerUpdates();
|
||||||
void call_handleObservables();
|
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) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(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(peerPhotoDone(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
||||||
connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
||||||
|
@ -488,31 +485,23 @@ void CoverWidget::onShareContact() {
|
||||||
|
|
||||||
void CoverWidget::onSetPhoto() {
|
void CoverWidget::onSetPhoto() {
|
||||||
App::CallDelayed(st::profilePrimaryButton.ripple.hideDuration, this, [this] {
|
App::CallDelayed(st::profilePrimaryButton.ripple.hideDuration, this, [this] {
|
||||||
QStringList imgExtensions(cImgExtensions());
|
auto imgExtensions = cImgExtensions();
|
||||||
QString filter(qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + filedialogAllFilesFilter());
|
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) {
|
||||||
_setPhotoFileQueryId = FileDialog::queryReadFile(lang(lng_choose_image), filter);
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void CoverWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
|
||||||
if (_setPhotoFileQueryId != update.queryId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_setPhotoFileQueryId = 0;
|
|
||||||
|
|
||||||
if (update.filePaths.isEmpty() && update.remoteContent.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage img;
|
QImage img;
|
||||||
if (!update.remoteContent.isEmpty()) {
|
if (!result.remoteContent.isEmpty()) {
|
||||||
img = App::readImage(update.remoteContent);
|
img = App::readImage(result.remoteContent);
|
||||||
} else {
|
} else {
|
||||||
img = App::readImage(update.filePaths.front());
|
img = App::readImage(result.paths.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
showSetPhotoBox(img);
|
showSetPhotoBox(img);
|
||||||
|
}));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoverWidget::showSetPhotoBox(const QImage &img) {
|
void CoverWidget::showSetPhotoBox(const QImage &img) {
|
||||||
|
|
|
@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "core/observer.h"
|
#include "core/observer.h"
|
||||||
#include "core/file_utilities.h"
|
|
||||||
|
|
||||||
namespace style {
|
namespace style {
|
||||||
struct RoundButton;
|
struct RoundButton;
|
||||||
|
@ -83,7 +82,6 @@ protected:
|
||||||
private:
|
private:
|
||||||
// Observed notifications.
|
// Observed notifications.
|
||||||
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
||||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
|
||||||
|
|
||||||
// Counts userpic button left offset for a new widget width.
|
// Counts userpic button left offset for a new widget width.
|
||||||
int countPhotoLeft(int newWidth) const;
|
int countPhotoLeft(int newWidth) const;
|
||||||
|
@ -138,8 +136,6 @@ private:
|
||||||
|
|
||||||
int _onlineCount = 0;
|
int _onlineCount = 0;
|
||||||
|
|
||||||
FileDialog::QueryId _setPhotoFileQueryId = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Profile
|
} // namespace Profile
|
||||||
|
|
|
@ -32,6 +32,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "window/themes/window_theme.h"
|
#include "window/themes/window_theme.h"
|
||||||
#include "window/themes/window_theme_editor.h"
|
#include "window/themes/window_theme_editor.h"
|
||||||
|
#include "core/file_utilities.h"
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
|
@ -199,9 +200,6 @@ void BackgroundRow::updateImage() {
|
||||||
BackgroundWidget::BackgroundWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_background)) {
|
BackgroundWidget::BackgroundWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_background)) {
|
||||||
createControls();
|
createControls();
|
||||||
|
|
||||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
|
||||||
notifyFileQueryUpdated(update);
|
|
||||||
});
|
|
||||||
using Update = Window::Theme::BackgroundUpdate;
|
using Update = Window::Theme::BackgroundUpdate;
|
||||||
subscribe(Window::Theme::Background(), [this](const Update &update) {
|
subscribe(Window::Theme::Background(), [this](const Update &update) {
|
||||||
if (update.type == Update::Type::New) {
|
if (update.type == Update::Type::New) {
|
||||||
|
@ -248,31 +246,14 @@ void BackgroundWidget::needBackgroundUpdate(bool tile) {
|
||||||
void BackgroundWidget::onChooseFromFile() {
|
void BackgroundWidget::onChooseFromFile() {
|
||||||
auto imgExtensions = cImgExtensions();
|
auto imgExtensions = cImgExtensions();
|
||||||
auto filters = QStringList(qsl("Theme files (*.tdesktop-theme *.tdesktop-palette *") + imgExtensions.join(qsl(" *")) + qsl(")"));
|
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) {
|
||||||
_chooseFromFileQueryId = FileDialog::queryReadFile(lang(lng_choose_image), filters.join(qsl(";;")));
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||||
}
|
|
||||||
|
|
||||||
void BackgroundWidget::onEditTheme() {
|
|
||||||
Window::Theme::Editor::Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!update.filePaths.isEmpty()) {
|
if (!result.paths.isEmpty()) {
|
||||||
auto filePath = update.filePaths.front();
|
auto filePath = result.paths.front();
|
||||||
if (filePath.endsWith(qstr(".tdesktop-theme"), Qt::CaseInsensitive)
|
if (filePath.endsWith(qstr(".tdesktop-theme"), Qt::CaseInsensitive)
|
||||||
|| filePath.endsWith(qstr(".tdesktop-palette"), Qt::CaseInsensitive)) {
|
|| filePath.endsWith(qstr(".tdesktop-palette"), Qt::CaseInsensitive)) {
|
||||||
Window::Theme::Apply(filePath);
|
Window::Theme::Apply(filePath);
|
||||||
|
@ -281,10 +262,10 @@ void BackgroundWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &upd
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage img;
|
QImage img;
|
||||||
if (!update.remoteContent.isEmpty()) {
|
if (!result.remoteContent.isEmpty()) {
|
||||||
img = App::readImage(update.remoteContent);
|
img = App::readImage(result.remoteContent);
|
||||||
} else {
|
} else {
|
||||||
img = App::readImage(update.filePaths.front());
|
img = App::readImage(result.paths.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (img.isNull() || img.width() <= 0 || img.height() <= 0) return;
|
if (img.isNull() || img.width() <= 0 || img.height() <= 0) return;
|
||||||
|
@ -298,6 +279,15 @@ void BackgroundWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &upd
|
||||||
Window::Theme::Background()->setImage(Window::Theme::kCustomBackground, std::move(img));
|
Window::Theme::Background()->setImage(Window::Theme::kCustomBackground, std::move(img));
|
||||||
_tile->setChecked(false);
|
_tile->setChecked(false);
|
||||||
_background->updateImage();
|
_background->updateImage();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void BackgroundWidget::onEditTheme() {
|
||||||
|
Window::Theme::Editor::Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BackgroundWidget::onUseDefaultTheme() {
|
||||||
|
Window::Theme::ApplyDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackgroundWidget::onTile() {
|
void BackgroundWidget::onTile() {
|
||||||
|
|
|
@ -22,7 +22,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
|
|
||||||
#include "settings/settings_block_widget.h"
|
#include "settings/settings_block_widget.h"
|
||||||
#include "ui/effects/radial_animation.h"
|
#include "ui/effects/radial_animation.h"
|
||||||
#include "core/file_utilities.h"
|
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
|
@ -82,14 +81,11 @@ private slots:
|
||||||
private:
|
private:
|
||||||
void createControls();
|
void createControls();
|
||||||
void needBackgroundUpdate(bool tile);
|
void needBackgroundUpdate(bool tile);
|
||||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
|
||||||
|
|
||||||
object_ptr<BackgroundRow> _background = { nullptr };
|
object_ptr<BackgroundRow> _background = { nullptr };
|
||||||
object_ptr<Ui::Checkbox> _tile = { nullptr };
|
object_ptr<Ui::Checkbox> _tile = { nullptr };
|
||||||
object_ptr<Ui::WidgetSlideWrap<Ui::Checkbox>> _adaptive = { nullptr };
|
object_ptr<Ui::WidgetSlideWrap<Ui::Checkbox>> _adaptive = { nullptr };
|
||||||
|
|
||||||
FileDialog::QueryId _chooseFromFileQueryId = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Settings
|
} // 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) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(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(peerPhotoDone(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
||||||
connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
||||||
|
@ -303,33 +300,25 @@ void CoverWidget::refreshStatusText() {
|
||||||
|
|
||||||
void CoverWidget::onSetPhoto() {
|
void CoverWidget::onSetPhoto() {
|
||||||
auto imageExtensions = cImgExtensions();
|
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) {
|
||||||
_setPhotoFileQueryId = FileDialog::queryReadFile(lang(lng_choose_image), filter);
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage img;
|
QImage img;
|
||||||
if (!update.remoteContent.isEmpty()) {
|
if (!result.remoteContent.isEmpty()) {
|
||||||
img = App::readImage(update.remoteContent);
|
img = App::readImage(result.remoteContent);
|
||||||
} else {
|
} else {
|
||||||
img = App::readImage(update.filePaths.front());
|
img = App::readImage(result.paths.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
showSetPhotoBox(img);
|
showSetPhotoBox(img);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoverWidget::onEditName() {
|
||||||
|
Ui::show(Box<EditNameTitleBox>(self()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoverWidget::showSetPhotoBox(const QImage &img) {
|
void CoverWidget::showSetPhotoBox(const QImage &img) {
|
||||||
|
|
|
@ -21,8 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "core/observer.h"
|
#include "core/observer.h"
|
||||||
#include "core/file_utilities.h"
|
|
||||||
|
|
||||||
#include "settings/settings_block_widget.h"
|
#include "settings/settings_block_widget.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
@ -71,7 +69,6 @@ protected:
|
||||||
private:
|
private:
|
||||||
// Observed notifications.
|
// Observed notifications.
|
||||||
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
||||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
|
||||||
|
|
||||||
PhotoData *validatePhoto() const;
|
PhotoData *validatePhoto() const;
|
||||||
|
|
||||||
|
@ -105,8 +102,6 @@ private:
|
||||||
|
|
||||||
int _dividerTop = 0;
|
int _dividerTop = 0;
|
||||||
|
|
||||||
FileDialog::QueryId _setPhotoFileQueryId = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
|
@ -160,9 +160,6 @@ GeneralWidget::GeneralWidget(QWidget *parent, UserData *self) : BlockWidget(pare
|
||||||
, _changeLanguage(this, lang(lng_settings_change_lang), st::boxLinkButton) {
|
, _changeLanguage(this, lang(lng_settings_change_lang), st::boxLinkButton) {
|
||||||
connect(_changeLanguage, SIGNAL(clicked()), this, SLOT(onChangeLanguage()));
|
connect(_changeLanguage, SIGNAL(clicked()), this, SLOT(onChangeLanguage()));
|
||||||
subscribe(Global::RefChooseCustomLang(), [this]() { chooseCustomLang(); });
|
subscribe(Global::RefChooseCustomLang(), [this]() { chooseCustomLang(); });
|
||||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
|
||||||
notifyFileQueryUpdated(update);
|
|
||||||
});
|
|
||||||
refreshControls();
|
refreshControls();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,21 +207,12 @@ void GeneralWidget::refreshControls() {
|
||||||
void GeneralWidget::chooseCustomLang() {
|
void GeneralWidget::chooseCustomLang() {
|
||||||
auto filter = qsl("Language files (*.strings)");
|
auto filter = qsl("Language files (*.strings)");
|
||||||
auto title = qsl("Choose language .strings file");
|
auto title = qsl("Choose language .strings file");
|
||||||
|
FileDialog::GetOpenPath(title, filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
||||||
_chooseLangFileQueryId = FileDialog::queryReadFile(title, filter);
|
if (result.paths.isEmpty()) {
|
||||||
}
|
|
||||||
|
|
||||||
void GeneralWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
|
||||||
if (_chooseLangFileQueryId != update.queryId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_chooseLangFileQueryId = 0;
|
|
||||||
|
|
||||||
if (update.filePaths.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_testLanguage = QFileInfo(update.filePaths.front()).absoluteFilePath();
|
_testLanguage = QFileInfo(result.paths.front()).absoluteFilePath();
|
||||||
LangLoaderPlain loader(_testLanguage, langLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok));
|
LangLoaderPlain loader(_testLanguage, langLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok));
|
||||||
if (loader.errors().isEmpty()) {
|
if (loader.errors().isEmpty()) {
|
||||||
LangLoaderResult result = loader.found();
|
LangLoaderResult result = loader.found();
|
||||||
|
@ -240,6 +228,7 @@ void GeneralWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update
|
||||||
} else {
|
} else {
|
||||||
Ui::show(Box<InformBox>("Custom lang failed :(\n\nError: " + loader.errors()));
|
Ui::show(Box<InformBox>("Custom lang failed :(\n\nError: " + loader.errors()));
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralWidget::onChangeLanguage() {
|
void GeneralWidget::onChangeLanguage() {
|
||||||
|
|
|
@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "settings/settings_block_widget.h"
|
#include "settings/settings_block_widget.h"
|
||||||
#include "core/file_utilities.h"
|
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
|
@ -106,7 +105,6 @@ private:
|
||||||
void refreshControls();
|
void refreshControls();
|
||||||
void updateWorkmode();
|
void updateWorkmode();
|
||||||
void chooseCustomLang();
|
void chooseCustomLang();
|
||||||
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
|
|
||||||
|
|
||||||
object_ptr<Ui::LinkButton> _changeLanguage;
|
object_ptr<Ui::LinkButton> _changeLanguage;
|
||||||
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
||||||
|
@ -119,7 +117,6 @@ private:
|
||||||
object_ptr<Ui::WidgetSlideWrap<Ui::Checkbox>> _startMinimized = { nullptr };
|
object_ptr<Ui::WidgetSlideWrap<Ui::Checkbox>> _startMinimized = { nullptr };
|
||||||
object_ptr<Ui::Checkbox> _addInSendTo = { nullptr };
|
object_ptr<Ui::Checkbox> _addInSendTo = { nullptr };
|
||||||
|
|
||||||
FileDialog::QueryId _chooseLangFileQueryId = 0;
|
|
||||||
QString _testLanguage;
|
QString _testLanguage;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1118,12 +1118,12 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals
|
||||||
bool mp3 = (data->mime == qstr("audio/mp3"));
|
bool mp3 = (data->mime == qstr("audio/mp3"));
|
||||||
name = already.isEmpty() ? (mp3 ? qsl(".mp3") : qsl(".ogg")) : already;
|
name = already.isEmpty() ? (mp3 ? qsl(".mp3") : qsl(".ogg")) : already;
|
||||||
filter = mp3 ? qsl("MP3 Audio (*.mp3);;") : qsl("OGG Opus Audio (*.ogg);;");
|
filter = mp3 ? qsl("MP3 Audio (*.mp3);;") : qsl("OGG Opus Audio (*.ogg);;");
|
||||||
filter += filedialogAllFilesFilter();
|
filter += FileDialog::AllFilesFilter();
|
||||||
caption = lang(lng_save_audio);
|
caption = lang(lng_save_audio);
|
||||||
prefix = qsl("audio");
|
prefix = qsl("audio");
|
||||||
} else if (data->isVideo()) {
|
} else if (data->isVideo()) {
|
||||||
name = already.isEmpty() ? qsl(".mov") : already;
|
name = already.isEmpty() ? qsl(".mov") : already;
|
||||||
filter = qsl("MOV Video (*.mov);;") + filedialogAllFilesFilter();
|
filter = qsl("MOV Video (*.mov);;") + FileDialog::AllFilesFilter();
|
||||||
caption = lang(lng_save_video);
|
caption = lang(lng_save_video);
|
||||||
prefix = qsl("video");
|
prefix = qsl("video");
|
||||||
} else {
|
} else {
|
||||||
|
@ -1134,7 +1134,7 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals
|
||||||
if (pattern.isEmpty()) {
|
if (pattern.isEmpty()) {
|
||||||
filter = QString();
|
filter = QString();
|
||||||
} else {
|
} else {
|
||||||
filter = mimeType.filterString() + qsl(";;") + filedialogAllFilesFilter();
|
filter = mimeType.filterString() + qsl(";;") + FileDialog::AllFilesFilter();
|
||||||
}
|
}
|
||||||
caption = lang(data->song() ? lng_save_audio_file : lng_save_file);
|
caption = lang(data->song() ? lng_save_audio_file : lng_save_file);
|
||||||
prefix = qsl("doc");
|
prefix = qsl("doc");
|
||||||
|
|
Loading…
Reference in New Issue