r15681 by fschmid - User defined Palettes are now stored in $HOME/.scribus/swatches

scribus-commit scribus-commit at lists.scribus.net
Fri Oct 29 21:16:07 CEST 2010


Author: fschmid
Date: Fri Oct 29 19:16:07 2010
New Revision: 15681

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15681
Log:
User defined Palettes are now stored in $HOME/.scribus/swatches
Added protected folder $HOME/.scribus/swatches/locked

Modified:
    trunk/Scribus/scribus/colorsetmanager.cpp
    trunk/Scribus/scribus/colorsetmanager.h
    trunk/Scribus/scribus/prefsmanager.cpp
    trunk/Scribus/scribus/ui/cmykfw.cpp
    trunk/Scribus/scribus/ui/paintmanager.cpp
    trunk/Scribus/scribus/ui/swatchcombo.cpp

Modified: trunk/Scribus/scribus/colorsetmanager.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15681&path=/trunk/Scribus/scribus/colorsetmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/colorsetmanager.cpp (original)
+++ trunk/Scribus/scribus/colorsetmanager.cpp Fri Oct 29 19:16:07 2010
@@ -12,6 +12,7 @@
 #include "colorsetmanager.h"
 #include "scpaths.h"
 #include "util.h"
+#include "util_icon.h"
 #include "commonstrings.h"
 #include "prefsstructs.h"
 #include <QDomElement>
@@ -134,7 +135,7 @@
 	}
 }
 
-void ColorSetManager::searchDir(QString path, QTreeWidgetItem* parent)
+void ColorSetManager::searchDir(QString path, QMap<QString, QString> &pList, QTreeWidgetItem* parent)
 {
 	QStringList exts;
 	exts << "xml" << "gpl" << "eps" << "ai" << "sla" << "soc";
@@ -147,30 +148,43 @@
 			QFileInfo fi(path + dirs[dc]);
 			if (fi.isDir())
 			{
-				QString setName = fi.baseName();
-				setName.replace("_", " ");
-				if (parent != NULL)
-				{
-					QTreeWidgetItem* item = new QTreeWidgetItem(parent);
-					item->setFlags(Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
-					item->setText(0, setName);
-					searchDir(path + dirs[dc] + "/", item);
-				}
-				else
-					searchDir(path + dirs[dc] + "/", parent);
-			}
-			else
-			{
-				if (exts.contains(fi.suffix().toLower()))
+				QDir sd(path + dirs[dc], "*", QDir::Name, QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files | QDir::NoSymLinks);
+				if (sd.count() > 0)
 				{
 					QString setName = fi.baseName();
 					setName.replace("_", " ");
-					palettes.insert(setName, fi.absoluteFilePath());
+					if (parent != NULL)
+					{
+						QTreeWidgetItem* item;
+						if (path + dirs[dc] == ScPaths::getApplicationDataDir()+"swatches/locked")
+							item = parent;
+						else
+						{
+							item = new QTreeWidgetItem(parent);
+							item->setFlags(Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+							item->setIcon(0, QIcon(loadIcon("16/folder.png")));
+							item->setText(0, setName);
+						}
+						searchDir(path + dirs[dc] + "/", pList, item);
+					}
+					else
+						searchDir(path + dirs[dc] + "/", pList, parent);
+				}
+			}
+			else
+			{
+				if (exts.contains(fi.suffix().toLower()))
+				{
+					QString setName = fi.baseName();
+					setName.replace("_", " ");
+					pList.insert(setName, fi.absoluteFilePath());
 					if (parent != 0)
 					{
 						QTreeWidgetItem* item = new QTreeWidgetItem(parent);
 						item->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
 						item->setText(0, setName);
+						if ((!fi.isWritable()) || (fi.absolutePath().contains(ScPaths::getApplicationDataDir()+"swatches/locked")))
+							item->setIcon(0, QIcon(loadIcon("16/lock.png")));
 					}
 				}
 			}
@@ -185,11 +199,17 @@
 	for ( QStringList::Iterator it = paletteLocations.begin(); it != paletteLocations.end(); ++it )
 	{
 		path = (*it);
-		searchDir(path, parent);
-	}
-}
-
-QStringList ColorSetManager::paletteNames( )
+		searchDir(path, palettes, parent);
+	}
+}
+
+void ColorSetManager::findUserPalettes(QTreeWidgetItem* parent)
+{
+	userPalettes.clear();
+	searchDir(ScPaths::getApplicationDataDir() + "swatches/", userPalettes, parent);
+}
+
+QStringList ColorSetManager::paletteNames()
 {
 	QStringList nameList;
 	for ( QMap<QString, QString>::Iterator it = palettes.begin(); it != palettes.end(); ++it )
@@ -197,6 +217,14 @@
 	return nameList;
 }
 
+QStringList ColorSetManager::userPaletteNames()
+{
+	QStringList nameList;
+	for ( QMap<QString, QString>::Iterator it = userPalettes.begin(); it != userPalettes.end(); ++it )
+		nameList << it.key();
+	return nameList;
+}
+
 QString ColorSetManager::paletteFileFromName(const QString& paletteName)
 {
 	if (palettes.contains(paletteName))
@@ -204,6 +232,13 @@
 	return QString();
 }
 
+QString ColorSetManager::userPaletteFileFromName(const QString& paletteName)
+{
+	if (userPalettes.contains(paletteName))
+		return userPalettes[paletteName];
+	return QString();
+}
+
 bool ColorSetManager::paletteLocationLocked(const QString& palettePath)
 {
 	return (paletteLocationLocks.contains(palettePath) && paletteLocationLocks.value(palettePath)==true);

Modified: trunk/Scribus/scribus/colorsetmanager.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15681&path=/trunk/Scribus/scribus/colorsetmanager.h
==============================================================================
--- trunk/Scribus/scribus/colorsetmanager.h (original)
+++ trunk/Scribus/scribus/colorsetmanager.h Fri Oct 29 19:16:07 2010
@@ -28,15 +28,20 @@
 		
 		void initialiseDefaultPrefs(struct ApplicationPrefs& appPrefs);
 		void findPaletteLocations();
-		void searchDir(QString path, QTreeWidgetItem* parent = NULL);
+		void searchDir(QString path, QMap<QString, QString> &pList, QTreeWidgetItem* parent = NULL);
 		void findPalettes(QTreeWidgetItem* parent = NULL);
+		void findUserPalettes(QTreeWidgetItem* parent = NULL);
 		QStringList paletteNames();
+		QStringList userPaletteNames();
+		
 		QString paletteFileFromName(const QString& paletteName);
+		QString userPaletteFileFromName(const QString& paletteName);
 		bool paletteLocationLocked(const QString& palettePath);
 		
 	protected:
 		QStringList paletteLocations;
 		QMap<QString, QString> palettes;
+		QMap<QString, QString> userPalettes;
 		QMap<QString, bool> paletteLocationLocks;
 };
 #endif

Modified: trunk/Scribus/scribus/prefsmanager.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15681&path=/trunk/Scribus/scribus/prefsmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/prefsmanager.cpp (original)
+++ trunk/Scribus/scribus/prefsmanager.cpp Fri Oct 29 19:16:07 2010
@@ -741,6 +741,14 @@
 		scrapDirectoryT.mkdir(QDir::convertSeparators(scB+"/tmp"));
 	}
 	prefsLocation=PrefsPfad;
+	QFileInfo scSwatch = QFileInfo(ScPaths::getApplicationDataDir()+"swatches");
+	if (!scSwatch.exists())
+	{
+		QDir swatchDir = QDir();
+		swatchDir.mkpath(ScPaths::getApplicationDataDir()+"swatches");
+		swatchDir.mkpath(ScPaths::getApplicationDataDir()+"swatches/locked");
+		
+	}
 	return PrefsPfad;
 }
 
@@ -1620,12 +1628,6 @@
 		kscc.setAttribute("Action",ksc.value().actionName);
 		kscc.setAttribute("KeySequence",TabKeyboardShortcutsWidget::getKeyText(ksc.value().keySequence));
 		elem.appendChild(kscc);
-	}
-	for (int ccs=0; ccs<appPrefs.colorPrefs.CustomColorSets.count(); ++ccs)
-	{
-		QDomElement cos=docu.createElement("ColorSet");
-		cos.setAttribute("Name",appPrefs.colorPrefs.CustomColorSets[ccs]);
-		elem.appendChild(cos);
 	}
 	QDomElement cosd=docu.createElement("DefaultColorSet");
 	cosd.setAttribute("Name",appPrefs.colorPrefs.DColorSet);
@@ -1802,6 +1804,8 @@
 	csm.initialiseDefaultPrefs(appPrefs);
 	csm.findPaletteLocations();
 	csm.findPalettes();
+	csm.findUserPalettes();
+	appPrefs.colorPrefs.CustomColorSets = csm.userPaletteNames();
 	ScColor lf = ScColor();
 	QDomNode DOC=elem.firstChild();
 	if (!DOC.namedItem("CheckProfile").isNull())
@@ -2304,24 +2308,37 @@
 		}
 		if (dc.tagName()=="Substitute")
 		  appPrefs.fontPrefs.GFontSub[dc.attribute("Name")] = dc.attribute("Replace");
-		if (dc.tagName()=="ColorSet")
-			appPrefs.colorPrefs.CustomColorSets.append(dc.attribute("Name"));
 		if (dc.tagName()=="DefaultColorSet")
 		{
 			appPrefs.colorPrefs.DColors.clear();
 			QString pfadC = "";
 			appPrefs.colorPrefs.DColorSet = dc.attribute("Name");
 			if (appPrefs.colorPrefs.CustomColorSets.contains(appPrefs.colorPrefs.DColorSet))
-			{
-				QString Fname = appPrefs.colorPrefs.DColorSet;
-				Fname.replace(" ", "_");
-				Fname += ".xml";
-				pfadC = QDir::convertSeparators(ScPaths::getApplicationDataDir()+Fname);
-			}
+				pfadC = csm.userPaletteFileFromName(appPrefs.colorPrefs.DColorSet);
 			else
 				pfadC = csm.paletteFileFromName(appPrefs.colorPrefs.DColorSet);
 			if (appPrefs.colorPrefs.DColorSet != "Scribus Small")
-				importColorsFromFile(pfadC, appPrefs.colorPrefs.DColors, &appPrefs.defaultGradients, false);
+			{
+				if (importColorsFromFile(pfadC, appPrefs.colorPrefs.DColors, &appPrefs.defaultGradients, false))
+					appPrefs.colorPrefs.DColors.ensureBlackAndWhite();
+				else
+				{
+					appPrefs.colorPrefs.DColors.insert("White", ScColor(0, 0, 0, 0));
+					appPrefs.colorPrefs.DColors.insert("Black", ScColor(0, 0, 0, 255));
+					ScColor cc = ScColor(255, 255, 255, 255);
+					cc.setRegistrationColor(true);
+					appPrefs.colorPrefs.DColors.insert("Registration", cc);
+					appPrefs.colorPrefs.DColors.insert("Blue", ScColor(255, 255, 0, 0));
+					appPrefs.colorPrefs.DColors.insert("Cyan", ScColor(255, 0, 0, 0));
+					appPrefs.colorPrefs.DColors.insert("Green", ScColor(255, 0, 255, 0));
+					appPrefs.colorPrefs.DColors.insert("Red", ScColor(0, 255, 255, 0));
+					appPrefs.colorPrefs.DColors.insert("Yellow", ScColor(0, 0, 255, 0));
+					appPrefs.colorPrefs.DColors.insert("Magenta", ScColor(0, 255, 0, 0));
+					if (appPrefs.colorPrefs.CustomColorSets.contains(appPrefs.colorPrefs.DColorSet))
+						appPrefs.colorPrefs.CustomColorSets.removeAll(appPrefs.colorPrefs.DColorSet);
+					appPrefs.colorPrefs.DColorSet = "Scribus Small";
+				}
+			}
 			else
 			{
 				appPrefs.colorPrefs.DColors.insert("White", ScColor(0, 0, 0, 0));

Modified: trunk/Scribus/scribus/ui/cmykfw.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15681&path=/trunk/Scribus/scribus/ui/cmykfw.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/cmykfw.cpp (original)
+++ trunk/Scribus/scribus/ui/cmykfw.cpp Fri Oct 29 19:16:07 2010
@@ -197,24 +197,7 @@
 	Swatches->addSubItem("Scribus Small", systemSwatches);
 	systemSwatches->setExpanded(true);
 	userSwatches = Swatches->addTopLevelItem( tr("User Swatches"));
-	if (Cust.count() != 0)
-	{
-		QStringList realEx;
-		realEx.clear();
-		for (int m = 0; m < Cust.count(); ++m)
-		{
-			QString Cpfad = QDir::convertSeparators(ScPaths::getApplicationDataDir() + Cust[m] + ".xml");
-			QFileInfo cfi(Cpfad);
-			if (cfi.exists())
-			{
-				QString setName = cfi.baseName();
-				setName.replace("_", " ");
-				Swatches->addSubItem(setName, userSwatches);
-				realEx.append(Cust[m]);
-			}
-		}
-		CColSet = realEx;
-	}
+	csm.findUserPalettes(userSwatches);
 	userSwatches->setExpanded(true);
 	Swatches->setCurrentComboItem( tr( "HSV Color Map" ));
 	Frame4Layout->addWidget( Swatches );
@@ -596,12 +579,7 @@
 		if ( c->parent() != userSwatches)
 			pfadC2 = csm.paletteFileFromName(c->text(0));
 		else
-		{
-			QString listText = c->text(0);
-			listText.replace(" ", "_");
-			listText += ".xml";
-			pfadC2 = QDir::convertSeparators(ScPaths::getApplicationDataDir() + listText);
-		}
+			pfadC2 = csm.userPaletteFileFromName(c->text(0));
 		if (importColorsFromFile(pfadC2, CurrSwatch))
 		{
 			CurrSwatch.insert("White", ScColor(0, 0, 0, 0));

Modified: trunk/Scribus/scribus/ui/paintmanager.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15681&path=/trunk/Scribus/scribus/ui/paintmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/paintmanager.cpp (original)
+++ trunk/Scribus/scribus/ui/paintmanager.cpp Fri Oct 29 19:16:07 2010
@@ -53,7 +53,6 @@
 #include "util_color.h"
 #include "util_formats.h"
 #include "util_icon.h"
-#include <QDebug>
 
 PaintManagerDialog::PaintManagerDialog(QWidget* parent, QMap<QString, VGradient> *docGradients, ColorList doco, QString docColSet, QStringList custColSet, ScribusDoc *doc, ScribusMainWindow *scMW) : QDialog(parent)
 {
@@ -86,24 +85,7 @@
 	LoadColSet->addSubItem("Scribus Small", systemSwatches);
 	systemSwatches->setExpanded(true);
 	userSwatches = LoadColSet->addTopLevelItem( tr("User Swatches"));
-	if (custColSet.count() != 0)
-	{
-		QStringList realEx;
-		realEx.clear();
-		for (int m = 0; m < custColSet.count(); ++m)
-		{
-			QString Cpfad = QDir::convertSeparators(ScPaths::getApplicationDataDir() + custColSet[m] + ".xml");
-			QFileInfo cfi(Cpfad);
-			if (cfi.exists())
-			{
-				QString setName = cfi.baseName();
-				setName.replace("_", " ");
-				LoadColSet->addSubItem(setName, userSwatches);
-				realEx.append(custColSet[m]);
-			}
-		}
-		customColSet = realEx;
-	}
+	csm.findUserPalettes(userSwatches);
 	userSwatches->setExpanded(true);
 	LoadColSet->setCurrentComboItem(docColSet);
 	if (m_doc != 0)
@@ -114,18 +96,19 @@
 	}
 	else
 	{
-		QString pfad = "";
-		if (custColSet.contains(docColSet))
-		{
-			QString Fname = docColSet;
-			Fname.replace(" ", "_");
-			Fname += ".xml";
-			pfad = QDir::convertSeparators(ScPaths::getApplicationDataDir()+Fname);
-		}
-		else
-			pfad = csm.paletteFileFromName(docColSet);
-		QFileInfo fi(pfad);
-		paletteLocked = !fi.isWritable();
+		if (docColSet != "Scribus Small")
+		{
+			QString pfad = "";
+			if (custColSet.contains(docColSet))
+				pfad = csm.userPaletteFileFromName(docColSet);
+			else
+				pfad = csm.paletteFileFromName(docColSet);
+			QFileInfo fi(pfad);
+			if (fi.absolutePath().contains(ScPaths::getApplicationDataDir()+"swatches/locked"))
+				paletteLocked = true;
+			else
+				paletteLocked = !fi.isWritable();
+		}
 	}
 	importButton->setEnabled(false);
 	newButton->setEnabled(false);
@@ -1115,7 +1098,6 @@
 
 void PaintManagerDialog::loadDefaults(const QString &txt)
 {
-	QTreeWidgetItem *c = LoadColSet->currentItem();
 	if (m_doc == NULL)
 	{
 		m_colorList.clear();
@@ -1139,19 +1121,17 @@
 	}
 	else
 	{
-		if ( c->parent() != userSwatches)
+		if (!customColSet.contains(txt))
 			pfadC2 = csm.paletteFileFromName(txt);
 		else
-		{
-			QString Fname = txt;
-			Fname.replace(" ", "_");
-			Fname += ".xml";
-			pfadC2 = QDir::convertSeparators(ScPaths::getApplicationDataDir()+Fname);
-		}
+			pfadC2 = csm.userPaletteFileFromName(txt);
 		if (m_doc == 0)
 		{
 			QFileInfo fi(pfadC2);
-			paletteLocked = !fi.isWritable();
+			if (fi.absolutePath().contains(ScPaths::getApplicationDataDir()+"swatches/locked"))
+				paletteLocked = true;
+			else
+				paletteLocked = !fi.isWritable();
 		}
 		else
 			paletteLocked = false;
@@ -1159,10 +1139,7 @@
 	if (txt != "Scribus Small")
 	{
 		if (importColorsFromFile(pfadC2, m_colorList, &dialogGradients, (m_doc!=0)))
-		{
-			m_colorList.insert("White", ScColor(0, 0, 0, 0));
-			m_colorList.insert("Black", ScColor(0, 0, 0, 255));
-		}
+			m_colorList.ensureBlackAndWhite();
 		else
 		{
 			m_colorList.insert("White", ScColor(0, 0, 0, 0));
@@ -1187,11 +1164,10 @@
 {
 	QString Name = LoadColSet->text();
 	Query* dia = new Query(this, "Name", 1, 0, tr("&Name:"), tr("Choose a Name"));
-	if ((Name == "Scribus Basic") || (Name == "Scribus Small") || (Name == "X11 RGB-Set") || (Name == "OpenOffice.org-Set")
-	        || (Name == "X11 Grey-Set") || (Name == "Gnome-Set") || (Name == "SVG-Set") || paletteLocked)
+	if ((customColSet.contains(Name)) && (!paletteLocked))
+		dia->setEditText(Name, false);
+	else
 		dia->setEditText("", false);
-	else
-		dia->setEditText(Name, false);
 	if (dia->exec())
 		doSaveDefaults(dia->getEditText(), (dia->getEditText() != Name));
 	delete dia;
@@ -1202,7 +1178,7 @@
 	QString Cpfad = QDir::convertSeparators(ScPaths::getApplicationDataDir());
 	QString Fname = name;
 	Fname.replace(" ", "_");
-	Fname  = Cpfad + Fname;
+	Fname  = Cpfad + "swatches/"+ Fname;
 	Fname += ".xml";
 	QFile fx(Fname);
 	if (fx.open(QIODevice::WriteOnly))

Modified: trunk/Scribus/scribus/ui/swatchcombo.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15681&path=/trunk/Scribus/scribus/ui/swatchcombo.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/swatchcombo.cpp (original)
+++ trunk/Scribus/scribus/ui/swatchcombo.cpp Fri Oct 29 19:16:07 2010
@@ -44,7 +44,7 @@
 {
 	if (item)
 	{
-		if (item->flags() | Qt::ItemIsSelectable)
+		if (item->flags() & Qt::ItemIsSelectable)
 		{
 			menu()->hide();
 			setText(item->text(0));




More information about the scribus-commit mailing list