r22422 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Tue Mar 6 22:54:26 UTC 2018
Author: jghali
Date: Tue Mar 6 22:54:26 2018
New Revision: 22422
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22422
Log:
refactoring and fixed for gettext dialogs
Modified:
trunk/Scribus/scribus/gtgettext.cpp
trunk/Scribus/scribus/ui/gtdialogs.cpp
trunk/Scribus/scribus/ui/gtdialogs.h
Modified: trunk/Scribus/scribus/gtgettext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22422&path=/trunk/Scribus/scribus/gtgettext.cpp
==============================================================================
--- trunk/Scribus/scribus/gtgettext.cpp (original)
+++ trunk/Scribus/scribus/gtgettext.cpp Tue Mar 6 22:54:26 2018
@@ -67,8 +67,7 @@
// If the map is found, assign ida to the corresponding struct in the map.
ida = *m_importerMap[fend];
// Otherwise, test for the lowercase version
- else
- if (m_importerMap.find(fendL) != m_importerMap.end())
+ else if (m_importerMap.find(fendL) != m_importerMap.end())
// If the map is found, assign ida to the corresponding struct in the map.
ida = *m_importerMap[fendL];
// Otherwise, try and ask the user.
@@ -78,7 +77,7 @@
m_dias = new gtDialogs();
// Pop up the dialog asking the user to select the type from our list (ilist) of
// importable file types. If one is not selected, set callImporter to false.
- callImporter = m_dias->runImporterDialog(m_ilist);
+ callImporter = m_dias->runImporterDialog(filename, m_ilist);
// If we're gonna call an importer, we need to copy it's struct to ida.
if (callImporter)
ida = m_importers[m_dias->getImporter()];
@@ -223,9 +222,7 @@
impsetup.importer = m_dias->getImporter();
impsetup.textOnly = m_dias->importTextOnly();
impsetup.prefixNames = m_dias->prefixStyles();
-// launchImporter(dias->getImporter(), dias->getFileName(),
-// dias->importTextOnly(), dias->getEncoding(), append);
- } // if (dias->runFileDialog(filters, ilist))
+ }
// Destroy the dialog.
delete m_dias;
// Return the ImportSetup struct.
Modified: trunk/Scribus/scribus/ui/gtdialogs.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22422&path=/trunk/Scribus/scribus/ui/gtdialogs.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/gtdialogs.cpp (original)
+++ trunk/Scribus/scribus/ui/gtdialogs.cpp Tue Mar 6 22:54:26 2018
@@ -32,6 +32,8 @@
#include "prefsmanager.h"
#include "sccombobox.h"
#include "ui/gtfiledialog.h"
+
+#include <QFileInfo>
#include <QHBoxLayout>
#include <QLabel>
#include <QPixmap>
@@ -43,8 +45,13 @@
/********* Class gtImporterDialog*******************************************************************/
-gtImporterDialog::gtImporterDialog(const QStringList& importers, int currentSelection)
-{
+gtImporterDialog::gtImporterDialog(const QString& fileName, const QStringList& importers, int currentSelection)
+{
+ QFileInfo fInfo(fileName);
+ QString ext = fInfo.suffix();
+ if ((ext.length() > 0) && !ext.startsWith("."))
+ ext.prepend(".");
+
setWindowTitle( tr("Choose the importer to use"));
setWindowIcon(IconManager::instance()->loadIcon("AppIcon.png"));
@@ -53,7 +60,13 @@
QBoxLayout* llayout = new QHBoxLayout;
llayout->setMargin(5);
llayout->setSpacing(5);
- QLabel* label = new QLabel( tr("Choose the importer to use"), this);
+
+ QString labelText;
+ if (ext.length() > 0)
+ labelText = tr("Choose the importer to use for %1 file:").arg(ext);
+ else
+ labelText = tr("Choose the importer to use:");
+ QLabel* label = new QLabel(labelText, this);
llayout->addWidget(label);
layout->addLayout(llayout);
@@ -111,12 +124,11 @@
gtDialogs::gtDialogs()
{
- fdia = NULL;
- fileName = "";
- encoding = "";
- importer = -1;
- prefs = PrefsManager::instance()->prefsFile->getContext("gtDialogs");
- pwd = QDir::currentPath();
+ m_fdia = NULL;
+ m_fileName = "";
+ m_encoding = "";
+ m_importer = -1;
+ m_prefs = PrefsManager::instance()->prefsFile->getContext("gtDialogs");
}
bool gtDialogs::runFileDialog(const QString& filters, const QStringList& importers)
@@ -124,56 +136,56 @@
bool accepted = false;
PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
QString dir = dirs->get("get_text", ".");
- fdia = new gtFileDialog(filters, importers, dir);
- if (fdia->exec() == QDialog::Accepted)
- {
- fileName = fdia->selectedFile();
- if (!fileName.isEmpty())
+ m_fdia = new gtFileDialog(filters, importers, dir);
+ if (m_fdia->exec() == QDialog::Accepted)
+ {
+ m_fileName = m_fdia->selectedFile();
+ if (!m_fileName.isEmpty())
accepted = true;
- encoding = fdia->encodingCombo->currentText();
+ m_encoding = m_fdia->encodingCombo->currentText();
// if (encoding == "UTF-16")
// encoding = "ISO-10646-UCS-2";
- importer = fdia->importerCombo->currentIndex() - 1;
- dirs->set("get_text", fileName.left(fileName.lastIndexOf("/")));
- }
- QDir::setCurrent(pwd);
+ m_importer = m_fdia->importerCombo->currentIndex() - 1;
+ dirs->set("get_text", m_fileName.left(m_fileName.lastIndexOf("/")));
+ }
return accepted;
}
-bool gtDialogs::runImporterDialog(const QStringList& importers)
-{
- int curSel = prefs->getInt("curSel", 0);
- QString extension = "";
- QString shortName = fileName.right(fileName.length() - fileName.lastIndexOf("/") - 1);
- if (shortName.indexOf(".") == -1)
- extension = ".no_extension";
- else
- extension = fileName.right(fileName.length() - fileName.lastIndexOf("."));
- int extensionSel = prefs->getInt(extension, -1);
- QString imp = prefs->get("remember"+extension, QString("false"));
+bool gtDialogs::runImporterDialog(const QString& fileName, const QStringList& importers)
+{
+ bool ok = false;
+ bool shouldRemember = false;
+
+ QFileInfo fileInfo(fileName);
+ QString fileExtension = fileInfo.suffix();
+ if (fileExtension.length() > 0 && !fileExtension.startsWith("."))
+ fileExtension.prepend(".");
+ if (fileExtension.isEmpty())
+ fileExtension = ".no_extension";
+
+ QString imp = m_prefs->get("remember"+ fileExtension, QString("false"));
QString res = "";
- bool shouldRemember = false;
- bool ok = false;
if (imp != "false")
{
res = imp;
- if (importers.contains(res) > 0)
+ if (importers.contains(res))
ok = true;
}
if (!ok)
{
+ int curSel = m_prefs->getInt("curSel", 0);
+ int extensionSel = m_prefs->getInt(fileExtension, -1);
if ((extensionSel > -1) && (extensionSel < static_cast<int>(importers.count())))
curSel = extensionSel;
else
curSel = 0;
- gtImporterDialog* idia = new gtImporterDialog(importers, curSel);
+ gtImporterDialog* idia = new gtImporterDialog(fileName, importers, curSel);
if (idia->exec())
{
res = idia->getImporter();
shouldRemember = idia->shouldRemember();
-
ok = true;
}
delete idia;
@@ -181,27 +193,17 @@
if (ok)
{
- QString fileExtension = "";
- for (int i = 0; i < importers.count(); ++i)
+ QString fileExtension;
+ int importerIndex = importers.indexOf(res);
+ if (importerIndex >= 0)
{
- if (importers[i] == res)
+ m_importer = importerIndex;
+ m_prefs->set("curSel", static_cast<int>(importerIndex));
+ if (!fileExtension.isEmpty())
{
- importer = i;
- prefs->set("curSel", static_cast<int>(i));
- if (fileName.indexOf(".") != -1)
- {
- if (shortName.indexOf(".") == -1)
- fileExtension = ".no_extension";
- else
- fileExtension = fileName.right(fileName.length() - fileName.lastIndexOf("."));
- if (!fileExtension.isEmpty())
- {
- prefs->set(fileExtension, static_cast<int>(i));
- if (shouldRemember)
- prefs->set("remember"+fileExtension, res);
- }
- }
- break;
+ m_prefs->set(fileExtension, static_cast<int>(importerIndex));
+ if (shouldRemember)
+ m_prefs->set("remember" + fileExtension, res);
}
}
}
@@ -210,36 +212,36 @@
const QString& gtDialogs::getFileName()
{
- return fileName;
+ return m_fileName;
}
const QString& gtDialogs::getEncoding()
{
- return encoding;
+ return m_encoding;
}
int gtDialogs::getImporter()
{
- return importer;
+ return m_importer;
}
bool gtDialogs::importTextOnly()
{
bool ret = false;
- if (fdia)
- ret = fdia->textOnlyCheckBox->isChecked();
+ if (m_fdia)
+ ret = m_fdia->textOnlyCheckBox->isChecked();
return ret;
}
bool gtDialogs::prefixStyles()
{
bool ret = false;
- if (fdia)
- ret = fdia->prefixStylesCheckBox->isChecked();
+ if (m_fdia)
+ ret = m_fdia->prefixStylesCheckBox->isChecked();
return ret;
}
gtDialogs::~gtDialogs()
{
- delete fdia;
-}
+ delete m_fdia;
+}
Modified: trunk/Scribus/scribus/ui/gtdialogs.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22422&path=/trunk/Scribus/scribus/ui/gtdialogs.h
==============================================================================
--- trunk/Scribus/scribus/ui/gtdialogs.h (original)
+++ trunk/Scribus/scribus/ui/gtdialogs.h Tue Mar 6 22:54:26 2018
@@ -45,7 +45,7 @@
QCheckBox* rememberCheck;
QPushButton* okButton;
public:
- gtImporterDialog(const QStringList& importers, int currentSelection);
+ gtImporterDialog(const QString& fileName, const QStringList& importers, int currentSelection);
~gtImporterDialog();
bool shouldRemember();
QString getImporter();
@@ -53,23 +53,24 @@
class SCRIBUS_API gtDialogs
{
-private:
- gtFileDialog* fdia;
- QString fileName;
- QString encoding;
- int importer;
- PrefsContext* prefs;
- QString pwd;
public:
gtDialogs();
~gtDialogs();
+
const QString& getFileName();
const QString& getEncoding();
int getImporter();
bool importTextOnly();
bool prefixStyles();
bool runFileDialog(const QString& filters, const QStringList& importers);
- bool runImporterDialog(const QStringList& importers);
+ bool runImporterDialog(const QString& file, const QStringList& importers);
+
+private:
+ gtFileDialog* m_fdia;
+ QString m_fileName;
+ QString m_encoding;
+ int m_importer;
+ PrefsContext* m_prefs;
};
#endif // GTDIALOGS_H
More information about the scribus-commit
mailing list