📄 callbacks.c
字号:
/* callback.c --- code of the different callbacks *//* Copyright (c) E. Lassauge, 2000-2001. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation. * * This file is provided AS IS with no warranties of any kind. The author * shall have no liability with respect to the infringement of copyrights, * trade secrets or any patents by this file or any part thereof. In no * event will the author be liable for any lost revenue or profits or * other special, indirect and consequential damages. * * mailto:lassauge@mail.dotcom.fr * http://lassauge.free.fr/ * * REVISION HISTORY: see Changelog * */#include <stdlib.h>#ifdef HAVE_CONFIG_H# include <config.h>#endif#include <gnome.h>#include "sms.h"#include "callbacks.h"#include "interface.h"#include "support.h"/* local variables */static int aliasRow = -1;static const GtkSortType clist_sort[] = {GTK_SORT_ASCENDING,GTK_SORT_DESCENDING};static GtkSortType sort[SCRIPT_CLIST_COLS] = {0,1,1}; /* is index in previous array */#include "checked.xpm"static GdkPixmap *check = (GdkPixmap *) NULL;static GdkBitmap *mask = (GdkBitmap *)NULL;/* All callbacks */void on_script_ok_pressed(GtkWidget * widget, GtkFileSelection *filesel){ /* callback on script selection */ gchar *filename; gchar *ext; PProvider_t Pv=NULL; filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel))); gtk_widget_destroy(GTK_WIDGET(filesel)); ext = (gchar *)g_extension_pointer(filename); if (g_strncasecmp(g_extension_pointer(filename),SMSSEND_SUF,3) == 0) { Pv = create_provider(filename); if (!Pv) { g_printerr(_("Error for '%s'!\n"),filename); } else { gchar *status; status = g_strdup_printf(_("%s : %d provider(s) found"),PACKAGE,NumProvider); gnome_appbar_set_status(GNOME_APPBAR(Appbar), status); g_free(status); } } g_free(filename);}void on_pref_ok_pressed(GtkButton * button, gpointer user_data){ /* update preferences variables: user_data is 1 if write pref file */ GtkWidget *widget = GTK_WIDGET(button); gchar *config_file; UseProxy = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(widget, "use_proxy"))); if (UseProxy) { g_snprintf(ProxyHost, P_LENGTH, "%s", gtk_entry_get_text(GTK_ENTRY(lookup_widget(widget, "proxy_host")))); ProxyPort = (gint) atoi(gtk_entry_get_text(GTK_ENTRY(lookup_widget(widget, "proxy_port")))); g_snprintf(ProxyUser, P_LENGTH, "%s", gtk_entry_get_text(GTK_ENTRY(lookup_widget(widget, "proxy_user")))); g_snprintf(ProxyPass, P_LENGTH, "%s", gtk_entry_get_text(GTK_ENTRY(lookup_widget(widget, "proxy_password")))); } DebugLevel = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(widget, "debug_level"))); TimeOut = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(widget, "timeout"))); AutoCheck = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(widget, "auto_check"))); DelaySend = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(widget, "delay_send"))); KeepPass = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(widget, "keep_pass"))); Retries = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(widget, "retries"))); config_file = gtk_entry_get_text(GTK_ENTRY(lookup_widget(widget, "header_file"))); if (strlen(config_file)) HeaderFile = g_strdup(config_file); /* Save current configuration */ if ((int)user_data == OK_PRESSED) { gchar *path; config_file=gnome_util_prepend_user_home(".smssend/smssendrc"); /* =/home/me/.smssend/smssendrc=/Proxy/use_proxy=true */ path = g_strdup_printf("=%s=/Proxy/use_proxy",config_file); gnome_config_set_bool(path,UseProxy); g_free(path); if (UseProxy) { gchar *temp; path = g_strdup_printf("=%s=/Proxy/proxy_host",config_file); gnome_config_set_string(path,ProxyHost); g_free(path); path = g_strdup_printf("=%s=/Proxy/proxy_port",config_file); gnome_config_set_int(path,ProxyPort); g_free(path); path = g_strdup_printf("=%s=/Proxy/proxy_user",config_file); gnome_config_set_string(path,ProxyUser); g_free(path); path = g_strdup_printf("=%s=/Proxy/proxy_password",config_file); temp = g_strdup(ProxyPass); crypt_password(temp); gnome_config_set_string(path,temp); g_free(temp); g_free(path); } path = g_strdup_printf("=%s=/Misc/debug_level",config_file); gnome_config_set_int(path,DebugLevel); g_free(path); path = g_strdup_printf("=%s=/Misc/timeout",config_file); gnome_config_set_int(path,TimeOut); g_free(path); path = g_strdup_printf("=%s=/Misc/auto_check",config_file); gnome_config_set_bool(path,AutoCheck); g_free(path); path = g_strdup_printf("=%s=/Misc/keep_pass",config_file); gnome_config_set_bool(path,KeepPass); g_free(path); path = g_strdup_printf("=%s=/Misc/delay_calls",config_file); gnome_config_set_bool(path,DelaySend); path = g_strdup_printf("=%s=/Misc/retries",config_file); gnome_config_set_int(path,Retries); g_free(path); gnome_config_sync(); g_free(config_file); }}void on_new_file_activate(GtkMenuItem * menuitem, gpointer user_data){ /* Open a dialog box to choose a new provider file */ Scripts_fs=create_scripts_file_selection(); gtk_widget_show(Scripts_fs);}void on_goto_smssend_activate(GtkMenuItem * menuitem, gpointer user_data){ /* Open a web browser on the smssend homepage */ gnome_url_show(SMSSEND_URL_SCRIPTS);}void on_sendnow_activate(GtkMenuItem * menuitem, gpointer user_data){ if (DelayList) { gnome_appbar_set_status(GNOME_APPBAR(Appbar), "SmsSend ..."); gnome_appbar_set_progress(GNOME_APPBAR(Appbar), 0.0); /* call DelayedSms for each element of the list */ g_slist_foreach(DelayList, DelayedSms, (gpointer) NULL); /* free list (all elements are freed in DelayedSms) */ g_slist_free(DelayList); DelayList = (GSList*)NULL; }}void on_close_activate(GtkMenuItem * menuitem, gpointer user_data){ /* remove currently selected notebook tab, but not Provider struct */ GtkNotebook *nb = GTK_NOTEBOOK(Notebook); gint curpage = gtk_notebook_get_current_page(nb); GtkWidget *curwidget; PProvider_t Pv; /* check page number ! */ if (curpage < 0) return; /* get Provider struct from selected tab (saved at creation) */ curwidget = nb->cur_page->child; Pv = (PProvider_t) gtk_object_get_data(GTK_OBJECT(curwidget),"provider"); /* remove from hash */ g_hash_table_remove(ShownProviderHash, (gconstpointer) Pv->Filename); gtk_notebook_remove_page(nb,curpage);}void on_exit_activate(GtkMenuItem * menuitem, gpointer user_data){ if (DelayList) { gnome_appbar_set_status(GNOME_APPBAR(Appbar), _("** WARNING **: You have delayed messages !")); g_warning(_("You have delayed SMS messages !")); return; } /* this is the end TODO: wait for end of current connection */ gtk_exit(0);}void on_preferences_activate(GtkMenuItem * menuitem, gpointer user_data){ /* open the preference dialog box */ Preference = create_preferences(); gtk_widget_show(Preference);}void on_check_updates_activate(GtkMenuItem * menuitem, gpointer user_data){ /* launch "smssend -update" */ LaunchSms(NULL, FALSE, TRUE);}void on_manage_alias_activate(GtkMenuItem * menuitem, gpointer user_data){ /* open the alias dialog box */ if (!Alias) Alias = create_aliases(); gtk_widget_show(Alias);}void on_script_clist_click_column(GtkCList *clist, gint column, gpointer user_data){ int sort_type = sort[column]; sort[column] = (sort_type + 1) % 2; gtk_clist_set_sort_column(clist,column); gtk_clist_set_sort_type(clist,clist_sort[sort[column]]); gtk_clist_sort(clist);}void on_script_clist_select_row(GtkCList *clist, gint row, gint column, GdkEvent *event, gpointer user_data){#if 0 GtkStyle *row_style = gtk_widget_get_style(GTK_WIDGET(clist));#endif if ((int)user_data == SEL_PRESSED) {#if 0 /* TODO: set_background/set_row_style doesn't do what I want : get rid of selection bg */ gtk_style_set_background (row_style,GTK_WIDGET(clist)->window,GTK_STATE_NORMAL); gtk_clist_set_row_style(clist,row,row_style);#endif if (column) { /* gtk_clist_set_text(clist,row,column,"/"); */ gtk_clist_set_pixmap(clist, row, column,check,mask); } } else { if (column) gtk_clist_set_text(clist,row,column," "); }}static void update_script_dialog(gpointer key, gpointer value, gpointer user_data){ GtkCList *clist = GTK_CLIST(user_data); gchar *row_data[SCRIPT_CLIST_COLS] = {NULL," "," "}; gint row = -1; gint col = -1; row_data[SCRIPT_COL] = (gchar *)key; /* called for each detected script */ if ( (SavedProviderHash) && (g_hash_table_lookup (SavedProviderHash, (gconstpointer) key)) ) { /* script was allready saved */ col = SAVE_COL; row = gtk_clist_append(clist,row_data); /* SAVE/SHOW column will be updated by "select-row" signal */ gtk_clist_select_row(clist,row,col); if ( g_hash_table_lookup(ShownProviderHash, (gconstpointer) key) ) { /* script was allready shown */ col = SHOW_COL; gtk_clist_select_row(clist,row,col); } return; } if ( g_hash_table_lookup(ShownProviderHash, (gconstpointer) key) ) { /* script was allready shown */ col = SHOW_COL; } row = gtk_clist_append(clist,row_data); if (col > SCRIPT_COL) /* SHOW column will be updated by "select-row" signal */ gtk_clist_select_row(clist,row,col);}void on_manage_scripts_activate(GtkMenuItem * menuitem, gpointer user_data){ GtkCList *clist; /* open the script dialog box */ if (!Scripts) { Scripts = create_scripts(); } clist = GTK_CLIST(lookup_widget(GTK_WIDGET(Scripts), "script_clist")); gtk_widget_show(Scripts); /* update the script dialog content */ if (!check) { check = gdk_pixmap_create_from_xpm_d(clist->clist_window,&mask,NULL,check_data); } gtk_clist_freeze(clist); g_hash_table_foreach(ProviderHash,update_script_dialog,(gpointer)clist); gtk_clist_set_sort_column(clist,0); gtk_clist_set_sort_type(clist,GTK_SORT_ASCENDING); gtk_clist_sort(clist); gtk_clist_columns_autosize(clist); gtk_clist_unselect_all(clist); gtk_clist_thaw(clist);}void on_about_activate(GtkMenuItem * menuitem, gpointer user_data){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -