|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Photos image fetcher client. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QList> |
|
19 |
|
20 #include <caservice.h> |
|
21 #include <canotifier.h> |
|
22 #include <canotifierfilter.h> |
|
23 |
|
24 #include "hsmenuentryremovedhandler.h" |
|
25 /*! |
|
26 \class HsMenuEntryRemovedHandler |
|
27 Listens for entry removal notifications and calls a callback. |
|
28 \ingroup group_hsutils |
|
29 \brief |
|
30 */ |
|
31 |
|
32 /*! |
|
33 Constructor. |
|
34 \param entryId identifies entry which removal is to be observed. |
|
35 \param receiver object which \a callback is to be called on requested entry |
|
36 removal. If \receiver is passed 0 no action will be taken on the entry removal. |
|
37 \param callback signal or slot that will be called on entry removal. The \a callback |
|
38 signature should correspond to void (*)(int, ChangeType) signal otherwise |
|
39 runtime warning will be provided. If \a callback is 0 no action will be |
|
40 taken on the entry removal. |
|
41 */ |
|
42 HsMenuEntryRemovedHandler::HsMenuEntryRemovedHandler( |
|
43 int entryId, |
|
44 QObject *receiver, |
|
45 const char *callback): |
|
46 mNotifier(0) |
|
47 { |
|
48 if (receiver != 0 && callback != 0) { |
|
49 connect(this, SIGNAL(notify()), receiver, callback); |
|
50 subscribe(entryId); |
|
51 } |
|
52 }; |
|
53 |
|
54 /*! |
|
55 Destructor. |
|
56 */ |
|
57 HsMenuEntryRemovedHandler::~HsMenuEntryRemovedHandler() {}; |
|
58 |
|
59 /*! |
|
60 Subscribes the observer for notifications for a given entryId and |
|
61 makes sure the \a HsMenuEntryRemovedObserver::entryChagned will be called |
|
62 on any notification for the entry. |
|
63 \param entryId identifier of the entry to be observed. |
|
64 |
|
65 */ |
|
66 void HsMenuEntryRemovedHandler::subscribe(int entryId) |
|
67 { |
|
68 // create notifier for a given entryId |
|
69 CaNotifierFilter filter; |
|
70 QList<int> entryIds; |
|
71 entryIds.append(entryId); |
|
72 filter.setIds(entryIds); |
|
73 mNotifier.reset(CaService::instance()->createNotifier(filter)); |
|
74 |
|
75 connect(mNotifier.data(), |
|
76 SIGNAL(entryChanged(int, ChangeType)), |
|
77 this, |
|
78 SLOT(entryChanged(int, ChangeType)), |
|
79 Qt::UniqueConnection); |
|
80 } |
|
81 |
|
82 |
|
83 /*! |
|
84 Handles notification about entry change |
|
85 \param entryId ignored as the observer is subscribed for exactly one entry. |
|
86 \param changeType notified change type. |
|
87 */ |
|
88 void HsMenuEntryRemovedHandler::entryChanged(int entryId, |
|
89 ChangeType changeType) |
|
90 { |
|
91 Q_UNUSED(entryId); // CaNotifier should care about matching id, skip it here |
|
92 |
|
93 if (changeType == RemoveChangeType) { |
|
94 emit notify(); |
|
95 mNotifier.reset(0); |
|
96 } |
|
97 } |