1/* 2 * This file is part of gitg 3 * 4 * Copyright (C) 2014 - Jesse van den Kieboom 5 * 6 * gitg is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * gitg is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with gitg. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20namespace Gitg 21{ 22 23public enum AuthenticationLifeTime 24{ 25 FORGET, 26 SESSION, 27 FOREVER 28} 29 30[GtkTemplate ( ui = "/org/gnome/gitg/ui/gitg-authentication-dialog.ui" )] 31public class AuthenticationDialog : Gtk.Dialog 32{ 33 [GtkChild ( name = "label_title" )] 34 private Gtk.Label d_label_title; 35 36 [GtkChild ( name = "label_failed" )] 37 private Gtk.Label d_label_failed; 38 39 [GtkChild ( name = "entry_username" )] 40 private Gtk.Entry d_entry_username; 41 42 [GtkChild ( name = "entry_password" )] 43 private Gtk.Entry d_entry_password; 44 45 [GtkChild ( name = "radio_button_forget" )] 46 private Gtk.RadioButton d_radio_button_forget; 47 48 [GtkChild ( name = "radio_button_session" )] 49 private Gtk.RadioButton d_radio_button_session; 50 51 [GtkChild ( name = "radio_button_forever" )] 52 private Gtk.RadioButton d_radio_button_forever; 53 54 private static AuthenticationLifeTime s_last_lifetime; 55 56 static construct 57 { 58 s_last_lifetime = AuthenticationLifeTime.SESSION; 59 } 60 61 public AuthenticationDialog(string url, string? username, bool failed) 62 { 63 Object(use_header_bar: 1); 64 65 set_default_response(Gtk.ResponseType.OK); 66 67 /* Translators: %s will be replaced with a URL indicating the resource 68 for which the authentication is required. */ 69 d_label_title.label = _("Password required for %s").printf(url); 70 d_label_failed.visible = failed; 71 72 if (username != null) 73 { 74 d_entry_username.text = username; 75 d_entry_password.grab_focus(); 76 } 77 78 switch (s_last_lifetime) 79 { 80 case AuthenticationLifeTime.FORGET: 81 d_radio_button_forget.active = true; 82 break; 83 case AuthenticationLifeTime.SESSION: 84 d_radio_button_session.active = true; 85 break; 86 case AuthenticationLifeTime.FOREVER: 87 d_radio_button_forever.active = true; 88 break; 89 } 90 } 91 92 public string username 93 { 94 get { return d_entry_username.text; } 95 } 96 97 public string password 98 { 99 get { return d_entry_password.text; } 100 } 101 102 public AuthenticationLifeTime life_time 103 { 104 get 105 { 106 if (d_radio_button_forget.active) 107 { 108 return AuthenticationLifeTime.FORGET; 109 } 110 else if (d_radio_button_session.active) 111 { 112 return AuthenticationLifeTime.SESSION; 113 } 114 else 115 { 116 return AuthenticationLifeTime.FOREVER; 117 } 118 } 119 } 120} 121 122} 123