Port MatrixSearchGrouping to C
This commit is contained in:
parent
1c14ad77ff
commit
03625e8a8f
@ -2165,3 +2165,125 @@ matrix_event_context_init(MatrixEventContext *matrix_event_context)
|
||||
priv->_after_limit = -1;
|
||||
priv->_include_profile = FALSE;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
MatrixSearchGroupBy _key;
|
||||
} MatrixSearchGroupingPrivate;
|
||||
|
||||
/**
|
||||
* MatrixSearchGrouping:
|
||||
*
|
||||
* Class to hold grouping keys for search results.
|
||||
*
|
||||
* <note><para>
|
||||
* Not to be confused with #MatrixSearchGroupings which is essentially a container for this type.
|
||||
* </para></note>
|
||||
*/
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(MatrixSearchGrouping, matrix_search_grouping, MATRIX_TYPE_JSON_COMPACT);
|
||||
|
||||
static JsonNode *
|
||||
matrix_search_grouping_get_json_node(MatrixJsonCompact *matrix_json_compact, GError **error)
|
||||
{
|
||||
MatrixSearchGroupingPrivate *priv;
|
||||
JsonBuilder *builder;
|
||||
JsonNode *result;
|
||||
|
||||
g_return_val_if_fail(matrix_json_compact != NULL, NULL);
|
||||
|
||||
priv = matrix_search_grouping_get_instance_private(MATRIX_SEARCH_GROUPING(matrix_json_compact));
|
||||
|
||||
if (priv->_key == MATRIX_SEARCH_GROUP_BY_NONE) {
|
||||
g_set_error(error, MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, "Search grouping data incomplete");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
builder = json_builder_new();
|
||||
json_builder_begin_object(builder);
|
||||
|
||||
|
||||
json_builder_set_member_name(builder, "key");
|
||||
json_builder_add_string_value(builder, _matrix_g_enum_to_string(MATRIX_TYPE_SEARCH_GROUP_BY, priv->_key, TRUE));
|
||||
|
||||
json_builder_end_object(builder);
|
||||
|
||||
result = json_builder_get_root(builder);
|
||||
g_object_unref(builder);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_search_grouping_new:
|
||||
*
|
||||
* Create a new #MatrixSearchGrouping object
|
||||
*
|
||||
* Returns: (transfer full): a new #MatrixSearchGrouping object
|
||||
*/
|
||||
MatrixSearchGrouping *
|
||||
matrix_search_grouping_new(void)
|
||||
{
|
||||
return (MatrixSearchGrouping * )matrix_json_compact_construct(MATRIX_TYPE_SEARCH_GROUPING);
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_search_grouping_get_key:
|
||||
* @search_grouping: a #MatrixSearchGrouping object
|
||||
*
|
||||
* Get the grouping key from the grouping details.
|
||||
*
|
||||
* Returns: the grouping key
|
||||
*/
|
||||
MatrixSearchGroupBy
|
||||
matrix_search_grouping_get_key(MatrixSearchGrouping *matrix_search_grouping)
|
||||
{
|
||||
MatrixSearchGroupingPrivate *priv;
|
||||
|
||||
g_return_val_if_fail(matrix_search_grouping != NULL, MATRIX_SEARCH_GROUP_BY_NONE);
|
||||
|
||||
priv = matrix_search_grouping_get_instance_private(matrix_search_grouping);
|
||||
|
||||
return priv->_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_search_grouping_set_key:
|
||||
* @search_grouping: a #MatrixSearchGrouping object
|
||||
* @key: a grouping key
|
||||
*
|
||||
* Set the grouping key to be used in the search results.
|
||||
*/
|
||||
void
|
||||
matrix_search_grouping_set_key(MatrixSearchGrouping *matrix_search_grouping, MatrixSearchGroupBy key)
|
||||
{
|
||||
MatrixSearchGroupingPrivate *priv;
|
||||
|
||||
g_return_if_fail(matrix_search_grouping != NULL);
|
||||
|
||||
priv = matrix_search_grouping_get_instance_private(matrix_search_grouping);
|
||||
|
||||
priv->_key = key;
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_search_grouping_finalize(MatrixJsonCompact *matrix_json_compact)
|
||||
{
|
||||
MATRIX_JSON_COMPACT_CLASS(matrix_search_grouping_parent_class)->finalize (matrix_json_compact);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_search_grouping_class_init(MatrixSearchGroupingClass *klass)
|
||||
{
|
||||
((MatrixJsonCompactClass *)klass)->finalize = matrix_search_grouping_finalize;
|
||||
((MatrixJsonCompactClass *)klass)->get_json_node = matrix_search_grouping_get_json_node;
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_search_grouping_init(MatrixSearchGrouping *matrix_search_grouping)
|
||||
{
|
||||
MatrixSearchGroupingPrivate *priv;
|
||||
|
||||
priv = matrix_search_grouping_get_instance_private(matrix_search_grouping);
|
||||
|
||||
priv->_key = MATRIX_SEARCH_GROUP_BY_NONE;
|
||||
}
|
||||
|
@ -173,6 +173,17 @@ void matrix_event_context_set_after_limit (MatrixEventContext *event_context, gi
|
||||
gboolean matrix_event_context_get_include_profile (MatrixEventContext *event_context);
|
||||
void matrix_event_context_set_include_profile (MatrixEventContext *event_context, gboolean include_profile);
|
||||
|
||||
# define MATRIX_TYPE_SEARCH_GROUPING matrix_search_grouping_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixSearchGrouping, matrix_search_grouping, MATRIX, SEARCH_GROUPING, MatrixJsonCompact)
|
||||
|
||||
struct _MatrixSearchGroupingClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
MatrixSearchGrouping *matrix_search_grouping_new(void);
|
||||
MatrixSearchGroupBy matrix_search_grouping_get_key(MatrixSearchGrouping *search_grouping);
|
||||
void matrix_search_grouping_set_key(MatrixSearchGrouping *search_grouping, MatrixSearchGroupBy key);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MATRIX_GLIB_SDK_COMPACTS_H__ */
|
||||
|
@ -17,31 +17,6 @@
|
||||
*/
|
||||
|
||||
namespace Matrix {
|
||||
public class SearchGrouping : JsonCompact {
|
||||
public SearchGroupBy key { get; set; default = SearchGroupBy.NONE; }
|
||||
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (key == SearchGroupBy.NONE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("key");
|
||||
builder.add_string_value(
|
||||
_g_enum_value_to_nick(typeof(SearchGroupBy), key, true));
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
public class SearchGroupings : JsonCompact {
|
||||
public SearchGrouping[] group_by { get; set; }
|
||||
|
||||
|
@ -365,6 +365,14 @@ namespace Matrix {
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-c-compacts.h")]
|
||||
public class SearchGrouping : JsonCompact {
|
||||
public SearchGroupBy key { get; set; default = SearchGroupBy.NONE; }
|
||||
|
||||
public override Json.Node? get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
/* Utilities */
|
||||
[CCode (cheader_filename = "utils.h", cname = "_matrix_g_enum_to_string")]
|
||||
public string? _g_enum_value_to_nick(GLib.Type enum_type, int value, bool convert_dashes = true);
|
||||
|
Loading…
Reference in New Issue
Block a user