2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-24 19:27:17 +00:00

176 lines
4.5 KiB
C
Raw Normal View History

2024-07-04 12:18:30 +04:00
/*
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"
2024-07-11 16:31:33 +02:00
#include "base/timer.h"
2024-07-04 12:18:30 +04:00
#include "base/weak_ptr.h"
2024-07-07 21:01:26 +04:00
#include "core/current_geo_location.h"
#include "mtproto/sender.h"
2024-07-04 12:18:30 +04:00
#include "webview/webview_common.h"
2024-07-07 21:01:26 +04:00
namespace Data {
struct InputVenue;
} // namespace Data
namespace Main {
class Session;
class SessionShow;
} // namespace Main
2024-07-04 12:18:30 +04:00
namespace Webview {
class Window;
} // namespace Webview
namespace Ui {
2024-07-26 17:23:41 +02:00
class AbstractButton;
2024-07-07 15:10:35 +04:00
class SeparatePanel;
2024-07-04 12:18:30 +04:00
class RpWidget;
2024-07-07 21:01:26 +04:00
class ScrollArea;
2024-07-12 15:07:21 +02:00
class VerticalLayout;
template <typename Widget>
class SlideWrap;
2024-07-04 12:18:30 +04:00
2024-07-07 21:01:26 +04:00
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<Data::InputVenue> list;
friend inline bool operator==(
const PickerVenueList&,
const PickerVenueList&) = default;
};
using PickerVenueState = std::variant<
PickerVenueLoading,
PickerVenueNothingFound,
PickerVenueWaitingForLocation,
PickerVenueList>;
2024-07-12 12:23:47 +02:00
struct LocationPickerConfig {
QString mapsToken;
QString geoToken;
};
2024-07-04 12:18:30 +04:00
class LocationPicker final : public base::has_weak_ptr {
public:
struct Descriptor {
RpWidget *parent = nullptr;
2024-07-12 12:23:47 +02:00
LocationPickerConfig config;
rpl::producer<QString> chooseLabel;
2024-07-12 17:00:16 +02:00
PeerData *recipient = nullptr;
2024-07-07 21:01:26 +04:00
not_null<Main::Session*> session;
Core::GeoLocation initial;
2024-07-12 12:23:47 +02:00
Fn<void(Data::InputVenue)> callback;
2024-07-04 12:18:30 +04:00
Fn<void()> quit;
Webview::StorageId storageId;
rpl::producer<> closeRequests;
};
2024-07-12 12:23:47 +02:00
[[nodiscard]] static bool Available(const LocationPickerConfig &config);
2024-07-04 12:18:30 +04:00
static not_null<LocationPicker*> Show(Descriptor &&descriptor);
2024-07-26 17:23:41 +02:00
void activate();
2024-07-04 12:18:30 +04:00
void close();
void minimize();
void quit();
private:
2024-07-07 21:01:26 +04:00
struct VenuesCacheEntry {
Core::GeoLocation location;
PickerVenueList result;
};
2024-07-04 12:18:30 +04:00
explicit LocationPicker(Descriptor &&descriptor);
2024-07-07 21:01:26 +04:00
[[nodiscard]] std::shared_ptr<Main::SessionShow> uiShow();
2024-07-04 12:18:30 +04:00
void setup(const Descriptor &descriptor);
void setupWindow(const Descriptor &descriptor);
2024-07-26 17:23:41 +02:00
void setupWebview();
2024-07-04 12:18:30 +04:00
void processKey(const QString &key, const QString &modifier);
void resolveCurrentLocation();
2024-07-11 16:31:33 +02:00
void resolveAddressByTimer();
2024-07-07 21:01:26 +04:00
void resolveAddress(Core::GeoLocation location);
void mapReady();
2024-07-12 15:07:21 +02:00
bool venuesFromCache(Core::GeoLocation location, QString query = {});
2024-07-07 21:01:26 +04:00
void venuesRequest(Core::GeoLocation location, QString query = {});
void venuesSendRequest();
2024-07-12 15:07:21 +02:00
void venuesApplyResults(PickerVenueList venues);
void venuesSearchEnableAt(Core::GeoLocation location);
void venuesSearchChanged(const std::optional<QString> &query);
2024-07-04 12:18:30 +04:00
2024-07-12 12:23:47 +02:00
LocationPickerConfig _config;
Fn<void(Data::InputVenue)> _callback;
2024-07-04 12:18:30 +04:00
Fn<void()> _quit;
2024-07-07 15:10:35 +04:00
std::unique_ptr<SeparatePanel> _window;
not_null<RpWidget*> _body;
2024-07-04 12:18:30 +04:00
RpWidget *_container = nullptr;
2024-07-26 17:23:41 +02:00
RpWidget *_mapPlaceholder = nullptr;
RpWidget *_mapLoading = nullptr;
AbstractButton *_mapButton = nullptr;
2024-07-12 15:07:21 +02:00
SlideWrap<VerticalLayout> *_mapControlsWrap = nullptr;
2024-07-26 17:23:41 +02:00
rpl::variable<QString> _chooseButtonLabel;
2024-07-07 21:01:26 +04:00
ScrollArea *_scroll = nullptr;
2024-07-26 17:23:41 +02:00
Webview::StorageId _webviewStorageId;
2024-07-04 12:18:30 +04:00
std::unique_ptr<Webview::Window> _webview;
SingleQueuedInvokation _updateStyles;
2024-07-16 18:13:17 +02:00
Core::GeoLocation _initialProvided;
2024-07-26 17:23:41 +02:00
int _mapPlaceholderAdded = 0;
2024-07-04 12:18:30 +04:00
bool _subscribedToColors = false;
2024-07-11 16:31:33 +02:00
base::Timer _geocoderResolveTimer;
Core::GeoLocation _geocoderResolvePostponed;
2024-07-07 21:01:26 +04:00
Core::GeoLocation _geocoderResolvingFor;
2024-07-11 18:15:17 +02:00
QString _geocoderSavedAddress;
2024-07-07 21:01:26 +04:00
rpl::variable<QString> _geocoderAddress;
rpl::variable<PickerVenueState> _venueState;
const not_null<Main::Session*> _session;
2024-07-12 15:07:21 +02:00
std::optional<Core::GeoLocation> _venuesSearchLocation;
std::optional<QString> _venuesSearchQuery;
base::Timer _venuesSearchDebounceTimer;
2024-07-07 21:01:26 +04:00
MTP::Sender _api;
2024-07-12 17:00:16 +02:00
PeerData *_venueRecipient = nullptr;
2024-07-07 21:01:26 +04:00
UserData *_venuesBot = nullptr;
mtpRequestId _venuesBotRequestId = 0;
mtpRequestId _venuesRequestId = 0;
Core::GeoLocation _venuesRequestLocation;
QString _venuesRequestQuery;
2024-07-12 15:07:21 +02:00
QString _venuesInitialQuery;
2024-07-07 21:01:26 +04:00
base::flat_map<QString, std::vector<VenuesCacheEntry>> _venuesCache;
2024-07-12 15:07:21 +02:00
Core::GeoLocation _venuesNoSearchLocation;
rpl::variable<bool> _venuesSearchShown = false;
2024-07-07 21:01:26 +04:00
2024-07-12 12:23:47 +02:00
rpl::lifetime _lifetime;
2024-07-04 12:18:30 +04:00
};
} // namespace Ui