Beispiel #1
0
        private void ConvertTitles()
        {
            int numTitles = ClbEpisodes.Items.Count;

            for (int i = 0; i < numTitles; i++)
            {
                StatusUpdate("episodes/disks", i + 1, numTitles);
                Title t = (Title)ClbEpisodes.Items[i];
                if (t != null)
                {
                    if (ClbEpisodes.GetItemChecked(i))
                    {
                        try
                        {
                            GeneralPersistense.Upsert(t);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, "Error updating title " + t.TitleName);
                        }
                    }
                }
            }
            EndUpdate();
            ClbEpisodes.Items.Clear();
        }
Beispiel #2
0
        private void buttonManSave_Click(object sender, EventArgs e)
        {
            if (m_currentTitle == null)
            {
                return;                                     //I don't see the use case, but still
            }
            string description = TbxDescription.Text;
            int    year        = TbxReleaseYear.Text.To <int>(0);

            bool modified = false;

            if (string.IsNullOrWhiteSpace(description))
            {
                m_currentTitle.Description = description;
                modified = true;
            }
            if (year > 0)
            {
                m_currentTitle.Year = year;
                modified            = true;
            }
            if (modified)
            {
                m_currentTitle.DateModifiedUtc = GeneralPersistense.GetTimestamp();
                GeneralPersistense.Upsert(m_currentTitle);
            }
            BtnNext_Click(sender, e);
        }
Beispiel #3
0
        private void LVLocations_CellEditFinishing(object sender, CellEditEventArgs e)
        {
            var item = e.RowObject as LocationForDisplay;

            if (item != null)
            {
                switch (e.SubItemIndex)
                {
                case 1:
                {
                    var ctrl = e.Control as ComboBox;
                    if (ctrl != null)
                    {
                        var selected = ctrl.SelectedItem as ComboBoxItem;
                        if (selected != null)
                        {
                            item.LocationBaseId  = (long)selected.Key;
                            e.NewValue           = item.LocationBase = selected.ToString();
                            item.DateModifiedUtc = GeneralPersistense.GetTimestamp();
                            GeneralPersistense.Upsert(new Location(item));
                        }
                    }
                    break;
                }

                case 2:
                    item.LocationData    = (string)e.NewValue;
                    item.DateModifiedUtc = GeneralPersistense.GetTimestamp();
                    GeneralPersistense.Upsert(new Location(item));
                    break;
                }
            }
        }
Beispiel #4
0
        private void Set()
        {
            if (m_currentTitle == null)
            {
                return;
            }

            m_currentTitle.DateModifiedUtc = GeneralPersistense.GetTimestamp();
            m_currentTitle.TitleName       = TbxTitleName.Text;
            m_currentTitle.Kind            = CbxKind.GetSelectedKey <TitleKind>();
            m_currentTitle.Year            = TbxReleaseYear.Text.To <int>(0);
            m_currentTitle.Description     = TbxDescription.Text;
            m_currentTitle.ImdbId          = TbxImdbId.Text;
            m_currentTitle.Season          = TbxSeason.Text.To <int>(0);
            m_currentTitle.Disk            = TbxDisk.Text.To <int>(0);
            m_currentTitle.EpisodeOrTrack  = TbxEpisode.Text.To <int>(0);

            GeneralPersistense.Upsert(m_currentTitle);
            SetControlsFromDirtyState(false);


            //HACK: TVTitles.Sort doesn't work
            if (!m_currentTitle.ParentTitleId.HasValue)
            {
                var roots = new List <Title>(TVTitles.Roots.Cast <Title>());
                roots.Sort();
                TVTitles.Roots = roots;
                TVTitles.EnsureModelVisible(m_currentTitle);
            }
        }
Beispiel #5
0
        public ActionResult UpdateLocations(SetRequest rq)
        {
            if (rq == null)
            {
                throw new ArgumentNullException("rq");
            }
            if (!rq.ParentId.HasValue)
            {
                throw new ArgumentException("Request should have parentId");
            }
            long pid = rq.ParentId.Value;

            if (pid <= 0)
            {
                throw new ArgumentException("parentId should be positive");
            }
            if (rq.Edits != null)
            {
                foreach (var e in rq.ToPoco <LocationBaseDeviceMapping>())
                {
                    var data = new DeviceLocationMap {
                        DeviceId = pid, LocationBaseId = e.LocationBaseId, Mapping = e.Mapping
                    };
                    GeneralPersistense.Upsert(data);
                }
            }
            return(ListLocations(pid));
        }
Beispiel #6
0
        public Ratings()
        {
            InitializeComponent();
            var ratings = GeneralPersistense.FetchAll <RatingProvider>();

            LVRatings.VirtualMode = false;
            LVRatings.SetObjects(ratings);

            olvColumnRatingStep.AspectPutter = (object o, object val) => {
                var r = o as RatingProvider;
                if (r != null)
                {
                    r.RatingStep = Convert.ToSingle(val);
                }
            };
            olvColumnRatingMin.AspectPutter = (object o, object val) => {
                var r = o as RatingProvider;
                if (r != null)
                {
                    r.RatingMax = Convert.ToSingle(val);
                }
            };
            olvColumnRatingMax.AspectPutter = (object o, object val) => {
                var r = o as RatingProvider;
                if (r != null)
                {
                    r.RatingMax = Convert.ToSingle(val);
                }
            };
        }
        public void SetNewLocation()
        {
            LocationBaseId  = NewLocationBaseId;
            LocationData    = NewLocationData;
            DateModifiedUtc = GeneralPersistense.GetTimestamp();

            using (var db = DB.GetDatabase())
            {
                db.Update(this);
            }
        }
        public void Set <T>(string key, T value)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("Key cannot be empty or null", "key");
            }
            var data = new AppConfig {
                ConfigKey = key, ConfigValue = ((value == null) ? null : value.ToString())
            };

            GeneralPersistense.Upsert(data);
        }
        public static Title AddTitle(string name, TitleKind kind, int season, int disk, int episodeOrTrack, long?parentId)
        {
            string now = GeneralPersistense.GetTimestamp();
            var    t   = new Title {
                TitleName = name, Kind = kind, Season = season, Disk = disk, EpisodeOrTrack = episodeOrTrack, ParentTitleId = parentId, DateAddedUtc = now, DateModifiedUtc = now, ImdbId = "", Description = ""
            };

            using (var db = DB.GetDatabase())
            {
                db.Insert(t);
            }
            return(t);
        }
        public void Save()
        {
            TitleKind kind;

            switch (this.DataType)
            {
            case MediaType.AudioFolder:
            case MediaType.Cd:
            case MediaType.CdImage:
                kind = TitleKind.Album;
                break;

            case MediaType.MediaFileAudio:
                kind = TitleKind.Track;
                break;

            default:
                if (Episode == 0 && Disk > 0)
                {
                    kind = TitleKind.Disk;
                }
                else if (Episode > 0)
                {
                    kind = TitleKind.Episode;
                }
                else if (Season > 0 && Episode == 0 && Disk == 0)
                {
                    kind = TitleKind.Season;
                }
                else
                {
                    kind = TitleKind.Title;
                }
                break;
            }

            string now   = GeneralPersistense.GetTimestamp();
            var    title = new Title {
                Id = 0, Kind = kind, TitleName = Title, DateAddedUtc = now, DateModifiedUtc = now, Season = Season, Disk = Disk, EpisodeOrTrack = Episode, ImdbId = "", Description = ""
            };

            using (var db = DB.GetDatabase())
            {
                db.Insert(title);
                var location = new Location {
                    Id = 0, LocationBaseId = m_locationBaseId, LocationData = RelativePath, MediaKind = DataType, TitleId = title.Id, DateAddedUtc = now, DateModifiedUtc = now
                };
                db.Insert(location);
            }
        }
Beispiel #11
0
        private void SetTitle(TmdbResult searchResult)
        {
            if (m_currentTitle == null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(searchResult.ImdbId))
            {
                //TODO: make it async
                (new Wait((cts) => searchResult.GetMore(cts.Token), "Retrieving additional info: {0} seconds elapsed")).ShowDialog();
            }
            m_currentTitle.DateModifiedUtc = GeneralPersistense.GetTimestamp();
            if (CbxOverrideDescription.Checked && !string.IsNullOrWhiteSpace(searchResult.Overview))
            {
                m_currentTitle.Description = searchResult.Overview;
            }
            if (CbxOverrideTitle.Checked && !string.IsNullOrWhiteSpace(searchResult.Title))
            {
                m_currentTitle.TitleName = searchResult.Title;
            }
            if (CbxOverrideYear.Checked && searchResult.ReleaseDate.HasValue)
            {
                m_currentTitle.Year = searchResult.ReleaseDate.Value.Year;
            }
            if (!string.IsNullOrWhiteSpace(searchResult.ImdbId))
            {
                m_currentTitle.ImdbId = searchResult.ImdbId;
            }


            /*StoredItem.SeasonPersistence,
            *  StoredItem.DiskPersistence,
            *  StoredItem.EpisodePersistence*/

            if (m_currentTitle.TitleName == null)
            {
                m_currentTitle.TitleName = "";
            }
            GeneralPersistense.Upsert(m_currentTitle);

            if (searchResult.Poster != null && searchResult.Poster.Length > 0)
            {
                MediaSamplePersistence.AddSample(searchResult.Poster, m_currentTitle.Id, MediaSampleKind.Image, Path.GetExtension(searchResult.PosterPath));
            }
        }
Beispiel #12
0
        private void BtnNew_Click(object sender, EventArgs e)
        {
            TitleKind kind;

            switch (GetResourceKind())
            {
            case ResourceKind.Audio: kind = TitleKind.AlbumArtist; break;

            case ResourceKind.Video: kind = TitleKind.Title; break;

            default: return;
            }

            Title newTitle = null;

            foreach (Title item in TVTitles.Objects)
            {
                if (item.Id < 1)
                {
                    //Unsaved new item already there
                    newTitle = item;
                }
            }
            if (newTitle == null)
            {
                newTitle = new Title()
                {
                    TitleName = "New", Kind = kind, DateAddedUtc = GeneralPersistense.GetTimestamp()
                };
                TVTitles.AddObject(newTitle);
            }
            TVTitles.SelectedObject = newTitle;
            DisplayTitleInfo(newTitle);
            TVTitles.EnsureModelVisible(newTitle);
            TbxTitleName.Focus();
        }
Beispiel #13
0
        public MainForm()
        {
            InitializeComponent();
            LVLocations.VirtualMode = false;
            LVRatings.VirtualMode   = false;

            AppDomain.CurrentDomain.UnhandledException += (o, e) => {
                var    ex  = e.ExceptionObject as Exception;
                string msg = ex == null ? "Unhandled error" : ex.Message;
                MessageBox.Show(msg, "Application Error");
            };
            Application.ThreadException += (o, e) => {
                string msg = e.Exception == null ? "Unhandled error (thread)" : e.Exception.Message;
                MessageBox.Show(msg, "Application Error");
            };

            TVTitles.CanExpandGetter = (o) => {
                var t = o as Title;
                if (t == null)
                {
                    return(false);
                }
                return(t.Kind != TitleKind.Episode && t.Kind != TitleKind.Track && t.Kind != TitleKind.Title);
            };

            TVTitles.ChildrenGetter = (o) => {
                var t = o as Title;
                if (t == null)
                {
                    return(null);
                }
                return(new SortableTitles(TitlePersistence.ListTitlesByParent(t.Id)));
            };

            OlvColumnName.ImageGetter = (o) => {
                var t = o as Title;
                if (t == null)
                {
                    return(-1);
                }
                return((int)t.Kind);
            };

            OlvBtnPlay.AspectGetter = (o) => {
                var l = o as LocationForDisplay;
                if (l != null && l.LocationKind != LocationBaseKind.Shelf)
                {
                    return("Play");
                }
                return(null);
            };

            var sink = (BrightIdeasSoftware.SimpleDropSink)TVTitles.DropSink;

            sink.AcceptExternal      = false;
            sink.CanDropBetween      = false;
            sink.CanDropOnBackground = false;
            sink.CanDropOnItem       = true;
            sink.CanDropOnSubItem    = true;

            sink.CanDrop += (sender, e) => {
                e.Handled = true;
                e.Effect  = DragDropEffects.None;
                var models = GetModelsFromDropEvent(e);

                if (CanDrop(models.Item1, models.Item2))
                {
                    e.Effect = DragDropEffects.Move;
                }
            };

            sink.Dropped += (sender, e) => {
                var models = GetModelsFromDropEvent(e);
                if (models.Item1 == null || models.Item2 == null)
                {
                    return;
                }
                SetSeriesHierarchy(models.Item1, models.Item2);
                GeneralPersistense.Upsert(models.Item1);
                e.Effect = DragDropEffects.Move;
                TVTitles.RemoveObject(models.Item1);
                TVTitles.RefreshObject(models.Item2);
            };

            TVTitles.ModelFilter = new ModelFilter((m) => {
                var t = m as Title;
                if (t == null)
                {
                    return(false);
                }

                string filter = TbxSearch.Text.Trim().ToLower();
                if (m_titleFilter.Count > 0)
                {
                    if (m_titleFilter.Contains(t.Id))
                    {
                        if (filter.Length == 0)
                        {
                            return(true);
                        }
                        return(t.TitleName.ToLower().Contains(filter));
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (filter.Length == 0)
                    {
                        return(true);
                    }
                    return(t.TitleName.ToLower().Contains(filter));
                }
            });

            olvColumnRatingValue.AspectPutter = (object o, object val) => {
                var r = o as TitleRatingWithName;
                if (r != null)
                {
                    r.RatingValue = Convert.ToSingle(val);
                }
            };



            CbxDevices.Items.AddRange(DevicePersistense.ListForPalyback().ToArray());
            if (CbxDevices.Items.Count > 0)
            {
                CbxDevices.SelectedIndex = 0;
            }

            m_imageIndex = 0;
        }