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