Commit 1f9338f3 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Only show ALPM scriptlet lines

As suggested by Antonio Rojas, kde maintainer in ArchLinux
parent 5178f31a
......@@ -18,7 +18,7 @@
*/
#include "ReadFile.h"
#include <QRegularExpression>
#include <QDebug>
ReadFile::ReadFile()
{
......@@ -26,6 +26,12 @@ ReadFile::ReadFile()
connect(&m_file, &QFile::readyRead, this, &ReadFile::processAll);
}
void ReadFile::componentComplete()
{
completed = true;
openNow();
}
void ReadFile::setPath(QString path)
{
processPath(path);
......@@ -33,7 +39,7 @@ void ReadFile::setPath(QString path)
return;
if (path.isEmpty())
return;;
return;
if (m_file.isOpen())
m_watcher.removePath(m_file.fileName());
......@@ -46,6 +52,9 @@ void ReadFile::setPath(QString path)
void ReadFile::openNow()
{
if (!completed)
return;
if (!m_contents.isEmpty()) {
m_contents.clear();
Q_EMIT contentsChanged(m_contents);
......@@ -57,7 +66,7 @@ void ReadFile::openNow()
return;
m_stream.reset(new QTextStream(&m_file));
process(800);
processAll();
}
void ReadFile::processPath(QString& path)
......@@ -75,6 +84,29 @@ void ReadFile::process(uint max)
QString read = m_stream->readAll();
if (max>0)
read = read.right(max);
m_contents += read;
if (m_filter.isValid()) {
auto it = m_filter.globalMatch(read);
while(it.hasNext()) {
const auto match = it.next();
m_contents.append(match.capturedRef(match.lastCapturedIndex()));
m_contents.append(QLatin1Char('\n'));
}
} else
m_contents += read;
Q_EMIT contentsChanged(m_contents);
}
void ReadFile::setFilter(const QString& filter)
{
m_filter = QRegularExpression(filter);
if (!m_filter.isValid())
qDebug() << "error" << m_filter.errorString();
Q_ASSERT(filter.isEmpty() || m_filter.isValid());
}
QString ReadFile::filter() const
{
return m_filter.pattern();
}
......@@ -21,15 +21,19 @@
#define READFILE_H
#include <QFile>
#include <QFileSystemWatcher>
#include <QTextStream>
#include <QSharedPointer>
#include <QFileSystemWatcher>
#include <QRegularExpression>
#include <QQmlParserStatus>
class ReadFile : public QObject
class ReadFile : public QObject, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QString contents READ contents NOTIFY contentsChanged)
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
Q_PROPERTY(QString filter READ filter WRITE setFilter FINAL)
public:
ReadFile();
......@@ -37,6 +41,11 @@ public:
QString path() const { return m_file.fileName(); }
void setPath(QString path);
QString filter() const;
void setFilter(const QString &filter);
void classBegin() override {}
void componentComplete() override;
Q_SIGNALS:
void pathChanged(const QString &path);
......@@ -48,10 +57,12 @@ private:
void openNow();
void processPath(QString& path);
bool completed = false;
QFile m_file;
QString m_contents;
QSharedPointer<QTextStream> m_stream;
QFileSystemWatcher m_watcher;
QRegularExpression m_filter;
};
#endif // READFILE_H
......@@ -55,6 +55,7 @@ DiscoverPage
ReadFile {
id: log
filter: ".*ALPM-SCRIPTLET\\] .*"
path: "/var/log/pacman.log"
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment