Ejemplo n.º 1
0
static void
cycle_focus (GiggleCloneDialog *dialog, GtkWidget *widget)
{
	GtkWidget *next_widget = NULL;

	if (input_is_valid (dialog))
		next_widget = dialog->priv->clone_button;
	else if (widget == dialog->priv->remote_entry)
		next_widget = dialog->priv->local_entry;

	if (next_widget)
		gtk_widget_grab_focus (next_widget);
}
Ejemplo n.º 2
0
static void
clone_repository (GiggleCloneDialog *dialog, GtkButton *button)
{
	GiggleJob *job;
	GtkFileChooser *chooser;
	const gchar  *repo, *name;
	gchar *base;

	if (input_is_valid (dialog) == FALSE) {
		warning_dialog (GTK_WINDOW (dialog));
		return;
	}

	gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
	gtk_widget_set_sensitive (dialog->priv->remote_entry, FALSE);
	gtk_widget_set_sensitive (dialog->priv->local_entry, FALSE);
	gtk_widget_set_sensitive (dialog->priv->folder_button, FALSE);

	dialog->priv->pulse_timeout_id = g_timeout_add (100,
	                                                update_progress_bar,
	                                                dialog);

	chooser = GTK_FILE_CHOOSER (dialog->priv->folder_button);
	base = gtk_file_chooser_get_filename (chooser);

	name = gtk_entry_get_text (GTK_ENTRY (dialog->priv->local_entry));
	repo = gtk_entry_get_text (GTK_ENTRY (dialog->priv->remote_entry));

	dialog->priv->git_directory = g_build_filename (base, name, NULL);
	g_free (base);

	job = giggle_git_clone_new (repo, dialog->priv->git_directory);

	giggle_git_run_job (dialog->priv->git, job,
	                    clone_repository_finished, dialog);
}
Ejemplo n.º 3
0
static void
verify_input (GiggleCloneDialog *dialog, GtkEditable *editable)
{
	gtk_widget_set_sensitive (dialog->priv->clone_button,
	                          input_is_valid (dialog));
}
Ejemplo n.º 4
0
int
main (int argc, char *argv[])
{
	GOptionContext *opt_context;
	GError *error;
	GMainLoop *loop;
	GDBusServer *server;
	gchar *guid;
	GDBusServerFlags server_flags;

	gchar *action;
	gchar *message;
	gint ret;

	introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
	g_assert (introspection_data != NULL);
	users = g_array_new (FALSE,TRUE,sizeof (GUser));

	guid = g_dbus_generate_guid ();
	server_flags = G_DBUS_SERVER_FLAGS_NONE;
	ret = 1;
	g_type_init ();
	error = NULL;

	opt_context = g_option_context_new ("ksr-chat-server() usage:");
	g_option_context_set_summary (opt_context,
									"To start a local server located under tcp:host=0.0.0.0, use:\n"
									"  \"ksr-chat-server -a tcp:host=0.0.0.0\"");

	g_option_context_add_main_entries (opt_context, opt_entries, NULL);

	if (!g_option_context_parse (opt_context, &argc, &argv, &error))
	{
		g_printerr ("Error parsing options: %s\n", error->message);
		goto out;
	}

	if (!input_is_valid())
		goto out;

	server = g_dbus_server_new_sync (opt_address,
										server_flags,
										guid,
										NULL, /* GDBusAuthObserver */
										NULL, /* GCancellable */
										&error);

	g_dbus_server_start (server);
	g_free (guid);

	if (server == NULL)
	{
		g_printerr ("Error creating server at address %s: %s\n", opt_address, error->message);
		g_error_free (error);
		goto out;
	}

	g_print ("Server is listening at: %s\n", g_dbus_server_get_client_address (server));
	g_signal_connect (server,
						"new-connection",
						G_CALLBACK (on_new_connection),
						NULL);

	loop = g_main_loop_new (NULL, FALSE);

	g_main_loop_run (loop);

	g_main_loop_unref (loop);

	ret = 0;

	out:
	return ret;
}
Ejemplo n.º 5
0
void sim_input_test (char lign[220], int *status, int *ptr)
{
	int j;
	
	switch (*status)
	{
		case CLOCK:
			if ( sscanf (lign, "%d", &horloge) )
			{
				if ( test_clock (horloge) )
				{
					sim_save_time (horloge);
					*status=OASIS_SIZE_PARAMETER;
					break;
				}
				
				else 
				{
					*status=EXIT;
					break;
				}
			}
			
			else 
			{
				error_missing_time();
				*status = EXIT;
				break;
			}
		
		case OASIS_SIZE_PARAMETER:
			if ( (sscanf(lign, "%d", &oasis)) )
			{
				if ( (test_oasis_size_parameter (oasis) ) )
				{
					oasis = 2*(oasis) + 1;
					sim_save_oasis(oasis);
					cell_create_tab(oasis);
					*status=OASIS;
					i=0;
					break;
				}
				
				else 
				{
					*status=EXIT;
					break;
				}
				
			}
			
			else 
			{
				error_missing_map_size();
				*status=EXIT;
				break;
			}
			
		case OASIS:
			for (j=0; j<oasis;j++)
			{
				if ( (sscanf (lign, "%c", &c_cell) ) )
				{
					if ( (test_oasis_cell(c_cell, i, j)) )
					{
						cell_add(oasis-1+DESERT_SIZE-i, j+DESERT_SIZE, c_cell);
						c_cell=0;
						lign++;
					}
					
					else
					{
						*status=EXIT;
						break;
					}	
				}
			}
			
			i++;
			
			if (i==oasis) 
			{
				*status = PREY_NUMBER;
				i=0;
				break;
			}
			
			break;
			
		case PREY_NUMBER:
			if( (sscanf(lign, "%d", &prey_nb)) && (test_number (prey_nb, PREY_NUMBER, oasis) ) )
			{
				sim_save_prey_nb(prey_nb);
				*status=PREY_COORDINATES;
				break;
			}
			 
			else 
			{
				error_missing_prey_number();
				*status=EXIT;
				break;
			}
			
		case PREY_COORDINATES:
			if ( (sscanf (lign, " %d %d %d %f ", &prey_x, &prey_y, &prey_bool, &prey_energy)) )
			{				
				if(test_coordinates (i, prey_nb, oasis, PREY_COORDINATES, prey_x, prey_y, prey_energy))
				{
					prey_add(prey_x, prey_y, prey_bool, prey_energy);
				
					if (i==prey_nb-1)
					{
						i=0;
						*status=PREDATOR_NUMBER;
						break;
					}
					
					if (i<prey_nb-1)
					{
						i++;
						break;
					}
				}
				
				else 
				{
					*status=EXIT;
					break;
				}
			}
			
			else 
			{
				*status = EXIT;
				break; 
			}
			
		
		case PREDATOR_NUMBER:
			if( (sscanf(lign, "%d", &pred_nb)) && (test_number (pred_nb, PREDATOR_NUMBER, oasis) ) )
			{
				sim_save_pred_nb(pred_nb);
				*status=PREDATOR_COORDINATES;
				break;
			}
			 
			else 
			{
				error_missing_predator_number();
				*status=EXIT;
				break;
			}
			
		case PREDATOR_COORDINATES:	
			if ( (sscanf (lign, " %d %d %f ", &pred_x, &pred_y, &pred_energy)) )
			{		
				pred_add(pred_x, pred_y, pred_energy);
				
				(*ptr)++;

				if(test_coordinates (i, pred_nb, oasis, PREDATOR_COORDINATES, pred_x, pred_y, pred_energy))
				{
					if (i==pred_nb-1)
					{
						input_is_valid();
						*status=CORRECT;
						break;
					}
					
					if (i<pred_nb-1)
					{
						i++;	
					}
				}
				
				else 
				{
					*status=EXIT;
					break;
				}
			}
			
			else 
			{
				*status = EXIT;
				break; 
			}
			
		case EXIT:
			break;
	}
	
}
Ejemplo n.º 6
0
int
main (int argc, char *argv[])
{
	GOptionContext *opt_context;
	GError *error;
	GDBusConnectionFlags connection_flags;
	GIOChannel *io_channel;
	GDBusProxyFlags proxy_flags;
	GDBusMessage *message;
	GVariant *value;
	gchar *client_ident;
	gchar *input;
	gchar *response;
	gsize *len;
	gint ret,ret_loc;

	ret = 1;
	g_type_init ();
	error = NULL;
	object_path = NULL;

	opt_context = g_option_context_new ("ksr-chat-client() usage:");
	g_option_context_set_summary (opt_context,
									"To connect to server under tcp:host=0.0.0.0 as \"maryl\" and start chatting, use:\n"
									"  \"ksr-chat-client -n maryl -a tcp:host=0.0.0.0");
	g_option_context_add_main_entries (opt_context, opt_entries, NULL);

	if (!g_option_context_parse (opt_context, &argc, &argv, &error))
	{
		g_printerr ("Error parsing options: %s\n", error->message);
		g_error_free (error);
		goto out;
	}

	if (!input_is_valid())
		goto out;

	connection_flags = G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT;

	connection = g_dbus_connection_new_for_address_sync (opt_address,
														   connection_flags,
														   NULL, /* GDBusAuthObserver */
														   NULL, /* GCancellable */
														   &error);

	if (connection == NULL)
	{
		g_printerr ("Error connecting to the DBus : %s\n", error->message);
		g_error_free(error);
		goto out;
	}

	g_print ("Connected to server!\n");

	disallowed_chars = g_regex_new("\n", 0, 0, NULL);
	object_path = g_strdup_printf ("%s/%s", OBJECT_PATH,opt_name);

	// Now register the nickname
	error = NULL;
	value = g_dbus_connection_call_sync (connection,
											   NULL,
											   TMP_OBJECT_PATH,
											   INTERFACE_PATH,
											   "RegisterMe",
											   g_variant_new ("(s)", opt_name),
											   NULL,
											   G_DBUS_CALL_FLAGS_NONE,
											   -1,
											   NULL,
											   &error);

	if (value == NULL)
	{
		g_printerr ("Could not register!\n");
		goto out;
	}
	else
	{
		g_variant_get (value, "(&s)", &response);
		if (g_strcmp0(response,REGISTRATION_RESPONSE_OK) == 0)
			g_print ("Registered a nickname %s , the chat is ready!\n",opt_name);
		else if (g_strcmp0(response,REGISTRATION_RESPONSE_NOT_OK) == 0)
		{
			g_print ("Could not register your nickname %s, please change it!\n",opt_name);
			goto out;
		}
	}

	g_dbus_connection_signal_subscribe(connection,
										NULL,
										INTERFACE_PATH,
										NULL,
										NULL,
										NULL,
										G_DBUS_SIGNAL_FLAGS_NONE,
										handle_signals,
										NULL,
										NULL);

	loop = g_main_loop_new (NULL, FALSE);

	// FD = 0 = stdin
	io_channel = g_io_channel_unix_new(0);

	if (!g_io_add_watch_full (io_channel, G_PRIORITY_HIGH, G_IO_IN, handle_input, NULL, NULL))
			g_error ("Cannot add watch on GIOChannel!\n");

	g_main_loop_run (loop);

	ret = 0;

	out:
	g_option_context_free (opt_context);
	return ret;
}