mirror of
https://github.com/KDE/kasts.git
synced 2025-01-23 05:49:26 +01:00
Implement feed export to opml
This commit is contained in:
parent
fd9420fe2d
commit
b8ea078fcf
@ -11,6 +11,7 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QUrl>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "alligatorsettings.h"
|
||||
#include "database.h"
|
||||
@ -156,13 +157,12 @@ void Database::addFeed(QString url)
|
||||
Fetcher::instance().fetch(urlFromInput.toString());
|
||||
}
|
||||
|
||||
void Database::importFeedsFromUrl(QString url)
|
||||
void Database::importFeeds(QString path)
|
||||
{
|
||||
QFile *file = new QFile(QUrl(url).toLocalFile());
|
||||
file->open(QIODevice::ReadOnly);
|
||||
QFile file(QUrl(path).toLocalFile());
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
QXmlStreamReader xmlReader;
|
||||
xmlReader.setDevice(file);
|
||||
QXmlStreamReader xmlReader(&file);
|
||||
while(!xmlReader.atEnd()) {
|
||||
xmlReader.readNext();
|
||||
if(xmlReader.tokenType() == 4 && xmlReader.attributes().hasAttribute(QStringLiteral("xmlUrl"))) {
|
||||
@ -171,3 +171,28 @@ void Database::importFeedsFromUrl(QString url)
|
||||
}
|
||||
Fetcher::instance().fetchAll();
|
||||
}
|
||||
|
||||
void Database::exportFeeds(QString path)
|
||||
{
|
||||
QFile file(QUrl(path).toLocalFile());
|
||||
file.open(QIODevice::WriteOnly);
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument(QStringLiteral("1.0"));
|
||||
xmlWriter.writeStartElement(QStringLiteral("opml"));
|
||||
xmlWriter.writeEmptyElement(QStringLiteral("head"));
|
||||
xmlWriter.writeStartElement(QStringLiteral("body"));
|
||||
xmlWriter.writeAttribute(QStringLiteral("version"), QStringLiteral("1.0"));
|
||||
QSqlQuery query;
|
||||
query.prepare(QStringLiteral("SELECT url, name FROM Feeds;"));
|
||||
execute(query);
|
||||
while(query.next()) {
|
||||
xmlWriter.writeEmptyElement(QStringLiteral("outline"));
|
||||
xmlWriter.writeAttribute(QStringLiteral("xmlUrl"), query.value(0).toString());
|
||||
xmlWriter.writeAttribute(QStringLiteral("title"), query.value(1).toString());
|
||||
}
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndDocument();
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ public:
|
||||
bool execute(QSqlQuery &query);
|
||||
bool execute(QString query);
|
||||
Q_INVOKABLE void addFeed(QString url);
|
||||
Q_INVOKABLE void importFeedsFromUrl(QString url);
|
||||
Q_INVOKABLE void importFeeds(QString path);
|
||||
Q_INVOKABLE void exportFeeds(QString path);
|
||||
|
||||
Q_SIGNALS:
|
||||
void feedAdded(QString url);
|
||||
|
@ -36,6 +36,11 @@ Kirigami.ScrollablePage {
|
||||
text: i18n("Import Feeds...")
|
||||
iconName: "document-import"
|
||||
onTriggered: importDialog.open()
|
||||
},
|
||||
Kirigami.Action {
|
||||
text: i18n("Export Feeds...")
|
||||
iconName: "document-export"
|
||||
onTriggered: exportDialog.open()
|
||||
}
|
||||
]
|
||||
|
||||
@ -75,7 +80,16 @@ Kirigami.ScrollablePage {
|
||||
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)
|
||||
nameFilters: [i18n("All Files (*)"), i18n("XML Files (*.xml)"), i18n("OPML Files (*.opml)")]
|
||||
onAccepted: Database.importFeeds(file)
|
||||
}
|
||||
|
||||
FileDialog {
|
||||
id: exportDialog
|
||||
title: i18n("Export Feeds")
|
||||
folder: StandardPaths.writableLocation(StandardPaths.HomeLocation)
|
||||
nameFilters: [i18n("All Files")]
|
||||
onAccepted: Database.exportFeeds(file)
|
||||
fileMode: FileDialog.SaveFile
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user