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 */ 8 9#include <Beep.h> 10#include <Notifications.h> 11#include <PropertyInfo.h> 12 13#include "NotificationWindow.h" 14#include "NotificationServer.h" 15 16const char* kSoundNames[] = { 17 "Information notification", 18 "Important notification", 19 "Error notification", 20 "Progress notification", 21 NULL 22}; 23 24 25NotificationServer::NotificationServer() 26 : BApplication(kNotificationServerSignature) 27{ 28} 29 30 31NotificationServer::~NotificationServer() 32{ 33} 34 35 36void 37NotificationServer::ReadyToRun() 38{ 39 fWindow = new NotificationWindow(); 40} 41 42 43void 44NotificationServer::MessageReceived(BMessage* message) 45{ 46 switch (message->what) { 47 case kNotificationMessage: 48 { 49 // Skip this message if we don't have the window 50 if (!fWindow) 51 return; 52 53 int32 type = 0; 54 55 // Emit a sound for this event 56 if (message->FindInt32("type", &type) == B_OK) { 57 if (type < (int32)(sizeof(kSoundNames) / sizeof(const char*))) 58 system_beep(kSoundNames[type]); 59 } 60 61 // Let the notification window handle this message 62 BMessenger(fWindow).SendMessage(message); 63 break; 64 } 65 default: 66 BApplication::MessageReceived(message); 67 } 68} 69 70 71status_t 72NotificationServer::GetSupportedSuites(BMessage* msg) 73{ 74 msg->AddString("suites", "suite/x-vnd.Haiku-notification_server"); 75 76 BPropertyInfo info(main_prop_list); 77 msg->AddFlat("messages", &info); 78 79 return BApplication::GetSupportedSuites(msg); 80} 81 82 83BHandler* 84NotificationServer::ResolveSpecifier(BMessage* msg, int32 index, 85 BMessage* spec, int32 from, const char* prop) 86{ 87 BPropertyInfo info(main_prop_list); 88 89 if (strcmp(prop, "message") == 0) { 90 BMessenger messenger(fWindow); 91 messenger.SendMessage(msg, fWindow); 92 return NULL; 93 } 94 95 return BApplication::ResolveSpecifier(msg, index, spec, from, prop); 96} 97 98 99int 100main(int argc, char* argv[]) 101{ 102 int32 i = 0; 103 104 // Add system sounds 105 while (kSoundNames[i] != NULL) 106 add_system_beep_event(kSoundNames[i++], 0); 107 108 // Start! 109 NotificationServer server; 110 server.Run(); 111 112 return 0; 113} 114