Add rendering forms to messages, add configuring mucs, add getting muc affiliations, add a bunch of other stuff idk man check the diff
This commit is contained in:
1 parent
7a875f84a5
commit
34b885a770
19 files changed
+706
-101
No files matched your search
+222
-5
@@ -7,7 +7,10 @@ import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
_ "sync"
|
||||
|
||||
"github.com/boxes-ltd/imaging"
|
||||
"github.com/crazy3lf/colorconv"
|
||||
@@ -77,7 +80,11 @@ func showUserWindow(u stanza.Presence, custom_nick string) {
|
||||
win.SetTitle(JidMustParse(u.From).Resource)
|
||||
nick.AddCSSClass("author")
|
||||
nick.SetSelectable(true)
|
||||
profile_box.Append(nick)
|
||||
|
||||
nbox := gtk.NewBox(gtk.OrientationHorizontal, 5)
|
||||
nbox.SetHAlign(gtk.AlignCenter)
|
||||
nbox.Append(nick)
|
||||
profile_box.Append(nbox)
|
||||
if u.Status != "" {
|
||||
status_message := gtk.NewLabel(u.Status)
|
||||
status_message.AddCSSClass("status")
|
||||
@@ -128,6 +135,7 @@ func showUserWindow(u stanza.Presence, custom_nick string) {
|
||||
if ok {
|
||||
for _, hat := range hats.Hats {
|
||||
l := gtk.NewLabel(hat.Title)
|
||||
l.SetSelectable(true)
|
||||
l.AddCSSClass("hat")
|
||||
profile_box.Append(l)
|
||||
}
|
||||
@@ -141,6 +149,11 @@ func showUserWindow(u stanza.Presence, custom_nick string) {
|
||||
ji.AddCSSClass("jid")
|
||||
ji.SetSelectable(true)
|
||||
profile_box.Append(ji)
|
||||
if JidMustParse(mu.MucUserItem.JID).Bare() == JidMustParse(clientroot.Session.BindJid).Bare() {
|
||||
you_label := gtk.NewLabel("(You)")
|
||||
you_label.AddCSSClass("you")
|
||||
nbox.Append(you_label)
|
||||
}
|
||||
}
|
||||
profile_box.Append(gtk.NewLabel(loadedLocale["connectedWithRole"] + mu.MucUserItem.Role))
|
||||
var affil string
|
||||
@@ -308,7 +321,7 @@ func createTab(jid string, isMuc bool, name string) bool {
|
||||
})
|
||||
newTab.name = name
|
||||
newTab.msg_refsID = make(map[string]*abMessage)
|
||||
newTab.msg_refsOSID = make(map[string]*abMessage)
|
||||
//newTab.msg_refsOSID = make(map[string]*abMessage)
|
||||
tabs.Store(jid, newTab)
|
||||
return true
|
||||
}
|
||||
@@ -785,11 +798,215 @@ func showErrorDialog(err error, w *gtk.Window) {
|
||||
err_win.Present()
|
||||
}
|
||||
|
||||
func showDialog(s string, w *gtk.Window) {
|
||||
err_win := gtk.NewWindow()
|
||||
err_win.SetTitle("Information")
|
||||
err_win.SetDefaultSize(400, 200)
|
||||
err_win.SetResizable(false)
|
||||
|
||||
box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
err_label := gtk.NewLabel(s)
|
||||
err_label.SetSelectable(true)
|
||||
box.Append(err_label)
|
||||
|
||||
close_btn := gtk.NewButtonWithLabel(loadedLocale["close"])
|
||||
close_btn.ConnectClicked(func() {
|
||||
err_win.Destroy()
|
||||
})
|
||||
box.Append(close_btn)
|
||||
err_win.SetChild(box)
|
||||
err_win.SetTransientFor(w)
|
||||
err_win.Present()
|
||||
}
|
||||
|
||||
func showFormDialog(f stanza.Form) (*stanza.Form, gtk.Window, string) {
|
||||
form_type := ""
|
||||
|
||||
var ret *stanza.Form = &f
|
||||
|
||||
form_win := gtk.NewWindow()
|
||||
form_win.SetTitle(f.Title)
|
||||
form_win.SetDefaultSize(400, 400)
|
||||
form_win.SetResizable(false)
|
||||
|
||||
form_box := gtk.NewBox(gtk.OrientationVertical, 2)
|
||||
|
||||
for _, instruction := range f.Instructions {
|
||||
form_box.Append(gtk.NewLabel(instruction))
|
||||
}
|
||||
|
||||
// for x, item := range f.Items {
|
||||
for y, field := range f.Fields {
|
||||
if field.Var == "FORM_TYPE" {
|
||||
form_type = field.ValuesList[0]
|
||||
}
|
||||
field_box := gtk.NewBox(gtk.OrientationHorizontal, 2)
|
||||
field_label := gtk.NewLabel(field.Label)
|
||||
field_label.SetTooltipText(field.Description)
|
||||
|
||||
btn_box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
btn_box.SetHAlign(gtk.AlignEnd)
|
||||
btn_box.SetHExpand(true)
|
||||
|
||||
switch field.Type {
|
||||
case "boolean":
|
||||
if len(field.ValuesList) == 0 {
|
||||
field.ValuesList = append(field.ValuesList, "0")
|
||||
f.Fields[y].ValuesList = append(f.Fields[y].ValuesList, "0")
|
||||
}
|
||||
|
||||
tick := gtk.NewCheckButton()
|
||||
if field.ValuesList[0] == "1" {
|
||||
tick.SetActive(true)
|
||||
} else {
|
||||
tick.SetActive(false)
|
||||
}
|
||||
|
||||
tick.ConnectToggled(func() {
|
||||
str := ""
|
||||
if tick.Active() {
|
||||
str = "1"
|
||||
} else {
|
||||
str = "0"
|
||||
}
|
||||
f.Fields[y].ValuesList[0] = str
|
||||
})
|
||||
btn_box.Append(tick)
|
||||
case "fixed":
|
||||
for _, v := range field.ValuesList {
|
||||
label := gtk.NewLabel(v)
|
||||
label.AddCSSClass("visitor")
|
||||
btn_box.SetHAlign(gtk.AlignCenter)
|
||||
btn_box.Append(label)
|
||||
}
|
||||
case "hidden":
|
||||
// do nothing
|
||||
case "jid-multi":
|
||||
// TODO
|
||||
case "jid-single":
|
||||
e_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
jid_entry := gtk.NewEntry()
|
||||
jid_entry.SetText(field.ValuesList[0])
|
||||
buildAJIDButton := gtk.NewImageFromPaintable(clientAssetsLoad("jabber"))
|
||||
buildAJIDButton.Connect("pressed", func() {
|
||||
jidBuilder(jid_entry)
|
||||
})
|
||||
|
||||
jid_entry.ConnectChanged(func() {
|
||||
f.Fields[y].ValuesList[0] = jid_entry.Text()
|
||||
})
|
||||
|
||||
e_box.Append(buildAJIDButton)
|
||||
e_box.Append(jid_entry)
|
||||
|
||||
btn_box.Append(e_box)
|
||||
case "list-multi":
|
||||
// TODO
|
||||
case "list-single":
|
||||
var selected uint
|
||||
str := []string{}
|
||||
for i, option := range field.Options {
|
||||
if slices.Equal(option.ValuesList, field.ValuesList) {
|
||||
selected = uint(i)
|
||||
}
|
||||
str = append(str, option.ValuesList[0])
|
||||
}
|
||||
|
||||
dropdown := gtk.NewDropDownFromStrings(str)
|
||||
dropdown.SetSelected(selected)
|
||||
dropdown.ConnectActivate(func() {
|
||||
f.Fields[y].ValuesList[0] = field.Options[dropdown.Selected()].ValuesList[0]
|
||||
})
|
||||
|
||||
btn_box.Append(dropdown)
|
||||
case "text-private":
|
||||
p_entry := gtk.NewPasswordEntry()
|
||||
p_entry.SetText(field.ValuesList[0])
|
||||
p_entry.ConnectChanged(func() {
|
||||
f.Fields[y].ValuesList[0] = p_entry.Text()
|
||||
})
|
||||
|
||||
btn_box.Append(p_entry)
|
||||
case "text-multi":
|
||||
textView := gtk.NewTextView()
|
||||
textView.SetWrapMode(gtk.WrapWordChar)
|
||||
txt := ""
|
||||
|
||||
for i, line := range field.ValuesList {
|
||||
txt = txt + line
|
||||
if i != len(field.ValuesList)-1 {
|
||||
txt = txt + "\n"
|
||||
}
|
||||
}
|
||||
textView.Buffer().SetText(txt)
|
||||
|
||||
textView.Buffer().ConnectChanged(func() {
|
||||
txt := textView.Buffer().Text(textView.Buffer().StartIter(), textView.Buffer().EndIter(), false)
|
||||
f.Fields[y].ValuesList = strings.Split(txt, "\n")
|
||||
})
|
||||
|
||||
scroll := gtk.NewScrolledWindow()
|
||||
scroll.SetChild(textView)
|
||||
scroll.SetMinContentHeight(150)
|
||||
|
||||
btn_box.Append(scroll)
|
||||
|
||||
default: // includes text-single
|
||||
en := gtk.NewEntry()
|
||||
txt := ""
|
||||
if len(field.ValuesList) != 0 {
|
||||
txt = field.ValuesList[0]
|
||||
}
|
||||
en.SetText(txt)
|
||||
en.ConnectChanged(func() {
|
||||
if len(field.ValuesList) == 0 {
|
||||
f.Fields[y].ValuesList = append(f.Fields[y].ValuesList, en.Text())
|
||||
} else {
|
||||
f.Fields[y].ValuesList[0] = en.Text()
|
||||
}
|
||||
})
|
||||
|
||||
btn_box.Append(en)
|
||||
}
|
||||
|
||||
field_box.Append(field_label)
|
||||
field_box.Append(btn_box)
|
||||
form_box.Append(field_box)
|
||||
}
|
||||
|
||||
form_box.Append(gtk.NewSeparator(gtk.OrientationHorizontal))
|
||||
|
||||
btn_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
btn_box.SetHAlign(gtk.AlignCenter)
|
||||
|
||||
cancelbtn := gtk.NewButtonWithLabel("Cancel")
|
||||
cancelbtn.ConnectClicked(func() {
|
||||
form_win.Close()
|
||||
})
|
||||
|
||||
okbtn := gtk.NewButtonWithLabel(loadedLocale["submit"])
|
||||
okbtn.ConnectClicked(func() {
|
||||
ret = &f
|
||||
form_win.Close()
|
||||
})
|
||||
|
||||
btn_box.Append(okbtn)
|
||||
btn_box.Append(cancelbtn)
|
||||
|
||||
form_box.Append(btn_box)
|
||||
|
||||
form_win.SetChild(form_box)
|
||||
form_win.SetVisible(true)
|
||||
|
||||
return ret, *form_win, form_type
|
||||
}
|
||||
|
||||
func createIdenticon(word string, always_create bool, i *gtk.Image) { // This function generates an identicon
|
||||
if !loadedConfig.Identicons && !always_create {
|
||||
// return gtk.NewImageFromPaintable(clientAssetsLoad("DefaultAvatar"))
|
||||
glib.IdleAdd(func() {
|
||||
i.SetFromPaintable(clientAssetsLoad("DefaultAvatar"))
|
||||
p := clientAssetsLoad("DefaultAvatar")
|
||||
glib.IdleAddPriority(glib.PriorityLow, func() {
|
||||
i.SetFromPaintable(p)
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -814,7 +1031,7 @@ func createIdenticon(word string, always_create bool, i *gtk.Image) { // This fu
|
||||
p := loader.Pixbuf()
|
||||
gt := gdk.NewTextureForPixbuf(p)
|
||||
|
||||
glib.IdleAdd(func() {
|
||||
glib.IdleAddPriority(glib.PriorityLow, func() {
|
||||
i.SetFromPaintable(gt)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user