--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file GoogleSettingsDialog.cpp
+ \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
+*/
+
+#include "GoogleDialog.h"
+#include <QDebug>
+
+GoogleDialog::GoogleDialog(GooglePlugin *plugin,
+ GoogleDialogType type,
+ QWidget *parent) : QDialog(parent) {
+ this->plugin = plugin;
+ this->type = type;
+ _settings = 0;
+
+ if(plugin) {
+ _langTo=GooglePlugin::languages.key(
+ plugin->settings()->value("lang_to"));
+
+ _langFrom=GooglePlugin::languages.key(
+ plugin->settings()->value("lang_from"));
+ }
+ else {
+ _langTo=GooglePlugin::languages.key("pl");
+ _langFrom=GooglePlugin::languages.key("en");
+ }
+
+
+
+ initializeUI();
+
+ connect(confirmButton, SIGNAL(clicked()),
+ this, SLOT(accept()));
+
+ connect(langFromComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(langFromChanged(int)));
+
+ connect(langToComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(langToChanged(int)));
+
+ connect(changeLangButton, SIGNAL(clicked()),
+ this, SLOT(changeLangButtonClicked()));
+}
+
+
+void GoogleDialog::initializeUI() {
+ setWindowTitle(tr("Google Plugin Settings"));
+
+ langFromLabel = new QLabel(tr("From:"));
+ langToLabel = new QLabel(tr("To: "));
+
+ verticalLayout = new QVBoxLayout;
+ setLayout(verticalLayout);
+
+
+ langLayout = new QVBoxLayout;
+ langFromLayout = new QHBoxLayout;
+ langToLayout = new QHBoxLayout;
+ changeLangLayout = new QHBoxLayout;
+
+
+ #ifdef Q_WS_MAEMO_5
+ setMinimumHeight(370);
+ changeLangButton=new QPushButton(
+ QIcon::fromTheme("general_refresh"), "");
+ #else
+ changeLangButton=new QPushButton(
+ QIcon::fromTheme("object-flip-vertical"),"");
+ #endif
+
+ infoLabel = new QLabel;
+ infoLabel->setText(tr("Plugin: GoogleTranslator \n")+
+ tr("From: ") + _langFrom + "\n" +
+ tr("To: ") + _langTo);
+ verticalLayout->addWidget(infoLabel);
+
+
+ #ifdef Q_WS_MAEMO_5
+ connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet " "connection, so it may cost You."));
+ connectInfoLabel->setWordWrap(true);
+
+ verticalLayout->addWidget(connectInfoLabel);
+ #endif
+
+ langFromComboBox = new QComboBox;
+ langToComboBox = new QComboBox;
+
+ int i=0;
+ int actualLangTo=0;
+ int actualLangFrom=0;
+
+ foreach(QString langs, GooglePlugin::languages.keys()){
+ if(langs==_langTo)
+ actualLangTo=i;
+ if(langs==_langFrom)
+ actualLangFrom=i;
+ langToComboBox->addItem(langs);
+ langFromComboBox->addItem(langs);
+ i++;
+ }
+
+ langToComboBox->setCurrentIndex(actualLangTo);
+ langFromComboBox->setCurrentIndex(actualLangFrom);
+
+ langFromLayout->addWidget(langFromLabel);
+ langFromLayout->addWidget(langFromComboBox);
+
+ langToLayout->addWidget(langToLabel);
+ langToLayout->addWidget(langToComboBox);
+
+ langLayout->addLayout(langFromLayout);
+ langLayout->addLayout(langToLayout);
+
+ changeLangLayout->addLayout(langLayout);
+ changeLangLayout->addWidget(changeLangButton);
+
+ verticalLayout->addLayout(changeLangLayout);
+
+ confirmButton = new QPushButton;
+ if(type == New) {
+ confirmButton->setText(tr("Add"));
+ }
+ else {
+ confirmButton->setText(tr("Save settings"));
+ }
+
+ verticalLayout->addWidget(confirmButton);
+
+ setModal(true);
+}
+
+void GoogleDialog::langFromChanged(int index) {
+ _langFrom=langFromComboBox->itemText(index);
+}
+
+void GoogleDialog::langToChanged(int index) {
+ _langTo=langToComboBox->itemText(index);
+}
+
+void GoogleDialog::changeLangButtonClicked() {
+ int tempIndexTo=langToComboBox->currentIndex();
+ QString tempLangTo=_langTo;
+
+ langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
+ langFromComboBox->setCurrentIndex(tempIndexTo);
+
+ _langTo=_langFrom;
+ _langFrom=tempLangTo;
+}
+
+void GoogleDialog::accept() {
+ saveSettings();
+
+ QDialog::accept();
+}
+
+void GoogleDialog::saveSettings() {
+ _settings = new Settings;
+ if(plugin) {
+ foreach(QString key, plugin->settings()->keys())
+ _settings->setValue(key, plugin->settings()->value(key));
+ }
+
+ _settings->setValue("lang_to",
+ GooglePlugin::languages.value(_langTo));
+ _settings->setValue("lang_from",
+ GooglePlugin::languages.value(_langFrom));
+}
+
+Settings* GoogleDialog::getSettings() {
+ return _settings;
+}
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file GoogleDialog.cpp
+ \author Mateusz Półrola <mateusz.polrola@gmail.com>
+ \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
+*/
+
+#ifndef GOOGLEDIALOG_H
+#define GOOGLEDIALOG_H
+
+#include <QDialog>
+#include "../../include/settings.h"
+#include <QtGui>
+#include "GooglePlugin.h"
+
+//! Implementation of google plugin's dialogs.
+/*!
+ This class can create dialogs for adding new dictionary or changins settings
+ of existing one, based on dialog type passed to contructor.
+ These type are different only in confirm button label.
+ Both provides comboboxes with availaible languages to choose.
+*/
+class GoogleDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ /*!
+ Describes type of dialog. New means that dialog confirm button has label
+ Add", Change means dialog confirm button has label "Save settings"
+ */
+ enum GoogleDialogType {New, Change};
+
+ //! Constructor
+ /*!
+ Creates new google dialog
+ \param plugin if creating dialog of type Change it must be set to
+ pointer of plugin whose settings will be changed
+ \param type describes type of creating dialog
+ \param parent parent widget of creating dialog
+ */
+ explicit GoogleDialog(GooglePlugin* plugin = 0,
+ GoogleDialogType type = New,
+ QWidget* parent = 0);
+
+
+ //! Returns settings of plugin
+ /*!
+ After acceptance of dialog this method return plugin's settings based on
+ user choises in dialog.
+ */
+ Settings* getSettings();
+
+Q_SIGNALS:
+ //! Request to show notification
+ void notify(Notify::NotifyType, QString);
+
+public Q_SLOTS:
+ //! Reimplemented accept method, to save new settings
+ void accept();
+
+private Q_SLOTS:
+ //! assigns the language chosen from a list(langFromComboBox) to _langFrom
+ void langFromChanged(int);
+
+ //! assigns the language chosen from a list(langToComboBox) to _langTo
+ void langToChanged(int);
+
+ //! handles the "swap languages" button
+ void changeLangButtonClicked();
+
+private:
+ void initializeUI();
+
+ //! saves new settings after acceptance of dialog
+ void saveSettings();
+
+ QLabel* infoLabel;
+ QLabel* langFromLabel;
+ QLabel* langToLabel;
+ QLabel* connectInfoLabel;
+ QPushButton* confirmButton;
+ QPushButton* changeLangButton;
+ QComboBox *langFromComboBox;
+ QComboBox *langToComboBox;
+ QVBoxLayout* verticalLayout;
+ QVBoxLayout* langLayout;
+ QHBoxLayout* langFromLayout;
+ QHBoxLayout* langToLayout;
+ QHBoxLayout* changeLangLayout;
+ QString _langFrom;
+ QString _langTo;
+
+ Settings* _settings;
+ GooglePlugin* plugin;
+ GoogleDialogType type;
+};
+
+#endif // GOOGLEDIALOG_H
*/
#include "GoogleDictDialog.h"
+#include "GoogleDialog.h"
GoogleDictDialog::GoogleDictDialog(GooglePlugin *plugin, QObject *parent) :
DictDialog(parent) {
}
Settings* GoogleDictDialog::addNewDictionary(QWidget *parent) {
- return GoogleSettingsDialog::getSettings(parent);
+ GoogleDialog d(0, GoogleDialog::New, parent);
+
+ connect(&d, SIGNAL(notify(Notify::NotifyType,QString)),
+ this, SIGNAL(notify(Notify::NotifyType,QString)));
+
+ if(d.exec() == QDialog::Accepted) {
+ return d.getSettings();
+ }
+
+ return 0;
}
void GoogleDictDialog::changeSettings(QWidget * parent) {
- GoogleSettingsDialog::changeSettings(plugin,parent);
+ GoogleDialog d(plugin, GoogleDialog::Change, parent);
+
+ connect(&d, SIGNAL(notify(Notify::NotifyType,QString)),
+ this, SIGNAL(notify(Notify::NotifyType,QString)));
+
+ if(d.exec() == QDialog::Accepted) {
+ plugin->setSettings(d.getSettings());
+ }
}
#include "../../include/DictDialog.h"
#include "../../include/settings.h"
#include "GooglePlugin.h"
-#include "GoogleSettingsDialog.h"
class GooglePlugin;
#include <QDebug>
#include "GoogleDictDialog.h"
+QMap<QString, QString> GooglePlugin::languages;
+
GooglePlugin::GooglePlugin(QObject *parent): CommonDictInterface(parent),
_name(""),_infoNote("") {
_settings = new Settings();
_icon = QIcon("/usr/share/mdictionary/google.png");
stopped = false;
- languages=initLanguages();
+ initLanguages();
http = new QHttp(this);
connect(http, SIGNAL(done(bool)), this, SLOT(done()));
void GooglePlugin::retranslate() {
QString locale = QLocale::system().name();
- QTranslator *googleTranslator = new QTranslator(this);
-
- if(locale == "pl_PL")
- googleTranslator->load(":/translations/dict_google_pl");
- else
- googleTranslator->load(":/translations/dict_google_en");
+ QTranslator *translator = new QTranslator(this);
- QCoreApplication::installTranslator(googleTranslator);
+ if(!translator->load(":/translations/" + locale)) {
+ translator->load(":/translations/en_EN");
+ }
+ QCoreApplication::installTranslator(translator);
}
}
-QMap<QString, QString> GooglePlugin::initLanguages() {
- QMap<QString, QString> languages;
+void GooglePlugin::initLanguages() {
+ if(languages.count() != 0) return;
+
languages["Afrikaans"] = "af";
languages["Albanian"] = "sq";
languages["Arabic"] = "ar";
// languages["TONGA"] = "to";
// languages["UZBEK"] = "uz";
// languages["UIGHUR"] = "ug";
- return languages;
}
Translation* getTranslationFor(QString key);
//! initializes the list of available languages in Google translator
- static QMap<QString, QString> initLanguages();
+ static void initLanguages();
+
+ static QMap<QString, QString> languages;
public slots:
/*! performs search in dictionary
void retranslate();
private:
- //! maps languages full names to two-letter acronyms
- QMap<QString, QString> languages;
-
//! name of a dictionary
QString _name;
//! type of a dictionary
+++ /dev/null
-/*******************************************************************************
-
- This file is part of mDictionary.
-
- mDictionary is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- mDictionary is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
-
- Copyright 2010 Comarch S.A.
-
-*******************************************************************************/
-
-/*! \file GoogleSettingsDialog.cpp
- \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
-*/
-
-#include "GoogleSettingsDialog.h"
-#include <QDebug>
-
-GoogleSettingsDialog::GoogleSettingsDialog(QWidget *parent,
- Settings *pluginSettings,
- QString acceptButtonLabel) :
- QDialog(parent)
-{
- QMap<QString, QString> languages;
- languages=GooglePlugin::initLanguages();
-
- int actualLangTo=1;
- int actualLangFrom=1;
-
- if(pluginSettings==0) {
- _langTo=languages.key("pl");
- _langFrom=languages.key("en");
- }
- else {
- _langTo=languages.key(pluginSettings->value("lang_to"));
- _langFrom=languages.key(pluginSettings->value("lang_from"));
- }
-
-
- #ifdef Q_WS_MAEMO_5
- setMinimumHeight(370);
- changeLangButton=new QPushButton(
- QIcon::fromTheme("general_refresh"), "");
- #else
- changeLangButton=new QPushButton(
- QIcon::fromTheme("object-flip-vertical"),tr(""));
- #endif
-
- langFromLabel = new QLabel(tr("From:"));
- langToLabel = new QLabel(tr(" To: "));
-
- setWindowTitle(tr("Google Settings"));
-
- verticalLayout = new QVBoxLayout;
- langLayout = new QVBoxLayout;
- langFromLayout = new QHBoxLayout;
- langToLayout = new QHBoxLayout;
- changelangLayout = new QHBoxLayout;
-
- setLayout(verticalLayout);
-
- infoLabel = new QLabel;
- infoLabel->setText(tr("Plugin: GoogleTranslator \n")+
- tr("From: ") + _langFrom + "\n" +
- tr("To: ") + _langTo);
- verticalLayout->addWidget(infoLabel);
-
-
- #ifdef Q_WS_MAEMO_5
- connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet "
- "connection, so it may cost You."));
- connectInfoLabel->setWordWrap(true);
-
- verticalLayout->addWidget(connectInfoLabel);
- #endif
-
- langFromComboBox = new QComboBox;
- langToComboBox = new QComboBox;
-
- int i=0;
- foreach(QString langs,languages.keys()){
- if(langs==_langTo)
- actualLangTo=i;
- if(langs==_langFrom)
- actualLangFrom=i;
- langToComboBox->addItem(langs);
- langFromComboBox->addItem(langs);
- i++;
- }
- langToComboBox->setCurrentIndex(actualLangTo);
- langFromComboBox->setCurrentIndex(actualLangFrom);
-
-
- langFromLayout->addWidget(langFromLabel);
- langFromLayout->addWidget(langFromComboBox);
- langToLayout->addWidget(langToLabel);
- langToLayout->addWidget(langToComboBox);
-
-
- langLayout->addLayout(langFromLayout);
- langLayout->addLayout(langToLayout);
- changelangLayout->addLayout(langLayout);
- changelangLayout->addWidget(changeLangButton);
- verticalLayout->addLayout(changelangLayout);
-
- saveButton = new QPushButton(acceptButtonLabel);
- verticalLayout->addWidget(saveButton);
-
- setModal(true);
-
- connect(saveButton, SIGNAL(clicked()),
- this, SLOT(accept()));
-
-
- connect(langFromComboBox, SIGNAL(activated(int)),
- this, SLOT(activatedFrom(int)));
- connect(langToComboBox, SIGNAL(activated(int)),
- this, SLOT(activatedTo(int)));
-
-
- connect(changeLangButton, SIGNAL(clicked()),
- this, SLOT(changeLangButtonClicked()));
-}
-
-
-void GoogleSettingsDialog::activatedFrom(int index) {
- _langFrom=langFromComboBox->itemText(index);
-}
-
-void GoogleSettingsDialog::activatedTo(int index) {
- _langTo=langToComboBox->itemText(index);
-}
-
-
-void GoogleSettingsDialog::changeLangButtonClicked() {
-
- int tempIndexTo=langToComboBox->currentIndex();
- QString tempLangTo=_langTo;
- langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
- langFromComboBox->setCurrentIndex(tempIndexTo);
- _langTo=_langFrom;
- _langFrom=tempLangTo;
-
-}
-
-QString GoogleSettingsDialog::langFrom() {
- return _langFrom;
-}
-
-QString GoogleSettingsDialog::langTo() {
- return _langTo;
-}
-
-Settings* GoogleSettingsDialog::getSettings(QWidget *parent,
- Settings *pluginSettings,
- QString acceptButtonLabel) {
- GoogleSettingsDialog settingsDialog(parent,pluginSettings,acceptButtonLabel);
-
- QMap<QString, QString> languages;
- languages=GooglePlugin::initLanguages();
- if(settingsDialog.exec()==QDialog::Accepted) {
- Settings *settings = new Settings();
- settings->setValue("lang_to",languages.value(settingsDialog.langTo()));
- settings->setValue("lang_from",languages.value(settingsDialog.langFrom()));
- settings->setValue("connection_accepted","true");
- settings->setValue("type","google");
- return settings;
- }
- return 0;
-}
-
-void GoogleSettingsDialog::changeSettings(GooglePlugin* plugin,
- QWidget *parent) {
- Settings *settings = new Settings();
- settings=getSettings(parent,plugin->settings(),tr("Save changes"));
- plugin->setSettings(settings);
- delete settings;
-}
+++ /dev/null
-/*******************************************************************************
-
- This file is part of mDictionary.
-
- mDictionary is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- mDictionary is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
-
- Copyright 2010 Comarch S.A.
-
-*******************************************************************************/
-
-/*! \file GoogleSettingsDialog.h
- \brief Class creates dialog to get or change settings for Google Plugin
- \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
-*/
-
-#ifndef GOOGLESETTINGSDIALOG_H
-#define GOOGLESETTINGSDIALOG_H
-
-#include <QDialog>
-#include "../../include/settings.h"
-#include <QtGui>
-#include "GooglePlugin.h"
-
-class GooglePlugin;
-
-class GoogleSettingsDialog : public QDialog
-{
- Q_OBJECT
-public:
- explicit GoogleSettingsDialog(QWidget *parent = 0,
- Settings *pluginSettings=0,
- QString acceptButtonLabel = tr("Add"));
-
- /*!
- \param parent parent widget on which dialog will be displayed
- \param langTo language which is displayed in the comboBox as a startup item
- \param langFrom language which is displayed in the comboBox as a startup item
- \returns function returns settings to GooglePlugin
- */
- static Settings* getSettings(QWidget *parent,
- Settings *pluginSettings=0,
- QString acceptButtonLabel = tr("Add"));
- /*!
- function sets a new settings in plugin;
- \param plugin plugin whose settings you will change
- \param parent parent widget on which dialog will be displayed
- */
- static void changeSettings(GooglePlugin* plugin, QWidget *parent);
-
- //! \return source language code iso 639-2
- QString langFrom();
-
- //! \return destination language code iso 639-2
- QString langTo();
-
-private slots:
- //! assigns the language chosen from a list(langFromComboBox) to _langFrom
- void activatedFrom(int);
- //! assigns the language chosen from a list(langToComboBox) to _langTo
- void activatedTo(int);
- //! handles the "swap languages" button
- void changeLangButtonClicked();
-
-
-private:
- QLabel* infoLabel;
- QLabel* langFromLabel;
- QLabel* langToLabel;
- QLabel* connectInfoLabel;
- QPushButton* saveButton;
- QPushButton* changeLangButton;
- QComboBox *langFromComboBox;
- QComboBox *langToComboBox;
- QVBoxLayout* verticalLayout;
- QVBoxLayout* langLayout;
- QHBoxLayout* langFromLayout;
- QHBoxLayout* langToLayout;
- QHBoxLayout* changelangLayout;
- QString _langFrom;
- QString _langTo;
-};
-
-#endif // GOOGLESETTINGSDIALOG_H
GooglePlugin.cpp \
TranslationGoogle.cpp \
GoogleDictDialog.cpp \
- GoogleSettingsDialog.cpp
+ GoogleDialog.cpp
HEADERS += \
GooglePlugin.h \
../../include/CommonDictInterface.h \
TranslationGoogle.h \
GoogleDictDialog.h \
- GoogleSettingsDialog.h
+ GoogleDialog.h
TRANSLATIONS += dict_google_pl.ts \
dict_google_en.ts
<RCC>
<qresource prefix="/">
- <file>translations/dict_google_en.qm</file>
- <file>translations/dict_google_pl.qm</file>
+ <file>translations/en_EN.qm</file>
+ <file>translations/pl_PL.qm</file>
</qresource>
</RCC>
_bookmark=0;
}
-TranslationXdxf::~TranslationXdxf() {
- ;
-}
QString TranslationXdxf::key() const {
return _key;
{
public:
TranslationXdxf();
- TranslationXdxf(QString _key,QString _dictionaryInfo, XdxfPlugin *xdxfPlugin);
- ~TranslationXdxf();
+ TranslationXdxf(QString _key,
+ QString _dictionaryInfo,
+ XdxfPlugin *xdxfPlugin);
//! \return word to be translated
QString key() const;
#include <QDebug>
-XdxfCachingDialog::XdxfCachingDialog(XdxfPlugin *parent) //:
-// QDialog((QWidget*)parent)
-{
+XdxfCachingDialog::XdxfCachingDialog(XdxfPlugin *parent) {
verticalLayout = new QVBoxLayout(this);
setLayout(verticalLayout);
connect(cancelButton, SIGNAL(clicked()),
this, SIGNAL(cancelCaching()));
- connect(parent, SIGNAL(updateCachingProgress(int, int)),
- this, SLOT(updateCachingProgress(int, int)));
+ connect(parent, SIGNAL(updateCachingProgress(int, int)),
+ this, SLOT(updateCachingProgress(int, int)));
time.start();
}
tr("%n second(s)", "", seconds));
if(progress >= 100)
this->hide();
-
-
-}
-
-void XdxfCachingDialog::cancelButtonClicked(){
- return;
}
Copyright 2010 Comarch S.A.
*******************************************************************************/
-/*! \file XdxfCachingDialog.h
+/*!
+ \file XdxfCachingDialog.h
+ \author Mateusz Półrola <mateusz.polrola@gmail.com>
*/
-//Created by Mateusz Półrola
+
#ifndef XDXFCACHINGDIALOG_H
#define XDXFCACHINGDIALOG_H
class XdxfPlugin;
-
+//! Shows dialog with progress of dictionary caching
+/*!
+ Displays progress bar and estimated time left of caching
+*/
class XdxfCachingDialog : public QDialog
{
Q_OBJECT
void cancelCaching();
private Q_SLOTS:
- void cancelButtonClicked();
void updateCachingProgress(int, int);
private:
tr("From: ") + plugin->langFrom() + "\n" +
tr("To: ") + plugin->langTo() + "\n" +
tr("Description: ") + plugin->name() + "\n" +
- tr("License: ") + plugin->infoNote());
+ plugin->infoNote());
mainVerticalLayout->addWidget(infoLabel);
}
*******************************************************************************/
-//Created by Mateusz Półrola
+/*!
+ \file XdxfDialog.cpp
+ \author Mateusz Półrola <mateusz.polrola@gmail.com>
+*/
#ifndef XDXFDIALOG_H
#define XDXFDIALOG_H
#include <QtGui>
#include "xdxfplugin.h"
+
+//! Implementation of xdxf plugin's dialogs.
+/*!
+ This class can create dialogs for adding new dictionary or changins settings
+ of existing one, based on dialog type passed to contructor.
+ When adding new dictionary dialog contains button to browse file system and
+ select dictionary file. When changing settings dialog displays basic
+ information about dictionary i. e. name, languages and license info.
+ In both types of dialogs there are comboboxes with cache and remove accents
+ options. On maemo right next to comboboxes are tool button which allow to
+ see more information about this options, on desktop the same information is
+ displayed as tool tip.
+ All content of dialog is in scroll area.
+*/
class XdxfDialog : public QDialog
{
Q_OBJECT
public:
+ /*!
+ Describes type of dialog. New means that dialog contains widgets to browse
+ file system and select dictionary file. Change means that dialog displays
+ information about dictionary.
+ In both types dialog provides widgets to create or delete cache and remove
+ or left accents.
+ */
enum XdxfDialogType {New, Change};
+ //! Constructor
+ /*!
+ Creates new xdxf dialog
+ \param plugin if creating dialog of type Change it must be set to
+ pointer of plugin whose settings will be changed
+ \param type describes type of creating dialog
+ \param parent parent widget of creating dialog
+ */
explicit XdxfDialog(XdxfPlugin* plugin = 0,
XdxfDialogType type = New,
- QWidget *parent = 0);
+ QWidget* parent = 0);
+ //! Returns settings of plugin
+ /*!
+ After acceptance of dialog this method return plugin's settings based on
+ user choises in dialog.
+ */
Settings* getSettings();
Q_SIGNALS:
+ //! Request to show notification
void notify(Notify::NotifyType, QString);
public Q_SLOTS:
+ //! Reimplemented accept method, to check if all necessery fields in
+ //! dialog are correct e. g. dictionary file path
+ //! and saves new settings
void accept();
private Q_SLOTS:
+ //! displays dialog to browse and select file
void selectFile();
- void saveSettings();
void setGenerateCache(bool);
void setAccents(bool);
#ifdef Q_WS_MAEMO_5
+ //! on maemo shows information about checkboxes
void showCacheInfo();
void showAccentsInfo();
#endif
private:
void initializeUI();
+ //! saves new settings after acceptance of dialog
+ void saveSettings();
+
QLabel* infoLabel;
QPushButton* browseButton;
QHBoxLayout* browseLayout;
//Created by Mateusz Półrola
#include "XdxfDictDialog.h"
-#include "XdxfLoadDialog.h"
-#include "XdxfSettingsDialog.h"
#include "xdxfplugin.h"
#include "XdxfDialog.h"
#include <QDebug>
}
Settings* XdxfDictDialog::addNewDictionary(QWidget *parent) {
- qDebug()<<parent;
XdxfDialog d(0, XdxfDialog::New, parent);
connect(&d, SIGNAL(notify(Notify::NotifyType,QString)),
#define XDXFDICTDIALOG_H
#include "../../include/DictDialog.h"
-#include "XdxfLoadDialog.h"
class XdxfPlugin;
+++ /dev/null
-/*******************************************************************************
-
- This file is part of mDictionary.
-
- mDictionary is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- mDictionary is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
-
- Copyright 2010 Comarch S.A.
-
-*******************************************************************************/
-
-/*! \file XdxfLoadDialog.cpp
-*/
-//Created by Mateusz Półrola
-
-#include "XdxfLoadDialog.h"
-
-XdxfLoadDialog::XdxfLoadDialog(QWidget *parent) :
- QDialog(parent) {
- verticalLayout = new QVBoxLayout;
- setLayout(verticalLayout);
-
- setWindowTitle(tr("Add new XDXF dictionary"));
-
-
-
- browseLayout = new QHBoxLayout;
-
- browseButton = new QPushButton(tr("Browse"));
- browseLabel = new QLabel(tr("Dictionary file: not selected"));
- //browseLabel->setMargin(5);
-
- browseLayout->addWidget(browseLabel, 0, Qt::AlignLeft);
- browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
-
- verticalLayout->addLayout(browseLayout);
-
- cacheLayout = new QHBoxLayout;
- verticalLayout->addLayout(cacheLayout);
- accentsCheckBox = new QCheckBox(tr("Strip accents (searching takes more "
- "time, but spelling don't have to be exact)"));
- verticalLayout->addWidget(accentsCheckBox);
-
- cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"),this);
- cacheCheckBox->setChecked(true);
- cacheLayout->addWidget(cacheCheckBox);
-
- addButton = new QPushButton(tr("Add"));
-
- verticalLayout->addWidget(addButton);
-
- setModal(true);
-
- connect(browseButton, SIGNAL(clicked()),
- this, SLOT(selectFile()));
-
- connect(addButton, SIGNAL(clicked()),
- this, SLOT(addDictionary()));
-
- connect(cacheCheckBox, SIGNAL(toggled(bool)),
- SLOT(setGenerateCache(bool)));
-
- connect(accentsCheckBox, SIGNAL(clicked(bool)), SLOT(setAccents(bool)));
- lastAccents = accentsCheckBox->isChecked();
- _dicitonaryFilePath = QString();
-}
-
-
-
-void XdxfLoadDialog::setAccents(bool state) {
- lastAccents = state;
-}
-
-
-
-void XdxfLoadDialog::selectFile() {
- QString fileName = QFileDialog::getOpenFileName(this,
- tr("Select dictionary file"),
- _dicitonaryFilePath,
- tr("XDXF Files (*.xdxf)"),
- NULL,
- NULL);
-
- if (!fileName.isEmpty()) {
- browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
- _dicitonaryFilePath = fileName;
- }repaint(rect());
- resize(size());
-}
-
-void XdxfLoadDialog::addDictionary() {
- _generateCache = cacheCheckBox->isChecked();
- if(!_dicitonaryFilePath.isEmpty()) {
- accept();
- }
-}
-
-QString XdxfLoadDialog::dicitonaryFilePath() {
- return _dicitonaryFilePath;
-}
-
-bool XdxfLoadDialog::generateCache() {
- return _generateCache;
-}
-
-void XdxfLoadDialog::setGenerateCache(bool generate) {
- _generateCache = generate;
-
- if(generate)
- accentsCheckBox->setChecked(true);
- else
- accentsCheckBox->setChecked(lastAccents);
-
- accentsCheckBox->setEnabled(!generate);
-}
-
-Settings* XdxfLoadDialog::getSettings(QWidget *parent) {
- XdxfLoadDialog loadDialog(parent);
- Settings* settings = new Settings;
-
- if(loadDialog.exec()==QDialog::Accepted) {
- settings->setValue("path", loadDialog.dicitonaryFilePath());
- if(loadDialog.generateCache()) {
- settings->setValue("generateCache", "true");
- }
- else {
- settings->setValue("generateCache", "false");
- }
- if(loadDialog.accentsCheckBox->isChecked())
- settings->setValue("strip_accents", "true");
- else
- settings->setValue("strip_accents", "false");
-
-
- return settings;
- }
-
- return NULL;
-}
-
-
+++ /dev/null
-/*******************************************************************************
-
- This file is part of mDictionary.
-
- mDictionary is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- mDictionary is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
-
- Copyright 2010 Comarch S.A.
-
-*******************************************************************************/
-/*! \file XdxfLoadDialog.h
-*/
-//Created by Mateusz Półrola
-
-#ifndef XDXFLOADDIALOG_H
-#define XDXFLOADDIALOG_H
-
-#include <QDialog>
-#include <QtGui>
-#include "../../include/settings.h"
-
-//! Displays dialog which allows user to add new xdxf dictionary
-class XdxfLoadDialog : public QDialog {
- Q_OBJECT
-public:
- explicit XdxfLoadDialog(QWidget *parent = 0);
-
- /*! Displays dialog and returns settings of new dictionary
- \return Settings object containing new dictionary settings or NULL in
- case user cancels dialog
- */
- static Settings* getSettings(QWidget *parent);
-
- //! Returns dictionary file path chosen by user
- QString dicitonaryFilePath();
-
- //! Returns if user wants to cache dictionary
- bool generateCache();
-
-private Q_SLOTS:
- void selectFile();
- void addDictionary();
- void setGenerateCache(bool);
- void setAccents(bool);
-
-private:
- QPushButton* addButton;
- QPushButton* browseButton;
- QLabel* browseLabel;
- QCheckBox* cacheCheckBox;
- QCheckBox* accentsCheckBox;
- QVBoxLayout* verticalLayout;
- QHBoxLayout* browseLayout;
- QHBoxLayout* cacheLayout;
- QString _dicitonaryFilePath;
- bool _generateCache;
- bool lastAccents;
-
-};
-
-#endif // XDXFLOADDIALOG_H
+++ /dev/null
-/*******************************************************************************
-
- This file is part of mDictionary.
-
- mDictionary is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- mDictionary is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
-
- Copyright 2010 Comarch S.A.
-
-*******************************************************************************/
-
-/*! \file XdxfSettingsDialog.cpp
-*/
-
-
-#include "XdxfSettingsDialog.h"
-#include <QDebug>
-
-XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
- QDialog(parent)
-{
- this->plugin = plugin;
-
- verticalLayout = new QVBoxLayout;
-
- QWidget* w = new QWidget;
- w->setLayout(verticalLayout);
-
- setWindowTitle(tr("XDXF Settings"));
-
-
- infoLabel = new QLabel(this);
-
- 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);
-
-
- verticalLayout->addWidget(infoLabel);
-
-
- accentsCheckBox = new QCheckBox(tr("Strip accents"));
- /*(searching takes more time, "
- "but spelling don't have to be exact)*/
- if(plugin->settings()->value("strip_accents") == "true")
- accentsCheckBox->setChecked(true);
- else
- accentsCheckBox->setChecked(false);
-
- cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches"));
-/*(may take some time)*/
- if(plugin->settings()->value("cached") == "true") {
- cacheCheckBox->setChecked(true);
- accentsCheckBox->setChecked(true);
- accentsCheckBox->setEnabled(false);
- _generateCache = true;
- }
- else {
- cacheCheckBox->setChecked(false);
- _generateCache = false;
- }
-
- accentsToolButton = new QToolButton;
- cacheToolButton = new QToolButton;
-
- accentsToolButton->setIcon(QIcon::fromTheme("general_information"));
- cacheToolButton->setIcon(QIcon::fromTheme("general_information"));
-
- cacheLayout = new QHBoxLayout;
- accentsLayout = new QHBoxLayout;
-
- accentsLayout->addWidget(accentsCheckBox);
- accentsLayout->addWidget(accentsToolButton);
-
- cacheLayout->addWidget(cacheCheckBox);
- cacheLayout->addWidget(cacheToolButton);
-
- verticalLayout->addLayout(cacheLayout);
- verticalLayout->addLayout(accentsLayout);
-
-
-
- saveButton = new QPushButton(tr("Save settings"));
-
- verticalLayout->addWidget(saveButton);
-
- scrollArea = new QScrollArea;
- scrollArea->setWidget(w);
-
-
- QHBoxLayout* layout = new QHBoxLayout();
-
- scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- scrollArea->setWidgetResizable(true);
- layout->addWidget(scrollArea);
- setLayout(layout);
-
-
-
- setModal(true);
-
- connect(saveButton, SIGNAL(clicked()),
- this, SLOT(accept()));
-
- connect(cacheCheckBox, SIGNAL(toggled(bool)),
- SLOT(setGenerateCache(bool)));
-
- connect(accentsCheckBox, SIGNAL(clicked(bool)), SLOT(setAccents(bool)));
-
-
- _dicitonaryFilePath = plugin->settings()->value("path");
- lastAccents = accentsCheckBox->isChecked();
-}
-
-
-void XdxfSettingsDialog::setAccents(bool state) {
- lastAccents = state;
-}
-
-void XdxfSettingsDialog::setGenerateCache(bool generate) {
- _generateCache = generate;
-
- if(generate)
- accentsCheckBox->setChecked(true);
- else
- accentsCheckBox->setChecked(lastAccents);
-
- accentsCheckBox->setEnabled(!generate);
-}
-
-bool XdxfSettingsDialog::generateCache() {
- return _generateCache;
-}
-
-QString XdxfSettingsDialog::dicitonaryFilePath() {
- return _dicitonaryFilePath;
-}
-
-Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
- QWidget *parent) {
- XdxfSettingsDialog settingsDialog(plugin, parent);
-
-
- if(settingsDialog.exec()==QDialog::Accepted) {
- Settings* settings = new Settings;
- foreach(QString key, plugin->settings()->keys())
- settings->setValue(key, plugin->settings()->value(key));
- settings->setValue("path", settingsDialog.dicitonaryFilePath());
-
- if(settingsDialog.generateCache()) {
- settings->setValue("generateCache", "true");
- }
- else {
- settings->setValue("generateCache", "false");
- }
-
- if(settingsDialog.accentsCheckBox->isChecked())
- settings->setValue("strip_accents", "true");
- else
- settings->setValue("strip_accents", "false");
-
- plugin->setSettings(settings);
- delete settings;
- return 0;
- }
-
- return 0;
-}
-
-
+++ /dev/null
-/*******************************************************************************
-
- This file is part of mDictionary.
-
- mDictionary is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- mDictionary is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
-
- Copyright 2010 Comarch S.A.
-
-*******************************************************************************/
-/*! \file XdxfSettingsDialog.h
-*/
-//Created by Mateusz Półrola
-
-#ifndef XDXFSETTINGSDIALOG_H
-#define XDXFSETTINGSDIALOG_H
-
-#include <QDialog>
-#include "../../include/settings.h"
-#include <QtGui>
-#include "xdxfplugin.h"
-
-class XdxfSettingsDialog : public QDialog
-{
- Q_OBJECT
-public:
- explicit XdxfSettingsDialog(XdxfPlugin* plugin, QWidget *parent = 0);
- //! \returns settings of a given plugin
- static Settings* getSettings(XdxfPlugin* plugin, QWidget *parent);
-
- //! \returns dictionary file path chosen by user
- QString dicitonaryFilePath();
-
- //! \returns if user wants to cache dictionary
- bool generateCache();
-
-private Q_SLOTS:
- void setGenerateCache(bool);
- void setAccents(bool);
-
-private:
- QLabel* infoLabel;
- QPushButton* saveButton;
-
-
- QCheckBox* cacheCheckBox;
- QCheckBox* accentsCheckBox;
-
- QHBoxLayout* cacheLayout;
- QHBoxLayout* accentsLayout;
-
- QToolButton* cacheToolButton;
- QToolButton* accentsToolButton;
-
- QVBoxLayout* verticalLayout;
-
- QString _dicitonaryFilePath;
- bool _generateCache;
- XdxfPlugin* plugin;
- bool lastAccents;
-
- QScrollArea* scrollArea;
-
-};
-
-#endif // XDXFSETTINGSDIALOG_H
SOURCES += \
xdxfplugin.cpp \
TranslationXdxf.cpp \
- XdxfLoadDialog.cpp \
XdxfDictDialog.cpp \
- XdxfSettingsDialog.cpp \
XdxfCachingDialog.cpp \
XdxfDialog.cpp
HEADERS += \
xdxfplugin.h \
TranslationXdxf.h \
- XdxfLoadDialog.h \
../../include/DictDialog.h \
XdxfDictDialog.h \
../../include/translation.h \
../../include/settings.h \
../../include/CommonDictInterface.h \
- XdxfSettingsDialog.h \
XdxfCachingDialog.h \
XdxfDialog.h
<RCC>
<qresource prefix="/">
- <file>translations/dict_xdxf_en.qm</file>
- <file>translations/dict_xdxf_pl.qm</file>
+ <file>translations/en_EN.qm</file>
+ <file>translations/pl_PL.qm</file>
</qresource>
</RCC>
cachingDialog = new XdxfCachingDialog(this);
-
_settings->setValue("type","xdxf");
_icon = QIcon("/usr/share/mdictionary/xdxf.png");
_wordsCount = -1;
QTranslator *translator = new QTranslator(this);
- if(locale == "pl_PL")
- translator->load(":/translations/dict_xdxf_pl");
- else
- translator->load(":/translations/dict_xdxf_en");
-
+ if(!translator->load(":/translations/" + locale)) {
+ translator->load(":/translations/en_EN");
+ }
QCoreApplication::installTranslator(translator);
}
CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
XdxfPlugin *plugin = new XdxfPlugin();
- connect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
- this, SIGNAL(notify(Notify::NotifyType,QString)));
+
if(settings && plugin->setSettings(settings)) {
return plugin;
}
QString infoNote() const;
/*! returns DictDialog object that creates dialogs
- for adding new dictionary and changing plugin things
+ for adding new dictionary and changing plugin settings
*/
DictDialog* dictDialog();
//! loads translations for each plugin only once
void retranslate();
-
-
Q_SIGNALS:
//! emitted with percent count of caching progress, and time elapsed from
//! last signal emit
void updateCachingProgress(int, int);
-
private:
/*! returns true or false depending on whether the dictionary is cached