1 /* 2 Copyright (C) 2014 Aseman 3 http://aseman.co 4 5 This project is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This project is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef CUTEGRAM_H 20 #define CUTEGRAM_H 21 22 #include <QObject> 23 #include <QSize> 24 #include <QVariantMap> 25 #include <QSystemTrayIcon> 26 #include <QFont> 27 28 class DatabaseAbstractEncryptor; 29 class QMenu; 30 class ThemeItem; 31 class CutegramPrivate; 32 class Cutegram : public QObject 33 { 34 Q_OBJECT 35 Q_ENUMS(StartupOptions) 36 Q_ENUMS(StatusIconStyles) 37 38 Q_PROPERTY(QString defaultHostAddress READ defaultHostAddress WRITE setDefaultHostAddress NOTIFY defaultHostAddressChanged) 39 Q_PROPERTY(int defaultHostPort READ defaultHostPort WRITE setDefaultHostPort NOTIFY defaultHostPortChanged) 40 Q_PROPERTY(int defaultHostDcId READ defaultHostDcId WRITE setDefaultHostDcId NOTIFY defaultHostDcIdChanged) 41 Q_PROPERTY(int appId READ appId WRITE setAppId NOTIFY appIdChanged) 42 Q_PROPERTY(QString appHash READ appHash WRITE setAppHash NOTIFY appHashChanged) 43 44 Q_PROPERTY(DatabaseAbstractEncryptor* encrypter READ encrypter NOTIFY encrypterChanged) 45 46 Q_PROPERTY(QStringList languages READ languages NOTIFY fakeSignal) 47 Q_PROPERTY(QString personalStickerDirectory READ personalStickerDirectory NOTIFY fakeSignal) 48 Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor NOTIFY highlightColorChanged) 49 Q_PROPERTY(bool allowNativeTitleBar READ allowNativeTitleBar NOTIFY fakeSignal) 50 51 Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged ) 52 Q_PROPERTY(QString messageAudio READ messageAudio WRITE setMessageAudio NOTIFY messageAudioChanged) 53 Q_PROPERTY(QString background READ background WRITE setBackground NOTIFY backgroundChanged ) 54 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged ) 55 Q_PROPERTY(QString masterColor READ masterColor WRITE setMasterColor NOTIFY masterColorChanged ) 56 57 Q_PROPERTY(int sysTrayCounter READ sysTrayCounter WRITE setSysTrayCounter NOTIFY sysTrayCounterChanged ) 58 Q_PROPERTY(int startupOption READ startupOption WRITE setStartupOption NOTIFY startupOptionChanged ) 59 Q_PROPERTY(bool notification READ notification WRITE setNotification NOTIFY notificationChanged ) 60 Q_PROPERTY(bool emojiOnHover READ emojiOnHover WRITE setEmojiOnHover NOTIFY emojiOnHoverChanged ) 61 Q_PROPERTY(bool minimumDialogs READ minimumDialogs WRITE setMinimumDialogs NOTIFY minimumDialogsChanged ) 62 Q_PROPERTY(bool showLastMessage READ showLastMessage WRITE setShowLastMessage NOTIFY showLastMessageChanged ) 63 Q_PROPERTY(bool darkSystemTray READ darkSystemTray WRITE setDarkSystemTray NOTIFY darkSystemTrayChanged ) 64 Q_PROPERTY(bool cutegramSubscribe READ cutegramSubscribe WRITE setAsemanSubscribe NOTIFY cutegramSubscribeChanged) 65 Q_PROPERTY(int statusIconStyle READ statusIconStyle WRITE setStatusIconStyle NOTIFY statusIconStyleChanged ) 66 Q_PROPERTY(bool smoothScroll READ smoothScroll WRITE setSmoothScroll NOTIFY smoothScrollChanged ) 67 Q_PROPERTY(bool autoEmojis READ autoEmojis WRITE setAutoEmojis NOTIFY autoEmojisChanged ) 68 Q_PROPERTY(bool sendByCtrlEnter READ sendByCtrlEnter WRITE setSendByCtrlEnter NOTIFY sendByCtrlEnterChanged ) 69 Q_PROPERTY(bool kWallet READ kWallet WRITE setKWallet NOTIFY kWalletChanged ) 70 Q_PROPERTY(bool nativeTitleBar READ nativeTitleBar WRITE setNativeTitleBar NOTIFY nativeTitleBarChanged ) 71 72 Q_PROPERTY(ThemeItem* currentTheme READ currentTheme NOTIFY currentThemeChanged) 73 Q_PROPERTY(QStringList themes READ themes NOTIFY themesChanged) 74 Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) 75 Q_PROPERTY(QStringList emojisThemes READ emojisThemes NOTIFY emojisThemesChanged) 76 Q_PROPERTY(QString emojisTheme READ emojisTheme WRITE setEmojisTheme NOTIFY emojisThemeChanged) 77 78 Q_PROPERTY(QStringList searchEngines READ searchEngines NOTIFY searchEnginesChanged) 79 Q_PROPERTY(QString searchEngine READ searchEngine WRITE setSearchEngine NOTIFY searchEngineChanged) 80 81 Q_PROPERTY(bool closingState READ closingState NOTIFY closingStateChanged) 82 83 public: 84 enum StartupOptions { 85 StartupAutomatic = 0, 86 StartupVisible = 1, 87 StartupHide = 2 88 }; 89 90 enum StatusIconStyles { 91 StatusIconAutomatic, 92 StatusIconDark, 93 StatusIconLight 94 }; 95 96 Cutegram(QObject *parent = 0); 97 ~Cutegram(); 98 99 Q_INVOKABLE static QVariantList intListToVariantList(const QList<qint32> &list); 100 Q_INVOKABLE static QList<qint32> variantListToIntList(const QVariantList &list); 101 102 Q_INVOKABLE QSize imageSize( const QString & path ); 103 Q_INVOKABLE bool filsIsImage(const QString & path); 104 Q_INVOKABLE qreal htmlWidth( const QString & txt ); 105 106 Q_INVOKABLE void deleteFile(const QString &path); 107 Q_INVOKABLE QString storeMessage(const QString &msg); 108 109 Q_INVOKABLE QString getTimeString( const QDateTime & dt ); 110 111 Q_INVOKABLE int showMenu( const QStringList & actions, QPoint point = QPoint() ); 112 113 void setDefaultHostAddress(const QString &host); 114 QString defaultHostAddress() const; 115 116 void setDefaultHostPort(int port); 117 int defaultHostPort() const; 118 119 void setDefaultHostDcId(int dcId); 120 int defaultHostDcId() const; 121 122 void setAppId(int appId); 123 int appId() const; 124 125 void setAppHash(const QString &appHash); 126 QString appHash() const; 127 128 void setSysTrayCounter(int count , bool force = false); 129 int sysTrayCounter() const; 130 131 QStringList languages(); 132 133 void setLanguage( const QString & lang ); 134 QString language() const; 135 136 bool closingState() const; 137 138 void setStartupOption( int opt ); 139 int startupOption() const; 140 141 void setNotification(bool stt); 142 bool notification() const; 143 144 void setEmojiOnHover(bool stt); 145 bool emojiOnHover() const; 146 147 void setMinimumDialogs(bool stt); 148 bool minimumDialogs() const; 149 150 void setShowLastMessage(bool stt); 151 bool showLastMessage() const; 152 153 void setDarkSystemTray(bool stt); 154 bool darkSystemTray() const; 155 156 void setSmoothScroll(bool stt); 157 bool smoothScroll() const; 158 159 void setKWallet(bool stt); 160 bool kWallet() const; 161 162 void setNativeTitleBar(bool stt); 163 bool nativeTitleBar() const; 164 bool allowNativeTitleBar() const; 165 166 void setBackground(const QString &background); 167 QString background() const; 168 169 void setMessageAudio(const QString &file); 170 QString messageAudio() const; 171 172 void setMasterColor(const QString &color); 173 QString masterColor() const; 174 175 QColor highlightColor() const; 176 void setHighlightColor(const QColor &color); 177 178 void setVisualEffects(bool stt); 179 bool visualEffects() const; 180 181 void setFont(const QFont &font); 182 QFont font() const; 183 184 void setAsemanSubscribe(bool stt); 185 bool cutegramSubscribe() const; 186 187 void setAutoEmojis(bool stt); 188 bool autoEmojis() const; 189 190 void setSendByCtrlEnter(bool stt); 191 bool sendByCtrlEnter() const; 192 193 void setStatusIconStyle(int style); 194 int statusIconStyle(); 195 196 QStringList themes() const; 197 void setTheme(const QString &theme); 198 QString theme() const; 199 ThemeItem *currentTheme(); 200 201 QStringList emojisThemes() const; 202 void setEmojisTheme(const QString& theme); 203 QString emojisTheme() const; 204 205 QStringList searchEngines() const; 206 void setSearchEngine(const QString &se); 207 QString searchEngine() const; 208 209 QString personalStickerDirectory() const; 210 211 DatabaseAbstractEncryptor *encrypter(); 212 void setEncrypterKey(const QString &key); 213 214 Q_INVOKABLE bool isLoggedIn(const QString &phone) const; 215 Q_INVOKABLE QString normalizeText(const QString &text) const; 216 217 public slots: 218 void start(bool forceVisible = false); 219 void restart(); 220 void logout(const QString & phone); 221 void close(); 222 void quit(); 223 void contact(); 224 void aboutAseman(); 225 void about(); 226 void configure(); 227 void incomingAppMessage(const QString & msg); 228 void active(); 229 void addToPersonal(const QString &src); 230 void installSticker(const QString &shortName); 231 void savePosition(bool force = true); 232 233 signals: 234 void defaultHostAddressChanged(); 235 void defaultHostPortChanged(); 236 void defaultHostDcIdChanged(); 237 void appIdChanged(); 238 void appHashChanged(); 239 void encrypterChanged(); 240 241 void backRequest(); 242 void sysTrayCounterChanged(); 243 void fakeSignal(); 244 void emojiOnHoverChanged(); 245 void languageChanged(); 246 void languageDirectionChanged(); 247 void startupOptionChanged(); 248 void notificationChanged(); 249 void minimumDialogsChanged(); 250 void nativeTitleBarChanged(); 251 void showLastMessageChanged(); 252 void backgroundChanged(); 253 void messageAudioChanged(); 254 void masterColorChanged(); 255 void highlightColorChanged(); 256 void darkSystemTrayChanged(); 257 void fontChanged(); 258 void closingStateChanged(); 259 void cutegramSubscribeChanged(); 260 void statusIconStyleChanged(); 261 void smoothScrollChanged(); 262 void autoEmojisChanged(); 263 void sendByCtrlEnterChanged(); 264 void kWalletChanged(); 265 266 void themesChanged(); 267 void currentThemeChanged(); 268 void themeChanged(); 269 270 void emojisThemesChanged(); 271 void emojisThemeChanged(); 272 273 void searchEngineChanged(); 274 void searchEnginesChanged(); 275 276 void configureRequest(); 277 void aboutAsemanRequest(); 278 279 protected: 280 bool eventFilter(QObject *o, QEvent *e); 281 282 private slots: 283 void systray_action( QSystemTrayIcon::ActivationReason act ); 284 285 private: 286 void init_systray(); 287 QImage generateIcon( const QImage & img, int count ); 288 void init_languages(); 289 void init_theme(); 290 291 bool lowLevelDarkSystemTray(); 292 293 QMenu *contextMenu(); 294 295 private: 296 CutegramPrivate *p; 297 }; 298 299 Q_DECLARE_METATYPE( QList<qint32> ) 300 301 #endif // CUTEGRAM_H 302