xref: /haiku/src/apps/debugger/user_interface/gui/GraphicalUserInterface.cpp (revision 922e7ba1f3228e6f28db69b0ded8f86eb32dea17)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "GraphicalUserInterface.h"
8 
9 #include <Alert.h>
10 
11 #include "TeamWindow.h"
12 #include "Tracing.h"
13 
14 
15 GraphicalUserInterface::GraphicalUserInterface()
16 	:
17 	fTeamWindow(NULL),
18 	fTeamWindowMessenger(NULL)
19 {
20 }
21 
22 
23 GraphicalUserInterface::~GraphicalUserInterface()
24 {
25 	delete fTeamWindowMessenger;
26 }
27 
28 
29 status_t
30 GraphicalUserInterface::Init(Team* team, UserInterfaceListener* listener)
31 {
32 	try {
33 		fTeamWindow = TeamWindow::Create(team, listener);
34 		fTeamWindowMessenger = new BMessenger(fTeamWindow);
35 	} catch (...) {
36 		// TODO: Notify the user!
37 		ERROR("Error: Failed to create team window!\n");
38 		return B_NO_MEMORY;
39 	}
40 
41 	return B_OK;
42 }
43 
44 
45 void
46 GraphicalUserInterface::Show()
47 {
48 	fTeamWindow->Show();
49 }
50 
51 
52 void
53 GraphicalUserInterface::Terminate()
54 {
55 	// quit window
56 	if (fTeamWindowMessenger && fTeamWindowMessenger->LockTarget())
57 		fTeamWindow->Quit();
58 }
59 
60 
61 void
62 GraphicalUserInterface::NotifyUser(const char* title, const char* message,
63 	user_notification_type type)
64 {
65 	// convert notification type to alert type
66 	alert_type alertType;
67 	switch (type) {
68 		case USER_NOTIFICATION_INFO:
69 			alertType = B_INFO_ALERT;
70 			break;
71 		case USER_NOTIFICATION_WARNING:
72 		case USER_NOTIFICATION_ERROR:
73 		default:
74 			alertType = B_WARNING_ALERT;
75 			break;
76 	}
77 
78 	BAlert* alert = new(std::nothrow) BAlert(title, message, "OK",
79 		NULL, NULL, B_WIDTH_AS_USUAL, alertType);
80 	if (alert != NULL)
81 		alert->Go(NULL);
82 
83 	// TODO: We need to let the alert run asynchronously, but we shouldn't just
84 	// create it and don't care anymore. Maybe an error window, which can
85 	// display a list of errors would be the better choice.
86 }
87 
88 
89 int32
90 GraphicalUserInterface::SynchronouslyAskUser(const char* title,
91 	const char* message, const char* choice1, const char* choice2,
92 	const char* choice3)
93 {
94 	BAlert* alert = new(std::nothrow) BAlert(title, message,
95 		choice1, choice2, choice3);
96 	if (alert == NULL)
97 		return 0;
98 	return alert->Go();
99 }
100