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

153 lines
4.5 KiB
C++
Raw Normal View History

/*
* Copyright 2010, Oliver Ruiz Dorantes. All rights reserved.
* Copyright 2012, Dario Casalinuovo. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <Button.h>
#include <CheckBox.h>
#include <ControlLook.h>
#include <Deskbar.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <ScrollView.h>
#include <StringView.h>
#include "AccountManager.h"
#include "CayaProtocol.h"
#include "PreferencesBehavior.h"
#include "CayaPreferences.h"
#include "ProtocolManager.h"
#include "ProtocolSettings.h"
#include "MainWindow.h"
#include "ReplicantStatusView.h"
#include "TheApp.h"
const uint32 kToCurrentWorkspace = 'CBcw';
const uint32 kFocusOnMessageReceived= 'FCmr';
const uint32 kFocusUserIsTyping = 'FCit';
const uint32 kNotifyProtocolsLogin = 'NTpl';
const uint32 kNotifyContactStatus = 'NTcl';
PreferencesBehavior::PreferencesBehavior()
: BView("Behavior", B_WILL_DRAW)
{
2010-05-30 17:02:50 -05:00
fOnIncoming = new BStringView("onIncoming", "On incoming message...");
2010-05-30 17:00:09 -05:00
fOnIncoming->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
fOnIncoming->SetFont(be_bold_font);
fToCurrentWorkspace = new BCheckBox("ToCurrentWorkspace",
"Move window to current workspace",
new BMessage(kToCurrentWorkspace));
fFocusOnMessageReceived = new BCheckBox("FocusOnMessageReceived",
"Get focus when a message is received",
new BMessage(kFocusOnMessageReceived));
fFocusUserIsTyping = new BCheckBox("FocusUserIsTyping",
"Get focus when user is typing",
new BMessage(kFocusUserIsTyping));
fPlaySoundOnMessageReceived = new BCheckBox("PlaySoundOnMessageReceived",
"Play sound event", NULL);
fPlaySoundOnMessageReceived->SetEnabled(false); // not implemented
fMarkUnreadWindow = new BCheckBox("MarkUnreadWindow",
"Mark unread window chat", NULL);
2010-05-30 17:00:09 -05:00
fMarkUnreadWindow->SetEnabled(false);
fMarkUnreadReplicant = new BCheckBox("MarkUnreadReplicant",
"Mark unread the Deskbar Replicant", NULL);
fMarkUnreadReplicant->SetEnabled(false);
2010-05-30 17:00:09 -05:00
// not implemented
fNotifications = new BStringView("notifications", "Deskbar Notifications");
fNotifications->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
fNotifications->SetFont(be_bold_font);
fNotifyProtocols = new BCheckBox("EnableProtocolNotify",
"Enable protocol status notifications",new BMessage(kNotifyProtocolsLogin));
fNotifyContactStatus = new BCheckBox("EnableContactNotify",
"Enable contact status notifications",new BMessage(kNotifyContactStatus));
const float spacing = be_control_look->DefaultItemSpacing();
SetLayout(new BGroupLayout(B_HORIZONTAL, spacing));
AddChild(BGroupLayoutBuilder(B_VERTICAL)
2010-05-30 17:00:09 -05:00
.Add(fOnIncoming)
.AddGroup(B_VERTICAL, spacing)
.Add(fToCurrentWorkspace)
.Add(fFocusOnMessageReceived)
.Add(fFocusUserIsTyping)
.Add(fMarkUnreadWindow)
.Add(fMarkUnreadReplicant)
.Add(fPlaySoundOnMessageReceived)
. SetInsets(spacing * 2, spacing, spacing, spacing)
.End()
.Add(fNotifications)
.AddGroup(B_VERTICAL, spacing)
.Add(fNotifyProtocols)
.Add(fNotifyContactStatus)
. SetInsets(spacing * 2, spacing, spacing, spacing)
.End()
2010-05-19 17:06:25 -05:00
.AddGlue()
.SetInsets(spacing, spacing, spacing, spacing)
.TopView()
);
}
void
PreferencesBehavior::AttachedToWindow()
{
fToCurrentWorkspace->SetTarget(this);
fFocusUserIsTyping->SetTarget(this);
fFocusOnMessageReceived->SetTarget(this);
fNotifyProtocols->SetTarget(this);
fNotifyContactStatus->SetTarget(this);
fToCurrentWorkspace->SetValue(
CayaPreferences::Item()->MoveToCurrentWorkspace);
fFocusUserIsTyping->SetValue(
CayaPreferences::Item()->FocusUserIsTyping);
fFocusOnMessageReceived->SetValue(
CayaPreferences::Item()->FocusOnMessageReceived);
fNotifyProtocols->SetValue(
CayaPreferences::Item()->NotifyProtocolStatus);
fNotifyContactStatus->SetValue(
CayaPreferences::Item()->NotifyContactStatus);
}
void
PreferencesBehavior::MessageReceived(BMessage* message)
{
switch (message->what) {
case kToCurrentWorkspace:
CayaPreferences::Item()->MoveToCurrentWorkspace
= fToCurrentWorkspace->Value();
break;
case kFocusOnMessageReceived:
CayaPreferences::Item()->FocusOnMessageReceived
= fFocusOnMessageReceived->Value();
break;
case kFocusUserIsTyping:
CayaPreferences::Item()->FocusUserIsTyping
= fFocusUserIsTyping->Value();
break;
case kNotifyProtocolsLogin:
CayaPreferences::Item()->NotifyProtocolStatus
= fNotifyProtocols->Value();
break;
case kNotifyContactStatus:
CayaPreferences::Item()->NotifyContactStatus
= fNotifyContactStatus->Value();
break;
default:
BView::MessageReceived(message);
}
}