Commit c2cca166958b83e04a98840f7394ab962a59bd86
1 parent
7df54950
Exists in
master
and in
4 other branches
Implementing action list widget.
Showing
6 changed files
with
263 additions
and
30 deletions
Show diff stats
pw3270.cbp
| ... | ... | @@ -102,6 +102,9 @@ |
| 102 | 102 | <Unit filename="src/objects/actions/v3270/property.c"> |
| 103 | 103 | <Option compilerVar="CC" /> |
| 104 | 104 | </Unit> |
| 105 | + <Unit filename="src/objects/actions/view.c"> | |
| 106 | + <Option compilerVar="CC" /> | |
| 107 | + </Unit> | |
| 105 | 108 | <Unit filename="src/objects/actions/window.c"> |
| 106 | 109 | <Option compilerVar="CC" /> |
| 107 | 110 | </Unit> | ... | ... |
src/include/pw3270/actions.h
| ... | ... | @@ -37,6 +37,7 @@ |
| 37 | 37 | #define PW3270_ACTIONS_H_INCLUDED |
| 38 | 38 | |
| 39 | 39 | #include <gio/gio.h> |
| 40 | + #include <gtk/gtk.h> | |
| 40 | 41 | #include <lib3270.h> |
| 41 | 42 | #include <lib3270/actions.h> |
| 42 | 43 | |
| ... | ... | @@ -110,6 +111,9 @@ |
| 110 | 111 | /// @brief Get the action icon name. |
| 111 | 112 | const gchar * pw3270_action_get_icon_name(GAction *action); |
| 112 | 113 | |
| 114 | + /// @brief Get the action image icon. | |
| 115 | + GtkImage * pw3270_action_get_image(GAction *action, GtkIconSize icon_size); | |
| 116 | + | |
| 113 | 117 | /// @brief Get the action label. |
| 114 | 118 | const gchar * pw3270_action_get_label(GAction *action); |
| 115 | 119 | |
| ... | ... | @@ -249,6 +253,15 @@ |
| 249 | 253 | |
| 250 | 254 | GAction * v3270_conditional_action_new(GtkWidget *widget, const gchar *property_name); |
| 251 | 255 | |
| 256 | + // | |
| 257 | + // Action view | |
| 258 | + // | |
| 259 | + typedef GSList Pw3270ActionList; | |
| 260 | + | |
| 261 | + GtkWidget * pw3270_action_view_new(); | |
| 262 | + Pw3270ActionList * pw3270_action_list_new(GtkApplication *application); | |
| 263 | + void pw3270_action_list_free(Pw3270ActionList *action_list); | |
| 264 | + | |
| 252 | 265 | G_END_DECLS |
| 253 | 266 | |
| 254 | 267 | #endif // PW3270_ACTIONS_H_INCLUDED | ... | ... |
src/objects/actions/abstract.c
| ... | ... | @@ -61,7 +61,11 @@ |
| 61 | 61 | PROP_PARAMETER_TYPE, |
| 62 | 62 | PROP_ENABLED, |
| 63 | 63 | PROP_STATE_TYPE, |
| 64 | - PROP_STATE | |
| 64 | + PROP_STATE, | |
| 65 | + PROP_TOOLBAR_ICON, | |
| 66 | + PROP_ICON_NAME, | |
| 67 | + PROP_LABEL, | |
| 68 | + PROP_TOOLTIP | |
| 65 | 69 | }; |
| 66 | 70 | |
| 67 | 71 | /* |
| ... | ... | @@ -106,29 +110,58 @@ |
| 106 | 110 | |
| 107 | 111 | // Install properties |
| 108 | 112 | g_object_class_install_property(object_class, PROP_NAME, |
| 109 | - g_param_spec_string ("name", | |
| 113 | + g_param_spec_string ( | |
| 114 | + "name", | |
| 110 | 115 | N_("Action Name"), |
| 111 | 116 | N_("The name used to invoke the action"), |
| 112 | 117 | NULL, |
| 113 | - G_PARAM_READWRITE | | |
| 114 | - G_PARAM_CONSTRUCT_ONLY | | |
| 115 | - G_PARAM_STATIC_STRINGS)); | |
| 118 | + G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); | |
| 119 | + | |
| 120 | + g_object_class_install_property(object_class, PROP_ICON_NAME, | |
| 121 | + g_param_spec_string ( | |
| 122 | + "icon-name", | |
| 123 | + N_("Icon Name"), | |
| 124 | + N_("The name of the icon associated with the action"), | |
| 125 | + NULL, | |
| 126 | + G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
| 127 | + | |
| 128 | + g_object_class_install_property(object_class, PROP_TOOLBAR_ICON, | |
| 129 | + g_param_spec_object ( | |
| 130 | + "toolbar-icon", | |
| 131 | + N_("Icon pixbuf"), | |
| 132 | + N_("A image widget with the action icon"), | |
| 133 | + GTK_TYPE_IMAGE, | |
| 134 | + G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE)); | |
| 135 | + | |
| 136 | + g_object_class_install_property(object_class, PROP_LABEL, | |
| 137 | + g_param_spec_string ( | |
| 138 | + "label", | |
| 139 | + N_("The action label"), | |
| 140 | + N_("The label for the action"), | |
| 141 | + NULL, | |
| 142 | + G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
| 143 | + | |
| 144 | + g_object_class_install_property(object_class, PROP_TOOLTIP, | |
| 145 | + g_param_spec_string ( | |
| 146 | + "tooltip", | |
| 147 | + N_("The action tooltip"), | |
| 148 | + N_("The tooltip for the action"), | |
| 149 | + NULL, | |
| 150 | + G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
| 116 | 151 | |
| 117 | 152 | g_object_class_install_property (object_class, PROP_PARAMETER_TYPE, |
| 118 | 153 | g_param_spec_boxed ("parameter-type", |
| 119 | 154 | N_("Parameter Type"), |
| 120 | 155 | N_("The type of GVariant passed to activate()"), |
| 121 | 156 | G_TYPE_VARIANT_TYPE, |
| 122 | - G_PARAM_READWRITE | | |
| 123 | - G_PARAM_CONSTRUCT_ONLY | | |
| 124 | - G_PARAM_STATIC_STRINGS)); | |
| 157 | + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); | |
| 125 | 158 | |
| 126 | 159 | g_object_class_install_property (object_class, PROP_STATE_TYPE, |
| 127 | 160 | g_param_spec_boxed ("state-type", |
| 128 | 161 | N_("State Type"), |
| 129 | 162 | N_("The type of the state kept by the action"), |
| 130 | 163 | G_TYPE_VARIANT_TYPE, |
| 131 | - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
| 164 | + G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
| 132 | 165 | |
| 133 | 166 | // Enabled property |
| 134 | 167 | klass->properties.enabled = |
| ... | ... | @@ -137,7 +170,7 @@ |
| 137 | 170 | N_("Enabled"), |
| 138 | 171 | N_("If the action can be activated"), |
| 139 | 172 | TRUE, |
| 140 | - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | |
| 173 | + G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | |
| 141 | 174 | ); |
| 142 | 175 | |
| 143 | 176 | g_object_class_install_property(object_class, PROP_ENABLED, klass->properties.enabled); |
| ... | ... | @@ -150,7 +183,7 @@ |
| 150 | 183 | N_("The state the action is in"), |
| 151 | 184 | G_VARIANT_TYPE_ANY, |
| 152 | 185 | NULL, |
| 153 | - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | |
| 186 | + G_PARAM_STATIC_NAME| G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | |
| 154 | 187 | ); |
| 155 | 188 | |
| 156 | 189 | g_object_class_install_property (object_class, PROP_STATE, klass->properties.state); |
| ... | ... | @@ -198,13 +231,29 @@ |
| 198 | 231 | |
| 199 | 232 | GAction *action = G_ACTION(object); |
| 200 | 233 | |
| 201 | - debug("%s(%d)",__FUNCTION__,prop_id); | |
| 234 | +// debug("%s(%d)",__FUNCTION__,prop_id); | |
| 202 | 235 | |
| 203 | 236 | switch (prop_id) { |
| 204 | 237 | case PROP_NAME: |
| 205 | 238 | g_value_set_string(value, pw3270_action_get_name(action)); |
| 206 | 239 | break; |
| 207 | 240 | |
| 241 | + case PROP_ICON_NAME: | |
| 242 | + g_value_set_string(value, pw3270_action_get_icon_name(action)); | |
| 243 | + break; | |
| 244 | + | |
| 245 | + case PROP_TOOLBAR_ICON: | |
| 246 | + g_value_set_object(value, pw3270_action_get_image(action,GTK_ICON_SIZE_LARGE_TOOLBAR)); | |
| 247 | + break; | |
| 248 | + | |
| 249 | + case PROP_LABEL: | |
| 250 | + g_value_set_string(value, pw3270_action_get_label(action)); | |
| 251 | + break; | |
| 252 | + | |
| 253 | + case PROP_TOOLTIP: | |
| 254 | + g_value_set_string(value, pw3270_action_get_tooltip(action)); | |
| 255 | + break; | |
| 256 | + | |
| 208 | 257 | case PROP_PARAMETER_TYPE: |
| 209 | 258 | g_value_set_boxed(value, get_parameter_type(action)); |
| 210 | 259 | break; |
| ... | ... | @@ -408,6 +457,16 @@ |
| 408 | 457 | return PW3270_ACTION_GET_CLASS(action)->get_icon_name(action); |
| 409 | 458 | } |
| 410 | 459 | |
| 460 | + GtkImage * pw3270_action_get_image(GAction *action, GtkIconSize icon_size) { | |
| 461 | + | |
| 462 | + const gchar * icon_name = pw3270_action_get_icon_name(action); | |
| 463 | + if(!icon_name) | |
| 464 | + return NULL; | |
| 465 | + | |
| 466 | + return GTK_IMAGE(gtk_image_new_from_icon_name(icon_name,icon_size)); | |
| 467 | + } | |
| 468 | + | |
| 469 | + | |
| 411 | 470 | const gchar * pw3270_action_get_label(GAction *action) { |
| 412 | 471 | const gchar * label = PW3270_ACTION_GET_CLASS(action)->get_label(action); |
| 413 | 472 | ... | ... |
| ... | ... | @@ -0,0 +1,166 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * @brief Implement PW3270 Action view widget and related tools. | |
| 32 | + * | |
| 33 | + */ | |
| 34 | + | |
| 35 | + #include <config.h> | |
| 36 | + #include <pw3270.h> | |
| 37 | + #include <pw3270/actions.h> | |
| 38 | + #include <lib3270/log.h> | |
| 39 | + | |
| 40 | + struct ListElement { | |
| 41 | + GAction * action; | |
| 42 | + GtkImage * image; | |
| 43 | + gchar name[1]; | |
| 44 | + }; | |
| 45 | + | |
| 46 | + GtkWidget * pw3270_action_view_new() { | |
| 47 | + | |
| 48 | + GtkWidget * view = GTK_WIDGET(gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtk_list_store_new(1,G_TYPE_OBJECT)))); | |
| 49 | + | |
| 50 | + gtk_widget_set_hexpand(view,TRUE); | |
| 51 | + gtk_widget_set_vexpand(view,TRUE); | |
| 52 | + gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(view),FALSE); | |
| 53 | + | |
| 54 | + // Create Renderers | |
| 55 | + GtkCellRenderer * text_renderer = gtk_cell_renderer_text_new(); | |
| 56 | + | |
| 57 | + gtk_tree_view_insert_column_with_attributes( | |
| 58 | + GTK_TREE_VIEW(view), | |
| 59 | + -1, | |
| 60 | + _("Label"), | |
| 61 | + text_renderer, | |
| 62 | + "text",0, | |
| 63 | + NULL | |
| 64 | + ); | |
| 65 | + | |
| 66 | + return view; | |
| 67 | + } | |
| 68 | + | |
| 69 | + /* | |
| 70 | + void pw3270_action_view_append_application_action(GtkWidget *widget, GAction *action) { | |
| 71 | + | |
| 72 | + g_return_if_fail(PW3270_IS_ACTION(action)); | |
| 73 | + | |
| 74 | + GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); | |
| 75 | + GtkTreeIter iter; | |
| 76 | + | |
| 77 | + gtk_list_store_append(store, &iter); | |
| 78 | + gtk_list_store_set(store, &iter, 0, action); | |
| 79 | + | |
| 80 | + } | |
| 81 | + */ | |
| 82 | + | |
| 83 | + static GSList * append_action(GSList * list, const gchar *type, GAction *action) { | |
| 84 | + | |
| 85 | + if(!action) | |
| 86 | + return list; | |
| 87 | + | |
| 88 | + GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(action),"toolbar-icon"); | |
| 89 | + | |
| 90 | + if(!spec) | |
| 91 | + return list; | |
| 92 | + | |
| 93 | + const gchar *name = g_action_get_name(action); | |
| 94 | +// debug("%s=%p",name,action); | |
| 95 | + | |
| 96 | + GValue value = G_VALUE_INIT; | |
| 97 | + g_value_init(&value, GTK_TYPE_IMAGE); | |
| 98 | + | |
| 99 | + g_object_get_property(G_OBJECT(action),"toolbar-icon",&value); | |
| 100 | + GObject * image = g_value_get_object(&value); | |
| 101 | + g_value_unset (&value); | |
| 102 | + | |
| 103 | + if(!image) | |
| 104 | + return list; | |
| 105 | + | |
| 106 | + struct ListElement * element = (struct ListElement *) g_malloc0(sizeof(struct ListElement) + strlen(type) + strlen(name)); | |
| 107 | + | |
| 108 | + strcpy(element->name,type); | |
| 109 | + strcat(element->name,name); | |
| 110 | + | |
| 111 | + element->action = action; | |
| 112 | + | |
| 113 | + element->image = GTK_IMAGE(image); | |
| 114 | + g_object_ref_sink(G_OBJECT(element->image)); | |
| 115 | + | |
| 116 | + return g_slist_prepend(list,element); | |
| 117 | + | |
| 118 | + } | |
| 119 | + | |
| 120 | + Pw3270ActionList * pw3270_action_list_new(GtkApplication *application) { | |
| 121 | + | |
| 122 | + GSList * list = NULL; | |
| 123 | + | |
| 124 | + gchar ** action_names; | |
| 125 | + size_t ix; | |
| 126 | + | |
| 127 | + // Get application actions. | |
| 128 | + | |
| 129 | + action_names = g_action_group_list_actions(G_ACTION_GROUP(application)); | |
| 130 | + for(ix = 0; action_names[ix];ix++) { | |
| 131 | + list = append_action(list,"app.",g_action_map_lookup_action(G_ACTION_MAP(application),action_names[ix])); | |
| 132 | + } | |
| 133 | + g_strfreev(action_names); | |
| 134 | + | |
| 135 | + // Get Windows actions. | |
| 136 | + GtkWindow * window = gtk_application_get_active_window(application); | |
| 137 | + | |
| 138 | + if(window && G_IS_ACTION_GROUP(window)) { | |
| 139 | + | |
| 140 | + // Get window actions. | |
| 141 | + action_names = g_action_group_list_actions(G_ACTION_GROUP(window)); | |
| 142 | + for(ix = 0; action_names[ix];ix++) { | |
| 143 | + list = append_action(list,"win.",g_action_map_lookup_action(G_ACTION_MAP(window),action_names[ix])); | |
| 144 | + } | |
| 145 | + g_strfreev(action_names); | |
| 146 | + | |
| 147 | + } | |
| 148 | + | |
| 149 | + return (Pw3270ActionList *) list; | |
| 150 | + } | |
| 151 | + | |
| 152 | + static void free_element(struct ListElement *element) { | |
| 153 | + | |
| 154 | + if(element->image) { | |
| 155 | + g_object_unref(element->image); | |
| 156 | + element->image = NULL; | |
| 157 | + } | |
| 158 | + | |
| 159 | + g_free(element); | |
| 160 | + | |
| 161 | + } | |
| 162 | + | |
| 163 | + void pw3270_action_list_free(Pw3270ActionList *action_list) { | |
| 164 | + g_slist_free_full((GSList *) action_list, (GDestroyNotify) free_element); | |
| 165 | + } | |
| 166 | + | ... | ... |
src/objects/toolbar/settings.c
| ... | ... | @@ -29,6 +29,7 @@ |
| 29 | 29 | |
| 30 | 30 | #include "private.h" |
| 31 | 31 | #include <pw3270/settings.h> |
| 32 | + #include <pw3270/actions.h> | |
| 32 | 33 | |
| 33 | 34 | typedef struct _ToolbarSettingsPage { |
| 34 | 35 | Pw3270SettingsPage parent; |
| ... | ... | @@ -39,21 +40,19 @@ |
| 39 | 40 | |
| 40 | 41 | static void load(Pw3270SettingsPage *pg, GtkApplication *application, GSettings *settings) { |
| 41 | 42 | debug("%s",__FUNCTION__); |
| 42 | - } | |
| 43 | 43 | |
| 44 | - static void apply(Pw3270SettingsPage *pg, GtkApplication *application, GSettings *settings) { | |
| 45 | - debug("%s",__FUNCTION__); | |
| 46 | - } | |
| 44 | + // Populate views | |
| 45 | + Pw3270ActionList * actions = pw3270_action_list_new(application); | |
| 46 | + | |
| 47 | 47 | |
| 48 | - GtkWidget * pw3270_action_store_new() { | |
| 49 | 48 | |
| 50 | - GtkWidget * view = GTK_WIDGET(gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtk_list_store_new(2,G_TYPE_OBJECT,G_TYPE_STRING)))); | |
| 49 | + pw3270_action_list_free(actions); | |
| 51 | 50 | |
| 52 | - gtk_widget_set_hexpand(view,TRUE); | |
| 53 | - gtk_widget_set_vexpand(view,TRUE); | |
| 54 | - gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(view),FALSE); | |
| 55 | 51 | |
| 56 | - return view; | |
| 52 | + } | |
| 53 | + | |
| 54 | + static void apply(Pw3270SettingsPage *pg, GtkApplication *application, GSettings *settings) { | |
| 55 | + debug("%s",__FUNCTION__); | |
| 57 | 56 | } |
| 58 | 57 | |
| 59 | 58 | Pw3270SettingsPage * pw3270_toolbar_settings_new() { |
| ... | ... | @@ -78,7 +77,7 @@ |
| 78 | 77 | |
| 79 | 78 | for(ix = 0; ix < G_N_ELEMENTS(page->views); ix++) { |
| 80 | 79 | |
| 81 | - page->views[ix] = pw3270_action_store_new(); | |
| 80 | + page->views[ix] = pw3270_action_view_new(); | |
| 82 | 81 | |
| 83 | 82 | gtk_grid_attach( |
| 84 | 83 | GTK_GRID(page->parent.widget), | ... | ... |
src/objects/window/window.c
| ... | ... | @@ -284,13 +284,6 @@ |
| 284 | 284 | G_SETTINGS_BIND_DEFAULT |
| 285 | 285 | ); |
| 286 | 286 | |
| 287 | -#ifdef DEBUG | |
| 288 | - { | |
| 289 | - g_autofree gchar * an = pw3270_window_get_action_names(window); | |
| 290 | - | |
| 291 | - } | |
| 292 | -#endif // DEBUG | |
| 293 | - | |
| 294 | 287 | } else { |
| 295 | 288 | |
| 296 | 289 | gtk_window_set_title(GTK_WINDOW(window), title); | ... | ... |