Debian Codegraph @

src/job/fm-file-info-job.h

raw
1 /*
2 * fm-file-info-job.h
3 *
4 * Copyright 2009 PCMan <[email protected]>
5 * Copyright 2013 Andriy Grytsenko (LStranger) <[email protected]>
6 *
7 * This file is a part of the Libfm library.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24
25 #ifndef __FM_FILE_INFO_JOB_H__
26 #define __FM_FILE_INFO_JOB_H__
27
28 #include "fm-job.h"
29 #include "fm-file-info.h"
30
31 G_BEGIN_DECLS
32
33 #define FM_TYPE_FILE_INFO_JOB (fm_file_info_job_get_type())
34 #define FM_FILE_INFO_JOB(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
35 FM_TYPE_FILE_INFO_JOB, FmFileInfoJob))
36 #define FM_FILE_INFO_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),\
37 FM_TYPE_FILE_INFO_JOB, FmFileInfoJobClass))
38 #define FM_IS_FILE_INFO_JOB(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),\
39 FM_TYPE_FILE_INFO_JOB))
40 #define FM_IS_FILE_INFO_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),\
41 FM_TYPE_FILE_INFO_JOB))
42
43 typedef struct _FmFileInfoJob FmFileInfoJob;
44 typedef struct _FmFileInfoJobClass FmFileInfoJobClass;
45
46 /**
47 * FmFileInfoJobFlags:
48 * @FM_FILE_INFO_JOB_NONE: default
49 * @FM_FILE_INFO_JOB_FOLLOW_SYMLINK: not yet implemented
50 * @FM_FILE_INFO_JOB_EMIT_FOR_EACH_FILE: emit #FmFileInfoJob::got-info for each file
51 */
52 typedef enum {
53 FM_FILE_INFO_JOB_NONE = 0,
54 FM_FILE_INFO_JOB_FOLLOW_SYMLINK = 1 << 0, /* FIXME: not yet implemented */
55 FM_FILE_INFO_JOB_EMIT_FOR_EACH_FILE = 1 << 1
56 } FmFileInfoJobFlags;
57
58 /**
59 * FmFileInfoJob
60 * @parent: the parent object
61 * @flags: flags for the job
62 * @file_infos: gathered data
63 */
64 struct _FmFileInfoJob
65 {
66 /*< public >*/
67 FmJob parent;
68 FmFileInfoJobFlags flags;
69 FmFileInfoList* file_infos;
70 /*< private >*/
71 FmPath* current;
72 };
73
74 /**
75 * FmFileInfoJobClass:
76 * @got_info: the class closure for the #FmFileInfoJob::got-info signal.
77 */
78 struct _FmFileInfoJobClass
79 {
80 /*< private >*/
81 FmJobClass parent_class;
82 /*< public >*/
83 void (*got_info)(FmFileInfoJob *job, FmFileInfo *info);
84 /*< private >*/
85 gpointer _reserved1;
86 };
87
88 GType fm_file_info_job_get_type(void);
89 FmFileInfoJob* fm_file_info_job_new(FmPathList* files_to_query, FmFileInfoJobFlags flags);
90
91 /* this can only be called before running the job. */
92 void fm_file_info_job_add(FmFileInfoJob* job, FmPath* path);
93 void fm_file_info_job_add_gfile(FmFileInfoJob* job, GFile* gf);
94
95 /* This API should only be called in error handler */
96 FmPath* fm_file_info_job_get_current(FmFileInfoJob* job);
97
98 #ifndef __GTK_DOC_IGNORE__
99 /* useful inline routines for FmJob classes */
100 static inline gboolean
101 _fm_file_info_job_get_info_for_native_file(FmJob* job, FmFileInfo* fi, const char* path, GError** err)
102 {
103 if( ! fm_job_is_cancelled(job) )
104 return fm_file_info_set_from_native_file(fi, path, err);
105 return TRUE;
106 }
107
108 extern const char gfile_info_query_attribs[];
109
110 static inline gboolean
111 _fm_file_info_job_update_fs_readonly(GFile *gf, GFileInfo *inf, GCancellable *cancellable, GError **error)
112 {
113 /* check if FS is R/O and set attr. into inf */
114 GFileInfo *fs_inf = g_file_query_filesystem_info(gf, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY,
115 cancellable, error);
116 if (fs_inf)
117 {
118 if (g_file_info_has_attribute(fs_inf, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY))
119 g_file_info_set_attribute_boolean(inf, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY,
120 g_file_info_get_attribute_boolean(fs_inf, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY));
121 g_object_unref(fs_inf);
122 return TRUE;
123 }
124 return FALSE;
125 }
126
127 static inline gboolean
128 _fm_file_info_job_get_info_for_gfile(FmJob* job, FmFileInfo* fi, GFile* gf, GError** err)
129 {
130 GFileInfo *inf;
131 inf = g_file_query_info(gf, gfile_info_query_attribs, (GFileQueryInfoFlags)0, fm_job_get_cancellable(job), err);
132 if( !inf )
133 return FALSE;
134 _fm_file_info_job_update_fs_readonly(gf, inf, NULL, NULL);
135 fm_file_info_set_from_g_file_data(fi, gf, inf);
136 g_object_unref(inf);
137
138 return TRUE;
139 }
140 #endif /* __GTK_DOC_IGNORE__ */
141
142 G_END_DECLS
143
144 #endif /* __FM_FILE_INFO_JOB_H__ */