Pogger/src/Preferences.cpp

146 lines
2.8 KiB
C++
Raw Normal View History

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-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/"));
2021-01-28 00:19:36 -06:00
fOpenAs = storage.GetInt8("openAs", kOpenAsUrl);
fOpenWith = BString(storage.GetString("openWith",
"application/x-vnd.Haiku-WebPositive"));
2021-01-25 19:39:31 -06:00
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("openWith", fOpenWith.String());
2021-01-28 00:19:36 -06:00
storage.AddInt8("openAs", fOpenAs);
2021-01-25 19:39:31 -06:00
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;
}
2021-01-28 00:19:36 -06:00
BString
Preferences::EntryDir()
2021-01-25 19:39:31 -06:00
{
2021-01-28 00:19:36 -06:00
return fEntryDir;
2021-01-25 19:39:31 -06:00
}
2021-01-28 00:19:36 -06:00
status_t
Preferences::SetEntryDir(const char* path)
2021-01-25 19:39:31 -06:00
{
2021-01-28 00:19:36 -06:00
status_t testStatus = BEntry(path).InitCheck();
if (testStatus == B_OK)
fEntryDir = BString(path);
return testStatus;
2021-01-25 19:39:31 -06:00
}
2021-01-28 00:19:36 -06:00
BString
Preferences::EntryOpenWith()
2021-01-25 19:39:31 -06:00
{
2021-01-28 00:19:36 -06:00
return fOpenWith;
2021-01-25 19:39:31 -06:00
}
2021-01-28 00:19:36 -06:00
status_t
Preferences::SetEntryOpenWith(const char* binPath)
2021-01-25 19:39:31 -06:00
{
2021-01-28 00:19:36 -06:00
// status_t testStatus = BEntry(binPath).InitCheck();
// if (testStatus == B_OK)
fOpenWith = BString(binPath);
return B_OK;
// return testStatus;
2021-01-25 19:39:31 -06:00
}