X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=searchresultsdialog.cpp;h=15d69772be0819cc1526431e7e30e61dc7fbda6d;hb=6c8d9bb19213aee37517232ef889409200e53ac1;hp=a523839c9eecc5067f117afa94f9f5a6cfc7ec61;hpb=8eea7446dbcf2df23b7633db28d6e8e78bb856f3;p=dorian diff --git a/searchresultsdialog.cpp b/searchresultsdialog.cpp index a523839..15d6977 100644 --- a/searchresultsdialog.cpp +++ b/searchresultsdialog.cpp @@ -1,14 +1,21 @@ +#include + #include +#include +#include +#include -#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 results_, - QWidget *parent): ListWindow(parent), results(results_) + QWidget *parent): ListWindow(tr("(No results)"), parent), results(results_) { - setWindowTitle(tr("Search Results")); + setWindowTitle(tr("Search results")); foreach (Search::Result result, results) { QString author; @@ -19,22 +26,22 @@ SearchResultsDialog::SearchResultsDialog(const QList results_, } QStringListModel *model = new QStringListModel(data, this); - list = new ListView; - list->setSelectionMode(QAbstractItemView::SingleSelection); - list->setModel(model); - list->setUniformItemSizes(true); - addList(list); - addItemAction(tr("Download book"), this, SLOT(onDownload())); - connect(list, SIGNAL(activated(const QModelIndex &)), + setModel(model); + connect(this, SIGNAL(activated(const QModelIndex &)), 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); @@ -48,23 +55,43 @@ void SearchResultsDialog::onItemActivated(const QModelIndex &index) } } -void SearchResultsDialog::onDownload() -{ - onItemActivated(list->currentIndex()); -} - QString SearchResultsDialog::downloadName() const { - // FIXME - return QString("/tmp/book.epub"); + 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) { - Trace t("SearchResultsDialog::onBeginDownload"); + 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) { + model()->removeRow(row); + } + Platform::instance()->information(tr("Downloaded \"%1\"\nand added to the " + "library").arg(result.title), this); + } }