22 #include <hsshortcutservice.h> |
22 #include <hsshortcutservice.h> |
23 #include <hscontentservice.h> |
23 #include <hscontentservice.h> |
24 |
24 |
25 #include "hsmenubasestate.h" |
25 #include "hsmenubasestate.h" |
26 |
26 |
27 // --------------------------------------------------------------------------- |
27 /*! |
28 // --------------------------------------------------------------------------- |
28 \class HsMenuBaseState |
29 // |
29 \ingroup group_hsworkerstateplugin |
|
30 \brief Menu Base State |
|
31 Menu Base state is the base class for states used in Menu. |
|
32 It provides basic functionality that makes implemenatation state easier. |
|
33 Derived implementation can request specific service and access it using convience function. |
|
34 \lib ?library |
|
35 */ |
|
36 |
|
37 /*! |
|
38 Constructor. |
|
39 \param objectName object name, used for debug purpose |
|
40 \param parent Owner. |
|
41 */ |
30 HsMenuBaseState::HsMenuBaseState(const QString &objectName, QState *parent) : |
42 HsMenuBaseState::HsMenuBaseState(const QString &objectName, QState *parent) : |
31 QState(parent) |
43 QState(parent) |
32 { |
44 { |
33 construct(objectName); |
45 construct(objectName); |
34 } |
46 } |
35 |
47 |
36 // --------------------------------------------------------------------------- |
48 /*! |
37 // --------------------------------------------------------------------------- |
49 Destructor. |
38 // |
50 */ |
39 |
|
40 HsMenuBaseState::~HsMenuBaseState() |
51 HsMenuBaseState::~HsMenuBaseState() |
41 { |
52 { |
42 } |
53 } |
43 |
54 |
44 // --------------------------------------------------------------------------- |
55 /*! |
45 // --------------------------------------------------------------------------- |
56 Constructs contained objects. |
46 // |
57 \param objectName object name, used for debug purpose |
|
58 */ |
47 void HsMenuBaseState::construct(const QString &objectName) |
59 void HsMenuBaseState::construct(const QString &objectName) |
48 { |
60 { |
49 if (this->parent()) { |
61 if (this->parent()) { |
50 setObjectName(this->parent()->objectName() + "/" + objectName); |
62 setObjectName(this->parent()->objectName() + "/" + objectName); |
51 } else { |
63 } else { |
52 setObjectName(objectName); |
64 setObjectName(objectName); |
53 } |
65 } |
54 } |
66 } |
55 |
67 |
56 // --------------------------------------------------------------------------- |
68 /*! |
57 // --------------------------------------------------------------------------- |
69 Convenience method that request single service. |
58 // |
70 \param service service to be requested. |
|
71 \see requestServices |
|
72 */ |
59 void HsMenuBaseState::requestService(const QVariant &service) |
73 void HsMenuBaseState::requestService(const QVariant &service) |
60 { |
74 { |
61 requestServices(QList<QVariant> () << service); |
75 requestServices(QList<QVariant> () << service); |
62 } |
76 } |
63 |
77 |
64 // --------------------------------------------------------------------------- |
78 /*! |
65 // --------------------------------------------------------------------------- |
79 Request for services |
66 // |
80 notice that services are appended to the list, |
|
81 so this fuction can be called more than once. |
|
82 \param services list of requested services |
|
83 this method must be called during construction phased of derived class |
|
84 */ |
67 void HsMenuBaseState::requestServices(const QVariantList &services) |
85 void HsMenuBaseState::requestServices(const QVariantList &services) |
68 { |
86 { |
69 // if value is not list, it returns empty list |
87 // if value is not list, it returns empty list |
70 QVariantList value = property(HS_SERVICES_REGISTRATION_KEY).toList(); |
88 QVariantList value = property(HS_SERVICES_REGISTRATION_KEY).toList(); |
71 // apppend to list |
89 // apppend to list |
72 value.append(services); |
90 value.append(services); |
73 setProperty(HS_SERVICES_REGISTRATION_KEY, value); |
91 setProperty(HS_SERVICES_REGISTRATION_KEY, value); |
74 } |
92 } |
75 |
93 |
76 // --------------------------------------------------------------------------- |
94 /*! |
77 // --------------------------------------------------------------------------- |
95 Convenience method that returns the shortcut serviceif was requested |
78 // |
96 \return Shortcut service if exists. |
|
97 */ |
79 HsShortcutService *HsMenuBaseState::shortcutService() const |
98 HsShortcutService *HsMenuBaseState::shortcutService() const |
80 { |
99 { |
81 return propertyWithChecking(SHORTCUT_SERVICE_KEY).value< |
100 return propertyWithChecking(SHORTCUT_SERVICE_KEY).value< |
82 HsShortcutService *> (); |
101 HsShortcutService *> (); |
83 } |
102 } |
84 |
103 |
85 // --------------------------------------------------------------------------- |
104 /*! |
86 // --------------------------------------------------------------------------- |
105 Convenient method that returns the content serviceif was requested |
87 // |
106 \return Content service if exists. |
|
107 */ |
88 HsContentService *HsMenuBaseState::contentService() const |
108 HsContentService *HsMenuBaseState::contentService() const |
89 { |
109 { |
90 return propertyWithChecking(CONTENT_SERVICE_KEY).value< |
110 return propertyWithChecking(CONTENT_SERVICE_KEY).value< |
91 HsContentService *> (); |
111 HsContentService *> (); |
92 } |
112 } |
93 |
113 |
94 // --------------------------------------------------------------------------- |
114 /*! |
95 // --------------------------------------------------------------------------- |
115 Function return value for specified property and |
96 // |
116 if it is not valid add warning message on console. |
|
117 \param propertyName Property name. |
|
118 \return Property after validation. |
|
119 */ |
97 QVariant HsMenuBaseState::propertyWithChecking(const char *propertyName) const |
120 QVariant HsMenuBaseState::propertyWithChecking(const char *propertyName) const |
98 { |
121 { |
99 QVariant val = property(propertyName); |
122 QVariant val = property(propertyName); |
100 if (!val.isValid()) { |
123 if (!val.isValid()) { |
101 qWarning() << "Missing value for property: " << propertyName; |
124 qWarning() << "Missing value for property: " << propertyName; |