]> git.0d.be Git - empathy.git/commitdiff
Use a default Template.html if not provided by the theme.
authorXavier Claessens <xclaesse@gmail.com>
Fri, 18 Jul 2008 22:09:13 +0000 (00:09 +0200)
committerXavier Claessens <xclaesse@gmail.com>
Thu, 11 Jun 2009 16:06:30 +0000 (18:06 +0200)
data/Template.html [new file with mode: 0644]
libempathy-gtk/empathy-theme-adium.c

diff --git a/data/Template.html b/data/Template.html
new file mode 100644 (file)
index 0000000..708e85b
--- /dev/null
@@ -0,0 +1,159 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+       <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+       <base href="%@">
+       <script type="text/ecmascript" defer="defer">
+       
+               //Appending new content to the message view
+               function appendMessage(html) {
+                       shouldScroll = nearBottom();
+               
+                       //Remove any existing insertion point
+                       insert = document.getElementById("insert");
+                       if(insert) insert.parentNode.removeChild(insert);
+
+                       //Append the new message to the bottom of our chat block
+                       chat = document.getElementById("Chat");
+                       range = document.createRange();
+                       range.selectNode(chat);
+                       documentFragment = range.createContextualFragment(html);
+                       chat.appendChild(documentFragment);
+                       
+                       alignChat(shouldScroll);
+               }
+               function appendMessageNoScroll(html) {
+                       //Remove any existing insertion point
+                       insert = document.getElementById("insert");
+                       if(insert) insert.parentNode.removeChild(insert);
+
+                       //Append the new message to the bottom of our chat block
+                       chat = document.getElementById("Chat");
+                       range = document.createRange();
+                       range.selectNode(chat);
+                       documentFragment = range.createContextualFragment(html);
+                       chat.appendChild(documentFragment);
+               }
+               function appendNextMessage(html){
+                       shouldScroll = nearBottom();
+
+                       //Locate the insertion point
+                       insert = document.getElementById("insert");
+               
+                       //make new node
+                       range = document.createRange();
+                       range.selectNode(insert.parentNode);
+                       newNode = range.createContextualFragment(html);
+
+                       //swap
+                       insert.parentNode.replaceChild(newNode,insert);
+                       
+                       alignChat(shouldScroll);
+               }
+               function appendNextMessageNoScroll(html){
+                       //Locate the insertion point
+                       insert = document.getElementById("insert");
+               
+                       //make new node
+                       range = document.createRange();
+                       range.selectNode(insert.parentNode);
+                       newNode = range.createContextualFragment(html);
+
+                       //swap
+                       insert.parentNode.replaceChild(newNode,insert);
+               }
+               
+               //Auto-scroll to bottom.  Use nearBottom to determine if a scrollToBottom is desired.
+               function nearBottom() {
+                       return ( document.body.scrollTop >= ( document.body.offsetHeight - ( window.innerHeight * 1.2 ) ) );
+               }
+               function scrollToBottom() {
+                       document.body.scrollTop = document.body.offsetHeight;
+               }
+
+               //Dynamically exchange the active stylesheet
+               function setStylesheet( id, url ) {
+                       code = "<style id=\"" + id + "\" type=\"text/css\" media=\"screen,print\">";
+                       if( url.length ) code += "@import url( \"" + url + "\" );";
+                       code += "</style>";
+                       range = document.createRange();
+                       head = document.getElementsByTagName( "head" ).item(0);
+                       range.selectNode( head );
+                       documentFragment = range.createContextualFragment( code );
+                       head.removeChild( document.getElementById( id ) );
+                       head.appendChild( documentFragment );
+               }
+               
+               //Swap an image with its alt-tag text on click, or expand/unexpand an attached image
+               document.onclick = imageCheck;
+               function imageCheck() {         
+                       node = event.target;
+                       if(node.tagName == 'IMG' && !client.zoomImage(node) && node.alt) {
+                               a = document.createElement('a');
+                               a.setAttribute('onclick', 'imageSwap(this)');
+                               a.setAttribute('src', node.getAttribute('src'));
+                               a.className = node.className;
+                               text = document.createTextNode(node.alt);
+                               a.appendChild(text);
+                               node.parentNode.replaceChild(a, node);
+                       }
+               }
+
+               function imageSwap(node) {
+                       shouldScroll = nearBottom();
+
+                       //Swap the image/text
+                       img = document.createElement('img');
+                       img.setAttribute('src', node.getAttribute('src'));
+                       img.setAttribute('alt', node.firstChild.nodeValue);
+                       img.className = node.className;
+                       node.parentNode.replaceChild(img, node);
+                       
+                       alignChat(shouldScroll);
+               }
+               
+               //Align our chat to the bottom of the window.  If true is passed, view will also be scrolled down
+               function alignChat(shouldScroll) {
+                       var windowHeight = window.innerHeight;
+                       
+                       if (windowHeight > 0) {
+                               var contentElement = document.getElementById('Chat');
+                               var contentHeight = contentElement.offsetHeight;
+                               if (windowHeight - contentHeight > 0) {
+                                       contentElement.style.position = 'relative';
+                                       contentElement.style.top = (windowHeight - contentHeight) + 'px';
+                               } else {
+                                       contentElement.style.position = 'static';
+                               }
+                       }
+                       
+                       if (shouldScroll) scrollToBottom();
+               }
+               
+               function windowDidResize(){
+                       alignChat(true/*nearBottom()*/); //nearBottom buggy with inactive tabs
+               }
+               
+               window.onresize = windowDidResize;
+       </script>
+       
+       <!-- This style is shared by all variants. !-->
+       <style id="baseStyle" type="text/css" media="screen,print">     
+               %@  
+               *{ word-wrap:break-word; }
+               img.scaledToFitImage { height:auto; width:100%; }
+       </style>
+       
+       <!-- Although we call this mainStyle for legacy reasons, it's actually the variant style !-->
+       <style id="mainStyle" type="text/css" media="screen,print">     
+               @import url( "%@" );
+       </style>
+
+</head>
+<body onload="alignChat(true);" style="==bodyBackground==">
+%@
+<div id="Chat">
+</div>
+%@
+</body>
+</html>
index 89790b6442743a4fc7aaed4367198e2aef9f7569..9e3c41527a033b3887faa5f2a30d1014b9fd3675 100644 (file)
@@ -74,20 +74,18 @@ theme_adium_load (EmpathyThemeAdium *theme)
        EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
        gchar                 *basedir;
        gchar                 *file;
-       gchar                 *template_html;
+       gchar                 *template_html = NULL;
        gsize                  template_len;
        GString               *string;
-       gchar                **strv;
+       gchar                **strv = NULL;
        gchar                 *content;
        gchar                 *css_path;
+       guint                  len = 0;
+       guint                  i = 0;
 
        basedir = g_build_filename (priv->path, "Contents", "Resources", NULL);
 
        /* Load html files */
-       file = g_build_filename (basedir, "Template.html", NULL);
-       g_file_get_contents (file, &template_html, &template_len, NULL);
-       g_free (file);
-
        file = g_build_filename (basedir, "Incoming", "Content.html", NULL);
        g_file_get_contents (file, &priv->in_content_html, &priv->in_content_len, NULL);
        g_free (file);
@@ -106,18 +104,48 @@ theme_adium_load (EmpathyThemeAdium *theme)
 
        css_path = g_build_filename (basedir, "main.css", NULL);
 
-       /* Replace %@ with the needed information in the template html */
-       strv = g_strsplit (template_html, "%@", 5);
+       /* There is 2 formats for Template.html: The old one has 4 parameters,
+        * the new one has 5 parameters. */
+       file = g_build_filename (basedir, "Template.html", NULL);
+       if (g_file_get_contents (file, &template_html, &template_len, NULL)) {
+               strv = g_strsplit (template_html, "%@", -1);
+               len = g_strv_length (strv);
+       }
+       g_free (file);
+
+       if (len != 5 && len != 6) {
+               /* Either the theme has no template or it don't have the good
+                * number of parameters. Fallback to use our own template. */
+               g_free (template_html);
+               g_strfreev (strv);
+
+               file = empathy_file_lookup ("Template.html", "data");
+               g_file_get_contents (file, &template_html, &template_len, NULL);
+               g_free (file);
+               strv = g_strsplit (template_html, "%@", -1);
+               len = g_strv_length (strv);
+       }
+
+       /* Replace %@ with the needed information in the template html. */
        string = g_string_sized_new (template_len);
-       g_string_append (string, strv[0]);
+       g_string_append (string, strv[i++]);
        g_string_append (string, basedir);
-       g_string_append (string, strv[1]);
-       g_string_append (string, css_path);
-       g_string_append (string, strv[2]);
+       g_string_append (string, strv[i++]);
+       if (len == 6) {
+               /* We include main.css by default */
+               g_string_append_printf (string, "@import url(\"%s\");", css_path);
+               g_string_append (string, strv[i++]);
+               /* FIXME: We should set the variant css here */
+               g_string_append (string, "");
+       } else {
+               /* FIXME: We should set main.css OR the variant css */
+               g_string_append (string, css_path);
+       }
+       g_string_append (string, strv[i++]);
        g_string_append (string, ""); /* We don't want header */
-       g_string_append (string, strv[3]);
-       g_string_append (string, ""); /* We have no footer */
-       g_string_append (string, strv[4]);
+       g_string_append (string, strv[i++]);
+       g_string_append (string, ""); /* FIXME: We don't support footer yet */
+       g_string_append (string, strv[i++]);
        content = g_string_free (string, FALSE);
 
        /* Load the template */