1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2011, Rene Gollent, rene@gollent.com. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include "GraphicalUserInterface.h" 9 10 #include <Alert.h> 11 12 #include "GUITeamUISettings.h" 13 #include "TeamWindow.h" 14 #include "Tracing.h" 15 16 17 GraphicalUserInterface::GraphicalUserInterface() 18 : 19 fTeamWindow(NULL), 20 fTeamWindowMessenger(NULL) 21 { 22 } 23 24 25 GraphicalUserInterface::~GraphicalUserInterface() 26 { 27 delete fTeamWindowMessenger; 28 } 29 30 31 const char* 32 GraphicalUserInterface::ID() const 33 { 34 return "GraphicalUserInterface"; 35 } 36 37 38 status_t 39 GraphicalUserInterface::Init(Team* team, UserInterfaceListener* listener) 40 { 41 try { 42 fTeamWindow = TeamWindow::Create(team, listener); 43 fTeamWindowMessenger = new BMessenger(fTeamWindow); 44 45 // start the message loop 46 fTeamWindow->Hide(); 47 fTeamWindow->Show(); 48 } catch (...) { 49 // TODO: Notify the user! 50 ERROR("Error: Failed to create team window!\n"); 51 return B_NO_MEMORY; 52 } 53 54 return B_OK; 55 } 56 57 58 void 59 GraphicalUserInterface::Show() 60 { 61 fTeamWindow->Show(); 62 } 63 64 65 void 66 GraphicalUserInterface::Terminate() 67 { 68 // quit window 69 if (fTeamWindowMessenger && fTeamWindowMessenger->LockTarget()) 70 fTeamWindow->Quit(); 71 } 72 73 74 status_t 75 GraphicalUserInterface::LoadSettings(const TeamUISettings* settings) 76 { 77 status_t result = fTeamWindow->LoadSettings((GUITeamUISettings*)settings); 78 79 return result; 80 } 81 82 83 status_t 84 GraphicalUserInterface::SaveSettings(TeamUISettings*& settings) const 85 { 86 settings = new(std::nothrow) GUITeamUISettings(ID()); 87 if (settings == NULL) 88 return B_NO_MEMORY; 89 90 fTeamWindow->SaveSettings((GUITeamUISettings*)settings); 91 92 return B_OK; 93 } 94 95 96 void 97 GraphicalUserInterface::NotifyUser(const char* title, const char* message, 98 user_notification_type type) 99 { 100 // convert notification type to alert type 101 alert_type alertType; 102 switch (type) { 103 case USER_NOTIFICATION_INFO: 104 alertType = B_INFO_ALERT; 105 break; 106 case USER_NOTIFICATION_WARNING: 107 case USER_NOTIFICATION_ERROR: 108 default: 109 alertType = B_WARNING_ALERT; 110 break; 111 } 112 113 BAlert* alert = new(std::nothrow) BAlert(title, message, "OK", 114 NULL, NULL, B_WIDTH_AS_USUAL, alertType); 115 if (alert != NULL) 116 alert->Go(NULL); 117 118 // TODO: We need to let the alert run asynchronously, but we shouldn't just 119 // create it and don't care anymore. Maybe an error window, which can 120 // display a list of errors would be the better choice. 121 } 122 123 124 int32 125 GraphicalUserInterface::SynchronouslyAskUser(const char* title, 126 const char* message, const char* choice1, const char* choice2, 127 const char* choice3) 128 { 129 BAlert* alert = new(std::nothrow) BAlert(title, message, 130 choice1, choice2, choice3); 131 if (alert == NULL) 132 return 0; 133 return alert->Go(); 134 } 135