location_pickers.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #include "data/components/location_pickers.h"
  8. #include "api/api_common.h"
  9. #include "ui/controls/location_picker.h"
  10. namespace Data {
  11. struct LocationPickers::Entry {
  12. Api::SendAction action;
  13. base::weak_ptr<Ui::LocationPicker> picker;
  14. };
  15. LocationPickers::LocationPickers() = default;
  16. LocationPickers::~LocationPickers() = default;
  17. Ui::LocationPicker *LocationPickers::lookup(const Api::SendAction &action) {
  18. for (auto i = begin(_pickers); i != end(_pickers);) {
  19. if (const auto strong = i->picker.get()) {
  20. if (i->action == action) {
  21. return i->picker.get();
  22. }
  23. ++i;
  24. } else {
  25. i = _pickers.erase(i);
  26. }
  27. }
  28. return nullptr;
  29. }
  30. void LocationPickers::emplace(
  31. const Api::SendAction &action,
  32. not_null<Ui::LocationPicker*> picker) {
  33. _pickers.push_back({ action, picker });
  34. }
  35. } // namespace Data