Show total number of results for google driver too. Helps to know if my query resulte...
[beagle.git] / search / GroupView.cs
blobe1948ec0edfd07ed350048416f1e12b75a320a3d
1 using System;
2 using System.Collections;
4 using Mono.Posix;
5 using Gtk;
6 using Beagle;
7 using Search.Tiles;
9 namespace Search {
11 public delegate void TileHandler (Tiles.Tile tile);
13 public enum MatchType {
14 None,
15 NoneInScope,
16 Matched
19 public class GroupView : VBox {
21 public event TileHandler TileSelected;
22 private Gtk.SizeGroup tileSizeGroup;
23 private Hashtable categories;
24 private Gtk.Widget selection;
26 public GroupView () : base (false, 0)
28 categories = new Hashtable ();
29 tileSizeGroup = new Gtk.SizeGroup (Gtk.SizeGroupMode.Both);
30 Category box = null;
32 foreach (Tiles.TileGroupInfo info in Tiles.Utils.GroupInfo) {
34 if (info.Group == Tiles.TileGroup.Conversations)
35 box = new ConversationCategory (info);
36 else
37 box = new TileCategory (info, tileSizeGroup);
39 PackStart (box, false, false, 0);
40 box.NoShowAll = true;
41 box.CategoryToggle += OnCategoryToggle;
42 categories [info.Group] = box;
45 // FIXME: Add the Best match category
48 public void AddHit (Tiles.Tile tile)
50 tile.Show ();
51 tile.Selected += OnTileSelected;
53 Category box = (Category)categories [tile.Group];
54 box.Add (tile);
56 if (GroupInScope (tile.Group))
57 box.Show ();
60 public void SubtractHit (Uri uri)
62 foreach (Category box in categories.Values) {
63 foreach (Tile tile in box.AllTiles) {
64 if (tile.Hit.Uri.Equals (uri)) {
65 if (tile.State == StateType.Selected)
66 OnTileSelected (null, EventArgs.Empty);
67 box.Remove (tile);
68 return;
74 public void Finished (bool grabFocus)
76 Category first = null;
77 bool others = false;
79 foreach (Category category in categories.Values) {
80 if (category.Visible) {
81 if (first == null)
82 first = category;
83 else {
84 others = true;
85 break;
90 if (first != null)
91 first.Select (grabFocus, !others);
94 public MatchType MatchState {
95 get {
96 bool hiddenMatches = false;
97 foreach (Category category in categories.Values) {
98 if (category.Visible)
99 return MatchType.Matched;
100 else if (!category.Empty)
101 hiddenMatches = true;
104 return hiddenMatches ? MatchType.NoneInScope : MatchType.None;
108 private void OnTileSelected (object tile, EventArgs args)
110 if (tile == selection)
111 return;
113 if (TileSelected != null)
114 TileSelected ((Tiles.Tile)tile);
116 if (selection != null)
117 selection.State = StateType.Normal;
118 selection = (Gtk.Widget)tile;
119 if (selection != null)
120 selection.State = StateType.Selected;
123 private ScopeType scope;
124 public ScopeType Scope {
125 set {
126 scope = value;
127 foreach (TileGroup group in categories.Keys) {
128 Category category = (Category)categories[group];
129 if (!GroupInScope (group))
130 category.Expanded = false;
131 else if (!category.Empty)
132 category.Expanded = true;
137 private bool GroupInScope (TileGroup group)
139 ScopeType scopetype = Utils.TileGroupToScopeType (group);
141 return (scope & scopetype) == scopetype;
144 public SortType Sort {
145 set {
146 foreach (Category category in categories.Values)
147 category.Sort = value;
151 public void Clear ()
153 foreach (Category box in categories.Values) {
154 box.Clear ();
155 box.Hide ();
159 private void OnCategoryToggle (ScopeType catScope)
161 // we're not using the set function cause we directly
162 // close/open the expander in Category.cs
163 scope = scope ^ catScope;
164 CategoryToggled (catScope);
167 public delegate void CategoryToggledDelegate (ScopeType catScope);
168 public event CategoryToggledDelegate CategoryToggled;