diff --git a/src/control/signal.c b/src/control/signal.c index 646c3b8bc044..47c9c3feb9ad 100644 --- a/src/control/signal.c +++ b/src/control/signal.c @@ -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; diff --git a/src/control/signal.h b/src/control/signal.h index 24a7d443e882..225c1cc65d1f 100644 --- a/src/control/signal.h +++ b/src/control/signal.h @@ -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; diff --git a/src/imageio/storage/imageio_storage_api.h b/src/imageio/storage/imageio_storage_api.h index f1a56974c5a8..384a2423b3bc 100644 --- a/src/imageio/storage/imageio_storage_api.h +++ b/src/imageio/storage/imageio_storage_api.h @@ -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 diff --git a/src/imageio/storage/piwigo.c b/src/imageio/storage/piwigo.c index 7488bfdc664b..b7d983eafbce 100644 --- a/src/imageio/storage/piwigo.c +++ b/src/imageio/storage/piwigo.c @@ -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, @@ -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, @@ -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, @@ -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; @@ -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; @@ -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) { diff --git a/src/libs/export.c b/src/libs/export.c index a505941ec0f5..35ca22716807 100644 --- a/src/libs/export.c +++ b/src/libs/export.c @@ -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, @@ -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); @@ -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) @@ -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); @@ -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)