/* 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 "fileunzip.h" #include "hysettings.h" #include "hyphenator.h" #include "langmgr.h" #include "scribusapp.h" #include "scribusdoc.h" #include "util_icon.h" #include "util.h" #include "util_file.h" #include "scpaths.h" #include #include #include #include extern ScribusQApp* ScQApp; HySettings::HySettings( QWidget* parent) : QWidget( parent ) { setupUi(this); 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); buttonExceptRemove->setIcon(QIcon(loadIcon("16/list-remove.png"))); buttonExceptRemove->setEnabled(false); buttonIgnoreAdd->setIcon(QIcon(loadIcon("16/list-add.png"))); buttonIgnoreEdit->setEnabled(false); buttonIgnoreRemove->setIcon(QIcon(loadIcon("16/list-remove.png"))); buttonIgnoreRemove->setEnabled(false); connect(buttonIgnoreAdd, SIGNAL(clicked()), this, SLOT(addToIgnoreList())); connect(buttonIgnoreEdit, SIGNAL(clicked()), this, SLOT(editIgnoreListEntry())); connect(buttonIgnoreRemove, SIGNAL(clicked()), this, SLOT(removeIgnoreListEntry())); connect(ignoreList, SIGNAL(itemSelectionChanged()), this, SLOT(enableIgnoreButtons())); connect(buttonExceptAdd, SIGNAL(clicked()), this, SLOT(addToExceptList())); 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) { verbose->setChecked(!prefsData->Automatic); input->setChecked(prefsData->AutoCheck); setCurrentComboItem(language, LanguageManager::instance()->getTransLangFromLang(prefsData->Language)); wordLen->setValue(prefsData->MinWordLen); maxCount->setValue(prefsData->HyCount); ignoreList->addItems(prefsData->ignoredWords.toList()); ignoreList->sortItems(); exceptList->addItems(prefsData->specialWords.values()); exceptList->sortItems(); } void HySettings::restoreDefaults(ScribusDoc *prefsData) { verbose->setChecked(!prefsData->Automatic); input->setChecked(prefsData->AutoCheck); setCurrentComboItem(language, LanguageManager::instance()->getTransLangFromLang(prefsData->Language)); wordLen->setValue(prefsData->MinWordLen); maxCount->setValue(prefsData->HyCount); ignoreList->addItems(prefsData->docHyphenator->ignoredWords.toList()); ignoreList->sortItems(); exceptList->addItems(prefsData->docHyphenator->specialWords.values()); exceptList->sortItems(); } void HySettings::addToIgnoreList() { bool ok; QString text = QInputDialog::getText(this, tr("Ignore List"), tr("Add a new Entry"), QLineEdit::Normal, "", &ok); if ((ok) && (!text.isEmpty())) { if (ignoreList->findItems(text, Qt::MatchExactly).count() == 0) ignoreList->addItem(text); ignoreList->sortItems(); } } void HySettings::editIgnoreListEntry() { bool ok; QString text = QInputDialog::getText(this, tr("Ignore List"), tr("Edit Entry"), QLineEdit::Normal, ignoreList->currentItem()->text(), &ok); if ((ok) && (!text.isEmpty())) { if (ignoreList->findItems(text, Qt::MatchExactly).count() == 0) ignoreList->currentItem()->setText(text); ignoreList->sortItems(); } } void HySettings::removeIgnoreListEntry() { QListWidgetItem *item = ignoreList->takeItem(ignoreList->row(ignoreList->currentItem())); delete item; if (ignoreList->count() == 0) { buttonIgnoreEdit->setEnabled(false); buttonIgnoreRemove->setEnabled(false); } } void HySettings::enableIgnoreButtons() { buttonIgnoreEdit->setEnabled(true); buttonIgnoreRemove->setEnabled(true); } void HySettings::addToExceptList() { bool ok; QString text = QInputDialog::getText(this, tr("Exception List"), tr("Add a new Entry"), QLineEdit::Normal, "", &ok); if ((ok) && (!text.isEmpty())) { if (exceptList->findItems(text, Qt::MatchExactly).count() == 0) exceptList->addItem(text); exceptList->sortItems(); } } void HySettings::editExceptListEntry() { bool ok; QString text = QInputDialog::getText(this, tr("Exception List"), tr("Edit Entry"), QLineEdit::Normal, exceptList->currentItem()->text(), &ok); if ((ok) && (!text.isEmpty())) { if (exceptList->findItems(text, Qt::MatchExactly).count() == 0) exceptList->currentItem()->setText(text); exceptList->sortItems(); } } void HySettings::removeExceptListEntry() { QListWidgetItem *item = exceptList->takeItem(exceptList->row(exceptList->currentItem())); delete item; if (exceptList->count() == 0) { buttonExceptEdit->setEnabled(false); buttonExceptRemove->setEnabled(false); } } void HySettings::enableExceptButtons() { buttonExceptEdit->setEnabled(true); 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 (d.filetype=="plain") { //qDebug()<dlManager()->addURL(d.url+"/"+s, 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; } if (d.filetype=="plain") { QStringList files=d.files.split(";", QString::SkipEmptyParts); foreach (QString s, files) { //qDebug()<<"plain data found"<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(); } int HySettings::getMaxCount() { return maxCount->value(); } bool HySettings::getVerbose() { return verbose->isChecked(); } bool HySettings::getInput() { return input->isChecked(); } QString HySettings::getLanguage() { return language->itemData(language->currentIndex()).toString(); } QSet HySettings::getIgnoreList() { QSet ret; for (int row = 0; row < ignoreList->count(); row++) { ret.insert(ignoreList->item(row)->text()); } return ret; } QHash HySettings::getExceptionList() { QHash ret; for (int row = 0; row < exceptList->count(); row++) { ret.insert(exceptList->item(row)->text().remove("-"), exceptList->item(row)->text()); } return ret; } void HySettings::setSpellingInvisible() { tabWidget->removeTab(1); }