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