From 203058bd58c62ee4ab17099d2fb65bd6ad20a8f0 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sat, 27 Feb 2021 13:20:03 -0600 Subject: [PATCH] Show download/parse/failure status in the feeds list --- TODO.txt | 2 +- src/App.cpp | 4 +++- src/FeedController.cpp | 5 +++-- src/FeedListItem.cpp | 39 +++++++++++++++++++++++++++++++++++ src/FeedListItem.h | 16 ++++++++++++-- src/FeedsView.cpp | 47 ++++++++++++++++++++++++++++++++---------- src/FeedsView.h | 2 +- 7 files changed, 97 insertions(+), 18 deletions(-) diff --git a/TODO.txt b/TODO.txt index d7e2731..8fe8557 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,5 @@ Important Features: -* Show download progress/failures in FeedView's feedlist +* Show progress in FeedView's feedlist as icons * Show in desktray * Make archivable * Get menu working diff --git a/src/App.cpp b/src/App.cpp index a939a65..9af2afc 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -60,8 +60,9 @@ App::MessageReceived(BMessage* msg) fFeedController->MessageReceived(msg); break; } - case kEnqueueFeed: case kDownloadComplete: + fMainWindow->PostMessage(msg); + case kEnqueueFeed: { fNotifier->MessageReceived(msg); fFeedController->MessageReceived(msg); @@ -83,6 +84,7 @@ App::MessageReceived(BMessage* msg) case kDownloadFail: { fNotifier->MessageReceived(msg); + fMainWindow->PostMessage(msg); break; } default: diff --git a/src/FeedController.cpp b/src/FeedController.cpp index dffef5e..0d89121 100644 --- a/src/FeedController.cpp +++ b/src/FeedController.cpp @@ -116,7 +116,8 @@ FeedController::_ProcessQueueItem() send_data(fDownloadThread, 0, (void*)buffer, sizeof(Feed)); BMessage downloadInit = BMessage(kDownloadStart); - downloadInit.AddString("feed", buffer->GetTitle()); + downloadInit.AddString("feed_url", buffer->GetXmlUrl().UrlString()); + downloadInit.AddString("feed_name", buffer->GetTitle()); ((App*)be_app)->MessageReceived(&downloadInit); } } @@ -154,7 +155,7 @@ FeedController::_CheckStatus() case kParseComplete: { BMessage complete = BMessage(kParseComplete); - complete.AddString("feed_name", feedBuffer->GetTitle()); + complete.AddString("feed_url", feedBuffer->GetXmlUrl().UrlString()); complete.AddInt32("entry_count", feedBuffer->GetNewEntries().CountItems()); ((App*)be_app)->MessageReceived(&complete); break; diff --git a/src/FeedListItem.cpp b/src/FeedListItem.cpp index 45422a6..ac1e1cc 100644 --- a/src/FeedListItem.cpp +++ b/src/FeedListItem.cpp @@ -5,18 +5,48 @@ #include "FeedListItem.h" +#include + #include "Feed.h" FeedListItem::FeedListItem(Feed* feed) : BStringItem(feed->GetTitle().String(), 0, false), + fStatus(kClearStatus), fFeedUrl(feed->GetXmlUrl()), fFeedPath(feed->GetCachePath()) { } +void +FeedListItem::DrawItem(BView* owner, BRect frame, bool complete) +{ + BStringItem::DrawItem(owner, frame, complete); + + owner->MovePenTo(frame.right - 20, frame.top + BaselineOffset()); + + switch (fStatus) { + case kDownloadingStatus: + { + owner->DrawString("…"); + break; + } + case kParsingStatus: + { + owner->DrawString("―"); + break; + } + case kErrorStatus: + { + owner->DrawString("X"); + break; + } + } +} + + BString FeedListItem::GetFeedPath() { @@ -29,3 +59,12 @@ FeedListItem::GetFeedUrl() { return fFeedUrl; } + + +void +FeedListItem::SetStatus(int8 status) +{ + fStatus = status; +} + + diff --git a/src/FeedListItem.h b/src/FeedListItem.h index 8c30b2a..a214643 100644 --- a/src/FeedListItem.h +++ b/src/FeedListItem.h @@ -9,20 +9,32 @@ #include #include -//class BString; -//class BUrl; class Feed; +enum +{ + kClearStatus = 0, + kDownloadingStatus = 1, + kParsingStatus = 2, + kErrorStatus = 3 +}; + + class FeedListItem : public BStringItem { public: FeedListItem(Feed* feed); + void DrawItem(BView* owner, BRect frame, bool complete); + BUrl GetFeedUrl(); BString GetFeedPath(); + void SetStatus(int8 status); + private: + int8 fStatus; BUrl fFeedUrl; BString fFeedPath; }; diff --git a/src/FeedsView.cpp b/src/FeedsView.cpp index 0d72c15..96a2e5f 100644 --- a/src/FeedsView.cpp +++ b/src/FeedsView.cpp @@ -65,15 +65,24 @@ FeedsView::MessageReceived(BMessage* msg) } case kDownloadStart: { - BString feedName; - if (msg->FindString("feed", &feedName) == B_OK) - _UpdateProgress(feedName); - } - default: - { -// BWindow::MessageReceived(msg); + _UpdateProgress(msg, kDownloadingStatus); break; } + case kDownloadComplete: + { + _UpdateProgress(msg, kParsingStatus); + break; + } + case kDownloadFail: + case kParseFail: + { + _UpdateProgress(msg, kErrorStatus); + break; + } + case kParseComplete: + { + _UpdateProgress(msg, kClearStatus); + } } } @@ -195,11 +204,27 @@ FeedsView::_PopulateFeedList() void -FeedsView::_UpdateProgress(BString feedName) +FeedsView::_UpdateProgress(BMessage* msg, int8 status) { - BString label("Fetching "); - label << feedName << "…"; - fProgressLabel->SetText(label); + BString feedName, feedUrl; + if (msg->FindString("feed_url", &feedUrl) != B_OK) + return; + if (msg->FindString("feed_name", &feedName) != B_OK) + feedName = feedUrl; + + if (status == kDownloadingStatus) { + BString label("Fetching "); + label << feedName << "…"; + fProgressLabel->SetText(label); + } + + for (int i = 0; i < fFeedsListView->CountItems(); i++) { + FeedListItem* item = (FeedListItem*)fFeedsListView->ItemAt(i); + if (item->GetFeedUrl().UrlString() == feedUrl) { + item->SetStatus(status); + fFeedsListView->InvalidateItem(i); + } + } } diff --git a/src/FeedsView.h b/src/FeedsView.h index ce56767..c387c5b 100644 --- a/src/FeedsView.h +++ b/src/FeedsView.h @@ -39,7 +39,7 @@ private: void _PopulateFeedList(); - void _UpdateProgress(BString feedName); + void _UpdateProgress(BMessage* msg, int8 status); BButton* fAddButton; BButton* fRemoveButton;