Skip to content

Commit

Permalink
1. Fix dropdown menu bug in Symbol input and embedded player.
Browse files Browse the repository at this point in the history
  • Loading branch information
ettoolong committed Jun 1, 2015
1 parent 3b69b15 commit fd94f02
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 95 deletions.
44 changes: 11 additions & 33 deletions chrome/content/ansiFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ function AnsiFile(ansiColor) {
}

AnsiFile.prototype = {
openFile: function() {
doPasteFileData: function(data) {
//TODO: remove clipboard operation, paste data directly
//FIXME: load file with different charset
var data = this.loadFile();
if(!data)
return;

var text = this.ansi.convertStringToUTF8(data);
this.ansi.ansiClipboard(text);
this.ansi.paste();
this.ansi.paste();
},

savePage: function(saveMode) {
//FIXME: save file with different charset
/*
Expand Down Expand Up @@ -55,31 +52,12 @@ AnsiFile.prototype = {
},

loadFile: function() {
//TODO: need modify for E10S
/*
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
fp.init(window, null, nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterAll);
if(fp.show() == nsIFilePicker.returnCancel)
return '';
if(!fp.file.exists())
return '';
var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
// Read data with 2-color DBCS char
fstream.init(fp.file, -1, -1, false);
var bstream = Components.classes["@mozilla.org/binaryinputstream;1"]
.createInstance(Components.interfaces.nsIBinaryInputStream);
bstream.setInputStream(fstream);
var bytes = bstream.readBytes(bstream.available());
return bytes;
*/
return [];
var nsIFilePicker = Components.interfaces.nsIFilePicker;
bbsfox.sendCoreCommand({command: "openFilepicker",
title: null,
mode: nsIFilePicker.modeOpen,
appendFilters: [nsIFilePicker.filterAll],
postCommand: "doPasteFileData"});
},

saveFile: function(data, saveMode) {
Expand Down Expand Up @@ -130,7 +108,7 @@ AnsiFile.prototype = {
mode: nsIFilePicker.modeSave,
defaultExtension:"html",
defaultString: "newhtml",
appendFilters: [nsIFilePicker.filterHTML],
appendFilters: appendFilters,
saveData: data,
convertUTF8: convertUTF8});
},
Expand Down
38 changes: 24 additions & 14 deletions chrome/content/bbsfox.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ BBSFox.prototype={
if(this.prefs) {
this.prefs.updateEventPrefs(); //force update
this.prefs.updateOverlayPrefs(); //force update
this.loadLoginData();
} else {
}
} else {
Expand Down Expand Up @@ -1829,20 +1830,29 @@ BBSFox.prototype={
}
},

loadLoginData: function(ds, ss){
var url = this.isDefaultPref ? ds : ss + this.siteAuthInfo;
try {
var logins = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager).findLogins({}, url, ds, null);
if(logins.length)
{
return [logins[0]['username'], logins[0]['password']];
}
else
{
return ['',''];
}
} catch(e) {
return ['',''];
loadLoginData: function(){
var ds, ss, url;
if(document.location.protocol == 'telnet:') {
ds = 'chrome://bbsfox2';
ss = 'telnet://';
url = this.isDefaultPref ? ds : ss + this.siteAuthInfo;
this.sendCoreCommand({command: "loadAutoLoginInfo", querys: [{
protocol: "telnet",
url: url,
ds: ds}]});
} else if(document.location.protocol == 'ssh:') {
var querys = [];
ds = 'chrome://bbsfox2';
ss = 'telnet://';
url = this.isDefaultPref ? ds : ss + this.siteAuthInfo;
querys.push({protocol: "telnet", url: url, ds: ds})

ds = 'chrome://bbsfox3';
ss = 'ssh://';
url = this.isDefaultPref ? ds : ss + this.siteAuthInfo;
querys.push({protocol: "ssh", url: url, ds: ds})

this.sendCoreCommand({command: "loadAutoLoginInfo", querys: querys});
}
},

Expand Down
105 changes: 77 additions & 28 deletions chrome/content/bbsfoxOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ var ETT_BBSFOX_Overlay =
this.writePrefs(data.branchName, data.name, data.vtype, data.value);
break;
case "openFilepicker":
this.openFilepicker(data.title, data.mode, data.defaultExtension, data.defaultString, data.appendFilters, data.saveData, data.convertUTF8);
this.openFilepicker(data, message.target);
break;
case "loadAutoLoginInfo":
this.loadAutoLoginInfo(data.querys, message.target);
break;
case "setTabFocus":
//var tab = gBrowser.getTabForBrowser( message.target );
Expand Down Expand Up @@ -486,10 +489,14 @@ var ETT_BBSFOX_Overlay =
document.defaultView.gBrowser.selectedBrowser.messageManager
.sendAsyncMessage("bbsfox@ettoolong:bbsfox-overlayCommand", {command:command});
},
setBBSCmdEx: function(commandSet) {
//browserMM
document.defaultView.gBrowser.selectedBrowser.messageManager
.sendAsyncMessage("bbsfox@ettoolong:bbsfox-overlayCommand", commandSet);
setBBSCmdEx: function(commandSet, target) {
var browserMM;
if(target) {
browserMM = target.messageManager;
} else {
browserMM = document.defaultView.gBrowser.selectedBrowser.messageManager;
}
browserMM.sendAsyncMessage("bbsfox@ettoolong:bbsfox-overlayCommand", commandSet);
},

writePrefs: function(branchName, name, vtype, value) {
Expand All @@ -509,41 +516,83 @@ var ETT_BBSFOX_Overlay =
}
},

openFilepicker: function(title, mode, extension, defaultStr, filters, data, convertUTF8) {
loadAutoLoginInfo: function(querys, target) {
//TODO: load auto login info, send a message to tab(set ready status to start connection)
var result = {};
for(var i=0;i<querys.length;++i){
try{
var logins = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager).findLogins({}, querys[i].url, querys[i].ds, null);
if(logins.length) {
result[querys[i].protocol] = { userName: logins[0]['username'], password: logins[0]['password'] };
} else {
result[querys[i].protocol] = { userName: '', password: '' };
}
}catch(ex){
result[querys[i].protocol] = { userName: '', password: '' };
}
}
this.setBBSCmdEx({command: "loginInfoReady", result: result}, target);
},

openFilepicker: function(data, target) {
var title = data.title;
var mode = data.mode;
var extension = data.extension;
var defaultStr = data.defaultStr;
var filters = data.filters;
var writeData = data.writeData;
var convertUTF8 = data.convertUTF8;
var postCommand = data.postCommand;

var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fileChooser = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fileChooser.init(window, title, mode);

fileChooser.defaultExtension = extension;
fileChooser.defaultString = defaultStr;
if(extension)
fileChooser.defaultExtension = extension;
if(defaultStr)
fileChooser.defaultString = defaultStr;
for(var i=0;i<filters.length;++i)
fileChooser.appendFilters(filters[i]);
fileChooser.open(function(result) {
//returnOK 0
//returnCancel 1
//returnReplace 2
if (result != nsIFilePicker.returnCancel) {
// file is nsIFile, data is a string
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
if(fileChooser.file.exists()){
fileChooser.file.remove(true);
}
fileChooser.file.create(fileChooser.file.NORMAL_FILE_TYPE, 0666);
foStream.init(fileChooser.file, 0x02 | 0x08 | 0x20, 0666, null);
if(convertUTF8) {
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
converter.init(foStream, "UTF-8", 0, 0);
converter.writeString(data);
converter.close(); // this closes foStream
} else {
foStream.write(data, data.length);
if (foStream instanceof Components.interfaces.nsISafeOutputStream)
foStream.finish();
else
foStream.close();

if(mode == nsIFilePicker.modeSave) {
// file is nsIFile, data is a string
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
if(fileChooser.file.exists()){
fileChooser.file.remove(true);
}
fileChooser.file.create(fileChooser.file.NORMAL_FILE_TYPE, 0666);
foStream.init(fileChooser.file, 0x02 | 0x08 | 0x20, 0666, null);
if(convertUTF8) {
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
converter.init(foStream, "UTF-8", 0, 0);
converter.writeString(writeData);
converter.close(); // this closes foStream
} else {
foStream.write(writeData, writeData.length);
if (foStream instanceof Components.interfaces.nsISafeOutputStream)
foStream.finish();
else
foStream.close();
}
} else if(mode == nsIFilePicker.modeSave) {
var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
// Read data with 2-color DBCS char
fstream.init(fp.file, -1, -1, false);
var bstream = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
bstream.setInputStream(fstream);
var bytes = bstream.readBytes(bstream.available());
if(postCommand) {
this.setBBSCmdEx({command: postCommand, fileData: bytes}, target);
}
}

}
});
}.bind(this));
},

getPrefs: function() {
Expand Down
35 changes: 33 additions & 2 deletions chrome/content/embeddedPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ function EmbeddedPlayer(playerURL, showbtn, playerSize) {
box3.classList.add('dragUI');
box3.classList.add('nonspan');

/*
// XUL <menulist> not working in E10S (Firefox bug ?)
// Modify: Use html tag <select>
var sizeSelect = document.createElementNS(XUL_NS, 'menulist');
box3.appendChild(sizeSelect);
sizeSelect.style.fontSize='12px';
Expand All @@ -88,6 +91,34 @@ function EmbeddedPlayer(playerURL, showbtn, playerSize) {
sizeSelect.insertItemAt(0, '425 x 344 (4:3)', 0);
sizeSelect.selectedIndex = playerSize;
sizeSelect.addEventListener('command', this.selectitem.bind(this), false);
*/
// XUL <menulist> not working in E10S (Firefox bug ?)
// Modify: Use html tag <select>
//create select tag - start
var sizeSelect = document.createElement('select');
box3.appendChild(sizeSelect);
sizeSelect.style.fontSize='12px';
sizeSelect.style.margin='4px 2px';
sizeSelect.setAttribute('editable','false');
sizeSelect.classList.add('extUI');
sizeSelect.classList.add('buttonUI');
sizeSelect.classList.add('WinBtn');
sizeSelect.setAttribute('sizetopopup','always');
//
var resArr = ['425 x 344 (4:3)', '480 x 385 (4:3)', '640 x 505 (4:3)', '960 x 745 (4:3)',
'560 x 340 (16:9)', '640 x 385 (16:9)', '853 x 505 (16:9)', '1280 x 745 (16:9)'];
for(var i=0;i<resArr.length;++i)
{
var option = document.createElement('option');
option.text = resArr[i];
option.value = i;
option.classList.add('extUI');
sizeSelect.appendChild(option);
}
//
sizeSelect.selectedIndex = playerSize;
sizeSelect.addEventListener('change', this.selectitem.bind(this), false);
//create select tag - end

var copyUrlBtn = document.createElementNS(XUL_NS, 'button');
box3.appendChild(copyUrlBtn);
Expand Down Expand Up @@ -288,7 +319,7 @@ EmbeddedPlayer.prototype={
this.removeAllChild(n);
n.appendChild(doc.body.firstChild);
},

createLinkStr: function(pt, code, w, h, loop, autoPlay, autoUseHighQuality) {
if(pt=='Y')
{
Expand Down Expand Up @@ -660,7 +691,7 @@ PlayerMgr.prototype={
}
}
}

if(youtubeURLType==1 || youtubeURLType==2 || youtubeURLType==3)
{
tempurl = 'http://www.youtube.com/watch?v='+aurl;
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/gesturehandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ BBSGestureHandler.prototype={
doGesture = true;
break;
case "LoadFile":
bbscore.ansiColor.file.openFile();
bbscore.ansiColor.file.loadFile();
doGesture = true;
break;
case "SelectAll":
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/mainpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function startup() {
}
bbsfox.setInputAreaFocus();
resize();
bbsfox.connect();//document.location.host
//bbsfox.connect();//document.location.host
}

function release() {
Expand Down
9 changes: 8 additions & 1 deletion chrome/content/overlayCmdListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ BBSOverlayCmdListener.prototype={
bbscore.ansiColor.file.savePage(data.downloadColor);
break;
case "doLoadFile":
bbscore.ansiColor.file.openFile();
bbscore.ansiColor.file.loadFile();
break;
case "doPasteFileData":
bbscore.ansiColor.file.doPasteFileData(data.fileData);
break;
case "checkPrefExist":
bbscore.doSiteSettingCheck(250);
Expand All @@ -153,6 +156,10 @@ BBSOverlayCmdListener.prototype={
case "removeFromBlacklist":
bbscore.removeFromBlacklist();
break;
case "loginInfoReady":
bbscore.robot.initialAutoLogin(data.result);
bbscore.connect();
break;
case "setAlert":
//bbscore.view.showAlertMessageEx(false, true, false, data.alertMessage);
//alert(param);
Expand Down
10 changes: 5 additions & 5 deletions chrome/content/robot.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ Robot.prototype={
},
*/
// Modified from pcmanx-gtk2
initialAutoLogin: function() {
var acc = this.listener.loadLoginData('chrome://bbsfox2','telnet://'); //load login data
this.prefs.loginStr[1] = acc[0];
this.prefs.loginStr[2] = acc[1];
initialAutoLogin: function(result) {
//var acc = this.listener.loadLoginData('chrome://bbsfox2','telnet://'); //load login data
this.prefs.loginStr[1] = result.telnet.userName;
this.prefs.loginStr[2] = result.telnet.password;

if(this.prefs.loginStr[1])
this.autoLoginStage = this.prefs.loginStr[0] ? 1 : 2;
Expand Down Expand Up @@ -270,7 +270,7 @@ DownloadArticle.prototype={
if(fontFace=="")
fontFace = "MingLiu";
var bgcolor = (this.listener.view.colorTable==0) ? this.prefs.bbsColor[0] : this.listener.view.invertColor(this.prefs.bbsColor[0]);

selstr = '<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><style type="text/css">';
selstr += '.main {font-family: ';
selstr += fontFace;
Expand Down
Loading

0 comments on commit fd94f02

Please sign in to comment.