[Banshee-List] iTunes-style check boxes for syncing - patch
- From: Michael Quinn <mikeq wam umd edu>
- To: banshee-list gnome org
- Subject: [Banshee-List] iTunes-style check boxes for syncing - patch
- Date: Tue, 05 Sep 2006 20:15:27 -0400
Heres a small patch I've worked on that adds the iTunes-style checkbox
interface to banshee, so you can specify which songs you want synced to
your device. I hope people find this useful!
Index: data/UIManagerLayout.xml
===================================================================
RCS file: /cvs/gnome/banshee/data/UIManagerLayout.xml,v
retrieving revision 1.19
diff -u -r1.19 UIManagerLayout.xml
--- data/UIManagerLayout.xml 4 Sep 2006 00:22:29 -0000 1.19
+++ data/UIManagerLayout.xml 6 Sep 2006 00:02:33 -0000
@@ -96,6 +96,9 @@
<menuitem name="SearchForSameGenre"
action="SearchForSameGenreAction" />
</menu>
<separator />
+ <menuitem name="CheckSongs" action="CheckSongsAction" />
+ <menuitem name="UncheckSongs" action="UncheckSongsAction" />
+ <separator />
<menuitem name="SelectAll" action="SelectAllAction" />
<menuitem name="SelectNone" action="SelectNoneAction" />
<separator />
Index: src/PlayerInterface.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/PlayerInterface.cs,v
retrieving revision 1.211
diff -u -r1.211 PlayerInterface.cs
--- src/PlayerInterface.cs 4 Sep 2006 22:58:11 -0000 1.211
+++ src/PlayerInterface.cs 6 Sep 2006 00:02:35 -0000
@@ -935,6 +935,8 @@
Globals.ActionManager.SongActions.Sensitive = true;
Globals.ActionManager["WriteCDAction"].Sensitive = !(source
is AudioCdSource);
Globals.ActionManager["RemoveSongsAction"].Sensitive
= !(source is AudioCdSource);
+ Globals.ActionManager["CheckSongsAction"].Visible = (source
is LibrarySource);
+ Globals.ActionManager["UncheckSongsAction"].Visible =
(source is LibrarySource);
Globals.ActionManager["DeleteSongsFromDriveAction"].Sensitive =
!(source is AudioCdSource || source is DapSource);
}
@@ -1120,6 +1122,8 @@
gxml["DapContainer"].Hide();
}
+ playlistView.SyncColumn.Visible = source is LibrarySource;
+
// Make some choices for audio CDs, they can't be rated,
nor have plays or
// last-played info. Only show the rip button for audio CDs
gxml["SearchLabel"].Sensitive = source.SearchEnabled;
@@ -1556,7 +1560,7 @@
"/SongViewPopup/AddToPlaylist") as MenuItem;
rating_menu_item =
Globals.ActionManager.GetWidget("/SongViewPopup/Rating") as MenuItem;
}
-
+
bool sensitive = playlistView.Selection.CountSelectedRows()
> 0;
if(sensitive && (SourceManager.ActiveSource is
LibrarySource || SourceManager.ActiveSource is PlaylistSource)) {
@@ -1612,6 +1616,20 @@
plMenu.ShowAll();
ratingMenu.ShowAll();
+
+ if (SourceManager.ActiveSource is LibrarySource)
+ {
+ bool showCheck = false;
+ bool showUncheck = false;
+ foreach(TreePath path in
playlistView.Selection.GetSelectedRows()) {
+ LibraryTrackInfo track =
(LibraryTrackInfo)playlistModel.PathTrackInfo(path);
+ if (track.ToSync == true) showUncheck = true;
+ if (track.ToSync == false) showCheck = true;
+ }
+
+ Globals.ActionManager["CheckSongsAction"].Visible =
showCheck;
+ Globals.ActionManager["UncheckSongsAction"].Visible
= showUncheck;
+ }
} else {
Globals.ActionManager["AddToPlaylistAction"].Visible =
false;
Globals.ActionManager["RatingAction"].Visible = false;
@@ -2041,7 +2059,7 @@
switch(md.Run()) {
case (int)ResponseType.Ok:
-
dapSource.Device.Save(Globals.Library.Tracks.Values);
+
dapSource.Device.Save(Globals.Library.GetSyncTracks());
break;
case (int)ResponseType.Apply:
dapSource.Device.Save();
@@ -2313,6 +2331,34 @@
suspendSearch = false;
playlistView.HasFocus = true;
+ }
+
+ private void OnCheckSongsAction(object o, EventArgs args)
+ {
+ int selCount = playlistView.Selection.CountSelectedRows();
+
+ if(selCount <= 0) {
+ return;
+ }
+
+ foreach(TreePath path in
playlistView.Selection.GetSelectedRows()) {
+ LibraryTrackInfo track =
(LibraryTrackInfo)playlistModel.PathTrackInfo(path);
+ track.ToSync = true;
+ }
+ }
+
+ private void OnUncheckSongsAction(object o, EventArgs args)
+ {
+ int selCount = playlistView.Selection.CountSelectedRows();
+
+ if(selCount <= 0) {
+ return;
+ }
+
+ foreach(TreePath path in
playlistView.Selection.GetSelectedRows()) {
+ LibraryTrackInfo track =
(LibraryTrackInfo)playlistModel.PathTrackInfo(path);
+ track.ToSync = false;
+ }
}
// --- Help Menu ---
Index: src/PlaylistView.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/PlaylistView.cs,v
retrieving revision 1.54
diff -u -r1.54 PlaylistView.cs
--- src/PlaylistView.cs 5 Aug 2006 20:51:12 -0000 1.54
+++ src/PlaylistView.cs 6 Sep 2006 00:02:36 -0000
@@ -74,6 +74,7 @@
Pixbuf ripColumnPixbuf;
public TreeViewColumn RipColumn;
+ public TreeViewColumn SyncColumn;
public PlaylistColumn RatingColumn;
public PlaylistColumn PlaysColumn;
public PlaylistColumn LastPlayedColumn;
@@ -177,7 +178,22 @@
RipColumn.PackStart(ripRenderer, true);
RipColumn.SetCellDataFunc(ripRenderer, new
TreeCellDataFunc(RipCellInd));
InsertColumn(RipColumn, 1);
-
+
+ // Add sync column
+ SyncColumn = new TreeViewColumn();
+ SyncColumn.Expand = false;
+ SyncColumn.Resizable = false;
+ SyncColumn.Clickable = false;
+ SyncColumn.Reorderable = false;
+ SyncColumn.Visible = true;
+
+ CellRendererToggle syncRenderer = new CellRendererToggle();
+ syncRenderer.Activatable = true;
+ syncRenderer.Toggled += OnSyncToggled;
+ SyncColumn.PackStart(syncRenderer, true);
+ SyncColumn.SetCellDataFunc(syncRenderer, new
TreeCellDataFunc(SyncCellInd));
+ InsertColumn(SyncColumn, 1);
+
ColumnDragFunction = new
TreeViewColumnDropFunc(CheckColumnDrop);
Model = this.model = model;
@@ -222,6 +238,18 @@
}
}
+
+ private void OnSyncToggled(object o, ToggledArgs args)
+ {
+ try {
+ LibraryTrackInfo ti =
(LibraryTrackInfo)model.PathTrackInfo(new TreePath(args.Path));
+ CellRendererToggle renderer = (CellRendererToggle)o;
+ ti.ToSync = !ti.ToSync;
+ renderer.Active = ti.ToSync;
+ } catch(Exception) {
+
+ }
+ }
private bool CheckColumnDrop(TreeView tree, TreeViewColumn col,
TreeViewColumn prev,
TreeViewColumn next)
@@ -426,6 +454,19 @@
toggle.Sensitive = ti.CanPlay && !ti.IsRipped;
toggle.Activatable = toggle.Sensitive;
toggle.Active = ti.CanRip && !ti.IsRipped;
+ } else {
+ toggle.Active = false;
+ }
+ }
+
+ protected void SyncCellInd(TreeViewColumn tree_column,
CellRenderer cell,
+ TreeModel tree_model, TreeIter iter)
+ {
+ CellRendererToggle toggle = (CellRendererToggle)cell;
+ LibraryTrackInfo ti = model.IterTrackInfo(iter) as
LibraryTrackInfo;
+
+ if(ti != null) {
+ toggle.Active = ti.ToSync;
} else {
toggle.Active = false;
}
Index: src/Banshee.Base/ActionManager.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Base/ActionManager.cs,v
retrieving revision 1.22
diff -u -r1.22 ActionManager.cs
--- src/Banshee.Base/ActionManager.cs 4 Sep 2006 00:22:29 -0000 1.22
+++ src/Banshee.Base/ActionManager.cs 6 Sep 2006 00:02:36 -0000
@@ -236,7 +236,15 @@
new ActionEntry("RatingAction", null,
Catalog.GetString("Rating"), null,
- Catalog.GetString("Set rating for selected songs"),
null)
+ Catalog.GetString("Set rating for selected songs"),
null),
+
+ new ActionEntry("CheckSongsAction", null,
+ Catalog.GetString("Check Song(s)"), null,
+ Catalog.GetString("Mark songs to be synced with
audio player"), null),
+
+ new ActionEntry("UncheckSongsAction", null,
+ Catalog.GetString("Uncheck Song(s)"), null,
+ Catalog.GetString("Unmark songs to be synced with
audio player"), null)
});
ui.InsertActionGroup(song_actions, 0);
Index: src/Banshee.Base/Database.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Base/Database.cs,v
retrieving revision 1.7
diff -u -r1.7 Database.cs
--- src/Banshee.Base/Database.cs 22 May 2006 17:01:49 -0000 1.7
+++ src/Banshee.Base/Database.cs 6 Sep 2006 00:02:36 -0000
@@ -74,7 +74,9 @@
LastPlayedStamp INTEGER,
DateAddedStamp INTEGER,
- RemoteLookupStatus INTEGER
+ RemoteLookupStatus INTEGER,
+
+ ToSync INTEGER NOT NULL DEFAULT 1
)");
}
@@ -120,7 +122,14 @@
} catch(ApplicationException) {
LogCore.Instance.PushDebug("Adding new database
column", "RemoteLookupStatus INTEGER");
Execute("ALTER TABLE Tracks ADD RemoteLookupStatus
INTEGER");
- }
+ }
+
+ try {
+ QuerySingle("SELECT ToSync FROM Tracks LIMIT 1");
+ } catch(ApplicationException) {
+ LogCore.Instance.PushDebug("Adding new database
column", "ToSync INTEGER");
+ Execute("ALTER TABLE Tracks ADD ToSync INTEGER NOT NULL
DEFAULT 1");
+ }
try {
QuerySingle("SELECT ViewOrder FROM PlaylistEntries
LIMIT 1");
Index: src/Banshee.Base/Library.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Base/Library.cs,v
retrieving revision 1.12
diff -u -r1.12 Library.cs
--- src/Banshee.Base/Library.cs 28 Jul 2006 17:49:47 -0000 1.12
+++ src/Banshee.Base/Library.cs 6 Sep 2006 00:02:37 -0000
@@ -301,5 +301,19 @@
{
return PathUtil.MakeFileNameKey(uri);
}
+
+ public ICollection<TrackInfo> GetSyncTracks()
+ {
+ List<TrackInfo> syncTracks = new List<TrackInfo>();
+ foreach (LibraryTrackInfo track in Tracks.Values)
+ {
+ if (track.ToSync == true)
+ {
+ syncTracks.Add(track);
+ }
+ }
+
+ return syncTracks;
+ }
}
}
Index: src/Banshee.Base/LibraryTrackInfo.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Base/LibraryTrackInfo.cs,v
retrieving revision 1.14
diff -u -r1.14 LibraryTrackInfo.cs
--- src/Banshee.Base/LibraryTrackInfo.cs 24 Aug 2006 16:35:50 -0000 1.14
+++ src/Banshee.Base/LibraryTrackInfo.cs 6 Sep 2006 00:02:37 -0000
@@ -39,6 +39,8 @@
{
public class LibraryTrackInfo : TrackInfo
{
+ protected bool to_sync;
+
public static int GetId(SafeUri lookup)
{
string query = String.Format(@"
@@ -174,7 +176,8 @@
this.duration = duration;
this.asin = asin;
this.remote_lookup_status = remote_lookup_status;
-
+ this.to_sync = true;
+
this.date_added = DateTime.Now;
CheckIfExists(uri);
@@ -200,7 +203,8 @@
LoadFromFile(filename);
string new_filename = MoveToPlace(filename, true);
uri = new SafeUri(new_filename != null ? new_filename :
filename);
- CheckIfExists(uri);
+ CheckIfExists(uri);
+ this.to_sync = true;
SaveToDatabase(true);
}
@@ -313,7 +317,8 @@
"Rating", rating,
"NumberOfPlays", play_count,
"LastPlayedStamp",
DateTimeUtil.FromDateTime(last_played),
- "RemoteLookupStatus", (int)remote_lookup_status);
+ "RemoteLookupStatus", (int)remote_lookup_status,
+ "ToSync", Convert.ToInt32(to_sync));
} else {
tracksQuery = new Update("Tracks",
"Uri", uri.AbsoluteUri,
@@ -337,7 +342,8 @@
"Rating", rating,
"NumberOfPlays", play_count,
"LastPlayedStamp",
DateTimeUtil.FromDateTime(last_played),
- "RemoteLookupStatus", (int)remote_lookup_status) +
+ "RemoteLookupStatus", (int)remote_lookup_status,
+ "ToSync", Convert.ToInt32(to_sync)) +
new Where(new Compare("TrackID", Op.EqualTo,
track_id));// +
// new Limit(1);
}
@@ -420,6 +426,8 @@
if(temp_stamp > 0) {
date_added = DateTimeUtil.ToDateTime(temp_stamp);
}
+
+ to_sync = Convert.ToBoolean(reader["ToSync"]);
}
private void LoadFromFile(string filename)
@@ -467,6 +475,16 @@
new Where(new Compare("TrackID", Op.EqualTo,
track_id));
Core.Library.Db.Execute(query);*/
Save();
+ }
+
+ public bool ToSync {
+ get {
+ return to_sync;
+ }
+ set {
+ to_sync = value;
+ Save();
+ }
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]