49 return left.IsHidden_ == right.IsHidden_ &&
50 left.Type_ == right.Type_ &&
51 left.Name_ == right.Name_ &&
52 left.GenericName_ == right.GenericName_ &&
53 left.Comments_ == right.Comments_ &&
54 left.Categories_ == right.Categories_ &&
55 left.Command_ == right.Command_ &&
56 left.WD_ == right.WD_ &&
57 left.IconName_ == right.IconName_;
62 return !(left == right);
67 return !Name_.isEmpty ();
81 command.remove (
"%c");
82 command.remove (
"%f");
83 command.remove (
"%F");
84 command.remove (
"%u");
85 command.remove (
"%U");
86 command.remove (
"%i");
87 auto items = command.split (
' ', QString::SkipEmptyParts);
88 auto removePred = [] (
const QString& str)
89 {
return str.size () == 2 && str.at (0) ==
'%'; };
90 items.erase (std::remove_if (items.begin (), items.end (), removePred),
102 proxy->GetEntityManager ()->HandleEntity (e);
106 qWarning () << Q_FUNC_INFO
107 <<
"don't know how to execute this type of app";
113 QString ByLang (
const QHash<QString, QString>& cont,
const QString& lang)
115 return cont.value (cont.contains (lang) ? lang : QString ());
121 return ByLang (Name_, lang);
126 return ByLang (GenericName_, lang);
131 return ByLang (Comments_, lang);
171 if (name.endsWith (
".png") || name.endsWith (
".svg"))
174 auto result = proxy->GetIconThemeManager ()->GetIcon (name);
175 if (!result.isNull ())
179 if (!result.isNull ())
182 qDebug () << Q_FUNC_INFO << name <<
"not found";
198 dbg.nospace () <<
"DesktopItem\n{\n\tNames: " << Name_
199 <<
"\n\tGenericNames: " << GenericName_
200 <<
"\n\tComments: " << Comments_
201 <<
"\n\tCategories: " << Categories_
202 <<
"\n\tCommand: " << Command_
203 <<
"\n\tWorkingDir: " << WD_
204 <<
"\n\tIconName: " << IconName_
205 <<
"\n\tHidden: " << IsHidden_
212 QHash<QString, QString> FirstValues (
const QHash<QString, QStringList>& hash)
214 QHash<QString, QString> result;
215 for (
auto i = hash.begin (), end = hash.end (); i != end; ++i)
216 result [i.key ()] = i->value (0);
223 QFile file (filename);
224 if (!file.open (QIODevice::ReadOnly))
225 throw std::runtime_error (
"Unable to open file");
228 const auto& group = result [
"Desktop Entry"];
230 const auto& item = std::make_shared<Item> ();
231 item->Name_ = FirstValues (group [
"Name"]);
232 item->GenericName_ = FirstValues (group [
"GenericName"]);
233 item->Comments_ = FirstValues (group [
"Comment"]);
235 item->Categories_ = group [
"Categories"] [{}];
237 auto getSingle = [&group] (
const QString& name) {
return group [name] [{}].value (0); };
239 item->IconName_ = getSingle (
"Icon");
241 const auto& typeStr = getSingle (
"Type");
242 if (typeStr ==
"Application")
245 item->Command_ = getSingle (
"Exec");
246 item->WD_ = getSingle (
"Path");
248 else if (typeStr ==
"URL")
251 item->Command_ = getSingle (
"URL");
253 else if (typeStr ==
"Directory")
258 item->IsHidden_ = getSingle (
"NoDisplay").toLower () ==
"true";
Entity MakeEntity(const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
void Execute(ICoreProxy_ptr proxy) const
Executes this item, if possible.
std::shared_ptr< Item > Item_ptr
bool operator!=(const Item &left, const Item &right)
QString GetIconName() const
Returns the name of the icon for 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.
QStringList GetCategories() const
Returns the categories where this item belongs.
bool IsValid() const
Checks whether this XDG item is valid.
bool operator==(const Item &left, const Item &right)
QString GetName(const QString &language) const
Returns the name of this item.
QDebug DebugPrint(QDebug stream) const
Serializes item contents to the debugging stream.
Type
Describes the various types of XDG .desktop files.
QString GetComment(const QString &language) const
Returns the comment of this item.
QString GetPermanentID() const
Returns the permanent ID of this item.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
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)
bool IsHidden() const
Checks whether this XDG item should be hidden.
QString GetWorkingDirectory() const
Returns the working directory for command execution.
QIcon GetIcon(const ICoreProxy_ptr &) const
Returns the icon previously set by SetIcon().
QDebug operator<<(QDebug dbg, const Item &item)
Serializes item contents to the debugging stream.
Type GetType() const
Returns the type of this item.
A shortcut to a directory.
A parser for XDG .desktop files.