1 /*****************************************************************************
2 * application.cpp - QStarDict, a StarDict clone written using Qt *
3 * Copyright (C) 2008 Alexander Rodin *
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. *
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. *
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 *****************************************************************************/
20 #include "application.h"
22 #ifdef QSTARDICT_WITH_TRANSLATIONS
23 #include <QLibraryInfo>
25 #include <QTranslator>
26 #include <QStringList>
27 #endif // QSTARDICT_WITH_TRANSLATIONS
29 #include "mainwindow.h"
30 #include "popupwindow.h"
33 #ifdef QSTARDICT_WITH_DBUS
34 #include "dbusadaptor.h"
35 #endif // QSTARDICT_WITH_DBUS
40 Application::Application(int &argc, char **argv)
41 : QApplication(argc, argv)
43 setOrganizationName("qstardict");
44 setApplicationName("qstardict");
47 setQuitOnLastWindowClosed(false);
51 setQuitOnLastWindowClosed(true);
54 #ifdef QSTARDICT_WITH_TRANSLATIONS
55 m_translator = new QTranslator;
57 QString binPath = QCoreApplication::applicationDirPath();
58 // navigate through mac's bundle tree structore
59 m_translator->load("qstardict-" + QLocale::system().name(), binPath + "/../i18n/");
61 m_translator->load("qstardict-" + QLocale::system().name(), QSTARDICT_TRANSLATIONS_DIR);
63 installTranslator(m_translator);
64 m_qtTranslator = new QTranslator;
65 m_qtTranslator->load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
66 installTranslator(m_qtTranslator);
67 #endif // QSTARDICT_WITH_TRANSLATIONS
69 m_dictCore = new DictCore;
70 m_popupWindow = new PopupWindow;
71 m_popupWindow->setDict(m_dictCore);
72 m_speaker = new Speaker;
74 m_trayIcon = new TrayIcon;
76 m_mainWindow = new MainWindow;
77 m_mainWindow->setDict(m_dictCore);
79 m_mainWindow->setVisible(true);
81 #ifdef QSTARDICT_WITH_DBUS
82 m_dbusAdaptor = new DBusAdaptor(m_mainWindow);
83 #endif // QSTARDICT_WITH_DBUS
86 Application::~Application()
95 #ifdef QSTARDICT_WITH_TRANSLATIONS
96 removeTranslator(m_translator);
98 removeTranslator(m_qtTranslator);
99 delete m_qtTranslator;
100 #endif // QSTARDICT_WITH_TRANSLATIONS
103 int Application::exec()
105 QString text = commandLineText();
106 if (text != QString::null)
107 m_mainWindow->showTranslation(text);
108 return QApplication::exec();
111 QString Application::commandLineText()
113 QStringList args(arguments());
114 for(int i = 1; i < args.count(); ++i)
116 if(! args.at(i).startsWith('-'))
119 return QString::null;
124 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc