1 -- $Id: dfui.lua,v 1.32 2005/04/03 20:46:01 cpressey Exp $
2 -- Wrapper/helper/extra abstractions for DFUI.
9 -- This is a wrapper object around DFUI.Connection and DFUI.Progress,
10 -- intended to be used as a "UI adapter" for the App object.
15 DFUI
= require
"ldfui"
16 local POSIX
= require
"posix"
18 DFUI
.log = function(fmt
, ...)
19 print(string.format(fmt
, unpack(arg
)))
22 DFUI
.new
= function(tab
)
24 local transport
= tab
.transport
or "tcp"
25 local rendezvous
= tab
.rendezvous
or "9999"
28 dfui
.start
= function(dfui
)
29 connection
= DFUI
.Connection
.new(transport
, rendezvous
)
30 if connection
:start() == 0 then
32 DFUI
.log("Could not establish DFUI connection " ..
33 " on %s:%s", transport
, rendezvous
)
36 DFUI
.log("DFUI connection on %s:%s successfully established",
37 transport
, rendezvous
)
41 dfui
.stop
= function(dfui
)
42 return connection
:stop()
45 dfui
.present
= function(dfui
, tab
)
46 return connection
:present(tab
)
50 -- Handy dialogs. (Perhaps a bit too handy?)
53 dfui
.inform
= function(dfui
, msg
)
54 return connection
:present({
68 dfui
.confirm
= function(dfui
, msg
)
69 return connection
:present({
71 name
= "Are you SURE?",
87 dfui
.select
= function(dfui
, msg
, map
)
89 local consequence
= {}
94 table.insert(action
, {
95 id
= tostring(id_num
),
98 consequence
[tostring(id_num
)] = v
102 return consequence
[connection
:present({
104 name
= "Please Select",
106 role
= "informative",
111 dfui
.select_file
= function(dfui
, tab
)
112 local title
= tab
.title
or "Select File"
113 local short_desc
= tab
.short_desc
or title
114 local long_desc
= tab
.long_desc
or ""
115 local cancel_desc
= tab
.cancel_desc
or "Cancel"
116 local dir
= assert(tab
.dir
)
117 local ext
= tab
.ext
or nil
118 local files
, i
, filename
123 short_desc
= short_desc
,
124 long_desc
= long_desc
,
131 files
= POSIX
.dir(dir
)
133 for i
, filename
in files
do
134 if not ext
or string.find(filename
, "%." .. ext
.. "$") then
135 table.insert(form
.actions
, {
142 table.insert(form
.actions
, {
147 return connection
:present(form
).action_id
151 -- Constructor within a constructor, here...
153 dfui
.new_progress_bar
= function(dfui
, tab
)
156 local title
= tab
.title
or "Working..."
157 local short_desc
= tab
.short_desc
or title
158 local long_desc
= tab
.long_desc
or ""
161 pr
= DFUI
.Progress
.new(connection
,
162 title
, short_desc
, long_desc
, amount
)
164 method
.start
= function(method
)
168 method
.set_amount
= function(method
, new_amount
)
169 return pr
:set_amount(new_amount
)
172 method
.set_short_desc
= function(method
, new_short_desc
)
173 return pr
:set_short_desc(new_short_desc
)
176 method
.update
= function(method
)
180 method
.stop
= function(method
)