4 #include "searchresultsdialog.h"
5 #include "searchresultinfodialog.h"
8 SearchResultsDialog::SearchResultsDialog(const QList<Search::Result> results_,
9 QWidget *parent): ListWindow(parent), results(results_)
11 setWindowTitle(tr("Search Results"));
13 foreach (Search::Result result, results) {
15 if (result.authors.length()) {
16 author = result.authors[0];
18 data.append(result.title + "\n" + author);
21 QStringListModel *model = new QStringListModel(data, this);
23 list->setSelectionMode(QAbstractItemView::SingleSelection);
24 list->setModel(model);
25 list->setUniformItemSizes(true);
27 addItemAction(tr("Download book"), this, SLOT(onDownload()));
28 connect(list, SIGNAL(activated(const QModelIndex &)),
29 this, SLOT(onItemActivated(const QModelIndex &)));
30 Search *search = Search::instance();
31 connect(search, SIGNAL(beginDownload(int)), this, SLOT(onBeginDownload(int)));
32 connect(search, SIGNAL(endDownload()), this, SLOT(onEndDownload()));
35 void SearchResultsDialog::onItemActivated(const QModelIndex &index)
37 Trace t("SearchResultsDialog::onItemActivated");
38 Search::Result result = results[index.row()];
39 qDebug() << "Book" << index.row() << ":" << result.title;
40 SearchResultInfoDialog *d = new SearchResultInfoDialog(result, this);
41 d->setAttribute(Qt::WA_DeleteOnClose);
43 if (ret == QDialog::Accepted) {
44 qDebug() << "Accepted -> Start download";
45 QString fileName = downloadName();
46 qDebug() << "Downloading to" << fileName;
47 Search::instance()->download(result, fileName);
51 void SearchResultsDialog::onDownload()
53 onItemActivated(list->currentIndex());
56 QString SearchResultsDialog::downloadName() const
59 return QString("/tmp/book.epub");
62 void SearchResultsDialog::onBeginDownload(int size)
64 Trace t("SearchResultsDialog::onBeginDownload");
67 void SearchResultsDialog::onEndDownload()
69 Trace t("SearchResultsDialog::onEndDownload");