1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 
8 #include "prefs_plugins.h"
9 
10 #include <QCheckBox>
11 #include <QLabel>
12 #include "ui/scmwmenumanager.h"
13 #include "pluginmanager.h"
14 #include "scraction.h"
15 #include "scplugin.h"
16 #include "scribuscore.h"
17 #include "scribusdoc.h"
18 
19 #include "commonstrings.h"
20 
Prefs_Plugins(QWidget * parent,ScribusDoc * doc)21 Prefs_Plugins::Prefs_Plugins(QWidget* parent, ScribusDoc* doc)
22 	: Prefs_Pane(parent)
23 {
24 	setupUi(this);
25 	languageChange();
26 
27 	m_caption = tr("Plugins");
28 	m_icon = "plugins_16.png";
29 
30 	PluginManager& pluginManager(PluginManager::instance());
31 	//Hide this stuff as we don't want it now we are not letting people turn plugins on or off
32 	pluginTable->setColumnHidden(3, true);
33 	restartLabel->setHidden(true);
34 
35 	// Get a list of all internal plugin names, including those of disabled
36 	// plugins, then loop over them and add each one to the plugin list.
37 	QStringList pluginNames(pluginManager.pluginNames(true));
38 	pluginTable->setRowCount(pluginNames.count());
39 	ScPlugin* plugin;
40 	ScActionPlugin* ixplug;
41 	QString pName;
42 	ScribusMainWindow* scMW=ScCore->primaryMainWindow();
43 	for (int i = 0; i < pluginNames.count(); ++i)
44 	{
45 		pName = pluginNames.at(i);
46 		plugin = pluginManager.getPlugin(pName, true);
47 		Q_ASSERT(plugin); // all the returned names should represent loaded plugins
48 
49 		PluginPrefsTableItem *i0 = new PluginPrefsTableItem(plugin->fullTrName());
50 		pluginTable->setItem(i, 0, i0);
51 
52 		PluginPrefsTableItem *i1 = new PluginPrefsTableItem("");
53 		// Resident plugins don't have predefined actions
54 		if (plugin->inherits("ScActionPlugin"))
55 		{
56 			ixplug = qobject_cast<ScActionPlugin*>(plugin);
57 			Q_ASSERT(ixplug);
58 			ScActionPlugin::ActionInfo ai(ixplug->actionInfo());
59 			// menu path
60 			QString men = "";
61 			if (!ai.parentMenu.isEmpty())
62 			{
63 				if (scMW->scrMenuMgr->menuExists(ai.parentMenu))
64 					men = scMW->scrMenuMgr->getLocalPopupMenu(ai.parentMenu)->title().remove(QRegExp("&(?!&)")) + " -> ";
65 			}
66 			if (scMW->scrMenuMgr->menuExists(ai.menu))
67 			{
68 				QMenu *m=scMW->scrMenuMgr->getLocalPopupMenu(ai.menu);
69 				if (m)
70 					men += m->title().remove(QRegExp("&(?!&)")) + " -> ";
71 			}
72 			i1->setText(men + QString("%1").arg(scMW->scrActions[ai.name]->text().remove(QRegExp("&(?!&)"))));
73 		}
74 		pluginTable->setItem(i, 1, i1);
75 
76 		PluginPrefsTableItem *i2 = new PluginPrefsTableItem(plugin->pluginTypeName());
77 		pluginTable->setItem(i, 2, i2);
78 	/* Don't need this column at all now we are not allowing users to turn plugins on or off
79 		// load at start?
80 		if (plugin->inherits("ScPersistentPlugin"))
81 		{
82 			bool onStart = pluginManager.enableOnStartup(pName);
83 			//		QCheckBox *onStartCheck = new QCheckBox(onStart ? CommonStrings::trYes : CommonStrings::trNo, this);
84 			QCheckBox *onStartCheck = new QCheckBox(this);
85 			pluginTable->setCellWidget(i, 3, onStartCheck);
86 			onStartCheck->setChecked(onStart);
87 		}
88 	*/
89 
90 		PluginPrefsTableItem *i4 = new PluginPrefsTableItem(pName);
91 		pluginTable->setItem(i, 4, i4); // plugname for developers
92 		PluginPrefsTableItem *i5 = new PluginPrefsTableItem(pluginManager.getPluginPath(pName));
93 		pluginTable->setItem(i, 5, i5); // file path for developers
94 	}
95 	pluginTable->resizeColumnsToContents();
96 }
97 
98 Prefs_Plugins::~Prefs_Plugins() = default;
99 
languageChange()100 void Prefs_Plugins::languageChange()
101 {
102 }
103 
restoreDefaults(struct ApplicationPrefs * prefsData)104 void Prefs_Plugins::restoreDefaults(struct ApplicationPrefs *prefsData)
105 {
106 }
107 
saveGuiToPrefs(struct ApplicationPrefs * prefsData) const108 void Prefs_Plugins::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
109 {
110 }
111 
PluginPrefsTableItem(const QString & text)112 PluginPrefsTableItem::PluginPrefsTableItem(const QString & text)
113 	: QTableWidgetItem(text)
114 {
115 	setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
116 }
117 
118