# -*- coding: iso-8859-1 -*-
u"""
    MoinMoin - GoogleTalk macro Version 0.1 ALPHA
    This macro will let your visitors to chat directly with you

    <<GoogleTalk(badge="the badge id", title="your title for the link", nichname="whatever you like")>>
    You have allways create a badge id via your Google Talk Account and add this to your macro!

    Examples:
     * <<GoogleTalk(z01q6amlqf4qijtj2tko5ro20gi71ftvhgl62duou3thjptol6ubdfasdfsadfadhsbgkm54q1v5pnott46lk73nfld8g2vhavoljvsnsjsfjanud07hg)>>
     * <<GoogleTalk(badge="z01q6amlqf4qijtj2tko5ro20gi71ftvhgl62duou3thjptol6ubdfasdfsadfadhsbgkm54q1v5pnott46lk73nfld8g2vhavoljvsnsjsfjanud07hg", title="Open Up and Say aah!", nickname="Poison")>>

    @copyright: 2011 by MarcelHäfner (http://moinmo.in/MarcelHäfner),

    @license: GNU GPL, see COPYING for details.

    Attention:
     * This macro just using features from Google Talk. Read Term of Services, Privacy Polices and Legal Notice:
       http://www.google.com//talk/terms.html
     * To work with this macro you need to have a Google Mail-/Talk-Account and also neeed first to create a
       unique batch for yourself, see here http://www.google.com/talk/service/badge/New
       1. change style to "URL only"
       2. copy the value from the paramter "tk"
       3. this is now your "badge" to add to your macro

"""

from MoinMoin import wikiutil
Dependencies = ['time', ]

def macro_GoogleTalk(macro, badge, title=u"Talk to us!", nickname=u"MoinMoin", ssl=False):
    request = macro.request
    _ = request.getText
    
    if ssl is True:
        protocol = "https"
    else:
        protocol = "http"
    if badge is not None:
        parameters = {
            "title":  wikiutil.escape(title),
            "nickname": wikiutil.escape(nickname),
            "badge": wikiutil.escape(badge),
            "height": "12", 
            "width": "12", 
            "protocol": protocol, 
        }
        
        html = u"""
        <span class="googletalk %(nickname)s">
            <img style="padding:0 2px 0 0;margin:0;border:none" src="%(protocol)s://www.google.com/talk/service/badge/Show?tk=%(badge)s&amp;w=%(width)s&amp;h=%(height)s" alt="" height="%(height)s" width="%(width)s">
            <a href="%(protocol)s://www.google.com/talk/service/badge/Start?tk=%(badge)s" target="_blank" title="%(nickname)s">%(title)s</a>
        </span>
        """ % parameters
    else:
        parameters = {
                      "message": _("Error, Missing parameter 'badge'"), 
                      }
        html = """
            <div class="error">
                <p>%(message)s<br><a href="http://www.google.com/talk/service/badge/New">Google Talk Servic</a></p>
            </div>
        """ % parameters

    return macro.formatter.rawHTML(html)

