Exemplo n.º 1
0
gchar* remmina_file_manager_get_groups(void)
{
	gchar dirname[MAX_PATH_LEN];
	gchar filename[MAX_PATH_LEN];
	GDir* dir;
	const gchar* name;
	RemminaFile* remminafile;
	RemminaStringArray* array;
	const gchar* group;
	gchar* groups;

	array = remmina_string_array_new();

	g_snprintf(dirname, MAX_PATH_LEN, "%s/.remmina", g_get_home_dir());
	dir = g_dir_open(dirname, 0, NULL);
	if (dir == NULL)
		return 0;
	while ((name = g_dir_read_name(dir)) != NULL)
	{
		if (!g_str_has_suffix(name, ".remmina"))
			continue;
		g_snprintf(filename, MAX_PATH_LEN, "%s/%s", dirname, name);
		remminafile = remmina_file_load(filename);
		group = remmina_file_get_string(remminafile, "group");
		if (group && remmina_string_array_find(array, group) < 0)
		{
			remmina_string_array_add(array, group);
		}
		remmina_file_free(remminafile);
	}
	g_dir_close(dir);
	remmina_string_array_sort(array);
	groups = remmina_string_array_to_string(array);
	remmina_string_array_free(array);
	return groups;
}
Exemplo n.º 2
0
void __for_each_file(const std::string& dirname, const std::string& suff,
                     const List& order_list, const List& disable_list,
                     Function f)
{
    GDir *dir = g_dir_open(dirname.c_str(), 0, NULL);
    if (dir) {
        const gchar *filename;

        while ((filename = g_dir_read_name(dir))!=NULL) {
            std::string fullfilename(dirname+G_DIR_SEPARATOR_S+filename);
            if (g_file_test(fullfilename.c_str(), G_FILE_TEST_IS_DIR))
                __for_each_file(fullfilename, suff, order_list, disable_list, f);
            else if (g_str_has_suffix(filename, suff.c_str()) &&
                     std::find(order_list.begin(), order_list.end(),
                               fullfilename)==order_list.end()) {
                bool disable=std::find(disable_list.begin(),
                                       disable_list.end(),
                                       fullfilename)!=disable_list.end();
                f(fullfilename, disable);
            }
        }
        g_dir_close(dir);
    }
}
Exemplo n.º 3
0
static int
dt_imageio_load_modules_storage (dt_imageio_t *iio)
{
  iio->plugins_storage = NULL;
  dt_imageio_module_storage_t *module;
  char plugindir[PATH_MAX], plugin_name[256];
  const gchar *d_name;
  dt_loc_get_plugindir(plugindir, sizeof(plugindir));
  g_strlcat(plugindir, "/plugins/imageio/storage", sizeof(plugindir));
  GDir *dir = g_dir_open(plugindir, 0, NULL);
  if(!dir) return 1;
  const int name_offset = strlen(SHARED_MODULE_PREFIX),
            name_end    = strlen(SHARED_MODULE_PREFIX) + strlen(SHARED_MODULE_SUFFIX);
  while((d_name = g_dir_read_name(dir)))
  {
    // get lib*.so
    if(!g_str_has_prefix(d_name, SHARED_MODULE_PREFIX)) continue;
    if(!g_str_has_suffix(d_name, SHARED_MODULE_SUFFIX)) continue;
    strncpy(plugin_name, d_name+name_offset, strlen(d_name)-name_end);
    plugin_name[strlen(d_name)-name_end] = '\0';
    module = (dt_imageio_module_storage_t *)malloc(sizeof(dt_imageio_module_storage_t));
    gchar *libname = g_module_build_path(plugindir, (const gchar *)plugin_name);
    if(dt_imageio_load_module_storage(module, libname, plugin_name))
    {
      free(module);
      continue;
    }
    module->gui_data = NULL;
    module->gui_init(module);
    if(module->widget) g_object_ref(module->widget);
    g_free(libname);
    dt_imageio_insert_storage(module);
  }
  g_dir_close(dir);
  return 0;
}
Exemplo n.º 4
0
static void
iterate_over_input(const gchar **knw,
		   ifile_iterator_t iter, void *data) {
  unsigned idx = 0;
  const gchar *inp;

  while ((inp = knw[idx++])) {
    GDir *dir = g_dir_open(inp, 0, NULL);
    const gchar *file;

    if (!dir)
      continue;

    /* Iterate over elements in the directory */
    while ((file = g_dir_read_name (dir)))
      if (g_str_has_suffix(file, ".dat")) {
	gchar *filename = g_build_filename(inp,file,NULL);
	iter(filename, data);
	g_free(filename);
      }

    g_dir_close(dir);
  }
}
Exemplo n.º 5
0
void search_in_dir(const gchar* dirname, const gchar* search_text, SearchTools* self) {
	GDir* dir = g_dir_open(dirname, 0, 0);
	if( !dir )
		return;

	for(;;) {
		gchar* filename;
		const gchar* fname = g_dir_read_name(dir);
		if( !fname )
			break;

		if( fname[0]=='.' )
			continue;

		filename = g_build_filename(dirname, fname, NULL);
		if( g_file_test(filename, G_FILE_TEST_IS_DIR) ) {
			search_in_dir(filename, search_text, self);
		} else {
			search_in_file(filename, search_text, self);
		}
		g_free(filename);
	}
	g_dir_close(dir);
}
Exemplo n.º 6
0
static void swap_clean (void)
{
  const gchar  *swap_dir = gegl_swap_dir ();
  GDir         *dir;

  if (! swap_dir)
    return;

  dir = g_dir_open (gegl_swap_dir (), 0, NULL);

  if (dir != NULL)
    {
      GPatternSpec *pattern = g_pattern_spec_new ("*");
      const gchar  *name;

      while ((name = g_dir_read_name (dir)) != NULL)
        {
          if (g_pattern_match_string (pattern, name))
            {
              gint readpid = atoi (name);

              if (!pid_is_running (readpid))
                {
                  gchar *fname = g_build_filename (gegl_swap_dir (),
                                                   name,
                                                   NULL);
                  g_unlink (fname);
                  g_free (fname);
                }
            }
         }

      g_pattern_spec_free (pattern);
      g_dir_close (dir);
    }
}
Exemplo n.º 7
0
static int
dt_imageio_load_modules_format(dt_imageio_t *iio)
{
  iio->plugins_format = NULL;
  GList *res = NULL;
  dt_imageio_module_format_t *module;
  char plugindir[1024], plugin_name[256];
  const gchar *d_name;
  dt_util_get_plugindir(plugindir, 1024);
  g_strlcat(plugindir, "/plugins/imageio/format", 1024);
  GDir *dir = g_dir_open(plugindir, 0, NULL);
  if(!dir) return 1;
  while((d_name = g_dir_read_name(dir)))
  {
    // get lib*.so
    if(strncmp(d_name, "lib", 3)) continue;
    if(strncmp(d_name + strlen(d_name) - 3, ".so", 3)) continue;
    strncpy(plugin_name, d_name+3, strlen(d_name)-6);
    plugin_name[strlen(d_name)-6] = '\0';
    module = (dt_imageio_module_format_t *)malloc(sizeof(dt_imageio_module_format_t));
    gchar *libname = g_module_build_path(plugindir, (const gchar *)plugin_name);
    if(dt_imageio_load_module_format(module, libname, plugin_name))
    {
      free(module);
      continue;
    }
    module->gui_data = NULL;
    module->gui_init(module);
    if(module->widget) gtk_widget_ref(module->widget);
    g_free(libname);
    res = g_list_insert_sorted(res, module, dt_imageio_sort_modules_format);
  }
  g_dir_close(dir);
  iio->plugins_format = res;
  return 0;
}
Exemplo n.º 8
0
void template_setup (GuTemplate* t) {
    const gchar *filename;
    char *filepath = NULL;
    GError *error = NULL;
    GtkTreeIter iter;

    gchar *dirpath = g_build_filename (g_get_user_config_dir (), "gummi",
                                      "templates" , NULL);

    GDir* dir = g_dir_open (dirpath, 0, &error);
    if (error) {
        /* print error if directory does not exist */
        slog (L_INFO, "unable to read template directory, creating new..\n");
        g_mkdir_with_parents (dirpath, DIR_PERMS);
        g_free (dirpath);
        return;
    }

    while ( (filename = g_dir_read_name (dir))) {
        filepath = g_build_filename (dirpath, filename, NULL);
        gtk_list_store_append (t->list_templates, &iter);
        gtk_list_store_set (t->list_templates, &iter, 0, filename, 1,
                filepath, -1);
        g_free (filepath);
    }
    g_free (dirpath);

    // disable the add button when there are no tabs opened (#388)
    if (!tabmanager_has_tabs()) {
        gtk_widget_set_sensitive (t->template_add, FALSE);
    }

    gtk_widget_set_sensitive (t->template_open, FALSE);


}
Exemplo n.º 9
0
/* find_sensors():
 *      - Get the sensor directory, and store it in '*sensor'.
 *      - It is searched for in 'directory'.
 *      - Only the subdirectories starting with 'subdir_prefix' are accepted as sensors.
 *      - 'subdir_prefix' may be NULL, in which case any subdir is considered a sensor. */
static void
find_sensors(thermal* th, char const* directory, char const* subdir_prefix,
             GetTempFunc get_temp, GetTempFunc get_crit)
{
    GDir *sensorsDirectory;
    const char *sensor_name;
    char sensor_path[100];

    if (! (sensorsDirectory = g_dir_open(directory, 0, NULL)))
        return;

    /* Scan the thermal_zone directory for available sensors */
    while ((sensor_name = g_dir_read_name(sensorsDirectory))) {
        if (sensor_name[0] == '.')
            continue;
        if (subdir_prefix) {
            if (strncmp(sensor_name, subdir_prefix, strlen(subdir_prefix)) != 0)
                continue;
        }
        snprintf(sensor_path,sizeof(sensor_path),"%s%s/", directory, sensor_name);
        add_sensor(th, sensor_path, sensor_name, get_temp, get_crit);
    }
    g_dir_close(sensorsDirectory);
}
Exemplo n.º 10
0
gboolean battery_os_init()
{
    GDir *directory = 0;
    GError *error = NULL;
    const char *entryname;

    battery_os_free();

    gchar *dir_path = g_build_filename(battery_sys_prefix, "/sys/class/power_supply", NULL);
    directory = g_dir_open(dir_path, 0, &error);
    g_free(dir_path);
    RETURN_ON_ERROR(error);

    while ((entryname = g_dir_read_name(directory))) {
        fprintf(stderr, GREEN "tint2: Found power device %s" RESET "\n", entryname);
        enum psy_type type = power_supply_get_type(entryname);

        switch (type) {
        case PSY_BATTERY:
            add_battery(entryname);
            break;
        case PSY_MAINS:
            add_mains(entryname);
            break;
        default:
            break;
        }
    }

    g_dir_close(directory);

    uevent_register_notifier(&psy_change);
    uevent_register_notifier(&psy_plug);

    return batteries != NULL;
}
Exemplo n.º 11
0
static void
query_dir (const char *dirname)
{
  GString *data;
  GDir *dir;
  const char *name;
  char *cachename;
  char **(* query)  (void);
  GError *error;
  int i;

  if (!g_module_supported ())
    return;

  error = NULL;
  dir = g_dir_open (dirname, 0, &error);
  if (!dir)
    {
      g_printerr ("Unable to open directory %s: %s\n", dirname, error->message);
      g_error_free (error);
      return;
    }

  data = g_string_new ("");

  while ((name = g_dir_read_name (dir)))
    {
      GModule *module;
      gchar     *path;
      char **extension_points;

      if (!is_valid_module_name (name))
	continue;

      path = g_build_filename (dirname, name, NULL);
      module = g_module_open (path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
      g_free (path);

      if (module)
	{
	  g_module_symbol (module, "g_io_module_query", (gpointer) &query);

	  if (query)
	    {
	      extension_points = query ();

	      if (extension_points)
		{
		  g_string_append_printf (data, "%s: ", name);

		  for (i = 0; extension_points[i] != NULL; i++)
		    g_string_append_printf (data, "%s%s", i == 0 ? "" : ",", extension_points[i]);

		  g_string_append (data, "\n");
		  g_strfreev (extension_points);
		}
	    }

	  g_module_close (module);
	}
    }

  g_dir_close (dir);

  cachename = g_build_filename (dirname, "giomodule.cache", NULL);

  if (data->len > 0)
    {
      error = NULL;

      if (!g_file_set_contents (cachename, data->str, data->len, &error))
        {
          g_printerr ("Unable to create %s: %s\n", cachename, error->message);
          g_error_free (error);
        }
    }
  else
    {
      if (g_unlink (cachename) != 0 && errno != ENOENT)
        g_printerr ("Unable to unlink %s: %s\n", cachename, g_strerror (errno));
    }

  g_string_free (data, TRUE);
}
static void
populate_store (GtkListStore *store,
		const gchar *path)
{
  GDir *dir;
  GError *error = NULL;
  gchar *item;
  GtkTreeIter iter;
  struct stat stat_info;
  GdkPixbuf *pixbuf = NULL;
  GtkWidget *dummy;

  dir = g_dir_open (path, 0, &error);
  if (error)
    {
      g_debug ("Error populating store: %s", error->message);
      g_error_free (error);
      return;
    }

  /* Dummy widget for gtk_widget_render_icon */
  dummy = gtk_label_new ("");

  while ((item = (gchar*)g_dir_read_name (dir)) != NULL)
    {
      gchar *file_path = g_strconcat (path, "/", item, NULL);

      if (stat (file_path, &stat_info) == -1)
	{
	  g_debug ("error retrieving stat info for %s", item);
	  continue;
	}
      g_free (file_path);

      gtk_list_store_append (store, &iter);

      if (S_ISDIR (stat_info.st_mode))
        {
          pixbuf = gtk_widget_render_icon (dummy, GTK_STOCK_DIRECTORY,
                                           GTK_ICON_SIZE_BUTTON, NULL);
        }
      else
        {
          pixbuf = gtk_widget_render_icon (dummy, GTK_STOCK_FILE,
                                           GTK_ICON_SIZE_BUTTON, NULL);
        }

      gtk_list_store_set (store, &iter,
			  ICON_COL, pixbuf,
			  STRING_COL, item,
			  IS_DIR_COL, S_ISDIR (stat_info.st_mode) ? TRUE : FALSE,
			  -1);
      if (pixbuf)
	g_object_unref (pixbuf);
    }

  g_dir_close (dir);

  gtk_widget_destroy (dummy);

  return;
}
Exemplo n.º 13
0
/**
 * camel_provider_init:
 *
 * Initialize the Camel provider system by reading in the .urls
 * files in the provider directory and creating a hash table mapping
 * URLs to module names.
 *
 * A .urls file has the same initial prefix as the shared library it
 * correspond to, and consists of a series of lines containing the URL
 * protocols that that library handles.
 *
 * TODO: This should be pathed?
 * TODO: This should be plugin-d?
 **/
void
camel_provider_init (void)
{
	GDir *dir;
	const gchar *entry;
	gchar *p, *name, buf[80];
	CamelProviderModule *m;
	static gint loaded = 0;
	const gchar *provider_dir;

	provider_dir = g_getenv (EDS_CAMEL_PROVIDER_DIR);
	if (!provider_dir)
		provider_dir = CAMEL_PROVIDERDIR;

	g_once (&setup_once, provider_setup, NULL);

	if (loaded)
		return;

	loaded = 1;

	dir = g_dir_open (provider_dir, 0, NULL);
	if (!dir) {
		g_warning (
			"Could not open camel provider directory (%s): %s",
			provider_dir, g_strerror (errno));
		return;
	}

	while ((entry = g_dir_read_name (dir))) {
		FILE *fp;

		p = strrchr (entry, '.');
		if (!p || strcmp (p, ".urls") != 0)
			continue;

		name = g_strdup_printf ("%s/%s", provider_dir, entry);
		fp = g_fopen (name, "r");
		if (!fp) {
			g_warning (
				"Could not read provider info file %s: %s",
				name, g_strerror (errno));
			g_free (name);
			continue;
		}

		p = strrchr (name, '.');
		if (p)
			strcpy (p, "." G_MODULE_SUFFIX);

		m = g_malloc0 (sizeof (*m));
		m->path = name;

		while ((fgets (buf, sizeof (buf), fp))) {
			buf[sizeof (buf) - 1] = '\0';
			p = strchr (buf, '\n');
			if (p)
				*p = '\0';

			if (*buf) {
				gchar *protocol = g_strdup (buf);

				m->types = g_slist_prepend (m->types, protocol);
				g_hash_table_insert (module_table, protocol, m);
			}
		}

		fclose (fp);
	}

	g_dir_close (dir);
}
Exemplo n.º 14
0
/*
 * Initialize and run the language listing parser. This call must be
 * made only once, at program initialization, but after language_init().
 */
void
gimp_language_store_parser_init (void)
{
  GHashTable     *base_lang_list;
  gchar          *current_env;
  GDir           *locales_dir;
  GHashTableIter  lang_iter;
  gpointer        key;

  if (l10n_lang_list != NULL)
    {
      g_warning ("gimp_language_store_parser_init() must be run only once.");
      return;
    }

  current_env = g_strdup (g_getenv ("LANGUAGE"));

  l10n_lang_list = g_hash_table_new_full (g_str_hash, g_str_equal,
                                          (GDestroyNotify) g_free,
                                          (GDestroyNotify) g_free);
  all_lang_list = g_hash_table_new_full (g_str_hash, g_str_equal,
                                         (GDestroyNotify) g_free,
                                         (GDestroyNotify) g_free);
  base_lang_list = g_hash_table_new_full (g_str_hash, g_str_equal,
                                          (GDestroyNotify) g_free,
                                          (GDestroyNotify) g_free);

  /* Check all locales we have translations for. */
  locales_dir = g_dir_open (gimp_locale_directory (), 0, NULL);
  if (locales_dir)
    {
      const gchar *locale;

      while ((locale = g_dir_read_name (locales_dir)) != NULL)
        {
          gchar *filename = g_build_filename (gimp_locale_directory (),
                                              locale,
                                              "LC_MESSAGES",
                                              GETTEXT_PACKAGE ".mo",
                                              NULL);
          if (g_file_test (filename, G_FILE_TEST_EXISTS))
            {
              gchar *delimiter = NULL;
              gchar *base_code = NULL;

              delimiter = strchr (locale, '_');

              if (delimiter)
                base_code = g_strndup (locale, delimiter - locale);
              else
                base_code = g_strdup (locale);

              delimiter = strchr (base_code, '@');

              if (delimiter)
                {
                  gchar *temp = base_code;
                  base_code = g_strndup (base_code, delimiter - base_code);
                  g_free (temp);
                }

              /* Save the full language code. */
              g_hash_table_insert (l10n_lang_list, g_strdup (locale), NULL);
              /* Save the base language code. */
              g_hash_table_insert (base_lang_list, base_code, NULL);
            }

          g_free (filename);
        }

      g_dir_close (locales_dir);
    }

  /* Parse ISO-639 file to get full list of language and their names. */
  parse_iso_codes (base_lang_list, NULL);

  /* Generate the localized language names. */
  g_hash_table_iter_init (&lang_iter, l10n_lang_list);
  while (g_hash_table_iter_next (&lang_iter, &key, NULL))
    {
      gchar *code           = (gchar*) key;
      gchar *localized_name = NULL;
      gchar *english_name   = NULL;
      gchar *delimiter      = NULL;
      gchar *base_code      = NULL;

      delimiter = strchr (code, '_');

      if (delimiter)
        base_code = g_strndup (code, delimiter - code);
      else
        base_code = g_strdup (code);

      delimiter = strchr (base_code, '@');

      if (delimiter)
        {
          gchar *temp = base_code;
          base_code = g_strndup (base_code, delimiter - base_code);
          g_free (temp);
        }

      english_name = (gchar*) (g_hash_table_lookup (base_lang_list, base_code));

      if (english_name)
        {
          gchar *semicolon;

          /* If possible, we want to localize a language in itself.
           * If it fails, gettext fallbacks to C (en_US) itself.
           */
          g_setenv ("LANGUAGE", code, TRUE);
          setlocale (LC_ALL, "");

          localized_name = g_strdup (dgettext ("iso_639", english_name));

          /* If original and localized names are the same for other than English,
           * maybe localization failed. Try now in the main dialect. */
          if (g_strcmp0 (english_name, localized_name) == 0 &&
              g_strcmp0 (base_code, "en") != 0 &&
              g_strcmp0 (code, base_code) != 0)
            {
              g_free (localized_name);

              g_setenv ("LANGUAGE", base_code, TRUE);
              setlocale (LC_ALL, "");

              localized_name = g_strdup (dgettext ("iso_639", english_name));
            }

          /*  there might be several language names; use the first one  */
          semicolon = strchr (localized_name, ';');

          if (semicolon)
            {
              gchar *temp = localized_name;
              localized_name = g_strndup (localized_name, semicolon - localized_name);
              g_free (temp);
            }
        }

      g_hash_table_replace (l10n_lang_list, g_strdup(code),
                            g_strdup_printf ("%s [%s]",
                                             localized_name ?
                                             localized_name : "???",
                                             code));
      g_free (localized_name);
      g_free (base_code);
    }

  /*  Add special entries for system locale.
   *  We want the system locale to be localized in itself. */
  g_setenv ("LANGUAGE", setlocale (LC_ALL, NULL), TRUE);
  setlocale (LC_ALL, "");

  /* g_str_hash() does not accept NULL. I give an empty code instead.
   * Other solution would to create a custom hash. */
  g_hash_table_insert (l10n_lang_list, g_strdup(""),
                       g_strdup (_("System Language")));

  /* Go back to original localization. */
  if (current_env)
    {
      g_setenv ("LANGUAGE", current_env, TRUE);
      g_free (current_env);
    }
  else
    g_unsetenv ("LANGUAGE");
  setlocale (LC_ALL, "");

  /* Add special entry for C (en_US). */
  g_hash_table_insert (l10n_lang_list, g_strdup ("en_US"),
                       g_strdup ("English [en_US]"));

  g_hash_table_destroy (base_lang_list);
}
int
main (int argc, char **argv)
{
  GList *v;
  GDir *dir;
  gchar *text;
  const gchar *filename;
  ClutterActor *stage, *label;
  gint x, y, n, cols, rows, width, height;

  GList *views = NULL;
  GError *error = NULL;

  clutter_init (&argc, &argv);
  
  /* This is a *massive* hack just to demonstrate live previews. Please don't
   * ever do this, use IPC to coordinate doing this cleanly with
   * clutter_mozembed_new_view() and clutter_mozembed_connect_view()
   */
  dir = g_dir_open (g_get_tmp_dir (), 0, &error);
  
  if (!dir)
    {
      g_warning ("Error opening temporary files directory: %s", error->message);
      g_error_free (error);
    }
  else
    {
      while ((filename = g_dir_read_name (dir)))
        {
          gint fd;
          ClutterActor *mozembed;
          gchar *full_file, *input, *output, *command;

          if (!strstr (filename, "clutter-mozheadless-"))
            continue;
          
          full_file = g_build_filename (g_get_tmp_dir (), filename, NULL);

          /* I've *no* idea what happens when two processes are writing on the
           * same pipe in terms of the possibility of interleaved messages...
           */
          
          /* Open the pipe and ask it to create a new view */
          fd = open (full_file, O_WRONLY | O_NDELAY);
          
          if (fd)
            {
              mozembed = clutter_mozembed_new_view ();

              /* Get the pipe names */
              g_object_get (G_OBJECT (mozembed),
                            "input", &input,
                            "output", &output,
                            NULL);

              /* You should NEVER do this, you need to use IPC to tell the
               * parent application to connect the view with
               * clutter_mozembed_connect_view()
               */
              command = g_strdup_printf ("new-view %s %s", input, output);
              write (fd, command, strlen (command) + 1);
              g_free (command);

              close (fd);
              g_free (input);
              g_free (output);

              views = g_list_append (views, mozembed);
            }

          g_free (full_file);
        }
      g_dir_close (dir);
    }

  /* Now put all the views on a stage */
  stage = clutter_stage_get_default ();
  clutter_actor_set_size (stage, 800, 600);

  n = g_list_length (views);
  text = g_strdup_printf ("%d live previews:", n);
  label = clutter_text_new_with_text ("Sans 20px", text);
  
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
  clutter_actor_set_position (label, 10, 10);
  
  x = y = 0;
  rows = MAX (1, (gint)sqrt ((gdouble)n));
  cols = MAX (1, n / rows);
  width = (clutter_actor_get_width (stage) - 20) / cols;
  height = (clutter_actor_get_height (stage) - 60) / rows;
  for (v = views; v; v = v->next)
    {
      ClutterActor *mozembed = CLUTTER_ACTOR (v->data);
      clutter_container_add_actor (CLUTTER_CONTAINER (stage), mozembed);
      clutter_actor_set_position (mozembed, (x*width) + 10, (y*height) + 40);
      clutter_actor_set_size (mozembed, width, height);
      
      x++;
      if (x > cols)
        {
          x = 0;
          y++;
        }
    }
  g_list_free (views);
  
  clutter_actor_show_all (stage);
  
  clutter_main ();
  
  clutter_actor_destroy (stage);
  
  return 0;
}
static gboolean build_gnutls_ca_and_crl_lists(GIOSchedulerJob *job,
			GCancellable *cancellable, gpointer user_data)
{
	HevImpathyTLSVerifier *self = HEV_IMPATHY_TLS_VERIFIER(user_data);
	HevImpathyTLSVerifierPrivate *priv =
		HEV_IMPATHY_TLS_VERIFIER_GET_PRIVATE(self);
	gint idx = 0;
	gchar *user_certs_dir = NULL;
	GDir *dir = NULL;
	GError *error = NULL;

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	priv->trusted_ca_list = g_ptr_array_new_with_free_func(
				(GDestroyNotify)gnutls_x509_crt_deinit);

	for(idx=0; idx<(gint)G_N_ELEMENTS(system_ca_paths)-1; idx++)
	{
		const gchar *path = NULL;
		gchar *contents = NULL;
		gsize length = 0;
		gint res = 0, n_certs = 0;
		gnutls_x509_crt_t *cert_list = NULL;
		gnutls_datum_t datum = { NULL, 0 };
		gnutls_x509_crt_fmt_t format = 0;

		path = system_ca_paths[idx];
		g_file_get_contents(path, &contents, &length, &error);

		if(NULL != error)
		{
			g_clear_error(&error);
			continue;
		}

		datum.data = (guchar *)contents;
		datum.size = length;
		n_certs = get_number_and_type_of_certificates(&datum, &format);

		if(0 > n_certs)
		{
			g_free(contents);
			continue;
		}

		cert_list = g_malloc0(sizeof(gnutls_x509_crt_t) * n_certs);
		res = gnutls_x509_crt_list_import(cert_list, (guint *)&n_certs,
					&datum, format, 0);

		if(0 > res)
		{
			g_free(contents);
			continue;
		}

		for(idx=0; idx<n_certs; idx++)
		  g_ptr_array_add(priv->trusted_ca_list, cert_list[idx]);

		g_free(contents);
		g_free(cert_list);
	}

	/* user certs */
	user_certs_dir = g_build_filename(g_get_user_config_dir(),
				"telepathy", "certs", NULL);
	dir = g_dir_open(user_certs_dir, 0, &error);

	if(NULL == error)
	{
		const gchar *cert_name = NULL;

		while(NULL != (cert_name=g_dir_read_name(dir)))
		{
			gchar *contents = NULL, *cert_path = NULL;
			gsize length = 0;
			gint res = 0;
			gnutls_datum_t datum = { NULL, 0 };
			gnutls_x509_crt_t cert = 0;

			cert_path = g_build_filename(user_certs_dir, cert_name, NULL);

			g_file_get_contents(cert_path, &contents, &length, &error);
			if(NULL != error)
			{
				g_clear_error(&error);
				g_free(cert_path);
				continue;
			}

			datum.data = (guchar *)contents;
			datum.size = length;

			gnutls_x509_crt_init(&cert);
			res = gnutls_x509_crt_import(cert, &datum,
						GNUTLS_X509_FMT_PEM);
			if(GNUTLS_E_SUCCESS == res)
			  g_ptr_array_add(priv->trusted_ca_list, cert);

			g_free(contents);
			g_free(cert_path);
		}

		g_dir_close(dir);
	}
	else
	{
		g_error_free(error);
	}

	g_free(user_certs_dir);

	g_io_scheduler_job_send_to_mainloop_async(job,
				start_verification, self, NULL);

	return FALSE;
}
Exemplo n.º 17
0
static void
display_files(GooCanvasItem *root_item, gchar *rootdir)
{
  GooCanvasItem *item;
  const gchar *one_dirent;
  GDir  *dir;

  /* Initial image position */
  guint ix  = 0.0;
  guint iy  = 30.0;

  GtkWidget	  *w;
  GooCanvasItem *bg_item;

  GtkWidget *canvas; /* The scrolled part */

  GList  *dir_list  = NULL;
  GList  *file_list = NULL;
  GList  *listrunner;

  GtkAdjustment *adj;

  if(!rootitem)
    return;

  /* Display the directory content */
  dir = g_dir_open(rootdir, 0, NULL);

  if (!dir) {
    g_warning("gcompris_file_selector : no root directory found in %s", rootdir);
    g_free(rootdir);
    return;
  }

  /* Delete the previous file root if any */
  if(file_root_item)
    goo_canvas_item_remove(file_root_item);

  /* Create a root item to put the image list in it */
  file_root_item = goo_canvas_group_new (root_item, NULL);

  /*
   * Create the scrollbar
   * --------------------
   */
  canvas = goo_canvas_new();

  goo_canvas_widget_new (file_root_item,
			 canvas,
			 DRAWING_AREA_X1,
			 DRAWING_AREA_Y1,
			 DRAWING_AREA_X2 - DRAWING_AREA_X1 - 20.0,
			 DRAWING_AREA_Y2 - DRAWING_AREA_Y1 - 35.0,
			 NULL);

  gtk_widget_show (canvas);

  /* Set the new canvas to the background color or it's white */
  bg_item = goo_canvas_rect_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)),
				 0,
				 0,
				 DRAWING_AREA_X2 - DRAWING_AREA_X1 + 200,
				 DRAWING_AREA_Y2 - DRAWING_AREA_Y1,
				 "fill-color-rgba", gc_skin_get_color("gcompris/fileselectbg"),
				 "line-width", 0.0,
				 NULL);


  adj = \
    GTK_ADJUSTMENT (gtk_adjustment_new (0.00, 0.00,
					IMAGE_HEIGHT,
					10, IMAGE_HEIGHT,
					(DRAWING_AREA_Y2 - DRAWING_AREA_Y1)/3)
		    );
  w = gtk_vscrollbar_new (adj);

  goo_canvas_widget_new (file_root_item,
			 w,
			 DRAWING_AREA_X2 - 15.0,
			 DRAWING_AREA_Y1,
			 30.0,
			 DRAWING_AREA_Y2 - DRAWING_AREA_Y1 - 20.0,
			 NULL);
  gtk_widget_show (w);

  /* Set the scrollwheel event */
  g_signal_connect (adj, "value_changed",
		    (GtkSignalFunc) item_event_scroll,
		    canvas);

  /* Display the directory name
   * --------------------------
   */

  item = goo_canvas_text_new (file_root_item,
			      rootdir,
			      (gdouble)control_area_x1,
			      (gdouble)directory_label_y,
			      -1,
			      GTK_ANCHOR_NW,
			      "font", "Sans 7",
			      "fill-color-rgba",
			      gc_skin_get_color("gcompris/fileselectcol"),
			      NULL);

  /* Insert all files in a sorted list */

  while((one_dirent = g_dir_read_name(dir)) != NULL)
    {
      gchar *filename;

      filename = g_strdup_printf("%s/%s",
				 rootdir, (gchar*)(one_dirent));

      if(g_file_test(filename, G_FILE_TEST_IS_DIR))
	{
	  dir_list = g_list_insert_sorted(dir_list, filename,
					  (GCompareFunc)strcmp);
	}
      else
	{
	  file_list = g_list_insert_sorted(file_list, filename,
					   (GCompareFunc)strcmp);
	}
    }

  /* Concat the directory list and file list */
  file_list = g_list_concat(dir_list, file_list);

  g_list_free(dir_list);
  dir_list = NULL;

  /* We have the list sorted, now display it */
  listrunner = g_list_first(file_list);
  while(listrunner)
    {
      /* add the file to the display */
      gchar *svg_id;

      gchar *allfilename = listrunner->data;
      gchar *filename    = g_path_get_basename(allfilename);
      gchar *ext = g_strrstr(filename, ".");
      gchar *file_wo_ext = g_strdup(filename);

      if(ext)
	{
	  gchar *ext2 = g_strrstr(file_wo_ext, ".");
	  *ext2 = '\0';
	}

      if(g_file_test(allfilename, G_FILE_TEST_IS_DIR))
	svg_id = "#FOLDER";
      else
	svg_id = "#FILE";

      item = goo_canvas_svg_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)),
				 gc_skin_rsvg_get(),
				 "svg-id", svg_id,
				 NULL);

      SET_ITEM_LOCATION_CENTER(item,
			       ix + (IMAGE_WIDTH + IMAGE_GAP)/2,
			       iy);

      if(g_file_test(allfilename, G_FILE_TEST_IS_DIR))
	{
	  g_signal_connect(item, "button_press_event",
			   (GtkSignalFunc) item_event_directory,
			   allfilename);
	}
      else
	{
	  g_signal_connect(item, "button_press_event",
			   (GtkSignalFunc) item_event_file_selector,
			   allfilename);
	}
      gc_item_focus_init(item, NULL);

      g_object_set_data_full (G_OBJECT (item),
			      "allfilename", allfilename, g_free);
      /* The type */
      if(ext)
	{
	  GooCanvasItem *_item = \
	    goo_canvas_text_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)),
				 ext,
				 ix + (IMAGE_WIDTH + IMAGE_GAP)/2,
				 iy + 10,
				 -1,
				 GTK_ANCHOR_CENTER,
				 "font", "Sans 6",
				 "fill-color-rgba",
				 gc_skin_get_color("gcompris/fileselectcol"),
				 NULL);
	  g_signal_connect(_item, "button_press_event",
			   (GtkSignalFunc) item_event_file_selector,
			   allfilename);
	  gc_item_focus_init(_item, item);
	}

      /* The filename */
      GooCanvasItem *name_item = \
	goo_canvas_text_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)),
			     file_wo_ext,
			     ix + (IMAGE_WIDTH + IMAGE_GAP)/2,
			     iy + IMAGE_HEIGHT - 30,
			     -1,
			     GTK_ANCHOR_CENTER,
			     "font", "Sans 7",
			     "fill-color-rgba", gc_skin_get_color("gcompris/fileselectcol"),
			     NULL);
      g_free(file_wo_ext);
      g_free(filename);

      if(g_file_test(allfilename, G_FILE_TEST_IS_DIR))
	{
	  g_signal_connect(name_item, "button_press_event",
			   (GtkSignalFunc) item_event_directory,
			   allfilename);
	}
      else
	{
	  g_signal_connect(name_item, "button_press_event",
			   (GtkSignalFunc) item_event_file_selector,
			   allfilename);
	}
      gc_item_focus_init(name_item, item);

      ix += IMAGE_WIDTH + IMAGE_GAP;

      if(ix >= DRAWING_AREA_X2 - DRAWING_AREA_X1 -
	 (IMAGE_WIDTH + IMAGE_GAP) )
	{
	  ix=0;

	  iy+=IMAGE_HEIGHT + IMAGE_GAP;

	  goo_canvas_set_bounds (GOO_CANVAS(canvas),
				 0, 0,
				 DRAWING_AREA_X2- DRAWING_AREA_X1,
				 iy + IMAGE_HEIGHT + IMAGE_GAP);

	  if(iy >= DRAWING_AREA_Y2-DRAWING_AREA_Y1)
	    {
	      g_object_set(bg_item,
			   "height", (double)iy + IMAGE_HEIGHT + IMAGE_GAP,
			   NULL);
	      g_object_set(adj,
			   "upper", (double)iy - IMAGE_HEIGHT + IMAGE_GAP - 1,
			   NULL);
	    }
	}
      listrunner = g_list_next(listrunner);
    }

  g_dir_close(dir);
  g_list_free(file_list);

}
Exemplo n.º 18
0
static gboolean
as_app_builder_search_locale_gettext (AsAppBuilderContext *ctx,
				      const gchar *locale,
				      const gchar *messages_path,
				      AsAppBuilderFlags flags,
				      GError **error)
{
	const gchar *filename;
	gboolean found_anything = FALSE;
	guint i;
	g_autoptr(GDir) dir = NULL;
	g_autoptr(GPtrArray) mo_paths = NULL;

	/* list files */
	dir = g_dir_open (messages_path, 0, error);
	if (dir == NULL)
		return FALSE;

	/* do a first pass at this, trying to find the prefered .mo */
	mo_paths = g_ptr_array_new_with_free_func (g_free);
	while ((filename = g_dir_read_name (dir)) != NULL) {
		g_autofree gchar *path = NULL;
		path = g_build_filename (messages_path, filename, NULL);
		if (!g_file_test (path, G_FILE_TEST_EXISTS))
			continue;
		for (i = 0; i < ctx->translations->len; i++) {
			AsTranslation *t = g_ptr_array_index (ctx->translations, i);
			g_autofree gchar *fn = NULL;
			if (as_translation_get_kind (t) != AS_TRANSLATION_KIND_GETTEXT &&
			    as_translation_get_kind (t) != AS_TRANSLATION_KIND_UNKNOWN)
				continue;
			fn = g_strdup_printf ("%s.mo", as_translation_get_id (t));
			if (g_strcmp0 (filename, fn) == 0) {
				if (!as_app_builder_parse_file_gettext (ctx,
									locale,
									path,
									error))
					return FALSE;
				found_anything = TRUE;
			}
		}
		g_ptr_array_add (mo_paths, g_strdup (path));
	}

	/* we got data from one or more of the translations */
	if (found_anything == TRUE)
		return TRUE;

	/* fall back to parsing *everything*, which might give us more
	 * language results than is actually true */
	if (flags & AS_APP_BUILDER_FLAG_USE_FALLBACKS) {
		for (i = 0; i < mo_paths->len; i++) {
			filename = g_ptr_array_index (mo_paths, i);
			if (!as_app_builder_parse_file_gettext (ctx,
								locale,
								filename,
								error))
				return FALSE;
		}
	}

	return TRUE;
}
Exemplo n.º 19
0
int
main (int argc, char **argv)
{
  gboolean byteswap = G_BYTE_ORDER != G_LITTLE_ENDIAN;
  GError *error;
  GHashTable *table;
  GDir *dir;
  const gchar *file;
  gchar *srcdir;
  gchar *targetdir = NULL;
  gchar *target;
  gboolean uninstall = FALSE;
  gboolean dry_run = FALSE;
  gchar **schema_files = NULL;
  GOptionContext *context;
  GOptionEntry entries[] = {
    { "targetdir", 0, 0, G_OPTION_ARG_FILENAME, &targetdir, N_("where to store the gschemas.compiled file"), N_("DIRECTORY") },
    { "dry-run", 0, 0, G_OPTION_ARG_NONE, &dry_run, N_("Do not write the gschema.compiled file"), NULL },
    { "uninstall", 0, 0, G_OPTION_ARG_NONE, &uninstall, N_("Do not give error for empty directory"), NULL },
    { "allow-any-name", 0, 0, G_OPTION_ARG_NONE, &allow_any_name, N_("Do not enforce key name restrictions") },

    /* These options are only for use in the gschema-compile tests */
    { "schema-file", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME_ARRAY, &schema_files, NULL, NULL },
    { NULL }
  };

  setlocale (LC_ALL, "");

  context = g_option_context_new (N_("DIRECTORY"));
  g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
  g_option_context_set_summary (context,
    N_("Compile all GSettings schema files into a schema cache.\n"
       "Schema files are required to have the extension .gschema.xml,\n"
       "and the cache file is called gschemas.compiled."));
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);

  error = NULL;
  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      fprintf (stderr, "%s", error->message);
      return 1;
    }

  g_option_context_free (context);

  if (!schema_files && argc != 2)
    {
      fprintf (stderr, _("You should give exactly one directory name\n"));
      return 1;
    }

  srcdir = argv[1];

  if (targetdir == NULL)
    targetdir = srcdir;

  target = g_build_filename (targetdir, "gschemas.compiled", NULL);

  if (!schema_files)
    {
      GPtrArray *files;

      files = g_ptr_array_new ();

      dir = g_dir_open (srcdir, 0, &error);
      if (dir == NULL)
        {
          fprintf (stderr, "%s\n", error->message);
          return 1;
        }

      while ((file = g_dir_read_name (dir)) != NULL)
        {
          if (g_str_has_suffix (file, ".gschema.xml"))
            g_ptr_array_add (files, g_build_filename (srcdir, file, NULL));
        }

      if (files->len == 0)
        {
          if (uninstall)
            {
              g_unlink (target);
              return 0;
            }
          else
            {
              fprintf (stderr, _("No schema files found\n"));
              return 1;
            }
        }
      g_ptr_array_add (files, NULL);

      schema_files = (char **) g_ptr_array_free (files, FALSE);
    }


  if (!(table = parse_gschema_files (schema_files, byteswap, &error)) ||
      (!dry_run && !gvdb_table_write_contents (table, target, byteswap, &error)))
    {
      fprintf (stderr, "%s\n", error->message);
      return 1;
    }

  g_free (target);

  return 0;
}
Exemplo n.º 20
0
sc_result sc_ext_initialize(const sc_char *ext_dir_path)
{
    GDir *ext_dir = nullptr;
    const gchar *file_name = 0;
    GModule *module = 0;
    gchar *module_path = 0;
    fModuleFunc func = 0;

    // doesn't need to initialize extensions
    if (ext_dir_path == nullptr)
        return SC_RESULT_OK;

    // check if modules supported on this platform
    if (g_module_supported() == FALSE)
    {
        g_warning("Modules not supported on this platform");
        return SC_RESULT_ERROR;
    }

    g_message("Initialize extensions from %s", ext_dir_path);

    // check if specified directory exist
    if (g_file_test(ext_dir_path, G_FILE_TEST_IS_DIR) == FALSE)
        return SC_RESULT_ERROR_INVALID_PARAMS;

    // get list of files in extension directory
    ext_dir = g_dir_open(ext_dir_path, 0, 0);
    if (ext_dir == nullptr)
        return SC_RESULT_ERROR;

    modules_table = g_hash_table_new(&g_str_hash, &modules_table_equal_func);

    // list all files in directory and try to load them
    file_name = g_dir_read_name(ext_dir);
    while (file_name != nullptr)
    {
        // build module path
        module_path = g_module_build_path(ext_dir_path, file_name);

        // open module
        module = g_module_open(module_path, G_MODULE_BIND_LOCAL);

        // skip non module files
        if (g_str_has_suffix(file_name, G_MODULE_SUFFIX) == TRUE)
        {

            if (module == nullptr)
            {
                g_warning("Can't load module: %s. Error: %s", file_name, g_module_error());
            }else
            {
                g_message("Initialize module: %s", file_name);
                if (g_module_symbol(module, "initialize", (gpointer*) &func) == FALSE)
                {
                    g_warning("Can't find 'initialize' symbol in module: %s", file_name);
                }else
                {
                    if (func() != SC_RESULT_OK)
                    {
                        g_warning("Something happends, on module initialization: %s", file_name);
                    }
                }

                g_hash_table_insert(modules_table, module_path, (gpointer)module);
            }
        }

        file_name = g_dir_read_name(ext_dir);
    }

    g_dir_close(ext_dir);

    return SC_RESULT_OK;
}
Exemplo n.º 21
0
static void
blog_plugin_init_dir (const gchar *realpath)
{
  GDir *dir;
  GModule *mod;
  const gchar *name;
  gchar *modpath;
  blog_plugin_t *plg;
  const gchar * (*modname) ();
  GList *cur;

  dir = g_dir_open (realpath, 0600, NULL);
  if (dir == NULL)
    {
      return;
    }

  while ((name = g_dir_read_name (dir)) != NULL)
    {
      if (*name == '.')
        {
          continue;
        }

#ifdef WIN32
      if (g_ascii_strcasecmp (name + strlen (name) - 4, ".dll") != 0)
#else
      if (g_ascii_strcasecmp (name + strlen (name) - 3, ".so") != 0)
#endif
        {
          continue;
        }

      modpath = g_build_filename (realpath, name, NULL);
      if (modpath == NULL)
        {
          continue;
        }

      mod = g_module_open (modpath, G_MODULE_BIND_MASK);
      g_free (modpath);
      if (mod == NULL)
        {
          g_error (g_module_error ());
          continue;
        }

      g_module_symbol (mod, "module_name", (gpointer) &modname);
      if (modname == NULL)
        {
          g_error (g_module_error ());
          continue;
        }

      for (cur = blog_plugin_list;
           cur != NULL;
           cur = g_list_next (cur)
      )
        {
          plg = cur->data;
          if (plg 
              && plg->name 
              && strcmp (plg->name (), modname ()) == 0)
            {
              break;
            }
        }

      if (cur)
        {
          g_module_close (mod);
          continue;
        }

      plg = g_malloc (sizeof (blog_plugin_t));
      if (plg == NULL)
        {
          g_error (_ ("Memory error.\n"));
          g_module_close (mod);
          continue;
        } 

      g_module_symbol (mod, "module_name", (gpointer) &plg->name);
      g_module_symbol (mod, "module_version", (gpointer) &plg->version);
      g_module_symbol (mod, "module_init", (gpointer) &plg->init);
      g_module_symbol (mod, "module_destroy", (gpointer) &plg->destroy);
      g_module_symbol (mod, "blog_add_widget", (gpointer) &plg->add_widget);
      g_module_symbol (mod, "blog_add", (gpointer) &plg->add);
      g_module_symbol (mod, "blog_pub", (gpointer) &plg->pub);

      if (plg->init () == FALSE)
        {
          g_error (_ ("Module '%s' init failed.\n"), name);
          g_module_close (mod);
          g_free (plg);
        }

      blog_plugin_list = g_list_append (blog_plugin_list, plg);
    }

  g_dir_close (dir);
}
Exemplo n.º 22
0
/**
 * 
 * 
 * @param path_list A GList of gchar*.
 * @param prefix The prefix of the filename, cannot be #NULL.
 * @param suffix The suffix of filename. If #match_prefix is #TRUE, #NULL or
 *               empty string means any suffix is acceptable.
 * @param match_prefix 
 * 
 * @return 
 */
static gchar *
_find_file_in_path_list (GList *path_list,
                         const gchar *prefix,
                         const gchar *suffix,
                         gboolean match_prefix,
                         gboolean (*file_test_func) (const gchar *))
{
  ol_assert_ret (prefix != NULL, NULL);
  if (suffix == NULL)
    suffix = "";
  if (!file_test_func)
    file_test_func = _file_exists;
  GList *pathiter;
  gchar *ret = NULL;
  for (pathiter = path_list; pathiter != NULL; pathiter = g_list_next (pathiter))
  {
    gchar *path = pathiter->data;
    if (!match_prefix)
    {
      gchar *filename = NULL;
      gchar *fullname = g_strdup_printf ("%s%s", prefix, suffix);
      filename = g_build_filename (path, fullname, NULL);
      g_free (fullname);
      if (file_test_func (filename))
        ret = filename;
      else
        g_free (filename);
    } /* if !match_prefix */
    else
    {
      GError *error = NULL;
      GDir *dir = g_dir_open (path, 0, &error);
      if (!dir)
      {
        ol_errorf ("Cannot open path %s: %s\n", path, error->message);
        g_error_free (error);
        continue;
      }
      const gchar *name;
      while ((name = g_dir_read_name (dir)) != NULL)
      {
        if (g_str_has_prefix (name, prefix) && g_str_has_suffix (name, suffix))
        {
          gchar *filename = g_build_filename (path, name, NULL);
          if (file_test_func (filename) &&
              (!ret || strcmp (filename, ret) < 0))
          {
            g_free (ret);
            ret = filename;
          }
          else
          {
            g_free (filename);
          }
        }
      }
      g_dir_close (dir);
    }
    if (ret != NULL) break;
  }
  return ret;
}
Exemplo n.º 23
0
void gui_init(struct dt_iop_module_t *self)
{
  self->gui_data = malloc(sizeof(dt_iop_colorout_gui_data_t));
  memset(self->gui_data,0,sizeof(dt_iop_colorout_gui_data_t));
  dt_iop_colorout_gui_data_t *g = (dt_iop_colorout_gui_data_t *)self->gui_data;

  g->profiles = NULL;
  dt_iop_color_profile_t *prof = (dt_iop_color_profile_t *)g_malloc0(sizeof(dt_iop_color_profile_t));
  g_strlcpy(prof->filename, "sRGB", sizeof(prof->filename));
  g_strlcpy(prof->name, "sRGB", sizeof(prof->name));
  int pos;
  int display_pos;
  prof->pos = 0;
  prof->display_pos = 0;
  g->profiles = g_list_append(g->profiles, prof);

  prof = (dt_iop_color_profile_t *)g_malloc0(sizeof(dt_iop_color_profile_t));
  g_strlcpy(prof->filename, "adobergb", sizeof(prof->filename));
  g_strlcpy(prof->name, "adobergb", sizeof(prof->name));
  prof->pos = 1;
  prof->display_pos = 1;
  g->profiles = g_list_append(g->profiles, prof);

  prof = (dt_iop_color_profile_t *)g_malloc0(sizeof(dt_iop_color_profile_t));
  g_strlcpy(prof->filename, "X profile", sizeof(prof->filename));
  g_strlcpy(prof->name, "X profile", sizeof(prof->name));
  prof->pos = -1;
  prof->display_pos = 2;
  g->profiles = g_list_append(g->profiles, prof);

  prof = (dt_iop_color_profile_t *)g_malloc0(sizeof(dt_iop_color_profile_t));
  g_strlcpy(prof->filename, "linear_rgb", sizeof(prof->filename));
  g_strlcpy(prof->name, "linear_rgb", sizeof(prof->name));
  pos = prof->pos = 2;
  display_pos = prof->display_pos = 3;
  g->profiles = g_list_append(g->profiles, prof);

  // read {conf,data}dir/color/out/*.icc
  char datadir[DT_MAX_PATH_LEN];
  char confdir[DT_MAX_PATH_LEN];
  char dirname[DT_MAX_PATH_LEN];
  char filename[DT_MAX_PATH_LEN];
  dt_loc_get_user_config_dir(confdir, DT_MAX_PATH_LEN);
  dt_loc_get_datadir(datadir, DT_MAX_PATH_LEN);
  snprintf(dirname, DT_MAX_PATH_LEN, "%s/color/out", confdir);
  if(!g_file_test(dirname, G_FILE_TEST_IS_DIR))
    snprintf(dirname, DT_MAX_PATH_LEN, "%s/color/out", datadir);
  cmsHPROFILE tmpprof;
  const gchar *d_name;
  GDir *dir = g_dir_open(dirname, 0, NULL);
  if(dir)
  {
    while((d_name = g_dir_read_name(dir)))
    {
      snprintf(filename, DT_MAX_PATH_LEN, "%s/%s", dirname, d_name);
      tmpprof = cmsOpenProfileFromFile(filename, "r");
      if(tmpprof)
      {
        char *lang = getenv("LANG");
        if (!lang) lang = "en_US";

        dt_iop_color_profile_t *prof = (dt_iop_color_profile_t *)g_malloc0(sizeof(dt_iop_color_profile_t));
        char name[1024];
        cmsGetProfileInfoASCII(tmpprof, cmsInfoDescription, lang, lang+3, name, 1024);
        g_strlcpy(prof->name, name, sizeof(prof->name));
        g_strlcpy(prof->filename, d_name, sizeof(prof->filename));
        prof->pos = ++pos;
        prof->display_pos = ++display_pos;
        cmsCloseProfile(tmpprof);
        g->profiles = g_list_append(g->profiles, prof);
      }
    }
    g_dir_close(dir);
  }

  self->widget = gtk_vbox_new(TRUE, DT_BAUHAUS_SPACE);

  // TODO:
  g->cbox1 = dt_bauhaus_combobox_new(self);
  gtk_box_pack_start(GTK_BOX(self->widget), g->cbox1, TRUE, TRUE, 0);
  dt_bauhaus_widget_set_label(g->cbox1, _("output intent"));
  dt_bauhaus_combobox_add(g->cbox1, _("perceptual"));
  dt_bauhaus_combobox_add(g->cbox1, _("relative colorimetric"));
  dt_bauhaus_combobox_add(g->cbox1, C_("rendering intent", "saturation"));
  dt_bauhaus_combobox_add(g->cbox1, _("absolute colorimetric"));
  g->cbox4 = dt_bauhaus_combobox_new(self);
  dt_bauhaus_widget_set_label(g->cbox4, _("display intent"));
  gtk_box_pack_start(GTK_BOX(self->widget), g->cbox4, TRUE, TRUE, 0);
  dt_bauhaus_combobox_add(g->cbox4, _("perceptual"));
  dt_bauhaus_combobox_add(g->cbox4, _("relative colorimetric"));
  dt_bauhaus_combobox_add(g->cbox4, C_("rendering intent", "saturation"));
  dt_bauhaus_combobox_add(g->cbox4, _("absolute colorimetric"));
  g->cbox2 = dt_bauhaus_combobox_new(self);
  g->cbox3 = dt_bauhaus_combobox_new(self);
  g->cbox5 = dt_bauhaus_combobox_new(self);
  dt_bauhaus_widget_set_label(g->cbox2, _("output profile"));
  dt_bauhaus_widget_set_label(g->cbox5, _("softproof profile"));
  dt_bauhaus_widget_set_label(g->cbox3, _("display profile"));
  gtk_box_pack_start(GTK_BOX(self->widget), g->cbox2, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(self->widget), g->cbox5, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(self->widget), g->cbox3, TRUE, TRUE, 0);
  GList *l = g->profiles;
  while(l)
  {
    dt_iop_color_profile_t *prof = (dt_iop_color_profile_t *)l->data;
    if(!strcmp(prof->name, "X profile"))
    {
      // the system display profile is only suitable for display purposes
      dt_bauhaus_combobox_add(g->cbox3, _("system display profile"));
    }
    else if(!strcmp(prof->name, "linear_rgb"))
    {
      dt_bauhaus_combobox_add(g->cbox2, _("linear RGB"));
      dt_bauhaus_combobox_add(g->cbox3, _("linear RGB"));
      dt_bauhaus_combobox_add(g->cbox5, _("linear RGB"));
    }
    else if(!strcmp(prof->name, "sRGB"))
    {
      dt_bauhaus_combobox_add(g->cbox2, _("sRGB (web-safe)"));
      dt_bauhaus_combobox_add(g->cbox3, _("sRGB (web-safe)"));
      dt_bauhaus_combobox_add(g->cbox5, _("sRGB (web-safe)"));
    }
    else if(!strcmp(prof->name, "adobergb"))
    {
      dt_bauhaus_combobox_add(g->cbox2, _("Adobe RGB"));
      dt_bauhaus_combobox_add(g->cbox3, _("Adobe RGB"));
      dt_bauhaus_combobox_add(g->cbox5, _("Adobe RGB"));
    }
    else
    {
      dt_bauhaus_combobox_add(g->cbox2, prof->name);
      dt_bauhaus_combobox_add(g->cbox3, prof->name);
      dt_bauhaus_combobox_add(g->cbox5, prof->name);
    }
    l = g_list_next(l);
  }

  char tooltip[1024];
  g_object_set(G_OBJECT(g->cbox1), "tooltip-text", _("rendering intent"), (char *)NULL);
  snprintf(tooltip, 1024, _("icc profiles in %s/color/out or %s/color/out"), confdir, datadir);
  g_object_set(G_OBJECT(g->cbox2), "tooltip-text", tooltip, (char *)NULL);
  snprintf(tooltip, 1024, _("display icc profiles in %s/color/out or %s/color/out"), confdir, datadir);
  g_object_set(G_OBJECT(g->cbox3), "tooltip-text", tooltip, (char *)NULL);
  snprintf(tooltip, 1024, _("softproof icc profiles in %s/color/out or %s/color/out"), confdir, datadir);
  g_object_set(G_OBJECT(g->cbox5), "tooltip-text", tooltip, (char *)NULL);

  g_signal_connect (G_OBJECT (g->cbox1), "value-changed",
                    G_CALLBACK (intent_changed),
                    (gpointer)self);
  g_signal_connect (G_OBJECT (g->cbox4), "value-changed",
                    G_CALLBACK (display_intent_changed),
                    (gpointer)self);
  g_signal_connect (G_OBJECT (g->cbox2), "value-changed",
                    G_CALLBACK (output_profile_changed),
                    (gpointer)self);
  g_signal_connect (G_OBJECT (g->cbox3), "value-changed",
                    G_CALLBACK (display_profile_changed),
                    (gpointer)self);
  g_signal_connect (G_OBJECT (g->cbox5), "value-changed",
                    G_CALLBACK (softproof_profile_changed),
                    (gpointer)self);

  // reload the profiles when the display profile changed!
  dt_control_signal_connect(darktable.signals, DT_SIGNAL_CONTROL_PROFILE_CHANGED,
                            G_CALLBACK(_signal_profile_changed), self);
}
Exemplo n.º 24
0
int __near_plugin_init(const char *pattern, const char *exclude)
{
	gchar **patterns = NULL;
	gchar **excludes = NULL;
	GSList *list;
	GDir *dir;
	const gchar *file;
	gchar *filename;
	unsigned int i;

	DBG("");

	if (pattern)
		patterns = g_strsplit_set(pattern, ":, ", -1);

	if (exclude)
		excludes = g_strsplit_set(exclude, ":, ", -1);

	for (i = 0; __near_builtin[i]; i++) {
		if (!check_plugin(__near_builtin[i], patterns, excludes))
			continue;

		add_plugin(NULL, __near_builtin[i]);
	}

	dir = g_dir_open(PLUGINDIR, 0, NULL);
	if (dir) {
		while ((file = g_dir_read_name(dir))) {
			void *handle;
			struct near_plugin_desc *desc;

			if (g_str_has_prefix(file, "lib") ||
					!g_str_has_suffix(file, ".so"))
				continue;

			filename = g_build_filename(PLUGINDIR, file, NULL);

			handle = dlopen(filename, RTLD_NOW);
			if (!handle) {
				near_error("Can't load %s: %s",
							filename, dlerror());
				g_free(filename);
				continue;
			}

			g_free(filename);

			desc = dlsym(handle, "near_plugin_desc");
			if (!desc) {
				near_error("Can't load symbol: %s",
								dlerror());
				dlclose(handle);
				continue;
			}

			if (!check_plugin(desc, patterns, excludes)) {
				dlclose(handle);
				continue;
			}

			if (!add_plugin(handle, desc))
				dlclose(handle);
		}

		g_dir_close(dir);
	}

	for (list = plugins; list; list = list->next) {
		struct near_plugin *plugin = list->data;

		if (plugin->desc->init() < 0)
			continue;

		plugin->active = true;
	}

	g_strfreev(patterns);
	g_strfreev(excludes);

	return 0;
}
Exemplo n.º 25
0
void read_custom_files(void)
{
    gint i, n = 0;
    gchar *fullname;

    if (custom_directory == NULL)
        return;

    struct custom_data *d = g_malloc0(sizeof(struct custom_data));
    GDir *dir = g_dir_open(custom_directory, 0, NULL);

    GtkTextBuffer *msgbuf = message_window();
    show_msg(msgbuf, NULL, "Reading directory %s\n", custom_directory);

    if (dir) {
        db_create_blob_table();
        const gchar *fname = g_dir_read_name(dir);
        while (fname) {
            char *p = strstr(fname, ".txt");
            fullname = g_build_filename(custom_directory, fname, NULL);
            if (p && p[4] == 0) {
                LOG("\n---------- %s ------------", fname);
                show_msg(msgbuf, "bold", "Reading file %s\n", fname);

                char *msg = read_custom_category(fullname, d);
                if (msg) {
                    g_free(fullname);
                    fname = g_dir_read_name(dir);
                    show_msg(msgbuf, "red", "  %s\n", msg);
                    //show_message(msg);
                    continue;
                }
                guint hash = g_str_hash(d->name_short) << 5;
                db_delete_blob_line(hash);
                gint length;
                gchar *encoded = encode_custom_data(d, &length);
		if (length == 0)
		    show_msg(msgbuf, "red", "  Problem with encoding!\n");
                db_write_blob(hash, (void *)encoded, length);

                gchar buf[64];
                snprintf(buf, sizeof(buf) - 8, "%s", fname);
                p = strstr(buf, ".txt");
                if (p) *p = 0;
                else p = buf + strlen(buf);
                i = 1;
                while (1) {
                    sprintf(p, "-%d.svg", i);
                    gchar *svgname = g_build_filename(custom_directory, buf, NULL);
                    void *data = NULL;
                    gsize datalen;
                    GError *error = NULL;
                    gboolean ok = g_file_get_contents(svgname, (gchar **)&data, &datalen, &error);
                    if (!ok) {
                        if (i == 1) {
                            show_msg(msgbuf, "red", "  %s\n", error->message);
                            show_msg(msgbuf, NULL, "  Trying to read an example file\n");
                            sprintf(p, ".svg");
                            g_free(svgname);
                            svgname = g_build_filename(custom_directory, buf, NULL);
                            g_error_free(error);
                            error = NULL;
                            ok = g_file_get_contents(svgname, (gchar **)&data, &datalen, &error);
                            if (!ok) {
                                show_msg(msgbuf, "red", "  %s\n", error->message);
                                show_msg(msgbuf, NULL, "  Creating example file\n");
                                char *args[2] = {"", fullname};

                                // obtain the existing locale name for numbers    
                                char *old_locale = setlocale(LC_NUMERIC, NULL);
                                // set locale that uses points as decimal separator
                                setlocale(LC_NUMERIC, "en_US.UTF-8");
                                make_svg_file(2, args);
                                // set the locale back
                                setlocale(LC_NUMERIC, old_locale);

                                g_error_free(error);
                                error = NULL;
                                ok = g_file_get_contents(svgname, (gchar **)&data, &datalen, &error);
                                if (!ok) show_msg(msgbuf, "red", "  %s: %s\n", error->message);
                            }
                        }
                        if (error) g_error_free(error);
                        g_free(svgname);
                        svgname = NULL;
                        if (!ok) 
                            break;
                    }
                    g_free(svgname);
                    db_delete_blob_line(hash | i);
                    db_write_blob(hash | i, data, datalen);
                    g_free(data);
                    data = NULL;
                    i++;
                }
                show_msg(msgbuf, NULL, "  %d SVG pages found\n", i-1);
                n++;
            } // if
            g_free(fullname);
            fname = g_dir_read_name(dir);
        } // while fname

        g_dir_close(dir);
    } // if dir

    g_free(d);

    read_custom_from_db();
}
Exemplo n.º 26
0
/*! \todo Finish function description!!!
 *  \brief
 *  \par Function Description
 *
 *  \param [in] path  
 *  \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
 */
SCM g_rc_source_library_search(SCM path)
{
  gchar *string;
  char *temp;
  GDir *dir;
  const gchar *entry;
  
  SCM_ASSERT (scm_is_string (path), path,
              SCM_ARG1, "source-library-search");

  /* take care of any shell variables */
  temp = scm_to_utf8_string (path);
  string = s_expand_env_variables (temp);
  free (temp);

  /* invalid path? */
  if (!g_file_test (string, G_FILE_TEST_IS_DIR)) {
    fprintf (stderr,
             "Invalid path [%s] passed to source-library-search\n",
             string);
    g_free(string);
    return SCM_BOOL_F;
  }

  dir = g_dir_open (string, 0, NULL);
  if (dir == NULL) {
    fprintf (stderr,
             "Invalid path [%s] passed to source-library-search\n",
             string);
    g_free(string);
    return SCM_BOOL_F;
  }

  while ((entry = g_dir_read_name (dir))) {
    /* don't do . and .. and special case font */
    if ((g_strcasecmp (entry, ".")    != 0) && 
        (g_strcasecmp (entry, "..")   != 0) &&
        (g_strcasecmp (entry, "font") != 0))
    {
      gchar *fullpath = g_build_filename (string, entry, NULL);

      if (g_file_test (fullpath, G_FILE_TEST_IS_DIR)) {
        if (s_slib_uniq (fullpath)) {
          if (g_path_is_absolute (fullpath)) {
            s_slib_add_entry (fullpath);
          } else {
            gchar *cwd = g_get_current_dir ();
            gchar *temp;
            temp = g_build_filename (cwd, fullpath, NULL);
            s_slib_add_entry (temp);
            g_free(temp);
            g_free(cwd);
          }
        }
      }
      g_free(fullpath);
    }
  }

  g_free(string);
  g_dir_close(dir);

  return SCM_BOOL_T;
}
Exemplo n.º 27
0
GtkWidget* puss_create_global_options_setup_widget(gpointer tag) {
	gchar* filepath;
	GtkBuilder* builder;
	GtkWidget* panel;
	GtkWidget* w;
	GError* err = 0;
	const Option* option;

	// create UI
	builder = gtk_builder_new();
	if( !builder )
		return 0;
	gtk_builder_set_translation_domain(builder, TEXT_DOMAIN);

	filepath = g_build_filename(puss_app->module_path, "res", "puss_setup_widget.ui", NULL);
	if( !filepath ) {
		g_printerr("ERROR(puss) : build setup dialog filepath failed!\n");
		g_object_unref(G_OBJECT(builder));
		return 0;
	}

	gtk_builder_add_from_file(builder, filepath, &err);
	g_free(filepath);

	if( err ) {
		g_printerr("ERROR(puss): %s\n", err->message);
		g_error_free(err);
		g_object_unref(G_OBJECT(builder));
		return 0;
	}

	panel = GTK_WIDGET(g_object_ref(gtk_builder_get_object(builder, "main_panel")));

#ifdef G_OS_WIN32
	{
		gchar* path;
		GDir*  dir;
		const gchar* fname;
		gchar* rcfile;
		gint i;
		gint index = -1;

		option = puss_option_manager_option_find("puss", "theme");
		w = GTK_WIDGET(gtk_builder_get_object(builder, "theme_combo"));

		path = gtk_rc_get_theme_dir();
		dir = g_dir_open(path, 0, 0);
		if( dir ) {
			i = 0;
			for(;;) {
				fname = g_dir_read_name(dir);
				if( !fname )
					break;

				rcfile = g_build_filename(path, fname, "gtk-2.0", "gtkrc", NULL);
				if( g_file_test(rcfile, G_FILE_TEST_EXISTS) ) {
#if GTK_MAJOR_VERSION==2
					gtk_combo_box_append_text(GTK_COMBO_BOX(w), fname);
#else
					gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(w), fname);
#endif
					if( index < 0 && option->value ) {
						if( g_str_equal(fname, option->value) )
							index = i;
						++i;
					}
				}
				g_free(rcfile);
			}
			g_dir_close(dir);
		}
		g_free(path);

		if( index >= 0 )
			gtk_combo_box_set_active(GTK_COMBO_BOX(w), index);

		g_signal_connect(w, "changed", G_CALLBACK(cb_combo_box_option_changed), (gpointer)option);
	}
#endif

	{
		const gchar* const * ids;
		const gchar* const * p;
		gint i;
		gint index = -1;

		GtkSourceStyleSchemeManager* ssm = gtk_source_style_scheme_manager_get_default();

		option = puss_option_manager_option_find("puss", "editor.style");
		w = GTK_WIDGET(gtk_builder_get_object(builder, "style_combo"));

		if( ssm ) {
			gtk_source_style_scheme_manager_force_rescan(ssm);

			ids = gtk_source_style_scheme_manager_get_scheme_ids(ssm);
			i = 0;
			for( p=ids; *p; ++p ) {
#if GTK_MAJOR_VERSION==2
				gtk_combo_box_append_text(GTK_COMBO_BOX(w), *p);
#else
				gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(w), *p);
#endif

				if( index < 0 && option->value ) {
					if( g_str_equal(*p, option->value) )
						index = i;
					++i;
				}
			}
			
			if( index >= 0 )
				gtk_combo_box_set_active(GTK_COMBO_BOX(w), index);
		}

		g_signal_connect(w, "changed", G_CALLBACK(cb_combo_box_option_changed), (gpointer)option);
	}

	{
		option = puss_option_manager_option_find("puss", "editor.font");
		w = GTK_WIDGET(gtk_builder_get_object(builder, "font_button"));

		if( option->value && option->value[0] )
			gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), option->value);

		g_signal_connect(w, "font-set", G_CALLBACK(cb_font_button_changed), (gpointer)option);
	}

	{
		GtkEntry* entry;
		option = puss_option_manager_option_find("puss", "fileloader.charset_list");
		entry = GTK_ENTRY(gtk_builder_get_object(builder, "charset_entry"));
		w = GTK_WIDGET(gtk_builder_get_object(builder, "charset_apply_button"));

		gtk_entry_set_text(entry, option->value);
		g_signal_connect(w, "clicked", G_CALLBACK(cb_apply_button_changed), (gpointer)entry);
	}

	g_object_unref(G_OBJECT(builder));

	return panel;
}
Exemplo n.º 28
0
void
ags_machine_open_extended_response_callback(GtkWidget *widget, gint response, AgsMachine *machine)
{
  GtkFileChooserDialog *file_chooser;
  AgsFileSelection *file_selection;
  GtkCheckButton *overwrite;
  GtkCheckButton *create;

  GSList *filenames;

  gchar *current_folder;

  GError *error;

  file_chooser = (GtkFileChooserDialog *) gtk_widget_get_toplevel(widget);

  if(response == GTK_RESPONSE_ACCEPT){
    filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(file_chooser));
    overwrite = g_object_get_data((GObject *) widget, "overwrite");
    create = g_object_get_data((GObject *) widget, "create");

    current_folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(file_chooser));
    //TODO:JK: you need to check against recently used
    //TODO:JK: add more file types to AgsFileSelection

    /* check for supported packed audio files */
    file_selection = (AgsFileSelection *) gtk_file_chooser_get_extra_widget(GTK_FILE_CHOOSER(file_chooser));

    if(file_selection != NULL && g_strcmp0(file_selection->directory, current_folder)){
      gtk_widget_destroy(GTK_WIDGET(file_selection));

      file_selection = NULL;
    }

    if(file_selection == NULL ||
       (AGS_FILE_SELECTION_COMPLETED & (file_selection->flags)) == 0){

      if((AGS_MACHINE_ACCEPT_SOUNDFONT2 & (machine->file_input_flags)) != 0){
	GDir *current_directory;

	GList *new_entry, *old_entry;	  
	GSList *slist;

	gchar *current_filename;
	
	slist = filenames;
	new_entry = NULL;
	
	while(slist != NULL){
	  if(g_str_has_suffix(slist->data,
			      ".sf2")){
	    AgsFileSelectionEntry *entry;
	    
	    
	    entry = ags_file_selection_entry_alloc();
	    entry->filename = slist->data;
	  
	    new_entry = g_list_prepend(new_entry,
				       entry);
	  }
	  
	  slist = slist->next;
	}
	
	old_entry = NULL;
	
	if(file_selection == NULL){
	  if(new_entry != NULL){
	    file_selection = ags_file_selection_new();
	    gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(file_chooser),
					      GTK_WIDGET(file_selection));

	    ags_file_selection_set_entry(file_selection,
					 new_entry);
	    ags_connectable_connect(AGS_CONNECTABLE(file_selection));

	    gtk_widget_show_all(GTK_WIDGET(file_selection));

	    return;
	  }
	}else if(AGS_IS_FILE_SELECTION(file_selection)){
	  GList *really_new_entry;
	  GList *list;
	  
	  old_entry = file_selection->entry;
	  list = new_entry;
	  really_new_entry = NULL;
	  
	  /* check against existing entries */
	  if(new_entry != NULL){
	    while(list != NULL){
	      if(g_list_find(old_entry, list->data) == NULL){
		really_new_entry = g_list_prepend(really_new_entry,
						  list->data);
	      }else{
		free(list->data);
	      }
	      
	      list = list->next;
	    }
	    
	    g_list_free(new_entry);
	  }
	  
	  ags_file_selection_set_entry(file_selection,
				       really_new_entry);

	  /* adding lost files */
	  //TODO:JK: figure out if you need to copy the GSList of filenames
	  gtk_file_chooser_select_all(GTK_FILE_CHOOSER(file_chooser));
	  
	  current_directory = g_dir_open(current_folder,
					 0,
					 &error);
	  
	  while((current_filename = (gchar *) g_dir_read_name(current_directory)) != NULL){
	    if(!g_strcmp0(".", current_filename) ||
	       !g_strcmp0("..", current_filename))
	      continue;

	    if(!ags_file_selection_contains_file(file_selection,
						 current_filename) &&
	       g_slist_find(filenames, current_filename) == NULL){
	      gtk_file_chooser_unselect_filename(GTK_FILE_CHOOSER(file_chooser),
						 current_filename);
	    }
	  }
	  
	  g_dir_close(current_directory);
	  
	  return;
	}
      }
    }
    
    //TODO:JK: fix GSList filenames memory leak
    ags_machine_open_files(machine,
			   filenames,
			   overwrite->toggle_button.active,
			   create->toggle_button.active);
  }
}
static void
wckbuttons_load_themes (GtkWidget *view, WBPlugin *wb)
{
    GtkTreeModel *model;
    GHashTable   *themes;
    GDir         *dir;
    const gchar  *file;
    gchar       **theme_dirs;
    gchar        *themedir;
    gint          i;

    themes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));

    /* clear any previous row */
    gtk_list_store_clear (GTK_LIST_STORE (model));

    xfce_resource_push_path (XFCE_RESOURCE_THEMES, DATADIR G_DIR_SEPARATOR_S "themes");
    theme_dirs = xfce_resource_dirs (XFCE_RESOURCE_THEMES);
    xfce_resource_pop_path (XFCE_RESOURCE_THEMES);

    for (i = 0; theme_dirs[i] != NULL; ++i)
    {
        dir = g_dir_open (theme_dirs[i], 0, NULL);

        if (G_UNLIKELY (dir == NULL))
            continue;

        while ((file = g_dir_read_name (dir)) != NULL)
        {
            /* check if there is not already a theme with the
            * same name in the database */
            if (g_hash_table_lookup (themes, file) == NULL) {

                if (wb->prefs->sync_wm_theme)
                {
                    if (!test_theme_dir(file, "xfwm4", THEMERC))
                        continue;
                }

                themedir = get_theme_dir (file, NULL);
                if (!themedir)
                    continue;

                GtkTreeIter   iter;
                g_hash_table_insert (themes, g_strdup (file), GINT_TO_POINTER (1));

                /* insert in the list store */
                gtk_list_store_append (GTK_LIST_STORE (model), &iter);
                gtk_list_store_set (GTK_LIST_STORE (model), &iter,
                                  COL_THEME_NAME, file,
                                  COL_THEME_RC, g_path_get_basename (themedir), -1);

                    if (G_UNLIKELY (g_str_equal (wb->prefs->theme, file)))
                    {
                        GtkTreePath *path = gtk_tree_model_get_path (model, &iter);

                        gtk_tree_selection_select_iter (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)),
                                                      &iter);
                        gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (view), path, NULL, TRUE, 0.5, 0.5);

                        gtk_tree_path_free (path);
                    }
                g_free (themedir);
            }
        }

      g_dir_close (dir);
    }

  g_strfreev (theme_dirs);
  g_hash_table_destroy (themes);
}
Exemplo n.º 30
0
void
gui_init (dt_lib_module_t *self)
{
  dt_lib_export_t *d = (dt_lib_export_t *)malloc(sizeof(dt_lib_export_t));
  self->data = (void *)d;
  self->widget = gtk_table_new(8, 2, FALSE);
  gtk_table_set_row_spacings(GTK_TABLE(self->widget), 5);

  GtkWidget *label;

  label = dtgtk_label_new(_("target storage"), DARKTABLE_LABEL_TAB | DARKTABLE_LABEL_ALIGN_RIGHT);
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
  gtk_table_attach(GTK_TABLE(self->widget), label, 0, 2, 0, 1, GTK_FILL|GTK_EXPAND, 0, 0, 0);
  d->storage = GTK_COMBO_BOX(gtk_combo_box_new_text());
  GList *it = darktable.imageio->plugins_storage;
  while(it)
  {
    dt_imageio_module_storage_t *module = (dt_imageio_module_storage_t *)it->data;
    gtk_combo_box_append_text(d->storage, module->name(module));
    it = g_list_next(it);
  }
  dt_control_signal_connect(darktable.signals,DT_SIGNAL_IMAGEIO_STORAGE_CHANGE,G_CALLBACK(on_storage_list_changed),self);
  gtk_table_attach(GTK_TABLE(self->widget), GTK_WIDGET(d->storage), 0, 2, 1, 2, GTK_EXPAND|GTK_FILL, 0, 0, 0);
  g_signal_connect (G_OBJECT (d->storage), "changed",
                    G_CALLBACK (storage_changed),
                    (gpointer)d);

  d->storage_box = GTK_CONTAINER(gtk_alignment_new(1.0, 1.0, 1.0, 1.0));
  gtk_alignment_set_padding(GTK_ALIGNMENT(d->storage_box), 0, 0, 0, 0);
  gtk_table_attach(GTK_TABLE(self->widget), GTK_WIDGET(d->storage_box), 0, 2, 2, 3, GTK_EXPAND|GTK_FILL, 0, 0, 0);

  label = dtgtk_label_new(_("file format"), DARKTABLE_LABEL_TAB | DARKTABLE_LABEL_ALIGN_RIGHT);
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
  gtk_table_set_row_spacing(GTK_TABLE(self->widget), 2, 20);
  gtk_table_attach(GTK_TABLE(self->widget), label, 0, 2, 3, 4, GTK_EXPAND|GTK_FILL, 0, 0, 0);
  d->format = GTK_COMBO_BOX(gtk_combo_box_new_text());

  gtk_table_attach(GTK_TABLE(self->widget), GTK_WIDGET(d->format), 0, 2, 4, 5, GTK_EXPAND|GTK_FILL, 0, 0, 0);
  g_signal_connect (G_OBJECT (d->format), "changed",
                    G_CALLBACK (format_changed),
                    (gpointer)d);

  d->format_box = GTK_CONTAINER(gtk_alignment_new(1.0, 1.0, 1.0, 1.0));
  gtk_alignment_set_padding(GTK_ALIGNMENT(d->format_box), 0, 0, 0, 0);
  gtk_table_attach(GTK_TABLE(self->widget), GTK_WIDGET(d->format_box), 0, 2, 5, 6, GTK_EXPAND|GTK_FILL, 0, 0, 0);

  label = dtgtk_label_new(_("global options"), DARKTABLE_LABEL_TAB | DARKTABLE_LABEL_ALIGN_RIGHT);
  gtk_table_set_row_spacing(GTK_TABLE(self->widget), 5, 20);
  gtk_table_attach(GTK_TABLE(self->widget), label, 0, 2, 6, 7, GTK_EXPAND|GTK_FILL, 0, 0, 0);
  d->width  = GTK_SPIN_BUTTON(gtk_spin_button_new_with_range(0, 10000, 1));
  g_object_set(G_OBJECT(d->width), "tooltip-text", _("maximum output width\nset to 0 for no scaling"), (char *)NULL);
  d->height = GTK_SPIN_BUTTON(gtk_spin_button_new_with_range(0, 10000, 1));
  g_object_set(G_OBJECT(d->height), "tooltip-text", _("maximum output height\nset to 0 for no scaling"), (char *)NULL);

  dt_gui_key_accel_block_on_focus_connect (GTK_WIDGET (d->width));
  dt_gui_key_accel_block_on_focus_connect (GTK_WIDGET (d->height));
  /*
    gtk_widget_add_events(GTK_WIDGET(d->width), GDK_FOCUS_CHANGE_MASK);
    g_signal_connect (G_OBJECT (d->width), "focus-in-event",  G_CALLBACK(focus_in),  NULL);
    g_signal_connect (G_OBJECT (d->width), "focus-out-event", G_CALLBACK(focus_out), NULL);
    gtk_widget_add_events(GTK_WIDGET(d->height), GDK_FOCUS_CHANGE_MASK);
    g_signal_connect (G_OBJECT (d->height), "focus-in-event",  G_CALLBACK(focus_in),  NULL);
    g_signal_connect (G_OBJECT (d->height), "focus-out-event", G_CALLBACK(focus_out), NULL);
    */
  label = gtk_label_new(_("max size"));
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
  gtk_table_attach(GTK_TABLE(self->widget), label, 0, 1, 7, 8, GTK_EXPAND|GTK_FILL, 0, 0, 0);
  GtkBox *hbox = GTK_BOX(gtk_hbox_new(FALSE, 5));
  gtk_box_pack_start(hbox, GTK_WIDGET(d->width), TRUE, TRUE, 0);
  gtk_box_pack_start(hbox, gtk_label_new(_("x")), FALSE, FALSE, 0);
  gtk_box_pack_start(hbox, GTK_WIDGET(d->height), TRUE, TRUE, 0);
  gtk_table_attach(GTK_TABLE(self->widget), GTK_WIDGET(hbox), 1, 2, 7, 8, GTK_EXPAND|GTK_FILL, 0, 0, 0);

  label = gtk_label_new(_("intent"));
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
  gtk_table_attach(GTK_TABLE(self->widget), label, 0, 1, 8, 9, GTK_EXPAND|GTK_FILL, 0, 0, 0);
  d->intent = GTK_COMBO_BOX(gtk_combo_box_new_text());
  gtk_combo_box_append_text(d->intent, _("image settings"));
  gtk_combo_box_append_text(d->intent, _("perceptual"));
  gtk_combo_box_append_text(d->intent, _("relative colorimetric"));
  gtk_combo_box_append_text(d->intent, C_("rendering intent", "saturation"));
  gtk_combo_box_append_text(d->intent, _("absolute colorimetric"));
  gtk_table_attach(GTK_TABLE(self->widget), GTK_WIDGET(d->intent), 1, 2, 8, 9, GTK_EXPAND|GTK_FILL, 0, 0, 0);

  //  Add profile combo

  d->profiles = NULL;

  dt_lib_export_profile_t *prof = (dt_lib_export_profile_t *)g_malloc0(sizeof(dt_lib_export_profile_t));
  g_strlcpy(prof->filename, "sRGB", sizeof(prof->filename));
  g_strlcpy(prof->name, _("sRGB (web-safe)"), sizeof(prof->name));
  int pos;
  prof->pos = 1;
  d->profiles = g_list_append(d->profiles, prof);

  prof = (dt_lib_export_profile_t *)g_malloc0(sizeof(dt_lib_export_profile_t));
  g_strlcpy(prof->filename, "adobergb", sizeof(prof->filename));
  g_strlcpy(prof->name, _("Adobe RGB"), sizeof(prof->name));
  prof->pos = 2;
  d->profiles = g_list_append(d->profiles, prof);

  prof = (dt_lib_export_profile_t *)g_malloc0(sizeof(dt_lib_export_profile_t));
  g_strlcpy(prof->filename, "X profile", sizeof(prof->filename));
  g_strlcpy(prof->name, "X profile", sizeof(prof->name));
  prof->pos = 3;
  d->profiles = g_list_append(d->profiles, prof);

  prof = (dt_lib_export_profile_t *)g_malloc0(sizeof(dt_lib_export_profile_t));
  g_strlcpy(prof->filename, "linear_rgb", sizeof(prof->filename));
  g_strlcpy(prof->name, _("linear RGB"), sizeof(prof->name));
  pos = prof->pos = 4;
  d->profiles = g_list_append(d->profiles, prof);

  // read datadir/color/out/*.icc
  char datadir[DT_MAX_PATH_LEN];
  char confdir[DT_MAX_PATH_LEN];
  char dirname[DT_MAX_PATH_LEN];
  char filename[DT_MAX_PATH_LEN];
  dt_loc_get_user_config_dir(confdir, DT_MAX_PATH_LEN);
  dt_loc_get_datadir(datadir, DT_MAX_PATH_LEN);
  cmsHPROFILE tmpprof;
  const gchar *d_name;
  snprintf(dirname, DT_MAX_PATH_LEN, "%s/color/out", confdir);
  if(!g_file_test(dirname, G_FILE_TEST_IS_DIR))
    snprintf(dirname, DT_MAX_PATH_LEN, "%s/color/out", datadir);
  GDir *dir = g_dir_open(dirname, 0, NULL);
  if(dir)
  {
    while((d_name = g_dir_read_name(dir)))
    {
      snprintf(filename, DT_MAX_PATH_LEN, "%s/%s", dirname, d_name);
      tmpprof = cmsOpenProfileFromFile(filename, "r");
      if(tmpprof)
      {
        char *lang = getenv("LANG");
        if (!lang) lang = "en_US";

        dt_lib_export_profile_t *prof = (dt_lib_export_profile_t *)g_malloc0(sizeof(dt_lib_export_profile_t));
        char name[1024];
        cmsGetProfileInfoASCII(tmpprof, cmsInfoDescription, lang, lang+3, name, 1024);
        g_strlcpy(prof->name, name, sizeof(prof->name));
        g_strlcpy(prof->filename, d_name, sizeof(prof->filename));
        prof->pos = ++pos;
        cmsCloseProfile(tmpprof);
        d->profiles = g_list_append(d->profiles, prof);
      }
    }
    g_dir_close(dir);
  }
  GList *l = d->profiles;
  label = gtk_label_new(_("profile"));
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
  gtk_table_attach(GTK_TABLE(self->widget), label, 0, 1, 9, 10, GTK_EXPAND|GTK_FILL, 0, 0, 0);
  d->profile = GTK_COMBO_BOX(gtk_combo_box_new_text());
  dt_ellipsize_combo(d->profile);
  gtk_table_attach(GTK_TABLE(self->widget), GTK_WIDGET(d->profile), 1, 2, 9, 10, GTK_SHRINK|GTK_EXPAND|GTK_FILL, 0, 0, 0);
  // gtk_table_attach(GTK_TABLE(self->widget), GTK_WIDGET(d->profile), 1, 2, 9, 10, GTK_EXPAND|GTK_FILL, 0, 0, 0);
  gtk_combo_box_append_text(d->profile, _("image settings"));
  while(l)
  {
    dt_lib_export_profile_t *prof = (dt_lib_export_profile_t *)l->data;
    if(!strcmp(prof->name, "X profile"))
      gtk_combo_box_append_text(d->profile, _("system display profile"));
    else
      gtk_combo_box_append_text(d->profile, prof->name);
    l = g_list_next(l);
  }

  gtk_combo_box_set_active(d->profile, 0);
  char tooltip[1024];
  snprintf(tooltip, 1024, _("output icc profiles in %s/color/out or %s/color/out"), confdir, datadir);
  g_object_set(G_OBJECT(d->profile), "tooltip-text", tooltip, (char *)NULL);


  //  Add style combo

  label = gtk_label_new(_("style"));
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
  gtk_table_attach(GTK_TABLE(self->widget), label, 0, 1, 10, 11, GTK_EXPAND|GTK_FILL, 0, 0, 0);
  d->style = GTK_COMBO_BOX(gtk_combo_box_new_text());

  dt_ellipsize_combo(d->style);

  gtk_combo_box_append_text(d->style, _("none"));

  GList *styles = dt_styles_get_list("");
  while (styles)
  {
    dt_style_t *style=(dt_style_t *)styles->data;
    gtk_combo_box_append_text(d->style, style->name);
    styles=g_list_next(styles);
  }
  gtk_table_attach(GTK_TABLE(self->widget), GTK_WIDGET(d->style), 1, 2, 10, 11, GTK_EXPAND|GTK_FILL, 0, 0, 0);
  g_object_set(G_OBJECT(d->style), "tooltip-text", _("temporary style to append while exporting"), (char *)NULL);

  //  Set callback signals

  g_signal_connect (G_OBJECT (d->intent), "changed",
                    G_CALLBACK (intent_changed),
                    (gpointer)d);
  g_signal_connect (G_OBJECT (d->profile), "changed",
                    G_CALLBACK (profile_changed),
                    (gpointer)d);
  g_signal_connect (G_OBJECT (d->style), "changed",
                    G_CALLBACK (style_changed),
                    (gpointer)d);

  // Export button

  GtkButton *button = GTK_BUTTON(gtk_button_new_with_label(_("export")));
  d->export_button = button;
  g_object_set(G_OBJECT(button), "tooltip-text", _("export with current settings (ctrl-e)"), (char *)NULL);
  gtk_table_attach(GTK_TABLE(self->widget), GTK_WIDGET(button), 1, 2, 11, 12, GTK_EXPAND|GTK_FILL, 0, 0, 0);

  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (export_button_clicked),
                    (gpointer)self);
  g_signal_connect (G_OBJECT (d->width), "value-changed",
                    G_CALLBACK (width_changed),
                    (gpointer)0);
  g_signal_connect (G_OBJECT (d->height), "value-changed",
                    G_CALLBACK (height_changed),
                    (gpointer)0);

  self->gui_reset(self);
}