attach_extensions.cpp 897 B

123456789101112131415161718192021222324252627282930
  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 "ui/chat/attach/attach_extensions.h"
  8. #include <QtCore/QMimeDatabase>
  9. #include <QtGui/QImageReader>
  10. namespace Ui {
  11. const QStringList &ImageExtensions() {
  12. static const auto result = [] {
  13. const auto formats = QImageReader::supportedImageFormats();
  14. return formats | ranges::views::transform([](const auto &format) {
  15. return '.' + format.toLower();
  16. }) | ranges::views::filter([](const auto &format) {
  17. const auto mimes = QMimeDatabase().mimeTypesForFileName(
  18. u"test"_q + format);
  19. return !mimes.isEmpty()
  20. && mimes.front().name().startsWith(u"image/"_q);
  21. }) | ranges::to<QStringList>;
  22. }();
  23. return result;
  24. }
  25. } // namespace Ui