2014-05-30 08:53:19 +00:00
/*
This file is part of Telegram Desktop ,
2014-12-01 10:47:38 +00:00
the official desktop version of Telegram messaging app , see https : //telegram.org
2014-05-30 08:53:19 +00: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 .
Full license : https : //github.com/telegramdesktop/tdesktop/blob/master/LICENSE
2014-12-01 10:47:38 +00:00
Copyright ( c ) 2014 John Preston , https : //desktop.telegram.org
2014-05-30 08:53:19 +00:00
*/
# pragma once
# include "types.h"
class Application ;
class Window ;
class MainWidget ;
2014-08-01 11:09:46 +00:00
class SettingsWidget ;
2015-03-19 09:18:19 +00:00
class ApiWrap ;
2014-05-30 08:53:19 +00:00
class Font ;
class Color ;
class FileUploader ;
# include "history.h"
typedef QMap < HistoryItem * , bool > HistoryItemsMap ;
typedef QHash < VideoData * , HistoryItemsMap > VideoItems ;
typedef QHash < AudioData * , HistoryItemsMap > AudioItems ;
typedef QHash < DocumentData * , HistoryItemsMap > DocumentItems ;
2015-04-04 20:01:34 +00:00
typedef QHash < WebPageData * , HistoryItemsMap > WebPageItems ;
2015-06-17 19:43:03 +00:00
struct ReplyMarkup {
ReplyMarkup ( int32 flags = 0 ) : flags ( flags ) {
}
typedef QList < QList < QString > > Commands ;
Commands commands ;
int32 flags ;
} ;
2014-05-30 08:53:19 +00:00
2015-05-20 19:28:24 +00:00
enum RoundCorners {
MaskCorners = 0x00 , // for images
BlackCorners ,
ServiceCorners ,
ServiceSelectedCorners ,
SelectedOverlayCorners ,
DateCorners ,
DateSelectedCorners ,
ForwardCorners ,
MediaviewSaveCorners ,
EmojiHoverCorners ,
StickerHoverCorners ,
2015-06-15 17:19:24 +00:00
BotKeyboardCorners ,
BotKeyboardOverCorners ,
BotKeyboardDownCorners ,
2015-08-28 15:15:56 +00:00
PhotoSelectOverlayCorners ,
DocRedCorners ,
DocYellowCorners ,
DocGreenCorners ,
DocBlueCorners ,
2015-05-20 19:28:24 +00:00
InShadowCorners , // for photos without bg
InSelectedShadowCorners ,
MessageInCorners , // with shadow
MessageInSelectedCorners ,
MessageOutCorners ,
MessageOutSelectedCorners ,
ButtonHoverCorners ,
RoundCornersCount
} ;
2014-05-30 08:53:19 +00:00
namespace App {
Application * app ( ) ;
Window * wnd ( ) ;
MainWidget * main ( ) ;
2014-08-01 11:09:46 +00:00
SettingsWidget * settings ( ) ;
2015-03-02 12:34:16 +00:00
bool passcoded ( ) ;
2014-05-30 08:53:19 +00:00
FileUploader * uploader ( ) ;
2015-03-19 09:18:19 +00:00
ApiWrap * api ( ) ;
2014-05-30 08:53:19 +00:00
void showSettings ( ) ;
void logOut ( ) ;
bool loggedOut ( ) ;
QString formatPhone ( QString phone ) ;
2015-06-10 12:48:26 +00:00
int32 onlineForSort ( UserData * user , int32 now ) ;
int32 onlineWillChangeIn ( UserData * user , int32 nowOnServer ) ;
2014-11-22 09:45:04 +00:00
QString onlineText ( UserData * user , int32 nowOnServer , bool precise = false ) ;
2015-06-24 17:24:48 +00:00
bool onlineColorUse ( UserData * user , int32 now ) ;
2014-05-30 08:53:19 +00:00
2015-06-29 22:09:23 +00:00
UserData * feedUsers ( const MTPVector < MTPUser > & users , bool emitPeerUpdated = true ) ; // returns last user
2015-09-03 10:48:40 +00:00
PeerData * feedChats ( const MTPVector < MTPChat > & chats , bool emitPeerUpdated = true ) ; // returns last chat
2015-06-29 22:09:23 +00: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-09-01 21:33:44 +00:00
void checkEntitiesUpdate ( const MTPDmessage & m ) ;
2015-03-19 09:18:19 +00:00
void feedMsgs ( const MTPVector < MTPMessage > & msgs , int msgsState = 0 ) ; // 2 - new read message, 1 - new unread message, 0 - not new message, -1 - searched message
2015-09-03 10:48:40 +00: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-29 22:09:23 +00: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 15:02:46 +00:00
ImagePtr image ( const MTPPhotoSize & size ) ;
2015-08-07 12:11:50 +00:00
StorageImageLocation imageLocation ( int32 w , int32 h , const MTPFileLocation & loc ) ;
2015-05-19 15:46:45 +00:00
StorageImageLocation imageLocation ( const MTPPhotoSize & size ) ;
2015-02-03 15:02:46 +00:00
2014-05-30 08:53:19 +00: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 18:52:43 +00:00
AudioData * feedAudio ( const MTPaudio & audio , AudioData * convert = 0 ) ;
2014-05-30 08:53:19 +00:00
AudioData * feedAudio ( const MTPDaudio & audio , AudioData * convert = 0 ) ;
2015-01-02 14:55:24 +00: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 20:01:34 +00: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 08:53:19 +00:00
2015-09-03 10:48:40 +00:00
PeerData * peerLoaded ( const PeerId & id ) ;
UserData * userLoaded ( const PeerId & id ) ;
ChatData * chatLoaded ( const PeerId & id ) ;
ChannelData * channelLoaded ( const PeerId & id ) ;
2014-05-30 08:53:19 +00:00
UserData * userLoaded ( int32 user ) ;
ChatData * chatLoaded ( int32 chat ) ;
2015-09-03 10:48:40 +00: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 08:53:19 +00:00
UserData * self ( ) ;
2014-12-03 13:10:32 +00:00
UserData * userByName ( const QString & username ) ;
2014-05-30 08:53:19 +00:00
QString peerName ( const PeerData * peer , bool forDialogs = false ) ;
2015-07-21 14:55:23 +00:00
PhotoData * photo ( const PhotoId & photo ) ;
2015-08-12 18:01:32 +00: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 14:55:23 +00:00
VideoData * video ( const VideoId & video ) ;
2015-08-12 18:01:32 +00: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 14:55:23 +00:00
AudioData * audio ( const AudioId & audio ) ;
2015-08-12 18:01:32 +00: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 15:46:45 +00: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 14:55:23 +00:00
WebPageData * webPage ( const WebPageId & webPage ) ;
2015-08-30 14:57:21 +00: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 14:55:23 +00:00
ImageLinkData * imageLink ( const QString & imageLink ) ;
ImageLinkData * imageLinkSet ( const QString & imageLink , ImageLinkType type , const QString & url ) ;
2014-11-12 20:18:00 +00:00
void forgetMedia ( ) ;
2014-05-30 08:53:19 +00:00
MTPPhoto photoFromUserPhoto ( MTPint userId , MTPint date , const MTPUserProfilePhoto & photo ) ;
Histories & histories ( ) ;
2015-03-13 13:01:25 +00:00
History * history ( const PeerId & peer , int32 unreadCnt = 0 , int32 maxInboxRead = 0 ) ;
2014-05-30 08:53:19 +00:00
History * historyLoaded ( const PeerId & peer ) ;
2015-09-03 10:48:40 +00:00
HistoryItem * histItemById ( ChannelId channelId , MsgId itemId ) ;
inline HistoryItem * histItemById ( const FullMsgId & msgId ) {
return histItemById ( msgId . channel , msgId . msg ) ;
}
2014-07-04 11:12:54 +00:00
HistoryItem * historyRegItem ( HistoryItem * item ) ;
void historyItemDetached ( HistoryItem * item ) ;
2014-05-30 08:53:19 +00:00
void historyUnregItem ( HistoryItem * item ) ;
void historyClearMsgs ( ) ;
void historyClearItems ( ) ;
2015-03-19 09:18:19 +00:00
void historyRegReply ( HistoryReply * reply , HistoryItem * to ) ;
void historyUnregReply ( HistoryReply * reply , HistoryItem * to ) ;
2014-05-30 08:53:19 +00:00
2015-09-03 10:48:40 +00:00
void historyRegRandom ( uint64 randomId , const FullMsgId & itemId ) ;
2014-05-30 08:53:19 +00:00
void historyUnregRandom ( uint64 randomId ) ;
2015-09-03 10:48:40 +00: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 08:53:19 +00: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-04-11 10:04:10 +00:00
const QPixmap & sprite ( ) ;
const QPixmap & emojis ( ) ;
2015-05-08 12:45:14 +00:00
const QPixmap & emojisLarge ( ) ;
const QPixmap & emojiSingle ( EmojiPtr emoji , int32 fontHeight ) ;
2014-05-30 08:53:19 +00:00
void initMedia ( ) ;
void deinitMedia ( bool completely = true ) ;
void playSound ( ) ;
void checkImageCacheSize ( ) ;
bool isValidPhone ( QString phone ) ;
void quit ( ) ;
bool quiting ( ) ;
void setQuiting ( ) ;
2014-12-22 23:11:37 +00:00
QImage readImage ( QByteArray data , QByteArray * format = 0 , bool opaque = true , bool * animated = 0 ) ;
2015-01-02 14:55:24 +00:00
QImage readImage ( const QString & file , QByteArray * format = 0 , bool opaque = true , bool * animated = 0 , QByteArray * content = 0 ) ;
2014-05-30 08:53:19 +00: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 20:01:34 +00:00
void regWebPageItem ( WebPageData * data , HistoryItem * item ) ;
void unregWebPageItem ( WebPageData * data , HistoryItem * item ) ;
const WebPageItems & webPageItems ( ) ;
2015-09-02 10:20:33 +00:00
void regSharedContactPhone ( int32 userId , const QString & phone ) ;
QString phoneFromSharedContact ( int32 userId ) ;
2015-04-30 13:53:36 +00:00
void regMuted ( PeerData * peer , int32 changeIn ) ;
void unregMuted ( PeerData * peer ) ;
void updateMuted ( ) ;
2015-09-03 10:48:40 +00: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 17:19:24 +00:00
2014-05-30 08:53:19 +00:00
void setProxySettings ( QNetworkAccessManager & manager ) ;
void setProxySettings ( QTcpSocket & socket ) ;
2015-06-15 17:19:24 +00:00
void sendBotCommand ( const QString & cmd , MsgId replyTo = 0 ) ;
2015-06-17 19:43:03 +00:00
void insertBotCommand ( const QString & cmd ) ;
2014-07-16 06:58:36 +00:00
void searchByHashtag ( const QString & tag ) ;
2015-06-17 19:43:03 +00:00
void openUserByName ( const QString & username , bool toProfile = false , const QString & startToken = QString ( ) ) ;
2015-04-30 13:53:36 +00:00
void joinGroupByHash ( const QString & hash ) ;
2015-05-19 15:46:45 +00:00
void stickersBox ( const QString & name ) ;
2014-12-03 13:10:32 +00:00
void openLocalUrl ( const QString & url ) ;
2014-07-16 06:58:36 +00:00
2015-05-20 19:28:24 +00:00
QImage * * cornersMask ( ) ;
QPixmap * * corners ( RoundCorners index ) ;
void roundRect ( QPainter & p , int32 x , int32 y , int32 w , int32 h , const style : : color & bg , RoundCorners index , const style : : color * sh = 0 ) ;
inline void roundRect ( QPainter & p , const QRect & rect , const style : : color & bg , RoundCorners index , const style : : color * sh = 0 ) {
return roundRect ( p , rect . x ( ) , rect . y ( ) , rect . width ( ) , rect . height ( ) , bg , index , sh ) ;
}
2015-05-22 11:14:52 +00:00
void roundShadow ( QPainter & p , int32 x , int32 y , int32 w , int32 h , const style : : color & sh , RoundCorners index ) ;
inline void roundShadow ( QPainter & p , const QRect & rect , const style : : color & sh , RoundCorners index ) {
return roundShadow ( p , rect . x ( ) , rect . y ( ) , rect . width ( ) , rect . height ( ) , sh , index ) ;
}
2015-05-20 19:28:24 +00:00
2015-04-23 15:50:11 +00:00
void initBackground ( int32 id = DefaultChatBackground , const QImage & p = QImage ( ) , bool nowrite = false ) ;
2015-02-03 15:02:46 +00:00
2015-05-20 19:50:05 +00: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 15:02:46 +00: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 ) ;
2014-05-30 08:53:19 +00:00
} ;