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) * ~50kb per feed on download (+2MB w 40 feeds)
* This leak is in Util.ccp, fetch(). I'm stumped here. * This leak is in Util.ccp, fetch(). I'm stumped here.
* ~20kb per feed on parsing (+1MB w 40 feeds) * ~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) * Fix background of Feeds List error status icon (it's black, not transparent)
* Make UI friendly to whatever font-size you throw at it * Make UI friendly to whatever font-size you throw at it
* Give a max size to the progress label in FeedsView * Give a max size to the progress label in FeedsView
@ -21,9 +18,6 @@ Important improvements:
Nice Improvements: Nice Improvements:
* Proper scripting support * Proper scripting support
* Show in desktray * 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 * Move the provisional BList download queue to a BJob + JobQueue system
* This might add some more flexibility * This might add some more flexibility
* Multiple downloads at once * Multiple downloads at once

View File

@ -119,11 +119,10 @@ App::ArgvReceived(int32 argc, char** argv)
refMsg.AddRef("refs", &ref); refMsg.AddRef("refs", &ref);
} }
else if (BUrl(argv[i]).IsValid()) { else if (BUrl(argv[i]).IsValid()) {
Feed* newFeed = new Feed(BUrl(argv[i])); BString url = BString(argv[i]);
BMessage enqueue = BMessage(kEnqueueFeed); 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); MessageReceived(&enqueue);
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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