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 #include "commonstrings.h"
8
9 #include "importqxp.h"
10 #include "importqxpplugin.h"
11 #include "prefscontext.h"
12 #include "prefsfile.h"
13 #include "prefsmanager.h"
14 #include "scpage.h"
15 #include "scraction.h"
16 #include "scribuscore.h"
17 #include "undomanager.h"
18 #include "util_formats.h"
19
20 #include "ui/customfdialog.h"
21 #include "ui/scmwmenumanager.h"
22
importqxp_getPluginAPIVersion()23 int importqxp_getPluginAPIVersion()
24 {
25 return PLUGIN_API_VERSION;
26 }
27
importqxp_getPlugin()28 ScPlugin* importqxp_getPlugin()
29 {
30 ImportQxpPlugin* plug = new ImportQxpPlugin();
31 Q_CHECK_PTR(plug);
32 return plug;
33 }
34
importqxp_freePlugin(ScPlugin * plugin)35 void importqxp_freePlugin(ScPlugin* plugin)
36 {
37 ImportQxpPlugin* plug = dynamic_cast<ImportQxpPlugin*>(plugin);
38 Q_ASSERT(plug);
39 delete plug;
40 }
41
ImportQxpPlugin()42 ImportQxpPlugin::ImportQxpPlugin() : LoadSavePlugin(),
43 importAction(new ScrAction(ScrAction::DLL, QPixmap(), QPixmap(), "", QKeySequence(), this))
44 {
45 // Set action info in languageChange, so we only have to do it in one
46 // place. This includes registering file format support.
47 registerFormats();
48 languageChange();
49 }
50
languageChange()51 void ImportQxpPlugin::languageChange()
52 {
53 importAction->setText( tr("Import QuarkXPress..."));
54 FileFormat* fmt = getFormatByExt("qxd");
55 fmt->trName = tr("QuarkXPress");
56 fmt->filter = tr("QuarkXPress (*.qxd *.QXD *.qxt *.QXT)");
57 }
58
~ImportQxpPlugin()59 ImportQxpPlugin::~ImportQxpPlugin()
60 {
61 unregisterAll();
62 }
63
fullTrName() const64 QString ImportQxpPlugin::fullTrName() const
65 {
66 return QObject::tr("QuarkXPress Importer");
67 }
68
getAboutData() const69 const ScActionPlugin::AboutData* ImportQxpPlugin::getAboutData() const
70 {
71 AboutData* about = new AboutData;
72 about->authors = "Franz Schmid <franz@scribus.info>";
73 about->shortDescription = tr("Imports QuarkXPress Files");
74 about->description = tr("Imports QuarkXPress 3.1-4.1 files into the current document, converting their vector data into Scribus objects.");
75 about->license = "GPL";
76 Q_CHECK_PTR(about);
77 return about;
78 }
79
deleteAboutData(const AboutData * about) const80 void ImportQxpPlugin::deleteAboutData(const AboutData* about) const
81 {
82 Q_ASSERT(about);
83 delete about;
84 }
85
registerFormats()86 void ImportQxpPlugin::registerFormats()
87 {
88 FileFormat fmt(this);
89 fmt.trName = tr("QuarkXPress");
90 fmt.filter = tr("QuarkXPress (*.qxd *.QXD *.qxt *.QXT)");
91 fmt.formatId = 0;
92 fmt.fileExtensions = QStringList() << "qxd" << "qxt";
93 fmt.load = true;
94 fmt.save = false;
95 fmt.thumb = true;
96 fmt.colorReading = true;
97 fmt.mimeTypes = QStringList();
98 fmt.priority = 64; // Priority
99 registerFormat(fmt);
100 }
101
fileSupported(QIODevice *,const QString & fileName) const102 bool ImportQxpPlugin::fileSupported(QIODevice* /* file */, const QString & fileName) const
103 {
104 return true;
105 }
106
loadFile(const QString & fileName,const FileFormat &,int flags,int)107 bool ImportQxpPlugin::loadFile(const QString & fileName, const FileFormat &, int flags, int /*index*/)
108 {
109 // There's only one format to handle, so we just call import(...)
110 return import(fileName, flags);
111 }
112
import(QString fileName,int flags)113 bool ImportQxpPlugin::import(QString fileName, int flags)
114 {
115 if (!checkFlags(flags))
116 return false;
117 if (fileName.isEmpty())
118 {
119 flags |= lfInteractive;
120 PrefsContext* prefs = PrefsManager::instance().prefsFile->getPluginContext("importqxp");
121 QString wdir = prefs->get("wdir", ".");
122 CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), tr("All Supported Formats")+" (*.qxd *.QXD *.qxt *.QXT);;All Files (*)");
123 if (diaf.exec())
124 {
125 fileName = diaf.selectedFile();
126 prefs->set("wdir", fileName.left(fileName.lastIndexOf("/")));
127 }
128 else
129 return true;
130 }
131 m_Doc=ScCore->primaryMainWindow()->doc;
132 UndoTransaction* activeTransaction = nullptr;
133 bool emptyDoc = (m_Doc == nullptr);
134 bool hasCurrentPage = (m_Doc && m_Doc->currentPage());
135 TransactionSettings trSettings;
136 trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : "";
137 trSettings.targetPixmap = Um::IImageFrame;
138 trSettings.actionName = Um::ImportQXP;
139 trSettings.description = fileName;
140 trSettings.actionPixmap = Um::IXFIG;
141 if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted))
142 UndoManager::instance()->setUndoEnabled(false);
143 if (UndoManager::undoEnabled())
144 activeTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(trSettings));
145 QxpPlug *dia = new QxpPlug(m_Doc, flags);
146 Q_CHECK_PTR(dia);
147 dia->import(fileName, trSettings, flags, !(flags & lfScripted));
148 if (activeTransaction)
149 {
150 activeTransaction->commit();
151 delete activeTransaction;
152 activeTransaction = nullptr;
153 }
154 if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted))
155 UndoManager::instance()->setUndoEnabled(true);
156 delete dia;
157 return true;
158 }
159
readThumbnail(const QString & fileName)160 QImage ImportQxpPlugin::readThumbnail(const QString& fileName)
161 {
162 if (fileName.isEmpty())
163 return QImage();
164 UndoManager::instance()->setUndoEnabled(false);
165 m_Doc = nullptr;
166 QxpPlug *dia = new QxpPlug(m_Doc, lfCreateThumbnail);
167 Q_CHECK_PTR(dia);
168 QImage ret = dia->readThumbnail(fileName);
169 UndoManager::instance()->setUndoEnabled(true);
170 delete dia;
171 return ret;
172 }
173