Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

gtask-file.c

Go to the documentation of this file.
00001 #include <string.h>
00002 
00003 #include <gtask/gtask-file.h>
00004 
00007 /* @{ */
00008 
00009 enum {
00010     C_PROP_0,
00011     C_PROP_URI,
00012     C_PROP_MIME_TYPE,
00013     C_PROP_THUMBNAIL_URI,
00014     C_PROP_DESCRIPTION,
00015     C_PROP_COMPLETED
00016 };
00017 
00018 static gpointer parent_class;
00019 
00020 static void
00021 gtask_file_class_init( GTaskFileClass *klass );
00022 
00023 static void
00024 gtask_file_init( GTaskFile *gtask );
00025 
00026 static void
00027 gtask_file_finalize( GObject *obj );
00028 
00029 
00030 static void
00031 gtask_file_set_property( GObject *object,
00032                          guint param_id,
00033                          const GValue *value,
00034                          GParamSpec *pspec );
00035 
00036 static void
00037 gtask_file_get_property( GObject *object,
00038                          guint param_id,
00039                          GValue *value,
00040                          GParamSpec *pspec );
00041 
00042 GType gtask_file_get_type( ) {
00043     static GType type = 0;
00044 
00045     if( type == 0 ) {
00046         static const GTypeInfo info = {
00047             sizeof( GTaskFileClass ),
00048             NULL,   /* base_init */
00049             NULL,   /* base_finalize */
00050             (GClassInitFunc) gtask_file_class_init,  /* class_init */
00051             NULL,   /* class_finalize */
00052             NULL,   /* class_data */
00053             sizeof( GTaskFile ),
00054             0,      /* n_preallocs */
00055             (GInstanceInitFunc) gtask_file_init
00056         };
00057 
00058         type = g_type_register_static( G_TYPE_OBJECT,
00059                                        "GTaskFile",
00060                                        &info,
00061                                        0 );
00062     }
00063 
00064     return type;
00065 }
00066 
00067 static void
00068 gtask_file_init( GTaskFile *file ) {
00069     GTaskFilePrivate *private = g_new0( GTaskFilePrivate, 1 );
00070 
00071     file->private = private;
00072 
00073     private->uri = g_string_new( NULL );
00074     private->thumbnail_uri = g_string_new( NULL );
00075     private->description = g_string_new( NULL );
00076     private->mime_type = g_string_new( NULL );
00077     private->completed = FALSE;
00078 }
00079 
00080 static void
00081 gtask_file_class_init( GTaskFileClass *klass ) {
00082     GObjectClass *gobject_class = G_OBJECT_CLASS( klass );
00083 
00084     parent_class = g_type_class_peek_parent( klass );
00085 
00086     gobject_class->finalize = gtask_file_finalize;
00087 
00088     gobject_class->get_property = gtask_file_get_property;
00089     gobject_class->set_property = gtask_file_set_property;
00090 
00091     g_object_class_install_property( gobject_class,
00092                                      C_PROP_URI,
00093                                      g_param_spec_string( "uri",
00094                                                           "URIApplication",
00095                                                           "The uri of the file.",
00096                                                           "",
00097                                                           G_PARAM_READWRITE ) );
00098 
00099     g_object_class_install_property( gobject_class,
00100                                      C_PROP_THUMBNAIL_URI,
00101                                      g_param_spec_string( "thumbnail-uri",
00102                                                           "Thumbnail URI",
00103                                                           "The URI of a thumbnail to be used while the GTaskFile has yet to be completed",
00104                                                           "",
00105                                                           G_PARAM_READWRITE ) );
00106 
00107     g_object_class_install_property( gobject_class,
00108                                      C_PROP_MIME_TYPE,
00109                                      g_param_spec_string( "mime-type",
00110                                                           "Mime Type",
00111                                                           "The mime type of the file.",
00112                                                           "",
00113                                                           G_PARAM_READWRITE ) );
00114 
00115     g_object_class_install_property( gobject_class,
00116                                      C_PROP_DESCRIPTION,
00117                                      g_param_spec_string( "description",
00118                                                           "Description",
00119                                                           "An optional human readable description of the file. This is generally used instead of printing out the uri.",
00120                                                           "",
00121                                                           G_PARAM_READWRITE ) );
00122 
00123     g_object_class_install_property( gobject_class,
00124                                      C_PROP_COMPLETED,
00125                                      g_param_spec_boolean( "completed",
00126                                                            "Completed",
00127                                                            "Whether or not all task interactions with this file have been completed.",
00128                                                            FALSE,
00129                                                            G_PARAM_READWRITE ) );
00130 }
00131 
00132 static void
00133 gtask_file_finalize( GObject *obj ) {
00134     GTaskFile        *task = GTASK_FILE( obj );
00135     GTaskFilePrivate *private = task->private;
00136 
00137     g_string_free( private->uri, TRUE );
00138 
00139     g_string_free( private->thumbnail_uri, TRUE );
00140 
00141     g_string_free( private->mime_type, TRUE );
00142 
00143     g_string_free( private->description, TRUE );
00144 
00145     g_free( task->private );
00146 
00147     if( G_OBJECT_CLASS( parent_class )->finalize )
00148         G_OBJECT_CLASS( parent_class )->finalize( obj );
00149 }
00150 
00151 static void
00152 gtask_file_set_property( GObject *object,
00153                          guint param_id,
00154                          const GValue *value,
00155                          GParamSpec *pspec )
00156 {
00157     GTaskFile *file = GTASK_FILE( object );
00158 
00159     switch( param_id ) {
00160         case C_PROP_URI:
00161             gtask_file_set_uri( file, g_value_get_string( value ) );
00162             break;
00163         case C_PROP_THUMBNAIL_URI:
00164             gtask_file_set_thumbnail_uri( file, g_value_get_string( value ) );
00165             break;
00166         case C_PROP_MIME_TYPE:
00167             gtask_file_set_mime_type( file, g_value_get_string( value ) );
00168             break;
00169         case C_PROP_DESCRIPTION:
00170             gtask_file_set_description( file, g_value_get_string( value ) );
00171             break;
00172         case C_PROP_COMPLETED:
00173             gtask_file_set_completed( file, g_value_get_boolean( value ) );
00174             break;
00175         default:
00176             G_OBJECT_WARN_INVALID_PROPERTY_ID( object, param_id, pspec );
00177     }
00178 }
00179 
00180 static void
00181 gtask_file_get_property( GObject *object,
00182                          guint param_id,
00183                          GValue *value,
00184                          GParamSpec *pspec )
00185 {
00186     GTaskFile        *file = GTASK_FILE( object );
00187     GTaskFilePrivate *private = file->private;
00188 
00189     switch( param_id ) {
00190         case C_PROP_URI:
00191             g_value_set_string( value, private->uri->str );
00192             break;
00193         case C_PROP_THUMBNAIL_URI:
00194             g_value_set_string( value, private->thumbnail_uri->str );
00195             break;
00196         case C_PROP_MIME_TYPE:
00197             g_value_set_string( value, private->mime_type->str );
00198             break;
00199         case C_PROP_DESCRIPTION:
00200             g_value_set_string( value, private->description->str );
00201             break;
00202         case C_PROP_COMPLETED:
00203             g_value_set_boolean( value, private->completed );
00204             break;
00205         default:
00206             G_OBJECT_WARN_INVALID_PROPERTY_ID( object, param_id, pspec );
00207     }
00208 }
00209 
00210 
00218 GTaskFile *
00219 gtask_file_new( ) {
00220     return g_object_new( GTASK_FILE_TYPE, NULL );
00221 }
00222 
00235 GTaskFile *
00236 gtask_file_new_with_properties( const char *uri,
00237                                 const char *mime_type,
00238                                 const char *thumbnail_uri,
00239                                 const char *description )
00240 {
00241     GTaskFile *file = gtask_file_new( );
00242 
00243     gtask_file_set_uri( file, uri );
00244     gtask_file_set_mime_type( file, mime_type );
00245     gtask_file_set_thumbnail_uri( file, thumbnail_uri );
00246     gtask_file_set_description( file, description );
00247 
00248     return file;
00249 }
00250 
00257 void
00258 gtask_file_set_uri( GTaskFile *file, const char *uri ) {
00259     g_return_if_fail( GTASK_IS_FILE( file ) );
00260     g_return_if_fail( uri != NULL );
00261 
00262     g_string_assign( file->private->uri, uri );
00263 
00264     g_object_notify( (GObject *) file, "uri" );
00265 }
00266 
00276 const char *
00277 gtask_file_get_uri( GTaskFile *file ) {
00278     g_return_val_if_fail( GTASK_IS_FILE( file ), "" );
00279 
00280     return file->private->uri->str;
00281 }
00282 
00289 void
00290 gtask_file_set_thumbnail_uri( GTaskFile *file, const char *thumbnail_uri ) {
00291     g_return_if_fail( GTASK_IS_FILE( file ) );
00292     g_return_if_fail( thumbnail_uri != NULL );
00293 
00294     g_string_assign( file->private->thumbnail_uri, thumbnail_uri );
00295 
00296     g_object_notify( (GObject *) file, "thumbnail-uri" );
00297 }
00298 
00308 const char *
00309 gtask_file_get_thumbnail_uri( GTaskFile *file ) {
00310     g_return_val_if_fail( GTASK_IS_FILE( file ), "" );
00311 
00312     return file->private->thumbnail_uri->str;
00313 }
00314 
00321 void
00322 gtask_file_set_mime_type( GTaskFile *file, const char *mime_type ) {
00323     g_return_if_fail( GTASK_IS_FILE( file ) );
00324     g_return_if_fail( mime_type != NULL );
00325 
00326     g_string_assign( file->private->mime_type, mime_type );
00327 
00328     g_object_notify( (GObject *) file, "mime-type" );
00329 }
00330 
00340 const char *
00341 gtask_file_get_mime_type( GTaskFile *file ) {
00342     g_return_val_if_fail( GTASK_IS_FILE( file ), "" );
00343 
00344     return file->private->mime_type->str;
00345 }
00346 
00354 void
00355 gtask_file_set_description( GTaskFile *file, const char *description ) {
00356     g_return_if_fail( GTASK_IS_FILE( file ) );
00357     g_return_if_fail( description != NULL );
00358 
00359     g_string_assign( file->private->description, description );
00360 
00361     g_object_notify( (GObject *) file, "description" );
00362 }
00363 
00373 const char *
00374 gtask_file_get_description( GTaskFile *file ) {
00375     g_return_val_if_fail( GTASK_IS_FILE( file ), "" );
00376 
00377     return file->private->description->str;
00378 }
00379 
00386 void
00387 gtask_file_set_completed( GTaskFile *file, gboolean completed ) {
00388     g_return_if_fail( GTASK_IS_FILE( file ) );
00389 
00390     file->private->completed = completed;
00391 
00392     g_object_notify( (GObject *) file, "completed" );
00393 }
00394 
00402 gboolean
00403 gtask_file_get_completed( GTaskFile *file ) {
00404     g_return_val_if_fail( GTASK_IS_FILE( file ), FALSE );
00405 
00406     return file->private->completed;
00407 }

Generated on Mon Feb 2 21:26:14 2004 for libgtask by doxygen 1.3.4