Commit 627823e23984bd11f7809b4b30029ddf2af23463

Authored by Perry Werneck
1 parent 174e1cfc

Implementing linux version of the save launcher action.

Makefile.in
... ... @@ -39,6 +39,7 @@ SOURCES= \
39 39 $(wildcard src/objects/terminal/*.c) \
40 40 $(wildcard src/objects/toolbar/*.c) \
41 41 $(wildcard src/objects/settings/*.c) \
  42 + $(wildcard src/objects/@OSNAME@/*.c) \
42 43 $(wildcard src/main/*.c) \
43 44 $(wildcard src/main/@OSNAME@/*.c) \
44 45 $(wildcard src/main/@OSNAME@/*.rc)
... ...
pw3270.cbp
... ... @@ -109,6 +109,9 @@
109 109 <Option compilerVar="CC" />
110 110 </Unit>
111 111 <Unit filename="src/objects/application/private.h" />
  112 + <Unit filename="src/objects/linux/savedesktopicon.c">
  113 + <Option compilerVar="CC" />
  114 + </Unit>
112 115 <Unit filename="src/objects/settings/dialog.c">
113 116 <Option compilerVar="CC" />
114 117 </Unit>
... ...
src/objects/linux/savedesktopicon.c 0 → 100644
... ... @@ -0,0 +1,188 @@
  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 Linux version of the save desktop icon action.
  32 + *
  33 + */
  34 +
  35 + #include <v3270.h>
  36 + #include <pw3270.h>
  37 + #include <pw3270/application.h>
  38 + #include <v3270/actions.h>
  39 + #include <lib3270.h>
  40 + #include <lib3270/log.h>
  41 +
  42 + static GtkWidget * factory(V3270SimpleAction *action, GtkWidget *terminal);
  43 + static void response(GtkWidget *dialog, gint response_id, GtkWidget *terminal);
  44 +
  45 +/*
  46 +
  47 +[Desktop Entry]
  48 +GenericName=pw3270
  49 +Name=pw3270
  50 +Comment=Comment
  51 +Exec=/usr/bin/sisbb
  52 +Icon=pw3270
  53 +Terminal=false
  54 +Type=Application
  55 +StartupNotify=true
  56 +Categories=GTK;GNOME;TerminalEmulator
  57 +OnlyShowIn=GNOME;Unity
  58 +X-Desktop-File-Install-Version=0.23
  59 +
  60 +*/
  61 +
  62 + static const struct _entry {
  63 +
  64 + const gchar * label;
  65 + const gchar * tooltip;
  66 + gint width;
  67 +// gint n_chars;
  68 +
  69 + } entries[] = {
  70 +
  71 + {
  72 + .label = N_("File name"),
  73 + .width = 40,
  74 +// .n_chars = 40
  75 + },
  76 +
  77 + {
  78 + .label = N_("Launcher name"),
  79 + .width = 20,
  80 +// .n_chars = 128
  81 + },
  82 +
  83 + {
  84 + .label = N_("Comment"),
  85 + .width = 30,
  86 +// .n_chars = 128
  87 + }
  88 +
  89 + };
  90 +
  91 + GAction * pw3270_action_save_desktop_icon_new(void) {
  92 +
  93 + V3270SimpleAction * action = v3270_dialog_action_new(factory);
  94 +
  95 + action->name = "save.launcher";
  96 + action->label = _("Save desktop launcher");
  97 + action->tooltip = _("Save desktop launcher");
  98 +
  99 + return G_ACTION(action);
  100 +
  101 + }
  102 +
  103 + GtkWidget * factory(V3270SimpleAction *action, GtkWidget *terminal) {
  104 +
  105 + size_t ix;
  106 +
  107 + gboolean use_header;
  108 + g_object_get(gtk_settings_get_default(), "gtk-dialogs-use-header", &use_header, NULL);
  109 +
  110 + GtkWidget * dialog =
  111 + GTK_WIDGET(g_object_new(
  112 + GTK_TYPE_DIALOG,
  113 + "use-header-bar", (use_header ? 1 : 0),
  114 + NULL
  115 + ));
  116 +
  117 +
  118 + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE);
  119 + gtk_window_set_title(GTK_WINDOW(dialog),action->label);
  120 +
  121 + gtk_dialog_add_buttons(
  122 + GTK_DIALOG(dialog),
  123 + _("_Cancel"), GTK_RESPONSE_CANCEL,
  124 + _("_Save"), GTK_RESPONSE_APPLY,
  125 + NULL
  126 + );
  127 +
  128 + g_signal_connect(dialog,"response",G_CALLBACK(response),terminal);
  129 +
  130 + // Create entry fields
  131 + GtkWidget ** inputs = g_new0(GtkWidget *,G_N_ELEMENTS(entries));
  132 + g_object_set_data_full(G_OBJECT(dialog),"inputs",inputs,g_free);
  133 +
  134 + GtkGrid * grid = GTK_GRID(gtk_grid_new());
  135 +
  136 + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),GTK_WIDGET(grid),TRUE,TRUE,0);
  137 +
  138 + // https://developer.gnome.org/hig/stable/visual-layout.html.en
  139 + gtk_container_set_border_width(GTK_CONTAINER(grid),18);
  140 + gtk_grid_set_row_spacing(GTK_GRID(grid),6);
  141 + gtk_grid_set_column_spacing(GTK_GRID(grid),12);
  142 +
  143 + // https://developer.gnome.org/hig/stable/visual-layout.html.en
  144 + // gtk_box_set_spacing(GTK_BOX(content_area),18);
  145 +
  146 + for(ix = 0; ix < G_N_ELEMENTS(entries); ix++) {
  147 +
  148 + GtkWidget * label = gtk_label_new(gettext(entries[ix].label));
  149 + gtk_label_set_xalign(GTK_LABEL(label),1);
  150 + gtk_grid_attach(grid,label,0,ix,1,1);
  151 +
  152 + inputs[ix] = gtk_entry_new();
  153 + gtk_entry_set_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].width);
  154 +// gtk_entry_set_max_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].n_chars);
  155 + gtk_widget_set_hexpand(inputs[ix],FALSE);
  156 + gtk_widget_set_vexpand(inputs[ix],FALSE);
  157 +
  158 + gtk_grid_attach(grid,inputs[ix],1,ix,entries[ix].width,1);
  159 +
  160 + }
  161 +
  162 + g_autofree gchar * filename = g_strdup_printf("%s/" G_STRINGIFY(PRODUCT_NAME) ".desktop",g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP));
  163 +
  164 + gtk_entry_set_text(GTK_ENTRY(inputs[0]),filename);
  165 +
  166 + gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[1]),G_STRINGIFY(PRODUCT_NAME));
  167 + gtk_entry_set_text(GTK_ENTRY(inputs[1]),G_STRINGIFY(PRODUCT_NAME));
  168 +
  169 + gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[2]),v3270_get_url(terminal));
  170 + gtk_entry_set_text(GTK_ENTRY(inputs[2]),v3270_get_url(terminal));
  171 + gtk_entry_set_input_hints(GTK_ENTRY(inputs[2]),GTK_INPUT_HINT_SPELLCHECK);
  172 +
  173 + gtk_widget_show_all(GTK_WIDGET(grid));
  174 + return dialog;
  175 + }
  176 +
  177 + void response(GtkWidget *dialog, gint response_id, GtkWidget *terminal) {
  178 +
  179 + debug("%s(%d)",__FUNCTION__,response_id);
  180 +
  181 +
  182 + gtk_widget_destroy(dialog);
  183 +
  184 + if(response_id == GTK_RESPONSE_OK) {
  185 +
  186 + }
  187 +
  188 + }
... ...
src/objects/window/private.h
... ... @@ -89,6 +89,7 @@
89 89 G_GNUC_INTERNAL GAction * pw3270_action_window_close_new(void);
90 90 G_GNUC_INTERNAL GAction * pw3270_action_connect_new(void);
91 91 G_GNUC_INTERNAL GAction * pw3270_action_save_session_as_new(void);
  92 + G_GNUC_INTERNAL GAction * pw3270_action_save_desktop_icon_new(void);
92 93  
93 94 GAction * pw3270_action_session_properties_new(void);
94 95  
... ...
src/objects/window/window.c
... ... @@ -229,6 +229,8 @@
229 229 v3270_pfkey_action_new(),
230 230 v3270_pakey_action_new(),
231 231  
  232 + pw3270_action_save_desktop_icon_new(),
  233 +
232 234 };
233 235  
234 236 for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) {
... ...
ui/application.xml
... ... @@ -134,25 +134,38 @@
134 134  
135 135 <attribute name='label' translatable='yes'>Save</attribute>
136 136  
137   - <item>
138   - <attribute name="label" translatable="yes">Session properties</attribute>
139   - <attribute name="action">win.save.session.as</attribute>
140   - </item>
  137 + <section>
141 138  
142   - <item>
143   - <attribute name="label" translatable="yes">Current screen</attribute>
144   - <attribute name="action">win.save-all</attribute>
145   - </item>
  139 + <item>
  140 + <attribute name="label" translatable="yes">Current screen</attribute>
  141 + <attribute name="action">win.save-all</attribute>
  142 + </item>
146 143  
147   - <item>
148   - <attribute name="label" translatable="yes">Selected area</attribute>
149   - <attribute name="action">win.save-selected</attribute>
150   - </item>
  144 + <item>
  145 + <attribute name="label" translatable="yes">Selected area</attribute>
  146 + <attribute name="action">win.save-selected</attribute>
  147 + </item>
151 148  
152   - <item>
153   - <attribute name="label" translatable="yes">Clipboard contents</attribute>
154   - <attribute name="action">win.save-copy</attribute>
155   - </item>
  149 + <item>
  150 + <attribute name="label" translatable="yes">Clipboard contents</attribute>
  151 + <attribute name="action">win.save-copy</attribute>
  152 + </item>
  153 +
  154 + </section>
  155 +
  156 + <section>
  157 +
  158 + <item>
  159 + <attribute name="label" translatable="yes">Desktop icon</attribute>
  160 + <attribute name="action">win.save.launcher</attribute>
  161 + </item>
  162 +
  163 + <item>
  164 + <attribute name="label" translatable="yes">Session properties</attribute>
  165 + <attribute name="action">win.save.session.as</attribute>
  166 + </item>
  167 +
  168 + </section>
156 169  
157 170 </submenu>
158 171  
... ...
ui/window.xml
... ... @@ -68,25 +68,38 @@
68 68  
69 69 <attribute name='label' translatable='yes'>Save</attribute>
70 70  
71   - <item>
72   - <attribute name="label" translatable="yes">Session properties</attribute>
73   - <attribute name="action">win.save.session.as</attribute>
74   - </item>
  71 + <section>
75 72  
76   - <item>
77   - <attribute name="label" translatable="yes">Current screen</attribute>
78   - <attribute name="action">win.save-all</attribute>
79   - </item>
  73 + <item>
  74 + <attribute name="label" translatable="yes">Current screen</attribute>
  75 + <attribute name="action">win.save-all</attribute>
  76 + </item>
80 77  
81   - <item>
82   - <attribute name="label" translatable="yes">Selected area</attribute>
83   - <attribute name="action">win.save-selected</attribute>
84   - </item>
  78 + <item>
  79 + <attribute name="label" translatable="yes">Selected area</attribute>
  80 + <attribute name="action">win.save-selected</attribute>
  81 + </item>
85 82  
86   - <item>
87   - <attribute name="label" translatable="yes">Clipboard contents</attribute>
88   - <attribute name="action">win.save-copy</attribute>
89   - </item>
  83 + <item>
  84 + <attribute name="label" translatable="yes">Clipboard contents</attribute>
  85 + <attribute name="action">win.save-copy</attribute>
  86 + </item>
  87 +
  88 + </section>
  89 +
  90 + <section>
  91 +
  92 + <item>
  93 + <attribute name="label" translatable="yes">Desktop icon</attribute>
  94 + <attribute name="action">win.save.launcher</attribute>
  95 + </item>
  96 +
  97 + <item>
  98 + <attribute name="label" translatable="yes">Session properties</attribute>
  99 + <attribute name="action">win.save.session.as</attribute>
  100 + </item>
  101 +
  102 + </section>
90 103  
91 104 </submenu>
92 105  
... ...