public FormTrackMetadata(TrackMetadata aMetadata)
 {
     InitializeComponent();
     this.Icon            = Icon.FromHandle(Properties.Resources.Track.GetHicon());
     textBoxMetadata.Text = aMetadata.ToString();
     iAlbumArtFileName    = aMetadata.AlbumArtPath;
     Refresh();
     pictureBoxAlbumArt.Select();
 }
Beispiel #2
0
        private void CreatePresets()
        {
            int currentPreset = 0;

            foreach (TreeNode node in iUserCreatedNodes) // bookmarks
            {
                foreach (TreeNode subNode in node.Nodes) // presets
                {
                    currentPreset++;
                    iProgressChanged(currentPreset * 100 / iPresetCount, "Creating preset " + currentPreset + " of " + iPresetCount, Progress.State.eInProgress);
                    Playlist playlist = new Playlist(Path.GetFullPath(iPresetDir + currentPreset.ToString() + ".dpl"));
                    if (subNode.Nodes.Count <= MediaCollection.kPlaylistMaxTracks || !iHelper.OptionPageSetup.Randomize)
                    {
                        // if playlist too large, use first 1000 tracks
                        uint trackCount = 0;
                        foreach (TreeNode track in subNode.Nodes) // tracks
                        {
                            TrackMetadata   data      = (TrackMetadata)track.Tag;
                            Upnp.upnpObject upnpTrack = data.GetUpnpMusicTrack(iHelper.OptionPageSetup, iHelper);
                            if (upnpTrack != null && upnpTrack is Upnp.musicTrack)
                            {
                                trackCount++;
                                if (trackCount > MediaCollection.kPlaylistMaxTracks)
                                {
                                    break; // only save max playlist tracks
                                }
                                playlist.Insert(playlist.Tracks.Count, upnpTrack);
                            }
                        }
                    }
                    else
                    {
                        // if playlust too large, use random 1000 tracks
                        List <int> randomPlaylist = RandomPlaylist(subNode.Nodes.Count);
                        for (int i = 0; i < MediaCollection.kPlaylistMaxTracks; i++)
                        {
                            TreeNode        track     = subNode.Nodes[randomPlaylist[i]];
                            TrackMetadata   data      = (TrackMetadata)track.Tag;
                            Upnp.upnpObject upnpTrack = data.GetUpnpMusicTrack(iHelper.OptionPageSetup, iHelper);
                            if (upnpTrack != null && upnpTrack is Upnp.musicTrack)
                            {
                                playlist.Insert(playlist.Tracks.Count, upnpTrack);
                            }
                        }
                    }
                    playlist.Save();
                }
            }
        }
Beispiel #3
0
        private void CreateCollection()
        {
            try {
                List <string>        tagsArtist           = new List <string>();
                List <string>        tagsAlbum            = new List <string>();
                List <string>        tagsGenre            = new List <string>();
                List <string>        tagsComposer         = new List <string>();
                List <string>        tagsConductor        = new List <string>();
                List <string>        tagsArtistAlbum      = new List <string>();
                List <string>        tagsArtistAz         = new List <string>();
                List <string>        tagsTitleAz          = new List <string>();
                List <string>        tagsAlbumArtistAlbum = new List <string>();
                List <string>        tagsAlbumArtist      = new List <string>();
                List <TrackMetadata> trackList            = new List <TrackMetadata>();

                iCurrent = 0;
                string directory = iCollectionDir;
                if (iQuickScanLocation != null)
                {
                    directory = iQuickScanLocation;
                }
                // get all relevant audio files
                iProgressChanged(0, "Creating File List", Progress.State.eInProgress);
                DirectoryInfo   di = new DirectoryInfo(directory);
                List <FileInfo> fi = new List <FileInfo>();
                fi.AddRange(di.GetFiles("*.*", SearchOption.AllDirectories));
                iProgressChanged(0, "Sorting File List", Progress.State.eInProgress);
                fi = fi.FindAll(delegate(FileInfo f) {
                    return(IsAudioFile(f));
                });
                iTotal += fi.Count;
                foreach (FileInfo f in fi)
                {
                    // build the complete file list for this dir
                    try {
                        string        file      = f.FullName;
                        TrackMetadata trackData = new TrackMetadata(file, iHelper);
                        trackList.Add(trackData);

                        tagsArtist.Add(MoveTheFromStart(trackData.Artist));
                        tagsAlbum.Add(MoveTheFromStart(trackData.Album));
                        tagsGenre.Add(MoveTheFromStart(trackData.Genre));
                        tagsComposer.Add(MoveTheFromStart(trackData.Composer));
                        tagsConductor.Add(MoveTheFromStart(trackData.Conductor));
                        tagsAlbumArtist.Add(MoveTheFromStart(trackData.AlbumArtist));
                        tagsAlbumArtistAlbum.Add(MoveTheFromStart(trackData.AlbumArtist) + "/" + trackData.Album);
                        if (trackData.IsCompilation)
                        {
                            // for Artist-Album sort type, always label compilation album artists as various
                            // the track by track artist metadata will remain in tact
                            tagsArtistAlbum.Add(TrackMetadata.kCompilationsArtist + "/" + trackData.Album);
                        }
                        else
                        {
                            tagsArtistAlbum.Add(MoveTheFromStart(trackData.Artist) + "/" + trackData.Album);
                        }

                        string trim = MoveTheFromStart(trackData.Artist).Trim(); // insure no whitespace at start
                        tagsArtistAz.Add(trim);                                  // leave full artist until sorted, then drop to single letter

                        trim = MoveTheFromStart(trackData.Title).Trim();         // insure no whitespace at start
                        tagsTitleAz.Add(trim);                                   // leave full title until sorted, then drop to single letter
                    }
                    catch (System.IO.PathTooLongException) {
                        try {
                            Linn.UserLog.WriteLine("WARNING: File ignored (path too long): " + f);
                        }
                        catch {
                            Linn.UserLog.WriteLine("WARNING: File ignored (path too long)");
                        }
                    }

                    // update the progress
                    iCurrent++;
                    iProgressChanged(iCurrent * 100 / iTotal, "Parsing: " + iCurrent + " of " + iTotal, Progress.State.eInProgress);
                }

                // initialise all nodes
                TreeNode nodeNewTracks        = new TreeNode(SortTypeToString(SortType.eNew));
                TreeNode nodeArtistAlbum      = new TreeNode(SortTypeToString(SortType.eArtistAlbum));
                TreeNode nodeArtist           = new TreeNode(SortTypeToString(SortType.eArtist));
                TreeNode nodeAlbum            = new TreeNode(SortTypeToString(SortType.eAlbum));
                TreeNode nodeGenre            = new TreeNode(SortTypeToString(SortType.eGenre));
                TreeNode nodeComposer         = new TreeNode(SortTypeToString(SortType.eComposer));
                TreeNode nodeConductor        = new TreeNode(SortTypeToString(SortType.eConductor));
                TreeNode nodeArtistAz         = new TreeNode(SortTypeToString(SortType.eArtistAz));
                TreeNode nodeTitleAz          = new TreeNode(SortTypeToString(SortType.eTitleAz));
                TreeNode nodeAlbumArtistAlbum = new TreeNode(SortTypeToString(SortType.eAlbumArtistAlbum));
                TreeNode nodeAlbumArtist      = new TreeNode(SortTypeToString(SortType.eAlbumArtist));
                TreeNode nodeAllTracks        = new TreeNode(SortTypeToString(SortType.eAll));

                // create all nodes
                if (iHelper.OptionPageOrganisation.SortTypeArtistAlbum)
                {
                    nodeArtistAlbum = CreateCollectionTag(SortType.eArtistAlbum, tagsArtistAlbum, trackList, nodeAllTracks, nodeNewTracks);
                }
                if (iHelper.OptionPageOrganisation.SortTypeArtist)
                {
                    nodeArtist = CreateCollectionTag(SortType.eArtist, tagsArtist, trackList, nodeAllTracks, nodeNewTracks);
                }
                if (iHelper.OptionPageOrganisation.SortTypeAlbum)
                {
                    nodeAlbum = CreateCollectionTag(SortType.eAlbum, tagsAlbum, trackList, nodeAllTracks, nodeNewTracks);
                }
                if (iHelper.OptionPageOrganisation.SortTypeGenre)
                {
                    nodeGenre = CreateCollectionTag(SortType.eGenre, tagsGenre, trackList, nodeAllTracks, nodeNewTracks);
                }
                if (iHelper.OptionPageOrganisation.SortTypeComposer)
                {
                    nodeComposer = CreateCollectionTag(SortType.eComposer, tagsComposer, trackList, nodeAllTracks, nodeNewTracks);
                }
                if (iHelper.OptionPageOrganisation.SortTypeConductor)
                {
                    nodeConductor = CreateCollectionTag(SortType.eConductor, tagsConductor, trackList, nodeAllTracks, nodeNewTracks);
                }
                if (iHelper.OptionPageOrganisation.SortTypeArtistAz)
                {
                    nodeArtistAz = CreateCollectionTag(SortType.eArtistAz, tagsArtistAz, trackList, nodeAllTracks, nodeNewTracks);
                }
                if (iHelper.OptionPageOrganisation.SortTypeTitleAz)
                {
                    nodeTitleAz = CreateCollectionTag(SortType.eTitleAz, tagsTitleAz, trackList, nodeAllTracks, nodeNewTracks);
                }
                if (iHelper.OptionPageOrganisation.SortTypeAlbumArtistAlbum)
                {
                    nodeAlbumArtistAlbum = CreateCollectionTag(SortType.eAlbumArtistAlbum, tagsAlbumArtistAlbum, trackList, nodeAllTracks, nodeNewTracks);
                }
                if (iHelper.OptionPageOrganisation.SortTypeAlbumArtist)
                {
                    nodeAlbumArtist = CreateCollectionTag(SortType.eAlbumArtist, tagsAlbumArtist, trackList, nodeAllTracks, nodeNewTracks);
                }
                // add all nodes
                iProgressChanged(100, "Updating Music Collection", Progress.State.eInProgress);
                if (iHelper.OptionPageOrganisation.SortTypeNew)
                {
                    iNodeCreated(nodeNewTracks);
                }
                if (iHelper.OptionPageOrganisation.SortTypeArtistAlbum)
                {
                    iNodeCreated(nodeArtistAlbum);
                }
                if (iHelper.OptionPageOrganisation.SortTypeArtist)
                {
                    iNodeCreated(nodeArtist);
                }
                if (iHelper.OptionPageOrganisation.SortTypeAlbum)
                {
                    iNodeCreated(nodeAlbum);
                }
                if (iHelper.OptionPageOrganisation.SortTypeGenre)
                {
                    iNodeCreated(nodeGenre);
                }
                if (iHelper.OptionPageOrganisation.SortTypeComposer)
                {
                    iNodeCreated(nodeComposer);
                }
                if (iHelper.OptionPageOrganisation.SortTypeConductor)
                {
                    iNodeCreated(nodeConductor);
                }
                if (iHelper.OptionPageOrganisation.SortTypeArtistAz)
                {
                    iNodeCreated(nodeArtistAz);
                }
                if (iHelper.OptionPageOrganisation.SortTypeTitleAz)
                {
                    iNodeCreated(nodeTitleAz);
                }
                if (iHelper.OptionPageOrganisation.SortTypeAlbumArtistAlbum)
                {
                    iNodeCreated(nodeAlbumArtistAlbum);
                }
                if (iHelper.OptionPageOrganisation.SortTypeAlbumArtist)
                {
                    iNodeCreated(nodeAlbumArtist);
                }
                if (iHelper.OptionPageOrganisation.SortTypeAll)
                {
                    iNodeCreated(nodeAllTracks);
                }
                if (iHelper.OptionPageOrganisation.IncludeLocalRadio)
                {
                    CreateLocalRadio();
                }
            }
            catch (Exception e) {
                string message = "The following error was encountered:" + Environment.NewLine + Environment.NewLine + e.Message;
                if (e.GetType() == typeof(ThreadAbortException))
                {
                    message = "Operation was cancelled by the user" + Environment.NewLine;
                }
                Linn.UserLog.WriteLine("Scan Failed: " + message);
                iProgressChanged(0, message, Progress.State.eFail);
                return;
            }
            finally {
                iProgressChanged(0, null, Progress.State.eComplete);
            }
            iProgressChanged(iTotal, null, Progress.State.eSuccess);
            Linn.UserLog.WriteLine("Scan complete. Total Tracks Scanned: " + iTotal);
        }
Beispiel #4
0
        private void CreateLocalRadio()
        {
            string        geoLocation    = "Unknown";
            List <string> links          = new List <string>();
            XmlTextReader reader         = null;
            TreeNode      nodeLocalRadio = new TreeNode();

            try {
                iProgressChanged(0, "Adding: Local Radio", Progress.State.eInProgress);
                // generate list of local locations and links based on geoId (from server IP)
                reader = new XmlTextReader(GetHttpResponse(kTuneInLocalQuery).GetResponseStream());
                reader.WhitespaceHandling = WhitespaceHandling.None;
                reader.MoveToContent();
                while (reader.Read())
                {
                    if (reader.Name == "outline" && reader.IsStartElement())
                    {
                        if (reader.GetAttribute("type") == "link")
                        {
                            links.Add(reader.GetAttribute("URL"));
                        }
                        else if (reader.GetAttribute("type") == "audio")
                        {
                            links.Add(kTuneInLocalQuery); // no links - just local stations (will generate 1 preset only)
                            break;
                        }
                    }
                    else if (reader.Name == "title" && reader.IsStartElement()) // geoId location
                    {
                        reader.Read();
                        geoLocation = reader.Value;
                    }
                    else if (reader.Name == "body" && !reader.IsStartElement()) // end tag
                    {
                        break;
                    }
                }
                // create single bookmark node for local radio
                nodeLocalRadio.Text               = "Local Radio (" + geoLocation + ") Powered by TuneIn Radio";
                nodeLocalRadio.Name               = "1";
                nodeLocalRadio.ImageIndex         = 0;
                nodeLocalRadio.SelectedImageIndex = 0;
                int i = 0;
                // generate list of stations based on location based links
                foreach (string link in links)
                {
                    iProgressChanged(i++ *100 / links.Count, "Adding: Local Radio", Progress.State.eInProgress);
                    reader = new XmlTextReader(GetHttpResponse(link).GetResponseStream());
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    reader.MoveToContent();
                    TreeNode nodeAllStations = new TreeNode();
                    while (reader.Read())
                    {
                        if (reader.Name == "outline" && reader.IsStartElement())
                        {
                            if (reader.GetAttribute("type") == "audio")
                            {
                                Upnp.musicTrack upnpTrack = new Upnp.musicTrack();
                                upnpTrack.Title = reader.GetAttribute("text");
                                Upnp.artist artist = new Upnp.artist();
                                artist.Artist = "Powered by TuneIn Radio";
                                upnpTrack.Artist.Add(artist);
                                string info = reader.GetAttribute("subtext") + " (Bitrate: " + reader.GetAttribute("bitrate") + "kbps, Reliability: " + reader.GetAttribute("reliability") + "%)";
                                upnpTrack.Album.Add(info);
                                Upnp.resource res = new Upnp.resource();
                                res.Uri = reader.GetAttribute("URL");
                                upnpTrack.Res.Add(res);
                                upnpTrack.ArtworkUri.Add(reader.GetAttribute("image"));
                                upnpTrack.AlbumArtUri.Add(reader.GetAttribute("image"));
                                TrackMetadata data = new TrackMetadata(upnpTrack);

                                TreeNode item = new TreeNode(data.Title);
                                item.Tag                = data;
                                item.ToolTipText        = data.ToString();
                                item.ImageIndex         = 2;
                                item.SelectedImageIndex = 2;
                                nodeAllStations.Nodes.Add(item);
                            }
                        }
                        else if (reader.Name == "title" && reader.IsStartElement()) // geoId location
                        {
                            reader.Read();
                            geoLocation = reader.Value;
                        }
                        else if (reader.Name == "body" && !reader.IsStartElement()) // end tag
                        {
                            break;
                        }
                    }
                    // create region preset node and add all stations
                    TreeNode subnodeRegion = new TreeNode(geoLocation);
                    subnodeRegion.Name               = "1";
                    subnodeRegion.ImageIndex         = 1;
                    subnodeRegion.SelectedImageIndex = 1;
                    foreach (TreeNode node in nodeAllStations.Nodes)
                    {
                        subnodeRegion.Nodes.Add((TreeNode)node.Clone());
                    }
                    subnodeRegion.ToolTipText = "Count: " + subnodeRegion.Nodes.Count;
                    nodeLocalRadio.Nodes.Add(subnodeRegion);
                }
                nodeLocalRadio.ToolTipText = "Count: " + nodeLocalRadio.Nodes.Count;
                iNodeCreated(nodeLocalRadio);
            }
            catch (Exception e) {
                UserLog.WriteLine("CreateLocalRadio Error: " + e);
            }
            finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Beispiel #5
0
        private void CreateDocument()
        {
            iProgressChanged(0, "Catalog: Initialise", Progress.State.eInProgress);
            string fileName = Path.GetFullPath(iDocumentFilename);

            iTextSharp.text.Document document = null;
            bool pdf = true;

            if (iPageLayoutTrackDetailsLandscape.Checked || iPageLayoutAlbumArtOnlyLandscape.Checked)
            {
                document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate()); // landscape
            }
            else
            {
                document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4); // portrait
            }
            try {
                float fontSizePreset            = 10F;
                float fontSizePresetNumber      = 10F;
                float fontSizeBookmark          = 12F;
                float fontSizePresetLarge       = 32F;
                float fontSizePresetNumberLarge = 48F;

                iTextSharp.text.Font fontPreset            = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, fontSizePreset, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);
                iTextSharp.text.Font fontPresetNumber      = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, fontSizePresetNumber, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);
                iTextSharp.text.Font fontBookmark          = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, fontSizeBookmark, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLUE);
                iTextSharp.text.Font fontPresetLarge       = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, fontSizePresetLarge, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);
                iTextSharp.text.Font fontPresetNumberLarge = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, fontSizePresetNumberLarge, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);

                if (Path.GetExtension(fileName) == ".rtf")
                {
                    iTextSharp.text.rtf.RtfWriter2.GetInstance(document, new FileStream(fileName, FileMode.Create));
                    pdf = false;
                }
                else
                {
                    iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
                    writer.ViewerPreferences = iTextSharp.text.pdf.PdfWriter.PageLayoutSinglePage;
                }
                document.Open();
                if (pdf)
                {
                    document.Add(new iTextSharp.text.Paragraph()); // pdf needs alignment on first page, rtf does not
                }
                // TOC
                bool   firstPage = true;
                string text      = "";
                if (printSectionCheckedListBox.GetItemChecked(0))
                {
                    iProgressChanged(0, "Catalog: TOC", Progress.State.eInProgress);
                    if (iTreeViewPreset.Nodes.Count > 0)
                    {
                        firstPage = false;
                        foreach (TreeNode bookmark in iTreeViewPreset.Nodes)
                        {
                            if (bookmark.Index > 0)
                            {
                                document.Add(new iTextSharp.text.Chunk("\n"));
                            }
                            document.Add(new iTextSharp.text.Phrase(fontSizeBookmark + 2, bookmark.Text, fontBookmark));
                            document.Add(new iTextSharp.text.Paragraph());
                            if (bookmark.Nodes.Count > 0)
                            {
                                foreach (TreeNode preset in bookmark.Nodes)
                                {
                                    document.Add(new iTextSharp.text.Chunk("0" + preset.Name, fontPresetNumber));
                                    text = preset.Text.Replace("/", " / ");
                                    document.Add(new iTextSharp.text.Phrase(fontSizePreset + 2, " - " + text + " (" + preset.Nodes.Count + ")", fontPreset));
                                    document.Add(new iTextSharp.text.Paragraph());
                                }
                            }
                        }
                    }
                }
                // One page per preset (with album covers)
                if (iTreeViewPreset.Nodes.Count > 0)
                {
                    int currItem   = 0;
                    int totalItems = 0;
                    foreach (TreeNode bookmark in iTreeViewPreset.Nodes)
                    {
                        if (printSectionCheckedListBox.GetItemChecked(bookmark.Index + 1))
                        {
                            totalItems += bookmark.Nodes.Count; // only add selected sections to total
                        }
                    }
                    foreach (TreeNode bookmark in iTreeViewPreset.Nodes)
                    {
                        if (bookmark.Nodes.Count > 0 && iPresetCount > 0)
                        {
                            if (!printSectionCheckedListBox.GetItemChecked(bookmark.Index + 1))
                            {
                                // only print selected sections
                                continue;
                            }
                            foreach (TreeNode preset in bookmark.Nodes)
                            {
                                iProgressChanged((++currItem * 100 / totalItems), "Catalog: Page " + currItem + " of " + totalItems, Progress.State.eInProgress);
                                if (!firstPage)
                                {
                                    document.NewPage();
                                }
                                firstPage = false;
                                document.Add(new iTextSharp.text.Chunk("0" + preset.Name, fontPresetNumberLarge));
                                text = preset.Text.Replace("/", " / ");
                                document.Add(new iTextSharp.text.Phrase(fontSizePresetLarge + 2, "   " + text, fontPresetLarge));
                                document.Add(new iTextSharp.text.Paragraph());
                                document.Add(new iTextSharp.text.Chunk("\n"));
                                foreach (TreeNode track in preset.Nodes)
                                {
                                    TrackMetadata data = (TrackMetadata)track.Tag;
                                    if (track.Index == 0)
                                    {
                                        try {
                                            iTextSharp.text.Image albumArt = iTextSharp.text.Image.GetInstance(new Uri(data.AlbumArtPath));

                                            if (iPageLayoutTrackDetailsLandscape.Checked || iPageLayoutAlbumArtOnlyLandscape.Checked)
                                            {
                                                // landscape
                                                if (iPageLayoutTrackDetailsLandscape.Checked)
                                                {
                                                    // include track details
                                                    albumArt.Alignment        = iTextSharp.text.Image.LEFT_ALIGN | iTextSharp.text.Image.TEXTWRAP;
                                                    albumArt.IndentationRight = 36;
                                                    albumArt.ScaleToFit(350, 350);
                                                    // album art not lined up - use all available space for track details
                                                }
                                                else
                                                {
                                                    // no track details
                                                    if (pdf)
                                                    {
                                                        albumArt.ScaleToFit(400, 400);
                                                    }
                                                    else
                                                    {
                                                        albumArt.ScaleToFit(350, 350);        // margins handled slightly differently
                                                    }
                                                    albumArt.SetAbsolutePosition(221, 32.5f); // all album art lined up in document
                                                }
                                            }
                                            else
                                            {
                                                // portrait
                                                if (iPageLayoutTrackDetailsPortrait.Checked)
                                                {
                                                    // include track details
                                                    albumArt.Alignment = iTextSharp.text.Image.LEFT_ALIGN;
                                                    albumArt.ScaleToFit(350, 350);
                                                    // album art not lined up - use all available space for track details
                                                }
                                                else
                                                {
                                                    // no track details
                                                    albumArt.ScaleToFit(525, 525);
                                                    albumArt.SetAbsolutePosition(35, 108.5f); // all album art lined up in document
                                                }
                                            }
                                            document.Add(albumArt);
                                            document.Add(new iTextSharp.text.Chunk("\n"));
                                        }
                                        catch { // invalid or missing album art
                                        }
                                    }
                                    if (iPageLayoutTrackDetailsLandscape.Checked || iPageLayoutTrackDetailsPortrait.Checked)   // include track details
                                    {
                                        string trackInfo = (track.Index + 1).ToString().PadLeft(2, '0');
                                        trackInfo += ".  " + data.Title;
                                        trackInfo += " - " + data.Artist;
                                        trackInfo += " - " + data.Album;
                                        trackInfo += " (" + data.Duration;
                                        trackInfo += ")";
                                        document.Add(new iTextSharp.text.Phrase(fontSizePreset + 2, trackInfo, fontPreset));
                                        document.Add(new iTextSharp.text.Paragraph());
                                    }
                                }
                            }
                        }
                    }
                }
                iProgressChanged(100, "Catalog: Finalise", Progress.State.eInProgress);
            }
            catch (Exception exc) {
                string message = "Unable to create file: " + fileName + Environment.NewLine + exc.Message;
                if (exc.GetType() == typeof(ThreadAbortException))
                {
                    message = "Operation was cancelled by the user" + Environment.NewLine;
                }
                Linn.UserLog.WriteLine("Print Failed: " + message);
                iProgressChanged(0, message, Progress.State.eFail);
                iProgressChanged(100, null, Progress.State.eComplete);
                return;
            }
            finally {
                try {
                    document.Close();
                }
                catch (System.IO.IOException) { // document has no pages
                }
            }

            try {
                if (pdf && iDocumentPagesPerSheet >= kMultiplePagesMin && iDocumentPagesPerSheet <= kMultiplePagesMax)
                {
                    string newName = Path.GetTempPath() + iHelper.Title + System.Guid.NewGuid().ToString() + "MultiplePagesPresets.pdf";
                    MultiplePages(iDocumentFilename, newName, iDocumentPagesPerSheet, (iPageLayoutTrackDetailsLandscape.Checked || iPageLayoutAlbumArtOnlyLandscape.Checked));
                    File.Delete(iDocumentFilename); // delete source file
                    File.Copy(newName, iDocumentFilename);
                }
            }
            catch (Exception e) {
                if (e.GetType() == typeof(ThreadAbortException))
                {
                    string msg = "Operation was cancelled by the user" + Environment.NewLine;
                    Linn.UserLog.WriteLine(msg);
                    iProgressChanged(0, msg, Progress.State.eFail);
                    return;
                }
                else
                {
                    Linn.UserLog.WriteLine("Print (multiple pages) Failed: " + e.Message);
                }
            }
            finally {
                iProgressChanged(100, null, Progress.State.eComplete);
            }

            if (iDocumentPreview)
            {
                try {
                    System.Diagnostics.Process.Start(iDocumentFilename);
                }
                catch (Exception exc) {
                    string docType = "PDF";
                    if (!pdf)
                    {
                        docType = "RTF";
                    }
                    Linn.UserLog.WriteLine("Unable to preview catalog (" + docType + " docuemnt support required): " + exc.Message);
                    MessageBox.Show("Unable to preview catalog: " + docType + " docuemnt support required", "Preview Failed", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
            iProgressChanged(0, null, Progress.State.eSuccess);
            Linn.UserLog.WriteLine("Print complete");
        }
Beispiel #6
0
        private void LoadPlaylistTracks(string aPlaylist, TreeNode aPreset)
        {
            string pl         = Path.GetFullPath(aPlaylist);
            uint   trackCount = 0;

            if (File.Exists(pl))
            {
                iPlaylist.Load(pl);
                if (iPlaylist.Tracks.Count > 0)
                {
                    foreach (Upnp.upnpObject track in iPlaylist.Tracks)
                    {
                        if (track is Upnp.musicTrack)
                        {
                            trackCount++;
                            if (trackCount > MediaCollection.kPlaylistMaxTracks)
                            {
                                return; // only import max playlist tracks
                            }
                            // offer to update IP address (IpV4 only) for imported tracks if it is different from the user setup IP address
                            if (track.Res.Count > 0)
                            {
                                Uri imported = new Uri(track.Res[0].Uri);
                                Uri stored;
                                if (!iHelper.OptionPageSetup.UseHttpServer)
                                {
                                    stored = new Uri(iHelper.OptionPageSetup.CollectionHttpLocation);
                                }
                                else
                                {
                                    stored = new Uri(iHelper.HttpServer.Uri("FILE"));
                                }
                                if (stored.Scheme == Uri.UriSchemeHttp && stored.HostNameType == UriHostNameType.IPv4 && imported.HostNameType == UriHostNameType.IPv4)
                                {
                                    if (stored.Host != imported.Host)
                                    {
                                        if (!iReplaceIpAddressMessage)
                                        {
                                            DialogResult result = MessageBox.Show("Would you like to update the imported IP addresses to match the user configured IP address?" + Environment.NewLine + Environment.NewLine + "User configured IP address: " + stored.Host + Environment.NewLine + "Imported IP address: " + imported.Host + Environment.NewLine, "Import: IP Address Mismatch Detected", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                                            if (result == DialogResult.Yes)
                                            {
                                                iReplaceIpAddress = true;
                                            }
                                            iReplaceIpAddressMessage = true;
                                        }
                                        if (iReplaceIpAddress)
                                        {
                                            track.Res[0].Uri = track.Res[0].Uri.Replace(imported.Host, stored.Host);
                                            if (track.AlbumArtUri.Count > 0)
                                            {
                                                track.AlbumArtUri[0] = track.AlbumArtUri[0].Replace(imported.Host, stored.Host);
                                            }
                                            if (track.ArtworkUri.Count > 0)
                                            {
                                                track.ArtworkUri[0] = track.ArtworkUri[0].Replace(imported.Host, stored.Host);
                                            }
                                        }
                                    }
                                }
                            }

                            // track nodes
                            TrackMetadata data = new TrackMetadata(track);
                            TreeNode      item = new TreeNode(data.Title);
                            item.Tag                = data;
                            item.ToolTipText        = data.ToString();
                            item.ImageIndex         = 2;
                            item.SelectedImageIndex = 2;
                            aPreset.Nodes.Add(item);
                        }
                    }
                }
            }
        }
Beispiel #7
0
 public static string UriPath(HelperKinskyJukebox aHelper)
 {
     return(TrackMetadata.GetUri(Presets.DirectoryPath(aHelper.OptionPageSetup), aHelper));
 }
Beispiel #8
0
        private void CreateManifest()
        {
            XmlDocument document = new XmlDocument();
            XmlElement  manifest = document.CreateElement("linn", "Jukebox", "urn:linn-co-uk/jukebox");

            manifest.SetAttribute("version", kManifestVersion.ToString());

            XmlElement presetImageBase = document.CreateElement("linn", "ImageBase", "urn:linn-co-uk/jukebox");
            string     imageBase       = iHelper.OptionPageSetup.CollectionHttpLocation;

            if (!(imageBase.EndsWith("/") || imageBase.EndsWith("\\")))
            {
                imageBase += "/";
            }
            imageBase = imageBase.Replace("\\", "/");
            XmlText presetImageBaseText = document.CreateTextNode(imageBase);

            presetImageBase.AppendChild(presetImageBaseText);
            manifest.AppendChild(presetImageBase);

            iPresetCount = 0;

            foreach (TreeNode node in iUserCreatedNodes)
            {
                XmlElement bookmark = document.CreateElement("linn", "Bookmark", "urn:linn-co-uk/jukebox");

                XmlElement bookmarkName     = document.CreateElement("linn", "Name", "urn:linn-co-uk/jukebox");
                XmlText    bookmarkNameText = document.CreateTextNode(node.Text);
                bookmarkName.AppendChild(bookmarkNameText);

                XmlElement bookmarkNumber     = document.CreateElement("linn", "Number", "urn:linn-co-uk/jukebox");
                XmlText    bookmarkNumberText = document.CreateTextNode((iPresetCount + 1).ToString());
                bookmarkNumber.AppendChild(bookmarkNumberText);

                bookmark.AppendChild(bookmarkName);
                bookmark.AppendChild(bookmarkNumber);
                manifest.AppendChild(bookmark);

                foreach (TreeNode subNode in node.Nodes)
                {
                    XmlElement preset = document.CreateElement("linn", "Preset", "urn:linn-co-uk/jukebox");

                    XmlElement presetName     = document.CreateElement("linn", "Name", "urn:linn-co-uk/jukebox");
                    XmlText    presetNameText = document.CreateTextNode(subNode.Text);
                    presetName.AppendChild(presetNameText);
                    preset.AppendChild(presetName);

                    XmlElement presetNumber     = document.CreateElement("linn", "Number", "urn:linn-co-uk/jukebox");
                    XmlText    presetNumberText = document.CreateTextNode(subNode.Name);
                    presetNumber.AppendChild(presetNumberText);
                    preset.AppendChild(presetNumber);

                    string imagePath = null;
                    try {
                        TrackMetadata data = (TrackMetadata)subNode.Nodes[0].Tag;
                        string        rel  = data.AlbumArtPath.Remove(0, iHelper.OptionPageSetup.CollectionLocation.Length);
                        if (rel.StartsWith("/") || rel.StartsWith("\\"))
                        {
                            rel = rel.Remove(0, 1);
                        }
                        imagePath = rel.Replace("\\", "/");
                    }
                    catch (Exception) {
                        imagePath = null;
                    }
                    if (imagePath != null && imagePath.Trim() != "")
                    {
                        XmlElement presetImage     = document.CreateElement("linn", "Image", "urn:linn-co-uk/jukebox");
                        XmlText    presetImageText = document.CreateTextNode(imagePath);
                        presetImage.AppendChild(presetImageText);
                        preset.AppendChild(presetImage);
                    }

                    iPresetCount = int.Parse(subNode.Name);
                    manifest.AppendChild(preset);
                }
            }

            document.AppendChild(manifest);
            document.Save(iManifestPath);
        }