feat: 初始代码
AM初始代码,迁移自gitlabwh Log: Task: https://pms.uniontech.com/task-view-108539.html Influence: Change-Id: I6096f97e5d68d13796ff5dc51d9858c0f40264a0
This commit is contained in:
79
src/modules/applicationhelper/helper.h
Normal file
79
src/modules/applicationhelper/helper.h
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef A7B4B7B1_0422_4EC9_8441_778273A85F9C
|
||||
#define A7B4B7B1_0422_4EC9_8441_778273A85F9C
|
||||
|
||||
#include "../tools/desktop_deconstruction.hpp"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace modules {
|
||||
namespace ApplicationHelper {
|
||||
class Helper {
|
||||
QString m_file;
|
||||
|
||||
public:
|
||||
Helper(const QString &desktop)
|
||||
: m_file(desktop)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
inline QString desktop() const { return m_file; }
|
||||
|
||||
template <typename T>
|
||||
T value(const QString &key) const
|
||||
{
|
||||
QSettings settings = DesktopDeconstruction(m_file);
|
||||
settings.beginGroup("Desktop Entry");
|
||||
return settings.value(key).value<T>();
|
||||
}
|
||||
|
||||
QStringList categories() const
|
||||
{
|
||||
QStringList result;
|
||||
QStringList tmp{ value<QString>("Categories").split(";") };
|
||||
for (auto t : tmp) {
|
||||
if (t.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
result << t;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString icon() const
|
||||
{
|
||||
return value<QString>("Icon");
|
||||
}
|
||||
|
||||
QString id() const
|
||||
{
|
||||
return m_file.split("/").last().split(".").first();
|
||||
}
|
||||
|
||||
QStringList mimetypes() const
|
||||
{
|
||||
QStringList result;
|
||||
QStringList tmp{ value<QString>("MimeType").split(";") };
|
||||
for (auto t : tmp) {
|
||||
if (t.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
result << t;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString comment(const QString &locale) const
|
||||
{
|
||||
return value<QString>(QString("Comment[%1]").arg(locale));
|
||||
}
|
||||
|
||||
QString name(const QString &name) const
|
||||
{
|
||||
return value<QString>(QString("Name[%1]").arg(name));
|
||||
}
|
||||
};
|
||||
} // namespace ApplicationHelper
|
||||
} // namespace modules
|
||||
|
||||
#endif /* A7B4B7B1_0422_4EC9_8441_778273A85F9C */
|
Reference in New Issue
Block a user