Patch by Jorma Karvonnen, mostly rewritten by me :

* dstcheck is now localized
 * it also localize the date using the locale kit instead of strftime
I also added a way to force the message to display, because it helps testing a lot. Run "dstcheck force" for that.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37297 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues
2010-06-29 09:34:42 +00:00
parent b3df2c9a87
commit 69b8708d75
+27 -10
View File
@@ -6,7 +6,10 @@
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Application.h>
#include <Catalog.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Locale.h>
#include <LocaleRoster.h>
#include <MessageRunner.h> #include <MessageRunner.h>
#include <Roster.h> #include <Roster.h>
#include <String.h> #include <String.h>
@@ -17,6 +20,10 @@
#include <unistd.h> #include <unistd.h>
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "dstcheck"
const uint32 TIMEDALERT_UPDATE = 'taup'; const uint32 TIMEDALERT_UPDATE = 'taup';
class TimedAlert : public BAlert { class TimedAlert : public BAlert {
@@ -67,19 +74,24 @@ TimedAlert::MessageReceived(BMessage *msg)
void void
TimedAlert::GetLabel(BString &string) TimedAlert::GetLabel(BString &string)
{ {
string = "Attention!\n\nBecause of the switch from daylight saving time, " string = B_TRANSLATE("Attention!\n\nBecause of the switch from daylight "
"your computer's clock may be an hour off. Currently, your computer " "saving time, your computer's clock may be an hour off. Currently, "
"thinks it is "; "your computer thinks it is ");
time_t t; time_t t;
struct tm tm; struct tm tm;
char timestring[15]; char timestring[15];
time(&t); time(&t);
localtime_r(&t, &tm); localtime_r(&t, &tm);
strftime(timestring, 15, "%I:%M %p", &tm);
BCountry* here;
be_locale_roster->GetDefaultCountry(&here);
here->FormatTime(timestring, 15, t, false);
string += timestring; string += timestring;
string += ".\n\nIs this the correct time?"; string += B_TRANSLATE(".\n\nIs this the correct time?");
} }
@@ -89,6 +101,7 @@ TimedAlert::GetLabel(BString &string)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
BCatalog fCatalog;
time_t t; time_t t;
struct tm tm; struct tm tm;
tzset(); tzset();
@@ -121,20 +134,24 @@ main(int argc, char **argv)
dst = tm.tm_isdst; dst = tm.tm_isdst;
} }
if (dst != tm.tm_isdst) { if (dst != tm.tm_isdst || argc > 1) {
BApplication app("application/x-vnd.Haiku-cmd-dstconfig"); BApplication app("application/x-vnd.Haiku-cmd-dstconfig");
be_locale->GetAppCatalog(&fCatalog);
BString string; BString string;
TimedAlert::GetLabel(string); TimedAlert::GetLabel(string);
int32 index = (new TimedAlert("timedAlert", string.String(), "Ask me later", "Yes", "No"))->Go(); int32 index = (new TimedAlert("timedAlert", string.String(),
B_TRANSLATE("Ask me later"), B_TRANSLATE("Yes"),
B_TRANSLATE("No")))->Go();
if (index == 0) if (index == 0)
exit(0); exit(0);
if (index == 2) { if (index == 2) {
index = (new BAlert("dstcheck", index = (new BAlert("dstcheck",
"Would you like to set the clock using the Time and\nDate preference utility?", B_TRANSLATE("Would you like to set the clock using the Time and"
"No", "Yes"))->Go(); "\nDate preference utility?"),
B_TRANSLATE("No"), B_TRANSLATE("Yes")))->Go();
if (index == 1) if (index == 1)
be_roster->Launch("application/x-vnd.Haiku-Time"); be_roster->Launch("application/x-vnd.Haiku-Time");