summaryrefslogtreecommitdiff
path: root/gui/misc.c
blob: 9ec09b23bc20e80915ed1e960e9634d5f8f3c742 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* GDM - The GNOME Display Manager - misc functions
 * Copyright (C) 1998, 1999, 2000 Martin K, Petersen <mkp@mkp.net>
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <gtk/gtk.h>
#include <glade/glade.h>
#include <string.h>
#include <stdio.h>

#include "misc.h"
#include "gdmconfig.h"

#define INDEX_FILE1 "index.theme"
#define INDEX_FILE2 "index.theme.disabled"

static char *
gdm_get_font (const char *theme_name)
{
	char *font_name;
	char *theme_dir;
	char *file_name;
	char buf[512];
	GtkStyle *style;
	FILE *fp;

	style = gtk_widget_get_default_style ();
	font_name = pango_font_description_to_string (style->font_desc);

	theme_dir = gtk_rc_get_theme_dir ();
	file_name = g_build_filename (theme_dir, theme_name, INDEX_FILE1, NULL);
	if ( ! g_file_test (file_name, G_FILE_TEST_EXISTS)) {
		g_free (file_name);
		file_name = g_build_filename (theme_dir, theme_name, INDEX_FILE2, NULL);
		if ( ! g_file_test (file_name, G_FILE_TEST_EXISTS)) {
			g_free (theme_dir);
			g_free (file_name);
			return font_name;
		}
	} 
	g_free (theme_dir);

	/*
	 * FIXME: this is evil!
	 */
	fp = fopen (file_name, "r");
	if (fp != NULL) {
		while (fgets (buf, 512, fp) != NULL) {
			if (strncmp ("ApplicationFont", buf, 15) == 0) {
				char *tmp_name;
				tmp_name = strchr (buf, '=');

				if (tmp_name != NULL) {
					g_free (font_name);
					font_name = strdup (tmp_name + 1);
				}

				fclose (fp);
				g_free (file_name);
				return font_name;
			}
		}
		fclose (fp);
	}
	g_free (file_name);
	return font_name;
}

/* perhaps needs to do something like:
    login_window_resize (FALSE);
    gdm_wm_center_window (GTK_WINDOW (login));
   after calling if doing during runtime
  */
void
gdm_set_theme (const char *theme_name)
{
	char *font_name;
	GtkSettings *settings = gtk_settings_get_default ();

	font_name = gdm_get_font (theme_name);

	gtk_settings_set_string_property (settings,
					  "gtk-theme-name", theme_name, "gdm");
	gtk_settings_set_string_property (settings,
					  "gtk-font-name", font_name, "gdm");
	g_free (font_name);
}

gboolean
gdm_working_command_exists (const char *commands)
{
	char *command = ve_get_first_working_command
		(commands, TRUE /* only_existance */);
	if (command == NULL)
		return FALSE;
	g_free (command);
	return TRUE;
}


/* EOF */