Commit 73102f41 authored by Emmanuel Promayon's avatar Emmanuel Promayon

NEW manage user extension for viewers

Users can specify a viewer extension file. This will be saved in the preference
and load at initialisation time
parent 5dc51ea2
......@@ -191,7 +191,7 @@
</property>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="componentPluginDescription">
<widget class="QLabel" name="componentExtensionDescription">
<property name="text">
<string>Click on a registered component extension above to display its description.</string>
</property>
......
......@@ -330,13 +330,14 @@ void SettingsDialog::on_removeComponentExtensionButton_released() {
// removing is allowed by selecting a new component extension
myUI->removeComponentExtensionButton->setEnabled(false);
myUI->componentExtensionDescription->setText("Click on a registered component extension above to display its description.");
}
// ------------------------------ on_componentExtensionList_cellClicked -------------------------------
void SettingsDialog::on_componentExtensionList_cellClicked(int row, int column) {
const ComponentExtension* ce = ExtensionManager::getComponentExtension(myUI->componentExtensionList->item(myUI->componentExtensionList->currentRow(), 0)->text());
myUI->removeComponentExtensionButton->setEnabled(userComponents.contains(ce->getLocation()));
myUI->componentPluginDescription->setText(ce->getDescription());
myUI->componentExtensionDescription->setText(ce->getDescription());
}
// ------------------------------ on_addActionExtensionButton_released -------------------------------
......@@ -370,6 +371,9 @@ void SettingsDialog::on_removeActionExtensionButton_released() {
// remove the plugin
QString actionFileName = myUI->actionExtensionList->item(myUI->actionExtensionList->currentRow(), 2)->text();
ActionList actions = ExtensionManager::getActionExtension(actionFileName)->getActions();
// If the action extension contains other actions than the one selected, ask the user if this ok
// (as removing one action removes the whole extension and the extension might contain more than one action)
bool reallyDelete = true;
if (actions.size() > 1) {
QString actionName = myUI->actionExtensionList->item(myUI->actionExtensionList->currentRow(), 0)->text();
......@@ -393,6 +397,7 @@ void SettingsDialog::on_removeActionExtensionButton_released() {
// removing is allowed by selecting a new component extension
myUI->removeActionExtensionButton->setEnabled(false);
myUI->actionExtensionDescription->setText("Click on an registered action above to display its description.");
}
}
......@@ -407,12 +412,63 @@ void SettingsDialog::on_actionExtensionList_cellClicked(int row, int column) {
// ------------------------------ on_addViewerExtensionButton_released -------------------------------
void SettingsDialog::on_addViewerExtensionButton_released() {
// TODO
QStringList files = QFileDialog::getOpenFileNames(nullptr, "Add an Viewer Extension", Core::getViewerDirectories().first(), "Viewer Extension (*.so.* *.dll *.dylib)");
QStringList pluginFile = files;
QStringList::Iterator it = pluginFile.begin();
while (it != pluginFile.end()) {
if (!ExtensionManager::loadExtension(ExtensionManager::VIEWER, *it)) {
CAMITK_ERROR(tr("ViewerExtension error: cannot load plugin from file:\n\"%1\"\nTry recompile the plugin\n(plugin might be outdated)").arg((*it)))
}
else {
Application::showStatusBarMessage("Plugin " + (*it) + " loaded.");
// Add the filename in the application settings: this is a manually loaded plugin, it should therefore
// be kept in a list for the next run
userViewers += (*it);
writeUserExtensions();
}
++it; //next one!
}
// update the display
updateViewerExtensionList();
}
// ----------------- on_removeViewerExtensionButton_released ----------------------------
void SettingsDialog::on_removeViewerExtensionButton_released() {
// TODO
// remove the plugin
QString viewerFileName = myUI->viewerExtensionList->item(myUI->viewerExtensionList->currentRow(), 2)->text();
ViewerList viewers = ExtensionManager::getViewerExtension(viewerFileName)->getViewers();
// If the viewer extension contains other viewers than the one selected, ask the user if this ok
// (as removing one viewer removes the whole extension and the extension might manage more than one viewer)
bool reallyDelete = true;
if (viewers.size() > 1) {
QString viewerName = myUI->viewerExtensionList->item(myUI->viewerExtensionList->currentRow(), 0)->text();
QStringList viewerNames;
foreach(Viewer* v, viewers) {
if (v->getName() != viewerName) {
viewerNames << v->getName();
}
}
// CCC Exception: Use a QMessageBox::warning instead of CAMITK_WARNING as the user interaction is required
reallyDelete = (QMessageBox::warning(this, "Removing multiple viewers", tr("Removing viewer \"") + viewerName + tr(" \" will also remove the following viewers:<ul><li>") + viewerNames.join("</li><li>") + tr("</li></ul>Are you sure you want to delete all these viewers?"), QMessageBox::Yes | QMessageBox::Cancel) == QMessageBox::Yes);
}
if (reallyDelete) {
ExtensionManager::unloadViewerExtension(viewerFileName);
// remove from settings
userViewers.removeAll(viewerFileName);
writeUserExtensions();
// update the display
updateViewerExtensionList();
// removing is allowed by selecting a new component extension
myUI->removeViewerExtensionButton->setEnabled(false);
myUI->viewerExtensionDescription->setText("Click on an registered viewer above to display its description.");
}
}
// ------------------------------ on_viewerExtensionList_cellClicked -------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment