Commit 5c5fa189661b037ecfbc471d5c2f2ae63cb6e4a3
1 parent
8803e9e5
Exists in
master
and in
4 other branches
Implementing the new UI.
Showing
6 changed files
with
164 additions
and
27 deletions
Show diff stats
src/include/pw3270/window.h
| @@ -68,6 +68,15 @@ | @@ -68,6 +68,15 @@ | ||
| 68 | /// @brief Get the active session handle. | 68 | /// @brief Get the active session handle. |
| 69 | H3270 * pw3270_window_get_session_handle(GtkWidget *window); | 69 | H3270 * pw3270_window_get_session_handle(GtkWidget *window); |
| 70 | 70 | ||
| 71 | + /// @brief Switches to the page number page_num. | ||
| 72 | + void pw3270_window_set_current_page(GtkWidget *window, gint page_num); | ||
| 73 | + | ||
| 74 | + /// @brief Appends a new terminal to window. | ||
| 75 | + gint pw3270_window_append_page(GtkWidget *window, GFile *file); | ||
| 76 | + | ||
| 77 | + /// @brief Set window sub-title (If enabled). | ||
| 78 | + void pw3270_window_set_subtitle(GtkWidget *window, const gchar *subtitle); | ||
| 79 | + | ||
| 71 | G_END_DECLS | 80 | G_END_DECLS |
| 72 | 81 | ||
| 73 | 82 |
src/objects/window/application.c
| @@ -42,9 +42,9 @@ | @@ -42,9 +42,9 @@ | ||
| 42 | GtkApplication parent; | 42 | GtkApplication parent; |
| 43 | }; | 43 | }; |
| 44 | 44 | ||
| 45 | - static void startup(GApplication * application); | ||
| 46 | - static void activate(GApplication * application); | ||
| 47 | - static void open(GApplication * application, GFile **files, gint n_files, const gchar *hint); | 45 | + static void startup(GApplication * application); |
| 46 | + static void activate(GApplication * application); | ||
| 47 | + static void open(GApplication * application, GFile **files, gint n_files, const gchar *hint); | ||
| 48 | 48 | ||
| 49 | G_DEFINE_TYPE(pw3270Application, pw3270Application, GTK_TYPE_APPLICATION); | 49 | G_DEFINE_TYPE(pw3270Application, pw3270Application, GTK_TYPE_APPLICATION); |
| 50 | 50 | ||
| @@ -152,26 +152,39 @@ | @@ -152,26 +152,39 @@ | ||
| 152 | 152 | ||
| 153 | GtkWidget * window = pw3270_application_window_new(GTK_APPLICATION(application)); | 153 | GtkWidget * window = pw3270_application_window_new(GTK_APPLICATION(application)); |
| 154 | 154 | ||
| 155 | - gtk_application_window_set_show_menubar(GTK_APPLICATION_WINDOW(window),TRUE); | ||
| 156 | - | ||
| 157 | // Create terminal widget | 155 | // Create terminal widget |
| 158 | pw3270_terminal_new(window); | 156 | pw3270_terminal_new(window); |
| 159 | - pw3270_terminal_new(window); | ||
| 160 | - | ||
| 161 | - // Setup and show main window | ||
| 162 | - gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); | ||
| 163 | - gtk_window_set_default_size (GTK_WINDOW (window), 800, 500); | ||
| 164 | 157 | ||
| 165 | - // gtk_widget_show_all(window); | 158 | + // Present the new window |
| 166 | gtk_window_present(GTK_WINDOW(window)); | 159 | gtk_window_present(GTK_WINDOW(window)); |
| 160 | + pw3270_window_set_current_page(window,0); | ||
| 167 | 161 | ||
| 168 | } | 162 | } |
| 169 | 163 | ||
| 170 | void open(GApplication *application, GFile **files, gint n_files, const gchar *hint) { | 164 | void open(GApplication *application, GFile **files, gint n_files, const gchar *hint) { |
| 171 | 165 | ||
| 166 | + GtkWindow * window = gtk_application_get_active_window(GTK_APPLICATION(application)); | ||
| 167 | + | ||
| 168 | + debug("%s was called with %d files (active_window=%p)", __FUNCTION__, n_files, window); | ||
| 169 | + | ||
| 170 | + if(!window) | ||
| 171 | + window = GTK_WINDOW(pw3270_application_window_new(GTK_APPLICATION(application))); | ||
| 172 | + | ||
| 173 | + // Add tabs to the window | ||
| 174 | + gint file; | ||
| 175 | + gint last = -1; | ||
| 176 | + | ||
| 177 | + for(file = 0; file < n_files; file++) { | ||
| 178 | + last = pw3270_window_append_page(GTK_WIDGET(window), files[file]); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + gtk_window_present(window); | ||
| 182 | + | ||
| 183 | + if(last != -1) | ||
| 184 | + pw3270_window_set_current_page(GTK_WIDGET(window),last); | ||
| 185 | + | ||
| 172 | } | 186 | } |
| 173 | 187 | ||
| 174 | PW3270_UI_TYPE pw3270_application_get_ui_type(GApplication *app) { | 188 | PW3270_UI_TYPE pw3270_application_get_ui_type(GApplication *app) { |
| 175 | return PW3270_UI_STYLE_GNOME; | 189 | return PW3270_UI_STYLE_GNOME; |
| 176 | } | 190 | } |
| 177 | - |
src/objects/window/private.h
src/objects/window/terminal.c
| @@ -29,6 +29,7 @@ | @@ -29,6 +29,7 @@ | ||
| 29 | 29 | ||
| 30 | #include "private.h" | 30 | #include "private.h" |
| 31 | #include <pw3270/actions.h> | 31 | #include <pw3270/actions.h> |
| 32 | + #include <lib3270/toggle.h> | ||
| 32 | 33 | ||
| 33 | static void session_changed(GtkWidget *terminal, GtkWidget *label) { | 34 | static void session_changed(GtkWidget *terminal, GtkWidget *label) { |
| 34 | 35 | ||
| @@ -40,7 +41,7 @@ | @@ -40,7 +41,7 @@ | ||
| 40 | 41 | ||
| 41 | pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(toplevel); | 42 | pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(toplevel); |
| 42 | 43 | ||
| 43 | - if(window->terminal == terminal) { | 44 | + if(gtk_widget_has_default(terminal)) { |
| 44 | g_autofree gchar * title = v3270_get_session_title(terminal); | 45 | g_autofree gchar * title = v3270_get_session_title(terminal); |
| 45 | gtk_window_set_title(GTK_WINDOW(window), title); | 46 | gtk_window_set_title(GTK_WINDOW(window), title); |
| 46 | } | 47 | } |
| @@ -49,39 +50,119 @@ | @@ -49,39 +50,119 @@ | ||
| 49 | 50 | ||
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | - static gboolean on_terminal_focus(GtkWidget *terminal, GdkEvent *event, pw3270ApplicationWindow * window) { | 53 | + static gboolean on_terminal_focus(GtkWidget *terminal, GdkEvent *event, GtkWindow * window) { |
| 53 | 54 | ||
| 54 | - // Store the active terminal widget. | ||
| 55 | - window->terminal = terminal; | 55 | + // Store the active terminal widget. |
| 56 | + gtk_widget_grab_default(terminal); | ||
| 57 | + debug("Terminal %p is now default",terminal); | ||
| 56 | 58 | ||
| 57 | // Change window title | 59 | // Change window title |
| 58 | g_autofree gchar * title = v3270_get_session_title(terminal); | 60 | g_autofree gchar * title = v3270_get_session_title(terminal); |
| 59 | - gtk_window_set_title(GTK_WINDOW(window), title); | 61 | + gtk_window_set_title(window, title); |
| 62 | + | ||
| 63 | + pw3270_window_set_subtitle(GTK_WIDGET(window), v3270_is_connected(terminal) ? _("Connected to host") : _("Disconnected from host")); | ||
| 60 | 64 | ||
| 61 | return FALSE; | 65 | return FALSE; |
| 62 | } | 66 | } |
| 63 | 67 | ||
| 64 | - GtkWidget * pw3270_terminal_new(GtkWidget *widget) { | 68 | + static gboolean bg_auto_connect(GtkWidget *terminal) { |
| 69 | + v3270_reconnect(terminal); | ||
| 70 | + return FALSE; | ||
| 71 | + } | ||
| 65 | 72 | ||
| 66 | - g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(widget),NULL); | 73 | + static void disconnected(GtkWidget *terminal, GtkWindow * window) { |
| 74 | + | ||
| 75 | + debug("%s",__FUNCTION__); | ||
| 76 | + | ||
| 77 | + if(terminal != gtk_window_get_default_widget(window)) | ||
| 78 | + return; | ||
| 79 | + | ||
| 80 | + pw3270_window_set_subtitle(GTK_WIDGET(window), _("Disconnected from host")); | ||
| 81 | + | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + static void connected(GtkWidget *terminal, const gchar *host, GtkWindow * window) { | ||
| 85 | + | ||
| 86 | + debug("%s(%s)",__FUNCTION__,host); | ||
| 87 | + | ||
| 88 | + if(terminal != gtk_window_get_default_widget(window)) | ||
| 89 | + return; | ||
| 90 | + | ||
| 91 | + pw3270_window_set_subtitle(GTK_WIDGET(window), _("Connected to host")); | ||
| 92 | + | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + static gint append_terminal_page(pw3270ApplicationWindow * window, GtkWidget * terminal) { | ||
| 67 | 96 | ||
| 68 | - pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(widget); | ||
| 69 | - GtkWidget * terminal = v3270_new(); | ||
| 70 | GtkWidget * label = gtk_label_new(v3270_get_session_name(terminal)); | 97 | GtkWidget * label = gtk_label_new(v3270_get_session_name(terminal)); |
| 71 | 98 | ||
| 72 | - g_signal_connect(G_OBJECT(terminal), "focus-in-event", G_CALLBACK(on_terminal_focus), widget); | 99 | + g_signal_connect(G_OBJECT(terminal), "focus-in-event", G_CALLBACK(on_terminal_focus), window); |
| 73 | g_signal_connect(G_OBJECT(terminal), "session_changed", G_CALLBACK(session_changed),label); | 100 | g_signal_connect(G_OBJECT(terminal), "session_changed", G_CALLBACK(session_changed),label); |
| 101 | + g_signal_connect(G_OBJECT(terminal),"disconnected",G_CALLBACK(disconnected),window); | ||
| 102 | + g_signal_connect(G_OBJECT(terminal),"connected",G_CALLBACK(connected),window); | ||
| 74 | 103 | ||
| 75 | gtk_widget_show_all(terminal); | 104 | gtk_widget_show_all(terminal); |
| 76 | gtk_widget_show_all(label); | 105 | gtk_widget_show_all(label); |
| 77 | 106 | ||
| 78 | - gtk_notebook_append_page(window->notebook,terminal,label); | ||
| 79 | - gtk_notebook_set_show_tabs(window->notebook,gtk_notebook_get_n_pages(GTK_NOTEBOOK(window->notebook)) > 1); | 107 | + gint page = gtk_notebook_append_page(window->notebook,terminal,label); |
| 108 | + gtk_notebook_set_show_tabs(window->notebook,gtk_notebook_get_n_pages(window->notebook) > 1); | ||
| 80 | 109 | ||
| 81 | gtk_notebook_set_tab_detachable(window->notebook,terminal,TRUE); | 110 | gtk_notebook_set_tab_detachable(window->notebook,terminal,TRUE); |
| 82 | gtk_notebook_set_tab_reorderable(window->notebook,terminal,TRUE); | 111 | gtk_notebook_set_tab_reorderable(window->notebook,terminal,TRUE); |
| 83 | 112 | ||
| 113 | + // Setup session. | ||
| 114 | + | ||
| 115 | + H3270 * hSession = v3270_get_session(terminal); | ||
| 116 | + | ||
| 117 | + if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_CONNECT_ON_STARTUP)) | ||
| 118 | + g_idle_add((GSourceFunc) bg_auto_connect, terminal); | ||
| 119 | + | ||
| 120 | + return page; | ||
| 121 | + | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + GtkWidget * pw3270_terminal_new(GtkWidget *widget) { | ||
| 125 | + | ||
| 126 | + g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(widget),NULL); | ||
| 127 | + | ||
| 128 | + pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(widget); | ||
| 129 | + GtkWidget * terminal = v3270_new(); | ||
| 130 | + | ||
| 131 | + append_terminal_page(window,terminal); | ||
| 132 | + | ||
| 84 | return terminal; | 133 | return terminal; |
| 85 | 134 | ||
| 86 | } | 135 | } |
| 87 | 136 | ||
| 137 | + gint pw3270_window_append_page(GtkWidget *widget, GFile * file) { | ||
| 138 | + | ||
| 139 | + g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(widget),-1); | ||
| 140 | + | ||
| 141 | + pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(widget); | ||
| 142 | + GtkWidget * terminal = v3270_new(); | ||
| 143 | + | ||
| 144 | + // Identify argument. | ||
| 145 | + g_autofree gchar * scheme = g_file_get_uri_scheme(file); | ||
| 146 | + | ||
| 147 | + if(!(g_ascii_strcasecmp(scheme,"tn3270") && g_ascii_strcasecmp(scheme,"tn3270s"))) { | ||
| 148 | + | ||
| 149 | + // Is a 3270 URL. | ||
| 150 | + g_autofree gchar * uri = g_file_get_uri(file); | ||
| 151 | + size_t sz = strlen(uri); | ||
| 152 | + | ||
| 153 | + if(sz > 0 && uri[sz-1] == '/') | ||
| 154 | + uri[sz-1] = 0; | ||
| 155 | + | ||
| 156 | + v3270_set_url(terminal,uri); | ||
| 157 | + | ||
| 158 | + } else { | ||
| 159 | + | ||
| 160 | + g_message("Unexpected URI scheme: \"%s\"",scheme); | ||
| 161 | + | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + return append_terminal_page(window, terminal); | ||
| 165 | + | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + |
src/objects/window/testprogram/testprogram.c
| @@ -63,6 +63,11 @@ GtkWidget * pw3270_toolbar_new(void) { | @@ -63,6 +63,11 @@ GtkWidget * pw3270_toolbar_new(void) { | ||
| 63 | 63 | ||
| 64 | GtkToolItem * button = gtk_tool_button_new(gtk_image_new_from_icon_name(itens[item].icon,GTK_ICON_SIZE_LARGE_TOOLBAR),itens[item].label); | 64 | GtkToolItem * button = gtk_tool_button_new(gtk_image_new_from_icon_name(itens[item].icon,GTK_ICON_SIZE_LARGE_TOOLBAR),itens[item].label); |
| 65 | gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(button),TRUE); | 65 | gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(button),TRUE); |
| 66 | + | ||
| 67 | + gtk_widget_set_can_focus(GTK_WIDGET(button),FALSE); | ||
| 68 | + gtk_widget_set_can_default(GTK_WIDGET(button),FALSE); | ||
| 69 | + gtk_widget_set_focus_on_click(GTK_WIDGET(button),FALSE); | ||
| 70 | + | ||
| 66 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), button, -1); | 71 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), button, -1); |
| 67 | 72 | ||
| 68 | } | 73 | } |
src/objects/window/window.c
| @@ -56,7 +56,6 @@ | @@ -56,7 +56,6 @@ | ||
| 56 | GtkBox * vBox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL,0)); | 56 | GtkBox * vBox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL,0)); |
| 57 | 57 | ||
| 58 | widget->notebook = GTK_NOTEBOOK(gtk_notebook_new()); | 58 | widget->notebook = GTK_NOTEBOOK(gtk_notebook_new()); |
| 59 | - widget->terminal = pw3270_terminal_new(GTK_WIDGET(widget)); | ||
| 60 | widget->toolbar = GTK_TOOLBAR(pw3270_toolbar_new()); | 59 | widget->toolbar = GTK_TOOLBAR(pw3270_toolbar_new()); |
| 61 | 60 | ||
| 62 | gtk_notebook_set_show_tabs(widget->notebook,FALSE); | 61 | gtk_notebook_set_show_tabs(widget->notebook,FALSE); |
| @@ -102,7 +101,8 @@ | @@ -102,7 +101,8 @@ | ||
| 102 | gtk_header_bar_set_show_close_button(header,TRUE); | 101 | gtk_header_bar_set_show_close_button(header,TRUE); |
| 103 | 102 | ||
| 104 | gtk_header_bar_set_title(header,title); | 103 | gtk_header_bar_set_title(header,title); |
| 105 | - gtk_header_bar_set_subtitle(header,_("Disconnected from host")); | 104 | + // gtk_header_bar_set_subtitle(header,_("Disconnected from host")); |
| 105 | + gtk_header_bar_set_has_subtitle(header,TRUE); | ||
| 106 | 106 | ||
| 107 | // Create gear button | 107 | // Create gear button |
| 108 | // https://wiki.gnome.org/Initiatives/GnomeGoals/GearIcons | 108 | // https://wiki.gnome.org/Initiatives/GnomeGoals/GearIcons |
| @@ -133,7 +133,37 @@ | @@ -133,7 +133,37 @@ | ||
| 133 | 133 | ||
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | + // Setup and show main window | ||
| 137 | + gtk_application_window_set_show_menubar(GTK_APPLICATION_WINDOW(window),TRUE); | ||
| 138 | + | ||
| 139 | + gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); | ||
| 140 | + gtk_window_set_default_size (GTK_WINDOW (window), 800, 500); | ||
| 141 | + | ||
| 136 | return GTK_WIDGET(window); | 142 | return GTK_WIDGET(window); |
| 137 | 143 | ||
| 138 | } | 144 | } |
| 139 | 145 | ||
| 146 | + void pw3270_window_set_current_page(GtkWidget *window, gint page_num) { | ||
| 147 | + | ||
| 148 | + g_return_if_fail(PW3270_IS_APPLICATION_WINDOW(window)); | ||
| 149 | + | ||
| 150 | + GtkNotebook * notebook = PW3270_APPLICATION_WINDOW(window)->notebook; | ||
| 151 | + | ||
| 152 | + debug("Selecting tab %d", page_num); | ||
| 153 | + | ||
| 154 | + gtk_notebook_set_current_page(notebook, page_num); | ||
| 155 | + gtk_widget_grab_focus(gtk_notebook_get_nth_page(notebook, page_num)); | ||
| 156 | + | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + void pw3270_window_set_subtitle(GtkWidget *window, const gchar *subtitle) { | ||
| 160 | + | ||
| 161 | + g_return_if_fail(PW3270_IS_APPLICATION_WINDOW(window)); | ||
| 162 | + | ||
| 163 | + GtkWidget * title_bar = gtk_window_get_titlebar(GTK_WINDOW(window)); | ||
| 164 | + | ||
| 165 | + if(title_bar && GTK_IS_HEADER_BAR(title_bar) && gtk_header_bar_get_has_subtitle(GTK_HEADER_BAR(title_bar))) { | ||
| 166 | + gtk_header_bar_set_subtitle(GTK_HEADER_BAR(title_bar), subtitle); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + } |