Changeset 3399 for trunk/jons-gtk2-gui

Show
Ignore:
Timestamp:
03/22/03 12:28:27 (6 years ago)
Author:
bostjanlah
Message:

Add character encoding selection

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/jons-gtk2-gui/src/convo.cpp

    r3384 r3399  
    2828 
    2929#include <list> 
     30#include <iostream> 
    3031using namespace std; // for std::list 
    3132 
     
    4041    GtkWidget *send_urgent; 
    4142    GtkWidget *send_list; 
     43    GtkWidget *charset; 
    4244    GdkColor *clrFore; 
    4345    GdkColor *clrBack; 
     
    7981        c->window = 0; 
    8082        c->user = user; 
     83         
    8184        c->clrBack = new GdkColor; 
    8285        c->clrFore = new GdkColor; 
     
    101104} 
    102105 
    103 conversation *convo_find(unsigned long uin) 
     106conversation * 
     107convo_find(unsigned long uin) 
    104108{ 
    105109    for (list<conversation *>::iterator i = cnv.begin(); i != cnv.end(); ++i) 
     
    127131} 
    128132 
     133void 
     134charset_select(GtkWidget *w, struct conversation *c) 
     135{ 
     136    char *p =   (char *)g_object_get_data(G_OBJECT(w), "encoding"); 
     137    if (strcmp(p, c->user->UserEncoding()) == 0) 
     138        return; 
     139         
     140    unsigned long uin = c->user->Uin(); 
     141    ICQUser *u = gUserManager.FetchUser(uin, LOCK_W); 
     142    u->SetUserEncoding(p); 
     143    u->SaveLicqInfo(); 
     144    gUserManager.DropUser(u); 
     145    c->user = gUserManager.FetchUser(uin, LOCK_R); 
     146} 
     147 
     148void 
     149charset_popup(GtkWidget *w, struct conversation *c) 
     150{ 
     151    /* Add the character set menu */ 
     152    GtkWidget *menu = gtk_menu_new(); 
     153    const char *user_enc = c->user->UserEncoding(); 
     154    if (user_enc == NULL || *user_enc == 0) 
     155        user_enc = "UTF-8"; 
     156    for (encoding *ep = encodings; ep->name != NULL; ++ep) { 
     157        char *lbl = g_strdup_printf("%s (%s)", ep->name, ep->enc); 
     158        GtkWidget *item = gtk_check_menu_item_new_with_label(lbl); 
     159        g_free(lbl); 
     160        if (strcmp(user_enc, ep->enc) == 0) 
     161            gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); 
     162        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); 
     163        g_object_set_data(G_OBJECT(item), "encoding", ep->enc); 
     164        g_signal_connect(G_OBJECT(item), "activate", 
     165                G_CALLBACK(charset_select), c); 
     166    } 
     167    gtk_widget_show_all(menu); 
     168    gtk_menu_popup(GTK_MENU(menu), 0, 0, 0, 0, 0, gtk_get_current_event_time()); 
     169} 
     170     
    129171void convo_show(conversation *c) 
    130172{ 
     
    196238    /* Send the message to contact list */ 
    197239    c->send_list = gtk_check_button_new_with_mnemonic("M_ultiple recipients"); 
    198     gtk_box_pack_start(GTK_BOX(options_box), c->send_list, FALSE, FALSE, 0); 
     240    gtk_box_pack_start(GTK_BOX(options_box), c->send_list, FALSE, FALSE, 5); 
     241     
     242    /* Character set */ 
     243    GtkWidget *bbox = hbutton_box_new(); 
     244    c->charset = gtk_button_new(); 
     245    gtk_container_add(GTK_CONTAINER(c->charset),  
     246            gtk_image_new_from_pixbuf(charset_icon)); 
     247    gtk_container_add(GTK_CONTAINER(bbox), c->charset); 
     248    gtk_box_pack_end(GTK_BOX(options_box), bbox, FALSE, FALSE, 0); 
     249    g_signal_connect(G_OBJECT(c->charset), "clicked",  
     250            G_CALLBACK(charset_popup), c); 
    199251 
    200252    /* Now pack the options_box */ 
     
    236288 
    237289    /* Set the title of the window */ 
    238     gchar *temp = c->user->GetAlias(); 
    239     const gchar *win_title = g_strdup_printf("Conversation with %s", temp); 
     290    gchar *win_title = g_strdup_printf("Conversation with %s",  
     291            s_convert_to_utf8(c->user->GetAlias(), c->user->UserEncoding()).c_str()); 
    240292    gtk_window_set_title(GTK_WINDOW(c->window), win_title); 
    241  
     293    g_free(win_title); 
     294     
    242295    /* Set the focus of the window */ 
    243296    gtk_window_set_focus(GTK_WINDOW(c->window), c->entry); 
     
    278331     
    279332    // How about their alias and an optional timestamp? 
    280     if (show_convo_timestamp) 
    281     { 
     333    if (show_convo_timestamp) { 
    282334        char szTime[26]; 
    283335        struct tm *_tm = localtime(&message_time); 
     
    310362{ 
    311363    /* Set the 2 button widgets */ 
    312     if(GTK_WIDGET_IS_SENSITIVE(c->send)) 
     364    if (GTK_WIDGET_IS_SENSITIVE(c->send)) 
    313365        gtk_widget_set_sensitive(c->send, false); 
    314366    toggle_close_cancel(c, 2); 
     
    331383    /* I don't like those popups to send urgent... so just send it ** 
    332384    ** urgently unless the user says to send it to the contact list*/    
    333     if((c->user->Status() == ICQ_STATUS_DND || 
     385    if ((c->user->Status() == ICQ_STATUS_DND || 
    334386       c->user->Status() == ICQ_STATUS_OCCUPIED) && 
    335387       !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_urgent))) 
     
    338390    strcpy(c->etag->buf, "Sending message "); 
    339391 
    340     if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_server))) 
     392    if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_server))) 
    341393        strcat(c->etag->buf, "directly ... "); 
    342394    else 
     
    344396 
    345397    /* Send the message */ 
    346     if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_urgent)) || 
    347        urgent) 
    348     {  
    349        c->etag->e_tag = icq_daemon->icqSendMessage(c->user->Uin(), message, 
    350          (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_server))), 
    351          ICQ_TCPxMSG_URGENT); 
    352     } 
    353  
     398    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_urgent)) || 
     399          urgent) 
     400      c->etag->e_tag = icq_daemon->icqSendMessage(c->user->Uin(), message, 
     401            (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_server))), 
     402            ICQ_TCPxMSG_URGENT); 
    354403    /* Send to contact list */ 
    355     else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_list))) 
    356     { 
     404    else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_list))) 
    357405      c->etag->e_tag = icq_daemon->icqSendMessage(c->user->Uin(), message, 
    358              (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_server))), 
    359              ICQ_TCPxMSG_LIST); 
    360     } 
    361  
     406                (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_server))), 
     407        ICQ_TCPxMSG_LIST); 
    362408    else /* Just send it normally */ 
    363     { 
    364409      c->etag->e_tag = icq_daemon->icqSendMessage(c->user->Uin(), message, 
    365              (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_server))), 
    366              ICQ_TCPxMSG_NORMAL); 
    367     } 
     410            (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->send_server))), 
     411        ICQ_TCPxMSG_NORMAL); 
    368412 
    369413    /* Take care of the etd buffer and add it to the slist */ 
     
    407451 
    408452    /* If the window doesn't exist, don't show anything */ 
    409     if(c == 0) 
    410     { 
     453    if (c == 0) { 
    411454        system_status_refresh(); 
    412455        return; 
     
    416459 
    417460    /* Make sure we really have an event */ 
    418     if(u_event == 0) 
     461    if (u_event == 0) 
    419462        return; 
    420463 
     
    423466 
    424467    // Get the color that it was sent in if it's wanted 
    425     if (recv_colors) 
    426     { 
     468    if (recv_colors) { 
    427469        if (!c->clrBack) 
    428470            c->clrBack = new GdkColor; 
     
    435477                pIcqColor->Background() == 0x00FFFFFF) 
    436478            bIgnoreBW = true; 
    437         else 
    438         { 
     479        else { 
    439480            c->clrFore->red   = pIcqColor->ForeRed() * 257; 
    440481            c->clrFore->green = pIcqColor->ForeGreen() * 257; 
     
    447488        } 
    448489    } 
    449     else 
    450     { 
    451         if (c->clrFore) 
    452         { 
     490    else { 
     491        if (c->clrFore) { 
    453492            delete c->clrFore; 
    454493            c->clrFore = 0; 
    455494        } 
    456  
    457         if (c->clrBack) 
    458         { 
     495        if (c->clrBack) { 
    459496            delete c->clrBack; 
    460497            c->clrBack = 0; 
     
    464501    // How about their alias and an optional timestamp? 
    465502    GtkTextBuffer *tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(c->text)); 
    466     convo_nick_timestamp(c->text, c->user->GetAlias(), u_event->Time(), "remote"); 
     503    convo_nick_timestamp(c->text,  
     504            s_convert_to_utf8(c->user->GetAlias(), c->user->UserEncoding()).c_str(),  
     505            u_event->Time(), "remote"); 
    467506    GtkTextIter iter; 
    468507    gtk_text_buffer_get_end_iter(tb, &iter); 
    469508    gchar *txt; 
    470509     
    471     switch (u_event->SubCommand()) 
    472     { 
     510    switch (u_event->SubCommand()) { 
    473511      case ICQ_CMDxSUB_MSG: 
     512            cerr << "encoding: " << c->user->UserEncoding() << endl 
     513                    << "text: " << u_event->Text() << endl; 
    474514            txt = convert_to_utf8(u_event->Text(), c->user->UserEncoding()); 
    475             if (!bIgnoreBW) 
    476             { 
     515            if (!bIgnoreBW) { 
    477516                GtkTextTag *tag = gtk_text_buffer_create_tag(tb, NULL,  
    478517                        "foreground-gdk", c->clrFore,