Ejemplo n.º 1
0
static void
recent_manager_lookup_item (void)
{
  GtkRecentManager *manager;
  GtkRecentInfo *info;
  GError *error;

  manager = gtk_recent_manager_get_default ();

  error = NULL;
  info = gtk_recent_manager_lookup_item (manager,
                                         "file:///tmp/testrecentdoesnotexist.txt",
                                         &error);
  g_assert (info == NULL);
  g_assert (error != NULL);
  g_assert (error->domain == GTK_RECENT_MANAGER_ERROR);
  g_assert (error->code == GTK_RECENT_MANAGER_ERROR_NOT_FOUND);
  g_error_free (error);

  error = NULL;
  info = gtk_recent_manager_lookup_item (manager, uri2, &error);
  g_assert (info != NULL);
  g_assert (error == NULL);

  g_assert (gtk_recent_info_has_application (info, "testrecentchooser"));

  gtk_recent_info_unref (info);
}
Ejemplo n.º 2
0
/**
 * gnm_app_history_get_list:
 *
 * creating it if necessary.
 *
 * Return value: (element-type char) (transfer full): the list, which must be
 * freed along with the strings in it.
 **/
GSList *
gnm_app_history_get_list (int max_elements)
{
	GSList *res = NULL;
	GList *items, *l;
	GtkFileFilter *filter;
	int n_elements = 0;

	if (app->recent == NULL)
		return NULL;

	items = gtk_recent_manager_get_items (app->recent);
	items = g_list_sort (items, (GCompareFunc)compare_mru);

	filter = gnm_app_create_opener_filter (NULL);

	for (l = items; l && n_elements < max_elements; l = l->next) {
		GtkRecentInfo *ri = l->data;
		const char *uri = gtk_recent_info_get_uri (ri);
		gboolean want_it;

		if (gtk_recent_info_has_application (ri, g_get_application_name ())) {
			want_it = TRUE;
		} else {
			GtkFileFilterInfo fi;
			char *display_name = g_filename_display_basename (uri);

			memset (&fi, 0, sizeof (fi));
			fi.contains = (GTK_FILE_FILTER_MIME_TYPE |
				       GTK_FILE_FILTER_URI |
				       GTK_FILE_FILTER_DISPLAY_NAME);
			fi.uri = uri;
			fi.mime_type = gtk_recent_info_get_mime_type (ri);
			fi.display_name = display_name;
			want_it = gtk_file_filter_filter (filter, &fi);
			g_free (display_name);
		}

		if (want_it) {
			char *filename = go_filename_from_uri (uri);
			if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS))
				want_it = FALSE;
			g_free (filename);
		}

		if (want_it) {
			res = g_slist_prepend (res, g_strdup (uri));
			n_elements++;
		}
	}

	g_list_free_full (items, (GDestroyNotify)gtk_recent_info_unref);
	g_object_ref_sink (filter);
	g_object_unref (filter);

	return g_slist_reverse (res);
}
Ejemplo n.º 3
0
static GtkListStore *
get_list_store(const gchar *recent_group)
{
  GtkRecentManager *manager = gtk_recent_manager_get_default();
  
  GtkListStore *store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);

  GList *ptr;
  int count = 0;
  GtkTreeIter iter;
  GList *list = gtk_recent_manager_get_items(manager);
  for (ptr = list; (ptr != NULL) && (count < 10); ptr = ptr->next)
    {
      GtkRecentInfo *info = ptr->data;
      if (!gtk_recent_info_has_application(info, "KCemu"))
        continue;
      if ((recent_group != NULL) && !gtk_recent_info_has_group(info, recent_group))
        continue;

      GFile *file = g_file_new_for_uri(gtk_recent_info_get_uri(info));
      if (g_file_is_native(file) /* && g_file_query_exists(file, NULL) */)
        {
          gchar *path = g_file_get_path(file);
          gchar *basename = g_file_get_basename(file);

          if ((path != NULL) && (basename != NULL))
            {
              gtk_list_store_append(store, &iter);
              gtk_list_store_set(store, &iter, 0, basename, 1, path, -1);
              count++;
            }

          g_free(path);
          g_free(basename);
        }
      g_object_unref(file);
    }
  
  return store;
}
Ejemplo n.º 4
0
/* Callback for when of the items from the File->Open Recent submenu
 is selected */
void
action_open_recent(GtkAction *action, I7App *app)
{
	GtkRecentInfo *item = gtk_recent_chooser_get_current_item(GTK_RECENT_CHOOSER(action));
	g_assert(gtk_recent_info_has_application(item, "Inform 7"));

	GFile *file = g_file_new_for_uri(gtk_recent_info_get_uri(item));

	if(gtk_recent_info_has_group(item, "inform7_project")) {
		i7_story_new_from_file(app, file);
	} else if(gtk_recent_info_has_group(item, "inform7_extension")) {
		i7_extension_new_from_file(app, file, FALSE);
	} else if(gtk_recent_info_has_group(item, "inform7_builtin")) {
		i7_extension_new_from_file(app, file, TRUE);
	} else {
		g_warning("Recent manager file does not have an Inform tag. This means "
			"it was not saved by Inform. I'll try to open it anyway.");
		i7_story_new_from_file(app, file);
	}

	g_object_unref(file);
	gtk_recent_info_unref(item);
}
Ejemplo n.º 5
0
static void
populate_recent_model (GtkBuilder *gui)
{
	GtkListStore *list = GTK_LIST_STORE (gtk_builder_get_object (gui, "recent_model"));
	gboolean existing_only = gtk_toggle_button_get_active
		(GTK_TOGGLE_BUTTON (gtk_builder_get_object (gui, "existing_only_button")));
	gboolean gnumeric_only = gtk_toggle_button_get_active
		(GTK_TOGGLE_BUTTON (gtk_builder_get_object (gui, "gnumeric_only_button")));
	GtkRecentManager *manager = gtk_recent_manager_get_default ();
	GList *docs, *l;

	gtk_list_store_clear (list);

	docs = gtk_recent_manager_get_items (manager);
	docs = g_list_sort (docs, by_age_uri);
	for (l = docs; l; l = l->next) {
		GtkRecentInfo *ri = l->data;
		GtkTreeIter iter;

		if (existing_only) {
			gboolean exists = gtk_recent_info_is_local (ri)
				? gtk_recent_info_exists (ri)
				: TRUE;  /* Just assume so */
			if (!exists)
				continue;
		}

		if (gnumeric_only) {
			if (!gtk_recent_info_has_application (ri, g_get_application_name ()))
				continue;
		}

		gtk_list_store_append (list, &iter);
		gtk_list_store_set (list, &iter, RECENT_COL_INFO, ri, -1);
	}
	g_list_free_full (docs, (GDestroyNotify)gtk_recent_info_unref);
}
Ejemplo n.º 6
0
static VALUE
rg_has_application_p(VALUE self, VALUE app_name)
{
    return CBOOL2RVAL(gtk_recent_info_has_application(_SELF(self), 
                                                RVAL2CSTR(app_name)));
}
Ejemplo n.º 7
0
void
documents_clear_cmd_callback (GtkAction *action,
                              gpointer   data)
{
  GimpContainerEditor *editor  = GIMP_CONTAINER_EDITOR (data);
  GimpContext         *context = gimp_container_view_get_context (editor->view);
  Gimp                *gimp    = context->gimp;
  GtkWidget           *dialog;

  dialog = gimp_message_dialog_new (_("Clear Document History"),
                                    GIMP_STOCK_SHRED,
                                    GTK_WIDGET (editor),
                                    GTK_DIALOG_MODAL |
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    gimp_standard_help_func, NULL,

                                    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                    GTK_STOCK_CLEAR,  GTK_RESPONSE_OK,

                                    NULL);

  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);

  g_signal_connect_object (gtk_widget_get_toplevel (GTK_WIDGET (editor)),
                           "unmap",
                           G_CALLBACK (gtk_widget_destroy),
                           dialog, G_CONNECT_SWAPPED);

  gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
                                     _("Clear the Recent Documents list?"));

  gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
                             _("Clearing the document history will "
                               "permanently remove all images from "
                               "the recent documents list."));

  if (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK)
    {
      GtkRecentManager *manager = gtk_recent_manager_get_default ();
      GList            *items;
      GList            *list;

      items = gtk_recent_manager_get_items (manager);

      for (list = items; list; list = list->next)
        {
          GtkRecentInfo *info = list->data;

          if (gtk_recent_info_has_application (info,
                                               "GNU Image Manipulation Program"))
            {
              gtk_recent_manager_remove_item (manager,
                                              gtk_recent_info_get_uri (info),
                                              NULL);
            }

          gtk_recent_info_unref (info);
        }

      g_list_free (items);

      gimp_container_clear (gimp->documents);
    }

  gtk_widget_destroy (dialog);
}