banshee r3489 - in trunk/banshee: . build src/Extensions src/Extensions/Banshee.Bookmarks src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks src/Extensions/Banshee.Bookmarks/Resources
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3489 - in trunk/banshee: . build src/Extensions src/Extensions/Banshee.Bookmarks src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks src/Extensions/Banshee.Bookmarks/Resources
- Date: Thu, 20 Mar 2008 03:33:47 +0000 (GMT)
Author: gburt
Date: Thu Mar 20 03:33:46 2008
New Revision: 3489
URL: http://svn.gnome.org/viewvc/banshee?rev=3489&view=rev
Log:
2008-03-19 Gabriel Burt <gabriel burt gmail com>
Patch from Bertrand Lorentz porting the Bookmarks plugin.
* build/build.environment.mk:
* configure.ac:
* src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks.addin.xml:
* src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks.mdp:
* src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/BookmarksService.cs:
* src/Extensions/Banshee.Bookmarks/Makefile.am:
* src/Extensions/Banshee.Bookmarks/Resources/BookmarksMenu.xml:
* src/Extensions/Extensions.mds:
* src/Extensions/Makefile.am: Port the Bookmarks plugin to trunk.
Added:
trunk/banshee/src/Extensions/Banshee.Bookmarks/ (props changed)
trunk/banshee/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/
trunk/banshee/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks.addin.xml
trunk/banshee/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks.mdp
trunk/banshee/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/BookmarksService.cs
trunk/banshee/src/Extensions/Banshee.Bookmarks/Makefile.am
trunk/banshee/src/Extensions/Banshee.Bookmarks/Resources/
trunk/banshee/src/Extensions/Banshee.Bookmarks/Resources/BookmarksMenu.xml
Modified:
trunk/banshee/ChangeLog
trunk/banshee/build/build.environment.mk
trunk/banshee/configure.ac
trunk/banshee/src/Extensions/Extensions.mds
trunk/banshee/src/Extensions/Makefile.am
Modified: trunk/banshee/build/build.environment.mk
==============================================================================
--- trunk/banshee/build/build.environment.mk (original)
+++ trunk/banshee/build/build.environment.mk Thu Mar 20 03:33:46 2008
@@ -119,6 +119,7 @@
REF_BACKEND_UNIX = $(LINK_BANSHEE_CORE_DEPS) $(LINK_MONO_POSIX)
# Extensions
+REF_EXTENSION_BOOKMARKS = $(LINK_BANSHEE_THICKCLIENT_DEPS)
REF_EXTENSION_MULTIMEDIAKEYS = $(LINK_BANSHEE_SERVICES_DEPS)
REF_EXTENSION_NOTIFICATIONAREA = $(LINK_BANSHEE_THICKCLIENT_DEPS)
REF_EXTENSION_PLAYQUEUE = $(LINK_BANSHEE_THICKCLIENT_DEPS)
Modified: trunk/banshee/configure.ac
==============================================================================
--- trunk/banshee/configure.ac (original)
+++ trunk/banshee/configure.ac Thu Mar 20 03:33:46 2008
@@ -150,6 +150,7 @@
src/Libraries/Mono.Media/Makefile
src/Extensions/Makefile
+src/Extensions/Banshee.Bookmarks/Makefile
src/Extensions/Banshee.Lastfm/Makefile
src/Extensions/Banshee.MultimediaKeys/Makefile
src/Extensions/Banshee.NotificationArea/Makefile
Added: trunk/banshee/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks.addin.xml
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks.addin.xml Thu Mar 20 03:33:46 2008
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Addin
+ id="Banshee.Bookmarks"
+ version="1.0"
+ compatVersion="1.0"
+ copyright="Â 2008 Novell Inc. Licensed under the MIT X11 license."
+ name="Bookmarks"
+ description="Bookmark your position in tracks."
+ url="http://banshee-project.org/"
+ defaultEnabled="true">
+
+ <Dependencies>
+ <Addin id="Banshee.Services" version="1.0"/>
+ </Dependencies>
+
+ <Extension path="/Banshee/ServiceManager/Service">
+ <Service class="Banshee.Bookmarks.BookmarksService"/>
+ </Extension>
+
+</Addin>
Added: trunk/banshee/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks.mdp
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks.mdp Thu Mar 20 03:33:46 2008
@@ -0,0 +1,30 @@
+<Project name="Banshee.Bookmarks" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
+ <Configurations active="Debug">
+ <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+ <Output directory="../../../bin" assemblyKeyFile="." assembly="Banshee.Bookmarks" />
+ <Build debugmode="True" target="Library" />
+ <Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+ </Configuration>
+ </Configurations>
+ <Contents>
+ <File name="Banshee.Bookmarks.addin.xml" subtype="Code" buildaction="EmbedAsResource" />
+ <File name="Resources/BookmarksMenu.xml" subtype="Code" buildaction="EmbedAsResource" />
+ <File name="Banshee.Bookmarks/BookmarksService.cs" subtype="Code" buildaction="Compile" />
+ </Contents>
+ <References>
+ <ProjectReference type="Project" localcopy="True" refto="Banshee.Core" />
+ <ProjectReference type="Project" localcopy="True" refto="Banshee.Services" />
+ <ProjectReference type="Project" localcopy="True" refto="Hyena" />
+ <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ </References>
+ <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="./Makefile.am">
+ <BuildFilesVar Sync="True" Name="SOURCES" />
+ <DeployFilesVar />
+ <ResourcesVar Sync="True" Name="RESOURCES" />
+ <OthersVar />
+ <GacRefVar />
+ <AsmRefVar />
+ <ProjectRefVar />
+ </MonoDevelop.Autotools.MakefileInfo>
+</Project>
\ No newline at end of file
Added: trunk/banshee/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/BookmarksService.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/BookmarksService.cs Thu Mar 20 03:33:46 2008
@@ -0,0 +1,327 @@
+using System;
+using System.Data;
+using System.Collections.Generic;
+using Gtk;
+using Mono.Unix;
+
+using Hyena.Data.Sqlite;
+
+using Banshee.Base;
+using Banshee.Collection;
+using Banshee.Collection.Database;
+using Banshee.Gui;
+using Banshee.ServiceStack;
+using Hyena;
+
+namespace Banshee.Bookmarks
+{
+ public class BookmarksService : IExtensionService, IDisposable
+ {
+ private BookmarkUI ui;
+
+ public BookmarksService ()
+ {
+ }
+
+ void IExtensionService.Initialize ()
+ {
+ Bookmark.Initialize();
+ ui = BookmarkUI.Instance;
+ }
+
+ public void Dispose ()
+ {
+ if (ui != null)
+ ui.Dispose();
+ }
+
+ string IService.ServiceName {
+ get { return "BookmarksService"; }
+ }
+ }
+
+ public class BookmarkUI
+ {
+ private Menu bookmark_menu;
+ private Menu remove_menu;
+
+ private ImageMenuItem bookmark_item;
+ private ImageMenuItem new_item;
+ private ImageMenuItem remove_item;
+ private SeparatorMenuItem separator;
+
+ private List<Bookmark> bookmarks = new List<Bookmark>();
+ private Dictionary<Bookmark, MenuItem> select_items = new Dictionary<Bookmark, MenuItem>();
+ private Dictionary<Bookmark, MenuItem> remove_items = new Dictionary<Bookmark, MenuItem>();
+ private Dictionary<MenuItem, Bookmark> bookmark_map = new Dictionary<MenuItem, Bookmark>();
+
+ private InterfaceActionService action_service;
+ private ActionGroup actions;
+ private uint ui_manager_id;
+
+ private static BookmarkUI instance = null;
+ public static BookmarkUI Instance {
+ get {
+ if (instance == null)
+ instance = new BookmarkUI();
+ return instance;
+ }
+ }
+
+ public static bool Instantiated {
+ get { return instance != null; }
+ }
+
+ private BookmarkUI()
+ {
+ action_service = ServiceManager.Get<InterfaceActionService> ("InterfaceActionService");
+
+ actions = new ActionGroup("Bookmarks");
+
+ actions.Add(new ActionEntry [] {
+ new ActionEntry("BookmarksAction", null,
+ Catalog.GetString("_Bookmarks"), null,
+ null, null),
+ new ActionEntry("BookmarksAddAction", Stock.Add,
+ Catalog.GetString("_Add Bookmark"), "<control>D",
+ Catalog.GetString("Bookmark the Position in the Current Track"),
+ HandleNewBookmark)
+ });
+
+ action_service.UIManager.InsertActionGroup(actions, 0);
+ ui_manager_id = action_service.UIManager.AddUiFromResource("BookmarksMenu.xml");
+ bookmark_item = action_service.UIManager.GetWidget("/MainMenu/ToolsMenu/Bookmarks") as ImageMenuItem;
+ new_item = action_service.UIManager.GetWidget("/MainMenu/ToolsMenu/Bookmarks/Add") as ImageMenuItem;
+
+ bookmark_menu = bookmark_item.Submenu as Menu;
+ bookmark_item.Selected += HandleMenuShown;
+
+ remove_item = new ImageMenuItem(Catalog.GetString("_Remove Bookmark"));
+ remove_item.Sensitive = false;
+ remove_item.Image = new Image(Stock.Remove, IconSize.Menu);
+
+ remove_item.Submenu = remove_menu = new Menu();
+ bookmark_menu.Append(remove_item);
+
+ LoadBookmarks ();
+ }
+
+ private void HandleMenuShown(object sender, EventArgs args)
+ {
+ new_item.Sensitive = (ServiceManager.PlayerEngine.CurrentTrack != null);
+ }
+
+ private void HandleNewBookmark(object sender, EventArgs args)
+ {
+ DatabaseTrackInfo track = ServiceManager.PlayerEngine.CurrentTrack as DatabaseTrackInfo;
+ if (track != null) {
+ try {
+ Bookmark bookmark = new Bookmark(track.TrackId, ServiceManager.PlayerEngine.Position);
+ AddBookmark(bookmark);
+ } catch (Exception e) {
+ Log.Warning("Unable to Add New Bookmark", e.ToString(), false);
+ }
+ }
+ }
+
+ private void LoadBookmarks ()
+ {
+ separator = new SeparatorMenuItem();
+
+ foreach (Bookmark bookmark in Bookmark.LoadAll()) {
+ AddBookmark(bookmark);
+ }
+
+ bookmark_item.ShowAll();
+ }
+
+ public void AddBookmark(Bookmark bookmark)
+ {
+ if (select_items.ContainsKey(bookmark))
+ return;
+
+ bookmarks.Add(bookmark);
+ if (bookmarks.Count == 1) {
+ bookmark_menu.Append(separator);
+ remove_item.Sensitive = true;
+ }
+
+ // Add menu item to jump to this bookmark
+ ImageMenuItem select_item = new ImageMenuItem(bookmark.Name.Replace("_", "__"));
+ select_item.Image = new Image(Stock.JumpTo, IconSize.Menu);
+ select_item.Activated += delegate {
+ Console.WriteLine ("item delegate, main thread? {0}", Banshee.Base.ThreadAssist.InMainThread);
+ bookmark.JumpTo();
+ };
+ bookmark_menu.Append(select_item);
+ select_items[bookmark] = select_item;
+
+ // Add menu item to remove this bookmark
+ ImageMenuItem rem = new ImageMenuItem(bookmark.Name.Replace("_", "__"));
+ rem.Image = new Image(Stock.Remove, IconSize.Menu);
+ rem.Activated += delegate {
+ bookmark.Remove();
+ };
+ remove_menu.Append(rem);
+ remove_items[bookmark] = rem;
+ bookmark_map[rem] = bookmark;
+
+ bookmark_menu.ShowAll();
+ }
+
+ public void RemoveBookmark(Bookmark bookmark)
+ {
+ if (!remove_items.ContainsKey(bookmark))
+ return;
+
+ bookmark_menu.Remove(select_items[bookmark]);
+ remove_menu.Remove(remove_items[bookmark]);
+ bookmarks.Remove(bookmark);
+ select_items.Remove(bookmark);
+ bookmark_map.Remove(remove_items[bookmark]);
+ remove_items.Remove(bookmark);
+
+ if (bookmarks.Count == 0) {
+ bookmark_menu.Remove(separator);
+ remove_item.Sensitive = false;
+ }
+ }
+
+ public void Dispose()
+ {
+ action_service.UIManager.RemoveUi(ui_manager_id);
+ action_service.UIManager.RemoveActionGroup(actions);
+ actions = null;
+
+ instance = null;
+ }
+ }
+
+ public class Bookmark
+ {
+ private int id;
+ private int track_id;
+ private uint position;
+ private DateTime created_at;
+
+ // Translators: This is used to generate bookmark names. {0} is track title, {1} is minutes
+ // (possibly more than two digits) and {2} is seconds (between 00 and 60).
+ private readonly string bookmark_format = Catalog.GetString("{0} ({1}:{2:00})");
+
+ private string name;
+ public string Name {
+ get { return name; }
+ set { name = value; }
+ }
+
+ public DateTime CreatedAt {
+ get { return created_at; }
+ }
+
+ public TrackInfo Track {
+ get { return DatabaseTrackInfo.Provider.FetchSingle(track_id); }
+ }
+
+ private Bookmark(int id, int track_id, uint position, DateTime created_at)
+ {
+ this.id = id;
+ this.track_id = track_id;
+ this.position = position;
+ this.created_at = created_at;
+ uint position_seconds = position/1000;
+ Name = String.Format(bookmark_format, Track.DisplayTrackTitle, position_seconds/60, position_seconds%60);
+ }
+
+ public Bookmark(int track_id, uint position)
+ {
+ Console.WriteLine ("Bookmark, main thread? {0}", Banshee.Base.ThreadAssist.InMainThread);
+ this.track_id = track_id;
+ this.position = position;
+ this.created_at = DateTime.Now;
+ uint position_seconds = position/1000;
+ Name = String.Format(bookmark_format, Track.DisplayTrackTitle, position_seconds/60, position_seconds%60);
+
+ this.id = ServiceManager.DbConnection.Execute (new HyenaSqliteCommand (@"
+ INSERT INTO Bookmarks
+ (TrackID, Position, CreatedAt)
+ VALUES (?, ?, ?)",
+ track_id, position, DateTimeUtil.FromDateTime(created_at) ));
+ }
+
+ public void JumpTo()
+ {
+ DatabaseTrackInfo track = Track as DatabaseTrackInfo;
+ DatabaseTrackInfo current_track = ServiceManager.PlayerEngine.CurrentTrack as DatabaseTrackInfo;
+ if (track != null) {
+ if (current_track == null || current_track.TrackId != track.TrackId) {
+ ServiceManager.PlayerEngine.Open (track);
+ }
+
+ if (ServiceManager.PlayerEngine.CanSeek) {
+ ServiceManager.PlayerEngine.Position = position;
+ }
+
+ if (ServiceManager.PlayerEngine.CurrentState != Banshee.MediaEngine.PlayerEngineState.Playing) {
+ ServiceManager.PlayerEngine.Play ();
+ }
+ } else {
+ Remove();
+ }
+ }
+
+ public void Remove()
+ {
+ try {
+ ServiceManager.DbConnection.Execute(String.Format(
+ "DELETE FROM Bookmarks WHERE BookmarkID = {0}", id
+ ));
+
+ if (BookmarkUI.Instantiated)
+ BookmarkUI.Instance.RemoveBookmark(this);
+ } catch (Exception e) {
+ Log.Warning("Error Removing Bookmark", e.ToString(), false);
+ }
+ }
+
+ public static List<Bookmark> LoadAll()
+ {
+ List<Bookmark> bookmarks = new List<Bookmark>();
+
+ IDataReader reader = ServiceManager.DbConnection.Query(
+ "SELECT BookmarkID, TrackID, Position, CreatedAt FROM Bookmarks"
+ );
+
+ while (reader.Read()) {
+ try {
+ bookmarks.Add(new Bookmark(
+ (int) reader[0], (int) reader[1], (uint)(int) reader[2],
+ DateTimeUtil.ToDateTime(Convert.ToInt64(reader[3]))
+ ));
+ } catch (Exception e) {
+ ServiceManager.DbConnection.Execute(String.Format(
+ "DELETE FROM Bookmarks WHERE BookmarkID = {0}", (int)reader[0]
+ ));
+
+ Log.Warning("Error Loading Bookmark", e.ToString(), false);
+ }
+ }
+ reader.Dispose();
+
+ return bookmarks;
+ }
+
+ public static void Initialize()
+ {
+ if (!ServiceManager.DbConnection.TableExists("Bookmarks")) {
+ ServiceManager.DbConnection.Execute(@"
+ CREATE TABLE Bookmarks (
+ BookmarkID INTEGER PRIMARY KEY,
+ TrackID INTEGER NOT NULL,
+ Position INTEGER NOT NULL,
+ CreatedAt INTEGER NOT NULL
+ )
+ ");
+ }
+ }
+ }
+}
Added: trunk/banshee/src/Extensions/Banshee.Bookmarks/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.Bookmarks/Makefile.am Thu Mar 20 03:33:46 2008
@@ -0,0 +1,13 @@
+ASSEMBLY = Banshee.Bookmarks
+TARGET = library
+LINK = $(REF_EXTENSION_BOOKMARKS)
+INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
+
+SOURCES = Banshee.Bookmarks/BookmarksService.cs
+
+RESOURCES = \
+ Banshee.Bookmarks.addin.xml \
+ Resources/BookmarksMenu.xml
+
+include $(top_srcdir)/build/build.mk
+
Added: trunk/banshee/src/Extensions/Banshee.Bookmarks/Resources/BookmarksMenu.xml
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.Bookmarks/Resources/BookmarksMenu.xml Thu Mar 20 03:33:46 2008
@@ -0,0 +1,9 @@
+<ui>
+ <menubar name="MainMenu">
+ <menu name="ToolsMenu" action="ToolsMenuAction">
+ <menu name="Bookmarks" action="BookmarksAction">
+ <menuitem name="Add" action="BookmarksAddAction" />
+ </menu>
+ </menu>
+ </menubar>
+</ui>
Modified: trunk/banshee/src/Extensions/Extensions.mds
==============================================================================
--- trunk/banshee/src/Extensions/Extensions.mds (original)
+++ trunk/banshee/src/Extensions/Extensions.mds Thu Mar 20 03:33:46 2008
@@ -1,11 +1,12 @@
<Combine name="Extensions" fileversion="2.0">
<Configurations active="Debug">
<Configuration name="Debug" ctype="CombineConfiguration">
- <Entry build="True" name="Banshee.NotificationArea" configuration="Debug" />
+ <Entry build="True" name="Banshee.Bookmarks" configuration="Debug" />
+ <Entry build="True" name="Banshee.Lastfm" configuration="Debug" />
<Entry build="True" name="Banshee.MultimediaKeys" configuration="Debug" />
- <Entry build="True" name="Banshee.PlayQueue" configuration="Debug" />
- <Entry build="False" name="Banshee.Lastfm" configuration="Debug" />
+ <Entry build="True" name="Banshee.NotificationArea" configuration="Debug" />
<Entry build="True" name="Banshee.NowPlaying" configuration="Debug" />
+ <Entry build="True" name="Banshee.PlayQueue" configuration="Debug" />
</Configuration>
</Configurations>
<StartMode startupentry="Banshee.NotificationArea" single="True">
@@ -13,6 +14,7 @@
<Execute type="None" entry="Banshee.DapCore" />
<Execute type="None" entry="Banshee.Dap.MassStorage" />
<Execute type="None" entry="Banshee.NowPlaying" />
+ <Execute type="None" entry="Banshee.Bookmarks" />
</StartMode>
<Entries>
<Entry filename="Banshee.NotificationArea/Banshee.NotificationArea.mdp" />
@@ -20,5 +22,6 @@
<Entry filename="Banshee.PlayQueue/Banshee.PlayQueue.mdp" />
<Entry filename="Banshee.Lastfm/Banshee.Lastfm.mdp" />
<Entry filename="Banshee.NowPlaying/Banshee.NowPlaying.mdp" />
+ <Entry filename="Banshee.Bookmarks/Banshee.Bookmarks.mdp" />
</Entries>
-</Combine>
\ No newline at end of file
+</Combine>
Modified: trunk/banshee/src/Extensions/Makefile.am
==============================================================================
--- trunk/banshee/src/Extensions/Makefile.am (original)
+++ trunk/banshee/src/Extensions/Makefile.am Thu Mar 20 03:33:46 2008
@@ -1,4 +1,5 @@
SUBDIRS = \
+ Banshee.Bookmarks \
Banshee.Lastfm \
Banshee.MultimediaKeys \
Banshee.NotificationArea \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]