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