Maintain date added and date last opened.
[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         if (book->dateAdded.isValid()) {
50             QLabel *added = new QLabel("Added to library: " +
51                 book->dateAdded.toString(Qt::SystemLocaleShortDate), this);
52             added->setWordWrap(true);
53             addWidget(added);
54         }
55         if (book->dateOpened.isValid()) {
56             QLabel *opened = new QLabel("Last read: " +
57                 book->dateOpened.toString(Qt::SystemLocaleShortDate), this);
58             opened->setWordWrap(true);
59             addWidget(opened);
60         }
61         addStretch();
62     }
63
64     addButton(tr("Read"), this, SLOT(onReadBook()),
65               QDialogButtonBox::ActionRole);
66     addButton(tr("Delete"), this, SLOT(onRemoveBook()),
67               QDialogButtonBox::DestructiveRole);
68 }
69
70 void InfoDialog::onReadBook()
71 {
72     done(InfoDialog::Read);
73 }
74
75 void InfoDialog::onRemoveBook()
76 {
77     if (QMessageBox::Yes ==
78         QMessageBox::question(this, tr("Delete book"),
79             tr("Delete book \"%1\" from library?").arg(book->shortName()),
80             QMessageBox::Yes | QMessageBox::No)) {
81         done(InfoDialog::Delete);
82     }
83 }