_settings = QHash<QString, QString>(set->_settings);
}
- /*! \returns value fo a given key
- \param key name of a given setting
- \return value of a given setting
+ /*!
+ \returns value fo a given key
+ \param key name of a given setting
+ \return value of a given setting
*/
QString value(const QString key) const {
if(!_settings.contains(key)) {
setWindowFlags(windowFlags() | Qt::Window);
#endif
-
initializeUI();
setWindowTitle("mDictionary");
initButtons();
#endif
- // webkit->repaint(this->rect());
- // update(this->rect());
-
- QString trans;
- QString t;
-
- foreach(t, translations) {
- trans += t + "\n";
- }
-
-
- trans=QString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + QString("\n <ar>")
- + trans + QString("\n </ar>");
-
- trans=checkTranslation(trans);
- qDebug()<<"\n\n trans"<<trans;
- trans=XslConversion(trans);
+ QString trans= createTranslation(translations);
QString head = "<html><head>";
- head += "<link rel=\"stylesheet\" type=\"text/css\" " ;
- head += "href=\"/usr/share/mdictionary/css/" "style.css";
- head += "\" /></head><body ondragstart=\"return false\">";
- trans = head + trans;
+ head += "<link rel=\"stylesheet\" type=\"text/css\" "
+ "href=\"/usr/share/mdictionary/css/" "style.css"
+ "\" /></head><body ondragstart=\"return false\">";
+ trans = head + trans + "</body></html>";
- trans+= "</body></html>";
trans.replace("$STAR$", "/usr/share/mdictionary/staron.png");
- // qDebug()<<"\n\n trans"<<trans;
webkit->setHtml(trans, QUrl().fromLocalFile("/"));
- //webkit->repaint(this->rect());
- //update(this->rect());
+}
+
- // Q_EMIT updateSize();
+QString TranslationWidget::createTranslation(QStringList translations) {
+ QString trans;
+ if(!translations.size())
+ return QString("Empty translation");
+ int element=-1;
+ do{
+ int a=0;
+ foreach(QString t, translations){
+ if(a!=element)
+ trans += t + "\n";
+ a++;
+ }
+ trans=QString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + QString("\n <ar>")
+ + trans + QString("\n </ar>");
+
+ trans=checkTranslation(trans);
+ trans=XslConversion(trans);
+ element++;
+ if(element>translations.size())
+ return QString("Empty translation");
+ } while(trans==""); // trans=="" only when XslConversation have a error;
+ return trans;
}
+
QString TranslationWidget::XslConversion(QString translation)
{
QXmlQuery myQuery(QXmlQuery::XSLT20);
return result;
}
+
QString TranslationWidget::checkTranslation(QString trans){
/*check all "&"*/
int pos=0;
int pos2;
int count=0;
+ /*check "<" and ">" in key */
while(pos!=-1){
pos=trans.indexOf("&",pos+1);
pos2=trans.indexOf("amp;",pos);
trans.insert(pos+1,"amp;");
}
-
- /*check all "<" and ">" in key */
+ /*check "<" and ">" in key */
pos=0;
count=0;
while(pos<trans.size()){
if(pos==trans.indexOf("<key>",pos)){
- qDebug()<<"key";
count++;
pos+=4;
}
pos++;
}
+ /*checking unclosed tag's*/
+ pos=0;
+ count=0;
+ while(pos<trans.size()){
+ if(trans.at(pos)=='<')
+ count++;
+ else if(trans.at(pos)=='>')
+ count--;
+ if(count==-1){ // remove ">"
+ trans.remove(pos,1);
+ count=0;
+ }
+ pos++;
+ }
+ pos=trans.size()-1;
+ count=0;
+ while(pos>-1){
+ if(trans.at(pos)=='>')
+ count++;
+ else if(trans.at(pos)=='<')
+ count--;
+ if(count==-1){ // remove "<"
+ trans.remove(pos,1);
+ count=0;
+ }
+ pos--;
+ }
- /*check all """ and "'" */
+ /*check """ and "'" */
pos=0;
count=0;
while(pos<trans.size()){
return trans;
}
+
#ifdef Q_WS_MAEMO_5
void TranslationWidget::initButtons() {
-
int x = width() - showButtonsButton->sizeHint().width();
int y = height() - showButtonsButton->sizeHint().height();
showButtonsButton->move(QPoint(x,y));
showButtonsButton->show();
-
-
x = width() - zoomOutButton->sizeHint().width();
y = height() - 2*zoomOutButton->sizeHint().height();
zoomOutButton->move(QPoint(x, height()));
- zoomOutButtonAnimation =
- new QPropertyAnimation(zoomOutButton, "pos", this);
-
+ zoomOutButtonAnimation = new QPropertyAnimation(zoomOutButton,
+ "pos", this);
zoomOutButtonAnimation->setStartValue(QPoint(x, height()));
zoomOutButtonAnimation->setEndValue(QPoint(x,y));
zoomOutButtonAnimation->setDuration(200);
zoomOutButtonAnimation->setEasingCurve(QEasingCurve::InOutBack);
-
-
x = width() - zoomInButton->sizeHint().width();
y = height() - 3*zoomInButton->sizeHint().height();
zoomInButton->move(QPoint(x, height()));
- zoomInButtonAnimation =
- new QPropertyAnimation(zoomInButton, "pos", this);
-
+ zoomInButtonAnimation = new QPropertyAnimation(zoomInButton,
+ "pos", this);
zoomInButtonAnimation->setStartValue(QPoint(x, height()));
zoomInButtonAnimation->setEndValue(QPoint(x,y));
zoomInButtonAnimation->setDuration(400);
zoomInButtonAnimation->setEasingCurve(QEasingCurve::InOutBack);
-
-
x = 0;
y = height() - copyButton->sizeHint().height();
copyButton->move(QPoint(x, height()));
-
- copyButtonAnimation =
- new QPropertyAnimation(copyButton, "pos", this);
-
+ copyButtonAnimation = new QPropertyAnimation(copyButton, "pos", this);
copyButtonAnimation->setStartValue(QPoint(x, height()));
copyButtonAnimation->setEndValue(QPoint(x,y));
copyButtonAnimation->setDuration(200);
copyButtonAnimation->setEasingCurve(QEasingCurve::InOutBack);
-
-
x = 0;
y = height() - 2*copyButton->sizeHint().height();
selectAllButton->move(QPoint(x, height()));
-
- selectAllButtonAnimation =
- new QPropertyAnimation(selectAllButton, "pos", this);
-
+ selectAllButtonAnimation = new QPropertyAnimation(selectAllButton,
+ "pos", this);
selectAllButtonAnimation->setStartValue(QPoint(x, height()));
selectAllButtonAnimation->setEndValue(QPoint(x,y));
selectAllButtonAnimation->setDuration(400);
selectAllButtonAnimation->setEasingCurve(QEasingCurve::InOutBack);
-
-
x = 0;
y = height() - 3*copyButton->sizeHint().height();
searchButton->move(QPoint(x, height()));
-
- searchButtonAnimation =
- new QPropertyAnimation(searchButton, "pos", this);
-
+ searchButtonAnimation = new QPropertyAnimation(searchButton,
+ "pos", this);
searchButtonAnimation->setStartValue(QPoint(x, height()));
searchButtonAnimation->setEndValue(QPoint(x,y));
searchButtonAnimation->setDuration(600);
searchButtonAnimation->setEasingCurve(QEasingCurve::InOutBack);
-
-
-
buttonsAnimation = new QParallelAnimationGroup(this);
buttonsAnimation->addAnimation(zoomInButtonAnimation);
buttonsAnimation->addAnimation(zoomOutButtonAnimation);
#endif
void TranslationWidget::initializeUI() {
-
webkit = new TranslationView(this);
Settings* set = guiinterface->settings();
qreal fac = set->value("zoom").toFloat();
private:
QString XslConversion(QString translation);
QString checkTranslation(QString trans);
+ QString createTranslation(QStringList translations);
QToolButton* zoomInToolButton;
QToolButton* zoomOutToolButton;
TranslationView *webkit;
Copyright 2010 Comarch S.A.
*******************************************************************************/
-
-/*! \file GoogleSettingsDialog.cpp
+/*!
+ \file GoogleSettingsDialog.cpp
\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
*/
void GoogleDialog::initializeUI() {
+ int i=0,j=0;
+ int actualLangTo=0;
+ int actualLangFrom=0;
+
setWindowTitle(tr("Google Plugin Settings"));
langFromLabel = new QLabel(tr("From:"));
verticalLayout = new QVBoxLayout;
setLayout(verticalLayout);
-
langLayout = new QVBoxLayout;
langsFormLayout = new QFormLayout;
changeLangLayout = new QHBoxLayout;
-
#ifdef Q_WS_MAEMO_5
setMinimumHeight(370);
changeLangButton=new QPushButton(
- QIcon::fromTheme("general_refresh"), "");
+ QIcon::fromTheme("general_refresh"), "");
#else
changeLangButton=new QPushButton(
QIcon::fromTheme("object-flip-vertical"),"");
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 j=0;
- int actualLangTo=0;
- int actualLangFrom=0;
-
foreach(QString langs, GooglePlugin::languages.keys()){
if(langs==_langTo)
actualLangTo=j;
langLayout->addLayout(langsFormLayout);
langsFormLayout->addRow(langFromLabel, langFromComboBox);
-
langsFormLayout->addRow(langToLabel, langToComboBox);
changeLangLayout->addLayout(langLayout);
verticalLayout->addWidget(confirmButton);
setModal(true);
-
setMinimumSize(sizeHint());
setMaximumSize(sizeHint());
}
+
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();
+void GoogleDialog::changeLangButtonClicked() {
int indexTo=langToComboBox->findText(langFromComboBox->currentText());
int indexFrom=langFromComboBox->findText(langToComboBox->currentText());
langToComboBox->setCurrentIndex(indexTo);
langFromComboBox->setCurrentIndex(indexFrom);
}
-
- // langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
- //langFromComboBox->setCurrentIndex(tempIndexTo);
}
+
void GoogleDialog::accept() {
saveSettings();
-
QDialog::accept();
}
+
void GoogleDialog::saveSettings() {
_settings = new Settings;
if(plugin) {
GooglePlugin::languages.value(_langFrom));
}
+
Settings* GoogleDialog::getSettings() {
return _settings;
}
Copyright 2010 Comarch S.A.
*******************************************************************************/
-
/*!
\file GoogleDialog.cpp
\author Mateusz Półrola <mateusz.polrola@gmail.com>
GoogleDialogType type = New,
QWidget* parent = 0);
-
//! \returns settings of plugin
/*!
After acceptance of dialog this method returns plugin's settings based on
Copyright 2010 Comarch S.A.
*******************************************************************************/
-
-/*! \file GoogleDictDialog.cpp
+/*!
+ \file GoogleDictDialog.cpp
\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
*/
this->plugin = plugin;
}
+
Settings* GoogleDictDialog::addNewDictionary(QWidget *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) {
+ if(d.exec() == QDialog::Accepted)
return d.getSettings();
- }
-
return 0;
}
connect(&d, SIGNAL(notify(Notify::NotifyType,QString)),
this, SIGNAL(notify(Notify::NotifyType,QString)));
- if(d.exec() == QDialog::Accepted) {
+ if(d.exec() == QDialog::Accepted)
plugin->setSettings(d.getSettings());
- }
}
Copyright 2010 Comarch S.A.
*******************************************************************************/
-
/*! \file GoogleDictDialog.h
\brief Class launches dialog which generates a new dictionary, or changes
settings
public:
explicit GoogleDictDialog(GooglePlugin* plugin, QObject *parent = 0);
/*!
- Shows "add new google dictionary" dialog and returns settings of a new dict
- \param parent parent widget on which dialog will be displayed
- */
+ Shows "add new google dictionary" dialog and returns settings of a new dict
+ \param parent parent widget on which dialog will be displayed
+ */
Settings* addNewDictionary(QWidget *parent);
/*!
- Shows "settings" dialog and saves new settings in plugin
- \param parent parent widget on which dialog will be displayed
- */
+ Shows "settings" dialog and saves new settings in plugin
+ \param parent parent widget on which dialog will be displayed
+ */
void changeSettings(QWidget *parent);
private:
Copyright 2010 Comarch S.A.
*******************************************************************************/
-
-/*! \file GooglePlugin.cpp
+/*!
+ \file GooglePlugin.cpp
\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
*/
void GooglePlugin::retranslate() {
QString locale = QLocale::system().name();
-
QTranslator *translator = new QTranslator(this);
-
if(!translator->load(":/google/translations/" + locale)) {
translator->load(":/google/translations/en_US");
}
QString GooglePlugin::search(QString) {
- qDebug() << "function is not used in this plugin";
+ qDebug() << "function is not used in google plugin";
return QString("");
}
if(isAvailable()) {
QString error("");
char wrongChar[]={"*?&<>"};
- for(unsigned int a=0;a<sizeof(wrongChar);a++){ /*remove wrong char*/
+ for(unsigned int a=0;a<sizeof(wrongChar);a++) /*remove wrong char*/
word.replace(wrongChar[a],"");
- }
QString url=QString("/translate_a/t?client=t&sl=%1&tl=%2").arg(
_settings->value("lang_from"),
error=http->errorString();
if(lastState!=http->state()) {
lastState=http->state();
- if(lastState==0){
+ if(lastState==0)
done();
- }
}
}
if(error!="" && error!="Unknown error") {
QString GooglePlugin::jsonParse(QString result) {
- //qDebug()<<"Json"<<result;
int pos=0,pos2=0,index=0,size=0;
QString returnLang;
QString translation;
}
returnLang=list1.at(index*2+1);
if(partOfSpeach.size()==0){
- if(translation.toLower()==original.toLower()){
+ if(translation.toLower()==original.toLower())
return QString(""); // word doesn't exist";
- }
else
return "\""+translation+"\"";
}
result+=words.at(i)->at(j)+", ";
result.remove(result.size()-2,2);
}
- //qDebug()<<"PO"<<result;
return result;
}
Copyright 2010 Comarch S.A.
*******************************************************************************/
-
-/*! \file GooglePlugin.h
-
+/*!
+ \file GooglePlugin.h
\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
*/
//! sets the language from which the translation is done
void setLangFrom(QString langFrom);
- /*! \returns DictDialog object that creates dialogs
+ /*!
+ \returns DictDialog object that creates dialogs
for adding new dictionaries and changing plugin things
- */
+ */
DictDialog* dictDialog();
//! \returns new, clean copy of plugin with settings set as in Settings*
Copyright 2010 Comarch S.A.
*******************************************************************************/
-
-/*! \file TranslationGoogle.h
+/*!
+ \file TranslationGoogle.h
\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
*/
//! \return parsed raw format into xml
QString toXml() const;
- /*! sets the word for which we want to find a translation
- \param word for which we want to find a translation */
+ /*!
+ sets the word for which we want to find a translation
+ \param word for which we want to find a translation
+ */
void setKey(QString);
//! sets information about dictionary
//! \return whether given translation is taken from bookmarks
int isBookmark() const {
return _bookmark;
- }
+ }
//! \returns corresponding dict object
uint dict() const {return _dictHash;}
QString StarDictPlugin::interpret(QByteArray::iterator it,
QByteArray::iterator end, QChar mode,QString key, bool last) {
QString result;
- qDebug()<<"****** mode: "<<mode;
-
+// qDebug()<<"****** mode: "<<mode;
if(mode == 'm' ||
mode == 'l' ||
mode == 'g' ||
} else
result += read(it++, end);
} */
-
- qDebug()<<"wynik "<<result;
return result;
}
#else
if(type==New) {
infoLabel->setMinimumWidth(250);
- setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
- setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
#endif
#include <QDebug>
#include <QProcess>
#include <bzlib.h>
-#ifndef Q_WS_MAEMO_5
-#include <libtar.h>
-#endif
#include <stdio.h>
#include <fcntl.h>
+#ifndef Q_WS_MAEMO_5
+ #include <libtar.h>
+#endif
+
+
typedef void BZFILE;
+
XdxfDictDownloader::XdxfDictDownloader(QObject *parent) :
QObject(parent) {
parentDialog = 0;
progressDialog->show();
QString url = selectDialog.link();
-
_fileName = url.split('/').last();
QProcess clean;
if(err == -1)
return false;
- err = tar_extract_all(t,"/tmp/mdict/");
+ char text[]={"/tmp/mdict/"};
+ err = tar_extract_all(t,text);
if(err == -1) {
return false;
}