Fix stream export
This commit is contained in:
@@ -229,15 +229,28 @@ void StreamsPage::importXml()
|
||||
void StreamsPage::exportXml()
|
||||
{
|
||||
QModelIndexList selected=view->selectedIndexes();
|
||||
QModelIndexList mapped;
|
||||
QSet<StreamsModel::Item *> items;
|
||||
QSet<StreamsModel::Item *> categories;
|
||||
foreach (const QModelIndex &idx, selected) {
|
||||
mapped.append(proxy.mapToSource(idx));
|
||||
QModelIndex i=proxy.mapToSource(idx);
|
||||
StreamsModel::Item *itm=static_cast<StreamsModel::Item *>(i.internalPointer());
|
||||
if (itm->isCategory()) {
|
||||
if (!categories.contains(itm)) {
|
||||
categories.insert(itm);
|
||||
}
|
||||
foreach (StreamsModel::StreamItem *s, static_cast<StreamsModel::CategoryItem *>(itm)->streams) {
|
||||
items.insert(s);
|
||||
}
|
||||
} else {
|
||||
items.insert(itm);
|
||||
categories.insert(static_cast<StreamsModel::StreamItem *>(itm)->parent);
|
||||
}
|
||||
}
|
||||
|
||||
QString name;
|
||||
|
||||
if (1==mapped.count()) {
|
||||
name=static_cast<StreamsModel::StreamItem*>(mapped.first().internalPointer())->name+QLatin1String(".cantata");
|
||||
if (1==categories.count()) {
|
||||
name=static_cast<StreamsModel::StreamItem *>(*(categories.begin()))->name+QLatin1String(".cantata");
|
||||
}
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
QString fileName=KFileDialog::getSaveFileName(name, i18n("*.cantata|Cantata Streams"), this, i18n("Export Streams"));
|
||||
@@ -249,7 +262,7 @@ void StreamsPage::exportXml()
|
||||
return;
|
||||
}
|
||||
|
||||
if (!model.save(fileName, mapped)) {
|
||||
if (!model.save(fileName, categories+items)) {
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
KMessageBox::error(this, i18n("Failed to create <b>%1</b>!", fileName));
|
||||
#else
|
||||
|
||||
@@ -284,7 +284,7 @@ bool StreamsModel::load(const QString &filename, bool isInternal)
|
||||
return haveInserted;
|
||||
}
|
||||
|
||||
bool StreamsModel::save(const QString &filename, const QModelIndexList &selection)
|
||||
bool StreamsModel::save(const QString &filename, const QSet<StreamsModel::Item *> &selection)
|
||||
{
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
@@ -293,31 +293,30 @@ bool StreamsModel::save(const QString &filename, const QModelIndexList &selectio
|
||||
|
||||
QDomDocument doc;
|
||||
QDomElement root = doc.createElement("cantata");
|
||||
QSet<const Item *> selectedItems;
|
||||
foreach (const QModelIndex &idx, selection) {
|
||||
selectedItems.insert(static_cast<const Item *>(idx.internalPointer()));
|
||||
}
|
||||
|
||||
root.setAttribute("version", "1.0");
|
||||
doc.appendChild(root);
|
||||
foreach (const CategoryItem *c, items) {
|
||||
if (selectedItems.isEmpty() || selectedItems.contains(c)) {
|
||||
foreach (CategoryItem *c, items) {
|
||||
if (selection.isEmpty() || selection.contains(c)) {
|
||||
QDomElement cat = doc.createElement("category");
|
||||
cat.setAttribute("name", c->name);
|
||||
if (!c->icon.isEmpty() && c->icon!=constDefaultCategoryIcon) {
|
||||
cat.setAttribute("icon", c->icon);
|
||||
}
|
||||
root.appendChild(cat);
|
||||
foreach (const StreamItem *s, c->streams) {
|
||||
QDomElement stream = doc.createElement("stream");
|
||||
stream.setAttribute("name", s->name);
|
||||
stream.setAttribute("url", s->url.toString());
|
||||
if (!s->icon.isEmpty() && s->icon!=constDefaultStreamIcon) {
|
||||
stream.setAttribute("icon", s->icon);
|
||||
foreach (StreamItem *s, c->streams) {
|
||||
if (selection.isEmpty() || selection.contains(s)) {
|
||||
QDomElement stream = doc.createElement("stream");
|
||||
stream.setAttribute("name", s->name);
|
||||
stream.setAttribute("url", s->url.toString());
|
||||
if (!s->icon.isEmpty() && s->icon!=constDefaultStreamIcon) {
|
||||
stream.setAttribute("icon", s->icon);
|
||||
}
|
||||
if (!s->genre.isEmpty()) {
|
||||
stream.setAttribute("genre", s->genre);
|
||||
}
|
||||
cat.appendChild(stream);
|
||||
}
|
||||
if (!s->genre.isEmpty()) {
|
||||
stream.setAttribute("genre", s->genre);
|
||||
}
|
||||
cat.appendChild(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
QVariant data(const QModelIndex &, int) const;
|
||||
void reload();
|
||||
void save(bool force=false);
|
||||
bool save(const QString &filename, const QModelIndexList &selection=QModelIndexList());
|
||||
bool save(const QString &filename, const QSet<StreamsModel::Item *> &selection=QSet<StreamsModel::Item *>());
|
||||
bool import(const QString &filename) { return load(filename, false); }
|
||||
bool add(const QString &cat, const QString &name, const QString &genre, const QString &icon, const QString &url);
|
||||
void editCategory(const QModelIndex &index, const QString &name, const QString &icon);
|
||||
|
||||
Reference in New Issue
Block a user