29 #include "../../../../Exception.h" 30 #include "../../../../core/plugin/Exception.h" 31 #include "../../../../core/plugin/PluginManager.h" 32 #include "../../../../core/plugin/Serializers.h" 33 #include "../../../../core/plugin/Utils.h" 34 #include "../../help/HelpManager.h" 35 #include "../../utils/CentralizedCheckBoxDelegate.h" 36 #include "../../utils/ResourceChooser.h" 37 #include "ui_PluginManagerDialogForm.h" 40 #include <boost/algorithm/string/join.hpp> 41 #include <boost/format.hpp> 44 #include <QMessageBox> 45 #include <QtCore/QDir> 46 #include <QtCore/QFileInfo> 49 std::vector<std::string>& dependents)
51 std::vector<std::string> curDeps =
54 for(
auto dep : curDeps)
58 auto it = std::find(dependents.begin(), dependents.end(), plugin_name);
59 if(it == dependents.end())
60 dependents.push_back(plugin_name);
65 if(
const std::string*
d = boost::get_error_info<te::ErrorDescription>(e))
66 QMessageBox::warning(
nullptr,
"Plugin manager",
d->c_str());
68 QMessageBox::warning(
nullptr,
"Plugin manager",
69 QObject::tr(
"Unknown error has occurred"));
75 :
QDialog(parent, f), m_ui(new
Ui::PluginManagerDialogForm)
79 setWindowTitle(tr(
"Manage Application Plugins"));
82 labels << QObject::tr(
"Enabled") << QObject::tr(
"Plugin")
83 << QObject::tr(
"Version") << QObject::tr(
"License")
84 << QObject::tr(
"Site") << QObject::tr(
"Provider")
85 << QObject::tr(
"Provider site") << QObject::tr(
"Provider email")
86 << QObject::tr(
"Name");
88 m_ui->m_tableWidget->setColumnCount(labels.size());
89 m_ui->m_tableWidget->setHorizontalHeaderLabels(labels);
90 m_ui->m_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
96 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"plugin").pixmap(48, 48));
97 m_ui->m_addButton->setIcon(QIcon::fromTheme(
"list-add"));
98 m_ui->m_removeButton->setIcon(QIcon::fromTheme(
"list-remove"));
101 m_ui->m_helpPushButton->setPageReference(
102 "widgets/pluginmanager/PluginManager.html");
104 connect(
m_ui->m_addButton, SIGNAL(clicked()),
this,
106 connect(
m_ui->m_removeButton, SIGNAL(clicked()),
this,
108 connect(
m_ui->m_applyPushButton, SIGNAL(clicked()),
this,
110 connect(
m_ui->m_closePushButton, SIGNAL(clicked()),
this,
112 connect(
m_ui->m_enableAll, SIGNAL(stateChanged(
int)),
this,
121 int nRow =
m_ui->m_tableWidget->rowCount();
122 int nCol =
m_ui->m_tableWidget->columnCount();
124 m_ui->m_tableWidget->insertRow(nRow);
129 QCheckBox* checkBox =
new QCheckBox();
130 checkBox->setObjectName(pinfo.
name.c_str());
131 QHBoxLayout* layout =
new QHBoxLayout(widget);
134 checkBox->setVisible(
false);
135 layout->addWidget(checkBox);
136 layout->setAlignment(Qt::AlignCenter);
137 layout->setContentsMargins(0, 0, 0, 0);
138 widget->setLayout(layout);
139 m_ui->m_tableWidget->setCellWidget(nRow, PluginHeader::enabled, widget);
140 connect(checkBox, SIGNAL(stateChanged(
int)),
this,
145 QTableWidgetItem* item =
new QTableWidgetItem();
148 case PluginHeader::display_name:
149 item->setText(QString::fromUtf8(pinfo.
display_name.c_str()));
151 case PluginHeader::version:
152 item->setText(QString::fromUtf8(pinfo.
version.c_str()));
154 case PluginHeader::license_description:
157 case PluginHeader::site:
158 item->setText(QString::fromUtf8(pinfo.
site.c_str()));
160 case PluginHeader::provider_name:
161 item->setText(QString::fromUtf8(pinfo.
provider.
name.c_str()));
163 case PluginHeader::provider_site:
164 item->setText(QString::fromUtf8(pinfo.
provider.
site.c_str()));
166 case PluginHeader::provider_email:
167 item->setText(QString::fromUtf8(pinfo.
provider.
email.c_str()));
169 case PluginHeader::name:
170 item->setText(QString::fromUtf8(pinfo.
name.c_str()));
175 item->setFlags(Qt::ItemFlags(item->flags() ^ Qt::ItemIsEditable));
176 m_ui->m_tableWidget->setItem(nRow,
col, item);
178 m_ui->m_tableWidget->resizeColumnsToContents();
182 const std::string& plugin_name)
186 ->cellWidget(
getPluginRow(plugin_name), PluginHeader::enabled)
188 QCheckBox* checkBox =
189 findChild<QCheckBox*>(layout->itemAt(0)->widget()->objectName());
191 checkBox->setCheckState(
192 (checkBox->checkState() == Qt::Checked) ? Qt::Unchecked : Qt::Checked);
197 QWidget* widget =
m_ui->m_tableWidget->cellWidget(row, 0);
198 widget->setEnabled(
false);
199 int nCol =
m_ui->m_tableWidget->columnCount();
202 if(
col == PluginHeader::enabled)
205 widget->setEnabled(
false);
208 QTableWidgetItem* item =
m_ui->m_tableWidget->item(row,
col);
209 item->setFlags(Qt::ItemFlags(item->flags() ^ Qt::ItemIsEnabled));
215 std::vector<te::core::PluginInfo> loaded =
217 std::vector<te::core::PluginInfo> unloaded =
219 std::vector<te::core::PluginInfo> broken =
222 for(
int i = 0; i < (
int)loaded.size(); ++i)
225 for(
int i = 0; i < (
int)unloaded.size(); ++i)
228 for(
int i = 0; i < (
int)broken.size(); ++i)
234 QTableWidgetItem* item =
m_ui->m_tableWidget->item(
235 row, te::qt::widgets::PluginManagerDialog::PluginHeader::name);
236 std::string plugin_name = item->text().toUtf8().data();
241 const std::string& plugin_name)
243 int nRow =
m_ui->m_tableWidget->rowCount();
244 for(
int row = 0; row < nRow; ++row)
246 QTableWidgetItem* item =
m_ui->m_tableWidget->item(
247 row, te::qt::widgets::PluginManagerDialog::PluginHeader::name);
248 if(item->text().toUtf8().data() == plugin_name)
257 QTableWidgetItem* item =
m_ui->m_tableWidget->item(row, PluginHeader::name);
258 std::string plugin_name = item->text().toUtf8().data();
260 QLayout* layout =
m_ui->m_tableWidget->cellWidget(row, 0)->layout();
261 QCheckBox* checkBox =
262 findChild<QCheckBox*>(layout->itemAt(0)->widget()->objectName());
264 if(!checkBox->isEnabled())
266 if(!checkBox->isVisible())
268 if(checkBox->isChecked())
284 std::vector<te::core::PluginInfo> v_broken =
286 for(
auto broken : v_broken)
293 QCheckBox* checkBox =
294 findChild<QCheckBox*>(layout->itemAt(0)->widget()->objectName());
295 checkBox->setVisible(
true);
301 std::vector<te::core::PluginInfo> v_pInfo)
311 catch(
const boost::exception& e)
315 QLayout* layout =
m_ui->m_tableWidget->cellWidget(row, 0)->layout();
316 QCheckBox* checkBox =
317 findChild<QCheckBox*>(layout->itemAt(0)->widget()->objectName());
318 checkBox->setVisible(
false);
319 checkBox->setChecked(
false);
329 qApp->applicationDirPath(),
330 tr(
"TerraLib Plug-in Files (*.teplg.json *.TEPLG.JSON)"),
this);
344 info.absoluteFilePath().toUtf8().data());
353 throw tr(
"There's no resource selected, no plugins found.");
356 filters <<
"*.teplg.json" 359 QDir dir(info.canonicalFilePath());
361 QString qdir_s = dir.absolutePath();
363 QStringList plgs = dir.entryList(filters, QDir::Files);
367 boost::format err_msg(
368 tr(
"There is no plugin in the following directory: %1%")
372 (err_msg % dir.absolutePath().toUtf8().data()).str());
374 QStringList::iterator it;
376 for(it = plgs.begin(); it != plgs.end(); ++it)
379 dir.absoluteFilePath(*it).toUtf8().data());
387 catch(
const boost::exception& e)
391 m_ui->m_applyPushButton->setFocus();
392 m_ui->m_applyPushButton->setEnabled(
true);
397 int nRow =
m_ui->m_tableWidget->rowCount();
398 std::vector<te::core::PluginInfo> toUnload;
399 std::vector<te::core::PluginInfo> toLoad;
400 std::vector<te::core::PluginInfo> toRemove;
401 for(
int row = 0; row < nRow; ++row)
424 catch(
const boost::exception& e)
429 if(!toUnload.empty())
431 if(!toRemove.empty())
436 m_ui->m_applyPushButton->setEnabled(
false);
446 int nRow =
m_ui->m_tableWidget->rowCount();
450 for(
int row = 0; row < nRow; ++row)
453 m_ui->m_tableWidget->cellWidget(row, PluginHeader::enabled)
455 QCheckBox* checkBox =
456 findChild<QCheckBox*>(layout->itemAt(0)->widget()->objectName());
457 if(checkBox->isVisible())
458 checkBox->setChecked(
true);
462 for(
int row = 0; row < nRow; ++row)
465 m_ui->m_tableWidget->cellWidget(row, PluginHeader::enabled)
467 QCheckBox* checkBox =
468 findChild<QCheckBox*>(layout->itemAt(0)->widget()->objectName());
469 if(checkBox->isVisible())
470 checkBox->setChecked(
false);
480 QCheckBox* checkBox = qobject_cast<QCheckBox*>(QObject::sender());
481 std::string plugin_name = checkBox->objectName().toUtf8().data();
494 m_ui->m_applyPushButton->setEnabled(
true);
500 "widgets/pluginmanager/PluginManager.html",
"dpi.inpe.br.qtwidgets");
505 QModelIndexList indexList =
506 m_ui->m_tableWidget->selectionModel()->selectedIndexes();
507 for(
const auto index : indexList)
511 m_ui->m_applyPushButton->setFocus();
512 m_ui->m_applyPushButton->setEnabled(
true);
516 std::vector<te::core::PluginInfo> v_pInfo)
524 m_ui->m_tableWidget->removeRow(row);
531 int nCol =
m_ui->m_tableWidget->columnCount();
537 m_ui->m_tableWidget->item(row,
col)->setFont(font);
539 m_ui->m_tableWidget->resizeColumnsToContents();
543 std::vector<te::core::PluginInfo> v_pInfo)
546 for(
auto plugin = v_pInfo.rbegin(); plugin != v_pInfo.rend(); ++plugin)
557 QMessageBox::StandardButton reply;
558 boost::format msg(tr(
"Unloading '%1%' will unload the following:\n" 560 "Do you want to continue?")
564 std::vector<std::string> dependents;
568 std::remove(dependents.begin(), dependents.end(), plugin->name),
571 reply = QMessageBox::question(
573 (msg % plugin->name % boost::algorithm::join(dependents,
"\n"))
576 QMessageBox::Yes | QMessageBox::No);
579 if(reply == QMessageBox::Yes)
581 for(
auto it = dependents.begin(); it != dependents.end(); ++it)
583 if(*it != plugin->name)
std::string license_description
A brief description about the plugin license.
std::string email
The provider contact e-mail.
void recursiveUnload(const std::string &plugin_name)
Try to unload a given plugin and its dependents recursively.
TECOREEXPORT std::vector< PluginInfo > TopologicalSort(const std::vector< PluginInfo > &v_pinfo)
void stop(const std::string &plugin_name)
Stop a loaded plugin.
An exception indicating an error when trying to shutdown a plugin with a dependent.
void insert(const PluginInfo &pinfo)
Adds plugin with its plugin information to the list of unloaded plugins.
std::vector< PluginInfo > getBrokenPlugins() const
Return the list of plugins that could not be loaded.
Basic information about a plugin.
std::string site
The provider home page.
bool isUnloaded(const std::string &plugin_name) const
Returns true if the plugin is in the not-loaded list of plugins.
void load(const std::string &plugin_name, const bool start=true)
It tries to load the informed plugin.
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
std::string display_name
The plugin name to be displayed in a graphical interface.
std::string name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
static PluginManager & instance()
Access the singleton.
std::vector< PluginInfo > getUnloadedPlugins() const
Return the list of plugins that were not loaded.
static HelpManager & getInstance()
It returns a reference to the singleton instance.
std::vector< std::string > getDependents(const std::string plugin_name)
Return the list of plugins that depends of a given plugin.
std::string name
Provider name: may be a person or a company.
void GetDependents(const std::string &plugin_name, std::vector< std::string > &dependents)
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
bool isLoaded(const std::string &plugin_name) const
Returns true if the plugin is loaded otherwise returns false.
void ShowException(const boost::exception &e)
TECOREEXPORT PluginInfo JSONPluginInfoSerializer(const std::string &file_name)
A plugin finder that search for plugins in some special directories defined by compile time macros...
std::string site
An URL pointing to the plugin site.
void remove(const std::string &plugin_name)
Remove plugin from the manager.
std::string version
The plugin version.
A Qt dialog for plugin management.
An exception indicating that a given argument is not valid, for instance if a given item already exis...
Provider provider
Information about the plugin provider.
std::vector< PluginInfo > getLoadedPlugins() const
Return the list of plugins that are loaded.
void unload(const std::string &plugin_name)
Try to unload a given plugin.