Diff of /gsoc2009/textfilter/scribus/plugins/idmlimplugin/importidmlplugin.cpp [000000] .. [r373] Maximize Restore

  Switch to side-by-side view

--- a
+++ b/gsoc2009/textfilter/scribus/plugins/idmlimplugin/importidmlplugin.cpp
@@ -0,0 +1,151 @@
+/*
+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 "commonstrings.h"
+#include "ui/customfdialog.h"
+#include "importidml.h"
+#include "importidmlplugin.h"
+#include "menumanager.h"
+#include "page.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
+#include "prefsmanager.h"
+#include "scraction.h"
+#include "scribuscore.h"
+#include "undomanager.h"
+#include "util_formats.h"
+
+int importidml_getPluginAPIVerion()
+{
+	return PLUGIN_API_VERSION;
+}
+
+ScPlugin* importidml_getPlugin()
+{
+	ImportIdmlPlugin* plug = dynamic_cast<ImportIdmlPlugin*>(plugin);
+	Q_ASSERT(plug);
+	delete plug;
+}
+
+ImportIdmlPlugin::ImportIdmlPlugin(): LoadSavePlugin(),
+	importAction(new ScrAction(ScrAction::DLL,QPixmap(),QPixmap(),"",QKeySequence(),this))
+{
+	// Set action info in languageChange, so we only have to do it in one
+	// place. This includes registering file format support.
+	languageChange();
+}
+
+void ImportIdmlPlugin::languageChange()
+{
+	importAction->setText(tr("Import Idml..."));
+	// (Re)register file formats
+	unregisterAll();
+	registerFormats();
+}
+
+ImportIdmlPlugin::~ImportIdmlPlugin()
+{
+	unregisterAll();
+}
+
+const QString ImportIdmlPlugin::fullTrName() const
+{
+	return QObject::tr("Idml Importer");
+}
+
+const ScActionPlugin::AboutData* ImportIdmlPlugin::getAboutData() const
+{
+	AboutData *about = new AboutData;
+	about->authors = "Jain Basil Aliyas<jainbasil@gmail.com>";
+	about->shortDescription = tr("Imports Adobe Idml Packages");
+	about->description = tr("Imports Adobe Indesign's idml packages into Scribus\n converting Indesign objects into scribus pageitems; not all are supported in Scribus, but all those supported are being imported here");
+	about->license = tr("GPL");
+	Q_CHECK_PTR(about);
+	return about;
+}
+
+void ImportIdmlPlugin::deleteAboutData(const AboutData* about) const
+{
+	Q_ASSERT(about);
+	delete(about);
+}
+
+void ImportIdmlPlugin::registerFormats()
+{
+	FileFormat fmt(this);
+	QString idmlName=tr("Adobe Indesign Markup Language Package","Import/Export Name");
+	fmt.trName = idmlName;
+	fmt.formatId = FORMATID_IDMLIMPORT;
+	fmt.filter =idmlName + "(*.idml *.IDML)"; // QFileDialog filter
+	fmt.nameMatch = QRegExp("\\.idml$", Qt::CaseInsensitive);
+	fmt.load = true;
+	fmt.save = false;
+	fmt.mimeTypes = QStringList("application/vnd.adobe.indesign-idml-package"); // MIME types
+	fmt.priority = 64; // Priority
+	registerFormat(fmt);
+}
+
+bool ImportIdmlPlugin::fileSupported(QIODevice * /*file */,const QString &fileName) const
+{
+	return true;
+}
+
+bool ImportIdmlPlugin::loadFile(const QString & fileName, const FileFormat &, int flags, int /*index */ )
+{
+	/* We just call the import function here since there is only one format to handle */
+	return import(fileName,flags);
+}
+
+bool ImportIdmlPlugin::import(QString fileName, int flags)
+{
+	if(!checkFlags(flags))
+	{
+		return false;
+	}
+	if(fileName.isEmpty())
+	{
+		flags |= lflInteractive;
+		PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("importidml");
+		QString wdir = prefs->get("wdir", ".");
+		CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), tr("All Supported Formats")+" (*.idml *.IDML);;All Files (*)");
+		if(diaf.exec())
+		{
+			fileName = diaf.selectedFile();
+			prefs->set("wdir", fileName.left(fileName.lastIndexOf("/")));
+		}
+		else
+			return true;
+	}
+	
+	m_Doc = ScCore->primaryMainWindow()->doc;
+	UndoTransaction* activeTransaction = NULL;
+	bool emptyDoc = (m_Doc == NULL);
+	bool hasCurrentPage = (m_Doc && m_Doc->currentPage());
+	TransactionSettings trSettings;
+	trSettings.targetName   = hasCurrentPage ? m_Doc->currentPage()->getUName() : "";
+	trSettings.targetPixmap = Um::IImageFrame; //using IImageFrame for now.
+	trSettings.actionName   = Um::ImportIDML;
+	trSettings.description  = fileName;
+	trSettings.actionPixmap = Um::IXFIG;//Using action pixmap as IXFIG for now, later on we will change it
+	if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted))
+		UndoManager::instance()->setUndoEnabled(false);
+	if (UndoManager::undoEnabled())
+		activeTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(trSettings));
+	IdmlPlug *dia = new IdmlPlug(m_Doc, flags);
+	Q_CHECK_PTR(dia);
+	dia->import(fileName, trSettings, flags);
+	if (activeTransaction)
+	{
+		activeTransaction->commit();
+		delete activeTransaction;
+		activeTransaction = NULL;
+	}
+	if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted))
+		UndoManager::instance()->setUndoEnabled(true);
+	delete dia;
+	return true;
+}