Chat-O-Matic/application/preferences/AppPreferences.cpp

111 lines
3.8 KiB
C++
Raw Permalink Normal View History

/*
* Copyright 2012, Casalinuovo Dario. All rights reserved.
2021-07-28 19:10:09 -05:00
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
2021-07-28 19:10:09 -05:00
#include "AppPreferences.h"
#include <Path.h>
2021-07-28 19:10:09 -05:00
#include "Utils.h"
2021-07-28 19:10:09 -05:00
AppPreferences* AppPreferences::fInstance = NULL;
2021-07-28 19:10:09 -05:00
AppPreferences*
AppPreferences::Get()
{
2021-07-28 19:10:09 -05:00
if (fInstance == NULL) {
fInstance = new AppPreferences();
fInstance->Load();
}
return fInstance;
}
void
2021-07-28 19:10:09 -05:00
AppPreferences::Load()
{
2021-07-28 19:10:09 -05:00
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);
MarkUnreadWindow = settings.GetBool("MarkUnreadWindow", false);
2021-07-28 19:10:09 -05:00
NotifyProtocolStatus = settings.GetBool("NotifyProtocolStatus", true);
NotifyNewMessage = settings.GetBool("NotifyNewMessage", true);
NotifyContactStatus = settings.GetBool("NotifyContactStatus", false);
SoundOnMessageReceived = settings.GetBool("SoundOnMessageReceived", true);
SoundOnMention = settings.GetBool("SoundOnMention", true);
2021-07-28 19:10:09 -05:00
HideDeskbar = settings.GetBool("HideDeskbar", false);
DisableReplicant = settings.GetBool("DisableReplicant", true);
DisableQuitConfirm = settings.GetBool("DisableQuitConfirm", false);
MembershipUpdates = settings.GetBool("MembershipUpdates", true);
2021-07-28 19:10:09 -05:00
IgnoreEmoticons = settings.GetBool("IgnoreEmoticons", true);
HideOffline = settings.GetBool("HideOffline", false);
2021-07-28 19:25:55 -05:00
MainWindowListWeight = settings.GetFloat("MainWindowListWeight", 1);
MainWindowChatWeight = settings.GetFloat("MainWindowChatWeight", 5);
ChatViewHorizChatWeight = settings.GetFloat("ChatViewHorizChatWeight", 8);
ChatViewHorizListWeight = settings.GetFloat("ChatViewHorizListWeight", 1);
ChatViewVertChatWeight = settings.GetFloat("ChatViewVertChatWeight", 20);
ChatViewVertSendWeight = settings.GetFloat("ChatViewVertSendWeight", 1);
2021-07-28 19:25:55 -05:00
MainWindowRect = settings.GetRect("MainWindowRect", BRect(0, 0, 600, 400));
RoomDirectoryRect = settings.GetRect("RoomDirectoryRect", BRect(0, 0, 630, 330));
}
void
2021-07-28 19:10:09 -05:00
AppPreferences::Save()
{
2021-07-28 19:10:09 -05:00
const char* path = _PreferencesPath();
BFile file(_PreferencesPath(), B_WRITE_ONLY | B_CREATE_FILE);
2021-07-28 19:10:09 -05:00
BMessage settings;
settings.AddBool("MoveToCurrentWorkpace", MoveToCurrentWorkspace);
settings.AddBool("RaiseOnMessageReceived", RaiseOnMessageReceived);
settings.AddBool("MarkUnreadWindow", MarkUnreadWindow);
settings.AddBool("NotifyProtocolStatus", NotifyProtocolStatus);
settings.AddBool("NotifyNewMessage", NotifyNewMessage);
settings.AddBool("NotifyContactStatus", NotifyContactStatus);
settings.AddBool("SoundOnMessageReceived", SoundOnMessageReceived);
settings.AddBool("SoundOnMention", SoundOnMention);
2021-07-28 19:10:09 -05:00
settings.AddBool("HideDeskbar", HideDeskbar);
settings.AddBool("DisableReplicant", DisableReplicant);
settings.AddBool("DisableQuitConfirm", DisableQuitConfirm);
settings.AddBool("IgnoreEmoticons", IgnoreEmoticons);
settings.AddBool("MembershipUpdates", MembershipUpdates);
2021-07-28 19:10:09 -05:00
settings.AddBool("HideOffline", HideOffline);
settings.AddFloat("MainWindowListWeight", MainWindowListWeight);
settings.AddFloat("MainWindowChatWeight", MainWindowChatWeight);
settings.AddFloat("ChatViewHorizChatWeight", ChatViewHorizChatWeight);
settings.AddFloat("ChatViewHorizListWeight", ChatViewHorizListWeight);
settings.AddFloat("ChatViewVertChatWeight", ChatViewVertChatWeight);
settings.AddFloat("ChatViewVertSendWeight", ChatViewVertSendWeight);
2021-07-28 19:25:55 -05:00
settings.AddRect("MainWindowRect", MainWindowRect);
settings.AddRect("RoomDirectoryRect", RoomDirectoryRect);
2021-07-28 19:25:55 -05:00
2021-07-28 19:10:09 -05:00
if (file.InitCheck() == B_OK)
settings.Flatten(&file);
}
const char*
2021-07-28 19:10:09 -05:00
AppPreferences::_PreferencesPath()
{
2021-07-28 19:10:09 -05:00
BPath path(SettingsPath());
path.Append("preferences");
return path.Path();
}