connect(downloadButton, SIGNAL(clicked()),
this, SLOT(downloadFile()));
+
+ connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)),
+ this, SLOT(fileDownloaded(QString)));
}
connect(confirmButton, SIGNAL(clicked()),
}
+void XdxfDialog::fileDownloaded(QString name) {
+ infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
+ _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
+ updateGeometry();
+}
+
void XdxfDialog::initializeUI() {
mainVerticalLayout = new QVBoxLayout;
QHBoxLayout* buttonLayout = new QHBoxLayout;
browseButton = new QPushButton(tr("Browse"));
- browseButton->setMaximumWidth(150);
+ browseButton->setMaximumWidth(100);
downloadButton = new QPushButton(tr("Download"));
downloadButton->setMaximumWidth(150);
void downloadFile();
void setGenerateCache(bool);
void setAccents(bool);
+ void fileDownloaded(QString);
#ifdef Q_WS_MAEMO_5
//! on maemo shows information about checkboxes
#include "XdxfDictDownloadProgressDialog.h"
-XdxfDictDownloadProgressDialog::XdxfDictDownloadProgressDialog(QWidget*parent):
+XdxfDictDownloadProgressDialog::XdxfDictDownloadProgressDialog(QString title, QWidget*parent):
QDialog(parent) {
verticalLayout = new QVBoxLayout(this);
setLayout(verticalLayout);
- setWindowTitle(tr("Downloading dictionary, please wait"));
+ setWindowTitle(title);
downloadProgressBar = new QProgressBar(this);
downloadProgressBar->setMinimum(0);
- downloadProgressBar->setMaximum(100);
+ downloadProgressBar->setMaximum(0);
downloadProgressBar->setTextVisible(true);
- cancelButton = new QPushButton(tr("Cancel"),this);
+ // cancelButton = new QPushButton(tr("Cancel"),this);
- downloadTimeLabel = new QLabel(this);
- downloadTimeLabel->hide();
-
#ifndef Q_WS_MAEMO_5
downloadLabel = new QLabel(this);
- downloadLabel->setText(tr("Downloading dictionary, please wait"));
+ downloadLabel->setText(title);
verticalLayout->addWidget(downloadLabel, 0, Qt::AlignCenter);
#endif
-
- verticalLayout->addWidget(downloadTimeLabel);
verticalLayout->addWidget(downloadProgressBar);
- verticalLayout->addWidget(cancelButton);
-
- connect(cancelButton, SIGNAL(clicked()),
- this, SIGNAL(cancelDownloading()));
-
- time.start();
+ //erticalLayout->addWidget(cancelButton);
setModal(true);
}
void XdxfDictDownloadProgressDialog::reject() {
return;
}
-
-void XdxfDictDownloadProgressDialog::updateDownloadProgress(int progress,
- int time) {
- if(!downloadTimeLabel->isVisible())
- downloadTimeLabel->show();
-
- int seconds = float((100 - progress)*time) / (5*1000);
-
- downloadTimeLabel->setText(tr("Estimated time left: ") +
- tr("%n second(s)", "", seconds));
- if(progress >= 100)
- this->accept();
-}
class XdxfDictDownloadProgressDialog : public QDialog {
Q_OBJECT
public:
- XdxfDictDownloadProgressDialog(QWidget *parent = 0);
+ XdxfDictDownloadProgressDialog(QString title, QWidget *parent = 0);
public Q_SLOTS:
void reject();
- void updateDownloadProgress(int, int);
Q_SIGNALS:
//! signal emitted when user cancels downloading of a dictionary
private:
QLabel* downloadLabel;
- QLabel* downloadTimeLabel;
QProgressBar* downloadProgressBar;
QPushButton* cancelButton;
QVBoxLayout* verticalLayout;
//! used to check the progress of dictionary downloading
- QTime time;
};
#endif // XDXFDICTDOWNLOADPROGRESSDIALOG_H
XdxfDictDownloader::XdxfDictDownloader(QObject *parent) :
QObject(parent) {
parentDialog = 0;
+ process = new QProcess(this);
+
+ connect(process, SIGNAL(finished(int)),
+ this, SLOT(processFinished(int)));
}
this, SLOT(dictListReceived(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://xdxf.revdanica.com/down/")));
+
+ progressDialog = new XdxfDictDownloadProgressDialog(tr("Downloading dictionaries list"), parent);
+ progressDialog->show();
+}
+
+QString XdxfDictDownloader::downloadedFile() {
+ return _downloadedFile;
+}
+
+void XdxfDictDownloader::processFinished(int exitcode) {
+ if(++currentCommand<commands.size()) {
+ process->start(commands[currentCommand]);
+ }
+ else {
+ downloadComplete();
+ }
}
+void XdxfDictDownloader::downloadComplete() {
+ QDir dir("/tmp/mdict");
+ QString dictDirName = dir.entryList().at(2);
+ QFile dictFile("/tmp/mdict/" + dictDirName + "/dict.xdxf");
+ dictFile.copy(QDir::homePath() + "/.mdictionary/" + dictDirName + ".xdxf");
+ QFile::remove("/tmp/" + _fileName);
+
+ _downloadedFile = QDir::homePath() + "/.mdictionary/" + dictDirName + ".xdxf";
+
+ progressDialog->accept();
+ delete progressDialog;
+ emit fileDownloaded(_downloadedFile);
+}
void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) {
+ progressDialog->accept();
+ delete progressDialog;
QString page(QString::fromUtf8(reply->readAll()));
QRegExp regOuter("<td>Icon</td><td>Name</td><td>Archive filename</td><td>Archive file size</td><td>Dict file size</td><td>Number of articles</td><td>From</td><td>To</td><td>Submitted by</td><td>Submition date</td></tr>(.*)</table>");
regOuter.setMinimal(true);
XdxfDictSelectDialog selectDialog(dicts, parentDialog);
- if(selectDialog.exec()==QDialog::accept()) {
+ if(selectDialog.exec()==QDialog::Accepted) {
+
+ progressDialog = new XdxfDictDownloadProgressDialog(tr("Downloading dictionary"), parentDialog);
+ progressDialog->show();
QString url = selectDialog.link();
+ _fileName = url.split('/').last();
+ commands.clear();
+ commands.push_back("rm -rf /tmp/mdict");
+ commands.push_back("mkdir /tmp/mdict");
+ commands.push_back("wget --quiet -P /tmp/ " + url);
+ commands.push_back(QString("tar -xjvf /tmp/") + _fileName + QString(" -C /tmp/mdict"));
+ process->start(commands[0]);
}
}
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <DownloadDict.h>
+#include "XdxfDictDownloadProgressDialog.h"
class XdxfDictDownloader : public QObject {
Q_OBJECT
public:
XdxfDictDownloader(QObject *parent = 0);
+ QString downloadedFile();
public Q_SLOTS:
void download(QWidget* parent);
+Q_SIGNALS:
+ void fileDownloaded(QString);
+
private Q_SLOTS:
void dictListReceived(QNetworkReply*);
+ void processFinished(int);
private:
+ void downloadComplete();
QList<DownloadDict> dicts;
QWidget* parentDialog;
+ QString _downloadedFile;
+ XdxfDictDownloadProgressDialog* progressDialog;
+ QStringList commands;
+ int currentCommand;
+ QProcess* process;
+ QString _fileName;
};
#endif // XDXFDICTDOWNLOADER_H
treeView->setExpandsOnDoubleClick(false);
treeView->setSortingEnabled(true);
+ treeView->sortByColumn(0, Qt::AscendingOrder);
+
+ treeView->resizeColumnToContents(0);
+ treeView->resizeColumnToContents(1);
+ treeView->resizeColumnToContents(2);
+ treeView->resizeColumnToContents(3);
+
// treeView->sortByColumn(0);
layout->addWidget(treeView);
}
void XdxfDictSelectDialog::itemClicked(QModelIndex index) {
- _link = index.model()->data(index, Qt::UserRole);
+ _link = index.model()->data(index, Qt::UserRole).toString();
accept();
}