Fix game:addSpawnShapesByZone
[ryzomcore.git] / studio / src / plugins / core / plugin_view_dialog.cpp
blob76cbc828e4dda5156b1bdae2c9586fdfab93543d
1 // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2011 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Winch Gate Property Limited
6 // Copyright (C) 2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "plugin_view_dialog.h"
22 #include "core_constants.h"
24 #include "nel/misc/debug.h"
26 // Qt includes
27 #include <QtCore/QDir>
28 #include <QtGui/QIcon>
29 #include <QtGui/QStyle>
30 #include <QtGui/QTreeWidgetItem>
31 #include <QMessageBox>
32 #include <QFileDialog>
34 // Project includes
35 #include "../../extension_system/iplugin_spec.h"
36 #include "../../extension_system/iplugin_manager.h"
38 namespace Core
41 PluginView::PluginView(ExtensionSystem::IPluginManager *pluginManager, QWidget *parent)
42 : QDialog(parent),
43 m_checkStateColumn(0)
45 m_ui.setupUi(this);
46 m_pluginManager = pluginManager;
48 connect(m_pluginManager, SIGNAL(pluginsChanged()), this, SLOT(updateList()));
49 connect(this, SIGNAL(accepted()), this, SLOT(updateSettings()));
51 connect( m_ui.pluginTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), this, SLOT( onItemClicked() ) );
52 connect( m_ui.unloadButton, SIGNAL( clicked( bool ) ), this, SLOT( onUnloadClicked() ) );
53 connect( m_ui.loadButton, SIGNAL( clicked( bool ) ), this, SLOT( onLoadClicked() ) );
55 // WhiteList is list of plugins which can not disable.
56 m_whiteList << Constants::OVQT_CORE_PLUGIN;
57 updateList();
60 PluginView::~PluginView()
64 void PluginView::updateList()
66 static QIcon okIcon = QApplication::style()->standardIcon(QStyle::SP_DialogApplyButton);
67 static QIcon errorIcon = QApplication::style()->standardIcon(QStyle::SP_DialogCancelButton);
68 static QIcon notLoadedIcon = QApplication::style()->standardIcon(QStyle::SP_DialogResetButton);
70 m_specToItem.clear();
71 m_itemToSpec.clear();
73 QList<QTreeWidgetItem *> items;
74 Q_FOREACH (ExtensionSystem::IPluginSpec *spec, m_pluginManager->plugins())
76 QTreeWidgetItem *item = new QTreeWidgetItem(QStringList()
77 << spec->name()
78 << QString("%1").arg(spec->version())
79 << spec->vendor()
80 << QDir::toNativeSeparators(spec->filePath()));
82 bool ok = !spec->hasError();
83 QIcon icon = ok ? okIcon : errorIcon;
84 if (ok && (spec->state() != ExtensionSystem::State::Running))
85 icon = notLoadedIcon;
87 item->setIcon(m_checkStateColumn, icon);
89 if (!m_whiteList.contains(spec->name()))
90 item->setCheckState(m_checkStateColumn, spec->isEnabled() ? Qt::Checked : Qt::Unchecked);
92 items.append(item);
93 m_specToItem.insert(spec, item);
94 m_itemToSpec.insert(item, spec);
97 m_ui.pluginTreeWidget->clear();
98 if (!items.isEmpty())
99 m_ui.pluginTreeWidget->addTopLevelItems(items);
101 m_ui.pluginTreeWidget->resizeColumnToContents(m_checkStateColumn);
104 void PluginView::updateSettings()
106 Q_FOREACH (ExtensionSystem::IPluginSpec *spec, m_pluginManager->plugins())
108 if (m_specToItem.contains(spec) && (!m_whiteList.contains(spec->name())))
110 QTreeWidgetItem *item = m_specToItem.value(spec);
111 if (item->checkState(m_checkStateColumn) == Qt::Checked)
112 spec->setEnabled(true);
113 else
114 spec->setEnabled(false);
119 void PluginView::onItemClicked()
121 m_ui.unloadButton->setEnabled( true );
124 void PluginView::onUnloadClicked()
126 QTreeWidgetItem *item = m_ui.pluginTreeWidget->currentItem();
127 if( item == NULL )
129 QMessageBox::warning( this,
130 tr( "Plugin unload" ),
131 tr( "No plugin selected!" ) );
132 return;
135 QMap< QTreeWidgetItem*, ExtensionSystem::IPluginSpec* >::const_iterator itr
136 = m_itemToSpec.find( item );
137 if( itr == m_itemToSpec.end() )
138 return;
140 bool success = m_pluginManager->unloadPlugin( itr.value() );
141 if( !success )
143 QMessageBox::warning( this,
144 tr( "Plugin unload" ),
145 tr( "Failed to unload plugin." ) );
149 void PluginView::onLoadClicked()
151 QString f = QFileDialog::getOpenFileName( this,
152 tr( "Loading a plugin" ),
153 ".",
154 "Plugin specifications ( *.xml )" );
156 if( f.isEmpty() )
158 return;
161 QApplication::setOverrideCursor( Qt::WaitCursor );
162 bool success = m_pluginManager->loadPlugin( f );
163 QApplication::setOverrideCursor( Qt::ArrowCursor );
165 if( !success )
167 QMessageBox::warning( this,
168 tr( "Loading plugin" ),
169 tr( "Error loading plugin!" ) );
174 } /* namespace Core */