appearanceObserver doesn't create icon again
[wmaker-crm.git] / WPrefs.app / Themes.c
blob453dd5c92d2c1e1624e96f0bebe0e3dc7f4d0f20
1 /* Themes.c- Theme stuff
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "WPrefs.h"
24 #include <unistd.h>
26 typedef struct _Panel {
27 WMBox *box;
29 char *sectionName;
31 CallbackRec callbacks;
33 WMWidget *parent;
35 WMButton *saveB;
36 WMList *list;
37 WMButton *loadB;
38 WMButton *instB;
40 WMFrame *totF;
41 WMButton *totB;
42 WMLabel *totL;
44 WMFrame *botF;
45 WMButton *botB;
46 WMLabel *botL;
48 pid_t tilePID;
49 pid_t barPID;
50 } _Panel;
52 #define ICON_FILE "theme"
54 static void showData(_Panel * panel)
59 static void finishedTileDownload(void *data)
61 _Panel *panel = (_Panel *) data;
63 WMSetButtonText(panel->totB, _("Set"));
64 panel->tilePID = 0;
67 static void finishedBarDownload(void *data)
69 _Panel *panel = (_Panel *) data;
71 WMSetButtonText(panel->botB, _("Set"));
72 panel->barPID = 0;
75 static pid_t downloadFile(WMScreen * scr, _Panel * panel, char *file)
77 pid_t pid;
79 pid = fork();
80 if (pid < 0) {
81 werror("could not fork() process");
83 WMRunAlertPanel(scr, GetWindow(panel), _("Error"),
84 "Could not start download. fork() failed", _("OK"), NULL, NULL);
85 return -1;
87 if (pid != 0) {
88 return pid;
91 close(ConnectionNumber(WMScreenDisplay(scr)));
93 exit(1);
96 static void downloadCallback(WMWidget * w, void *data)
98 _Panel *panel = (_Panel *) data;
99 pid_t newPid;
100 WMButton *button = (WMButton *) w;
101 pid_t *pid;
103 if (button == panel->totB) {
104 pid = &panel->tilePID;
105 } else {
106 pid = &panel->barPID;
109 if (*pid == 0) {
110 newPid = downloadFile(WMWidgetScreen(w), panel, NULL);
111 if (newPid < 0) {
112 return;
114 WMSetButtonText(button, _("Stop"));
116 if (button == panel->totB) {
117 AddDeadChildHandler(newPid, finishedTileDownload, data);
118 } else {
119 AddDeadChildHandler(newPid, finishedBarDownload, data);
121 *pid = newPid;
122 } else {
123 *pid = 0;
125 WMSetButtonText(button, _("Download"));
129 static void createPanel(Panel * p)
131 _Panel *panel = (_Panel *) p;
133 panel->box = WMCreateBox(panel->parent);
134 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
136 panel->saveB = WMCreateCommandButton(panel->box);
137 WMResizeWidget(panel->saveB, 154, 24);
138 WMMoveWidget(panel->saveB, 15, 10);
139 WMSetButtonText(panel->saveB, _("Save Current Theme"));
141 panel->list = WMCreateList(panel->box);
142 WMResizeWidget(panel->list, 154, 150);
143 WMMoveWidget(panel->list, 15, 40);
145 panel->loadB = WMCreateCommandButton(panel->box);
146 WMResizeWidget(panel->loadB, 74, 24);
147 WMMoveWidget(panel->loadB, 15, 200);
148 WMSetButtonText(panel->loadB, _("Load"));
150 panel->instB = WMCreateCommandButton(panel->box);
151 WMResizeWidget(panel->instB, 74, 24);
152 WMMoveWidget(panel->instB, 95, 200);
153 WMSetButtonText(panel->instB, _("Install"));
155 /**************** Tile of the day ****************/
157 panel->totF = WMCreateFrame(panel->box);
158 WMResizeWidget(panel->totF, 210, 105);
159 WMMoveWidget(panel->totF, 240, 10);
160 WMSetFrameTitle(panel->totF, _("Tile of The Day"));
162 panel->totL = WMCreateLabel(panel->totF);
163 WMResizeWidget(panel->totL, 67, 67);
164 WMMoveWidget(panel->totL, 25, 25);
165 WMSetLabelRelief(panel->totL, WRSunken);
167 panel->totB = WMCreateCommandButton(panel->totF);
168 WMResizeWidget(panel->totB, 86, 24);
169 WMMoveWidget(panel->totB, 105, 45);
170 WMSetButtonText(panel->totB, _("Download"));
171 WMSetButtonAction(panel->totB, downloadCallback, panel);
173 WMMapSubwidgets(panel->totF);
175 /**************** Bar of the day ****************/
177 panel->botF = WMCreateFrame(panel->box);
178 WMResizeWidget(panel->botF, 315, 95);
179 WMMoveWidget(panel->botF, 190, 125);
180 WMSetFrameTitle(panel->botF, _("Bar of The Day"));
182 panel->botL = WMCreateLabel(panel->botF);
183 WMResizeWidget(panel->botL, 285, 32);
184 WMMoveWidget(panel->botL, 15, 20);
185 WMSetLabelRelief(panel->botL, WRSunken);
187 panel->botB = WMCreateCommandButton(panel->botF);
188 WMResizeWidget(panel->botB, 86, 24);
189 WMMoveWidget(panel->botB, 110, 60);
190 WMSetButtonText(panel->botB, _("Download"));
191 WMSetButtonAction(panel->botB, downloadCallback, panel);
193 WMMapSubwidgets(panel->botF);
195 WMRealizeWidget(panel->box);
196 WMMapSubwidgets(panel->box);
198 showData(panel);
201 static void storeData(_Panel * panel)
205 Panel *InitThemes(WMScreen * scr, WMWidget * parent)
207 _Panel *panel;
209 panel = wmalloc(sizeof(_Panel));
211 panel->sectionName = _("Themes");
213 panel->parent = parent;
215 panel->callbacks.createWidgets = createPanel;
216 panel->callbacks.updateDomain = storeData;
218 AddSection(panel, ICON_FILE);
220 return panel;