Rev 18298 | Rev 19420 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 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 | */ |
||
10292 | cbradney | 7 | #include "commonstrings.h" |
16736 | jghali | 8 | |
10292 | cbradney | 9 | #include "importps.h" |
3255 | craig | 10 | #include "importpsplugin.h" |
16736 | jghali | 11 | |
3255 | craig | 12 | #include "prefscontext.h" |
13 | #include "prefsfile.h" |
||
10292 | cbradney | 14 | #include "prefsmanager.h" |
16729 | fschmid | 15 | #include "scconfig.h" |
16736 | jghali | 16 | #include "scpage.h" |
10292 | cbradney | 17 | #include "scraction.h" |
18 | #include "scribuscore.h" |
||
3255 | craig | 19 | #include "undomanager.h" |
10292 | cbradney | 20 | #include "util_formats.h" |
3255 | craig | 21 | |
16736 | jghali | 22 | #include "ui/customfdialog.h" |
23 | #include "ui/scmwmenumanager.h" |
||
24 | |||
3255 | craig | 25 | int importps_getPluginAPIVersion() |
26 | { |
||
27 | return PLUGIN_API_VERSION; |
||
28 | } |
||
29 | |||
30 | ScPlugin* importps_getPlugin() |
||
31 | { |
||
32 | ImportPSPlugin* plug = new ImportPSPlugin(); |
||
33 | Q_CHECK_PTR(plug); |
||
34 | return plug; |
||
35 | } |
||
36 | |||
37 | void importps_freePlugin(ScPlugin* plugin) |
||
38 | { |
||
39 | ImportPSPlugin* plug = dynamic_cast<ImportPSPlugin*>(plugin); |
||
40 | Q_ASSERT(plug); |
||
41 | delete plug; |
||
42 | } |
||
43 | |||
3696 | craig | 44 | ImportPSPlugin::ImportPSPlugin() : LoadSavePlugin(), |
17118 | craig | 45 | importAction(new ScrAction(ScrAction::DLL, "", QKeySequence(), this)) |
3255 | craig | 46 | { |
3686 | craig | 47 | // Set action info in languageChange, so we only have to do it in one |
48 | // place. This includes registering file format support. |
||
3255 | craig | 49 | languageChange(); |
5243 | cbradney | 50 | } |
12110 | fschmid | 51 | /* |
5243 | cbradney | 52 | void ImportPSPlugin::addToMainWindowMenu(ScribusMainWindow *mw) |
53 | { |
||
3696 | craig | 54 | importAction->setEnabled(true); |
10725 | jghali | 55 | connect( importAction, SIGNAL(triggered()), SLOT(import()) ); |
5781 | cbradney | 56 | mw->scrMenuMgr->addMenuItem(importAction, "FileImport"); |
3255 | craig | 57 | } |
12110 | fschmid | 58 | */ |
3255 | craig | 59 | void ImportPSPlugin::languageChange() |
60 | { |
||
10427 | cbradney | 61 | importAction->setText( tr("Import PostScript...")); |
3686 | craig | 62 | // (Re)register file format support |
63 | unregisterAll(); |
||
64 | registerFormats(); |
||
3255 | craig | 65 | } |
66 | |||
3686 | craig | 67 | ImportPSPlugin::~ImportPSPlugin() |
68 | { |
||
69 | unregisterAll(); |
||
70 | }; |
||
3255 | craig | 71 | |
72 | const QString ImportPSPlugin::fullTrName() const |
||
73 | { |
||
10292 | cbradney | 74 | return QObject::tr("PostScript Importer"); |
3255 | craig | 75 | } |
76 | |||
77 | |||
78 | const ScActionPlugin::AboutData* ImportPSPlugin::getAboutData() const |
||
79 | { |
||
80 | AboutData* about = new AboutData; |
||
3344 | fschmid | 81 | about->authors = "Franz Schmid <franz@scribus.info>"; |
10292 | cbradney | 82 | about->shortDescription = tr("Imports PostScript Files"); |
83 | about->description = tr("Imports most PostScript files into the current document,\nconverting their vector data into Scribus objects."); |
||
3344 | fschmid | 84 | about->license = "GPL"; |
3255 | craig | 85 | Q_CHECK_PTR(about); |
86 | return about; |
||
87 | } |
||
88 | |||
89 | void ImportPSPlugin::deleteAboutData(const AboutData* about) const |
||
90 | { |
||
91 | Q_ASSERT(about); |
||
92 | delete about; |
||
93 | } |
||
94 | |||
3686 | craig | 95 | void ImportPSPlugin::registerFormats() |
3487 | craig | 96 | { |
19179 | craig | 97 | if (!ScCore->haveGS()) |
98 | return; |
||
4024 | craig | 99 | FileFormat fmt(this); |
14061 | fschmid | 100 | fmt.trName = FormatsManager::instance()->nameOfFormat(FormatsManager::EPS); // Human readable name |
18298 | jghali | 101 | fmt.formatId = 0; |
14061 | fschmid | 102 | fmt.filter = FormatsManager::instance()->extensionsForFormat(FormatsManager::EPS);// QFileDialog filter |
14665 | fschmid | 103 | fmt.fileExtensions = QStringList() << "eps" << "epsf" << "epsi" << "eps2" << "eps3" << "epi" << "ept"; |
3686 | craig | 104 | fmt.load = true; |
105 | fmt.save = false; |
||
14061 | fschmid | 106 | fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::EPS); // MIME types |
3643 | craig | 107 | fmt.priority = 64; // Priority |
3686 | craig | 108 | registerFormat(fmt); |
14061 | fschmid | 109 | |
4717 | avox | 110 | FileFormat fmt2(this); |
14061 | fschmid | 111 | fmt2.trName = FormatsManager::instance()->nameOfFormat(FormatsManager::PS); // Human readable name |
18298 | jghali | 112 | fmt2.formatId = 0; |
14061 | fschmid | 113 | fmt2.filter = FormatsManager::instance()->extensionsForFormat(FormatsManager::PS);// QFileDialog filter |
14793 | fschmid | 114 | fmt2.fileExtensions = QStringList() << "ps"; |
4717 | avox | 115 | fmt2.load = true; |
116 | fmt2.save = false; |
||
14061 | fschmid | 117 | fmt2.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::PS); // MIME types |
4717 | avox | 118 | fmt2.priority = 64; // Priority |
119 | registerFormat(fmt2); |
||
14061 | fschmid | 120 | |
121 | FileFormat fmt3(this); |
||
122 | fmt3.trName = FormatsManager::instance()->nameOfFormat(FormatsManager::PDF); // Human readable name |
||
18298 | jghali | 123 | fmt3.formatId = 0; |
14061 | fschmid | 124 | fmt3.filter = FormatsManager::instance()->extensionsForFormat(FormatsManager::PDF);// QFileDialog filter |
14793 | fschmid | 125 | fmt3.fileExtensions = QStringList() << "pdf"; |
14061 | fschmid | 126 | fmt3.load = true; |
127 | fmt3.save = false; |
||
128 | fmt3.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::PDF); // MIME types |
||
129 | fmt3.priority = 64; // Priority |
||
130 | registerFormat(fmt3); |
||
3487 | craig | 131 | } |
132 | |||
5642 | cbradney | 133 | bool ImportPSPlugin::fileSupported(QIODevice* /* file */, const QString & fileName) const |
3487 | craig | 134 | { |
135 | // TODO: check for %!PS-Adobe |
||
136 | return true; |
||
137 | } |
||
138 | |||
5539 | mrdocs | 139 | bool ImportPSPlugin::loadFile(const QString & fileName, const FileFormat &, int flags, int /*index*/) |
4024 | craig | 140 | { |
141 | // There's only one format to handle, so we just call import(...) |
||
5539 | mrdocs | 142 | return import(fileName, flags); |
4024 | craig | 143 | } |
3487 | craig | 144 | |
5539 | mrdocs | 145 | bool ImportPSPlugin::import(QString fileName, int flags) |
3255 | craig | 146 | { |
5539 | mrdocs | 147 | if (!checkFlags(flags)) |
148 | return false; |
||
149 | if( fileName.isEmpty() ) |
||
3255 | craig | 150 | { |
5539 | mrdocs | 151 | flags |= lfInteractive; |
3255 | craig | 152 | PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("importps"); |
153 | QString wdir = prefs->get("wdir", "."); |
||
10292 | cbradney | 154 | CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), FormatsManager::instance()->fileDialogFormatList(FormatsManager::EPS|FormatsManager::PS)); |
3255 | craig | 155 | if (diaf.exec()) |
156 | { |
||
157 | fileName = diaf.selectedFile(); |
||
10427 | cbradney | 158 | prefs->set("wdir", fileName.left(fileName.lastIndexOf("/"))); |
3255 | craig | 159 | } |
160 | else |
||
161 | return true; |
||
162 | } |
||
5781 | cbradney | 163 | m_Doc=ScCore->primaryMainWindow()->doc; |
11576 | avox | 164 | UndoTransaction* activeTransaction = NULL; |
165 | bool emptyDoc = (m_Doc == NULL); |
||
13378 | jghali | 166 | bool hasCurrentPage = (m_Doc && m_Doc->currentPage()); |
13371 | jghali | 167 | TransactionSettings trSettings; |
13378 | jghali | 168 | trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : ""; |
13371 | jghali | 169 | trSettings.targetPixmap = Um::IImageFrame; |
170 | trSettings.actionName = Um::ImportEPS; |
||
171 | trSettings.description = fileName; |
||
172 | trSettings.actionPixmap = Um::IEPS; |
||
173 | if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) |
||
174 | UndoManager::instance()->setUndoEnabled(false); |
||
175 | if (UndoManager::undoEnabled()) |
||
3255 | craig | 176 | { |
13371 | jghali | 177 | activeTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(trSettings)); |
3255 | craig | 178 | } |
8052 | jghali | 179 | EPSPlug *dia = new EPSPlug(m_Doc, flags); |
3255 | craig | 180 | Q_CHECK_PTR(dia); |
13371 | jghali | 181 | dia->import(fileName, trSettings, flags); |
11576 | avox | 182 | if (activeTransaction) |
183 | { |
||
184 | activeTransaction->commit(); |
||
185 | delete activeTransaction; |
||
186 | activeTransaction = NULL; |
||
187 | } |
||
13371 | jghali | 188 | if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) |
3255 | craig | 189 | UndoManager::instance()->setUndoEnabled(true); |
190 | delete dia; |
||
191 | return true; |
||
192 | } |