Skip to content

Commit

Permalink
Add Deskbar clock settings to Time Preferences
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jscipione committed Dec 20, 2012
1 parent 9a538a2 commit 31c0024
Show file tree
Hide file tree
Showing 21 changed files with 570 additions and 139 deletions.
78 changes: 60 additions & 18 deletions src/apps/deskbar/BarApp.cpp
Expand Up @@ -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>
Expand All @@ -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;

Expand All @@ -95,6 +96,7 @@ main()
TBarApp::TBarApp()
: BApplication(kDeskbarSignature),
fSettingsFile(NULL),
fClockSettingsFile(NULL),
fPreferencesWindow(NULL)
{
InitSettings();
Expand Down Expand Up @@ -159,8 +161,11 @@ TBarApp::~TBarApp()
= static_cast<BMessenger*>(sSubscribers.ItemAt(i));
delete messenger;
}

SaveSettings();

delete fSettingsFile;
delete fClockSettingsFile;
}


Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}


Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/apps/deskbar/BarApp.h
Expand Up @@ -75,8 +75,6 @@ struct desk_settings {
bool vertical;
bool left;
bool top;
bool showSeconds;
bool showDayOfWeek;
uint32 state;
float width;
BPoint switcherLoc;
Expand All @@ -99,6 +97,12 @@ struct desk_settings {
bool recentFoldersEnabled;
};

struct clock_settings {
bool showSeconds;
bool showDayOfWeek;
bool showTimeZone;
};

class BFile;
class BList;
class BBitmap;
Expand Down Expand Up @@ -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; }

Expand All @@ -156,7 +161,9 @@ class TBarApp : public BApplication {
BMessenger fSwitcherMessenger;
BMessenger fStatusViewMessenger;
BFile* fSettingsFile;
BFile* fClockSettingsFile;
desk_settings fSettings;
clock_settings fClockSettings;

PreferencesWindow* fPreferencesWindow;

Expand Down
5 changes: 5 additions & 0 deletions src/apps/deskbar/BarView.cpp
Expand Up @@ -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;

Expand Down
7 changes: 3 additions & 4 deletions src/apps/deskbar/DeskbarMenu.cpp
Expand Up @@ -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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/apps/deskbar/DeskbarMenu.h
Expand Up @@ -37,6 +37,8 @@ All rights reserved.


#include "NavMenu.h"
#include "PreferencesWindow.h"
// for message constants


class TBarView;
Expand Down
44 changes: 5 additions & 39 deletions src/apps/deskbar/PreferencesWindow.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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<>()
Expand Down Expand Up @@ -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();

Expand Down
9 changes: 0 additions & 9 deletions src/apps/deskbar/PreferencesWindow.h
Expand Up @@ -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;
Expand All @@ -51,7 +46,6 @@ class PreferencesWindow : public BWindow
private:
BBox* fMenuBox;
BBox* fAppsBox;
BBox* fClockBox;
BBox* fWindowBox;

BCheckBox* fMenuRecentDocuments;
Expand All @@ -72,9 +66,6 @@ class PreferencesWindow : public BWindow
BCheckBox* fWindowAlwaysOnTop;
BCheckBox* fWindowAutoRaise;
BCheckBox* fWindowAutoHide;

BCheckBox* fShowSeconds;
BCheckBox* fShowDayOfWeek;
};


Expand Down

0 comments on commit 31c0024

Please sign in to comment.