Commit 36af5e51 authored by Georges Basile Stavracas Neto's avatar Georges Basile Stavracas Neto
Browse files

shell-model: Remove boilerplate and update code style

parent 3228632d
......@@ -19,23 +19,25 @@
* Author: Thomas Wood <thos@gnome.org>
*/
#include "cc-shell-model.h"
#include "cc-util.h"
#include <string.h>
#include <gio/gdesktopappinfo.h>
#include "cc-shell-model.h"
#include "cc-util.h"
#define GNOME_SETTINGS_PANEL_ID_KEY "X-GNOME-Settings-Panel"
#define GNOME_SETTINGS_PANEL_CATEGORY GNOME_SETTINGS_PANEL_ID_KEY
#define GNOME_SETTINGS_PANEL_ID_KEYWORDS "Keywords"
struct _CcShellModelPrivate
struct _CcShellModel
{
gchar **sort_terms;
GtkListStore parent;
GStrv sort_terms;
};
G_DEFINE_TYPE_WITH_PRIVATE (CcShellModel, cc_shell_model, GTK_TYPE_LIST_STORE)
G_DEFINE_TYPE (CcShellModel, cc_shell_model, GTK_TYPE_LIST_STORE)
static gint
sort_by_name (GtkTreeModel *model,
......@@ -224,20 +226,19 @@ cc_shell_model_sort_func (GtkTreeModel *model,
gpointer data)
{
CcShellModel *self = data;
CcShellModelPrivate *priv = self->priv;
if (!priv->sort_terms || !priv->sort_terms[0])
if (!self->sort_terms || !self->sort_terms[0])
return sort_by_name (model, a, b);
else
return sort_with_terms (model, a, b, priv->sort_terms);
return sort_with_terms (model, a, b, self->sort_terms);
}
static void
cc_shell_model_finalize (GObject *object)
{
CcShellModelPrivate *priv = CC_SHELL_MODEL (object)->priv;;
CcShellModel *self = CC_SHELL_MODEL (object);
g_strfreev (priv->sort_terms);
g_clear_pointer (&self->sort_terms, g_strfreev);
G_OBJECT_CLASS (cc_shell_model_parent_class)->finalize (object);
}
......@@ -245,9 +246,8 @@ cc_shell_model_finalize (GObject *object)
static void
cc_shell_model_class_init (CcShellModelClass *klass)
{
GObjectClass *gobject_class;
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = cc_shell_model_finalize;
}
......@@ -257,8 +257,6 @@ cc_shell_model_init (CcShellModel *self)
GType types[] = {G_TYPE_STRING, G_TYPE_STRING, G_TYPE_APP_INFO, G_TYPE_STRING,
G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_ICON, G_TYPE_STRV};
self->priv = cc_shell_model_get_instance_private (self);
gtk_list_store_set_column_types (GTK_LIST_STORE (self),
N_COLS, types);
......@@ -390,13 +388,14 @@ void
cc_shell_model_set_sort_terms (CcShellModel *self,
gchar **terms)
{
CcShellModelPrivate *priv = self->priv;
g_return_if_fail (CC_IS_SHELL_MODEL (self));
g_strfreev (priv->sort_terms);
priv->sort_terms = g_strdupv (terms);
g_clear_pointer (&self->sort_terms, g_strfreev);
self->sort_terms = g_strdupv (terms);
/* trigger a re-sort */
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (self),
cc_shell_model_sort_func,
self, NULL);
self,
NULL);
}
......@@ -18,9 +18,7 @@
* Author: Thomas Wood <thos@gnome.org>
*/
#ifndef _CC_SHELL_MODEL_H
#define _CC_SHELL_MODEL_H
#pragma once
#include <gtk/gtk.h>
......@@ -28,31 +26,10 @@ G_BEGIN_DECLS
#define CC_TYPE_SHELL_MODEL cc_shell_model_get_type()
#define CC_SHELL_MODEL(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
CC_TYPE_SHELL_MODEL, CcShellModel))
#define CC_SHELL_MODEL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
CC_TYPE_SHELL_MODEL, CcShellModelClass))
#define CC_IS_SHELL_MODEL(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
CC_TYPE_SHELL_MODEL))
#define CC_IS_SHELL_MODEL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
CC_TYPE_SHELL_MODEL))
G_DECLARE_FINAL_TYPE (CcShellModel, cc_shell_model, CC, SHELL_MODEL, GtkListStore)
#define CC_SHELL_MODEL_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
CC_TYPE_SHELL_MODEL, CcShellModelClass))
typedef struct _CcShellModel CcShellModel;
typedef struct _CcShellModelClass CcShellModelClass;
typedef struct _CcShellModelPrivate CcShellModelPrivate;
typedef enum {
typedef enum
{
CC_CATEGORY_CONNECTIVITY,
CC_CATEGORY_PERSONALIZATION,
CC_CATEGORY_ACCOUNT,
......@@ -77,37 +54,22 @@ enum
N_COLS
};
struct _CcShellModel
{
GtkListStore parent;
CcShellModelPrivate *priv;
};
struct _CcShellModelClass
{
GtkListStoreClass parent_class;
};
CcShellModel* cc_shell_model_new (void);
GType cc_shell_model_get_type (void) G_GNUC_CONST;
void cc_shell_model_add_item (CcShellModel *model,
CcPanelCategory category,
GAppInfo *appinfo,
const char *id);
CcShellModel *cc_shell_model_new (void);
gboolean cc_shell_model_has_panel (CcShellModel *model,
const char *id);
void cc_shell_model_add_item (CcShellModel *model,
CcPanelCategory category,
GAppInfo *appinfo,
const char *id);
gboolean cc_shell_model_iter_matches_search (CcShellModel *model,
GtkTreeIter *iter,
const char *term);
gboolean cc_shell_model_has_panel (CcShellModel *model,
const char *id);
gboolean cc_shell_model_iter_matches_search (CcShellModel *model,
GtkTreeIter *iter,
const char *term);
void cc_shell_model_set_sort_terms (CcShellModel *model,
gchar **terms);
void cc_shell_model_set_sort_terms (CcShellModel *model,
GStrv terms);
G_END_DECLS
#endif /* _CC_SHELL_MODEL_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment