| 1 | /* |
| 2 | This file is part of the KDE project |
| 3 | SPDX-FileCopyrightText: 1998-2009 David Faure <faure@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | |
| 8 | #ifndef KFILEITEMACTIONS_P_H |
| 9 | #define KFILEITEMACTIONS_P_H |
| 10 | |
| 11 | #include "config-kiowidgets.h" |
| 12 | #include "kabstractfileitemactionplugin.h" |
| 13 | #include <KConfig> |
| 14 | #include <KDesktopFileAction> |
| 15 | #include <KService> |
| 16 | #include <kfileitem.h> |
| 17 | #include <kfileitemlistproperties.h> |
| 18 | |
| 19 | #include <QActionGroup> |
| 20 | #include <QObject> |
| 21 | |
| 22 | class KFileItemActions; |
| 23 | |
| 24 | typedef QList<KDesktopFileAction> ServiceList; |
| 25 | |
| 26 | class KFileItemActionsPrivate : public QObject |
| 27 | { |
| 28 | Q_OBJECT |
| 29 | friend class KFileItemActions; |
| 30 | |
| 31 | public: |
| 32 | explicit KFileItemActionsPrivate(KFileItemActions *qq); |
| 33 | ~KFileItemActionsPrivate() override; |
| 34 | |
| 35 | int (const QMap<QString, ServiceList> &list, QMenu *); |
| 36 | int (const ServiceList &list, QMenu *); |
| 37 | |
| 38 | // For "open with" |
| 39 | KService::List associatedApplications(); |
| 40 | QAction *createAppAction(const KService::Ptr &service, bool singleOffer); |
| 41 | |
| 42 | struct ServiceRank { |
| 43 | int score; |
| 44 | KService::Ptr service; |
| 45 | }; |
| 46 | |
| 47 | // Inline function for sorting lists of ServiceRank |
| 48 | static bool lessRank(const ServiceRank &id1, const ServiceRank &id2) |
| 49 | { |
| 50 | return id1.score < id2.score; |
| 51 | } |
| 52 | |
| 53 | QStringList listMimeTypes(const KFileItemList &items); |
| 54 | QStringList listPreferredServiceIds(const QStringList &mimeTypeList, const QStringList &excludedDesktopEntryNames); |
| 55 | |
| 56 | struct ServiceActionInfo { |
| 57 | int userItemCount = 0; |
| 58 | QMenu * = nullptr; |
| 59 | }; |
| 60 | ServiceActionInfo (QMenu *mainMenu, const QList<QAction *> &additionalActions, const QStringList &excludeList); |
| 61 | int (QMenu *mainMenu, QMenu *, const QStringList &excludeList); |
| 62 | void (QAction *before, QMenu *, const QStringList &excludedDesktopEntryNames); |
| 63 | static KService::List associatedApplications(const QStringList &mimeTypeList, const QStringList &excludedDesktopEntryNames); |
| 64 | |
| 65 | QStringList (); |
| 66 | |
| 67 | public Q_SLOTS: |
| 68 | void slotRunPreferredApplications(); |
| 69 | |
| 70 | private: |
| 71 | void openWithByMime(const KFileItemList &fileItems); |
| 72 | |
| 73 | // Utility function which returns true if the service menu should be displayed |
| 74 | bool (const KConfigGroup &cfg, const QString &protocol) const; |
| 75 | // Utility functions which returns true if the types for the service are set and the exclude types are not contained |
| 76 | bool checkTypesMatch(const KConfigGroup &cfg) const; |
| 77 | |
| 78 | private Q_SLOTS: |
| 79 | // For servicemenus |
| 80 | void slotExecuteService(QAction *act); |
| 81 | // For "open with" applications |
| 82 | void slotRunApplication(QAction *act); |
| 83 | void slotOpenWithDialog(); |
| 84 | |
| 85 | public: |
| 86 | KFileItemActions *const q; |
| 87 | KFileItemListProperties m_props; |
| 88 | QStringList m_mimeTypeList; |
| 89 | KFileItemList m_fileOpenList; |
| 90 | QActionGroup m_executeServiceActionGroup; |
| 91 | QActionGroup m_runApplicationActionGroup; |
| 92 | QWidget *m_parentWidget; |
| 93 | KConfig m_config; |
| 94 | QHash<QString, KAbstractFileItemActionPlugin *> m_loadedPlugins; |
| 95 | }; |
| 96 | |
| 97 | Q_DECLARE_METATYPE(KService::Ptr) |
| 98 | Q_DECLARE_METATYPE(KServiceAction) |
| 99 | |
| 100 | #endif /* KFILEITEMACTIONS_P_H */ |
| 101 | |