make the plugin selector combobox work

This commit is contained in:
Marco Martin 2013-08-27 13:27:49 +02:00
parent 39b49bf464
commit b44f9d17cb
3 changed files with 40 additions and 9 deletions

View File

@ -43,7 +43,8 @@ CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containme
{
QHash<int, QByteArray> roleNames;
roleNames[ActionRole] = "action";
roleNames[PluginRole] = "plugin";
roleNames[PluginNameRole] = "pluginName";
roleNames[HasConfigurationInterfaceRole] = "hasConfigurationInterface";
setRoleNames(roleNames);
@ -59,12 +60,15 @@ CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containme
QStandardItem *item = new QStandardItem();
item->setData(i.key(), ActionRole);
item->setData(i.value()->pluginInfo().pluginName(), PluginRole);
appendRow(item);
item->setData(i.value()->pluginInfo().pluginName(), PluginNameRole);
m_plugins[i.key()] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, i.value()->pluginInfo().pluginName());
m_plugins[i.key()]->setContainment(m_containment);
KConfigGroup cfg(&m_baseCfg, i.key());
m_plugins[i.key()]->restore(cfg);
item->setData(m_plugins[i.key()]->pluginInfo().property("X-Plasma-HasConfigurationInterface").toBool(), HasConfigurationInterfaceRole);
appendRow(item);
}
}
@ -102,33 +106,42 @@ bool CurrentContainmentActionsModel::append(const QString &action, const QString
QStandardItem *item = new QStandardItem();
item->setData(action, ActionRole);
item->setData(plugin, PluginRole);
appendRow(item);
item->setData(plugin, PluginNameRole);
m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin);
m_plugins[action]->setContainment(m_containment);
//empty config: the new one will ne in default state
KConfigGroup tempConfig(&m_tempConfigParent, "test");
m_plugins[action]->restore(tempConfig);
item->setData(m_plugins[action]->pluginInfo().property("X-Plasma-HasConfigurationInterface").toBool(), HasConfigurationInterfaceRole);
appendRow(item);
return true;
}
void CurrentContainmentActionsModel::update(int row, const QString &action, const QString &plugin)
{
const QString oldPlugin = itemData(index(row, 0)).value(PluginRole).toString();
const QString oldPlugin = itemData(index(row, 0)).value(PluginNameRole).toString();
const QString oldTrigger = itemData(index(row, 0)).value(ActionRole).toString();
if (oldTrigger == action && oldPlugin == plugin) {
return;
}
QModelIndex idx = index(row, 0);
if (idx.isValid()) {
setData(idx, action, ActionRole);
setData(idx, plugin, PluginRole);
setData(idx, plugin, PluginNameRole);
if (m_plugins.contains(action) && oldPlugin != plugin) {
if (!m_plugins.contains(action) || oldPlugin != plugin) {
delete m_plugins[action];
m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin);
m_plugins[action]->setContainment(m_containment);
//empty config: the new one will ne in default state
KConfigGroup tempConfig(&m_tempConfigParent, "test");
m_plugins[action]->restore(tempConfig);
setData(idx, m_plugins[action]->pluginInfo().property("X-Plasma-HasConfigurationInterface").toBool(), HasConfigurationInterfaceRole);
}
}
}

View File

@ -37,7 +37,8 @@ class CurrentContainmentActionsModel : public QStandardItemModel
public:
enum Roles {
ActionRole = Qt::UserRole+1,
PluginRole
PluginNameRole,
HasConfigurationInterfaceRole
};
CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent = 0);

View File

@ -47,13 +47,30 @@ Item {
text: model.action
}
QtControls.ComboBox {
id: pluginsCombo
Layout.fillWidth: true
model: configDialog.containmentActionConfigModel
textRole: "name"
property bool initialized: false
Component.onCompleted: {
for (var i = 0; i < configDialog.containmentActionConfigModel.count; ++i) {
if (configDialog.containmentActionConfigModel.get(i).pluginName == pluginName) {
pluginsCombo.currentIndex = i;
break;
}
}
pluginsCombo.initialized = true;
}
onCurrentIndexChanged: {
if (initialized && configDialog.containmentActionConfigModel.get(currentIndex).pluginName != pluginName) {
configDialog.currentContainmentActionsModel.update(index, action, configDialog.containmentActionConfigModel.get(currentIndex).pluginName);
}
}
}
QtControls.Button {
iconName: "configure"
width: height
enabled: model.hasConfigurationInterface
onClicked: {
configDialog.currentContainmentActionsModel.showConfiguration(index);
}