LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
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 
15 namespace LC::Util::XDG
16 {
17  namespace
18  {
19  QStringList ToPathsImpl (Type type)
20  {
21  switch (type)
22  {
23  case Type::Application:
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 }
QList< Type >
LC::Util::XDG::Type::Other
@ Other
Unknown type.
LC::Util::XDG::Type::Application
@ Application
A shortcut to an application.
LC::Util::XDG::Type
Type
Describes the various types of XDG .desktop files.
Definition: itemtypes.h:23
itemtypes.h
LC::Util::XDG
Definition: desktopparser.cpp:15
LC::Util::XDG::ToPaths
QStringList ToPaths(const QList< Type > &types)
Returns a set of typical directories with desktop files of the given types.
Definition: itemtypes.cpp:66
prelude.h
LC::Util::XDG::Type::URL
@ URL
A shortcut to an URL.
LC::Util::XDG::Type::Dir
@ Dir
A shortcut to a directory.
LC::Util::ConcatMap
auto ConcatMap(Cont &&c, F &&f)
Definition: prelude.h:190