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
145 if (!item->IsValid ())
147 qWarning () << Q_FUNC_INFO
153 for (
const auto& cat : item->GetCategories ())
154 if (!cat.startsWith (
"X-"))
155 result [cat] << item;
167 Items_ = FindAndParse (Types_);
169 FixIcons (Items_, Proxy_);
177 SIGNAL (finished ()),
179 SLOT (handleScanParseFinished ()));
180 watcher->setFuture (QtConcurrent::run (FindAndParse, Types_));
183 void ItemsFinder::handleScanParseFinished ()
186 auto result = watcher->result ();
187 watcher->deleteLater ();
188 if (result == Items_)
191 Items_ = std::move (result);
192 FixIcons (Items_, Proxy_);
Cat2Items_t GetItems() const
std::shared_ptr< Item > Item_ptr
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
static Item_ptr FromDesktopFile(const QString &)
QSet< QString > ToPaths(Type type)
QHash< QString, QList< Item_ptr > > Cat2Items_t
Item_ptr FindItem(const QString &permanentID) const
QIcon GetAppIcon(const QString &name)
ItemsFinder(ICoreProxy_ptr, const QList< Type > &, QObject *=0)