spellchecker_common.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #ifndef TDESKTOP_DISABLE_SPELLCHECK
  9. #include "storage/storage_cloud_blob.h"
  10. #include "base/unique_qptr.h"
  11. namespace Main {
  12. class Session;
  13. } // namespace Main
  14. namespace Spellchecker {
  15. struct Dict : public Storage::CloudBlob::Blob {
  16. };
  17. int64 GetDownloadSize(int id);
  18. MTP::DedicatedLoader::Location GetDownloadLocation(int id);
  19. [[nodiscard]] QString DictionariesPath();
  20. [[nodiscard]] QString DictPathByLangId(int langId);
  21. bool UnpackDictionary(const QString &path, int langId);
  22. [[nodiscard]] bool DictionaryExists(int langId);
  23. bool RemoveDictionary(int langId);
  24. [[nodiscard]] bool IsEn(int langId);
  25. bool WriteDefaultDictionary();
  26. std::vector<Dict> Dictionaries();
  27. void Start(not_null<Main::Session*> session);
  28. [[nodiscard]] rpl::producer<QString> ButtonManageDictsState(
  29. not_null<Main::Session*> session);
  30. std::vector<int> DefaultLanguages();
  31. class DictLoader : public Storage::CloudBlob::BlobLoader {
  32. public:
  33. DictLoader(
  34. QObject *parent,
  35. not_null<Main::Session*> session,
  36. int id,
  37. MTP::DedicatedLoader::Location location,
  38. const QString &folder,
  39. int64 size,
  40. Fn<void()> destroyCallback);
  41. void destroy() override;
  42. rpl::lifetime &lifetime() {
  43. return _lifetime;
  44. }
  45. private:
  46. void unpack(const QString &path) override;
  47. void fail() override;
  48. // Be sure to always call it in the main thread.
  49. Fn<void()> _destroyCallback;
  50. rpl::lifetime _lifetime;
  51. };
  52. std::shared_ptr<base::unique_qptr<DictLoader>> GlobalLoader();
  53. rpl::producer<int> GlobalLoaderChanged();
  54. } // namespace Spellchecker
  55. #endif // !TDESKTOP_DISABLE_SPELLCHECK