Move MediaView from MainWindow to Messenger.

This commit is contained in:
John Preston 2017-08-08 11:31:48 +02:00
parent fa818407e6
commit b08732cf28
28 changed files with 266 additions and 271 deletions

View File

@ -160,7 +160,7 @@ namespace App {
MainWindow *wnd() {
if (auto instance = Messenger::InstancePointer()) {
return instance->mainWindow();
return instance->getActiveWindow();
}
return nullptr;
}

View File

@ -222,6 +222,9 @@ public:
void checkAutoLock();
void checkAutoLockIn(TimeMs time);
base::Observable<DocumentData*> documentUpdated;
base::Observable<std::pair<HistoryItem*, MsgId>> messageIdChanging;
~AuthSession();
private:

View File

@ -24,6 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "storage/localstorage.h"
#include "platform/platform_file_utilities.h"
#include "base/task_queue.h"
#include "messenger.h"
bool filedialogGetSaveFile(QString &file, const QString &caption, const QString &filter, const QString &initialPath) {
QStringList files;
@ -220,7 +221,7 @@ bool GetDefault(QStringList &files, QByteArray &remoteContent, const QString &ca
}
QString file;
if (type == Type::ReadFiles) {
files = QFileDialog::getOpenFileNames(App::wnd() ? App::wnd()->filedialogParent() : 0, caption, startFile, filter);
files = QFileDialog::getOpenFileNames(Messenger::Instance().getFileDialogParent(), caption, startFile, filter);
QString path = files.isEmpty() ? QString() : QFileInfo(files.back()).absoluteDir().absolutePath();
if (!path.isEmpty() && path != cDialogLastPath()) {
cSetDialogLastPath(path);
@ -228,11 +229,11 @@ bool GetDefault(QStringList &files, QByteArray &remoteContent, const QString &ca
}
return !files.isEmpty();
} else if (type == Type::ReadFolder) {
file = QFileDialog::getExistingDirectory(App::wnd() ? App::wnd()->filedialogParent() : 0, caption, startFile);
file = QFileDialog::getExistingDirectory(Messenger::Instance().getFileDialogParent(), caption, startFile);
} else if (type == Type::WriteFile) {
file = QFileDialog::getSaveFileName(App::wnd() ? App::wnd()->filedialogParent() : 0, caption, startFile, filter);
file = QFileDialog::getSaveFileName(Messenger::Instance().getFileDialogParent(), caption, startFile, filter);
} else {
file = QFileDialog::getOpenFileName(App::wnd() ? App::wnd()->filedialogParent() : 0, caption, startFile, filter);
file = QFileDialog::getOpenFileName(Messenger::Instance().getFileDialogParent(), caption, startFile, filter);
}
if (file.isEmpty()) {
files = QStringList();

View File

@ -241,11 +241,6 @@ bool isLayerShown() {
return false;
}
bool isMediaViewShown() {
if (auto w = App::wnd()) return w->ui_isMediaViewShown();
return false;
}
void repaintHistoryItem(gsl::not_null<const HistoryItem*> item) {
if (auto main = App::main()) {
main->ui_repaintHistoryItem(item);
@ -282,10 +277,7 @@ void showPeerHistoryAsync(const PeerId &peer, MsgId msgId, ShowWay way) {
}
PeerData *getPeerForMouseAction() {
if (auto w = App::wnd()) {
return w->ui_getPeerForMouseAction();
}
return nullptr;
return Messenger::Instance().ui_getPeerForMouseAction();
}
bool hideWindowNoQuit() {

View File

@ -103,7 +103,6 @@ QPointer<BoxType> show(object_ptr<BoxType> content, ShowLayerOptions options = C
void hideLayer(bool fast = false);
void hideSettingsAndLayer(bool fast = false);
bool isLayerShown();
bool isMediaViewShown();
void repaintHistoryItem(gsl::not_null<const HistoryItem*> item);
void autoplayMediaInlineAsync(const FullMsgId &msgId);

View File

@ -29,6 +29,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "chat_helpers/message_field.h"
#include "mainwindow.h"
#include "mainwidget.h"
#include "messenger.h"
#include "apiwrap.h"
#include "window/window_controller.h"
#include "auth_session.h"
@ -986,7 +987,7 @@ void InnerWidget::openContextGif() {
if (auto item = App::contextItem()) {
if (auto media = item->getMedia()) {
if (auto document = media->getDocument()) {
_controller->window()->showDocument(document, item);
Messenger::Instance().showDocument(document, item);
}
}
}

View File

@ -33,6 +33,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "mainwindow.h"
#include "mainwidget.h"
#include "auth_session.h"
#include "messenger.h"
#include "apiwrap.h"
#include "lang/lang_keys.h"
@ -1463,7 +1464,7 @@ void HistoryInner::openContextGif() {
if (auto item = App::contextItem()) {
if (auto media = item->getMedia()) {
if (auto document = media->getDocument()) {
_controller->window()->showDocument(document, item);
Messenger::Instance().showDocument(document, item);
}
}
}

View File

@ -828,7 +828,7 @@ void MainWidget::notify_historyMuteUpdated(History *history) {
}
bool MainWidget::cmd_search() {
if (Ui::isLayerShown() || Ui::isMediaViewShown()) return false;
if (Ui::isLayerShown() || !isActiveWindow()) return false;
if (_wideSection) {
return _wideSection->cmd_search();
}
@ -836,12 +836,12 @@ bool MainWidget::cmd_search() {
}
bool MainWidget::cmd_next_chat() {
if (Ui::isLayerShown() || Ui::isMediaViewShown()) return false;
if (Ui::isLayerShown() || !isActiveWindow()) return false;
return _history->cmd_next_chat();
}
bool MainWidget::cmd_previous_chat() {
if (Ui::isLayerShown() || Ui::isMediaViewShown()) return false;
if (Ui::isLayerShown() || !isActiveWindow()) return false;
return _history->cmd_previous_chat();
}
@ -1557,7 +1557,7 @@ bool MainWidget::insertBotCommand(const QString &cmd) {
}
void MainWidget::searchMessages(const QString &query, PeerData *inPeer) {
App::wnd()->hideMediaview();
Messenger::Instance().hideMediaView();
_dialogs->searchMessages(query, inPeer);
if (Adaptive::OneColumn()) {
Ui::showChatsList();
@ -1606,10 +1606,6 @@ void MainWidget::mediaOverviewUpdated(const Notify::PeerUpdate &update) {
}
}
void MainWidget::changingMsgId(HistoryItem *row, MsgId newId) {
if (_overview) _overview->changingMsgId(row, newId);
}
void MainWidget::itemEdited(HistoryItem *item) {
if (_history->peer() == item->history()->peer || (_history->peer() && _history->peer() == item->history()->peer->migrateTo())) {
_history->itemEdited(item);
@ -1926,7 +1922,7 @@ void MainWidget::documentLoadProgress(DocumentData *document) {
Ui::repaintHistoryItem(item);
}
}
App::wnd()->documentUpdated(document);
Auth().documentUpdated.notify(document, true);
if (!document->loaded() && document->song()) {
Media::Player::instance()->documentLoadProgress(document);
@ -3941,7 +3937,7 @@ bool MainWidget::started() {
}
void MainWidget::openPeerByName(const QString &username, MsgId msgId, const QString &startToken) {
App::wnd()->hideMediaview();
Messenger::Instance().hideMediaView();
PeerData *peer = App::peerByName(username);
if (peer) {
@ -3981,12 +3977,12 @@ void MainWidget::openPeerByName(const QString &username, MsgId msgId, const QStr
}
void MainWidget::joinGroupByHash(const QString &hash) {
App::wnd()->hideMediaview();
Messenger::Instance().hideMediaView();
MTP::send(MTPmessages_CheckChatInvite(MTP_string(hash)), rpcDone(&MainWidget::inviteCheckDone, hash), rpcFail(&MainWidget::inviteCheckFail));
}
void MainWidget::stickersBox(const MTPInputStickerSet &set) {
App::wnd()->hideMediaview();
Messenger::Instance().hideMediaView();
auto box = Ui::show(Box<StickerSetBox>(set));
connect(box, SIGNAL(installed(uint64)), this, SLOT(onStickersInstalled(uint64)));
}
@ -4768,7 +4764,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
_history->peerMessagesUpdated();
} else {
App::historyUnregItem(msgRow);
if (App::wnd()) App::wnd()->changingMsgId(msgRow, d.vid.v);
Auth().messageIdChanging.notify({ msgRow, d.vid.v }, true);
msgRow->setId(d.vid.v);
if (msgRow->history()->peer->isSelf()) {
msgRow->history()->unregSendAction(App::self());

View File

@ -318,7 +318,6 @@ public:
void jumpToDate(gsl::not_null<PeerData*> peer, const QDate &date);
void searchMessages(const QString &query, PeerData *inPeer);
bool preloadOverview(PeerData *peer, MediaOverviewType type);
void changingMsgId(HistoryItem *row, MsgId newId);
void itemEdited(HistoryItem *item);
void loadMediaBack(PeerData *peer, MediaOverviewType type, bool many = false);

View File

@ -181,8 +181,6 @@ void MainWindow::firstShow() {
psFirstShow();
updateTrayMenu();
createMediaView();
}
void MainWindow::clearWidgetsHook() {
@ -229,7 +227,7 @@ void MainWindow::setupPasscode() {
updateControlsGeometry();
if (_main) _main->hide();
hideMediaview();
Messenger::Instance().hideMediaView();
Ui::hideSettingsAndLayer(true);
if (_intro) _intro->hide();
if (animated) {
@ -421,7 +419,7 @@ void MainWindow::ui_showBox(object_ptr<BoxContent> box, ShowLayerOptions options
destroyLayerDelayed();
}
}
hideMediaview();
Messenger::Instance().hideMediaView();
}
}
@ -460,15 +458,6 @@ void MainWindow::ui_hideMediaPreview() {
_mediaPreview->hidePreview();
}
PeerData *MainWindow::ui_getPeerForMouseAction() {
if (Ui::isMediaViewShown()) {
return Platform::MainWindow::ui_getPeerForMouseAction();
} else if (_main) {
return _main->ui_getPeerForMouseAction();
}
return nullptr;
}
void MainWindow::showConnecting(const QString &text, const QString &reconnect) {
if (_connecting) {
_connecting->set(text, reconnect);
@ -555,74 +544,47 @@ void MainWindow::setInnerFocus() {
bool MainWindow::eventFilter(QObject *object, QEvent *e) {
switch (e->type()) {
case QEvent::KeyPress:
case QEvent::KeyPress: {
if (cDebug() && e->type() == QEvent::KeyPress && object == windowHandle()) {
auto key = static_cast<QKeyEvent*>(e)->key();
FeedLangTestingKey(key);
}
// [[fallthrough]];
case QEvent::MouseButtonPress:
case QEvent::TouchBegin:
case QEvent::Wheel:
psUserActionDone();
break;
} break;
case QEvent::MouseMove:
case QEvent::MouseMove: {
if (_main && _main->isIdle()) {
psUserActionDone();
_main->checkIdleFinish();
}
break;
} break;
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonRelease: {
Ui::hideMediaPreview();
break;
} break;
case QEvent::ShortcutOverride: // handle shortcuts ourselves
return true;
case QEvent::Shortcut:
DEBUG_LOG(("Shortcut event caught: %1").arg(static_cast<QShortcutEvent*>(e)->key().toString()));
if (Shortcuts::launch(static_cast<QShortcutEvent*>(e)->shortcutId())) {
return true;
}
break;
case QEvent::ApplicationActivate:
case QEvent::ApplicationActivate: {
if (object == QCoreApplication::instance()) {
psUserActionDone();
App::CallDelayed(1, this, [this] {
InvokeQueued(this, [this] {
handleActiveChanged();
});
}
break;
} break;
case QEvent::FileOpen:
if (object == QCoreApplication::instance()) {
QString url = static_cast<QFileOpenEvent*>(e)->url().toEncoded().trimmed();
if (url.startsWith(qstr("tg://"), Qt::CaseInsensitive)) {
cSetStartUrl(url.mid(0, 8192));
Messenger::Instance().checkStartUrl();
}
activate();
}
break;
case QEvent::WindowStateChange:
case QEvent::WindowStateChange: {
if (object == this) {
auto state = (windowState() & Qt::WindowMinimized) ? Qt::WindowMinimized :
((windowState() & Qt::WindowMaximized) ? Qt::WindowMaximized :
((windowState() & Qt::WindowFullScreen) ? Qt::WindowFullScreen : Qt::WindowNoState));
handleStateChanged(state);
}
break;
} break;
case QEvent::Move:
case QEvent::Resize:
case QEvent::Resize: {
if (object == this) {
positionUpdated();
}
break;
} break;
}
return Platform::MainWindow::eventFilter(object, e);
@ -990,18 +952,13 @@ QImage MainWindow::iconWithCounter(int size, int count, style::color bg, style::
void MainWindow::sendPaths() {
if (App::passcoded()) return;
hideMediaview();
Messenger::Instance().hideMediaView();
Ui::hideSettingsAndLayer(true);
if (_main) {
_main->activate();
}
}
void MainWindow::changingMsgId(HistoryItem *row, MsgId newId) {
if (_main) _main->changingMsgId(row, newId);
Platform::MainWindow::changingMsgId(row, newId);
}
void MainWindow::updateIsActiveHook() {
if (_main) _main->updateOnline();
}

View File

@ -115,8 +115,6 @@ public:
void sendPaths();
void changingMsgId(HistoryItem *row, MsgId newId) override;
QImage iconWithCounter(int size, int count, style::color bg, style::color fg, bool smallIcon) override;
bool contentOverlapped(const QRect &globalRect);
@ -138,7 +136,6 @@ public:
void ui_showMediaPreview(DocumentData *document);
void ui_showMediaPreview(PhotoData *photo);
void ui_hideMediaPreview();
PeerData *ui_getPeerForMouseAction() override;
protected:
bool eventFilter(QObject *o, QEvent *e) override;

View File

@ -72,7 +72,7 @@ bool typeHasMediaOverview(MediaOverviewType type) {
} // namespace
MediaView::MediaView(QWidget*) : TWidget(nullptr)
MediaView::MediaView() : TWidget(nullptr)
, _transparentBrush(style::transparentPlaceholderBrush())
, _animStarted(getms())
, _docDownload(this, lang(lng_media_download), st::mediaviewFileLink)
@ -106,6 +106,14 @@ MediaView::MediaView(QWidget*) : TWidget(nullptr)
onVideoPauseResume();
}
});
subscribe(Auth().documentUpdated, [this](DocumentData *document) {
if (!isHidden()) {
documentUpdated(document);
}
});
subscribe(Auth().messageIdChanging, [this](std::pair<HistoryItem*, MsgId> update) {
changingMsgId(update.first, update.second);
});
}
};
subscribe(Messenger::Instance().authSessionChanged(), [handleAuthSessionChange] {
@ -133,8 +141,6 @@ MediaView::MediaView(QWidget*) : TWidget(nullptr)
_saveMsgUpdater.setSingleShot(true);
connect(&_saveMsgUpdater, SIGNAL(timeout()), this, SLOT(updateImage()));
connect(App::wnd()->windowHandle(), SIGNAL(activeChanged()), this, SLOT(onCheckActive()));
setAttribute(Qt::WA_AcceptTouchEvents);
_touchTimer.setSingleShot(true);
connect(&_touchTimer, SIGNAL(timeout()), this, SLOT(onTouchTimer()));
@ -156,17 +162,24 @@ void MediaView::refreshLang() {
}
void MediaView::moveToScreen() {
if (App::wnd() && windowHandle() && App::wnd()->windowHandle() && windowHandle()->screen() != App::wnd()->windowHandle()->screen()) {
windowHandle()->setScreen(App::wnd()->windowHandle()->screen());
auto widgetScreen = [this](auto &&widget) -> QScreen* {
if (auto handle = widget ? widget->windowHandle() : nullptr) {
return handle->screen();
}
return nullptr;
};
auto activeWindow = Messenger::Instance().getActiveWindow();
auto activeWindowScreen = widgetScreen(activeWindow);
auto myScreen = widgetScreen(this);
if (activeWindowScreen && myScreen && myScreen != activeWindowScreen) {
windowHandle()->setScreen(activeWindowScreen);
}
auto available = activeWindow ? Sandbox::screenGeometry(activeWindow->geometry().center()) : QApplication::desktop()->screenGeometry();
if (geometry() != available) {
setGeometry(available);
}
auto wndCenter = App::wnd()->geometry().center();
QRect avail = Sandbox::screenGeometry(wndCenter);
if (avail != geometry()) {
setGeometry(avail);
}
int32 navSkip = 2 * st::mediaviewControlMargin + st::mediaviewControlSize;
auto navSkip = 2 * st::mediaviewControlMargin + st::mediaviewControlSize;
_closeNav = myrtlrect(width() - st::mediaviewControlMargin - st::mediaviewControlSize, st::mediaviewControlMargin, st::mediaviewControlSize, st::mediaviewControlSize);
_closeNavIcon = centerrect(_closeNav, st::mediaviewClose);
_leftNav = myrtlrect(st::mediaviewControlMargin, navSkip, st::mediaviewControlSize, height() - 2 * navSkip);
@ -275,10 +288,12 @@ void MediaView::changingMsgId(HistoryItem *row, MsgId newId) {
}
// Send a fake update.
Notify::PeerUpdate update(row->history()->peer);
update.flags |= Notify::PeerUpdate::Flag::SharedMediaChanged;
update.mediaTypesMask |= (1 << _overview);
mediaOverviewUpdated(update);
if (!isHidden()) {
Notify::PeerUpdate update(row->history()->peer);
update.flags |= Notify::PeerUpdate::Flag::SharedMediaChanged;
update.mediaTypesMask |= (1 << _overview);
mediaOverviewUpdated(update);
}
}
void MediaView::updateDocSize() {
@ -670,9 +685,7 @@ void MediaView::updateMixerVideoVolume() const {
void MediaView::close() {
if (_menu) _menu->hideMenu(true);
if (App::wnd()) {
Ui::hideLayer(true);
}
Messenger::Instance().hideMediaView();
}
void MediaView::activateControls() {
@ -750,10 +763,8 @@ void MediaView::onScreenResized(int screen) {
void MediaView::onToMessage() {
if (auto item = _msgid ? App::histItemById(_msgmigrated ? 0 : _channel, _msgid) : 0) {
if (App::wnd()) {
close();
Ui::showPeerHistoryAtItem(item);
}
close();
Ui::showPeerHistoryAtItem(item);
}
}
@ -957,13 +968,11 @@ void MediaView::onForward() {
auto item = App::histItemById(_msgmigrated ? 0 : _channel, _msgid);
if (!_msgid || !item || item->id < 0 || item->serviceMsg()) return;
if (App::wnd()) {
close();
if (auto main = App::main()) {
auto items = SelectedItemSet();
items.insert(item->id, item);
main->showForwardLayer(items);
}
close();
if (auto main = App::main()) {
auto items = SelectedItemSet();
items.insert(item->id, item);
main->showForwardLayer(items);
}
}
@ -2528,7 +2537,7 @@ void MediaView::mouseReleaseEvent(QMouseEvent *e) {
}
if (_over == OverName && _down == OverName) {
if (App::wnd() && _from) {
if (_from) {
close();
Ui::showPeerProfile(_from);
}
@ -2608,15 +2617,15 @@ void MediaView::touchEvent(QTouchEvent *e) {
case QEvent::TouchEnd:
if (!_touchPress) return;
if (!_touchMove && App::wnd()) {
if (!_touchMove) {
Qt::MouseButton btn(_touchRightButton ? Qt::RightButton : Qt::LeftButton);
QPoint mapped(mapFromGlobal(_touchStart)), winMapped(App::wnd()->mapFromGlobal(_touchStart));
auto mapped = mapFromGlobal(_touchStart);
QMouseEvent pressEvent(QEvent::MouseButtonPress, mapped, winMapped, _touchStart, btn, Qt::MouseButtons(btn), Qt::KeyboardModifiers());
QMouseEvent pressEvent(QEvent::MouseButtonPress, mapped, mapped, _touchStart, btn, Qt::MouseButtons(btn), Qt::KeyboardModifiers());
pressEvent.accept();
mousePressEvent(&pressEvent);
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, mapped, winMapped, _touchStart, btn, Qt::MouseButtons(btn), Qt::KeyboardModifiers());
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, mapped, mapped, _touchStart, btn, Qt::MouseButtons(btn), Qt::KeyboardModifiers());
mouseReleaseEvent(&releaseEvent);
if (_touchRightButton) {
@ -2733,16 +2742,6 @@ void MediaView::onDropdown() {
_dropdown->setFocus();
}
void MediaView::onCheckActive() {
if (App::wnd() && isVisible()) {
if (App::wnd()->isActiveWindow() && App::wnd()->hasFocus()) {
activateWindow();
Sandbox::setActiveWindow(this);
setFocus();
}
}
}
void MediaView::onTouchTimer() {
_touchRightButton = true;
}

View File

@ -52,7 +52,7 @@ class MediaView : public TWidget, private base::Subscriber, public RPCSender, pu
Q_OBJECT
public:
MediaView(QWidget*);
MediaView();
void setVisible(bool visible) override;
@ -73,8 +73,6 @@ public:
}
void mediaOverviewUpdated(const Notify::PeerUpdate &update);
void documentUpdated(DocumentData *doc);
void changingMsgId(HistoryItem *row, MsgId newId);
void close();
@ -126,7 +124,6 @@ private slots:
void onDropdown();
void onCheckActive();
void onTouchTimer();
void updateImage();
@ -186,6 +183,9 @@ private:
void destroyThemePreview();
void updateThemePreviewGeometry();
void documentUpdated(DocumentData *doc);
void changingMsgId(HistoryItem *row, MsgId newId);
// Radial animation interface.
float64 radialProgress() const;
bool radialLoading() const;

View File

@ -35,6 +35,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "observer_peer.h"
#include "storage/file_upload.h"
#include "mainwidget.h"
#include "mediaview.h"
#include "mtproto/dc_options.h"
#include "mtproto/mtp_instance.h"
#include "media/player/media_player_instance.h"
@ -129,6 +130,9 @@ Messenger::Messenger() : QObject()
_window->createWinId();
_window->init();
_mediaView = std::make_unique<MediaView>();
QCoreApplication::instance()->installEventFilter(this);
Sandbox::connect(SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onAppStateChanged(Qt::ApplicationState)));
DEBUG_LOG(("Application Info: window created..."));
@ -180,6 +184,97 @@ Messenger::Messenger() : QObject()
}
}
bool Messenger::hideMediaView() {
if (_mediaView && !_mediaView->isHidden()) {
_mediaView->hide();
_window->reActivateWindow();
return true;
}
return false;
}
void Messenger::showPhoto(gsl::not_null<const PhotoOpenClickHandler*> link, HistoryItem *item) {
return (!item && link->peer())
? showPhoto(link->photo(), link->peer())
: showPhoto(link->photo(), item);
}
void Messenger::showPhoto(gsl::not_null<PhotoData*> photo, HistoryItem *item) {
if (_mediaView->isHidden()) Ui::hideLayer(true);
_mediaView->showPhoto(photo, item);
_mediaView->activateWindow();
_mediaView->setFocus();
}
void Messenger::showPhoto(gsl::not_null<PhotoData*> photo, PeerData *peer) {
if (_mediaView->isHidden()) Ui::hideLayer(true);
_mediaView->showPhoto(photo, peer);
_mediaView->activateWindow();
_mediaView->setFocus();
}
void Messenger::showDocument(gsl::not_null<DocumentData*> document, HistoryItem *item) {
if (cUseExternalVideoPlayer() && document->isVideo()) {
QDesktopServices::openUrl(QUrl("file:///" + document->location(false).fname));
} else {
if (_mediaView->isHidden()) Ui::hideLayer(true);
_mediaView->showDocument(document, item);
_mediaView->activateWindow();
_mediaView->setFocus();
}
}
PeerData *Messenger::ui_getPeerForMouseAction() {
if (_mediaView && !_mediaView->isHidden()) {
return _mediaView->ui_getPeerForMouseAction();
} else if (auto main = App::main()) {
return main->ui_getPeerForMouseAction();
}
return nullptr;
}
bool Messenger::eventFilter(QObject *object, QEvent *e) {
switch (e->type()) {
case QEvent::KeyPress:
case QEvent::MouseButtonPress:
case QEvent::TouchBegin:
case QEvent::Wheel: {
psUserActionDone();
} break;
case QEvent::ShortcutOverride: {
// handle shortcuts ourselves
return true;
} break;
case QEvent::Shortcut: {
DEBUG_LOG(("Shortcut event caught: %1").arg(static_cast<QShortcutEvent*>(e)->key().toString()));
if (Shortcuts::launch(static_cast<QShortcutEvent*>(e)->shortcutId())) {
return true;
}
} break;
case QEvent::ApplicationActivate: {
if (object == QCoreApplication::instance()) {
psUserActionDone();
}
} break;
case QEvent::FileOpen: {
if (object == QCoreApplication::instance()) {
auto url = QString::fromUtf8(static_cast<QFileOpenEvent*>(e)->url().toEncoded().trimmed());
if (url.startsWith(qstr("tg://"), Qt::CaseInsensitive)) {
cSetStartUrl(url.mid(0, 8192));
checkStartUrl();
}
_window->activate();
}
} break;
}
return QObject::eventFilter(object, e);
}
void Messenger::setMtpMainDcId(MTP::DcId mainDcId) {
Expects(!_mtproto);
_private->mtpConfig.mainDcId = mainDcId;
@ -616,6 +711,8 @@ void Messenger::authSessionDestroy() {
_private->storedAuthSession.reset();
_private->authSessionUserId = 0;
authSessionChanged().notify(true);
loggedOut();
}
void Messenger::setInternalLinkDomain(const QString &domain) const {
@ -800,6 +897,7 @@ Messenger::~Messenger() {
Expects(SingleInstance == this);
_window.reset();
_mediaView.reset();
// Some MTP requests can be cancelled from data clearing.
App::clearHistories();
@ -832,10 +930,30 @@ Messenger::~Messenger() {
SingleInstance = nullptr;
}
MainWindow *Messenger::mainWindow() {
MainWindow *Messenger::getActiveWindow() {
return _window.get();
}
QWidget *Messenger::getFileDialogParent() {
return (_mediaView && _mediaView->isVisible()) ? (QWidget*)_mediaView.get() : (QWidget*)getActiveWindow();
}
void Messenger::checkMediaViewActivation() {
if (_mediaView && !_mediaView->isHidden()) {
_mediaView->activateWindow();
Sandbox::setActiveWindow(_mediaView.get());
_mediaView->setFocus();
}
}
void Messenger::loggedOut() {
if (_mediaView) {
hideMediaView();
_mediaView->rpcClear();
_mediaView->clearData();
}
}
QPoint Messenger::getPointForCallPanelCenter() const {
Expects(_window != nullptr);
Expects(_window->windowHandle() != nullptr);

View File

@ -41,6 +41,7 @@ class AuthSessionData;
class MainWidget;
class FileUploader;
class Translator;
class MediaView;
namespace Local {
struct StoredAuthSession;
@ -69,7 +70,22 @@ public:
~Messenger();
MainWindow *mainWindow();
// Windows interface.
MainWindow *getActiveWindow();
QWidget *getFileDialogParent();
QWidget *getGlobalShortcutParent() {
return &_globalShortcutParent;
}
// MediaView interface.
void checkMediaViewActivation();
bool hideMediaView();
void showPhoto(gsl::not_null<const PhotoOpenClickHandler*> link, HistoryItem *item = nullptr);
void showPhoto(gsl::not_null<PhotoData*> photo, HistoryItem *item);
void showPhoto(gsl::not_null<PhotoData*> photo, PeerData *item);
void showDocument(gsl::not_null<DocumentData*> document, HistoryItem *item);
PeerData *ui_getPeerForMouseAction();
QPoint getPointForCallPanelCenter() const;
QImage logo() const {
return _logo;
@ -174,6 +190,9 @@ public:
_callDelayedTimer.call(duration, std::move(lambda));
}
protected:
bool eventFilter(QObject *object, QEvent *event) override;
signals:
void peerPhotoDone(PeerId peer);
void peerPhotoFail(PeerId peer);
@ -198,6 +217,8 @@ private:
static void QuitAttempt();
void quitDelayed();
void loggedOut();
QMap<FullMsgId, PeerId> photoUpdates;
QMap<MTP::DcId, TimeMs> killDownloadSessionTimes;
@ -207,7 +228,10 @@ private:
struct Private;
const std::unique_ptr<Private> _private;
QWidget _globalShortcutParent;
std::unique_ptr<MainWindow> _window;
std::unique_ptr<MediaView> _mediaView;
std::unique_ptr<Lang::Instance> _langpack;
std::unique_ptr<Lang::CloudManager> _langCloudManager;
std::unique_ptr<Lang::Translator> _translator;

View File

@ -41,7 +41,7 @@ namespace Layout {
namespace {
TextParseOptions _documentNameOptions = {
TextParseMultiline | TextParseRichText | TextParseLinks | TextParseHashtags | TextParseMentions | TextParseBotCommands | TextParseMarkdown, // flags
TextParseMultiline | TextParseRichText | TextParseLinks | TextParseMarkdown, // flags
0, // maxw
0, // maxh
Qt::LayoutDirectionAuto, // dir

View File

@ -96,6 +96,9 @@ OverviewInner::OverviewInner(OverviewWidget *overview, Ui::ScrollArea *scroll, P
subscribe(App::wnd()->dragFinished(), [this] {
dragActionUpdate(QCursor::pos());
});
subscribe(Auth().messageIdChanging, [this](std::pair<HistoryItem*, MsgId> update) {
changingMsgId(update.first, update.second);
});
if (_type == OverviewLinks || _type == OverviewFiles) {
_search->show();
@ -1725,6 +1728,10 @@ void OverviewInner::mediaOverviewUpdated() {
}
void OverviewInner::changingMsgId(HistoryItem *row, MsgId newId) {
if (peer() != row->history()->peer && migratePeer() != row->history()->peer) {
return;
}
MsgId oldId = complexMsgId(row);
if (row->history() == _migrated) newId = -newId;
@ -2245,12 +2252,6 @@ void OverviewWidget::mediaOverviewUpdated(const Notify::PeerUpdate &update) {
}
}
void OverviewWidget::changingMsgId(HistoryItem *row, MsgId newId) {
if (peer() == row->history()->peer || migratePeer() == row->history()->peer) {
_inner->changingMsgId(row, newId);
}
}
void OverviewWidget::grapWithoutTopBarShadow() {
grabStart();
_topShadow->hide();

View File

@ -88,7 +88,6 @@ public:
void setSelectMode(bool enabled);
void mediaOverviewUpdated();
void changingMsgId(HistoryItem *row, MsgId newId);
void repaintItem(const HistoryItem *msg);
Window::TopBarWidget::SelectedState getSelectionState() const;
@ -144,6 +143,7 @@ private:
void itemRemoved(HistoryItem *item);
MsgId complexMsgId(const HistoryItem *item) const;
void changingMsgId(HistoryItem *row, MsgId newId);
bool itemMigrated(MsgId msgId) const;
ChannelId itemChannel(MsgId msgId) const;
@ -320,7 +320,6 @@ public:
void doneShow();
void mediaOverviewUpdated(const Notify::PeerUpdate &update);
void changingMsgId(HistoryItem *row, MsgId newId);
void itemRemoved(HistoryItem *item);
QPoint clampMousePosition(QPoint point);

View File

@ -23,6 +23,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include <private/qguiapplication_p.h>
#include "platform/linux/linux_libs.h"
#include "platform/linux/linux_gdk_helper.h"
#include "messenger.h"
#include "mainwindow.h"
#include "storage/localstorage.h"
@ -149,7 +150,7 @@ bool PreviewSupported() {
}
bool GetNative(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, Type type, QString startFile) {
auto parent = App::wnd() ? App::wnd()->filedialogParent() : nullptr;
auto parent = Messenger::Instance().getFileDialogParent();
internal::GtkFileDialog dialog(parent, caption, QString(), filter);
dialog.setModal(true);

View File

@ -24,6 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "storage/localstorage.h"
#include "platform/win/windows_dlls.h"
#include "lang/lang_keys.h"
#include "messenger.h"
#include <Shlwapi.h>
#include <Windowsx.h>
@ -356,7 +357,8 @@ bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption,
// that forced file icon and maybe other properties being resolved and this was
// a blocking operation.
auto helperPath = cDialogHelperPathFinal();
QFileDialog dialog(App::wnd() ? App::wnd()->filedialogParent() : 0, caption, helperPath, filter);
auto parent = Messenger::Instance().getFileDialogParent();
QFileDialog dialog(parent, caption, helperPath, filter);
dialog.setModal(true);
if (type == Type::ReadFile || type == Type::ReadFiles) {

View File

@ -106,7 +106,7 @@ PhotoData *CoverWidget::validatePhoto() const {
void CoverWidget::onPhotoShow() {
if (auto photo = validatePhoto()) {
App::wnd()->showPhoto(photo, _peer);
Messenger::Instance().showPhoto(photo, _peer);
}
}

View File

@ -87,7 +87,7 @@ PhotoData *CoverWidget::validatePhoto() const {
void CoverWidget::onPhotoShow() {
if (auto photo = validatePhoto()) {
App::wnd()->showPhoto(photo, _self);
Messenger::Instance().showPhoto(photo, _self);
}
}

View File

@ -57,9 +57,11 @@ bool minimize_telegram() {
}
bool close_telegram() {
if (!Ui::hideWindowNoQuit()) {
if (auto w = App::wnd()) {
w->close();
if (!Messenger::Instance().hideMediaView()) {
if (!Ui::hideWindowNoQuit()) {
if (auto w = App::wnd()) {
w->close();
}
}
}
return true;
@ -251,7 +253,7 @@ QKeySequence setShortcut(const QString &keys, const QString &command) {
if (it == DataPtr->commands.cend()) {
LOG(("Warning: could not find shortcut command handler '%1'").arg(command));
} else {
auto shortcut = std::make_unique<QShortcut>(seq, App::wnd(), nullptr, nullptr, Qt::ApplicationShortcut);
auto shortcut = std::make_unique<QShortcut>(seq, Messenger::Instance().getGlobalShortcutParent(), nullptr, nullptr, Qt::ApplicationShortcut);
if (!DataPtr->autoRepeatCommands.contains(command)) {
shortcut->setAutoRepeat(false);
}

View File

@ -1234,7 +1234,7 @@ ImagePtr PhotoData::makeReplyPreview() {
}
void PhotoOpenClickHandler::onClickImpl() const {
App::wnd()->showPhoto(this, App::hoveredLinkItem() ? App::hoveredLinkItem() : App::contextItem());
Messenger::Instance().showPhoto(this, App::hoveredLinkItem() ? App::hoveredLinkItem() : App::contextItem());
}
void PhotoSaveClickHandler::onClickImpl() const {
@ -1440,7 +1440,7 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, HistoryItem *context,
auto &location = data->location(true);
if (auto applyTheme = data->isTheme()) {
if (!location.isEmpty() && location.accessEnable()) {
App::wnd()->showDocument(data, context);
Messenger::Instance().showDocument(data, context);
location.accessDisable();
return;
}
@ -1478,9 +1478,9 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, HistoryItem *context,
}
} else if (playVideo) {
if (!data->data().isEmpty()) {
App::wnd()->showDocument(data, context);
Messenger::Instance().showDocument(data, context);
} else if (location.accessEnable()) {
App::wnd()->showDocument(data, context);
Messenger::Instance().showDocument(data, context);
location.accessDisable();
} else {
auto filepath = location.name();
@ -1500,14 +1500,14 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, HistoryItem *context,
if (action == ActionOnLoadPlayInline && context && context->getMedia()) {
context->getMedia()->playInline();
} else {
App::wnd()->showDocument(data, context);
Messenger::Instance().showDocument(data, context);
}
} else if (location.accessEnable()) {
if (data->isAnimation() || QImageReader(location.name()).canRead()) {
if (action == ActionOnLoadPlayInline && context && context->getMedia()) {
context->getMedia()->playInline();
} else {
App::wnd()->showDocument(data, context);
Messenger::Instance().showDocument(data, context);
}
} else {
File::Launch(location.name());
@ -1748,7 +1748,7 @@ void DocumentData::performActionOnLoad() {
auto playAnimation = isAnimation() && (_actionOnLoad == ActionOnLoadPlayInline || _actionOnLoad == ActionOnLoadOpen) && showImage && item && item->getMedia();
if (auto applyTheme = isTheme()) {
if (!loc.isEmpty() && loc.accessEnable()) {
App::wnd()->showDocument(this, item);
Messenger::Instance().showDocument(this, item);
loc.accessDisable();
return;
}
@ -1788,7 +1788,7 @@ void DocumentData::performActionOnLoad() {
if (_actionOnLoad == ActionOnLoadPlayInline && item->getMedia()) {
item->getMedia()->playInline();
} else {
App::wnd()->showDocument(this, item);
Messenger::Instance().showDocument(this, item);
}
}
} else {
@ -1807,7 +1807,7 @@ void DocumentData::performActionOnLoad() {
if (_actionOnLoad == ActionOnLoadPlayInline && item && item->getMedia()) {
item->getMedia()->playInline();
} else {
App::wnd()->showDocument(this, item);
Messenger::Instance().showDocument(this, item);
}
} else {
File::Launch(already);

View File

@ -478,11 +478,9 @@ PopupMenu::~PopupMenu() {
for (auto submenu : base::take(_submenus)) {
delete submenu;
}
#if defined Q_OS_LINUX32 || defined Q_OS_LINUX64
if (auto w = App::wnd()) {
w->reActivateWindow();
}
#endif
if (_destroyedCallback) {
_destroyedCallback();
}

View File

@ -80,10 +80,6 @@ MainWindow::MainWindow() : QWidget()
}
bool MainWindow::hideNoQuit() {
if (_mediaView && !_mediaView->isHidden()) {
hideMediaview();
return true;
}
if (Global::WorkMode().value() == dbiwmTrayOnly || Global::WorkMode().value() == dbiwmWindowAndTray) {
if (minimizeToTray()) {
Ui::showChatsList();
@ -101,48 +97,10 @@ bool MainWindow::hideNoQuit() {
void MainWindow::clearWidgets() {
Ui::hideLayer(true);
if (_mediaView) {
hideMediaview();
_mediaView->rpcClear();
_mediaView->clearData();
}
clearWidgetsHook();
updateGlobalMenu();
}
void MainWindow::showPhoto(const PhotoOpenClickHandler *lnk, HistoryItem *item) {
return (!item && lnk->peer()) ? showPhoto(lnk->photo(), lnk->peer()) : showPhoto(lnk->photo(), item);
}
void MainWindow::showPhoto(PhotoData *photo, HistoryItem *item) {
if (_mediaView->isHidden()) Ui::hideLayer(true);
_mediaView->showPhoto(photo, item);
_mediaView->activateWindow();
_mediaView->setFocus();
}
void MainWindow::showPhoto(PhotoData *photo, PeerData *peer) {
if (_mediaView->isHidden()) Ui::hideLayer(true);
_mediaView->showPhoto(photo, peer);
_mediaView->activateWindow();
_mediaView->setFocus();
}
void MainWindow::showDocument(DocumentData *doc, HistoryItem *item) {
if (cUseExternalVideoPlayer() && doc->isVideo()) {
QDesktopServices::openUrl(QUrl("file:///" + doc->location(false).fname));
} else {
if (_mediaView->isHidden()) Ui::hideLayer(true);
_mediaView->showDocument(doc, item);
_mediaView->activateWindow();
_mediaView->setFocus();
}
}
bool MainWindow::ui_isMediaViewShown() {
return _mediaView && !_mediaView->isHidden();
}
void MainWindow::updateIsActive(int timeout) {
if (timeout > 0) {
return _isActiveTimer.callOnce(timeout);
@ -155,15 +113,6 @@ bool MainWindow::computeIsActive() const {
return isActiveWindow() && isVisible() && !(windowState() & Qt::WindowMinimized);
}
void MainWindow::hideMediaview() {
if (_mediaView && !_mediaView->isHidden()) {
_mediaView->hide();
#if defined Q_OS_LINUX32 || defined Q_OS_LINUX64
reActivateWindow();
#endif
}
}
void MainWindow::onReActivate() {
if (auto w = App::wnd()) {
if (auto f = QApplication::focusWidget()) {
@ -178,14 +127,6 @@ void MainWindow::onReActivate() {
}
}
QWidget *MainWindow::filedialogParent() {
return (_mediaView && _mediaView->isVisible()) ? (QWidget*)_mediaView : (QWidget*)this;
}
void MainWindow::createMediaView() {
_mediaView.create(nullptr);
}
void MainWindow::updateWindowIcon() {
setWindowIcon(_icon);
}
@ -221,9 +162,8 @@ void MainWindow::handleStateChanged(Qt::WindowState state) {
}
void MainWindow::handleActiveChanged() {
if (isActiveWindow() && _mediaView && !_mediaView->isHidden()) {
_mediaView->activateWindow();
_mediaView->setFocus();
if (isActiveWindow()) {
Messenger::Instance().checkMediaViewActivation();
}
App::CallDelayed(1, this, [this] {
updateTrayMenu();
@ -438,23 +378,6 @@ void MainWindow::tryToExtendWidthBy(int addToWidth) {
}
}
void MainWindow::documentUpdated(DocumentData *doc) {
if (!_mediaView || _mediaView->isHidden()) return;
_mediaView->documentUpdated(doc);
}
void MainWindow::changingMsgId(HistoryItem *row, MsgId newId) {
if (!_mediaView || _mediaView->isHidden()) return;
_mediaView->changingMsgId(row, newId);
}
PeerData *MainWindow::ui_getPeerForMouseAction() {
if (_mediaView && !_mediaView->isHidden()) {
return _mediaView->ui_getPeerForMouseAction();
}
return nullptr;
}
void MainWindow::launchDrag(std::unique_ptr<QMimeData> data) {
auto weak = QPointer<MainWindow>(this);
auto drag = std::make_unique<QDrag>(App::wnd());

View File

@ -49,7 +49,6 @@ public:
}
bool hideNoQuit();
void hideMediaview();
void init();
HitTestResult hitTest(const QPoint &p) const;
@ -70,18 +69,12 @@ public:
}
void reActivateWindow() {
#if defined Q_OS_LINUX32 || defined Q_OS_LINUX64
onReActivate();
QTimer::singleShot(200, this, SLOT(onReActivate()));
#endif // Q_OS_LINUX32 || Q_OS_LINUX64
}
void showPhoto(const PhotoOpenClickHandler *lnk, HistoryItem *item = 0);
void showPhoto(PhotoData *photo, HistoryItem *item);
void showPhoto(PhotoData *photo, PeerData *item);
void showDocument(DocumentData *doc, HistoryItem *item);
bool ui_isMediaViewShown();
QWidget *filedialogParent();
void showRightColumn(object_ptr<TWidget> widget);
bool canExtendWidthBy(int addToWidth);
void tryToExtendWidthBy(int addToWidth);
@ -89,16 +82,11 @@ public:
virtual void updateTrayMenu(bool force = false) {
}
// TODO: rewrite using base::Observable
void documentUpdated(DocumentData *doc);
virtual void changingMsgId(HistoryItem *row, MsgId newId);
virtual ~MainWindow();
TWidget *bodyWidget() {
return _body.data();
}
virtual PeerData *ui_getPeerForMouseAction();
void launchDrag(std::unique_ptr<QMimeData> data);
base::Observable<void> &dragFinished() {
@ -165,8 +153,6 @@ protected:
void setPositionInited();
void createMediaView();
private slots:
void savePositionByTimer() {
savePosition();
@ -197,8 +183,6 @@ private:
bool _wasInactivePress = false;
base::Timer _inactivePressTimer;
object_ptr<MediaView> _mediaView = { nullptr };
base::Observable<void> _dragFinished;
base::Observable<void> _widgetGrabbed;

View File

@ -384,9 +384,7 @@ void Manager::notificationActivated(PeerId peerId, MsgId msgId) {
if (auto window = App::wnd()) {
auto history = App::history(peerId);
window->showFromTray();
#if defined Q_OS_LINUX32 || defined Q_OS_LINUX64
window->reActivateWindow();
#endif
if (App::passcoded()) {
window->setInnerFocus();
system()->clearAll();