~elementary-apps/pantheon-files/trunk

« back to all changes in this revision

Viewing changes to libcore/gof-file.c

  • Committer: Jeremy Wootten
  • Date: 2017-01-13 13:36:33 UTC
  • mfrom: (2444 pantheon-files)
  • mto: This revision was merged to the branch mainline in revision 2471.
  • Revision ID: jeremy@elementaryos.org-20170113133633-ajg6izr1e6irmj0g
Merge r2444

Show diffs side-by-side

added added

removed removed

Lines of Context:
287
287
}
288
288
 
289
289
gboolean
 
290
gof_file_is_recent_uri_scheme (GOFFile *file)
 
291
{
 
292
    if (!G_IS_FILE (file->location))
 
293
        return TRUE;
 
294
 
 
295
    return g_file_has_uri_scheme (file->location, "recent");
 
296
}
 
297
 
 
298
gboolean
290
299
gof_file_is_other_uri_scheme (GOFFile *file)
291
300
{
292
301
    GFile *loc = file->location;
343
352
gof_file_update_size (GOFFile *file)
344
353
{
345
354
    g_free (file->format_size);
346
 
    if (gof_file_is_folder (file) || gof_file_is_root_network_folder (file))
 
355
 
 
356
    if (gof_file_is_folder (file) || gof_file_is_root_network_folder (file)) {
347
357
        file->format_size = g_strdup ("—");
348
 
    else
 
358
    } else if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) {
349
359
        file->format_size = g_format_size (file->size);
 
360
    } else {
 
361
        file->format_size = g_strdup (_("Inaccessible"));
 
362
    }
350
363
}
351
364
 
352
365
static void
521
534
        }
522
535
    }
523
536
 
 
537
    if (file->custom_display_name == NULL) {
 
538
        /* Use custom_display_name to store default display name if there is no custom name */
 
539
        if (file->info && g_file_info_get_display_name (file->info) != NULL) {
 
540
            if (file->directory != NULL &&
 
541
                strcmp (g_file_get_uri_scheme (file->directory), "network") == 0 &&
 
542
                !(strcmp (g_file_get_uri (file->target_location), "smb:///") == 0)) {
 
543
                /* Show protocol after server name (lp:1184606) */
 
544
                file->custom_display_name = g_strdup_printf ("%s (%s)", g_file_info_get_display_name (file->info),
 
545
                                                                        g_utf8_strup (g_file_get_uri_scheme (file->target_location), -1));
 
546
            } else {
 
547
                file->custom_display_name = g_strdup (g_file_info_get_display_name (file->info));
 
548
            }
 
549
        }
 
550
    }
 
551
 
524
552
    /* sizes */
525
553
    gof_file_update_size (file);
526
554
    /* modified date */
527
 
    file->formated_modified = gof_file_get_formated_time (file, G_FILE_ATTRIBUTE_TIME_MODIFIED);
 
555
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) {
 
556
        file->formated_modified = gof_file_get_formated_time (file, G_FILE_ATTRIBUTE_TIME_MODIFIED);
 
557
    } else {
 
558
        file->formated_modified = g_strdup (_("Inaccessible"));
 
559
    }
528
560
    /* icon */
529
561
    if (file->is_directory) {
530
562
        gof_file_get_folder_icon_from_uri_or_path (file);
560
592
 
561
593
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_UNIX_UID)) {
562
594
        file->uid = g_file_info_get_attribute_uint32 (file->info, G_FILE_ATTRIBUTE_UNIX_UID);
563
 
        if (file->owner == NULL)
 
595
        if (file->owner == NULL) {
564
596
            file->owner = g_strdup_printf ("%d", file->uid);
 
597
        }
 
598
    } else if (file->owner != NULL) { /* e.g. ftp info yields owner but not uid */
 
599
        file->uid = atoi (file->owner);
565
600
    }
566
601
 
567
602
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_UNIX_GID)) {
568
603
        file->gid = g_file_info_get_attribute_uint32 (file->info, G_FILE_ATTRIBUTE_UNIX_GID);
569
 
        if (file->group == NULL)
 
604
        if (file->group == NULL) {
570
605
            file->group = g_strdup_printf ("%d", file->gid);
 
606
        }
 
607
    } else if (file->group != NULL) {  /* e.g. ftp info yields owner but not uid */
 
608
        file->gid = atoi (file->group);
571
609
    }
572
610
 
573
611
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT))
1321
1359
gof_file_is_writable (GOFFile *file)
1322
1360
{
1323
1361
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
1324
 
 
1325
1362
    if (file->target_gof && !g_file_equal (file->location, file->target_gof->location)) {
1326
1363
        return gof_file_is_writable (file->target_gof);
1327
1364
    } else if (file->info != NULL && g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
1328
1365
        return g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
1329
1366
    } else if (file->has_permissions) {
1330
 
        return (file->permissions & S_IWOTH) ||
1331
 
               (file->permissions & S_IWUSR) && (strcmp (file->owner, g_get_user_name ()) == 0) ||
1332
 
               (file->permissions & S_IWGRP) && eel_user_in_group (file->group);
 
1367
        return ((file->permissions & S_IWOTH) > 0) ||
 
1368
               ((file->permissions & S_IWUSR) > 0) && (file->uid < 0 || file->uid == geteuid ()) ||
 
1369
               ((file->permissions & S_IWGRP) > 0) && eel_user_in_group (file->group);
1333
1370
    } else {
1334
1371
        return TRUE;  /* We will just have to assume we can write to the file */
1335
1372
    }
 
1373
 
 
1374
    gboolean can_write = g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
 
1375
 
 
1376
    if (file->directory && g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE)) {
 
1377
        return can_write && g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
 
1378
    }
 
1379
 
 
1380
    return can_write;
1336
1381
}
1337
1382
 
1338
1383
gboolean
1346
1391
        return g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
1347
1392
    } else if (file->has_permissions) {
1348
1393
        return (file->permissions & S_IROTH) ||
1349
 
               (file->permissions & S_IRUSR) && (strcmp (file->owner, g_get_user_name ()) == 0) ||
 
1394
               (file->permissions & S_IRUSR) && (file->uid < 0 || file->uid == geteuid ()) ||
1350
1395
               (file->permissions & S_IRGRP) && eel_user_in_group (file->group);
1351
1396
    } else {
1352
1397
        return TRUE;  /* We will just have to assume we can read the file */
1388
1433
    g_return_val_if_fail (file != NULL, NULL);
1389
1434
    g_return_val_if_fail (file->info != NULL, NULL);
1390
1435
 
1391
 
    guint64 date = g_file_info_get_attribute_uint64 (file->info, attr);
1392
 
    if (date == 0)
1393
 
        return NULL;
1394
 
 
1395
 
    return eel_get_date_as_string (date, gof_preferences_get_default ()->pref_date_format);
 
1436
    return pf_file_utils_get_formatted_time_attribute_from_info (file->info,
 
1437
                                                                 attr,
 
1438
                                                                 gof_preferences_get_default ()->pref_date_format);
1396
1439
}
1397
1440
 
1398
1441
 
1725
1768
                return 0;
1726
1769
        }
1727
1770
 
1728
 
        /* if the source offers both copy and move and the GTK+ suggested action is copy, try to be smart telling whether we should copy or move by default by checking whether the source and target are on the same disk. */
 
1771
        /* if the source offers both copy and move and the GTK+ suggested action is copy, try to
 
1772
         * be smart telling whether we should copy or move by default by checking whether the
 
1773
         * source and target are on the same disk. */
1729
1774
        if ((actions & (GDK_ACTION_COPY | GDK_ACTION_MOVE)) != 0
1730
1775
            && (suggested_action == GDK_ACTION_COPY))
1731
1776
        {
1748
1793
                if (ofile == NULL
1749
1794
                    || !gof_file_same_filesystem (file, ofile)
1750
1795
                    || (ofile->info != NULL
1751
 
                        && g_file_info_get_attribute_uint32 (ofile->info,
1752
 
                                                             G_FILE_ATTRIBUTE_UNIX_UID) != effective_user_id))
 
1796
                        && ofile->uid > -1
 
1797
                        && ofile->uid != effective_user_id ))
1753
1798
                {
1754
1799
                    /* default to copy and get outa here */
1755
1800
                    suggested_action = GDK_ACTION_COPY;
2490
2535
const gchar *
2491
2536
gof_file_get_display_name (GOFFile *file)
2492
2537
{
2493
 
    if (file->is_desktop) {
2494
 
        if (gof_preferences_get_default ()->pref_interpret_desktop_files && file->custom_display_name != NULL)
2495
 
            return file->custom_display_name;
2496
 
    } else {
2497
 
        if (file->custom_display_name != NULL)
2498
 
            return file->custom_display_name;
2499
 
    }
2500
 
 
2501
 
    if (file->info && g_file_info_get_display_name (file->info) != NULL)
2502
 
        return g_file_info_get_display_name (file->info);
2503
 
 
2504
 
    return file->basename;
 
2538
    return file->custom_display_name ? file->custom_display_name : file->basename;
2505
2539
}
2506
2540
 
2507
2541
gboolean
2573
2607
char*
2574
2608
gof_file_get_display_target_uri (GOFFile *file)
2575
2609
{
2576
 
    return g_file_info_get_attribute_as_string (file->info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
 
2610
    /* This returns a string that requires freeing */
 
2611
    gchar* uri;
 
2612
 
 
2613
    uri = g_file_info_get_attribute_as_string (file->info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
 
2614
 
 
2615
    if (uri == NULL) {
 
2616
        uri = strdup (file->uri);
 
2617
    }
 
2618
 
 
2619
    return uri;
2577
2620
}
2578
2621
 
2579
2622
const gchar *