Beispiel #1
0
void save_as_dialog(){
	char *pth = NULL, *nam = NULL;
	dialog = gtk_file_chooser_dialog_new ("Сохранить пазл как",
						(GtkWindow *)window,
						GTK_FILE_CHOOSER_ACTION_SAVE,
						GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
						GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
						NULL);
	gtk_file_chooser_set_do_overwrite_confirmation (
										GTK_FILE_CHOOSER (dialog), TRUE);
	if(last_opened_file){
		pth = get_file_path_name(last_opened_file, TRUE);
		nam = get_file_path_name(last_opened_file, FALSE);
		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), pth);
		gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), nam);
	}
	else
		gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog),
														NEW_FILE_NAME);
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT){
		if(last_opened_file) free(last_opened_file);
		last_opened_file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
	}
	gtk_widget_destroy (dialog);
	if(pth) free(pth); if(nam) free(nam);
}
Beispiel #2
0
struct _list* load_file_to_list(const char *dir_name, const char *file_name)
{
	char *file_path_name = get_file_path_name(dir_name, file_name);
	char *content = get_file_content(file_path_name);

	free(file_path_name);
	if (content == NULL)
		return NULL;

	struct _list *data = list_init();

	int len = strlen(content);

	int sym, last_sym = 0;
	for (sym = 0; sym < len; sym++)
	{
		if (content[sym] != '\n')
			continue;

		if (last_sym == sym)
		{
			last_sym++;
			continue;
		}

		content[sym] = '\0';
		data->add(data, content + last_sym);

		last_sym = sym + 1;
	}

	free(content);
	return data;
}
Beispiel #3
0
void xneur_set_lock(void)
{
	int xneur_pid = getpid();

	char *lock_file = get_file_path_name(LOCK_FILE);
	if (xneur_check_lock_exists(lock_file))
	{
		free(lock_file);
		exit(EXIT_FAILURE);
	}

	FILE *fpid = fopen(lock_file, "w");
	if (!fpid)
	{
		log_message(ERROR, "Failed to create lock file %s", lock_file);
		free(lock_file);
		exit(EXIT_FAILURE);
	}

	fprintf(fpid, "%d", xneur_pid);
	fclose(fpid);

	log_message(LOG, "Set PID %d to lock file %s", xneur_pid, lock_file);
	free(lock_file);
}
Beispiel #4
0
char* get_file_content_path(const char *dir_name, const char *file_name)
{
	char *file_path_name = get_file_path_name(dir_name, file_name);

	char *content = get_file_content(file_path_name);

	free(file_path_name);

	return content;
}
Beispiel #5
0
void open_file_dialog(){
	char *pth = NULL;
	dialog = gtk_file_chooser_dialog_new ("Открыть пазл", (GtkWindow *)window,
						GTK_FILE_CHOOSER_ACTION_OPEN,
						GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
						GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
						NULL);
	gtk_my_patter_add(dialog, "Japanes puzzle", "*.jc[r,c]");
	gtk_my_patter_add(dialog, "All files (*.*)", "*");

	if(last_opened_file){
		pth = get_file_path_name(last_opened_file, TRUE);
		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), pth);
	}
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT){
		if(last_opened_file) free(last_opened_file);
		last_opened_file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
	}
	gtk_widget_destroy (dialog);
	if(pth) free(pth);
}