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

« back to all changes in this revision

Viewing changes to libempathy-gtk/empathy-log-window.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:
31
31
#include <gtk/gtk.h>
32
32
 
33
33
#include <telepathy-glib/account-manager.h>
34
 
#include <telepathy-glib/proxy-subclass.h>
35
 
 
36
34
#include <telepathy-logger/log-manager.h>
37
35
 
38
 
#include <extensions/extensions.h>
39
 
 
40
36
#include <libempathy/empathy-chatroom-manager.h>
41
37
#include <libempathy/empathy-chatroom.h>
42
38
#include <libempathy/empathy-message.h>
65
61
        GtkWidget         *button_previous;
66
62
        GtkWidget         *button_next;
67
63
 
68
 
        GtkWidget         *hbox_chats;
 
64
        GtkWidget         *vbox_chats;
69
65
        GtkWidget         *account_chooser_chats;
70
66
        GtkWidget         *entry_chats;
71
67
        GtkWidget         *calendar_chats;
100
96
                                                            EmpathyLogWindow *window);
101
97
static void     log_window_button_previous_clicked_cb      (GtkWidget        *widget,
102
98
                                                            EmpathyLogWindow *window);
 
99
static void     log_window_button_close_clicked_cb         (GtkWidget        *widget,
 
100
                                                            EmpathyLogWindow *window);
103
101
static void     log_window_chats_changed_cb                (GtkTreeSelection *selection,
104
102
                                                            EmpathyLogWindow *window);
105
103
static void     log_window_chats_populate                  (EmpathyLogWindow *window);
120
118
                                                            EmpathyLogWindow *window);
121
119
static void     log_window_entry_chats_activate_cb         (GtkWidget        *entry,
122
120
                                                            EmpathyLogWindow *window);
123
 
static void     log_window_delete_menu_clicked_cb          (GtkMenuItem      *menuitem,
124
 
                                                            EmpathyLogWindow *window);
125
 
 
126
 
static void
127
 
empathy_account_chooser_filter_has_logs (TpAccount *account,
128
 
                                         EmpathyAccountChooserFilterResultCallback callback,
129
 
                                         gpointer callback_data,
130
 
                                         gpointer user_data);
131
121
 
132
122
enum {
133
123
        COL_FIND_ACCOUNT_ICON,
174
164
        account_num = g_list_length (accounts);
175
165
        g_list_free (accounts);
176
166
 
177
 
        gtk_widget_show_all (window->hbox_chats);
 
167
        if (account_num > 1) {
 
168
                gtk_widget_show (window->vbox_chats);
 
169
                gtk_widget_show (window->account_chooser_chats);
 
170
        } else {
 
171
                gtk_widget_hide (window->vbox_chats);
 
172
                gtk_widget_hide (window->account_chooser_chats);
 
173
        }
178
174
}
179
175
 
180
176
static void
219
215
                        gboolean     is_chatroom,
220
216
                        GtkWindow   *parent)
221
217
{
222
 
        EmpathyAccountChooser   *account_chooser;
223
218
        TpAccountManager        *account_manager;
224
219
        GtkBuilder             *gui;
225
220
        gchar                  *filename;
226
221
        EmpathyLogWindow       *window;
227
222
        EmpathyThemeManager    *theme_mgr;
228
 
        GtkWidget *menu_delete;
229
223
 
230
224
        if (log_window != NULL) {
231
225
                gtk_window_present (GTK_WINDOW (log_window->window));
247
241
                                        "libempathy-gtk");
248
242
        gui = empathy_builder_get_file (filename,
249
243
                                       "log_window", &window->window,
250
 
                                       "menu_delete", &menu_delete,
251
244
                                       "notebook", &window->notebook,
252
245
                                       "entry_find", &window->entry_find,
253
246
                                       "button_find", &window->button_find,
257
250
                                       "button_next", &window->button_next,
258
251
                                       "entry_chats", &window->entry_chats,
259
252
                                       "calendar_chats", &window->calendar_chats,
260
 
                                       "hbox_chats", &window->hbox_chats,
 
253
                                       "vbox_chats", &window->vbox_chats,
261
254
                                       "treeview_chats", &window->treeview_chats,
262
255
                                       "scrolledwindow_chats", &window->scrolledwindow_chats,
263
256
                                       NULL);
269
262
                              "entry_find", "activate", log_window_entry_find_activate_cb,
270
263
                              "button_previous", "clicked", log_window_button_previous_clicked_cb,
271
264
                              "button_next", "clicked", log_window_button_next_clicked_cb,
 
265
                              "button_close", "clicked", log_window_button_close_clicked_cb,
 
266
                              "button_close2", "clicked", log_window_button_close_clicked_cb,
272
267
                              "button_find", "clicked", log_window_button_find_clicked_cb,
273
268
                              "entry_chats", "changed", log_window_entry_chats_changed_cb,
274
269
                              "entry_chats", "activate", log_window_entry_chats_activate_cb,
275
 
                              "menu_delete", "activate", log_window_delete_menu_clicked_cb,
276
270
                              NULL);
277
271
 
278
272
        g_object_unref (gui);
304
298
 
305
299
        /* Account chooser for chats */
306
300
        window->account_chooser_chats = empathy_account_chooser_new ();
307
 
        account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats);
308
 
        empathy_account_chooser_set_filter (account_chooser, empathy_account_chooser_filter_has_logs, NULL);
309
301
 
310
 
        gtk_box_pack_start (GTK_BOX (window->hbox_chats),
 
302
        gtk_box_pack_start (GTK_BOX (window->vbox_chats),
311
303
                            window->account_chooser_chats,
312
304
                            FALSE, TRUE, 0);
313
305
 
583
575
{
584
576
        GtkTreeView        *view;
585
577
        GtkTreeModel       *model;
586
 
        GtkTreeSelection   *selection;
587
578
        GtkListStore       *store;
588
579
 
589
580
        view = GTK_TREE_VIEW (window->treeview_find);
590
581
        model = gtk_tree_view_get_model (view);
591
 
        selection = gtk_tree_view_get_selection (view);
592
582
        store = GTK_LIST_STORE (model);
593
583
 
594
584
        empathy_chat_view_clear (window->chatview_find);
766
756
        }
767
757
}
768
758
 
 
759
static void
 
760
log_window_button_close_clicked_cb (GtkWidget *widget,
 
761
                                    EmpathyLogWindow *window)
 
762
{
 
763
        gtk_widget_destroy (window->window);
 
764
}
 
765
 
769
766
/*
770
767
 * Chats Code
771
768
 */
786
783
        log_window_chats_get_messages (window, NULL);
787
784
}
788
785
 
789
 
typedef struct
790
 
{
791
 
        EmpathyLogWindow *window;
792
 
        TpAccount *account;
793
 
} GetEntitiesCtx;
794
 
 
795
 
static GetEntitiesCtx *
796
 
get_entities_ctx_new (EmpathyLogWindow *window,
797
 
                      TpAccount *account)
798
 
{
799
 
        GetEntitiesCtx *ctx = g_slice_new (GetEntitiesCtx);
800
 
 
801
 
        /* EmpathyLogWindow isn't a proper GObject so we can't ref it */
802
 
        ctx->window = window;
803
 
        ctx->account = g_object_ref (account);
804
 
        return ctx;
805
 
}
806
 
 
807
 
static void
808
 
get_entities_ctx_free (GetEntitiesCtx *ctx)
809
 
{
810
 
        g_object_unref (ctx->account);
811
 
        g_slice_free (GetEntitiesCtx, ctx);
812
 
}
813
 
 
814
786
static void
815
787
log_manager_got_entities_cb (GObject *manager,
816
788
                             GAsyncResult *result,
817
789
                             gpointer user_data)
818
790
{
819
 
        GetEntitiesCtx        *ctx = user_data;
820
791
        GList                 *entities;
821
792
        GList                 *l;
822
793
        GtkTreeView           *view;
826
797
        GtkTreeIter            iter;
827
798
        GError                *error = NULL;
828
799
        gboolean               select_account = FALSE;
829
 
 
830
 
        view = GTK_TREE_VIEW (ctx->window->treeview_chats);
 
800
        TpAccount             *account = user_data;
831
801
 
832
802
        if (log_window == NULL)
833
803
                goto out;
839
809
                        goto out;
840
810
        }
841
811
 
842
 
        view = GTK_TREE_VIEW (ctx->window->treeview_chats);
 
812
        view = GTK_TREE_VIEW (log_window->treeview_chats);
843
813
        model = gtk_tree_view_get_model (view);
844
814
        selection = gtk_tree_view_get_selection (view);
845
815
        store = GTK_LIST_STORE (model);
853
823
                gtk_list_store_set (store, &iter,
854
824
                                COL_CHAT_ICON, "empathy-available", /* FIXME */
855
825
                                COL_CHAT_NAME, tpl_entity_get_alias (entity),
856
 
                                COL_CHAT_ACCOUNT, ctx->account,
 
826
                                COL_CHAT_ACCOUNT, account,
857
827
                                COL_CHAT_TARGET, entity,
858
828
                                -1);
859
829
 
860
 
                if (ctx->window->selected_account != NULL &&
861
 
                    !tp_strdiff (tp_proxy_get_object_path (ctx->account),
862
 
                    tp_proxy_get_object_path (ctx->window->selected_account)))
 
830
                if (log_window->selected_account != NULL &&
 
831
                    !tp_strdiff (tp_proxy_get_object_path (account),
 
832
                    tp_proxy_get_object_path (log_window->selected_account)))
863
833
                        select_account = TRUE;
864
834
 
865
835
                /* FIXME: Update COL_CHAT_ICON/NAME */
872
842
        /* Unblock signals */
873
843
        g_signal_handlers_unblock_by_func (selection,
874
844
                        log_window_chats_changed_cb,
875
 
                        ctx->window);
 
845
                        log_window);
876
846
 
877
847
        /* We display the selected account if we populate the model with chats from
878
848
         * this account. */
879
849
        if (select_account)
880
 
                log_window_chats_set_selected (ctx->window);
 
850
                log_window_chats_set_selected (log_window);
881
851
 
882
852
out:
883
 
        get_entities_ctx_free (ctx);
 
853
        g_object_unref (account);
884
854
}
885
855
 
886
856
static void
893
863
        GtkTreeModel         *model;
894
864
        GtkTreeSelection     *selection;
895
865
        GtkListStore         *store;
896
 
        GetEntitiesCtx       *ctx;
897
866
 
898
867
        account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats);
899
868
        account = empathy_account_chooser_dup_account (account_chooser);
915
884
 
916
885
        gtk_list_store_clear (store);
917
886
 
918
 
        ctx = get_entities_ctx_new (window, account);
919
 
 
 
887
        /* Pass the account reference to the callback */
920
888
        tpl_log_manager_get_entities_async (window->log_manager, account,
921
 
                        log_manager_got_entities_cb, ctx);
 
889
                        log_manager_got_entities_cb, account);
922
890
}
923
891
 
924
892
static void
1420
1388
                                            FALSE);
1421
1389
        }
1422
1390
}
1423
 
 
1424
 
typedef struct {
1425
 
        EmpathyAccountChooserFilterResultCallback callback;
1426
 
        gpointer                                  user_data;
1427
 
} FilterCallbackData;
1428
 
 
1429
 
static void
1430
 
got_entities (GObject      *manager,
1431
 
              GAsyncResult *result,
1432
 
              gpointer      user_data)
1433
 
{
1434
 
        FilterCallbackData *data = user_data;
1435
 
        GList *entities;
1436
 
        GError *error;
1437
 
 
1438
 
        if (!tpl_log_manager_get_entities_finish (TPL_LOG_MANAGER (manager), result, &entities, &error)) {
1439
 
                DEBUG ("Could not get entities: %s", error->message);
1440
 
                g_error_free (error);
1441
 
                data->callback (FALSE, data->user_data);
1442
 
        } else {
1443
 
                data->callback (entities != NULL, data->user_data);
1444
 
 
1445
 
                g_list_free_full (entities, g_object_unref);
1446
 
        }
1447
 
 
1448
 
        g_slice_free (FilterCallbackData, data);
1449
 
}
1450
 
 
1451
 
static void
1452
 
empathy_account_chooser_filter_has_logs (TpAccount *account,
1453
 
                                         EmpathyAccountChooserFilterResultCallback callback,
1454
 
                                         gpointer callback_data,
1455
 
                                         gpointer user_data)
1456
 
{
1457
 
        TplLogManager *manager = tpl_log_manager_dup_singleton ();
1458
 
        FilterCallbackData *cb_data = g_slice_new0 (FilterCallbackData);
1459
 
 
1460
 
        cb_data->callback = callback;
1461
 
        cb_data->user_data = callback_data;
1462
 
 
1463
 
        tpl_log_manager_get_entities_async (manager, account, got_entities, cb_data);
1464
 
 
1465
 
        g_object_unref (manager);
1466
 
}
1467
 
 
1468
 
static void
1469
 
log_window_logger_clear_account_cb (TpProxy *proxy,
1470
 
                                    const GError *error,
1471
 
                                    gpointer user_data,
1472
 
                                    GObject *weak_object)
1473
 
{
1474
 
        EmpathyLogWindow *window = user_data;
1475
 
 
1476
 
        if (error != NULL)
1477
 
                g_warning ("Error when clearing logs: %s", error->message);
1478
 
 
1479
 
        /* Refresh the log viewer so the logs are cleared if the account
1480
 
         * has been deleted */
1481
 
        empathy_chat_view_clear (window->chatview_chats);
1482
 
        log_window_chats_populate (window);
1483
 
 
1484
 
        /* Re-filter the account chooser so the accounts without logs get greyed out */
1485
 
        empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats),
1486
 
                                            empathy_account_chooser_filter_has_logs, NULL);
1487
 
}
1488
 
 
1489
 
static void
1490
 
log_window_clear_logs_chooser_select_account (EmpathyAccountChooser *chooser,
1491
 
                                              EmpathyLogWindow *window)
1492
 
{
1493
 
        empathy_account_chooser_set_account (chooser,
1494
 
                empathy_account_chooser_get_account (EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats)));
1495
 
}
1496
 
 
1497
 
static void
1498
 
log_window_delete_menu_clicked_cb (GtkMenuItem      *menuitem,
1499
 
                                   EmpathyLogWindow *window)
1500
 
{
1501
 
        GtkWidget *dialog, *content_area, *hbox, *label;
1502
 
        EmpathyAccountChooser *account_chooser;
1503
 
        gint response_id;
1504
 
        TpDBusDaemon *bus;
1505
 
        TpProxy *logger;
1506
 
        GError *error = NULL;
1507
 
 
1508
 
        account_chooser = (EmpathyAccountChooser *) empathy_account_chooser_new ();
1509
 
        empathy_account_chooser_set_has_all_option (account_chooser, TRUE);
1510
 
        empathy_account_chooser_set_filter (account_chooser, empathy_account_chooser_filter_has_logs, NULL);
1511
 
 
1512
 
        /* Select the same account as in the history window */
1513
 
        if (empathy_account_chooser_is_ready (account_chooser))
1514
 
                log_window_clear_logs_chooser_select_account (account_chooser, window);
1515
 
        else
1516
 
                g_signal_connect (account_chooser, "ready",
1517
 
                                  G_CALLBACK (log_window_clear_logs_chooser_select_account), window);
1518
 
 
1519
 
        dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (window->window),
1520
 
                GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
1521
 
                GTK_BUTTONS_NONE,
1522
 
                _("Are you sure you want to delete all logs of previous conversations?"));
1523
 
 
1524
 
        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
1525
 
                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1526
 
                _("Clear All"), GTK_RESPONSE_APPLY,
1527
 
                NULL);
1528
 
 
1529
 
        content_area = gtk_message_dialog_get_message_area (
1530
 
                GTK_MESSAGE_DIALOG (dialog));
1531
 
 
1532
 
        hbox = gtk_hbox_new (FALSE, 6);
1533
 
        label = gtk_label_new (_("Delete from:"));
1534
 
        gtk_box_pack_start (GTK_BOX (hbox), label,
1535
 
                FALSE, FALSE, 0);
1536
 
        gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (account_chooser),
1537
 
                FALSE, FALSE, 0);
1538
 
        gtk_box_pack_start (GTK_BOX (content_area), hbox,
1539
 
                FALSE, FALSE, 0);
1540
 
 
1541
 
        gtk_widget_show_all (hbox);
1542
 
 
1543
 
        response_id = gtk_dialog_run (GTK_DIALOG (dialog));
1544
 
 
1545
 
        if (response_id != GTK_RESPONSE_APPLY)
1546
 
                goto out;
1547
 
 
1548
 
        bus = tp_dbus_daemon_dup (&error);
1549
 
        if (error != NULL) {
1550
 
                g_warning ("Could not delete logs: %s", error->message);
1551
 
                g_error_free (error);
1552
 
                goto out;
1553
 
        }
1554
 
 
1555
 
        logger = g_object_new (TP_TYPE_PROXY,
1556
 
                               "bus-name", "org.freedesktop.Telepathy.Logger",
1557
 
                               "object-path", "/org/freedesktop/Telepathy/Logger",
1558
 
                               "dbus-daemon", bus,
1559
 
                               NULL);
1560
 
        g_object_unref (bus);
1561
 
 
1562
 
        tp_proxy_add_interface_by_id (logger, EMP_IFACE_QUARK_LOGGER);
1563
 
 
1564
 
        if (empathy_account_chooser_has_all_selected (account_chooser)) {
1565
 
                DEBUG ("Deleting logs for all the accounts");
1566
 
 
1567
 
                emp_cli_logger_call_clear (logger, -1,
1568
 
                                           log_window_logger_clear_account_cb,
1569
 
                                           window, NULL, G_OBJECT (window->window));
1570
 
        } else {
1571
 
                TpAccount *account = empathy_account_chooser_get_account (account_chooser);
1572
 
 
1573
 
                DEBUG ("Deleting logs for %s", tp_proxy_get_object_path (account));
1574
 
 
1575
 
                emp_cli_logger_call_clear_account (logger, -1,
1576
 
                                                   tp_proxy_get_object_path (account),
1577
 
                                                   log_window_logger_clear_account_cb,
1578
 
                                                   window, NULL, G_OBJECT (window->window));
1579
 
        }
1580
 
 
1581
 
        g_object_unref (logger);
1582
 
 out:
1583
 
        gtk_widget_destroy (dialog);
1584
 
}