[PATCH] More email capplet
- From: Patrick Decowski <decowski mit edu>
- To: gnome-pilot-list gnome org
- Subject: [PATCH] More email capplet
- Date: Wed, 27 Oct 1999 23:07:49 -0400 (EDT)
hi,
i looked some more into the email capplet and changed the GtkCombos
into GtkOptionMenus - looks much better. also changed the
try/ok/cancel logic to that what vadim put out so nicely - is there a
Gnome/Capplet style guide anywhere? fixed a couple of bugs and the
capplet will now properly change state when you _only_ delete
chars. btw, this seems to also be a problem in the pilotlink, backup
and memo_file capplets, basically everywhere where there are GtkEntry
boxes. the fix is to attach a 'delete-text' signal and call the change
state func, see the patch below.
cheers,
patrick.
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-pilot/conduits/email/ChangeLog,v
retrieving revision 1.4
diff -u -r1.4 ChangeLog
--- ChangeLog 1999/10/26 19:26:26 1.4
+++ ChangeLog 1999/10/28 02:59:04
@@ -1,4 +1,15 @@
+1999-10-27 Patrick Decowski <decowski@mit.edu>
+
+ * email-conduit-control-applet.c: changed the logic of
+ try/ok/revert as per vadim's suggestion. the options can now be
+ selected with a GtkOptionMenu instead of the ComboMenu, fixed the
+ thing with deleting text in a GtkEntry and the capplet not
+ changing state if that is the only thing that is done: you need to
+ call a special 'delete-text' signal to change the state....
+ also fixed a few bugs where the gstrings weren't properly duplicated
+ into the ConduitCfg struct and then deleted.
+
1999-10-26 Patrick Decowski <decowski@mit.edu>
* email-conduit-control-applet.c: the user can now edit the 'From'
Index: email-conduit-control-applet.c
===================================================================
RCS file: /cvs/gnome/gnome-pilot/conduits/email/email-conduit-control-applet.c,v
retrieving revision 1.10
diff -u -r1.10 email-conduit-control-applet.c
--- email-conduit-control-applet.c 1999/10/26 19:26:26 1.10
+++ email-conduit-control-applet.c 1999/10/28 02:59:04
@@ -33,14 +33,15 @@
ConduitCfg *origState = NULL;
ConduitCfg *curState = NULL;
-static void doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg);
-static void doRevertSettings(GtkWidget *widget, ConduitCfg *conduitCfg);
-static void doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg);
+static void doTrySettings(GtkWidget *widget, gpointer dummy);
+static void doRevertSettings(GtkWidget *widget, gpointer dummy);
+static void doSaveSettings(GtkWidget *widget, gpointer dummy);
+static void doCancelSettings(GtkWidget *widget, gpointer dummy);
-static void readOptionsCfg(GtkWidget *w, ConduitCfg **state);
+static void readOptionsCfg(GtkWidget *w, ConduitCfg *state);
static void setOptionsCfg(GtkWidget *w, ConduitCfg *state);
-static void readStateCfg(GtkWidget *w,ConduitCfg **state);
-static void setStateCfg(GtkWidget *w,ConduitCfg *state);
+static void readStateCfg(GtkWidget *w, ConduitCfg *state);
+static void setStateCfg(GtkWidget *w, ConduitCfg *state);
gint pilotId;
CORBA_Environment ev;
@@ -48,36 +49,48 @@
#define ACTION_OPTIONS_COUNT 2
static gchar* action_options[] = { N_("file"),
N_("delete") };
+static void
+setSettings(ConduitCfg* conduitCfg)
+{
+ if(activated)
+ gpilotd_conduit_mgmt_enable(conduit,pilotId,GnomePilotConduitSyncTypeCustom);
+ else
+ gpilotd_conduit_mgmt_disable(conduit,pilotId);
+ save_configuration(conduitCfg);
+}
static void
-doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg)
+doTrySettings(GtkWidget *widget, gpointer dummy)
{
- readStateCfg(cfgStateWindow, &conduitCfg);
- readOptionsCfg(cfgOptionsWindow, &conduitCfg);
- if(activated)
- gpilotd_conduit_mgmt_enable(conduit,pilotId,GnomePilotConduitSyncTypeCustom);
- else
- gpilotd_conduit_mgmt_disable(conduit,pilotId);
+ readStateCfg(cfgStateWindow, curState);
+ readOptionsCfg(cfgOptionsWindow, curState);
+ setSettings(curState);
}
static void
-doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg)
+doSaveSettings(GtkWidget *widget, gpointer dummy)
{
- doTrySettings(widget, conduitCfg);
- save_configuration(conduitCfg);
+ doTrySettings(widget, curState);
}
static void
-doRevertSettings(GtkWidget *widget, ConduitCfg *conduitCfg)
+doRevertSettings(GtkWidget *widget, gpointer dummy)
{
- activated = org_activation_state;
- destroy_configuration(&curState);
- curState = dupe_configuration(origState);
- setOptionsCfg(cfgOptionsWindow, curState);
- setStateCfg(cfgStateWindow, curState);
+ activated = org_activation_state;
+ destroy_configuration(&curState);
+ curState = dupe_configuration(origState);
+ setOptionsCfg(cfgOptionsWindow, curState);
+ setStateCfg(cfgStateWindow, curState);
+ setSettings(curState);
}
+static void
+doCancelSettings(GtkWidget *widget, gpointer dummy)
+{
+ setSettings(origState);
+}
+
/* Don't allow any spaces */
static void
insert_callback (GtkEditable *editable, const gchar *text,
@@ -103,20 +116,32 @@
}
}
+/* make the ok/try/cancel buttons active */
static void
-insert_callback2(GtkEditable *editable, const gchar *text,
+statechange_cb(GtkEditable *editable, const gchar *text,
gint length, gint *position,
void *data)
+{
+ if (!ignore_changes)
+ capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE);
+}
+
+/* option menu callback for 'sendAction' */
+static void
+sendaction_cb(GtkMenuItem *widget, gpointer data)
{
- if (!ignore_changes)
- capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE);
+ curState->sendAction = g_strdup((gchar*)data);
+ if(!ignore_changes)
+ capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE);
}
+/* option menu callback for 'receiverAction' */
static void
-clist_changed(GtkWidget *widget, gpointer data)
+recvaction_cb(GtkMenuItem *widget, gpointer data)
{
- if (!ignore_changes)
- capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE);
+ curState->receiveAction = g_strdup((gchar*)data);
+ if(!ignore_changes)
+ capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE);
}
void about_cb (GtkWidget *widget, gpointer data) {
@@ -187,7 +212,7 @@
static void
-readStateCfg(GtkWidget *widget,ConduitCfg **cfg)
+readStateCfg(GtkWidget *widget,ConduitCfg *cfg)
{
GtkWidget *button;
@@ -203,9 +228,8 @@
{
GtkWidget *vbox, *table;
GtkWidget *entry, *label;
- GtkWidget *button;
- GtkWidget *combo;
- GList *options=NULL;
+ GtkWidget *menuItem, *optionMenu;
+ GtkMenu *menu;
int i;
vbox = gtk_vbox_new(FALSE, GNOME_PAD);
@@ -227,8 +251,13 @@
GTK_SIGNAL_FUNC(insert_callback),
NULL);
+ /* change the state of the capplet on delete chars as well */
+ gtk_signal_connect(GTK_OBJECT(entry), "delete_text",
+ GTK_SIGNAL_FUNC(statechange_cb),
+ NULL);
+
gtk_signal_connect_after(GTK_OBJECT(entry), "insert_text",
- GTK_SIGNAL_FUNC(insert_callback2),
+ GTK_SIGNAL_FUNC(statechange_cb),
NULL);
/* Get the MH Directory */
@@ -243,8 +272,13 @@
GTK_SIGNAL_FUNC(insert_callback),
NULL);
+ /* change the state of the capplet on delete chars as well */
+ gtk_signal_connect(GTK_OBJECT(entry), "delete_text",
+ GTK_SIGNAL_FUNC(statechange_cb),
+ NULL);
+
gtk_signal_connect_after(GTK_OBJECT(entry), "insert_text",
- GTK_SIGNAL_FUNC(insert_callback2),
+ GTK_SIGNAL_FUNC(statechange_cb),
NULL);
/* Get sendmail location */
@@ -255,42 +289,60 @@
gtk_object_set_data(GTK_OBJECT(vbox), "SendmailLoc", entry);
gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 2, 2, 3);
+ /* change the state of the capplet on delete chars as well */
+ gtk_signal_connect(GTK_OBJECT(entry), "delete_text",
+ GTK_SIGNAL_FUNC(statechange_cb),
+ NULL);
+
gtk_signal_connect_after(GTK_OBJECT(entry), "insert_text",
- GTK_SIGNAL_FUNC(insert_callback2),
+ GTK_SIGNAL_FUNC(statechange_cb),
NULL);
+
+ /* what to do with mail sent from the pilot */
+ label = gtk_label_new(_("Mail sent from pilot"));
+ gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4);
+ menu = GTK_MENU(gtk_menu_new());
for (i = 0; i < ACTION_OPTIONS_COUNT; i++) {
action_options[i] = _(action_options[i]);
- options = g_list_append(options, action_options[i]);
+ menuItem = gtk_menu_item_new_with_label(action_options[i]);
+ gtk_widget_show(menuItem);
+ gtk_signal_connect(GTK_OBJECT(menuItem),"activate",
+ GTK_SIGNAL_FUNC(sendaction_cb),
+ action_options[i]);
+ gtk_menu_append(menu, menuItem);
}
-
- /* is the mail on the host computer archived? */
- label = gtk_label_new(_("Mail on Host"));
- gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4);
- combo = gtk_combo_new();
- gtk_combo_set_popdown_strings( GTK_COMBO(combo), options) ;
- gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed",
- GTK_SIGNAL_FUNC(insert_callback2),
+ optionMenu = gtk_option_menu_new();
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(optionMenu),GTK_WIDGET(menu));
+ gtk_signal_connect(GTK_OBJECT(menu), "selection-done",
+ GTK_SIGNAL_FUNC(statechange_cb),
NULL);
- gtk_object_set_data(GTK_OBJECT(vbox), "SendAction", combo);
-
- gtk_table_attach_defaults(GTK_TABLE(table), combo, 1, 2, 4, 5);
+ gtk_table_attach_defaults(GTK_TABLE(table), optionMenu, 1, 2, 3, 4);
+ gtk_object_set_data(GTK_OBJECT(vbox), "SendAction", optionMenu);
- /* what to do with mail sent from the pilot */
- label = gtk_label_new(_("Mail sent from pilot"));
+ /* is the mail on the host computer archived? */
+ label = gtk_label_new(_("Mail on Host"));
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5);
-
- combo = gtk_combo_new();
- gtk_combo_set_popdown_strings( GTK_COMBO(combo), options) ;
- gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed",
- GTK_SIGNAL_FUNC(insert_callback2),
+ menu = GTK_MENU(gtk_menu_new());
+ for (i = 0; i < ACTION_OPTIONS_COUNT; i++) {
+ action_options[i] = _(action_options[i]);
+ menuItem = gtk_menu_item_new_with_label(action_options[i]);
+ gtk_widget_show(menuItem);
+ gtk_signal_connect(GTK_OBJECT(menuItem),"activate",
+ GTK_SIGNAL_FUNC(recvaction_cb),
+ action_options[i]);
+ gtk_menu_append(menu, menuItem);
+ }
+ optionMenu = gtk_option_menu_new();
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(optionMenu),GTK_WIDGET(menu));
+ gtk_signal_connect(GTK_OBJECT(menu), "selection-done",
+ GTK_SIGNAL_FUNC(statechange_cb),
NULL);
- gtk_object_set_data(GTK_OBJECT(vbox), "RecvAction", combo);
-
- gtk_table_attach_defaults(GTK_TABLE(table), combo, 1, 2, 3, 4);
+ gtk_table_attach_defaults(GTK_TABLE(table), optionMenu, 1, 2, 4, 5);
+ gtk_object_set_data(GTK_OBJECT(vbox), "RecvAction", optionMenu);
return vbox;
}
@@ -299,6 +351,7 @@
setOptionsCfg(GtkWidget *pilotcfg, ConduitCfg *state)
{
GtkWidget *fromAddress, *mailDir, *sendmailLoc, *sendAct, *recvAct;
+ int i;
fromAddress = gtk_object_get_data(GTK_OBJECT(pilotcfg), "FromAddress");
mailDir = gtk_object_get_data(GTK_OBJECT(pilotcfg), "MailDir");
@@ -309,36 +362,39 @@
g_assert(fromAddress != NULL);
g_assert(mailDir != NULL);
g_assert(sendmailLoc != NULL);
- g_assert(sendAct != NULL);
- g_assert(recvAct != NULL);
+ g_assert(sendAct != NULL);
+ g_assert(recvAct != NULL);
ignore_changes = TRUE;
gtk_entry_set_text(GTK_ENTRY(fromAddress), state->fromAddr);
gtk_entry_set_text(GTK_ENTRY(mailDir), state->mhDirectory);
gtk_entry_set_text(GTK_ENTRY(sendmailLoc), state->sendmail);
- gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(sendAct)->entry), state->sendAction);
- gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(recvAct)->entry), state->receiveAction);
+
+ /* find the entry in the option menu. if not found,
+ default to the last */
+ for(i = 0; i < ACTION_OPTIONS_COUNT && g_strncasecmp(state->sendAction, action_options[i], 20) != 0; i++);
+ gtk_option_menu_set_history(GTK_OPTION_MENU(sendAct), i);
+
+ for(i = 0; i < ACTION_OPTIONS_COUNT && g_strncasecmp(state->receiveAction, action_options[i], 20) != 0; i++);
+ gtk_option_menu_set_history(GTK_OPTION_MENU(recvAct), i);
ignore_changes = FALSE;
}
static void
-readOptionsCfg(GtkWidget *pilotcfg, ConduitCfg **state)
+readOptionsCfg(GtkWidget *pilotcfg, ConduitCfg *state)
{
GtkWidget *fromAddress, *mailDir, *sendmailLoc, *sendAct, *recvAct;
fromAddress = gtk_object_get_data(GTK_OBJECT(pilotcfg), "FromAddress");
mailDir = gtk_object_get_data(GTK_OBJECT(pilotcfg), "MailDir");
sendmailLoc = gtk_object_get_data(GTK_OBJECT(pilotcfg), "SendmailLoc");
- sendAct = gtk_object_get_data(GTK_OBJECT(pilotcfg), "SendAction");
- recvAct = gtk_object_get_data(GTK_OBJECT(pilotcfg), "RecvAction");
- (*state)->fromAddr = gtk_entry_get_text(GTK_ENTRY(fromAddress));
- (*state)->mhDirectory = gtk_entry_get_text(GTK_ENTRY(mailDir));
- (*state)->sendmail = gtk_entry_get_text(GTK_ENTRY(sendmailLoc));
- (*state)->sendAction = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(sendAct)->entry));
- (*state)->receiveAction = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(recvAct)->entry));
+ state->fromAddr = g_strdup(gtk_entry_get_text(GTK_ENTRY(fromAddress)));
+ state->mhDirectory = g_strdup(gtk_entry_get_text(GTK_ENTRY(mailDir)));
+ state->sendmail = g_strdup(gtk_entry_get_text(GTK_ENTRY(sendmailLoc)));
+ /* the sendAction and receiveAction were already updated in the cb */
}
static void
@@ -365,11 +421,13 @@
gtk_container_add(GTK_CONTAINER(frame), cfgOptionsWindow);
gtk_signal_connect(GTK_OBJECT(capplet), "try",
- GTK_SIGNAL_FUNC(doTrySettings), curState);
+ GTK_SIGNAL_FUNC(doTrySettings), NULL);
gtk_signal_connect(GTK_OBJECT(capplet), "revert",
- GTK_SIGNAL_FUNC(doRevertSettings), curState);
+ GTK_SIGNAL_FUNC(doRevertSettings), NULL);
gtk_signal_connect(GTK_OBJECT(capplet), "ok",
- GTK_SIGNAL_FUNC(doSaveSettings), curState);
+ GTK_SIGNAL_FUNC(doSaveSettings), NULL);
+ gtk_signal_connect(GTK_OBJECT(capplet), "cancel",
+ GTK_SIGNAL_FUNC(doCancelSettings), NULL);
gtk_signal_connect(GTK_OBJECT(capplet), "help",
GTK_SIGNAL_FUNC(about_cb), NULL);
-------------------------------------------o-------------------------------
Patrick Decowski |
24-504 | Home: (617)625-9352
Massachusetts Institute of Technology | Office: (617)253-9735
77 Massachusetts Ave | Fax: (617)253-1755
Cambridge, MA 02139-4307 |
-------------------------------------------o-------------------------------
http://web.mit.edu/decowski/www/home.html | e-mail: decowski@mit.edu
-------------------------------------------o-------------------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]