1 #include <QDomDocument>
3 #include <QImageReader>
24 #define LOC QString("RSSEditor: ")
25 #define LOC_WARN QString("RSSEditor, Warning: ")
26 #define LOC_ERR QString("RSSEditor, Error: ")
30 const QString CEID_NEWIMAGE =
"image";
32 QStringList GetSupportedImageExtensionFilter()
36 QList<QByteArray> exts = QImageReader::supportedImageFormats();
37 for (QList<QByteArray>::iterator
p = exts.begin();
p != exts.end(); ++
p)
39 ret.append(QString(
"*.").append(*
p));
51 const QString &
url,
bool edit,
55 m_urlText(url), m_editing(edit),
56 m_thumbImage(NULL), m_thumbButton(NULL),
57 m_urlEdit(NULL), m_titleEdit(NULL),
58 m_descEdit(NULL), m_authorEdit(NULL),
59 m_okButton(NULL), m_cancelButton(NULL),
60 m_download(NULL), m_manager(NULL),
96 LOG(VB_GENERAL, LOG_ERR,
"Cannot load screen 'rsseditpopup'");
119 if (!thumb.isEmpty())
139 bool handled =
false;
185 const QUrl& oldRedirectUrl)
const
188 if(!possibleRedirectUrl.isEmpty() && possibleRedirectUrl != oldRedirectUrl)
189 redirectUrl = possibleRedirectUrl;
195 QVariant possibleRedirectUrl =
196 reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
198 QUrl urlRedirectedTo;
200 possibleRedirectUrl.toUrl(), urlRedirectedTo);
202 if(!urlRedirectedTo.isEmpty())
205 m_manager->get(QNetworkRequest(urlRedirectedTo));
212 reply->deleteLater();
217 QDomDocument document;
218 document.setContent(reply->read(reply->bytesAvailable()),
true);
220 QString text = document.toString();
227 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Text to Parse: %1").arg(text));
229 QDomElement root = document.documentElement();
230 QDomElement channel = root.firstChildElement (
"channel");
231 if (!channel.isNull ())
235 title = channel.firstChildElement(
"title").text().trimmed();
236 if (description.isEmpty())
237 description = channel.firstChildElement(
"description").text();
238 if (author.isEmpty())
240 if (author.isEmpty())
241 author = channel.firstChildElement(
"managingEditor").text();
242 if (author.isEmpty())
243 author = channel.firstChildElement(
"webMaster").text();
245 QString thumbnailURL = channel.firstChildElement(
"image").attribute(
"url");
246 if (thumbnailURL.isEmpty())
248 QDomElement thumbElem = channel.firstChildElement(
"image");
249 if (!thumbElem.isNull())
250 thumbnailURL = thumbElem.firstChildElement(
"url").text();
252 if (thumbnailURL.isEmpty())
254 QDomNodeList nodes = channel.elementsByTagNameNS(
255 "http://www.itunes.com/dtds/podcast-1.0.dtd",
"image");
258 thumbnailURL = nodes.at(0).toElement().attributeNode(
"href").value();
259 if (thumbnailURL.isEmpty())
260 thumbnailURL = nodes.at(0).toElement().text();
271 QString filename(
"");
278 if (!thumbnailURL.isEmpty() && filename.isEmpty())
282 QDir dir(fileprefix);
284 dir.mkdir(fileprefix);
286 fileprefix +=
"/MythNetvision";
288 dir = QDir(fileprefix);
290 dir.mkdir(fileprefix);
292 fileprefix +=
"/sitecovers";
294 dir = QDir(fileprefix);
296 dir.mkdir(fileprefix);
298 QFileInfo fi(thumbnailURL);
299 QString rawFilename = fi.fileName();
301 filename = QString(
"%1/%2").arg(fileprefix).arg(rawFilename);
320 QObject &inst,
const QString &returnEvent)
341 if (dce->
GetId() == CEID_NEWIMAGE)
352 m_changed(
false), m_sites(NULL), m_new(NULL), m_delete(NULL), m_edit(NULL),
353 m_image(NULL), m_title(NULL),
m_url(NULL),
m_desc(NULL), m_author(NULL)
359 QMutexLocker locker(&
m_lock);
367 QMutexLocker locker(&
m_lock);
389 LOG(VB_GENERAL, LOG_ERR,
"Cannot load screen 'rsseditor'");
396 connect(
m_delete, SIGNAL(Clicked(
void)),
398 connect(
m_edit, SIGNAL(Clicked(
void)),
400 connect(
m_new, SIGNAL(Clicked(
void)),
442 bool handled =
false;
446 for (
int i = 0; i < actions.size() && !handled; i++)
448 QString
action = actions[i];
472 QMutexLocker locker(&
m_lock);
476 for (RSSSite::rssList::iterator i =
m_siteList.begin();
483 item->
SetText((*i)->GetTitle(),
"title");
484 item->
SetText((*i)->GetDescription(),
"description");
485 item->
SetText((*i)->GetURL(),
"url");
486 item->
SetText((*i)->GetAuthor(),
"author");
487 item->
SetData(qVariantFromValue(*i));
507 if (!thumb.isEmpty())
526 QMutexLocker locker(&
m_lock);
528 QString message = tr(
"Are you sure you want to unsubscribe from this feed?");
535 if (confirmdialog->
Create())
539 connect(confirmdialog, SIGNAL(haveResult(
bool)),
543 delete confirmdialog;
548 QMutexLocker locker(&
m_lock);
558 if (rsseditpopup->
Create())
560 connect(rsseditpopup, SIGNAL(saving()),
this,
574 QMutexLocker locker(&
m_lock);
580 if (rsseditpopup->
Create())
582 connect(rsseditpopup, SIGNAL(saving()),
this,
595 QMutexLocker locker(&
m_lock);