Improve icons. Move some menu items to the toolbar. Don't show buttons in current...
[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, bool showButtons):
8         Dyalog(parent, showButtons), book(b)
9 {
10     setWindowTitle(tr("Book Details"));
11
12     if (book) {
13         QLabel *title = new QLabel(book->title, this);
14         addWidget(title);
15         if (book->subject != "") {
16             QLabel *subject = new QLabel(book->subject, this);
17             addWidget(subject);
18         }
19         if (book->creators.size()) {
20             QLabel *creators = new QLabel(this);
21             QString c = "By " + book->creators[0];
22             for (int i = 1; i < book->creators.size(); i++) {
23                 c += ", " + book->creators[i];
24             }
25             creators->setText(c);
26             addWidget(creators);
27         }
28         QLabel *path = new QLabel("File: " + book->path(), this);
29         addWidget(path);
30         if (book->publisher != "") {
31             QLabel *publisher =
32                     new QLabel("Published by " + book->publisher, this);
33             addWidget(publisher);
34         }
35         if (book->source != "") {
36             QLabel *source = new QLabel("Source: " + book->source, this);
37             addWidget(source);
38         }
39         if (book->rights != "") {
40             QLabel *rights = new QLabel(book->rights, this);
41             addWidget(rights);
42         }
43         addStretch();
44     }
45
46     QPushButton *read = new QPushButton(tr("Read"), this);
47     QPushButton *remove = new QPushButton(tr("Delete"), this);
48     connect(read, SIGNAL(clicked()), this, SLOT(onReadBook()));
49     connect(remove, SIGNAL(clicked()), this, SLOT(onRemoveBook()));
50     addButton(read, QDialogButtonBox::ActionRole);
51     addButton(remove, QDialogButtonBox::DestructiveRole);
52 }
53
54 void InfoDialog::onReadBook()
55 {
56     Library::instance()->setNowReading(Library::instance()->find(book));
57     close();
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         Library::instance()->remove(Library::instance()->find(book));
67         close();
68     }
69 }