Commit 5178f31a authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Include pacman's log on arch

Otherwise the user is kind of lost
parent 2eafbe24
......@@ -11,6 +11,7 @@ add_executable(plasma-discover ${plasma_discover_SRCS}
FeaturedModel.cpp
PaginateModel.cpp
UnityLauncher.cpp
ReadFile.cpp
resources.qrc
assets.qrc
......
......@@ -18,6 +18,7 @@
*/
#include "DiscoverDeclarativePlugin.h"
#include "ReadFile.h"
#include <Category/CategoryModel.h>
#include <Category/Category.h>
#include <Transaction/TransactionListener.h>
......@@ -62,6 +63,7 @@ void DiscoverDeclarativePlugin::registerTypes(const char* /*uri*/)
qmlRegisterType<ScreenshotsModel>("org.kde.discover", 2, 0, "ScreenshotsModel");
qmlRegisterType<ActionsModel>("org.kde.discover", 2, 0, "ActionsModel");
qmlRegisterType<UpdateModel>("org.kde.discover", 2, 0, "UpdateModel");
qmlRegisterType<ReadFile>("org.kde.discover", 2, 0, "ReadFile");
qmlRegisterUncreatableType<QAction>("org.kde.discover", 2, 0, "QAction", QStringLiteral("Use QQC Action"));
qmlRegisterUncreatableType<AbstractResource>("org.kde.discover", 2, 0, "AbstractResource", QStringLiteral("should come from the ResourcesModel"));
......
/*
* Copyright (C) 2018 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library/Lesser General Public License
* version 2, or (at your option) any later version, as published by the
* Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library/Lesser General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "ReadFile.h"
#include <QRegularExpression>
ReadFile::ReadFile()
{
connect(&m_watcher, &QFileSystemWatcher::fileChanged, this, &ReadFile::openNow);
connect(&m_file, &QFile::readyRead, this, &ReadFile::processAll);
}
void ReadFile::setPath(QString path)
{
processPath(path);
if (path == m_file.fileName())
return;
if (path.isEmpty())
return;;
if (m_file.isOpen())
m_watcher.removePath(m_file.fileName());
m_file.setFileName(path);
openNow();
m_watcher.addPath(m_file.fileName());
}
void ReadFile::openNow()
{
if (!m_contents.isEmpty()) {
m_contents.clear();
Q_EMIT contentsChanged(m_contents);
}
m_file.close();
const auto open = m_file.open(QIODevice::ReadOnly | QIODevice::Text);
Q_EMIT pathChanged(path());
if (!open)
return;
m_stream.reset(new QTextStream(&m_file));
process(800);
}
void ReadFile::processPath(QString& path)
{
const QRegularExpression envRx(QStringLiteral("\\$([A-Z_]+)"));
auto matchIt = envRx.globalMatch(path);
while(matchIt.hasNext()) {
auto match = matchIt.next();
path.replace(match.capturedStart(), match.capturedLength(), QString::fromUtf8(qgetenv(match.capturedRef(1).toUtf8().constData())));
}
}
void ReadFile::process(uint max)
{
QString read = m_stream->readAll();
if (max>0)
read = read.right(max);
m_contents += read;
Q_EMIT contentsChanged(m_contents);
}
/*
* Copyright (C) 2018 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library/Lesser General Public License
* version 2, or (at your option) any later version, as published by the
* Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library/Lesser General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef READFILE_H
#define READFILE_H
#include <QFile>
#include <QTextStream>
#include <QSharedPointer>
#include <QFileSystemWatcher>
class ReadFile : public QObject
{
Q_OBJECT
Q_PROPERTY(QString contents READ contents NOTIFY contentsChanged)
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
public:
ReadFile();
QString contents() const { return m_contents; }
QString path() const { return m_file.fileName(); }
void setPath(QString path);
Q_SIGNALS:
void pathChanged(const QString &path);
void contentsChanged(const QString &contents);
private:
void processAll() { return process(0); }
void process(uint max);
void openNow();
void processPath(QString& path);
QFile m_file;
QString m_contents;
QSharedPointer<QTextStream> m_stream;
QFileSystemWatcher m_watcher;
};
#endif // READFILE_H
......@@ -45,6 +45,20 @@ DiscoverPage
onTriggered: resourcesUpdatesModel.updateAll()
}
footer: TextArea {
width: parent.width
height: Kirigami.Units.gridUnit * 10
text: log.contents
visible: text.length > 0
onTextChanged: flickableItem.contentY = flickableItem.contentHeight - flickableItem.height
ReadFile {
id: log
path: "/var/log/pacman.log"
}
}
Kirigami.Action
{
id: cancelUpdateAction
......
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