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