Back to index

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