1 module webkit2.Credential; 2 3 private import glib.ConstructionException; 4 private import glib.Str; 5 private import gobject.ObjectG; 6 private import webkit2.c.functions; 7 public import webkit2.c.types; 8 9 10 /** */ 11 public class Credential 12 { 13 /** the main Gtk struct */ 14 protected WebKitCredential* webKitCredential; 15 protected bool ownedRef; 16 17 /** Get the main Gtk struct */ 18 public WebKitCredential* getCredentialStruct(bool transferOwnership = false) 19 { 20 if (transferOwnership) 21 ownedRef = false; 22 return webKitCredential; 23 } 24 25 /** the main Gtk struct as a void* */ 26 protected void* getStruct() 27 { 28 return cast(void*)webKitCredential; 29 } 30 31 /** 32 * Sets our main struct and passes it to the parent class. 33 */ 34 public this (WebKitCredential* webKitCredential, bool ownedRef = false) 35 { 36 this.webKitCredential = webKitCredential; 37 this.ownedRef = ownedRef; 38 } 39 40 ~this () 41 { 42 if ( ownedRef ) 43 webkit_credential_free(webKitCredential); 44 } 45 46 47 /** */ 48 public static GType getType() 49 { 50 return webkit_credential_get_type(); 51 } 52 53 /** 54 * Create a new credential from the provided username, password and persistence mode. 55 * 56 * Params: 57 * username = The username for the new credential 58 * password = The password for the new credential 59 * persistence = The #WebKitCredentialPersistence of the new credential 60 * 61 * Returns: A #WebKitCredential. 62 * 63 * Since: 2.2 64 * 65 * Throws: ConstructionException GTK+ fails to create the object. 66 */ 67 public this(string username, string password, WebKitCredentialPersistence persistence) 68 { 69 auto __p = webkit_credential_new(Str.toStringz(username), Str.toStringz(password), persistence); 70 71 if(__p is null) 72 { 73 throw new ConstructionException("null returned by new"); 74 } 75 76 this(cast(WebKitCredential*) __p); 77 } 78 79 /** 80 * Make a copy of the #WebKitCredential. 81 * 82 * Returns: A copy of passed in #WebKitCredential 83 * 84 * Since: 2.2 85 */ 86 public Credential copy() 87 { 88 auto __p = webkit_credential_copy(webKitCredential); 89 90 if(__p is null) 91 { 92 return null; 93 } 94 95 return ObjectG.getDObject!(Credential)(cast(WebKitCredential*) __p, true); 96 } 97 98 /** 99 * Free the #WebKitCredential. 100 * 101 * Since: 2.2 102 */ 103 public void free() 104 { 105 webkit_credential_free(webKitCredential); 106 ownedRef = false; 107 } 108 109 /** 110 * Get the password currently held by this #WebKitCredential. 111 * 112 * Returns: The password stored in the #WebKitCredential. 113 * 114 * Since: 2.2 115 */ 116 public string getPassword() 117 { 118 return Str.toString(webkit_credential_get_password(webKitCredential)); 119 } 120 121 /** 122 * Get the persistence mode currently held by this #WebKitCredential. 123 * 124 * Returns: The #WebKitCredentialPersistence stored in the #WebKitCredential. 125 * 126 * Since: 2.2 127 */ 128 public WebKitCredentialPersistence getPersistence() 129 { 130 return webkit_credential_get_persistence(webKitCredential); 131 } 132 133 /** 134 * Get the username currently held by this #WebKitCredential. 135 * 136 * Returns: The username stored in the #WebKitCredential. 137 * 138 * Since: 2.2 139 */ 140 public string getUsername() 141 { 142 return Str.toString(webkit_credential_get_username(webKitCredential)); 143 } 144 145 /** 146 * Determine whether this credential has a password stored. 147 * 148 * Returns: %TRUE if the credential has a password or %FALSE otherwise. 149 * 150 * Since: 2.2 151 */ 152 public bool hasPassword() 153 { 154 return webkit_credential_has_password(webKitCredential) != 0; 155 } 156 }