diff --git a/src/rss/rss.pri b/src/rss/rss.pri index 3265eac1e..2dbcec27e 100644 --- a/src/rss/rss.pri +++ b/src/rss/rss.pri @@ -13,6 +13,7 @@ HEADERS += $$PWD/rss_imp.h \ $$PWD/rssdownloadrule.h \ $$PWD/rssdownloadrulelist.h \ $$PWD/cookiesdlg.h \ + $$PWD/rssarticle_p.h SOURCES += $$PWD/rss_imp.cpp \ $$PWD/rsssettingsdlg.cpp \ diff --git a/src/rss/rssarticle.cpp b/src/rss/rssarticle.cpp index f36ca488c..8a557e93e 100644 --- a/src/rss/rssarticle.cpp +++ b/src/rss/rssarticle.cpp @@ -35,6 +35,7 @@ #include #include "rssarticle.h" +#include "rssarticle_p.h" static const char shortDay[][4] = { "Mon", "Tue", "Wed", @@ -190,7 +191,10 @@ QDateTime RssArticle::parseDate(const QString &string) { } // public constructor -RssArticle::RssArticle(RssFeed* parent, QXmlStreamReader& xml): m_parent(parent), m_read(false) { +RssArticle::RssArticle(RssFeed* parent, QXmlStreamReader& xml) +{ + d = new RssArticleData; + d->parent = parent; while(!xml.atEnd()) { xml.readNext(); @@ -199,55 +203,65 @@ RssArticle::RssArticle(RssFeed* parent, QXmlStreamReader& xml): m_parent(parent) if(xml.isStartElement()) { if(xml.name() == "title") { - m_title = xml.readElementText(); + d->title = xml.readElementText(); } else if(xml.name() == "enclosure") { if(xml.attributes().value("type") == "application/x-bittorrent") { - m_torrentUrl = xml.attributes().value("url").toString(); + d->torrentUrl = xml.attributes().value("url").toString(); } } else if(xml.name() == "link") { - m_link = xml.readElementText(); - if(m_guid.isEmpty()) - m_guid = m_link; + d->link = xml.readElementText(); + if(d->guid.isEmpty()) + d->guid = d->link; } else if(xml.name() == "description") { - m_description = xml.readElementText(); + d->description = xml.readElementText(); } else if(xml.name() == "pubDate") { - m_date = parseDate(xml.readElementText()); + d->date = parseDate(xml.readElementText()); } else if(xml.name() == "author") { - m_author = xml.readElementText(); + d->author = xml.readElementText(); } else if(xml.name() == "guid") { - m_guid = xml.readElementText(); + d->guid = xml.readElementText(); } } } } -RssArticle::RssArticle(RssFeed* parent, const QString &guid): - m_parent(parent), m_guid(guid), m_read(false) { +RssArticle::RssArticle(RssFeed* parent, const QString &guid) { + d = new RssArticleData; + d->parent = parent; + d->guid = guid; } -RssArticle::~RssArticle(){ +RssArticle::~RssArticle() {} + +RssArticle::RssArticle(const RssArticle& other): d(other.d) { +} + +RssArticle & RssArticle::operator =(const RssArticle &other) +{ + d = other.d; + return *this; } bool RssArticle::hasAttachment() const { - return !m_torrentUrl.isEmpty(); + return !d->torrentUrl.isEmpty(); } QVariantHash RssArticle::toHash() const { QVariantHash item; - item["title"] = m_title; - item["id"] = m_guid; - item["torrent_url"] = m_torrentUrl; - item["news_link"] = m_link; - item["description"] = m_description; - item["date"] = m_date; - item["author"] = m_author; - item["read"] = m_read; + item["title"] = d->title; + item["id"] = d->guid; + item["torrent_url"] = d->torrentUrl; + item["news_link"] = d->link; + item["description"] = d->description; + item["date"] = d->date; + item["author"] = d->author; + item["read"] = d->read; return item; } @@ -255,52 +269,62 @@ RssArticle hashToRssArticle(RssFeed* parent, const QVariantHash &h) { const QString guid = h.value("id").toString(); if(guid.isEmpty()) return RssArticle(); RssArticle art(parent, guid); - art.m_title = h.value("title", "").toString(); - art.m_torrentUrl = h.value("torrent_url", "").toString(); - art.m_link = h.value("news_link", "").toString(); - art.m_description = h.value("description").toString(); - art.m_date = h.value("date").toDateTime(); - art.m_author = h.value("author").toString(); - art.m_read = h.value("read").toBool(); + art.d->title = h.value("title", "").toString(); + art.d->torrentUrl = h.value("torrent_url", "").toString(); + art.d->link = h.value("news_link", "").toString(); + art.d->description = h.value("description").toString(); + art.d->date = h.value("date").toDateTime(); + art.d->author = h.value("author").toString(); + art.d->read = h.value("read").toBool(); Q_ASSERT(art.isValid()); return art; } RssFeed* RssArticle::parent() const { - return m_parent; + return d->parent; } bool RssArticle::isValid() const { - return !m_guid.isEmpty(); + return !d->guid.isEmpty(); } QString RssArticle::author() const { - return m_author; + return d->author; } QString RssArticle::torrentUrl() const{ - return m_torrentUrl; + return d->torrentUrl; } QString RssArticle::link() const { - return m_link; + return d->link; } QString RssArticle::description() const{ - if(m_description.isNull()) + if(d->description.isNull()) return ""; - return m_description; + return d->description; } QDateTime RssArticle::date() const { - return m_date; + return d->date; } bool RssArticle::isRead() const{ - return m_read; + return d->read; } void RssArticle::markAsRead(){ - m_read = true; + d->read = true; +} + +QString RssArticle::guid() const +{ + return d->guid; +} + +QString RssArticle::title() const +{ + return d->title; } diff --git a/src/rss/rssarticle.h b/src/rss/rssarticle.h index 7441de451..172bb96bc 100644 --- a/src/rss/rssarticle.h +++ b/src/rss/rssarticle.h @@ -34,8 +34,10 @@ #include #include #include +#include class RssFeed; +class RssArticleData; // Item of a rss stream, single information class RssArticle { @@ -43,13 +45,15 @@ class RssArticle { public: RssArticle(RssFeed* parent, QXmlStreamReader& xml); RssArticle(RssFeed* parent = 0, const QString &guid = QString()); + RssArticle(const RssArticle& other); // Copy constructor + RssArticle& operator=(const RssArticle& other); ~RssArticle(); // Accessors bool isValid() const; bool hasAttachment() const; - inline QString guid() const { return m_guid; } + QString guid() const; RssFeed* parent() const; - inline QString title() const { return m_title; } + QString title() const; QString author() const; QString torrentUrl() const; QString link() const; @@ -66,15 +70,7 @@ private: static QDateTime parseDate(const QString &string); private: - RssFeed* m_parent; - QString m_guid; - QString m_title; - QString m_torrentUrl; - QString m_link; - QString m_description; - QDateTime m_date; - QString m_author; - bool m_read; + QExplicitlySharedDataPointer d; }; RssArticle hashToRssArticle(RssFeed* parent, const QVariantHash &hash); diff --git a/src/rss/rssarticle_p.h b/src/rss/rssarticle_p.h new file mode 100644 index 000000000..20cfdc8e1 --- /dev/null +++ b/src/rss/rssarticle_p.h @@ -0,0 +1,61 @@ +/* + * Bittorrent Client using Qt4 and libtorrent. + * Copyright (C) 2010 Christophe Dumez, Arnaud Demaiziere + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * 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 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. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + * + * Contact: chris@qbittorrent.org, arnaud@qbittorrent.org + */ + +#ifndef RSSARTICLE_P_H +#define RSSARTICLE_P_H + +#include +#include +#include + +class RssFeed; + +class RssArticleData: public QSharedData { +public: + RssArticleData(): QSharedData(), read(false) {} + ~RssArticleData() {} + RssArticleData(const RssArticleData& other): + QSharedData(other), parent(other.parent), + guid(other.guid), title(other.title), torrentUrl(other.torrentUrl), + link(other.link), description(other.description), date(other.date), + author(other.author), read(other.read) {} + + RssFeed* parent; + QString guid; + QString title; + QString torrentUrl; + QString link; + QString description; + QDateTime date; + QString author; + bool read; +}; + +#endif // RSSARTICLE_P_H