Beispiel #1
0
/**
 * nemo_location_bar_update_icon
 *
 * if the text in the entry matches the uri, set the label to "location", otherwise use "goto"
 *
 **/
static void
nemo_location_bar_update_icon (NemoLocationBar *bar)
{
       const char *current_text;
       GFile *location;
       GFile *last_location;

       if (bar->details->last_location == NULL){
               nemo_location_entry_set_secondary_action (NEMO_LOCATION_ENTRY (bar->details->entry),
                                                             NEMO_LOCATION_ENTRY_ACTION_GOTO);
               return;
       }

       current_text = gtk_entry_get_text (GTK_ENTRY (bar->details->entry));
       location = g_file_parse_name (current_text);
       last_location = g_file_parse_name (bar->details->last_location);

       if (g_file_equal (last_location, location)) {
               nemo_location_entry_set_secondary_action (NEMO_LOCATION_ENTRY (bar->details->entry),
                                                             NEMO_LOCATION_ENTRY_ACTION_CLEAR);
       } else {
               nemo_location_entry_set_secondary_action (NEMO_LOCATION_ENTRY (bar->details->entry),
                                                             NEMO_LOCATION_ENTRY_ACTION_GOTO);
       }

       g_object_unref (location);
       g_object_unref (last_location);
}
/**
 * athena_location_bar_update_label
 *
 * if the text in the entry matches the uri, set the label to "location", otherwise use "goto"
 *
 **/
static void
athena_location_bar_update_label (AthenaLocationBar *bar)
{
	const char *current_text;
	GFile *location;
	GFile *last_location;
	
	if (bar->details->last_location == NULL){
		gtk_label_set_text (GTK_LABEL (bar->details->label), GO_TO_LABEL);
		athena_location_entry_set_secondary_action (ATHENA_LOCATION_ENTRY (bar->details->entry), 
							      ATHENA_LOCATION_ENTRY_ACTION_GOTO);
		return;
	}

	current_text = gtk_entry_get_text (GTK_ENTRY (bar->details->entry));
	location = g_file_parse_name (current_text);
	last_location = g_file_parse_name (bar->details->last_location);
	
	if (g_file_equal (last_location, location)) {
		gtk_label_set_text (GTK_LABEL (bar->details->label), LOCATION_LABEL);
		athena_location_entry_set_secondary_action (ATHENA_LOCATION_ENTRY (bar->details->entry), 
							      ATHENA_LOCATION_ENTRY_ACTION_CLEAR);
	} else {		 
		gtk_label_set_text (GTK_LABEL (bar->details->label), GO_TO_LABEL);
		athena_location_entry_set_secondary_action (ATHENA_LOCATION_ENTRY (bar->details->entry), 
							      ATHENA_LOCATION_ENTRY_ACTION_GOTO);
	}

	g_object_unref (location);
	g_object_unref (last_location);
}
Beispiel #3
0
static void _save_file(EDITOR *e)
{
	GtkRecentManager *rm = NULL;
	GString *data = g_string_new("");

	editor_get_document_content(data, e);
	XI_message(("%s", data->str));

	if (!e->filename || (0 == g_strcmp0("Untitled document", e->filename)) || g_strrstr(e->filename, ".spt")) {
		GtkWidget *dialog = gtk_file_chooser_dialog_new("Save as",		      //const gchar *title,
								NULL,			      //GtkWindow *parent,
								GTK_FILE_CHOOSER_ACTION_SAVE, //GtkFileChooserAction action,
#ifdef HAVE_GTK_310
								"_OK",
								GTK_RESPONSE_OK,
								"_Cancel",
								GTK_RESPONSE_CANCEL,
#else
								GTK_STOCK_OK,
								GTK_RESPONSE_OK,
								GTK_STOCK_CANCEL,
								GTK_RESPONSE_CANCEL,
#endif
								NULL);
		gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);

		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
						    settings.studypaddir);
		if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
			gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
			e->filename = g_strdup(filename);
			GFile *gfile = g_file_parse_name(filename);
			g_file_replace_contents(gfile, data->str, data->len, NULL, TRUE, G_FILE_CREATE_NONE, NULL, NULL, NULL); //GError **error
		}
		change_window_title(e->window, e->filename);
		gtk_widget_destroy(dialog);

	} else {

		GFile *gfile = g_file_parse_name(e->filename);
		g_file_replace_contents(gfile, data->str, data->len, NULL, TRUE, G_FILE_CREATE_NONE, NULL, NULL, NULL); //GError **error
	}

	rm = gtk_recent_manager_get_default();
	gtk_recent_manager_add_item(rm, e->filename);

	e->is_changed = FALSE;
	g_string_free(data, TRUE);
}
static void
nautilus_location_entry_update_action (NautilusLocationEntry *entry)
{
	const char *current_text;
	GFile *location;

	if (entry->details->last_location == NULL){
		nautilus_location_entry_set_secondary_action (entry,
							      NAUTILUS_LOCATION_ENTRY_ACTION_GOTO);
		return;
	}

	current_text = gtk_entry_get_text (GTK_ENTRY (entry));
	location = g_file_parse_name (current_text);

	if (g_file_equal (entry->details->last_location, location)) {
		nautilus_location_entry_set_secondary_action (entry,
							      NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR);
	} else {
		nautilus_location_entry_set_secondary_action (entry,
							      NAUTILUS_LOCATION_ENTRY_ACTION_GOTO);
	}

	g_object_unref (location);
}
Beispiel #5
0
void
logview_prefs_remove_stored_log (LogviewPrefs *prefs, GFile *target)
{
  gchar **stored_logs;
  GFile *stored;
  GPtrArray *new_value;
  gint idx;
  gboolean removed = FALSE;

  g_assert (LOGVIEW_IS_PREFS (prefs));
  g_assert (G_IS_FILE (target));

  stored_logs = logview_prefs_get_stored_logfiles (prefs);
  new_value = g_ptr_array_new ();

  for (idx = 0; stored_logs[idx] != NULL; idx++) {
    stored = g_file_parse_name (stored_logs[idx]);
    if (!g_file_equal (stored, target)) {
      g_ptr_array_add (new_value, g_strdup (stored_logs[idx]));
    }

    g_object_unref (stored);
  }

  g_ptr_array_add (new_value, NULL);
  g_strfreev (stored_logs);
  stored_logs = (gchar **) g_ptr_array_free (new_value, FALSE);

  g_settings_set_strv (prefs->priv->logview_prefs,
                       PREF_LOGFILES,
                       (const gchar **) stored_logs);

  g_strfreev (stored_logs);
}
Beispiel #6
0
void
trash_dir_cb (GtkMenuItem *pmenu, gpointer dummy)
{
	GFile *file;

	g_assert (!dummy);
	g_assert (baobab.selected_path);

	file = g_file_parse_name (baobab.selected_path);

	if (trash_file (file)) {
		GtkTreeIter iter;
		guint64 filesize;
		GtkTreeSelection *selection;

		selection =
		    gtk_tree_view_get_selection ((GtkTreeView *) baobab.
						 tree_view);
		gtk_tree_selection_get_selected (selection, NULL, &iter);
		gtk_tree_model_get ((GtkTreeModel *) baobab.model, &iter,
				    5, &filesize, -1);
		gtk_tree_store_remove (GTK_TREE_STORE (baobab.model),
				       &iter);
	}

	g_object_unref (file);
}
Beispiel #7
0
/* Returns a list of possible matches and the basename to use for it */
static GList *
init_completion (GFilenameCompleter *completer,
		 const char *initial_text,
		 char **basename_out)
{
  gboolean should_escape;
  GFile *file, *parent;
  char *basename;
  char *t;
  int len;

  *basename_out = NULL;
  
  should_escape = ! (g_path_is_absolute (initial_text) || *initial_text == '~');

  len = strlen (initial_text);
  
  if (len > 0 &&
      initial_text[len - 1] == '/')
    return NULL;
  
  file = g_file_parse_name (initial_text);
  parent = g_file_get_parent (file);
  if (parent == NULL)
    {
      g_object_unref (file);
      return NULL;
    }

  if (completer->basenames_dir == NULL ||
      completer->basenames_are_escaped != should_escape ||
      !g_file_equal (parent, completer->basenames_dir))
    {
      schedule_load_basenames (completer, parent, should_escape);
      g_object_unref (file);
      return NULL;
    }
  
  basename = g_file_get_basename (file);
  if (should_escape)
    {
      t = basename;
      basename = g_uri_escape_string (basename, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
      g_free (t);
    }
  else
    {
      t = basename;
      basename = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
      g_free (t);
      
      if (basename == NULL)
	return NULL;
    }

  *basename_out = basename;

  return completer->basenames;
}
static void
update_bookmark_from_text (NautilusBookmarksWindow *self)
{
	NautilusBookmark *bookmark, *bookmark_in_list;
	const char *name;
	GIcon *icon;
	guint selected_row;
	GtkTreeIter iter;
	GFile *location;

	if (!self->priv->text_changed ||
	    gtk_entry_get_text_length (GTK_ENTRY (self->priv->uri_field)) == 0) {
		return;
	}

	location = g_file_parse_name 
		(gtk_entry_get_text (GTK_ENTRY (self->priv->uri_field)));

	bookmark = nautilus_bookmark_new (location,
					  self->priv->name_text_changed ?
					  gtk_entry_get_text (GTK_ENTRY (self->priv->name_field)) : NULL,
					  NULL);
	g_object_unref (location);

	selected_row = get_selected_row (self);

	/* turn off list updating 'cuz otherwise the list-reordering code runs
	 * after repopulate(), thus reordering the correctly-ordered list.
	 */
	g_signal_handler_block (self->priv->bookmarks, self->priv->bookmarks_changed_id);
	nautilus_bookmark_list_delete_item_at (self->priv->bookmarks, selected_row);
	nautilus_bookmark_list_insert_item (self->priv->bookmarks, bookmark, selected_row);
	g_signal_handler_unblock (self->priv->bookmarks, self->priv->bookmarks_changed_id);
	g_object_unref (bookmark);

	/* We also have to update the bookmark pointer in the list
	   store. */
	gtk_tree_selection_get_selected (self->priv->selection, NULL, &iter);
	g_signal_handler_block (self->priv->model, self->priv->row_changed_id);

	bookmark_in_list = nautilus_bookmark_list_item_at (self->priv->bookmarks, selected_row);
	name = nautilus_bookmark_get_name (bookmark_in_list);
	icon = nautilus_bookmark_get_icon (bookmark_in_list);

	gtk_list_store_set (self->priv->model, &iter,
			    BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark_in_list,
			    BOOKMARK_LIST_COLUMN_NAME, name,
			    BOOKMARK_LIST_COLUMN_ICON, icon,
			    -1);

	g_signal_handler_unblock (self->priv->model, self->priv->row_changed_id);
	g_object_unref (icon);
}
static GFile *
nautilus_location_entry_get_location (NautilusLocationEntry *entry)
{
	char *user_location;
	GFile *location;

	user_location = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
	location = g_file_parse_name (user_location);
	g_free (user_location);

	return location;
}
Beispiel #10
0
/**
 * nemo_location_bar_get_location
 *
 * Get the GFile represented by the text in the location bar.
 **/
static GFile *
nemo_location_bar_get_location (NemoLocationBar *bar)
{
	char *user_location;
	GFile *location;

	user_location = gtk_editable_get_chars (GTK_EDITABLE (bar->details->entry), 0, -1);
	location = g_file_parse_name (user_location);
	g_free (user_location);

	return location;
}
/**
 * athena_location_bar_get_location
 *
 * Get the "URI" represented by the text in the location bar.
 *
 * @bar: A AthenaLocationBar.
 *
 * returns a newly allocated "string" containing the mangled
 * (by g_file_parse_name) text that the user typed in...maybe a URI 
 * but not guaranteed.
 *
 **/
static char *
athena_location_bar_get_location (AthenaLocationBar *bar) 
{
	char *user_location, *uri;
	GFile *location;
	
	user_location = gtk_editable_get_chars (GTK_EDITABLE (bar->details->entry), 0, -1);
	location = g_file_parse_name (user_location);
	g_free (user_location);
	uri = g_file_get_uri (location);
	g_object_unref (location);
	return uri;
}
Beispiel #12
0
static gboolean
on_tv_button_press (GtkWidget *widget,
		    GdkEventButton *event,
		    gpointer data)
{
	GtkTreePath *path;
	GtkTreeIter iter;
	GFile *file;

	gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
				       event->x, event->y,
				       &path, NULL, NULL, NULL);
	if (!path)
		return TRUE;		

	/* get the selected path */
	g_free (baobab.selected_path);
	gtk_tree_model_get_iter (GTK_TREE_MODEL (baobab.model), &iter,
				 path);
	gtk_tree_model_get (GTK_TREE_MODEL (baobab.model), &iter,
			    COL_H_PARSENAME, &baobab.selected_path, -1);

	file = g_file_parse_name (baobab.selected_path);

	if (baobab.CONTENTS_CHANGED_DELAYED) {
		GFile *home_file;

		home_file = g_file_new_for_path (g_get_home_dir ());
		if (g_file_has_prefix (file, home_file)) {
			baobab.CONTENTS_CHANGED_DELAYED = FALSE;
			if (baobab.STOP_SCANNING) {
				contents_changed ();
			}
		}
		g_object_unref (home_file);
	}

	/* right-click */
	if (event->button == 3) {

		if (g_file_query_exists (file, NULL)) {
		     popupmenu_list (path, event, can_trash_file (file));
		}
	}

	gtk_tree_path_free (path);
	g_object_unref (file);

	return FALSE;
}
Beispiel #13
0
static GFile *list_get_file(const unsigned int row)
{
	g_assert(row <= list.rows);

	GtkTreeIter iter;

	if (!gtk_tree_model_iter_nth_child(gui.treemodel, &iter, NULL, row))
		g_assert_not_reached();

	GValue value = G_VALUE_INIT;
	gtk_tree_model_get_value(gui.treemodel, &iter, COL_PNAME, &value);
	GFile *file = g_file_parse_name(g_value_get_string(&value));
	g_value_unset(&value);

	return file;
}
static GFile*
get_hotkey_home (void)
{
	GFile   *home;
	
	home = g_file_parse_name (HOTKEY_HOME);
	
	if (g_file_query_exists(home, NULL) &&
		!gtk_hotkey_g_file_is_directory(home)) {
		g_critical (HOTKEY_HOME" exists but is not a directory");
		g_object_unref (home);
		return NULL;
	}
	
	return home;
}
Beispiel #15
0
void
scan_folder_cb (GtkMenuItem *pmenu, gpointer dummy)
{
	GFile	*file;

	g_assert (!dummy);
	g_assert (baobab.selected_path);

	file = g_file_parse_name (baobab.selected_path);

	if (!g_file_query_exists (file, NULL)) {
		message (_("The folder does not exist."), "", GTK_MESSAGE_INFO, baobab.window);
	}

	baobab_scan_location (file);
	g_object_unref (file);
}
Beispiel #16
0
void
open_file_cb (GtkMenuItem *pmenu, gpointer dummy)
{
	GFile *file;

	g_assert (!dummy);
	g_assert (baobab.selected_path);

	file = g_file_parse_name (baobab.selected_path);

	if (!g_file_query_exists (file, NULL)) {
		message (_("The document does not exist."), "",
		GTK_MESSAGE_INFO, baobab.window);
		g_object_unref (file);
		return;
	}

	open_file_with_application (file);
	g_object_unref (file);
}
Beispiel #17
0
static void
gimp_file_entry_file_manager_clicked (GtkWidget     *widget,
                                      GimpFileEntry *entry)
{
  gchar  *utf8;
  GFile  *file;
  GError *error = NULL;

  utf8 = gtk_editable_get_chars (GTK_EDITABLE (entry->entry), 0, -1);
  file = g_file_parse_name (utf8);
  g_free (utf8);

  if (! gimp_file_show_in_file_manager (file, &error))
    {
      g_message (_("Can't show file in file manager: %s"),
                 error->message);
      g_clear_error (&error);
    }

  g_object_unref (file);
}
Beispiel #18
0
static int
korva_control_push (KorvaController1 *controller, const char *path, const char *uid, const char *title)
{
    GFile *source;
    GVariantBuilder *builder;
    char *out_tag;
    GError *error = NULL;

    if (g_str_has_prefix (path, "~")) {
        source = g_file_parse_name (path);
    } else {
        source = g_file_new_for_commandline_arg (path);
    }
    builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
    g_variant_builder_add (builder, "{sv}", "URI", g_variant_new_string (g_file_get_uri (source)));
    if (title != NULL) {
        g_variant_builder_add (builder, "{sv}", "Title", g_variant_new_string (title));
    }

    korva_controller1_call_push_sync (controller,
                                      g_variant_builder_end (builder),
                                      device,
                                      &out_tag,
                                      NULL,
                                      &error);
    if (error != NULL) {
        g_print ("Failed to Push %s to %s: %s\n",
                 file,
                 device,
                 error->message);

        g_error_free (error);

        return 1;
    } else {
        g_print ("Pushed %s to %s. The ID is %s\n", file, device, out_tag);

        return 0;
    }
}
Beispiel #19
0
void
logview_prefs_store_log (LogviewPrefs *prefs, GFile *file)
{
  gchar **stored_logs;
  GFile *stored;
  gboolean found = FALSE;
  gint idx, old_size;

  g_assert (LOGVIEW_IS_PREFS (prefs));
  g_assert (G_IS_FILE (file));

  stored_logs = logview_prefs_get_stored_logfiles (prefs);

  for (idx = 0; stored_logs[idx] != NULL; idx++) {
    stored = g_file_parse_name (stored_logs[idx]);
    if (g_file_equal (file, stored)) {
      found = TRUE;
    }

    g_object_unref (stored);

    if (found) {
      break;
    }
  }

  if (!found) {
    old_size = g_strv_length (stored_logs);
    stored_logs = g_realloc (stored_logs, (old_size + 2) * sizeof (gchar *));
    stored_logs[old_size] = g_file_get_parse_name (file);
    stored_logs[old_size + 1] = NULL;

    g_settings_set_strv (prefs->priv->logview_prefs,
                         PREF_LOGFILES,
                         (const gchar **) stored_logs);
  }

  g_strfreev (stored_logs);
}
Beispiel #20
0
char *list_get_uri(const unsigned int row)
{
	g_assert(row <= list_count_rows());

	GtkTreeIter iter;
	GValue value;
	value.g_type = 0;

	if (!gtk_tree_model_get_iter_first(gui.treemodel, &iter))
		return NULL;

	for (unsigned int i = 0; i < row; i++)
		gtk_tree_model_iter_next(gui.treemodel, &iter);

	gtk_tree_model_get_value(gui.treemodel, &iter, COL_FILE, &value);
	GFile *file = g_file_parse_name(g_value_get_string(&value));
	g_value_unset(&value);

	char *uri = g_file_get_uri(file);
	g_object_unref(file);

	return uri;
}
Beispiel #21
0
static void
update_bookmark_from_text (void)
{
    if (text_changed)
    {
        CajaBookmark *bookmark, *bookmark_in_list;
        char *name;
        GdkPixbuf *pixbuf;
        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 = caja_bookmark_new (location, gtk_entry_get_text (GTK_ENTRY (name_field)),
                                      name_text_changed, 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);
        caja_bookmark_list_delete_item_at (bookmarks, selected_row);
        caja_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 = caja_bookmark_list_item_at (bookmarks,
                           selected_row);

        name = caja_bookmark_get_name (bookmark_in_list);

        pixbuf = caja_bookmark_get_pixbuf (bookmark_in_list, GTK_ICON_SIZE_MENU);

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

        g_object_unref (pixbuf);
        g_free (name);
    }
}