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