summaryrefslogtreecommitdiff
path: root/client/gtk.c
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@kodafritt.se>2014-02-01 19:28:50 +0100
committerSamuel Lidén Borell <samuel@kodafritt.se>2014-02-01 19:28:50 +0100
commit78905cdd9947e5fae1cc9745032a26e6b714b1f9 (patch)
tree6db799bbc4fc57c62bd0ee7831a6ed2e54e94101 /client/gtk.c
parentc3fff1478ea3898ce4921fe937aaf99a4bbfe646 (diff)
downloadfribid-78905cdd9947e5fae1cc9745032a26e6b714b1f9.tar.gz
fribid-78905cdd9947e5fae1cc9745032a26e6b714b1f9.tar.bz2
fribid-78905cdd9947e5fae1cc9745032a26e6b714b1f9.zip
Select the last sorted (usaully the newest) token at start up
Diffstat (limited to 'client/gtk.c')
-rw-r--r--client/gtk.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/client/gtk.c b/client/gtk.c
index 2156b6e..e7a4382 100644
--- a/client/gtk.c
+++ b/client/gtk.c
@@ -132,7 +132,7 @@ static GtkLabel *info_label;
static GtkListStore *tokens;
static BackendNotifier *notifier;
-static bool signDialogShown;
+static bool signDialogShown, signDialogMapped;
/* Password choice and key generation dialog */
static GtkDialog *keygenDialog;
@@ -261,15 +261,37 @@ static void removeTokenFile(const char *filename) {
}
}
-static void selectDefaultToken() {
+/**
+ * Selects the newest token. Since the token names usually start with
+ * a date (at least file-based tokens from Swedbank) this function
+ * simply uses strcmp().
+ */
+static void selectDefaultToken(GtkWidget *ignored1, gpointer *ignored2) {
GtkTreeModel *model = GTK_TREE_MODEL(tokens);
GtkTreeIter iter = { .stamp = 0 };
- if (gtk_tree_model_get_iter_first(model, &iter) &&
- !gtk_tree_model_iter_next(model, &iter)) {
- // There's only one item, select it
- gtk_tree_model_get_iter_first(model, &iter);
- gtk_combo_box_set_active_iter(tokenCombo, &iter);
+ if (signDialogMapped) return;
+ signDialogMapped = true;
+
+ if (gtk_tree_model_get_iter_first(model, &iter)) {
+ char *newest = NULL;
+ gint newest_index = -1;
+ gint current_index = 0;
+ do {
+ char *current;
+ gtk_tree_model_get(model, &iter, 0, &current, -1);
+
+ if (!newest || strcmp(current, newest) > 0) {
+ newest = current;
+ newest_index = current_index;
+ }
+ current_index++;
+ } while (gtk_tree_model_iter_next(model, &iter));
+
+ if (newest) {
+ gtk_tree_model_iter_nth_child(model, &iter, NULL, newest_index);
+ gtk_combo_box_set_active_iter(tokenCombo, &iter);
+ }
}
}
@@ -334,8 +356,12 @@ void platform_startSign(const char *url, const char *hostname, const char *ip,
platform_setMessage(NULL);
validateDialog(NULL, NULL);
+ g_signal_connect(G_OBJECT(signDialog), "map-event",
+ G_CALLBACK(selectDefaultToken), NULL);
+
gtk_window_set_modal(GTK_WINDOW(signDialog), TRUE);
signDialogShown = false;
+ signDialogMapped = false;
}
void platform_endSign() {
@@ -524,7 +550,6 @@ bool platform_sign(Token **token, char *password, int password_maxlen) {
gtk_entry_set_max_length(passwordEntry, password_maxlen-1);
if (!signDialogShown) {
- selectDefaultToken();
gtk_widget_show(GTK_WIDGET(signDialog));
signDialogShown = true;
}