diff --git a/src/include/pw3270/actions.h b/src/include/pw3270/actions.h index 8fa7595..8781663 100644 --- a/src/include/pw3270/actions.h +++ b/src/include/pw3270/actions.h @@ -44,142 +44,46 @@ G_BEGIN_DECLS - /* // // Abstract action // - #define PW3270_TYPE_ACTION (pw3270Action_get_type()) - #define PW3270_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_ACTION, pw3270Action)) - #define PW3270_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_ACTION, pw3270ActionClass)) + #define PW3270_TYPE_ACTION (PW3270Action_get_type()) + #define PW3270_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_ACTION, PW3270Action)) + #define PW3270_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_ACTION, PW3270ActionClass)) #define PW3270_IS_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), PW3270_TYPE_ACTION)) #define PW3270_IS_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PW3270_TYPE_ACTION)) - #define PW3270_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_ACTION, pw3270ActionClass)) + #define PW3270_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_ACTION, PW3270ActionClass)) - typedef struct _pw3270Action { + typedef struct _PW3270Action { GObject parent; - const gchar * name; ///> @brief Action name (const string). - GtkWidget * terminal; ///> @brief The active terminal widget. - - struct { - const GVariantType * state; ///> @brief State type type. - const GVariantType * parameter; ///> @brief Parameter type. - } types; + const gchar * name; + const gchar * icon_name; + const gchar * label; + const gchar * tooltip; /// @brief Activation method. - void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); - - /// @brief Get State method. - GVariant * (*get_state_property)(GAction *action, GtkWidget *terminal); + void (*activate)(GAction *action, GVariant *parameter, GtkApplication *application); - /// @brief Get state hint. - GVariant * (*get_state_hint)(GAction *action, GtkWidget *terminal); + } PW3270Action; - } pw3270Action; - - typedef struct _pw3270ActionClass { + typedef struct _PW3270ActionClass { GObjectClass parent_class; + gboolean (*get_enabled)(GAction *action); + struct { GParamSpec * state; GParamSpec * enabled; } properties; - void (*change_widget)(GAction *action, GtkWidget *from, GtkWidget *to); - gboolean (*get_enabled)(GAction *action, GtkWidget *terminal); - - const gchar * (*get_icon_name)(GAction *action); - const gchar * (*get_label)(GAction *action); - const gchar * (*get_tooltip)(GAction *action); - - } pw3270ActionClass; - - GType pw3270Action_get_type(void) G_GNUC_CONST; - - /// @brief New generic action. - GAction * pw3270_action_new(); - - /// @brief Get action name. - const gchar * pw3270_action_get_name(GAction *action); - - /// @brief Set action name. - void pw3270_action_set_name(GAction *action, const gchar *name); - - /// @brief Get the action icon name. - const gchar * pw3270_action_get_icon_name(GAction *action); - - /// @brief Get the action image icon. - GtkImage * pw3270_action_get_image(GAction *action, GtkIconSize icon_size); - - /// @brief Get the action label. - const gchar * pw3270_action_get_label(GAction *action); - - /// @brief Get the action tooltip. - const gchar * pw3270_action_get_tooltip(GAction *action); - - /// @brief Create a button associated with the action. - //GtkWidget * pw3270_action_button_new(GAction *action, const gchar *action_name); - - /// @brief Associate action with the terminal widget. - void pw3270_action_set_terminal_widget(GAction *action, GtkWidget *terminal); - - /// @brief Get lib3270 session handle. - H3270 * pw3270_action_get_session(GAction *action); - */ - - /* - // - // "Simple" action - // - #define PW3270_TYPE_SIMPLE_ACTION (pw3270SimpleAction_get_type()) - #define PW3270_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_SIMPLE_ACTION, pw3270SimpleAction)) - #define PW3270_SIMPLE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_SIMPLE_ACTION, pw3270SimpleActionClass)) - #define PW3270_IS_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), PW3270_TYPE_SIMPLE_ACTION)) - #define PW3270_IS_SIMPLE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PW3270_TYPE_SIMPLE_ACTION)) - #define PW3270_SIMPLE_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_SIMPLE_ACTION, pw3270SimpleActionClass)) - - typedef struct _pw3270SimpleAction { - - pw3270Action parent; - - // Fixed data - const gchar * icon_name; - const gchar * label; - const gchar * tooltip; - - // Lib3270 Action group - struct { - LIB3270_ACTION_GROUP id; - const void * listener; - } group; - - /// @brief Activation method. - void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); - - } pw3270SimpleAction; - - typedef struct _pw3270SimpleActionClass { - - pw3270ActionClass parent_class; - - } pw3270SimpleActionClass; - - GType pw3270SimpleAction_get_type(void) G_GNUC_CONST; - - /// @brief Create an empty simple action. - pw3270SimpleAction * pw3270_simple_action_new(); - - /// @brief New simple action from LIB3270's control data. - pw3270SimpleAction * pw3270_simple_action_new_from_lib3270(const LIB3270_ACTION * definition, const gchar *name); - - /// @brief New simple action from LIB3270's action name. - pw3270SimpleAction * pw3270_simple_action_new_from_name(const gchar *source_name, const gchar *name); + } PW3270ActionClass; - /// @brief Update simple action from LIB3270's property description. - void pw3270_simple_action_set_lib3270_property(pw3270SimpleAction *action, const LIB3270_PROPERTY * property); - */ + GType PW3270Action_get_type(void) G_GNUC_CONST; + PW3270Action * pw3270action_new(); + PW3270Action * pw3270_dialog_action_new(GtkWidget * (*factory)(PW3270Action *action, GtkApplication *application)); // // Action view diff --git a/src/objects/actions/abstract.c b/src/objects/actions/abstract.c index 8ad9eae..6d92452 100644 --- a/src/objects/actions/abstract.c +++ b/src/objects/actions/abstract.c @@ -1,5 +1,5 @@ /* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * "Software v3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a * aplicativos mainframe. Registro no INPI sob o nome G3270. * @@ -28,34 +28,37 @@ */ #include "private.h" - #include - - /* - - static void pw3270_action_iface_init(GActionInterface *iface); - static void pw3270Action_class_init(pw3270ActionClass *klass); - static void pw3270Action_init(pw3270Action *action); - static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); - static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); - static gboolean get_enabled(GAction *action); - static void activate(GAction *action, GVariant *parameter); - - static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to); - static const gchar *get_null(GAction *action); - - static void finalize(GObject *object); - - static const GVariantType * get_state_type(GAction *action); - static GVariant * get_state_property(GAction *action); - - static GVariant * internal_get_state_property(GAction *action, GtkWidget *terminal); - static gboolean internal_get_enabled(GAction *action, GtkWidget *terminal); - static void internal_activate(GAction *action, GVariant *parameter, GtkWidget *terminal); - static GVariant * internal_get_state_hint(GAction *action, GtkWidget *terminal); - - static const GVariantType * get_parameter_type(GAction *action); - static GVariant * get_state_hint(GAction *action); - static void change_state(GAction *action, GVariant *value); + #include + + static void PW3270_action_iface_init(GActionInterface *iface); + static void PW3270Action_class_init(PW3270ActionClass *klass); + static void PW3270Action_init(PW3270Action *action); + + static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); + + static const gchar * get_icon_name(GAction *action); + static const gchar * get_label(GAction *action); + static const gchar * get_tooltip(GAction *action); + static const gchar * get_name(GAction *action); + static const GVariantType * get_state_type(GAction *action); + static const GVariantType * get_parameter_type(GAction *object); + + static void finalize(GObject *object); + + static gboolean get_enabled(GAction *action); + static void activate(GAction *action, GVariant *parameter, GtkApplication *application); + static GVariant * get_state(GAction *action); + + static const gchar * iface_get_name(GAction *action); + static const GVariantType * iface_get_parameter_type(GAction *action); + static GVariant * iface_get_state_hint(GAction *action); + static const GVariantType * iface_get_state_type(GAction *action); + static GVariant * iface_get_state(GAction *action); + static gboolean iface_get_enabled(GAction *action); + static GVariant * iface_get_state(GAction *object); + static void iface_change_state(GAction *object, GVariant *value); + static void iface_activate(GAction *object, GVariant *parameter); enum { PROP_NONE, @@ -64,40 +67,24 @@ PROP_ENABLED, PROP_STATE_TYPE, PROP_STATE, - PROP_TOOLBAR_ICON, PROP_ICON_NAME, PROP_LABEL, PROP_TOOLTIP }; - G_DEFINE_TYPE_WITH_CODE(pw3270Action, pw3270Action, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_ACTION, pw3270_action_iface_init)) - - void pw3270_action_iface_init(GActionInterface *iface) { - iface->get_name = pw3270_action_get_name; - iface->get_parameter_type = get_parameter_type; - iface->get_state_type = get_state_type; - iface->get_state_hint = get_state_hint; - iface->get_enabled = get_enabled; - iface->get_state = get_state_property; - iface->change_state = change_state; - iface->activate = activate; - } + G_DEFINE_TYPE_WITH_CODE(PW3270Action, PW3270Action, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_ACTION, PW3270_action_iface_init)) - void pw3270Action_class_init(pw3270ActionClass *klass) { + void PW3270Action_class_init(PW3270ActionClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); debug("%s",__FUNCTION__); - klass->change_widget = change_widget; - klass->get_enabled = internal_get_enabled; - klass->get_icon_name = get_null; - klass->get_label = get_null; - klass->get_tooltip = get_null; + klass->get_enabled = get_enabled; object_class->finalize = finalize; - object_class->set_property = set_property; object_class->get_property = get_property; + object_class->set_property = set_property; // Install properties g_object_class_install_property(object_class, PROP_NAME, @@ -106,7 +93,7 @@ N_("Action Name"), N_("The name used to invoke the action"), NULL, - G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property(object_class, PROP_ICON_NAME, g_param_spec_string ( @@ -114,15 +101,7 @@ N_("Icon Name"), N_("The name of the icon associated with the action"), NULL, - G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property(object_class, PROP_TOOLBAR_ICON, - g_param_spec_object ( - "toolbar-icon", - N_("Icon pixbuf"), - N_("A image widget with the action icon"), - GTK_TYPE_IMAGE, - G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE)); + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property(object_class, PROP_LABEL, g_param_spec_string ( @@ -130,7 +109,7 @@ N_("The action label"), N_("The label for the action"), NULL, - G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property(object_class, PROP_TOOLTIP, g_param_spec_string ( @@ -138,7 +117,7 @@ N_("The action tooltip"), N_("The tooltip for the action"), NULL, - G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_PARAMETER_TYPE, g_param_spec_boxed ("parameter-type", @@ -152,7 +131,7 @@ N_("State Type"), N_("The type of the state kept by the action"), G_TYPE_VARIANT_TYPE, - G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); // Enabled property klass->properties.enabled = @@ -161,7 +140,7 @@ N_("Enabled"), N_("If the action can be activated"), TRUE, - G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS ); g_object_class_install_property(object_class, PROP_ENABLED, klass->properties.enabled); @@ -174,34 +153,21 @@ N_("The state the action is in"), G_VARIANT_TYPE_ANY, NULL, - G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS ); g_object_class_install_property (object_class, PROP_STATE, klass->properties.state); } - void pw3270Action_init(pw3270Action *action) { - - action->terminal = NULL; - action->types.parameter = NULL; - - action->activate = internal_activate; - action->get_state_property = internal_get_state_property; - action->get_state_hint = internal_get_state_hint; - + void PW3270Action_init(PW3270Action *action) { + action->activate = activate; } void finalize(GObject *object) { - pw3270Action * action = PW3270_ACTION(object); - - if(action->terminal) { - pw3270_action_set_terminal_widget(G_ACTION(object),NULL); - action->terminal = NULL; - } - - G_OBJECT_CLASS(pw3270Action_parent_class)->finalize(object); + // PW3270Action * action = PW3270_ACTION(object); + G_OBJECT_CLASS(PW3270Action_parent_class)->finalize(object); } @@ -209,27 +175,21 @@ GAction *action = G_ACTION(object); -// debug("%s(%d)",__FUNCTION__,prop_id); - switch (prop_id) { case PROP_NAME: - g_value_set_string(value, pw3270_action_get_name(action)); + g_value_set_string(value, g_action_get_name(action)); break; case PROP_ICON_NAME: - g_value_set_string(value, pw3270_action_get_icon_name(action)); - break; - - case PROP_TOOLBAR_ICON: - g_value_set_object(value, pw3270_action_get_image(action,GTK_ICON_SIZE_LARGE_TOOLBAR)); + g_value_set_string(value, get_icon_name(action)); break; case PROP_LABEL: - g_value_set_string(value, pw3270_action_get_label(action)); + g_value_set_string(value, get_label(action)); break; case PROP_TOOLTIP: - g_value_set_string(value, pw3270_action_get_tooltip(action)); + g_value_set_string(value, get_tooltip(action)); break; case PROP_PARAMETER_TYPE: @@ -245,37 +205,7 @@ break; case PROP_STATE: - g_value_take_variant(value, get_state_property(action)); - break; - - default: - g_assert_not_reached (); - } - - } - - void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) { - -// debug("%s(%d)",__FUNCTION__,prop_id); - - GAction *action = G_ACTION(object); - - switch (prop_id) - { - case PROP_NAME: - pw3270_action_set_name(action, g_value_get_string(value)); - break; - - case PROP_PARAMETER_TYPE: -// action->parameter_type = g_value_dup_boxed (value); - break; - - case PROP_ENABLED: -// action->enabled = g_value_get_boolean (value); - break; - - case PROP_STATE: -// pw3270_action_set_state(action, g_value_get_variant(value)); + g_value_take_variant(value, get_state(action)); break; default: @@ -284,278 +214,148 @@ } - const gchar * pw3270_action_get_name(GAction *action) { - return PW3270_ACTION(action)->name; - } - - void pw3270_action_set_name(GAction *action, const gchar *name) { - PW3270_ACTION(action)->name = g_intern_string(name); - } - - GVariant * internal_get_state_hint(GAction G_GNUC_UNUSED(*action), GtkWidget G_GNUC_UNUSED(*terminal)) { - return NULL; - } - - GVariant * internal_get_state_property(GAction *object, GtkWidget G_GNUC_UNUSED(*terminal)) { - - pw3270Action * action = PW3270_ACTION(object); - - if(action->types.state == G_VARIANT_TYPE_BOOLEAN) - return g_variant_new_boolean(FALSE); - - return NULL; - } - - GVariant * get_state_property(GAction *object) { - - pw3270Action * action = PW3270_ACTION(object); - GVariant * state; - - if(action->terminal) - state = action->get_state_property(object,action->terminal); - else - state = internal_get_state_property(object,NULL); - - if(state) - g_variant_ref(state); - - return state; - } - - const GVariantType * get_parameter_type(GAction *action) { - return PW3270_ACTION(action)->types.parameter; - } - - const GVariantType * get_state_type(GAction *object) { - return PW3270_ACTION(object)->types.state; - } - - GVariant * get_state_hint(GAction *object) { - pw3270Action *action = PW3270_ACTION(object); - return action->get_state_hint(object,action->terminal); - } - - void change_state(GAction G_GNUC_UNUSED(*object), GVariant G_GNUC_UNUSED(*value)) { - debug("%s",__FUNCTION__) + void set_property(GObject G_GNUC_UNUSED(*object), guint G_GNUC_UNUSED(prop_id), const GValue G_GNUC_UNUSED(*value), GParamSpec *pspec) { +// g_message("Action %s property %s is read-only",g_action_get_name(G_ACTION(object)),pspec->name); } static gboolean bg_notify_enabled(GObject *action) { - // debug("%s(%s,%s)",__FUNCTION__,g_action_get_name(G_ACTION(action)),(g_action_get_enabled(G_ACTION(action)) ? "enabled" : "disabled")); + debug("%s(%s,%s)",__FUNCTION__,g_action_get_name(G_ACTION(action)),(g_action_get_enabled(G_ACTION(action)) ? "enabled" : "disabled")); g_object_notify(action, "enabled"); return FALSE; } - void pw3270_action_notify_enabled(GAction *action) { - g_idle_add((GSourceFunc) bg_notify_enabled, G_OBJECT(action)); - } - static gboolean bg_notify_state(GObject *action) { g_object_notify(action, "state"); return FALSE; } - void pw3270_action_notify_state(GAction *action) { - g_idle_add((GSourceFunc) bg_notify_state, G_OBJECT(action)); + void pw3270_action_notify_enabled(GAction *action) { + g_idle_add((GSourceFunc) bg_notify_enabled, G_OBJECT(action)); } - static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { - - if(from != to) { - - pw3270Action *action = PW3270_ACTION(object); - - action->terminal = to; - - pw3270_action_notify_enabled(object); - - if(action->types.state) - pw3270_action_notify_state(object); - - } - + void pw3270_action_notify_state(GAction *action) { + if(g_action_get_state_type(action)) + g_idle_add((GSourceFunc) bg_notify_state, G_OBJECT(action)); } - void pw3270_action_set_terminal_widget(GAction *object, GtkWidget *widget) { - - g_return_if_fail(PW3270_IS_ACTION(object)); - - if(widget) { - g_return_if_fail(GTK_IS_V3270(widget)); - } - - pw3270Action * action = PW3270_ACTION(object); - - if(action->terminal != widget) { - PW3270_ACTION_GET_CLASS(object)->change_widget(object,action->terminal,widget); - action->terminal = widget; - } - + gboolean get_enabled(GAction G_GNUC_UNUSED(*object)) { + return TRUE; } - gboolean get_enabled(GAction *object) { - - gboolean enabled = FALSE; - - pw3270Action * action = PW3270_ACTION(object); - - if(action && action->terminal) { - enabled = PW3270_ACTION_GET_CLASS(object)->get_enabled(object,action->terminal); -// debug("Action %s is %s",g_action_get_name(object),enabled ? "enabled" : "disabled"); - } - - return enabled; + void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkApplication G_GNUC_UNUSED(*application)) { + g_message("Action %s can't be activated",g_action_get_name(action)); + } + // + // Action methods. + // + GAction * pw3270_action_new() { + return G_ACTION(g_object_new(PW3270_TYPE_ACTION, NULL)); } - void activate(GAction *object, GVariant *parameter) { + GdkPixbuf * pw3270_action_get_pixbuf(GAction *action, GtkIconSize icon_size, GtkIconLookupFlags flags) { - pw3270Action * action = PW3270_ACTION(object); + const gchar * icon_name = v3270_action_get_icon_name(action); - debug("%s: terminal=%p",__FUNCTION__,action->terminal); + if(!icon_name) + return NULL; - if(action && action->terminal) { - action->activate(object,parameter,action->terminal); - } + return gtk_icon_theme_load_icon( + gtk_icon_theme_get_default(), + icon_name, + icon_size, + flags, + NULL + ); } - gboolean internal_get_enabled(GAction G_GNUC_UNUSED(*object), GtkWidget *terminal) { - return terminal != NULL; +// +// Default methods. +// + GVariant * get_state(GAction G_GNUC_UNUSED(*object)) { + return g_variant_new_boolean(TRUE); } - void internal_activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) { - debug("%s",__FUNCTION__); - g_message("Action %s can't be activated",pw3270_action_get_name(action)); +// +// Interface Methods. +// + void PW3270_action_iface_init(GActionInterface *iface) { + iface->get_name = iface_get_name; + iface->get_parameter_type = iface_get_parameter_type; + iface->get_state_type = iface_get_state_type; + iface->get_state_hint = iface_get_state_hint; + iface->get_enabled = iface_get_enabled; + iface->get_state = iface_get_state; + iface->change_state = iface_change_state; + iface->activate = iface_activate; } - const gchar * get_null(GAction G_GNUC_UNUSED(*action)) { - return NULL; + const gchar * iface_get_name(GAction *action) { + return get_name(action); } - const gchar * pw3270_action_get_icon_name(GAction *action) { - return PW3270_ACTION_GET_CLASS(action)->get_icon_name(action); - } + GVariant * iface_get_state(GAction *object) { - GtkImage * pw3270_action_get_image(GAction *action, GtkIconSize icon_size) { + GVariant * state = NULL; - const gchar * icon_name = pw3270_action_get_icon_name(action); - if(!icon_name) - return NULL; + if(g_action_get_state_type(object)) { - return GTK_IMAGE(gtk_image_new_from_icon_name(icon_name,icon_size)); - } + state = get_state(object); + if(state) + g_variant_ref(state); - const gchar * pw3270_action_get_label(GAction *action) { - const gchar * label = PW3270_ACTION_GET_CLASS(action)->get_label(action); + } - if(label) - return gettext(label); + return state; - return NULL; } - const gchar * pw3270_action_get_tooltip(GAction *action) { - const gchar * tooltip = PW3270_ACTION_GET_CLASS(action)->get_tooltip(action); + const GVariantType * iface_get_parameter_type(GAction *object) { + return get_parameter_type(object); + } - if(tooltip) - return gettext(tooltip); + const GVariantType * iface_get_state_type(GAction *object) { + return get_state_type(object); + } + GVariant * iface_get_state_hint(GAction G_GNUC_UNUSED(*object)) { return NULL; } - H3270 * pw3270_action_get_session(GAction *action) { - return v3270_get_session(PW3270_ACTION(action)->terminal); + void iface_change_state(GAction G_GNUC_UNUSED(*object), GVariant G_GNUC_UNUSED(*value)) { + debug("%s",__FUNCTION__); } - GAction * pw3270_action_new() { - return G_ACTION(g_object_new(PW3270_TYPE_ACTION, NULL)); + gboolean iface_get_enabled(GAction *object) { + return PW3270_ACTION_GET_CLASS(object)->get_enabled(object); } - gchar * g_action_get_text(GAction *action, const gchar * property_name) { - gchar *rc = NULL; - - GValue value = G_VALUE_INIT; - g_value_init(&value, G_TYPE_STRING); - g_object_get_property(G_OBJECT(action),property_name,&value); - - const gchar * text = g_value_get_string(&value); - if(text) - rc = g_strdup(text); - - g_value_unset(&value); - - return rc; - + void iface_activate(GAction *object, GVariant *parameter) { + PW3270_ACTION(object)->activate(object,parameter,GTK_APPLICATION(g_application_get_default())); } - gchar * g_action_get_tooltip(GAction *action) { - return g_action_get_text(action, "tooltip"); + const gchar * get_icon_name(GAction *action) { + return PW3270_ACTION(action)->icon_name; } - gchar * g_action_get_label(GAction *action) { - return g_action_get_text(action, "label"); + const gchar * get_label(GAction *action) { + return PW3270_ACTION(action)->label; } - gchar * g_action_get_icon_name(GAction *action) { - return g_action_get_text(action, "icon-name"); + const gchar * get_tooltip(GAction *action) { + return PW3270_ACTION(action)->tooltip; } - static GdkPixbuf * pixbuf_from_icon_name(GValue *value, gint width, gint G_GNUC_UNUSED(height), GtkIconLookupFlags flags) { - - const gchar * icon_name = g_value_get_string(value); - - if(!icon_name) - return NULL; - - return gtk_icon_theme_load_icon( - gtk_icon_theme_get_default(), - icon_name, - width, - flags, // GTK_ICON_LOOKUP_GENERIC_FALLBACK, - NULL - ); - + const gchar * get_name(GAction *action) { + return PW3270_ACTION(action)->name; } - GdkPixbuf * g_action_get_pixbuf(GAction *action, GtkIconSize icon_size, GtkIconLookupFlags flags) { - - struct Properties { - const gchar * name; - GType value_type; - GdkPixbuf * (*translate)(GValue *value, gint width, gint height, GtkIconLookupFlags flags); - } properties[] = { - { - .name = "icon-name", - .value_type = G_TYPE_STRING, - .translate = pixbuf_from_icon_name - } - }; - - size_t ix; - GdkPixbuf * pixbuf = NULL; - gint width, height; - - gtk_icon_size_lookup(icon_size,&width,&height); - - for(ix = 0; ix < G_N_ELEMENTS(properties) && !pixbuf; ix++) { - - GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(action),properties[ix].name); - if(spec && spec->value_type == properties[ix].value_type && (spec->flags & G_PARAM_READABLE) != 0) { - - GValue value = G_VALUE_INIT; - g_value_init(&value, properties[ix].value_type); - - g_object_get_property(G_OBJECT(action),properties[ix].name,&value); - - pixbuf = properties[ix].translate(&value,width,height,flags); - - g_value_unset(&value); - - } - - } + const GVariantType * get_state_type(GAction G_GNUC_UNUSED(*object)) { + return NULL; + } - return pixbuf; + const GVariantType * get_parameter_type(GAction G_GNUC_UNUSED(*object)) { + return NULL; } -*/ diff --git a/src/objects/actions/dialog.c b/src/objects/actions/dialog.c index c203ed1..b0e2dad 100644 --- a/src/objects/actions/dialog.c +++ b/src/objects/actions/dialog.c @@ -32,95 +32,100 @@ * */ - /* #include "private.h" - #include - #include + #include - static void pw3270DialogAction_class_init(pw3270DialogActionClass *klass); - static void pw3270DialogAction_init(pw3270DialogAction *action); - static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal); + typedef struct _PW3270DialogAction { - struct _pw3270DialogAction { - - pw3270SimpleAction parent; + PW3270Action parent; GtkWidget * dialog; - GtkWidget * (*factory)(pw3270SimpleAction *, GtkWidget *); - - }; + GtkWidget * (*factory)(PW3270Action *, GtkApplication *); - struct _pw3270DialogActionClass { + } PW3270DialogAction; - pw3270SimpleActionClass parent_class; + typedef struct _PW3270DialogActionClass { - }; + PW3270ActionClass parent_class; - G_DEFINE_TYPE(pw3270DialogAction, pw3270DialogAction, PW3270_TYPE_SIMPLE_ACTION); + } PW3270DialogActionClass; - static gboolean get_enabled(GAction *action, GtkWidget *terminal) { - - if((PW3270_DIALOG_ACTION(action)->dialog)) { - return FALSE; - } + #define PW3270_TYPE_DIALOG_ACTION (PW3270DialogAction_get_type()) + #define PW3270_DIALOG_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_DIALOG_ACTION, PW3270DialogAction)) + #define PW3270_DIALOG_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_DIALOG_ACTION, PW3270DialogActionClass)) + #define PW3270_IS_DIALOG_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), PW3270_TYPE_DIALOG_ACTION)) + #define PW3270_IS_DIALOG_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PW3270_TYPE_DIALOG_ACTION)) + #define PW3270_DIALOG_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_DIALOG_ACTION, PW3270DialogActionClass)) - if(terminal) { - return lib3270_action_group_get_activatable(v3270_get_session(terminal),PW3270_SIMPLE_ACTION(action)->group.id); - } + static void PW3270DialogAction_class_init(PW3270DialogActionClass *klass); + static void PW3270DialogAction_init(PW3270DialogAction *action); + static void activate(GAction *action, GVariant *parameter, GtkApplication *application); + static GtkWidget * factory(PW3270Action *action, GtkApplication *application); + static gboolean get_enabled(GAction *action); - return FALSE; + G_DEFINE_TYPE(PW3270DialogAction, PW3270DialogAction, PW3270_TYPE_ACTION); + PW3270Action * pw3270_dialog_action_new(GtkWidget * (*factory)(PW3270Action *, GtkApplication *application)) { + PW3270DialogAction *action = PW3270_DIALOG_ACTION(g_object_new(PW3270_TYPE_DIALOG_ACTION, NULL)); + action->parent.activate = activate; + action->factory = factory; + return PW3270_ACTION(action); } - static void pw3270DialogAction_class_init(pw3270DialogActionClass *klass) { - klass->parent_class.parent_class.get_enabled = get_enabled; + void PW3270DialogAction_class_init(PW3270DialogActionClass *klass) { + klass->parent_class.get_enabled = get_enabled; } - static void pw3270DialogAction_init(pw3270DialogAction *action) { - - action->dialog = NULL; - action->parent.parent.activate = activate; + void PW3270DialogAction_init(PW3270DialogAction *action) { + action->factory = factory; + } + GtkWidget * factory(PW3270Action *action, GtkApplication G_GNUC_UNUSED(*application)) { + g_warning("No widget factory for action \"%s\"",g_action_get_name(G_ACTION(action))); + return NULL; } - pw3270SimpleAction * pw3270_dialog_action_new(GtkWidget * (*factory)(pw3270SimpleAction *, GtkWidget *)) { + gboolean get_enabled(GAction *action) { - pw3270DialogAction * action = (pw3270DialogAction *) g_object_new(PW3270_TYPE_DIALOG_ACTION, NULL); - action->factory = factory; - return PW3270_SIMPLE_ACTION(action); + if((PW3270_DIALOG_ACTION(action)->dialog)) { + return FALSE; + } + + return PW3270_ACTION_CLASS(PW3270DialogAction_parent_class)->get_enabled(action); } - static void on_destroy(GtkWidget *dialog, pw3270DialogAction *action) { +static void on_destroy(GtkWidget *dialog, PW3270DialogAction *action) { - if(action->dialog == dialog) { + if(action->dialog == dialog) { action->dialog = NULL; pw3270_action_notify_enabled(G_ACTION(action)); - } + } } - void activate(GAction *object, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { - - if(!GTK_IS_V3270(terminal)) - return; + void activate(GAction *object, GVariant G_GNUC_UNUSED(*parameter), GtkApplication *application) { - pw3270DialogAction * action = PW3270_DIALOG_ACTION(object); + PW3270DialogAction * action = PW3270_DIALOG_ACTION(object); - if(action->dialog || !action->factory) + if(action->dialog) return; - action->dialog = action->factory((pw3270SimpleAction *) object, terminal); - pw3270_action_notify_enabled(G_ACTION(action)); + action->dialog = action->factory(PW3270_ACTION(action), application); if(action->dialog) { + GtkWindow * window = gtk_application_get_active_window(application); + if(window) { + gtk_window_set_attached_to(GTK_WINDOW(action->dialog), GTK_WIDGET(window)); + gtk_window_set_transient_for(GTK_WINDOW(action->dialog),window); + } + + pw3270_action_notify_enabled(G_ACTION(action)); g_signal_connect(action->dialog,"destroy",G_CALLBACK(on_destroy),action); g_signal_connect(action->dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); - gtk_widget_show_all(GTK_WIDGET(action->dialog)); + gtk_widget_show(GTK_WIDGET(action->dialog)); } } - -*/ diff --git a/src/objects/application/actions/about.c b/src/objects/application/actions/about.c index a77a795..7aee443 100644 --- a/src/objects/application/actions/about.c +++ b/src/objects/application/actions/about.c @@ -28,9 +28,10 @@ */ #include "../private.h" + #include #include - void pw3270_application_about_activated(GSimpleAction G_GNUC_UNUSED(* action), GVariant G_GNUC_UNUSED(*parameter), gpointer application) { + static GtkWidget * factory(PW3270Action G_GNUC_UNUSED(*action), GtkApplication G_GNUC_UNUSED(*application)) { static const gchar *authors[] = { @@ -119,10 +120,22 @@ gtk_about_dialog_set_authors(dialog,authors); gtk_about_dialog_set_translator_credits(dialog,_("translator-credits")); - g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); + g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL); gtk_widget_show_all(GTK_WIDGET(dialog)); + return GTK_WIDGET(dialog); } + GAction * pw3270_about_action_new() { + + PW3270Action * action = pw3270_dialog_action_new(factory); + + action->name = "about"; + action->label = _("About pw3270"); + action->icon_name = "help-about"; + + return G_ACTION(action); + } diff --git a/src/objects/application/application.c b/src/objects/application/application.c index f11e2c2..2160bcb 100644 --- a/src/objects/application/application.c +++ b/src/objects/application/application.c @@ -321,16 +321,15 @@ void startup(GApplication *application) { + size_t ix; + G_APPLICATION_CLASS(pw3270Application_parent_class)->startup(application); + /* // // Setup application default actions. // static GActionEntry actions[] = { - { - .name = "about", - .activate = pw3270_application_about_activated, - }, { .name = "preferences", @@ -375,6 +374,15 @@ G_N_ELEMENTS(actions), application ); + */ + + GAction * actions[] = { + pw3270_about_action_new() + }; + + for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) { + g_action_map_add_action(G_ACTION_MAP(application),actions[ix]); + } // // Setup application menus diff --git a/src/objects/application/private.h b/src/objects/application/private.h index 8c22baf..edebd5a 100644 --- a/src/objects/application/private.h +++ b/src/objects/application/private.h @@ -50,11 +50,12 @@ G_GNUC_INTERNAL GtkWidget * pw3270_terminal_new(const gchar *session_file); // Actions + G_GNUC_INTERNAL GAction * pw3270_about_action_new(); + G_GNUC_INTERNAL void pw3270_application_generic_activated(GSimpleAction * action, GVariant *parameter, gpointer application); G_GNUC_INTERNAL void pw3270_application_quit_activated(GSimpleAction * action, GVariant *parameter, gpointer application); G_GNUC_INTERNAL void pw3270_application_new_tab_activated(GSimpleAction * action, GVariant *parameter, gpointer application); G_GNUC_INTERNAL void pw3270_application_new_window_activated(GSimpleAction * action, GVariant *parameter, gpointer application); - G_GNUC_INTERNAL void pw3270_application_about_activated(GSimpleAction * action, GVariant *parameter, gpointer application); G_GNUC_INTERNAL void pw3270_application_preferences_activated(GSimpleAction * action, GVariant *parameter, gpointer application); G_GNUC_INTERNAL void pw3270_application_open_activated(GSimpleAction * action, GVariant *parameter, gpointer application); -- libgit2 0.21.2