Russian translation. Gui fix.
[qstardict] / qstardict / main.cpp
1 /*****************************************************************************
2  * main.cpp - QStarDict, a StarDict clone written with using Qt              *
3  * Copyright (C) 2007 Alexander Rodin                                        *
4  *                                                                           *
5  * This program is free software; you can redistribute it and/or modify      *
6  * it under the terms of the GNU General Public License as published by      *
7  * the Free Software Foundation; either version 2 of the License, or         *
8  * (at your option) any later version.                                       *
9  *                                                                           *
10  * This program is distributed in the hope that it will be useful,           *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
13  * GNU General Public License for more details.                              *
14  *                                                                           *
15  * You should have received a copy of the GNU General Public License along   *
16  * with this program; if not, write to the Free Software Foundation, Inc.,   *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.               *
18  *****************************************************************************/
19
20 #include "application.h"
21
22 #ifdef Q_OS_UNIX
23 #include <QDateTime>
24 #include <QDir>
25 #include <QFileInfo>
26 #include <QSettings>
27 #include <unistd.h>
28 #elif defined(Q_OS_WIN) // Q_OS_UNIX
29 #include <windows.h>
30 #include <QMessageBox>
31 #endif // Q_OS_WIN
32
33 #ifdef QSTARDICT_WITH_TRANSLATIONS
34 #include <QLocale>
35 #include <QTranslator>
36 #endif // QSTARDICT_WITH_TRANSLATIONS
37
38 int main(int argc, char *argv[])
39 {
40     QStarDict::Application app(argc, argv);
41 #ifdef Q_OS_UNIX
42     QSettings lockFile(QDir::homePath() + "/.qstardict/qstardict.pid", QSettings::IniFormat);
43     QString lastPid = lockFile.value("LastStart/pid").toString();
44     if (lastPid.length() && QDir("/proc/" + lastPid).exists() &&
45         lockFile.value("LastStart/time").toDateTime() == QFileInfo("/proc/" + lastPid).created())
46     {
47         qDebug("qstardict: already running");
48         return 0;
49     }
50     lockFile.setValue("LastStart/pid", getpid());
51     lockFile.setValue("LastStart/time", QFileInfo("/proc/" + QString::number(getpid())).created());
52     lockFile.sync();
53 #elif defined(Q_OS_WIN) // Q_OS_UNIX
54     HANDLE hMutex = CreateMutex(NULL, true, (LPCTSTR)"qstardict");
55     if (GetLastError() == ERROR_ALREADY_EXISTS)
56     {
57         QMessageBox::information(0, "Warning", "QStarDict is already running");
58         // Strange encoding issue...
59         // MessageBox(0, (LPCWSTR)"Warning", (LPCWSTR)"QStarDict is already running", MB_ICONWARNING);
60         return 0;
61     }
62 #endif // Q_OS_WIN
63
64     app.setProperty("FingerScrollable", true);
65     app.setProperty("FingerScrollBars", true);
66     return app.exec();
67 }
68
69 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc
70