summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Bouchaud <michael.bouchaud@ext.actia.fr>2017-02-22 21:04:34 +0100
committerMichael Bouchaud <michael.bouchaud@ext.actia.fr>2017-02-22 21:08:52 +0100
commit31d3b5914f8923a449fe6ef71572e2b96663950e (patch)
tree3b043b134b5a6ca8f23ff8798a7129ff2d0bebad
parent3ce76c66d22be70c9d009b3cb5ec4c783d403e2c (diff)
e_askpass: compliant with GIT_ASKPASS for querying username
It isn't well documented but git could use SSH_ASKPASS env var for querying username. So we use the argument passed to the command to know what to do.
-rw-r--r--src/bin/e_askpass_main.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/bin/e_askpass_main.c b/src/bin/e_askpass_main.c
index 67b785667..a5d6095db 100644
--- a/src/bin/e_askpass_main.c
+++ b/src/bin/e_askpass_main.c
@@ -1,8 +1,11 @@
1#include <Elementary.h> 1#include <Elementary.h>
2 2
3#define TITLE "Enter Your Password" 3#define TITLE_USER "Enter Your Username"
4#define TITLE_PWD "Enter Your Password"
5#define SUDO_LBL "[sudo]"
4#define TEXT "Please enter your user password" 6#define TEXT "Please enter your user password"
5#define GUIDE "Password" 7#define GUIDE_USER "Username"
8#define GUIDE_PWD "Password"
6#define OK "OK" 9#define OK "OK"
7#define CANCEL "Cancel" 10#define CANCEL "Cancel"
8#define PAD "pad_medium" 11#define PAD "pad_medium"
@@ -33,9 +36,25 @@ cb_cancel(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info
33} 36}
34 37
35EAPI int 38EAPI int
36elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) 39elm_main(int argc, char **argv)
37{ 40{
38 Evas_Object *win, *bx, *fr, *lab, *en, *sep, *bx2, *bt; 41 Evas_Object *win, *bx, *fr, *lab, *en, *sep, *bx2, *bt;
42 const char *txt = NULL;
43 Eina_Bool askpass = EINA_TRUE;
44
45 if (argc > 1)
46 {
47 /* Git could use SSH_ASKPASS env to query user and password. */
48 /* At least git has no i18n, so this should work for all languages */
49 /* as long as the string is unchanged. */
50 if (!strncmp(argv[1], "Username", sizeof("Username") - 1))
51 askpass = EINA_FALSE;
52 /* Sudo prompt [sudo] at the begining of line */
53 if (!strncmp(argv[1], SUDO_LBL, sizeof(SUDO_LBL) - 1))
54 txt = &argv[1][sizeof(SUDO_LBL)];
55 else
56 txt = argv[1];
57 }
39 58
40 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); 59 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
41 60
@@ -45,7 +64,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
45 elm_app_info_set(elm_main, "enlightenment", "AUTHORS"); 64 elm_app_info_set(elm_main, "enlightenment", "AUTHORS");
46 65
47 { 66 {
48 win = elm_win_util_standard_add("main", TITLE); 67 win = elm_win_util_standard_add("main", askpass ? TITLE_PWD : TITLE_PWD);
49 elm_win_autodel_set(win, EINA_TRUE); 68 elm_win_autodel_set(win, EINA_TRUE);
50 { 69 {
51 bx = elm_box_add(win); 70 bx = elm_box_add(win);
@@ -60,7 +79,10 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
60 { 79 {
61 lab = elm_label_add(win); 80 lab = elm_label_add(win);
62 evas_object_size_hint_align_set(lab, EVAS_HINT_FILL, 0.5); 81 evas_object_size_hint_align_set(lab, EVAS_HINT_FILL, 0.5);
63 elm_object_text_set(lab, TEXT); 82 if (txt)
83 elm_object_text_set(lab, txt);
84 else
85 elm_object_text_set(lab, TEXT);
64 elm_object_content_set(fr, lab); 86 elm_object_content_set(fr, lab);
65 evas_object_show(lab); 87 evas_object_show(lab);
66 } 88 }
@@ -78,9 +100,9 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
78 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0); 100 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
79 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5); 101 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
80 elm_scroller_policy_set(en, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); 102 elm_scroller_policy_set(en, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
81 elm_object_part_text_set(en, "guide", GUIDE); 103 elm_object_part_text_set(en, "guide", askpass ? GUIDE_PWD : GUIDE_USER);
82 elm_entry_single_line_set(en, EINA_TRUE); 104 elm_entry_single_line_set(en, EINA_TRUE);
83 elm_entry_password_set(en, EINA_TRUE); 105 elm_entry_password_set(en, askpass);
84 evas_object_smart_callback_add(en, "activated", cb_ok, NULL); 106 evas_object_smart_callback_add(en, "activated", cb_ok, NULL);
85 evas_object_smart_callback_add(en, "aborted", cb_cancel, NULL); 107 evas_object_smart_callback_add(en, "aborted", cb_cancel, NULL);
86 elm_object_content_set(fr, en); 108 elm_object_content_set(fr, en);