~ubuntu-branches/ubuntu/precise/empathy/precise-proposed-201205180810

« back to all changes in this revision

Viewing changes to libempathy-gtk/empathy-chat-text-view.c

  • Committer: Bazaar Package Importer
  • Author(s): Brian Curtis, Brian Curtis, Ken VanDine
  • Date: 2011-06-01 10:35:24 UTC
  • mfrom: (1.1.70 upstream) (6.3.44 experimental)
  • Revision ID: james.westby@ubuntu.com-20110601103524-wx3wgp71394730jt
Tags: 3.1.1-1ubuntu1
[ Brian Curtis ]
* Merge with Debian experimental, remaining Ubuntu changes:
* debian/control:
  - Drop geoclue/mapping build-depends (they are in Universe)
  - Add Vcz-Bzr link
  - Add Suggests on telepathy-idle
  - Bump telepathy-butterfly, telepathy-haze to recommends
  - Don't recommend the freedesktop sound theme we have an ubuntu one
  - Add build depend for libunity-dev
* debian/rules:
  - Use autoreconf.mk
  - Disable map and location
* debian/empathy.install:
  - Install message indicator configuration
* debian/indicators/empathy:
  - Message indicator configuration
* debian/patches/01_lpi.patch:
  - Add Launchpad integration
* debian/patches/10_use_notify_osd_icons.patch:
  - Use the notify-osd image for new messages
* debian/patches/34_start_raised_execpt_in_session.patch
  - If not started with the session, we should always raise
* debian/patches/36_chat_window_default_size.patch:
  - Make the default chat window size larger
* debian/patches/37_facebook_default.patch:
  - Make facebook the default chat account type
* debian/patches/38_lp_569289.patch
  - Set freenode as default IRC network for new IRC accounts 
* debian/patches/41_unity_launcher_progress.patch
  - Display file transfer progress in the unity launcher

[ Ken VanDine ]
* debian/control
  - build depend on libgcr-3-dev instead of libgcr-dev
  - dropped build depends for libindicate, we will use telepathy-indicator
  - Depend on dconf-gsettings-backend | gsettings-backend
  - Added a Recommends for telepathy-indicator
* +debian/empathy.gsettings-override
  - Added an override for notifications-focus
* debian/patches/series
  - commented out 23_idomessagedialog_for_voip_and_ft.patch, until ido has 
    been ported to gtk3

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
#include <glib/gi18n-lib.h>
34
34
#include <gtk/gtk.h>
35
 
#include <gconf/gconf-client.h>
36
35
 
37
36
#include <telepathy-glib/util.h>
38
37
 
49
48
#include <libempathy/empathy-debug.h>
50
49
 
51
50
/* Number of seconds between timestamps when using normal mode, 5 minutes. */
52
 
#define TIMESTAMP_INTERVAL 300
 
51
#define TIMESTAMP_INTERVAL (5 * G_TIME_SPAN_MINUTE)
53
52
 
54
53
#define MAX_LINES 800
55
54
#define MAX_SCROLL_TIME 0.4 /* seconds */
66
65
        gboolean              find_wrapped;
67
66
        gboolean              find_last_direction;
68
67
        EmpathyContact       *last_contact;
69
 
        time_t                last_timestamp;
 
68
        gint64                last_timestamp;
70
69
        gboolean              allow_scrolling;
71
70
        guint                 notify_system_fonts_id;
72
 
        GConfClient          *gconf_client;
 
71
        GSettings            *gsettings_desktop;
 
72
        GSettings            *gsettings_chat;
73
73
        EmpathySmileyManager *smiley_manager;
74
74
        gboolean              only_if_date;
75
75
} EmpathyChatTextViewPriv;
209
209
        PangoFontDescription *font_description = NULL;
210
210
        gchar                *font_name;
211
211
 
212
 
        font_name = gconf_client_get_string (priv->gconf_client,
213
 
                        "/desktop/gnome/interface/document_font_name",
214
 
                        NULL);
 
212
        font_name = g_settings_get_string (priv->gsettings_desktop,
 
213
                        EMPATHY_PREFS_DESKTOP_INTERFACE_DOCUMENT_FONT_NAME);
215
214
 
216
215
        if (font_name != NULL) {
217
216
                font_description = pango_font_description_from_string (font_name);
220
219
                font_description = NULL;
221
220
        }
222
221
 
223
 
        gtk_widget_modify_font (GTK_WIDGET (view), font_description);
 
222
        gtk_widget_override_font (GTK_WIDGET (view), font_description);
224
223
 
225
224
        if (font_description) {
226
225
                pango_font_description_free (font_description);
228
227
}
229
228
 
230
229
static void
231
 
chat_text_view_notify_system_font_cb (GConfClient *conf,
232
 
                                      guint id,
233
 
                                      GConfEntry *entry,
234
 
                                      gpointer user_data)
 
230
chat_text_view_notify_system_font_cb (GSettings *gsettings,
 
231
                                      const gchar *key,
 
232
                                      EmpathyChatTextView *self)
235
233
{
236
 
        EmpathyChatTextView *view = user_data;
237
 
 
238
 
        chat_text_view_system_font_update (view);
 
234
        chat_text_view_system_font_update (self);
239
235
}
240
236
 
241
237
static void
274
270
        /* Clear menu item */
275
271
        if (gtk_text_buffer_get_char_count (priv->buffer) > 0) {
276
272
                item = gtk_separator_menu_item_new ();
277
 
                gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
 
273
                gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
278
274
                gtk_widget_show (item);
279
275
 
280
276
                item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
281
 
                gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
 
277
                gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
282
278
                gtk_widget_show (item);
283
279
 
284
280
                g_signal_connect_swapped (item, "activate",
344
340
        gdouble upper;
345
341
        gdouble page_size;
346
342
 
347
 
        vadj = gtk_text_view_get_vadjustment (GTK_TEXT_VIEW (view));
 
343
        vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view));
348
344
        value = gtk_adjustment_get_value (vadj);
349
345
        upper = gtk_adjustment_get_upper (vadj);
350
346
        page_size = gtk_adjustment_get_page_size (vadj);
402
398
 
403
399
static void
404
400
chat_text_view_append_timestamp (EmpathyChatTextView *view,
405
 
                                 time_t               timestamp,
 
401
                                 gint64               timestamp,
406
402
                                 gboolean             show_date)
407
403
{
408
404
        EmpathyChatTextViewPriv *priv = GET_PRIV (view);
414
410
 
415
411
        /* Append date if needed */
416
412
        if (show_date) {
417
 
                GDate *date;
418
 
                gchar  buf[256];
419
 
 
420
 
                date = g_date_new ();
421
 
                g_date_set_time_t (date, timestamp);
422
413
                /* Translators: timestamp displayed between conversations in
423
414
                 * chat windows (strftime format string) */
424
 
                g_date_strftime (buf, 256, _("%A %B %d %Y"), date);
425
 
                g_string_append (str, buf);
 
415
                tmp = empathy_time_to_string_utc (timestamp, _("%A %B %d %Y"));
 
416
                g_string_append (str, tmp);
426
417
                g_string_append (str, ", ");
427
 
                g_date_free (date);
 
418
                g_free (tmp);
428
419
        }
429
420
 
430
421
        /* Append time */
448
439
 
449
440
static void
450
441
chat_text_maybe_append_date_and_time (EmpathyChatTextView *view,
451
 
                                      time_t               timestamp)
 
442
                                      gint64               timestamp)
452
443
{
453
444
        EmpathyChatTextViewPriv *priv = GET_PRIV (view);
454
 
        GDate                   *date, *last_date;
 
445
        GDateTime               *date, *last_date;
455
446
        gboolean                 append_date = FALSE;
456
447
        gboolean                 append_time = FALSE;
 
448
        GTimeSpan                delta;
457
449
 
458
450
        /* Get the date from last message */
459
 
        last_date = g_date_new ();
460
 
        g_date_set_time_t (last_date, priv->last_timestamp);
 
451
        last_date = g_date_time_new_from_unix_utc (priv->last_timestamp);
461
452
 
462
453
        /* Get the date of the message we are appending */
463
 
        date = g_date_new ();
464
 
        g_date_set_time_t (date, timestamp);
 
454
        date = g_date_time_new_from_unix_utc (timestamp);
465
455
 
 
456
        delta = g_date_time_difference (last_date, date);
466
457
        /* If last message was from another day we append date and time */
467
 
        if (g_date_compare (date, last_date) > 0) {
 
458
        if (delta >= G_TIME_SPAN_DAY) {
468
459
                append_date = TRUE;
469
460
                append_time = TRUE;
470
461
        }
471
462
 
472
 
        g_date_free (last_date);
473
 
        g_date_free (date);
 
463
        g_date_time_unref (last_date);
 
464
        g_date_time_unref (date);
474
465
 
475
466
        /* If last message is 'old' append the time */
476
 
        if (timestamp - priv->last_timestamp >= TIMESTAMP_INTERVAL) {
 
467
        if (delta >= TIMESTAMP_INTERVAL) {
477
468
                append_time = TRUE;
478
469
        }
479
470
 
495
486
        if (down) {
496
487
                GtkAdjustment *adj;
497
488
 
498
 
                adj = gtk_text_view_get_vadjustment (GTK_TEXT_VIEW (widget));
 
489
                adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (widget));
499
490
                gtk_adjustment_set_value (adj,
500
491
                                          gtk_adjustment_get_upper (adj) -
501
492
                                          gtk_adjustment_get_page_size (adj));
565
556
 
566
557
        DEBUG ("%p", object);
567
558
 
568
 
        gconf_client_notify_remove (priv->gconf_client,
569
 
                                    priv->notify_system_fonts_id);
570
 
        g_object_unref (priv->gconf_client);
 
559
        g_object_unref (priv->gsettings_chat);
 
560
        g_object_unref (priv->gsettings_desktop);
571
561
 
572
562
        if (priv->last_contact) {
573
563
                g_object_unref (priv->last_contact);
642
632
                      "cursor-visible", FALSE,
643
633
                      NULL);
644
634
 
645
 
        priv->gconf_client = gconf_client_get_default ();
646
 
        gconf_client_add_dir (priv->gconf_client,
647
 
                              "/desktop/gnome/interface",
648
 
                              GCONF_CLIENT_PRELOAD_ONELEVEL,
649
 
                              NULL);
650
 
        priv->notify_system_fonts_id =
651
 
                gconf_client_notify_add (priv->gconf_client,
652
 
                                         "/desktop/gnome/interface/document_font_name",
653
 
                                         chat_text_view_notify_system_font_cb,
654
 
                                         view, NULL, NULL);
 
635
        priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
 
636
 
 
637
        priv->gsettings_desktop = g_settings_new (
 
638
                          EMPATHY_PREFS_DESKTOP_INTERFACE_SCHEMA);
 
639
        g_signal_connect (priv->gsettings_desktop,
 
640
                          "changed::" EMPATHY_PREFS_DESKTOP_INTERFACE_DOCUMENT_FONT_NAME,
 
641
                          G_CALLBACK (chat_text_view_notify_system_font_cb),
 
642
                          view);
655
643
        chat_text_view_system_font_update (view);
656
644
        chat_text_view_create_tags (view);
657
645
 
683
671
 
684
672
        priv = GET_PRIV (view);
685
673
 
686
 
        adj = gtk_text_view_get_vadjustment (GTK_TEXT_VIEW (view));
 
674
        adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view));
687
675
        max_val = gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj);
688
676
 
689
677
        g_return_val_if_fail (priv->scroll_time != NULL, FALSE);
732
720
        EmpathyChatTextView     *text_view = EMPATHY_CHAT_TEXT_VIEW (view);
733
721
        EmpathyChatTextViewPriv *priv = GET_PRIV (text_view);
734
722
        gboolean                 bottom;
735
 
        time_t                   timestamp;
 
723
        gint64                   timestamp;
736
724
 
737
725
        g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view));
738
726
        g_return_if_fail (EMPATHY_IS_MESSAGE (msg));
1327
1315
        return priv->last_contact;
1328
1316
}
1329
1317
 
1330
 
time_t
 
1318
gint64
1331
1319
empathy_chat_text_view_get_last_timestamp (EmpathyChatTextView *view)
1332
1320
{
1333
1321
        EmpathyChatTextViewPriv *priv = GET_PRIV (view);
1418
1406
        GtkTextIter              start_iter;
1419
1407
        GtkTextIter              iter;
1420
1408
        GtkTextMark             *mark;
1421
 
        GSettings               *gsettings_chat;
1422
1409
 
1423
1410
        /* Check if we have to parse smileys */
1424
 
        gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1425
 
        use_smileys = g_settings_get_boolean (gsettings_chat,
 
1411
        use_smileys = g_settings_get_boolean (priv->gsettings_chat,
1426
1412
                        EMPATHY_PREFS_CHAT_SHOW_SMILEYS);
1427
1413
 
1428
1414
        if (use_smileys)
1449
1435
                                           &iter);
1450
1436
 
1451
1437
        gtk_text_buffer_delete_mark (priv->buffer, mark);
1452
 
 
1453
 
        g_object_unref (gsettings_chat);
1454
1438
}
1455
1439
 
1456
1440
void