1/*
2 * Copyright 2005, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
3 * Copyright 2010, Adrien Destugues <pulkomandy@pulkomandy.ath.cx>. All rightts reserved.
4 * Distributed under the terms of the MIT License.
5 */
6
7
8#include <AboutWindow.h>
9#include <Alert.h>
10#include <Application.h>
11#include <Catalog.h>
12#include <Locale.h>
13#include <Roster.h>
14#include <TextView.h>
15
16#include "LocalePreflet.h"
17#include "LocaleWindow.h"
18
19
20#undef B_TRANSLATION_CONTEXT
21#define B_TRANSLATION_CONTEXT "Locale Preflet"
22
23
24const char* kAppName = B_TRANSLATE("Locale");
25const char* kSignature = "application/x-vnd.Haiku-Locale";
26
27
28class LocalePreflet : public BApplication {
29	public:
30							LocalePreflet();
31		virtual				~LocalePreflet();
32
33		virtual	void		MessageReceived(BMessage* message);
34
35private:
36		status_t			_RestartApp(const char* signature) const;
37
38		LocaleWindow*		fLocaleWindow;
39};
40
41
42//	#pragma mark -
43
44
45LocalePreflet::LocalePreflet()
46	:
47	BApplication(kSignature),
48	fLocaleWindow(new LocaleWindow())
49{
50	fLocaleWindow->Show();
51}
52
53
54LocalePreflet::~LocalePreflet()
55{
56}
57
58
59void
60LocalePreflet::MessageReceived(BMessage* message)
61{
62	switch (message->what) {
63		case B_LOCALE_CHANGED:
64			BLocaleRoster::Default()->Refresh();
65			fLocaleWindow->PostMessage(message);
66			break;
67
68		case kMsgRestartTrackerAndDeskbar:
69			if (message->FindInt32("which") == 1) {
70				_RestartApp("application/x-vnd.Be-TRAK");
71				_RestartApp("application/x-vnd.Be-TSKB");
72			}
73			break;
74
75		case B_ABOUT_REQUESTED:
76		{
77			BAboutWindow* window;
78
79			const char* authors[] = {
80				"Axel D��rfler",
81				"Adrien Destugues",
82				"Oliver Tappe",
83				NULL
84			};
85
86			window = new BAboutWindow(kAppName, kSignature);
87			window->AddCopyright(2005, "Haiku, Inc.");
88			window->AddAuthors(authors);
89
90			window->Show();
91
92			break;
93		}
94
95		default:
96			BApplication::MessageReceived(message);
97			break;
98	}
99}
100
101
102status_t
103LocalePreflet::_RestartApp(const char* signature) const
104{
105	app_info info;
106	status_t status = be_roster->GetAppInfo(signature, &info);
107	if (status != B_OK)
108		return status;
109
110	BMessenger application(signature);
111	status = application.SendMessage(B_QUIT_REQUESTED);
112	if (status != B_OK)
113		return status;
114
115	status_t exit;
116	wait_for_thread(info.thread, &exit);
117
118	return be_roster->Launch(signature);
119}
120
121
122//	#pragma mark -
123
124
125int
126main(int argc, char** argv)
127{
128	LocalePreflet app;
129	app.Run();
130	return 0;
131}
132
133