make the plugin selector combobox work
This commit is contained in:
parent
39b49bf464
commit
b44f9d17cb
@ -43,7 +43,8 @@ CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containme
|
|||||||
{
|
{
|
||||||
QHash<int, QByteArray> roleNames;
|
QHash<int, QByteArray> roleNames;
|
||||||
roleNames[ActionRole] = "action";
|
roleNames[ActionRole] = "action";
|
||||||
roleNames[PluginRole] = "plugin";
|
roleNames[PluginNameRole] = "pluginName";
|
||||||
|
roleNames[HasConfigurationInterfaceRole] = "hasConfigurationInterface";
|
||||||
|
|
||||||
setRoleNames(roleNames);
|
setRoleNames(roleNames);
|
||||||
|
|
||||||
@ -59,12 +60,15 @@ CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containme
|
|||||||
|
|
||||||
QStandardItem *item = new QStandardItem();
|
QStandardItem *item = new QStandardItem();
|
||||||
item->setData(i.key(), ActionRole);
|
item->setData(i.key(), ActionRole);
|
||||||
item->setData(i.value()->pluginInfo().pluginName(), PluginRole);
|
item->setData(i.value()->pluginInfo().pluginName(), PluginNameRole);
|
||||||
appendRow(item);
|
|
||||||
m_plugins[i.key()] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, i.value()->pluginInfo().pluginName());
|
m_plugins[i.key()] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, i.value()->pluginInfo().pluginName());
|
||||||
m_plugins[i.key()]->setContainment(m_containment);
|
m_plugins[i.key()]->setContainment(m_containment);
|
||||||
KConfigGroup cfg(&m_baseCfg, i.key());
|
KConfigGroup cfg(&m_baseCfg, i.key());
|
||||||
m_plugins[i.key()]->restore(cfg);
|
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();
|
QStandardItem *item = new QStandardItem();
|
||||||
item->setData(action, ActionRole);
|
item->setData(action, ActionRole);
|
||||||
item->setData(plugin, PluginRole);
|
item->setData(plugin, PluginNameRole);
|
||||||
appendRow(item);
|
|
||||||
m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin);
|
m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin);
|
||||||
m_plugins[action]->setContainment(m_containment);
|
m_plugins[action]->setContainment(m_containment);
|
||||||
//empty config: the new one will ne in default state
|
//empty config: the new one will ne in default state
|
||||||
KConfigGroup tempConfig(&m_tempConfigParent, "test");
|
KConfigGroup tempConfig(&m_tempConfigParent, "test");
|
||||||
m_plugins[action]->restore(tempConfig);
|
m_plugins[action]->restore(tempConfig);
|
||||||
|
item->setData(m_plugins[action]->pluginInfo().property("X-Plasma-HasConfigurationInterface").toBool(), HasConfigurationInterfaceRole);
|
||||||
|
|
||||||
|
appendRow(item);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurrentContainmentActionsModel::update(int row, const QString &action, const QString &plugin)
|
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);
|
QModelIndex idx = index(row, 0);
|
||||||
|
|
||||||
if (idx.isValid()) {
|
if (idx.isValid()) {
|
||||||
setData(idx, action, ActionRole);
|
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];
|
delete m_plugins[action];
|
||||||
m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin);
|
m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin);
|
||||||
m_plugins[action]->setContainment(m_containment);
|
m_plugins[action]->setContainment(m_containment);
|
||||||
//empty config: the new one will ne in default state
|
//empty config: the new one will ne in default state
|
||||||
KConfigGroup tempConfig(&m_tempConfigParent, "test");
|
KConfigGroup tempConfig(&m_tempConfigParent, "test");
|
||||||
m_plugins[action]->restore(tempConfig);
|
m_plugins[action]->restore(tempConfig);
|
||||||
|
setData(idx, m_plugins[action]->pluginInfo().property("X-Plasma-HasConfigurationInterface").toBool(), HasConfigurationInterfaceRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ class CurrentContainmentActionsModel : public QStandardItemModel
|
|||||||
public:
|
public:
|
||||||
enum Roles {
|
enum Roles {
|
||||||
ActionRole = Qt::UserRole+1,
|
ActionRole = Qt::UserRole+1,
|
||||||
PluginRole
|
PluginNameRole,
|
||||||
|
HasConfigurationInterfaceRole
|
||||||
};
|
};
|
||||||
|
|
||||||
CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent = 0);
|
CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent = 0);
|
||||||
|
@ -47,13 +47,30 @@ Item {
|
|||||||
text: model.action
|
text: model.action
|
||||||
}
|
}
|
||||||
QtControls.ComboBox {
|
QtControls.ComboBox {
|
||||||
|
id: pluginsCombo
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
model: configDialog.containmentActionConfigModel
|
model: configDialog.containmentActionConfigModel
|
||||||
textRole: "name"
|
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 {
|
QtControls.Button {
|
||||||
iconName: "configure"
|
iconName: "configure"
|
||||||
width: height
|
width: height
|
||||||
|
enabled: model.hasConfigurationInterface
|
||||||
onClicked: {
|
onClicked: {
|
||||||
configDialog.currentContainmentActionsModel.showConfiguration(index);
|
configDialog.currentContainmentActionsModel.showConfiguration(index);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user