/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "settings/settings_main.h" #include "settings/settings_common.h" #include "settings/settings_codes.h" #include "boxes/abstract_box.h" #include "boxes/language_box.h" #include "boxes/confirm_box.h" #include "boxes/about_box.h" #include "boxes/photo_crop_box.h" #include "ui/wrap/vertical_layout.h" #include "ui/widgets/labels.h" #include "ui/widgets/discrete_sliders.h" #include "info/profile/info_profile_button.h" #include "info/profile/info_profile_cover.h" #include "lang/lang_keys.h" #include "storage/localstorage.h" #include "auth_session.h" #include "apiwrap.h" #include "core/file_utilities.h" #include "styles/style_settings.h" namespace Settings { namespace { void SetupUploadPhotoButton( not_null container, not_null self) { AddDivider(container); AddSkip(container); const auto upload = [=] { const auto imageExtensions = cImgExtensions(); const auto filter = qsl("Image files (*") + imageExtensions.join(qsl(" *")) + qsl(");;") + FileDialog::AllFilesFilter(); const auto callback = [=](const FileDialog::OpenResult &result) { if (result.paths.isEmpty() && result.remoteContent.isEmpty()) { return; } const auto image = result.remoteContent.isEmpty() ? App::readImage(result.paths.front()) : App::readImage(result.remoteContent); if (image.isNull() || image.width() > 10 * image.height() || image.height() > 10 * image.width()) { Ui::show(Box(lang(lng_bad_photo))); return; } auto box = Ui::show(Box(image, self)); box->ready( ) | rpl::start_with_next([=](QImage &&image) { Auth().api().uploadPeerPhoto(self, std::move(image)); }, box->lifetime()); }; FileDialog::GetOpenPath( container.get(), lang(lng_choose_image), filter, crl::guard(container, callback)); }; container->add(object_ptr