xref: /haiku/src/preferences/time/Time.cpp (revision 922e7ba1f3228e6f28db69b0ded8f86eb32dea17)
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 <stdio.h>
16 #include <unistd.h>
17 
18 #include <Alert.h>
19 #include <Catalog.h>
20 
21 #include "NetworkTimeView.h"
22 #include "TimeWindow.h"
23 
24 
25 #undef B_TRANSLATE_CONTEXT
26 #define B_TRANSLATE_CONTEXT "Time"
27 
28 
29 const char* kAppSignature = "application/x-vnd.Haiku-Time";
30 
31 
32 TimeApplication::TimeApplication()
33 	:
34 	BApplication(kAppSignature),
35 	fWindow(NULL)
36 {
37 	fWindow = new TTimeWindow();
38 }
39 
40 
41 TimeApplication::~TimeApplication()
42 {
43 }
44 
45 
46 void
47 TimeApplication::ReadyToRun()
48 {
49 	fWindow->Show();
50 }
51 
52 
53 void
54 TimeApplication::AboutRequested()
55 {
56 	BAlert* alert = new BAlert(B_TRANSLATE("about"),
57 		B_TRANSLATE(
58 		"Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t"
59 		"Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2008, Haiku."),
60 		B_TRANSLATE("OK"));
61 	alert->Go();
62 }
63 
64 
65 int
66 main(int argc, char** argv)
67 {
68 	if (argc > 1) {
69 		if (strcmp(argv[1], "--update") != 0)
70 			return 0;
71 
72 		Settings settings;
73 		if (!settings.GetSynchronizeAtBoot())
74 			return 0;
75 
76 		const char* errorString = NULL;
77 		int32 errorCode = 0;
78 		if (update_time(settings, &errorString, &errorCode) == B_OK)
79 			printf("Synchronization successful\r\n");
80 		else if (errorCode != 0)
81 			printf("The following error occured "
82 				"while synchronizing:\r\n%s: %s\r\n",
83 				errorString, strerror(errorCode));
84 		else
85 			printf("The following error occured "
86 				"while synchronizing:\r\n%s\r\n",
87 				errorString);
88 	}
89 	else {
90 		TimeApplication app;
91 		setuid(0);
92 		app.Run();
93 	}
94 
95 	return 0;
96 }
97 
98