OSDN Git Service

svnから移動
[assistrb/assistrb.git] / src / AssistRB / DlnaItemList.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Net;
6
7 namespace AssistRB
8 {
9     public class DlnaItem
10     {
11         public string Parent { get; set; }
12         public string Id { get; set; }
13         public string Title { get; set; }
14         public string Series { get; set; }
15         public string ClassType { get; set; }
16         public Int64 Size { get; set; }
17         public string Date { get; set; }
18     }
19
20     public class DlnaItemList
21     {
22         private const string RootFolderId = "FS-Folder";
23
24         static DlnaItemList instance = null;
25
26         private List<DlnaItem> dlnaItem = new List<DlnaItem>();
27         private Dictionary<string, string> folderDictionary = new Dictionary<string, string>();
28         private List<string> invalidFolder = new List<string>();
29
30         public delegate void ListChangedDelegate();
31         public event ListChangedDelegate ListChanged;
32
33         public static DlnaItemList GetInstance()
34         {
35             if (instance == null)
36             {
37                 instance = new DlnaItemList();
38                 instance.InvalidateAll();
39             }
40
41             return instance;
42         }
43
44         public void InvalidateAll()
45         {
46             invalidFolder.Clear();
47             invalidFolder.Add(RootFolderId);
48         }
49
50         public void Invalidate(string folder)
51         {
52             if (invalidFolder.Contains(RootFolderId))
53             {
54                 return;
55             }
56
57             if (folder == RootFolderId)
58             {
59                 InvalidateAll();
60             }
61             else
62             {
63                 if (!invalidFolder.Contains(folder))
64                 {
65                     invalidFolder.Add(folder);
66                 }
67             }
68         }
69
70         public List<DlnaItem> GetList()
71         {
72             return this.dlnaItem;
73         }
74
75         public Dictionary<string, string> GetFolderList()
76         {
77             return this.folderDictionary;
78         }
79
80         public List<string> GetInvalidList()
81         {
82             return this.invalidFolder;
83         }
84
85         public void UpdateList(
86             List<DlnaItem> newList)
87         {
88             this.dlnaItem = newList;
89
90             this.invalidFolder.Clear();
91
92             // フォルダ辞書の更新
93             folderDictionary.Clear();
94             folderDictionary.Add("FS-Folder", "ROOT");
95             foreach (DlnaItem item in this.dlnaItem)
96             {
97                 if (item.ClassType == "container")
98                 {
99                     folderDictionary.Add(item.Id, item.Title);
100                 }
101             }
102
103             if (this.ListChanged != null)
104             {
105                 this.ListChanged();
106             }
107         }
108     }
109 }