- Auszuschliessende Verzeichnisse in Projektfunktionen hinzugefügt - Dateien können als Paramter übergeben werden - Englisch hinzugefügt
107 lines
3.3 KiB
C++
107 lines
3.3 KiB
C++
#include <QApplication>
|
|
#include <QIcon>
|
|
#include <QTranslator>
|
|
#include <QLocale>
|
|
#include <QLibraryInfo>
|
|
#include <QSettings>
|
|
#include <QDir>
|
|
#include <QCoreApplication>
|
|
#include "core/MainWindow.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QApplication app(argc, argv);
|
|
|
|
app.setApplicationName("BareCode");
|
|
app.setApplicationVersion("1.3.0");
|
|
app.setOrganizationName("BareCode");
|
|
|
|
// Icon
|
|
QIcon appIcon;
|
|
appIcon.addFile(":/icon_16.png", QSize(16, 16));
|
|
appIcon.addFile(":/icon_32.png", QSize(32, 32));
|
|
appIcon.addFile(":/icon_48.png", QSize(48, 48));
|
|
appIcon.addFile(":/icon_64.png", QSize(64, 64));
|
|
appIcon.addFile(":/icon_128.png", QSize(128, 128));
|
|
appIcon.addFile(":/icon_256.png", QSize(256, 256));
|
|
appIcon.addFile(":/icon_512.png", QSize(512, 512));
|
|
app.setWindowIcon(appIcon);
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Übersetzung laden
|
|
// .qm-Dateien liegen im Unterverzeichnis "translations" neben der Binary
|
|
// oder unter /usr/share/BareCode/translations nach Installation
|
|
// ---------------------------------------------------------------------------
|
|
QSettings settings(QSettings::IniFormat, QSettings::UserScope,
|
|
"BareCode", "BareCode");
|
|
QString locale = settings.value("language/locale", QString()).toString();
|
|
|
|
if (locale.isEmpty())
|
|
{
|
|
locale = QLocale::system().name(); // z.B. "de_DE", "en_US"
|
|
}
|
|
|
|
const QString shortLocale = locale.left(2); // "de", "en"
|
|
|
|
// Suchpfade für .qm-Dateien
|
|
QStringList searchPaths;
|
|
searchPaths << QCoreApplication::applicationDirPath() + "/translations"
|
|
<< QDir::homePath() + "/.local/share/BareCode/translations"
|
|
<< "/usr/share/BareCode/translations"
|
|
<< "/usr/local/share/BareCode/translations";
|
|
|
|
// Qt-eigene Übersetzungen (Dialoge, Standard-Buttons)
|
|
QTranslator qtTranslator;
|
|
if (qtTranslator.load("qt_" + locale,
|
|
QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
|
|
{
|
|
app.installTranslator(&qtTranslator);
|
|
}
|
|
|
|
// BareCode-Übersetzung — in allen Suchpfaden versuchen
|
|
QTranslator appTranslator;
|
|
bool loaded = false;
|
|
|
|
for (const QString &path : searchPaths)
|
|
{
|
|
if (appTranslator.load(QString("barecode_%1").arg(locale), path) ||
|
|
appTranslator.load(QString("barecode_%1").arg(shortLocale), path))
|
|
{
|
|
app.installTranslator(&appTranslator);
|
|
loaded = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Fallback: Englisch
|
|
if (!loaded && shortLocale != "de")
|
|
{
|
|
for (const QString &path : searchPaths)
|
|
{
|
|
if (appTranslator.load("barecode_en", path))
|
|
{
|
|
app.installTranslator(&appTranslator);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
MainWindow window;
|
|
window.show();
|
|
|
|
// Datei(en) öffnen, die beim Start per Kommandozeile übergeben wurden
|
|
// (z. B. Doppelklick auf eine Datei im Dateibrowser → "Öffnen mit BareCode").
|
|
// Das erste Argument ist der Programmname selbst und wird übersprungen.
|
|
QStringList cliFiles = app.arguments();
|
|
if (!cliFiles.isEmpty())
|
|
{
|
|
cliFiles.removeFirst();
|
|
}
|
|
if (!cliFiles.isEmpty())
|
|
{
|
|
window.openFilesFromArguments(cliFiles);
|
|
}
|
|
|
|
return app.exec();
|
|
}
|