Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r373]: gsoc2009 / textfilter / scribus / plugins / idmlimplugin / importidml.cpp Maximize Restore History

Download this file

importidml.cpp    185 lines (177 with data), 5.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include <QByteArray>
#include <QCursor>
#include <QDrag>
#include <QFile>
#include <QMimeData>
#include <QRegExp>
#include <QTextCodec>
#include <QDebug>
#include "designmap.h"
#include "idmlstyles.h"
#include "spreads.h"
#include "ui/customfdialog.h"
#include "importidml.h"
#include "loadsaveplugin.h"
#include "ui/missing.h"
#include "ui/multiprogressdialog.h"
#include "pageitem_imageframe.h"
#include "pageitem_polygon.h"
#include "pageitem_polyline.h"
#include "pagesize.h"
#include "prefscontext.h"
#include "prefsfile.h"
#include "prefsmanager.h"
#include "prefstable.h"
#include "ui/propertiespalette.h"
#include "rawimage.h"
#include "scclocale.h"
#include "sccolorengine.h"
#include "scconfig.h"
#include "scmimedata.h"
#include "scpaths.h"
#include "scpattern.h"
#include "scribus.h"
#include "scribusXml.h"
#include "scribuscore.h"
#include "sctextstream.h"
#include "selection.h"
#include "undomanager.h"
#include "util.h"
#include "util_formats.h"
#include "util_icon.h"
#include "util_math.h"
extern SCRIBUS_API ScribusQApp * ScQApp;
IdmlPlug::IdmlPlug(ScribusDoc* doc, int flags)
{
tmpSel=new Selection(this, false);
m_Doc=doc;
interactive = (flags & LoadSavePlugin::lfInteractive);
}
bool IdmlPlug::import(QString fn, const TransactionSettings& trSettings, int flags, bool showProgress = true)
{
QString fName = fn;
bool success = false;
interactive = (flags & LoadSavePlugin::lflInteractive);
importerFlags = flags;
cancel = false;
double x,y,b,h;
bool ret = false;
QFileInfo fi = QFileInfo(fName);
if ( !ScCore->usingGUI() )
{
interactive = false;
showProgress = false;
}
baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/"));
if( showProgress )
{
ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw);
QStringList barNames, barTexts;
barNames<< "GI";
barTextx<< tr("Analyzing File:");
QList<bool> barsNumeric;
barsNumeric = false;
progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
progressDialog->setOverallTotalSteps(3);
progressDialog->setOverallProgress(0);
progressDialog->setProgress("GI", 0);
progressDialog->show();
connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
qApp->processEvents();
}
else
progressDialog = NULL;
/* Now we set default page to size defined in Preferences */
x = 0.0;
y = 0.0;
b = 0.0;
h = 0.0;
if(progressDialog)
{
progressDialog->setOverallProgress(1);
qApp->processEvents();
}
if (b == 0.0)
b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
if (h == 0.0)
h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
docWidth = b;
docHeight = h;
baseX = 0;
baseY = 0;
if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
{
m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
m_Doc->addPage(0);
m_Doc->view()->addPage(0, true);
baseX = -x;
baseY = -y;
}
else
{
if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
{
m_Doc=ScCore->primaryMainWindow()->doFileNew(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
ScCore->primaryMainWindow()->HaveNewDoc();
ret = true;
baseX = m_Doc->currentPage()->xOffset() - x;
baseY = m_Doc->currentPage()->yOffset() - y;
}
}
if ((!ret) && (interactive))
{
baseX = m_Doc->currentPage()->xOffset() - x;
baseY = m_Doc->currentPage()->yOffset() - y;
}
if ((ret) || (!interactive))
{
if (docWidth > docHeight)
m_Doc->PageOri = 1;
else
m_Doc->PageOri = 0;
m_Doc->m_pageSize = "Custom";
}
Elements.clear();
FPoint minSize = m_Doc->minCanvasCoordinate;
FPoint maxSize = m_Doc->maxCanvasCoordinate;
FPoint cOrigin = m_Doc->view()->canvasOrigin();
m_Doc->setLoading(true);
m_Doc->DoDrawing = false;
m_Doc->view()->updatesOn(false);
m_Doc->scMW()->ScriptRunning = true;
qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
QString CurDirP = QDir::currentPath();
QDir::setCurrent(fi.path());
if(convert(fName))
{
}
}
bool IdmlPlug::convert(QString fn)
{
if(progressDialog)
{
progressDialog->setOverallProgress(2);
progressDialog->setLabel("GI", tr("Generating Items"));
qApp->processEvents();
}
/* The object idmlFile is deleted only after getting all the paths required */
FileUnzip* idmlFile = new FileUnzip(fn);
desmapPath = fun->getFile(DESIGNMAP);
fontPath = fun->getFile(FONTS);
stylePath = fun->getFile(STYLES);
graphicPath = fun->getFile(GRAPHIC);
preferPath = fun->getFile(PREFERENCES);
mspreadPath = fun->getFile(MASTERSPREADS);
if( !desmapPath.isNull() )
{
IDPKGDesignMap *Design = new IDPKGDesignMap(desmapPath);
Design->processDesginMap();
}
}