示例#1
0
文件: Driver.cs 项目: GNOME/last-exit
        public static void Main(string[] args)
        {
            // Search for existing DBus server
            IDBusPlayer dbus_core = DetectInstanceAndDbus();
            HandleDbusCommands (dbus_core, args);

            // If we are the only instance, start a new DBus server
            Console.WriteLine("Starting new Last Exit server");
            try {
                dbus_remote = new DBusRemote();
                dbus_player = new DBusPlayer();
                if (dbus_player != null) {
                    dbus_remote.RegisterObject(dbus_player, "Player");
                }
            } catch (Exception e) {
                Console.Error.WriteLine (e);
            }

            string username;
            string password;

            try {
                Driver.SetProcessName ("last-exit");
            } catch {} // Ignore exception if fail (not needed to run)

            Catalog.Init("last-exit", Defines.LOCALE_DIR);
            Application.Init("last-exit", ref args);

            StockIcons.Initialize ();

            SetDefaultWindowIcon ();

            config = new Config ();

            if (config.FirstRun) {
                FirstRunDialog frd = new FirstRunDialog ();

                int response = frd.Run ();

                frd.Visible = false;

                switch (response) {
                    case (int) ResponseType.Reject:
                        Gtk.Application.Quit();
                        Environment.Exit (0);
                        break;

                    case (int) ResponseType.Ok:
                        config.Username = frd.Username;
                        config.Password = frd.Password;
                        break;

                    default:
                        break;
                }

                frd.Destroy ();
                config.FirstRun = false;
            }

            Driver.SetUpConfigDirectory ();

            //TrayIcon.ShowNotifications = config.ShowNotifications;

            username = config.Username;
            password = config.Password;

            // We must get a reference to the JIT's SEGV handler because
            // GStreamer will set its own and not restore the previous, which
            // will cause what should be NullReferenceExceptions to be unhandled
            // segfaults for the duration of the instance, as the JIT is powerless!
            // FIXME: http://bugzilla.gnome.org/show_bug.cgi?id=391777
            IntPtr mono_jit_segv_handler = System.Runtime.InteropServices.Marshal.AllocHGlobal(512);
            sigaction(Mono.Unix.Native.Signum.SIGSEGV, IntPtr.Zero, mono_jit_segv_handler);

            connection = new FMConnection (username, password);
            connection.Handshake ();

            Scrobbler scrobbler = new Scrobbler (username, password);
            Playlist playlist = new Playlist (connection);

            player = new Player (playlist);
            player.SongEnded += new Player.NewSongHandler (scrobbler.Scrobble);
            player.NewSong += new Player.NewSongHandler (scrobbler.NowPlayingNotification);

            actions = new Actions ();
            player_window = new PlayerWindow ();

            if (args.Length > 0) {
                player_window.InitialStation = args[0];
            }

            player_window.Run ();

            Application.Run ();

            // Reset the SEGV handle to that of the JIT again (SIGH!)
            sigaction(Mono.Unix.Native.Signum.SIGSEGV, mono_jit_segv_handler, IntPtr.Zero);
            System.Runtime.InteropServices.Marshal.FreeHGlobal(mono_jit_segv_handler);
        }
示例#2
0
        private void OnConnectionChanged(FMConnection.ConnectionState state)
        {
            bool connected = (state == FMConnection.ConnectionState.Connected);

            if (state == FMConnection.ConnectionState.InvalidPassword) {
                this.Visible = false;

                FirstRunDialog frd = new FirstRunDialog ();

                int response = frd.Run ();

                frd.Visible = false;
                switch (response) {
                case (int) ResponseType.Reject:
                    Environment.Exit (0);
                    break;

                case (int) ResponseType.Ok:
                    Driver.config.Username = frd.Username;
                    Driver.config.Password = frd.Password;
                    break;

                default:
                    break;
                }

                Driver.connection.Username = Driver.config.Username;
                Driver.connection.Password = Driver.config.Password;
                Driver.connection.Handshake ();

                frd.Destroy ();
                this.Visible = true;
            }

            station_combo.Sensitive = connected;
            toggle_play_button.Sensitive = connected;

            if (current_song != null) {
                love_button.Sensitive = connected;
                hate_button.Sensitive = connected;
                tag_button.Sensitive = connected;
                journal_button.Sensitive = connected;
                info_button.Sensitive = connected;
            }

            string personal = FMConnection.MakeUserRadio (Driver.connection.Username, "/personal");
            string loved = FMConnection.MakeUserRadio (Driver.connection.Username, "/loved");

            TreeIter iter;
            bool ret = stations.GetIterFirst (out iter);
            while (ret) {
                string p = (string) stations.GetValue (iter, (int) Column.Path);
                if ( p == personal || p == loved ) {
                    stations.SetValue (iter, (int) Column.Sensitive, connected & Driver.connection.Subscriber);
                }
                ret = stations.IterNext (ref iter);
            }

            if (InitialStation != null) {
                Driver.connection.ChangeStation (InitialStation);

                // Don't have an initial station anymore...
                InitialStation = null;
            }
        }