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		BAboutWindow*		fAboutWindow;
40};
41
42
43//	#pragma mark -
44
45
46LocalePreflet::LocalePreflet()
47	:
48	BApplication(kSignature),
49	fLocaleWindow(new LocaleWindow()),
50	fAboutWindow(NULL)
51{
52	fLocaleWindow->Show();
53}
54
55
56LocalePreflet::~LocalePreflet()
57{
58	// replicant deleted, destroy the about window
59	if (fAboutWindow != NULL)
60		fAboutWindow->Quit();
61}
62
63
64void
65LocalePreflet::MessageReceived(BMessage* message)
66{
67	switch (message->what) {
68		case B_LOCALE_CHANGED:
69			BLocaleRoster::Default()->Refresh();
70			fLocaleWindow->PostMessage(message);
71			break;
72
73		case kMsgRestartTrackerAndDeskbar:
74			if (message->FindInt32("which") == 1) {
75				_RestartApp("application/x-vnd.Be-TRAK");
76				_RestartApp("application/x-vnd.Be-TSKB");
77			}
78			break;
79
80		case B_ABOUT_REQUESTED:
81			if (fAboutWindow == NULL) {
82				const char* authors[] = {
83					"Axel Dörfler",
84					"Adrien Destugues",
85					"Oliver Tappe",
86					NULL
87				};
88
89				fAboutWindow = new BAboutWindow(kAppName, kSignature);
90				fAboutWindow->AddCopyright(2005, "Haiku, Inc.");
91				fAboutWindow->AddAuthors(authors);
92				fAboutWindow->Show();
93			} else if (fAboutWindow->IsHidden())
94				fAboutWindow->Show();
95			else
96				fAboutWindow->Activate();
97
98			break;
99
100		default:
101			BApplication::MessageReceived(message);
102			break;
103	}
104}
105
106
107status_t
108LocalePreflet::_RestartApp(const char* signature) const
109{
110	app_info info;
111	status_t status = be_roster->GetAppInfo(signature, &info);
112	if (status != B_OK)
113		return status;
114
115	BMessenger application(signature);
116	status = application.SendMessage(B_QUIT_REQUESTED);
117	if (status != B_OK)
118		return status;
119
120	status_t exit;
121	wait_for_thread(info.thread, &exit);
122
123	return be_roster->Launch(signature);
124}
125
126
127//	#pragma mark -
128
129
130int
131main(int argc, char** argv)
132{
133	LocalePreflet app;
134	app.Run();
135	return 0;
136}
137
138