| 1 | /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ |
| 2 | /* vim:set et sts=4: */ |
| 3 | /* ibus - The Input IBus |
| 4 | * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com> |
| 5 | * Copyright (C) 2008-2013 Red Hat, Inc. |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 20 | * USA |
| 21 | */ |
| 22 | |
| 23 | #if !defined (__IBUS_H_INSIDE__) && !defined (IBUS_COMPILATION) |
| 24 | #error "Only <ibus.h> can be included directly" |
| 25 | #endif |
| 26 | |
| 27 | #ifndef __IBUS_OBSERVED_PATH_H_ |
| 28 | #define __IBUS_OBSERVED_PATH_H_ |
| 29 | |
| 30 | /** |
| 31 | * SECTION: ibusobservedpath |
| 32 | * @short_description: Path object of IBus. |
| 33 | * @stability: Stable |
| 34 | * |
| 35 | * IBusObservedPath provides methods for file path manipulation, |
| 36 | * such as monitor modification, directory tree traversal. |
| 37 | */ |
| 38 | |
| 39 | #include "ibusserializable.h" |
| 40 | #include "ibusxml.h" |
| 41 | |
| 42 | /* |
| 43 | * Type macros. |
| 44 | */ |
| 45 | |
| 46 | /* define GOBJECT macros */ |
| 47 | #define IBUS_TYPE_OBSERVED_PATH \ |
| 48 | (ibus_observed_path_get_type ()) |
| 49 | #define IBUS_OBSERVED_PATH(obj) \ |
| 50 | (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_OBSERVED_PATH, IBusObservedPath)) |
| 51 | #define IBUS_OBSERVED_PATH_CLASS(klass) \ |
| 52 | (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_OBSERVED_PATH, IBusObservedPathClass)) |
| 53 | #define IBUS_IS_OBSERVED_PATH(obj) \ |
| 54 | (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_OBSERVED_PATH)) |
| 55 | #define IBUS_IS_OBSERVED_PATH_CLASS(klass) \ |
| 56 | (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_OBSERVED_PATH)) |
| 57 | #define IBUS_OBSERVED_PATH_GET_CLASS(obj) \ |
| 58 | (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_OBSERVED_PATH, IBusObservedPathClass)) |
| 59 | |
| 60 | G_BEGIN_DECLS |
| 61 | |
| 62 | typedef struct _IBusObservedPath IBusObservedPath; |
| 63 | typedef struct _IBusObservedPathClass IBusObservedPathClass; |
| 64 | |
| 65 | /** |
| 66 | * IBusObservedPath: |
| 67 | * @path: Path to be handled. |
| 68 | * @mtime: Modified time. |
| 69 | * @is_dir: Whether the file is the path directory. |
| 70 | * @is_exist: Whether the file exists. |
| 71 | * |
| 72 | * Data structure of IBusObservedPath. |
| 73 | */ |
| 74 | struct _IBusObservedPath { |
| 75 | IBusSerializable parent; |
| 76 | /* instance members */ |
| 77 | |
| 78 | /*< public >*/ |
| 79 | gchar *path; |
| 80 | glong mtime; |
| 81 | gboolean is_dir; |
| 82 | gboolean is_exist; |
| 83 | |
| 84 | }; |
| 85 | |
| 86 | struct _IBusObservedPathClass { |
| 87 | IBusSerializableClass parent; |
| 88 | |
| 89 | /* class members */ |
| 90 | }; |
| 91 | |
| 92 | GType ibus_observed_path_get_type (void); |
| 93 | |
| 94 | /** |
| 95 | * ibus_observed_path_new_from_xml_node: |
| 96 | * @node: An XML node that contain path. |
| 97 | * @fill_stat: Auto-fill the path status. |
| 98 | * |
| 99 | * Creates an new #IBusObservedPath from an XML node. |
| 100 | * |
| 101 | * Returns: A newly allocated #IBusObservedPath. |
| 102 | */ |
| 103 | IBusObservedPath *ibus_observed_path_new_from_xml_node (XMLNode *node, |
| 104 | gboolean fill_stat); |
| 105 | |
| 106 | /** |
| 107 | * ibus_observed_path_new: |
| 108 | * @path: The path string. |
| 109 | * @fill_stat: Auto-fill the path status. |
| 110 | * |
| 111 | * Creates a new #IBusObservedPath from an XML node. |
| 112 | * |
| 113 | * Returns: A newly allocated #IBusObservedPath. |
| 114 | */ |
| 115 | IBusObservedPath *ibus_observed_path_new (const gchar *path, |
| 116 | gboolean fill_stat); |
| 117 | |
| 118 | /** |
| 119 | * ibus_observed_path_traverse: |
| 120 | * @path: An IBusObservedPath. |
| 121 | * @dir_only: Only looks for subdirs, not files |
| 122 | * |
| 123 | * Recursively traverse the path and put the files and subdirectory in to |
| 124 | * a newly allocated |
| 125 | * GLists, if the @path is a directory. Otherwise returns NULL. |
| 126 | * |
| 127 | * Returns: (transfer full) (element-type IBusObservedPath): A newly allocate |
| 128 | * GList which holds content in path; NULL if @path is not directory. |
| 129 | */ |
| 130 | GList *ibus_observed_path_traverse (IBusObservedPath *path, |
| 131 | gboolean dir_only); |
| 132 | |
| 133 | /** |
| 134 | * ibus_observed_path_check_modification: |
| 135 | * @path: An IBusObservedPath. |
| 136 | * |
| 137 | * Checks whether the path is modified by comparing the mtime in object and |
| 138 | * mtime in file system. |
| 139 | * |
| 140 | * Returns: %TRUE if imtime is changed, otherwise %FALSE. |
| 141 | */ |
| 142 | gboolean ibus_observed_path_check_modification (IBusObservedPath *path); |
| 143 | |
| 144 | /** |
| 145 | * ibus_observed_path_output: |
| 146 | * @path: An IBusObservedPath. |
| 147 | * @output: Path is appended to. |
| 148 | * @indent: number of indent. |
| 149 | * |
| 150 | * Append the observed path to a string with following format: |
| 151 | * <path mtime="<i>modified time</i>" ><i>path</i></path> |
| 152 | */ |
| 153 | void ibus_observed_path_output (IBusObservedPath *path, |
| 154 | GString *output, |
| 155 | gint indent); |
| 156 | |
| 157 | G_END_DECLS |
| 158 | #endif |
| 159 | |
| 160 | |