File indexing completed on 2024-04-28 15:40:12

0001 // SPDX-FileCopyrightText: 2003-2010 Jesper K. Pedersen <blackie@kde.org>
0002 // SPDX-FileCopyrightText: 2020-2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0003 //
0004 // SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 #ifndef EXTERNALPOPUP_H
0007 #define EXTERNALPOPUP_H
0008 #include <DB/ImageInfoList.h>
0009 #include <kpabase/FileNameList.h>
0010 #include <kpabase/StringSet.h>
0011 
0012 #include <QMenu>
0013 #include <QPixmap>
0014 #include <qpair.h>
0015 
0016 #include <KService>
0017 
0018 namespace DB
0019 {
0020 class ImageInfo;
0021 }
0022 
0023 namespace MainWindow
0024 {
0025 
0026 class ExternalPopup : public QMenu
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     explicit ExternalPopup(QWidget *parent);
0032     void populate(DB::ImageInfoPtr current, const DB::FileNameList &list);
0033 
0034 protected:
0035     QString mimeType(const DB::FileName &file);
0036     Utilities::StringSet mimeTypes(const DB::FileNameList &files);
0037     /**
0038      * @brief appInfos gets a list of KService entries for the list of files.
0039      * The result list only contains entries that are valid for all files and is sorted by preference.
0040      * Note that "sorted by preference" means sorted by one of the mime types, so if the user has vastly different preferences for different mime types they might still end up with a somewhat random order.
0041      * @param files
0042      * @return
0043      */
0044     KService::List appInfos(const DB::FileNameList &files);
0045 
0046 private:
0047     enum class PopupAction { OpenCurrent,
0048                              OpenAllSelected,
0049                              CopyAndOpenAllSelected };
0050     void runService(KService::Ptr servicel, QList<QUrl> urls);
0051     QList<QUrl> relevantUrls(PopupAction which);
0052 
0053     DB::FileNameList m_list;
0054     DB::ImageInfoPtr m_currentInfo;
0055     QMap<QString, Utilities::StringSet> m_appToMimeTypeMap;
0056 };
0057 }
0058 
0059 bool operator<(const QPair<QString, QPixmap> &a, const QPair<QString, QPixmap> &b);
0060 
0061 #endif /* EXTERNALPOPUP_H */
0062 
0063 // vi:expandtab:tabstop=4 shiftwidth=4: