You guys could post your commands on http://gist.github.com - they have
syntax highlighting and they support ubiquity commands.

@Toph Are you using ubiquity from source? If yes, can you send a diff with
your changes so we can take a better look?

On Mon, Feb 16, 2009 at 12:29 PM, Toph <[email protected]> wrote:

> Hello Paulo,
> I just found Ubiquity last week and was playing around a bit with the
> e-mail command
> since I didn't find it quite as useful as what I would like. Perhaps we
> could merge our
> code if you find mine useful.
>
> I basically updated two things: 1) I updated the noun_type_contact and
> getGmailContacts()
>  in "feed-parts/header/en/nountypes.js" to be a little bit smarter. It now
> imports all
> available fields and adds an object containing all of the data to the
> suggestion. It leaves
> the text and html fields of the suggestion as the contact's email address,
> so unless
> people are grabbing data from the noun_type_contact.contactList variable,
> it should
> be backwards compatible with everything currently in the works. 2) I
> created a better
> preview for the e-mail that updates as you type and looks more like what an
> e-mail
> should look like.
>
> I tested my changes fairly thoroughly but there still may be bugs, so
> please let me
> know if you see anything that might break or that needs to be cleaned up
> :-)
>
> I haven't had a chance to check out the source and update it there, so
> things could
> be different, but I wanted to get this on the list before I forgot about
> it. Appropriate
> portions of the files are below:
>
> (Please forgive any formatting errors that g-mail introduces...the file was
> formatted
> correctly in my editor)
>
> -------------------
> nountypes.js
> -------------------
> function getGmailContacts( callback ) {
>   var url = "http://mail.google.com/mail/contacts/data/export";;
>   var params = {
>     exportType: "ALL",
>     out: "CSV"
>   };
>
>   jQuery.get(url, params, function(data) {
>     data = data.split("\n");
>
>     var contacts = {};
>
>     for each( var line in data ) {
>       var splitLine = line.split(",");
>
>       if (splitLine[0].match("Name")) {
>         continue;
>       }
>
>       var contact = {};
>
>       contact.emails = {};
>       contact.numbers = {};
>
>       contact.name = splitLine[0];
>       contact.emails.home = splitLine[1];
>
>       if (splitLine.length >= 14) {
>         contact.notes = splitLine[2];
>         contact.description = splitLine[3];
>         contact.emails.work = splitLine[4];
>         contact.im = splitLine[5];
>
>         contact.numbers.home = splitLine[6];
>         contact.numbers.mobile = splitLine[7];
>         contact.numbers.pager = splitLine[8];
>         contact.numbers.fax = splitLine[9];
>
>         contact.company = splitLine[10];
>         contact.title = splitLine[11];
>         contact.other = splitLine[12];
>         contact.address = splitLine[13];
>       }
>
>       if (contact.numbers.mobile != "") {
>         contact.phone = contact.numbers.mobile;
>       } else if (contact.numbers.home != "") {
>         contact.phone = contact.numbers.home;
>       }
>
>       contact.email = contact.emails.home;
>
>       contacts[contact.name] = contact;
>     }
>
>     callback(contacts);
>   }, "text");
> }
>
> var noun_type_contact = {
>   _name: "contact",
>
>   contactList: null,
>
>   contactListLastUpdated: null,
>
>   callback:function(contacts) {
>     noun_type_contact.contactList = contacts;
>     contactListLastUpdated = new Date();
>   },
>
>   suggest: function(text, html) {
>     var now = new Date();
>
>     if (noun_type_contact.contactList == null ||
>       now.getMinutes() - contactListLastUpdated.getMinutes() > 10) {
>       getGmailContacts( noun_type_contact.callback);
>       var suggs = noun_type_email.suggest(text, html);
>       return suggs.length > 0 ? suggs : [];
>     }
>
>     if( text.length < 2 ) return [];
>
>     var suggestions  = [];
>     for ( var c in this.contactList ) {
>       var contact = this.contactList[c];
>
>       if (contact.email == null || contact.email == "") {
>         contact.email = "";
>       }
>
>       if (contact.name.match(text, "i") != null ||
> contact.email.match(text, "i") != null) {
>         suggestions.push(CmdUtils.makeSugg(contact.name, contact.name,
> contact));
>       }
>     }
>
>     var suggs = noun_type_email.suggest(text, html);
>
>     if (suggs.length > 0) {
>       suggestions.push(suggs[0]);
>     }
>
>     return suggestions.splice(0, 5);
>   }
> };
>
> -------------------
> command file
> -------------------
> var _author = { name: "Topher Fangio", email: "[email protected]" };
>
> function _replaceNull(value) {
>   return value == null ? "" : value;
> }
>
> CmdUtils.CreateCommand({
>   name: "my-email",
>
>   author: _author,
>
>   takes: { "message": noun_arb_text },
>
>   modifiers: { "to": noun_type_contact, "as": noun_arb_text },
>
>   preview:
>     function(pblock, message, mods) {
>       if (pblock == null) {
>         return;
>       }
>
>       var contact = mods["to"].data
>
>       if (contact == null) {
>         contact = { name:"", email:"" };
>       }
>
>       var msg = "";
>
>       msg += "<p>Sends the following e-mail to the requested
> recipient.</p><hr />";
>
>       msg += "<strong>To: ${name}</strong>";
>
>       msg += "&lt;${email}&gt;<br />";
>       msg += "<strong>Subject:</strong> <em>${subject}</em><br />";
>
>       msg += "<p>${message}</p>";
>
>       var templateData = {
>         name: contact.name + " ",
>         email: contact.email,
>         subject: mods["as"].text,
>         message: message.html
>       };
>
>       pblock.innerHTML = CmdUtils.renderTemplate( msg, templateData );
>     },
>
>   execute:
>       function() {
>         displayMessage("sending email!!!");
>       }
> });
>
>
> On Mon, Feb 16, 2009 at 8:52 AM, psargaco <[email protected]>wrote:
>
>>
>> I've done a bit of customization on the email command. The standard
>> one wasn't really working for me because I find it more useful to
>> write the subject in ubiquity instead of writing the body of the
>> message. Even so, that is still a possibility in my version of the
>> command. I'm posting it here just for kicks, I don't think it'll be
>> very useful for most people because part of the predefined contents
>> were translated to European Portuguese. And there are still some rough
>> edges, I haven't fully tested it yet. Meanwhile if anybody knows a way
>> how to distinguish between directObj having been obtained from the
>> command line or from the selected text on the page I would appreciate
>> if you could share it with me. Other suggestions will be greatly
>> appreciated.
>>
>> Here's my version of the command:
>>
>> /* No changes in this function  */
>> function findGmailTab() {
>>  var window = Application.activeWindow;
>>
>>  var gmailURL = "://mail.google.com";
>>  var currentLocation = String
>> (Application.activeWindow.activeTab.document.location);
>>  if(currentLocation.indexOf(gmailURL) != -1) {
>>    return Application.activeWindow.activeTab;
>>  }
>>
>>  for (var i = 0; i < window.tabs.length; i++) {
>>    var tab = window.tabs[i];
>>    var location = String(tab.document.location);
>>    if (location.indexOf(gmailURL) != -1) {
>>      return tab;
>>    }
>>  }
>>  return null;
>> }
>>
>> CmdUtils.CreateCommand({
>>  name: "my_email",
>>  takes: {"message": noun_arb_text},
>>  icon: "chrome://ubiquity/skin/icons/email.png",
>>  modifiers: {subject:noun_arb_text,
>>                to: noun_type_contact},
>>  description:"Begins composing an email to a person from your contact
>> list.",
>>  help:"Currently only works with <a href=\"http://mail.google.com
>> \">Google Mail</a>, so you'll need a Gmail account to use it." +
>>       " Try selecting part of a web page (including links, images,
>> etc) and then issuing &quot;email this&quot;.  You can" +
>>       " also specify the recipient of the email using the word
>> &quot;to&quot; and the name of someone from your contact list." +
>>       " For example, try issuing &quot;email hello to jono&quot;
>> (assuming you have a friend named &quot;jono&quot;).",
>>  preview: function(pblock, directObj, modifiers) {
>>    var html = "Creates an email message ";
>>    if (modifiers.subject) {
>>        html += "with the subject " + modifiers.subject.text + " ";
>>    }
>>    if (modifiers.to) {
>>      html += "to " + modifiers.to.text + " ";
>>    }
>>    if (directObj.html) {
>>      html += "with these contents:" + directObj.html;
>>    } else {
>>      html += "with a link to the current page.";
>>    }
>>    pblock.innerHTML = html;
>>  },
>>
>>  execute: function(directObj, headers) {
>>    var html = directObj.html;
>>    var document = context.focusedWindow.document;
>>    var title, subject_text;
>>    var toAddress = "";
>>    var location = document.location;
>>    if (document.title)
>>      title = document.title;
>>    else
>>      title = location;
>>    var gmailTab = findGmailTab();
>>    var pageLink = "<a href=\"" + location + "\">" + title + "</a>";
>>    if (html) {
>>      html = ("&quot;" + html + "&quot;" + "<br /><p>in " + pageLink +
>> ":</p>");
>>    } else {
>>      // If there's no selection, just send the current page.
>>      html = "<p>Vê este endereço: " + pageLink + ".</p>";
>>    }
>>    html = html + "<br /><br />    Paulo"
>>
>>    if (headers.subject) {
>>        if (headers.subject.text) {
>>            subject_text = headers.subject.text;
>>        } else {
>>            subject_text = title;
>>        }
>>    }
>>
>>    if (headers.to)
>>      if (headers.to.text)
>>          toAddress = headers.to.text;
>>
>>    if (gmailTab) {
>>      // Note that this is technically insecure because we're
>>      // accessing wrappedJSObject, but we're only executing this
>>      // in a Gmail tab, and Gmail is trusted code.
>>      var console =
>> gmailTab.document.defaultView.wrappedJSObject.console;
>>      var gmonkey =
>> gmailTab.document.defaultView.wrappedJSObject.gmonkey;
>>
>>      var continuer = function() {
>>        // For some reason continuer.apply() won't work--we get
>>        // a security violation on Function.__parent__--so we'll
>>        // manually safety-wrap this.
>>    try {
>>          var gmail = gmonkey.get("1.0");
>>          var sidebar = gmail.getNavPaneElement();
>>          var composeMail = sidebar.getElementsByTagName("span")[0];
>>      //var composeMail = sidebar.getElementById(":qw");
>>          var event = composeMail.ownerDocument.createEvent("Events");
>>          event.initEvent("click", true, false);
>>          composeMail.dispatchEvent(event);
>>          var active = gmail.getActiveViewElement();
>>      var toField = composeMail.ownerDocument.getElementsByName("to")
>> [0];
>>      toField.value = toAddress;
>>          var subject = active.getElementsByTagName("input")[0];
>>          if (subject) subject.value = subject_text;
>>          var iframe = active.getElementsByTagName("iframe")[0];
>>          if (iframe)
>>            iframe.contentDocument.execCommand("insertHTML", false,
>> html);
>>          else {
>>            var body = composeMail.ownerDocument.getElementsByName
>> ("body")[0];
>>            html = ("Note: the following probably looks strange
>> because " +
>>                    "you don't have rich formatting enabled.  Please "
>> +
>>                    "click the 'Rich formatting' link above, discard "
>> +
>>                    "this message, and try " +
>>                    "the email command again.\n\n" + html);
>>            body.value = html;
>>          }
>>          gmailTab.focus();
>>        } catch (e) {
>>          displayMessage({text: "A gmonkey exception occurred.",
>>                          exception: e});
>>        }
>>      };
>>
>>      gmonkey.load("1.0", continuer);
>>    } else {
>>      // No Gmail tab open?  Open a new one:
>>      var params = {fs:1, tf:1, view:"cm", su:title, to:toAddress,
>> body:html};
>>      Utils.openUrlInBrowser("http://mail.google.com/mail/?"; +
>>                 Utils.paramsToString(params));
>>    }
>>  }
>> });
>>
>>
>
>
> --
> Topher Fangio
> Software Developer
> [email protected]
>
> >
>


-- 
Fernando "Takai"
http://flickr.com/photos/supeertakai
http://fernandotakai.jaiku.com

Get Ubiquity: https://ubiquity.mozilla.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ubiquity-firefox" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ubiquity-firefox?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to