Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

aboutplugins.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 "aboutplugins.h"
00008 
00009 #include "pluginmanager.h"
00010 #include "scplugin.h"
00011 #include "commonstrings.h"
00012 
00013 #include <QListWidget>
00014 #include <QListWidgetItem>
00015 #include <QString>
00016 #include <QTextBrowser>
00017 #include <QFileInfo>
00018 #include <QList>
00019 
00020 
00021 AboutPlugins::AboutPlugins( QWidget* parent )
00022     : QDialog(parent),
00023     // Get a list of plugins, enabled or not
00024     pluginNames(PluginManager::instance().pluginNames(true))
00025 {
00026     setupUi(this);
00027     // Populate the list with translated human-readable plugin names
00028     QStringList::const_iterator it(pluginNames.begin());
00029     QStringList::const_iterator itEnd(pluginNames.end());
00030     for ( ; it != itEnd; ++it )
00031     {
00032         ScPlugin* plugin = PluginManager::instance().getPlugin(*it, true);
00033         Q_ASSERT(plugin);
00034         pluginList->addItem(plugin->fullTrName());
00035     }
00036     // Hook up a connection to update the plugin info when
00037     // the selection changes
00038     connect(pluginList, SIGNAL(itemClicked(QListWidgetItem*)), SLOT(displayPlugin(QListWidgetItem*)));
00039     // and select the first plugin, if any
00040     if (pluginList->count())
00041     {
00042         pluginList->setCurrentRow(0);
00043         displayPlugin(pluginList->currentItem());
00044     }
00045 }
00046 
00047 AboutPlugins::~AboutPlugins()
00048 {
00049 }
00050 
00051 void AboutPlugins::displayPlugin(QListWidgetItem* item)
00052 {
00053     int sel = pluginList->row(item);
00054     // Look up the list entry to get the plugin name and use
00055     // it to grab the plugin instance and get its about data.
00056     PluginManager& pluginManager = PluginManager::instance();
00057     const QString& name(pluginNames[sel]);
00058     ScPlugin* plugin = pluginManager.getPlugin(name, true);
00059     Q_ASSERT(plugin);
00060     const ScPlugin::AboutData* about = plugin->getAboutData();
00061     Q_ASSERT(about);
00062     // Now set the text into the html "template"
00063     // Set the filename using the basename of the path
00064     QFileInfo fi(pluginManager.getPluginPath(name));
00065     QString html;
00066     html = QString("<html><body><h1>%1</h1>").arg(plugin->fullTrName());
00067     html += "<table>";
00068     html += QString("<tr><th>%1</th><td>%2</td></tr>").arg( tr("Filename:")).arg(fi.completeBaseName());
00069     html += QString("<tr><th>%1</th><td>%2</td></tr>").arg( tr("Version:")).arg(about->version);
00070     QString ena;
00071     ena = pluginManager.enabled(name) ? CommonStrings::trYes : CommonStrings::trNo;
00072     html += QString("<tr><th>%1</th><td>%2</td></tr>").arg( tr("Enabled:")).arg(ena);
00073     html += QString("<tr><th>%1</th><td>%2</td></tr>").arg( tr("Release Date:")).arg(about->releaseDate.toString());
00074     html += "</table>";
00075     QString desc;
00076     if (!about->shortDescription.isNull())
00077         desc += QString("<p>%1</p>").arg(about->shortDescription);
00078     if (!about->description.isNull())
00079         desc += QString("<p>%1</p>").arg(about->description);
00080     html += QString("<h2>%1</h2>%2").arg( tr("Description:")).arg(desc);
00081     html += QString("<h2>%1</h2><p>%2</p>").arg( tr("Author(s):")).arg(htmlize(about->authors));
00082     html += QString("<h2>%1</h2><p>%2</p>").arg( tr("Copyright:")).arg(htmlize(about->copyright));
00083     html += QString("<h2>%1</h2><p>%2</p>").arg( tr("License:")).arg(htmlize(about->license));
00084     html += "</html>";
00085     infoBrowser->setHtml(html);
00086     // Use the plugin to delete the about info, so we don't
00087     // confuse win32's segmented memory.
00088     plugin->deleteAboutData(about);
00089 }
00090 
00091 QString AboutPlugins::htmlize(QString s)
00092 {
00093     QString ret = s.replace('<', "&lt;");
00094     ret = ret.replace('>', "&gt;");
00095     return ret;
00096 }
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.