Actually delete books from database. Delete all books when "Clear
[dorian] / devtools.cpp
1 #include <QtGui>
2 #include <QDebug>
3
4 #include "devtools.h"
5 #include "trace.h"
6 #include "settings.h"
7 #include "toolbuttonbox.h"
8 #include "bookdb.h"
9
10 DevTools::DevTools(QWidget *parent): Dyalog(parent, false)
11 {
12     setWindowTitle(tr("Developer"));
13     QPushButton *clearSettings = new QPushButton("Clear persistent data", this);
14     connect(clearSettings, SIGNAL(clicked()), this, SLOT(onClear()));
15     addWidget(clearSettings);
16
17     QLabel *level = new QLabel(tr("Trace level:"), this);
18     addWidget(level);
19
20     ToolButtonBox *box = new ToolButtonBox(this);
21     addWidget(box);
22     box->addButton(QtDebugMsg, tr("Debug"));
23     box->addButton(QtWarningMsg, tr("Warning"));
24     box->addButton(QtCriticalMsg, tr("Critical"));
25     box->addButton(QtFatalMsg, tr("Fatal"));
26     box->toggle(Trace::level);
27     connect(box, SIGNAL(buttonClicked(int)),
28             this, SLOT(onLevelButtonClicked(int)));
29     addStretch();
30 }
31
32 void DevTools::onClear()
33 {
34     if (QMessageBox::Yes ==
35         QMessageBox::question(this, tr("Clear persistent data"),
36                               tr("Library and settings will be cleared, "
37                                  "application will be restarted. Continue?"),
38                               QMessageBox::Yes | QMessageBox::No)) {
39         QSettings().clear();
40         BookDb::instance()->removeAll();
41         QApplication::exit(1000);
42     }
43 }
44
45 void DevTools::onLevelButtonClicked(int level) {
46     Trace::level = (QtMsgType)level;
47     Settings::instance()->setValue("tracelevel", level);
48 }