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

205 lines
6.1 KiB
C++
Raw Normal View History

/*
* Copyright 2010, Oliver Ruiz Dorantes. All rights reserved.
* Copyright 2012, Dario Casalinuovo. All rights reserved.
* Copyright 2021, Jaidyn Levesque. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "PreferencesBehavior.h"
#include <Box.h>
2021-07-19 09:54:27 -05:00
#include <Catalog.h>
#include <CheckBox.h>
#include <ControlLook.h>
#include <LayoutBuilder.h>
#include "AccountManager.h"
2021-06-20 12:44:20 -05:00
#include "AppPreferences.h"
2021-07-19 09:54:27 -05:00
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "PreferencesBehavior"
const uint32 kToCurrentWorkspace = 'CBcw';
const uint32 kRaiseOnMessageReceived = 'FCmr';
const uint32 kRaiseUserIsTyping = 'FCit';
const uint32 kNotifyProtocolsLogin = 'NTpl';
const uint32 kNotifyContactStatus = 'NTcl';
const uint32 kNotifyNewMessage = 'NTms';
const uint32 kMarkUnreadWindow = 'MKuw';
const uint32 kHideOffline = 'HiOf';
const uint32 kDisablePrompt = 'DiPr';
PreferencesBehavior::PreferencesBehavior()
2021-07-19 09:54:27 -05:00
: BView(B_TRANSLATE("Behavior"), B_WILL_DRAW)
{
BBox* incomingBox = new BBox("incoming");
incomingBox->SetLabel(B_TRANSLATE("On incoming" B_UTF8_ELLIPSIS));
fHideOffline = new BCheckBox("HideOfflineContacts",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Hide offline contacts"),
new BMessage(kHideOffline));
fToCurrentWorkspace = new BCheckBox("ToCurrentWorkspace",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Move window to current workspace"),
new BMessage(kToCurrentWorkspace));
fRaiseOnMessageReceived = new BCheckBox("FocusOnMessageReceived",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Auto-raise when a message is received"),
new BMessage(kRaiseOnMessageReceived));
fRaiseUserIsTyping = new BCheckBox("FocusUserIsTyping",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Auto-raise when user is typing"),
new BMessage(kRaiseUserIsTyping));
fPlaySoundOnMessageReceived = new BCheckBox("PlaySoundOnMessageReceived",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Play sound event"), NULL);
fPlaySoundOnMessageReceived->SetEnabled(false); // not implemented
fMarkUnreadWindow = new BCheckBox("MarkUnreadWindow",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Mark unread window chat"),
new BMessage(kMarkUnreadWindow));
/*fMarkUnreadWindow->SetEnabled(false); implementing it right now*/
fMarkUnreadReplicant = new BCheckBox("MarkUnreadReplicant",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Mark unread the Deskbar Replicant"), NULL);
fMarkUnreadReplicant->SetEnabled(false);
2010-05-30 17:00:09 -05:00
// not implemented
BBox* notificationBox = new BBox("notificationBox");
notificationBox->SetLabel(B_TRANSLATE("Deskbar notifications"));
fNotifyProtocols = new BCheckBox("EnableProtocolNotify",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Enable protocol status notifications"),
new BMessage(kNotifyProtocolsLogin));
fNotifyContactStatus = new BCheckBox("EnableContactNotify",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Enable contact status notifications"),
new BMessage(kNotifyContactStatus));
fNotifyNewMessage = new BCheckBox("EnableMessageNotify",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Enable message notifications"),
new BMessage(kNotifyNewMessage));
BBox* generalBox = new BBox("general");
generalBox->SetLabel(B_TRANSLATE("General"));
fDisableQuitConfirm = new BCheckBox("DisableQuitConfirm",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Don't ask confirmation at Quit"),
new BMessage(kDisablePrompt));
const float spacing = be_control_look->DefaultItemSpacing();
BLayoutBuilder::Group<>(generalBox, B_VERTICAL)
.SetInsets(spacing, spacing * 2, spacing, spacing)
.Add(fDisableQuitConfirm)
.End();
BLayoutBuilder::Group<>(incomingBox, B_VERTICAL)
.SetInsets(spacing, spacing * 2, spacing, spacing)
.Add(fHideOffline)
.Add(fToCurrentWorkspace)
.Add(fRaiseOnMessageReceived)
.Add(fRaiseUserIsTyping)
.Add(fMarkUnreadWindow)
.Add(fMarkUnreadReplicant)
.Add(fPlaySoundOnMessageReceived)
.End();
BLayoutBuilder::Group<>(notificationBox, B_VERTICAL)
.SetInsets(spacing, spacing * 2, spacing, spacing)
.Add(fNotifyProtocols)
.Add(fNotifyContactStatus)
.Add(fNotifyNewMessage)
.End();
BLayoutBuilder::Group<>(this, B_VERTICAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.Add(generalBox)
.Add(incomingBox)
.Add(notificationBox)
2010-05-19 17:06:25 -05:00
.AddGlue()
.End();
}
void
PreferencesBehavior::AttachedToWindow()
{
fHideOffline->SetTarget(this);
fToCurrentWorkspace->SetTarget(this);
fRaiseUserIsTyping->SetTarget(this);
fRaiseOnMessageReceived->SetTarget(this);
fNotifyProtocols->SetTarget(this);
fNotifyContactStatus->SetTarget(this);
fNotifyNewMessage->SetTarget(this);
fDisableQuitConfirm->SetTarget(this);
fHideOffline->SetValue(
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->HideOffline);
fToCurrentWorkspace->SetValue(
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->MoveToCurrentWorkspace);
fRaiseUserIsTyping->SetValue(
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->RaiseUserIsTyping);
fRaiseOnMessageReceived->SetValue(
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->RaiseOnMessageReceived);
fMarkUnreadWindow->SetValue(
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->MarkUnreadWindow);
fNotifyProtocols->SetValue(
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->NotifyProtocolStatus);
fNotifyContactStatus->SetValue(
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->NotifyContactStatus);
fNotifyNewMessage->SetValue(
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->NotifyNewMessage);
fDisableQuitConfirm->SetValue(
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->DisableQuitConfirm);
}
void
PreferencesBehavior::MessageReceived(BMessage* message)
{
switch (message->what) {
case kHideOffline:
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->HideOffline
= fHideOffline->Value();
break;
case kToCurrentWorkspace:
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->MoveToCurrentWorkspace
= fToCurrentWorkspace->Value();
break;
case kRaiseOnMessageReceived:
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->RaiseOnMessageReceived
= fRaiseOnMessageReceived->Value();
break;
case kRaiseUserIsTyping:
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->RaiseUserIsTyping
= fRaiseUserIsTyping->Value();
break;
case kNotifyProtocolsLogin:
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->NotifyProtocolStatus
= fNotifyProtocols->Value();
break;
case kNotifyContactStatus:
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->NotifyContactStatus
= fNotifyContactStatus->Value();
break;
case kNotifyNewMessage:
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->NotifyNewMessage
= fNotifyNewMessage->Value();
break;
case kMarkUnreadWindow:
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->MarkUnreadWindow
= fMarkUnreadWindow->Value();
break;
case kDisablePrompt:
2021-06-20 12:44:20 -05:00
AppPreferences::Item()->DisableQuitConfirm
= fDisableQuitConfirm->Value();
break;
default:
BView::MessageReceived(message);
}
}