~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

« back to all changes in this revision

Viewing changes to scribus/plugins/psimport/importpsplugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2010-07-15 12:43:00 UTC
  • mfrom: (0.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100715124300-2u304r2rvy55vpkv
Tags: 1.3.7.dfsg~svn20100715-1
* Upstream svn. update.
* debian/scribus-ng.lintian: Updated overrides.
* debian/control: Updated standards version to 3.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#include "customfdialog.h"
9
 
#include "importps.h"
10
 
#include "importpsplugin.h"
11
 
#include "menumanager.h"
12
 
#include "page.h"
13
 
#include "prefscontext.h"
14
 
#include "prefsfile.h"
15
 
#include "prefsmanager.h"
16
 
#include "scraction.h"
17
 
#include "scribuscore.h"
18
 
#include "undomanager.h"
19
 
#include "util_formats.h"
20
 
 
21
 
int importps_getPluginAPIVersion()
22
 
{
23
 
        return PLUGIN_API_VERSION;
24
 
}
25
 
 
26
 
ScPlugin* importps_getPlugin()
27
 
{
28
 
        ImportPSPlugin* plug = new ImportPSPlugin();
29
 
        Q_CHECK_PTR(plug);
30
 
        return plug;
31
 
}
32
 
 
33
 
void importps_freePlugin(ScPlugin* plugin)
34
 
{
35
 
        ImportPSPlugin* plug = dynamic_cast<ImportPSPlugin*>(plugin);
36
 
        Q_ASSERT(plug);
37
 
        delete plug;
38
 
}
39
 
 
40
 
ImportPSPlugin::ImportPSPlugin() : LoadSavePlugin(),
41
 
        importAction(new ScrAction(ScrAction::DLL, QPixmap(), QPixmap(), "", QKeySequence(), this))
42
 
{
43
 
        // Set action info in languageChange, so we only have to do it in one
44
 
        // place. This includes registering file format support.
45
 
        languageChange();
46
 
}
47
 
/*
48
 
void ImportPSPlugin::addToMainWindowMenu(ScribusMainWindow *mw)
49
 
{
50
 
        importAction->setEnabled(true);
51
 
        connect( importAction, SIGNAL(triggered()), SLOT(import()) );
52
 
        mw->scrMenuMgr->addMenuItem(importAction, "FileImport");
53
 
}
54
 
*/
55
 
void ImportPSPlugin::languageChange()
56
 
{
57
 
        importAction->setText( tr("Import PostScript..."));
58
 
        // (Re)register file format support
59
 
        unregisterAll();
60
 
        registerFormats();
61
 
}
62
 
 
63
 
ImportPSPlugin::~ImportPSPlugin()
64
 
{
65
 
        unregisterAll();
66
 
};
67
 
 
68
 
const QString ImportPSPlugin::fullTrName() const
69
 
{
70
 
        return QObject::tr("PostScript Importer");
71
 
}
72
 
 
73
 
 
74
 
const ScActionPlugin::AboutData* ImportPSPlugin::getAboutData() const
75
 
{
76
 
        AboutData* about = new AboutData;
77
 
        about->authors = "Franz Schmid <franz@scribus.info>";
78
 
        about->shortDescription = tr("Imports PostScript Files");
79
 
        about->description = tr("Imports most PostScript files into the current document,\nconverting their vector data into Scribus objects.");
80
 
        about->license = "GPL";
81
 
        Q_CHECK_PTR(about);
82
 
        return about;
83
 
}
84
 
 
85
 
void ImportPSPlugin::deleteAboutData(const AboutData* about) const
86
 
{
87
 
        Q_ASSERT(about);
88
 
        delete about;
89
 
}
90
 
 
91
 
void ImportPSPlugin::registerFormats()
92
 
{
93
 
        FileFormat fmt(this);
94
 
        fmt.trName = FormatsManager::instance()->nameOfFormat(FormatsManager::PS); // Human readable name
95
 
        fmt.formatId = FORMATID_PSIMPORT;
96
 
        fmt.filter = FormatsManager::instance()->extensionsForFormat(FormatsManager::EPS|FormatsManager::PS);// QFileDialog filter
97
 
        fmt.nameMatch = QRegExp("\\.("+FormatsManager::instance()->extensionListForFormat(FormatsManager::EPS|FormatsManager::PS, 1)+")$", Qt::CaseInsensitive);
98
 
        fmt.load = true;
99
 
        fmt.save = false;
100
 
        fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::PS); // MIME types
101
 
        fmt.priority = 64; // Priority
102
 
        registerFormat(fmt);
103
 
 
104
 
        FileFormat fmt2(this);
105
 
        fmt2.trName = FormatsManager::instance()->nameOfFormat(FormatsManager::PDF); // Human readable name
106
 
        fmt2.formatId = FORMATID_PDFIMPORT;
107
 
        fmt2.filter = FormatsManager::instance()->extensionsForFormat(FormatsManager::PDF);// QFileDialog filter
108
 
        fmt2.nameMatch = QRegExp("\\."+FormatsManager::instance()->extensionListForFormat(FormatsManager::PDF, 1)+"$", Qt::CaseInsensitive);
109
 
        fmt2.load = true;
110
 
        fmt2.save = false;
111
 
        fmt2.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::PDF); // MIME types
112
 
        fmt2.priority = 64; // Priority
113
 
        registerFormat(fmt2);
114
 
}
115
 
 
116
 
bool ImportPSPlugin::fileSupported(QIODevice* /* file */, const QString & fileName) const
117
 
{
118
 
        // TODO: check for %!PS-Adobe
119
 
        return true;
120
 
}
121
 
 
122
 
bool ImportPSPlugin::loadFile(const QString & fileName, const FileFormat &, int flags, int /*index*/)
123
 
{
124
 
        // There's only one format to handle, so we just call import(...)
125
 
        return import(fileName, flags);
126
 
}
127
 
 
128
 
bool ImportPSPlugin::import(QString fileName, int flags)
129
 
{
130
 
        if (!checkFlags(flags))
131
 
                return false;
132
 
        if( fileName.isEmpty() )
133
 
        {
134
 
                flags |= lfInteractive;
135
 
                PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("importps");
136
 
                QString wdir = prefs->get("wdir", ".");
137
 
                CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), FormatsManager::instance()->fileDialogFormatList(FormatsManager::EPS|FormatsManager::PS));
138
 
                if (diaf.exec())
139
 
                {
140
 
                        fileName = diaf.selectedFile();
141
 
                        prefs->set("wdir", fileName.left(fileName.lastIndexOf("/")));
142
 
                }
143
 
                else
144
 
                        return true;
145
 
        }
146
 
        m_Doc=ScCore->primaryMainWindow()->doc;
147
 
        UndoTransaction* activeTransaction = NULL;
148
 
        bool emptyDoc = (m_Doc == NULL);
149
 
        bool hasCurrentPage = (m_Doc && m_Doc->currentPage());
150
 
        TransactionSettings trSettings;
151
 
        trSettings.targetName   = hasCurrentPage ? m_Doc->currentPage()->getUName() : "";
152
 
        trSettings.targetPixmap = Um::IImageFrame;
153
 
        trSettings.actionName   = Um::ImportEPS;
154
 
        trSettings.description  = fileName;
155
 
        trSettings.actionPixmap = Um::IEPS;
156
 
        if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted))
157
 
                UndoManager::instance()->setUndoEnabled(false);
158
 
        if (UndoManager::undoEnabled())
159
 
        {
160
 
                activeTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(trSettings));
161
 
        }
162
 
        EPSPlug *dia = new EPSPlug(m_Doc, flags);
163
 
        Q_CHECK_PTR(dia);
164
 
        dia->import(fileName, trSettings, flags);
165
 
        if (activeTransaction)
166
 
        {
167
 
                activeTransaction->commit();
168
 
                delete activeTransaction;
169
 
                activeTransaction = NULL;
170
 
        }
171
 
        if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted))
172
 
                UndoManager::instance()->setUndoEnabled(true);
173
 
        delete dia;
174
 
        return true;
175
 
}