1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7
8 #include <QDebug>
9 #include <QDomDocument>
10 #include <QInputDialog>
11 #include <QListWidget>
12 #include <QTableWidgetItem>
13 #include <QTextCodec>
14 #include <QTextStream>
15
16 #include "downloadmanager/scdlmgr.h"
17 #include "iconmanager.h"
18 #include "prefs_hyphenator.h"
19 #include "prefsstructs.h"
20 #include "scpaths.h"
21 #include "scribusapp.h"
22 #include "scribusdoc.h"
23 #include "third_party/zip/scribus_zip.h"
24 #include "util.h"
25 #include "util_file.h"
26
Prefs_Hyphenator(QWidget * parent,ScribusDoc * doc)27 Prefs_Hyphenator::Prefs_Hyphenator(QWidget* parent, ScribusDoc* doc)
28 : Prefs_Pane(parent)
29 {
30 setupUi(this);
31 languageChange();
32
33 m_caption = tr("Hyphenator");
34 m_icon = "signature_16.png";
35
36 exceptionAddButton->setIcon(IconManager::instance().loadIcon("16/list-add.png"));
37 exceptionEditButton->setEnabled(false);
38 exceptionRemoveButton->setIcon(IconManager::instance().loadIcon("16/list-remove.png"));
39 exceptionRemoveButton->setEnabled(false);
40 ignoreAddButton->setIcon(IconManager::instance().loadIcon("16/list-add.png"));
41 ignoreEditButton->setEnabled(false);
42 ignoreRemoveButton->setIcon(IconManager::instance().loadIcon("16/list-remove.png"));
43 ignoreRemoveButton->setEnabled(false);
44 connect(ignoreAddButton, SIGNAL(clicked()), this, SLOT(addToIgnoreList()));
45 connect(ignoreEditButton, SIGNAL(clicked()), this, SLOT(editIgnoreListEntry()));
46 connect(ignoreRemoveButton, SIGNAL(clicked()), this, SLOT(removeIgnoreListEntry()));
47 connect(ignoreListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(enableIgnoreButtons()));
48 connect(exceptionAddButton, SIGNAL(clicked()), this, SLOT(addToExceptList()));
49 connect(exceptionEditButton, SIGNAL(clicked()), this, SLOT(editExceptListEntry()));
50 connect(exceptionRemoveButton, SIGNAL(clicked()), this, SLOT(removeExceptListEntry()));
51 connect(exceptionListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(enableExceptButtons()));
52 }
53
54 Prefs_Hyphenator::~Prefs_Hyphenator() = default;
55
languageChange()56 void Prefs_Hyphenator::languageChange()
57 {
58 }
59
restoreDefaults(struct ApplicationPrefs * prefsData)60 void Prefs_Hyphenator::restoreDefaults(struct ApplicationPrefs *prefsData)
61 {
62 hyphSuggestionsCheckBox->setChecked(!prefsData->hyphPrefs.Automatic);
63 hyphAutoCheckBox->setChecked(prefsData->hyphPrefs.AutoCheck);
64 ignoreListWidget->addItems(prefsData->hyphPrefs.ignoredWords.values());
65 ignoreListWidget->sortItems();
66 exceptionListWidget->addItems(prefsData->hyphPrefs.specialWords.values());
67 exceptionListWidget->sortItems();
68 }
69
saveGuiToPrefs(struct ApplicationPrefs * prefsData) const70 void Prefs_Hyphenator::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
71 {
72 prefsData->hyphPrefs.Automatic = !hyphSuggestionsCheckBox->isChecked();
73 prefsData->hyphPrefs.AutoCheck = hyphAutoCheckBox->isChecked();
74 QSet<QString> ignoreList;
75 for (int row = 0; row < ignoreListWidget->count(); row++)
76 {
77 ignoreList.insert(ignoreListWidget->item(row)->text());
78 }
79 prefsData->hyphPrefs.ignoredWords = ignoreList;
80 QHash<QString, QString> exceptionList;
81 for (int row = 0; row < exceptionListWidget->count(); row++)
82 {
83 exceptionList.insert(exceptionListWidget->item(row)->text().remove("-"), exceptionListWidget->item(row)->text());
84 }
85 prefsData->hyphPrefs.specialWords = exceptionList;
86 }
87
addToIgnoreList()88 void Prefs_Hyphenator::addToIgnoreList()
89 {
90 bool ok;
91 QString text = QInputDialog::getText(this, tr("Ignore List"), tr("Add a new Entry"), QLineEdit::Normal, "", &ok);
92 if ((ok) && (!text.isEmpty()))
93 {
94 if (ignoreListWidget->findItems(text, Qt::MatchExactly).count() == 0)
95 ignoreListWidget->addItem(text);
96 ignoreListWidget->sortItems();
97 }
98 }
99
editIgnoreListEntry()100 void Prefs_Hyphenator::editIgnoreListEntry()
101 {
102 bool ok;
103 QString text = QInputDialog::getText(this, tr("Ignore List"), tr("Edit Entry"), QLineEdit::Normal, ignoreListWidget->currentItem()->text(), &ok);
104 if ((ok) && (!text.isEmpty()))
105 {
106 if (ignoreListWidget->findItems(text, Qt::MatchExactly).count() == 0)
107 ignoreListWidget->currentItem()->setText(text);
108 ignoreListWidget->sortItems();
109 }
110 }
111
removeIgnoreListEntry()112 void Prefs_Hyphenator::removeIgnoreListEntry()
113 {
114 QListWidgetItem *item = ignoreListWidget->takeItem(ignoreListWidget->row(ignoreListWidget->currentItem()));
115 delete item;
116 if (ignoreListWidget->count() == 0)
117 {
118 ignoreEditButton->setEnabled(false);
119 ignoreRemoveButton->setEnabled(false);
120 }
121 }
122
enableIgnoreButtons()123 void Prefs_Hyphenator::enableIgnoreButtons()
124 {
125 ignoreEditButton->setEnabled(true);
126 ignoreRemoveButton->setEnabled(true);
127 }
128
addToExceptList()129 void Prefs_Hyphenator::addToExceptList()
130 {
131 bool ok;
132 QString text = QInputDialog::getText(this, tr("Exception List"), tr("Add a new Entry"), QLineEdit::Normal, "", &ok);
133 if ((ok) && (!text.isEmpty()))
134 {
135 if (exceptionListWidget->findItems(text, Qt::MatchExactly).count() == 0)
136 exceptionListWidget->addItem(text);
137 exceptionListWidget->sortItems();
138 }
139 }
140
editExceptListEntry()141 void Prefs_Hyphenator::editExceptListEntry()
142 {
143 bool ok;
144 QString text = QInputDialog::getText(this, tr("Exception List"), tr("Edit Entry"), QLineEdit::Normal, exceptionListWidget->currentItem()->text(), &ok);
145 if ((ok) && (!text.isEmpty()))
146 {
147 if (exceptionListWidget->findItems(text, Qt::MatchExactly).count() == 0)
148 exceptionListWidget->currentItem()->setText(text);
149 exceptionListWidget->sortItems();
150 }
151 }
152
removeExceptListEntry()153 void Prefs_Hyphenator::removeExceptListEntry()
154 {
155 QListWidgetItem *item = exceptionListWidget->takeItem(exceptionListWidget->row(exceptionListWidget->currentItem()));
156 delete item;
157 if (exceptionListWidget->count() == 0)
158 {
159 exceptionEditButton->setEnabled(false);
160 exceptionRemoveButton->setEnabled(false);
161 }
162 }
163
enableExceptButtons()164 void Prefs_Hyphenator::enableExceptButtons()
165 {
166 exceptionEditButton->setEnabled(true);
167 exceptionRemoveButton->setEnabled(true);
168 }
169