1 /*
2     SPDX-FileCopyrightText: 2010 Milian Wolff <mail@milianw.de>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KDEVPLATFORM_PLUGIN_IOPENWITH_H
8 #define KDEVPLATFORM_PLUGIN_IOPENWITH_H
9 
10 #include <QUrl>
11 
12 #include <interfaces/icore.h>
13 #include <interfaces/iplugincontroller.h>
14 #include <interfaces/idocumentcontroller.h>
15 #include <interfaces/context.h>
16 
17 namespace KDevelop {
18 
19 /**
20  * Interface for the OpenWith plugin.
21  */
22 class IOpenWith {
23 public:
~IOpenWith()24     virtual ~IOpenWith() {}
25     /**
26      * Open @p files with the preferred applications or parts as chosen by the user.
27      *
28      * If the open with plugin was disabled by the user, the files will be opened
29      * as text documents.
30      */
openFiles(const QList<QUrl> & files)31     static void openFiles(const QList<QUrl> &files)
32     {
33         IPlugin* i = ICore::self()->pluginController()->pluginForExtension( QStringLiteral( "org.kdevelop.IOpenWith" ) );
34         if (i) {
35             auto* openWith = i->extension<KDevelop::IOpenWith>();
36             Q_ASSERT(openWith);
37             openWith->openFilesInternal(files);
38             return;
39         }
40 
41         for (const QUrl& url : files) {
42             ICore::self()->documentController()->openDocument( url );
43         }
44     }
45 
46 protected:
47     virtual void openFilesInternal(const QList<QUrl> &files) = 0;
48 };
49 
50 }
51 
52 Q_DECLARE_INTERFACE( KDevelop::IOpenWith, "org.kdevelop.IOpenWith" )
53 
54 #endif // KDEVPLATFORM_PLUGIN_IOPENWITH_H
55