Skip to content

Instantly share code, notes, and snippets.

@hubgit
Created January 30, 2012 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hubgit/1704009 to your computer and use it in GitHub Desktop.
Save hubgit/1704009 to your computer and use it in GitHub Desktop.
Re-arrange Nautilus sidebar sections. Moves a couple of sections further down, no code changes other than that.
--- nautilus-ubuntu-orig/nautilus-3.2.1/src/nautilus-places-sidebar.c 2011-10-17 21:29:15.000000000 +0100
+++ nautilus-ubuntu/nautilus-3.2.1/src/nautilus-places-sidebar.c 2012-01-30 11:40:01.794711707 +0000
@@ -487,174 +487,6 @@
volume_monitor = sidebar->volume_monitor;
- /* first go through all connected drives */
- drives = g_volume_monitor_get_connected_drives (volume_monitor);
-
- for (l = drives; l != NULL; l = l->next) {
- drive = l->data;
-
- volumes = g_drive_get_volumes (drive);
- if (volumes != NULL) {
- for (ll = volumes; ll != NULL; ll = ll->next) {
- volume = ll->data;
- mount = g_volume_get_mount (volume);
- if (mount != NULL) {
- /* Show mounted volume in the sidebar */
- icon = g_mount_get_icon (mount);
- root = g_mount_get_default_location (mount);
- mount_uri = g_file_get_uri (root);
- name = g_mount_get_name (mount);
- tooltip = g_file_get_parse_name (root);
-
- last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
- SECTION_DEVICES,
- name, icon, mount_uri,
- drive, volume, mount, 0, tooltip);
- compare_for_selection (sidebar,
- location, mount_uri, last_uri,
- &last_iter, &select_path);
- g_object_unref (root);
- g_object_unref (mount);
- g_object_unref (icon);
- g_free (tooltip);
- g_free (name);
- g_free (mount_uri);
- } else {
- /* Do show the unmounted volumes in the sidebar;
- * this is so the user can mount it (in case automounting
- * is off).
- *
- * Also, even if automounting is enabled, this gives a visual
- * cue that the user should remember to yank out the media if
- * he just unmounted it.
- */
- icon = g_volume_get_icon (volume);
- name = g_volume_get_name (volume);
- tooltip = g_strdup_printf (_("Mount and open %s"), name);
-
- last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
- SECTION_DEVICES,
- name, icon, NULL,
- drive, volume, NULL, 0, tooltip);
- g_object_unref (icon);
- g_free (name);
- g_free (tooltip);
- }
- g_object_unref (volume);
- }
- g_list_free (volumes);
- } else {
- if (g_drive_is_media_removable (drive) && !g_drive_is_media_check_automatic (drive)) {
- /* If the drive has no mountable volumes and we cannot detect media change.. we
- * display the drive in the sidebar so the user can manually poll the drive by
- * right clicking and selecting "Rescan..."
- *
- * This is mainly for drives like floppies where media detection doesn't
- * work.. but it's also for human beings who like to turn off media detection
- * in the OS to save battery juice.
- */
- icon = g_drive_get_icon (drive);
- name = g_drive_get_name (drive);
- tooltip = g_strdup_printf (_("Mount and open %s"), name);
-
- last_iter = add_place (sidebar, PLACES_BUILT_IN,
- SECTION_DEVICES,
- name, icon, NULL,
- drive, NULL, NULL, 0, tooltip);
- g_object_unref (icon);
- g_free (tooltip);
- g_free (name);
- }
- }
- g_object_unref (drive);
- }
- g_list_free (drives);
-
- /* add all volumes that is not associated with a drive */
- volumes = g_volume_monitor_get_volumes (volume_monitor);
- for (l = volumes; l != NULL; l = l->next) {
- volume = l->data;
- drive = g_volume_get_drive (volume);
- if (drive != NULL) {
- g_object_unref (volume);
- g_object_unref (drive);
- continue;
- }
- mount = g_volume_get_mount (volume);
- if (mount != NULL) {
- icon = g_mount_get_icon (mount);
- root = g_mount_get_default_location (mount);
- mount_uri = g_file_get_uri (root);
- tooltip = g_file_get_parse_name (root);
- g_object_unref (root);
- name = g_mount_get_name (mount);
- last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
- SECTION_DEVICES,
- name, icon, mount_uri,
- NULL, volume, mount, 0, tooltip);
- compare_for_selection (sidebar,
- location, mount_uri, last_uri,
- &last_iter, &select_path);
- g_object_unref (mount);
- g_object_unref (icon);
- g_free (name);
- g_free (tooltip);
- g_free (mount_uri);
- } else {
- /* see comment above in why we add an icon for an unmounted mountable volume */
- icon = g_volume_get_icon (volume);
- name = g_volume_get_name (volume);
- last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
- SECTION_DEVICES,
- name, icon, NULL,
- NULL, volume, NULL, 0, name);
- g_object_unref (icon);
- g_free (name);
- }
- g_object_unref (volume);
- }
- g_list_free (volumes);
-
- /* add bookmarks */
- bookmark_count = nautilus_bookmark_list_length (sidebar->bookmarks);
-
- for (index = 0; index < bookmark_count; ++index) {
- bookmark = nautilus_bookmark_list_item_at (sidebar->bookmarks, index);
-
- if (nautilus_bookmark_uri_known_not_to_exist (bookmark)) {
- continue;
- }
-
- root = nautilus_bookmark_get_location (bookmark);
- file = nautilus_file_get (root);
-
- if (is_built_in_bookmark (file)) {
- g_object_unref (root);
- nautilus_file_unref (file);
- continue;
- }
- nautilus_file_unref (file);
-
- bookmark_name = nautilus_bookmark_get_name (bookmark);
- icon = nautilus_bookmark_get_icon (bookmark);
- mount_uri = nautilus_bookmark_get_uri (bookmark);
- tooltip = g_file_get_parse_name (root);
-
- last_iter = add_place (sidebar, PLACES_BOOKMARK,
- SECTION_BOOKMARKS,
- bookmark_name, icon, mount_uri,
- NULL, NULL, NULL, index,
- tooltip);
- compare_for_selection (sidebar,
- location, mount_uri, last_uri,
- &last_iter, &select_path);
-
- g_object_unref (root);
- g_object_unref (icon);
- g_free (mount_uri);
- g_free (tooltip);
- }
-
last_iter = add_heading (sidebar, SECTION_COMPUTER,
_("Computer"));
@@ -801,6 +633,174 @@
location, mount_uri, last_uri,
&last_iter, &select_path);
g_object_unref (icon);
+
+ /* add bookmarks */
+ bookmark_count = nautilus_bookmark_list_length (sidebar->bookmarks);
+
+ for (index = 0; index < bookmark_count; ++index) {
+ bookmark = nautilus_bookmark_list_item_at (sidebar->bookmarks, index);
+
+ if (nautilus_bookmark_uri_known_not_to_exist (bookmark)) {
+ continue;
+ }
+
+ root = nautilus_bookmark_get_location (bookmark);
+ file = nautilus_file_get (root);
+
+ if (is_built_in_bookmark (file)) {
+ g_object_unref (root);
+ nautilus_file_unref (file);
+ continue;
+ }
+ nautilus_file_unref (file);
+
+ bookmark_name = nautilus_bookmark_get_name (bookmark);
+ icon = nautilus_bookmark_get_icon (bookmark);
+ mount_uri = nautilus_bookmark_get_uri (bookmark);
+ tooltip = g_file_get_parse_name (root);
+
+ last_iter = add_place (sidebar, PLACES_BOOKMARK,
+ SECTION_BOOKMARKS,
+ bookmark_name, icon, mount_uri,
+ NULL, NULL, NULL, index,
+ tooltip);
+ compare_for_selection (sidebar,
+ location, mount_uri, last_uri,
+ &last_iter, &select_path);
+
+ g_object_unref (root);
+ g_object_unref (icon);
+ g_free (mount_uri);
+ g_free (tooltip);
+ }
+
+ /* go through all connected drives */
+ drives = g_volume_monitor_get_connected_drives (volume_monitor);
+
+ for (l = drives; l != NULL; l = l->next) {
+ drive = l->data;
+
+ volumes = g_drive_get_volumes (drive);
+ if (volumes != NULL) {
+ for (ll = volumes; ll != NULL; ll = ll->next) {
+ volume = ll->data;
+ mount = g_volume_get_mount (volume);
+ if (mount != NULL) {
+ /* Show mounted volume in the sidebar */
+ icon = g_mount_get_icon (mount);
+ root = g_mount_get_default_location (mount);
+ mount_uri = g_file_get_uri (root);
+ name = g_mount_get_name (mount);
+ tooltip = g_file_get_parse_name (root);
+
+ last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
+ SECTION_DEVICES,
+ name, icon, mount_uri,
+ drive, volume, mount, 0, tooltip);
+ compare_for_selection (sidebar,
+ location, mount_uri, last_uri,
+ &last_iter, &select_path);
+ g_object_unref (root);
+ g_object_unref (mount);
+ g_object_unref (icon);
+ g_free (tooltip);
+ g_free (name);
+ g_free (mount_uri);
+ } else {
+ /* Do show the unmounted volumes in the sidebar;
+ * this is so the user can mount it (in case automounting
+ * is off).
+ *
+ * Also, even if automounting is enabled, this gives a visual
+ * cue that the user should remember to yank out the media if
+ * he just unmounted it.
+ */
+ icon = g_volume_get_icon (volume);
+ name = g_volume_get_name (volume);
+ tooltip = g_strdup_printf (_("Mount and open %s"), name);
+
+ last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
+ SECTION_DEVICES,
+ name, icon, NULL,
+ drive, volume, NULL, 0, tooltip);
+ g_object_unref (icon);
+ g_free (name);
+ g_free (tooltip);
+ }
+ g_object_unref (volume);
+ }
+ g_list_free (volumes);
+ } else {
+ if (g_drive_is_media_removable (drive) && !g_drive_is_media_check_automatic (drive)) {
+ /* If the drive has no mountable volumes and we cannot detect media change.. we
+ * display the drive in the sidebar so the user can manually poll the drive by
+ * right clicking and selecting "Rescan..."
+ *
+ * This is mainly for drives like floppies where media detection doesn't
+ * work.. but it's also for human beings who like to turn off media detection
+ * in the OS to save battery juice.
+ */
+ icon = g_drive_get_icon (drive);
+ name = g_drive_get_name (drive);
+ tooltip = g_strdup_printf (_("Mount and open %s"), name);
+
+ last_iter = add_place (sidebar, PLACES_BUILT_IN,
+ SECTION_DEVICES,
+ name, icon, NULL,
+ drive, NULL, NULL, 0, tooltip);
+ g_object_unref (icon);
+ g_free (tooltip);
+ g_free (name);
+ }
+ }
+ g_object_unref (drive);
+ }
+ g_list_free (drives);
+
+ /* add all volumes that is not associated with a drive */
+ volumes = g_volume_monitor_get_volumes (volume_monitor);
+ for (l = volumes; l != NULL; l = l->next) {
+ volume = l->data;
+ drive = g_volume_get_drive (volume);
+ if (drive != NULL) {
+ g_object_unref (volume);
+ g_object_unref (drive);
+ continue;
+ }
+ mount = g_volume_get_mount (volume);
+ if (mount != NULL) {
+ icon = g_mount_get_icon (mount);
+ root = g_mount_get_default_location (mount);
+ mount_uri = g_file_get_uri (root);
+ tooltip = g_file_get_parse_name (root);
+ g_object_unref (root);
+ name = g_mount_get_name (mount);
+ last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
+ SECTION_DEVICES,
+ name, icon, mount_uri,
+ NULL, volume, mount, 0, tooltip);
+ compare_for_selection (sidebar,
+ location, mount_uri, last_uri,
+ &last_iter, &select_path);
+ g_object_unref (mount);
+ g_object_unref (icon);
+ g_free (name);
+ g_free (tooltip);
+ g_free (mount_uri);
+ } else {
+ /* see comment above in why we add an icon for an unmounted mountable volume */
+ icon = g_volume_get_icon (volume);
+ name = g_volume_get_name (volume);
+ last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
+ SECTION_DEVICES,
+ name, icon, NULL,
+ NULL, volume, NULL, 0, name);
+ g_object_unref (icon);
+ g_free (name);
+ }
+ g_object_unref (volume);
+ }
+ g_list_free (volumes);
/* network */
last_iter = add_heading (sidebar, SECTION_NETWORK,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment