Skip to content

Commit

Permalink
Show GIF in Mediaview on click.
Browse files Browse the repository at this point in the history
This way you can watch GIF on full screen and switch between them.
  • Loading branch information
john-preston committed May 24, 2017
1 parent 2377873 commit efb59e8
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/Telegram/Resources/art/grid_200x.png
/Telegram/Resources/art/sprite_125x.png
/Telegram/Resources/art/sprite_150x.png
/Telegram/Debug/
/Telegram/*.user
*.vcxproj*
*.sln
Expand Down
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
"lng_context_delete_file" = "Delete File";
"lng_context_close_file" = "Close File";
"lng_context_copy_text" = "Copy Text";
"lng_context_open_gif" = "Open GIF";
"lng_context_save_gif" = "Save GIF";
"lng_context_to_msg" = "Go To Message";
"lng_context_reply_msg" = "Reply";
Expand Down
16 changes: 0 additions & 16 deletions Telegram/SourceFiles/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,6 @@ enum MediaOverviewType {
OverviewCount
};

inline MTPMessagesFilter typeToMediaFilter(MediaOverviewType &type) {
switch (type) {
case OverviewPhotos: return MTP_inputMessagesFilterPhotos();
case OverviewVideos: return MTP_inputMessagesFilterVideo();
case OverviewMusicFiles: return MTP_inputMessagesFilterMusic();
case OverviewFiles: return MTP_inputMessagesFilterDocument();
case OverviewVoiceFiles: return MTP_inputMessagesFilterVoice();
case OverviewRoundVoiceFiles: return MTP_inputMessagesFilterRoundVoice();
case OverviewLinks: return MTP_inputMessagesFilterUrl();
case OverviewChatPhotos: return MTP_inputMessagesFilterChatPhotos();
case OverviewCount: break;
default: type = OverviewCount; break;
}
return MTPMessagesFilter();
}

struct TextWithTags {
struct Tag {
int offset, length;
Expand Down
16 changes: 16 additions & 0 deletions Telegram/SourceFiles/history/history_inner_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
_menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true);
} else {
if (document->loaded() && document->isGifv()) {
if (!cAutoPlayGif()) {
_menu->addAction(lang(lng_context_open_gif), this, SLOT(openContextGif()))->setEnabled(true);
}
_menu->addAction(lang(lng_context_save_gif), this, SLOT(saveContextGif()))->setEnabled(true);
}
if (!document->filepath(DocumentData::FilePathResolveChecked).isEmpty()) {
Expand Down Expand Up @@ -1384,6 +1387,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
_menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true);
} else {
if (document->isGifv()) {
if (!cAutoPlayGif()) {
_menu->addAction(lang(lng_context_open_gif), this, SLOT(openContextGif()))->setEnabled(true);
}
_menu->addAction(lang(lng_context_save_gif), this, SLOT(saveContextGif()))->setEnabled(true);
}
if (!document->filepath(DocumentData::FilePathResolveChecked).isEmpty()) {
Expand Down Expand Up @@ -1522,6 +1528,16 @@ void HistoryInner::saveDocumentToFile(DocumentData *document) {
DocumentSaveClickHandler::doSave(document, true);
}

void HistoryInner::openContextGif() {
if (auto item = App::contextItem()) {
if (auto media = item->getMedia()) {
if (auto document = media->getDocument()) {
App::wnd()->showDocument(document, item);
}
}
}
}

void HistoryInner::saveContextGif() {
if (auto item = App::contextItem()) {
if (auto media = item->getMedia()) {
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/history/history_inner_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public slots:
void cancelContextDownload();
void showContextInFolder();
void saveContextGif();
void openContextGif();
void copyContextText();
void copySelectedText();

Expand Down
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/history/history_media_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,7 @@ HistoryGif::HistoryGif(HistoryItem *parent, DocumentData *document, const QStrin
, _data(document)
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) {
setDocumentLinks(_data, true);
_openInMediaviewLink = MakeShared<DocumentOpenClickHandler>(_data);

setStatusSize(FileStatusSizeReady);

Expand Down Expand Up @@ -2217,6 +2218,8 @@ HistoryTextState HistoryGif::getState(int x, int y, HistoryStateRequest request)
result.link = _cancell;
} else if (!_gif || !cAutoPlayGif() || _data->isRoundVideo()) {
result.link = _data->loaded() ? _openl : (_data->loading() ? _cancell : _savel);
} else {
result.link = _openInMediaviewLink;
}
if (!isChildMedia) {
int32 fullRight = usex + skipx + usew, fullBottom = skipy + height;
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/history/history_media_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ class HistoryGif : public HistoryFileMedia {
}

gsl::not_null<DocumentData*> _data;
ClickHandlerPtr _openInMediaviewLink;
int32 _thumbw = 1;
int32 _thumbh = 1;
Text _caption;
Expand Down
45 changes: 35 additions & 10 deletions Telegram/SourceFiles/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "calls/calls_instance.h"
#include "calls/calls_top_bar.h"

namespace {

MTPMessagesFilter typeToMediaFilter(MediaOverviewType &type) {
switch (type) {
case OverviewPhotos: return MTP_inputMessagesFilterPhotos();
case OverviewVideos: return MTP_inputMessagesFilterVideo();
case OverviewMusicFiles: return MTP_inputMessagesFilterMusic();
case OverviewFiles: return MTP_inputMessagesFilterDocument();
case OverviewVoiceFiles: return MTP_inputMessagesFilterVoice();
case OverviewRoundVoiceFiles: return MTP_inputMessagesFilterRoundVoice();
case OverviewGIFs: return MTP_inputMessagesFilterGif();
case OverviewLinks: return MTP_inputMessagesFilterUrl();
case OverviewChatPhotos: return MTP_inputMessagesFilterChatPhotos();
default: return MTP_inputMessagesFilterEmpty();
}
}

} // namespace

StackItemSection::StackItemSection(std::unique_ptr<Window::SectionMemento> &&memento) : StackItem(nullptr)
, _memento(std::move(memento)) {
}
Expand Down Expand Up @@ -1335,11 +1354,13 @@ void MainWidget::searchMessages(const QString &query, PeerData *inPeer) {
}

bool MainWidget::preloadOverview(PeerData *peer, MediaOverviewType type) {
MTPMessagesFilter filter = typeToMediaFilter(type);
if (type == OverviewCount) return false;
auto filter = typeToMediaFilter(type);
if (filter.type() == mtpc_inputMessagesFilterEmpty) {
return false;
}

History *h = App::history(peer->id);
if (h->overviewCountLoaded(type) || _overviewPreload[type].contains(peer)) {
auto history = App::history(peer->id);
if (history->overviewCountLoaded(type) || _overviewPreload[type].contains(peer)) {
return false;
}

Expand Down Expand Up @@ -1399,13 +1420,17 @@ bool MainWidget::overviewFailed(PeerData *peer, const RPCError &error, mtpReques
void MainWidget::loadMediaBack(PeerData *peer, MediaOverviewType type, bool many) {
if (_overviewLoad[type].constFind(peer) != _overviewLoad[type].cend()) return;

History *history = App::history(peer->id);
if (history->overviewLoaded(type)) return;
auto history = App::history(peer->id);
if (history->overviewLoaded(type)) {
return;
}

MsgId minId = history->overviewMinId(type);
int32 limit = (many || history->overview[type].size() > MediaOverviewStartPerPage) ? SearchPerPage : MediaOverviewStartPerPage;
MTPMessagesFilter filter = typeToMediaFilter(type);
if (type == OverviewCount) return;
auto minId = history->overviewMinId(type);
auto limit = (many || history->overview[type].size() > MediaOverviewStartPerPage) ? SearchPerPage : MediaOverviewStartPerPage;
auto filter = typeToMediaFilter(type);
if (filter.type() == mtpc_inputMessagesFilterEmpty) {
return;
}

_overviewLoad[type].insert(peer, MTP::send(MTPmessages_Search(MTP_flags(0), peer->input, MTPstring(), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(minId), MTP_int(limit)), rpcDone(&MainWidget::overviewLoaded, history)));
}
Expand Down
6 changes: 3 additions & 3 deletions Telegram/SourceFiles/mediaview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void MediaView::updateControls() {
_dateNav = myrtlrect(st::mediaviewTextLeft, height() - st::mediaviewTextTop, st::mediaviewFont->width(_dateText), st::mediaviewFont->height);
}
updateHeader();
if (_photo || (_history && (_overview == OverviewPhotos || _overview == OverviewChatPhotos || _overview == OverviewFiles || _overview == OverviewVideos))) {
if (_photo || (_history && _overview != OverviewCount)) {
_leftNavVisible = (_index > 0) || (_index == 0 && (
(!_msgmigrated && _history && _history->overview[_overview].size() < _history->overviewCount(_overview)) ||
(_msgmigrated && _migrated && _migrated->overview[_overview].size() < _migrated->overviewCount(_overview)) ||
Expand Down Expand Up @@ -1152,7 +1152,7 @@ void MediaView::showDocument(DocumentData *doc, HistoryItem *context) {
_canForward = _msgid > 0;
_canDelete = context ? context->canDelete() : false;
if (_history) {
_overview = doc->isVideo() ? OverviewVideos : OverviewFiles;
_overview = doc->isGifv() ? OverviewGIFs : doc->isVideo() ? OverviewVideos : OverviewFiles;
findCurrent();
}
if (doc->isVideo() || doc->isRoundVideo()) {
Expand Down Expand Up @@ -2153,7 +2153,7 @@ bool MediaView::moveToNext(int32 delta) {
}
return false;
}
if ((_history && _overview != OverviewPhotos && _overview != OverviewChatPhotos && _overview != OverviewFiles && _overview != OverviewVideos) || (_overview == OverviewCount && !_user)) {
if (_overview == OverviewCount && (_history || !_user)) {
return false;
}
if (_msgmigrated && !_history->overviewLoaded(_overview)) {
Expand Down

0 comments on commit efb59e8

Please sign in to comment.