summaryrefslogtreecommitdiff
path: root/thunar/thunar-launcher.c
blob: 20789fe7c9f5402458aeba47e86eaf0540b2b3ba (plain)
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
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
 * Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org>
 * Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * 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 General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

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

#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif

#include <thunar/thunar-application.h>
#include <thunar/thunar-browser.h>
#include <thunar/thunar-chooser-dialog.h>
#include <thunar/thunar-dialogs.h>
#include <thunar/thunar-file-monitor.h>
#include <thunar/thunar-gio-extensions.h>
#include <thunar/thunar-gobject-extensions.h>
#include <thunar/thunar-gtk-extensions.h>
#include <thunar/thunar-launcher.h>
#include <thunar/thunar-launcher-ui.h>
#include <thunar/thunar-private.h>
#include <thunar/thunar-sendto-model.h>
#include <thunar/thunar-device-monitor.h>
#include <thunar/thunar-util.h>
#include <thunar/thunar-window.h>



typedef struct _ThunarLauncherMountData ThunarLauncherMountData;
typedef struct _ThunarLauncherPokeData ThunarLauncherPokeData;



/* Property identifiers */
enum
{
  PROP_0,
  PROP_CURRENT_DIRECTORY,
  PROP_SELECTED_FILES,
  PROP_UI_MANAGER,
  PROP_WIDGET,
  N_PROPERTIES
};



static void                    thunar_launcher_component_init             (ThunarComponentIface     *iface);
static void                    thunar_launcher_navigator_init             (ThunarNavigatorIface     *iface);
static void                    thunar_launcher_dispose                    (GObject                  *object);
static void                    thunar_launcher_finalize                   (GObject                  *object);
static void                    thunar_launcher_get_property               (GObject                  *object,
                                                                           guint                     prop_id,
                                                                           GValue                   *value,
                                                                           GParamSpec               *pspec);
static void                    thunar_launcher_set_property               (GObject                  *object,
                                                                           guint                     prop_id,
                                                                           const GValue             *value,
                                                                           GParamSpec               *pspec);
static ThunarFile             *thunar_launcher_get_current_directory      (ThunarNavigator          *navigator);
static void                    thunar_launcher_set_current_directory      (ThunarNavigator          *navigator,
                                                                           ThunarFile               *current_directory);
static GList                  *thunar_launcher_get_selected_files         (ThunarComponent          *component);
static void                    thunar_launcher_set_selected_files         (ThunarComponent          *component,
                                                                           GList                    *selected_files);
static GtkUIManager           *thunar_launcher_get_ui_manager             (ThunarComponent          *component);
static void                    thunar_launcher_set_ui_manager             (ThunarComponent          *component,
                                                                           GtkUIManager             *ui_manager);
static void                    thunar_launcher_execute_files              (ThunarLauncher           *launcher,
                                                                           GList                    *files);
static void                    thunar_launcher_open_files                 (ThunarLauncher           *launcher,
                                                                           GList                    *files);
static void                    thunar_launcher_open_paths                 (GAppInfo                 *app_info,
                                                                           GList                    *file_list,
                                                                           ThunarLauncher           *launcher);
static void                    thunar_launcher_open_windows               (ThunarLauncher           *launcher,
                                                                           GList                    *directories);
static void                    thunar_launcher_update                     (ThunarLauncher           *launcher);
static void                    thunar_launcher_action_open                (GtkAction                *action,
                                                                           ThunarLauncher           *launcher);
static void                    thunar_launcher_action_open_with_other     (GtkAction                *action,
                                                                           ThunarLauncher           *launcher);
static void                    thunar_launcher_action_open_in_new_window  (GtkAction                *action,
                                                                           ThunarLauncher           *launcher);
static void                    thunar_launcher_action_open_in_new_tab     (GtkAction                *action,
                                                                           ThunarLauncher           *launcher);
static void                    thunar_launcher_action_sendto_desktop      (GtkAction                *action,
                                                                           ThunarLauncher           *launcher);
static void                    thunar_launcher_action_sendto_device       (GtkAction                *action,
                                                                           ThunarLauncher           *launcher);
static void                    thunar_launcher_widget_destroyed           (ThunarLauncher           *launcher,
                                                                           GtkWidget                *widget);
static gboolean                thunar_launcher_sendto_idle                (gpointer                  user_data);
static void                    thunar_launcher_sendto_idle_destroy        (gpointer                  user_data);
static void                    thunar_launcher_mount_data_free            (ThunarLauncherMountData  *data);
static void                    thunar_launcher_poke_files                 (ThunarLauncher           *launcher,
                                                                           ThunarLauncherPokeData   *poke_data);
static void                    thunar_launcher_poke_files_finish          (ThunarBrowser            *browser,
                                                                           ThunarFile               *file,
                                                                           ThunarFile               *target_file,
                                                                           GError                   *error,
                                                                           gpointer                  user_data);
static ThunarLauncherPokeData *thunar_launcher_poke_data_new              (GList                    *files);
static void                    thunar_launcher_poke_data_free             (ThunarLauncherPokeData   *data);
static GtkWidget              *thunar_launcher_get_widget                 (const ThunarLauncher     *launcher);


struct _ThunarLauncherClass
{
  GObjectClass __parent__;
};

struct _ThunarLauncher
{
  GObject __parent__;

  ThunarFile             *current_directory;
  GList                  *selected_files;

  guint                   launcher_idle_id;

  GtkActionGroup         *action_group;
  GtkUIManager           *ui_manager;
  guint                   ui_merge_id;
  guint                   ui_addons_merge_id;

  GtkAction              *action_open;
  GtkAction              *action_open_with_other;
  GtkAction              *action_open_in_new_window;
  GtkAction              *action_open_in_new_tab;
  GtkAction              *action_open_with_other_in_menu;

  GtkWidget              *widget;

  ThunarDeviceMonitor    *device_monitor;
  ThunarSendtoModel      *sendto_model;
  guint                   sendto_idle_id;

  ThunarFileMonitor      *file_monitor;
};

struct _ThunarLauncherMountData
{
  ThunarLauncher *launcher;
  GList          *files;
};

struct _ThunarLauncherPokeData
{
  GList *files;
  GList *resolved_files;
  guint  directories_in_tabs : 1;
};



static const GtkActionEntry action_entries[] =
{
  { "open", "document-open", N_ ("_Open"), "<control>O", NULL, G_CALLBACK (thunar_launcher_action_open), },
  { "open-in-new-tab", NULL, N_ ("Open in New _Tab"), "<control><shift>P", NULL, G_CALLBACK (thunar_launcher_action_open_in_new_tab), },
  { "open-in-new-window", NULL, N_ ("Open in New _Window"), "<control><shift>O", NULL, G_CALLBACK (thunar_launcher_action_open_in_new_window), },
  { "open-with-other", NULL, N_ ("Open With Other _Application..."), NULL, N_ ("Choose another application with which to open the selected file"), G_CALLBACK (thunar_launcher_action_open_with_other), },
  { "open-with-menu", NULL, N_ ("Open With"), NULL, NULL, NULL, },
  { "open-with-other-in-menu", NULL, N_ ("Open With Other _Application..."), NULL, N_ ("Choose another application with which to open the selected file"), G_CALLBACK (thunar_launcher_action_open_with_other), },
  { "sendto-desktop", "user-desktop", "", NULL, NULL, G_CALLBACK (thunar_launcher_action_sendto_desktop), },
};

static GQuark thunar_launcher_handler_quark;



static GParamSpec *launcher_props[N_PROPERTIES] = { NULL, };



G_DEFINE_TYPE_WITH_CODE (ThunarLauncher, thunar_launcher, G_TYPE_OBJECT,
    G_IMPLEMENT_INTERFACE (THUNAR_TYPE_BROWSER, NULL)
    G_IMPLEMENT_INTERFACE (THUNAR_TYPE_NAVIGATOR, thunar_launcher_navigator_init)
    G_IMPLEMENT_INTERFACE (THUNAR_TYPE_COMPONENT, thunar_launcher_component_init))



static void
thunar_launcher_class_init (ThunarLauncherClass *klass)
{
  GObjectClass *gobject_class;
  gpointer      g_iface;

  /* determine the "thunar-launcher-handler" quark */
  thunar_launcher_handler_quark = g_quark_from_static_string ("thunar-launcher-handler");

  gobject_class = G_OBJECT_CLASS (klass);
  gobject_class->dispose = thunar_launcher_dispose;
  gobject_class->finalize = thunar_launcher_finalize;
  gobject_class->get_property = thunar_launcher_get_property;
  gobject_class->set_property = thunar_launcher_set_property;

  /**
   * ThunarLauncher:widget:
   *
   * The #GtkWidget with which this launcher is associated.
   **/
  launcher_props[PROP_WIDGET] =
      g_param_spec_object ("widget",
                           "widget",
                           "widget",
                           GTK_TYPE_WIDGET,
                           EXO_PARAM_READWRITE);

  /* Override ThunarNavigator's properties */
  g_iface = g_type_default_interface_peek (THUNAR_TYPE_NAVIGATOR);
  launcher_props[PROP_CURRENT_DIRECTORY] =
      g_param_spec_override ("current-directory",
                             g_object_interface_find_property (g_iface, "current-directory"));

  /* Override ThunarComponent's properties */
  g_iface = g_type_default_interface_peek (THUNAR_TYPE_COMPONENT);
  launcher_props[PROP_SELECTED_FILES] =
      g_param_spec_override ("selected-files",
                             g_object_interface_find_property (g_iface, "selected-files"));

  launcher_props[PROP_UI_MANAGER] =
      g_param_spec_override ("ui-manager",
                             g_object_interface_find_property (g_iface, "ui-manager"));

  /* install properties */
  g_object_class_install_properties (gobject_class, N_PROPERTIES, launcher_props);
}



static void
thunar_launcher_component_init (ThunarComponentIface *iface)
{
  iface->get_selected_files = thunar_launcher_get_selected_files;
  iface->set_selected_files = thunar_launcher_set_selected_files;
  iface->get_ui_manager = thunar_launcher_get_ui_manager;
  iface->set_ui_manager = thunar_launcher_set_ui_manager;
}



static void
thunar_launcher_navigator_init (ThunarNavigatorIface *iface)
{
  iface->get_current_directory = thunar_launcher_get_current_directory;
  iface->set_current_directory = thunar_launcher_set_current_directory;
}



static void
thunar_launcher_init (ThunarLauncher *launcher)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  /* setup the action group for the launcher actions */
  launcher->action_group = gtk_action_group_new ("ThunarLauncher");
  gtk_action_group_set_translation_domain (launcher->action_group, GETTEXT_PACKAGE);
  gtk_action_group_add_actions (launcher->action_group, action_entries, G_N_ELEMENTS (action_entries), launcher);

  /* determine references to our actions */
  launcher->action_open = gtk_action_group_get_action (launcher->action_group, "open");
  launcher->action_open_with_other = gtk_action_group_get_action (launcher->action_group, "open-with-other");
  launcher->action_open_in_new_window = gtk_action_group_get_action (launcher->action_group, "open-in-new-window");
  launcher->action_open_in_new_tab = gtk_action_group_get_action (launcher->action_group, "open-in-new-tab");
  launcher->action_open_with_other_in_menu = gtk_action_group_get_action (launcher->action_group, "open-with-other-in-menu");
G_GNUC_END_IGNORE_DEPRECATIONS

  /* setup the "Send To" support */
  launcher->sendto_model = thunar_sendto_model_get_default ();

  /* the "Send To" menu also displays removable devices from the device monitor */
  launcher->device_monitor = thunar_device_monitor_get ();
  g_signal_connect_swapped (launcher->device_monitor, "device-added", G_CALLBACK (thunar_launcher_update), launcher);
  g_signal_connect_swapped (launcher->device_monitor, "device-removed", G_CALLBACK (thunar_launcher_update), launcher);

  /* update launcher actions when any monitored file changes */
  launcher->file_monitor = thunar_file_monitor_get_default ();
  g_signal_connect_swapped (launcher->file_monitor, "file-changed", G_CALLBACK (thunar_launcher_update), launcher);
}



static void
thunar_launcher_dispose (GObject *object)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (object);

  /* reset our properties */
  thunar_navigator_set_current_directory (THUNAR_NAVIGATOR (launcher), NULL);
  thunar_component_set_ui_manager (THUNAR_COMPONENT (launcher), NULL);
  thunar_launcher_set_widget (THUNAR_LAUNCHER (launcher), NULL);

  /* disconnect from the currently selected files */
  thunar_g_file_list_free (launcher->selected_files);
  launcher->selected_files = NULL;

  (*G_OBJECT_CLASS (thunar_launcher_parent_class)->dispose) (object);
}



static void
thunar_launcher_finalize (GObject *object)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (object);

  /* be sure to cancel the sendto idle source */
  if (G_UNLIKELY (launcher->sendto_idle_id != 0))
    g_source_remove (launcher->sendto_idle_id);

  /* be sure to cancel the launcher idle source */
  if (G_UNLIKELY (launcher->launcher_idle_id != 0))
    g_source_remove (launcher->launcher_idle_id);

  /* release the reference on the action group */
  g_object_unref (launcher->action_group);

  /* disconnect from the device monitor used for the "Send To" menu */
  g_signal_handlers_disconnect_by_func (launcher->device_monitor, thunar_launcher_update, launcher);
  g_object_unref (launcher->device_monitor);

  /* release the reference on the sendto model */
  g_object_unref (launcher->sendto_model);

  /* disconnect from the file monitor */
  g_signal_handlers_disconnect_by_func (launcher->file_monitor, thunar_launcher_update, launcher);
  g_object_unref (launcher->file_monitor);

  (*G_OBJECT_CLASS (thunar_launcher_parent_class)->finalize) (object);
}



static void
thunar_launcher_get_property (GObject    *object,
                              guint       prop_id,
                              GValue     *value,
                              GParamSpec *pspec)
{
  switch (prop_id)
    {
    case PROP_CURRENT_DIRECTORY:
      g_value_set_object (value, thunar_navigator_get_current_directory (THUNAR_NAVIGATOR (object)));
      break;

    case PROP_SELECTED_FILES:
      g_value_set_boxed (value, thunar_component_get_selected_files (THUNAR_COMPONENT (object)));
      break;

    case PROP_UI_MANAGER:
      g_value_set_object (value, thunar_component_get_ui_manager (THUNAR_COMPONENT (object)));
      break;

    case PROP_WIDGET:
      g_value_set_object (value, thunar_launcher_get_widget (THUNAR_LAUNCHER (object)));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}



static void
thunar_launcher_set_property (GObject      *object,
                              guint         prop_id,
                              const GValue *value,
                              GParamSpec   *pspec)
{
  switch (prop_id)
    {
    case PROP_CURRENT_DIRECTORY:
      thunar_navigator_set_current_directory (THUNAR_NAVIGATOR (object), g_value_get_object (value));
      break;

    case PROP_SELECTED_FILES:
      thunar_component_set_selected_files (THUNAR_COMPONENT (object), g_value_get_boxed (value));
      break;

    case PROP_UI_MANAGER:
      thunar_component_set_ui_manager (THUNAR_COMPONENT (object), g_value_get_object (value));
      break;

    case PROP_WIDGET:
      thunar_launcher_set_widget (THUNAR_LAUNCHER (object), g_value_get_object (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}



static ThunarFile*
thunar_launcher_get_current_directory (ThunarNavigator *navigator)
{
  return THUNAR_LAUNCHER (navigator)->current_directory;
}



static void
thunar_launcher_set_current_directory (ThunarNavigator *navigator,
                                       ThunarFile      *current_directory)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (navigator);

  /* disconnect from the previous directory */
  if (G_LIKELY (launcher->current_directory != NULL))
    g_object_unref (G_OBJECT (launcher->current_directory));

  /* activate the new directory */
  launcher->current_directory = current_directory;

  /* connect to the new directory */
  if (G_LIKELY (current_directory != NULL))
    g_object_ref (G_OBJECT (current_directory));

  /* notify listeners */
  g_object_notify_by_pspec (G_OBJECT (launcher), launcher_props[PROP_CURRENT_DIRECTORY]);
}



static GList*
thunar_launcher_get_selected_files (ThunarComponent *component)
{
  return THUNAR_LAUNCHER (component)->selected_files;
}



static void
thunar_launcher_set_selected_files (ThunarComponent *component,
                                    GList           *selected_files)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (component);
  GList          *np;
  GList          *op;

  /* compare the old and the new list of selected files */
  for (np = selected_files, op = launcher->selected_files; np != NULL && op != NULL; np = np->next, op = op->next)
    if (G_UNLIKELY (np->data != op->data))
      break;

  /* check if the list of selected files really changed */
  if (G_UNLIKELY (np != NULL || op != NULL))
    {
      /* disconnect from the previously selected files */
      thunar_g_file_list_free (launcher->selected_files);

      /* connect to the new selected files list */
      launcher->selected_files = thunar_g_file_list_copy (selected_files);

      /* update the launcher actions */
      thunar_launcher_update (launcher);

      /* notify listeners */
      g_object_notify_by_pspec (G_OBJECT (launcher), launcher_props[PROP_SELECTED_FILES]);
    }
}



static GtkUIManager*
thunar_launcher_get_ui_manager (ThunarComponent *component)
{
  return THUNAR_LAUNCHER (component)->ui_manager;
}



static void
thunar_launcher_set_ui_manager (ThunarComponent *component,
                                GtkUIManager    *ui_manager)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (component);
  GError         *error = NULL;

  /* disconnect from the previous UI manager */
  if (G_UNLIKELY (launcher->ui_manager != NULL))
    {
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      /* drop our action group from the previous UI manager */
      gtk_ui_manager_remove_action_group (launcher->ui_manager, launcher->action_group);

      /* unmerge our addons ui controls from the previous UI manager */
      if (G_LIKELY (launcher->ui_addons_merge_id != 0))
        {
          gtk_ui_manager_remove_ui (launcher->ui_manager, launcher->ui_addons_merge_id);
          launcher->ui_addons_merge_id = 0;
        }

      /* unmerge our ui controls from the previous UI manager */
      gtk_ui_manager_remove_ui (launcher->ui_manager, launcher->ui_merge_id);
G_GNUC_END_IGNORE_DEPRECATIONS

      /* drop the reference on the previous UI manager */
      g_object_unref (G_OBJECT (launcher->ui_manager));
    }

  /* activate the new UI manager */
  launcher->ui_manager = ui_manager;

  /* connect to the new UI manager */
  if (G_LIKELY (ui_manager != NULL))
    {
      /* we keep a reference on the new manager */
      g_object_ref (G_OBJECT (ui_manager));

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      /* add our action group to the new manager */
      gtk_ui_manager_insert_action_group (ui_manager, launcher->action_group, -1);

      /* merge our UI control items with the new manager */
      launcher->ui_merge_id = gtk_ui_manager_add_ui_from_string (ui_manager, thunar_launcher_ui, thunar_launcher_ui_length, &error);
G_GNUC_END_IGNORE_DEPRECATIONS
      if (G_UNLIKELY (launcher->ui_merge_id == 0))
        {
          g_error ("Failed to merge ThunarLauncher menus: %s", error->message);
          g_error_free (error);
        }

      /* update the user interface */
      thunar_launcher_update (launcher);
    }

  /* notify listeners */
  g_object_notify_by_pspec (G_OBJECT (launcher), launcher_props[PROP_UI_MANAGER]);
}



static void
thunar_launcher_execute_files (ThunarLauncher *launcher,
                               GList          *files)
{
  GError *error = NULL;
  GFile  *working_directory;
  GList  *lp;

  /* execute all selected files */
  for (lp = files; lp != NULL; lp = lp->next)
    {
      working_directory = thunar_file_get_file (launcher->current_directory);

      if (!thunar_file_execute (lp->data, working_directory, launcher->widget, NULL, NULL, &error))
        {
          /* display an error message to the user */
          thunar_dialogs_show_error (launcher->widget, error, _("Failed to execute file \"%s\""), thunar_file_get_display_name (lp->data));
          g_error_free (error);
          break;
        }
    }
}



static guint
thunar_launcher_g_app_info_hash (gconstpointer app_info)
{
  return 0;
}



static void
thunar_launcher_open_files (ThunarLauncher *launcher,
                            GList          *files)
{
  GHashTable *applications;
  GAppInfo   *app_info;
  GList      *file_list;
  GList      *lp;

  /* allocate a hash table to associate applications to URIs. since GIO allocates
   * new GAppInfo objects every time, g_direct_hash does not work. we therefor use
   * a fake hash function to always hit the collision list of the hash table and
   * avoid storing multiple equal GAppInfos by means of g_app_info_equal(). */
  applications = g_hash_table_new_full (thunar_launcher_g_app_info_hash,
                                        (GEqualFunc) g_app_info_equal,
                                        (GDestroyNotify) g_object_unref,
                                        (GDestroyNotify) thunar_g_file_list_free);

  for (lp = files; lp != NULL; lp = lp->next)
    {
      /* determine the default application for the MIME type */
      app_info = thunar_file_get_default_handler (lp->data);

      /* check if we have an application here */
      if (G_LIKELY (app_info != NULL))
        {
          /* check if we have that application already */
          file_list = g_hash_table_lookup (applications, app_info);
          if (G_LIKELY (file_list != NULL))
            {
              /* take a copy of the list as the old one will be dropped by the insert */
              file_list = thunar_g_file_list_copy (file_list);
            }

          /* append our new URI to the list */
          file_list = thunar_g_file_list_append (file_list, thunar_file_get_file (lp->data));

          /* (re)insert the URI list for the application */
          g_hash_table_insert (applications, app_info, file_list);
        }
      else
        {
          /* display a chooser dialog for the file and stop */
          thunar_show_chooser_dialog (launcher->widget, lp->data, TRUE);
          break;
        }
    }

  /* run all collected applications */
  g_hash_table_foreach (applications, (GHFunc) thunar_launcher_open_paths, launcher);

  /* drop the applications hash table */
  g_hash_table_destroy (applications);
}



static void
thunar_launcher_open_paths (GAppInfo       *app_info,
                            GList          *path_list,
                            ThunarLauncher *launcher)
{
  GdkAppLaunchContext *context;
  GdkScreen           *screen;
  GError              *error = NULL;
  GFile               *working_directory = NULL;
  gchar               *message;
  gchar               *name;
  guint                n;

  /* determine the screen on which to launch the application */
  screen = (launcher->widget != NULL) ? gtk_widget_get_screen (launcher->widget) : NULL;

  /* create launch context */
  context = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
  gdk_app_launch_context_set_screen (context, screen);
  gdk_app_launch_context_set_timestamp (context, gtk_get_current_event_time ());
  gdk_app_launch_context_set_icon (context, g_app_info_get_icon (app_info));

  /* determine the working directory */
  if (launcher->current_directory != NULL)
    working_directory = thunar_file_get_file (launcher->current_directory);

  /* try to execute the application with the given URIs */
  if (!thunar_g_app_info_launch (app_info, working_directory, path_list, G_APP_LAUNCH_CONTEXT (context), &error))
    {
      /* figure out the appropriate error message */
      n = g_list_length (path_list);
      if (G_LIKELY (n == 1))
        {
          /* we can give a precise error message here */
          name = g_filename_display_name (g_file_get_basename (path_list->data));
          message = g_strdup_printf (_("Failed to open file \"%s\""), name);
          g_free (name);
        }
      else
        {
          /* we can just tell that n files failed to open */
          message = g_strdup_printf (ngettext ("Failed to open %d file", "Failed to open %d files", n), n);
        }

      /* display an error dialog to the user */
      thunar_dialogs_show_error (launcher->widget, error, "%s", message);
      g_error_free (error);
      g_free (message);
    }

  /* destroy the launch context */
  g_object_unref (context);
}



static void
thunar_launcher_open_windows (ThunarLauncher *launcher,
                              GList          *directories)
{
  ThunarApplication *application;
  GtkWidget         *dialog;
  GtkWidget         *window;
  GdkScreen         *screen;
  gchar             *label;
  GList             *lp;
  gint               response = GTK_RESPONSE_YES;
  gint               n;

  /* ask the user if we would open more than one new window */
  n = g_list_length (directories);
  if (G_UNLIKELY (n > 1))
    {
      /* open a message dialog */
      window = (launcher->widget != NULL) ? gtk_widget_get_toplevel (launcher->widget) : NULL;
      dialog = gtk_message_dialog_new ((GtkWindow *) window,
                                       GTK_DIALOG_DESTROY_WITH_PARENT
                                       | GTK_DIALOG_MODAL,
                                       GTK_MESSAGE_QUESTION,
                                       GTK_BUTTONS_NONE,
                                       _("Are you sure you want to open all folders?"));
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                                ngettext ("This will open %d separate file manager window.",
                                                          "This will open %d separate file manager windows.",
                                                          n),
                                                n);
      label = g_strdup_printf (ngettext ("Open %d New Window", "Open %d New Windows", n), n);
      gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL);
      gtk_dialog_add_button (GTK_DIALOG (dialog), label, GTK_RESPONSE_YES);
      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
      response = gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);
      g_free (label);
    }

  /* open n new windows if the user approved it */
  if (G_LIKELY (response == GTK_RESPONSE_YES))
    {
      /* query the application object */
      application = thunar_application_get ();

      /* determine the screen on which to open the new windows */
      screen = (launcher->widget != NULL) ? gtk_widget_get_screen (launcher->widget) : NULL;

      /* open all requested windows */
      for (lp = directories; lp != NULL; lp = lp->next)
        thunar_application_open_window (application, lp->data, screen, NULL, TRUE);

      /* release the application object */
      g_object_unref (G_OBJECT (application));
    }
}



static gboolean
thunar_launcher_update_idle (gpointer data)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (data);
  const gchar    *context_menu_path;
  const gchar    *file_menu_path;
  GtkAction      *action;
  gboolean        default_is_open_with_other = FALSE;
  GList          *applications;
  GList          *actions;
  GList          *lp;
  gchar          *tooltip;
  gchar          *label;
  gchar          *name;
  gint            n_directories = 0;
  gint            n_executables = 0;
  gint            n_regulars = 0;
  gint            n_selected_files = 0;
  gint            n;

  /* verify that we're connected to an UI manager */
  if (G_UNLIKELY (launcher->ui_manager == NULL))
    return FALSE;

THUNAR_THREADS_ENTER

  /* drop the previous addons ui controls from the UI manager */
  if (G_LIKELY (launcher->ui_addons_merge_id != 0))
    {
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      gtk_ui_manager_remove_ui (launcher->ui_manager, launcher->ui_addons_merge_id);
      gtk_ui_manager_ensure_update (launcher->ui_manager);
G_GNUC_END_IGNORE_DEPRECATIONS
      launcher->ui_addons_merge_id = 0;
    }

  /* reset the application set for the "Open" action */
  g_object_set_qdata (G_OBJECT (launcher->action_open), thunar_launcher_handler_quark, NULL);

  /* determine the number of files/directories/executables */
  for (lp = launcher->selected_files; lp != NULL; lp = lp->next, ++n_selected_files)
    {
      if (thunar_file_is_directory (lp->data)
          || thunar_file_is_shortcut (lp->data)
          || thunar_file_is_mountable (lp->data))
        {
          ++n_directories;
        }
      else
        {
          if (thunar_file_is_executable (lp->data))
            ++n_executables;
          ++n_regulars;
        }
    }

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  /* Prepare "Open" label and icon */
  gtk_action_set_label (launcher->action_open, _("_Open"));
  gtk_action_set_icon_name (launcher->action_open, "document-open");
G_GNUC_END_IGNORE_DEPRECATIONS

  /* Only directories got selected */
  if (n_selected_files == n_directories && n_directories >= 1)
    {
      if (n_directories > 1)
        {
          /* turn "Open New Window" into "Open in n New Windows" */
          label = g_strdup_printf (ngettext ("Open in %d New _Window", "Open in %d New _Windows", n_directories), n_directories);
          tooltip = g_strdup_printf (ngettext ("Open the selected directory in %d new window",
                                               "Open the selected directories in %d new windows",
                                               n_directories), n_directories);
          g_object_set (G_OBJECT (launcher->action_open_in_new_window),
                        "label", label,
                        "tooltip", tooltip,
                        NULL);
          g_free (tooltip);
          g_free (label);

          /* turn "Open in New Tab" into "Open in x New Tabs" */
          label = g_strdup_printf (ngettext ("Open in %d New _Tab", "Open in %d New _Tabs", n_directories), n_directories);
          tooltip = g_strdup_printf (ngettext ("Open the selected directory in %d new tab",
                                               "Open the selected directories in %d new tabs",
                                               n_directories), n_directories);
          g_object_set (G_OBJECT (launcher->action_open_in_new_tab),
                        "label", label,
                        "tooltip", tooltip,
                        NULL);
          g_free (tooltip);
          g_free (label);
        }
      else if (n_directories == 1)
        {
          /* prepare "Open in New Window" */
          g_object_set (G_OBJECT (launcher->action_open_in_new_window),
                        "label", _("Open in New _Window"),
                        "tooltip", _("Open the selected directory in a new window"),
                        NULL);

          /* prepare "Open in New Tab" */
          g_object_set (G_OBJECT (launcher->action_open_in_new_tab),
                        "label", _("Open in New _Tab"),
                        "tooltip", _("Open the selected directory in a new tab"),
                        NULL);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
          /* set tooltip that makes sence */
          gtk_action_set_tooltip (launcher->action_open, _("Open the selected directory"));
        }

      /* Show Window/Tab action if there are only directories selected */
      gtk_action_set_visible (launcher->action_open_in_new_window, n_directories > 0);
      gtk_action_set_visible (launcher->action_open_in_new_tab, n_directories > 0);

      /* Show open if there is exactly 1 directory selected */
      gtk_action_set_visible (launcher->action_open, n_directories == 1);
      gtk_action_set_sensitive (launcher->action_open, TRUE);
    }
  else /* not only directories got selected */
    {
      /* Hide New Window and Tab action */
      gtk_action_set_visible (launcher->action_open_in_new_window, FALSE);
      gtk_action_set_visible (launcher->action_open_in_new_tab, FALSE);
    }

  /* drop all previous addon actions from the action group */
  actions = gtk_action_group_list_actions (launcher->action_group);
  for (lp = actions; lp != NULL; lp = lp->next)
    if (strncmp (gtk_action_get_name (lp->data), "thunar-launcher-addon-", 22) == 0)
      gtk_action_group_remove_action (launcher->action_group, lp->data);
  g_list_free (actions);

  /* allocate a new merge id from the UI manager */
  launcher->ui_addons_merge_id = gtk_ui_manager_new_merge_id (launcher->ui_manager);

  /* make the "Open" action sensitive */
  gtk_action_set_sensitive (launcher->action_open, TRUE);
G_GNUC_END_IGNORE_DEPRECATIONS

  /* determine the set of applications that work for all selected files */
  applications = thunar_file_list_get_applications (launcher->selected_files);

  /* reset the desktop actions list */
  actions = NULL;

  /* check if we have only executable files in the selection */
  if (G_UNLIKELY (n_executables == n_selected_files))
    {
      /* turn the "Open" action into "Execute" */
      g_object_set (G_OBJECT (launcher->action_open),
                    "label", _("_Execute"),
                    "icon-name", "system-run",
                    "tooltip", ngettext ("Execute the selected file", "Execute the selected files", n_selected_files),
                    NULL);
    }
  else if (G_LIKELY (n_directories >= 1))
    {
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      /* Normal open action, because there are also directories included */
      gtk_action_set_visible (launcher->action_open, TRUE);
      gtk_action_set_sensitive (launcher->action_open, n_selected_files > 0);
      gtk_action_set_tooltip (launcher->action_open,
                              ngettext ("Open the selected file",
                                        "Open the selected files",
                                        n_selected_files));
G_GNUC_END_IGNORE_DEPRECATIONS
    }
  else if (G_LIKELY (applications != NULL))
    {
      /* turn the "Open" action into "Open With DEFAULT" */
      label = g_strdup_printf (_("_Open With \"%s\""), g_app_info_get_name (applications->data));
      tooltip = g_strdup_printf (ngettext ("Use \"%s\" to open the selected file",
                                           "Use \"%s\" to open the selected files",
                                           n_selected_files), g_app_info_get_name (applications->data));
      g_object_set (G_OBJECT (launcher->action_open),
                    "label", label,
                    "tooltip", tooltip,
                    NULL);
      g_free (tooltip);
      g_free (label);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      /* load default application icon */
      gtk_action_set_stock_id (launcher->action_open, NULL);
      gtk_action_set_gicon (launcher->action_open, g_app_info_get_icon (applications->data));
G_GNUC_END_IGNORE_DEPRECATIONS

      /* remember the default application for the "Open" action */
      g_object_set_qdata_full (G_OBJECT (launcher->action_open), thunar_launcher_handler_quark, applications->data, g_object_unref);

      /* FIXME Add the desktop actions for this application.
       * Unfortunately this is not supported by GIO directly */

      /* drop the default application from the list */
      applications = g_list_delete_link (applications, applications);
    }
  else if (G_UNLIKELY (n_selected_files == 1))
    {
      /* turn the "Open" action into "Open With Other Application" */
      g_object_set (G_OBJECT (launcher->action_open),
                    "label", _("_Open With Other Application..."),
                    "tooltip", _("Choose another application with which to open the selected file"),
                    NULL);
      default_is_open_with_other = TRUE;
    }
  else
    {
      /* we can only show a generic "Open" action */
      g_object_set (G_OBJECT (launcher->action_open),
                    "label", _("_Open With Default Applications"),
                    "tooltip", ngettext ("Open the selected file with the default application",
                                         "Open the selected files with the default applications", n_selected_files),
                    NULL);
    }

  /* FIXME Add desktop actions here. Unfortunately they are not supported by
   * GIO, so we'll have to roll our own thing here */

  /* place the other applications in the "Open With" submenu if we have more than 2 other applications, or the
   * default action for the file is "Execute", in which case the "Open With" actions aren't that relevant either
   */
  if (G_UNLIKELY (g_list_length (applications) > 2 || n_executables == n_selected_files) )
    {
      /* determine the base paths for the actions */
      file_menu_path = "/main-menu/file-menu/placeholder-launcher/open-with-menu/placeholder-applications";
      context_menu_path = "/file-context-menu/placeholder-launcher/open-with-menu/placeholder-applications";
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      /* show the "Open With Other Application" in the submenu and hide the toplevel one */
      gtk_action_set_visible (launcher->action_open_with_other, FALSE);
      gtk_action_set_visible (launcher->action_open_with_other_in_menu, (n_selected_files == 1));
G_GNUC_END_IGNORE_DEPRECATIONS
    }
  else
    {
      /* determine the base paths for the actions */
      file_menu_path = "/main-menu/file-menu/placeholder-launcher/placeholder-applications";
      context_menu_path = "/file-context-menu/placeholder-launcher/placeholder-applications";

      /* add a separator if we have more than one additional application */
      if (G_LIKELY (applications != NULL))
        {
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
          /* add separator after the DEFAULT/execute action */
          gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
                                 file_menu_path, "separator", NULL,
                                 GTK_UI_MANAGER_SEPARATOR, FALSE);
          gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
                                 context_menu_path, "separator", NULL,
                                 GTK_UI_MANAGER_SEPARATOR, FALSE);
        }

      /* show the toplevel "Open With Other Application" (if not already done by the "Open" action) */
      gtk_action_set_visible (launcher->action_open_with_other, !default_is_open_with_other && (n_selected_files == 1));
      gtk_action_set_visible (launcher->action_open_with_other_in_menu, FALSE);
    }
G_GNUC_END_IGNORE_DEPRECATIONS

  /* add actions for all remaining applications */
  if (G_LIKELY (applications != NULL))
    {
      /* process all applications and determine the desktop actions */
      for (lp = applications, n = 0; lp != NULL; lp = lp->next, ++n)
        {
          /* FIXME Determine the desktop actions for this application.
           * Unfortunately this is not supported by GIO directly. */

          /* generate a unique label, unique id and tooltip for the application's action */
          name = g_strdup_printf ("thunar-launcher-addon-application%d-%p", n, launcher);
          label = g_strdup_printf (_("Open With \"%s\""), g_app_info_get_name (lp->data));
          tooltip = g_strdup_printf (ngettext ("Use \"%s\" to open the selected file",
                                               "Use \"%s\" to open the selected files",
                                               n_selected_files), g_app_info_get_name (lp->data));

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
          /* allocate a new action for the application */
          action = gtk_action_new (name, label, tooltip, NULL);
          gtk_action_set_gicon (action, g_app_info_get_icon (lp->data));
          gtk_action_group_add_action (launcher->action_group, action);
          g_object_set_qdata_full (G_OBJECT (action), thunar_launcher_handler_quark, lp->data, g_object_unref);
          g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (thunar_launcher_action_open), launcher);
          gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
                                 file_menu_path, name, name,
                                 GTK_UI_MANAGER_MENUITEM, FALSE);
          gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
                                 context_menu_path, name, name,
                                 GTK_UI_MANAGER_MENUITEM, FALSE);
          g_object_unref (G_OBJECT (action));
G_GNUC_END_IGNORE_DEPRECATIONS

          /* cleanup */
          g_free (tooltip);
          g_free (label);
          g_free (name);
        }

      /* cleanup */
      g_list_free (applications);
    }
  /* schedule an update of the "Send To" menu */
  if (G_LIKELY (launcher->sendto_idle_id == 0))
    {
      launcher->sendto_idle_id = g_idle_add_full (G_PRIORITY_LOW, thunar_launcher_sendto_idle,
                                                  launcher, thunar_launcher_sendto_idle_destroy);
    }

THUNAR_THREADS_LEAVE

  return FALSE;
}



static void
thunar_launcher_update_idle_destroy (gpointer data)
{
  THUNAR_LAUNCHER (data)->launcher_idle_id = 0;
}



static void
thunar_launcher_update_check (ThunarLauncher *launcher,
                              GtkWidget      *menu)
{
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));
  _thunar_return_if_fail (menu == NULL || GTK_IS_MENU (menu));

  /* check if the menu is in a dirty state */
  if (launcher->launcher_idle_id != 0)
    {
      /* stop the timeout */
      g_source_remove (launcher->launcher_idle_id);

      /* force an update */
      thunar_launcher_update_idle (launcher);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      /* ui update */
      gtk_ui_manager_ensure_update (launcher->ui_manager);
G_GNUC_END_IGNORE_DEPRECATIONS

      /* make sure the menu is positioned correctly after the
       * interface update */
      if (menu != NULL)
        gtk_menu_reposition (GTK_MENU (menu));
    }
}



static void
thunar_launcher_update (ThunarLauncher *launcher)
{
  GSList    *proxies, *lp;
  GtkWidget *menu;
  gboolean   instant_update;

  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  proxies = gtk_action_get_proxies (launcher->action_open);
G_GNUC_END_IGNORE_DEPRECATIONS
  instant_update = (proxies == NULL);
  for (lp = proxies; lp != NULL; lp = lp->next)
    {
      menu = gtk_widget_get_ancestor (lp->data, GTK_TYPE_MENU);
      if (G_LIKELY (menu != NULL))
        {
          /* instant update if a menu is visible */
          if (gtk_widget_get_visible (menu))
            instant_update = TRUE;

          /* watch menu changes */
          g_signal_handlers_disconnect_by_func (G_OBJECT (menu), G_CALLBACK (thunar_launcher_update_check), launcher);
          g_signal_connect_swapped (G_OBJECT (menu), "show", G_CALLBACK (thunar_launcher_update_check), launcher);
        }
    }

  /* stop pending timeouts */
  if (launcher->launcher_idle_id != 0)
    g_source_remove (launcher->launcher_idle_id);

  if (instant_update)
    {
      /* directly update without interruption */
      thunar_launcher_update_idle (launcher);
    }
  else
    {
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      /* assume all actions are working */
      gtk_action_set_sensitive (launcher->action_open, TRUE);
      gtk_action_set_visible (launcher->action_open_with_other, TRUE);
      gtk_action_set_visible (launcher->action_open_in_new_window, TRUE);
      gtk_action_set_visible (launcher->action_open_in_new_tab, TRUE);
      gtk_action_set_visible (launcher->action_open_with_other_in_menu, TRUE);
G_GNUC_END_IGNORE_DEPRECATIONS
      /* delayed update */
      launcher->launcher_idle_id = g_timeout_add_seconds_full (G_PRIORITY_LOW, 5, thunar_launcher_update_idle,
                                                               launcher, thunar_launcher_update_idle_destroy);
    }
}



static void
thunar_launcher_open_file (ThunarLauncher *launcher,
                           ThunarFile     *file)
{
  GList files;

  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));
  _thunar_return_if_fail (THUNAR_IS_FILE (file));

  files.data = file;
  files.next = NULL;
  files.prev = NULL;

  if (thunar_file_is_directory (file))
    {
      /* check if we're in a regular view (i.e. current_directory is set) */
      if (G_LIKELY (launcher->current_directory != NULL))
        {
          /* we want to open one directory, so just emit "change-directory" here */
          thunar_navigator_change_directory (THUNAR_NAVIGATOR (launcher), file);
        }
      else
        {
          /* open the selected directory in a new window */
          thunar_launcher_open_windows (launcher, &files);
        }
    }
  else
    {
      if (thunar_file_is_executable (file))
        {
          /* try to execute the file */
          thunar_launcher_execute_files (launcher, &files);
        }
      else
        {
          /* try to open the file using its default application */
          thunar_launcher_open_files (launcher, &files);
        }
    }
}



static void
thunar_launcher_poke_file_finish (ThunarBrowser *browser,
                                  ThunarFile    *file,
                                  ThunarFile    *target_file,
                                  GError        *error,
                                  gpointer       ignored)
{
  if (error == NULL)
    {
      thunar_launcher_open_file (THUNAR_LAUNCHER (browser), target_file);
    }
  else
    {
      thunar_dialogs_show_error (THUNAR_LAUNCHER (browser)->widget, error,
                                 _("Failed to open \"%s\""),
                                 thunar_file_get_display_name (file));
    }
}



static void
thunar_launcher_poke_files (ThunarLauncher         *launcher,
                            ThunarLauncherPokeData *poke_data)
{
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));
  _thunar_return_if_fail (poke_data != NULL);
  _thunar_return_if_fail (poke_data->files != NULL);

  thunar_browser_poke_file (THUNAR_BROWSER (launcher), poke_data->files->data,
                            launcher->widget, thunar_launcher_poke_files_finish,
                            poke_data);
}



static void
thunar_launcher_poke_files_finish (ThunarBrowser *browser,
                                   ThunarFile    *file,
                                   ThunarFile    *target_file,
                                   GError        *error,
                                   gpointer       user_data)
{
  ThunarLauncherPokeData *poke_data = user_data;
  gboolean                executable = TRUE;
  GList                  *directories = NULL;
  GList                  *files = NULL;
  GList                  *lp;

  _thunar_return_if_fail (THUNAR_IS_BROWSER (browser));
  _thunar_return_if_fail (THUNAR_IS_FILE (file));
  _thunar_return_if_fail (poke_data != NULL);
  _thunar_return_if_fail (poke_data->files != NULL);

  /* check if poking succeeded */
  if (error == NULL)
    {
      /* add the resolved file to the list of file to be opened/executed later */
      poke_data->resolved_files = g_list_prepend (poke_data->resolved_files,
                                                  g_object_ref (target_file));
    }

  /* release and remove the just poked file from the list */
  g_object_unref (poke_data->files->data);
  poke_data->files = g_list_delete_link (poke_data->files, poke_data->files);

  if (poke_data->files == NULL)
    {
      /* separate files and directories in the selected files list */
      for (lp = poke_data->resolved_files; lp != NULL; lp = lp->next)
        {
          if (thunar_file_is_directory (lp->data))
            {
              /* add to our directory list */
              directories = g_list_prepend (directories, lp->data);
            }
          else
            {
              /* add to our file list */
              files = g_list_prepend (files, lp->data);

              /* check if the file is executable */
              executable = (executable && thunar_file_is_executable (lp->data));
            }
        }

      /* check if we have any directories to process */
      if (G_LIKELY (directories != NULL))
        {
          if (poke_data->directories_in_tabs)
            {
              /* open new tabs */
              for (lp = directories; lp != NULL; lp = lp->next)
                thunar_navigator_open_new_tab (THUNAR_NAVIGATOR (browser), lp->data);
            }
          else
            {
              /* open new windows for all directories */
              thunar_launcher_open_windows (THUNAR_LAUNCHER (browser), directories);
            }
          g_list_free (directories);
        }

      /* check if we have any files to process */
      if (G_LIKELY (files != NULL))
        {
          /* if all files are executable, we just run them here */
          if (G_UNLIKELY (executable))
            {
              /* try to execute all given files */
              thunar_launcher_execute_files (THUNAR_LAUNCHER (browser), files);
            }
          else
            {
              /* try to open all files using their default applications */
              thunar_launcher_open_files (THUNAR_LAUNCHER (browser), files);
            }

          /* cleanup */
          g_list_free (files);
        }

      /* free all files allocated for the poke data */
      thunar_launcher_poke_data_free (poke_data);
    }
  else
    {
      /* we need to continue this until all files have been resolved */
      thunar_launcher_poke_files (THUNAR_LAUNCHER (browser), poke_data);
    }
}



static void
thunar_launcher_action_open (GtkAction      *action,
                             ThunarLauncher *launcher)
{
  ThunarLauncherPokeData *poke_data;
  GAppInfo               *app_info;
  GList                  *selected_paths;

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (GTK_IS_ACTION (action));
G_GNUC_END_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  /* force update if still dirty */
  thunar_launcher_update_check (launcher, NULL);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  if (!gtk_action_get_sensitive (action))
    return;
G_GNUC_END_IGNORE_DEPRECATIONS

  /* check if we have a mime handler associated with the action */
  app_info = g_object_get_qdata (G_OBJECT (action), thunar_launcher_handler_quark);
  if (G_LIKELY (app_info != NULL))
    {
      /* try to open the selected files using the given application */
      selected_paths = thunar_file_list_to_thunar_g_file_list (launcher->selected_files);
      thunar_launcher_open_paths (app_info, selected_paths, launcher);
      thunar_g_file_list_free (selected_paths);
    }
  else if (launcher->selected_files != NULL)
    {
      if (launcher->selected_files->next == NULL)
        {
          thunar_browser_poke_file (THUNAR_BROWSER (launcher),
                                    launcher->selected_files->data, launcher->widget,
                                    thunar_launcher_poke_file_finish, NULL);
        }
      else
        {
          /* resolve files one after another until none is left. Open/execute
           * the resolved files/directories when all this is done at a later
           * stage */
           poke_data = thunar_launcher_poke_data_new (launcher->selected_files);
           thunar_launcher_poke_files (launcher, poke_data);
        }
    }
}



static void
thunar_launcher_action_open_with_other (GtkAction      *action,
                                        ThunarLauncher *launcher)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (GTK_IS_ACTION (action));
G_GNUC_END_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  /* force update if still dirty */
  thunar_launcher_update_check (launcher, NULL);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  if (!gtk_action_get_visible (action))
    return;
G_GNUC_END_IGNORE_DEPRECATIONS

  /* verify that we have atleast one selected file */
  if (G_LIKELY (launcher->selected_files != NULL))
    {
      /* popup the chooser dialog for the first selected file */
      thunar_show_chooser_dialog (launcher->widget, launcher->selected_files->data, TRUE);
    }
}



static void
thunar_launcher_action_open_in_new_window (GtkAction      *action,
                                           ThunarLauncher *launcher)
{
  ThunarLauncherPokeData *poke_data;

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (GTK_IS_ACTION (action));
G_GNUC_END_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  /* force update if still dirty */
  thunar_launcher_update_check (launcher, NULL);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  if (!gtk_action_get_visible (action))
    return;
G_GNUC_END_IGNORE_DEPRECATIONS

  /* open the selected directories in new windows */
  poke_data = thunar_launcher_poke_data_new (launcher->selected_files);
  thunar_launcher_poke_files (launcher, poke_data);
}



static void
thunar_launcher_action_open_in_new_tab (GtkAction      *action,
                                        ThunarLauncher *launcher)
{
  ThunarLauncherPokeData *poke_data;

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (GTK_IS_ACTION (action));
G_GNUC_END_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  /* force update if still dirty */
  thunar_launcher_update_check (launcher, NULL);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  if (!gtk_action_get_visible (action))
    return;
G_GNUC_END_IGNORE_DEPRECATIONS

  /* open all selected directories in a new tab */
  poke_data = thunar_launcher_poke_data_new (launcher->selected_files);
  poke_data->directories_in_tabs = TRUE;
  thunar_launcher_poke_files (launcher, poke_data);
}



static void
thunar_launcher_action_sendto_desktop (GtkAction      *action,
                                       ThunarLauncher *launcher)
{
  ThunarApplication *application;
  GFile             *desktop_file;
  GList             *files;

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (GTK_IS_ACTION (action));
G_GNUC_END_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  /* determine the source files */
  files = thunar_file_list_to_thunar_g_file_list (launcher->selected_files);
  if (G_UNLIKELY (files == NULL))
    return;

  /* determine the file to the ~/Desktop folder */
  desktop_file = thunar_g_file_new_for_desktop ();

  /* launch the link job */
  application = thunar_application_get ();
  thunar_application_link_into (application, launcher->widget, files, desktop_file, NULL);
  g_object_unref (G_OBJECT (application));

  /* cleanup */
  g_object_unref (desktop_file);
  thunar_g_file_list_free (files);
}



static ThunarLauncherMountData *
thunar_launcher_mount_data_new (ThunarLauncher *launcher,
                                GList          *files)
{
  ThunarLauncherMountData *data;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), NULL);

  data = g_slice_new0 (ThunarLauncherMountData);
  data->launcher = g_object_ref (launcher);
  data->files = thunar_g_file_list_copy (files);

  return data;
}



static void
thunar_launcher_mount_data_free (ThunarLauncherMountData *data)
{
  _thunar_return_if_fail (data != NULL);
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (data->launcher));

  g_object_unref (data->launcher);
  thunar_g_file_list_free (data->files);
  g_slice_free (ThunarLauncherMountData, data);
}



static ThunarLauncherPokeData *
thunar_launcher_poke_data_new (GList *files)
{
  ThunarLauncherPokeData *data;

  data = g_slice_new0 (ThunarLauncherPokeData);
  data->files = thunar_g_file_list_copy (files);
  data->resolved_files = NULL;
  data->directories_in_tabs = FALSE;

  return data;
}



static void
thunar_launcher_poke_data_free (ThunarLauncherPokeData *data)
{
  _thunar_return_if_fail (data != NULL);

  thunar_g_file_list_free (data->files);
  thunar_g_file_list_free (data->resolved_files);
  g_slice_free (ThunarLauncherPokeData, data);
}



static void
thunar_launcher_sendto_device (ThunarLauncher *launcher,
                               ThunarDevice   *device,
                               GList          *files)
{
  ThunarApplication *application;
  GFile             *mount_point;

  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));
  _thunar_return_if_fail (THUNAR_IS_DEVICE (device));

  if (!thunar_device_is_mounted (device))
    return;

  mount_point = thunar_device_get_root (device);
  if (mount_point != NULL)
    {
      /* copy the files onto the specified device */
      application = thunar_application_get ();
      thunar_application_copy_into (application, launcher->widget, files, mount_point, NULL);
      g_object_unref (application);

      g_object_unref (mount_point);
    }
}



static void
thunar_launcher_sendto_mount_finish (ThunarDevice *device,
                                     const GError *error,
                                     gpointer      user_data)
{
  ThunarLauncherMountData *data = user_data;
  gchar                   *device_name;

  _thunar_return_if_fail (THUNAR_IS_DEVICE (device));
  _thunar_return_if_fail (user_data != NULL);
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (data->launcher));

  if (error != NULL)
    {
      /* tell the user that we were unable to mount the device, which is
       * required to send files to it */
      device_name = thunar_device_get_name (device);
      thunar_dialogs_show_error (data->launcher->widget, error, _("Failed to mount \"%s\""), device_name);
      g_free (device_name);
    }
  else
    {
      thunar_launcher_sendto_device (data->launcher, device, data->files);
    }

  thunar_launcher_mount_data_free (data);
}



static void
thunar_launcher_action_sendto_device (GtkAction      *action,
                                      ThunarLauncher *launcher)
{
  ThunarLauncherMountData *data;
  GMountOperation         *mount_operation;
  ThunarDevice            *device;
  GList                   *files;

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (GTK_IS_ACTION (action));
G_GNUC_END_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  /* determine the source paths */
  files = thunar_file_list_to_thunar_g_file_list (launcher->selected_files);
  if (G_UNLIKELY (files == NULL))
    return;

  /* determine the device to which to send */
  device = g_object_get_qdata (G_OBJECT (action), thunar_launcher_handler_quark);
  if (G_UNLIKELY (device == NULL))
    return;

  /* make sure to mount the device first, if it's not already mounted */
  if (!thunar_device_is_mounted (device))
    {
      /* allocate mount data */
      data = thunar_launcher_mount_data_new (launcher, files);

      /* allocate a GTK+ mount operation */
      mount_operation = thunar_gtk_mount_operation_new (launcher->widget);

      /* try to mount the device and later start sending the files */
      thunar_device_mount (device,
                           mount_operation,
                           NULL,
                           thunar_launcher_sendto_mount_finish,
                           data);

      g_object_unref (mount_operation);
    }
  else
    {
      thunar_launcher_sendto_device (launcher, device, files);
    }

  /* cleanup */
  thunar_g_file_list_free (files);
}



static void
thunar_launcher_widget_destroyed (ThunarLauncher *launcher,
                                  GtkWidget      *widget)
{
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));
  _thunar_return_if_fail (launcher->widget == widget);
  _thunar_return_if_fail (GTK_IS_WIDGET (widget));

  /* just reset the widget property for the launcher */
  thunar_launcher_set_widget (launcher, NULL);
}



static gboolean
thunar_launcher_sendto_idle (gpointer user_data)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (user_data);
  const gchar    *label;
  GtkAction      *action;
  gboolean        linkable = TRUE;
  GIcon          *icon;
  GList          *handlers;
  GList          *devices;
  GList          *lp;
  gchar          *name;
  gchar          *tooltip;
  gchar          *device_name;
  gint            n_selected_files;
  gint            n = 0;
  gboolean        got_devices = FALSE;
  const gchar    *file_menu_path;
  const gchar    *context_menu_path;

  /* verify that we have an UI manager */
  if (launcher->ui_manager == NULL)
    return FALSE;

THUNAR_THREADS_ENTER

  /* determine the number of selected files and check whether atleast one of these
   * files is located in the trash (to en-/disable the "sendto-desktop" action).
   */
  for (lp = launcher->selected_files, n_selected_files = 0; lp != NULL; lp = lp->next, ++n_selected_files)
    {
      /* check if this file is in trash */
      if (G_UNLIKELY (linkable))
        linkable = !thunar_file_is_trashed (lp->data);
    }

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  /* update the "Desktop (Create Link)" sendto action */
  action = gtk_action_group_get_action (launcher->action_group, "sendto-desktop");
G_GNUC_END_IGNORE_DEPRECATIONS
  g_object_set (G_OBJECT (action),
                "label", ngettext ("Desktop (Create Link)", "Desktop (Create Links)", n_selected_files),
                "tooltip", ngettext ("Create a link to the selected file on the desktop",
                                     "Create links to the selected files on the desktop",
                                     n_selected_files),
                "visible", (linkable && n_selected_files > 0),
                NULL);

  /* re-add the content to "Send To" if we have any files */
  if (G_LIKELY (n_selected_files > 0))
    {
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      /* drop all previous sendto actions from the action group */
      handlers = gtk_action_group_list_actions (launcher->action_group);
      for (lp = handlers; lp != NULL; lp = lp->next)
        if (strncmp (gtk_action_get_name (lp->data), "thunar-launcher-sendto", 22) == 0)
          gtk_action_group_remove_action (launcher->action_group, lp->data);
      g_list_free (handlers);

      /* allocate a new merge id from the UI manager (if not already done) */
      if (G_UNLIKELY (launcher->ui_addons_merge_id == 0))
        launcher->ui_addons_merge_id = gtk_ui_manager_new_merge_id (launcher->ui_manager);
G_GNUC_END_IGNORE_DEPRECATIONS

      /* determine the currently active devices */
      devices = thunar_device_monitor_get_devices (launcher->device_monitor);
      got_devices = (devices != NULL);

      /* paths in ui */
      file_menu_path = "/main-menu/file-menu/sendto-menu/placeholder-sendto-actions";
      context_menu_path = "/file-context-menu/sendto-menu/placeholder-sendto-actions";

      /* add removable (and writable) drives and media */
      for (lp = devices; lp != NULL; lp = lp->next, ++n)
        {
          /* generate a unique name and tooltip for the device */
          device_name = thunar_device_get_name (lp->data);
          name = g_strdup_printf ("thunar-launcher-sendto%d-%p", n, launcher);
          tooltip = g_strdup_printf (ngettext ("Send the selected file to \"%s\"",
                                               "Send the selected files to \"%s\"",
                                               n_selected_files), device_name);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
          /* allocate a new action for the device */
          action = gtk_action_new (name, device_name, tooltip, NULL);
          g_object_set_qdata_full (G_OBJECT (action), thunar_launcher_handler_quark, lp->data, g_object_unref);
          g_object_set_data (G_OBJECT (lp->data), "skip-app-info-update", GUINT_TO_POINTER (1));
          g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (thunar_launcher_action_sendto_device), launcher);
          gtk_action_group_add_action (launcher->action_group, action);
          gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
                                 file_menu_path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
          gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
                                 context_menu_path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
          g_object_unref (action);

          icon = thunar_device_get_icon (lp->data);
          if (G_LIKELY (icon != NULL))
            {
              gtk_action_set_gicon (action, icon);
              g_object_unref (icon);
            }
G_GNUC_END_IGNORE_DEPRECATIONS

          /* cleanup */
          g_free (name);
          g_free (tooltip);
          g_free (device_name);
        }

      /* free the devices list */
      g_list_free (devices);

      /* determine the sendto handlers for the selected files */
      handlers = thunar_sendto_model_get_matching (launcher->sendto_model, launcher->selected_files);
      if (G_LIKELY (handlers != NULL))
        {
          if (got_devices)
            {
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
              /* add separator between the devices and actions action */
              gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
                                     file_menu_path, "separator", NULL,
                                     GTK_UI_MANAGER_SEPARATOR, FALSE);
              gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
                                     context_menu_path, "separator", NULL,
                                     GTK_UI_MANAGER_SEPARATOR, FALSE);
G_GNUC_END_IGNORE_DEPRECATIONS
            }

          /* add all handlers to the user interface */
          for (lp = handlers; lp != NULL; lp = lp->next, ++n)
            {
              /* generate a unique name and tooltip for the handler */
              label = g_app_info_get_name (lp->data);
              name = g_strdup_printf ("thunar-launcher-sendto%d-%p", n, launcher);
              tooltip = g_strdup_printf (ngettext ("Send the selected file to \"%s\"",
                                                   "Send the selected files to \"%s\"",
                                                   n_selected_files), label);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
              /* allocate a new action for the handler */
              action = gtk_action_new (name, label, tooltip, NULL);
              gtk_action_set_gicon (action, g_app_info_get_icon (lp->data));
              g_object_set_qdata_full (G_OBJECT (action), thunar_launcher_handler_quark, lp->data, g_object_unref);
              g_object_set_data (G_OBJECT (lp->data), "skip-app-info-update", GUINT_TO_POINTER (1));
              g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (thunar_launcher_action_open), launcher);
              gtk_action_group_add_action (launcher->action_group, action);
              gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
                                     file_menu_path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
              gtk_ui_manager_add_ui (launcher->ui_manager, launcher->ui_addons_merge_id,
                                     context_menu_path, name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
              g_object_unref (G_OBJECT (action));
G_GNUC_END_IGNORE_DEPRECATIONS

              /* cleanup */
              g_free (tooltip);
              g_free (name);
            }

          /* release the handler list */
          g_list_free (handlers);
        }
    }

THUNAR_THREADS_LEAVE

  return FALSE;
}



static void
thunar_launcher_sendto_idle_destroy (gpointer user_data)
{
  THUNAR_LAUNCHER (user_data)->sendto_idle_id = 0;
}



/**
 * thunar_launcher_new:
 *
 * Allocates a new #ThunarLauncher instance.
 *
 * Return value: the newly allocated #ThunarLauncher.
 **/
ThunarLauncher*
thunar_launcher_new (void)
{
  return g_object_new (THUNAR_TYPE_LAUNCHER, NULL);
}



/**
 * thunar_launcher_get_widget:
 * @launcher : a #ThunarLauncher.
 *
 * Returns the #GtkWidget currently associated with @launcher.
 *
 * Return value: the widget associated with @launcher.
 **/
static GtkWidget*
thunar_launcher_get_widget (const ThunarLauncher *launcher)
{
  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), NULL);
  return launcher->widget;
}



/**
 * thunar_launcher_set_widget:
 * @launcher : a #ThunarLauncher.
 * @widget   : a #GtkWidget or %NULL.
 *
 * Associates @launcher with @widget.
 **/
void
thunar_launcher_set_widget (ThunarLauncher *launcher,
                            GtkWidget      *widget)
{
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));
  _thunar_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));

  /* disconnect from the previous widget */
  if (G_UNLIKELY (launcher->widget != NULL))
    {
      g_signal_handlers_disconnect_by_func (G_OBJECT (launcher->widget), thunar_launcher_widget_destroyed, launcher);
      g_object_unref (G_OBJECT (launcher->widget));
    }

  /* activate the new widget */
  launcher->widget = widget;

  /* connect to the new widget */
  if (G_LIKELY (widget != NULL))
    {
      g_object_ref (G_OBJECT (widget));
      g_signal_connect_swapped (G_OBJECT (widget), "destroy", G_CALLBACK (thunar_launcher_widget_destroyed), launcher);
    }

  /* notify listeners */
  g_object_notify_by_pspec (G_OBJECT (launcher), launcher_props[PROP_WIDGET]);
}