621eaaa684eba1c501fabfe0ac5e267d571bf137
[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         title->setWordWrap(true);
18         addWidget(title);
19         if (book->subject != "") {
20             QLabel *subject = new QLabel(book->subject, this);
21             subject->setWordWrap(true);
22             addWidget(subject);
23         }
24         if (book->creators.size()) {
25             QLabel *creators = new QLabel(this);
26             creators->setWordWrap(true);
27             creators->setText(book->creators.join(", "));
28             addWidget(creators);
29         }
30         QLabel *path = new QLabel("File: " + book->path(), this);
31         path->setWordWrap(true);
32         addWidget(path);
33         if (book->publisher != "") {
34             QLabel *publisher =
35                     new QLabel("Published by " + book->publisher, this);
36             publisher->setWordWrap(true);
37             addWidget(publisher);
38         }
39         if (book->source != "") {
40             QLabel *source = new QLabel("Source: " + book->source, this);
41             source->setWordWrap(true);
42             addWidget(source);
43         }
44         if (book->rights != "") {
45             QLabel *rights = new QLabel(book->rights, this);
46             rights->setWordWrap(true);
47             addWidget(rights);
48         }
49         addStretch();
50     }
51
52     addButton(tr("Read"), this, SLOT(onReadBook()),
53               QDialogButtonBox::ActionRole);
54     addButton(tr("Delete"), this, SLOT(onRemoveBook()),
55               QDialogButtonBox::DestructiveRole);
56 }
57
58 void InfoDialog::onReadBook()
59 {
60     done(InfoDialog::Read);
61 }
62
63 void InfoDialog::onRemoveBook()
64 {
65     if (QMessageBox::Yes ==
66         QMessageBox::question(this, tr("Delete book"),
67             tr("Delete book \"%1\" from library?").arg(book->shortName()),
68             QMessageBox::Yes | QMessageBox::No)) {
69         done(InfoDialog::Delete);
70     }
71 }