settingsdialog.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*****************************************************************************
  2. * settingsdialog.cpp - QStarDict, a dictionary application for learning *
  3. * foreign languages *
  4. * Copyright (C) 2007-2023 Alexander Rodin *
  5. * Copyright (C) 2016 Sergey Il'inykh *
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; either version 2 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * You should have received a copy of the GNU General Public License along *
  18. * with this program; if not, write to the Free Software Foundation, Inc., *
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  20. *****************************************************************************/
  21. #include "settingsdialog.h"
  22. #include <QFileDialog>
  23. #include <QMessageBox>
  24. #include <QStandardItemModel>
  25. #include <QHeaderView>
  26. #include <QInputDialog>
  27. #include <QSettings>
  28. #include <QKeySequence>
  29. #include <math.h>
  30. #include <QStyledItemDelegate>
  31. #include <QPainter>
  32. #include <QTimer>
  33. #include "dictcore.h"
  34. #include "mainwindow.h"
  35. #include "popupwindow.h"
  36. #include "application.h"
  37. #include "speaker.h"
  38. #include "pluginsmodel.h"
  39. #include "pluginmanager.h"
  40. #include "qxt/qxtglobalshortcut.h"
  41. #include "../plugins/dictplugin.h"
  42. #include "../plugins/pluginserver.h"
  43. #ifdef QSTARDICT_WITH_TRAY_ICON
  44. #include "trayicon.h"
  45. #endif
  46. namespace
  47. {
  48. int toPercents(double value)
  49. {
  50. int integralValue = static_cast<int>(value * 100.0);
  51. if (value * 100.0 - 0.5 > integralValue)
  52. ++integralValue;
  53. return integralValue;
  54. }
  55. QString getModifierName(int key)
  56. {
  57. switch (key)
  58. {
  59. case Qt::ShiftModifier:
  60. return "Shift";
  61. case Qt::ControlModifier:
  62. #ifdef Q_OS_MAC
  63. return "Command";
  64. #else
  65. return "Control";
  66. #endif
  67. case Qt::AltModifier:
  68. #ifdef Q_OS_MAC
  69. return "Option";
  70. #else
  71. return "Alt";
  72. #endif
  73. case Qt::MetaModifier:
  74. #ifdef Q_OS_MAC
  75. return "Control";
  76. #elif Q_OS_WIN
  77. return "Win";
  78. #else
  79. return "Super";
  80. #endif
  81. default:
  82. return "";
  83. }
  84. }
  85. void initModifierComboBox(QComboBox *box, int selectedKey)
  86. {
  87. box->clear();
  88. box->addItem(getModifierName(Qt::AltModifier), Qt::AltModifier);
  89. box->addItem(getModifierName(Qt::ShiftModifier), Qt::ShiftModifier);
  90. box->addItem(getModifierName(Qt::ControlModifier), Qt::ControlModifier);
  91. box->addItem(getModifierName(Qt::MetaModifier), Qt::MetaModifier);
  92. box->setCurrentIndex(qMax(0, box->findData(selectedKey)));
  93. }
  94. }
  95. namespace QStarDict {
  96. SettingsDialog::SettingsDialog(QWidget *parent)
  97. : QDialog(parent)
  98. {
  99. setupUi(this);
  100. Application * const app = Application::instance();
  101. DictCore *dict = app->dictCore();
  102. m_oldPlugins = app->pluginManager()->loadedPlugins();
  103. m_oldDicts = dict->loadedDicts();
  104. m_dictPluginsModel = new PluginsModel(PluginsModel::LoadType::JustDict, app->pluginManager());
  105. m_miscPluginsModel = new PluginsModel(PluginsModel::LoadType::ExceptDict, app->pluginManager());
  106. pluginsTableView->setModel(m_dictPluginsModel);
  107. miscPluginsView->setModel(m_miscPluginsModel);
  108. pluginsTableView->configureColumns();
  109. miscPluginsView->configureColumns();
  110. m_dictsModel = new QStandardItemModel(this);
  111. m_dictsModel->setHorizontalHeaderLabels(QStringList() << tr("Enabled") << tr("Name") << tr("Plugin"));
  112. loadDictsList();
  113. dictsTableView->setModel(m_dictsModel);
  114. dictsTableView->verticalHeader()->hide();
  115. dictsTableView->setColumnWidth(0, 60);
  116. dictsTableView->setColumnWidth(1, 270);
  117. dictsTableView->setColumnWidth(2, 120);
  118. // Load global settings
  119. runInBackgroundBox->setChecked(!app->mainWindow()->quitOnClose());
  120. instantSearchBox->setChecked(app->mainWindow()->isInstantSearch());
  121. speechCmdEdit->setText(app->speaker()->speechCmd());
  122. #ifdef Q_OS_LINUX
  123. QFile desktop(QDir::homePath() + "/.config/autostart/qstardict.desktop");
  124. if (desktop.open(QIODevice::ReadOnly) && QString(desktop.readAll())
  125. .contains(QRegExp("\\bhidden\\s*=\\s*false", Qt::CaseInsensitive))) {
  126. autostartBox->setChecked(true);
  127. }
  128. #elif defined(Q_OS_WIN)
  129. QSettings reg("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\"
  130. "CurrentVersion\\Run", QSettings::NativeFormat);
  131. autostartBox->setChecked(
  132. reg.contains(QCoreApplication::applicationName()));
  133. #else
  134. autostartBox->setVisible(false);
  135. #endif
  136. linksBox->setChecked(app->mainWindow()->showLinks());
  137. linksModifierBox->setChecked(app->mainWindow()->showLinksModifierKey() != 0);
  138. initModifierComboBox(linksModifierKeyBox, app->mainWindow()->showLinksModifierKey());
  139. ipaPronounceBox->setChecked(app->mainWindow()->showIpaPronouncers());
  140. espeakCmdEdit->setText(app->espeakSpeaker()->speechCmd());
  141. // Load popup shortcut settings
  142. shortcutPopupEdit->setText(app->popupShortcut()->shortcut().toString());
  143. shortcutPopupBox->setChecked(app->popupShortcut()->isEnabled());
  144. switchScanningEdit->setText(app->switchScanningShortcut()->shortcut().toString());
  145. switchScanningBox->setChecked(app->switchScanningShortcut()->isEnabled());
  146. // Load popup window settings
  147. PopupWindow *popup = app->popupWindow();
  148. useScanBox->setChecked(popup->isScan());
  149. useScanModifierBox->setChecked(popup->modifierKey() != 0);
  150. initModifierComboBox(modifierKeyBox, popup->modifierKey());
  151. showIfNotFoundBox->setChecked(popup->showIfNotFound());
  152. popupOpacitySpin->setValue(toPercents(popup->windowOpacity()));
  153. timeoutBeforeHideSpin->setValue(popup->timeoutBeforeHide() / 1000.0);
  154. popupDefaultWidthSpin->setValue(popup->defaultSize().width());
  155. popupDefaultHeightSpin->setValue(popup->defaultSize().height());
  156. pronounceWordBox->setChecked(popup->pronounceWord());
  157. // Load translations CSS
  158. QVector<QPair<QString, QString>> cssAliases;
  159. cssAliases.append({"body", tr("All translation")});
  160. cssAliases.append({"font.dict_name", tr("Dictionary name")});
  161. cssAliases.append({"font.title", tr("Title")});
  162. cssAliases.append({"font.transcription", tr("Transcription")});
  163. cssAliases.append({"font.explanation", tr("Explanation")});
  164. cssAliases.append({"font.abbreviature", tr("Abbreviation")});
  165. cssAliases.append({"font.example", tr("Example")});
  166. appearanceCSSEdit->setElementsNames(cssAliases);
  167. appearanceCSSEdit->setCSS(app->mainWindow()->defaultStyleSheet());
  168. connect(m_dictPluginsModel, SIGNAL(loadedListChanged()),
  169. SLOT(dictLoadedPluginsChanged()));
  170. connect(pluginsTableView, SIGNAL(clicked(QModelIndex)), SLOT(pluginClicked(QModelIndex)));
  171. connect(miscPluginsView, SIGNAL(clicked(QModelIndex)), SLOT(pluginClicked(QModelIndex)));
  172. connect(dictsTableView, SIGNAL(clicked(QModelIndex)), SLOT(dictSelected()));
  173. // There is no signal emitted when an dictionary item is selected using keyboard,
  174. // not mouse. So it is necessary check whether the item selection changed or not
  175. // periodically.
  176. m_dictsTimer = new QTimer(this);
  177. m_dictsTimer->setInterval(100);
  178. connect(m_dictsTimer, SIGNAL(timeout()), SLOT(dictSelected()));
  179. m_dictsTimer->start();
  180. linksModifierContainer->setEnabled(linksBox->isChecked());
  181. linksModifierKeyBox->setEnabled(linksModifierBox->isChecked());
  182. espeakCmdLabel->setEnabled(ipaPronounceBox->isChecked());
  183. espeakCmdEdit->setEnabled(ipaPronounceBox->isChecked());
  184. scanModifierContainer->setEnabled(useScanBox->isChecked());
  185. modifierKeyBox->setEnabled(useScanModifierBox->isChecked());
  186. shortcutPopupEdit->setEnabled(shortcutPopupBox->isChecked());
  187. switchScanningEdit->setEnabled(switchScanningBox->isChecked());
  188. }
  189. void SettingsDialog::accept()
  190. {
  191. Application * const app = Application::instance();
  192. // Save dicts and plugins settings
  193. DictCore *dict = app->dictCore();
  194. //dict->setLoadedPlugins(m_dictPluginsModel->loadedPlugins() + m_miscPluginsModel->loadedPlugins());
  195. QList<DictCore::Dictionary> loadedDicts;
  196. int rowCount = m_dictsModel->rowCount();
  197. for (int i = 0; i < rowCount; ++i)
  198. if (m_dictsModel->item(i, 0)->checkState() == Qt::Checked)
  199. loadedDicts << DictCore::Dictionary(m_dictsModel->item(i, 2)->text(), m_dictsModel->item(i, 1)->text());
  200. dict->setLoadedDicts(loadedDicts);
  201. // Save global settings
  202. app->mainWindow()->setQuitOnClose(!runInBackgroundBox->isChecked());
  203. #ifdef QSTARDICT_WITH_TRAY_ICON
  204. app->trayIcon()->setVisible(runInBackgroundBox->isChecked());
  205. #endif
  206. app->mainWindow()->setInstantSearch(instantSearchBox->isChecked());
  207. app->speaker()->setSpeechCmd(speechCmdEdit->text());
  208. #ifdef Q_OS_LINUX
  209. QDir home = QDir::home();
  210. if (!home.exists(".config/autostart")) {
  211. home.mkpath(".config/autostart");
  212. }
  213. QFile desktopFile(QSTARDICT_INSTALL_PREFIX "/share/applications/qstardict.desktop");
  214. if (desktopFile.open(QIODevice::ReadOnly)) {
  215. QByteArray contents = desktopFile.readAll();
  216. QFile f(home.absolutePath() +
  217. "/.config/autostart/qstardict.desktop");
  218. if (f.open(QIODevice::WriteOnly | QIODevice::Text)) {
  219. f.write(contents.trimmed());
  220. f.write(QString("\nHidden=%1").arg(autostartBox->isChecked()?
  221. "false\n":"true\n").toUtf8());
  222. }
  223. }
  224. #elif defined(Q_OS_WIN)
  225. QSettings reg("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\"
  226. "CurrentVersion\\Run", QSettings::NativeFormat);
  227. if(autostartBox->isChecked())
  228. reg.setValue(QCoreApplication::applicationName(), '"' +
  229. QDir::toNativeSeparators(QCoreApplication::
  230. applicationFilePath()) + '"');
  231. else
  232. reg.remove(QCoreApplication::applicationName());
  233. #endif
  234. app->mainWindow()->setShowLinks(linksBox->isChecked());
  235. app->popupWindow()->setShowLinks(linksBox->isChecked());
  236. int linksModifierKey = linksModifierBox->isChecked() ? linksModifierKeyBox->currentData().toInt() : 0;
  237. app->mainWindow()->setShowLinksModifierKey(linksModifierKey);
  238. app->popupWindow()->setShowLinksModifierKey(linksModifierKey);
  239. app->mainWindow()->setShowIpaPronouncers(ipaPronounceBox->isChecked());
  240. app->popupWindow()->setShowIpaPronouncers(ipaPronounceBox->isChecked());
  241. app->espeakSpeaker()->setSpeechCmd(espeakCmdEdit->text());
  242. // Save popup shortcut settings
  243. app->popupShortcut()->setShortcut(QKeySequence(shortcutPopupEdit->text()));
  244. app->popupShortcut()->setEnabled(shortcutPopupBox->isChecked());
  245. app->switchScanningShortcut()->setShortcut(QKeySequence(switchScanningEdit->text()));
  246. app->switchScanningShortcut()->setEnabled(switchScanningBox->isChecked());
  247. // Save popup window settings
  248. PopupWindow *popup = app->popupWindow();
  249. popup->setScan(useScanBox->isChecked());
  250. popup->setShowIfNotFound(showIfNotFoundBox->isChecked());
  251. if (useScanModifierBox->isChecked())
  252. popup->setModifierKey(modifierKeyBox->currentData().toInt());
  253. else
  254. popup->setModifierKey(0);
  255. popup->setWindowOpacity(popupOpacitySpin->value() / 100.0);
  256. popup->setTimeoutBeforeHide(static_cast<int>(timeoutBeforeHideSpin->value() * 1000.0));
  257. popup->setDefaultSize(QSize(popupDefaultWidthSpin->value(), popupDefaultHeightSpin->value()));
  258. popup->setPronounceWord(pronounceWordBox->isChecked());
  259. // Save translations CSS
  260. app->mainWindow()->setDefaultStyleSheet(appearanceCSSEdit->css());
  261. app->popupWindow()->setDefaultStyleSheet(appearanceCSSEdit->css());
  262. if (app->mainWindow()->quitOnClose())
  263. app->mainWindow()->show();
  264. app->mainWindow()->reload();
  265. app->mainWindow()->reloadToolbar();
  266. app->popupWindow()->reloadToolbar();
  267. app->dictCore()->saveSettings();
  268. app->mainWindow()->saveSettings();
  269. #ifdef QSTARDICT_WITH_TRAY_ICON
  270. app->trayIcon()->saveSettings();
  271. #endif
  272. app->popupWindow()->saveSettings();
  273. QDialog::accept();
  274. }
  275. void SettingsDialog::reject()
  276. {
  277. DictCore *dict = Application::instance()->dictCore();
  278. Application::instance()->pluginManager()->setLoadedPlugins(m_oldPlugins);
  279. dict->setLoadedDicts(m_oldDicts);
  280. QDialog::reject();
  281. }
  282. void SettingsDialog::loadDictsList()
  283. {
  284. int i;
  285. QList<DictCore::Dictionary> loadedDicts = Application::instance()->dictCore()->loadedDicts();
  286. m_dictsModel->setRowCount(0);
  287. for (i = 0; i < loadedDicts.size(); ++i)
  288. {
  289. QStandardItem *item = new QStandardItem();
  290. item->setCheckable(true);
  291. item->setCheckState(Qt::Checked);
  292. m_dictsModel->setItem(i, 0, item);
  293. m_dictsModel->setItem(i, 1, new QStandardItem(loadedDicts[i].name()));
  294. m_dictsModel->setItem(i, 2, new QStandardItem(loadedDicts[i].plugin()));
  295. }
  296. QList<DictCore::Dictionary> dicts = Application::instance()->dictCore()->availableDicts();
  297. for (QList<DictCore::Dictionary>::const_iterator iter = dicts.begin(); iter != dicts.end(); ++iter)
  298. {
  299. if (! loadedDicts.contains(*iter))
  300. {
  301. QStandardItem *item = new QStandardItem();
  302. item->setCheckable(true);
  303. item->setCheckState(Qt::Unchecked);
  304. m_dictsModel->setItem(i, 0, item);
  305. m_dictsModel->setItem(i, 1, new QStandardItem(iter->name()));
  306. m_dictsModel->setItem(i, 2, new QStandardItem(iter->plugin()));
  307. ++i;
  308. }
  309. }
  310. dictSelected();
  311. }
  312. void SettingsDialog::dictSelected()
  313. {
  314. int currentRow = dictsTableView->currentIndex().row();
  315. if (currentRow == -1)
  316. {
  317. dictsMoveUpButton->setEnabled(false);
  318. dictsMoveDownButton->setEnabled(false);
  319. dictsRemoveButton->setEnabled(false);
  320. dictsShowInfoButton->setEnabled(false);
  321. }
  322. else
  323. {
  324. dictsMoveUpButton->setEnabled(currentRow > 0);
  325. dictsMoveDownButton->setEnabled(currentRow < m_dictsModel->rowCount() - 1);
  326. QString dict = m_dictsModel->item(currentRow, 1)->text();
  327. QString pluginName = m_dictsModel->item(currentRow, 2)->text();
  328. DictPlugin *plugin = Application::instance()->pluginManager()->plugin<DictPlugin>(pluginName);
  329. dictsRemoveButton->setEnabled(plugin->isDictionaryRemovable(dict));
  330. dictsShowInfoButton->setEnabled(true);
  331. }
  332. }
  333. void SettingsDialog::on_dictsMoveUpButton_clicked()
  334. {
  335. int currentRow = dictsTableView->currentIndex().row();
  336. if (currentRow > 0)
  337. {
  338. m_dictsModel->insertRow(currentRow - 1, m_dictsModel->takeRow(currentRow));
  339. dictsTableView->selectRow(currentRow - 1);
  340. }
  341. }
  342. void SettingsDialog::on_dictsMoveDownButton_clicked()
  343. {
  344. int currentRow = dictsTableView->currentIndex().row();
  345. if (currentRow < m_dictsModel->rowCount() - 1)
  346. {
  347. m_dictsModel->insertRow(currentRow + 1, m_dictsModel->takeRow(currentRow));
  348. dictsTableView->selectRow(currentRow + 1);
  349. }
  350. }
  351. void SettingsDialog::on_dictsShowInfoButton_clicked()
  352. {
  353. int currentRow = dictsTableView->currentIndex().row();
  354. if (currentRow == -1)
  355. return;
  356. QString dict = m_dictsModel->item(currentRow, 1)->text();
  357. QString plugin = m_dictsModel->item(currentRow, 2)->text();
  358. DictPlugin::DictInfo info = Application::instance()->pluginManager()->plugin<DictPlugin>(plugin)->dictInfo(dict);
  359. QMessageBox::information(this,
  360. tr("Information about dictionary \"%1\"").arg(dict),
  361. tr("<b>Name:</b> %1<br>").arg(dict) +
  362. tr("<b>Plugin:</b> %1<br>").arg(plugin) +
  363. (info.filename().isEmpty() ? "" : tr("<b>Filename:</b> %1<br>").arg(info.filename())) +
  364. tr("<b>Author:</b> %1<br>").arg(info.author()) +
  365. tr("<b>Words count:</b> %1<br>").arg((info.wordsCount() == -1) ? tr("unknown") : QString::number(info.wordsCount())) +
  366. (info.description().isEmpty() ? "" : tr("<b>Description:</b> %1").arg(info.description())));
  367. }
  368. void SettingsDialog::pluginClicked(const QModelIndex &index)
  369. {
  370. QString id = index.data(PluginsModel::IdRole).toString();
  371. if (index.column() == 2) {// settings
  372. auto plugin = Application::instance()->pluginManager()->plugin<ConfigurablePlugin>(id);
  373. if (plugin && plugin->execSettingsDialog(this) == QDialog::Accepted)
  374. {
  375. Application::instance()->dictCore()->reloadDicts();
  376. loadDictsList();
  377. }
  378. }
  379. if (index.column() == 3) {
  380. auto pm = Application::instance()->pluginManager();
  381. DictPlugin *dplugin = pm->plugin<DictPlugin>(id);
  382. const PluginMetadata &md = pm->pluginDesc(id)->metadata;
  383. QStringList authors = md.authors;
  384. auto *messageBox = new QMessageBox(this);
  385. messageBox->setIconPixmap(md.icon.pixmap(QSize(128, 128)));
  386. messageBox->setWindowTitle(tr("Information about %1 plugin").arg(md.name));
  387. messageBox->setText(
  388. tr("<b>Name:</b> %1<br>").arg(md.name) +
  389. tr("<b>Version:</b> %1<br>").arg(md.version) +
  390. tr("<b>Authors:</b> %1<br>").arg(authors.replaceInStrings("<", "&lt;").replaceInStrings(">", "&gt;").join(tr("<br>"))) +
  391. (dplugin? tr("<b>Can search similar words:</b> %1<br>").arg(dplugin->features().testFlag(DictPlugin::Feature::SearchSimilar) ? tr("yes") : tr("no")) : "") +
  392. tr("<b>Description:</b> %1").arg(md.description));
  393. messageBox->show();
  394. }
  395. }
  396. void SettingsDialog::dictLoadedPluginsChanged()
  397. {
  398. DictCore *dict = Application::instance()->dictCore();
  399. Application::instance()->pluginManager()->setLoadedPlugins(m_dictPluginsModel->loadedPlugins() + m_miscPluginsModel->loadedPlugins());
  400. dict->reloadDicts();
  401. loadDictsList();
  402. }
  403. void SettingsDialog::on_dictsAddButton_clicked()
  404. {
  405. auto pluginManager = Application::instance()->pluginManager();
  406. QStringList filters;
  407. QHash<QString, QString> pluginsByFilters;
  408. for (const QString &pluginId: pluginManager->loadedPlugins()) {
  409. DictPlugin *plugin = pluginManager->plugin<DictPlugin>(pluginId);
  410. if (!plugin)
  411. continue;
  412. std::optional<QString> dictionaryFileFilter = plugin->dictionaryFileFilter();
  413. if (!dictionaryFileFilter)
  414. continue;
  415. filters.push_back(*dictionaryFileFilter);
  416. pluginsByFilters[*dictionaryFileFilter] = pluginId;
  417. }
  418. QFileDialog fileDialog(this, tr("Import a dictionary from a file"),
  419. QString(), filters.join(";;"));
  420. if (!fileDialog.exec())
  421. return;
  422. QString selectedPluginId = pluginsByFilters[fileDialog.selectedNameFilter()];
  423. DictPlugin *selectedPlugin = pluginManager->plugin<DictPlugin>(selectedPluginId);
  424. QString selectedFileName = fileDialog.selectedFiles().at(0);
  425. selectedPlugin->loadedDicts();
  426. std::optional<QString> dict = selectedPlugin->addDictionary(this, selectedFileName);
  427. if (!dict)
  428. return;
  429. Application::instance()->dictCore()->reloadDicts();
  430. loadDictsList();
  431. // Move the added dictionary to the top and enable it
  432. for (int i = 0; i < m_dictsModel->rowCount(); ++i)
  433. {
  434. if (m_dictsModel->item(i, 1)->text() == *dict)
  435. {
  436. m_dictsModel->insertRow(0, m_dictsModel->takeRow(i));
  437. m_dictsModel->item(0, 0)->setCheckState(Qt::Checked);
  438. dictsTableView->selectRow(0);
  439. dictSelected();
  440. break;
  441. }
  442. }
  443. }
  444. void SettingsDialog::on_dictsRemoveButton_clicked()
  445. {
  446. int currentRow = dictsTableView->currentIndex().row();
  447. if (currentRow == -1)
  448. return;
  449. QString dict = m_dictsModel->item(currentRow, 1)->text();
  450. QString pluginName = m_dictsModel->item(currentRow, 2)->text();
  451. DictPlugin *plugin = Application::instance()->pluginManager()->plugin<DictPlugin>(pluginName);
  452. if (! plugin->removeDictionary(dict))
  453. {
  454. QMessageBox::warning(this, tr("Unable to remove dictionary"),
  455. tr("Cannot remove dictionary %1 with plugin %1").arg(dict, pluginName));
  456. }
  457. else
  458. {
  459. DictCore *dict = Application::instance()->dictCore();
  460. dict->reloadDicts();
  461. loadDictsList();
  462. }
  463. }
  464. }
  465. // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc