~ubuntu-branches/debian/wheezy/brasero/wheezy

« back to all changes in this revision

Viewing changes to src/brasero-data-project.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette, Pedro Fragoso, Luca Bruno, Josselin Mouette, Emilio Pozuelo Monfort
  • Date: 2009-06-24 18:59:46 UTC
  • mfrom: (1.2.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624185946-iyxkgf3gjptir5y3
Tags: 2.26.2-1
[ Pedro Fragoso ]
* Add myself to Maintainer field
  - Thanks Ondřej Surý
* New upstream version (Closes: #528945)
  - Split package into brasero, libbrasero-media0 and libbrasero-dev
  - Add Replaces to libbrasero-media0
  - Bump libgtk to 2.14.0
  - Remove libnotify Build-dep
  - Add Build-dep libnautilus-extension-dev (>= 2.22.2)
    and install it.
  - Add Build-dep to libsm-dev
  - Add Build-dep on intltool
* Install omf files to prevent crash on Help
* Move gstreamer0.10-plugins-bad to Suggests, and add
  dvdauthor and vcdimager
* Recommends gvfs (Closes: #491827)
* Pass --disable-scrollkeeper in DEB_CONFIGURE_EXTRA_FLAGS
* debian/patches/007-fix-gnome-doc-utils-path.patch:
  - Removed, not needed anymore
* debian/patches/008-fix-volume-identifier-crash.patch:
  - Removed, merged upstream
* debian/patches/011_nautilus_menu_move.patch:
 - Move CD/DVD Creator Menu to Acessories, taken from Ubuntu

[ Luca Bruno ]
* debian/control.in:
  - Add Build-Depend gtk-doc-tools 1.9.
* debian/patches/006-fix-libdvdcss.patch:
  - Removed as applied upstream.

[ Josselin Mouette ]
* New upstream release.
* Update build-dependencies.
* Move the translations and data to a new brasero-common package.
* Rewrite the descriptions.
* Add -dev depends to the development package.
* Remove inappropriate recommends in the library package.
* Let’s not forget dvd+rw-tools so that we can write DVDs too.
* Rework dependencies accordingly.
* Put the nautilus extension in brasero.
* Conflict against nautilus-cd-burner to avoid having two burning 
  extensions.
* Include clean-la.mk and gnome-version.mk; build-depend on 
  gnome-pkg-tools 0.7.
* Don’t run dh_makeshlibs on brasero and libbrasero-plugins.
* 011_nautilus_menu_move.patch: add NoDisplay=true, this icon is 
  duplicating existing functionality (brasero icon in sound&video 
  menu, and nautilus autorun).
* Update list of copyright holders.

[ Emilio Pozuelo Monfort ]
* debian/copyright: updated.

[ Josselin Mouette ]
* copyright: improve indentation, and point to versioned LGPL.
* 090_relibtoolize.patch: add a relibtoolization patch to avoid the 
  rpath crap.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * brasero
4
4
 * Copyright (C) Philippe Rouquier 2007-2008 <bonfire-app@wanadoo.fr>
5
5
 * 
6
 
 * brasero is free software.
7
 
 * 
8
 
 * You may redistribute it and/or modify it under the terms of the
9
 
 * GNU General Public License, as published by the Free Software
10
 
 * Foundation; either version 2 of the License, or (at your option)
11
 
 * any later version.
 
6
 *  Brasero is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
12
10
 * 
13
11
 * brasero is distributed in the hope that it will be useful,
14
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36
34
 
37
35
#include <gio/gio.h>
38
36
 
 
37
#include <gconf/gconf-client.h>
 
38
 
39
39
#include "brasero-data-project.h"
40
40
#include "brasero-marshal.h"
41
41
 
42
42
#include "brasero-utils.h"
 
43
#include "brasero-io.h"
43
44
 
44
45
 
45
46
typedef struct _BraseroDataProjectPrivate BraseroDataProjectPrivate;
71
72
 
72
73
        /* This is a counter for the number of files to be loaded */
73
74
        guint loading;
 
75
 
 
76
        guint is_loading_contents:1;
74
77
};
75
78
 
76
79
#define BRASERO_DATA_PROJECT_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_DATA_PROJECT, BraseroDataProjectPrivate))
442
445
                        break;
443
446
 
444
447
                /* the + 1 is for the separator */
445
 
                escaped_name = g_uri_escape_string (BRASERO_FILE_NODE_NAME (node), NULL, TRUE);
 
448
                escaped_name = g_uri_escape_string (BRASERO_FILE_NODE_NAME (node),
 
449
                                                    G_URI_RESERVED_CHARS_ALLOWED_IN_PATH,
 
450
                                                    FALSE);
446
451
                uri_len += strlen (escaped_name) + 1;
447
452
                list = g_slist_prepend (list, escaped_name);
448
453
        }
542
547
                if (graft)
543
548
                        break;
544
549
 
545
 
                dirname (parent);
 
550
                parent = dirname (parent);
546
551
        }
547
552
 
548
553
        if (!graft) {
718
723
                        return TRUE;
719
724
                }
720
725
 
721
 
                dirname (parent);
 
726
                parent = dirname (parent);
722
727
        }
723
728
 
724
729
        g_free (parent);
792
797
         * node is missing. */
793
798
        graft_parent = g_hash_table_lookup (priv->grafts, parent);
794
799
        while (parent && !graft_parent) {
795
 
                dirname (parent);
 
800
                parent = dirname (parent);
796
801
                graft_parent = g_hash_table_lookup (priv->grafts, parent);
797
802
        }
798
803
        g_free (parent);
841
846
                brasero_utils_unregister_string (key);
842
847
 
843
848
        if (graft) {
844
 
                /* NOTE: no need to free graft->uri since that's key */
 
849
                /* NOTE: no need to free graft->uri since that's the key */
845
850
                g_slist_free (graft->nodes);
846
851
                g_free (graft);
847
852
        }
848
853
}
849
854
 
 
855
static gboolean
 
856
brasero_data_project_graft_is_needed (BraseroDataProject *self,
 
857
                                      BraseroURINode *uri_node)
 
858
{
 
859
        if (uri_node->nodes)
 
860
                return TRUE;
 
861
 
 
862
        /* there aren't any node grafted for this URI. See if we should keep the
 
863
         * URI in the hash; if so, the URI must have parents in the hash */
 
864
        if (brasero_data_project_uri_has_parent (self, uri_node->uri)) {
 
865
                /* here that means that this URI is nowhere in the tree but has
 
866
                 * parent URIs which are grafted. So keep it in the hash to
 
867
                 * signal that URI is not in the tree. */
 
868
                return TRUE;
 
869
        }
 
870
 
 
871
        brasero_data_project_uri_remove_graft (self, uri_node->uri);
 
872
        return FALSE;
 
873
}
 
874
 
850
875
static BraseroURINode *
851
876
brasero_data_project_uri_add_graft (BraseroDataProject *self,
852
877
                                    const gchar *uri)
885
910
        return brasero_data_project_uri_add_graft (self, uri);
886
911
}
887
912
 
888
 
static void
 
913
static BraseroURINode *
889
914
brasero_data_project_uri_graft_nodes (BraseroDataProject *self,
890
915
                                      const gchar *uri)
891
916
{
896
921
 
897
922
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
898
923
 
899
 
        /* see if that's really needed */
900
 
        if (g_hash_table_lookup (priv->grafts, uri))
901
 
                return;
902
 
 
903
924
        /* Find all the nodes that should be grafted.
904
925
         * NOTE: this must be done before asking for a new graft */
905
926
        nodes = brasero_data_project_uri_to_nodes (self, uri);
915
936
                brasero_file_node_graft (iter_node, graft);
916
937
        }
917
938
        g_slist_free (nodes);
 
939
 
 
940
        return graft;
918
941
}
919
942
 
920
943
static void
961
984
                        continue;
962
985
 
963
986
                if (brasero_file_node_is_ancestor (data->node, iter_node))
964
 
                        graft->nodes = g_slist_remove (graft->nodes, iter_node);
 
987
                        brasero_file_node_ungraft (iter_node);
965
988
        }
966
989
 
967
990
        if (graft->nodes)
1014
1037
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
1015
1038
 
1016
1039
#ifdef BUILD_INOTIFY
 
1040
 
1017
1041
        /* remove all monitoring */
1018
1042
        if (node->is_monitored)
1019
1043
                brasero_file_monitor_foreach_cancel (BRASERO_FILE_MONITOR (self),
1051
1075
                graft = BRASERO_FILE_NODE_GRAFT (node);
1052
1076
                uri_node = graft->node;
1053
1077
 
1054
 
                if (g_slist_length (uri_node->nodes) == 1) {
 
1078
                /* NOTE: after this function the graft is invalid */
 
1079
                brasero_file_node_ungraft (node);
 
1080
 
 
1081
                if (!uri_node->nodes) {
1055
1082
                        /* that's the last node grafted for this URI.
1056
1083
                         * There are no more nodes for this URI after.
1057
1084
                         * See if we should keep the URI in the hash;
1058
1085
                         * if so, the URI must have parents in the hash
1059
1086
                         */
1060
 
                        if (brasero_data_project_uri_has_parent (self, uri_node->uri)) {
1061
 
                                /* here that means that this URI is 
1062
 
                                 * nowhere in the tree but has parent
1063
 
                                 * URIs which are grafted. */
1064
 
                                g_slist_free (uri_node->nodes);
1065
 
                                uri_node->nodes = NULL;
1066
 
                        }
1067
 
                        else
 
1087
                        if (!brasero_data_project_uri_has_parent (self, uri_node->uri))
1068
1088
                                brasero_data_project_uri_remove_graft (self, uri_node->uri);
1069
1089
                }
1070
 
                else
1071
 
                        uri_node->nodes = g_slist_remove (uri_node->nodes, node);
1072
1090
        }
1073
1091
        else if (!node->is_imported) {
1074
1092
                gchar *uri;
1075
1093
 
1076
1094
                /* This URI will need a graft if it hasn't one yet */
1077
1095
                uri = brasero_data_project_node_to_uri (self, node);
1078
 
                brasero_data_project_uri_graft_nodes (self, uri);
 
1096
 
 
1097
                if (!g_hash_table_lookup (priv->grafts, uri))
 
1098
                        brasero_data_project_uri_graft_nodes (self, uri);
1079
1099
 
1080
1100
                /* NOTE: since the URI wasn't grafted it has to have a
1081
1101
                 * valid parent that's why we don't check the graft 
1123
1143
                       0);
1124
1144
}
1125
1145
 
 
1146
static void
 
1147
brasero_data_project_convert_to_fake (BraseroDataProject *self,
 
1148
                                      BraseroFileNode *node)
 
1149
{
 
1150
        BraseroURINode *graft;
 
1151
        BraseroDataProjectPrivate *priv;
 
1152
 
 
1153
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
 
1154
 
 
1155
        /* make it a fake directory not to break order */
 
1156
        node->is_fake = TRUE;
 
1157
        node->is_loading = FALSE;
 
1158
        node->is_tmp_parent = FALSE;
 
1159
 
 
1160
        brasero_file_node_ungraft (node);
 
1161
        graft = brasero_data_project_uri_ensure_graft (self, NEW_FOLDER);
 
1162
        brasero_file_node_graft (node, graft);
 
1163
        brasero_data_project_node_changed (self, node);
 
1164
 
 
1165
        /* Remove 2 since we're not going to load its contents */
 
1166
        priv->loading -= 2;
 
1167
        g_signal_emit (self,
 
1168
                       brasero_data_project_signals [PROJECT_LOADED_SIGNAL],
 
1169
                       0,
 
1170
                       priv->loading);
 
1171
}
 
1172
 
1126
1173
void
1127
1174
brasero_data_project_remove_node (BraseroDataProject *self,
1128
1175
                                  BraseroFileNode *node)
1134
1181
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
1135
1182
 
1136
1183
        if (node->is_tmp_parent) {
1137
 
                BraseroURINode *graft;
1138
 
 
1139
1184
                /* This node was created as a temporary parent, it doesn't exist
1140
1185
                 * so we replace it with a fake one. */
1141
1186
 
1142
1187
                /* Don't exclude any URI since it doesn't exist apparently */
1143
1188
 
1144
 
                /* No need to check for deep directory since that was in
1145
 
                 * the project as such. Keep it that way. */
1146
 
 
1147
 
                /* Remove 2 since we're not going to load its contents */
1148
 
                priv->loading -= 2;
1149
 
                g_signal_emit (self,
1150
 
                               brasero_data_project_signals [PROJECT_LOADED_SIGNAL],
1151
 
                               0,
1152
 
                               priv->loading);
1153
 
 
1154
 
                node->is_tmp_parent = FALSE;
1155
 
 
1156
 
                /* make it a fake directory not to break order */
1157
 
                node->is_fake = TRUE;
1158
 
                node->is_loading = FALSE;
1159
 
 
1160
 
                brasero_file_node_ungraft (node);
1161
 
                graft = brasero_data_project_uri_ensure_graft (self, NEW_FOLDER);
1162
 
                brasero_file_node_graft (node, graft);
1163
 
                brasero_data_project_node_changed (self, node);
 
1189
                /* No need to check for deep directory since that was in the
 
1190
                 * project as such. Keep it that way. */
 
1191
 
 
1192
                brasero_data_project_convert_to_fake (self, node);
1164
1193
                return;
1165
1194
        }
1166
1195
        else if (priv->loading && node->is_grafted) {
1167
 
                /* that means that's a grafted that failed to load decrement by 2 */
1168
 
                priv->loading -= 2;
1169
 
                g_signal_emit (self,
1170
 
                               brasero_data_project_signals [PROJECT_LOADED_SIGNAL],
1171
 
                               0,
1172
 
                               priv->loading);
 
1196
                /* that means that's a grafted that failed to load */
 
1197
                brasero_data_project_convert_to_fake (self, node);
 
1198
                return;
1173
1199
        }
1174
1200
 
1175
1201
        /* check for a sibling now (before destruction) */
1176
1202
        imported_sibling = brasero_file_node_check_imported_sibling (node);
1177
 
 
1178
1203
        brasero_data_project_remove_real (self, node);
1179
1204
 
1180
1205
        /* add the sibling now (after destruction) */
1222
1247
         * used to remove imported nodes. */
1223
1248
}
1224
1249
 
 
1250
static gboolean
 
1251
brasero_data_project_is_deep (BraseroDataProject *self,
 
1252
                              BraseroFileNode *parent,
 
1253
                              const gchar *name,
 
1254
                              gboolean isfile)
 
1255
{
 
1256
        gint parent_depth;
 
1257
        BraseroFileTreeStats *stats;
 
1258
        BraseroDataProjectPrivate *priv;
 
1259
 
 
1260
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
 
1261
 
 
1262
        /* if there are already deep files accepts new ones (includes the 
 
1263
         * possible imported ones. */
 
1264
        stats = brasero_file_node_get_tree_stats (priv->root, NULL);
 
1265
        if (stats->num_deep)
 
1266
                return TRUE;
 
1267
 
 
1268
        /* This node could have been moved beyond the depth 6 only in one case,
 
1269
         * which is with imported directories. Otherwise since we check
 
1270
         * directories for a depth of 5, its parent would have already been 
 
1271
         * detected. */
 
1272
        parent_depth = brasero_file_node_get_depth (parent);
 
1273
        if (!isfile) {
 
1274
                if (parent_depth < 5)
 
1275
                        return TRUE;
 
1276
        }
 
1277
        else {
 
1278
                if (parent_depth < 6)
 
1279
                        return TRUE;
 
1280
        }
 
1281
 
 
1282
        if (brasero_data_project_file_signal (self, DEEP_DIRECTORY_SIGNAL, name))
 
1283
                return FALSE;
 
1284
 
 
1285
        return TRUE;
 
1286
}
 
1287
 
1225
1288
gboolean
1226
1289
brasero_data_project_move_node (BraseroDataProject *self,
1227
1290
                                BraseroFileNode *node,
1252
1315
                return FALSE;
1253
1316
 
1254
1317
        /* see if we won't break the max path depth barrier */
1255
 
        if (!node->is_file && brasero_file_node_get_depth (parent) == 5
1256
 
        &&   brasero_data_project_file_signal (self, DEEP_DIRECTORY_SIGNAL, BRASERO_FILE_NODE_NAME (node)))
 
1318
        if (!brasero_data_project_is_deep (self, parent, BRASERO_FILE_NODE_NAME (node), node->is_file))
1257
1319
                return FALSE;
1258
1320
 
1259
1321
        /* One case could make us fail: if there is the same name in
1283
1345
                 * move it should probably be a graft now.
1284
1346
                 * NOTE: we need to do it now before it gets unparented. */
1285
1347
                uri = brasero_data_project_node_to_uri (self, node);
1286
 
                brasero_data_project_uri_graft_nodes (self, uri);
 
1348
                if (!g_hash_table_lookup (priv->grafts, uri))
 
1349
                        brasero_data_project_uri_graft_nodes (self, uri);
1287
1350
                g_free (uri);
1288
1351
 
1289
1352
                check_graft = FALSE;
1298
1361
        /* unparent node now in case its target sibling is a parent */
1299
1362
        former_parent = node->parent;
1300
1363
        former_position = brasero_file_node_get_pos_as_child (node);
 
1364
        stats = brasero_file_node_get_tree_stats (priv->root, NULL);
1301
1365
        brasero_file_node_move_from (node, stats);
1302
1366
 
1303
1367
        klass = BRASERO_DATA_PROJECT_GET_CLASS (self);
1387
1451
                 * we need to add one with all nodes having the same
1388
1452
                 * URI. */
1389
1453
                uri = brasero_data_project_node_to_uri (self, node);
1390
 
                brasero_data_project_uri_graft_nodes (self, uri);
 
1454
                if (!g_hash_table_lookup (priv->grafts, uri))
 
1455
                        brasero_data_project_uri_graft_nodes (self, uri);
1391
1456
                g_free (uri);
1392
1457
 
1393
1458
                /* now we can change the name */
1446
1511
                /* If there is already a graft for this URI, then add node */
1447
1512
                brasero_file_node_graft (node, graft);
1448
1513
        }
1449
 
        else if (node->is_symlink) {
1450
 
                /* NOTE: info has the uri for the target of the symlink */
1451
 
                graft = brasero_data_project_uri_ensure_graft (self, uri);
1452
 
                brasero_file_node_graft (node, graft);
1453
 
        }
1454
1514
        else if (node->parent == priv->root) {
1455
 
                /* The node is at the root of the project; graft it */
1456
 
                graft = brasero_data_project_uri_ensure_graft (self, uri);
 
1515
                /* The node is at the root of the project; graft it as well as
 
1516
                 * all the nodes already in the tree with the same URI */
 
1517
                graft = brasero_data_project_uri_graft_nodes (self, uri);
1457
1518
                brasero_file_node_graft (node, graft);
1458
1519
        }
1459
1520
        else if (node->is_fake) {
1460
 
                /* The node is a fake directory; graft it */
1461
 
                graft = brasero_data_project_uri_ensure_graft (self, uri);
1462
 
                brasero_file_node_graft (node, graft);
 
1521
                /* The node is a fake directory; graft it as well as all the 
 
1522
                 * nodes already in the tree with the same URI */
 
1523
                graft = brasero_data_project_uri_graft_nodes (self, uri);
1463
1524
        }
1464
1525
        else {
1465
1526
                gchar *parent_uri;
 
1527
                gchar *name_uri;
1466
1528
 
1467
1529
                parent_uri = brasero_data_project_node_to_uri (self, node->parent);
 
1530
                name_uri = g_path_get_basename (uri);
 
1531
 
 
1532
                /* NOTE: in here use a special function here since that node 
 
1533
                 * could already be in the tree but under its rightful parent
 
1534
                 * and then it won't have any graft yet. That's why these nodes
 
1535
                 * need to be grafted as well. */ 
1468
1536
                if (parent_uri) {
1469
1537
                        guint parent_len;
1470
1538
 
1471
1539
                        parent_len = strlen (parent_uri);
1472
1540
                        if (strncmp (parent_uri, uri, parent_len)
1473
 
                        &&  uri [parent_len] != G_DIR_SEPARATOR) {
 
1541
                        ||  uri [parent_len] != G_DIR_SEPARATOR
 
1542
                        || !name_uri
 
1543
                        || !BRASERO_FILE_NODE_NAME (node)
 
1544
                        ||  strcmp (name_uri, BRASERO_FILE_NODE_NAME (node))) {
1474
1545
                                /* The node hasn't been put under its rightful
1475
1546
                                 * parent from the original file system. That
1476
 
                                 * means we must add a graft*/
1477
 
                                graft = brasero_data_project_uri_add_graft (self, uri);
 
1547
                                 * means we must add a graft */
 
1548
                                graft = brasero_data_project_uri_graft_nodes (self, uri);
1478
1549
                                brasero_file_node_graft (node, graft);
1479
1550
                        }
1480
1551
                        /* NOTE: we don't need to check if the nodes's name
1488
1559
                }
1489
1560
                else {
1490
1561
                        /* its father is probably an fake empty directory */
1491
 
                        graft = brasero_data_project_uri_add_graft (self, uri);
 
1562
                        graft = brasero_data_project_uri_graft_nodes (self, uri);
1492
1563
                        brasero_file_node_graft (node, graft);
1493
1564
                }
 
1565
                g_free (name_uri);
1494
1566
        }
1495
1567
 
1496
1568
        /* check joliet compatibility; do it after node was created. */
1497
1569
        if (strlen (BRASERO_FILE_NODE_NAME (node)) > 64)
1498
1570
                brasero_data_project_joliet_add_node (self, node);
1499
1571
 
 
1572
        if (priv->is_loading_contents)
 
1573
                return;
 
1574
 
1500
1575
        /* Signal that something has changed in the tree */
1501
1576
        klass = BRASERO_DATA_PROJECT_GET_CLASS (self);
1502
1577
        if (klass->node_added)
1566
1641
 
1567
1642
BraseroFileNode *
1568
1643
brasero_data_project_add_imported_session_file (BraseroDataProject *self,
1569
 
                                                BraseroVolFile *file,
 
1644
                                                GFileInfo *info,
1570
1645
                                                BraseroFileNode *parent)
1571
1646
{
1572
1647
        BraseroFileNode *node;
1574
1649
        BraseroDataProjectPrivate *priv;
1575
1650
 
1576
1651
        g_return_val_if_fail (BRASERO_IS_DATA_PROJECT (self), NULL);
1577
 
        g_return_val_if_fail (file != NULL, NULL);
 
1652
        g_return_val_if_fail (info != NULL, NULL);
1578
1653
 
1579
1654
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
1580
1655
 
1581
1656
        if (!parent)
1582
1657
                parent = priv->root;
1583
1658
 
1584
 
        node = brasero_file_node_check_name_existence (parent, BRASERO_VOLUME_FILE_NAME (file));
 
1659
        node = brasero_file_node_check_name_existence (parent, g_file_info_get_name (info));
1585
1660
        if (node) {
 
1661
                /* The node exists but it may be that we've loaded the project
 
1662
                 * before. Then the necessary directories to hold the grafted
 
1663
                 * files will have been created as fake directories. We need to
 
1664
                 * replace those whenever we run into one but not lose their 
 
1665
                 * children. */
 
1666
                if (node->is_fake && node->is_tmp_parent) {
 
1667
                        BraseroGraft *graft;
 
1668
                        BraseroURINode *uri_node;
 
1669
 
 
1670
                        graft = BRASERO_FILE_NODE_GRAFT (node);
 
1671
                        uri_node = graft->node;
 
1672
 
 
1673
                        /* NOTE after this function graft is invalid */
 
1674
                        brasero_file_node_ungraft (node);
 
1675
 
 
1676
                        /* see if uri_node is still needed */
 
1677
                        if (!uri_node->nodes
 
1678
                        &&  !brasero_data_project_uri_has_parent (self, uri_node->uri))
 
1679
                                brasero_data_project_uri_remove_graft (self, uri_node->uri);
 
1680
 
 
1681
                        if (node->is_file)
 
1682
                                node->is_fake = FALSE;
 
1683
                        else
 
1684
                                node->union3.imported_address = g_file_info_get_attribute_int64 (info, BRASERO_IO_DIR_CONTENTS_ADDR);
 
1685
 
 
1686
                        node->is_imported = TRUE;
 
1687
                        node->is_tmp_parent = FALSE;
 
1688
 
 
1689
                        /* Something has changed, tell the tree */
 
1690
                        klass = BRASERO_DATA_PROJECT_GET_CLASS (self);
 
1691
                        if (klass->node_changed)
 
1692
                                klass->node_changed (self, node);
 
1693
 
 
1694
                        return node;
 
1695
                }
 
1696
 
1586
1697
                if (brasero_data_project_file_signal (self, NAME_COLLISION_SIGNAL, BRASERO_FILE_NODE_NAME (node)))
1587
1698
                        return NULL;
1588
1699
 
1592
1703
                brasero_data_project_remove_real (self, node);
1593
1704
        }
1594
1705
 
1595
 
        node = brasero_file_node_new_imported_session_file (file, parent, priv->sort_func);
 
1706
        node = brasero_file_node_new_imported_session_file (info, parent, priv->sort_func);
1596
1707
 
1597
1708
        /* In this case, there can be no graft, and furthermore the
1598
1709
         * lengths of the names are not our problem. Just signal that
1622
1733
                parent = priv->root;
1623
1734
 
1624
1735
        /* check directory_depth */
1625
 
        if (brasero_file_node_get_depth (parent) == 5) {
1626
 
                if (brasero_data_project_file_signal (self, DEEP_DIRECTORY_SIGNAL, name))
1627
 
                        return NULL;
1628
 
        }
 
1736
        if (!brasero_data_project_is_deep (self, parent, name, FALSE))
 
1737
                return NULL;
1629
1738
 
1630
1739
        node = brasero_file_node_check_name_existence (parent, name);
1631
1740
        if (node) {
1647
1756
        return node;
1648
1757
}
1649
1758
 
 
1759
static void
 
1760
brasero_data_project_update_uri (BraseroDataProject *self,
 
1761
                                 BraseroFileNode *node,
 
1762
                                 const gchar *uri)
 
1763
{
 
1764
        gchar *parent_uri;
 
1765
        BraseroGraft *graft;
 
1766
        BraseroURINode *uri_node;
 
1767
        BraseroURINode *former_uri_node;
 
1768
 
 
1769
        graft = BRASERO_FILE_NODE_GRAFT (node);
 
1770
        former_uri_node = graft->node;
 
1771
 
 
1772
        if (!strcmp (former_uri_node->uri, uri)) {
 
1773
                /* Nothing needs update */
 
1774
                return;
 
1775
        }
 
1776
 
 
1777
        /* different URIS; make sure the node still needs a graft:
 
1778
         * - if so, update it
 
1779
         * - if not, remove it */
 
1780
        parent_uri = brasero_data_project_node_to_uri (self, node->parent);
 
1781
        if (parent_uri) {
 
1782
                guint parent_len;
 
1783
 
 
1784
                parent_len = strlen (parent_uri);
 
1785
 
 
1786
                if (strncmp (parent_uri, uri, parent_len)
 
1787
                &&  uri [parent_len] != G_DIR_SEPARATOR) {
 
1788
                        /* The node hasn't been put under its rightful parent
 
1789
                         * from the original file system. That means we must add
 
1790
                         * a graft or update the current one. */
 
1791
                        uri_node = brasero_data_project_uri_add_graft (self, uri);
 
1792
                        brasero_file_node_graft (node, uri_node);
 
1793
                }
 
1794
                else {
 
1795
                        /* rightful parent: ungraft it */
 
1796
                        brasero_file_node_ungraft (node);
 
1797
                }
 
1798
 
 
1799
                g_free (parent_uri);
 
1800
        }
 
1801
        else {
 
1802
                uri_node = brasero_data_project_uri_add_graft (self, uri);
 
1803
                brasero_file_node_graft (node, uri_node);
 
1804
        }
 
1805
 
 
1806
        /* the node was ungrafted, check if the former graft is still needed */
 
1807
        brasero_data_project_graft_is_needed (self, former_uri_node);
 
1808
}
 
1809
 
1650
1810
void
1651
1811
brasero_data_project_node_loaded (BraseroDataProject *self,
1652
1812
                                  BraseroFileNode *node,
1660
1820
        BraseroDataProjectPrivate *priv;
1661
1821
 
1662
1822
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
 
1823
 
1663
1824
        type = g_file_info_get_file_type (info);
1664
1825
        if (node->is_tmp_parent) {
1665
1826
                /* we must make sure that this is really a directory */
1666
1827
                if (type != G_FILE_TYPE_DIRECTORY) {
1667
 
                        BraseroURINode *graft;
1668
 
 
1669
 
                        /* it isn't a directory so it won't be loaded but turned
1670
 
                         * into a fake one. Decrement the number of loading */
1671
 
                        priv->loading -= 2;
1672
 
                        g_signal_emit (self,
1673
 
                                       brasero_data_project_signals [PROJECT_LOADED_SIGNAL],
1674
 
                                       0,
1675
 
                                       priv->loading);
1676
 
 
1677
 
                        /* no need to check for deep directory since that was in
1678
 
                         * the project as such. Keep it that way. */
1679
 
 
1680
 
                        /* make it a fake directory not to break order */
1681
 
                        node->is_fake = TRUE;
1682
 
                        node->is_loading = FALSE;
1683
 
                        node->is_tmp_parent = FALSE;
1684
 
 
1685
1828
                        /* exclude the URI we're replacing */
1686
1829
                        brasero_data_project_exclude_uri (self, uri);
1687
 
                        brasero_file_node_ungraft (node);
1688
 
 
1689
 
                        graft = brasero_data_project_uri_ensure_graft (self, NEW_FOLDER);
1690
 
                        brasero_file_node_graft (node, graft);
1691
 
                        brasero_data_project_node_changed (self, node);
1692
 
 
1693
 
                        /* since that URI wasn't a folder no contents loading */
 
1830
                        brasero_data_project_convert_to_fake (self, node);
1694
1831
                        return;
1695
1832
                }
1696
1833
 
1715
1852
                               priv->loading);
1716
1853
        }
1717
1854
 
 
1855
        /* If the node is not grafted because it was put under its original 
 
1856
         * parent on the file system it comes from, then its parent URI can't
 
1857
         * have changed (the parent it was put under had already its URI cleaned
 
1858
         * of any symlink). Its URI may be different though if it's a symlink
 
1859
         * but that case is treated somewhere else. */
 
1860
        if (node->is_grafted) {
 
1861
                /* The URI of the node could be different from the one we gave
 
1862
                 * earlier as brasero-io looks for parent symlinks and replace
 
1863
                 * them with their target. So since it's a graft, we need to 
 
1864
                 * update the graft URI just to make sure. */
 
1865
                brasero_data_project_update_uri (self, node, uri);
 
1866
        }
 
1867
 
1718
1868
        size = g_file_info_get_size (info);
1719
1869
        if (type != G_FILE_TYPE_DIRECTORY) {
1720
 
                if (BRASERO_SIZE_TO_SECTORS (size, 2048) > BRASERO_FILE_2G_LIMIT
 
1870
                if (BRASERO_BYTES_TO_SECTORS (size, 2048) > BRASERO_FILE_2G_LIMIT
1721
1871
                &&  BRASERO_FILE_NODE_SECTORS (node) < BRASERO_FILE_2G_LIMIT) {
1722
1872
                        if (brasero_data_project_file_signal (self, G2_FILE_SIGNAL, g_file_info_get_name (info))) {
1723
1873
                                brasero_data_project_remove_node (self, node);
1725
1875
                        }
1726
1876
                }
1727
1877
        }
 
1878
 
1728
1879
        /* avoid signalling twice for the same directory */
1729
 
        else if (!node->is_file
1730
 
             &&  brasero_file_node_get_depth (node) == 6
1731
 
             &&  brasero_data_project_file_signal (self, DEEP_DIRECTORY_SIGNAL, g_file_info_get_name (info))) {
 
1880
        if (!brasero_data_project_is_deep (self, node->parent,  BRASERO_FILE_NODE_NAME (node), node->is_file)) {
1732
1881
                brasero_data_project_remove_node (self, node);
1733
1882
                return;
1734
1883
        }
1735
1884
 
1736
 
        size_changed = (BRASERO_SIZE_TO_SECTORS (size, 2048) != BRASERO_FILE_NODE_SECTORS (node));
 
1885
        size_changed = (BRASERO_BYTES_TO_SECTORS (size, 2048) != BRASERO_FILE_NODE_SECTORS (node));
1737
1886
        stats = brasero_file_node_get_tree_stats (priv->root, NULL);
1738
1887
        brasero_file_node_set_from_info (node, stats, info);
1739
1888
 
1740
1889
        /* Check it that needs a graft: this node has not been moved so we don't
1741
1890
         * need to check these cases yet it could turn out that it was a symlink
1742
1891
         * then we need a graft. */
1743
 
        if (node->is_symlink) {
 
1892
        if (g_file_info_get_is_symlink (info) && g_file_info_get_file_type (info) != G_FILE_TYPE_SYMBOLIC_LINK) {
1744
1893
                BraseroURINode *graft;
1745
1894
                gchar *uri;
1746
1895
 
1750
1899
                brasero_data_project_exclude_uri (self, uri);
1751
1900
                g_free (uri);
1752
1901
 
1753
 
                /* NOTE: info has the uri for the target of the symlink */
1754
 
                graft = brasero_data_project_uri_ensure_graft (self, g_file_info_get_symlink_target (info));
 
1902
                /* NOTE: info has the uri for the target of the symlink.
 
1903
                 * NOTE 2: all nodes with target URI become grafted. */
 
1904
                graft = brasero_data_project_uri_graft_nodes (self, g_file_info_get_symlink_target (info));
1755
1905
                brasero_file_node_graft (node, graft);
1756
1906
        }
1757
1907
 
1775
1925
 
1776
1926
        /* signal the changes */
1777
1927
        brasero_data_project_node_changed (self, node);
1778
 
 
1779
1928
        if (size_changed)
1780
1929
                g_signal_emit (self,
1781
1930
                               brasero_data_project_signals [SIZE_CHANGED_SIGNAL],
1806
1955
 
1807
1956
        size = g_file_info_get_size (info);
1808
1957
        name = g_file_info_get_name (info);
1809
 
        if (BRASERO_SIZE_TO_SECTORS (size, 2048) > BRASERO_FILE_2G_LIMIT
 
1958
        if (BRASERO_BYTES_TO_SECTORS (size, 2048) > BRASERO_FILE_2G_LIMIT
1810
1959
        &&  BRASERO_FILE_NODE_SECTORS (node) < BRASERO_FILE_2G_LIMIT) {
1811
1960
                if (brasero_data_project_file_signal (self, G2_FILE_SIGNAL, name)) {
1812
1961
                        brasero_data_project_remove_node (self, node);
1814
1963
                }
1815
1964
        }
1816
1965
 
1817
 
        size_changed = (BRASERO_SIZE_TO_SECTORS (size, 2048) == BRASERO_FILE_NODE_SECTORS (node));
 
1966
        size_changed = (BRASERO_BYTES_TO_SECTORS (size, 2048) == BRASERO_FILE_NODE_SECTORS (node));
1818
1967
        if (BRASERO_FILE_NODE_MIME (node) && !size_changed)
1819
1968
                return;
1820
1969
 
1850
1999
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
1851
2000
 
1852
2001
        graft = g_hash_table_lookup (priv->grafts, uri);
1853
 
 
1854
2002
        if (!parent)
1855
2003
                parent = priv->root;
1856
2004
 
1860
2008
        /* make sure that name doesn't exist */
1861
2009
        node = brasero_file_node_check_name_existence (parent, name);
1862
2010
        if (node) {
1863
 
                if (brasero_data_project_file_signal (self, NAME_COLLISION_SIGNAL, BRASERO_FILE_NODE_NAME (node))) {
 
2011
                if (brasero_data_project_file_signal (self,
 
2012
                                                      NAME_COLLISION_SIGNAL,
 
2013
                                                      BRASERO_FILE_NODE_NAME (node))) {
1864
2014
                        g_free (name);
1865
2015
                        return NULL;
1866
2016
                }
1908
2058
        }
1909
2059
}
1910
2060
 
 
2061
/* This function is only used in brasero-data-vfs.c to add new nodes
 
2062
 * discovered through exploration */
 
2063
 
1911
2064
BraseroFileNode *
1912
2065
brasero_data_project_add_node_from_info (BraseroDataProject *self,
1913
2066
                                         const gchar *uri,
1975
2128
                guint64 size;
1976
2129
 
1977
2130
                size = g_file_info_get_size (info);
1978
 
                if (BRASERO_SIZE_TO_SECTORS (size, 2048) > BRASERO_FILE_2G_LIMIT)
 
2131
                if (BRASERO_BYTES_TO_SECTORS (size, 2048) > BRASERO_FILE_2G_LIMIT)
1979
2132
                        if (brasero_data_project_file_signal (self, G2_FILE_SIGNAL, name))
1980
2133
                                return NULL;
1981
2134
        }
1982
 
        else if (!brasero_file_node_get_depth (parent) == 5) {
 
2135
        /* This is a special case where we won't try all checks for deep nested
 
2136
         * files. Since this function is only used by brasero-data-vfs.c to 
 
2137
         * add the results of its exploration, we only check directories and
 
2138
         * just check for a directory to have a depth of 6 (means parent has a
 
2139
         * depth of 5. */
 
2140
        else if (brasero_file_node_get_depth (parent) == 5) {
1983
2141
                if (brasero_data_project_file_signal (self, DEEP_DIRECTORY_SIGNAL, name))
1984
2142
                        return NULL;
1985
 
        }
1986
 
 
1987
 
        node = brasero_file_node_new_from_info (info, parent, priv->sort_func);
1988
 
        if (node->is_symlink) {
1989
 
                gchar *symlink_uri;
1990
 
 
 
2143
        } 
 
2144
 
 
2145
        node = brasero_file_node_new_from_info (info,
 
2146
                                                parent,
 
2147
                                                priv->sort_func);
 
2148
 
 
2149
        if (g_file_info_get_is_symlink (info)
 
2150
        &&  g_file_info_get_file_type (info) != G_FILE_TYPE_SYMBOLIC_LINK) {
1991
2151
                /* first we exclude the symlink, then we graft its target */
1992
 
                symlink_uri = brasero_data_project_node_to_uri (self, node);
1993
 
                brasero_data_project_exclude_uri (self, symlink_uri);
1994
 
                g_free (symlink_uri);
 
2152
                brasero_data_project_exclude_uri (self, uri);
1995
2153
 
1996
2154
                /* then we add the node */
1997
2155
                brasero_data_project_add_node_real (self,
2000
2158
                                                    g_file_info_get_symlink_target (info));
2001
2159
        }
2002
2160
        else
2003
 
                brasero_data_project_add_node_real (self, node, graft, uri);
 
2161
                brasero_data_project_add_node_real (self,
 
2162
                                                    node,
 
2163
                                                    graft,
 
2164
                                                    uri);
2004
2165
 
2005
2166
        if (type != G_FILE_TYPE_DIRECTORY)
2006
2167
                g_signal_emit (self,
2036
2197
 * Export tree internals into a track 
2037
2198
 */
2038
2199
struct _MakeTrackData {
2039
 
        gboolean joliet_compat;
2040
2200
        gboolean append_slash;
2041
2201
 
2042
2202
        GSList *grafts;
2046
2206
};
2047
2207
typedef struct _MakeTrackData MakeTrackData;
2048
2208
 
2049
 
static guint
2050
 
brasero_data_project_set_joliet_compliant_name (BraseroDataProject *self,
2051
 
                                                BraseroFileNode *node,
2052
 
                                                gchar *buffer)
2053
 
{
2054
 
        BraseroDataProjectPrivate *priv;
2055
 
        BraseroJolietKey key;
2056
 
        guint retval;
2057
 
        GSList *list;
2058
 
        gchar *name;
2059
 
        gchar *dot;
2060
 
        gint width;
2061
 
        gint num;
2062
 
        gint len;
2063
 
 
2064
 
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
2065
 
 
2066
 
        brasero_data_project_joliet_set_key (&key, node);
2067
 
        list = g_hash_table_lookup (priv->joliet, &key);
2068
 
        name = BRASERO_FILE_NODE_NAME (node);
2069
 
 
2070
 
        /* see if it is joliet non compliant */
2071
 
        if (!list) {
2072
 
                len = strlen (name);
2073
 
                memcpy (buffer, name, len);
2074
 
                return len;
2075
 
        }
2076
 
 
2077
 
        if (g_slist_length (list) == 1) {
2078
 
                /* Simply return joliet name truncated to 64 chars.
2079
 
                 * try to keep the extension. */
2080
 
                dot = g_utf8_strrchr (name, -1, '.');
2081
 
                if (dot && strlen (dot) < 5 && strlen (dot) > 1 )
2082
 
                        retval = sprintf (buffer,
2083
 
                                          "%.*s%s",
2084
 
                                          64 - strlen (dot),
2085
 
                                          name,
2086
 
                                          dot);
2087
 
                else {
2088
 
                        retval = 64;
2089
 
                        memcpy (buffer,
2090
 
                                name,
2091
 
                                64);
2092
 
                }
2093
 
 
2094
 
                return 64;
2095
 
        }
2096
 
 
2097
 
        num = g_slist_index (list, node);
2098
 
 
2099
 
        width = 1;
2100
 
        while (num / (width * 10)) width ++;
2101
 
        width = 64 - width;
2102
 
 
2103
 
        /* try to keep the extension */
2104
 
        dot = g_utf8_strrchr (name, -1, '.');
2105
 
        if (dot && strlen (dot) < 5 && strlen (dot) > 1 )
2106
 
                retval = sprintf (buffer,
2107
 
                                  "%.*s%i%s",
2108
 
                                  width - strlen (dot),
2109
 
                                  name,
2110
 
                                  num,
2111
 
                                  dot);
2112
 
        else
2113
 
                retval = sprintf (buffer,
2114
 
                                  "%.*s%i",
2115
 
                                  width,
2116
 
                                  name,
2117
 
                                  num);
2118
 
        return retval;
2119
 
}
2120
 
 
2121
2209
static gchar *
2122
2210
brasero_data_project_node_to_path (BraseroDataProject *self,
2123
 
                                   BraseroFileNode *node,
2124
 
                                   gboolean joliet_compat)
 
2211
                                   BraseroFileNode *node)
2125
2212
{
2126
2213
        guint len;
2127
2214
        GSList *list;
2141
2228
        len = 0;
2142
2229
        for (iter = list; iter; iter = iter->next) {
2143
2230
                gchar *name;
 
2231
                guint name_len;
2144
2232
 
2145
2233
                node = iter->data;
2146
2234
 
2151
2239
                        return NULL;
2152
2240
 
2153
2241
                /* Make sure path length didn't go over MAXPATHLEN. */
2154
 
                if (!joliet_compat) {
2155
 
                        guint name_len;
2156
 
 
2157
 
                        name = BRASERO_FILE_NODE_NAME (node);
2158
 
 
2159
 
                        name_len = strlen (name);
2160
 
                        if (len + name_len > MAXPATHLEN)
2161
 
                                return NULL;
2162
 
 
2163
 
                        memcpy (path + len, name, name_len);
2164
 
                        len += name_len;
2165
 
                }
2166
 
                else {
2167
 
                        /* must have enough room for 64 characters */
2168
 
                        if (len + 64 > MAXPATHLEN)
2169
 
                                return NULL;
2170
 
 
2171
 
                        len += brasero_data_project_set_joliet_compliant_name (self,
2172
 
                                                                               node,
2173
 
                                                                               path + len);
2174
 
                }
 
2242
                name = BRASERO_FILE_NODE_NAME (node);
 
2243
 
 
2244
                name_len = strlen (name);
 
2245
                if (len + name_len > MAXPATHLEN)
 
2246
                        return NULL;
 
2247
 
 
2248
                memcpy (path + len, name, name_len);
 
2249
                len += name_len;
2175
2250
        }
2176
2251
        g_slist_free (list);
2177
2252
 
2210
2285
                if (uri && uri != NEW_FOLDER)
2211
2286
                        graft->uri = g_strdup (uri);
2212
2287
 
2213
 
                graft->path = brasero_data_project_node_to_path (data->project,
2214
 
                                                                 node,
2215
 
                                                                 data->joliet_compat);
 
2288
                graft->path = brasero_data_project_node_to_path (data->project, node);
2216
2289
                if (!node->is_file && data->append_slash) {
2217
2290
                        gchar *tmp;
2218
2291
 
2248
2321
                        continue;
2249
2322
 
2250
2323
                graft = g_new0 (BraseroGraftPt, 1);
2251
 
                graft->path = brasero_data_project_node_to_path (data->project, node, TRUE);
 
2324
                graft->path = brasero_data_project_node_to_path (data->project, node);
2252
2325
                if (!node->is_file && data->append_slash) {
2253
2326
                        gchar *tmp;
2254
2327
 
2289
2362
        callback_data.grafts = NULL;
2290
2363
        callback_data.excluded = NULL;
2291
2364
        callback_data.append_slash = append_slash;
2292
 
        callback_data.joliet_compat = joliet_compat;
2293
2365
 
2294
2366
        g_hash_table_foreach (priv->grafts,
2295
2367
                              (GHFunc) _foreach_grafts_make_list_cb,
2296
2368
                              &callback_data);
2297
2369
 
2298
2370
        if (joliet_compat) {
2299
 
                /* we have to make sure that even the files that are not grafted
2300
 
                 * have joliet compatible names. */
 
2371
                /* Make sure that all nodes with incompatible joliet names are
 
2372
                 * added as graft points. */
2301
2373
                g_hash_table_foreach (priv->joliet,
2302
2374
                                      (GHFunc) _foreach_joliet_incompatible_make_list_cb,
2303
2375
                                      &callback_data);
2317
2389
}
2318
2390
 
2319
2391
gboolean
 
2392
brasero_data_project_has_symlinks (BraseroDataProject *self)
 
2393
{
 
2394
        BraseroDataProjectPrivate *priv;
 
2395
        BraseroFileTreeStats *stats;
 
2396
 
 
2397
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
 
2398
 
 
2399
        stats = brasero_file_node_get_tree_stats (priv->root, NULL);
 
2400
        if (stats->num_sym)
 
2401
                return TRUE;
 
2402
 
 
2403
        return FALSE;
 
2404
}
 
2405
 
 
2406
gboolean
2320
2407
brasero_data_project_is_joliet_compliant (BraseroDataProject *self)
2321
2408
{
2322
2409
        BraseroDataProjectPrivate *priv;
 
2410
        BraseroFileTreeStats *stats;
2323
2411
 
2324
2412
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
2325
2413
 
 
2414
        stats = brasero_file_node_get_tree_stats (priv->root, NULL);
 
2415
        if (stats->num_sym)
 
2416
                return FALSE;
 
2417
 
2326
2418
        if (!priv->joliet || !g_hash_table_size (priv->joliet))
2327
2419
                return TRUE;
2328
2420
 
2393
2485
        BraseroDataProjectPrivate *priv;
2394
2486
 
2395
2487
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
2396
 
 
2397
2488
        if (g_hash_table_size (priv->grafts))
2398
2489
                return FALSE;
2399
2490
 
2442
2533
                 * isn't one. */
2443
2534
                parent->is_tmp_parent = TRUE;
2444
2535
 
2445
 
                /* Increment it by 2 (loading folder and then its contents) */
2446
 
                priv->loading += 2;
2447
 
 
2448
2536
                (*folders) = g_slist_prepend ((*folders), parent);
2449
2537
 
2450
2538
                /* Go on with the next; skip the separator */
2564
2652
                        node->is_loading = FALSE;
2565
2653
                        node->is_reloading = FALSE;
2566
2654
 
2567
 
                        /* decrement that since we're not going to load anything */
2568
 
                        priv->loading -= 2;
2569
 
 
2570
 
                        /* Signal that something has changed in the tree */
2571
 
                        if (klass->node_added)
2572
 
                                klass->node_added (self, node, NULL);
 
2655
                        /* Don't signal the node addition yet we'll do it later
 
2656
                         * when all the nodes are created */
2573
2657
                }
2574
2658
                else {
2575
2659
                        node->is_file = FALSE;
2577
2661
                        node->is_loading = TRUE;
2578
2662
                        node->is_reloading = FALSE;
2579
2663
 
2580
 
                        /* No need to increment priv->loading here since that
2581
 
                         * was done at the creation of the temporary folder */
2582
 
 
2583
 
                        /* Signal that something has changed in the tree */
2584
 
                        if (klass->node_added)
2585
 
                                klass->node_added (self, node, uri);
 
2664
                        /* Don't signal the node addition yet we'll do it later
 
2665
                         * when all the nodes are created */
2586
2666
                }
2587
2667
        }
2588
2668
        else if (node) {
2594
2674
                /* don't use brasero_data_project_add_loading_node since that way:
2595
2675
                 * - we don't check for sibling
2596
2676
                 * - we set right from the start the right name */
2597
 
                if (uri != NEW_FOLDER) {
 
2677
                if (uri != NEW_FOLDER)
2598
2678
                        node = brasero_file_node_new_loading (path, parent, priv->sort_func);
2599
 
 
2600
 
                        /* Set loading counter to 2: 1 operation for loading the graft
2601
 
                         * point and 1 for loading its contents if that's a folder. */
2602
 
                        priv->loading += 2;
2603
 
                }
2604
2679
                else
2605
2680
                        node = brasero_file_node_new_empty_folder (path, parent, priv->sort_func);
2606
2681
 
2648
2723
                        break;
2649
2724
 
2650
2725
                graft = NULL;
2651
 
                dirname (parent_uri);
 
2726
                parent_uri = dirname (parent_uri);
2652
2727
        }
2653
2728
        g_free (parent_uri);
2654
2729
 
2710
2785
        return folders;
2711
2786
}
2712
2787
 
 
2788
static gint
 
2789
brasero_data_project_load_contents_notify_directory (BraseroDataProject *self,
 
2790
                                                     BraseroFileNode *parent,
 
2791
                                                     BraseroDataNodeAddedFunc func)
 
2792
{
 
2793
        BraseroFileNode *child;
 
2794
        gint num = 0;
 
2795
 
 
2796
        child = BRASERO_FILE_NODE_CHILDREN (parent);
 
2797
        while (child) {
 
2798
                gchar *uri;
 
2799
                gboolean res;
 
2800
                BraseroFileNode *next;
 
2801
 
 
2802
                /* The child could be removed during the process */
 
2803
                next = child->next;
 
2804
                        
 
2805
                /**
 
2806
                 * This is to get the number of operations remaining before the
 
2807
                 * whole project is loaded.
 
2808
                 * +1 for loading information about a file or a directory (that
 
2809
                 * means they must not be fake).
 
2810
                 * +1 for loading the directory contents.
 
2811
                 */
 
2812
                if (child->is_fake) {
 
2813
                        /* This is a fake directory, there is no operation */
 
2814
                        res = func (self, child, NULL);
 
2815
                        child = next;
 
2816
                        continue;
 
2817
                }
 
2818
 
 
2819
                uri = brasero_data_project_node_to_uri (self, child);
 
2820
                res = func (self, child, uri);
 
2821
                g_free (uri);
 
2822
 
 
2823
                if (res)
 
2824
                        num ++;
 
2825
 
 
2826
                /* for whatever reason the node could have been invalidated */
 
2827
                if (res && !child->is_file) {
 
2828
                        num ++;
 
2829
                        num += brasero_data_project_load_contents_notify_directory (self,
 
2830
                                                                                    child,
 
2831
                                                                                    func);
 
2832
                }
 
2833
 
 
2834
                child = next;
 
2835
        }
 
2836
 
 
2837
        return num;
 
2838
}
 
2839
 
 
2840
static gint
 
2841
brasero_data_project_load_contents_notify (BraseroDataProject *self)
 
2842
{
 
2843
        gint num;
 
2844
        BraseroDataProjectClass *klass;
 
2845
        BraseroDataProjectPrivate *priv;
 
2846
 
 
2847
        klass = BRASERO_DATA_PROJECT_GET_CLASS (self);
 
2848
        if (!klass->node_added)
 
2849
                return 0;
 
2850
 
 
2851
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
 
2852
 
 
2853
        /* we'll notify for every single node in the tree starting from the top.
 
2854
         * NOTE: at this point there are only grafted nodes (fake or not) in the
 
2855
         * tree. */
 
2856
        num = brasero_data_project_load_contents_notify_directory (self,
 
2857
                                                                   priv->root,
 
2858
                                                                   klass->node_added);
 
2859
        return num;
 
2860
}
 
2861
 
2713
2862
guint
2714
2863
brasero_data_project_load_contents (BraseroDataProject *self,
2715
2864
                                    GSList *grafts,
2717
2866
{
2718
2867
        GSList *iter;
2719
2868
        GSList *folders = NULL;
2720
 
        BraseroDataProjectClass *klass;
2721
2869
        BraseroDataProjectPrivate *priv;
2722
2870
 
 
2871
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
 
2872
        priv->is_loading_contents = 1;
 
2873
 
2723
2874
        for (iter = grafts; iter; iter = iter->next) {
2724
2875
                BraseroGraftPt *graft;
 
2876
                GFile *file;
 
2877
                gchar *uri;
2725
2878
 
2726
2879
                graft = iter->data;
 
2880
 
 
2881
                if (graft->uri) {
 
2882
                        file = g_file_new_for_uri (graft->uri);
 
2883
                        uri = g_file_get_uri (file);
 
2884
                        g_object_unref (file);
 
2885
                }
 
2886
                else
 
2887
                        uri = NULL;
 
2888
 
2727
2889
                folders = brasero_data_project_add_path (self,
2728
2890
                                                         graft->path,
2729
 
                                                         graft->uri,
 
2891
                                                         uri,
2730
2892
                                                         folders);
 
2893
 
 
2894
                if (uri)
 
2895
                        g_free (uri);
2731
2896
        }
2732
2897
 
2733
2898
        for (iter = excluded; iter; iter = iter->next) {
2734
2899
                gchar *uri;
2735
 
 
2736
 
                uri = iter->data;
 
2900
                GFile *file;
 
2901
 
 
2902
                file = g_file_new_for_uri (iter->data);
 
2903
                uri = g_file_get_uri (file);
 
2904
                g_object_unref (file);
 
2905
 
2737
2906
                folders = brasero_data_project_add_excluded_uri (self,
2738
2907
                                                                 uri,
2739
2908
                                                                 folders);
 
2909
                g_free (uri);
2740
2910
        }
2741
2911
 
2742
2912
        /* Now load the temporary folders that were created */
2743
 
        klass = BRASERO_DATA_PROJECT_GET_CLASS (self);
2744
 
        priv = BRASERO_DATA_PROJECT_PRIVATE (self);
2745
 
 
2746
2913
        for (iter = folders; iter; iter = iter->next) {
2747
2914
                BraseroURINode *graft;
2748
2915
                BraseroFileNode *tmp;
2753
2920
                /* get the URI for this node. There should be one now that all
2754
2921
                 * graft nodes are in the tree. */
2755
2922
                uri = brasero_data_project_node_to_uri (self, tmp);
 
2923
                if (!uri) {
 
2924
                        /* This node has been grafted under a node that was
 
2925
                         * imported or was itself an imported node. Since there
 
2926
                         * is no imported nodes any more, then it has to become
 
2927
                         * fake.
 
2928
                         * NOTE: it has to be a directory */
 
2929
                        tmp->is_fake = TRUE;
 
2930
                        tmp->is_loading = FALSE;
 
2931
                        tmp->is_reloading = FALSE;
 
2932
 
 
2933
                        graft = brasero_data_project_uri_ensure_graft (self, NEW_FOLDER);
 
2934
                        brasero_file_node_graft (tmp, graft);
 
2935
 
 
2936
                        /* Don't signal the node addition yet we'll do it later
 
2937
                         * when all the nodes are created */
 
2938
 
 
2939
                        continue;
 
2940
                }
2756
2941
 
2757
2942
                /* graft it ? */
2758
2943
                graft = brasero_data_project_uri_ensure_graft (self, uri);
2759
2944
                brasero_file_node_graft (tmp, graft);
2760
 
 
2761
 
                /* Signal that something has changed in the tree */
2762
 
                if (klass->node_added)
2763
 
                        klass->node_added (self, tmp, uri);
2764
 
 
2765
2945
                g_free (uri);
 
2946
 
 
2947
                /* Don't signal the node addition yet we'll do it later when 
 
2948
                 * all the nodes are created */
2766
2949
        }
2767
2950
        g_slist_free (folders);
2768
2951
 
 
2952
        priv->loading = brasero_data_project_load_contents_notify (self);
 
2953
 
 
2954
        priv->is_loading_contents = 0;
2769
2955
        return priv->loading;
2770
2956
}
2771
2957
 
3026
3212
 
3027
3213
        /* get the new URI */
3028
3214
        parent_uri = brasero_data_project_node_to_uri (BRASERO_DATA_PROJECT (monitor), parent);
3029
 
        escaped_name = g_uri_escape_string (name, NULL, TRUE);
 
3215
        escaped_name = g_uri_escape_string (name,
 
3216
                                            G_URI_RESERVED_CHARS_ALLOWED_IN_PATH,
 
3217
                                            FALSE);
3030
3218
        uri = g_strconcat (parent_uri, G_DIR_SEPARATOR_S, escaped_name, NULL);
3031
3219
        g_free (escaped_name);
3032
3220
        g_free (parent_uri);
3064
3252
        uri_node = graft->node;
3065
3253
 
3066
3254
        /* get the new uri */
3067
 
        escaped_name = g_uri_escape_string (name, NULL, TRUE);
 
3255
        escaped_name = g_uri_escape_string (name,
 
3256
                                            G_URI_RESERVED_CHARS_ALLOWED_IN_PATH,
 
3257
                                            FALSE);
3068
3258
        uri = g_build_path (G_DIR_SEPARATOR_S, parent_uri, escaped_name, NULL);
3069
3259
        g_free (escaped_name);
3070
3260
 
3140
3330
        parent = g_path_get_dirname (uri);
3141
3331
        g_free (uri);
3142
3332
 
3143
 
        escaped_name = g_uri_escape_string (real_name, NULL, TRUE);
 
3333
        escaped_name = g_uri_escape_string (real_name,
 
3334
                                            G_URI_RESERVED_CHARS_ALLOWED_IN_PATH,
 
3335
                                            FALSE);
3144
3336
        uri = g_strconcat (parent, G_DIR_SEPARATOR_S, escaped_name, NULL);
3145
3337
        g_free (escaped_name);
3146
3338
        g_free (parent);
3285
3477
                brasero_data_project_joliet_remove_node (BRASERO_DATA_PROJECT (monitor), node);
3286
3478
 
3287
3479
                /* see if we won't break the max path depth barrier */
3288
 
                if (!node->is_file && brasero_file_node_get_depth (parent) == 5
3289
 
                &&   brasero_data_project_file_signal (BRASERO_DATA_PROJECT (monitor), DEEP_DIRECTORY_SIGNAL, BRASERO_FILE_NODE_NAME (node))) {
 
3480
                if (!brasero_data_project_is_deep (BRASERO_DATA_PROJECT (monitor), parent,  BRASERO_FILE_NODE_NAME (node), node->is_file)) {
3290
3481
                        brasero_data_project_remove_node (BRASERO_DATA_PROJECT (monitor), node);
3291
3482
                        return;
3292
3483
                }