/**
 * shell_doc_system_queue_existence_check:
 * @system: A #ShellDocSystem
 * @n_items: Count of items to check for existence, starting from most recent
 *
 * Asynchronously start a check of a number of recent file for existence;
 * any deleted files will be emitted from the #ShellDocSystem::deleted
 * signal.  Note that this function ignores non-local files; they
 * will simply always appear to exist (until they are removed from
 * the recent file list manually).
 *
 * The intent of this function is to be called after a #ShellDocSystem::changed
 * signal has been emitted, and a display has shown a subset of those files.
 */
void
shell_doc_system_queue_existence_check (ShellDocSystem   *self,
                                        guint             n_items)
{
  GSList *iter;
  guint i;

  for (i = 0, iter = self->priv->infos_by_timestamp; i < n_items && iter; i++, iter = iter->next)
    {
      GtkRecentInfo *info = iter->data;
      const char *uri;
      GFile *file;
      ShellDocSystemRecentQueryData *data;

      if (!gtk_recent_info_is_local (info))
        continue;

      data = g_new0 (ShellDocSystemRecentQueryData, 1);
      data->self = self;
      data->info = gtk_recent_info_ref (info);

      uri = gtk_recent_info_get_uri (info);
      file = g_file_new_for_uri (uri);

      g_file_query_info_async (file, "standard::type", G_FILE_QUERY_INFO_NONE,
                               G_PRIORITY_DEFAULT, NULL, on_recent_file_query_result, data);
      g_object_unref (file);
    }
}
Пример #2
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);
}
Пример #3
0
static VALUE
rg_local_p(VALUE self)
{
    return CBOOL2RVAL(gtk_recent_info_is_local(_SELF(self)));
}
Пример #4
0
static void
reload_recent_items (GVfsBackendRecent *backend)
{
  GVfsMonitor *monitor;
  GList *items;
  GList *node;
  GList *added = NULL;
  GList *changed = NULL;
  GList *not_seen_items = NULL;
  GList *l;

  not_seen_items = g_hash_table_get_values (backend->items);
  items = gtk_recent_manager_get_items (backend->recent_manager);
  for (node = items; node; node = node->next)
    {
      GtkRecentInfo *recent_info = node->data;
      const char *uri;
      const char *guid;

      if (!gtk_recent_info_is_local (recent_info)
          || gtk_recent_info_get_private_hint (recent_info)
          || g_strcmp0 (gtk_recent_info_get_mime_type (recent_info), "inode/directory") == 0)
        continue;

      uri = gtk_recent_info_get_uri (recent_info);
      guid = g_hash_table_lookup (backend->uri_map, uri);
      if (guid)
        {
          if (gtk_recent_info_exists (recent_info))
            {
              RecentItem *item;
              item = g_hash_table_lookup (backend->items, guid);
              if (recent_item_update (item, recent_info))
                changed = g_list_prepend (changed, item->guid);
              not_seen_items = g_list_remove (not_seen_items, item);
            }
        }
      else
        {
          RecentItem *item;
          item = recent_item_new (recent_info);
          added = g_list_prepend (added, item->guid);
          g_hash_table_insert (backend->items, item->guid, item);
          g_hash_table_insert (backend->uri_map, item->uri, item->guid);
        }
      gtk_recent_info_unref (recent_info);
    }

  g_list_free (items);

  monitor = recent_backend_get_dir_monitor (backend, FALSE);

  /* process removals */
  for (l = not_seen_items; l; l = l->next)
    {
      RecentItem *item = l->data;
      g_hash_table_remove (backend->uri_map, item->uri);
      g_hash_table_steal (backend->items, item->guid);
      if (monitor)
        g_vfs_monitor_emit_event (monitor, G_FILE_MONITOR_EVENT_DELETED, item->guid, NULL);
      recent_item_free (item);
    }
  g_list_free (not_seen_items);

  /* process additions */
  if (monitor)
    {
      for (l = added; l; l = l->next)
        g_vfs_monitor_emit_event (monitor, G_FILE_MONITOR_EVENT_CREATED, l->data, NULL);
    }
  g_list_free (added);

  /* process changes */
  for (l = changed; l; l = l->next)
    {
      /* FIXME: signals */
    }
  g_list_free (changed);

  if (monitor)
    g_object_unref (monitor);
}
Пример #5
0
GList *
gedit_recent_get_items (GeditRecentConfiguration *config)
{
    GtkRecentFilterFlags needed;
    GList *items;
    GList *retitems = NULL;
    gint length;
    gboolean has_substring_filter;

    if (config->limit == 0)
    {
        return NULL;
    }

    items = gtk_recent_manager_get_items (config->manager);

    if (!items)
    {
        return NULL;
    }

    needed = gtk_recent_filter_get_needed (config->filter);
    has_substring_filter = (config->substring_filter && *config->substring_filter != '\0');

    while (items)
    {
        GtkRecentInfo *info;
        GtkRecentFilterInfo filter_info;
        gboolean is_filtered;

        info = items->data;
        is_filtered = FALSE;

        if (config->local_only && !gtk_recent_info_is_local (info))
        {
            is_filtered = TRUE;
        }
        else if (!config->show_private && gtk_recent_info_get_private_hint (info))
        {
            is_filtered = TRUE;
        }
        else if (!config->show_not_found && !gtk_recent_info_exists (info))
        {
            is_filtered = TRUE;
        }
        else
        {
            if (has_substring_filter)
            {
                gchar *uri_lower;

                uri_lower = g_utf8_strdown (gtk_recent_info_get_uri (info), -1);

                if (strstr (uri_lower, config->substring_filter) == NULL)
                {
                    is_filtered = TRUE;
                }

                g_free (uri_lower);
            }

            if (!is_filtered)
            {
                populate_filter_info (info, &filter_info, needed);
                is_filtered = !gtk_recent_filter_filter (config->filter, &filter_info);

                /* these we own */
                if (filter_info.applications)
                {
                    g_strfreev ((gchar **) filter_info.applications);
                }

                if (filter_info.groups)
                {
                    g_strfreev ((gchar **) filter_info.groups);
                }
            }
        }

        if (!is_filtered)
        {
            retitems = g_list_prepend (retitems, info);
        }
        else
        {
            gtk_recent_info_unref (info);
        }

        items = g_list_delete_link (items, items);
    }

    if (!retitems)
    {
        return NULL;
    }

    retitems = g_list_sort_with_data (retitems, (GCompareDataFunc) sort_recent_items_mru, NULL);
    length = g_list_length (retitems);

    if ((config->limit != -1) && (length > config->limit))
    {
        GList *clamp, *l;

        clamp = g_list_nth (retitems, config->limit - 1);

        if (!clamp)
        {
            return retitems;
        }

        l = clamp->next;
        clamp->next = NULL;

        g_list_free_full (l, (GDestroyNotify) gtk_recent_info_unref);
    }

    return retitems;
}
Пример #6
0
/*
 * _gtk_recent_chooser_get_items:
 * @chooser: a #GtkRecentChooser
 * @filter: a #GtkRecentFilter
 * @sort_func: (allow-none): sorting function, or %NULL
 * @sort_data: (allow-none): sorting function data, or %NULL
 *
 * Default implementation for getting the filtered, sorted and
 * clamped list of recently used resources from a #GtkRecentChooser.
 * This function should be used by implementations of the
 * #GtkRecentChooser interface inside the GtkRecentChooser::get_items
 * vfunc.
 *
 * Return value: a list of #GtkRecentInfo objects
 */
GList *
_gtk_recent_chooser_get_items (GtkRecentChooser  *chooser,
                               GtkRecentFilter   *filter,
                               GtkRecentSortFunc  sort_func,
                               gpointer           sort_data)
{
  GtkRecentManager *manager;
  gint limit;
  GtkRecentSortType sort_type;
  GList *items;
  GCompareDataFunc compare_func;
  gint length;

  g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);

  manager = _gtk_recent_chooser_get_recent_manager (chooser);
  if (!manager)
    return NULL;

  items = gtk_recent_manager_get_items (manager);
  if (!items)
    return NULL;

  limit = gtk_recent_chooser_get_limit (chooser);
  if (limit == 0)
    return NULL;

  if (filter)
    {
      GList *filter_items, *l;
      gboolean local_only = FALSE;
      gboolean show_private = FALSE;
      gboolean show_not_found = FALSE;

      g_object_get (G_OBJECT (chooser),
                    "local-only", &local_only,
                    "show-private", &show_private,
                    "show-not-found", &show_not_found,
                    NULL);

      filter_items = NULL;
      for (l = items; l != NULL; l = l->next)
        {
          GtkRecentInfo *info = l->data;
          gboolean remove_item = FALSE;

          if (get_is_recent_filtered (filter, info))
            remove_item = TRUE;
          
          if (local_only && !gtk_recent_info_is_local (info))
            remove_item = TRUE;

          if (!show_private && gtk_recent_info_get_private_hint (info))
            remove_item = TRUE;

          if (!show_not_found && !gtk_recent_info_exists (info))
            remove_item = TRUE;
          
          if (!remove_item)
            filter_items = g_list_prepend (filter_items, info);
          else
            gtk_recent_info_unref (info);
        }
      
      g_list_free (items);
      items = filter_items;
    }

  if (!items)
    return NULL;

  sort_type = gtk_recent_chooser_get_sort_type (chooser);
  switch (sort_type)
    {
    case GTK_RECENT_SORT_NONE:
      compare_func = NULL;
      break;
    case GTK_RECENT_SORT_MRU:
      compare_func = (GCompareDataFunc) sort_recent_items_mru;
      break;
    case GTK_RECENT_SORT_LRU:
      compare_func = (GCompareDataFunc) sort_recent_items_lru;
      break;
    case GTK_RECENT_SORT_CUSTOM:
      compare_func = (GCompareDataFunc) sort_recent_items_proxy;
      break;
    default:
      g_assert_not_reached ();
      break;
    }

  if (compare_func)
    {
      SortRecentData sort_recent;

      sort_recent.func = sort_func;
      sort_recent.data = sort_data;

      items = g_list_sort_with_data (items, compare_func, &sort_recent);
    }
  
  length = g_list_length (items);
  if ((limit != -1) && (length > limit))
    {
      GList *clamp, *l;
      
      clamp = g_list_nth (items, limit - 1);
      if (!clamp)
        return items;
      
      l = clamp->next;
      clamp->next = NULL;
    
      g_list_free_full (l, (GDestroyNotify) gtk_recent_info_unref);
    }

  return items;
}