⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialog-pref.c

📁 GNOME下的短信息发送中心
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * preferences dialog * * Authors:     Michael Jochum <e9725005@stud3.tuwien.ac.at> * * TODO:         * * Fixes: * * For license terms, see the file COPYING in the project directory. */#include <config.h>#include <gnome.h>#include "pref.h"#include "dialog-pref.h"#include "app.h"/* preferences widgets */typedef struct {	GtkWidget * propertybox;	/* Network */	GtkWidget * net_cbhttp_proxy;	GtkWidget * net_ehttp_proxy;	GtkWidget * net_ehttp_proxy_port;	GtkWidget * net_sbtimeout;	GtkWidget * net_sbthreads;	/* Mail */	GtkWidget * mail_send_nb;	GtkWidget * mail_receive_nb;	/* POP3 Widgets */	GtkWidget * pop3_eserver;	GtkWidget * pop3_eport;	GtkWidget * pop3_euser;	GtkWidget * pop3_epasswd;	GtkWidget * pop3_cbcheck;	GtkWidget * pop3_sbcheck_period;	GtkWidget * pop3_cbstore_passwd;	GtkWidget * pop3_cbdelete;	/* SMTP Widgets */	GtkWidget * smtp_eserver;	GtkWidget * smtp_eport;	GtkWidget * smtp_email;	GtkWidget * smtp_ehostname;	/* FONT Widgets */	GtkWidget * fontsel;	GtkWidget * font_entry;} PreferencesWidgets;static PreferencesWidgets pw;static void save_to_configuration(void);static GtkWidget * network_page(void);static GtkWidget * email_send_page(void);static GtkWidget * pref_mail_smtp(void);static GtkWidget * email_receive_page(void);static GtkWidget * pref_mail_pop3(void);static GtkWidget * set_font_page(void);/* callbacks */static void network_proxy_enable_cb(GtkToggleButton * togglebutton, 				    gpointer user_data);static void email_send_method_cb(GtkToggleButton * togglebutton, 				 gpointer user_data);static void email_receive_method_cb(GtkToggleButton * togglebutton, 				 gpointer user_data);static void prefs_changed_cb (GtkWidget *widget, gpointer data);static void apply_cb (GnomePropertyBox *pbox, gint page, gpointer data);static void font_sel_open_cb (GtkWidget *button, gpointer user_data);static void set_font_cb(GtkFontSelectionDialog *selector, gpointer user_data);/* bring the preferences dialog up - modal dialog*/void gsms_preferences_dialog(void) {	GtkWidget *propertybox;	pw.propertybox = NULL; /* set to NULL because property_box_changed				  should not be called during setup */	propertybox = gnome_property_box_new();	gtk_window_set_modal( GTK_WINDOW(propertybox), TRUE);	gnome_property_box_append_page(GNOME_PROPERTY_BOX(propertybox),				       network_page(),				       gtk_label_new(_("Network") ));	gnome_property_box_append_page(GNOME_PROPERTY_BOX(propertybox),				       email_send_page(),				       gtk_label_new(_("Sending Mails") ));	gnome_property_box_append_page(GNOME_PROPERTY_BOX(propertybox),				       email_receive_page(),				       gtk_label_new(_("Receiving Mails") ));	gnome_property_box_append_page(GNOME_PROPERTY_BOX(propertybox),				       set_font_page(),				       gtk_label_new(_("Textfont") ));	/* connect signals */	gtk_signal_connect (GTK_OBJECT (propertybox), "apply",			    GTK_SIGNAL_FUNC (apply_cb), NULL);/*	gtk_signal_connect (GTK_OBJECT (propertybox),			    "destroy",			    GTK_SIGNAL_FUNC (destroy_cb), NULL);	gtk_signal_connect (GTK_OBJECT (propertybox),			    "delete_event",			    GTK_SIGNAL_FUNC (gtk_false), NULL);	gtk_signal_connect (GTK_OBJECT (propertybox),			    "help",			    GTK_SIGNAL_FUNC (help_cb), NULL);*/	pw.propertybox = propertybox;	gtk_widget_show(propertybox);}static void save_to_configuration(void){	const gchar *send_methods[] = { "smtp", "sendmail", "none", NULL };	const gchar *receive_methods[] = { "pop3", "mbox", "none", NULL };	gchar *str;	gint n;	/* save network settings */	g_free(configuration.http_proxy);	configuration.http_proxy_enabled = gtk_toggle_button_get_active(		GTK_TOGGLE_BUTTON(pw.net_cbhttp_proxy));	str = gtk_editable_get_chars(		GTK_EDITABLE(pw.net_ehttp_proxy_port),0, -1);	if( sscanf(str, "%d", &n) != 1)		n = 8000;	g_free(str);        if(n <= 0 || n >= 65535)		n = 8000;	configuration.http_proxy_port = n;	configuration.http_proxy = gtk_editable_get_chars(		GTK_EDITABLE(pw.net_ehttp_proxy), 0, -1);	configuration.net_timeout = gtk_spin_button_get_value_as_int(		GTK_SPIN_BUTTON(pw.net_sbtimeout));	configuration.max_threads = gtk_spin_button_get_value_as_int(		GTK_SPIN_BUTTON(pw.net_sbthreads));	/* save mail settings */	n = gtk_notebook_get_current_page(GTK_NOTEBOOK(pw.mail_send_nb));	g_free(configuration.mail_send_method);	configuration.mail_send_method = g_strdup(send_methods[n]);	n = gtk_notebook_get_current_page(GTK_NOTEBOOK(pw.mail_receive_nb));	g_free(configuration.mail_receive_method);	configuration.mail_receive_method = g_strdup(receive_methods[n]);	/* save POP3 settings */	g_free(configuration.pop3_server);	configuration.pop3_server = gtk_editable_get_chars(		GTK_EDITABLE(pw.pop3_eserver), 0, -1);	str = gtk_editable_get_chars(GTK_EDITABLE(pw.pop3_eport), 0, -1);	if( sscanf(str, "%d", &n) != 1)		n = 110;	g_free(str);        if(n <= 0 || n >= 65535)		n = 110;	configuration.pop3_port = n;	g_free(configuration.pop3_user);	configuration.pop3_user = gtk_editable_get_chars(		GTK_EDITABLE(pw.pop3_euser), 0, -1);	g_free(configuration.pop3_passwd);	configuration.pop3_passwd = gtk_editable_get_chars(		GTK_EDITABLE(pw.pop3_epasswd), 0, -1);	n = -1;	if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pw.pop3_cbcheck)))		n = 1;	configuration.pop3_check = n * gtk_spin_button_get_value_as_int(		GTK_SPIN_BUTTON(pw.pop3_sbcheck_period));	configuration.pop3_store = gtk_toggle_button_get_active(		GTK_TOGGLE_BUTTON(pw.pop3_cbstore_passwd));	configuration.pop3_delete = gtk_toggle_button_get_active(		GTK_TOGGLE_BUTTON(pw.pop3_cbdelete));	/* save SMTP settings */	g_free(configuration.smtp_server);	configuration.smtp_server = gtk_editable_get_chars(		GTK_EDITABLE(pw.smtp_eserver), 0, -1);	str = gtk_editable_get_chars(GTK_EDITABLE(pw.smtp_eport), 0, -1);	if( sscanf(str, "%d", &n) != 1)		n = 110;	g_free(str);        if(n <= 0 || n >= 65535)		n = 110;	configuration.smtp_port = n;	g_free(configuration.smtp_email);	configuration.smtp_email = gtk_editable_get_chars(		GTK_EDITABLE(pw.smtp_email), 0, -1);	g_free(configuration.smtp_host);	configuration.smtp_host = gtk_editable_get_chars(		GTK_EDITABLE(pw.smtp_ehostname), 0, -1);	g_free(configuration.fontname);	configuration.fontname = gtk_editable_get_chars(		GTK_EDITABLE(pw.font_entry), 0, -1);	app_set_font();}/****************************** network page ********************************//* returns the page to configure how e-mails are send */static GtkWidget *network_page(void){	GtkWidget *label;	GtkWidget *table;	GtkWidget *box;	GtkAdjustment *adj_threads, *adj_timeout;	gchar str[8];	/* Table Layout for this page */	table = gtk_table_new(4, 2, FALSE);	/* labels */	label = gtk_label_new(_("HTTP-Proxy"));	gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);	gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_SHRINK,			 GTK_SHRINK, 5, 2);	label = gtk_label_new(_("Network Timeout"));	gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT);	gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, GTK_SHRINK,			 GTK_SHRINK, 5, 2);	label = gtk_label_new(_("Max. Threads"));	gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT);	gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, GTK_SHRINK,			 GTK_SHRINK, 5, 2);	/* Proxy */	pw.net_cbhttp_proxy = gtk_check_button_new_with_label(		_("Use HTTP Proxy"));	gtk_table_attach(GTK_TABLE(table), pw.net_cbhttp_proxy, 1, 2, 0, 1,			 GTK_EXPAND | GTK_FILL, GTK_SHRINK, 5, 2);	box = gtk_hbox_new(FALSE, 0);	gtk_table_attach(GTK_TABLE(table), box, 1, 2, 1, 2,			 GTK_EXPAND | GTK_FILL, GTK_SHRINK, 5, 2);	pw.net_ehttp_proxy = gtk_entry_new();	gtk_box_pack_start(GTK_BOX(box), pw.net_ehttp_proxy, TRUE, TRUE, 0);	pw.net_ehttp_proxy_port = gtk_entry_new_with_max_length(6);	gtk_widget_set_usize(pw.net_ehttp_proxy_port, 60, -2);	gtk_box_pack_end(GTK_BOX(box),			 pw.net_ehttp_proxy_port, FALSE, FALSE, 0);	label = gtk_label_new(_("  Port:"));	gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);	gtk_box_pack_end(GTK_BOX(box), label, FALSE, FALSE, 4);	/* Timeout */	adj_timeout = (GtkAdjustment *) gtk_adjustment_new(2, 1, 180, 1, 1, 0);	pw.net_sbtimeout = gtk_spin_button_new(adj_timeout, 0.0, 0);	gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(pw.net_sbtimeout), TRUE);	gtk_table_attach(GTK_TABLE(table), pw.net_sbtimeout, 1, 2, 2, 3,			 GTK_EXPAND | GTK_FILL, GTK_SHRINK, 5, 2);	/* Threads */	adj_threads = (GtkAdjustment *) gtk_adjustment_new(2, 1, 32, 1, 1, 0);	pw.net_sbthreads = gtk_spin_button_new(adj_threads, 0.0, 0);	gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(pw.net_sbthreads), TRUE);	gtk_table_attach(GTK_TABLE(table), pw.net_sbthreads, 1, 2, 3, 4,			 GTK_EXPAND | GTK_FILL, GTK_SHRINK, 5, 2);	/* load configuration data */	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pw.net_cbhttp_proxy),			   configuration.http_proxy_enabled);	sprintf(str, "%d", (gint) configuration.http_proxy_port);	gtk_entry_set_text(GTK_ENTRY(pw.net_ehttp_proxy_port), str);	gtk_entry_set_text(GTK_ENTRY(pw.net_ehttp_proxy), 			   configuration.http_proxy);	gtk_spin_button_set_value(GTK_SPIN_BUTTON(pw.net_sbtimeout),				  (gfloat) configuration.net_timeout);	gtk_spin_button_set_value(GTK_SPIN_BUTTON(pw.net_sbthreads),				  (gfloat) configuration.max_threads);	/* connect to prefs_changed callback */	gtk_signal_connect(GTK_OBJECT(pw.net_cbhttp_proxy), "toggled",			   GTK_SIGNAL_FUNC(network_proxy_enable_cb), NULL);	network_proxy_enable_cb(GTK_TOGGLE_BUTTON(pw.net_cbhttp_proxy), NULL);	gtk_signal_connect(GTK_OBJECT(pw.net_ehttp_proxy), "changed",			   GTK_SIGNAL_FUNC(prefs_changed_cb), NULL);	gtk_signal_connect(GTK_OBJECT(pw.net_ehttp_proxy_port), "changed",			   GTK_SIGNAL_FUNC(prefs_changed_cb), NULL);	gtk_signal_connect (GTK_OBJECT (adj_threads), "value_changed",			    GTK_SIGNAL_FUNC (prefs_changed_cb), NULL);	gtk_signal_connect (GTK_OBJECT (adj_timeout), "value_changed",			    GTK_SIGNAL_FUNC (prefs_changed_cb), NULL);	gtk_widget_show_all(table);	return table;}/*************************** sending mail page ******************************//* returns the page to configure how e-mails are send */static GtkWidget *email_send_page(void){	GtkWidget *vbox;	GtkWidget *frame;	GtkWidget *notebook;	GtkWidget *table;	GtkWidget *rb[3];		/* radio Button */	const gchar *send_methods[] = { "smtp", "sendmail", "none", NULL };	gint i;	/* each sen method is a page in notebook */	pw.mail_send_nb = notebook = gtk_notebook_new();	gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);	gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);	gtk_notebook_append_page( GTK_NOTEBOOK(notebook), 				  pref_mail_smtp(), NULL );	gtk_notebook_append_page( GTK_NOTEBOOK(notebook), 				  gtk_label_new("not implemented"), NULL);	gtk_notebook_append_page( GTK_NOTEBOOK(notebook), 				  gtk_label_new(_("can't send mails")), 				  NULL);	/* Table Layout for this page */	table = gtk_table_new(1, 2, FALSE);        frame = gtk_frame_new(_("Send-Method"));        gtk_table_attach(GTK_TABLE(table), frame, 0, 1, 0, 1,                         GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_FILL, 5, 5);        vbox = gtk_vbox_new(FALSE, 0);        gtk_container_add(GTK_CONTAINER(frame), vbox);        frame = gtk_frame_new(NULL);        gtk_table_attach(GTK_TABLE(table), notebook, 1, 2, 0, 1,                         GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 5, 5);	rb[0] = gtk_radio_button_new_with_label_from_widget(NULL, 							 _("SMTP"));	gtk_box_pack_start(GTK_BOX(vbox), rb[0], FALSE, FALSE, 2);	gtk_signal_connect(GTK_OBJECT(rb[0]), "toggled",			   GTK_SIGNAL_FUNC(email_send_method_cb),			   GINT_TO_POINTER(0));/* data is the pagenum of the						   notebook */	rb[1] = gtk_radio_button_new_with_label_from_widget(		GTK_RADIO_BUTTON(rb[0]),							_("Sendmail"));	gtk_box_pack_start(GTK_BOX(vbox), rb[1], FALSE, FALSE, 2);	gtk_signal_connect(GTK_OBJECT(rb[1]), "toggled",			   GTK_SIGNAL_FUNC(email_send_method_cb),			   GINT_TO_POINTER(1));	rb[2] = gtk_radio_button_new_with_label_from_widget(		GTK_RADIO_BUTTON(rb[1]), _("none"));	gtk_box_pack_start(GTK_BOX(vbox), rb[2], FALSE, FALSE, 2);	gtk_signal_connect(GTK_OBJECT(rb[2]), "toggled",			   GTK_SIGNAL_FUNC(email_send_method_cb),			   GINT_TO_POINTER(2));	for(i = 0; send_methods[i] != NULL; i++)		if(strcmp(send_methods[i], 			  configuration.mail_send_method) == 0) {			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb[i]),						     TRUE);			break;		}	gtk_widget_show_all(table);	gtk_notebook_set_page(GTK_NOTEBOOK(notebook),i);	return table;}/* preferences frame for SMTP in the send configuration */static GtkWidget *pref_mail_smtp(void){	GtkWidget *vbox, *box;	GtkWidget *table;	GtkWidget *label;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -