Enqueue feeds as paths

This commit is contained in:
Jaidyn Ann 2021-03-06 12:36:33 -06:00
parent 8af0aa7c1d
commit c4990b719c
9 changed files with 57 additions and 58 deletions

View File

@ -8,9 +8,6 @@ Important improvements:
* ~50kb per feed on download (+2MB w 40 feeds)
* This leak is in Util.ccp, fetch(). I'm stumped here.
* ~20kb per feed on parsing (+1MB w 40 feeds)
* Very slight on enqueue
* Use path-strings or entry_refs when communicating about feeds inter-threads,
and in the queue.
* Fix background of Feeds List error status icon (it's black, not transparent)
* Make UI friendly to whatever font-size you throw at it
* Give a max size to the progress label in FeedsView
@ -21,9 +18,6 @@ Important improvements:
Nice Improvements:
* Proper scripting support
* Show in desktray
* Store feeds in kEnqueueFeeds/etc messages as paths? hmm
* This way, if the user edits the feed after it is enqueued but before
processing, the changes will be applied.
* Move the provisional BList download queue to a BJob + JobQueue system
* This might add some more flexibility
* Multiple downloads at once

View File

@ -119,11 +119,10 @@ App::ArgvReceived(int32 argc, char** argv)
refMsg.AddRef("refs", &ref);
}
else if (BUrl(argv[i]).IsValid()) {
Feed* newFeed = new Feed(BUrl(argv[i]));
BString url = BString(argv[i]);
BMessage enqueue = BMessage(kEnqueueFeed);
enqueue.AddData("feeds", B_RAW_TYPE, (void*)newFeed, sizeof(Feed));
enqueue.AddData("feedPaths", B_STRING_TYPE, &url, sizeof(BString));
MessageReceived(&enqueue);
}
}

View File

@ -57,6 +57,12 @@ Feed::Feed(BEntry entry)
}
Feed::Feed(const char* pathStr)
: Feed(BEntry(pathStr))
{
}
// For new feed
Feed::Feed(BUrl xml, BEntry entry)
: Feed()

View File

@ -24,6 +24,7 @@ public:
Feed(BUrl);
Feed(BUrl, BString);
Feed(BEntry);
Feed(const char* pathStr);
Feed(BUrl xml, BEntry entry);
Feed(Feed*);
Feed();

View File

@ -11,6 +11,7 @@
#include <Message.h>
#include <MessageRunner.h>
#include <Notification.h>
#include <StringList.h>
#include "App.h"
#include "AtomFeed.h"
@ -24,7 +25,7 @@ FeedController::FeedController()
fMainThread(find_thread(NULL)),
fDownloadThread(0),
fParseThread(0),
fDownloadQueue(new BObjectList<Feed>(5, true)),
fDownloadQueue(new BStringList()),
fMessageRunner(new BMessageRunner(be_app, BMessage(kControllerCheck), 50000, -1))
{
@ -53,22 +54,21 @@ FeedController::MessageReceived(BMessage* msg)
{
int i = 0;
const void* data;
ssize_t size = sizeof(Feed);
ssize_t size = sizeof(BString);
while (msg->HasData("feeds", B_RAW_TYPE, i)) {
msg->FindData("feeds", B_RAW_TYPE, i, &data, &size);
_EnqueueFeed((Feed*)data);
i++;
}
BStringList paths;
msg->FindStrings("feedPaths", &paths);
fDownloadQueue->Add(paths);
fMessageRunner->SetCount(-1);
_SendProgress();
break;
}
case kUpdateSubscribed:
{
BList subFeeds = SubscribedFeeds();
for (int i = 0; i < subFeeds.CountItems(); i++) {
_EnqueueFeed((Feed*)subFeeds.ItemAt(i));
}
BStringList subFeeds = SubscribedFeeds();
fDownloadQueue->Add(subFeeds);
_SendProgress();
break;
}
@ -87,7 +87,7 @@ FeedController::MessageReceived(BMessage* msg)
}
BList
BStringList
FeedController::SubscribedFeeds()
{
BPath subPath;
@ -97,10 +97,12 @@ FeedController::SubscribedFeeds()
BDirectory subDir(subPath.Path());
BEntry feedEntry;
BList feeds;
BPath feedPath;
BStringList feeds;
while (subDir.GetNextEntry(&feedEntry) == B_OK)
feeds.AddItem(new Feed(feedEntry));
while (subDir.GetNextEntry(&feedEntry) == B_OK
&& feedEntry.GetPath(&feedPath) == B_OK)
feeds.Add(feedPath.Path());
return feeds;
}
@ -108,7 +110,7 @@ FeedController::SubscribedFeeds()
void
FeedController::_SendProgress()
{
int32 dqCount = fDownloadQueue->CountItems();
int32 dqCount = fDownloadQueue->CountStrings();
if (fEnqueuedTotal < dqCount)
fEnqueuedTotal = dqCount;
@ -123,21 +125,19 @@ FeedController::_SendProgress()
}
void
FeedController::_EnqueueFeed(Feed* feed)
{
fMessageRunner->SetCount(-1);
fDownloadQueue->AddItem(feed);
}
void
FeedController::_ProcessQueueItem()
{
if (has_data(fDownloadThread) && !fDownloadQueue->IsEmpty()) {
Feed* buffer = fDownloadQueue->ItemAt(0);
BString feed = fDownloadQueue->Remove(0);
Feed* buffer;
if (BUrl(feed.String()).IsValid() == true)
buffer = new Feed(BUrl(feed.String()));
else
buffer = new Feed(feed.String());
send_data(fDownloadThread, 0, (void*)buffer, sizeof(Feed));
fDownloadQueue->RemoveItemAt(0);
BMessage downloadInit = BMessage(kDownloadStart);
downloadInit.AddString("feed_name", buffer->GetTitle());

View File

@ -11,6 +11,7 @@
class BMessage;
class BMessageRunner;
class BStringList;
class Feed;
@ -36,13 +37,11 @@ public:
void MessageReceived(BMessage* msg);
static BList SubscribedFeeds();
static BStringList SubscribedFeeds();
private:
void _SendProgress();
void _EnqueueFeed(Feed* feed);
void _ProcessQueueItem();
void _ReceiveStatus();
@ -55,7 +54,7 @@ private:
thread_id fDownloadThread;
thread_id fParseThread;
BObjectList<Feed>* fDownloadQueue;
BStringList* fDownloadQueue;
BMessageRunner* fMessageRunner;
};

View File

@ -14,7 +14,6 @@
#include <TextControl.h>
#include "App.h"
#include "Feed.h"
#include "FeedController.h"
#include "FeedListItem.h"
#include "FeedsView.h"
@ -29,7 +28,7 @@ FeedEditWindow::FeedEditWindow()
MoveOnScreen();
fDeleteButton->SetEnabled(false);
fFeed = new Feed();
fFeed = Feed();
}
@ -38,10 +37,10 @@ FeedEditWindow::FeedEditWindow(BEntry feedEntry)
FeedEditWindow()
{
SetTitle("Edit Feed");
fFeed = new Feed(feedEntry);
fFeed = Feed(feedEntry);
fFeedNameText->SetText(fFeed->GetTitle().String());
fFeedUrlText->SetText(fFeed->GetXmlUrl().UrlString().String());
fFeedNameText->SetText(fFeed.GetTitle().String());
fFeedUrlText->SetText(fFeed.GetXmlUrl().UrlString().String());
fDeleteButton->SetEnabled(true);
}
@ -158,17 +157,17 @@ FeedEditWindow::_SaveFeed()
filename = BString(title);
subPath.Append(filename);
if (fFeed->GetCachePath().IsEmpty())
fFeed->SetCachePath(BString(subPath.Path()));
if (fFeed.GetCachePath().IsEmpty())
fFeed.SetCachePath(BString(subPath.Path()));
if (!title.IsEmpty())
fFeed->SetTitle(title.String());
fFeed->SetXmlUrl(BUrl(urlString));
fFeed->Filetize();
fFeed.SetTitle(title.String());
fFeed.SetXmlUrl(BUrl(urlString));
fFeed.Filetize();
BMessage edited(kFeedsEdited);
BMessage enqueueUpdated(kEnqueueFeed);
enqueueUpdated.AddData("feeds", B_RAW_TYPE, (void*)fFeed, sizeof(Feed));
enqueueUpdated.AddString("feedPaths", fFeed.GetCachePath());
((App*)be_app)->MessageReceived(&enqueueUpdated);
((App*)be_app)->PostMessage(&edited);
@ -179,7 +178,7 @@ FeedEditWindow::_SaveFeed()
void
FeedEditWindow::_DeleteFeed()
{
fFeed->Unfiletize();
fFeed.Unfiletize();
BMessage edited(kFeedsEdited);
((App*)be_app)->PostMessage(&edited);
Quit();

View File

@ -7,6 +7,8 @@
#include <Window.h>
#include "Feed.h"
class BButton;
class BStringView;
class BTextControl;
@ -37,7 +39,7 @@ private:
void _DeleteFeed();
BString fFeedPath;
Feed* fFeed;
Feed fFeed;
BStringView* fFeedNameLabel;
BTextControl* fFeedNameText;

View File

@ -11,6 +11,7 @@
#include <ListView.h>
#include <ScrollView.h>
#include <SeparatorView.h>
#include <StringList.h>
#include <StringView.h>
#include "App.h"
@ -183,20 +184,18 @@ FeedsView::_RemoveSelectedFeed()
void
FeedsView::_PopulateFeedList()
{
BList feeds = FeedController::SubscribedFeeds();
BStringList feeds = FeedController::SubscribedFeeds();
int32 selected = fFeedsListView->CurrentSelection();
for (int i = fFeedsListView->CountItems(); i >= 0; i--)
delete ((FeedListItem*)fFeedsListView->RemoveItem(i));
for (int i = 0; i < feeds.CountItems(); i++) {
FeedListItem* item = new FeedListItem((Feed*)feeds.ItemAt(i));
for (int i = 0; i < feeds.CountStrings(); i++) {
Feed feed = Feed(feeds.StringAt(i).String());
FeedListItem* item = new FeedListItem(&feed);
fFeedsListView->AddItem(item);
}
for (int i = feeds.CountItems(); i >= 0; i--)
delete ((Feed*)feeds.RemoveItem(i));
if (fFeedsListView->CountItems() < selected)
selected = fFeedsListView->CountItems();
fFeedsListView->Select(selected);