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 |
|
---|
35 | #include <stdbool.h>
|
---|
36 | #include <errno.h>
|
---|
37 | #include <stdio.h>
|
---|
38 | #include <stdlib.h>
|
---|
39 | #include <str.h>
|
---|
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>
|
---|
47 | #include <canvas.h>
|
---|
48 |
|
---|
49 | #include <draw/surface.h>
|
---|
50 | #include <draw/source.h>
|
---|
51 | #include <draw/drawctx.h>
|
---|
52 | #include <draw/codec.h>
|
---|
53 |
|
---|
54 | #include "images.h"
|
---|
55 |
|
---|
56 | #define NAME "vlaunch"
|
---|
57 |
|
---|
58 | #define LOGO_WIDTH 196
|
---|
59 | #define LOGO_HEIGHT 66
|
---|
60 |
|
---|
61 | static char *display_svc = DISPLAY_DEFAULT;
|
---|
62 |
|
---|
63 | static int app_launch(const char *app)
|
---|
64 | {
|
---|
65 | errno_t rc;
|
---|
66 | task_id_t id;
|
---|
67 | task_wait_t wait;
|
---|
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 |
|
---|
77 | if (rc != EOK) {
|
---|
78 | printf("%s: Error spawning %s %s (%s)\n", NAME, app,
|
---|
79 | display_svc != DISPLAY_DEFAULT ? display_svc :
|
---|
80 | "<default>", str_error(rc));
|
---|
81 | return -1;
|
---|
82 | }
|
---|
83 |
|
---|
84 | task_exit_t texit;
|
---|
85 | int retval;
|
---|
86 | rc = task_wait(&wait, &texit, &retval);
|
---|
87 | if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
|
---|
88 | printf("%s: Error retrieving retval from %s (%s)\n", NAME,
|
---|
89 | app, str_error(rc));
|
---|
90 | return -1;
|
---|
91 | }
|
---|
92 |
|
---|
93 | return retval;
|
---|
94 | }
|
---|
95 |
|
---|
96 | static void on_btn_click(widget_t *widget, void *data)
|
---|
97 | {
|
---|
98 | const char *app = (const char *) widget_get_data(widget);
|
---|
99 | app_launch(app);
|
---|
100 | }
|
---|
101 |
|
---|
102 | static void print_syntax(void)
|
---|
103 | {
|
---|
104 | printf("Syntax: %s [-d <display>]\n", NAME);
|
---|
105 | }
|
---|
106 |
|
---|
107 | int main(int argc, char *argv[])
|
---|
108 | {
|
---|
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 | }
|
---|
127 | }
|
---|
128 |
|
---|
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 | }
|
---|
134 |
|
---|
135 | window_t *main_window = window_open(display_svc, NULL,
|
---|
136 | WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vlaunch");
|
---|
137 | if (!main_window) {
|
---|
138 | printf("Cannot open main window.\n");
|
---|
139 | return 1;
|
---|
140 | }
|
---|
141 |
|
---|
142 | pixel_t grd_bg = PIXEL(255, 255, 255, 255);
|
---|
143 |
|
---|
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);
|
---|
147 |
|
---|
148 | pixel_t lbl_bg = PIXEL(255, 255, 255, 255);
|
---|
149 | pixel_t lbl_text = PIXEL(255, 0, 0, 0);
|
---|
150 |
|
---|
151 | canvas_t *logo_canvas = create_canvas(NULL, NULL, LOGO_WIDTH, LOGO_HEIGHT,
|
---|
152 | logo);
|
---|
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);
|
---|
157 | button_t *btn_vcalc = create_button(NULL, "/app/vcalc", "vcalc",
|
---|
158 | 16, btn_bg, btn_fg, btn_text);
|
---|
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);
|
---|
163 | grid_t *grid = create_grid(window_root(main_window), NULL, 1, 6, grd_bg);
|
---|
164 |
|
---|
165 | if ((!logo_canvas) || (!lbl_caption) || (!btn_vterm) ||
|
---|
166 | (!btn_vcalc) || (!btn_vdemo) || (!btn_vlaunch) || (!grid)) {
|
---|
167 | window_close(main_window);
|
---|
168 | printf("Cannot create widgets.\n");
|
---|
169 | return 1;
|
---|
170 | }
|
---|
171 |
|
---|
172 | sig_connect(&btn_vterm->clicked, &btn_vterm->widget, on_btn_click);
|
---|
173 | sig_connect(&btn_vcalc->clicked, &btn_vcalc->widget, on_btn_click);
|
---|
174 | sig_connect(&btn_vdemo->clicked, &btn_vdemo->widget, on_btn_click);
|
---|
175 | sig_connect(&btn_vlaunch->clicked, &btn_vlaunch->widget, on_btn_click);
|
---|
176 |
|
---|
177 | grid->add(grid, &logo_canvas->widget, 0, 0, 1, 1);
|
---|
178 | grid->add(grid, &lbl_caption->widget, 0, 1, 1, 1);
|
---|
179 | grid->add(grid, &btn_vterm->widget, 0, 2, 1, 1);
|
---|
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);
|
---|
183 |
|
---|
184 | window_resize(main_window, 0, 0, 210, 164 + LOGO_HEIGHT,
|
---|
185 | WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_TOP);
|
---|
186 | window_exec(main_window);
|
---|
187 |
|
---|
188 | task_retval(0);
|
---|
189 | async_manager();
|
---|
190 |
|
---|
191 | return 0;
|
---|
192 | }
|
---|
193 |
|
---|
194 | /** @}
|
---|
195 | */
|
---|