← Back to team overview

nuvola-player-devel team mailing list archive

[Merge] lp:~mpdeimos/nuvola-player/nuvola-player into lp:nuvola-player

 

mpdeimos has proposed merging lp:~mpdeimos/nuvola-player/nuvola-player into lp:nuvola-player.

Commit message:
Implements:
* Bug #1065602: Mouse back/forward button interaction
* Bug #1212167: Back/forward buttons in UI (default off) for Google Play

Requested reviews:
  Jiří Janoušek (fenryxo)

For more details, see:
https://code.launchpad.net/~mpdeimos/nuvola-player/nuvola-player/+merge/199922

Implements:
* Bug #1065602: Mouse back/forward button interaction
* Bug #1212167: Back/forward buttons in UI (default off) for Google Play

For the latter a canNavigateBack/Forward JSApi property would be cool, but worked around this with navigation state emulation.

PS: This is my first collaboration (pull request) on launchpad, so let me know if I'm doing something wrong ;)
-- 
https://code.launchpad.net/~mpdeimos/nuvola-player/nuvola-player/+merge/199922
Your team Nuvola Player Development is subscribed to branch lp:nuvola-player.
=== modified file 'data/nuvolaplayer/services/googleplay/integration.js'
--- data/nuvolaplayer/services/googleplay/integration.js	2013-11-22 22:02:57 +0000
+++ data/nuvolaplayer/services/googleplay/integration.js	2013-12-22 23:39:18 +0000
@@ -254,8 +254,85 @@
 			head.appendChild(style);
 		}
 		
+		if (Nuvola.config.navigationButtons === true)
+		{
+			this.addNavigationButtons();
+		}
+		
 		if (Nuvola.config.simulateActivity === true)
+		{
 			setTimeout(Nuvola.bind(this, this.simulateActivity), ACTIVITY_INTERVAL);
+		}
+	}
+	
+	Integration.prototype.addNavigationButtons = function(){
+		var queryBar = document.getElementById("gbq2");
+		if (!queryBar)
+		{
+			console.log("Could not find the query bar.");
+			return;
+		}
+		
+		var queryBarFirstChild = queryBar.firstChild;
+		
+		var navigateBack = document.createElement('button');
+		navigateBack.className = "button small vertical-align";
+		navigateBack.disabled = true;
+		navigateBack.style.float = "left";
+		navigateBack.style.marginRight = "0px";
+		navigateBack.style.borderTopRightRadius = "2px";
+		navigateBack.style.borderBottomRightRadius = "2px";
+		navigateBack.innerText = "<";
+		navigateBack.addEventListener('click', function() {window.history.back();});
+		queryBar.insertBefore(navigateBack, queryBarFirstChild);
+		
+		var navigateFwd = document.createElement('button');
+		navigateFwd.className = "button small vertical-align";
+		navigateFwd.disabled = true;
+		navigateFwd.style.float = "left";
+		navigateFwd.style.marginRight = "15px";
+		navigateFwd.style.borderLeft = "none";
+		navigateFwd.style.borderTopLeftRadius = "2px";
+		navigateFwd.style.borderLeftRightRadius = "2px";
+		navigateFwd.innerText = ">";
+		navigateFwd.addEventListener('click', function() {window.history.forward();});
+		queryBar.insertBefore(navigateFwd, queryBarFirstChild);
+		
+		var navigationStack = [];
+		var updateNavigationButtons = function(evt)
+		{
+			var pageIndex; // one-based
+			var found = false;
+			for (pageIndex = navigationStack.length; pageIndex > 0; pageIndex--)
+			{
+				var url = navigationStack[pageIndex - 1];
+				if (url === evt.newURL)
+				{
+					found = true;
+					break;
+				}
+			}
+			if (!found)
+			{
+				for (pageIndex = navigationStack.length; pageIndex > 0; pageIndex--)
+				{
+					var url = navigationStack[pageIndex - 1];
+					if (url === evt.oldURL)
+					{
+						// this means a new site is added to the top of the stack,
+						// and the rest can safely be removed.
+						navigationStack = navigationStack.slice(0, pageIndex);
+						navigationStack.push(evt.newURL);
+						pageIndex++; // advance to current page
+						break;
+					}
+				}
+			}
+			navigateBack.disabled = pageIndex == 1;
+			navigateFwd.disabled = pageIndex == navigationStack.length;
+		};
+		navigationStack.push(document.location.toString());
+		window.addEventListener('hashchange', updateNavigationButtons)
 	}
 	
 	Integration.prototype.simulateActivity = function(){

=== modified file 'data/nuvolaplayer/services/googleplay/settings.js'
--- data/nuvolaplayer/services/googleplay/settings.js	2012-07-31 13:46:59 +0000
+++ data/nuvolaplayer/services/googleplay/settings.js	2013-12-22 23:39:18 +0000
@@ -37,6 +37,15 @@
 	}
 ));
 
+form.append(new Nuvola.Checkbox(_("Integrate navigation buttons"),
+	Nuvola.config.navigationButtons === true,
+	function(){
+		Nuvola.config.navigationButtons = this.checked ? true : false;
+		Nuvola.saveConfig();
+		form.showReloadNotice();
+	}
+));
+
 form.append(new Nuvola.Checkbox(_("Don't stop playback due to inactivity"),
 	Nuvola.config.simulateActivity === true,
 	function(){

=== modified file 'src/nuvola/gui/mainwebview.vala'
--- src/nuvola/gui/mainwebview.vala	2013-08-15 20:08:26 +0000
+++ src/nuvola/gui/mainwebview.vala	2013-12-22 23:39:18 +0000
@@ -103,6 +103,8 @@
 
 		navigation_policy_decision_requested.connect(on_new_page);
 		new_window_policy_decision_requested.connect(on_new_window);
+		
+		this.button_release_event.connect(this.on_mouse_button_released);
 	}
 	
 	public override WebKit.WebView create_web_view(WebFrame frame){
@@ -230,6 +232,24 @@
 	}
 	
 	/**
+	 * Handles special mouse buttons (back & forward navigation)
+	 */
+	private bool on_mouse_button_released(Gdk.EventButton button)
+	{
+		switch (button.button)
+		{
+			case 8:  // mouse back button
+				this.go_back();
+				return true;
+			case 9:  // mouse forward button
+				this.go_forward();
+				return true;
+			default: // ignore all other buttons
+				return false;
+		}
+	}
+	
+	/**
 	 * Logs debug message with libfenryxo domain // FIXME
 	 * @param format format string
 	 */

=== modified file 'src/nuvola/gui/servicesmanagerview.vala'
--- src/nuvola/gui/servicesmanagerview.vala	2013-07-05 13:26:10 +0000
+++ src/nuvola/gui/servicesmanagerview.vala	2013-12-22 23:39:18 +0000
@@ -108,6 +108,7 @@
 		manager_buttons.add(button_remove);
 		
 		page = new Diorite.SimpleDocView();
+		page.editable = false;
 		page.wrap_mode = Gtk.WrapMode.WORD_CHAR;
 		page.border_width = 15;
 		


Follow ups