[longomatch] Fix playlist serialization
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Fix playlist serialization
- Date: Tue, 30 Aug 2011 20:58:27 +0000 (UTC)
commit bee42f7da348ffa22839b743ebf5754e42f44e98
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Sun Aug 28 20:13:54 2011 +0200
Fix playlist serialization
LongoMatch/Common/Constants.cs | 1 +
LongoMatch/Gui/Component/PlayListWidget.cs | 10 ++--
LongoMatch/Playlist/IPlayList.cs | 2 +-
LongoMatch/Playlist/PlayList.cs | 81 ++++++++++------------------
4 files changed, 36 insertions(+), 58 deletions(-)
---
diff --git a/LongoMatch/Common/Constants.cs b/LongoMatch/Common/Constants.cs
index d43ce15..dcd3ebe 100644
--- a/LongoMatch/Common/Constants.cs
+++ b/LongoMatch/Common/Constants.cs
@@ -92,5 +92,6 @@ Xavier Queralt Mateu (ca)";
public const string TEAMS_TEMPLATE_EXT = ".ltt";
public const string CAT_TEMPLATE_EXT = ".lct";
public const string SUBCAT_TEMPLATE_EXT = ".lst";
+ public const string PLAYLIST_EXT = ".lpl";
}
}
diff --git a/LongoMatch/Gui/Component/PlayListWidget.cs b/LongoMatch/Gui/Component/PlayListWidget.cs
index b488844..eed19b8 100644
--- a/LongoMatch/Gui/Component/PlayListWidget.cs
+++ b/LongoMatch/Gui/Component/PlayListWidget.cs
@@ -24,6 +24,7 @@ using Gdk;
using LongoMatch.Video.Editor;
using Mono.Unix;
using System.IO;
+using LongoMatch.Common;
using LongoMatch.Handlers;
using LongoMatch.Store;
using LongoMatch.Video.Player;
@@ -81,14 +82,15 @@ namespace LongoMatch.Gui.Component
public void Load(string filePath) {
try {
- playList = new PlayList(filePath);
+ playList = PlayList.Load(filePath);
Model = playList.GetModel();
label1.Visible = false;
newvideobutton.Show();
playlisttreeview1.PlayList = playList;
playlisttreeview1.Sensitive = true;
savebutton.Sensitive = true;
- } catch {
+ } catch (Exception e){
+ Log.Exception (e);
MessagePopup.PopupMessage(this,MessageType.Error,Catalog.GetString("The file you are trying to load is not a playlist or it's not compatible with the current version"));
}
}
@@ -193,8 +195,8 @@ namespace LongoMatch.Gui.Component
private FileFilter FileFilter {
get {
FileFilter filter = new FileFilter();
- filter.Name = "LGM playlist";
- filter.AddPattern("*.lgm");
+ filter.Name = Catalog.GetString("LongoMatch playlist");
+ filter.AddPattern("*" + Constants.PLAYLIST_EXT);
return filter;
}
}
diff --git a/LongoMatch/Playlist/IPlayList.cs b/LongoMatch/Playlist/IPlayList.cs
index 8ba44ba..f787cd7 100644
--- a/LongoMatch/Playlist/IPlayList.cs
+++ b/LongoMatch/Playlist/IPlayList.cs
@@ -35,7 +35,7 @@ namespace LongoMatch.Playlist {
void Add(PlayListPlay play);
- void Remove(PlayListPlay play);
+ bool Remove(PlayListPlay play);
PlayListPlay Next();
diff --git a/LongoMatch/Playlist/PlayList.cs b/LongoMatch/Playlist/PlayList.cs
index d414618..38c7c0a 100644
--- a/LongoMatch/Playlist/PlayList.cs
+++ b/LongoMatch/Playlist/PlayList.cs
@@ -32,46 +32,25 @@ namespace LongoMatch.Playlist
{
- public class PlayList: SerializableObject,IPlayList
+ [Serializable]
+ public class PlayList: List<PlayListPlay>, IPlayList
{
- private List<PlayListPlay> list;
- private string filename = null;
private int indexSelection = 0;
private Version version;
#region Constructors
public PlayList() {
- list = new List<PlayListPlay>();
- version = new Version(1,0);
+ version = new Version(2,0);
}
- public PlayList(string file)
- {
- //For new Play List
- if(!System.IO.File.Exists(file)) {
- list = new List<PlayListPlay>();
- filename = file;
- }
- else
- Load(file);
-
- version = new Version(1,0);
- }
#endregion
#region Properties
- public int Count {
- get {
- return list.Count;
- }
- }
-
- public string File {
- get {
- return filename;
- }
+ public string Filename {
+ get;
+ set;
}
public Version Version {
@@ -83,19 +62,23 @@ namespace LongoMatch.Playlist
#region Public methods
public void Save() {
- Save(File);
+ Save(Filename);
}
public void Save(string filePath) {
- Save(this, filePath);
+ SerializableObject.Save(this, filePath);
}
public static PlayList Load(string filePath) {
- return Load<PlayList>(filePath);
- }
-
- public bool isLoaded() {
- return filename != null;
+ PlayList pl;
+ string filename = System.IO.Path.ChangeExtension(filePath, Constants.PLAYLIST_EXT);
+
+ //For new Play List
+ if(!System.IO.File.Exists(filePath))
+ pl = new PlayList();
+ else
+ pl = SerializableObject.Load<PlayList>(filePath);
+ return pl;
}
public int GetCurrentIndex() {
@@ -105,33 +88,29 @@ namespace LongoMatch.Playlist
public PlayListPlay Next() {
if(HasNext())
indexSelection++;
- return list[indexSelection];
+ return this[indexSelection];
}
public PlayListPlay Prev() {
if(HasPrev())
indexSelection--;
- return list[indexSelection];
+ return this[indexSelection];
}
- public void Add(PlayListPlay plNode) {
- list.Add(plNode);
- }
-
- public void Remove(PlayListPlay plNode) {
-
- list.Remove(plNode);
- if(GetCurrentIndex() >= list.Count)
+ public new bool Remove(PlayListPlay plNode) {
+ bool ret = base.Remove(plNode);
+ if(GetCurrentIndex() >= Count)
indexSelection --;
+ return ret;
}
public PlayListPlay Select(int index) {
indexSelection = index;
- return list[index];
+ return this[index];
}
public bool HasNext() {
- return indexSelection < list.Count-1;
+ return indexSelection < Count-1;
}
public bool HasPrev() {
@@ -140,7 +119,7 @@ namespace LongoMatch.Playlist
public ListStore GetModel() {
Gtk.ListStore listStore = new ListStore(typeof(PlayListPlay));
- foreach(PlayListPlay plNode in list) {
+ foreach(PlayListPlay plNode in this) {
listStore.AppendValues(plNode);
}
return listStore;
@@ -150,17 +129,13 @@ namespace LongoMatch.Playlist
TreeIter iter ;
listStore.GetIterFirst(out iter);
- list.Clear();
+ Clear();
while(listStore.IterIsValid(iter)) {
- list.Add(listStore.GetValue(iter, 0) as PlayListPlay);
+ Add(listStore.GetValue(iter, 0) as PlayListPlay);
listStore.IterNext(ref iter);
}
}
- public IEnumerator GetEnumerator() {
- return list.GetEnumerator();
- }
-
public IPlayList Copy() {
return (IPlayList)(MemberwiseClone());
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]