1 /* 2 * Copyright 2010, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com 7 * Stephan Aßmus <superstippi@gmx.de> 8 */ 9 10 11 #include <Notification.h> 12 13 #include <new> 14 15 #include <stdlib.h> 16 #include <string.h> 17 18 #include <Bitmap.h> 19 #include <Message.h> 20 21 22 BNotification::BNotification(notification_type type) 23 : 24 fType(type), 25 fFile(NULL), 26 fBitmap(NULL) 27 { 28 } 29 30 31 BNotification::~BNotification() 32 { 33 delete fFile; 34 delete fBitmap; 35 36 for (int32 i = fRefs.CountItems() - 1; i >= 0; i--) 37 delete (entry_ref*)fRefs.ItemAtFast(i); 38 39 for (int32 i = fArgv.CountItems() - 1; i >= 0; i--) 40 free(fArgv.ItemAtFast(i)); 41 } 42 43 44 notification_type 45 BNotification::Type() const 46 { 47 return fType; 48 } 49 50 51 const char* 52 BNotification::Application() const 53 { 54 return fAppName; 55 } 56 57 58 void 59 BNotification::SetApplication(const BString& app) 60 { 61 fAppName = app; 62 } 63 64 65 const char* 66 BNotification::Title() const 67 { 68 return fTitle; 69 } 70 71 72 void 73 BNotification::SetTitle(const BString& title) 74 { 75 fTitle = title; 76 } 77 78 79 const char* 80 BNotification::Content() const 81 { 82 return fContent; 83 } 84 85 86 void 87 BNotification::SetContent(const BString& content) 88 { 89 fContent = content; 90 } 91 92 93 const char* 94 BNotification::MessageID() const 95 { 96 return fID; 97 } 98 99 100 void 101 BNotification::SetMessageID(const BString& id) 102 { 103 fID = id; 104 } 105 106 107 float 108 BNotification::Progress() const 109 { 110 return fProgress; 111 } 112 113 114 void 115 BNotification::SetProgress(float progress) 116 { 117 fProgress = progress; 118 } 119 120 121 const char* 122 BNotification::OnClickApp() const 123 { 124 return fApp; 125 } 126 127 128 void 129 BNotification::SetOnClickApp(const BString& app) 130 { 131 fApp = app; 132 } 133 134 135 const entry_ref* 136 BNotification::OnClickFile() const 137 { 138 return fFile; 139 } 140 141 142 status_t 143 BNotification::SetOnClickFile(const entry_ref* file) 144 { 145 delete fFile; 146 147 if (file != NULL) { 148 fFile = new(std::nothrow) entry_ref(*file); 149 if (fFile == NULL) 150 return B_NO_MEMORY; 151 } else 152 fFile = NULL; 153 154 return B_OK; 155 } 156 157 158 status_t 159 BNotification::AddOnClickRef(const entry_ref* ref) 160 { 161 if (ref == NULL) 162 return B_BAD_VALUE; 163 164 entry_ref* clonedRef = new(std::nothrow) entry_ref(*ref); 165 if (clonedRef == NULL || !fRefs.AddItem(clonedRef)) 166 return B_NO_MEMORY; 167 168 return B_OK; 169 } 170 171 172 int32 173 BNotification::CountOnClickRefs() const 174 { 175 return fRefs.CountItems(); 176 } 177 178 179 const entry_ref* 180 BNotification::OnClickRefAt(int32 index) const 181 { 182 return (entry_ref*)fArgv.ItemAt(index); 183 } 184 185 186 status_t 187 BNotification::AddOnClickArg(const BString& arg) 188 { 189 char* clonedArg = strdup(arg.String()); 190 if (clonedArg == NULL || !fArgv.AddItem(clonedArg)) 191 return B_NO_MEMORY; 192 193 return B_OK; 194 } 195 196 197 int32 198 BNotification::CountOnClickArgs() const 199 { 200 return fArgv.CountItems(); 201 } 202 203 204 const char* 205 BNotification::OnClickArgAt(int32 index) const 206 { 207 return (char*)fArgv.ItemAt(index); 208 } 209 210 211 const BBitmap* 212 BNotification::Icon() const 213 { 214 return fBitmap; 215 } 216 217 218 status_t 219 BNotification::SetIcon(const BBitmap* icon) 220 { 221 delete fBitmap; 222 223 if (icon != NULL) { 224 fBitmap = new(std::nothrow) BBitmap(icon); 225 if (fBitmap == NULL) 226 return B_NO_MEMORY; 227 return fBitmap->InitCheck(); 228 } 229 230 fBitmap = NULL; 231 return B_OK; 232 } 233