File indexing completed on 2024-05-12 17:21:58
0001 /* 0002 SPDX-FileCopyrightText: 2002 Shie Erlich <erlich@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2002 Rafi Yanai <yanai@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef PANELVIEWER_H 0010 #define PANELVIEWER_H 0011 0012 // QtCore 0013 #include <QHash> 0014 #include <QString> 0015 #include <QUrl> 0016 // QtWidgets 0017 #include <QLabel> 0018 #include <QStackedWidget> 0019 0020 #include <KParts/Part> 0021 0022 #include "krviewer.h" 0023 0024 class PanelViewerBase : public QStackedWidget 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 explicit PanelViewerBase(QWidget *parent, KrViewer::Mode mode = KrViewer::Default); 0030 ~PanelViewerBase() override; 0031 inline QUrl url() const 0032 { 0033 return curl; 0034 } 0035 inline KParts::ReadOnlyPart *part() const 0036 { 0037 return cpart; 0038 } 0039 virtual bool isModified() 0040 { 0041 return false; 0042 } 0043 virtual bool isEditor() = 0; 0044 0045 public slots: 0046 virtual bool closeUrl() 0047 { 0048 return false; 0049 } 0050 virtual bool queryClose() 0051 { 0052 return true; 0053 } 0054 0055 void openUrl(const QUrl &url); 0056 0057 signals: 0058 void openUrlRequest(const QUrl &url); 0059 void urlChanged(PanelViewerBase *, const QUrl &); 0060 void partDestroyed(PanelViewerBase *); 0061 void openUrlFinished(PanelViewerBase *viewWidget, bool success); 0062 0063 protected slots: 0064 void slotCPartDestroyed() 0065 { 0066 emit partDestroyed(this); 0067 } 0068 void slotStatResult(KJob *job); 0069 0070 protected: 0071 virtual void openFile(KFileItem fi) = 0; 0072 virtual KParts::ReadOnlyPart *createPart(QString mimetype) = 0; 0073 KParts::ReadOnlyPart *getPart(const QString &mimetype); 0074 0075 QHash<QString, QPointer<KParts::ReadOnlyPart>> *mimes; 0076 QPointer<KParts::ReadOnlyPart> cpart; 0077 0078 QUrl curl; 0079 QLabel *fallback; 0080 KrViewer::Mode mode; 0081 }; 0082 0083 class PanelViewer : public PanelViewerBase 0084 { 0085 Q_OBJECT 0086 public slots: 0087 bool closeUrl() override; 0088 0089 public: 0090 explicit PanelViewer(QWidget *parent, KrViewer::Mode mode = KrViewer::Default); 0091 ~PanelViewer() override; 0092 0093 bool isEditor() override 0094 { 0095 return false; 0096 } 0097 0098 protected: 0099 void openFile(KFileItem fi) override; 0100 KParts::ReadOnlyPart *createPart(QString mimetype) override; 0101 KParts::ReadOnlyPart *getDefaultPart(const KFileItem &fi); 0102 KParts::ReadOnlyPart *getHexPart(); 0103 KParts::ReadOnlyPart *getListerPart(bool hexMode = false); 0104 KParts::ReadOnlyPart *getTextPart(); 0105 }; 0106 0107 class PanelEditor : public PanelViewerBase 0108 { 0109 Q_OBJECT 0110 public: 0111 bool isModified() override; 0112 bool isEditor() override 0113 { 0114 return true; 0115 } 0116 0117 static void configureDeps(); 0118 0119 public slots: 0120 bool closeUrl() override; 0121 bool queryClose() override; 0122 0123 public: 0124 explicit PanelEditor(QWidget *parent, KrViewer::Mode mode = KrViewer::Default); 0125 ~PanelEditor() override; 0126 0127 protected: 0128 void openFile(KFileItem fi) override; 0129 KParts::ReadOnlyPart *createPart(QString mimetype) override; 0130 static QString missingKPartMsg(); 0131 }; 0132 0133 #endif