From 1ae91cf9fdb1dc8292404bf2d6c58384f0557eda Mon Sep 17 00:00:00 2001 From: craig Date: Thu, 7 Jun 2012 20:01:10 +0000 Subject: Add in dictionary downloader code, updates to downloader threading and add in GUI to hyphenator preferences for downloading git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17542 11d20701-8431-0410-a711-e3c959e3b870 --- scribus/CMakeLists.txt | 7 + scribus/downloadmanager/scdlthread.cpp | 1 + scribus/hysettings.cpp | 212 ++++++- scribus/hysettings.h | 28 +- scribus/hysettingsBase.ui | 647 ++++++++++++--------- scribus/langmgr.cpp | 36 +- scribus/langmgr.h | 2 + .../tools/hunspellcheck/hunspellpluginimpl.cpp | 40 +- .../tools/hunspellcheck/hunspellpluginimpl.h | 3 +- scribus/prefs.cpp | 2 +- scribus/reformdoc.cpp | 3 +- scribus/scribusapp.cpp | 14 + scribus/scribusapp.h | 11 +- scribus/ui/downloaddictionaries.cpp | 184 ++++++ scribus/ui/downloaddictionaries.h | 56 ++ scribus/ui/downloaddictionaries.ui | 73 +++ 16 files changed, 984 insertions(+), 335 deletions(-) create mode 100644 scribus/ui/downloaddictionaries.cpp create mode 100644 scribus/ui/downloaddictionaries.h create mode 100644 scribus/ui/downloaddictionaries.ui diff --git a/scribus/CMakeLists.txt b/scribus/CMakeLists.txt index dcd7e10..8503d6c 100644 --- a/scribus/CMakeLists.txt +++ b/scribus/CMakeLists.txt @@ -62,6 +62,7 @@ SET(SCRIBUS_UI_SRC tocindexprefs.ui ui/copypagetomasterpage.ui ui/createrange.ui + ui/downloaddictionaries.ui ui/helpbrowser.ui unicodesearch.ui useprintermarginsdialog.ui @@ -118,6 +119,8 @@ SET(SCRIBUS_MOC_CLASSES docinfo.h docitemattrprefs.h docsections.h + downloadmanager/scdlmgr.h + downloadmanager/scdlthread.h editor.h effectsdialog.h extimageprops.h @@ -278,6 +281,7 @@ SET(SCRIBUS_MOC_CLASSES tt/simpletreemodel/treemodel.h ui/copypagetomasterpagedialog.h ui/createrange.h + ui/downloaddictionaries.h ui/edittoolbar.h ui/filetoolbar.h ui/modetoolbar.h @@ -364,6 +368,8 @@ SET(SCRIBUS_SOURCES docsections.cpp documentchecker.cpp documentinformation.cpp + downloadmanager/scdlmgr.cpp + downloadmanager/scdlthread.cpp editor.cpp effectsdialog.cpp exif.cpp @@ -602,6 +608,7 @@ SET(SCRIBUS_SOURCES tt/simpletreemodel/treemodel.cpp ui/copypagetomasterpagedialog.cpp ui/createrange.cpp + ui/downloaddictionaries.cpp ui/edittoolbar.cpp ui/filetoolbar.cpp ui/modetoolbar.cpp diff --git a/scribus/downloadmanager/scdlthread.cpp b/scribus/downloadmanager/scdlthread.cpp index 5be2c15..a2a12ac 100644 --- a/scribus/downloadmanager/scdlthread.cpp +++ b/scribus/downloadmanager/scdlthread.cpp @@ -98,6 +98,7 @@ void ScDLThread::startNextDownload() if (downloadQueue.isEmpty()) { qDebug()< +#include #include +#include -HySettings::HySettings( QWidget* parent/*, QMap* langs*/ ) : QWidget( parent ) +extern ScribusQApp* ScQApp; + +HySettings::HySettings( QWidget* parent) : QWidget( parent ) { -// langsMap = *langs; + setupUi(this); -// QMap::Iterator it; -// QStringList lada; -// for (it = langs->begin(); it != langs->end(); ++it) -// lada.append(it.value()); -// lada.sort(); -// language->addItems(lada); + + downloadLocation=ScPaths::downloadDir(); LanguageManager *lmg(LanguageManager::instance()); language->setInsertPolicy(QComboBox::InsertAlphabetically); foreach(QString hlang, lmg->hyphLangs()) { language->addItem( lmg->getLangFromAbbrev(hlang), lmg->getLangFromAbbrev(hlang,false) ); } + updateDictList(); + setAvailDictsXMLFile(downloadLocation + "scribus_spell_dicts.xml"); buttonExceptAdd->setIcon(QIcon(loadIcon("16/list-add.png"))); buttonExceptEdit->setEnabled(false); @@ -46,6 +52,8 @@ HySettings::HySettings( QWidget* parent/*, QMap* langs*/ ) : QW connect(buttonExceptEdit, SIGNAL(clicked()), this, SLOT(editExceptListEntry())); connect(buttonExceptRemove, SIGNAL(clicked()), this, SLOT(removeExceptListEntry())); connect(exceptList, SIGNAL(itemSelectionChanged()), this, SLOT(enableExceptButtons())); + connect(spellDownloadButton, SIGNAL(clicked()), this, SLOT(downloadSpellDicts())); + connect(availListDownloadButton, SIGNAL(clicked()), this, SLOT(updateAvailDictList())); } void HySettings::restoreDefaults(struct ApplicationPrefs *prefsData) @@ -156,6 +164,187 @@ void HySettings::enableExceptButtons() buttonExceptRemove->setEnabled(true); } +void HySettings::downloadSpellDicts() +{ + qDebug()<<"Now attempting downloads"; + int rows=availDictTableWidget->rowCount(); + QStringList dlLangs; + for (int i=0; iitem(i,3); + if (dlItem->checkState()==Qt::Checked) + dlLangs<item(i,1)->text(); + } + qDebug()<dlManager()->addURL(d.url, true, downloadLocation); + downloadList.append(d); + ++i; + } + } + if (i>0) + { + connect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadSpellDictsFinished())); + ScQApp->dlManager()->startDownloads(); + } +} + +void HySettings::updateDictList() +{ + bool dictsFound=LanguageManager::instance()->findDictionaries(dictionaryPaths); + if (!dictsFound) + return; + dictionaryMap.clear(); + LanguageManager::instance()->findDictionarySets(dictionaryPaths, dictionaryMap); + + dictTableWidget->clear(); + dictTableWidget->setRowCount(dictionaryMap.count()); + dictTableWidget->setColumnCount(3); + QMapIterator i(dictionaryMap); + int row=0; + while (i.hasNext()) + { + i.next(); + int column=0; + //qDebug()<getLangFromAbbrev(i.key())); + newItem1->setFlags(newItem1->flags() & ~Qt::ItemIsEditable); + dictTableWidget->setItem(row, column++, newItem1); + QTableWidgetItem *newItem2 = new QTableWidgetItem(i.key()); + newItem2->setFlags(newItem1->flags()); + dictTableWidget->setItem(row, column++, newItem2); + QTableWidgetItem *newItem3 = new QTableWidgetItem(i.value()); + newItem3->setFlags(newItem1->flags()); + newItem3->setToolTip(i.value()); + dictTableWidget->setItem(row, column++, newItem3); + ++row; + } + QStringList headers; + headers << tr("Language") << tr("Code") << tr("Location"); + dictTableWidget->setHorizontalHeaderLabels(headers); + dictTableWidget->resizeColumnsToContents(); +} + +void HySettings::updateAvailDictList() +{ + ScQApp->dlManager()->addURL("http://services.scribus.net/scribus_spell_dicts.xml", true, downloadLocation); + connect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadDictListFinished())); + ScQApp->dlManager()->startDownloads(); +} + +void HySettings::downloadDictListFinished() +{ + disconnect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadDictListFinished())); + setAvailDictsXMLFile(downloadLocation + "scribus_spell_dicts.xml"); +} + +void HySettings::downloadSpellDictsFinished() +{ + disconnect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadDictListFinished())); + //qDebug()<<"Downloads All Finished"; + QString userDictDir(ScPaths::getUserDictDir(true)); + foreach(DictData d, downloadList) + { + QString basename = QFileInfo(d.url).fileName(); + QString filename=downloadLocation+"/"+basename; + //qDebug()<getFile(s, userDictDir); + } + delete fun; + } + updateDictList(); +} + +void HySettings::setAvailDictsXMLFile(QString availDictsXMLDataFile) +{ + QFile dataFile(availDictsXMLDataFile); + dataFile.open(QIODevice::ReadOnly); + QTextStream ts(&dataFile); + ts.setCodec(QTextCodec::codecForName("UTF-8")); + QString errorMsg; + int eline; + int ecol; + QDomDocument doc( "scribus_spell_dicts" ); + QString data(ts.readAll()); + dataFile.close(); + if ( !doc.setContent( data, &errorMsg, &eline, &ecol )) + { + if (data.toLower().contains("404 not found")) + qDebug()<<"File not found on server"; + else + qDebug()<<"Could not open file"<clear(); + availDictTableWidget->setRowCount(dictList.count()); + availDictTableWidget->setColumnCount(4); + int row=0; + foreach(DictData d, dictList) + { + int column=0; + //qDebug()<setFlags(newItem1->flags() & ~Qt::ItemIsEditable); + availDictTableWidget->setItem(row, column++, newItem1); + QTableWidgetItem *newItem2 = new QTableWidgetItem(d.lang); + newItem2->setFlags(newItem1->flags()); + availDictTableWidget->setItem(row, column++, newItem2); + QTableWidgetItem *newItem3 = new QTableWidgetItem(); + newItem3->setCheckState(dictionaryMap.contains(d.lang) ? Qt::Checked : Qt::Unchecked); + newItem3->setFlags(newItem1->flags() & ~Qt::ItemIsUserCheckable); + availDictTableWidget->setItem(row, column++, newItem3); + QTableWidgetItem *newItem4 = new QTableWidgetItem(); + newItem4->setCheckState(d.download ? Qt::Checked : Qt::Unchecked); + availDictTableWidget->setItem(row, column++, newItem4); + ++row; + } + QStringList headers; + headers << tr("Language") << tr("Code") << tr("Installed") << tr("Download"); + availDictTableWidget->setHorizontalHeaderLabels(headers); + availDictTableWidget->resizeColumnsToContents(); +} + int HySettings::getWordLen() { return wordLen->value(); @@ -200,3 +389,8 @@ QHash HySettings::getExceptionList() } return ret; } + +void HySettings::setSpellingInvisible() +{ + tabWidget->removeTab(1); +} diff --git a/scribus/hysettings.h b/scribus/hysettings.h index 6b0541a..acc5a41 100644 --- a/scribus/hysettings.h +++ b/scribus/hysettings.h @@ -17,10 +17,22 @@ class ScribusDoc; class SCRIBUS_API HySettings : public QWidget, Ui::hysettingsBase { + //TODO: Dict license showing, URL background unzipping, checksumming + struct DictData + { + QString lang; + QString version; + QString files; + QString url; + QString desc; + QString license; + bool download; + }; + Q_OBJECT public: - HySettings( QWidget* parent/*, QMap* langs*/); + HySettings( QWidget* parent); ~HySettings() {}; void restoreDefaults(struct ApplicationPrefs *prefsData); void restoreDefaults(ScribusDoc *prefsData); @@ -31,6 +43,7 @@ public: QString getLanguage(); QSet getIgnoreList(); QHash getExceptionList(); + void setSpellingInvisible(); private slots: void addToIgnoreList(); @@ -41,8 +54,19 @@ private slots: void editExceptListEntry(); void removeExceptListEntry(); void enableExceptButtons(); + void downloadSpellDicts(); + void updateDictList(); + void updateAvailDictList(); + void downloadDictListFinished(); + void downloadSpellDictsFinished(); + void setAvailDictsXMLFile(QString availDictsXMLDataFile); -// protected: + protected: + QMap dictionaryMap; + QStringList dictionaryPaths; + QString downloadLocation; + QList dictList; + QList downloadList; // QMap langsMap; }; diff --git a/scribus/hysettingsBase.ui b/scribus/hysettingsBase.ui index dacb176..f1b8942 100644 --- a/scribus/hysettingsBase.ui +++ b/scribus/hysettingsBase.ui @@ -1,306 +1,385 @@ - + + hysettingsBase - - + + 0 0 - 593 - 444 + 720 + 445 - + Form - - + + 10 - - 10 - - - 10 - - - 10 - - - 5 - - + 5 - - - - General Options + + + + QTabWidget::Rounded - - - 5 - - - 10 - - - 10 - - - 10 - - - 10 - - - - - A dialog box showing all possible hyphens for each word will show up when you use the Extras, Hyphenate Text option. - - - &Hyphenation Suggestions - - - - - - - Enables automatic hyphenation of your text while typing. - - - Hyphenate Text Automatically &During Typing - - - - - - - - - - Behaviour + + 0 - - - 10 - - - 10 - - - 10 - - - 10 - - - 5 - - - 5 - - - - - &Language: - - - language - - - - - - - - - - &Smallest Word: - - - wordLen - - - - - - - Length of the smallest word to be hyphenated. - - - 3 - - - - - - - Chars - - - - - - - Consecutive Hyphenations &Allowed: - - - false - - - maxCount - - - - - - - Maximum number of Hyphenations following each other. + + + Hyphenation + + + + + + + 0 + 0 + + + + General Options + + + + 5 + + + 10 + + + + + A dialog box showing all possible hyphens for each word will show up when you use the Extras, Hyphenate Text option. + + + &Hyphenation Suggestions + + + + + + + Enables automatic hyphenation of your text while typing. + + + Hyphenate Text Automatically &During Typing + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + Behaviour + + + + 10 + + + 5 + + + + + &Language: + + + language + + + + + + + + + + &Smallest Word: + + + wordLen + + + + + + + Length of the smallest word to be hyphenated. + + + 3 + + + + + + + Chars + + + + + + + Consecutive Hyphenations &Allowed: + + + false + + + maxCount + + + + + + + Maximum number of Hyphenations following each other. A value of 0 means unlimited hyphenations. - - - - - - - - - - Exceptions - - - - 10 - - - 10 - - - 10 - - - 10 - - - 5 - - - 5 - - - - - - - - - - - - - - - Edit - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Ignore List - - - - 10 - - - 10 - - - 10 - - - 10 - - - 5 - - - 5 - - - - - - 0 - 0 - - - - - - - - - - - - - - - Edit - - - - - - - - - - - - - - Qt::Horizontal - - - - 21 - 20 - - - - - + + + + + + + + + + + 0 + 0 + + + + Exceptions + + + + 10 + + + 5 + + + + + + + + + + + + + + + Edit + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + 0 + + + + Ignore List + + + + 10 + + + 5 + + + + + + 0 + 0 + + + + + + + + + + + + + + + Edit + + + + + + + + + + + + + + Qt::Horizontal + + + + 21 + 20 + + + + + + + + + + + + Spelling + + + + + + + + + + Installed Spelling Dictionaries + + + + + + + false + + + + + + + + + + + Downloadable Spelling Dictionaries + + + + + + + false + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Refresh Downloadable List + + + + + + + Download Selected Dictionaries + + + + + + + - + diff --git a/scribus/langmgr.cpp b/scribus/langmgr.cpp index f19832b..7f13ed3 100644 --- a/scribus/langmgr.cpp +++ b/scribus/langmgr.cpp @@ -20,7 +20,7 @@ for which a new license (GPL+exception) is in place. ***************************************************************************/ #include - +#include #include #include #include @@ -302,6 +302,40 @@ QString LanguageManager::numericSequence(QString seq) return retSeq; } +bool LanguageManager::findDictionaries(QStringList &sl) +{ + sl=ScPaths::instance().spellDirs(); + if (sl.count()==0) + return false; + return true; +} + +void LanguageManager::findDictionarySets(QStringList &dictionaryPaths, QMap &dictionaryMap) +{ + for (int i=0; i& dictionaryMap); void addHyphLang(const QString& lang, const QString& filename); const QString getHyphFilename(const QString& lang, bool langIsAbbreviated = true); diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp index be5cfda..2ff9493 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp +++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp @@ -32,7 +32,7 @@ for which a new license (GPL+exception) is in place. HunspellPluginImpl::HunspellPluginImpl() : QObject(0) { //hspellers=NULL; - numDicts=0; +// numDicts=0; m_runningForSE=false; m_SE=NULL; } @@ -45,7 +45,7 @@ HunspellPluginImpl::~HunspellPluginImpl() h = NULL; } hspellerMap.clear(); - numDicts = 0; +// numDicts = 0; } bool HunspellPluginImpl::run(const QString & target, ScribusDoc* doc) @@ -62,45 +62,17 @@ bool HunspellPluginImpl::run(const QString & target, ScribusDoc* doc) return spellCheckOk; } -bool HunspellPluginImpl::findDictionaries() -{ - dictionaryPaths=ScPaths::instance().spellDirs(); - if (dictionaryPaths.count()==0) - return false; - return true; -} - bool HunspellPluginImpl::initHunspell() { - bool dictPathFound=findDictionaries(); + bool dictPathFound=LanguageManager::instance()->findDictionaries(dictionaryPaths); if (!dictPathFound) { qDebug()<<"No preinstalled dictonary paths found"; return false; } - for (int i=0; ifindDictionarySets(dictionaryPaths, dictionaryMap); +// numDicts=dictionaryMap.count(); if (dictionaryMap.count()==0) return false; diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h index 7963d4a..3048636 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h +++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h @@ -30,7 +30,6 @@ class HunspellPluginImpl : public QObject HunspellPluginImpl(); ~HunspellPluginImpl(); bool run(const QString & target, ScribusDoc* doc=0); - bool findDictionaries(); bool initHunspell(); bool checkWithHunspell(); bool checkWithHunspellSE(); @@ -43,7 +42,7 @@ class HunspellPluginImpl : public QObject protected: QMap dictionaryMap; QStringList dictionaryPaths; - int numDicts, numAFFs; + //int numDicts, numAFFs; QMap hspellerMap; ScribusDoc* m_doc; bool m_runningForSE; diff --git a/scribus/prefs.cpp b/scribus/prefs.cpp index 30609bb..88eb0a8 100644 --- a/scribus/prefs.cpp +++ b/scribus/prefs.cpp @@ -87,7 +87,7 @@ Preferences::Preferences( QWidget* parent) : PrefsDialogBase( parent ) addItem( tr("Tools"), loadIcon("tools.png"), tabTools); tabHyphenator = new HySettings(prefsWidgets/*, &ap->LangTransl*/); - addItem( tr("Hyphenator"), loadIcon("hyphenate.png"), tabHyphenator); + addItem( tr("Hyphenation and Spelling"), loadIcon("hyphenate.png"), tabHyphenator); tabFonts = new FontPrefs(prefsWidgets, false, prefsManager->preferencesLocation(), ap->doc); addItem( tr("Fonts"), loadIcon("font.png"), tabFonts); diff --git a/scribus/reformdoc.cpp b/scribus/reformdoc.cpp index a4bc3a0..4d1e2c5 100644 --- a/scribus/reformdoc.cpp +++ b/scribus/reformdoc.cpp @@ -80,7 +80,8 @@ ReformDoc::ReformDoc( QWidget* parent, ScribusDoc* doc ) : PrefsDialogBase( pare tabTools = new TabTools( prefsWidgets, &doc->toolSettings, docUnitIndex, doc); addItem( tr("Tools"), loadIcon("tools.png"), tabTools); - tabHyphenator = new HySettings(prefsWidgets/*, &ScMW->LangTransl*/); + tabHyphenator = new HySettings(prefsWidgets); + tabHyphenator->setSpellingInvisible(); addItem( tr("Hyphenator"), loadIcon("hyphenate.png"), tabHyphenator); tabFonts = new FontPrefs(prefsWidgets, true, PrefsManager::instance()->preferencesLocation(), doc); diff --git a/scribus/scribusapp.cpp b/scribus/scribusapp.cpp index b725217..82582d1 100644 --- a/scribus/scribusapp.cpp +++ b/scribus/scribusapp.cpp @@ -94,10 +94,13 @@ ScribusQApp::ScribusQApp( int & argc, char ** argv ) : QApplication(argc, argv), { ScQApp=this; ScCore=NULL; + + initDLMgr(); } ScribusQApp::~ScribusQApp() { + m_scDLMgr->deleteLater(); PrefsManager::deleteInstance(); } @@ -109,6 +112,12 @@ void ScribusQApp::initLang() installTranslators(langs); } +void ScribusQApp::initDLMgr() +{ + m_scDLMgr=new ScDLManager(this); + connect(m_scDLMgr, SIGNAL(fileReceived(const QString&)), SLOT(downloadComplete(const QString&))); +} + void ScribusQApp::parseCommandLine() { showSplash=!neverSplashExists(); @@ -502,6 +511,11 @@ bool ScribusQApp::neverSplashExists() return QFileInfo(ScPaths::getApplicationDataDir() + ".neversplash").exists(); } +void ScribusQApp::downloadComplete(const QString &t) +{ + qDebug()<<"ScribusQApp: download finished:"<type()) diff --git a/scribus/scribusapp.h b/scribus/scribusapp.h index 65d07aa..9048328 100644 --- a/scribus/scribusapp.h +++ b/scribus/scribusapp.h @@ -25,6 +25,7 @@ for which a new license (GPL+exception) is in place. #include #include "scribusapi.h" +#include "downloadmanager/scdlmgr.h" class ScribusCore; class ScribusMainWindow; @@ -36,7 +37,6 @@ class SCRIBUS_API ScribusQApp : public QApplication ScribusQApp( int & argc, char ** argv ); ~ScribusQApp(); int init(); - void initLang(); void parseCommandLine(); void changeGUILanguage(const QString & lang); /*! @@ -66,9 +66,17 @@ class SCRIBUS_API ScribusQApp : public QApplication void neverSplash(bool splashOff); bool neverSplashExists(); const QString& currGUILanguage() {return GUILang;}; + ScDLManager* dlManager() { return m_scDLMgr; } + + public slots: + + protected slots: + void downloadComplete(const QString& t); private: ScribusCore* m_ScCore; + void initLang(); + void initDLMgr(); void showHeader(); void showVersion(); /*! @@ -95,6 +103,7 @@ class SCRIBUS_API ScribusQApp : public QApplication QString prefsUserFile; QList filesToLoad; QString fileName; + ScDLManager *m_scDLMgr; protected: virtual bool event(QEvent *event); diff --git a/scribus/ui/downloaddictionaries.cpp b/scribus/ui/downloaddictionaries.cpp new file mode 100644 index 0000000..db990e9 --- /dev/null +++ b/scribus/ui/downloaddictionaries.cpp @@ -0,0 +1,184 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "downloaddictionaries.h" + +#include "fileunzip.h" +#include "scpaths.h" +#include "scribusapp.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +extern ScribusQApp* ScQApp; + +DownloadDictionaries::DownloadDictionaries(QWidget* parent, Qt::WFlags fl) + : QDialog(parent, fl) +{ + setupUi(this); + downloadLocation=ScPaths::downloadDir(); + + connect(closeButton, SIGNAL(clicked()), SLOT(close())); + connect(downloadButton, SIGNAL(clicked()), SLOT(download())); + connect(downloadListButton, SIGNAL(clicked()), SLOT(downloadDictList())); +} + +DownloadDictionaries::~DownloadDictionaries() +{ +} + +void DownloadDictionaries::setXMLFile(const QString &f) +{ + m_xmlDataFile=f; + parseData(); +} + +void DownloadDictionaries::parseData() +{ + QFile dataFile(m_xmlDataFile); + dataFile.open(QIODevice::ReadOnly); + QTextStream ts(&dataFile); + ts.setCodec(QTextCodec::codecForName("UTF-8")); + QString errorMsg; + int eline; + int ecol; + QDomDocument doc( "scribus_spell_dicts" ); + QString data(ts.readAll()); + dataFile.close(); + if ( !doc.setContent( data, &errorMsg, &eline, &ecol )) + { + if (data.toLower().contains("404 not found")) + qDebug()<<"File not found on server"; + else + qDebug()<<"Could not open file"<clear(); + dictTableWidget->setRowCount(dictList.count()); + dictTableWidget->setColumnCount(3); + int row=0; + foreach(DictData d, dictList) + { + int column=0; + qDebug()<setFlags(newItem1->flags() & ~Qt::ItemIsEditable); + dictTableWidget->setItem(row, column++, newItem1); + QTableWidgetItem *newItem2 = new QTableWidgetItem(d.lang); + newItem2->setFlags(newItem1->flags()); + dictTableWidget->setItem(row, column++, newItem2); + QTableWidgetItem *newItem3 = new QTableWidgetItem(); + newItem3->setCheckState(d.download ? Qt::Checked : Qt::Unchecked); + dictTableWidget->setItem(row, column++, newItem3); + ++row; + } + QStringList headers; + headers << tr("Language") << tr("Code") << tr("Location"); + dictTableWidget->setHorizontalHeaderLabels(headers); + dictTableWidget->resizeColumnsToContents(); +} + +void DownloadDictionaries::download() +{ + qDebug()<<"Now attempting downloads"; + int rows=dictTableWidget->rowCount(); + QStringList dlLangs; + for (int i=0; iitem(i,2); + if (dlItem->checkState()==Qt::Checked) + dlLangs<item(i,1)->text(); + } + qDebug()<dlManager()->addURL(d.url, true, downloadLocation); + downloadList.append(d); + ++i; + } + } + if (i>0) + { + connect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadsFinished())); + ScQApp->dlManager()->startDownloads(); + } +} + +void DownloadDictionaries::downloadDictList() +{ + ScQApp->dlManager()->addURL("http://services.scribus.net/scribus_spell_dicts.xml", true, downloadLocation); + connect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadDictListFinished())); + ScQApp->dlManager()->startDownloads(); +} + +void DownloadDictionaries::downloadDictListFinished() +{ + disconnect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadDictListFinished())); + setXMLFile(downloadLocation + "scribus_spell_dicts.xml"); +} + +void DownloadDictionaries::downloadsFinished() +{ + disconnect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadsFinished())); + qDebug()<<"Downloads All Finished"; + QString userDictDir(ScPaths::getUserDictDir(true)); + foreach(DictData d, downloadList) + { + QString basename = QFileInfo(d.url).fileName(); + QString filename=downloadLocation+"/"+basename; + qDebug()<getFile(s, userDictDir); + } + delete fun; + } +} + diff --git a/scribus/ui/downloaddictionaries.h b/scribus/ui/downloaddictionaries.h new file mode 100644 index 0000000..d1366c8 --- /dev/null +++ b/scribus/ui/downloaddictionaries.h @@ -0,0 +1,56 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef DOWNLOADDICTIONARIES +#define DOWNLOADDICTIONARIES + +#include "scribusapi.h" +#include "ui_downloaddictionaries.h" + +#include +#include +#include + + + +class SCRIBUS_API DownloadDictionaries : public QDialog, Ui::DownloadDictionaries +{ + struct DictData + { + QString lang; + QString version; + QString files; + QString url; + QString desc; + QString license; + bool download; + }; + + Q_OBJECT + public: + DownloadDictionaries(QWidget* parent, Qt::WFlags fl=0); + ~DownloadDictionaries(); + + void setXMLFile(const QString& f); + + + protected: + void parseData(); + + + QString m_xmlDataFile; + QList dictList; + QList downloadList; + QString downloadLocation; + + protected slots: + void download(); + void downloadDictList(); + void downloadDictListFinished(); + void downloadsFinished(); +}; + +#endif diff --git a/scribus/ui/downloaddictionaries.ui b/scribus/ui/downloaddictionaries.ui new file mode 100644 index 0000000..5634129 --- /dev/null +++ b/scribus/ui/downloaddictionaries.ui @@ -0,0 +1,73 @@ + + + DownloadDictionaries + + + + 0 + 0 + 542 + 270 + + + + Download Dictionaries + + + + + + Available Dictionary Downloads + + + + + + + QAbstractItemView::SingleSelection + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Update Dictionary List + + + + + + + Download Dictionaries + + + + + + + Close + + + + + + + + + + -- cgit