Пример #1
0
void get_icon_theme() {
  if (g_key_file_has_key(keyFile,"PNMixer","IconTheme",NULL)) {
    gchar* theme_name = g_key_file_get_string(keyFile,"PNMixer","IconTheme",NULL);
    if (icon_theme == NULL || (icon_theme == gtk_icon_theme_get_default()))
      icon_theme = gtk_icon_theme_new();
    gtk_icon_theme_set_custom_theme(icon_theme,theme_name);
    g_free(theme_name);
  }
  else 
    icon_theme = gtk_icon_theme_get_default();
}
Пример #2
0
GtkIconTheme *
dawati_panel_devices_get_icon_theme (void)
{
  static GtkIconTheme *theme = NULL;

  if (G_LIKELY (theme))
    return theme;

  theme = gtk_icon_theme_new ();
  gtk_icon_theme_set_custom_theme (theme, "dawati");

  return theme;
}
Пример #3
0
QString ThemeAppIcon::getThemeIconPath(QString iconName, int size)
{
    QByteArray bytes = iconName.toUtf8();
    char *name = bytes.data();

    if (g_path_is_absolute(name))
            return g_strdup(name);

        g_return_val_if_fail(name != NULL, NULL);

        int pic_name_len = strlen(name);
        char* ext = strrchr(name, '.');
        if (ext != NULL) {
            if (g_ascii_strcasecmp(ext+1, "png") == 0 || g_ascii_strcasecmp(ext+1, "svg") == 0 || g_ascii_strcasecmp(ext+1, "jpg") == 0) {
                pic_name_len = ext - name;
//                qDebug() << "desktop's Icon name should an absoulte path or an basename without extension";
            }
        }

        // In pratice, default icon theme may not gets the right icon path when program starting.
        if (them == NULL)
            them = gtk_icon_theme_new();
        char* icon_theme_name = get_icon_theme_name();
        gtk_icon_theme_set_custom_theme(them, icon_theme_name);
        g_free(icon_theme_name);

        char* pic_name = g_strndup(name, pic_name_len);

        GtkIconInfo* info = gtk_icon_theme_lookup_icon(them, pic_name, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
        if (info == NULL) {
            info = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), pic_name, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
            if (info == NULL) {
//                qWarning() << "get gtk icon theme info failed for" << pic_name;
                g_free(pic_name);
                return "";
            }
        }
        g_free(pic_name);

        char* path = g_strdup(gtk_icon_info_get_filename(info));

    #if GTK_MAJOR_VERSION >= 3
        g_object_unref(info);
    #elif GTK_MAJOR_VERSION == 2
        gtk_icon_info_free(info);
    #endif
        g_debug("get icon from icon theme is: %s", path);
        return path;
}
Пример #4
0
void
icon_theme_set_theme(const char* name)
{
	mime_type_clear();

	dbg(1, "setting theme: %s.", theme_name);

	if(name && name[0]){
		if(!*theme_name) icon_theme = gtk_icon_theme_new(); // the old icon theme cannot be updated
		g_strlcpy(theme_name, name, 64);
		gtk_icon_theme_set_custom_theme(icon_theme, theme_name);
	}

	if(!strlen(theme_name))
		g_idle_add(check_default_theme, NULL);

	gtk_icon_theme_rescan_if_needed(icon_theme);
}
Пример #5
0
GtkCssValue *
gtk_css_icon_theme_value_parse (GtkCssParser *parser)
{
  GtkIconTheme *icontheme;
  GtkCssValue *result;
  char *s;

  s = _gtk_css_parser_read_string (parser);
  if (s == NULL)
    return NULL;

  icontheme = gtk_icon_theme_new ();
  gtk_icon_theme_set_custom_theme (icontheme, s);

  result = gtk_css_icon_theme_value_new (icontheme);

  g_object_unref (icontheme);
  g_free (s);

  return result;
}
Пример #6
0
int
clip_GTK_ICONTHEMENEW(ClipMachine * cm)
{
	ClipVar *cv       = _clip_spar(cm,1);
        C_object *cicon;
        GtkIconTheme *icon;

	CHECKOPT(1,MAP_t);

	icon = gtk_icon_theme_new();

	if (icon)
	{
		cicon = _list_get_cobject(cm,icon);
		if (!cicon) cicon = _register_object(cm,icon,GTK_TYPE_ICON_THEME,cv,NULL);
		if (cicon) _clip_mclone(cm,RETPTR(cm),&cicon->obj);
	}

	return 0;
err:
	return 1;
}
Пример #7
0
static VALUE
it_initialize(VALUE self)
{
    G_INITIALIZE(self, gtk_icon_theme_new());
    return Qnil;
}
Пример #8
0
gint
main (gint argc, gchar ** argv)
{
    GOptionContext *ctx;
    GError *err = NULL;
    gint w, h;
    gchar *str;
    gint ret = 0;

    setlocale (LC_ALL, "");

#ifdef ENABLE_NLS
    bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);
#endif

#if !GLIB_CHECK_VERSION(2,36,0)
    g_type_init ();
#endif
    read_settings ();

    gtk_init (&argc, &argv);
    g_set_application_name ("YAD");
    yad_options_init ();

    ctx = yad_create_context ();
    /* parse YAD_OPTIONS */
    if (g_getenv ("YAD_OPTIONS"))
    {
        gchar *cmd, **args = NULL;
        gint cnt;

        cmd = g_strdup_printf ("yad %s", g_getenv ("YAD_OPTIONS"));

        if (g_shell_parse_argv (cmd, &cnt, &args, &err))
        {
            g_option_context_parse (ctx, &cnt, &args, &err);
            if (err)
            {
                g_printerr (_("Unable to parse YAD_OPTIONS: %s\n"), err->message);
                g_error_free (err);
                err = NULL;
            }
        }
        else
        {
            g_printerr (_("Unable to parse YAD_OPTIONS: %s\n"), err->message);
            g_error_free (err);
            err = NULL;
        }

        g_free (cmd);
    }
    /* parse command line */
    g_option_context_parse (ctx, &argc, &argv, &err);
    if (err)
    {
        g_printerr (_("Unable to parse command line: %s\n"), err->message);
        return -1;
    }
    yad_set_mode ();

    /* parse custom gtkrc */
    if (options.gtkrc_file)
        gtk_rc_parse (options.gtkrc_file);

    /* set default icons and icon theme */
    if (options.data.icon_theme)
    {
        settings.icon_theme = gtk_icon_theme_new ();
        gtk_icon_theme_set_custom_theme (settings.icon_theme, options.data.icon_theme);
    }
    else
        settings.icon_theme = gtk_icon_theme_get_default ();
    gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &w, &h);
    settings.big_fallback_image =
        gtk_icon_theme_load_icon (settings.icon_theme, "yad", MIN (w, h), GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
    gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h);
    settings.small_fallback_image =
        gtk_icon_theme_load_icon (settings.icon_theme, "yad", MIN (w, h), GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);

    /* correct separators */
    str = g_strcompress (options.common_data.separator);
    options.common_data.separator = str;
    str = g_strcompress (options.common_data.item_separator);
    options.common_data.item_separator = str;

    /* loads an extra arguments, if specified */
    if (options.rest_file)
    {
        GIOChannel *ioc;
        gchar *buf;
        guint len, line = 0;

        g_strfreev (options.extra_data);
        options.extra_data = NULL;

        ioc = g_io_channel_new_file (options.rest_file, "r", NULL);
        while (TRUE)
        {
            gint status = g_io_channel_read_line (ioc, &buf, NULL, NULL, NULL);

            if (status != G_IO_STATUS_NORMAL)
                break;

            /* remove \n at the end of string */
            len = strlen (buf);
            if (buf[len - 1] == '\n')
                buf[len - 1] = '\0';

            /* add line to arguments array */
            options.extra_data = g_realloc (options.extra_data, (line + 2) * sizeof (gchar *));
            options.extra_data[line] = g_strcompress (buf);
            options.extra_data[line + 1] = NULL;

            g_free (buf);
            line++;
        }
        g_io_channel_shutdown (ioc, FALSE, NULL);
    }

#ifndef G_OS_WIN32
    /* add YAD_PID variable */
    str = g_strdup_printf ("%d", getpid ());
    g_setenv ("YAD_PID", str, TRUE);
    /* set signal handlers */
    signal (SIGUSR1, sa_usr1);
    signal (SIGUSR2, sa_usr2);
#endif

    /* plug mode */
    if (options.plug != -1)
    {
        create_plug ();
        gtk_main ();
        shmdt (tabs);
        return ret;
    }

    switch (options.mode)
    {
    case YAD_MODE_ABOUT:
        ret = yad_about ();
        break;

    case YAD_MODE_VERSION:
        g_print ("%s (GTK+ %d.%d.%d)\n", VERSION, gtk_major_version, gtk_minor_version, gtk_micro_version);
        break;

    case YAD_MODE_NOTIFICATION:
        ret = yad_notification_run ();
        break;

    case YAD_MODE_PRINT:
        ret = yad_print_run ();
        break;

#ifdef HAVE_HTML
    case YAD_MODE_HTML:
        /* Webkit doesn't handle focus for child dialogs when gtk_dialog_run() is used */
        /* FIXME: maybe this solution must be expanded to all dialogs */
        dialog = create_dialog ();
        g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (html_response_cb), &ret);

        gtk_widget_show_all (dialog);

        gtk_main ();
        break;
#endif

    default:
        dialog = create_dialog ();

#ifndef G_OS_WIN32
        /* add YAD_XID variable */
        str = g_strdup_printf ("0x%X", GDK_WINDOW_XID (gtk_widget_get_window (dialog)));
        g_setenv ("YAD_XID", str, TRUE);
#endif

        if (options.mode == YAD_MODE_FILE)
        {
            /* show custom confirmation dialog */
            g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (confirm_overwrite_cb), NULL);
        }
        else if (options.mode == YAD_MODE_NOTEBOOK)
            notebook_swallow_childs ();
        else if (options.mode == YAD_MODE_PANED)
            paned_swallow_childs ();

        ret = gtk_dialog_run (GTK_DIALOG (dialog));
        if (options.data.always_print)
            print_result ();
        else if (ret != YAD_RESPONSE_TIMEOUT && ret != YAD_RESPONSE_ESC)
        {
            /* standard OK button pressed */
            if (ret == YAD_RESPONSE_OK && options.data.buttons == NULL)
                print_result ();
            /* custom even button pressed */
            else if (options.data.buttons && !(ret & 1))
                print_result ();
        }
#ifndef G_OS_WIN32
        if (options.mode == YAD_MODE_NOTEBOOK)
            notebook_close_childs ();
        else if (options.mode == YAD_MODE_PANED)
            paned_close_childs ();
        /* autokill option for progress dialog */
        if (!options.kill_parent)
        {
            if ((options.mode == YAD_MODE_PROGRESS || options.mode == YAD_MODE_MULTI_PROGRESS) &&
                    options.progress_data.autokill && ret != YAD_RESPONSE_OK)
                kill (getppid (), SIGHUP);
        }
#endif
    }

#ifndef G_OS_WIN32
    /* NSIG defined in signal.h */
    if (options.kill_parent > 0 && options.kill_parent < NSIG)
        kill (getppid (), options.kill_parent);
#endif

    return ret;
}
Пример #9
0
gint
main (gint argc, gchar * argv[])
{
  IconBrowserData *data;
  gchar **themes = NULL;
  GList *ic, *icat;
  GtkListStore *store;
  GtkTreeSelection *sel;
  GtkTreeViewColumn *col;
  GtkCellRenderer *r;
  GtkWidget *w, *p, *box, *t;

  GOptionEntry entrs[] = {
    {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &themes, NULL, NULL},
    {NULL}
  };

  data = g_new0 (IconBrowserData, 1);

#ifdef ENABLE_NLS
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#endif

  data = g_new0 (IconBrowserData, 1);

  /* initialize GTK+ and parse the command line arguments */
  gtk_init_with_args (&argc, &argv, _("- Icon browser"), entrs, GETTEXT_PACKAGE, NULL);

  /* load icon theme */
  if (themes && themes[0])
    {
      data->theme = gtk_icon_theme_new ();
      gtk_icon_theme_set_custom_theme (data->theme, themes[0]);
    }
  else
    data->theme = gtk_icon_theme_get_default ();

  /* create interface */
  data->win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (data->win), _("Icon browser"));
  gtk_window_set_icon_name (GTK_WINDOW (data->win), "gtk-info");
  gtk_window_set_default_size (GTK_WINDOW (data->win), 500, 400);
  g_signal_connect (G_OBJECT (data->win), "delete-event", G_CALLBACK (gtk_main_quit), NULL);
  g_signal_connect (G_OBJECT (data->win), "key-press-event", G_CALLBACK (key_press_cb), NULL);

#if !GTK_CHECK_VERSION(3,0,0)
  box = gtk_vbox_new (FALSE, 5);
#else
  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
#endif
  gtk_container_add (GTK_CONTAINER (data->win), box);
  gtk_container_set_border_width (GTK_CONTAINER (data->win), 5);

  /* create icon info box */
#if !GTK_CHECK_VERSION(3,0,0)
  t = gtk_table_new (3, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (t), 5);
  gtk_table_set_row_spacings (GTK_TABLE (t), 5);
#else
  t = gtk_grid_new ();
  gtk_grid_set_row_spacing (GTK_GRID (t), 5);
  gtk_grid_set_column_spacing (GTK_GRID (t), 5);
#endif
  gtk_box_pack_start (GTK_BOX (box), t, FALSE, FALSE, 2);

  data->image = gtk_image_new_from_stock ("gtk-missing-image", GTK_ICON_SIZE_DIALOG);
#if !GTK_CHECK_VERSION(3,0,0)
  gtk_table_attach (GTK_TABLE (t), data->image, 0, 1, 0, 3, GTK_FILL, 0, 0, 0);
#else
  gtk_grid_attach (GTK_GRID (t), data->image, 0, 0, 1, 3);
#endif

  w = gtk_label_new (NULL);
  gtk_label_set_markup (GTK_LABEL (w), _("<b>Name:</b>"));
  gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
#if !GTK_CHECK_VERSION(3,0,0)
  gtk_table_attach (GTK_TABLE (t), w, 1, 2, 0, 1, GTK_FILL, 0, 0, 0);
#else
  gtk_grid_attach (GTK_GRID (t), w, 1, 0, 1, 1);
#endif
  data->lname = gtk_label_new (NULL);
  gtk_label_set_selectable (GTK_LABEL (data->lname), TRUE);
  gtk_misc_set_alignment (GTK_MISC (data->lname), 0, 0.5);
#if !GTK_CHECK_VERSION(3,0,0)
  gtk_table_attach (GTK_TABLE (t), data->lname, 2, 3, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
#else
  gtk_grid_attach (GTK_GRID (t), data->lname, 2, 0, 1, 1);
  gtk_widget_set_hexpand (data->lname, TRUE);
#endif

  w = gtk_label_new (NULL);
  gtk_label_set_markup (GTK_LABEL (w), _("<b>Sizes:</b>"));
  gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
#if !GTK_CHECK_VERSION(3,0,0)
  gtk_table_attach (GTK_TABLE (t), w, 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
#else
  gtk_grid_attach (GTK_GRID (t), w, 1, 1, 1, 1);
#endif
  data->lsize = gtk_label_new (NULL);
  gtk_label_set_selectable (GTK_LABEL (data->lsize), TRUE);
  gtk_misc_set_alignment (GTK_MISC (data->lsize), 0, 0.5);
#if !GTK_CHECK_VERSION(3,0,0)
  gtk_table_attach (GTK_TABLE (t), data->lsize, 2, 3, 1, 2, GTK_FILL | GTK_EXPAND, 0, 0, 0);
#else
  gtk_grid_attach (GTK_GRID (t), data->lsize, 2, 1, 1, 1);
  gtk_widget_set_hexpand (data->lsize, TRUE);
#endif

  w = gtk_label_new (NULL);
  gtk_label_set_markup (GTK_LABEL (w), _("<b>Filename:</b>"));
  gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
#if !GTK_CHECK_VERSION(3,0,0)
  gtk_table_attach (GTK_TABLE (t), w, 1, 2, 2, 3, GTK_FILL, 0, 0, 0);
#else
  gtk_grid_attach (GTK_GRID (t), w, 1, 2, 1, 1);
#endif
  data->lfile = gtk_label_new (NULL);
  gtk_label_set_selectable (GTK_LABEL (data->lfile), TRUE);
  gtk_misc_set_alignment (GTK_MISC (data->lfile), 0, 0.5);
#if !GTK_CHECK_VERSION(3,0,0)
  gtk_table_attach (GTK_TABLE (t), data->lfile, 2, 3, 2, 3, GTK_FILL | GTK_EXPAND, 0, 0, 0);
#else
  gtk_grid_attach (GTK_GRID (t), data->lfile, 2, 2, 1, 1);
  gtk_widget_set_hexpand (data->lfile, TRUE);
#endif

  /* create icon browser */
#if !GTK_CHECK_VERSION(3,0,0)
  p = gtk_hpaned_new ();
#else
  p = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
#endif
  gtk_paned_set_position (GTK_PANED (p), 150);
  gtk_box_pack_start (GTK_BOX (box), p, TRUE, TRUE, 2);

  /* create category list */
  w = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (w), GTK_SHADOW_ETCHED_IN);
  gtk_paned_add1 (GTK_PANED (p), w);

  store = gtk_list_store_new (1, G_TYPE_STRING);

  data->cat_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (data->cat_list), TRUE);
  gtk_container_add (GTK_CONTAINER (w), data->cat_list);

  sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->cat_list));
  g_signal_connect (G_OBJECT (sel), "changed", G_CALLBACK (select_cat), data);

  r = gtk_cell_renderer_text_new ();
  col = gtk_tree_view_column_new_with_attributes (_("Category"), r, "text", 0, NULL);
  gtk_tree_view_column_set_expand (col, TRUE);
  gtk_tree_view_append_column (GTK_TREE_VIEW (data->cat_list), col);

  /* load icons category */
  data->icons = g_hash_table_new (g_direct_hash, g_direct_equal);
  icat = gtk_icon_theme_list_contexts (data->theme);
  for (ic = icat; ic; ic = ic->next)
    {
      GtkTreeIter iter;

      gtk_list_store_append (store, &iter);
      gtk_list_store_set (store, &iter, 0, ic->data, -1);
      g_free (ic->data);
    }
  g_list_free (icat);

  /* create icons list */
  w = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (w), GTK_SHADOW_ETCHED_IN);
  gtk_paned_add2 (GTK_PANED (p), w);

  data->icon_list = gtk_tree_view_new ();
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (data->icon_list), TRUE);
  gtk_container_add (GTK_CONTAINER (w), data->icon_list);

  sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->icon_list));
  g_signal_connect (G_OBJECT (sel), "changed", G_CALLBACK (select_icon), data);

  col = gtk_tree_view_column_new ();
  gtk_tree_view_column_set_title (col, _("Icons"));
  gtk_tree_view_column_set_sort_column_id (col, 1);
  r = gtk_cell_renderer_pixbuf_new ();
  gtk_tree_view_column_pack_start (col, r, FALSE);
  gtk_tree_view_column_set_attributes (col, r, "pixbuf", 0, NULL);
  r = gtk_cell_renderer_text_new ();
  gtk_tree_view_column_pack_start (col, r, FALSE);
  gtk_tree_view_column_set_attributes (col, r, "text", 1, NULL);
  gtk_tree_view_column_set_expand (col, TRUE);
  gtk_tree_view_append_column (GTK_TREE_VIEW (data->icon_list), col);

  gtk_widget_show_all (data->win);

  /* run it */
  gtk_main ();

  return 0;
}