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
21class KFileItemActions;
22
23typedef QList<KDesktopFileAction> ServiceList;
24
25class KFileItemActionsPrivate : public QObject
26{
27 Q_OBJECT
28 friend class KFileItemActions;
29
30public:
31 explicit KFileItemActionsPrivate(KFileItemActions *qq);
32 ~KFileItemActionsPrivate() override;
33
34 int insertServicesSubmenus(const QMap<QString, ServiceList> &list, QMenu *menu);
35 int insertServices(const ServiceList &list, QMenu *menu);
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 *menu = nullptr;
58 };
59 ServiceActionInfo addServiceActionsTo(QMenu *mainMenu, const QList<QAction *> &additionalActions, const QStringList &excludeList);
60 int addPluginActionsTo(QMenu *mainMenu, QMenu *actionsMenu, const QStringList &excludeList);
61 void insertOpenWithActionsTo(QAction *before, QMenu *topMenu, const QStringList &excludedDesktopEntryNames);
62 static KService::List associatedApplications(const QStringList &mimeTypeList, const QStringList &excludedDesktopEntryNames);
63
64 QStringList serviceMenuFilePaths();
65
66public Q_SLOTS:
67 void slotRunPreferredApplications();
68
69private:
70 void openWithByMime(const KFileItemList &fileItems);
71
72 // Utility function which returns true if the service menu should be displayed
73 bool shouldDisplayServiceMenu(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
77private Q_SLOTS:
78 // For servicemenus
79 void slotExecuteService(QAction *act);
80 // For "open with" applications
81 void slotRunApplication(QAction *act);
82 void slotOpenWithDialog();
83
84public:
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
96Q_DECLARE_METATYPE(KService::Ptr)
97Q_DECLARE_METATYPE(KServiceAction)
98
99#endif /* KFILEITEMACTIONS_P_H */
100

source code of kio/src/widgets/kfileitemactions_p.h