+ Search *search = Search::instance();
+ connect(search, SIGNAL(beginDownload(int)), this, SLOT(onBeginDownload(int)));
+ connect(search,
+ SIGNAL(endDownload(int, const Search::Result &, const QString &)),
+ this,
+ SLOT(onEndDownload(int, const Search::Result &, const QString &)));
+
+ progress = new ProgressDialog(tr("Downloading book"), this);
+}
+
+void SearchResultsDialog::onItemActivated(const QModelIndex &index)
+{
+ TRACE;
+ Search::Result result = results[index.row()];
+ qDebug() << "Book" << index.row() << ":" << result.title;
+ SearchResultInfoDialog *d = new SearchResultInfoDialog(result, this);
+ d->setAttribute(Qt::WA_DeleteOnClose);
+ int ret = d->exec();
+ if (ret == QDialog::Accepted) {
+ qDebug() << "Accepted -> Start download";
+ QString fileName = downloadName();
+ qDebug() << "Downloading to" << fileName;
+ Search::instance()->download(result, fileName);
+ }
+}
+
+QString SearchResultsDialog::downloadName() const
+{
+ TRACE;
+ QString dir = Platform::instance()->downloadDir();
+ QDir().mkpath(dir); // Not sure if this works. QDir API is quiet lame.
+ unsigned i = 0;
+ QString fileName;
+ do {
+ char tmp[9];
+ snprintf(tmp, 8, "%8.8x", i++);
+ tmp[8] = '\0';
+ fileName = QDir(dir).absoluteFilePath(QString(tmp) + ".epub");
+ } while (QFile(fileName).exists());
+ qDebug() << fileName;
+ return fileName;
+}
+
+void SearchResultsDialog::onBeginDownload(int size)
+{
+ Q_UNUSED(size);
+ TRACE;
+ progress->showWait();