xref: /haiku/src/preferences/time/Time.cpp (revision 3d4afef9cba2f328e238089d4609d00d4b1524f3)
1 /*
2  * Copyright 2002-2021, 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  *		Panagiotis Vasilopoulos <hello@alwayslivid.com>
11  */
12 
13 
14 #include "Time.h"
15 
16 #include <locale.h>
17 #include <stdio.h>
18 #include <unistd.h>
19 
20 #include <AboutWindow.h>
21 #include <Alert.h>
22 #include <Catalog.h>
23 #include <Locale.h>
24 #include <LocaleRoster.h>
25 
26 #include "NetworkTimeView.h"
27 #include "TimeMessages.h"
28 #include "TimeWindow.h"
29 
30 
31 #undef B_TRANSLATION_CONTEXT
32 #define B_TRANSLATION_CONTEXT "Time"
33 
34 
35 const char* kAppSignature = "application/x-vnd.Haiku-Time";
36 
37 
38 TimeApplication::TimeApplication()
39 	:
40 	BApplication(kAppSignature),
41 	fWindow(NULL)
42 {
43 	fWindow = new TTimeWindow();
44 }
45 
46 
47 TimeApplication::~TimeApplication()
48 {
49 }
50 
51 
52 void
53 TimeApplication::ReadyToRun()
54 {
55 	fWindow->Show();
56 }
57 
58 
59 void
60 TimeApplication::AboutRequested()
61 {
62 	BAboutWindow* window = new BAboutWindow(B_TRANSLATE_SYSTEM_NAME(
63 		"Time & Date"), kAppSignature);
64 
65 	const char* authors[] = {
66 		"Mike Berg",
67 		"Andrew Edward McCall",
68 		"Hamish Morrison",
69 		"Philippe Saint-Pierre",
70 		"Panagiotis Vasilopoulos",
71 		"Julun",
72 		NULL
73 	};
74 
75 	window->AddCopyright(2021, "Haiku, Inc.");
76 	window->AddAuthors(authors);
77 
78 	window->Show();
79 }
80 
81 
82 void
83 TimeApplication::MessageReceived(BMessage* message)
84 {
85 	switch (message->what) {
86 		case kSelectClockTab:
87 		case kShowHideTime:
88 		case B_LOCALE_CHANGED:
89 			fWindow->PostMessage(message);
90 			break;
91 
92 		default:
93 			BApplication::MessageReceived(message);
94 			break;
95 	}
96 }
97 
98 
99 int
100 main(int argc, char** argv)
101 {
102 	if (argc > 1) {
103 		if (strcmp(argv[1], "--update") != 0)
104 			return 0;
105 
106 		Settings settings;
107 		const char* errorString = NULL;
108 		int32 errorCode = 0;
109 		if (update_time(settings, &errorString, &errorCode) == B_OK) {
110 			printf("Synchronization successful\n");
111 		} else if (errorCode != 0) {
112 			printf("The following error occured "
113 					"while synchronizing:\n%s: %s\n",
114 				errorString, strerror(errorCode));
115 		} else {
116 			printf("The following error occured while synchronizing:\n%s\n",
117 				errorString);
118 		}
119 	} else {
120 		setlocale(LC_ALL, "");
121 
122 		TimeApplication app;
123 		setuid(0);
124 		app.Run();
125 	}
126 
127 	return 0;
128 }
129 
130