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

121 lines
3.2 KiB
C++
Raw Permalink 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>
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 kMarkUnreadWindow = 'MKuw';
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));
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));
fMarkUnreadWindow = new BCheckBox("MarkUnreadWindow",
2021-07-19 09:54:27 -05:00
B_TRANSLATE("Mark unread window chat"),
new BMessage(kMarkUnreadWindow));
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(fToCurrentWorkspace)
.Add(fRaiseOnMessageReceived)
.Add(fMarkUnreadWindow)
.End();
BLayoutBuilder::Group<>(this, B_VERTICAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.Add(generalBox)
.Add(incomingBox)
2010-05-19 17:06:25 -05:00
.AddGlue()
.End();
}
void
PreferencesBehavior::AttachedToWindow()
{
fToCurrentWorkspace->SetTarget(this);
fRaiseOnMessageReceived->SetTarget(this);
fMarkUnreadWindow->SetTarget(this);
fDisableQuitConfirm->SetTarget(this);
fToCurrentWorkspace->SetValue(
2021-07-28 19:10:09 -05:00
AppPreferences::Get()->MoveToCurrentWorkspace);
fRaiseOnMessageReceived->SetValue(
2021-07-28 19:10:09 -05:00
AppPreferences::Get()->RaiseOnMessageReceived);
fMarkUnreadWindow->SetValue(
2021-07-28 19:10:09 -05:00
AppPreferences::Get()->MarkUnreadWindow);
fDisableQuitConfirm->SetValue(
2021-07-28 19:10:09 -05:00
AppPreferences::Get()->DisableQuitConfirm);
}
void
PreferencesBehavior::MessageReceived(BMessage* message)
{
switch (message->what) {
case kToCurrentWorkspace:
2021-07-28 19:10:09 -05:00
AppPreferences::Get()->MoveToCurrentWorkspace
= fToCurrentWorkspace->Value();
break;
case kRaiseOnMessageReceived:
2021-07-28 19:10:09 -05:00
AppPreferences::Get()->RaiseOnMessageReceived
= fRaiseOnMessageReceived->Value();
break;
case kMarkUnreadWindow:
2021-07-28 19:10:09 -05:00
AppPreferences::Get()->MarkUnreadWindow
= fMarkUnreadWindow->Value();
break;
case kDisablePrompt:
2021-07-28 19:10:09 -05:00
AppPreferences::Get()->DisableQuitConfirm
= fDisableQuitConfirm->Value();
break;
default:
BView::MessageReceived(message);
}
}