/* change to an existing vt */ static void change_vt (int vt) { char *cmd; char *ret; cmd = g_strdup_printf (MDM_SUP_SET_VT " %d", vt); ret = mdmcomm_call_mdm (cmd, auth_cookie, "1.0.0.0", 5); g_free (cmd); if (ve_string_empty (ret) || strcmp (ret, "OK") != 0) { GtkWidget *dialog; const char *message = mdmcomm_get_error_message (ret, use_xnest); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot change display"), message); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } g_free (ret); }
static void set_face_from_filename (const char *filename) { GtkWidget *image; GdkPixbuf *pixbuf; GdkPixbuf *scaled; image = glade_xml_get_widget (xml, "face_image"); pixbuf = gdk_pixbuf_new_from_file (filename, NULL); scaled = scale_pixbuf (pixbuf); g_object_unref (pixbuf); pixbuf = scaled; if (! pixbuf) return; if (gdk_pixbuf_save (pixbuf, photofile, "png", NULL, NULL) != TRUE) { GtkWidget *d; char *tmp = g_filename_to_utf8 (photofile, -1, NULL, NULL, NULL); char *msg; msg = g_strdup_printf (_("File %s cannot be opened for " "writing."), tmp); d = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot open file"), msg); gtk_dialog_run (GTK_DIALOG (d)); gtk_widget_destroy (d); g_free (tmp); g_free (msg); } else { /* Change to g_chmod after glib 2.8 release */ g_chmod (photofile, 0644); } gtk_image_set_from_file (GTK_IMAGE (image), photofile); }
int main (int argc, char *argv[]) { GtkWidget *dialog; char *command; char *version; char *ret; const char *message; GOptionContext *ctx; bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Option parsing */ ctx = g_option_context_new ("- New mdm login"); g_option_context_add_main_entries (ctx, options, _("main options")); g_option_context_parse (ctx, &argc, &argv, NULL); g_option_context_free (ctx); if (monte_carlo_pi) { calc_pi (); return 0; } mdm_log_init (); mdm_log_set_debug (debug_in); if (args_remaining != NULL && args_remaining[0] != NULL) server = args_remaining[0]; if (send_command != NULL) { if ( ! mdmcomm_check (FALSE)) { mdm_common_error (_("Error: MDM (MDM Display Manager) is not running.")); mdm_common_error (_("You might be using a different display manager.")); return 1; } } else { /* * The --command argument does not display anything, so avoid * running gtk_init until it finishes. Sometimes the * --command argument is used when there is no display so it * will fail and cause the program to exit, complaining about * "no display". */ gtk_init (&argc, &argv); if ( ! mdmcomm_check (TRUE)) { return 1; } } /* Start reading config data in bulk */ mdmcomm_comm_bulk_start (); /* Process --command option */ g_type_init (); if (send_command != NULL) { /* gdk_init is needed for cookie code to get display */ gdk_init (&argc, &argv); if (authenticate) auth_cookie = mdmcomm_get_auth_cookie (); /* * If asking for a translatable config value, then try to get * the translated value first. If this fails, then go ahead * and call the normal sockets command. */ if (strncmp (send_command, MDM_SUP_GET_CONFIG " ", strlen (MDM_SUP_GET_CONFIG " ")) == 0) { gchar *value = NULL; const char *key = &send_command[strlen (MDM_SUP_GET_CONFIG " ")]; if (is_key (MDM_KEY_WELCOME, key) || is_key (MDM_KEY_REMOTE_WELCOME, key)) { value = mdm_config_get_translated_string ((gchar *)key); if (value != NULL) { ret = g_strdup_printf ("OK %s", value); } } /* * If the above didn't return a value, then must be a * different key, so call mdmcomm_call_mdm. */ if (value == NULL) ret = mdmcomm_call_mdm (send_command, auth_cookie, "1.0.0.0", 5); } else { ret = mdmcomm_call_mdm (send_command, auth_cookie, "1.0.0.0", 5); } /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); if (ret != NULL) { g_print ("%s\n", ret); return 0; } else { dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot communicate with MDM " "(The MDM Display Manager)"), _("Perhaps you have an old version " "of MDM running.")); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } } /* * Now process what mdmflexiserver is more frequently used to * do, start VT (Virtual Terminal) sesions - at least on * systems where it is supported. On systems where it is not * supporteed VT stands for "Very Tight" and will mess up your * display if you use it. Tight! So do not use it. * * I would accept a patch to disable it on such systems, but it * is easy to avoid not using it as long as your distro does not * put the menu choice in the application launch button on the * panel (don't ship the desktop file). */ /* * Always attempt to get cookie and authenticate. On remote * servers */ auth_cookie = mdmcomm_get_auth_cookie (); if (use_xnest) { char *cookie = mdmcomm_get_a_cookie (FALSE /* binary */); if (cookie == NULL) { /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You do not seem to have the " "authentication needed for this " "operation"), _("Perhaps your .Xauthority " "file is not set up correctly.")); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } command = g_strdup_printf (MDM_SUP_FLEXI_XNEST " %s %d %s %s", mdmcomm_get_display (), (int)getuid (), cookie, XauFileName ()); g_free (cookie); version = "1.0.0.0"; auth_cookie = NULL; } else { /* check for other displays/logged in users */ check_for_users (); if (auth_cookie == NULL) { /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You do not seem to be logged in on the " "console"), _("Starting a new login only " "works correctly on the console.")); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } read_servers (); server = choose_server (); if (server == NULL) command = g_strdup (MDM_SUP_FLEXI_XSERVER); else command = g_strdup_printf (MDM_SUP_FLEXI_XSERVER " %s", server); version = "1.0.0.0"; } ret = mdmcomm_call_mdm (command, auth_cookie, version, 5); g_free (command); g_free (auth_cookie); g_strfreev (args_remaining); /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); if (ret != NULL && strncmp (ret, "OK ", 3) == 0) { /* if we switched to a different screen as a result of this, * lock the current screen */ if ( ! no_lock && ! use_xnest) { maybe_lock_screen (); } /* all fine and dandy */ g_free (ret); return 0; } message = mdmcomm_get_error_message (ret, use_xnest); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot start new display"), message); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_free (ret); return 1; }
int main (int argc, char *argv[]) { GtkWidget *dialog; char *ret; const char *message; GOptionContext *ctx; bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Option parsing */ ctx = g_option_context_new ("- New mdm login"); g_option_context_add_main_entries (ctx, options, _("main options")); g_option_context_parse (ctx, &argc, &argv, NULL); g_option_context_free (ctx); mdm_log_init (); mdm_log_set_debug (debug_in); if (send_command != NULL) { if ( ! mdmcomm_is_daemon_running (FALSE)) { mdm_common_error (_("Error: MDM (MDM Display Manager) is not running.")); mdm_common_error (_("You might be using a different display manager.")); return 1; } } else { /* * The --command argument does not display anything, so avoid * running gtk_init until it finishes. Sometimes the * --command argument is used when there is no display so it * will fail and cause the program to exit, complaining about * "no display". */ gtk_init (&argc, &argv); if ( ! mdmcomm_is_daemon_running (TRUE)) { return 1; } } mdmcomm_open_connection_to_daemon (); /* Process --command option */ g_type_init (); if (send_command != NULL) { /* gdk_init is needed for cookie code to get display */ gdk_init (&argc, &argv); if (authenticate) auth_cookie = mdmcomm_get_auth_cookie (); /* * If asking for a translatable config value, then try to get * the translated value first. If this fails, then go ahead * and call the normal sockets command. */ if (strncmp (send_command, MDM_SUP_GET_CONFIG " ", strlen (MDM_SUP_GET_CONFIG " ")) == 0) { gchar *value = NULL; const char *key = &send_command[strlen (MDM_SUP_GET_CONFIG " ")]; if (is_key (MDM_KEY_WELCOME, key)) { value = mdm_config_get_translated_string ((gchar *)key); if (value != NULL) { ret = g_strdup_printf ("OK %s", value); } } /* * If the above didn't return a value, then must be a * different key, so call the daemon. */ if (value == NULL) ret = mdmcomm_send_cmd_to_daemon_with_args (send_command, auth_cookie, 5); } else { ret = mdmcomm_send_cmd_to_daemon_with_args (send_command, auth_cookie, 5); } /* At this point we are done using the socket, so close it */ mdmcomm_close_connection_to_daemon (); if (ret != NULL) { g_print ("%s\n", ret); return 0; } else { dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot communicate with MDM " "(The MDM Display Manager)"), _("Perhaps you have an old version " "of MDM running.")); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } } /* * Always attempt to get cookie and authenticate. On remote * servers */ auth_cookie = mdmcomm_get_auth_cookie (); /* check for other displays/logged in users */ check_for_users (); if (auth_cookie == NULL) { /* At this point we are done using the socket, so close it */ mdmcomm_close_connection_to_daemon (); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You do not seem to be logged in on the " "console"), _("Starting a new login only " "works correctly on the console.")); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } ret = mdmcomm_send_cmd_to_daemon_with_args (MDM_SUP_FLEXI_XSERVER, auth_cookie, 5); g_free (auth_cookie); g_strfreev (args_remaining); /* At this point we are done using the socket, so close it */ mdmcomm_close_connection_to_daemon (); if (ret != NULL && strncmp (ret, "OK ", 3) == 0) { /* if we switched to a different screen as a result of this, * lock the current screen */ if ( ! no_lock ) { maybe_lock_screen (); } /* all fine and dandy */ g_free (ret); return 0; } message = mdmcomm_get_error_message (ret); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot start new display"), message); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_free (ret); return 1; }