Add Deskbar clock settings to Time Preferences

* Added a new Clock tab to the Time preflet. Added Clock related
  controls there. They all function by communicating with Deskbar.
* Put controls in a BBox controlled by the Show clock checkbox.
  This more clearly shows that all the clock settings are dependent
  on the show clock setting since it doesn't matter what your clock
  settings are if you don't show the clock.
* Make revert work.
* Split clock settings into it's own file and struct.
* Re-add the time zone setting.
* Remove the clock settings from the Deskbar preference window, they
  are in Time now.
* Make Locale preferences accepts B_LOCALE_CHANGED message, although
  not used.
This commit is contained in:
John Scipione 2012-11-08 00:43:14 -05:00
parent 9a538a294c
commit 31c0024d1b
21 changed files with 573 additions and 142 deletions

View File

@ -51,6 +51,8 @@ All rights reserved.
#include <FindDirectory.h>
#include <Locale.h>
#include <Mime.h>
#include <Message.h>
#include <Messenger.h>
#include <Path.h>
#include <Roster.h>
#include <RosterPrivate.h>
@ -74,9 +76,8 @@ BList TBarApp::sBarTeamInfoList;
BList TBarApp::sSubscribers;
const uint32 kShowDeskbarMenu = 'BeMn';
const uint32 kShowTeamMenu = 'TmMn';
const uint32 kShowDeskbarMenu = 'BeMn';
const uint32 kShowTeamMenu = 'TmMn';
static const color_space kIconColorSpace = B_RGBA32;
@ -95,6 +96,7 @@ main()
TBarApp::TBarApp()
: BApplication(kDeskbarSignature),
fSettingsFile(NULL),
fClockSettingsFile(NULL),
fPreferencesWindow(NULL)
{
InitSettings();
@ -159,8 +161,11 @@ TBarApp::~TBarApp()
= static_cast<BMessenger*>(sSubscribers.ItemAt(i));
delete messenger;
}
SaveSettings();
delete fSettingsFile;
delete fClockSettingsFile;
}
@ -204,9 +209,6 @@ TBarApp::SaveSettings()
storedSettings.AddInt32("state", fSettings.state);
storedSettings.AddFloat("width", fSettings.width);
storedSettings.AddBool("showSeconds", fSettings.showSeconds);
storedSettings.AddBool("showDayOfWeek", fSettings.showDayOfWeek);
storedSettings.AddPoint("switcherLoc", fSettings.switcherLoc);
storedSettings.AddInt32("recentAppsCount", fSettings.recentAppsCount);
storedSettings.AddInt32("recentDocsCount", fSettings.recentDocsCount);
@ -233,6 +235,20 @@ TBarApp::SaveSettings()
storedSettings.Flatten(fSettingsFile);
}
if (fClockSettingsFile->InitCheck() == B_OK) {
fClockSettingsFile->Seek(0, SEEK_SET);
BMessage storedSettings;
storedSettings.AddBool("showSeconds",
fClockSettings.showSeconds);
storedSettings.AddBool("showDayOfWeek",
fClockSettings.showDayOfWeek);
storedSettings.AddBool("showTimeZone",
fClockSettings.showTimeZone);
storedSettings.Flatten(fClockSettingsFile);
}
}
@ -243,8 +259,6 @@ TBarApp::InitSettings()
settings.vertical = true;
settings.left = false;
settings.top = true;
settings.showSeconds = false;
settings.showDayOfWeek = false;
settings.state = kExpandoState;
settings.width = 0;
settings.switcherLoc = BPoint(5000, 5000);
@ -266,13 +280,19 @@ TBarApp::InitSettings()
settings.recentDocsEnabled = true;
settings.recentFoldersEnabled = true;
clock_settings clock;
clock.showSeconds = false;
clock.showDayOfWeek = false;
clock.showTimeZone = false;
BPath dirPath;
const char* settingsFileName = "Deskbar_settings";
const char* clockSettingsFileName = "Deskbar_clock_settings";
find_directory(B_USER_DESKBAR_DIRECTORY, &dirPath, true);
// just make it
if (find_directory (B_USER_SETTINGS_DIRECTORY, &dirPath, true) == B_OK) {
if (find_directory(B_USER_SETTINGS_DIRECTORY, &dirPath, true) == B_OK) {
BPath filePath = dirPath;
filePath.Append(settingsFileName);
fSettingsFile = new BFile(filePath.Path(), O_RDWR);
@ -282,6 +302,13 @@ TBarApp::InitSettings()
theDir.CreateFile(settingsFileName, fSettingsFile);
}
fClockSettingsFile = new BFile(filePath.Path(), O_RDWR);
if (fClockSettingsFile->InitCheck() != B_OK) {
BDirectory theDir(dirPath.Path());
if (theDir.InitCheck() == B_OK)
theDir.CreateFile(clockSettingsFileName, fClockSettingsFile);
}
BMessage storedSettings;
if (fSettingsFile->InitCheck() == B_OK
&& storedSettings.Unflatten(fSettingsFile) == B_OK) {
@ -299,14 +326,6 @@ TBarApp::InitSettings()
}
if (storedSettings.FindFloat("width", &settings.width) != B_OK)
settings.width = 0;
if (storedSettings.FindBool("showSeconds", &settings.showSeconds)
!= B_OK) {
settings.showSeconds = false;
}
if (storedSettings.FindBool("showDayOfWeek", &settings.showDayOfWeek)
!= B_OK) {
settings.showDayOfWeek = false;
}
if (storedSettings.FindPoint("switcherLoc", &settings.switcherLoc)
!= B_OK) {
settings.switcherLoc = BPoint(5000, 5000);
@ -378,9 +397,26 @@ TBarApp::InitSettings()
settings.recentFoldersEnabled = true;
}
}
if (fClockSettingsFile->InitCheck() == B_OK
&& storedSettings.Unflatten(fClockSettingsFile) == B_OK) {
if (storedSettings.FindBool("showSeconds", &clock.showSeconds)
!= B_OK) {
clock.showSeconds = false;
}
if (storedSettings.FindBool("showDayOfWeek",
&clock.showDayOfWeek) != B_OK) {
clock.showDayOfWeek = false;
}
if (storedSettings.FindBool("showTimeZone",
&clock.showTimeZone) != B_OK) {
clock.showDayOfWeek = false;
}
}
}
fSettings = settings;
fClockSettings = clock;
}
@ -626,13 +662,19 @@ TBarApp::MessageReceived(BMessage* message)
bool localize;
if (message->FindBool("filesys", &localize) == B_OK)
gLocalizedNamePreferred = localize;
}
// fall-through
case kShowHideTime:
case kShowSeconds:
case kShowDayOfWeek:
case kShowTimeZone:
case kGetClockSettings:
fStatusViewMessenger.SendMessage(message);
// Notify the replicant tray (through BarView) that the time
// interval has changed and it should update the time view
// and reflow the tray icons.
break;
}
default:
BApplication::MessageReceived(message);

View File

@ -75,8 +75,6 @@ struct desk_settings {
bool vertical;
bool left;
bool top;
bool showSeconds;
bool showDayOfWeek;
uint32 state;
float width;
BPoint switcherLoc;
@ -99,6 +97,12 @@ struct desk_settings {
bool recentFoldersEnabled;
};
struct clock_settings {
bool showSeconds;
bool showDayOfWeek;
bool showTimeZone;
};
class BFile;
class BList;
class BBitmap;
@ -132,6 +136,7 @@ class TBarApp : public BApplication {
virtual void RefsReceived(BMessage* refs);
desk_settings* Settings() { return &fSettings; }
clock_settings* ClockSettings() { return &fClockSettings; }
TBarView* BarView() const { return fBarView; }
TBarWindow* BarWindow() const { return fBarWindow; }
@ -156,7 +161,9 @@ class TBarApp : public BApplication {
BMessenger fSwitcherMessenger;
BMessenger fStatusViewMessenger;
BFile* fSettingsFile;
BFile* fClockSettingsFile;
desk_settings fSettings;
clock_settings fClockSettings;
PreferencesWindow* fPreferencesWindow;

View File

@ -223,6 +223,11 @@ TBarView::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_LOCALE_CHANGED:
case kShowHideTime:
case kShowSeconds:
case kShowDayOfWeek:
case kShowTimeZone:
case kGetClockSettings:
fReplicantTray->MessageReceived(message);
break;

View File

@ -388,13 +388,12 @@ TDeskbarMenu::ResetTargets()
case kRebootSystem:
case kSuspendSystem:
case kShutdownSystem:
item->SetTarget(be_app);
break;
case kShowHideTime:
case kShowSeconds:
case kShowDayOfWeek:
item->SetTarget(fBarView->fReplicantTray);
case kShowTimeZone:
case kGetClockSettings:
item->SetTarget(be_app);
break;
}
}

View File

@ -37,6 +37,8 @@ All rights reserved.
#include "NavMenu.h"
#include "PreferencesWindow.h"
// for message constants
class TBarView;

View File

@ -91,12 +91,6 @@ PreferencesWindow::PreferencesWindow(BRect frame)
fWindowAutoHide = new BCheckBox(B_TRANSLATE("Auto-hide"),
new BMessage(kAutoHide));
// Clock controls
fShowSeconds = new BCheckBox(B_TRANSLATE("Show seconds"),
new BMessage(kShowSeconds));
fShowDayOfWeek = new BCheckBox(B_TRANSLATE("Show day of week"),
new BMessage(kShowDayOfWeek));
// Get settings from BarApp
TBarApp* barApp = static_cast<TBarApp*>(be_app);
desk_settings* settings = barApp->Settings();
@ -156,16 +150,6 @@ PreferencesWindow::PreferencesWindow(BRect frame)
fWindowAutoRaise->SetValue(settings->autoRaise);
fWindowAutoHide->SetValue(settings->autoHide);
// Clock settings
TReplicantTray* replicantTray = barApp->BarView()->ReplicantTray();
if (replicantTray->Time() != NULL) {
fShowSeconds->SetValue(replicantTray->Time()->ShowSeconds());
fShowDayOfWeek->SetValue(replicantTray->Time()->ShowDayOfWeek());
} else {
fShowSeconds->SetValue(settings->showSeconds);
fShowDayOfWeek->SetValue(settings->showDayOfWeek);
}
EnableDisableDependentItems();
// Targets
@ -179,19 +163,14 @@ PreferencesWindow::PreferencesWindow(BRect frame)
fWindowAutoRaise->SetTarget(be_app);
fWindowAutoHide->SetTarget(be_app);
fShowSeconds->SetTarget(replicantTray);
fShowDayOfWeek->SetTarget(replicantTray);
// Layout
fMenuBox = new BBox("fMenuBox");
fAppsBox = new BBox("fAppsBox");
fWindowBox = new BBox("fWindowBox");
fClockBox = new BBox("fClockBox");
fMenuBox->SetLabel(B_TRANSLATE("Menu"));
fAppsBox->SetLabel(B_TRANSLATE("Applications"));
fWindowBox->SetLabel(B_TRANSLATE("Window"));
fClockBox->SetLabel(B_TRANSLATE("Clock"));
BView* view;
view = BLayoutBuilder::Group<>()
@ -252,25 +231,12 @@ PreferencesWindow::PreferencesWindow(BRect frame)
.View();
fWindowBox->AddChild(view);
view = BLayoutBuilder::Group<>()
.AddGroup(B_VERTICAL, 0)
.Add(fShowSeconds)
.Add(fShowDayOfWeek)
.AddGlue()
.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
.End()
.View();
fClockBox->AddChild(view);
BLayoutBuilder::Group<>(this)
.AddGrid(5, 5)
.Add(fMenuBox, 0, 0)
.Add(fWindowBox, 1, 0)
.Add(fAppsBox, 0, 1)
.Add(fClockBox, 1, 1)
.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
.Add(fMenuBox)
.Add(fAppsBox)
.Add(fWindowBox)
.SetInsets(B_USE_DEFAULT_SPACING)
.End()
.End();

View File

@ -23,11 +23,6 @@ const uint32 kResizeTeamIcons = 'RTIs';
const uint32 kAutoRaise = 'AtRs';
const uint32 kAutoHide = 'AtHd';
const uint32 kShowHideTime = 'ShTm';
const uint32 kShowSeconds = 'SwSc';
const uint32 kShowDayOfWeek = 'SwDw';
class BBox;
class BButton;
class BCheckBox;
@ -51,7 +46,6 @@ public:
private:
BBox* fMenuBox;
BBox* fAppsBox;
BBox* fClockBox;
BBox* fWindowBox;
BCheckBox* fMenuRecentDocuments;
@ -72,9 +66,6 @@ private:
BCheckBox* fWindowAlwaysOnTop;
BCheckBox* fWindowAutoRaise;
BCheckBox* fWindowAutoHide;
BCheckBox* fShowSeconds;
BCheckBox* fShowDayOfWeek;
};

View File

@ -147,14 +147,8 @@ TReplicantTray::TReplicantTray(TBarView* parent, bool vertical)
fMinimumTrayWidth = sMinimumWindowWidth - kGutter - kDragRegionWidth;
}
BFormattingConventions conventions;
BLocale::Default()->GetFormattingConventions(&conventions);
bool use24HourClock = conventions.Use24HourClock();
desk_settings* settings = ((TBarApp*)be_app)->Settings();
// Create the time view
fTime = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0,
use24HourClock, settings->showSeconds, settings->showDayOfWeek);
fTime = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0);
}
@ -180,6 +174,12 @@ TReplicantTray::AttachedToWindow()
Window()->SetPulseRate(1000000);
// Set clock settings
clock_settings* settings = ((TBarApp*)be_app)->ClockSettings();
fTime->SetShowSeconds(settings->showSeconds);
fTime->SetShowDayOfWeek(settings->showDayOfWeek);
fTime->SetShowTimeZone(settings->showTimeZone);
AddChild(fTime);
fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - 1, 2);
@ -279,10 +279,7 @@ TReplicantTray::MessageReceived(BMessage* message)
if (fTime == NULL)
return;
// Locale may have updated 12/24 hour clock
BFormattingConventions conventions;
BLocale::Default()->GetFormattingConventions(&conventions);
fTime->SetUse24HourClock(conventions.Use24HourClock());
fTime->Update();
// time string reformat -> realign
RealignReplicants();
@ -317,6 +314,36 @@ TReplicantTray::MessageReceived(BMessage* message)
AdjustPlacement();
break;
case kShowTimeZone:
if (fTime == NULL)
return;
fTime->SetShowTimeZone(!fTime->ShowTimeZone());
// time string reformat -> realign
RealignReplicants();
AdjustPlacement();
break;
case kGetClockSettings:
{
if (fTime == NULL)
return;
bool showClock = !fTime->IsHidden();
bool showSeconds = fTime->ShowSeconds();
bool showDayOfWeek = fTime->ShowDayOfWeek();
bool showTimeZone = fTime->ShowTimeZone();
BMessage* reply = new BMessage(kGetClockSettings);
reply->AddBool("showClock", showClock);
reply->AddBool("showSeconds", showSeconds);
reply->AddBool("showDayOfWeek", showDayOfWeek);
reply->AddBool("showTimeZone", showTimeZone);
message->SendReply(reply);
break;
}
#ifdef DB_ADDONS
case B_NODE_MONITOR:
HandleEntryUpdate(message);
@ -375,12 +402,12 @@ TReplicantTray::ShowReplicantMenu(BPoint point)
BPopUpMenu* menu = new BPopUpMenu("", false, false);
menu->SetFont(be_plain_font);
// If clock is visible show the extended menu, otherwise show "Show time"
// If clock is visible show the extended menu, otherwise show "Show clock"
if (!fTime->IsHidden())
fTime->ShowTimeOptions(ConvertToScreen(point));
else {
BMenuItem* item = new BMenuItem(B_TRANSLATE("Show time"),
BMenuItem* item = new BMenuItem(B_TRANSLATE("Show clock"),
new BMessage(kShowHideTime));
menu->AddItem(item);
menu->SetTargetForItems(this);
@ -411,6 +438,12 @@ TReplicantTray::ShowHideTime()
RealignReplicants();
AdjustPlacement();
// message Time preferences to update it's show time setting
BMessenger messenger("application/x-vnd.Haiku-Time");
BMessage* message = new BMessage(kShowHideTime);
message->AddBool("showClock", !fTime->IsHidden());
messenger.SendMessage(message);
}
@ -1235,9 +1268,10 @@ TReplicantTray::SaveTimeSettings()
if (fTime == NULL)
return;
desk_settings* settings = ((TBarApp*)be_app)->Settings();
clock_settings* settings = ((TBarApp*)be_app)->ClockSettings();
settings->showSeconds = fTime->ShowSeconds();
settings->showDayOfWeek = fTime->ShowDayOfWeek();
settings->showTimeZone = fTime->ShowTimeZone();
}

View File

@ -38,6 +38,7 @@ All rights reserved.
#include <string.h>
#include <Application.h>
#include <Catalog.h>
#include <Debug.h>
#include <Locale.h>
@ -55,20 +56,11 @@ static const char* const kMinString = "99:99 AM";
static const float kHMargin = 2.0;
enum {
kShowTime,
kChangeTime,
kHide,
kShowCalendar
};
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "TimeView"
TTimeView::TTimeView(float maxWidth, float height, bool use24HourClock,
bool showSeconds, bool showDayOfWeek)
TTimeView::TTimeView(float maxWidth, float height)
:
BView(BRect(-100, -100, -90, -90), "_deskbar_tv_",
B_FOLLOW_RIGHT | B_FOLLOW_TOP,
@ -77,9 +69,9 @@ TTimeView::TTimeView(float maxWidth, float height, bool use24HourClock,
fMaxWidth(maxWidth),
fHeight(height),
fOrientation(true),
fUse24HourClock(use24HourClock),
fShowSeconds(showSeconds),
fShowDayOfWeek(showDayOfWeek)
fShowSeconds(false),
fShowDayOfWeek(false),
fShowTimeZone(false)
{
fCurrentTime = fLastTime = time(NULL);
fSeconds = fMinute = fHour = 0;
@ -88,7 +80,6 @@ TTimeView::TTimeView(float maxWidth, float height, bool use24HourClock,
fLastTimeStr[0] = 0;
fLastDateStr[0] = 0;
fNeedToUpdate = true;
fLocale = *BLocale::Default();
}
@ -125,7 +116,10 @@ status_t
TTimeView::Archive(BMessage* data, bool deep) const
{
BView::Archive(data, deep);
data->AddBool("seconds", fShowSeconds);
data->AddBool("showSeconds", fShowSeconds);
data->AddBool("showDayOfWeek", fShowDayOfWeek);
data->AddBool("showTimeZone", fShowTimeZone);
data->AddBool("orientation", fOrientation);
data->AddInt32("deskbar:private_align", B_ALIGN_RIGHT);
return B_OK;
@ -194,13 +188,21 @@ TTimeView::MessageReceived(BMessage* message)
{
switch (message->what) {
case kChangeTime:
{
// launch the time prefs app
be_roster->Launch("application/x-vnd.Haiku-Time");
// tell Time preflet to switch to the clock tab
BMessenger messenger("application/x-vnd.Haiku-Time");
BMessage* switchToClock = new BMessage('SlCk');
messenger.SendMessage(switchToClock);
break;
}
case kShowHideTime:
Window()->PostMessage(message, Parent());
{
be_app->MessageReceived(message);
break;
}
case kShowCalendar:
{
@ -302,21 +304,6 @@ TTimeView::SetOrientation(bool orientation)
}
bool
TTimeView::Use24HourClock() const
{
return fUse24HourClock;
}
void
TTimeView::SetUse24HourClock(bool use24HourClock)
{
fUse24HourClock = use24HourClock;
Update();
}
bool
TTimeView::ShowSeconds() const
{
@ -347,6 +334,21 @@ TTimeView::SetShowDayOfWeek(bool show)
}
bool
TTimeView::ShowTimeZone() const
{
return fShowTimeZone;
}
void
TTimeView::SetShowTimeZone(bool show)
{
fShowTimeZone = show;
Update();
}
void
TTimeView::ShowCalendar(BPoint where)
{
@ -379,16 +381,17 @@ TTimeView::ShowCalendar(BPoint where)
void
TTimeView::GetCurrentTime()
{
ssize_t offset = 0;
ssize_t offset_dow = 0;
ssize_t offset_time = 0;
// ToDo: Check to see if we should write day of week after time for locale
if (fShowDayOfWeek) {
BString timeFormat("eee ");
offset = fLocale.FormatTime(fCurrentTimeStr, sizeof(fCurrentTimeStr),
fCurrentTime, timeFormat);
offset_dow = fLocale.FormatTime(fCurrentTimeStr,
sizeof(fCurrentTimeStr), fCurrentTime, timeFormat);
if (offset < 0) {
if (offset_dow < 0) {
// error occured, attempt to overwrite with current time
// (this should not ever happen)
fLocale.FormatTime(fCurrentTimeStr, sizeof(fCurrentTimeStr),
@ -398,9 +401,16 @@ TTimeView::GetCurrentTime()
}
}
fLocale.FormatTime(fCurrentTimeStr + offset,
sizeof(fCurrentTimeStr) - offset, fCurrentTime,
offset_time = fLocale.FormatTime(fCurrentTimeStr + offset_dow,
sizeof(fCurrentTimeStr) - offset_dow, fCurrentTime,
fShowSeconds ? B_MEDIUM_TIME_FORMAT : B_SHORT_TIME_FORMAT);
if (fShowTimeZone) {
BString timeFormat(" V");
ssize_t offset = offset_dow + offset_time;
fLocale.FormatTime(fCurrentTimeStr + offset,
sizeof(fCurrentTimeStr) - offset, fCurrentTime, timeFormat);
}
}
@ -456,7 +466,7 @@ TTimeView::ShowTimeOptions(BPoint point)
new BMessage(kChangeTime));
menu->AddItem(item);
item = new BMenuItem(B_TRANSLATE("Hide time"),
item = new BMenuItem(B_TRANSLATE("Hide clock"),
new BMessage(kShowHideTime));
menu->AddItem(item);

View File

@ -41,7 +41,28 @@ All rights reserved.
#include <Messenger.h>
#include <View.h>
#include "PreferencesWindow.h" // For message constants
// open Time preferences
const uint32 kChangeTime = 'ChTm';
// pop the calendar
const uint32 kShowCalendar = 'ShCa';
// show or hide clock
const uint32 kShowHideTime = 'ShTm';
// show seconds
const uint32 kShowSeconds = 'SwSc';
// show day of week
const uint32 kShowDayOfWeek = 'SwDw';
// show time zone
const uint32 kShowTimeZone = 'SwTz';
// get clock settings to send to Time prefs
const uint32 kGetClockSettings = 'GCkS';
class BCountry;
@ -53,9 +74,7 @@ class _EXPORT TTimeView;
class TTimeView : public BView {
public:
TTimeView(float maxWidth, float height,
bool use24HourClock, bool showSeconds,
bool showDayOfWeek);
TTimeView(float maxWidth, float height);
TTimeView(BMessage* data);
~TTimeView();
@ -77,15 +96,15 @@ public:
bool Orientation() const;
void SetOrientation(bool o);
bool Use24HourClock() const;
void SetUse24HourClock(bool use24HourClock);
bool ShowSeconds() const;
void SetShowSeconds(bool show);
bool ShowDayOfWeek() const;
void SetShowDayOfWeek(bool show);
bool ShowTimeZone() const;
void SetShowTimeZone(bool show);
void ShowCalendar(BPoint where);
private:
@ -116,9 +135,12 @@ private:
float fHeight;
bool fOrientation; // vertical = true
bool fOverrideLocale;
bool fUse24HourClock;
bool fShowSeconds;
bool fShowDayOfWeek;
bool fShowTimeZone;
BString fTimeFormat;
BPoint fTimeLocation;

View File

@ -258,12 +258,27 @@ void
FormatSettingsView::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_LOCALE_CHANGED:
{
// Time updated 12/24 hour clock
BFormattingConventions conventions;
BLocale::Default()->GetFormattingConventions(&conventions);
if (conventions.Use24HourClock())
f24HourRadioButton->SetValue(B_CONTROL_ON);
else
f12HourRadioButton->SetValue(B_CONTROL_ON);
_UpdateExamples();
Window()->PostMessage(kMsgSettingsChanged);
break;
}
case kClockFormatChange:
{
BFormattingConventions conventions;
BLocale::Default()->GetFormattingConventions(&conventions);
conventions.SetExplicitUse24HourClock(
f24HourRadioButton->Value() ? true : false);
f24HourRadioButton->Value() == B_CONTROL_ON);
MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
conventions);

View File

@ -65,6 +65,11 @@ void
LocalePreflet::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_LOCALE_CHANGED:
BLocaleRoster::Default()->Refresh();
fLocaleWindow->PostMessage(message);
break;
case kMsgRestartTrackerAndDeskbar:
if (message->FindInt32("which") == 1) {
_RestartApp("application/x-vnd.Be-TRAK");

View File

@ -295,6 +295,10 @@ void
LocaleWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_LOCALE_CHANGED:
fFormatView->MessageReceived(message);
break;
case kMsgDefaults:
_Defaults();
break;
@ -478,8 +482,7 @@ LocaleWindow::Show()
void
LocaleWindow::_SettingsChanged()
{
bool haveAnythingToRevert = fFormatView->IsReversible() || _IsReversible();
fRevertButton->SetEnabled(haveAnythingToRevert);
fRevertButton->SetEnabled(fFormatView->IsReversible() || _IsReversible());
}

View File

@ -0,0 +1,227 @@
/*
* Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* John Scipione <jscipione@gmail.com>
*/
#include "ClockView.h"
#include <Alignment.h>
#include <Box.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <ControlLook.h>
#include <LayoutBuilder.h>
#include <Locale.h>
#include <Message.h>
#include <Messenger.h>
#include <RadioButton.h>
#include <SpaceLayoutItem.h>
#include <Window.h>
#include "TimeMessages.h"
static const char* kDeskbarSignature = "application/x-vnd.Be-TSKB";
static const float kIndentSpacing
= be_control_look->DefaultItemSpacing() * 2.3;
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Time"
ClockView::ClockView(const char* name)
:
BView(name, 0),
fCachedShowClock(B_CONTROL_ON),
fCachedShowSeconds(B_CONTROL_OFF),
fCachedShowDayOfWeek(B_CONTROL_OFF),
fCachedShowTimeZone(B_CONTROL_OFF)
{
fShowClock = new BCheckBox(B_TRANSLATE("Show clock in Deskbar"),
new BMessage(kShowHideTime));
fShowSeconds = new BCheckBox(B_TRANSLATE("Display time with seconds"),
new BMessage(kShowSeconds));
fShowDayOfWeek = new BCheckBox(B_TRANSLATE("Show day of week"),
new BMessage(kShowDayOfWeek));
fShowTimeZone = new BCheckBox(B_TRANSLATE("Show time zone"),
new BMessage(kShowTimeZone));
BView* view = BLayoutBuilder::Group<>(B_VERTICAL, 0)
.Add(fShowSeconds)
.Add(fShowDayOfWeek)
.Add(fShowTimeZone)
.AddGlue()
.SetInsets(B_USE_DEFAULT_SPACING)
.View();
BBox* showClockBox = new BBox("show clock box");
showClockBox->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP));
showClockBox->SetLabel(fShowClock);
showClockBox->AddChild(view);
BLayoutBuilder::Group<>(this)
.AddGroup(B_VERTICAL, 0)
.Add(showClockBox)
.End()
.SetInsets(B_USE_DEFAULT_SPACING);
}
ClockView::~ClockView()
{
}
void
ClockView::AttachedToWindow()
{
if (Parent())
SetViewColor(Parent()->ViewColor());
fShowClock->SetTarget(this);
fShowSeconds->SetTarget(this);
fShowDayOfWeek->SetTarget(this);
fShowTimeZone->SetTarget(this);
// Disable these controls initially, they'll be enabled
// when we get a response from Deskbar.
fShowClock->SetEnabled(false);
fShowSeconds->SetEnabled(false);
fShowDayOfWeek->SetEnabled(false);
fShowTimeZone->SetEnabled(false);
// Ask Deskbar for current clock settings, it will reply
// asynchronously in MesssageReceived() below.
BMessenger* messenger = new BMessenger(kDeskbarSignature);
BMessenger replyMessenger(this);
BMessage* message = new BMessage(kGetClockSettings);
messenger->SendMessage(message, replyMessenger);
}
void
ClockView::MessageReceived(BMessage* message)
{
switch (message->what) {
case kGetClockSettings:
{
// Get current clock settings from Deskbar
bool showClock;
bool showSeconds;
bool showDayOfWeek;
bool showTimeZone;
if (message->FindBool("showSeconds", &showSeconds) == B_OK) {
fCachedShowSeconds = showSeconds
? B_CONTROL_ON : B_CONTROL_OFF;
fShowSeconds->SetValue(fCachedShowSeconds);
fShowSeconds->SetEnabled(true);
}
if (message->FindBool("showDayOfWeek", &showDayOfWeek) == B_OK) {
fCachedShowDayOfWeek = showDayOfWeek
? B_CONTROL_ON : B_CONTROL_OFF;
fShowDayOfWeek->SetValue(fCachedShowDayOfWeek);
fShowDayOfWeek->SetEnabled(true);
}
if (message->FindBool("showTimeZone", &showTimeZone) == B_OK) {
fCachedShowTimeZone = showTimeZone
? B_CONTROL_ON : B_CONTROL_OFF;
fShowTimeZone->SetValue(fCachedShowTimeZone);
fShowTimeZone->SetEnabled(true);
}
// do this one last because it might disable the others
if (message->FindBool("showClock", &showClock) == B_OK) {
fCachedShowClock = showClock ? B_CONTROL_ON : B_CONTROL_OFF;
fShowClock->SetValue(fCachedShowClock);
fShowClock->SetEnabled(true);
fShowSeconds->SetEnabled(showClock);
fShowDayOfWeek->SetEnabled(showClock);
fShowTimeZone->SetEnabled(showClock);
}
break;
}
case kShowHideTime:
{
bool showClock;
if (message->FindBool("showClock", &showClock) == B_OK) {
// message originated from Deskbar, handle special
fShowClock->SetValue(showClock ? B_CONTROL_ON : B_CONTROL_OFF);
fShowSeconds->SetEnabled(showClock);
fShowDayOfWeek->SetEnabled(showClock);
fShowTimeZone->SetEnabled(showClock);
Window()->PostMessage(kMsgChange);
break;
// don't fall through
}
showClock = fShowClock->Value() == B_CONTROL_ON;
fShowSeconds->SetEnabled(showClock);
fShowDayOfWeek->SetEnabled(showClock);
fShowTimeZone->SetEnabled(showClock);
}
// fall-through
case kShowSeconds:
case kShowDayOfWeek:
case kShowTimeZone:
{
BMessenger* messenger = new BMessenger(kDeskbarSignature);
messenger->SendMessage(message);
Window()->PostMessage(kMsgChange);
break;
}
case kMsgRevert:
_Revert();
break;
default:
BView::MessageReceived(message);
break;
}
}
bool
ClockView::CheckCanRevert()
{
return fShowClock->Value() != fCachedShowClock
|| fShowSeconds->Value() != fCachedShowSeconds
|| fShowDayOfWeek->Value() != fCachedShowDayOfWeek
|| fShowTimeZone->Value() != fCachedShowTimeZone;
}
void
ClockView::_Revert()
{
if (fShowClock->Value() != fCachedShowClock) {
fShowClock->SetValue(fCachedShowClock);
fShowClock->Invoke();
}
if (fShowSeconds->Value() != fCachedShowSeconds) {
fShowSeconds->SetValue(fCachedShowSeconds);
fShowSeconds->Invoke();
}
if (fShowDayOfWeek->Value() != fCachedShowDayOfWeek) {
fShowDayOfWeek->SetValue(fCachedShowDayOfWeek);
fShowDayOfWeek->Invoke();
}
if (fShowTimeZone->Value() != fCachedShowTimeZone) {
fShowTimeZone->SetValue(fCachedShowTimeZone);
fShowTimeZone->Invoke();
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* John Scipione <jscipione@gmail.com>
*/
#ifndef _CLOCK_VIEW_H
#define _CLOCK_VIEW_H
#include <View.h>
class BCheckBox;
class BRadioButton;
class ClockView : public BView {
public:
ClockView(const char* name);
virtual ~ClockView();
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
bool CheckCanRevert();
private:
void _Revert();
BCheckBox* fShowClock;
BCheckBox* fShowSeconds;
BCheckBox* fShowDayOfWeek;
BCheckBox* fShowTimeZone;
int32 fCachedShowClock;
int32 fCachedShowSeconds;
int32 fCachedShowDayOfWeek;
int32 fCachedShowTimeZone;
};
#endif // _CLOCK_VIEW_H

View File

@ -9,6 +9,7 @@ local sources =
AnalogClock.cpp
BaseView.cpp
Bitmaps.cpp
ClockView.cpp
DateTimeEdit.cpp
SectionEdit.cpp
DateTimeView.cpp

View File

@ -20,6 +20,7 @@
#include <Catalog.h>
#include "NetworkTimeView.h"
#include "TimeMessages.h"
#include "TimeWindow.h"
@ -64,6 +65,22 @@ TimeApplication::AboutRequested()
}
void
TimeApplication::MessageReceived(BMessage* message)
{
switch (message->what) {
case kSelectClockTab:
case kShowHideTime:
fWindow->PostMessage(message);
break;
default:
BApplication::MessageReceived(message);
break;
}
}
int
main(int argc, char** argv)
{

View File

@ -14,6 +14,7 @@
#include <Application.h>
class BMessage;
class TTimeWindow;
@ -25,6 +26,8 @@ public:
virtual void ReadyToRun();
virtual void AboutRequested();
virtual void MessageReceived(BMessage* message);
private:
TTimeWindow* fWindow;
};

View File

@ -49,5 +49,23 @@ const uint32 kMsgChange = 'chng';
// change time finished
const uint32 kChangeTimeFinished = 'tcfi';
// show or hide Deskbar clock
const uint32 kShowHideTime = 'ShTm';
// show seconds
const uint32 kShowSeconds = 'SwSc';
// show day of week
const uint32 kShowDayOfWeek = 'SwDw';
// show time zone
const uint32 kShowTimeZone = 'SwTz';
// get clock settings from Deskbar
const uint32 kGetClockSettings = 'GCkS';
// bring the clock tab to front
const uint32 kSelectClockTab = 'SlCk';
#endif // _TIME_MESSAGES_H

View File

@ -19,6 +19,7 @@
#include <TabView.h>
#include "BaseView.h"
#include "ClockView.h"
#include "DateTimeView.h"
#include "NetworkTimeView.h"
#include "TimeMessages.h"
@ -79,6 +80,7 @@ TTimeWindow::MessageReceived(BMessage* message)
fDateTimeView->MessageReceived(message);
fTimeZoneView->MessageReceived(message);
fNetworkTimeView->MessageReceived(message);
fClockView->MessageReceived(message);
fRevertButton->SetEnabled(false);
break;
@ -92,6 +94,15 @@ TTimeWindow::MessageReceived(BMessage* message)
_SetRevertStatus();
break;
case kSelectClockTab:
// focus the clock tab (last one)
fTabView->Select(fTabView->CountTabs() - 1);
break;
case kShowHideTime:
fClockView->MessageReceived(message);
break;
default:
BWindow::MessageReceived(message);
break;
@ -107,17 +118,19 @@ TTimeWindow::_InitWindow()
fDateTimeView = new DateTimeView(B_TRANSLATE("Date and time"));
fTimeZoneView = new TimeZoneView(B_TRANSLATE("Time zone"));
fNetworkTimeView = new NetworkTimeView(B_TRANSLATE("Network time"));
fClockView = new ClockView(B_TRANSLATE("Clock"));
fBaseView = new TTimeBaseView("baseView");
fBaseView->StartWatchingAll(fDateTimeView);
fBaseView->StartWatchingAll(fTimeZoneView);
BTabView* tabView = new BTabView("tabView");
tabView->AddTab(fDateTimeView);
tabView->AddTab(fTimeZoneView);
tabView->AddTab(fNetworkTimeView);
fTabView = new BTabView("tabView");
fTabView->AddTab(fDateTimeView);
fTabView->AddTab(fTimeZoneView);
fTabView->AddTab(fNetworkTimeView);
fTabView->AddTab(fClockView);
fBaseView->AddChild(tabView);
fBaseView->AddChild(fTabView);
fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
new BMessage(kMsgRevert));
@ -166,5 +179,6 @@ TTimeWindow::_SetRevertStatus()
{
fRevertButton->SetEnabled(fDateTimeView->CheckCanRevert()
|| fTimeZoneView->CheckCanRevert()
|| fNetworkTimeView->CheckCanRevert());
|| fNetworkTimeView->CheckCanRevert()
|| fClockView->CheckCanRevert());
}

View File

@ -14,10 +14,12 @@
class BMessage;
class BTabView;
class ClockView;
class DateTimeView;
class TTimeBaseView;
class TimeZoneView;
class NetworkTimeView;
class TimeZoneView;
class TTimeBaseView;
class TTimeWindow : public BWindow {
@ -35,9 +37,13 @@ private:
void _SetRevertStatus();
TTimeBaseView* fBaseView;
BTabView* fTabView;
DateTimeView* fDateTimeView;
TimeZoneView* fTimeZoneView;
NetworkTimeView* fNetworkTimeView;
ClockView* fClockView;
BButton* fRevertButton;
};