tdesktop/Telegram/SourceFiles/storage/localstorage.h

206 lines
4.8 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "storage/file_download.h"
#include "storage/cache/storage_cache_database.h"
#include "storage/localimageloader.h"
#include "auth_session.h"
2019-01-16 17:26:26 +00:00
namespace Data {
2019-01-28 13:59:49 +00:00
class WallPaper;
2019-01-16 17:26:26 +00:00
} // namespace Data
namespace Lang {
struct Language;
} // namespace Lang
namespace Storage {
class EncryptionKey;
} // namespace Storage
namespace Window {
namespace Theme {
struct Saved;
} // namespace Theme
} // namespace Window
2018-06-22 21:32:00 +00:00
namespace Export {
struct Settings;
} // namespace Export
2016-09-15 19:15:49 +00:00
namespace Local {
2016-09-15 19:15:49 +00:00
void start();
void finish();
2016-09-15 19:15:49 +00:00
void readSettings();
void writeSettings();
void writeUserSettings();
void writeMtpData();
2018-05-03 06:39:10 +00:00
void writeAutoupdatePrefix(const QString &prefix);
QString readAutoupdatePrefix();
2016-09-15 19:15:49 +00:00
void reset();
2016-09-15 19:15:49 +00:00
bool checkPasscode(const QByteArray &passcode);
void setPasscode(const QByteArray &passcode);
2016-09-15 19:15:49 +00:00
enum ClearManagerTask {
ClearManagerAll = 0xFFFF,
ClearManagerDownloads = 0x01,
ClearManagerStorage = 0x02,
};
2016-09-15 19:15:49 +00:00
struct ClearManagerData;
class ClearManager : public QObject {
Q_OBJECT
2016-09-15 19:15:49 +00:00
public:
ClearManager();
bool addTask(int task);
bool hasTask(ClearManagerTask task);
void start();
void stop();
2016-09-15 19:15:49 +00:00
signals:
void succeed(int task, void *manager);
void failed(int task, void *manager);
2016-09-15 19:15:49 +00:00
private slots:
void onStart();
2016-09-15 19:15:49 +00:00
private:
~ClearManager();
2016-09-15 19:15:49 +00:00
ClearManagerData *data;
2016-09-15 19:15:49 +00:00
};
enum ReadMapState {
ReadMapFailed = 0,
ReadMapDone = 1,
ReadMapPassNeeded = 2,
};
ReadMapState readMap(const QByteArray &pass);
int32 oldMapVersion();
int32 oldSettingsVersion();
struct MessageDraft {
MessageDraft(MsgId msgId = 0, TextWithTags textWithTags = TextWithTags(), bool previewCancelled = false)
: msgId(msgId)
, textWithTags(textWithTags)
, previewCancelled(previewCancelled) {
}
MsgId msgId;
TextWithTags textWithTags;
bool previewCancelled;
};
void writeDrafts(const PeerId &peer, const MessageDraft &localDraft, const MessageDraft &editDraft);
void readDraftsWithCursors(History *h);
void writeDraftCursors(const PeerId &peer, const MessageCursor &localCursor, const MessageCursor &editCursor);
bool hasDraftCursors(const PeerId &peer);
bool hasDraft(const PeerId &peer);
void writeFileLocation(MediaKey location, const FileLocation &local);
FileLocation readFileLocation(MediaKey location, bool check = true);
QString cachePath();
Storage::EncryptionKey cacheKey();
Storage::Cache::Database::Settings cacheSettings();
void updateCacheSettings(Storage::Cache::Database::SettingsUpdate &update);
2016-09-15 19:15:49 +00:00
void countVoiceWaveform(DocumentData *document);
void cancelTask(TaskId id);
void writeInstalledStickers();
void writeFeaturedStickers();
void writeRecentStickers();
void writeFavedStickers();
2016-09-15 19:15:49 +00:00
void writeArchivedStickers();
void readInstalledStickers();
void readFeaturedStickers();
void readRecentStickers();
void readFavedStickers();
2016-09-15 19:15:49 +00:00
void readArchivedStickers();
int32 countStickersHash(bool checkOutdatedInfo = false);
int32 countRecentStickersHash();
int32 countFavedStickersHash();
2016-09-15 19:15:49 +00:00
int32 countFeaturedStickersHash();
void writeSavedGifs();
void readSavedGifs();
int32 countSavedGifsHash();
2019-01-16 17:26:26 +00:00
void writeBackground(const Data::WallPaper &paper, const QImage &img);
2016-09-15 19:15:49 +00:00
bool readBackground();
void writeTheme(const Window::Theme::Saved &saved);
void clearTheme();
bool copyThemeColorsToPalette(const QString &file);
Window::Theme::Saved readThemeAfterSwitch();
void writeLangPack();
void pushRecentLanguage(const Lang::Language &language);
std::vector<Lang::Language> readRecentLanguages();
void saveRecentLanguages(const std::vector<Lang::Language> &list);
void removeRecentLanguage(const QString &id);
2016-09-15 19:15:49 +00:00
void writeRecentHashtagsAndBots();
void readRecentHashtagsAndBots();
void saveRecentSentHashtags(const QString &text);
void saveRecentSearchHashtags(const QString &text);
2016-09-15 19:15:49 +00:00
2018-06-22 21:32:00 +00:00
void WriteExportSettings(const Export::Settings &settings);
Export::Settings ReadExportSettings();
2016-09-15 19:15:49 +00:00
void addSavedPeer(PeerData *peer, const QDateTime &position);
void removeSavedPeer(PeerData *peer);
void readSavedPeers();
void writeReportSpamStatuses();
2018-09-11 14:36:09 +00:00
void writeSelf();
void readSelf(const QByteArray &serialized, int32 streamVersion);
2016-09-15 19:15:49 +00:00
void makeBotTrusted(UserData *bot);
bool isBotTrusted(UserData *bot);
bool encrypt(const void *src, void *dst, uint32 len, const void *key128);
bool decrypt(const void *src, void *dst, uint32 len, const void *key128);
namespace internal {
class Manager : public QObject {
Q_OBJECT
public:
Manager();
void writeMap(bool fast);
void writingMap();
void writeLocations(bool fast);
void writingLocations();
void finish();
2016-11-24 19:28:23 +00:00
public slots:
2016-09-15 19:15:49 +00:00
void mapWriteTimeout();
void locationsWriteTimeout();
private:
QTimer _mapWriteTimer;
QTimer _locationsWriteTimer;
};
2016-09-15 19:15:49 +00:00
} // namespace internal
} // namespace Local