Pogger/src/MainWindow.cpp

130 lines
2.6 KiB
C++
Raw Normal View History

2020-12-30 21:13:12 -06:00
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "MainWindow.h"
#include <Button.h>
#include <GroupView.h>
#include <LayoutBuilder.h>
#include <SeparatorView.h>
#include <StatusBar.h>
2020-12-30 21:13:12 -06:00
#include <String.h>
#include <TabView.h>
2020-12-30 21:13:12 -06:00
#include <cstdio>
2020-12-30 21:13:12 -06:00
#include "App.h"
#include "EntriesView.h"
2021-01-12 15:30:21 -06:00
#include "FeedController.h"
#include "FeedsView.h"
#include "Notifier.h"
#include "UpdatesView.h"
2020-12-30 21:13:12 -06:00
2021-01-15 22:22:33 -06:00
MainWindow::MainWindow()
2020-12-30 21:13:12 -06:00
:
BWindow(BRect(BPoint(-1000.0, -1000.0), BSize(520, 380)), "Pogger",
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
2020-12-30 21:13:12 -06:00
{
_InitInterface();
MoveOnScreen();
}
void
MainWindow::MessageReceived(BMessage *msg)
{
switch (msg->what)
{
2021-01-15 22:22:33 -06:00
case kFeedsAddButton:
case kFeedsRemoveButton:
case kFeedsEditButton:
case kFeedsSelected:
case kFeedsEdited:
2021-02-18 23:16:45 -06:00
case kDownloadStart:
2021-01-15 22:22:33 -06:00
{
fFeedsView->MessageReceived(msg);
break;
}
2021-01-28 00:19:36 -06:00
case kOpenWithSelect:
{
fEntriesView->MessageReceived(msg);
break;
}
case kProgress:
{
2021-02-18 23:16:45 -06:00
fFeedsView->MessageReceived(msg);
int32 max = 0;
int32 current = 0;
if (msg->FindInt32("max", &max) == B_OK
&& msg->FindInt32("current", &current) == B_OK)
{
2021-02-18 22:38:59 -06:00
_UpdateProgress(max, current);
}
break;
}
default:
{
BWindow::MessageReceived(msg);
break;
}
}
2020-12-30 21:13:12 -06:00
}
void
MainWindow::_InitInterface()
{
// Tabs
2020-12-30 21:13:12 -06:00
fBaseView = new BGroupView("baseView");
fTabView = new BTabView("tabView", B_WIDTH_FROM_WIDEST);
fFeedsView = new FeedsView("Feeds");
fEntriesView = new EntriesView("Entries");
fUpdatesView = new UpdatesView("Updates");
2020-12-30 21:13:12 -06:00
fTabView->AddTab(fFeedsView);
fTabView->AddTab(fEntriesView);
fTabView->AddTab(fUpdatesView);
2020-12-30 21:13:12 -06:00
fTabView->SetBorder(B_NO_BORDER);
fBaseView->AddChild(fTabView);
// Bottom bar
fStatusBar = new BStatusBar("feedProgress");
fUpdateNowButton = new BButton("updateNow", "Update Now",
2021-01-12 15:30:21 -06:00
new BMessage(kUpdateSubscribed));
fUpdateNowButton->SetTarget((App*)be_app);
fUpdateNowButton->SetExplicitAlignment(
BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE));
2020-12-30 21:13:12 -06:00
2020-12-30 21:13:12 -06:00
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)
2020-12-30 21:13:12 -06:00
.SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING,
B_USE_DEFAULT_SPACING, B_USE_WINDOW_SPACING)
.End()
.End();
2020-12-30 21:13:12 -06:00
}
void
2021-02-18 22:38:59 -06:00
MainWindow::_UpdateProgress(int32 max, int32 current)
{
2021-02-18 22:38:59 -06:00
int32 prog = max - current;
fStatusBar->SetMaxValue(max);
fStatusBar->SetTo(prog);
printf("%i / %i\n", prog, max);
}