update
[midnight-commander.git] / xv / xvaction.c
blobede889db92cd6547c3135f069b94689befa869bf
1 /* XView Action Icons (for Drag and Drop).
2 Copyright (C) 1995 Jakub Jelinek.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 #include <config.h>
20 #include <stdlib.h>
21 #include "setup.h"
22 #include "profile.h"
23 #include "xvmain.h"
24 #include "ext.h"
25 #include "mad.h"
27 #ifdef HAVE_XPM_SHAPE
28 #include "xvicon.h"
30 extern char *regex_command_title;
32 extern Display *dpy;
34 void add_action_icon (char *filename, char *geometry)
36 char *iconname, *title, *p, *base = x_basename (filename);
37 int x, y, z;
38 XpmIcon *icon;
40 iconname = regex_command (base, "Icon", NULL, NULL);
41 if (iconname == NULL)
42 iconname = strdup ("file.xpm");
43 if (*iconname != '/') {
44 p = copy_strings (ICONDIR, iconname, NULL);
45 free (iconname);
46 iconname = p;
48 title = regex_command_title;
49 if (title == NULL)
50 title = strdup (base);
51 else {
52 char *q, *r;
54 y = strlen (filename);
55 z = strlen (base);
56 for (q = title, x = 1; *q; q++, x++)
57 if (*q == '%') {
58 if (q [1] == 'p')
59 x += z - 2;
60 else if (q [1] == 'd')
61 x += y - 2;
63 r = xmalloc (x, "Icon Title");
64 for (q = title, p = r; *q; q++, p++)
65 if (*q == '%') {
66 if (q [1] == 'p') {
67 strcpy (p, base);
68 p += z - 1;
69 q++;
70 } else if (q [1] == 'd') {
71 strcpy (p, filename);
72 p += y - 1;
73 q++;
74 } else
75 *p = *q;
76 } else
77 *p = *q;
78 *p = 0;
79 free (title);
80 title = r;
82 x = atoi (geometry);
83 for (p = geometry; *p && (*p < '0' || *p > '9'); p++);
84 for (; *p >= '0' && *p <= '9'; p++);
85 y = atoi (p);
86 icon = CreateXpmIcon (iconname, x, y, title);
87 if (icon != NULL) {
88 icon->filename = strdup (filename);
90 free (iconname);
91 free (title);
92 XFlush (dpy);
93 xv_dispatch_a_bit ();
95 #endif
97 void xv_action_icons (void)
99 #ifdef HAVE_XPM_SHAPE
100 char *key, *value;
101 void *keys = profile_init_iterator ("Action Icons", profile_name);
103 xv_dispatch_a_bit ();
104 if (keys == NULL) {
105 add_action_icon ("/bin/rm", "+45+100");
106 add_action_icon ("/usr/bin/lpr", "+45+160");
109 while (keys != NULL) {
110 keys = profile_iterator_next (keys, &key, &value);
111 add_action_icon (key, value);
113 #endif