pidgin/pidgin

Make PurpleRequestFieldLabel into a GObject

14 months ago, Elliott Sales de Andrade
7ecf7a18e627
Parents beba61bbdf19
Children 809019093568
Make PurpleRequestFieldLabel into a GObject

This also does an `hg cp`, though with this being so so short, maybe that wasn't as useful for tracking the diff.

Testing Done:
Compiled and opened Request Fields from the Demo protocol.

Reviewed at https://reviews.imfreedom.org/r/2337/
--- a/libpurple/meson.build Fri Mar 10 17:17:53 2023 -0600
+++ b/libpurple/meson.build Fri Mar 10 17:25:22 2023 -0600
@@ -101,6 +101,7 @@
'request/purplerequestfieldbool.c',
'request/purplerequestfieldchoice.c',
'request/purplerequestfieldint.c',
+ 'request/purplerequestfieldlabel.c',
'request/purplerequestfieldlist.c',
'request/purplerequestfieldstring.c',
'request-datasheet.c',
@@ -230,6 +231,7 @@
'request/purplerequestfieldbool.h',
'request/purplerequestfieldchoice.h',
'request/purplerequestfieldint.h',
+ 'request/purplerequestfieldlabel.h',
'request/purplerequestfieldlist.h',
'request/purplerequestfieldstring.h',
]
--- a/libpurple/purplerequestfield.c Fri Mar 10 17:17:53 2023 -0600
+++ b/libpurple/purplerequestfield.c Fri Mar 10 17:25:22 2023 -0600
@@ -635,19 +635,6 @@
}
PurpleRequestField *
-purple_request_field_label_new(const char *id, const char *text)
-{
- PurpleRequestField *field;
-
- g_return_val_if_fail(id != NULL, NULL);
- g_return_val_if_fail(text != NULL, NULL);
-
- field = purple_request_field_new(id, text, PURPLE_REQUEST_FIELD_LABEL);
-
- return field;
-}
-
-PurpleRequestField *
purple_request_field_image_new(const char *id, const char *text, const char *buf, gsize size)
{
PurpleRequestField *field;
--- a/libpurple/purplerequestfield.h Fri Mar 10 17:17:53 2023 -0600
+++ b/libpurple/purplerequestfield.h Fri Mar 10 17:25:22 2023 -0600
@@ -64,7 +64,6 @@
/**
* PurpleRequestFieldType:
* @PURPLE_REQUEST_FIELD_NONE: No field.
- * @PURPLE_REQUEST_FIELD_LABEL: Label field.
* @PURPLE_REQUEST_FIELD_IMAGE: Image field.
* @PURPLE_REQUEST_FIELD_DATASHEET: Datasheet field.
*
@@ -73,7 +72,6 @@
typedef enum
{
PURPLE_REQUEST_FIELD_NONE,
- PURPLE_REQUEST_FIELD_LABEL,
PURPLE_REQUEST_FIELD_IMAGE,
PURPLE_REQUEST_FIELD_DATASHEET
@@ -309,22 +307,6 @@
gboolean purple_request_field_is_sensitive(PurpleRequestField *field);
/**************************************************************************/
-/* Label Field API */
-/**************************************************************************/
-
-/**
- * purple_request_field_label_new:
- * @id: The field ID.
- * @text: The label of the field.
- *
- * Creates a label field.
- *
- * Returns: (transfer full): The new field.
- */
-PurpleRequestField *purple_request_field_label_new(const char *id,
- const char *text);
-
-/**************************************************************************/
/* Image Field API */
/**************************************************************************/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/request/purplerequestfieldlabel.c Fri Mar 10 17:25:22 2023 -0600
@@ -0,0 +1,58 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#include <glib/gi18n-lib.h>
+
+#include "glibcompat.h"
+#include "purplerequestfield.h"
+#include "request/purplerequestfieldlabel.h"
+
+struct _PurpleRequestFieldLabel {
+ PurpleRequestField parent;
+};
+
+/******************************************************************************
+ * GObject Implementation
+ *****************************************************************************/
+G_DEFINE_TYPE(PurpleRequestFieldLabel, purple_request_field_label,
+ PURPLE_TYPE_REQUEST_FIELD)
+
+static void
+purple_request_field_label_init(G_GNUC_UNUSED PurpleRequestFieldLabel *field) {
+}
+
+static void
+purple_request_field_label_class_init(G_GNUC_UNUSED PurpleRequestFieldLabelClass *klass) {
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+PurpleRequestField *
+purple_request_field_label_new(const char *id, const char *text) {
+ g_return_val_if_fail(id != NULL, NULL);
+ g_return_val_if_fail(text != NULL, NULL);
+
+ return g_object_new(PURPLE_TYPE_REQUEST_FIELD_LABEL,
+ "id", id,
+ "label", text,
+ NULL);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/request/purplerequestfieldlabel.h Fri Mar 10 17:25:22 2023 -0600
@@ -0,0 +1,63 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION)
+# error "only <purple.h> may be included directly"
+#endif
+
+#ifndef PURPLE_REQUEST_FIELD_LABEL_H
+#define PURPLE_REQUEST_FIELD_LABEL_H
+
+#include <stdlib.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+/**
+ * PurpleRequestFieldLabel:
+ *
+ * A label request field.
+ */
+typedef struct _PurpleRequestFieldLabel PurpleRequestFieldLabel;
+
+#include "purplerequestfield.h"
+
+G_BEGIN_DECLS
+
+#define PURPLE_TYPE_REQUEST_FIELD_LABEL (purple_request_field_label_get_type())
+G_DECLARE_FINAL_TYPE(PurpleRequestFieldLabel, purple_request_field_label,
+ PURPLE, REQUEST_FIELD_LABEL, PurpleRequestField)
+
+/**
+ * purple_request_field_label_new:
+ * @id: The field ID.
+ * @text: The label of the field.
+ *
+ * Creates a label field.
+ *
+ * Returns: (transfer full): The new field.
+ */
+PurpleRequestField *purple_request_field_label_new(const char *id, const char *text);
+
+G_END_DECLS
+
+#endif /* PURPLE_REQUEST_FIELD_LABEL_H */
--- a/pidgin/gtkrequest.c Fri Mar 10 17:17:53 2023 -0600
+++ b/pidgin/gtkrequest.c Fri Mar 10 17:25:22 2023 -0600
@@ -2050,8 +2050,7 @@
if (type == PURPLE_REQUEST_FIELD_DATASHEET)
contains_resizable = TRUE;
- if (type == PURPLE_REQUEST_FIELD_LABEL)
- {
+ if(PURPLE_IS_REQUEST_FIELD_LABEL(field)) {
rows++;
}
else if(PURPLE_IS_REQUEST_FIELD_LIST(field) ||
@@ -2108,7 +2107,7 @@
if (field_label[strlen(field_label) - 1] != ':' &&
field_label[strlen(field_label) - 1] != '?' &&
- type != PURPLE_REQUEST_FIELD_LABEL)
+ !PURPLE_IS_REQUEST_FIELD_LABEL(field))
{
text = g_strdup_printf("%s:", field_label);
}
@@ -2123,7 +2122,7 @@
gtk_size_group_add_widget(sg, label);
- if (type == PURPLE_REQUEST_FIELD_LABEL ||
+ if (PURPLE_IS_REQUEST_FIELD_LABEL(field) ||
PURPLE_IS_REQUEST_FIELD_LIST(field) ||
(PURPLE_IS_REQUEST_FIELD_STRING(field) &&
purple_request_field_string_is_multiline(PURPLE_REQUEST_FIELD_STRING(field))))