From: Alberto Ruiz Date: Wed, 20 Jul 2011 11:16:12 +0000 (+0100) Subject: Implement full service matching algorithm X-Git-Tag: 0.7.1~177^2~7 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=moonshot-ui.git;a=commitdiff_plain;h=53bef1ed8950525f8117220eb2ef90b593fffbab Implement full service matching algorithm --- diff --git a/Makefile.am b/Makefile.am index 33bebef..9fe8cc3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,11 +48,11 @@ src_moonshot_webp_SOURCES = \ src/moonshot-webp-parser.vala \ src/moonshot-id.vala -src_moonshot_VALAFLAGS = --pkg gtk+-2.0 $(AM_VALAFLAGS) +src_moonshot_VALAFLAGS = --pkg gdk-2.0 gtk+-2.0 $(AM_VALAFLAGS) src_moonshot_CPPFLAGS = $(moonshot_CFLAGS) $(AM_CPPFLAGS) src_moonshot_LDADD = $(moonshot_LIBS) -src_moonshot_webp_VALAFLAGS = --vapidir=$(top_srcdir)/libmoonshot --pkg libmoonshot $(AM_VALAFLAGS) +src_moonshot_webp_VALAFLAGS = --vapidir=$(top_srcdir)/libmoonshot --pkg gdk-2.0 --pkg libmoonshot $(AM_VALAFLAGS) src_moonshot_webp_CPPFLAGS = $(moonshot_CFLAGS) $(AM_CPPFLAGS) src_moonshot_webp_LDADD = $(moonshot_LIBS) ${top_builddir}/libmoonshot/libmoonshot.la diff --git a/src/moonshot-window.vala b/src/moonshot-window.vala index bbd3b87..5522953 100644 --- a/src/moonshot-window.vala +++ b/src/moonshot-window.vala @@ -73,11 +73,6 @@ class MainWindow : Window { candidates.append (idcard); } - - public void clear_candidates () - { - candidates = new SList(); - } private bool visible_func (TreeModel model, TreeIter iter) { @@ -455,23 +450,27 @@ class MainWindow : Window { bool has_nai = request.nai != null && request.nai != ""; bool has_srv = request.service != null && request.service != ""; - foreach (IdCard tmp in identities_manager.id_card_list) + bool confirm = false; + IdCard nai_provided = null; + + foreach (IdCard id in identities_manager.id_card_list) { /* If NAI matches we add id card to the candidate list */ - if (has_nai && request.nai == tmp.nai) + if (has_nai && request.nai == id.nai) { - add_candidate (tmp); + nai_provided = id; + add_candidate (id); continue; } /* If any service matches we add id card to the candidate list */ if (has_srv) { - foreach (string srv in tmp.services) + foreach (string srv in id.services) { if (request.service == srv) { - add_candidate (tmp); + add_candidate (id); continue; } } @@ -509,21 +508,48 @@ class MainWindow : Window } } + /* If there are no candidates we use the service matching rules */ if (candidates.length () == 0) { - /*TODO: Check regex rules against service */ - } + foreach (IdCard id in identities_manager.id_card_list) + { + foreach (Rule rule in id.rules) + { + if (!match_service_pattern (request.service, rule.pattern)) + continue; + + candidates.append (id); - filter.refilter(); - show (); - } - else - { - // Send back the identity (we can't directly run the - // callback because we may be being called from a 'yield') - Idle.add (() => { send_identity_cb (identity); return false; }); - return; + if (rule.always_confirm == "true") + confirm = true; + } + } + } + + if (candidates.length () > 1) + confirm = true; + else + identity = candidates.nth_data (0); + + + if (confirm) + { + filter.refilter(); + redraw_id_card_widgets (); + show (); + return; + } } + // Send back the identity (we can't directly run the + // callback because we may be being called from a 'yield') + Idle.add (() => { send_identity_cb (identity); return false; }); + return; + } + + private bool match_service_pattern (string service, string pattern) + { + var pspec = new PatternSpec (pattern); + return pspec.match_string (service); } public void send_identity_cb (IdCard identity) @@ -562,7 +588,7 @@ class MainWindow : Window if (reset_password) identity.password = null; - candidates = null; + candidates = new SList(); } private void label_make_bold (Label label) @@ -622,24 +648,24 @@ class MainWindow : Window SList services = new SList(); - foreach (string srv in id_card.services) + foreach (string srv in idcard.services) { if (srv == candidate) continue; services.append (srv); } - id_card.services = new string[services.length()]; - for (int j=0; j