summaryrefslogtreecommitdiff
path: root/src/gui/panels/updating.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-12-24 16:26:51 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-12-24 16:26:51 (GMT)
commit93dfdc30d815629a7e0c9393f0e8f0462844ff56 (patch)
tree8fe59f8c0186871ffd79873ec20905bf39170528 /src/gui/panels/updating.c
parentc388ad8910dbb1a3c478176d8b1ab3142fdbd9d5 (diff)
Ported the panel update mechanisms to the Python API.
Diffstat (limited to 'src/gui/panels/updating.c')
-rw-r--r--src/gui/panels/updating.c56
1 files changed, 40 insertions, 16 deletions
diff --git a/src/gui/panels/updating.c b/src/gui/panels/updating.c
index 31f42c3..c5d59e7 100644
--- a/src/gui/panels/updating.c
+++ b/src/gui/panels/updating.c
@@ -55,7 +55,7 @@ struct _GPanelUpdate
size_t max; /* Marge de progression finale */
void *data; /* Données utiles au traitement*/
- const char *msg; /* Description d'activité */
+ char *msg; /* Description d'activité */
};
@@ -120,24 +120,30 @@ static void g_updatable_panel_default_init(GUpdatablePanelInterface *iface)
* uid = identifiant de la phase de traitement. *
* count = nombre d'étapes à prévoir dans le traitement. [OUT] *
* data = données sur lesquelles s'appuyer ensuite. [OUT] *
+* msg = description du message d'information. [OUT] *
* *
* Description : Prépare une opération de mise à jour de panneau. *
* *
-* Retour : Description du message d'information. *
+* Retour : Bilan de la préparation. *
* *
* Remarques : - *
* *
******************************************************************************/
-const char *g_updatable_panel_setup(const GUpdatablePanel *panel, unsigned int uid, size_t *count, void **data)
+bool g_updatable_panel_setup(const GUpdatablePanel *panel, unsigned int uid, size_t *count, void **data, char **msg)
{
+ bool result; /* Bilan à retourner */
GUpdatablePanelIface *iface; /* Interface utilisée */
iface = G_UPDATABLE_PANEL_GET_IFACE(panel);
+ *count = 0;
*data = NULL;
+ *msg = NULL;
- return iface->setup(panel, uid, count, data);
+ result = iface->setup(panel, uid, count, data, msg);
+
+ return result;
}
@@ -148,7 +154,7 @@ const char *g_updatable_panel_setup(const GUpdatablePanel *panel, unsigned int u
* *
* Description : Obtient le groupe de travail dédié à une mise à jour. *
* *
-* Retour : - *
+* Retour : Identifiant de groupe de travail. *
* *
* Remarques : - *
* *
@@ -259,7 +265,7 @@ void g_updatable_panel_conclude(GUpdatablePanel *panel, unsigned int uid, void *
* *
******************************************************************************/
-void g_updatable_panel_clean_data(GUpdatablePanel *panel, unsigned int uid, void *data)
+void g_updatable_panel_clean_data(const GUpdatablePanel *panel, unsigned int uid, void *data)
{
GUpdatablePanelIface *iface; /* Interface utilisée */
@@ -324,6 +330,12 @@ static void g_panel_update_class_init(GPanelUpdateClass *klass)
static void g_panel_update_init(GPanelUpdate *update)
{
+ update->panel = NULL;
+ update->uid = -1;
+
+ update->max = 0;
+ update->data = NULL;
+ update->msg = NULL;
}
@@ -342,7 +354,10 @@ static void g_panel_update_init(GPanelUpdate *update)
static void g_panel_update_dispose(GPanelUpdate *update)
{
- g_object_unref(G_OBJECT(update->panel));
+ if (update->panel != NULL)
+ g_updatable_panel_clean_data(update->panel, update->uid, update->data);
+
+ g_clear_object(&update->panel);
G_OBJECT_CLASS(g_panel_update_parent_class)->dispose(G_OBJECT(update));
@@ -363,11 +378,12 @@ static void g_panel_update_dispose(GPanelUpdate *update)
static void g_panel_update_finalize(GPanelUpdate *update)
{
- g_updatable_panel_clean_data(update->panel, update->uid, update->data);
-
if (update->data != NULL)
free(update->data);
+ if (update->msg != NULL)
+ free(update->msg);
+
G_OBJECT_CLASS(g_panel_update_parent_class)->finalize(G_OBJECT(update));
}
@@ -389,6 +405,7 @@ static void g_panel_update_finalize(GPanelUpdate *update)
GPanelUpdate *g_panel_update_new(GUpdatablePanel *panel, unsigned int uid)
{
GPanelUpdate *result; /* Tâche à retourner */
+ bool status; /* Bilan de la préparation */
result = g_object_new(G_TYPE_PANEL_UPDATE, NULL);
@@ -397,7 +414,10 @@ GPanelUpdate *g_panel_update_new(GUpdatablePanel *panel, unsigned int uid)
result->uid = uid;
- result->msg = g_updatable_panel_setup(panel, uid, &result->max, &result->data);
+ status = g_updatable_panel_setup(panel, uid, &result->max, &result->data, &result->msg);
+
+ if (!status)
+ g_clear_object(&result);
return result;
@@ -477,15 +497,19 @@ void run_panel_update(GUpdatablePanel *panel, unsigned int uid)
update = g_panel_update_new(panel, uid);
- g_signal_connect_to_main(update, "work-completed", G_CALLBACK(conclude_panel_update), panel,
- g_cclosure_marshal_VOID__VOID);
+ if (update != NULL)
+ {
+ g_signal_connect_to_main(update, "work-completed", G_CALLBACK(conclude_panel_update), panel,
+ g_cclosure_marshal_VOID__VOID);
+
+ g_updatable_panel_introduce(panel, uid, update->data);
- g_updatable_panel_introduce(panel, uid, update->data);
+ queue = get_work_queue();
- queue = get_work_queue();
+ gid = g_updatable_panel_get_group(panel);
- gid = g_updatable_panel_get_group(panel);
+ g_work_queue_schedule_work(queue, G_DELAYED_WORK(update), gid);
- g_work_queue_schedule_work(queue, G_DELAYED_WORK(update), gid);
+ }
}