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