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
|
|
|
|
|
|
|
|
extern bool gDebug;
|
|
|
|
inline bool cDebug() {
|
2014-10-25 09:25:18 +00:00
|
|
|
#if defined _DEBUG
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
2014-10-25 09:25:18 +00:00
|
|
|
#elif defined _WITH_DEBUG
|
2014-05-30 08:53:19 +00:00
|
|
|
return gDebug;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
inline void cSetDebug(bool debug) {
|
|
|
|
gDebug = debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DeclareReadSetting(Type, Name) extern Type g##Name; \
|
|
|
|
inline const Type &c##Name() { \
|
|
|
|
return g##Name; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DeclareSetting(Type, Name) DeclareReadSetting(Type, Name) \
|
|
|
|
inline void cSet##Name(const Type &Name) { \
|
|
|
|
g##Name = Name; \
|
|
|
|
}
|
|
|
|
|
2015-05-08 12:45:14 +00:00
|
|
|
#define DeclareRefSetting(Type, Name) DeclareSetting(Type, Name) \
|
|
|
|
inline Type &cRef##Name() { \
|
|
|
|
return g##Name; \
|
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
DeclareSetting(bool, Rtl);
|
|
|
|
DeclareSetting(Qt::LayoutDirection, LangDir);
|
|
|
|
inline bool rtl() {
|
|
|
|
return cRtl();
|
|
|
|
}
|
|
|
|
|
2015-03-02 12:34:16 +00:00
|
|
|
struct mtpDcOption {
|
2015-06-10 12:48:26 +00:00
|
|
|
mtpDcOption(int id, int flags, const string &ip, int port) : id(id), flags(flags), ip(ip), port(port) {
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int id;
|
2015-06-10 12:48:26 +00:00
|
|
|
int flags;
|
2015-03-02 12:34:16 +00:00
|
|
|
string ip;
|
|
|
|
int port;
|
|
|
|
};
|
|
|
|
typedef QMap<int, mtpDcOption> mtpDcOptions;
|
|
|
|
DeclareSetting(mtpDcOptions, DcOptions);
|
|
|
|
|
2015-07-28 13:47:21 +00:00
|
|
|
DeclareSetting(bool, DevVersion);
|
|
|
|
|
2015-01-23 15:24:36 +00:00
|
|
|
DeclareSetting(bool, TestMode);
|
2014-05-30 08:53:19 +00:00
|
|
|
DeclareSetting(QString, LoggedPhoneNumber);
|
|
|
|
DeclareReadSetting(uint32, ConnectionsInSession);
|
|
|
|
DeclareSetting(bool, AutoStart);
|
|
|
|
DeclareSetting(bool, StartMinimized);
|
2015-01-27 16:58:58 +00:00
|
|
|
DeclareSetting(bool, StartInTray);
|
2014-07-18 10:37:34 +00:00
|
|
|
DeclareSetting(bool, SendToMenu);
|
2014-05-30 08:53:19 +00:00
|
|
|
DeclareReadSetting(bool, FromAutoStart);
|
|
|
|
DeclareSetting(QString, WorkingDir);
|
|
|
|
inline void cForceWorkingDir(const QString &newDir) {
|
|
|
|
cSetWorkingDir(newDir);
|
|
|
|
QDir dir;
|
2014-09-30 14:11:09 +00:00
|
|
|
if (!gWorkingDir.isEmpty()) dir.mkpath(gWorkingDir);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-11-27 18:20:48 +00:00
|
|
|
DeclareReadSetting(QString, ExeName);
|
2014-05-30 08:53:19 +00:00
|
|
|
DeclareReadSetting(QString, ExeDir);
|
|
|
|
DeclareSetting(QString, DialogLastPath);
|
|
|
|
DeclareSetting(QString, DialogHelperPath);
|
|
|
|
inline const QString &cDialogHelperPathFinal() {
|
|
|
|
return cDialogHelperPath().isEmpty() ? cExeDir() : cDialogHelperPath();
|
|
|
|
}
|
|
|
|
DeclareSetting(bool, CtrlEnter);
|
2015-02-03 15:02:46 +00:00
|
|
|
|
|
|
|
typedef QPixmap *QPixmapPointer;
|
|
|
|
DeclareSetting(QPixmapPointer, ChatBackground);
|
|
|
|
DeclareSetting(int32, ChatBackgroundId);
|
|
|
|
DeclareSetting(QPixmapPointer, ChatDogImage);
|
|
|
|
DeclareSetting(bool, TileBackground);
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
DeclareSetting(bool, SoundNotify);
|
2015-08-28 15:15:56 +00:00
|
|
|
DeclareSetting(bool, IncludeMuted);
|
2014-05-30 08:53:19 +00:00
|
|
|
DeclareSetting(bool, NeedConfigResave);
|
|
|
|
DeclareSetting(bool, DesktopNotify);
|
2014-07-18 10:37:34 +00:00
|
|
|
DeclareSetting(DBINotifyView, NotifyView);
|
2014-05-30 08:53:19 +00:00
|
|
|
DeclareSetting(bool, AutoUpdate);
|
|
|
|
|
2015-08-11 19:50:48 +00:00
|
|
|
DeclareSetting(bool, WindowsNotifications);
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
struct TWindowPos {
|
|
|
|
TWindowPos() : moncrc(0), maximized(0), x(0), y(0), w(0), h(0) {
|
|
|
|
}
|
|
|
|
int32 moncrc, maximized;
|
|
|
|
int32 x, y, w, h;
|
|
|
|
};
|
|
|
|
DeclareSetting(TWindowPos, WindowPos);
|
2015-01-15 14:22:15 +00:00
|
|
|
DeclareSetting(bool, SupportTray);
|
2014-05-30 08:53:19 +00:00
|
|
|
DeclareSetting(DBIWorkMode, WorkMode);
|
|
|
|
DeclareSetting(DBIConnectionType, ConnectionType);
|
2015-06-25 18:04:40 +00:00
|
|
|
DeclareSetting(bool, TryIPv6);
|
2014-05-30 08:53:19 +00:00
|
|
|
DeclareSetting(DBIDefaultAttach, DefaultAttach);
|
|
|
|
DeclareSetting(ConnectionProxy, ConnectionProxy);
|
|
|
|
DeclareSetting(bool, SeenTrayTooltip);
|
|
|
|
DeclareSetting(bool, RestartingUpdate);
|
|
|
|
DeclareSetting(bool, Restarting);
|
2014-12-19 21:20:30 +00:00
|
|
|
DeclareSetting(bool, RestartingToSettings);
|
2014-12-02 16:25:17 +00:00
|
|
|
DeclareSetting(bool, WriteProtected);
|
2014-05-30 08:53:19 +00:00
|
|
|
DeclareSetting(int32, LastUpdateCheck);
|
|
|
|
DeclareSetting(bool, NoStartUpdate);
|
|
|
|
DeclareSetting(bool, StartToSettings);
|
|
|
|
DeclareSetting(int32, MaxGroupCount);
|
|
|
|
DeclareSetting(bool, ReplaceEmojis);
|
|
|
|
DeclareReadSetting(bool, ManyInstance);
|
|
|
|
DeclareSetting(bool, AskDownloadPath);
|
|
|
|
DeclareSetting(QString, DownloadPath);
|
|
|
|
DeclareSetting(QByteArray, LocalSalt);
|
|
|
|
DeclareSetting(DBIScale, RealScale);
|
|
|
|
DeclareSetting(DBIScale, ScreenScale);
|
|
|
|
DeclareSetting(DBIScale, ConfigScale);
|
2014-09-20 21:35:46 +00:00
|
|
|
DeclareSetting(bool, CompressPastedImage);
|
2015-02-10 18:55:04 +00:00
|
|
|
DeclareSetting(QString, TimeFormat);
|
|
|
|
|
2015-03-02 12:34:16 +00:00
|
|
|
DeclareSetting(int32, AutoLock);
|
|
|
|
DeclareSetting(bool, HasPasscode);
|
|
|
|
|
2015-06-01 10:58:46 +00:00
|
|
|
DeclareSetting(bool, HasAudioPlayer);
|
|
|
|
DeclareSetting(bool, HasAudioCapture);
|
|
|
|
|
2015-02-10 18:55:04 +00:00
|
|
|
inline void cChangeTimeFormat(const QString &newFormat) {
|
|
|
|
if (!newFormat.isEmpty()) cSetTimeFormat(newFormat);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
inline DBIScale cEvalScale(DBIScale scale) {
|
|
|
|
return (scale == dbisAuto) ? cScreenScale() : scale;
|
|
|
|
}
|
|
|
|
inline DBIScale cScale() {
|
|
|
|
return cEvalScale(cRealScale());
|
|
|
|
}
|
|
|
|
|
2014-11-12 22:35:00 +00:00
|
|
|
template <typename T>
|
|
|
|
T convertScale(T v) {
|
|
|
|
switch (cScale()) {
|
|
|
|
case dbisOneAndQuarter: return qRound(float64(v) * 1.25 - 0.01);
|
|
|
|
case dbisOneAndHalf: return qRound(float64(v) * 1.5 - 0.01);
|
|
|
|
case dbisTwo: return v * 2;
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
DeclareSetting(DBIEmojiTab, EmojiTab);
|
|
|
|
|
|
|
|
struct EmojiData {
|
2015-04-30 13:56:33 +00:00
|
|
|
EmojiData(uint16 x, uint16 y, uint32 code, uint32 code2, uint16 len, uint16 postfix, uint32 color) : x(x), y(y), code(code), code2(code2), len(len), postfix(postfix), color(color) {
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-11-23 21:49:14 +00:00
|
|
|
uint16 x, y;
|
2014-05-30 08:53:19 +00:00
|
|
|
uint32 code, code2;
|
2014-11-23 21:49:14 +00:00
|
|
|
uint16 len;
|
|
|
|
uint16 postfix;
|
2015-04-30 13:56:33 +00:00
|
|
|
uint32 color;
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef const EmojiData *EmojiPtr;
|
2015-04-30 13:56:33 +00:00
|
|
|
static EmojiPtr TwoSymbolEmoji = EmojiPtr(0x01);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
typedef QVector<EmojiPtr> EmojiPack;
|
2015-05-08 12:45:14 +00:00
|
|
|
typedef QVector<QPair<uint32, ushort> > RecentEmojisPreloadOld;
|
|
|
|
typedef QVector<QPair<uint64, ushort> > RecentEmojisPreload;
|
2014-05-30 08:53:19 +00:00
|
|
|
typedef QVector<QPair<EmojiPtr, ushort> > RecentEmojiPack;
|
2015-05-08 12:45:14 +00:00
|
|
|
typedef QMap<uint32, uint64> EmojiColorVariants;
|
|
|
|
DeclareRefSetting(RecentEmojiPack, RecentEmojis);
|
|
|
|
DeclareSetting(RecentEmojisPreload, RecentEmojisPreload);
|
|
|
|
DeclareRefSetting(EmojiColorVariants, EmojiVariants);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-05-08 12:45:14 +00:00
|
|
|
RecentEmojiPack &cGetRecentEmojis();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-01-02 14:55:24 +00:00
|
|
|
struct DocumentData;
|
|
|
|
typedef QVector<DocumentData*> StickerPack;
|
|
|
|
DeclareSetting(QByteArray, StickersHash);
|
2015-01-05 20:17:33 +00:00
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
typedef QList<QPair<DocumentData*, int16> > RecentStickerPackOld;
|
|
|
|
typedef QVector<QPair<uint64, ushort> > RecentStickerPreload;
|
|
|
|
typedef QVector<QPair<DocumentData*, ushort> > RecentStickerPack;
|
|
|
|
DeclareSetting(RecentStickerPreload, RecentStickersPreload);
|
|
|
|
DeclareRefSetting(RecentStickerPack, RecentStickers);
|
|
|
|
|
|
|
|
RecentStickerPack &cGetRecentStickers();
|
|
|
|
|
|
|
|
DeclareSetting(uint64, LastStickersUpdate);
|
|
|
|
|
2015-06-28 12:37:10 +00:00
|
|
|
static const uint64 DefaultStickerSetId = 0; // for backward compatibility
|
|
|
|
static const uint64 CustomStickerSetId = 0xFFFFFFFFFFFFFFFFLLU, RecentStickerSetId = 0xFFFFFFFFFFFFFFFELLU;
|
2015-05-19 15:46:45 +00:00
|
|
|
struct StickerSet {
|
2015-06-28 12:37:10 +00:00
|
|
|
StickerSet(uint64 id, uint64 access, const QString &title, const QString &shortName, int32 count, int32 hash, int32 flags) : id(id), access(access), title(title), shortName(shortName), count(count), hash(hash), flags(flags) {
|
2015-05-19 15:46:45 +00:00
|
|
|
}
|
|
|
|
uint64 id, access;
|
|
|
|
QString title, shortName;
|
2015-06-28 12:37:10 +00:00
|
|
|
int32 count, hash, flags;
|
2015-05-19 15:46:45 +00:00
|
|
|
StickerPack stickers;
|
|
|
|
};
|
|
|
|
typedef QMap<uint64, StickerSet> StickerSets;
|
|
|
|
DeclareRefSetting(StickerSets, StickerSets);
|
2015-05-21 10:44:26 +00:00
|
|
|
typedef QList<uint64> StickerSetsOrder;
|
|
|
|
DeclareRefSetting(StickerSetsOrder, StickerSetsOrder);
|
2015-01-02 14:55:24 +00:00
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
typedef QList<QPair<QString, ushort> > RecentHashtagPack;
|
|
|
|
DeclareSetting(RecentHashtagPack, RecentWriteHashtags);
|
|
|
|
DeclareSetting(RecentHashtagPack, RecentSearchHashtags);
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
DeclareSetting(bool, PasswordRecovered);
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
DeclareSetting(int32, PasscodeBadTries);
|
|
|
|
DeclareSetting(uint64, PasscodeLastTry);
|
|
|
|
|
|
|
|
inline bool passcodeCanTry() {
|
|
|
|
if (cPasscodeBadTries() < 3) return true;
|
|
|
|
uint64 dt = getms(true) - cPasscodeLastTry();
|
|
|
|
switch (cPasscodeBadTries()) {
|
|
|
|
case 3: return dt >= 5000;
|
|
|
|
case 4: return dt >= 10000;
|
|
|
|
case 5: return dt >= 15000;
|
|
|
|
case 6: return dt >= 20000;
|
|
|
|
case 7: return dt >= 25000;
|
|
|
|
}
|
|
|
|
return dt >= 30000;
|
|
|
|
}
|
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
inline void incrementRecentHashtag(RecentHashtagPack &recent, const QString &tag) {
|
|
|
|
RecentHashtagPack::iterator i = recent.begin(), e = recent.end();
|
|
|
|
for (; i != e; ++i) {
|
|
|
|
if (i->first == tag) {
|
|
|
|
++i->second;
|
|
|
|
if (qAbs(i->second) > 0x4000) {
|
|
|
|
for (RecentHashtagPack::iterator j = recent.begin(); j != e; ++j) {
|
|
|
|
if (j->second > 1) {
|
|
|
|
j->second /= 2;
|
|
|
|
} else if (j->second > 0) {
|
|
|
|
j->second = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (; i != recent.begin(); --i) {
|
|
|
|
if (qAbs((i - 1)->second) > qAbs(i->second)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
qSwap(*i, *(i - 1));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == e) {
|
|
|
|
while (recent.size() >= 64) recent.pop_back();
|
|
|
|
recent.push_back(qMakePair(tag, 1));
|
|
|
|
for (i = recent.end() - 1; i != recent.begin(); --i) {
|
|
|
|
if ((i - 1)->second > i->second) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
qSwap(*i, *(i - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-19 21:20:30 +00:00
|
|
|
DeclareSetting(int32, Lang);
|
2014-12-20 21:33:08 +00:00
|
|
|
DeclareSetting(QString, LangFile);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2014-07-18 10:37:34 +00:00
|
|
|
DeclareSetting(QStringList, SendPaths);
|
2014-12-03 13:10:32 +00:00
|
|
|
DeclareSetting(QString, StartUrl);
|
2014-07-18 10:37:34 +00:00
|
|
|
|
2014-12-18 18:40:49 +00:00
|
|
|
DeclareSetting(QString, LangErrors);
|
|
|
|
|
2014-06-14 19:32:11 +00:00
|
|
|
DeclareSetting(bool, Retina);
|
|
|
|
DeclareSetting(float64, RetinaFactor);
|
2014-06-15 12:31:03 +00:00
|
|
|
DeclareSetting(int32, IntRetinaFactor);
|
2014-06-14 19:32:11 +00:00
|
|
|
DeclareSetting(bool, CustomNotifies);
|
|
|
|
|
2014-06-16 09:31:10 +00:00
|
|
|
DeclareReadSetting(uint64, Instance);
|
|
|
|
|
2014-06-14 19:32:11 +00:00
|
|
|
DeclareReadSetting(DBIPlatform, Platform);
|
2014-06-25 07:25:55 +00:00
|
|
|
DeclareReadSetting(QUrl, UpdateURL);
|
2014-06-14 19:32:11 +00:00
|
|
|
|
2014-11-25 12:15:29 +00:00
|
|
|
DeclareSetting(bool, ContactsReceived);
|
2015-06-15 17:19:24 +00:00
|
|
|
DeclareSetting(bool, DialogsReceived);
|
2014-11-25 12:15:29 +00:00
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
DeclareSetting(bool, WideMode);
|
|
|
|
|
2015-01-26 13:04:41 +00:00
|
|
|
DeclareSetting(int, OnlineUpdatePeriod);
|
|
|
|
DeclareSetting(int, OfflineBlurTimeout);
|
|
|
|
DeclareSetting(int, OfflineIdleTimeout);
|
|
|
|
DeclareSetting(int, OnlineFocusTimeout);
|
|
|
|
DeclareSetting(int, OnlineCloudTimeout);
|
|
|
|
DeclareSetting(int, NotifyCloudDelay);
|
|
|
|
DeclareSetting(int, NotifyDefaultDelay);
|
|
|
|
|
|
|
|
DeclareSetting(int, OtherOnline);
|
|
|
|
|
2015-07-03 08:47:16 +00:00
|
|
|
DeclareSetting(float64, SongVolume);
|
|
|
|
|
2015-08-07 12:11:50 +00:00
|
|
|
struct PeerData;
|
|
|
|
typedef QMap<PeerData*, QDateTime> SavedPeers;
|
|
|
|
typedef QMultiMap<QDateTime, PeerData*> SavedPeersByTime;
|
|
|
|
DeclareRefSetting(SavedPeers, SavedPeers);
|
|
|
|
DeclareRefSetting(SavedPeersByTime, SavedPeersByTime);
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void settingsParseArgs(int argc, char *argv[]);
|