Compute lucene-style scores for our hits.
[beagle.git] / Best / Best.cs
blob93df41616f4533f2015e9754dea6322d162fce39
1 //
2 // Best.cs
3 // Bleeding Edge Search Tool: Beagle search GUI
4 //
5 // Nat Friedman <nat@novell.com>
6 //
7 // Copyright (C) 2004 Novell, Inc.
8 //
10 using System;
12 using Gtk;
13 using GtkSharp;
14 using Gnome;
16 using Mono.Posix;
18 using Beagle;
19 using Beagle.Util;
21 namespace Best {
23 class Best {
25 static public string DefaultWindowTitle = "Beagle Search (beta)";
27 static void PrintUsageAndExit ()
29 string usage =
30 "best: GUI interface to the Beagle search system.\n" +
31 "Web page: http://www.gnome.org/projects/beagle\n" +
32 "Copyright (C) 2004-2005 Novell, Inc.\n\n";
34 usage +=
35 "Usage: best [OPTIONS] [<query string>]\n\n" +
36 "Options:\n" +
37 " --no-tray\t\t\tDo not create a notification area applet.\n" +
38 " --show-window\t\t\tDisplay a search window.\n" +
39 " --help\t\t\tPrint this usage message.\n";
41 Console.WriteLine (usage);
43 System.Environment.Exit (0);
46 static string query = "";
47 static bool doTray = true;
48 static bool showWindow = false;
49 static bool autostarted = false;
51 static void ParseArgs (String[] args)
53 int i = 0;
54 while (i < args.Length) {
55 switch (args [i]) {
56 case "--no-tray":
57 doTray = false;
58 break;
60 case "--show-window":
61 showWindow = true;
62 break;
64 case "--help":
65 case "--usage":
66 PrintUsageAndExit ();
67 return;
69 // Ignore session management
70 case "--sm-config-prefix":
71 case "--sm-client-id":
72 case "--screen":
73 // These all take an argument, so
74 // increment i
75 i++;
76 break;
78 case "--autostarted":
79 if (! Conf.Searching.Autostart){
80 Console.WriteLine ("Autostarting is disabled, not starting");
81 Environment.Exit (0);
83 autostarted = true;
84 break;
86 default:
87 if (query.Length != 0)
88 query += " ";
89 query += args [i];
90 break;
93 i ++;
97 static void NoTrayWindowDeleteEvent (object o, Gtk.DeleteEventArgs args)
99 Application.Quit ();
102 static void Main (String[] args)
104 ParseArgs (args);
106 Program best = new Program ("best", "0.0", Modules.UI, args);
108 GeckoUtils.Init ();
109 GeckoUtils.SetSystemFonts ();
111 // I18N
112 Catalog.Init ("beagle", ExternalStringsHack.LocaleDir);
114 // Create the window.
115 BestWindow win;
116 if (query != "") {
117 win = new BestWindow (query);
118 win.Show ();
119 } else {
120 win = new BestWindow ();
121 if (showWindow)
122 win.Show ();
125 // Create the tray icon.
126 BestTray icon;
127 if (doTray) {
128 icon = new BestTray (win, autostarted);
129 icon.Show ();
130 Console.WriteLine (Catalog.GetString ("If you're wondering whether Best is working check " +
131 "your notification area (system tray)"));
132 } else {
133 win.Show ();
134 win.Present ();
135 win.FocusEntry ();
136 win.DeleteEvent += new Gtk.DeleteEventHandler (NoTrayWindowDeleteEvent);
139 best.Run ();