forked from notepadqq/notepadqq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotepadqq.cpp
164 lines (132 loc) · 5.17 KB
/
notepadqq.cpp
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "include/notepadqq.h"
#include "include/Extensions/extensionsloader.h"
#include "include/Extensions/runtimesupport.h"
#include "include/nqqsettings.h"
#include <QCheckBox>
#include <QDir>
#include <QFileInfo>
#include <QMessageBox>
const QString Notepadqq::version = POINTVERSION;
const QString Notepadqq::contributorsUrl = "https://github.com/notepadqq/notepadqq/graphs/contributors";
const QString Notepadqq::website = "https://notepadqq.com";
QString Notepadqq::copyright()
{
return QObject::trUtf8("Copyright © 2010-%1, Daniele Di Sarli").arg(COPYRIGHT_YEAR);
}
QString Notepadqq::appDataPath(QString fileName)
{
#ifdef Q_OS_MACX
QString def = QString("%1/../Resources/").
arg(qApp->applicationDirPath());
#else
QString def = QString("%1/../appdata/").
arg(qApp->applicationDirPath());
#endif
if(!QDir(def).exists())
def = QString("%1/../../share/%2/").
arg(qApp->applicationDirPath()).
arg(qApp->applicationName().toLower());
if (!fileName.isNull()) {
def.append(fileName);
}
return def;
}
QString Notepadqq::editorPath()
{
return appDataPath("editor/index.html");
}
QString Notepadqq::extensionToolsPath()
{
return appDataPath("extension_tools");
}
QString Notepadqq::nodejsPath() {
NqqSettings& s = NqqSettings::getInstance();
return s.Extensions.getRuntimeNodeJS();
}
QString Notepadqq::npmPath() {
NqqSettings& s = NqqSettings::getInstance();
return s.Extensions.getRuntimeNpm();
}
QString Notepadqq::fileNameFromUrl(const QUrl &url)
{
return QFileInfo(url.toDisplayString(
QUrl::RemoveScheme |
QUrl::RemovePassword |
QUrl::RemoveUserInfo |
QUrl::RemovePort |
QUrl::RemoveAuthority |
QUrl::RemoveQuery |
QUrl::RemoveFragment |
QUrl::PreferLocalFile )
).fileName();
}
QSharedPointer<QCommandLineParser> Notepadqq::getCommandLineArgumentsParser(const QStringList &arguments)
{
QSharedPointer<QCommandLineParser> parser =
QSharedPointer<QCommandLineParser>(new QCommandLineParser());
parser->setApplicationDescription("Text editor for developers");
parser->addHelpOption();
parser->addVersionOption();
QCommandLineOption newWindowOption("new-window",
QObject::tr("Open a new window in an existing instance of %1.")
.arg(QCoreApplication::applicationName()));
parser->addOption(newWindowOption);
QCommandLineOption setLine({"l", "line"},
QObject::tr("Open file at specified line."),
"line",
"0");
parser->addOption(setLine);
QCommandLineOption setCol({"c", "column"},
QObject::tr("Open file at specified column."),
"column",
"0");
parser->addOption(setCol);
QCommandLineOption allowRootOption("allow-root", QObject::tr("Allows Notepadqq to be run as root."));
parser->addOption(allowRootOption);
QCommandLineOption printDebugOption("print-debug-info", QObject::tr("Print system information for debugging."));
parser->addOption(printDebugOption);
parser->addPositionalArgument("urls",
QObject::tr("Files to open."),
"[urls...]");
parser->process(arguments);
return parser;
}
QString Notepadqq::extensionsPath()
{
QSettings settings;
QFileInfo f = QFileInfo(settings.fileName());
return f.absoluteDir().absoluteFilePath("extensions");
}
QList<QString> Notepadqq::translations()
{
QList<QString> out;
QDir dir(":/translations");
QStringList fileNames = dir.entryList(QStringList("notepadqq_*.qm"));
// FIXME this can be removed if we create a .qm file for English too, which should exist for consistency purposes
out.append("en");
for (int i = 0; i < fileNames.size(); ++i) {
// get locale extracted by filename
QString langCode;
langCode = fileNames[i]; // "notepadqq_de.qm"
langCode.truncate(langCode.lastIndexOf('.')); // "notepadqq_de"
langCode.remove(0, langCode.indexOf('_') + 1); // "de"
out.append(langCode);
}
return out;
}
void Notepadqq::printEnvironmentInfo()
{
qDebug() << QString("Notepadqq: %1").arg(POINTVERSION).toStdString().c_str();
#ifdef BUILD_SNAP
qDebug() << "Snap build: yes";
#else
qDebug() << "Snap build: no";
#endif
qDebug() << QString("Qt: %1 - %2").arg(qVersion(), QSysInfo::buildAbi()).toStdString().c_str();
qDebug() << QString("OS: %1 (%2 %3)")
.arg(QSysInfo::prettyProductName(), QSysInfo::productType(), QSysInfo::productVersion())
.toStdString()
.c_str();
qDebug() << QString("CPU: %1").arg(QSysInfo::currentCpuArchitecture()).toStdString().c_str();
qDebug() << QString("Kernel: %1 - %2").arg(QSysInfo::kernelType(), QSysInfo::kernelVersion()).toStdString().c_str();
}