Exemplo n.º 1
0
    public MainWindow()
    {
      InitializeComponent();
      This = this;

      Title = string.Format("WpfMpdClient v.{0}", Assembly.GetExecutingAssembly().GetName().Version);
      stcAbout.DataContext = m_About;
      try {
        txtLicense.Text = File.ReadAllText("LICENSE.TXT");
      } catch (Exception){ 
        txtLicense.Text = "LICENSE not found!!!";
      }

      m_Settings = Settings.Deserialize(Settings.GetSettingsFileName());
      if (m_Settings != null) {
        txtServerAddress.Text = m_Settings.ServerAddress;
        txtServerPort.Text = m_Settings.ServerPort.ToString();
        txtPassword.Password = m_Settings.Password;
        chkAutoreconnect.IsChecked = m_Settings.AutoReconnect;
        chkShowStop.IsChecked = m_Settings.ShowStopButton;
        chkShowFilesystem.IsChecked = m_Settings.ShowFilesystemTab;
        chkMinimizeToTray.IsChecked = m_Settings.MinimizeToTray;
        chkCloseToTray.IsChecked = m_Settings.CloseToTray;
        chkShowMiniPlayer.IsChecked = m_Settings.ShowMiniPlayer;
        chkScrobbler.IsChecked = m_Settings.Scrobbler;
        cmbLastFmLang.SelectedIndex = m_Languages.IndexOf(m_Settings.InfoLanguage);
        if (cmbLastFmLang.SelectedIndex == -1)
          cmbLastFmLang.SelectedIndex = 0;
        cmbPlaylistStyle.SelectedIndex = m_Settings.StyledPlaylist ? 1 : 0;

        chkTray_Changed(null, null);

        lstTracks.SetColumnsInfo(m_Settings.TracksListView);
        lstPlaylist.SetColumnsInfo(m_Settings.PlayListView);
      } else
        m_Settings = new Settings();
      m_LastfmScrobbler = new LastfmScrobbler(Utilities.DecryptString(m_Settings.ScrobblerSessionKey));

      if (m_Settings.WindowWidth > 0 && m_Settings.WindowHeight > 0){
        Width = m_Settings.WindowWidth;
        Height = m_Settings.WindowHeight;
      }
      if (m_Settings.WindowLeft >= 0 && m_Settings.WindowHeight >= 0){
        Left = m_Settings.WindowLeft;
        Top = m_Settings.WindowTop;
      }else
        WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
      if (m_Settings.WindowMaximized)
        WindowState = System.Windows.WindowState.Maximized;

      m_Mpc = new Mpc();
      m_Mpc.OnConnected += MpcConnected;
      m_Mpc.OnDisconnected += MpcDisconnected;

      m_MpcIdle = new Mpc();
      m_MpcIdle.OnConnected += MpcIdleConnected;
      m_MpcIdle.OnSubsystemsChanged += MpcIdleSubsystemsChanged;

      cmbSearch.SelectedIndex = 0;

      tabFileSystem.Visibility = m_Settings.ShowFilesystemTab ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
      playerControl.ShowStopButton = m_Settings.ShowStopButton;
      playerControl.Mpc = m_Mpc;
      lstPlaylist.Visibility = m_Settings.StyledPlaylist ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;
      lstPlaylistStyled.Visibility = m_Settings.StyledPlaylist ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;

      lstTracks.Visibility = m_Settings.StyledPlaylist ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;
      lstTracksStyled.Visibility = m_Settings.StyledPlaylist ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;


      m_NotifyIcon = new System.Windows.Forms.NotifyIcon();
      m_NotifyIcon.Icon = new System.Drawing.Icon("mpd_icon.ico", new System.Drawing.Size(32,32));
      m_NotifyIcon.MouseDown += new System.Windows.Forms.MouseEventHandler(NotifyIcon_MouseDown);
      m_NotifyIconMenu = (ContextMenu)this.FindResource("TrayIconContextMenu");
      Closing += CloseHandler;

      if (!string.IsNullOrEmpty(m_Settings.ServerAddress)){
        m_StartTimer = new System.Timers.Timer();
        m_StartTimer.Interval = 500;
        m_StartTimer.Elapsed += StartTimerHandler;
        m_StartTimer.Start();
      }

      m_Updater = new Updater(new Uri("http://www.sakya.it/updater/updater.php"), "WpfMpdClient", "Windows");
      m_Updater.AppCurrentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
      m_Updater.CheckCompletedDelegate += CheckCompleted;
      m_Updater.Check();

      lstArtist.ItemsSource = m_ArtistsSource;
      Type t = typeof(ListboxEntry);
      lstArtist.SearchProperty = t.GetProperty("Artist");

      lstAlbums.ItemsSource = m_AlbumsSource;
      lstAlbums.SearchProperty = t.GetProperty("Album");

      lstGenresAlbums.ItemsSource = m_GenresAlbumsSource;
      lstGenresAlbums.SearchProperty = t.GetProperty("Album");

      lstPlaylist.ItemsSource = m_PlaylistTracks;
      lstPlaylistStyled.ItemsSource = m_PlaylistTracks;
      m_DragDropManager = new ListViewDragDropManager<MpdFile>(m_Settings.StyledPlaylist ? lstPlaylistStyled : lstPlaylist);
      m_DragDropManager.ProcessDrop += dragMgr_ProcessDrop;

      lstChannels.ItemsSource = m_Channels;
      cmbChannnels.ItemsSource = m_Channels;
      lstMessages.ItemsSource = m_Messages;
      CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lstMessages.ItemsSource);
      PropertyGroupDescription group = new PropertyGroupDescription("Channel");
      view.GroupDescriptions.Add(group);

      m_ArtDownloader.Start();      
      txtStatus.Text = "Not connected";
    }
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();
              This = this;

              Title = string.Format("WpfMpdClient v.{0}", Assembly.GetExecutingAssembly().GetName().Version);
              stcAbout.DataContext = m_About;
              try {
            txtLicense.Text = File.ReadAllText("LICENSE.TXT");
              } catch (Exception){
            txtLicense.Text = "LICENSE not found!!!";
              }

              m_Settings = Settings.Deserialize(Settings.GetSettingsFileName());
              if (m_Settings != null) {
            txtServerAddress.Text = m_Settings.ServerAddress;
            txtServerPort.Text = m_Settings.ServerPort.ToString();
            txtPassword.Password = m_Settings.Password;
            chkAutoreconnect.IsChecked = m_Settings.AutoReconnect;
            chkShowStop.IsChecked = m_Settings.ShowStopButton;
            chkShowFilesystem.IsChecked = m_Settings.ShowFilesystemTab;
            chkMinimizeToTray.IsChecked = m_Settings.MinimizeToTray;
            chkCloseToTray.IsChecked = m_Settings.CloseToTray;
            chkScrobbler.IsChecked = m_Settings.Scrobbler;
              } else
            m_Settings = new Settings();
              m_LastfmScrobbler = new LastfmScrobbler(Utilities.DecryptString(m_Settings.ScrobblerSessionKey));

              if (m_Settings.WindowWidth > 0 && m_Settings.WindowHeight > 0){
            Width = m_Settings.WindowWidth;
            Height = m_Settings.WindowHeight;
              }
              if (m_Settings.WindowLeft >= 0 && m_Settings.WindowHeight >= 0){
            Left = m_Settings.WindowLeft;
            Top = m_Settings.WindowTop;
              }else
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
              if (m_Settings.WindowMaximized)
            WindowState = System.Windows.WindowState.Maximized;

              m_Mpc = new Mpc();
              m_Mpc.OnConnected += MpcConnected;
              m_Mpc.OnDisconnected += MpcDisconnected;

              m_Timer = new Timer();

              cmbSearch.SelectedIndex = 0;

              tabFileSystem.Visibility = m_Settings.ShowFilesystemTab ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
              playerControl.ShowStopButton = m_Settings.ShowStopButton;
              playerControl.Mpc = m_Mpc;
              playerControl.PlayClicked += PlayClickedHandler;
              playerControl.PauseClicked += PauseClickedHandler;
              playerControl.BackClicked += BackClickedHandler;
              playerControl.ForwardClicked += ForwardClickedHandler;
              playerControl.RandomClicked += RandomClickedHandler;
              playerControl.RepeatClicked += RepeatClickedHandler;
              playerControl.StopClicked += StopClickedHandler;

              m_NotifyIcon = new System.Windows.Forms.NotifyIcon();
              m_NotifyIcon.Icon = new System.Drawing.Icon("mpd_icon.ico", new System.Drawing.Size(32,32));
              m_NotifyIcon.MouseDown += new System.Windows.Forms.MouseEventHandler(NotifyIcon_MouseDown);
              m_NotifyIconMenu = (ContextMenu)this.FindResource("TrayIconContextMenu");
              Closing += CloseHandler;

              if (!string.IsNullOrEmpty(m_Settings.ServerAddress)){
            m_StartTimer = new Timer();
            m_StartTimer.Interval = 500;
            m_StartTimer.Elapsed += StartTimerHandler;
            m_StartTimer.Start();
              }

              m_Updater = new Updater(new Uri("http://www.sakya.it/updater/updater.php"), "WpfMpdClient", "Windows");
              m_Updater.CheckCompletedDelegate += CheckCompleted;
              m_Updater.Check();
        }