1 // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2011 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
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>
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"
27 #include <QtCore/QDir>
28 #include <QtGui/QIcon>
29 #include <QtGui/QStyle>
30 #include <QtGui/QTreeWidgetItem>
31 #include <QMessageBox>
32 #include <QFileDialog>
35 #include "../../extension_system/iplugin_spec.h"
36 #include "../../extension_system/iplugin_manager.h"
41 PluginView::PluginView(ExtensionSystem::IPluginManager
*pluginManager
, QWidget
*parent
)
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
;
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
);
73 QList
<QTreeWidgetItem
*> items
;
74 Q_FOREACH (ExtensionSystem::IPluginSpec
*spec
, m_pluginManager
->plugins())
76 QTreeWidgetItem
*item
= new QTreeWidgetItem(QStringList()
78 << QString("%1").arg(spec
->version())
80 << QDir::toNativeSeparators(spec
->filePath()));
82 bool ok
= !spec
->hasError();
83 QIcon icon
= ok
? okIcon
: errorIcon
;
84 if (ok
&& (spec
->state() != ExtensionSystem::State::Running
))
87 item
->setIcon(m_checkStateColumn
, icon
);
89 if (!m_whiteList
.contains(spec
->name()))
90 item
->setCheckState(m_checkStateColumn
, spec
->isEnabled() ? Qt::Checked
: Qt::Unchecked
);
93 m_specToItem
.insert(spec
, item
);
94 m_itemToSpec
.insert(item
, spec
);
97 m_ui
.pluginTreeWidget
->clear();
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);
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();
129 QMessageBox::warning( this,
130 tr( "Plugin unload" ),
131 tr( "No plugin selected!" ) );
135 QMap
< QTreeWidgetItem
*, ExtensionSystem::IPluginSpec
* >::const_iterator itr
136 = m_itemToSpec
.find( item
);
137 if( itr
== m_itemToSpec
.end() )
140 bool success
= m_pluginManager
->unloadPlugin( itr
.value() );
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" ),
154 "Plugin specifications ( *.xml )" );
161 QApplication::setOverrideCursor( Qt::WaitCursor
);
162 bool success
= m_pluginManager
->loadPlugin( f
);
163 QApplication::setOverrideCursor( Qt::ArrowCursor
);
167 QMessageBox::warning( this,
168 tr( "Loading plugin" ),
169 tr( "Error loading plugin!" ) );
174 } /* namespace Core */