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 ;
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 ,
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 ) ;
inline bool isChat ( const PeerId & peer ) {
return peer & 0x100000000L ;
}
PeerId peerFromMTP ( const MTPPeer & peer_id ) ;
PeerId peerFromChat ( int32 chat_id ) ;
inline PeerId peerFromChat ( const MTPint & chat_id ) {
return peerFromChat ( chat_id . v ) ;
}
PeerId peerFromUser ( int32 user_id ) ;
inline PeerId peerFromUser ( const MTPint & user_id ) {
return peerFromUser ( user_id . v ) ;
}
MTPpeer peerToMTP ( const PeerId & peer_id ) ;
2014-06-16 09:31:10 +00:00
int32 userFromPeer ( const PeerId & peer_id ) ;
int32 chatFromPeer ( const PeerId & peer_id ) ;
2014-05-30 08:53:19 +00:00
2014-11-18 12:41:33 +00:00
int32 onlineForSort ( int32 online , int32 now ) ;
2014-05-30 08:53:19 +00:00
int32 onlineWillChangeIn ( int32 onlineOnServer , int32 nowOnServer ) ;
2014-11-22 09:45:04 +00:00
QString onlineText ( UserData * user , int32 nowOnServer , bool precise = false ) ;
2015-01-23 11:02:45 +00:00
bool onlineColorUse ( int32 online , int32 now ) ;
2014-05-30 08:53:19 +00:00
2015-04-30 13:53:36 +00:00
UserData * feedUsers ( const MTPVector < MTPUser > & users ) ; // returns last user
ChatData * feedChats ( const MTPVector < MTPChat > & chats ) ; // returns last chat
2014-05-30 08:53:19 +00:00
void feedParticipants ( const MTPChatParticipants & p ) ;
void feedParticipantAdd ( const MTPDupdateChatParticipantAdd & d ) ;
void feedParticipantDelete ( const MTPDupdateChatParticipantDelete & d ) ;
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
2014-05-30 08:53:19 +00:00
void feedWereRead ( const QVector < MTPint > & msgsIds ) ;
2015-03-13 13:01:25 +00:00
void feedInboxRead ( const PeerId & peer , int32 upTo ) ;
void feedOutboxRead ( const PeerId & peer , int32 upTo ) ;
2014-05-30 08:53:19 +00:00
void feedWereDeleted ( const QVector < MTPint > & msgsIds ) ;
void feedUserLinks ( const MTPVector < MTPcontacts_Link > & links ) ;
2015-03-13 13:01:25 +00:00
void feedUserLink ( MTPint userId , const MTPContactLink & myLink , const MTPContactLink & foreignLink ) ;
2014-05-30 08:53:19 +00:00
int32 maxMsgId ( ) ;
2015-02-03 15:02:46 +00:00
ImagePtr image ( const MTPPhotoSize & size ) ;
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
UserData * userLoaded ( const PeerId & user ) ;
ChatData * chatLoaded ( const PeerId & chat ) ;
PeerData * peerLoaded ( const PeerId & peer ) ;
UserData * userLoaded ( int32 user ) ;
ChatData * chatLoaded ( int32 chat ) ;
PeerData * peer ( const PeerId & peer ) ;
UserData * user ( const PeerId & peer ) ;
UserData * user ( int32 user ) ;
UserData * self ( ) ;
2014-12-03 13:10:32 +00:00
UserData * userByName ( const QString & username ) ;
2014-05-30 08:53:19 +00:00
ChatData * chat ( const PeerId & peer ) ;
ChatData * chat ( int32 chat ) ;
QString peerName ( const PeerData * peer , bool forDialogs = false ) ;
2014-08-15 11:19:32 +00:00
PhotoData * photo ( const PhotoId & photo , PhotoData * convert = 0 , const uint64 & access = 0 , int32 user = 0 , int32 date = 0 , const ImagePtr & thumb = ImagePtr ( ) , const ImagePtr & medium = ImagePtr ( ) , const ImagePtr & full = ImagePtr ( ) ) ;
2014-05-30 08:53:19 +00:00
VideoData * video ( const VideoId & video , VideoData * convert = 0 , const uint64 & access = 0 , int32 user = 0 , int32 date = 0 , int32 duration = 0 , int32 w = 0 , int32 h = 0 , const ImagePtr & thumb = ImagePtr ( ) , int32 dc = 0 , int32 size = 0 ) ;
2015-01-27 16:58:58 +00:00
AudioData * audio ( const AudioId & audio , AudioData * convert = 0 , const uint64 & access = 0 , int32 user = 0 , int32 date = 0 , const QString & mime = QString ( ) , int32 duration = 0 , int32 dc = 0 , int32 size = 0 ) ;
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-04-07 23:03:32 +00:00
WebPageData * webPage ( const WebPageId & webPage , WebPageData * convert = 0 , const QString & type = QString ( ) , const QString & url = QString ( ) , const QString & displayUrl = QString ( ) , const QString & siteName = QString ( ) , const QString & title = QString ( ) , const QString & description = QString ( ) , PhotoData * photo = 0 , int32 duration = 0 , const QString & author = QString ( ) , int32 pendingTill = - 2 ) ;
2014-11-12 20:18:00 +00:00
ImageLinkData * imageLink ( const QString & imageLink , ImageLinkType type = InvalidImageLink , const QString & url = QString ( ) ) ;
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 ) ;
HistoryItem * histItemById ( MsgId itemId ) ;
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
// void deleteHistory(const PeerId &peer);
void historyRegRandom ( uint64 randomId , MsgId itemId ) ;
void historyUnregRandom ( uint64 randomId ) ;
MsgId histItemByRandom ( uint64 randomId ) ;
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-04-30 13:53:36 +00:00
void regMuted ( PeerData * peer , int32 changeIn ) ;
void unregMuted ( PeerData * peer ) ;
void updateMuted ( ) ;
2014-05-30 08:53:19 +00:00
void setProxySettings ( QNetworkAccessManager & manager ) ;
void setProxySettings ( QTcpSocket & socket ) ;
2014-07-16 06:58:36 +00:00
void searchByHashtag ( const QString & tag ) ;
2015-03-19 09:18:19 +00:00
void openUserByName ( const QString & username , bool toProfile = false ) ;
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
} ;