common: Make the Quassel class a proper singleton, clean up
[quassel.git] / src / common / quassel.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2016 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
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) version 3.                                           *
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     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "quassel.h"
22
23 #include <iostream>
24 #include <signal.h>
25 #if !defined Q_OS_WIN && !defined Q_OS_MAC
26 #  include <sys/types.h>
27 #  include <sys/time.h>
28 #  include <sys/resource.h>
29 #endif
30
31 #include <QCoreApplication>
32 #include <QDateTime>
33 #include <QDir>
34 #include <QFileInfo>
35 #include <QHostAddress>
36 #include <QLibraryInfo>
37 #include <QSettings>
38 #include <QTranslator>
39 #include <QUuid>
40
41 #include "bufferinfo.h"
42 #include "identity.h"
43 #include "logger.h"
44 #include "message.h"
45 #include "network.h"
46 #include "peer.h"
47 #include "protocol.h"
48 #include "syncableobject.h"
49 #include "types.h"
50
51 #include "../../version.h"
52
53 Quassel *Quassel::instance()
54 {
55     static Quassel instance;
56     return &instance;
57 }
58
59
60 Quassel::Quassel()
61 {
62     // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel.
63     signal(SIGTERM, handleSignal);
64     signal(SIGINT, handleSignal);
65 #ifndef Q_OS_WIN
66     // SIGHUP is used to reload configuration (i.e. SSL certificates)
67     // Windows does not support SIGHUP
68     signal(SIGHUP, handleSignal);
69 #endif
70 }
71
72
73 bool Quassel::init()
74 {
75     if (instance()->_initialized)
76         return true;  // allow multiple invocations because of MonolithicApplication
77
78     if (instance()->_handleCrashes) {
79         // we have crashhandler for win32 and unix (based on execinfo).
80 #if defined(Q_OS_WIN) || defined(HAVE_EXECINFO)
81 # ifndef Q_OS_WIN
82         // we only handle crashes ourselves if coredumps are disabled
83         struct rlimit *limit = (rlimit *)malloc(sizeof(struct rlimit));
84         int rc = getrlimit(RLIMIT_CORE, limit);
85
86         if (rc == -1 || !((long)limit->rlim_cur > 0 || limit->rlim_cur == RLIM_INFINITY)) {
87 # endif /* Q_OS_WIN */
88         signal(SIGABRT, handleSignal);
89         signal(SIGSEGV, handleSignal);
90 # ifndef Q_OS_WIN
91         signal(SIGBUS, handleSignal);
92     }
93     free(limit);
94 # endif /* Q_OS_WIN */
95 #endif /* Q_OS_WIN || HAVE_EXECINFO */
96     }
97
98     instance()->_initialized = true;
99     qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
100
101     instance()->setupEnvironment();
102     instance()->registerMetaTypes();
103
104     Network::setDefaultCodecForServer("ISO-8859-1");
105     Network::setDefaultCodecForEncoding("UTF-8");
106     Network::setDefaultCodecForDecoding("ISO-8859-15");
107
108     if (isOptionSet("help")) {
109         instance()->_cliParser->usage();
110         return false;
111     }
112
113     if (isOptionSet("version")) {
114         std::cout << qPrintable("Quassel IRC: " + Quassel::buildInfo().plainVersionString) << std::endl;
115         return false;
116     }
117
118     // set up logging
119     if (Quassel::runMode() != Quassel::ClientOnly) {
120         if (isOptionSet("loglevel")) {
121             QString level = optionValue("loglevel");
122
123             if (level == "Debug")
124                 setLogLevel(DebugLevel);
125             else if (level == "Info")
126                 setLogLevel(InfoLevel);
127             else if (level == "Warning")
128                 setLogLevel(WarningLevel);
129             else if (level == "Error")
130                 setLogLevel(ErrorLevel);
131             else {
132                 qWarning() << qPrintable(tr("Invalid log level %1; supported are Debug|Info|Warning|Error").arg(level));
133                 return false;
134             }
135         }
136
137         QString logfilename = optionValue("logfile");
138         if (!logfilename.isEmpty()) {
139             instance()->_logFile.reset(new QFile{logfilename});
140             if (!logFile()->open(QIODevice::Append | QIODevice::Text)) {
141                 qWarning() << "Could not open log file" << logfilename << ":" << logFile()->errorString();
142                 instance()->_logFile.reset();
143             }
144         }
145 #ifdef HAVE_SYSLOG
146         instance()->_logToSyslog = isOptionSet("syslog");
147 #endif
148     }
149
150     return true;
151 }
152
153
154 void Quassel::destroy()
155 {
156     if (logFile()) {
157         logFile()->close();
158         instance()->_logFile.reset();
159     }
160 }
161
162
163 void Quassel::registerQuitHandler(QuitHandler handler)
164 {
165     instance()->_quitHandlers.emplace_back(std::move(handler));
166 }
167
168 void Quassel::quit()
169 {
170     if (_quitHandlers.empty()) {
171         QCoreApplication::quit();
172     }
173     else {
174         for (auto &&handler : _quitHandlers) {
175             handler();
176         }
177     }
178 }
179
180
181 void Quassel::registerReloadHandler(ReloadHandler handler)
182 {
183     instance()->_reloadHandlers.emplace_back(std::move(handler));
184 }
185
186
187 bool Quassel::reloadConfig()
188 {
189     bool result{true};
190     for (auto &&handler : _reloadHandlers) {
191         result = result && handler();
192     }
193     return result;
194 }
195
196
197 //! Register our custom types with Qt's Meta Object System.
198 /**  This makes them available for QVariant and in signals/slots, among other things.
199 *
200 */
201 void Quassel::registerMetaTypes()
202 {
203     // Complex types
204     qRegisterMetaType<Message>("Message");
205     qRegisterMetaType<BufferInfo>("BufferInfo");
206     qRegisterMetaType<NetworkInfo>("NetworkInfo");
207     qRegisterMetaType<Network::Server>("Network::Server");
208     qRegisterMetaType<Identity>("Identity");
209
210     qRegisterMetaTypeStreamOperators<Message>("Message");
211     qRegisterMetaTypeStreamOperators<BufferInfo>("BufferInfo");
212     qRegisterMetaTypeStreamOperators<NetworkInfo>("NetworkInfo");
213     qRegisterMetaTypeStreamOperators<Network::Server>("Network::Server");
214     qRegisterMetaTypeStreamOperators<Identity>("Identity");
215
216     qRegisterMetaType<IdentityId>("IdentityId");
217     qRegisterMetaType<BufferId>("BufferId");
218     qRegisterMetaType<NetworkId>("NetworkId");
219     qRegisterMetaType<UserId>("UserId");
220     qRegisterMetaType<AccountId>("AccountId");
221     qRegisterMetaType<MsgId>("MsgId");
222
223     qRegisterMetaType<QHostAddress>("QHostAddress");
224     qRegisterMetaTypeStreamOperators<QHostAddress>("QHostAddress");
225     qRegisterMetaType<QUuid>("QUuid");
226     qRegisterMetaTypeStreamOperators<QUuid>("QUuid");
227
228     qRegisterMetaTypeStreamOperators<IdentityId>("IdentityId");
229     qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
230     qRegisterMetaTypeStreamOperators<NetworkId>("NetworkId");
231     qRegisterMetaTypeStreamOperators<UserId>("UserId");
232     qRegisterMetaTypeStreamOperators<AccountId>("AccountId");
233     qRegisterMetaTypeStreamOperators<MsgId>("MsgId");
234
235     qRegisterMetaType<Protocol::SessionState>("Protocol::SessionState");
236     qRegisterMetaType<PeerPtr>("PeerPtr");
237     qRegisterMetaTypeStreamOperators<PeerPtr>("PeerPtr");
238
239     // Versions of Qt prior to 4.7 didn't define QVariant as a meta type
240     if (!QMetaType::type("QVariant")) {
241         qRegisterMetaType<QVariant>("QVariant");
242         qRegisterMetaTypeStreamOperators<QVariant>("QVariant");
243     }
244 }
245
246
247 void Quassel::setupEnvironment()
248 {
249     // On modern Linux systems, XDG_DATA_DIRS contains a list of directories containing application data. This
250     // is, for example, used by Qt for finding icons and other things. In case Quassel is installed in a non-standard
251     // prefix (or run from the build directory), it makes sense to add this to XDG_DATA_DIRS so we don't have to
252     // hack extra search paths into various places.
253 #ifdef Q_OS_UNIX
254     QString xdgDataVar = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
255     if (xdgDataVar.isEmpty())
256         xdgDataVar = QLatin1String("/usr/local/share:/usr/share"); // sane defaults
257
258     QStringList xdgDirs = xdgDataVar.split(QLatin1Char(':'), QString::SkipEmptyParts);
259
260     // Add our install prefix (if we're not in a bindir, this just adds the current workdir)
261     QString appDir = QCoreApplication::applicationDirPath();
262     int binpos = appDir.lastIndexOf("/bin");
263     if (binpos >= 0) {
264         appDir.replace(binpos, 4, "/share");
265         xdgDirs.append(appDir);
266         // Also append apps/quassel, this is only for QIconLoader to find icons there
267         xdgDirs.append(appDir + "/apps/quassel");
268     } else
269         xdgDirs.append(appDir);  // build directory is always the last fallback
270
271     xdgDirs.removeDuplicates();
272
273     qputenv("XDG_DATA_DIRS", QFile::encodeName(xdgDirs.join(":")));
274 #endif
275 }
276
277
278 void Quassel::setupBuildInfo()
279 {
280     BuildInfo buildInfo;
281     buildInfo.applicationName = "quassel";
282     buildInfo.coreApplicationName = "quasselcore";
283     buildInfo.clientApplicationName = "quasselclient";
284     buildInfo.organizationName = "Quassel Project";
285     buildInfo.organizationDomain = "quassel-irc.org";
286
287     buildInfo.protocolVersion = 10; // FIXME: deprecated, will be removed
288
289     buildInfo.baseVersion = QUASSEL_VERSION_STRING;
290     buildInfo.generatedVersion = GIT_DESCRIBE;
291
292     // Check if we got a commit hash
293     if (!QString(GIT_HEAD).isEmpty()) {
294         buildInfo.commitHash = GIT_HEAD;
295         QDateTime date;
296         date.setTime_t(GIT_COMMIT_DATE);
297         buildInfo.commitDate = date.toString();
298     }
299     else if (!QString(DIST_HASH).contains("Format")) {
300         buildInfo.commitHash = DIST_HASH;
301         buildInfo.commitDate = QString(DIST_DATE);
302     }
303
304     // create a nice version string
305     if (buildInfo.generatedVersion.isEmpty()) {
306         if (!buildInfo.commitHash.isEmpty()) {
307             // dist version
308             buildInfo.plainVersionString = QString{"v%1 (dist-%2)"}
309                                                .arg(buildInfo.baseVersion)
310                                                .arg(buildInfo.commitHash.left(7));
311             buildInfo.fancyVersionString = QString{"v%1 (dist-<a href=\"https://github.com/quassel/quassel/commit/%3\">%2</a>)"}
312                                                .arg(buildInfo.baseVersion)
313                                                .arg(buildInfo.commitHash.left(7))
314                                                .arg(buildInfo.commitHash);
315         }
316         else {
317             // we only have a base version :(
318             buildInfo.plainVersionString = QString{"v%1 (unknown revision)"}.arg(buildInfo.baseVersion);
319         }
320     }
321     else {
322         // analyze what we got from git-describe
323         static const QRegExp rx{"(.*)-(\\d+)-g([0-9a-f]+)(-dirty)?$"};
324         if (rx.exactMatch(buildInfo.generatedVersion)) {
325             QString distance = rx.cap(2) == "0" ? QString{} : QString{"%1+%2 "}.arg(rx.cap(1), rx.cap(2));
326             buildInfo.plainVersionString = QString{"v%1 (%2git-%3%4)"}.arg(buildInfo.baseVersion, distance, rx.cap(3), rx.cap(4));
327             if (!buildInfo.commitHash.isEmpty()) {
328                 buildInfo.fancyVersionString = QString{"v%1 (%2git-<a href=\"https://github.com/quassel/quassel/commit/%5\">%3</a>%4)"}
329                                                    .arg(buildInfo.baseVersion, distance, rx.cap(3), rx.cap(4), buildInfo.commitHash);
330             }
331         }
332         else {
333             buildInfo.plainVersionString = QString{"v%1 (invalid revision)"}.arg(buildInfo.baseVersion);
334         }
335     }
336     if (buildInfo.fancyVersionString.isEmpty()) {
337         buildInfo.fancyVersionString = buildInfo.plainVersionString;
338     }
339
340     instance()->_buildInfo = std::move(buildInfo);
341 }
342
343
344 const Quassel::BuildInfo &Quassel::buildInfo()
345 {
346     return instance()->_buildInfo;
347 }
348
349
350 //! Signal handler for graceful shutdown.
351 void Quassel::handleSignal(int sig)
352 {
353     switch (sig) {
354     case SIGTERM:
355     case SIGINT:
356         qWarning("%s", qPrintable(QString("Caught signal %1 - exiting.").arg(sig)));
357         instance()->quit();
358         break;
359 #ifndef Q_OS_WIN
360 // Windows does not support SIGHUP
361     case SIGHUP:
362         // Most applications use this as the 'configuration reload' command, e.g. nginx uses it for
363         // graceful reloading of processes.
364         quInfo() << "Caught signal" << SIGHUP << "- reloading configuration";
365         if (instance()->reloadConfig()) {
366             quInfo() << "Successfully reloaded configuration";
367         }
368         break;
369 #endif
370     case SIGABRT:
371     case SIGSEGV:
372 #ifndef Q_OS_WIN
373     case SIGBUS:
374 #endif
375         instance()->logBacktrace(instance()->coreDumpFileName());
376         exit(EXIT_FAILURE);
377     default:
378         ;
379     }
380 }
381
382
383 void Quassel::disableCrashHandler()
384 {
385     instance()->_handleCrashes = false;
386 }
387
388
389 Quassel::RunMode Quassel::runMode() {
390     return instance()->_runMode;
391 }
392
393
394 void Quassel::setRunMode(RunMode runMode)
395 {
396     instance()->_runMode = runMode;
397 }
398
399
400 void Quassel::setCliParser(std::shared_ptr<AbstractCliParser> parser)
401 {
402     instance()->_cliParser = std::move(parser);
403 }
404
405
406 QString Quassel::optionValue(const QString &key)
407 {
408     return instance()->_cliParser ? instance()->_cliParser->value(key) : QString{};
409 }
410
411
412 bool Quassel::isOptionSet(const QString &key)
413 {
414     return instance()->_cliParser ? instance()->_cliParser->isSet(key) : false;
415 }
416
417
418 Quassel::LogLevel Quassel::logLevel()
419 {
420     return instance()->_logLevel;
421 }
422
423
424 void Quassel::setLogLevel(LogLevel logLevel)
425 {
426     instance()->_logLevel = logLevel;
427 }
428
429
430 QFile *Quassel::logFile() {
431     return instance()->_logFile.get();
432 }
433
434
435 bool Quassel::logToSyslog()
436 {
437     return instance()->_logToSyslog;
438 }
439
440
441 void Quassel::logFatalMessage(const char *msg)
442 {
443 #ifdef Q_OS_MAC
444     Q_UNUSED(msg)
445 #else
446     QFile dumpFile(instance()->coreDumpFileName());
447     dumpFile.open(QIODevice::Append);
448     QTextStream dumpStream(&dumpFile);
449
450     dumpStream << "Fatal: " << msg << '\n';
451     dumpStream.flush();
452     dumpFile.close();
453 #endif
454 }
455
456
457 Quassel::Features Quassel::features()
458 {
459     Features feats = 0;
460     for (int i = 1; i <= NumFeatures; i <<= 1)
461         feats |= (Feature)i;
462
463     // Disable DCC until it is ready
464     feats &= ~Feature::DccFileTransfer;
465
466     return feats;
467 }
468
469
470 const QString &Quassel::coreDumpFileName()
471 {
472     if (_coreDumpFileName.isEmpty()) {
473         QDir configDir(configDirPath());
474         _coreDumpFileName = configDir.absoluteFilePath(QString("Quassel-Crash-%1.log").arg(QDateTime::currentDateTime().toString("yyyyMMdd-hhmm")));
475         QFile dumpFile(_coreDumpFileName);
476         dumpFile.open(QIODevice::Append);
477         QTextStream dumpStream(&dumpFile);
478         dumpStream << "Quassel IRC: " << _buildInfo.baseVersion << ' ' << _buildInfo.commitHash << '\n';
479         qDebug() << "Quassel IRC: " << _buildInfo.baseVersion << ' ' << _buildInfo.commitHash;
480         dumpStream.flush();
481         dumpFile.close();
482     }
483     return _coreDumpFileName;
484 }
485
486
487 QString Quassel::configDirPath()
488 {
489     if (!instance()->_configDirPath.isEmpty())
490         return instance()->_configDirPath;
491
492     QString path;
493     if (isOptionSet("datadir")) {
494         qWarning() << "Obsolete option --datadir used!";
495         path = Quassel::optionValue("datadir");
496     }
497     else if (isOptionSet("configdir")) {
498         path = Quassel::optionValue("configdir");
499     }
500     else {
501 #ifdef Q_OS_MAC
502         // On Mac, the path is always the same
503         path = QDir::homePath() + "/Library/Application Support/Quassel/";
504 #else
505         // We abuse QSettings to find us a sensible path on the other platforms
506 #  ifdef Q_OS_WIN
507         // don't use the registry
508         QSettings::Format format = QSettings::IniFormat;
509 #  else
510         QSettings::Format format = QSettings::NativeFormat;
511 #  endif
512         QSettings s(format, QSettings::UserScope, QCoreApplication::organizationDomain(), buildInfo().applicationName);
513         QFileInfo fileInfo(s.fileName());
514         path = fileInfo.dir().absolutePath();
515 #endif /* Q_OS_MAC */
516     }
517
518     if (!path.endsWith(QDir::separator()) && !path.endsWith('/'))
519         path += QDir::separator();
520
521     QDir qDir{path};
522     if (!qDir.exists(path)) {
523         if (!qDir.mkpath(path)) {
524             qCritical() << "Unable to create Quassel config directory:" << qPrintable(qDir.absolutePath());
525             return {};
526         }
527     }
528
529     instance()->_configDirPath = path;
530
531     return path;
532 }
533
534
535 void Quassel::setDataDirPaths(const QStringList &paths) {
536     instance()->_dataDirPaths = paths;
537 }
538
539
540 QStringList Quassel::dataDirPaths()
541 {
542     return instance()->_dataDirPaths;
543 }
544
545
546 QStringList Quassel::findDataDirPaths()
547 {
548     // TODO Qt5
549     // We don't use QStandardPaths for now, as we still need to provide fallbacks for Qt4 and
550     // want to stay consistent.
551
552     QStringList dataDirNames;
553 #ifdef Q_OS_WIN
554     dataDirNames << qgetenv("APPDATA") + QCoreApplication::organizationDomain() + "/share/apps/quassel/"
555                  << qgetenv("APPDATA") + QCoreApplication::organizationDomain()
556                  << QCoreApplication::applicationDirPath();
557 #elif defined Q_OS_MAC
558     dataDirNames << QDir::homePath() + "/Library/Application Support/Quassel/"
559                  << QCoreApplication::applicationDirPath();
560 #else
561     // Linux et al
562
563     // XDG_DATA_HOME is the location for users to override system-installed files, usually in .local/share
564     // This should thus come first.
565     QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
566     if (xdgDataHome.isEmpty())
567         xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
568     dataDirNames << xdgDataHome;
569
570     // Now whatever is configured through XDG_DATA_DIRS
571     QString xdgDataDirs = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
572     if (xdgDataDirs.isEmpty())
573         dataDirNames << "/usr/local/share" << "/usr/share";
574     else
575         dataDirNames << xdgDataDirs.split(':', QString::SkipEmptyParts);
576
577     // Just in case, also check our install prefix
578     dataDirNames << QCoreApplication::applicationDirPath() + "/../share";
579
580     // Normalize and append our application name
581     for (int i = 0; i < dataDirNames.count(); i++)
582         dataDirNames[i] = QDir::cleanPath(dataDirNames.at(i)) + "/quassel/";
583
584 #endif
585
586     // Add resource path and workdir just in case.
587     // Workdir should have precedence
588     dataDirNames.prepend(QCoreApplication::applicationDirPath() + "/data/");
589     dataDirNames.append(":/data/");
590
591     // Append trailing '/' and check for existence
592     auto iter = dataDirNames.begin();
593     while (iter != dataDirNames.end()) {
594         if (!iter->endsWith(QDir::separator()) && !iter->endsWith('/'))
595             iter->append(QDir::separator());
596         if (!QFile::exists(*iter))
597             iter = dataDirNames.erase(iter);
598         else
599             ++iter;
600     }
601
602     dataDirNames.removeDuplicates();
603
604     return dataDirNames;
605 }
606
607
608 QString Quassel::findDataFilePath(const QString &fileName)
609 {
610     QStringList dataDirs = dataDirPaths();
611     foreach(QString dataDir, dataDirs) {
612         QString path = dataDir + fileName;
613         if (QFile::exists(path))
614             return path;
615     }
616     return QString();
617 }
618
619
620 QStringList Quassel::scriptDirPaths()
621 {
622     QStringList res(configDirPath() + "scripts/");
623     foreach(QString path, dataDirPaths())
624     res << path + "scripts/";
625     return res;
626 }
627
628
629 QString Quassel::translationDirPath()
630 {
631     if (instance()->_translationDirPath.isEmpty()) {
632         // We support only one translation dir; fallback mechanisms wouldn't work else.
633         // This means that if we have a $data/translations dir, the internal :/i18n resource won't be considered.
634         foreach(const QString &dir, dataDirPaths()) {
635             if (QFile::exists(dir + "translations/")) {
636                 instance()->_translationDirPath = dir + "translations/";
637                 break;
638             }
639         }
640         if (instance()->_translationDirPath.isEmpty())
641             instance()->_translationDirPath = ":/i18n/";
642     }
643     return instance()->_translationDirPath;
644 }
645
646
647 void Quassel::loadTranslation(const QLocale &locale)
648 {
649     QTranslator *qtTranslator = QCoreApplication::instance()->findChild<QTranslator *>("QtTr");
650     QTranslator *quasselTranslator = QCoreApplication::instance()->findChild<QTranslator *>("QuasselTr");
651
652     if (qtTranslator)
653         qApp->removeTranslator(qtTranslator);
654     if (quasselTranslator)
655         qApp->removeTranslator(quasselTranslator);
656
657     // We use QLocale::C to indicate that we don't want a translation
658     if (locale.language() == QLocale::C)
659         return;
660
661     qtTranslator = new QTranslator(qApp);
662     qtTranslator->setObjectName("QtTr");
663     qApp->installTranslator(qtTranslator);
664
665     quasselTranslator = new QTranslator(qApp);
666     quasselTranslator->setObjectName("QuasselTr");
667     qApp->installTranslator(quasselTranslator);
668
669 #if QT_VERSION >= 0x040800 && !defined Q_OS_MAC
670     bool success = qtTranslator->load(locale, QString("qt_"), translationDirPath());
671     if (!success)
672         qtTranslator->load(locale, QString("qt_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
673     quasselTranslator->load(locale, QString(""), translationDirPath());
674 #else
675     bool success = qtTranslator->load(QString("qt_%1").arg(locale.name()), translationDirPath());
676     if (!success)
677         qtTranslator->load(QString("qt_%1").arg(locale.name()), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
678     quasselTranslator->load(QString("%1").arg(locale.name()), translationDirPath());
679 #endif
680 }