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

« back to all changes in this revision

Viewing changes to scribus/plugins/wmfimplugin/wmfimportplugin.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 "scconfig.h"
8
 
#include "wmfimportplugin.h"
9
 
 
10
 
#include <QFile>
11
 
#include <QRegExp>
12
 
#include <QCursor>
13
 
 
14
 
#include "customfdialog.h"
15
 
#include "scribus.h"
16
 
#include "scribusXml.h"
17
 
#include "prefsfile.h"
18
 
 
19
 
#include <cmath>
20
 
#include "commonstrings.h"
21
 
#include "fpointarray.h"
22
 
#include "menumanager.h"
23
 
#include "prefsmanager.h"
24
 
#include "pageitem.h"
25
 
#include "scraction.h"
26
 
#include "scribuscore.h"
27
 
#include "scribusdoc.h"
28
 
#include "selection.h"
29
 
#include "undomanager.h"
30
 
#include "loadsaveplugin.h"
31
 
#include "util.h"
32
 
#include "util_formats.h"
33
 
#include "fonts/scfontmetrics.h"
34
 
 
35
 
#include "wmfimport.h"
36
 
 
37
 
using namespace std;
38
 
 
39
 
int wmfimplugin_getPluginAPIVersion()
40
 
{
41
 
        return PLUGIN_API_VERSION;
42
 
}
43
 
 
44
 
ScPlugin* wmfimplugin_getPlugin()
45
 
{
46
 
        WMFImportPlugin* plug = new WMFImportPlugin();
47
 
        Q_CHECK_PTR(plug);
48
 
        return plug;
49
 
}
50
 
 
51
 
void wmfimplugin_freePlugin(ScPlugin* plugin)
52
 
{
53
 
        WMFImportPlugin* plug = dynamic_cast<WMFImportPlugin*>(plugin);
54
 
        Q_ASSERT(plug);
55
 
        delete plug;
56
 
}
57
 
 
58
 
WMFImportPlugin::WMFImportPlugin() : LoadSavePlugin(),
59
 
        importAction(new ScrAction(ScrAction::DLL, QPixmap(), QPixmap(), "", QKeySequence(), this))
60
 
{
61
 
        // Set action info in languageChange, so we only have to do
62
 
        // it in one place. This includes registering file format
63
 
        // support.
64
 
        languageChange();
65
 
}
66
 
/*
67
 
void WMFImportPlugin::addToMainWindowMenu(ScribusMainWindow *mw)
68
 
{
69
 
        importAction->setEnabled(true);
70
 
        connect( importAction, SIGNAL(triggered()), SLOT(import()) );
71
 
        mw->scrMenuMgr->addMenuItem(importAction, "FileImport");
72
 
}
73
 
*/
74
 
WMFImportPlugin::~WMFImportPlugin()
75
 
{
76
 
        unregisterAll();
77
 
};
78
 
 
79
 
void WMFImportPlugin::languageChange()
80
 
{
81
 
        importAction->setText( tr("Import &WMF..."));
82
 
        // (Re)register file format support.
83
 
        unregisterAll();
84
 
        registerFormats();
85
 
}
86
 
 
87
 
const QString WMFImportPlugin::fullTrName() const
88
 
{
89
 
        return QObject::tr("WMF Import");
90
 
}
91
 
 
92
 
const ScActionPlugin::AboutData* WMFImportPlugin::getAboutData() const
93
 
{
94
 
        AboutData* about = new AboutData;
95
 
        about->authors = "Jean Ghali <jghali@scribus.info>";
96
 
        about->shortDescription = tr("Imports WMF Files");
97
 
        about->description = tr("Imports most WMF files into the current document,\nconverting their vector data into Scribus objects.");
98
 
        about->license = "GPL";
99
 
        Q_CHECK_PTR(about);
100
 
        return about;
101
 
}
102
 
 
103
 
void WMFImportPlugin::deleteAboutData(const AboutData* about) const
104
 
{
105
 
        Q_ASSERT(about);
106
 
        delete about;
107
 
}
108
 
 
109
 
void WMFImportPlugin::registerFormats()
110
 
{
111
 
        FileFormat fmt(this);
112
 
        fmt.trName = FormatsManager::instance()->nameOfFormat(FormatsManager::WMF);
113
 
        fmt.formatId = FORMATID_WMFIMPORT;
114
 
        fmt.filter = FormatsManager::instance()->extensionsForFormat(FormatsManager::WMF);
115
 
        fmt.nameMatch = QRegExp("\\."+FormatsManager::instance()->extensionListForFormat(FormatsManager::WMF, 1)+"$", Qt::CaseInsensitive);
116
 
        fmt.load = true;
117
 
        fmt.save = false;
118
 
        fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::WMF);
119
 
        fmt.priority = 64;
120
 
        registerFormat(fmt);
121
 
}
122
 
 
123
 
bool WMFImportPlugin::fileSupported(QIODevice* /* file */, const QString & fileName) const
124
 
{
125
 
        // TODO: identify valid WMF
126
 
        return true;
127
 
}
128
 
 
129
 
bool WMFImportPlugin::loadFile(const QString & fileName, const FileFormat & /* fmt */, int flags, int /*index*/)
130
 
{
131
 
        // For now, "load file" and import are the same thing for this plugin
132
 
        return import(fileName, flags);
133
 
}
134
 
 
135
 
bool WMFImportPlugin::import(QString filename, int flags)
136
 
{
137
 
        if (!checkFlags(flags))
138
 
                return false;
139
 
        m_Doc=ScCore->primaryMainWindow()->doc;
140
 
        ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
141
 
        if (filename.isEmpty())
142
 
        {
143
 
                flags |= lfInteractive;
144
 
                PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("WMFPlugin");
145
 
                QString wdir = prefs->get("wdir", ".");
146
 
                CustomFDialog diaf(mw, wdir, QObject::tr("Open"), FormatsManager::instance()->fileDialogFormatList(FormatsManager::WMF));
147
 
                if (diaf.exec())
148
 
                {
149
 
                        filename = diaf.selectedFile();
150
 
                        prefs->set("wdir", filename.left(filename.lastIndexOf("/")));
151
 
                }
152
 
                else
153
 
                        return true;
154
 
        }
155
 
        
156
 
        bool hasCurrentPage = (m_Doc && m_Doc->currentPage());
157
 
        TransactionSettings trSettings;
158
 
        trSettings.targetName   = hasCurrentPage ? m_Doc->currentPage()->getUName() : "";
159
 
        trSettings.targetPixmap = Um::IImageFrame;
160
 
        trSettings.actionName   = Um::ImportWMF;
161
 
        trSettings.description  = filename;
162
 
        trSettings.actionPixmap = Um::IWMF;
163
 
        UndoTransaction* activeTransaction = NULL;
164
 
        if ((m_Doc == NULL) || !(flags & lfInteractive) || !(flags & lfScripted))
165
 
                UndoManager::instance()->setUndoEnabled(false);
166
 
        if (UndoManager::undoEnabled())
167
 
                activeTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(trSettings));
168
 
        WMFImport *dia = new WMFImport(mw, flags);
169
 
        dia->import(filename, trSettings, flags);
170
 
        Q_CHECK_PTR(dia);
171
 
        if (activeTransaction)
172
 
        {
173
 
                activeTransaction->commit();
174
 
                delete activeTransaction;
175
 
                activeTransaction = NULL;
176
 
        }
177
 
        if ((m_Doc == NULL) || !(flags & lfInteractive) || !(flags & lfScripted))
178
 
                UndoManager::instance()->setUndoEnabled(true);
179
 
        if (dia->importCanceled)
180
 
        {
181
 
                if (dia->importFailed)
182
 
                        QMessageBox::warning(mw, CommonStrings::trWarning, tr("The file could not be imported"), 1, 0, 0);
183
 
                else if (dia->unsupported)
184
 
                        QMessageBox::warning(mw, CommonStrings::trWarning, tr("WMF file contains some unsupported features"), 1, 0, 0);
185
 
        }
186
 
 
187
 
        bool success = !dia->importFailed;
188
 
        delete dia;
189
 
        return success;
190
 
}