File indexing completed on 2025-01-05 05:14:49

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "libkommitwidgets_export.h"
0010 #include "ui_fileviewerdialog.h"
0011 
0012 #include <QPointer>
0013 
0014 #include <KParts/MainWindow>
0015 #include <KParts/ReadOnlyPart>
0016 #include <KService>
0017 
0018 class QMimeType;
0019 namespace Git
0020 {
0021 class Manager;
0022 class File;
0023 }
0024 class LIBKOMMITWIDGETS_EXPORT FileViewerDialog : public KParts::MainWindow, private Ui::FileViewerDialog
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     explicit FileViewerDialog(Git::Manager *git, const QString &place, const QString &fileName, QWidget *parent = nullptr);
0030     explicit FileViewerDialog(Git::Manager *git, const Git::File &file, QWidget *parent = nullptr);
0031 
0032     ~FileViewerDialog() override;
0033 
0034 private:
0035     Git::Manager *mGit = nullptr;
0036     QString mFilePath;
0037 
0038     void showFile(const Git::File &file);
0039     void showInEditor(const Git::File &file);
0040     void showAsImage(const Git::File &file);
0041     QPointer<KParts::ReadOnlyPart> m_part;
0042 
0043     bool viewInInternalViewer(const KService::Ptr &viewer, const QString &fileName, const QMimeType &mimeType);
0044     KService::Ptr getExternalViewer(const QString &mimeType);
0045     KService::Ptr getInternalViewer(const QString &mimeType);
0046 
0047 protected:
0048     void keyPressEvent(QKeyEvent *event) override;
0049 };