Initial Commit
[packages] / xemacs-packages / xwem / lisp / xwem-appcollect.el
1 ;;; xwem-appcollect.el --- Collect an applications.
2
3 ;; Copyright (C) 2004,2005 by XWEM Org.
4
5 ;; Author: Zajcev Evgeny <zevlg@yandex.ru>
6 ;; Created: Fri Oct 29 04:35:18 MSD 2004
7 ;; Keywords: xwem
8 ;; X-CVS: $Id: xwem-appcollect.el,v 1.2 2005-04-04 19:54:10 lg Exp $
9
10 ;; This file is part of XWEM.
11
12 ;; XWEM is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; XWEM is distributed in the hope that it will be useful, but WITHOUT
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
20 ;; License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;; 02111-1307, USA.
26
27 ;;; Synched up with: Not in FSF
28
29 ;;; Commentary:
30
31 ;; Helpfull util to create `xwem-applications-alist'.
32 ;; Usage:
33 ;; 
34 ;;     (xwem-appcollect '("xterm" "mozilla"))
35
36 ;;     (xwem-appcollect '("xterm" "mozilla") '(name class) 'or)
37
38 ;;     (xwem-appcollect '("xterm" "mozilla") '(command) 'or)
39
40 ;;; Code:
41 \f
42 (require 'xwem-load)
43 (require 'xwem-manage)
44 (require 'xwem-launcher)
45
46 (define-xwem-method manage appcollect (cl)
47   "Manage method when collecting info about applications."
48   (declare (special xwem-app-collection))
49   (declare (special xwem-app-collect-wait))
50
51   (let ((app-name (xwem-cl-get-prop cl 'xwem-appcollect-app-name))
52         (op (xwem-cl-get-prop cl 'xwem-appcollect-op))
53         (params (xwem-cl-get-prop cl 'xwem-appcollect-params))
54         mspec)
55
56     (setq mspec (list op))
57     (mapc (lambda (par)
58             (cond ((eq par 'class)
59                    (push `(and (class-inst ,(concat "^" (car (xwem-hints-wm-class (xwem-cl-hints cl))) "$"))
60                                (class-name ,(concat "^" (cdr (xwem-hints-wm-class (xwem-cl-hints cl))) "$")))
61                          mspec))
62                   ((eq par 'name)
63                    (push `(name ,(concat "^" (xwem-hints-wm-name (xwem-cl-hints cl)) "$"))
64                          mspec))
65                   ((eq par 'command)
66                    (push `(command ,(concat "^" (xwem-hints-wm-command (xwem-cl-hints cl)) "$"))
67                          mspec))))
68           params)
69     (setq mspec (nreverse mspec))
70           
71     (setq xwem-app-collection (put-alist app-name (list mspec) xwem-app-collection))
72     (xwem-client-kill cl t)
73     (setq xwem-app-collect-wait nil)))
74
75 ;;;###autoload(autoload 'xwem-appcollect "xwem-appcollect" nil nil)
76 (defun xwem-appcollect (app-names &optional params operation)
77   "Collect and return applications manage specs.
78 APP-NAMES is a list of applications to collect.
79
80 PARAMS is a list of elements where each element is one of:
81   `class'   - Include class-inst/class-name into mspec.
82   `name'    - Include app name into mspec.
83   `command' - Include command into mspec."
84   (let ((xwem-app-collection nil))
85     (declare (special xwem-app-collection))
86
87     (mapc (lambda (app)
88             (let ((cmd (xwem-launcher-normalize-cmd app))
89                   (xwem-app-collect-wait t))
90               (declare (special xwem-app-collect-wait))
91               (xwem-manda-add-expectance
92                `(appcollect (xwem-appcollect-op ,(or operation 'and) xwem-appcollect-params ,(or params '(class))
93                              xwem-appcollect-app-name ,app)
94                             (eval t)) 120)
95               (xwem-execute-program cmd)
96               (while xwem-app-collect-wait
97                 (dispatch-event (next-event)))))
98           app-names)
99     
100     (nreverse xwem-app-collection)))
101
102 \f
103 (provide 'xwem-appcollect)
104
105 ;;; xwem-appcollect.el ends here