4 #include "searchresultsdialog.h"
5 #include "searchresultinfodialog.h"
7 #include "progressdialog.h"
9 SearchResultsDialog::SearchResultsDialog(const QList<Search::Result> results_,
10 QWidget *parent): ListWindow(parent), results(results_)
12 setWindowTitle(tr("Search Results"));
14 foreach (Search::Result result, results) {
16 if (result.authors.length()) {
17 author = result.authors[0];
19 data.append(result.title + "\n" + author);
22 QStringListModel *model = new QStringListModel(data, this);
24 list->setSelectionMode(QAbstractItemView::SingleSelection);
25 list->setModel(model);
26 list->setUniformItemSizes(true);
28 addItemAction(tr("Download book"), this, SLOT(onDownload()));
29 connect(list, SIGNAL(activated(const QModelIndex &)),
30 this, SLOT(onItemActivated(const QModelIndex &)));
31 Search *search = Search::instance();
32 connect(search, SIGNAL(beginDownload(int)), this, SLOT(onBeginDownload(int)));
33 connect(search, SIGNAL(endDownload()), this, SLOT(onEndDownload()));
35 progress = new ProgressDialog(tr("Downloading Book"), this);
38 void SearchResultsDialog::onItemActivated(const QModelIndex &index)
40 Trace t("SearchResultsDialog::onItemActivated");
41 Search::Result result = results[index.row()];
42 qDebug() << "Book" << index.row() << ":" << result.title;
43 SearchResultInfoDialog *d = new SearchResultInfoDialog(result, this);
44 d->setAttribute(Qt::WA_DeleteOnClose);
46 if (ret == QDialog::Accepted) {
47 qDebug() << "Accepted -> Start download";
48 QString fileName = downloadName();
49 qDebug() << "Downloading to" << fileName;
50 Search::instance()->download(result, fileName);
54 void SearchResultsDialog::onDownload()
56 onItemActivated(list->currentIndex());
59 QString SearchResultsDialog::downloadName() const
62 return QString("/tmp/book.epub");
65 void SearchResultsDialog::onBeginDownload(int size)
67 Trace t("SearchResultsDialog::onBeginDownload");
68 progress->setMinimum(0);
69 progress->setMaximum(0);
70 progress->setValue(0);
74 void SearchResultsDialog::onEndDownload()
76 Trace t("SearchResultsDialog::onEndDownload");