~ubuntu-branches/ubuntu/trusty/epiphany-browser/trusty

« back to all changes in this revision

Viewing changes to lib/ephy-file-helpers.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2011-11-21 17:15:18 UTC
  • mfrom: (1.6.3) (98.2.3 sid)
  • Revision ID: package-import@ubuntu.com-20111121171518-0f07y0i5rvb2wrix
Tags: 3.2.1-2ubuntu1
* Resynchronize on Debian, remaining diffs:
* debian/branding.conf.in: set the branding to Ubuntu.
* debian/epiphany-browser-data.gsettings-override:
  - set startpage and search to Ubuntu
* debian/patches/80_ubuntu_search_url.patch: use Ubuntu search
* debian/patches/81_ubuntu_force_update_bookmarks_menu.patch:
  - update the bookmarks menu every time the internal structure
    is changed (needed for the indicator application menu to work correctly).

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 */
54
54
 
55
55
#define EPHY_UUID               "0d82d98f-7079-401c-abff-203fcde1ece3"
56
 
#define EPHY_UUID_ENVVAR        "EPHY_UNIQUE"
57
56
#define EPHY_UUID_ENVSTRING     EPHY_UUID_ENVVAR "=" EPHY_UUID
58
57
 
59
58
#define DELAY_MAX_TICKS 64
62
61
static GHashTable *files = NULL;
63
62
static GHashTable *mime_table = NULL;
64
63
 
65
 
static gboolean have_private_profile = FALSE;
66
64
static gboolean keep_temp_directory = FALSE; /* for debug purposes */
67
65
static char *dot_dir = NULL;
68
66
static char *tmp_dir = NULL;
274
272
}
275
273
 
276
274
/**
277
 
 * ephy_has_private_profile:
278
 
 *
279
 
 * Whether Epiphany is running with a private profile (-p command line option).
280
 
 *
281
 
 * Returns: %TRUE if a private profile is in use
282
 
 **/
283
 
gboolean
284
 
ephy_has_private_profile (void)
285
 
{
286
 
        return have_private_profile;
287
 
}
288
 
 
289
 
/**
290
275
 * ephy_file_helpers_init:
291
276
 * @profile_dir: directory to use as Epiphany's profile
292
277
 * @private_profile: %TRUE if we should use a private profile
324
309
                                       (GDestroyNotify) g_free,
325
310
                                       (GDestroyNotify) g_free);
326
311
 
327
 
        have_private_profile = private_profile;
328
312
        keep_temp_directory = keep_temp_dir;
329
313
 
330
314
        if (private_profile && profile_dir != NULL)
397
381
        {
398
382
                if (!keep_temp_directory)
399
383
                {
400
 
                        /* recursively delete the contents and the directory */
401
 
                        ephy_file_delete_directory (tmp_dir);
 
384
                        GFile *tmp_dir_file;
 
385
                        tmp_dir_file = g_file_new_for_path (tmp_dir);
 
386
 
 
387
                        /* recursively delete the contents and the
 
388
                         * directory */
 
389
                        LOG ("shutdown: delete tmp_dir %s", tmp_dir);
 
390
                        ephy_file_delete_dir_recursively (tmp_dir_file,
 
391
                                                          NULL);
 
392
                        g_object_unref (tmp_dir_file);
402
393
                }
403
394
 
404
395
                g_free (tmp_dir);
753
744
/**
754
745
 * ephy_file_launch_desktop_file:
755
746
 * @filename: the path to the .desktop file
756
 
 * @parameter: path to a parameter file to pass to the application
 
747
 * @parameter: path to an optional parameter file to pass to the application
757
748
 * @user_time: user time to prevent focus stealing
758
749
 * @widget: an optional widget for ephy_file_launch_application()
759
750
 *
769
760
                               GtkWidget *widget)
770
761
{
771
762
        GDesktopAppInfo *app;
772
 
        GFile *file;
 
763
        GFile *file = NULL;
773
764
        GList *list = NULL;
774
765
        gboolean ret;
775
766
 
776
767
        app = g_desktop_app_info_new (filename);
777
 
        file = g_file_new_for_path (parameter);
778
 
        list = g_list_append (list, file);
 
768
        if (parameter)
 
769
        {
 
770
                file = g_file_new_for_path (parameter);
 
771
                list = g_list_append (list, file);
 
772
        }
779
773
        
780
774
        ret = ephy_file_launch_application (G_APP_INFO (app), list, user_time, widget);
781
775
        g_list_free (list);
782
 
        g_object_unref (file);
 
776
        if (file)
 
777
                g_object_unref (file);
783
778
        return ret;
784
779
}
785
780
 
863
858
ephy_file_browse_to (GFile *file,
864
859
                     guint32 user_time)
865
860
{
866
 
        GFile *parent;
867
 
        gboolean ret;
868
 
 
869
 
        parent = g_file_get_parent (file);
870
 
        /* TODO find a way to make nautilus scroll to the actual file */
871
 
        ret = ephy_file_launch_handler ("inode/directory",
872
 
                                        parent,
873
 
                                        user_time);
874
 
 
875
 
        g_object_unref (parent);
876
 
 
877
 
        return ret;
 
861
        return ephy_file_launch_handler ("inode/directory", file, user_time);
878
862
}
879
863
 
880
864
/**
881
 
 * ephy_file_delete_directory:
882
 
 * @path: the path to remove
 
865
 * ephy_file_delete_dir_recursively:
 
866
 * @directory: directory to remove
 
867
 * @error: location to set any #GError
883
868
 *
884
869
 * Remove @path and its contents. Like calling rm -rf @path.
885
870
 **/
886
 
void
887
 
ephy_file_delete_directory (const char *path)
 
871
gboolean
 
872
ephy_file_delete_dir_recursively (GFile *directory, GError **error)
888
873
{
889
 
        GFile *file;
890
 
        gboolean ret;
891
 
        
892
 
        file = g_file_new_for_path (path);
893
 
        
894
 
        ret = g_file_delete (file, NULL, NULL);
895
 
        
896
 
        if (ret == TRUE)
897
 
        {
898
 
                LOG ("Deleted dir '%s'", path);
899
 
        }
900
 
        else
901
 
        {
902
 
                LOG ("Couldn't delete dir '%s'", path);
903
 
        }
904
 
        g_object_unref (file);
 
874
        GFileEnumerator *children = NULL;
 
875
        GFileInfo *info;
 
876
        gboolean ret = TRUE;
 
877
 
 
878
        children = g_file_enumerate_children (directory,
 
879
                                              "standard::name,standard::type",
 
880
                                              0, NULL, error);
 
881
        if (error)
 
882
                goto out;
 
883
 
 
884
        info = g_file_enumerator_next_file (children, NULL, error);
 
885
        while (info || error) {
 
886
                GFile *child;
 
887
                const char *name;
 
888
                GFileType type;
 
889
 
 
890
                if (error)
 
891
                        goto out;
 
892
 
 
893
                name = g_file_info_get_name (info);
 
894
                child = g_file_get_child (directory, name);
 
895
                type = g_file_info_get_file_type (info);
 
896
 
 
897
                LOG ("ephy-file-delete-dir: delete child %s", name);
 
898
                if (type == G_FILE_TYPE_DIRECTORY)
 
899
                        ret = ephy_file_delete_dir_recursively (child, error);
 
900
                else if (type == G_FILE_TYPE_REGULAR)
 
901
                        ret =   g_file_delete (child, NULL, error);
 
902
 
 
903
                g_object_unref (info);
 
904
 
 
905
                if (!ret)
 
906
                        goto out;
 
907
 
 
908
                info = g_file_enumerator_next_file (children, NULL, error);
 
909
        }
 
910
 
 
911
        ret = TRUE;
 
912
 
 
913
        LOG ("ephy-file-delete-dir: delete successful");
 
914
        g_file_delete (directory, NULL, error);
 
915
 
 
916
out:
 
917
        if (children)
 
918
                g_object_unref (children);
 
919
 
 
920
        return ret;
905
921
}
906
922
 
907
923
/**
932
948
        }
933
949
        g_object_unref (file);
934
950
}
 
951
 
 
952
static gchar *
 
953
get_accels_filename (void)
 
954
{
 
955
        const char *home;
 
956
 
 
957
        home = g_get_home_dir();
 
958
        if (!home)
 
959
                return NULL;
 
960
        return g_build_filename (home, GNOME_DOT_GNOME, "accels", PACKAGE, NULL);
 
961
}
 
962
 
 
963
void
 
964
ephy_file_load_accels (void)
 
965
{
 
966
        char *filename;
 
967
 
 
968
        filename = get_accels_filename ();
 
969
        if (!filename)
 
970
                return;
 
971
 
 
972
        gtk_accel_map_load (filename);
 
973
        g_free (filename);
 
974
}
 
975
 
 
976
void
 
977
ephy_file_save_accels (void)
 
978
{
 
979
        char *filename;
 
980
 
 
981
        filename = get_accels_filename ();
 
982
        if (!filename)
 
983
                return;
 
984
 
 
985
        gtk_accel_map_save (filename);
 
986
        g_free (filename);
 
987
}