Make 'Updates' tab settings functional

This commit is contained in:
Jaidyn Ann 2021-01-25 19:39:31 -06:00
parent 0066b9a522
commit afcbea6fba
10 changed files with 223 additions and 60 deletions

View File

@ -9,7 +9,7 @@
#include <StorageKit.h> #include <StorageKit.h>
#include <String.h> #include <String.h>
#include <getopt.h> #include <iostream>
#include "AtomFeed.h" #include "AtomFeed.h"
#include "Entry.h" #include "Entry.h"
@ -42,14 +42,21 @@ App::App() : BApplication("application/x-vnd.Pogger")
fPreferences->Load(); fPreferences->Load();
fMainWindow = new MainWindow(); fMainWindow = new MainWindow();
fNotifier = new Notifier();
fFeedController = new FeedController();
fMainWindow->Show(); fMainWindow->Show();
fNotifier = new Notifier();
fFeedController = new FeedController();
BMessage* updateMessage = new BMessage(kUpdateSubscribed); BMessage* updateMessage = new BMessage(kUpdateSubscribed);
int64 interval = fPreferences->UpdateInterval();
int32 count = -1;
if (interval == -1)
count = 0;
// else
// MessageReceived(updateMessage); // MessageReceived(updateMessage);
fUpdateRunner = new BMessageRunner(this, updateMessage,
fPreferences->updateInterval); fUpdateRunner = new BMessageRunner(this, updateMessage, interval, count);
} }

View File

@ -5,7 +5,6 @@
#ifndef APP_H #ifndef APP_H
#define APP_H #define APP_H
#include <SupportDefs.h> #include <SupportDefs.h>
#include <Application.h> #include <Application.h>
@ -25,7 +24,6 @@ public:
void MessageReceived(BMessage* msg); void MessageReceived(BMessage* msg);
void ArgvReceived(int32 argc, char** argv); void ArgvReceived(int32 argc, char** argv);
MainWindow* fMainWindow; MainWindow* fMainWindow;
Preferences* fPreferences; Preferences* fPreferences;
Notifier* fNotifier; Notifier* fNotifier;
@ -35,7 +33,8 @@ private:
FeedController* fFeedController; FeedController* fFeedController;
}; };
int main ( int, char** );
int main(int argc, char** argv);
extern const char* configPath; extern const char* configPath;

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.
*/ */

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 ENTRIESVIEW_H #ifndef ENTRIESVIEW_H

View File

@ -150,7 +150,7 @@ FeedController::_ParseLoop(void* ignored)
BList entries; BList entries;
BString feedTitle; BString feedTitle;
BUrl feedUrl = feedBuffer->GetXmlUrl(); BUrl feedUrl = feedBuffer->GetXmlUrl();
BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->outDir); BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->fEntryDir);
if (feedBuffer->IsAtom()) { if (feedBuffer->IsAtom()) {
AtomFeed* feed = (AtomFeed*)malloc(sizeof(AtomFeed)); AtomFeed* feed = (AtomFeed*)malloc(sizeof(AtomFeed));

View File

@ -73,6 +73,9 @@ Notifier::MessageReceived(BMessage* msg)
void void
Notifier::_NewEntryNotification(BString feedName, int32 entryCount) Notifier::_NewEntryNotification(BString feedName, int32 entryCount)
{ {
if (((App*)be_app)->fPreferences->NotifyOnNew() == false)
return;
BNotification notifyNew(B_INFORMATION_NOTIFICATION); BNotification notifyNew(B_INFORMATION_NOTIFICATION);
BString notifyLabel("New Feed Entries"); BString notifyLabel("New Feed Entries");
BString notifyText("%n% new entries from %source%"); BString notifyText("%n% new entries from %source%");
@ -91,6 +94,9 @@ Notifier::_NewEntryNotification(BString feedName, int32 entryCount)
void void
Notifier::_ParseFailNotification(BString feedUrl) Notifier::_ParseFailNotification(BString feedUrl)
{ {
if (((App*)be_app)->fPreferences->NotifyOnFailure() == false)
return;
BNotification notifyError(B_ERROR_NOTIFICATION); BNotification notifyError(B_ERROR_NOTIFICATION);
BString notifyText("Failed to parse feed from %url%"); BString notifyText("Failed to parse feed from %url%");
@ -108,6 +114,9 @@ Notifier::_ParseFailNotification(BString feedUrl)
void void
Notifier::_DownloadFailNotification(BString feedUrl) Notifier::_DownloadFailNotification(BString feedUrl)
{ {
if (((App*)be_app)->fPreferences->NotifyOnFailure() == false)
return;
BNotification notifyError(B_ERROR_NOTIFICATION); BNotification notifyError(B_ERROR_NOTIFICATION);
BString notifyText("Failed to download feed from %url%"); BString notifyText("Failed to download feed from %url%");

View File

@ -22,20 +22,24 @@ Preferences::Preferences(Preferences* pref) {
void void
Preferences::Load() Preferences::Load()
{ {
configDir = BString("/boot/home/config/settings/Pogger/"); BString configDir("/boot/home/config/settings/Pogger/");
BString filename = BString(configDir); BString filename = BString(configDir);
filename.Append("settings"); filename.Append("Settings");
BFile file(filename.String(), B_READ_ONLY); BFile file(filename.String(), B_READ_ONLY);
status_t result = file.InitCheck(); status_t result = file.InitCheck();
BMessage storage; BMessage storage;
storage.Unflatten(&file); storage.Unflatten(&file);
updateInterval = storage.GetInt64("updateInterval", 3600000000); fEntryDir = BString(storage.GetString("entryDir", "/boot/home/feeds/"));
outDir = BString(storage.GetString("outDir", "/boot/home/feeds/")); fEntryFileExt = BString(storage.GetString("entryExt", ""));
cacheDir = BString(storage.GetString("cacheDir", fOpenAsHtml = storage.GetBool("openAsHtml", false);
"/boot/home/config/cache/Pogger/")); fOpenWith = BString(storage.GetString("openWith", "WebPositive"));
fNewNotify = storage.GetBool("notifyNew", true);
fFailureNotify = storage.GetBool("notifyFailure", true);
fUpdateInterval = storage.GetInt8("updateInterval", 1);
} }
@ -43,8 +47,7 @@ Preferences::Load()
void void
Preferences::Save() Preferences::Save()
{ {
if (configDir == NULL) BString configDir = BString("/boot/home/config/settings/Pogger/");
configDir = BString("/boot/home/config/settings/Pogger/");
BPath* cfgPath = new BPath(configDir.String(), NULL, true); BPath* cfgPath = new BPath(configDir.String(), NULL, true);
BEntry* cfgEntry = new BEntry(cfgPath->Path()); BEntry* cfgEntry = new BEntry(cfgPath->Path());
@ -56,16 +59,81 @@ Preferences::Save ()
cfgDir->CreateDirectory(cfgPath->Path(), NULL); cfgDir->CreateDirectory(cfgPath->Path(), NULL);
BMessage storage; BMessage storage;
BString filename = BString(configDir).Append("/settings"); BString filename = BString(configDir).Append("/Settings");
BFile* file = new BFile(filename.String(), B_WRITE_ONLY | B_CREATE_FILE BFile* file = new BFile(filename.String(), B_WRITE_ONLY | B_CREATE_FILE
| B_ERASE_FILE); | B_ERASE_FILE);
status_t result = file->InitCheck(); status_t result = file->InitCheck();
storage.AddFloat("updateInterval", updateInterval); storage.AddString("entryDir", fEntryDir.String());
storage.AddString("outDir", outDir.String()); storage.AddString("entryExt", fEntryFileExt.String());
storage.AddString("cacheDir", cacheDir.String()); storage.AddBool("openAsHtml", fOpenAsHtml);
storage.AddString("openWith", fOpenWith.String());
storage.AddBool("notifyNew", fNewNotify);
storage.AddBool("notifyFailure", fFailureNotify);
storage.AddInt8("updateInterval", fUpdateInterval);
storage.Flatten(file); storage.Flatten(file);
} }
int64
Preferences::UpdateInterval()
{
int hours = fUpdateInterval - 1;
switch (hours)
{
case -1:
return -1;
case 0:
return HOUR_IN_MICROSECONDS / 2;
default:
return HOUR_IN_MICROSECONDS * hours;
}
}
int
Preferences::UpdateIntervalIndex()
{
return fUpdateInterval;
}
void
Preferences::SetUpdateIntervalIndex(int8 index)
{
fUpdateInterval = index;
}
bool
Preferences::NotifyOnFailure()
{
return fFailureNotify;
}
bool
Preferences::NotifyOnNew()
{
return fNewNotify;
}
void
Preferences::SetNotifyOnFailure(bool value)
{
fFailureNotify = value;
}
void
Preferences::SetNotifyOnNew(bool value)
{
fNewNotify = value;
}

View File

@ -11,6 +11,9 @@
#include <StorageKit.h> #include <StorageKit.h>
const int64 HOUR_IN_MICROSECONDS = 3600000000;
class Preferences { class Preferences {
public: public:
Preferences(); Preferences();
@ -19,16 +22,27 @@ public:
void Load(); void Load();
void Save(); void Save();
bool verbose; int64 UpdateInterval();
bool daemon; int UpdateIntervalIndex();
BString outDir; void SetUpdateIntervalIndex(int8 index);
int64 updateInterval; bool NotifyOnFailure();
BString configDir; bool NotifyOnNew();
BString cacheDir; void SetNotifyOnFailure(bool value);
bool will_save; void SetNotifyOnNew(bool value);
bool updateFeeds;
BString fEntryDir;
BString fEntryFileExt;
bool fOpenAsHtml;
BString fOpenWith;
private:
int8 fUpdateInterval;
bool fNewNotify;
bool fFailureNotify;
}; };

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.
*/ */
@ -8,11 +8,14 @@
#include <Box.h> #include <Box.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <Message.h> #include <Message.h>
#include <MessageRunner.h>
#include <LayoutBuilder.h> #include <LayoutBuilder.h>
#include <Slider.h> #include <Slider.h>
#include <cstdio> #include <cstdio>
#include "App.h"
UpdatesView::UpdatesView(const char* name) UpdatesView::UpdatesView(const char* name)
: :
@ -26,7 +29,7 @@ void
UpdatesView::AttachedToWindow() UpdatesView::AttachedToWindow()
{ {
fNotifyNewCheck->SetTarget(this); fNotifyNewCheck->SetTarget(this);
fNotifyErrorCheck->SetTarget(this); fNotifyFailCheck->SetTarget(this);
fIntervalSlider->SetTarget(this); fIntervalSlider->SetTarget(this);
} }
@ -36,14 +39,31 @@ UpdatesView::MessageReceived(BMessage* msg)
{ {
switch (msg->what) switch (msg->what)
{ {
case 'iiii': case kNotifyNewCheckbox:
{ {
if (fNotifyNewCheck->Value() == B_CONTROL_ON)
((App*)be_app)->fPreferences->SetNotifyOnNew(true);
else
((App*)be_app)->fPreferences->SetNotifyOnNew(false);
break;
}
case kNotifyFailCheckbox:
{
if (fNotifyFailCheck->Value() == B_CONTROL_ON)
((App*)be_app)->fPreferences->SetNotifyOnFailure(true);
else
((App*)be_app)->fPreferences->SetNotifyOnFailure(false);
break;
}
case kIntervalChanged:
{
_UpdateIntervalPreference();
_UpdateIntervalLabel(); _UpdateIntervalLabel();
break; break;
} }
default: default:
{ {
// BWindow::MessageReceived(msg); BGroupView::MessageReceived(msg);
break; break;
} }
} }
@ -53,32 +73,44 @@ UpdatesView::MessageReceived(BMessage* msg)
void void
UpdatesView::_InitInterface() UpdatesView::_InitInterface()
{ {
fNotifyNewCheck = new BCheckBox("newNotify", "Notify about new entries", // Notifications
new BMessage('nnnc'));
fNotifyErrorCheck = new BCheckBox("errorNotify",
"Notify about update failures", new BMessage('nnnc'));
fNotificationsBox = new BBox("notifications"); fNotificationsBox = new BBox("notifications");
fNotificationsBox->SetLabel("Notifications"); fNotificationsBox->SetLabel("Notifications");
fNotifyNewCheck = new BCheckBox("newNotify", "Notify about new entries",
new BMessage(kNotifyNewCheckbox));
fNotifyFailCheck = new BCheckBox("errorNotify",
"Notify about update failures", new BMessage(kNotifyFailCheckbox));
// Update scheduling
fSchedulingBox = new BBox("scheduling");
fSchedulingBox->SetLabel("Scheduling");
fIntervalSlider = fIntervalSlider =
new BSlider("interval", "Never automatically update", new BSlider("interval", "Never automatically update",
new BMessage('iiii'), 0, 25, B_HORIZONTAL); new BMessage(kIntervalChanged), 0, 25, B_HORIZONTAL);
fIntervalSlider->SetHashMarkCount(26); fIntervalSlider->SetHashMarkCount(26);
fIntervalSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fIntervalSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
fIntervalSlider->SetLimitLabels("Never", "24 hours"); fIntervalSlider->SetLimitLabels("Never", "24 hours");
fIntervalSlider->SetModificationMessage(new BMessage('iiii')); fIntervalSlider->SetModificationMessage(new BMessage('iiii'));
fSchedulingBox = new BBox("scheduling"); // Display current settings
fSchedulingBox->SetLabel("Scheduling"); if (((App*)be_app)->fPreferences->NotifyOnNew() == true)
fNotifyNewCheck->SetValue(B_CONTROL_ON);
if (((App*)be_app)->fPreferences->NotifyOnFailure() == true)
fNotifyFailCheck->SetValue(B_CONTROL_ON);
fIntervalSlider->SetValue(((App*)be_app)->fPreferences->UpdateIntervalIndex());
_UpdateIntervalLabel();
BLayoutBuilder::Group<>(fNotificationsBox, B_VERTICAL, B_USE_HALF_ITEM_SPACING) BLayoutBuilder::Group<>(fNotificationsBox, B_VERTICAL, B_USE_HALF_ITEM_SPACING)
.SetInsets(B_USE_ITEM_INSETS) .SetInsets(B_USE_ITEM_INSETS)
.AddStrut(B_USE_ITEM_SPACING) .AddStrut(B_USE_ITEM_SPACING)
.Add(fNotifyNewCheck) .Add(fNotifyNewCheck)
.Add(fNotifyErrorCheck) .Add(fNotifyFailCheck)
.End(); .End();
BLayoutBuilder::Group<>(fSchedulingBox, B_VERTICAL, B_USE_HALF_ITEM_SPACING) BLayoutBuilder::Group<>(fSchedulingBox, B_VERTICAL, B_USE_HALF_ITEM_SPACING)
@ -94,29 +126,53 @@ UpdatesView::_InitInterface()
.Add(fSchedulingBox) .Add(fSchedulingBox)
.AddGlue() .AddGlue()
.End(); .End();
}
_UpdateIntervalLabel();
void
UpdatesView::_UpdateIntervalPreference()
{
int32 limit;
fIntervalSlider->GetLimits(NULL, &limit);
int8 index = fIntervalSlider->Position() / (1/(float)limit);
int8 oldIndex = ((App*)be_app)->fPreferences->UpdateIntervalIndex();
((App*)be_app)->fPreferences->SetUpdateIntervalIndex(index);
if (oldIndex == 0)
((App*)be_app)->fUpdateRunner->SetCount(-1);
else if (index == 0)
((App*)be_app)->fUpdateRunner->SetCount(0);
((App*)be_app)->fUpdateRunner->SetInterval(
((App*)be_app)->fPreferences->UpdateInterval());
} }
void void
UpdatesView::_UpdateIntervalLabel() UpdatesView::_UpdateIntervalLabel()
{ {
int32 limit; int8 hours = ((App*)be_app)->fPreferences->UpdateIntervalIndex() - 1;
fIntervalSlider->GetLimits(NULL, &limit);
int index = fIntervalSlider->Position() / (1/(float)limit);
int hours = index - 1;
BString newLabel; BString newLabel;
BString strHour; BString strHour;
strHour << (int)hours; strHour << hours;
if (hours == -1 ) switch (hours)
{
case -1:
{
newLabel = "Never automatically update"; newLabel = "Never automatically update";
else if (hours == 0) break;
}
case 0:
{
newLabel = "Update every 30 minutes"; newLabel = "Update every 30 minutes";
else break;
}
default:
newLabel = "Update every %hour% hours"; newLabel = "Update every %hour% hours";
}
newLabel.ReplaceAll("%hour%", strHour); newLabel.ReplaceAll("%hour%", strHour);
fIntervalSlider->SetLabel(newLabel.String()); fIntervalSlider->SetLabel(newLabel.String());

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 UPDATESVIEW_H #ifndef UPDATESVIEW_H
@ -15,6 +15,14 @@ class BMessage;
class BSlider; class BSlider;
enum
{
kIntervalChanged = 'intu',
kNotifyNewCheckbox = 'chnn',
kNotifyFailCheckbox = 'chnf'
};
class UpdatesView : public BGroupView { class UpdatesView : public BGroupView {
public: public:
UpdatesView(const char* name); UpdatesView(const char* name);
@ -24,13 +32,15 @@ public:
private: private:
void _InitInterface(); void _InitInterface();
void _UpdateIntervalPreference();
void _UpdateIntervalLabel(); void _UpdateIntervalLabel();
BBox* fNotificationsBox; BBox* fNotificationsBox;
BBox* fSchedulingBox; BBox* fSchedulingBox;
BCheckBox* fNotifyNewCheck; BCheckBox* fNotifyNewCheck;
BCheckBox* fNotifyErrorCheck; BCheckBox* fNotifyFailCheck;
BSlider* fIntervalSlider; BSlider* fIntervalSlider;
}; };