File: gtkrecentchooserdefault.c

package info (click to toggle)
gtk%2B3.0 3.22.11-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 182,828 kB
  • ctags: 82,378
  • sloc: ansic: 1,165,043; xml: 9,259; makefile: 6,914; sh: 5,179; python: 402; perl: 370; cpp: 34; sed: 16
file content (1869 lines) | stat: -rw-r--r-- 56,819 bytes parent folder | download | duplicates (6)
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
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
/* GTK - The GIMP Toolkit
 * gtkrecentchooserdefault.c
 * Copyright (C) 2005-2006, Emmanuele Bassi
 *
 * This library 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) any later version.
 *
 * This library 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 this library. If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include <string.h>
#include <time.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include "gtkicontheme.h"
#include "gtksettings.h"
#include "gtktreeview.h"
#include "gtkliststore.h"
#include "gtkbutton.h"
#include "gtkcelllayout.h"
#include "gtkcellrendererpixbuf.h"
#include "gtkcellrenderertext.h"
#include "gtkcheckmenuitem.h"
#include "gtkclipboard.h"
#include "gtkcomboboxtext.h"
#include "gtkcssiconthemevalueprivate.h"
#include "gtkdragsource.h"
#include "gtkentry.h"
#include "gtkeventbox.h"
#include "gtkexpander.h"
#include "gtkframe.h"
#include "gtkbox.h"
#include "gtkpaned.h"
#include "gtkimage.h"
#include "gtkintl.h"
#include "gtklabel.h"
#include "gtkmenuitem.h"
#include "gtkmessagedialog.h"
#include "gtkscrolledwindow.h"
#include "gtkseparatormenuitem.h"
#include "gtksizegroup.h"
#include "gtksizerequest.h"
#include "gtkstylecontextprivate.h"
#include "gtktreemodelsort.h"
#include "gtktreemodelfilter.h"
#include "gtktreeselection.h"
#include "gtktreestore.h"
#include "gtktooltip.h"
#include "gtktypebuiltins.h"
#include "gtkorientable.h"
#include "gtkwindowgroup.h"
#include "deprecated/gtkactivatable.h"

#include "gtkrecentmanager.h"
#include "gtkrecentfilter.h"
#include "gtkrecentchooser.h"
#include "gtkrecentchooserprivate.h"
#include "gtkrecentchooserutils.h"
#include "gtkrecentchooserdefault.h"


enum 
{
  PROP_0,

  /* activatable properties */
  PROP_ACTIVATABLE_RELATED_ACTION,
  PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
};

typedef struct
{
  GtkRecentManager *manager;
  gulong manager_changed_id;
  guint local_manager : 1;

  gint icon_size;

  /* RecentChooser properties */
  gint limit;
  GtkRecentSortType sort_type;
  guint show_private : 1;
  guint show_not_found : 1;
  guint select_multiple : 1;
  guint show_tips : 1;
  guint show_icons : 1;
  guint local_only : 1;

  guint limit_set : 1;
  
  GSList *filters;
  GtkRecentFilter *current_filter;
  GtkWidget *filter_combo_hbox;
  GtkWidget *filter_combo;
  
  GtkRecentSortFunc sort_func;
  gpointer sort_data;
  GDestroyNotify sort_data_destroy;

  GtkIconTheme *icon_theme;
  
  GtkWidget *recent_view;
  GtkListStore *recent_store;
  GtkTreeViewColumn *icon_column;
  GtkTreeViewColumn *meta_column;
  GtkCellRenderer *icon_renderer;
  GtkCellRenderer *meta_renderer;
  GtkTreeSelection *selection;
  
  GtkWidget *recent_popup_menu;
  GtkWidget *recent_popup_menu_copy_item;
  GtkWidget *recent_popup_menu_remove_item;
  GtkWidget *recent_popup_menu_clear_item;
  GtkWidget *recent_popup_menu_show_private_item;
 
  guint load_id;
  GList *recent_items;
  gint n_recent_items;
  gint loaded_items;
  guint load_state;
} GtkRecentChooserDefaultPrivate;

struct _GtkRecentChooserDefault
{
  GtkBox parent_instance;

  GtkRecentChooserDefaultPrivate *priv;
};

typedef struct _GtkRecentChooserDefaultClass
{
  GtkBoxClass parent_class;
} GtkRecentChooserDefaultClass;

/* Keep inline with GtkTreeStore defined in gtkrecentchooserdefault.ui */
enum {
  RECENT_URI_COLUMN,
  RECENT_DISPLAY_NAME_COLUMN,
  RECENT_INFO_COLUMN,
  N_RECENT_COLUMNS
};

enum {
  LOAD_EMPTY,    /* initial state: the model is empty */
  LOAD_PRELOAD,  /* the model is loading and not inserted in the tree yet */
  LOAD_LOADING,  /* the model is fully loaded but not inserted */
  LOAD_FINISHED  /* the model is fully loaded and inserted */
};

/* Icon size for if we can't get it from the theme */
#define FALLBACK_ICON_SIZE  48
#define FALLBACK_ITEM_LIMIT 20

#define NUM_CHARS 40
#define NUM_LINES 9

#define DEFAULT_RECENT_FILES_LIMIT 50



/* GObject */
static void     _gtk_recent_chooser_default_class_init  (GtkRecentChooserDefaultClass *klass);
static void     _gtk_recent_chooser_default_init        (GtkRecentChooserDefault      *impl);
static void     gtk_recent_chooser_default_finalize     (GObject                      *object);
static void     gtk_recent_chooser_default_dispose      (GObject                      *object);
static void     gtk_recent_chooser_default_set_property (GObject                      *object,
						         guint                         prop_id,
						         const GValue                 *value,
						         GParamSpec                   *pspec);
static void     gtk_recent_chooser_default_get_property (GObject                      *object,
						         guint                         prop_id,
						         GValue                       *value,
						         GParamSpec                   *pspec);

/* GtkRecentChooserIface */
static void              gtk_recent_chooser_iface_init                 (GtkRecentChooserIface  *iface);
static gboolean          gtk_recent_chooser_default_set_current_uri    (GtkRecentChooser       *chooser,
								        const gchar            *uri,
								        GError                **error);
static gchar *           gtk_recent_chooser_default_get_current_uri    (GtkRecentChooser       *chooser);
static gboolean          gtk_recent_chooser_default_select_uri         (GtkRecentChooser       *chooser,
								        const gchar            *uri,
								        GError                **error);
static void              gtk_recent_chooser_default_unselect_uri       (GtkRecentChooser       *chooser,
								        const gchar            *uri);
static void              gtk_recent_chooser_default_select_all         (GtkRecentChooser       *chooser);
static void              gtk_recent_chooser_default_unselect_all       (GtkRecentChooser       *chooser);
static GList *           gtk_recent_chooser_default_get_items          (GtkRecentChooser       *chooser);
static GtkRecentManager *gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser       *chooser);
static void              gtk_recent_chooser_default_set_sort_func      (GtkRecentChooser       *chooser,
									GtkRecentSortFunc       sort_func,
									gpointer                sort_data,
									GDestroyNotify          data_destroy);
static void              gtk_recent_chooser_default_add_filter         (GtkRecentChooser       *chooser,
								        GtkRecentFilter        *filter);
static void              gtk_recent_chooser_default_remove_filter      (GtkRecentChooser       *chooser,
								        GtkRecentFilter        *filter);
static GSList *          gtk_recent_chooser_default_list_filters       (GtkRecentChooser       *chooser);


static void gtk_recent_chooser_default_map      (GtkWidget *widget);
static void gtk_recent_chooser_default_show_all (GtkWidget *widget);

static void set_current_filter        (GtkRecentChooserDefault *impl,
				       GtkRecentFilter         *filter);

static GtkIconTheme *get_icon_theme_for_widget (GtkWidget   *widget);
static gint          get_icon_size_for_widget  (GtkWidget   *widget,
						GtkIconSize  icon_size);

static void reload_recent_items (GtkRecentChooserDefault *impl);
static void chooser_set_model   (GtkRecentChooserDefault *impl);

static void set_recent_manager (GtkRecentChooserDefault *impl,
				GtkRecentManager        *manager);

static void chooser_set_sort_type (GtkRecentChooserDefault *impl,
				   GtkRecentSortType        sort_type);

static void recent_manager_changed_cb (GtkRecentManager  *manager,
			               gpointer           user_data);
static void recent_icon_data_func     (GtkTreeViewColumn *tree_column,
				       GtkCellRenderer   *cell,
				       GtkTreeModel      *model,
				       GtkTreeIter       *iter,
				       gpointer           user_data);
static void recent_meta_data_func     (GtkTreeViewColumn *tree_column,
				       GtkCellRenderer   *cell,
				       GtkTreeModel      *model,
				       GtkTreeIter       *iter,
				       gpointer           user_data);

static void selection_changed_cb      (GtkTreeSelection  *z,
				       gpointer           user_data);
static void row_activated_cb          (GtkTreeView       *tree_view,
				       GtkTreePath       *tree_path,
				       GtkTreeViewColumn *tree_column,
				       gpointer           user_data);
static void filter_combo_changed_cb   (GtkComboBox       *combo_box,
				       gpointer           user_data);

static void remove_all_activated_cb   (GtkMenuItem       *menu_item,
				       gpointer           user_data);
static void remove_item_activated_cb  (GtkMenuItem       *menu_item,
				       gpointer           user_data);
static void show_private_toggled_cb   (GtkCheckMenuItem  *menu_item,
				       gpointer           user_data);

static gboolean recent_view_popup_menu_cb   (GtkWidget      *widget,
					     gpointer        user_data);
static gboolean recent_view_button_press_cb (GtkWidget      *widget,
					     GdkEventButton *event,
					     gpointer        user_data);

static void     recent_view_drag_begin_cb         (GtkWidget        *widget,
						   GdkDragContext   *context,
						   gpointer          user_data);
static void     recent_view_drag_data_get_cb      (GtkWidget        *widget,
						   GdkDragContext   *context,
						   GtkSelectionData *selection_data,
						   guint             info,
						   guint32           time_,
						   gpointer          data);
static gboolean recent_view_query_tooltip_cb      (GtkWidget        *widget,
                                                   gint              x,
                                                   gint              y,
                                                   gboolean          keyboard_tip,
                                                   GtkTooltip       *tooltip,
                                                   gpointer          user_data);

static void gtk_recent_chooser_activatable_iface_init (GtkActivatableIface  *iface);
static void gtk_recent_chooser_update                 (GtkActivatable       *activatable,
						       GtkAction            *action,
						       const gchar          *property_name);
static void gtk_recent_chooser_sync_action_properties (GtkActivatable       *activatable,
						       GtkAction            *action);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDefault,
			 _gtk_recent_chooser_default,
			 GTK_TYPE_BOX,
                         G_ADD_PRIVATE (GtkRecentChooserDefault)
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
				 		gtk_recent_chooser_iface_init)
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
				 		gtk_recent_chooser_activatable_iface_init))
G_GNUC_END_IGNORE_DEPRECATIONS;



static void
gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
{
  iface->set_current_uri = gtk_recent_chooser_default_set_current_uri;
  iface->get_current_uri = gtk_recent_chooser_default_get_current_uri;
  iface->select_uri = gtk_recent_chooser_default_select_uri;
  iface->unselect_uri = gtk_recent_chooser_default_unselect_uri;
  iface->select_all = gtk_recent_chooser_default_select_all;
  iface->unselect_all = gtk_recent_chooser_default_unselect_all;
  iface->get_items = gtk_recent_chooser_default_get_items;
  iface->get_recent_manager = gtk_recent_chooser_default_get_recent_manager;
  iface->set_sort_func = gtk_recent_chooser_default_set_sort_func;
  iface->add_filter = gtk_recent_chooser_default_add_filter;
  iface->remove_filter = gtk_recent_chooser_default_remove_filter;
  iface->list_filters = gtk_recent_chooser_default_list_filters;
}

static void
gtk_recent_chooser_activatable_iface_init (GtkActivatableIface *iface)

{
  iface->update = gtk_recent_chooser_update;
  iface->sync_action_properties = gtk_recent_chooser_sync_action_properties;
}

static void
_gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

  gobject_class->set_property = gtk_recent_chooser_default_set_property;
  gobject_class->get_property = gtk_recent_chooser_default_get_property;
  gobject_class->dispose = gtk_recent_chooser_default_dispose;
  gobject_class->finalize = gtk_recent_chooser_default_finalize;
  
  widget_class->map = gtk_recent_chooser_default_map;
  widget_class->show_all = gtk_recent_chooser_default_show_all;
  
  _gtk_recent_chooser_install_properties (gobject_class);

  g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
  g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");

  /* Bind class to template
   */
  gtk_widget_class_set_template_from_resource (widget_class,
					       "/org/gtk/libgtk/ui/gtkrecentchooserdefault.ui");

  gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, filter_combo_hbox);
  gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, filter_combo);
  gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, recent_view);
  gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, recent_store);
  gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, icon_column);
  gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, meta_column);
  gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, icon_renderer);
  gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, meta_renderer);
  gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, selection);

  gtk_widget_class_bind_template_callback (widget_class, selection_changed_cb);
  gtk_widget_class_bind_template_callback (widget_class, row_activated_cb);
  gtk_widget_class_bind_template_callback (widget_class, filter_combo_changed_cb);
  gtk_widget_class_bind_template_callback (widget_class, recent_view_popup_menu_cb);
  gtk_widget_class_bind_template_callback (widget_class, recent_view_button_press_cb);
  gtk_widget_class_bind_template_callback (widget_class, recent_view_drag_begin_cb);
  gtk_widget_class_bind_template_callback (widget_class, recent_view_drag_data_get_cb);
  gtk_widget_class_bind_template_callback (widget_class, recent_view_query_tooltip_cb);
}

static void
_gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
{
  GtkRecentChooserDefaultPrivate *priv;

  impl->priv = priv = _gtk_recent_chooser_default_get_instance_private (impl);

  /* by default, we use the global manager */
  priv->local_manager = FALSE;

  priv->limit = FALLBACK_ITEM_LIMIT;
  priv->sort_type = GTK_RECENT_SORT_NONE;

  priv->show_icons = TRUE;
  priv->show_private = FALSE;
  priv->show_not_found = TRUE;
  priv->show_tips = FALSE;
  priv->select_multiple = FALSE;
  priv->local_only = TRUE;
  
  priv->icon_size = FALLBACK_ICON_SIZE;
  priv->icon_theme = NULL;
  
  priv->current_filter = NULL;

  priv->recent_items = NULL;
  priv->n_recent_items = 0;
  priv->loaded_items = 0;
  
  priv->load_state = LOAD_EMPTY;

  gtk_widget_init_template (GTK_WIDGET (impl));

  g_object_set_data (G_OBJECT (priv->recent_view),
                     "GtkRecentChooserDefault", impl);

  gtk_tree_view_column_set_cell_data_func (priv->icon_column,
  					   priv->icon_renderer,
  					   recent_icon_data_func,
  					   impl,
  					   NULL);
  gtk_tree_view_column_set_cell_data_func (priv->meta_column,
  					   priv->meta_renderer,
  					   recent_meta_data_func,
  					   impl,
  					   NULL);
  gtk_drag_source_set (priv->recent_view,
		       GDK_BUTTON1_MASK,
		       NULL, 0,
		       GDK_ACTION_COPY);
  gtk_drag_source_add_uri_targets (priv->recent_view);
}

static void
gtk_recent_chooser_default_set_property (GObject      *object,
				         guint         prop_id,
					 const GValue *value,
					 GParamSpec   *pspec)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
  
  switch (prop_id)
    {
    case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
      set_recent_manager (impl, g_value_get_object (value));
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
      if (impl->priv->show_private != g_value_get_boolean (value))
        {
          impl->priv->show_private = g_value_get_boolean (value);
          if (impl->priv->recent_popup_menu_show_private_item)
            {
              GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM (impl->priv->recent_popup_menu_show_private_item);
              g_signal_handlers_block_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
              gtk_check_menu_item_set_active (item, impl->priv->show_private);
              g_signal_handlers_unblock_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
            }
          reload_recent_items (impl);
          g_object_notify_by_pspec (object, pspec);
        }
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
      if (impl->priv->show_not_found != g_value_get_boolean (value))
        {
          impl->priv->show_not_found = g_value_get_boolean (value);
          reload_recent_items (impl);
          g_object_notify_by_pspec (object, pspec);
        }
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
      if (impl->priv->show_tips != g_value_get_boolean (value))
        {
          impl->priv->show_tips = g_value_get_boolean (value);
          g_object_notify_by_pspec (object, pspec);
        }
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
      if (impl->priv->show_icons != g_value_get_boolean (value))
        {
          impl->priv->show_icons = g_value_get_boolean (value);
          gtk_tree_view_column_set_visible (impl->priv->icon_column, impl->priv->show_icons);
          g_object_notify_by_pspec (object, pspec);
        }
      break;
    case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
      if (impl->priv->select_multiple != g_value_get_boolean (value))
        {
          impl->priv->select_multiple = g_value_get_boolean (value);
          if (impl->priv->select_multiple)
            gtk_tree_selection_set_mode (impl->priv->selection, GTK_SELECTION_MULTIPLE);
          else
            gtk_tree_selection_set_mode (impl->priv->selection, GTK_SELECTION_SINGLE);
          g_object_notify_by_pspec (object, pspec);
        }
      break;
    case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
      if (impl->priv->local_only != g_value_get_boolean (value))
        {
          impl->priv->local_only = g_value_get_boolean (value);
          reload_recent_items (impl);
          g_object_notify_by_pspec (object, pspec);
        }
      break;
    case GTK_RECENT_CHOOSER_PROP_LIMIT:
      if (impl->priv->limit != g_value_get_int (value))
        {
          impl->priv->limit = g_value_get_int (value);
          impl->priv->limit_set = TRUE;
          reload_recent_items (impl);
          g_object_notify_by_pspec (object, pspec);
        }
      break;
    case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
      chooser_set_sort_type (impl, g_value_get_enum (value));
      break;
    case GTK_RECENT_CHOOSER_PROP_FILTER:
      set_current_filter (impl, g_value_get_object (value));
      break;
    case PROP_ACTIVATABLE_RELATED_ACTION:
      _gtk_recent_chooser_set_related_action (GTK_RECENT_CHOOSER (impl), g_value_get_object (value));
      break;
    case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: 
      _gtk_recent_chooser_set_use_action_appearance (GTK_RECENT_CHOOSER (impl), g_value_get_boolean (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
gtk_recent_chooser_default_get_property (GObject    *object,
					 guint       prop_id,
					 GValue     *value,
					 GParamSpec *pspec)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
  
  switch (prop_id)
    {
    case GTK_RECENT_CHOOSER_PROP_LIMIT:
      g_value_set_int (value, impl->priv->limit);
      break;
    case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
      g_value_set_enum (value, impl->priv->sort_type);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
      g_value_set_boolean (value, impl->priv->show_private);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
      g_value_set_boolean (value, impl->priv->show_icons);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
      g_value_set_boolean (value, impl->priv->show_not_found);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
      g_value_set_boolean (value, impl->priv->show_tips);
      break;
    case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
      g_value_set_boolean (value, impl->priv->local_only);
      break;
    case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
      g_value_set_boolean (value, impl->priv->select_multiple);
      break;
    case GTK_RECENT_CHOOSER_PROP_FILTER:
      g_value_set_object (value, impl->priv->current_filter);
      break;
    case PROP_ACTIVATABLE_RELATED_ACTION:
      g_value_set_object (value, _gtk_recent_chooser_get_related_action (GTK_RECENT_CHOOSER (impl)));
      break;
    case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: 
      g_value_set_boolean (value, _gtk_recent_chooser_get_use_action_appearance (GTK_RECENT_CHOOSER (impl)));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
gtk_recent_chooser_default_dispose (GObject *object)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);

  if (impl->priv->load_id)
    {
      g_source_remove (impl->priv->load_id);
      impl->priv->load_state = LOAD_EMPTY;
      impl->priv->load_id = 0;
    }

  g_list_free_full (impl->priv->recent_items, (GDestroyNotify) gtk_recent_info_unref);
  impl->priv->recent_items = NULL;

  if (impl->priv->manager && impl->priv->manager_changed_id)
    {
      g_signal_handler_disconnect (impl->priv->manager, impl->priv->manager_changed_id);
      impl->priv->manager_changed_id = 0;
    }

  if (impl->priv->filters)
    {
      g_slist_free_full (impl->priv->filters, g_object_unref);
      impl->priv->filters = NULL;
    }
  
  if (impl->priv->current_filter)
    {
      g_object_unref (impl->priv->current_filter);
      impl->priv->current_filter = NULL;
    }

  G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->dispose (object);
}

static void
gtk_recent_chooser_default_finalize (GObject *object)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);

  impl->priv->manager = NULL; 
  
  if (impl->priv->sort_data_destroy)
    {
      impl->priv->sort_data_destroy (impl->priv->sort_data);
      impl->priv->sort_data_destroy = NULL;
    }
  
  impl->priv->sort_data = NULL;
  impl->priv->sort_func = NULL;
  
  G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->finalize (object);
}

/* override GtkWidget::show_all since we have internal widgets we wish to keep
 * hidden unless we decide otherwise, like the filter combo box.
 */
static void
gtk_recent_chooser_default_show_all (GtkWidget *widget)
{
  gtk_widget_show (widget);
}



/* Shows an error dialog set as transient for the specified window */
static void
error_message_with_parent (GtkWindow   *parent,
			   const gchar *msg,
			   const gchar *detail)
{
  GtkWidget *dialog;

  dialog = gtk_message_dialog_new (parent,
				   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
				   GTK_MESSAGE_ERROR,
				   GTK_BUTTONS_OK,
				   "%s",
				   msg);
  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
					    "%s", detail);

  if (gtk_window_has_group (parent))
    gtk_window_group_add_window (gtk_window_get_group (parent),
                                 GTK_WINDOW (dialog));

  gtk_dialog_run (GTK_DIALOG (dialog));
  gtk_widget_destroy (dialog);
}

/* Returns a toplevel GtkWindow, or NULL if none */
static GtkWindow *
get_toplevel (GtkWidget *widget)
{
  GtkWidget *toplevel;

  toplevel = gtk_widget_get_toplevel (widget);
  if (!gtk_widget_is_toplevel (toplevel))
    return NULL;
  else
    return GTK_WINDOW (toplevel);
}

/* Shows an error dialog for the file chooser */
static void
error_message (GtkRecentChooserDefault *impl,
	       const gchar             *msg,
	       const gchar             *detail)
{
  error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
}

static void
set_busy_cursor (GtkRecentChooserDefault *impl,
		 gboolean                 busy)
{
  GtkWindow *toplevel;
  GdkDisplay *display;
  GdkCursor *cursor;

  toplevel = get_toplevel (GTK_WIDGET (impl));
  if (!toplevel || !gtk_widget_get_realized (GTK_WIDGET (toplevel)))
    return;

  display = gtk_widget_get_display (GTK_WIDGET (toplevel));

  if (busy)
    cursor = gdk_cursor_new_from_name (display, "progress");
  else
    cursor = NULL;

  gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (toplevel)), cursor);
  gdk_display_flush (display);

  if (cursor)
    g_object_unref (cursor);
}

static void
chooser_set_model (GtkRecentChooserDefault *impl)
{
  g_assert (impl->priv->recent_store != NULL);
  g_assert (impl->priv->load_state == LOAD_LOADING);

  gtk_tree_view_set_model (GTK_TREE_VIEW (impl->priv->recent_view),
                           GTK_TREE_MODEL (impl->priv->recent_store));
  gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->priv->recent_view));
  gtk_tree_view_set_enable_search (GTK_TREE_VIEW (impl->priv->recent_view), TRUE);
  gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->priv->recent_view),
  				   RECENT_DISPLAY_NAME_COLUMN);

  impl->priv->load_state = LOAD_FINISHED;
}

static gboolean
load_recent_items (gpointer user_data)
{
  GtkRecentChooserDefault *impl;
  GtkRecentInfo *info;
  GtkTreeIter iter;
  const gchar *uri, *name;
  gboolean retval;
  
  impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
  
  g_assert ((impl->priv->load_state == LOAD_EMPTY) ||
            (impl->priv->load_state == LOAD_PRELOAD));
  
  /* store the items for multiple runs */
  if (!impl->priv->recent_items)
    {
      impl->priv->recent_items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (impl));
      if (!impl->priv->recent_items)
        {
	  impl->priv->load_state = LOAD_FINISHED;
          impl->priv->load_id = 0;
          return FALSE;
        }
        
      impl->priv->n_recent_items = g_list_length (impl->priv->recent_items);
      impl->priv->loaded_items = 0;
      impl->priv->load_state = LOAD_PRELOAD;
    }
  
  info = (GtkRecentInfo *) g_list_nth_data (impl->priv->recent_items,
                                            impl->priv->loaded_items);
  g_assert (info);

  uri = gtk_recent_info_get_uri (info);
  name = gtk_recent_info_get_display_name (info);
  
  /* at this point, everything goes inside the model; operations on the
   * visualization of items inside the model are done in the cell data
   * funcs (remember that there are two of those: one for the icon and
   * one for the text), while the filtering is done only when a filter
   * is actually loaded. */
  gtk_list_store_append (impl->priv->recent_store, &iter);
  gtk_list_store_set (impl->priv->recent_store, &iter,
  		      RECENT_URI_COLUMN, uri,           /* uri  */
  		      RECENT_DISPLAY_NAME_COLUMN, name, /* display_name */
  		      RECENT_INFO_COLUMN, info,         /* info */
  		      -1);
  
  impl->priv->loaded_items += 1;

  if (impl->priv->loaded_items == impl->priv->n_recent_items)
    {
      /* we have finished loading, so we remove the items cache */
      impl->priv->load_state = LOAD_LOADING;
      
      g_list_free_full (impl->priv->recent_items, (GDestroyNotify) gtk_recent_info_unref);
      
      impl->priv->recent_items = NULL;
      impl->priv->n_recent_items = 0;
      impl->priv->loaded_items = 0;

      /* load the filled up model */
      chooser_set_model (impl);

      retval = FALSE;
      impl->priv->load_id = 0;
    }
  else
    {
      /* we did not finish, so continue loading */
      retval = TRUE;
    }
  
  return retval;
}

static void
cleanup_after_load (gpointer user_data)
{
  GtkRecentChooserDefault *impl;
  
  impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);

  if (impl->priv->load_id != 0)
    {
      g_assert ((impl->priv->load_state == LOAD_EMPTY) ||
                (impl->priv->load_state == LOAD_PRELOAD) ||
		(impl->priv->load_state == LOAD_LOADING) ||
		(impl->priv->load_state == LOAD_FINISHED));
      
      /* we have officialy finished loading all the items,
       * so we can reset the state machine
       */
      impl->priv->load_id = 0;
      impl->priv->load_state = LOAD_EMPTY;
    }
  else
    g_assert ((impl->priv->load_state == LOAD_EMPTY) ||
	      (impl->priv->load_state == LOAD_LOADING) ||
	      (impl->priv->load_state == LOAD_FINISHED));

  set_busy_cursor (impl, FALSE);
}

/* clears the current model and reloads the recently used resources */
static void
reload_recent_items (GtkRecentChooserDefault *impl)
{
  GtkWidget *widget;

  /* reload is already in progress - do not disturb */
  if (impl->priv->load_id)
    return;
  
  widget = GTK_WIDGET (impl);

  gtk_tree_view_set_model (GTK_TREE_VIEW (impl->priv->recent_view), NULL);
  gtk_list_store_clear (impl->priv->recent_store);
  
  if (!impl->priv->icon_theme)
    impl->priv->icon_theme = get_icon_theme_for_widget (widget);

  impl->priv->icon_size = get_icon_size_for_widget (widget,
		  			      GTK_ICON_SIZE_BUTTON);

  if (!impl->priv->limit_set)
    impl->priv->limit = DEFAULT_RECENT_FILES_LIMIT;

  set_busy_cursor (impl, TRUE);

  impl->priv->load_state = LOAD_EMPTY;
  impl->priv->load_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
                                             load_recent_items,
                                             impl,
                                             cleanup_after_load);
  g_source_set_name_by_id (impl->priv->load_id, "[gtk+] load_recent_items");
}

/* taken form gtkfilechooserdialog.c */
static void
set_default_size (GtkRecentChooserDefault *impl)
{
  GtkScrolledWindow *scrollw;
  GtkWidget *widget;
  gint width, height;
  double font_size;
  GdkDisplay *display;
  GdkMonitor *monitor;
  GtkRequisition req;
  GdkRectangle workarea;
  GtkStyleContext *context;

  widget = GTK_WIDGET (impl);
  context = gtk_widget_get_style_context (widget);

  /* Size based on characters and the icon size */
  gtk_style_context_get (context, gtk_style_context_get_state (context), "font-size", &font_size, NULL);

  width = impl->priv->icon_size + font_size * NUM_CHARS + 0.5;
  height = (impl->priv->icon_size + font_size) * NUM_LINES + 0.5;

  /* Use at least the requisition size... */
  gtk_widget_get_preferred_size (widget, &req, NULL);
  width = MAX (width, req.width);
  height = MAX (height, req.height);

  /* ... but no larger than the monitor */
  display = gtk_widget_get_display (widget);
  monitor = gdk_display_get_monitor_at_window (display, gtk_widget_get_window (widget));
  gdk_monitor_get_workarea (monitor, &workarea);

  width = MIN (width, workarea.width * 3 / 4);
  height = MIN (height, workarea.height * 3 / 4);

  /* Set size */
  scrollw = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (impl->priv->recent_view));
  gtk_scrolled_window_set_min_content_width (scrollw, width);
  gtk_scrolled_window_set_min_content_height (scrollw, height);
}

static void
gtk_recent_chooser_default_map (GtkWidget *widget)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (widget);

  GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map (widget);

  /* reloads everything */
  reload_recent_items (impl);

  set_default_size (impl);
}

static void
recent_icon_data_func (GtkTreeViewColumn *tree_column,
		       GtkCellRenderer   *cell,
		       GtkTreeModel      *model,
		       GtkTreeIter       *iter,
		       gpointer           user_data)
{
  GtkRecentInfo *info = NULL;
  GIcon *icon;

  gtk_tree_model_get (model, iter, RECENT_INFO_COLUMN, &info, -1);
  g_assert (info != NULL);

  icon = gtk_recent_info_get_gicon (info);
  g_object_set (cell, "gicon", icon, NULL);

  if (icon != NULL)
    g_object_unref (icon);

  gtk_recent_info_unref (info);
}

static void
recent_meta_data_func (GtkTreeViewColumn *tree_column,
		       GtkCellRenderer   *cell,
		       GtkTreeModel      *model,
		       GtkTreeIter       *iter,
		       gpointer           user_data)
{
  GtkRecentInfo *info = NULL;
  gchar *name;
  
  gtk_tree_model_get (model, iter,
                      RECENT_DISPLAY_NAME_COLUMN, &name,
                      RECENT_INFO_COLUMN, &info,
                      -1);
  g_assert (info != NULL);
  
  if (!name)
    name = gtk_recent_info_get_short_name (info);

  g_object_set (cell, "text", name, NULL);
  
  g_free (name);
  gtk_recent_info_unref (info);
}


static gchar *
gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
  
  g_assert (impl->priv->selection != NULL);
  
  if (!impl->priv->select_multiple)
    {
      GtkTreeModel *model;
      GtkTreeIter iter;
      gchar *uri = NULL;
      
      if (!gtk_tree_selection_get_selected (impl->priv->selection, &model, &iter))
        return NULL;
      
      gtk_tree_model_get (model, &iter, RECENT_URI_COLUMN, &uri, -1);
      
      return uri;
    }
  
  return NULL;
}

typedef struct
{
  guint found : 1;
  guint do_select : 1;
  guint do_activate : 1;
  
  gchar *uri;
  
  GtkRecentChooserDefault *impl;
} SelectURIData;

static gboolean
scan_for_uri_cb (GtkTreeModel *model,
		 GtkTreePath  *path,
		 GtkTreeIter  *iter,
		 gpointer      user_data)
{
  SelectURIData *select_data = (SelectURIData *) user_data;
  gchar *uri = NULL;
  
  if (!select_data)
    return TRUE;
  
  if (select_data->found)
    return TRUE;
  
  gtk_tree_model_get (model, iter, RECENT_URI_COLUMN, &uri, -1);
  if (!uri)
    return FALSE;
  
  if (strcmp (uri, select_data->uri) == 0)
    {
      select_data->found = TRUE;
      
      if (select_data->do_activate)
        gtk_tree_view_row_activated (GTK_TREE_VIEW (select_data->impl->priv->recent_view),
        			     path,
        			     select_data->impl->priv->meta_column);
      
      if (select_data->do_select)
        gtk_tree_selection_select_path (select_data->impl->priv->selection, path);
      else
        gtk_tree_selection_unselect_path (select_data->impl->priv->selection, path);

      g_free (uri);
      
      return TRUE;
    }

  g_free (uri);
  
  return FALSE;
}

static gboolean
gtk_recent_chooser_default_set_current_uri (GtkRecentChooser  *chooser,
					    const gchar       *uri,
					    GError           **error)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
  SelectURIData *data;
  
  data = g_new0 (SelectURIData, 1);
  data->uri = g_strdup (uri);
  data->impl = impl;
  data->found = FALSE;
  data->do_activate = TRUE;
  data->do_select = TRUE;
  
  gtk_tree_model_foreach (GTK_TREE_MODEL (impl->priv->recent_store),
  			  scan_for_uri_cb,
  			  data);
  
  if (!data->found)
    {
      g_free (data->uri);
      g_free (data);
      
      g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
      		   GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
      		   _("No item for URI '%s' found"),
      		   uri);
      return FALSE;
    }
  
  g_free (data->uri);
  g_free (data);

  return TRUE;
}

static gboolean
gtk_recent_chooser_default_select_uri (GtkRecentChooser  *chooser,
				       const gchar       *uri,
				       GError           **error)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
  SelectURIData *data;
  
  data = g_new0 (SelectURIData, 1);
  data->uri = g_strdup (uri);
  data->impl = impl;
  data->found = FALSE;
  data->do_activate = FALSE;
  data->do_select = TRUE;
  
  gtk_tree_model_foreach (GTK_TREE_MODEL (impl->priv->recent_store),
  			  scan_for_uri_cb,
  			  data);
  
  if (!data->found)
    {
      g_free (data->uri);
      g_free (data);
      
      g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
      		   GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
      		   _("No item for URI '%s' found"),
      		   uri);
      return FALSE;
    }
  
  g_free (data->uri);
  g_free (data);

  return TRUE;
}

static void
gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
					 const gchar      *uri)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
  SelectURIData *data;
  
  data = g_new0 (SelectURIData, 1);
  data->uri = g_strdup (uri);
  data->impl = impl;
  data->found = FALSE;
  data->do_activate = FALSE;
  data->do_select = FALSE;
  
  gtk_tree_model_foreach (GTK_TREE_MODEL (impl->priv->recent_store),
  			  scan_for_uri_cb,
  			  data);
  
  g_free (data->uri);
  g_free (data);
}

static void
gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
  
  if (!impl->priv->select_multiple)
    return;
  
  gtk_tree_selection_select_all (impl->priv->selection);
}

static void
gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
  
  gtk_tree_selection_unselect_all (impl->priv->selection);
}

static void
gtk_recent_chooser_default_set_sort_func (GtkRecentChooser  *chooser,
					  GtkRecentSortFunc  sort_func,
					  gpointer           sort_data,
					  GDestroyNotify     data_destroy)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
  
  if (impl->priv->sort_data_destroy)
    {
      impl->priv->sort_data_destroy (impl->priv->sort_data);
      impl->priv->sort_data_destroy = NULL;
    }
      
  impl->priv->sort_func = NULL;
  impl->priv->sort_data = NULL;
  
  if (sort_func)
    {
      impl->priv->sort_func = sort_func;
      impl->priv->sort_data = sort_data;
      impl->priv->sort_data_destroy = data_destroy;
    }
}

static GList *
gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser)
{
  GtkRecentChooserDefault *impl;

  impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);

  return _gtk_recent_chooser_get_items (chooser,
                                        impl->priv->current_filter,
                                        impl->priv->sort_func,
                                        impl->priv->sort_data);
}

static GtkRecentManager *
gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser)
{
  return GTK_RECENT_CHOOSER_DEFAULT (chooser)->priv->manager;
}

static void
show_filters (GtkRecentChooserDefault *impl,
              gboolean                 show)
{
  if (show)
    gtk_widget_show (impl->priv->filter_combo_hbox);
  else
    gtk_widget_hide (impl->priv->filter_combo_hbox);
}

static void
gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
				       GtkRecentFilter  *filter)
{
  GtkRecentChooserDefault *impl;
  const gchar *name;

  impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
  
  if (g_slist_find (impl->priv->filters, filter))
    {
      g_warning ("gtk_recent_chooser_add_filter() called on filter already in list");
      return;
    }
  
  g_object_ref_sink (filter);
  impl->priv->filters = g_slist_append (impl->priv->filters, filter);
  
  /* display new filter */
  name = gtk_recent_filter_get_name (filter);
  if (!name)
    name = _("Untitled filter");

  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (impl->priv->filter_combo), name);

  if (!g_slist_find (impl->priv->filters, impl->priv->current_filter))
    set_current_filter (impl, filter);
  
  show_filters (impl, TRUE);
}

static void
gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
					  GtkRecentFilter  *filter)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
  GtkTreeModel *model;
  GtkTreeIter iter;
  gint filter_idx;
  
  filter_idx = g_slist_index (impl->priv->filters, filter);
  
  if (filter_idx < 0)
    {
      g_warning ("gtk_recent_chooser_remove_filter() called on filter not in list");
      return;  
    }
  
  impl->priv->filters = g_slist_remove (impl->priv->filters, filter);
  
  if (filter == impl->priv->current_filter)
    {
      if (impl->priv->filters)
        set_current_filter (impl, impl->priv->filters->data);
      else
        set_current_filter (impl, NULL);
    }
  
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->priv->filter_combo));
  gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_idx);
  gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
  
  g_object_unref (filter);
  
  if (!impl->priv->filters)
    show_filters (impl, FALSE);
}

static GSList *
gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
  
  return g_slist_copy (impl->priv->filters);
}

static void
set_current_filter (GtkRecentChooserDefault *impl,
		    GtkRecentFilter         *filter)
{
  if (impl->priv->current_filter != filter)
    {
      gint filter_idx;
      
      filter_idx = g_slist_index (impl->priv->filters, filter);
      if (impl->priv->filters && filter && filter_idx < 0)
        return;
      
      if (impl->priv->current_filter)
        g_object_unref (impl->priv->current_filter);
      
      impl->priv->current_filter = filter;
      
      if (impl->priv->current_filter)     
        {
          g_object_ref_sink (impl->priv->current_filter);
        }
      
      if (impl->priv->filters)
        gtk_combo_box_set_active (GTK_COMBO_BOX (impl->priv->filter_combo),
                                  filter_idx);
      
      if (impl->priv->recent_store)
        reload_recent_items (impl);

      g_object_notify (G_OBJECT (impl), "filter");
    }
}

static void
chooser_set_sort_type (GtkRecentChooserDefault *impl,
		       GtkRecentSortType        sort_type)
{
  if (impl->priv->sort_type != sort_type)
    {
      impl->priv->sort_type = sort_type;
      reload_recent_items (impl);
      g_object_notify (G_OBJECT (impl), "sort-type");
    }
}


static GtkIconTheme *
get_icon_theme_for_widget (GtkWidget *widget)
{
  return gtk_css_icon_theme_value_get_icon_theme
    (_gtk_style_context_peek_property (gtk_widget_get_style_context (widget),
                                       GTK_CSS_PROPERTY_ICON_THEME));
}

static gint
get_icon_size_for_widget (GtkWidget   *widget,
			  GtkIconSize  icon_size)
{
  gint width, height;

  if (gtk_icon_size_lookup (icon_size, &width, &height))
    return MAX (width, height);

  return FALLBACK_ICON_SIZE;
}

static void
recent_manager_changed_cb (GtkRecentManager *manager,
			   gpointer          user_data)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);

  reload_recent_items (impl);
}

static void
selection_changed_cb (GtkTreeSelection *selection,
		      gpointer          user_data)
{
  _gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
}

static void
row_activated_cb (GtkTreeView       *tree_view,
		  GtkTreePath       *tree_path,
		  GtkTreeViewColumn *tree_column,
		  gpointer           user_data)
{
  _gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
}

static void
filter_combo_changed_cb (GtkComboBox *combo_box,
			 gpointer     user_data)
{
  GtkRecentChooserDefault *impl;
  gint new_index;
  GtkRecentFilter *filter;
  
  impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
  
  new_index = gtk_combo_box_get_active (combo_box);
  filter = g_slist_nth_data (impl->priv->filters, new_index);
  
  set_current_filter (impl, filter);
}

static GdkPixbuf *
get_drag_pixbuf (GtkRecentChooserDefault *impl)
{
  GtkRecentInfo *info;
  GdkPixbuf *retval;
  gint size;
  
  g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));

  info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
  if (!info)
    return NULL;

  size = get_icon_size_for_widget (GTK_WIDGET (impl), GTK_ICON_SIZE_DND);

  retval = gtk_recent_info_get_icon (info, size);
  gtk_recent_info_unref (info);

  return retval;
}

static void
recent_view_drag_begin_cb (GtkWidget      *widget,
			   GdkDragContext *context,
			   gpointer        user_data)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
  GdkPixbuf *pixbuf;

  pixbuf = get_drag_pixbuf (impl);
  if (pixbuf)
    {
      gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
      g_object_unref (pixbuf);
    }
  else
    gtk_drag_set_icon_default (context);
}

typedef struct
{
  gchar **uri_list;
  gsize next_pos;
} DragData;

static void
append_uri_to_urilist (GtkTreeModel *model,
		       GtkTreePath  *path,
		       GtkTreeIter  *iter,
		       gpointer      user_data)
{
  DragData *drag_data = (DragData *) user_data;
  gchar *uri = NULL;
  gsize pos;

  gtk_tree_model_get (model, iter,
  		      RECENT_URI_COLUMN, &uri,
  		      -1);
  g_assert (uri != NULL);

  pos = drag_data->next_pos;
  drag_data->uri_list[pos] = g_strdup (uri);
  drag_data->next_pos = pos + 1;
}

static void
recent_view_drag_data_get_cb (GtkWidget        *widget,
			      GdkDragContext   *context,
			      GtkSelectionData *selection_data,
			      guint             info,
			      guint32           time_,
			      gpointer          data)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (data);
  DragData drag_data;
  gsize n_uris;
  
  n_uris = gtk_tree_selection_count_selected_rows (impl->priv->selection);
  if (n_uris == 0)
    return;

  drag_data.uri_list = g_new0 (gchar *, n_uris + 1);
  drag_data.next_pos = 0;
  
  gtk_tree_selection_selected_foreach (impl->priv->selection,
      				       append_uri_to_urilist,
      				       &drag_data);
  
  gtk_selection_data_set_uris (selection_data, drag_data.uri_list);

  g_strfreev (drag_data.uri_list);
}

static gboolean
recent_view_query_tooltip_cb (GtkWidget  *widget,
                              gint        x,
                              gint        y,
                              gboolean    keyboard_tip,
                              GtkTooltip *tooltip,
                              gpointer    user_data)
{
  GtkRecentChooserDefault *impl = user_data;
  GtkTreeView *tree_view;
  GtkTreeIter iter;
  GtkTreePath *path = NULL;
  GtkRecentInfo *info = NULL;
  gchar *uri_display;

  if (!impl->priv->show_tips)
    return FALSE;

  tree_view = GTK_TREE_VIEW (impl->priv->recent_view);

  gtk_tree_view_get_tooltip_context (tree_view,
                                     &x, &y,
                                     keyboard_tip,
                                     NULL, &path, NULL);
  if (!path)
    return FALSE;

  if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->priv->recent_store), &iter, path))
    {
      gtk_tree_path_free (path);
      return FALSE;
    }

  gtk_tree_model_get (GTK_TREE_MODEL (impl->priv->recent_store), &iter,
                      RECENT_INFO_COLUMN, &info,
                      -1);

  uri_display = gtk_recent_info_get_uri_display (info);
  
  gtk_tooltip_set_text (tooltip, uri_display);
  gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);

  g_free (uri_display);
  gtk_tree_path_free (path);
  gtk_recent_info_unref (info);

  return TRUE;
}

static void
remove_selected_from_list (GtkRecentChooserDefault *impl)
{
  gchar *uri;
  GError *err;
  
  if (impl->priv->select_multiple)
    return;
  
  uri = gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (impl));
  if (!uri)
    return;
  
  err = NULL;
  if (!gtk_recent_manager_remove_item (impl->priv->manager, uri, &err))
    {
      gchar *msg;
   
      msg = g_strdup (_("Could not remove item"));
      error_message (impl, msg, err->message);
      
      g_free (msg);
      g_error_free (err);
    }
  
  g_free (uri);
}

static void
copy_activated_cb (GtkMenuItem *menu_item,
		   gpointer     user_data)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
  GtkRecentInfo *info;
  gchar *utf8_uri;

  info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
  if (!info)
    return;

  utf8_uri = gtk_recent_info_get_uri_display (info);
  
  gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (impl),
			  			    GDK_SELECTION_CLIPBOARD),
                          utf8_uri, -1);

  gtk_recent_info_unref (info);
  g_free (utf8_uri);
}

static void
remove_all_activated_cb (GtkMenuItem *menu_item,
			 gpointer     user_data)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
  GError *err = NULL;
  
  gtk_recent_manager_purge_items (impl->priv->manager, &err);
  if (err)
    {
       gchar *msg;

       msg = g_strdup (_("Could not clear list"));

       error_message (impl, msg, err->message);
       
       g_free (msg);
       g_error_free (err);
    }
}

static void
remove_item_activated_cb (GtkMenuItem *menu_item,
			  gpointer     user_data)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
  
  remove_selected_from_list (impl);
}

static void
show_private_toggled_cb (GtkCheckMenuItem *menu_item,
			 gpointer          user_data)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
  
  g_object_set (G_OBJECT (impl),
  		"show-private", gtk_check_menu_item_get_active (menu_item),
  		NULL);
}

static void
recent_popup_menu_detach_cb (GtkWidget *attach_widget,
			     GtkMenu   *menu)
{
  GtkRecentChooserDefault *impl;
  
  impl = g_object_get_data (G_OBJECT (attach_widget), "GtkRecentChooserDefault");
  g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
  
  impl->priv->recent_popup_menu = NULL;
  impl->priv->recent_popup_menu_remove_item = NULL;
  impl->priv->recent_popup_menu_copy_item = NULL;
  impl->priv->recent_popup_menu_clear_item = NULL;
  impl->priv->recent_popup_menu_show_private_item = NULL;
}

static void
recent_view_menu_ensure_state (GtkRecentChooserDefault *impl)
{
  gint count;
  
  g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
  g_assert (impl->priv->recent_popup_menu != NULL);

  if (!impl->priv->manager)
    count = 0;
  else
    g_object_get (G_OBJECT (impl->priv->manager), "size", &count, NULL);

  if (count == 0)
    {
      gtk_widget_set_sensitive (impl->priv->recent_popup_menu_remove_item, FALSE);
      gtk_widget_set_sensitive (impl->priv->recent_popup_menu_copy_item, FALSE);
      gtk_widget_set_sensitive (impl->priv->recent_popup_menu_clear_item, FALSE);
      gtk_widget_set_sensitive (impl->priv->recent_popup_menu_show_private_item, FALSE);
    }
}

static void
recent_view_menu_build (GtkRecentChooserDefault *impl)
{
  GtkWidget *item;
  
  if (impl->priv->recent_popup_menu)
    {
      recent_view_menu_ensure_state (impl);
      
      return;
    }
  
  impl->priv->recent_popup_menu = gtk_menu_new ();
  gtk_menu_attach_to_widget (GTK_MENU (impl->priv->recent_popup_menu),
  			     impl->priv->recent_view,
  			     recent_popup_menu_detach_cb);
  
  item = gtk_menu_item_new_with_mnemonic (_("Copy _Location"));
  impl->priv->recent_popup_menu_copy_item = item;
  g_signal_connect (item, "activate",
		    G_CALLBACK (copy_activated_cb), impl);
  gtk_widget_show (item);
  gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);

  item = gtk_separator_menu_item_new ();
  gtk_widget_show (item);
  gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
  
  item = gtk_menu_item_new_with_mnemonic (_("_Remove From List"));
  impl->priv->recent_popup_menu_remove_item = item;
  g_signal_connect (item, "activate",
  		    G_CALLBACK (remove_item_activated_cb), impl);
  gtk_widget_show (item);
  gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);

  item = gtk_menu_item_new_with_mnemonic (_("_Clear List"));
  impl->priv->recent_popup_menu_clear_item = item;
  g_signal_connect (item, "activate",
		    G_CALLBACK (remove_all_activated_cb), impl);
  
  gtk_widget_show (item);
  gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
  
  item = gtk_separator_menu_item_new ();
  gtk_widget_show (item);
  gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
  
  item = gtk_check_menu_item_new_with_mnemonic (_("Show _Private Resources"));
  impl->priv->recent_popup_menu_show_private_item = item;
  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), impl->priv->show_private);
  g_signal_connect (item, "toggled",
  		    G_CALLBACK (show_private_toggled_cb), impl);
  gtk_widget_show (item);
  gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
  
  recent_view_menu_ensure_state (impl);
}

static void
recent_view_menu_popup (GtkRecentChooserDefault *impl,
			GdkEventButton          *event)
{
  recent_view_menu_build (impl);
  
  if (event && gdk_event_triggers_context_menu ((GdkEvent *) event))
    gtk_menu_popup_at_pointer (GTK_MENU (impl->priv->recent_popup_menu), (GdkEvent *) event);
  else
    {
      gtk_menu_popup_at_widget (GTK_MENU (impl->priv->recent_popup_menu),
                                impl->priv->recent_view,
                                GDK_GRAVITY_CENTER,
                                GDK_GRAVITY_CENTER,
                                (GdkEvent *) event);

      gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->priv->recent_popup_menu), FALSE);
    }
}

static gboolean
recent_view_popup_menu_cb (GtkWidget *widget,
			   gpointer   user_data)
{
  recent_view_menu_popup (GTK_RECENT_CHOOSER_DEFAULT (user_data), NULL);
  return TRUE;
}

static gboolean
recent_view_button_press_cb (GtkWidget      *widget,
			     GdkEventButton *event,
			     gpointer        user_data)
{
  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);

  if (gdk_event_triggers_context_menu ((GdkEvent *) event))
    {
      GtkTreePath *path;
      gboolean res;

      if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (impl->priv->recent_view)))
        return FALSE;

      res = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (impl->priv->recent_view),
		      			   event->x, event->y,
					   &path,
					   NULL, NULL, NULL);
      if (!res)
        return FALSE;

      /* select the path before creating the popup menu */
      gtk_tree_selection_select_path (impl->priv->selection, path);
      gtk_tree_path_free (path);
      
      recent_view_menu_popup (impl, event);

      return TRUE;
    }
  
  return FALSE;
}

static void
set_recent_manager (GtkRecentChooserDefault *impl,
		    GtkRecentManager        *manager)
{
  if (impl->priv->manager)
    {
      if (impl->priv->manager_changed_id)
        {
          g_signal_handler_disconnect (impl, impl->priv->manager_changed_id);
          impl->priv->manager_changed_id = 0;
        }

      impl->priv->manager = NULL;
    }
  
  if (manager)
    impl->priv->manager = manager;
  else
    impl->priv->manager = gtk_recent_manager_get_default ();
  
  if (impl->priv->manager)
    {
      impl->priv->manager_changed_id = g_signal_connect (impl->priv->manager, "changed",
							 G_CALLBACK (recent_manager_changed_cb),
							 impl);
    }
}

static void
gtk_recent_chooser_update (GtkActivatable *activatable,
			   GtkAction      *action,
			   const gchar    *property_name)
{
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
  if (strcmp (property_name, "visible") == 0)
    {
      if (gtk_action_is_visible (action))
	gtk_widget_show (GTK_WIDGET (activatable));
      else
	gtk_widget_hide (GTK_WIDGET (activatable));
    }

  if (strcmp (property_name, "sensitive") == 0)
    gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));

  G_GNUC_END_IGNORE_DEPRECATIONS;

  _gtk_recent_chooser_update (activatable, action, property_name);
}


static void 
gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
				           GtkAction      *action)
{
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
  if (action)
    {
      if (gtk_action_is_visible (action))
	gtk_widget_show (GTK_WIDGET (activatable));
      else
	gtk_widget_hide (GTK_WIDGET (activatable));
      
      gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
    }
  G_GNUC_END_IGNORE_DEPRECATIONS;

  _gtk_recent_chooser_sync_action_properties (activatable, action);
}


GtkWidget *
_gtk_recent_chooser_default_new (GtkRecentManager *manager)
{
  return g_object_new (GTK_TYPE_RECENT_CHOOSER_DEFAULT,
  		       "recent-manager", manager,
  		       NULL);
}