gnome-control-center/capplets/theme-switcher/lister.c-42011
Owen Taylor 4d6e8150b5 Add an error dialog if installing a theme fails.
Fri Mar 12 02:21:55 1999  Owen Taylor  <otaylor@redhat.com>

	* capplets/theme-switcher/gui.c (browse_dialog_close):
	Add an error dialog if installing a theme fails.

	* capplets/theme-switcher/install.c (install_theme): Add
	a return value indicating success or failure.

	* capplets/theme-switcher/install.c (install_theme):
	Fixed reversed arguments for installing ungipped tarballs

Fri Mar 12 01:12:15 1999  Owen Taylor  <otaylor@redhat.com>

	[ Patch from Patrik Nordebo <isildur@a39.ryd.student.liu.se> ]

	* capplets/theme-switcher/install.c (install_theme): Removed
	useless call to wait(). Install themes in .themes,
	not .gtk/themes.

Fri Mar 12 01:06:53 1999  Owen Taylor  <otaylor@redhat.com>

	* capplets/theme-switcher/lister.c (edit_file_to_use): Fixed
	reversed lines that were causing initial creation
	not to work properly.

	* capplets/theme-switcher/demo.c (send_reread): You
	can't fsync() a pipe...

	* capplets/theme-switcher/gui.c: Don't select list
	items before they are added to the list ... removed
	hack that sort of worked around this.

	* capplets/theme-switcher/gui.c (make_main): Major
	un-rasterization. (Sort of a shame, this was some
	of the funniest code I've ever seen.)

	* capplets/theme-switcher/gui.c (install_theme_callback):
	Removed non-functional transient-for code.

	* capplets/theme-switcher/demo.c (demo_data_in): Removed
	brutal, unreliable kill -9 in favor of noticing when
	the IPC pipe closes.

	* capplets/theme-switcher/demo.c (demo_main): Solved
	problem where dup2() was going astray by not using it.

	* capplets/theme-switcher/gui.c (update_theme_entries): Fix
	cut-and-paste typo.
1999-03-12 07:28:19 +00:00

181 lines
3.8 KiB
Text

#include "da.h"
#include <sys/types.h>
#include <utime.h>
void
edit_file_to_use(gchar *file, gchar *theme)
{
FILE *fin, *fout;
gchar tmp[4096], buf[4096];
gchar nextline = 0, hastheme = 0;
srand(time(NULL));
g_snprintf(tmp, sizeof(tmp), "/tmp/gtkrc_%i", rand());
fout = fopen(tmp, "w");
if (!fout)
return;
fin = fopen(file, "r");
if (!fin)
{
fprintf(fout, "# -- THEME AUTO-WRITTEN DO NOT EDIT\n");
fprintf(fout, "include \"%s\"\n\n", theme);
fclose(fout);
cp(tmp, file);
return;
}
while (fgets(buf, sizeof(buf), fin))
{
if (!strcmp("# -- THEME AUTO-WRITTEN DO NOT EDIT\n", buf))
hastheme = 1;
}
rewind(fin);
if (!hastheme)
{
fprintf(fout, "# -- THEME AUTO-WRITTEN DO NOT EDIT\n");
fprintf(fout, "include \"%s\"\n\n", theme);
while (fgets(buf, sizeof(buf), fin))
fprintf(fout, "%s", buf);
}
else
{
while (fgets(buf, sizeof(buf), fin))
{
if (!nextline)
fprintf(fout, "%s", buf);
else
{
nextline = 0;
fprintf(fout, "include \"%s\"\n\n", theme);
}
if (!strcmp("# -- THEME AUTO-WRITTEN DO NOT EDIT\n", buf))
nextline = 1;
}
}
fclose(fin);
fclose(fout);
cp(tmp, file);
rm(tmp);
}
void
set_tmp_rc(void)
{
gchar s[4096], *home;
home = g_get_home_dir ();
if (!home)
return;
g_snprintf(s, sizeof(s), "%s/.gtkrc", home);
srand(time(NULL));
g_snprintf(gtkrc_tmp, sizeof(gtkrc_tmp), "/tmp/%i-gtkrc-%i", time(NULL), rand());
cp(s, gtkrc_tmp);
}
void
use_theme(gchar *theme)
{
gchar s[4096], *home;
home = g_get_home_dir ();
if (!home)
return;
g_snprintf(s, sizeof(s), "%s/.gtkrc", home);
edit_file_to_use(s, theme);
}
void
test_theme(gchar *theme)
{
static time_t last_written_time = 0;
time_t current_time = time (NULL);
struct utimbuf buf;
edit_file_to_use(gtkrc_tmp, theme);
if (last_written_time >= current_time)
{
current_time = last_written_time + 1;
buf.actime = current_time;
buf.modtime = current_time;
utime (gtkrc_tmp, &buf);
}
last_written_time = current_time;
}
void
free_theme_list(ThemeEntry *list, gint number)
{
gint i;
for(i = 0; i < number; i++)
{
g_free(list[i].name);
g_free(list[i].rc);
g_free(list[i].readme);
g_free(list[i].icon);
}
g_free(list);
}
ThemeEntry *
list_themes(gchar *dir, gint *number)
{
gchar **dir_listing = NULL, tmp[4096];
ThemeEntry *list = NULL;
gint i = 0, j = 0, num = 0;
dir_listing = ls(dir, &num);
for(i = 0; i < num; i++)
{
g_snprintf(tmp, sizeof(tmp), "%s/%s/gtk/gtkrc", dir, dir_listing[i]);
if (isfile(tmp))
{
list = g_realloc(list, sizeof(ThemeEntry) * ++j);
list[j - 1].name = g_strdup(dir_listing[i]);
list[j - 1].rc = g_strdup(tmp);
g_snprintf(tmp, sizeof(tmp), "%s/%s", dir, dir_listing[i]);
list[j - 1].dir = g_strdup(tmp);
g_snprintf(tmp, sizeof(tmp), "%s/%s/README.html", dir, dir_listing[i]);
list[j - 1].readme = g_strdup(tmp);
g_snprintf(tmp, sizeof(tmp), "%s/%s/ICON.png", dir, dir_listing[i]);
list[j - 1].icon = g_strdup(tmp);
}
}
freestrlist(dir_listing, num);
*number = j;
return list;
}
ThemeEntry *
list_system_themes(gint *number)
{
gchar *theme_dir = NULL;
ThemeEntry *list = NULL;
theme_dir = gtk_rc_get_theme_dir();
list = list_themes(theme_dir, number);
g_free(theme_dir);
return list;
}
ThemeEntry *
list_user_themes(gint *number)
{
gchar *home = NULL;
gchar *theme_dir = NULL;
ThemeEntry *list = NULL;
home = g_get_home_dir ();
if (!home)
return NULL;
if (!isdir(home))
return NULL;
theme_dir = g_malloc(strlen(home) + strlen("/.themes") + 1);
sprintf(theme_dir, "%s%s", home, "/.themes");
list = list_themes(theme_dir, number);
g_free(theme_dir);
return list;
}