commands2.el 94.3 KB
Newer Older
David Byers's avatar
David Byers committed
1
;;;;; -*-coding: iso-8859-1;-*-
Linus Tolke's avatar
Linus Tolke committed
2
3
;;;;;
;;;;; $Id$
4
;;;;; Copyright (C) 1991, 1996  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke committed
5
6
7
8
9
;;;;;
;;;;; This file is part of the LysKOM server.
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
10
;;;;; the Free Software Foundation; either version 2, or (at your option) 
Linus Tolke's avatar
Linus Tolke committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
;;;;; any later version.
;;;;; 
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;;;;; for more details.
;;;;; 
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING.  If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se. 
;;;;;
Per Cederqvist's avatar
.  
Per Cederqvist committed
26
27
28
29
30
31
32
33
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: commands2.el
;;;;
;;;; This file contains the code for some high level commands.
;;;;

34
35
36
37
(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))

38
39
40
(eval-when-compile
  (require 'lyskom-command "command"))

41

Per Cederqvist's avatar
.  
Per Cederqvist committed
42
43
44
45
46
47
48
;;; ================================================================
;;;              Lista medlemsskap - List membership

;;; Author: Linus Tolke
;;; Rewritten by ceder


49
;; This functions is left in its "asynchronous way".
David Kågedal's avatar
David Kågedal committed
50
(def-kom-command kom-membership ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
51
52
  "Show memberships last visited, priority, unread and name."
  (interactive)
David Byers's avatar
David Byers committed
53
  (let ((buffer (lyskom-get-buffer-create 'list-membership
David Byers's avatar
X    
David Byers committed
54
55
56
57
                                          (concat (buffer-name 
                                                   (current-buffer))
                                                  "-membership")
                                          t)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
58
59
    (save-window-excursion
      (set-buffer buffer)
David Byers's avatar
X    
David Byers committed
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
      (lyskom-view-mode)
      (lyskom-add-hook 'lyskom-new-membership-list-hook
                       'lyskom-update-membership-when-changed t)
      (setq truncate-lines t)
      (let ((inhibit-read-only t))
        (erase-buffer)
        (insert (lyskom-get-string 'your-memberships))
        (insert (lyskom-get-string 'memberships-header))))
    (save-selected-window
      (lyskom-display-buffer buffer))
    (lyskom-update-membership-buffer)))

(defun lyskom-update-membership-buffer ()
  (let ((buf (car (lyskom-buffers-of-category 'list-membership))))
    (when (buffer-live-p buf)
      (let ((inhibit-read-only t))
        (save-excursion (set-buffer buf)
                        (erase-buffer))
        (lyskom-traverse x lyskom-membership
          (initiate-get-conf-stat 'memberhsip 'lyskom-memb-received-1
                                  (membership->conf-no x)
                                  x buf))))))

(defun lyskom-update-membership-when-changed ()
  (let ((buffer (car (lyskom-buffers-of-category 'list-membership))))
    (if (buffer-live-p buffer)
        (save-excursion (set-buffer buffer)
                        (lyskom-update-membership-buffer))
      (lyskom-remove-hook 
       'lyskom-new-membership-list-hook
       'lyskom-update-membership-when-changed))))


93

Per Cederqvist's avatar
.  
Per Cederqvist committed
94
95
96
97
98
99
100
101
102
(defun lyskom-memb-received-1 (conf-stat membership buffer)
  "Part of kom-membership.
Get maps for the conference CONF-STAT. MEMBERSHIP is the users
membership in that conference. Call lyskom-memb-received with
the resulting MAP, CONF-STAT, MEMBERSHIP and BUFFER.
Args: CONF-STAT MEMBERSHIP BUFFER."
  (if (/= (conf-stat->conf-no conf-stat)
	  (membership->conf-no membership))
      (signal 'lyskom-internal-error '("lyskom-memb-received-1")))
103
104
105
106
  (let* ((first-wanted (1+ (membership->last-text-read membership)))
	 (last-existing  (+ (conf-stat->first-local-no conf-stat)
			    (conf-stat->no-of-texts conf-stat)
			    -1)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
107
108
109
    (if (> first-wanted last-existing)
	(lyskom-run 'membership 'lyskom-memb-received
		    nil conf-stat membership buffer)
110
111
112
113
114
115
116
117
118
119
      (if (> (- last-existing first-wanted) 50)
	  (lyskom-run 'membership 'lyskom-memb-received
		      (- last-existing first-wanted)
		      conf-stat membership buffer)
	(initiate-get-map 'membership 'lyskom-memb-received
			  (membership->conf-no membership)
			  first-wanted
			  (+ 1 last-existing
			     (- first-wanted))
			  conf-stat membership buffer)))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
120
121
122
123
124
125
126
127

(defun lyskom-memb-received (map conf-stat membership buffer)
  "Args: MAP CONF-STAT MEMBERSHIP BUFFER.
Prints membership in a conferences.
MAP may be nil if there are no new texts."
  (save-window-excursion
    (set-buffer buffer)
    (goto-char (point-max))
David Byers's avatar
X    
David Byers committed
128
129
    (let ((lyskom-executing-command 'kom-membership)
          (lyskom-current-command 'kom-membership)
130
131
          (inhibit-read-only t)
          (kom-print-seconds-in-time-strings nil))
David Byers's avatar
X    
David Byers committed
132
      (lyskom-format-insert 'memberships-line
133
134
135
                            (lyskom-format-time 'date-and-time
                                                (membership->last-time-read
                                                 membership))
David Byers's avatar
X    
David Byers committed
136
137
138
139
140
141
142
143
144
145
                            (membership->priority membership)
                            (cond
                             ((null map) 0)
                             ((numberp map) map)
                             ((listp map)
                              (length (lyskom-list-unread map membership)))
                             (t (signal
                                 'lyskom-internal-error
                                 '("Erroneous map in lyskom-memb-received"))))
                            conf-stat))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
146
147
148
149
150
151
152
153
154


;;; ================================================================
;;;          Status (f|r) M|te - Status for a conference

;;; Author: ceder (with some help by Linus)
;;; much enhanced by Inge Wallin (lyskom-status-conf-2 and beyond)


David Kågedal's avatar
David Kågedal committed
155
(def-kom-command kom-status-conf (&optional conf-no)
Per Cederqvist's avatar
.  
Per Cederqvist committed
156
157
158
159
  "Prints conference status.
If argument CONF-NO is existing and non-nil then this conference is used. 
otherwise: the conference is read with lyskom-completing-read."
  (interactive)
David Kågedal's avatar
David Kågedal committed
160
161
162
  (let ((conf-no
	 (or conf-no
	     (lyskom-read-conf-no (lyskom-get-string 'conf-for-status)
163
164
				  '(all) nil nil t)))
        (kom-print-seconds-in-time-strings nil))
David Kågedal's avatar
David Kågedal committed
165
    (cache-del-conf-stat conf-no)
David Byers's avatar
David Byers committed
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
    (cache-del-uconf-stat conf-no)
    (blocking-do-multiple ((conf-stat (get-conf-stat conf-no))
                           (uconf-stat (get-uconf-stat conf-no)))
      (if (null conf-stat)
          (lyskom-insert-string 'no-such-conf)
        (let* ((type (uconf-stat->conf-type uconf-stat))
               (box (conf-type->letterbox type))
               (ori (conf-type->original type))
               (pro (conf-type->rd_prot type))
               (sec (conf-type->secret type)))
          (lyskom-format-insert 'status-record
                                conf-stat
                                conf-stat
                                (cond
                                 ((or box ori pro sec)
                                  (concat
                                   "("
                                   (if box (lyskom-get-string 'Mailbox) "")
                                   (if (and box (or sec ori pro)) ", " "")
                                   (if sec (lyskom-get-string
                                            'Protected) "")
                                   (if (and sec (or ori pro)) ", " "")
                                   (if ori (lyskom-get-string
                                            'no-comments) "")
                                   (if (and ori pro) ", " "")
                                   (if pro (lyskom-get-string 'closed) "")
                                   ")"))
                                 (t ""))))
        (let ((creator (conf-stat->creator conf-stat)))
          (lyskom-format-insert 'created-by
                                creator
                                creator
                                (if (and 
                                     (lyskom-conf-stat-p creator)
David Byers's avatar
David Byers committed
200
                                     (> (lyskom-string-width (conf-stat->name creator))
David Byers's avatar
David Byers committed
201
202
203
204
                                        (- (lyskom-window-width) 46)))
                                    "\n"
                                  "")))
        (lyskom-format-insert 'created-at
205
206
                              (lyskom-format-time
                               'date-and-time
David Byers's avatar
David Byers committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
                               (conf-stat->creation-time conf-stat)))
        (lyskom-format-insert 'members
                              (conf-stat->no-of-members conf-stat))
        (lyskom-format-insert 'conf-allows-secret-members
                              (lyskom-get-string 
                               (if (conf-type->forbid-secret 
                                    (uconf-stat->conf-type uconf-stat))
                                   'secret-members-not-permitted
                                 'secret-members-permitted)))
        (lyskom-format-insert 'conf-allows-anon-texts
                              (lyskom-get-string 
                               (if (conf-type->anarchy
                                    (uconf-stat->conf-type uconf-stat))
                                   'anon-texts-permitted
                                 'anon-texts-not-permitted))) 
        (lyskom-format-insert 'garb-nice
                              (conf-stat->garb-nice conf-stat))
        (lyskom-format-insert 'lowest-local-no
                              (conf-stat->first-local-no conf-stat))
        (lyskom-format-insert 'highest-local-no
                              (1- (+ (conf-stat->no-of-texts conf-stat)
                                     (conf-stat->first-local-no conf-stat))))
        (lyskom-format-insert 'last-text-time
230
231
                              (lyskom-format-time
                               'date-and-time
David Byers's avatar
David Byers committed
232
233
234
235
236
237
238
239
240
                               (conf-stat->last-written conf-stat)))
        (lyskom-format-insert 'no-of-motd
                              (conf-stat->msg-of-day conf-stat))
        (let ((superconf (conf-stat->super-conf conf-stat)))
          (lyskom-format-insert 'superconf-is-no-name
                                superconf
                                superconf
                                (if (and 
                                     (lyskom-conf-stat-p superconf)
David Byers's avatar
David Byers committed
241
                                     (> (lyskom-string-width (conf-stat->name superconf))
David Byers's avatar
David Byers committed
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
                                        (- (lyskom-window-width) 46)))
                                    "\n"
                                  "")))
        (let ((permitted-submitters (conf-stat->permitted-submitters conf-stat)))
          (lyskom-format-insert 'permitted-submitters-no-name
                                permitted-submitters
                                (if (zerop permitted-submitters)
                                    (lyskom-get-string 'Everybody)
                                  permitted-submitters)
                                ""))
        (let ((supervisor (conf-stat->supervisor conf-stat)))
          (lyskom-format-insert 'supervisor-is-no-name
                                supervisor
                                supervisor
                                ""))
        (lyskom-format-insert 'presentation-no
                              (conf-stat->presentation conf-stat))

        (if (zerop (conf-stat->msg-of-day conf-stat))
            nil
          (lyskom-format-insert 'conf-has-motd conf-stat)
          (lyskom-view-text (conf-stat->msg-of-day conf-stat)))

David Byers's avatar
David Byers committed
265
266
267
268
        ;; Show aux items

        (lyskom-traverse-aux item
            (conf-stat->aux-items conf-stat)
269
          (lyskom-aux-item-call item 'status-print item conf-stat))
David Byers's avatar
David Byers committed
270

271
272
273
274
275
276
277
        (let ((mship (lyskom-try-get-membership (conf-stat->conf-no conf-stat) t)))
          (when mship
            (lyskom-format-insert 'conf-mship-priority
                                  (membership->priority mship)
                                  (lyskom-return-membership-type
                                   (membership->type mship)))))

David Byers's avatar
David Byers committed
278
279
280
281
282
283
284
        ;; Show all members of CONF-STAT if the user so wishes."
        (lyskom-scroll)
        (if (lyskom-j-or-n-p
             (lyskom-get-string 'show-members-list-also-q))
            (let ((member-list (blocking-do 'get-members
                                            (conf-stat->conf-no conf-stat)
                                            0 lyskom-max-int)))
David Kågedal's avatar
David Kågedal committed
285
	    
David Byers's avatar
David Byers committed
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
              (if (null member-list)
                  (lyskom-format-insert 'conf-has-no-members conf-stat)
                (lyskom-format-insert 'conf-has-these-members conf-stat)
                (if (lyskom-j-or-n-p (lyskom-get-string 'show-membership-info-q))
                    (progn
                      (lyskom-insert-string 'member-list-header)
                      (lyskom-traverse 
                       member (member-list->members member-list)
                       (let ((membership (blocking-do
                                          'query-read-texts 
                                          (member->pers-no member)
                                          (conf-stat->conf-no conf-stat))))
                         ;; Print a row describing the membership of MEMBER
                         ;; (described by MEMBERSHIP) in CONF-STAT.
                         (if (or (null membership))
                             (lyskom-insert-string 'secret-membership)
                           (lyskom-insert 
                            (format "%17s"
304
305
                                    (lyskom-format-time
                                     'date-and-time
David Byers's avatar
David Byers committed
306
307
308
309
310
311
312
313
314
315
                                     (membership->last-time-read membership))))
                           (let ((unread (- (+ (conf-stat->first-local-no
                                                conf-stat)
                                               (conf-stat->no-of-texts conf-stat))
                                            (membership->last-text-read membership)
                                            (length (membership->read-texts
                                                     membership))
                                            1)))
                             (lyskom-format-insert 'conf-membership-line
                                                   (if (zerop unread)
316
317
                                                       "           "
                                                     (format "%9d  " unread))
David Byers's avatar
David Byers committed
318
319
320
321
322
323
324
325
                                                   (member->pers-no member)
                                                   (lyskom-return-membership-type (member->membership-type member))
                                                   )
                             (when (and (member->created-by member)
                                        (not (zerop (member->created-by member)))
                                        (not (eq (member->pers-no member)
                                                 (member->created-by member))))
                               (lyskom-format-insert 'conf-membership-line-2
326
327
                                                     (lyskom-format-time
                                                      'date-and-time
David Byers's avatar
David Byers committed
328
329
330
                                                      (member->created-at member))
                                                     (member->created-by member)))
                             )))))
David Kågedal's avatar
David Kågedal committed
331
	      
David Byers's avatar
David Byers committed
332
333
334
335
336
337
                  ;; Don't show membership info
                  (lyskom-insert "\n")
                  (lyskom-traverse
                   member (member-list->members member-list)
                   (lyskom-format-insert "  %#1P\n" 
                                         (member->pers-no member)))))))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
338
339
340
341
342
343
344
345
346


;;; ================================================================
;;;            Status (f|r) Person - status for a person

;;; Author: ceder
;;; Heavily enhanced: Inge Wallin (lyskom-status-pers-3 and beyond)


David Kågedal's avatar
David Kågedal committed
347
(def-kom-command kom-status-person (&optional pers-no)
Per Cederqvist's avatar
.  
Per Cederqvist committed
348
349
  "Prints status for a person."
  (interactive)
David Kågedal's avatar
David Kågedal committed
350
  (let ((pers-no
351
352
         (or pers-no
             (lyskom-read-conf-no (lyskom-get-string 'pers-for-status)
353
                                  '(pers) nil "" t)))
354
        (kom-print-seconds-in-time-strings nil)
David Kågedal's avatar
David Kågedal committed
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
	conf-stat
	pers-stat)
    (cache-del-conf-stat pers-no)
    (cache-del-pers-stat pers-no)
    (setq pers-stat (blocking-do 'get-pers-stat pers-no))
    (setq conf-stat (blocking-do 'get-conf-stat pers-no))

    ;; "Print status about PERS-STAT. The name is in CONF-STAT"
    (if (or (null pers-stat)
	    (null conf-stat))
	(lyskom-insert-string 'no-such-pers)
      (lyskom-format-insert 'pers-status-record
			    conf-stat
			    conf-stat)
      (lyskom-format-insert 'created-time
370
371
			    (lyskom-format-time
                             'date-and-time
David Kågedal's avatar
David Kågedal committed
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
			     (conf-stat->creation-time conf-stat)))

      (lyskom-format-insert 'created-confs
			    (pers-stat->created-confs pers-stat))
      (lyskom-format-insert 'created-persons
			    (pers-stat->created-persons pers-stat))
      (lyskom-format-insert 'created-texts
			    (1- (+ (pers-stat->no-of-created-texts pers-stat)
				   (pers-stat->first-created-text pers-stat))))
      (lyskom-format-insert 'created-lines
			    (pers-stat->created-lines pers-stat))
      (lyskom-format-insert 'created-chars
			    (pers-stat->created-bytes pers-stat))

      (lyskom-format-insert 'no-of-sessions
			    (pers-stat->sessions pers-stat))
388
389
390
391
392
393
394
      (let ((time (pers-stat->total-time-present pers-stat)))
	(unless (zerop time) ;; Why not let it print "0 d 00:00:00"?
	  (lyskom-format-insert 'present-time-d-h-m-s
				(floor time (* 24 3600))
				(mod (floor time 3600) 24)
				(mod (floor time 60) 60)
				(round (mod time 60)))))
David Kågedal's avatar
David Kågedal committed
395
      (lyskom-format-insert 'last-log-in
396
397
			    (lyskom-format-time
                             'date-and-time
David Kågedal's avatar
David Kågedal committed
398
399
400
401
402
			     (pers-stat->last-login pers-stat)))
      (lyskom-format-insert 'user-name
			    (pers-stat->username pers-stat))
      (lyskom-format-insert 'read-texts
			    (pers-stat->read-texts pers-stat))
403
404
      (if (= (pers-stat->pers-no pers-stat) lyskom-pers-no)
          (lyskom-format-insert 'marked-texts
David Kågedal's avatar
David Kågedal committed
405
				(pers-stat->no-of-marks pers-stat)))
David Kågedal's avatar
David Kågedal committed
406
      (lyskom-format-insert 'time-for-last-letter
407
408
			    (lyskom-format-time
                             'date-and-time
David Kågedal's avatar
David Kågedal committed
409
410
			     (conf-stat->last-written conf-stat)))

David Kågedal's avatar
David Kågedal committed
411
      (let ((superconf (conf-stat->super-conf conf-stat)))
David Kågedal's avatar
David Kågedal committed
412
413
414
	(lyskom-format-insert 'superconf
			      superconf
			      superconf
David Kågedal's avatar
David Kågedal committed
415
			      ""))
David Kågedal's avatar
David Kågedal committed
416
      (if (not (zerop (conf-stat->supervisor conf-stat)))
David Kågedal's avatar
David Kågedal committed
417
	  (let ((supervisor (conf-stat->supervisor conf-stat)))
David Kågedal's avatar
David Kågedal committed
418
419
420
	    (lyskom-format-insert 'supervisor
				  supervisor
				  supervisor
David Kågedal's avatar
David Kågedal committed
421
				  "")))
David Kågedal's avatar
David Kågedal committed
422
423
424
425
426
427
428
429
430
431
      (lyskom-format-insert 'member-of-confs
			    (pers-stat->no-of-confs pers-stat))
      (lyskom-format-insert 'presentation
			    (conf-stat->presentation conf-stat))

      (if (not (zerop (conf-stat->msg-of-day conf-stat)))
	  (progn
	    (lyskom-format-insert 'has-motd conf-stat)
	    (lyskom-view-text (conf-stat->msg-of-day conf-stat))))

David Byers's avatar
David Byers committed
432
433
434
435
      ;; Show aux items
      
      (lyskom-traverse-aux item
          (conf-stat->aux-items conf-stat)
436
        (lyskom-aux-item-call item 'status-print item conf-stat))
David Byers's avatar
David Byers committed
437

David Kågedal's avatar
David Kågedal committed
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
      ;; "Show all conferences CONF-STAT is a member of if the user so wishes."
      (lyskom-scroll)
      (if (null (lyskom-j-or-n-p (lyskom-get-string
				  'show-membership-list-also-q))) 
	  nil
	(let ((membership-list 
	       (blocking-do 'get-membership
			    (conf-stat->conf-no conf-stat)))
	      (lyskom-count-var 0))

	  (if (null membership-list)
	      (lyskom-format-insert 'not-allowed-see-confs conf-stat)
	    (lyskom-format-insert 'is-member-of conf-stat)
	    (lyskom-insert-string 'membership-list-header)
	    (setq lyskom-count-var 0)
	    (lyskom-traverse
David Kågedal's avatar
David Kågedal committed
454
455
456
457
458
459
460
461
	     membership membership-list
	     (let ((cs (cache-get-conf-stat
			(membership->conf-no membership))))
	       (and cs
		    (lyskom-time-greater
		     (membership->last-time-read membership)
		     (conf-stat->last-written conf-stat))
		    (cache-del-conf-stat (membership->conf-no membership))))
462
		  
David Kågedal's avatar
David Kågedal committed
463
464
465
466
467
468
469
470
471
472
	     ;; "Print a row describing the membership of
	     ;; MEMBER-CONF-STAT
	     (let ((member-conf-stat
		    (blocking-do 'get-conf-stat 
				 (membership->conf-no membership))))
	       (if (or (null member-conf-stat)
		       (null membership))
		   (lyskom-insert-string 'secret-membership)
		 (lyskom-insert 
		  (format "%17s"
473
474
			  (lyskom-format-time
                           'date-and-time
David Kågedal's avatar
David Kågedal committed
475
476
477
478
479
480
481
482
483
484
485
			   (membership->last-time-read membership))))
		 (let ((unread (- (+ (conf-stat->first-local-no
				      member-conf-stat)
				     (conf-stat->no-of-texts
				      member-conf-stat))
				  (membership->last-text-read membership)
				  (length (membership->read-texts
					   membership))
				  1)))
		   (lyskom-format-insert
		    'pers-membership-line
486
		    (if (zerop unread) "          " (format "%9d " unread))
David Kågedal's avatar
David Kågedal committed
487
488
489
490
		    (if (= (conf-stat->conf-no conf-stat)
			   (conf-stat->supervisor member-conf-stat))
			(lyskom-get-string 'is-supervisor-mark)
		      "  ")
491
492
493
494
495
496
497
498
		    member-conf-stat
                    (lyskom-return-membership-type (membership->type membership))
                    )
                   (when (and (membership->created-by membership)
                              (not (zerop (membership->created-by membership)))
                              (not (eq (conf-stat->conf-no conf-stat)
                                       (membership->created-by membership))))
                     (lyskom-format-insert 'pers-membership-line-2
499
500
                                           (lyskom-format-time
                                            'date-and-time
501
502
503
                                            (membership->created-at membership))
                                           (membership->created-by membership)))

David Kågedal's avatar
David Kågedal committed
504
		   (setq lyskom-count-var (+ lyskom-count-var unread)))))))
David Kågedal's avatar
David Kågedal committed
505
506
507
508
509

	  ;; "Print the total number of unread texts for the person CONF-STAT."
	  (lyskom-format-insert 'his-total-unread 
				conf-stat
				lyskom-count-var))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
510
511
512
513
514
515
516



;;; ================================================================
;;;              Skicka meddelande - Send message

;;; Author: Inge Wallin
517
;;; Rewritten to use lyskom-read-conf-no by Linus Tolke
518
;;; Modified to use default recipient by David Byers
Per Cederqvist's avatar
.  
Per Cederqvist committed
519
520


521
(def-kom-command kom-send-message (&optional who message)
522
  "Send a message to one of the users in KOM right now."
Per Cederqvist's avatar
.  
Per Cederqvist committed
523
  (interactive)
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
  (let* ((tmp nil)
         (target (or who
                     (lyskom-read-conf-no
                      (format (lyskom-get-string 'who-to-send-message-to)
                              (lyskom-get-string 'nobody))
                      (if kom-permissive-completion
                          '(all)
                        '(login conf))
                      ;; Initial string:
                      t
                      (cond
                       ((eq kom-default-message-recipient 'everybody) nil)

                       ((and (eq kom-default-message-recipient 'group)
                             lyskom-last-group-message-recipient)
                        (cons lyskom-last-group-message-recipient 0))

                       ((or (and (eq kom-default-message-recipient 'group)
                                 (null lyskom-last-group-message-recipient))
                            (and (eq kom-default-message-recipient 'sender)
                                 lyskom-last-personal-message-sender))
                        (cons lyskom-last-personal-message-sender 0))

                       ((and (eq kom-default-message-recipient 'last-recipient)
                             lyskom-last-message-recipient
                             (not (eq 0 lyskom-last-message-recipient))
                             (setq tmp (blocking-do 'get-uconf-stat lyskom-last-message-recipient)))
                        (cons (conf-stat->name tmp) 0))

                       (t 
                        (if lyskom-last-personal-message-sender
                            (cons lyskom-last-personal-message-sender 0)
                          "")))
                      t))))
David Kågedal's avatar
David Kågedal committed
558
    (if (zerop target)
David Byers's avatar
David Byers committed
559
560
        (lyskom-format-insert 'message-use-alarm-instead
                              (lyskom-command-name 'kom-send-alarm))
561
      (setq lyskom-last-message-recipient target)
David Byers's avatar
David Byers committed
562
563
      (lyskom-format-insert 'message-recipient-info target)
      (lyskom-send-message target message))))
Linus Tolke's avatar
Linus Tolke committed
564
  
565

566
(def-kom-command kom-send-alarm (&optional message)
567
568
  "Send a message to all of the users in KOM right now."
  (interactive)
David Byers's avatar
David Byers committed
569
  (lyskom-insert (lyskom-get-string 'message-all-info))
570
  (lyskom-send-message 0 message))
Per Cederqvist's avatar
.  
Per Cederqvist committed
571
572


David Byers's avatar
David Byers committed
573
574
575
576
(defvar lyskom-message-recipient)
(defvar lyskom-message-string)


David Byers's avatar
David Byers committed
577
578
579
580
581
582
583
584
585
586
587
588
(defun lyskom-send-message-minibuffer-setup-hook ()
  (unwind-protect
      (run-hooks 'lyskom-send-message-setup-hook)
    (remove-hook 'minibuffer-setup-hook 
                 'lyskom-send-message-minibuffer-setup-hook)))

(defun lyskom-send-message-minibuffer-exit-hook ()
  (unwind-protect
      (run-hooks 'lyskom-send-message-exit-hook)
    (remove-hook 'minibuffer-exit-hook
                 'lyskom-send-message-minibuffer-exit-hook)))

David Byers's avatar
David Byers committed
589
590
(defun lyskom-send-message (pers-no
                            message &optional dontshow)
David Byers's avatar
David Byers committed
591
592
593
  "Send a message to the person with the number PERS-NO.  PERS-NO == 0
means send the message to everybody. MESSAGE is the message to
send. If DONTSHOW is non-nil, don't display the sent message."
David Byers's avatar
David Byers committed
594
  (let* ((lyskom-message-string nil)
David Byers's avatar
David Byers committed
595
         (reply nil)
David Byers's avatar
David Byers committed
596
597
         (lyskom-message-recipient nil)
         (lyskom-last-text-format-flags nil))
David Byers's avatar
David Byers committed
598
599

    (add-hook 'minibuffer-setup-hook
David Byers's avatar
David Byers committed
600
              'lyskom-send-message-minibuffer-setup-hook)
David Byers's avatar
David Byers committed
601
    (add-hook 'minibuffer-exit-hook
David Byers's avatar
David Byers committed
602
              'lyskom-send-message-minibuffer-exit-hook)
David Byers's avatar
David Byers committed
603
604
    (setq lyskom-message-string 
          (or message
David Byers's avatar
David Byers committed
605
606
607
              (lyskom-read-string (lyskom-get-string 'message-prompt)
                                  nil
                                  'lyskom-message-history)))
David Byers's avatar
David Byers committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
    (setq lyskom-message-recipient (if (zerop pers-no)
                                       nil
                                     (blocking-do 'get-conf-stat 
                                                  pers-no)))

    (run-hooks 'lyskom-send-message-hook)
    (if lyskom-message-string
        (progn
          (setq reply (blocking-do 'send-message pers-no
                                   lyskom-message-string))

          (if reply
              (if (not dontshow)
                  (lyskom-handle-as-personal-message
                   (if lyskom-message-recipient
623
624
                       (lyskom-format (lyskom-get-string-sol 
                                       'message-sent-to-user)
David Byers's avatar
David Byers committed
625
626
                                      lyskom-message-string 
                                      lyskom-message-recipient)
627
628
                     (lyskom-format (lyskom-get-string-sol 
                                     'message-sent-to-all)
David Byers's avatar
David Byers committed
629
630
631
632
633
634
635
636
637
                                    lyskom-message-string))
                   lyskom-pers-no
                   lyskom-filter-outgoing-messages))
            (lyskom-format-insert-before-prompt
             'message-nope 
             (or lyskom-message-recipient
                 (lyskom-get-string 'everybody))
             lyskom-message-string)))
      (lyskom-insert-string 'interrupted))                   ;+++ lyskom-errno
638
    ))
Per Cederqvist's avatar
.  
Per Cederqvist committed
639

David Byers's avatar
David Byers committed
640
(defun lyskom-send-message-trim-newlines ()
641
642
643
644
645
646
647
648
649
650
651
652
653
  (when (stringp lyskom-message-string)
    (let ((size (length lyskom-message-string)))
      (while (and (> size 0)
                  (eq ?\n (aref lyskom-message-string (1- size))))
        (setq size (1- size)))
      (cond ((and (eq size 0)
                  (not (lyskom-j-or-n-p (lyskom-get-string 
                                         'send-empty-message-p))))
             (setq lyskom-message-string nil))
            ((eq size 0)
             (setq lyskom-message-string ""))
            (t (setq lyskom-message-string (substring lyskom-message-string 
                                                      0 size)))))))
David Byers's avatar
David Byers committed
654

655
656
(lyskom-external-function resize-minibuffer-setup)

657
658
659
660
661
(defun lyskom-send-message-turn-off-resize-on-exit ()
  (resize-minibuffer-mode -1)
  (remove-hook 'lyskom-send-message-exit-hook
               'lyskom-send-message-turn-off-resize-on-exit))
               
662
(defvar resize-minibuffer-mode)
663
664
(defun lyskom-send-message-resize-minibuffer ()
  "Temporarily turn on resizing of minibuffer"
665
666
667
668
669
  (unless resize-minibuffer-mode
    (resize-minibuffer-mode 1)
    (resize-minibuffer-setup)
    (add-hook 'lyskom-send-message-exit-hook
              'lyskom-send-message-turn-off-resize-on-exit)))
670
671
672
673


(defun lyskom-send-message-auto-fill ()
  "Temporarily turn on auto fill in minibuffer"
David Byers's avatar
X    
David Byers committed
674
  (setq fill-column 78)                 ;+++ Ta bort?
675
676
  (auto-fill-mode 1))

Per Cederqvist's avatar
.  
Per Cederqvist committed
677
678
679
680
681
682
683


;;; ================================================================
;;;       Endast l{sa senaste - Set unread articles in a conf. 
;;;            (Skip or re-read articles).

;;; Author: Linus Tolke
684
;;; Rehacked: David K}gedal
Per Cederqvist's avatar
.  
Per Cederqvist committed
685
686


687
(def-kom-command kom-set-unread (&optional arg conf-no)
Per Cederqvist's avatar
.  
Per Cederqvist committed
688
  "Set number of unread articles in current conference."
689
  (interactive "P")
690
  (setq conf-no (or conf-no lyskom-current-conf))
David Byers's avatar
David Byers committed
691
  (if (or (null conf-no) (zerop conf-no))
692
693
694
      (progn
        (lyskom-insert-string 'not-present-anywhere)
        (lyskom-insert-string "\n"))
695
    (let ((conf-stat (blocking-do 'get-conf-stat conf-no)))
696
697
698
699
700
701
702
703
704
705
706
707
      (if (null conf-stat)              ;+++ annan errorhantering
          (lyskom-insert "Error!\n")	;+++ Hrrrmmmmffff????
        (let* ((narg (prefix-numeric-value arg))
               (n (if (and arg
                           (<= 0 narg)
                           (<= narg (conf-stat->no-of-texts conf-stat)))
                      narg
                    (lyskom-read-num-range 
                     0 (conf-stat->no-of-texts conf-stat)
                     (lyskom-format 'only-last
                                    (conf-stat->no-of-texts conf-stat)
                                    (conf-stat->name conf-stat)))))
708
709
710
	       (result (blocking-do 'set-unread conf-no n))
               (membership (blocking-do 'query-read-texts
					lyskom-pers-no
David Byers's avatar
David Byers committed
711
					conf-no)))
712
          (lyskom-ignore result)
David Byers's avatar
David Byers committed
713
	  (lyskom-replace-membership membership)
714
715
716
	  (if (= conf-no lyskom-current-conf)
	      (set-read-list-empty lyskom-reading-list))
	  (read-list-delete-read-info conf-no lyskom-to-do-list)
717
718
719
720
          (if (= conf-no lyskom-current-conf)
              (progn (lyskom-fetch-start-of-map conf-stat membership)
                     (lyskom-go-to-conf lyskom-current-conf t))
            (lyskom-prefetch-map conf-no membership))
721
	  )))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
722
723
724
725
726
727
728



;;; ================================================================
;;;                 Lista Nyheter - List News

;;; Author:   Linus Tolke
729
;;; Rehacked: Inge Wallin, Johan Sundstrm
Per Cederqvist's avatar
.  
Per Cederqvist committed
730
731


732
(defvar lyskom-special-conf-name "\\`\\(Inl.gg .t mig\\|NL:\\)\\'"
733
734
  "Regexp to match conf names that are special.")

735

736
737
738
739
740
741
742
743
(defvar lyskom-iter-list-news-total-confs)
(defvar lyskom-iter-list-news-mship-confs)
(defvar lyskom-iter-list-news-shown-unreads)
(defvar lyskom-iter-list-news-shown-confs)
(defvar lyskom-iter-list-news-total-unreads)
(defvar lyskom-iter-list-news-total-confs)

(defun lyskom-iter-list-news (unreads conf-stat at-least at-most)
744
745
746
747
748
749
750
  "Callback function used to show the number of unread messages of a
conference. It heavily relies on (and destructively modifies) its
environment."
  (when (and (or (not at-least)
		 (>= unreads at-least))	; unreads within lower bound
	     (or (not at-most)
		 (<= unreads at-most)))	; unreads within upper bound
751
752
753
754
    (when lyskom-iter-list-news-mship-confs			; remember all read conferences?
      (setq lyskom-iter-list-news-mship-confs
            (delq (conf-stat->conf-no conf-stat) 
                  lyskom-iter-list-news-mship-confs)))
755
756
757
758
759
760
761
    (cond
     ((and (boundp 'lyskom-special-conf-name)
	   (stringp lyskom-special-conf-name)
	   (string-match lyskom-special-conf-name
			 (conf-stat->name conf-stat)))
      (lyskom-format-insert 'you-have-unreads-special unreads conf-stat))
     (t (lyskom-format-insert 'you-have-unreads unreads conf-stat)))
762
763
764
765
766
767
768
769
    (setq lyskom-iter-list-news-shown-unreads 
          (+ lyskom-iter-list-news-shown-unreads unreads)
	  lyskom-iter-list-news-shown-confs
          (1+ lyskom-iter-list-news-shown-confs)))
  (setq lyskom-iter-list-news-total-unreads 
        (+ lyskom-iter-list-news-total-unreads unreads)
	lyskom-iter-list-news-total-confs
        (1+ lyskom-iter-list-news-total-confs)))
770
771


David Kågedal's avatar
David Kågedal committed
772
(def-kom-command kom-list-news (&optional num)
773
774
775
776
  "Print the number of unread articles to the user. A prefix argument
of zero lists all conferences, a positive prefix arguments sets a
lower bound on the number of unread messages, whereas a negative
prefix argument sets an upper bound on the number of unread messages."
David Kågedal's avatar
David Kågedal committed
777
  (interactive "P")
778
779
780
781
782
  (let ((num-arg (cond
		  ((numberp num) num)
		  ((and (listp num)
			(numberp (car num))) (car num))
		  (t nil)))
783
	(lyskom-iter-list-news-mship-confs nil)
784
785
	(at-least 1)
	(at-most nil)
786
787
788
789
	(lyskom-iter-list-news-shown-unreads 0)
	(lyskom-iter-list-news-total-unreads 0)
	(lyskom-iter-list-news-shown-confs 0)
	(lyskom-iter-list-news-total-confs 0))
790
791
792
793
    (when num-arg
      (cond
       ((= num-arg 0)
	(setq at-least nil
794
795
796
797
798
799
800
	      lyskom-iter-list-news-mship-confs 
              (delq nil
                    (mapcar (lambda (el)
                              (when (not (membership-type->passive
                                          (membership->type el)))
                                (membership->conf-no el)))
                            lyskom-membership))))
801
802
803
804
805
806
807
       ((> num-arg 0)
	(lyskom-format-insert 'list-unread-with-n-unread
			      (setq at-least num-arg)))
       ((< num-arg 0)
	(lyskom-format-insert 'list-unread-with-at-most-n-unread
			      (setq at-most (- num-arg))))))

808
809
810
811
812
813
    ;; The following variables are bound in the callback
    ;; lyskom-iter-list-news-total-unreads
    ;; lyskom-iter-list-news-shown-unreads
    ;; lyskom-iter-list-news-total-confs
    ;; lyskom-iter-list-news-shown-confs
    ;; lyskom-iter-list-news-mship-confs
814

815
816
817
    (lyskom-list-news 'lyskom-iter-list-news (list at-least at-most))
    (when lyskom-iter-list-news-mship-confs ; then list all read conferences too
      (lyskom-traverse conf-no lyskom-iter-list-news-mship-confs
818
819
	(lyskom-format-insert 'you-have-no-unreads conf-no)))

820
    (if (= 0 lyskom-iter-list-news-total-unreads)
821
	(lyskom-insert-string 'you-have-read-everything)
822
      (if (= 0 lyskom-iter-list-news-shown-unreads)
823
824
825
	  (lyskom-insert-string 'no-unreads-shown)
	(lyskom-insert "\n")) ; separate the shown list from the summary message
      (when (and
826
827
828
829
830
831
832
833
834
	     (> lyskom-iter-list-news-shown-unreads 0)
	     (< lyskom-iter-list-news-shown-unreads
                lyskom-iter-list-news-total-unreads))
	(lyskom-format-insert 'shown-unreads
                              lyskom-iter-list-news-shown-unreads
                              lyskom-iter-list-news-shown-confs))
      (lyskom-format-insert 'total-unreads
                            lyskom-iter-list-news-total-unreads 
                            lyskom-iter-list-news-total-confs))))
835
836
837
838
839
840
841
842
843
844
845


(defun lyskom-list-news (&optional callback &optional callback-args)
  "With no arguments, returns a list of tuples (unread . conf-stat).
When called with a CALLBACK function, this function is called
iteratively as the list is built up. This function should take the two
arguments `number-of-unread-messages-in-conference' and `conf-stat'
and optionally any other arguments sent in the list CALLBACK-ARGS, and
its return value will form the elements of the list returned from
lyskom-list-news. The callback will only be fed conferences with at
least one unread message in them."
David Kågedal's avatar
David Kågedal committed
846

847
848
849
  (unless kom-allow-incompleteness
    (sit-for 0)
    (lyskom-prefetch-all-confs))
David Kågedal's avatar
David Kågedal committed
850

851
852
853
854
855
856
857
858
859
860
861
  (mapcar
   (function
    (lambda (info)
      (let ((unreads (length (cdr (read-info->text-list info))))
	    (conf-stat (read-info->conf-stat info)))
	(when (eq (read-info->type info) 'CONF)
	  (if callback
	      (apply callback unreads conf-stat callback-args)
	    (cons unreads conf-stat))))))
   (read-list->all-entries lyskom-to-do-list)))

Per Cederqvist's avatar
.  
Per Cederqvist committed
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876


;;; ================================================================
;;; 			V{nta - Idle wait


(defun kom-busy-wait (arg)
  "Sets the kom-session in wait-mode.
The wait-mode is interrupted when a text in a conference with higher priority
than that of the next text to be read.
If you want another priority to break that the ones higher that the next text 
to be read, give the priority as a prefix argument.
When a text is received the new text is displayed."
  (interactive "P")
  (lyskom-start-of-command 'kom-busy-wait)
David Kågedal's avatar
David Kågedal committed
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
  (unwind-protect
      (let ((waitfor (or (cond
			  ((integerp arg) arg)
			  ((listp arg) (car arg)))
			 (read-info->priority
			  (read-list->first lyskom-to-do-list))
			 -2)))
	(lyskom-tell-server kom-mercial)
	(if (not (read-list-isempty lyskom-reading-list))
	    (set-read-list-empty lyskom-reading-list))
	(if (= waitfor -2)
	    (lyskom-insert-string 'waiting-for-anything)
	  (lyskom-format-insert 'waiting-higher-than waitfor))
	(lyskom-scroll)
	(setq lyskom-is-waiting
	      (list '>
		    '(or (read-info->priority
			  (read-list->first lyskom-reading-list))
			 (read-info->priority
			  (read-list->first lyskom-to-do-list))
			 257)
		    waitfor))
	(while lyskom-is-waiting
	  ;; This is a bit trial-and-error stuff at the momemt.
	  ;; o How to make personal messages appear *fast*
	  ;; o How to enable C-g with a quick response
David Kågedal's avatar
David Kågedal committed
903
	  (sit-for 0)
David Kågedal's avatar
David Kågedal committed
904
905
906
907
908
909
	  (accept-process-output nil 1)
	  (sit-for 0)
	  (if lyskom-quit-flag
	      (signal 'quit nil))))
    (lyskom-end-of-command))
  ;; We are done waiting
910
  (lyskom-beep kom-ding-on-wait-done)
David Kågedal's avatar
David Kågedal committed
911
912
913
914
  (if (read-list-isempty lyskom-reading-list)
      (kom-go-to-next-conf))
  (kom-next-command))
  
Per Cederqvist's avatar
.  
Per Cederqvist committed
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934


(defun lyskom-time-greater (time1 time2)
  "Returns t if TIME2 is before TIME1 chronologically."
  (cond
   ((< (time->year time2) (time->year time1)))
   ((< (time->mon time2) (time->mon time1)))
   ((< (time->mday time2) (time->mday time1)))
   ((< (time->hour time2) (time->hour time1)))
   ((< (time->min time2) (time->min time1)))
   ((< (time->sec time2) (time->sec time1)))
   (t nil)))


;;; ================================================================
;;;               Lista {rende - list summary

;;; Author: Linus Tolke


David Kågedal's avatar
David Kågedal committed
935
(def-kom-command kom-list-summary ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
936
937
938
939
  "List a summary of the unread in the current conf.
The summary contains the date, number of lines, author and subject of the text
on one line."
  (interactive)
David Kågedal's avatar
David Kågedal committed
940
941
  (if (read-list-isempty lyskom-reading-list)
      (lyskom-insert-string 'have-to-be-in-conf-with-unread)
942
	
David Kågedal's avatar
David Kågedal committed
943
944
945
    (lyskom-list-summary
      (text-list->texts 
       (read-info->text-list 
946
	(let ((len (read-list-length lyskom-reading-list))
David Kågedal's avatar
David Kågedal committed
947
948
949
950
951
	      (r 0))
	  (while (< r len)
	    (let ((type (read-info->type 
			 (read-list->nth lyskom-reading-list
					 r))))
952
	      (if (memq type '(CONF REVIEW-MARK REVIEW))
David Kågedal's avatar
David Kågedal committed
953
954
955
956
957
958
959
960
961
		  (setq len 0)
		(++ r))))
	  (read-list->nth lyskom-reading-list r)))))))


(defun lyskom-list-summary (texts)
  "List a summary of the texts in TEXTS.
The summary contains the date, number of lines, author and subject of the text
on one line."
962
  (let ((time (lyskom-current-server-time))
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
	(author-width (/ (- (lyskom-window-width) 22) 3)))
    
    ;; Start fetching all text-stats and text to list them.
    (lyskom-format-insert (concat "%-8#1s%-6#2s%-4#3s %-"
				  (int-to-string author-width)
				  "#4s  %#5s\n")
			  (lyskom-get-string 'Texts)
			  (lyskom-get-string 'Date)
			  (lyskom-get-string 'Lines)
			  (lyskom-get-string 'Author)
			  (lyskom-get-string 'Subject))
    (lyskom-traverse
	text-no texts
      (let ((text-stat (blocking-do 'get-text-stat text-no))
	    (text (blocking-do 'get-text text-no))
	    ;; We could do som optimization here. 
	    ;; We really don't need the whole text.
	    )
	(lyskom-print-summary-line text-stat text text-no 
982
983
984
				   (time->year time)
                                   (time->mon time)
                                   (time->mday time))
985
	(sit-for 0)))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
986
987


988
(defun lyskom-print-summary-line (text-stat text text-no year mon mday)
Per Cederqvist's avatar
.  
Per Cederqvist committed
989
990
991
992
993
994
995
  "Handle the info, fetch the author and print it.
Args: TEXT-STAT TEXT TEXT-NO YEAR DAY.
The year and day is there to be able to choose format on the day.
Format is 23:29 if the text is written today. Otherwise 04-01."
  (if (not (and text-stat text))	;+++ B{ttre felhantering.
      (lyskom-format-insert 'could-not-read text-no)
    (let* ((lines (text-stat->no-of-lines text-stat))
996
	   (txt (text->decoded-text-mass text text-stat))
Per Cederqvist's avatar
.  
Per Cederqvist committed
997
998
	   (eos (string-match (regexp-quote "\n") txt))
	   (subject (substring txt 0 eos))
999
1000
1001
           (mx-date (car (lyskom-get-aux-item (text-stat->aux-items text-stat) 21)))
           (mx-from (car (lyskom-get-aux-item (text-stat->aux-items text-stat) 17)))
           (mx-author (car (lyskom-get-aux-item (text-stat->aux-items text-stat) 16)))
David Byers's avatar
David Byers committed
1002
	   ;; length of the number %%%%%% :8
Per Cederqvist's avatar
.  
Per Cederqvist committed
1003
	   ;; length for time is: 6
1004
1005
           (time (or (lyskom-mx-date-to-time mx-date)
                     (text-stat->creation-time text-stat)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1006
	   (time (if (and (= year (time->year time))
1007
1008
			  (= mon (time->mon time))
                          (= mday (time->mday time)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1009
1010
		     (format "%02d:%02d" (time->hour time)
			     		 (time->min time))
1011
		   (format "%02d-%02d" (time->mon time)
Per Cederqvist's avatar
.  
Per Cederqvist committed
1012
1013
1014
			   	       (time->mday time))))
	   ;; length for lines is: 4
	   ;; We split the rest between author and subject
David Byers's avatar
David Byers committed
1015
1016
	   (namelen (/ (- (lyskom-window-width) 22) 3))
	   (subjlen (/ (* (- (lyskom-window-width) 22) 2) 3))
1017
1018
1019
1020
1021
1022
	   (format-string (concat "%=-8#1n%#2s%4#3d  %=-"
				  (int-to-string namelen)
				  "#4P  %[%#5@%=-"
				  (int-to-string subjlen)
				  "#6r%]\n")))
      (lyskom-format-insert format-string
1023
1024
1025
			    text-no
			    time
			    lines
1026
                            (if (or mx-from mx-author)
1027
1028
                                (lyskom-format-mx-author mx-from mx-author)
                              (text-stat->author text-stat))
1029
1030
			    (lyskom-default-button 'text
						   text-no)
1031
			    subject))))
1032

Per Cederqvist's avatar
.  
Per Cederqvist committed
1033
1034


David Byers's avatar
David Byers committed
1035
1036
1037
;;; ============================================================
;;; kom-list-marks                      Lista markeringar
;;; Author: David Byers
1038
;;; Modified by: Joel Rosdahl
David Byers's avatar
David Byers committed
1039
1040

(def-kom-command kom-list-marks (&optional which-mark)
1041
  "List texts marked with a particular mark number."
David Byers's avatar
David Byers committed
1042
1043
  (interactive "P")
  (when (not (numberp which-mark))
1044
1045
1046
    (setq which-mark (lyskom-read-mark-type
                      (lyskom-get-string 'list-which-mark)
                      t)))
David Byers's avatar
David Byers committed
1047
1048
  (let ((marks
         (sort (listify-vector (blocking-do 'get-marks))
1049
               (lambda (a b) (< (mark->mark-type a) (mark->mark-type b)))))
1050
        (time (lyskom-current-server-time))
1051
1052
1053
1054
1055
1056
        (author-width (max 0
                           (/ (- (lyskom-window-width)
                                 23
                                 (lyskom-max-mark-width))
                              3))))

David Byers's avatar
David Byers committed
1057
    ;; Start fetching all text-stats and text to list them.
1058
1059
1060
    (lyskom-format-insert (concat "%-"
                                  (int-to-string (1+ (lyskom-max-mark-width)))
                                  "#6s%-8#1s%-6#2s%-4#3s %-"
David Byers's avatar
David Byers committed
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
				  (int-to-string author-width)
				  "#4s  %#5s\n")
			  (lyskom-get-string 'Texts)
			  (lyskom-get-string 'Date)
			  (lyskom-get-string 'Lines)
			  (lyskom-get-string 'Author)
			  (lyskom-get-string 'Subject)
                          (lyskom-get-string 'mark-type))
;    (lyskom-insert (make-string (1- (window-width)) ?-))
;    (lyskom-insert "\n")
    (lyskom-traverse
	mark marks
      (when (or (null which-mark)
                (eq (mark->mark-type mark) which-mark))
        (let* ((text-no (mark->text-no mark))
               (text-stat (blocking-do 'get-text-stat text-no))
               (text (blocking-do 'get-text text-no))
	    ;; We could do som optimization here. 
	    ;; We really don't need the whole text.
	    )
          (lyskom-print-mark-summary-line mark text-stat text text-no 
                                     (time->year time) (time->yday time))
          (sit-for 0))))
;    (lyskom-insert (make-string (1- (window-width)) ?-))
;    (lyskom-insert "\n")
1086
1087
    ))

David Byers's avatar
David Byers committed
1088
1089
1090
1091
1092
(defun lyskom-print-mark-summary-line (mark text-stat text text-no year day)
  "Handle the info, fetch the author and print it.
Args: TEXT-STAT TEXT TEXT-NO YEAR DAY.
The year and day is there to be able to choose format on the day.
Format is 23:29 if the text is written today. Otherwise 04-01."
1093
1094
  (lyskom-format-insert (format "%%-%d#1s " (lyskom-max-mark-width))
                        (mark->symbolic-mark-type mark))
David Byers's avatar
David Byers committed
1095
1096
1097
  (if (not (and text-stat text))	;+++ B{ttre felhantering.
      (lyskom-format-insert 'could-not-read text-no)
    (let* ((lines (text-stat->no-of-lines text-stat))
1098
	   (txt (text->decoded-text-mass text text-stat))
David Byers's avatar
David Byers committed
1099
1100
	   (eos (string-match (regexp-quote "\n") txt))
	   (subject (substring txt 0 eos))
1101
1102
1103
1104
1105
1106
           (author-and-subj-width (max 0
                                       (- (lyskom-window-width)
                                          23
                                          (lyskom-max-mark-width))))
	   ;; length of the number: 8
	   ;; length for time: 6
David Byers's avatar
David Byers committed
1107
1108
1109
1110
1111
	   (time (text-stat->creation-time text-stat))
	   (time (if (and (= year (time->year time))
			  (= day (time->yday time)))
		     (format "%02d:%02d" (time->hour time)
			     		 (time->min time))
1112
		   (format "%02d-%02d" (time->mon time)
David Byers's avatar
David Byers committed
1113
			   	       (time->mday time))))
1114
	   ;; length for lines: 5
David Byers's avatar
David Byers committed
1115
	   ;; We split the rest between author and subject
1116
1117
	   (namelen (/ author-and-subj-width 3))
	   (subjlen (- author-and-subj-width namelen))
David Byers's avatar
David Byers committed
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
	   (format-string (concat "%=-8#1n%#2s%4#3d  %=-"
				  (int-to-string namelen)
				  "#4P  %[%#5@%=-"
				  (int-to-string subjlen)
				  "#6r%]\n")))
      (lyskom-format-insert format-string
			    text-no
			    time
			    lines
			    (text-stat->author text-stat)
			    (lyskom-default-button 'text
						   text-no)
			    subject))))

1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
(defun lyskom-symbolic-mark-type-string (mark-no)
  "Return a symbolic name string for the mark-type of MARK."
  (or (car-safe (rassoc mark-no kom-symbolic-marks-alist))
      (int-to-string mark-no)))

(defun lyskom-max-mark-width ()
  (max 3
       (apply 'max
              (mapcar (function (lambda (x) (length (car x))))
                      kom-symbolic-marks-alist))))
David Byers's avatar
David Byers committed
1142

David Byers's avatar
David Byers committed
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
;;; ============================================================
;;;     kom-who-am-i - Vem r jag
;;;
;;; Author: David Byers

(def-kom-command kom-who-am-i ()
  "Show my name"
  (interactive)
  (if (and lyskom-current-conf
           (not (zerop lyskom-current-conf)))
      (lyskom-format-insert 'who-i-am-present 
                            lyskom-pers-no
                            lyskom-current-conf)
    (lyskom-format-insert 'who-i-am-not-present lyskom-pers-no))

  (lyskom-format-insert 
   'who-i-am-server
   lyskom-server-name
1161
   (version-info->software-version lyskom-server-version-info))
David Byers's avatar
David Byers committed
1162
1163

  (lyskom-format-insert 'who-i-am-client
David Byers's avatar
David Byers committed
1164
1165
                        lyskom-clientversion
                        lyskom-mule-compiled)
David Byers's avatar
David Byers committed
1166
1167

  (lyskom-format-insert 'who-i-am-emacs
David Byers's avatar
David Byers committed
1168
1169
                        (emacs-version)
                        enable-multibyte-characters))
David Byers's avatar
David Byers committed
1170
1171
                        

Per Cederqvist's avatar
.  
Per Cederqvist committed
1172
1173
1174
1175
1176
1177
1178

;;; ================================================================
;;;      kom-display-who-buffer - Visa vilka-listan

;;; Author: Linus Tolke


1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
;;(def-kom-command kom-display-who-buffer ()
;;  "Make the who-buffer appear on the screen as a temp buffer."
;;  (interactive)
;;  (let ((win (selected-window))
;;	(who (display-buffer lyskom-who-info-buffer)))
;;    (unwind-protect
;;	(progn
;;	  (select-window who)
;;	  (if (numberp kom-who-buffer-size-when-displaying)
;;	      (enlarge-window (- kom-who-buffer-size-when-displaying 
;;				 (window-height who)))))
;;      (select-window win))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202



;;; ================================================================
;;;          Hj{lp vid del av kommando - Help function

;;; Author: Linus Tolke


(defun lyskom-help ()
  "Prints a short list of alternatives when you don't know what you can do."
  (interactive)
1203
  (let* ((tohere (cond
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
                  ((stringp (this-command-keys))
                   (substring (this-command-keys) 0 -1))
                  (t                    ;This is the case in the lucid-emacs.
                   (let* ((tck (this-command-keys))
                          (newvec (make-vector (1- (length tck)) nil))
                          (r 0))
                     (while (< r (length newvec))
                       (aset newvec r (aref tck r))
                       (++ r))
                     newvec))))
         (binding (key-binding tohere))
         (keymap (cond
                  ((and (symbolp binding)
                        (fboundp binding))
                   (symbol-function binding))
                  (t binding)))
         (keylis (lyskom-help-get-keylist keymap))
         (text (format "\n%s: \n%s\n"
                       (mapconcat 'single-key-description tohere " ")
                       (mapconcat
                        (function
                         (lambda (arg)
                           (format "%s - %s" 
David Byers's avatar
David Byers committed
1227
                                   (if (fboundp 'key-description)
David Byers's avatar
David Byers committed
1228
1229
1230
				       (if (not (vectorp (car arg)))
					   (key-description (vector (car arg)))
					 (key-description (car arg)))
David Byers's avatar
David Byers committed
1231
1232
1233
1234
1235
                                     (cond ((symbolp (car arg))
                                            (format "%s" (car arg)))
                                           ((characterp (car arg))
                                            (format "%c" (car arg)))
                                           (t (format "%S" (car arg)))))
1236
1237
                                   (or (lyskom-command-name (cdr arg))
                                       (and (keymapp (cdr arg))
1238
1239
                                            (lyskom-get-string
					     'multiple-choice))
1240
1241
1242
                                       (cdr arg)))))
                        keylis
                        "\n")))
1243
1244
         ;; next-char
	 )
Per Cederqvist's avatar
.  
Per Cederqvist committed
1245
    (if (eq major-mode 'lyskom-mode)
1246
1247
1248
        (progn
          (lyskom-insert text)
          (lyskom-end-of-command))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1249
      (with-output-to-temp-buffer "*Help*"
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
        (princ text)))))


(defun lyskom-help-get-keylist (keymap)
  (cond
   ((fboundp 'map-keymap)
    (and keymap
         (let (list)
           (map-keymap
            (function
             (lambda (event function)
               (setq list (cons (cons event function) list))))
            keymap t)
           (nreverse list))))
   ((vectorp keymap)
    (let ((lis nil)
          (r 0))
      (while (< r (length keymap))
        (if (aref keymap r)
            (setq lis (cons (cons r (aref keymap r))
                            lis)))
        (++ r))
      (nreverse lis))) 
   (t
    (cdr keymap))))




Per Cederqvist's avatar
.  
Per Cederqvist committed
1279
1280
1281
1282
;    (setq next-char (read-char))
;    (cond
;     ((commandp (key-binding (concat tohere (char-to-string next-char))))
;      (command-execute (concat tohere (char-to-string next-char))))
1283
;     (t (lyskom-message "%s" (lyskom-get-string 'does-not-exist))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1284
1285
1286
1287
1288
1289
1290
1291
1292



;;; ================================================================
;;;      [ndra livsl{ngd - Set lifespan of texts in a conference

;;; Author: Inge Wallin


David Kågedal's avatar
David Kågedal committed
1293
(def-kom-command kom-set-garb-nice ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
1294
1295
  "Set the garb-nice value for a conference."
  (interactive)
David Kågedal's avatar
David Kågedal committed
1296
1297
  (let ((conf-stat (lyskom-read-conf-stat
		    (lyskom-get-string 'conf-to-set-garb-nice-q)
1298
		    '(all) nil nil t)))
David Kågedal's avatar
David Kågedal committed
1299
1300
    (if (not conf-stat)
	(lyskom-insert-string 'somebody-deleted-that-conf)
David Byers's avatar
David Byers committed
1301
      (let ((garb-nice (lyskom-read-number 'new-garb-nice-q)))
David Kågedal's avatar
David Kågedal committed
1302
1303
1304
1305
1306
1307
1308
1309
1310
	(lyskom-format-insert 'garb-nice-for-is
			      conf-stat
			      garb-nice)
	(if (not (blocking-do 'set-garb-nice
			      (conf-stat->conf-no conf-stat) 
			      garb-nice))
	    (lyskom-insert-string 'nope) ;+++lyskom-errno
	  (lyskom-insert-string 'done)
	  (cache-del-conf-stat (conf-stat->conf-no conf-stat)))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1311
1312


Linus Tolke's avatar
Linus Tolke committed
1313
1314
1315
1316
1317
;;; ================================================================
;;;       S{tt till}tna f|rfattare - set-permitted-submitters

;;; Author: Linus Tolke

David Kågedal's avatar
David Kågedal committed
1318
(def-kom-command kom-set-permitted-submitters ()
Linus Tolke's avatar
Linus Tolke committed
1319
1320
  "Set the permitted submitters of a conference."
  (interactive)
David Kågedal's avatar
David Kågedal committed
1321
1322
  (let ((conf-stat (lyskom-read-conf-stat 
		    (lyskom-get-string 'conf-to-set-permitted-submitters-q)
1323
		    '(all) nil nil t)))
David Kågedal's avatar
David Kågedal committed
1324
1325
1326
1327
1328
1329

    (if (not conf-stat)
	(lyskom-insert-string 'somebody-deleted-that-conf)
      (let ((new-conf (lyskom-read-conf-stat
		       (lyskom-format 'new-permitted-submitters-q
				      (conf-stat->name conf-stat))
1330
		       '(all) 
1331
		       t nil t)))
David Kågedal's avatar
David Kågedal committed
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
	(if (eq new-conf nil)
	    (lyskom-format-insert 'permitted-submitters-removed-for-conf 
				  conf-stat)
	  (lyskom-format-insert 'submitters-conf-for-is
				conf-stat
				new-conf))
	(if (not (blocking-do 'set-permitted-submitters
			      (conf-stat->conf-no conf-stat) 
			      (if (eq new-conf nil) ;Allowing all to write there
				  0
				(conf-stat->conf-no new-conf))))
	    (lyskom-insert-string 'nope) ;+++ lyskom-errno
	  (lyskom-insert-string 'done)
	  (cache-del-conf-stat (conf-stat->conf-no conf-stat)))))))
Linus Tolke's avatar
Linus Tolke committed
1346
1347


inge's avatar
inge committed
1348
1349
1350
1351
1352
1353
;;; ================================================================
;;;             [ndra superm|te - Set super conference 

;;; Author: Inge Wallin


David Kågedal's avatar
David Kågedal committed
1354
(def-kom-command kom-set-super-conf ()
inge's avatar
inge committed
1355
1356
  "Set the super conference for a conference."
  (interactive)
David Kågedal's avatar
David Kågedal committed
1357
1358
  (let ((conf-stat (lyskom-read-conf-stat 
		    (lyskom-get-string 'conf-to-set-super-conf-q)
1359
		    '(all) nil nil t)))
David Kågedal's avatar
David Kågedal committed
1360
1361
1362
1363
1364
    (if (not conf-stat)
	(lyskom-insert-string 'somebody-deleted-that-conf)
      (let ((new-conf (lyskom-read-conf-stat
		       (lyskom-format 'new-super-conf-q
				      (conf-stat->name conf-stat))
1365
		       '(all) nil nil t)))
1366
      
David Kågedal's avatar
David Kågedal committed
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
	;; Set the super conference for conf-stat to new-conf.
	(lyskom-format-insert 'super-conf-for-is
			      conf-stat
			      new-conf)
	(if (not (blocking-do 'set-super-conf 
			      (conf-stat->conf-no conf-stat) 
			      (conf-stat->conf-no new-conf)))
	    (lyskom-insert-string 'nope) ;+++ lyskom-errno
	  (lyskom-insert-string 'done)
	  (cache-del-conf-stat (conf-stat->conf-no conf-stat)))))))
inge's avatar
inge committed
1377
1378
1379



1380
1381
1382
1383
1384
1385
1386
;;; ================================================================
;;;                  Spara databasen - Save database
;;;

(def-kom-command kom-sync-database ()
  "Save the LysKOM database."
  (interactive)
1387
1388
1389
1390
  (if (and (>= (version-info->protocol-version lyskom-server-version-info) 8)
           (lyskom-ja-or-nej-p (lyskom-get-string 'really-sync)))
      (progn (lyskom-insert-string 'syncing-server)
             (lyskom-report-command-answer (blocking-do 'sync)))
1391
1392
    (setq lyskom-errno 12)
    (lyskom-report-command-answer nil)))
1393

inge's avatar
inge committed
1394

Per Cederqvist's avatar
.  
Per Cederqvist committed
1395
1396
1397
1398
1399
;;; ================================================================
;;;                  St{ng av servern - Shutdown

;;; Author: Inge Wallin

1400
(def-kom-command kom-shutdown-server ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
1401
1402
  "Shutdown the LysKOM server."
  (interactive)
Linus Tolke's avatar
Linus Tolke committed
1403
  (if (lyskom-ja-or-nej-p (lyskom-get-string 'really-shutdown))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1404
1405
      (progn
	(lyskom-insert-string 'closing-server)
1406
        (lyskom-report-command-answer (blocking-do 'shutdown 0)))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1407
1408
1409
1410
1411
1412
1413
1414
1415


;;; ================================================================
;;;       \verg} till adm.mod - Enable administrator capabilities