Ejemplo n.º 1
0
static void
gail_toggle_button_real_notify_gtk (GObject           *obj,
                                    GParamSpec        *pspec)
{
  GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
  AtkObject *atk_obj;

  atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));

  if (strcmp (pspec->name, "inconsistent") == 0)
    atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED,
                       (gtk_widget_get_sensitive (GTK_WIDGET (toggle_button)) &&
                        !gtk_toggle_button_get_inconsistent (toggle_button)));
  else if (strcmp (pspec->name, "sensitive") == 0)
    {
      /* Need to override gailwidget behavior of notifying for ENABLED */
      gboolean sensitive;
      gboolean enabled;
      sensitive = gtk_widget_get_sensitive (GTK_WIDGET (toggle_button));
      enabled = sensitive &&
                !gtk_toggle_button_get_inconsistent (toggle_button);
    atk_object_notify_state_change (atk_obj, ATK_STATE_SENSITIVE, sensitive);
    atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, enabled);
    }
  else
    GAIL_WIDGET_CLASS (gail_toggle_button_parent_class)->notify_gtk (obj, pspec);
}
Ejemplo n.º 2
0
static AtkStateSet*
gail_toggle_button_ref_state_set (AtkObject *accessible)
{
  AtkStateSet *state_set;
  GtkToggleButton *toggle_button;
  GtkWidget *widget;

  state_set = ATK_OBJECT_CLASS (gail_toggle_button_parent_class)->ref_state_set (accessible);
  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
 
  if (widget == NULL)
    return state_set;

  toggle_button = GTK_TOGGLE_BUTTON (widget);

  if (gtk_toggle_button_get_active (toggle_button))
    atk_state_set_add_state (state_set, ATK_STATE_CHECKED);

  if (gtk_toggle_button_get_inconsistent (toggle_button))
    {
      atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
      atk_state_set_add_state (state_set, ATK_STATE_INDETERMINATE);
    }
 
  return state_set;
}
static void
gtk_toggle_button_accessible_notify_gtk (GObject    *obj,
                                         GParamSpec *pspec)
{
  GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
  AtkObject *atk_obj;
  gboolean sensitive;
  gboolean inconsistent;

  atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));
  sensitive = gtk_widget_get_sensitive (GTK_WIDGET (toggle_button));
  inconsistent = gtk_toggle_button_get_inconsistent (toggle_button);

  if (strcmp (pspec->name, "inconsistent") == 0)
    {
      atk_object_notify_state_change (atk_obj, ATK_STATE_INDETERMINATE, inconsistent);
      atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
    }
  else if (strcmp (pspec->name, "sensitive") == 0)
    {
      /* Need to override gailwidget behavior of notifying for ENABLED */
      atk_object_notify_state_change (atk_obj, ATK_STATE_SENSITIVE, sensitive);
      atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
    }
  else
    GTK_WIDGET_ACCESSIBLE_CLASS (gtk_toggle_button_accessible_parent_class)->notify_gtk (obj, pspec);
}
Ejemplo n.º 4
0
static gboolean
panel_toggle_button_draw (GtkWidget *widget, cairo_t *cr)
{
  GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
  GtkStateType state_type;
  GtkShadowType shadow_type;
  GtkAllocation allocation;
  GtkStyleContext *context = gtk_widget_get_style_context (widget);
  GtkStateFlags flags = 0;

  state_type = gtk_widget_get_state (widget);
    
  /* FIXME: someone make this layout work nicely for all themes
   * Currently I'm trying to imitate the volume applet's widget */
  if (gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (widget))) {
    if (state_type == GTK_STATE_ACTIVE)
      state_type = GTK_STATE_NORMAL;
    shadow_type = GTK_SHADOW_ETCHED_IN;
  } else {
    shadow_type = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
  }
  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
    state_type = GTK_STATE_SELECTED;
  /* FIXME: better detail? */
  gtk_widget_get_allocation (widget, &allocation);
  gtk_style_context_add_class (context, "togglebutton");
  switch (state_type)
    {
    case GTK_STATE_PRELIGHT:
      flags |= GTK_STATE_FLAG_PRELIGHT;
      break;
    case GTK_STATE_SELECTED:
      flags |= GTK_STATE_FLAG_SELECTED;
      break;
    case GTK_STATE_INSENSITIVE:
      flags |= GTK_STATE_FLAG_INSENSITIVE;
      break;
    case GTK_STATE_ACTIVE:
      flags |= GTK_STATE_FLAG_ACTIVE;
      break;
    case GTK_STATE_FOCUSED:
      flags |= GTK_STATE_FLAG_FOCUSED;
      break;
    case GTK_STATE_NORMAL:
    case GTK_STATE_INCONSISTENT:
    default:
      break;
  }

  gtk_style_context_set_state (context, flags);
  gtk_render_background (context, cr, (gdouble) allocation.x, (gdouble) allocation.y,
                                 (gdouble) allocation.width, (gdouble) allocation.height);
  (void) shadow_type;

  if (child)
    gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr);
  
  return FALSE;
}
Ejemplo n.º 5
0
static int gtkToggleGetCheck(Ihandle* ih)
{
  if (gtk_toggle_button_get_inconsistent((GtkToggleButton*)ih->handle))
    return -1;
  if (gtk_toggle_button_get_active((GtkToggleButton*)ih->handle))
    return 1;
  else
    return 0;
}
Ejemplo n.º 6
0
static void gtk_checkbox_toggled_callback(GtkWidget *widget, wxCheckBox *cb)
{
    if (!cb->m_hasVMT) return;

    if (g_blockEventsOnDrag) return;

    // Transitions for 3state checkbox must be done manually, GTK's checkbox
    // is 2state with additional "undetermined state" flag which isn't
    // changed automatically:
    if (cb->Is3State())
    {
        GtkToggleButton *toggle = GTK_TOGGLE_BUTTON(widget);

        if (cb->Is3rdStateAllowedForUser())
        {
            // The 3 states cycle like this when clicked:
            // checked -> undetermined -> unchecked -> checked -> ...
            bool active = gtk_toggle_button_get_active(toggle) != 0;
            bool inconsistent = gtk_toggle_button_get_inconsistent(toggle) != 0;

            cb->GTKDisableEvents();

            if (!active && !inconsistent)
            {
                // checked -> undetermined
                gtk_toggle_button_set_active(toggle, true);
                gtk_toggle_button_set_inconsistent(toggle, true);
            }
            else if (!active && inconsistent)
            {
                // undetermined -> unchecked
                gtk_toggle_button_set_inconsistent(toggle, false);
            }
            else if (active && !inconsistent)
            {
                // unchecked -> checked
                // nothing to do
            }
            else
            {
                wxFAIL_MSG(wxT("3state wxCheckBox in unexpected state!"));
            }

            cb->GTKEnableEvents();
        }
        else
        {
            // user's action unsets undetermined state:
            gtk_toggle_button_set_inconsistent(toggle, false);
        }
    }

    wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
    event.SetInt(cb->Get3StateValue());
    event.SetEventObject(cb);
    cb->HandleWindowEvent(event);
}
Ejemplo n.º 7
0
wxCheckBoxState wxCheckBox::DoGet3StateValue() const
{
    if (gtk_toggle_button_get_inconsistent(GTK_TOGGLE_BUTTON(m_widgetCheckbox)))
    {
        return wxCHK_UNDETERMINED;
    }
    else
    {
        return GetValue() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
    }
}
static void
toggle_clicked                                  (GtkButton *button, 
                                                 gpointer unused)
{
    GtkToggleButton *t_b = GTK_TOGGLE_BUTTON (button);

    /* we have to remove the inconsistent state ourselves */
    if (gtk_toggle_button_get_inconsistent (t_b))
    {
        gtk_toggle_button_set_inconsistent (t_b, FALSE);
        gtk_toggle_button_set_active (t_b, FALSE);
    }
}
Ejemplo n.º 9
0
static void
gail_toggle_button_real_notify_gtk (GObject           *obj,
                                    GParamSpec        *pspec)
{
  GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
  AtkObject *atk_obj;

  atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));

  if (strcmp (pspec->name, "inconsistent") == 0)
    atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED,
                       !gtk_toggle_button_get_inconsistent (toggle_button));
  else
    GAIL_WIDGET_CLASS (gail_toggle_button_parent_class)->notify_gtk (obj, pspec);
}
static void array_button_toggled_cb(GtkToggleButton *togglebutton, gpointer user_data) {
	RyosconfigLayerIlluminationDialog *dialog = RYOSCONFIG_LAYER_ILLUMINATION_DIALOG(user_data);
	RyosconfigLayerIlluminationDialogPrivate *priv = dialog->priv;
	guint8 value;
	guint8 *data;

	if (gtk_toggle_button_get_inconsistent(togglebutton)) {
		gtk_toggle_button_set_inconsistent(togglebutton, FALSE);
		gtk_toggle_button_set_active(togglebutton, TRUE);
	}

	value = key_state(dialog, gtk_toggle_button_get_active(togglebutton));
	data = g_object_get_data(G_OBJECT(togglebutton), array_key);
	ryos_custom_lights_set_from_array(priv->light_layer, data, value);

	ryosconfig_layer_send(dialog);
}
Ejemplo n.º 11
0
static void on_exec_toggled (GtkToggleButton *btn, FmFilePropData *data)
{
    // Bypass the default handler
    g_signal_stop_emission_by_name ( btn, "toggled" );
    /* Block this handler while we are changing the state of buttons,
      or this handler will be called recursively. */
    g_signal_handlers_block_matched ( btn, G_SIGNAL_MATCH_FUNC, 0,
                                      0, NULL, on_exec_toggled, NULL );

    if ( gtk_toggle_button_get_inconsistent ( btn ) )
    {
        gtk_toggle_button_set_inconsistent ( btn, FALSE );
        gtk_toggle_button_set_active ( btn, TRUE );
    }
    else if ( gtk_toggle_button_get_active ( btn ) )
    {
        gtk_toggle_button_set_inconsistent ( btn, TRUE );
    }

    g_signal_handlers_unblock_matched ( btn, G_SIGNAL_MATCH_FUNC, 0,
                                        0, NULL, on_exec_toggled, NULL );
}
Ejemplo n.º 12
0
void
on_dlg_response ( GtkDialog *dialog,
                                gint response_id,
                                gpointer user_data )
{
    FilePropertiesDialogData * data;
    PtkFileTask* task;
    gboolean mod_change;
    uid_t uid = -1;
    gid_t gid = -1;
    const char* owner_name;
    const char* group_name;
    int i;
    GList* l;
    GList* file_list;
    char* file_path;
    GtkWidget* ask_recursive;
    VFSFileInfo* file;
    GtkAllocation allocation;

    gtk_widget_get_allocation ( GTK_WIDGET( dialog ), &allocation );
    
    int width = allocation.width;
    int height = allocation.height;
    if ( width && height )
    {
        char* str = g_strdup_printf( "%d", width );
        xset_set( "app_dlg", "s", str );
        g_free( str );
        str = g_strdup_printf( "%d", height );
        xset_set( "app_dlg", "z", str );
        g_free( str );
    }

    data = ( FilePropertiesDialogData* ) g_object_get_data( G_OBJECT( dialog ),
                                                            "DialogData" );
    if ( data )
    {
        if ( data->update_label_timer )
            g_source_remove( data->update_label_timer );
        data->cancel = TRUE;

        if ( data->calc_size_thread )
            g_thread_join( data->calc_size_thread );

        if ( response_id == GTK_RESPONSE_OK )
        {
            GtkWidget* open_with;

            /* Set default action for mimetype */
            if( ( open_with = (GtkWidget*)g_object_get_data( G_OBJECT(dialog), "open_with" ) ) )
            {
                GtkTreeModel* model = gtk_combo_box_get_model( GTK_COMBO_BOX(open_with) );
                GtkTreeIter it;

                if( model && gtk_combo_box_get_active_iter( GTK_COMBO_BOX(open_with), &it ) )
                {
                    char* action;
                    gtk_tree_model_get( model, &it, 2, &action, -1 );
                    if( action )
                    {
                        file = ( VFSFileInfo* ) data->file_list->data;
                        VFSMimeType* mime = vfs_file_info_get_mime_type( file );
                        vfs_mime_type_set_default_action( mime, action );
                        vfs_mime_type_unref( mime );
                        g_free( action );
                    }
                }
            }

            /* Check if we need chown */
            owner_name = gtk_entry_get_text( data->owner );
            if ( owner_name && *owner_name &&
                 (!data->owner_name || strcmp( owner_name, data->owner_name ) ) )
            {
                uid = uid_from_name( owner_name );
                if ( uid == -1 )
                {
                    ptk_show_error( GTK_WINDOW( dialog ), _("Error"), _( "Invalid User" ) );
                    return ;
                }
            }
            group_name = gtk_entry_get_text( data->group );
            if ( group_name && *group_name &&
                 (!data->group_name || strcmp( group_name, data->group_name ) ) )
            {
                gid = gid_from_name( group_name );
                if ( gid == -1 )
                {
                    ptk_show_error( GTK_WINDOW( dialog ), _("Error"), _( "Invalid Group" ) );
                    return ;
                }
            }

            for ( i = 0; i < N_CHMOD_ACTIONS; ++i )
            {
                if ( gtk_toggle_button_get_inconsistent( data->chmod_btns[ i ] ) )
                {
                    data->chmod_states[ i ] = 2;  /* Don't touch this bit */
                }
                else if ( data->chmod_states[ i ] != gtk_toggle_button_get_active( data->chmod_btns[ i ] ) )
                {
                    mod_change = TRUE;
                    data->chmod_states[ i ] = gtk_toggle_button_get_active( data->chmod_btns[ i ] );
                }
                else /* Don't change this bit */
                {
                    data->chmod_states[ i ] = 2;
                }
            }

            if ( uid != -1 || gid != -1 || mod_change )
            {
                file_list = NULL;
                for ( l = data->file_list; l; l = l->next )
                {
                    file = ( VFSFileInfo* ) l->data;
                    file_path = g_build_filename( data->dir_path,
                            vfs_file_info_get_name( file ), NULL );
                    file_list = g_list_prepend( file_list, file_path );
                }

                task = ptk_file_task_new( VFS_FILE_TASK_CHMOD_CHOWN,
                                          file_list,
                                          NULL,
                                          GTK_WINDOW(gtk_widget_get_parent( GTK_WIDGET( dialog ) )),
                                          NULL );
                //MOD
                ptk_file_task_set_recursive( task,
                                        gtk_toggle_button_get_active(
                                        GTK_TOGGLE_BUTTON( data->recurse ) ) );
                /*
                for ( l = data->file_list; l; l = l->next )
                {
                    file = ( VFSFileInfo* ) l->data;
                    if ( vfs_file_info_is_dir( file ) )
                    {
                        ask_recursive = gtk_message_dialog_new(
                                            GTK_WINDOW( data->dlg ),
                                            GTK_DIALOG_MODAL,
                                            GTK_MESSAGE_QUESTION,
                                            GTK_BUTTONS_YES_NO,
                                            _( "Do you want to recursively apply these changes to all files and sub-folders?" ) );
                        ptk_file_task_set_recursive( task,
                                ( GTK_RESPONSE_YES == gtk_dialog_run( GTK_DIALOG( ask_recursive ) ) ) );
                        gtk_widget_destroy( ask_recursive );
                        break;
                    }
                }
                */
                if ( mod_change )
                {
                     /* If the permissions of file has been changed by the user */
                    ptk_file_task_set_chmod( task, data->chmod_states );
                }
                /* For chown */
                ptk_file_task_set_chown( task, uid, gid );
                ptk_file_task_run( task );

                /*
                * This file list will be freed by file operation, so we don't
                * need to do this. Just set the pointer to NULL.
                */
                data->file_list = NULL;
            }
        }

        g_free( data->owner_name );
        g_free( data->group_name );
        /*
         *NOTE: File operation chmod/chown will free the list when it's done,
         *and we only need to free it when there is no file operation applyed.
        */
        g_slice_free( FilePropertiesDialogData, data );
    }

    gtk_widget_destroy( GTK_WIDGET( dialog ) );
}
Ejemplo n.º 13
0
static int
extract_cb (GtkWidget   *w,
	    DialogData  *data)
{
	FrWindow   *window = data->window;
	gboolean    do_not_extract = FALSE;
	char       *extract_to_dir;
	gboolean    overwrite;
	gboolean    skip_newer;
	gboolean    selected_files;
	gboolean    pattern_files;
	gboolean    junk_paths;
	GList      *file_list;
	char       *base_dir = NULL;
	GError     *error = NULL;

	data->extract_clicked = TRUE;

	/* collect extraction options. */

	extract_to_dir = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (data->dialog));

	/* check directory existence. */

	if (! uri_is_dir (extract_to_dir)) {
		if (! ForceDirectoryCreation) {
			GtkWidget *d;
			int        r;
			char      *folder_name;
			char      *msg;

			folder_name = g_filename_display_name (extract_to_dir);
			msg = g_strdup_printf (_("Destination folder \"%s\" does not exist.\n\nDo you want to create it?"), folder_name);
			g_free (folder_name);

			d = _gtk_message_dialog_new (GTK_WINDOW (data->dialog),
						     GTK_DIALOG_MODAL,
						     GTK_STOCK_DIALOG_QUESTION,
						     msg,
						     NULL,
						     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
						     _("Create _Folder"), GTK_RESPONSE_YES,
						     NULL);

			gtk_dialog_set_default_response (GTK_DIALOG (d), GTK_RESPONSE_YES);
			r = gtk_dialog_run (GTK_DIALOG (d));
			gtk_widget_destroy (GTK_WIDGET (d));

			g_free (msg);

			if (r != GTK_RESPONSE_YES)
				do_not_extract = TRUE;
		}

		if (! do_not_extract && ! ensure_dir_exists (extract_to_dir, 0755, &error)) {
			GtkWidget  *d;

			d = _gtk_error_dialog_new (GTK_WINDOW (window),
						   GTK_DIALOG_DESTROY_WITH_PARENT,
						   NULL,
						   _("Extraction not performed"),
						   _("Could not create the destination folder: %s."),
						   error->message);
			gtk_dialog_run (GTK_DIALOG (d));
			gtk_widget_destroy (GTK_WIDGET (d));

			g_error_free (error);

			return FALSE;
		}
	}

	if (do_not_extract) {
		GtkWidget *d;

		d = _gtk_message_dialog_new (GTK_WINDOW (window),
					     GTK_DIALOG_DESTROY_WITH_PARENT,
					     GTK_STOCK_DIALOG_WARNING,
					     _("Extraction not performed"),
					     NULL,
					     GTK_STOCK_OK, GTK_RESPONSE_OK,
					     NULL);
		gtk_dialog_set_default_response (GTK_DIALOG (d), GTK_RESPONSE_OK);
		gtk_dialog_run (GTK_DIALOG (d));
		gtk_widget_destroy (GTK_WIDGET (d));

		if (fr_window_is_batch_mode (data->window))
			gtk_widget_destroy (data->dialog);

		return FALSE;
	}

	/* check extraction directory permissions. */

	if (uri_is_dir (extract_to_dir)
	    && ! check_permissions (extract_to_dir, R_OK | W_OK)) 
	{
		GtkWidget *d;
		char      *utf8_path;

		utf8_path = g_filename_display_name (extract_to_dir);

		d = _gtk_error_dialog_new (GTK_WINDOW (window),
					   GTK_DIALOG_DESTROY_WITH_PARENT,
					   NULL,
					   _("Extraction not performed"),
					   _("You don't have the right permissions to extract archives in the folder \"%s\""),
					   utf8_path);
		gtk_dialog_run (GTK_DIALOG (d));
		gtk_widget_destroy (GTK_WIDGET (d));

		g_free (utf8_path);
		g_free (extract_to_dir);

		return FALSE;
	}

	fr_window_set_extract_default_dir (window, extract_to_dir, TRUE);

	overwrite = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->e_overwrite_checkbutton));
	skip_newer = ! gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (data->e_not_newer_checkbutton)) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->e_not_newer_checkbutton));
	junk_paths = ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->e_recreate_dir_checkbutton));

	g_settings_set_boolean (data->settings, PREF_EXTRACT_OVERWRITE, overwrite);
	if (! gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (data->e_not_newer_checkbutton)))
	g_settings_set_boolean (data->settings, PREF_EXTRACT_SKIP_NEWER, skip_newer);
	g_settings_set_boolean (data->settings, PREF_EXTRACT_RECREATE_FOLDERS, ! junk_paths);

	selected_files = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->e_selected_radiobutton));
	pattern_files = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->e_files_radiobutton));

	/* create the file list. */

	file_list = NULL;

	if (selected_files) {
		file_list = data->selected_files;
		data->selected_files = NULL;       /* do not the list when destroying the dialog. */
	}
	else if (pattern_files) {
		const char *pattern;

		pattern = gtk_entry_get_text (GTK_ENTRY (data->e_files_entry));
		file_list = fr_window_get_file_list_pattern (window, pattern);
		if (file_list == NULL) {
			gtk_widget_destroy (data->dialog);
			g_free (extract_to_dir);
			return FALSE;
		}
	}

	if (selected_files) {
		base_dir = data->base_dir_for_selection;
		data->base_dir_for_selection = NULL;
	}
	else
		base_dir = NULL;

	/* close the dialog. */

	gtk_widget_destroy (data->dialog);

	/* extract ! */

	fr_window_archive_extract (window,
				   file_list,
				   extract_to_dir,
				   base_dir,
				   skip_newer,
				   overwrite ? FR_OVERWRITE_YES : FR_OVERWRITE_NO,
				   junk_paths,
				   TRUE);

	path_list_free (file_list);
	g_free (extract_to_dir);
	g_free (base_dir);

	return TRUE;
}
static void
hildon_font_selection_dialog_get_property       (GObject *object,
                                                 guint prop_id,
                                                 GValue *value,
                                                 GParamSpec *pspec)
{
    gint i;
    GdkColor color;

    HildonFontSelectionDialogPrivate *priv =
        HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(object);

    g_assert (priv);

    switch (prop_id)
    {
        case PROP_FAMILY:
            i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_type));
            if(i >= 0 && i < priv->n_families)
                g_value_set_string(value, 
                        pango_font_family_get_name (priv->families[i]));
            else
                g_value_set_string (value, "Sans");
                /* FIXME Bad hardcoding here */
            break;

        case PROP_FAMILY_SET:
            i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_type));
            if(i >= 0 && i < priv->n_families)
                g_value_set_boolean (value, TRUE);
            else
                g_value_set_boolean (value, FALSE);
            break;

        case PROP_SIZE:
            i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_size));
            if(i >= 0 && i < G_N_ELEMENTS (font_sizes))
                g_value_set_int (value, font_sizes[i]);
            else
                g_value_set_int (value, 16);
            break;

        case PROP_SIZE_SET:
            i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_size));
            if(i >= 0 && i < G_N_ELEMENTS (font_sizes))
                g_value_set_boolean (value, TRUE);
            else
                g_value_set_boolean (value, FALSE);
            break;

        case PROP_COLOR:
            hildon_color_button_get_color
                (HILDON_COLOR_BUTTON (priv->font_color_button), &color);
            g_value_set_boxed (value, (gconstpointer) &color);
            break;

        case PROP_COLOR_SET:
            g_value_set_boolean (value, priv->color_set);
            break;

        case PROP_BOLD:
            g_value_set_boolean (value, 
                    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->chk_bold)));
            break;

        case PROP_BOLD_SET:
            g_value_set_boolean (value,
                    ! gtk_toggle_button_get_inconsistent
                    (GTK_TOGGLE_BUTTON (priv->chk_bold)));
            break;

        case PROP_ITALIC:
            g_value_set_boolean (value, 
                    gtk_toggle_button_get_active
                    (GTK_TOGGLE_BUTTON (priv->chk_italic)));
            break;

        case PROP_ITALIC_SET:
            g_value_set_boolean (value,
                    ! gtk_toggle_button_get_inconsistent
                    (GTK_TOGGLE_BUTTON (priv->chk_italic)));
            break;

        case PROP_UNDERLINE:
            g_value_set_boolean (value, 
                    gtk_toggle_button_get_active
                    (GTK_TOGGLE_BUTTON (priv->chk_underline)));
            break;

        case PROP_UNDERLINE_SET:
            g_value_set_boolean (value,
                    ! gtk_toggle_button_get_inconsistent
                    (GTK_TOGGLE_BUTTON (priv->chk_underline)));
            break;

        case PROP_STRIKETHROUGH:
            g_value_set_boolean(value, 
                    gtk_toggle_button_get_active
                    (GTK_TOGGLE_BUTTON (priv->chk_strikethrough)));
            break;

        case PROP_STRIKETHROUGH_SET:
            g_value_set_boolean(value,
                    ! gtk_toggle_button_get_inconsistent
                    (GTK_TOGGLE_BUTTON (priv->chk_strikethrough)));
            break;

        case PROP_POSITION:
            i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_positioning));
            if(i == 1) /* super */
                g_value_set_int (value, 1);
            else if(i == 2)/* sub */
                g_value_set_int (value, -1);
            else
                g_value_set_int (value, 0);
            break;

        case PROP_FONT_SCALING:
            g_value_set_double (value, priv->font_scaling);
            break;

        case PROP_POSITION_SET:
            i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_positioning));
            if(i >= 0 && i < 3)
                g_value_set_boolean (value, TRUE);
            else
                g_value_set_boolean (value, FALSE);
            break;

        case PROP_PREVIEW_TEXT:
            g_value_set_string (value,
                    hildon_font_selection_dialog_get_preview_text (HILDON_FONT_SELECTION_DIALOG (object)));
            break;

        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
            break;
    }
}
Ejemplo n.º 15
0
GValue*
ghb_widget_value(GtkWidget *widget)
{
    GValue *value = NULL;
    const gchar *name;
    GType type;

    if (widget == NULL)
    {
        g_debug("NULL widget\n");
        return NULL;
    }

    type = G_OBJECT_TYPE(widget);
    name = ghb_get_setting_key(widget);
    g_debug("ghb_widget_value widget (%s)\n", name);
    if (type == GTK_TYPE_ENTRY)
    {
        const gchar *str = gtk_entry_get_text(GTK_ENTRY(widget));
        value = ghb_string_value_new(str);
    }
    else if (type == GTK_TYPE_RADIO_BUTTON)
    {
        g_debug("\tradio_button");
        gboolean bval;
        bval = gtk_toggle_button_get_inconsistent(GTK_TOGGLE_BUTTON(widget));
        if (bval)
        {
            value = ghb_boolean_value_new(FALSE);
        }
        else
        {
            bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
            value = ghb_boolean_value_new(bval);
        }
    }
    else if (type == GTK_TYPE_CHECK_BUTTON)
    {
        g_debug("\tcheck_button");
        gboolean bval;
        bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
        value = ghb_boolean_value_new(bval);
    }
    else if (type == GTK_TYPE_TOGGLE_TOOL_BUTTON)
    {
        g_debug("\ttoggle_tool_button");
        gboolean bval;
        bval = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
        value = ghb_boolean_value_new(bval);
    }
    else if (type == GTK_TYPE_TOGGLE_BUTTON)
    {
        g_debug("\ttoggle_button");
        gboolean bval;
        bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
        value = ghb_boolean_value_new(bval);
    }
    else if (type == GTK_TYPE_CHECK_MENU_ITEM)
    {
        g_debug("\tcheck_menu_item");
        gboolean bval;
        bval = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
        value = ghb_boolean_value_new(bval);
    }
    else if (type == GTK_TYPE_COMBO_BOX)
    {
        g_debug("\tcombo_box");
        GtkTreeModel *store;
        GtkTreeIter iter;
        gchar *shortOpt;

        store = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
        if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter))
        {
            gtk_tree_model_get(store, &iter, 2, &shortOpt, -1);
            value = ghb_string_value_new(shortOpt);
            g_free(shortOpt);
        }
        else if (gtk_combo_box_get_has_entry(GTK_COMBO_BOX(widget)))
        {
            const gchar *str;
            str = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(widget))));
            if (str == NULL) str = "";
            value = ghb_string_value_new(str);
        }
        else
        {
            value = ghb_string_value_new("");
        }
    }
    else if (type == GTK_TYPE_SPIN_BUTTON)
    {
        gint ival;
        ival = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
        value = ghb_int64_value_new(ival);
    }
    else if (type == GTK_TYPE_SCALE)
    {
        gdouble dval;
        gint digits;

        digits = gtk_scale_get_digits(GTK_SCALE(widget));
        dval = gtk_range_get_value(GTK_RANGE(widget));
        if (digits)
        {
            value = ghb_double_value_new(dval);
        }
        else
        {
            value = ghb_int_value_new(dval);
        }
    }
    else if (type == GTK_TYPE_SCALE_BUTTON)
    {
        gdouble dval;

        dval = gtk_scale_button_get_value(GTK_SCALE_BUTTON(widget));
        value = ghb_double_value_new(dval);
    }
    else if (type == GTK_TYPE_TEXT_VIEW)
    {
        GtkTextBuffer *buffer;
        GtkTextIter start, end;
        gchar *str;

        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
        gtk_text_buffer_get_bounds(buffer, &start, &end);
        str = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
        value = ghb_string_value_new(str);
        g_free(str);
    }
    else if (type == GTK_TYPE_LABEL)
    {
        const gchar *str;
        str = gtk_label_get_text (GTK_LABEL(widget));
        value = ghb_string_value_new(str);
    }
    else if (type == GTK_TYPE_FILE_CHOOSER_BUTTON)
    {
        gchar *str = NULL;
        str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(widget));
        if (str == NULL)
        {
            str = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(widget));
        }
        value = ghb_string_value_new(str);
        if (str != NULL)
            g_free(str);
    }
    else
    {
        g_debug("Attempt to set unknown widget type: %s\n", name);
        g_free(value);
        value = NULL;
    }
    return value;
}
Ejemplo n.º 16
0
static void on_response (GtkDialog *dlg, int response, FmFilePropData *data)
{
    if ( response == GTK_RESPONSE_OK )
    {
        int sel;
        const char *new_owner = gtk_entry_get_text (GTK_ENTRY (data->owner));
        const char *new_group = gtk_entry_get_text (GTK_ENTRY (data->group));
        guint32 uid = -1, gid = -1;
        mode_t new_mode = 0, new_mode_mask = 0;

        if (!ensure_valid_owner (data) || !ensure_valid_group (data))
        {
            g_signal_stop_emission_by_name (dlg, "response");
            return;
        }

        /* FIXME_pcm: if all files are native, it's possible to check
         * if the names are legal user and group names on the local
         * machine prior to chown. */
        if (new_owner && *new_owner && g_strcmp0 (data->orig_owner, new_owner))
        {
            // change owner
            g_debug ("change owner to: %d", data->uid);
        }
        else
            data->uid = -1;

        if (new_group && *new_group && g_strcmp0 (data->orig_group, new_group))
        {
            // change group
            g_debug ("change group to: %d", data->gid);
        }
        else
            data->gid = -1;

        // check if chmod is needed here.
        sel = gtk_combo_box_get_active (GTK_COMBO_BOX (data->owner_perm));
        if ( sel != NO_CHANGE ) // need to change owner permission
        {
            if (data->owner_perm_sel != sel) // new value is different from original
            {
                new_mode_mask |= S_IRUSR|S_IWUSR;
                data->owner_perm_sel = sel;
                switch (sel)
                {
                case READ_WRITE:
                    new_mode |= S_IRUSR|S_IWUSR;
                    break;
                case READ_ONLY:
                    new_mode |= S_IRUSR;
                    break;
                case WRITE_ONLY:
                    new_mode |= S_IWUSR;
                    break;
                }
            }
            else // otherwise, no change
                data->owner_perm_sel = NO_CHANGE;
        }
        else
            data->owner_perm_sel = NO_CHANGE;

        sel = gtk_combo_box_get_active (GTK_COMBO_BOX (data->group_perm));
        if ( sel != NO_CHANGE ) // need to change group permission
        {
            if (data->group_perm_sel != sel) // new value is different from original
            {
                new_mode_mask |= S_IRGRP|S_IWGRP;
                data->group_perm_sel = sel;
                switch (sel)
                {
                case READ_WRITE:
                    new_mode |= S_IRGRP|S_IWGRP;
                    break;
                case READ_ONLY:
                    new_mode |= S_IRGRP;
                    break;
                case WRITE_ONLY:
                    new_mode |= S_IWGRP;
                    break;
                }
            }
            else // otherwise, no change
                data->group_perm_sel = NO_CHANGE;
        }
        else
            data->group_perm_sel = NO_CHANGE;

#if 0
        sel = gtk_combo_box_get_active (GTK_COMBO_BOX (data->other_perm));
        if ( sel != NO_CHANGE ) // need to change other permission
        {
            if (data->other_perm_sel != sel) // new value is different from original
            {
                new_mode_mask |= S_IROTH|S_IWOTH;
                switch (sel)
                {
                case READ_WRITE:
                    new_mode |= S_IROTH|S_IWOTH;
                    break;
                case READ_ONLY:
                    new_mode |= S_IROTH;
                    break;
                case WRITE_ONLY:
                    new_mode |= S_IWOTH;
                    break;
                }
                data->other_perm_sel = sel;
            }
            else // otherwise, no change
                data->other_perm_sel = NO_CHANGE;
        }
        else
            data->other_perm_sel = NO_CHANGE;

        if (!data->has_dir
                && !gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (data->exec))
                && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->exec)) != data->exec_state)
        {
            new_mode_mask |=  (S_IXUSR|S_IXGRP|S_IXOTH);
            if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->exec)))
                new_mode |=  (S_IXUSR|S_IXGRP|S_IXOTH);
        }

        if (new_mode_mask || data->uid != -1 || data->gid != -1)
        {
            FmPathList *paths = fm_path_list_new_from_file_info_list (data->files);
            FmFileOpsJob *job = (FmFileOpsJob*) fm_file_ops_job_new (FM_FILE_OP_CHANGE_ATTR, paths);

            // need to chown
            if (data->uid != -1 || data->gid != -1)
                fm_file_ops_job_set_chown (job, data->uid, data->gid);

            // need to do chmod
            if (new_mode_mask)
                fm_file_ops_job_set_chmod (job, new_mode, new_mode_mask);

            if (data->has_dir)
            {
                if (fm_yes_no (GTK_WINDOW (data->dlg), NULL, _( "Do you want to recursively apply these changes to all files and sub-folders?" ), TRUE))
                    fm_file_ops_job_set_recursive (job, TRUE);
            }

            // show progress dialog
            fm_file_ops_job_run_with_progress (GTK_WINDOW (data->dlg), job);
            fm_list_unref (paths);
        }

        // change default application for the mime-type if needed
        if (data->mime_type && fm_mime_type_get_type (data->mime_type) && data->open_with)
        {
            GAppInfo *app;
            gboolean default_app_changed = FALSE;
            GError *err = NULL;
            app = fm_app_chooser_combo_box_get_selected (GTK_COMBO_BOX (data->open_with), &default_app_changed);
            if (app)
            {
                if (default_app_changed)
                {
                    g_app_info_set_as_default_for_type (app, fm_mime_type_get_type (data->mime_type), &err);
                    if (err)
                    {
                        fm_show_error (GTK_WINDOW (dlg), NULL, err->message);
                        g_error_free (err);
                    }
                }
                g_object_unref (app);
            }
        }

        if (data->single_file) // when only one file is shown
        {
            // if the user has changed its name
            if ( g_strcmp0 (data->file_info->disp_name, gtk_entry_get_text (GTK_ENTRY (data->name))) )
            {
                // FIXME_pcm: rename the file or set display name for it.
            }
        }
#endif
    }
    gtk_widget_destroy (GTK_WIDGET (dlg));
}