xref: /haiku/src/preferences/bluetooth/BluetoothMain.cpp (revision 1345706a9ff6ad0dc041339a02d4259998b0765d)
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 <Locale.h>
10 #include <MessageRunner.h>
11 #include <Roster.h>
12 
13 #include "BluetoothMain.h"
14 #include "BluetoothWindow.h"
15 #include "defs.h"
16 
17 
18 #undef B_TRANSLATE_CONTEXT
19 #define B_TRANSLATE_CONTEXT "main"
20 
21 BluetoothApplication::BluetoothApplication(void)
22  :	BApplication(BLUETOOTH_APP_SIGNATURE)
23 {
24 }
25 
26 
27 void
28 BluetoothApplication::ReadyToRun()
29 {
30 	if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) {
31 
32 		int32 choice = (new BAlert("bluetooth_server not running",
33 			"bluetooth_server has not been found running on the system."
34 			"Should be started, or stay offline", "Work offline",
35 			"Quit", "Start please", B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
36 
37 
38 		switch (choice) {
39 			case 1:
40 				PostMessage(B_QUIT_REQUESTED);
41 			case 2:
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 			}
55 		}
56 
57 		return;
58 	}
59 
60 	PostMessage(new BMessage('Xtmp'));
61 }
62 
63 
64 void
65 BluetoothApplication::MessageReceived(BMessage* message)
66 {
67 	switch (message->what) {
68 		case kMsgAddToRemoteList:
69 			fWindow->PostMessage(message);
70 			break;
71 
72 		case 'Xtmp':
73 			if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) {
74 				// Give another chance
75 				BMessageRunner::StartSending(be_app_messenger,
76 					new BMessage('Xtmp'), 2 * 1000000, 1);
77 			} else {
78 				fWindow = new BluetoothWindow(BRect(100, 100, 550, 420));
79 				fWindow->Show();
80 			}
81 			break;
82 
83 		default:
84 			BApplication::MessageReceived(message);
85 	}
86 }
87 
88 
89 void
90 BluetoothApplication::AboutRequested()
91 {
92 
93 	(new BAlert("about", B_TRANSLATE("Haiku Bluetooth system, (ARCE)\n\n"
94 							"Created by Oliver Ruiz Dorantes\n\n"
95 							"With support of:\n"
96 							"	- Mika Lindqvist\n"
97 							"	- Adrien Destugues\n"
98 							"	- Maksym Yevmenkin\n\n"
99 							"Thanks to the individuals who helped...\n\n"
100 							"Shipping/donating hardware:\n"
101 							"	- Henry Jair Abril Florez (el Colombian)\n"
102 							"		& Stefanie Bartolich\n"
103 							"	- Edwin Erik Amsler\n"
104 							"	- Dennis d'Entremont\n"
105 							"	- Luroh\n"
106 							"	- Pieter Panman\n\n"
107 							"Economically:\n"
108 							"	- Karl vom Dorff, Andrea Bernardi (OSDrawer),\n"
109 							"	- Matt M, Doug F, Hubert H,\n"
110 							"	- Sebastian B, Andrew M, Jared E,\n"
111 							"	- Frederik H, Tom S, Ferry B,\n"
112 							"	- Greg G, David F, Richard S, Martin W:\n\n"
113 							"With patches:\n"
114 							"	- Michael Weirauch\n"
115 							"	- Fredrik Ekdahl\n"
116 							"	- Raynald Lesieur\n"
117 							"	- Andreas Färber\n"
118 							"	- Joerg Meyer\n"
119 							"Testing:\n"
120 							"	- Petter H. Juliussen\n"
121 							"Who gave me all the knowledge:\n"
122 							"	- the yellowTAB team"),
123 						B_TRANSLATE("OK")))->Go();
124 
125 }
126 
127 
128 int
129 main(int, char**)
130 {
131 	BluetoothApplication myApplication;
132 	myApplication.Run();
133 
134 	return 0;
135 }
136