aboutsummaryrefslogtreecommitdiffstats
path: root/mail/e-mail-notebook-view.c
blob: cf957c3fe0c9f9b359b432992d712b3dccaca8c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Authors:
 *      Srinivasa Ragavan <sragavan@gnome.org>
 *
 * Copyright (C) 2010 Intel corporation. (www.intel.com)
 *
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <glib.h>
#include <glib/gi18n.h>

#include "mail/e-mail-reader.h"
#include "mail/message-list.h"
#include "mail/em-folder-tree.h"
#include "e-mail-notebook-view.h"
#include "e-mail-folder-pane.h"
#include "e-mail-message-pane.h"

#include <shell/e-shell-window-actions.h>

#if HAVE_CLUTTER
#include <clutter/clutter.h>
#include <mx/mx.h>
#include <clutter-gtk/clutter-gtk.h>

#include "e-mail-tab-picker.h"
#endif

#define E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_MAIL_NOTEBOOK_VIEW, EMailNotebookViewPrivate))

struct _EMailNotebookViewPrivate {
    GtkNotebook *book;
    EMailView *current_view;
    GHashTable *views;
    gboolean inited;

#if HAVE_CLUTTER
    EMailTabPicker *tab_picker;
    GtkWidget *embed;
    ClutterActor *actor;
    ClutterActor *stage;
#endif
};

enum {
    PROP_0,
    PROP_FORWARD_STYLE,
    PROP_GROUP_BY_THREADS,
    PROP_REPLY_STYLE
};

#define E_SHELL_WINDOW_ACTION_GROUP_MAIL(window) \
    E_SHELL_WINDOW_ACTION_GROUP ((window), "mail")

/* Forward Declarations */
static void e_mail_notebook_view_reader_init (EMailReaderInterface *interface);

G_DEFINE_TYPE_WITH_CODE (
    EMailNotebookView, e_mail_notebook_view, E_TYPE_MAIL_VIEW,
    G_IMPLEMENT_INTERFACE (
        E_TYPE_MAIL_READER, e_mail_notebook_view_reader_init))

#if HAVE_CLUTTER
static void
mnv_set_current_tab (EMailNotebookView *view,
                     gint page)
{
    ClutterAnimation *animation;

    clutter_actor_set_opacity (view->priv->actor, 0);
    gtk_notebook_set_current_page (view->priv->book, page);

    animation = clutter_actor_animate (
        (ClutterActor *)view->priv->actor,
        CLUTTER_EASE_IN_SINE, 500, "opacity", 255, NULL);
}
#endif

static gint
emnv_get_page_num (EMailNotebookView *view,
                   GtkWidget *widget)
{
    EMailNotebookViewPrivate *priv = view->priv;
    gint i, n;

    n = gtk_notebook_get_n_pages (priv->book);

    for (i=0; i<n; i++) {
        GtkWidget *curr = gtk_notebook_get_nth_page (priv->book, i);
        if (curr == widget)
            return i;
    }

    return 0;
}

static void
mnv_page_changed (GtkNotebook *book,
                  GtkWidget *page,
                  guint page_num,
                  EMailView *view)
{
    EMailNotebookViewPrivate *priv;
    EShellView *shell_view;
    EShellSidebar *shell_sidebar;
    EMFolderTree *folder_tree;
    EMailView *mview;
    const gchar *uri;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    shell_view = e_mail_view_get_shell_view (view);
    shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);

    page = gtk_notebook_get_nth_page (book, page_num);
    uri = e_mail_reader_get_folder_uri (E_MAIL_READER (page));
    mview = E_MAIL_VIEW (page);

    g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);

    if (uri && E_IS_MAIL_FOLDER_PANE (mview))
        em_folder_tree_set_selected (folder_tree, uri, FALSE);

    if (mview != priv->current_view) {
        e_mail_view_set_previous_view (mview, priv->current_view);
        priv->current_view = mview;
    }

    /* For EMailReader related changes to EShellView */
    g_signal_emit_by_name (view, "changed");
    g_signal_emit_by_name (view, "folder-loaded");

    /* For EMailShellContent related changes */
    g_signal_emit_by_name (view, "view-changed");

    g_object_unref (folder_tree);
}

#if HAVE_CLUTTER
static void
fix_tab_picker_width (GtkWidget *widget,
                      GtkAllocation *allocation,
                      ClutterActor *actor)
{
    ClutterActor *stage = g_object_get_data ((GObject *)actor, "stage");

    clutter_actor_set_size (actor, allocation->width-1, -1);
    clutter_actor_set_size (stage, allocation->width-1, -1);
}

static void
fix_height_cb (ClutterActor *actor,
               GParamSpec *pspec,
               ClutterActor *table)
{
    GtkWidget *embed = (GtkWidget *)g_object_get_data ((GObject *)actor, "embed");
    ClutterActor *stage = g_object_get_data ((GObject *)actor, "stage");

    clutter_actor_set_height (stage, clutter_actor_get_height (actor));
    gtk_widget_set_size_request (embed, -1, (gint) clutter_actor_get_height (actor));
}

static void
chooser_clicked_cb (EMailTabPicker *picker,
                    EMailNotebookView *view)
{
    EMailNotebookViewPrivate *priv;

    gboolean preview_mode;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);
    preview_mode = !e_mail_tab_picker_get_preview_mode (priv->tab_picker);

    e_mail_tab_picker_set_preview_mode (priv->tab_picker , preview_mode);
}

static void
tab_picker_preview_mode_notify (EMailTabPicker *picker,
                                GParamSpec *pspec,
                                EMailNotebookView *view)
{
    GList *tabs, *t;
    gboolean preview_mode = e_mail_tab_picker_get_preview_mode (picker);

    clutter_actor_set_name (
        CLUTTER_ACTOR (picker),
        preview_mode ? "tab-picker-preview" : NULL);

    tabs = e_mail_tab_picker_get_tabs (picker);
    for (t = tabs; t; t = t->next) {
        EMailTab *tab;
        ClutterActor *preview;
        tab = E_MAIL_TAB (t->data);

        preview = e_mail_tab_get_preview_actor (tab);

        if (!preview)
            continue;

        if (preview_mode) {
            /* Show all pages so that the preview clones work correctly */
            clutter_actor_set_opacity (preview, 255);
            clutter_actor_show (preview);
        } else {
            clutter_actor_hide (preview);
        }
    }
    g_list_free (tabs);
}

static void
mnv_tab_anim_frame_cb (ClutterTimeline *timeline,
                               gint             frame_num,
                               EMailTab          *tab)
{
    if (!clutter_actor_get_parent (CLUTTER_ACTOR (tab))) {
        clutter_timeline_stop (timeline);
        g_object_unref (timeline);
        g_object_unref (tab);

        return;
    }

    e_mail_tab_set_width (tab, 200 * clutter_timeline_get_progress (timeline));
}

static void
mnv_tab_anim_complete_cb (ClutterTimeline *timeline,
                                  EMailTab          *tab)
{
    e_mail_tab_set_width (tab, 200);
    g_object_unref (tab);
    g_object_unref (timeline);
}

struct _tab_data {
    gboolean select;
    EMailNotebookView *view;
    EMailTab *tab;
};

static void
mnv_tab_closed_cb (ClutterTimeline *timeline,
        struct _tab_data *data)
{
    EMailView *page = g_object_get_data ((GObject *)data->tab, "page");
    const gchar *folder_uri = e_mail_reader_get_folder_uri (E_MAIL_READER (page));
    EMailView *prev;
    gint num;

    if (E_IS_MAIL_FOLDER_PANE (page))
        g_hash_table_remove (data->view->priv->views, folder_uri);
    prev = e_mail_view_get_previous_view (page);
    if (prev) {
        num = emnv_get_page_num (data->view, (GtkWidget *)prev);
        mnv_set_current_tab (data->view, num);
        e_mail_tab_picker_set_current_tab (data->view->priv->tab_picker, num);
    }

    e_mail_tab_picker_remove_tab (data->view->priv->tab_picker, data->tab);
    gtk_notebook_remove_page (data->view->priv->book,
            gtk_notebook_page_num (data->view->priv->book, (GtkWidget *)page));

}

static void
mnv_tab_closed (EMailTab *tab, EMailNotebookView *view)
{
    EMailNotebookViewPrivate *priv = view->priv;
    gint page, cur;
    gboolean select = FALSE;
    ClutterTimeline *timeline;
    struct _tab_data *data = g_new0 (struct _tab_data, 1);

    if (e_mail_tab_picker_get_n_tabs (priv->tab_picker) == 1)
        return;

    page = e_mail_tab_picker_get_tab_no (priv->tab_picker,
                         tab);
    cur = e_mail_tab_picker_get_current_tab (priv->tab_picker);

    if (cur == page)
        select = TRUE;

    data->select  = select;
    data->tab = tab;
    data->view = view;

    clutter_actor_set_reactive (CLUTTER_ACTOR (tab), FALSE);
    timeline = clutter_timeline_new (150);
    clutter_timeline_set_direction (timeline, CLUTTER_TIMELINE_BACKWARD);
    g_signal_connect (
        timeline, "new-frame",
        G_CALLBACK (mnv_tab_anim_frame_cb), tab);
    g_signal_connect (
        timeline, "completed",
        G_CALLBACK (mnv_tab_closed_cb), data);
    clutter_timeline_start (timeline);
}

static void
tab_activated_cb (EMailTabPicker *picker,
          EMailTab   *tab,
          EMailNotebookView *view)
{
    EMailView *page = g_object_get_data ((GObject *)tab, "page");
    gint num = emnv_get_page_num (view, (GtkWidget *)page);

    mnv_set_current_tab (view, num);
}
#endif

static void
tab_remove_gtk_cb (GtkWidget *button,
           EMailNotebookView *view)
{
    EMailView *page = g_object_get_data ((GObject *)button, "page");
    const gchar *folder_uri = e_mail_reader_get_folder_uri (E_MAIL_READER (page));
    EMailView *prev;
    gint num;

    if (gtk_notebook_get_n_pages (view->priv->book) == 1)
        return;

    if (E_IS_MAIL_FOLDER_PANE (page))
        g_hash_table_remove (view->priv->views, folder_uri);

    prev = e_mail_view_get_previous_view (page);
    if (prev) {
        num = emnv_get_page_num (view, (GtkWidget *)prev);
        gtk_notebook_set_current_page (view->priv->book, num);
    }
    gtk_notebook_remove_page (view->priv->book,
            gtk_notebook_page_num (view->priv->book, (GtkWidget *)page));

}

static GtkWidget *
create_tab_label (EMailNotebookView *view,
          EMailView *page,
          const gchar *str)
{
    GtkWidget *container, *widget;

    widget = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (widget);
    container = widget;

    widget = gtk_label_new (str);
    gtk_widget_show (widget);
    gtk_box_pack_start (GTK_BOX (container), widget, TRUE, FALSE, 0);

    widget = gtk_button_new ();
    gtk_button_set_relief (GTK_BUTTON (widget), GTK_RELIEF_NONE);
    gtk_button_set_image (
        GTK_BUTTON (widget), gtk_image_new_from_stock (
        "gtk-close", GTK_ICON_SIZE_MENU));
    gtk_widget_show_all (widget);
    gtk_box_pack_end (GTK_BOX (container), widget, FALSE, FALSE, 0);
    g_object_set_data ((GObject *)widget, "page", page);
    g_object_set_data ((GObject *)page, "close-button", widget);

    g_signal_connect (
        widget, "clicked",
        G_CALLBACK (tab_remove_gtk_cb), view);

    return container;
}

#if HAVE_CLUTTER

static ClutterActor *
create_gtk_actor (GtkWidget *vbox)
{
  GtkWidget       *bin;
  ClutterActor    *gtk_actor;

  gtk_actor = gtk_clutter_actor_new ();
  bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (gtk_actor));

  gtk_container_add (GTK_CONTAINER (bin), vbox);

  gtk_widget_show (bin);
  gtk_widget_show (vbox);
  return gtk_actor;
}

static void
fix_clutter_embed_width (GtkWidget *widget,
                         GtkAllocation *allocation,
                         ClutterActor *actor)
{
    GtkWidget *embed = (GtkWidget *)g_object_get_data ((GObject *)actor, "embed");
    GtkAllocation galoc;

    gtk_widget_get_allocation (embed, &galoc);
    clutter_actor_set_size (actor, allocation->width-1, galoc.height);
}

static GtkWidget *
create_under_clutter (GtkWidget *widget, GtkWidget *paned)
{
    GtkWidget *embed;
    ClutterActor *stage, *actor;

    embed = gtk_clutter_embed_new ();
    gtk_widget_show (embed);

    actor = create_gtk_actor (widget);
    clutter_actor_show (actor);
    stage = gtk_clutter_embed_get_stage ((GtkClutterEmbed *)embed);
    clutter_container_add_actor ((ClutterContainer *)stage, actor);

    g_object_set_data ((GObject *)actor, "embed", embed);
    g_object_set_data ((GObject *)actor, "stage", stage);
    g_object_set_data ((GObject *)actor, "widget", widget);
    g_object_set_data ((GObject *)widget, "actor", actor);
    g_object_set_data ((GObject *)embed, "actor", actor);

    g_signal_connect (
        paned, "size-allocate",
        G_CALLBACK (fix_clutter_embed_width), actor);
    clutter_actor_show (stage);

    return embed;
}

#endif

static void
mail_notebook_view_constructed (GObject *object)
{
    EMailNotebookViewPrivate *priv;
    EShellView *shell_view;
    GtkWidget *container;
    GtkWidget *widget;
#if HAVE_CLUTTER
    EMailTab *tab;
    ClutterActor *stage, *clone;
    ClutterTimeline *timeline;
#endif

    priv = E_MAIL_NOTEBOOK_VIEW (object)->priv;

    container = GTK_WIDGET (object);

#if HAVE_CLUTTER
    widget = gtk_clutter_embed_new ();
    gtk_widget_show (widget);
    gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);

    stage = gtk_clutter_embed_get_stage ((GtkClutterEmbed *)widget);
    clutter_actor_show (stage);
    clutter_actor_set_reactive (stage, TRUE);

    priv->tab_picker = (EMailTabPicker *)e_mail_tab_picker_new ();
    clutter_actor_show ((ClutterActor *)priv->tab_picker);
    g_signal_connect (
        priv->tab_picker, "tab-activated",
        G_CALLBACK (tab_activated_cb), object);
    g_signal_connect (
        priv->tab_picker, "chooser-clicked",
        G_CALLBACK (chooser_clicked_cb), object);
    g_signal_connect (
        priv->tab_picker, "notify::preview-mode",
        G_CALLBACK (tab_picker_preview_mode_notify), object);
    g_signal_connect (
        priv->tab_picker, "notify::height",
        G_CALLBACK (fix_height_cb), widget);

    clutter_container_add_actor (
        (ClutterContainer *) stage,
        (ClutterActor *) priv->tab_picker);

    e_mail_tab_picker_enable_drop (priv->tab_picker, TRUE);

    g_object_set_data ((GObject *)priv->tab_picker, "embed", widget);
    g_object_set_data ((GObject *)priv->tab_picker, "stage", stage);

    g_signal_connect (
        object, "size-allocate",
        G_CALLBACK (fix_tab_picker_width), priv->tab_picker);

    clutter_actor_set_height (
        stage, clutter_actor_get_height (
        (ClutterActor *) priv->tab_picker));
    gtk_widget_set_size_request (
        widget, -1, (gint) clutter_actor_get_height (
        (ClutterActor *) priv->tab_picker));

    tab = (EMailTab *) e_mail_tab_new_full ("", NULL, 1);
    clone = e_mail_tab_new_full ("", NULL, 200);

    e_mail_tab_set_can_close ((EMailTab *)clone, FALSE);
    clutter_actor_set_reactive (clone, FALSE);
    clutter_actor_show (clone);

    e_mail_tab_set_preview_actor ((EMailTab *)tab, clone);
    e_mail_tab_set_can_close (tab, TRUE);

    e_mail_tab_picker_add_tab (priv->tab_picker, tab, -1);
    clutter_actor_show ((ClutterActor *)tab);
    e_mail_tab_picker_set_current_tab (priv->tab_picker, 0);
    e_mail_tab_enable_drag (tab, TRUE);

    g_object_ref (tab);
    timeline = clutter_timeline_new (150);
    g_signal_connect (
        timeline, "new-frame",
        G_CALLBACK (mnv_tab_anim_frame_cb), tab);
    g_signal_connect (
        timeline, "completed",
        G_CALLBACK (mnv_tab_anim_complete_cb), tab);
    clutter_timeline_start (timeline);
#endif

    widget = gtk_notebook_new ();
    priv->book = (GtkNotebook *)widget;
    gtk_widget_show (widget);
#if HAVE_CLUTTER
    priv->embed = create_under_clutter (widget, container);
    gtk_box_pack_start (GTK_BOX (container), priv->embed, TRUE, TRUE, 0);
    priv->actor = g_object_get_data((GObject *)priv->embed, "actor");
    priv->stage = g_object_get_data((GObject *)priv->actor, "stage");
#else
    gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
#endif

#if HAVE_CLUTTER
    gtk_notebook_set_show_tabs ((GtkNotebook *)widget, FALSE);
#else
    gtk_notebook_set_scrollable ((GtkNotebook *)widget, TRUE);
#endif

    gtk_notebook_set_show_border ((GtkNotebook *)widget, FALSE);

    shell_view = e_mail_view_get_shell_view (E_MAIL_VIEW (object));
    priv->current_view = e_mail_folder_pane_new (shell_view);
    e_mail_view_set_preview_visible (priv->current_view, FALSE);
    gtk_widget_show (GTK_WIDGET (priv->current_view));

    gtk_notebook_append_page (
        priv->book, GTK_WIDGET (priv->current_view),
        create_tab_label (E_MAIL_NOTEBOOK_VIEW (object),
        priv->current_view, _("Please select a folder")));

    g_signal_connect (
        priv->book, "switch-page",
        G_CALLBACK (mnv_page_changed), object);

    /* Chain up to parent's constructed() method. */
    G_OBJECT_CLASS (e_mail_notebook_view_parent_class)->constructed (object);
}

static void
mail_notebook_view_set_property (GObject *object,
                                 guint property_id,
                                 const GValue *value,
                                 GParamSpec *pspec)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (object);

    switch (property_id) {
        case PROP_FORWARD_STYLE:
            e_mail_reader_set_forward_style (
                E_MAIL_READER (priv->current_view),
                g_value_get_enum (value));
            return;

        case PROP_GROUP_BY_THREADS:
            e_mail_reader_set_group_by_threads (
                E_MAIL_READER (priv->current_view),
                g_value_get_boolean (value));
            return;

        case PROP_REPLY_STYLE:
            e_mail_reader_set_reply_style (
                E_MAIL_READER (priv->current_view),
                g_value_get_enum (value));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
mail_notebook_view_get_property (GObject *object,
                                 guint property_id,
                                 GValue *value,
                                 GParamSpec *pspec)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (object);

    switch (property_id) {
        case PROP_FORWARD_STYLE:
            g_value_set_enum (
                value,
                e_mail_reader_get_forward_style (
                E_MAIL_READER (priv->current_view)));
            return;

        case PROP_GROUP_BY_THREADS:
            g_value_set_boolean (
                value,
                e_mail_reader_get_group_by_threads (
                E_MAIL_READER (priv->current_view)));
            return;

        case PROP_REPLY_STYLE:
            g_value_set_enum (
                value,
                e_mail_reader_get_reply_style (
                E_MAIL_READER (priv->current_view)));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
mail_notebook_view_set_search_strings (EMailView *view,
                                       GSList *search_strings)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    e_mail_view_set_search_strings (priv->current_view, search_strings);
}

static GalViewInstance *
mail_notebook_view_get_view_instance (EMailView *view)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    if (priv->current_view == NULL)
        return NULL;

    return e_mail_view_get_view_instance (priv->current_view);
}

static void
mail_notebook_view_update_view_instance (EMailView *view)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    if (priv->current_view == NULL)
        return;

    e_mail_view_update_view_instance (priv->current_view);
}

static void
mail_notebook_view_set_orientation (EMailView *view,
                                    GtkOrientation orientation)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    if (priv->current_view == NULL)
        return;

    e_mail_view_set_orientation (priv->current_view, orientation);
}

static GtkOrientation
mail_notebook_view_get_orientation (EMailView *view)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    if (priv->current_view == NULL)
        return GTK_ORIENTATION_VERTICAL;

    return e_mail_view_get_orientation (priv->current_view);
}

static gboolean
mail_notebook_view_get_show_deleted (EMailView *view)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    if (priv->current_view == NULL)
        return FALSE;

    return e_mail_view_get_show_deleted (priv->current_view);
}

static void
mail_notebook_view_set_show_deleted (EMailView *view,
                                     gboolean show_deleted)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    if (priv->current_view == NULL)
        return;

    e_mail_view_set_show_deleted (priv->current_view, show_deleted);
}

static gboolean
mail_notebook_view_get_preview_visible (EMailView *view)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    if (priv->current_view == NULL)
        return FALSE;

    return e_mail_view_get_preview_visible (priv->current_view);
}

static void
mail_notebook_view_set_preview_visible (EMailView *view,
                                        gboolean preview_visible)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    if (priv->current_view == NULL)
        return;

    e_mail_view_set_preview_visible (priv->current_view, preview_visible);
}

static GtkActionGroup *
mail_notebook_view_get_action_group (EMailReader *reader)
{
    EMailView *view;
    EShellWindow *shell_window;
    EShellView *shell_view;

    view = E_MAIL_VIEW (reader);
    shell_view = e_mail_view_get_shell_view (view);
    shell_window = e_shell_view_get_shell_window (shell_view);

    return E_SHELL_WINDOW_ACTION_GROUP_MAIL (shell_window);
}

static EAlertSink *
mail_notebook_view_get_alert_sink (EMailReader *reader)
{
    EMailView *view;
    EShellView *shell_view;
    EShellContent *shell_content;

    view = E_MAIL_VIEW (reader);
    shell_view = e_mail_view_get_shell_view (view);
    shell_content = e_shell_view_get_shell_content (shell_view);

    return E_ALERT_SINK (shell_content);
}

static EMailBackend *
mail_notebook_view_get_backend (EMailReader *reader)
{
    EMailView *view;
    EShellView *shell_view;
    EShellBackend *shell_backend;

    view = E_MAIL_VIEW (reader);
    shell_view = e_mail_view_get_shell_view (view);
    shell_backend = e_shell_view_get_shell_backend (shell_view);

    return E_MAIL_BACKEND (shell_backend);
}

static EMFormatHTML *
mail_notebook_view_get_formatter (EMailReader *reader)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (reader);

    if (priv->current_view == NULL)
        return NULL;

    return e_mail_reader_get_formatter (E_MAIL_READER (priv->current_view));
}

static gboolean
mail_notebook_view_get_hide_deleted (EMailReader *reader)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (reader);

    if (priv->current_view == NULL)
        return FALSE;

    reader = E_MAIL_READER (priv->current_view);

    return e_mail_reader_get_hide_deleted (reader);
}

static GtkWidget *
mail_notebook_view_get_message_list (EMailReader *reader)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (reader);

    if (priv->current_view == NULL)
        return NULL;

    reader = E_MAIL_READER (priv->current_view);

    return e_mail_reader_get_message_list (reader);
}

static GtkMenu *
mail_notebook_view_get_popup_menu (EMailReader *reader)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (reader);

    if (priv->current_view == NULL)
        return NULL;

    reader = E_MAIL_READER (priv->current_view);

    return e_mail_reader_get_popup_menu (reader);
}

static GtkWindow *
mail_notebook_view_get_window (EMailReader *reader)
{
    EMailView *view;
    EShellWindow *shell_window;
    EShellView *shell_view;

    view = E_MAIL_VIEW (reader);
    shell_view = e_mail_view_get_shell_view (view);
    shell_window = e_shell_view_get_shell_window (shell_view);

    return GTK_WINDOW (shell_window);
}

static void
reconnect_changed_event (EMailReader *child, EMailReader *parent)
{
    g_signal_emit_by_name (parent, "changed");
}

static void
reconnect_folder_loaded_event (EMailReader *child,
                               EMailReader *parent)
{
    g_signal_emit_by_name (parent, "folder-loaded");
}

static void
mail_netbook_view_open_mail (EMailView *view,
                             const gchar *uid,
                             EMailNotebookView *nview)
{
    EMailNotebookViewPrivate *priv;
    EShellView *shell_view;
    const gchar *folder_uri;
    CamelFolder *folder;
    EMailView *pane;
    gint page;
    CamelMessageInfo *info;
    gint pos;

#if HAVE_CLUTTER
    EMailTab *tab;
    ClutterActor *clone;
    ClutterTimeline *timeline;
    GtkWidget *mlist;
#endif

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (nview);

#if HAVE_CLUTTER
    e_mail_tab_set_active (
        e_mail_tab_picker_get_tab (priv->tab_picker,
        e_mail_tab_picker_get_current_tab (priv->tab_picker)), FALSE);
#endif

    shell_view = e_mail_view_get_shell_view (E_MAIL_VIEW (nview));
    pos = emnv_get_page_num (nview, GTK_WIDGET (priv->current_view));
    pane = e_mail_message_pane_new (shell_view);
    e_mail_view_set_previous_view (pane, priv->current_view);
    E_MAIL_MESSAGE_PANE (pane)->parent_folder_view = priv->current_view;
    priv->current_view = pane;

    gtk_widget_show (GTK_WIDGET (pane));

    folder = e_mail_reader_get_folder (E_MAIL_READER (view));
    folder_uri = e_mail_reader_get_folder_uri (E_MAIL_READER (view));

    info = camel_folder_get_message_info (folder, uid);

    page = gtk_notebook_insert_page (
        priv->book, GTK_WIDGET (pane),
        create_tab_label (nview, priv->current_view,
        camel_message_info_subject (info)), pos + 1);

#if HAVE_CLUTTER
    mlist = e_mail_reader_get_message_list (E_MAIL_READER (pane));
    mnv_set_current_tab (nview, page);
    g_object_set_data ((GObject *)priv->current_view, "stage", priv->stage);
    g_object_set_data ((GObject *)mlist, "stage", priv->stage);
    g_object_set_data ((GObject *)mlist, "preview-actor", priv->actor);
#else
    gtk_notebook_set_current_page (priv->book, page);
#endif

#if HAVE_CLUTTER
    tab = (EMailTab *)e_mail_tab_new_full (camel_message_info_subject (info), NULL, 1);
    g_object_set_data ((GObject *)tab, "page", pane);
    g_object_set_data ((GObject *)pane, "tab", tab);

    clutter_actor_show ((ClutterActor *)tab);

    clone = e_mail_tab_new_full (camel_message_info_subject (info), NULL, 200);
    clutter_actor_set_reactive (clone, FALSE);
    clutter_actor_show (clone);

    e_mail_tab_set_preview_actor (tab, clone);
    e_mail_tab_set_can_close (tab, TRUE);
    e_mail_tab_picker_add_tab (priv->tab_picker, tab, pos+1);
    e_mail_tab_enable_drag (tab, TRUE);

    page = e_mail_tab_picker_get_tab_no (priv->tab_picker, tab);
    e_mail_tab_picker_set_current_tab (priv->tab_picker, page);

    g_signal_connect (tab , "closed",
              G_CALLBACK (mnv_tab_closed), nview);

    g_object_ref (tab);
    timeline = clutter_timeline_new (150);
    g_signal_connect (
        timeline, "new-frame",
        G_CALLBACK (mnv_tab_anim_frame_cb), tab);
    g_signal_connect (
        timeline, "completed",
        G_CALLBACK (mnv_tab_anim_complete_cb), tab);
    clutter_timeline_start (timeline);
#endif

    g_signal_connect (
        E_MAIL_READER(pane), "changed",
        G_CALLBACK (reconnect_changed_event), nview);
    g_signal_connect (
        E_MAIL_READER (pane), "folder-loaded",
        G_CALLBACK (reconnect_folder_loaded_event), nview);
    e_mail_reader_set_folder (
        E_MAIL_READER (pane), folder, folder_uri);
    e_mail_reader_set_group_by_threads (
        E_MAIL_READER (pane),
        e_mail_reader_get_group_by_threads (E_MAIL_READER (view)));

    e_mail_reader_enable_show_folder (E_MAIL_READER (pane));
    e_mail_reader_set_message (E_MAIL_READER (pane), uid);
    camel_message_info_free (info);
}

#if HAVE_CLUTTER
static ClutterActor *
build_histogram (GtkWidget *widget, CamelFolder *folder)
{
    gint week_time = 60 * 60 * 24 * 7;
    gint weeks[54];
    gint i;
    GPtrArray *uids;
    gint max = 1;
    ClutterActor *texture;
    cairo_t *cr;
    gfloat ratio;
    gint x = 0;
    time_t now = time (NULL);
    GtkStyle *style;
    GdkColor *color;

    for (i=0; i<54; i++)
        weeks[i] = 0;

    style = gtk_widget_get_style (GTK_WIDGET (widget));
    color = &style->mid[GTK_STATE_NORMAL];

    uids = camel_folder_get_uids (folder);
    camel_folder_summary_prepare_fetch_all (folder->summary, NULL);
    for (i = 0; i < uids->len; i++) {
        CamelMessageInfo *info = camel_folder_get_message_info (folder, uids->pdata[i]);
        if (info) {
            time_t dreceived = now - camel_message_info_date_received (info);
            gint week;

            week = (dreceived / week_time) - 1;
            if (week > 52)
                weeks[53]++;
            else
                weeks[week]++;

            camel_message_info_free (info);
        }
    }

    for (i=0; i< 53; i++) {
        if (weeks[i] > max)
            max = weeks[i];
    }

    ratio = 50.0/max;

    camel_folder_free_uids (folder, uids);

    texture = clutter_cairo_texture_new (200, 50);
    clutter_actor_set_size (texture, 200, 50);
    cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (texture));

    clutter_actor_show_all (texture);

    cairo_save (cr);
    cairo_new_path (cr);
    cairo_move_to (cr, x, 50 - (weeks[52] * ratio));

    cairo_set_source_rgba (cr, 0.3, 0.2, 0.4, 1.0);

    for (i=51; i>=0; i--) {
        x+=3;
        cairo_line_to (cr, x, 50 - (weeks[i]*ratio));

    }

    cairo_stroke (cr);
    cairo_restore (cr);

    cairo_save (cr);

    cairo_set_source_rgba (cr, 0.8, 0.5, 0.3, 1.0);
    cairo_arc (cr, x,  50 - (weeks[0] * ratio), 3, 0, 2*M_PI);

    cairo_fill (cr);
    cairo_restore (cr);

    cairo_destroy (cr);

    return texture;
}
#endif

static void
mail_notebook_view_set_folder (EMailReader *reader,
                               CamelFolder *folder,
                               const gchar *folder_uri)
{
    EMailNotebookViewPrivate *priv;
    GtkWidget *new_view;
#if HAVE_CLUTTER
    EMailTab *tab;
    ClutterActor *clone;
    ClutterTimeline *timeline;
#endif

    if (!folder_uri)
        return;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (reader);

    new_view = g_hash_table_lookup (priv->views, folder_uri);
    if (new_view) {
        gint curr = emnv_get_page_num (E_MAIL_NOTEBOOK_VIEW (reader), new_view);
#if HAVE_CLUTTER
        EMailTab *tab;

        if (curr == e_mail_tab_picker_get_current_tab (priv->tab_picker))
            return;

        e_mail_tab_set_active (e_mail_tab_picker_get_tab (priv->tab_picker,
                        e_mail_tab_picker_get_current_tab (priv->tab_picker)),
                    FALSE);
#endif

        priv->current_view = (EMailView *)new_view;
#if HAVE_CLUTTER
        mnv_set_current_tab (E_MAIL_NOTEBOOK_VIEW (reader), curr);
#else
        gtk_notebook_set_current_page (priv->book, curr);
#endif

#if HAVE_CLUTTER
        tab = (EMailTab *)g_object_get_data ((GObject *)priv->current_view, "page");
        curr = e_mail_tab_picker_get_tab_no (priv->tab_picker, tab);
        e_mail_tab_picker_set_current_tab (priv->tab_picker, curr);
#endif
        return;
    }

    if (folder || folder_uri) {
        gint page;
#if HAVE_CLUTTER
        GtkWidget *list;
#endif

        if (priv->inited) {
            EMailView *old_view = priv->current_view;
            EShellView *shell_view;

            shell_view = e_mail_view_get_shell_view (E_MAIL_VIEW (reader));
            priv->current_view = e_mail_folder_pane_new (shell_view);
            gtk_widget_show ((GtkWidget *)priv->current_view);
            e_mail_view_set_previous_view (priv->current_view, old_view);
            page = gtk_notebook_append_page (
                priv->book, (GtkWidget *)priv->current_view,
                create_tab_label (
                    E_MAIL_NOTEBOOK_VIEW (reader),
                    priv->current_view,
                    camel_folder_get_full_name (folder)));
#if HAVE_CLUTTER
            mnv_set_current_tab (E_MAIL_NOTEBOOK_VIEW (reader), page);
#else
            gtk_notebook_set_current_page (priv->book, page);
#endif

#if HAVE_CLUTTER
            e_mail_tab_set_active (
                e_mail_tab_picker_get_tab (
                    priv->tab_picker,
                    e_mail_tab_picker_get_current_tab (
                        priv->tab_picker)),
                FALSE);

            tab = (EMailTab *) e_mail_tab_new_full (
                camel_folder_get_full_name (folder), NULL, 1);
            g_object_set_data ((GObject *)tab, "page", priv->current_view);
            g_object_set_data ((GObject *)priv->current_view, "page", tab);
            g_object_set_data ((GObject *)priv->current_view, "tab", tab);

            clutter_actor_show ((ClutterActor *)tab);

            clone = build_histogram ((GtkWidget *)reader, folder);
            clutter_actor_set_reactive (clone, FALSE);
            clutter_actor_show (clone);

            e_mail_tab_set_preview_actor (tab, clone);
            e_mail_tab_set_can_close (tab, TRUE);
            e_mail_tab_set_preview_mode (
                tab, e_mail_tab_picker_get_preview_mode (
                priv->tab_picker));

            e_mail_tab_picker_add_tab (priv->tab_picker, tab, -1);
            page = e_mail_tab_picker_get_tab_no (priv->tab_picker, tab);
            e_mail_tab_picker_set_current_tab (priv->tab_picker, page);

            e_mail_tab_enable_drag (tab, TRUE);
            g_object_ref (tab);
            timeline = clutter_timeline_new (150);
            g_signal_connect (
                timeline, "new-frame",
                G_CALLBACK (mnv_tab_anim_frame_cb), tab);
            g_signal_connect (
                timeline, "completed",
                G_CALLBACK (mnv_tab_anim_complete_cb), tab);
            clutter_timeline_start (timeline);
#endif
        } else {
            priv->inited = TRUE;
            gtk_notebook_set_tab_label (priv->book, (GtkWidget *)priv->current_view,
                        create_tab_label (E_MAIL_NOTEBOOK_VIEW (reader),
                                  priv->current_view,
                                  camel_folder_get_full_name (folder)));

#if HAVE_CLUTTER
            tab = e_mail_tab_picker_get_tab (priv->tab_picker,
                        e_mail_tab_picker_get_current_tab (priv->tab_picker));
            g_object_set_data ((GObject *)tab, "page", priv->current_view);
            g_object_set_data ((GObject *)priv->current_view, "page", tab);
            g_object_set_data ((GObject *)priv->current_view, "tab", tab);

            e_mail_tab_set_text (tab, camel_folder_get_full_name (folder));
            clone = build_histogram ((GtkWidget *)reader, folder);
            clutter_actor_set_reactive (clone, FALSE);
            clutter_actor_show (clone);
            e_mail_tab_set_preview_actor (tab, clone);
#endif
        }

#if HAVE_CLUTTER
        list = e_mail_reader_get_message_list (E_MAIL_READER (priv->current_view));
        g_signal_connect (tab , "closed",
                   G_CALLBACK (mnv_tab_closed), reader);
        g_object_set_data ((GObject *)priv->current_view, "stage", priv->stage);
        g_object_set_data ((GObject *)list, "stage", priv->stage);
        g_object_set_data ((GObject *)list, "actor", priv->actor);

#endif
        e_mail_reader_set_folder (E_MAIL_READER (priv->current_view), folder, folder_uri);
        g_hash_table_insert (priv->views, g_strdup (folder_uri), priv->current_view);
        g_signal_connect (
            priv->current_view, "changed",
            G_CALLBACK (reconnect_changed_event), reader);
        g_signal_connect (
            priv->current_view, "folder-loaded",
            G_CALLBACK (reconnect_folder_loaded_event), reader);
        g_signal_connect (
            priv->current_view, "open-mail",
            G_CALLBACK (mail_netbook_view_open_mail), reader);
    }
}

static void
mail_notebook_view_show_search_bar (EMailReader *reader)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (reader);

    if (priv->current_view == NULL)
        return;

    reader = E_MAIL_READER (priv->current_view);

    e_mail_reader_show_search_bar (reader);
}

static gboolean
mail_notebook_view_enable_show_folder (EMailReader *reader)
{
    EMailNotebookViewPrivate *priv = E_MAIL_NOTEBOOK_VIEW (reader)->priv;

    if (!priv->current_view)
        return FALSE;

    return e_mail_reader_get_enable_show_folder (E_MAIL_READER (priv->current_view));
}

static guint
mail_notebook_view_open_selected_mail (EMailReader *reader)
{
    EMailNotebookViewPrivate *priv;

    priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (reader);

    if (priv->current_view == NULL)
        return 0;

    reader = E_MAIL_READER (priv->current_view);

    return e_mail_reader_open_selected_mail (reader);
}

static void
e_mail_notebook_view_class_init (EMailNotebookViewClass *class)
{
    GObjectClass *object_class;
    EMailViewClass *mail_view_class;

    g_type_class_add_private (class, sizeof (EMailNotebookViewPrivate));

    object_class = G_OBJECT_CLASS (class);
    object_class->constructed = mail_notebook_view_constructed;
    object_class->set_property = mail_notebook_view_set_property;
    object_class->get_property = mail_notebook_view_get_property;

    mail_view_class = E_MAIL_VIEW_CLASS (class);
    mail_view_class->set_search_strings = mail_notebook_view_set_search_strings;
    mail_view_class->get_view_instance = mail_notebook_view_get_view_instance;
    mail_view_class->update_view_instance = mail_notebook_view_update_view_instance;
    mail_view_class->set_orientation = mail_notebook_view_set_orientation;
    mail_view_class->get_orientation = mail_notebook_view_get_orientation;
    mail_view_class->get_show_deleted = mail_notebook_view_get_show_deleted;
    mail_view_class->set_show_deleted = mail_notebook_view_set_show_deleted;
    mail_view_class->get_preview_visible = mail_notebook_view_get_preview_visible;
    mail_view_class->set_preview_visible = mail_notebook_view_set_preview_visible;

    /* Inherited from EMailReader */
    g_object_class_override_property (
        object_class,
        PROP_FORWARD_STYLE,
        "forward-style");

    /* Inherited from EMailReader */
    g_object_class_override_property (
        object_class,
        PROP_GROUP_BY_THREADS,
        "group-by-threads");

    /* Inherited from EMailReader */
    g_object_class_override_property (
        object_class,
        PROP_REPLY_STYLE,
        "reply-style");
}

static void
e_mail_notebook_view_reader_init (EMailReaderInterface *interface)
{
    interface->get_action_group = mail_notebook_view_get_action_group;
    interface->get_alert_sink = mail_notebook_view_get_alert_sink;
    interface->get_backend = mail_notebook_view_get_backend;
    interface->get_formatter = mail_notebook_view_get_formatter;
    interface->get_hide_deleted = mail_notebook_view_get_hide_deleted;
    interface->get_message_list = mail_notebook_view_get_message_list;
    interface->get_popup_menu = mail_notebook_view_get_popup_menu;
    interface->get_window = mail_notebook_view_get_window;
    interface->set_folder = mail_notebook_view_set_folder;
    interface->show_search_bar = mail_notebook_view_show_search_bar;
    interface->open_selected_mail = mail_notebook_view_open_selected_mail;
    interface->enable_show_folder = mail_notebook_view_enable_show_folder;
}

static void
e_mail_notebook_view_init (EMailNotebookView  *view)
{
    view->priv = E_MAIL_NOTEBOOK_VIEW_GET_PRIVATE (view);

    view->priv->inited = FALSE;
    view->priv->views = g_hash_table_new (g_str_hash, g_str_equal);
}

static void
emnv_show_folder (EMailNotebookView *view, gpointer not_used)
{
    gint pos;
    EMailNotebookViewPrivate *priv = view->priv;

    pos = emnv_get_page_num (
        view, (GtkWidget *) E_MAIL_MESSAGE_PANE (
        priv->current_view)->parent_folder_view);

#if HAVE_CLUTTER
    e_mail_tab_picker_set_current_tab (priv->tab_picker, pos);
    mnv_set_current_tab (E_MAIL_NOTEBOOK_VIEW (view), pos);
#else
    gtk_notebook_set_current_page (priv->book, pos);
#endif

}

static void
emnv_show_prevtab (EMailNotebookView *view, gpointer not_used)
{
    gint pos;
    EMailNotebookViewPrivate *priv = view->priv;

    pos = emnv_get_page_num (
        view, (GtkWidget *) E_MAIL_MESSAGE_PANE (
        priv->current_view)->parent_folder_view);

#if HAVE_CLUTTER
    pos = e_mail_tab_picker_get_current_tab (priv->tab_picker);
    if (pos > 0) {
        e_mail_tab_picker_set_current_tab (priv->tab_picker, pos-1);
        mnv_set_current_tab (E_MAIL_NOTEBOOK_VIEW (view), pos-1);
    }
#else
    pos = gtk_notebook_get_current_page (priv->book);
    if (pos > 0 )
        gtk_notebook_set_current_page (priv->book, pos-1);
#endif

}

static void
emnv_show_nexttab (EMailNotebookView *view, gpointer not_used)
{
    gint pos;
    EMailNotebookViewPrivate *priv = view->priv;

#if HAVE_CLUTTER
    pos = e_mail_tab_picker_get_current_tab (priv->tab_picker);

    if (pos < (gtk_notebook_get_n_pages (priv->book)-1)) {
        e_mail_tab_picker_set_current_tab (priv->tab_picker, pos+1);
        mnv_set_current_tab (E_MAIL_NOTEBOOK_VIEW (view), pos+1);
    }
#else
    pos = gtk_notebook_get_current_page (priv->book);
    if (pos < (gtk_notebook_get_n_pages (priv->book)-1))
        gtk_notebook_set_current_page (priv->book, pos+1);
#endif

}

static void
emnv_close_tab (EMailNotebookView *view, gpointer not_used)
{
    EMailNotebookViewPrivate *priv = view->priv;

#if HAVE_CLUTTER
    mnv_tab_closed (g_object_get_data((GObject *)priv->current_view, "tab"),
            view);
#else
    tab_remove_gtk_cb (g_object_get_data((GObject *)priv->current_view, "close-button"),
                view);
#endif

}

GtkWidget *
e_mail_notebook_view_new (EShellView *shell_view)
{
    GtkWidget *widget;

    g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);

    widget = g_object_new (
        E_TYPE_MAIL_NOTEBOOK_VIEW,
        "shell-view", shell_view, NULL);
    g_signal_connect (widget, "show-folder",
            G_CALLBACK (emnv_show_folder), widget);
    g_signal_connect (widget, "show-next-tab",
            G_CALLBACK (emnv_show_nexttab), widget);
    g_signal_connect (widget, "show-previous-tab",
            G_CALLBACK (emnv_show_prevtab), widget);
    g_signal_connect (widget, "close-tab",
            G_CALLBACK (emnv_close_tab), widget);

    return widget;
}