1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Johannes Schmid 2012 <jhs@Obelix>
6 * anjuta is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * anjuta is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "search-filter-file-command.h"
21 #include <libanjuta/anjuta-debug.h>
23 struct _SearchFilterFileCommandPrivate
40 search_filter_file_command_run (AnjutaCommand
* anjuta_cmd
)
42 SearchFilterFileCommand
* cmd
= SEARCH_FILTER_FILE_COMMAND (anjuta_cmd
);
44 gchar
** mime_types
= g_strsplit (cmd
->priv
->mime_types
, ",", -1);
51 file_info
= g_file_query_info (cmd
->priv
->file
,
52 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
,
53 G_FILE_QUERY_INFO_NONE
,
58 for (mime_type
= mime_types
; mime_type
&& *mime_type
; mime_type
++)
60 gchar
* content_type
= g_content_type_from_mime_type (*mime_type
);
61 if (g_content_type_is_a (g_file_info_get_content_type (file_info
),
65 g_free (content_type
);
69 g_object_unref (file_info
);
73 int code
= error
->code
;
74 DEBUG_PRINT ("Couldn't query mime-type: %s", error
->message
);
78 g_strfreev(mime_types
);
83 G_DEFINE_TYPE (SearchFilterFileCommand
, search_filter_file_command
, ANJUTA_TYPE_ASYNC_COMMAND
);
86 search_filter_file_command_init (SearchFilterFileCommand
*cmd
)
88 cmd
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (cmd
,
89 SEARCH_TYPE_FILTER_FILE_COMMAND
,
90 SearchFilterFileCommandPrivate
);
94 search_filter_file_command_finalize (GObject
*object
)
96 SearchFilterFileCommand
* cmd
= SEARCH_FILTER_FILE_COMMAND(object
);
99 g_object_unref (cmd
->priv
->file
);
100 g_free (cmd
->priv
->mime_types
);
102 G_OBJECT_CLASS (search_filter_file_command_parent_class
)->finalize (object
);
106 search_filter_file_command_set_property (GObject
*object
, guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
108 SearchFilterFileCommand
* cmd
;
110 g_return_if_fail (SEARCH_IS_FILTER_FILE_COMMAND (object
));
112 cmd
= SEARCH_FILTER_FILE_COMMAND(object
);
118 g_object_unref (cmd
->priv
->file
);
119 cmd
->priv
->file
= G_FILE(g_value_dup_object (value
));
121 case PROP_MIME_TYPES
:
122 g_free (cmd
->priv
->mime_types
);
123 cmd
->priv
->mime_types
= g_value_dup_string (value
);
126 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
132 search_filter_file_command_get_property (GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
134 SearchFilterFileCommand
* cmd
;
136 g_return_if_fail (SEARCH_IS_FILTER_FILE_COMMAND (object
));
138 cmd
= SEARCH_FILTER_FILE_COMMAND(object
);
143 g_value_set_object (value
, cmd
->priv
->file
);
145 case PROP_MIME_TYPES
:
146 g_value_set_string (value
, cmd
->priv
->mime_types
);
149 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
155 search_filter_file_command_class_init (SearchFilterFileCommandClass
*klass
)
157 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
158 AnjutaCommandClass
* cmd_class
= ANJUTA_COMMAND_CLASS (klass
);
160 object_class
->finalize
= search_filter_file_command_finalize
;
161 object_class
->set_property
= search_filter_file_command_set_property
;
162 object_class
->get_property
= search_filter_file_command_get_property
;
164 g_object_class_install_property (object_class
,
166 g_param_spec_object ("file",
170 G_PARAM_READABLE
| G_PARAM_WRITABLE
| G_PARAM_CONSTRUCT_ONLY
));
172 g_object_class_install_property (object_class
,
174 g_param_spec_string ("mime-types",
178 G_PARAM_READABLE
| G_PARAM_WRITABLE
| G_PARAM_CONSTRUCT
));
180 cmd_class
->run
= search_filter_file_command_run
;
182 g_type_class_add_private (klass
, sizeof (SearchFilterFileCommandPrivate
));
186 SearchFilterFileCommand
*
187 search_filter_file_command_new (GFile
* file
, const gchar
* mime_types
)
189 SearchFilterFileCommand
* cmd
;
191 cmd
= SEARCH_FILTER_FILE_COMMAND (g_object_new (SEARCH_TYPE_FILTER_FILE_COMMAND
,
193 "mime-types", mime_types
,