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 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.
20  */
21 
22 #include "WPrefs.h"
23 
24 #include <unistd.h>
25 
26 typedef struct _Panel {
27 	WMBox *box;
28 
29 	char *sectionName;
30 
31 	CallbackRec callbacks;
32 
33 	WMWidget *parent;
34 
35 	WMButton *saveB;
36 	WMList *list;
37 	WMButton *loadB;
38 	WMButton *instB;
39 
40 	WMFrame *totF;
41 	WMButton *totB;
42 	WMLabel *totL;
43 
44 	WMFrame *botF;
45 	WMButton *botB;
46 	WMLabel *botL;
47 
48 	pid_t tilePID;
49 	pid_t barPID;
50 } _Panel;
51 
52 #define ICON_FILE	"theme"
53 
showData(_Panel * panel)54 static void showData(_Panel * panel)
55 {
56 
57 }
58 
finishedTileDownload(void * data)59 static void finishedTileDownload(void *data)
60 {
61 	_Panel *panel = (_Panel *) data;
62 
63 	WMSetButtonText(panel->totB, _("Set"));
64 	panel->tilePID = 0;
65 }
66 
finishedBarDownload(void * data)67 static void finishedBarDownload(void *data)
68 {
69 	_Panel *panel = (_Panel *) data;
70 
71 	WMSetButtonText(panel->botB, _("Set"));
72 	panel->barPID = 0;
73 }
74 
downloadFile(WMScreen * scr,_Panel * panel,const char * file)75 static pid_t downloadFile(WMScreen * scr, _Panel * panel, const char *file)
76 {
77 	pid_t pid;
78 
79 	pid = fork();
80 	if (pid < 0) {
81 		werror("could not fork() process");
82 
83 		WMRunAlertPanel(scr, GetWindow(), _("Error"),
84 				"Could not start download. fork() failed", _("OK"), NULL, NULL);
85 		return -1;
86 	}
87 	if (pid != 0) {
88 		return pid;
89 	}
90 
91 	close(ConnectionNumber(WMScreenDisplay(scr)));
92 
93 	exit(1);
94 }
95 
downloadCallback(WMWidget * w,void * data)96 static void downloadCallback(WMWidget * w, void *data)
97 {
98 	_Panel *panel = (_Panel *) data;
99 	pid_t newPid;
100 	WMButton *button = (WMButton *) w;
101 	pid_t *pid;
102 
103 	if (button == panel->totB) {
104 		pid = &panel->tilePID;
105 	} else {
106 		pid = &panel->barPID;
107 	}
108 
109 	if (*pid == 0) {
110 		newPid = downloadFile(WMWidgetScreen(w), panel, NULL);
111 		if (newPid < 0) {
112 			return;
113 		}
114 		WMSetButtonText(button, _("Stop"));
115 
116 		if (button == panel->totB) {
117 			AddDeadChildHandler(newPid, finishedTileDownload, data);
118 		} else {
119 			AddDeadChildHandler(newPid, finishedBarDownload, data);
120 		}
121 		*pid = newPid;
122 	} else {
123 		*pid = 0;
124 
125 		WMSetButtonText(button, _("Download"));
126 	}
127 }
128 
createPanel(Panel * p)129 static void createPanel(Panel * p)
130 {
131 	_Panel *panel = (_Panel *) p;
132 
133 	panel->box = WMCreateBox(panel->parent);
134 	WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
135 
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"));
140 
141 	panel->list = WMCreateList(panel->box);
142 	WMResizeWidget(panel->list, 154, 150);
143 	WMMoveWidget(panel->list, 15, 40);
144 
145 	panel->loadB = WMCreateCommandButton(panel->box);
146 	WMResizeWidget(panel->loadB, 74, 24);
147 	WMMoveWidget(panel->loadB, 15, 200);
148 	WMSetButtonText(panel->loadB, _("Load"));
149 
150 	panel->instB = WMCreateCommandButton(panel->box);
151 	WMResizeWidget(panel->instB, 74, 24);
152 	WMMoveWidget(panel->instB, 95, 200);
153 	WMSetButtonText(panel->instB, _("Install"));
154 
155     /**************** Tile of the day ****************/
156 
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"));
161 
162 	panel->totL = WMCreateLabel(panel->totF);
163 	WMResizeWidget(panel->totL, 67, 67);
164 	WMMoveWidget(panel->totL, 25, 25);
165 	WMSetLabelRelief(panel->totL, WRSunken);
166 
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);
172 
173 	WMMapSubwidgets(panel->totF);
174 
175     /**************** Bar of the day ****************/
176 
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"));
181 
182 	panel->botL = WMCreateLabel(panel->botF);
183 	WMResizeWidget(panel->botL, 285, 32);
184 	WMMoveWidget(panel->botL, 15, 20);
185 	WMSetLabelRelief(panel->botL, WRSunken);
186 
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);
192 
193 	WMMapSubwidgets(panel->botF);
194 
195 	WMRealizeWidget(panel->box);
196 	WMMapSubwidgets(panel->box);
197 
198 	showData(panel);
199 }
200 
storeData(_Panel * panel)201 static void storeData(_Panel * panel)
202 {
203 }
204 
InitThemes(WMWidget * parent)205 Panel *InitThemes(WMWidget *parent)
206 {
207 	_Panel *panel;
208 
209 	panel = wmalloc(sizeof(_Panel));
210 
211 	panel->sectionName = _("Themes");
212 
213 	panel->parent = parent;
214 
215 	panel->callbacks.createWidgets = createPanel;
216 	panel->callbacks.updateDomain = storeData;
217 
218 	AddSection(panel, ICON_FILE);
219 
220 	return panel;
221 }
222