diff options
author | Gilles Dartiguelongue <gdartigu@src.gnome.org> | 2007-11-08 21:36:03 +0800 |
---|---|---|
committer | Gilles Dartiguelongue <gdartigu@src.gnome.org> | 2007-11-08 21:36:03 +0800 |
commit | 78b09515e67fdd065d53b98a993671336a30e54b (patch) | |
tree | 1bec30025f5d7839ce2e0b8d721973bbcab04aa4 /plugins | |
parent | e57bc4e409481165726cd503efd2405cd778c534 (diff) | |
download | gsoc2013-evolution-78b09515e67fdd065d53b98a993671336a30e54b.tar.gz gsoc2013-evolution-78b09515e67fdd065d53b98a993671336a30e54b.tar.zst gsoc2013-evolution-78b09515e67fdd065d53b98a993671336a30e54b.zip |
Remove useless GtkVBox, remove the useless popup to have an inline header
* imap-headers.c: (imap_headers_abort), (imap_headers_commit),
(epif_header_is_valid), (epif_add_sensitivity), (epif_add_header),
(epif_remove_header_clicked), (epif_fetch_all_headers_toggled),
(epif_entry_changed), (org_gnome_imap_headers):
* imap-headers.glade:
Remove useless GtkVBox,
remove the useless popup to have an inline header entry field,
concentrate all UI elements in a structure, added a prefix to
relevant functions.
svn path=/trunk/; revision=34516
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/imap-features/ChangeLog | 12 | ||||
-rw-r--r-- | plugins/imap-features/imap-headers.c | 220 | ||||
-rw-r--r-- | plugins/imap-features/imap-headers.glade | 115 |
3 files changed, 221 insertions, 126 deletions
diff --git a/plugins/imap-features/ChangeLog b/plugins/imap-features/ChangeLog index cdbc0f36c6..f4983906d9 100644 --- a/plugins/imap-features/ChangeLog +++ b/plugins/imap-features/ChangeLog @@ -1,3 +1,15 @@ +2007-11-08 Gilles Dartiguelongue <gdartigu@svn.gnome.org> + + * imap-headers.c: (imap_headers_abort), (imap_headers_commit), + (epif_header_is_valid), (epif_add_sensitivity), (epif_add_header), + (epif_remove_header_clicked), (epif_fetch_all_headers_toggled), + (epif_entry_changed), (org_gnome_imap_headers): + * imap-headers.glade: + Remove useless GtkVBox, + remove the useless popup to have an inline header entry field, + concentrate all UI elements in a structure, added a prefix to + relevant functions. + 2007-07-30 Andre Klapper <a9016009@gmx.de> * imap-headers.glade: diff --git a/plugins/imap-features/imap-headers.c b/plugins/imap-features/imap-headers.c index 78556bc122..6c65a61153 100644 --- a/plugins/imap-features/imap-headers.c +++ b/plugins/imap-features/imap-headers.c @@ -43,27 +43,38 @@ #include <glib/gi18n.h> -GtkWidget *all_headers, *basic_headers, *mailing_list_headers; -GtkWidget *custom_headers_box = NULL; -GtkTreeView *custom_headers_tree; -static GtkTreeStore *store; -GtkTreeIter iter; +typedef struct _epif_data EPImapFeaturesData; +struct _epif_data { + GtkWidget *all_headers; + GtkWidget *basic_headers; + GtkWidget *mailing_list_headers; + GtkWidget *custom_headers_box; -GtkButton *add_header, *remove_header; + GtkEntry *entry_header; -gchar **custom_headers_array = NULL; + GtkButton *add_header; + GtkButton *remove_header; -void imap_headers_abort (GtkWidget *button, EConfigHookItemFactoryData *data); -void imap_headers_commit (GtkWidget *button, EConfigHookItemFactoryData *data); + GtkTreeView *custom_headers_tree; + GtkTreeStore *store; + + gchar **custom_headers_array; +}; + +static EPImapFeaturesData *ui = NULL; + +void imap_headers_abort (EPlugin *efp, EConfigHookItemFactoryData *data); +void imap_headers_commit (EPlugin *efp, EConfigHookItemFactoryData *data); GtkWidget * org_gnome_imap_headers (EPlugin *epl, EConfigHookItemFactoryData *data); void -imap_headers_abort (GtkWidget *button, EConfigHookItemFactoryData *data) +imap_headers_abort (EPlugin *efp, EConfigHookItemFactoryData *data) { + /* Nothing to do here */ } void -imap_headers_commit (GtkWidget *button, EConfigHookItemFactoryData *data) +imap_headers_commit (EPlugin *efp, EConfigHookItemFactoryData *data) { EMConfigTargetAccount *target_account; EAccount *account; @@ -87,7 +98,7 @@ imap_headers_commit (GtkWidget *button, EConfigHookItemFactoryData *data) url = camel_url_new (e_account_get_string(account, E_ACCOUNT_SOURCE_URL), &ex); - model = gtk_tree_view_get_model (custom_headers_tree); + model = gtk_tree_view_get_model (ui->custom_headers_tree); if (gtk_tree_model_get_iter_first(model, &iter)) { do { @@ -103,10 +114,10 @@ imap_headers_commit (GtkWidget *button, EConfigHookItemFactoryData *data) camel_url_set_param (url, "imap_custom_headers", header); g_free (header); - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(all_headers))) { + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui->all_headers))) { camel_url_set_param (url, "all_headers", "1"); camel_url_set_param (url, "basic_headers", NULL); - } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic_headers))) { + } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui->basic_headers))) { camel_url_set_param (url, "basic_headers", "1"); camel_url_set_param (url, "all_headers", NULL); } else { @@ -122,72 +133,118 @@ imap_headers_commit (GtkWidget *button, EConfigHookItemFactoryData *data) } } +/* return true is the header is considered valid */ +static gboolean +epif_header_is_valid (const char *header) +{ + gint len = g_utf8_strlen (header, -1); + + if (header[0] == 0 + || g_utf8_strchr (header, len, ':') != NULL + || g_utf8_strchr (header, len, ' ') != NULL) + return FALSE; + + return TRUE; +} + static void -add_header_clicked (GtkButton *button) +epif_add_sensitivity (EPImapFeaturesData *ui) +{ + const char *entry_contents; + GtkTreeIter iter; + gboolean valid; + + /* the add header button should be sensitive if the text box contains + * a valid header string, that is not a duplicate with something already + * in the list view */ + entry_contents = gtk_entry_get_text (GTK_ENTRY (ui->entry_header)); + if (!epif_header_is_valid (entry_contents)) { + gtk_widget_set_sensitive (GTK_WIDGET (ui->add_header), FALSE); + return; + } + + /* check if this is a duplicate */ + valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ui->store), &iter); + while (valid) { + char *header_name; + + gtk_tree_model_get (GTK_TREE_MODEL (ui->store), &iter, + 0, &header_name, + -1); + if (g_ascii_strcasecmp (header_name, entry_contents) == 0) { + gtk_widget_set_sensitive (GTK_WIDGET (ui->add_header), FALSE); + return; + } + + valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (ui->store), &iter); + } + + gtk_widget_set_sensitive (GTK_WIDGET (ui->add_header), TRUE); +} + +static void +epif_add_header (GtkButton *button, EPImapFeaturesData *ui) { - GtkDialog *dialog; - GtkEntry *header; GtkTreeModel *model; GtkTreeIter iter, first; - gint result; - - dialog = GTK_DIALOG (gtk_dialog_new_with_buttons (_("Custom Header"), - NULL, - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, - GTK_RESPONSE_REJECT, - GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, - NULL)); - header = GTK_ENTRY(gtk_entry_new ()); - gtk_container_add (GTK_CONTAINER(dialog->vbox), GTK_WIDGET(header)); - gtk_dialog_set_default_response (dialog, GTK_RESPONSE_ACCEPT); - gtk_widget_show_all (GTK_WIDGET(dialog)); - result = gtk_dialog_run (GTK_DIALOG (dialog)); - model = gtk_tree_view_get_model (custom_headers_tree); - - switch (result) - { - case GTK_RESPONSE_ACCEPT: - gtk_tree_store_append (GTK_TREE_STORE(model), &iter, NULL); - gtk_tree_store_set (GTK_TREE_STORE(model), &iter, 0, gtk_entry_get_text (header), -1); - break; - } - gtk_widget_destroy (GTK_WIDGET(dialog)); + model = gtk_tree_view_get_model (ui->custom_headers_tree); + gtk_tree_store_append (GTK_TREE_STORE(model), &iter, NULL); + gtk_tree_store_set (GTK_TREE_STORE(model), &iter, 0, gtk_entry_get_text (ui->entry_header), -1); - if (gtk_tree_model_get_iter_first (model, &first)==FALSE) - gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE); + if (gtk_tree_model_get_iter_first (model, &first)!=FALSE) + gtk_widget_set_sensitive (GTK_WIDGET (ui->remove_header), TRUE); + + gtk_entry_set_text (ui->entry_header, ""); + epif_add_sensitivity (ui); } static void -remove_header_clicked (GtkButton *button) +epif_remove_header_clicked (GtkButton *button, EPImapFeaturesData *ui) { GtkTreeSelection *select; GtkTreeModel *model; GtkTreeIter iter, first; - - select = gtk_tree_view_get_selection (custom_headers_tree); + GtkTreePath *path; + gboolean valid = TRUE; + + select = gtk_tree_view_get_selection (ui->custom_headers_tree); if (gtk_tree_selection_get_selected (select, &model, &iter)) { + path = gtk_tree_model_get_path (model, &iter); gtk_tree_store_remove(GTK_TREE_STORE(model), &iter); - } + + if (gtk_tree_path_prev (path)) { + gtk_tree_model_get_iter (model, &iter, path); + } else { + valid = gtk_tree_model_get_iter_first (model, &iter); + } + if (valid) + gtk_tree_selection_select_iter (select, &iter); + } if (gtk_tree_model_get_iter_first (model, &first)==FALSE) gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE); + + epif_add_sensitivity (ui); } static void -fetch_all_headers_toggled (GtkWidget *all_option) +epif_fetch_all_headers_toggled (GtkWidget *all_option, EPImapFeaturesData *ui) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(all_option))) - gtk_widget_set_sensitive (custom_headers_box, FALSE); + gtk_widget_set_sensitive (ui->custom_headers_box, FALSE); else - gtk_widget_set_sensitive (custom_headers_box, TRUE); + gtk_widget_set_sensitive (ui->custom_headers_box, TRUE); } +static void +epif_entry_changed (GtkWidget *entry, EPImapFeaturesData *ui) +{ + epif_add_sensitivity (ui); +} GtkWidget * org_gnome_imap_headers (EPlugin *epl, EConfigHookItemFactoryData *data) @@ -201,7 +258,9 @@ org_gnome_imap_headers (EPlugin *epl, EConfigHookItemFactoryData *data) GladeXML *gladexml; GtkCellRenderer *renderer; GtkTreeViewColumn *column; - GtkTreeIter first; + GtkTreeIter first, iter; + + ui = g_new0 (EPImapFeaturesData, 1); target_account = (EMConfigTargetAccount *)data->config->target; account = target_account->account; @@ -214,18 +273,19 @@ org_gnome_imap_headers (EPlugin *epl, EConfigHookItemFactoryData *data) g_free (gladefile); vbox = glade_xml_get_widget (gladexml, "vbox2"); - all_headers = glade_xml_get_widget (gladexml, "allHeaders"); - basic_headers = glade_xml_get_widget (gladexml, "basicHeaders"); - mailing_list_headers = glade_xml_get_widget (gladexml, "mailingListHeaders"); - custom_headers_box = glade_xml_get_widget (gladexml, "custHeaderHbox"); - custom_headers_tree = GTK_TREE_VIEW(glade_xml_get_widget (gladexml, "custHeaderTree")); - add_header = GTK_BUTTON(glade_xml_get_widget (gladexml, "addHeader")); - remove_header = GTK_BUTTON(glade_xml_get_widget (gladexml, "removeHeader")); + ui->all_headers = glade_xml_get_widget (gladexml, "allHeaders"); + ui->basic_headers = glade_xml_get_widget (gladexml, "basicHeaders"); + ui->mailing_list_headers = glade_xml_get_widget (gladexml, "mailingListHeaders"); + ui->custom_headers_box = glade_xml_get_widget (gladexml, "custHeaderHbox"); + ui->custom_headers_tree = GTK_TREE_VIEW(glade_xml_get_widget (gladexml, "custHeaderTree")); + ui->add_header = GTK_BUTTON(glade_xml_get_widget (gladexml, "addHeader")); + ui->remove_header = GTK_BUTTON(glade_xml_get_widget (gladexml, "removeHeader")); + ui->entry_header = GTK_ENTRY (glade_xml_get_widget (gladexml, "customHeaderEntry")); url = camel_url_new (e_account_get_string(account, E_ACCOUNT_SOURCE_URL), &ex); - store = gtk_tree_store_new (1, G_TYPE_STRING); - gtk_tree_view_set_model (custom_headers_tree, GTK_TREE_MODEL(store)); + ui->store = gtk_tree_store_new (1, G_TYPE_STRING); + gtk_tree_view_set_model (ui->custom_headers_tree, GTK_TREE_MODEL(ui->store)); if (url) { char *custom_headers; @@ -234,39 +294,43 @@ org_gnome_imap_headers (EPlugin *epl, EConfigHookItemFactoryData *data) if (custom_headers) { int i=0; - custom_headers_array = g_strsplit (custom_headers, " ", -1); - while (custom_headers_array[i] ) { - if (strlen(g_strstrip(custom_headers_array[i]))) { - gtk_tree_store_append (store, &iter, NULL); - gtk_tree_store_set (store, &iter, 0, custom_headers_array[i], -1); + ui->custom_headers_array = g_strsplit (custom_headers, " ", -1); + while (ui->custom_headers_array[i] ) { + if (strlen(g_strstrip(ui->custom_headers_array[i]))) { + gtk_tree_store_append (ui->store, &iter, NULL); + gtk_tree_store_set (ui->store, &iter, 0, ui->custom_headers_array[i], -1); } i++; } - g_strfreev (custom_headers_array); + g_strfreev (ui->custom_headers_array); } g_free (custom_headers); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(mailing_list_headers), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->mailing_list_headers), TRUE); if (camel_url_get_param (url, "all_headers")) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(all_headers), TRUE); - gtk_widget_set_sensitive (custom_headers_box, FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->all_headers), TRUE); + gtk_widget_set_sensitive (ui->custom_headers_box, FALSE); } else if (camel_url_get_param (url, "basic_headers")) - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(basic_headers), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->basic_headers), TRUE); camel_url_free (url); } renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes (_("Custom Headers"), renderer, "text", 0, NULL); - gtk_tree_view_append_column (custom_headers_tree , column); + gtk_tree_view_append_column (ui->custom_headers_tree , column); - if (gtk_tree_model_get_iter_first (gtk_tree_view_get_model (custom_headers_tree), &first)==FALSE) - gtk_widget_set_sensitive (GTK_WIDGET (remove_header), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (ui->add_header), FALSE); + if (gtk_tree_model_get_iter_first (gtk_tree_view_get_model (ui->custom_headers_tree), &first)==FALSE) + gtk_widget_set_sensitive (GTK_WIDGET (ui->remove_header), FALSE); - g_signal_connect (all_headers, "toggled", G_CALLBACK(fetch_all_headers_toggled), NULL); - g_signal_connect (add_header, "clicked", G_CALLBACK(add_header_clicked), NULL); - g_signal_connect (remove_header, "clicked", G_CALLBACK(remove_header_clicked), NULL); + g_signal_connect (ui->all_headers, "toggled", G_CALLBACK (epif_fetch_all_headers_toggled), ui); + g_signal_connect (ui->add_header, "clicked", G_CALLBACK (epif_add_header), ui); + g_signal_connect (ui->remove_header, "clicked", G_CALLBACK (epif_remove_header_clicked), ui); + g_signal_connect (ui->entry_header, "changed", G_CALLBACK (epif_entry_changed), ui); + g_signal_connect (ui->entry_header, "activate", G_CALLBACK (epif_add_header), ui); gtk_notebook_append_page ((GtkNotebook *)(data->parent), vbox, gtk_label_new(_("IMAP Headers"))); gtk_widget_show_all (vbox); - return NULL; + + return GTK_WIDGET (vbox); } diff --git a/plugins/imap-features/imap-headers.glade b/plugins/imap-features/imap-headers.glade index 0f910cc535..542decd608 100644 --- a/plugins/imap-features/imap-headers.glade +++ b/plugins/imap-features/imap-headers.glade @@ -234,26 +234,58 @@ You can ignore this if you choose "All Headers".</property> <property name="spacing">5</property> <child> - <widget class="GtkScrolledWindow" id="scrolledwindow1"> + <widget class="GtkVBox" id="customHeaderVBox"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_IN</property> - <property name="window_placement">GTK_CORNER_TOP_LEFT</property> + <property name="homogeneous">False</property> + <property name="spacing">6</property> <child> - <widget class="GtkTreeView" id="custHeaderTree"> + <widget class="GtkEntry" id="customHeaderEntry"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="headers_visible">False</property> - <property name="rules_hint">False</property> - <property name="reorderable">False</property> - <property name="enable_search">True</property> - <property name="fixed_height_mode">False</property> - <property name="hover_selection">False</property> - <property name="hover_expand">False</property> + <property name="editable">True</property> + <property name="visibility">True</property> + <property name="max_length">0</property> + <property name="text" translatable="yes"></property> + <property name="has_frame">True</property> + <property name="invisible_char">*</property> + <property name="activates_default">False</property> </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">True</property> + </packing> + </child> + + <child> + <widget class="GtkScrolledWindow" id="scrolledwindow1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> + <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> + <property name="shadow_type">GTK_SHADOW_IN</property> + <property name="window_placement">GTK_CORNER_TOP_LEFT</property> + + <child> + <widget class="GtkTreeView" id="custHeaderTree"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="headers_visible">False</property> + <property name="rules_hint">False</property> + <property name="reorderable">False</property> + <property name="enable_search">True</property> + <property name="fixed_height_mode">False</property> + <property name="hover_selection">False</property> + <property name="hover_expand">False</property> + </widget> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> </child> </widget> <packing> @@ -264,50 +296,37 @@ You can ignore this if you choose "All Headers".</property> </child> <child> - <widget class="GtkVBox" id="vbox3"> + <widget class="GtkVButtonBox" id="vbuttonbox1"> <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">0</property> + <property name="layout_style">GTK_BUTTONBOX_START</property> + <property name="spacing">6</property> <child> - <widget class="GtkVButtonBox" id="vbuttonbox1"> + <widget class="GtkButton" id="addHeader"> <property name="visible">True</property> - <property name="layout_style">GTK_BUTTONBOX_DEFAULT_STYLE</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkButton" id="addHeader"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-add</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - </widget> - </child> + <property name="can_focus">True</property> + <property name="label">gtk-add</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + </widget> + </child> - <child> - <widget class="GtkButton" id="removeHeader"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-remove</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - </widget> - </child> + <child> + <widget class="GtkButton" id="removeHeader"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label">gtk-remove</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> </widget> - <packing> - <property name="padding">4</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> </child> </widget> <packing> - <property name="padding">0</property> + <property name="padding">4</property> <property name="expand">False</property> - <property name="fill">True</property> + <property name="fill">False</property> </packing> </child> </widget> |