parentDialog = 0;
process = new QProcess(this);
+
connect(process, SIGNAL(finished(int)),
this, SLOT(processFinished(int)));
+
+ progressDialog = 0;
+}
+
+XdxfDictDownloader::~XdxfDictDownloader() {
+
}
void XdxfDictDownloader::download(QWidget *parent) {
parentDialog = parent;
+ aborted = false;
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
manager->get(QNetworkRequest(QUrl("http://xdxf.revdanica.com/down/")));
- progressDialog = new XdxfDictDownloadProgressDialog(tr("Downloading dictionaries list"), parent);
+ progressDialog = new XdxfDictDownloadProgressDialog(parent);
+
+ connect(progressDialog, SIGNAL(cancelDownloading()),
+ this, SLOT(breakDownloading()));
+ progressDialog->setText(tr("Downloading dictionaries list"));
progressDialog->show();
}
return _downloadedFile;
}
+
+void XdxfDictDownloader::breakDownloading() {
+ aborted = true;
+ if(process->state() != QProcess::NotRunning) {
+ process->kill();
+ }
+
+ if(progressDialog && progressDialog->isVisible()) {
+ progressDialog->accept();
+ }
+
+ Q_EMIT notify(Notify::Info, tr("Downloading canceled"));
+}
+
void XdxfDictDownloader::processFinished(int exitcode) {
+ if(aborted) return;
+ if(exitcode != 0) {
+ Q_EMIT notify(Notify::Error, tr("Error while downloading or processing dictionary"));
+ }
if(++currentCommand<commands.size()) {
process->start(commands[currentCommand]);
}
}
void XdxfDictDownloader::downloadComplete() {
+<<<<<<< HEAD
+ if(aborted) return;
// Downloaded tar file name is different than extracted folder so we need
// some clean directory to identify extracted files
QDir dir("/tmp/mdict");
progressDialog->accept();
delete progressDialog;
+ progressDialog = 0;
+
emit fileDownloaded(_downloadedFile);
}
void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) {
+ if(aborted) return;
progressDialog->accept();
- delete progressDialog;
+
+ if(reply->error() != QNetworkReply::NoError) {
+ Q_EMIT notify(Notify::Error, reply->errorString());
+ return;
+ }
+
QString page(QString::fromUtf8(reply->readAll()));
// You can look at http://xdxf.revdanica.com/down/, we need to get table
QRegExp regInner("<tr>.*</tr>");
regInner.setMinimal(true);
int pos = 0;
- QStringList tmp;
+
while ((pos = regInner.indexIn(page, pos)) != -1) {
- dicts.append(DownloadDict(regInner.cap(0)));
+ DownloadDict temp = DownloadDict(regInner.cap(0));
+ if(!temp.fromLang().isEmpty())
+ dicts.append(temp);
pos += regInner.matchedLength();
}
if(selectDialog.exec()==QDialog::Accepted) {
- progressDialog = new XdxfDictDownloadProgressDialog(tr("Downloading dictionary"), parentDialog);
+ progressDialog->setText(tr("Downloading dictionary"));
progressDialog->show();
+
QString url = selectDialog.link();
_fileName = url.split('/').last();