Refactor preference saving/loading
This commit is contained in:
parent
d696ef55b3
commit
f038c492f7
|
@ -96,7 +96,7 @@ Conversation::ImMessage(BMessage* msg)
|
||||||
|| (text.IFindFirst(contact->GetName()) != B_ERROR));
|
|| (text.IFindFirst(contact->GetName()) != B_ERROR));
|
||||||
|
|
||||||
// Send a notification, if appropriate
|
// Send a notification, if appropriate
|
||||||
if (winFocused == false && AppPreferences::Item()->NotifyNewMessage
|
if (winFocused == false && AppPreferences::Get()->NotifyNewMessage
|
||||||
&& (fUsers.CountItems() <= 2 || mentioned == true))
|
&& (fUsers.CountItems() <= 2 || mentioned == true))
|
||||||
{
|
{
|
||||||
BString notifyTitle = B_TRANSLATE("New mention");
|
BString notifyTitle = B_TRANSLATE("New mention");
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <Notification.h>
|
#include <Notification.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
@ -136,7 +137,7 @@ Server::Filter(BMessage* message, BHandler **target)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
// "Whoops" notification
|
// "Whoops" notification
|
||||||
if (AppPreferences::Item()->NotifyProtocolStatus == true
|
if (AppPreferences::Get()->NotifyProtocolStatus == true
|
||||||
&& message->FindString("name", &name) == B_OK) {
|
&& message->FindString("name", &name) == B_OK) {
|
||||||
BBitmap* icon = new BBitmap(message);
|
BBitmap* icon = new BBitmap(message);
|
||||||
BString content(B_TRANSLATE("%user% has been disabled!"));
|
BString content(B_TRANSLATE("%user% has been disabled!"));
|
||||||
|
@ -552,7 +553,7 @@ Server::ImMessage(BMessage* msg)
|
||||||
if (msg->FindFloat("progress", &progress) != B_OK)
|
if (msg->FindFloat("progress", &progress) != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
if (!AppPreferences::Item()->NotifyProtocolStatus)
|
if (!AppPreferences::Get()->NotifyProtocolStatus)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
BNotification notification(B_PROGRESS_NOTIFICATION);
|
BNotification notification(B_PROGRESS_NOTIFICATION);
|
||||||
|
@ -586,7 +587,7 @@ Server::ImMessage(BMessage* msg)
|
||||||
fAccountEnabled.AddItem(looper->Protocol()->GetName(), true);
|
fAccountEnabled.AddItem(looper->Protocol()->GetName(), true);
|
||||||
|
|
||||||
// Ready notification
|
// Ready notification
|
||||||
if (AppPreferences::Item()->NotifyProtocolStatus == true)
|
if (AppPreferences::Get()->NotifyProtocolStatus == true)
|
||||||
_ProtocolNotification(looper, BString(B_TRANSLATE("Connected")),
|
_ProtocolNotification(looper, BString(B_TRANSLATE("Connected")),
|
||||||
BString(B_TRANSLATE("%user% has connected!")));
|
BString(B_TRANSLATE("%user% has connected!")));
|
||||||
|
|
||||||
|
|
|
@ -113,16 +113,29 @@ ChatResources()
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
AccountsPath()
|
SettingsPath()
|
||||||
{
|
{
|
||||||
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 NULL;
|
return NULL;
|
||||||
|
|
||||||
path.Append(APP_NAME "/Accounts");
|
path.Append(APP_NAME);
|
||||||
if (create_directory(path.Path(), 0755) != B_OK)
|
if (create_directory(path.Path(), 0755) != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
return path.Path();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char*
|
||||||
|
AccountsPath()
|
||||||
|
{
|
||||||
|
BPath path(SettingsPath());
|
||||||
|
if (path.InitCheck() != B_OK)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
path.Append("Accounts");
|
||||||
|
if (create_directory(path.Path(), 0755) != B_OK)
|
||||||
|
return NULL;
|
||||||
return path.Path();
|
return path.Path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,10 +161,11 @@ AccountPath(const char* signature, const char* subsignature)
|
||||||
const char*
|
const char*
|
||||||
CachePath()
|
CachePath()
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path(SettingsPath());
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (path.InitCheck() != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
path.Append(APP_NAME "/Cache");
|
|
||||||
|
path.Append("Cache");
|
||||||
if (create_directory(path.Path(), 0755) != B_OK)
|
if (create_directory(path.Path(), 0755) != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
return path.Path();
|
return path.Path();
|
||||||
|
@ -165,6 +179,7 @@ AccountCachePath(const char* accountName)
|
||||||
path.Append("Accounts");
|
path.Append("Accounts");
|
||||||
if (path.InitCheck() != B_OK)
|
if (path.InitCheck() != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
path.Append(accountName);
|
path.Append(accountName);
|
||||||
if (create_directory(path.Path(), 0755) != B_OK)
|
if (create_directory(path.Path(), 0755) != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -178,6 +193,7 @@ RoomsCachePath(const char* accountName)
|
||||||
BPath path(AccountCachePath(accountName));
|
BPath path(AccountCachePath(accountName));
|
||||||
if (path.InitCheck() != B_OK)
|
if (path.InitCheck() != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
path.Append("Rooms");
|
path.Append("Rooms");
|
||||||
if (create_directory(path.Path(), 0755) != B_OK)
|
if (create_directory(path.Path(), 0755) != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -189,7 +205,9 @@ const char*
|
||||||
RoomCachePath(const char* accountName, const char* roomIdentifier)
|
RoomCachePath(const char* accountName, const char* roomIdentifier)
|
||||||
{
|
{
|
||||||
BPath path(RoomsCachePath(accountName));
|
BPath path(RoomsCachePath(accountName));
|
||||||
if (path.InitCheck() != B_OK) return NULL;
|
if (path.InitCheck() != B_OK)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
path.Append(roomIdentifier);
|
path.Append(roomIdentifier);
|
||||||
return path.Path();
|
return path.Path();
|
||||||
}
|
}
|
||||||
|
@ -199,9 +217,12 @@ const char*
|
||||||
UserCachePath(const char* accountName, const char* userIdentifier)
|
UserCachePath(const char* accountName, const char* userIdentifier)
|
||||||
{
|
{
|
||||||
BPath path(AccountCachePath(accountName));
|
BPath path(AccountCachePath(accountName));
|
||||||
if (path.InitCheck() != B_OK) return NULL;
|
if (path.InitCheck() != B_OK)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
path.Append("Users");
|
path.Append("Users");
|
||||||
if (create_directory(path.Path(), 0755) != B_OK) return NULL;
|
if (create_directory(path.Path(), 0755) != B_OK)
|
||||||
|
return NULL;
|
||||||
path.Append(userIdentifier);
|
path.Append(userIdentifier);
|
||||||
return path.Path();
|
return path.Path();
|
||||||
}
|
}
|
||||||
|
@ -211,9 +232,12 @@ const char*
|
||||||
ContactCachePath(const char* accountName, const char* userIdentifier)
|
ContactCachePath(const char* accountName, const char* userIdentifier)
|
||||||
{
|
{
|
||||||
BPath path(AccountCachePath(accountName));
|
BPath path(AccountCachePath(accountName));
|
||||||
if (path.InitCheck() != B_OK) return NULL;
|
if (path.InitCheck() != B_OK)
|
||||||
|
return NULL;
|
||||||
path.Append("Contacts");
|
path.Append("Contacts");
|
||||||
if (create_directory(path.Path(), 0755) != B_OK) return NULL;
|
|
||||||
|
if (create_directory(path.Path(), 0755) != B_OK)
|
||||||
|
return NULL;
|
||||||
path.Append(userIdentifier);
|
path.Append(userIdentifier);
|
||||||
return path.Path();
|
return path.Path();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ BString CommandArgs(BString line);
|
||||||
|
|
||||||
BResources* ChatResources();
|
BResources* ChatResources();
|
||||||
|
|
||||||
|
const char* SettingsPath();
|
||||||
|
|
||||||
const char* AccountsPath();
|
const char* AccountsPath();
|
||||||
const char* AccountPath(const char* signature, const char* subsignature);
|
const char* AccountPath(const char* signature, const char* subsignature);
|
||||||
|
|
||||||
|
|
|
@ -1,230 +1,82 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012, Casalinuovo Dario. All rights reserved.
|
* Copyright 2012, Casalinuovo Dario. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
||||||
|
* All rights reserved. Distributed under the terms of the MIT license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "AppPreferences.h"
|
#include "AppPreferences.h"
|
||||||
#include "Cardie.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include "Utils.h"
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
template<> const char* AppPreferences::fFolder = APP_NAME;
|
|
||||||
template<> const char* AppPreferences::fFilename = "preferences";
|
|
||||||
|
|
||||||
/* TODO update _Add* methods to
|
AppPreferences* AppPreferences::fInstance = NULL;
|
||||||
don't take the BPositionIO argument
|
|
||||||
and to automatically increase
|
|
||||||
length counters. For example
|
|
||||||
the _AddBool() method, should
|
|
||||||
take the BPositionIO argument from
|
|
||||||
a private class value, and increase
|
|
||||||
the the size of another class value
|
|
||||||
respectively. This way the api looks better
|
|
||||||
and the possibility of bugs related to
|
|
||||||
size become very minimal : ).
|
|
||||||
*/
|
|
||||||
|
|
||||||
AppPreferencesData::AppPreferencesData()
|
|
||||||
:
|
AppPreferences*
|
||||||
MoveToCurrentWorkspace(true),
|
AppPreferences::Get()
|
||||||
RaiseOnMessageReceived(false),
|
|
||||||
RaiseUserIsTyping(false),
|
|
||||||
MarkUnreadWindow(true),
|
|
||||||
HideDeskbar(false),
|
|
||||||
DisableReplicant(true),
|
|
||||||
IgnoreEmoticons(true),
|
|
||||||
NotifyProtocolStatus(true),
|
|
||||||
NotifyContactStatus(false),
|
|
||||||
NotifyNewMessage(true),
|
|
||||||
HideOffline(true),
|
|
||||||
DisableQuitConfirm(true)
|
|
||||||
{
|
{
|
||||||
}
|
if (fInstance == NULL) {
|
||||||
|
fInstance = new AppPreferences();
|
||||||
|
fInstance->Load();
|
||||||
AppPreferencesData::~AppPreferencesData()
|
}
|
||||||
{
|
return fInstance;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
AppPreferencesData::IsFixedSize() const
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type_code
|
|
||||||
AppPreferencesData::TypeCode() const
|
|
||||||
{
|
|
||||||
return APP_PREFERENCES_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
AppPreferencesData::AllowsTypeCode(type_code code) const
|
|
||||||
{
|
|
||||||
if (code == APP_PREFERENCES_TYPE)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
|
||||||
AppPreferencesData::FlattenedSize() const
|
|
||||||
{
|
|
||||||
// NOTE add the size of every settings
|
|
||||||
// you added.
|
|
||||||
|
|
||||||
ssize_t size = sizeof(bool) * 11;
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
AppPreferencesData::Flatten(BPositionIO* flatData) const
|
|
||||||
{
|
|
||||||
if (flatData == NULL)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
// Write our type code
|
|
||||||
type_code code = APP_PREFERENCES_TYPE;
|
|
||||||
flatData->Write(&code, sizeof(type_code));
|
|
||||||
|
|
||||||
// Behaviour
|
|
||||||
_AddBool(flatData, MoveToCurrentWorkspace);
|
|
||||||
_AddBool(flatData, RaiseOnMessageReceived);
|
|
||||||
_AddBool(flatData, RaiseUserIsTyping);
|
|
||||||
_AddBool(flatData, MarkUnreadWindow);
|
|
||||||
|
|
||||||
_AddBool(flatData, NotifyProtocolStatus);
|
|
||||||
_AddBool(flatData, NotifyContactStatus);
|
|
||||||
_AddBool(flatData, NotifyNewMessage);
|
|
||||||
_AddBool(flatData, DisableQuitConfirm);
|
|
||||||
|
|
||||||
// Replicant
|
|
||||||
_AddBool(flatData, HideDeskbar);
|
|
||||||
_AddBool(flatData, DisableReplicant);
|
|
||||||
|
|
||||||
// Chat window
|
|
||||||
_AddBool(flatData, IgnoreEmoticons);
|
|
||||||
|
|
||||||
// Contact list
|
|
||||||
_AddBool(flatData, HideOffline);
|
|
||||||
|
|
||||||
// Usage example for strings :
|
|
||||||
// _AddString(flatData, yourBString.String());
|
|
||||||
|
|
||||||
// NOTE : The order is very important, Unflatten and Flatten
|
|
||||||
// classes should read/write the values in the same order.
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
AppPreferencesData::Flatten(void* buffer, ssize_t size) const
|
|
||||||
{
|
|
||||||
if (buffer == NULL)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
BMemoryIO flatData(buffer, size);
|
|
||||||
return Flatten(&flatData, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
AppPreferencesData::Unflatten(type_code code, const void* buffer, ssize_t size)
|
|
||||||
{
|
|
||||||
if (buffer == NULL)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
BMemoryIO flatData(buffer, size);
|
|
||||||
return Unflatten(code, &flatData);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
AppPreferencesData::Unflatten(type_code code, BPositionIO* flatData)
|
|
||||||
{
|
|
||||||
if (code != APP_PREFERENCES_TYPE || flatData == NULL)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
// Reading our type code
|
|
||||||
type_code typeCode;
|
|
||||||
flatData->Read(&typeCode, sizeof(type_code));
|
|
||||||
|
|
||||||
// checking if the typecode is correct
|
|
||||||
if (code != typeCode)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
// Behaviour
|
|
||||||
MoveToCurrentWorkspace = _ReadBool(flatData);
|
|
||||||
RaiseOnMessageReceived = _ReadBool(flatData);
|
|
||||||
RaiseUserIsTyping = _ReadBool(flatData);
|
|
||||||
MarkUnreadWindow = _ReadBool(flatData);
|
|
||||||
|
|
||||||
NotifyProtocolStatus = _ReadBool(flatData);
|
|
||||||
NotifyContactStatus = _ReadBool(flatData);
|
|
||||||
NotifyNewMessage = _ReadBool(flatData);
|
|
||||||
DisableQuitConfirm = _ReadBool(flatData);
|
|
||||||
|
|
||||||
// Replicant
|
|
||||||
HideDeskbar = _ReadBool(flatData);
|
|
||||||
DisableReplicant = _ReadBool(flatData);
|
|
||||||
|
|
||||||
// Chat window
|
|
||||||
IgnoreEmoticons = _ReadBool(flatData);
|
|
||||||
|
|
||||||
// Contact list
|
|
||||||
HideOffline = _ReadBool(flatData);
|
|
||||||
|
|
||||||
// Usage example for strings :
|
|
||||||
// const char* str = _ReadString(flatData);
|
|
||||||
// yourBString.SetTo(str);
|
|
||||||
|
|
||||||
// NOTE : The order is very important, Unflatten and Flatten
|
|
||||||
// classes should read/write the values in the same order.
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AppPreferencesData::_AddBool(BPositionIO* data, bool value) const
|
AppPreferences::Load()
|
||||||
{
|
{
|
||||||
data->Write(&value, sizeof(value));
|
const char* path = _PreferencesPath();
|
||||||
|
BFile file(_PreferencesPath(), B_READ_ONLY);
|
||||||
|
BMessage settings;
|
||||||
|
|
||||||
|
if (file.InitCheck() == B_OK)
|
||||||
|
settings.Unflatten(&file);
|
||||||
|
|
||||||
|
MoveToCurrentWorkspace = settings.GetBool("MoveToCurrentWorkpace", false);
|
||||||
|
RaiseOnMessageReceived = settings.GetBool("RaiseOnMessageReceived", false);
|
||||||
|
RaiseUserIsTyping = settings.GetBool("RaiseUserIsTyping", false);
|
||||||
|
MarkUnreadWindow = settings.GetBool("MarkUnreadWindow", true);
|
||||||
|
NotifyProtocolStatus = settings.GetBool("NotifyProtocolStatus", true);
|
||||||
|
NotifyNewMessage = settings.GetBool("NotifyNewMessage", true);
|
||||||
|
NotifyContactStatus = settings.GetBool("NotifyContactStatus", false);
|
||||||
|
HideDeskbar = settings.GetBool("HideDeskbar", false);
|
||||||
|
DisableReplicant = settings.GetBool("DisableReplicant", true);
|
||||||
|
DisableQuitConfirm = settings.GetBool("DisableQuitConfirm", false);
|
||||||
|
IgnoreEmoticons = settings.GetBool("IgnoreEmoticons", true);
|
||||||
|
HideOffline = settings.GetBool("HideOffline", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AppPreferencesData::_AddString(BPositionIO* data, const char* value) const
|
AppPreferences::Save()
|
||||||
{
|
{
|
||||||
size_t len = strlen(value);
|
const char* path = _PreferencesPath();
|
||||||
data->Write(&len, sizeof(size_t));
|
BFile file(_PreferencesPath(), B_WRITE_ONLY);
|
||||||
data->Write(value, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
BMessage settings;
|
||||||
|
settings.AddBool("MoveToCurrentWorkpace", MoveToCurrentWorkspace);
|
||||||
|
settings.AddBool("RaiseOnMessageReceived", RaiseOnMessageReceived);
|
||||||
|
settings.AddBool("RaiseUserIsTyping", RaiseUserIsTyping);
|
||||||
|
settings.AddBool("MarkUnreadWindow", MarkUnreadWindow);
|
||||||
|
settings.AddBool("NotifyProtocolStatus", NotifyProtocolStatus);
|
||||||
|
settings.AddBool("NotifyNewMessage", NotifyNewMessage);
|
||||||
|
settings.AddBool("NotifyContactStatus", NotifyContactStatus);
|
||||||
|
settings.AddBool("HideDeskbar", HideDeskbar);
|
||||||
|
settings.AddBool("DisableReplicant", DisableReplicant);
|
||||||
|
settings.AddBool("DisableQuitConfirm", DisableQuitConfirm);
|
||||||
|
settings.AddBool("IgnoreEmoticons", IgnoreEmoticons);
|
||||||
|
settings.AddBool("HideOffline", HideOffline);
|
||||||
|
|
||||||
bool
|
if (file.InitCheck() == B_OK)
|
||||||
AppPreferencesData::_ReadBool(BPositionIO* data)
|
settings.Flatten(&file);
|
||||||
{
|
|
||||||
bool ret;
|
|
||||||
data->Read(&ret, sizeof(bool));
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
AppPreferencesData::_ReadString(BPositionIO* data)
|
AppPreferences::_PreferencesPath()
|
||||||
{
|
{
|
||||||
size_t len;
|
BPath path(SettingsPath());
|
||||||
data->Read(&len, sizeof(size_t));
|
path.Append("preferences");
|
||||||
char* ret = new char[len];
|
return path.Path();
|
||||||
data->Read(ret, len);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +1,42 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2010, Oliver Ruiz Dorantes. All rights reserved.
|
* Copyright 2010, Oliver Ruiz Dorantes. All rights reserved.
|
||||||
* Copyright 2012, Casalinuovo Dario. All rights reserved.
|
* Copyright 2012, Casalinuovo Dario. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
||||||
|
* All rights reserved. Distributed under the terms of the MIT license.
|
||||||
*/
|
*/
|
||||||
#ifndef _APP_PREFERENCES_H
|
#ifndef _APP_PREFERENCES_H
|
||||||
#define _APP_PREFERENCES_H
|
#define _APP_PREFERENCES_H
|
||||||
|
|
||||||
#include "PreferencesContainer.h"
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
class AppPreferencesData : public BFlattenable {
|
class AppPreferences {
|
||||||
public:
|
public:
|
||||||
AppPreferencesData();
|
static AppPreferences* Get();
|
||||||
virtual ~AppPreferencesData();
|
|
||||||
|
|
||||||
virtual bool IsFixedSize() const;
|
void Load();
|
||||||
virtual type_code TypeCode() const;
|
void Save();
|
||||||
virtual bool AllowsTypeCode(type_code code) const;
|
|
||||||
virtual ssize_t FlattenedSize() const;
|
|
||||||
|
|
||||||
status_t Flatten(BPositionIO* flatData) const;
|
bool MoveToCurrentWorkspace;
|
||||||
virtual status_t Flatten(void* buffer, ssize_t size) const;
|
bool RaiseOnMessageReceived;
|
||||||
virtual status_t Unflatten(type_code code, const void* buffer,
|
bool RaiseUserIsTyping;
|
||||||
ssize_t size);
|
bool MarkUnreadWindow;
|
||||||
status_t Unflatten(type_code code, BPositionIO* flatData);
|
bool NotifyProtocolStatus;
|
||||||
|
bool NotifyContactStatus;
|
||||||
|
bool NotifyNewMessage;
|
||||||
|
|
||||||
bool MoveToCurrentWorkspace;
|
bool HideDeskbar;
|
||||||
bool RaiseOnMessageReceived;
|
bool DisableReplicant;
|
||||||
bool RaiseUserIsTyping;
|
bool DisableQuitConfirm;
|
||||||
bool MarkUnreadWindow;
|
|
||||||
bool NotifyProtocolStatus;
|
|
||||||
bool NotifyContactStatus;
|
|
||||||
bool NotifyNewMessage;
|
|
||||||
|
|
||||||
bool HideDeskbar;
|
bool IgnoreEmoticons;
|
||||||
bool DisableReplicant;
|
|
||||||
bool DisableQuitConfirm;
|
|
||||||
|
|
||||||
bool IgnoreEmoticons;
|
bool HideOffline;
|
||||||
|
|
||||||
bool HideOffline;
|
|
||||||
private:
|
private:
|
||||||
void _AddBool(BPositionIO* data, bool value) const;
|
const char* _PreferencesPath();
|
||||||
void _AddString(BPositionIO* data,
|
|
||||||
const char* value) const;
|
|
||||||
|
|
||||||
bool _ReadBool(BPositionIO* data);
|
static AppPreferences* fInstance;
|
||||||
const char* _ReadString(BPositionIO* data);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef PreferencesContainer<AppPreferencesData> AppPreferences;
|
#endif // _APP_PREFERENCES_H
|
||||||
|
|
||||||
#endif // _APP_PREFERENCES_H
|
|
||||||
|
|
|
@ -138,23 +138,23 @@ PreferencesBehavior::AttachedToWindow()
|
||||||
fDisableQuitConfirm->SetTarget(this);
|
fDisableQuitConfirm->SetTarget(this);
|
||||||
|
|
||||||
fHideOffline->SetValue(
|
fHideOffline->SetValue(
|
||||||
AppPreferences::Item()->HideOffline);
|
AppPreferences::Get()->HideOffline);
|
||||||
fToCurrentWorkspace->SetValue(
|
fToCurrentWorkspace->SetValue(
|
||||||
AppPreferences::Item()->MoveToCurrentWorkspace);
|
AppPreferences::Get()->MoveToCurrentWorkspace);
|
||||||
fRaiseUserIsTyping->SetValue(
|
fRaiseUserIsTyping->SetValue(
|
||||||
AppPreferences::Item()->RaiseUserIsTyping);
|
AppPreferences::Get()->RaiseUserIsTyping);
|
||||||
fRaiseOnMessageReceived->SetValue(
|
fRaiseOnMessageReceived->SetValue(
|
||||||
AppPreferences::Item()->RaiseOnMessageReceived);
|
AppPreferences::Get()->RaiseOnMessageReceived);
|
||||||
fMarkUnreadWindow->SetValue(
|
fMarkUnreadWindow->SetValue(
|
||||||
AppPreferences::Item()->MarkUnreadWindow);
|
AppPreferences::Get()->MarkUnreadWindow);
|
||||||
fNotifyProtocols->SetValue(
|
fNotifyProtocols->SetValue(
|
||||||
AppPreferences::Item()->NotifyProtocolStatus);
|
AppPreferences::Get()->NotifyProtocolStatus);
|
||||||
fNotifyContactStatus->SetValue(
|
fNotifyContactStatus->SetValue(
|
||||||
AppPreferences::Item()->NotifyContactStatus);
|
AppPreferences::Get()->NotifyContactStatus);
|
||||||
fNotifyNewMessage->SetValue(
|
fNotifyNewMessage->SetValue(
|
||||||
AppPreferences::Item()->NotifyNewMessage);
|
AppPreferences::Get()->NotifyNewMessage);
|
||||||
fDisableQuitConfirm->SetValue(
|
fDisableQuitConfirm->SetValue(
|
||||||
AppPreferences::Item()->DisableQuitConfirm);
|
AppPreferences::Get()->DisableQuitConfirm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,39 +163,39 @@ PreferencesBehavior::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kHideOffline:
|
case kHideOffline:
|
||||||
AppPreferences::Item()->HideOffline
|
AppPreferences::Get()->HideOffline
|
||||||
= fHideOffline->Value();
|
= fHideOffline->Value();
|
||||||
break;
|
break;
|
||||||
case kToCurrentWorkspace:
|
case kToCurrentWorkspace:
|
||||||
AppPreferences::Item()->MoveToCurrentWorkspace
|
AppPreferences::Get()->MoveToCurrentWorkspace
|
||||||
= fToCurrentWorkspace->Value();
|
= fToCurrentWorkspace->Value();
|
||||||
break;
|
break;
|
||||||
case kRaiseOnMessageReceived:
|
case kRaiseOnMessageReceived:
|
||||||
AppPreferences::Item()->RaiseOnMessageReceived
|
AppPreferences::Get()->RaiseOnMessageReceived
|
||||||
= fRaiseOnMessageReceived->Value();
|
= fRaiseOnMessageReceived->Value();
|
||||||
break;
|
break;
|
||||||
case kRaiseUserIsTyping:
|
case kRaiseUserIsTyping:
|
||||||
AppPreferences::Item()->RaiseUserIsTyping
|
AppPreferences::Get()->RaiseUserIsTyping
|
||||||
= fRaiseUserIsTyping->Value();
|
= fRaiseUserIsTyping->Value();
|
||||||
break;
|
break;
|
||||||
case kNotifyProtocolsLogin:
|
case kNotifyProtocolsLogin:
|
||||||
AppPreferences::Item()->NotifyProtocolStatus
|
AppPreferences::Get()->NotifyProtocolStatus
|
||||||
= fNotifyProtocols->Value();
|
= fNotifyProtocols->Value();
|
||||||
break;
|
break;
|
||||||
case kNotifyContactStatus:
|
case kNotifyContactStatus:
|
||||||
AppPreferences::Item()->NotifyContactStatus
|
AppPreferences::Get()->NotifyContactStatus
|
||||||
= fNotifyContactStatus->Value();
|
= fNotifyContactStatus->Value();
|
||||||
break;
|
break;
|
||||||
case kNotifyNewMessage:
|
case kNotifyNewMessage:
|
||||||
AppPreferences::Item()->NotifyNewMessage
|
AppPreferences::Get()->NotifyNewMessage
|
||||||
= fNotifyNewMessage->Value();
|
= fNotifyNewMessage->Value();
|
||||||
break;
|
break;
|
||||||
case kMarkUnreadWindow:
|
case kMarkUnreadWindow:
|
||||||
AppPreferences::Item()->MarkUnreadWindow
|
AppPreferences::Get()->MarkUnreadWindow
|
||||||
= fMarkUnreadWindow->Value();
|
= fMarkUnreadWindow->Value();
|
||||||
break;
|
break;
|
||||||
case kDisablePrompt:
|
case kDisablePrompt:
|
||||||
AppPreferences::Item()->DisableQuitConfirm
|
AppPreferences::Get()->DisableQuitConfirm
|
||||||
= fDisableQuitConfirm->Value();
|
= fDisableQuitConfirm->Value();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -53,7 +53,7 @@ void
|
||||||
PreferencesChatWindow::AttachedToWindow()
|
PreferencesChatWindow::AttachedToWindow()
|
||||||
{
|
{
|
||||||
fIgnoreEmoticons->SetTarget(this);
|
fIgnoreEmoticons->SetTarget(this);
|
||||||
fIgnoreEmoticons->SetValue(AppPreferences::Item()->IgnoreEmoticons);
|
fIgnoreEmoticons->SetValue(AppPreferences::Get()->IgnoreEmoticons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ PreferencesChatWindow::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kIgnoreEmoticons:
|
case kIgnoreEmoticons:
|
||||||
AppPreferences::Item()->IgnoreEmoticons
|
AppPreferences::Get()->IgnoreEmoticons
|
||||||
= fIgnoreEmoticons->Value();
|
= fIgnoreEmoticons->Value();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2010, Oliver Ruiz Dorantes. All rights reserved.
|
|
||||||
* Copyright 2012, Casalinuovo Dario. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*/
|
|
||||||
#ifndef _PREFERENCES_CONTAINER_H
|
|
||||||
#define _PREFERENCES_CONTAINER_H
|
|
||||||
|
|
||||||
#include <libsupport/Singleton.h>
|
|
||||||
|
|
||||||
#include <Directory.h>
|
|
||||||
#include <File.h>
|
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <Path.h>
|
|
||||||
|
|
||||||
enum {
|
|
||||||
APP_PREFERENCES_TYPE = 'CPTY'
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: added to main singleton class?
|
|
||||||
template<typename T> T* Singleton<T>::fInstance = 0;
|
|
||||||
|
|
||||||
|
|
||||||
template<class AppPreferencesData>
|
|
||||||
class PreferencesContainer
|
|
||||||
: public Singleton<PreferencesContainer<AppPreferencesData> > {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
static AppPreferencesData*
|
|
||||||
Item()
|
|
||||||
{
|
|
||||||
return &(Singleton<PreferencesContainer<AppPreferencesData> >
|
|
||||||
::Get()->fSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t Load()
|
|
||||||
{
|
|
||||||
if (fPreferencesFile.SetTo(&fDirectory, fFilename,
|
|
||||||
B_READ_WRITE | B_FAIL_IF_EXISTS) == B_OK) {
|
|
||||||
|
|
||||||
return fSettings.Unflatten(APP_PREFERENCES_TYPE,
|
|
||||||
&fPreferencesFile);
|
|
||||||
}
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t Save()
|
|
||||||
{
|
|
||||||
if (fPreferencesFile.SetTo(&fDirectory, fFilename,
|
|
||||||
B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE) == B_OK) {
|
|
||||||
|
|
||||||
return fSettings.Flatten(&fPreferencesFile);
|
|
||||||
}
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
PreferencesContainer<AppPreferencesData>()
|
|
||||||
: Singleton<PreferencesContainer<AppPreferencesData> >()
|
|
||||||
{
|
|
||||||
BPath path;
|
|
||||||
|
|
||||||
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
|
||||||
path.Append(fFolder);
|
|
||||||
fDirectory.SetTo(path.Path());
|
|
||||||
|
|
||||||
Load();
|
|
||||||
}
|
|
||||||
|
|
||||||
AppPreferencesData fSettings;
|
|
||||||
BFile fPreferencesFile;
|
|
||||||
BDirectory fDirectory;
|
|
||||||
|
|
||||||
static const char* fFilename;
|
|
||||||
static const char* fFolder;
|
|
||||||
|
|
||||||
friend class Singleton<PreferencesContainer<AppPreferencesData> >;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _PREFERENCES_CONTAINER_H
|
|
|
@ -36,7 +36,7 @@ PreferencesReplicant::PreferencesReplicant()
|
||||||
B_TRANSLATE("Disable deskbar replicant"),
|
B_TRANSLATE("Disable deskbar replicant"),
|
||||||
new BMessage(kDisableReplicant));
|
new BMessage(kDisableReplicant));
|
||||||
|
|
||||||
if (!AppPreferences::Item()->HideDeskbar)
|
if (!AppPreferences::Get()->HideDeskbar)
|
||||||
Looper()->PostMessage(new BMessage(kDisableReplicant));
|
Looper()->PostMessage(new BMessage(kDisableReplicant));
|
||||||
|
|
||||||
fPermanentReplicant = new BCheckBox("PermanentReplicant",
|
fPermanentReplicant = new BCheckBox("PermanentReplicant",
|
||||||
|
@ -72,9 +72,9 @@ PreferencesReplicant::AttachedToWindow()
|
||||||
fDisableReplicant->SetTarget(this);
|
fDisableReplicant->SetTarget(this);
|
||||||
|
|
||||||
fHideDeskbar->SetValue(
|
fHideDeskbar->SetValue(
|
||||||
AppPreferences::Item()->HideDeskbar);
|
AppPreferences::Get()->HideDeskbar);
|
||||||
fDisableReplicant->SetValue(
|
fDisableReplicant->SetValue(
|
||||||
AppPreferences::Item()->DisableReplicant);
|
AppPreferences::Get()->DisableReplicant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,11 +83,11 @@ PreferencesReplicant::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kHideDeskbar:
|
case kHideDeskbar:
|
||||||
AppPreferences::Item()->HideDeskbar
|
AppPreferences::Get()->HideDeskbar
|
||||||
= fHideDeskbar->Value();
|
= fHideDeskbar->Value();
|
||||||
break;
|
break;
|
||||||
case kDisableReplicant:
|
case kDisableReplicant:
|
||||||
AppPreferences::Item()->DisableReplicant
|
AppPreferences::Get()->DisableReplicant
|
||||||
= fDisableReplicant->Value();
|
= fDisableReplicant->Value();
|
||||||
|
|
||||||
if (fDisableReplicant->Value() == true)
|
if (fDisableReplicant->Value() == true)
|
||||||
|
|
|
@ -361,7 +361,7 @@ instantiate_deskbar_item(void)
|
||||||
status_t
|
status_t
|
||||||
ReplicantStatusView::InstallReplicant()
|
ReplicantStatusView::InstallReplicant()
|
||||||
{
|
{
|
||||||
if (AppPreferences::Item()->DisableReplicant == true)
|
if (AppPreferences::Get()->DisableReplicant == true)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
BDeskbar deskbar;
|
BDeskbar deskbar;
|
||||||
|
|
|
@ -149,7 +149,7 @@ RosterView::ImMessage(BMessage* msg)
|
||||||
UpdateListItem(rosterItem);
|
UpdateListItem(rosterItem);
|
||||||
|
|
||||||
// Check if the user want the notification
|
// Check if the user want the notification
|
||||||
if (!AppPreferences::Item()->NotifyContactStatus)
|
if (!AppPreferences::Get()->NotifyContactStatus)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
|
|
|
@ -80,7 +80,7 @@ bool
|
||||||
MainWindow::QuitRequested()
|
MainWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
int32 button_index = 0;
|
int32 button_index = 0;
|
||||||
if(!AppPreferences::Item()->DisableQuitConfirm)
|
if(!AppPreferences::Get()->DisableQuitConfirm)
|
||||||
{
|
{
|
||||||
BAlert* alert = new BAlert(B_TRANSLATE("Closing"),
|
BAlert* alert = new BAlert(B_TRANSLATE("Closing"),
|
||||||
B_TRANSLATE("Are you sure you want to quit?"),
|
B_TRANSLATE("Are you sure you want to quit?"),
|
||||||
|
|
Ŝarĝante…
Reference in New Issue