1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
/* vim:tabstop=8:noexpandtab:shiftwidth=8:
3
3
* Authors: Iain Holmes <iain@gnome.org>
5
5
* Copyright 2005, 2006 Iain Holmes
31
public sealed class Driver : Gnome.Program {
31
public sealed class Driver
32
33
// The size of the cover images.
33
34
public static int CoverSize = 66;
35
//private static Actions actions;
36
private static Actions actions;
36
37
private static PlayerWindow player_window;
38
39
public static FMConnection connection;
42
43
public static string ConfigDirectory {
43
44
get { return config_directory; }
47
public static void DBusMessage (string message, string content)
50
case "change_station":
51
connection.ChangeStation(content);
52
player_window.Present();
54
case "focus_instance":
55
// if player window is hidden don't show it
56
if (player_window.Visible == true) {
57
player_window.Present();
46
63
public static Config config;
48
public static void DBusChangeStation (string station) {
49
connection.ChangeStation (station);
52
65
public static void Main (string[] args) {
66
DBus.dbus_g_thread_init ();
56
70
Driver.SetProcessName ("last-exit");
57
new Gnome.Program ("last-exit", "0.1", Gnome.Modules.UI, args);
71
Application.Init("last-exit", ref args);
59
75
switch (DBus.CheckInstance ()) {
60
case DBus.DBusState.Error:
61
Console.WriteLine ("Error contacting other instance.");
76
case DBus.DBusState.Error:
77
Console.WriteLine ("Error contacting other instance.");
64
case DBus.DBusState.AlreadyRunning:
65
if (args.Length > 0) {
66
DBus.ChangeStation (args[0]);
80
case DBus.DBusState.AlreadyRunning:
81
if (args.Length > 0) {
82
DBus.ChangeStation (args[0]);
84
DBus.FocusInstance ();
70
case DBus.DBusState.NotRunning:
71
DBus.Init (new DBus.StationChangeHandler (DBusChangeStation));
88
case DBus.DBusState.NotRunning:
89
DBus.Init (DBusMessage);
75
94
StockIcons.Initialize ();
77
96
SetDefaultWindowIcon ();
84
103
int response = frd.Run ();
86
105
frd.Visible = false;
87
107
switch (response) {
88
case (int) ResponseType.Reject:
108
case (int) ResponseType.Reject:
109
Gtk.Application.Quit();
110
Environment.Exit (0);
92
case (int) ResponseType.Ok:
93
config.Username = frd.Username;
94
config.Password = frd.Password;
113
case (int) ResponseType.Ok:
114
config.Username = frd.Username;
115
config.Password = frd.Password;
105
126
Driver.SetUpConfigDirectory ();
107
TrayIcon.ShowNotifications = config.ShowNotifications;
128
//TrayIcon.ShowNotifications = config.ShowNotifications;
109
130
username = config.Username;
110
131
password = config.Password;
146
167
[DllImport ("libc")]
147
168
private static extern int prctl (int option,
152
174
private static void SetProcessName (string name)
154
176
if (prctl (15, Encoding.ASCII.GetBytes (name + "\0"), 0, 0, 0) != 0) {
159
181
private static void SetUpConfigDirectory ()
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) {