1#########################################################################
2# COPYRIGHT (C) 2003         EDF R&D              WWW.CODE-ASTER.ORG    #
3#                                                                       #
4# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR         #
5# MODIFY IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS        #
6# PUBLISHED BY THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE    #
7# LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.                       #
8# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,       #
9# BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF        #
10# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU      #
11# GENERAL PUBLIC LICENSE FOR MORE DETAILS.                              #
12#                                                                       #
13# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE     #
14# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO : EDF R&D CODE_ASTER,       #
15#    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.        #
16#########################################################################
17
18# $Id: file_funct.tcl 3469 2008-09-12 07:36:29Z courtois $
19
20# fonctions de manipulations des fichiers
21
22# ouvrir un fichier :
23#  "edit" : édition
24#  "def" : lance l'appli par défaut en fonction du type
25# numfich permet de lancer l'outil sur le "numfich"ième fichier sélectionné
26# si numfich<0, on lance sur tous les fichiers
27#################################################################
28proc ashare::file_open { act {numfich -1}} {
29   set lfich $astk::sel(filename)
30   set maxfich [llength $lfich]
31   if { $maxfich == 0 } {
32      set msg [ashare::mess ihm 25]
33      tk_messageBox -title [ashare::mess ihm 138] -message $msg -type ok -icon info
34      change_status $msg
35      return
36   }
37   if { $numfich == -1 } {
38      set numfich 0
39   } else {
40      set maxfich [expr $numfich + 1]
41   }
42   for {set ind $numfich} {$ind < $maxfich} {incr ind} {
43      set fich [lindex $lfich $ind]
44      set serv $astk::inv(serv,$astk::sel(servname))
45      switch $act {
46         edit {
47         # edition
48            set cmd $astk::config($serv,editeur)
49            if { $cmd != "" } {
50               set cmd2 "$astk::cmd(shell_cmd) \"if test -d $fich ; then $cmd $fich/*; else $cmd $fich ; fi\""
51               ashare::rexec_cmd $serv astk::config $cmd2 "" 1 out
52            } else {
53               set msg [ashare::mess erreur 15 [ashare::mess ihm 83] $astk::sel(servname)]
54               tk_messageBox -message $msg -type ok -icon info
55               change_status $msg
56            }
57         }
58         typ {
59         # action par defaut en fonction du type de fichier
60            # cherche l'outil à lancer par défaut sur ce type
61            set var $astk::sel(liste)
62            set i   $astk::sel(indice)
63            set outil [quel_outil $astk::profil($var,fich,$i,type)]
64            if { $outil != -1 } {
65               run_tool $outil $ind
66            } else {
67               ashare::file_open edit $ind
68            }
69         }
70         ext {
71         # action par defaut en fonction de l'extension fichier
72            # cherche l'outil à lancer par défaut sur ce type
73            set var $astk::sel(liste)
74            set i   $astk::sel(indice)
75            set ext [file extension $fich]
76            regsub "^\." $ext "" ext
77            set outil [quel_outil $ext]
78            if { $outil != -1 } {
79               run_tool $outil $ind
80            } else {
81               ashare::file_open edit $ind
82            }
83         }
84         default {
85         }
86      }
87   }
88}
89
90# action propriétés
91#################################################################
92proc ashare::file_prop { } {
93   set lfich $astk::sel(filename)
94   if { [llength $lfich] == 0 } {
95      set msg [ashare::mess ihm 25]
96      tk_messageBox -title [ashare::mess ihm 138] -message $msg -type ok -icon info
97      change_status $msg
98      return
99   }
100   # multiplie les ls
101   set cmd "$astk::cmd(shell_cmd) \""
102   for {set ind 0} {$ind < [llength $lfich]} {incr ind} {
103      set fich [lindex $lfich $ind]
104      set dir  [file dirname $fich]
105      set base [file tail $fich]
106      append cmd "cd $dir ; /bin/ls -la $base ;"
107   }
108   append cmd "\""
109   set serv $astk::inv(serv,$astk::sel(servname))
110   set cmd [ashare::subst_var $cmd]
111   set iret [ashare::rexec_cmd $serv astk::config $cmd "" 0 retour_ls]
112   set msg [ashare::mess ihm 172]
113   append msg " :"
114   set fen .fen_prop
115   ashare::fen_info $fen [ashare::mess ihm 138] $msg $retour_ls
116}
117
118# fenetre d'informations avec "scrollbar"
119#################################################################
120proc ashare::fen_info { fen titre entete contenu } {
121   toplevel $fen
122   wm title $fen $titre
123# parent n'est pas "." pour la bsf
124#   wm transient $fen .
125   grab set $fen
126   label $fen.lbl -font $astk::ihm(font,lab) -text $entete
127   pack $fen.lbl -anchor w -side top -padx 5 -pady 3
128
129   pack [frame $fen.f -relief flat -bd 0] -anchor w -side top -padx 5 -pady 3 -fill both -expand yes
130   text $fen.f.tx -xscrollcommand "$fen.f.scrollx set" -yscrollcommand "$fen.f.scrolly set" \
131      -width 90 -height 8 -font $astk::ihm(font,txtfix) -bg $astk::ihm(couleur,entry_background) -wrap none
132   scrollbar $fen.f.scrolly -command "$fen.f.tx yview"
133   scrollbar $fen.f.scrollx -command "$fen.f.tx xview" -orient h
134   pack $fen.f.scrolly -side right  -fill y
135   pack $fen.f.scrollx -side bottom -fill x
136   pack $fen.f.tx -expand yes -fill both
137   $fen.f.tx insert end $contenu
138   $fen.f.tx configure -state disabled
139
140   button $fen.ok -font $astk::ihm(font,labbout) -text "Ok" \
141      -background $astk::ihm(couleur,valid) \
142      -command "grab release $fen ; destroy $fen"
143   pack $fen.ok -side top -pady 10
144   tkwait window $fen
145}
146
147# imprimer un fichier avec choix de l'imprimante
148#################################################################
149proc ashare::file_print_to { {parent .} } {
150   global select_printer bid_pr iret_print
151   #
152   set iret_print 0
153   set fen .fen_print
154   catch {destroy $fen}
155   toplevel $fen
156   wm title $fen "[ashare::mess ihm 247]"
157   wm transient $fen $parent
158   wm withdraw $fen
159
160   ##############################
161   pack [frame $fen.f0  -relief flat -bd 0] -fill x -anchor nw
162   pack [frame $fen.f1  -relief flat -bd 0] -fill x
163   pack [frame $fen.f99 -relief flat -bd 0]
164
165   ##############################
166   # liste
167   if { $astk::print(nb) > 0 } {
168      set bid_pr ""
169      catch {set bid_pr $astk::print($select_printer,label)}
170      if { $bid_pr == "" } {
171         set select_printer 0
172         set bid_pr $astk::print($select_printer,label)
173      }
174      set MenuPr [tk_optionMenu $fen.f1.lst bid_pr $astk::print(0,label)]
175      $MenuPr entryconfigure 0 -font $astk::ihm(font,labmenu) -command "set select_printer 0"
176      for {set j 1} {$j < $astk::print(nb)} {incr j} {
177         $MenuPr add radiobutton
178         $MenuPr entryconfigure $j -label $astk::print($j,label) -font $astk::ihm(font,labmenu) -variable bid_pr -command "set select_printer $j"
179      }
180   } else {
181      label $fen.f1.lst -text "No printer"
182   }
183   pack $fen.f1.lst -fill x -padx 15 -pady 10 -expand yes
184
185   ##############################
186   if { $astk::print(nb) > 0 } {
187      button $fen.f99.ok -font $astk::ihm(font,labbout) -text [ashare::mess ihm 251] \
188         -command "ashare::file_pre-print $fen $parent"
189      pack $fen.f99.ok -padx 10 -pady 3 -side left
190   }
191   button $fen.f99.can -font $astk::ihm(font,labbout) -text [ashare::mess ihm 85] \
192      -background $astk::ihm(couleur,annul) \
193      -command "set iret_print 1 ; destroy $fen"
194   pack $fen.f99.can -padx 10 -pady 3
195   ashare::centre_fen $fen $parent
196   wm deiconify $fen
197   tkwait window $fen
198   return $iret_print
199}
200
201#################################################################
202proc ashare::file_pre-print { fen parent } {
203   global select_printer bid_pr
204   set simp $astk::inv(serv,$astk::print($select_printer,serv))
205   set file $astk::print($select_printer,file)
206   regsub -all "@P" $astk::print($select_printer,cmde) $file cmde
207   catch {destroy $fen}
208   ashare::file_print $simp $cmde $parent
209}
210
211# imprimer un fichier
212# simp : numéro du serveur
213# cmde : ligne de commande
214# on utilise /tmp sur le serveur d'impression
215#################################################################
216proc ashare::file_print { simp cmde {parent .}} {
217   set lfich $astk::sel(filename)
218   set maxfich [llength $lfich]
219   if { $maxfich == 0 } {
220      set msg [ashare::mess ihm 25]
221      tk_messageBox -title [ashare::mess ihm 138] -message $msg -type ok -icon info
222      change_status $msg
223      return
224   }
225   if { $cmde == "" } {
226      set msg [ashare::mess erreur 18]
227      tk_messageBox -message $msg -type ok -icon info
228      change_status $msg
229      return 1
230   }
231   for {set ind 0} {$ind < $maxfich} {incr ind} {
232      set fich [lindex $lfich $ind]
233   # fichier sur le serveur d'impression ou non
234      set dist 0
235      set serv $astk::inv(serv,$astk::sel(servname))
236      if { [ashare::meme_machine $astk::config($serv,nom_complet) $astk::config($simp,nom_complet)] != 1
237        || $astk::config($serv,login) != $astk::config($simp,login) } {
238         set dist 1
239      }
240      if { $dist } {
241         set ftmp $astk::sel(servname)
242         append ftmp "_"
243         regsub -all "/" $fich "_" ftmp2
244         append ftmp $ftmp2
245         set ftmp [file join "/tmp" $ftmp]
246         # récupère le fichier vers le serveur d'impression
247         set macrcmd "$astk::cmd(shell_cmd) \""
248         #set cmdcpy "rcp $astk::config($nsrv,login)@$astk::config($nsrv,nom_complet):$fich $ftmp"
249         set cmdcpy [ashare::rcp_cmd astk::config $serv $fich $simp $ftmp "commande"]
250         append macrcmd $cmdcpy
251         append macrcmd ";"
252         # commande d'impression
253         append macrcmd $cmde
254         # efface le temporaire
255         append macrcmd ";/bin/rm -f $ftmp"
256         append macrcmd "\""
257      } else {
258         set macrcmd $cmde
259         set ftmp $fich
260      }
261      # "sélection" du fichier temporaire (pour subst_var)
262      set astk::sel(filename) $ftmp
263   # impression
264      ashare::rexec_cmd $simp astk::config $macrcmd "" 0 out $parent
265   }
266   # retour sélection normale
267   set astk::sel(filename) $lfich
268   return 0
269}
270
271# action Terminal
272#################################################################
273proc ashare::file_terminal { } {
274   set lfich $astk::sel(filename)
275   set maxfich [llength $lfich]
276   if { $maxfich == 0 } {
277      set msg [ashare::mess ihm 175]
278      tk_messageBox -title [ashare::mess ihm 138] -message $msg -type ok -icon info
279      change_status $msg
280      return
281   }
282   set dir  [file dirname $lfich]
283   set serv $astk::inv(serv,$astk::sel(servname))
284   set cmd $astk::config($serv,xterm)
285   if { $cmd != "" } {
286      set cmd2 "$astk::cmd(shell_cmd) \"if test -d $lfich; then { cd $lfich; $cmd; } else { cd $dir; $cmd; } fi\""
287      ashare::rexec_cmd $serv astk::config $cmd2 "" 1 out
288   } else {
289      set msg [ashare::mess erreur 15 [ashare::mess ihm 82] $astk::sel(servname)]
290      tk_messageBox -message $msg -type ok -icon info
291      change_status $msg
292   }
293}
294
295# action Ouvrir une URL
296#################################################################
297proc ashare::file_open_url { url } {
298   set cmd $astk::config(-1,browser)
299   if { $cmd != "" } {
300      append cmd " $url"
301      ashare::rexec_cmd -1 astk::config $cmd "" 1 out
302   } else {
303      set msg [ashare::mess erreur 15 [ashare::mess ihm 363] $astk::local_server]
304      tk_messageBox -message $msg -type ok -icon info
305      change_status $msg
306   }
307}
308