xref: /haiku/src/preferences/locale/LocalePreflet.cpp (revision 323b65468e5836bb27a5e373b14027d902349437)
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_TRANSLATE_CONTEXT
21 #define B_TRANSLATE_CONTEXT "Locale Preflet"
22 
23 
24 const char* kSignature = "application/x-vnd.Haiku-Locale";
25 
26 
27 class LocalePreflet : public BApplication {
28 	public:
29 							LocalePreflet();
30 		virtual				~LocalePreflet();
31 
32 		virtual	void		AboutRequested();
33 		virtual	void		MessageReceived(BMessage* message);
34 
35 private:
36 		status_t			_RestartApp(const char* signature) const;
37 
38 		LocaleWindow*		fLocaleWindow;
39 };
40 
41 
42 //	#pragma mark -
43 
44 
45 LocalePreflet::LocalePreflet()
46 	:
47 	BApplication(kSignature)
48 {
49 	fLocaleWindow = new LocaleWindow();
50 
51 	fLocaleWindow->Show();
52 }
53 
54 
55 LocalePreflet::~LocalePreflet()
56 {
57 }
58 
59 
60 void
61 LocalePreflet::AboutRequested()
62 {
63 	const char* authors[] = {
64 		"Axel Dörfler",
65 		"Adrien Destugues",
66 		"Oliver Tappe",
67 		NULL
68 	};
69 	BAboutWindow about(B_TRANSLATE("Locale"), 2005, authors);
70 	about.Show();
71 }
72 
73 
74 void
75 LocalePreflet::MessageReceived(BMessage* message)
76 {
77 	switch (message->what) {
78 		case kMsgRestartTrackerAndDeskbar:
79 			if (message->FindInt32("which") == 1) {
80 				_RestartApp("application/x-vnd.Be-TRAK");
81 				_RestartApp("application/x-vnd.Be-TSKB");
82 			}
83 			break;
84 
85 		default:
86 			BApplication::MessageReceived(message);
87 			break;
88 	}
89 }
90 
91 
92 status_t
93 LocalePreflet::_RestartApp(const char* signature) const
94 {
95 	app_info info;
96 	status_t status = be_roster->GetAppInfo(signature, &info);
97 	if (status != B_OK)
98 		return status;
99 
100 	BMessenger application(signature);
101 	status = application.SendMessage(B_QUIT_REQUESTED);
102 	if (status != B_OK)
103 		return status;
104 
105 	status_t exit;
106 	wait_for_thread(info.thread, &exit);
107 
108 	return be_roster->Launch(signature);
109 }
110 
111 
112 //	#pragma mark -
113 
114 
115 int
116 main(int argc, char** argv)
117 {
118 	LocalePreflet app;
119 	app.Run();
120 	return 0;
121 }
122 
123