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

View File

@ -78,8 +78,15 @@ FeedController::MessageReceived(BMessage* msg)
while (msg->HasData("feeds", B_RAW_TYPE, i)) {
msg->FindData("feeds", B_RAW_TYPE, i, &data, &size);
if (((Feed*)data)->IsUpdated() == true)
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++;
}
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.
*/
@ -16,6 +16,7 @@
#include "Feed.h"
#include "FeedController.h"
#include "FeedListItem.h"
#include "FeedsView.h"
FeedEditWindow::FeedEditWindow()
@ -136,9 +137,11 @@ FeedEditWindow::_SaveFeed()
fFeed->SetXmlUrl(BUrl(urlString));
fFeed->Filetize();
BMessage* firstUpdate = new BMessage(kEnqueueFeed);
firstUpdate->AddData("feeds", B_RAW_TYPE, (void*)fFeed, sizeof(Feed));
((App*)be_app)->MessageReceived(firstUpdate);
BMessage* enqueueUpdated = new BMessage(kEnqueueFeed);
enqueueUpdated->AddData("feeds", B_RAW_TYPE, (void*)fFeed, sizeof(Feed));
((App*)be_app)->MessageReceived(enqueueUpdated);
((App*)be_app)->MessageReceived(new BMessage(kFeedsEdited));
Quit();
}
@ -147,6 +150,7 @@ void
FeedEditWindow::_DeleteFeed()
{
fFeed->Unfiletize();
((App*)be_app)->MessageReceived(new BMessage(kFeedsEdited));
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.
*/
@ -44,22 +44,25 @@ FeedsView::MessageReceived(BMessage* msg)
case kFeedsRemoveButton:
{
_RemoveSelectedFeed();
_PopulateFeedList();
break;
}
case kFeedsEditButton:
{
_EditSelectedFeed();
_PopulateFeedList();
break;
}
case kFeedsSelected:
{
fEditButton->SetEnabled(true);
fRemoveButton->SetEnabled(true);
bool enabled = msg->GetInt32("index", -1) >= 0;
fEditButton->SetEnabled(enabled);
fRemoveButton->SetEnabled(enabled);
break;
}
case kFeedsEdited:
{
break;
// _PopulateFeedList();
}
default:
{
@ -80,11 +83,7 @@ FeedsView::_InitInterface()
fFeedsListView->SetSelectionMessage(new BMessage(kFeedsSelected));
fFeedsListView->SetInvocationMessage(new BMessage(kFeedsEditButton));
BList feeds = FeedController::SubscribedFeeds();
for (int i = 0; i < feeds.CountItems(); i++) {
FeedListItem* item = new FeedListItem((Feed*)feeds.ItemAt(i));
fFeedsListView->AddItem(item);
}
_PopulateFeedList();
// Add, Remove, Edit
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.
*/
#ifndef FEEDSVIEW_H
@ -28,7 +28,7 @@ class FeedsView : public BGroupView {
public:
FeedsView(const char* name);
void MessageReceived(BMessage* msg);
virtual void MessageReceived(BMessage* msg);
private:
void _InitInterface();
@ -36,6 +36,8 @@ private:
void _EditSelectedFeed();
void _RemoveSelectedFeed();
void _PopulateFeedList();
BButton* fAddButton;
BButton* fRemoveButton;
BButton* fEditButton;

View File

@ -7,10 +7,11 @@
#include <Button.h>
#include <GroupView.h>
#include <TabView.h>
#include <LayoutBuilder.h>
#include <SeparatorView.h>
#include <StatusBar.h>
#include <String.h>
#include <TabView.h>
#include <cstdio>
@ -18,6 +19,7 @@
#include "EntriesView.h"
#include "FeedController.h"
#include "FeedsView.h"
#include "Notifier.h"
#include "UpdatesView.h"
@ -40,10 +42,24 @@ MainWindow::MessageReceived(BMessage *msg)
case kFeedsRemoveButton:
case kFeedsEditButton:
case kFeedsSelected:
case kFeedsEdited:
{
fFeedsView->MessageReceived(msg);
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:
{
BWindow::MessageReceived(msg);
@ -56,6 +72,7 @@ MainWindow::MessageReceived(BMessage *msg)
void
MainWindow::_InitInterface()
{
// Tabs
fBaseView = new BGroupView("baseView");
fTabView = new BTabView("tabView", B_WIDTH_FROM_WIDEST);
fFeedsView = new FeedsView("Feeds");
@ -68,17 +85,22 @@ MainWindow::_InitInterface()
fTabView->SetBorder(B_NO_BORDER);
fBaseView->AddChild(fTabView);
// Bottom bar
fStatusBar = new BStatusBar("feedProgress");
fUpdateNowButton = new BButton("updateNow", "Update Now",
new BMessage(kUpdateSubscribed));
fUpdateNowButton->SetTarget((App*)be_app);
fUpdateNowButton->SetExplicitAlignment(
BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE));
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
.SetInsets(0, B_USE_DEFAULT_SPACING, 0, 0)
.Add(fBaseView)
.Add(new BSeparatorView(B_HORIZONTAL))
.AddGroup(B_HORIZONTAL)
.Add(fStatusBar)
.Add(fUpdateNowButton)
.SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_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 BGroupView;
class BStatusBar;
class BTabView;
class EntriesView;
class FeedsView;
@ -21,13 +22,16 @@ public:
private:
void _InitInterface();
BGroupView* fBaseView;
void _UpdateProgress();
BGroupView* fBaseView;
BTabView* fTabView;
EntriesView* fEntriesView;
FeedsView* fFeedsView;
UpdatesView* fUpdatesView;
BButton* fUpdateNowButton;
BStatusBar* fStatusBar;
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.
*/
#include "Notifier.h"
#include <Message.h>
#include <Notification.h>
#include "App.h"
#include "FeedController.h"
#include "Notifier.h"
Notifier::Notifier()
:
fEnqueuedFeeds(0),
fFeedsInProgress(0)
{
}
void
@ -16,6 +25,13 @@ Notifier::MessageReceived(BMessage* msg)
{
switch (msg->what)
{
case kEnqueueFeed:
{
fEnqueuedFeeds++;
fFeedsInProgress++;
_UpdateProgress();
break;
}
case kParseComplete:
{
BString feedName;
@ -27,18 +43,28 @@ Notifier::MessageReceived(BMessage* msg)
if (entryCount > 0)
_NewEntryNotification(feedName, entryCount);
}
fFeedsInProgress--;
_UpdateProgress();
break;
}
case kParseFail:
{
BString feedUrl = msg->GetString("feed_url", "");
_ParseFailNotification(feedUrl);
fFeedsInProgress--;
_UpdateProgress();
break;
}
case kDownloadFail:
{
BString feedUrl = msg->GetString("feed_url", "");
_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.
*/
#ifndef NOTIFIER_H
@ -8,10 +8,19 @@
#include <SupportDefs.h>
class BString;
class BMessage;
enum
{
kProgress = 'npro'
};
class Notifier {
public:
Notifier();
void MessageReceived(BMessage* msg);
private:
@ -19,6 +28,10 @@ private:
void _ParseFailNotification(BString feedUrl);
void _DownloadFailNotification(BString feedUrl);
void _UpdateProgress();
int32 fEnqueuedFeeds;
int32 fFeedsInProgress;
};