List subscribed feeds in FeedsView

This commit is contained in:
Jaidyn Ann 2021-01-13 20:23:21 -06:00
parent 4383c4b906
commit f67a9f3d28
9 changed files with 109 additions and 14 deletions

View File

@ -36,6 +36,7 @@ SRCS = \
src/EntriesView.cpp, \ src/EntriesView.cpp, \
src/Feed.cpp, \ src/Feed.cpp, \
src/FeedController.cpp \ src/FeedController.cpp \
src/FeedListItem.cpp \
src/FeedsView.cpp, \ src/FeedsView.cpp, \
src/MainWindow.cpp, \ src/MainWindow.cpp, \
src/Mimetypes.cpp, \ src/Mimetypes.cpp, \

View File

@ -3,8 +3,6 @@
* Do this for file refs when Feeds, too * Do this for file refs when Feeds, too
* Revamp configuration * Revamp configuration
* Fix saving, etc. * Fix saving, etc.
* Notifications
* On failures
* Show progress * Show progress
* With progress bar * With progress bar
* With indicator in the feeds list * With indicator in the feeds list

View File

@ -31,6 +31,7 @@ Feed::Feed(BUrl xml)
} }
// For pre-existing feed
Feed::Feed(BEntry entry) Feed::Feed(BEntry entry)
: Feed() : Feed()
{ {
@ -39,9 +40,32 @@ Feed::Feed(BEntry entry)
entry.GetPath(&path); entry.GetPath(&path);
SetCachePath(BString(path.Path())); SetCachePath(BString(path.Path()));
BString name;
BString url; BString url;
file.ReadAttrString("META:url", &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);
} }

View File

@ -23,6 +23,7 @@ public:
Feed(BUrl); Feed(BUrl);
Feed(BUrl, BString); Feed(BUrl, BString);
Feed(BEntry); Feed(BEntry);
Feed(BUrl xml, BEntry entry);
Feed(Feed*); Feed(Feed*);
Feed(); Feed();

View File

@ -57,16 +57,14 @@ FeedController::MessageReceived(BMessage* msg)
} }
case kUpdateSubscribed: case kUpdateSubscribed:
{ {
BDirectory subDir("/boot/home/config/settings/Pogger/Subscriptions"); BList subFeeds = SubscribedFeeds();
BEntry feedEntry; for (int i = 0; i < subFeeds.CountItems(); i++) {
Feed* feed;
while (subDir.GetNextEntry(&feedEntry) == B_OK) {
feed = new Feed(feedEntry);
BMessage* getFeed = new BMessage(kEnqueueFeed); 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); ((App*)be_app)->MessageReceived(getFeed);
} }
break;
} }
case kClearQueue: 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 int32
FeedController::_DownloadLoop(void* ignored) FeedController::_DownloadLoop(void* ignored)
{ {

View File

@ -8,6 +8,7 @@
#include <SupportDefs.h> #include <SupportDefs.h>
#include <OS.h> #include <OS.h>
class BList;
class BMessage; class BMessage;
@ -28,6 +29,7 @@ public:
FeedController(); FeedController();
~FeedController(); ~FeedController();
void MessageReceived(BMessage* msg); void MessageReceived(BMessage* msg);
static BList SubscribedFeeds();
private: private:
static int32 _DownloadLoop(void* ignored); static int32 _DownloadLoop(void* ignored);

19
src/FeedListItem.cpp Normal file
View File

@ -0,0 +1,19 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* 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())
{
}

29
src/FeedListItem.h Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef FEEDITEM_H
#define FEEDITEM_H
#include <String.h>
#include <StringItem.h>
#include <Url.h>
//class BString;
//class BUrl;
class Feed;
class FeedListItem : public BStringItem
{
public:
FeedListItem(Feed* feed);
private:
BUrl fFeedUrl;
BString fFeedPath;
};
#endif // FEEDITEM_H

View File

@ -14,6 +14,10 @@
#include <cstdio> #include <cstdio>
#include "FeedController.h"
#include "FeedListItem.h"
FeedsView::FeedsView(const char* name) FeedsView::FeedsView(const char* name)
: :
BGroupView(name, B_VERTICAL, B_USE_DEFAULT_SPACING) BGroupView(name, B_VERTICAL, B_USE_DEFAULT_SPACING)
@ -44,10 +48,11 @@ FeedsView::_InitInterface()
fFeedsScrollView = new BScrollView("feedsScroll", fFeedsListView, fFeedsScrollView = new BScrollView("feedsScroll", fFeedsListView,
B_WILL_DRAW, false, true); B_WILL_DRAW, false, true);
font_height fontHeight; BList feeds = FeedController::SubscribedFeeds();
GetFontHeight(&fontHeight); for (int i = 0; i < feeds.CountItems(); i++) {
int16 buttonHeight = int16(fontHeight.ascent + fontHeight.descent + 12); FeedListItem* item = new FeedListItem((Feed*)feeds.ItemAt(i));
BSize charButtonSize(buttonHeight, buttonHeight); fFeedsListView->AddItem(item);
}
// Add, Remove, Edit // Add, Remove, Edit
fAddButton = new BButton("addFeed", "+", fAddButton = new BButton("addFeed", "+",
@ -55,6 +60,11 @@ FeedsView::_InitInterface()
fRemoveButton = new BButton("removeFeed", "-", fRemoveButton = new BButton("removeFeed", "-",
new BMessage('frem')); new BMessage('frem'));
font_height fontHeight;
GetFontHeight(&fontHeight);
int16 buttonHeight = int16(fontHeight.ascent + fontHeight.descent + 12);
BSize charButtonSize(buttonHeight, buttonHeight);
fAddButton->SetTarget(this); fAddButton->SetTarget(this);
fAddButton->SetExplicitSize(charButtonSize); fAddButton->SetExplicitSize(charButtonSize);
fRemoveButton->SetTarget(this); fRemoveButton->SetTarget(this);