Skip to content

Commit

Permalink
* new in options dialog : specify the path of GPG, show the FireGPG o…
Browse files Browse the repository at this point in the history
…fficial

  website.
* Shorter version of names : firegpgSelect -> Selection, 
  Selection.isSelectionEditable -> isEditable, getSelection -> get,
  setSelection -> set.
* some little modifications in the source code
* new optional argument in getPrivateKeyPassword : useSaverPassword.
* FireGPG_GPG* -> GPG (because it's shorter and we have the already the namespace)


git-svn-id: http://svn.getfiregpg.org/firegpg@95 1e1cc2a3-b62a-0410-bc93-fb3b3b0a0737
  • Loading branch information
achraf committed Mar 5, 2007
1 parent 5e452f0 commit 66012be
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 112 deletions.
8 changes: 7 additions & 1 deletion ChangeLog
Expand Up @@ -4,7 +4,7 @@
* Implementation of getSelfKey(), for get the default key !
* Full implementation for saving the password, with a menu for erase it.
* Come back to default UUID
* Fixed problems with complied packtage !
* Fixed problems with complied package !
* Version 0.1 Packed, and uploaded to the server !
* Fixed a bug in select system who didn't look at \n in some texts
* Add support for select text with HTML and <br> balises
Expand All @@ -14,6 +14,12 @@
the generic function getPassword(question, save_password)
* new in options dialog : specify the path of GPG, show the FireGPG official
website.
* Shorter version of names : firegpgSelect -> Selection,
Selection.isSelectionEditable -> isEditable, getSelection -> get,
setSelection -> set.
* some little modifications in the source code
* new optional argument in getPrivateKeyPassword : useSaverPassword.
* FireGPG_GPG* -> GPG (because it's shorter and we have the already the namespace)

2007-03-04 Achraf cherti
* the default private key is saved and selected by default when
Expand Down
64 changes: 30 additions & 34 deletions content/cgpg.js
Expand Up @@ -42,24 +42,24 @@ const WINDOWS = "WINNT";
const FireGPG_OS = Components.classes[NS_APPINFO_CONTRACTID].getService(Components.interfaces.nsIXULRuntime).OS;;

// Return class, for return 2 or 3 informations in an object.
var FireGPG_GPGReturn = {
var GPGReturn = {
}

// Main class for access to GPG
var FireGPG_GPG = {
var GPG = {
/*
* Function for sign a text
* Function to sign a text.
*/
sign: function() {
var texte = firegpgSelect.getSelection();
var text = Selection.get();

// Needed for a sign
var password = getPrivateKeyPassword();
var keyID = getSelfKey();

// We get the result
var result = this.GPGAccess.sign(texte,password,keyID);
var crypttexte = result.output;
var result = this.GPGAccess.sign(text, password, keyID);
var crypttext = result.output;
result = result.sdOut;

// For i18n
Expand All @@ -68,33 +68,30 @@ var FireGPG_GPG = {
// If the sign failled
if(result.indexOf("SIG_CREATED") == "-1") {
// We alert the user
if(result.indexOf("BAD_PASSPHRASE") != "-1")
{
if(result.indexOf("BAD_PASSPHRASE") != "-1") {
alert(i18n.getString("signFailledPassword"));
eraseSavedPassword();
}
else
alert(i18n.getString("signFailled"));
}
else {
//We test is the selection in editable :
if (firegpgSelect.isSelectionEdit())
{ //If yes, we edit this selection with the new text
firegpgSelect.setSelection(crypttexte);
}
else
{ //Else, we show a windows with the result
showText(crypttexte);
// We test if the selection is editable :
if(Selection.isEditable()) {
// If yes, we edit this selection with the new text
Selection.set(crypttext);
}
else //Else, we show a windows with the result
showText(crypttext);
}
},

// Verify a signature
verify: function() {
var texte = firegpgSelect.getSelection();
var text = Selection.get();

// We get the result
var result = this.GPGAccess.verify(texte);
var result = this.GPGAccess.verify(text);

// For I18N
var i18n = document.getElementById("firegpg-strings");
Expand Down Expand Up @@ -154,17 +151,17 @@ var FireGPG_GPG = {
},

/*
* Function for crypt a text
* Function to crypt a text.
*/
crypt: function() {
var texte = firegpgSelect.getSelection();
var text = Selection.get();

// Needed for a crypt
var keyID = getAKey();

// We get the result
var result = this.GPGAccess.crypt(texte,keyID);
var crypttexte = result.output;
var result = this.GPGAccess.crypt(text, keyID);
var crypttext = result.output;
result = result.sdOut;

// For i18n
Expand All @@ -177,13 +174,13 @@ var FireGPG_GPG = {
}
else {
//We test is the selection in editable :
if (firegpgSelect.isSelectionEdit())
if(Selection.isEditable())
{ //If yes, we edit this selection with the new text
firegpgSelect.setSelection(crypttexte);
Selection.set(crypttext);
}
else
{ //Else, we show a windows with the result
showText(crypttexte);
showText(crypttext);
}
}
},
Expand All @@ -192,23 +189,22 @@ var FireGPG_GPG = {
* Function for decrypt a text
*/
dcrypt: function() {
var texte = firegpgSelect.getSelection();
var text = Selection.get();

// Needed for a decrypt
var password = getPrivateKeyPassword();


// We get the result
var result = this.GPGAccess.dcrypt(texte,password);
var crypttexte = result.output;
var result = this.GPGAccess.dcrypt(text,password);
var crypttext = result.output;
result = result.sdOut;

// For i18n
var i18n = document.getElementById("firegpg-strings");

// If the crypt failled
if(result.indexOf("DECRYPTION_OKAY") == "-1") {
// We alert the user
// We alert the user
if(result.indexOf("BAD_PASSPHRASE") != "-1")
{
Expand All @@ -220,20 +216,20 @@ var FireGPG_GPG = {
}
else {
//We test is the selection in editable :
if (firegpgSelect.isSelectionEdit())
if(Selection.isEditable())
{ //If yes, we edit this selection with the new text
firegpgSelect.setSelection(crypttexte);
Selection.set(crypttext);
}
else
{ //Else, we show a windows with the result
showText(crypttexte);
showText(crypttext);
}
}
}
};

// We load the good class for the OS
FireGPG_GPG.GPGAccess = (FireGPG_OS == WINDOWS) ? FireGPG_GPGWin : FireGPG_GPGLin;
FireGPG_GPG.GPGAccess.parent = FireGPG_GPG;
GPG.GPGAccess = (FireGPG_OS == WINDOWS) ? GPGWin : GPGLin;
GPG.GPGAccess.parent = GPG;

// vim:ai:noet:sw=4:ts=4:sts=4:tw=0:fenc=utf-8:foldmethod=indent:
18 changes: 9 additions & 9 deletions content/cgpglin.js
Expand Up @@ -40,7 +40,7 @@ const comment = "http://firegpg.tuxfamily.org";
/*
* Class to access to GPG on GNU/Linux.
*/
var FireGPG_GPGLin = {
var GPGLin = {
var: parent,

/*
Expand All @@ -58,7 +58,7 @@ var FireGPG_GPGLin = {
removeFile(tmpOutput);

// We lanch gpg
var running = getContents("chrome://firegpg/content/run.sh")
var running = getContent("chrome://firegpg/content/run.sh")

putIntoFile(tmpRun,running);

Expand All @@ -77,7 +77,7 @@ var FireGPG_GPGLin = {

// The signed text
var crypttexte = getFromFile(tmpOutput);
var result2 = FireGPG_GPGReturn;
var result2 = GPGReturn;
result2.output = crypttexte;
result2.sdOut = result;

Expand All @@ -99,7 +99,7 @@ var FireGPG_GPGLin = {
putIntoFile(tmpInput,text); // TMP

// We lanch gpg
var running = getContents("chrome://firegpg/content/run.sh")
var running = getContent("chrome://firegpg/content/run.sh")

putIntoFile(tmpRun,running);

Expand Down Expand Up @@ -133,7 +133,7 @@ var FireGPG_GPGLin = {
mode = "--list-secret-keys";

// We lanch gpg
var running = getContents("chrome://firegpg/content/run.sh")
var running = getContent("chrome://firegpg/content/run.sh")

putIntoFile(tmpRun,running);

Expand Down Expand Up @@ -168,7 +168,7 @@ var FireGPG_GPGLin = {
removeFile(tmpOutput);

// We lanch gpg
var running = getContents("chrome://firegpg/content/run.sh")
var running = getContent("chrome://firegpg/content/run.sh")

putIntoFile(tmpRun,running);

Expand All @@ -185,7 +185,7 @@ var FireGPG_GPGLin = {

// The crypted text
var crypttexte = getFromFile(tmpOutput);
var result2 = FireGPG_GPGReturn;
var result2 = GPGReturn;
result2.output = crypttexte;
result2.sdOut = result;

Expand Down Expand Up @@ -214,7 +214,7 @@ var FireGPG_GPGLin = {
removeFile(tmpOutput);

// We lanch gpg
var running = getContents("chrome://firegpg/content/run.sh")
var running = getContent("chrome://firegpg/content/run.sh");

putIntoFile(tmpRun,running);

Expand All @@ -230,7 +230,7 @@ var FireGPG_GPGLin = {

// The decrypted text
var crypttexte = getFromFile(tmpOutput);
var result2 = FireGPG_GPGReturn;
var result2 = GPGReturn;
result2.output = crypttexte;
result2.sdOut = result;

Expand Down
2 changes: 1 addition & 1 deletion content/cgpgwin.js
Expand Up @@ -37,7 +37,7 @@
/*
* Class to access to GPG on windows
*/
var FireGPG_GPGWin = {
var GPGWin = {
crypt: function() {
alert('Crypt ! - Win');
}
Expand Down
49 changes: 25 additions & 24 deletions content/cselect.js
Expand Up @@ -34,21 +34,21 @@
*
* ***** END LICENSE BLOCK ***** */

//Classe for selection
var firegpgSelect = {
// Class to handle selection
var Selection = {
/*
* Return actual selection.
*/
getSelection: function() {
// Select text from Docuement
var myBrowser = getBrowser();
var selObj = myBrowser.contentWindow.getSelection();

value = selObj.toString();
get: function() {
// Select a text from the actual document
var selObj = getBrowser().contentWindow.get();

// value is returned
var value = selObj.toString();

// If not text is selected, we try to get text
// If the text is not selected, we try to get it
// from inputs and textareas
if (value == "") {
if(value == "") {
try {
var focused = document.commandDispatcher.focusedElement;
var value = focused.value;
Expand All @@ -57,34 +57,35 @@ var firegpgSelect = {
catch (e) {
}
}
else
{
// the text is selected !
else {
value = selObj.getRangeAt(0);
documentFragment = value.cloneContents();

var s = new XMLSerializer();
var d = documentFragment;
var str = s.serializeToString(d);

var reg=new RegExp("<br />", "gi");
str = str.replace(reg,"\n");
reg=new RegExp("<br/>", "gi");
reg = new RegExp("<br/>", "gi");
str = str.replace(reg,"\n");
var reg=new RegExp("<br>", "gi");

var reg = new RegExp("<br>", "gi");
str = str.replace(reg,"\n");
reg=new RegExp("<[^>]+>", "g");
str = str.replace(reg, "");

value = str;
}


return value;
},

/*
* Return true if selection can be edit
* Return true if the selection is editable.
*/
isSelectionEdit: function() {
isEditable: function() {
// We try to get a text from a textaera or input :
try {
var focused = document.commandDispatcher.focusedElement;
Expand All @@ -97,20 +98,20 @@ var firegpgSelect = {
return false;
}

// If texte is empty, this is strange, so we consider that
// If text is empty, this is strange, so we consider that
// there are not textaera or input focused
if (value == "")
if(value == "")
return false;

return true; //If it's ok !
},

/*
* Edit selection
* Modify the selection.
*/
setSelection: function(texte) {
set: function(text) {
// We verify that the selection can be edited
if (this.isSelectionEdit()) {
if(this.isEditable()) {
// Get the focused element
var focused = document.commandDispatcher.focusedElement;
var value = focused.value;
Expand All @@ -119,11 +120,11 @@ var firegpgSelect = {
var chaine = focused.value;

// We create the new string and replace it into focused element
focused.value = chaine.substring(0, startPos) + texte + chaine.substring(endPos, chaine.length);
focused.value = chaine.substring(0, startPos) + text + chaine.substring(endPos, chaine.length);

// We select the new text.
focused.selectionStart = startPos;
focused.selectionEnd = startPos + texte.length ;
focused.selectionEnd = startPos + text.length ;
}
}
}
Expand Down

0 comments on commit 66012be

Please sign in to comment.