25 return left.IsHidden_ == right.IsHidden_ &&
26 left.Type_ == right.Type_ &&
27 left.Name_ == right.Name_ &&
28 left.GenericName_ == right.GenericName_ &&
29 left.Comments_ == right.Comments_ &&
30 left.Categories_ == right.Categories_ &&
31 left.Command_ == right.Command_ &&
32 left.WD_ == right.WD_ &&
33 left.IconName_ == right.IconName_;
38 return !(left == right);
43 return !Name_.isEmpty ();
57 command.remove (QStringLiteral (
"%c"));
58 command.remove (QStringLiteral (
"%f"));
59 command.remove (QStringLiteral (
"%F"));
60 command.remove (QStringLiteral (
"%u"));
61 command.remove (QStringLiteral (
"%U"));
62 command.remove (QStringLiteral (
"%i"));
63 auto items = command.split (
' ', Qt::SkipEmptyParts);
64 auto removePred = [] (
const QString& str)
65 {
return str.size () == 2 && str.at (0) ==
'%'; };
66 items.erase (std::remove_if (items.begin (), items.end (), removePred),
78 proxy->GetEntityManager ()->HandleEntity (e);
82 qWarning () << Q_FUNC_INFO
83 <<
"don't know how to execute this type of app";
89 QString ByLang (
const QHash<QString, QString>& cont,
const QString& lang)
91 return cont.value (cont.contains (lang) ? lang : QString ());
97 return ByLang (Name_, lang);
102 return ByLang (GenericName_, lang);
107 return ByLang (Comments_, lang);
147 if (name.endsWith (
".png"_ql) || name.endsWith (
".svg"_ql))
150 auto result = proxy->GetIconThemeManager ()->GetIcon (name);
151 if (!result.isNull ())
155 if (!result.isNull ())
158 qDebug () << Q_FUNC_INFO << name <<
"not found";
174 dbg.nospace () <<
"DesktopItem\n{\n\tNames: " << Name_
175 <<
"\n\tGenericNames: " << GenericName_
176 <<
"\n\tComments: " << Comments_
177 <<
"\n\tCategories: " << Categories_
178 <<
"\n\tCommand: " << Command_
179 <<
"\n\tWorkingDir: " << WD_
180 <<
"\n\tIconName: " << IconName_
181 <<
"\n\tHidden: " << IsHidden_
188 QHash<QString, QString> FirstValues (
const QHash<QString, QStringList>& hash)
190 QHash<QString, QString> result;
192 result [key] = values.value (0);
199 QFile file (filename);
200 if (!file.open (QIODevice::ReadOnly))
201 throw std::runtime_error (
"Unable to open file");
204 const auto& group = result [QStringLiteral (
"Desktop Entry")];
206 const auto& item = std::make_shared<Item> ();
207 item->Name_ = FirstValues (group [QStringLiteral (
"Name")]);
208 item->GenericName_ = FirstValues (group [QStringLiteral (
"GenericName")]);
209 item->Comments_ = FirstValues (group [QStringLiteral (
"Comment")]);
211 item->Categories_ = group [QStringLiteral (
"Categories")] [{}];
213 auto getSingle = [&group] (
const QString& name) {
return group [name] [{}].value (0); };
215 item->IconName_ = getSingle (QStringLiteral (
"Icon"));
217 const auto& typeStr = getSingle (QStringLiteral (
"Type"));
218 if (typeStr ==
"Application"_ql)
221 item->Command_ = getSingle (QStringLiteral (
"Exec"));
222 item->WD_ = getSingle (QStringLiteral (
"Path"));
224 else if (typeStr ==
"URL"_ql)
227 item->Command_ = getSingle (QStringLiteral (
"URL"));
229 else if (typeStr ==
"Directory"_ql)
234 item->IsHidden_ = getSingle (QStringLiteral (
"NoDisplay")).toLower () ==
"true"_ql;
Type GetType() const
Returns the type of this item.
QString GetCommand() const
Returns type type-specific command for this item.
QString GetGenericName(const QString &language) const
Returns the generic name of this item.
QIcon GetAppIcon(const QString &name)
A parser for XDG .desktop files.
bool operator==(const Item &left, const Item &right)
auto Stlize(Assoc &&assoc) noexcept
Converts an Qt's associative sequence assoc to an STL-like iteratable range.
QString GetPermanentID() const
Returns the permanent ID of this item.
Entity MakeEntity(const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
A shortcut to an application.
Type
Describes the various types of XDG .desktop files.
QDebug operator<<(QDebug dbg, const Item &item)
Serializes item contents to the debugging stream.
QString GetIconName() const
Returns the name of the icon for this item.
bool IsValid() const
Checks whether this XDG item is valid.
Describes a single XDG .desktop entry.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
QString GetName(const QString &language) const
Returns the name of this item.
QStringList GetCategories() const
Returns the categories where this item belongs.
bool operator!=(const Item &left, const Item &right)
std::shared_ptr< Item > Item_ptr
QDebug DebugPrint(QDebug stream) const
Serializes item contents to the debugging stream.
QIcon GetIcon(const ICoreProxy_ptr &) const
Returns the icon previously set by SetIcon().
A shortcut to a directory.
QString GetWorkingDirectory() const
Returns the working directory for command execution.
QString GetComment(const QString &language) const
Returns the comment of this item.
bool IsHidden() const
Checks whether this XDG item should be hidden.
static Item_ptr FromDesktopFile(const QString &file)
Loads the XDG .desktop item from file.
void Execute(const ICoreProxy_ptr &proxy) const
Executes this item, if possible.