From 2f0eb7b11e9cdb428b2da5bfaac25c9998b02e03 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 2 Jul 2010 17:15:55 +0000 Subject: [PATCH] * Introduce a new method in BCountry to get the first day of week (monday or sunday) * Localize date in deskbar properly, and use the new API to show the calendar. The "show european date" checkbox is now gone. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37344 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/locale/Country.h | 2 ++ src/apps/deskbar/BarApp.cpp | 3 --- src/apps/deskbar/BarApp.h | 5 ++-- src/apps/deskbar/BeMenu.cpp | 1 - src/apps/deskbar/CalendarMenuWindow.cpp | 10 ++++++-- src/apps/deskbar/CalendarMenuWindow.h | 2 +- src/apps/deskbar/PreferencesWindow.cpp | 6 ----- src/apps/deskbar/PreferencesWindow.h | 1 - src/apps/deskbar/StatusView.cpp | 13 +--------- src/apps/deskbar/StatusView.h | 1 - src/apps/deskbar/TimeView.cpp | 32 +++---------------------- src/apps/deskbar/TimeView.h | 7 +----- src/kits/locale/Country.cpp | 22 +++++++++++++++++ 13 files changed, 40 insertions(+), 65 deletions(-) diff --git a/headers/os/locale/Country.h b/headers/os/locale/Country.h index ec34e4f667..cb8c7825fd 100644 --- a/headers/os/locale/Country.h +++ b/headers/os/locale/Country.h @@ -49,6 +49,8 @@ class BCountry { const char* DateSeparator() const; const char* TimeSeparator() const; + int StartOfWeek(); + // numbers virtual void FormatNumber(char* string, size_t maxSize, double value); diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index bb7af8644f..50f3a30f7a 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -192,7 +192,6 @@ TBarApp::SaveSettings() fSettingsFile->Write(&fSettings.recentDocsCount, sizeof(int32)); fSettingsFile->Write(&fSettings.timeShowSeconds, sizeof(bool)); fSettingsFile->Write(&fSettings.recentFoldersCount, sizeof(int32)); - fSettingsFile->Write(&fSettings.timeShowEuro, sizeof(bool)); fSettingsFile->Write(&fSettings.alwaysOnTop, sizeof(bool)); fSettingsFile->Write(&fSettings.timeFullDate, sizeof(bool)); fSettingsFile->Write(&fSettings.trackerAlwaysFirst, sizeof(bool)); @@ -223,7 +222,6 @@ TBarApp::InitSettings() settings.recentDocsCount = 10; settings.timeShowSeconds = false; settings.recentFoldersCount = 10; - settings.timeShowEuro = false; settings.alwaysOnTop = false; settings.timeFullDate = false; settings.trackerAlwaysFirst = false; @@ -278,7 +276,6 @@ TBarApp::InitSettings() fSettingsFile->Read(&settings.recentFoldersCount, sizeof(int32)); if (size >= kValidSettingsSize6) { - fSettingsFile->Read(&settings.timeShowEuro, sizeof(bool)); fSettingsFile->Read(&settings.alwaysOnTop, sizeof(bool)); } if (size >= kValidSettingsSize7) diff --git a/src/apps/deskbar/BarApp.h b/src/apps/deskbar/BarApp.h index 1a8585f459..c557699352 100644 --- a/src/apps/deskbar/BarApp.h +++ b/src/apps/deskbar/BarApp.h @@ -105,8 +105,7 @@ struct desk_settings { int32 recentDocsCount; bool timeShowSeconds; // version 4 int32 recentFoldersCount; // version 5 - bool timeShowEuro; // version 6 - bool alwaysOnTop; + bool alwaysOnTop; // version 6 bool timeFullDate; // version 7 bool trackerAlwaysFirst; // version 8 bool sortRunningApps; @@ -127,7 +126,7 @@ const uint32 kValidSettingsSize2 = sizeof(BPoint) + kValidSettingsSize1; const uint32 kValidSettingsSize3 = 2 * sizeof(int32) + kValidSettingsSize2; const uint32 kValidSettingsSize4 = sizeof(bool) + kValidSettingsSize3; const uint32 kValidSettingsSize5 = sizeof(int32) + kValidSettingsSize4; -const uint32 kValidSettingsSize6 = 2 * sizeof(bool) + kValidSettingsSize5; +const uint32 kValidSettingsSize6 = sizeof(bool) + kValidSettingsSize5; const uint32 kValidSettingsSize7 = sizeof(bool) + kValidSettingsSize6; const uint32 kValidSettingsSize8 = 2 * sizeof(bool) + kValidSettingsSize7; const uint32 kValidSettingsSize9 = 2 * sizeof(bool) + kValidSettingsSize8; diff --git a/src/apps/deskbar/BeMenu.cpp b/src/apps/deskbar/BeMenu.cpp index fe4e81db41..790509bdba 100644 --- a/src/apps/deskbar/BeMenu.cpp +++ b/src/apps/deskbar/BeMenu.cpp @@ -371,7 +371,6 @@ TBeMenu::ResetTargets() case kConfigShow: case kAlwaysTop: case kShowSeconds: - case kEuroDate: case kRebootSystem: case kSuspendSystem: case kShutdownSystem: diff --git a/src/apps/deskbar/CalendarMenuWindow.cpp b/src/apps/deskbar/CalendarMenuWindow.cpp index a54ac9b714..8368c6b976 100644 --- a/src/apps/deskbar/CalendarMenuWindow.cpp +++ b/src/apps/deskbar/CalendarMenuWindow.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -77,7 +79,7 @@ enum { }; -CalendarMenuWindow::CalendarMenuWindow(BPoint where, bool euroDate) +CalendarMenuWindow::CalendarMenuWindow(BPoint where) : BWindow(BRect(0.0, 0.0, 100.0, 130.0), "", B_BORDERED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_CLOSE_ON_ESCAPE @@ -87,6 +89,10 @@ CalendarMenuWindow::CalendarMenuWindow(BPoint where, bool euroDate) fCalendarView(NULL), fSuppressFirstClose(true) { + BCountry* here; + be_locale_roster->GetDefaultCountry(&here); + BPrivate::week_start startOfWeek = /*here->StartOfWeek()*/ B_WEEK_START_MONDAY; + RemoveShortcut('H', B_COMMAND_KEY | B_CONTROL_KEY); AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); @@ -97,7 +103,7 @@ CalendarMenuWindow::CalendarMenuWindow(BPoint where, bool euroDate) fMonthLabel->SetFontSize(10.0); fCalendarView = new BCalendarView(Bounds(), "calendar", - euroDate ? B_WEEK_START_MONDAY : B_WEEK_START_SUNDAY, B_FOLLOW_ALL); + startOfWeek, B_FOLLOW_ALL); fCalendarView->SetInvocationMessage(new BMessage(kInvokationMessage)); fCalendarView->SetFontSize(10.0); diff --git a/src/apps/deskbar/CalendarMenuWindow.h b/src/apps/deskbar/CalendarMenuWindow.h index 9b27be4030..57b627eabc 100644 --- a/src/apps/deskbar/CalendarMenuWindow.h +++ b/src/apps/deskbar/CalendarMenuWindow.h @@ -22,7 +22,7 @@ using BPrivate::BCalendarView; class CalendarMenuWindow : public BWindow { public: - CalendarMenuWindow(BPoint where, bool euroDate); + CalendarMenuWindow(BPoint where); virtual ~CalendarMenuWindow(); virtual void Show(); diff --git a/src/apps/deskbar/PreferencesWindow.cpp b/src/apps/deskbar/PreferencesWindow.cpp index af0167ec29..b7e559f062 100644 --- a/src/apps/deskbar/PreferencesWindow.cpp +++ b/src/apps/deskbar/PreferencesWindow.cpp @@ -60,8 +60,6 @@ PreferencesWindow::PreferencesWindow(BRect frame) fClockSeconds = new BCheckBox(B_TRANSLATE("Show seconds"), new BMessage(kShowSeconds)); - fClockEuropeanDate = new BCheckBox(B_TRANSLATE("European date"), - new BMessage(kEuroDate)); fClockFullDate = new BCheckBox(B_TRANSLATE("Full date"), new BMessage(kFullDate)); @@ -123,12 +121,10 @@ PreferencesWindow::PreferencesWindow(BRect frame) TReplicantTray* replicantTray = barApp->BarView()->fReplicantTray; fClockSeconds->SetValue(replicantTray->ShowingSeconds()); - fClockEuropeanDate->SetValue(replicantTray->ShowingEuroDate()); fClockFullDate->SetValue(replicantTray->ShowingFullDate()); bool showingClock = barApp->BarView()->ShowingClock(); fClockSeconds->SetEnabled(showingClock); - fClockEuropeanDate->SetEnabled(showingClock); fClockFullDate->SetEnabled(replicantTray->CanShowFullDate()); fWindowAlwaysOnTop->SetValue(appSettings->alwaysOnTop); @@ -142,7 +138,6 @@ PreferencesWindow::PreferencesWindow(BRect frame) fAppsExpandNew->SetTarget(be_app); fClockSeconds->SetTarget(replicantTray); - fClockEuropeanDate->SetTarget(replicantTray); fClockFullDate->SetTarget(replicantTray); fWindowAlwaysOnTop->SetTarget(be_app); @@ -199,7 +194,6 @@ PreferencesWindow::PreferencesWindow(BRect frame) view = BLayoutBuilder::Group<>() .AddGroup(B_VERTICAL, 1) .Add(fClockSeconds) - .Add(fClockEuropeanDate) .Add(fClockFullDate) .AddGlue() .SetInsets(10, 10, 10, 10) diff --git a/src/apps/deskbar/PreferencesWindow.h b/src/apps/deskbar/PreferencesWindow.h index aee5775b89..a40179f403 100644 --- a/src/apps/deskbar/PreferencesWindow.h +++ b/src/apps/deskbar/PreferencesWindow.h @@ -53,7 +53,6 @@ private: BCheckBox* fAppsExpandNew; BCheckBox* fClockSeconds; - BCheckBox* fClockEuropeanDate; BCheckBox* fClockFullDate; BCheckBox* fWindowAlwaysOnTop; diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp index bedf826512..1acd0312d5 100644 --- a/src/apps/deskbar/StatusView.cpp +++ b/src/apps/deskbar/StatusView.cpp @@ -199,7 +199,6 @@ TReplicantTray::RememberClockSettings() desk_settings* settings = ((TBarApp*)be_app)->Settings(); settings->timeShowSeconds = fClock->ShowingSeconds(); - settings->timeShowEuro = fClock->ShowingEuroDate(); settings->timeFullDate = fClock->ShowingFullDate(); } } @@ -214,15 +213,6 @@ TReplicantTray::ShowingSeconds() } -bool -TReplicantTray::ShowingEuroDate() -{ - if (fClock) - return fClock->ShowingEuroDate(); - return false; -} - - bool TReplicantTray::ShowingFullDate() { @@ -252,7 +242,7 @@ TReplicantTray::DealWithClock(bool showClock) fClock = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0, settings->timeShowSeconds, settings->timeFullDate, - settings->timeShowEuro, false); + false); AddChild(fClock); fClock->MoveTo(Bounds().right - fClock->Bounds().Width() - 1, 2); @@ -375,7 +365,6 @@ TReplicantTray::MessageReceived(BMessage* message) break; case kShowSeconds: - case kEuroDate: case kFullDate: if (fClock != NULL) Window()->PostMessage(message, fClock); diff --git a/src/apps/deskbar/StatusView.h b/src/apps/deskbar/StatusView.h index 78303a274a..a67bdbe2cb 100644 --- a/src/apps/deskbar/StatusView.h +++ b/src/apps/deskbar/StatusView.h @@ -113,7 +113,6 @@ public: bool ShowingSeconds(void); bool ShowingMiltime(void); - bool ShowingEuroDate(void); bool ShowingFullDate(void); bool CanShowFullDate(void); diff --git a/src/apps/deskbar/TimeView.cpp b/src/apps/deskbar/TimeView.cpp index 151a90a2b1..7541d997e0 100644 --- a/src/apps/deskbar/TimeView.cpp +++ b/src/apps/deskbar/TimeView.cpp @@ -52,11 +52,6 @@ All rights reserved. #include "CalendarMenuWindow.h" -const char* kShortDateFormat = "%m/%d/%y"; -const char* kShortEuroDateFormat = "%d/%m/%y"; -const char* kLongDateFormat = "%a, %B %d, %Y"; -const char* kLongEuroDateFormat = "%a, %d %B, %Y"; - static const char* const kMinString = "99:99 AM"; static const float kHMargin = 2.0; @@ -74,7 +69,7 @@ enum { #define B_TRANSLATE_CONTEXT "TimeView" TTimeView::TTimeView(float maxWidth, float height, bool showSeconds, - bool fullDate, bool euroDate, bool) + bool fullDate, bool) : BView(BRect(-100,-100,-90,-90), "_deskbar_tv_", B_FOLLOW_RIGHT | B_FOLLOW_TOP, @@ -84,7 +79,6 @@ TTimeView::TTimeView(float maxWidth, float height, bool showSeconds, fShowSeconds(showSeconds), fFullDate(fullDate), fCanShowFullDate(false), - fEuroDate(euroDate), fMaxWidth(maxWidth), fHeight(height), fOrientation(true), @@ -108,7 +102,6 @@ TTimeView::TTimeView(BMessage* data) fTime = fLastTime = time(NULL); data->FindBool("seconds", &fShowSeconds); data->FindBool("fulldate", &fFullDate); - data->FindBool("eurodate", &fEuroDate); data->FindBool("interval", &fInterval); fShowingDate = false; @@ -140,7 +133,6 @@ TTimeView::Archive(BMessage* data, bool deep) const BView::Archive(data, deep); data->AddBool("seconds", fShowSeconds); data->AddBool("fulldate", fFullDate); - data->AddBool("eurodate", fEuroDate); data->AddBool("interval", fInterval); data->AddInt32("deskbar:private_align", B_ALIGN_RIGHT); @@ -223,10 +215,6 @@ TTimeView::MessageReceived(BMessage* message) ShowSeconds(!ShowingSeconds()); break; - case kEuroDate: - ShowEuroDate(!ShowingEuroDate()); - break; - case kChangeClock: // launch the time prefs app be_roster->Launch("application/x-vnd.Haiku-Time"); @@ -279,7 +267,7 @@ TTimeView::ShowCalendar(BPoint where) if (where.y >= BScreen().Frame().bottom) where.y -= (Bounds().Height() + 4.0); - CalendarMenuWindow* window = new CalendarMenuWindow(where, fEuroDate); + CalendarMenuWindow* window = new CalendarMenuWindow(where); fCalendarWindow = BMessenger(window); window->Show(); @@ -329,14 +317,8 @@ void TTimeView::GetCurrentDate() { char tmp[64]; - tm time = *localtime(&fTime); - if (fFullDate && CanShowFullDate()) - strftime(tmp, 64, fEuroDate ? kLongEuroDateFormat : kLongDateFormat, - &time); - else - strftime(tmp, 64, fEuroDate ? kShortEuroDateFormat : kShortDateFormat, - &time); + fHere->FormatDate(tmp, 64, fTime, fFullDate && CanShowFullDate()); // remove leading 0 from date when month is less than 10 (MM/DD/YY) // or remove leading 0 from date when day is less than 10 (DD/MM/YY) @@ -466,14 +448,6 @@ TTimeView::ShowFullDate(bool on) } -void -TTimeView::ShowEuroDate(bool on) -{ - fEuroDate = on; - Update(); -} - - void TTimeView::AllowFullDate(bool allow) { diff --git a/src/apps/deskbar/TimeView.h b/src/apps/deskbar/TimeView.h index 333eba695a..1190348a1f 100644 --- a/src/apps/deskbar/TimeView.h +++ b/src/apps/deskbar/TimeView.h @@ -42,7 +42,6 @@ All rights reserved. const uint32 kShowSeconds = 'ShSc'; const uint32 kFullDate = 'FDat'; -const uint32 kEuroDate = 'EDat'; class BCountry; class BMessageRunner; @@ -55,8 +54,7 @@ class _EXPORT TTimeView; class TTimeView : public BView { public: TTimeView(float maxWidth, float height, bool showSeconds = false, - bool fullDate = false, bool euroDate = false, - bool showInterval = false); + bool fullDate = false, bool showInterval = false); TTimeView(BMessage* data); ~TTimeView(); @@ -83,8 +81,6 @@ class TTimeView : public BView { void ShowFullDate(bool); bool CanShowFullDate() const { return fCanShowFullDate; } void AllowFullDate(bool); - bool ShowingEuroDate() {return fEuroDate; } - void ShowEuroDate(bool); void ShowCalendar(BPoint where); void StartLongClickNotifier(BPoint where); void StopLongClickNotifier(); @@ -122,7 +118,6 @@ class TTimeView : public BView { bool fShowingDate; bool fFullDate; bool fCanShowFullDate; - bool fEuroDate; float fMaxWidth; float fHeight; diff --git a/src/kits/locale/Country.cpp b/src/kits/locale/Country.cpp index 7d6bae1984..6eaf94194e 100644 --- a/src/kits/locale/Country.cpp +++ b/src/kits/locale/Country.cpp @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -24,6 +25,10 @@ #include +using BPrivate::B_WEEK_START_MONDAY; +using BPrivate::B_WEEK_START_SUNDAY; + + const char* gStrings[] = { // date/time format "", @@ -231,6 +236,23 @@ BCountry::TimeFormat(BString& format, bool longFormat) const } +int +BCountry::StartOfWeek() +{ + UErrorCode err = U_ZERO_ERROR; + Calendar* c = Calendar::createInstance(*fICULocale, err); + + if (err == U_ZERO_ERROR && c->getFirstDayOfWeek(err) == UCAL_SUNDAY) { + delete c; + return B_WEEK_START_SUNDAY; + } else { + delete c; + // Might be another day, but BeAPI will not handle it + return B_WEEK_START_MONDAY; + } +} + + // TODO find how to get it from ICU (setting it is ok, we use the pattern-string // for that) // Or remove this function ?