~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Do/src/Do.cs

  • Committer: Hardeep S
  • Date: 2009-06-23 05:57:47 UTC
  • Revision ID: ootz0rz@gmail.com-20090623055747-3srobsuq3q8wbn81
initial adding of Do core stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Do.cs
 
2
//
 
3
// GNOME Do is the legal property of its developers. Please refer to the
 
4
// COPYRIGHT file distributed with this source distribution.
 
5
//
 
6
// This program is free software: you can redistribute it and/or modify
 
7
// it under the terms of the GNU General Public License as published by
 
8
// the Free Software Foundation, either version 3 of the License, or
 
9
// (at your option) any later version.
 
10
//
 
11
// This program is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
// GNU General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public License
 
17
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
//
 
19
 
 
20
using System;
 
21
using System.Threading;
 
22
using System.Diagnostics;
 
23
using System.Collections.Generic;
 
24
 
 
25
using Mono.Unix;
 
26
 
 
27
using Do.UI;
 
28
using Do.Core;
 
29
using Do.Platform;
 
30
 
 
31
namespace Do {
 
32
 
 
33
        static class Do {
 
34
                
 
35
                static XKeybinder keybinder;
 
36
                static Controller controller;
 
37
                static UniverseManager universe_manager;
 
38
 
 
39
                public static CorePreferences Preferences { get; private set; } 
 
40
                public static CoreKeybindings Keybindings { get; private set; } 
 
41
 
 
42
                internal static void Main (string [] args)
 
43
                {
 
44
                        Catalog.Init ("gnome-do", AssemblyInfo.LocaleDirectory);
 
45
                        Gtk.Application.Init ();
 
46
                        Gdk.Threads.Init ();
 
47
 
 
48
                        // We are conservative with the log at first.
 
49
                        Log.DisplayLevel = LogLevel.Error;
 
50
                        if (CorePreferences.PeekDebug)
 
51
                                Log.DisplayLevel = LogLevel.Debug;
 
52
 
 
53
                        PluginManager.Initialize ();
 
54
                        Services.System.EnsureSingleApplicationInstance ();
 
55
 
 
56
                        Preferences = new CorePreferences ();
 
57
 
 
58
                        Keybindings = new CoreKeybindings ();
 
59
 
 
60
                        // Now we can set the preferred log level.
 
61
                        if (Preferences.QuietStart)
 
62
                                Log.DisplayLevel = LogLevel.Error;
 
63
                        // Check for debug again in case QuietStart is also set.
 
64
                        if (Preferences.Debug)
 
65
                                Log.DisplayLevel = LogLevel.Debug;
 
66
 
 
67
                        try {
 
68
                                Util.SetProcessName ("gnome-do");
 
69
                        } catch (Exception e) {
 
70
                                Log.Error ("Failed to set process name: {0}", e.Message);
 
71
                        }
 
72
                        
 
73
                        Controller.Initialize ();
 
74
                        UniverseManager.Initialize ();
 
75
                        
 
76
                        keybinder = new XKeybinder ();
 
77
                        SetupKeybindings ();
 
78
 
 
79
                        if (!Preferences.QuietStart)
 
80
                                Controller.Summon ();
 
81
                        
 
82
                        Gtk.Application.Run ();
 
83
                        
 
84
                        RelevanceProvider.Serialize (RelevanceProvider.DefaultProvider);
 
85
                }
 
86
 
 
87
                
 
88
                public static Controller Controller {
 
89
                        get {
 
90
                                if (controller == null)
 
91
                                        controller = new Controller ();
 
92
                                return controller;
 
93
                        }
 
94
                }
 
95
 
 
96
                public static UniverseManager UniverseManager {
 
97
                        get {
 
98
                                if (universe_manager == null)
 
99
                                        universe_manager = new UniverseManager ();
 
100
                                return universe_manager;
 
101
                        }
 
102
                }
 
103
 
 
104
                static void SummonKeyCb (object sender, PreferencesChangedEventArgs e)
 
105
                {
 
106
                        try {
 
107
                                if (e.OldValue != null)
 
108
                                        keybinder.Unbind (e.OldValue as string);
 
109
                                keybinder.Bind (Keybindings.GetKeybinding ("SummonKey"), OnActivate);
 
110
                        } catch (Exception ex) {
 
111
                                Log.Error ("Could not bind summon key: {0}", ex.Message);
 
112
                                Log.Debug (ex.StackTrace);
 
113
                        }
 
114
 
 
115
                }
 
116
                
 
117
                static void SetupKeybindings ()
 
118
                {
 
119
                        try {
 
120
                                keybinder.Bind (Keybindings.GetKeybinding ("SummonKey"), OnActivate);
 
121
                        } catch (Exception e) {
 
122
                                Log.Error ("Could not bind summon key: {0}", e.Message);
 
123
                                Log.Debug (e.StackTrace);
 
124
                        }
 
125
 
 
126
                        // Watch preferences for changes to the keybinding so we
 
127
                        // can change the binding when the user reassigns it.
 
128
                        Keybindings.RegisterNotification ("SummonKey", SummonKeyCb);
 
129
                }
 
130
                
 
131
                static void OnActivate (object sender, EventArgs e)
 
132
                {
 
133
                        controller.Summon ();
 
134
                }
 
135
        }
 
136
}