xref: /haiku/src/preferences/time/Time.cpp (revision 002f37b0cca92e4cf72857c72ac95db5a8b09615)
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 
22 #include "NetworkTimeView.h"
23 #include "TimeMessages.h"
24 #include "TimeWindow.h"
25 
26 
27 #undef B_TRANSLATION_CONTEXT
28 #define B_TRANSLATION_CONTEXT "Time"
29 
30 
31 const char* kAppSignature = "application/x-vnd.Haiku-Time";
32 
33 
34 TimeApplication::TimeApplication()
35 	:
36 	BApplication(kAppSignature),
37 	fWindow(NULL)
38 {
39 	fWindow = new TTimeWindow();
40 }
41 
42 
43 TimeApplication::~TimeApplication()
44 {
45 }
46 
47 
48 void
49 TimeApplication::ReadyToRun()
50 {
51 	fWindow->Show();
52 }
53 
54 
55 void
56 TimeApplication::AboutRequested()
57 {
58 	BAlert* alert = new BAlert(B_TRANSLATE("about"),
59 		B_TRANSLATE(
60 		"Time & Date, written by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t"
61 		"Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2012, Haiku."),
62 		B_TRANSLATE("OK"));
63 	alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
64 	alert->Go();
65 }
66 
67 
68 void
69 TimeApplication::MessageReceived(BMessage* message)
70 {
71 	switch (message->what) {
72 		case kSelectClockTab:
73 		case kShowHideTime:
74 			fWindow->PostMessage(message);
75 			break;
76 
77 		default:
78 			BApplication::MessageReceived(message);
79 			break;
80 	}
81 }
82 
83 
84 int
85 main(int argc, char** argv)
86 {
87 	if (argc > 1) {
88 		if (strcmp(argv[1], "--update") != 0)
89 			return 0;
90 
91 		Settings settings;
92 		if (!settings.GetSynchronizeAtBoot())
93 			return 0;
94 
95 		const char* errorString = NULL;
96 		int32 errorCode = 0;
97 		if (update_time(settings, &errorString, &errorCode) == B_OK) {
98 			printf("Synchronization successful\r\n");
99 		} else if (errorCode != 0) {
100 			printf("The following error occured "
101 					"while synchronizing:\r\n%s: %s\r\n",
102 				errorString, strerror(errorCode));
103 		} else {
104 			printf("The following error occured while synchronizing:\r\n%s\r\n",
105 				errorString);
106 		}
107 	} else {
108 		setlocale(LC_ALL, "");
109 
110 		TimeApplication app;
111 		setuid(0);
112 		app.Run();
113 	}
114 
115 	return 0;
116 }
117 
118