ee7f5d9bc56ec8358c31de6e5dcb81afcd2e94ab
[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 #ifdef Q_OS_SYMBIAN
87     if (QDir("E:/").exists()) {
88         return "E:/Books";
89     }
90     return "C:/Books";
91 #else
92     return QDir::home().absoluteFilePath("Books");
93 #endif
94 }
95
96 QString Platform::defaultFont()
97 {
98 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_X11)
99     return QString("Serif");
100 #elif defined(Q_WS_MAC)
101     return QString("Hoefler Text");
102 #elif defined Q_WS_S60
103     return QString("Nokia Sans S60");
104 #else
105     return QString("Times New Roman");
106 #endif
107 }
108
109 void Platform::information(const QString &label, QWidget *parent)
110 {
111 #ifdef Q_WS_MAEMO_5
112     QMaemo5InformationBox::information(parent, label,
113                                        QMaemo5InformationBox::DefaultTimeout);
114 #else
115     (void)QMessageBox::information(parent, QObject::tr("Dorian"), label,
116                                    QMessageBox::Ok);
117 #endif
118 }
119
120 void Platform::showBusy(QWidget *w, bool isBusy)
121 {
122 #ifdef Q_WS_MAEMO_5
123     w->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, isBusy);
124 #else
125     Q_UNUSED(w);
126     Q_UNUSED(isBusy);
127 #endif
128 }
129
130 QString Platform::traceFileName()
131 {
132     return QDir::home().absoluteFilePath(DORIAN_LOG);
133 }
134
135 int Platform::defaultZoom()
136 {
137     return 150;
138 }
139
140 QString Platform::defaultOrientation()
141 {
142 #ifdef Q_OS_SYMBIAN
143     return QString("portrait");
144 #else
145     return QString("landscape");
146 #endif
147 }