r15418 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:56:01 CEST 2010


Author: craig
Date: Sun Aug 15 21:56:01 2010
New Revision: 15418

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

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

Modified: branches/Version135/Scribus/scribus/newfile.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15418&path=/branches/Version135/Scribus/scribus/newfile.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/newfile.cpp (original)
+++ branches/Version135/Scribus/scribus/newfile.cpp Sun Aug 15 21:56:01 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: branches/Version135/Scribus/scribus/newfile.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15418&path=/branches/Version135/Scribus/scribus/newfile.h
==============================================================================
--- branches/Version135/Scribus/scribus/newfile.h (original)
+++ branches/Version135/Scribus/scribus/newfile.h Sun Aug 15 21:56:01 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: branches/Version135/Scribus/scribus/nftdialog.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15418&path=/branches/Version135/Scribus/scribus/nftdialog.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/nftdialog.cpp (original)
+++ branches/Version135/Scribus/scribus/nftdialog.cpp Sun Aug 15 21:56:01 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: branches/Version135/Scribus/scribus/nftdialog.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15418&path=/branches/Version135/Scribus/scribus/nftdialog.h
==============================================================================
--- branches/Version135/Scribus/scribus/nftdialog.h (original)
+++ branches/Version135/Scribus/scribus/nftdialog.h Sun Aug 15 21:56:01 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: branches/Version135/Scribus/scribus/nftrcreader.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15418&path=/branches/Version135/Scribus/scribus/nftrcreader.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/nftrcreader.cpp (original)
+++ branches/Version135/Scribus/scribus/nftrcreader.cpp Sun Aug 15 21:56:01 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: branches/Version135/Scribus/scribus/nftsettings.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15418&path=/branches/Version135/Scribus/scribus/nftsettings.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/nftsettings.cpp (original)
+++ branches/Version135/Scribus/scribus/nftsettings.cpp Sun Aug 15 21:56:01 2010
@@ -8,16 +8,14 @@
  *   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,9 +27,11 @@
 
 	addTemplates(scribusShare);
 	addTemplates(scribusUserHome+"/templates");
+	QString userTemplateDir(PrefsManager::instance()->appPrefs.documentTemplatesDir);
+	if (userTemplateDir.right(1) == "/")
+		userTemplateDir.chop(1);
 	if ((!userTemplateDir.isNull()) && (!userTemplateDir.isEmpty()))
-		addTemplates(userTemplateDir);
-}
+		addTemplates(userTemplateDir);}
 
 void nftsettings::addTemplates(QString dir) // dir will be searched for a sub folder called templates
 {
@@ -53,23 +53,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: branches/Version135/Scribus/scribus/nftsettings.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15418&path=/branches/Version135/Scribus/scribus/nftsettings.h
==============================================================================
--- branches/Version135/Scribus/scribus/nftsettings.h (original)
+++ branches/Version135/Scribus/scribus/nftsettings.h Sun Aug 15 21:56:01 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: branches/Version135/Scribus/scribus/nftwidget.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15418&path=/branches/Version135/Scribus/scribus/nftwidget.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/nftwidget.cpp (original)
+++ branches/Version135/Scribus/scribus/nftwidget.cpp Sun Aug 15 21:56:01 2010
@@ -7,14 +7,12 @@
 /***************************************************************************
  *   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 +22,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 +47,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 +107,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: branches/Version135/Scribus/scribus/nftwidget.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15418&path=/branches/Version135/Scribus/scribus/nftwidget.h
==============================================================================
--- branches/Version135/Scribus/scribus/nftwidget.h (original)
+++ branches/Version135/Scribus/scribus/nftwidget.h Sun Aug 15 21:56:01 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();

Modified: branches/Version135/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15418&path=/branches/Version135/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp (original)
+++ branches/Version135/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp Sun Aug 15 21:56:01 2010
@@ -117,16 +117,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);
 		}
 	}
 }
@@ -181,7 +178,10 @@
 	
 	addCategories(scribusHome + "/templates");
 	addCategories(scribusShare); 
-	
+	QString userTemplateDir(PrefsManager::instance()->appPrefs.documentTemplatesDir);
+	if ((!userTemplateDir.isNull()) && (!userTemplateDir.isEmpty()))
+		addCategories(userTemplateDir);
+
 	QStringList list;
 	QMap<QString, QString>::ConstIterator it;
 	for (it = cats.constBegin(); it != cats.constEnd(); ++it)

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




More information about the scribus-commit mailing list