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