LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
itemtypes.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "itemtypes.h"
10#include <QStringList>
11#include <QDir>
12#include <QtDebug>
13#include <util/sll/prelude.h>
14
15namespace LC::Util::XDG
16{
17 namespace
18 {
19 QStringList ToPathsImpl (Type type)
20 {
21 switch (type)
22 {
24 case Type::Dir:
25 case Type::URL:
26 return
27 {
28 QStringLiteral ("/usr/share/applications"),
29 QStringLiteral ("/usr/local/share/applications")
30 };
31 case Type::Other:
32 return {};
33 }
34
35 qWarning () << Q_FUNC_INFO
36 << "unknown type"
37 << static_cast<int> (type);
38 return {};
39 }
40
41 QStringList Recurse (const QString& path)
42 {
43 const auto& infos = QDir { path }.entryInfoList (QDir::AllDirs | QDir::NoDotAndDotDot);
44
45 QStringList result { path };
46 result += Util::ConcatMap (infos,
47 [] (const QFileInfo& info)
48 {
49 return Recurse (info.absoluteFilePath ());
50 });
51 return result;
52 }
53
54 QStringList ToPathsRecurse (Type type)
55 {
56 return Util::ConcatMap (ToPathsImpl (type), Recurse);
57 }
58 }
59
60 QStringList ToPaths (const QList<Type>& types)
61 {
62 return Util::ConcatMap (types, ToPathsRecurse);
63 }
64}
Type
Describes the various types of XDG .desktop files.
Definition itemtypes.h:24
@ Dir
A shortcut to a directory.
Definition itemtypes.h:39
@ Other
Unknown type.
Definition itemtypes.h:27
@ Application
A shortcut to an application.
Definition itemtypes.h:31
@ URL
A shortcut to an URL.
Definition itemtypes.h:35
QStringList ToPaths(const QList< Type > &types)
Returns a set of typical directories with desktop files of the given types.
Definition itemtypes.cpp:60
auto ConcatMap(Cont &&c, F &&f)
Definition prelude.h:168