/**
 * Set up the Newt graphical environment. If @p g_text_mode is TRUE, then
 * only allocate some memory.
 */
	void
	 setup_newt_stuff() {

		/*@ int *********************************************************** */
		int i = 0;
		int cols;

		if (!g_text_mode) {
			newtInit();
			newtCls();
			newtPushHelpLine
				(_("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed."));
			/*  newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */
			newtDrawRootText(18, 0, WELCOME_STRING);
			newtRefresh();
			newtGetScreenSize(&cols, &g_noof_rows);
			g_noof_log_lines = (g_noof_rows / 5) + 1;
		}

		err_log_lines =
			(char **) malloc(sizeof(char *) * g_noof_log_lines);
		if (!err_log_lines) {
			fatal_error("Out of memory");
		}

		for (i = 0; i < g_noof_log_lines; i++) {
			err_log_lines[i] = NULL;
		}
	}
예제 #2
0
struct ui_progress *ui_progress__new(const char *title, u64 total)
{
	struct ui_progress *self = malloc(sizeof(*self));

	if (self != NULL) {
		int cols;

		if (use_browser <= 0)
			return self;
		newtGetScreenSize(&cols, NULL);
		cols -= 4;
		newtCenteredWindow(cols, 1, title);
		self->form  = newtForm(NULL, NULL, 0);
		if (self->form == NULL)
			goto out_free_self;
		self->scale = newtScale(0, 0, cols, total);
		if (self->scale == NULL)
			goto out_free_form;
		newtFormAddComponent(self->form, self->scale);
		newtRefresh();
	}

	return self;

out_free_form:
	newtFormDestroy(self->form);
out_free_self:
	free(self);
	return NULL;
}
예제 #3
0
static NmtNewtForm *
nmt_edit_main_connection_list (gboolean is_top)
{
	int screen_width, screen_height;
	NmtNewtForm *form;
	NmtNewtWidget *quit, *list;

	newtGetScreenSize (&screen_width, &screen_height);

	form = g_object_new (NMT_TYPE_NEWT_FORM,
	                     "y", 2,
	                     "height", screen_height - 4,
	                     "escape-exits", TRUE,
	                     NULL);

	quit = nmt_newt_button_new (is_top ? _("Quit") : _("Back"));
	nmt_newt_widget_set_exit_on_activate (quit, TRUE);

	list = g_object_new (NMT_TYPE_EDIT_CONNECTION_LIST,
	                     "extra-widget", quit,
	                     "connection-filter", edit_connection_list_filter,
	                     NULL);

	g_signal_connect (list, "add-connection",
	                  G_CALLBACK (list_add_connection), form);
	g_signal_connect (list, "edit-connection",
	                  G_CALLBACK (list_edit_connection), form);
	g_signal_connect (list, "remove-connection",
	                  G_CALLBACK (list_remove_connection), form);

	nmt_newt_form_set_content (form, list);
	return form;
}
예제 #4
0
파일: ruby_newt.c 프로젝트: lzap/ruby-newt
static VALUE rb_ext_Screen_Size(VALUE self)
{
  int cols, rows;
  VALUE ary = rb_ary_new2(2);

  newtGetScreenSize(&cols, &rows);
  rb_ary_push(ary, INT2NUM(cols));
  rb_ary_push(ary, INT2NUM(rows));

  return ary;
}
예제 #5
0
void ui_browser__refresh_dimensions(struct ui_browser *self)
{
	int cols, rows;
	newtGetScreenSize(&cols, &rows);

	if (self->width > cols - 4)
		self->width = cols - 4;
	self->height = rows - 5;
	if (self->height > self->nr_entries)
		self->height = self->nr_entries;
	self->y  = (rows - self->height) / 2;
	self->x = (cols - self->width) / 2;
}
예제 #6
0
// =======================================================
CInterfaceNewt::CInterfaceNewt(bool bBatchMode): CInterface(bBatchMode)
{
  int cols, rows;
	
  m_bPushDone = false;
  //m_bBatchMode = bBatchMode; // in CInterface
  SLang_init_tty('*', 0, 0); // '*' to send SIGTERM
  //myNewtInit(32);
  newtInit();
  //SLang_Abort_Char = 27;
  newtCls();
  newtGetScreenSize(&cols, &rows);
  newtDrawRootText((int)((cols-14)/2), (int)(rows/2), i18n("Please wait..."));
  newtPushHelpLine("");
  newtRefresh();

}
예제 #7
0
void init_frontend_newt(const char * welcome_msg)
{
	int i;
	for (i=0; i<38; i++) printf("\n");
	newtInit();
	newtCls();

	if (welcome_msg[0]) {
		char *msg;
		int cols, rows;
		newtGetScreenSize(&cols, &rows);
		asprintf(&msg, " %-*s", cols - 1, welcome_msg);
		newtDrawRootText(0, 0, msg);
		free(msg);
		newtPushHelpLine(" <Alt-F1> for here, <Alt-F11> to see the logs, <Alt-F12> for kernel msg");
	}
	newtRefresh();
}
예제 #8
0
static NmtNewtForm *
nmt_connect_connection_list (void)
{
	int screen_width, screen_height;
	NmtNewtForm *form;
	NmtNewtWidget *list, *activate, *quit, *bbox, *grid;

	newtGetScreenSize (&screen_width, &screen_height);

	form = g_object_new (NMT_TYPE_NEWT_FORM,
	                     "y", 2,
	                     "height", screen_height - 4,
	                     "escape-exits", TRUE,
	                     NULL);

	grid = nmt_newt_grid_new ();

	list = nmt_connect_connection_list_new ();
	nmt_newt_grid_add (NMT_NEWT_GRID (grid), list, 0, 0);
	nmt_newt_grid_set_flags (NMT_NEWT_GRID (grid), list,
	                         NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y |
	                         NMT_NEWT_GRID_EXPAND_X | NMT_NEWT_GRID_EXPAND_Y);
	g_signal_connect (list, "activated", G_CALLBACK (listbox_activated), NULL);

	bbox = nmt_newt_button_box_new (NMT_NEWT_BUTTON_BOX_VERTICAL);
	nmt_newt_grid_add (NMT_NEWT_GRID (grid), bbox, 1, 0);
	nmt_newt_widget_set_padding (bbox, 1, 1, 0, 1);

	activate = nmt_newt_button_box_add_start (NMT_NEWT_BUTTON_BOX (bbox), _("Activate"));
	g_signal_connect (list, "notify::active", G_CALLBACK (listbox_active_changed), activate);
	listbox_active_changed (G_OBJECT (list), NULL, activate);
	g_signal_connect (activate, "clicked", G_CALLBACK (activate_clicked), list);

	quit = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (bbox), _("Quit"));
	nmt_newt_widget_set_exit_on_activate (quit, TRUE);

	nmt_newt_form_set_content (form, grid);
	return form;
}
예제 #9
0
static void
nmt_newt_form_set_property (GObject      *object,
                            guint         prop_id,
                            const GValue *value,
                            GParamSpec   *pspec)
{
	NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (object);
	int screen_width, screen_height;

	switch (prop_id) {
	case PROP_TITLE:
		if (g_value_get_string (value)) {
			priv->title_lc = nmt_newt_locale_from_utf8 (g_value_get_string (value));
		} else
			priv->title_lc = NULL;
		break;
	case PROP_FULLSCREEN:
		if (g_value_get_boolean (value)) {
			newtGetScreenSize (&screen_width, &screen_height);
			priv->x = priv->y = 2;
			priv->fixed_x = priv->fixed_y = TRUE;
			priv->width = screen_width - 4;
			priv->height = screen_height - 4;
			priv->fixed_width = priv->fixed_height = TRUE;
		}
		break;
	case PROP_FULLSCREEN_VERTICAL:
		if (g_value_get_boolean (value)) {
			newtGetScreenSize (&screen_width, &screen_height);
			priv->y = 2;
			priv->fixed_y = TRUE;
			priv->height = screen_height - 4;
			priv->fixed_height = TRUE;
		}
		break;
	case PROP_FULLSCREEN_HORIZONTAL:
		if (g_value_get_boolean (value)) {
			newtGetScreenSize (&screen_width, &screen_height);
			priv->x = 2;
			priv->fixed_x = TRUE;
			priv->width = screen_width - 4;
			priv->fixed_width = TRUE;
		}
		break;
	case PROP_X:
		if (g_value_get_uint (value)) {
			priv->x = g_value_get_uint (value);
			priv->fixed_x = TRUE;
		}
		break;
	case PROP_Y:
		if (g_value_get_uint (value)) {
			priv->y = g_value_get_uint (value);
			priv->fixed_y = TRUE;
		}
		break;
	case PROP_WIDTH:
		if (g_value_get_uint (value)) {
			priv->width = g_value_get_uint (value);
			priv->fixed_width = TRUE;
		}
		break;
	case PROP_HEIGHT:
		if (g_value_get_uint (value)) {
			priv->height = g_value_get_uint (value);
			priv->fixed_height = TRUE;
		}
		break;
	case PROP_PADDING:
		priv->padding = g_value_get_uint (value);
		break;
	case PROP_ESCAPE_EXITS:
		priv->escape_exits = g_value_get_boolean (value);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
예제 #10
0
static void
nmt_newt_form_build (NmtNewtForm *form)
{
	NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (form);
	int screen_height, screen_width, form_height, form_width;
	newtComponent *cos;
	int i;

	priv->dirty = FALSE;
	nmt_newt_widget_realize (NMT_NEWT_WIDGET (form));

	nmt_newt_widget_size_request (priv->content, &form_width, &form_height);
	newtGetScreenSize (&screen_width, &screen_height);

	if (!priv->fixed_width)
		priv->width = MIN (form_width + 2 * priv->padding, screen_width - 2);
	if (!priv->fixed_height)
		priv->height = MIN (form_height + 2 * priv->padding, screen_height - 2);

	if (!priv->fixed_x)
		priv->x = (screen_width - form_width) / 2;
	if (!priv->fixed_y)
		priv->y = (screen_height - form_height) / 2;

	nmt_newt_widget_size_allocate (priv->content,
	                               priv->padding,
	                               priv->padding,
	                               priv->width - 2 * priv->padding,
	                               priv->height - 2 * priv->padding);

	if (priv->height - 2 * priv->padding < form_height) {
		newtComponent scroll_bar =
			newtVerticalScrollbar (priv->width - 1, 0, priv->height,
			                       NEWT_COLORSET_WINDOW,
			                       NEWT_COLORSET_ACTCHECKBOX);

		priv->form = newtForm (scroll_bar, NULL, NEWT_FLAG_NOF12);
		newtFormAddComponent (priv->form, scroll_bar);
		newtFormSetHeight (priv->form, priv->height - 2);
	} else
		priv->form = newtForm (NULL, NULL, NEWT_FLAG_NOF12);

	if (priv->escape_exits)
		newtFormAddHotKey (priv->form, NEWT_KEY_ESCAPE);

	cos = nmt_newt_widget_get_components (priv->content);
	for (i = 0; cos[i]; i++)
		newtFormAddComponent (priv->form, cos[i]);
	g_free (cos);

	if (priv->focus) {
		newtComponent fco;

		fco = nmt_newt_widget_get_focus_component (priv->focus);
		if (fco)
			newtFormSetCurrent (priv->form, fco);
	}
#ifdef HAVE_NEWTFORMGETSCROLLPOSITION
	if (priv->scroll_position)
		newtFormSetScrollPosition (priv->form, priv->scroll_position);
#endif

	newtOpenWindow (priv->x, priv->y, priv->width, priv->height, priv->title_lc);
}
예제 #11
0
static void
nmt_newt_dialog_g_log_handler (const char     *log_domain,
                               GLogLevelFlags  log_level,
                               const char     *message,
                               gpointer        user_data)
{
	const char *level_name;
	char *full_message;
	int screen_width, screen_height;
	newtComponent text, ok, form;
	newtGrid grid;

	g_assert (!(log_level & G_LOG_FLAG_RECURSION));

	if (log_level & G_LOG_LEVEL_DEBUG)
		return;

	switch (log_level & G_LOG_LEVEL_MASK) {
	case G_LOG_LEVEL_ERROR:
		level_name = "ERROR";
		break;
	case G_LOG_LEVEL_CRITICAL:
		level_name = "CRITICAL";
		break;
	case G_LOG_LEVEL_WARNING:
		level_name = "WARNING";
		break;
	case G_LOG_LEVEL_MESSAGE:
		level_name = "Message";
		break;
	default:
		level_name = NULL;
	}

	full_message = g_strdup_printf ("%s%s%s%s%s",
	                                log_domain ? log_domain : "",
	                                log_domain && level_name ? " " : "",
	                                level_name ? level_name : "",
	                                log_domain || level_name ? ": " : "",
	                                message);

	/* newtWinMessage() wraps the window too narrowly by default, so
	 * we don't want to use that. But we intentionally avoid using any
	 * NmtNewt classes, to avoid possible error recursion.
	 */

	newtGetScreenSize (&screen_width, &screen_height);
	text = newtTextboxReflowed (-1, -1, full_message, MAX (70, screen_width - 10), 0, 0, 0);
	g_free (full_message);

	ok = newtButton (-1, -1, "OK");

	grid = newtCreateGrid (1, 2);
	newtGridSetField (grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 0, 0, 0);
	newtGridSetField (grid, 0, 1, NEWT_GRID_COMPONENT, ok, 0, 1, 0, 0,
	                  NEWT_ANCHOR_RIGHT, 0);

	newtGridWrappedWindow (grid, (char *) (level_name ? level_name : ""));
	newtGridFree (grid, TRUE);

	form = newtForm (NULL, NULL, 0);
	newtFormAddComponents (form, text, ok, NULL);
	newtRunForm (form);
	newtFormDestroy (form);
	newtPopWindow ();
}