Show choose file box over the passport panel.

This commit is contained in:
John Preston 2018-04-17 19:19:34 +04:00
parent 6c2a39f1fc
commit 67ea175fc6
21 changed files with 170 additions and 47 deletions

View File

@ -83,20 +83,25 @@ void DownloadPathBox::radioChanged(Directory value) {
} }
void DownloadPathBox::onEditPath() { void DownloadPathBox::onEditPath() {
auto initialPath = [] { const auto initialPath = [] {
if (!Global::DownloadPath().isEmpty() && Global::DownloadPath() != qstr("tmp")) { if (!Global::DownloadPath().isEmpty() && Global::DownloadPath() != qstr("tmp")) {
return Global::DownloadPath().left(Global::DownloadPath().size() - (Global::DownloadPath().endsWith('/') ? 1 : 0)); return Global::DownloadPath().left(Global::DownloadPath().size() - (Global::DownloadPath().endsWith('/') ? 1 : 0));
} }
return QString(); return QString();
}; }();
FileDialog::GetFolder(lang(lng_download_path_choose), initialPath(), base::lambda_guarded(this, [this](const QString &result) { const auto handleFolder = [=](const QString &result) {
if (!result.isEmpty()) { if (!result.isEmpty()) {
_path = result + '/'; _path = result + '/';
_pathBookmark = psDownloadPathBookmark(_path); _pathBookmark = psDownloadPathBookmark(_path);
setPathText(QDir::toNativeSeparators(_path)); setPathText(QDir::toNativeSeparators(_path));
_group->setValue(Directory::Custom); _group->setValue(Directory::Custom);
} }
})); };
FileDialog::GetFolder(
this,
lang(lng_download_path_choose),
initialPath,
base::lambda_guarded(this, handleFolder));
} }
void DownloadPathBox::save() { void DownloadPathBox::save() {

View File

@ -13,17 +13,38 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "messenger.h" #include "messenger.h"
bool filedialogGetSaveFile( bool filedialogGetSaveFile(
QPointer<QWidget> parent,
QString &file, QString &file,
const QString &caption, const QString &caption,
const QString &filter, const QString &filter,
const QString &initialPath) { const QString &initialPath) {
QStringList files; QStringList files;
QByteArray remoteContent; QByteArray remoteContent;
bool result = Platform::FileDialog::Get(files, remoteContent, caption, filter, FileDialog::internal::Type::WriteFile, initialPath); bool result = Platform::FileDialog::Get(
parent,
files,
remoteContent,
caption,
filter,
FileDialog::internal::Type::WriteFile,
initialPath);
file = files.isEmpty() ? QString() : files.at(0); file = files.isEmpty() ? QString() : files.at(0);
return result; return result;
} }
bool filedialogGetSaveFile(
QString &file,
const QString &caption,
const QString &filter,
const QString &initialPath) {
return filedialogGetSaveFile(
Messenger::Instance().getFileDialogParent(),
file,
caption,
filter,
initialPath);
}
QString filedialogDefaultName( QString filedialogDefaultName(
const QString &prefix, const QString &prefix,
const QString &extension, const QString &extension,
@ -130,6 +151,7 @@ void UnsafeLaunchDefault(const QString &filepath) {
namespace FileDialog { namespace FileDialog {
void GetOpenPath( void GetOpenPath(
QPointer<QWidget> parent,
const QString &caption, const QString &caption,
const QString &filter, const QString &filter,
base::lambda<void(OpenResult &&result)> callback, base::lambda<void(OpenResult &&result)> callback,
@ -138,6 +160,7 @@ void GetOpenPath(
auto files = QStringList(); auto files = QStringList();
auto remoteContent = QByteArray(); auto remoteContent = QByteArray();
const auto success = Platform::FileDialog::Get( const auto success = Platform::FileDialog::Get(
parent,
files, files,
remoteContent, remoteContent,
caption, caption,
@ -161,6 +184,7 @@ void GetOpenPath(
} }
void GetOpenPaths( void GetOpenPaths(
QPointer<QWidget> parent,
const QString &caption, const QString &caption,
const QString &filter, const QString &filter,
base::lambda<void(OpenResult &&result)> callback, base::lambda<void(OpenResult &&result)> callback,
@ -169,6 +193,7 @@ void GetOpenPaths(
auto files = QStringList(); auto files = QStringList();
auto remoteContent = QByteArray(); auto remoteContent = QByteArray();
const auto success = Platform::FileDialog::Get( const auto success = Platform::FileDialog::Get(
parent,
files, files,
remoteContent, remoteContent,
caption, caption,
@ -188,6 +213,7 @@ void GetOpenPaths(
} }
void GetWritePath( void GetWritePath(
QPointer<QWidget> parent,
const QString &caption, const QString &caption,
const QString &filter, const QString &filter,
const QString &initialPath, const QString &initialPath,
@ -195,7 +221,7 @@ void GetWritePath(
base::lambda<void()> failed) { base::lambda<void()> failed) {
InvokeQueued(QApplication::instance(), [=] { InvokeQueued(QApplication::instance(), [=] {
auto file = QString(); auto file = QString();
if (filedialogGetSaveFile(file, caption, filter, initialPath)) { if (filedialogGetSaveFile(parent, file, caption, filter, initialPath)) {
if (callback) { if (callback) {
callback(std::move(file)); callback(std::move(file));
} }
@ -206,6 +232,7 @@ void GetWritePath(
} }
void GetFolder( void GetFolder(
QPointer<QWidget> parent,
const QString &caption, const QString &caption,
const QString &initialPath, const QString &initialPath,
base::lambda<void(QString &&result)> callback, base::lambda<void(QString &&result)> callback,
@ -214,6 +241,7 @@ void GetFolder(
auto files = QStringList(); auto files = QStringList();
auto remoteContent = QByteArray(); auto remoteContent = QByteArray();
const auto success = Platform::FileDialog::Get( const auto success = Platform::FileDialog::Get(
parent,
files, files,
remoteContent, remoteContent,
caption, caption,
@ -244,7 +272,14 @@ void InitLastPathDefault() {
cSetDialogLastPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); cSetDialogLastPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
} }
bool GetDefault(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, FileDialog::internal::Type type, QString startFile = QString()) { bool GetDefault(
QPointer<QWidget> parent,
QStringList &files,
QByteArray &remoteContent,
const QString &caption,
const QString &filter,
FileDialog::internal::Type type,
QString startFile = QString()) {
if (cDialogLastPath().isEmpty()) { if (cDialogLastPath().isEmpty()) {
Platform::FileDialog::InitLastPath(); Platform::FileDialog::InitLastPath();
} }

View File

@ -54,22 +54,26 @@ struct OpenResult {
QByteArray remoteContent; QByteArray remoteContent;
}; };
void GetOpenPath( void GetOpenPath(
QPointer<QWidget> parent,
const QString &caption, const QString &caption,
const QString &filter, const QString &filter,
base::lambda<void(OpenResult &&result)> callback, base::lambda<void(OpenResult &&result)> callback,
base::lambda<void()> failed = base::lambda<void()>()); base::lambda<void()> failed = base::lambda<void()>());
void GetOpenPaths( void GetOpenPaths(
QPointer<QWidget> parent,
const QString &caption, const QString &caption,
const QString &filter, const QString &filter,
base::lambda<void(OpenResult &&result)> callback, base::lambda<void(OpenResult &&result)> callback,
base::lambda<void()> failed = base::lambda<void()>()); base::lambda<void()> failed = base::lambda<void()>());
void GetWritePath( void GetWritePath(
QPointer<QWidget> parent,
const QString &caption, const QString &caption,
const QString &filter, const QString &filter,
const QString &initialPath, const QString &initialPath,
base::lambda<void(QString &&result)> callback, base::lambda<void(QString &&result)> callback,
base::lambda<void()> failed = base::lambda<void()>()); base::lambda<void()> failed = base::lambda<void()>());
void GetFolder( void GetFolder(
QPointer<QWidget> parent,
const QString &caption, const QString &caption,
const QString &initialPath, const QString &initialPath,
base::lambda<void(QString &&result)> callback, base::lambda<void(QString &&result)> callback,
@ -89,6 +93,7 @@ enum class Type {
void InitLastPathDefault(); void InitLastPathDefault();
bool GetDefault( bool GetDefault(
QPointer<QWidget> parent,
QStringList &files, QStringList &files,
QByteArray &remoteContent, QByteArray &remoteContent,
const QString &caption, const QString &caption,

View File

@ -1085,6 +1085,7 @@ void InnerWidget::savePhotoToFile(PhotoData *photo) {
auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter(); auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter();
FileDialog::GetWritePath( FileDialog::GetWritePath(
this,
lang(lng_save_photo), lang(lng_save_photo),
filter, filter,
filedialogDefaultName(qsl("photo"), qsl(".jpg")), filedialogDefaultName(qsl("photo"), qsl(".jpg")),

View File

@ -1738,6 +1738,7 @@ void HistoryInner::savePhotoToFile(not_null<PhotoData*> photo) {
auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter(); auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter();
FileDialog::GetWritePath( FileDialog::GetWritePath(
this,
lang(lng_save_photo), lang(lng_save_photo),
filter, filter,
filedialogDefaultName( filedialogDefaultName(

View File

@ -3221,7 +3221,7 @@ void HistoryWidget::chooseAttach() {
auto filter = FileDialog::AllFilesFilter() + qsl(";;Image files (*") + cImgExtensions().join(qsl(" *")) + qsl(")"); auto filter = FileDialog::AllFilesFilter() + qsl(";;Image files (*") + cImgExtensions().join(qsl(" *")) + qsl(")");
FileDialog::GetOpenPaths(lang(lng_choose_files), filter, base::lambda_guarded(this, [this](FileDialog::OpenResult &&result) { FileDialog::GetOpenPaths(this, lang(lng_choose_files), filter, base::lambda_guarded(this, [this](FileDialog::OpenResult &&result) {
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) { if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
return; return;
} }

View File

@ -49,6 +49,7 @@ void SavePhotoToFile(not_null<PhotoData*> photo) {
} }
FileDialog::GetWritePath( FileDialog::GetWritePath(
Messenger::Instance().getFileDialogParent(),
lang(lng_save_photo), lang(lng_save_photo),
qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter(), qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter(),
filedialogDefaultName(qsl("photo"), qsl(".jpg")), filedialogDefaultName(qsl("photo"), qsl(".jpg")),

View File

@ -231,7 +231,7 @@ void CloudManager::switchToLanguage(QString id) {
void CloudManager::performSwitchToCustom() { void CloudManager::performSwitchToCustom() {
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, [weak = base::make_weak(this)](const FileDialog::OpenResult &result) { FileDialog::GetOpenPath(Messenger::Instance().getFileDialogParent(), title, filter, [weak = base::make_weak(this)](const FileDialog::OpenResult &result) {
if (!weak || result.paths.isEmpty()) { if (!weak || result.paths.isEmpty()) {
return; return;
} }

View File

@ -851,6 +851,7 @@ void MediaView::onSaveAs() {
psBringToBack(this); psBringToBack(this);
auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter(); auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter();
FileDialog::GetWritePath( FileDialog::GetWritePath(
this,
lang(lng_save_photo), lang(lng_save_photo),
filter, filter,
filedialogDefaultName( filedialogDefaultName(

View File

@ -833,13 +833,11 @@ void PanelController::editWithUpload(int index, int documentIndex) {
Expects(documentIndex >= 0 Expects(documentIndex >= 0
&& documentIndex < _scopes[index].documents.size()); && documentIndex < _scopes[index].documents.size());
EditScans::ChooseScan( EditScans::ChooseScan(_panel.get(), [=](QByteArray &&content) {
base::lambda_guarded(_panel.get(), base::take(_scopeDocumentTypeBox);
[=](QByteArray &&content) { editScope(index, documentIndex);
base::take(_scopeDocumentTypeBox); uploadScan(std::move(content));
editScope(index, documentIndex); });
uploadScan(std::move(content));
}));
} }
void PanelController::editScope(int index, int documentIndex) { void PanelController::editScope(int index, int documentIndex) {

View File

@ -423,22 +423,27 @@ void EditScans::chooseScan() {
_controller->showToast(lang(lng_passport_scans_limit_reached)); _controller->showToast(lang(lng_passport_scans_limit_reached));
return; return;
} }
ChooseScan(base::lambda_guarded(this, [=](QByteArray &&content) { ChooseScan(this, [=](QByteArray &&content) {
_controller->uploadScan(std::move(content)); _controller->uploadScan(std::move(content));
})); });
} }
void EditScans::chooseSelfie() { void EditScans::chooseSelfie() {
ChooseScan(base::lambda_guarded(this, [=](QByteArray &&content) { ChooseScan(this, [=](QByteArray &&content) {
_controller->uploadSelfie(std::move(content)); _controller->uploadSelfie(std::move(content));
})); });
} }
void EditScans::ChooseScan(base::lambda<void(QByteArray&&)> callback) { void EditScans::ChooseScan(
QPointer<QWidget> parent,
base::lambda<void(QByteArray&&)> callback) {
Expects(parent != nullptr);
const auto filter = FileDialog::AllFilesFilter() const auto filter = FileDialog::AllFilesFilter()
+ qsl(";;Image files (*") + qsl(";;Image files (*")
+ cImgExtensions().join(qsl(" *")) + cImgExtensions().join(qsl(" *"))
+ qsl(")"); + qsl(")");
const auto guardedCallback = base::lambda_guarded(parent, callback);
const auto processFile = [=](FileDialog::OpenResult &&result) { const auto processFile = [=](FileDialog::OpenResult &&result) {
if (result.paths.size() == 1) { if (result.paths.size() == 1) {
auto content = [&] { auto content = [&] {
@ -449,13 +454,14 @@ void EditScans::ChooseScan(base::lambda<void(QByteArray&&)> callback) {
return f.readAll(); return f.readAll();
}(); }();
if (!content.isEmpty()) { if (!content.isEmpty()) {
callback(std::move(content)); guardedCallback(std::move(content));
} }
} else if (!result.remoteContent.isEmpty()) { } else if (!result.remoteContent.isEmpty()) {
callback(std::move(result.remoteContent)); guardedCallback(std::move(result.remoteContent));
} }
}; };
FileDialog::GetOpenPath( FileDialog::GetOpenPath(
parent,
lang(lng_passport_choose_image), lang(lng_passport_choose_image),
filter, filter,
processFile); processFile);

View File

@ -41,7 +41,9 @@ public:
base::optional<int> validateGetErrorTop(); base::optional<int> validateGetErrorTop();
static void ChooseScan(base::lambda<void(QByteArray&&)> callback); static void ChooseScan(
QPointer<QWidget> parent,
base::lambda<void(QByteArray&&)> callback);
private: private:
void setupContent(const QString &header); void setupContent(const QString &header);

View File

@ -139,8 +139,14 @@ bool PreviewSupported() {
&& (Libs::gdk_pixbuf_new_from_file_at_size != nullptr); && (Libs::gdk_pixbuf_new_from_file_at_size != nullptr);
} }
bool GetNative(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, Type type, QString startFile) { bool GetNative(
auto parent = Messenger::Instance().getFileDialogParent(); QPointer<QWidget> parent,
QStringList &files,
QByteArray &remoteContent,
const QString &caption,
const QString &filter,
Type type,
QString startFile) {
internal::GtkFileDialog dialog(parent, caption, QString(), filter); internal::GtkFileDialog dialog(parent, caption, QString(), filter);
dialog.setModal(true); dialog.setModal(true);
@ -185,13 +191,34 @@ bool GetNative(QStringList &files, QByteArray &remoteContent, const QString &cap
} // namespace } // namespace
bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, Type type, QString startFile) { bool Get(
QPointer<QWidget> parent,
QStringList &files,
QByteArray &remoteContent,
const QString &caption,
const QString &filter,
Type type,
QString startFile) {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION #ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
if (NativeSupported()) { if (NativeSupported()) {
return GetNative(files, remoteContent, caption, filter, type, startFile); return GetNative(
parent,
files,
remoteContent,
caption,
filter,
type,
startFile);
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
return ::FileDialog::internal::GetDefault(files, remoteContent, caption, filter, type, startFile); return ::FileDialog::internal::GetDefault(
parent,
files,
remoteContent,
caption,
filter,
type,
startFile);
} }
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION #ifndef TDESKTOP_DISABLE_GTK_INTEGRATION

View File

@ -27,8 +27,22 @@ inline void InitLastPath() {
::FileDialog::internal::InitLastPathDefault(); ::FileDialog::internal::InitLastPathDefault();
} }
inline bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, ::FileDialog::internal::Type type, QString startFile) { inline bool Get(
return ::FileDialog::internal::GetDefault(files, remoteContent, caption, filter, type, startFile); QPointer<QWidget> parent,
QStringList &files,
QByteArray &remoteContent,
const QString &caption,
const QString &filter,
::FileDialog::internal::Type type,
QString startFile) {
return ::FileDialog::internal::GetDefault(
parent,
files,
remoteContent,
caption,
filter,
type,
startFile);
} }
} // namespace FileDialog } // namespace FileDialog

View File

@ -29,7 +29,14 @@ namespace FileDialog {
void InitLastPath(); void InitLastPath();
bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, ::FileDialog::internal::Type type, QString startFile = QString()); bool Get(
QPointer<QWidget> parent,
QStringList &files,
QByteArray &remoteContent,
const QString &caption,
const QString &filter,
::FileDialog::internal::Type type,
QString startFile = QString());
} // namespace FileDialog } // namespace FileDialog
} // namespace Platform } // namespace Platform

View File

@ -333,7 +333,14 @@ void InitLastPath() {
} }
} }
bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, ::FileDialog::internal::Type type, QString startFile) { bool Get(
QPointer<QWidget> parent,
QStringList &files,
QByteArray &remoteContent,
const QString &caption,
const QString &filter,
::FileDialog::internal::Type type,
QString startFile) {
if (cDialogLastPath().isEmpty()) { if (cDialogLastPath().isEmpty()) {
Platform::FileDialog::InitLastPath(); Platform::FileDialog::InitLastPath();
} }
@ -344,7 +351,6 @@ bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption,
// that forced file icon and maybe other properties being resolved and this was // that forced file icon and maybe other properties being resolved and this was
// a blocking operation. // a blocking operation.
auto helperPath = cDialogHelperPathFinal(); auto helperPath = cDialogHelperPathFinal();
auto parent = Messenger::Instance().getFileDialogParent();
QFileDialog dialog(parent, caption, helperPath, filter); QFileDialog dialog(parent, caption, helperPath, filter);
dialog.setModal(true); dialog.setModal(true);

View File

@ -231,7 +231,7 @@ 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(FileDialog::AllFilesFilter()); filters.push_back(FileDialog::AllFilesFilter());
FileDialog::GetOpenPath(lang(lng_choose_image), filters.join(qsl(";;")), base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) { const auto callback = [=](const FileDialog::OpenResult &result) {
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) { if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
return; return;
} }
@ -263,7 +263,12 @@ void BackgroundWidget::onChooseFromFile() {
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();
})); };
FileDialog::GetOpenPath(
this,
lang(lng_choose_image),
filters.join(qsl(";;")),
base::lambda_guarded(this, callback));
} }
void BackgroundWidget::onEditTheme() { void BackgroundWidget::onEditTheme() {

View File

@ -343,7 +343,7 @@ void CoverWidget::refreshStatusText() {
void CoverWidget::chooseNewPhoto() { void CoverWidget::chooseNewPhoto() {
auto imageExtensions = cImgExtensions(); auto imageExtensions = cImgExtensions();
auto filter = qsl("Image files (*") + imageExtensions.join(qsl(" *")) + qsl(");;") + FileDialog::AllFilesFilter(); 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) { const auto callback = [=](const FileDialog::OpenResult &result) {
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) { if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
return; return;
} }
@ -356,7 +356,12 @@ void CoverWidget::chooseNewPhoto() {
} }
showSetPhotoBox(img); showSetPhotoBox(img);
})); };
FileDialog::GetOpenPath(
this,
lang(lng_choose_image),
filter,
base::lambda_guarded(this, callback));
} }
void CoverWidget::editName() { void CoverWidget::editName() {

View File

@ -90,7 +90,7 @@ void fillCodes() {
} }
}); });
Codes.insert(qsl("loadcolors"), [] { Codes.insert(qsl("loadcolors"), [] {
FileDialog::GetOpenPath("Open palette file", "Palette (*.tdesktop-palette)", [](const FileDialog::OpenResult &result) { FileDialog::GetOpenPath(Messenger::Instance().getFileDialogParent(), "Open palette file", "Palette (*.tdesktop-palette)", [](const FileDialog::OpenResult &result) {
if (!result.paths.isEmpty()) { if (!result.paths.isEmpty()) {
Window::Theme::Apply(result.paths.front()); Window::Theme::Apply(result.paths.front());
} }
@ -108,7 +108,7 @@ void fillCodes() {
})); }));
}); });
Codes.insert(qsl("endpoints"), [] { Codes.insert(qsl("endpoints"), [] {
FileDialog::GetOpenPath("Open DC endpoints", "DC Endpoints (*.tdesktop-endpoints)", [](const FileDialog::OpenResult &result) { FileDialog::GetOpenPath(Messenger::Instance().getFileDialogParent(), "Open DC endpoints", "DC Endpoints (*.tdesktop-endpoints)", [](const FileDialog::OpenResult &result) {
if (!result.paths.isEmpty()) { if (!result.paths.isEmpty()) {
if (!Messenger::Instance().mtp()->dcOptions()->loadFromFile(result.paths.front())) { if (!Messenger::Instance().mtp()->dcOptions()->loadFromFile(result.paths.front())) {
Ui::show(Box<InformBox>("Could not load endpoints :( Errors in 'log.txt'.")); Ui::show(Box<InformBox>("Could not load endpoints :( Errors in 'log.txt'."));
@ -136,7 +136,7 @@ void fillCodes() {
return; return;
} }
FileDialog::GetOpenPath("Open audio file", audioFilters, [key](const FileDialog::OpenResult &result) { FileDialog::GetOpenPath(Messenger::Instance().getFileDialogParent(), "Open audio file", audioFilters, [key](const FileDialog::OpenResult &result) {
if (AuthSession::Exists() && !result.paths.isEmpty()) { if (AuthSession::Exists() && !result.paths.isEmpty()) {
auto track = Media::Audio::Current().createTrack(); auto track = Media::Audio::Current().createTrack();
track->fillFromFile(result.paths.front()); track->fillFromFile(result.paths.front());

View File

@ -95,7 +95,10 @@ void SuggestPhotoFile(
} }
template <typename Callback> template <typename Callback>
void ShowChoosePhotoBox(PeerId peerForCrop, Callback &&callback) { void ShowChoosePhotoBox(
QPointer<QWidget> parent,
PeerId peerForCrop,
Callback &&callback) {
auto imgExtensions = cImgExtensions(); auto imgExtensions = cImgExtensions();
auto filter = qsl("Image files (*") auto filter = qsl("Image files (*")
+ imgExtensions.join(qsl(" *")) + imgExtensions.join(qsl(" *"))
@ -108,6 +111,7 @@ void ShowChoosePhotoBox(PeerId peerForCrop, Callback &&callback) {
SuggestPhotoFile(result, peerForCrop, std::move(callback)); SuggestPhotoFile(result, peerForCrop, std::move(callback));
}; };
FileDialog::GetOpenPath( FileDialog::GetOpenPath(
parent,
lang(lng_choose_image), lang(lng_choose_image),
filter, filter,
std::move(handleChosenPhoto)); std::move(handleChosenPhoto));
@ -470,7 +474,7 @@ void UserpicButton::changePhotoLazy() {
auto callback = base::lambda_guarded( auto callback = base::lambda_guarded(
this, this,
[this](QImage &&image) { setImage(std::move(image)); }); [this](QImage &&image) { setImage(std::move(image)); });
ShowChoosePhotoBox(_peerForCrop, std::move(callback)); ShowChoosePhotoBox(this, _peerForCrop, std::move(callback));
} }
void UserpicButton::uploadNewPeerPhoto() { void UserpicButton::uploadNewPeerPhoto() {
@ -482,7 +486,7 @@ void UserpicButton::uploadNewPeerPhoto() {
_peer->id _peer->id
); );
}); });
ShowChoosePhotoBox(_peerForCrop, std::move(callback)); ShowChoosePhotoBox(this, _peerForCrop, std::move(callback));
} }
void UserpicButton::openPeerPhoto() { void UserpicButton::openPeerPhoto() {

View File

@ -621,7 +621,7 @@ void ThemeExportBox::updateThumbnail() {
} }
void ThemeExportBox::chooseBackgroundFromFile() { void ThemeExportBox::chooseBackgroundFromFile() {
FileDialog::GetOpenPath(lang(lng_theme_editor_choose_image), "Image files (*.jpeg *.jpg *.png)", base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) { FileDialog::GetOpenPath(this, lang(lng_theme_editor_choose_image), "Image files (*.jpeg *.jpg *.png)", base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
auto content = result.remoteContent; auto content = result.remoteContent;
if (!result.paths.isEmpty()) { if (!result.paths.isEmpty()) {
QFile f(result.paths.front()); QFile f(result.paths.front());
@ -651,7 +651,7 @@ void ThemeExportBox::exportTheme() {
auto caption = lang(lng_theme_editor_choose_name); auto caption = lang(lng_theme_editor_choose_name);
auto filter = "Themes (*.tdesktop-theme)"; auto filter = "Themes (*.tdesktop-theme)";
auto name = "awesome.tdesktop-theme"; auto name = "awesome.tdesktop-theme";
FileDialog::GetWritePath(caption, filter, name, base::lambda_guarded(this, [this](const QString &path) { FileDialog::GetWritePath(this, caption, filter, name, base::lambda_guarded(this, [this](const QString &path) {
zlib::FileToWrite zip; zlib::FileToWrite zip;
zip_fileinfo zfi = { { 0, 0, 0, 0, 0, 0 }, 0, 0, 0 }; zip_fileinfo zfi = { { 0, 0, 0, 0, 0, 0 }, 0, 0, 0 };
@ -787,7 +787,7 @@ void Editor::paintEvent(QPaintEvent *e) {
void Editor::Start() { void Editor::Start() {
auto palettePath = Local::themePaletteAbsolutePath(); auto palettePath = Local::themePaletteAbsolutePath();
if (palettePath.isEmpty()) { if (palettePath.isEmpty()) {
FileDialog::GetWritePath(lang(lng_theme_editor_save_palette), "Palette (*.tdesktop-palette)", "colors.tdesktop-palette", [](const QString &path) { FileDialog::GetWritePath(App::wnd(), lang(lng_theme_editor_save_palette), "Palette (*.tdesktop-palette)", "colors.tdesktop-palette", [](const QString &path) {
if (!Local::copyThemeColorsToPalette(path)) { if (!Local::copyThemeColorsToPalette(path)) {
writeDefaultPalette(path); writeDefaultPalette(path);
} }