Skip to content

Commit

Permalink
selected_profile tab saved in the model
Browse files Browse the repository at this point in the history
  • Loading branch information
hypatia2 committed Aug 18, 2015
1 parent 9264828 commit db7de85
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
3 changes: 2 additions & 1 deletion fruho/add_from_file.tcl
Expand Up @@ -85,7 +85,8 @@ proc ::from_file::ImportClicked {tab} {
go update-bulk-loc $profileid

# when repainting tabset select the newly created tab
tabset-profiles .c.tabsetenvelope [window-sibling $tab [name2id $newprofilename]]
set ::model::selected_profile [name2id $newprofilename]
tabset-profiles .c.tabsetenvelope
}
} on error {e1 e2} {
puts stderr [log $e1 $e2]
Expand Down
3 changes: 2 additions & 1 deletion fruho/add_securitykiss.tcl
Expand Up @@ -120,7 +120,8 @@ proc ::securitykiss::ImportClicked {tab} {
set ::${name}::password ""

# when repainting tabset select the newly created tab
tabset-profiles .c.tabsetenvelope [window-sibling $tab [name2id $newprofilename]]
set ::model::selected_profile [name2id $newprofilename]
tabset-profiles .c.tabsetenvelope
} on error {e1 e2} {
puts stderr [log $e1 $e2]
}
Expand Down
34 changes: 22 additions & 12 deletions fruho/main.tcl
Expand Up @@ -723,8 +723,6 @@ proc vpapi-config-direct {profilename host port urlpath username password} {
try {
set profileid [name2id $profilename]
channel {chout cherr} 1
set query [http::formatQuery os [this-os] arch [this-arch]]
append urlpath ? $query
set f [ovpndir $profileid config.ovpn]
curl-dispatch $chout $cherr $host:$port -urlpath $urlpath -gettofile $f -basicauth [list $username $password]
set httpcode ""
Expand Down Expand Up @@ -1502,12 +1500,12 @@ proc dynafont {args} {
}


proc tabset-profiles {p {selectedtab ""}} {
proc tabset-profiles {p} {
set nb $p.nb
catch {destroy $nb}
ttk::notebook $nb
ttk::notebook::enableTraversal $nb
bind $nb <<NotebookTabChanged>> ProfileTabChanged
bind $nb <<NotebookTabChanged>> [list ProfileTabChanged $nb]
foreach profileid [model active-profiles] {
set tab [frame-profile $nb $profileid]
set pdict [dict get $::model::Profiles $profileid]
Expand All @@ -1516,16 +1514,27 @@ proc tabset-profiles {p {selectedtab ""}} {
}
$nb add [frame-addvpnprovider $nb] -text "Add VPN Provider..."
grid $nb -sticky news -padx 10 -pady 10
if {$selectedtab ne ""} {
$nb select $selectedtab
} else {
#TODO this is temporary: auto select last tab
$nb select [expr {[llength [$nb tabs]] - 2}]
}
select-profile $nb
return $nb
}

proc ProfileTabChanged {} {
proc select-profile {nb} {
set candidate $nb.$::model::selected_profile
foreach tab [$nb tabs] {
if {$tab eq $candidate} {
$nb select $candidate
return
}
}
# otherwise select first tab and save in the model
set first [lindex [$nb tabs] 0]
set ::model::selected_profile [lindex [split $first .] end]
$nb select $first
}

proc ProfileTabChanged {nb} {
set profileid [lindex [split [$nb select] .] end]
set ::model::selected_profile $profileid
if {![is-addprovider-tab-selected]} {
#usage-meter-update [model now]
}
Expand Down Expand Up @@ -1578,6 +1587,7 @@ proc window-sibling {w name} {
return $parent.$name
}


# For example: .c.tabsetenvelope.nb.<profilename>
proc current-tab-frame {} {
return [.c.tabsetenvelope.nb select]
Expand Down Expand Up @@ -2215,7 +2225,7 @@ proc this-pcv {} {
set platform [this-os]-[this-arch]
set version [build-version]
set cn $::model::Cn
return "p=$platform&v=$version&c=$cn"
return [http::formatQuery p $platform v $version c $cn]
}


Expand Down
4 changes: 2 additions & 2 deletions fruho/model.tcl
Expand Up @@ -29,8 +29,8 @@ namespace eval ::model {
# General globals
########################################

# currently selected profile tab
variable current_profile fruho
# currently selected tab as a profileid (may need to be converted to full name of the tab frame)
variable selected_profile fruho

# fruhod --- fruho client connection socket
variable Ffconn_sock ""
Expand Down

0 comments on commit db7de85

Please sign in to comment.