search.cpp \
widgets/flickable.cpp \
widgets/listview.cpp \
- searchresultsdialog.cpp
+ searchresultsdialog.cpp \
+ searchresultinfodialog.cpp
HEADERS += \
mainwindow.h \
searchdialog.h \
search.h \
widgets/flickable.h \
- searchresultsdialog.h
+ searchresultsdialog.h \
+ searchresultinfodialog.h
RESOURCES += \
dorian.qrc
r.title = titles[0];
}
r.language = cols[4].toPlainText().trimmed();
+ r.source = "Project Gutenberg";
searchResults.append(r);
qDebug() << id;
qDebug() << " Authors:" << r.authors;
--- /dev/null
+#include <QtGui>
+
+#include "searchresultinfodialog.h"
+#include "search.h"
+#include "trace.h"
+
+SearchResultInfoDialog::SearchResultInfoDialog(const Search::Result &result_,
+ QWidget *parent):
+ Dyalog(parent), result(result_)
+{
+ setWindowTitle(tr("Book Details"));
+
+ QLabel *title = new QLabel(result.title, this);
+ addWidget(title);
+ if (result.authors.size()) {
+ QLabel *creators = new QLabel(this);
+ QString c = "By " + result.authors[0];
+ for (int i = 1; i < result.authors.size(); i++) {
+ c += ", " + result.authors[i];
+ }
+ creators->setText(c);
+ creators->setWordWrap(true);
+ addWidget(creators);
+ }
+ QLabel *source = new QLabel(tr("Source: %1").arg(result.source), this);
+ addWidget(source);
+ addStretch();
+ addButton(tr("Download"), this, SLOT(accept()), QDialogButtonBox::ActionRole);
+ addButton(tr("Close"), this, SLOT(reject()), QDialogButtonBox::DestructiveRole);
+}
--- /dev/null
+#ifndef SEARCHRESULTINFODIALOG_H
+#define SEARCHRESULTINFODIALOG_H
+
+#include "dyalog.h"
+#include "search.h"
+
+class SearchResultInfoDialog: public Dyalog
+{
+ Q_OBJECT
+public:
+ explicit SearchResultInfoDialog(const Search::Result &result,
+ QWidget *parent = 0);
+
+private:
+ const Search::Result &result;
+};
+
+#endif // SEARCHRESULTINFODIALOG_H
#include "listview.h"
#include "searchresultsdialog.h"
+#include "searchresultinfodialog.h"
+#include "trace.h"
SearchResultsDialog::SearchResultsDialog(const QList<Search::Result> results_,
QWidget *parent): ListWindow(parent), results(results_)
list->setModel(model);
list->setUniformItemSizes(true);
addList(list);
+ addItemAction(tr("Download book"), this, SLOT(onDownload()));
connect(list, SIGNAL(activated(const QModelIndex &)),
this, SLOT(onItemActivated(const QModelIndex &)));
}
+void SearchResultsDialog::onItemActivated(const QModelIndex &index)
+{
+ Trace t("SearchResultsDialog::onItemActivated");
+ 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";
+ }
+}
+
+void SearchResultsDialog::onDownload()
+{
+ onItemActivated(list->currentIndex());
+}
#include "search.h"
class ListView;
+class QModelIndex;
class SearchResultsDialog: public ListWindow
{
+ Q_OBJECT
+
public:
explicit SearchResultsDialog(const QList<Search::Result> searchResults,
QWidget *parent = 0);
+protected slots:
+ void onDownload();
+ void onItemActivated(const QModelIndex &index);
+
protected:
const QList<Search::Result> results;
ListView *list;