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 
8 #include "barcode.h"
9 #include "barcodegenerator.h"
10 #include "scribuscore.h"
11 #include "scribusstructs.h"
12 #include "iconmanager.h"
13 #include "scpaths.h"
14 
Barcode()15 Barcode::Barcode()
16 {
17 	languageChange();
18 }
19 
20 Barcode::~Barcode() = default;
21 
languageChange()22 void Barcode::languageChange()
23 {
24 	m_actionInfo.name = "BarcodeGenerator";
25 	m_actionInfo.text = tr("Barcode");
26 	m_actionInfo.helpText = tr("Insert a barcode");
27 	if (ScCore->haveGS())
28 	{
29 		m_actionInfo.menu = "Insert";
30 		m_actionInfo.menuAfterName = "toolsInsertRenderFrame";
31 		m_actionInfo.toolbar = "Tools";
32 	}
33 	m_actionInfo.iconPath1 = "16/insert-barcode.png";
34 	m_actionInfo.iconPath2 = "22/insert-barcode.png";
35 	m_actionInfo.enabledOnStartup = false;
36 //	m_actionInfo.forAppMode.append(modeNormal);
37 	m_actionInfo.needsNumObjects = -1;
38 }
39 
fullTrName() const40 QString Barcode::fullTrName() const
41 {
42 	return QObject::tr("Barcode Generator");
43 }
44 
getAboutData() const45 const ScActionPlugin::AboutData* Barcode::getAboutData() const
46 {
47 	AboutData* about = new AboutData;
48 	Q_CHECK_PTR(about);
49 
50 	about->authors = QString::fromUtf8("Terry Burton - <tez@terryburton.co.uk>, Petr Van\xc4\x9bk <petr@scribus.info>");
51 	about->shortDescription = tr("Scribus frontend for Barcode Writer in Pure PostScript");
52 	about->description = "Barcode Writer in Pure Postscript generates all barcode formats entirely within PostScript hence this plugin requires Ghostscript to be installed on your system. https://bwipp.terryburton.co.uk";
53 
54 	// Extract the version information from BWIPP
55 	QFile f( ScPaths::instance().shareDir() + QString("/plugins/barcode.ps") );
56 	if (f.open(QIODevice::ReadOnly))
57 	{
58 		QTextStream ts(&f);
59 		QString bwipp = ts.read(150);
60 		f.close();
61 		QRegExp rx("\\n% Barcode Writer in Pure PostScript - Version ([\\d-]+)\\n");
62 		if (rx.indexIn(bwipp) >= 0)
63 			about->version = "Backend: " + rx.cap(1);
64 		else
65 			about->version = "Backend: Unknown";
66 	}
67 	else
68 		about->version = "Unable to open backend file";
69 	// about->releaseDate
70 	about->copyright = QString::fromUtf8("Backend: Copyright (c) 2004-2018 Terry Burton - tez@terryburton.co.uk\nFrontend: Copyright (c) 2005 Petr Van\xc4\x9bk - petr@scribus.info");
71 	about->license = "Backend: MIT/X-Consortium, Frontend: GPL";
72 	return about;
73 }
74 
deleteAboutData(const AboutData * about) const75 void Barcode::deleteAboutData(const AboutData* about) const
76 {
77 	Q_ASSERT(about);
78 	delete about;
79 }
80 
run(ScribusDoc * doc,const QString &)81 bool Barcode::run(ScribusDoc* doc, const QString& /*target*/ )
82 {
83 	if (!doc || !ScCore->haveGS())
84 		return false;
85 	BarcodeGenerator *bg = new BarcodeGenerator();
86 	Q_CHECK_PTR(bg);
87 	bg->exec();
88 	delete bg;
89 	return true;
90 }
91 
barcodegenerator_getPluginAPIVersion()92 int barcodegenerator_getPluginAPIVersion()
93 {
94 	return PLUGIN_API_VERSION;
95 }
96 
barcodegenerator_getPlugin()97 ScPlugin* barcodegenerator_getPlugin()
98 {
99 	Barcode* plug = new Barcode();
100 	Q_CHECK_PTR(plug);
101 	return plug;
102 }
103 
barcodegenerator_freePlugin(ScPlugin * plugin)104 void barcodegenerator_freePlugin(ScPlugin* plugin)
105 {
106 	Barcode* plug = qobject_cast<Barcode*>(plugin);
107 	Q_ASSERT(plug);
108 	delete plug;
109 }
110