Mercurial > hg > ltpda-connection-manager
diff LTPDAConnectionManager.m @ 5:35f1cfcaa5a9
Add crude Java GUI.
author | Daniele Nicolodi <daniele@science.unitn.it> |
---|---|
date | Wed, 02 Jun 2010 17:29:18 +0200 |
parents | c706c10a76bd |
children |
line wrap: on
line diff
--- a/LTPDAConnectionManager.m Mon May 24 00:14:37 2010 +0200 +++ b/LTPDAConnectionManager.m Wed Jun 02 17:29:18 2010 +0200 @@ -399,65 +399,40 @@ function [username, password, cache] = inputCredentials(cm, cred) % INPUTCREDENTIALS Queries the user for database username and password. - % this is a stubb that must be replaced by a graphical interface - % build a cell array of usernames and passwords users = { cred(:).username }; passw = { cred(:).password }; - % default to the latest used username + % sort on the expiry time [e, ids] = sort([ cred(:).expiry ]); - default = users{ids(1)}; - - username = choose('Username', users, default); + users = users{ids} + passw = passw{ids} - % pick the corresponding password - ids = find(strcmp(users, username)); - if ~isempty(ids) - default = passw{ids(1)}; - else - default = []; + dialog = connectionmanager.CredentialsDialog(users, passw); + dialog.show(); + if dialog.cancelled + throw(MException('utils:jmysql:connect:UserCancelled', '### user cancelled'); end - - password = ask('Password', ''); - - if cm.cachePassword == 2 - cache = ask('Store credentials', 'n'); - if ~isempty(cache) && cache(1) == 'y' - cache = true; - else - cache = false; - end - else - cache = logical(cm.cachePassword); - end + username = char(dialog.username); + password = char(dialog.password); + cache = logical(dialog.cache); end function [hostname, database, username] = selectDatabase(cm) % SELECTDATABASE Makes the user choose to which database connect to. - % this is a stubb that must be replaced by a graphical interface - - for kk = 1:numel(cm.credentials) - fprintf('% 2d. %s\n', char(cm.credentials{kk})); + dialog = connectionmanager.DatabaseSelectorDialog(); + for c = cm.credentials + dialog.add(c{1}.hostname, c{1}.database, c{1}.username); end - fprintf('%d. NEW (default)\n', numel(cm.credentials)+1); - str = input('Select connection: ', 's'); - if isempty(str) - id = numel(cm.credentials)+1; - else - id = eval(str); + dialog.show(); + if dialog.cancelled + throw(MException('utils:jmysql:connect:UserCancelled', '### user cancelled'); end - if id > numel(cm.credentials) - hostname = input('Hostname: ', 's'); - database = input('Database: ', 's'); - username = []; - else - hostname = cm.credentials{kk}.hostname; - database = cm.credentials{kk}.database; - username = cm.credentials{kk}.username; - end + hostname = char(dialog.hostname); + database = char(dialog.database); + username = char(dialog.username); end end % private methods @@ -500,26 +475,3 @@ rethrow(ex); end end - - -function str = ask(msg, default) - str = input(sprintf('%s (default: %s): ', msg, default), 's'); - if isempty(str) - str = default; - end - if ~ischar(str) - str = char(str); - end -end - -function str = choose(msg, choices, default) - options = sprintf('%s, ', choices{:}); - options = options(1:end-2); - str = input(sprintf('%s (options: %s, default: %s): ', msg, options, default), 's'); - if isempty(str) - str = default; - end - if ~ischar(str) - str = char(str); - end -end