Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pluginmanagerprefsgui.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "pluginmanagerprefsgui.h"
00008 #include "pluginmanager.h"
00009 #include "scplugin.h"
00010 #include "util.h"
00011 #include "commonstrings.h"
00012 
00013 #include <qlayout.h>
00014 #include <qlistview.h>
00015 #include <qgroupbox.h>
00016 #include <qlabel.h>
00017 
00018 extern QPixmap loadIcon(QString nam);
00019 
00020 
00021 PluginManagerPrefsGui::PluginManagerPrefsGui(QWidget * parent)
00022        : PrefsPanel(parent, "pluginManagerPrefsWidget")
00023 {
00024        PluginManager& pluginManager(PluginManager::instance());
00025        pluginMainLayout = new QVBoxLayout( this, 0, 5, "pluginMainLayout");
00026        pluginMainLayout->setAlignment( Qt::AlignTop );
00027        plugGroupBox = new QGroupBox( tr("Plugin Manager"), this, "plugGroupBox");
00028        plugGroupBox->setColumnLayout(0, Qt::Vertical);
00029        plugGroupBox->layout()->setSpacing(6);
00030        plugGroupBox->layout()->setMargin(11);
00031        plugGroupBoxLayout = new QGridLayout( plugGroupBox->layout() );
00032        plugGroupBoxLayout->setAlignment(Qt::AlignTop);
00033        plugLayout1 = new QVBoxLayout( 0, 0, 6, "plugLayout1");
00034        pluginsList = new QListView(plugGroupBox, "pluginsList");
00035        pluginsList->setAllColumnsShowFocus(true);
00036        pluginsList->setShowSortIndicator(true);
00037        pluginsList->addColumn( tr("Plugin"));
00038        pluginsList->setColumnWidthMode(0, QListView::Maximum);
00039        pluginsList->addColumn( tr("How to run"));
00040        pluginsList->setColumnWidthMode(1, QListView::Maximum);
00041        pluginsList->addColumn( tr("Type"));
00042        pluginsList->setColumnWidthMode(2, QListView::Maximum);
00043        pluginsList->addColumn( tr("Load it?"));
00044        pluginsList->setColumnWidthMode(3, QListView::Maximum);
00045        pluginsList->addColumn( tr("Plugin ID"));
00046        pluginsList->setColumnWidthMode(4, QListView::Maximum);
00047        pluginsList->addColumn( tr("File"));
00048        pluginsList->setColumnWidthMode(5, QListView::Maximum);
00049 
00050        checkOn = getQCheckBoxPixmap(true, pluginsList->paletteBackgroundColor());
00051        checkOff = getQCheckBoxPixmap(false, pluginsList->paletteBackgroundColor());
00052        // Get a list of all internal plugin names, including those of disabled
00053        // plugins, then loop over them and add each one to the plugin list.
00054        QValueList<QCString> pluginNames(pluginManager.pluginNames(true));
00055        for (QValueList<QCString>::Iterator it = pluginNames.begin(); it != pluginNames.end(); ++it)
00056        {
00057               QListViewItem *plugItem = new QListViewItem(pluginsList);
00058               // Get the plugin, even if it's loaded but disabled
00059               ScPlugin* plugin = pluginManager.getPlugin(*it, true);
00060               Q_ASSERT(plugin); // all the returned names should represent loaded plugins
00061               plugItem->setText(0, plugin->fullTrName());
00062               if (plugin->inherits("ScActionPlugin"))
00063               {
00064                      ScActionPlugin* ixplug = dynamic_cast<ScActionPlugin*>(plugin);
00065                      Q_ASSERT(ixplug);
00066                      ScActionPlugin::ActionInfo ai(ixplug->actionInfo());
00067                      plugItem->setText(1, QString("%1 %2").arg(ai.menu).arg(ai.menuAfterName)); // menu path
00068               }
00069               else
00070               {
00071                      // Resident plug-ins don't have predefined actions
00072                      plugItem->setText(1, QString(""));
00073               }
00074               plugItem->setText(2, plugin->pluginTypeName());
00075               // load at start?
00076               bool onstart = pluginManager.enableOnStartup(*it);
00077               plugItem->setPixmap(3, onstart ? checkOn : checkOff);
00078               plugItem->setText(3, onstart ? CommonStrings::trYes : CommonStrings::trNo);
00079               plugItem->setText(4, QString("%1").arg(*it)); // plugname for developers
00080               plugItem->setText(5, pluginManager.getPluginPath(*it)); // file path for developers
00081               // Populate the working settings info for the plug-in
00082               pluginSettings[*it].enableOnStartup = onstart;
00083        }
00084        plugLayout1->addWidget(pluginsList);
00085        pluginWarning = new QLabel(plugGroupBox);
00086        pluginWarning->setText("<qt>" + tr("You need to restart the application to apply the changes.") + "</qt>");
00087        plugLayout1->addWidget(pluginWarning);
00088        plugGroupBoxLayout->addLayout(plugLayout1, 0, 0);
00089        pluginMainLayout->addWidget(plugGroupBox);
00090 
00091        connect(pluginsList, SIGNAL(clicked(QListViewItem *, const QPoint &, int)),
00092                      this, SLOT(updateSettings(QListViewItem *, const QPoint &, int)));
00093 }
00094 
00095 PluginManagerPrefsGui::~PluginManagerPrefsGui()
00096 {
00097 }
00098 
00099 void PluginManagerPrefsGui::updateSettings(QListViewItem *item, const QPoint &, int column)
00100 {
00101        if (column != 3)
00102               // Only the plugin enable/disabled checkbox is editable
00103               return;
00104        PluginSettings& settings = pluginSettings[item->text(4).latin1()];
00105        bool onstartup;
00106        if (item->text(3) == CommonStrings::trYes)
00107        {
00108               item->setPixmap(3, checkOff);
00109               item->setText(3, CommonStrings::trNo);
00110               // Update our stored settings with the new flag
00111               onstartup = false;
00112        }
00113        else
00114        {
00115               item->setPixmap(3, checkOn);
00116               item->setText(3, CommonStrings::trYes);
00117               onstartup = true;
00118        }
00119        // Store changed setting(s) into working setting info
00120        settings.enableOnStartup = onstartup;
00121 }
00122 
00123 void PluginManagerPrefsGui::apply()
00124 {
00125        PluginManager& pluginManager(PluginManager::instance());
00126        // For each plugin:
00127        QMap<QCString,PluginSettings>::Iterator itEnd(pluginSettings.end());
00128        for ( QMap<QCString,PluginSettings>::Iterator it(pluginSettings.begin()) ; it != itEnd ; ++it )
00129        {
00130               // Save any changes from our working info to the plugin manager
00131               pluginManager.enableOnStartup(it.key()) = it.data().enableOnStartup;
00132        }
00133 }
00134 
00135 #include "pluginmanagerprefsgui.moc"