Fix FreeBSD build.
[haiku.git] / src / preferences / time / Time.cpp
blobff32eeefe83b852b68e5529b0ddc88f8477f5004
1 /*
2 * Copyright 2002-2011, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Andrew McCall <mccall@digitalparadise.co.uk>
7 * Mike Berg <mike@berg-net.us>
8 * Julun <host.haiku@gmx.de>
9 * Hamish Morrison <hamish@lavabit.com>
13 #include "Time.h"
15 #include <locale.h>
16 #include <stdio.h>
17 #include <unistd.h>
19 #include <Alert.h>
20 #include <Catalog.h>
21 #include <LocaleRoster.h>
23 #include "NetworkTimeView.h"
24 #include "TimeMessages.h"
25 #include "TimeWindow.h"
28 #undef B_TRANSLATION_CONTEXT
29 #define B_TRANSLATION_CONTEXT "Time"
32 const char* kAppSignature = "application/x-vnd.Haiku-Time";
35 TimeApplication::TimeApplication()
37 BApplication(kAppSignature),
38 fWindow(NULL)
40 fWindow = new TTimeWindow();
44 TimeApplication::~TimeApplication()
49 void
50 TimeApplication::ReadyToRun()
52 fWindow->Show();
56 void
57 TimeApplication::AboutRequested()
59 BAlert* alert = new BAlert(B_TRANSLATE("about"),
60 B_TRANSLATE(
61 "Time & Date, written by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t"
62 "Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2012, Haiku."),
63 B_TRANSLATE("OK"));
64 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
65 alert->Go();
69 void
70 TimeApplication::MessageReceived(BMessage* message)
72 switch (message->what) {
73 case kSelectClockTab:
74 case kShowHideTime:
75 case B_LOCALE_CHANGED:
76 fWindow->PostMessage(message);
77 break;
79 default:
80 BApplication::MessageReceived(message);
81 break;
86 int
87 main(int argc, char** argv)
89 if (argc > 1) {
90 if (strcmp(argv[1], "--update") != 0)
91 return 0;
93 Settings settings;
94 if (!settings.GetSynchronizeAtBoot())
95 return 0;
97 const char* errorString = NULL;
98 int32 errorCode = 0;
99 if (update_time(settings, &errorString, &errorCode) == B_OK) {
100 printf("Synchronization successful\r\n");
101 } else if (errorCode != 0) {
102 printf("The following error occured "
103 "while synchronizing:\r\n%s: %s\r\n",
104 errorString, strerror(errorCode));
105 } else {
106 printf("The following error occured while synchronizing:\r\n%s\r\n",
107 errorString);
109 } else {
110 setlocale(LC_ALL, "");
112 TimeApplication app;
113 setuid(0);
114 app.Run();
117 return 0;