Rename Dialog to Dyalog. Create About dialog box.
[dorian] / infodialog.cpp
1 #include <QtGui>
2
3 #include "infodialog.h"
4 #include "book.h"
5 #include "library.h"
6
7 InfoDialog::InfoDialog(Book *b, QWidget *parent): Dyalog(parent), book(b)
8 {
9     setWindowTitle(tr("Book Details"));
10
11     if (book) {
12         QLabel *title = new QLabel(book->title, this);
13         addWidget(title);
14         if (book->subject != "") {
15             QLabel *subject = new QLabel(book->subject, this);
16             addWidget(subject);
17         }
18         if (book->creators.size()) {
19             QLabel *creators = new QLabel(this);
20             QString c = "By " + book->creators[0];
21             for (int i = 1; i < book->creators.size(); i++) {
22                 c += ", " + book->creators[i];
23             }
24             creators->setText(c);
25             addWidget(creators);
26         }
27         QLabel *path = new QLabel("File: " + book->path(), this);
28         addWidget(path);
29         if (book->publisher != "") {
30             QLabel *publisher =
31                     new QLabel("Published by " + book->publisher, this);
32             addWidget(publisher);
33         }
34         if (book->source != "") {
35             QLabel *source = new QLabel("Source: " + book->source, this);
36             addWidget(source);
37         }
38         if (book->rights != "") {
39             QLabel *rights = new QLabel(book->rights, this);
40             addWidget(rights);
41         }
42         addStretch();
43     }
44
45     QPushButton *read = new QPushButton(tr("Read"), this);
46     QPushButton *remove = new QPushButton(tr("Delete"), this);
47     connect(read, SIGNAL(clicked()), this, SLOT(onReadBook()));
48     connect(remove, SIGNAL(clicked()), this, SLOT(onRemoveBook()));
49     addButton(read, QDialogButtonBox::ActionRole);
50     addButton(remove, QDialogButtonBox::DestructiveRole);
51 }
52
53 void InfoDialog::onReadBook()
54 {
55     Library::instance()->setNowReading(Library::instance()->find(book));
56     close();
57 }
58
59 void InfoDialog::onRemoveBook()
60 {
61     if (QMessageBox::Yes ==
62         QMessageBox::question(this, tr("Delete book"),
63             tr("Delete book \"%1\" from library?").arg(book->shortName()),
64             QMessageBox::Yes | QMessageBox::No)) {
65         Library::instance()->remove(Library::instance()->find(book));
66         close();
67     }
68 }