File indexing completed on 2024-06-23 05:30:47

0001 /*
0002     SPDX-FileCopyrightText: 2015 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "abstractentry.h"
0010 
0011 #include <KService>
0012 #include <KServiceGroup>
0013 
0014 #include <QPointer>
0015 
0016 class AppsModel;
0017 class MenuEntryEditor;
0018 
0019 class AppEntry : public AbstractEntry
0020 {
0021 public:
0022     enum NameFormat {
0023         NameOnly = 0,
0024         GenericNameOnly,
0025         NameAndGenericName,
0026         GenericNameAndName,
0027     };
0028 
0029     explicit AppEntry(AbstractModel *owner, KService::Ptr service, NameFormat nameFormat);
0030     explicit AppEntry(AbstractModel *owner, const QString &id);
0031     ~AppEntry() override;
0032 
0033     EntryType type() const override
0034     {
0035         return RunnableType;
0036     }
0037 
0038     bool isValid() const override;
0039 
0040     QString icon() const override;
0041     QString name() const override;
0042     QString description() const override;
0043     KService::Ptr service() const;
0044     QString group() const override;
0045 
0046     QString id() const override;
0047     QUrl url() const override;
0048 
0049     bool hasActions() const override;
0050     QVariantList actions() const override;
0051 
0052     bool run(const QString &actionId = QString(), const QVariant &argument = QVariant()) override;
0053 
0054     QString menuId() const;
0055 
0056     static QString nameFromService(const KService::Ptr &service, NameFormat nameFormat);
0057     static KService::Ptr defaultAppByName(const QString &name);
0058 
0059 private:
0060     void init(NameFormat nameFormat);
0061 
0062     QString m_id;
0063     QString m_name;
0064     QString m_description;
0065     // Not an actual group name, but the first character for transliterated name.
0066     mutable QString m_group;
0067     mutable QString m_icon;
0068     KService::Ptr m_service;
0069     static MenuEntryEditor *m_menuEntryEditor;
0070     QMetaObject::Connection m_con;
0071 };
0072 
0073 class AppGroupEntry : public AbstractGroupEntry
0074 {
0075 public:
0076     AppGroupEntry(AppsModel *parentModel, KServiceGroup::Ptr group, bool paginate, int pageSize, bool flat, bool sorted, bool separators, int appNameFormat);
0077 
0078     QString icon() const override;
0079     QString name() const override;
0080 
0081     bool hasChildren() const override;
0082     AbstractModel *childModel() const override;
0083 
0084 private:
0085     KServiceGroup::Ptr m_group;
0086     mutable QString m_icon;
0087     QPointer<AbstractModel> m_childModel;
0088 };