34 #include <QFutureWatcher>
35 #include <QtConcurrentRun>
53 QTimer::singleShot (1000,
this, SLOT (update ()));
68 for (
const auto& list : Items_)
70 const auto pos = std::find_if (list.begin (), list.end (),
71 [&id] (
Item_ptr item) {
return item->GetPermanentID () == id; });
72 if (pos != list.end ())
81 QStringList ScanDir (
const QString& path)
83 const auto& infos = QDir (path).entryInfoList (QStringList (
"*.desktop"),
84 QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot);
86 for (
const auto& info : infos)
87 result += info.isDir () ?
88 ScanDir (info.absoluteFilePath ()) :
89 QStringList (info.absoluteFilePath ());
98 if (name.endsWith (
".png") || name.endsWith (
".svg"))
101 auto result = proxy->GetIconThemeManager ()->GetIcon (name);
102 if (!result.isNull ())
106 if (!result.isNull ())
109 qDebug () << Q_FUNC_INFO << name <<
"not found";
116 for (
const auto& list : items)
117 for (
auto item : list)
118 if (item->GetIcon ().isNull ())
119 item->SetIcon (GetIconDevice (proxy, item->GetIconName ()));
127 for (
const auto& dir :
ToPaths (types))
128 paths << ScanDir (dir);
130 for (
const auto& path : paths)
137 catch (
const std::exception& e)
139 qWarning () << Q_FUNC_INFO
146 if (!item->IsValid ())
148 qWarning () << Q_FUNC_INFO
154 for (
const auto& cat : item->GetCategories ())
155 if (!cat.startsWith (
"X-"))
156 result [cat] << item;
168 Items_ = FindAndParse (Types_);
170 FixIcons (Items_, Proxy_);
176 ExecuteFuture ([
this] {
return QtConcurrent::run (FindAndParse, Types_); },
179 if (result == Items_)
182 Items_ = std::move (result);
183 FixIcons (Items_, Proxy_);
Cat2Items_t GetItems() const
Returns the categorized list of XDG items.
ItemsFinder(ICoreProxy_ptr, const QList< Type > &types, QObject *parent=nullptr)
Constructs the items finder for the given types.
std::shared_ptr< Item > Item_ptr
void update()
Updates the list of items.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
static Item_ptr FromDesktopFile(const QString &file)
Loads the XDG .desktop item from file.
QSet< QString > ToPaths(Type type)
QHash< QString, QList< Item_ptr > > Cat2Items_t
Item_ptr FindItem(const QString &permanentID) const
Finds an XDG item for the given permanent ID.
bool IsReady() const
Checks whether this items finder is ready.
void itemsListChanged()
Notifies when the list of items changes in any way.
QIcon GetAppIcon(const QString &name)
void ExecuteFuture(Executor f, ResultHandler rh, QObject *parent, Args...args)
Runs a QFuture-returning function and feeding the future to a handler when it is ready.