1 
2 /*
3  * input-msg.c: Input Message
4  *
5  * Copyright (C) 2002 Jody Goldberg (jody@gnome.org)
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) version 3.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
20  * USA
21  */
22 #include <gnumeric-config.h>
23 #include <glib/gi18n-lib.h>
24 #include <gnumeric.h>
25 #include <input-msg.h>
26 
27 #include <gsf/gsf-impl-utils.h>
28 
29 struct _GnmInputMsg {
30 	GObject obj;
31 	GOString *title;
32 	GOString *msg;
33 };
34 
35 typedef struct {
36 	GObjectClass obj;
37 } GnmInputMsgClass;
38 
39 static void
gnm_input_msg_finalize(GObject * obj)40 gnm_input_msg_finalize (GObject *obj)
41 {
42 	GObjectClass *parent_class;
43 	GnmInputMsg *msg = (GnmInputMsg *)obj;
44 
45 	go_string_unref (msg->title);
46 	msg->title = NULL;
47 
48 	go_string_unref (msg->msg);
49 	msg->msg = NULL;
50 
51 	parent_class = g_type_class_peek (G_TYPE_OBJECT);
52 	parent_class->finalize (obj);
53 }
54 
55 static void
gnm_input_msg_class_init(GObjectClass * object_class)56 gnm_input_msg_class_init (GObjectClass *object_class)
57 {
58 	object_class->finalize = gnm_input_msg_finalize;
59 }
60 static void
gnm_input_msg_init(GObject * obj)61 gnm_input_msg_init (GObject *obj)
62 {
63 	GnmInputMsg *msg = (GnmInputMsg * )obj;
64 	msg->title = NULL;
65 	msg->msg   = NULL;
66 }
67 
GSF_CLASS(GnmInputMsg,gnm_input_msg,gnm_input_msg_class_init,gnm_input_msg_init,G_TYPE_OBJECT)68 GSF_CLASS (GnmInputMsg, gnm_input_msg,
69 	   gnm_input_msg_class_init, gnm_input_msg_init, G_TYPE_OBJECT)
70 
71 /**
72  * gnm_input_msg_new:
73  * @msg: (nullable): A message to show
74  * @title: (nullable): A title to show for the message
75  *
76  * Returns: a ref to new #GnmInputMsg.
77  **/
78 GnmInputMsg *
79 gnm_input_msg_new (char const *msg, char const *title)
80 {
81 	GnmInputMsg *res = g_object_new (GNM_INPUT_MSG_TYPE, NULL);
82 
83 	if (msg != NULL)
84 		res->msg = go_string_new (msg);
85 	if (title != NULL)
86 		res->title = go_string_new (title);
87 
88 	return res;
89 }
90 
91 gboolean
gnm_input_msg_equal(GnmInputMsg const * a,GnmInputMsg const * b)92 gnm_input_msg_equal (GnmInputMsg const *a,
93 		     GnmInputMsg const *b)
94 {
95 	g_return_val_if_fail (GNM_IS_INPUT_MSG (a), FALSE);
96 	g_return_val_if_fail (GNM_IS_INPUT_MSG (b), FALSE);
97 
98 	return (g_strcmp0 (a->title ? a->title->str : NULL,
99 			   b->title ? b->title->str : NULL) == 0 &&
100 		g_strcmp0 (a->msg ? a->msg->str : NULL,
101 			   b->msg ? b->msg->str : NULL) == 0);
102 }
103 
104 
105 /**
106  * gnm_input_msg_get_msg:
107  * @msg: #GnmInputMsg
108  *
109  * Returns: (transfer none): The message to show
110  **/
111 char const *
gnm_input_msg_get_msg(GnmInputMsg const * msg)112 gnm_input_msg_get_msg (GnmInputMsg const *msg)
113 {
114 	return (msg->msg != NULL) ? msg->msg->str : "";
115 }
116 
117 /**
118  * gnm_input_msg_get_title:
119  * @msg: #GnmInputMsg
120  *
121  * Returns: (transfer none): The title of the message to show
122  **/
123 char const  *
gnm_input_msg_get_title(GnmInputMsg const * msg)124 gnm_input_msg_get_title (GnmInputMsg const *msg)
125 {
126 	return (msg->title != NULL) ? msg->title->str : "";
127 }
128