r15417 by craig - #9255: When adding template categories via new template definitions, add them correctly to new from and save as template dialogs

scribus-commit scribus-commit at lists.scribus.net
Sun Aug 15 23:55:59 CEST 2010


Author: craig
Date: Sun Aug 15 21:55:59 2010
New Revision: 15417

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15417
Log:
#9255: When adding template categories via new template definitions, add them correctly to new from and save as template dialogs

Modified:
    trunk/Scribus/scribus/nftrcreader.cpp
    trunk/Scribus/scribus/nftsettings.cpp
    trunk/Scribus/scribus/nftsettings.h
    trunk/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/ui/newfile.cpp
    trunk/Scribus/scribus/ui/newfile.h
    trunk/Scribus/scribus/ui/nftdialog.cpp
    trunk/Scribus/scribus/ui/nftdialog.h
    trunk/Scribus/scribus/ui/nftwidget.cpp
    trunk/Scribus/scribus/ui/nftwidget.h

Modified: trunk/Scribus/scribus/nftrcreader.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/nftrcreader.cpp
==============================================================================
--- trunk/Scribus/scribus/nftrcreader.cpp (original)
+++ trunk/Scribus/scribus/nftrcreader.cpp Sun Aug 15 21:55:59 2010
@@ -7,6 +7,7 @@
 /***************************************************************************
  *   Riku Leino, tsoots at gmail.com                                          *
  ***************************************************************************/
+
 #include "nftrcreader.h"
 
 using namespace std;
@@ -65,7 +66,8 @@
 		inEmail = true;
 
 
-	if (name == "template") { // new template starts here
+	if (name == "template") // new template starts here
+	{
 		inTemplate = true;
 		QString category;
 		QString enCat;
@@ -187,6 +189,8 @@
 QString nftrcreader::getCategory(QString cat) 
 {
 	QMap<QString, QString>::iterator it = cats.find(cat);
+	if (it==cats.end())
+		cats.insert(cat, cat);
 	if (it != cats.end())
 		return it.value();
 	return cat;

Modified: trunk/Scribus/scribus/nftsettings.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/nftsettings.cpp
==============================================================================
--- trunk/Scribus/scribus/nftsettings.cpp (original)
+++ trunk/Scribus/scribus/nftsettings.cpp Sun Aug 15 21:55:59 2010
@@ -7,17 +7,17 @@
 /***************************************************************************
  *   Riku Leino, tsoots at gmail.com                                          *
  ***************************************************************************/
+
 #include "nftsettings.h"
+#include "prefsmanager.h"
 #include "scpaths.h"
 
-nftsettings::nftsettings(QString guilang, QString templateDir)
+nftsettings::nftsettings(QString guilang)
 {
 	lang = guilang;
 	scribusShare = ScPaths::instance().templateDir();
 	scribusUserHome = QDir::convertSeparators(ScPaths::getApplicationDataDir());
-	userTemplateDir = templateDir;
-	if (userTemplateDir.right(1) == "/")
-		userTemplateDir = userTemplateDir.left(userTemplateDir.length() - 1);
+
 	read();
 }
 
@@ -29,6 +29,9 @@
 
 	addTemplates(scribusShare);
 	addTemplates(scribusUserHome+"/templates");
+	QString userTemplateDir(PrefsManager::instance()->appPrefs.pathPrefs.documentTemplates);
+	if (userTemplateDir.right(1) == "/")
+		userTemplateDir.chop(1);
 	if ((!userTemplateDir.isNull()) && (!userTemplateDir.isEmpty()))
 		addTemplates(userTemplateDir);
 }
@@ -53,23 +56,21 @@
 	QDir tmpldir(dir);
 	if (tmpldir.exists())
 	{
-		tmpldir.setFilter(QDir::Dirs);
+		tmpldir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
 		QStringList dirs = tmpldir.entryList();
 		for (int i = 0; i < dirs.size(); ++i)
 		{
-			if ((dirs[i] != ".") && (dirs[i] != "..")) {
-				tmplFile = findTemplateXml(dir + "/" + dirs[i]);
-				QFile* tmplxml = new QFile(QDir::convertSeparators(tmplFile));
-				handler->setSourceDir(dir+"/"+dirs[i]);
-				handler->setSourceFile(tmplFile);
-				if (tmplxml->exists())
-				{
-					QXmlInputSource* source = new QXmlInputSource(tmplxml);
-					reader->parse(source);
-					delete source;
-				}
-				delete tmplxml;
+			tmplFile = findTemplateXml(dir + "/" + dirs[i]);
+			QFile* tmplxml = new QFile(QDir::convertSeparators(tmplFile));
+			handler->setSourceDir(dir+"/"+dirs[i]);
+			handler->setSourceFile(tmplFile);
+			if (tmplxml->exists())
+			{
+				QXmlInputSource* source = new QXmlInputSource(tmplxml);
+				reader->parse(source);
+				delete source;
 			}
+			delete tmplxml;
 		}
 	}
 }

Modified: trunk/Scribus/scribus/nftsettings.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/nftsettings.h
==============================================================================
--- trunk/Scribus/scribus/nftsettings.h (original)
+++ trunk/Scribus/scribus/nftsettings.h Sun Aug 15 21:55:59 2010
@@ -22,7 +22,6 @@
 private:
 	QString scribusShare;
 	QString scribusUserHome;
-	QString userTemplateDir;
 	QString nftHomeDir;
 	QString lang;
 	nftrcreader* handler;
@@ -32,7 +31,7 @@
 	QString findTemplateXml(QString dir);
 public:
 	std::vector<nfttemplate*> templates;
-	nftsettings(QString guilang, QString templateDir);
+	nftsettings(QString guilang);
 	~nftsettings();
 };
 

Modified: trunk/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp (original)
+++ trunk/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp Sun Aug 15 21:55:59 2010
@@ -118,16 +118,13 @@
 	QDir tmpldir(dir);
 	if (tmpldir.exists())
 	{
-		tmpldir.setFilter(QDir::Dirs);
+		tmpldir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
 		QStringList dirs = tmpldir.entryList();
 		for (int i = 0; i < dirs.size(); ++i)
 		{
-			if ((dirs[i] != ".") && (dirs[i] != "..")) 
-			{
-				tmplFile = findTemplateXml(dir + "/" + dirs[i]);
-				if (QFile::exists(tmplFile))
-					readCategories(tmplFile);
-			}
+			tmplFile = findTemplateXml(dir + "/" + dirs[i]);
+			if (QFile::exists(tmplFile))
+				readCategories(tmplFile);
 		}
 	}
 }
@@ -182,7 +179,10 @@
 	
 	addCategories(scribusHome + "/templates");
 	addCategories(scribusShare); 
-	
+	QString userTemplateDir(PrefsManager::instance()->appPrefs.pathPrefs.documentTemplates);
+	if ((!userTemplateDir.isNull()) && (!userTemplateDir.isEmpty()))
+		addCategories(userTemplateDir);
+
 	QStringList list;
 	QMap<QString, QString>::ConstIterator it;
 	for (it = cats.constBegin(); it != cats.constEnd(); ++it)

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Sun Aug 15 21:55:59 2010
@@ -1630,7 +1630,7 @@
 {
 	bool docSet = false;
 	PrefsContext* docContext = prefsManager->prefsFile->getContext("docdirs", false);
-	NewDoc* dia = new NewDoc(this, RecentDocs, true, ScCore->getGuiLanguage(), PrefsManager::instance()->appPrefs.pathPrefs.documentTemplates);
+	NewDoc* dia = new NewDoc(this, RecentDocs, true, ScCore->getGuiLanguage());
 	if (dia->exec())
 	{
 		if (dia->tabSelected() == NewDoc::NewDocumentTab)
@@ -1949,7 +1949,7 @@
 
 void ScribusMainWindow::newFileFromTemplate()
 {
-	nftdialog* nftdia = new nftdialog(this, ScCore->getGuiLanguage(), PrefsManager::instance()->appPrefs.pathPrefs.documentTemplates);
+	nftdialog* nftdia = new nftdialog(this, ScCore->getGuiLanguage());
 	if (nftdia->exec())
 	{
 		if (nftdia->nftGui->currentDocumentTemplate)

Modified: trunk/Scribus/scribus/ui/newfile.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/ui/newfile.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/newfile.cpp (original)
+++ trunk/Scribus/scribus/ui/newfile.cpp Sun Aug 15 21:55:59 2010
@@ -87,7 +87,7 @@
 	return QSize(maxX, maxY);
 }
 
-NewDoc::NewDoc( QWidget* parent, const QStringList& recentDocs, bool startUp, QString lang, QString templateDir ) : QDialog( parent )
+NewDoc::NewDoc( QWidget* parent, const QStringList& recentDocs, bool startUp, QString lang) : QDialog( parent )
 {
 	setObjectName(QString::fromLocal8Bit("NewDocumentWindow"));
 	setModal(true);
@@ -110,7 +110,7 @@
 	{
 		tabWidget->addTab(newDocFrame, tr("&New Document"));
 		createNewFromTempPage();
-		nftGui->setupSettings(lang, templateDir);
+		nftGui->setupSettings(lang);
 		tabWidget->addTab(newFromTempFrame, tr("New &from Template"));
 		createOpenDocPage();
 		tabWidget->addTab(openDocFrame, tr("Open &Existing Document"));

Modified: trunk/Scribus/scribus/ui/newfile.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/ui/newfile.h
==============================================================================
--- trunk/Scribus/scribus/ui/newfile.h (original)
+++ trunk/Scribus/scribus/ui/newfile.h Sun Aug 15 21:55:59 2010
@@ -65,7 +65,7 @@
 		OpenRecentTab
 	} ActionSelected;
 
-	NewDoc( QWidget* parent, const QStringList& recentDocs, bool startUp = false, QString lang = "", QString templateDir = "" );
+	NewDoc( QWidget* parent, const QStringList& recentDocs, bool startUp = false, QString lang = "");
 	~NewDoc() {};
 	void createNewDocPage();
 	void createNewFromTempPage();

Modified: trunk/Scribus/scribus/ui/nftdialog.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/ui/nftdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/nftdialog.cpp (original)
+++ trunk/Scribus/scribus/ui/nftdialog.cpp Sun Aug 15 21:55:59 2010
@@ -15,12 +15,12 @@
 #include "util_icon.h"
 
 
-nftdialog::nftdialog(QWidget* parent, QString lang, QString templateDir) : QDialog(parent)
+nftdialog::nftdialog(QWidget* parent, QString lang) : QDialog(parent)
 {
 	setupUi(this);
 	setModal(true);
 	setWindowIcon(loadIcon("AppIcon.png"));
-	nftGui->setupSettings(lang, templateDir);
+	nftGui->setupSettings(lang);
 	connect(nftGui, SIGNAL(leaveOK()), this, SLOT(accept()));
 	connect(nftGui, SIGNAL(ButtonBoxEnable(bool)), this, SLOT(enableButtonBox(bool)));
 }

Modified: trunk/Scribus/scribus/ui/nftdialog.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/ui/nftdialog.h
==============================================================================
--- trunk/Scribus/scribus/ui/nftdialog.h (original)
+++ trunk/Scribus/scribus/ui/nftdialog.h Sun Aug 15 21:55:59 2010
@@ -21,7 +21,7 @@
 {
 	Q_OBJECT
 public:
-	nftdialog(QWidget* parent, QString lang, QString templateDir);
+	nftdialog(QWidget* parent, QString lang);
 	~nftdialog() {};
 public slots:
 	void enableButtonBox(bool);

Modified: trunk/Scribus/scribus/ui/nftwidget.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/ui/nftwidget.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/nftwidget.cpp (original)
+++ trunk/Scribus/scribus/ui/nftwidget.cpp Sun Aug 15 21:55:59 2010
@@ -7,14 +7,13 @@
 /***************************************************************************
  *   Riku Leino, tsoots at gmail.com                                          *
  ***************************************************************************/
+
+#include <QAction>
+#include <QPainter>
+
 #include "nftwidget.h"
-
 #include "scconfig.h"
 #include "scribusapi.h"
-
-#include <QAction>
-#include <QPainter>
-
 #include "util_icon.h"
 
 
@@ -24,9 +23,9 @@
 	currentDocumentTemplate = NULL;
 }
 
-void nftwidget::setupSettings(QString lang, QString templateDir)
-{
-	settings = new nftsettings(lang, templateDir);
+void nftwidget::setupSettings(QString lang)
+{
+	settings = new nftsettings(lang);
 	// context menu
 	removeAction = new QAction(tr("&Remove"), tnailGrid);
 	openAction = new QAction(tr("&Open"), tnailGrid);
@@ -49,16 +48,16 @@
 
 void nftwidget::setupCategories() 
 {
-	QString categories("");
+	QStringList categories;
 	categoryList->clear();
 	categoryList->addItem(tr("All"));
 	for (uint i = 0; i < settings->templates.size(); i++)
 	{
-		if ((categories.indexOf(settings->templates[i]->templateCategory) == -1) &&
+		if ((!categories.contains(settings->templates[i]->templateCategory)) &&
 		    (!settings->templates[i]->isDeleted))
 		{
 			categoryList->addItem(settings->templates[i]->templateCategory);
-			categories += settings->templates[i]->templateCategory;
+			categories << settings->templates[i]->templateCategory;
 		}
 	}
 	categoryList->sortItems();
@@ -109,7 +108,7 @@
 		tnailGrid->clear();
 		for (uint i = 0; i < iconItems.size(); ++i)
 		{
-			if (curtype.indexOf(iconItems[i]->first->templateCategory) != -1)
+			if (curtype==iconItems[i]->first->templateCategory)
 			{
 				QPixmap pm(iconItems[i]->first->tnail);
 				if (pm.width() > 60)

Modified: trunk/Scribus/scribus/ui/nftwidget.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15417&path=/trunk/Scribus/scribus/ui/nftwidget.h
==============================================================================
--- trunk/Scribus/scribus/ui/nftwidget.h (original)
+++ trunk/Scribus/scribus/ui/nftwidget.h Sun Aug 15 21:55:59 2010
@@ -38,7 +38,7 @@
 public:
 	nfttemplate* currentDocumentTemplate;
 	nftwidget(QWidget* parent);
-	void setupSettings(QString lang, QString templateDir);
+	void setupSettings(QString lang);
 	~nftwidget();
 private slots: 
 	void setTNails();




More information about the scribus-commit mailing list