diff --git a/Makefile b/Makefile index 10a36ce..64805e0 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ SRCS = \ src/EntriesView.cpp, \ src/Feed.cpp, \ src/FeedController.cpp \ + src/FeedListItem.cpp \ src/FeedsView.cpp, \ src/MainWindow.cpp, \ src/Mimetypes.cpp, \ diff --git a/TODO.txt b/TODO.txt index 244d72e..49c1584 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,8 +3,6 @@ * Do this for file refs when Feeds, too * Revamp configuration * Fix saving, etc. -* Notifications - * On failures * Show progress * With progress bar * With indicator in the feeds list diff --git a/src/Feed.cpp b/src/Feed.cpp index 2822a5e..52d96b2 100644 --- a/src/Feed.cpp +++ b/src/Feed.cpp @@ -31,6 +31,7 @@ Feed::Feed(BUrl xml) } +// For pre-existing feed Feed::Feed(BEntry entry) : Feed() { @@ -39,9 +40,32 @@ Feed::Feed(BEntry entry) entry.GetPath(&path); SetCachePath(BString(path.Path())); + BString name; BString url; file.ReadAttrString("META:url", &url); - xmlUrl = BUrl(url); + file.ReadAttrString("Feed:name", &name); + + if (!url.IsEmpty()) + SetXmlUrl(BUrl(url)); + if (!name.IsEmpty()) + SetTitle(name); +} + + +// For new feed +Feed::Feed(BUrl xml, BEntry entry) + : Feed() +{ + BPath path; + BString pathString; + entry.GetPath(&path); + pathString = path.Path(); + + if (entry.IsDirectory()) + pathString += BString(urlToFilename(xml)); + + SetCachePath(pathString); + SetXmlUrl(xml); } diff --git a/src/Feed.h b/src/Feed.h index 77e7322..afb7fce 100644 --- a/src/Feed.h +++ b/src/Feed.h @@ -23,6 +23,7 @@ public: Feed(BUrl); Feed(BUrl, BString); Feed(BEntry); + Feed(BUrl xml, BEntry entry); Feed(Feed*); Feed(); diff --git a/src/FeedController.cpp b/src/FeedController.cpp index c9e3660..72fd652 100644 --- a/src/FeedController.cpp +++ b/src/FeedController.cpp @@ -57,16 +57,14 @@ FeedController::MessageReceived(BMessage* msg) } case kUpdateSubscribed: { - BDirectory subDir("/boot/home/config/settings/Pogger/Subscriptions"); - BEntry feedEntry; - Feed* feed; - - while (subDir.GetNextEntry(&feedEntry) == B_OK) { - feed = new Feed(feedEntry); + BList subFeeds = SubscribedFeeds(); + for (int i = 0; i < subFeeds.CountItems(); i++) { BMessage* getFeed = new BMessage(kEnqueueFeed); - getFeed->AddData("feeds", B_RAW_TYPE, feed, sizeof(Feed)); + getFeed->AddData("feeds", B_RAW_TYPE, subFeeds.ItemAt(i), + sizeof(Feed)); ((App*)be_app)->MessageReceived(getFeed); } + break; } case kClearQueue: { @@ -95,6 +93,19 @@ FeedController::MessageReceived(BMessage* msg) } +BList +FeedController::SubscribedFeeds() +{ + BDirectory subDir("/boot/home/config/settings/Pogger/Subscriptions"); + BEntry feedEntry; + BList feeds; + + while (subDir.GetNextEntry(&feedEntry) == B_OK) + feeds.AddItem(new Feed(feedEntry)); + return feeds; +} + + int32 FeedController::_DownloadLoop(void* ignored) { diff --git a/src/FeedController.h b/src/FeedController.h index f4f8eff..e472ef0 100644 --- a/src/FeedController.h +++ b/src/FeedController.h @@ -8,6 +8,7 @@ #include #include +class BList; class BMessage; @@ -28,6 +29,7 @@ public: FeedController(); ~FeedController(); void MessageReceived(BMessage* msg); + static BList SubscribedFeeds(); private: static int32 _DownloadLoop(void* ignored); diff --git a/src/FeedListItem.cpp b/src/FeedListItem.cpp new file mode 100644 index 0000000..709769d --- /dev/null +++ b/src/FeedListItem.cpp @@ -0,0 +1,19 @@ +/* + * Copyright 2020, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#include "FeedListItem.h" + +#include "Feed.h" + + +FeedListItem::FeedListItem(Feed* feed) + : + BStringItem(feed->GetTitle().String(), 0, false), + fFeedUrl(feed->GetXmlUrl()), + fFeedPath(feed->GetCachePath()) +{ +} + + diff --git a/src/FeedListItem.h b/src/FeedListItem.h new file mode 100644 index 0000000..8679e51 --- /dev/null +++ b/src/FeedListItem.h @@ -0,0 +1,29 @@ +/* + * Copyright 2020, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef FEEDITEM_H +#define FEEDITEM_H + +#include +#include +#include + +//class BString; +//class BUrl; +class Feed; + + +class FeedListItem : public BStringItem +{ +public: + FeedListItem(Feed* feed); + +private: + BUrl fFeedUrl; + BString fFeedPath; +}; + + +#endif // FEEDITEM_H + diff --git a/src/FeedsView.cpp b/src/FeedsView.cpp index 4e7941b..b865d40 100644 --- a/src/FeedsView.cpp +++ b/src/FeedsView.cpp @@ -14,6 +14,10 @@ #include +#include "FeedController.h" +#include "FeedListItem.h" + + FeedsView::FeedsView(const char* name) : BGroupView(name, B_VERTICAL, B_USE_DEFAULT_SPACING) @@ -44,10 +48,11 @@ FeedsView::_InitInterface() fFeedsScrollView = new BScrollView("feedsScroll", fFeedsListView, B_WILL_DRAW, false, true); - font_height fontHeight; - GetFontHeight(&fontHeight); - int16 buttonHeight = int16(fontHeight.ascent + fontHeight.descent + 12); - BSize charButtonSize(buttonHeight, buttonHeight); + BList feeds = FeedController::SubscribedFeeds(); + for (int i = 0; i < feeds.CountItems(); i++) { + FeedListItem* item = new FeedListItem((Feed*)feeds.ItemAt(i)); + fFeedsListView->AddItem(item); + } // Add, Remove, Edit fAddButton = new BButton("addFeed", "+", @@ -55,6 +60,11 @@ FeedsView::_InitInterface() fRemoveButton = new BButton("removeFeed", "-", new BMessage('frem')); + font_height fontHeight; + GetFontHeight(&fontHeight); + int16 buttonHeight = int16(fontHeight.ascent + fontHeight.descent + 12); + BSize charButtonSize(buttonHeight, buttonHeight); + fAddButton->SetTarget(this); fAddButton->SetExplicitSize(charButtonSize); fRemoveButton->SetTarget(this);