qulogic/talkatu
Clone
Summary
Browse
Changes
Graph
Cleanups found during review
2019-07-22, Gary Kramlich
10a61ad59924
Cleanups found during review
/*
* talkatu
* Copyright (C) 2017-2019 Gary Kramlich <grim@reaperworld.com>
*
* This library 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) any later version.
*
* This library 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 this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include
<gtk/gtk.h>
#include
"talkatu/talkatumessage.h"
#include
"talkatu/talkatuenums.h"
/**
* SECTION:talkatumessage
* @Title: Message
* @Short_description: A message representation
*
* Talkatu needs a way to represent a message in a client agnostic way, this is
* the API that does that.
*/
/**
* TALKATU_TYPE_MESSAGE:
*
* The standard _get_type macro for #TalkatuMessage.
*/
/**
* TalkatuMessage:
*
* #TalkatuMessage is an opaque data structure and can only be accessed using
* the following functions.
*/
/**
* TalkatuMessageInterface:
*
* #TalkatuMessage is an interface to be implemented to standardize the way
* messages are handled. All of its properties should be overridden with a
* sensible value returned for them.
*/
/**
* TalkatuContentType:
* @TALKATU_CONTENT_TYPE_PLAIN: Plain text content.
* @TALKATU_CONTENT_TYPE_PANGO: Pango Markup content.
* @TALKATU_CONTENT_TYPE_HTML: HTML content.
* @TALKATU_CONTENT_TYPE_MARKDOWN: Markdown content.
*
* An enum representing a given markup type.
*/
G_DEFINE_INTERFACE
(
TalkatuMessage
,
talkatu_message
,
G_TYPE_INVALID
)
/******************************************************************************
* GObject Stuff
*****************************************************************************/
static
void
talkatu_message_default_init
(
TalkatuMessageInterface
*
iface
)
{
GParamSpec
*
pspec
=
NULL
;
/**
* TalkatuMessage::id:
*
* The identifier of the message.
*/
pspec
=
g_param_spec_uint64
(
"id"
,
"id"
,
"The identifier of the message"
,
0
,
G_MAXUINT64
,
0
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT
);
g_object_interface_install_property
(
iface
,
pspec
);
/**
* TalkatuMessage::timestamp:
*
* The timestamp for when this message was created.
*/
pspec
=
g_param_spec_pointer
(
"timestamp"
,
"timestamp"
,
"The timestamp of the message"
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT_ONLY
);
g_object_interface_install_property
(
iface
,
pspec
);
/**
* TalkatuMessage::content-type:
*
* The #TalkatuContentType of the message.
*/
pspec
=
g_param_spec_enum
(
"content-type"
,
"content-type"
,
"The content-type of the message"
,
TALKATU_TYPE_CONTENT_TYPE
,
TALKATU_CONTENT_TYPE_PLAIN
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT_ONLY
);
g_object_interface_install_property
(
iface
,
pspec
);
/**
* TalkatuMessage::author:
*
* The author of the message.
*/
pspec
=
g_param_spec_string
(
"author"
,
"author"
,
"The author of the message"
,
NULL
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT
);
g_object_interface_install_property
(
iface
,
pspec
);
/**
* TalkatuMessage::contents:
*
* The contents of the message.
*/
pspec
=
g_param_spec_string
(
"contents"
,
"contents"
,
"The contents of the message"
,
NULL
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT
);
g_object_interface_install_property
(
iface
,
pspec
);
/**
* TalkatuMessage::edited:
*
* Sets whether the message has been edited by its author or not.
*/
pspec
=
g_param_spec_boolean
(
"edited"
,
"edited"
,
"Whether this message has been edited by its author"
,
FALSE
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT
);
g_object_interface_install_property
(
iface
,
pspec
);
}
/******************************************************************************
* Public API
*****************************************************************************/
/**
* talkatu_message_get_id:
* @message: The #TalkatuMessage instance.
*
* Gets the identifier of the @message.
*
* Returns: The identifier of @message.
*/
guint64
talkatu_message_get_id
(
TalkatuMessage
*
message
)
{
guint64
ret
=
0
;
g_return_val_if_fail
(
TALKATU_IS_MESSAGE
(
message
),
0
);
g_object_get
(
G_OBJECT
(
message
),
"id"
,
&
ret
,
NULL
);
return
ret
;
}
/**
* talkatu_message_set_id:
* @message: The #TalkatuMessage instance.
* @id: The new identifier of @message.
*
* Sets the identifier of @message.
*/
void
talkatu_message_set_id
(
TalkatuMessage
*
message
,
guint64
id
)
{
g_return_if_fail
(
TALKATU_IS_MESSAGE
(
message
));
g_object_set
(
G_OBJECT
(
message
),
"id"
,
id
,
NULL
);
}
/**
* talkatu_message_get_timestamp:
* @message: The #TalkatuMessage instance.
*
* Gets the timestamp for when this message was created.
*
* Returns: (transfer full) (nullable): The timestamp of @message.
*/
GDateTime
*
talkatu_message_get_timestamp
(
TalkatuMessage
*
message
)
{
GDateTime
*
timestamp
;
g_return_val_if_fail
(
TALKATU_IS_MESSAGE
(
message
),
NULL
);
g_object_get
(
G_OBJECT
(
message
),
"timestamp"
,
&
timestamp
,
NULL
);
if
(
timestamp
!=
NULL
)
{
return
g_date_time_ref
(
timestamp
);
}
return
NULL
;
}
/**
* talkatu_message_set_timestamp:
* @message: The #TalkatuMessage instance.
* @timestamp: (nullable): The new timestamp for @message.
*
* Sets the creation timestamp for @message to @timestamp.
*/
void
talkatu_message_set_timestamp
(
TalkatuMessage
*
message
,
GDateTime
*
timestamp
)
{
g_return_if_fail
(
TALKATU_IS_MESSAGE
(
message
));
g_object_set
(
G_OBJECT
(
message
),
"timestamp"
,
timestamp
,
NULL
);
}
/**
* talkatu_message_get_content_type:
* @message: The #TalkatuMessage instance.
*
* Gets the content-type of @message.
*
* Returns: The content type of @message.
*/
TalkatuContentType
talkatu_message_get_content_type
(
TalkatuMessage
*
message
)
{
TalkatuContentType
content_type
;
g_return_val_if_fail
(
TALKATU_IS_MESSAGE
(
message
),
TALKATU_CONTENT_TYPE_PLAIN
);
g_object_get
(
G_OBJECT
(
message
),
"content-type"
,
&
content_type
,
NULL
);
return
content_type
;
}
/**
* talkatu_message_get_author:
* @message: The #TalkatuMessage instance.
*
* Gets the author of @message.
*
* Returns: (transfer full): The author of @message.
*/
gchar
*
talkatu_message_get_author
(
TalkatuMessage
*
message
)
{
gchar
*
author
=
NULL
;
g_return_val_if_fail
(
TALKATU_IS_MESSAGE
(
message
),
NULL
);
g_object_get
(
G_OBJECT
(
message
),
"author"
,
&
author
,
NULL
);
return
author
;
}
/**
* talkatu_message_set_author:
* @message: The #TalkatuMessage instance.
* @author: The new author of @message.
*
* Sets the author of @message to @author.
*/
void
talkatu_message_set_author
(
TalkatuMessage
*
message
,
const
gchar
*
author
)
{
g_return_if_fail
(
TALKATU_IS_MESSAGE
(
message
));
g_object_set
(
G_OBJECT
(
message
),
"author"
,
author
,
NULL
);
}
/**
* talkatu_message_get_contents:
* @message: The #TalkatuMessage instance.
*
* Gets the contents of @message.
*
* Returns: (transfer full): The contents of @message.
*/
gchar
*
talkatu_message_get_contents
(
TalkatuMessage
*
message
)
{
gchar
*
contents
=
NULL
;
g_return_val_if_fail
(
TALKATU_IS_MESSAGE
(
message
),
NULL
);
g_object_get
(
G_OBJECT
(
message
),
"contents"
,
&
contents
,
NULL
);
return
contents
;
}
/**
* talkatu_message_set_contents:
* @message: The #TalkatuMessage instance.
* @contents: The new contents of @message.
*
* Sets the contents of @message to @contents.
*/
void
talkatu_message_set_contents
(
TalkatuMessage
*
message
,
const
gchar
*
contents
)
{
g_return_if_fail
(
TALKATU_IS_MESSAGE
(
message
));
g_object_set
(
G_OBJECT
(
message
),
"contents"
,
contents
,
NULL
);
}
/**
* talkatu_message_get_edited:
* @message: The #TalkatuMessage instance.
*
* Gets whether @message has been edited by its author.
*
* Returns: %TRUE if @message was edited by its author, or %FALSE if not.
*/
gboolean
talkatu_message_get_edited
(
TalkatuMessage
*
message
)
{
gboolean
edited
=
FALSE
;
g_return_val_if_fail
(
TALKATU_IS_MESSAGE
(
message
),
FALSE
);
g_object_get
(
G_OBJECT
(
message
),
"edited"
,
&
edited
,
NULL
);
return
edited
;
}
/**
* talkatu_message_set_edited:
* @message: The #TalkatuMessage instance.
* @edited: Whether the message has been edited or not.
*
* Sets whether @message has been edited or not.
*/
void
talkatu_message_set_edited
(
TalkatuMessage
*
message
,
gboolean
edited
)
{
g_return_if_fail
(
TALKATU_IS_MESSAGE
(
message
));
g_object_set
(
G_OBJECT
(
message
),
"edited"
,
edited
,
NULL
);
}