File: gtk_fonts.c

package info (click to toggle)
cpanel 0.4.0-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,612 kB
  • ctags: 777
  • sloc: ansic: 7,931; sh: 3,099; makefile: 376; yacc: 318; perl: 68
file content (157 lines) | stat: -rw-r--r-- 4,511 bytes parent folder | download
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*****************************************************************
 *
 *   gtk_fonts.c
 *
 *     Copyright (c) 2000  Kam Tik <kamtik@hongkong.com>
 *
 *	http://debian.kamtik.net
 *
 *     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, USA.
 *
 ******************************************************************/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include "cpanel.h"
#include "defaults.h"

extern gboolean if_gb;
extern gchar gtk_font[STR_BUFFER_SIZE];
extern gchar gtk_font_gb[STR_BUFFER_SIZE];

extern gboolean if_not_warning;

GtkWidget *entry[1];

void ok_gtk_fonts(GtkWidget *button, gpointer *data)
{
	if(if_gb)
	strcpy(gtk_font_gb,gtk_entry_get_text(GTK_ENTRY(entry[0])));
	else
	strcpy(gtk_font,gtk_entry_get_text(GTK_ENTRY(entry[0])));
	if(if_gb)
	save_gtk_fonts(gtk_font_gb,1);
	else
	save_gtk_fonts(gtk_font,0);
}

void def_gtk_fonts(GtkWidget *button, gpointer *data)
{
	if(if_gb)
	gtk_entry_set_text(GTK_ENTRY(entry[0]),GTK_FONT_GB);
	else
	gtk_entry_set_text(GTK_ENTRY(entry[0]),GTK_FONT);
}

void help_gtk_fonts(GtkWidget *button, gpointer *data)
{
	show_help("gtk_fonts_opt",_("Help - Gtk+ fonts Options"),600,300);
}

void gtk_fonts_opt(GtkWidget *button, gpointer *data)
{
	/* entry[]: 0: gtk_font */
	GtkWidget *win;
	GtkWidget *vbox;
	GtkWidget *hbox;
	GtkWidget *ok_button;
	GtkWidget *cancel_button;
	GtkWidget *def_button;
	GtkWidget *help_button;
	GtkWidget *separator;

	win = make_opt_win(_("Options - Set GTK+ fonts"),button);
	vbox = gtk_vbox_new(FALSE,0);

	if(if_gb)
	hbox = make_fonts_opt(_("Set GTK+ fonts (Simplified Chinese) to: "),entry,0,gtk_font_gb, win);
	else
	hbox = make_fonts_opt(_("Set GTK+ fonts (Traditional Chinese) to: "),entry,0,gtk_font, win);

	gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,1);

	/* OK CANEL DEFAULT HELP */
	ok_button = gtk_button_new_with_label(_("OK"));
	gtk_signal_connect(GTK_OBJECT(ok_button),"clicked",
			GTK_SIGNAL_FUNC(ok_gtk_fonts),NULL);
	if(!if_not_warning)
		gtk_signal_connect(GTK_OBJECT(ok_button),"clicked",
				GTK_SIGNAL_FUNC(warning),_("Warning! The file ~/.gtkrc.zh_TW.big5 has been overwritten.\nThe old file is ~/.gtkrc.zh_TW.big5.cpanel"));

	cancel_button = gtk_button_new_with_label(_("Cancel"));

	def_button = gtk_button_new_with_label(_("Use Defaults"));
	gtk_signal_connect(GTK_OBJECT(def_button),"clicked",
			GTK_SIGNAL_FUNC(def_gtk_fonts),NULL);

	help_button = gtk_button_new_with_label(_("Help"));
	gtk_signal_connect(GTK_OBJECT(help_button),"clicked",
			GTK_SIGNAL_FUNC(help_gtk_fonts),NULL);

	/* Make buttons: make_button(ok,canel,def,help,win); */
	separator = gtk_hseparator_new();
	gtk_box_pack_start(GTK_BOX(vbox),separator,FALSE,FALSE,5);
	hbox = make_button(ok_button,cancel_button,def_button,help_button,
			win,button);
	gtk_box_pack_end(GTK_BOX(vbox),hbox,FALSE,FALSE,0);

	/* show window */
	gtk_container_add(GTK_CONTAINER(win),vbox);
	gtk_widget_show_all(win);
}

void gtk_fonts_help(GtkWidget *button, gpointer *data)
{
	show_help("gtk_fonts_help",_("Help - Set GTK+ fonts"),600,300);
}

void save_gtk_fonts(gchar *fontName, gboolean gb)
{
	FILE *f;
	gchar *path;
	
	if(gb)
	path = g_strconcat(getenv("HOME"),"/",GTK_LOCALE_FILE_NAME_GB,NULL);
	else
	path = g_strconcat(getenv("HOME"),"/",GTK_LOCALE_FILE_NAME,NULL);

	f = fopen(path,"w");
	if(!f)
	{
		fprintf(stderr,"Error saving gtk locale file: %s\n",path);
		fprintf(stderr,"Does $HOME point to your home dir??\n");
		g_free(path);
		return;
	}

	fprintf(f,"##################################################\n");
	fprintf(f,"# This file is generated by Debian Chinese Panel #\n");
	fprintf(f,"##################################################\n");
	fprintf(f,"\n");

	if(gb)
	fprintf(f,"style \"gtk-default-zh-cn\" {\n");
	else
	fprintf(f,"style \"gtk-default-zh-tw\" {\n");

	fprintf(f,"\tfontset = \"-adobe-helvetica-medium-r-normal--14-*-*-*-*-*-iso8859-*,\\\n");
	fprintf(f,"\t\t%s\"\n",fontName);
	fprintf(f,"}\n");

	if(gb)
	fprintf(f,"class \"GtkWidget\" style \"gtk-default-zh-cn\"");
	else
	fprintf(f,"class \"GtkWidget\" style \"gtk-default-zh-tw\"");

	fclose(f);
	g_free(path);
}