Enable tracing to file. Attempt to fix last position restoration on S^3.
[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 #define DORIAN_LOG "dorian.txt"
29
30 #ifdef Q_WS_MAEMO_5
31 #   include <QtMaemo5/QMaemo5InformationBox>
32 #else
33 #   include <QMessageBox>
34 #endif
35
36 QString Platform::dbPath()
37 {
38     QString base(QDir::home().absoluteFilePath(DORIAN_BASE));
39     return QDir(base).absoluteFilePath("books.db");
40 }
41
42 QString Platform::icon(const QString &name)
43 {
44     QString iconName = QString(DORIAN_ICON_PREFIX) + name + ".png";
45     if (QFile(iconName).exists()) {
46         return iconName;
47     } else {
48         return QString(":/icons/") + name + ".png";
49     }
50 }
51
52 void Platform::restart(char *argv[])
53 {
54 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
55     extern char **environ;
56     execve(argv[0], argv, environ);
57 #else
58     Q_UNUSED(argv);
59 #endif
60 }
61
62 QString Platform::version()
63 {
64     return QString(DORIAN_VERSION);
65 }
66
67 QString Platform::downloadDir()
68 {
69     return QDir::home().absoluteFilePath("Books");
70 }
71
72 QString Platform::defaultFont()
73 {
74 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_X11)
75     return QString("Serif");
76 #elif defined(Q_WS_MAC)
77     return QString("Hoefler Text");
78 #elif defined Q_WS_S60
79     return QString("Nokia Sans S60");
80 #else
81     return QString("Times New Roman");
82 #endif
83 }
84
85 void Platform::information(const QString &label, QWidget *parent)
86 {
87 #ifdef Q_WS_MAEMO_5
88     QMaemo5InformationBox::information(parent, label,
89                                        QMaemo5InformationBox::DefaultTimeout);
90 #else
91     (void)QMessageBox::information(parent, QObject::tr("Dorian"), label,
92                                    QMessageBox::Ok);
93 #endif
94 }
95
96 void Platform::showBusy(QWidget *w, bool isBusy)
97 {
98 #ifdef Q_WS_MAEMO_5
99     w->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, isBusy);
100 #else
101     Q_UNUSED(w);
102     Q_UNUSED(isBusy);
103 #endif
104 }
105
106 QString Platform::traceFileName()
107 {
108     return QDir::home().absoluteFilePath(DORIAN_LOG);
109 }