Update splash pixmap.
[dorian] / platform.cpp
1 #include <QtGlobal>
2 #include <QDir>
3 #include <QtGui>
4
5 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
6 #   include <unistd.h>
7 #endif
8
9 #include "platform.h"
10
11 #if defined(Q_OS_WIN32) || defined(Q_OS_SYMBIAN)
12 #   define DORIAN_BASE "dorian"
13 #else
14 #   define DORIAN_BASE ".dorian"
15 #endif
16
17 #if defined(Q_WS_MAC)
18 #   define DORIAN_ICON_PREFIX ":/icons/mac/"
19 #elif defined(Q_OS_SYMBIAN)
20 #   define DORIAN_ICON_PREFIX ":/icons/symbian/"
21 #else
22 #   define DORIAN_ICON_PREFIX ":/icons/"
23 #endif
24
25 static const char *DORIAN_VERSION =
26 #include "pkg/version.txt"
27 ;
28
29 #define DORIAN_LOG "dorian.txt"
30
31 #ifdef Q_WS_MAEMO_5
32 #   include <QtMaemo5/QMaemo5InformationBox>
33 #else
34 #   include <QMessageBox>
35 #endif
36
37 static Platform *theInstance;
38
39 Platform *Platform::instance()
40 {
41     if (!theInstance) {
42         theInstance = new Platform();
43     }
44     return theInstance;
45 }
46
47 void Platform::close()
48 {
49     delete theInstance;
50     theInstance = 0;
51 }
52
53 QString Platform::dbPath()
54 {
55     QString base(QDir::home().absoluteFilePath(DORIAN_BASE));
56     return QDir(base).absoluteFilePath("books.db");
57 }
58
59 QString Platform::icon(const QString &name)
60 {
61     QString iconName = QString(DORIAN_ICON_PREFIX) + name + ".png";
62     if (QFile(iconName).exists()) {
63         return iconName;
64     } else {
65         return QString(":/icons/") + name + ".png";
66     }
67 }
68
69 void Platform::restart(char *argv[])
70 {
71 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
72     extern char **environ;
73     execve(argv[0], argv, environ);
74 #else
75     Q_UNUSED(argv);
76 #endif
77 }
78
79 QString Platform::version()
80 {
81     return QString(DORIAN_VERSION);
82 }
83
84 QString Platform::downloadDir()
85 {
86     return QDir::home().absoluteFilePath("Books");
87 }
88
89 QString Platform::defaultFont()
90 {
91 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_X11)
92     return QString("Serif");
93 #elif defined(Q_WS_MAC)
94     return QString("Hoefler Text");
95 #elif defined Q_WS_S60
96     return QString("Nokia Sans S60");
97 #else
98     return QString("Times New Roman");
99 #endif
100 }
101
102 void Platform::information(const QString &label, QWidget *parent)
103 {
104 #ifdef Q_WS_MAEMO_5
105     QMaemo5InformationBox::information(parent, label,
106                                        QMaemo5InformationBox::DefaultTimeout);
107 #else
108     (void)QMessageBox::information(parent, QObject::tr("Dorian"), label,
109                                    QMessageBox::Ok);
110 #endif
111 }
112
113 void Platform::showBusy(QWidget *w, bool isBusy)
114 {
115 #ifdef Q_WS_MAEMO_5
116     w->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, isBusy);
117 #else
118     Q_UNUSED(w);
119     Q_UNUSED(isBusy);
120 #endif
121 }
122
123 QString Platform::traceFileName()
124 {
125     return QDir::home().absoluteFilePath(DORIAN_LOG);
126 }
127
128 int Platform::defaultZoom()
129 {
130     return 150;
131 }
132
133 QString Platform::defaultOrientation()
134 {
135 #ifdef Q_OS_SYMBIAN
136     return QString("portrait");
137 #else
138     return QString("landscape");
139 #endif
140 }