This repository has been archived by the owner on Oct 6, 2018. It is now read-only.
/
main.go
97 lines (82 loc) · 2.68 KB
/
main.go
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
// Copyright © 2018 MTRNord <info@nordgedanken.de>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package app
import (
"database/sql"
"github.com/Nordgedanken/Morpheusv2/pkg/loginUI"
"github.com/Nordgedanken/Morpheusv2/pkg/mainUI"
"github.com/Nordgedanken/Morpheusv2/pkg/util"
"github.com/matrix-org/gomatrix"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
"log"
)
var args []string
var cli *gomatrix.Client
var windowHeight = 600
var windowWidth = 950
var window *widgets.QMainWindow
// Start prepares the Main QT Window and opens it
func Start(argsArg []string) error {
args = argsArg
log.Println("Starting Morpheus v2")
initApp()
_, err := util.DB.GetCurrentUser()
// We special case ErrNoRows because this is expected to happen if user is missing
if err == sql.ErrNoRows {
loginUIs := loginUI.NewLoginUI(windowWidth, windowHeight, window)
SetNewWindow(loginUIs, window)
} else if err != nil {
return err
} else {
mainUIs := mainUI.NewMainUI(windowWidth, windowHeight, window)
SetNewWindow(mainUIs, window)
}
widgets.QApplication_Exec()
return nil
}
func initApp() {
log.Println("Create QApp")
app := widgets.NewQApplication(len(args), args)
app.SetAttribute(core.Qt__AA_UseHighDpiPixmaps, true)
app.SetApplicationName("Morpheus")
app.SetApplicationVersion("0.1.0")
appIcon := gui.NewQIcon5(":/qml/resources/logos/MorpheusBig.png")
app.SetWindowIcon(appIcon)
window = widgets.NewQMainWindow(nil, 0)
app.SetActiveWindow(window)
desktopApp := app.Desktop()
primaryScreen := desktopApp.PrimaryScreen()
screen := desktopApp.Screen(primaryScreen)
windowX := (screen.Width() - windowHeight) / 2
windowY := (screen.Height() - windowWidth) / 2
window.Resize2(windowWidth, windowHeight)
window.Move2(windowX, windowY)
window.ConnectCloseEvent(func(event *gui.QCloseEvent) {
log.Println("Morpheus closed")
})
}
// SetNewWindow loads the new UI into the QMainWindow
func SetNewWindow(ui ui, window *widgets.QMainWindow) error {
ui.SetCli(cli)
uiErr := ui.NewUI()
if uiErr != nil {
return uiErr
}
ui.GetWidget().Resize2(windowWidth, windowHeight)
window.SetCentralWidget(ui.GetWidget())
window.Show()
return nil
}