summaryrefslogtreecommitdiffstats
path: root/quanta/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'quanta/plugins')
-rw-r--r--quanta/plugins/Makefile.am15
-rw-r--r--quanta/plugins/pluginconfig.ui270
-rw-r--r--quanta/plugins/plugineditor.ui208
-rw-r--r--quanta/plugins/quantaplugin.cpp395
-rw-r--r--quanta/plugins/quantaplugin.h128
-rw-r--r--quanta/plugins/quantapluginconfig.cpp94
-rw-r--r--quanta/plugins/quantapluginconfig.h48
-rw-r--r--quanta/plugins/quantaplugineditor.cpp240
-rw-r--r--quanta/plugins/quantaplugineditor.h79
-rw-r--r--quanta/plugins/quantaplugininterface.cpp271
-rw-r--r--quanta/plugins/quantaplugininterface.h103
11 files changed, 1851 insertions, 0 deletions
diff --git a/quanta/plugins/Makefile.am b/quanta/plugins/Makefile.am
new file mode 100644
index 00000000..bdbdd141
--- /dev/null
+++ b/quanta/plugins/Makefile.am
@@ -0,0 +1,15 @@
+noinst_LTLIBRARIES = libplugins.la
+
+METASOURCES = AUTO
+
+libplugins_la_SOURCES = quantaplugininterface.cpp quantaplugineditor.cpp quantapluginconfig.cpp quantaplugin.cpp plugineditor.ui pluginconfig.ui
+
+AM_CPPFLAGS = -I$(top_srcdir)/quanta/utility \
+ -I$(top_srcdir)/quanta/parsers \
+ -I$(top_srcdir)/quanta/src \
+ -I$(top_srcdir)/quanta/project \
+ -I$(top_srcdir)/quanta/messages \
+ -I$(top_srcdir)/lib \
+ $(KMDI_INCLUDES) $(all_includes)
+
+
diff --git a/quanta/plugins/pluginconfig.ui b/quanta/plugins/pluginconfig.ui
new file mode 100644
index 00000000..a4cc6052
--- /dev/null
+++ b/quanta/plugins/pluginconfig.ui
@@ -0,0 +1,270 @@
+<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
+<class>PluginConfig</class>
+<comment>/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+</comment>
+<author>(C) 2002 by Marc Britton &lt;consume@optushome.com.au&gt;, (C) 2003 by Andras Mantia &lt;amantia@kde.org&gt;</author>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>PluginConfig</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>560</width>
+ <height>281</height>
+ </rect>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>560</width>
+ <height>280</height>
+ </size>
+ </property>
+ <property name="caption">
+ <string>Configure Plugin</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QCheckBox" row="1" column="0">
+ <property name="name">
+ <cstring>validateCheckBox</cstring>
+ </property>
+ <property name="text">
+ <string>Validate plugin</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <spacer row="1" column="1">
+ <property name="name">
+ <cstring>Spacer10</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>247</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QGroupBox" row="0" column="0" rowspan="1" colspan="4">
+ <property name="name">
+ <cstring>GroupBox2</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <property name="midLineWidth">
+ <number>0</number>
+ </property>
+ <property name="title">
+ <string>Plugin Options</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>TextLabel3_2</cstring>
+ </property>
+ <property name="text">
+ <string>Name:</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="0" column="1" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>pluginName</cstring>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>The plugin name as it appears in the Plugins menu.</string>
+ </property>
+ </widget>
+ <widget class="KIconButton" row="0" column="3">
+ <property name="name">
+ <cstring>iconButton</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>0</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>48</width>
+ <height>48</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>48</width>
+ <height>48</height>
+ </size>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="2" column="0">
+ <property name="name">
+ <cstring>TextLabel3</cstring>
+ </property>
+ <property name="text">
+ <string>Location:</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="2" column="1" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>location</cstring>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>The exact location of the plugin. If not set the global search paths setting is used.</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="3" column="1" rowspan="1" colspan="4">
+ <property name="name">
+ <cstring>pluginFileName</cstring>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>The plugin executable or library name (with extension).</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="3" column="0">
+ <property name="name">
+ <cstring>TextLabel4_2</cstring>
+ </property>
+ <property name="text">
+ <string>File name:</string>
+ </property>
+ </widget>
+ <widget class="QComboBox" row="1" column="1" rowspan="1" colspan="4">
+ <property name="name">
+ <cstring>outputWindow</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>3</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ <widget class="QLabel" row="1" column="0">
+ <property name="name">
+ <cstring>TextLabel1</cstring>
+ </property>
+ <property name="text">
+ <string>Output window:</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" row="2" column="4">
+ <property name="name">
+ <cstring>locationButton</cstring>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>28</width>
+ <height>32767</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="5" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>readOnlyBox</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Read only part</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="4" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>textLabel1</cstring>
+ </property>
+ <property name="text">
+ <string>Input:</string>
+ </property>
+ </widget>
+ <widget class="QComboBox" row="4" column="2" rowspan="1" colspan="3">
+ <item>
+ <property name="text">
+ <string>None</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Current File</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Current File Path</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Project Folder</string>
+ </property>
+ </item>
+ <property name="name">
+ <cstring>inputBox</cstring>
+ </property>
+ </widget>
+ </grid>
+ </widget>
+ </grid>
+</widget>
+<tabstops>
+ <tabstop>pluginName</tabstop>
+ <tabstop>iconButton</tabstop>
+ <tabstop>outputWindow</tabstop>
+ <tabstop>location</tabstop>
+ <tabstop>locationButton</tabstop>
+ <tabstop>pluginFileName</tabstop>
+ <tabstop>inputBox</tabstop>
+ <tabstop>readOnlyBox</tabstop>
+ <tabstop>validateCheckBox</tabstop>
+</tabstops>
+<includes>
+ <include location="global" impldecl="in implementation">kicondialog.h</include>
+</includes>
+<slots>
+ <slot>pluginType_highlighted(const QString&amp;)</slot>
+ <slot>slotPluginTypeHighlighted(const QString&amp;)</slot>
+</slots>
+<layoutdefaults spacing="6" margin="11"/>
+<includehints>
+ <includehint>kicondialog.h</includehint>
+</includehints>
+</UI>
diff --git a/quanta/plugins/plugineditor.ui b/quanta/plugins/plugineditor.ui
new file mode 100644
index 00000000..104d9923
--- /dev/null
+++ b/quanta/plugins/plugineditor.ui
@@ -0,0 +1,208 @@
+<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
+<class>PluginEditor</class>
+<comment>/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+</comment>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>pluginEditor</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>662</width>
+ <height>306</height>
+ </rect>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>500</width>
+ <height>224</height>
+ </size>
+ </property>
+ <property name="caption">
+ <string>Edit Plugins</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>11</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>TextLabel6</cstring>
+ </property>
+ <property name="text">
+ <string>Search paths:</string>
+ </property>
+ </widget>
+ <widget class="QGroupBox" row="1" column="0" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>GroupBox3</cstring>
+ </property>
+ <property name="title">
+ <string>Plugins</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>11</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <widget class="QListView" row="0" column="1" rowspan="5" colspan="1">
+ <column>
+ <property name="text">
+ <string>Name</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Valid</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Location</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>File Name</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Output Window</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <property name="name">
+ <cstring>pluginList</cstring>
+ </property>
+ </widget>
+ <widget class="QPushButton" row="0" column="0">
+ <property name="name">
+ <cstring>addButton</cstring>
+ </property>
+ <property name="text">
+ <string>Add...</string>
+ </property>
+ <property name="default">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QPushButton" row="1" column="0">
+ <property name="name">
+ <cstring>configureButton</cstring>
+ </property>
+ <property name="text">
+ <string>Configure...</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" row="2" column="0">
+ <property name="name">
+ <cstring>removeButton</cstring>
+ </property>
+ <property name="text">
+ <string>Remove</string>
+ </property>
+ </widget>
+ <spacer row="3" column="0">
+ <property name="name">
+ <cstring>Spacer2</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>67</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QPushButton" row="4" column="0">
+ <property name="name">
+ <cstring>refreshButton</cstring>
+ </property>
+ <property name="text">
+ <string>Refresh</string>
+ </property>
+ </widget>
+ </grid>
+ </widget>
+ <widget class="QPushButton" row="0" column="2">
+ <property name="name">
+ <cstring>addSearchPathButton</cstring>
+ </property>
+ <property name="text">
+ <string>Add...</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="0" column="1">
+ <property name="name">
+ <cstring>searchPaths</cstring>
+ </property>
+ </widget>
+ </grid>
+</widget>
+<tabstops>
+ <tabstop>searchPaths</tabstop>
+ <tabstop>addSearchPathButton</tabstop>
+ <tabstop>addButton</tabstop>
+ <tabstop>configureButton</tabstop>
+ <tabstop>removeButton</tabstop>
+ <tabstop>refreshButton</tabstop>
+ <tabstop>pluginList</tabstop>
+</tabstops>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>
diff --git a/quanta/plugins/quantaplugin.cpp b/quanta/plugins/quantaplugin.cpp
new file mode 100644
index 00000000..89cde63f
--- /dev/null
+++ b/quanta/plugins/quantaplugin.cpp
@@ -0,0 +1,395 @@
+/***************************************************************************
+ quantaplugin.cpp - Base class for quanta plugins
+ -------------------
+ begin : Mon Sep 16 2002
+ copyright : (C) 2002 by Marc Britton <consume@optushome.com.au>
+ (C) 2003-2004 by Andras Mantia <amantia@kde.org>
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+/* KDE INCLUDES */
+#include <kstandarddirs.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kaction.h>
+#include <kparts/componentfactory.h>
+#include <kparts/part.h>
+#include <klocale.h>
+#include <kdockwidget.h>
+#include <kdebug.h>
+#include <kmessagebox.h>
+
+/* QT INCLUDES */
+#include <qstring.h>
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <qwidget.h>
+#include <qwidgetstack.h>
+#include <qstringlist.h>
+#include <qobject.h>
+
+/* OTHER INCLUDES */
+#include "quantaplugin.h"
+#include "resource.h"
+#include "quanta.h"
+#include "quantaview.h"
+#include "document.h"
+#include "quantacommon.h"
+#include "resource.h"
+#include "messageoutput.h"
+#include "project.h"
+
+#include "viewmanager.h"
+
+
+QuantaPlugin::QuantaPlugin()
+ : m_isRunning(false)
+{
+ m_readOnlyPart = true;
+ m_action = 0L;
+ m_icon = "";
+ m_part = 0L;
+ m_view = 0L;
+ m_pluginToolView = 0L;
+ m_targetWidget = 0L;
+}
+
+QuantaPlugin::~QuantaPlugin()
+{
+ unload();
+}
+
+/** Sets the superficial name of the plugin */
+void QuantaPlugin::setPluginName(const QString &a_name)
+{
+ m_name = a_name;
+ if (!m_action)
+ {
+ m_action = new KToggleAction(i18n(a_name.utf8()), 0, this, SLOT(toggle()), quantaApp->actionCollection(), a_name);
+ }
+ m_action->setText(a_name);
+}
+
+QString QuantaPlugin::pluginName() const
+{
+ return m_name;
+}
+
+void QuantaPlugin::setLocation(const QString &a_location)
+{
+ m_location = a_location;
+}
+
+QString QuantaPlugin::location() const
+{
+ return m_location;
+}
+
+bool QuantaPlugin::load()
+{
+ if(isLoaded())
+ return false;
+
+ QString loc = location();
+ if(loc.isEmpty())
+ {
+ KStandardDirs *dirs = QuantaCommon::pluginDirs("lib");
+ loc = dirs->findResource("lib", fileName());
+ delete dirs;
+ }
+ else
+ {
+ loc += QString("/") + fileName();
+ }
+
+ QFileInfo partInfo(loc);
+ QString ow = outputWindow();
+ m_targetWidget = new QWidget(quantaApp);
+ if (m_readOnlyPart)
+ m_part = KParts::ComponentFactory::createPartInstanceFromLibrary<KParts::ReadOnlyPart>(partInfo.baseName().latin1(), m_targetWidget, 0, m_targetWidget, 0 );
+ else
+ m_part = KParts::ComponentFactory::createPartInstanceFromLibrary<KParts::ReadWritePart>(partInfo.baseName().latin1(), m_targetWidget, 0, m_targetWidget, 0 );
+ if(!m_part)
+ {
+ KMessageBox::error(quantaApp, i18n("<qt>The <b>%1</b> plugin could not be loaded.<br>Possible reasons are:<br> - <b>%2</b> is not installed;<br> - the file <i>%3</i> is not installed or it is not reachable.").arg(m_name).arg(m_name).arg(m_fileName));
+ delete m_targetWidget;
+ m_targetWidget = 0L;
+ return false;
+ }
+ m_part->setName(m_name); // for better debug output
+ m_part->widget()->setName(m_name); //needed to be able to dock the same plugin twice in separate toolviews
+ m_part->widget()->setFocusPolicy(QWidget::ClickFocus);
+ quantaApp->slotNewPart(m_part, false); // register the part in the partmanager
+ return true;
+}
+
+bool QuantaPlugin::run()
+{
+ if(!isLoaded())
+ load();
+
+ if(isLoaded())
+ {
+ bool result = true;
+ QuantaView *view = ViewManager::ref()->activeView();
+ if (view->document())
+ {
+ switch (m_input)
+ {
+ case 1: { result = m_part->openURL(view->document()->url());
+ break;
+ }
+ case 2: { KURL url = view->document()->url();
+ url.setPath(url.directory());
+ url.adjustPath(1);
+ result = m_part->openURL(url);
+ break;
+ }
+ case 3: { KURL url;
+ if ( Project::ref()->hasProject() &&
+ (Project::ref()->contains(view->document()->url()) ||
+ view->document()->isUntitled())
+ )
+ {
+ url = Project::ref()->projectBaseURL();
+ }
+ else
+ {
+ url = view->document()->url();
+ url.setPath(url.directory());
+ url.adjustPath(1);
+ }
+ result = m_part->openURL(url);
+ break;
+ }
+ default: ;
+ }
+ } else
+ {
+ if (m_input == 3 && (Project::ref()->hasProject())) //open project dir
+ result = m_part->openURL(Project::ref()->projectBaseURL());
+ }
+ if (!result)
+ {
+ unload(false);
+ return false;
+ }
+ addWidget();
+ setRunning(true);
+ connect( m_part, SIGNAL(setStatusBarText(const QString &)),
+ quantaApp, SLOT(slotStatusMsg( const QString & )));
+
+
+ emit pluginStarted();
+
+ return true;
+ }
+ return false;
+}
+
+bool QuantaPlugin::toggle()
+{
+ if (isLoaded())
+ {
+ return unload();
+ } else
+ {
+ bool result = run();
+ if (!result)
+ {
+ m_action->blockSignals(true);
+ m_action->setChecked(false);
+ m_action->blockSignals(false);
+ }
+ return result;
+ }
+}
+
+/** Returns the file name of the plugin */
+QString QuantaPlugin::fileName() const
+{
+ return m_fileName;
+}
+
+/** Sets the file name of the plugin */
+void QuantaPlugin::setFileName(const QString &a_fileName)
+{
+ m_fileName = a_fileName;
+}
+
+/** Sets the output window */
+void QuantaPlugin::setOutputWindow(const QString &a_outputWindow)
+{
+ m_outputWindow = a_outputWindow;
+}
+
+/** Gets the output window */
+QString QuantaPlugin::outputWindow() const
+{
+ return m_outputWindow;
+}
+
+bool QuantaPlugin::validatePlugin(QuantaPlugin *a_plugin)
+{
+ if(a_plugin)
+ {
+ return QuantaPlugin::validatePluginInfo(a_plugin->pluginName(),
+ a_plugin->location(), a_plugin->fileName(),
+ a_plugin->outputWindow());
+ }
+ return false;
+}
+
+/** Returns true if the information of a plugin is valid, otherwise false */
+bool QuantaPlugin::validatePluginInfo(const QString & /*a_name*/,
+ const QString &a_location, const QString &a_fileName, const QString &/*a_outputWindow*/)
+{
+ bool valid = true;
+ // look the file up if location is null
+ if(!a_location.isEmpty())
+ {
+ QString path = a_location + QString("/") + a_fileName;
+
+ QFileInfo pluginFile(path);
+ if(!pluginFile.exists())
+ valid = false;
+ /* TODO : What other tests should we perform? Permissions etc? */
+ }
+ else
+ {
+ if (valid)
+ {
+ KStandardDirs *dirs = QuantaCommon::pluginDirs("lib");
+ if(dirs->findResource("lib", a_fileName).isNull())
+ valid = false;
+ delete dirs;
+ }
+ }
+ return valid; // past all tests, valid
+}
+
+/** Returns whether the plugin is loaded or not */
+bool QuantaPlugin::isLoaded()
+{
+ return m_targetWidget != 0L;
+}
+
+bool QuantaPlugin::unload(bool remove)
+{
+ if(!isLoaded())
+ return false;
+
+ disconnect( m_part, SIGNAL(setStatusBarText(const QString &)),
+ quantaApp, SLOT(slotStatusMsg( const QString & )));
+
+ delete (KParts::ReadOnlyPart*) m_part;
+ m_part = 0;
+ delete m_targetWidget;
+ m_targetWidget = 0L;
+ setRunning(false);
+
+ emit pluginStopped();
+
+ m_action->setChecked(false);
+ if (remove)
+ removeWidget();
+ return true;
+}
+
+bool QuantaPlugin::isRunning() const
+{
+ return m_isRunning;
+}
+
+void QuantaPlugin::setRunning(bool a_enable)
+{
+ m_isRunning = a_enable;
+}
+
+/** Sets the plugin's standard attribute */
+void QuantaPlugin::setStandard(bool isStandard)
+{
+ m_standard = isStandard;
+}
+
+/** Gets the plugin's standard attribute */
+bool QuantaPlugin::isStandard() const
+{
+ return m_standard;
+}
+
+/** No descriptions */
+QString QuantaPlugin::standardName()
+{
+ return m_standardName;
+}
+/** No descriptions */
+void QuantaPlugin::setStandardName(const QString& a_stdName)
+{
+ m_standardName = a_stdName;
+}
+/** No descriptions */
+QString QuantaPlugin::icon()
+{
+ return m_icon;
+}
+/** No descriptions */
+void QuantaPlugin::setIcon(const QString& a_icon)
+{
+ m_icon = a_icon;
+ if (m_action) m_action->setIcon(a_icon);
+}
+
+void QuantaPlugin::addWidget()
+{
+ QString ow = outputWindow();
+ if(ow == i18n("Separate Toolview"))
+ {
+ m_part->widget()->setCaption(m_name);
+ m_part->widget()->setIcon(SmallIcon(m_icon));
+ m_pluginToolView = quantaApp->addToolWindow(m_part->widget(), quantaApp->prevDockPosition(m_part->widget(), KDockWidget::DockBottom), quantaApp->getMainDockWidget());
+ m_pluginToolView->show();
+ } else
+ {
+ m_view = ViewManager::ref()->createView();
+ m_view->addPlugin(this);
+ }
+}
+
+void QuantaPlugin::removeWidget()
+{
+ QString ow = outputWindow();
+ if(ow == i18n("Separate Toolview"))
+ {
+ delete m_pluginToolView;
+ m_pluginToolView = 0L;
+ ViewManager::ref()->activeView()->setFocus();
+ } else
+ {
+ ViewManager::ref()->removeView(m_view, true);
+ }
+}
+
+QWidget *QuantaPlugin::widget()
+{
+ if (isLoaded()) {
+ return m_part->widget();
+ } else {
+ return NULL;
+ }
+}
+
+void QuantaPlugin::plugAction(QPopupMenu *menu)
+{
+ m_action->plug(menu);
+}
+
+#include "quantaplugin.moc"
diff --git a/quanta/plugins/quantaplugin.h b/quanta/plugins/quantaplugin.h
new file mode 100644
index 00000000..08b4dbdc
--- /dev/null
+++ b/quanta/plugins/quantaplugin.h
@@ -0,0 +1,128 @@
+/***************************************************************************
+ quantaplugin.h - description
+ -------------------
+ begin : Mon Sep 16 2002
+ copyright : (C) 2002 by Marc Britton <consume@optushome.com.au>
+ (C) 2003-2004 by Andras Mantia <amantia@kde.org>
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef QUANTAPLUGIN_H
+#define QUANTAPLUGIN_H
+
+/* KDE INCLUDES */
+#include <kparts/part.h>
+
+/* QT INCLUDES */
+#include <qguardedptr.h>
+#include <qobject.h>
+
+class QString;
+
+/**Base class for quanta plugins
+ *@author Marc Britton
+ */
+
+class KToggleAction;
+class KMdiToolViewAccessor;
+
+class QuantaView;
+
+class QuantaPlugin : public QObject
+{
+ Q_OBJECT
+public:
+ QuantaPlugin();
+ ~QuantaPlugin();
+ virtual bool isRunning() const;
+ /** Gets the superficial plugin name */
+ virtual QString pluginName() const;
+ /** Gets the location of the plugin */
+ virtual QString location() const;
+ /** Gets the plugin's standard attribute */
+ virtual bool isStandard() const;
+ /** Gets the output window */
+ virtual QString outputWindow() const;
+ /** Returns true if the plugin specified by a_plugin is valid, false otherwise */
+ static bool validatePlugin(QuantaPlugin *);
+ /** Returns true if the options of a plugin are valid, otherwise false */
+ static bool validatePluginInfo(const QString &, const QString &,
+ const QString &, const QString &);
+
+ virtual void addWidget();
+ virtual void removeWidget();
+ QWidget *widget();
+ KParts::ReadOnlyPart *part() {return m_part;}
+ QString name() {return m_name;}
+ /** plugs action into menu */
+ void plugAction(QPopupMenu *menu);
+public slots:
+ /** Sets whether the plugin is running or not */
+ virtual void setRunning(bool);
+ /** Loads the plugin */
+ virtual bool load();
+ /** Unloads te plugin. If remove is true, it will also remove the plugin widget. */
+ virtual bool unload(bool remove = true);
+ /** Runs the plugin */
+ virtual bool run();
+ /** Runs the plugin if it's not running yet, unloads otherwise.*/
+ virtual bool toggle();
+ /** Sets the superficial name of the plugin */
+ virtual void setPluginName(const QString &);
+ /** Sets the output window */
+ virtual void setOutputWindow(const QString &);
+ /** Sets the plugin's standard attribute */
+ virtual void setStandard(bool isStandard);
+ /** Sets the location of the plugin */
+ virtual void setLocation(const QString &);
+ /** Sets the file name of the plugin */
+ virtual void setFileName(const QString &);
+ /** Returns the file name of the plugin */
+ virtual QString fileName() const;
+ virtual int input() {return m_input;}
+ virtual void setInput(int a_input) { m_input = a_input;}
+ /** Returns whether the plugin is loaded or not */
+ virtual bool isLoaded();
+ /** No descriptions */
+ void setIcon(const QString& a_icon);
+ /** No descriptions */
+ QString icon();
+ /** No descriptions */
+ void setStandardName(const QString& a_stdName);
+ /** No descriptions */
+ QString standardName();
+ void setReadOnlyPart(bool a_readOnlyPart) {m_readOnlyPart = a_readOnlyPart;}
+ bool readOnlyPart() {return m_readOnlyPart;}
+signals:
+ void pluginStarted();
+ void pluginStopped();
+protected:
+ /** Superficial name of plugin */
+ QString m_fileName;
+ QString m_name;
+ QString m_location;
+ QString m_icon;
+ QString m_outputWindow;
+ int m_input;
+ /** True, if it is not a user added plugin. Special handling code may be necessary for standard plugins. */
+ bool m_standard;
+ bool m_isRunning;
+ QGuardedPtr<KParts::ReadOnlyPart> m_part;
+ bool m_readOnlyPart;
+ QuantaView *m_view;
+ KToggleAction *m_action;
+private: // Private attributes
+ QString m_standardName;
+ KMdiToolViewAccessor* m_pluginToolView;
+ QWidget *m_targetWidget; //this will be the parent, used only to make the plugin widget hidden until addWidget is called
+};
+
+#endif
diff --git a/quanta/plugins/quantapluginconfig.cpp b/quanta/plugins/quantapluginconfig.cpp
new file mode 100644
index 00000000..a03ffc2c
--- /dev/null
+++ b/quanta/plugins/quantapluginconfig.cpp
@@ -0,0 +1,94 @@
+/***************************************************************************
+ quantapluginconfig.cpp - description
+ -------------------
+ begin : Sat Sep 21 2002
+ copyright : (C) 2002 by Marc Britton <consume@optushome.com.au>
+ (C) 2003-2004 by Andras Mantia <amantia@kde.org>
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+/* KDE INCLUDES */
+#include <kdialogbase.h>
+#include <kfiledialog.h>
+#include <kmessagebox.h>
+#include <klocale.h>
+#include <kicondialog.h>
+
+/* QT INCLUDES */
+#include <qpushbutton.h>
+#include <qcheckbox.h>
+#include <qlineedit.h>
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qcombobox.h>
+#include <qwidgetstack.h>
+
+/* OTHER INCLUDES */
+#include "quantapluginconfig.h"
+#include "quantaplugin.h"
+#include "pluginconfig.h"
+
+QuantaPluginConfig::QuantaPluginConfig(QWidget *a_parent, const char *a_name)
+ : KDialogBase(a_parent, a_name, true, i18n("Configure Plugin"), KDialogBase::Ok | KDialogBase::Cancel)
+{
+ m_pluginConfigWidget = new PluginConfig(this);
+
+ QStringList windows;
+ i18n("Message Area Tab");
+ windows << i18n("Editor Tab") << i18n("Separate Toolview");
+ m_pluginConfigWidget->outputWindow->insertStringList(windows);
+ m_pluginConfigWidget->iconButton->setStrictIconSize(false);
+
+ connect(m_pluginConfigWidget->pluginName, SIGNAL(textChanged(const QString &)), this, SLOT(nameChanged(const QString &)));
+ connect(m_pluginConfigWidget->locationButton, SIGNAL(clicked()), this, SLOT(selectLocation()));
+
+ setMainWidget(m_pluginConfigWidget);
+}
+
+QuantaPluginConfig::~QuantaPluginConfig()
+{
+}
+
+void QuantaPluginConfig::accept()
+{
+ if(m_pluginConfigWidget->validateCheckBox->isChecked())
+ {
+ bool isValid = QuantaPlugin::validatePluginInfo(m_pluginConfigWidget->pluginName->text(), m_pluginConfigWidget->location->text(), m_pluginConfigWidget->pluginFileName->text(), m_pluginConfigWidget->outputWindow->currentText());
+
+ if(!isValid)
+ {
+ int answer = KMessageBox::questionYesNo(this, i18n("The plugin information you entered appears to be invalid. Are you sure you want to apply these settings?"), i18n("Invalid Plugin"), KStdGuiItem::apply(), i18n("Do Not Apply"));
+
+ if(answer == KMessageBox::No)
+ return;
+ }
+ }
+ KDialogBase::accept();
+}
+
+/** Gets the plugin location */
+void QuantaPluginConfig::selectLocation()
+{
+ QString pluginLocation = KFileDialog::getExistingDirectory(QString::null, this, i18n("Select Plugin Folder"));
+ if(!pluginLocation.isNull())
+ {
+ m_pluginConfigWidget->location->setText(pluginLocation);
+ }
+}
+
+void QuantaPluginConfig::nameChanged(const QString &a_text)
+{
+ QString text = a_text;
+ text = "lib" + text + ".la";
+ m_pluginConfigWidget->pluginFileName->setText(text.lower());
+}
+
+#include "quantapluginconfig.moc"
diff --git a/quanta/plugins/quantapluginconfig.h b/quanta/plugins/quantapluginconfig.h
new file mode 100644
index 00000000..f56142e9
--- /dev/null
+++ b/quanta/plugins/quantapluginconfig.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ quantapluginconfig.h - description
+ -------------------
+ begin : Sat Sep 21 2002
+ copyright : (C) 2002 by Marc Britton <consume@optushome.com.au>
+ (C) 2003 by Andras Mantia <amantia@kde.org>
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef QUANTAPLUGINCONFIG_H
+#define QUANTAPLUGINCONFIG_H
+
+class PluginConfig;
+class KDialogBase;
+
+/**Dialog to configure a plugin's options
+ *@author Marc Britton
+ */
+
+class QString;
+
+class QuantaPluginConfig : public KDialogBase
+{
+ Q_OBJECT
+public:
+ QuantaPluginConfig(QWidget *, const char *);
+ ~QuantaPluginConfig();
+public slots:
+ /** Validates the dialog before accepting */
+ void accept();
+ /** Gets the plugin location */
+ void selectLocation();
+ /** Updates other widgets based on the name */
+ void nameChanged(const QString &);
+
+protected:
+ PluginConfig *m_pluginConfigWidget;
+};
+
+#endif
diff --git a/quanta/plugins/quantaplugineditor.cpp b/quanta/plugins/quantaplugineditor.cpp
new file mode 100644
index 00000000..e7c32ec0
--- /dev/null
+++ b/quanta/plugins/quantaplugineditor.cpp
@@ -0,0 +1,240 @@
+/***************************************************************************
+ quantaplugineditor.cpp - description
+ -------------------
+ begin : Fri Sep 20 2002
+ copyright : (C) 2002 by Marc Britton <consume@optushome.com.au>
+ (C) 2003 by Andras Mantia <amantia@kde.org>
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+/* KDE INCLUDES */
+#include <kfiledialog.h>
+#include <kiconloader.h>
+#include <kglobal.h>
+#include <klocale.h>
+#include <kicondialog.h>
+#include <kdialogbase.h>
+
+/* QT INCLUDES */
+#include <qwidget.h>
+#include <qobject.h>
+#include <qdict.h>
+#include <qcheckbox.h>
+#include <qpushbutton.h>
+#include <qlineedit.h>
+#include <qcombobox.h>
+#include <qlistview.h>
+
+/* OTHER INCLUDES */
+#include "quantaplugineditor.h"
+#include "quantaplugin.h"
+#include "quantapluginconfig.h"
+#include "pluginconfig.h"
+#include "plugineditor.h"
+#include "resource.h"
+
+QuantaPluginEditor::QuantaPluginEditor(QWidget *a_parent, const char *a_name)
+ : KDialogBase(a_parent, a_name, true, i18n("Edit Plugins"), KDialogBase::Ok | KDialogBase::Cancel)
+{
+ // m_plugins.setAutoDelete(true);
+
+ m_pluginEditorWidget = new PluginEditor(this);
+ setMainWidget(m_pluginEditorWidget);
+ m_pluginEditorWidget->pluginList->setSelectionMode(QListView::Single);
+ m_pluginEditorWidget->pluginList->setAllColumnsShowFocus(true);
+ m_pluginEditorWidget->pluginList->setColumnAlignment(2, Qt::AlignHCenter);
+
+ connect(this, SIGNAL(pluginsChanged()), SLOT(refreshPlugins()));
+ connect(m_pluginEditorWidget->refreshButton, SIGNAL(clicked()), SLOT(refreshPlugins()));
+ connect(m_pluginEditorWidget->addButton, SIGNAL(clicked()), SLOT(addPlugin()));
+ connect(m_pluginEditorWidget->removeButton, SIGNAL(clicked()), SLOT(removePlugin()));
+ connect(m_pluginEditorWidget->addSearchPathButton, SIGNAL(clicked()), SLOT(addSearchPath()));
+ connect(m_pluginEditorWidget->configureButton, SIGNAL(clicked()), SLOT(configurePlugin()));
+ connect(m_pluginEditorWidget->pluginList, SIGNAL(doubleClicked(QListViewItem*, const QPoint&, int)),
+ SLOT(configurePlugin(QListViewItem*, const QPoint&, int)));
+}
+
+QuantaPluginEditor::~QuantaPluginEditor()
+{
+}
+
+QDict<QuantaPlugin> QuantaPluginEditor::plugins()
+{
+ return m_plugins;
+}
+
+void QuantaPluginEditor::addPlugin()
+{
+ // new plugin config menu
+ // create new plugin and add to list
+ QuantaPluginConfig *configDlg = new QuantaPluginConfig(this, "pluginConfig");
+ PluginConfig *configWidget = static_cast<PluginConfig*>(configDlg->mainWidget());
+
+ if(configDlg->exec())
+ {
+ // plugin accepted, create the proper type
+ QuantaPlugin *newPlugin = 0;
+ newPlugin = new QuantaPlugin();
+
+ newPlugin->setPluginName(configWidget->pluginName->text());
+ newPlugin->setFileName(configWidget->pluginFileName->text());
+ newPlugin->setLocation(configWidget->location->text());
+ newPlugin->setOutputWindow(configWidget->outputWindow->currentText());
+ newPlugin->setStandard(false);
+ newPlugin->setIcon(configWidget->iconButton->icon());
+ QString pluginName = newPlugin->pluginName();
+ m_plugins.insert(pluginName, newPlugin);
+ emit pluginsChanged();
+ }
+ delete configDlg;
+}
+
+void QuantaPluginEditor::addSearchPath()
+{
+ // Get a dir and append it to the line edit
+ QString appendDir = KFileDialog::getExistingDirectory(QString::null, 0, i18n("Select Folder"));
+ if(!appendDir.isNull())
+ {
+ m_pluginEditorWidget->searchPaths->setText(m_pluginEditorWidget->searchPaths->text()+appendDir+":");
+ }
+}
+
+void QuantaPluginEditor::configurePlugin()
+{
+ // create a new config dialog. populate with plugin data
+ QString key;
+ QListViewItem *item = m_pluginEditorWidget->pluginList->currentItem();
+ if(item)
+ key = item->text(0);
+
+ if(!key.isNull() && m_plugins.find(key))
+ {
+ QuantaPluginConfig *configDlg = new QuantaPluginConfig(this, "pluginConfig");
+ QuantaPlugin *curPlugin = m_plugins.find(key);
+ PluginConfig *configWidget = static_cast<PluginConfig*>(configDlg->mainWidget());
+
+ configWidget->outputWindow->setCurrentText(curPlugin->outputWindow());
+ configWidget->pluginName->setText(curPlugin->pluginName());
+ configWidget->pluginFileName->setText(curPlugin->fileName());
+ configWidget->location->setText(curPlugin->location());
+ configWidget->iconButton->setIcon(curPlugin->icon());
+ configWidget->inputBox->setCurrentItem(curPlugin->input());
+ configWidget->readOnlyBox->setChecked(curPlugin->readOnlyPart());
+
+ if(configDlg->exec())
+ {
+ curPlugin->setPluginName(configWidget->pluginName->text());
+ curPlugin->setFileName(configWidget->pluginFileName->text());
+ curPlugin->setLocation(configWidget->location->text());
+ curPlugin->setOutputWindow(configWidget->outputWindow->currentText());
+ curPlugin->setIcon(configWidget->iconButton->icon());
+ curPlugin->setInput(configWidget->inputBox->currentItem());
+ curPlugin->setReadOnlyPart(configWidget->readOnlyBox->isChecked());
+ }
+
+ delete configDlg;
+
+ emit pluginsChanged();
+ }
+}
+
+void QuantaPluginEditor::configurePlugin(QListViewItem* item, const QPoint&, int)
+{
+ if (item)
+ configurePlugin();
+}
+
+void QuantaPluginEditor::refreshPlugins()
+{
+ // call validate on all plugins to refresh their status
+ m_pluginEditorWidget->pluginList->clear();
+
+ QDictIterator<QuantaPlugin> it(m_plugins);
+ for(;it.current();++it)
+ {
+ QListViewItem *newItem = new PluginEditorItem(m_pluginEditorWidget->pluginList);
+ QuantaPlugin *curPlugin = it.current();
+
+ newItem->setText(0, curPlugin->pluginName());
+
+ QPixmap statusIcon;
+ bool isValid = QuantaPlugin::validatePlugin(curPlugin);
+ if(isValid)
+ statusIcon = SmallIcon("ok", KGlobal::instance());
+ else
+ statusIcon = SmallIcon("no", KGlobal::instance());
+ newItem->setPixmap(1, statusIcon);
+
+ newItem->setText(2, curPlugin->location());
+ newItem->setText(3, curPlugin->fileName());
+ newItem->setText(4, curPlugin->outputWindow());
+
+ m_pluginEditorWidget->pluginList->insertItem(newItem);
+ }
+}
+
+void QuantaPluginEditor::removePlugin()
+{
+ QListViewItem *currentItem = m_pluginEditorWidget->pluginList->currentItem();
+ if (currentItem)
+ {
+ QuantaPlugin *plugin = m_plugins.find(currentItem->text(0));
+ if(plugin)
+ {
+ m_plugins.remove(plugin->pluginName());
+ delete plugin;
+ emit pluginsChanged();
+ }
+ }
+}
+
+void QuantaPluginEditor::setPlugins(QDict<QuantaPlugin> a_plugins)
+{
+ m_plugins = a_plugins;
+
+ emit pluginsChanged();
+}
+
+PluginEditorItem::PluginEditorItem(QListView *a_parent)
+ : QListViewItem(a_parent)
+{
+}
+
+void PluginEditorItem::paintCell(QPainter *a_painter, const QColorGroup &a_cg, int a_column, int a_width, int a_align)
+{
+/*
+ if(a_column == 2)
+ a_align = Qt::AlignCenter;
+ FIXME : Why won't QT let us align cell contents?
+*/
+ QListViewItem::paintCell(a_painter, a_cg, a_column, a_width, a_align);
+}
+
+/** No descriptions */
+void QuantaPluginEditor::setSearchPaths(const QStringList& paths)
+{
+ QString str;
+ for (uint i =0; i < paths.count(); i++)
+ {
+ str += paths[i] +":";
+ }
+ m_pluginEditorWidget->searchPaths->setText(str);
+}
+/** No descriptions */
+QStringList QuantaPluginEditor::searchPathList()
+{
+ QString str = m_pluginEditorWidget->searchPaths->text();
+ QStringList paths = QStringList::split(":",str);
+
+ return paths;
+}
+
+#include "quantaplugineditor.moc"
diff --git a/quanta/plugins/quantaplugineditor.h b/quanta/plugins/quantaplugineditor.h
new file mode 100644
index 00000000..fc028056
--- /dev/null
+++ b/quanta/plugins/quantaplugineditor.h
@@ -0,0 +1,79 @@
+/***************************************************************************
+ quantaplugineditor.h - description
+ -------------------
+ begin : Fri Sep 20 2002
+ copyright : (C) 2002 by Marc Britton <consume@optushome.com.au>
+ (C) 2003 by Andras Mantia <amantia@kde.org>
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef QUANTAPLUGINEDITOR_H
+#define QUANTAPLUGINEDITOR_H
+
+/* KDE INCLUDES */
+#include <kdialogbase.h>
+
+/* QT INCLUDES */
+#include <qdict.h>
+#include <qlistview.h>
+
+/* OTHER INCLUDES */
+#include "quantaplugin.h"
+#include "plugineditor.h"
+
+/**Editor for the plugins that manages configuration
+ *@author Marc Britton
+ */
+
+/* FORWARD DECLARATIONS */
+class QWidget;
+class QListView;
+class KDialogBase;
+class PluginEditor;
+
+class QuantaPluginEditor : public KDialogBase
+{
+ Q_OBJECT
+
+public:
+ QuantaPluginEditor(QWidget *, const char *);
+ ~QuantaPluginEditor();
+ QDict<QuantaPlugin> plugins();
+ /** No descriptions */
+ QStringList searchPathList();
+ /** No descriptions */
+ void setSearchPaths(const QStringList& paths);
+
+signals:
+ void pluginsChanged();
+
+public slots:
+ void setPlugins(QDict<QuantaPlugin>);
+ void addSearchPath();
+ void addPlugin();
+ void removePlugin();
+ void configurePlugin();
+ void configurePlugin(QListViewItem*, const QPoint&, int);
+ void refreshPlugins();
+
+protected:
+ QDict<QuantaPlugin> m_plugins;
+ PluginEditor *m_pluginEditorWidget;
+};
+
+class PluginEditorItem : public QListViewItem
+{
+public:
+ PluginEditorItem(QListView *);
+ virtual void paintCell(QPainter *, const QColorGroup &, int, int, int);
+};
+
+#endif
diff --git a/quanta/plugins/quantaplugininterface.cpp b/quanta/plugins/quantaplugininterface.cpp
new file mode 100644
index 00000000..45fb8caa
--- /dev/null
+++ b/quanta/plugins/quantaplugininterface.cpp
@@ -0,0 +1,271 @@
+/***************************************************************************
+ quantaplugininterface.cpp - General interface to the plugin system
+ -------------------
+ begin : Mon Sep 16 2002
+ copyright : (C) 2002 by Marc Britton <consume@optushome.com.au>
+ (C) 2003-2004 by Andras Mantia <amantia@kde.org>
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+/* KDE INCLUDES */
+#include <kactioncollection.h>
+#include <kconfig.h>
+#include <kstandarddirs.h>
+#include <kmainwindow.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kmessagebox.h>
+
+/* QT INCLUDES */
+#include <qdict.h>
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qfileinfo.h>
+
+/* OTHER INCLUDES */
+#include "quantaplugininterface.h"
+#include "quantaplugineditor.h"
+#include "quantaplugin.h"
+
+#include "resource.h"
+#include "quantacommon.h"
+
+QuantaPluginInterface::QuantaPluginInterface(QWidget *parent)
+{
+ m_parent = parent;
+ (void) new KAction( i18n( "Configure &Plugins..." ), 0, 0,
+ this, SLOT( slotPluginsEdit() ),
+ ((KMainWindow*)parent)->actionCollection(), "configure_plugins" );
+ m_pluginMenu = 0L;
+ // m_plugins.setAutoDelete(true);
+}
+
+QuantaPluginInterface::~QuantaPluginInterface()
+{
+ m_plugins.clear();
+ // TODO : free plugins
+}
+
+void QuantaPluginInterface::readConfigFile(const QString& configFile)
+{
+ KConfig *config = new KConfig(configFile);
+ config->setGroup("General");
+ QStringList pList = config->readListEntry("Plugins");
+ for(QStringList::Iterator it = pList.begin();it != pList.end(); ++it)
+ (*it) = (*it).stripWhiteSpace();
+ //setPluginNames(pList);
+
+ QStringList paths = QuantaCommon::readPathListEntry(config, "SearchPaths");
+ for(QStringList::Iterator it = paths.begin();it != paths.end(); ++it)
+ (*it) = (*it).stripWhiteSpace();
+ qConfig.pluginSearchPaths = paths;
+
+ // now that we have a list of the plugins, go through and get the details of them
+ for(QStringList::Iterator it = pList.begin();it != pList.end();++it)
+ {
+ if (m_plugins.find(*it))
+ continue;
+ config->setGroup(*it);
+
+ QuantaPlugin *newPlugin = 0;
+ QString pluginType = config->readEntry("Type", "KPart");
+ bool isStandard = config->readBoolEntry("Standard",false);
+/* if (isStandard)
+ {
+ QString stdName = config->readEntry("Standard Name");
+ if (newPlugin)
+ {
+ newPlugin->setStandardName(stdName);
+ }
+ } else */
+ {
+ if (pluginType == "Command Line")
+ {
+ emit hideSplash();
+ KMessageBox::information(m_parent, i18n("<qt><b>%1</b> is a command line plugin. We have removed support for command-line plugins. However, the functionality has not been lost as script actions can still be used to run command-line tools. </qt>").arg(*it), i18n("Unsupported Plugin Type"), "CommandLinePluginWarning");
+ continue;
+ }
+
+ newPlugin = new QuantaPlugin();
+ }
+ newPlugin->setStandard(isStandard);
+ newPlugin->setPluginName(*it);
+ newPlugin->setFileName(config->readEntry("FileName"));
+ newPlugin->setLocation(config->readEntry("Location"));
+ newPlugin->setIcon(config->readEntry("Icon"));
+ QString type = config->readEntry("OutputWindow");
+ if (type == "Message Frame" || type == "Separate Toolview")
+ type = i18n("Separate Toolview");
+ else
+ type = i18n("Editor Tab");
+ newPlugin->setOutputWindow(type);
+ newPlugin->setInput(config->readNumEntry("Input", 0));
+ newPlugin->setReadOnlyPart(config->readBoolEntry("ReadOnly", true));
+
+ m_plugins.insert(*it, newPlugin);
+ }
+ delete config;
+}
+
+/** Reads the plugin settings from the rc file */
+void QuantaPluginInterface::readConfig()
+{
+ m_plugins.clear();
+
+ // read the local plugins.rc
+ QString configFile = locateLocal("appdata", "plugins.rc");
+ if (QFileInfo(configFile).exists())
+ readConfigFile(configFile);
+ // read the global plugins.rc
+ configFile = qConfig.globalDataDir + resourceDir + "plugins.rc";
+ readConfigFile(configFile);
+}
+
+/** Writes the plugin settings to the rc file */
+void QuantaPluginInterface::writeConfig()
+{
+ // write the plugin settings to the rc file
+ KConfig *config = new KConfig(locateLocal("appdata", "plugins.rc"));
+
+ QStringList names = pluginNames();
+
+ config->setGroup("General");
+ config->writeEntry("Plugins", names);
+ config->writePathEntry("SearchPaths", qConfig.pluginSearchPaths);
+
+ for(QStringList::Iterator it = names.begin();it != names.end(); ++it)
+ {
+ config->setGroup(*it);
+
+ QuantaPlugin *curPlugin = m_plugins[*it];
+ if(curPlugin)
+ {
+ config->writeEntry("FileName", curPlugin->fileName());
+ config->writeEntry("Type", "KPart"); //not used, but just to be compatible
+ config->writeEntry("Location", curPlugin->location());
+ config->writeEntry("Icon", curPlugin->icon());
+ QString type = curPlugin->outputWindow();
+ if (type == i18n("Editor Tab")) type = "Editor Tab";
+ if (type == i18n("Separate Toolview")) type = "Separate Toolview";
+ config->writeEntry("OutputWindow", type);
+ config->writeEntry("Input", curPlugin->input());
+ config->writeEntry("Standard", curPlugin->isStandard());
+ if (curPlugin->isStandard()) config->writeEntry("Standard Name", curPlugin->standardName());
+ config->writeEntry("ReadOnly", curPlugin->readOnlyPart());
+ }
+ }
+ config->sync();
+ if (config->isReadOnly())
+ {
+ kdWarning() << "Plugin config file " << locateLocal("appdata", "plugins.rc") << " is read only! Plugin settings were not saved!" << endl;
+ }
+ delete config;
+}
+
+
+/** Returns true if the plugin is available */
+bool QuantaPluginInterface::pluginAvailable(const QString &a_name)
+{
+ if (a_name.isEmpty())
+ return false;
+ QuantaPlugin *availPlugin = m_plugins.find(a_name);
+ if(availPlugin && QuantaPlugin::validatePlugin(availPlugin))
+ return true;
+
+ return false;
+}
+
+/** Gets the plugin names */
+QStringList QuantaPluginInterface::pluginNames() const
+{
+ QStringList names;
+ QDictIterator<QuantaPlugin> it(m_plugins);
+ for(;it.current();++it)
+ {
+ names << (*it)->pluginName();
+ }
+ return names;
+}
+
+
+/** Gets the plugin specified by a_name */
+QuantaPlugin *QuantaPluginInterface::plugin(const QString &a_name)
+{
+ if (a_name.isEmpty())
+ return 0L;
+ return m_plugins[a_name];
+}
+
+/** Builds the plugins menu */
+void QuantaPluginInterface::buildPluginMenu()
+{
+ m_pluginMenu->clear();
+// m_pluginMenu->setCheckable(true);
+
+ QDictIterator<QuantaPlugin> it(m_plugins);
+ for(;it.current() != 0;++it)
+ {
+ QuantaPlugin *curPlugin = it.current();
+ if(curPlugin)
+ {
+// int id = m_pluginMenu->insertItem(curPlugin->pluginName());
+// if(curPlugin->isRunning())
+// m_pluginMenu->setItemChecked(id, true);
+ curPlugin->plugAction(m_pluginMenu);
+ }
+ }
+}
+
+void QuantaPluginInterface::slotPluginsEdit()
+{
+ QuantaPluginEditor *editor = new QuantaPluginEditor(m_parent, "plugin_editor");
+ editor->setSearchPaths(qConfig.pluginSearchPaths);
+ editor->setPlugins(plugins());
+
+ editor->exec();
+ qConfig.pluginSearchPaths = editor->searchPathList();
+ setPlugins(editor->plugins());
+ writeConfig();
+ buildPluginMenu();
+ slotPluginsValidate();
+}
+
+void QuantaPluginInterface::slotPluginsValidate()
+{
+ QValueList<QuantaPlugin*> invalidPlugins;
+ QDictIterator<QuantaPlugin> it(m_plugins);
+ for(;it.current();++it)
+ {
+ if(!QuantaPlugin::validatePlugin(it.current()))
+ {
+ invalidPlugins.append(it.current());
+ }
+ }
+ uint invalidCount = invalidPlugins.count();
+ if (invalidCount > 0)
+ {
+ QString invalidNames;
+ for (uint i=0; i < invalidCount; i++)
+ {
+ invalidNames += "<br>" + invalidPlugins[i]->name();
+ }
+ int answer = KMessageBox::questionYesNo(m_parent, i18n("<qt>The following plugins seems to be invalid:<b>%1</b>.<br><br>Do you want to edit the plugins?</qt>").arg(invalidNames), i18n("Invalid Plugins"), i18n("Edit Plugins"), i18n("Do Not Edit"));
+ if(answer == KMessageBox::Yes)
+ {
+ slotPluginsEdit();
+ }
+ return;
+ } else
+ emit statusMsg(i18n("All plugins validated successfully."));
+}
+
+
+#include "quantaplugininterface.moc"
diff --git a/quanta/plugins/quantaplugininterface.h b/quanta/plugins/quantaplugininterface.h
new file mode 100644
index 00000000..a3e85030
--- /dev/null
+++ b/quanta/plugins/quantaplugininterface.h
@@ -0,0 +1,103 @@
+/***************************************************************************
+ quantaplugininterface.h - description
+ -------------------
+ begin : Mon Sep 16 2002
+ copyright : (C) 2002 by Marc Britton <consume@optushome.com.au>
+ (C) 2003 by Andras Mantia <amantia@kde.org>
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef QUANTAPLUGININTERFACE_H
+#define QUANTAPLUGININTERFACE_H
+
+/* KDE INCLUDES */
+#include <kconfig.h>
+#include <kstandarddirs.h>
+
+/* QT INCLUDES */
+#include <qobject.h>
+#include <qdict.h>
+#include <qstringlist.h>
+#include <qpopupmenu.h>
+
+/* OTHER INCLUDES */
+
+class QuantaPlugin;
+
+/**Provides an interface to the installed plugins
+ *@author Marc Britton
+ */
+class QuantaPluginInterface : public QObject
+{
+ Q_OBJECT
+public:
+ /**
+ * since this class is a singleton you must use this function to access it
+ *
+ * the parameters are only used at the first call to create the class
+ *
+ */
+ static QuantaPluginInterface* const ref(QWidget *parent = 0L)
+ {
+ static QuantaPluginInterface *m_ref;
+ if (!m_ref) m_ref = new QuantaPluginInterface (parent);
+ return m_ref;
+ }
+
+ ~QuantaPluginInterface();
+ /** Reads the rc file */
+ virtual void readConfig();
+ /** Write the rc file */
+ virtual void writeConfig();
+ /* Returns TRUE if the plugin specified by a_name is available for us*/
+ bool pluginAvailable(const QString &);
+ /** Gets the plugins */
+ QDict<QuantaPlugin> plugins() {return m_plugins;};
+ /** Sets the plugins */
+ void setPlugins(QDict<QuantaPlugin> plugins) {m_plugins = plugins;};
+ /** Gets the plugin specified by a_name */
+ virtual QuantaPlugin *plugin(const QString &);
+ /** Gets the plugin menu */
+ virtual QPopupMenu *pluginMenu() {return m_pluginMenu;};
+ void setPluginMenu(QPopupMenu *pluginMenu) {m_pluginMenu = pluginMenu;}
+ /** Builds the plugins menu dynamically */
+ void buildPluginMenu();
+
+private:
+ /** The constructor is privat because we use singleton patter.
+ * If you need the class use QuantaPluginInterface::ref() for
+ * construction and reference
+ */
+ QuantaPluginInterface(QWidget *parent);
+
+protected slots:
+ /** slot for the menu: validate */
+ void slotPluginsValidate();
+ /** slot for the menu: edit */
+ void slotPluginsEdit();
+
+protected:
+ /** Gets the plugin names */
+ virtual QStringList pluginNames() const;
+ void readConfigFile(const QString& configFile);
+
+ QDict<QuantaPlugin> m_plugins;
+
+ QWidget *m_parent;
+
+ QPopupMenu *m_pluginMenu;
+
+signals:
+ void hideSplash();
+ void statusMsg(const QString &);
+};
+
+#endif