Implement feed import from opml

This commit is contained in:
Tobias Fella 2020-09-03 00:09:59 +02:00
parent 745c742172
commit fd9420fe2d
3 changed files with 33 additions and 0 deletions

View File

@ -9,6 +9,8 @@
#include <QSqlDatabase> #include <QSqlDatabase>
#include <QSqlError> #include <QSqlError>
#include <QStandardPaths> #include <QStandardPaths>
#include <QUrl>
#include <QXmlStreamReader>
#include "alligatorsettings.h" #include "alligatorsettings.h"
#include "database.h" #include "database.h"
@ -153,3 +155,19 @@ void Database::addFeed(QString url)
Fetcher::instance().fetch(urlFromInput.toString()); Fetcher::instance().fetch(urlFromInput.toString());
} }
void Database::importFeedsFromUrl(QString url)
{
QFile *file = new QFile(QUrl(url).toLocalFile());
file->open(QIODevice::ReadOnly);
QXmlStreamReader xmlReader;
xmlReader.setDevice(file);
while(!xmlReader.atEnd()) {
xmlReader.readNext();
if(xmlReader.tokenType() == 4 && xmlReader.attributes().hasAttribute(QStringLiteral("xmlUrl"))) {
addFeed(xmlReader.attributes().value(QStringLiteral("xmlUrl")).toString());
}
}
Fetcher::instance().fetchAll();
}

View File

@ -21,6 +21,7 @@ public:
bool execute(QSqlQuery &query); bool execute(QSqlQuery &query);
bool execute(QString query); bool execute(QString query);
Q_INVOKABLE void addFeed(QString url); Q_INVOKABLE void addFeed(QString url);
Q_INVOKABLE void importFeedsFromUrl(QString url);
Q_SIGNALS: Q_SIGNALS:
void feedAdded(QString url); void feedAdded(QString url);

View File

@ -6,6 +6,7 @@
import QtQuick 2.14 import QtQuick 2.14
import QtQuick.Controls 2.14 as Controls import QtQuick.Controls 2.14 as Controls
import Qt.labs.platform 1.1
import QtQuick.Layouts 1.14 import QtQuick.Layouts 1.14
import org.kde.kirigami 2.12 as Kirigami import org.kde.kirigami 2.12 as Kirigami
@ -30,6 +31,11 @@ Kirigami.ScrollablePage {
iconName: "view-refresh" iconName: "view-refresh"
onTriggered: refreshing = true onTriggered: refreshing = true
visible: !Kirigami.Settings.isMobile visible: !Kirigami.Settings.isMobile
},
Kirigami.Action {
text: i18n("Import Feeds...")
iconName: "document-import"
onTriggered: importDialog.open()
} }
] ]
@ -64,4 +70,12 @@ Kirigami.ScrollablePage {
delegate: FeedListDelegate { } delegate: FeedListDelegate { }
} }
FileDialog {
id: importDialog
title: i18n("Import Feeds")
folder: StandardPaths.writableLocation(StandardPaths.HomeLocation)
nameFilters: [i18n("All Files (*.*)"), i18n("XML Files (*.xml)"), i18n("OPML Files (*.opml)")]
onAccepted: Database.importFeedsFromUrl(file)
}
} }