xref: /haiku/src/preferences/bluetooth/BluetoothMain.cpp (revision 5629675a326ecf2ff3fd23f154beb525c171048d)
1 /*
2  * Copyright 2008-10, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com>
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #include <stdio.h>
6 
7 #include <Alert.h>
8 #include <Catalog.h>
9 #include <MessageRunner.h>
10 #include <Roster.h>
11 #include <private/interface/AboutWindow.h>
12 
13 #include "BluetoothMain.h"
14 #include "BluetoothWindow.h"
15 #include "defs.h"
16 
17 
18 #undef B_TRANSLATION_CONTEXT
19 #define B_TRANSLATION_CONTEXT "main"
20 
21 BluetoothApplication::BluetoothApplication()
22 	:
23 	BApplication(BLUETOOTH_APP_SIGNATURE)
24 {
25 }
26 
27 
28 void
29 BluetoothApplication::ReadyToRun()
30 {
31 	if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) {
32 		BAlert* alert = new BAlert("Services not running",
33 			B_TRANSLATE("The Bluetooth services are not currently running "
34 				"on this system."),
35 			B_TRANSLATE("Launch now"), B_TRANSLATE("Quit"), "",
36 			B_WIDTH_AS_USUAL, B_WARNING_ALERT);
37 		alert->SetShortcut(1, B_ESCAPE);
38 		int32 choice = alert->Go();
39 
40 		switch (choice) {
41 			case 0:
42 			{
43 				status_t error;
44 				error = be_roster->Launch(BLUETOOTH_SIGNATURE);
45 				printf("kMsgStartServices: %s\n", strerror(error));
46 				// TODO: This is temporal
47 				// BMessage handcheck: use the version of Launch()
48 				// that includes a BMessage	in that message include
49 				// a BMessenger to yourself and the BT server could
50 				// use that messenger to send back a reply indicating
51 				// when it's ready and you could just create window
52 				BMessageRunner::StartSending(be_app_messenger,
53 					new BMessage('Xtmp'), 2 * 1000000, 1);
54 				break;
55 			}
56 			case 1:
57 				PostMessage(B_QUIT_REQUESTED);
58 				break;
59 		}
60 
61 		return;
62 	}
63 
64 	PostMessage(new BMessage('Xtmp'));
65 }
66 
67 
68 void
69 BluetoothApplication::MessageReceived(BMessage* message)
70 {
71 	switch (message->what) {
72 		case kMsgAddToRemoteList:
73 			fWindow->PostMessage(message);
74 			break;
75 
76 		case 'Xtmp':
77 			if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) {
78 				// Give another chance
79 				BMessageRunner::StartSending(be_app_messenger,
80 					new BMessage('Xtmp'), 2 * 1000000, 1);
81 			} else {
82 				fWindow = new BluetoothWindow(BRect(100, 100, 750, 420));
83 				fWindow->Show();
84 			}
85 			break;
86 
87 		default:
88 			BApplication::MessageReceived(message);
89 	}
90 }
91 
92 
93 void
94 BluetoothApplication::AboutRequested()
95 {
96 	BAboutWindow* about = new BAboutWindow("Bluetooth", BLUETOOTH_APP_SIGNATURE);
97 	about->AddCopyright(2010, "Oliver Ruiz Dorantes");
98 	about->AddText(B_TRANSLATE(
99 		"With support of:\n"
100 		" - Mika Lindqvist\n"
101 		" - Adrien Destugues\n"
102 		" - Maksym Yevmenkin\n\n"
103 		"Thanks to the individuals who helped" B_UTF8_ELLIPSIS "\n\n"
104 		"Shipping/donating hardware:\n"
105 		" - Henry Jair Abril Florez (el Colombian)\n"
106 		"	& Stefanie Bartolich\n"
107 		" - Edwin Erik Amsler\n"
108 		" - Dennis d'Entremont\n"
109 		" - Luroh\n"
110 		" - Pieter Panman\n\n"
111 		"Economically:\n"
112 		" - Karl vom Dorff, Andrea Bernardi (OSDrawer),\n"
113 		" - Matt M, Doug F, Hubert H,\n"
114 		" - Sebastian B, Andrew M, Jared E,\n"
115 		" - Frederik H, Tom S, Ferry B,\n"
116 		" - Greg G, David F, Richard S, Martin W:\n\n"
117 		"With patches:\n"
118 		" - Michael Weirauch\n"
119 		" - Fredrik Ekdahl\n"
120 		" - Raynald Lesieur\n"
121 		" - Andreas Färber\n"
122 		" - Joerg Meyer\n"
123 		"Testing:\n"
124 		" - Petter H. Juliussen\n"
125 		"Who gave me all the knowledge:\n"
126 		" - the yellowTAB team"));
127 	about->Show();
128 }
129 
130 
131 int
132 main(int, char**)
133 {
134 	BluetoothApplication app;
135 	app.Run();
136 
137 	return 0;
138 }
139