Exemple #1
0
static void sig_dialog(void)
{
	const char *label = pdf_field_label(ctx, sig_widget->obj);

	ui_dialog_begin(400, (ui.gridsize+4)*3 + ui.lineheight*10);
	{
		ui_layout(T, X, NW, 2, 2);

		ui_label("%s", label);
		ui_spacer();

		if (sig_result)
			ui_label("Signature is valid.\n%s", sig_status);
		else
			ui_label("Could not verify signature:\n%s", sig_status);

		ui_layout(B, X, NW, 2, 2);
		ui_panel_begin(0, ui.gridsize, 0, 0, 0);
		{
			ui_layout(R, NONE, S, 0, 0);
			if (ui_button("Cancel") || (!ui.focus && ui.key == KEY_ESCAPE))
				ui.dialog = NULL;
			ui_spacer();
			if (ui_button("Sign"))
			{
				fz_strlcpy(cert_filename, filename, sizeof cert_filename);
				ui_init_open_file(".", cert_file_filter);
				ui.dialog = cert_file_dialog;
			}
		}
		ui_panel_end();
	}
	ui_dialog_end();
}
Exemple #2
0
static void cert_password_dialog(void)
{
	int is;
	ui_dialog_begin(400, (ui.gridsize+4)*3);
	{
		ui_layout(T, X, NW, 2, 2);
		ui_label("Password:"******"Cancel"))
				ui.dialog = NULL;
			ui_spacer();
			if (ui_button("Okay") || is == UI_INPUT_ACCEPT)
			{
				ui.dialog = NULL;
				do_sign();
			}
		}
		ui_panel_end();
	}
	ui_dialog_end();
}
Exemple #3
0
static void tx_dialog(void)
{
	int ff = pdf_field_flags(ctx, tx_widget->obj);
	const char *label = pdf_field_label(ctx, tx_widget->obj);
	int tx_h = (ff & PDF_TX_FIELD_IS_MULTILINE) ? 10 : 1;
	int lbl_h = ui_break_lines((char*)label, NULL, 20, 394, NULL);
	int is;

	ui_dialog_begin(400, (ui.gridsize+4)*3 + ui.lineheight*(tx_h+lbl_h-2));
	{
		ui_layout(T, X, NW, 2, 2);
		ui_label("%s", label);
		is = ui_input(&tx_input, 200, tx_h);

		ui_layout(B, X, NW, 2, 2);
		ui_panel_begin(0, ui.gridsize, 0, 0, 0);
		{
			ui_layout(R, NONE, S, 0, 0);
			if (ui_button("Cancel") || (!ui.focus && ui.key == KEY_ESCAPE))
				ui.dialog = NULL;
			ui_spacer();
			if (ui_button("Okay") || is == UI_INPUT_ACCEPT)
			{
				pdf_set_text_field_value(ctx, tx_widget, tx_input.text);
				if (pdf_update_page(ctx, tx_widget->page))
					render_page();
				ui.dialog = NULL;
			}
		}
		ui_panel_end();
	}
	ui_dialog_end();
}
Exemple #4
0
static void ch_dialog(void)
{
	const char *label;
	const char *value;
	const char **options;
	int n, choice;
	int label_h;

	label = pdf_field_label(ctx, ch_widget->obj);
	label_h = ui_break_lines((char*)label, NULL, 20, 394, NULL);
	n = pdf_choice_widget_options(ctx, ch_widget->page->doc, ch_widget, 0, NULL);
	options = fz_malloc_array(ctx, n, sizeof(char*));
	pdf_choice_widget_options(ctx, ch_widget->page->doc, ch_widget, 0, options);
	value = pdf_field_value(ctx, ch_widget->obj);

	ui_dialog_begin(400, (ui.gridsize+4)*3 + ui.lineheight*(label_h-1));
	{
		ui_layout(T, X, NW, 2, 2);

		ui_label("%s", label);
		choice = ui_select("Widget/Ch", value, options, n);
		if (choice >= 0)
			pdf_set_choice_field_value(ctx, ch_widget, options[choice]);

		ui_layout(B, X, NW, 2, 2);
		ui_panel_begin(0, ui.gridsize, 0, 0, 0);
		{
			ui_layout(R, NONE, S, 0, 0);
			if (ui_button("Cancel") || (!ui.focus && ui.key == KEY_ESCAPE))
				ui.dialog = NULL;
			ui_spacer();
			if (ui_button("Okay"))
			{
				if (pdf_update_page(ctx, ch_widget->page))
					render_page();
				ui.dialog = NULL;
			}
		}
		ui_panel_end();
	}
	ui_dialog_end();

	fz_free(ctx, options);
}
Exemple #5
0
void ui_set_unobstructed_area(GRect unobstructed_area) {
    bool new_is_obstructed = true;

    if (unobstructed_area.size.w == PWIDTH && unobstructed_area.size.h == PHEIGHT) {
        new_is_obstructed = false;
    }

    if (new_is_obstructed != is_obstructed) {
        is_obstructed = new_is_obstructed;

        ui_layout();
    }
}
Exemple #6
0
void ui_set_sleeping(bool sleeping, int sleep_time, int restful_sleep_time) {
    is_sleeping = sleeping;

    if (sleep_time != -1) { //So is_sleeping can be updated without the sleep time
        float sleep_hours = (float) sleep_time / SECONDS_PER_HOUR;

        snprintf(ui.texts.sleep_time, sizeof(ui.texts.sleep_time), "%d.%d", (int)(sleep_hours), (int)(sleep_hours * 10) % 10);
        ui_set_info(STATUS_ITEMS_SLEEP_TIME, ui.texts.sleep_time);
    }

    if (restful_sleep_time != -1) { //So is_sleeping can be updated without the sleep time
        float restful_sleep_hours = (float) restful_sleep_time / SECONDS_PER_HOUR;

        snprintf(ui.texts.restful_sleep_time, sizeof(ui.texts.restful_sleep_time), "%d.%d", (int)(restful_sleep_hours), (int)(restful_sleep_hours * 10) % 10);
        ui_set_info(STATUS_ITEMS_RESTFUL_SLEEP_TIME, ui.texts.restful_sleep_time);
    }

    ui_layout();
}
Exemple #7
0
void ui_window_load(Window *window) {
    ui.layers.window = window_get_root_layer(window);

    //Dynamically set sizes
    GRect window_bounds = layer_get_bounds(ui.layers.window);
    PWIDTH = window_bounds.size.w;
    HALFPWIDTH = window_bounds.size.w / 2;
    PHEIGHT = window_bounds.size.h;
    HALFPHEIGHT = window_bounds.size.h / 2;
    STATUS_BAR_ITEM_WIDTH = (PWIDTH - (STATUS_BAR_MARGIN * 2)) / 3;

    ui.layers.time = text_layer_init(
        ui.layers.window,
        GRect(0, MARGINTOP, PWIDTH, 100),
        ui.fonts.time_text,
        GColorClear,
        GColorBlack,
        GTextAlignmentCenter
    );

    ui.layers.battery = layer_init(ui.layers.window, GRect(0, MARGINTOP + 29, PWIDTH, 100), ui_battery_dirty);

    ui.layers.date = text_layer_init(
        ui.layers.window,
        GRect(0, MARGINTOP + 60, PWIDTH, 100),
        ui.fonts.info_text,
        GColorClear,
        GColorBlack,
        GTextAlignmentCenter
    );

    ui.layers.month = text_layer_init(
        ui.layers.window,
        GRect(0, MARGINTOP + 96, PWIDTH, 28),
        ui.fonts.month_text,
        GColorClear,
        GColorBlack,
        GTextAlignmentCenter
    );

    ui.layers.info_box_left = text_layer_init(
        ui.layers.window,
        GRect(INFO_MARGIN, MARGINTOP + 118, HALFPWIDTH + 10, 50),
        ui.fonts.info_text,
        GColorClear,
        GColorBlack,
        GTextAlignmentCenter
    );

    ui.layers.info_box_right = text_layer_init(
        ui.layers.window,
        GRect(HALFPWIDTH + 1, MARGINTOP + 119, (HALFPWIDTH - INFO_MARGIN), 50),
        ui.fonts.info_icons,
        GColorClear,
        GColorBlack,
        GTextAlignmentCenter
    );

    //This is a text layer to avoid having a dirty funciton for just coloring it
    ui.layers.status_bar = text_layer_init(
        ui.layers.window,
        GRect(0, 0, PWIDTH, STATUS_BAR_HEIGHT),
        ui.fonts.status_text,
        get_color(config.status_bar_day_color),
        get_color(config.status_bar_day_text_color),
        GTextAlignmentLeft
    );

    ui.layers.status_bar1 = text_layer_init(
        ui.layers.window,
        GRect(STATUS_BAR_MARGIN, STATUS_BAR_MARGINTOP, STATUS_BAR_ITEM_WIDTH, (STATUS_BAR_HEIGHT - STATUS_BAR_MARGINTOP)),
        ui.fonts.status_text,
        GColorClear,
        get_color(config.status_bar_day_text_color),
        GTextAlignmentLeft
    );

    ui.layers.status_bar2 = text_layer_init(
        ui.layers.window,
        GRect(STATUS_BAR_MARGIN + STATUS_BAR_ITEM_WIDTH, STATUS_BAR_MARGINTOP, STATUS_BAR_ITEM_WIDTH, (STATUS_BAR_HEIGHT - STATUS_BAR_MARGINTOP)),
        ui.fonts.status_text,
        GColorClear,
        get_color(config.status_bar_day_text_color),
        GTextAlignmentCenter
    );

    ui.layers.status_bar3 = text_layer_init(
        ui.layers.window,
        GRect(STATUS_BAR_MARGIN + (STATUS_BAR_ITEM_WIDTH * 2), STATUS_BAR_MARGINTOP, STATUS_BAR_ITEM_WIDTH, (STATUS_BAR_HEIGHT - STATUS_BAR_MARGINTOP)),
        ui.fonts.status_text,
        GColorClear,
        get_color(config.status_bar_day_text_color),
        GTextAlignmentRight
    );

    ui_layout();
    ui_colorize();

    //Check if we are obstructed
    ui_set_unobstructed_area(layer_get_unobstructed_bounds(ui.layers.window));
}
Exemple #8
0
int
main(int argc, char **argv)
{
        bool force_ascii = false;
        int delay = 500;

        int opt;
        while ((opt = getopt(argc, argv, "ad:h")) != -1) {
                switch (opt) {
                case 'a':
                        force_ascii = true;
                        break;
                case 'd':
                {
                        char *end;
                        float val = strtof(optarg, &end);
                        if (*end) {
                                fprintf(stderr, "Delay argument (-d) requires "
                                        "a number\n");
                                exit(2);
                        }
                        delay = 1000 * val;
                        break;
                }
                default:
                        fprintf(stderr, "Usage: %s [-a] [-d delay]\n", argv[0]);
                        if (opt == 'h') {
                                fprintf(stderr,
                                        "\n"
                                        "Display CPU usage as a bar chart.\n"
                                        "\n"
                                        "Options:\n"
                                        "  -a       Use ASCII-only bars (instead of Unicode)\n"
                                        "  -d SECS  Specify delay between updates (decimals accepted)\n"
                                        "\n"
                                        "If your bars look funky, use -a or specify LANG=C.\n"
                                        "\n"
                                        "For kernels prior to 2.6.37, using a small delay on a large system can\n"
                                        "induce significant system time overhead.\n");
                                exit(0);
                        }
                        exit(2);
                }
        }
        if (optind < argc) {
                fprintf(stderr, "Unexpected arguments\n");
                exit(2);
        }

        struct sigaction sa = {
                .sa_handler = on_sigint
        };
        sigaction(SIGINT, &sa, NULL);

        cpustats_init();
        term_init();
        ui_init(force_ascii);

        struct cpustats *before = cpustats_alloc(),
                *after = cpustats_alloc(),
                *delta = cpustats_alloc(),
                *prevLayout = cpustats_alloc();

        cpustats_read(before);
        cpustats_subtract(prevLayout, before, before);
        ui_layout(prevLayout);
        fflush(stdout);
        while (!need_exit) {
                // Sleep or take input
                struct pollfd pollfd = {
                        .fd = 0,
                        .events = POLLIN
                };
                if (poll(&pollfd, 1, delay) < 0 && errno != EINTR)
                        epanic("poll failed");
                if (pollfd.revents & POLLIN) {
                        char ch = 0;
                        if (read(0, &ch, 1) < 0)
                                epanic("read failed");
                        if (ch == 'q')
                                break;
                }

                // Get new statistics
                cpustats_read(after);
                cpustats_subtract(delta, after, before);

                // Recompute the layout if necessary
                if (term_check_resize() || !cpustats_sets_equal(delta, prevLayout))
                        ui_layout(delta);

                // Show the load average
                float loadavg[3];
                cpustats_loadavg(loadavg);
                ui_show_load(loadavg);

                if (delta->real) {
                        ui_compute_bars(delta);
                        ui_show_bars();
                }

                // Done updating UI
                fflush(stdout);

                SWAP(before, after);
                SWAP(delta, prevLayout);
        }

        return 0;
}
Exemple #9
0
int ui_save_file(char filename[PATH_MAX], void (*extra_panel)(void))
{
	int i, rv = 0;

	ui_panel_begin(0, 0, 4, 4, 1);
	{
		ui_layout(L, Y, NW, 0, 0);
		ui_panel_begin(150, 0, 0, 0, 0);
		{
			ui_layout(T, X, NW, 2, 2);
			list_drives();
			if (extra_panel)
			{
				ui_spacer();
				extra_panel();
			}
			ui_layout(B, X, NW, 2, 2);
			if (ui_button("Cancel") || (!ui.focus && ui.key == KEY_ESCAPE))
			{
				filename[0] = 0;
				rv = 1;
			}
		}
		ui_panel_end();

		ui_layout(T, X, NW, 2, 2);
		if (ui_input(&fc.input_dir, 0, 1) == UI_INPUT_ACCEPT)
			load_dir(fc.input_dir.text);

		ui_layout(T, X, NW, 2, 2);
		ui_panel_begin(0, ui.gridsize, 0, 0, 0);
		{
			ui_layout(R, NONE, CENTER, 0, 0);
			if (ui_button("Save"))
			{
				fz_snprintf(filename, PATH_MAX, "%s/%s", fc.curdir, fc.input_file.text);
				rv = 1;
			}
			ui_spacer();
			if (ui_button("\xe2\x9e\x95")) /* U+2795 HEAVY PLUS */
				bump_file_version(1);
			if (ui_button("\xe2\x9e\x96")) /* U+2796 HEAVY MINUS */
				bump_file_version(-1);
			ui_spacer();
			ui_layout(ALL, X, CENTER, 0, 0);
			ui_input(&fc.input_file, 0, 1);
		}
		ui_panel_end();

		ui_layout(ALL, BOTH, NW, 2, 2);
		ui_list_begin(&fc.list_dir, fc.count, 0, 0);
		for (i = 0; i < fc.count; ++i)
		{
			const char *name = fc.files[i].name;
			char buf[PATH_MAX];
			if (fc.files[i].is_dir)
				fz_snprintf(buf, sizeof buf, "\xf0\x9f\x93\x81 %s", name);
			else
				fz_snprintf(buf, sizeof buf, "\xf0\x9f\x93\x84 %s", name);
			if (ui_list_item(&fc.list_dir, &fc.files[i], buf, i==fc.selected))
			{
				fc.selected = i;
				if (fc.files[i].is_dir)
				{
					fz_snprintf(buf, sizeof buf, "%s/%s", fc.curdir, name);
					load_dir(buf);
					ui.active = NULL;
				}
				else
				{
					ui_input_init(&fc.input_file, name);
				}
			}
		}
		ui_list_end(&fc.list_dir);
	}
	ui_panel_end();

	return rv;
}
Exemple #10
0
int ui_open_file(char filename[PATH_MAX])
{
	static int last_click_time = 0;
	static int last_click_sel = -1;
	int i, rv = 0;

	ui_panel_begin(0, 0, 4, 4, 1);
	{
		ui_layout(L, Y, NW, 0, 0);
		ui_panel_begin(150, 0, 0, 0, 0);
		{
			ui_layout(T, X, NW, 2, 2);
			list_drives();
			ui_layout(B, X, NW, 2, 2);
			if (ui_button("Cancel") || (!ui.focus && ui.key == KEY_ESCAPE))
			{
				filename[0] = 0;
				rv = 1;
			}
		}
		ui_panel_end();

		ui_layout(T, X, NW, 2, 2);
		ui_panel_begin(0, ui.gridsize, 0, 0, 0);
		{
			if (fc.selected >= 0)
			{
				ui_layout(R, NONE, CENTER, 0, 0);
				if (ui_button("Open") || (!ui.focus && ui.key == KEY_ENTER))
				{
					fz_snprintf(filename, PATH_MAX, "%s/%s", fc.curdir, fc.files[fc.selected].name);
					rv = 1;
				}
				ui_spacer();
			}
			ui_layout(ALL, X, CENTER, 0, 0);
			if (ui_input(&fc.input_dir, 0, 1) == UI_INPUT_ACCEPT)
				load_dir(fc.input_dir.text);
		}
		ui_panel_end();

		ui_layout(ALL, BOTH, NW, 2, 2);
		ui_list_begin(&fc.list_dir, fc.count, 0, 0);
		for (i = 0; i < fc.count; ++i)
		{
			const char *name = fc.files[i].name;
			char buf[PATH_MAX];
			if (fc.files[i].is_dir)
				fz_snprintf(buf, sizeof buf, "%C %s", ICON_FOLDER, name);
			else
				fz_snprintf(buf, sizeof buf, "%C %s", ICON_DOCUMENT, name);
			if (ui_list_item(&fc.list_dir, &fc.files[i], buf, i==fc.selected))
			{
				fc.selected = i;
				if (fc.files[i].is_dir)
				{
					fz_snprintf(buf, sizeof buf, "%s/%s", fc.curdir, name);
					load_dir(buf);
					ui.active = NULL;
					last_click_sel = -1;
				}
				else
				{
					int click_time = glutGet(GLUT_ELAPSED_TIME);
					if (i == last_click_sel && click_time < last_click_time + 250)
					{
						fz_snprintf(filename, PATH_MAX, "%s/%s", fc.curdir, name);
						rv = 1;
					}
					last_click_time = click_time;
					last_click_sel = i;
				}
			}
		}
		ui_list_end(&fc.list_dir);
	}
	ui_panel_end();

	return rv;
}