Example #1
0
        void resetStartupItem(DBItem startupItem)
        {
            startupEmu       = null;
            startupGame      = null;
            startupGroup     = null;
            this.startupItem = startupItem;

            if (startupItem == null)
            {
                return;
            }

            startupEmu = startupItem as Emulator;
            if (startupEmu != null)
            {
                return;
            }

            startupGame = startupItem as Game;
            if (startupGame != null)
            {
                return;
            }

            startupGroup = startupItem as RomGroup;
        }
Example #2
0
        public List <RomGroup> LoadGroups()
        {
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            string xmlPath             = System.IO.Path.Combine(MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Config), "Emulators2Groups.xml");

            bool loaded = false;
            bool error  = false;

            if (System.IO.File.Exists(xmlPath))
            {
                try
                {
                    doc.Load(xmlPath);
                    loaded = true;
                }
                catch (Exception ex)
                {
                    loaded = false;
                    error  = true;
                    Logger.LogError("Error loading Groups xml from location '{0}' - {1}", xmlPath, ex.Message);
                }
            }

            if (!loaded)
            {
                using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyEmulators2.Data.Emulators2Groups.xml"))
                {
                    doc.Load(stream);
                }
                if (!error)
                {
                    try
                    {
                        doc.Save(xmlPath);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError("Unable to save Group xml to location '{0}' - {1}", xmlPath, ex.Message);
                    }
                }
            }

            List <RomGroup> groups = new List <RomGroup>();

            foreach (System.Xml.XmlNode node in doc.GetElementsByTagName("Group"))
            {
                RomGroup group = new RomGroup(node);
                if (group.IsReady)
                {
                    groups.Add(group);
                }
            }
            return(groups);
        }
        public GroupViewModel(RomGroup group, EmulatorsMainModel model)
        {
            this.model = model;
            Group = group;
            Name = group.Title;
            ThumbGroup thumbGroup = group.ThumbGroup;
            if (thumbGroup != null)
            {
                FrontCover = thumbGroup.FrontCoverDefaultPath;
                Fanart = thumbGroup.FanartDefaultPath;
            }

            Command = new MethodDelegateCommand(() =>
            {
                model.GroupSelected(Group);
            });
        }
Example #4
0
        bool groupSelected(ExtendedGUIListItem selectedListItem, int index, int parentIndex, bool allowSortChange)
        {
            RomGroup romGroup = selectedListItem.RomGroup;

            if (romGroup == null)
            {
                return(false);
            }

            romGroup.Refresh();
            if (romGroup.GroupItems.Count < 1)
            {
                return(false);
            }

            if (allowSortChange)
            {
                SortProperty = romGroup.SortProperty;
                if (sortAsc == romGroup.SortDescending)
                {
                    sortAsc = !romGroup.SortDescending;
                    if (OnSortAscendingChanged != null)
                    {
                        OnSortAscendingChanged(sortAsc);
                    }
                }
            }

            setItemsToFacade(romGroup.GroupItems, selectedListItem, parentIndex, index);

            lastItem      = selectedListItem;
            lastitemIndex = parentIndex;
            if (romGroup.Layout < 0)
            {
                romGroup.Layout = currentLayout;
            }
            else
            {
                setLayout(romGroup.Layout);
            }
            return(true);
        }
Example #5
0
        public override void ClosePanel()
        {
            if (!groupsLoaded)
            {
                return;
            }

            updateSelectedGroupItem();
            updateSelectedGroup();
            List <RomGroup> groups = new List <RomGroup>();

            foreach (ListViewItem item in groupsListView.Items)
            {
                RomGroup group = item.Tag as RomGroup;
                if (group != null)
                {
                    groups.Add(group);
                }
            }

            GroupHandler.Instance.SaveGroups(groups);

            base.ClosePanel();
        }
Example #6
0
        void groupsListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (!e.IsSelected)
                return;

            updateButtons();
            updateSelectedGroupItem();
            selectedGroupItem = null;
            updateSelectedGroup();
            selectedGroup = null;
            selectedListItem = null;

            allowGroupItemUpdate = false;
            resetSQLGroup();
            resetDynamicGroup();

            if (groupsListView.SelectedItems.Count > 1)
                return;

            selectedListItem = e.Item;
            selectedGroup = e.Item.Tag as RomGroup;
            if (selectedGroup == null)
            {
                selectedListItem = null;
                return;
            }

            txt_Title.Text = selectedGroup.Title;
            sortDescCheckBox.Checked = selectedGroup.SortDescending;
            bool found = false;
            foreach (KeyValuePair<string, ListItemProperty> keyVal in sortDropdownItems)
            {
                if (keyVal.Value == selectedGroup.SortProperty)
                {
                    found = true;
                    sortComboBox.SelectedItem = keyVal.Key;
                    break;
                }
            }
            if (!found)
                sortComboBox.SelectedIndex = 0;

            found = false;
            foreach (KeyValuePair<string, int> keyVal in layoutDropdownItems)
            {
                if (keyVal.Value == selectedGroup.Layout)
                {
                    found = true;
                    layoutComboBox.SelectedItem = keyVal.Key;
                    break;
                }
            }
            if (!found)
                layoutComboBox.SelectedIndex = 0;

            groupItemsTreeView.Nodes.Clear();
            foreach (GroupItemInfo item in selectedGroup.GroupItemInfos)
            {
                TreeNode newNode = new TreeNode() { Tag = item };
                switch (item.ItemType)
                {
                    case GroupItemType.SQL:
                        newNode.Text = "SQL";
                        newNode.Nodes.Add("Loading...");
                        break;
                    case GroupItemType.DYNAMIC:
                        newNode.Text = "Dynamic";
                        newNode.Nodes.Add("Loading...");
                        break;
                    case GroupItemType.EMULATOR:
                        if (item.ItemId == GroupItemInfo.ALL_ITEMS_ID)
                        {
                            newNode.Text = "All Emulators";
                            newNode.Nodes.Add("Loading...");
                        }
                        else
                        {
                            Emulator emu;
                            if (allEmulators.TryGetValue(item.ItemId, out emu))
                                newNode.Text = emu.Title;
                            else
                                continue;
                        }
                        break;
                    case GroupItemType.GAME:
                        if (item.ItemId == GroupItemInfo.ALL_ITEMS_ID)
                        {
                            newNode.Text = "All Games";
                            newNode.Nodes.Add("Loading...");
                        }
                        else
                        {
                            Game game;
                            if (allGames.TryGetValue(item.ItemId, out game))
                                newNode.Text = game.Title;
                            else
                                continue;
                        }
                        break;
                }                
                groupItemsTreeView.Nodes.Add(newNode);
            }
            allowGroupItemUpdate = true;
        }
Example #7
0
        void groupsListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (!e.IsSelected)
            {
                return;
            }

            updateButtons();
            updateSelectedGroupItem();
            selectedGroupItem = null;
            updateSelectedGroup();
            selectedGroup    = null;
            selectedListItem = null;

            allowGroupItemUpdate = false;
            resetSQLGroup();
            resetDynamicGroup();

            if (groupsListView.SelectedItems.Count > 1)
            {
                return;
            }

            selectedListItem = e.Item;
            selectedGroup    = e.Item.Tag as RomGroup;
            if (selectedGroup == null)
            {
                selectedListItem = null;
                return;
            }

            txt_Title.Text = selectedGroup.Title;

            sortDescCheckBox.Checked = selectedGroup.SortDescending;
            bool found = false;

            foreach (KeyValuePair <string, ListItemProperty> keyVal in sortDropdownItems)
            {
                if (keyVal.Value == selectedGroup.SortProperty)
                {
                    found = true;
                    sortComboBox.SelectedItem = keyVal.Key;
                    break;
                }
            }
            if (!found)
            {
                sortComboBox.SelectedIndex = 0;
            }

            found = false;
            foreach (KeyValuePair <string, int> keyVal in layoutDropdownItems)
            {
                if (keyVal.Value == selectedGroup.Layout)
                {
                    found = true;
                    layoutComboBox.SelectedItem = keyVal.Key;
                    break;
                }
            }
            if (!found)
            {
                layoutComboBox.SelectedIndex = 0;
            }

            groupItemsTreeView.Nodes.Clear();

            foreach (GroupItemInfo item in selectedGroup.GroupItemInfos)
            {
                TreeNode newNode = new TreeNode()
                {
                    Tag = item
                };
                if (item.SQL != null)
                {
                    if (string.IsNullOrEmpty(item.Column))
                    {
                        newNode.Text = "SQL";
                    }
                    else
                    {
                        newNode.Text = "Dynamic";
                    }

                    newNode.Nodes.Add("Loading...");
                }
                else if (item.Emulator)
                {
                    Emulator emu;
                    if (item.Id == -2)
                    {
                        newNode.Text = "All Emulators";
                        newNode.Nodes.Add("Loading...");
                    }
                    else if (allEmulators.TryGetValue(item.Id, out emu))
                    {
                        newNode.Text = emu.Title;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    Game game;
                    if (item.Id == -2)
                    {
                        newNode.Text = "All Games";
                        newNode.Nodes.Add("Loading...");
                    }
                    else if (allGames.TryGetValue(item.Id, out game))
                    {
                        newNode.Text = game.Title;
                    }
                    else
                    {
                        continue;
                    }
                }
                groupItemsTreeView.Nodes.Add(newNode);
            }

            allowGroupItemUpdate = true;
        }
        public void GroupSelected(RomGroup group)
        {
            group.Refresh();
            List<ListItem> items = new List<ListItem>();
            foreach (DBItem item in group.GroupItems)
            {
                Game game = item as Game;
                if (game != null)
                {
                    items.Add(new GameViewModel(game, this));
                    continue;
                }

                RomGroup subGroup = item as RomGroup;
                if (subGroup != null)
                {
                    items.Add(new GroupViewModel(subGroup, this));
                    continue;
                }

                Emulator emulator = item as Emulator;
                if (emulator != null)
                    items.Add(new EmulatorViewModel(emulator, this));
            }

            NavigationData navigationData = new NavigationData() { DisplayName = group.Title, ItemsList = items };
            PushTransientState("emuSubGroup", navigationData.DisplayName, navigationData);
        }