2020-12-30 22:07:54 -06:00
|
|
|
/*
|
|
|
|
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
|
|
*/
|
|
|
|
|
2021-01-24 23:20:11 -06:00
|
|
|
#include "Preferences.h"
|
2020-07-03 19:13:41 -05:00
|
|
|
|
2020-12-30 22:07:54 -06:00
|
|
|
#include <String.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
2021-01-24 23:20:11 -06:00
|
|
|
Preferences::Preferences() {
|
2020-07-03 19:13:41 -05:00
|
|
|
}
|
2020-07-07 20:17:52 -05:00
|
|
|
|
2020-12-30 22:07:54 -06:00
|
|
|
|
2021-01-24 23:20:11 -06:00
|
|
|
Preferences::Preferences(Preferences* pref) {
|
2020-08-14 12:34:09 -05:00
|
|
|
}
|
|
|
|
|
2020-12-30 22:07:54 -06:00
|
|
|
|
2020-07-07 20:17:52 -05:00
|
|
|
// !! handle file status
|
|
|
|
void
|
2021-01-24 23:20:11 -06:00
|
|
|
Preferences::Load()
|
2020-07-07 20:17:52 -05:00
|
|
|
{
|
2021-01-25 19:39:31 -06:00
|
|
|
BString configDir("/boot/home/config/settings/Pogger/");
|
2020-07-07 20:17:52 -05:00
|
|
|
|
2020-07-13 12:31:52 -05:00
|
|
|
BString filename = BString(configDir);
|
2021-01-25 19:39:31 -06:00
|
|
|
filename.Append("Settings");
|
2021-01-12 19:08:42 -06:00
|
|
|
BFile file(filename.String(), B_READ_ONLY);
|
|
|
|
status_t result = file.InitCheck();
|
2020-07-07 20:17:52 -05:00
|
|
|
|
|
|
|
BMessage storage;
|
2021-01-12 19:08:42 -06:00
|
|
|
storage.Unflatten(&file);
|
|
|
|
|
2021-01-25 19:39:31 -06:00
|
|
|
fEntryDir = BString(storage.GetString("entryDir", "/boot/home/feeds/"));
|
|
|
|
fEntryFileExt = BString(storage.GetString("entryExt", ""));
|
|
|
|
fOpenAsHtml = storage.GetBool("openAsHtml", false);
|
|
|
|
fOpenWith = BString(storage.GetString("openWith", "WebPositive"));
|
|
|
|
|
|
|
|
fNewNotify = storage.GetBool("notifyNew", true);
|
|
|
|
fFailureNotify = storage.GetBool("notifyFailure", true);
|
|
|
|
fUpdateInterval = storage.GetInt8("updateInterval", 1);
|
2020-07-07 20:17:52 -05:00
|
|
|
}
|
|
|
|
|
2020-12-30 22:07:54 -06:00
|
|
|
|
2020-07-07 20:17:52 -05:00
|
|
|
// !! handle file status
|
|
|
|
void
|
2021-01-25 19:39:31 -06:00
|
|
|
Preferences::Save()
|
2020-07-07 20:17:52 -05:00
|
|
|
{
|
2021-01-25 19:39:31 -06:00
|
|
|
BString configDir = BString("/boot/home/config/settings/Pogger/");
|
2020-07-07 20:17:52 -05:00
|
|
|
|
2020-12-30 22:07:54 -06:00
|
|
|
BPath* cfgPath = new BPath(configDir.String(), NULL, true);
|
|
|
|
BEntry* cfgEntry = new BEntry(cfgPath->Path());
|
|
|
|
BDirectory* cfgDir = new BDirectory;
|
2020-07-07 20:17:52 -05:00
|
|
|
|
|
|
|
cfgDir->CreateDirectory(cfgPath->Path(), NULL);
|
|
|
|
|
2020-12-30 22:07:54 -06:00
|
|
|
if (cfgEntry->Exists() == false)
|
|
|
|
cfgDir->CreateDirectory(cfgPath->Path(), NULL);
|
2020-07-07 20:17:52 -05:00
|
|
|
|
|
|
|
BMessage storage;
|
2021-01-25 19:39:31 -06:00
|
|
|
BString filename = BString(configDir).Append("/Settings");
|
2020-07-07 20:17:52 -05:00
|
|
|
|
2020-12-30 22:07:54 -06:00
|
|
|
BFile* file = new BFile(filename.String(), B_WRITE_ONLY | B_CREATE_FILE
|
|
|
|
| B_ERASE_FILE);
|
2020-07-07 20:17:52 -05:00
|
|
|
status_t result = file->InitCheck();
|
|
|
|
|
2021-01-25 19:39:31 -06:00
|
|
|
storage.AddString("entryDir", fEntryDir.String());
|
|
|
|
storage.AddString("entryExt", fEntryFileExt.String());
|
|
|
|
storage.AddBool("openAsHtml", fOpenAsHtml);
|
|
|
|
storage.AddString("openWith", fOpenWith.String());
|
|
|
|
|
|
|
|
storage.AddBool("notifyNew", fNewNotify);
|
|
|
|
storage.AddBool("notifyFailure", fFailureNotify);
|
|
|
|
storage.AddInt8("updateInterval", fUpdateInterval);
|
2020-07-07 20:17:52 -05:00
|
|
|
|
2020-12-30 22:07:54 -06:00
|
|
|
storage.Flatten(file);
|
2020-07-07 20:17:52 -05:00
|
|
|
}
|
|
|
|
|
2021-01-25 19:39:31 -06:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|