Moved process of separated window for shared media to correspond file.

This commit is contained in:
23rd 2025-01-30 12:32:22 +03:00
parent a676138745
commit ef9f7ab27a
6 changed files with 109 additions and 107 deletions

View file

@ -959,6 +959,7 @@ PRIVATE
info/global_media/info_global_media_inner_widget.h
info/global_media/info_global_media_provider.cpp
info/global_media/info_global_media_provider.h
info/media/info_media_buttons.cpp
info/media/info_media_buttons.h
info/media/info_media_common.cpp
info/media/info_media_common.h

View file

@ -0,0 +1,87 @@
/*
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 "info/media/info_media_buttons.h"
#include "base/call_delayed.h"
#include "ui/widgets/popup_menu.h"
#include "window/window_separate_id.h"
#include "styles/style_menu_icons.h"
namespace Info {
namespace Media {
namespace {
Window::SeparateSharedMediaType ToSeparateType(
Storage::SharedMediaType type) {
using Type = Storage::SharedMediaType;
using SeparatedType = Window::SeparateSharedMediaType;
return (type == Type::Photo)
? SeparatedType::Photos
: (type == Type::Video)
? SeparatedType::Videos
: (type == Type::File)
? SeparatedType::Files
: (type == Type::MusicFile)
? SeparatedType::Audio
: (type == Type::Link)
? SeparatedType::Links
: (type == Type::RoundVoiceFile)
? SeparatedType::Voices
: (type == Type::GIF)
? SeparatedType::GIF
: SeparatedType::None;
}
} // namespace
Fn<void()> SeparateWindowFactory(
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer,
MsgId topicRootId,
Storage::SharedMediaType type) {
const auto separateType = ToSeparateType(type);
if (separateType == Window::SeparateSharedMediaType::None) {
return nullptr;
}
return [=] {
controller->showInNewWindow({
Window::SeparateSharedMedia(separateType, peer, topicRootId),
});
};
}
void AddContextMenuToButton(
not_null<Ui::AbstractButton*> button,
Fn<void()> openInWindow) {
if (!openInWindow) {
return;
}
button->setAcceptBoth();
struct State final {
base::unique_qptr<Ui::PopupMenu> menu;
};
const auto state = button->lifetime().make_state<State>();
button->addClickHandler([=](Qt::MouseButton mouse) {
if (mouse != Qt::RightButton) {
return;
}
state->menu = base::make_unique_q<Ui::PopupMenu>(
button.get(),
st::popupMenuWithIcons);
state->menu->addAction(tr::lng_context_new_window(tr::now), [=] {
base::call_delayed(
st::popupMenuWithIcons.showDuration,
crl::guard(button, openInWindow));
}, &st::menuIconNewWindow);
state->menu->popup(QCursor::pos());
});
}
} // namespace Media
} // namespace Info

View file

@ -84,6 +84,16 @@ inline auto AddCountedButton(
return button;
};
Fn<void()> SeparateWindowFactory(
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer,
MsgId topicRootId,
Type type);
void AddContextMenuToButton(
not_null<Ui::AbstractButton*> button,
Fn<void()> openInWindow);
inline auto AddButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
@ -91,13 +101,18 @@ inline auto AddButton(
MsgId topicRootId,
PeerData *migrated,
Type type,
Ui::MultiSlideTracker &tracker,
Fn<void()> openInWindow) {
Ui::MultiSlideTracker &tracker) {
auto result = AddCountedButton(
parent,
Profile::SharedMediaCountValue(peer, topicRootId, migrated, type),
MediaText(type),
tracker)->entity();
const auto openInWindow = SeparateWindowFactory(
navigation->parentController(),
peer,
topicRootId,
type);
AddContextMenuToButton(result, openInWindow);
result->addClickHandler([=](Qt::MouseButton mouse) {
if (mouse == Qt::RightButton) {
return;

View file

@ -92,8 +92,7 @@ void InnerWidget::createTypeButtons() {
topicRootId,
migrated,
buttonType,
tracker,
nullptr);
tracker);
object_ptr<Profile::FloatingIcon>(
result,
icon,

View file

@ -7,119 +7,29 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/profile/info_profile_inner_widget.h"
#include "base/call_delayed.h"
#include "info/info_memento.h"
#include "info/info_controller.h"
#include "info/profile/info_profile_widget.h"
#include "info/profile/info_profile_text.h"
#include "info/profile/info_profile_values.h"
#include "info/profile/info_profile_cover.h"
#include "info/profile/info_profile_icon.h"
#include "info/profile/info_profile_members.h"
#include "info/profile/info_profile_actions.h"
#include "info/media/info_media_buttons.h"
#include "boxes/abstract_box.h"
#include "boxes/add_contact_box.h"
#include "data/data_changes.h"
#include "data/data_forum_topic.h"
#include "data/data_photo.h"
#include "data/data_file_origin.h"
#include "ui/boxes/confirm_box.h"
#include "mainwidget.h"
#include "main/main_session.h"
#include "apiwrap.h"
#include "api/api_peer_photo.h"
#include "window/main_window.h"
#include "window/window_separate_id.h"
#include "window/window_session_controller.h"
#include "storage/storage_shared_media.h"
#include "lang/lang_keys.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/popup_menu.h"
#include "ui/widgets/scroll_area.h"
#include "ui/widgets/shadow.h"
#include "ui/widgets/box_content_divider.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/ui_utility.h"
#include "data/data_channel.h"
#include "data/data_shared_media.h"
#include "styles/style_info.h"
#include "styles/style_boxes.h"
#include "styles/style_menu_icons.h"
namespace Info {
namespace Profile {
namespace {
Window::SeparateSharedMediaType ToSeparateType(
Storage::SharedMediaType type) {
using Type = Storage::SharedMediaType;
using SeparatedType = Window::SeparateSharedMediaType;
return (type == Type::Photo)
? SeparatedType::Photos
: (type == Type::Video)
? SeparatedType::Videos
: (type == Type::File)
? SeparatedType::Files
: (type == Type::MusicFile)
? SeparatedType::Audio
: (type == Type::Link)
? SeparatedType::Links
: (type == Type::RoundVoiceFile)
? SeparatedType::Voices
: (type == Type::GIF)
? SeparatedType::GIF
: SeparatedType::None;
}
Fn<void()> SeparateWindowFactory(
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer,
MsgId topicRootId,
Storage::SharedMediaType type) {
const auto separateType = ToSeparateType(type);
if (separateType == Window::SeparateSharedMediaType::None) {
return nullptr;
}
return [=] {
controller->showInNewWindow({
Window::SeparateSharedMedia(separateType, peer, topicRootId),
});
};
}
void AddContextMenu(
not_null<Ui::AbstractButton*> button,
Fn<void()> openInWindow) {
if (!openInWindow) {
return;
}
button->setAcceptBoth();
struct State final {
base::unique_qptr<Ui::PopupMenu> menu;
};
const auto state = button->lifetime().make_state<State>();
button->addClickHandler([=](Qt::MouseButton mouse) {
if (mouse != Qt::RightButton) {
return;
}
state->menu = base::make_unique_q<Ui::PopupMenu>(
button.get(),
st::popupMenuWithIcons);
state->menu->addAction(tr::lng_context_new_window(tr::now), [=] {
base::call_delayed(
st::popupMenuWithIcons.showDuration,
crl::guard(button, openInWindow));
}, &st::menuIconNewWindow);
state->menu->popup(QCursor::pos());
});
}
} // namespace
InnerWidget::InnerWidget(
QWidget *parent,
not_null<Controller*> controller,
@ -224,23 +134,14 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
auto addMediaButton = [&](
MediaType type,
const style::icon &icon) {
const auto topicRootId = _topic ? _topic->rootId() : 0;
const auto window = _controller->parentController();
const auto openInWindow = SeparateWindowFactory(
window,
_peer,
topicRootId,
type);
auto result = Media::AddButton(
content,
_controller,
_peer,
topicRootId,
_topic ? _topic->rootId() : 0,
_migrated,
type,
tracker,
openInWindow);
AddContextMenu(result, openInWindow);
tracker);
object_ptr<Profile::FloatingIcon>(
result,
icon,

View file

@ -109,8 +109,7 @@ void SublistsWidget::setupOtherTypes() {
MsgId(), // topicRootId
nullptr, // migrated
buttonType,
tracker,
nullptr);
tracker);
object_ptr<Profile::FloatingIcon>(
result,
icon,