-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
136 lines (117 loc) · 4.82 KB
/
Copy pathmain.cpp
File metadata and controls
136 lines (117 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <QApplication>
#include <QCommandLineParser>
#include <QIcon>
#include <QDebug>
#include <QTranslator>
#include <QLocale>
#include <QLibraryInfo>
#include <QSettings>
#include <QStandardPaths>
#include <QDir>
#include <QMap>
#include "core/Application.h"
int main(int argc, char *argv[])
{
qunsetenv("SESSION_MANAGER");
QApplication app(argc, argv);
// Set application metadata
QCoreApplication::setOrganizationName("Notepad++");
QCoreApplication::setApplicationName("Notepad++ Linux");
QCoreApplication::setApplicationVersion("1.2.0");
app.setWindowIcon(QIcon(":/images/notepad++linux3_600.png"));
// Load translations
QTranslator translator;
QTranslator qtTranslator;
// Check user language preference - use same settings file as ConfigManager
QString configDir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QString configFile = QDir(configDir).filePath("notepadplusplus.ini");
QSettings settings(configFile, QSettings::IniFormat);
QString userLanguage = settings.value("General/Language", "System").toString();
QString language;
QString locale;
// Determine which language to use
if (userLanguage == "System") {
// Use system locale
locale = QLocale::system().name(); // e.g., "de_DE"
language = locale.section('_', 0, 0); // e.g., "de"
} else if (userLanguage == "English") {
// Use English (no translation needed)
language = "";
locale = "en_US";
} else {
// Map language names to codes
QMap<QString, QString> languageMap = {
{"Deutsch", "de"},
{"Español", "es"},
{"Français", "fr"},
{"中文", "zh"},
{"日本語", "ja"},
{"Русский", "ru"}
};
language = languageMap.value(userLanguage, "");
locale = language + "_" + language.toUpper();
}
// Try to load Qt translations if not English
if (!language.isEmpty()) {
if (qtTranslator.load("qt_" + locale,
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QLibraryInfo::path(QLibraryInfo::TranslationsPath)
#else
QLibraryInfo::location(QLibraryInfo::TranslationsPath)
#endif
)) {
app.installTranslator(&qtTranslator);
}
// Try to load application translations
// First try from installation directory
QString translationPath = "/usr/local/share/notepadplusplus/translations";
if (translator.load("notepadplusplus_" + language, translationPath)) {
app.installTranslator(&translator);
qDebug() << "Loaded translation:" << userLanguage << "(" << language << ")" << "from" << translationPath;
}
// Try from build directory (for development)
else if (translator.load("notepadplusplus_" + language, "./translations")) {
app.installTranslator(&translator);
qDebug() << "Loaded translation:" << userLanguage << "(" << language << ")" << "from ./translations";
}
// Try from parent directory (for development)
else if (translator.load("notepadplusplus_" + language, "../translations")) {
app.installTranslator(&translator);
qDebug() << "Loaded translation:" << userLanguage << "(" << language << ")" << "from ../translations";
}
else {
}
} else {
}
// Command line parser
QCommandLineParser parser;
parser.setApplicationDescription("Notepad++ - Free source code editor for Linux");
parser.addHelpOption();
parser.addVersionOption();
// Add custom command line options
QCommandLineOption sessionOption(QStringList() << "s" << "session",
"Load session file", "session");
parser.addOption(sessionOption);
QCommandLineOption readOnlyOption(QStringList() << "ro" << "readonly",
"Open files in read-only mode");
parser.addOption(readOnlyOption);
parser.addPositionalArgument("files", "Files to open", "[files...]");
parser.process(app);
// Create and initialize application
NotepadPlusPlus::Application notepadApp;
// Handle command line arguments
if (parser.isSet(sessionOption)) {
notepadApp.loadSession(parser.value(sessionOption));
}
if (parser.isSet(readOnlyOption)) {
notepadApp.setReadOnlyMode(true);
}
// Open files from command line
const QStringList files = parser.positionalArguments();
for (const QString& file : files) {
notepadApp.openFile(file);
}
// Show main window and run
notepadApp.show();
return app.exec();
}