Skip to content

Commit

Permalink
Merge pull request #17362 from zisoft/piwigo-login-check
Browse files Browse the repository at this point in the history
[piwigo export] fix crash when not logged in
  • Loading branch information
TurboGit authored Aug 26, 2024
2 parents 9cbb4a8 + d2ccd6f commit 31b04e6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/control/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ static dt_signal_description _signal_description[DT_SIGNAL_COUNT] = {
{ "dt-location-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_generic, 1, pointer_arg, NULL,
TRUE }, // DT_SIGNAL_LOCATION_CHANGED

{ "dt-imageio-storage-export-enable", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL,
FALSE }, // DT_SIGNAL_IMAGEIO_STORAGE_EXPORT_ENABLE

};

static GType _signal_type;
Expand Down
5 changes: 5 additions & 0 deletions src/control/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ typedef enum dt_signal_t
/* \brief This signal is raised when the user choses a new location from map (module location)*/
DT_SIGNAL_LOCATION_CHANGED,

/** \brief This signal is raised when a storage module signalizes to enable/disable the export
no param, no returned value
*/
DT_SIGNAL_IMAGEIO_STORAGE_EXPORT_ENABLE,

/* do not touch !*/
DT_SIGNAL_COUNT
} dt_signal_t;
Expand Down
3 changes: 3 additions & 0 deletions src/imageio/storage/imageio_storage_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ OPTIONAL(void, export_dispatched, struct dt_imageio_module_storage_t *self);

OPTIONAL(char *, ask_user_confirmation, struct dt_imageio_module_storage_t *self);

/* ask the storage if export is currently possible */
OPTIONAL(gboolean, export_enabled, struct dt_imageio_module_storage_t *self);

#ifdef FULL_API_H

#pragma GCC visibility pop
Expand Down
30 changes: 28 additions & 2 deletions src/imageio/storage/piwigo.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ static void _piwigo_authenticate(dt_storage_piwigo_gui_data_t *ui)
_piwigo_set_status(ui, _("not authenticated, cannot reach server"), "#e07f7f");
_piwigo_ctx_destroy(&ui->api);
}

DT_DEBUG_CONTROL_SIGNAL_RAISE(darktable.signals, DT_SIGNAL_IMAGEIO_STORAGE_EXPORT_ENABLE);
}

static void _piwigo_entry_changed(GtkEntry *entry,
Expand All @@ -608,9 +610,11 @@ static void _piwigo_entry_changed(GtkEntry *entry,
dt_storage_piwigo_gui_data_t *ui = (dt_storage_piwigo_gui_data_t *)data;

_piwigo_set_status(ui, _("not authenticated"), "#e07f7f");
gtk_widget_set_sensitive(GTK_WIDGET(ui->album_list), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(ui->album_list), FALSE);

if(ui->api) _piwigo_ctx_destroy(&ui->api);

DT_DEBUG_CONTROL_SIGNAL_RAISE(darktable.signals, DT_SIGNAL_IMAGEIO_STORAGE_EXPORT_ENABLE);
}

static void _piwigo_server_entry_changed(GtkEntry *entry,
Expand All @@ -624,6 +628,8 @@ static void _piwigo_server_entry_changed(GtkEntry *entry,
_piwigo_ctx_destroy(&ui->api);
gtk_widget_set_sensitive(GTK_WIDGET(ui->album_list), FALSE);
}

DT_DEBUG_CONTROL_SIGNAL_RAISE(darktable.signals, DT_SIGNAL_IMAGEIO_STORAGE_EXPORT_ENABLE);
}

static void _piwigo_account_changed(GtkComboBox *cb,
Expand Down Expand Up @@ -1214,8 +1220,13 @@ static gboolean _finalize_store(gpointer user_data)
{
dt_storage_piwigo_gui_data_t *g = (dt_storage_piwigo_gui_data_t *)user_data;

// notify that uploads are completed to empty the lounge
if(g->api == NULL)
{
// not logged in, nothing to cleanup
return FALSE;
}

// notify that uploads are completed to empty the lounge
if(!g->api->error_occured)
{
GList *args = NULL;
Expand Down Expand Up @@ -1265,6 +1276,14 @@ int store(dt_imageio_module_storage_t *self,
dt_storage_piwigo_gui_data_t *ui = self->gui_data;
dt_storage_piwigo_params_t *p = (dt_storage_piwigo_params_t *)sdata;

if(p->api == NULL)
{
dt_print(DT_DEBUG_ALWAYS,
"[imageio_storage_piwigo] not logged in to Piwigo server!\n");
dt_control_log(_("not logged in to Piwigo server!"));
return 1;
}

gint result = 0;
gint skipped = 0;

Expand Down Expand Up @@ -1585,6 +1604,13 @@ gboolean supported(dt_imageio_module_storage_t *storage,
return FALSE;
}

gboolean export_enabled(dt_imageio_module_storage_t *self)
{
dt_storage_piwigo_gui_data_t *ui = self->gui_data;

return ui->api != NULL && ui->api->authenticated;
}

void free_params(dt_imageio_module_storage_t *self,
dt_imageio_module_data_t *params)
{
Expand Down
30 changes: 25 additions & 5 deletions src/libs/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,17 @@ void gui_update(dt_lib_module_t *self)
const int storage_index =
dt_imageio_get_index_of_storage(dt_imageio_get_storage_by_name(storage_name));

dt_imageio_module_storage_t *storage = dt_imageio_get_storage();

gboolean export_enabled = TRUE;
if(storage->export_enabled)
export_enabled = storage->export_enabled(storage);

gtk_widget_set_sensitive(GTK_WIDGET(d->export_button),
has_act_on && format_index != -1 && storage_index != -1);
has_act_on
&& format_index != -1
&& storage_index != -1
&& export_enabled);
}

static void _image_selection_changed_callback(gpointer instance,
Expand All @@ -221,6 +230,12 @@ static void _mouse_over_image_callback(gpointer instance, dt_lib_module_t *self)
dt_lib_gui_queue_update(self);
}

static void _export_enable_callback(gpointer instance,
dt_lib_module_t *self)
{
dt_lib_gui_queue_update(self);
}

gboolean _is_int(double value)
{
return (value == (int)value);
Expand Down Expand Up @@ -844,12 +859,15 @@ static void set_storage_by_name(dt_lib_export_t *d,
dt_bauhaus_combobox_set(d->format, 0);
}

static void _storage_changed(GtkWidget *widget, dt_lib_export_t *d)
static void _storage_changed(GtkWidget *widget, dt_lib_module_t *self)
{
dt_lib_export_t *d = self->data;

const gchar *name = dt_bauhaus_combobox_get_text(d->storage);
g_signal_handlers_block_by_func(widget, _storage_changed, d);
g_signal_handlers_block_by_func(widget, _storage_changed, self);
if(name) set_storage_by_name(d, name);
g_signal_handlers_unblock_by_func(widget, _storage_changed, d);
g_signal_handlers_unblock_by_func(widget, _storage_changed, self);
dt_lib_gui_queue_update(self);
}

static void _profile_changed(GtkWidget *widget, dt_lib_export_t *d)
Expand Down Expand Up @@ -1173,7 +1191,7 @@ void gui_init(dt_lib_module_t *self)
DT_DEBUG_CONTROL_SIGNAL_CONNECT(darktable.signals, DT_SIGNAL_IMAGEIO_STORAGE_CHANGE,
G_CALLBACK(_on_storage_list_changed), self);
g_signal_connect(G_OBJECT(d->storage), "value-changed",
G_CALLBACK(_storage_changed), (gpointer)d);
G_CALLBACK(_storage_changed), self);

label = dt_ui_section_label_new(C_("section", "format options"));
gtk_box_pack_start(GTK_BOX(self->widget), label, FALSE, TRUE, 0);
Expand Down Expand Up @@ -1494,6 +1512,8 @@ void gui_init(dt_lib_module_t *self)
G_CALLBACK(_mouse_over_image_callback), self);
DT_DEBUG_CONTROL_SIGNAL_CONNECT(darktable.signals, DT_SIGNAL_COLLECTION_CHANGED,
G_CALLBACK(_collection_updated_callback), self);
DT_DEBUG_CONTROL_SIGNAL_CONNECT(darktable.signals, DT_SIGNAL_IMAGEIO_STORAGE_EXPORT_ENABLE,
G_CALLBACK(_export_enable_callback), self);
}

void gui_cleanup(dt_lib_module_t *self)
Expand Down

0 comments on commit 31b04e6

Please sign in to comment.