File indexing completed on 2024-05-12 17:08:48

0001 /*
0002     SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QPointer>
0011 #include <QString>
0012 #include <QUrl>
0013 
0014 #include <KService>
0015 
0016 class QAction;
0017 
0018 namespace KIO
0019 {
0020 class MimeTypeFinderJob;
0021 }
0022 
0023 class FileInfo : public QObject
0024 {
0025     Q_OBJECT
0026 
0027     Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
0028 
0029     Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
0030     Q_PROPERTY(int error READ error NOTIFY errorChanged)
0031 
0032     Q_PROPERTY(QString mimeType READ mimeType NOTIFY mimeTypeChanged)
0033     Q_PROPERTY(QString iconName READ iconName NOTIFY mimeTypeChanged)
0034 
0035     Q_PROPERTY(QAction *openAction READ openAction NOTIFY openActionChanged)
0036     // QML can't deal with QIcon...
0037     Q_PROPERTY(QString openActionIconName READ openActionIconName NOTIFY openActionIconNameChanged)
0038 
0039 public:
0040     explicit FileInfo(QObject *parent = nullptr);
0041     ~FileInfo() override;
0042 
0043     QUrl url() const;
0044     void setUrl(const QUrl &url);
0045     Q_SIGNAL void urlChanged(const QUrl &url);
0046 
0047     bool busy() const;
0048     Q_SIGNAL void busyChanged(bool busy);
0049 
0050     int error() const;
0051     Q_SIGNAL void errorChanged(bool error);
0052 
0053     QString mimeType() const;
0054     Q_SIGNAL void mimeTypeChanged();
0055 
0056     QString iconName() const;
0057     Q_SIGNAL void iconNameChanged(const QString &iconName);
0058 
0059     QAction *openAction() const;
0060     Q_SIGNAL void openActionChanged();
0061 
0062     QString openActionIconName() const;
0063     Q_SIGNAL void openActionIconNameChanged();
0064 
0065 private:
0066     void reload();
0067     void mimeTypeFound(const QString &mimeType);
0068 
0069     void setBusy(bool busy);
0070     void setError(int error);
0071 
0072     QUrl m_url;
0073 
0074     QPointer<KIO::MimeTypeFinderJob> m_job;
0075     bool m_busy = false;
0076     int m_error = 0;
0077 
0078     QString m_mimeType;
0079     QString m_iconName;
0080 
0081     KService::Ptr m_preferredApplication;
0082     QAction *m_openAction = nullptr;
0083 };