static MateConfValue* combo_conv_from_widget_term_flag (MateConfPropertyEditor *peditor, const MateConfValue *value)
{
    MateConfValue *ret;
    GList *handlers;
    gint index;
    MateDATermItem *item;

    g_object_get (G_OBJECT (peditor), "data", &handlers, NULL);
    index = mateconf_value_get_int (value);

    item = g_list_nth_data (handlers, index);
    ret = mateconf_value_new (MATECONF_VALUE_STRING);

    if (!item)
    {
        /* if item was not found, this is probably the "Custom" item */

        /* XXX: returning "" as the value here is not ideal, but required to
         * prevent the combo box from jumping back to the previous value if the
         * user has selected Custom */
        mateconf_value_set_string (ret, "");
        return ret;
    }
    else
    {
        mateconf_value_set_string (ret, item->exec_flag);
        return ret;
    }
}
Ejemplo n.º 2
0
static void
cb_dev_selected (GtkComboBox *box,
		 gpointer    data)
{
  MateVolumeAppletPreferences *prefs = data;
  /* MateVolumeApplet *applet = (MateVolumeApplet *) prefs->applet; */
  GtkTreeIter iter;

  if (gtk_combo_box_get_active_iter (box, &iter)) {
    gchar *label;
    MateConfValue *value;

    gtk_tree_model_get (gtk_combo_box_get_model (box),
			&iter, COL_LABEL, &label, -1);

    /* write to mateconf */
    value = mateconf_value_new (MATECONF_VALUE_STRING);
    mateconf_value_set_string (value, label);
    mate_panel_applet_mateconf_set_value (MATE_PANEL_APPLET (prefs->applet),
		      MATE_VOLUME_APPLET_KEY_ACTIVE_ELEMENT,
		      value, NULL);
    g_free (label);
    mateconf_value_free (value);
  }
}
static MateConfValue* web_combo_conv_from_widget (MateConfPropertyEditor *peditor, const MateConfValue *value)
{
    MateConfValue *ret;
    GList *handlers;
    gint index;
    MateDAWebItem *item;
    const gchar *command;
    MateDACapplet *capplet;

    g_object_get (G_OBJECT (peditor), "data", &capplet, NULL);

    index = mateconf_value_get_int (value);
    handlers = capplet->web_browsers;

    item = g_list_nth_data (handlers, index);

    ret = mateconf_value_new (MATECONF_VALUE_STRING);
    if (!item)
    {
        /* if item was not found, this is probably the "Custom" item */
        /* XXX: returning "" as the value here is not ideal, but required to
         * prevent the combo box from jumping back to the previous value if the
         * user has selected Custom */
        mateconf_value_set_string (ret, "");
        return ret;
    }
    else
    {
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (capplet->new_win_radiobutton)) && item->netscape_remote == TRUE)
            command = item->win_command;
        else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (capplet->new_tab_radiobutton)) && item->netscape_remote == TRUE)
            command = item->tab_command;
        else
            command = item->generic.command;

        mateconf_value_set_string (ret, command);
        return ret;
    }
}
static MateConfValue *
application_font_to_mateconf (MateConfPropertyEditor *peditor,
			   MateConfValue          *value)
{
  MateConfValue *new_value;
  const char *new_font;
  GtkWidget *font_button;
  gint danger_level;

  font_button = GTK_WIDGET (mateconf_property_editor_get_ui_control (peditor));
  g_return_val_if_fail (font_button != NULL, NULL);

  new_value = mateconf_value_new (MATECONF_VALUE_STRING);
  new_font = mateconf_value_get_string (value);
  if (font_dangerous (old_font)) {
    /* If we're already too large, we don't warn again. */
    mateconf_value_set_string (new_value, new_font);
    return new_value;
  }

  danger_level = font_dangerous (new_font);
  if (danger_level) {
    GtkWidget *warning_dialog, *apply_button;
    const gchar *warning_label;
    gchar *warning_label2;

    warning_label = _("Font may be too large");

    if (danger_level > MAX_FONT_POINT_WITHOUT_WARNING) {
      warning_label2 = g_strdup_printf (ngettext (
			"The font selected is %d point large, "
			"and may make it difficult to effectively "
			"use the computer.  It is recommended that "
			"you select a size smaller than %d.",
			"The font selected is %d points large, "
			"and may make it difficult to effectively "
			"use the computer. It is recommended that "
			"you select a size smaller than %d.",
			danger_level),
			danger_level,
			MAX_FONT_POINT_WITHOUT_WARNING);
    } else {
      warning_label2 = g_strdup_printf (ngettext (
			"The font selected is %d point large, "
			"and may make it difficult to effectively "
			"use the computer.  It is recommended that "
			"you select a smaller sized font.",
			"The font selected is %d points large, "
			"and may make it difficult to effectively "
			"use the computer. It is recommended that "
			"you select a smaller sized font.",
			danger_level),
			danger_level);
    }

    warning_dialog = gtk_message_dialog_new (NULL,
					     GTK_DIALOG_MODAL,
					     GTK_MESSAGE_WARNING,
					     GTK_BUTTONS_NONE,
					     "%s",
					     warning_label);

    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (warning_dialog),
					      "%s", warning_label2);

    gtk_dialog_add_button (GTK_DIALOG (warning_dialog),
			   _("Use previous font"), GTK_RESPONSE_CLOSE);

    apply_button = gtk_button_new_with_label (_("Use selected font"));

    gtk_button_set_image (GTK_BUTTON (apply_button), gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON));
    gtk_dialog_add_action_widget (GTK_DIALOG (warning_dialog), apply_button, GTK_RESPONSE_APPLY);
    gtk_widget_set_can_default (apply_button, TRUE);
    gtk_widget_show (apply_button);

    gtk_dialog_set_default_response (GTK_DIALOG (warning_dialog), GTK_RESPONSE_CLOSE);

    g_free (warning_label2);

    if (gtk_dialog_run (GTK_DIALOG (warning_dialog)) == GTK_RESPONSE_APPLY) {
      mateconf_value_set_string (new_value, new_font);
    } else {
      mateconf_value_set_string (new_value, old_font);
      gtk_font_button_set_font_name (GTK_FONT_BUTTON (font_button), old_font);
    }

    gtk_widget_destroy (warning_dialog);
  } else {
    mateconf_value_set_string (new_value, new_font);
  }

  return new_value;
}
Ejemplo n.º 5
0
/* load_history indicates whether the history list is being loaded at startup.
** If true then don't save the new entries with mateconf (since they are being read
** using mateconf
*/
void
append_history_entry(MCData *mcdata, const char * entry, gboolean load_history)
{
    MatePanelApplet *applet = mcdata->applet;
    MateConfValue *history;
    GSList *list = NULL;
    int pos, i;

    /* remove older dupes */
    for(pos = 0; pos <= MC_HISTORY_LIST_LENGTH - 1; pos++)
	{
	    if(exists_history_entry(pos) && strcmp(entry, history_command[pos]) == 0)
		/* dupe found */
		delete_history_entry(pos);
	}

    /* delete oldest entry */
    if(history_command[0] != NULL)
	free(history_command[0]);

    /* move entries */
    for(pos = 0; pos < MC_HISTORY_LIST_LENGTH - 1; pos++)
	{
	    history_command[pos] = history_command[pos+1];
	    /* printf("%s\n", history_command[pos]); */
	}

    /* append entry */
    history_command[MC_HISTORY_LIST_LENGTH - 1] = (char *)malloc(sizeof(char) * (strlen(entry) + 1));
    strcpy(history_command[MC_HISTORY_LIST_LENGTH - 1], entry);
    
    if (load_history)
    	return;

    /* If not writable, just keeps the history around for this session */
    if ( ! mc_key_writable (mcdata, "history"))
        return;
    	
    /* Save history - this seems like a waste to do it every time it's updated 
    ** but it doesn't seem to work when called on the destroy signal of the applet 
    */
    for(i = 0; i < MC_HISTORY_LIST_LENGTH; i++)
	{
	    MateConfValue *value_entry;
	    
	    value_entry = mateconf_value_new (MATECONF_VALUE_STRING);
	    if(exists_history_entry(i)) {
	    	mateconf_value_set_string (value_entry, (gchar *) get_history_entry(i));
	    	list = g_slist_append (list, value_entry);
	    }        
	    
	}

    history = mateconf_value_new (MATECONF_VALUE_LIST);
    if (list) {
    	mateconf_value_set_list_type (history, MATECONF_VALUE_STRING);
        mateconf_value_set_list (history, list);
        mate_panel_applet_mateconf_set_value (applet, "history", history, NULL);
    }
   
    while (list) {
    	MateConfValue *value = list->data;
    	mateconf_value_free (value);
    	list = g_slist_next (list);
    }
   
    mateconf_value_free (history);
    
}
Ejemplo n.º 6
0
static gboolean
cb_track_select (GtkTreeSelection *selection,
		 GtkTreeModel     *model,
		 GtkTreePath      *path,
		 gboolean          path_selected,
		 gpointer          data)
{
  MateVolumeAppletPreferences *prefs = data;
  GtkTreeIter iter;
  gchar *label;
  MateConfValue *value;
  GtkTreeSelection *sel;
  GString *mateconf_string;
  GstMixerTrack *selected_track; /* the track just selected */
  MateVolumeApplet *applet = (MateVolumeApplet*) prefs->applet; /* required to update the track settings */
  int volume_percent;

  if (prefs->track_lock)
    return TRUE;

  mateconf_string = g_string_new ("");

  /* get value */
  gtk_tree_model_get_iter (model, &iter, path);
  gtk_tree_model_get (model, &iter, COL_LABEL, &label, COL_TRACK, &selected_track, -1);
  sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (prefs->treeview));

  /* clear the list of selected tracks */
  if (applet->tracks) {
    g_list_free (applet->tracks);
    applet->tracks = NULL;
  }

  if (gtk_tree_selection_count_selected_rows (sel) > 0) {
    GList *lst;

    /* add the ones already selected */
    for (lst = gtk_tree_selection_get_selected_rows (sel, &model); lst != NULL; lst = lst->next) {
      GstMixerTrack *curr = NULL;
      gchar *it_label;

      gtk_tree_model_get_iter (model, &iter, lst->data);
      gtk_tree_model_get (model, &iter, COL_LABEL, &it_label, COL_TRACK, &curr, -1);

      /* grab the main volume (they will all be the same, so it doesn't matter 
       * which one we get) */
      volume_percent = mate_volume_applet_get_volume (prefs->mixer, curr);

      if (strcmp (it_label, label)) {
	applet->tracks = g_list_append (applet->tracks, curr);

	if (!path_selected) {
	  g_string_append_printf (mateconf_string, "%s:", curr->label);
	} else {
	  mateconf_string = g_string_append (mateconf_string, curr->label);
	}
      }
    }
    g_list_foreach (lst, (GFunc)gtk_tree_path_free, NULL);
    g_list_free (lst);
  }

  /* add the one just selected and adjust its volume if it's not the only one
   * selected */
  if (!path_selected) {
    GstMixerTrack *curr;

    gtk_tree_model_get_iter (model, &iter, path);
    gtk_tree_model_get (model, &iter, COL_TRACK, &curr, -1);
    mateconf_string = g_string_append (mateconf_string, curr->label);

    applet->tracks = g_list_append (applet->tracks, curr);

    /* unify the volume of this track with the others already added */
    if (g_list_length (applet->tracks) > 1) {
      mate_volume_applet_adjust_volume (prefs->mixer, curr, volume_percent);
    }
  }

  /* write to mateconf */
  value = mateconf_value_new (MATECONF_VALUE_STRING);
  mateconf_value_set_string (value, mateconf_string->str);
  mate_panel_applet_mateconf_set_value (MATE_PANEL_APPLET (prefs->applet),
				MATE_VOLUME_APPLET_KEY_ACTIVE_TRACK,
				value, NULL);
  g_free (label);
  g_string_free (mateconf_string, TRUE);
  mateconf_value_free (value);
  
  return TRUE;
}
MateConfValue* 
mateconf_value_new_from_string(MateConfValueType type, const gchar* value_str,
                             GError** err)
{
  MateConfValue* value;

  g_return_val_if_fail (type != MATECONF_VALUE_LIST, NULL);
  g_return_val_if_fail (type != MATECONF_VALUE_PAIR, NULL);

  value = mateconf_value_new(type);

  switch (type)
    {
    case MATECONF_VALUE_INT:
      {
        char* endptr = NULL;
        glong result;

        errno = 0;
        result = strtol(value_str, &endptr, 10);

        if (endptr == value_str)
          {
            if (err)
              *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR,
                                      _("Didn't understand `%s' (expected integer)"),
                                      value_str);
            
            mateconf_value_free(value);
            value = NULL;
          }
        else if (errno == ERANGE)
          {
            if (err)
              *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR,
                                      _("Integer `%s' is too large or small"),
                                      value_str);
            mateconf_value_free(value);
            value = NULL;
          }
        else
          mateconf_value_set_int(value, result);
      }
      break;
    case MATECONF_VALUE_FLOAT:
      {
        double num;

        if (mateconf_string_to_double(value_str, &num))
          {
            mateconf_value_set_float(value, num);
          }
        else
          {
            if (err)
              *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR,
                                      _("Didn't understand `%s' (expected real number)"),
                                     value_str);
            
            mateconf_value_free(value);
            value = NULL;
          }
      }
      break;
    case MATECONF_VALUE_STRING:      
      if (!g_utf8_validate (value_str, -1, NULL))
        {
          g_set_error (err, MATECONF_ERROR,
                       MATECONF_ERROR_PARSE_ERROR,
                       _("Text contains invalid UTF-8"));
          mateconf_value_free(value);
          value = NULL;
        }
      else
        {
          mateconf_value_set_string(value, value_str);
        }
      break;
    case MATECONF_VALUE_BOOL:
      switch (*value_str)
        {
        case 't':
        case 'T':
        case '1':
        case 'y':
        case 'Y':
          mateconf_value_set_bool(value, TRUE);
          break;

        case 'f':
        case 'F':
        case '0':
        case 'n':
        case 'N':
          mateconf_value_set_bool(value, FALSE);
          break;
          
        default:
          if (err)
            *err = mateconf_error_new(MATECONF_ERROR_PARSE_ERROR,
                                   _("Didn't understand `%s' (expected true or false)"),
                                   value_str);
          
          mateconf_value_free(value);
          value = NULL;
          break;
        }
      break;
    case MATECONF_VALUE_LIST:
    case MATECONF_VALUE_PAIR:
    default:
      g_assert_not_reached();
      break;
    }

  return value;
}