Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic configuration #112

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ea6cf4d
[qml][settings] Set up general stack view to open settings page
stdevMac Aug 21, 2019
5ea7a90
[qml][settings] Add menu bar for settings and display basic Page
stdevMac Aug 21, 2019
b8a2160
[config] Code ConfigManager, walletSource, WalletSource types and oth…
mauricio1802 Aug 21, 2019
ad704d4
[QML] Register ConfigManager and WalletSource
mauricio1802 Aug 21, 2019
5d5d6cf
[config] Make ConfigManager singleton throw GetConfigManager func
mauricio1802 Aug 21, 2019
44fab0e
[config] Set ownership of ConfigManager and WalletSource to Cpp to av…
mauricio1802 Aug 21, 2019
5e0fb53
[core] Add ConfigManager type to core package and change ConfigManage…
mauricio1802 Aug 21, 2019
2ef64f1
[qml][settings] Add PanelItem for Accordion of settings
stdevMac Aug 21, 2019
0084ea1
[qml][settings] refs #111 Remove Accordion.qml
stdevMac Aug 21, 2019
079b86e
[qml][settings] Add WalletSettings qml
stdevMac Aug 22, 2019
c14f964
[qml][settings] Set animation delay and width in PanelItem
stdevMac Aug 22, 2019
fdfb96d
[qml][settings] Add NetworkSettings qml
stdevMac Aug 22, 2019
71f0000
[qml][settings] Set up Settings using PanelItems accordions like
stdevMac Aug 22, 2019
a6b9ae8
[config] Add configManagerJson and walletSourceJson types to core pac…
mauricio1802 Aug 22, 2019
5f2ba5b
[config] remove Debug comments
mauricio1802 Aug 22, 2019
45162f3
Merge branch 'stdevMac_t111_dynamic_configuration' of https://github.…
mauricio1802 Aug 22, 2019
7668f22
[qml][settings] Add wallet env selection to settings
stdevMac Aug 25, 2019
18ac831
[qml][settings] Add id field to {Wallet|Network}Settings
stdevMac Aug 25, 2019
54e7665
[qml][settings] Add property for nodeDirection in NetworkSettings.qml
stdevMac Aug 26, 2019
1246ea4
[qml][settings] Set size propertly on WalletSettings.qml
stdevMac Aug 26, 2019
734a084
[qml][settings] Add delegate for settings
stdevMac Aug 26, 2019
274a88f
[qml][settings] Set up settings view with columnlayout
stdevMac Aug 26, 2019
92e2583
Merge branch 'develop' into stdevMac_t111_dynamic_configuration
stdevMac Aug 26, 2019
5f4be4d
Solve merge issues
stdevMac Aug 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package main

import (
"os"

_ "github.com/fibercrypto/FiberCryptoWallet/src/coin/skycoin"
_ "github.com/fibercrypto/FiberCryptoWallet/src/models"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/qml"

"os"

_ "github.com/fibercrypto/FiberCryptoWallet/src/models"
)

Expand Down
22 changes: 20 additions & 2 deletions src/coin/skycoin/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package skycoin

import (
skycoin "github.com/fibercrypto/FiberCryptoWallet/src/coin/skycoin/models"
"github.com/fibercrypto/FiberCryptoWallet/src/core"

util "github.com/fibercrypto/FiberCryptoWallet/src/util"
)

Expand Down Expand Up @@ -47,8 +49,24 @@ func (p *SkyFiberPlugin) GetDescription() string {
}

func (p *SkyFiberPlugin) LoadWalletEnvs() []core.WalletEnv {
// TODO: Load wallets at $HOME/.skycoin/wallets
return nil

config := core.GetConfigManager()
wltSources := config.GetSources()

wltEnvs := make([]core.WalletEnv, 0)
for _, wltS := range wltSources {
tp := wltS.GetType()
source := wltS.GetSource()
var wltEnv core.WalletEnv
if tp == core.LocalWallet {
wltEnv = &skycoin.WalletDirectory{WalletDir: source}
} else if tp == core.RemoteWallet {
wltEnv = &skycoin.WalletNode{NodeAddress: source}
}
wltEnvs = append(wltEnvs, wltEnv)
}

return wltEnvs
}

func NewSkyFiberPlugin(params SkyFiberParams) core.AltcoinPlugin {
Expand Down
2 changes: 1 addition & 1 deletion src/coin/skycoin/models/account.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package skycoin

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion src/coin/skycoin/models/blockchain.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package skycoin

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion src/coin/skycoin/models/cipher.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package skycoin

import (
"github.com/fibercrypto/FiberCryptoWallet/src/core"
Expand Down
7 changes: 3 additions & 4 deletions src/coin/skycoin/models/wallet.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package skycoin

import (
"encoding/hex"
Expand All @@ -9,7 +9,6 @@ import (
"strings"
"time"

"github.com/fibercrypto/FiberCryptoWallet/src/coin/skycoin"
"github.com/fibercrypto/FiberCryptoWallet/src/core"
"github.com/fibercrypto/FiberCryptoWallet/src/util"
"github.com/skycoin/skycoin/src/api"
Expand All @@ -20,8 +19,8 @@ import (
)

const (
Sky = skycoin.SkycoinTicker
CoinHour = skycoin.CoinHoursTicker
Sky = "SKY"
CoinHour = "SKYCH"
WalletTypeDeterministic = "deterministic"

WalletTypeCollection = "collection"
Expand Down
167 changes: 167 additions & 0 deletions src/core/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package core

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"sync"
)

const (
pathToConfigFromHome = ".fiber/config.json"
pathToDefaultWalletsFromHome = ".skycoin/wallets"
LocalWallet = iota
RemoteWallet
)

var (
confManager *ConfigManager
once sync.Once
)

type ConfigManager struct {
sourceList []*WalletSource
node string
}

type WalletSource struct {
sourceType int
source string
}

func (ws *WalletSource) GetType() int {
return ws.sourceType
}
func (ws *WalletSource) GetSource() string {
return ws.source
}
func (ws *WalletSource) getWalletSourceJson() *walletSourceJson {
return &walletSourceJson{
SourceType: ws.GetType(),
Source: ws.GetSource(),
}
}

func (cm *ConfigManager) GetSources() []*WalletSource {
return cm.sourceList
}

func (cm *ConfigManager) getConfigManagerJson() *configManagerJson {
wltSources := make([]*walletSourceJson, 0)
for _, wltS := range cm.sourceList {
wltSources = append(wltSources, wltS.getWalletSourceJson())
}
return &configManagerJson{
SourceList: wltSources,
Node: cm.node,
}
}

type configManagerJson struct {
SourceList []*walletSourceJson `json:"SourceList"`
Node string `json:"Node"`
}

func (cmJ *configManagerJson) getConfigManager() *ConfigManager {
wltsSource := make([]*WalletSource, 0)
for _, wltS := range cmJ.SourceList {
wltsSource = append(wltsSource, wltS.getWalletSource())
}

return &ConfigManager{
node: cmJ.Node,
sourceList: wltsSource,
}
}

type walletSourceJson struct {
SourceType int `json:"Type"`
Source string `json:"Source"`
}

func (wsJ *walletSourceJson) getWalletSource() *WalletSource {
return &WalletSource{
source: wsJ.Source,
sourceType: wsJ.SourceType,
}
}

func GetConfigManager() *ConfigManager {
once.Do(func() {
var cm *ConfigManager

if configFileExist() {

cm = loadConfigFromFile()
} else {

cm = getDefaultConfigManager()

}
confManager = cm
})

return confManager
}

func configFileExist() bool {
fileDir := getConfigFileDir()
if _, err := os.Stat(fileDir); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}

func loadConfigFromFile() *ConfigManager {
cm := new(configManagerJson)
fileDir := getConfigFileDir()
dat, err := ioutil.ReadFile(fileDir)

if err != nil {

return getDefaultConfigManager()
}
err = json.Unmarshal(dat, cm)
if err != nil {

return getDefaultConfigManager()
}

return cm.getConfigManager()

}

func getDefaultConfigManager() *ConfigManager {

cm := new(ConfigManager)

cm.node = "http://stagin.node.skycoin.net"
cm.sourceList = []*WalletSource{getDefaultWalletSource()}

jsonFormat, _ := json.Marshal(cm.getConfigManagerJson())

os.MkdirAll(filepath.Dir(getConfigFileDir()), 0755)

ioutil.WriteFile(getConfigFileDir(), jsonFormat, 0644)

return cm

}

func getConfigFileDir() string {
homeDir := os.Getenv("HOME")
fileDir := filepath.Join(homeDir, pathToConfigFromHome)
return fileDir
}

func getDefaultWalletSource() *WalletSource {
ws := new(WalletSource)
ws.sourceType = LocalWallet
walletsDir := filepath.Join(os.Getenv("HOME"), pathToDefaultWalletsFromHome)
ws.source = walletsDir
return ws

}
41 changes: 41 additions & 0 deletions src/models/configurationManager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package models

import (
"github.com/fibercrypto/FiberCryptoWallet/src/core"

"github.com/therecipe/qt/qml"

qtcore "github.com/therecipe/qt/core"
)

type WalletSource struct {
qtcore.QObject
_ int `property:"sourceType"`
_ string `property:"source"`
}

type ConfigManager struct {
qtcore.QObject
configManager *core.ConfigManager
_ func() `constructor:"init"`
_ func() []*WalletSource `slot:"getSources"`
}

func (cm *ConfigManager) init() {
qml.QQmlEngine_SetObjectOwnership(cm, qml.QQmlEngine__CppOwnership)
cm.configManager = core.GetConfigManager()
cm.ConnectGetSources(cm.getSources)

}

func (cm *ConfigManager) getSources() []*WalletSource {
wltsSource := make([]*WalletSource, 0)
for _, wltS := range cm.configManager.GetSources() {
newWltSource := NewWalletSource(nil)
qml.QQmlEngine_SetObjectOwnership(newWltSource, qml.QQmlEngine__CppOwnership)
newWltSource.SetSourceType(wltS.GetType())
newWltSource.SetSource(wltS.GetSource())
wltsSource = append(wltsSource, newWltSource)
}
return wltsSource
}
2 changes: 2 additions & 0 deletions src/models/wallets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ func init() {
AddressesModel_QmlRegisterType2("WalletsManager", 1, 0, "AddressModel")
QAddress_QmlRegisterType2("WalletsManager", 1, 0, "QAddress")
WalletManager_QmlRegisterType2("WalletsManager", 1, 0, "WalletManager")
ConfigManager_QmlRegisterType2("Config", 1, 0, "ConfigManager")
WalletSource_QmlRegisterType2("Config", 1, 0, "WalletSource")
}
11 changes: 8 additions & 3 deletions src/models/walletsManager.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package models

import (
"github.com/fibercrypto/FiberCryptoWallet/src/coin/skycoin/models"
skycoin "github.com/fibercrypto/FiberCryptoWallet/src/coin/skycoin/models"
"github.com/fibercrypto/FiberCryptoWallet/src/core"
qtcore "github.com/therecipe/qt/core"
)
Expand Down Expand Up @@ -33,10 +33,15 @@ func (walletM *WalletManager) init() {
walletM.ConnectDecryptWallet(walletM.decryptWallet)
walletM.ConnectGetWallets(walletM.getWallets)
walletM.ConnectGetAddresses(walletM.getAddresses)
altManager := core.LoadAltcoinManager()
walletsEnvs := make([]core.WalletEnv, 0)
for _, plug := range altManager.ListRegisteredPlugins() {
walletsEnvs = append(walletsEnvs, plug.LoadWalletEnvs()...)
}

walletM.WalletEnv = &models.WalletDirectory{WalletDir: "/home/kid/.skycoin/wallets"} //just example
walletM.WalletEnv = walletsEnvs[0]

walletM.SeedGenerator = new(models.SeedService)
walletM.SeedGenerator = new(skycoin.SeedService)

}

Expand Down
10 changes: 10 additions & 0 deletions src/ui/CustomMenuBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ RowLayout {
property alias enablePendingTransactions: menuItemPendingTransactions.enabled
property alias enableBlockchain: menuItemBlockchain.enabled
property alias enableNetworking: menuItemNetworking.enabled
property alias enableSettings: menuItemSettings.enabled

// Signals
signal outputsRequested()
signal pendingTransactionsRequested()
signal networkingRequested()
signal settingsRequested()
signal blockchainRequested()
signal aboutRequested()
signal aboutQtRequested()
Expand Down Expand Up @@ -67,6 +69,7 @@ RowLayout {
enablePendingTransactions = true
enableBlockchain = true
enableNetworking = true
enableSettings = true
}
}

Expand Down Expand Up @@ -122,6 +125,13 @@ RowLayout {

onClicked: networkingRequested()
}
CustomMenuItem {
id: menuItemSettings
text: qsTr("&Settings")
iconSource: "qrc:/images/resources/images/icons/warning.svg"

onClicked: settingsRequested()
}
} // menuTools
Menu {
id: menuHelp
Expand Down
Loading