r20038 by jghali - rework a bit shortwords plugin code

scribus-commit scribus-commit at lists.scribus.net
Thu Apr 30 04:07:50 UTC 2015


Author: jghali
Date: Thu Apr 30 04:07:50 2015
New Revision: 20038

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20038
Log:
rework a bit shortwords plugin code

Modified:
    trunk/Scribus/scribus/plugins/short-words/configuration.cpp
    trunk/Scribus/scribus/plugins/short-words/configuration.h
    trunk/Scribus/scribus/plugins/short-words/parse.cpp
    trunk/Scribus/scribus/plugins/short-words/swdialog.cpp

Modified: trunk/Scribus/scribus/plugins/short-words/configuration.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20038&path=/trunk/Scribus/scribus/plugins/short-words/configuration.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/short-words/configuration.cpp (original)
+++ trunk/Scribus/scribus/plugins/short-words/configuration.cpp Thu Apr 30 04:07:50 2015
@@ -39,7 +39,7 @@
 	//userConfig = prefs->getUInt("userConfig", 0);
 	//editor = prefs->get("editor", "");
 	useStyle = prefs->getBool("useStyle", true);
-	currentLanguage = prefs->getInt("currentLanguage", 0);
+	currentLanguage = prefs->get("currentLanguage", "en");
 }
 
 void SWConfig::saveConfig()
@@ -100,36 +100,28 @@
 	return allShorts + getShortWordsFromFile(lang, RC_PATH);*/
 }
 
-QStringList SWConfig::getAvailableLanguagesFromFile(QString filename)
+QStringList SWConfig::getAvailableLanguageCodes(QString filename)
 {
-	QStringList langs;
 	QStringList nations;
-	QString aRow;
+	QString aRow, code, lang;
 
 	QFile f(filename);
-	if (f.open(QIODevice::ReadOnly))
+	if (!f.open(QIODevice::ReadOnly))
+		return QStringList();
+
+	QTextStream t(&f);
+	while (!t.atEnd())
 	{
-		QTextStream t(&f);
-		while (!t.atEnd())
+		aRow = t.readLine();
+		code = aRow.left(2);
+		if (aRow.left(1) != "#" && aRow.length() != 0 && aRow.left(1) != " " && !nations.contains(code))
 		{
-			aRow = t.readLine();
-			if (aRow.left(1) != "#" && aRow.length() != 0 && aRow.left(1) != " " && !langs.contains(aRow.left(2)))
-			{
-				nations.append(getLangFromCode(aRow.left(2)));
-				langs.append(aRow.left(2));
-			}
+			nations.append(code);
 		}
-		f.close();
 	}
-	else
-	{
-		return QStringList();
-	}
-// 	if (filename == RC_PATH_USR)
-// 		return QObject::tr("Custom (optional) configuration: ", "short words plugin") + " " + nations.join(", ");
-// 	if (filename == RC_PATH)
-// 		return QObject::tr("Standard configuration: ", "short words plugin") + " " + nations.join(", ");
-	return nations; //.join(", "); // save return only
+	f.close();
+
+	return nations;
 }
 
 QStringList SWConfig::getAvailableLanguagesList()
@@ -137,36 +129,38 @@
 	QStringList allConfig;
 	
 	if (QFile::exists(RC_PATH_USR))
-		allConfig << getAvailableLanguagesFromFile(RC_PATH_USR);
+		allConfig = getAvailableLanguageCodes(RC_PATH_USR);
 	else
-		allConfig << getAvailableLanguagesFromFile(RC_PATH);
+		allConfig = getAvailableLanguageCodes(RC_PATH);
 	return allConfig;
 }
 
 QString SWConfig::getAvailableLanguages()
 {
-	QStringList allConfig;
+	QStringList allCodes, allConfig;
+	allCodes = getAvailableLanguageCodes(RC_PATH);
 	allConfig << QObject::tr("Standard configuration: ", "short words plugin") << "<p>";
-	allConfig << getAvailableLanguagesFromFile(RC_PATH).join(", ");
+	allConfig << getLanguageStringsFromCodes(allCodes).join(", ");
 	if (QFile::exists(RC_PATH_USR))
 	{
+		allCodes = getAvailableLanguageCodes(RC_PATH_USR);
 		allConfig << "<p>" << QObject::tr("Custom (optional) configuration: ", "short words plugin") << "<p>";
-		allConfig << getAvailableLanguagesFromFile(RC_PATH_USR).join(", ");
+		allConfig << getLanguageStringsFromCodes(allCodes).join(", ");
 	}
-	return  allConfig.join("");
+	return allConfig.join("");
 }
 
-QString SWConfig::getLangCodeFromHyph(QString hyphenCode)
+QStringList SWConfig::getLanguageStringsFromCodes(QStringList codes)
 {
-	hyphenCode.remove(0, 5);
-	return hyphenCode.remove(2, 10);
-}
+	QStringList languages;
 
-QString SWConfig::getLangFromCode(QString code)
-{
-	QMap<QString,QString>::Iterator it;
-	QString lang;
-// 	LanguageManager langmgr;
-// 	langmgr.init(false);
-	return LanguageManager::instance()->getLangFromAbbrev(code, true);
-}
+	for (int i = 0; i < codes.count(); ++i)
+	{
+		QString code = codes.at(i);
+		QString lang = LanguageManager::instance()->getLangFromAbbrev(code, true);
+		if (lang.length() > 0)
+			languages.append(lang);
+	}
+
+	return languages;
+}

Modified: trunk/Scribus/scribus/plugins/short-words/configuration.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20038&path=/trunk/Scribus/scribus/plugins/short-words/configuration.h
==============================================================================
--- trunk/Scribus/scribus/plugins/short-words/configuration.h (original)
+++ trunk/Scribus/scribus/plugins/short-words/configuration.h Thu Apr 30 04:07:50 2015
@@ -35,9 +35,8 @@
 	/*! \brief Id of the UI radiobutton  */
 	uint action;
 	//*! \brief UI checkbox */
-	//uint userConfig;
 	bool useStyle;
-	int currentLanguage;
+	QString currentLanguage;
 
 	/*! \brief Returns all options for specified language.
 	\param lang language of the ext frame */
@@ -46,10 +45,7 @@
 	\retval QString with languages in the configuration. */
 	static QString getAvailableLanguages();
 	static QStringList getAvailableLanguagesList();
-	/*! \brief get lang code (en, cs, pl) from Scribus hyphenator configuration structure.
-	\param hyphenCode code of the language.
-	\retval QString full named language. */
-	static QString getLangCodeFromHyph(QString hyphenCode);
+
 	/*! \brief Save cfg. */
 	void saveConfig();
 
@@ -63,12 +59,11 @@
 	QStringList getShortWordsFromFile(QString lang, QString filename);
 	/*! \brief getAvailableLanguages use this one. available config in the specified file for UI about
 	\param filename config file
-	\retval QString all supported languages in one string */
-	static QStringList getAvailableLanguagesFromFile(QString filename);
-	/*! \brief returns full lang name by lang code (en -> English)
-	\param code language code
-	\retval QString full named language */
-	static QString getLangFromCode(QString code);
+	\retval QStringList all supported language codes */
+	static QStringList getAvailableLanguageCodes(QString filename);
+	/*! \brief Retrieve translated language strings from language codes
+	\retval QStringList with languages. */
+	static QStringList getLanguageStringsFromCodes(QStringList codes);
 };
 
 #endif

Modified: trunk/Scribus/scribus/plugins/short-words/parse.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20038&path=/trunk/Scribus/scribus/plugins/short-words/parse.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/short-words/parse.cpp (original)
+++ trunk/Scribus/scribus/plugins/short-words/parse.cpp Thu Apr 30 04:07:50 2015
@@ -63,11 +63,7 @@
 		if (lang.isNull() || lang.isEmpty())
 			qDebug("SWParse::parseItem - variable lang is still empty. No changes are made.");
 	}
-/* IL
-	QString langCode;
-// 	if (aFrame->doc()->scMW()->Sprachen.contains(lang))
-		langCode = cfg->getLangCodeFromHyph(LanguageManager::instance()->getHyphFilename(lang,false));
-*/
+
 	// apply spaces after shorts
 	shorts = cfg->getShortWords(lang);
 	if (shorts.count()==0)
@@ -134,7 +130,7 @@
 	doc->scMW()->mainWindowProgressBar->setMaximum(docSelectionCount);
 	for (uint i=0; i < docSelectionCount; ++i)
 	{
-	doc->scMW()->mainWindowProgressBar->setValue(i);
+		doc->scMW()->mainWindowProgressBar->setValue(i);
 		parseItem(doc->m_Selection->itemAt(i));
 	} // for items
 	doc->scMW()->mainWindowProgressBar->setValue(docSelectionCount);

Modified: trunk/Scribus/scribus/plugins/short-words/swdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20038&path=/trunk/Scribus/scribus/plugins/short-words/swdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/short-words/swdialog.cpp (original)
+++ trunk/Scribus/scribus/plugins/short-words/swdialog.cpp Thu Apr 30 04:07:50 2015
@@ -42,7 +42,13 @@
 
 	cfg = new SWConfig();
 
-	languageComboBox->addItems(cfg->getAvailableLanguagesList());
+	QStringList langCodes = cfg->getAvailableLanguagesList();
+	for (int i = 0; i< langCodes.count(); ++i)
+	{
+		QString code = langCodes.at(i);
+		QString lang = LanguageManager::instance()->getLangFromAbbrev(code, true);
+		languageComboBox->addItem(lang, code);
+	}
 
 	languageChange();
 	resize(minimumSizeHint());
@@ -57,7 +63,10 @@
 
 	selectAction(cfg->action);
 	styleCheckBox->setChecked(cfg->useStyle);
-	languageComboBox->setCurrentIndex(cfg->currentLanguage);
+
+	int langIndex = languageComboBox->findData(cfg->currentLanguage);
+	if (langIndex >= 0)
+		languageComboBox->setCurrentIndex(langIndex);
 }
 
 /*
@@ -85,14 +94,15 @@
 
 QString SWDialog::lang()
 {
-	return LanguageManager::instance()->getAbbrevFromLang(languageComboBox->currentText(), true);
+	QVariant langCode = languageComboBox->currentData(Qt::UserRole);
+	return langCode.toString();
 }
 
 void SWDialog::savePrefs()
 {
 	cfg->action = actionSelected();
 	cfg->useStyle = styleCheckBox->isChecked();
-	cfg->currentLanguage = languageComboBox->currentIndex();
+	cfg->currentLanguage = languageComboBox->currentData().toString();
 	cfg->saveConfig();
 }
 




More information about the scribus-commit mailing list