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

gtask-generic-task.c

Go to the documentation of this file.
00001 #include <string.h>
00002 
00003 #include <gtask/gtask-generic-task.h>
00004 
00007 /* @{ */
00008 
00009 enum {
00010     C_PROP_0,
00011     C_PROP_APP,
00012     C_PROP_ID,
00013     C_PROP_TITLE,
00014     C_PROP_PERCENT,
00015     C_PROP_ACTIVITY_STATE,
00016     C_PROP_STATUS,
00017     C_PROP_ERROR,
00018     C_PROP_CATEGORY,
00019     C_PROP_THUMBNAIL
00020 };
00021 
00022 static gpointer parent_class;
00023 
00024 static void
00025 gtask_generic_task_class_init( GTaskGenericTaskClass *klass );
00026 
00027 static void
00028 gtask_generic_task_init( GTaskGenericTask *gtask );
00029 
00030 static gboolean
00031 gtask_generic_task_fill_xml_doc( GTaskGenericTask *task, xmlDocPtr doc );
00032 
00033 static void
00034 gtask_generic_task_dispose( GObject *obj );
00035 
00036 static void
00037 gtask_generic_task_finalize( GObject *obj );
00038 
00039 
00040 static void
00041 gtask_generic_task_set_property( GObject *object,
00042                                  guint param_id,
00043                                  const GValue *value,
00044                                  GParamSpec *pspec );
00045 
00046 static void
00047 gtask_generic_task_get_property( GObject *object,
00048                                  guint param_id,
00049                                  GValue *value,
00050                                  GParamSpec *pspec );
00051 
00052 GType gtask_activity_state_get_type( ) {
00053     static GType type = 0;
00054 
00055     if( type == 0 ) {
00056         static const GEnumValue values[] = {
00057             { GTASK_ACTIVITY_STATE_ACTIVE, "GTASK_ACTIVITY_STATE_ACTIVE", "active" },
00058             { GTASK_ACTIVITY_STATE_INACTIVE, "GTASK_ACTIVITY_STATE_INACTIVE", "inactive" },
00059             { GTASK_ACTIVITY_STATE_COMPLETED, "GTASK_ACTIVITY_STATE_COMPLETED", "completed" },
00060             { 0, NULL, NULL }
00061         };
00062 
00063         type = g_enum_register_static( "GTaskActivityState", values );
00064     }
00065 
00066     return type;
00067 }
00068 
00069 GType gtask_generic_task_get_type( ) {
00070     static GType type = 0;
00071 
00072     if( type == 0 ) {
00073         static const GTypeInfo info = {
00074             sizeof( GTaskGenericTaskClass ),
00075             NULL,   /* base_init */
00076             NULL,   /* base_finalize */
00077             (GClassInitFunc) gtask_generic_task_class_init,  /* class_init */
00078             NULL,   /* class_finalize */
00079             NULL,   /* class_data */
00080             sizeof( GTaskGenericTask ),
00081             0,      /* n_preallocs */
00082             (GInstanceInitFunc) gtask_generic_task_init
00083         };
00084 
00085         type = g_type_register_static( G_TYPE_OBJECT,
00086                                        "GTaskGenericTask",
00087                                        &info,
00088                                        0 );
00089     }
00090 
00091     return type;
00092 }
00093 
00094 static void
00095 gtask_generic_task_init( GTaskGenericTask *gtask ) {
00096     GTaskGenericTaskPrivate *private;
00097 
00098     private = g_new0( GTaskGenericTaskPrivate, 1 );
00099 
00100     gtask->private = private;
00101 
00102     private->activity_state = GTASK_ACTIVITY_STATE_INACTIVE;
00103 
00104     private->application = g_string_new( NULL );
00105     private->task_id= g_string_new( NULL );
00106     private->title = g_string_new( NULL );
00107     private->category= g_string_new( NULL );
00108     private->thumbnail_uri = g_string_new( NULL );
00109     private->status_msg = g_string_new( NULL );
00110     private->error_msg = g_string_new( NULL );
00111 
00112     private->files = NULL;
00113 
00114     private->time_left = GTASK_TIME_LEFT_UNKNOWN;
00115 
00116     private->dispose_has_run = FALSE;
00117 }
00118 
00129 gboolean
00130 gtask_generic_task_serialize_to( GTaskGenericTask *task,
00131                                  GTaskConnection *conn )
00132 {
00133     xmlOutputBufferPtr xml_output;
00134     xmlDocPtr          doc;
00135     xmlNodePtr         task_node;
00136 
00137     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), FALSE );
00138     g_return_val_if_fail( GTASK_IS_CONNECTION( conn ), FALSE );
00139     g_return_val_if_fail( !task->private->dispose_has_run, FALSE );
00140     g_return_val_if_fail( gtask_connection_is_connected( conn ), FALSE );
00141 
00142     doc = xmlNewDoc( "1.0" );
00143 
00144     if( !doc )
00145         return FALSE;
00146 
00149     if( !gtask_generic_task_fill_xml_doc( task, doc ) ) {
00150         xmlFreeDoc( doc );
00151 
00152         g_message( "error filling xml doc" );
00153         return FALSE;
00154     }
00155 
00156     task_node  = xmlDocGetRootElement( doc );
00157     xml_output = gtask_connection_get_xml_output_buffer( conn );
00158 
00159     xmlNodeDumpOutput( xml_output, doc, task_node, 1, 1, NULL );
00160     xmlOutputBufferFlush( xml_output );
00161 
00162     xmlFreeDoc( doc );
00163 
00164     return TRUE;
00165 }
00166 
00178 static gboolean
00179 gtask_generic_task_fill_xml_doc( GTaskGenericTask *task, xmlDocPtr doc ) {
00180     GTaskGenericTaskPrivate *private = task->private;
00181     xmlNodePtr               task_node;
00182     GString                 *tmp;
00183     GList                   *files = private->files;
00184 
00185     task_node = xmlNewNode( NULL, "task" );
00186 
00187     if( !task_node )
00188         return FALSE;
00189 
00190     xmlDocSetRootElement( doc, task_node );
00191 
00192     if( !xmlNewProp( task_node, "application", private->application->str ) ) {
00193         g_message( "err app" );
00194         return FALSE;
00195     }
00196 
00197     if( !xmlNewProp( task_node, "id", private->task_id->str ) ) {
00198         g_message( "err id" );
00199         return FALSE;
00200     }
00201 
00202     while( files ) {
00203         GTaskFile  *file = GTASK_FILE( files->data );
00204         xmlNodePtr  file_node = xmlNewNode( NULL, "file" );
00205         char       *completed = ( gtask_file_get_completed( file ) ) ? "1" : "0";
00206 
00207         if( !file_node )
00208             return FALSE;
00209 
00210         if( !xmlAddChild( task_node, file_node ) )
00211             return FALSE;
00212 
00213         if( !xmlNewProp( file_node, "uri", gtask_file_get_uri( file ) ) )
00214             return FALSE;
00215 
00216         if( !xmlNewProp( file_node, "thumbnail-uri", gtask_file_get_thumbnail_uri( file ) ) )
00217             return FALSE;
00218 
00219         if( !xmlNewProp( file_node, "description", gtask_file_get_description( file ) ) )
00220             return FALSE;
00221 
00222         if( !xmlNewProp( file_node, "mime-type", gtask_file_get_mime_type( file ) ) )
00223             return FALSE;
00224 
00225         if( !xmlNewProp( file_node, "completed", completed ) )
00226             return FALSE;
00227 
00228         files = g_list_next( files );
00229     }
00230 
00231     if( !xmlNewTextChild( task_node, NULL, "title", private->title->str ) ) {
00232         g_message( "err title" );
00233         return FALSE;
00234     }
00235 
00236     if( !xmlNewTextChild( task_node, NULL, "category", private->category->str ) ) {
00237         g_message( "err category" );
00238         return FALSE;
00239     }
00240 
00241     if( !xmlNewTextChild( task_node, NULL, "thumbnail-uri", private->thumbnail_uri->str ) ) {
00242         g_message( "err thumn" );
00243         return FALSE;
00244     }
00245 
00246     tmp = g_string_new( NULL );
00247 
00248     g_string_printf( tmp, "%0.2f", gtask_generic_task_get_percent_done( task ) );
00249 
00250     if( !xmlNewTextChild( task_node, NULL, "percent-completed", tmp->str ) ) {
00251         g_message( "err percent" );
00252 
00253         g_string_free( tmp, TRUE );
00254         return FALSE;
00255     }
00256 
00257     if( !xmlNewTextChild( task_node, NULL, "activity-state", gtask_generic_task_get_activity_state_as_string( task ) ) ) {
00258         g_message( "err acti" );
00259         return FALSE;
00260     }
00261 
00262     if( !xmlNewTextChild( task_node, NULL, "status-message", private->status_msg->str ) ) {
00263         g_message( "err status" );
00264         return FALSE;
00265     }
00266 
00267     if( !xmlNewTextChild( task_node, NULL, "error-message", private->error_msg->str ) ) {
00268         g_message( "err err" );
00269         return FALSE;
00270     }
00271 
00272     g_string_printf( tmp, "%ld", gtask_generic_task_get_time_left( task ) );
00273 
00274     if( !xmlNewTextChild( task_node, NULL, "time-left", tmp->str ) ) {
00275         g_message( "err time left" );
00276 
00277         g_string_free( tmp, TRUE );
00278         return FALSE;
00279     }
00280 
00281     g_string_free( tmp, TRUE );
00282 
00283     return TRUE;
00284 }
00285 
00295 gboolean
00296 gtask_generic_task_serialize( GTaskGenericTask *task ) {
00297     GSList    *conns;
00298     gboolean  ret = FALSE;
00299 
00300     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), FALSE );
00301     g_return_val_if_fail( !task->private->dispose_has_run, FALSE );
00302 
00303     conns = gtask_connection_group_get_list( task->private->conn_group );
00304 
00305     while( conns ) {
00306         if( !gtask_generic_task_serialize_to( task, (GTaskConnection *) conns->data ) )
00307             ret = FALSE;
00308 
00309         conns = g_slist_next( conns );
00310     }
00311 
00312     return ret;
00313 }
00314 
00315 static void
00316 gtask_generic_task_class_init( GTaskGenericTaskClass *klass ) {
00317     GObjectClass *gobject_class = G_OBJECT_CLASS( klass );
00318 
00319     parent_class = g_type_class_peek_parent( klass );
00320 
00321     gobject_class->dispose = gtask_generic_task_dispose;
00322     gobject_class->finalize = gtask_generic_task_finalize;
00323 
00324     gobject_class->get_property = gtask_generic_task_get_property;
00325     gobject_class->set_property = gtask_generic_task_set_property;
00326 
00327     g_object_class_install_property( gobject_class,
00328                                      C_PROP_APP,
00329                                      g_param_spec_string( "application",
00330                                                           "Application",
00331                                                           "The name of the application handling the task.",
00332                                                           "",
00333                                                           G_PARAM_READWRITE ) );
00334 
00335     g_object_class_install_property( gobject_class,
00336                                      C_PROP_ID,
00337                                      g_param_spec_string( "task-id",
00338                                                           "Task Id",
00339                                                           "The unique identifier of the task.",
00340                                                           "",
00341                                                           G_PARAM_READWRITE ) );
00342 
00343     g_object_class_install_property( gobject_class,
00344                                      C_PROP_TITLE,
00345                                      g_param_spec_string( "title",
00346                                                           "Title",
00347                                                           "The title of the task.",
00348                                                           "",
00349                                                           G_PARAM_READWRITE ) );
00350 
00351     g_object_class_install_property( gobject_class,
00352                                      C_PROP_THUMBNAIL,
00353                                      g_param_spec_string( "thumbnail-uri",
00354                                                           "Thumbnail Uri",
00355                                                           "The uri of to be used as a thumbnail (preview) for the task.",
00356                                                           "",
00357                                                           G_PARAM_READWRITE ) );
00358 
00359     g_object_class_install_property( gobject_class,
00360                                      C_PROP_PERCENT,
00361                                      g_param_spec_float( "percent-done",
00362                                                          "Percent Done",
00363                                                           "The percentage of the task that is completed.",
00364                                                           0.0, 1.0, 0.0,
00365                                                           G_PARAM_READWRITE ) );
00366 
00367     g_object_class_install_property( gobject_class,
00368                                      C_PROP_ACTIVITY_STATE,
00369                                      g_param_spec_enum( "activity-state",
00370                                                         "Activity State",
00371                                                         "The activity state of the task (active, inactive, or completed).",
00372                                                         GTASK_ACTIVITY_STATE_TYPE,
00373                                                         GTASK_ACTIVITY_STATE_INACTIVE,
00374                                                         G_PARAM_READWRITE ) );
00375 
00376     g_object_class_install_property( gobject_class,
00377                                      C_PROP_STATUS,
00378                                      g_param_spec_string( "status-message",
00379                                                           "Status Message",
00380                                                           "The status message associated with the task. This field should be set to information that is deemed useful for the user.",
00381                                                           "",
00382                                                           G_PARAM_READWRITE ) );
00383 
00384     g_object_class_install_property( gobject_class,
00385                                      C_PROP_ERROR,
00386                                      g_param_spec_string( "error-message",
00387                                                           "Error Message",
00388                                                           "The error message associated with the task. This field should be set if an error has occurred and cleared once the error condition ceases to be relevant.",
00389                                                           "",
00390                                                           G_PARAM_READWRITE ) );
00391 
00392     g_object_class_install_property( gobject_class,
00393                                      C_PROP_CATEGORY,
00394                                      g_param_spec_string( "category",
00395                                                           "Category",
00396                                                           "The category of the task.",
00397                                                           "",
00398                                                           G_PARAM_READWRITE ) );
00399 }
00400 
00401 static void
00402 gtask_generic_task_dispose( GObject *obj ) {
00403     GTaskGenericTask *task = GTASK_GENERIC_TASK( obj );
00404 
00405     if( task->private->dispose_has_run )
00406         return;
00407 
00408     g_object_unref( task->private->conn_group );
00409 
00410     g_list_foreach( task->private->files, (GFunc) g_object_unref, NULL );
00411     g_list_free( task->private->files );
00412 
00413     task->private->files = NULL;
00414 
00415     task->private->conn_group = NULL;
00416 
00417     task->private->dispose_has_run = TRUE;
00418 
00419     if( G_OBJECT_CLASS( parent_class )->dispose )
00420         G_OBJECT_CLASS( parent_class )->dispose( obj );
00421 }
00422 
00423 static void
00424 gtask_generic_task_finalize( GObject *obj ) {
00425     GTaskGenericTask        *task = GTASK_GENERIC_TASK( obj );
00426     GTaskGenericTaskPrivate *private = task->private;
00427 
00428     g_string_free( private->application, TRUE );
00429 
00430     g_string_free( private->task_id, TRUE );
00431 
00432     g_string_free( private->title, TRUE );
00433 
00434     g_string_free( private->thumbnail_uri, TRUE );
00435 
00436     g_string_free( private->status_msg, TRUE );
00437 
00438     g_string_free( private->error_msg, TRUE );
00439 
00440     g_free( task->private );
00441 
00442     if( G_OBJECT_CLASS( parent_class )->finalize )
00443         G_OBJECT_CLASS( parent_class )->finalize( obj );
00444 }
00445 
00446 static void
00447 gtask_generic_task_set_property( GObject *object,
00448                                  guint param_id,
00449                                  const GValue *value,
00450                                  GParamSpec *pspec )
00451 {
00452     GTaskGenericTask *task = GTASK_GENERIC_TASK( object );
00453 
00454     switch( param_id ) {
00455         case C_PROP_APP:
00456             gtask_generic_task_set_application( task, g_value_get_string( value ) );
00457             break;
00458         case C_PROP_ID:
00459             gtask_generic_task_set_id( task, g_value_get_string( value ) );
00460             break;
00461         case C_PROP_TITLE:
00462             gtask_generic_task_set_title( task, g_value_get_string( value ) );
00463             break;
00464         case C_PROP_PERCENT:
00465             gtask_generic_task_set_percent_done( task, g_value_get_float( value ) );
00466             break;
00467         case C_PROP_ACTIVITY_STATE:
00468             gtask_generic_task_set_activity_state( task, g_value_get_enum( value ) );
00469             break;
00470         case C_PROP_STATUS:
00471             gtask_generic_task_set_status_message( task, g_value_get_string( value ) );
00472             break;
00473         case C_PROP_ERROR:
00474             gtask_generic_task_set_error_message( task, g_value_get_string( value ) );
00475             break;
00476         case C_PROP_CATEGORY:
00477             gtask_generic_task_set_category( task, g_value_get_string( value ) );
00478             break;
00479         default:
00480             G_OBJECT_WARN_INVALID_PROPERTY_ID( object, param_id, pspec );
00481     }
00482 }
00483 
00484 static void
00485 gtask_generic_task_get_property( GObject *object,
00486                                  guint param_id,
00487                                  GValue *value,
00488                                  GParamSpec *pspec )
00489 {
00490     GTaskGenericTask        *task = GTASK_GENERIC_TASK( object );
00491     GTaskGenericTaskPrivate *private = task->private;
00492 
00493     switch( param_id ) {
00494         case C_PROP_APP:
00495             g_value_set_string( value, private->application->str );
00496             break;
00497         case C_PROP_ID:
00498             g_value_set_string( value, private->task_id->str );
00499             break;
00500         case C_PROP_TITLE:
00501             g_value_set_string( value, private->title->str );
00502             break;
00503         case C_PROP_PERCENT:
00504             g_value_set_float( value, private->percent_done );
00505             break;
00506         case C_PROP_ACTIVITY_STATE:
00507             g_value_set_enum( value, private->activity_state );
00508             break;
00509         case C_PROP_STATUS:
00510             g_value_set_string( value, private->status_msg->str );
00511             break;
00512         case C_PROP_ERROR:
00513             g_value_set_string( value, private->error_msg->str );
00514             break;
00515         case C_PROP_CATEGORY:
00516             g_value_set_string( value, private->category->str );
00517             break;
00518         default:
00519             G_OBJECT_WARN_INVALID_PROPERTY_ID( object, param_id, pspec );
00520     }
00521 }
00522 
00523 
00531 GTaskGenericTask *
00532 gtask_generic_task_new( ) {
00533     return g_object_new( GTASK_GENERIC_TASK_TYPE, NULL );
00534 }
00535 
00548 GTaskGenericTask *
00549 gtask_generic_task_new_with_connection_group( GTaskConnectionGroup *conn_group ) {
00550     GTaskGenericTask *task;
00551 
00552     g_return_val_if_fail( GTASK_IS_CONNECTION_GROUP( conn_group ), NULL );
00553     
00554     task = gtask_generic_task_new( );
00555 
00556     task->private->conn_group = conn_group;
00557 
00558     g_object_ref( conn_group );
00559 
00560     return task;
00561 }
00562 
00571 void
00572 gtask_generic_task_set_application( GTaskGenericTask *task, const gchar *app ) {
00573     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00574     g_return_if_fail( app != NULL );
00575     g_return_if_fail( !task->private->dispose_has_run );
00576 
00577     g_string_assign( task->private->application, app );
00578 
00579     g_object_notify( (GObject *) task, "application" );
00580 }
00581 
00593 const gchar *
00594 gtask_generic_task_get_application( GTaskGenericTask *task ) {
00595     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), "" );
00596 
00597     return task->private->application->str;
00598 }
00599 
00608 void
00609 gtask_generic_task_set_id( GTaskGenericTask *task, const gchar *id ) {
00610     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00611     g_return_if_fail( id != NULL );
00612 
00613     g_string_assign( task->private->task_id, id );
00614 
00615     g_object_notify( (GObject *)task, "task-id" );
00616 }
00617 
00629 const gchar *
00630 gtask_generic_task_get_id( GTaskGenericTask *task ) {
00631     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), "" );
00632 
00633     return task->private->task_id->str;
00634 }
00635 
00644 void
00645 gtask_generic_task_set_title( GTaskGenericTask *task, const gchar *title ) {
00646     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00647     g_return_if_fail( title != NULL );
00648 
00649     g_string_assign( task->private->title, title );
00650 
00651     g_object_notify( (GObject *) task, "title" );
00652 }
00653 
00665 const gchar *
00666 gtask_generic_task_get_title( GTaskGenericTask *task ) {
00667     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), "" );
00668 
00669     return task->private->title->str;
00670 }
00671 
00678 void
00679 gtask_generic_task_set_thumbnail_uri( GTaskGenericTask *task,
00680                                       const gchar *uri )
00681 {
00682     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00683     g_return_if_fail( uri != NULL );
00684 
00685     g_string_assign( task->private->thumbnail_uri, uri );
00686 
00687     g_object_notify( (GObject *) task, "thumbnail-uri" );
00688 }
00689 
00701 const gchar*
00702 gtask_generic_task_get_thumbnail_uri( GTaskGenericTask *task ) {
00703     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), "" );
00704 
00705     return task->private->thumbnail_uri->str;
00706 }
00707 
00722 void
00723 gtask_generic_task_set_percent_done( GTaskGenericTask *task, gfloat percent ) {
00724     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00725 
00726     if( percent < 0 )
00727         percent = 0.0;
00728     else if( percent >= 1.0 ) {
00729         percent = 1.0;
00730 
00731         gtask_generic_task_set_activity_state( task,
00732                                                GTASK_ACTIVITY_STATE_COMPLETED );
00733     } else {
00734         gtask_generic_task_set_activity_state( task,
00735                                                GTASK_ACTIVITY_STATE_ACTIVE );
00736     }
00737 
00738     task->private->percent_done = percent;
00739 
00740     g_object_notify( (GObject *) task, "percent-done" );
00741 }
00742 
00752 gfloat
00753 gtask_generic_task_get_percent_done( GTaskGenericTask *task ) {
00754     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), 0.0 );
00755 
00756     return task->private->percent_done;
00757 }
00758 
00771 void
00772 gtask_generic_task_set_activity_state( GTaskGenericTask *task, 
00773                                        GTaskActivityState state )
00774 {
00775     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00776 
00777     task->private->activity_state = state;
00778 
00779     if( state == GTASK_ACTIVITY_STATE_COMPLETED ) {
00780         GList *files = gtask_generic_task_get_files( task );
00781 
00782         g_warning( "=+=+=+=+=+=+=+=+=+> setting down files" );
00783         while( files ) {
00784             GTaskFile *file = (GTaskFile *) files->data;
00785 
00786             g_warning( "HEH" );
00787 
00788             gtask_file_set_completed( file, TRUE );
00789 
00790             files = g_list_next( files );
00791         }
00792     }
00793 
00794     g_object_notify( (GObject *) task, "activity-state" );
00795 }
00796 
00806 GTaskActivityState
00807 gtask_generic_task_get_activity_state( GTaskGenericTask *task ) {
00808     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ),
00809                           GTASK_ACTIVITY_STATE_INACTIVE );
00810 
00811     return task->private->activity_state;
00812 }
00813 
00823 const gchar *
00824 gtask_generic_task_get_activity_state_as_string( GTaskGenericTask *task ) {
00825     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), "unknown" );
00826 
00827     switch( task->private->activity_state ) {
00828         case GTASK_ACTIVITY_STATE_ACTIVE:
00829             return "active";
00830         case GTASK_ACTIVITY_STATE_INACTIVE:
00831             return "inactive";
00832         case GTASK_ACTIVITY_STATE_COMPLETED:
00833             return "completed";
00834         default:
00835             break;
00836     }
00837 
00838     return "unknown";
00839 }
00840 
00851 void
00852 gtask_generic_task_set_activity_state_from_string( GTaskGenericTask *task,
00853                                                    const char *state )
00854 {
00855     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00856     g_return_if_fail( state != NULL );
00857 
00858     if( strcasecmp( state, "active" ) == 0 ) {
00859         gtask_generic_task_set_activity_state( task,
00860                                                GTASK_ACTIVITY_STATE_ACTIVE );
00861     } else if( strcasecmp( state, "completed" ) == 0 ) {
00862         gtask_generic_task_set_activity_state( task,
00863                                                GTASK_ACTIVITY_STATE_COMPLETED );
00864     } else {
00865         gtask_generic_task_set_activity_state( task,
00866                                                GTASK_ACTIVITY_STATE_INACTIVE );
00867     }
00868 
00869     g_object_notify( (GObject *) task, "activity-state" );
00870 }
00871 
00880 void
00881 gtask_generic_task_set_status_message( GTaskGenericTask *task,
00882                                        const gchar *msg )
00883 {
00884     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00885     g_return_if_fail( msg != NULL );
00886 
00887     g_string_assign( task->private->status_msg, msg );
00888 
00889     g_object_notify( (GObject *) task, "status-message" );
00890 }
00891 
00902 const gchar *
00903 gtask_generic_task_get_status_message( GTaskGenericTask *task ) {
00904     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), "" );
00905 
00906     return task->private->status_msg->str;
00907 }
00908 
00917 void
00918 gtask_generic_task_set_error_message( GTaskGenericTask *task,
00919                                       const gchar *msg )
00920 {
00921     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00922     g_return_if_fail( msg != NULL );
00923 
00924     g_string_assign( task->private->error_msg, msg );
00925 
00926     g_object_notify( (GObject *) task, "error-message" );
00927 }
00928 
00940 const gchar *
00941 gtask_generic_task_get_error_message( GTaskGenericTask *task ) {
00942     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), "" );
00943 
00944     return task->private->error_msg->str;
00945 }
00946 
00955 void
00956 gtask_generic_task_set_category( GTaskGenericTask *task, const gchar *cat ) {
00957     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00958     g_return_if_fail( cat != NULL );
00959 
00960     g_string_assign( task->private->category, cat );
00961 
00962     g_object_notify( (GObject *) task, "category" );
00963 }
00964 
00976 const gchar *
00977 gtask_generic_task_get_category( GTaskGenericTask *task ) {
00978     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), "" );
00979 
00980     return task->private->category->str;
00981 }
00982 
00988 void
00989 gtask_generic_task_dump( GTaskGenericTask *task ) {
00990     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
00991 
00992     printf( "GTaskGenericTask:\n" );
00993     printf( "\tApplication: %s\n", gtask_generic_task_get_application( task ) ) ;
00994     printf( "\tId: %s\n", gtask_generic_task_get_id( task ) ) ;
00995     printf( "\tCategory: %s\n", gtask_generic_task_get_category( task ) ) ;
00996     printf( "\tThumbnail URI: %s\n", gtask_generic_task_get_thumbnail_uri( task ) ) ;
00997     printf( "\tStatus Message: %s\n", gtask_generic_task_get_status_message( task ) ) ;
00998     printf( "\tError Message: %s\n", gtask_generic_task_get_error_message( task ) ) ;
00999     printf( "\tPercent Done: %f\n", gtask_generic_task_get_percent_done( task ) ) ;
01000     printf( "\tTime Left: %ld\n", gtask_generic_task_get_time_left( task ) ) ;
01001     printf( "\tActivity State: %s\n", gtask_generic_task_get_activity_state_as_string( task ) ) ;
01002 }
01003 
01014 void
01015 gtask_generic_task_set_time_left( GTaskGenericTask *task, glong time_left ) {
01016     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
01017 
01018     task->private->time_left = ( time_left < 0 ) ? GTASK_TIME_LEFT_UNKNOWN : time_left;
01019 }
01020 
01029 glong
01030 gtask_generic_task_get_time_left( GTaskGenericTask *task ) {
01031     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), GTASK_TIME_LEFT_UNKNOWN );
01032 
01033     return task->private->time_left;
01034 
01035 }
01036 
01047 void
01048 gtask_generic_task_add_file( GTaskGenericTask *task, GTaskFile *file ) {
01049     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
01050     g_return_if_fail( GTASK_IS_FILE( file ) );
01051 
01052     g_object_ref( file );
01053 
01054     task->private->files = g_list_append( task->private->files, file );
01055 }
01056 
01066 void
01067 gtask_generic_task_add_files( GTaskGenericTask *task, GList *files ) {
01068     GList *list = files;
01069 
01070     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
01071 
01072     while( list ) {
01073         if( !GTASK_IS_FILE( list->data ) )
01074             continue;
01075 
01076         g_object_ref( list->data );
01077         
01078         task->private->files = g_list_append( task->private->files, list->data );
01079 
01080         list = g_list_next( list );
01081     }
01082 }
01083 
01093 GList *
01094 gtask_generic_task_get_files( GTaskGenericTask *task ) {
01095     g_return_val_if_fail( GTASK_IS_GENERIC_TASK( task ), NULL );
01096 
01097     return task->private->files;
01098 }
01099 
01105 void
01106 gtask_generic_task_clear_files( GTaskGenericTask *task ) {
01107     g_return_if_fail( GTASK_IS_GENERIC_TASK( task ) );
01108 
01109     g_list_foreach( task->private->files, (GFunc) g_object_unref, NULL );
01110 
01111     g_list_free( task->private->files );
01112 
01113     task->private->files = NULL;
01114 }
01115 
01116 /* @} */

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