summaryrefslogtreecommitdiff
path: root/src/fr-list-model.c
blob: cd4efa2497d944953cb82be4b753c0abfc7b5d88 (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  Engrampa
 *
 *  Copyright (C) 2005 Free Software Foundation, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <config.h>
#include "eggtreemultidnd.h"
#include "fr-list-model.h"
#include "fr-window.h"

static GtkListStoreClass *parent_class;

static gboolean
fr_list_model_multi_row_draggable (EggTreeMultiDragSource *drag_source,
				   GList                  *path_list)
{
	FrWindow     *window;
	GtkTreeModel *model;
	GList        *scan;

	window = g_object_get_data (G_OBJECT (drag_source), "FrWindow");
	g_return_val_if_fail (window != NULL, FALSE);

	model = fr_window_get_list_store (window);

	for (scan = path_list; scan; scan = scan->next) {
		GtkTreeRowReference *reference = scan->data;
		GtkTreePath         *path;
		GtkTreeIter          iter;
		FileData            *fdata;

		path = gtk_tree_row_reference_get_path (reference);
		if (path == NULL)
			continue;

		if (! gtk_tree_model_get_iter (model, &iter, path))
			continue;

		gtk_tree_model_get (model, &iter,
				    COLUMN_FILE_DATA, &fdata,
				    -1);

		if (fdata != NULL)
			return TRUE;
	}

	return FALSE;
}

static gboolean
fr_list_model_multi_drag_data_get (EggTreeMultiDragSource *drag_source,
				   GdkDragContext         *context,
				   GtkSelectionData       *selection_data,
				   GList                  *path_list)
{
	FrWindow *window;

	window = g_object_get_data (G_OBJECT (drag_source), "FrWindow");
	g_return_val_if_fail (window != NULL, FALSE);

	return fr_window_file_list_drag_data_get (window,
						  context,
						  selection_data,
						  path_list);
}

static gboolean
fr_list_model_multi_drag_data_delete (EggTreeMultiDragSource *drag_source,
				      GList                  *path_list)
{
	return TRUE;
}

static void
fr_list_model_finalize (GObject *object)
{
	if (G_OBJECT_CLASS (parent_class)->finalize)
		G_OBJECT_CLASS (parent_class)->finalize (object);
}

static void
fr_list_model_init (FRListModel *model)
{
}

static void
fr_list_model_class_init (FRListModelClass *klass)
{
	GObjectClass *object_class;

	object_class = (GObjectClass *)klass;
	parent_class = g_type_class_peek_parent (klass);

	object_class->finalize = fr_list_model_finalize;
}

static void
fr_list_model_multi_drag_source_init (EggTreeMultiDragSourceIface *iface)
{
	iface->row_draggable = fr_list_model_multi_row_draggable;
	iface->drag_data_get = fr_list_model_multi_drag_data_get;
	iface->drag_data_delete = fr_list_model_multi_drag_data_delete;
}

GType
fr_list_model_get_type (void)
{
	static GType object_type = 0;

	if (object_type == 0) {
		static const GTypeInfo object_info = {
			sizeof (FRListModelClass),
			NULL,		/* base_init */
			NULL,		/* base_finalize */
			(GClassInitFunc) fr_list_model_class_init,
			NULL,		/* class_finalize */
			NULL,		/* class_data */
			sizeof (FRListModel),
			0,
			(GInstanceInitFunc) fr_list_model_init,
			NULL
		};

		static const GInterfaceInfo multi_drag_source_info = {
			(GInterfaceInitFunc) fr_list_model_multi_drag_source_init,
			NULL,
			NULL
		};

		object_type = g_type_register_static (GTK_TYPE_LIST_STORE, "FRListModel", &object_info, 0);
		g_type_add_interface_static (object_type,
					     EGG_TYPE_TREE_MULTI_DRAG_SOURCE,
					     &multi_drag_source_info);
	}

	return object_type;
}

GtkListStore *
fr_list_model_new (int n_columns, ...)
{
	GtkListStore *retval;
	GType        *types;
	va_list       args;
	int           i;

	g_return_val_if_fail (n_columns > 0, NULL);

	retval = g_object_new (FR_TYPE_LIST_MODEL, NULL);

	va_start (args, n_columns);
	types = g_new0 (GType, n_columns);
	for (i = 0; i < n_columns; i++)
		types[i] = va_arg (args, GType);
	va_end (args);

	gtk_list_store_set_column_types (retval, n_columns, types);
	g_free (types);

	return retval;
}