r14678 by fschmid - The scrapbook can now use vector files too, this works with all vector files for which thumbnail generation works.

scribus-commit scribus-commit at lists.scribus.net
Wed Feb 10 13:50:51 CET 2010


Revision: 14678
Author: fschmid
Date: 2010-02-10T12:42:42.055834Z
Commit message: The scrapbook can now use vector files too, this works with all vector files for which thumbnail generation works.

Changeset: 
M  /trunk/Scribus/scribus/plugins/import/xar/importxarplugin.cpp
M  /trunk/Scribus/scribus/loadsaveplugin.cpp
M  /trunk/Scribus/scribus/plugins/import/drw/importdrwplugin.cpp
M  /trunk/Scribus/scribus/ui/customfdialog.cpp
M  /trunk/Scribus/scribus/plugins/import/wpg/importwpgplugin.cpp
M  /trunk/Scribus/scribus/plugins/import/xfig/importxfigplugin.cpp
M  /trunk/Scribus/scribus/ui/scrapbookpalette.cpp
M  /trunk/Scribus/scribus/plugins/import/cgm/importcgmplugin.cpp
M  /trunk/Scribus/scribus/plugins/import/pct/importpctplugin.cpp
M  /trunk/Scribus/scribus/loadsaveplugin.h
M  /trunk/Scribus/scribus/plugins/import/cvg/importcvgplugin.cpp

Diffs:
Index: scribus/loadsaveplugin.h
===================================================================
--- scribus/loadsaveplugin.h	(revision 14677)
+++ scribus/loadsaveplugin.h	(revision 14678)
@@ -57,6 +57,8 @@
 
 		// Return a list of file extensions
 		static const QStringList getExtensionsForImport(const int id = 47);
+		// Return a list of file extensions
+		static const QStringList getExtensionsForPreview(const int id = 47);
 
 		// Return a list of format descriptions suitable for use with
 		// QFileDialog.  You can convert it to QString form with
@@ -181,9 +183,9 @@
 {
 	public:
 		// Default ctor to make QValueList happy
-		FileFormat() : load(false), save(false), plug(0) {}
+		FileFormat() : load(false), save(false), thumb(false), plug(0) {}
 		// Standard ctor that sets up a valid FileFormat
-		FileFormat(LoadSavePlugin * plug) : load(false), save(false), plug(plug) {}
+		FileFormat(LoadSavePlugin * plug) : load(false), save(false), thumb(false), plug(plug) {}
 		// Load a file with this format
 		bool loadFile(const QString & fileName, int flags, int index = 0) const;
 		// Save a file with this format
@@ -226,6 +228,8 @@
 		bool load;
 		// Can we save it?
 		bool save;
+		// Do we support thumbnails
+		bool thumb;
 		// Priority of this format from 0 (lowest, tried last) to
 		// 255 (highest, tried first). 64-128 recommended in general.
 		// Priority controls the order options are displayed in when a file
Index: scribus/loadsaveplugin.cpp
===================================================================
--- scribus/loadsaveplugin.cpp	(revision 14677)
+++ scribus/loadsaveplugin.cpp	(revision 14678)
@@ -92,6 +92,38 @@
 	return filterList;
 }
 
+const QStringList LoadSavePlugin::getExtensionsForPreview(const int id)
+{
+	QList<FileFormat>::const_iterator it(findFormat(id));
+	QList<FileFormat>::const_iterator itEnd(formats.constEnd());
+	QStringList filterList;
+	// We know the list is sorted by id, then priority, so we can just take the
+	// highest priority entry for each ID, and we can start with the first entry
+	// in the list.
+	//First, check if we even have any plugins to load with
+	if (it!=itEnd)
+	{
+		if (((*it).load) && ((*it).thumb))
+			filterList.append((*it).fileExtensions);
+		unsigned int lastID = (*it).formatId;
+		++it;
+		for ( ; it != itEnd ; ++it )
+		{
+			// Find the next load/save (as appropriate) plugin for the next format type
+			if ((((*it).load) && ((*it).thumb)) && ((*it).formatId > lastID))
+			{
+				// And add it to the filter list, since we know it's 
+				// the highest priority because of the sort order.
+				filterList.append((*it).fileExtensions);
+				lastID = (*it).formatId;
+			}
+		}
+	}
+	else
+		qDebug("%s", tr("No File Loader Plugins Found").toLocal8Bit().data());
+	return filterList;
+}
+
 const QStringList LoadSavePlugin::getDialogFilter(bool forLoad)
 {
 	QList<FileFormat>::const_iterator it(formats.constBegin());
@@ -422,7 +454,7 @@
 
 QImage FileFormat::readThumbnail(const QString& fileName) const
 {
-	return (plug && load) ? plug->readThumbnail(fileName) : QImage();
+	return (plug && load && thumb) ? plug->readThumbnail(fileName) : QImage();
 }
 
 
Index: scribus/ui/customfdialog.cpp
===================================================================
--- scribus/ui/customfdialog.cpp	(revision 14677)
+++ scribus/ui/customfdialog.cpp	(revision 14678)
@@ -148,7 +148,7 @@
  	QStringList formats = formatD.split("|");
 	formats.append("pat");
 	
-	QStringList allFormatsV = LoadSavePlugin::getExtensionsForImport(FORMATID_ODGIMPORT);
+	QStringList allFormatsV = LoadSavePlugin::getExtensionsForPreview(FORMATID_ODGIMPORT);
 	if (ext.isEmpty())
 		ext = getImageType(name);
 	if (formats.contains(ext.toUtf8()))
Index: scribus/ui/scrapbookpalette.cpp
===================================================================
--- scribus/ui/scrapbookpalette.cpp	(revision 14677)
+++ scribus/ui/scrapbookpalette.cpp	(revision 14678)
@@ -43,6 +43,9 @@
 #include "query.h"
 #include "scpreview.h"
 #include "stencilreader.h"
+#include "fileloader.h"
+#include "loadsaveplugin.h"
+#include "plugins/formatidlist.h"
 #include "util.h"
 #include "util_file.h"
 #include "util_icon.h"
@@ -71,6 +74,7 @@
 
  void BibView::startDrag(Qt::DropActions supportedActions)
  {
+	QStringList vectorFiles = LoadSavePlugin::getExtensionsForPreview(FORMATID_ODGIMPORT);
 	QString dt = objectMap[currentItem()->text()].Data;
 	QFileInfo fi(dt);
 	if (fi.suffix().toLower() == "sml")
@@ -99,6 +103,14 @@
 			dt = ur.toString();
 		}
 	}
+	else if (vectorFiles.contains(fi.suffix().toLower()))
+	{
+		if ( fi.exists() )
+		{
+			QUrl ur = QUrl::fromLocalFile(dt);
+			dt = ur.toString();
+		}
+	}
 	QMimeData *mimeData = new QMimeData;
 	mimeData->setText(dt);
 	QDrag *drag = new QDrag(this);
@@ -361,6 +373,51 @@
 			pm.save(QDir::cleanPath(QDir::convertSeparators(fi3.path()+"/"+fi3.baseName()+".png")), "PNG");
 		}
 	}
+	QStringList vectorFiles = LoadSavePlugin::getExtensionsForPreview(FORMATID_ODGIMPORT);
+	for (int v = 0; v < vectorFiles.count(); v++)
+	{
+		QString ext = "*." + vectorFiles[v];
+		QDir d4(name, ext, QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
+		if ((d4.exists()) && (d4.count() != 0))
+		{
+			for (uint dc = 0; dc < d4.count(); ++dc)
+			{
+				QByteArray cf;
+				if (!loadRawText(QDir::cleanPath(QDir::convertSeparators(oldName + "/" + d4[dc])), cf))
+					continue;
+				QFile fil(QDir::cleanPath(QDir::convertSeparators(name + "/" + d4[dc])));
+				if(!fil.open(QIODevice::WriteOnly))
+					continue ;
+				QDataStream s(&fil);
+				s.writeRawData(cf.data(), cf.length());
+				fil.close();
+				QPixmap pm;
+				QFileInfo fi(QDir::cleanPath(QDir::convertSeparators(name + "/" + d4[dc])));
+				QFileInfo fi2(QDir::cleanPath(QDir::convertSeparators(fi.path()+"/"+fi.baseName()+".png")));
+				if (fi2.exists())
+					pm.load(QDir::cleanPath(QDir::convertSeparators(fi.path()+"/"+fi.baseName()+".png")));
+				else
+				{
+					FileLoader *fileLoader = new FileLoader(QDir::cleanPath(QDir::convertSeparators(name + "/" + d4[dc])));
+					int testResult = fileLoader->TestFile();
+					delete fileLoader;
+					if ((testResult != -1) && (testResult >= FORMATID_ODGIMPORT))
+					{
+						const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult);
+						if( fmt )
+						{
+							QImage im = fmt->readThumbnail(QDir::cleanPath(QDir::convertSeparators(name + "/" + d4[dc])));
+							if (canWrite)
+								im.save(QDir::cleanPath(QDir::convertSeparators(fi.path()+"/"+fi.baseName()+".png")), "PNG");
+							pm = QPixmap::fromImage(im);
+						}
+					}
+				}
+				QFileInfo fi3(QDir::cleanPath(QDir::convertSeparators(name + "/" + d4[dc])));
+				pm.save(QDir::cleanPath(QDir::convertSeparators(fi3.path()+"/"+fi3.baseName()+".png")), "PNG");
+			}
+		}
+	}
 }
 
 void BibView::ReadOldContents(QString name, QString newName)
@@ -497,6 +554,41 @@
 			AddObj(fi.baseName(), QDir::cleanPath(QDir::convertSeparators(name + "/" + d3[dc])), pm);
 		}
 	}
+	QStringList vectorFiles = LoadSavePlugin::getExtensionsForPreview(FORMATID_ODGIMPORT);
+	for (int v = 0; v < vectorFiles.count(); v++)
+	{
+		QString ext = "*." + vectorFiles[v];
+		QDir d4(name, ext, QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
+		if ((d4.exists()) && (d4.count() != 0))
+		{
+			for (uint dc = 0; dc < d4.count(); ++dc)
+			{
+				QPixmap pm;
+				QFileInfo fi(QDir::cleanPath(QDir::convertSeparators(name + "/" + d4[dc])));
+				QFileInfo fi2(QDir::cleanPath(QDir::convertSeparators(fi.path()+"/"+fi.baseName()+".png")));
+				if (fi2.exists())
+					pm.load(QDir::cleanPath(QDir::convertSeparators(fi.path()+"/"+fi.baseName()+".png")));
+				else
+				{
+					FileLoader *fileLoader = new FileLoader(QDir::cleanPath(QDir::convertSeparators(name + "/" + d4[dc])));
+					int testResult = fileLoader->TestFile();
+					delete fileLoader;
+					if ((testResult != -1) && (testResult >= FORMATID_ODGIMPORT))
+					{
+						const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult);
+						if( fmt )
+						{
+							QImage im = fmt->readThumbnail(QDir::cleanPath(QDir::convertSeparators(name + "/" + d4[dc])));
+							if (canWrite)
+								im.save(QDir::cleanPath(QDir::convertSeparators(fi.path()+"/"+fi.baseName()+".png")), "PNG");
+							pm = QPixmap::fromImage(im);
+						}
+					}
+				}
+				AddObj(fi.baseName(), QDir::cleanPath(QDir::convertSeparators(name + "/" + d4[dc])), pm);
+			}
+		}
+	}
 	QMap<QString,Elem>::Iterator itf;
 	for (itf = objectMap.begin(); itf != objectMap.end(); ++itf)
 	{
Index: scribus/plugins/import/cvg/importcvgplugin.cpp
===================================================================
--- scribus/plugins/import/cvg/importcvgplugin.cpp	(revision 14677)
+++ scribus/plugins/import/cvg/importcvgplugin.cpp	(revision 14678)
@@ -99,6 +99,7 @@
 	fmt.fileExtensions = QStringList() << "cvg";
 	fmt.load = true;
 	fmt.save = false;
+	fmt.thumb = true;
 	fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::CVG); // MIME types
 	fmt.priority = 64; // Priority
 	registerFormat(fmt);
Index: scribus/plugins/import/cgm/importcgmplugin.cpp
===================================================================
--- scribus/plugins/import/cgm/importcgmplugin.cpp	(revision 14677)
+++ scribus/plugins/import/cgm/importcgmplugin.cpp	(revision 14678)
@@ -100,6 +100,7 @@
 	fmt.fileExtensions = QStringList() << "cgm";
 	fmt.load = true;
 	fmt.save = false;
+	fmt.thumb = true;
 	fmt.mimeTypes = QStringList(); // MIME types
 	fmt.priority = 64; // Priority
 	registerFormat(fmt);
Index: scribus/plugins/import/pct/importpctplugin.cpp
===================================================================
--- scribus/plugins/import/pct/importpctplugin.cpp	(revision 14677)
+++ scribus/plugins/import/pct/importpctplugin.cpp	(revision 14678)
@@ -92,6 +92,7 @@
 	fmt.fileExtensions = QStringList() << "pct" << "pic" << "pict";
 	fmt.load = true;
 	fmt.save = false;
+	fmt.thumb = true;
 	fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::PCT); // MIME types
 	fmt.priority = 64; // Priority
 	registerFormat(fmt);
Index: scribus/plugins/import/xar/importxarplugin.cpp
===================================================================
--- scribus/plugins/import/xar/importxarplugin.cpp	(revision 14677)
+++ scribus/plugins/import/xar/importxarplugin.cpp	(revision 14678)
@@ -93,6 +93,7 @@
 	fmt.fileExtensions = QStringList() << "xar";
 	fmt.load = true;
 	fmt.save = false;
+	fmt.thumb = true;
 	fmt.mimeTypes = QStringList(); // MIME types
 	fmt.priority = 64; // Priority
 	registerFormat(fmt);
Index: scribus/plugins/import/drw/importdrwplugin.cpp
===================================================================
--- scribus/plugins/import/drw/importdrwplugin.cpp	(revision 14677)
+++ scribus/plugins/import/drw/importdrwplugin.cpp	(revision 14678)
@@ -101,6 +101,7 @@
 	fmt.fileExtensions = QStringList() << "drw";
 	fmt.load = true;
 	fmt.save = false;
+	fmt.thumb = true;
 	fmt.mimeTypes = QStringList(); // MIME types
 	fmt.priority = 64; // Priority
 	registerFormat(fmt);
Index: scribus/plugins/import/wpg/importwpgplugin.cpp
===================================================================
--- scribus/plugins/import/wpg/importwpgplugin.cpp	(revision 14677)
+++ scribus/plugins/import/wpg/importwpgplugin.cpp	(revision 14678)
@@ -99,6 +99,7 @@
 	fmt.fileExtensions = QStringList() << "wpg";
 	fmt.load = true;
 	fmt.save = false;
+	fmt.thumb = true;
 	fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::WPG); // MIME types
 	fmt.priority = 64; // Priority
 	registerFormat(fmt);
Index: scribus/plugins/import/xfig/importxfigplugin.cpp
===================================================================
--- scribus/plugins/import/xfig/importxfigplugin.cpp	(revision 14677)
+++ scribus/plugins/import/xfig/importxfigplugin.cpp	(revision 14678)
@@ -99,6 +99,7 @@
 	fmt.fileExtensions = QStringList() << "fig";
 	fmt.load = true;
 	fmt.save = false;
+	fmt.thumb = true;
 	fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::XFIG); // MIME types
 	fmt.priority = 64; // Priority
 	registerFormat(fmt);




More information about the scribus-commit mailing list