r20193 by craig - Move to xml based iconset reading

scribus-commit scribus-commit at lists.scribus.net
Mon Jun 22 20:46:52 UTC 2015


Author: craig
Date: Mon Jun 22 20:46:52 2015
New Revision: 20193

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20193
Log:
Move to xml based iconset reading

Modified:
    trunk/Scribus/resources/iconsets/1_5_0/1_5_0.xml
    trunk/Scribus/resources/iconsets/1_5_1/1_5_1.xml
    trunk/Scribus/scribus/iconmanager.cpp
    trunk/Scribus/scribus/iconmanager.h
    trunk/Scribus/scribus/prefsstructs.h
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribus.h
    trunk/Scribus/scribus/scribuscore.cpp
    trunk/Scribus/scribus/ui/about.cpp
    trunk/Scribus/scribus/ui/prefs_userinterface.cpp

Modified: trunk/Scribus/resources/iconsets/1_5_0/1_5_0.xml
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20193&path=/trunk/Scribus/resources/iconsets/1_5_0/1_5_0.xml
==============================================================================
Binary files - no diff available.

Modified: trunk/Scribus/resources/iconsets/1_5_1/1_5_1.xml
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20193&path=/trunk/Scribus/resources/iconsets/1_5_1/1_5_1.xml
==============================================================================
Binary files - no diff available.

Modified: trunk/Scribus/scribus/iconmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20193&path=/trunk/Scribus/scribus/iconmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/iconmanager.cpp (original)
+++ trunk/Scribus/scribus/iconmanager.cpp Mon Jun 22 20:46:52 2015
@@ -50,17 +50,21 @@
 	_instance = 0;
 }
 
-void IconManager::setup()
+bool IconManager::setup()
 {
 	if (!initIcons())
+	{
 		qDebug()<<"No icons found :(";
+		return false;
+	}
+	return true;
 }
 
 
 bool IconManager::initIcons()
 {
 	readIconConfigFiles();
-	if (m_iconSets.isEmpty())
+	if (m_iconSets.isEmpty() || m_activeSetBasename.isEmpty())
 		return false;
 	return true;
 }
@@ -82,7 +86,7 @@
 		for (uint i = 0; i < id.count(); ++i)
 		{
 			QFileInfo file(*it + id[i]);
-			qDebug()<<file.absoluteFilePath();
+			//qDebug()<<file.absoluteFilePath();
 			QFile dataFile(file.absoluteFilePath());
 			if (!dataFile.exists())
 				continue;
@@ -112,35 +116,75 @@
 				QDomElement e = n.toElement();
 				if( !e.isNull() )
 				{
+					//qDebug()<<e.tagName()<<e.text();
 					if (e.tagName()=="path")
 					{
 						isd.path=e.text();
-						isd.baseName=e.text();
-						qDebug()<<e.tagName()<<e.text();
 					}
 					else
 					if (e.tagName()=="author")
 					{
 						isd.author=e.text();
-						qDebug()<<e.tagName()<<e.text();
 					}
 					else
 					if (e.tagName()=="license")
 					{
 						isd.license=e.text();
-						qDebug()<<e.tagName()<<e.text();
+					}
+					else
+					if (e.tagName()=="activeversion")
+					{
+						isd.activeversion=e.text();
 					}
 					else
 					if (e.tagName()=="nametext")
 					{
 						if (e.hasAttribute("lang"))
+						{
 							isd.nameTranslations.insert(e.attribute("lang"),e.text());
-						qDebug()<<e.tagName()<<e.text();
+							if (e.attribute("lang")=="en_US")
+								isd.baseName=e.text();
+						}
 					}
 				}
 				n = n.nextSibling();
 			}
-			m_iconSets.insert(isd.path, isd);
+			//just in case there's no en_US basename
+			if (!isd.baseName.isEmpty())
+			{
+
+				m_iconSets.insert(isd.baseName, isd);
+				if(!isd.activeversion.isEmpty())
+				{
+					int av_major, av_minor, av_patch, curr_major, curr_minor, curr_patch, ver_major, ver_minor, ver_patch;
+					av_major=isd.activeversion.section(".",0,0).toInt();
+					av_minor=isd.activeversion.section(".",1,1).toInt();
+					av_patch=isd.activeversion.section(".",2,2).toInt();
+					curr_major=m_activeSetVersion.section(".",0,0).toInt();
+					curr_minor=m_activeSetVersion.section(".",1,1).toInt();
+					curr_patch=m_activeSetVersion.section(".",2,2).toInt();
+					ver_major=QString(VERSION).section(".",0,0).toInt();
+					ver_minor=QString(VERSION).section(".",1,1).toInt();
+					ver_patch=QString(VERSION).section(".",2,2).toInt();
+					//If iconset version <= app version, and iconset version >= current active iconset version
+					if (av_major<=ver_major &&
+						av_minor<=ver_minor &&
+						av_patch<=ver_patch &&
+						(
+						av_major>=curr_major ||
+						(av_major==curr_major && av_minor>=curr_minor) ||
+						(av_major==curr_major && av_minor==curr_minor && av_patch>=curr_patch)
+						)
+						)
+					{
+						m_backupSetBasename=m_activeSetBasename;
+						m_backupSetVersion=m_backupSetVersion;
+						m_activeSetBasename=isd.baseName;
+						m_activeSetVersion=isd.activeversion;
+						//qDebug()<<"backupSetBasename"<<m_backupSetBasename<<"activeSetBasename"<<m_activeSetBasename;
+					}
+				}
+			}
 		}
 	}
 }
@@ -157,8 +201,8 @@
 
 QPixmap IconManager::loadPixmap(const QString nam, bool forceUseColor)
 {
-	if (pxCache.contains(nam))
-		return *pxCache[nam];
+	if (m_pxCache.contains(nam))
+		return *m_pxCache[nam];
 
 	QString iconFilePath(pathForIcon(nam));
 	QPixmap *pm = new QPixmap();
@@ -169,7 +213,7 @@
 //		qDebug()<<"Successful icon load from"<<iconFilePath;
 	if (PrefsManager::instance()->appPrefs.uiPrefs.grayscaleIcons && !forceUseColor)
 		iconToGrayscale(pm);
-	pxCache.insert(nam, pm);
+	m_pxCache.insert(nam, pm);
 	return *pm;
 }
 
@@ -191,15 +235,39 @@
 	*pm=QPixmap::fromImage(qi);
 }
 
+bool IconManager::setActiveFromPrefs(QString prefsSet)
+{
+	//qDebug()<<"setting active from prefs to"<<prefsSet;
+	if (m_iconSets.contains(prefsSet))
+	{
+		m_activeSetBasename=m_iconSets[prefsSet].baseName;
+		m_activeSetVersion=m_iconSets[prefsSet].activeversion;
+		return true;
+	}
+	return false;
+}
+
+QString IconManager::baseNameForTranslation(QString transName)
+{
+	QString name;
+	foreach (ScIconSetData value, m_iconSets)
+	{
+		QMapIterator<QString, QString> nameValue(value.nameTranslations);
+		while (nameValue.hasNext())
+		{
+			nameValue.next();
+			if (nameValue.value()==transName)
+				return value.nameTranslations["en_US"];
+		}
+	}
+	return name;
+}
+
 QString IconManager::pathForIcon(const QString nam)
 {
 	QString iconset(PrefsManager::instance()->appPrefs.uiPrefs.iconSet);
-	QString iconSubdir("1_5_0/");
-	QString primaryIconSubdir("1_5_0/");
-	//temporary until second icon dir is there
-	if (iconset=="Dezso" || iconset=="1_5_1")
-		iconSubdir="1_5_1/";
-
+	QString iconSubdir(m_iconSets[m_activeSetBasename].path+"/");
+	QString primaryIconSubdir(m_iconSets[m_backupSetBasename].path+"/");
 
 	QString iconFilePath(QString("%1%2%3").arg(ScPaths::instance().iconDir()).arg(iconSubdir).arg(nam));
 	if (QFile::exists(iconFilePath))
@@ -209,12 +277,40 @@
 	iconFilePath=QString("%1%2%3").arg(ScPaths::instance().iconDir()).arg(primaryIconSubdir).arg(nam);
 
 	if (QFile::exists(iconFilePath))
+	{
+		//qDebug()<<iconFilePath;
 		return iconFilePath;
+	}
 
 	qWarning("pathForIcon: Unable to load icon %s: File not found", iconFilePath.toLatin1().constData());
 	return "";
 }
 
+QStringList IconManager::pathList()
+{
+	QStringList paths;
+	foreach (ScIconSetData value, m_iconSets)
+		paths << value.path;
+	return paths;
+}
+
+QStringList IconManager::nameList(QString language)
+{
+	QStringList names;
+	foreach (ScIconSetData value, m_iconSets)
+	{
+		if (value.nameTranslations.contains(language))
+			names << value.nameTranslations.value(language);
+		else if (value.nameTranslations.contains("en_US"))
+			names << value.nameTranslations.value("en_US");
+		else if (value.nameTranslations.contains("en"))
+			names << value.nameTranslations.value("en");
+		else
+			names << value.path;
+	}
+	return names;
+}
+
 void IconManager::languageChange()
 {
 

Modified: trunk/Scribus/scribus/iconmanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20193&path=/trunk/Scribus/scribus/iconmanager.h
==============================================================================
--- trunk/Scribus/scribus/iconmanager.h (original)
+++ trunk/Scribus/scribus/iconmanager.h Mon Jun 22 20:46:52 2015
@@ -48,12 +48,17 @@
 	* Must be called when IconManager is no longer needed.
 	*/
 	static void deleteInstance();
-	void setup();
+	bool setup();
 	QCursor loadCursor(const QString nam, bool forceUseColor=false);
 	QIcon loadIcon(const QString nam, bool forceUseColor=false);
 	QPixmap loadPixmap(const QString nam, bool forceUseColor=false);
 	QString pathForIcon(const QString nam);
+	QStringList pathList();
+	QStringList nameList(QString language);
 	void iconToGrayscale(QPixmap *pm);
+	bool setActiveFromPrefs(QString prefsSet);
+	QString activeSetBasename() { return m_activeSetBasename; }
+	QString baseNameForTranslation(QString transName);
 
 public slots:
 	void languageChange();
@@ -67,7 +72,11 @@
 	*/
 	static IconManager* _instance;
 	QMap<QString, ScIconSetData> m_iconSets;
-	ScPixmapCache<QString> pxCache;
+	ScPixmapCache<QString> m_pxCache;
+	QString m_activeSetBasename;
+	QString m_activeSetVersion;
+	QString m_backupSetBasename;
+	QString m_backupSetVersion;
 
 	bool initIcons();
 	void readIconConfigFiles();

Modified: trunk/Scribus/scribus/prefsstructs.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20193&path=/trunk/Scribus/scribus/prefsstructs.h
==============================================================================
--- trunk/Scribus/scribus/prefsstructs.h (original)
+++ trunk/Scribus/scribus/prefsstructs.h Mon Jun 22 20:46:52 2015
@@ -503,6 +503,7 @@
 	QString baseName;
 	QString license;
 	QString author;
+	QString activeversion;
 	QMap<QString, QString> nameTranslations;
 };
 

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20193&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Mon Jun 22 20:46:52 2015
@@ -303,7 +303,7 @@
 #ifdef Q_OS_MAC
 	//commenting this out until this is resolved :https://bugreports.qt.io/browse/QTBUG-44565
 	//ScQApp->setAttribute(Qt::AA_DontShowIconsInMenus);
-	noIcon = IconManager::instance()->loadPixmap("noicon.xpm");
+	//noIcon = IconManager::instance()->loadPixmap("noicon.xpm");
 #endif
 }
 

Modified: trunk/Scribus/scribus/scribus.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20193&path=/trunk/Scribus/scribus/scribus.h
==============================================================================
--- trunk/Scribus/scribus/scribus.h (original)
+++ trunk/Scribus/scribus/scribus.h Mon Jun 22 20:46:52 2015
@@ -612,7 +612,7 @@
 
 	QLabel* mainWindowStatusLabel;
 	QString statusLabelText;
-	QPixmap noIcon;
+	//QPixmap noIcon;
 
 	int toolbarMenuTools;
 	int toolbarMenuPDFTools;

Modified: trunk/Scribus/scribus/scribuscore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20193&path=/trunk/Scribus/scribus/scribuscore.cpp
==============================================================================
--- trunk/Scribus/scribus/scribuscore.cpp (original)
+++ trunk/Scribus/scribus/scribuscore.cpp Mon Jun 22 20:46:52 2015
@@ -102,11 +102,11 @@
 	ScMWList.append(scribus);
 	m_currScMW=0;
 	int retVal=initScribusCore(showSplash, showFontInfo, showProfileInfo,newGuiLanguage, prefsUserFile);
-	if (retVal == 1)
+	if (retVal == EXIT_FAILURE)
 		return(EXIT_FAILURE);
 	
 	retVal = scribus->initScMW(true);
-	if (retVal == 1)
+	if (retVal == EXIT_FAILURE)
 		return(EXIT_FAILURE);
 	
 	closeSplash();
@@ -143,7 +143,8 @@
 {
 	CommonStrings::languageChange();
 	iconManager = IconManager::instance();
-	iconManager->setup();
+	if (!iconManager->setup())
+		return EXIT_FAILURE;
 
 	// FIXME: Splash needs the prefs loaded by initDefaults() to know if it must force the image to grayscale
 	initSplash(showSplash);
@@ -154,7 +155,7 @@
 	bool haveFonts=false;
 	haveFonts=ScCore->initFonts(showFontInfo);
 	if (!haveFonts)
-		return 1;
+		return EXIT_FAILURE;
 	prefsManager->initDefaults();
 	prefsManager->initDefaultGUIFont(qApp->font());
 	prefsManager->initArrowStyles();
@@ -170,7 +171,12 @@
 	else
 		prefsManager->ReadPrefs(prefsUserFile);
 	prefsManager->appPrefs.uiPrefs.showSplashOnStartup=showSplash;
-		
+	if (!iconManager->setActiveFromPrefs(prefsManager->appPrefs.uiPrefs.iconSet))
+	{
+		//reset prefs name to chosen name based on version, when prefs is empty or not found
+		prefsManager->appPrefs.uiPrefs.iconSet=iconManager->activeSetBasename();
+	}
+
 	m_HaveGS = testGSAvailability();
 	m_HavePngAlpha = testGSDeviceAvailability("pngalpha");
 	m_HaveTiffSep = testGSDeviceAvailability("tiffsep");

Modified: trunk/Scribus/scribus/ui/about.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20193&path=/trunk/Scribus/scribus/ui/about.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/about.cpp (original)
+++ trunk/Scribus/scribus/ui/about.cpp Mon Jun 22 20:46:52 2015
@@ -115,8 +115,8 @@
 	buildID = new QLabel( tab );
 	buildID->setAlignment(Qt::AlignCenter);
 	buildID->setTextInteractionFlags(Qt::TextSelectableByMouse);
-	QString BUILD_DAY = "25";
-	QString BUILD_MONTH = CommonStrings::may;
+	QString BUILD_DAY = "22";
+	QString BUILD_MONTH = CommonStrings::june;
 	QString BUILD_YEAR = "2015";
 	QString BUILD_TIME = "";
 	QString BUILD_TZ = "";

Modified: trunk/Scribus/scribus/ui/prefs_userinterface.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20193&path=/trunk/Scribus/scribus/ui/prefs_userinterface.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_userinterface.cpp (original)
+++ trunk/Scribus/scribus/ui/prefs_userinterface.cpp Mon Jun 22 20:46:52 2015
@@ -10,12 +10,15 @@
 #include <QPixmap>
 #include <QStyleFactory>
 
+#include "iconmanager.h"
 #include "langmgr.h"
 #include "prefs_userinterface.h"
 #include "prefsstructs.h"
+#include "scribusapp.h"
 #include "scribusdoc.h"
 #include "util.h"
 
+extern ScribusQApp *ScQApp;
 
 Prefs_UserInterface::Prefs_UserInterface(QWidget* parent, ScribusDoc* doc)
 	: Prefs_Pane(parent)
@@ -32,7 +35,7 @@
 	themeComboBox->addItem("");
 	themeComboBox->addItems(styleList);
 	QStringList iconSetList;
-	iconSetList<<"1_5_0"<<"1_5_1";
+	iconSetList=IconManager::instance()->nameList(ScQApp->currGUILanguage());
 	iconSetComboBox->addItems(iconSetList);
 
 	connect(languageComboBox, SIGNAL(activated(const QString &)), this, SLOT(setSelectedGUILang(const QString &)));
@@ -88,7 +91,7 @@
 {
 	prefsData->uiPrefs.language=selectedGUILang;
 	prefsData->uiPrefs.style=themeComboBox->currentText();
-	prefsData->uiPrefs.iconSet=iconSetComboBox->currentText();
+	prefsData->uiPrefs.iconSet=IconManager::instance()->baseNameForTranslation(iconSetComboBox->currentText());
 	prefsData->uiPrefs.applicationFontSize=fontSizeMenuSpinBox->value();
 	prefsData->uiPrefs.paletteFontSize=fontSizePaletteSpinBox->value();
 	prefsData->uiPrefs.wheelJump=wheelJumpSpinBox->value();




More information about the scribus-commit mailing list