static GSList *
sort_and_concat_results (ShellAppSystem *system,
                         GSList         *multiple_matches,
                         GSList         *prefix_matches,
                         GSList         *substring_matches)
{
  multiple_matches = g_slist_sort_with_data (multiple_matches, shell_app_info_compare, system);
  prefix_matches = g_slist_sort_with_data (prefix_matches, shell_app_info_compare, system);
  substring_matches = g_slist_sort_with_data (substring_matches, shell_app_info_compare, system);
  return g_slist_concat (multiple_matches, g_slist_concat (prefix_matches, substring_matches));
}
Example #2
0
static GSList *
sort_and_concat_results (ShellAppSystem *system,
                         GSList         *prefix_matches,
                         GSList         *substring_matches)
{
  prefix_matches = g_slist_sort_with_data (prefix_matches,
                                           compare_apps_by_usage,
                                           system);
  substring_matches = g_slist_sort_with_data (substring_matches,
                                              compare_apps_by_usage,
                                              system);
  return g_slist_concat (prefix_matches, substring_matches);
}
Example #3
0
/* Create the filetypes array and fill it with the known filetypes.
 * Warning: GTK isn't necessarily initialized yet. */
void filetypes_init_types(void)
{
	filetype_id ft_id;
	gchar *f;

	g_return_if_fail(filetypes_array == NULL);
	g_return_if_fail(filetypes_hash == NULL);

	filetypes_array = g_ptr_array_sized_new(GEANY_MAX_BUILT_IN_FILETYPES);
	filetypes_hash = g_hash_table_new(g_str_hash, g_str_equal);

	/* Create built-in filetypes */
	for (ft_id = 0; ft_id < GEANY_MAX_BUILT_IN_FILETYPES; ft_id++)
	{
		filetypes[ft_id] = filetype_new();
	}
	init_builtin_filetypes();

	/* Add built-in filetypes to the hash now the name fields are set */
	for (ft_id = 0; ft_id < GEANY_MAX_BUILT_IN_FILETYPES; ft_id++)
	{
		filetype_add(filetypes[ft_id]);
	}
	init_custom_filetypes(app->datadir);
	f = g_build_filename(app->configdir, GEANY_FILEDEFS_SUBDIR, NULL);
	init_custom_filetypes(f);
	g_free(f);

	/* sort last instead of on insertion to prevent exponential time */
	filetypes_by_title = g_slist_sort_with_data(filetypes_by_title,
		cmp_filetype, GINT_TO_POINTER(FALSE));

	read_filetype_config();
}
Example #4
0
static MuContainer*
container_sort_real (MuContainer *c, SortFuncData *sfdata)
{
	GSList *lst;
	MuContainer *cur;

	if (!c)
		return NULL;

	for (cur = c; cur; cur = cur->next) {
		if (cur->child)
			cur->child = container_sort_real (cur->child, sfdata);
		cur->leader = find_sorted_tree_leader (cur, sfdata);
	}

	/* sort siblings */
	lst = mu_container_to_list (c);
	lst = g_slist_sort_with_data(lst,
				     (GCompareDataFunc)sort_func_wrapper,
				     sfdata);
	c = mu_container_from_list (lst);
	g_slist_free (lst);

	return c;
}
static gboolean
gutter_renderer_query_tooltip (GtkSourceGutterRenderer *renderer,
                               GtkTextIter             *iter,
                               GdkRectangle            *area,
                               gint                     x,
                               gint                     y,
                               GtkTooltip              *tooltip)
{
	GSList *marks;
	GtkSourceView *view;
	GtkSourceBuffer *buffer;

	view = GTK_SOURCE_VIEW (gtk_source_gutter_renderer_get_view (renderer));
	buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));

	marks = gtk_source_buffer_get_source_marks_at_iter (buffer,
	                                                    iter,
	                                                    NULL);

	if (marks != NULL)
	{
		marks = g_slist_sort_with_data (marks,
		                                sort_marks_by_priority,
		                                view);

		marks = g_slist_reverse (marks);

		return set_tooltip_widget_from_marks (view, tooltip, marks);
	}

	return FALSE;
}
Example #6
0
void fe_channels_nicklist(CHANNEL_REC *channel, int flags)
{
	NICK_REC *nick;
	GSList *tmp, *nicklist, *sorted;
	int nicks, normal, voices, halfops, ops;
	const char *nick_flags;

	nicks = normal = voices = halfops = ops = 0;
	nicklist = nicklist_getnicks(channel);
	sorted = NULL;
	nick_flags = channel->server->get_nick_flags(channel->server);

	/* filter (for flags) and count ops, halfops, voices */
	for (tmp = nicklist; tmp != NULL; tmp = tmp->next) {
		nick = tmp->data;

		nicks++;
		if (nick->op) {
			ops++;
			if ((flags & CHANNEL_NICKLIST_FLAG_OPS) == 0)
                                continue;
		} else if (nick->halfop) {
			halfops++;
			if ((flags & CHANNEL_NICKLIST_FLAG_HALFOPS) == 0)
				continue;
		} else if (nick->voice) {
			voices++;
			if ((flags & CHANNEL_NICKLIST_FLAG_VOICES) == 0)
				continue;
		} else {
			normal++;
			if ((flags & CHANNEL_NICKLIST_FLAG_NORMAL) == 0)
				continue;
		}

		sorted = g_slist_prepend(sorted, nick);
	}
	g_slist_free(nicklist);

	/* sort the nicklist */
	sorted = g_slist_sort_with_data(sorted, (GCompareDataFunc) nicklist_compare, (void *)nick_flags);

	/* display the nicks */
        if ((flags & CHANNEL_NICKLIST_FLAG_COUNT) == 0) {
		printformat(channel->server, channel->visible_name,
			    MSGLEVEL_CLIENTCRAP, TXT_NAMES,
			    channel->visible_name,
			    nicks, ops, halfops, voices, normal);
		display_sorted_nicks(channel, sorted);
	}
	g_slist_free(sorted);

	printformat(channel->server, channel->visible_name,
		    MSGLEVEL_CLIENTNOTICE, TXT_ENDOFNAMES,
		    channel->visible_name, nicks, ops, halfops, voices, normal);
}
Example #7
0
/** Gets a list of filetype pointers sorted by name.
 * The list does not change on subsequent calls.
 * @return The list - do not free.
 * @see filetypes_by_title. */
const GSList *filetypes_get_sorted_by_name(void)
{
	static GSList *list = NULL;

	g_return_val_if_fail(filetypes_by_title, NULL);

	if (!list)
	{
		list = g_slist_copy(filetypes_by_title);
		list = g_slist_sort_with_data(list, cmp_filetype, GINT_TO_POINTER(TRUE));
	}
	return list;
}
Example #8
0
static Window *visible_windows_on_all_outputs(i3ipcCon *root, SortMethod sort_method)
{
    GSList *raw_replies = i3ipc_connection_get_workspaces(connection, NULL);
    GSList *replies = g_slist_reverse(raw_replies); // i3ipc-glib reverses the order internally

    if (sort_method == BY_NUMBER)
    {
        replies = g_slist_sort(replies, compare_workspace_nums);
    }
    else if (sort_method == BY_LOCATION)
    {
        GSList *outputs = i3ipc_connection_get_outputs(connection, NULL);
        replies = g_slist_sort_with_data(replies, compare_workspace_position, outputs);
        g_slist_free_full(outputs, (GDestroyNotify) i3ipc_output_reply_free);
    }

    GList *workspaces = i3ipc_con_workspaces(root);

    Window *res = NULL;
    const GSList *reply;
    i3ipcWorkspaceReply *curr_reply;
    for (reply = replies; reply; reply = reply->next)
    {
        curr_reply = reply->data;
        if (!curr_reply->visible)
            continue;

        const GList *ws;
        i3ipcCon *curr_ws;
        for (ws = workspaces; ws; ws = ws->next)
        {
            curr_ws = ws->data;
            const char *name = i3ipc_con_get_name(curr_ws);
            if (strcmp(curr_reply->name, name) == 0)
            {
                i3ipcCon *con = con_get_visible_container(curr_ws);
                res = window_append(res, visible_windows(con));
                break;
            }
        }
    }

    g_slist_free_full(replies, (GDestroyNotify) i3ipc_workspace_reply_free);
    g_list_free(workspaces);

    return res;
}
Example #9
0
/**
 * cinnamon_app_get_windows:
 * @app:
 *
 * Get the toplevel, interesting windows which are associated with this
 * application.  The returned list will be sorted first by whether
 * they're on the active workspace, then by whether they're visible,
 * and finally by the time the user last interacted with them.
 *
 * Returns: (transfer none) (element-type MetaWindow): List of windows
 */
GSList *
cinnamon_app_get_windows (CinnamonApp *app)
{
  if (app->running_state == NULL)
    return NULL;

  if (app->running_state->window_sort_stale)
    {
      CompareWindowsData data;
      data.app = app;
      data.active_workspace = meta_screen_get_active_workspace (cinnamon_global_get_screen (cinnamon_global_get ()));
      app->running_state->windows = g_slist_sort_with_data (app->running_state->windows, cinnamon_app_compare_windows, &data);
      app->running_state->window_sort_stale = FALSE;
    }

  return app->running_state->windows;
}
Example #10
0
/* Picks best ap, deletes the rest. Creates one if necessary */
static GSList *provision_pick_best_ap(GSList *list, const char* spn,
	const struct provision_ap_defaults *defaults)
{
	/* Sort the list */
	list = g_slist_sort_with_data(list, provision_compare_ap, (void*)spn);
	if (list) {
		/* Pick the best one, delete the rest */
		GSList *best = list;
		g_slist_free_full(g_slist_remove_link(list, best),
							provision_free_ap);
		return best;
	} else {
		/* or create one from the default data */
		struct ofono_gprs_provision_data *ap =
			g_new0(struct ofono_gprs_provision_data, 1);

		ap->type = defaults->type;
		ap->name = g_strdup(defaults->name);
		ap->apn = g_strdup(defaults->apn);
		return g_slist_append(NULL, ap);
	}
}
/**
 * shell_app_usage_get_most_used:
 * @usage: the usage instance to request
 * @context: Activity identifier
 *
 * Get a list of most popular applications for a given context.
 *
 * Returns: (element-type ShellApp) (transfer full): List of applications
 */
GSList *
shell_app_usage_get_most_used (ShellAppUsage   *self,
                               const char      *context)
{
  GSList *apps;
  GList *appids, *iter;
  GHashTable *usages;
  ShellAppSystem *appsys;
  SortAppsByUsageData data;

  usages = g_hash_table_lookup (self->app_usages_for_context, context);
  if (usages == NULL)
    return NULL;

  appsys = shell_app_system_get_default ();

  appids = g_hash_table_get_keys (usages);
  apps = NULL;
  for (iter = appids; iter; iter = iter->next)
    {
      const char *appid = iter->data;
      ShellApp *app;

      app = shell_app_system_lookup_app (appsys, appid);
      if (!app)
        continue;

      apps = g_slist_prepend (apps, g_object_ref (app));
    }

  g_list_free (appids);

  data.usage = self;
  data.context_usages = usages;
  apps = g_slist_sort_with_data (apps, sort_apps_by_usage, &data);

  return apps;
}
Example #12
0
static void
test_slist_sort_with_data (void)
{
  GSList *slist = NULL;
  gint    i;

  PRINT_MSG (("testing g_slist_sort_with_data()"));

  for (i = 0; i < SIZE; i++) {
    slist = g_slist_append (slist, GINT_TO_POINTER (array[i]));
  }

  slist = g_slist_sort_with_data (slist, (GCompareDataFunc)sort, NULL);
  for (i = 0; i < SIZE - 1; i++) {
    gpointer p1, p2;

    p1 = g_slist_nth_data (slist, i);
    p2 = g_slist_nth_data (slist, i+1);

    g_assert (GPOINTER_TO_INT (p1) <= GPOINTER_TO_INT (p2));
    DEBUG_MSG (("slist_sort_with_data #%3.3d ---> %d", i, GPOINTER_TO_INT (p1)));
  }
}
Example #13
0
/**
 * @brief Creates team spawns if the map doesn't have one. Also creates flags, although
 * chances are they will be in crap positions.
 */
static void G_CreateTeamSpawnPoints(GSList **dm_spawns, GSList **team_red_spawns, GSList **team_blue_spawns) {

	// find our flags
	g_entity_t *red_flag, *blue_flag;
	g_entity_t *reused_spawns[2] = { NULL, NULL };
	
	red_flag = g_team_red->flag_entity;
	blue_flag = g_team_blue->flag_entity;

	if (!!red_flag != !!blue_flag) {
		gi.Error("Make sure you have both flags in your map!\n");
	} else if (!red_flag) {
		// no flag in map, so let's make one by repurposing the furthest spawn points

		if (g_slist_length(*dm_spawns) < 4) {
			return; // not enough points to make a flag
		}

		vec_t furthest_dist = 0;

		for (GSList *pa = *dm_spawns; pa; pa = pa->next) {
			for (GSList *pb = *dm_spawns; pb; pb = pb->next) {

				if (pa == pb) {
					continue;
				}
				
				g_entity_t *pae = (g_entity_t *) pa->data;
				g_entity_t *pab = (g_entity_t *) pb->data;

				if ((reused_spawns[0] == pae && reused_spawns[1] == pab) ||
					(reused_spawns[0] == pab && reused_spawns[1] == pae)) {
					continue;
				}

				vec3_t line;
				VectorSubtract(pae->s.origin, pab->s.origin, line);
				line[2] /= 10.0; // don't consider Z as heavily as X/Y

				const vec_t dist = VectorLengthSquared(line);

				if (dist > furthest_dist) {

					reused_spawns[0] = pae;
					reused_spawns[1] = pab;
					furthest_dist = dist;
				}
			}
		}

		if (!reused_spawns[0] || !reused_spawns[1] || !furthest_dist) {
			return; // error in finding furthest points
		}
		
		red_flag = G_AllocEntity_(g_team_red->flag);
		blue_flag = G_AllocEntity_(g_team_blue->flag);

		const uint8_t r = Randomr(0, 2);

		VectorCopy(reused_spawns[r]->s.origin, red_flag->s.origin);
		VectorCopy(reused_spawns[r ^ 1]->s.origin, blue_flag->s.origin);
		
		G_SpawnItem(red_flag, g_media.items.flags[TEAM_RED]);
		G_SpawnItem(blue_flag, g_media.items.flags[TEAM_BLUE]);
		
		g_team_red->flag_entity = red_flag;
		g_team_blue->flag_entity = blue_flag;
	}

	for (GSList *point = *dm_spawns; point; point = point->next) {

		g_entity_t *p = (g_entity_t *) point->data;

		if (p == reused_spawns[0] || p == reused_spawns[1]) {
			continue;
		}

		const vec_t dist_to_red = VectorDistanceSquared(red_flag->s.origin, p->s.origin);
		const vec_t dist_to_blue = VectorDistanceSquared(blue_flag->s.origin, p->s.origin);

		if (dist_to_red < dist_to_blue) {
			*team_red_spawns = g_slist_prepend(*team_red_spawns, p);
		} else {
			*team_blue_spawns = g_slist_prepend(*team_blue_spawns, p);
		}
	}

	if (g_slist_length(*team_red_spawns) == g_slist_length(*team_blue_spawns)) {
		return; // best case scenario
	}
	
	// unmatched spawns, we need to move some
	*team_red_spawns = g_slist_sort_with_data(*team_red_spawns, G_CreateTeamSpawnPoints_CompareFunc, red_flag);
	*team_blue_spawns = g_slist_sort_with_data(*team_blue_spawns, G_CreateTeamSpawnPoints_CompareFunc, blue_flag);
		
	int32_t num_red_spawns = (int32_t) g_slist_length(*team_red_spawns);
	int32_t num_blue_spawns = (int32_t) g_slist_length(*team_blue_spawns);
	int32_t diff = abs(num_red_spawns - num_blue_spawns);

	GSList **from, **to;

	if (num_red_spawns > num_blue_spawns) {
		from = team_red_spawns;
		to = team_blue_spawns;
	} else {
		from = team_blue_spawns;
		to = team_red_spawns;
	}

	// odd number of points, make one neutral
	if (diff & 1) {
		g_entity_t *point = (g_entity_t *) ((*from)->data);

		*to = g_slist_prepend(*to, point);
	}

	int32_t num_move = diff - 1;
	
	// move spawns to the other team
	while (num_move) {

		g_entity_t *point = (g_entity_t *) ((*from)->data);

		*from = g_slist_remove(*from, point);
		*to = g_slist_prepend(*to, point);

		num_move--;
	}
}
static GdkPixbuf *
composite_marks (GtkSourceView *view,
                 GSList        *marks,
                 gint           size)
{
	GdkPixbuf *composite;
	gint mark_width;
	gint mark_height;

	/* Draw the mark with higher priority */
	marks = g_slist_sort_with_data (marks, sort_marks_by_priority, view);

	composite = NULL;
	mark_width = 0;
	mark_height = 0;

	/* composite all the pixbufs for the marks present at the line */
	do
	{
		GtkSourceMark *mark;
		GtkSourceMarkAttributes *attrs;
		const GdkPixbuf *pixbuf;

		mark = marks->data;
		attrs = gtk_source_view_get_mark_attributes (view,
		                                             gtk_source_mark_get_category (mark),
		                                             NULL);

		if (attrs == NULL)
		{
			continue;
		}

		pixbuf = gtk_source_mark_attributes_render_icon (attrs,
		                                                 GTK_WIDGET (view),
		                                                 size);

		if (pixbuf != NULL)
		{
			if (composite == NULL)
			{
				composite = gdk_pixbuf_copy (pixbuf);
				mark_width = gdk_pixbuf_get_width (composite);
				mark_height = gdk_pixbuf_get_height (composite);
			}
			else
			{
				gint pixbuf_w;
				gint pixbuf_h;

				pixbuf_w = gdk_pixbuf_get_width (pixbuf);
				pixbuf_h = gdk_pixbuf_get_height (pixbuf);

				gdk_pixbuf_composite (pixbuf,
				                      composite,
				                      0, 0,
				                      mark_width, mark_height,
				                      0, 0,
				                      (gdouble) pixbuf_w / mark_width,
				                      (gdouble) pixbuf_h / mark_height,
				                      GDK_INTERP_BILINEAR,
				                      COMPOSITE_ALPHA);
			}
		}

		marks = g_slist_next (marks);
	}
	while (marks);

	return composite;
}
Example #15
0
// Tests for slist
void tg_slist_tests()
{
	GSList *slist,*st,*rem;
	gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	gint chk_buf[20];
	gint i;
	gint g_slist_insert_data;
	gint g_slist_insert_before_data;
	gint ip1 = 10;
	gint ip2 = 15;
	gint ip3 = 5;
	gint ip4 = 12;
	gint g_slist_nth_data_op,g_slist_find_custom_op;
	
	//Trying to use the allocators so that even they get tested!
	GAllocator* alloc = g_allocator_new ("alloc_slist",5000);
	g_slist_push_allocator (alloc);
	
	
	slist = NULL;
	for (i = 0; i < 10; i++)
		slist = g_slist_append (slist, &nums[i]);
	
	//List looks like:
	// 0   1   2   3   4   5   6   7   8   9
	
	//Test for g_slist_insert....inserted 10 at pos 4
	g_slist_insert(slist,&ip1,4);
	st = g_slist_nth (slist,0);
	for(i = 0;i < 4;i++)
		st = st->next;
	g_slist_insert_data = *((gint*) st->data);
	g_assert(g_slist_insert_data == 10);
	
/*	for (i = 0; i < 10; i++)
    {
      st = g_slist_nth (slist, i);
      chk_buf[i] = *((gint*) st->data);
    }*/
    
	//List looks like:
	// 0   1   2   3   10   4   5   6   7   8   9
	
	//Test for g_slist_insert_before....inserted 15 at pos 7
	st = g_slist_nth (slist,7);
	g_slist_insert_before(slist,st,&ip2);
	st = g_slist_nth (slist,0);
	for(i = 0;i < 7;i++)
		st = st->next;
	g_slist_insert_before_data = *((gint*) st->data);
	g_assert(g_slist_insert_before_data == 15);
	
	//List looks like:
	// 0   1   2   3   10   4   5   15   6   7   8   9
	
	//Test for g_slist_index....finding 15 at pos 7
	st = g_slist_nth (slist,0);
	g_assert(g_slist_index(st,&ip2)==7);

	//Test for g_slist_nth_data....getting 6 at position 8
	g_slist_nth_data_op = *((gint*) g_slist_nth_data(slist,8));
	g_assert(g_slist_nth_data_op == 6)	;

	//Test for g_slist_position
	st = g_slist_nth (slist,7);
	g_assert(g_slist_position (slist,st) == 7);

	//Test for g_slist_find_custom
	st = g_slist_find_custom(slist,&ip3,compare_fun_gr);
	g_slist_find_custom_op = *((gint*) st->data);
	g_assert(g_slist_find_custom_op == 5);
	
	//Test for g_slist_sort_with_data
	st = g_slist_sort_with_data(slist,compare_fun_gr_data,&ip3);
	for (i = 0; i < 10; i++)
    {
      st = g_slist_nth (slist, i);
      g_assert (*((gint*) st->data) == i);
    }

	//List looks like:
	// 0   1   2   3   4   5   6   7   8   9   10   15
	
	//Test for g_slist_remove_link
	st = g_slist_nth (slist, 5);
	rem = g_slist_remove_link(slist , st);
	st = g_slist_nth (slist, 5);
    g_assert (*((gint*) st->data) == 6);

	//List looks like:
	// 0   1   2   3   4   6   7   8   9   10   15

	//Test for g_slist_remove_all
	g_slist_insert(slist,&ip4,4);
	g_slist_insert(slist,&ip4,6);
	g_slist_insert(slist,&ip4,8);
	//List looks like:
	// 0   1   2   3   4   12   6   7   12   8   12   9   10   15
	g_slist_remove_all(slist ,&ip4);
    
	g_slist_free (slist);
	g_slist_pop_allocator ();
}
void
gimp_plug_in_manager_restore (GimpPlugInManager  *manager,
                              GimpContext        *context,
                              GimpInitStatusFunc  status_callback)
{
  Gimp   *gimp;
  gchar  *pluginrc;
  GSList *list;
  GError *error = NULL;

  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
  g_return_if_fail (GIMP_IS_CONTEXT (context));
  g_return_if_fail (status_callback != NULL);

  gimp = manager->gimp;

  /* need a GimpPDBContext for calling gimp_plug_in_manager_run_foo() */
  context = gimp_pdb_context_new (gimp, context, TRUE);

  /* search for binaries in the plug-in directory path */
  gimp_plug_in_manager_search (manager, status_callback);

  /* read the pluginrc file for cached data */
  pluginrc = gimp_plug_in_manager_get_pluginrc (manager);

  gimp_plug_in_manager_read_pluginrc (manager, pluginrc, status_callback);

  /* query any plug-ins that changed since we last wrote out pluginrc */
  gimp_plug_in_manager_query_new (manager, context, status_callback);

  /* initialize the plug-ins */
  gimp_plug_in_manager_init_plug_ins (manager, context, status_callback);

  /* add the procedures to manager->plug_in_procedures */
  for (list = manager->plug_in_defs; list; list = list->next)
    {
      GimpPlugInDef *plug_in_def = list->data;
      GSList        *list2;

      for (list2 = plug_in_def->procedures; list2; list2 = list2->next)
        {
          gimp_plug_in_manager_add_procedure (manager, list2->data);
        }
    }

  /* write the pluginrc file if necessary */
  if (manager->write_pluginrc)
    {
      if (gimp->be_verbose)
        g_print ("Writing '%s'\n", gimp_filename_to_utf8 (pluginrc));

      if (! plug_in_rc_write (manager->plug_in_defs, pluginrc, &error))
        {
          gimp_message_literal (gimp,
				NULL, GIMP_MESSAGE_ERROR, error->message);
          g_clear_error (&error);
        }

      manager->write_pluginrc = FALSE;
    }

  g_free (pluginrc);

  /* create locale and help domain lists */
  for (list = manager->plug_in_defs; list; list = list->next)
    {
      GimpPlugInDef *plug_in_def = list->data;

      if (plug_in_def->locale_domain_name)
        gimp_plug_in_manager_add_locale_domain (manager,
                                                plug_in_def->prog,
                                                plug_in_def->locale_domain_name,
                                                plug_in_def->locale_domain_path);
      else
        /* set the default plug-in locale domain */
        gimp_plug_in_def_set_locale_domain (plug_in_def,
                                            gimp_plug_in_manager_get_locale_domain (manager,
                                                                                    plug_in_def->prog,
                                                                                    NULL),
                                            NULL);

      if (plug_in_def->help_domain_name)
        gimp_plug_in_manager_add_help_domain (manager,
                                              plug_in_def->prog,
                                              plug_in_def->help_domain_name,
                                              plug_in_def->help_domain_uri);
    }

  /* we're done with the plug-in-defs */
  g_slist_free_full (manager->plug_in_defs, (GDestroyNotify) g_object_unref);
  manager->plug_in_defs = NULL;

  /* bind plug-in text domains  */
  gimp_plug_in_manager_bind_text_domains (manager);

  /* add the plug-in procs to the procedure database */
  for (list = manager->plug_in_procedures; list; list = list->next)
    {
      gimp_plug_in_manager_add_to_db (manager, context, list->data);
    }

  /* sort the load, save and export procedures  */
  manager->load_procs =
    g_slist_sort_with_data (manager->load_procs,
                            gimp_plug_in_manager_file_proc_compare, manager);
  manager->save_procs =
    g_slist_sort_with_data (manager->save_procs,
                            gimp_plug_in_manager_file_proc_compare, manager);
  manager->export_procs =
    g_slist_sort_with_data (manager->export_procs,
                            gimp_plug_in_manager_file_proc_compare, manager);

  gimp_plug_in_manager_run_extensions (manager, context, status_callback);

  g_object_unref (context);
}
Example #17
0
/** @brief RmMDSDevice worker thread
 **/
static void rm_mds_factory(RmMDSDevice *device, RmMDS *mds) {
    /* rm_mds_factory processes tasks from device->task_list.
     * After completing one pass of the device, returns self to the
     * mds->pool threadpool. */
    gint processed = 0;
    g_mutex_lock(&device->lock);
    {
        /* check for empty queues - if so then wait a little while before giving up */
        if(!device->sorted_tasks && !device->unsorted_tasks && device->ref_count > 0) {
            /* timed wait for signal from rm_mds_push_task_impl() */
            gint64 end_time = g_get_monotonic_time() + MDS_EMPTYQUEUE_SLEEP_US;
            g_cond_wait_until(&device->cond, &device->lock, end_time);
        }

        /* sort and merge task lists */
        if(device->unsorted_tasks) {
            if(mds->prioritiser) {
                device->sorted_tasks = g_slist_concat(
                                           g_slist_sort_with_data(device->unsorted_tasks,
                                                   (GCompareDataFunc)rm_mds_compare,
                                                   (RmMDSSortFunc)mds->prioritiser),
                                           device->sorted_tasks);
            } else {
                device->sorted_tasks =
                    g_slist_concat(device->unsorted_tasks, device->sorted_tasks);
            }
            device->unsorted_tasks = NULL;
        }
    }
    g_mutex_unlock(&device->lock);

    /* process tasks from device->sorted_tasks */
    RmMDSTask *task = NULL;
    while(processed < mds->pass_quota && (task = rm_util_slist_pop(&device->sorted_tasks, &device->lock))) {
        if(mds->func(task->task_data, mds->user_data)) {
            /* task succeeded; update counters */
            ++processed;
        }
        rm_mds_task_free(task);
    }

    if(rm_mds_device_ref(device, 0) > 0) {
        /* return self to pool for further processing */
        if(processed == 0) {
            /* stalled queue; chill for a bit */
            g_usleep(1000);
        }
        rm_util_thread_pool_push(mds->pool, device);
    } else if(g_atomic_int_dec_and_test(&device->threads)) {
        /* free self and signal to rm_mds_free() */
        g_mutex_lock(&mds->lock);
        {
            rm_log_debug_line("Freeing device %" LLU " (pointer %p)", (RmOff)device->disk,
                              device);
            g_hash_table_remove(mds->disks, GINT_TO_POINTER(device->disk));
            rm_mds_device_free(device);
            g_cond_signal(&mds->cond);
        }
        g_mutex_unlock(&mds->lock);
    }
}