New version. Update home page link in About box.
[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 static Platform *theInstance;
37
38 Platform *Platform::instance()
39 {
40     if (!theInstance) {
41         theInstance = new Platform();
42     }
43     return theInstance;
44 }
45
46 void Platform::close()
47 {
48     delete theInstance;
49     theInstance = 0;
50 }
51
52 QString Platform::dbPath()
53 {
54     QString base(QDir::home().absoluteFilePath(DORIAN_BASE));
55     return QDir(base).absoluteFilePath("books.db");
56 }
57
58 QString Platform::icon(const QString &name)
59 {
60     QString iconName = QString(DORIAN_ICON_PREFIX) + name + ".png";
61     if (QFile(iconName).exists()) {
62         return iconName;
63     } else {
64         return QString(":/icons/") + name + ".png";
65     }
66 }
67
68 void Platform::restart(char *argv[])
69 {
70 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
71     extern char **environ;
72     execve(argv[0], argv, environ);
73 #else
74     Q_UNUSED(argv);
75 #endif
76 }
77
78 QString Platform::version()
79 {
80     return QString(DORIAN_VERSION);
81 }
82
83 QString Platform::downloadDir()
84 {
85     return QDir::home().absoluteFilePath("Books");
86 }
87
88 QString Platform::defaultFont()
89 {
90 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_X11)
91     return QString("Serif");
92 #elif defined(Q_WS_MAC)
93     return QString("Hoefler Text");
94 #elif defined Q_WS_S60
95     return QString("Nokia Sans S60");
96 #else
97     return QString("Times New Roman");
98 #endif
99 }
100
101 void Platform::information(const QString &label, QWidget *parent)
102 {
103 #ifdef Q_WS_MAEMO_5
104     QMaemo5InformationBox::information(parent, label,
105                                        QMaemo5InformationBox::DefaultTimeout);
106 #else
107     (void)QMessageBox::information(parent, QObject::tr("Dorian"), label,
108                                    QMessageBox::Ok);
109 #endif
110 }
111
112 void Platform::showBusy(QWidget *w, bool isBusy)
113 {
114 #ifdef Q_WS_MAEMO_5
115     w->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, isBusy);
116 #else
117     Q_UNUSED(w);
118     Q_UNUSED(isBusy);
119 #endif
120 }
121
122 QString Platform::traceFileName()
123 {
124     return QDir::home().absoluteFilePath(DORIAN_LOG);
125 }
126
127 int Platform::defaultZoom()
128 {
129     return 150;
130 }
131
132 QString Platform::defaultOrientation()
133 {
134 #ifdef Q_OS_SYMBIAN
135     return QString("portrait");
136 #else
137     return QString("landscape");
138 #endif
139 }