Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Themes.c
blobb42c49570957721c0de039c89ca683f250e26283
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
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.
23 #include "WPrefs.h"
25 #include <unistd.h>
27 typedef struct _Panel {
28 WMBox *box;
30 char *sectionName;
32 CallbackRec callbacks;
34 WMWidget *parent;
36 WMButton *saveB;
37 WMList *list;
38 WMButton *loadB;
39 WMButton *instB;
41 WMFrame *totF;
42 WMButton *totB;
43 WMLabel *totL;
45 WMFrame *botF;
46 WMButton *botB;
47 WMLabel *botL;
49 pid_t tilePID;
50 pid_t barPID;
51 } _Panel;
53 #define ICON_FILE "theme"
55 static void showData(_Panel * panel)
60 static void finishedTileDownload(void *data)
62 _Panel *panel = (_Panel *) data;
64 WMSetButtonText(panel->totB, _("Set"));
65 panel->tilePID = 0;
68 static void finishedBarDownload(void *data)
70 _Panel *panel = (_Panel *) data;
72 WMSetButtonText(panel->botB, _("Set"));
73 panel->barPID = 0;
76 static pid_t downloadFile(WMScreen * scr, _Panel * panel, char *file)
78 pid_t pid;
80 pid = fork();
81 if (pid < 0) {
82 wsyserror("could not fork() process");
84 WMRunAlertPanel(scr, GetWindow(panel), _("Error"),
85 "Could not start download. fork() failed", _("OK"), NULL, NULL);
86 return -1;
88 if (pid != 0) {
89 return pid;
92 close(ConnectionNumber(WMScreenDisplay(scr)));
94 exit(1);
97 static void downloadCallback(WMWidget * w, void *data)
99 _Panel *panel = (_Panel *) data;
100 pid_t newPid;
101 WMButton *button = (WMButton *) w;
102 pid_t *pid;
104 if (button == panel->totB) {
105 pid = &panel->tilePID;
106 } else {
107 pid = &panel->barPID;
110 if (*pid == 0) {
111 newPid = downloadFile(WMWidgetScreen(w), panel, NULL);
112 if (newPid < 0) {
113 return;
115 WMSetButtonText(button, _("Stop"));
117 if (button == panel->totB) {
118 AddDeadChildHandler(newPid, finishedTileDownload, data);
119 } else {
120 AddDeadChildHandler(newPid, finishedBarDownload, data);
122 *pid = newPid;
123 } else {
124 *pid = 0;
126 WMSetButtonText(button, _("Download"));
130 static void createPanel(Panel * p)
132 _Panel *panel = (_Panel *) p;
134 panel->box = WMCreateBox(panel->parent);
135 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
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"));
142 panel->list = WMCreateList(panel->box);
143 WMResizeWidget(panel->list, 154, 150);
144 WMMoveWidget(panel->list, 15, 40);
146 panel->loadB = WMCreateCommandButton(panel->box);
147 WMResizeWidget(panel->loadB, 74, 24);
148 WMMoveWidget(panel->loadB, 15, 200);
149 WMSetButtonText(panel->loadB, _("Load"));
151 panel->instB = WMCreateCommandButton(panel->box);
152 WMResizeWidget(panel->instB, 74, 24);
153 WMMoveWidget(panel->instB, 95, 200);
154 WMSetButtonText(panel->instB, _("Install"));
156 /**************** Tile of the day ****************/
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"));
163 panel->totL = WMCreateLabel(panel->totF);
164 WMResizeWidget(panel->totL, 67, 67);
165 WMMoveWidget(panel->totL, 25, 25);
166 WMSetLabelRelief(panel->totL, WRSunken);
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);
174 WMMapSubwidgets(panel->totF);
176 /**************** Bar of the day ****************/
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"));
183 panel->botL = WMCreateLabel(panel->botF);
184 WMResizeWidget(panel->botL, 285, 32);
185 WMMoveWidget(panel->botL, 15, 20);
186 WMSetLabelRelief(panel->botL, WRSunken);
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);
194 WMMapSubwidgets(panel->botF);
196 WMRealizeWidget(panel->box);
197 WMMapSubwidgets(panel->box);
199 showData(panel);
202 static void storeData(_Panel * panel)
206 Panel *InitThemes(WMScreen * scr, WMWidget * parent)
208 _Panel *panel;
210 panel = wmalloc(sizeof(_Panel));
211 memset(panel, 0, sizeof(_Panel));
213 panel->sectionName = _("Themes");
215 panel->parent = parent;
217 panel->callbacks.createWidgets = createPanel;
218 panel->callbacks.updateDomain = storeData;
220 AddSection(panel, ICON_FILE);
222 return panel;