1998-09-23 02:39:17 +00:00
|
|
|
#include "da.h"
|
1999-02-23 19:05:46 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <utime.h>
|
1999-04-01 00:58:38 +00:00
|
|
|
#define MARK_STRING "# -- THEME AUTO-WRITTEN DO NOT EDIT\n"
|
|
|
|
static void
|
|
|
|
print_standard_stuff(FILE *fout, gchar *theme, gchar *font)
|
|
|
|
{
|
1999-06-22 17:32:50 +00:00
|
|
|
gchar *homedir;
|
|
|
|
|
|
|
|
homedir = g_strconcat ("include \"",
|
|
|
|
gnome_util_user_home(),
|
|
|
|
"/.gtkrc.mine\"\n\n", NULL);
|
1999-04-01 00:58:38 +00:00
|
|
|
fprintf(fout, MARK_STRING);
|
|
|
|
fprintf(fout, "include \"%s\"\n\n", theme);
|
|
|
|
if (font)
|
|
|
|
fprintf(fout, "style \"user-font\"\n{\n font=\"%s\"\n}\nwidget_class \"*\" style \"user-font\"\n\n", font);
|
1999-06-22 17:32:50 +00:00
|
|
|
fprintf(fout, homedir);
|
|
|
|
g_free (homedir);
|
1999-04-01 00:58:38 +00:00
|
|
|
fprintf(fout, MARK_STRING);
|
|
|
|
}
|
1998-09-23 02:39:17 +00:00
|
|
|
void
|
1999-04-01 00:58:38 +00:00
|
|
|
edit_file_to_use(gchar *file, gchar *theme, gchar *font)
|
1998-09-23 02:39:17 +00:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
1999-04-01 00:58:38 +00:00
|
|
|
print_standard_stuff (fout, theme, font);
|
1998-09-23 02:39:17 +00:00
|
|
|
fclose(fout);
|
1999-03-12 07:28:19 +00:00
|
|
|
cp(tmp, file);
|
1998-09-23 02:39:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (fgets(buf, sizeof(buf), fin))
|
1999-04-01 00:58:38 +00:00
|
|
|
{
|
2001-10-13 19:19:16 +00:00
|
|
|
buf[sizeof(buf)-1] = '\0'; /* Be paranoid */
|
1999-04-01 00:58:38 +00:00
|
|
|
if (!strcmp(MARK_STRING, buf))
|
|
|
|
hastheme += 1;
|
1998-09-23 02:39:17 +00:00
|
|
|
}
|
|
|
|
rewind(fin);
|
|
|
|
if (!hastheme)
|
|
|
|
{
|
1999-04-01 00:58:38 +00:00
|
|
|
print_standard_stuff (fout, theme, font);
|
1998-09-23 02:39:17 +00:00
|
|
|
while (fgets(buf, sizeof(buf), fin))
|
|
|
|
fprintf(fout, "%s", buf);
|
|
|
|
}
|
1999-04-01 00:58:38 +00:00
|
|
|
else if (hastheme == 1)
|
|
|
|
/* we keep this in for backwards compatability. */
|
1998-09-23 02:39:17 +00:00
|
|
|
{
|
1999-04-01 00:58:38 +00:00
|
|
|
nextline = 0;
|
1998-09-23 02:39:17 +00:00
|
|
|
while (fgets(buf, sizeof(buf), fin))
|
|
|
|
{
|
2001-10-13 19:19:16 +00:00
|
|
|
buf[sizeof(buf)-1] = '\0'; /* Be paranoid */
|
1999-04-01 00:58:38 +00:00
|
|
|
if (nextline == 1)
|
|
|
|
nextline = 0;
|
|
|
|
else if (!strcmp(MARK_STRING, buf))
|
1998-09-23 02:39:17 +00:00
|
|
|
{
|
1999-04-01 00:58:38 +00:00
|
|
|
print_standard_stuff (fout, theme, font);
|
|
|
|
nextline = 1;
|
1998-09-23 02:39:17 +00:00
|
|
|
}
|
1999-04-01 00:58:38 +00:00
|
|
|
else if (nextline == 0)
|
|
|
|
fprintf(fout, "%s", buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nextline = 0;
|
|
|
|
while (fgets(buf, sizeof(buf), fin))
|
|
|
|
{
|
2001-10-13 19:19:16 +00:00
|
|
|
buf[sizeof(buf)-1] = '\0'; /* Be paranoid */
|
1999-04-01 00:58:38 +00:00
|
|
|
if (!strcmp(MARK_STRING, buf))
|
|
|
|
{
|
|
|
|
if (nextline == 0)
|
|
|
|
{
|
|
|
|
nextline = 1;
|
|
|
|
print_standard_stuff (fout, theme, font);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nextline = 0;
|
|
|
|
}
|
|
|
|
} else if (nextline == 0)
|
|
|
|
fprintf(fout, "%s", buf);
|
1998-09-23 02:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fin);
|
|
|
|
fclose(fout);
|
|
|
|
cp(tmp, file);
|
|
|
|
rm(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-03-12 07:28:19 +00:00
|
|
|
set_tmp_rc(void)
|
1998-09-23 02:39:17 +00:00
|
|
|
{
|
|
|
|
gchar s[4096], *home;
|
|
|
|
|
1999-02-23 19:05:46 +00:00
|
|
|
home = g_get_home_dir ();
|
1998-09-23 02:39:17 +00:00
|
|
|
if (!home)
|
|
|
|
return;
|
1999-02-23 19:05:46 +00:00
|
|
|
g_snprintf(s, sizeof(s), "%s/.gtkrc", home);
|
1998-09-23 02:39:17 +00:00
|
|
|
srand(time(NULL));
|
|
|
|
g_snprintf(gtkrc_tmp, sizeof(gtkrc_tmp), "/tmp/%i-gtkrc-%i", time(NULL), rand());
|
|
|
|
cp(s, gtkrc_tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-04-01 00:58:38 +00:00
|
|
|
use_theme(gchar *theme, gchar *font)
|
1998-09-23 02:39:17 +00:00
|
|
|
{
|
|
|
|
gchar s[4096], *home;
|
|
|
|
|
1999-02-23 19:05:46 +00:00
|
|
|
home = g_get_home_dir ();
|
1998-09-23 02:39:17 +00:00
|
|
|
if (!home)
|
|
|
|
return;
|
1999-02-23 19:05:46 +00:00
|
|
|
g_snprintf(s, sizeof(s), "%s/.gtkrc", home);
|
1999-04-01 00:58:38 +00:00
|
|
|
edit_file_to_use(s, theme, font);
|
1998-09-23 02:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-04-01 00:58:38 +00:00
|
|
|
test_theme(gchar *theme, gchar *font)
|
1998-09-23 02:39:17 +00:00
|
|
|
{
|
1999-02-23 19:05:46 +00:00
|
|
|
static time_t last_written_time = 0;
|
|
|
|
time_t current_time = time (NULL);
|
|
|
|
struct utimbuf buf;
|
|
|
|
|
1999-04-01 00:58:38 +00:00
|
|
|
edit_file_to_use(gtkrc_tmp, theme, font);
|
1999-02-23 19:05:46 +00:00
|
|
|
|
|
|
|
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;
|
1998-09-23 02:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-09-29 20:45:12 +00:00
|
|
|
GList *
|
|
|
|
list_themes(gchar *dir)
|
1998-09-23 02:39:17 +00:00
|
|
|
{
|
2001-09-29 20:45:12 +00:00
|
|
|
gchar **dir_listing = NULL, *tmp;
|
|
|
|
GList *list = NULL;
|
|
|
|
gint i = 0, num = 0;
|
1998-09-23 02:39:17 +00:00
|
|
|
|
|
|
|
dir_listing = ls(dir, &num);
|
|
|
|
for(i = 0; i < num; i++)
|
|
|
|
{
|
2001-09-29 20:45:12 +00:00
|
|
|
tmp = g_strdup_printf ("%s/%s/gtk/gtkrc", dir, dir_listing[i]);
|
1998-09-23 02:39:17 +00:00
|
|
|
if (isfile(tmp))
|
|
|
|
{
|
2001-09-29 20:45:12 +00:00
|
|
|
ThemeEntry *item = g_new0 (ThemeEntry, 1);
|
|
|
|
item->name = g_strdup(dir_listing[i]);
|
|
|
|
item->rc = g_strdup (tmp);
|
|
|
|
item->dir = g_strdup_printf ("%s/%s", dir, dir_listing[i]);
|
|
|
|
item->readme = g_strdup_printf ("%s/%s/README.html", dir, dir_listing[i]);
|
|
|
|
item->icon = g_strdup_printf ("%s/%s/ICON.png", dir, dir_listing[i]);
|
|
|
|
list = g_list_prepend (list, item);
|
1998-09-23 02:39:17 +00:00
|
|
|
}
|
2001-09-29 20:45:12 +00:00
|
|
|
g_free (tmp);
|
1998-09-23 02:39:17 +00:00
|
|
|
}
|
|
|
|
freestrlist(dir_listing, num);
|
2001-09-29 20:45:12 +00:00
|
|
|
return g_list_reverse (list);
|
1998-09-23 02:39:17 +00:00
|
|
|
}
|
|
|
|
|
2001-09-29 20:45:12 +00:00
|
|
|
GList *
|
|
|
|
list_system_themes(void)
|
1998-09-23 02:39:17 +00:00
|
|
|
{
|
|
|
|
gchar *theme_dir = NULL;
|
2001-09-29 20:45:12 +00:00
|
|
|
GList *list = NULL;
|
1998-09-23 02:39:17 +00:00
|
|
|
|
|
|
|
theme_dir = gtk_rc_get_theme_dir();
|
2001-09-29 20:45:12 +00:00
|
|
|
list = list_themes(theme_dir);
|
1998-09-23 02:39:17 +00:00
|
|
|
g_free(theme_dir);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2001-09-29 20:45:12 +00:00
|
|
|
GList *
|
|
|
|
list_user_themes()
|
1998-09-23 02:39:17 +00:00
|
|
|
{
|
|
|
|
gchar *home = NULL;
|
|
|
|
gchar *theme_dir = NULL;
|
2001-09-29 20:45:12 +00:00
|
|
|
GList *list = NULL;
|
1998-09-23 02:39:17 +00:00
|
|
|
|
1999-02-23 19:05:46 +00:00
|
|
|
home = g_get_home_dir ();
|
1998-09-23 02:39:17 +00:00
|
|
|
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");
|
2001-09-29 20:45:12 +00:00
|
|
|
list = list_themes(theme_dir);
|
1998-09-23 02:39:17 +00:00
|
|
|
g_free(theme_dir);
|
|
|
|
return list;
|
|
|
|
}
|