Back to index

scribus-ng  1.3.4.dfsg+svn20071115
shortwords.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 /* This is the Scribus Short Words plugin interface implementation.
00008 
00009 This code is based on the Scribus-Vlna plug in rewritten for
00010 international use.
00011 
00012 2004 Petr Vanek <petr@yarpen.cz>
00013 
00014 This program is free software - see LICENSE file in the distribution
00015 or documentation
00016 */
00017 
00018 #include <qcheckbox.h>
00019 #include <qcursor.h>
00020 #include <qdir.h>
00021 #include <qfile.h>
00022 #include <qmessagebox.h>
00023 #include <qprogressdialog.h>
00024 #include <qtextcodec.h>
00025 
00026 #include "shortwords.h"
00027 #include "shortwords.moc"
00028 #include "version.h"
00029 #include "vlnadialog.h"
00030 #include "configuration.h"
00031 #include "parse.h"
00032 #include "page.h"
00033 #include "swprefsgui.h"
00034 #include "scpaths.h"
00035 #include "scribus.h"
00036 #include "util.h"
00037 
00038 int scribusshortwords_getPluginAPIVersion()
00039 {
00040        return PLUGIN_API_VERSION;
00041 }
00042 
00043 ScPlugin* scribusshortwords_getPlugin()
00044 {
00045        ShortWordsPlugin* plug = new ShortWordsPlugin();
00046        Q_CHECK_PTR(plug);
00047        return plug;
00048 }
00049 
00050 void scribusshortwords_freePlugin(ScPlugin* plugin)
00051 {
00052        ShortWordsPlugin* plug = dynamic_cast<ShortWordsPlugin*>(plugin);
00053        Q_ASSERT(plug);
00054        delete plug;
00055 }
00056 
00057 ShortWordsPlugin::ShortWordsPlugin() : ScActionPlugin()
00058 {
00059        // Set action info in languageChange, so we only have to do
00060        // it in one place.
00061        languageChange();
00062 }
00063 
00064 ShortWordsPlugin::~ShortWordsPlugin() {};
00065 
00066 void ShortWordsPlugin::languageChange()
00067 {
00068        // Note that we leave the unused members unset. They'll be initialised
00069        // with their default ctors during construction.
00070        // Action name
00071        m_actionInfo.name = "ShortWords";
00072        // Action text for menu, including accel
00073        m_actionInfo.text = tr("Short &Words...", "short words plugin");
00074        // Menu
00075        m_actionInfo.menu = "Extras";
00076        m_actionInfo.enabledOnStartup = true;
00077 }
00078 
00079 const QString ShortWordsPlugin::fullTrName() const
00080 {
00081        return QObject::tr("Short Words");
00082 }
00083 
00084 const ScActionPlugin::AboutData* ShortWordsPlugin::getAboutData() const
00085 {
00086        AboutData* about = new AboutData;
00087        Q_CHECK_PTR(about);
00088        about->authors = QString::fromUtf8("Petr Van\xc4\x9bk <petr@scribus.info>, "
00089                      "Łukasz [DeeJay1] Jernaś <deejay1@nsj.srem.pl>, "
00090                      "Maciej Hanski, Zdenko Podobny, Mikolaj Machowski <mikmach@wp.pl>, "
00091                      "Ludi Maciel, Frederico Guimarães, "
00092                      "Claudio Beccari <claudio.beccari@polito.it>, "
00093                      "Christoph Schäfer <christoph-schaefer@gmx.de>, "
00094                      "intrigeri <intrigeri@boum.org>");
00095        about->shortDescription = tr("Short Words");
00096        about->description = tr("Special plug-in for adding non-breaking spaces before or after so called short words. Available in the following languages: ") + SWConfig::getAvailableLanguages();
00097        // about->version
00098        // about->releaseDate
00099        // about->copyright
00100        about->license = "GPL";
00101        return about;
00102 }
00103 
00104 void ShortWordsPlugin::deleteAboutData(const AboutData* about) const
00105 {
00106        Q_ASSERT(about);
00107        delete about;
00108 }
00109 
00110 bool ShortWordsPlugin::run(ScribusDoc* doc, QString target)
00111 {
00112        Q_ASSERT(target.isEmpty());
00113 
00114        uint originalPage = doc->currentPage()->pageNr();
00115        SWDialog *dlg = new SWDialog(doc->scMW(), "dlg", true, 0);
00116        if (dlg->exec() == QDialog::Accepted) {
00117               SWParse *parse = new SWParse();
00118               QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00119               doc->scMW()->setStatusBarInfoText(QObject::tr("Short Words processing. Wait please...", "short words plugin"));
00120               switch (dlg->actionSelected) {
00121                      case 0:
00122                             parse->parseSelection(doc);
00123                             break;
00124                      case 1:
00125                             parse->parsePage(doc, doc->currentPage()->pageNr());
00126                             break;
00127                      case 2:
00128                             parse->parseAll(doc);
00129                             break;
00130               } // switch
00131               // enable "Save" icon
00132               if (parse->modify > 0)
00133                      doc->changed();
00134               delete parse;
00135               // redraw document
00136               doc->view()->DrawNew();
00137               QApplication::restoreOverrideCursor();
00138               doc->scMW()->setStatusBarInfoText(QObject::tr("Short Words processing. Done.", "short words plugin"));
00139               doc->scMW()->mainWindowProgressBar->reset();
00140               // set page where user calls vlna
00141               doc->view()->GotoPage(originalPage);
00142        } // action
00143        delete dlg;
00144        return true;
00145 }
00146 
00147 bool ShortWordsPlugin::newPrefsPanelWidget(QWidget* parent,
00148                                                                       PrefsPanel*& panel,
00149                                                                       QString& caption,
00150                                                                       QPixmap& icon)
00151 {
00152        panel = new SWPrefsGui(parent);
00153        Q_CHECK_PTR(panel);
00154        caption = tr("Short Words");
00155        icon = loadIcon("shortwords.png");
00156        return true;
00157 }
00158