repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / ui / MessagePackageListener.cpp
blob382f8cd1065998fccc4a3006d1bd1abe4ad35e58
1 /*
2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
7 #include "MessagePackageListener.h"
9 #include <Messenger.h>
10 #include <View.h>
12 #include "PackageInfo.h"
15 // #pragma mark - MessagePackageListener
18 MessagePackageListener::MessagePackageListener(BHandler* target)
20 fTarget(target),
21 fChangesMask(0xffffffff)
26 MessagePackageListener::~MessagePackageListener()
31 void
32 MessagePackageListener::PackageChanged(const PackageInfoEvent& event)
34 if ((event.Changes() & fChangesMask) == 0)
35 return;
37 BMessenger messenger(fTarget);
38 if (!messenger.IsValid())
39 return;
41 BMessage message(MSG_UPDATE_PACKAGE);
42 message.AddString("name", event.Package()->Name());
43 message.AddUInt32("changes", event.Changes());
45 messenger.SendMessage(&message);
49 void
50 MessagePackageListener::SetChangesMask(uint32 mask)
52 fChangesMask = mask;
56 // #pragma mark - OnePackageMessagePackageListener
59 OnePackageMessagePackageListener::OnePackageMessagePackageListener(BHandler* target)
61 MessagePackageListener(target)
66 OnePackageMessagePackageListener::~OnePackageMessagePackageListener()
71 void
72 OnePackageMessagePackageListener::SetPackage(const PackageInfoRef& package)
74 if (fPackage == package)
75 return;
77 PackageInfoListenerRef listener(this);
79 if (fPackage.Get() != NULL)
80 fPackage->RemoveListener(listener);
82 fPackage = package;
84 if (fPackage.Get() != NULL)
85 fPackage->AddListener(listener);
89 const PackageInfoRef&
90 OnePackageMessagePackageListener::Package() const
92 return fPackage;