Start progress bar; update feed list on adds/deletes

This commit is contained in:
Jaidyn Ann 2021-01-22 20:25:54 -06:00
parent c6f5c4fed0
commit fc608eddf2
9 changed files with 151 additions and 29 deletions

View File

@ -16,6 +16,7 @@
#include "Entry.h" #include "Entry.h"
#include "Feed.h" #include "Feed.h"
#include "FeedController.h" #include "FeedController.h"
#include "FeedsView.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "Mimetypes.h" #include "Mimetypes.h"
#include "Notifier.h" #include "Notifier.h"
@ -57,32 +58,38 @@ App::MessageReceived(BMessage* msg)
{ {
switch (msg->what) switch (msg->what)
{ {
case kEnqueueFeed:
case kUpdateSubscribed: case kUpdateSubscribed:
case kDownloadComplete:
{ {
fFeedController->MessageReceived(msg); fFeedController->MessageReceived(msg);
break; break;
} }
case kEnqueueFeed:
case kDownloadComplete:
{
fNotifier->MessageReceived(msg);
fFeedController->MessageReceived(msg);
break;
}
case kFeedsEdited:
case kProgress:
{
fMainWindow->MessageReceived(msg);
break;
}
case kClearQueue: case kClearQueue:
{ {
break; break;
} }
case kParseComplete: case kParseComplete:
{
fNotifier->MessageReceived(msg);
break;
}
case kParseFail: case kParseFail:
case kDownloadFail: case kDownloadFail:
{ {
fNotifier->MessageReceived(msg); fNotifier->MessageReceived(msg);
fFeedController->MessageReceived(msg);
break; break;
} }
default: default:
{ {
// BApplication::MessageReceived(msg); BApplication::MessageReceived(msg);
break; break;
} }
} }

View File

@ -78,8 +78,15 @@ FeedController::MessageReceived(BMessage* msg)
while (msg->HasData("feeds", B_RAW_TYPE, i)) { while (msg->HasData("feeds", B_RAW_TYPE, i)) {
msg->FindData("feeds", B_RAW_TYPE, i, &data, &size); msg->FindData("feeds", B_RAW_TYPE, i, &data, &size);
if (((Feed*)data)->IsUpdated() == true) if (((Feed*)data)->IsUpdated() == true)
send_data(fParseThread, msg->what, data, size); send_data(fParseThread, msg->what, data, size);
else {
BMessage* complete = new BMessage(kParseComplete);
complete->AddString("feed_name", ((Feed*)data)->GetTitle());
complete->AddInt32("entry_count", 0);
((App*)be_app)->MessageReceived(complete);
}
i++; i++;
} }
break; break;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io> * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
@ -16,6 +16,7 @@
#include "Feed.h" #include "Feed.h"
#include "FeedController.h" #include "FeedController.h"
#include "FeedListItem.h" #include "FeedListItem.h"
#include "FeedsView.h"
FeedEditWindow::FeedEditWindow() FeedEditWindow::FeedEditWindow()
@ -136,9 +137,11 @@ FeedEditWindow::_SaveFeed()
fFeed->SetXmlUrl(BUrl(urlString)); fFeed->SetXmlUrl(BUrl(urlString));
fFeed->Filetize(); fFeed->Filetize();
BMessage* firstUpdate = new BMessage(kEnqueueFeed); BMessage* enqueueUpdated = new BMessage(kEnqueueFeed);
firstUpdate->AddData("feeds", B_RAW_TYPE, (void*)fFeed, sizeof(Feed)); enqueueUpdated->AddData("feeds", B_RAW_TYPE, (void*)fFeed, sizeof(Feed));
((App*)be_app)->MessageReceived(firstUpdate);
((App*)be_app)->MessageReceived(enqueueUpdated);
((App*)be_app)->MessageReceived(new BMessage(kFeedsEdited));
Quit(); Quit();
} }
@ -147,6 +150,7 @@ void
FeedEditWindow::_DeleteFeed() FeedEditWindow::_DeleteFeed()
{ {
fFeed->Unfiletize(); fFeed->Unfiletize();
((App*)be_app)->MessageReceived(new BMessage(kFeedsEdited));
Quit(); Quit();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io> * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
@ -44,22 +44,25 @@ FeedsView::MessageReceived(BMessage* msg)
case kFeedsRemoveButton: case kFeedsRemoveButton:
{ {
_RemoveSelectedFeed(); _RemoveSelectedFeed();
_PopulateFeedList();
break; break;
} }
case kFeedsEditButton: case kFeedsEditButton:
{ {
_EditSelectedFeed(); _EditSelectedFeed();
_PopulateFeedList();
break; break;
} }
case kFeedsSelected: case kFeedsSelected:
{ {
fEditButton->SetEnabled(true); bool enabled = msg->GetInt32("index", -1) >= 0;
fRemoveButton->SetEnabled(true); fEditButton->SetEnabled(enabled);
fRemoveButton->SetEnabled(enabled);
break; break;
} }
case kFeedsEdited: case kFeedsEdited:
{ {
break; // _PopulateFeedList();
} }
default: default:
{ {
@ -80,11 +83,7 @@ FeedsView::_InitInterface()
fFeedsListView->SetSelectionMessage(new BMessage(kFeedsSelected)); fFeedsListView->SetSelectionMessage(new BMessage(kFeedsSelected));
fFeedsListView->SetInvocationMessage(new BMessage(kFeedsEditButton)); fFeedsListView->SetInvocationMessage(new BMessage(kFeedsEditButton));
BList feeds = FeedController::SubscribedFeeds(); _PopulateFeedList();
for (int i = 0; i < feeds.CountItems(); i++) {
FeedListItem* item = new FeedListItem((Feed*)feeds.ItemAt(i));
fFeedsListView->AddItem(item);
}
// Add, Remove, Edit // Add, Remove, Edit
fAddButton = new BButton("addFeed", "+", new BMessage(kFeedsAddButton)); fAddButton = new BButton("addFeed", "+", new BMessage(kFeedsAddButton));
@ -162,3 +161,16 @@ FeedsView::_RemoveSelectedFeed()
} }
void
FeedsView::_PopulateFeedList()
{
BList feeds = FeedController::SubscribedFeeds();
fFeedsListView->MakeEmpty();
for (int i = 0; i < feeds.CountItems(); i++) {
FeedListItem* item = new FeedListItem((Feed*)feeds.ItemAt(i));
fFeedsListView->AddItem(item);
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io> * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef FEEDSVIEW_H #ifndef FEEDSVIEW_H
@ -28,7 +28,7 @@ class FeedsView : public BGroupView {
public: public:
FeedsView(const char* name); FeedsView(const char* name);
void MessageReceived(BMessage* msg); virtual void MessageReceived(BMessage* msg);
private: private:
void _InitInterface(); void _InitInterface();
@ -36,6 +36,8 @@ private:
void _EditSelectedFeed(); void _EditSelectedFeed();
void _RemoveSelectedFeed(); void _RemoveSelectedFeed();
void _PopulateFeedList();
BButton* fAddButton; BButton* fAddButton;
BButton* fRemoveButton; BButton* fRemoveButton;
BButton* fEditButton; BButton* fEditButton;

View File

@ -7,10 +7,11 @@
#include <Button.h> #include <Button.h>
#include <GroupView.h> #include <GroupView.h>
#include <TabView.h>
#include <LayoutBuilder.h> #include <LayoutBuilder.h>
#include <SeparatorView.h> #include <SeparatorView.h>
#include <StatusBar.h>
#include <String.h> #include <String.h>
#include <TabView.h>
#include <cstdio> #include <cstdio>
@ -18,6 +19,7 @@
#include "EntriesView.h" #include "EntriesView.h"
#include "FeedController.h" #include "FeedController.h"
#include "FeedsView.h" #include "FeedsView.h"
#include "Notifier.h"
#include "UpdatesView.h" #include "UpdatesView.h"
@ -40,10 +42,24 @@ MainWindow::MessageReceived(BMessage *msg)
case kFeedsRemoveButton: case kFeedsRemoveButton:
case kFeedsEditButton: case kFeedsEditButton:
case kFeedsSelected: case kFeedsSelected:
case kFeedsEdited:
{ {
fFeedsView->MessageReceived(msg); fFeedsView->MessageReceived(msg);
break; break;
} }
case kProgress:
{
int32 max = 0;
int32 current = 0;
if (msg->FindInt32("max", &max) == B_OK
&& msg->FindInt32("current", &current) == B_OK)
{
int32 prog = max - current;
printf("%i / %i\n", prog, max);
}
break;
}
default: default:
{ {
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
@ -56,6 +72,7 @@ MainWindow::MessageReceived(BMessage *msg)
void void
MainWindow::_InitInterface() MainWindow::_InitInterface()
{ {
// Tabs
fBaseView = new BGroupView("baseView"); fBaseView = new BGroupView("baseView");
fTabView = new BTabView("tabView", B_WIDTH_FROM_WIDEST); fTabView = new BTabView("tabView", B_WIDTH_FROM_WIDEST);
fFeedsView = new FeedsView("Feeds"); fFeedsView = new FeedsView("Feeds");
@ -68,17 +85,22 @@ MainWindow::_InitInterface()
fTabView->SetBorder(B_NO_BORDER); fTabView->SetBorder(B_NO_BORDER);
fBaseView->AddChild(fTabView); fBaseView->AddChild(fTabView);
// Bottom bar
fStatusBar = new BStatusBar("feedProgress");
fUpdateNowButton = new BButton("updateNow", "Update Now", fUpdateNowButton = new BButton("updateNow", "Update Now",
new BMessage(kUpdateSubscribed)); new BMessage(kUpdateSubscribed));
fUpdateNowButton->SetTarget((App*)be_app); fUpdateNowButton->SetTarget((App*)be_app);
fUpdateNowButton->SetExplicitAlignment( fUpdateNowButton->SetExplicitAlignment(
BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE)); BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE));
BLayoutBuilder::Group<>(this, B_VERTICAL, 0) BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
.SetInsets(0, B_USE_DEFAULT_SPACING, 0, 0) .SetInsets(0, B_USE_DEFAULT_SPACING, 0, 0)
.Add(fBaseView) .Add(fBaseView)
.Add(new BSeparatorView(B_HORIZONTAL)) .Add(new BSeparatorView(B_HORIZONTAL))
.AddGroup(B_HORIZONTAL) .AddGroup(B_HORIZONTAL)
.Add(fStatusBar)
.Add(fUpdateNowButton) .Add(fUpdateNowButton)
.SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING, .SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING,
B_USE_DEFAULT_SPACING, B_USE_WINDOW_SPACING) B_USE_DEFAULT_SPACING, B_USE_WINDOW_SPACING)
@ -87,3 +109,14 @@ MainWindow::_InitInterface()
} }
void
MainWindow::_UpdateProgress()
{
fStatusBar->SetTo(50.0);
// if (fInProgress == 0)
// printf("Done!\n");
// else
// printf("Current: %i\n", fInProgress);
}

View File

@ -6,6 +6,7 @@
class BButton; class BButton;
class BGroupView; class BGroupView;
class BStatusBar;
class BTabView; class BTabView;
class EntriesView; class EntriesView;
class FeedsView; class FeedsView;
@ -21,12 +22,15 @@ public:
private: private:
void _InitInterface(); void _InitInterface();
void _UpdateProgress();
BGroupView* fBaseView; BGroupView* fBaseView;
BTabView* fTabView; BTabView* fTabView;
EntriesView* fEntriesView; EntriesView* fEntriesView;
FeedsView* fFeedsView; FeedsView* fFeedsView;
UpdatesView* fUpdatesView; UpdatesView* fUpdatesView;
BStatusBar* fStatusBar;
BButton* fUpdateNowButton; BButton* fUpdateNowButton;
}; };

View File

@ -1,14 +1,23 @@
/* /*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io> * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#include "Notifier.h"
#include <Message.h> #include <Message.h>
#include <Notification.h> #include <Notification.h>
#include "App.h"
#include "FeedController.h" #include "FeedController.h"
#include "Notifier.h"
Notifier::Notifier()
:
fEnqueuedFeeds(0),
fFeedsInProgress(0)
{
}
void void
@ -16,6 +25,13 @@ Notifier::MessageReceived(BMessage* msg)
{ {
switch (msg->what) switch (msg->what)
{ {
case kEnqueueFeed:
{
fEnqueuedFeeds++;
fFeedsInProgress++;
_UpdateProgress();
break;
}
case kParseComplete: case kParseComplete:
{ {
BString feedName; BString feedName;
@ -27,18 +43,28 @@ Notifier::MessageReceived(BMessage* msg)
if (entryCount > 0) if (entryCount > 0)
_NewEntryNotification(feedName, entryCount); _NewEntryNotification(feedName, entryCount);
} }
fFeedsInProgress--;
_UpdateProgress();
break; break;
} }
case kParseFail: case kParseFail:
{ {
BString feedUrl = msg->GetString("feed_url", ""); BString feedUrl = msg->GetString("feed_url", "");
_ParseFailNotification(feedUrl); _ParseFailNotification(feedUrl);
fFeedsInProgress--;
_UpdateProgress();
break; break;
} }
case kDownloadFail: case kDownloadFail:
{ {
BString feedUrl = msg->GetString("feed_url", ""); BString feedUrl = msg->GetString("feed_url", "");
_DownloadFailNotification(feedUrl); _DownloadFailNotification(feedUrl);
fFeedsInProgress--;
_UpdateProgress();
break;
} }
} }
} }
@ -96,3 +122,17 @@ Notifier::_DownloadFailNotification(BString feedUrl)
} }
void
Notifier::_UpdateProgress()
{
BMessage* progress = new BMessage(kProgress);
progress->AddInt32("max", fEnqueuedFeeds);
progress->AddInt32("current", fFeedsInProgress);
((App*)be_app)->MessageReceived(progress);
if (fFeedsInProgress == 0)
fEnqueuedFeeds = 0;
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io> * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef NOTIFIER_H #ifndef NOTIFIER_H
@ -8,10 +8,19 @@
#include <SupportDefs.h> #include <SupportDefs.h>
class BString; class BString;
class BMessage;
enum
{
kProgress = 'npro'
};
class Notifier { class Notifier {
public: public:
Notifier();
void MessageReceived(BMessage* msg); void MessageReceived(BMessage* msg);
private: private:
@ -19,6 +28,10 @@ private:
void _ParseFailNotification(BString feedUrl); void _ParseFailNotification(BString feedUrl);
void _DownloadFailNotification(BString feedUrl); void _DownloadFailNotification(BString feedUrl);
void _UpdateProgress();
int32 fEnqueuedFeeds;
int32 fFeedsInProgress;
}; };