Click here to Skip to main content
15,879,326 members
Articles / Desktop Programming / Windows Forms

BSEtunes

Rate me:
Please Sign up or sign in to vote.
4.67/5 (11 votes)
24 Apr 2010CPOL4 min read 64.4K   4.3K   58  
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using BSE.Platten.BO;
using BSE.Platten.Common;
using BSE.Configuration;
using BSE.Platten.Audio;
using System.Globalization;
using BSE.Windows.Forms;
using BSE.Platten.Tunes.Properties;
using System.IO;
using System.Windows.Interop;

namespace BSE.Platten.Tunes
{
    public partial class CTunes : BaseForm, IConfigurationSettings
    {
        #region Constants

        private const string m_strSettingsFileNameSettingsPart = ".Settings";

        #endregion

        #region Enumeratoren

        public enum EPlayerApp
        {
            Radio,
            Lied,
            CD
        }

        public enum PlayButtonMode
        {
            Start,
            Pause,
            Stop
        }

        #endregion

        #region Delegates

        private delegate void DelegateRefreshControls();
        private delegate void DelegateStopRadio();

        #endregion

        #region FieldsPrivate

        private CTrackCollection m_trackCollectionByFilterSettings;
        private BSE.Platten.BO.Environment m_environment;
        private string m_strAudioHomeDirectory;
        private string m_strConnection;
        private Image m_imgSong;
        private System.Threading.Thread m_threadControlRefresh;

        #endregion

        #region Properties

        #region IConfigurationSettings

        public string ConfigurationFolder
        {
            get { return this.GetType().Namespace; }
        }

        public string ConfigurationFileName
        {
            get { return this.GetType().Namespace; }
        }

        public string SettingsFileName
        {
            get { return this.GetType().Namespace + m_strSettingsFileNameSettingsPart; }
        }
        #endregion

        internal string AudioHomeDirectory
        {
            get { return this.m_strAudioHomeDirectory; }
            set { this.m_strAudioHomeDirectory = value; }
        }

        internal string ConnectionString
        {
            get { return this.m_strConnection; }
            set { this.m_strConnection = value; }
        }

        internal BSE.Platten.BO.Environment Environment
        {
            get { return this.m_environment; }
            set { this.m_environment = value; }
        }

        internal CAlbum CurrentAlbum
        {
            get;
            set;
        }

        internal CTrackCollection TrackCollectionByFilterSettings
        {
            get { return this.m_trackCollectionByFilterSettings; }
            set { this.m_trackCollectionByFilterSettings = value; }
        }
        internal bool PerformTreeEvent
        {
            get;
            set;
        }
        #endregion

        #region MethodsPublic

        public CTunes()
            : base()
        {
            InitializeComponent();

            this.m_configuration.ApplicationSubDirectory = this.ConfigurationFolder;
            this.m_configuration.ConfigFileName = this.ConfigurationFileName;

            this.m_environment = new BSE.Platten.BO.Environment(this.m_configuration);

            this.m_settings.ApplicationSubDirectory = this.ConfigurationFolder;
            this.m_settings.ConfigFileName = this.SettingsFileName;

            this.m_imgSong = Properties.Resources.song;

            this.AllowDrop = true;
            this.KeyPreview = true;

            this.m_tsAudioPlayer.Stretch = true;
            this.m_tsAudioPlayer.GripStyle = ToolStripGripStyle.Hidden;
            ToolStripManager.Merge(this.m_tsSearch, this.m_tsMusic);
            ToolStripManager.Merge(this.m_tsMusic, this.m_tsAudioPlayer);

            this.m_pnlSearch.Tag = this.m_mnuView_Search;
            this.m_pnlPlayList.Tag = this.m_mnuView_PlaylistEditor;

            this.m_playList.PlayerManager = this.m_playerManager;
            this.m_albumProperties.PlayerManager = this.m_playerManager;
            this.m_clipBoard.PlayerManager = this.m_playerManager;

        }

        #endregion

        #region MethodsPrivate

        private void CTunes_Load(object sender, EventArgs e)
        {
            int iSplashStep = 0;
            int iSplashStepsTotal = 14;
            CSplashScreen.ShowSplashScreen();
            CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageLoadSystemsettings, iSplashStep++, iSplashStepsTotal);
            CTunesSettingsData settingsData = LoadSettings();
            try
            {
                this.m_mnuView.Enabled = false;
                this.m_mnuFilter.Enabled = false;
                this.m_mnuExtras_Statistik.Enabled = false;

                //Starte Player
                CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageStartPlayer, iSplashStep++, iSplashStepsTotal);
                this.m_playerManager.LoadPlayer(this.m_configuration);
                CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageCheckDatabaseConnection, iSplashStep++, iSplashStepsTotal);
                this.ConnectionString = this.m_environment.GetConnectionString();
                CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageCheckAudiodirectory, iSplashStep++, iSplashStepsTotal);
                this.AudioHomeDirectory = this.m_environment.GetAudioHomeDirectory();

                CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageCheckDatabaseHost, iSplashStep++, iSplashStepsTotal);
                if (this.m_ssMain.IsHostAvailable(this.m_environment) == true)
                {
                    this.m_mnuView.Enabled = true;
                    this.m_mnuFilter.Enabled = true;
                    this.m_mnuExtras_Statistik.Enabled = true;

                    CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.ConnectionString);

                    //Lade Covers
                    CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageLoadCovers, iSplashStep++, iSplashStepsTotal);
                    GetCovers();

                    //l�dt Alben und Genres in den Tree
                    CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageLoadAlbums, iSplashStep++, iSplashStepsTotal);
                    CInterpretData[] interpretsAndAlbums = tunesBusinessObject.GetInterpretsAndAlbums();
                    this.m_treeInterpretenTitel.SetInterpretsAndAlbums(interpretsAndAlbums);

                    //l�dt den TreeviewGenreInterpretsAndTitles
                    CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageLoadGenres, iSplashStep++, iSplashStepsTotal);
                    CGenreData[] genreWithAlbums = tunesBusinessObject.GetGenresWithAlbums();
                    this.m_treeInterpretenTitel.SetGenresWithAlbums(genreWithAlbums);

                    //l�dt den TreeviewYearInterpretsAndTitles
                    CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageLoadYears, iSplashStep++, iSplashStepsTotal);
                    CYearData[] yearsWithAlbums = tunesBusinessObject.GetYearsWithAlbums();
                    this.m_treeInterpretenTitel.SetYearsWithAlbums(yearsWithAlbums);

                    //l�scht alte Eintr�ge aus der Benutzerhistory
                    CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageDeleteHistory, iSplashStep++, iSplashStepsTotal);
                    tunesBusinessObject.DeleteTracksFromHistory(this.m_environment.UserName);

                    //l�dt die Benutzerhistory
                    CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageLoadHistory, iSplashStep++, iSplashStepsTotal);
                    SortableCollection<CHistoryTrack> trackCollection = tunesBusinessObject.GetHistoryTrackCollection(this.m_environment.UserName);
                    this.m_history.UpdateHistory(trackCollection);

                    //Lied Favorites
                    CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageLoadFavorites, iSplashStep++, iSplashStepsTotal);
                    CFavorite[] singleFavorites
                        = tunesBusinessObject.GetFavoritesByFavoritId(10, (int)EPlayerApp.Lied, this.m_environment.UserName);
                    this.m_treeFavorites.SetFavorites(singleFavorites, ListMode.Singlecharts);

                    //CD Favorites
                    CFavorite[] albumFavorites
                        = tunesBusinessObject.GetFavoritesByFavoritId(10, (int)EPlayerApp.CD, this.m_environment.UserName);
                    this.m_treeFavorites.SetFavorites(albumFavorites, ListMode.Albumcharts);

                    //Playlisten
                    CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageLoadPlaylists, iSplashStep++, iSplashStepsTotal);
                    CPlaylist[] playLists = tunesBusinessObject.GetPlaylistsByUserName(this.m_environment.UserName);
                    this.m_treeFavorites.SetPlayLists(playLists);

                    //Filter
                    CSplashScreen.SetStatusMessage(Resources.IDS_TunesLoadMessageLoadFilters, iSplashStep++, iSplashStepsTotal);
                    BSE.Platten.Tunes.Filters.FilterMain filter
                        = new BSE.Platten.Tunes.Filters.FilterMain();
                    Filters.FilterConfiguration filterConfiguration
                        = filter.GetFilterConfiguration(this.m_environment);
                    this.m_mnuFilter_Properties.Text = filterConfiguration.FilterName;
                    this.TrackCollectionByFilterSettings = filter.GetTracksByFilterSettings(this.m_environment, (FilterSettings)filterConfiguration);
                    if (this.TrackCollectionByFilterSettings.Count > 0)
                    {
                        int iIndex = this.TrackCollectionByFilterSettings.GetRandomIndex();
                        CTrack currentTrack = this.TrackCollectionByFilterSettings[iIndex] as CTrack;
                        if (currentTrack != null)
                        {
                            int iStartTitelId = currentTrack.TitelId;
                            GetSelectedTitle(iStartTitelId, true);
                        }
                    }

                    this.m_search.Environment = this.m_environment;
                    this.m_playList.Environment = this.m_environment;
                    this.m_history.Environment = this.m_environment;
                    this.m_clipBoard.Environment = this.m_environment;
                }
            }
            catch (BSE.Configuration.ConfigurationValueNotFoundException configurationValueNotFoundException)
            {
                if (CSplashScreen.SplashScreen != null)
                {
                    CSplashScreen.CloseSplashScreen(this);
                }
                DialogResult dialogResult = GlobalizedMessageBox.Show(this, configurationValueNotFoundException.Message, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                if (dialogResult == DialogResult.OK)
                {
                    OpenOptions();
                }
            }
            catch (Exception exception)
            {
                if (CSplashScreen.SplashScreen != null)
                {
                    CSplashScreen.CloseSplashScreen(this);
                }
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.m_ssMain.HostAvailabilityChanged += new EventHandler<HostAvailableEventArgs>(HostAvailabilityChanged);
                this.m_plstMain.Expand(this.m_pnlHistory);

                RenderStyleConfigurationData formStyleConfigurationData =
                    BSE.Platten.Common.RenderStyleConfigurationControl.GetConfiguration(this.m_configuration) as RenderStyleConfigurationData;
                if (formStyleConfigurationData != null)
                {
                    SetFormStyleSettings(formStyleConfigurationData);
                }

                if (settingsData != null && settingsData.WindowState == FormWindowState.Maximized)
                {
                    this.WindowState = FormWindowState.Maximized;
                }

                if (CSplashScreen.SplashScreen != null)
                {
                    CSplashScreen.CloseSplashScreen(this);
                }
            }
        }

        private void CTunes_FormClosing(object sender, FormClosingEventArgs e)
        {
            SaveSettings();
            if (this.m_playerManager.HasPlayerStarted)
            {
                this.m_playerManager.Close();
            }
            Application.Exit();
        }

        private void CTunes_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.F12:
                    if (this.CurrentAlbum.Tracks != null)
                    {
                        this.m_ctxTunes.Items.Clear();
                        this.m_ctxTunes.Items.AddRange(GetToolStripMenuItemsLieder());
                        this.m_ctxTunes.Show(new Point(Cursor.Position.X, Cursor.Position.Y));
                    }
                    break;
            }
        }

        private void OptionenClick(object sender, EventArgs e)
        {
            OpenOptions();
        }

        private void OpenOptions()
        {
            Application.DoEvents();
            try
            {
                using (Options options = new Options(this.m_configuration))
                {
                    options.ConfigurationChanged += new EventHandler(this.OptionsConfigurationChanged);
                    options.AudioPlayerChanged += new EventHandler(this.AudioPlayerChanged);
                    options.FormStyleChanged += new EventHandler(this.FormStyleChanged);
                    options.ShowDialog(this);
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OptionsConfigurationChanged(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                bool bHasChanged = false;
                //If the AudioHome Directory has changed
                string strAudioHomeDirectory = this.m_environment.GetAudioHomeDirectory();
                if (string.Compare(strAudioHomeDirectory,this.AudioHomeDirectory,  StringComparison.OrdinalIgnoreCase) != 0)
                {
                    this.AudioHomeDirectory = strAudioHomeDirectory;
                    bHasChanged = true;
                }

                //If the ConnectionString has changed
                string strConnection = this.m_environment.GetConnectionString();
                if (string.Compare(strConnection, this.ConnectionString, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    this.ConnectionString = strConnection;
                    bHasChanged = true;
                }
                if (bHasChanged == true)
                {
                    bool isHostAvailable = this.m_ssMain.IsHostAvailable(this.m_environment);
                    HostAvailabilityChanged(sender, new HostAvailableEventArgs(new DatabaseHostAvailability
                    {
                        IsAvailable = isHostAvailable
                    }));
                }
            }
            catch (BSE.Configuration.ConfigurationValueNotFoundException configurationValueNotFoundException)
            {
                DialogResult dialogResult = GlobalizedMessageBox.Show(this, configurationValueNotFoundException.Message, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                if (dialogResult == DialogResult.OK)
                {
                    OpenOptions();
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void AudioPlayerChanged(object sender, EventArgs e)
        {
            try
            {
                this.m_playerManager.LoadPlayer(this.m_configuration);
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void FormStyleChanged(object sender, EventArgs e)
        {
            RenderStyleConfigurationData formStyleConfigurationData = RenderStyleConfigurationControl.GetConfiguration(
                this.m_configuration) as RenderStyleConfigurationData;
            if (formStyleConfigurationData != null)
            {
                SetFormStyleSettings(formStyleConfigurationData);
            }
        }

        private void SetFormStyleSettings(RenderStyleConfigurationData renderStyleConfigurationData)
        {
            if ((ToolStripManager.VisualStylesEnabled == true) && (renderStyleConfigurationData != null))
            {
                RenderStyle renderStyle = renderStyleConfigurationData.RenderStyle;
                if (renderStyle != null)
                {
                    ToolStripProfessionalRenderer toolStripRenderer = null;
                    BSE.Windows.Forms.ProfessionalColorTable professionalColorTable = null;
                    BSE.Windows.Forms.PanelColors panelColors = null;
                    BSE.Windows.Forms.PanelStyle panelStyle = renderStyle.PanelStyle;

                    if (renderStyle.TypeProfessionalColorTable != null)
                    {
                        professionalColorTable =
                            Activator.CreateInstance(renderStyle.TypeProfessionalColorTable) as BSE.Windows.Forms.ProfessionalColorTable;
                        if (professionalColorTable != null)
                        {
                            panelColors = professionalColorTable.PanelColorTable;
                        }
                    }

                    if (renderStyle.TypeToolStripProfessionalRenderer != null)
                    {
                        if (professionalColorTable != null)
                        {
                            toolStripRenderer = Activator.CreateInstance(renderStyle.TypeToolStripProfessionalRenderer, new object[] { professionalColorTable }) as ToolStripProfessionalRenderer;
                        }
                        else
                        {
                            toolStripRenderer =
                                Activator.CreateInstance(renderStyle.TypeToolStripProfessionalRenderer) as ToolStripProfessionalRenderer;
                        }
                        if (toolStripRenderer != null)
                        {
                            if (professionalColorTable == null)
                            {
                                professionalColorTable = toolStripRenderer.ColorTable as BSE.Windows.Forms.ProfessionalColorTable;
                                if (professionalColorTable != null)
                                {
                                    panelColors = professionalColorTable.PanelColorTable;
                                }
                            }
                        }
                    }
                    if ((panelColors != null)
                        && (professionalColorTable != null)
                        && toolStripRenderer != null)
                    {
                        this.PanelStyle = panelStyle;
                        this.PanelColors = panelColors;
                        this.ProfessionalColorTable = professionalColorTable;
                        toolStripRenderer.RoundedEdges = false;
                        ToolStripManager.Renderer = toolStripRenderer;
                    }
                }
            }
        }

        private void StatistikClick(object sender, EventArgs e)
        {
            using (Statistics statistik = new Statistics
            {
                ConnectionString = this.ConnectionString
            })
            {
                statistik.ProfessionalColorTable = this.ProfessionalColorTable;
                statistik.ShowDialog();
            }
        }

        private void HelpAboutClick(object sender, EventArgs e)
        {
            Application.DoEvents();
            BSE.Windows.Forms.About about = new BSE.Windows.Forms.About();
            about.BackgroundImage = BSE.Platten.Tunes.Properties.Resources.BSEAbout;
            about.AlternatingBackColor = BSE.Platten.Common.BSEColors.AlternatingBackColor;
            about.ClientSize = about.BackgroundImage.Size;
            about.ShowInTaskbar = false;
            about.ShowDialog();
        }

        private void HostAvailabilityChanged(object sender, HostAvailableEventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                DatabaseHostAvailability databaseHostAvailability = e.DatabaseHostAvailability;
                if (databaseHostAvailability != null)
                {
                    if (databaseHostAvailability.IsAvailable == false)
                    {
                        //Alle Controls die Daten manipulieren k�nnen werden disabled
                        foreach (Control control in this.m_tscMain.Controls)
                        {
                            if (control.Contains(this.m_mnuMain) == true)
                            {
                                foreach (Control subControl in control.Controls)
                                {
                                    MenuStrip menuStrip = subControl as MenuStrip;
                                    if (menuStrip != null)
                                    {
                                        foreach (ToolStripItem toolStripItem in menuStrip.Items)
                                        {
                                            toolStripItem.Enabled = false;
                                            if (toolStripItem == this.m_mnuDatei)
                                            {
                                                toolStripItem.Enabled = true;
                                            }
                                            if (toolStripItem == this.m_mnuExtras)
                                            {
                                                toolStripItem.Enabled = true;
                                            }
                                            if (toolStripItem == this.m_mnuHelp)
                                            {
                                                toolStripItem.Enabled = true;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (control.Contains(this.m_ssMain) == true)
                            {
                                foreach (Control subControl in control.Controls)
                                {
                                    StatusStrip statusStrip = subControl as StatusStrip;
                                    if (statusStrip != null)
                                    {
                                        statusStrip.Enabled = true;
                                    }
                                }
                            }
                            else
                            {
                                control.Enabled = false;
                            }
                        }
                        this.m_mnuExtras_Statistik.Enabled = false;
                    }
                    else
                    {
                        foreach (Control control in this.m_tscMain.Controls)
                        {
                            control.Enabled = true;
                            if (control.Contains(this.m_mnuMain) == true)
                            {
                                foreach (Control subControl in control.Controls)
                                {
                                    MenuStrip menuStrip = subControl as MenuStrip;
                                    if (menuStrip != null)
                                    {
                                        foreach (ToolStripItem toolStripItem in menuStrip.Items)
                                        {
                                            toolStripItem.Enabled = true;
                                        }
                                    }
                                }
                            }
                        }
                        StartRefreshControlsThread();
                    }
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void BSEAdminClick(object sender, EventArgs e)
        {
            if (this.CurrentAlbum != null)
            {
                Application.DoEvents();
                try
                {
                    using (BSE.Platten.Admin.Admin admin
                        = new BSE.Platten.Admin.Admin(
                        this.m_configuration,
                        this.CurrentAlbum.AlbumId))
                    {
                        if (this.PanelColors != null)
                        {
                            admin.PanelStyle = this.PanelStyle;
                            admin.PanelColors = this.PanelColors;
                        }
                        admin.ProfessionalColorTable = this.ProfessionalColorTable;

                        admin.ShowInTaskbar = false;
                        admin.ShowDialog(this);
                    }
                }
                catch (Exception exception)
                {
                    GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void m_mnuDatei_Beenden_Click(object sender, EventArgs e)
        {
            Application.DoEvents();
            this.Close();
        }

        private void FilterPropertiesClick(object sender, EventArgs e)
        {
            Application.DoEvents();
            try
            {
                using (BSE.Platten.Tunes.Filters.FilterMain filter
                    = new BSE.Platten.Tunes.Filters.FilterMain(this.m_environment))
                {
                    if (this.PanelColors != null)
                    {
                        filter.PanelStyle = this.PanelStyle;
                        filter.PanelColors = this.PanelColors;
                    }
                    filter.ProfessionalColorTable = this.ProfessionalColorTable;

                    filter.FilterChanged -= new EventHandler<BSE.Platten.Tunes.Filters.FilterChangedEventArgs>(FilterChanged);
                    filter.FilterChanged += new EventHandler<BSE.Platten.Tunes.Filters.FilterChangedEventArgs>(FilterChanged);
                    filter.ShowDialog();
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void FilterChanged(object sender, Filters.FilterChangedEventArgs e)
        {
            BSE.Platten.Tunes.Filters.FilterMain filter
                                   = new BSE.Platten.Tunes.Filters.FilterMain();
            try
            {
                BSE.Platten.Tunes.Filters.FilterConfiguration filterConfiguration
                    = filter.GetFilterConfiguration(this.m_environment);
                this.m_mnuFilter_Properties.Text = filterConfiguration.FilterName;
                this.TrackCollectionByFilterSettings = filter.GetTracksByFilterSettings(this.m_environment, (FilterSettings)filterConfiguration);

                //Wenn das Radio l�uft und der Filter ge�ndert wurde, werden die neuen Tracks dem PlayerManager �bergeben
                if (this.m_mnuMusik_Radio.Checked == true)
                {
                    this.m_playerManager.SetTracksToPlay(this.TrackCollectionByFilterSettings);
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void PlayListEditorClick(object sender, EventArgs e)
        {
            XPanderPanelList parentList = this.m_pnlPlayList.Parent as XPanderPanelList;
            if (parentList == null)
            {
                this.m_plstMain.XPanderPanels.Add(this.m_pnlPlayList);
                if (this.PanelColors != null)
                {
                    this.m_pnlPlayList.SetPanelProperties(this.PanelColors);
                }
            }
            this.m_mnuView_PlaylistEditor.Checked = false;
            if (this.m_pnlPlayList.Expand == false)
            {
                this.m_plstMain.Expand(this.m_pnlPlayList);
            }
        }

        private void SearchClick(object sender, EventArgs e)
        {
            XPanderPanelList parentList = this.m_pnlSearch.Parent as XPanderPanelList;
            if (parentList == null)
            {
                this.m_plstMain.XPanderPanels.Add(this.m_pnlSearch);
                if (this.PanelColors != null)
                {
                    this.m_pnlSearch.SetPanelProperties(this.PanelColors);
                }
            }
            this.m_mnuView_Search.Checked = true;
            if (this.m_pnlSearch.Expand == false)
            {
                this.m_plstMain.Expand(this.m_pnlSearch);
            }
        }

        private void ShowListClick(object sender, EventArgs e)
        {
            this.m_pnlRight.Visible = !this.m_pnlRight.Visible;
        }

        private void ListVisibilityChanged(object sender, EventArgs e)
        {
            this.m_mnuView_List.Checked = this.m_pnlRight.Visible;
        }

        private void ListCloseClick(object sender, EventArgs e)
        {
            this.m_pnlRight.Visible = false;
        }

        private void ViewRefreshClick(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                StartRefreshControlsThread();
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void SearchExecuting(object sender, SearchExecuteEventArgs e)
        {
            this.m_search.SetSearchTerm(e.SearchTerm);
            SearchClick(sender, e);
        }

        private void SearchExecuted(object sender, SearchExecuteEventArgs e)
        {
            this.m_tsSearch.SetSearchTerm(e.SearchTerm);
        }

        private void RemovableDriveChanges(object sender, BSE.RemovableDrives.DriveChangeEventArgs e)
        {
            BSE.RemovableDrives.RemovableDrive removableDrive = e.RemovableDrive;
            if (removableDrive != null)
            {
                bool bIsNotInPanelList = true;
                foreach (BSE.Windows.Forms.XPanderPanel xpanderPanel in this.m_plstMain.XPanderPanels)
                {
                    XPanderPanelAudioDrive xPanderPanelAudioDrive = xpanderPanel as XPanderPanelAudioDrive;
                    if (xPanderPanelAudioDrive != null)
                    {
                        if (removableDrive.Equals(xPanderPanelAudioDrive.AudioDrive) == true)
                        {
                            bIsNotInPanelList = false;
                        }
                    }
                }
                if (bIsNotInPanelList == true)
                {
                    XPanderPanelAudioDrive xpanderPanel = new XPanderPanelAudioDrive();
                    xpanderPanel.ToolTipTextCloseIcon = Resources.IDS_TooltipPanelClose;
                    xpanderPanel.ToolTipTextExpandIconPanelCollapsed = Resources.IDS_TooltipPanelMaximize;
                    xpanderPanel.AudioDrive = removableDrive;
                    xpanderPanel.Environment = this.m_environment;
                    xpanderPanel.Settings = this.m_settings;
                    this.m_plstMain.XPanderPanels.Add(xpanderPanel);
                    this.m_plstMain.Expand(xpanderPanel);
                }
            }
        }

        private void RemovableDriveRemoved(object sender, BSE.RemovableDrives.DriveChangeEventArgs e)
        {
            BSE.RemovableDrives.RemovableDrive removableDrive = e.RemovableDrive;
            if (removableDrive != null)
            {
                foreach (BSE.Windows.Forms.XPanderPanel xpanderPanel in this.m_plstMain.XPanderPanels)
                {
                    XPanderPanelAudioDrive xPanderPanelAudioDrive = xpanderPanel as XPanderPanelAudioDrive;
                    if (xPanderPanelAudioDrive != null)
                    {
                        if (removableDrive.Equals(xPanderPanelAudioDrive.AudioDrive) == true)
                        {
                            xPanderPanelAudioDrive.AudioDrive = null;
                        }
                    }
                }
            }
        }

        private void RemovableDriveAdded(object sender, BSE.RemovableDrives.DriveChangeEventArgs e)
        {
            BSE.RemovableDrives.RemovableDrive removableDrive = e.RemovableDrive;
            if (removableDrive != null)
            {
                foreach (BSE.Windows.Forms.XPanderPanel xpanderPanel in this.m_plstMain.XPanderPanels)
                {
                    XPanderPanelAudioDrive xPanderPanelAudioDrive = xpanderPanel as XPanderPanelAudioDrive;
                    if (xPanderPanelAudioDrive != null)
                    {
                        if (xPanderPanelAudioDrive.VolumeName.Equals(removableDrive.VolumeName) == true)
                        {
                            xPanderPanelAudioDrive.AudioDrive = removableDrive;
                        }
                    }
                }
            }
        }

        private void RadioClick(object sender, EventArgs e)
        {
            try
            {
                if (this.m_mnuMusik_Radio.Checked == false)
                {
                    if (this.TrackCollectionByFilterSettings != null)
                    {
                        this.m_playerManager.PlayTracks(this.TrackCollectionByFilterSettings, PlayMode.Random);
                        this.m_mnuMusik_Radio.Checked = this.m_btnMusic_Radio.Checked = true;
                    }
                }
                else
                {
                    StopPlayingRadio();
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                StopPlayingRadio();
            }
        }

        private void StopPlayingRadio()
        {
            this.m_mnuMusik_Radio.Checked = this.m_btnMusic_Radio.Checked = false;
            this.m_btnMusic_CoverFlow.Enabled = this.m_mnuView_Coverflow.Enabled = false;
            this.m_playerManager.Stop();
        }

        private void PlayCDClick(object sender, EventArgs e)
        {
            StopPlayingRadio();
            if (this.CurrentAlbum != null && this.CurrentAlbum.Tracks != null)
            {
                CTrackCollection trackCollection = new CTrackCollection(this.CurrentAlbum.Tracks.Length);
                foreach (CTrack track in this.CurrentAlbum.Tracks)
                {
                    if (String.IsNullOrEmpty(track.FileFullName) == false)
                    {
                        trackCollection.Add(track);
                    }
                }
                if (trackCollection.Count > 0)
                {
                    try
                    {
                        this.m_playerManager.PlayTracks(trackCollection, BSE.Platten.Audio.PlayMode.CD);
                    }
                    catch (Exception exception)
                    {
                        GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }

        private void PlaySongClick(object sender, EventArgs e)
        {
            StopPlayingRadio();
            ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
            if (toolStripMenuItem != null)
            {
                CTrack track = toolStripMenuItem.Tag as CTrack;
                if (track != null)
                {
                    try
                    {
                        this.m_playerManager.PlayTrack(track, BSE.Platten.Audio.PlayMode.Song);
                    }
                    catch (Exception exception)
                    {
                        GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }

        private void CoverFlowClick(object sender, EventArgs e)
        {
            using (BSE.CoverFlow.WPFLib.WindowCoverFlow windowCoverFlow = new BSE.CoverFlow.WPFLib.WindowCoverFlow())
            {
                WindowInteropHelper windowInteropHelper = new WindowInteropHelper(windowCoverFlow);
                windowInteropHelper.Owner = this.Handle;
                windowCoverFlow.WindowState = System.Windows.WindowState.Maximized;
                windowCoverFlow.WindowStyle = System.Windows.WindowStyle.None;
                windowCoverFlow.ShowInTaskbar = false;
                windowCoverFlow.ConnectionString = this.ConnectionString;
                windowCoverFlow.PlayerManager = this.m_playerManager;

                try
                {
                    windowCoverFlow.LoadCovers();
                    windowCoverFlow.ShowDialog();
                }
                catch (Exception exception)
                {
                    GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void GetCovers()
        {
            CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.ConnectionString);
            try
            {
                CAlbum[] albumsWithCovers = tunesBusinessObject.GetNewestAlbumsWithCovers(20);
                this.m_covers.LoadCoverBoxes(albumsWithCovers);
                this.m_covers.Invalidate();
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void PlayerManagerPlayerPlays(object sender, BSE.Platten.Audio.PlayerManagerStatusChangedEventArgs e)
        {
            this.m_btnMusic_CoverFlow.Enabled = this.m_mnuView_Coverflow.Enabled = false;
            if ((this.m_playerManager.PlayMode == PlayMode.Playlist)
                || (this.m_playerManager.PlayMode == PlayMode.Random))
            {
                this.m_btnMusic_CoverFlow.Enabled = this.m_mnuView_Coverflow.Enabled = true;
            }
        }

        private void PlayerManagerTrackChanged(object sender, BSE.Platten.Audio.PlayerManagerStatusChangedEventArgs e)
        {
            this.m_ssMain.SetTickerText(e.CurrentTrack, e.PlayMode);
            this.m_history.UpdateHistory(e.CurrentTrack, e.PlayMode);
        }

        private void PlayerManagerStopped(object sender, BSE.Platten.Audio.PlayerManagerStatusChangedEventArgs e)
        {
            if (this.InvokeRequired == true)
            {
                this.Invoke(new DelegateStopRadio(StopPlayingRadio));
            }
            else
            {
                StopPlayingRadio();
            }
        }

        private void PlayerManagerClosed(object sender, BSE.Platten.Audio.PlayerManagerStatusChangedEventArgs e)
        {
            if (e.PlayMode == BSE.Platten.Audio.PlayMode.Random)
            {
                StopPlayingRadio();
            }
        }

        private void TreeInterpretenTitelAfterSelect(object sender, TreeInterpretenTitelEventArgs e)
        {
            GetSelectedTitle(e.TitelId, false);
        }

        private void TreeFavoritesClick(object sender, TreeViewFavoritesEventArgs e)
        {
            ListMode listMode = e.ListMode;
            switch (listMode)
            {
                case ListMode.Singlecharts:
                case ListMode.Albumcharts:
                    GetSelectedTitle(e.Id, true);
                    break;
                case ListMode.Playlists:
                    this.m_playList.SetPlaylist(e.Id);
                    PlayListEditorClick(sender, e);
                    break;
            }
        }

        private void TreeFavoritesPlayListEvent(object sender, TreeViewFavoritesEventArgs e)
        {
            switch (e.TreeViewListEvent)
            {
                case TreeViewFavorites.TreeViewListEvent.AddPlayList:
                    this.m_playList.SetNewPlayList();
                    break;
                case TreeViewFavorites.TreeViewListEvent.DeletePlaylist:
                    this.m_playList.SetDeletePlayList();
                    break;
                case TreeViewFavorites.TreeViewListEvent.PlayTracks:
                    this.m_playList.SetPlayTracks();
                    break;
                case TreeViewFavorites.TreeViewListEvent.PlayRandomTracks:
                    this.m_playList.SetPlayRandomTracks();
                    break;
            }
        }

        private void PanelListControlRemoved(object sender, ControlEventArgs e)
        {
            XPanderPanel xpanderPanel = e.Control as XPanderPanel;
            if (xpanderPanel != null)
            {
                ToolStripMenuItem menuItem = xpanderPanel.Tag as ToolStripMenuItem;
                if (menuItem != null)
                {
                    menuItem.Checked = false;
                }
                XPanderPanelAudioDrive xPanderPanelAudioDrive = xpanderPanel as XPanderPanelAudioDrive;
                if (xPanderPanelAudioDrive != null)
                {
                    //Activates the next control. When treeview or listview has the focus,
                    //a handle exeption rises at disposing
                    this.m_tscMain.SelectNextControl(xPanderPanelAudioDrive, false, true, true, true);
                    xPanderPanelAudioDrive.Dispose();
                }
            }
        }

        private void CoversCoverClick(object sender, BSE.Platten.Covers.CoverBoxClickEventArgs e)
        {
            GetSelectedTitle(e.TitelId, true);
        }

        private void AlbumSelecting(object sender, AlbumSelectEventArgs e)
        {
            GetSelectedTitle(e.TitelId, true);
        }

        private void ClipBoardAlbumSelected(object sender, PlayListEventArgs e)
        {
            if (e.Track != null)
            {
                GetSelectedTitle(e.Track.TitelId, true);
            }
        }

        private void PlayListInserted(object sender, PlayListEventArgs e)
        {
            CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.m_strConnection);
            CPlaylist[] playLists = tunesBusinessObject.GetPlaylistsByUserName(this.m_environment.UserName);
            this.m_treeFavorites.SetPlayLists(playLists, e.PlayList);
            if (this.m_pnlPlayList.Visible == false)
            {
                this.m_pnlPlayList.Visible = true;
            }
            if (this.m_pnlPlayList.Expand == false)
            {
                this.m_plstMain.Expand(this.m_pnlPlayList);
            }
        }

        private void PlayListDeleted(object sender, PlayListEventArgs e)
        {
            CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.m_strConnection);
            CPlaylist[] playLists = tunesBusinessObject.GetPlaylistsByUserName(this.m_environment.UserName);
            this.m_treeFavorites.SetPlayLists(playLists);
        }

        private void GetSelectedTitle(int iTitelid, bool bWithTreeEvent)
        {
            Cursor.Current = Cursors.WaitCursor;
            CurrentAlbumQueryData currentAlbumQueryData = new CurrentAlbumQueryData
            {
                ConnectionString = this.ConnectionString,
                TitelId = iTitelid
            };

            this.PerformTreeEvent = bWithTreeEvent;

            BackgroundWorker backgroundWorker = new BackgroundWorker();
            backgroundWorker.DoWork += new DoWorkEventHandler(BackgroundWorkerCurrentAlbumDoWork);
            backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorkerCurrentAlbumRunWorkerCompleted);
            backgroundWorker.RunWorkerAsync(currentAlbumQueryData);
        }

        private void BackgroundWorkerCurrentAlbumDoWork(object sender, DoWorkEventArgs e)
        {
            CurrentAlbumQueryData newAlbumData = e.Argument as CurrentAlbumQueryData;
            if (newAlbumData != null)
            {
                if (string.IsNullOrEmpty(newAlbumData.ConnectionString) == false)
                {
                    CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(newAlbumData.ConnectionString);
                    try
                    {
                        e.Result = tunesBusinessObject.GetAlbumById(newAlbumData.TitelId);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
        }

        private void BackgroundWorkerCurrentAlbumRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            using (BackgroundWorker backgroundWorker = sender as BackgroundWorker)
            {
                if (backgroundWorker != null)
                {
                    backgroundWorker.DoWork -= new DoWorkEventHandler(BackgroundWorkerCurrentAlbumDoWork);
                    backgroundWorker.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(BackgroundWorkerCurrentAlbumRunWorkerCompleted);

                    if (e.Error != null)
                    {
                        GlobalizedMessageBox.Show(this, e.Error.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        this.CurrentAlbum = e.Result as CAlbum;
                        if (this.CurrentAlbum != null)
                        {
                            this.m_mnuMusik_Tracks.DropDownItems.Clear();
                            this.m_btnMusic_Tracks.DropDownItems.Clear();
                            if (this.CurrentAlbum.Tracks != null)
                            {
                                string strAudioHomeDirectory = CAlbum.GetAudioHomeDirectory(this.m_environment);
                                foreach (BSE.Platten.BO.CTrack track in this.CurrentAlbum.Tracks)
                                {
                                    if (string.IsNullOrEmpty(track.FileFullName) == false)
                                    {
                                        track.ThumbNail = this.CurrentAlbum.Thumbnail;
                                        if (string.IsNullOrEmpty(track.FileName) == false)
                                        {
                                            track.FileFullName = strAudioHomeDirectory + track.FileName;
                                        }
                                    }
                                }

                                if (this.CurrentAlbum.Tracks.Length > 0)
                                {
                                    this.m_mnuMusik.Enabled = this.m_tsMusic.Enabled = true;
                                    this.m_albumProperties.SetCurrentAlbum(this.CurrentAlbum);
                                    this.m_mnuMusik_Tracks.DropDownItems.AddRange(GetToolStripMenuItemsLieder());
                                    this.m_btnMusic_Tracks.DropDownItems.AddRange(GetToolStripMenuItemsLieder());

                                    if (this.PerformTreeEvent == true)
                                    {
                                        this.PerformTreeEvent = false;
                                        this.m_treeInterpretenTitel.SetSelectedChildNode(this.CurrentAlbum.AlbumId);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.Cursor = Cursors.Default;
        }

        private ToolStripMenuItem[] GetToolStripMenuItemsLieder()
        {
            ToolStripMenuItem[] mnuLieder = null;
            if (this.CurrentAlbum.Tracks != null)
            {
                System.Collections.ArrayList aLieder
                    = new System.Collections.ArrayList(this.CurrentAlbum.Tracks.Length);
                foreach (CTrack track in this.CurrentAlbum.Tracks)
                {
                    ToolStripMenuItem mnuLied = new ToolStripMenuItem();
                    mnuLied.Image = this.m_imgSong;
                    if (track.Duration.Ticks > 0)
                    {
                        mnuLied.Text = string.Format(
                            CultureInfo.CurrentUICulture,
                            "{0} {1} ({2})",
                            track.TrackNumber.ToString("00", CultureInfo.CurrentUICulture),
                            track.Title.Replace("&", "&&"),
                            track.Duration.ToString());
                    }
                    else
                    {
                        mnuLied.Text = string.Format(
                            CultureInfo.CurrentUICulture,
                            "{0} {1}",
                            track.TrackNumber.ToString("00", CultureInfo.CurrentUICulture),
                            track.Title.Replace("&", "&&"));
                    }
                    if (String.IsNullOrEmpty(track.FileFullName) == true)
                    {
                        mnuLied.Enabled = false;
                    }
                    else
                    {
                        mnuLied.Tag = track;
                        mnuLied.Click += new EventHandler(PlaySongClick);
                    }
                    aLieder.Add(mnuLied);
                }
                if (aLieder.Count > 0)
                {
                    mnuLieder = new ToolStripMenuItem[aLieder.Count];
                    aLieder.CopyTo(mnuLieder);
                }
            }
            return mnuLieder;
        }

        private void StartRefreshControlsThread()
        {
            this.m_threadControlRefresh = null;
            this.m_threadControlRefresh = new System.Threading.Thread(
                new System.Threading.ThreadStart(this.InvokeRefreshControlsThread));
            this.m_threadControlRefresh.Start();
        }

        private void InvokeRefreshControlsThread()
        {
            System.Threading.Thread.Sleep(100);
            this.Invoke(new DelegateRefreshControls(this.RefreshControls));
            this.m_threadControlRefresh.Abort();
            this.m_threadControlRefresh.Join();
        }

        private void RefreshControls()
        {
            CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.ConnectionString);
            try
            {
                //Lade Covers
                GetCovers();

                //l�dt Alben und Genres in den Tree
                CInterpretData[] interpretsAndAlbums = tunesBusinessObject.GetInterpretsAndAlbums();
                this.m_treeInterpretenTitel.SetInterpretsAndAlbums(interpretsAndAlbums);

                //l�dt den TreeviewGenreInterpretsAndTitles
                CGenreData[] genreWithAlbums = tunesBusinessObject.GetGenresWithAlbums();
                this.m_treeInterpretenTitel.SetGenresWithAlbums(genreWithAlbums);

                //l�dt den TreeviewYearInterpretsAndTitles
                CYearData[] yearsWithAlbums = tunesBusinessObject.GetYearsWithAlbums();
                this.m_treeInterpretenTitel.SetYearsWithAlbums(yearsWithAlbums);

                //l�dt die Benutzerhistory
                SortableCollection<CHistoryTrack> trackCollection = tunesBusinessObject.GetHistoryTrackCollection(this.m_environment.UserName);
                this.m_history.UpdateHistory(trackCollection);

                //Lied Favorites
                CFavorite[] singleFavorites
                    = tunesBusinessObject.GetFavoritesByFavoritId(10, (int)EPlayerApp.Lied, this.m_environment.UserName);
                this.m_treeFavorites.SetFavorites(singleFavorites, ListMode.Singlecharts);

                //CD Favorites
                CFavorite[] albumFavorites
                    = tunesBusinessObject.GetFavoritesByFavoritId(10, (int)EPlayerApp.CD, this.m_environment.UserName);
                this.m_treeFavorites.SetFavorites(albumFavorites, ListMode.Albumcharts);

                //Playlisten
                CPlaylist[] playLists = tunesBusinessObject.GetPlaylistsByUserName(this.m_environment.UserName);
                this.m_treeFavorites.SetPlayLists(playLists);

                //Filter
                BSE.Platten.Tunes.Filters.FilterMain filter
                    = new BSE.Platten.Tunes.Filters.FilterMain();
                BSE.Platten.Tunes.Filters.FilterConfiguration filterConfiguration
                    = filter.GetFilterConfiguration(this.m_environment);
                this.m_mnuFilter_Properties.Text = filterConfiguration.FilterName;
                this.TrackCollectionByFilterSettings = filter.GetTracksByFilterSettings(this.m_environment, (FilterSettings)filterConfiguration);
                if (this.TrackCollectionByFilterSettings.Count > 0)
                {
                    int iIndex = this.TrackCollectionByFilterSettings.GetRandomIndex();
                    CTrack currentTrack = this.TrackCollectionByFilterSettings[iIndex] as CTrack;
                    if (currentTrack != null)
                    {
                        int iStartTitelId = currentTrack.TitelId;
                        GetSelectedTitle(iStartTitelId, true);
                    }
                }

                this.m_mnuExtras_Statistik.Enabled = true;
                this.m_search.Environment = this.m_environment;
                this.m_playList.Environment = this.m_environment;
                this.m_history.Environment = this.m_environment;
                this.m_clipBoard.Environment = this.m_environment;
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private CTunesSettingsData LoadSettings()
        {
            CTunesSettingsData tunesSettingsData = new CTunesSettingsData();
            //-------------------------------------------------------------------------------
            // Default Values
            //-------------------------------------------------------------------------------
            tunesSettingsData.WidthPnlLeft = this.m_pnlLeft.Width;
            tunesSettingsData.PanelClipBoardExpand = true;
            tunesSettingsData.PanelClipBoardVisible = true;
            tunesSettingsData.PanelClipBoardBounds = this.m_pnlRight.ClientRectangle;
            tunesSettingsData.PanelCoverExpand = true;
            tunesSettingsData.PanelCoverBounds = this.m_pnlCovers.ClientRectangle;
            tunesSettingsData.PanelMyListsExpand = true;
            tunesSettingsData.PanelMyListsBounds = this.m_pnlMyLists.ClientRectangle;
            tunesSettingsData.VisiblePnlPlayList = true;
            tunesSettingsData.VisiblePnlSearch = true;
            tunesSettingsData = tunesSettingsData.LoadSettings(this, this.m_settings, tunesSettingsData) as CTunesSettingsData;
            if (tunesSettingsData != null)
            {
                //-------------------------------------------------------------------------------
                // Background Image des Contents
                //-------------------------------------------------------------------------------
                this.ContentPanel.BackgroundImage = tunesSettingsData.BackgroundImage;
                if (this.ContentPanel.BackgroundImage != null)
                {
                    this.ContentPanel.BackgroundImageLayout = ImageLayout.Tile;
                }
                //-------------------------------------------------------------------------------
                // Breite des linken Panels
                //-------------------------------------------------------------------------------
                if (tunesSettingsData.WidthPnlLeft > 0)
                {
                    this.m_pnlLeft.Width = tunesSettingsData.WidthPnlLeft;
                }
                //-------------------------------------------------------------------------------
                // Breite des rechten Panels
                //-------------------------------------------------------------------------------
                bool bPanelClipBoardExpand = tunesSettingsData.PanelClipBoardExpand;
                this.m_pnlRight.Visible = tunesSettingsData.PanelClipBoardVisible;
                if (bPanelClipBoardExpand == false)
                {
                    this.m_pnlRight.Width = tunesSettingsData.PanelClipBoardBounds.Width;
                    this.m_pnlRight.Expand = bPanelClipBoardExpand;
                }
                else
                {
                    this.m_pnlRight.Width = tunesSettingsData.PanelClipBoardBounds.Width;
                }

                bool bPanelCoverExpand = tunesSettingsData.PanelCoverExpand;
                if (bPanelCoverExpand == false)
                {
                    this.m_pnlCovers.Height = tunesSettingsData.PanelCoverBounds.Height;
                    this.m_pnlCovers.Expand = bPanelCoverExpand;
                }
                else
                {
                    this.m_pnlCovers.Height = tunesSettingsData.PanelCoverBounds.Height;
                }
                //-------------------------------------------------------------------------------
                // H�he des MyLists Panels
                //-------------------------------------------------------------------------------
                bool bPanelMyListsExpand = tunesSettingsData.PanelMyListsExpand;
                if (bPanelMyListsExpand == false)
                {
                    this.m_pnlMyLists.Height = tunesSettingsData.PanelMyListsBounds.Height;
                    this.m_pnlMyLists.Expand = bPanelMyListsExpand;
                }
                else
                {
                    this.m_pnlMyLists.Height = tunesSettingsData.PanelMyListsBounds.Height;
                }
                //-------------------------------------------------------------------------------
                // Visibility des PlayList Panels
                //-------------------------------------------------------------------------------
                if (tunesSettingsData.VisiblePnlPlayList == false)
                {
                    this.m_plstMain.Controls.Remove(this.m_pnlPlayList);
                }
                //-------------------------------------------------------------------------------
                // Visibility des Search Panels
                //-------------------------------------------------------------------------------
                if (tunesSettingsData.VisiblePnlSearch == false)
                {
                    this.m_plstMain.Controls.Remove(this.m_pnlSearch);
                }
            }

            return tunesSettingsData;
        }

        private void SaveSettings()
        {
            CTunesSettingsData tunesSettingsData = new CTunesSettingsData();
            tunesSettingsData.BackgroundImage = this.ContentPanel.BackgroundImage;
            if ((this.WindowState == FormWindowState.Normal) ||
                (this.WindowState == FormWindowState.Maximized))
            {
                tunesSettingsData.WidthPnlLeft = this.m_pnlLeft.Width;

                tunesSettingsData.PanelClipBoardVisible = this.m_pnlRight.Visible;
                bool bPanelClipBoardExpand = this.m_pnlRight.Expand;
                tunesSettingsData.PanelClipBoardExpand = bPanelClipBoardExpand;
                if (bPanelClipBoardExpand == true)
                {
                    tunesSettingsData.PanelClipBoardBounds = this.m_pnlRight.ClientRectangle;
                }
                else
                {
                    tunesSettingsData.PanelClipBoardBounds = this.m_pnlRight.RestoreBounds;
                }

                bool bPanelCoverExpand = this.m_pnlCovers.Expand;
                tunesSettingsData.PanelCoverExpand = bPanelCoverExpand;
                if (bPanelCoverExpand == true)
                {
                    tunesSettingsData.PanelCoverBounds = this.m_pnlCovers.ClientRectangle;
                }
                else
                {
                    tunesSettingsData.PanelCoverBounds = this.m_pnlCovers.RestoreBounds;
                }

                bool bPanelMyListsExpand = this.m_pnlMyLists.Expand;
                tunesSettingsData.PanelMyListsExpand = bPanelMyListsExpand;
                if (bPanelMyListsExpand == true)
                {
                    tunesSettingsData.PanelMyListsBounds = this.m_pnlMyLists.ClientRectangle;
                }
                else
                {
                    tunesSettingsData.PanelMyListsBounds = this.m_pnlMyLists.RestoreBounds;
                }
            }
            if (this.m_pnlPlayList.Parent != null)
            {
                tunesSettingsData.VisiblePnlPlayList = true;
            }
            if (this.m_pnlSearch.Parent != null)
            {
                tunesSettingsData.VisiblePnlSearch = true;
            }
            tunesSettingsData.SaveSettings(this, this.m_settings, tunesSettingsData);
        }

        /// <summary>
        /// Used for querying the current album data
        /// </summary>
        internal class CurrentAlbumQueryData
        {
            /// <summary>
            /// Gets or sets the connection string
            /// </summary>
            public string ConnectionString
            {
                get;
                set;
            }
            /// <summary>
            /// Gets or sets the TitelId for the album.
            /// </summary>
            public int TitelId
            {
                get;
                set;
            }
        }

        #endregion


    }

    public class CTunesSettingsData : BaseFormSettingsData
    {
        #region FieldsPrivate
        private bool m_bPanelClipBoardExpand;
        private bool m_bPanelClipBoardVisible;
        private Rectangle m_PanelClipBoardBounds;
        private int m_iWidthPnlLeft;
        private bool m_bPanelCoverExpand;
        private Rectangle m_PanelCoverBounds;
        private bool m_bPanelMyListsExpand;
        private Rectangle m_PanelMyListsBounds;
        private bool m_bVisiblePnlPlayList;
        private bool m_bVisiblePnlSearch;
        #endregion

        #region Properties
        /// <summary>
        /// Breite des linken Panels
        /// </summary>
        public int WidthPnlLeft
        {
            get { return this.m_iWidthPnlLeft; }
            set { this.m_iWidthPnlLeft = value; }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the Panel ClipBoard is expanded.
        /// </summary>
        public bool PanelClipBoardExpand
        {
            get { return this.m_bPanelClipBoardExpand; }
            set { this.m_bPanelClipBoardExpand = value; }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the Panel ClipBoard is visible.
        /// </summary>
        public bool PanelClipBoardVisible
        {
            get { return this.m_bPanelClipBoardVisible; }
            set { this.m_bPanelClipBoardVisible = value; }
        }
        /// <summary>
        /// Gets or sets the size and location of the Panel ClipBoard.
        /// </summary>
        public Rectangle PanelClipBoardBounds
        {
            get { return this.m_PanelClipBoardBounds; }
            set { this.m_PanelClipBoardBounds = value; }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the Panel Covers is expanded.
        /// </summary>
        public bool PanelCoverExpand
        {
            get { return this.m_bPanelCoverExpand; }
            set { this.m_bPanelCoverExpand = value; }
        }
        /// <summary>
        /// Gets or sets the size and location of the Panel Covers.
        /// </summary>
        public Rectangle PanelCoverBounds
        {
            get { return this.m_PanelCoverBounds; }
            set { this.m_PanelCoverBounds = value; }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the Panel MyLists is expanded.
        /// </summary>
        public bool PanelMyListsExpand
        {
            get { return this.m_bPanelMyListsExpand; }
            set { this.m_bPanelMyListsExpand = value; }
        }
        /// <summary>
        /// Gets or sets the size and location of the Panel MyLists.
        /// </summary>
        public Rectangle PanelMyListsBounds
        {
            get { return this.m_PanelMyListsBounds; }
            set { this.m_PanelMyListsBounds = value; }
        }
        /// <summary>
        /// Visibility des PlayList Panels
        /// </summary>
        public bool VisiblePnlPlayList
        {
            get { return this.m_bVisiblePnlPlayList; }
            set { this.m_bVisiblePnlPlayList = value; }
        }
        /// <summary>
        /// Visibility des Search Panels
        /// </summary>
        public bool VisiblePnlSearch
        {
            get { return this.m_bVisiblePnlSearch; }
            set { this.m_bVisiblePnlSearch = value; }
        }
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions