Clean up volume key handling code.
[dorian] / platform.cpp
1 #include <QtGlobal>
2 #include <QDir>
3
4 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
5 #   include <unistd.h>
6 #endif
7
8 #include "platform.h"
9
10 #if defined(Q_OS_WIN32) || defined(Q_OS_SYMBIAN)
11 #   define DORIAN_BASE "dorian"
12 #else
13 #   define DORIAN_BASE ".dorian"
14 #endif
15
16 #if defined(Q_WS_MAC)
17 #   define DORIAN_ICON_PREFIX ":/icons/mac/"
18 #elif defined(Q_OS_SYMBIAN)
19 #   define DORIAN_ICON_PREFIX ":/icons/symbian/"
20 #else
21 #   define DORIAN_ICON_PREFIX ":/icons/"
22 #endif
23
24 static const char *DORIAN_VERSION =
25 #include "pkg/version.txt"
26 ;
27
28 #ifdef Q_WS_MAEMO_5
29 #   include <QtMaemo5/QMaemo5InformationBox>
30 #else
31 #   include <QMessageBox>
32 #endif
33
34 QString Platform::dbPath()
35 {
36     QString base(QDir::home().absoluteFilePath(DORIAN_BASE));
37     return QDir(base).absoluteFilePath("books.db");
38 }
39
40 QString Platform::icon(const QString &name)
41 {
42     QString iconName = QString(DORIAN_ICON_PREFIX) + name + ".png";
43     if (QFile(iconName).exists()) {
44         return iconName;
45     } else {
46         return QString(":/icons/") + name + ".png";
47     }
48 }
49
50 void Platform::restart(char *argv[])
51 {
52 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
53     extern char **environ;
54     execve(argv[0], argv, environ);
55 #else
56     Q_UNUSED(argv);
57 #endif
58 }
59
60 QString Platform::version()
61 {
62     return QString(DORIAN_VERSION);
63 }
64
65 QString Platform::downloadDir()
66 {
67     return QDir::home().absoluteFilePath("Books");
68 }
69
70 QString Platform::defaultFont()
71 {
72 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_X11)
73     return QString("Serif");
74 #elif defined(Q_WS_MAC)
75     return QString("Hoefler Text");
76 #elif defined Q_WS_S60
77     return QString("Nokia Sans S60");
78 #else
79     return QString("Times New Roman");
80 #endif
81 }
82
83 void Platform::information(const QString &label, QWidget *parent)
84 {
85 #ifdef Q_WS_MAEMO_5
86     QMaemo5InformationBox::information(parent, label,
87                                        QMaemo5InformationBox::DefaultTimeout);
88 #else
89     (void)QMessageBox::information(parent, QObject::tr("Dorian"), label,
90                                    QMessageBox::Ok);
91 #endif
92 }
93
94 void Platform::showBusy(QWidget *w, bool isBusy)
95 {
96 #ifdef Q_WS_MAEMO_5
97     w->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, isBusy);
98 #else
99     Q_UNUSED(w);
100     Q_UNUSED(isBusy);
101 #endif
102 }