2021-12-20 04:02:48 -05:00
package gokwallet
2021-12-22 03:20:08 -05:00
import (
"github.com/godbus/dbus/v5"
)
2021-12-20 04:02:48 -05:00
/ *
NewUnknownItem returns an UnknownItem . It requires a RecurseOpts
( you can use DefaultRecurseOpts , call NewRecurseOpts , or provide your own RecurseOpts struct ) .
It also requires a Folder .
* /
func NewUnknownItem ( f * Folder , keyName string , recursion * RecurseOpts ) ( unknown * UnknownItem , err error ) {
if ! f . isInit {
2021-12-25 02:54:18 -05:00
err = ErrInitFolder
2021-12-20 04:02:48 -05:00
return
}
unknown = & UnknownItem {
DbusObject : f . DbusObject ,
Name : keyName ,
// Value: "",
Recurse : recursion ,
wm : f . wallet . wm ,
wallet : f . wallet ,
folder : f ,
isInit : false ,
}
2021-12-25 02:54:18 -05:00
unknown . isInit = true
2021-12-20 04:02:48 -05:00
if unknown . Recurse . AllWalletItems || unknown . Recurse . UnknownItems {
if err = unknown . Update ( ) ; err != nil {
return
}
}
unknown . isInit = true
return
}
2021-12-23 04:21:21 -05:00
// Delete will delete this UnknownItem from its parent Folder. You may want to run Folder.UpdateUnknowns to update the existing map of UnknownItem items.
func ( u * UnknownItem ) Delete ( ) ( err error ) {
if err = u . folder . RemoveEntry ( u . Name ) ; err != nil {
return
}
u = nil
return
}
2021-12-28 02:50:54 -05:00
// Exists returns true if this UnknownItem actually exists.
func ( u * UnknownItem ) Exists ( ) ( exists bool , err error ) {
if exists , err = u . folder . HasEntry ( u . Name ) ; err != nil {
return
}
return
}
// Rename renames this UnknownItem (changes its key).
func ( u * UnknownItem ) Rename ( newName string ) ( err error ) {
if err = u . folder . RenameEntry ( u . Name , newName ) ; err != nil {
return
}
u . Name = newName
return
}
2021-12-23 04:21:21 -05:00
// SetValue will replace this UnknownItem's UnknownItem.Value.
func ( u * UnknownItem ) SetValue ( newValue [ ] byte ) ( err error ) {
if _ , err = u . folder . WriteUnknown ( u . Name , newValue ) ; err != nil {
return
}
u . Value = newValue
return
}
2021-12-20 04:02:48 -05:00
// Update fetches an UnknownItem's UnknownItem.Value.
func ( u * UnknownItem ) Update ( ) ( err error ) {
2021-12-25 02:54:18 -05:00
var call * dbus . Call
2021-12-22 03:20:08 -05:00
var v dbus . Variant
2021-12-28 02:50:54 -05:00
if err = u . folder . wallet . walletCheck ( ) ; err != nil {
return
}
2021-12-25 02:54:18 -05:00
if call = u . Dbus . Call (
2021-12-22 03:20:08 -05:00
DbusWMReadEntry , 0 , u . folder . wallet . handle , u . folder . Name , u . Name , u . folder . wallet . wm . AppID ,
2021-12-25 02:54:18 -05:00
) ; call . Err != nil {
err = call . Err
return
}
if err = call . Store ( & v ) ; err != nil {
2021-12-22 03:20:08 -05:00
return
}
u . Value = v . Value ( ) . ( [ ] byte )
2021-12-20 04:02:48 -05:00
return
}
// isWalletItem is needed for interface membership.
func ( u * UnknownItem ) isWalletItem ( ) ( isWalletItem bool ) {
isWalletItem = true
return
}