Changeset 7cfad2e713662f0eeea22b5c5d19c6a9596c4413

Show
Ignore:
Timestamp:
10/25/09 14:24:51 (4 years ago)
Author:
Benjamin Herr <ben@…>
git-author:
Benjamin Herr <ben@0x539.de> / 2009-01-16T21:27:01Z+0100
Parents:
ded2b4e54b49492e039d814453f12549e56ad518
Children:
63ca8047cee68d8fa40d41e4a02e1c38aad3726a
git-committer:
Benjamin Herr <ben@0x539.de> / 2009-10-25T14:24:51Z+0100
Message:

htmlexport: added "written by" tooltips, fixed (validation) warnings

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • code/commands/file-commands.cpp

    rded2b4e r7cfad2e  
    226226#include <ctime> 
    227227#include <cstring> 
     228#include <cmath> 
    228229 
    229230#include <gtkmm/textbuffer.h> 
     
    242243  line_counter = 0; 
    243244        xmlpp::Element* last_node = content; 
    244         last_node->add_child("div")->set_attribute("class", "line_no"); 
    245  
    246         //Glib::RefPtr<Gtk::TextBuffer> buffer( 
    247         //      Glib::wrap( 
     245        last_node->add_child("span")->set_attribute("class", "line_no"); 
     246 
    248247        GtkTextBuffer* buffer = GTK_TEXT_BUFFER(document.get_text_buffer()); 
    249248        InfTextGtkBuffer* inf_buffer 
     
    251250                                inf_session_get_buffer(INF_SESSION(document.get_session()))); 
    252251 
    253         guint user_id; 
    254         bool user_active = false; 
     252        InfTextUser* user = 0; 
    255253 
    256254        GtkTextIter begin; 
     
    260258                return; 
    261259 
    262         // TODO: I just made this use the Gtk+ API instead of Gtkmm at like 2 am, 
    263         //       surely there are a bunch of segfaults/memleaks lurking 
    264260        for (;;) { 
    265261                GtkTextIter next = begin; 
     
    282278 
    283279                                // drop author <span/> for a moment for the line number <span/> 
    284                                 if (user_active) 
     280                                if (user) 
    285281                                        last_node = last_node->get_parent(); 
    286282                                last_node 
    287                                   ->add_child("div") 
     283                                  ->add_child("span") 
    288284                                  ->set_attribute("class", "line_no"); 
    289                                 if (user_active) { 
     285                                if (user) { 
    290286                                        last_node = last_node->add_child("span"); 
    291287                                        last_node->set_attribute( 
    292288                                                "class", 
    293                                                 Glib::ustring::compose("user_%1", user_id)); 
     289                                                Glib::ustring::compose("user_%1", 
     290                                                                       inf_user_get_id(INF_USER(user)))); 
     291                                        last_node->set_attribute( 
     292                                          "title", 
     293                                          Glib::ustring::compose(_("written by: %1"), 
     294                                                                 inf_user_get_name(INF_USER(user)))); 
    294295                                } 
    295296                        } 
     
    307308 
    308309                // check author, insert new <span/> if necessary 
    309                 InfTextUser* user 
     310                InfTextUser* new_user 
    310311                        = inf_text_gtk_buffer_get_author(inf_buffer, &next); 
    311312 
    312                 if (user) { 
    313                         guint new_id = inf_user_get_id(INF_USER(user)); 
    314                         if (!user_active || new_id != user_id) { 
    315                                 if (user_active) 
     313                if (new_user) { 
     314                        guint new_id = inf_user_get_id(INF_USER(new_user)); 
     315                        if (!user || user != new_user) { 
     316                                if (user) 
    316317                                        last_node = last_node->get_parent(); 
    317318 
     
    320321                                        "class", 
    321322                                        Glib::ustring::compose("user_%1", new_id)); 
     323                                last_node->set_attribute( 
     324                                  "title", 
     325                                  Glib::ustring::compose(_("written by: %1"), 
     326                                                         inf_user_get_name(INF_USER(new_user)))); 
    322327                        } 
    323328 
    324                         user_id = new_id; 
    325                         user_active = true; 
     329                        user = new_user; 
    326330                        users.insert(user); 
    327331                } else { 
    328                         if (user_active) 
     332                        if (user) 
    329333                                last_node = last_node->get_parent(); 
    330                         user_active = false; 
     334                        user = 0; 
    331335                } 
    332336        } 
     
    381385                guint id = inf_user_get_id(INF_USER(*i)); 
    382386                gdouble hue = inf_text_user_get_hue(*i); 
    383                 if (hue == 1) 
    384                         hue = 0; 
     387                hue = std::fmod(hue, 1); 
    385388 
    386389                Gdk::Color c; 
    387390                c.set_hsv(360.0 * hue, 0.35, 1.0); 
    388391                gchar const* name = inf_user_get_name(INF_USER(*i)); 
    389                 // TODO: figure out if we can get "written by <name>" tooltips easily 
    390392                unsigned int rgb = 
    391393                          ((c.get_red()   & 0xff00) << 8) 
     
    411413void export_html(DocWindow& document, const Glib::ustring& output_path) { 
    412414        xmlpp::Document output; 
     415 
     416  output.set_internal_subset("html", 
     417    "-//W3C//DTD XHTML 1.1//EN", 
     418    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"); 
     419 
    413420        xmlpp::Element 
    414421                * root      = output.create_root_node("html", "http://www.w3.org/1999/xhtml"), 
     
    478485          static_cast<unsigned int>(std::log(line_counter)/std::log(10))+1)); 
    479486 
    480         output.write_to_file(output_path); 
     487        output.write_to_file(output_path, "utf-8"); 
    481488} 
    482489