Talk about add-ons and extension development.
davide ficano

Posts: 118Joined: April 10th, 2005, 9:21 amLocation: Palermo Italy
September 13th, 2008, 8:12 am
Posted September 13th, 2008, 8:12 am
I've a local file containing cyrillic characters in name (dir or filename)and I need to pass the corresponding path string as parameter to nsIProcess.run(). After a great discussion on extension dev irc I'm able to pass string under linux, but under Windows doesn't work. Below I show the code I use. I convert the uri into a nsiFile using the code shown below - Code: Select all
var ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); return ioService.newURI(url, null, null) .QueryInterface(Components.interfaces.nsIFileURL) .file;
Then I convert the path from unicode and under Linux works fine - Code: Select all
runArgument = fromUnicode(file.path, "UTF-8");
function fromUnicode(text, charset) { var unicodeCvt = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] .createInstance(Components.interfaces.nsIScriptableUnicodeConverter); unicodeCvt.charset = charset; return converter.ConvertFromUnicode(text) + converter.Finish(); }
I've tried different charset under Windows without success - Code: Select all
runArgument = fromUnicode(file.path, "xxxxxx");
May you help me?
Visit my website dafizilla dedicated to Mozilla extensions
vladmir
Posts: 130Joined: October 18th, 2004, 9:47 amLocation: RU
September 15th, 2008, 6:53 am
Posted September 15th, 2008, 6:53 am
May you help me?
And authors of JSView and Firebug needs the same help. 
vladmir
Posts: 130Joined: October 18th, 2004, 9:47 amLocation: RU
September 15th, 2008, 9:15 pm
Posted September 15th, 2008, 9:15 pm
DavideUser Infocatcher from forum.mozilla-russia.org sends you this part of code from his new extension (not finished). The code based on extension IE Tab. May be it will give you direction. - Code: Select all
var myObj = { openUriWithApp: function( ... ) { // ... // var path = "c:\\Program Files\\Internet Explorer\\iexplore.exe"; // var args = []; args.push(this.convertStrFromUnicode(uri)); this.startProcess(path, args); }, startProcess: function(path, args) { args = args || []; var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath(path); if(!file.exists()) { alert(path + "\nnot found!"); return; } var process = Components.classes["@mozilla.org/process/util;1"] .getService(Components.interfaces.nsIProcess); process.init(file); process.run(false, args, args.length); }, convertStrFromUnicode: function(str) { var charset = this.charset; if(!charset) return str; // this.ut._log("convertStrFromUnicode -> charset -> " + charset); var suc = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] .createInstance(Components.interfaces.nsIScriptableUnicodeConverter); suc.charset = charset; try { str = decodeURIComponent(str); // to UTF-8 } catch(e) { // does not work in fx 1.5 str = suc.ConvertToUnicode(unescape(str)); // Thanks to IE Tab! str = decodeURI(str); } return suc.ConvertFromUnicode(str); }, get charset() { var charset = ""; if(this.ut.pref("convertURIs")) { charset = this.ut.pref("convertURIsTo"); if(!charset) { charset = this.ut.getPref("intl.charset.default"); if(!charset || charset.indexOf("chrome://") == 0) charset = this.defaultCharset; } } return charset; }, _defaultCharset: null, get defaultCharset() { // thanks to IE Tab! if(this._defaultCharset == null) { var strBundle = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); try { this._defaultCharset = strBundle.createBundle("chrome://global-platform/locale/intl.properties") .GetStringFromName("intl.charset.default"); } catch(e) { this._defaultCharset = ""; } } return this._defaultCharset; } }; myObj.openUriWithApp( ... );
davide ficano

Posts: 118Joined: April 10th, 2005, 9:21 amLocation: Palermo Italy
September 16th, 2008, 8:47 am
Posted September 16th, 2008, 8:47 am
vladmir wrote:Davide
User Infocatcher from forum.mozilla-russia.org sends you this part of code from his new extension (not finished). The code based on extension IE Tab. May be it will give you direction.
Hi, thank you very much but Infocatcher's code doesn't work for me, at least on my italian Windows with charset 8859-1
Visit my website dafizilla dedicated to Mozilla extensions
Infocatcher

Posts: 23Joined: July 1st, 2007, 3:45 am
September 18th, 2008, 3:40 pm
Posted September 18th, 2008, 3:40 pm
davide ficano wrote:doesn't work for me, at least on my italian Windows with charset 8859-1
Try choose charset manually: this.ut.pref("convertURIs") = true this.ut.pref("convertURIsTo") = "iso-8859-1" (?) And what returns defaultCharset getter? And IE Tab works for you? Set path to external application and try open local file (file://) with non-ASCII characters in name (ctrl+left-click on icon in status bar). P.S. For me works conversion to windows-1251 (default system charset), but only for opening in IE (7.0) – it not work for Opera (9.52).
This game has no name. It will never be the same. ©
davide ficano

Posts: 118Joined: April 10th, 2005, 9:21 amLocation: Palermo Italy
September 19th, 2008, 12:07 am
Posted September 19th, 2008, 12:07 am
Infocatcher wrote:davide ficano wrote:doesn't work for me, at least on my italian Windows with charset 8859-1
Try choose charset manually: this.ut.pref("convertURIs") = true this.ut.pref("convertURIsTo") = "iso-8859-1" (?) And what returns defaultCharset getter?
The default charset is : ISO-8859-1 I've tried others charset, I obtain (obviously) different strings but all doesn't work (i.e. the passed path isn't recognized by editors) I've tried the charset shown below Windows-1250 Windows-1251 Windows-1252 Windows-1253 Windows-1254 Windows-1255 ISO 8859-1 (the default) ISO 8859-2 ISO 8859-5 and UTF-8 ... I've used different editors Windows Notepad Windows Wordpad Komodo Edit 4.4.x Notepad++ UltraEdit And IE Tab works for you? Set path to external application and try open local file (file://) with non-ASCII characters in name (ctrl+left-click on icon in status bar).
IETab doesn't open local path with cyrillic characters, no error and no messages into Error Console, silently the file isn't open. P.S. For me works conversion to windows-1251 (default system charset), but only for opening in IE (7.0) – it not work for Opera (9.52).
I've tried only on IE 6.0 thanks for your feedback
Visit my website dafizilla dedicated to Mozilla extensions
davide ficano

Posts: 118Joined: April 10th, 2005, 9:21 amLocation: Palermo Italy
September 20th, 2008, 4:47 am
Posted September 20th, 2008, 4:47 am
Hi,
I've fixed the problem but under Windows it works only if I change the "Language for non-Unicode programs" to Russian (*), my default value is Italian. Under Linux seems to work simply using the UTF-8 charset. I'm unable to test under Mac OSX so actually OSX uses the same technique used by Linux. I've done a little improvement using the current browser document characterSet property.
I don't like the solution because I can't directly open russian files inside my italian-configured Windows but I think this is a little step ahead.
Thanks for your help
(*) Control Panel -> Date, Time, Languages, and Regional Options -> Add other Languages Select the Advanced tab and choose Russian as language.
Visit my website dafizilla dedicated to Mozilla extensions
vladmir
Posts: 130Joined: October 18th, 2004, 9:47 amLocation: RU
September 23rd, 2008, 1:50 pm
Posted September 23rd, 2008, 1:50 pm
It works only for saved pages with win1251 in meta tag For <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> doesn't work source and css-js  I,ll try more.
davide ficano

Posts: 118Joined: April 10th, 2005, 9:21 amLocation: Palermo Italy
September 24th, 2008, 10:53 am
Posted September 24th, 2008, 10:53 am
vladmir wrote:It works only for saved pages with win1251 in meta tag For <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> doesn't work source and css-js  I,ll try more.
Does work with IETab? I'm unable to find a original Russian WinXP
Visit my website dafizilla dedicated to Mozilla extensions
vladmir
Posts: 130Joined: October 18th, 2004, 9:47 amLocation: RU
September 25th, 2008, 4:59 am
Posted September 25th, 2008, 4:59 am
IETab opens source of utf-8 pages
vladmir
Posts: 130Joined: October 18th, 2004, 9:47 amLocation: RU
September 26th, 2008, 4:13 am
Posted September 26th, 2008, 4:13 am
New info by another user in forum.mozilla-russia.org The same problem with the function in FF 3.0.1 itself  pref("view_source.editor.external", false); set to true and set path to editor in pref("view_source.editor.path", ""); Then View -> Page Source Error with pages with win-1251 and utf-8 === In Netscape 9.0 (FF 2.0) the same.
Last edited by vladmir on September 26th, 2008, 6:38 am, edited 1 time in total.
vladmir
Posts: 130Joined: October 18th, 2004, 9:47 amLocation: RU
September 26th, 2008, 11:54 am
Posted September 26th, 2008, 11:54 am
Bug 408923 – View source with an external editor doesn't works with a web page with a ' in title and UTF-8 encoding, editor is opened but file is not found https://bugzilla.mozilla.org/show_bug.cgi?id=408923
davide ficano

Posts: 118Joined: April 10th, 2005, 9:21 amLocation: Palermo Italy
September 26th, 2008, 11:18 pm
Posted September 26th, 2008, 11:18 pm
vladmir wrote:IETab opens source of utf-8 pages
After many tests I'm unable to allow IETab to open UTF-8 local pages. I use your test page and try to open using IETab and windows notepad inside a clean Firefox 3.0.3 but I receive error from notepad "The filename, directory name, or volume label syntax is incorrect" This simply means the IETab passed file path isn't recognized from Windows Operating System
Visit my website dafizilla dedicated to Mozilla extensions
vladmir
Posts: 130Joined: October 18th, 2004, 9:47 amLocation: RU
September 27th, 2008, 4:32 am
Posted September 27th, 2008, 4:32 am
OK, I,ll see on new winXP.
Return to Extension Development
Who is online
Users browsing this forum: No registered users and 5 guests
|