Copyright 2010 Comarch S.A.
*******************************************************************************/
+/*!
+ \file XdxfDialog.cpp
+ \brief Implementation of xdxf plugin's dialogs.
-//Created by Mateusz Półrola
+ \author Mateusz Półrola <mateusz.polrola@gmail.com>
+*/
#include "XdxfDialog.h"
#include <QDebug>
XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
XdxfDialogType type,
QWidget *parent) :
- QDialog(parent) {
+ QDialog(parent) {
+
this->plugin = plugin;
this->type = type;
- initializeUI();
+#ifndef Q_WS_MAEMO_5
+
+ view= new QDeclarativeView();
+ view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/XdxfDialog.qml"));
+ view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+ view->setAlignment(Qt::AlignCenter);
+ view->show();
+
+ mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(view);
+ setLayout(mainLayout);
+ view->setWindowTitle(tr("Xdxf Settings"));
+
+ QGraphicsObject *rootObject = view->rootObject();
+
+ connect(this, SIGNAL(setPlugin(QVariant)),
+ rootObject, SLOT(setPlugin(QVariant)));
+ connect(this, SIGNAL(setFrom(QVariant)),
+ rootObject, SLOT(setFrom(QVariant)));
+ connect(this, SIGNAL(setTo(QVariant)),
+ rootObject, SLOT(setTo(QVariant)));
+ connect(this, SIGNAL(setDescription(QVariant)),
+ rootObject, SLOT(setDescription(QVariant)));
+ connect(this, SIGNAL(setInfo(QVariant)),
+ rootObject, SLOT(setInfo(QVariant)));
+ connect(this, SIGNAL(setCheckedOptimalize(QVariant)),
+ rootObject, SLOT(setCheckedOptimalize(QVariant)));
+ connect(this, SIGNAL(setCheckedStrip(QVariant)),
+ rootObject, SLOT(setCheckedStrip(QVariant)));
+ connect(this,SIGNAL(setButtonText(QVariant)),
+ rootObject, SLOT(setButtonText(QVariant)));
+ connect(this,SIGNAL(setNew(QVariant)),
+ rootObject, SLOT(setNew(QVariant)));
+ connect(this,SIGNAL(setPath(QVariant)),
+ rootObject, SLOT(setPath(QVariant)));
+
+ connect(rootObject, SIGNAL(saveButtonClicked()),
+ this, SLOT(accept()));
+ connect(rootObject, SIGNAL(downloadButtonClicked()),
+ this, SLOT(downloadFile()));
+ connect(rootObject, SIGNAL(browseButtonClicked()),
+ this, SLOT(selectFile()));
+
+ connect(rootObject, SIGNAL(optimalizeCheckboxChanged(bool)),
+ this, SLOT(setGenerateCache(bool)));
+ connect(rootObject, SIGNAL(stripCheckboxChanged(bool)),
+ this, SLOT(setAccents(bool)));
+
+#else
+
+ cacheToolTip = tr("Optimize for quicker searches (may take some time)");
+ accentsToolTip = tr("Strip accents (searching takes more time, but spelling doesn't have to be exact)");
connect(cacheCheckBox, SIGNAL(toggled(bool)),
this, SLOT(setGenerateCache(bool)));
-
connect(accentsCheckBox, SIGNAL(toggled(bool)),
this, SLOT(setAccents(bool)));
- connect(accentsInfoToolButton, SIGNAL(clicked()),
- this, SLOT(showAccentsInfo()));
-
- connect(cacheInfoToolButton, SIGNAL(clicked()),
- this, SLOT(showCacheInfo()));
+ #ifdef Q_WS_MAEMO_5
+ connect(accentsInfoToolButton, SIGNAL(clicked()),
+ this, SLOT(showAccentsInfo()));
+ connect(cacheInfoToolButton, SIGNAL(clicked()),
+ this, SLOT(showCacheInfo()));
+ #endif
if(type == New) {
connect(browseButton, SIGNAL(clicked()),
this, SLOT(selectFile()));
-
- connect(addButton, SIGNAL(clicked()),
- this, SLOT(accept()));
- }
- else {
- connect(saveButton, SIGNAL(clicked()),
- this, SLOT(accept()));
+ connect(downloadButton, SIGNAL(clicked()),
+ this, SLOT(downloadFile()));
+ connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)),
+ this, SLOT(fileDownloaded(QString)));
}
+ connect(confirmButton, SIGNAL(clicked()),
+ this, SLOT(accept()));
+#endif
+ initializeUI();
}
void XdxfDialog::initializeUI() {
+#ifndef Q_WS_MAEMO_5
+
+ if(type != New){
+ emit setNew(false);
+ emit setPlugin(plugin->type().toUpper());
+ emit setFrom(plugin->langFrom());
+ emit setTo(plugin->langTo());
+ emit setDescription(plugin->name());
+ emit setInfo(plugin->infoNote());
+ emit setButtonText("Save settings");
+ }
+ else{
+ emit setButtonText("Add");
+ emit setNew(true);
+ connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)),
+ this, SLOT(fileDownloaded(QString)));
+ }
+
+ if(!plugin) {
+ emit setCheckedOptimalize(true);
+ emit setCheckedStrip(true);
+// accentsCheckBox->setEnabled(false);
+ _generateCache = true;
+ _accents = true;
+ _dictionaryFilePath = "";
+ }
+ else if(plugin && plugin->settings()->value("cached") == "true") {
+ emit setCheckedOptimalize(true);
+ emit setCheckedStrip(true);
+// accentsCheckBox->setEnabled(false);
+ _generateCache = true;
+ _accents = true;
+ }
+ else {
+ emit setCheckedOptimalize(false);
+ _generateCache = false;
+ if(plugin->settings()->value("strip_accents") == "true") {
+ emit setCheckedStrip(true);
+ _accents = true;
+ }
+ else {
+ emit setCheckedStrip(false);
+ _accents = false;
+ }
+ }
+
+#else
mainVerticalLayout = new QVBoxLayout;
widget = new QWidget;
widget->setLayout(mainVerticalLayout);
+ infoLabel = new QLabel;
+ infoLabel->setWordWrap(true);
+
if(type == New) {
setWindowTitle(tr("Add new XDXF dictionary"));
-
browseLayout = new QHBoxLayout;
+
+ QVBoxLayout* buttonLayout = new QVBoxLayout;
browseButton = new QPushButton(tr("Browse"));
- browseLabel = new QLabel(tr("Dictionary file: not selected"));
+ browseButton->setMaximumWidth(150);
+
+ downloadButton = new QPushButton(tr("Download"));
+ downloadButton->setMaximumWidth(150);
- browseLayout->addWidget(browseLabel, 0, Qt::AlignLeft);
- browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
+ infoLayout = new QHBoxLayout;
+ infoLabel->setText(tr("Dictionary file: not selected"));
+
+ browseLayout->addWidget(infoLabel,0,Qt::AlignLeft);
+ browseLayout->addLayout(buttonLayout);
+ buttonLayout->addWidget(browseButton,0,Qt::AlignLeft);
+ buttonLayout->addWidget(downloadButton,0,Qt::AlignLeft);
mainVerticalLayout->addLayout(browseLayout);
}
else {
setWindowTitle(tr("XDXF Settings"));
-
- infoLabel = new QLabel;
-
infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
tr("From: ") + plugin->langFrom() + "\n" +
tr("To: ") + plugin->langTo() + "\n" +
tr("Description: ") + plugin->name() + "\n" +
- tr("License: ") + plugin->infoNote());
- infoLabel->setWordWrap(true);
+ plugin->infoNote());
mainVerticalLayout->addWidget(infoLabel);
}
- accentsCheckBox = new QCheckBox(tr("Strip accents"));
- accentsInfoToolButton = new QToolButton;
- accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
-
accentsLayout = new QHBoxLayout;
- accentsLayout->addWidget(accentsCheckBox);
- accentsLayout->addWidget(accentsInfoToolButton);
-
-
- cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches"));
- cacheInfoToolButton = new QToolButton;
- cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
+ accentsCheckBox = new QCheckBox(tr("Strip accents"));
+ accentsCheckBox->setToolTip(accentsToolTip);
+ accentsLayout->addWidget(accentsCheckBox);
+ #ifdef Q_WS_MAEMO_5
+ accentsInfoToolButton = new QToolButton;
+ accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
+ accentsLayout->addWidget(accentsInfoToolButton);
+ #endif
cacheLayout = new QHBoxLayout;
+ cacheCheckBox = new QCheckBox(tr("Optimize"));
+ cacheCheckBox->setToolTip(cacheToolTip);
cacheLayout->addWidget(cacheCheckBox);
- cacheLayout->addWidget(cacheInfoToolButton);
+
+ #ifdef Q_WS_MAEMO_5
+ cacheInfoToolButton = new QToolButton;
+ cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
+ cacheLayout->addWidget(cacheInfoToolButton);
+ #endif
mainVerticalLayout->addLayout(cacheLayout);
mainVerticalLayout->addLayout(accentsLayout);
-
//load old setting if exists
if(!plugin) {
cacheCheckBox->setChecked(true);
}
}
- if(type == New) {
- addButton = new QPushButton(tr("Add"));
- mainVerticalLayout->addWidget(addButton);
- }
- else {
- saveButton = new QPushButton(tr("Save settings"));
- mainVerticalLayout->addWidget(saveButton);
- }
+ confirmButton = new QPushButton;
+ mainVerticalLayout->addWidget(confirmButton);
+ if(type == New)
+ confirmButton->setText(tr("Add"));
+ else
+ confirmButton->setText(tr("Save settings"));
scrollArea = new QScrollArea;
scrollArea->setWidget(widget);
scrollArea->setWidgetResizable(true);
- scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ #ifdef Q_WS_MAEMO_5
+ scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ #else
+ if(type==New) {
+ infoLabel->setMinimumWidth(250);
+ scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ }
+ #endif
layout = new QHBoxLayout;
layout->addWidget(scrollArea);
setLayout(layout);
+
+ #ifndef Q_WS_MAEMO_5
+ setMinimumSize(385,200);
+ #else
+ setMinimumHeight(350);
+ #endif
+
+ scrollArea->setLineWidth(0);
+ scrollArea->setMidLineWidth(0);
+ scrollArea->setFrameStyle(QFrame::NoFrame);
+#endif
}
_accents = accents;
}
+
void XdxfDialog::setGenerateCache(bool generate) {
_generateCache = generate;
-
+#ifndef Q_WS_MAEMO_5
+ if(generate) {
+ _lastAccents = _accents;
+ emit setCheckedOptimalize(true);
+ emit setCheckedStrip(true);
+ }
+ else{
+ emit setCheckedStrip(_lastAccents);
+ }
+// accentsCheckBox->setEnabled(!generate);
+#else
if(generate) {
_lastAccents = _accents;
accentsCheckBox->setChecked(true);
}
else
accentsCheckBox->setChecked(_lastAccents);
-
accentsCheckBox->setEnabled(!generate);
+#endif
}
+
void XdxfDialog::selectFile() {
QString fileName = QFileDialog::getOpenFileName(this,
tr("Select dictionary file"),
tr("XDXF Files (*.xdxf)"),
NULL,
NULL);
-
if (!fileName.isEmpty()) {
- browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
_dictionaryFilePath = fileName;
+ #ifndef Q_WS_MAEMO_5
+ emit setPath(tr("Dictionary file: %1").arg(fileName));
+ #else
+ infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
+ updateGeometry();
+ #endif
}
}
+
+void XdxfDialog::fileDownloaded(QString) {
+#ifndef Q_WS_MAEMO_5
+ emit setPath(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
+ _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
+#else
+ infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
+ _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
+ updateGeometry();
+#endif
+}
+
+
+void XdxfDialog::downloadFile() {
+ XdxfPlugin::dictDownloader.download(this);
+}
+
+
void XdxfDialog::saveSettings() {
_settings = new Settings;
if(plugin) {
foreach(QString key, plugin->settings()->keys())
_settings->setValue(key, plugin->settings()->value(key));
}
- else {
+ else
_settings->setValue("path", _dictionaryFilePath);
- }
-
if(_generateCache)
_settings->setValue("generateCache", "true");
else
_settings->setValue("strip_accents", "false");
}
+
void XdxfDialog::accept() {
if(type == New && _dictionaryFilePath.isEmpty()) {
Q_EMIT notify(Notify::Warning, tr("File path is not set"));
-
return;
}
QDialog::accept();
}
+
Settings* XdxfDialog::getSettings() {
return _settings;
}
-void XdxfDialog::showCacheInfo() {
- Q_EMIT notify(Notify::Warning, tr("Optimize for quicker searches (may take some time)"));
-}
-void XdxfDialog::showAccentsInfo() {
- Q_EMIT notify(Notify::Warning, tr("Strip accents (searching takes more "
- "time, but spelling don't have to be exact)"));
-}
+#ifdef Q_WS_MAEMO_5
+ void XdxfDialog::showCacheInfo() {
+ Q_EMIT notify(Notify::Warning, cacheToolTip);
+ }
+
+
+ void XdxfDialog::showAccentsInfo() {
+ Q_EMIT notify(Notify::Warning, accentsToolTip);
+ }
+#endif