File indexing completed on 2025-04-27 03:58:06
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2014-05-08 0007 * Description : Service menu operation methods 0008 * 0009 * SPDX-FileCopyrightText: 2014-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_DSERVICE_MENU_H 0016 #define DIGIKAM_DSERVICE_MENU_H 0017 0018 // Qt includes 0019 0020 #include <QUrl> 0021 #include <QString> 0022 #include <QStringList> 0023 0024 // KDE includes 0025 0026 // Pragma directives to reduce warnings from KDE header files. 0027 #if defined(Q_CC_GNU) 0028 # pragma GCC diagnostic push 0029 # pragma GCC diagnostic ignored "-Wdeprecated-declarations" 0030 #endif 0031 0032 #if defined(Q_CC_CLANG) 0033 # pragma clang diagnostic push 0034 # pragma clang diagnostic ignored "-Wmismatched-tags" 0035 # pragma clang diagnostic ignored "-Wdeprecated-declarations" 0036 #endif 0037 0038 #include <kservice.h> 0039 0040 // Restore warnings 0041 #if defined(Q_CC_GNU) 0042 # pragma GCC diagnostic pop 0043 #endif 0044 0045 #if defined(Q_CC_CLANG) 0046 # pragma clang diagnostic pop 0047 #endif 0048 0049 // Local includes 0050 0051 #include "digikam_export.h" 0052 0053 namespace Digikam 0054 { 0055 0056 class DIGIKAM_EXPORT DServiceMenu 0057 { 0058 public: 0059 0060 //@{ 0061 0062 // Linux Services methods implemented in dservicemenu_linux.cpp 0063 0064 /** 0065 * Linux only: open file urls with the service. 0066 */ 0067 static bool runFiles(const KService::Ptr& service, const QList<QUrl>& urls); 0068 0069 /** 0070 * Linux only: open file urls with the application command. 0071 */ 0072 static bool runFiles(const QString& appCmd, 0073 const QList<QUrl>& urls, 0074 const KService::Ptr& service = KService::Ptr()); 0075 0076 /** 0077 * Linux only: return list of service available on desktop to open files. 0078 */ 0079 static KService::List servicesForOpenWith(const QList<QUrl>& urls); 0080 0081 //@} 0082 0083 //@{ 0084 0085 // MacOS Application Bundles methods implemented in dservicemenu_mac.mm 0086 0087 #ifdef Q_OS_MAC 0088 0089 /** 0090 * Given a filename extension 'suffix', here's how to find all of the 0091 * applications known to the MacOS who can open files of that type. 0092 * Return a list of suitable MacOS bundle urls for 'suffix'. 0093 * First one is the default MacOS bundle application. 0094 */ 0095 static QList<QUrl> MacApplicationForFileExtension(const QString& suffix); 0096 0097 /** 0098 * Function to open your file urls with a specific MacOS application bundle url. 0099 * Return true if application can be started. 0100 */ 0101 static bool MacOpenFilesWithApplication(const QList<QUrl>& fileUrls, const QUrl& appUrl); 0102 0103 /** 0104 * Return a list of common MacOS Application bundles suitable for a list of files. 0105 * The function check all common Applications which can handle urls to open files. 0106 * Only common Applications are returned on the list. 0107 * The list can be empty if no common Application is found. 0108 */ 0109 static QList<QUrl> MacApplicationsForFiles(const QList<QUrl>& files); 0110 0111 /** 0112 * Return the MacOS Application bundle name based on url. 0113 */ 0114 static QString MacApplicationBundleName(const QUrl& appUrl); 0115 0116 /** 0117 * Return the MacOS Application bundle icon based on url. 0118 */ 0119 static QIcon MacApplicationBundleIcon(const QUrl& appUrl, int size = 32); 0120 0121 #endif 0122 0123 //@} 0124 0125 }; 0126 0127 } // namespace Digikam 0128 0129 #endif // DIGIKAM_DSERVICE_MENU_H