~ubuntu-branches/ubuntu/lucid/last-exit/lucid

« back to all changes in this revision

Viewing changes to src/Driver.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-09-24 20:33:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060924203343-jenir1e2jklb987x
Tags: 3.0-0ubuntu1
* New upstream release
* debian/patches/01_dllmaps.patch:
  + Add missing dllmaps

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/*
 
2
/* vim:tabstop=8:noexpandtab:shiftwidth=8:
3
3
 *  Authors: Iain Holmes <iain@gnome.org>
4
4
 *
5
5
 *  Copyright 2005, 2006 Iain Holmes
28
28
 
29
29
namespace LastExit
30
30
{
31
 
        public sealed class Driver : Gnome.Program {
 
31
        public sealed class Driver
 
32
        {
32
33
                // The size of the cover images.
33
34
                public static int CoverSize = 66;
34
35
 
35
 
                //private static Actions actions;
 
36
                private static Actions actions;
36
37
                private static PlayerWindow player_window;
37
38
 
38
39
                public static FMConnection connection;
42
43
                public static string ConfigDirectory {
43
44
                        get { return config_directory; }
44
45
                }
45
 
                
 
46
 
 
47
                public static void DBusMessage (string message, string content)
 
48
                {
 
49
                        switch (message) {
 
50
                                case "change_station":
 
51
                                        connection.ChangeStation(content);
 
52
                                        player_window.Present();
 
53
                                        break;
 
54
                                case "focus_instance":
 
55
                                        // if player window is hidden don't show it
 
56
                                        if (player_window.Visible == true) { 
 
57
                                                player_window.Present();
 
58
                                        }
 
59
                                        break;
 
60
                        }
 
61
                }
 
62
 
46
63
                public static Config config;
47
64
 
48
 
                public static void DBusChangeStation (string station) {
49
 
                        connection.ChangeStation (station);
50
 
                }
51
 
 
52
65
                public static void Main (string[] args) {
 
66
                        DBus.dbus_g_thread_init ();
53
67
                        string username;
54
68
                        string password;
55
69
 
56
70
                        Driver.SetProcessName ("last-exit");
57
 
                        new Gnome.Program ("last-exit", "0.1", Gnome.Modules.UI, args);
58
 
 
 
71
                        Application.Init("last-exit", ref args);
 
72
 
 
73
 
 
74
                                        
59
75
                        switch (DBus.CheckInstance ()) {
60
 
                        case DBus.DBusState.Error:
61
 
                                Console.WriteLine ("Error contacting other instance.");
62
 
                                break;
 
76
                                case DBus.DBusState.Error:
 
77
                                        Console.WriteLine ("Error contacting other instance.");
 
78
                                        break;
63
79
 
64
 
                        case DBus.DBusState.AlreadyRunning:
65
 
                                if (args.Length > 0) {
66
 
                                        DBus.ChangeStation (args[0]);
67
 
                                }
68
 
                                return;
 
80
                                case DBus.DBusState.AlreadyRunning:
 
81
                                        if (args.Length > 0) {
 
82
                                                DBus.ChangeStation (args[0]);
 
83
                                        } else {
 
84
                                                DBus.FocusInstance ();
 
85
                                        }
 
86
                                        return;
69
87
                                
70
 
                        case DBus.DBusState.NotRunning:
71
 
                                DBus.Init (new DBus.StationChangeHandler (DBusChangeStation));
72
 
                                break;
 
88
                                case DBus.DBusState.NotRunning:
 
89
                                        DBus.Init (DBusMessage);
 
90
                                        break;
73
91
                        }
74
 
                                
 
92
                                        
 
93
 
75
94
                        StockIcons.Initialize ();
76
95
 
77
96
                        SetDefaultWindowIcon ();
84
103
                                int response = frd.Run ();
85
104
 
86
105
                                frd.Visible = false;
 
106
 
87
107
                                switch (response) {
88
 
                                case (int) ResponseType.Reject:
89
 
                                        Environment.Exit (0);
90
 
                                        break;
 
108
                                        case (int) ResponseType.Reject:
 
109
                                                Gtk.Application.Quit();
 
110
                                                Environment.Exit (0);
 
111
                                                break;
91
112
 
92
 
                                case (int) ResponseType.Ok:
93
 
                                        config.Username = frd.Username;
94
 
                                        config.Password = frd.Password;
95
 
                                        break;
 
113
                                        case (int) ResponseType.Ok:
 
114
                                                config.Username = frd.Username;
 
115
                                                config.Password = frd.Password;
 
116
                                                break;
96
117
                                        
97
 
                                default:
98
 
                                        break;
 
118
                                        default:
 
119
                                                break;
99
120
                                }
100
121
 
101
122
                                frd.Destroy ();
104
125
 
105
126
                        Driver.SetUpConfigDirectory ();
106
127
 
107
 
                        TrayIcon.ShowNotifications = config.ShowNotifications;
108
 
                        
 
128
                        //TrayIcon.ShowNotifications = config.ShowNotifications;
 
129
                
109
130
                        username = config.Username;
110
131
                        password = config.Password;
111
132
 
114
135
 
115
136
                        player = new Player ();
116
137
 
117
 
                        //actions = new Actions ();
 
138
                        actions = new Actions ();
118
139
                        player_window = new PlayerWindow ();
119
140
 
120
141
                        if (args.Length > 0) {
145
166
 
146
167
                [DllImport ("libc")]
147
168
                private static extern int prctl (int option,  
148
 
                                                 byte[] arg2,
149
 
                                                 ulong arg3,
150
 
                                                 ulong arg4,
151
 
                                                 ulong arg5);
 
169
                                 byte[] arg2,
 
170
                                 ulong arg3,
 
171
                                 ulong arg4,
 
172
                                 ulong arg5);
 
173
        
152
174
                private static void SetProcessName (string name)
153
175
                {
154
176
                        if (prctl (15, Encoding.ASCII.GetBytes (name + "\0"), 0, 0, 0) != 0) {
158
180
 
159
181
                private static void SetUpConfigDirectory ()
160
182
                {
161
 
                        config_directory = Path.Combine (Gnome.User.DirGet (), "last-exit");
 
183
                        config_directory = Path.Combine (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "last-exit");
162
184
                        DirectoryInfo dinfo = new DirectoryInfo (config_directory);
163
185
                        if (dinfo.Exists) {
164
186
                                return;
166
188
                        
167
189
                        dinfo.Create ();
168
190
                }
 
191
 
 
192
                public static Actions Actions {
 
193
                        get { return actions; }
 
194
                }
 
195
 
 
196
                public static PlayerWindow PlayerWindow {
 
197
                        get { return player_window; }
 
198
                }
169
199
        }
170
200
}