current_geo_location.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. namespace Core {
  9. enum class GeoLocationAccuracy : uchar {
  10. Exact,
  11. Country,
  12. Failed,
  13. };
  14. struct GeoLocation {
  15. QPointF point;
  16. QRectF bounds;
  17. GeoLocationAccuracy accuracy = GeoLocationAccuracy::Failed;
  18. [[nodiscard]] bool exact() const {
  19. return accuracy == GeoLocationAccuracy::Exact;
  20. }
  21. [[nodiscard]] bool country() const {
  22. return accuracy == GeoLocationAccuracy::Country;
  23. }
  24. [[nodiscard]] bool failed() const {
  25. return accuracy == GeoLocationAccuracy::Failed;
  26. }
  27. explicit operator bool() const {
  28. return !failed();
  29. }
  30. };
  31. [[nodiscard]] bool AreTheSame(const GeoLocation &a, const GeoLocation &b);
  32. struct GeoAddress {
  33. QString name;
  34. [[nodiscard]] bool empty() const {
  35. return name.isEmpty();
  36. }
  37. explicit operator bool() const {
  38. return !empty();
  39. }
  40. };
  41. [[nodiscard]] GeoLocation ResolveCurrentCountryLocation();
  42. void ResolveCurrentGeoLocation(Fn<void(GeoLocation)> callback);
  43. void ResolveLocationAddress(
  44. const GeoLocation &location,
  45. const QString &language,
  46. const QString &token,
  47. Fn<void(GeoAddress)> callback);
  48. } // namespace Core