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
21BluetoothApplication::BluetoothApplication()
22	:
23	BApplication(BLUETOOTH_APP_SIGNATURE)
24{
25}
26
27
28void
29BluetoothApplication::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
68void
69BluetoothApplication::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			break;
90	}
91}
92
93
94void
95BluetoothApplication::AboutRequested()
96{
97	BAboutWindow* about = new BAboutWindow("Bluetooth", BLUETOOTH_APP_SIGNATURE);
98	about->AddCopyright(2010, "Oliver Ruiz Dorantes");
99	about->AddText(B_TRANSLATE(
100		"With support of:\n"
101		" - Mika Lindqvist\n"
102		" - Adrien Destugues\n"
103		" - Maksym Yevmenkin\n\n"
104		"Thanks to the individuals who helped" B_UTF8_ELLIPSIS "\n\n"
105		"Shipping/donating hardware:\n"
106		" - Henry Jair Abril Florez (el Colombian)\n"
107		"	& Stefanie Bartolich\n"
108		" - Edwin Erik Amsler\n"
109		" - Dennis d'Entremont\n"
110		" - Luroh\n"
111		" - Pieter Panman\n\n"
112		"Economically:\n"
113		" - Karl vom Dorff, Andrea Bernardi (OSDrawer),\n"
114		" - Matt M, Doug F, Hubert H,\n"
115		" - Sebastian B, Andrew M, Jared E,\n"
116		" - Frederik H, Tom S, Ferry B,\n"
117		" - Greg G, David F, Richard S, Martin W:\n\n"
118		"With patches:\n"
119		" - Michael Weirauch\n"
120		" - Fredrik Ekdahl\n"
121		" - Raynald Lesieur\n"
122		" - Andreas F��rber\n"
123		" - Joerg Meyer\n"
124		"Testing:\n"
125		" - Petter H. Juliussen\n"
126		"Who gave me all the knowledge:\n"
127		" - the yellowTAB team"));
128	about->Show();
129}
130
131
132int
133main(int, char**)
134{
135	BluetoothApplication app;
136	app.Run();
137
138	return 0;
139}
140