Slot refactoring
This commit is contained in:
parent
4027ed0c4f
commit
9149de6eb9
|
@ -16,25 +16,25 @@
|
||||||
|
|
||||||
AtomFeed::AtomFeed()
|
AtomFeed::AtomFeed()
|
||||||
{
|
{
|
||||||
title = BString("Untitled Feed");
|
fTitle = BString("Untitled Feed");
|
||||||
cachePath = BString("");
|
fCachePath = BString("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AtomFeed::AtomFeed(Feed* feed)
|
AtomFeed::AtomFeed(Feed* feed)
|
||||||
: AtomFeed::AtomFeed()
|
: AtomFeed::AtomFeed()
|
||||||
{
|
{
|
||||||
SetXmlUrl(feed->GetXmlUrl());
|
SetXmlUrl(feed->XmlUrl());
|
||||||
SetCachePath(feed->GetCachePath());
|
SetCachePath(feed->CachePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AtomFeed::Parse ()
|
AtomFeed::Parse()
|
||||||
{
|
{
|
||||||
entries = BObjectList<Entry>(5, true);
|
fEntries = BObjectList<Entry>(5, true);
|
||||||
tinyxml2::XMLDocument xml;
|
tinyxml2::XMLDocument xml;
|
||||||
xml.LoadFile(GetCachePath().String());
|
xml.LoadFile(CachePath().String());
|
||||||
|
|
||||||
Feed::Parse();
|
Feed::Parse();
|
||||||
|
|
||||||
|
@ -54,17 +54,17 @@ AtomFeed::RootParse(tinyxml2::XMLElement* xfeed)
|
||||||
|
|
||||||
bool set = false;
|
bool set = false;
|
||||||
|
|
||||||
SetTitle(xfeed->FirstChildElement("title"));
|
_SetTitle(xfeed->FirstChildElement("title"));
|
||||||
|
|
||||||
set = SetDate(xfeed->FirstChildElement("updated"));
|
set = _SetDate(xfeed->FirstChildElement("updated"));
|
||||||
if (!set)
|
if (!set)
|
||||||
set = SetDate(xfeed->FirstChildElement("published"));
|
set = _SetDate(xfeed->FirstChildElement("published"));
|
||||||
if (!set && xentry)
|
if (!set && xentry)
|
||||||
set = SetDate(xentry->FirstChildElement("updated"));
|
set = _SetDate(xentry->FirstChildElement("updated"));
|
||||||
if (!set && xentry)
|
if (!set && xentry)
|
||||||
set = SetDate(xentry->FirstChildElement("published"));
|
set = _SetDate(xentry->FirstChildElement("published"));
|
||||||
|
|
||||||
std::cout << "Channel '" << title << "' at '" << xmlUrl.UrlString()
|
std::cout << "Channel '" << fTitle << "' at '" << fXmlUrl.UrlString()
|
||||||
<< "':\n";
|
<< "':\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,28 +80,29 @@ AtomFeed::EntryParse(tinyxml2::XMLElement* xentry)
|
||||||
|
|
||||||
newEntry->SetTitle(xentry->FirstChildElement("title"));
|
newEntry->SetTitle(xentry->FirstChildElement("title"));
|
||||||
newEntry->SetPostUrl(xentry->FirstChildElement("link")->Attribute("href"));
|
newEntry->SetPostUrl(xentry->FirstChildElement("link")->Attribute("href"));
|
||||||
newEntry->SetFeedTitle(title);
|
newEntry->SetFeedTitle(fTitle);
|
||||||
|
|
||||||
bool set = false;
|
bool set = false;
|
||||||
set = newEntry->SetDesc(xentry->FirstChildElement("summary"));
|
set = newEntry->SetDescription(xentry->FirstChildElement("summary"));
|
||||||
if (!set)
|
if (!set)
|
||||||
set = newEntry->SetDesc(xentry->FirstChildElement("description"));
|
set = newEntry->SetDescription(xentry->FirstChildElement("description"));
|
||||||
if (!set && xmedia)
|
if (!set && xmedia)
|
||||||
set = newEntry->SetDesc(xmedia->FirstChildElement("media:description"));
|
set = newEntry->SetDescription(
|
||||||
|
xmedia->FirstChildElement("media:description"));
|
||||||
|
|
||||||
set = newEntry->SetDate(xentry->FirstChildElement("updated"));
|
set = newEntry->SetDate(xentry->FirstChildElement("updated"));
|
||||||
if (!set)
|
if (!set)
|
||||||
set = newEntry->SetDate(xentry->FirstChildElement("published"));
|
set = newEntry->SetDate(xentry->FirstChildElement("published"));
|
||||||
|
|
||||||
if (date == NULL || date < newEntry->GetDate())
|
if (fDate == NULL || fDate < newEntry->Date())
|
||||||
SetDate(newEntry->GetDate());
|
_SetDate(newEntry->Date());
|
||||||
|
|
||||||
if (xcontent) {
|
if (xcontent) {
|
||||||
xcontent->Accept(&xprinter);
|
xcontent->Accept(&xprinter);
|
||||||
newEntry->SetContent(xprinter.CStr());
|
newEntry->SetContent(xprinter.CStr());
|
||||||
}
|
}
|
||||||
|
|
||||||
AddEntry(newEntry);
|
_AddEntry(newEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,8 +113,8 @@ AtomFeed::ParseEntries(tinyxml2::XMLElement* xfeed)
|
||||||
|
|
||||||
xentry = xfeed->FirstChildElement("entry");
|
xentry = xfeed->FirstChildElement("entry");
|
||||||
|
|
||||||
int entryCount = xmlCountSiblings(xentry, "entry");
|
int entryCount = _XmlCountSiblings(xentry, "entry");
|
||||||
entries = BObjectList<Entry>(entryCount, true);
|
fEntries = BObjectList<Entry>(entryCount, true);
|
||||||
|
|
||||||
std::cout << "\t-" << entryCount << "-\n";
|
std::cout << "\t-" << entryCount << "-\n";
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,13 @@
|
||||||
|
|
||||||
|
|
||||||
Entry::Entry()
|
Entry::Entry()
|
||||||
|
:
|
||||||
|
fTitle(BString()),
|
||||||
|
fDescription(BString()),
|
||||||
|
fFeedTitle(BString()),
|
||||||
|
fPostUrl(BString()),
|
||||||
|
fContent(BString())
|
||||||
{
|
{
|
||||||
title = BString("");
|
|
||||||
description = BString("");
|
|
||||||
feedTitle = BString("");
|
|
||||||
postUrl = BString("");
|
|
||||||
content = BString("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,43 +31,50 @@ Entry::~Entry()
|
||||||
bool
|
bool
|
||||||
Entry::Filetize(BDirectory outDir)
|
Entry::Filetize(BDirectory outDir)
|
||||||
{
|
{
|
||||||
BFile file(title.String(), B_READ_WRITE);
|
BFile file(fTitle.String(), B_READ_WRITE);
|
||||||
BEntry outDirEntry;
|
BEntry outDirEntry;
|
||||||
time_t tt_date = date.Time_t();
|
time_t tt_date = fDate.Time_t();
|
||||||
|
|
||||||
outDir.GetEntry(&outDirEntry);
|
outDir.GetEntry(&outDirEntry);
|
||||||
if (outDir.InitCheck() == B_ENTRY_NOT_FOUND) {
|
if (outDir.InitCheck() == B_ENTRY_NOT_FOUND) {
|
||||||
outDir.CreateDirectory(BPath(&outDirEntry).Path(), &outDir);
|
outDir.CreateDirectory(BPath(&outDirEntry).Path(), &outDir);
|
||||||
}
|
}
|
||||||
outDir.CreateFile(title.String(), &file);
|
outDir.CreateFile(fTitle.String(), &file);
|
||||||
|
|
||||||
BString betype = BString("text/x-feed-entry");
|
BString betype = BString("text/x-feed-entry");
|
||||||
file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0, betype.String(),
|
file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0, betype.String(),
|
||||||
betype.CountChars() + 1);
|
betype.CountChars() + 1);
|
||||||
|
|
||||||
file.WriteAttr("Feed:name", B_STRING_TYPE, 0,
|
file.WriteAttr("Feed:name", B_STRING_TYPE, 0,
|
||||||
title.String(), title.CountChars());
|
fTitle.String(), fTitle.CountChars());
|
||||||
file.WriteAttr("Feed:description", B_STRING_TYPE, 0,
|
file.WriteAttr("Feed:description", B_STRING_TYPE, 0,
|
||||||
description.String(), description.CountChars());
|
fDescription.String(), fDescription.CountChars());
|
||||||
file.WriteAttr("Feed:source", B_STRING_TYPE, 0,
|
file.WriteAttr("Feed:source", B_STRING_TYPE, 0,
|
||||||
feedTitle.String(), feedTitle.CountChars());
|
fFeedTitle.String(), fFeedTitle.CountChars());
|
||||||
file.WriteAttr("META:url", B_STRING_TYPE, 0, postUrl.String(),
|
file.WriteAttr("META:url", B_STRING_TYPE, 0, fPostUrl.String(),
|
||||||
postUrl.CountChars());
|
fPostUrl.CountChars());
|
||||||
|
|
||||||
if (date != NULL) {
|
if (fDate != NULL) {
|
||||||
file.WriteAttr("Feed:when", B_TIME_TYPE, 0, &tt_date, sizeof(time_t));
|
file.WriteAttr("Feed:when", B_TIME_TYPE, 0, &tt_date, sizeof(time_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
file.Write(content.String(), content.Length());
|
file.Write(fContent.String(), fContent.Length());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
Entry::Title()
|
||||||
|
{
|
||||||
|
return fTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Entry::SetTitle(const char* titleStr)
|
Entry::SetTitle(const char* titleStr)
|
||||||
{
|
{
|
||||||
if (titleStr != NULL)
|
if (titleStr != NULL)
|
||||||
title = BString(titleStr);
|
fTitle = BString(titleStr);
|
||||||
else return false;
|
else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -81,40 +89,61 @@ Entry::SetTitle(tinyxml2::XMLElement* elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
Entry::Description()
|
||||||
|
{
|
||||||
|
return fDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Entry::SetDesc(const char* descStr)
|
Entry::SetDescription(const char* descStr)
|
||||||
{
|
{
|
||||||
if (descStr != NULL)
|
if (descStr != NULL)
|
||||||
description = BString(descStr);
|
fDescription = BString(descStr);
|
||||||
else return false;
|
else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Entry::SetDesc(tinyxml2::XMLElement* elem)
|
Entry::SetDescription(tinyxml2::XMLElement* elem)
|
||||||
{
|
{
|
||||||
if (elem != NULL)
|
if (elem != NULL)
|
||||||
return SetDesc(elem->GetText());
|
return SetDescription(elem->GetText());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
Entry::FeedTitle()
|
||||||
|
{
|
||||||
|
return fFeedTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Entry::SetFeedTitle(BString titleStr)
|
Entry::SetFeedTitle(BString titleStr)
|
||||||
{
|
{
|
||||||
if (titleStr != NULL)
|
if (titleStr != NULL)
|
||||||
feedTitle = titleStr;
|
fFeedTitle = titleStr;
|
||||||
else return false;
|
else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
Entry::Content()
|
||||||
|
{
|
||||||
|
return fContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Entry::SetContent(const char* contentStr)
|
Entry::SetContent(const char* contentStr)
|
||||||
{
|
{
|
||||||
if (contentStr != NULL)
|
if (contentStr != NULL)
|
||||||
content = BString(contentStr);
|
fContent = BString(contentStr);
|
||||||
else return false;
|
else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -129,11 +158,18 @@ Entry::SetContent(tinyxml2::XMLElement* elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
Entry::PostUrl()
|
||||||
|
{
|
||||||
|
return fPostUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Entry::SetPostUrl(const char* urlStr)
|
Entry::SetPostUrl(const char* urlStr)
|
||||||
{
|
{
|
||||||
if (urlStr != NULL)
|
if (urlStr != NULL)
|
||||||
postUrl = BString(urlStr);
|
fPostUrl = BString(urlStr);
|
||||||
else return false;
|
else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -148,6 +184,13 @@ Entry::SetPostUrl(tinyxml2::XMLElement* elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BDateTime
|
||||||
|
Entry::Date()
|
||||||
|
{
|
||||||
|
return fDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Entry::SetDate(const char* dateStr)
|
Entry::SetDate(const char* dateStr)
|
||||||
{
|
{
|
||||||
|
@ -156,7 +199,7 @@ Entry::SetDate(const char* dateStr)
|
||||||
BDateTime newDate = feedDateToBDate(dateStr);
|
BDateTime newDate = feedDateToBDate(dateStr);
|
||||||
if (newDate == NULL)
|
if (newDate == NULL)
|
||||||
return false;
|
return false;
|
||||||
date = newDate;
|
fDate = newDate;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,10 +213,3 @@ Entry::SetDate(tinyxml2::XMLElement* elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BDateTime
|
|
||||||
Entry::GetDate()
|
|
||||||
{
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
30
src/Entry.h
30
src/Entry.h
|
@ -22,25 +22,37 @@ public:
|
||||||
|
|
||||||
bool Filetize(BDirectory outDir);
|
bool Filetize(BDirectory outDir);
|
||||||
|
|
||||||
|
BString Title();
|
||||||
bool SetTitle(const char*);
|
bool SetTitle(const char*);
|
||||||
bool SetTitle(tinyxml2::XMLElement*);
|
bool SetTitle(tinyxml2::XMLElement*);
|
||||||
bool SetDesc(const char*);
|
|
||||||
bool SetDesc(tinyxml2::XMLElement*);
|
BString Description();
|
||||||
|
bool SetDescription(const char*);
|
||||||
|
bool SetDescription(tinyxml2::XMLElement*);
|
||||||
|
|
||||||
|
BString FeedTitle();
|
||||||
bool SetFeedTitle(BString);
|
bool SetFeedTitle(BString);
|
||||||
|
|
||||||
|
BString Content();
|
||||||
bool SetContent(const char*);
|
bool SetContent(const char*);
|
||||||
bool SetContent(tinyxml2::XMLElement*);
|
bool SetContent(tinyxml2::XMLElement*);
|
||||||
|
|
||||||
|
BString PostUrl();
|
||||||
bool SetPostUrl(const char*);
|
bool SetPostUrl(const char*);
|
||||||
bool SetPostUrl(tinyxml2::XMLElement*);
|
bool SetPostUrl(tinyxml2::XMLElement*);
|
||||||
|
|
||||||
|
BDateTime Date();
|
||||||
bool SetDate(const char*);
|
bool SetDate(const char*);
|
||||||
bool SetDate(tinyxml2::XMLElement*);
|
bool SetDate(tinyxml2::XMLElement*);
|
||||||
BDateTime GetDate();
|
|
||||||
|
|
||||||
BString title;
|
|
||||||
BString description;
|
private:
|
||||||
BString feedTitle;
|
BString fTitle;
|
||||||
BDateTime date;
|
BString fDescription;
|
||||||
BString postUrl;
|
BString fFeedTitle;
|
||||||
BString content;
|
BDateTime fDate;
|
||||||
|
BString fPostUrl;
|
||||||
|
BString fContent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
92
src/Feed.cpp
92
src/Feed.cpp
|
@ -31,7 +31,7 @@ Feed::Feed(BUrl xml)
|
||||||
find_directory(B_USER_CACHE_DIRECTORY, &cache);
|
find_directory(B_USER_CACHE_DIRECTORY, &cache);
|
||||||
cache.Append("Pogger");
|
cache.Append("Pogger");
|
||||||
|
|
||||||
cache.Append(urlToFilename(xmlUrl));
|
cache.Append(urlToFilename(fXmlUrl));
|
||||||
SetCachePath(cache.Path());
|
SetCachePath(cache.Path());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,16 +83,16 @@ Feed::Feed(BUrl xml, BEntry entry)
|
||||||
Feed::Feed(Feed* feed)
|
Feed::Feed(Feed* feed)
|
||||||
: Feed()
|
: Feed()
|
||||||
{
|
{
|
||||||
SetTitle(feed->GetTitle());
|
SetTitle(feed->Title());
|
||||||
SetXmlUrl(feed->GetXmlUrl());
|
SetXmlUrl(feed->XmlUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Feed::Feed()
|
Feed::Feed()
|
||||||
:
|
:
|
||||||
title(BString("Untitled Feed"))
|
fTitle(BString("Untitled Feed"))
|
||||||
{
|
{
|
||||||
lastDate = BDateTime::CurrentDateTime(B_LOCAL_TIME);
|
fLastDate = BDateTime::CurrentDateTime(B_LOCAL_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,13 +104,13 @@ Feed::~Feed()
|
||||||
void
|
void
|
||||||
Feed::Parse()
|
Feed::Parse()
|
||||||
{
|
{
|
||||||
BFile feedFile = BFile(cachePath, B_READ_ONLY);
|
BFile feedFile = BFile(fCachePath, B_READ_ONLY);
|
||||||
time_t tt_lastDate = 0;
|
time_t tt_lastDate = 0;
|
||||||
|
|
||||||
feedFile.ReadAttr("Feed:when", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t));
|
feedFile.ReadAttr("Feed:when", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t));
|
||||||
|
|
||||||
if (tt_lastDate > 0)
|
if (tt_lastDate > 0)
|
||||||
lastDate.SetTime_t(tt_lastDate);
|
fLastDate.SetTime_t(tt_lastDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,12 +118,12 @@ Feed::Parse()
|
||||||
bool
|
bool
|
||||||
Feed::Fetch()
|
Feed::Fetch()
|
||||||
{
|
{
|
||||||
BFile cacheFile = BFile(cachePath, B_READ_WRITE | B_CREATE_FILE);
|
BFile cacheFile = BFile(fCachePath, B_READ_WRITE | B_CREATE_FILE);
|
||||||
|
|
||||||
cacheFile.ReadAttrString("Feed:hash", &lastHash);
|
cacheFile.ReadAttrString("Feed:hash", &fLastHash);
|
||||||
|
|
||||||
int32 result = fetch(xmlUrl, &cacheFile, &hash, 30);
|
int32 result = fetch(fXmlUrl, &cacheFile, &fHash, 30);
|
||||||
cacheFile.WriteAttrString("Feed:hash", &hash);
|
cacheFile.WriteAttrString("Feed:hash", &fHash);
|
||||||
|
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -134,10 +134,10 @@ Feed::Fetch()
|
||||||
void
|
void
|
||||||
Feed::Filetize()
|
Feed::Filetize()
|
||||||
{
|
{
|
||||||
BFile feedFile(cachePath, B_WRITE_ONLY | B_CREATE_FILE);
|
BFile feedFile(fCachePath, B_WRITE_ONLY | B_CREATE_FILE);
|
||||||
time_t tt_date = date.Time_t();
|
time_t tt_date = fDate.Time_t();
|
||||||
BString url = xmlUrl.UrlString();
|
BString url = fXmlUrl.UrlString();
|
||||||
BString name = GetTitle();
|
BString name = Title();
|
||||||
BString type("application/x-feed-source");
|
BString type("application/x-feed-source");
|
||||||
|
|
||||||
feedFile.WriteAttrString("Feed:name", &name);
|
feedFile.WriteAttrString("Feed:name", &name);
|
||||||
|
@ -152,7 +152,7 @@ Feed::Filetize()
|
||||||
void
|
void
|
||||||
Feed::Unfiletize()
|
Feed::Unfiletize()
|
||||||
{
|
{
|
||||||
BEntry entry(GetCachePath().String());
|
BEntry entry(CachePath().String());
|
||||||
entry.Remove();
|
entry.Remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ bool
|
||||||
Feed::IsRss()
|
Feed::IsRss()
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument xml;
|
tinyxml2::XMLDocument xml;
|
||||||
xml.LoadFile(cachePath.String());
|
xml.LoadFile(fCachePath.String());
|
||||||
|
|
||||||
if (xml.FirstChildElement("rss"))
|
if (xml.FirstChildElement("rss"))
|
||||||
return true;
|
return true;
|
||||||
|
@ -173,7 +173,7 @@ bool
|
||||||
Feed::IsAtom()
|
Feed::IsAtom()
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument xml;
|
tinyxml2::XMLDocument xml;
|
||||||
xml.LoadFile(cachePath.String());
|
xml.LoadFile(fCachePath.String());
|
||||||
|
|
||||||
if (xml.FirstChildElement("feed"))
|
if (xml.FirstChildElement("feed"))
|
||||||
return true;
|
return true;
|
||||||
|
@ -184,13 +184,13 @@ Feed::IsAtom()
|
||||||
bool
|
bool
|
||||||
Feed::IsUpdated()
|
Feed::IsUpdated()
|
||||||
{
|
{
|
||||||
return lastHash != hash;
|
return fLastHash != fHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Count the amount of siblings to an element of given type name
|
// Count the amount of siblings to an element of given type name
|
||||||
int
|
int
|
||||||
Feed::xmlCountSiblings (tinyxml2::XMLElement* xsibling, const char* sibling_name)
|
Feed::_XmlCountSiblings (tinyxml2::XMLElement* xsibling, const char* sibling_name)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (xsibling) {
|
while (xsibling) {
|
||||||
|
@ -202,27 +202,27 @@ Feed::xmlCountSiblings (tinyxml2::XMLElement* xsibling, const char* sibling_name
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Feed::AddEntry (Entry* newEntry)
|
Feed::_AddEntry (Entry* newEntry)
|
||||||
{
|
{
|
||||||
entries.AddItem(newEntry);
|
fEntries.AddItem(newEntry);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BObjectList<Entry>
|
BObjectList<Entry>
|
||||||
Feed::GetEntries()
|
Feed::Entries()
|
||||||
{
|
{
|
||||||
return entries;
|
return fEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BObjectList<Entry>
|
BObjectList<Entry>
|
||||||
Feed::GetNewEntries()
|
Feed::NewEntries()
|
||||||
{
|
{
|
||||||
BObjectList<Entry> newEntries;
|
BObjectList<Entry> newEntries;
|
||||||
for (int i = 0; i < entries.CountItems(); i++) {
|
for (int i = 0; i < fEntries.CountItems(); i++) {
|
||||||
Entry* entry = entries.ItemAt(i);
|
Entry* entry = fEntries.ItemAt(i);
|
||||||
if (entry->GetDate() > lastDate)
|
if (entry->Date() > fLastDate)
|
||||||
newEntries.AddItem(entry);
|
newEntries.AddItem(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,14 +234,14 @@ bool
|
||||||
Feed::SetTitle(const char* titleStr)
|
Feed::SetTitle(const char* titleStr)
|
||||||
{
|
{
|
||||||
if (titleStr != NULL)
|
if (titleStr != NULL)
|
||||||
title = BString(titleStr);
|
fTitle = BString(titleStr);
|
||||||
else return false;
|
else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Feed::SetTitle(tinyxml2::XMLElement* elem)
|
Feed::_SetTitle(tinyxml2::XMLElement* elem)
|
||||||
{
|
{
|
||||||
if (elem != NULL)
|
if (elem != NULL)
|
||||||
return SetTitle(elem->GetText());
|
return SetTitle(elem->GetText());
|
||||||
|
@ -250,76 +250,76 @@ Feed::SetTitle(tinyxml2::XMLElement* elem)
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
Feed::GetTitle()
|
Feed::Title()
|
||||||
{
|
{
|
||||||
return title;
|
return fTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Feed::SetXmlUrl(BUrl newUrl)
|
Feed::SetXmlUrl(BUrl newUrl)
|
||||||
{
|
{
|
||||||
xmlUrl = newUrl;
|
fXmlUrl = newUrl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BUrl
|
BUrl
|
||||||
Feed::GetXmlUrl()
|
Feed::XmlUrl()
|
||||||
{
|
{
|
||||||
return xmlUrl;
|
return fXmlUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Feed::SetCachePath(BString path)
|
Feed::SetCachePath(BString path)
|
||||||
{
|
{
|
||||||
cachePath = path;
|
fCachePath = path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
Feed::GetCachePath()
|
Feed::CachePath()
|
||||||
{
|
{
|
||||||
return cachePath;
|
return fCachePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set the latest date given by feed (from entry or from root)
|
// Set the latest date given by feed (from entry or from root)
|
||||||
bool
|
bool
|
||||||
Feed::SetDate(BDateTime newDate)
|
Feed::_SetDate(BDateTime newDate)
|
||||||
{
|
{
|
||||||
if (newDate == NULL)
|
if (newDate == NULL)
|
||||||
return false;
|
return false;
|
||||||
date = newDate;
|
fDate = newDate;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Feed::SetDate(const char* dateCStr)
|
Feed::_SetDate(const char* dateCStr)
|
||||||
{
|
{
|
||||||
if (dateCStr == NULL)
|
if (dateCStr == NULL)
|
||||||
return false;
|
return false;
|
||||||
SetDate(feedDateToBDate(dateCStr));
|
_SetDate(feedDateToBDate(dateCStr));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Feed::SetDate(tinyxml2::XMLElement* elem)
|
Feed::_SetDate(tinyxml2::XMLElement* elem)
|
||||||
{
|
{
|
||||||
if (elem != NULL)
|
if (elem != NULL)
|
||||||
return SetDate(elem->GetText());
|
return _SetDate(elem->GetText());
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BDateTime
|
BDateTime
|
||||||
Feed::GetDate()
|
Feed::Date()
|
||||||
{
|
{
|
||||||
return date;
|
return fDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
41
src/Feed.h
41
src/Feed.h
|
@ -33,8 +33,8 @@ public:
|
||||||
|
|
||||||
virtual void Parse();
|
virtual void Parse();
|
||||||
|
|
||||||
BObjectList<Entry> GetEntries();
|
BObjectList<Entry> Entries();
|
||||||
BObjectList<Entry> GetNewEntries();
|
BObjectList<Entry> NewEntries();
|
||||||
|
|
||||||
bool Fetch();
|
bool Fetch();
|
||||||
|
|
||||||
|
@ -45,38 +45,37 @@ public:
|
||||||
bool IsAtom();
|
bool IsAtom();
|
||||||
bool IsUpdated();
|
bool IsUpdated();
|
||||||
|
|
||||||
BString GetTitle();
|
BString Title();
|
||||||
bool SetDate(BDateTime);
|
bool SetDate(BDateTime);
|
||||||
|
|
||||||
BUrl GetXmlUrl();
|
BUrl XmlUrl();
|
||||||
BDateTime GetDate();
|
BDateTime Date();
|
||||||
|
|
||||||
bool SetTitle(const char*);
|
bool SetTitle(const char*);
|
||||||
bool SetXmlUrl(BUrl newUrl);
|
bool SetXmlUrl(BUrl newUrl);
|
||||||
bool SetCachePath(BString path);
|
bool SetCachePath(BString path);
|
||||||
|
|
||||||
BString GetCachePath();
|
BString CachePath();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool SetTitle(tinyxml2::XMLElement*);
|
bool _SetTitle(tinyxml2::XMLElement*);
|
||||||
bool SetDate(const char*);
|
bool _SetDate(const char*);
|
||||||
bool SetDate(tinyxml2::XMLElement*);
|
bool _SetDate(tinyxml2::XMLElement*);
|
||||||
|
bool _SetDate(BDateTime newDate);
|
||||||
|
|
||||||
bool AddEntry(Entry*);
|
bool _AddEntry(Entry*);
|
||||||
|
|
||||||
int xmlCountSiblings(tinyxml2::XMLElement*, const char*);
|
int _XmlCountSiblings(tinyxml2::XMLElement*, const char*);
|
||||||
|
|
||||||
BString title;
|
BString fTitle;
|
||||||
BDateTime date;
|
BDateTime fDate;
|
||||||
BDateTime lastDate;
|
BDateTime fLastDate;
|
||||||
BUrl xmlUrl;
|
BUrl fXmlUrl;
|
||||||
BString cachePath;
|
BString fCachePath;
|
||||||
BString hash;
|
BString fHash;
|
||||||
BString lastHash;
|
BString fLastHash;
|
||||||
|
|
||||||
BObjectList<Entry> entries;
|
BObjectList<Entry> fEntries;
|
||||||
bool fetched;
|
|
||||||
bool updated;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -143,8 +143,8 @@ FeedController::_ProcessQueueItem()
|
||||||
send_data(fDownloadThread, 0, (void*)buffer, sizeof(Feed));
|
send_data(fDownloadThread, 0, (void*)buffer, sizeof(Feed));
|
||||||
|
|
||||||
BMessage downloadInit = BMessage(kDownloadStart);
|
BMessage downloadInit = BMessage(kDownloadStart);
|
||||||
downloadInit.AddString("feed_name", buffer->GetTitle());
|
downloadInit.AddString("feed_name", buffer->Title());
|
||||||
downloadInit.AddString("feed_url", buffer->GetXmlUrl().UrlString());
|
downloadInit.AddString("feed_url", buffer->XmlUrl().UrlString());
|
||||||
((App*)be_app)->MessageReceived(&downloadInit);
|
((App*)be_app)->MessageReceived(&downloadInit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,9 +164,9 @@ FeedController::_ReceiveStatus()
|
||||||
case kDownloadComplete:
|
case kDownloadComplete:
|
||||||
{
|
{
|
||||||
BMessage complete = BMessage(kDownloadComplete);
|
BMessage complete = BMessage(kDownloadComplete);
|
||||||
complete.AddString("feed_name", feedBuffer->GetTitle());
|
complete.AddString("feed_name", feedBuffer->Title());
|
||||||
complete.AddString("feed_url",
|
complete.AddString("feed_url",
|
||||||
feedBuffer->GetXmlUrl().UrlString());
|
feedBuffer->XmlUrl().UrlString());
|
||||||
((App*)be_app)->MessageReceived(&complete);
|
((App*)be_app)->MessageReceived(&complete);
|
||||||
|
|
||||||
send_data(fParseThread, 0, (void*)feedBuffer, sizeof(Feed));
|
send_data(fParseThread, 0, (void*)feedBuffer, sizeof(Feed));
|
||||||
|
@ -175,9 +175,9 @@ FeedController::_ReceiveStatus()
|
||||||
case kDownloadFail:
|
case kDownloadFail:
|
||||||
{
|
{
|
||||||
BMessage failure = BMessage(kDownloadFail);
|
BMessage failure = BMessage(kDownloadFail);
|
||||||
failure.AddString("feed_name", feedBuffer->GetTitle());
|
failure.AddString("feed_name", feedBuffer->Title());
|
||||||
failure.AddString("feed_url",
|
failure.AddString("feed_url",
|
||||||
feedBuffer->GetXmlUrl().UrlString());
|
feedBuffer->XmlUrl().UrlString());
|
||||||
((App*)be_app)->MessageReceived(&failure);
|
((App*)be_app)->MessageReceived(&failure);
|
||||||
_SendProgress();
|
_SendProgress();
|
||||||
break;
|
break;
|
||||||
|
@ -185,8 +185,8 @@ FeedController::_ReceiveStatus()
|
||||||
case kParseFail:
|
case kParseFail:
|
||||||
{
|
{
|
||||||
BMessage failure = BMessage(kParseFail);
|
BMessage failure = BMessage(kParseFail);
|
||||||
failure.AddString("feed_name", feedBuffer->GetTitle());
|
failure.AddString("feed_name", feedBuffer->Title());
|
||||||
failure.AddString("feed_url", feedBuffer->GetXmlUrl().UrlString());
|
failure.AddString("feed_url", feedBuffer->XmlUrl().UrlString());
|
||||||
((App*)be_app)->MessageReceived(&failure);
|
((App*)be_app)->MessageReceived(&failure);
|
||||||
_SendProgress();
|
_SendProgress();
|
||||||
break;
|
break;
|
||||||
|
@ -194,8 +194,8 @@ FeedController::_ReceiveStatus()
|
||||||
// If parse was successful, the code is the amount of new entries
|
// If parse was successful, the code is the amount of new entries
|
||||||
default:
|
default:
|
||||||
BMessage complete = BMessage(kParseComplete);
|
BMessage complete = BMessage(kParseComplete);
|
||||||
complete.AddString("feed_name", feedBuffer->GetTitle());
|
complete.AddString("feed_name", feedBuffer->Title());
|
||||||
complete.AddString("feed_url", feedBuffer->GetXmlUrl().UrlString());
|
complete.AddString("feed_url", feedBuffer->XmlUrl().UrlString());
|
||||||
complete.AddInt32("entry_count", code);
|
complete.AddInt32("entry_count", code);
|
||||||
((App*)be_app)->MessageReceived(&complete);
|
((App*)be_app)->MessageReceived(&complete);
|
||||||
_SendProgress();
|
_SendProgress();
|
||||||
|
@ -217,7 +217,7 @@ FeedController::_DownloadLoop(void* data)
|
||||||
receive_data(&sender, (void*)feedBuffer, sizeof(Feed));
|
receive_data(&sender, (void*)feedBuffer, sizeof(Feed));
|
||||||
|
|
||||||
std::cout << "Downloading feed from "
|
std::cout << "Downloading feed from "
|
||||||
<< feedBuffer->GetXmlUrl().UrlString() << "…\n";
|
<< feedBuffer->XmlUrl().UrlString() << "…\n";
|
||||||
|
|
||||||
if (feedBuffer->Fetch()) {
|
if (feedBuffer->Fetch()) {
|
||||||
send_data(main, kDownloadComplete, (void*)feedBuffer, sizeof(Feed));
|
send_data(main, kDownloadComplete, (void*)feedBuffer, sizeof(Feed));
|
||||||
|
@ -244,15 +244,15 @@ FeedController::_ParseLoop(void* data)
|
||||||
BObjectList<Entry> entries;
|
BObjectList<Entry> entries;
|
||||||
int32 entriesCount = 0;
|
int32 entriesCount = 0;
|
||||||
BString feedTitle;
|
BString feedTitle;
|
||||||
BUrl feedUrl = feedBuffer->GetXmlUrl();
|
BUrl feedUrl = feedBuffer->XmlUrl();
|
||||||
BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->EntryDir());
|
BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->EntryDir());
|
||||||
|
|
||||||
if (feedBuffer->IsAtom() && feedBuffer->IsUpdated()) {
|
if (feedBuffer->IsAtom() && feedBuffer->IsUpdated()) {
|
||||||
AtomFeed feed(feedBuffer);
|
AtomFeed feed(feedBuffer);
|
||||||
feed.Parse();
|
feed.Parse();
|
||||||
entries = feed.GetNewEntries();
|
entries = feed.NewEntries();
|
||||||
entriesCount = entries.CountItems();
|
entriesCount = entries.CountItems();
|
||||||
feedTitle = feed.GetTitle();
|
feedTitle = feed.Title();
|
||||||
|
|
||||||
for (int i = 0; i < entriesCount; i++)
|
for (int i = 0; i < entriesCount; i++)
|
||||||
entries.ItemAt(i)->Filetize(outDir);
|
entries.ItemAt(i)->Filetize(outDir);
|
||||||
|
@ -261,9 +261,9 @@ FeedController::_ParseLoop(void* data)
|
||||||
else if (feedBuffer->IsRss() && feedBuffer->IsUpdated()) {
|
else if (feedBuffer->IsRss() && feedBuffer->IsUpdated()) {
|
||||||
RssFeed feed(feedBuffer);
|
RssFeed feed(feedBuffer);
|
||||||
feed.Parse();
|
feed.Parse();
|
||||||
entries = feed.GetNewEntries();
|
entries = feed.NewEntries();
|
||||||
entriesCount = entries.CountItems();
|
entriesCount = entries.CountItems();
|
||||||
feedTitle = feed.GetTitle();
|
feedTitle = feed.Title();
|
||||||
|
|
||||||
for (int i = 0; i < entriesCount; i++)
|
for (int i = 0; i < entriesCount; i++)
|
||||||
entries.ItemAt(i)->Filetize(outDir);
|
entries.ItemAt(i)->Filetize(outDir);
|
||||||
|
|
|
@ -39,8 +39,8 @@ FeedEditWindow::FeedEditWindow(BEntry feedEntry)
|
||||||
SetTitle("Edit Feed");
|
SetTitle("Edit Feed");
|
||||||
fFeed = Feed(feedEntry);
|
fFeed = Feed(feedEntry);
|
||||||
|
|
||||||
fFeedNameText->SetText(fFeed.GetTitle().String());
|
fFeedNameText->SetText(fFeed.Title().String());
|
||||||
fFeedUrlText->SetText(fFeed.GetXmlUrl().UrlString().String());
|
fFeedUrlText->SetText(fFeed.XmlUrl().UrlString().String());
|
||||||
|
|
||||||
fDeleteButton->SetEnabled(true);
|
fDeleteButton->SetEnabled(true);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ FeedEditWindow::FeedEditWindow(BEntry feedEntry)
|
||||||
|
|
||||||
FeedEditWindow::FeedEditWindow(FeedListItem* feedItem)
|
FeedEditWindow::FeedEditWindow(FeedListItem* feedItem)
|
||||||
:
|
:
|
||||||
FeedEditWindow(BEntry(feedItem->GetFeedPath()))
|
FeedEditWindow(BEntry(feedItem->FeedPath()))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ FeedEditWindow::_SaveFeed()
|
||||||
filename = BString(title);
|
filename = BString(title);
|
||||||
subPath.Append(filename);
|
subPath.Append(filename);
|
||||||
|
|
||||||
if (fFeed.GetCachePath().IsEmpty())
|
if (fFeed.CachePath().IsEmpty())
|
||||||
fFeed.SetCachePath(BString(subPath.Path()));
|
fFeed.SetCachePath(BString(subPath.Path()));
|
||||||
|
|
||||||
if (!title.IsEmpty())
|
if (!title.IsEmpty())
|
||||||
|
@ -171,7 +171,7 @@ FeedEditWindow::_SaveFeed()
|
||||||
|
|
||||||
BMessage edited(kFeedsEdited);
|
BMessage edited(kFeedsEdited);
|
||||||
BMessage enqueueUpdated(kEnqueueFeed);
|
BMessage enqueueUpdated(kEnqueueFeed);
|
||||||
enqueueUpdated.AddString("feedPaths", fFeed.GetCachePath());
|
enqueueUpdated.AddString("feedPaths", fFeed.CachePath());
|
||||||
|
|
||||||
((App*)be_app)->MessageReceived(&enqueueUpdated);
|
((App*)be_app)->MessageReceived(&enqueueUpdated);
|
||||||
((App*)be_app)->PostMessage(&edited);
|
((App*)be_app)->PostMessage(&edited);
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
|
|
||||||
FeedListItem::FeedListItem(Feed* feed)
|
FeedListItem::FeedListItem(Feed* feed)
|
||||||
:
|
:
|
||||||
BStringItem(feed->GetTitle().String(), 0, false),
|
BStringItem(feed->Title().String(), 0, false),
|
||||||
fStatus(kClearStatus),
|
fStatus(kClearStatus),
|
||||||
fFeedUrl(feed->GetXmlUrl()),
|
fFeedUrl(feed->XmlUrl()),
|
||||||
fFeedPath(feed->GetCachePath())
|
fFeedPath(feed->CachePath())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,14 +52,14 @@ FeedListItem::DrawItem(BView* owner, BRect frame, bool complete)
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
FeedListItem::GetFeedPath()
|
FeedListItem::FeedPath()
|
||||||
{
|
{
|
||||||
return fFeedPath;
|
return fFeedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BUrl
|
BUrl
|
||||||
FeedListItem::GetFeedUrl()
|
FeedListItem::FeedUrl()
|
||||||
{
|
{
|
||||||
return fFeedUrl;
|
return fFeedUrl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@ public:
|
||||||
|
|
||||||
void DrawItem(BView* owner, BRect frame, bool complete);
|
void DrawItem(BView* owner, BRect frame, bool complete);
|
||||||
|
|
||||||
BUrl GetFeedUrl();
|
BUrl FeedUrl();
|
||||||
BString GetFeedPath();
|
BString FeedPath();
|
||||||
|
|
||||||
void SetStatus(int8 status);
|
void SetStatus(int8 status);
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ FeedsView::_RemoveSelectedFeed()
|
||||||
{
|
{
|
||||||
int32 selIndex = fFeedsListView->CurrentSelection();
|
int32 selIndex = fFeedsListView->CurrentSelection();
|
||||||
FeedListItem* selected = (FeedListItem*)fFeedsListView->ItemAt(selIndex);
|
FeedListItem* selected = (FeedListItem*)fFeedsListView->ItemAt(selIndex);
|
||||||
Feed delFeed = Feed(BEntry(selected->GetFeedPath()));
|
Feed delFeed = Feed(BEntry(selected->FeedPath()));
|
||||||
|
|
||||||
delFeed.Unfiletize();
|
delFeed.Unfiletize();
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ FeedsView::_UpdateProgress(BMessage* msg, int8 status)
|
||||||
|
|
||||||
for (int i = 0; i < fFeedsListView->CountItems(); i++) {
|
for (int i = 0; i < fFeedsListView->CountItems(); i++) {
|
||||||
FeedListItem* item = (FeedListItem*)fFeedsListView->ItemAt(i);
|
FeedListItem* item = (FeedListItem*)fFeedsListView->ItemAt(i);
|
||||||
if (item->GetFeedUrl().UrlString() == feedUrl) {
|
if (item->FeedUrl().UrlString() == feedUrl) {
|
||||||
item->SetStatus(status);
|
item->SetStatus(status);
|
||||||
fFeedsListView->InvalidateItem(i);
|
fFeedsListView->InvalidateItem(i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
|
|
||||||
RssFeed::RssFeed()
|
RssFeed::RssFeed()
|
||||||
{
|
{
|
||||||
title = BString("Untitled Feed");
|
fTitle = BString("Untitled Feed");
|
||||||
xmlUrl = BString("");
|
fXmlUrl = BString("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RssFeed::RssFeed(Feed* feed)
|
RssFeed::RssFeed(Feed* feed)
|
||||||
: RssFeed::RssFeed()
|
: RssFeed::RssFeed()
|
||||||
{
|
{
|
||||||
SetXmlUrl(feed->GetXmlUrl());
|
SetXmlUrl(feed->XmlUrl());
|
||||||
SetCachePath(feed->GetCachePath());
|
SetCachePath(feed->CachePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,11 +31,11 @@ void
|
||||||
RssFeed::Parse()
|
RssFeed::Parse()
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument xml;
|
tinyxml2::XMLDocument xml;
|
||||||
entries = BObjectList<Entry>(5, true);
|
fEntries = BObjectList<Entry>(5, true);
|
||||||
|
|
||||||
Feed::Parse();
|
Feed::Parse();
|
||||||
|
|
||||||
xml.LoadFile(GetCachePath().String());
|
xml.LoadFile(CachePath().String());
|
||||||
tinyxml2::XMLElement* xchan = xml.FirstChildElement("rss")->FirstChildElement("channel");
|
tinyxml2::XMLElement* xchan = xml.FirstChildElement("rss")->FirstChildElement("channel");
|
||||||
|
|
||||||
RootParse(xchan);
|
RootParse(xchan);
|
||||||
|
@ -48,10 +48,10 @@ RssFeed::Parse()
|
||||||
void
|
void
|
||||||
RssFeed::RootParse(tinyxml2::XMLElement* xchan)
|
RssFeed::RootParse(tinyxml2::XMLElement* xchan)
|
||||||
{
|
{
|
||||||
SetTitle(xchan->FirstChildElement("title"));
|
_SetTitle(xchan->FirstChildElement("title"));
|
||||||
SetDate(xchan->FirstChildElement("lastBuildDate"));
|
_SetDate(xchan->FirstChildElement("lastBuildDate"));
|
||||||
|
|
||||||
std::cout << "Channel '" << title.String() << "' at '" << xmlUrl.UrlString()
|
std::cout << "Channel '" << fTitle.String() << "' at '" << fXmlUrl.UrlString()
|
||||||
<< ":\n";
|
<< ":\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,16 +62,16 @@ RssFeed::EntryParse(tinyxml2::XMLElement* xitem)
|
||||||
Entry* newEntry = new Entry();
|
Entry* newEntry = new Entry();
|
||||||
|
|
||||||
newEntry->SetTitle(xitem->FirstChildElement("title"));
|
newEntry->SetTitle(xitem->FirstChildElement("title"));
|
||||||
newEntry->SetDesc(xitem->FirstChildElement("description"));
|
newEntry->SetDescription(xitem->FirstChildElement("description"));
|
||||||
newEntry->SetDate(xitem->FirstChildElement("pubDate"));
|
newEntry->SetDate(xitem->FirstChildElement("pubDate"));
|
||||||
newEntry->SetPostUrl(xitem->FirstChildElement("link"));
|
newEntry->SetPostUrl(xitem->FirstChildElement("link"));
|
||||||
newEntry->SetContent(xitem->FirstChildElement("content:encoded"));
|
newEntry->SetContent(xitem->FirstChildElement("content:encoded"));
|
||||||
newEntry->SetFeedTitle(title);
|
newEntry->SetFeedTitle(fTitle);
|
||||||
|
|
||||||
if (date == NULL || date < newEntry->GetDate())
|
if (fDate == NULL || fDate < newEntry->Date())
|
||||||
date = newEntry->date;
|
fDate = newEntry->Date();
|
||||||
|
|
||||||
AddEntry(newEntry);
|
_AddEntry(newEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,8 +82,8 @@ RssFeed::ParseEntries(tinyxml2::XMLElement* xchan)
|
||||||
|
|
||||||
xitem = xchan->FirstChildElement("item");
|
xitem = xchan->FirstChildElement("item");
|
||||||
|
|
||||||
int entryCount = xmlCountSiblings(xitem, "item");
|
int entryCount = _XmlCountSiblings(xitem, "item");
|
||||||
entries = BObjectList<Entry>(entryCount, true);
|
fEntries = BObjectList<Entry>(entryCount, true);
|
||||||
|
|
||||||
std::cout << "\t-" << entryCount << " entries-\n";
|
std::cout << "\t-" << entryCount << " entries-\n";
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue