[6d5e378] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Petr Koupy
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup vlaunch
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[3e6a98c5] | 35 | #include <stdbool.h>
|
---|
[6d5e378] | 36 | #include <errno.h>
|
---|
| 37 | #include <stdio.h>
|
---|
[38d150e] | 38 | #include <stdlib.h>
|
---|
[fd11144] | 39 | #include <str.h>
|
---|
[6d5e378] | 40 | #include <task.h>
|
---|
| 41 | #include <str_error.h>
|
---|
| 42 |
|
---|
| 43 | #include <window.h>
|
---|
| 44 | #include <grid.h>
|
---|
| 45 | #include <button.h>
|
---|
| 46 | #include <label.h>
|
---|
[b8f1a349] | 47 | #include <canvas.h>
|
---|
[6d5e378] | 48 |
|
---|
[2bb6d04] | 49 | #include <draw/surface.h>
|
---|
| 50 | #include <draw/source.h>
|
---|
| 51 | #include <draw/drawctx.h>
|
---|
| 52 | #include <draw/codec.h>
|
---|
[b8f1a349] | 53 |
|
---|
| 54 | #include "images.h"
|
---|
| 55 |
|
---|
| 56 | #define NAME "vlaunch"
|
---|
| 57 |
|
---|
[b4f43a1] | 58 | #define LOGO_WIDTH 196
|
---|
| 59 | #define LOGO_HEIGHT 66
|
---|
[6d5e378] | 60 |
|
---|
[fd11144] | 61 | static char *display_svc = DISPLAY_DEFAULT;
|
---|
[6d5e378] | 62 |
|
---|
| 63 | static int app_launch(const char *app)
|
---|
| 64 | {
|
---|
[fd11144] | 65 | errno_t rc;
|
---|
[6d5e378] | 66 | task_id_t id;
|
---|
[1c635d6] | 67 | task_wait_t wait;
|
---|
[fd11144] | 68 |
|
---|
| 69 | if (display_svc != DISPLAY_DEFAULT) {
|
---|
| 70 | printf("%s: Spawning %s -d %s\n", NAME, app, display_svc);
|
---|
| 71 | rc = task_spawnl(&id, &wait, app, app, "-d", display_svc, NULL);
|
---|
| 72 | } else {
|
---|
| 73 | printf("%s: Spawning %s\n", NAME, app);
|
---|
| 74 | rc = task_spawnl(&id, &wait, app, app, NULL);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[6d5e378] | 77 | if (rc != EOK) {
|
---|
| 78 | printf("%s: Error spawning %s %s (%s)\n", NAME, app,
|
---|
[fd11144] | 79 | display_svc != DISPLAY_DEFAULT ? display_svc :
|
---|
| 80 | "<default>", str_error(rc));
|
---|
[6d5e378] | 81 | return -1;
|
---|
| 82 | }
|
---|
[a35b458] | 83 |
|
---|
[b5674b2] | 84 | task_exit_t texit;
|
---|
| 85 | int retval;
|
---|
[1c635d6] | 86 | rc = task_wait(&wait, &texit, &retval);
|
---|
[b5674b2] | 87 | if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
|
---|
[6d5e378] | 88 | printf("%s: Error retrieving retval from %s (%s)\n", NAME,
|
---|
| 89 | app, str_error(rc));
|
---|
| 90 | return -1;
|
---|
| 91 | }
|
---|
[a35b458] | 92 |
|
---|
[6d5e378] | 93 | return retval;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[10cb47e] | 96 | static void on_btn_click(widget_t *widget, void *data)
|
---|
[6d5e378] | 97 | {
|
---|
[10cb47e] | 98 | const char *app = (const char *) widget_get_data(widget);
|
---|
| 99 | app_launch(app);
|
---|
[6d5e378] | 100 | }
|
---|
| 101 |
|
---|
[fd11144] | 102 | static void print_syntax(void)
|
---|
| 103 | {
|
---|
| 104 | printf("Syntax: %s [-d <display>]\n", NAME);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[6d5e378] | 107 | int main(int argc, char *argv[])
|
---|
| 108 | {
|
---|
[fd11144] | 109 | int i;
|
---|
| 110 |
|
---|
| 111 | i = 1;
|
---|
| 112 | while (i < argc) {
|
---|
| 113 | if (str_cmp(argv[i], "-d") == 0) {
|
---|
| 114 | ++i;
|
---|
| 115 | if (i >= argc) {
|
---|
| 116 | printf("Argument missing.\n");
|
---|
| 117 | print_syntax();
|
---|
| 118 | return 1;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | display_svc = argv[i++];
|
---|
| 122 | } else {
|
---|
| 123 | printf("Invalid option '%s'.\n", argv[i]);
|
---|
| 124 | print_syntax();
|
---|
| 125 | return 1;
|
---|
| 126 | }
|
---|
[6d5e378] | 127 | }
|
---|
[a35b458] | 128 |
|
---|
[b8f1a349] | 129 | surface_t *logo = decode_tga((void *) helenos_tga, helenos_tga_size, 0);
|
---|
| 130 | if (!logo) {
|
---|
| 131 | printf("Unable to decode logo.\n");
|
---|
| 132 | return 1;
|
---|
| 133 | }
|
---|
[a35b458] | 134 |
|
---|
[fd11144] | 135 | window_t *main_window = window_open(display_svc, NULL,
|
---|
[2c7fdaa] | 136 | WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vlaunch");
|
---|
[bdf3c0c] | 137 | if (!main_window) {
|
---|
| 138 | printf("Cannot open main window.\n");
|
---|
| 139 | return 1;
|
---|
| 140 | }
|
---|
[a35b458] | 141 |
|
---|
[9e7898e] | 142 | pixel_t grd_bg = PIXEL(255, 255, 255, 255);
|
---|
[a35b458] | 143 |
|
---|
[296e124e] | 144 | pixel_t btn_bg = PIXEL(255, 255, 255, 255);
|
---|
| 145 | pixel_t btn_fg = PIXEL(255, 186, 186, 186);
|
---|
| 146 | pixel_t btn_text = PIXEL(255, 0, 0, 0);
|
---|
[a35b458] | 147 |
|
---|
[9e7898e] | 148 | pixel_t lbl_bg = PIXEL(255, 255, 255, 255);
|
---|
[296e124e] | 149 | pixel_t lbl_text = PIXEL(255, 0, 0, 0);
|
---|
[a35b458] | 150 |
|
---|
[10cb47e] | 151 | canvas_t *logo_canvas = create_canvas(NULL, NULL, LOGO_WIDTH, LOGO_HEIGHT,
|
---|
[b8f1a349] | 152 | logo);
|
---|
[10cb47e] | 153 | label_t *lbl_caption = create_label(NULL, NULL, "Launch application:",
|
---|
| 154 | 16, lbl_bg, lbl_text);
|
---|
| 155 | button_t *btn_vterm = create_button(NULL, "/app/vterm", "vterm",
|
---|
| 156 | 16, btn_bg, btn_fg, btn_text);
|
---|
[bdfdc51c] | 157 | button_t *btn_vcalc = create_button(NULL, "/app/vcalc", "vcalc",
|
---|
| 158 | 16, btn_bg, btn_fg, btn_text);
|
---|
[10cb47e] | 159 | button_t *btn_vdemo = create_button(NULL, "/app/vdemo", "vdemo",
|
---|
| 160 | 16, btn_bg, btn_fg, btn_text);
|
---|
| 161 | button_t *btn_vlaunch = create_button(NULL, "/app/vlaunch", "vlaunch",
|
---|
| 162 | 16, btn_bg, btn_fg, btn_text);
|
---|
[bdfdc51c] | 163 | grid_t *grid = create_grid(window_root(main_window), NULL, 1, 6, grd_bg);
|
---|
[a35b458] | 164 |
|
---|
[b8f1a349] | 165 | if ((!logo_canvas) || (!lbl_caption) || (!btn_vterm) ||
|
---|
[bdfdc51c] | 166 | (!btn_vcalc) || (!btn_vdemo) || (!btn_vlaunch) || (!grid)) {
|
---|
[bdf3c0c] | 167 | window_close(main_window);
|
---|
| 168 | printf("Cannot create widgets.\n");
|
---|
| 169 | return 1;
|
---|
| 170 | }
|
---|
[a35b458] | 171 |
|
---|
[10cb47e] | 172 | sig_connect(&btn_vterm->clicked, &btn_vterm->widget, on_btn_click);
|
---|
[bdfdc51c] | 173 | sig_connect(&btn_vcalc->clicked, &btn_vcalc->widget, on_btn_click);
|
---|
[10cb47e] | 174 | sig_connect(&btn_vdemo->clicked, &btn_vdemo->widget, on_btn_click);
|
---|
| 175 | sig_connect(&btn_vlaunch->clicked, &btn_vlaunch->widget, on_btn_click);
|
---|
[a35b458] | 176 |
|
---|
[b8f1a349] | 177 | grid->add(grid, &logo_canvas->widget, 0, 0, 1, 1);
|
---|
[395ca2e] | 178 | grid->add(grid, &lbl_caption->widget, 0, 1, 1, 1);
|
---|
| 179 | grid->add(grid, &btn_vterm->widget, 0, 2, 1, 1);
|
---|
[bdfdc51c] | 180 | grid->add(grid, &btn_vcalc->widget, 0, 3, 1, 1);
|
---|
| 181 | grid->add(grid, &btn_vdemo->widget, 0, 4, 1, 1);
|
---|
| 182 | grid->add(grid, &btn_vlaunch->widget, 0, 5, 1, 1);
|
---|
[a35b458] | 183 |
|
---|
[bdfdc51c] | 184 | window_resize(main_window, 0, 0, 210, 164 + LOGO_HEIGHT,
|
---|
[62fbb7e] | 185 | WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_TOP);
|
---|
[bdf3c0c] | 186 | window_exec(main_window);
|
---|
[a35b458] | 187 |
|
---|
[bdf3c0c] | 188 | task_retval(0);
|
---|
| 189 | async_manager();
|
---|
[a35b458] | 190 |
|
---|
[bdf3c0c] | 191 | return 0;
|
---|
[6d5e378] | 192 | }
|
---|
| 193 |
|
---|
| 194 | /** @}
|
---|
| 195 | */
|
---|