2010-08-02 00:28:19 +04:00
|
|
|
/*
|
2006-05-13 18:11:49 +04:00
|
|
|
* Copyright 2004, Jérôme Duval, jerome.duval@free.fr.
|
2004-12-14 19:28:23 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
|
2006-10-31 03:50:47 +03:00
|
|
|
|
2004-12-14 19:28:23 +03:00
|
|
|
#include <Alert.h>
|
|
|
|
#include <Application.h>
|
2010-06-29 13:34:42 +04:00
|
|
|
#include <Catalog.h>
|
2004-12-14 19:28:23 +03:00
|
|
|
#include <FindDirectory.h>
|
2010-06-29 13:34:42 +04:00
|
|
|
#include <Locale.h>
|
2004-12-14 19:28:23 +03:00
|
|
|
#include <MessageRunner.h>
|
|
|
|
#include <Roster.h>
|
|
|
|
#include <String.h>
|
|
|
|
#include <TextView.h>
|
2006-10-31 03:50:47 +03:00
|
|
|
|
2004-12-14 19:28:23 +03:00
|
|
|
#include <stdio.h>
|
2005-11-13 02:27:14 +03:00
|
|
|
#include <stdlib.h>
|
2006-08-03 21:53:43 +04:00
|
|
|
#include <unistd.h>
|
2004-12-14 19:28:23 +03:00
|
|
|
|
2006-10-31 03:50:47 +03:00
|
|
|
|
2012-04-16 23:31:22 +04:00
|
|
|
#undef B_TRANSLATION_CONTEXT
|
|
|
|
#define B_TRANSLATION_CONTEXT "dstcheck"
|
2010-06-29 13:34:42 +04:00
|
|
|
|
|
|
|
|
2004-12-14 19:28:23 +03:00
|
|
|
const uint32 TIMEDALERT_UPDATE = 'taup';
|
|
|
|
|
2006-10-31 03:50:47 +03:00
|
|
|
class TimedAlert : public BAlert {
|
2012-02-26 22:01:25 +04:00
|
|
|
public:
|
|
|
|
TimedAlert(const char *title, const char *text, const char *button1,
|
|
|
|
const char *button2 = NULL, const char *button3 = NULL,
|
|
|
|
button_width width = B_WIDTH_AS_USUAL,
|
|
|
|
alert_type type = B_INFO_ALERT);
|
|
|
|
void MessageReceived(BMessage *);
|
|
|
|
void Show();
|
|
|
|
|
|
|
|
static void GetLabel(BString &string);
|
|
|
|
|
|
|
|
private:
|
|
|
|
BMessageRunner *fRunner;
|
2004-12-14 19:28:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TimedAlert::TimedAlert(const char *title, const char *text, const char *button1,
|
2006-10-31 03:50:47 +03:00
|
|
|
const char *button2, const char *button3,
|
|
|
|
button_width width, alert_type type)
|
2004-12-14 19:28:23 +03:00
|
|
|
: BAlert(title, text, button1, button2, button3, width, type),
|
|
|
|
fRunner(NULL)
|
|
|
|
{
|
2011-03-08 02:01:45 +03:00
|
|
|
SetShortcut(0, B_ESCAPE);
|
2004-12-14 19:28:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TimedAlert::Show()
|
|
|
|
{
|
2012-02-26 22:01:25 +04:00
|
|
|
fRunner
|
|
|
|
= new BMessageRunner(this, new BMessage(TIMEDALERT_UPDATE), 60000000);
|
2009-03-29 12:16:26 +04:00
|
|
|
SetFeel(B_FLOATING_ALL_WINDOW_FEEL);
|
2004-12-14 19:28:23 +03:00
|
|
|
BAlert::Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-02 00:28:19 +04:00
|
|
|
void
|
2004-12-14 19:28:23 +03:00
|
|
|
TimedAlert::MessageReceived(BMessage *msg)
|
|
|
|
{
|
|
|
|
if (msg->what == TIMEDALERT_UPDATE) {
|
|
|
|
BString string;
|
2010-08-02 00:28:19 +04:00
|
|
|
GetLabel(string);
|
2006-10-31 03:50:47 +03:00
|
|
|
TextView()->SetText(string.String());
|
2012-02-26 22:01:25 +04:00
|
|
|
} else {
|
2004-12-14 19:28:23 +03:00
|
|
|
BAlert::MessageReceived(msg);
|
2012-02-26 22:01:25 +04:00
|
|
|
}
|
2004-12-14 19:28:23 +03:00
|
|
|
}
|
|
|
|
|
2006-10-31 03:50:47 +03:00
|
|
|
|
2004-12-14 19:28:23 +03:00
|
|
|
void
|
|
|
|
TimedAlert::GetLabel(BString &string)
|
|
|
|
{
|
2010-06-29 13:34:42 +04:00
|
|
|
string = B_TRANSLATE("Attention!\n\nBecause of the switch from daylight "
|
2010-07-29 21:25:40 +04:00
|
|
|
"saving time, your computer's clock may be an hour off.\n"
|
|
|
|
"Your computer thinks it is");
|
2006-10-31 03:50:47 +03:00
|
|
|
|
2004-12-14 19:28:23 +03:00
|
|
|
time_t t;
|
|
|
|
struct tm tm;
|
|
|
|
char timestring[15];
|
|
|
|
time(&t);
|
|
|
|
localtime_r(&t, &tm);
|
2010-08-02 00:28:19 +04:00
|
|
|
|
2010-11-22 16:06:36 +03:00
|
|
|
BLocale::Default()->FormatTime(timestring, 15, t, B_SHORT_TIME_FORMAT);
|
2010-08-02 00:28:19 +04:00
|
|
|
|
2010-07-29 21:25:40 +04:00
|
|
|
string += " ";
|
2004-12-14 19:28:23 +03:00
|
|
|
string += timestring;
|
2006-10-31 03:50:47 +03:00
|
|
|
|
2010-06-29 13:34:42 +04:00
|
|
|
string += B_TRANSLATE(".\n\nIs this the correct time?");
|
2004-12-14 19:28:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-31 03:50:47 +03:00
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
2004-12-14 19:28:23 +03:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
time_t t;
|
|
|
|
struct tm tm;
|
2005-10-26 17:23:43 +04:00
|
|
|
tzset();
|
2004-12-14 19:28:23 +03:00
|
|
|
time(&t);
|
2010-08-02 00:28:19 +04:00
|
|
|
localtime_r(&t, &tm);
|
2004-12-14 19:28:23 +03:00
|
|
|
|
2010-08-02 00:28:19 +04:00
|
|
|
char path[B_PATH_NAME_LENGTH];
|
2012-02-26 22:01:25 +04:00
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, true, path,
|
|
|
|
B_PATH_NAME_LENGTH) != B_OK) {
|
2004-12-14 19:28:23 +03:00
|
|
|
fprintf(stderr, "%s: can't find settings directory\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat(path, "/time_dststatus");
|
|
|
|
bool dst = false;
|
2007-12-11 23:20:45 +03:00
|
|
|
int fd = open(path, O_RDWR | O_EXCL | O_CREAT, S_IRUSR | S_IWUSR);
|
2004-12-14 19:28:23 +03:00
|
|
|
if (fd < 0) {
|
|
|
|
fd = open(path, O_RDWR);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("couldn't open dst status settings file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char dst_byte;
|
|
|
|
read(fd, &dst_byte, 1);
|
|
|
|
|
|
|
|
dst = dst_byte == '1';
|
|
|
|
} else {
|
|
|
|
dst = tm.tm_isdst;
|
|
|
|
}
|
|
|
|
|
2010-06-29 13:34:42 +04:00
|
|
|
if (dst != tm.tm_isdst || argc > 1) {
|
|
|
|
BApplication app("application/x-vnd.Haiku-cmd-dstconfig");
|
2004-12-14 19:28:23 +03:00
|
|
|
|
|
|
|
BString string;
|
|
|
|
TimedAlert::GetLabel(string);
|
|
|
|
|
2010-06-29 13:34:42 +04:00
|
|
|
int32 index = (new TimedAlert("timedAlert", string.String(),
|
2011-03-13 22:28:24 +03:00
|
|
|
B_TRANSLATE("Ask me later"), B_TRANSLATE("Use this time"),
|
|
|
|
B_TRANSLATE("Manually adjust time" B_UTF8_ELLIPSIS)))->Go();
|
2004-12-14 19:28:23 +03:00
|
|
|
if (index == 0)
|
|
|
|
exit(0);
|
|
|
|
|
2011-03-13 22:28:24 +03:00
|
|
|
if (index == 2)
|
|
|
|
be_roster->Launch("application/x-vnd.Haiku-Time");
|
2004-12-14 19:28:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
char dst_byte = tm.tm_isdst ? '1' : '0';
|
|
|
|
write(fd, &dst_byte, 1);
|
|
|
|
close(fd);
|
2006-10-31 03:50:47 +03:00
|
|
|
|
|
|
|
return 0;
|
2004-12-14 19:28:23 +03:00
|
|
|
}
|