More Symbian fixes.
[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     addButton(tr("Read"), this, SLOT(onReadBook()),
47               QDialogButtonBox::ActionRole);
48     addButton(tr("Delete"), this, SLOT(onRemoveBook()),
49               QDialogButtonBox::DestructiveRole);
50 }
51
52 void InfoDialog::onReadBook()
53 {
54     Library::instance()->setNowReading(Library::instance()->find(book));
55     close();
56 }
57
58 void InfoDialog::onRemoveBook()
59 {
60     if (QMessageBox::Yes ==
61         QMessageBox::question(this, tr("Delete book"),
62             tr("Delete book \"%1\" from library?").arg(book->shortName()),
63             QMessageBox::Yes | QMessageBox::No)) {
64         Library::instance()->remove(Library::instance()->find(book));
65         close();
66     }
67 }