diff options
-rw-r--r-- | data/icons/hicolor/scalable/apps/com.jadupc.support.svg | 148 | ||||
-rw-r--r-- | data/icons/hicolor/symbolic/apps/com.jadupc.support-symbolic.svg | 1 | ||||
-rw-r--r-- | data/ui/window.ui | 2 | ||||
-rw-r--r-- | meson.build | 55 | ||||
-rw-r--r-- | meson_options.txt | 1 | ||||
-rw-r--r-- | src/application.vala | 78 | ||||
-rw-r--r-- | src/config.vala | 23 | ||||
-rw-r--r-- | src/config.vapi | 9 | ||||
-rw-r--r-- | src/main.vala | 29 | ||||
-rw-r--r-- | src/meson.build | 26 | ||||
-rw-r--r-- | src/utils.vala | 46 | ||||
-rw-r--r-- | src/window.vala | 96 |
12 files changed, 513 insertions, 1 deletions
diff --git a/data/icons/hicolor/scalable/apps/com.jadupc.support.svg b/data/icons/hicolor/scalable/apps/com.jadupc.support.svg new file mode 100644 index 0000000..34f2bc6 --- /dev/null +++ b/data/icons/hicolor/scalable/apps/com.jadupc.support.svg @@ -0,0 +1,148 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + width="64" + height="64" + version="1" + id="svg8" + xml:space="preserve" + sodipodi:docname="plain.svg" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview + id="namedview1" + pagecolor="#ffffff" + bordercolor="#000000" + borderopacity="0.25" + inkscape:showpageshadow="2" + inkscape:pageopacity="0.0" + inkscape:pagecheckerboard="0" + inkscape:deskcolor="#d1d1d1" /><defs + id="defs8" /><g + id="g1"><g + id="bot" + transform="matrix(0.75,0,0,0.76190476,8,18.404762)"><path + style="opacity:0.2" + d="M 20,57 16,53 H 8 C 5.784,53 4,51.216 4,49 V 13 C 4,10.784 5.784,9 8,9 h 48 c 2.216,0 4,1.784 4,4 v 36 c 0,2.216 -1.784,4 -4,4 h -8 l -4,4 z" + id="mathar-chaya" /><path + style="fill:#afafb1" + d="M 20,56 16,52 H 8 C 5.784,52 4,50.216 4,48 V 12 C 4,9.784 5.784,8 8,8 h 48 c 2.216,0 4,1.784 4,4 v 36 c 0,2.216 -1.784,4 -4,4 h -8 l -4,4 z" + id="matha" /><path + id="chehara" + style="opacity:0.68" + d="m 12,16 v 28 h 8 l 4,4 h 16 l 4,-4 h 8 V 16 Z" /><g + style="fill:#f8c44e" + transform="scale(1,-1)" + id="kopal"><path + id="rect3" + d="m 18,-16.00061 v -3.999024 h 4 v 3.999024 z m 6,0 v -3.999024 h 4 v 3.999024 z m 6,0 v -3.999024 h 4 v 3.999024 z m 6,0 v -3.999024 h 4 v 3.999024 z m 6,0 v -3.999024 h 4 v 3.999024 z" /></g><path + style="opacity:0.2;fill:#ffffff" + d="M 8,8 C 5.784,8 4,9.784 4,12 v 1 C 4,10.784 5.784,9 8,9 h 48 c 2.216,0 4,1.784 4,4 V 12 C 60,9.784 58.216,8 56,8 Z" + id="chandi-part-1" /><path + style="opacity:0.2;fill:#ffffff" + d="m 12,44 v 1 h 8 l 4,4 h 16 l 4,-4 h 8 v -1 h -8 l -4,4 H 24 l -4,-4 z" + id="thutni-part-1" /><g + id="face" + transform="matrix(0.57828939,0,0,0.58746859,11.832619,17.745473)"><g + id="dan-chokh" + transform="matrix(0,-0.96899414,1.031998,0,-6.5508203,34.997582)"><rect + style="opacity:0.2" + width="16.763" + height="5.5879998" + x="-17.209999" + y="30.209999" + rx="1.397" + ry="1.397" + transform="matrix(0.72400601,-0.68979366,0.72400601,0.68979366,0,0)" + id="rect5-3-3" /><rect + style="fill:#a2a2a2" + width="16.763" + height="5.5879998" + x="-16.49" + y="29.48" + rx="1.397" + ry="1.397" + transform="matrix(0.72400601,-0.68979366,0.72400601,0.68979366,0,0)" + id="rect6-6-6" /><rect + style="opacity:0.2" + width="16.763" + height="5.5879998" + x="19.030001" + y="-6.04" + rx="1.397" + ry="1.397" + transform="matrix(0.72400601,0.68979366,0.72400601,-0.68979366,0,0)" + id="rect7-0-0" /><rect + style="fill:#ffffff" + width="16.763" + height="5.5879998" + x="18.309999" + y="-5.3099999" + rx="1.397" + ry="1.397" + transform="matrix(0.72400601,0.68979366,0.72400601,-0.68979366,0,0)" + id="rect8-6" /></g><g + id="ThOt" + transform="matrix(1.0000082,0,0,1,0.3739191,5.6480429)"><rect + style="opacity:0.2" + width="17" + height="6" + x="26" + y="30" + rx="1.4170001" + ry="1.5" + id="rect3-0-7" /><rect + style="fill:#ffffff" + width="17" + height="6" + x="26" + y="29" + rx="1.4170001" + ry="1.5" + id="rect4-9-0" /></g><g + id="bam-chokh" + transform="matrix(0,-0.96901681,1.0320416,0,28.032871,34.997979)"><rect + style="opacity:0.2" + width="16.763" + height="5.5879998" + x="-17.209999" + y="30.209999" + rx="1.397" + ry="1.397" + transform="matrix(0.72400601,-0.68979366,0.72400601,0.68979366,0,0)" + id="rect5-3-3-6" /><rect + style="fill:#a2a2a2" + width="16.763" + height="5.5879998" + x="-16.49" + y="29.48" + rx="1.397" + ry="1.397" + transform="matrix(0.72400601,-0.68979366,0.72400601,0.68979366,0,0)" + id="rect6-6-6-1" /><rect + style="opacity:0.2" + width="16.763" + height="5.5879998" + x="19.030001" + y="-6.04" + rx="1.397" + ry="1.397" + transform="matrix(0.72400601,0.68979366,0.72400601,-0.68979366,0,0)" + id="rect7-0-0-8" /><rect + style="fill:#ffffff" + width="16.763" + height="5.5879998" + x="18.309999" + y="-5.3099999" + rx="1.397" + ry="1.397" + transform="matrix(0.72400601,0.68979366,0.72400601,-0.68979366,0,0)" + id="rect8-6-7" /></g></g></g><g + id="headphone" + transform="matrix(1.1071429,0,0,0.95081346,-3.4285626,1.5987534)"><path + style="fill:#4f4f4f" + d="m 32,2.0004 c -15.464,0 -28,12.536 -28,28 v 18 c 0,7.1392 5.0838,9.082 8,9.6132 v -27.614 c 0,-11.08 8.92,-20 20,-20 11.08,0 20,8.92 20,20 v 27.624 c 2.916,-0.536 8,-2.484 8,-9.624 v -18 c 0,-15.464 -12.536,-28 -28,-28 z" + id="headset" /><path + style="display:inline;opacity:0.1;fill:#ffffff" + d="M 32,2 C 16.536,2 4,14.536 4,30 v 1 C 4,15.536 16.536,3 32,3 47.464,3 60,15.536 60,31 V 30 C 60,14.536 47.464,2 32,2 Z" + id="headsetshadow" /></g></g></svg> diff --git a/data/icons/hicolor/symbolic/apps/com.jadupc.support-symbolic.svg b/data/icons/hicolor/symbolic/apps/com.jadupc.support-symbolic.svg new file mode 100644 index 0000000..0444828 --- /dev/null +++ b/data/icons/hicolor/symbolic/apps/com.jadupc.support-symbolic.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><g color="#000" fill="#2e3436"><path d="M7.188 2.281c-.094.056-.192.125-.29.19L5.566 3.803a1.684 1.684 0 11-2.17 2.17L2.332 7.037c.506-.069 1.017-.136 1.2.026.242.214.139 1.031.155 1.656.213.088.427.171.657.219.04.008.085-.007.125 0 .337-.525.683-1.288 1-1.344.322-.057.905.562 1.406.937a3.67 3.67 0 00.656-.468c-.195-.595-.594-1.369-.437-1.657.158-.29 1.019-.37 1.625-.531.028-.183.062-.371.062-.562 0-.075-.027-.146-.031-.22-.587-.217-1.435-.385-1.562-.687-.128-.302.34-1.021.593-1.593a3.722 3.722 0 00-.593-.532zm3.875 3.25c-.165.475-.305 1.086-.47 1.563-.43.047-.84.14-1.218.312-.38-.322-.787-.773-1.156-1.093a5.562 5.562 0 00-.688.468c.177.46.453 1.001.625 1.469-.298.309-.531.67-.719 1.063-.494 0-1.102-.084-1.593-.094a5.68 5.68 0 00-.219.812c.435.24 1.006.468 1.438.72-.006.093-.032.185-.032.28 0 .333.049.66.125.97-.382.304-.898.63-1.28.937.015.044.04.083.058.127l.613.613c.417-.1.868-.223 1.266-.303.248.343.532.626.875.875-.027.135-.068.283-.104.428.174-.063.34-.155.482-.297l1.432-1.432a1.994 1.994 0 01.533-3.918c.919 0 1.684.623 1.918 1.467l1.338-1.338c.06-.06.11-.124.156-.191-.035-.062-.06-.13-.1-.188.096-.152.205-.31.315-.47.017-.348-.1-.7-.37-.971l-.177-.176c-.28.192-.561.387-.83.555-.345-.233-.746-.383-1.156-.5-.077-.507-.107-1.132-.187-1.625a5.44 5.44 0 00-.875-.063zm-9.247.608c-.087.068-.173.138-.254.205l.014.035z" style="marker:none" overflow="visible"/><path d="M8.707.293a1 1 0 00-1.415 0l-6.999 7a1 1 0 000 1.413l7 7.001a1 1 0 001.415 0l7-7a1 1 0 000-1.413zm-.708 2.121l5.587 5.587L8 13.586 2.414 7.999z" style="line-height:normal;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000;text-transform:none;text-orientation:mixed;shape-padding:0;isolation:auto;mix-blend-mode:normal;marker:none" font-weight="400" font-family="sans-serif" overflow="visible"/></g></svg>
\ No newline at end of file diff --git a/data/ui/window.ui b/data/ui/window.ui index 2a67dbc..3ce7cc3 100644 --- a/data/ui/window.ui +++ b/data/ui/window.ui @@ -177,7 +177,7 @@ </packing> </child> <child> - <object class="GtkSpinner" id="spinner"> + <object class="GtkSpinner"> <property name="visible">True</property> <property name="can-focus">False</property> <property name="active">True</property> diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..faa901e --- /dev/null +++ b/meson.build @@ -0,0 +1,55 @@ +project('support', + ['c', 'vala'], + version: '0.1.0', + meson_version: '>= 0.52.0', + license: 'GPL-3.0-or-later', + default_options: [ + 'warning_level=2', + 'werror=false', + ], +) + +description = '''JaduPc Remote Support Console''' +desktop_name = 'JaduPc Remote Support Console' + + +if get_option('debug') + add_project_arguments('-DG_LOG_USE_STRUCTURED=1', language : 'c') + add_project_arguments('--debug', language : 'vala') +endif + +maintainer_rname = 'com.jadupc' +project_name = meson.project_name () +application_id = '@0@.@1@'.format (maintainer_rname, project_name) +application_path = '/'.join([''] + application_id.split('.')) +application_name = '@0@-@1@'.format(maintainer_rname.split('.').get(-1), project_name) + +i18n = import('i18n') +gnome = import('gnome') + +valac = meson.get_compiler ('vala') +conf = configuration_data () + +srcs = [] +i18n_data = [] + +conf.set_quoted ('GETTEXT_PACKAGE', application_name) +conf.set_quoted ('DATADIR', get_option ('prefix') / get_option ('datadir')) +conf.set_quoted ('LOCALEDIR', get_option ('prefix') / get_option ('localedir')) +conf.set_quoted ('APPLICATION_ID', application_id) +conf.set_quoted ('VERSION', meson.project_version ()) +conf.set_quoted ('SECURE_PATH', get_option('secure-path')) + +config_h = declare_dependency ( + sources: configure_file ( + output: 'config.h', + configuration: conf + ) +) + +config_h_dir = include_directories ('.') +config_dep = valac.find_library ('config', dirs: meson.current_source_dir() / 'src') + +subdir('data') +subdir('src') +subdir('po') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..8d0af00 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +option('secure-path', type : 'string', value : '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', description : 'Secure $PATH') diff --git a/src/application.vala b/src/application.vala new file mode 100644 index 0000000..b4f543c --- /dev/null +++ b/src/application.vala @@ -0,0 +1,78 @@ +/* application.vala + + * + * Copyright 2023 Mubashshir + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +namespace JadupcSupport +{ + public class Application : Gtk.Application + { + public Application () + { + Object (application_id: "com.jadupc.support", flags: ApplicationFlags.FLAGS_NONE); + } + + construct { + {var _ = Vte.get_major_version();} // This is useless, but removing this breaks linking with vte + ActionEntry[] action_entries = { + { "about", this.on_about_action }, + { "preferences", this.on_preferences_action }, + { "quit", this.quit } + }; + this.add_action_entries (action_entries, this); + } + + public override void activate () + { + base.activate (); + var win = this.active_window; + if (win == null) { + // Fix vte issues + win = new JadupcSupport.Window (this); + + this.set_accels_for_action ("app.quit", {"<primary>q"}); + this.set_accels_for_action ("app.about", {"<primary>question"}); + this.set_accels_for_action ("app.preferences", {"<primary>p"}); + var settings = Gtk.Settings.get_default(); + if (settings != null) + settings.gtk_dialogs_use_header = true; + } + win.present (); + } + + private void on_about_action () + { + var info = new Config.Info(); + Gtk.show_about_dialog (this.active_window, + program_name: _("JaduPc Remote Support Console"), + copyright: string.joinv("\n", info.copyright), + license_type: Gtk.License.GPL_2_0, + logo_icon_name: "com.jadupc.support", + authors: info.authors, + artists: info.artists, + website: "https://jadupc.com", + website_label: _("JaduPc Ltd."), + version: Config.VERSION); + } + + private void on_preferences_action () + { + message ("app.preferences action activated"); + } + } +} diff --git a/src/config.vala b/src/config.vala new file mode 100644 index 0000000..4a2de87 --- /dev/null +++ b/src/config.vala @@ -0,0 +1,23 @@ +namespace Config +{ + [SingleInstance] + public class Info: Object + { + public string[] authors {get; construct;} + public string[] copyright {get; construct;} + public string[] artists {get; construct;} + construct { + authors = { + _("Mubashshir <ahm@jadupc.com>"), + _("Saikat <fas@jadupc.com>"), + }; + copyright = { + _("Copyright © 2023 Mubashshir"), + _("Copyright © 2023 Saikat"), + }; + artists = { + _("Maliha <maliha.0250@gmail.com>"), + }; + } + } +} diff --git a/src/config.vapi b/src/config.vapi new file mode 100644 index 0000000..175cfb3 --- /dev/null +++ b/src/config.vapi @@ -0,0 +1,9 @@ +[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")] +namespace Config { + public const string GETTEXT_PACKAGE; + public const string DATADIR; + public const string LOCALEDIR; + public const string APPLICATION_ID; + public const string VERSION; + public const string SECURE_PATH; +} diff --git a/src/main.vala b/src/main.vala new file mode 100644 index 0000000..0467354 --- /dev/null +++ b/src/main.vala @@ -0,0 +1,29 @@ +/* main.vala + + * + * Copyright 2023 Mubashshir + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +public static int main(string[] args) +{ + Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR); + Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8"); + Intl.textdomain (Config.GETTEXT_PACKAGE); + + var app = new JadupcSupport.Application (); + return app.run (args); +} diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..f002b7b --- /dev/null +++ b/src/meson.build @@ -0,0 +1,26 @@ +sources = [ + 'main.vala', + 'window.vala', + 'application.vala', + 'utils.vala', + 'config.vala', +] + +foreach file : sources + srcs += files(file) +endforeach + +deps = [ + dependency('gtk+-3.0'), + dependency('vte-2.91'), + meson.get_compiler('vala').find_library('posix'), + config_h, + config_dep +] + +executable(application_name, srcs + resources, + include_directories: config_h_dir, + vala_args: '--target-glib=2.50', dependencies: deps, + install: true, + c_args: ['-include', 'config.h'], +) diff --git a/src/utils.vala b/src/utils.vala new file mode 100644 index 0000000..04837df --- /dev/null +++ b/src/utils.vala @@ -0,0 +1,46 @@ +namespace JadupcSupport +{ + namespace utils + { + internal string get_message_icon(Gtk.MessageType type) + { + switch (type) { + case ERROR: + return "dialog-error"; + case INFO: + return "dialog-information"; + case QUESTION: + return "dialog-question"; + case WARNING: + return "dialog-warning"; + default: + return "image-missing"; + } + } + +// This function takes a visible Gtk Widget and recursively realizes +// the childrens as Gtk whines on key event if even one +// ((great)grand)children widget is not realized... + internal void realize_all(Gtk.Container container) + { + if (!container.get_realized()) + container.realize(); + + container.foreach((widget) => { + if (widget is Gtk.Container) realize_all(widget as Gtk.Container); + else if (!widget.get_realized()) widget.realize(); + }); + } + + internal string strret(int ret, string[] retstrs = {}) + { + if (0 < ret <= 64 && !(ret == 11 || ret == 28 || 3 <= ret <= 8)) + return "%s".printf(strsignal(ret) ?? _("Unknown Signal - %d").printf(ret)); + else if (128 < ret < 256) + return "%s".printf(strsignal(ret - 128) ?? _("Unknown Signal - %d").printf(ret)); + else if (ret % 256 == 0) + return _("Process returned %d").printf(ret / 256); + return _("Exit status - %d (unknown)").printf(ret); + } + } +} diff --git a/src/window.vala b/src/window.vala new file mode 100644 index 0000000..bea5408 --- /dev/null +++ b/src/window.vala @@ -0,0 +1,96 @@ +/* window.vala + + * + * Copyright 2023 Mubashshir + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +namespace JadupcSupport +{ + + [GtkTemplate (ui = "/com/jadupc/support/ui/window.ui")] + public class Window : Gtk.ApplicationWindow + { + [GtkChild] private unowned Gtk.Label session; + [GtkChild] private unowned Gtk.InfoBar infobar; + [GtkChild] private unowned Gtk.Stack view; + [GtkChild] private unowned Vte.Terminal terminal; + [GtkChild] private unowned Gtk.Button sessionbutton; + [GtkChild] private unowned Gtk.Label infobarText; + [GtkChild] private unowned Gtk.Image infobarIcon; + + public Window (Gtk.Application app) + { + var lang = Environment.get_variable("LANG"); // fix locale for Vte.Terminal + Environment.set_variable("LANG", "en_US", true); // fix locale for Vte.Terminal + Object (application: app); + Environment.set_variable("LANG", lang, true); // fix locale for Vte.Terminal + + utils.realize_all(this); // Realize all children to pacify Gtk. + icon_name = "com.jadupc.support"; + + infobar.response.connect(() => infobar.set_revealed(false)); + sessionbutton.clicked.connect(() => { + if (infobar.revealed) + infobar.revealed = false; + session.label = _("Connecting..."); + view.visible_child_name = "inprogress"; + Timeout.add_once(3000, () => on_session_connect("test@tty.jadupc.com")); + }); + + terminal.child_exited.connect(status => { + if(status > 0) + show_in_infobar(ERROR, _("Error: %s").printf(utils.strret(status))); + reset_window(); + }); + + show_in_infobar(INFO, _("Welcome to JaduPc Remote Support Console!")); + } + + internal void show_in_infobar(Gtk.MessageType type, string message) + { + infobarIcon.icon_name = utils.get_message_icon(type); + + infobarText.label = message; + infobar.message_type = type; + infobar.revealed = true; + } + + private void reset_window() + { + session.label = _("Disconnected..."); + Timeout.add_once(view.transition_duration, () => terminal.reset(true, true)); + view.visible_child_name = "session"; + } + + private void spawn_async_cb(Vte.Terminal term, Pid pid, Error? error) + { + if(pid > 1) return; + reset_window(); + show_in_infobar(ERROR, error.message); + } + + private void on_session_connect(string url) + { + session.label = @"<a href=\"ssh://$url\">ssh://$url</a>"; + view.visible_child_name = "terminal"; + terminal.has_focus = true; + + terminal.spawn_async(Vte.PtyFlags.DEFAULT, "~", {"sh"}, {@"PATH=$(Config.SECURE_PATH)"}, + SpawnFlags.SEARCH_PATH_FROM_ENVP, null, -1, null, spawn_async_cb); + } + } +} |