3f166be7e73e9e563cf08a8f4886f3e08e253634
[mdictionary] / src / mdictionary / gui / main.cpp
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary 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 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary 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
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 //! \file main.cpp
23 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
24
25 #include <QtGui/QApplication>
26 #include "MainWindow.h"
27 #include "../backbone/backbone.h"
28 #include "../../include/translation.h"
29 #include "../../include/Notify.h"
30 #include "DBusAdapter.h"
31 #include <QDebug>
32 #include <QDBusConnection>
33
34
35
36 QStringList parseParameters(int argc, char *argv[]) {
37     bool wordListStarted = false;
38     QStringList result;
39     for(int i=1; i<argc; i++) {
40         QString argument(argv[i]);
41         if(!wordListStarted) {
42             if(argument == "-s" || argument == "--search") {
43                 wordListStarted = true;
44             }
45         }
46         else {
47             if(!argument.startsWith("-") &&
48                !argument.startsWith("--")) {
49                 result << argument;
50             }
51         }
52     }
53
54     return result;
55 }
56
57 int main(int argc, char *argv[]) {
58     QApplication a(argc, argv);
59     QApplication::setOrganizationName("Comarch S.A.");
60     QApplication::setOrganizationDomain("comarch.com");
61     QApplication::setApplicationName("mDictionary");
62
63     QStringList search = parseParameters(argc, argv);
64
65     qRegisterMetaType<Translation*>("Translation*");
66     qRegisterMetaType<QList<Translation*> >("QList<Translation*>");
67     qRegisterMetaType<Notify>("Notify");
68     qRegisterMetaType<Notify::NotifyType>("Notify::NotifyType");
69
70     QString locale = QLocale::system().name();
71
72     QTranslator qtTranslator;
73     qtTranslator.load("qt_" + QLocale::system().name(),
74     QLibraryInfo::location(QLibraryInfo::TranslationsPath));
75
76     a.installTranslator(&qtTranslator);
77
78     QTranslator myTranslator;
79     if(locale == "pl_PL")
80         myTranslator.load(":/translations/dict_pl");
81     else
82         myTranslator.load(":/translations/dict_en");
83     a.installTranslator(&myTranslator);
84
85     Backbone backbone;
86     MainWindow w(&backbone);
87
88     DBusAdapter* adapter = new DBusAdapter(&w);
89
90     QDBusConnection::sessionBus().registerObject("/mainWindow",
91                                                  &w);
92     QDBusConnection::sessionBus().registerService("com.comarch.mdictionary");
93
94
95     w.show();
96
97
98     if(search.count() > 0) {
99         w.setExactSearch(true);
100         w.searchExact(search[0]);
101     }
102
103     return a.exec();
104 }