summaryrefslogtreecommitdiff
path: root/src/nautilus-view-item-model.c
blob: e50f2d8004daa64cf7ff487580914c9e018566c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "nautilus-view-item-model.h"
#include "nautilus-file.h"

struct _NautilusViewItemModel
{
    GObject parent_instance;
    guint icon_size;
    NautilusFile *file;
    GtkLabel *label;
    GtkWidget *item_ui;
};

G_DEFINE_TYPE (NautilusViewItemModel, nautilus_view_item_model, G_TYPE_OBJECT)

enum
{
    PROP_0,
    PROP_FILE,
    PROP_ICON_SIZE,
    PROP_ITEM_UI,
    N_PROPS
};

static void
nautilus_view_item_model_finalize (GObject *object)
{
    G_OBJECT_CLASS (nautilus_view_item_model_parent_class)->finalize (object);
}

static void
nautilus_view_item_model_get_property (GObject    *object,
                                       guint       prop_id,
                                       GValue     *value,
                                       GParamSpec *pspec)
{
    NautilusViewItemModel *self = NAUTILUS_VIEW_ITEM_MODEL (object);

    switch (prop_id)
    {
        case PROP_FILE:
        {
            g_value_set_object (value, self->file);
        }
        break;

        case PROP_ICON_SIZE:
        {
            g_value_set_int (value, self->icon_size);
        }
        break;

        case PROP_ITEM_UI:
        {
            g_value_set_object (value, self->item_ui);
        }
        break;

        default:
        {
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        }
    }
}

static void
nautilus_view_item_model_set_property (GObject      *object,
                                       guint         prop_id,
                                       const GValue *value,
                                       GParamSpec   *pspec)
{
    NautilusViewItemModel *self = NAUTILUS_VIEW_ITEM_MODEL (object);

    switch (prop_id)
    {
        case PROP_FILE:
        {
            nautilus_view_item_model_set_file (self, g_value_get_object (value));
        }
        break;

        case PROP_ICON_SIZE:
        {
            nautilus_view_item_model_set_icon_size (self, g_value_get_int (value));
        }
        break;

        case PROP_ITEM_UI:
        {
            nautilus_view_item_model_set_item_ui (self, g_value_get_object (value));
        }
        break;

        default:
        {
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        }
    }
}

static void
nautilus_view_item_model_init (NautilusViewItemModel *self)
{
}

static void
nautilus_view_item_model_class_init (NautilusViewItemModelClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);

    object_class->finalize = nautilus_view_item_model_finalize;
    object_class->get_property = nautilus_view_item_model_get_property;
    object_class->set_property = nautilus_view_item_model_set_property;

    g_object_class_install_property (object_class,
                                     PROP_ICON_SIZE,
                                     g_param_spec_int ("icon-size",
                                                       "Icon size",
                                                       "The size in pixels of the icon",
                                                       NAUTILUS_CANVAS_ICON_SIZE_SMALL,
                                                       NAUTILUS_CANVAS_ICON_SIZE_LARGEST,
                                                       NAUTILUS_CANVAS_ICON_SIZE_LARGE,
                                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
    g_object_class_install_property (object_class,
                                     PROP_FILE,
                                     g_param_spec_object ("file",
                                                          "File",
                                                          "The file the icon item represents",
                                                          NAUTILUS_TYPE_FILE,
                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));

    g_object_class_install_property (object_class,
                                     PROP_ITEM_UI,
                                     g_param_spec_object ("item-ui",
                                                          "Item ui",
                                                          "The UI that reprensents the item model",
                                                          GTK_TYPE_WIDGET,
                                                          G_PARAM_READWRITE));
}

NautilusViewItemModel *
nautilus_view_item_model_new (NautilusFile *file,
                              guint         icon_size)
{
    return g_object_new (NAUTILUS_TYPE_VIEW_ITEM_MODEL,
                         "file", file,
                         "icon-size", icon_size,
                         NULL);
}

guint
nautilus_view_item_model_get_icon_size (NautilusViewItemModel *self)
{
    g_return_val_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self), -1);

    return self->icon_size;
}

void
nautilus_view_item_model_set_icon_size (NautilusViewItemModel *self,
                                        guint                  icon_size)
{
    g_return_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self));

    self->icon_size = icon_size;

    g_object_notify (G_OBJECT (self), "icon-size");
}

NautilusFile *
nautilus_view_item_model_get_file (NautilusViewItemModel *self)
{
    g_return_val_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self), NULL);

    return self->file;
}

void
nautilus_view_item_model_set_file (NautilusViewItemModel *self,
                                   NautilusFile          *file)
{
    g_return_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self));

    g_clear_object (&self->file);
    self->file = g_object_ref (file);

    g_object_notify (G_OBJECT (self), "file");
}

GtkWidget *
nautilus_view_item_model_get_item_ui (NautilusViewItemModel *self)
{
    g_return_val_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self), NULL);

    return self->item_ui;
}

void
nautilus_view_item_model_set_item_ui (NautilusViewItemModel *self,
                                      GtkWidget             *item_ui)
{
    g_return_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self));

    g_clear_object (&self->item_ui);
    self->item_ui = g_object_ref (item_ui);

    g_object_notify (G_OBJECT (self), "item-ui");
}