1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /* This is the Scribus Short Words plugin interface implementation.
8
9 This code is based on the Scribus-Vlna plug in rewritten for
10 international use.
11
12 2004 Petr Vanek <petr@yarpen.cz>
13
14 This program is free software - see LICENSE file in the distribution
15 or documentation
16 */
17
18 #include <QCheckBox>
19 #include <QCursor>
20 #include <QDir>
21 #include <QFile>
22 #include <QMessageBox>
23 #include <QProgressBar>
24 #include <QTextCodec>
25 #include <QPixmap>
26
27 #include "configuration.h"
28 #include "iconmanager.h"
29 #include "parse.h"
30 #include "prefs_shortwords.h"
31 #include "scpage.h"
32 #include "scpaths.h"
33 #include "scribus.h"
34 #include "scribusdoc.h"
35 #include "scribusview.h"
36 #include "shortwords.h"
37 #include "swdialog.h"
38 #include "version.h"
39
40
scribusshortwords_getPluginAPIVersion()41 int scribusshortwords_getPluginAPIVersion()
42 {
43 return PLUGIN_API_VERSION;
44 }
45
scribusshortwords_getPlugin()46 ScPlugin* scribusshortwords_getPlugin()
47 {
48 ShortWordsPlugin* plug = new ShortWordsPlugin();
49 Q_CHECK_PTR(plug);
50 return plug;
51 }
52
scribusshortwords_freePlugin(ScPlugin * plugin)53 void scribusshortwords_freePlugin(ScPlugin* plugin)
54 {
55 ShortWordsPlugin* plug = qobject_cast<ShortWordsPlugin*>(plugin);
56 Q_ASSERT(plug);
57 delete plug;
58 }
59
ShortWordsPlugin()60 ShortWordsPlugin::ShortWordsPlugin()
61 {
62 // Set action info in languageChange, so we only have to do
63 // it in one place.
64 languageChange();
65 }
66
67 ShortWordsPlugin::~ShortWordsPlugin() = default;
68
languageChange()69 void ShortWordsPlugin::languageChange()
70 {
71 // Note that we leave the unused members unset. They'll be initialised
72 // with their default ctors during construction.
73 // Action name
74 m_actionInfo.name = "ShortWords";
75 // Action text for menu, including accel
76 m_actionInfo.text = tr("Short &Words...", "short words plugin");
77 // Menu
78 m_actionInfo.menu = "Extras";
79 m_actionInfo.menuAfterName = "extrasDeHyphenateText";
80 m_actionInfo.enabledOnStartup = false;
81 m_actionInfo.needsNumObjects = -1;
82 }
83
fullTrName() const84 QString ShortWordsPlugin::fullTrName() const
85 {
86 return QObject::tr("Short Words");
87 }
88
getAboutData() const89 const ScActionPlugin::AboutData* ShortWordsPlugin::getAboutData() const
90 {
91 AboutData* about = new AboutData;
92 Q_CHECK_PTR(about);
93 about->authors = QString::fromUtf8("Petr Van\xc4\x9bk <petr@scribus.info>, "
94 "Łukasz [DeeJay1] Jernaś <deejay1@nsj.srem.pl>, "
95 "Maciej Hanski, Zdenko Podobny, Mikolaj Machowski <mikmach@wp.pl>, "
96 "Ludi Maciel, Frederico Guimarães, "
97 "Claudio Beccari <claudio.beccari@polito.it>, "
98 "Christoph Schäfer <christoph-schaefer@gmx.de>, "
99 "intrigeri <intrigeri@boum.org>");
100 about->shortDescription = tr("Short Words");
101 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();
102 // about->version
103 // about->releaseDate
104 // about->copyright
105 about->license = "GPL";
106 return about;
107 }
108
deleteAboutData(const AboutData * about) const109 void ShortWordsPlugin::deleteAboutData(const AboutData* about) const
110 {
111 Q_ASSERT(about);
112 delete about;
113 }
114
run(ScribusDoc * doc,const QString & target)115 bool ShortWordsPlugin::run(ScribusDoc* doc, const QString& target)
116 {
117 if (doc == nullptr)
118 return false;
119 Q_ASSERT(target.isEmpty());
120
121 uint originalPage = doc->currentPage()->pageNr();
122 SWDialog *dlg = new SWDialog(doc->scMW());
123 if (dlg->exec() == QDialog::Accepted) {
124 SWParse *parse = new SWParse();
125 QApplication::changeOverrideCursor(QCursor(Qt::WaitCursor));
126 if (!dlg->useStyleLang())
127 parse->lang = dlg->lang();
128 else
129 parse->lang.clear(); // get it from style
130
131 doc->scMW()->setStatusBarInfoText(QObject::tr("Short Words processing. Wait please...", "short words plugin"));
132 switch (dlg->actionSelected())
133 {
134 case 0:
135 parse->parseSelection(doc);
136 break;
137 case 1:
138 parse->parsePage(doc, doc->currentPage()->pageNr());
139 break;
140 case 2:
141 parse->parseAll(doc);
142 break;
143 } // switch
144 // enable "Save" icon
145 if (parse->modify > 0)
146 doc->changed();
147 delete parse;
148 // redraw document
149 doc->view()->DrawNew();
150 QApplication::changeOverrideCursor(Qt::ArrowCursor);
151 doc->scMW()->setStatusBarInfoText(QObject::tr("Short Words processing. Done.", "short words plugin"));
152 doc->scMW()->mainWindowProgressBar->reset();
153 // set page where user calls vlna
154 doc->view()->GotoPage(originalPage);
155 } // action
156 delete dlg;
157 return true;
158 }
159
newPrefsPanelWidget(QWidget * parent,Prefs_Pane * & panel)160 bool ShortWordsPlugin::newPrefsPanelWidget(QWidget* parent, Prefs_Pane*& panel)
161 {
162 panel = new Prefs_ShortWords(parent);
163 Q_CHECK_PTR(panel);
164 return true;
165 }
166