Beispiel #1
0
struct _list_char* load_list_from_file(const char *dir_name, const char *file_name)
{
	char *content = get_file_content_path(dir_name, file_name);
	if (content == NULL)
		return NULL;

	struct _list_char *data = list_char_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 #2
0
struct _list_char* list_char_clone(struct _list_char *list)
{
	struct _list_char *list_copy = list_char_init();

	for (int i = 0; i < list->data_count; i++)
		list_copy->add(list_copy, list->data[i].string);

	return list_copy;
}
Beispiel #3
0
struct _list_char* stringListToListChar(const QStringList& list)
{
  // Note that memory for the _list_char is allocated and must be freed manually
  _list_char* ret = list_char_init();

  for (int i = 0; i < list.size(); ++i)
    ret->add(ret, list[i].toLocal8Bit());

  return ret;
}
static char* keymap_keycode_to_symbol_real(struct _keymap *p, KeyCode kc, int group, int state)
{
	XEvent event;
	event.type		= KeyPress;
	event.xkey.type		= KeyPress;
	event.xkey.root		= RootWindow(p->display, DefaultScreen(p->display));
	event.xkey.subwindow	= None;
	event.xkey.same_screen	= True;
	event.xkey.display	= p->display;
	event.xkey.keycode = kc;
	event.xkey.state = 0;
	event.xkey.time		= CurrentTime;
	
	if (group >= 0)
		event.xkey.state = keyboard_groups[group];
	event.xkey.state |= state;

	char *symbol = (char *) malloc((256 + 1) * sizeof(char));
	symbol[0] = NULLSYM;
	
	int nbytes = XLookupString((XKeyEvent *) &event, symbol, 256, NULL, NULL);
		
	if (nbytes <= 0)
	{
		//log_message (TRACE, "Symbol at KeyCode %d not found on default locale.", kc);
		struct _list_char *locales = list_char_init();
		locales->add(locales, "C");
		locales->add(locales, "POSIX");

		
		/*FILE *fp = popen("locale -a", "r");
		if (fp != NULL)
		{
			char buffer[1024];

			while(fgets(buffer, 1024, fp) != NULL)
			{
				buffer[strlen(buffer) - 1] = NULLSYM;
				//log_message(ERROR, "%s", buffer);
				locales->add(locales, buffer);
			}
			pclose(fp);
		}*/

		//log_message(ERROR, _("Not find symbol for keycode %d and modifier 0x%x!"), event.xkey.keycode, event.xkey.state);
		
		for (int i = 0; i < locales->data_count; i++)
		{
			if (setlocale(LC_ALL, locales->data[i].string) != NULL)
			{
				//log_message (TRACE, "Check symbol at KeyCode %d on locale %c!", kc, locales->data[i].string);
				event.xkey.root		= RootWindow(p->display, DefaultScreen(p->display));
				event.xkey.display  = p->display;
				nbytes = XLookupString((XKeyEvent *) &event, symbol, 256, NULL, NULL);
				
				setlocale(LC_ALL, ""); 
				
				if (nbytes > 0)
				{
					symbol[nbytes] = NULLSYM;
					locales->uninit(locales);
					//log_message (TRACE, "Found symbol '%s' at KeyCode %d on locale %c!", symbol, kc, locales->data[i].string);
					return symbol;
				}
			}
		}

		log_message(ERROR, _("Failed to look up symbol for keycode %d and modifier 0x%x!"), event.xkey.keycode, event.xkey.state);
		log_message(ERROR, _("Try run the program with command \"env LC_ALL=<LOCALE> %s\", \nwhere LOCALE available over command \"locale -a\""), PACKAGE);
		symbol[0] = NULLSYM;
		strcat(symbol, " ");

		locales->uninit(locales);
		
	}
	else
	{
		symbol[nbytes] = NULLSYM;
		//log_message (TRACE, "Found symbol '%s' at KeyCode %d on default locale!", symbol, kc);
	}
	
	return symbol;
}
Beispiel #5
0
void xneur_save_preference(void)
{
	GtkWidget *widgetPtrToBefound1;
	GtkWidget *widgetPtrToBefound3;
		
	widgetPtrToBefound1 = lookup_widget(wPreference, "combobox1");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound1)) == 0)
		xconfig->xneur_data->xneur_mode = AUTO_MODE;
	else
		xconfig->xneur_data->xneur_mode = MANUAL_MODE;
		
	int total_lang = 0;
	char **lang_name = malloc(4 * sizeof(char*));
	char **lang_dir = malloc(4 * sizeof(char*)); 
	int *lang_group = malloc(4 * sizeof(int));
	
	widgetPtrToBefound1 = lookup_widget(wPreference, "combobox21");
	widgetPtrToBefound3 = lookup_widget(wPreference, "combobox13");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound1)) > 0)
	{
		lang_name[total_lang] = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widgetPtrToBefound1));
		lang_dir[total_lang] = get_dir_by_index(gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound1)));
		lang_group[total_lang] = gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound3));
		total_lang++;
	}
	
	widgetPtrToBefound1 = lookup_widget(wPreference, "combobox22");
	widgetPtrToBefound3 = lookup_widget(wPreference, "combobox14");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound1)) > 0)
	{
		lang_name[total_lang] = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widgetPtrToBefound1));
		lang_dir[total_lang] = get_dir_by_index(gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound1)));
		lang_group[total_lang] = gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound3));
		total_lang++;
	}
	
	widgetPtrToBefound1 = lookup_widget(wPreference, "combobox23");
	widgetPtrToBefound3 = lookup_widget(wPreference, "combobox15");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound1)) > 0)
	{
		lang_name[total_lang] = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widgetPtrToBefound1));
		lang_dir[total_lang] = get_dir_by_index(gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound1)));
		lang_group[total_lang] = gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound3));
		total_lang++;
	}
	
	widgetPtrToBefound1 = lookup_widget(wPreference, "combobox24");
	widgetPtrToBefound3 = lookup_widget(wPreference, "combobox16");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound1)) > 0)
	{
		lang_name[total_lang] = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widgetPtrToBefound1));
		lang_dir[total_lang] = get_dir_by_index(gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound1)));
		lang_group[total_lang] = gtk_combo_box_get_active(GTK_COMBO_BOX(widgetPtrToBefound3));
		total_lang++;
	}

	xconfig->set_languages(xconfig, lang_name, lang_dir, lang_group, total_lang);

	xconfig->excluded_apps->uninit(xconfig->excluded_apps);
	xconfig->excluded_apps = list_char_init();

	gtk_tree_model_foreach(GTK_TREE_MODEL(store_exclude_app), save_exclude_app, NULL);
		
	xconfig->auto_apps->uninit(xconfig->auto_apps);
	xconfig->auto_apps = list_char_init();

	gtk_tree_model_foreach(GTK_TREE_MODEL(store_auto_app), save_auto_app, NULL);
		
	xconfig->manual_apps->uninit(xconfig->manual_apps);
	xconfig->manual_apps = list_char_init();

	gtk_tree_model_foreach(GTK_TREE_MODEL(store_manual_app), save_manual_app, NULL);

	fill_binds(0, "combobox10", "combobox3", FALSE);
	fill_binds(1, "combobox11", "combobox5", FALSE);
	fill_binds(2, "combobox6", "combobox7", FALSE);
	fill_binds(3, "combobox8", "combobox9", FALSE);
	fill_binds(4, "combobox17", "combobox18", FALSE);
	fill_binds(5, "combobox19", "combobox20", FALSE);

	widgetPtrToBefound1 = lookup_widget(wPreference, "checkbutton1");
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widgetPtrToBefound1)))
		xconfig->mouse_processing_mode = MOUSE_GRAB_ENABLE;
	else
		xconfig->mouse_processing_mode = MOUSE_GRAB_DISABLE;
		
	widgetPtrToBefound1 = lookup_widget(wPreference, "checkbutton2");
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widgetPtrToBefound1)))
		xconfig->education_mode = EDUCATION_MODE_ENABLE;
	else
		xconfig->education_mode = EDUCATION_MODE_DISABLE;

	widgetPtrToBefound1 = lookup_widget(wPreference, "checkbutton3");
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widgetPtrToBefound1)))
		xconfig->layout_remember_mode = LAYOUTE_REMEMBER_ENABLE;
	else
		xconfig->layout_remember_mode = LAYOUTE_REMEMBER_DISABLE;
		
	widgetPtrToBefound1 = lookup_widget(wPreference, "checkbutton4");
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widgetPtrToBefound1)))
		xconfig->save_selection_mode = SELECTION_SAVE_ENABLED;
	else
		xconfig->save_selection_mode = SELECTION_SAVE_DISABLED;
		
	gtk_widget_destroy(wPreference);

	xconfig->save(xconfig);
	xconfig->reload_config(xconfig);
}