}
-
void Bookmarks::remove(Translation* translation) {
QSqlDatabase db = getDbCnx(dbName);
if(!db.isOpen() && !db.open()) {
int Backbone::_searchLimit;
-// Sadly QtConcurrent mapped doesn't let me use something like calling method of
-// some class with supplied argument
+// Sadly QtConcurent::mapped dosent let me use something like calling method of
+// some class with supplied argument; so i have to sin against art and put
+// global function and variable so i could supply function with some parametr
QString mappedSearch;
QList<Translation*> mapSearch(CommonDictInterface *dict) {
if(dict)
return QList<Translation*>();
}
+
+
+/*! Smart pointer (kind of) for translation object
+
+ QtConcurent::mapped use collection of data and one function, what i need is
+ to map signle data object to method calls for multiple objects. TranslationPtr
+ is try to store method call as a data -> moreover QtConcurent allow only for
+ methods without any parameters so TranslationPtr is created with Translation
+ object -> ready to call toHtml() for supplied Translation.
+
+ Another thing is that QtConcurent dont like pointers in data collection
+ so TranslationPtr is way to hide real translation object (pointer for object)
+ */
class TranslationPtr {
Translation* _tr;
public:
TranslationPtr(Translation* tr) :_tr(tr) {}
+
+ /*! \return translation text for corresponding Translation object */
QString toHtml() const {
QString trans;
trans = _tr->toHtml();
_searchLimit = 15;
loadPrefs(_defaultConfigPath);
+
+ // Default configuration are stored in separate config file and we dont want
+ // to update it
_defaultPluginPath = _pluginPath;
_defaultHistoryLen = _historyLen;
_defaultSearchLimit = _searchLimit;
connect(&_bookmarkSearchWatcher, SIGNAL(finished()), this,
SLOT(translationReady()));
+ // In common opinion perfect thread count is cores_number+1 (in qt perfect
+ // thread count is set to cores number
QThreadPool::globalInstance()->setMaxThreadCount(
QThreadPool::globalInstance()->maxThreadCount()+1);
{
_pluginPath = pluginPath;
_configPath = configPath;
+
_defaultConfigPath = configPath;
dryRun = false;
if(dry)
void Backbone::search(QString word){
- qDebug() << "SEEEEEEEEEARCH";
_result.clear();
mappedSearch = word.toLower();
stopped = false;
+
+ // When dictFin and bookmarkFin is set to true then translationReady()
+ // signal is emited see translationReady(),
+ // so when searching only in one of them, coresponding *Fin is set to false
+ // and other to true so program is waiting only for one translation
dictFin = !_searchDicts;
bookmarkFin = !_searchBookmarks;
void Backbone::addInternalDictionary(CommonDictInterface* dict, bool active) {
- dict->setHash(++_dictNum);
+ dict->setHash(++_dictNum); // Hash must be uniqe in every session but not between
_dicts[dict] = active;
+
connect(dict, SIGNAL(settingsChanged()), this, SLOT(dictUpdated()));
connect(dict, SIGNAL(notify(Notify::NotifyType,QString)), this,
SIGNAL(notify(Notify::NotifyType,QString)));
void Backbone::translationReady() {
- bool changed = 0; // prevents from doubling ready() signal, when both are
+ bool changed = 0; // prevents doubling ready() signal, when both if's are
// executed in one translationReady() call then second
- // call doubles ready*() emit without any new data
+ // translationReady() call doubles ready*() emit
+
if(!dictFin && _innerResult.isFinished()) {
changed = 1;
dictFin = 1;
}
if(!stopped && bookmarkFin && dictFin && changed) {
- qDebug() << "EMITTTTTT";
Q_EMIT ready();
- }
+ }
}
QStringList Backbone::getFilesFromDir(QString dir, QStringList nameFilter) {
void Backbone::loadDicts(QString fileName, bool _default) {
if(dryRun)
return;
+
QFileInfo file(QDir::toNativeSeparators(fileName));
QDir confDir(file.dir());
if(!confDir.exists()){
void Backbone::dictUpdated() {
if(dryRun)
return;
+
+ // For convienence this function is called for each change in dictionaries
+ // and each call dumps configuration for all dictionaries into file.
+ // Maybe better way would be to store new/changed configuration but
+ // parsing settings file and figuring out what was changed, in my opinion,
+ // would take more time
_history->setMaxSize(_historyLen);
QFileInfo file(QDir::toNativeSeparators(_configPath));
QDir confDir(file.dir());
return;
if(!set || !plugSet)
return;
+
QString section;
section.append(QString("dictionary_%1").arg(hash));
QList<QString> keys = plugSet->keys();
else
_searchBookmarks = 0;
dictUpdated();
+ if(settings)
+ delete settings;
}
/*! Removes all bookmarks
*/
- void removeAllBookmark(){
+ void removeAllBookmarks(){
_bookmarks.clear();
}
+/*******************************************************************************
+
+ 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 AboutWidget.cpp
+\brief Simple "about" widget - product, company, license info
+
+
+\author Bartosz Szatkowski <bulislaw@linux.com>
+*/
+
#include "AboutWidget.h"
AboutWidget::AboutWidget(GUIInterface *parent): QDialog(parent)
#ifndef Q_WS_MAEMO_5
w->setLayout(mainLayout);
scroll->setWidget(w);
+ scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollLayout->addWidget(scroll, 0, Qt::AlignHCenter);
this->setLayout(scrollLayout);
- this->resize(img.width()*1.65, img.height()*2.60);
+ w->setMinimumSize(img.width()*1.6, img.height()*2.45);
#else
setLayout(mainLayout);
#endif
+/*******************************************************************************
+
+ 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 AboutWidget.h
+\brief Simple "about" widget - product, company, license info
+
+
+\author Bartosz Szatkowski <bulislaw@linux.com>
+*/
+
#ifndef ABOUTWIDGET_H
#define ABOUTWIDGET_H
connect(removeAllBookmarksPushButton, SIGNAL(clicked()),
this, SIGNAL(removeAllBookmarks()));
}
+
+
public:
explicit BookmarksWidget(GUIInterface *parent = 0);
+
Q_SIGNALS:
void showAllBookmarks();
void removeAllBookmarks();
+
private:
QPushButton* showAllBookmarksPushButton;
QPushButton* removeAllBookmarksPushButton;
connect(addNewDictButton, SIGNAL(clicked()),
+ this, SLOT(saveChanges()));
+ connect(addNewDictButton, SIGNAL(clicked()),
this, SLOT(addNewDictButtonClicked()));
connect(removeDictButton, SIGNAL(clicked()),
+ this, SLOT(saveChanges()));
+ connect(removeDictButton, SIGNAL(clicked()),
this, SLOT(removeButtonClicked()));
connect(settingsButton, SIGNAL(clicked()),
+ this, SLOT(saveChanges()));
+ connect(settingsButton, SIGNAL(clicked()),
this, SLOT(settingsButtonClicked()));
connect(dictListWidget, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(itemSelected(QListWidgetItem*)));
+ connect(dictListWidget, SIGNAL(itemChanged(QListWidgetItem*)),
+ this, SLOT(changed()));
+
refreshDictsList();
#ifndef Q_WS_MAEMO_5
setMinimumSize(500,300);
+ closeButton = new QPushButton(tr("Save"));
+ buttonGroup->addWidget(closeButton);
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
#endif
}
}
void DictManagerWidget::showEvent(QShowEvent *e) {
+ _changed = false;
+ #ifndef Q_WS_MAEMO_5
+ _save = false;
+ #endif
refreshDictsList();
QWidget::showEvent(e);
}
-void DictManagerWidget::hideEvent(QHideEvent *e)
-{
- QList<CommonDictInterface*> checkedDicts;
+void DictManagerWidget::saveChanges() {
+
+ #ifndef Q_WS_MAEMO_5
+ if(_save) {
+ #else
+ if(_changed &&
+ QMessageBox::question(this, "Save", "Do you want to save changes?",
+ QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
+ #endif
+ QList<CommonDictInterface*> checkedDicts;
- for(int i=0; i<dictListWidget->count(); i++) {
- QListWidgetItem* item = dictListWidget->item(i);
- if(item->checkState() == Qt::Checked) {
- checkedDicts.push_back(dictsHash[item]);
+ for(int i=0; i<dictListWidget->count(); i++) {
+ QListWidgetItem* item = dictListWidget->item(i);
+ if(item->checkState() == Qt::Checked) {
+ checkedDicts.push_back(dictsHash[item]);
+ }
}
+ emit selectedDictionaries(checkedDicts);
}
- Q_EMIT selectedDictionaries(checkedDicts);
+ _changed = false;
+}
+void DictManagerWidget::hideEvent(QHideEvent *e)
+{
+ saveChanges();
QWidget::hideEvent(e);
}
}
void DictManagerWidget::removeButtonClicked() {
- QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
- if(selected.count() > 0) {
- Q_EMIT removeDictionary(dictsHash[selected[0]]);
- refreshDictsList();
- }
+ if(QMessageBox::question(this, "Remove dictionary",
+ "Do you want to remove selected dictionary?",
+ QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) {
+ QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
+ if(selected.count() > 0) {
+ emit removeDictionary(dictsHash[selected[0]]);
+ refreshDictsList();
+ }
+ }
}
void DictManagerWidget::settingsButtonClicked() {
refreshDictsList();
}
}
+
+
+void DictManagerWidget::changed() {
+ _changed=true;
+}
+
+
+#ifndef Q_WS_MAEMO_5
+ void DictManagerWidget::save() {
+ _save = true;
+ hide();
+ }
+#endif
/*! Shows plugin's settings dialog*/
void settingsButtonClicked();
+ //! Each change of state (that needs to be saved) should call this to indicate state change
+ void changed();
+
+ //! saves changes
+ void saveChanges();
+
private:
QPushButton* addNewDictButton;
QPushButton* removeDictButton;
//holds association between items on list and CommonDictInterface objects
QHash<QListWidgetItem*, CommonDictInterface*> dictsHash;
GUIInterface* guiInterface;
+ bool _changed;
void refreshDictsList();
+ #ifndef Q_WS_MAEMO_5
+ QPushButton* closeButton;
+ bool _save;
+
+ public Q_SLOTS:
+ void save();
+ #endif
};
#endif // DICTMANAGERWIDGET_H
translationWidget = new TranslationWidget(this);
- mainLayout = new QVBoxLayout(this);
- QWidget* w = new QWidget(this);
+ mainLayout = new QVBoxLayout();
+ QWidget* w = new QWidget();
w->setLayout(mainLayout);
setCentralWidget(w);
- menuBar = new QMenuBar(this);
+ menuBar = new QMenuBar();
setMenuBar(menuBar);
- searchBarWidget = new SearchBarWidget(this);
+ searchBarWidget = new SearchBarWidget();
- wordListWidget = new WordListWidget(this);
+ wordListWidget = new WordListWidget();
- welcomeScreenWidget = new WelcomeScreenWidget(this);
+ welcomeScreenWidget = new WelcomeScreenWidget();
#ifdef Q_WS_MAEMO_5
void MainWindow::showNotify(Notify::NotifyType type, QString text) {
+
switch(type) {
case Notify::Info:
#ifdef Q_WS_MAEMO_5
break;
case Notify::Warning:
+ qDebug() << text;
#ifndef Q_WS_MAEMO_5
QMessageBox::warning(this, "Warning", text);
break;
+ #else
+ QMessageBox::information(this, "Warning", text);
#endif
case Notify::Error:
connect(backbone, SIGNAL(searchCanceled()),
this, SIGNAL(setIdle()));
+ connect(backbone, SIGNAL(notify(Notify::NotifyType,QString)),
+ this, SLOT(showNotify(Notify::NotifyType,QString)));
+
#ifdef Q_WS_MAEMO_5
//after removing bookmarks we search for it once again to clear word list
connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
- backbone, SLOT(removeAllBookmark()));
-
- connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
- backbone, SLOT(fetchBookmarks()));
+ this, SLOT(removeBookmarks()));
connect(bookmarksWidget, SIGNAL(showAllBookmarks()),
#else
+ connect(bookmarksRemoveAllAction, SIGNAL(triggered()),
+ this, SLOT(removeBookmarks()));
connect(bookmarksShowAllAction, SIGNAL(triggered()),
backbone, SLOT(fetchBookmarks()));
- connect(bookmarksRemoveAllAction, SIGNAL(triggered()),
- backbone, SLOT(removeAllBookmark()));
+ #endif
+}
- connect(bookmarksRemoveAllAction, SIGNAL(triggered()),
- backbone, SLOT(fetchBookmarks()));
+
+void MainWindow::removeBookmarks() {
+ QWidget* par;
+ #ifdef Q_WS_MAEMO_5
+ par = bookmarksWidget;
+ #else
+ par = this;
#endif
+ if(QMessageBox::question(par, "Delete all bookmarks",
+ "Do you want to delete all bookmarks? (This action cannot be revoked)",
+ QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) {
+ backbone->removeAllBookmarks();
+ if(searchString.size())
+ backbone->search(searchString);
+
+ }
}
//! disabled
void breakSearching();
+ //! Asks for confirmation when user click on "delete all bookmarks"
+ void removeBookmarks();
+
protected:
/*! When user wants to close application, we first send signal to stop all
#endif
- horizontalLayout = new QHBoxLayout(this);
- verticalLayout = new QVBoxLayout(this);
+ horizontalLayout = new QHBoxLayout();
+ verticalLayout = new QVBoxLayout();
- searchPushButton = new QPushButton(tr("Search"),this);
+ searchPushButton = new QPushButton(tr("Search"));
searchPushButton->setMinimumWidth(125);
- searchWordLineEdit = new QLineEdit(this);
+ searchWordLineEdit = new QLineEdit();
searchWordLineEdit->setMinimumWidth(250);
#ifndef Q_WS_MAEMO_5
//create layout for lineEdit to have clear button on it
- QHBoxLayout* lineEditLayout = new QHBoxLayout(this);
+ QHBoxLayout* lineEditLayout = new QHBoxLayout();
searchWordLineEdit->setLayout(lineEditLayout);
- clearSearchWordToolButton = new QToolButton(this);
+ clearSearchWordToolButton = new QToolButton();
#ifdef Q_WS_MAEMO_5
clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
//tool buttons will have size 2 times smaller
clearSearchWordToolButton->setMaximumSize(
clearSearchWordToolButton->sizeHint().height()/2,
clearSearchWordToolButton->sizeHint().height()/2);
+ lineEditLayout->setContentsMargins(0,0,10,0);
#else
clearSearchWordToolButton->setIcon(QIcon::fromTheme("edit-clear"));
clearSearchWordToolButton->setMinimumSize(
- clearSearchWordToolButton->sizeHint().height(),
- clearSearchWordToolButton->sizeHint().height());
+ searchWordLineEdit->sizeHint().height()*1.2,
+ searchWordLineEdit->sizeHint().height()*1.2);
+ lineEditLayout->setContentsMargins(0,0,5,0);
#endif
- historyNextToolButton = new QToolButton(this);
+ historyNextToolButton = new QToolButton();
#ifdef Q_WS_MAEMO_5
historyNextToolButton->setIcon(
generateIcon(QIcon::fromTheme("general_forward")));
- historyPrevToolButton = new QToolButton(this);
+ historyPrevToolButton = new QToolButton();
#ifdef Q_WS_MAEMO_5
historyPrevToolButton->setIcon(
generateIcon(QIcon::fromTheme("general_back")));
- historyShowToolButton = new QToolButton(this);
+ historyShowToolButton = new QToolButton();
#ifdef Q_WS_MAEMO_5
historyShowToolButton->setIcon(
generateIcon(QIcon::fromTheme("general_back"), 90));
fullScreenToolButton->sizeHint().height()*2);
#endif*/
- searchingProgressBar = new QProgressBar(this);
- //progress bar has minimum and maximum values set to 0, which will effect
+ searchingProgressBar = new QProgressBar();
+ //progress bar have minimum and maximum values set to 0, which will effect
//with "I'm alive" bar
searchingProgressBar->setMinimum(0);
searchingProgressBar->setMaximum(0);
// horizontalLayout->addWidget(fullScreenToolButton);
//adding clear toolButton to textEdit with right alignment
- lineEditLayout->addWidget(clearSearchWordToolButton, 0,
- Qt::AlignRight | Qt::AlignVCenter);
+ lineEditLayout->addWidget(clearSearchWordToolButton, 0, Qt::AlignRight);
+
verticalLayout->addLayout(horizontalLayout);
}
spinBoxesFormLayout->addRow(tr("History size"),
historySizeSpinBox);
- searchResultSizeSpinBox->setMinimum(1);
+ searchResultSizeSpinBox->setMinimum(0);
historySizeSpinBox->setMinimum(1);
#ifdef Q_WS_MAEMO_5
verticalLayout->addWidget(searchInBookmarksCheckBox);
+ connect(historySizeSpinBox, SIGNAL(valueChanged(int)), this,
+ SLOT(changed()));
+ connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), this,
+ SLOT(changed()));
+ connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), this,
+ SLOT(changed()));
+ connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), this,
+ SLOT(changed()));
+
+
settings = 0;
#ifndef Q_WS_MAEMO_5
setMinimumWidth(250);
setMaximumWidth(250);
+ footerLayout = new QHBoxLayout(this);
+ closeButton = new QPushButton(tr("Save"));
+ footerLayout->addStretch(0);
+ footerLayout->addWidget(closeButton);
+ verticalLayout->addLayout(footerLayout);
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
#endif
}
void SettingsWidget::showEvent(QShowEvent *e) {
+ #ifndef Q_WS_MAEMO_5
+ _save = false;
+ #endif
settings = guiInterface->settings();
historySizeSpinBox->setValue(
else
searchInDictionariesCheckBox->setChecked(false);
+ _changed = false;
QDialog::showEvent(e);
}
void SettingsWidget::hideEvent(QHideEvent *e) {
QDialog::hideEvent(e);
- if(settings) {
+ #ifndef Q_WS_MAEMO_5
+ if(settings && _save) {
+ #else
+ if(settings && _changed &&
+ QMessageBox::question(this, "Save", "Do you want to save changes?",
+ QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
+
+ #endif
Settings* newSettings = new Settings;
newSettings->setValue("history_size",
QString::number(historySizeSpinBox->value()));
}
}
+ }
+ if(settings) {
delete settings;
settings = 0;
}
+ _changed = false;
+}
+
+
+void SettingsWidget::changed() {
+ _changed = true;
}
+
+#ifndef Q_WS_MAEMO_5
+ void SettingsWidget::save() {
+ _save = true;
+ hide();
+ }
+#endif
#include <QWidget>
#include <QtGui>
+#include <QPushButton>
#include "../../includes/GUIInterface.h"
#include "../../includes/settings.h"
*/
explicit SettingsWidget(GUIInterface *parent = 0);
+
protected:
void showEvent(QShowEvent *);
void hideEvent(QHideEvent *);
GUIInterface* guiInterface;
Settings* settings;
+ bool _changed;
+ #ifndef Q_WS_MAEMO_5
+ QPushButton* closeButton;
+ QHBoxLayout* footerLayout;
+ bool _save;
+
+ private Q_SLOTS:
+ void save();
+ #endif
+
+private Q_SLOTS:
+ void changed();
+
};
#endif // SETTINGSWIDGET_H
void TranslationWidget::show(QStringList translations) {
+ textEdit->clear();
showMaximized();
if(!buttonsInitialized)
initButtons();
#endif
-
- textEdit->clear();
+ textEdit->repaint(this->rect());
+ update(this->rect());
QString trans;
QString t;
QTextDocument *document = textEdit->document();
document->addResource(QTextDocument::ImageResource, QUrl("mydata://image.png"), QVariant(image));
+
trans=tr("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + tr("\n <ar>") + trans + tr("\n </ar>");
trans=XslConversion(trans);
#include "MainWindow.h"
#include "../backbone/backbone.h"
#include "../../includes/translation.h"
+#include "../../includes/Notify.h"
#include <QDebug>
qRegisterMetaType<Translation*>("Translation*");
qRegisterMetaType<QList<Translation*> >("QList<Translation*>");
+ qRegisterMetaType<Notify>("Notify");
+ qRegisterMetaType<Notify::NotifyType>("Notify::NotifyType");
Backbone backbone;
MainWindow w(&backbone);
w.show();
#define NOTIFY_H
#include <QObject>
+#include <QMetaClassInfo>
/*! Notify wraps NotifyType which is interpreted by GUI and may change way in
which GUI handles given notification
class Notify : QObject {
Q_OBJECT
public:
+ Notify() : QObject(0) {}
+ Notify(const Notify&) : QObject(0) {}
enum notifytype {Error, Warning, Info};
Q_DECLARE_FLAGS(NotifyType, notifytype);
};
cachingLabel->setText(tr("Estimated time left: ") +
QString::number(seconds) + tr(" seconds"));
+ if(progress >= 100)
+ this->hide();
+
}
settings->setValue(key, plugin->settings()->value(key));
settings->setValue("path", settingsDialog.dicitonaryFilePath());
- qDebug()<<settingsDialog.generateCache();
if(settingsDialog.generateCache()) {
settings->setValue("generateCache", "true");
}
settings->setValue("generateCache", "false");
}
plugin->setSettings(settings);
- delete settings;
return 0;
}
#include "xdxfplugin.h"
#include <QDebug>
+#include "../../../includes/Notify.h"
XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
_langFrom(tr("")), _langTo(tr("")),_name(tr("")),
}
QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
- //if(_settings->value("cached") == "true")
if(word.indexOf("*")==-1 && word.indexOf("?")==-1 && word.indexOf("_")==-1
&& word.indexOf("%")==-1)
word+="*";
db.setDatabaseName(cacheFilePath);
if(!db.open()) {
qDebug() << "Database error" << db.lastError().text() << endl;
+ Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+ "opened for %1 dictionary. Searching in xdxf file. "
+ "You may want to recache.").arg(name()));
return searchWordListFile(word, limit);
}
word = word.replace("*", "%");
word = word.replace("?", "_");
word = removeAccents(word);
- //qDebug() << word;
QSqlQuery cur(db);
if(limit !=0)
regWord.setPatternSyntax(QRegExp::Wildcard);
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
qDebug()<<"Error: could not open file";
+ Q_EMIT notify(Notify::Warning,
+ QString("Xdxf file cannot be read for %1").arg(name()));
return translations.toList();
}
if(!db.open()) {
qDebug() << "Database error" << db.lastError().text() << endl;
+ Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+ "opened for %1 dictionary. Searching in xdxf file. "
+ "You may want to recache.").arg(name()));
return searchFile(key);
}
QFile dictionaryFile(path);
QString resultString("");
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
- qDebug()<<"Error: could not open file when search";
+ Q_EMIT notify(Notify::Warning,
+ QString("Xdxf file cannot be read for %1").arg(name()));
+ qDebug()<<"Error: could not open file";
return "";
}
QXmlStreamReader reader(&dictionaryFile);
void XdxfPlugin::getDictionaryInfo() {
QFile dictionaryFile(path);
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ Q_EMIT notify(Notify::Warning,
+ QString("Xdxf file cannot be read dictionary"));
qDebug()<<"Error: could not open file";
return;
}
QString format = "png";
QString initialPath = QDir::currentPath() + tr("/xdxf.") + format;
-// qDebug()<<initialPath;
-// QPixmap test(":/icons/xdxf.png");
-// qDebug()<<QPixmap(test).save(initialPath,format.toAscii());
-// qDebug()<<QPixmap("/home/jakub/star.jpg").save(initialPath,format.toAscii());
_infoNote="path=\""+initialPath+"\"> \n" + _name + " [" + _langFrom + "-" + _langTo + "] (" + _type + ")";
QFile dictionaryFile(path);
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ Q_EMIT notify(Notify::Warning,
+ QString("Xdxf file cannot be read for %1 dictionary")
+ .arg(name()));
qDebug()<<"Error: could not open file";
return -1;
}
if (!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ Q_EMIT updateCachingProgress(100, 0);
+ Q_EMIT notify(Notify::Warning,
+ QString("Xdxf file cannot be read for %1 dictionary")
+ .arg(name()));
return 0;
}
db.setDatabaseName(cachePathN);
if(!db.open()) {
qDebug() << "Database error" << db.lastError().text() << endl;
+ Q_EMIT updateCachingProgress(100, 0);
+ Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+ "opened for %1 dictionary. Searching in xdxf file. "
+ "You may want to recache.").arg(name()));
return false;
}
QCoreApplication::processEvents();
if(!cur.next() || countWords() != cur.value(0).toInt())
{
+ Q_EMIT updateCachingProgress(100, timer.restart());
+ Q_EMIT notify(Notify::Warning,
+ QString("Database caching error, please try againg."));
db.close();
return false;
}