+#include <stdio.h>
#include <QtGui>
+#ifdef Q_WS_MAEMO_5
+#include <QtMaemo5/QMaemo5InformationBox>
+#endif
+
#include "listview.h"
#include "searchresultsdialog.h"
#include "searchresultinfodialog.h"
#include "trace.h"
#include "progressdialog.h"
+#include "library.h"
+#include "platform.h"
SearchResultsDialog::SearchResultsDialog(const QList<Search::Result> results_,
QWidget *parent): ListWindow(parent), results(results_)
this, SLOT(onItemActivated(const QModelIndex &)));
Search *search = Search::instance();
connect(search, SIGNAL(beginDownload(int)), this, SLOT(onBeginDownload(int)));
- connect(search, SIGNAL(endDownload()), this, SLOT(onEndDownload()));
+ 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 t("SearchResultsDialog::onItemActivated");
+ TRACE;
Search::Result result = results[index.row()];
qDebug() << "Book" << index.row() << ":" << result.title;
SearchResultInfoDialog *d = new SearchResultInfoDialog(result, this);
QString SearchResultsDialog::downloadName() const
{
- // FIXME
- return QString("/tmp/book.epub");
+ TRACE;
+ QString dir = Platform::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)
{
- Trace t("SearchResultsDialog::onBeginDownload");
- progress->setMinimum(0);
- progress->setMaximum(0);
- progress->setValue(0);
- progress->show();
+ Q_UNUSED(size);
+ TRACE;
+ progress->showWait();
}
-void SearchResultsDialog::onEndDownload()
+void SearchResultsDialog::onEndDownload(int status, const Search::Result &result,
+ const QString &fileName)
{
- Trace t("SearchResultsDialog::onEndDownload");
+ Q_UNUSED(result);
+ TRACE;
progress->reset();
+ if (Search::Ok == status) {
+ Library::instance()->add(fileName);
+ int row = results.indexOf(result);
+ if (-1 != row) {
+ list->model()->removeRow(row);
+ }
+#ifdef Q_WS_MAEMO_5
+ QMaemo5InformationBox::information(this,
+ tr("Downloaded \"%1\"\nand added to the library").arg(result.title),
+ QMaemo5InformationBox::DefaultTimeout);
+#endif
+ }
}