xref: /haiku/src/preferences/time/Time.cpp (revision 2897df967633aab846ff4917b53e2af7d1e54eeb)
1 /*
2  * Copyright 2002-2011, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
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>
10  */
11 
12 
13 #include "Time.h"
14 
15 #include <locale.h>
16 #include <stdio.h>
17 #include <unistd.h>
18 
19 #include <Alert.h>
20 #include <Catalog.h>
21 #include <LocaleRoster.h>
22 
23 #include "NetworkTimeView.h"
24 #include "TimeMessages.h"
25 #include "TimeWindow.h"
26 
27 
28 #undef B_TRANSLATION_CONTEXT
29 #define B_TRANSLATION_CONTEXT "Time"
30 
31 
32 const char* kAppSignature = "application/x-vnd.Haiku-Time";
33 
34 
35 TimeApplication::TimeApplication()
36 	:
37 	BApplication(kAppSignature),
38 	fWindow(NULL)
39 {
40 	fWindow = new TTimeWindow();
41 }
42 
43 
44 TimeApplication::~TimeApplication()
45 {
46 }
47 
48 
49 void
50 TimeApplication::ReadyToRun()
51 {
52 	fWindow->Show();
53 }
54 
55 
56 void
57 TimeApplication::AboutRequested()
58 {
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();
66 }
67 
68 
69 void
70 TimeApplication::MessageReceived(BMessage* message)
71 {
72 	switch (message->what) {
73 		case kSelectClockTab:
74 		case kShowHideTime:
75 		case B_LOCALE_CHANGED:
76 			fWindow->PostMessage(message);
77 			break;
78 
79 		default:
80 			BApplication::MessageReceived(message);
81 			break;
82 	}
83 }
84 
85 
86 int
87 main(int argc, char** argv)
88 {
89 	if (argc > 1) {
90 		if (strcmp(argv[1], "--update") != 0)
91 			return 0;
92 
93 		Settings settings;
94 		if (!settings.GetSynchronizeAtBoot())
95 			return 0;
96 
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);
108 		}
109 	} else {
110 		setlocale(LC_ALL, "");
111 
112 		TimeApplication app;
113 		setuid(0);
114 		app.Run();
115 	}
116 
117 	return 0;
118 }
119 
120