Notifications: use a single settings file.
There were 3 setting files, each an archived BMessage. Now there is only one with all the data inside. * Rework the SettingsPane class to save and load settings from a message, rather than having each panel pick a file path on its own * Move saving the app filters to the preference app, rather than the server (so it's done at the same place as other settings) * Rework loading prefs in the server so the settings message is read from the file once and all settings are loaded from it. This turns out to be more changes than I anticipated. Fixes #9424.
This commit is contained in:
@@ -13,10 +13,7 @@
|
|||||||
const uint32 kNotificationMessage = 'nssm';
|
const uint32 kNotificationMessage = 'nssm';
|
||||||
|
|
||||||
// Settings constants
|
// Settings constants
|
||||||
extern const char* kSettingsDirectory;
|
extern const char* kSettingsFile;
|
||||||
extern const char* kFiltersSettings;
|
|
||||||
extern const char* kGeneralSettings;
|
|
||||||
extern const char* kDisplaySettings;
|
|
||||||
|
|
||||||
// General settings
|
// General settings
|
||||||
extern const char* kAutoStartName;
|
extern const char* kAutoStartName;
|
||||||
|
|||||||
@@ -52,9 +52,6 @@ DisplayView::DisplayView(SettingsHost* host)
|
|||||||
fIconSize->SetLabelFromMarked(true);
|
fIconSize->SetLabelFromMarked(true);
|
||||||
fIconSizeField = new BMenuField(B_TRANSLATE("Icon size:"), fIconSize);
|
fIconSizeField = new BMenuField(B_TRANSLATE("Icon size:"), fIconSize);
|
||||||
|
|
||||||
// Load settings
|
|
||||||
Load();
|
|
||||||
|
|
||||||
// Calculate inset
|
// Calculate inset
|
||||||
float inset = ceilf(be_plain_font->Size() * 0.7f);
|
float inset = ceilf(be_plain_font->Size() * 0.7f);
|
||||||
|
|
||||||
@@ -92,30 +89,20 @@ DisplayView::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DisplayView::Load()
|
DisplayView::Load(BMessage& settings)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
BPath path;
|
BPath path;
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
path.Append(kSettingsDirectory);
|
path.Append(kSettingsFile);
|
||||||
|
|
||||||
if (create_directory(path.Path(), 0755) != B_OK) {
|
|
||||||
BAlert* alert = new BAlert("",
|
|
||||||
B_TRANSLATE("There was a problem saving the preferences.\n"
|
|
||||||
"It's possible you don't have write access to the "
|
|
||||||
"settings directory."), B_TRANSLATE("OK"), NULL, NULL,
|
|
||||||
B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
|
||||||
(void)alert->Go();
|
|
||||||
}
|
|
||||||
|
|
||||||
path.Append(kDisplaySettings);
|
|
||||||
|
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
BFile file(path.Path(), B_READ_ONLY);
|
||||||
BMessage settings;
|
BMessage settings;
|
||||||
settings.Unflatten(&file);
|
settings.Unflatten(&file);
|
||||||
|
#endif
|
||||||
|
|
||||||
char buffer[255];
|
char buffer[255];
|
||||||
int32 setting;
|
int32 setting;
|
||||||
@@ -144,18 +131,8 @@ DisplayView::Load()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DisplayView::Save()
|
DisplayView::Save(BMessage& settings)
|
||||||
{
|
{
|
||||||
BPath path;
|
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
path.Append(kSettingsDirectory);
|
|
||||||
path.Append(kDisplaySettings);
|
|
||||||
|
|
||||||
BMessage settings;
|
|
||||||
|
|
||||||
float width = atof(fWindowWidth->Text());
|
float width = atof(fWindowWidth->Text());
|
||||||
settings.AddFloat(kWidthName, width);
|
settings.AddFloat(kWidthName, width);
|
||||||
|
|
||||||
@@ -169,19 +146,6 @@ DisplayView::Save()
|
|||||||
}
|
}
|
||||||
settings.AddInt32(kIconSizeName, (int32)iconSize);
|
settings.AddInt32(kIconSizeName, (int32)iconSize);
|
||||||
|
|
||||||
// Save settings file
|
|
||||||
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
|
||||||
status_t ret = settings.Flatten(&file);
|
|
||||||
if (ret != B_OK) {
|
|
||||||
BAlert* alert = new BAlert("",
|
|
||||||
B_TRANSLATE("Can't save preferenes, you probably don't have "
|
|
||||||
"write access to the settings directory or the disk is full."),
|
|
||||||
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
|
||||||
(void)alert->Go();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* msg);
|
virtual void MessageReceived(BMessage* msg);
|
||||||
|
|
||||||
// SettingsPane hooks
|
// SettingsPane hooks
|
||||||
status_t Load();
|
status_t Load(BMessage&);
|
||||||
status_t Save();
|
status_t Save(BMessage&);
|
||||||
status_t Revert();
|
status_t Revert();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -65,9 +65,6 @@ GeneralView::GeneralView(SettingsHost* host)
|
|||||||
// TODO: Here will come a screen representation with the four corners
|
// TODO: Here will come a screen representation with the four corners
|
||||||
// clickable
|
// clickable
|
||||||
|
|
||||||
// Load settings
|
|
||||||
Load();
|
|
||||||
|
|
||||||
// Calculate inset
|
// Calculate inset
|
||||||
float inset = ceilf(be_plain_font->Size() * 0.7f);
|
float inset = ceilf(be_plain_font->Size() * 0.7f);
|
||||||
|
|
||||||
@@ -180,31 +177,8 @@ GeneralView::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
GeneralView::Load()
|
GeneralView::Load(BMessage& settings)
|
||||||
{
|
{
|
||||||
BPath path;
|
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
path.Append(kSettingsDirectory);
|
|
||||||
|
|
||||||
if (create_directory(path.Path(), 0755) != B_OK) {
|
|
||||||
BAlert* alert = new BAlert("",
|
|
||||||
B_TRANSLATE("There was a problem saving the preferences.\n"
|
|
||||||
"It's possible you don't have write access to the "
|
|
||||||
"settings directory."), B_TRANSLATE("OK"), NULL, NULL,
|
|
||||||
B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
|
||||||
(void)alert->Go();
|
|
||||||
}
|
|
||||||
|
|
||||||
path.Append(kGeneralSettings);
|
|
||||||
|
|
||||||
BMessage settings;
|
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
|
||||||
settings.Unflatten(&file);
|
|
||||||
|
|
||||||
char buffer[255];
|
char buffer[255];
|
||||||
|
|
||||||
fNotificationBox->SetValue(_IsServerRunning() ? B_CONTROL_ON : B_CONTROL_OFF);
|
fNotificationBox->SetValue(_IsServerRunning() ? B_CONTROL_ON : B_CONTROL_OFF);
|
||||||
@@ -225,39 +199,14 @@ GeneralView::Load()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
GeneralView::Save()
|
GeneralView::Save(BMessage& settings)
|
||||||
{
|
{
|
||||||
BPath path;
|
|
||||||
|
|
||||||
status_t ret = B_OK;
|
|
||||||
ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
|
||||||
if (ret != B_OK)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
path.Append(kSettingsDirectory);
|
|
||||||
path.Append(kGeneralSettings);
|
|
||||||
|
|
||||||
BMessage settings;
|
|
||||||
|
|
||||||
bool autoStart = (fAutoStart->Value() == B_CONTROL_ON);
|
bool autoStart = (fAutoStart->Value() == B_CONTROL_ON);
|
||||||
settings.AddBool(kAutoStartName, autoStart);
|
settings.AddBool(kAutoStartName, autoStart);
|
||||||
|
|
||||||
int32 timeout = atol(fTimeout->Text());
|
int32 timeout = atol(fTimeout->Text());
|
||||||
settings.AddInt32(kTimeoutName, timeout);
|
settings.AddInt32(kTimeoutName, timeout);
|
||||||
|
|
||||||
// Save settings file
|
|
||||||
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
|
||||||
ret = settings.Flatten(&file);
|
|
||||||
if (ret != B_OK) {
|
|
||||||
BAlert* alert = new BAlert("",
|
|
||||||
B_TRANSLATE("An error occurred saving the preferences.\n"
|
|
||||||
"It's possible you are running out of disk space."),
|
|
||||||
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
|
||||||
(void)alert->Go();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find server path
|
// Find server path
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
if (!_CanFindServer(&ref)) {
|
if (!_CanFindServer(&ref)) {
|
||||||
@@ -273,7 +222,8 @@ GeneralView::Save()
|
|||||||
BPath serverPath(&ref);
|
BPath serverPath(&ref);
|
||||||
|
|
||||||
// Start server at boot time
|
// Start server at boot time
|
||||||
ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
|
BPath path;
|
||||||
|
status_t ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
|
||||||
if (ret != B_OK) {
|
if (ret != B_OK) {
|
||||||
BAlert* alert = new BAlert("",
|
BAlert* alert = new BAlert("",
|
||||||
B_TRANSLATE("Can't save preferences, you probably don't have "
|
B_TRANSLATE("Can't save preferences, you probably don't have "
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* msg);
|
virtual void MessageReceived(BMessage* msg);
|
||||||
|
|
||||||
// SettingsPane hooks
|
// SettingsPane hooks
|
||||||
status_t Load();
|
status_t Load(BMessage&);
|
||||||
status_t Save();
|
status_t Save(BMessage&);
|
||||||
status_t Revert();
|
status_t Revert();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -47,12 +47,10 @@ const int32 kDateIndex = 1;
|
|||||||
const int32 kTypeIndex = 2;
|
const int32 kTypeIndex = 2;
|
||||||
const int32 kAllowIndex = 3;
|
const int32 kAllowIndex = 3;
|
||||||
|
|
||||||
const int32 kSettingChanged = '_STC';
|
|
||||||
|
|
||||||
|
NotificationsView::NotificationsView(SettingsHost* host)
|
||||||
NotificationsView::NotificationsView()
|
|
||||||
:
|
:
|
||||||
BView("apps", B_WILL_DRAW)
|
SettingsPane("apps", host)
|
||||||
{
|
{
|
||||||
BRect rect(0, 0, 100, 100);
|
BRect rect(0, 0, 100, 100);
|
||||||
|
|
||||||
@@ -100,10 +98,6 @@ NotificationsView::NotificationsView()
|
|||||||
(kCLVTitlePadding * 2), rect.Width(), B_TRUNCATE_END, B_ALIGN_LEFT);
|
(kCLVTitlePadding * 2), rect.Width(), B_TRUNCATE_END, B_ALIGN_LEFT);
|
||||||
fNotifications->AddColumn(fAllowCol, kAllowIndex);
|
fNotifications->AddColumn(fAllowCol, kAllowIndex);
|
||||||
|
|
||||||
// Load the applications list
|
|
||||||
_LoadAppUsage();
|
|
||||||
_PopulateApplications();
|
|
||||||
|
|
||||||
// Calculate inset
|
// Calculate inset
|
||||||
float inset = ceilf(be_plain_font->Size() * 0.7f);
|
float inset = ceilf(be_plain_font->Size() * 0.7f);
|
||||||
|
|
||||||
@@ -169,33 +163,8 @@ NotificationsView::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
NotificationsView::_LoadAppUsage()
|
NotificationsView::Load(BMessage& settings)
|
||||||
{
|
{
|
||||||
BPath path;
|
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
path.Append(kSettingsDirectory);
|
|
||||||
|
|
||||||
if (create_directory(path.Path(), 0755) != B_OK) {
|
|
||||||
BAlert* alert = new BAlert("",
|
|
||||||
B_TRANSLATE("There was a problem saving the preferences.\n"
|
|
||||||
"It's possible you don't have write access to the "
|
|
||||||
"settings directory."), B_TRANSLATE("OK"), NULL, NULL,
|
|
||||||
B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
|
||||||
(void)alert->Go();
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
path.Append(kFiltersSettings);
|
|
||||||
|
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
|
||||||
BMessage settings;
|
|
||||||
if (settings.Unflatten(&file) != B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
type_code type;
|
type_code type;
|
||||||
int32 count = 0;
|
int32 count = 0;
|
||||||
|
|
||||||
@@ -215,6 +184,20 @@ NotificationsView::_LoadAppUsage()
|
|||||||
fAppFilters[app->Name()] = app;
|
fAppFilters[app->Name()] = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load the applications list
|
||||||
|
_PopulateApplications();
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
NotificationsView::Save(BMessage& storage)
|
||||||
|
{
|
||||||
|
appusage_t::iterator fIt;
|
||||||
|
for (fIt = fAppFilters.begin(); fIt != fAppFilters.end(); fIt++)
|
||||||
|
storage.AddFlat("app_usage", fIt->second);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include <notification/AppUsage.h>
|
#include <notification/AppUsage.h>
|
||||||
|
|
||||||
|
#include "SettingsPane.h"
|
||||||
|
|
||||||
typedef std::map<BString, AppUsage *> appusage_t;
|
typedef std::map<BString, AppUsage *> appusage_t;
|
||||||
|
|
||||||
class BCheckBox;
|
class BCheckBox;
|
||||||
@@ -18,15 +20,17 @@ class BColumnListView;
|
|||||||
class BStringColumn;
|
class BStringColumn;
|
||||||
class BDateColumn;
|
class BDateColumn;
|
||||||
|
|
||||||
class NotificationsView : public BView {
|
class NotificationsView : public SettingsPane {
|
||||||
public:
|
public:
|
||||||
NotificationsView();
|
NotificationsView(SettingsHost* host);
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void MessageReceived(BMessage* msg);
|
virtual void MessageReceived(BMessage* msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _LoadAppUsage();
|
status_t Load(BMessage&);
|
||||||
|
status_t Save(BMessage&);
|
||||||
|
status_t Revert() {return B_OK;} // FIXME implement this
|
||||||
void _PopulateApplications();
|
void _PopulateApplications();
|
||||||
void _Populate(AppUsage* usage);
|
void _Populate(AppUsage* usage);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ PrefletView::PrefletView(SettingsHost* host)
|
|||||||
// Pages
|
// Pages
|
||||||
GeneralView* general = new GeneralView(host);
|
GeneralView* general = new GeneralView(host);
|
||||||
DisplayView* display = new DisplayView(host);
|
DisplayView* display = new DisplayView(host);
|
||||||
NotificationsView* apps = new NotificationsView();
|
NotificationsView* apps = new NotificationsView(host);
|
||||||
|
|
||||||
// Page selector
|
// Page selector
|
||||||
BTab* tab = new BTab();
|
BTab* tab = new BTab();
|
||||||
|
|||||||
@@ -7,13 +7,19 @@
|
|||||||
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "PrefletWin.h"
|
||||||
|
|
||||||
|
#include <Alert.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <GroupLayout.h>
|
|
||||||
#include <GroupLayoutBuilder.h>
|
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
|
#include <FindDirectory.h>
|
||||||
|
#include <GroupLayout.h>
|
||||||
|
#include <GroupLayoutBuilder.h>
|
||||||
|
#include <Path.h>
|
||||||
|
|
||||||
|
#include <notification/Notifications.h>
|
||||||
|
|
||||||
#include "PrefletWin.h"
|
|
||||||
#include "PrefletView.h"
|
#include "PrefletView.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -60,6 +66,8 @@ PrefletWin::PrefletWin()
|
|||||||
.SetInsets(inset, inset, inset, inset)
|
.SetInsets(inset, inset, inset, inset)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ReloadSettings();
|
||||||
|
|
||||||
// Center this window on screen and show it
|
// Center this window on screen and show it
|
||||||
CenterOnScreen();
|
CenterOnScreen();
|
||||||
Show();
|
Show();
|
||||||
@@ -71,18 +79,44 @@ PrefletWin::MessageReceived(BMessage* msg)
|
|||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case kApply:
|
case kApply:
|
||||||
|
{
|
||||||
|
BPath path;
|
||||||
|
|
||||||
|
status_t ret = B_OK;
|
||||||
|
ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||||
|
if (ret != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
path.Append(kSettingsFile);
|
||||||
|
|
||||||
|
BMessage settingsStore;
|
||||||
for (int32 i = 0; i < fMainView->CountPages(); i++) {
|
for (int32 i = 0; i < fMainView->CountPages(); i++) {
|
||||||
SettingsPane* pane =
|
SettingsPane* pane =
|
||||||
dynamic_cast<SettingsPane*>(fMainView->PageAt(i));
|
dynamic_cast<SettingsPane*>(fMainView->PageAt(i));
|
||||||
if (pane) {
|
if (pane) {
|
||||||
if (pane->Save() == B_OK) {
|
if (pane->Save(settingsStore) == B_OK) {
|
||||||
fApply->SetEnabled(false);
|
fApply->SetEnabled(false);
|
||||||
fRevert->SetEnabled(true);
|
fRevert->SetEnabled(true);
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save settings file
|
||||||
|
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
|
ret = settingsStore.Flatten(&file);
|
||||||
|
if (ret != B_OK) {
|
||||||
|
BAlert* alert = new BAlert("",
|
||||||
|
B_TRANSLATE("An error occurred saving the preferences.\n"
|
||||||
|
"It's possible you are running out of disk space."),
|
||||||
|
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL,
|
||||||
|
B_STOP_ALERT);
|
||||||
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
|
(void)alert->Go();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case kRevert:
|
case kRevert:
|
||||||
for (int32 i = 0; i < fMainView->CountPages(); i++) {
|
for (int32 i = 0; i < fMainView->CountPages(); i++) {
|
||||||
SettingsPane* pane =
|
SettingsPane* pane =
|
||||||
@@ -112,3 +146,27 @@ PrefletWin::SettingChanged()
|
|||||||
{
|
{
|
||||||
fApply->SetEnabled(true);
|
fApply->SetEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PrefletWin::ReloadSettings()
|
||||||
|
{
|
||||||
|
BPath path;
|
||||||
|
|
||||||
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// FIXME don't load this again here, share with other tabs!
|
||||||
|
path.Append(kSettingsFile);
|
||||||
|
|
||||||
|
BMessage settings;
|
||||||
|
BFile file(path.Path(), B_READ_ONLY);
|
||||||
|
settings.Unflatten(&file);
|
||||||
|
|
||||||
|
for (int32 i = 0; i < fMainView->CountPages(); i++) {
|
||||||
|
SettingsPane* pane =
|
||||||
|
dynamic_cast<SettingsPane*>(fMainView->PageAt(i));
|
||||||
|
if (pane)
|
||||||
|
pane->Load(settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* msg);
|
virtual void MessageReceived(BMessage* msg);
|
||||||
|
|
||||||
virtual void SettingChanged();
|
virtual void SettingChanged();
|
||||||
|
void ReloadSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PrefletView* fMainView;
|
PrefletView* fMainView;
|
||||||
|
|||||||
@@ -8,10 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Node.h>
|
|
||||||
#include <Path.h>
|
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <Directory.h>
|
|
||||||
|
|
||||||
#include "SettingsPane.h"
|
#include "SettingsPane.h"
|
||||||
#include "SettingsHost.h"
|
#include "SettingsHost.h"
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ public:
|
|||||||
|
|
||||||
virtual void MessageReceived(BMessage* msg);
|
virtual void MessageReceived(BMessage* msg);
|
||||||
|
|
||||||
virtual status_t Load() = 0;
|
virtual status_t Load(BMessage&) = 0;
|
||||||
virtual status_t Save() = 0;
|
virtual status_t Save(BMessage&) = 0;
|
||||||
virtual status_t Revert() = 0;
|
virtual status_t Revert() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ NotificationWindow::NotificationWindow()
|
|||||||
SetLayout(new BGroupLayout(B_VERTICAL, 0));
|
SetLayout(new BGroupLayout(B_VERTICAL, 0));
|
||||||
|
|
||||||
_LoadSettings(true);
|
_LoadSettings(true);
|
||||||
_LoadAppFilters(true);
|
|
||||||
|
|
||||||
// Start the message loop
|
// Start the message loop
|
||||||
Hide();
|
Hide();
|
||||||
@@ -125,7 +124,6 @@ NotificationWindow::MessageReceived(BMessage* message)
|
|||||||
case B_NODE_MONITOR:
|
case B_NODE_MONITOR:
|
||||||
{
|
{
|
||||||
_LoadSettings();
|
_LoadSettings();
|
||||||
_LoadAppFilters();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case B_COUNT_PROPERTIES:
|
case B_COUNT_PROPERTIES:
|
||||||
@@ -407,108 +405,21 @@ NotificationWindow::SetPosition()
|
|||||||
|
|
||||||
void
|
void
|
||||||
NotificationWindow::_LoadSettings(bool startMonitor)
|
NotificationWindow::_LoadSettings(bool startMonitor)
|
||||||
{
|
|
||||||
_LoadGeneralSettings(startMonitor);
|
|
||||||
_LoadDisplaySettings(startMonitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
NotificationWindow::_LoadAppFilters(bool startMonitor)
|
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
|
BMessage settings;
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
path.Append(kSettingsDirectory);
|
path.Append(kSettingsFile);
|
||||||
|
|
||||||
if (create_directory(path.Path(), 0755) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
path.Append(kFiltersSettings);
|
|
||||||
|
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
BFile file(path.Path(), B_READ_ONLY);
|
||||||
BMessage settings;
|
settings.Unflatten(&file);
|
||||||
if (settings.Unflatten(&file) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
type_code type;
|
_LoadGeneralSettings(settings);
|
||||||
int32 count = 0;
|
_LoadDisplaySettings(settings);
|
||||||
|
_LoadAppFilters(settings);
|
||||||
if (settings.GetInfo("app_usage", &type, &count) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
|
||||||
AppUsage* app = new AppUsage();
|
|
||||||
settings.FindFlat("app_usage", i, app);
|
|
||||||
fAppFilters[app->Name()] = app;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startMonitor) {
|
|
||||||
node_ref nref;
|
|
||||||
BEntry entry(path.Path());
|
|
||||||
entry.GetNodeRef(&nref);
|
|
||||||
|
|
||||||
if (watch_node(&nref, B_WATCH_ALL, BMessenger(this)) != B_OK) {
|
|
||||||
BAlert* alert = new BAlert(B_TRANSLATE("Warning"),
|
|
||||||
B_TRANSLATE("Couldn't start filter monitor."
|
|
||||||
" Live filter changes disabled."), B_TRANSLATE("Darn."));
|
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
|
||||||
alert->Go();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
NotificationWindow::_SaveAppFilters()
|
|
||||||
{
|
|
||||||
BPath path;
|
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
path.Append(kSettingsDirectory);
|
|
||||||
path.Append(kFiltersSettings);
|
|
||||||
|
|
||||||
BMessage settings;
|
|
||||||
BFile file(path.Path(), B_WRITE_ONLY);
|
|
||||||
|
|
||||||
appfilter_t::iterator fIt;
|
|
||||||
for (fIt = fAppFilters.begin(); fIt != fAppFilters.end(); fIt++)
|
|
||||||
settings.AddFlat("app_usage", fIt->second);
|
|
||||||
|
|
||||||
settings.Flatten(&file);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
NotificationWindow::_LoadGeneralSettings(bool startMonitor)
|
|
||||||
{
|
|
||||||
BPath path;
|
|
||||||
BMessage settings;
|
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
path.Append(kSettingsDirectory);
|
|
||||||
if (create_directory(path.Path(), 0755) == B_OK) {
|
|
||||||
path.Append(kGeneralSettings);
|
|
||||||
|
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
|
||||||
settings.Unflatten(&file);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.FindInt32(kTimeoutName, &fTimeout) != B_OK)
|
|
||||||
fTimeout = kDefaultTimeout;
|
|
||||||
|
|
||||||
// Notify the view about the change
|
|
||||||
views_t::iterator it;
|
|
||||||
for (it = fViews.begin(); it != fViews.end(); ++it) {
|
|
||||||
NotificationView* view = (*it);
|
|
||||||
view->Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startMonitor) {
|
if (startMonitor) {
|
||||||
node_ref nref;
|
node_ref nref;
|
||||||
@@ -527,22 +438,40 @@ NotificationWindow::_LoadGeneralSettings(bool startMonitor)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NotificationWindow::_LoadDisplaySettings(bool startMonitor)
|
NotificationWindow::_LoadAppFilters(BMessage& settings)
|
||||||
{
|
{
|
||||||
BPath path;
|
type_code type;
|
||||||
BMessage settings;
|
int32 count = 0;
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (settings.GetInfo("app_usage", &type, &count) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
path.Append(kSettingsDirectory);
|
for (int32 i = 0; i < count; i++) {
|
||||||
if (create_directory(path.Path(), 0755) == B_OK) {
|
AppUsage* app = new AppUsage();
|
||||||
path.Append(kDisplaySettings);
|
settings.FindFlat("app_usage", i, app);
|
||||||
|
fAppFilters[app->Name()] = app;
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
|
||||||
settings.Unflatten(&file);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NotificationWindow::_LoadGeneralSettings(BMessage& settings)
|
||||||
|
{
|
||||||
|
if (settings.FindInt32(kTimeoutName, &fTimeout) != B_OK)
|
||||||
|
fTimeout = kDefaultTimeout;
|
||||||
|
|
||||||
|
// Notify the view about the change
|
||||||
|
views_t::iterator it;
|
||||||
|
for (it = fViews.begin(); it != fViews.end(); ++it) {
|
||||||
|
NotificationView* view = (*it);
|
||||||
|
view->Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NotificationWindow::_LoadDisplaySettings(BMessage& settings)
|
||||||
|
{
|
||||||
int32 setting;
|
int32 setting;
|
||||||
|
|
||||||
if (settings.FindFloat(kWidthName, &fWidth) != B_OK)
|
if (settings.FindFloat(kWidthName, &fWidth) != B_OK)
|
||||||
@@ -561,18 +490,4 @@ NotificationWindow::_LoadDisplaySettings(bool startMonitor)
|
|||||||
NotificationView* view = (*it);
|
NotificationView* view = (*it);
|
||||||
view->Invalidate();
|
view->Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startMonitor) {
|
|
||||||
node_ref nref;
|
|
||||||
BEntry entry(path.Path());
|
|
||||||
entry.GetNodeRef(&nref);
|
|
||||||
|
|
||||||
if (watch_node(&nref, B_WATCH_ALL, BMessenger(this)) != B_OK) {
|
|
||||||
BAlert* alert = new BAlert(B_TRANSLATE("Warning"),
|
|
||||||
B_TRANSLATE("Couldn't start display settings monitor.\n"
|
|
||||||
"Live filter changes disabled."), B_TRANSLATE("OK"));
|
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
|
||||||
alert->Go();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,10 +65,9 @@ private:
|
|||||||
|
|
||||||
void SetPosition();
|
void SetPosition();
|
||||||
void _LoadSettings(bool startMonitor = false);
|
void _LoadSettings(bool startMonitor = false);
|
||||||
void _LoadAppFilters(bool startMonitor = false);
|
void _LoadAppFilters(BMessage& settings);
|
||||||
void _SaveAppFilters();
|
void _LoadGeneralSettings(BMessage& settings);
|
||||||
void _LoadGeneralSettings(bool startMonitor);
|
void _LoadDisplaySettings(BMessage& settings);
|
||||||
void _LoadDisplaySettings(bool startMonitor);
|
|
||||||
|
|
||||||
views_t fViews;
|
views_t fViews;
|
||||||
appview_t fAppViews;
|
appview_t fAppViews;
|
||||||
|
|||||||
@@ -8,10 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// Settings constants
|
// Settings constants
|
||||||
const char* kSettingsDirectory = "system/notifications";
|
const char* kSettingsFile = "system/notifications";
|
||||||
const char* kFiltersSettings = "filters";
|
|
||||||
const char* kGeneralSettings = "general";
|
|
||||||
const char* kDisplaySettings = "display";
|
|
||||||
|
|
||||||
// General settings
|
// General settings
|
||||||
const char* kAutoStartName = "auto-start";
|
const char* kAutoStartName = "auto-start";
|
||||||
|
|||||||
Reference in New Issue
Block a user