aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@gnome-db.org>2011-11-08 19:48:40 +0800
committerRodrigo Moya <rodrigo@gnome-db.org>2011-11-08 19:48:40 +0800
commit1107fea0f8edff76d5956426044c9afe41c387fa (patch)
tree3140debb1cef6c058425360e0c43b6c55da75f3a /widgets
parentceda5ef420b4a4b97ce0011d49be3f96e857c9ef (diff)
parent88d5608a97ebaee9c04c3e8ac6b79278e824ecee (diff)
downloadgsoc2013-evolution-1107fea0f8edff76d5956426044c9afe41c387fa.tar.gz
gsoc2013-evolution-1107fea0f8edff76d5956426044c9afe41c387fa.tar.zst
gsoc2013-evolution-1107fea0f8edff76d5956426044c9afe41c387fa.zip
Merge branch 'master' into wip/gsettings
Diffstat (limited to 'widgets')
-rw-r--r--widgets/misc/Makefile.am2
-rw-r--r--widgets/misc/e-auth-combo-box.c260
-rw-r--r--widgets/misc/e-auth-combo-box.h71
-rw-r--r--widgets/misc/e-port-entry.c230
4 files changed, 451 insertions, 112 deletions
diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am
index 79bc14bcbe..5235c1ca54 100644
--- a/widgets/misc/Makefile.am
+++ b/widgets/misc/Makefile.am
@@ -23,6 +23,7 @@ widgetsinclude_HEADERS = \
e-attachment-store.h \
e-attachment-tree-view.h \
e-attachment-view.h \
+ e-auth-combo-box.h \
e-buffer-tagger.h \
e-calendar.h \
e-calendar-item.h \
@@ -107,6 +108,7 @@ libemiscwidgets_la_SOURCES = \
e-attachment-store.c \
e-attachment-tree-view.c \
e-attachment-view.c \
+ e-auth-combo-box.c \
e-buffer-tagger.c \
e-calendar.c \
e-calendar-item.c \
diff --git a/widgets/misc/e-auth-combo-box.c b/widgets/misc/e-auth-combo-box.c
new file mode 100644
index 0000000000..182e171c00
--- /dev/null
+++ b/widgets/misc/e-auth-combo-box.c
@@ -0,0 +1,260 @@
+/*
+ * e-auth-combo-box.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-auth-combo-box.h"
+
+#define E_AUTH_COMBO_BOX_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_AUTH_COMBO_BOX, EAuthComboBoxPrivate))
+
+struct _EAuthComboBoxPrivate {
+ CamelProvider *provider;
+};
+
+enum {
+ PROP_0,
+ PROP_PROVIDER
+};
+
+enum {
+ COLUMN_MECHANISM,
+ COLUMN_DISPLAY_NAME,
+ COLUMN_STRIKETHROUGH,
+ COLUMN_AUTHTYPE,
+ NUM_COLUMNS
+};
+
+G_DEFINE_TYPE (
+ EAuthComboBox,
+ e_auth_combo_box,
+ GTK_TYPE_COMBO_BOX)
+
+static void
+auth_combo_box_rebuild_model (EAuthComboBox *combo_box)
+{
+ GtkComboBox *gtk_combo_box;
+ CamelProvider *provider;
+ GtkTreeModel *model;
+ GList *link;
+ const gchar *active_id;
+
+ provider = e_auth_combo_box_get_provider (combo_box);
+
+ gtk_combo_box = GTK_COMBO_BOX (combo_box);
+ model = gtk_combo_box_get_model (gtk_combo_box);
+ active_id = gtk_combo_box_get_active_id (gtk_combo_box);
+
+ gtk_list_store_clear (GTK_LIST_STORE (model));
+
+ if (provider == NULL)
+ return;
+
+ for (link = provider->authtypes; link != NULL; link = link->next) {
+ CamelServiceAuthType *authtype = link->data;
+ GtkTreeIter iter;
+
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+
+ gtk_list_store_set (
+ GTK_LIST_STORE (model), &iter,
+ COLUMN_MECHANISM, authtype->authproto,
+ COLUMN_DISPLAY_NAME, authtype->name,
+ COLUMN_AUTHTYPE, authtype,
+ -1);
+ }
+
+ /* Try selecting the previous mechanism. */
+ if (active_id != NULL)
+ gtk_combo_box_set_active_id (gtk_combo_box, active_id);
+
+ /* Or else fall back to the first mechanism. */
+ if (gtk_combo_box_get_active (gtk_combo_box) == -1)
+ gtk_combo_box_set_active (gtk_combo_box, 0);
+}
+
+static void
+auth_combo_box_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_PROVIDER:
+ e_auth_combo_box_set_provider (
+ E_AUTH_COMBO_BOX (object),
+ g_value_get_pointer (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+auth_combo_box_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_PROVIDER:
+ g_value_set_pointer (
+ value,
+ e_auth_combo_box_get_provider (
+ E_AUTH_COMBO_BOX (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+auth_combo_box_constructed (GObject *object)
+{
+ GtkComboBox *combo_box;
+ GtkListStore *list_store;
+ GtkCellLayout *cell_layout;
+ GtkCellRenderer *cell_renderer;
+
+ /* Chain up to parent's constructed() method. */
+ G_OBJECT_CLASS (e_auth_combo_box_parent_class)->constructed (object);
+
+ list_store = gtk_list_store_new (
+ NUM_COLUMNS,
+ G_TYPE_STRING, /* COLUMN_MECHANISM */
+ G_TYPE_STRING, /* COLUMN_DISPLAY_NAME */
+ G_TYPE_BOOLEAN, /* COLUMN_STRIKETHROUGH */
+ G_TYPE_POINTER); /* COLUMN_AUTHTYPE */
+
+ combo_box = GTK_COMBO_BOX (object);
+ gtk_combo_box_set_model (combo_box, GTK_TREE_MODEL (list_store));
+ gtk_combo_box_set_id_column (combo_box, COLUMN_MECHANISM);
+ g_object_unref (list_store);
+
+ cell_layout = GTK_CELL_LAYOUT (object);
+ cell_renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (cell_layout, cell_renderer, TRUE);
+
+ gtk_cell_layout_set_attributes (
+ cell_layout, cell_renderer,
+ "text", COLUMN_DISPLAY_NAME,
+ "strikethrough", COLUMN_STRIKETHROUGH,
+ NULL);
+}
+
+static void
+e_auth_combo_box_class_init (EAuthComboBoxClass *class)
+{
+ GObjectClass *object_class;
+
+ g_type_class_add_private (class, sizeof (EAuthComboBoxPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = auth_combo_box_set_property;
+ object_class->get_property = auth_combo_box_get_property;
+ object_class->constructed = auth_combo_box_constructed;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_PROVIDER,
+ g_param_spec_pointer (
+ "provider",
+ "Provider",
+ "The provider to query for auth mechanisms",
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+e_auth_combo_box_init (EAuthComboBox *combo_box)
+{
+ combo_box->priv = E_AUTH_COMBO_BOX_GET_PRIVATE (combo_box);
+}
+
+CamelProvider *
+e_auth_combo_box_get_provider (EAuthComboBox *combo_box)
+{
+ g_return_val_if_fail (E_IS_AUTH_COMBO_BOX (combo_box), NULL);
+
+ return combo_box->priv->provider;
+}
+
+void
+e_auth_combo_box_set_provider (EAuthComboBox *combo_box,
+ CamelProvider *provider)
+{
+ g_return_if_fail (E_IS_AUTH_COMBO_BOX (combo_box));
+
+ if (provider == combo_box->priv->provider)
+ return;
+
+ combo_box->priv->provider = provider;
+
+ g_object_notify (G_OBJECT (combo_box), "provider");
+
+ auth_combo_box_rebuild_model (combo_box);
+}
+
+void
+e_auth_combo_box_update_available (EAuthComboBox *combo_box,
+ GList *available_authtypes)
+{
+ GtkComboBox *gtk_combo_box;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint active_index;
+ gint available_index = -1;
+ gint index = 0;
+ gboolean iter_set;
+
+ g_return_if_fail (E_IS_AUTH_COMBO_BOX (combo_box));
+
+ gtk_combo_box = GTK_COMBO_BOX (combo_box);
+ model = gtk_combo_box_get_model (gtk_combo_box);
+ active_index = gtk_combo_box_get_active (gtk_combo_box);
+
+ iter_set = gtk_tree_model_get_iter_first (model, &iter);
+
+ while (iter_set) {
+ CamelServiceAuthType *authtype;
+ gboolean available;
+
+ gtk_tree_model_get (
+ model, &iter, COLUMN_AUTHTYPE, &authtype, -1);
+
+ available = (g_list_find (
+ available_authtypes, authtype) != NULL);
+
+ gtk_list_store_set (
+ GTK_LIST_STORE (model), &iter,
+ COLUMN_STRIKETHROUGH, !available, -1);
+
+ if (index == active_index && !available)
+ active_index = -1;
+
+ if (available && available_index == -1)
+ available_index = index;
+
+ iter_set = gtk_tree_model_iter_next (model, &iter);
+ index++;
+ }
+
+ /* If the active combo_box item turned out to be unavailable
+ * (or there was no active item), select the first available. */
+ if (active_index == -1 && available_index != -1)
+ gtk_combo_box_set_active (gtk_combo_box, available_index);
+}
diff --git a/widgets/misc/e-auth-combo-box.h b/widgets/misc/e-auth-combo-box.h
new file mode 100644
index 0000000000..e449f1c06b
--- /dev/null
+++ b/widgets/misc/e-auth-combo-box.h
@@ -0,0 +1,71 @@
+/*
+ * e-auth-combo-box.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_AUTH_COMBO_BOX_H
+#define E_AUTH_COMBO_BOX_H
+
+#include <gtk/gtk.h>
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define E_TYPE_AUTH_COMBO_BOX \
+ (e_auth_combo_box_get_type ())
+#define E_AUTH_COMBO_BOX(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_AUTH_COMBO_BOX, EAuthComboBox))
+#define E_AUTH_COMBO_BOX_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_AUTH_COMBO_BOX, EAuthComboBoxClass))
+#define E_IS_AUTH_COMBO_BOX(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_AUTH_COMBO_BOX))
+#define E_IS_AUTH_COMBO_BOX_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_AUTH_COMBO_BOX))
+#define E_AUTH_COMBO_BOX_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_AUTH_COMBO_BOX, EAuthComboBoxClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EAuthComboBox EAuthComboBox;
+typedef struct _EAuthComboBoxClass EAuthComboBoxClass;
+typedef struct _EAuthComboBoxPrivate EAuthComboBoxPrivate;
+
+struct _EAuthComboBox {
+ GtkComboBox parent;
+ EAuthComboBoxPrivate *priv;
+};
+
+struct _EAuthComboBoxClass {
+ GtkComboBoxClass parent_class;
+};
+
+GType e_auth_combo_box_get_type (void) G_GNUC_CONST;
+GtkWidget * e_auth_combo_box_new (void);
+CamelProvider * e_auth_combo_box_get_provider (EAuthComboBox *combo_box);
+void e_auth_combo_box_set_provider (EAuthComboBox *combo_box,
+ CamelProvider *provider);
+void e_auth_combo_box_update_available
+ (EAuthComboBox *combo_box,
+ GList *available_authtypes);
+
+G_END_DECLS
+
+#endif /* E_AUTH_COMBO_BOX_H */
+
diff --git a/widgets/misc/e-port-entry.c b/widgets/misc/e-port-entry.c
index dd27ffa371..cc90302771 100644
--- a/widgets/misc/e-port-entry.c
+++ b/widgets/misc/e-port-entry.c
@@ -11,19 +11,20 @@
* Dan Vratil <dvratil@redhat.com>
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#include "e-port-entry.h"
+#include <config.h>
+#include <errno.h>
#include <stddef.h>
#include <string.h>
+#define E_PORT_ENTRY_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_PORT_ENTRY, EPortEntryPrivate))
+
struct _EPortEntryPrivate {
- guint port;
- gboolean is_valid;
CamelNetworkSecurityMethod method;
+ CamelProviderPortEntry *entries;
};
enum {
@@ -44,89 +45,98 @@ G_DEFINE_TYPE (
e_port_entry,
GTK_TYPE_COMBO_BOX)
-static void
-port_entry_set_is_valid (EPortEntry *port_entry,
- gboolean is_valid)
+static GtkEntry *
+port_entry_get_entry (EPortEntry *port_entry)
{
- g_return_if_fail (E_IS_PORT_ENTRY (port_entry));
-
- port_entry->priv->is_valid = is_valid;
-
- g_object_notify (G_OBJECT (port_entry), "is-valid");
+ return GTK_ENTRY (gtk_bin_get_child (GTK_BIN (port_entry)));
}
-/**
- * Returns number of port currently selected in the widget, no matter
- * what value is in the PORT property
- */
-static gint
-port_entry_get_model_active_port (EPortEntry *port_entry)
+static gboolean
+port_entry_get_numeric_port (EPortEntry *port_entry,
+ gint *out_port)
{
- const gchar *port;
+ GtkEntry *entry;
+ const gchar *port_string;
+ gboolean valid;
+ gint port;
- port = gtk_combo_box_get_active_id (GTK_COMBO_BOX (port_entry));
+ entry = port_entry_get_entry (port_entry);
- if (!port) {
- GtkWidget *entry = gtk_bin_get_child (GTK_BIN (port_entry));
- port = gtk_entry_get_text (GTK_ENTRY (entry));
- }
+ port_string = gtk_entry_get_text (entry);
+ g_return_val_if_fail (port_string != NULL, FALSE);
+
+ errno = 0;
+ port = strtol (port_string, NULL, 10);
+ valid = (errno == 0) && (port == CLAMP (port, 1, G_MAXUINT16));
- return atoi (port);
+ if (valid && out_port != NULL)
+ *out_port = port;
+
+ return valid;
}
static void
-port_entry_port_changed (EPortEntry *port_entry)
+port_entry_text_changed (GtkEditable *editable,
+ EPortEntry *port_entry)
{
- GtkTreeModel *model;
- GtkTreeIter iter;
- const gchar *port;
- const gchar *tooltip;
-
- g_return_if_fail (E_IS_PORT_ENTRY (port_entry));
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (port_entry));
- g_return_if_fail (model);
-
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (port_entry), &iter)) {
- GtkWidget *entry = gtk_bin_get_child (GTK_BIN (port_entry));
- port = gtk_entry_get_text (GTK_ENTRY (entry));
-
- /* Try if user just haven't happened to enter a default port */
- gtk_combo_box_set_active_id (GTK_COMBO_BOX (port_entry), port);
- } else {
- gtk_tree_model_get (model, &iter, PORT_NUM_COLUMN, &port, -1);
+ GObject *object = G_OBJECT (port_entry);
+ const gchar *desc = NULL;
+ gint port = 0;
+ gint ii = 0;
+
+ g_object_freeze_notify (object);
+
+ port_entry_get_numeric_port (port_entry, &port);
+
+ if (port_entry->priv->entries != NULL) {
+ while (port_entry->priv->entries[ii].port > 0) {
+ if (port == port_entry->priv->entries[ii].port) {
+ desc = port_entry->priv->entries[ii].desc;
+ break;
+ }
+ ii++;
+ }
}
- if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (port_entry), &iter)) {
- gtk_tree_model_get (model, &iter, PORT_DESC_COLUMN, &tooltip, -1);
- gtk_widget_set_tooltip_text (GTK_WIDGET (port_entry), tooltip);
- } else {
+ if (desc != NULL)
+ gtk_widget_set_tooltip_text (GTK_WIDGET (port_entry), desc);
+ else
gtk_widget_set_has_tooltip (GTK_WIDGET (port_entry), FALSE);
- }
- if (port == NULL || *port == '\0') {
- port_entry->priv->port = 0;
- port_entry_set_is_valid (port_entry, FALSE);
- } else {
- port_entry->priv->port = atoi (port);
- if ((port_entry->priv->port <= 0) ||
- (port_entry->priv->port > G_MAXUINT16)) {
- port_entry->priv->port = 0;
- port_entry_set_is_valid (port_entry, FALSE);
- } else {
- port_entry_set_is_valid (port_entry, TRUE);
- }
- }
+ g_object_notify (object, "port");
+ g_object_notify (object, "is-valid");
- g_object_notify (G_OBJECT (port_entry), "port");
+ g_object_thaw_notify (object);
}
static void
port_entry_method_changed (EPortEntry *port_entry)
{
CamelNetworkSecurityMethod method;
+ gboolean standard_port = FALSE;
+ gboolean valid;
+ gint port = 0;
+ gint ii = 0;
method = e_port_entry_get_security_method (port_entry);
+ valid = port_entry_get_numeric_port (port_entry, &port);
+
+ /* Only change the port number if it's currently on a standard
+ * port (i.e. listed in a CamelProviderPortEntry). Otherwise,
+ * leave custom port numbers alone. */
+
+ if (valid && port_entry->priv->entries != NULL) {
+ while (port_entry->priv->entries[ii].port > 0) {
+ if (port == port_entry->priv->entries[ii].port) {
+ standard_port = TRUE;
+ break;
+ }
+ ii++;
+ }
+ }
+
+ if (valid && !standard_port)
+ return;
switch (method) {
case CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT:
@@ -145,12 +155,6 @@ port_entry_set_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_IS_VALID:
- port_entry_set_is_valid (
- E_PORT_ENTRY (object),
- g_value_get_boolean (value));
- return;
-
case PROP_PORT:
e_port_entry_set_port (
E_PORT_ENTRY (object),
@@ -197,6 +201,21 @@ port_entry_get_property (GObject *object,
}
static void
+port_entry_constructed (GObject *object)
+{
+ GtkEntry *entry;
+
+ /* Chain up to parent's constructed() method. */
+ G_OBJECT_CLASS (e_port_entry_parent_class)->constructed (object);
+
+ entry = port_entry_get_entry (E_PORT_ENTRY (object));
+
+ g_signal_connect_after (
+ entry, "changed",
+ G_CALLBACK (port_entry_text_changed), object);
+}
+
+static void
port_entry_get_preferred_width (GtkWidget *widget,
gint *minimum_size,
gint *natural_size)
@@ -204,7 +223,7 @@ port_entry_get_preferred_width (GtkWidget *widget,
PangoContext *context;
PangoFontMetrics *metrics;
PangoFontDescription *font_desc;
- GtkStyleContext *style_context;
+ GtkStyleContext *style_context;
GtkStateFlags state;
gint digit_width;
gint parent_entry_width_min;
@@ -257,6 +276,7 @@ e_port_entry_class_init (EPortEntryClass *class)
object_class = G_OBJECT_CLASS (class);
object_class->set_property = port_entry_set_property;
object_class->get_property = port_entry_get_property;
+ object_class->constructed = port_entry_constructed;
widget_class = GTK_WIDGET_CLASS (class);
widget_class->get_preferred_width = port_entry_get_preferred_width;
@@ -304,10 +324,7 @@ e_port_entry_init (EPortEntry *port_entry)
GtkCellRenderer *renderer;
GtkListStore *store;
- port_entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (
- port_entry, E_TYPE_PORT_ENTRY, EPortEntryPrivate);
- port_entry->priv->port = 0;
- port_entry->priv->is_valid = FALSE;
+ port_entry->priv = E_PORT_ENTRY_GET_PRIVATE (port_entry);
store = gtk_list_store_new (
3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
@@ -335,11 +352,6 @@ e_port_entry_init (EPortEntry *port_entry)
GTK_CELL_LAYOUT (port_entry),
renderer, "text", PORT_DESC_COLUMN);
- /* Update the port property when port is changed */
- g_signal_connect (
- port_entry, "changed",
- G_CALLBACK (port_entry_port_changed), NULL);
-
g_signal_connect (
port_entry, "notify::security-method",
G_CALLBACK (port_entry_method_changed), NULL);
@@ -356,22 +368,31 @@ void
e_port_entry_set_camel_entries (EPortEntry *port_entry,
CamelProviderPortEntry *entries)
{
+ GtkComboBox *combo_box;
GtkTreeIter iter;
GtkTreeModel *model;
GtkListStore *store;
+ gint port = 0;
gint i = 0;
g_return_if_fail (E_IS_PORT_ENTRY (port_entry));
g_return_if_fail (entries);
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (port_entry));
- store = GTK_LIST_STORE (model);
+ port_entry->priv->entries = entries;
+
+ combo_box = GTK_COMBO_BOX (port_entry);
+ model = gtk_combo_box_get_model (combo_box);
+ store = GTK_LIST_STORE (model);
gtk_list_store_clear (store);
while (entries[i].port > 0) {
gchar *port_string;
+ /* Grab the first port number. */
+ if (port == 0)
+ port = entries[i].port;
+
port_string = g_strdup_printf ("%i", entries[i].port);
gtk_list_store_append (store, &iter);
@@ -386,49 +407,34 @@ e_port_entry_set_camel_entries (EPortEntry *port_entry,
g_free (port_string);
}
- /* Activate the first port */
- if (i > 0)
- e_port_entry_set_port (port_entry, entries[0].port);
+ e_port_entry_set_port (port_entry, port);
}
gint
e_port_entry_get_port (EPortEntry *port_entry)
{
+ gint port = 0;
+
g_return_val_if_fail (E_IS_PORT_ENTRY (port_entry), 0);
- return port_entry->priv->port;
+ port_entry_get_numeric_port (port_entry, &port);
+
+ return port;
}
void
e_port_entry_set_port (EPortEntry *port_entry,
gint port)
{
- g_return_if_fail (E_IS_PORT_ENTRY (port_entry));
-
- port_entry->priv->port = port;
- if ((port <= 0) || (port > G_MAXUINT16))
- port_entry_set_is_valid (port_entry, FALSE);
- else {
- gchar *port_string;
-
- port_string = g_strdup_printf ("%i", port);
-
- gtk_combo_box_set_active_id (
- GTK_COMBO_BOX (port_entry), port_string);
+ GtkEntry *entry;
+ gchar *port_string;
- if (port_entry_get_model_active_port (port_entry) != port) {
- GtkWidget *entry;
-
- entry = gtk_bin_get_child (GTK_BIN (port_entry));
- gtk_entry_set_text (GTK_ENTRY (entry), port_string);
- }
-
- port_entry_set_is_valid (port_entry, TRUE);
-
- g_free (port_string);
- }
+ g_return_if_fail (E_IS_PORT_ENTRY (port_entry));
- g_object_notify (G_OBJECT (port_entry), "port");
+ entry = port_entry_get_entry (port_entry);
+ port_string = g_strdup_printf ("%i", port);
+ gtk_entry_set_text (entry, port_string);
+ g_free (port_string);
}
gboolean
@@ -436,7 +442,7 @@ e_port_entry_is_valid (EPortEntry *port_entry)
{
g_return_val_if_fail (E_IS_PORT_ENTRY (port_entry), FALSE);
- return port_entry->priv->is_valid;
+ return port_entry_get_numeric_port (port_entry, NULL);
}
CamelNetworkSecurityMethod