Example #1
0
static void
nemo_bookmark_connect_file (NemoBookmark *bookmark)
{
    if (bookmark->details->file != NULL) {
        DEBUG ("%s: file already connected, returning",
               nemo_bookmark_get_name (bookmark));
        return;
    }

    if (bookmark->details->exists) {
        DEBUG ("%s: creating file", nemo_bookmark_get_name (bookmark));

        bookmark->details->file = nemo_file_get (bookmark->details->location);
        g_assert (!nemo_file_is_gone (bookmark->details->file));

        g_signal_connect_object (bookmark->details->file, "changed",
                     G_CALLBACK (bookmark_file_changed_callback), bookmark, 0);
    }

    if (bookmark->details->icon == NULL ||
        bookmark->details->symbolic_icon == NULL) {
        nemo_bookmark_set_icon_to_default (bookmark);
    }

    if (bookmark->details->file != NULL &&
        nemo_file_check_if_ready (bookmark->details->file, NEMO_FILE_ATTRIBUTE_INFO)) {
        bookmark_set_name_from_ready_file (bookmark, bookmark->details->file);
    }

    if (bookmark->details->name == NULL) {
        bookmark->details->name = nemo_compute_title_for_location (bookmark->details->location);
    }
}
Example #2
0
static void
bookmark_file_changed_callback (NemoFile *file,
				NemoBookmark *bookmark)
{
	GFile *location;

	g_assert (file == bookmark->details->file);

	DEBUG ("%s: file changed", nemo_bookmark_get_name (bookmark));

	location = nemo_file_get_location (file);

	if (!g_file_equal (bookmark->details->location, location) &&
	    !nemo_file_is_in_trash (file)) {
		DEBUG ("%s: file got moved", nemo_bookmark_get_name (bookmark));

		g_object_unref (bookmark->details->location);
		bookmark->details->location = g_object_ref (location);

		g_object_notify_by_pspec (G_OBJECT (bookmark), properties[PROP_LOCATION]);
		g_signal_emit (bookmark, signals[CONTENTS_CHANGED], 0);
	}

	g_object_unref (location);

	if (nemo_file_is_gone (file) ||
	    nemo_file_is_in_trash (file)) {
		/* The file we were monitoring has been trashed, deleted,
		 * or moved in a way that we didn't notice. We should make
		 * a spanking new NemoFile object for this
		 * location so if a new file appears in this place
		 * we will notice. However, we can't immediately do so
		 * because creating a new NemoFile directly as a result
		 * of noticing a file goes away may trigger i/o on that file
		 * again, noticeing it is gone, leading to a loop.
		 * So, the new NemoFile is created when the bookmark
		 * is used again. However, this is not really a problem, as
		 * we don't want to change the icon or anything about the
		 * bookmark just because its not there anymore.
		 */
		DEBUG ("%s: trashed", nemo_bookmark_get_name (bookmark));
		nemo_bookmark_disconnect_file (bookmark);
        nemo_bookmark_set_icon_to_default (bookmark);
	} else {
		nemo_bookmark_update_icon (bookmark);
		bookmark_set_name_from_ready_file (bookmark, file);

        if (metadata_changed (bookmark)) {
            g_signal_emit (bookmark, signals[CONTENTS_CHANGED], 0);
        }
	}
}
Example #3
0
static void
unity_bookmarks_handler_update_bookmarks () {

	NemoBookmark *bookmark;
	guint bookmark_count;
	guint index;
	GList *l;

	/* append new set of bookmarks */
	bookmark_count = nemo_bookmark_list_length (bookmarks);
	for (index = 0; index < bookmark_count; ++index) {

		bookmark = nemo_bookmark_list_item_at (bookmarks, index);

		if (nemo_bookmark_uri_known_not_to_exist (bookmark)) {
			continue;
		}

		for (l = unity_quicklist_get_launcher_entries (unity_quicklist_handler); l; l = l->next) {
			UnityLauncherEntry *entry = l->data;

			DbusmenuMenuitem* menuitem = dbusmenu_menuitem_new();
			gchar *bookmark_name_dbusmenu = eel_str_replace_substring (nemo_bookmark_get_name (bookmark), "_", "__");
			dbusmenu_menuitem_property_set (menuitem, "label", bookmark_name_dbusmenu);
			g_free (bookmark_name_dbusmenu);
			g_signal_connect (menuitem, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
										 (GCallback) activate_bookmark_by_quicklist,
										 bookmark);

			unity_quicklist_handler_append_menuitem (entry, menuitem);
		}
	}
}
Example #4
0
static void
nemo_bookmark_update_icon (NemoBookmark *bookmark)
{
	GIcon *new_icon;

	if (bookmark->details->file == NULL) {
		return;
	}

	if (!nemo_file_is_local (bookmark->details->file)) {
		/* never update icons for remote bookmarks */
		return;
	}

	if (!nemo_file_is_not_yet_confirmed (bookmark->details->file) &&
	    nemo_file_check_if_ready (bookmark->details->file,
					  NEMO_FILE_ATTRIBUTES_FOR_ICON)) {
		DEBUG ("%s: set new icon", nemo_bookmark_get_name (bookmark));

		new_icon = nemo_file_get_gicon (bookmark->details->file, 0);
		g_object_set (bookmark,
			      "icon", new_icon,
			      NULL);

		g_object_unref (new_icon);
	}
}
Example #5
0
static void
nemo_bookmark_set_icon_to_default (NemoBookmark *bookmark)
{
	GIcon *icon, *emblemed_icon, *folder;
	GEmblem *emblem;
	char *uri;

	if (g_file_is_native (bookmark->details->location)) {
		folder = g_themed_icon_new (NEMO_ICON_FOLDER);
	} else {
		uri = nemo_bookmark_get_uri (bookmark);
		if (g_str_has_prefix (uri, EEL_SEARCH_URI)) {
			folder = g_themed_icon_new (NEMO_ICON_FOLDER_SAVED_SEARCH);
		} else {
			folder = g_themed_icon_new (NEMO_ICON_FOLDER_REMOTE);
		}
		g_free (uri);
	}

	if (nemo_bookmark_uri_known_not_to_exist (bookmark)) {
		DEBUG ("%s: file does not exist, add emblem", nemo_bookmark_get_name (bookmark));

		icon = g_themed_icon_new (GTK_STOCK_DIALOG_WARNING);
		emblem = g_emblem_new (icon);

		emblemed_icon = g_emblemed_icon_new (folder, emblem);

		g_object_unref (emblem);
		g_object_unref (icon);
		g_object_unref (folder);

		folder = emblemed_icon;
	}

	DEBUG ("%s: setting icon to default", nemo_bookmark_get_name (bookmark));

	g_object_set (bookmark,
		      "icon", folder,
		      NULL);

	g_object_unref (folder);
}
Example #6
0
static void
nemo_bookmark_disconnect_file (NemoBookmark *bookmark)
{
	if (bookmark->details->file != NULL) {
		DEBUG ("%s: disconnecting file",
		       nemo_bookmark_get_name (bookmark));

		g_signal_handlers_disconnect_by_func (bookmark->details->file,
						      G_CALLBACK (bookmark_file_changed_callback),
						      bookmark);
		g_clear_object (&bookmark->details->file);
	}
}
Example #7
0
static void
nemo_bookmark_set_icon_to_default (NemoBookmark *bookmark)
{
    GIcon *icon, *symbolic_icon;
    char *uri;

    if (g_file_is_native (bookmark->details->location)) {
        symbolic_icon = get_native_icon (bookmark, TRUE);
        icon = get_native_icon (bookmark, FALSE);
    } else {
        uri = nemo_bookmark_get_uri (bookmark);
        if (g_str_has_prefix (uri, EEL_SEARCH_URI)) {
            symbolic_icon = g_themed_icon_new (NEMO_ICON_FOLDER_SAVED_SEARCH);
            icon = g_themed_icon_new (NEMO_ICON_FULLCOLOR_FOLDER_SAVED_SEARCH);
        } else {
            symbolic_icon = g_themed_icon_new (NEMO_ICON_FOLDER_REMOTE);
            icon = g_themed_icon_new (NEMO_ICON_FULLCOLOR_FOLDER_REMOTE);
        }
        g_free (uri);
    }

    if (!bookmark->details->exists) {
        DEBUG ("%s: file does not exist, add emblem", nemo_bookmark_get_name (bookmark));

        apply_warning_emblem (&icon, FALSE);
        apply_warning_emblem (&symbolic_icon, TRUE);
    }

    DEBUG ("%s: setting icon to default", nemo_bookmark_get_name (bookmark));

    g_object_set (bookmark,
              "icon", icon,
              "symbolic-icon", symbolic_icon,
              NULL);

    g_object_unref (icon);
    g_object_unref (symbolic_icon);
}
Example #8
0
static void
nemo_bookmark_set_icon_to_default (NemoBookmark *bookmark)
{
    gchar *icon_name;

    icon_name = construct_default_icon_from_metadata (bookmark);

    if (!nemo_bookmark_uri_get_exists (bookmark)) {
        DEBUG ("%s: file does not exist, use special icon", nemo_bookmark_get_name (bookmark));

        g_clear_pointer (&icon_name, g_free);

        icon_name = g_strdup (NEMO_ICON_SYMBOLIC_MISSING_BOOKMARK);
    }

    DEBUG ("%s: setting icon to default", nemo_bookmark_get_name (bookmark));

    g_object_set (bookmark,
                  "icon-name", icon_name,
                  NULL);

    g_free (icon_name);
}
Example #9
0
static void
nemo_bookmark_set_exists (NemoBookmark *bookmark,
                  gboolean exists)
{
    if (bookmark->details->exists == exists) {
        return;
    }

    bookmark->details->exists = exists;
    DEBUG ("%s: setting bookmark to exist: %d\n",
           nemo_bookmark_get_name (bookmark), exists);

    /* refresh icon */
    nemo_bookmark_set_icon_to_default (bookmark);
}
Example #10
0
static void
on_selection_changed (GtkTreeSelection *treeselection,
		      gpointer user_data)
{
	NemoBookmark *selected;
	const char *name = NULL;
	char *entry_text = NULL;
	GFile *location;

	g_assert (GTK_IS_ENTRY (name_field));
	g_assert (GTK_IS_ENTRY (uri_field));

	selected = get_selected_bookmark ();

	if (selected) {
		name = nemo_bookmark_get_name (selected);
		location = nemo_bookmark_get_location (selected);
		entry_text = g_file_get_parse_name (location);

		g_object_unref (location);
	}
	
	/* Set the sensitivity of widgets that require a selection */
	gtk_widget_set_sensitive (remove_button, selected != NULL);
    gtk_widget_set_sensitive (jump_button, selected != NULL);
    gtk_widget_set_sensitive (sort_button, selected != NULL);
	gtk_widget_set_sensitive (name_field, selected != NULL);
	gtk_widget_set_sensitive (uri_field, selected != NULL);

	g_signal_handler_block (name_field, name_field_changed_signal_id);
	nemo_entry_set_text (NEMO_ENTRY (name_field),
				 name ? name : "");
	g_signal_handler_unblock (name_field, name_field_changed_signal_id);

	g_signal_handler_block (uri_field, uri_field_changed_signal_id);
	nemo_entry_set_text (NEMO_ENTRY (uri_field),
				 entry_text ? entry_text : "");
	g_signal_handler_unblock (uri_field, uri_field_changed_signal_id);

	text_changed = FALSE;
	name_text_changed = FALSE;

	g_free (entry_text);
}
Example #11
0
static void
bookmark_set_name_from_ready_file (NemoBookmark *self,
				   NemoFile *file)
{
	gchar *display_name;

	if (self->details->has_custom_name) {
		return;
	}

	display_name = nemo_file_get_display_name (self->details->file);

	if (nemo_file_is_home (self->details->file)) {
		nemo_bookmark_set_custom_name (self, _("Home"));
	} else if (g_strcmp0 (self->details->name, display_name) != 0) {
		nemo_bookmark_set_custom_name (self, display_name);
		DEBUG ("%s: name changed to %s", nemo_bookmark_get_name (self), display_name);
	}

	g_free (display_name);
}
Example #12
0
static void
nemo_bookmark_update_icon (NemoBookmark *bookmark)
{
    gchar *new_icon_name;

    if (bookmark->details->file == NULL) {
        return;
    }

    if (!nemo_file_is_not_yet_confirmed (bookmark->details->file) &&
        nemo_file_check_if_ready (bookmark->details->file,
                                  NEMO_FILE_ATTRIBUTES_FOR_ICON)) {
        DEBUG ("%s: set new icon", nemo_bookmark_get_name (bookmark));

        new_icon_name = nemo_file_get_control_icon_name (bookmark->details->file);
        g_object_set (bookmark,
                      "icon-name", new_icon_name,
                      NULL);

        g_free (new_icon_name);
    }
}
Example #13
0
static void
nemo_bookmark_disconnect_file (NemoBookmark *bookmark)
{
    if (bookmark->details->file != NULL) {
        DEBUG ("%s: disconnecting file",
               nemo_bookmark_get_name (bookmark));

        g_signal_handlers_disconnect_by_func (bookmark->details->file,
                              G_CALLBACK (bookmark_file_changed_callback),
                              bookmark);
        g_clear_object (&bookmark->details->file);
    }

    if (bookmark->details->cancellable != NULL) {
        g_cancellable_cancel (bookmark->details->cancellable);
        g_clear_object (&bookmark->details->cancellable);
    }

    if (bookmark->details->exists_id != 0) {
        g_source_remove (bookmark->details->exists_id);
        bookmark->details->exists_id = 0;
    }
}
Example #14
0
void
nemo_menus_append_bookmark_to_menu (NemoWindow *window, 
					NemoBookmark *bookmark, 
					const char *parent_path,
					const char *parent_id,
					guint index_in_parent,
					GtkActionGroup *action_group,
					guint merge_id,
					GCallback refresh_callback,
					NemoBookmarkFailedCallback failed_callback)
{
	BookmarkHolder *bookmark_holder;
	char action_name[128];
	const char *name;
	char *path;
	GIcon *icon;
	GtkAction *action;
	GtkWidget *menuitem;

	g_assert (NEMO_IS_WINDOW (window));
	g_assert (NEMO_IS_BOOKMARK (bookmark));

	bookmark_holder = bookmark_holder_new (bookmark, window, refresh_callback, failed_callback);
	name = nemo_bookmark_get_name (bookmark);

	/* Create menu item with pixbuf */
	icon = nemo_bookmark_get_icon (bookmark);

	g_snprintf (action_name, sizeof (action_name), "%s%d", parent_id, index_in_parent);

	action = gtk_action_new (action_name,
				 name,
				 _("Go to the location specified by this bookmark"),
				 NULL);
	
	g_object_set_data_full (G_OBJECT (action), "menu-icon",
				icon,
				g_object_unref);

	g_signal_connect_data (action, "activate",
			       G_CALLBACK (activate_bookmark_in_menu_item),
			       bookmark_holder, 
			       bookmark_holder_free_cover, 0);

	gtk_action_group_add_action (action_group,
				     GTK_ACTION (action));

	g_object_unref (action);

	gtk_ui_manager_add_ui (window->details->ui_manager,
			       merge_id,
			       parent_path,
			       action_name,
			       action_name,
			       GTK_UI_MANAGER_MENUITEM,
			       FALSE);

	path = g_strdup_printf ("%s/%s", parent_path, action_name);
	menuitem = gtk_ui_manager_get_widget (window->details->ui_manager,
					      path);
	gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem),
						   TRUE);

	g_free (path);
}
Example #15
0
static void
repopulate (void)
{
	NemoBookmark *selected;
	GtkListStore *store;
	GtkTreePath *path;
	GtkTreeRowReference *reference;
	guint index;

	g_assert (GTK_IS_TREE_VIEW (bookmark_list_widget));
	g_assert (NEMO_IS_BOOKMARK_LIST (bookmarks));
	
	store = GTK_LIST_STORE (bookmark_list_store);

	selected = get_selected_bookmark ();

	g_signal_handler_block (bookmark_selection,
				selection_changed_id);
	g_signal_handler_block (bookmark_list_store,
				row_deleted_signal_id);
        g_signal_handler_block (bookmark_list_widget,
                                row_activated_signal_id);
        g_signal_handler_block (bookmark_list_widget,
                                key_pressed_signal_id);
        g_signal_handler_block (bookmark_list_widget,
                                button_pressed_signal_id);

	gtk_list_store_clear (store);
	
	g_signal_handler_unblock (bookmark_list_widget,
				  row_activated_signal_id);
        g_signal_handler_unblock (bookmark_list_widget,
                                  key_pressed_signal_id);
        g_signal_handler_unblock (bookmark_list_widget,
                                  button_pressed_signal_id);
	g_signal_handler_unblock (bookmark_list_store,
				  row_deleted_signal_id);
	g_signal_handler_unblock (bookmark_selection,
				  selection_changed_id);
	
	/* Fill the list in with the bookmark names. */
	g_signal_handler_block (store, row_changed_signal_id);

	reference = NULL;

	for (index = 0; index < nemo_bookmark_list_length (bookmarks); ++index) {
		NemoBookmark *bookmark;
		const char       *bookmark_name;
		GIcon            *bookmark_icon;
		GtkTreeIter       iter;

		bookmark = nemo_bookmark_list_item_at (bookmarks, index);
		bookmark_name = nemo_bookmark_get_name (bookmark);
		bookmark_icon = nemo_bookmark_get_icon (bookmark);

		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter, 
				    BOOKMARK_LIST_COLUMN_ICON, bookmark_icon,
				    BOOKMARK_LIST_COLUMN_NAME, bookmark_name,
				    BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark,
				    BOOKMARK_LIST_COLUMN_STYLE, PANGO_STYLE_NORMAL,
				    -1);

		if (bookmark == selected) {
			/* save old selection */
			GtkTreePath *path;

			path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
			reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path);
			gtk_tree_path_free (path);
		}

		g_object_unref (bookmark_icon);
	}

	g_signal_handler_unblock (store, row_changed_signal_id);

	if (reference != NULL) {
		/* restore old selection */

		/* bookmarks_set_empty() will call the selection change handler,
 		 * so we block it here in case of selection change.
 		 */
		g_signal_handler_block (bookmark_selection, selection_changed_id);

		g_assert (index != 0);
		g_assert (gtk_tree_row_reference_valid (reference));

		path = gtk_tree_row_reference_get_path (reference);
		gtk_tree_selection_select_path (bookmark_selection, path);
		gtk_tree_row_reference_free (reference);
		gtk_tree_path_free (path);

		g_signal_handler_unblock (bookmark_selection, selection_changed_id);
	}

	bookmarks_set_empty (index == 0);	  
}
Example #16
0
static void
update_bookmark_from_text (void)
{
	if (text_changed) {
		NemoBookmark *bookmark, *bookmark_in_list;
		const char *name;
		GIcon *icon;
		guint selected_row;
		GtkTreeIter iter;
		GFile *location;

		g_assert (GTK_IS_ENTRY (name_field));
		g_assert (GTK_IS_ENTRY (uri_field));

		if (gtk_entry_get_text_length (GTK_ENTRY (uri_field)) == 0) {
			return;
		}

		location = g_file_parse_name 
			(gtk_entry_get_text (GTK_ENTRY (uri_field)));
		
		bookmark = nemo_bookmark_new (location,
						  name_text_changed ? gtk_entry_get_text (GTK_ENTRY (name_field)) : NULL,
						  NULL);
		
		g_object_unref (location);

		selected_row = get_selected_row ();

		/* turn off list updating 'cuz otherwise the list-reordering code runs
		 * after repopulate(), thus reordering the correctly-ordered list.
		 */
		g_signal_handler_block (bookmarks, 
					bookmark_list_changed_signal_id);
		nemo_bookmark_list_delete_item_at (bookmarks, selected_row);
		nemo_bookmark_list_insert_item (bookmarks, bookmark, selected_row);
		g_signal_handler_unblock (bookmarks, 
					  bookmark_list_changed_signal_id);
		g_object_unref (bookmark);

		/* We also have to update the bookmark pointer in the list
		   store. */
		gtk_tree_selection_get_selected (bookmark_selection,
						 NULL, &iter);
		g_signal_handler_block (bookmark_list_store,
					row_changed_signal_id);

		bookmark_in_list = nemo_bookmark_list_item_at (bookmarks,
								   selected_row);

		name = nemo_bookmark_get_name (bookmark_in_list);
		icon = nemo_bookmark_get_icon (bookmark_in_list);

		gtk_list_store_set (bookmark_list_store, &iter,
				    BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark_in_list,
				    BOOKMARK_LIST_COLUMN_NAME, name,
				    BOOKMARK_LIST_COLUMN_ICON, icon,
				    -1);
		g_signal_handler_unblock (bookmark_list_store,
					  row_changed_signal_id);

		g_object_unref (icon);
	}
}