Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
bitmask-vpn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Merlin
bitmask-vpn
Commits
7f53bdb6
Unverified
Commit
7f53bdb6
authored
4 years ago
by
Kali Kaneko
Browse files
Options
Downloads
Patches
Plain Diff
[refactor] remove unneeded cruft
Signed-off-by:
kali kaneko (leap communications)
<
kali@leap.se
>
parent
737b82ac
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gui/main.cpp
+16
-38
16 additions, 38 deletions
gui/main.cpp
with
16 additions
and
38 deletions
gui/main.cpp
+
16
−
38
View file @
7f53bdb6
#include
<QApplication>
#include
<QQmlApplicationEngine>
#include
<QQuickWindow>
#include
<QSystemTrayIcon>
#include
<QTimer>
#include
<QtQml>
#include
<QQmlApplicationEngine>
#include
<QQuickWindow>
#include
<string>
#include
"handlers.h"
...
...
@@ -13,45 +14,15 @@
from blockbusters like "here be dragons" and "darling, I wrote a little
contraption". */
/* Our glorious global object state. In here we store a serialized snapshot of
the context from the application "backend", living in the linked Go-land
lib. */
QJsonWatch
*
qw
=
new
QJsonWatch
;
static
char
*
json
;
/* onStatusChanged is the C function that we register as a callback with CGO.
It pulls a string serialization of the context object, than we then pass
along to Qml via signals. */
/* We are interested in observing changes to this global json variable.
The jsonWatchdog bridges the gap from pure c callbacks to the rest of the c++
logic. QJsonWatch comes from QObject so it can emit signals. */
QJsonWatch
*
qw
;
struct
jsonWatchdog
{
jsonWatchdog
()
{
qw
=
new
QJsonWatch
;
}
void
changed
()
{
emit
qw
->
jsonChanged
(
QString
(
json
));
}
};
/* we need C wrappers around every C++ object, so that we can invoke their methods
from the function pointers passed as callbacks to CGO. */
extern
"C"
{
static
void
*
newWatchdog
(
void
)
{
return
(
void
*
)(
new
jsonWatchdog
);
}
static
void
jsonChanged
(
void
*
ptr
)
{
if
(
ptr
!=
NULL
)
{
jsonWatchdog
*
klsPtr
=
static_cast
<
jsonWatchdog
*>
(
ptr
);
klsPtr
->
changed
();
}
}
}
void
*
wd
=
newWatchdog
();
/* onStatusChanged is the C function that we register as a callback with CGO,
to be called from the Go side. It pulls a string serialization of the
context object, than we then pass along to Qt objects and to Qml. */
void
onStatusChanged
()
{
char
*
ctx
=
RefreshContext
();
json
=
ctx
;
/* the method wrapped emits a qt signal */
jsonChanged
(
wd
);
emit
qw
->
jsonChanged
(
QString
(
ctx
));
free
(
ctx
);
}
...
...
@@ -71,8 +42,15 @@ int main(int argc, char **argv) {
exit
(
0
);
}
QApplication
::
setAttribute
(
Qt
::
AA_EnableHighDpiScaling
);
QApplication
app
(
argc
,
argv
);
if
(
!
QSystemTrayIcon
::
isSystemTrayAvailable
())
{
qDebug
()
<<
"No systray icon available. Things won't work for now, sorry..."
;
exit
(
1
);
}
app
.
setQuitOnLastWindowClosed
(
false
);
QQmlApplicationEngine
engine
;
QQmlContext
*
ctx
=
engine
.
rootContext
();
...
...
@@ -95,7 +73,7 @@ int main(int argc, char **argv) {
/* connect the jsonChanged signal explicitely.
In the lambda, we reload the json in the model every time we receive an
update from Go */
QObject
::
connect
(
qw
,
&
QJsonWatch
::
jsonChanged
,
[
ctx
,
model
](
QString
js
)
{
QObject
::
connect
(
qw
,
&
QJsonWatch
::
jsonChanged
,
[
model
](
QString
js
)
{
model
->
loadJson
(
js
.
toUtf8
());
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment