47 return left.IsHidden_ == right.IsHidden_ &&
48 left.Type_ == right.Type_ &&
49 left.Name_ == right.Name_ &&
50 left.GenericName_ == right.GenericName_ &&
51 left.Comments_ == right.Comments_ &&
52 left.Categories_ == right.Categories_ &&
53 left.Command_ == right.Command_ &&
54 left.WD_ == right.WD_ &&
55 left.IconName_ == right.IconName_;
60 return !Name_.isEmpty ();
74 command.remove (
"%c");
75 command.remove (
"%f");
76 command.remove (
"%F");
77 command.remove (
"%u");
78 command.remove (
"%U");
79 command.remove (
"%i");
80 auto items = command.split (
' ', QString::SkipEmptyParts);
81 auto removePred = [] (
const QString& str)
82 {
return str.size () == 2 && str.at (0) ==
'%'; };
83 items.erase (std::remove_if (items.begin (), items.end (), removePred),
95 proxy->GetEntityManager ()->HandleEntity (e);
99 qWarning () << Q_FUNC_INFO
100 <<
"don't know how to execute this type of app";
106 QString ByLang (
const QHash<QString, QString>& cont,
const QString& lang)
108 return cont.value (cont.contains (lang) ? lang : QString ());
114 return ByLang (Name_, lang);
119 return ByLang (GenericName_, lang);
124 return ByLang (Comments_, lang);
169 dbg.nospace () <<
"DesktopItem\n{\n\tNames: " << Name_
170 <<
"\n\tGenericNames: " << GenericName_
171 <<
"\n\tComments: " << Comments_
172 <<
"\n\tCategories: " << Categories_
173 <<
"\n\tCommand: " << Command_
174 <<
"\n\tWorkingDir: " << WD_
175 <<
"\n\tIconName: " << IconName_
176 <<
"\n\tHidden: " << IsHidden_
183 QHash<QString, QString> FirstValues (
const QHash<QString, QStringList>& hash)
185 QHash<QString, QString> result;
186 for (
auto i = hash.begin (), end = hash.end (); i != end; ++i)
187 result [i.key ()] = i->value (0);
194 QFile file (filename);
195 if (!file.open (QIODevice::ReadOnly))
196 throw std::runtime_error (
"Unable to open file");
199 const auto& group = result [
"Desktop Entry"];
201 const auto& item = std::make_shared<Item> ();
202 item->Name_ = FirstValues (group [
"Name"]);
203 item->GenericName_ = FirstValues (group [
"GenericName"]);
204 item->Comments_ = FirstValues (group [
"Comment"]);
206 item->Categories_ = group [
"Categories"] [{}];
208 auto getSingle = [&group] (
const QString& name) {
return group [name] [{}].value (0); };
210 item->IconName_ = getSingle (
"Icon");
212 const auto& typeStr = getSingle (
"Type");
213 if (typeStr ==
"Application")
216 item->Command_ = getSingle (
"Exec");
217 item->WD_ = getSingle (
"Path");
219 else if (typeStr ==
"URL")
222 item->Command_ = getSingle (
"URL");
224 else if (typeStr ==
"Directory")
229 item->IsHidden_ = getSingle (
"NoDisplay").toLower () ==
"true";
bool IsHidden() const
Checks whether this XDG item should be hidden.
Entity MakeEntity(const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
QString GetName(const QString &language) const
Returns the name of this item.
QString GetGenericName(const QString &language) const
Returns the generic name of this item.
void Execute(ICoreProxy_ptr proxy) const
Executes this item, if possible.
std::shared_ptr< Item > Item_ptr
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
void SetIcon(const QIcon &icon)
Sets the icon associated with this item.
Describes a single XDG .desktop entry.
static Item_ptr FromDesktopFile(const QString &file)
Loads the XDG .desktop item from file.
A shortcut to an application.
QString GetIconName() const
Returns the name of the icon for this item.
Type GetType() const
Returns the type of this item.
bool operator==(const Item &left, const Item &right)
QIcon GetIcon() const
Returns the icon previously set by SetIcon().
QDebug DebugPrint(QDebug stream) const
Serializes item contents to the debugging stream.
QString GetWorkingDirectory() const
Returns the working directory for command execution.
QString GetCommand() const
Returns type type-specific command for this item.
Type
Describes the various types of XDG .desktop files.
QStringList GetCategories() const
Returns the categories where this item belongs.
QString GetPermanentID() const
Returns the permanent ID of this item.
QDebug operator<<(QDebug dbg, const Item &item)
Serializes item contents to the debugging stream.
QString GetComment(const QString &language) const
Returns the comment of this item.
A shortcut to a directory.
bool IsValid() const
Checks whether this XDG item is valid.
A parser for XDG .desktop files.