~ubuntu-branches/ubuntu/jaunty/beagle/jaunty-security

« back to all changes in this revision

Viewing changes to search/Beagle.Search/Search.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-04 00:31:32 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20080504003132-2tkm5o8moo5952ri
Tags: 0.3.7-2ubuntu1
 * Merge from Debian unstable. (LP: #225746) Remaining Ubuntu changes:
  - debian/control:
    + Rename ice{weasel,dove}-beagle to {mozilla,thunderbird}-beagle and
      and update the dependencies accordingly.
    + Change Maintainer to Ubuntu Mono Team.
  - debian/rules:
    + Install the mozilla-beagle and thunderbird-beagle extensions.
  - ice{dove,weasel}.dirs:
    + Renamed to {mozilla,thunderbird}-beagle.dirs.
    + Fixed paths to point to usr/lib/{firefox,thunderbird}

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Search.cs
 
3
//
 
4
// Copyright (C) 2008 Lukas Lipka <lukaslipka@gmail.com>
 
5
//
 
6
 
 
7
using System;
 
8
using System.Collections;
 
9
using System.Diagnostics;
 
10
 
 
11
using NDesk.DBus;
 
12
using Mono.Unix;
 
13
 
 
14
using Beagle.Util;
 
15
using Beagle.Search.Tray;
 
16
 
 
17
namespace Beagle.Search {
 
18
 
 
19
        public class Search : ISearch {
 
20
 
 
21
                // The reference count is only valid when
 
22
                // we don't run in icon mode.
 
23
 
 
24
                private uint ref_count = 0;
 
25
 
 
26
                private bool icon_enabled = false;
 
27
                private bool docs_enabled = false;
 
28
 
 
29
                private SearchWindow icon_window = null;
 
30
                private TrayIcon tray = null;
 
31
                private XKeybinder keybinder = null;
 
32
 
 
33
                public Search (bool icon_enabled, bool docs_enabled)
 
34
                {
 
35
                        this.icon_enabled = icon_enabled;
 
36
                        this.docs_enabled = docs_enabled;
 
37
 
 
38
                        if (icon_enabled) {
 
39
                                icon_window = new SearchWindow (this);
 
40
                                icon_window.QueryEvent += OnQueryEvent;
 
41
 
 
42
                                tray = new TrayIcon ();
 
43
                                tray.Clicked += OnTrayActivated;
 
44
                                tray.Search += OnTraySearch;
 
45
 
 
46
                                Config config = Conf.Get (Conf.Names.BeagleSearchConfig);
 
47
 
 
48
                                bool binding_ctrl = config.GetOption (Conf.Names.KeyBinding_Ctrl, false);
 
49
                                bool binding_alt = config.GetOption (Conf.Names.KeyBinding_Alt, false);
 
50
                                string binding_key = config.GetOption (Conf.Names.KeyBinding_Key, "F12");
 
51
 
 
52
                                string tip_text = Catalog.GetString ("Desktop Search");
 
53
                                string binding = new KeyBinding (binding_key, binding_ctrl, binding_alt).ToString ();
 
54
 
 
55
                                if (!String.IsNullOrEmpty (binding)) {
 
56
                                        tip_text += String.Format (" ({0})", binding);
 
57
                                        keybinder = new XKeybinder ();
 
58
                                        keybinder.Bind (binding, OnTrayActivated);
 
59
                                }
 
60
 
 
61
                                tray.TooltipText = tip_text;
 
62
                        }
 
63
                }
 
64
 
 
65
                public void Query (string query_text)
 
66
                {
 
67
                        if (icon_enabled) {
 
68
                                if (!String.IsNullOrEmpty (query_text))
 
69
                                        icon_window.Search (query_text);
 
70
 
 
71
                                icon_window.ShowAll ();
 
72
                        } else {
 
73
                                SearchWindow window = new SearchWindow (this);
 
74
                                window.DeleteEvent += OnWindowDeleteEvent;
 
75
                                
 
76
                                if (!String.IsNullOrEmpty (query_text))
 
77
                                        window.Search (query_text);
 
78
 
 
79
                                window.ShowAll ();
 
80
                                ref_count++;
 
81
                        }
 
82
                }
 
83
 
 
84
                private void OnWindowDeleteEvent (object o, Gtk.DeleteEventArgs args)
 
85
                {
 
86
                        if (--ref_count < 1)
 
87
                                Gtk.Application.Quit ();
 
88
                }
 
89
 
 
90
                private void OnTrayActivated (object o, EventArgs args)
 
91
                {
 
92
                        if (! icon_window.Visible) {
 
93
                                icon_window.ShowAll ();
 
94
                                icon_window.Present ();
 
95
                                icon_window.GrabEntryFocus ();
 
96
                        } else {
 
97
                                icon_window.Hide ();
 
98
                        }
 
99
                }
 
100
 
 
101
                private void OnTraySearch (string query)
 
102
                {
 
103
                        if (!icon_window.Visible)
 
104
                                icon_window.ShowAll ();
 
105
 
 
106
                        icon_window.Search (query);
 
107
                }
 
108
 
 
109
                private void OnQueryEvent (string query)
 
110
                {
 
111
                        // Update the list of searches in the tray
 
112
                        // icon menu.
 
113
 
 
114
                        tray.AddSearch (query);
 
115
                }
 
116
 
 
117
                public bool IconEnabled {
 
118
                        get { return icon_enabled; }
 
119
                }
 
120
 
 
121
                public bool DocsEnabled {
 
122
                        get { return docs_enabled; }
 
123
                }
 
124
        }
 
125
}