one object to rule them all -_-;; adding identities is now ugly but live
This commit is contained in:
parent
dbd646230c
commit
d6317563ea
138
identities.go
138
identities.go
|
@ -1,138 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/therecipe/qt/core"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() { QIdentityListModel_QmlRegisterType2("CustomQmlTypes", 1, 0, "QIdentityListModel") }
|
|
||||||
// TODO: register QObj of Item
|
|
||||||
|
|
||||||
const (
|
|
||||||
Name = int(core.Qt__UserRole) + 1<<iota
|
|
||||||
Onion
|
|
||||||
Color
|
|
||||||
ButtonType
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
identity = iota
|
|
||||||
unlock
|
|
||||||
add
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
type IdentityListItem struct {
|
|
||||||
|
|
||||||
name, onion, color string
|
|
||||||
buttonType int
|
|
||||||
|
|
||||||
/*core.QObject
|
|
||||||
|
|
||||||
//name, onion, color string
|
|
||||||
//buttonType int
|
|
||||||
_ string `property:"name"`
|
|
||||||
_ string `property:"onion"`
|
|
||||||
_ string `property:"color"`
|
|
||||||
_ int `property:"buttonType"`
|
|
||||||
|
|
||||||
_ func() `signal:"identityClick,auto"`
|
|
||||||
_ func() `signal:"unlockClick,auto"`
|
|
||||||
_ func() `signal:"addClick,auto"`
|
|
||||||
_ func() `signal:"unknownClick,auto"`*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
func NewIdentityListItemValues(name, onion, color string, buttonType int) *IdentityListItem {
|
|
||||||
i := NewIdentityListItem(nil)
|
|
||||||
i.SetName(name)
|
|
||||||
i.SetOnion(onion)
|
|
||||||
i.SetColor(color)
|
|
||||||
i.SetButtonType(buttonType)
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
type QIdentityListModel struct {
|
|
||||||
core.QAbstractListModel
|
|
||||||
|
|
||||||
_ int `property:"typeIdentity"`
|
|
||||||
_ int `property:"typeUnlock"`
|
|
||||||
_ int `property:"typeAdd"`
|
|
||||||
|
|
||||||
_ func() `constructor:"init"`
|
|
||||||
|
|
||||||
_ func(string) `signal:"clickIdentity,auto"`
|
|
||||||
|
|
||||||
//_ func() `signal:"remove,auto"`
|
|
||||||
//_ func(obj []*core.QVariant) `signal:"add,auto"`
|
|
||||||
//_ func(name string, onion string, color string) `signal:"edit,auto"`
|
|
||||||
|
|
||||||
modelData []IdentityListItem
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *QIdentityListModel) init() {
|
|
||||||
m.modelData = []IdentityListItem{}
|
|
||||||
m.SetTypeIdentity(identity)
|
|
||||||
m.SetTypeUnlock(unlock)
|
|
||||||
m.SetTypeAdd(add)
|
|
||||||
|
|
||||||
m.ConnectRoleNames(m.roleNames)
|
|
||||||
m.ConnectRowCount(m.rowCount)
|
|
||||||
m.ConnectData(m.data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *QIdentityListModel) roleNames() map[int]*core.QByteArray {
|
|
||||||
return map[int]*core.QByteArray{
|
|
||||||
Name: core.NewQByteArray2("Name", -1),
|
|
||||||
Onion: core.NewQByteArray2("Onion", -1),
|
|
||||||
Color: core.NewQByteArray2("Color", -1),
|
|
||||||
ButtonType: core.NewQByteArray2("ButtonType", -1),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *QIdentityListModel) rowCount(*core.QModelIndex) int {
|
|
||||||
return len(m.modelData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *QIdentityListModel) data(index *core.QModelIndex, role int) *core.QVariant {
|
|
||||||
item := m.modelData[index.Row()]
|
|
||||||
switch role {
|
|
||||||
case Name:
|
|
||||||
return core.NewQVariant14(item.name)
|
|
||||||
case Onion:
|
|
||||||
return core.NewQVariant14(item.onion)
|
|
||||||
case Color:
|
|
||||||
return core.NewQVariant14(item.color)
|
|
||||||
case ButtonType:
|
|
||||||
return core.NewQVariant7(item.buttonType)
|
|
||||||
}
|
|
||||||
return core.NewQVariant()
|
|
||||||
}
|
|
||||||
|
|
||||||
/*func (m *QIdentityListModel) remove() {
|
|
||||||
if len(m.modelData) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.BeginRemoveRows(core.NewQModelIndex(), len(m.modelData)-1, len(m.modelData)-1)
|
|
||||||
m.modelData = m.modelData[:len(m.modelData)-1]
|
|
||||||
m.EndRemoveRows()
|
|
||||||
}*/
|
|
||||||
|
|
||||||
func (m *QIdentityListModel) Add(i IdentityListItem) {
|
|
||||||
m.BeginInsertRows(core.NewQModelIndex(), len(m.modelData), len(m.modelData))
|
|
||||||
m.modelData = append(m.modelData, i)
|
|
||||||
m.EndInsertRows()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *QIdentityListModel) clickIdentity(s string) {
|
|
||||||
fmt.Println("clickIdentity: '" + s + "'")
|
|
||||||
}
|
|
||||||
|
|
||||||
/*func (m *QIdentityListModel) edit(name string, onion string, pcolor string) {
|
|
||||||
if len(m.modelData) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.modelData[len(m.modelData)-1] = IdentityListItem{name, onion, pcolor}
|
|
||||||
m.DataChanged(m.Index(len(m.modelData)-1, 0, core.NewQModelIndex()), m.Index(len(m.modelData)-1, 1, core.NewQModelIndex()), []int{Name, Onion, Pcolor})
|
|
||||||
}*/
|
|
54
main.go
54
main.go
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/therecipe/qt/core"
|
"github.com/therecipe/qt/core"
|
||||||
"github.com/therecipe/qt/gui"
|
"github.com/therecipe/qt/gui"
|
||||||
"github.com/therecipe/qt/qml"
|
"github.com/therecipe/qt/qml"
|
||||||
"github.com/therecipe/qt/quickcontrols2"
|
|
||||||
"git.openprivacy.ca/openprivacy/asaur"
|
"git.openprivacy.ca/openprivacy/asaur"
|
||||||
"cwtch.im/cwtch/app"
|
"cwtch.im/cwtch/app"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -15,26 +14,58 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
identity = iota
|
||||||
|
unlock
|
||||||
|
add
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
type QmlCwtchApp struct {
|
type QmlCwtchApp struct {
|
||||||
core.QObject
|
core.QObject
|
||||||
|
|
||||||
_ int `property:"torStatusProgress"`
|
_ int `property:"torStatusProgress"`
|
||||||
_ string `property:"torStatusSummary"`
|
_ string `property:"torStatusSummary"`
|
||||||
|
|
||||||
//_ QIdentityListModel `property:"identities"`
|
_ int `property:"typeIdentity"`
|
||||||
|
_ int `property:"typeUnlock"`
|
||||||
|
_ int `property:"typeAdd"`
|
||||||
|
|
||||||
|
_ func(string) `signal:"identityClicked,auto"`
|
||||||
|
_ func(string, string) `signal:"identityCreate,auto"`
|
||||||
|
_ func(string, string, string, int) `signal:"identityAddList"`
|
||||||
|
|
||||||
_ func() `constructor:"init"`
|
_ func() `constructor:"init"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qCwtchApp *QmlCwtchApp) init() {
|
func (ca *QmlCwtchApp) init() {
|
||||||
|
ca.SetTypeIdentity(identity)
|
||||||
|
ca.SetTypeUnlock(unlock)
|
||||||
|
ca.SetTypeAdd(add)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ca *QmlCwtchApp) identityClicked(s string) {
|
||||||
|
fmt.Println("clickIdentity: '" + s + "'")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ca *QmlCwtchApp) identityCreate(name, password string) {
|
||||||
|
fmt.Printf("identityCreate(%v)\n", name)
|
||||||
|
peer, err := cwtchApp.CreatePeer(name, password)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR creating new identity: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ca.IdentityAddList(peer.GetProfile().Name, peer.GetProfile().Onion, "red", identity)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var cwtchApp app.Application
|
var cwtchApp app.Application
|
||||||
|
|
||||||
func InitCwtch(engine *qml.QQmlApplicationEngine, qCwtchApp *QmlCwtchApp, identityList *QIdentityListModel) error {
|
func InitCwtch(engine *qml.QQmlApplicationEngine, qCwtchApp *QmlCwtchApp) error {
|
||||||
|
|
||||||
torPath, err := exec.LookPath("tor")
|
torPath, err := exec.LookPath("tor")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -76,9 +107,8 @@ func InitCwtch(engine *qml.QQmlApplicationEngine, qCwtchApp *QmlCwtchApp, identi
|
||||||
identityList.Add( *NewIdentityListItemValues( "unlock", "", "#af921d", unlock))
|
identityList.Add( *NewIdentityListItemValues( "unlock", "", "#af921d", unlock))
|
||||||
identityList.Add( *NewIdentityListItemValues("add", "", "#e0e0e0", add))*/
|
identityList.Add( *NewIdentityListItemValues("add", "", "#e0e0e0", add))*/
|
||||||
|
|
||||||
identityList.Add( IdentityListItem{"alice", "1234567890abcdef", "red", identity})
|
//cwtchApp.i( IdentityListItem{"alice", "1234567890abcdef", "red", identity})
|
||||||
identityList.Add( IdentityListItem{"unlock", "", "#af921d", unlock})
|
|
||||||
identityList.Add( IdentityListItem{"add", "", "#e0e0e0", add})
|
|
||||||
|
|
||||||
<-doneChan
|
<-doneChan
|
||||||
|
|
||||||
|
@ -98,11 +128,9 @@ func main() {
|
||||||
// use the material style
|
// use the material style
|
||||||
// the other inbuild styles are:
|
// the other inbuild styles are:
|
||||||
// Default, Fusion, Imagine, Universal
|
// Default, Fusion, Imagine, Universal
|
||||||
quickcontrols2.QQuickStyle_SetStyle("Material")
|
//quickcontrols2.QQuickStyle_SetStyle("Material")
|
||||||
|
|
||||||
var qCwtchApp = NewQmlCwtchApp(nil)
|
var qCwtchApp = NewQmlCwtchApp(nil)
|
||||||
var identityList = NewQIdentityListModel(nil)
|
|
||||||
|
|
||||||
|
|
||||||
//qCwtchApp.SetIdentities(append(qCwtchApp.Identities(), alice))*/
|
//qCwtchApp.SetIdentities(append(qCwtchApp.Identities(), alice))*/
|
||||||
|
|
||||||
|
@ -112,7 +140,6 @@ func main() {
|
||||||
//engine.QmlRegisterType()
|
//engine.QmlRegisterType()
|
||||||
|
|
||||||
engine.RootContext().SetContextProperty("cwtchApp", qCwtchApp)
|
engine.RootContext().SetContextProperty("cwtchApp", qCwtchApp)
|
||||||
engine.RootContext().SetContextProperty("identityList", identityList)
|
|
||||||
|
|
||||||
// load the embeeded qml file
|
// load the embeeded qml file
|
||||||
// created by either qtrcc or qtdeploy
|
// created by either qtrcc or qtdeploy
|
||||||
|
@ -122,8 +149,9 @@ func main() {
|
||||||
// you can also load a local file like this instead:
|
// you can also load a local file like this instead:
|
||||||
//engine.Load(core.QUrl_FromLocalFile("./qml/main.qml"))
|
//engine.Load(core.QUrl_FromLocalFile("./qml/main.qml"))
|
||||||
engine.Load(core.NewQUrl3("qrc:/qml/main.qml", 0))
|
engine.Load(core.NewQUrl3("qrc:/qml/main.qml", 0))
|
||||||
|
engine.Load(core.NewQUrl3("qrc:/qml/AddIdentity.qml", 0))
|
||||||
|
|
||||||
go InitCwtch(engine, qCwtchApp, identityList)
|
go InitCwtch(engine, qCwtchApp)
|
||||||
// start the main Qt event loop
|
// start the main Qt event loop
|
||||||
// and block until app.Exit() is called
|
// and block until app.Exit() is called
|
||||||
// or the window is closed by the user
|
// or the window is closed by the user
|
||||||
|
|
1
qml.qrc
1
qml.qrc
|
@ -6,5 +6,6 @@
|
||||||
<file>qml/ProfilesColumn.qml</file>
|
<file>qml/ProfilesColumn.qml</file>
|
||||||
<file>qml/main.qml</file>
|
<file>qml/main.qml</file>
|
||||||
<file>assets/cwtch-logo.png</file>
|
<file>assets/cwtch-logo.png</file>
|
||||||
|
<file>qml/AddIdentity.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
import QtQuick 2.0
|
||||||
|
import QtQuick.Window 2.2
|
||||||
|
import QtQuick.Controls 1.4
|
||||||
|
|
||||||
|
//import CustomQmlTypes 1.0
|
||||||
|
|
||||||
|
Window {
|
||||||
|
visible: false
|
||||||
|
id: addIdentityWindow
|
||||||
|
|
||||||
|
width: 600
|
||||||
|
//minimumWidth: 600
|
||||||
|
height: 400
|
||||||
|
//minimumHeight: 400
|
||||||
|
title: "Add Identity"
|
||||||
|
|
||||||
|
signal closed
|
||||||
|
onVisibleChanged: if (!visible) closed()
|
||||||
|
|
||||||
|
Item {
|
||||||
|
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: 200
|
||||||
|
|
||||||
|
|
||||||
|
Column {
|
||||||
|
Text { text: "Name:" }
|
||||||
|
TextField { id: nameText }
|
||||||
|
TextField { id: password; echoMode: TextInput.Password }
|
||||||
|
TextField { id: passconfirm; echoMode: TextInput.Password }
|
||||||
|
Text { id: passError; visible: false; text: "Passwords do not match"; color: "red" }
|
||||||
|
Button { text: "Create"; isDefault: true;
|
||||||
|
onClicked: {
|
||||||
|
if (password.text !== passconfirm.text) {
|
||||||
|
passError.visible = true
|
||||||
|
} else {
|
||||||
|
passError.visible = false
|
||||||
|
cwtchApp.identityCreate(nameText.text, password.text)
|
||||||
|
addIdentityWindow.visible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
import QtQuick 2.9
|
import QtQuick 2.9
|
||||||
import QtQuick.Window 2.2
|
import QtQuick.Window 2.2
|
||||||
import CustomQmlTypes 1.0
|
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
//visible: false
|
//visible: false
|
||||||
|
@ -9,11 +8,8 @@ Window {
|
||||||
height: 800
|
height: 800
|
||||||
title: qsTr("Bulletin")
|
title: qsTr("Bulletin")
|
||||||
|
|
||||||
property alias model: profilesColumn.model
|
|
||||||
|
|
||||||
ProfilesColumn {
|
ProfilesColumn {
|
||||||
id: profilesColumn
|
id: profilesColumn
|
||||||
model: identityList
|
|
||||||
|
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
|
|
@ -1,18 +1,22 @@
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import CustomQmlTypes 1.0
|
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
||||||
color: "#381F47"
|
color: "#381F47"
|
||||||
|
|
||||||
property alias model: list.model
|
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: list
|
id: list
|
||||||
//height: parent.height
|
//height: parent.height
|
||||||
width: parent.width
|
width: parent.width
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
|
ListModel {
|
||||||
|
id: identitiesModel
|
||||||
|
ListElement { name: "unlock"; onion: ""; color: "#af921d"; buttonType: 1}
|
||||||
|
ListElement { name: "add"; onion: ""; color: "#e0e0e0"; buttonType: 2}
|
||||||
|
}
|
||||||
|
model: identitiesModel
|
||||||
|
|
||||||
highlight: Item { Rectangle { width: 4; height: 100; color: "white"; radius: 2} }
|
highlight: Item { Rectangle { width: 4; height: 100; color: "white"; radius: 2} }
|
||||||
|
|
||||||
//highlight: highlightBar
|
//highlight: highlightBar
|
||||||
|
@ -20,7 +24,19 @@ Rectangle {
|
||||||
|
|
||||||
delegate: profileDelegate
|
delegate: profileDelegate
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: cwtchApp
|
||||||
|
|
||||||
|
onIdentityAddList: function (name, onion, color, buttonType) {
|
||||||
|
console.log("on Identity-Add-List(" + name + "," + onion +","+ color+ "," + buttonType+")")
|
||||||
|
identitiesModel.insert(identitiesModel.count-2, {
|
||||||
|
"name": name,
|
||||||
|
"onion": onion,
|
||||||
|
"color": color,
|
||||||
|
"buttonType": buttonType
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
|
@ -35,8 +51,8 @@ Rectangle {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: 10
|
anchors.leftMargin: 10
|
||||||
|
|
||||||
Rectangle { y: 10; width: 80; height: 80; color: model.Color }
|
Rectangle { y: 10; width: 80; height: 80; color: model.color }
|
||||||
Text { color: "#a0a0a0"; text: Name }
|
Text { color: "#a0a0a0"; text: name }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +63,18 @@ Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
list.currentIndex = index
|
list.currentIndex = index
|
||||||
list.model.clickIdentity(model.Name)
|
|
||||||
|
// var addIWin = AddIdentity{ }
|
||||||
|
console.log("onClicked " + model.name + " type " + model.buttonType)
|
||||||
|
if (model.buttonType === cwtchApp.typeAdd) {
|
||||||
|
var component = Qt.createComponent("AddIdentity.qml")
|
||||||
|
var object = component.createObject(root)
|
||||||
|
object.show()
|
||||||
|
//object.closed.connect(function() { object.destroy() })
|
||||||
|
} else
|
||||||
|
if (model.ButtonType === cwtchApp.typeIdentity) {
|
||||||
|
cwtchApp.identityClicked(model.name + " " + model.buttonType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ import QtQuick 2.0
|
||||||
import QtQuick.Controls 1.0
|
import QtQuick.Controls 1.0
|
||||||
import QtQuick.Layouts 1.0
|
import QtQuick.Layouts 1.0
|
||||||
import QtQuick.Window 2.0
|
import QtQuick.Window 2.0
|
||||||
import CustomQmlTypes 1.0
|
|
||||||
|
|
||||||
// Root non-graphical object providing window management and other logic.
|
// Root non-graphical object providing window management and other logic.
|
||||||
QtObject {
|
QtObject {
|
||||||
|
@ -12,8 +11,6 @@ QtObject {
|
||||||
onVisibleChanged: if (!visible) Qt.quit()
|
onVisibleChanged: if (!visible) Qt.quit()
|
||||||
}
|
}
|
||||||
|
|
||||||
property QIdentityListModel model: identityList
|
|
||||||
|
|
||||||
property LoadingWindow loadingWindow: LoadingWindow { visible: true }
|
property LoadingWindow loadingWindow: LoadingWindow { visible: true }
|
||||||
|
|
||||||
property Timer timer: Timer {
|
property Timer timer: Timer {
|
||||||
|
|
Loading…
Reference in New Issue