| 1 |
/* This file is part of lomiri-action-api |
| 2 |
* Copyright 2013 Canonical Ltd. |
| 3 |
* |
| 4 |
* lomiri-action-api is free software: you can redistribute it and/or modify it |
| 5 |
* under the terms of the GNU Lesser General Public License version 3, |
| 6 |
* as published by the Free Software Foundation. |
| 7 |
* |
| 8 |
* lomiri-action-api is distributed in the hope that it will be useful, but |
| 9 |
* WITHOUT ANY WARRANTY; without even the implied warranties of |
| 10 |
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 11 |
* PURPOSE. See the GNU Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include "qml-manager.h" |
| 18 |
|
| 19 |
using namespace lomiri::action; |
| 20 |
|
| 21 |
qml::ActionManager::ActionManager(QObject *parent) |
| 22 |
: lomiri::action::ActionManager(parent) |
| 23 |
{ |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
qml::ActionManager::~ActionManager() |
| 28 |
{ |
| 29 |
foreach(Action *action, globalContext()->actions()) { |
| 30 |
removeAction(action); |
| 31 |
} |
| 32 |
foreach(ActionContext *context, localContexts()) { |
| 33 |
removeLocalContext(context); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
QQmlListProperty<lomiri::action::ActionContext> |
| 39 |
qml::ActionManager::localContexts_list() |
| 40 |
{ |
| 41 |
return QQmlListProperty<ActionContext>(this, |
| 42 |
0, |
| 43 |
qml::ActionManager::contextAppend, |
| 44 |
qml::ActionManager::contextCount, |
| 45 |
0, // at() |
| 46 |
qml::ActionManager::contextClear); |
| 47 |
} |
| 48 |
|
| 49 |
QQmlListProperty<lomiri::action::Action> |
| 50 |
qml::ActionManager::actions_list() |
| 51 |
{ |
| 52 |
return QQmlListProperty<Action>(this, |
| 53 |
0, |
| 54 |
qml::ActionManager::actionAppend, |
| 55 |
qml::ActionManager::actionCount, |
| 56 |
0, // at |
| 57 |
qml::ActionManager::actionClear); |
| 58 |
} |
| 59 |
|
| 60 |
void |
| 61 |
qml::ActionManager::contextAppend(QQmlListProperty<ActionContext> *list, ActionContext *context) |
| 62 |
{ |
| 63 |
qml::ActionManager *manager = qobject_cast<qml::ActionManager *>(list->object); |
| 64 |
if (manager) { |
| 65 |
manager->addLocalContext(context); |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
Q_ASSERT(0); // should not be reached |
| 70 |
} |
| 71 |
|
| 72 |
void |
| 73 |
qml::ActionManager::contextClear(QQmlListProperty<ActionContext> *list) |
| 74 |
{ |
| 75 |
qml::ActionManager *manager = qobject_cast<qml::ActionManager *>(list->object); |
| 76 |
if (manager) { |
| 77 |
foreach(ActionContext *context, manager->localContexts()) { |
| 78 |
manager->removeLocalContext(context); |
| 79 |
} |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
Q_ASSERT(0); // should not be reached |
| 84 |
} |
| 85 |
|
| 86 |
QQMLISTPROPERTY_INT |
| 87 |
qml::ActionManager::contextCount(QQmlListProperty<ActionContext> *list) |
| 88 |
{ |
| 89 |
qml::ActionManager *manager = qobject_cast<qml::ActionManager *>(list->object); |
| 90 |
if (manager) { |
| 91 |
return manager->localContexts().count(); |
| 92 |
} |
| 93 |
|
| 94 |
Q_ASSERT(0); // should not be reached |
| 95 |
return 0; |
| 96 |
} |
| 97 |
|
| 98 |
void |
| 99 |
qml::ActionManager::actionAppend(QQmlListProperty<Action> *list, Action *action) |
| 100 |
{ |
| 101 |
qml::ActionManager *manager = qobject_cast<qml::ActionManager *>(list->object); |
| 102 |
if (manager) { |
| 103 |
manager->globalContext()->addAction(action); |
| 104 |
return; |
| 105 |
} |
| 106 |
|
| 107 |
Q_ASSERT(0); // should not be reached |
| 108 |
} |
| 109 |
|
| 110 |
void |
| 111 |
qml::ActionManager::actionClear(QQmlListProperty<Action> *list) |
| 112 |
{ |
| 113 |
qml::ActionManager *manager = qobject_cast<qml::ActionManager *>(list->object); |
| 114 |
if (manager) { |
| 115 |
foreach(Action *action, manager->globalContext()->actions()) { |
| 116 |
manager->globalContext()->removeAction(action); |
| 117 |
} |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
Q_ASSERT(0); // should not be reached |
| 122 |
} |
| 123 |
|
| 124 |
QQMLISTPROPERTY_INT |
| 125 |
qml::ActionManager::actionCount(QQmlListProperty<Action> *list) |
| 126 |
{ |
| 127 |
qml::ActionManager *manager = qobject_cast<qml::ActionManager *>(list->object); |
| 128 |
if (manager) { |
| 129 |
return manager->globalContext()->actions().count(); |
| 130 |
} |
| 131 |
|
| 132 |
Q_ASSERT(0); // should not be reached |
| 133 |
return 0; |
| 134 |
} |