File indexing completed on 2024-05-05 05:29:12
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QFile> 0010 #include <QFileSystemWatcher> 0011 #include <QQmlParserStatus> 0012 #include <QRegularExpression> 0013 #include <QSharedPointer> 0014 #include <QTextStream> 0015 0016 class ReadFile : public QObject, public QQmlParserStatus 0017 { 0018 Q_OBJECT 0019 Q_INTERFACES(QQmlParserStatus) 0020 Q_PROPERTY(QString contents READ contents NOTIFY contentsChanged) 0021 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) 0022 Q_PROPERTY(QString filter READ filter WRITE setFilter FINAL) 0023 public: 0024 ReadFile(); 0025 0026 QString contents() const 0027 { 0028 return m_contents; 0029 } 0030 QString path() const 0031 { 0032 return m_file.fileName(); 0033 } 0034 void setPath(QString path); 0035 0036 QString filter() const; 0037 void setFilter(const QString &filter); 0038 0039 void classBegin() override 0040 { 0041 } 0042 void componentComplete() override; 0043 0044 Q_SIGNALS: 0045 void pathChanged(const QString &path); 0046 void contentsChanged(const QString &contents); 0047 0048 private: 0049 void process(); 0050 void openNow(); 0051 void processPath(QString &path); 0052 0053 bool completed = false; 0054 QFile m_file; 0055 QString m_contents; 0056 QSharedPointer<QTextStream> m_stream; 0057 QFileSystemWatcher m_watcher; 0058 QRegularExpression m_filter; 0059 qint64 m_sizeOnSet = 0; 0060 };