Exemplo n.º 1
0
static gboolean 
update_device_lists(FormatDialog* dialog)
{
	if(dialog->hal_drive_list) {
		format_volume_list_free(dialog->hal_drive_list);
		dialog->hal_drive_list = NULL;
	}

	dialog->hal_drive_list = build_volume_list(dialog->hal_context, FORMATVOLUMETYPE_DRIVE,
			dialog->icon_cache, 22, 22);

	if(!dialog->hal_drive_list) {
		show_error_dialog(dialog->toplevel, 
				_("Cannot get list of disks"), 
				_("Make sure the HAL daemon is running and configured correctly"));
		return FALSE;
	}

	if(dialog->hal_volume_list) {
		format_volume_list_free(dialog->hal_volume_list);
		dialog->hal_volume_list = NULL;
	}

	dialog->hal_volume_list = build_volume_list(dialog->hal_context, FORMATVOLUMETYPE_VOLUME,
			dialog->icon_cache, 22, 22);

	if(!dialog->hal_volume_list) {
		show_error_dialog(dialog->toplevel, 
				_("Cannot get list of partitions"), 
				_("Make sure the HAL daemon is running and configured correctly"));
		return FALSE;
	}

	return TRUE;
}
Exemplo n.º 2
0
/* Test database status: database exists, correct tables, correct version */
static GdaConnection *
sql_get_tested_connection (const gchar   *dsn_name,
			   const gchar   *host,
			   const gchar   *db_name,
			   GdaClient     *client,
			   PlannerPlugin *plugin)
{
	GdaConnection *conn = NULL;
	gboolean       success;
	gchar         *str;
	GError        *error;

	conn = gda_client_open_connection (client, dsn_name, NULL, NULL, 0, &error);

	if (conn == NULL) {
		if (!create_database (dsn_name, host, db_name, plugin)) {
			str = g_strdup_printf (_("Connection to database '%s@%s' failed."),
					       db_name, host);
			show_error_dialog (plugin, str);
			conn = NULL;
		} else {
			conn = gda_client_open_connection (client, dsn_name, NULL, NULL, 0, &error);
		}
	}

	if (conn != NULL) {

		success = sql_execute_command (conn, "SET TIME ZONE 'UTC'");
		if (!success) {
			g_warning ("SET TIME ZONE command failed: %s.",
					sql_get_last_error (conn));
			goto out;
		}

		if (!check_database_tables (conn, plugin)) {
			str = g_strdup_printf (_("Test to tables in database '%s' failed."),
					       db_name);
			show_error_dialog (plugin, str);
			g_free (str);
			goto out;
		}
	}

	/* g_object_unref (client); */
	return conn;

out:
	if (conn) {
		gda_connection_close (conn);
	}

	return NULL;
}
Exemplo n.º 3
0
/* An application is valid if:
 *
 * 1) The file exists
 * 2) The user has permissions to run the file
 */
static gboolean
check_application (GtkAppChooserDialog  *self,
                   GAppInfo            **app_out)
{
  const char *command;
  char *path = NULL;
  char **argv = NULL;
  int argc;
  GError *error = NULL;
  gint retval = TRUE;
  GAppInfo *info;

  command = NULL;

  info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
  command = g_app_info_get_executable (info);

  g_shell_parse_argv (command, &argc, &argv, &error);

  if (error)
    {
      show_error_dialog (_("Could not run application"),
                         error->message,
                         GTK_WINDOW (self));
      g_error_free (error);
      retval = FALSE;
      goto cleanup;
    }

  path = g_find_program_in_path (argv[0]);
  if (!path)
    {
      char *error_message;

      error_message = g_strdup_printf (_("Could not find '%s'"),
                                       argv[0]);

      show_error_dialog (_("Could not find application"),
                         error_message,
                         GTK_WINDOW (self));
      g_free (error_message);
      retval = FALSE;
      goto cleanup;
    }

  *app_out = info;

 cleanup:
  g_strfreev (argv);
  g_free (path);

  return retval;
}
Exemplo n.º 4
0
bool GodotSharpEditor::_create_project_solution() {

	EditorProgress pr("create_csharp_solution", "Generating solution...", 2);

	pr.step("Generating C# project...");

	String path = OS::get_singleton()->get_resource_dir();
	String name = ProjectSettings::get_singleton()->get("application/config/name");
	if (name.empty()) {
		name = "UnnamedProject";
	}

	String guid = CSharpProject::generate_game_project(path, name);

	if (guid.length()) {

		NETSolution solution(name);

		if (!solution.set_path(path)) {
			show_error_dialog("Failed to create solution.");
			return false;
		}

		Vector<String> extra_configs;
		extra_configs.push_back("Tools");

		solution.add_new_project(name, guid, extra_configs);

		Error sln_error = solution.save();

		if (sln_error != OK) {
			show_error_dialog("Failed to save solution.");
			return false;
		}

		if (!GodotSharpBuilds::make_api_sln(GodotSharpBuilds::API_CORE))
			return false;

		if (!GodotSharpBuilds::make_api_sln(GodotSharpBuilds::API_EDITOR))
			return false;

		pr.step("Done");

		// Here, after all calls to progress_task_step
		call_deferred("_remove_create_sln_menu_option");

	} else {
		show_error_dialog("Failed to create C# project.");
	}

	return true;
}
Exemplo n.º 5
0
static void
software_button_clicked_cb (GtkButton           *button,
                            GtkAppChooserDialog *self)
{
  GSubprocess *process;
  GError *error = NULL;
  gchar *option;

  if (self->priv->content_type)
    option = g_strconcat ("--search=", self->priv->content_type, NULL);
  else
    option = g_strdup ("--mode=overview");

  process = g_subprocess_new (0, &error, "gnome-software", option, NULL);
  if (!process)
    {
      show_error_dialog (_("Failed to start GNOME Software"),
                         error->message, GTK_WINDOW (self));
      g_error_free (error);
    }
  else
    g_object_unref (process);

  g_free (option);
}
Exemplo n.º 6
0
uintptr_t object_alloc(int size, int tag)
{
  uintptr_t *ret;

  if(tag == FLOAT_TAG)
    ret = GC_MALLOC(sizeof(double));
  else
    ret = GC_MALLOC(size * sizeof(OBJECT_PTR));

  if(!ret)
  {
    if(!console_mode && !single_expression_mode && !pipe_mode)
    {
      char buf[MAX_STRING_LENGTH];
      memset(buf, '\0', MAX_STRING_LENGTH);
      int len=0;
      len += sprintf(buf, "Unable to allocate memory\n");
      show_error_dialog(buf);
    }
    else
      printf("Unable to allocate memory\n");

    cleanup();
    exit(1);
  }

  assert(is_valid_object((OBJECT_PTR)((uintptr_t)ret+tag)));

  return (uintptr_t)ret;
}
static void
on_realm_joined (GObject *source,
                 GAsyncResult *result,
                 gpointer user_data)
{
        UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
        GError *error = NULL;

        um_realm_join_finish (self->selected_realm,
                              result, &error);

        /* Yay, joined the domain, register the user locally */
        if (error == NULL) {
                g_debug ("Joining realm completed successfully");
                enterprise_permit_user_login (self);

        /* Credential failure while joining domain, prompt for admin creds */
        } else if (g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_LOGIN) ||
                   g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_PASSWORD)) {
                g_debug ("Joining realm failed due to credentials");
                join_show_prompt (self, error);

        /* Other failure */
        } else {
                show_error_dialog (self, _("Failed to join domain"), error);
                g_message ("Failed to join the domain: %s", error->message);
                finish_action (self);
                g_error_free (error);
        }

        g_object_unref (self);
}
static void
on_join_login (GObject *source,
               GAsyncResult *result,
               gpointer user_data)
{
        UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
        GError *error = NULL;
        GBytes *creds;

        um_realm_login_finish (result, &creds, &error);

        /* Logged in as admin successfully, use creds to join domain */
        if (error == NULL) {
                if (!um_realm_join_as_admin (self->selected_realm,
                                             gtk_entry_get_text (self->join_name),
                                             gtk_entry_get_text (self->join_password),
                                             creds, self->cancellable, on_realm_joined,
                                             g_object_ref (self))) {
                        show_error_dialog (self, _("No supported way to authenticate with this domain"), NULL);
                        g_message ("Authenticating as admin is not supported by the realm");
                        finish_action (self);
                }

                g_bytes_unref (creds);

        /* Couldn't login as admin, show prompt again */
        } else {
                join_show_prompt (self, error);
                g_message ("Couldn't log in as admin to join domain: %s", error->message);
                g_error_free (error);
        }

        g_object_unref (self);
}
Exemplo n.º 9
0
static gboolean
spawn_synaptic (GtkWindow   *window,
		const gchar *path,
		gint        *child_pid)
{
  gchar **argv;
  GError *error = NULL;
  gboolean retval = TRUE;
  gint i = 0;

  argv = g_new0 (gchar*, 6);
  argv[i++] = g_find_program_in_path ("gksudo");
  argv[i++] = g_strdup ("--desktop");
  argv[i++] = g_strdup ("/usr/share/applications/synaptic.desktop");
  argv[i++] = g_strdup ("--disable-grab");
  argv[i++] = get_synaptic_command_line (window, path);
  argv[i++] = NULL;

  if (!gdk_spawn_on_screen (gtk_window_get_screen (window),
			    NULL, argv, NULL,
			    G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
			    NULL, NULL, child_pid, &error))
    {
      show_error_dialog (window, (error) ? error->message : "");
      g_error_free (error);
      retval = FALSE;
    }

  g_strfreev (argv);

  return retval;
}
static void
on_register_user (GObject *source,
                  GAsyncResult *result,
                  gpointer user_data)
{
        UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
        GError *error = NULL;
        UmUser *user = NULL;

        um_user_manager_cache_user_finish (UM_USER_MANAGER (source),
                                           result, &user, &error);

        /* This is where we're finally done */
        if (error == NULL) {
                g_debug ("Successfully cached remote user: %s", um_user_get_user_name (user));
                finish_action (self);
                complete_dialog (self, user);

        } else {
                show_error_dialog (self, _("Failed to register account"), error);
                g_message ("Couldn't cache user account: %s", error->message);
                finish_action (self);
                g_error_free (error);
        }
}
Exemplo n.º 11
0
static void
search_for_mimetype_ready_cb (GObject      *source,
                              GAsyncResult *res,
                              gpointer      user_data)
{
  GtkAppChooserOnline *online = GTK_APP_CHOOSER_ONLINE (source);
  GtkAppChooserDialog *self = user_data;
  GError *error = NULL;

  gdk_threads_enter ();

  _gtk_app_chooser_online_search_for_mimetype_finish (online, res, &error);

  if (error != NULL)
    {
      show_error_dialog (_("Failed to look for applications online"),
                         error->message, GTK_WINDOW (self));
      g_error_free (error);
    }
  else
    {
      gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
    }

  gdk_threads_leave ();
}
static void
on_join_login (GObject *source,
               GAsyncResult *result,
               gpointer user_data)
{
  GisAccountPageEnterprise *page = user_data;
  GisAccountPageEnterprisePrivate *priv = gis_account_page_enterprise_get_instance_private (page);
  GError *error = NULL;
  GBytes *creds;

  um_realm_login_finish (priv->realm, result, &creds, &error);

  /* Logged in as admin successfully, use creds to join domain */
  if (error == NULL) {
    if (!um_realm_join_as_admin (priv->realm,
                                 gtk_entry_get_text (GTK_ENTRY (priv->join_name)),
                                 gtk_entry_get_text (GTK_ENTRY (priv->join_password)),
                                 creds, NULL, on_realm_joined, page)) {
      show_error_dialog (page, _("No supported way to authenticate with this domain"), NULL);
      g_message ("Authenticating as admin is not supported by the realm");
    }

    g_bytes_unref (creds);

  /* Couldn't login as admin, show prompt again */
  } else {
    join_show_prompt (page, error);
    g_message ("Couldn't log in as admin to join domain: %s", error->message);
    g_error_free (error);
  }
}
static void
on_realm_joined (GObject *source,
                 GAsyncResult *result,
                 gpointer user_data)
{
  GisAccountPageEnterprise *page = user_data;
  GisAccountPageEnterprisePrivate *priv = gis_account_page_enterprise_get_instance_private (page);
  GError *error = NULL;

  um_realm_join_finish (priv->realm, result, &error);

  /* Yay, joined the domain, register the user locally */
  if (error == NULL) {
    g_debug ("Joining realm completed successfully");
    enterprise_permit_user_login (page, priv->realm);

    /* Credential failure while joining domain, prompt for admin creds */
  } else if (g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_LOGIN) ||
             g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_PASSWORD) ||
             g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_HOSTNAME)) {
    g_debug ("Joining realm failed due to credentials or host name");

    join_show_prompt (page, error);

    /* Other failure */
  } else {
    show_error_dialog (page, _("Failed to join domain"), error);
    g_message ("Failed to join the domain: %s", error->message);
    apply_complete (page, FALSE);
  }

  g_clear_error (&error);
}
static void
on_realm_login (GObject *source,
                GAsyncResult *result,
                gpointer user_data)
{
        UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
        GError *error = NULL;
        GBytes *creds;

        um_realm_login_finish (result, &creds, &error);
        if (error == NULL) {

                /* Already joined to the domain, just register this user */
                if (um_realm_is_configured (self->selected_realm)) {
                        g_debug ("Already joined to this realm");
                        enterprise_permit_user_login (self);

                /* Join the domain, try using the user's creds */
                } else if (!um_realm_join_as_user (self->selected_realm,
                                                   gtk_entry_get_text (self->enterprise_login),
                                                   gtk_entry_get_text (self->enterprise_password),
                                                   creds, self->cancellable,
                                                   on_realm_joined,
                                                   g_object_ref (self))) {

                        /* If we can't do user auth, try to authenticate as admin */
                        g_debug ("Cannot join with user credentials");
                        join_show_prompt (self, NULL);
                }

                g_bytes_unref (creds);

        /* A problem with the user's login name or password */
        } else if (g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_LOGIN)) {
                g_debug ("Problem with the user's login: %s", error->message);
                set_entry_validation_error (self->enterprise_login, error->message);
                finish_action (self);
                gtk_widget_grab_focus (GTK_WIDGET (self->enterprise_login));

        } else if (g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_PASSWORD)) {
                g_debug ("Problem with the user's password: %s", error->message);
                set_entry_validation_error (self->enterprise_password, error->message);
                finish_action (self);
                gtk_widget_grab_focus (GTK_WIDGET (self->enterprise_password));

        /* Other login failure */
        } else {
                g_dbus_error_strip_remote_error (error);
                show_error_dialog (self, _("Failed to log into domain"), error);
                g_message ("Couldn't log in as user: %s", error->message);
                finish_action (self);
        }

        g_clear_error (&error);
        g_object_unref (self);
}
Exemplo n.º 15
0
/**
 * gdict_show_error_dialog:
 * @widget: the widget that emits the error
 * @title: the primary error message
 * @message: the secondary error message or %NULL
 *
 * Creates and shows an error dialog bound to @widget.
 *
 * Since: 1.0
 */
void
_gdict_show_error_dialog (GtkWidget   *widget,
			  const gchar *title,
			  const gchar *detail)
{
  g_return_if_fail (GTK_IS_WIDGET (widget));
  g_return_if_fail (title != NULL);
  
  show_error_dialog (get_toplevel_window (widget), title, detail);
}
Exemplo n.º 16
0
static FormatVolume*
write_partition_table(FormatDialog* dialog, FormatVolume* vol, const char* fs)
{
	FormatVolume* ret = NULL;
	char* drive_udi = g_strdup(libhal_drive_get_udi(vol->drive));

	/* Write out a new table */
	GError* err = NULL;

	/* FIXME: Somehow, we need to decide what kind of table to write */
	if(!write_partition_table_for_device(vol->drive, PART_TYPE_MSDOS, &err)) {
		show_error_dialog(dialog->toplevel, _("Error formatting disk"), err->message);
		g_error_free(err);
		goto out;
	}

	/* Set the partition type */
	int msdos_type = get_part_type_from_fs(fs);
	if( !set_partition_type(vol->drive, 0 /* Always first partition */, msdos_type) ) {
		show_error_dialog(dialog->toplevel, _("Error formatting disk"), _("Couldn't set partition type on drive"));
		goto out;
	}

	/* Find the partition attached to our drive */
	if(!update_device_lists(dialog))	goto out;
	GSList* iter; 
	for(iter = dialog->hal_volume_list; iter != NULL; iter = g_slist_next(iter)) {
		FormatVolume* vol = iter->data;
		if(!strcmp(vol->drive_udi, drive_udi))	break;
	}
	if(iter == NULL) {
		show_error_dialog(dialog->toplevel, _("Error formatting disk"), 
				_("Can't find new partition after formatting. Try again"));
		goto out;
	}

	ret = iter->data;

out:
	return ret;
}
Exemplo n.º 17
0
void
on_help_button_clicked (GtkWidget *w, gpointer user_data)
{
	GError *error = NULL;

	gnome_help_display_desktop_on_screen (NULL, "gformat", "gformat", "usage", 
					      gtk_widget_get_screen (w), &error);
	if (error) {
		show_error_dialog (gtk_widget_get_toplevel(w), _("Could not display help for the disk formatter."), error->message);
		g_error_free (error);
	}
}
Exemplo n.º 18
0
static void
check_wireless (WirelessApplet *applet)
{
	struct stat sbuf;
	
	if (stat ("/proc/net/wireless", &sbuf) != 0) {
		gtk_tooltips_set_tip (applet->tips,
				GTK_WIDGET (applet),
				_("No Wireless Devices"),
				NULL);
		show_error_dialog (_("There doesn't seem to be any wireless devices configured on your system.\nPlease verify your configuration if you think this is incorrect."));
	}
}
Exemplo n.º 19
0
/**
 * gdict_show_gerror_dialog:
 * @widget: the widget that emits the error
 * @title: the primary error message
 * @error: a #GError
 *
 * Creates and shows an error dialog bound to @widget, using @error
 * to fill the secondary text of the message dialog with the error
 * message.  Also takes care of freeing @error.
 *
 * Since: 1.0
 */
void
_gdict_show_gerror_dialog (GtkWidget   *widget,
			   const gchar *title,
			   GError      *error)
{
  g_return_if_fail (GTK_IS_WIDGET (widget));
  g_return_if_fail (title != NULL);
  g_return_if_fail (error != NULL);
  
  show_error_dialog (get_toplevel_window (widget), title, error->message);
      
  g_error_free (error);
}
Exemplo n.º 20
0
static void
launch_mate_disk (const gchar *device_file)
{
        gchar *command_line;
        GError *error;

        command_line = g_strdup_printf ("mate_disk --show-volume \"%s\"", device_file);

        error = NULL;
        if (!g_spawn_command_line_async (command_line, &error)) {
                show_error_dialog (NULL,
                                   _("Error launching Disk Utility"),
                                   error->message);
                g_error_free (error);
        }
        g_free (command_line);
}
Exemplo n.º 21
0
void load_keybind(	gmpv_handle *ctx,
			const gchar *config_path,
			gboolean notify_propexp )
{
	gboolean propexp;

	ctx->keybind_list
		= keybind_parse_config_with_defaults(config_path, &propexp);

	if(notify_propexp && propexp)
	{
		const gchar *msg = _(	"Keybindings that require Property "
					"Expansion are not supported and have "
					"been ignored." );

		show_error_dialog(ctx, NULL, msg);
	}
}
Exemplo n.º 22
0
static gboolean
find_app (GtkWindow   *window,
	  const gchar *app)
{
  gchar *path;

  path = g_find_program_in_path (app);

  if(!path)
    {
      show_error_dialog (window,
			 _("The necessary applications to install"
			   " the package could not be found."));
      return FALSE;
    }

  g_free (path);

  return TRUE;
}
Exemplo n.º 23
0
void Logger::log_handler(const gchar * log_domain,
			       GLogLevelFlags log_level,
			       const gchar *message,
			       gpointer user_data)
{
	std::stringstream buf;
	if(log_domain && log_domain[0])
		buf << "(" << log_domain << ") ";
	if(log_level & G_LOG_LEVEL_ERROR)
		buf << "[error] ";
	else if(log_level & G_LOG_LEVEL_CRITICAL)
		buf << "[critical] ";
	else if(log_level & G_LOG_LEVEL_WARNING)
		buf << "[warning] ";
	else if(log_level & G_LOG_LEVEL_MESSAGE)
		buf << "[message] ";
	else if(log_level & G_LOG_LEVEL_INFO)
		buf << "[info] ";
	else if(log_level & G_LOG_LEVEL_DEBUG)
		buf << "[debug] ";
	if(message)
		buf << message;
	buf << "\n";
	if(is_do_log_message(log_level, logger->console_message_level)) {
		std::cout << buf.str();
#ifdef ENABLE_LOG_WINDOW
		gLogWindow.append(buf.str().c_str());
#endif
	}
	if(is_do_log_message(log_level, logger->log_message_level) && logger->h_log_file) {
		fputs(buf.str().c_str(), logger->h_log_file);
		logger->start_flush_log_timer();
	}
	// the application will be aborted short after this message
	if(log_level & G_LOG_FLAG_FATAL) {
		if(logger->h_log_file)
			fflush(logger->h_log_file);
		// make the fault loud and clear for the user
		show_error_dialog(buf.str().c_str());
	}
}
static void
on_permit_user_login (GObject *source,
                      GAsyncResult *result,
                      gpointer user_data)
{
        UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
        UmRealmCommon *common;
        UmUserManager *manager;
        GError *error = NULL;
        gchar *login;

        common = UM_REALM_COMMON (source);
        um_realm_common_call_change_login_policy_finish (common, result, &error);
        if (error == NULL) {

                /*
                 * Now tell the account service about this user. The account service
                 * should also lookup information about this via the realm and make
                 * sure all that is functional.
                 */
                manager = um_user_manager_ref_default ();
                login = um_realm_calculate_login (common, gtk_entry_get_text (self->enterprise_login));
                g_return_if_fail (login != NULL);

                g_debug ("Caching remote user: %s", login);

                um_user_manager_cache_user (manager, login, self->cancellable,
                                            on_register_user, g_object_ref (self),
                                            g_object_unref);

                g_free (login);
                g_object_unref (manager);

        } else {
                show_error_dialog (self, _("Failed to register account"), error);
                g_message ("Couldn't permit logins on account: %s", error->message);
                finish_action (self);
        }

        g_object_unref (self);
}
Exemplo n.º 25
0
void raise_error(char *err_str)
{
  if(!console_mode && !single_expression_mode && !pipe_mode)
  {
    show_error_dialog(err_str);

#ifdef INTERPRETER_MODE
    debug_mode = true;
    debug_continuation = create_current_continuation();
    debug_env = reg_current_env;
    reg_next_expression = NIL;

    debug_execution_stack = reg_current_stack;

    create_debug_window(DEFAULT_DEBUG_WINDOW_POSX,
			DEFAULT_DEBUG_WINDOW_POSY,
			DEFAULT_DEBUG_WINDOW_WIDTH,
			DEFAULT_DEBUG_WINDOW_HEIGHT);
#endif
  }
  else
    fprintf(stdout, "%s\n", err_str);

  //to stay commented out till we are
  //able to prpvide a meaningful backtrace
  //fprintf(stdout, "Begin backtrace\n");
  //print_backtrace();
  //fprintf(stdout, "End backtrace\n");

#ifdef INTERPRETER_MODE
  reg_accumulator = NIL;
  reg_current_value_rib = NIL;
  reg_next_expression = NIL;
#endif

  in_error = true;
  exception_object = cons(get_symbol_object("EXCEPTION"), get_string_object(err_str));
}
static void
on_permit_user_login (GObject *source,
                      GAsyncResult *result,
                      gpointer user_data)
{
  GisAccountPageEnterprise *page = user_data;
  GisAccountPageEnterprisePrivate *priv = gis_account_page_enterprise_get_instance_private (page);
  UmRealmCommon *common;
  GError *error = NULL;
  gchar *login;

  common = UM_REALM_COMMON (source);
  um_realm_common_call_change_login_policy_finish (common, result, &error);
  if (error == NULL) {

    /*
     * Now tell the account service about this user. The account service
     * should also lookup information about this via the realm and make
     * sure all that is functional.
     */
    login = um_realm_calculate_login (common, gtk_entry_get_text (GTK_ENTRY (priv->login)));
    g_return_if_fail (login != NULL);

    g_debug ("Caching remote user: %s", login);

    priv->act_user = act_user_manager_cache_user (priv->act_client, login, NULL);
    g_signal_emit (page, signals[USER_CACHED], 0, priv->act_user, gtk_entry_get_text (GTK_ENTRY (priv->password)));
    apply_complete (page, TRUE);

    g_free (login);
  } else {
    show_error_dialog (page, _("Failed to register account"), error);
    g_message ("Couldn't permit logins on account: %s", error->message);
    g_error_free (error);
    apply_complete (page, FALSE);
  }
}
static void
create_user_done (UmUserManager   *manager,
                  GAsyncResult    *res,
                  UmAccountDialog *self)
{
        UmUser *user;
        GError *error;

        finish_action (self);

        /* Note that user is returned without an extra reference */

        error = NULL;
        if (!um_user_manager_create_user_finish (manager, res, &user, &error)) {
                g_debug ("Failed to create user: %s", error->message);
                if (!g_error_matches (error, UM_USER_MANAGER_ERROR, UM_USER_MANAGER_ERROR_PERMISSION_DENIED))
                       show_error_dialog (self, _("Failed to add account"), error);
                g_error_free (error);
                gtk_widget_grab_focus (self->local_name);
        } else {
                g_debug ("Created user: %s", um_user_get_user_name (user));
                complete_dialog (self, user);
        }
}
static void
on_realm_login (GObject *source,
                GAsyncResult *result,
                gpointer user_data)
{
  GisAccountPageEnterprise *page = user_data;
  GisAccountPageEnterprisePrivate *priv = gis_account_page_enterprise_get_instance_private (page);
  GError *error = NULL;
  GBytes *creds = NULL;

  um_realm_login_finish (priv->realm, result, &creds, &error);

  /*
   * User login is valid, but cannot authenticate right now (eg: user needs
   * to change password at next login etc.)
   */
  if (g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_CANNOT_AUTH)) {
    g_clear_error (&error);
    creds = NULL;
  }

  if (error == NULL) {

    /* Already joined to the domain, just register this user */
    if (um_realm_is_configured (priv->realm)) {
      g_debug ("Already joined to this realm");
      enterprise_permit_user_login (page, priv->realm);

      /* Join the domain, try using the user's creds */
    } else if (creds == NULL ||
               !um_realm_join_as_user (priv->realm,
                                       gtk_entry_get_text (GTK_ENTRY (priv->login)),
                                       gtk_entry_get_text (GTK_ENTRY (priv->password)),
                                       creds, priv->cancellable,
                                       on_realm_joined,
                                       page)) {

      /* If we can't do user auth, try to authenticate as admin */
      g_debug ("Cannot join with user credentials");

      join_show_prompt (page, error);
    }

    g_bytes_unref (creds);

    /* A problem with the user's login name or password */
  } else if (g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_LOGIN)) {
    g_debug ("Problem with the user's login: %s", error->message);
    set_entry_validation_error (GTK_ENTRY (priv->login), error->message);
    gtk_widget_grab_focus (priv->login);
    apply_complete (page, FALSE);

  } else if (g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_PASSWORD)) {
    g_debug ("Problem with the user's password: %s", error->message);
    set_entry_validation_error (GTK_ENTRY (priv->password), error->message);
    gtk_widget_grab_focus (priv->password);
    apply_complete (page, FALSE);

    /* Other login failure */
  } else {
    show_error_dialog (page, _("Failed to log into domain"), error);
    g_message ("Couldn't log in as user: %s", error->message);
    apply_complete (page, FALSE);
  }

  g_clear_error (&error);
}
Exemplo n.º 29
0
int
main (int argc, char *argv[])
{
        int ret;
        GError *error;
        MduPool *pool;
        MduDevice *device;
        MduDevice *device_to_unmount;
        MduDevice *device_to_mount;
        MduPresentable *volume;
        gchar *volume_name;
        gchar *confirmation_secondary;
        GtkWidget *dialog;
        gint response;
        gchar *fs_type;
        gchar *fs_label;
        gboolean encrypt;
        gchar *passphrase;
        gboolean save_passphrase_in_keyring;
        gboolean save_passphrase_in_keyring_session;
        GMainLoop *loop;
        GVolumeMonitor *gvolume_monitor;
        GList *l;
        GList *gvolumes;
        GVolume *gvolume;
        GMount *gmount;
        gboolean take_ownership;
        FormatData *format_data;
        MduPresentable *toplevel;
        gchar *drive_name;
        gchar *format_desc;
        gchar *formatting_desc;
        gchar *size_str;
        gint grace_timeout_id;

        ret = 1;
        pool = NULL;
        device = NULL;
        device_to_unmount = NULL;
        device_to_mount = NULL;
        volume = NULL;
        volume_name = NULL;
        confirmation_secondary = NULL;
        dialog = NULL;
        fs_type = NULL;
        fs_label = NULL;
        passphrase = NULL;
        loop = NULL;
        volume = NULL;
        gmount = NULL;
        gvolume_monitor = NULL;
        gvolumes = NULL;
        gvolume = NULL;
        gmount = NULL;
        format_data = NULL;
        toplevel = NULL;
        drive_name = NULL;
        format_desc = NULL;
        formatting_desc = NULL;
        size_str = NULL;

#if !GLIB_CHECK_VERSION (2, 32, 0)
        g_thread_init (NULL);
#endif

        /* Initialize gettext support */
        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);

        /*  Initialize gtk  */
        error = NULL;
        if (! gtk_init_with_args (&argc, &argv, NULL, entries, GETTEXT_PACKAGE, &error)) {
                g_printerr ("Could not parse arguments: %s\n", error->message);
                g_error_free (error);
                goto out;
        }

        loop = g_main_loop_new (NULL, FALSE);

        g_set_prgname ("mdu-format-tool");
        g_set_application_name (_("Mate Disk Utility formatting tool"));

        if (device_file == NULL) {
                g_printerr ("Incorrect usage. Try --help.\n");
                goto out;
        }

        pool = mdu_pool_new ();
        if (pool == NULL) {
                g_warning ("Unable to get device pool");
                goto out;
        }

        device = mdu_pool_get_by_device_file (pool, device_file);
        if (device == NULL) {
                g_printerr ("No device for %s\n", device_file);
                goto out;
        }

        /* if the user specified a luks device, find the slave backing device */
        if (mdu_device_is_luks_cleartext (device)) {
                const gchar *slave;
                slave = mdu_device_luks_cleartext_get_slave (device);
                g_object_ref (device);
                device = mdu_pool_get_by_object_path (pool, slave);
                /* don't support LUKS in LUKS... */
                g_assert (!mdu_device_is_luks_cleartext (device));
        }

        volume = mdu_pool_get_volume_by_device (pool, device);
        if (volume == NULL) {
                g_printerr ("%s is not a volume\n", device_file);
                goto out;
        }
        volume_name = mdu_presentable_get_name (volume);

        toplevel = mdu_presentable_get_toplevel (MDU_PRESENTABLE (volume));
        if (toplevel != NULL && MDU_IS_DRIVE (toplevel)) {
                drive_name = mdu_presentable_get_name (toplevel);
        }
        size_str = mdu_util_get_size_for_display (mdu_device_get_size (device),
                                                  FALSE,
                                                  FALSE);

        if (drive_name != NULL) {
                if (mdu_device_is_partition (device)) {
                        /* Translators: First argument is the partition number, second argument is the drive name,
                         * third argument is the size (e.g. 10 GB)
                         */
                        format_desc = g_strdup_printf (_("Format partition %d of %s (%s)"),
                                                       mdu_device_partition_get_number (device),
                                                       drive_name,
                                                       size_str);
                        /* Translators: First argument is the partition number, second argument is the drive name,
                         * third argument is the size (e.g. 10 GB)
                         */
                        formatting_desc = g_strdup_printf (_("Formatting partition %d of %s (%s)"),
                                                           mdu_device_partition_get_number (device),
                                                           drive_name,
                                                           size_str);
                } else {
                        /* Translators: First argument is the drive name, second argument is the size (e.g. 10 GB) */
                        format_desc = g_strdup_printf (_("Format %s (%s)"),
                                                       drive_name,
                                                       size_str);
                        /* Translators: First argument is the drive name, second argument is the size (e.g. 10 GB) */
                        formatting_desc = g_strdup_printf (_("Formatting %s (%s)"),
                                                           drive_name,
                                                           size_str);
                }
        } else {
                /* Translators: First argument is the size (e.g. 10 GB), second is the device (e.g. /dev/md0) */
                format_desc = g_strdup_printf (_("Format %s Volume (%s)"),
                                               size_str,
                                               mdu_device_get_device_file (device));
                /* Translators: First argument is the size (e.g. 10 GB), second is the device (e.g. /dev/md0) */
                formatting_desc = g_strdup_printf (_("Formatting %s Volume (%s)"),
                                                   size_str,
                                                   mdu_device_get_device_file (device));
        }

        dialog = mdu_format_dialog_new (NULL, /* no parent window */
                                        volume,
                                        MDU_FORMAT_DIALOG_FLAGS_SIMPLE |
                                        MDU_FORMAT_DIALOG_FLAGS_DISK_UTILITY_BUTTON);
        gtk_window_set_title (GTK_WINDOW (dialog), format_desc);
        gtk_window_set_icon_name (GTK_WINDOW (dialog), "caja-mdu");
        gtk_widget_show_all (dialog);

        response = gtk_dialog_run (GTK_DIALOG (dialog));

        switch (response) {
        case GTK_RESPONSE_OK:
                break;

        case GTK_RESPONSE_ACCEPT:
                gtk_widget_destroy (dialog);
                dialog = NULL;
                launch_mate_disk (device_file);
                goto out;

        default: /* explicit fallthrough */
        case GTK_RESPONSE_CANCEL:
                goto out;
        }

        fs_type = mdu_format_dialog_get_fs_type (MDU_FORMAT_DIALOG (dialog));
        fs_label = mdu_format_dialog_get_fs_label (MDU_FORMAT_DIALOG (dialog));
        encrypt = mdu_format_dialog_get_encrypt (MDU_FORMAT_DIALOG (dialog));
        gtk_widget_destroy (dialog);
        dialog = NULL;

        /* Ask for passphrase if needed */
        passphrase = NULL;
        save_passphrase_in_keyring = FALSE;
        save_passphrase_in_keyring_session = FALSE;
        if (encrypt) {
                passphrase = mdu_util_dialog_ask_for_new_secret (NULL,
                                                                 &save_passphrase_in_keyring,
                                                                 &save_passphrase_in_keyring_session);
                if (passphrase == NULL)
                        goto out;
        }

        take_ownership = (g_strcmp0 (fs_type, "vfat") != 0);

        format_data = g_new0 (FormatData, 1);
        format_data->loop = loop;
        format_data->error = NULL;

        dialog = mdu_format_progress_dialog_new (NULL,
                                                 device,
                                                 _("Preparing..."));
        gtk_window_set_title (GTK_WINDOW (dialog), formatting_desc);
        gtk_widget_show_all (dialog);
        g_signal_connect (dialog, "response", G_CALLBACK (on_progress_dialog_response), format_data);

        /* first a small 2.5 sec window to allow the user to cancel before initiating */
        grace_timeout_id = g_timeout_add (2500, on_grace_timeout, format_data);
        g_main_loop_run (loop);
        g_source_remove (grace_timeout_id);
        if (format_data->error != NULL &&
            format_data->error->domain == G_IO_ERROR &&
            format_data->error->code == G_IO_ERROR_CANCELLED) {
                /* cancelled already, we are done */
                goto out;
        }

        /* then unmount the mount if needed; we use GIO for this to handle tearing
         * down LUKS; first determine the device to unmount
         */
        if (mdu_device_is_luks (device)) {
                const gchar *holder;
                holder = mdu_device_luks_get_holder (device);
                device_to_unmount = mdu_pool_get_by_object_path (pool, holder);
        } else {
                device_to_unmount = g_object_ref (device);
        }
        g_assert (device_to_unmount != NULL);
        gvolume_monitor = g_volume_monitor_get ();
        gvolumes = g_volume_monitor_get_volumes (gvolume_monitor);
        for (l = gvolumes; l != NULL; l = l->next) {
                GVolume *v = G_VOLUME (l->data);
                if (g_strcmp0 (g_volume_get_identifier (v, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
                               mdu_device_get_device_file (device_to_unmount)) == 0) {
                        gvolume = g_object_ref (v);
                        break;
                }
        }
        if (gvolume != NULL) {
                gmount = g_volume_get_mount (gvolume);
                if (gmount != NULL) {
                        GMountOperation *mount_op;

                        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                                             _("Unmounting..."));

                        mount_op = gtk_mount_operation_new (GTK_WINDOW (dialog));
                        g_mount_unmount_with_operation (gmount,
                                                        G_MOUNT_UNMOUNT_NONE,
                                                        mount_op,
                                                        NULL,
                                                        unmount_cb,
                                                        format_data);
                        g_object_unref (mount_op);
                        g_main_loop_run (format_data->loop);

                        if (format_data->error != NULL) {

                                if (!(format_data->error->domain == G_IO_ERROR &&
                                      format_data->error->code == G_IO_ERROR_FAILED_HANDLED)) {
                                        gchar *primary;

                                        primary = g_strdup_printf (_("Unable to format '%s'"), volume_name);
                                        show_error_dialog (NULL,
                                                           primary,
                                                           format_data->error->message);

                                        g_free (primary);
                                }
                                g_error_free (format_data->error);
                                goto out;
                        }
                }
        }

        /* and now, kick off the operation */
        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                             _("Formatting..."));
        mdu_device_op_filesystem_create (device,
                                         fs_type,
                                         fs_label,
                                         passphrase,
                                         take_ownership,
                                         fs_create_cb,
                                         format_data);
 again:
        g_main_loop_run (loop);
        if (format_data->error != NULL) {
                gtk_widget_destroy (dialog);
                dialog = NULL;

                if (format_data->error->domain == G_IO_ERROR &&
                    format_data->error->code == G_IO_ERROR_CANCELLED) {
                        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                                             _("Cancelling..."));

                        /* cancel the job; no callback since op_filesystem_create will return an error */
                        mdu_device_op_cancel_job (device,
                                                  NULL,
                                                  NULL);
                        goto again;

                } else {
                        show_error_dialog (NULL,
                                           _("Error formatting volume"),
                                           format_data->error->message);
                        g_error_free (format_data->error);
                }
                goto out;
        }

        /* ugh, DeviceKit-disks bug - spin around in the mainloop for some time to ensure we
         * have gotten all changes
         */
        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                             _("Mounting volume..."));
        g_timeout_add (1500, on_hack_timeout, loop);
        g_main_loop_run (loop);

        /* OK, peachy, now mount the volume and open a window */
        if (passphrase != NULL) {
                const gchar *cleartext_objpath;

                g_assert (mdu_device_is_luks (device));
                cleartext_objpath = mdu_device_luks_get_holder (device);
                device_to_mount = mdu_pool_get_by_object_path (pool, cleartext_objpath);
        } else {
                device_to_mount = g_object_ref (device);
        }

        mdu_device_op_filesystem_mount (device_to_mount,
                                        NULL,
                                        fs_mount_cb,
                                        format_data);
        g_main_loop_run (loop);
        gtk_widget_destroy (dialog);
        dialog = NULL;
        if (format_data->error != NULL) {
                show_error_dialog (NULL,
                                   _("Error mounting device"),
                                   format_data->error->message);
                g_error_free (format_data->error);
                goto out;
        }

        /* open file manager */
        launch_file_manager (format_data->mount_point);

        g_free (format_data->mount_point);

        /* save passphrase in keyring if requested */
        if (passphrase != NULL && (save_passphrase_in_keyring || save_passphrase_in_keyring_session)) {
                if (!mdu_util_save_secret (device,
                                           passphrase,
                                           save_passphrase_in_keyring_session)) {
                        show_error_dialog (NULL,
                                           _("Error storing passphrase in keyring"),
                                           "");
                        goto out;
                }
        }

        ret = 0;

 out:
        if (toplevel != NULL)
                g_object_unref (toplevel);
        g_free (drive_name);
        g_free (size_str);
        g_free (format_desc);
        g_free (formatting_desc);
        if (gmount != NULL)
                g_object_unref (gmount);
        if (gvolume != NULL)
                g_object_unref (gvolume);
        g_list_foreach (gvolumes, (GFunc) g_object_unref, NULL);
        if (gvolume_monitor != NULL)
                g_object_unref (gvolume_monitor);
        g_free (confirmation_secondary);
        g_free (volume_name);
        g_free (passphrase);
        g_free (fs_type);
        g_free (fs_label);
        g_free (device_file);
        if (loop != NULL)
                g_main_loop_unref (loop);
        if (dialog != NULL)
                gtk_widget_destroy (dialog);
        if (volume != NULL)
                g_object_unref (volume);
        if (device != NULL)
                g_object_unref (device);
        if (device_to_unmount != NULL)
                g_object_unref (device_to_unmount);
        if (device_to_mount != NULL)
                g_object_unref (device_to_mount);
        if (pool != NULL)
                g_object_unref (pool);
        if (format_data != NULL)
                g_free (format_data);
        return ret;
}
Exemplo n.º 30
0
void show_import_request_dialog(FRONTEND * fe) {
    /* import dialog -> dialog (OK, cancel), filename entry & browse */
    GtkWidget *dlg;
    GtkEntry *filename_entry;
    GtkButton *browse_button;
    GtkBox *box;
    int status;
    gint result;

    dlg =
        gtk_dialog_new_with_buttons("Import Request",
                                    GTK_WINDOW(fe->mainWindow),
                                    GTK_DIALOG_MODAL |
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
                                    GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
    box = GTK_BOX(gtk_hbox_new(0, 5));

    gtk_box_pack_start(box, gtk_label_new("Import from"), FALSE, FALSE, 0);
    filename_entry = GTK_ENTRY(gtk_entry_new());
    gtk_box_pack_start(box, GTK_WIDGET(filename_entry), FALSE, FALSE, 0);
    browse_button = GTK_BUTTON(gtk_button_new_with_mnemonic("_Browse..."));
    gtk_box_pack_start(box, GTK_WIDGET(browse_button), FALSE, FALSE, 0);
    g_signal_connect(G_OBJECT(browse_button), "clicked",
                     G_CALLBACK(on_browse_button_clicked), dlg);
    g_object_set_data_full(G_OBJECT(browse_button), "entry", filename_entry, NULL);     /* don't ref the entry -- same lifetime */
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), GTK_WIDGET(box), FALSE,
                       FALSE, 0);

    gtk_widget_show_all(GTK_WIDGET(GTK_DIALOG(dlg)->vbox));
    result = gtk_dialog_run(GTK_DIALOG(dlg));
    if (result == GTK_RESPONSE_ACCEPT) {
        CRYPT_CERTIFICATE request;
        gchar *filename;

        filename =
            g_filename_from_utf8(gtk_entry_get_text(filename_entry), -1, NULL,
                                 NULL, NULL);
        if (filename != NULL) {
            void *data;
            int data_len;
            data = lmz_file_read_full(filename, &data_len);
            if (data != NULL) {
                status =
                    cryptImportCert(data, data_len, CRYPT_UNUSED, &request);
                if (cryptStatusOK(status)) {
                    int id;
                    status = lmz_ca_add_request(fe->db, request, &id);
                    if (!cryptStatusOK(status)) {
                        show_error_dialog(NULL,
                                          "error adding request to db (cl err %d)",
                                          status);
                    }
                    else {
                        /* yay, it worked */
                        GtkTreeView *mainwin_req_tv, *mainwin_cert_tv;
                        mainwin_req_tv =
                            GTK_TREE_VIEW(g_object_get_data
                                          (G_OBJECT(fe->mainWindow),
                                           "request-list"));
                        mainwin_cert_tv =
                            GTK_TREE_VIEW(g_object_get_data
                                          (G_OBJECT(fe->mainWindow),
                                           "certificate-list"));
                        refresh_request_tree_view(mainwin_req_tv, fe);
                        refresh_cert_tree_view(mainwin_cert_tv, fe);
                    }
                    cryptDestroyCert(request);
                }
                else {
                    show_error_dialog(NULL,
                                      "error importing request (cl err %d)",
                                      status);
                }
                free(data);
            }
            else {
                show_error_dialog(NULL, "error reading file");
            }
            g_free(filename);
        }
        else {
        }
    }
    gtk_widget_destroy(dlg);
}