Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoReX committed Sep 15, 2013
0 parents commit d2bfb73
Show file tree
Hide file tree
Showing 24 changed files with 451 additions and 0 deletions.
14 changes: 14 additions & 0 deletions chrome.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
content smplayerview chrome/content/

overlay chrome://browser/content/browser.xul chrome://smplayerview/content/smplayerviewOverlay.xul

skin smplayerview classic/1.0 chrome/skin/

style chrome://global/content/customizeToolbar.xul chrome://smplayerview/skin/skin.css
style chrome://browser/content/browser.xul chrome://smplayerview/skin/skin.css

locale smplayerview de-DE chrome/locale/de-DE/
locale smplayerview en-US chrome/locale/en-US/
locale smplayerview it chrome/locale/it/
locale smplayerview nl-NL chrome/locale/nl-NL/
locale smplayerview pt-BR chrome/locale/pt-BR/
40 changes: 40 additions & 0 deletions chrome/content/options.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://smplayerview/locale/smplayerview.dtd" >
<prefwindow
title="&smplayerview.prefs-title;"
id="smplayerviewprefs"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<stringbundleset>
<stringbundle id="smplayerview_strings" src="chrome://smplayerview/locale/smplayerview.properties"/>
</stringbundleset>
<script type="application/x-javascript" src="smplayerview.js"/>

<prefpane label="&smplayerview.prefs-title;">
<preferences>
<preference id="smplayerview-smplayerpath" name="extensions.smplayerview.smplayerpath" type="string"/>
</preferences>

<groupbox width="500">
<caption label="&smplayerview.prefs-pathtosmplayer;"/>
<description height="40">
&smplayerview.prefs-description;
</description>
<hbox>
<hbox width="100">
<label control="location" value="&smplayerview.prefs-pathtosmplayer;:"/>
</hbox>
<vbox>
<textbox type="text" id="location" preference="smplayerview-smplayerpath" size="75"/>
<hbox>
<button label="&smplayerview.prefs-test;" oncommand="smplayerview.test(document.getElementById('location').value);" />
<button label="&smplayerview.prefs-discover;" oncommand="smplayerview.discoverButton();" />
</hbox>
</vbox>
</hbox>
</groupbox>

</prefpane>

</prefwindow>
216 changes: 216 additions & 0 deletions chrome/content/smplayerview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
window.addEventListener(
"load",
function(e) {
smplayerview.init();
},
false
);

var smplayerview = {
badPath: "SMPlayer could not be found at the location you specified.",
notFound: "SMPlayer could not be found in the registry.",
smplayerPath: "",
smplayerParams: "",
smplayerviewBundle: null,
prefManager: null,
log: function(aText) {
var console = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
console.logStringMessage("SMPlayer View: "+aText);
},
init: function(){ // sets up event listeners
try {
document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", function(){smplayerview.context();}, false); // call context() when the context menu is opened
} catch (e) {
}

this.smplayerviewBundle = document.getElementById("smplayerview_strings");

this.prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);

// Get SMPlayer location from preferences
this.unicodeConverter = Components
.classes["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
this.unicodeConverter.charset = "UTF-8";
this.smplayerPath = this.unicodeConverter.ConvertToUnicode(this.prefManager.getCharPref("extensions.smplayerview.smplayerpath"));
if (this.smplayerPath=="") {
this.discover();
}
},
parseSMPlayerPath: function() {
// Post-process SMPlayer location
var params = "";
if (this.smplayerPath) {
var i;
if (this.smplayerPath.substr(0, 1)=='"') {
// The string starts with a quote, thus
// the second quote counts
this.smplayerPath = this.smplayerPath.substr(1);
i = this.smplayerPath.indexOf('"');
} else {
// The string does not start with a quote,
// thus the first blank counts
i = this.smplayerPath.indexOf(" ");
}

// Cut everything off after the filename
if (i!=-1) {
params = this.smplayerPath.substr(i+1);
this.smplayerPath = this.smplayerPath.substring(0, i);
}
}

// Pre-parse parameters
this.smplayerParams = new Array();
if (params!="") {
var p;
var q = /("(.*?)"|(\S+))/g;
while (p = q.exec(params)) {
if (p[1].length>0 && p[1][0]=='"') {
p[1] = p[1].substr(1, p[1].length-2);
}
this.smplayerParams.push(p[1]);
}
}
},
launch: function (href){
this.smplayerPath = this.unicodeConverter.ConvertToUnicode(this.prefManager.getCharPref("extensions.smplayerview.smplayerpath"));
this.parseSMPlayerPath();
this._launch(href);
},
_launch: function(href) {
if (!this.smplayerPath) {
alert(this.notFound);
return;
}

var targetFile=Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
targetFile.initWithPath(this.smplayerPath); // load path from pref into object
if (!targetFile.exists()) {
alert(this.smplayerviewBundle.getFormattedString("smplayerview.notexecutable", [this.smplayerPath]));
return;
}
var process=Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
var params = new Array();
for (var i=0; i<this.smplayerParams.length; i++) {
// Add every parameter, replacing %1 by the URL
params.push(this.smplayerParams[i].replace("%1", href));
}
if (params.length==0) {
// No parameters added yet
// Add URL
params.push(href);
}
process.init(targetFile);
process.run(false, params, params.length);
},
context: function(){ // control which context menu item is show
document.getElementById("smplayerview-view-page").hidden = gContextMenu.isTextSelected||gContextMenu.onLink||gContextMenu.onImage||gContextMenu.onTextInput; // hide launch page if on highlighted text, link, image, or input field
document.getElementById("smplayerview-view-link").hidden = !gContextMenu.onLink; // no link, no item
if (gContextMenu.onLink) {
var url = gContextMenu.getLinkURL();
document.getElementById("smplayerview-view-link").disabled =
url.indexOf("javascript:")==0
|| url.indexOf("mailto:")==0;
}
},
test: function(path) {
this.init();

var oldPath = this.smplayerPath;
var oldParams = this.smplayerParams;

this.smplayerPath = path;
this.parseSMPlayerPath();
this._launch("http://www.youtube.com/watch?v=oHg5SJYRHA0"); // RickRoll

this.smplayerPath = oldPath;
this.smplayerParams = oldParams;
},
discover: function() {
// Get the path to SMPlayer from the registry
var winhooks, winhooksAPI;
if ("@mozilla.org/windows-registry-key;1" in Components.classes) {
try {
winhooks = Components.classes["@mozilla.org/windows-registry-key;1"].getService(Components.interfaces.nsIWindowsRegKey);
winhooksAPI = 2;
} catch(ex) {
this.log("Unable to get windows-registry-key service!");
}
} else if ("@mozilla.org/winhooks;1" in Components.classes) {
try {
winhooks = Components.classes["@mozilla.org/winhooks;1"].getService(Components.interfaces.nsIWindowsRegistry);
winhooksAPI = 1;
} catch(ex) {
this.log("Unable to get winhooks service!");
}
} else if ("@mozilla.org/browser/shell-service;1" in Components.classes) {
try {
winhooks = Components.classes["@mozilla.org/browser/shell-service;1"].getService(Components.interfaces.nsIWindowsShellService);
winhooksAPI = 1;
} catch(ex) {
this.log("Unable to get browser shell service!");
}
} else {
this.log("Unable to get Components. This only works on Windows!");
return;
}
if (typeof(winhooks) == "undefined" || (winhooksAPI == 1 && typeof(winhooks.getRegistryEntry) != "function") || (winhooksAPI == 2 && typeof(winhooks.open) != "function")) {
this.log("Registry functions aren't available. This only works on Windows!");
return;
}
try {
// 0: HKEY_CLASSES_ROOT = 0x80000000
// 1: HKEY_CURRENT_CONFIG = 0x80000005
// 2: HKEY_CURRENT_USER = 0x80000001
// 3: HKEY_LOCAL_MACHINE = 0x80000002
// 4: HKEY_USERS = 0x80000003

var keys = new Array(
{key: 0x80000000, path: "MPlayerFileVideo\\shell\\open\\command", name: "", append: ""},
{key: 0x80000002, path: "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\SMPlayer", name: "DisplayIcon", append: ' "%1"'}
);
this.smplayerPath = false;
for (var i=0; i<keys.length; i++) {
this.log("Looking for SMPlayer in registry path "+keys[i].path);
if (winhooksAPI == 1) {
this.smplayerPath = winhooks.getRegistryEntry(keys[i].key, keys[i].path, keys[i].name);
} else if (winhooksAPI == 2) {
var regkey = Components.classes["@mozilla.org/windows-registry-key;1"].createInstance(Components.interfaces.nsIWindowsRegKey);
try {
regkey.open(keys[i].key, keys[i].path, Components.interfaces.nsIWindowsRegKey.ACCESS_READ);
if (regkey.valueCount) {
try {
this.smplayerPath = regkey.readStringValue(keys[i].name);
} catch(ex) {
}
}
} catch(ex) {
}
} else {
alert("Unknown winhooksAPI version");
}
if (this.smplayerPath) {
this.smplayerPath = this.smplayerPath+keys[i].append;
break;
}
}
} catch(ex) {
this.smplayerPath = false;
}
if (this.smplayerPath) {
this.log("Found SMPlayer there as "+this.smplayerPath);
this.prefManager.setCharPref("extensions.smplayerview.smplayerpath", this.smplayerPath);
} else {
this.log("SMPlayer not found");
alert(this.smplayerviewBundle.getFormattedString("smplayerview.notfound"));
}
},
discoverButton: function() {
this.discover();
if (this.smplayerPath) {
document.getElementById("smplayerview-smplayerpath").value = this.smplayerPath;
}
}
}
16 changes: 16 additions & 0 deletions chrome/content/smplayerviewOverlay.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://smplayerview/skin/skin.css" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://smplayerview/locale/smplayerview.dtd" >
<overlay id="smplayerviewOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<stringbundleset>
<stringbundle id="smplayerview_strings" src="chrome://smplayerview/locale/smplayerview.properties"/>
</stringbundleset>
<script type="application/x-javascript" src="smplayerview.js"/>
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id="smplayerview-button" class="toolbarbutton-1" label="SMPlayer View" tooltiptext="&smplayerview.view-page;" oncommand="smplayerview.launch(gBrowser.currentURI.spec);"/>
</toolbarpalette>
<popup id="contentAreaContextMenu">
<menuitem id="smplayerview-view-page" label="&smplayerview.view-page;" oncommand="smplayerview.launch(gBrowser.currentURI.spec)"/>
<menuitem id="smplayerview-view-link" label="&smplayerview.view-link;" oncommand="smplayerview.launch(gContextMenu.getLinkURL())"/>
</popup>
</overlay>
7 changes: 7 additions & 0 deletions chrome/locale/de-DE/smplayerview.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!ENTITY smplayerview.view-page "Seite in SMPlayer anzeigen">
<!ENTITY smplayerview.view-link "Link in SMPlayer öffnen">
<!ENTITY smplayerview.prefs-title "SMPlayer View-Einstellungen">
<!ENTITY smplayerview.prefs-pathtosmplayer "Pfad zu SMPlayer">
<!ENTITY smplayerview.prefs-description "SMPlayer View versucht, den Pfad zu SMPlayer automatisch zu erkennen. Sie können den Pfad hier auch manuell eingeben. &#039;&#37;1&#039; im Pfad wird durch die zu öffnende URL ersetzt.">
<!ENTITY smplayerview.prefs-test "Test">
<!ENTITY smplayerview.prefs-discover "automatische Erkennung">
2 changes: 2 additions & 0 deletions chrome/locale/de-DE/smplayerview.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
smplayerview.notexecutable = SMPlayer konnte als '%S' nicht gestartet werden.
smplayerview.notfound = SMPlayer konnte in der Registry nicht gefunden werden. Bitte geben Sie den Pfad zu SMPlayer manuell in den Einstellungen von SMPlayer View an.
7 changes: 7 additions & 0 deletions chrome/locale/en-US/smplayerview.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!ENTITY smplayerview.view-page "View This Page in SMPlayer">
<!ENTITY smplayerview.view-link "Open Link Target in SMPlayer">
<!ENTITY smplayerview.prefs-title "SMPlayer View Preferences">
<!ENTITY smplayerview.prefs-pathtosmplayer "Path to SMPlayer">
<!ENTITY smplayerview.prefs-description "SMPlayer View tries to auto-detect the path to SMPlayer when the extension is installed. You can change the location here. &#039;&#37;1&#039; in the path is replaced by the URL to be opened.">
<!ENTITY smplayerview.prefs-test "Test">
<!ENTITY smplayerview.prefs-discover "Auto detect">
2 changes: 2 additions & 0 deletions chrome/locale/en-US/smplayerview.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
smplayerview.notexecutable = SMPlayer could not be run as '%S'.
smplayerview.notfound = SMPlayer could not be found in the registry. Please specify the path to SMPlayer manually in SMPlayer View's settings.
7 changes: 7 additions & 0 deletions chrome/locale/it/smplayerview.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!ENTITY smplayerview.view-page "Apri questa pagina con SMPlayer">
<!ENTITY smplayerview.view-link "Apri il collegamento selezionato con SMPlayer">
<!ENTITY smplayerview.prefs-title "Opzioni di SMPlayer View">
<!ENTITY smplayerview.prefs-pathtosmplayer "Percorso all'eseguibile di SMPlayer">
<!ENTITY smplayerview.prefs-description "SMPlayer View proverà a riconoscere automaticamente il percorso all'eseguibile di SMPlayer dopo l'installazione dell'estensione. È comunque possibile cambiare il percorso da qui. La variabile &#039;&#039;&#37;1&#039;&#039; alla fine del percorso, verrà automaticamante rimpiazzata dall'URL che si desidera venga aperto.">
<!ENTITY smplayerview.prefs-test "Test">
<!ENTITY smplayerview.prefs-discover "Riconoscimento automatico">
2 changes: 2 additions & 0 deletions chrome/locale/it/smplayerview.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
smplayerview.notexecutable = Impossibile rilevare SMPlayer nella posizione specificata.
smplayerview.notfound = Impossibile rilevare SMPlayer nel registro. Specificare manualmente il percorso all'eseguibile di SMPlayer nelle Opzioni di SMPlayer View.
7 changes: 7 additions & 0 deletions chrome/locale/nl-NL/smplayerview.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!ENTITY smplayerview.view-page "Deze pagina in SMPlayer bekijken">
<!ENTITY smplayerview.view-link "Koppeling in SMPlayer bekijken">
<!ENTITY smplayerview.prefs-title "SMPlayer View instellingen">
<!ENTITY smplayerview.prefs-pathtosmplayer "SMPlayer locatie">
<!ENTITY smplayerview.prefs-description "SMPlayer View probeert de locatie van SMPlayer automatisch te herkennen. U kunt de locatie hier ook wijzigen. &#039;&#37;1&#039; wordt vervangen door de URL dat zal worden geopend.">
<!ENTITY smplayerview.prefs-test "Test">
<!ENTITY smplayerview.prefs-discover "Automisch herkennen">
2 changes: 2 additions & 0 deletions chrome/locale/nl-NL/smplayerview.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
smplayerview.notexecutable = SMPlayer kon op '%S' niet gevonden worden.
smplayerview.notfound = SMPlayer kon in de registry niet gevonden worden. Geef uw a.u.b. de SMPlayer locatie handmatig aan in de SMPlayer View instellingen.
7 changes: 7 additions & 0 deletions chrome/locale/pt-BR/smplayerview.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!ENTITY smplayerview.view-page "Visualizar essa página com o SMPlayer">
<!ENTITY smplayerview.view-link "Abrir link com o SMPlayer">
<!ENTITY smplayerview.prefs-title "Opções do SMPlayer View">
<!ENTITY smplayerview.prefs-pathtosmplayer "Caminho do SMPlayer">
<!ENTITY smplayerview.prefs-description "O SMPlayer View tenta detectar o caminho do SMPlayer automaticamente quando a extensão é instalada. Você pode mudar o local aqui. &#039;&#37;1&#039; no caminho é substituído pela URL a ser acessada.">
<!ENTITY smplayerview.prefs-test "Testar">
<!ENTITY smplayerview.prefs-discover "Detectar automaticamente">
2 changes: 2 additions & 0 deletions chrome/locale/pt-BR/smplayerview.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
smplayerview.notexecutable = Não foi possível executar SMPlayer com '%S'.
smplayerview.notfound = O SMPlayer não foi encontrado no registro. Por favor especifique um caminho para o SMPlayer manualmente nas opções do SMPlayer View.
Binary file added chrome/skin/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions chrome/skin/skin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#smplayerview-toolbar {
list-style-image: url("chrome://smplayerview/skin/icon.png");
}

#smplayerview-button {
list-style-image: url("chrome://smplayerview/skin/toolbar-24-enabled.png");
}

toolbar #smplayerview-button[disabled="true"] {
list-style-image: url("chrome://smplayerview/skin/toolbar-24-disabled.png");
}

toolbar[iconsize="small"] #smplayerview-button {
list-style-image: url("chrome://smplayerview/skin/toolbar-16-enabled.png");
}

toolbar[iconsize="small"] #smplayerview-button[disabled="true"] {
list-style-image: url("chrome://smplayerview/skin/toolbar-16-disabled.png");
}
Binary file added chrome/skin/toolbar-16-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chrome/skin/toolbar-16-enabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chrome/skin/toolbar-24-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chrome/skin/toolbar-24-enabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions credits.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
SMPlayer View
-----------------------------------
View a webpage in SMPlayer on Windows

COPYRIGHT:

Copyright (C) 2008-2009 by Lutz Issler.
Copyright (C) 2013 by Bruno Barbieri.

CREDITS:

SMPlayer View is based on Chrome View 0.2.2 by
Lutz Issler.

Chrome View is based on IE View Lite 1.3.2 by
Grayson Mixon.
Thanks to Mark Halpaap for providing the registry
key for SRware Iron, and for debugging the Iron
integration.

The registry code is based on Launchy 4.0.2 by
Henrik Gemal.

TRANSLATIONS:

Dutch translation by Arjan Menger
English translation by Lutz Issler
German translation by Lutz Issler
Italian translation by Giuliano Masseroni
Portuguese (Brazil) translation by Bruno Barbieri
Spanish translation by Oink!
Loading

0 comments on commit d2bfb73

Please sign in to comment.