2014-05-30 12:53:19 +04:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 13:47:38 +03:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 16:16:42 +03:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 12:53:19 +04:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2015-10-03 16:16:42 +03:00
|
|
|
Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
|
2014-05-30 12:53:19 +04:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
class Application;
|
|
|
|
class Window;
|
|
|
|
class MainWidget;
|
2014-08-01 15:09:46 +04:00
|
|
|
class SettingsWidget;
|
2015-03-19 12:18:19 +03:00
|
|
|
class ApiWrap;
|
2014-05-30 12:53:19 +04:00
|
|
|
class Font;
|
|
|
|
class Color;
|
|
|
|
class FileUploader;
|
|
|
|
|
|
|
|
#include "history.h"
|
2015-12-20 17:05:07 +03:00
|
|
|
#include "layout.h"
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2015-12-13 01:29:33 +03:00
|
|
|
typedef QMap<HistoryItem*, NullType> HistoryItemsMap;
|
|
|
|
typedef QMap<VideoData*, HistoryItemsMap> VideoItems;
|
|
|
|
typedef QMap<AudioData*, HistoryItemsMap> AudioItems;
|
|
|
|
typedef QMap<DocumentData*, HistoryItemsMap> DocumentItems;
|
|
|
|
typedef QMap<WebPageData*, HistoryItemsMap> WebPageItems;
|
|
|
|
typedef QMap<int32, HistoryItemsMap> SharedContactItems;
|
2015-12-15 17:50:51 +03:00
|
|
|
typedef QMap<ClipReader*, HistoryItem*> GifItems;
|
2015-06-17 22:43:03 +03:00
|
|
|
struct ReplyMarkup {
|
|
|
|
ReplyMarkup(int32 flags = 0) : flags(flags) {
|
|
|
|
}
|
|
|
|
typedef QList<QList<QString> > Commands;
|
|
|
|
Commands commands;
|
|
|
|
int32 flags;
|
|
|
|
};
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2015-11-13 18:14:33 +03:00
|
|
|
class LayeredWidget;
|
|
|
|
|
2014-05-30 12:53:19 +04:00
|
|
|
namespace App {
|
|
|
|
Application *app();
|
|
|
|
Window *wnd();
|
|
|
|
MainWidget *main();
|
2014-08-01 15:09:46 +04:00
|
|
|
SettingsWidget *settings();
|
2015-03-02 15:34:16 +03:00
|
|
|
bool passcoded();
|
2014-05-30 12:53:19 +04:00
|
|
|
FileUploader *uploader();
|
2015-03-19 12:18:19 +03:00
|
|
|
ApiWrap *api();
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
void logOut();
|
|
|
|
bool loggedOut();
|
|
|
|
|
|
|
|
QString formatPhone(QString phone);
|
|
|
|
|
2015-06-10 15:48:26 +03:00
|
|
|
int32 onlineForSort(UserData *user, int32 now);
|
|
|
|
int32 onlineWillChangeIn(UserData *user, int32 nowOnServer);
|
2014-11-22 12:45:04 +03:00
|
|
|
QString onlineText(UserData *user, int32 nowOnServer, bool precise = false);
|
2015-06-24 20:24:48 +03:00
|
|
|
bool onlineColorUse(UserData *user, int32 now);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2015-06-30 01:09:23 +03:00
|
|
|
UserData *feedUsers(const MTPVector<MTPUser> &users, bool emitPeerUpdated = true); // returns last user
|
2015-09-03 13:48:40 +03:00
|
|
|
PeerData *feedChats(const MTPVector<MTPChat> &chats, bool emitPeerUpdated = true); // returns last chat
|
2015-06-30 01:09:23 +03:00
|
|
|
void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos, bool emitPeerUpdated = true);
|
|
|
|
void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d, bool emitPeerUpdated = true);
|
|
|
|
void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d, bool emitPeerUpdated = true);
|
2015-10-29 15:10:49 -04:00
|
|
|
void feedChatAdmins(const MTPDupdateChatAdmins &d, bool emitPeerUpdated = true);
|
|
|
|
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d, bool emitPeerUpdated = true);
|
2015-10-15 02:15:28 +02:00
|
|
|
bool checkEntitiesAndViewsUpdate(const MTPDmessage &m); // returns true if item found and it is not detached
|
2015-11-18 17:59:17 +03:00
|
|
|
void feedMsgs(const QVector<MTPMessage> &msgs, NewMessageType type);
|
2015-09-20 11:55:41 +03:00
|
|
|
void feedMsgs(const MTPVector<MTPMessage> &msgs, NewMessageType type);
|
2015-09-03 13:48:40 +03:00
|
|
|
void feedInboxRead(const PeerId &peer, MsgId upTo);
|
|
|
|
void feedOutboxRead(const PeerId &peer, MsgId upTo);
|
|
|
|
void feedWereDeleted(ChannelId channelId, const QVector<MTPint> &msgsIds);
|
2015-06-30 01:09:23 +03:00
|
|
|
void feedUserLinks(const MTPVector<MTPcontacts_Link> &links, bool emitPeerUpdated = true);
|
|
|
|
void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink, bool emitPeerUpdated = true);
|
|
|
|
|
|
|
|
void markPeerUpdated(PeerData *data);
|
|
|
|
void clearPeerUpdated(PeerData *data);
|
|
|
|
void emitPeerUpdated();
|
|
|
|
|
2015-02-03 18:02:46 +03:00
|
|
|
ImagePtr image(const MTPPhotoSize &size);
|
2015-08-07 15:11:50 +03:00
|
|
|
StorageImageLocation imageLocation(int32 w, int32 h, const MTPFileLocation &loc);
|
2015-05-19 18:46:45 +03:00
|
|
|
StorageImageLocation imageLocation(const MTPPhotoSize &size);
|
2015-02-03 18:02:46 +03:00
|
|
|
|
2014-05-30 12:53:19 +04:00
|
|
|
PhotoData *feedPhoto(const MTPPhoto &photo, const PreparedPhotoThumbs &thumbs);
|
|
|
|
PhotoData *feedPhoto(const MTPPhoto &photo, PhotoData *convert = 0);
|
|
|
|
PhotoData *feedPhoto(const MTPDphoto &photo, PhotoData *convert = 0);
|
|
|
|
VideoData *feedVideo(const MTPDvideo &video, VideoData *convert = 0);
|
2015-05-29 21:52:43 +03:00
|
|
|
AudioData *feedAudio(const MTPaudio &audio, AudioData *convert = 0);
|
2014-05-30 12:53:19 +04:00
|
|
|
AudioData *feedAudio(const MTPDaudio &audio, AudioData *convert = 0);
|
2015-01-02 17:55:24 +03:00
|
|
|
DocumentData *feedDocument(const MTPdocument &document, const QPixmap &thumb);
|
|
|
|
DocumentData *feedDocument(const MTPdocument &document, DocumentData *convert = 0);
|
|
|
|
DocumentData *feedDocument(const MTPDdocument &document, DocumentData *convert = 0);
|
2015-04-04 23:01:34 +03:00
|
|
|
WebPageData *feedWebPage(const MTPDwebPage &webpage, WebPageData *convert = 0);
|
|
|
|
WebPageData *feedWebPage(const MTPDwebPagePending &webpage, WebPageData *convert = 0);
|
|
|
|
WebPageData *feedWebPage(const MTPWebPage &webpage);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2015-09-03 13:48:40 +03:00
|
|
|
PeerData *peerLoaded(const PeerId &id);
|
|
|
|
UserData *userLoaded(const PeerId &id);
|
|
|
|
ChatData *chatLoaded(const PeerId &id);
|
|
|
|
ChannelData *channelLoaded(const PeerId &id);
|
2014-05-30 12:53:19 +04:00
|
|
|
UserData *userLoaded(int32 user);
|
|
|
|
ChatData *chatLoaded(int32 chat);
|
2015-09-03 13:48:40 +03:00
|
|
|
ChannelData *channelLoaded(int32 channel);
|
|
|
|
|
|
|
|
PeerData *peer(const PeerId &id);
|
|
|
|
UserData *user(const PeerId &id);
|
|
|
|
ChatData *chat(const PeerId &id);
|
|
|
|
ChannelData *channel(const PeerId &id);
|
|
|
|
UserData *user(int32 user_id);
|
|
|
|
ChatData *chat(int32 chat_id);
|
|
|
|
ChannelData *channel(int32 channel_id);
|
2014-05-30 12:53:19 +04:00
|
|
|
UserData *self();
|
2015-09-06 13:17:09 +03:00
|
|
|
PeerData *peerByName(const QString &username);
|
2014-05-30 12:53:19 +04:00
|
|
|
QString peerName(const PeerData *peer, bool forDialogs = false);
|
2015-07-21 16:55:23 +02:00
|
|
|
PhotoData *photo(const PhotoId &photo);
|
2015-08-12 21:01:32 +03:00
|
|
|
PhotoData *photoSet(const PhotoId &photo, PhotoData *convert, const uint64 &access, int32 date, const ImagePtr &thumb, const ImagePtr &medium, const ImagePtr &full);
|
2015-07-21 16:55:23 +02:00
|
|
|
VideoData *video(const VideoId &video);
|
2015-08-12 21:01:32 +03:00
|
|
|
VideoData *videoSet(const VideoId &video, VideoData *convert, const uint64 &access, int32 date, int32 duration, int32 w, int32 h, const ImagePtr &thumb, int32 dc, int32 size);
|
2015-07-21 16:55:23 +02:00
|
|
|
AudioData *audio(const AudioId &audio);
|
2015-08-12 21:01:32 +03:00
|
|
|
AudioData *audioSet(const AudioId &audio, AudioData *convert, const uint64 &access, int32 date, const QString &mime, int32 duration, int32 dc, int32 size);
|
2015-05-19 18:46:45 +03:00
|
|
|
DocumentData *document(const DocumentId &document);
|
|
|
|
DocumentData *documentSet(const DocumentId &document, DocumentData *convert, const uint64 &access, int32 date, const QVector<MTPDocumentAttribute> &attributes, const QString &mime, const ImagePtr &thumb, int32 dc, int32 size, const StorageImageLocation &thumbLocation);
|
2015-07-21 16:55:23 +02:00
|
|
|
WebPageData *webPage(const WebPageId &webPage);
|
2015-08-30 17:57:21 +03:00
|
|
|
WebPageData *webPageSet(const WebPageId &webPage, WebPageData *convert, const QString &, 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);
|
2015-07-21 16:55:23 +02:00
|
|
|
ImageLinkData *imageLink(const QString &imageLink);
|
|
|
|
ImageLinkData *imageLinkSet(const QString &imageLink, ImageLinkType type, const QString &url);
|
2014-11-12 23:18:00 +03:00
|
|
|
void forgetMedia();
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
MTPPhoto photoFromUserPhoto(MTPint userId, MTPint date, const MTPUserProfilePhoto &photo);
|
|
|
|
|
|
|
|
Histories &histories();
|
2015-09-07 10:52:37 +03:00
|
|
|
History *history(const PeerId &peer);
|
|
|
|
History *historyFromDialog(const PeerId &peer, int32 unreadCnt, int32 maxInboxRead);
|
2014-05-30 12:53:19 +04:00
|
|
|
History *historyLoaded(const PeerId &peer);
|
2015-09-03 13:48:40 +03:00
|
|
|
HistoryItem *histItemById(ChannelId channelId, MsgId itemId);
|
|
|
|
inline HistoryItem *histItemById(const FullMsgId &msgId) {
|
|
|
|
return histItemById(msgId.channel, msgId.msg);
|
|
|
|
}
|
2015-12-23 15:55:32 +03:00
|
|
|
void historyRegItem(HistoryItem *item);
|
2014-07-04 15:12:54 +04:00
|
|
|
void historyItemDetached(HistoryItem *item);
|
2014-05-30 12:53:19 +04:00
|
|
|
void historyUnregItem(HistoryItem *item);
|
|
|
|
void historyClearMsgs();
|
|
|
|
void historyClearItems();
|
2015-03-19 12:18:19 +03:00
|
|
|
void historyRegReply(HistoryReply *reply, HistoryItem *to);
|
|
|
|
void historyUnregReply(HistoryReply *reply, HistoryItem *to);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2015-09-03 13:48:40 +03:00
|
|
|
void historyRegRandom(uint64 randomId, const FullMsgId &itemId);
|
2014-05-30 12:53:19 +04:00
|
|
|
void historyUnregRandom(uint64 randomId);
|
2015-09-03 13:48:40 +03:00
|
|
|
FullMsgId histItemByRandom(uint64 randomId);
|
|
|
|
void historyRegSentData(uint64 randomId, const PeerId &peerId, const QString &text);
|
|
|
|
void historyUnregSentData(uint64 randomId);
|
|
|
|
void histSentDataByItem(uint64 randomId, PeerId &peerId, QString &text);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
void hoveredItem(HistoryItem *item);
|
|
|
|
HistoryItem *hoveredItem();
|
|
|
|
void pressedItem(HistoryItem *item);
|
|
|
|
HistoryItem *pressedItem();
|
|
|
|
void hoveredLinkItem(HistoryItem *item);
|
|
|
|
HistoryItem *hoveredLinkItem();
|
|
|
|
void pressedLinkItem(HistoryItem *item);
|
|
|
|
HistoryItem *pressedLinkItem();
|
|
|
|
void contextItem(HistoryItem *item);
|
|
|
|
HistoryItem *contextItem();
|
|
|
|
void mousedItem(HistoryItem *item);
|
|
|
|
HistoryItem *mousedItem();
|
|
|
|
|
2015-10-23 18:06:56 +02:00
|
|
|
const style::font &monofont();
|
2015-04-11 11:04:10 +01:00
|
|
|
const QPixmap &sprite();
|
2015-10-06 22:49:23 +03:00
|
|
|
const QPixmap &emoji();
|
|
|
|
const QPixmap &emojiLarge();
|
2015-05-08 15:45:14 +03:00
|
|
|
const QPixmap &emojiSingle(EmojiPtr emoji, int32 fontHeight);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
void initMedia();
|
|
|
|
void deinitMedia(bool completely = true);
|
|
|
|
void playSound();
|
|
|
|
|
|
|
|
void checkImageCacheSize();
|
|
|
|
|
|
|
|
bool isValidPhone(QString phone);
|
|
|
|
|
|
|
|
void quit();
|
|
|
|
bool quiting();
|
|
|
|
void setQuiting();
|
|
|
|
|
2015-12-07 16:05:00 +03:00
|
|
|
QImage readImage(QByteArray data, QByteArray *format = 0, bool opaque = true, bool *animated = 0);
|
2015-01-02 17:55:24 +03:00
|
|
|
QImage readImage(const QString &file, QByteArray *format = 0, bool opaque = true, bool *animated = 0, QByteArray *content = 0);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
void regVideoItem(VideoData *data, HistoryItem *item);
|
|
|
|
void unregVideoItem(VideoData *data, HistoryItem *item);
|
|
|
|
const VideoItems &videoItems();
|
|
|
|
|
|
|
|
void regAudioItem(AudioData *data, HistoryItem *item);
|
|
|
|
void unregAudioItem(AudioData*data, HistoryItem *item);
|
|
|
|
const AudioItems &audioItems();
|
|
|
|
|
|
|
|
void regDocumentItem(DocumentData *data, HistoryItem *item);
|
|
|
|
void unregDocumentItem(DocumentData *data, HistoryItem *item);
|
|
|
|
const DocumentItems &documentItems();
|
|
|
|
|
2015-04-04 23:01:34 +03:00
|
|
|
void regWebPageItem(WebPageData *data, HistoryItem *item);
|
|
|
|
void unregWebPageItem(WebPageData *data, HistoryItem *item);
|
|
|
|
const WebPageItems &webPageItems();
|
|
|
|
|
2015-12-13 01:29:33 +03:00
|
|
|
void regSharedContactItem(int32 userId, HistoryItem *item);
|
|
|
|
void unregSharedContactItem(int32 userId, HistoryItem *item);
|
|
|
|
const SharedContactItems &sharedContactItems();
|
2015-09-02 13:20:33 +03:00
|
|
|
QString phoneFromSharedContact(int32 userId);
|
|
|
|
|
2015-12-15 17:50:51 +03:00
|
|
|
void regGifItem(ClipReader *reader, HistoryItem *item);
|
|
|
|
void unregGifItem(ClipReader *reader);
|
|
|
|
const GifItems &gifItems();
|
2015-12-16 16:35:15 +03:00
|
|
|
void stopGifItems();
|
2015-12-15 17:50:51 +03:00
|
|
|
|
2015-04-30 16:53:36 +03:00
|
|
|
void regMuted(PeerData *peer, int32 changeIn);
|
|
|
|
void unregMuted(PeerData *peer);
|
|
|
|
void updateMuted();
|
|
|
|
|
2015-09-03 13:48:40 +03:00
|
|
|
void feedReplyMarkup(ChannelId channelId, MsgId msgId, const MTPReplyMarkup &markup);
|
|
|
|
void clearReplyMarkup(ChannelId channelId, MsgId msgId);
|
|
|
|
const ReplyMarkup &replyMarkup(ChannelId channelId, MsgId msgId);
|
2015-06-15 20:19:24 +03:00
|
|
|
|
2014-05-30 12:53:19 +04:00
|
|
|
void setProxySettings(QNetworkAccessManager &manager);
|
|
|
|
void setProxySettings(QTcpSocket &socket);
|
|
|
|
|
2015-05-20 22:28:24 +03:00
|
|
|
QImage **cornersMask();
|
2015-09-19 12:13:21 +03:00
|
|
|
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, const style::color &bg, RoundCorners index, const style::color *sh = 0);
|
|
|
|
inline void roundRect(Painter &p, const QRect &rect, const style::color &bg, RoundCorners index, const style::color *sh = 0) {
|
2015-05-20 22:28:24 +03:00
|
|
|
return roundRect(p, rect.x(), rect.y(), rect.width(), rect.height(), bg, index, sh);
|
|
|
|
}
|
2015-09-19 12:13:21 +03:00
|
|
|
void roundShadow(Painter &p, int32 x, int32 y, int32 w, int32 h, const style::color &sh, RoundCorners index);
|
|
|
|
inline void roundShadow(Painter &p, const QRect &rect, const style::color &sh, RoundCorners index) {
|
2015-05-22 14:14:52 +03:00
|
|
|
return roundShadow(p, rect.x(), rect.y(), rect.width(), rect.height(), sh, index);
|
|
|
|
}
|
2015-10-03 13:09:09 +03:00
|
|
|
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, const style::color &bg);
|
|
|
|
inline void roundRect(Painter &p, const QRect &rect, const style::color &bg) {
|
|
|
|
return roundRect(p, rect.x(), rect.y(), rect.width(), rect.height(), bg);
|
|
|
|
}
|
2015-05-20 22:28:24 +03:00
|
|
|
|
2015-04-23 18:50:11 +03:00
|
|
|
void initBackground(int32 id = DefaultChatBackground, const QImage &p = QImage(), bool nowrite = false);
|
2015-02-03 18:02:46 +03:00
|
|
|
|
2015-05-20 22:50:05 +03:00
|
|
|
const style::color &msgServiceBg();
|
|
|
|
const style::color &msgServiceSelectBg();
|
|
|
|
const style::color &historyScrollBarColor();
|
|
|
|
const style::color &historyScrollBgColor();
|
|
|
|
const style::color &historyScrollBarOverColor();
|
|
|
|
const style::color &historyScrollBgOverColor();
|
|
|
|
const style::color &introPointHoverColor();
|
2015-02-03 18:02:46 +03:00
|
|
|
|
|
|
|
struct WallPaper {
|
|
|
|
WallPaper(int32 id, ImagePtr thumb, ImagePtr full) : id(id), thumb(thumb), full(full) {
|
|
|
|
}
|
|
|
|
int32 id;
|
|
|
|
ImagePtr thumb;
|
|
|
|
ImagePtr full;
|
|
|
|
};
|
|
|
|
typedef QList<WallPaper> WallPapers;
|
|
|
|
DeclareSetting(WallPapers, ServerBackgrounds);
|
|
|
|
|
2015-11-20 16:34:37 +03:00
|
|
|
};
|
2015-12-02 20:17:53 +03:00
|
|
|
|
|
|
|
inline int32 stickersCountHash(bool checkOfficial = false) {
|
|
|
|
uint32 acc = 0;
|
|
|
|
bool foundOfficial = false, foundBad = false;;
|
|
|
|
const StickerSets &sets(cStickerSets());
|
|
|
|
const StickerSetsOrder &order(cStickerSetsOrder());
|
|
|
|
for (StickerSetsOrder::const_iterator i = order.cbegin(), e = order.cend(); i != e; ++i) {
|
|
|
|
StickerSets::const_iterator j = sets.constFind(*i);
|
|
|
|
if (j != sets.cend()) {
|
|
|
|
if (j->id == 0) {
|
|
|
|
foundBad = true;
|
|
|
|
} else if (j->flags & MTPDstickerSet::flag_official) {
|
|
|
|
foundOfficial = true;
|
|
|
|
}
|
|
|
|
if (!(j->flags & MTPDstickerSet::flag_disabled)) {
|
|
|
|
acc = (acc * 20261) + j->hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (!checkOfficial || (!foundBad && foundOfficial)) ? int32(acc & 0x7FFFFFFF) : 0;
|
|
|
|
}
|
2015-12-07 16:05:00 +03:00
|
|
|
|
|
|
|
#include "facades.h"
|