1 /* 2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "MessagePackageListener.h" 8 9 #include <Messenger.h> 10 #include <View.h> 11 12 #include "PackageInfo.h" 13 14 15 // #pragma mark - MessagePackageListener 16 17 MessagePackageListener(BHandler * target)18MessagePackageListener::MessagePackageListener(BHandler* target) 19 : 20 fTarget(target), 21 fChangesMask(0xffffffff) 22 { 23 } 24 25 ~MessagePackageListener()26MessagePackageListener::~MessagePackageListener() 27 { 28 } 29 30 31 void PackageChanged(const PackageInfoEvent & event)32MessagePackageListener::PackageChanged(const PackageInfoEvent& event) 33 { 34 if ((event.Changes() & fChangesMask) == 0) 35 return; 36 37 BMessenger messenger(fTarget); 38 if (!messenger.IsValid()) 39 return; 40 41 BMessage message(MSG_UPDATE_PACKAGE); 42 message.AddString("name", event.Package()->Name()); 43 message.AddUInt32("changes", event.Changes()); 44 45 messenger.SendMessage(&message); 46 } 47 48 49 void SetChangesMask(uint32 mask)50MessagePackageListener::SetChangesMask(uint32 mask) 51 { 52 fChangesMask = mask; 53 } 54 55 56 // #pragma mark - OnePackageMessagePackageListener 57 58 OnePackageMessagePackageListener(BHandler * target)59OnePackageMessagePackageListener::OnePackageMessagePackageListener(BHandler* target) 60 : 61 MessagePackageListener(target) 62 { 63 } 64 65 ~OnePackageMessagePackageListener()66OnePackageMessagePackageListener::~OnePackageMessagePackageListener() 67 { 68 } 69 70 71 void SetPackage(const PackageInfoRef & package)72OnePackageMessagePackageListener::SetPackage(const PackageInfoRef& package) 73 { 74 if (fPackage == package) 75 return; 76 77 PackageInfoListenerRef listener(this); 78 79 if (fPackage.IsSet()) 80 fPackage->RemoveListener(listener); 81 82 fPackage = package; 83 84 if (fPackage.IsSet()) 85 fPackage->AddListener(listener); 86 } 87 88 89 const PackageInfoRef& Package() const90OnePackageMessagePackageListener::Package() const 91 { 92 return fPackage; 93 } 94