/soc/2013/ankitkv/gobjectification: 6587e5c7d9e3: Merged soc.201...
Ankit Vani
a at nevitus.org
Mon Oct 28 11:28:56 EDT 2013
Changeset: 6587e5c7d9e39ecc0bfd1a1934fe869047692c4e
Author: Ankit Vani <a at nevitus.org>
Date: 2013-10-28 20:58 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/6587e5c7d9e3
Description:
Merged soc.2013.gobjectification branch
diffstat:
libpurple/request.c | 44 ++++++++++++++++++
libpurple/request.h | 43 ++++++++++++++++++
pidgin/gtkrequest.c | 121 ++++++++++++++++++++++++++++++++++++++-------------
3 files changed, 177 insertions(+), 31 deletions(-)
diffs (truncated from 331 to 300 lines):
diff --git a/libpurple/request.c b/libpurple/request.c
--- a/libpurple/request.c
+++ b/libpurple/request.c
@@ -147,6 +147,8 @@ struct _PurpleRequestFields
GHashTable *fields;
+ gchar **tab_names;
+
GList *required_fields;
GList *validated_fields;
@@ -161,6 +163,7 @@ struct _PurpleRequestFieldGroup
PurpleRequestFields *fields_list;
char *title;
+ gint tab_no;
GList *fields;
};
@@ -494,6 +497,7 @@ purple_request_fields_destroy(PurpleRequ
{
g_return_if_fail(fields != NULL);
+ g_strfreev(fields->tab_names);
g_list_foreach(fields->groups, (GFunc)purple_request_field_group_destroy, NULL);
g_list_free(fields->groups);
g_list_free(fields->required_fields);
@@ -551,6 +555,32 @@ purple_request_fields_get_groups(const P
return fields->groups;
}
+void
+purple_request_fields_set_tab_names(PurpleRequestFields *fields,
+ const gchar **tab_names)
+{
+ guint i, tab_count;
+ gchar **new_names;
+
+ g_return_if_fail(fields != NULL);
+
+ tab_count = (tab_names != NULL) ? g_strv_length((gchar **)tab_names) : 0;
+ new_names = (tab_count > 0) ? g_new0(gchar*, tab_count + 1) : NULL;
+ for (i = 0; i < tab_count; i++)
+ new_names[i] = g_strdup(tab_names[i]);
+
+ g_strfreev(fields->tab_names);
+ fields->tab_names = new_names;
+}
+
+const gchar **
+purple_request_fields_get_tab_names(const PurpleRequestFields *fields)
+{
+ g_return_val_if_fail(fields != NULL, NULL);
+
+ return (const gchar **)fields->tab_names;
+}
+
gboolean
purple_request_fields_exists(const PurpleRequestFields *fields, const char *id)
{
@@ -798,6 +828,20 @@ purple_request_field_group_new(const cha
}
void
+purple_request_field_group_set_tab(PurpleRequestFieldGroup *group, guint tab_no)
+{
+ g_return_if_fail(group != NULL);
+
+ group->tab_no = tab_no;
+}
+
+guint
+purple_request_field_group_get_tab(const PurpleRequestFieldGroup *group)
+{
+ return group->tab_no;
+}
+
+void
purple_request_field_group_destroy(PurpleRequestFieldGroup *group)
{
g_return_if_fail(group != NULL);
diff --git a/libpurple/request.h b/libpurple/request.h
--- a/libpurple/request.h
+++ b/libpurple/request.h
@@ -488,6 +488,27 @@ void purple_request_fields_add_group(Pur
GList *purple_request_fields_get_groups(const PurpleRequestFields *fields);
/**
+ * Set tab names for a field list.
+ *
+ * @param fields The fields list.
+ * @param tab_names NULL-terminated array of localized tab labels,
+ * may be @c NULL.
+ */
+void purple_request_fields_set_tab_names(PurpleRequestFields *fields,
+ const gchar **tab_names);
+
+/**
+ * Returns tab names of a field list.
+ *
+ * @param fields The fields list.
+ *
+ * @return NULL-terminated array of localized tab labels, or NULL if tabs
+ * are disabled.
+ */
+const gchar **
+purple_request_fields_get_tab_names(const PurpleRequestFields *fields);
+
+/**
* Returns whether or not the field with the specified ID exists.
*
* @param fields The fields list.
@@ -661,6 +682,28 @@ void purple_request_fields_set_ui_data(P
PurpleRequestFieldGroup *purple_request_field_group_new(const char *title);
/**
+ * Sets tab number for a group.
+ *
+ * @param group The group.
+ * @param tab_no The tab number.
+ *
+ * @see purple_request_fields_set_tab_names
+ */
+void purple_request_field_group_set_tab(PurpleRequestFieldGroup *group,
+ guint tab_no);
+
+/**
+ * Returns tab number of a group.
+ *
+ * @param group The group.
+ *
+ * @return Tab number.
+ *
+ * @see purple_request_fields_get_tab_names
+ */
+guint purple_request_field_group_get_tab(const PurpleRequestFieldGroup *group);
+
+/**
* Destroys a fields group.
*
* @param group The group to destroy.
diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -1577,9 +1577,9 @@ pidgin_request_fields(const char *title,
{
PidginRequestData *data;
GtkWidget *win;
- GtkWidget *vbox;
- GtkWidget *vbox2;
- GtkWidget *hbox;
+ GtkNotebook *notebook;
+ GtkWidget **pages;
+ GtkWidget *hbox, *vbox;
GtkWidget *frame;
GtkWidget *label;
GtkWidget *table;
@@ -1591,10 +1591,11 @@ pidgin_request_fields(const char *title,
PurpleRequestField *field;
char *label_text;
char *primary_esc, *secondary_esc;
- int total_fields = 0;
const gboolean compact = purple_request_cpar_is_compact(cpar);
GSList *extra_actions, *it;
size_t extra_actions_count, i;
+ const gchar **tab_names;
+ guint tab_count;
data = g_new0(PidginRequestData, 1);
data->type = PURPLE_REQUEST_FIELDS;
@@ -1681,30 +1682,72 @@ pidgin_request_fields(const char *title,
g_free(label_text);
}
- for (gl = purple_request_fields_get_groups(fields); gl != NULL;
- gl = gl->next)
- total_fields += g_list_length(purple_request_field_group_get_fields(gl->data));
-
- if(total_fields > 9) {
- GtkWidget *hbox_for_spacing, *vbox_for_spacing;
-
- hbox_for_spacing = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER);
- gtk_box_pack_start(GTK_BOX(vbox),
- pidgin_make_scrollable(hbox_for_spacing, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC, GTK_SHADOW_NONE, -1, 200),
- TRUE, TRUE, 0);
- gtk_widget_show(hbox_for_spacing);
-
- vbox_for_spacing = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER);
- gtk_box_pack_start(GTK_BOX(hbox_for_spacing),
- vbox_for_spacing, TRUE, TRUE, PIDGIN_HIG_BOX_SPACE);
- gtk_widget_show(vbox_for_spacing);
-
- vbox2 = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER);
- gtk_box_pack_start(GTK_BOX(vbox_for_spacing),
- vbox2, TRUE, TRUE, PIDGIN_HIG_BOX_SPACE);
- gtk_widget_show(vbox2);
+ /* Setup tabs */
+ tab_names = purple_request_fields_get_tab_names(fields);
+ if (tab_names == NULL) {
+ notebook = NULL;
+ tab_count = 1;
+
+ pages = g_new0(GtkWidget*, 1);
+ pages[0] = vbox;
} else {
- vbox2 = vbox;
+ tab_count = g_strv_length((gchar **)tab_names);
+ notebook = GTK_NOTEBOOK(gtk_notebook_new());
+
+ pages = g_new0(GtkWidget*, tab_count);
+
+ for (i = 0; i < tab_count; i++) {
+ pages[i] = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER);
+ gtk_container_set_border_width(GTK_CONTAINER(pages[i]), PIDGIN_HIG_BORDER);
+ gtk_notebook_append_page(notebook, pages[i], NULL);
+ gtk_notebook_set_tab_label_text(notebook, pages[i], tab_names[i]);
+ gtk_widget_show(pages[i]);
+ }
+ }
+
+ for (i = 0; i < tab_count; i++) {
+ guint total_fields = 0;
+ GList *it;
+
+ it = purple_request_fields_get_groups(fields);
+ for (; it != NULL; it = g_list_next(it)) {
+ group = it->data;
+ if (purple_request_field_group_get_tab(group) != i)
+ continue;
+ total_fields += g_list_length(
+ purple_request_field_group_get_fields(group));
+ }
+
+ if(total_fields > 9) {
+ GtkWidget *hbox_for_spacing, *vbox_for_spacing;
+
+ gtk_container_set_border_width(
+ GTK_CONTAINER(pages[i]), 0);
+
+ hbox_for_spacing =
+ gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER);
+ gtk_box_pack_start(GTK_BOX(pages[i]),
+ pidgin_make_scrollable(hbox_for_spacing,
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC,
+ GTK_SHADOW_NONE, -1, 200),
+ TRUE, TRUE, 0);
+ gtk_widget_show(hbox_for_spacing);
+
+ vbox_for_spacing =
+ gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER);
+ gtk_box_pack_start(GTK_BOX(hbox_for_spacing),
+ vbox_for_spacing, TRUE, TRUE,
+ PIDGIN_HIG_BOX_SPACE);
+ gtk_widget_show(vbox_for_spacing);
+
+ pages[i] = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER);
+ gtk_box_pack_start(GTK_BOX(vbox_for_spacing),
+ pages[i], TRUE, TRUE, PIDGIN_HIG_BOX_SPACE);
+ gtk_widget_show(pages[i]);
+ }
+
+ if (notebook == NULL)
+ vbox = pages[0];
}
if (secondary) {
@@ -1715,10 +1758,16 @@ pidgin_request_fields(const char *title,
g_free(secondary_esc);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
- gtk_box_pack_start(GTK_BOX(vbox2), label, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), label, (notebook == NULL),
+ (notebook == NULL), 0);
gtk_widget_show(label);
}
+ if (notebook != NULL) {
+ gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(notebook), TRUE, TRUE, 0);
+ gtk_widget_show(GTK_WIDGET(notebook));
+ }
+
for (gl = purple_request_fields_get_groups(fields);
gl != NULL;
gl = gl->next)
@@ -1729,17 +1778,24 @@ pidgin_request_fields(const char *title,
size_t rows;
size_t col_num;
size_t row_num = 0;
+ guint tab_no;
group = gl->data;
field_list = purple_request_field_group_get_fields(group);
+ tab_no = purple_request_field_group_get_tab(group);
+ if (tab_no >= tab_count) {
+ purple_debug_warning("gtkrequest",
+ "Invalid tab number: %d", tab_no);
+ tab_no = 0;
+ }
More information about the Commits
mailing list