Skip to content

Commit

Permalink
Moved History[Media] classes to history_media_types module.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Sep 28, 2016
1 parent d277b0d commit 538ffb9
Show file tree
Hide file tree
Showing 33 changed files with 1,699 additions and 1,335 deletions.
Binary file modified Telegram/Resources/art/sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Telegram/Resources/art/sprite_200x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions Telegram/Resources/basic.style
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ introErrLabelTextStyle: textStyle(defaultTextStyle) {

mediaPadding: margins(0px, 0px, 0px, 0px);//1px, 1px, 1px, 1px);//2px, 2px, 2px, 2px);
mediaCaptionSkip: 5px;
mediaHeaderSkip: 5px;
mediaInBubbleSkip: 5px;
mediaThumbSize: 48px;
mediaNameTop: 3px;
mediaDetailsShift: 3px;
Expand Down Expand Up @@ -2285,7 +2285,6 @@ webPageLeft: 10px;
webPageBar: 2px;
webPageTitleFont: semiboldFont;
webPageDescriptionFont: normalFont;
webPagePhotoSkip: 5px;
webPagePhotoSize: 100px;
webPagePhotoDelta: 8px;

Expand Down
13 changes: 6 additions & 7 deletions Telegram/SourceFiles/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "data/data_abstract_structure.h"
#include "history/history_service_layout.h"
#include "history/history_location_manager.h"
#include "history/history_media_types.h"
#include "media/media_audio.h"
#include "inline_bots/inline_bot_layout_item.h"
#include "application.h"
Expand Down Expand Up @@ -1523,7 +1524,7 @@ namespace {
}

GameData *feedGame(const MTPDgame &game, GameData *convert) {
return App::gameSet(game.vid.v, convert, game.vaccess_hash.v, qs(game.vshort_name), qs(game.vtitle), qs(game.vdescription), qs(game.vurl), App::feedPhoto(game.vphoto), game.has_document() ? App::feedDocument(game.vdocument) : nullptr);
return App::gameSet(game.vid.v, convert, game.vaccess_hash.v, qs(game.vshort_name), qs(game.vtitle), qs(game.vdescription), App::feedPhoto(game.vphoto), game.has_document() ? App::feedDocument(game.vdocument) : nullptr);
}

UserData *curUser() {
Expand Down Expand Up @@ -1847,7 +1848,7 @@ namespace {
return i.value();
}

GameData *gameSet(const GameId &game, GameData *convert, const uint64 &accessHash, const QString &shortName, const QString &title, const QString &description, const QString &url, PhotoData *photo, DocumentData *document) {
GameData *gameSet(const GameId &game, GameData *convert, const uint64 &accessHash, const QString &shortName, const QString &title, const QString &description, PhotoData *photo, DocumentData *document) {
if (convert) {
if (convert->id != game) {
auto i = gamesData.find(convert->id);
Expand All @@ -1856,12 +1857,11 @@ namespace {
}
convert->id = game;
}
if (convert->url.isEmpty() && !url.isEmpty()) {
if (convert->shortName.isEmpty() && !shortName.isEmpty()) {
convert->accessHash = accessHash;
convert->shortName = shortName;
convert->title = title;
convert->description = description;
convert->url = url;
convert->photo = photo;
convert->document = document;
if (App::main()) App::main()->gameUpdated(convert);
Expand All @@ -1873,18 +1873,17 @@ namespace {
if (convert) {
result = convert;
} else {
result = new GameData(game, accessHash, shortName, title, description, url, photo, document);
result = new GameData(game, accessHash, shortName, title, description, photo, document);
}
gamesData.insert(game, result);
} else {
result = i.value();
if (result != convert) {
if (result->url.isEmpty() && !url.isEmpty()) {
if (result->shortName.isEmpty() && !shortName.isEmpty()) {
result->accessHash = accessHash;
result->shortName = shortName;
result->title = title;
result->description = description;
result->url = url;
result->photo = photo;
result->document = document;
if (App::main()) App::main()->gameUpdated(result);
Expand Down
5 changes: 4 additions & 1 deletion Telegram/SourceFiles/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ using GifItems = QHash<Media::Clip::Reader*, HistoryItem*>;
using PhotosData = QHash<PhotoId, PhotoData*>;
using DocumentsData = QHash<DocumentId, DocumentData*>;

struct LocationCoords;
struct LocationData;

namespace App {
AppClass *app();
MainWindow *wnd();
Expand Down Expand Up @@ -154,7 +157,7 @@ namespace App {
WebPageData *webPage(const WebPageId &webPage);
WebPageData *webPageSet(const WebPageId &webPage, WebPageData *convert, const QString &type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *doc, int32 duration, const QString &author, int32 pendingTill);
GameData *game(const GameId &game);
GameData *gameSet(const GameId &game, GameData *convert, const uint64 &accessHash, const QString &shortName, const QString &title, const QString &description, const QString &url, PhotoData *photo, DocumentData *doc);
GameData *gameSet(const GameId &game, GameData *convert, const uint64 &accessHash, const QString &shortName, const QString &title, const QString &description, PhotoData *photo, DocumentData *doc);
LocationData *location(const LocationCoords &coords);
void forgetMedia();

Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/boxes/photosendbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "localstorage.h"
#include "mainwidget.h"
#include "photosendbox.h"
#include "history/history_media_types.h"

PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxWideWidth)
, _file(file)
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "stdafx.h"
#include "history.h"

#include "history/history_media_types.h"
#include "dialogs/dialogs_indexed_list.h"
#include "styles/style_dialogs.h"
#include "data/data_drafts.h"
Expand Down
108 changes: 44 additions & 64 deletions Telegram/SourceFiles/history/history_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,84 +28,64 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "styles/style_dialogs.h"
#include "fileuploader.h"

class ReplyMarkupClickHandler : public LeftButtonClickHandler {
public:
ReplyMarkupClickHandler(const HistoryItem *item, int row, int col) : _itemId(item->fullId()), _row(row), _col(col) {
}

QString tooltip() const override {
return _fullDisplayed ? QString() : buttonText();
}

void setFullDisplayed(bool full) {
_fullDisplayed = full;
}

// Copy to clipboard support.
void copyToClipboard() const override {
if (auto button = getButton()) {
if (button->type == HistoryMessageReplyMarkup::Button::Type::Url) {
auto url = QString::fromUtf8(button->data);
if (!url.isEmpty()) {
QApplication::clipboard()->setText(url);
}
ReplyMarkupClickHandler::ReplyMarkupClickHandler(const HistoryItem *item, int row, int col)
: _itemId(item->fullId())
, _row(row)
, _col(col) {
}

// Copy to clipboard support.
void ReplyMarkupClickHandler::copyToClipboard() const {
if (auto button = getButton()) {
if (button->type == HistoryMessageReplyMarkup::Button::Type::Url) {
auto url = QString::fromUtf8(button->data);
if (!url.isEmpty()) {
QApplication::clipboard()->setText(url);
}
}
}
QString copyToClipboardContextItemText() const override {
if (auto button = getButton()) {
if (button->type == HistoryMessageReplyMarkup::Button::Type::Url) {
return lang(lng_context_copy_link);
}
}

QString ReplyMarkupClickHandler::copyToClipboardContextItemText() const {
if (auto button = getButton()) {
if (button->type == HistoryMessageReplyMarkup::Button::Type::Url) {
return lang(lng_context_copy_link);
}
return QString();
}
return QString();
}

// Finds the corresponding button in the items markup struct.
// If the button is not found it returns nullptr.
// Note: it is possible that we will point to the different button
// than the one was used when constructing the handler, but not a big deal.
const HistoryMessageReplyMarkup::Button *getButton() const {
if (auto item = App::histItemById(_itemId)) {
if (auto markup = item->Get<HistoryMessageReplyMarkup>()) {
if (_row < markup->rows.size()) {
auto &row = markup->rows.at(_row);
if (_col < row.size()) {
return &row.at(_col);
}
// Finds the corresponding button in the items markup struct.
// If the button is not found it returns nullptr.
// Note: it is possible that we will point to the different button
// than the one was used when constructing the handler, but not a big deal.
const HistoryMessageReplyMarkup::Button *ReplyMarkupClickHandler::getButton() const {
if (auto item = App::histItemById(_itemId)) {
if (auto markup = item->Get<HistoryMessageReplyMarkup>()) {
if (_row < markup->rows.size()) {
auto &row = markup->rows.at(_row);
if (_col < row.size()) {
return &row.at(_col);
}
}
}
return nullptr;
}

// We hold only FullMsgId, not HistoryItem*, because all click handlers
// are activated async and the item may be already destroyed.
void setMessageId(const FullMsgId &msgId) {
_itemId = msgId;
}
return nullptr;
}

protected:
void onClickImpl() const override {
if (auto item = App::histItemById(_itemId)) {
App::activateBotCommand(item, _row, _col);
}
void ReplyMarkupClickHandler::onClickImpl() const {
if (auto item = App::histItemById(_itemId)) {
App::activateBotCommand(item, _row, _col);
}
}

private:
FullMsgId _itemId;
int _row, _col;
bool _fullDisplayed = true;

// Returns the full text of the corresponding button.
QString buttonText() const {
if (auto button = getButton()) {
return button->text;
}
return QString();
// Returns the full text of the corresponding button.
QString ReplyMarkupClickHandler::buttonText() const {
if (auto button = getButton()) {
return button->text;
}

};
return QString();
}

ReplyKeyboard::ReplyKeyboard(const HistoryItem *item, StylePtr &&s)
: _item(item)
Expand Down
42 changes: 41 additions & 1 deletion Telegram/SourceFiles/history/history_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,47 @@ struct HistoryMessageReplyMarkup : public BaseComponent<HistoryMessageReplyMarku

};

class ReplyMarkupClickHandler;
class ReplyMarkupClickHandler : public LeftButtonClickHandler {
public:
ReplyMarkupClickHandler(const HistoryItem *item, int row, int col);

QString tooltip() const override {
return _fullDisplayed ? QString() : buttonText();
}

void setFullDisplayed(bool full) {
_fullDisplayed = full;
}

// Copy to clipboard support.
void copyToClipboard() const override;
QString copyToClipboardContextItemText() const override;

// Finds the corresponding button in the items markup struct.
// If the button is not found it returns nullptr.
// Note: it is possible that we will point to the different button
// than the one was used when constructing the handler, but not a big deal.
const HistoryMessageReplyMarkup::Button *getButton() const;

// We hold only FullMsgId, not HistoryItem*, because all click handlers
// are activated async and the item may be already destroyed.
void setMessageId(const FullMsgId &msgId) {
_itemId = msgId;
}

protected:
void onClickImpl() const override;

private:
FullMsgId _itemId;
int _row, _col;
bool _fullDisplayed = true;

// Returns the full text of the corresponding button.
QString buttonText() const;

};

class ReplyKeyboard {
private:
struct Button;
Expand Down
Loading

0 comments on commit 538ffb9

Please sign in to comment.