Show download/parse/failure status in the feeds list

This commit is contained in:
Jaidyn Ann 2021-02-27 13:20:03 -06:00
parent 6c63b23491
commit 203058bd58
7 changed files with 97 additions and 18 deletions

View File

@ -1,5 +1,5 @@
Important Features: Important Features:
* Show download progress/failures in FeedView's feedlist * Show progress in FeedView's feedlist as icons
* Show in desktray * Show in desktray
* Make archivable * Make archivable
* Get menu working * Get menu working

View File

@ -60,8 +60,9 @@ App::MessageReceived(BMessage* msg)
fFeedController->MessageReceived(msg); fFeedController->MessageReceived(msg);
break; break;
} }
case kEnqueueFeed:
case kDownloadComplete: case kDownloadComplete:
fMainWindow->PostMessage(msg);
case kEnqueueFeed:
{ {
fNotifier->MessageReceived(msg); fNotifier->MessageReceived(msg);
fFeedController->MessageReceived(msg); fFeedController->MessageReceived(msg);
@ -83,6 +84,7 @@ App::MessageReceived(BMessage* msg)
case kDownloadFail: case kDownloadFail:
{ {
fNotifier->MessageReceived(msg); fNotifier->MessageReceived(msg);
fMainWindow->PostMessage(msg);
break; break;
} }
default: default:

View File

@ -116,7 +116,8 @@ FeedController::_ProcessQueueItem()
send_data(fDownloadThread, 0, (void*)buffer, sizeof(Feed)); send_data(fDownloadThread, 0, (void*)buffer, sizeof(Feed));
BMessage downloadInit = BMessage(kDownloadStart); 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); ((App*)be_app)->MessageReceived(&downloadInit);
} }
} }
@ -154,7 +155,7 @@ FeedController::_CheckStatus()
case kParseComplete: case kParseComplete:
{ {
BMessage complete = BMessage(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()); complete.AddInt32("entry_count", feedBuffer->GetNewEntries().CountItems());
((App*)be_app)->MessageReceived(&complete); ((App*)be_app)->MessageReceived(&complete);
break; break;

View File

@ -5,18 +5,48 @@
#include "FeedListItem.h" #include "FeedListItem.h"
#include <View.h>
#include "Feed.h" #include "Feed.h"
FeedListItem::FeedListItem(Feed* feed) FeedListItem::FeedListItem(Feed* feed)
: :
BStringItem(feed->GetTitle().String(), 0, false), BStringItem(feed->GetTitle().String(), 0, false),
fStatus(kClearStatus),
fFeedUrl(feed->GetXmlUrl()), fFeedUrl(feed->GetXmlUrl()),
fFeedPath(feed->GetCachePath()) 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 BString
FeedListItem::GetFeedPath() FeedListItem::GetFeedPath()
{ {
@ -29,3 +59,12 @@ FeedListItem::GetFeedUrl()
{ {
return fFeedUrl; return fFeedUrl;
} }
void
FeedListItem::SetStatus(int8 status)
{
fStatus = status;
}

View File

@ -9,20 +9,32 @@
#include <StringItem.h> #include <StringItem.h>
#include <Url.h> #include <Url.h>
//class BString;
//class BUrl;
class Feed; class Feed;
enum
{
kClearStatus = 0,
kDownloadingStatus = 1,
kParsingStatus = 2,
kErrorStatus = 3
};
class FeedListItem : public BStringItem class FeedListItem : public BStringItem
{ {
public: public:
FeedListItem(Feed* feed); FeedListItem(Feed* feed);
void DrawItem(BView* owner, BRect frame, bool complete);
BUrl GetFeedUrl(); BUrl GetFeedUrl();
BString GetFeedPath(); BString GetFeedPath();
void SetStatus(int8 status);
private: private:
int8 fStatus;
BUrl fFeedUrl; BUrl fFeedUrl;
BString fFeedPath; BString fFeedPath;
}; };

View File

@ -65,15 +65,24 @@ FeedsView::MessageReceived(BMessage* msg)
} }
case kDownloadStart: case kDownloadStart:
{ {
BString feedName; _UpdateProgress(msg, kDownloadingStatus);
if (msg->FindString("feed", &feedName) == B_OK)
_UpdateProgress(feedName);
}
default:
{
// BWindow::MessageReceived(msg);
break; 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 void
FeedsView::_UpdateProgress(BString feedName) FeedsView::_UpdateProgress(BMessage* msg, int8 status)
{ {
BString label("Fetching "); BString feedName, feedUrl;
label << feedName << ""; if (msg->FindString("feed_url", &feedUrl) != B_OK)
fProgressLabel->SetText(label); 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);
}
}
} }

View File

@ -39,7 +39,7 @@ private:
void _PopulateFeedList(); void _PopulateFeedList();
void _UpdateProgress(BString feedName); void _UpdateProgress(BMessage* msg, int8 status);
BButton* fAddButton; BButton* fAddButton;
BButton* fRemoveButton; BButton* fRemoveButton;