Exemple #1
0
        /// <summary>
        /// Persists any pending updates to the database
        /// </summary>
        /// <returns></returns>
        public static bool SaveTitleUpdates()
        {
            System.Data.Linq.ChangeSet changeset = Dao.DBContext.Instance.GetChangeSet();

            // Find actual SQL run to process the update - debugging purposes
            string s = Dao.DBContext.Instance.GetType().GetMethod("GetChangeText", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(Dao.DBContext.Instance, null) as string;

            // updates all the pending image changes
            foreach (object title in changeset.Updates)
            {
                Dao.Title daoTitle = title as Dao.Title;

                if (daoTitle != null)
                {
                    UpdatesImagesForTitle(daoTitle);
                    Dao.TitleDao.UpdateCollectionsForTitle(daoTitle);

                    daoTitle.ResetPercentComplete();
                }
            }

            // todo : solomon : add error handing and logging here
            Dao.DBContext.Instance.SubmitChanges();
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Increments the watch count on the title object
        /// </summary>
        /// <param name="title"></param>
        public static void IncrementWatchedCount(Title title)
        {
            Dao.Title daoTitle = Dao.TitleCollectionDao.GetTitleById(title.Id);
            daoTitle.WatchedCount = (daoTitle.WatchedCount == null) ? 1 : daoTitle.WatchedCount.Value + 1;

            Dao.DBContext.Instance.SubmitChanges();
            title.WatchedCount = daoTitle.WatchedCount.Value;
        }
Exemple #3
0
        /// <summary>
        /// Clears the watched count on the title
        /// </summary>
        /// <param name="title"></param>
        public static void ClearWatchedCount(Title title)
        {
            Dao.Title daoTitle = Dao.TitleCollectionDao.GetTitleById(title.Id);
            daoTitle.WatchedCount = null;

            Dao.DBContext.Instance.SubmitChanges();

            title.WatchedCount = 0;
        }
Exemple #4
0
        /// <summary>
        /// Gets a title by it's id - will include all the actor information
        /// </summary>
        /// <param name="titleId"></param>
        /// <returns></returns>
        public static Title GetTitle(int titleId)
        {
            Dao.Title title = Dao.TitleCollectionDao.GetTitleById(titleId);
            if (title != null)
            {
                return(new Title(title));
            }

            return(null);
        }
        internal bool StartMetadataImport(Title title, MetaDataPluginDescriptor plugin, bool coverArtOnly, string titleNameSearch, string EpisodeName, int? SeasonNo, int? EpisodeNo)
        {
            try
            {
                if (titleNameSearch != null)
                {
                    if (plugin != null)
                    {
                        frmSearchResult searchResultForm = null;

                        if ((plugin.DataProviderCapabilities & MetadataPluginCapabilities.SupportsTVSearch) != 0)
                        {
                            // TV Search
                            if (((title.TitleType & TitleTypes.Season) != 0) ||
                                ((title.TitleType & TitleTypes.TVShow) != 0))
                            {
                                // Only searching for the Show / season
                                searchResultForm = new frmSearchResult(plugin, titleNameSearch, "", 0, 0, true, true);
                            }
                            else
                            {
                                // Searching for an episode
                                searchResultForm = new frmSearchResult(plugin, titleNameSearch, EpisodeName, SeasonNo, EpisodeNo, true, false);
                            }
                        }
                        else
                        {
                            searchResultForm = new frmSearchResult(plugin, titleNameSearch, EpisodeName, SeasonNo, EpisodeNo, false, false);
                        }

                        DialogResult result = searchResultForm.ShowDialog(); // ShowResults(plugin.GetAvailableTitles());
                        if (result == DialogResult.OK)
                        {
                            Cursor = Cursors.WaitCursor;
                            Title searchresult = OMLSDK.SDKUtilities.ConvertOMLSDKTitleToTitle(plugin.PluginDLL.GetTitle(searchResultForm.SelectedTitleIndex));
                            title.MetadataSourceName = plugin.DataProviderName;

                            if (searchresult != null)
                            {
                                if (coverArtOnly)
                                {
                                    title.FrontCoverPath = searchresult.FrontCoverPath;
                                    title.BackCoverPath = searchresult.BackCoverPath;
                                }
                                else
                                {
                                    title.CopyMetadata(searchresult,
                                        OMLEngine.Settings.OMLSettings.MetadataLookupOverwriteExistingDataManual,
                                        OMLEngine.Settings.OMLSettings.MetadataLookupUpdateNameManual,
                                        OMLEngine.Settings.OMLSettings.MetadataLookupOverwriteExistingDataManual);
                                }

                                LoadFanartFromPlugin(plugin, title);

                            }
                            CheckGenresAgainstSupported(title);
                            titleEditor.RefreshEditor();
                            Cursor = Cursors.Default;

                            return true;
                        }
                        else
                            return false;
                    }
                    else
                    {
                        // Preferred lookup. Offload the search to the MetadataSearchManagement class
                        Title searchresult = null;

                        MetadataSearchManagement mds = new MetadataSearchManagement(_metadataPlugins);

                        bool retval = mds.MetadataSearchUsingPreferred(title);

                        if (retval)
                        {
                            // Successful lookup, process
                            LoadFanart(mds.FanArt, title);
                            titleEditor.RefreshEditor();
                            Cursor = Cursors.Default;
                            return true;
                        }
                    }
                }
                Cursor = Cursors.Default;
                return false;

            }
            catch (Exception ex)
            {
                Utilities.DebugLine("[OMLDatabaseEditor] Exception {0}", ex);
                Cursor = Cursors.Default;
                return false;
            }
        }
 private void CheckGenresAgainstSupported(Title title)
 {
     List<String> genreList = new List<String>();
      //           if (Properties.Settings.Default.gsValidGenres != null
      //           && Properties.Settings.Default.gsValidGenres.Count > 0)
     int genreCount = TitleCollectionManager.GetAllGenreMetaDatas().Count();
     if (genreCount > 0)
     {
         //String[] arrGenre = new String[genreCount];
         //Properties.Settings.Default.gsValidGenres.CopyTo(arrGenre, 0);
         genreList.AddRange(from gm in TitleCollectionManager.GetAllGenreMetaDatas()
                                select gm.Name);
         Dictionary<string, string> genreIssuesList = new Dictionary<string, string>();
         Dictionary<string, string> genreChanges = new Dictionary<string, string>();
         foreach (string genre in title.Genres)
         {
             string newGenre = genre.Trim();
             if (!genreList.Contains(newGenre))
             {
                 if (OMLEngine.Settings.SettingsManager.GenreMap_GetMapping(newGenre) != null)
                 {
                     // Mapping already exists for genre
                     genreChanges[genre] = OMLEngine.Settings.SettingsManager.GenreMap_GetMapping(newGenre);
                 }
                 else
                 {
                     if (newGenre.EndsWith("Film", true, CultureInfo.InvariantCulture))
                         newGenre = newGenre.Replace(" Film", "");
                     if (genreList.Contains(newGenre))
                         genreIssuesList[genre] = newGenre;
                     else
                     {
                         string match = genreList.FirstOrDefault(s => s.Split(' ').Intersect(newGenre.Split(' ')).Count() != 0);
                         genreIssuesList[genre] = match;
                     }
                 }
             }
         }
         foreach (string genre in genreChanges.Keys)
         {
             //title.Genres.Remove(genre);
             title.RemoveGenre(genre);
             // Mapping contains empty string when user wants a specific genre ignored.
             if (!String.IsNullOrEmpty(genreChanges[genre]) && !title.Genres.Contains(genreChanges[genre]))
                 title.AddGenre(genreChanges[genre]);
                 //title.Genres.Add(genreChanges[genre]);
         }
         if (genreIssuesList.Keys.Count > 0)
         {
             ResolveGenres resolveGenres = new ResolveGenres(genreIssuesList, title);
             resolveGenres.ShowDialog();
         }
     }
 }
        private bool StartMetadataImport(Title title, MetaDataPluginDescriptor plugin, bool coverArtOnly)
        {
            int? SeasonNo = null;
            int? EpisodeNo = null;

            if (((title.TitleType & TitleTypes.Episode) != 0) ||
            ((title.TitleType & TitleTypes.Season) != 0) ||
            ((title.TitleType & TitleTypes.TVShow) != 0))
            {
                // TV Search
                if (title.SeasonNumber != null) SeasonNo = title.SeasonNumber.Value;
                if (title.EpisodeNumber != null) EpisodeNo = title.EpisodeNumber.Value;
                string Showname = null;

                // Try to find show name be looking up the folder structure.
                Title parenttitle = title;
                while ((parenttitle.TitleType & TitleTypes.Root) == 0)
                {
                    // Get parent
                    parenttitle = parenttitle.ParentTitle;
                    if ((parenttitle.TitleType & TitleTypes.TVShow) != 0)
                    {
                        Showname = parenttitle.Name;
                        break;
                    }
                }

                if (string.IsNullOrEmpty(Showname))
                {
                    // Cannot find a show name in the folder structure
                    return StartMetadataImport(title, plugin, coverArtOnly, title.Name, "", SeasonNo, EpisodeNo);
                }
                else
                {
                    return StartMetadataImport(title, plugin, coverArtOnly, Showname, title.Name, SeasonNo, EpisodeNo);
                }
            }
            else
            {
                // Movie Search
                return StartMetadataImport(title, plugin, coverArtOnly, title.Name, "", SeasonNo, EpisodeNo);
            }
        }
        private void AddCreatedTitle(Title addedTitle, bool RefreshUI)
        {
            _movieList.Add(addedTitle.Id, addedTitle);

            if (RefreshUI)
            {
                if ((addedTitle.TitleType & TitleTypes.AllMedia) != 0)
                {
                    // Added a media
                    PopulateMovieListV2(SelectedTreeRoot);
                    titleEditor.LoadDVD(addedTitle);
                    //ToggleSaveState(true);
                }
                else
                {
                    // Added a folder
                    PopulateMediaTree();
                    if (_mediaTree.ContainsKey(addedTitle.Id))
                    {
                        treeMedia.SelectedNode = _mediaTree[addedTitle.Id];
                    }
                }
            }
        }
        /// <summary>
        /// Clears the watched count on the title
        /// </summary>
        /// <param name="title"></param>
        public static void ClearWatchedCount(Title title)
        {
            Dao.Title daoTitle = Dao.TitleCollectionDao.GetTitleById(title.Id);
            daoTitle.WatchedCount = null;

            Dao.DBContext.Instance.SubmitChanges();

            title.WatchedCount = 0;
        }
 partial void UpdateTitle(Title instance);
Exemple #11
0
 internal static void AddThumbnailImage(Title title, Dao.ImageMapping image)
 {
     Dao.Title daoTitle = Dao.TitleCollectionDao.GetTitleById(title.Id);
     //daoTitle.WatchedCount = (daoTitle.WatchedCount == null) ? 1 : daoTitle.WatchedCount.Value + 1;
     daoTitle.Images.Add(image);
 }
 internal bool StartMetadataImport(Title title, string pluginName, bool coverArtOnly, string titleNameSearch, string EpisodeName, int SeasonNo, int EpisodeNo)
 {
     foreach (MetaDataPluginDescriptor plugin in _metadataPlugins)
     {
         if (plugin.DataProviderName == pluginName) return StartMetadataImport(title, plugin, coverArtOnly, titleNameSearch, EpisodeName, SeasonNo, EpisodeNo);
     }
     return false;
 }
 internal static void AddThumbnailImage(Title title, Dao.ImageMapping image)
 {
     Dao.Title daoTitle = Dao.TitleCollectionDao.GetTitleById(title.Id);
     //daoTitle.WatchedCount = (daoTitle.WatchedCount == null) ? 1 : daoTitle.WatchedCount.Value + 1;
     daoTitle.Images.Add(image);
 }
        public static void RemoveAllPersons(Title title, PeopleRole type)
        {
            var deletePersons = from d in Dao.DBContext.Instance.Persons
                                where d.Role == (byte)type
                                select d;

            foreach (Dao.Person daoperson in deletePersons)
            {
                title.DaoTitle.People.Remove(daoperson);
            }
        }
        /// <summary>
        /// Increments the watch count on the title object
        /// </summary>
        /// <param name="title"></param>
        public static void IncrementWatchedCount(Title title)
        {
            Dao.Title daoTitle = Dao.TitleCollectionDao.GetTitleById(title.Id);
            daoTitle.WatchedCount = (daoTitle.WatchedCount == null) ? 1 : daoTitle.WatchedCount.Value + 1;

            Dao.DBContext.Instance.SubmitChanges();
            title.WatchedCount = daoTitle.WatchedCount.Value;
        }
 /// <summary>
 /// Removes the given title and all it's meta data
 /// </summary>
 /// <param name="titleId"></param>
 public static void DeleteTitle(Title title)
 {
     Dao.TitleCollectionDao.DeleteTitle(title.DaoTitle);
 }
        public static Title CreateTitle(int? parentid, string Name, TitleTypes titletype, string Tag, short? SeasonNumber, short? EpisodeNumber, Disk[] disks)
        {
            Title newTitle = new Title();
            newTitle.Name = Name;

            if (parentid == null)
            {
                newTitle.TitleType = TitleTypes.Root | titletype;
            }
            else
            {
                newTitle.TitleType = titletype;
                newTitle.ParentTitleId = (int)parentid;

                if ((titletype & TitleTypes.Unknown) != 0)
                {
                    // Title type is unknown. Attempt to find title type by looking at parent
                    Title parent = GetTitle((int)parentid);
                    if (parent != null)
                    {
                        if (((parent.TitleType & TitleTypes.TVShow) != 0) ||
                        (((parent.TitleType & TitleTypes.Season) != 0)))
                        {
                            newTitle.TitleType = TitleTypes.Episode;
                        }

                        if ((parent.TitleType & TitleTypes.Collection) != 0)
                        {
                            newTitle.TitleType = TitleTypes.Movie;
                        }
                    }
                }
            }
            newTitle.DateAdded = DateTime.Now;

            newTitle.SeasonNumber = SeasonNumber;
            newTitle.EpisodeNumber = EpisodeNumber;

            if (Tag != null) newTitle.AddTag(Tag);

            if (disks != null)
            {
                foreach (Disk disk in disks)
                {
                    newTitle.AddDisk(disk);
                }
            }

            // Add the title now to get the title ID
            TitleCollectionManager.AddTitle(newTitle);

            // Get the new title from the DB and add it to the title list
            return TitleCollectionManager.GetTitle(newTitle.Id);
        }
Exemple #18
0
        private static void UpdatesImagesForTitle(Dao.Title title)
        {
            const int MAX_FANART_HEIGHT = 1080;

            // if there's a new front cover image path
            if (title.UpdatedFrontCoverPath != null)
            {
                // delete the old one if it exists
                for (int i = title.Images.Count - 1; i >= 0; i--)
                {
                    if (title.Images[i].ImageType == (byte)ImageType.FrontCoverImage)
                    {
                        Dao.TitleCollectionDao.SetDeleteImage(title.Images[i].ImageId);
                        Dao.DBContext.Instance.ImageMappings.DeleteOnSubmit(title.Images[i]);
                        title.Images.RemoveAt(i);
                    }
                }

                if (!string.IsNullOrEmpty(title.UpdatedFrontCoverPath))
                {
                    // add the new one
                    int?id = ImageManager.AddImageToDB(title.UpdatedFrontCoverPath);

                    // if we got an id back let's associate it
                    if (id != null)
                    {
                        Dao.ImageMapping image = new OMLEngine.Dao.ImageMapping();
                        image.ImageId   = id.Value;
                        image.ImageType = (byte)ImageType.FrontCoverImage;

                        title.Images.Add(image);
                    }
                }

                // clear it out
                title.UpdatedFrontCoverPath = null;
            }

            // if there's a new front cover image path
            if (title.UpdatedBackCoverPath != null)
            {
                // delete the old one if it exists
                for (int i = title.Images.Count - 1; i >= 0; i--)
                {
                    if (title.Images[i].ImageType == (byte)ImageType.BackCoverImage)
                    {
                        Dao.TitleCollectionDao.SetDeleteImage(title.Images[i].ImageId);
                        Dao.DBContext.Instance.ImageMappings.DeleteOnSubmit(title.Images[i]);
                        title.Images.RemoveAt(i);
                    }
                }

                if (!string.IsNullOrEmpty(title.UpdatedBackCoverPath))
                {
                    // add the new one
                    int?id = ImageManager.AddImageToDB(title.UpdatedBackCoverPath);

                    // if we got an id back let's associate it
                    if (id != null)
                    {
                        Dao.ImageMapping image = new OMLEngine.Dao.ImageMapping();
                        image.ImageId   = id.Value;
                        image.ImageType = (byte)ImageType.BackCoverImage;

                        title.Images.Add(image);
                    }
                }

                // clear it out
                title.UpdatedBackCoverPath = null;
            }

            if (title.UpdatedFanArtPaths != null)
            {
                IEnumerable <string> originalCoverArt = from t in title.Images
                                                        where t.ImageType == (byte)ImageType.FanartImage
                                                        select ImageManager.ConstructImagePathById(t.ImageId, ImageSize.Original);

                List <string> added   = new List <string>(title.UpdatedFanArtPaths.Where(t => !originalCoverArt.Contains(t)));
                List <string> removed = new List <string>(originalCoverArt.Where(t => !title.UpdatedFanArtPaths.Contains(t)));

                // remove ones no longer used
                foreach (string remove in removed)
                {
                    int?id = ImageManager.GetIdFromImagePath(remove);
                    if (id != null)
                    {
                        Dao.ImageMapping mapping = title.Images.FirstOrDefault(t => t.ImageId == id.Value);

                        if (mapping != null)
                        {
                            Dao.TitleCollectionDao.SetDeleteImage(mapping.DBImage);
                            Dao.DBContext.Instance.ImageMappings.DeleteOnSubmit(mapping);
                            title.Images.Remove(mapping);
                        }
                    }
                }

                // add the new ones
                foreach (string add in added)
                {
                    if (!ImageManager.CheckImageOriginalNameTitleThreadSafe(title.Id, add))
                    {
                        int?id = ImageManager.AddImageToDB(add, MAX_FANART_HEIGHT);

                        if (id != null)
                        {
                            Dao.ImageMapping mapping = new Dao.ImageMapping();
                            mapping.ImageId      = id.Value;
                            mapping.ImageType    = (byte)ImageType.FanartImage;
                            mapping.OriginalName = Path.GetFileName(add);

                            title.Images.Add(mapping);
                        }
                    }
                }

                title.UpdatedFanArtPaths = null;
            }
        }
        private void LoadFanart(List<string> _images, Title title)
        {
            List<string> images = new List<string>();

            foreach (string image in _images)
            {
                if (images.Count < OMLEngine.Settings.OMLSettings.MetadataLookupMaxFanartQty)
                {
                    if (!ImageManager.CheckImageOriginalNameTitleThreadSafe(title.Id, image))
                    {
                        images.Add(image);
                    }
                }
            }

            if (images.Count > 0)
            {
                DownloadingBackDropsForm dbdForm =
                    new DownloadingBackDropsForm(title, images);

                dbdForm.ShowDialog();
            }
        }
 private void LoadFanartFromPlugin(MetaDataPluginDescriptor metadata, Title title)
 {
     if ((metadata.DataProviderCapabilities & MetadataPluginCapabilities.SupportsBackDrops) != 0)
     {
         List<string> _images = metadata.PluginDLL.GetBackDropUrlsForTitle();
         if (_images != null)
         {
             LoadFanart(metadata.PluginDLL.GetBackDropUrlsForTitle(), title);
         }
     }
 }
        /*private void CheckDiskPathForImages(Title title, Disk disk)
        {
            if ((disk == null) || (string.IsNullOrEmpty(disk.Path))) return;

            string diskFolder = disk.GetDiskFolder;
            string diskPathWithExtension = null;
            string diskPathWithoutExtension = null;

            if (!string.IsNullOrEmpty(disk.GetDiskFile))
            {
                diskPathWithExtension = disk.Path;
                diskPathWithoutExtension = disk.GetDiskFolder + "\\" + Path.GetFileNameWithoutExtension(disk.GetDiskFile);
            }

            string image = null;

            // If the Disk is a media file, look for an image in the disk
            // folder with the same name as the media file.
            if (!string.IsNullOrEmpty(diskPathWithExtension))
            {
                if (File.Exists(diskPathWithExtension + ".jpg"))
                {
                    image = diskPathWithExtension + ".jpg";
                }
                else if (File.Exists(diskPathWithExtension + ".png"))
                {
                    image = diskPathWithExtension + ".png";
                }
                else if (File.Exists(diskPathWithoutExtension + ".jpg"))
                {
                    image = diskPathWithoutExtension + ".jpg";
                }
                else if (File.Exists(diskPathWithoutExtension + ".png"))
                {
                    image = diskPathWithoutExtension + ".png";
                }
            }

            // Look for a generic folder.xxx image
            if (string.IsNullOrEmpty(image))
            {
                if (File.Exists(Path.Combine(diskFolder, "folder.jpg")))
                {
                    image = Path.Combine(diskFolder, "folder.jpg");
                }
                else if (File.Exists(Path.Combine(diskFolder, "folder.png")))
                {
                    image = Path.Combine(diskFolder, "folder.png");
                }
            }

            // Look for any jpg image
            if (string.IsNullOrEmpty(image))
            {
                string[] imagefiles = Directory.GetFiles(diskFolder, "*.jpg");
                if (imagefiles.Count() > 0)
                {
                    image = imagefiles[0];
                }
            }

            // Look for any jpg image
            if (string.IsNullOrEmpty(image))
            {
                string[] imagefiles = Directory.GetFiles(diskFolder, "*.png");
                if (imagefiles.Count() > 0)
                {
                    image = imagefiles[0];
                }
            }

            if (!string.IsNullOrEmpty(image))
            {
                title.FrontCoverPath = image;
            }

            // Check for fanart
            string fanartfolder = Path.Combine(diskFolder, "Fanart");
            if (Directory.Exists(fanartfolder))
            {
                foreach (string imagefile in Directory.GetFiles(fanartfolder))
                {
                    string extension = Path.GetExtension(imagefile);
                    if (!string.IsNullOrEmpty(extension))
                    {
                        if ((string.Compare(extension, ".jpg", true) == 0) ||
                            (string.Compare(extension, ".png", true) == 0) ||
                            (string.Compare(extension, ".bmp", true) == 0))
                        {
                            title.AddFanArtImage(imagefile);
                        }
                    }
                }
            }
        }
        */
        private void LookupPreferredMetaData(Title title)
        {
            if (OMLEngine.Settings.OMLSettings.StSanaAutoLookupMeta)
            {
                if ((title == null) || (string.IsNullOrEmpty(OMLEngine.Settings.OMLSettings.DefaultMetadataPluginMovies))) return;
                StartMetadataImport(title, null, false);
            }
        }
 partial void InsertTitle(Title instance);
        private void lvTitles_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            //if (e.Index < 0) return;

            // Find the printing bounds
            int x = e.Bounds.X;
            int y = e.Bounds.Y;
            //int w = e.Bounds.Width;
            //int w = lvTitles.Size.Width - 20;
            int w = lvTitles.ClientRectangle.Width;
            int h = e.Bounds.Height;

            // Create the brushes
            if (_brushTitleListSelected == null)
            {
                _brushTitleListSelected = new LinearGradientBrush(new Point(0, 0), new Point(0, e.Bounds.Height), Color.LimeGreen, Color.PaleGreen);
                _brushTitleListFolder = new LinearGradientBrush(new Point(0, 0), new Point(0, e.Bounds.Height), Color.Gainsboro, Color.Silver);
                _brushTitleListFolderSelected = new LinearGradientBrush(new Point(0, 0), new Point(0, e.Bounds.Height), Color.Silver, Color.LightGreen);
            }

            Title currentTitle = null;
            int? currentTitleID = null;
            if (e.Item.Text == "All Media")
            {
                currentTitle = new Title();
                currentTitle.Name = e.Item.Text;
                currentTitle.TitleType = TitleTypes.Collection;
            }
            else
            {
                currentTitleID = Convert.ToInt32(e.Item.Text);
                currentTitle = _movieList[(int)currentTitleID];
            }

            // Setup string formatting
            StringFormat stf = new StringFormat();
            stf.Trimming = StringTrimming.EllipsisCharacter;
            stf.FormatFlags = StringFormatFlags.NoWrap;

            e.DrawBackground();

            if ((currentTitle.TitleType & TitleTypes.AllFolders) != 0)
            {
                // Folder specific paint goes here
                if (lvTitles.SelectedItems.ContainsKey(currentTitle.Id.ToString()))
                {
                    e.Graphics.FillRectangle(_brushTitleListFolderSelected, x, y, w, h);
                }
                else
                {
                    e.Graphics.FillRectangle(_brushTitleListFolder, x, y, w, h);
                }
                e.Graphics.DrawString(currentTitle.Name, new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold), new SolidBrush(Color.Black), new RectangleF(x, y + 2, w - 65, h), stf);

                int titleCount = 0;
                if (currentTitleID == null)
                {
                    titleCount = _movieRootCount;
                }
                else
                {
                    if (_movieCount.ContainsKey((int)currentTitleID))
                    {
                        titleCount = _movieCount[(int)currentTitleID];
                    }
                }

                e.Graphics.DrawString("Total titles " + titleCount.ToString(), new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Black), new RectangleF(x, y + 18, w - 65, h), stf);

                e.Graphics.DrawString(currentTitle.Name, new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold), new SolidBrush(Color.Black), new RectangleF(x, y + 2, w - 65, h), stf);
            }
            else
            {
                if (lvTitles.SelectedItems.ContainsKey(currentTitle.Id.ToString()))
                {
                    e.Graphics.FillRectangle(_brushTitleListSelected, x, y, w, h);
                }

                // Media specific paint goes here
                e.Graphics.DrawString(currentTitle.Name, new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Black), new RectangleF(x, y + 2, w - 65, h), stf);
                e.Graphics.DrawString(currentTitle.ReleaseDate.ToShortDateString(), new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Black), new RectangleF(w - 60, y + 2, w, h), stf);
                //e.Graphics.DrawString(currentTitle.Runtime.ToString() + " minutes, " + currentTitle.Studio, new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Gray), new RectangleF(8, y + 16, w - 40, h), stf);
                e.Graphics.DrawString(currentTitle.Runtime.ToString() + " minutes", new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Gray), new RectangleF(x + 22, y + 19, w - 102, h), stf);

                // Draw percentage complete box
                Image MetaPercentage = ImgMetaPercentage1;

                if (currentTitle.PercentComplete <= .2M)
                {
                    MetaPercentage = ImgMetaPercentage1;
                }
                else if (currentTitle.PercentComplete <= .4M)
                {
                    MetaPercentage = ImgMetaPercentage2;
                }
                else if (currentTitle.PercentComplete <= .6M)
                {
                    MetaPercentage = ImgMetaPercentage3;
                }
                else if (currentTitle.PercentComplete <= .8M)
                {
                    MetaPercentage = ImgMetaPercentage4;
                }
                else
                {
                    MetaPercentage = ImgMetaPercentage5;
                }

                e.Graphics.DrawImageUnscaled(MetaPercentage,x + 4,y + 18);
                //e.Graphics.FillEllipse(bb, new Rectangle(x + w - 30, y + 16, 14, 14));
                //e.Graphics.DrawEllipse(new Pen(Color.Black), new Rectangle(x + w - 30, y + 16, 14, 14));
            }

            // Common painting goes here
            e.Graphics.DrawLine(new Pen(Color.Gray), 0, y + h - 1, w, y + h - 1);

            // Draw rating stars
            Image Stars = null;
            switch (currentTitle.UserStarRating)
            {
                case 0: Stars = ImgStars0; break;
                case 1:
                case 2: Stars = ImgStars1; break;
                case 3:
                case 4: Stars = ImgStars2; break;
                case 5:
                case 6: Stars = ImgStars3; break;
                case 7:
                case 8:
                case 9: Stars = ImgStars4; break;
                default: Stars = ImgStars5; break;
            }
            e.Graphics.DrawImageUnscaled(Stars, x + w - 82, y + 18);
        }
 partial void DeleteTitle(Title instance);
        /// <summary>
        /// Adds a title to the db
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        public static bool AddTitle(Title title)
        {
            using (OMLEngine.Dao.LocalDataContext db = new OMLEngine.Dao.LocalDataContext(false))
            {
                // Set default titletype if none specified
                if ((title.TitleType == 0)) { title.TitleType = TitleTypes.Root | TitleTypes.Video; }

                // setup all the collections objects
                // todo : solomon : this should go away once it's understood how people
                // will be added
                Dao.TitleDao.SetupCollectionsToBeAdded(db.Context, title);

                // setup all the images
                UpdatesImagesForTitle(title.DaoTitle);

                // reset the % complete
                title.DaoTitle.ResetPercentComplete();

                // todo : solomon : do your duplicate logic here
                Dao.TitleCollectionDao.AddTitle(db.Context, title.DaoTitle);

                return true;
            }
        }