File: splits.tcl

package info (click to toggle)
tkirc 1.202-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 500 kB
  • ctags: 40
  • sloc: tcl: 9,813; makefile: 64; sh: 3
file content (268 lines) | stat: -rw-r--r-- 8,811 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268

# Description:  Newer IRC servers support a moderated channel (&SERVERS)
#               for server notices. Sometimes (especially on larger
#               irc-networks) you can see there splitting and rejoining
#               servers.
#
#               This file includes procedures which observe the traffic
#               on channel `&SERVERS' to show you the servers actually
#               splitted from that server you are connected to.
#
# Date:         10.03.98
# Author:       Andreas Gelhausen, atte@gecko.north.de
#
# Changes:      10.03.98  Small bug fixed. (Error: can't read
#                         "on_args(to)": no such element in array)
#               03.03.98  Now this script can automatically be loaded
#                         from tkirc (~.tkirc/autoload/) and you
#                         don't need to change your tkircrc!
#               06.02.98  Channel `&servers' can be observed without an
#                         additional window for its traffic. =:^)
#
# Install:
#               1. copy this file to `~/.tkirc/autoload/splits.tcl'
#               2. reload your tkircrc or restart tkirc
#
# Usage:
#               1. select entry `observ &servers' within menu `Private'
#                  and wait what's happening


# geometry_splitted: This variable allows you to set the geometry of 
#          your split-window.
global geometry_splitted
#set geometry_splitted "499x121+552+612"

proc on_leave_splits { } {
  global on_args nickname splitted
  if {[strcmp "$on_args(channel)" "&SERVERS"] == 0} {
    if {[strcmp "$nickname" "$on_args(nick)"] == 0} {
      if {[info exists splitted(window)]} {
        CloseMainWindow $splitted(window) ; unset splitted(window)
      }
    }
  }
}

proc on_menucreate_splits { } {
  global on_args
  $on_args(path).private.menu add command -label "observe &servers" \
      -command "ServerSplits window"
}

proc on_servernotice_splits { } {
  global on_args

  if {![strcmp "$on_args(to)" "&SERVERS"] && ![strcmp "" "$on_args(nick)"]} {
    if {[strmatch "Received SERVER *" "$on_args(rest)"]} {
      ServerSplits update RECEIVED_SERVER
    } elseif {[strmatch "Received SQUIT *" "$on_args(rest)"]} {
      ServerSplits update RECEIVED_SQUIT
    } elseif {[strmatch "Sending SERVER *" "$on_args(rest)"]} {
      ServerSplits update SENDING_SERVER
    } elseif {[strmatch "Sending SQUIT *" "$on_args(rest)"]} {
      ServerSplits update SENDING_SQUIT
    }
  }
}

proc on_364_splits { } {
  global on_args splitted

  set server "[lIndex "$on_args(line)" 3]"
  set len "[llength "$splitted(servers)"]"
  for {set k 0} {$k < $len} {incr k} {
    if {[strmatch "[lindex "$splitted(servers)" $k]" "$server"] \
     || [strmatch "$server" "[lindex "$splitted(servers)" $k]"]} {
      foreach x "dates servers messages" {
	set splitted($x) "[lreplace "$splitted($x)" $k $k]"
      }
      if {[winfo exists $path] && !$splitted(frozen)} {
	$path.list.entries delete $k
      }
    }
  }
}

global splitted
if ![info exists splitted] {
  foreach x "dates servers messages" {
    set splitted($x) ""
  }
}

proc ServerSplits {command args} {
  global on_args splitted chan win crapwindow margin

  if [info exists splitted(window)] {
    set path "[GetPathFromNum $splitted(window)]"
  }

  switch -- "[string tolower "$command"]" {
    "update" {
      set server [lIndex "$on_args(rest)" 2]
      global filternext ; set filternext 1
      if {[strmatch "*_SQUIT" "$args"]} {
	if {[strcmp "RECEIVED_SQUIT" "$args"] == 0} {
	  set cut 5
	} else {
	  # SENDING_SQUIT
	  set cut 3
        }
	set k [lsearch "$splitted(servers)" "[expand "$server"]"]
	if {$k != -1} {
	  set splitted(dates) "[lreplace "$splitted(dates)" $k $k]"
	  set splitted(servers) "[lreplace "$splitted(servers)" $k $k]"
	  set splitted(messages) "[lreplace "$splitted(messages)" $k $k]"
	  if {[winfo exists $path] && !$splitted(frozen)} {
	    $path.list.entries delete $k
	  }
	}
	lappend splitted(dates) "[longdate]"
	lappend splitted(servers) "$server"
	lappend splitted(messages) "[cutwords "$on_args(rest)" $cut]"
	if {[winfo exists $path] && !$splitted(frozen)} {
	  set end "[lindex "[$path.list.entries yview]" 1]"
	  $path.list.entries insert end "[longdate]  $server  [cutwords "$on_args(rest)" $cut]"
	  if {$end == 1} {
	    $path.list.entries yview end
	  }
	}
      } elseif {[strmatch "*_SERVER" "$args"]} {
	# RECEIVED_SERVER & SENDING_SERVER
	set len "[llength "$splitted(servers)"]"
	for {set k 0} {$k < $len} {incr k} {
	  if {[strmatch "[lindex "$splitted(servers)" $k]" "$server"] \
	   || [strmatch "$server" "[lindex "$splitted(servers)" $k]"]} {
	    foreach x "dates servers messages" {
	      set splitted($x) "[lreplace "$splitted($x)" $k $k]"
	    }
	    if {[winfo exists $path] && !$splitted(frozen)} {
	      $path.list.entries delete $k
	    }
	  }
	}
      }
    }

    "delete" {
      set i 0
      foreach k "[$path.list.entries curselection]" {
	set k [expr $k-$i]
	foreach x "dates servers messages" {
	  set splitted($x) "[lreplace "$splitted($x)" $k $k]"
	}
	$path.list.entries delete $k
	incr i
      }
    }

    "confirm" {
      if {[llength "[$path.list.entries curselection]"] > 1} {
        print2crap "+++ Confirming splits through `/links <server>' ..."
      } else {
        print2crap "+++ Executing `/links $tmp' ..."
      }
      foreach k "[$path.list.entries curselection]" {
        set tmp "[lIndex "[$path.list.entries get $k]" 2]"
        send2irc "/links $tmp"
      }
    }

    "clear" {
      foreach x "dates servers messages" {
	set splitted($x) ""
      }
      $path.list.entries delete 0 end
    }

    "save" {
      if {[string length "$args"] == 0} {
        FileRequester " Please select the file to save the \nsplitted servers in!" "Save" "ServerSplits save \:file" "" ""
        return
      }
      set file "[OpenFile "$args" a]"
      if {[string length "$file"]} {
        set ulen [llength "$splitted(servers)"]
        for {set i 0} {$i < $ulen} {incr i} {
          puts $file "[$path.list.entries get $i]"
        }
        close $file
        set margin(text) "note"
        print2crap " All splitted servers saved to file `$args'"
      }
    }

    "freeze" {
      if {$splitted(frozen)} {
	$path.buttons.delete configure -state disabled
      } else {
	$path.buttons.delete configure -state normal
	set end "[lindex "[$path.list.entries yview]" 1]"
	    
	$path.list.entries delete 0 end
	set slen [llength "$splitted(servers)"]
	for {set i 0} {$i < $slen} {incr i} {
	  $path.list.entries insert end "[lindex "$splitted(dates)" $i]  [lindex "$splitted(servers)" $i]  [lindex "$splitted(messages)" $i]"
	}
	if {$end == 1} {
	  $path.list.entries yview end
	}
      }
    }

    "window" {
      if {![info exists splitted(window)]} {
	set splitted(window) [MainWindow -5]
	lappend chan(tojoin) "&servers"
	lappend win(tojoin) "$splitted(window)"
	send2irc "/join &servers"
      }

      set path "[GetPathFromNum $splitted(window)]"
      if [catch {toplevel $path -class tkirc-request}] {
	raise $path
      } else {
	global geometry_splitted
	if {[info exists geometry_splitted]} {
	  wm geometry $path $geometry_splitted
	}
	set theend "CloseMainWindow $splitted(window) ; unset splitted(window)"
	wm title $path " tkirc: splitted servers (&servers) "
	wm protocol $path WM_DELETE_WINDOW "$theend"
	bind $path <Escape> "$theend"
	    
	set frame $path.buttons
	frame $frame
	pack $frame -fill x -pady 2 -side bottom
	button $frame.confirm -text "Confirm" -command "ServerSplits confirm"
	button $frame.delete -text "Delete" -command "ServerSplits delete"
	button $frame.clear -text "Clear list" -command "ServerSplits clear"
	button $frame.save -text "Save list" -command "ServerSplits save"
	button $frame.close -text "Close" -command "$theend"
	pack $frame.confirm $frame.delete -side left
	pack $frame.close $frame.save $frame.clear -side right
	checkbutton $frame.freeze -text "frozen" -variable splitted(frozen) \
	  -command "ServerSplits freeze"
	pack $frame.freeze -anchor c
	    
	frame $path.list -bd 0
	pack $path.list -expand true -fill both -pady 0 -ipady 0
	listbox $path.list.entries -width 12 -selectmode extended \
	  -relief raised -exportselection false \
	  -yscrollcommand "$path.list.scroll set"
	scrollbar $path.list.scroll -width 10 -orient vertical \
	  -command [list $path.list.entries yview]
	pack $path.list.entries -expand true -side left -fill both
	pack $path.list.scroll -side left -fill y
	bind $path.list.entries <Double-Button-1> "ServerSplits confirm"
	    
	$path.list.entries delete 0 end
	set slen [llength "$splitted(servers)"]
	for {set i 0} {$i < $slen} {incr i} {
	  $path.list.entries insert end "[lindex "$splitted(dates)" $i]  [lindex "$splitted(servers)" $i]  [lindex "$splitted(messages)" $i]"
	}
      }
    }
  }
}