Commit f99b0e51 authored by Joel Rosdahl's avatar Joel Rosdahl
Browse files

Removed some erroneous indentation.

parent 4c2743b1
2002-03-02 Joel Rosdahl <joel@lysator.liu.se>
* commands2.el: Removed some erroneous indentation.
* lyskom-buttons.el (lyskom-view-url-windows): Rewritten (based on
work by Klaus Zeuge).
......
;;;;; -*-coding: iso-8859-1;-*-
;;;;;
;;;;; $Id$
;;;;; Copyright (C) 1991-2002 Lysator Academic Computer Association.
;;;;;
;;;;; This file is part of the LysKOM Emacs LISP client.
;;;;;
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by
;;;;; the Free Software Foundation; either version 2, or (at your option)
;;;;; 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.
;;;;;
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: commands2.el
;;;;
;;;; This file contains the code for some high level commands.
;;;;
(setq lyskom-clientversion-long
(concat lyskom-clientversion-long
"$Id$\n"))
(eval-when-compile
(require 'lyskom-command "command"))
;;; ================================================================
;;; Lista medlemsskap - List membership
;;; Author: Linus Tolke
;;; Rewritten by ceder
;; This functions is left in its "asynchronous way".
(def-kom-command kom-membership ()
"Show memberships last visited, priority, unread and name."
(interactive)
(let ((buffer (lyskom-get-buffer-create 'list-membership
(concat (buffer-name
(current-buffer))
"-membership")
t)))
(save-window-excursion
(set-buffer buffer)
(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))))
(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")))
(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)))
(if (> first-wanted last-existing)
(lyskom-run 'membership 'lyskom-memb-received
nil conf-stat membership buffer)
(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)))))
(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))
(let ((lyskom-executing-command 'kom-membership)
(lyskom-current-command 'kom-membership)
(inhibit-read-only t)
(kom-print-seconds-in-time-strings nil))
(lyskom-format-insert 'memberships-line
(lyskom-format-time 'date-and-time
(membership->last-time-read
membership))
(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))))
;;; ================================================================
;;; 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)
(def-kom-command kom-status-conf (&optional conf-no)
"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)
(let ((conf-no
(or conf-no
(lyskom-read-conf-no (lyskom-get-string 'conf-for-status)
'(all) nil nil t)))
(kom-print-seconds-in-time-strings nil))
(cache-del-conf-stat conf-no)
(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)
(> (lyskom-string-width (conf-stat->name creator))
(- (lyskom-window-width) 46)))
"\n"
"")))
(lyskom-format-insert 'created-at
(lyskom-format-time
'date-and-time
(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
(lyskom-format-time
'date-and-time
(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)
(> (lyskom-string-width (conf-stat->name superconf))
(- (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)))
;; Show aux items
(lyskom-traverse-aux item
(conf-stat->aux-items conf-stat)
(lyskom-aux-item-call item 'status-print item conf-stat))
(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)))))
;; 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)))
(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"
(lyskom-format-time
'date-and-time
(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)
" "
(format "%9d " unread))
(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
(lyskom-format-time
'date-and-time
(member->created-at member))
(member->created-by member)))
)))))
;; 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)))))))))))
;;; ================================================================
;;; Status (f|r) Person - status for a person
;;; Author: ceder
;;; Heavily enhanced: Inge Wallin (lyskom-status-pers-3 and beyond)
(def-kom-command kom-status-person (&optional pers-no)
"Prints status for a person."
(interactive)
(let ((pers-no
(or pers-no
(lyskom-read-conf-no (lyskom-get-string 'pers-for-status)
'(pers) nil "" t)))
(kom-print-seconds-in-time-strings nil)
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
(lyskom-format-time
'date-and-time
(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))
(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)))))
(lyskom-format-insert 'last-log-in
(lyskom-format-time
'date-and-time
(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))
(if (= (pers-stat->pers-no pers-stat) lyskom-pers-no)
(lyskom-format-insert 'marked-texts
(pers-stat->no-of-marks pers-stat)))
(lyskom-format-insert 'time-for-last-letter
(lyskom-format-time
'date-and-time
(conf-stat->last-written conf-stat)))
(let ((superconf (conf-stat->super-conf conf-stat)))
(lyskom-format-insert 'superconf
superconf
superconf
""))
(if (not (zerop (conf-stat->supervisor conf-stat)))
(let ((supervisor (conf-stat->supervisor conf-stat)))
(lyskom-format-insert 'supervisor
supervisor
supervisor
"")))
(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))))
;; Show aux items
(lyskom-traverse-aux item
(conf-stat->aux-items conf-stat)
(lyskom-aux-item-call item 'status-print item conf-stat))
;; "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
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))))
;; "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"
(lyskom-format-time
'date-and-time
(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
(if (zerop unread) " " (format "%9d " unread))
(if (= (conf-stat->conf-no conf-stat)
(conf-stat->supervisor member-conf-stat))
(lyskom-get-string 'is-supervisor-mark)
" ")
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
(lyskom-format-time
'date-and-time
(membership->created-at membership))
(membership->created-by membership)))
(setq lyskom-count-var (+ lyskom-count-var unread)))))))
;; "Print the total number of unread texts for the person CONF-STAT."
(lyskom-format-insert 'his-total-unread
conf-stat
lyskom-count-var))))))
;;; ================================================================
;;; Skicka meddelande - Send message
;;; Author: Inge Wallin
;;; Rewritten to use lyskom-read-conf-no by Linus Tolke
;;; Modified to use default recipient by David Byers
(def-kom-command kom-send-message (&optional who message)
"Send a message to one of the users in KOM right now."
(interactive)
(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))))
(if (zerop target)
(lyskom-format-insert 'message-use-alarm-instead
(lyskom-command-name 'kom-send-alarm))
(setq lyskom-last-message-recipient target)
(lyskom-format-insert 'message-recipient-info target)
(lyskom-send-message target message))))
(def-kom-command kom-send-alarm (&optional message)
"Send a message to all of the users in KOM right now."
(interactive)
(lyskom-insert (lyskom-get-string 'message-all-info))
(lyskom-send-message 0 message))
(defvar lyskom-message-recipient)
(defvar lyskom-message-string)
(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)))
(defun lyskom-send-message (pers-no
message &optional dontshow)
"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."
(let* ((lyskom-message-string nil)
(reply nil)
(lyskom-message-recipient nil)
(lyskom-last-text-format-flags nil))
(add-hook 'minibuffer-setup-hook
'lyskom-send-message-minibuffer-setup-hook)
(add-hook 'minibuffer-exit-hook
'lyskom-send-message-minibuffer-exit-hook)
(setq lyskom-message-string
(or message
(lyskom-read-string (lyskom-get-string 'message-prompt)
nil
'lyskom-message-history)))
(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
;;;;; -*-coding: iso-8859-1;-*-
;;;;;
;;;;; $Id$