r14535 by fschmid - Changed the file loader with plugins slightly, its now no longer needed to specify a FileID Number in the formatidlist.h file. Setting FileFormat::formatID to 0 in your plugin will automatically assign an ID for you. No more changing of main source files is re- quired to write new plugins.

scribus-commit scribus-commit at lists.scribus.net
Tue Jan 19 14:20:42 CET 2010


Revision: 14535
Author: fschmid
Date: 2010-01-19T13:17:52.507284Z
Commit message: Changed the file loader with plugins slightly, its now no longer needed to specify a
FileID Number in the formatidlist.h file. Setting FileFormat::formatID to 0 in your plugin
will automatically assign an ID for you. No more changing of main source files is re-
quired to write new plugins.

Changeset: 
M  /trunk/Scribus/scribus/util_formats.cpp
M  /trunk/Scribus/scribus/plugins/import/xar/importxarplugin.cpp
M  /trunk/Scribus/scribus/loadsaveplugin.cpp
M  /trunk/Scribus/scribus/util_formats.h
M  /trunk/Scribus/scribus/plugins/import/idml/importidml.cpp
M  /trunk/Scribus/scribus/plugins/import/cgm/importcgmplugin.cpp
M  /trunk/Scribus/scribus/loadsaveplugin.h
M  /trunk/Scribus/scribus/scribusdoc.h
M  /trunk/Scribus/scribus/plugins/formatidlist.h

Diffs:
Index: scribus/loadsaveplugin.h
===================================================================
--- scribus/loadsaveplugin.h	(revision 14534)
+++ scribus/loadsaveplugin.h	(revision 14535)
@@ -65,6 +65,7 @@
 		// Get the highest priority format of a given id, or 0 if
 		// not found / not available.
 		static const FileFormat * getFormatById(const int id);
+		static FileFormat* getFormatByExt(const QString ext);
 
 		// Non-static members implemented by plugins:
 		//
@@ -107,7 +108,7 @@
 		virtual bool checkFlags(int flags);
 
 		/// Register the passed format so it can be used by the app
-		void registerFormat(const FileFormat & fmt);
+		void registerFormat(FileFormat & fmt);
 
 		/// Unregister the format with format ID `id' that references by the calling plugin.
 		void unregisterFormat(unsigned int id);
Index: scribus/util_formats.cpp
===================================================================
--- scribus/util_formats.cpp	(revision 14534)
+++ scribus/util_formats.cpp	(revision 14535)
@@ -37,9 +37,6 @@
 #endif
 	m_fmts.insert(FormatsManager::UNICONV, QStringList() << "cdr" << "cdt" << "ccx" << "cmx" << "aff" << "sk" << "sk1");
 	m_fmts.insert(FormatsManager::PCT,  QStringList() << "pct" << "pic" << "pict");
-	m_fmts.insert(FormatsManager::XAR,  QStringList() << "xar");
-	m_fmts.insert(FormatsManager::CGM,  QStringList() << "cgm");
-	m_fmts.insert(FormatsManager::IDML, QStringList() << "idml");
 	
 	m_fmtNames[FormatsManager::EPS]  = QObject::tr("Encapsulated PostScript \"*.eps\"");
 	m_fmtNames[FormatsManager::GIF]  = QObject::tr("GIF");
@@ -62,9 +59,6 @@
 #endif
 	m_fmtNames[FormatsManager::UNICONV] = QObject::tr("UniConvertor File");
 	m_fmtNames[FormatsManager::PCT]  = QObject::tr("Macintosh Pict File");
-	m_fmtNames[FormatsManager::XAR]  = QObject::tr("XARA \"*.xar\" File");
-	m_fmtNames[FormatsManager::CGM]  = QObject::tr("CGM File");
-	m_fmtNames[FormatsManager::IDML]  = QObject::tr("IDML File");
 	
 	m_fmtMimeTypes.insert(FormatsManager::EPS,  QStringList() << "application/postscript");
 	m_fmtMimeTypes.insert(FormatsManager::GIF,  QStringList() << "image/gif");
@@ -83,9 +77,6 @@
 	m_fmtMimeTypes.insert(FormatsManager::CVG,  QStringList() << "");
 	m_fmtMimeTypes.insert(FormatsManager::WPG,  QStringList() << "");
 	m_fmtMimeTypes.insert(FormatsManager::PCT,  QStringList() << "");
-	m_fmtMimeTypes.insert(FormatsManager::XAR,  QStringList() << "");
-	m_fmtMimeTypes.insert(FormatsManager::CGM,  QStringList() << "");
-	m_fmtMimeTypes.insert(FormatsManager::IDML, QStringList() << "");
 			
 	QMapIterator<int, QStringList> i(m_fmts);
 	while (i.hasNext()) 
Index: scribus/loadsaveplugin.cpp
===================================================================
--- scribus/loadsaveplugin.cpp	(revision 14534)
+++ scribus/loadsaveplugin.cpp	(revision 14535)
@@ -7,6 +7,7 @@
 #include "loadsaveplugin.h"
 #include "commonstrings.h"
 #include "scribuscore.h"
+#include "plugins/formatidlist.h"
 #include <QList>
 
 QList<FileFormat> LoadSavePlugin::formats;
@@ -40,6 +41,15 @@
 		return &(*it);
 }
 
+FileFormat* LoadSavePlugin::getFormatByExt(const QString ext)
+{
+	QList<FileFormat>::iterator it(findFormat(ext));
+	if (it == formats.end())
+		return 0;
+	else
+		return &(*it);
+}
+
 const QStringList LoadSavePlugin::fileDialogLoadFilter()
 {
 	return getDialogFilter(true);
@@ -127,7 +137,7 @@
 	return true;
 }
 
-void LoadSavePlugin::registerFormat(const FileFormat & fmt)
+void LoadSavePlugin::registerFormat(FileFormat & fmt)
 {
 	// We insert the format in a very specific location so that the formats
 	// list is sorted by ascending id, then descending priority.
@@ -136,16 +146,33 @@
 	//     - Equal ID and lesser or equal priority; or
 	//     - Greater ID
 	// If we don't find one, we insert before the end iterator, ie append.
-	QList<FileFormat>::iterator it(formats.begin());
-	QList<FileFormat>::iterator itEnd(formats.end());
-	while (it != itEnd)
+	if (fmt.formatId == 0) // only for custom plugins
 	{
-		if ( ( ((*it).formatId == fmt.formatId) && ((*it).priority <= fmt.priority) ) ||
-			 ((*it).formatId > fmt.formatId)) 
-				break;
-		++it;
+		uint id;
+		if (formats.isEmpty())
+			id = FORMATID_FIRSTUSER;
+		else
+		{
+			id = qMax(static_cast<int>(formats.last().formatId), FORMATID_FIRSTUSER-1);
+			id++;
+		}
+		fmt.formatId = id;
+		formats.insert(id, fmt);
 	}
-	formats.insert(it, fmt);
+	else
+	{
+		QList<FileFormat>::iterator it(formats.begin());
+		QList<FileFormat>::iterator itEnd(formats.end());
+		while (it != itEnd)
+		{
+			if ( ( ((*it).formatId == fmt.formatId) && ((*it).priority <= fmt.priority) ) ||
+				((*it).formatId > fmt.formatId)) 
+					break;
+			++it;
+		}
+		formats.insert(it, fmt);
+	}
+	//qDebug("Format: Id: %3u, Prio: %3hu, Name: %s", fmt.formatId, fmt.priority, fmt.trName.toLocal8Bit().data() );
 	//printFormatList(); // DEBUG
 }
 
Index: scribus/util_formats.h
===================================================================
--- scribus/util_formats.h	(revision 14534)
+++ scribus/util_formats.h	(revision 14535)
@@ -43,7 +43,7 @@
 #else
 			IMAGESIMGFRAME	= 1|2|4|16|32|64|128|256|512|32768|262144,  // all Types suitable for Image Frames
 #endif
-			VECTORIMAGES	= 1|64|1024|2048|16384|32768|131072|262144|2097152,  // All pure vector image types
+			VECTORIMAGES	= 1|64|1024|2048|16384|32768|131072|262144,  // All pure vector image types
 			RASTORIMAGES	= 2|4|8|32|512|65536,  // All pure rastor image types
 			EPS				= 1,      // Encapsulated PostScript
 			GIF				= 2,      // GIF files
@@ -66,9 +66,6 @@
 #endif
 			UNICONV			= 131072, // UniConvertor
 			PCT				= 262144,  // Mac Pict
-			XAR				= 524288,  // Xara
-			CGM				= 1048576, // CGM
-			IDML			= 2097152 // IDML
 		};
 	
 /*
Index: scribus/scribusdoc.h
===================================================================
--- scribus/scribusdoc.h	(revision 14534)
+++ scribus/scribusdoc.h	(revision 14535)
@@ -685,7 +685,7 @@
 	 */
 	void RecalcPictures(QList<PageItem*>* items, ProfilesL *Pr, ProfilesL *PrCMYK, QProgressBar *dia = 0);
 	/**
-	/**
+	 *
 	 * @brief Find the minX,MinY and maxX,maxY for the canvas required for the doc
 	 */
 	void canvasMinMax(FPoint&, FPoint&);
Index: scribus/plugins/formatidlist.h
===================================================================
--- scribus/plugins/formatidlist.h	(revision 14534)
+++ scribus/plugins/formatidlist.h	(revision 14535)
@@ -15,22 +15,20 @@
 #define FORMATID_SLA12XIMPORT 50
 #define FORMATID_NATIVEIMPORTEND 99
 
-#define FORMATID_ODGIMPORT 100
-#define FORMATID_SXDIMPORT 101
-#define FORMATID_SVGIMPORT 102
-#define FORMATID_EPSIMPORT  103
-#define FORMATID_WMFIMPORT 104
-#define FORMATID_AIIMPORT  105
-#define FORMATID_XFIGIMPORT  106
-#define FORMATID_CVGIMPORT  107
-#define FORMATID_WPGIMPORT  108
+#define FORMATID_ODGIMPORT     100
+#define FORMATID_SXDIMPORT     101
+#define FORMATID_SVGIMPORT     102
+#define FORMATID_EPSIMPORT     103
+#define FORMATID_WMFIMPORT     104
+#define FORMATID_AIIMPORT      105
+#define FORMATID_XFIGIMPORT    106
+#define FORMATID_CVGIMPORT     107
+#define FORMATID_WPGIMPORT     108
 #define FORMATID_UNICONVIMPORT 109
-#define FORMATID_PCTIMPORT 110
-#define FORMATID_PSIMPORT  111
-#define FORMATID_PDFIMPORT 112
-#define FORMATID_XARIMPORT 113
-#define FORMATID_CGMIMPORT 114
-#define FORMATID_IDMLIMPORT 115
+#define FORMATID_PCTIMPORT     110
+#define FORMATID_PSIMPORT      111
+#define FORMATID_PDFIMPORT     112
+#define FORMATID_FIRSTUSER     113
 
 // EXPORT
 
Index: scribus/plugins/import/idml/importidml.cpp
===================================================================
--- scribus/plugins/import/idml/importidml.cpp	(revision 14534)
+++ scribus/plugins/import/idml/importidml.cpp	(revision 14535)
@@ -37,6 +37,7 @@
 {
 	// Set action info in languageChange, so we only have to do
 	// it in one place.
+	registerFormats();
 	languageChange();
 }
 
@@ -47,8 +48,9 @@
 
 void ImportIdml::languageChange()
 {
-	unregisterAll();
-	registerFormats();
+	FileFormat* fmt = getFormatByExt("idml");
+	fmt->trName = tr("Adobe Indesign IDML");
+	fmt->filter = tr("Adobe Indesign IDML (*.idml *.IDML)");
 }
 
 const QString ImportIdml::fullTrName() const
@@ -76,17 +78,16 @@
 void ImportIdml::registerFormats()
 {
 	FileFormat fmt(this);
-        QString idmlName=tr("Adobe Indesign IDML");
+	QString idmlName=tr("Adobe Indesign IDML");
 	fmt.trName = idmlName;
-	fmt.formatId = FORMATID_IDMLIMPORT;
+	fmt.formatId = 0;
 	fmt.filter =idmlName + "(*.idml *.IDML)"; // QFileDialog filter
-	fmt.nameMatch = QRegExp("\\."+FormatsManager::instance()->extensionListForFormat(FormatsManager::IDML, 1)+"$", Qt::CaseInsensitive);
-//        fmt.nameMatch = QRegExp("\\.(idml|IDML)?", Qt::CaseInsensitive);
+	fmt.nameMatch = QRegExp("\\.idml$", Qt::CaseInsensitive);
 	fmt.load = true;
 	fmt.save = false;
-        fmt.mimeTypes = QStringList();
-        fmt.mimeTypes.append("application/vnd.adobe.indesign-idml-package");
-        fmt.priority = 64; // Priority
+	fmt.mimeTypes = QStringList();
+	fmt.mimeTypes.append("application/vnd.adobe.indesign-idml-package");
+	fmt.priority = 64; // Priority
 	registerFormat(fmt);
 }
 
Index: scribus/plugins/import/cgm/importcgmplugin.cpp
===================================================================
--- scribus/plugins/import/cgm/importcgmplugin.cpp	(revision 14534)
+++ scribus/plugins/import/cgm/importcgmplugin.cpp	(revision 14535)
@@ -50,22 +50,16 @@
 {
 	// Set action info in languageChange, so we only have to do it in one
 	// place. This includes registering file format support.
+	registerFormats();
 	languageChange();
 }
-/*
-void ImportXfigPlugin::addToMainWindowMenu(ScribusMainWindow *mw)
-{
-	importAction->setEnabled(true);
-	connect( importAction, SIGNAL(triggered()), SLOT(import()) );
-	mw->scrMenuMgr->addMenuItem(importAction, "FileImport");
-}
-*/
+
 void ImportCgmPlugin::languageChange()
 {
 	importAction->setText( tr("Import Cgm..."));
-	// (Re)register file format support
-	unregisterAll();
-	registerFormats();
+	FileFormat* fmt = getFormatByExt("cgm");
+	fmt->trName = tr("CGM File");
+	fmt->filter = tr("CGM File (*.cgm *.CGM)");
 }
 
 ImportCgmPlugin::~ImportCgmPlugin()
@@ -83,8 +77,8 @@
 {
 	AboutData* about = new AboutData;
 	about->authors = "Franz Schmid <franz at scribus.info>";
-	about->shortDescription = tr("Imports Cgm Files");
-	about->description = tr("Imports most Cgm files into the current document,\nconverting their vector data into Scribus objects.");
+	about->shortDescription = tr("Imports CGM Files");
+	about->description = tr("Imports most binary CGM files into the current document,\nconverting their vector data into Scribus objects.");
 	about->license = "GPL";
 	Q_CHECK_PTR(about);
 	return about;
@@ -99,13 +93,13 @@
 void ImportCgmPlugin::registerFormats()
 {
 	FileFormat fmt(this);
-	fmt.trName = FormatsManager::instance()->nameOfFormat(FormatsManager::CGM); // Human readable name
-	fmt.formatId = FORMATID_CGMIMPORT;
-	fmt.filter = FormatsManager::instance()->extensionsForFormat(FormatsManager::CGM); // QFileDialog filter
-	fmt.nameMatch = QRegExp("\\."+FormatsManager::instance()->extensionListForFormat(FormatsManager::CGM, 1)+"$", Qt::CaseInsensitive);
+	fmt.trName = tr("CGM File"); // Human readable name
+	fmt.formatId = 0;
+	fmt.filter = tr("CGM File (*.cgm *.CGM)"); // QFileDialog filter
+	fmt.nameMatch = QRegExp("\\.cgm$", Qt::CaseInsensitive);
 	fmt.load = true;
 	fmt.save = false;
-	fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::CGM); // MIME types
+	fmt.mimeTypes = QStringList(); // MIME types
 	fmt.priority = 64; // Priority
 	registerFormat(fmt);
 }
Index: scribus/plugins/import/xar/importxarplugin.cpp
===================================================================
--- scribus/plugins/import/xar/importxarplugin.cpp	(revision 14534)
+++ scribus/plugins/import/xar/importxarplugin.cpp	(revision 14535)
@@ -43,15 +43,16 @@
 {
 	// Set action info in languageChange, so we only have to do it in one
 	// place. This includes registering file format support.
+	registerFormats();
 	languageChange();
 }
 
 void ImportXarPlugin::languageChange()
 {
-	importAction->setText( tr("Import Pict..."));
-	// (Re)register file format support
-	unregisterAll();
-	registerFormats();
+	importAction->setText( tr("Import Xara..."));
+	FileFormat* fmt = getFormatByExt("xar");
+	fmt->trName = tr("XARA \"*.xar\" File");
+	fmt->filter = tr("XARA \"*.xar\" File (*.xar *.XAR)");
 }
 
 ImportXarPlugin::~ImportXarPlugin()
@@ -85,13 +86,13 @@
 void ImportXarPlugin::registerFormats()
 {
 	FileFormat fmt(this);
-	fmt.trName = FormatsManager::instance()->nameOfFormat(FormatsManager::XAR); // Human readable name
-	fmt.formatId = FORMATID_XARIMPORT;
-	fmt.filter = FormatsManager::instance()->extensionsForFormat(FormatsManager::XAR); // QFileDialog filter
-	fmt.nameMatch = QRegExp("\\."+FormatsManager::instance()->extensionListForFormat(FormatsManager::XAR, 1)+"$", Qt::CaseInsensitive);
+	fmt.trName = tr("XARA \"*.xar\" File"); // Human readable name
+	fmt.formatId = 0;
+	fmt.filter = tr("XARA \"*.xar\" File (*.cgm *.CGM)"); // QFileDialog filter
+	fmt.nameMatch = QRegExp("\\.xar$", Qt::CaseInsensitive);
 	fmt.load = true;
 	fmt.save = false;
-	fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::XAR); // MIME types
+	fmt.mimeTypes = QStringList(); // MIME types
 	fmt.priority = 64; // Priority
 	registerFormat(fmt);
 }




More information about the scribus-commit mailing list