1 /* 2 This file is part of Telegram Desktop, 3 the official desktop application for the Telegram messaging service. 4 5 For license and copyright information please follow this link: 6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL 7 */ 8 #pragma once 9 10 #include "history/view/media/history_view_media.h" 11 #include "ui/effects/animations.h" 12 #include "ui/effects/radial_animation.h" 13 14 class FileClickHandler; 15 16 namespace HistoryView { 17 18 class File : public Media, public base::has_weak_ptr { 19 public: File(not_null<Element * > parent,not_null<HistoryItem * > realParent)20 File( 21 not_null<Element*> parent, 22 not_null<HistoryItem*> realParent) 23 : Media(parent) 24 , _realParent(realParent) { 25 } 26 27 [[nodiscard]] bool toggleSelectionByHandlerClick( 28 const ClickHandlerPtr &p) const override; 29 [[nodiscard]] bool dragItemByHandler( 30 const ClickHandlerPtr &p) const override; 31 32 void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; 33 void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; 34 35 void refreshParentId(not_null<HistoryItem*> realParent) override; 36 allowsFastShare()37 [[nodiscard]] bool allowsFastShare() const override { 38 return true; 39 } 40 41 ~File(); 42 43 protected: 44 using FileClickHandlerPtr = std::shared_ptr<FileClickHandler>; 45 46 not_null<HistoryItem*> _realParent; 47 FileClickHandlerPtr _openl, _savel, _cancell; 48 49 void setLinks( 50 FileClickHandlerPtr &&openl, 51 FileClickHandlerPtr &&savel, 52 FileClickHandlerPtr &&cancell); 53 void setDocumentLinks( 54 not_null<DocumentData*> document, 55 not_null<HistoryItem*> realParent); 56 57 // >= 0 will contain download / upload string, _statusSize = loaded bytes 58 // < 0 will contain played string, _statusSize = -(seconds + 1) played 59 // 0x7FFFFFF0 will contain status for not yet downloaded file 60 // 0x7FFFFFF1 will contain status for already downloaded file 61 // 0x7FFFFFF2 will contain status for failed to download / upload file 62 mutable int _statusSize; 63 mutable QString _statusText; 64 65 // duration = -1 - no duration, duration = -2 - "GIF" duration 66 void setStatusSize(int newSize, int fullSize, int duration, qint64 realDuration) const; 67 68 void radialAnimationCallback(crl::time now) const; 69 void thumbAnimationCallback(); 70 71 void ensureAnimation() const; 72 void checkAnimationFinished() const; 73 isRadialAnimation()74 bool isRadialAnimation() const { 75 if (_animation) { 76 if (_animation->radial.animating()) { 77 return true; 78 } 79 checkAnimationFinished(); 80 } 81 return false; 82 } isThumbAnimation()83 bool isThumbAnimation() const { 84 if (_animation) { 85 if (_animation->a_thumbOver.animating()) { 86 return true; 87 } 88 checkAnimationFinished(); 89 } 90 return false; 91 } 92 93 virtual float64 dataProgress() const = 0; 94 virtual bool dataFinished() const = 0; 95 virtual bool dataLoaded() const = 0; 96 97 struct AnimationData { 98 template <typename Callback> AnimationDataAnimationData99 AnimationData(Callback &&radialCallback) 100 : radial(std::forward<Callback>(radialCallback)) { 101 } 102 103 Ui::Animations::Simple a_thumbOver; 104 Ui::RadialAnimation radial; 105 }; 106 mutable std::unique_ptr<AnimationData> _animation; 107 108 }; 109 110 } // namespace HistoryView 111