Files
wmaker/WPrefs.app/Themes.c
T

222 lines
5.1 KiB
C
Raw Normal View History

1999-01-06 15:22:33 +00:00
/* Themes.c- Theme stuff
2004-10-12 21:28:27 +00:00
*
1999-01-06 15:22:33 +00:00
* WPrefs - Window Maker Preferences Program
2004-10-12 21:28:27 +00:00
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1998-2003 Alfredo K. Kojima
2004-10-12 21:28:27 +00:00
*
1999-01-06 15:22:33 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1999-01-06 15:22:33 +00:00
*/
#include "WPrefs.h"
#include <unistd.h>
typedef struct _Panel {
2009-08-20 00:59:40 +02:00
WMBox *box;
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
char *sectionName;
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
CallbackRec callbacks;
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMWidget *parent;
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
WMButton *saveB;
WMList *list;
WMButton *loadB;
WMButton *instB;
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMFrame *totF;
WMButton *totB;
WMLabel *totL;
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMFrame *botF;
WMButton *botB;
WMLabel *botL;
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
pid_t tilePID;
pid_t barPID;
1999-01-06 15:22:33 +00:00
} _Panel;
#define ICON_FILE "theme"
2009-08-20 00:59:40 +02:00
static void showData(_Panel * panel)
1999-01-06 15:22:33 +00:00
{
}
2009-08-20 00:59:40 +02:00
static void finishedTileDownload(void *data)
1999-01-06 15:22:33 +00:00
{
2009-08-20 00:59:40 +02:00
_Panel *panel = (_Panel *) data;
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
WMSetButtonText(panel->totB, _("Set"));
panel->tilePID = 0;
1999-01-06 15:22:33 +00:00
}
2009-08-20 00:59:40 +02:00
static void finishedBarDownload(void *data)
1999-01-06 15:22:33 +00:00
{
2009-08-20 00:59:40 +02:00
_Panel *panel = (_Panel *) data;
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
WMSetButtonText(panel->botB, _("Set"));
panel->barPID = 0;
1999-01-06 15:22:33 +00:00
}
static pid_t downloadFile(WMScreen * scr, _Panel * panel, const char *file)
1999-01-06 15:22:33 +00:00
{
2009-08-20 00:59:40 +02:00
pid_t pid;
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
pid = fork();
if (pid < 0) {
werror("could not fork() process");
1999-01-06 15:22:33 +00:00
2014-01-31 20:07:57 +01:00
WMRunAlertPanel(scr, GetWindow(), _("Error"),
2009-08-20 00:59:40 +02:00
"Could not start download. fork() failed", _("OK"), NULL, NULL);
return -1;
}
if (pid != 0) {
return pid;
}
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
close(ConnectionNumber(WMScreenDisplay(scr)));
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
exit(1);
1999-01-06 15:22:33 +00:00
}
2009-08-20 00:59:40 +02:00
static void downloadCallback(WMWidget * w, void *data)
1999-01-06 15:22:33 +00:00
{
2009-08-20 00:59:40 +02:00
_Panel *panel = (_Panel *) data;
pid_t newPid;
WMButton *button = (WMButton *) w;
pid_t *pid;
if (button == panel->totB) {
pid = &panel->tilePID;
} else {
pid = &panel->barPID;
}
if (*pid == 0) {
newPid = downloadFile(WMWidgetScreen(w), panel, NULL);
if (newPid < 0) {
return;
}
WMSetButtonText(button, _("Stop"));
if (button == panel->totB) {
AddDeadChildHandler(newPid, finishedTileDownload, data);
} else {
AddDeadChildHandler(newPid, finishedBarDownload, data);
}
*pid = newPid;
} else {
*pid = 0;
WMSetButtonText(button, _("Download"));
}
1999-01-06 15:22:33 +00:00
}
2009-08-20 00:59:40 +02:00
static void createPanel(Panel * p)
1999-01-06 15:22:33 +00:00
{
2009-08-20 00:59:40 +02:00
_Panel *panel = (_Panel *) p;
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel->box = WMCreateBox(panel->parent);
WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel->saveB = WMCreateCommandButton(panel->box);
WMResizeWidget(panel->saveB, 154, 24);
WMMoveWidget(panel->saveB, 15, 10);
WMSetButtonText(panel->saveB, _("Save Current Theme"));
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel->list = WMCreateList(panel->box);
WMResizeWidget(panel->list, 154, 150);
WMMoveWidget(panel->list, 15, 40);
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel->loadB = WMCreateCommandButton(panel->box);
WMResizeWidget(panel->loadB, 74, 24);
WMMoveWidget(panel->loadB, 15, 200);
WMSetButtonText(panel->loadB, _("Load"));
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel->instB = WMCreateCommandButton(panel->box);
WMResizeWidget(panel->instB, 74, 24);
WMMoveWidget(panel->instB, 95, 200);
WMSetButtonText(panel->instB, _("Install"));
2004-10-12 21:28:27 +00:00
1999-01-06 15:22:33 +00:00
/**************** Tile of the day ****************/
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->totF = WMCreateFrame(panel->box);
WMResizeWidget(panel->totF, 210, 105);
WMMoveWidget(panel->totF, 240, 10);
WMSetFrameTitle(panel->totF, _("Tile of The Day"));
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel->totL = WMCreateLabel(panel->totF);
WMResizeWidget(panel->totL, 67, 67);
WMMoveWidget(panel->totL, 25, 25);
WMSetLabelRelief(panel->totL, WRSunken);
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel->totB = WMCreateCommandButton(panel->totF);
WMResizeWidget(panel->totB, 86, 24);
WMMoveWidget(panel->totB, 105, 45);
WMSetButtonText(panel->totB, _("Download"));
WMSetButtonAction(panel->totB, downloadCallback, panel);
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
WMMapSubwidgets(panel->totF);
2004-10-12 21:28:27 +00:00
1999-01-06 15:22:33 +00:00
/**************** Bar of the day ****************/
2009-08-20 00:59:40 +02:00
panel->botF = WMCreateFrame(panel->box);
WMResizeWidget(panel->botF, 315, 95);
WMMoveWidget(panel->botF, 190, 125);
WMSetFrameTitle(panel->botF, _("Bar of The Day"));
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel->botL = WMCreateLabel(panel->botF);
WMResizeWidget(panel->botL, 285, 32);
WMMoveWidget(panel->botL, 15, 20);
WMSetLabelRelief(panel->botL, WRSunken);
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel->botB = WMCreateCommandButton(panel->botF);
WMResizeWidget(panel->botB, 86, 24);
WMMoveWidget(panel->botB, 110, 60);
WMSetButtonText(panel->botB, _("Download"));
WMSetButtonAction(panel->botB, downloadCallback, panel);
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
WMMapSubwidgets(panel->botF);
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
WMRealizeWidget(panel->box);
WMMapSubwidgets(panel->box);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
showData(panel);
1999-01-06 15:22:33 +00:00
}
2009-08-20 00:59:40 +02:00
static void storeData(_Panel * panel)
1999-01-06 15:22:33 +00:00
{
}
Panel *InitThemes(WMWidget *parent)
1999-01-06 15:22:33 +00:00
{
2009-08-20 00:59:40 +02:00
_Panel *panel;
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel = wmalloc(sizeof(_Panel));
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
panel->sectionName = _("Themes");
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->parent = parent;
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->callbacks.createWidgets = createPanel;
panel->callbacks.updateDomain = storeData;
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
AddSection(panel, ICON_FILE);
1999-01-06 15:22:33 +00:00
2009-08-20 00:59:40 +02:00
return panel;
1999-01-06 15:22:33 +00:00
}