Skip to content

Commit 463a3db

Browse files
authored
Merge pull request #18744 from zisoft/piwigo-auto-login
Piwigo auto login
2 parents 0da0b42 + 1d0cf12 commit 463a3db

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

data/darktableconfig.xml.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,13 @@
28552855
<shortdescription>password storage backend to use</shortdescription>
28562856
<longdescription>the storage backend for password storage: auto, none, libsecret, kwallet, apple_keychain, windows_credentials</longdescription>
28572857
</dtconfig>
2858+
<dtconfig prefs="security" section="other">
2859+
<name>plugins/imageio/storage/export/auto_login</name>
2860+
<type>bool</type>
2861+
<default>false</default>
2862+
<shortdescription>auto login to storage server</shortdescription>
2863+
<longdescription>automatically login to last used storage server. this requires that a password storage backend is set.</longdescription>
2864+
</dtconfig>
28582865
<dtconfig>
28592866
<name>plugins/lighttable/export/icctype</name>
28602867
<type>int</type>

src/imageio/storage/piwigo.c

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@
4242
#include <unistd.h>
4343
#include <inttypes.h>
4444

45-
DT_MODULE(2)
45+
DT_MODULE(3)
4646

4747
#define piwigo_EXTRA_VERBOSE FALSE
4848

4949
#define MAX_ALBUM_NAME_SIZE 100
50+
#define MAX_SERVER_NAME_SIZE 2048
5051

5152
typedef struct _piwigo_api_context_t
5253
{
@@ -128,6 +129,7 @@ typedef struct dt_storage_piwigo_preset_data_t
128129
char filename_pattern[DT_MAX_PATH_FOR_PARAMS];
129130
dt_storage_piwigo_permissions_t privacy;
130131
dt_storage_piwigo_conflict_actions_t conflict_action;
132+
char server[MAX_SERVER_NAME_SIZE];
131133
} dt_storage_piwigo_preset_data_t;
132134

133135
typedef struct dt_storage_piwigo_params_t
@@ -149,17 +151,17 @@ void *legacy_params(dt_imageio_module_storage_t *self,
149151
int *new_version,
150152
size_t *new_size)
151153
{
152-
typedef struct dt_storage_piwigo_preset_data_v2_t
153-
{
154-
char filename_pattern[DT_MAX_PATH_FOR_PARAMS];
155-
dt_storage_piwigo_permissions_t privacy;
156-
dt_storage_piwigo_conflict_actions_t conflict_action;
157-
} dt_storage_piwigo_preset_data_v2_t;
158-
159154
if(old_version == 1)
160155
{
161156
// version 1 did not save any piwigo settings in the preset,
162157
// so we only need to initialize the data struct here
158+
typedef struct dt_storage_piwigo_preset_data_v2_t
159+
{
160+
char filename_pattern[DT_MAX_PATH_FOR_PARAMS];
161+
dt_storage_piwigo_permissions_t privacy;
162+
dt_storage_piwigo_conflict_actions_t conflict_action;
163+
} dt_storage_piwigo_preset_data_v2_t;
164+
163165
dt_storage_piwigo_preset_data_v2_t *n =
164166
(dt_storage_piwigo_preset_data_v2_t *)g_malloc0(sizeof(dt_storage_piwigo_preset_data_v2_t));
165167

@@ -172,6 +174,28 @@ void *legacy_params(dt_imageio_module_storage_t *self,
172174

173175
return n;
174176
}
177+
else if(old_version == 2)
178+
{
179+
// add server name to params
180+
typedef struct dt_storage_piwigo_preset_data_v3_t
181+
{
182+
char filename_pattern[DT_MAX_PATH_FOR_PARAMS];
183+
dt_storage_piwigo_permissions_t privacy;
184+
dt_storage_piwigo_conflict_actions_t conflict_action;
185+
char server[MAX_SERVER_NAME_SIZE];
186+
} dt_storage_piwigo_preset_data_v3_t;
187+
188+
dt_storage_piwigo_preset_data_v3_t *n =
189+
(dt_storage_piwigo_preset_data_v3_t *)g_malloc0(sizeof(dt_storage_piwigo_preset_data_v3_t));
190+
191+
memcpy(n, old_params, old_params_size);
192+
n->server[0] = '\0';
193+
194+
*new_size = sizeof(dt_storage_piwigo_preset_data_v3_t);
195+
*new_version = 3;
196+
197+
return n;
198+
}
175199

176200
return NULL;
177201
}
@@ -691,7 +715,7 @@ static void _piwigo_conflict_changed(GtkWidget *widget,
691715

692716
/** Refresh albums */
693717
static gboolean _piwigo_refresh_albums(dt_storage_piwigo_gui_data_t *ui,
694-
const gchar *select_album)
718+
const gchar *select_album)
695719
{
696720
gtk_widget_set_sensitive(GTK_WIDGET(ui->album_list), FALSE);
697721
gtk_widget_set_sensitive(GTK_WIDGET(ui->parent_album_list), FALSE);
@@ -1164,6 +1188,9 @@ void gui_init(dt_imageio_module_storage_t *self)
11641188
ui->create_box,
11651189
dt_gui_hbox(dt_ui_label_new(_("filename pattern")), ui->filename_pattern_entry),
11661190
ui->conflict_action);
1191+
1192+
if(dt_conf_get_bool("plugins/imageio/storage/export/auto_login"))
1193+
storage_login(self);
11671194
}
11681195

11691196
void gui_cleanup(dt_imageio_module_storage_t *self)
@@ -1454,6 +1481,8 @@ void *get_params(dt_imageio_module_storage_t *self)
14541481
// fill p from controls in ui
14551482
const char *text = dt_conf_get_string_const("plugins/imageio/storage/export/piwigo/filename_pattern");
14561483
g_strlcpy(p->preset_data.filename_pattern, text, sizeof(p->preset_data.filename_pattern));
1484+
text = dt_conf_get_string_const("plugins/imageio/storage/export/piwigo/server");
1485+
g_strlcpy(p->preset_data.server, text, sizeof(p->preset_data.server));
14571486

14581487
p->preset_data.conflict_action = dt_bauhaus_combobox_get(ui->conflict_action);
14591488

@@ -1549,6 +1578,21 @@ int set_params(dt_imageio_module_storage_t *self,
15491578
gtk_entry_set_text(GTK_ENTRY(g->filename_pattern_entry), d->preset_data.filename_pattern);
15501579
dt_bauhaus_combobox_set(g->conflict_action, d->preset_data.conflict_action);
15511580

1581+
if(dt_bauhaus_combobox_set_from_text(g->account_list, d->preset_data.server))
1582+
{
1583+
const _piwigo_account_t *account = _piwigo_get_account(g, d->preset_data.server);
1584+
if(account)
1585+
{
1586+
gtk_entry_set_text(g->server_entry, account->server);
1587+
gtk_entry_set_text(g->user_entry, account->username);
1588+
gtk_entry_set_text(g->pwd_entry, account->password);
1589+
1590+
// if we have a server name, do auto-login
1591+
if(dt_conf_get_bool("plugins/imageio/storage/export/auto_login"))
1592+
storage_login(self);
1593+
}
1594+
}
1595+
15521596
switch(d->preset_data.privacy)
15531597
{
15541598
case DT_PIWIGO_PERMISSION_EVERYONE: // everyone

0 commit comments

Comments
 (0)