Exemple #1
0
static void
ide_git_vcs__monitor_changed_cb (IdeGitVcs         *self,
                                 GFile             *file,
                                 GFile             *other_file,
                                 GFileMonitorEvent  event_type,
                                 gpointer           user_data)
{
  g_autofree gchar *name = NULL;
  g_autofree gchar *other_name = NULL;

  IDE_ENTRY;

  g_assert (IDE_IS_GIT_VCS (self));
  g_assert (G_IS_FILE (file));
  g_assert (!other_file || G_IS_FILE (other_file));

  name = g_file_get_basename (file);

  if (other_file != NULL)
    other_name = g_file_get_basename (other_file);

  if (dzl_str_equal0 (name, "index") ||
      dzl_str_equal0 (other_name, "index"))
    {
      dzl_clear_source (&self->changed_timeout);
      self->changed_timeout = g_timeout_add_seconds (DEFAULT_CHANGED_TIMEOUT_SECS,
                                                     ide_git_vcs__changed_timeout_cb,
                                                     self);
    }

  IDE_EXIT;
}
Exemple #2
0
static void
_really_delete (CheeseWindow *cheese_window, GList *files, gboolean batch)
{
  GList     *l           = NULL;
  GError    *error       = NULL;
  gint       list_length = g_list_length (files);
  GtkWidget *question_dialog;
  gint       response;
  gchar     *primary, *secondary;

  if (batch == FALSE)
  {
    if (list_length > 1)
    {
      primary = g_strdup_printf (ngettext ("Are you sure you want to permanently delete the %'d selected item?",
                                           "Are you sure you want to permanently delete the %'d selected items?",
                                           list_length),
                                 list_length);
    }
    else
    {
      primary = g_strdup_printf (_("Are you sure you want to permanently delete \"%s\"?"),
                                 g_file_get_basename (files->data));
    }
    secondary       = g_strdup_printf (_("If you delete an item, it will be permanently lost."));
    question_dialog = gtk_message_dialog_new (GTK_WINDOW (cheese_window),
                                              GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                              GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", primary);
    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (question_dialog), "%s", secondary);
    gtk_dialog_add_button (GTK_DIALOG (question_dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
    gtk_dialog_add_button (GTK_DIALOG (question_dialog), GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT);
    response = gtk_dialog_run (GTK_DIALOG (question_dialog));
    gtk_widget_destroy (question_dialog);
    g_free (primary);
    g_free (secondary);
    if (response != GTK_RESPONSE_ACCEPT)
      return;
  }

  for (l = files; l != NULL; l = l->next)
  {
    g_print ("deleting %s\n", g_file_get_basename (l->data));
    if (!g_file_delete (l->data, NULL, &error))
    {
      _delete_error_dialog (cheese_window, l->data,
                            error != NULL ? error->message : _("Unknown Error"));
      g_error_free (error);
      error = NULL;
    }
    g_object_unref (l->data);
  }
}
/**
 * cong_error_test_file_ops:
 * @parent_window:
 * @filename:
 * @vfs_result:
 *
 * TODO: Write me
 */
void 
cong_error_test_file_ops(GtkWindow *parent_window, 
			 GFile *file,
			 GError *error)
{
	GtkDialog* dialog;
	char *filename;

	gsize file_size = 5*1024*1024; /* 5 megabytes, for a test */

	filename = g_file_get_basename(file);

	g_message(_("Testing File->Open failure of \"%s\" with result %s"), filename, error->message);

	dialog = cong_error_dialog_new_from_file_open_failure_with_gerror(parent_window, file, error);
	cong_error_dialog_run(GTK_DIALOG(dialog));		
	gtk_widget_destroy(GTK_WIDGET(dialog));    

	g_message(_("Testing File->Save failure of \"%s\" with result %s"), filename, error->message);

	dialog = cong_error_dialog_new_from_file_save_failure(parent_window, file, error, &file_size);
	cong_error_dialog_run(GTK_DIALOG(dialog));		
	gtk_widget_destroy(GTK_WIDGET(dialog));    

	g_message(_("Testing generic failure of \"%s\" with result %s"), filename, error->message);

	dialog = cong_error_dialog_new_from_file_operation_failure(parent_window,
								   _("Conglomerate is simulating the failure of a generic file operation."),
								   file,
								   error,
								   _("This dialog was generated by the automated testing routine"));
	cong_error_dialog_run(GTK_DIALOG(dialog));		
	gtk_widget_destroy(GTK_WIDGET(dialog));
	g_free(filename);
}
/**
 * gs_plugin_app_remove:
 */
gboolean
gs_plugin_app_remove (GsPlugin *plugin, GsApp *app,
		      GCancellable *cancellable, GError **error)
{
	const gchar *epi_desktop;
	g_autofree gchar *basename = NULL;
	g_autofree gchar *app_desktop = NULL;
	g_autoptr(GFile) file_epi = NULL;
	g_autoptr(GFile) file_app = NULL;

	/* only process this app if was created by this plugin */
	if (g_strcmp0 (gs_app_get_management_plugin (app), "Epiphany") != 0)
		return TRUE;
	epi_desktop = gs_app_get_source_id_default (app);
	if (epi_desktop == NULL)
		return TRUE;

	/* remove the epi 'config' file */
	gs_app_set_state (app, AS_APP_STATE_REMOVING);
	file_epi = g_file_new_for_path (epi_desktop);
	if (!g_file_delete (file_epi, NULL, error))
		return FALSE;

	/* remove the shared desktop file */
	basename = g_file_get_basename (file_epi);
	app_desktop = g_build_filename (g_get_user_data_dir (),
	                                "applications",
	                                gs_app_get_id (app),
	                                NULL);
	file_app = g_file_new_for_path (app_desktop);
	if (!g_file_delete (file_app, NULL, error))
		return FALSE;
	gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
	return TRUE;
}
Exemple #5
0
static int
compare_files_by_basename (gconstpointer  ap,
                           gconstpointer  bp)
{
  GFile *a = *(GFile**)ap;
  GFile *b = *(GFile**)ap;
  char *name_a, *name_b;
  int c;

  name_a = g_file_get_basename (a);
  name_b = g_file_get_basename (b);
  c = strcmp (name_a, name_b);
  g_free (name_b);
  g_free (name_a);
  return c;
}
static void
gtk_filebutton_set_filename(GtkFilebutton *filebutton, const gchar *filename)
{
  if (g_strcmp0(filebutton->filename, filename) == 0)
    return;

  g_free(filebutton->filename);
  filebutton->filename = g_strdup(filename);

  const gchar *basename;
  if (filename == NULL)
    {
      filename = "";
      basename = "";
    }
  else
    {
      GFile *file = g_file_new_for_path(filename);
      basename = g_file_get_basename(file);
      g_object_unref(file);

      add_recent_info(filename, filebutton->recent_group);
      gtk_filebutton_set_recent_group(filebutton, filebutton->recent_group);
    }

  gtk_filebutton_set_entry_text(filebutton, basename);
  gtk_widget_set_tooltip_text(GTK_WIDGET(filebutton), filename);
  gtk_widget_set_sensitive(GTK_WIDGET(filebutton->button_clear), filebutton->filename != NULL);

  g_signal_emit(G_OBJECT(filebutton), filebutton_signals[FILEBUTTON_CHANGED_SIGNAL], 0);
}
static char *
xplayer_uri_get_subtitle_in_subdir (GFile *file, const char *subdir)
{
	char *filename, *subtitle, *full_path_str;
	GFile *parent, *full_path, *directory;

	/* Get the sibling directory @subdir of the file @file */
	parent = g_file_get_parent (file);
	directory = g_file_get_child (parent, subdir);
	g_object_unref (parent);

	/* Get the file of the same name as @file in the @subdir directory */
	filename = g_file_get_basename (file);
	full_path = g_file_get_child (directory, filename);
	g_object_unref (directory);
	g_free (filename);

	/* Get the subtitles from that URI */
	full_path_str = g_file_get_uri (full_path);
	g_object_unref (full_path);
	subtitle = xplayer_uri_get_subtitle_for_uri (full_path_str);
	g_free (full_path_str);

	return subtitle;
}
gboolean vfs_backend_move_file (const gchar *cURI, const gchar *cDirectoryURI)
{
	g_return_val_if_fail (cURI != NULL, FALSE);
	cd_message (" %s -> %s", cURI, cDirectoryURI);
	GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
	
	gchar *cFileName = g_file_get_basename (pFile);
	gchar *cNewFileURI = g_strconcat (cDirectoryURI, "/", cFileName, NULL);  // un peu moyen mais bon...
	GFile *pDestinationFile = (*cNewFileURI == '/' ? g_file_new_for_path (cNewFileURI) : g_file_new_for_uri (cNewFileURI));
	g_free (cNewFileURI);
	g_free (cFileName);
	
	GError *erreur = NULL;
	gboolean bSuccess = g_file_move (pFile,
		pDestinationFile,
		G_FILE_COPY_NOFOLLOW_SYMLINKS,
		NULL,
		NULL,  // GFileProgressCallback
		NULL,  // data
		&erreur);
	if (erreur != NULL)
	{
		cd_warning ("Attention : %s", erreur->message);
		g_error_free (erreur);
	}
	g_object_unref (pFile);
	g_object_unref (pDestinationFile);
	return bSuccess;
}
Exemple #9
0
/**
 * gedit_document_set_content_type:
 * @doc:
 * @content_type: (allow-none):
 */
void
gedit_document_set_content_type (GeditDocument *doc,
                                 const gchar   *content_type)
{
	g_return_if_fail (GEDIT_IS_DOCUMENT (doc));

	gedit_debug (DEBUG_DOCUMENT);

	if (content_type == NULL)
	{
		GFile *location;
		gchar *guessed_type = NULL;

		/* If content type is null, we guess from the filename */
		location = gtk_source_file_get_location (doc->priv->file);
		if (location != NULL)
		{
			gchar *basename;

			basename = g_file_get_basename (location);
			guessed_type = g_content_type_guess (basename, NULL, 0, NULL);

			g_free (basename);
		}

		set_content_type_no_guess (doc, guessed_type);
		g_free (guessed_type);
	}
	else
	{
		set_content_type_no_guess (doc, content_type);
	}
}
static IdeProjectFile *
create_file (IdeContext *context,
             GFile      *file,
             GFileType   file_type)
{
  g_autofree gchar *path = NULL;
  g_autofree gchar *name = NULL;
  g_autoptr(GFileInfo) file_info = NULL;
  IdeVcs *vcs;
  GFile *workdir;

  g_assert (IDE_IS_CONTEXT (context));
  g_assert (G_IS_FILE (file));
  g_assert ((file_type == G_FILE_TYPE_DIRECTORY) || (file_type == G_FILE_TYPE_REGULAR));

  vcs = ide_context_get_vcs (context);
  workdir = ide_vcs_get_working_directory (vcs);
  path = g_file_get_relative_path (workdir, file);
  name = g_file_get_basename (file);

  file_info = g_file_info_new ();
  g_file_info_set_file_type (file_info, file_type);
  g_file_info_set_name (file_info, name);
  g_file_info_set_display_name (file_info, name);

  return g_object_new (IDE_TYPE_PROJECT_FILE,
                       "context", context,
                       "file", file,
                       "file-info", file_info,
                       "path", path,
                       "parent", NULL,
                       NULL);
}
static char *
shell_util_get_file_display_name (GFile *file, gboolean use_fallback)
{
  GFileInfo *info;
  char *ret;

  ret = NULL;

  info = g_file_query_info (file, "standard::display-name",
      G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL);

  if (info)
    {
      ret = g_strdup (g_file_info_get_display_name (info));
      g_object_unref (info);
    }

  if (!ret && use_fallback)
    {
      /* can happen with URI schemes non supported by gvfs */
      char *basename;

      basename = g_file_get_basename (file);
      ret = g_filename_display_name (basename);
      g_free (basename);
    }

  return ret;
}
Exemple #12
0
static GtkSourceLanguage *
ide_file_create_language (IdeFile *self)
{
  GtkSourceLanguageManager *manager;
  GtkSourceLanguage *srclang;
  g_autofree gchar *content_type = NULL;
  const gchar *filename;
  gboolean uncertain = FALSE;

  g_assert (IDE_IS_FILE (self));

  filename = g_file_get_basename (self->file);

  if (self->content_type)
    content_type = g_strdup (self->content_type);
  else
    content_type = g_content_type_guess (filename, NULL, 0, &uncertain);

  if (uncertain)
    g_clear_pointer (&content_type, g_free);
  else if (self->content_type == NULL)
    self->content_type = g_strdup (content_type);

  manager = gtk_source_language_manager_get_default ();
  srclang = gtk_source_language_manager_guess_language (manager, filename, content_type);

  return srclang;
}
char *
nautilus_compute_title_for_location (GFile *location)
{
    NautilusFile *file;
    char *title;

    /* TODO-gio: This doesn't really work all that great if the
       info about the file isn't known atm... */

    if (nautilus_is_home_directory (location)) {
        return g_strdup (_("Home"));
    }

    title = NULL;
    if (location) {
        file = nautilus_file_get (location);
        title = nautilus_file_get_description (file);
        if (title == NULL) {
            title = nautilus_file_get_display_name (file);
        }
        nautilus_file_unref (file);
    }

    if (title == NULL) {
        title = g_file_get_basename (location);
    }

    return title;
}
static char *
get_display_name (GFile *file)
{
  GFileInfo *info;
  char *name, *tmp;

  /* This does sync I/O, which isn't ideal.
   * It should probably use the NautilusFile machinery
   */

  name = NULL;
  info = g_file_query_info (file,
			    G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
  if (info)
    {
      name = g_strdup (g_file_info_get_display_name (info));
      g_object_unref (info);
    }

  if (name == NULL)
    {
      name = g_file_get_basename (file);
      if (!g_utf8_validate (name, -1, NULL))
	{
	  tmp = name;
	  name =
	    g_uri_escape_string (name, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH,
				 TRUE);
	  g_free (tmp);
	}
    }

  return name;
}
Exemple #15
0
const gchar *
rstto_file_get_collate_key ( RsttoFile *r_file )
{
    if ( NULL == r_file->priv->collate_key )
    {
        gchar *basename = g_file_get_basename (rstto_file_get_file (r_file));
        if ( NULL != basename )
        {
            if ( g_utf8_validate (basename, -1, NULL) )
            {
                /* If we can use casefold for case insenstivie sorting, then
                 * do so */
                gchar *casefold = g_utf8_casefold (basename, -1);
                if ( NULL != casefold )
                {
                    r_file->priv->collate_key = g_utf8_collate_key_for_filename (casefold, -1);
                    g_free (casefold);
                }
                else
                {
                    r_file->priv->collate_key = g_utf8_collate_key_for_filename (basename, -1);
                }
            }
            else
            {
                r_file->priv->collate_key = g_strdup (basename);
            }
            g_free (basename);
        }
    }
    return (const gchar *)r_file->priv->collate_key;
}
Exemple #16
0
static EMsgComposer *
composer_registry_lookup (GQueue *registry,
                          const gchar *basename)
{
	GList *iter;

	/* Find the composer with the given snapshot filename. */
	for (iter = registry->head; iter != NULL; iter = iter->next) {
		EMsgComposer *composer;
		GFile *snapshot_file;
		gchar *snapshot_name;

		composer = E_MSG_COMPOSER (iter->data);
		snapshot_file = e_composer_get_snapshot_file (composer);

		if (!G_IS_FILE (snapshot_file))
			continue;

		snapshot_name = g_file_get_basename (snapshot_file);
		if (g_strcmp0 (basename, snapshot_name) == 0) {
			g_free (snapshot_name);
			return composer;
		}

		g_free (snapshot_name);
	}

	return NULL;
}
Exemple #17
0
static gboolean
builder_source_file_update (BuilderSource *source,
                            BuilderContext *context,
                            GError **error)
{
  BuilderSourceFile *self = BUILDER_SOURCE_FILE (source);
  g_autoptr(GFile) src = NULL;
  gboolean is_local, is_inline;

  src = get_source_file (self, context, &is_local, &is_inline, error);
  if (src == NULL)
    return FALSE;

  if (is_local)
    {
      g_autofree char *data = NULL;
      g_autofree char *base64 = NULL;
      gsize len;

      if (!g_file_load_contents (src, NULL, &data, &len, NULL, error))
        return FALSE;

      base64 = g_base64_encode ((const guchar *)data, len);
      g_free (self->url);
      self->url = g_strdup_printf ("data:text/plain;charset=utf8;base64,%s", base64);
      if (self->dest_filename == NULL || *self->dest_filename == 0)
        {
          g_free (self->dest_filename);
          self->dest_filename = g_file_get_basename (src);
        }
    }

  return TRUE;
}
Exemple #18
0
/* Cut a filename is part representing one directory or file name. By example
 * /home/user/project/foo will be generate a list containing:
 * foo, project, user, home */
static GList*
dir_cut_filename (GFile *file)
{
	GList *name_list = NULL;

	g_object_ref (file);
	do
	{
		DirMatchString *str;
		gchar *name = g_file_get_basename (file);

		if (strcmp(name, G_DIR_SEPARATOR_S) == 0)
		{
			g_free (name);
			g_object_unref (file);
			break;
		}
		
		str = dir_match_string_new (name);
		str->file = file;

		name_list = g_list_prepend (name_list, str);

		file = g_file_get_parent (file);
	}
	while (file != NULL);
	
	name_list = g_list_reverse (name_list);
	
	return name_list;
}
Exemple #19
0
void
gb_editor_tab_set_file (GbEditorTab *tab,
                        GFile       *file)
{
   GbEditorTabPrivate *priv;
   gchar *title;

   g_return_if_fail (GB_IS_EDITOR_TAB (tab));

   priv = tab->priv;

   if (file) {
      title = g_file_get_basename (file);
      priv->is_empty = FALSE;
   } else {
      title = _("Unsaved Document");
   }

   g_clear_object (&priv->file);
   priv->file = file ? g_object_ref (file) : NULL;

   gb_tab_set_title (GB_TAB (tab), title);
   gb_editor_tab_guess_language (tab);

   g_object_notify_by_pspec (G_OBJECT (tab), gParamSpecs[PROP_FILE]);
}
static void
gb_rename_file_popover_set_file (GbRenameFilePopover *self,
                                 GFile               *file)
{
  g_return_if_fail (GB_IS_RENAME_FILE_POPOVER (self));
  g_return_if_fail (G_IS_FILE (file));

  if (g_set_object (&self->file, file))
    {
      if (file != NULL)
        {
          gchar *name;
          gchar *label;

          name = g_file_get_basename (file);
          label = g_strdup_printf (_("Rename %s"), name);

          gtk_label_set_label (self->label, label);

          g_free (name);
          g_free (label);
        }

      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_FILE]);
    }
}
static void
add_file_chooser_response (GtkDialog *widget,
                           GtkResponseType response,
                           gpointer user_data)
{
  Place *place;
  GPtrArray *new_values;

  if (response != GTK_RESPONSE_OK)
    {
      gtk_widget_destroy (GTK_WIDGET (widget));
      return;
    }

  place = g_slice_new0 (Place);
  place->location = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (widget));
  place->settings_key = TRACKER_KEY_RECURSIVE_DIRECTORIES;
  place->display_name = g_file_get_basename (place->location);

  new_values = place_get_new_settings_values (place, FALSE);
  g_settings_set_strv (tracker_preferences, place->settings_key, (const gchar **) new_values->pdata);

  g_ptr_array_unref (new_values);
  gtk_widget_destroy (GTK_WIDGET (widget));
  place_free (place);
}
Exemple #22
0
static GdkPixbufLoader *
create_loader (GFile        *file,
               const guchar *data,
               gsize         size)
{
  GdkPixbufLoader *loader;
  GError *error = NULL;
  char *mime_type;
  char *filename;

  loader = NULL;

  /* need to specify the type here because the gdk_pixbuf_loader_write
     doesn't have access to the filename in order to correct detect
     the image type. */
  filename = g_file_get_basename (file);
  mime_type = g_content_type_guess (filename, data, size, NULL);
  g_free (filename);

  if (mime_type != NULL) {
    loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, &error);
  }

  if (loader == NULL) {
    g_debug ("Unable to create loader for mime type %s: %s", mime_type,
             (error != NULL) ? error->message : "(null)");
    g_clear_error (&error);
    loader = gdk_pixbuf_loader_new ();
  }
  g_free (mime_type);

  return loader;
}
static GList *
get_tracker_locations (void)
{
  gchar **locations;
  GList *list;
  gint idx;
  Place *location;
  const gchar *path;

  locations = g_settings_get_strv (tracker_preferences, TRACKER_KEY_RECURSIVE_DIRECTORIES);
  list = NULL;

  for (idx = 0; locations[idx] != NULL; idx++)
    {
      path = path_from_tracker_dir (locations[idx]);

      location = g_slice_new0 (Place);
      location->location = g_file_new_for_commandline_arg (path);
      location->display_name = g_file_get_basename (location->location);
      location->place_type = PLACE_OTHER;

      list = g_list_prepend (list, location);
    }

  g_strfreev (locations);

  return g_list_reverse (list);
}
static GList *
get_xdg_dirs (void)
{
  GList *xdg_dirs = NULL;
  gint idx;
  const gchar *path;
  Place *xdg_dir;

  for (idx = 0; idx < G_USER_N_DIRECTORIES; idx++)
    {
      path = get_user_special_dir_if_not_home (idx);
      if (path == NULL)
        continue;

      if (idx == G_USER_DIRECTORY_TEMPLATES ||
          idx == G_USER_DIRECTORY_PUBLIC_SHARE ||
          idx == G_USER_DIRECTORY_DESKTOP)
        continue;

      xdg_dir = g_slice_new0 (Place);
      xdg_dir->location = g_file_new_for_path (path);
      xdg_dir->display_name = g_file_get_basename (xdg_dir->location);
      xdg_dir->place_type = PLACE_XDG;

      xdg_dirs = g_list_prepend (xdg_dirs, xdg_dir);
    }

  return g_list_reverse (xdg_dirs);
}
static void
desktop_set_metadata_string (GFile *file,
                             const char *key,
                             const char *string)
{
    MateConfClient *client;
    char *mateconf_key;
    GFile *parent;
    char *name;

    parent = g_file_get_parent (file);
    if (parent == NULL)
    {
        name = g_strdup ("directory");
    }
    else
    {
        g_object_unref (parent);
        name = g_file_get_basename (file);
    }

    client = mateconf_client_get_default ();
    mateconf_key = get_metadata_mateconf_path (name, key);

    mateconf_client_set_string (client, mateconf_key, string, NULL);

    g_free (mateconf_key);
    g_free (name);
    g_object_unref (client);
}
Exemple #26
0
static void
set_content_type (GeditDocument *doc,
		  const gchar   *content_type)
{
	GeditDocumentPrivate *priv;

	gedit_debug (DEBUG_DOCUMENT);

	priv = gedit_document_get_instance_private (doc);

	if (content_type == NULL)
	{
		GFile *location;
		gchar *guessed_type = NULL;

		/* If content type is null, we guess from the filename */
		location = gtk_source_file_get_location (priv->file);
		if (location != NULL)
		{
			gchar *basename;

			basename = g_file_get_basename (location);
			guessed_type = g_content_type_guess (basename, NULL, 0, NULL);

			g_free (basename);
		}

		set_content_type_no_guess (doc, guessed_type);
		g_free (guessed_type);
	}
	else
	{
		set_content_type_no_guess (doc, content_type);
	}
}
/* Finish up the user's Release command by choosing a location to store the
project. This is a callback and the GDK lock is held when entering this
 function. */
void
i7_story_save_compiler_output(I7Story *story, const gchar *dialog_title)
{
    I7_STORY_USE_PRIVATE(story, priv);

    GFile *file = NULL;
    if(priv->copy_blorb_dest_file == NULL) {
        /* ask the user for a release file name if cBlorb didn't provide one */

        /* Create a file chooser */
        GtkFileFilter *filter = gtk_file_filter_new();
        if(i7_story_get_story_format(story) == I7_STORY_FORMAT_GLULX) {
            gtk_file_filter_set_name(filter, _("Glulx games (.ulx,.gblorb)"));
            gtk_file_filter_add_pattern(filter, "*.ulx");
            gtk_file_filter_add_pattern(filter, "*.gblorb");
        } else {
            gtk_file_filter_set_name(filter, _("Z-code games (.z?,.zblorb)"));
            gtk_file_filter_add_pattern(filter, "*.z?");
            gtk_file_filter_add_pattern(filter, "*.zblorb");
        }
        GtkWidget *dialog = gtk_file_chooser_dialog_new(dialog_title,
                            GTK_WINDOW(story), GTK_FILE_CHOOSER_ACTION_SAVE,
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                            NULL);
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
        char *curfilename = g_file_get_basename(priv->compiler_output_file);
        gchar *title = i7_document_get_display_name(I7_DOCUMENT(story));
        char *extension = strrchr(curfilename, '.'); /* not allocated */
        char *suggestname;
        if(title != NULL) {
            *(strrchr(title, '.')) = '\0';
            suggestname = g_strconcat(title, extension, NULL);
            g_free(title);
        } else {
            suggestname = g_strconcat("Untitled", extension, NULL);
        }
        g_free(curfilename);
        gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), suggestname);
        g_free(suggestname);
        gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);

        if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
            file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog));

        gtk_widget_destroy(dialog);
    } else {
        file = g_object_ref(priv->copy_blorb_dest_file);
    }

    if(file) {
        /* Move the finished file to the release location */
        GError *err = NULL;
        if(!g_file_move(priv->compiler_output_file, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &err)) {
            IO_ERROR_DIALOG(GTK_WINDOW(story), file, err, _("copying compiler output"));
        }
        g_object_unref(file);
    }
}
Exemple #28
0
static struct view *
view_create(struct display *display,
	    uint32_t key, const char *filename, int fullscreen, int *view_counter)
{
	struct view *view;
	gchar *basename;
	gchar *title;
	GFile *file = NULL;
	GError *error = NULL;

	view = malloc(sizeof *view);
	if (view == NULL)
		return view;
	memset(view, 0, sizeof *view);

	file = g_file_new_for_commandline_arg(filename);
	basename = g_file_get_basename(file);
	if(!basename) {
		title = g_strdup("Wayland View");
	} else {
	        title = g_strdup_printf("Wayland View - %s", basename);
	        g_free(basename);
	}

        view->document = poppler_document_new_from_file(g_file_get_uri(file),
                                                        NULL, &error);

        if(error) {
		title = g_strdup("File not found");
        }

	view->window = window_create(display);
	view->widget = frame_create(view->window, view);
	window_set_title(view->window, title);
	g_free(title);
	view->display = display;

	window_set_user_data(view->window, view);
	window_set_key_handler(view->window, key_handler);
	window_set_keyboard_focus_handler(view->window,
					  keyboard_focus_handler);
	window_set_fullscreen_handler(view->window, fullscreen_handler);
	window_set_close_handler(view->window, close_handler);

	widget_set_button_handler(view->widget, button_handler);
	widget_set_resize_handler(view->widget, resize_handler);
	widget_set_redraw_handler(view->widget, redraw_handler);

	view->page = 0;

	view->fullscreen = fullscreen;
	window_set_fullscreen(view->window, view->fullscreen);

	window_schedule_resize(view->window, 500, 400);
	view->view_counter = view_counter;
	*view_counter += 1;

	return view;
}
Exemple #29
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;
}
Exemple #30
0
static void on_folder_changed(GFileMonitor* mon, GFile* gf, GFile* other, GFileMonitorEvent evt, FmFolder* folder)
{
    GList* l;
    char* name;
/*
    const char* names[]={
        "G_FILE_MONITOR_EVENT_CHANGED",
        "G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT",
        "G_FILE_MONITOR_EVENT_DELETED",
        "G_FILE_MONITOR_EVENT_CREATED",
        "G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED",
        "G_FILE_MONITOR_EVENT_PRE_UNMOUNT",
        "G_FILE_MONITOR_EVENT_UNMOUNTED"
    };
    name = g_file_get_basename(gf);
    g_debug("folder: %p, file %s event: %s", folder, name, names[evt]);
    g_free(name);
*/

    if(g_file_equal(gf, folder->gf))
    {
        g_debug("event of the folder itself: %d", evt);
        /* FIXME: handle unmount events */
        if(evt == G_FILE_MONITOR_EVENT_PRE_UNMOUNT)
        {
            g_debug("folder is going to be unmounted");
        }
        else if(evt == G_FILE_MONITOR_EVENT_UNMOUNTED)
        {
            g_signal_emit(folder, signals[UNMOUNT], 0);
            g_debug("folder is unmounted");
        }
        return;
    }

    name = g_file_get_basename(gf);
    switch(evt)
    {
    case G_FILE_MONITOR_EVENT_CREATED:
        folder->files_to_add = g_slist_append(folder->files_to_add, name);
        break;
    case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
    case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
        folder->files_to_update = g_slist_append(folder->files_to_update, name);
        break;
    case G_FILE_MONITOR_EVENT_DELETED:
        l = _fm_folder_get_file_by_name(folder, name);
        if(l && !g_slist_find(folder->files_to_del, l) )
            folder->files_to_del = g_slist_prepend(folder->files_to_del, l);
        g_free(name);
        break;
    default:
        /* g_debug("folder %p %s event: %s", folder, name, names[evt]); */
        g_free(name);
        return;
    }
    if(!folder->idle_handler)
        folder->idle_handler = g_idle_add_full(G_PRIORITY_LOW, on_idle, folder, NULL);
}