Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
sqlitebrowser/src/Application.cpp at master · dwlcj/sqlitebrowser · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
dwlcj
sqlitebrowser
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
sqlitebrowser
/
src
/
Application.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
200 lines (182 loc) · 8.33 KB
master
Breadcrumbs
sqlitebrowser
/
src
/
Application.cpp
Copy path
Top
File metadata and controls
Code
Blame
200 lines (182 loc) · 8.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#
include
<
QFile
>
#
include
<
QFileOpenEvent
>
#
include
<
QTranslator
>
#
include
<
QTextCodec
>
#
include
<
QLibraryInfo
>
#
include
<
QLocale
>
#
include
<
QDebug
>
#
include
"
Application.h
"
#
include
"
MainWindow.h
"
#
include
"
Settings.h
"
#
include
"
version.h
"
Application::Application
(
int
& argc,
char
** argv) :
QApplication(argc, argv)
{
//
Set organisation and application names
setOrganizationName
(
"
sqlitebrowser
"
);
setApplicationName
(
"
DB Browser for SQLite
"
);
//
Set character encoding to UTF8
QTextCodec::setCodecForLocale
(
QTextCodec::codecForName
(
"
UTF-8
"
));
//
Load translations
bool
ok;
QString name =
Settings::getValue
(
"
General
"
,
"
language
"
).
toString
();
//
First of all try to load the application translation file.
m_translatorApp =
new
QTranslator
(
this
);
ok = m_translatorApp->
load
(
"
sqlb_
"
+ name,
QCoreApplication::applicationDirPath
() +
"
/translations
"
);
//
If failed then try to load .qm file from resources
if
(ok ==
false
) {
ok = m_translatorApp->
load
(
"
sqlb_
"
+ name,
"
:/translations
"
);
}
if
(ok ==
true
) {
Settings::setValue
(
"
General
"
,
"
language
"
, name);
installTranslator
(m_translatorApp);
//
The application translation file has been found and loaded.
//
And now try to load a Qt translation file.
//
Search path:
//
1) standard Qt translations directory;
//
2) the application translations directory.
m_translatorQt =
new
QTranslator
(
this
);
ok = m_translatorQt->
load
(
"
qt_
"
+ name,
QLibraryInfo::location
(QLibraryInfo::TranslationsPath));
if
(ok ==
false
)
ok = m_translatorQt->
load
(
"
qt_
"
+ name,
"
translations
"
);
if
(ok ==
true
)
installTranslator
(m_translatorQt);
}
else
{
//
Set the correct locale so that the program won't erroneously detect
//
a language change when the user toggles settings for the first time.
//
(it also prevents the program from always looking for a translation on launch)
Settings::setValue
(
"
General
"
,
"
language
"
,
"
en_US
"
);
//
Don't install a translator for Qt texts if no translator for DB4S texts could be loaded
m_translatorQt =
nullptr
;
}
//
On Windows, add the plugins subdirectory to the list of library directories. We need this
//
for Qt to search for more image format plugins.
#
ifdef
Q_WS_WIN
QApplication::addLibraryPath
(
QApplication::applicationDirPath
() +
"
/plugins
"
);
#
endif
//
Work around a bug in QNetworkAccessManager which sporadically causes high pings for Wifi connections
//
See https://bugreports.qt.io/browse/QTBUG-40332
qputenv
(
"
QT_BEARER_POLL_TIMEOUT
"
,
QByteArray::number
(
INT_MAX
));
//
Parse command line
QString fileToOpen;
QString tableToBrowse;
QStringList sqlToExecute;
bool
readOnly =
false
;
m_dontShowMainWindow =
false
;
for
(
int
i=
1
;i<
arguments
().
size
();i++)
{
//
Check next command line argument
if
(
arguments
().
at
(i) ==
"
-h
"
||
arguments
().
at
(i) ==
"
--help
"
)
{
//
Help
qWarning
() <<
qPrintable
(
tr
(
"
Usage: %1 [options] [db]
\n
"
).
arg
(argv[
0
]));
qWarning
() <<
qPrintable
(
tr
(
"
Possible command line arguments:
"
));
qWarning
() <<
qPrintable
(
tr
(
"
-h, --help
\t\t
Show command line options
"
));
qWarning
() <<
qPrintable
(
tr
(
"
-q, --quit
\t\t
Exit application after running scripts
"
));
qWarning
() <<
qPrintable
(
tr
(
"
-s, --sql [file]
\t
Execute this SQL file after opening the DB
"
));
qWarning
() <<
qPrintable
(
tr
(
"
-t, --table [table]
\t
Browse this table after opening the DB
"
));
qWarning
() <<
qPrintable
(
tr
(
"
-R, --read-only
\t
Open database in read-only mode
"
));
qWarning
() <<
qPrintable
(
tr
(
"
-o, --option [group/setting=value]
\t
Run application with this setting temporarily set to value
"
));
qWarning
() <<
qPrintable
(
tr
(
"
-v, --version
\t\t
Display the current version
"
));
qWarning
() <<
qPrintable
(
tr
(
"
[file]
\t\t
Open this SQLite database
"
));
m_dontShowMainWindow =
true
;
}
else
if
(
arguments
().
at
(i) ==
"
-v
"
||
arguments
().
at
(i) ==
"
--version
"
) {
qWarning
() <<
qPrintable
(
tr
(
"
This is DB Browser for SQLite version %1.
"
).
arg
(
versionString
()));
m_dontShowMainWindow =
true
;
}
else
if
(
arguments
().
at
(i) ==
"
-s
"
||
arguments
().
at
(i) ==
"
--sql
"
) {
//
Run SQL file: If file exists add it to list of scripts to execute
if
(++i >=
arguments
().
size
())
qWarning
() <<
qPrintable
(
tr
(
"
The -s/--sql option requires an argument
"
));
else
if
(!
QFile::exists
(
arguments
().
at
(i)))
qWarning
() <<
qPrintable
(
tr
(
"
The file %1 does not exist
"
).
arg
(
arguments
().
at
(i)));
else
sqlToExecute.
append
(
arguments
().
at
(i));
}
else
if
(
arguments
().
at
(i) ==
"
-t
"
||
arguments
().
at
(i) ==
"
--table
"
) {
if
(++i >=
arguments
().
size
())
qWarning
() <<
qPrintable
(
tr
(
"
The -t/--table option requires an argument
"
));
else
tableToBrowse =
arguments
().
at
(i);
}
else
if
(
arguments
().
at
(i) ==
"
-q
"
||
arguments
().
at
(i) ==
"
--quit
"
) {
m_dontShowMainWindow =
true
;
}
else
if
(
arguments
().
at
(i) ==
"
-R
"
||
arguments
().
at
(i) ==
"
--read-only
"
) {
readOnly =
true
;
}
else
if
(
arguments
().
at
(i) ==
"
-o
"
||
arguments
().
at
(i) ==
"
--option
"
) {
const
QString optionWarning =
tr
(
"
The -o/--option option requires an argument in the form group/setting=value
"
);
if
(++i >=
arguments
().
size
())
qWarning
() <<
qPrintable
(optionWarning);
else
{
QStringList option =
arguments
().
at
(i).
split
(
"
=
"
);
if
(option.
size
() !=
2
)
qWarning
() <<
qPrintable
(optionWarning);
else
{
QStringList setting = option.
at
(
0
).
split
(
"
/
"
);
if
(setting.
size
() !=
2
)
qWarning
() <<
qPrintable
(optionWarning);
else
Settings::setValue
(setting.
at
(
0
), setting.
at
(
1
), option.
at
(
1
),
/*
dont_save_to_disk
*/
true
);
}
}
}
else
{
//
Other: Check if it's a valid file name
if
(
QFile::exists
(
arguments
().
at
(i)))
fileToOpen =
arguments
().
at
(i);
else
qWarning
() <<
qPrintable
(
tr
(
"
Invalid option/non-existant file: %1
"
).
arg
(
arguments
().
at
(i)));
}
}
//
Show main window
m_mainWindow =
new
MainWindow
();
m_mainWindow->
show
();
connect
(
this
,
SIGNAL
(
lastWindowClosed
()),
this
,
SLOT
(
quit
()));
//
Open database if one was specified
if
(fileToOpen.
size
())
{
if
(m_mainWindow->
fileOpen
(fileToOpen,
false
, readOnly))
{
//
If database could be opened run the SQL scripts
for
(
const
QString& f : sqlToExecute)
{
QFile
file
(f);
if
(file.
open
(QIODevice::ReadOnly))
{
m_mainWindow->
getDb
().
executeMultiSQL
(file.
readAll
(),
false
,
true
);
file.
close
();
}
}
if
(!sqlToExecute.
isEmpty
())
m_mainWindow->
refresh
();
//
Jump to table if the -t/--table parameter was set
if
(!tableToBrowse.
isEmpty
())
m_mainWindow->
switchToBrowseDataTab
(tableToBrowse);
}
}
}
Application::~Application
()
{
delete
m_mainWindow;
}
bool
Application::event
(QEvent* event)
{
switch
(event->
type
())
{
case
QEvent::FileOpen:
m_mainWindow->
fileOpen
(
static_cast
<QFileOpenEvent*>(event)->
file
());
return
true
;
default
:
return
QApplication::event
(event);
}
}
QString
Application::versionString
()
{
//
Distinguish between high and low patch version numbers. High numbers as in x.y.99 indicate nightly builds or
//
beta releases. For these we want to include the build date. For the release versions we don't add the release
//
date in order to avoid confusion about what is more important, version number or build date, and about different
//
build dates for the same version. This also should help making release builds reproducible out of the box.
#
if
PATCH_VERSION >= 99
return
QString
(
"
%1 (%2)
"
).
arg
(
APP_VERSION
).
arg
(__DATE__);
#
else
return
QString
(
"
%1
"
).
arg
(
APP_VERSION
);
#
endif
}
You can’t perform that action at this time.