2 * Copyright 2004, Jérôme Duval, jerome.duval@free.fr.
3 * Distributed under the terms of the MIT License.
8 #include <Application.h>
10 #include <FindDirectory.h>
12 #include <MessageRunner.h>
16 #include <TimeFormat.h>
23 #undef B_TRANSLATION_CONTEXT
24 #define B_TRANSLATION_CONTEXT "dstcheck"
27 const uint32 TIMEDALERT_UPDATE
= 'taup';
29 class TimedAlert
: public BAlert
{
31 TimedAlert(const char *title
, const char *text
, const char *button1
,
32 const char *button2
= NULL
, const char *button3
= NULL
,
33 button_width width
= B_WIDTH_AS_USUAL
,
34 alert_type type
= B_INFO_ALERT
);
35 void MessageReceived(BMessage
*);
38 static void GetLabel(BString
&string
);
41 BMessageRunner
*fRunner
;
45 TimedAlert::TimedAlert(const char *title
, const char *text
, const char *button1
,
46 const char *button2
, const char *button3
,
47 button_width width
, alert_type type
)
48 : BAlert(title
, text
, button1
, button2
, button3
, width
, type
),
51 SetShortcut(0, B_ESCAPE
);
59 = new BMessageRunner(this, new BMessage(TIMEDALERT_UPDATE
), 60000000);
60 SetFeel(B_FLOATING_ALL_WINDOW_FEEL
);
66 TimedAlert::MessageReceived(BMessage
*msg
)
68 if (msg
->what
== TIMEDALERT_UPDATE
) {
71 TextView()->SetText(string
.String());
73 BAlert::MessageReceived(msg
);
79 TimedAlert::GetLabel(BString
&string
)
81 string
= B_TRANSLATE("Attention!\n\nBecause of the switch from daylight "
82 "saving time, your computer's clock may be an hour off.\n"
83 "Your computer thinks it is %current time%.\n\nIs this the correct "
92 BTimeFormat().Format(timestring
, 15, t
, B_SHORT_TIME_FORMAT
);
94 string
.ReplaceFirst("%current time%", timestring
);
102 main(int argc
, char **argv
)
108 localtime_r(&t
, &tm
);
110 char path
[B_PATH_NAME_LENGTH
];
111 if (find_directory(B_USER_SETTINGS_DIRECTORY
, -1, true, path
,
112 B_PATH_NAME_LENGTH
) != B_OK
) {
113 fprintf(stderr
, "%s: can't find settings directory\n", argv
[0]);
117 strcat(path
, "/time_dststatus");
119 int fd
= open(path
, O_RDWR
| O_EXCL
| O_CREAT
, S_IRUSR
| S_IWUSR
);
121 fd
= open(path
, O_RDWR
);
123 perror("couldn't open dst status settings file");
128 read(fd
, &dst_byte
, 1);
130 dst
= dst_byte
== '1';
135 if (dst
!= tm
.tm_isdst
|| argc
> 1) {
136 BApplication
app("application/x-vnd.Haiku-cmd-dstconfig");
139 TimedAlert::GetLabel(string
);
141 int32 index
= (new TimedAlert("timedAlert", string
.String(),
142 B_TRANSLATE("Keep this time"), B_TRANSLATE("Ask me later"),
143 B_TRANSLATE("Manually adjust time" B_UTF8_ELLIPSIS
)))->Go();
148 be_roster
->Launch("application/x-vnd.Haiku-Time");
151 lseek(fd
, 0, SEEK_SET
);
152 char dst_byte
= tm
.tm_isdst
? '1' : '0';
153 write(fd
, &dst_byte
, 1);