/* 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 "base/invoke_queued.h" #include "base/timer.h" #include "base/weak_ptr.h" #include "core/current_geo_location.h" #include "mtproto/sender.h" #include "webview/webview_common.h" namespace Data { struct InputVenue; } // namespace Data namespace Main { class Session; class SessionShow; } // namespace Main namespace Webview { class Window; } // namespace Webview namespace Ui { class SeparatePanel; class RpWidget; class ScrollArea; struct LocationInfo { float64 lat = 0.; float64 lon = 0.; }; struct PickerVenueLoading { friend inline bool operator==( PickerVenueLoading, PickerVenueLoading) = default; }; struct PickerVenueNothingFound { QString query; friend inline bool operator==( const PickerVenueNothingFound&, const PickerVenueNothingFound&) = default; }; struct PickerVenueWaitingForLocation { friend inline bool operator==( PickerVenueWaitingForLocation, PickerVenueWaitingForLocation) = default; }; struct PickerVenueList { std::vector list; friend inline bool operator==( const PickerVenueList&, const PickerVenueList&) = default; }; using PickerVenueState = std::variant< PickerVenueLoading, PickerVenueNothingFound, PickerVenueWaitingForLocation, PickerVenueList>; class LocationPicker final : public base::has_weak_ptr { public: struct Descriptor { RpWidget *parent = nullptr; not_null session; Fn callback; Fn quit; Webview::StorageId storageId; rpl::producer<> closeRequests; }; [[nodiscard]] static bool Available( const QString &mapsToken, const QString &geocodingToken); static not_null Show(Descriptor &&descriptor); void close(); void minimize(); void quit(); private: struct VenuesCacheEntry { Core::GeoLocation location; PickerVenueList result; }; explicit LocationPicker(Descriptor &&descriptor); [[nodiscard]] std::shared_ptr uiShow(); void setup(const Descriptor &descriptor); void setupWindow(const Descriptor &descriptor); void setupWebview(const Descriptor &descriptor); void processKey(const QString &key, const QString &modifier); void resolveCurrentLocation(); void resolveAddressByTimer(); void resolveAddress(Core::GeoLocation location); void mapReady(); void venuesRequest(Core::GeoLocation location, QString query = {}); void venuesSendRequest(); rpl::lifetime _lifetime; Fn _callback; Fn _quit; std::unique_ptr _window; not_null _body; RpWidget *_container = nullptr; ScrollArea *_scroll = nullptr; std::unique_ptr _webview; SingleQueuedInvokation _updateStyles; bool _subscribedToColors = false; base::Timer _geocoderResolveTimer; Core::GeoLocation _geocoderResolvePostponed; Core::GeoLocation _geocoderResolvingFor; QString _geocoderSavedAddress; rpl::variable _geocoderAddress; rpl::variable _venueState; const not_null _session; MTP::Sender _api; UserData *_venuesBot = nullptr; mtpRequestId _venuesBotRequestId = 0; mtpRequestId _venuesRequestId = 0; Core::GeoLocation _venuesRequestLocation; QString _venuesRequestQuery; base::flat_map> _venuesCache; }; } // namespace Ui