47 return IsHidden_ == item.IsHidden_ &&
48 Name_ == item.Name_ &&
49 GenericName_ == item.GenericName_ &&
50 Comments_ == item.Comments_ &&
51 Categories_ == item.Categories_ &&
52 Command_ == item.Command_ &&
54 IconName_ == item.IconName_;
59 return !Name_.isEmpty ();
73 command.remove (
"%c");
74 command.remove (
"%f");
75 command.remove (
"%F");
76 command.remove (
"%u");
77 command.remove (
"%U");
78 command.remove (
"%i");
79 auto items = command.split (
' ', QString::SkipEmptyParts);
80 auto removePred = [] (
const QString& str)
81 {
return str.size () == 2 && str.at (0) ==
'%'; };
82 items.erase (std::remove_if (items.begin (), items.end (), removePred),
94 proxy->GetEntityManager ()->HandleEntity (e);
98 qWarning () << Q_FUNC_INFO
99 <<
"don't know how to execute this type of app";
105 QString ByLang (
const QHash<QString, QString>& cont,
const QString& lang)
107 return cont.value (cont.contains (lang) ? lang : QString ());
113 return ByLang (Name_, lang);
118 return ByLang (GenericName_, lang);
123 return ByLang (Comments_, lang);
168 dbg.nospace () <<
"DesktopItem\n{\n\tNames: " << Name_
169 <<
"\n\tGenericNames: " << GenericName_
170 <<
"\n\tComments: " << Comments_
171 <<
"\n\tCategories: " << Categories_
172 <<
"\n\tCommand: " << Command_
173 <<
"\n\tWorkingDir: " << WD_
174 <<
"\n\tIconName: " << IconName_
175 <<
"\n\tHidden: " << IsHidden_
182 QHash<QString, QString> FirstValues (
const QHash<QString, QStringList>& hash)
184 QHash<QString, QString> result;
185 for (
auto i = hash.begin (), end = hash.end (); i != end; ++i)
186 result [i.key ()] = i->value (0);
193 QFile file (filename);
194 if (!file.open (QIODevice::ReadOnly))
195 throw std::runtime_error (
"Unable to open file");
198 const auto& group = result [
"Desktop Entry"];
201 item->Name_ = FirstValues (group [
"Name"]);
202 item->GenericName_ = FirstValues (group [
"GenericName"]);
203 item->Comments_ = FirstValues (group [
"Comment"]);
205 item->Categories_ = group [
"Categories"] [QString ()];
207 auto getSingle = [&group] (
const QString& name) {
return group [name] [QString ()].value (0); };
209 item->IconName_ = getSingle (
"Icon");
211 const auto& typeStr = getSingle (
"Type");
212 if (typeStr ==
"Application")
215 item->Command_ = getSingle (
"Exec");
216 item->WD_ = getSingle (
"Path");
218 else if (typeStr ==
"URL")
221 item->Command_ = getSingle (
"URL");
223 else if (typeStr ==
"Directory")
228 item->IsHidden_ = getSingle (
"NoDisplay").toLower () ==
"true";
Entity MakeEntity(const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
std::shared_ptr< Item > Item_ptr
QString GetName(const QString &) const
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
QDebug operator<<(QDebug dbg, const Item &item)
static Item_ptr FromDesktopFile(const QString &)
QString GetIconName() const
QString GetComment(const QString &) const
bool operator==(const Item &) const
QString GetWorkingDirectory() const
QString GetCommand() const
QStringList GetCategories() const
QString GetPermanentID() const
void Execute(ICoreProxy_ptr) const
QString GetGenericName(const QString &) const
void SetIcon(const QIcon &)
QDebug DebugPrint(QDebug) const