Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Themes.c
1 /* Themes.c- Theme stuff
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
6 *
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.
11 *
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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
21 */
22
23 #include "WPrefs.h"
24
25 #include <unistd.h>
26
27 typedef struct _Panel {
28 WMBox *box;
29
30 char *sectionName;
31
32 CallbackRec callbacks;
33
34 WMWidget *parent;
35
36 WMButton *saveB;
37 WMList *list;
38 WMButton *loadB;
39 WMButton *instB;
40
41 WMFrame *totF;
42 WMButton *totB;
43 WMLabel *totL;
44
45 WMFrame *botF;
46 WMButton *botB;
47 WMLabel *botL;
48
49 pid_t tilePID;
50 pid_t barPID;
51 } _Panel;
52
53 #define ICON_FILE "theme"
54
55 static void showData(_Panel * panel)
56 {
57
58 }
59
60 static void finishedTileDownload(void *data)
61 {
62 _Panel *panel = (_Panel *) data;
63
64 WMSetButtonText(panel->totB, _("Set"));
65 panel->tilePID = 0;
66 }
67
68 static void finishedBarDownload(void *data)
69 {
70 _Panel *panel = (_Panel *) data;
71
72 WMSetButtonText(panel->botB, _("Set"));
73 panel->barPID = 0;
74 }
75
76 static pid_t downloadFile(WMScreen * scr, _Panel * panel, char *file)
77 {
78 pid_t pid;
79
80 pid = fork();
81 if (pid < 0) {
82 wsyserror("could not fork() process");
83
84 WMRunAlertPanel(scr, GetWindow(panel), _("Error"),
85 "Could not start download. fork() failed", _("OK"), NULL, NULL);
86 return -1;
87 }
88 if (pid != 0) {
89 return pid;
90 }
91
92 close(ConnectionNumber(WMScreenDisplay(scr)));
93
94 exit(1);
95 }
96
97 static void downloadCallback(WMWidget * w, void *data)
98 {
99 _Panel *panel = (_Panel *) data;
100 pid_t newPid;
101 WMButton *button = (WMButton *) w;
102 pid_t *pid;
103
104 if (button == panel->totB) {
105 pid = &panel->tilePID;
106 } else {
107 pid = &panel->barPID;
108 }
109
110 if (*pid == 0) {
111 newPid = downloadFile(WMWidgetScreen(w), panel, NULL);
112 if (newPid < 0) {
113 return;
114 }
115 WMSetButtonText(button, _("Stop"));
116
117 if (button == panel->totB) {
118 AddDeadChildHandler(newPid, finishedTileDownload, data);
119 } else {
120 AddDeadChildHandler(newPid, finishedBarDownload, data);
121 }
122 *pid = newPid;
123 } else {
124 *pid = 0;
125
126 WMSetButtonText(button, _("Download"));
127 }
128 }
129
130 static void createPanel(Panel * p)
131 {
132 _Panel *panel = (_Panel *) p;
133
134 panel->box = WMCreateBox(panel->parent);
135 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
136
137 panel->saveB = WMCreateCommandButton(panel->box);
138 WMResizeWidget(panel->saveB, 154, 24);
139 WMMoveWidget(panel->saveB, 15, 10);
140 WMSetButtonText(panel->saveB, _("Save Current Theme"));
141
142 panel->list = WMCreateList(panel->box);
143 WMResizeWidget(panel->list, 154, 150);
144 WMMoveWidget(panel->list, 15, 40);
145
146 panel->loadB = WMCreateCommandButton(panel->box);
147 WMResizeWidget(panel->loadB, 74, 24);
148 WMMoveWidget(panel->loadB, 15, 200);
149 WMSetButtonText(panel->loadB, _("Load"));
150
151 panel->instB = WMCreateCommandButton(panel->box);
152 WMResizeWidget(panel->instB, 74, 24);
153 WMMoveWidget(panel->instB, 95, 200);
154 WMSetButtonText(panel->instB, _("Install"));
155
156 /**************** Tile of the day ****************/
157
158 panel->totF = WMCreateFrame(panel->box);
159 WMResizeWidget(panel->totF, 210, 105);
160 WMMoveWidget(panel->totF, 240, 10);
161 WMSetFrameTitle(panel->totF, _("Tile of The Day"));
162
163 panel->totL = WMCreateLabel(panel->totF);
164 WMResizeWidget(panel->totL, 67, 67);
165 WMMoveWidget(panel->totL, 25, 25);
166 WMSetLabelRelief(panel->totL, WRSunken);
167
168 panel->totB = WMCreateCommandButton(panel->totF);
169 WMResizeWidget(panel->totB, 86, 24);
170 WMMoveWidget(panel->totB, 105, 45);
171 WMSetButtonText(panel->totB, _("Download"));
172 WMSetButtonAction(panel->totB, downloadCallback, panel);
173
174 WMMapSubwidgets(panel->totF);
175
176 /**************** Bar of the day ****************/
177
178 panel->botF = WMCreateFrame(panel->box);
179 WMResizeWidget(panel->botF, 315, 95);
180 WMMoveWidget(panel->botF, 190, 125);
181 WMSetFrameTitle(panel->botF, _("Bar of The Day"));
182
183 panel->botL = WMCreateLabel(panel->botF);
184 WMResizeWidget(panel->botL, 285, 32);
185 WMMoveWidget(panel->botL, 15, 20);
186 WMSetLabelRelief(panel->botL, WRSunken);
187
188 panel->botB = WMCreateCommandButton(panel->botF);
189 WMResizeWidget(panel->botB, 86, 24);
190 WMMoveWidget(panel->botB, 110, 60);
191 WMSetButtonText(panel->botB, _("Download"));
192 WMSetButtonAction(panel->botB, downloadCallback, panel);
193
194 WMMapSubwidgets(panel->botF);
195
196 WMRealizeWidget(panel->box);
197 WMMapSubwidgets(panel->box);
198
199 showData(panel);
200 }
201
202 static void storeData(_Panel * panel)
203 {
204 }
205
206 Panel *InitThemes(WMScreen * scr, WMWidget * parent)
207 {
208 _Panel *panel;
209
210 panel = wmalloc(sizeof(_Panel));
211 memset(panel, 0, sizeof(_Panel));
212
213 panel->sectionName = _("Themes");
214
215 panel->parent = parent;
216
217 panel->callbacks.createWidgets = createPanel;
218 panel->callbacks.updateDomain = storeData;
219
220 AddSection(panel, ICON_FILE);
221
222 return panel;
223 }