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
|
/*
* TODO:
* - child elements focusing support
* - user defined icon/label cb
* - show/hide/add buttons ???
* - show/hide hidden files
* - multi-selection
* - make variable/function names that are sensible
* - Pattern Filter support
* - Custom Filter support
* - is 'is_save' flag and API needed? If it is not is_save mode,
* entry is disabled and anchor can't be clicked.
* Also user should be able to type custom name in this mode.
*/
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Elementary.h>
#include "elm_priv.h"
#include "elm_widget_fileselector.h"
EAPI Eo_Op ELM_OBJ_FILESELECTOR_BASE_ID = EO_NOOP;
#define MY_CLASS ELM_OBJ_FILESELECTOR_CLASS
#define MY_CLASS_NAME "elm_fileselector"
static Elm_Genlist_Item_Class *list_itc[ELM_FILE_LAST];
static Elm_Gengrid_Item_Class *grid_itc[ELM_FILE_LAST];
#define ELM_PRIV_FILESELECTOR_SIGNALS(cmd) \
cmd(SIG_ACTIVATED, "activated", "s") \
cmd(SIG_DIRECTORY_OPEN, "directory,open", "s") \
cmd(SIG_DONE, "done", "s") \
cmd(SIG_SELECTED, "selected", "s") \
cmd(SIG_SELECTED_INVALID, "selected,invalid", "s")
ELM_PRIV_FILESELECTOR_SIGNALS(ELM_PRIV_STATIC_VARIABLE_DECLARE);
static const Evas_Smart_Cb_Description _smart_callbacks[] = {
ELM_PRIV_FILESELECTOR_SIGNALS(ELM_PRIV_SMART_CALLBACKS_DESC)
{NULL, NULL}
};
/* final routine on deletion */
static void
_elm_fileselector_smart_del_do(Elm_Fileselector_Smart_Data *sd)
{
if (sd->path) eina_stringshare_del(sd->path);
if (sd->selection) eina_stringshare_del(sd->selection);
if (sd->populate_idler) free(ecore_idler_del(sd->populate_idler));
eo_do_super(sd->obj, MY_CLASS, evas_obj_smart_del());
}
static void
_elm_fileselector_smart_sizing_eval(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
{
Evas_Coord minw = -1, minh = -1;
Elm_Widget_Smart_Data *wd = eo_data_scope_get(obj, ELM_OBJ_WIDGET_CLASS);
elm_coords_finger_size_adjust(1, &minw, 1, &minh);
edje_object_size_min_restricted_calc
(wd->resize_obj, &minw, &minh, minw, minh);
evas_object_size_hint_min_set(obj, minw, minh);
}
static void
_mirrored_set(Evas_Object *obj, Eina_Bool rtl)
{
ELM_FILESELECTOR_DATA_GET(obj, sd);
elm_widget_mirrored_set(sd->cancel_button, rtl);
elm_widget_mirrored_set(sd->ok_button, rtl);
elm_widget_mirrored_set(sd->files_list, rtl);
elm_widget_mirrored_set(sd->files_grid, rtl);
elm_widget_mirrored_set(sd->up_button, rtl);
elm_widget_mirrored_set(sd->home_button, rtl);
}
static void
_elm_fileselector_smart_theme(Eo *obj, void *_pd, va_list *list)
{
const char *style;
const char *data;
char buf[1024];
Elm_Fileselector_Smart_Data *sd = _pd;
Elm_Widget_Smart_Data *wd = eo_data_scope_get(obj, ELM_OBJ_WIDGET_CLASS);
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
if (ret) *ret = EINA_FALSE;
Eina_Bool int_ret;
eo_do_super(obj, MY_CLASS, elm_wdg_theme(&int_ret));
if (!int_ret) return;
style = elm_widget_style_get(obj);
_mirrored_set(obj, elm_widget_mirrored_get(obj));
data = edje_object_data_get
(wd->resize_obj, "path_separator");
if (data) sd->path_separator = data;
else sd->path_separator = "/";
snprintf(buf, sizeof(buf), "fileselector/%s", style);
#define SWALLOW(part_name, object_ptn) \
if (object_ptn) \
{ \
elm_widget_style_set(object_ptn, buf); \
if (!elm_layout_content_set(obj, part_name, object_ptn)) \
evas_object_hide(object_ptn); \
}
SWALLOW("elm.swallow.up", sd->up_button);
SWALLOW("elm.swallow.home", sd->home_button);
SWALLOW("elm.swallow.spinner", sd->spinner);
elm_object_style_set(sd->spinner, "wheel");
if (sd->mode == ELM_FILESELECTOR_LIST)
{
if (elm_layout_content_set(obj, "elm.swallow.files", sd->files_list))
evas_object_hide(sd->files_grid);
else evas_object_hide(sd->files_list);
}
else
{
if (elm_layout_content_set(obj, "elm.swallow.files", sd->files_grid))
evas_object_hide(sd->files_list);
else evas_object_hide(sd->files_grid);
}
SWALLOW("elm.swallow.path", sd->path_entry);
SWALLOW("elm.swallow.filename", sd->name_entry);
snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
SWALLOW("elm.swallow.filters", sd->filter_hoversel);
SWALLOW("elm.swallow.cancel", sd->cancel_button);
SWALLOW("elm.swallow.ok", sd->ok_button);
#undef SWALLOW
edje_object_message_signal_process(wd->resize_obj);
elm_layout_sizing_eval(obj);
if (ret) *ret = EINA_TRUE;
}
/*** GENLIST/GENGRID "MODEL" ***/
static char *
_itc_text_get(void *data,
Evas_Object *obj __UNUSED__,
const char *source __UNUSED__)
{
return elm_entry_utf8_to_markup
(ecore_file_file_get(data)); /* NOTE this will be free()'d by
* the caller */
}
static Evas_Object *
_itc_icon_folder_get(void *data __UNUSED__,
Evas_Object *obj,
const char *source)
{
Evas_Object *ic;
if (strcmp(source, "elm.swallow.icon")) return NULL;
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "folder");
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
return ic;
}
static Evas_Object *
_itc_icon_image_get(void *data,
Evas_Object *obj,
const char *source)
{
const char *filename = data;
Evas_Object *ic;
if (strcmp(source, "elm.swallow.icon")) return NULL;
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "image");
elm_icon_thumb_set(ic, filename, NULL);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
return ic;
}
static Evas_Object *
_itc_icon_file_get(void *data __UNUSED__,
Evas_Object *obj,
const char *source)
{
Evas_Object *ic;
if (strcmp(source, "elm.swallow.icon")) return NULL;
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "file");
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
return ic;
}
static Eina_Bool
_itc_state_get(void *data __UNUSED__,
Evas_Object *obj __UNUSED__,
const char *source __UNUSED__)
{
return EINA_FALSE;
}
static void
_itc_del(void *data,
Evas_Object *obj __UNUSED__)
{
eina_stringshare_del(data);
}
static void
_anchors_do(Evas_Object *obj,
const char *path)
{
char **tok, buf[PATH_MAX * 3], *s;
int i, j;
ELM_FILESELECTOR_DATA_GET(obj, sd);
s = elm_entry_utf8_to_markup(path);
if (!s) return;
buf[0] = '\0';
tok = eina_str_split(s, "/", 0);
free(s);
eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
for (i = 0; tok[i]; i++)
{
if ((!tok[i]) || (!tok[i][0])) continue;
eina_strlcat(buf, sd->path_separator, sizeof(buf));
eina_strlcat(buf, "<a href=", sizeof(buf));
for (j = 0; j <= i; j++)
{
if (strlen(tok[j]) < 1) continue;
eina_strlcat(buf, "/", sizeof(buf));
eina_strlcat(buf, tok[j], sizeof(buf));
}
eina_strlcat(buf, ">", sizeof(buf));
eina_strlcat(buf, tok[i], sizeof(buf));
eina_strlcat(buf, "</a>", sizeof(buf));
}
free(tok[0]);
free(tok);
elm_object_text_set(sd->path_entry, buf);
}
static Eina_Bool
_mime_type_matched(const char *mime_filter, const char *mime_type)
{
int i = 0;
while (mime_filter[i] != '\0')
{
if (mime_filter[i] != mime_type[i])
{
if (mime_filter[i] == '*' && mime_filter[i + 1] == '\0')
return EINA_TRUE;
return EINA_FALSE;
}
i++;
}
if (mime_type[i] != '\0') return EINA_FALSE;
return EINA_TRUE;
}
static Eina_Bool
_check_filters(const Elm_Fileselector_Filter *filter, const char *file_name)
{
const char *mime_type = NULL;
int i;
if (!filter) return EINA_TRUE;
#ifdef ELM_EFREET
mime_type = efreet_mime_type_get(file_name);
#endif
if (!mime_type) return EINA_FALSE;
for (i = 0; filter->mime_types[i]; ++i)
{
if (_mime_type_matched(filter->mime_types[i], mime_type))
return EINA_TRUE;
}
return EINA_FALSE;
}
#ifdef HAVE_EIO
static Eina_Bool
_ls_filter_cb(void *data,
Eio_File *handler __UNUSED__,
const Eina_File_Direct_Info *info)
{
Listing_Request *lreq = data;
if (info->path[info->name_start] == '.')
return EINA_FALSE;
if (lreq->sd->only_folder && info->type != EINA_FILE_DIR)
return EINA_FALSE;
if (info->type != EINA_FILE_DIR && !_check_filters(lreq->sd->current_filter, info->path))
return EINA_FALSE;
return EINA_TRUE;
}
static int
_file_grid_cmp(const void *a,
const void *b)
{
const Elm_Object_Item *ga = a;
const Elm_Object_Item *gb = b;
const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
if (ca == grid_itc[ELM_DIRECTORY])
{
if (cb != grid_itc[ELM_DIRECTORY])
return -1;
}
else if (cb == grid_itc[ELM_DIRECTORY])
{
return 1;
}
return strcoll(elm_object_item_data_get(ga), elm_object_item_data_get(gb));
}
static int
_file_list_cmp(const void *a,
const void *b)
{
const Elm_Object_Item *la = a;
const Elm_Object_Item *lb = b;
const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
if (ca == list_itc[ELM_DIRECTORY])
{
if (cb != list_itc[ELM_DIRECTORY])
return -1;
}
else if (cb == list_itc[ELM_DIRECTORY])
{
return 1;
}
return strcoll(elm_object_item_data_get(la), elm_object_item_data_get(lb));
}
static void
_signal_first(Listing_Request *lreq)
{
if (!lreq->first) return;
evas_object_smart_callback_call
(lreq->obj, SIG_DIRECTORY_OPEN, (void *)lreq->path);
if (!lreq->parent_it)
{
elm_genlist_clear(lreq->sd->files_list);
elm_gengrid_clear(lreq->sd->files_grid);
eina_stringshare_replace(&lreq->sd->path, lreq->path);
_anchors_do(lreq->obj, lreq->path);
elm_object_text_set(lreq->sd->name_entry, "");
}
lreq->first = EINA_FALSE;
}
static void
_ls_main_cb(void *data,
Eio_File *handler,
const Eina_File_Direct_Info *info)
{
Listing_Request *lreq = data;
Elm_Object_Item *item;
int itcn = ELM_FILE_UNKNOW;
if (eio_file_check(handler)) return;
if (!lreq->sd->files_list || !lreq->sd->files_grid
|| lreq->sd->current != handler)
{
eio_file_cancel(handler);
return;
}
_signal_first(lreq);
if (info->type == EINA_FILE_DIR)
itcn = ELM_DIRECTORY;
else
{
if (evas_object_image_extension_can_load_get
(info->path + info->name_start))
itcn = ELM_FILE_IMAGE;
}
if (lreq->sd->mode == ELM_FILESELECTOR_LIST)
{
item = elm_genlist_item_sorted_insert(lreq->sd->files_list, list_itc[itcn],
eina_stringshare_add(info->path),
lreq->parent_it,
((lreq->sd->expand) && (itcn == ELM_DIRECTORY))
? ELM_GENLIST_ITEM_TREE : ELM_GENLIST_ITEM_NONE,
_file_list_cmp, NULL, NULL);
if (lreq->selected && !strcmp(info->path, lreq->selected))
{
elm_genlist_item_selected_set(item, EINA_TRUE);
elm_object_text_set(lreq->sd->name_entry, ecore_file_file_get(info->path));
}
}
else if (lreq->sd->mode == ELM_FILESELECTOR_GRID)
{
item = elm_gengrid_item_sorted_insert(lreq->sd->files_grid, grid_itc[itcn],
eina_stringshare_add(info->path),
_file_grid_cmp, NULL, NULL);
if (lreq->selected && !strcmp(info->path, lreq->selected))
{
elm_gengrid_item_selected_set(item, EINA_TRUE);
elm_object_text_set(lreq->sd->name_entry, ecore_file_file_get(info->path));
}
}
}
static void
_listing_request_cleanup(Listing_Request *lreq)
{
EINA_REFCOUNT_UNREF(lreq->sd) _elm_fileselector_smart_del_do(lreq->sd);
eina_stringshare_del(lreq->path);
eina_stringshare_del(lreq->selected);
free(lreq);
}
static void
_ls_done_cb(void *data, Eio_File *handler __UNUSED__)
{
Listing_Request *lreq = data;
_signal_first(lreq);
elm_progressbar_pulse(lreq->sd->spinner, EINA_FALSE);
elm_layout_signal_emit(lreq->obj, "elm,action,spinner,hide", "elm");
lreq->sd->current = NULL;
_listing_request_cleanup(lreq);
}
static void
_ls_error_cb(void *data, Eio_File *handler, int error __UNUSED__)
{
Listing_Request *lreq = data;
elm_progressbar_pulse(lreq->sd->spinner, EINA_FALSE);
elm_layout_signal_emit(lreq->obj, "elm,action,spinner,hide", "elm");
if (lreq->sd->current == handler)
lreq->sd->current = NULL;
_listing_request_cleanup(lreq);
}
#endif
static void
_populate(Evas_Object *obj,
const char *path,
Elm_Object_Item *parent_it,
const char *selected)
{
ELM_FILESELECTOR_DATA_GET(obj, sd);
if (!path) return;
#ifdef HAVE_EIO
Listing_Request *lreq;
#else
Eina_List *files = NULL, *dirs = NULL;
Eina_File_Direct_Info *file;
Eina_Iterator *it;
const char *entry;
#endif
#ifndef HAVE_EIO /* synchronous listing path */
if (!ecore_file_is_dir(path)) return;
it = eina_file_stat_ls(path);
if (!it) return;
evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
if (!parent_it)
{
elm_genlist_clear(sd->files_list);
elm_gengrid_clear(sd->files_grid);
eina_stringshare_replace(&sd->path, path);
_anchors_do(obj, path);
elm_object_text_set(sd->name_entry, "");
}
EINA_ITERATOR_FOREACH(it, file)
{
const char *filename;
if (file->path[file->name_start] == '.') continue;
filename = eina_stringshare_add(file->path);
if (file->type == EINA_FILE_DIR)
dirs = eina_list_append(dirs, filename);
else if (!sd->only_folder && _check_filters(sd->current_filter, filename))
files = eina_list_append(files, filename);
}
eina_iterator_free(it);
files = eina_list_sort
(files, eina_list_count(files), EINA_COMPARE_CB(strcoll));
dirs = eina_list_sort
(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
EINA_LIST_FREE(dirs, entry)
{
if (sd->mode == ELM_FILESELECTOR_LIST)
elm_genlist_item_append(sd->files_list, list_itc[ELM_DIRECTORY],
entry, /* item data */
parent_it,
(sd->expand)
? ELM_GENLIST_ITEM_TREE : ELM_GENLIST_ITEM_NONE,
NULL, NULL);
else if (sd->mode == ELM_FILESELECTOR_GRID)
elm_gengrid_item_append(sd->files_grid, grid_itc[ELM_DIRECTORY],
entry, /* item data */
NULL, NULL);
}
EINA_LIST_FREE(files, entry)
{
Elm_Fileselector_Type type =
evas_object_image_extension_can_load_fast_get(entry) ?
ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
if (sd->mode == ELM_FILESELECTOR_LIST)
{
Elm_Object_Item *item;
item = elm_genlist_item_append(sd->files_list, list_itc[type],
entry, /* item data */
parent_it, ELM_GENLIST_ITEM_NONE,
NULL, NULL);
if (selected && !strcmp(entry, selected))
{
elm_genlist_item_selected_set(item, EINA_TRUE);
elm_object_text_set(sd->name_entry, ecore_file_file_get(entry));
}
}
else if (sd->mode == ELM_FILESELECTOR_GRID)
{
Elm_Object_Item *item;
item = elm_gengrid_item_append(sd->files_grid, grid_itc[type],
entry, /* item data */
NULL, NULL);
if (selected && !strcmp(entry, selected))
{
elm_gengrid_item_selected_set(item, EINA_TRUE);
elm_object_text_set(sd->name_entry, ecore_file_file_get(entry));
}
}
}
#else /* asynchronous listing path */
if (sd->expand && sd->current) return;
if (sd->current) eio_file_cancel(sd->current);
lreq = malloc(sizeof (Listing_Request));
if (!lreq) return;
lreq->sd = sd;
EINA_REFCOUNT_REF(lreq->sd);
lreq->parent_it = parent_it; /* FIXME: should we refcount the parent_it ? */
lreq->obj = obj;
lreq->path = eina_stringshare_add(path);
lreq->first = EINA_TRUE;
if (selected)
lreq->selected = eina_stringshare_add(selected);
else
lreq->selected = NULL;
sd->current = eio_file_stat_ls(path, _ls_filter_cb, _ls_main_cb,
_ls_done_cb, _ls_error_cb, lreq);
elm_progressbar_pulse(sd->spinner, EINA_TRUE);
elm_layout_signal_emit(lreq->obj, "elm,action,spinner,show", "elm");
#endif
}
static void
_on_list_expanded(void *data,
Evas_Object *obj __UNUSED__,
void *event_info)
{
Elm_Object_Item *it = event_info;
const char *path = elm_object_item_data_get(it);
_populate(data, path, it, NULL);
}
static void
_on_list_contracted(void *data __UNUSED__,
Evas_Object *obj __UNUSED__,
void *event_info)
{
Elm_Object_Item *it = event_info;
elm_genlist_item_subitems_clear(it);
}
static void
_on_list_expand_req(void *data __UNUSED__,
Evas_Object *obj __UNUSED__,
void *event_info)
{
Elm_Object_Item *it = event_info;
elm_genlist_item_expanded_set(it, EINA_TRUE);
}
static void
_on_list_contract_req(void *data __UNUSED__,
Evas_Object *obj __UNUSED__,
void *event_info)
{
Elm_Object_Item *it = event_info;
elm_genlist_item_expanded_set(it, EINA_FALSE);
}
static Eina_Bool
_populate_do(void *data)
{
struct sel_data *sdata = data;
const char *p;
ELM_FILESELECTOR_DATA_GET(sdata->fs, sd);
/* keep a ref to path 'couse it will be destroyed by _populate */
p = eina_stringshare_add(sdata->path);
_populate(sdata->fs, p, NULL, NULL);
eina_stringshare_del(p);
sd->populate_idler = NULL;
free(sdata);
return ECORE_CALLBACK_CANCEL;
}
static void
_on_item_double_clicked(void *data,
Evas_Object *obj __UNUSED__,
void *event_info)
{
//This event_info could be a list or gengrid item
Elm_Object_Item *it = event_info;
struct sel_data *sdata;
void *old_sdata;
const char *path;
Eina_Bool is_dir;
ELM_FILESELECTOR_DATA_GET(data, sd);
if (!sd->double_tap_navigation) return;
path = elm_object_item_data_get(it);
if (!path) return;
is_dir = ecore_file_is_dir(path);
if (!is_dir) return;
sdata = malloc(sizeof(*sdata));
if (!sdata) return;
sdata->fs = data;
sdata->path = path;
if (sd->populate_idler)
{
old_sdata = ecore_idler_del(sd->populate_idler);
free(old_sdata);
}
sd->populate_idler = ecore_idler_add(_populate_do, sdata);
}
static void
_on_item_activated(void *data,
Evas_Object *obj __UNUSED__,
void *event_info)
{
//This event_info could be a list or gengrid item
Elm_Object_Item *it = event_info;
const char *path;
Eina_Bool is_dir;
path = elm_object_item_data_get(it);
if (!path) return;
is_dir = ecore_file_is_dir(path);
if (is_dir) return;
evas_object_smart_callback_call(data, SIG_ACTIVATED, (void *)path);
}
static void
_on_item_selected(void *data,
Evas_Object *obj __UNUSED__,
void *event_info)
{
//This event_info could be a list or gengrid item
Elm_Object_Item *it = event_info;
struct sel_data *sdata;
void *old_sdata;
const char *path;
char *parent_path;
Eina_Bool is_dir;
ELM_FILESELECTOR_DATA_GET(data, sd);
path = elm_object_item_data_get(it);
if (!path) return;
is_dir = ecore_file_is_dir(path);
/* We need to send callback when:
* - path is dir and mode is ONLY FOLDER
* - path is file and mode is NOT ONLY FOLDER */
if (is_dir == sd->only_folder)
{
elm_object_text_set(sd->name_entry, ecore_file_file_get(path));
evas_object_smart_callback_call(data, SIG_SELECTED, (void *)path);
}
else
elm_object_text_set(sd->name_entry, "");
/* We need to populate, if path is directory and:
* - mode is GRID;
* - mode is LIST and 'not expand mode';
* in other cases update anchors. */
if (!is_dir) return;
if (sd->expand && sd->mode == ELM_FILESELECTOR_LIST)
{
if (sd->only_folder)
{
parent_path = ecore_file_dir_get(path);
eina_stringshare_replace(&sd->path, parent_path);
_anchors_do(data, parent_path);
free(parent_path);
}
else
{
eina_stringshare_replace(&sd->path, path);
_anchors_do(data, path);
}
return;
}
if (sd->double_tap_navigation) return;
sdata = malloc(sizeof(*sdata));
if (!sdata) return;
sdata->fs = data;
sdata->path = path;
if (sd->populate_idler)
{
old_sdata = ecore_idler_del(sd->populate_idler);
free(old_sdata);
}
sd->populate_idler = ecore_idler_add(_populate_do, sdata);
}
static void
_on_dir_up(void *data,
Evas_Object *obj __UNUSED__,
void *event_info __UNUSED__)
{
Evas_Object *fs = data;
char *parent;
ELM_FILESELECTOR_DATA_GET(fs, sd);
parent = ecore_file_dir_get(sd->path);
_populate(fs, parent, NULL, NULL);
free(parent);
}
static void
_home(void *data,
Evas_Object *obj __UNUSED__,
void *event_info __UNUSED__)
{
Evas_Object *fs = data;
_populate(fs, getenv("HOME"), NULL, NULL);
}
static void
_current_filer_changed(void *data,
Evas_Object *obj,
void *event_info __UNUSED__)
{
Elm_Fileselector_Filter *filter = data;
if (filter->sd->current_filter == filter) return;
elm_object_text_set(obj, filter->filter_name);
filter->sd->current_filter = filter;
_populate(filter->sd->obj, filter->sd->path, NULL, NULL);
}
static void
_ok(void *data,
Evas_Object *obj __UNUSED__,
void *event_info __UNUSED__)
{
const char *name;
const char *selection = NULL;
Evas_Object *fs = data;
ELM_FILESELECTOR_DATA_GET(fs, sd);
if (!sd->path)
{
evas_object_smart_callback_call(fs, SIG_DONE, NULL);
return;
}
name = elm_object_text_get(sd->name_entry);
if (name && name[0] != '\0')
selection = eina_stringshare_printf("%s/%s", sd->path, name);
else
selection = eina_stringshare_add(elm_fileselector_selected_get(fs));
evas_object_smart_callback_call(fs, SIG_DONE, (void *)selection);
eina_stringshare_del(selection);
}
static void
_canc(void *data,
Evas_Object *obj __UNUSED__,
void *event_info __UNUSED__)
{
Evas_Object *fs = data;
evas_object_smart_callback_call(fs, SIG_DONE, NULL);
}
static void
_on_text_clicked(void *data __UNUSED__,
Evas_Object *obj,
void *event_info __UNUSED__)
{
ELM_FILESELECTOR_DATA_GET(data, sd);
/* FIXME: When anchor is clicked, current callback is also called.
* But when it is "anchor,clicked" entry should be unfocused, so we remove
* focus in achor_clicked.
*
* Check if entry is focused.
* It will be so if empty place (not anchor) was clicked. */
if (!elm_object_focus_get(obj)) return;
elm_entry_entry_set(obj, sd->path);
elm_entry_cursor_pos_set(obj, eina_stringshare_strlen(sd->path));
}
static void
_on_text_activated(void *data,
Evas_Object *obj,
void *event_info __UNUSED__)
{
Evas_Object *fs = data;
const char *p, *path;
char *dir;
ELM_FILESELECTOR_DATA_GET(fs, sd);
path = elm_object_text_get(obj);
if (!ecore_file_exists(path))
{
evas_object_smart_callback_call(fs, SIG_SELECTED, (void *)path);
evas_object_smart_callback_call(fs, SIG_SELECTED_INVALID, (void *)path);
goto end;
}
if (ecore_file_is_dir(path))
{
// keep a ref to path 'couse it will be destroyed by _populate
p = eina_stringshare_add(path);
_populate(fs, p, NULL, NULL);
eina_stringshare_del(p);
if (sd->only_folder)
evas_object_smart_callback_call(fs, SIG_SELECTED, (void *)path);
goto end;
}
dir = ecore_file_dir_get(path);
if (!dir) goto end;
if (strcmp(dir, sd->path))
{
_populate(fs, dir, NULL, path);
if (sd->only_folder)
evas_object_smart_callback_call(fs, SIG_SELECTED, (void *)path);
}
else
{
if (sd->mode == ELM_FILESELECTOR_LIST)
{
Elm_Object_Item *item = elm_genlist_first_item_get(sd->files_list);
while (item)
{
const char *item_path = elm_object_item_data_get(item);
if (!strcmp(item_path, path))
{
elm_genlist_item_selected_set(item, EINA_TRUE);
elm_object_text_set(sd->name_entry, ecore_file_file_get(path));
break;
}
item = elm_genlist_item_next_get(item);
}
}
else
{
Elm_Object_Item *item = elm_gengrid_first_item_get(sd->files_list);
while (item)
{
const char *item_path = elm_object_item_data_get(item);
if (!strcmp(item_path, path))
{
elm_gengrid_item_selected_set(item, EINA_TRUE);
elm_object_text_set(sd->name_entry, ecore_file_file_get(path));
break;
}
item = elm_gengrid_item_next_get(item);
}
}
}
free(dir);
end:
elm_object_focus_set(obj, EINA_FALSE);
}
static void
_on_text_unfocused(void *data,
Evas_Object *obj __UNUSED__,
void *event_info __UNUSED__)
{
ELM_FILESELECTOR_DATA_GET(data, sd);
_anchors_do(data, sd->path);
}
static void
_anchor_clicked(void *data,
Evas_Object *obj __UNUSED__,
void *event_info)
{
Elm_Entry_Anchor_Info *info = event_info;
Evas_Object *fs = data;
const char *p;
// keep a ref to path 'couse it will be destroyed by _populate
p = eina_stringshare_add(info->name);
_populate(fs, p, NULL, NULL);
eina_stringshare_del(p);
/* After anchor was clicked, entry will be focused, and will be editable.
* It's wrong. So remove focus. */
elm_object_focus_set(obj, EINA_FALSE);
}
static void
_elm_fileselector_smart_add(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
{
Evas_Object *ic, *bt, *li, *en, *grid, *pb;
int s;
Elm_Fileselector_Smart_Data *priv = _pd;
EINA_REFCOUNT_INIT(priv);
eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
elm_widget_sub_object_parent_add(obj);
elm_widget_can_focus_set(obj, EINA_FALSE);
priv->expand = !!_elm_config->fileselector_expand_enable;
priv->double_tap_navigation = !!_elm_config->fileselector_double_tap_navigation_enable;
if (!elm_layout_theme_set
(obj, "fileselector", "base", elm_widget_style_get(obj)))
CRITICAL("Failed to set layout!");
// up btn
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "arrow_up");
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
bt = elm_button_add(obj);
elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
elm_object_part_content_set(bt, "icon", ic);
elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Up"));
evas_object_size_hint_align_set(bt, 0.0, 0.0);
evas_object_smart_callback_add(bt, "clicked", _on_dir_up, obj);
elm_widget_sub_object_add(obj, bt);
priv->up_button = bt;
// home btn
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "home");
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
bt = elm_button_add(obj);
elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
elm_object_part_content_set(bt, "icon", ic);
elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Home"));
evas_object_size_hint_align_set(bt, 0.0, 0.0);
evas_object_smart_callback_add(bt, "clicked", _home, obj);
elm_widget_sub_object_add(obj, bt);
priv->home_button = bt;
// spinner
pb = elm_progressbar_add(obj);
elm_widget_sub_object_add(obj, pb);
priv->spinner = pb;
list_itc[ELM_DIRECTORY]->func.content_get =
grid_itc[ELM_DIRECTORY]->func.content_get = _itc_icon_folder_get;
list_itc[ELM_FILE_IMAGE]->func.content_get =
grid_itc[ELM_FILE_IMAGE]->func.content_get = _itc_icon_image_get;
list_itc[ELM_FILE_UNKNOW]->func.content_get =
grid_itc[ELM_FILE_UNKNOW]->func.content_get = _itc_icon_file_get;
li = elm_genlist_add(obj);
elm_widget_mirrored_automatic_set(li, EINA_FALSE);
evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_min_set(li, 100, 100);
grid = elm_gengrid_add(obj);
elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
// XXX: will fail for dynamic finger size changing
s = elm_config_finger_size_get() * 2;
elm_gengrid_item_size_set(grid, s, s);
elm_gengrid_align_set(grid, 0.0, 0.0);
evas_object_smart_callback_add(li, "selected", _on_item_selected, obj);
evas_object_smart_callback_add(li, "clicked,double", _on_item_double_clicked, obj);
evas_object_smart_callback_add(li, "activated", _on_item_activated, obj);
evas_object_smart_callback_add
(li, "expand,request", _on_list_expand_req, obj);
evas_object_smart_callback_add
(li, "contract,request", _on_list_contract_req, obj);
evas_object_smart_callback_add(li, "expanded", _on_list_expanded, obj);
evas_object_smart_callback_add(li, "contracted", _on_list_contracted, obj);
evas_object_smart_callback_add(grid, "selected", _on_item_selected, obj);
evas_object_smart_callback_add(grid, "clicked,double", _on_item_double_clicked, obj);
evas_object_smart_callback_add(grid, "activated", _on_item_activated, obj);
elm_widget_sub_object_add(obj, li);
elm_widget_sub_object_add(obj, grid);
priv->files_list = li;
priv->files_grid = grid;
// path entry
en = elm_entry_add(obj);
elm_entry_scrollable_set(en, EINA_TRUE);
elm_widget_mirrored_automatic_set(en, EINA_FALSE);
elm_entry_single_line_set(en, EINA_TRUE);
elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
evas_object_smart_callback_add(en, "clicked", _on_text_clicked, obj);
evas_object_smart_callback_add(en, "unfocused", _on_text_unfocused, obj);
evas_object_smart_callback_add(en, "activated", _on_text_activated, obj);
elm_widget_sub_object_add(obj, en);
priv->path_entry = en;
// name entry
en = elm_entry_add(obj);
elm_entry_scrollable_set(en, EINA_TRUE);
elm_widget_mirrored_automatic_set(en, EINA_FALSE);
elm_entry_editable_set(en, EINA_TRUE);
elm_entry_single_line_set(en, EINA_TRUE);
elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_widget_sub_object_add(obj, en);
priv->name_entry = en;
elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
elm_fileselector_is_save_set(obj, EINA_FALSE);
eo_do(obj, elm_wdg_theme(NULL));
}
static void
_elm_fileselector_smart_del(Eo *obj EINA_UNUSED, void *_pd, va_list *list EINA_UNUSED)
{
Elm_Fileselector_Smart_Data *sd = _pd;
Elm_Fileselector_Filter *filter;
#ifdef HAVE_EIO
if (sd->current) eio_file_cancel(sd->current);
#endif
EINA_LIST_FREE(sd->filter_list, filter)
{
eina_stringshare_del(filter->filter_name);
free(filter->mime_types[0]);
free(filter->mime_types);
free(filter);
}
sd->files_list = NULL;
sd->files_grid = NULL;
/* this one matching EINA_REFCOUNT_INIT() */
EINA_REFCOUNT_UNREF(sd) _elm_fileselector_smart_del_do(sd);
}
EAPI Evas_Object *
elm_fileselector_add(Evas_Object *parent)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
Evas_Object *obj = eo_add(MY_CLASS, parent);
eo_unref(obj);
return obj;
}
static void
_constructor(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
{
Elm_Fileselector_Smart_Data *sd = _pd;
sd->obj = obj;
eo_do_super(obj, MY_CLASS, eo_constructor());
eo_do(obj,
evas_obj_type_set(MY_CLASS_NAME),
evas_obj_smart_callbacks_descriptions_set(_smart_callbacks, NULL));
}
EAPI void
elm_fileselector_is_save_set(Evas_Object *obj,
Eina_Bool is_save)
{
ELM_FILESELECTOR_CHECK(obj);
eo_do(obj, elm_obj_fileselector_is_save_set(is_save));
}
static void
_is_save_set(Eo *obj, void *_pd, va_list *list)
{
Eina_Bool is_save = va_arg(*list, int);
Elm_Fileselector_Smart_Data *sd = _pd;
elm_object_disabled_set(sd->name_entry, !is_save);
if (is_save) elm_layout_signal_emit(obj, "elm,state,save,on", "elm");
else elm_layout_signal_emit(obj, "elm,state,save,off", "elm");
}
EAPI Eina_Bool
elm_fileselector_is_save_get(const Evas_Object *obj)
{
ELM_FILESELECTOR_CHECK(obj) EINA_FALSE;
Eina_Bool ret = EINA_FALSE;
eo_do((Eo *) obj, elm_obj_fileselector_is_save_get(&ret));
return ret;
}
static void
_is_save_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
{
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
Elm_Fileselector_Smart_Data *sd = _pd;
*ret = !elm_object_disabled_get(sd->name_entry);
}
EAPI void
elm_fileselector_folder_only_set(Evas_Object *obj,
Eina_Bool only)
{
ELM_FILESELECTOR_CHECK(obj);
eo_do(obj, elm_obj_fileselector_folder_only_set(only));
}
static void
_folder_only_set(Eo *obj, void *_pd, va_list *list)
{
Eina_Bool only = va_arg(*list, int);
Elm_Fileselector_Smart_Data *sd = _pd;
if (sd->only_folder == only) return;
sd->only_folder = !!only;
if (sd->path) _populate(obj, sd->path, NULL, NULL);
}
EAPI Eina_Bool
elm_fileselector_folder_only_get(const Evas_Object *obj)
{
ELM_FILESELECTOR_CHECK(obj) EINA_FALSE;
Eina_Bool ret = EINA_FALSE;
eo_do((Eo *) obj, elm_obj_fileselector_folder_only_get(&ret));
return ret;
}
static void
_folder_only_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
{
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
Elm_Fileselector_Smart_Data *sd = _pd;
*ret = sd->only_folder;
}
EAPI void
elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
Eina_Bool visible)
{
ELM_FILESELECTOR_CHECK(obj);
eo_do(obj, elm_obj_fileselector_buttons_ok_cancel_set(visible));
}
static void
_buttons_ok_cancel_set(Eo *obj, void *_pd, va_list *list)
{
Eina_Bool visible = va_arg(*list, int);
Evas_Object *bt;
Elm_Fileselector_Smart_Data *sd = _pd;
if (visible && (!sd->ok_button))
{
// cancel btn
bt = elm_button_add(obj);
elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Cancel"));
evas_object_smart_callback_add(bt, "clicked", _canc, obj);
sd->cancel_button = bt;
// ok btn
bt = elm_button_add(obj);
elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
elm_object_domain_translatable_text_set(bt, PACKAGE, N_("OK"));
evas_object_smart_callback_add(bt, "clicked", _ok, obj);
sd->ok_button = bt;
eo_do(obj, elm_wdg_theme(NULL));
}
else if (!visible)
{
evas_object_del(sd->cancel_button);
sd->cancel_button = NULL;
evas_object_del(sd->ok_button);
sd->ok_button = NULL;
}
}
EAPI Eina_Bool
elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
{
ELM_FILESELECTOR_CHECK(obj) EINA_FALSE;
Eina_Bool ret = EINA_FALSE;
eo_do((Eo *) obj, elm_obj_fileselector_buttons_ok_cancel_get(&ret));
return ret;
}
static void
_buttons_ok_cancel_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
{
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
Elm_Fileselector_Smart_Data *sd = _pd;
*ret = sd->ok_button ? EINA_TRUE : EINA_FALSE;
}
EAPI void
elm_fileselector_expandable_set(Evas_Object *obj,
Eina_Bool expand)
{
ELM_FILESELECTOR_CHECK(obj);
eo_do(obj, elm_obj_fileselector_expandable_set(expand));
}
static void
_expandable_set(Eo *obj, void *_pd, va_list *list)
{
Eina_Bool expand = va_arg(*list, int);
Elm_Fileselector_Smart_Data *sd = _pd;
sd->expand = !!expand;
if (sd->path) _populate(obj, sd->path, NULL, NULL);
}
EAPI Eina_Bool
elm_fileselector_expandable_get(const Evas_Object *obj)
{
ELM_FILESELECTOR_CHECK(obj) EINA_FALSE;
Eina_Bool ret = EINA_FALSE;
eo_do((Eo *) obj, elm_obj_fileselector_expandable_get(&ret));
return ret;
}
static void
_expandable_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
{
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
Elm_Fileselector_Smart_Data *sd = _pd;
*ret = sd->expand;
}
EAPI void
elm_fileselector_path_set(Evas_Object *obj,
const char *_path)
{
ELM_FILESELECTOR_CHECK(obj);
eo_do(obj, elm_obj_fileselector_path_set(_path));
}
static void
_path_set(Eo *obj, void *_pd EINA_UNUSED, va_list *list)
{
const char *_path = va_arg(*list, const char *);
char *path;
path = ecore_file_realpath(_path);
_populate(obj, path, NULL, NULL);
free(path);
}
EAPI const char *
elm_fileselector_path_get(const Evas_Object *obj)
{
ELM_FILESELECTOR_CHECK(obj) NULL;
const char *ret = NULL;
eo_do((Eo *) obj, elm_obj_fileselector_path_get(&ret));
return ret;
}
static void
_path_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
{
const char **ret = va_arg(*list, const char **);
Elm_Fileselector_Smart_Data *sd = _pd;
*ret = sd->path;
}
EAPI void
elm_fileselector_mode_set(Evas_Object *obj,
Elm_Fileselector_Mode mode)
{
ELM_FILESELECTOR_CHECK(obj);
eo_do(obj, elm_obj_fileselector_mode_set(mode));
}
static void
_mode_set(Eo *obj, void *_pd, va_list *list)
{
Elm_Fileselector_Mode mode = va_arg(*list, Elm_Fileselector_Mode);
Elm_Fileselector_Smart_Data *sd = _pd;
if (mode == sd->mode) return;
evas_object_hide(elm_layout_content_unset(obj, "elm.swallow.files"));
if (mode == ELM_FILESELECTOR_LIST)
elm_layout_content_set(obj, "elm.swallow.files", sd->files_list);
else elm_layout_content_set(obj, "elm.swallow.files", sd->files_grid);
sd->mode = mode;
_populate(obj, sd->path, NULL, NULL);
}
EAPI Elm_Fileselector_Mode
elm_fileselector_mode_get(const Evas_Object *obj)
{
ELM_FILESELECTOR_CHECK(obj) ELM_FILESELECTOR_LAST;
Elm_Fileselector_Mode ret = ELM_FILESELECTOR_LAST;
eo_do((Eo *) obj, elm_obj_fileselector_mode_get(&ret));
return ret;
}
static void
_mode_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
{
Elm_Fileselector_Mode *ret = va_arg(*list, Elm_Fileselector_Mode *);
Elm_Fileselector_Smart_Data *sd = _pd;
*ret = sd->mode;
}
EAPI const char *
elm_fileselector_selected_get(const Evas_Object *obj)
{
ELM_FILESELECTOR_CHECK(obj) NULL;
const char *ret = NULL;
eo_do((Eo *) obj, elm_obj_fileselector_selected_get(&ret));
return ret;
}
static void
_selected_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
{
const char *fp;
const char **ret = va_arg(*list, const char **);
*ret = NULL;
Elm_Fileselector_Smart_Data *sd = _pd;
if (!sd->path) return;
fp = elm_object_text_get(sd->path_entry);
if (ecore_file_exists(fp))
{
eina_stringshare_replace(&sd->selection, fp);
*ret = sd->selection;
return;
}
*ret = sd->path;
if (sd->mode == ELM_FILESELECTOR_LIST)
{
Elm_Object_Item *gl_it = elm_genlist_selected_item_get(sd->files_list);
if (gl_it) *ret = elm_object_item_data_get(gl_it);
}
else
{
Elm_Object_Item *gg_it = elm_gengrid_selected_item_get(sd->files_grid);
if (gg_it) *ret = elm_object_item_data_get(gg_it);
}
}
EAPI Eina_Bool
elm_fileselector_selected_set(Evas_Object *obj,
const char *_path)
{
ELM_FILESELECTOR_CHECK(obj) EINA_FALSE;
Eina_Bool ret = EINA_FALSE;
eo_do(obj, elm_obj_fileselector_selected_set(_path, &ret));
return ret;
}
static void
_selected_set(Eo *obj, void *_pd, va_list *list)
{
const char *_path = va_arg(*list, const char *);
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
char *selected;
if (ret) *ret = EINA_TRUE;
char *path;
Elm_Fileselector_Smart_Data *sd = _pd;
path = ecore_file_realpath(_path);
if (ecore_file_is_dir(path)) _populate(obj, path, NULL, NULL);
else
{
if (!ecore_file_exists(path))
{
if (ret) *ret = EINA_FALSE;
goto clean_up;
}
selected = ecore_file_dir_get(path);
_populate(obj, selected, NULL, NULL);
eina_stringshare_replace(&sd->selection, path);
free(selected);
}
clean_up:
free(path);
}
EAPI Eina_Bool
elm_fileselector_mime_types_filter_append(Evas_Object *obj, const char *mime_type, const char *filter_name)
{
ELM_FILESELECTOR_CHECK(obj) EINA_FALSE;
Eina_Bool ret = EINA_FALSE;
eo_do(obj, elm_obj_fileselector_mime_types_filter_append(mime_type, filter_name, &ret));
return ret;
}
static void
_mime_types_filter_append(Eo *obj, void *_pd, va_list *list)
{
const char *mime_types = va_arg(*list, const char *);
const char *filter_name = va_arg(*list, const char *);
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
Elm_Fileselector_Smart_Data *sd;
Elm_Fileselector_Filter *ff;
Eina_Bool int_ret = EINA_FALSE;
Eina_Bool need_theme = EINA_FALSE;
if (!mime_types) goto end;
sd = _pd;
ff = malloc(sizeof(Elm_Fileselector_Filter));
if (!ff) goto end;
if (filter_name)
ff->filter_name = eina_stringshare_add(filter_name);
else
ff->filter_name = eina_stringshare_add(mime_types);
ff->sd = sd;
ff->mime_types = eina_str_split(mime_types, ",", 0);
if (!sd->filter_list)
{
sd->current_filter = ff;
sd->filter_hoversel = elm_hoversel_add(obj);
elm_object_text_set(sd->filter_hoversel, ff->filter_name);
need_theme = EINA_TRUE;
}
elm_hoversel_item_add(sd->filter_hoversel, ff->filter_name, NULL, ELM_ICON_NONE, _current_filer_changed, ff);
sd->filter_list = eina_list_append(sd->filter_list, ff);
_populate(obj, sd->path, NULL, NULL);
if (need_theme)
eo_do(obj, elm_wdg_theme(NULL));
int_ret = EINA_TRUE;
end:
if (ret) *ret = int_ret;
}
EAPI void
elm_fileselector_filters_clear(Evas_Object *obj)
{
ELM_FILESELECTOR_CHECK(obj);
eo_do(obj, elm_obj_fileselector_filters_clear());
}
static void
_filters_clear(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
{
Elm_Fileselector_Smart_Data *sd = _pd;
Elm_Fileselector_Filter *filter;
EINA_LIST_FREE(sd->filter_list, filter)
{
eina_stringshare_del(filter->filter_name);
free(filter->mime_types[0]);
free(filter->mime_types);
free(filter);
}
ELM_SAFE_FREE(sd->filter_hoversel, evas_object_del);
_populate(obj, sd->path, NULL, NULL);
}
static void
_elm_fileselector_smart_focus_next_manager_is(Eo *obj EINA_UNUSED, void *_pd EINA_UNUSED, va_list *list)
{
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
*ret = EINA_FALSE;
}
static void
_elm_fileselector_smart_focus_direction_manager_is(Eo *obj EINA_UNUSED, void *_pd EINA_UNUSED, va_list *list)
{
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
*ret = EINA_FALSE;
}
static void
_elm_fileselector_smart_text_set(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
{
Elm_Fileselector_Smart_Data *sd = _pd;
const char *part = va_arg(*list, const char *);
const char *label = va_arg(*list, const char *);
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
if (ret) *ret = EINA_FALSE;
Eina_Bool int_ret = EINA_FALSE;
if (!part) return;
if (sd->ok_button && !strcmp(part, "ok"))
{
elm_object_text_set(sd->ok_button, label);
int_ret = EINA_TRUE;
}
else if (sd->cancel_button && !strcmp(part, "cancel"))
{
elm_object_text_set(sd->cancel_button, label);
int_ret = EINA_TRUE;
}
else
eo_do_super(obj, MY_CLASS, elm_obj_layout_text_set(part, label, &int_ret));
if (ret) *ret = int_ret;
}
static void
_class_constructor(Eo_Class *klass)
{
unsigned int i;
const Eo_Op_Func_Description func_desc[] = {
EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
EO_OP_FUNC(EVAS_OBJ_SMART_ID(EVAS_OBJ_SMART_SUB_ID_ADD), _elm_fileselector_smart_add),
EO_OP_FUNC(EVAS_OBJ_SMART_ID(EVAS_OBJ_SMART_SUB_ID_DEL), _elm_fileselector_smart_del),
EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_THEME), _elm_fileselector_smart_theme),
EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_NEXT_MANAGER_IS), _elm_fileselector_smart_focus_next_manager_is),
EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_DIRECTION_MANAGER_IS), _elm_fileselector_smart_focus_direction_manager_is),
EO_OP_FUNC(ELM_OBJ_LAYOUT_ID(ELM_OBJ_LAYOUT_SUB_ID_SIZING_EVAL), _elm_fileselector_smart_sizing_eval),
EO_OP_FUNC(ELM_OBJ_LAYOUT_ID(ELM_OBJ_LAYOUT_SUB_ID_TEXT_SET), _elm_fileselector_smart_text_set),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_IS_SAVE_SET), _is_save_set),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_IS_SAVE_GET), _is_save_get),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_FOLDER_ONLY_SET), _folder_only_set),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_FOLDER_ONLY_GET), _folder_only_get),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_BUTTONS_OK_CANCEL_SET), _buttons_ok_cancel_set),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_BUTTONS_OK_CANCEL_GET), _buttons_ok_cancel_get),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_EXPANDABLE_SET), _expandable_set),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_EXPANDABLE_GET), _expandable_get),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_PATH_SET), _path_set),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_PATH_GET), _path_get),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_MODE_SET), _mode_set),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_MODE_GET), _mode_get),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_SELECTED_GET), _selected_get),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_SELECTED_SET), _selected_set),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_MIME_TYPES_FILTER_APPEND), _mime_types_filter_append),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_FILTERS_CLEAR), _filters_clear),
EO_OP_FUNC_SENTINEL
};
eo_class_funcs_set(klass, func_desc);
evas_smart_legacy_type_register(MY_CLASS_NAME, klass);
for (i = 0; i < ELM_FILE_LAST; ++i)
{
list_itc[i] = elm_genlist_item_class_new();
grid_itc[i] = elm_gengrid_item_class_new();
list_itc[i]->item_style = "default";
list_itc[i]->func.text_get = grid_itc[i]->func.text_get =
_itc_text_get;
list_itc[i]->func.state_get = grid_itc[i]->func.state_get =
_itc_state_get;
list_itc[i]->func.del = grid_itc[i]->func.del = _itc_del;
}
}
static void
_class_destructor(Eo_Class *klass EINA_UNUSED)
{
unsigned int i;
for (i = 0; i < ELM_FILE_LAST; ++i)
{
elm_genlist_item_class_free(list_itc[i]);
elm_gengrid_item_class_free(grid_itc[i]);
}
}
static const Eo_Op_Description op_desc[] = {
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_IS_SAVE_SET, "Enable/disable the file name entry box where the user can type in a name for a file, in a given file selector widget."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_IS_SAVE_GET, "Get whether the given file selector is in 'saving dialog' mode."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_FOLDER_ONLY_SET, "Enable/disable folder-only view for a given file selector widget."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_FOLDER_ONLY_GET, "Get whether folder-only view is set for a given file selector widget."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_BUTTONS_OK_CANCEL_SET, "Enable/disable the 'ok' and 'cancel' buttons on a given file selector widget."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_BUTTONS_OK_CANCEL_GET, "Get whether the 'ok' and 'cancel' buttons on a given file selector widget are being shown."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_EXPANDABLE_SET, "Enable/disable a tree view in the given file selector widget, if it's in #ELM_FILESELECTOR_LIST mode."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_EXPANDABLE_GET, "Get whether tree view is enabled for the given file selector widget."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_PATH_SET, "Set, programmatically, the directory that a given file selector widget will display contents from."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_PATH_GET, "Get the parent directory's path that a given file selector widget is displaying."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_MODE_SET, "Set the mode in which a given file selector widget will display (layout) file system entries in its view."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_MODE_GET, "Get the mode in which a given file selector widget is displaying (layouting) file system entries in its view."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_SELECTED_GET, "Get the currently selected item's (full) path, in the given file selector widget."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_SELECTED_SET, "Set, programmatically, the currently selected file/directory in the given file selector widget."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_MIME_TYPES_FILTER_APPEND, "Append mime type filter"),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_FILTERS_CLEAR, "Clear filters"),
EO_OP_DESCRIPTION_SENTINEL
};
static const Eo_Class_Description class_desc = {
EO_VERSION,
MY_CLASS_NAME,
EO_CLASS_TYPE_REGULAR,
EO_CLASS_DESCRIPTION_OPS(&ELM_OBJ_FILESELECTOR_BASE_ID, op_desc, ELM_OBJ_FILESELECTOR_SUB_ID_LAST),
NULL,
sizeof(Elm_Fileselector_Smart_Data),
_class_constructor,
_class_destructor
};
EO_DEFINE_CLASS(elm_obj_fileselector_class_get, &class_desc, ELM_OBJ_LAYOUT_CLASS, NULL);
|