Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Themes.c
Commit [+]AuthorDateLineData
0261c326 dan1999-01-06 15:22:33 +00001/* Themes.c- Theme stuff
6830b057 dan2004-10-12 21:28:27 +00002 *
0261c326 dan1999-01-06 15:22:33 +00003 * WPrefs - Window Maker Preferences Program
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1998-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
0261c326 dan1999-01-06 15:22:33 +00007 * 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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
0261c326 dan1999-01-06 15:22:33 +000020 * USA.
21 */
22
0261c326 dan1999-01-06 15:22:33 +000023#include "WPrefs.h"
24
25#include <unistd.h>
26
27typedef struct _Panel {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020028 WMBox *box;
0261c326 dan1999-01-06 15:22:33 +000029
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020030 char *sectionName;
0261c326 dan1999-01-06 15:22:33 +000031
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020032 CallbackRec callbacks;
6830b057 dan2004-10-12 21:28:27 +000033
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020034 WMWidget *parent;
0261c326 dan1999-01-06 15:22:33 +000035
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020036 WMButton *saveB;
37 WMList *list;
38 WMButton *loadB;
39 WMButton *instB;
6830b057 dan2004-10-12 21:28:27 +000040
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020041 WMFrame *totF;
42 WMButton *totB;
43 WMLabel *totL;
6830b057 dan2004-10-12 21:28:27 +000044
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020045 WMFrame *botF;
46 WMButton *botB;
47 WMLabel *botL;
0261c326 dan1999-01-06 15:22:33 +000048
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020049 pid_t tilePID;
50 pid_t barPID;
0261c326 dan1999-01-06 15:22:33 +000051} _Panel;
52
0261c326 dan1999-01-06 15:22:33 +000053#define ICON_FILE "theme"
54
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020055static void showData(_Panel * panel)
0261c326 dan1999-01-06 15:22:33 +000056{
57
58}
59
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020060static void finishedTileDownload(void *data)
0261c326 dan1999-01-06 15:22:33 +000061{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020062 _Panel *panel = (_Panel *) data;
0261c326 dan1999-01-06 15:22:33 +000063
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020064 WMSetButtonText(panel->totB, _("Set"));
65 panel->tilePID = 0;
0261c326 dan1999-01-06 15:22:33 +000066}
67
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020068static void finishedBarDownload(void *data)
0261c326 dan1999-01-06 15:22:33 +000069{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020070 _Panel *panel = (_Panel *) data;
0261c326 dan1999-01-06 15:22:33 +000071
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020072 WMSetButtonText(panel->botB, _("Set"));
73 panel->barPID = 0;
0261c326 dan1999-01-06 15:22:33 +000074}
75
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020076static pid_t downloadFile(WMScreen * scr, _Panel * panel, char *file)
0261c326 dan1999-01-06 15:22:33 +000077{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020078 pid_t pid;
0261c326 dan1999-01-06 15:22:33 +000079
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020080 pid = fork();
81 if (pid < 0) {
82 wsyserror("could not fork() process");
0261c326 dan1999-01-06 15:22:33 +000083
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020084 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 }
0261c326 dan1999-01-06 15:22:33 +000091
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020092 close(ConnectionNumber(WMScreenDisplay(scr)));
6830b057 dan2004-10-12 21:28:27 +000093
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020094 exit(1);
0261c326 dan1999-01-06 15:22:33 +000095}
96
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020097static void downloadCallback(WMWidget * w, void *data)
0261c326 dan1999-01-06 15:22:33 +000098{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020099 _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 }
0261c326 dan1999-01-06 15:22:33 +0000128}
129
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200130static void createPanel(Panel * p)
0261c326 dan1999-01-06 15:22:33 +0000131{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200132 _Panel *panel = (_Panel *) p;
0261c326 dan1999-01-06 15:22:33 +0000133
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200134 panel->box = WMCreateBox(panel->parent);
135 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
0261c326 dan1999-01-06 15:22:33 +0000136
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200137 panel->saveB = WMCreateCommandButton(panel->box);
138 WMResizeWidget(panel->saveB, 154, 24);
139 WMMoveWidget(panel->saveB, 15, 10);
140 WMSetButtonText(panel->saveB, _("Save Current Theme"));
0261c326 dan1999-01-06 15:22:33 +0000141
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200142 panel->list = WMCreateList(panel->box);
143 WMResizeWidget(panel->list, 154, 150);
144 WMMoveWidget(panel->list, 15, 40);
0261c326 dan1999-01-06 15:22:33 +0000145
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200146 panel->loadB = WMCreateCommandButton(panel->box);
147 WMResizeWidget(panel->loadB, 74, 24);
148 WMMoveWidget(panel->loadB, 15, 200);
149 WMSetButtonText(panel->loadB, _("Load"));
0261c326 dan1999-01-06 15:22:33 +0000150
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200151 panel->instB = WMCreateCommandButton(panel->box);
152 WMResizeWidget(panel->instB, 74, 24);
153 WMMoveWidget(panel->instB, 95, 200);
154 WMSetButtonText(panel->instB, _("Install"));
6830b057 dan2004-10-12 21:28:27 +0000155
0261c326 dan1999-01-06 15:22:33 +0000156 /**************** Tile of the day ****************/
6830b057 dan2004-10-12 21:28:27 +0000157
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200158 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"));
0261c326 dan1999-01-06 15:22:33 +0000162
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200163 panel->totL = WMCreateLabel(panel->totF);
164 WMResizeWidget(panel->totL, 67, 67);
165 WMMoveWidget(panel->totL, 25, 25);
166 WMSetLabelRelief(panel->totL, WRSunken);
0261c326 dan1999-01-06 15:22:33 +0000167
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200168 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);
0261c326 dan1999-01-06 15:22:33 +0000173
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200174 WMMapSubwidgets(panel->totF);
6830b057 dan2004-10-12 21:28:27 +0000175
0261c326 dan1999-01-06 15:22:33 +0000176 /**************** Bar of the day ****************/
177
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200178 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"));
0261c326 dan1999-01-06 15:22:33 +0000182
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200183 panel->botL = WMCreateLabel(panel->botF);
184 WMResizeWidget(panel->botL, 285, 32);
185 WMMoveWidget(panel->botL, 15, 20);
186 WMSetLabelRelief(panel->botL, WRSunken);
0261c326 dan1999-01-06 15:22:33 +0000187
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200188 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);
0261c326 dan1999-01-06 15:22:33 +0000193
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200194 WMMapSubwidgets(panel->botF);
0261c326 dan1999-01-06 15:22:33 +0000195
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200196 WMRealizeWidget(panel->box);
197 WMMapSubwidgets(panel->box);
6830b057 dan2004-10-12 21:28:27 +0000198
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200199 showData(panel);
0261c326 dan1999-01-06 15:22:33 +0000200}
201
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200202static void storeData(_Panel * panel)
0261c326 dan1999-01-06 15:22:33 +0000203{
204}
205
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200206Panel *InitThemes(WMScreen * scr, WMWidget * parent)
0261c326 dan1999-01-06 15:22:33 +0000207{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200208 _Panel *panel;
0261c326 dan1999-01-06 15:22:33 +0000209
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200210 panel = wmalloc(sizeof(_Panel));
211 memset(panel, 0, sizeof(_Panel));
0261c326 dan1999-01-06 15:22:33 +0000212
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200213 panel->sectionName = _("Themes");
6830b057 dan2004-10-12 21:28:27 +0000214
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200215 panel->parent = parent;
6830b057 dan2004-10-12 21:28:27 +0000216
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200217 panel->callbacks.createWidgets = createPanel;
218 panel->callbacks.updateDomain = storeData;
0261c326 dan1999-01-06 15:22:33 +0000219
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200220 AddSection(panel, ICON_FILE);
0261c326 dan1999-01-06 15:22:33 +0000221
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200222 return panel;
0261c326 dan1999-01-06 15:22:33 +0000223}