Track session better in media viewer.

This commit is contained in:
John Preston 2020-06-25 13:42:30 +04:00
parent c19c0afe60
commit 8fec04ba7a
4 changed files with 78 additions and 60 deletions

View file

@ -149,12 +149,8 @@ Application::~Application() {
// Depend on activeWindow() for now :( // Depend on activeWindow() for now :(
Shortcuts::Finish(); Shortcuts::Finish();
_window.reset(); _window = nullptr;
_mediaView = nullptr;
if (_mediaView) {
_mediaView->clearData();
_mediaView = nullptr;
}
_domain->finish(); _domain->finish();
Local::finish(); Local::finish();

View file

@ -153,7 +153,6 @@ public:
} }
base::Observable<DocumentData*> documentUpdated; base::Observable<DocumentData*> documentUpdated;
base::Observable<std::pair<not_null<HistoryItem*>, MsgId>> messageIdChanging;
bool supportMode() const; bool supportMode() const;
Support::Helper &supportHelper() const; Support::Helper &supportHelper() const;

View file

@ -321,46 +321,6 @@ OverlayWidget::OverlayWidget()
connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int))); connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int)));
// While we have one mediaview for all sessions we have to do this.
Core::App().domain().activeSessionValue(
) | rpl::start_with_next([=](Main::Session *session) {
if (!isHidden()) {
close();
}
clearData();
setWindowIcon(Window::CreateIcon(session));
if (session) {
// #TODO multi
subscribe(session->downloaderTaskFinished(), [=] {
if (!isHidden()) {
updateControls();
}
});
subscribe(session->calls().currentCallChanged(), [=](Calls::Call *call) {
if (!_streamed) {
return;
}
if (call) {
playbackPauseOnCall();
} else {
playbackResumeOnCall();
}
});
subscribe(session->documentUpdated, [=](DocumentData *document) {
if (!isHidden()) {
documentUpdated(document);
}
});
subscribe(session->messageIdChanging, [=](std::pair<not_null<HistoryItem*>, MsgId> update) {
changingMsgId(update.first, update.second);
});
} else {
_sharedMedia = nullptr;
_userPhotos = nullptr;
_collage = nullptr;
}
}, lifetime());
#if defined Q_OS_UNIX && !defined Q_OS_MAC #if defined Q_OS_UNIX && !defined Q_OS_MAC
setWindowFlags(Qt::FramelessWindowHint | Qt::MaximizeUsingFullscreenGeometryHint); setWindowFlags(Qt::FramelessWindowHint | Qt::MaximizeUsingFullscreenGeometryHint);
#else // Q_OS_UNIX && !Q_OS_MAC #else // Q_OS_UNIX && !Q_OS_MAC
@ -554,9 +514,9 @@ void OverlayWidget::documentUpdated(DocumentData *doc) {
} }
} }
void OverlayWidget::changingMsgId(not_null<HistoryItem*> row, MsgId newId) { void OverlayWidget::changingMsgId(not_null<HistoryItem*> row, MsgId oldId) {
if (row->fullId() == _msgid) { if (FullMsgId(row->channelId(), oldId) == _msgid) {
_msgid = FullMsgId(_msgid.channel, newId); _msgid = row->fullId();
refreshMediaViewer(); refreshMediaViewer();
} }
} }
@ -1090,10 +1050,11 @@ void OverlayWidget::zoomUpdate(int32 &newZoom) {
setZoomLevel(newZoom); setZoomLevel(newZoom);
} }
void OverlayWidget::clearData() { void OverlayWidget::clearSession() {
if (!isHidden()) { if (!isHidden()) {
hide(); hide();
} }
_sessionLifetime.destroy();
if (!_animations.empty()) { if (!_animations.empty()) {
_animations.clear(); _animations.clear();
_stateAnimation.stop(); _stateAnimation.stop();
@ -1111,11 +1072,14 @@ void OverlayWidget::clearData() {
_pip = nullptr; _pip = nullptr;
_fullScreenVideo = false; _fullScreenVideo = false;
_caption.clear(); _caption.clear();
_sharedMedia = nullptr;
_userPhotos = nullptr;
_collage = nullptr;
_session = nullptr; _session = nullptr;
} }
OverlayWidget::~OverlayWidget() { OverlayWidget::~OverlayWidget() {
delete base::take(_menu); clearSession();
} }
void OverlayWidget::assignMediaPointer(DocumentData *document) { void OverlayWidget::assignMediaPointer(DocumentData *document) {
@ -1963,8 +1927,10 @@ void OverlayWidget::clearControlsState() {
} }
} }
void OverlayWidget::showPhoto(not_null<PhotoData*> photo, HistoryItem *context) { void OverlayWidget::showPhoto(
_session = &photo->session(); not_null<PhotoData*> photo,
HistoryItem *context) {
setSession(&photo->session());
if (context) { if (context) {
setContext(context); setContext(context);
@ -1981,9 +1947,10 @@ void OverlayWidget::showPhoto(not_null<PhotoData*> photo, HistoryItem *context)
activateControls(); activateControls();
} }
void OverlayWidget::showPhoto(not_null<PhotoData*> photo, not_null<PeerData*> context) { void OverlayWidget::showPhoto(
_session = &photo->session(); not_null<PhotoData*> photo,
not_null<PeerData*> context) {
setSession(&photo->session());
setContext(context); setContext(context);
clearControlsState(); clearControlsState();
@ -2012,7 +1979,7 @@ void OverlayWidget::showDocument(
HistoryItem *context, HistoryItem *context,
const Data::CloudTheme &cloud, const Data::CloudTheme &cloud,
bool continueStreaming) { bool continueStreaming) {
_session = &document->session(); setSession(&document->session());
if (context) { if (context) {
setContext(context); setContext(context);
@ -3545,6 +3512,59 @@ void OverlayWidget::setContext(
_user = _peer ? _peer->asUser() : nullptr; _user = _peer ? _peer->asUser() : nullptr;
} }
void OverlayWidget::setSession(not_null<Main::Session*> session) {
if (_session == session) {
return;
}
clearSession();
_session = session;
setWindowIcon(Window::CreateIcon(session));
base::ObservableViewer(
session->downloaderTaskFinished()
) | rpl::start_with_next([=] {
if (!isHidden()) {
updateControls();
}
}, _sessionLifetime);
base::ObservableViewer(
session->calls().currentCallChanged()
) | rpl::start_with_next([=](Calls::Call *call) {
if (!_streamed) {
return;
}
if (call) {
playbackPauseOnCall();
} else {
playbackResumeOnCall();
}
}, _sessionLifetime);
base::ObservableViewer(
session->documentUpdated
) | rpl::start_with_next([=](DocumentData *document) {
if (!isHidden()) {
documentUpdated(document);
}
}, _sessionLifetime);
session->data().itemIdChanged(
) | rpl::start_with_next([=](const Data::Session::IdChange &change) {
changingMsgId(change.item, change.oldId);
}, _sessionLifetime);
session->account().sessionChanges(
) | rpl::start_with_next_done([=](Main::Session *value) {
if (value != session) {
clearSession();
}
}, [=] {
clearSession();
}, _sessionLifetime);
}
bool OverlayWidget::moveToNext(int delta) { bool OverlayWidget::moveToNext(int delta) {
if (!_index) { if (!_index) {
return false; return false;

View file

@ -96,7 +96,7 @@ public:
void notifyFileDialogShown(bool shown); void notifyFileDialogShown(bool shown);
void clearData(); void clearSession();
~OverlayWidget(); ~OverlayWidget();
@ -169,6 +169,8 @@ private:
void setVisibleHook(bool visible) override; void setVisibleHook(bool visible) override;
void setSession(not_null<Main::Session*> session);
void playbackControlsPlay() override; void playbackControlsPlay() override;
void playbackControlsPause() override; void playbackControlsPause() override;
void playbackControlsSeekProgress(crl::time position) override; void playbackControlsSeekProgress(crl::time position) override;
@ -288,7 +290,7 @@ private:
void updateThemePreviewGeometry(); void updateThemePreviewGeometry();
void documentUpdated(DocumentData *doc); void documentUpdated(DocumentData *doc);
void changingMsgId(not_null<HistoryItem*> row, MsgId newId); void changingMsgId(not_null<HistoryItem*> row, MsgId oldId);
[[nodiscard]] int contentRotation() const; [[nodiscard]] int contentRotation() const;
[[nodiscard]] QRect contentRect() const; [[nodiscard]] QRect contentRect() const;
@ -352,6 +354,7 @@ private:
QBrush _transparentBrush; QBrush _transparentBrush;
Main::Session *_session = nullptr; Main::Session *_session = nullptr;
rpl::lifetime _sessionLifetime;
PhotoData *_photo = nullptr; PhotoData *_photo = nullptr;
DocumentData *_document = nullptr; DocumentData *_document = nullptr;
std::shared_ptr<Data::PhotoMedia> _photoMedia; std::shared_ptr<Data::PhotoMedia> _photoMedia;