More on model.
[dorian] / infodialog.cpp
1 #include <QtGui>
2
3 #include "infodialog.h"
4 #include "info.h"
5 #include "book.h"
6 #include "library.h"
7
8 InfoDialog::InfoDialog(Book *book_, QWidget *parent):
9         QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
10                 Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint),
11         book(book_)
12 {
13     setWindowTitle(tr("Book Details"));
14     Info *info = new Info(book);
15     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical, this);
16     QPushButton *read = new QPushButton(tr("Read"), this);
17     QPushButton *remove = new QPushButton(tr("Delete"), this);
18     connect(read, SIGNAL(clicked()), this, SLOT(onReadBook()));
19     connect(remove, SIGNAL(clicked()), this, SLOT(onRemoveBook()));
20     buttonBox->addButton(read, QDialogButtonBox::ActionRole);
21     buttonBox->addButton(remove, QDialogButtonBox::ActionRole);
22
23     QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
24     horizontalLayout->addWidget(info);
25     horizontalLayout->addWidget(buttonBox);
26     setLayout(horizontalLayout);
27 }
28
29 void InfoDialog::onReadBook()
30 {
31     Library::instance()->setNowReading(Library::instance()->find(book));
32     close();
33 }
34
35 void InfoDialog::onRemoveBook()
36 {
37     QString title = book->name();
38     if (QMessageBox::Yes ==
39         QMessageBox::question(this, "Delete book", "Delete book " + title,
40                               QMessageBox::Yes
41 #ifndef Q_WS_MAEMO_5
42                               , QMessageBox::No
43 #endif
44                               )) {
45         Library::instance()->remove(Library::instance()->find(book));
46         close();
47     }
48 }