Beispiel #1
0
Datei: fkeys.c Projekt: n2i/xvnkb
static int
key_action_tab_comp (GtkWidget *t, GdkEventKey *entry, char *d1, char *d2,
							struct session *sess)
{
	int len = 0, elen = 0, i = 0, cursor_pos, ent_start = 0, comp = 0, found = 0,
	    prefix_len, skip_len = 0, is_nick, is_cmd = 0;
	char buf[COMP_BUF], ent[CHANLEN], *postfix = NULL, *result, *ch;
	GList *list = NULL, *tmp_list = NULL;
	const char *text;
	GCompletion *gcomp = NULL;

	/* force the IM Context to reset */
	SPELL_ENTRY_SET_EDITABLE (t, FALSE);
	SPELL_ENTRY_SET_EDITABLE (t, TRUE);

	text = SPELL_ENTRY_GET_TEXT (t);
	if (text[0] == 0)
		return 1;

	len = g_utf8_strlen (text, -1); /* must be null terminated */

	cursor_pos = SPELL_ENTRY_GET_POS (t);

	buf[0] = 0; /* make sure we don't get garbage in the buffer */

	/* handle "nick: " or "nick " or "#channel "*/
	ch = g_utf8_find_prev_char(text, g_utf8_offset_to_pointer(text,cursor_pos));
	if (ch && ch[0] == ' ')
	{
		skip_len++;
		ch = g_utf8_find_prev_char(text, ch);
		if (!ch)
			return 2;

		cursor_pos = g_utf8_pointer_to_offset(text, ch);
		if (cursor_pos && (g_utf8_get_char_validated(ch, -1) == ':' || 
					g_utf8_get_char_validated(ch, -1) == ',' ||
					g_utf8_get_char_validated(ch, -1) == prefs.nick_suffix[0]))
		{
			skip_len++;
		}
		else
			cursor_pos = g_utf8_pointer_to_offset(text, g_utf8_offset_to_pointer(ch, 1));
	}

	comp = skip_len;
	
	/* store the text following the cursor for reinsertion later */
	if ((cursor_pos + skip_len) < len)
		postfix = g_utf8_offset_to_pointer(text, cursor_pos + skip_len);

	for (ent_start = cursor_pos; ; --ent_start)
	{
		if (ent_start == 0)
			break;
		ch = g_utf8_offset_to_pointer(text, ent_start - 1);
		if (ch && ch[0] == ' ')
			break;
	}

	if (ent_start == 0 && text[0] == prefs.cmdchar[0])
	{
		ent_start++;
		is_cmd = 1;
	}
	
	prefix_len = ent_start;
	elen = cursor_pos - ent_start;

	g_utf8_strncpy (ent, g_utf8_offset_to_pointer (text, prefix_len), elen);

	is_nick = (ent[0] == '#' || ent[0] == '&' || is_cmd) ? 0 : 1;
	
	if (sess->type == SESS_DIALOG && is_nick)
	{
		/* tab in a dialog completes the other person's name */
		if (rfc_ncasecmp (sess->channel, ent, elen) == 0)
		{
			result =  sess->channel;
			is_nick = 0;
		}
		else
			return 2;
	}
	else
	{
		if (is_nick)
		{
			gcomp = g_completion_new((GCompletionFunc)gcomp_nick_func);
			tmp_list = userlist_double_list(sess); /* create a temp list so we can free the memory */
			if (prefs.completion_sort == 1)	/* sort in last-talk order? */
				tmp_list = g_list_sort (tmp_list, (void *)talked_recent_cmp);
		}
		else
		{
			gcomp = g_completion_new (NULL);
			if (is_cmd)
			{
				tmp_list = cmdlist_double_list (command_list);
				for(i = 0; xc_cmds[i].name != NULL ; i++)
				{
					tmp_list = g_list_prepend (tmp_list, xc_cmds[i].name);
				}
				tmp_list = plugin_command_list(tmp_list);
			}
			else
				tmp_list = chanlist_double_list (sess_list);
		}
		tmp_list = g_list_reverse(tmp_list); /* make the comp entries turn up in the right order */
		g_completion_set_compare (gcomp, (GCompletionStrncmpFunc)rfc_ncasecmp);
		if (tmp_list)
		{
			g_completion_add_items (gcomp, tmp_list);
			g_list_free (tmp_list);
		}

		if (comp && !(rfc_ncasecmp(old_gcomp.data, ent, old_gcomp.elen) == 0))
		{
			key_action_tab_clean ();
			comp = 0;
		}
	
#if GLIB_CHECK_VERSION(2,4,0)
		list = g_completion_complete_utf8 (gcomp, comp ? old_gcomp.data : ent, &result);
#else
		list = g_completion_complete (gcomp, comp ? old_gcomp.data : ent, &result);
#endif
		
		if (result == NULL) /* No matches found */
		{
			g_completion_free(gcomp);
			return 2;
		}

		if (comp) /* existing completion */
		{
			while(list) /* find the current entry */
			{
				if(rfc_ncasecmp(list->data, ent, elen) == 0)
				{
					found = 1;
					break;
				}
				list = list->next;
			}

			if (found)
			{
				if (!(d1 && d1[0])) /* not holding down shift */
				{
					if (g_list_next(list) == NULL)
						list = g_list_first(list);
					else
						list = g_list_next(list);
				}
				else
				{
					if (g_list_previous(list) == NULL)
						list = g_list_last(list);
					else
						list = g_list_previous(list);
				}
				g_free(result);
				result = (char*)list->data;
			}
			else
			{
				g_free(result);
				g_completion_free(gcomp);
				return 2;
			}
		}
		else
		{
			strcpy(old_gcomp.data, ent);
			old_gcomp.elen = elen;

			/* Get the first nick and put out the data for future nickcompletes */
			if (prefs.completion_amount && g_list_length (list) <= prefs.completion_amount)
			{
				g_free(result);
				result = (char*)list->data;
			}
			else
			{
				/* bash style completion */
				if (g_list_next(list) != NULL)
				{
					if (strlen (result) > elen) /* the largest common prefix is larger than nick, change the data */
					{
						if (prefix_len)
							g_utf8_strncpy (buf, text, prefix_len);
						strncat (buf, result, COMP_BUF - prefix_len);
						cursor_pos = strlen (buf);
						g_free(result);
#if !GLIB_CHECK_VERSION(2,4,0)
						g_utf8_validate (buf, -1, (const gchar **)&result);
						(*result) = 0;
#endif
						if (postfix)
						{
							strcat (buf, " ");
							strncat (buf, postfix, COMP_BUF - cursor_pos -1);
						}
						SPELL_ENTRY_SET_TEXT (t, buf);
						SPELL_ENTRY_SET_POS (t, g_utf8_pointer_to_offset(buf, buf + cursor_pos));
						buf[0] = 0;
					}
					else
						g_free(result);
					while (list)
					{
						len = strlen (buf);	/* current buffer */
						elen = strlen (list->data);	/* next item to add */
						if (len + elen + 2 >= COMP_BUF) /* +2 is space + null */
						{
							PrintText (sess, buf);
							buf[0] = 0;
							len = 0;
						}
						strcpy (buf + len, (char *) list->data);
						strcpy (buf + len + elen, " ");
						list = list->next;
					}
					PrintText (sess, buf);
					g_completion_free(gcomp);
					return 2;
				}
				/* Only one matching entry */
				g_free(result);
				result = list->data;
			}
		}
	}
	
	if(result)
	{
		if (prefix_len)
			g_utf8_strncpy(buf, text, prefix_len);
		strncat (buf, result, COMP_BUF - (prefix_len + 3)); /* make sure nicksuffix and space fits */
		if(!prefix_len && is_nick)
			strcat (buf, &prefs.nick_suffix[0]);
		strcat (buf, " ");
		cursor_pos = strlen (buf);
		if (postfix)
			strncat (buf, postfix, COMP_BUF - cursor_pos - 2);
		SPELL_ENTRY_SET_TEXT (t, buf);
		SPELL_ENTRY_SET_POS (t, g_utf8_pointer_to_offset(buf, buf + cursor_pos));
	}
	if (gcomp)
		g_completion_free(gcomp);
	return 2;
}
Beispiel #2
0
static void add_dict_buttons(GtkWidget *bar)
{
	GtkWidget *toggle;
	GtkWidget *label;
	int idx;
	char name[64];
	char buff[256];

	GtkTreeIter   parent_iter;
	GtkTreeIter   child_iter;

	LOG(LOG_DEBUG, "IN : add_dict_buttons()");

	idx = 0;

	if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dict_store), &parent_iter) == TRUE){
		do { 
			gchar *title;
			gchar *fg, *bg;
			gboolean active;
			BOOK_INFO *binfo;
			gchar *tip_string;

			gtk_tree_model_get (GTK_TREE_MODEL(dict_store), 
					    &parent_iter, 
					    DICT_ACTIVE_COLUMN, &active,
					    -1);
			if(active == TRUE) {
				if(idx != 0){
					LOG(LOG_CRITICAL, "multipe group active");
					return;
				}

				if(gtk_tree_model_iter_children(GTK_TREE_MODEL(dict_store), &child_iter, &parent_iter) == TRUE){
					do {
						gtk_tree_model_get(GTK_TREE_MODEL(dict_store),
								   &child_iter,
								   DICT_TITLE_COLUMN, &title,
								   DICT_ACTIVE_COLUMN, &active,
								   DICT_MEMBER_COLUMN, &binfo,
								   DICT_FGCOLOR_COLUMN, &fg,
								   DICT_BGCOLOR_COLUMN, &bg,
								   -1);

						if(binfo == NULL) {
							continue;
						}

						g_utf8_strncpy(name, title, dict_button_length);
						if(fg == NULL) {
							if(bg == NULL)
								sprintf(buff, "%s", name);
							else
								sprintf(buff, "<span background=\"%s\">%s</span>",  bg, name);
						} else {
							if(bg == NULL)
								sprintf(buff, "<span foreground=\"%s\">%s</span>", fg, name);
							else
								sprintf(buff, "<span foreground=\"%s\" background=\"%s\">%s</span>", fg, bg, name);
						}

						toggle = gtk_toggle_button_new();
						if(benable_button_color)						
							label = gtk_label_new(buff);
						else 
							label = gtk_label_new(name);
						gtk_label_set_use_markup (GTK_LABEL (label), TRUE);

						gtk_container_add (GTK_CONTAINER (toggle), label);

						gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), active);
						g_signal_connect(G_OBJECT(toggle),"toggled",
								 G_CALLBACK(dict_toggled),
								 (gpointer)idx);
				
						gtk_box_pack_start(GTK_BOX(bar), toggle, FALSE, FALSE, 2);
						if(binfo->available == FALSE) {
							gtk_widget_set_sensitive(toggle, FALSE);
						}

						tip_string = g_strconcat(_("Push to enable this dictionary."), "\n(", title, ")", NULL);
						gtk_tooltips_set_tip(tooltip, toggle, tip_string, "Private");
						g_free(tip_string);
						g_free(title);

						idx ++;

					} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(dict_store), &child_iter) == TRUE);
				}
			}
	       } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(dict_store), &parent_iter) == TRUE);
	}

	LOG(LOG_DEBUG, "OUT : add_dict_buttons()");
}
Beispiel #3
0
static void _lib_recentcollection_updated(gpointer instance, gpointer user_data)
{
  dt_lib_module_t *self =(dt_lib_module_t *)user_data;
  dt_lib_recentcollect_t *d = (dt_lib_recentcollect_t *)self->data;
  // serialize, check for recently used
  char confname[200];
  const int bufsize = 4096;
  char buf[bufsize];
  if(dt_collection_serialize(buf, bufsize)) return;

  // is the current position, i.e. the one to be stored with the old collection (pos0, pos1-to-be)
  uint32_t curr_pos = 0;
  if(d->inited)
  {
    curr_pos = dt_view_lighttable_get_position(darktable.view_manager);
    dt_conf_set_int("plugins/lighttable/recentcollect/pos0", curr_pos);
  }
  else
  {
    curr_pos = dt_conf_get_int("plugins/lighttable/recentcollect/pos0");
    d->inited = 1;
  }
  uint32_t new_pos = 0;

  int n = -1;
  for(int k=0; k<CLAMPS(dt_conf_get_int("plugins/lighttable/recentcollect/num_items"), 0, NUM_LINES); k++)
  {
    // is it already in the current list?
    snprintf(confname, 200, "plugins/lighttable/recentcollect/line%1d", k);
    gchar *line = dt_conf_get_string(confname);
    if(!line) continue;
    if(!strcmp(line, buf))
    {
      snprintf(confname, 200, "plugins/lighttable/recentcollect/pos%1d", k);
      new_pos = dt_conf_get_int(confname);
      n = k;
      break;
    }
    g_free(line);
  }
  if(n < 0)
  {
    const int num_items = CLAMPS(dt_conf_get_int("plugins/lighttable/recentcollect/num_items"), 0, NUM_LINES);
    if(num_items < NUM_LINES)
    {
      // new, unused entry
      n = num_items;
      dt_conf_set_int("plugins/lighttable/recentcollect/num_items", num_items + 1);
    }
    else
    {
      // kill least recently used entry:
      n = num_items - 1;
    }
  }
  if(n >= 0 && n < NUM_LINES)
  {
    // sort n to the top
    for(int k=n; k>0; k--)
    {
      snprintf(confname, 200, "plugins/lighttable/recentcollect/line%1d", k-1);
      gchar *line1 = dt_conf_get_string(confname);
      snprintf(confname, 200, "plugins/lighttable/recentcollect/pos%1d", k-1);
      uint32_t pos1 = dt_conf_get_int(confname);
      if(line1 && line1[0] != '\0')
      {
        snprintf(confname, 200, "plugins/lighttable/recentcollect/line%1d", k);
        dt_conf_set_string(confname, line1);
        snprintf(confname, 200, "plugins/lighttable/recentcollect/pos%1d", k);
        dt_conf_set_int(confname, pos1);
      }
      g_free(line1);
    }
    dt_conf_set_string("plugins/lighttable/recentcollect/line0", buf);
    dt_conf_set_int("plugins/lighttable/recentcollect/pos0", new_pos);
  }
  // update button descriptions:
  for(int k=0; k<NUM_LINES; k++)
  {
    char str[200] = {0};
    char str_cut[200] = {0};
    char str_pretty[200] = {0};

    snprintf(confname, 200, "plugins/lighttable/recentcollect/line%1d", k);
    gchar *buf = dt_conf_get_string(confname);
    if(buf && buf[0] != '\0')
    {
      pretty_print(buf, str);
      g_free(buf);
    }
    g_object_set(G_OBJECT(d->item[k].button), "tooltip-text", str, (char *)NULL);
    const int cut = 45;
    if (g_utf8_strlen(str, -1) > cut)
    {
      g_utf8_strncpy(str_cut, str, cut);
      snprintf(str_pretty, 200, "%s...", str_cut);
      gtk_button_set_label(GTK_BUTTON(d->item[k].button), str_pretty);
    }
    else
    {
      gtk_button_set_label(GTK_BUTTON(d->item[k].button), str);
    }
    gtk_widget_set_no_show_all(d->item[k].button, TRUE);
    gtk_widget_set_visible(d->item[k].button, FALSE);
  }
  for(int k=0; k<CLAMPS(dt_conf_get_int("plugins/lighttable/recentcollect/num_items"), 0, NUM_LINES); k++)
  {
    gtk_widget_set_no_show_all(d->item[k].button, FALSE);
    gtk_widget_set_visible(d->item[k].button, TRUE);
  }
  dt_view_lighttable_set_position(darktable.view_manager, new_pos);
}
Beispiel #4
0
/* set the type of the token returned in string in returned_type */
void get_random_token(int token_type, gint *returned_type, gchar **string, gchar **second_value)
{
  gchar *result = NULL;
  gchar *second = NULL;
  gboolean skip;

  gint max_token;
  gint j, i, k;
  gint type;

  typedef struct {
    gint bound;
    gint type;
  } DATUM ;

  GList *data= NULL;
  GList *list;

  max_token = 0;

  if (token_type & TYPE_IMAGE){
    max_token += NUMBER_OF_IMAGES;

    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =  TYPE_IMAGE;
    data = g_list_append(data, dat);
  }

  if (token_type & TYPE_NUMBER) {
    max_token += g_utf8_strlen (numbers, -1);
    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =  TYPE_NUMBER;
    data = g_list_append(data, dat);
  }

  if (token_type & TYPE_UPPERCASE){
    max_token += g_utf8_strlen (alphabet_uppercase, -1);
    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =   TYPE_UPPERCASE;
    data = g_list_append(data, dat);
  }

  if (token_type & TYPE_LOWERCASE){
    max_token += g_utf8_strlen (alphabet_lowercase, -1);;
    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =   TYPE_LOWERCASE;
    data = g_list_append(data, dat);
  }


  if (token_type & TYPE_SOUND){
    max_token += NUMBER_OF_SOUNDS;
    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =   TYPE_SOUND;
    data = g_list_append(data, dat);
  }

  if (token_type & TYPE_ADD){
    max_token += (add_levelDescription[gcomprisBoard->level][0]+1)*(add_levelDescription[gcomprisBoard->level][1]+1);
    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =   TYPE_ADD;
    data = g_list_append(data, dat);
  }

  if (token_type & TYPE_MINUS){
    max_token += (minus_levelDescription[gcomprisBoard->level][0]+1)*(minus_levelDescription[gcomprisBoard->level][1]+1);
    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =   TYPE_MINUS;
    data = g_list_append(data, dat);
  }

  if (token_type & TYPE_MULT){
   max_token += (mult_levelDescription[gcomprisBoard->level][0]+1)*(mult_levelDescription[gcomprisBoard->level][1]+1);
    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =   TYPE_MULT;
    data = g_list_append(data, dat);
  }

  if (token_type & TYPE_DIV){
    max_token += (div_levelDescription[gcomprisBoard->level][0]+1)*(div_levelDescription[gcomprisBoard->level][1]+1);
    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =   TYPE_DIV;
    data = g_list_append(data, dat);
  }

  if (token_type & TYPE_ENUMERATE){
    max_token += NUMBER_OF_ENUMERATES;

    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =  TYPE_ENUMERATE;
    data = g_list_append(data, dat);
  }

  if (token_type & TYPE_WORDNUMBER){
    max_token += NUMBER_OF_WORDNUMBERS;

    DATUM *dat = g_malloc0(sizeof(DATUM));
    dat->bound = max_token;
    dat->type =  TYPE_WORDNUMBER;
    data = g_list_append(data, dat);
  }


  g_assert(max_token >0);

  i = g_random_int()%max_token;

  for (list = data; list != NULL; list = list->next)
    if ( i < ((DATUM *)list->data)->bound)
      break;

  j=-1;

  do {
    skip = FALSE;
    g_free(result);
    result = NULL;
    g_free(second);
    j++;

    if ((i+j) == max_token) {
      list = data;
    }

    if ((i+j)%max_token == ((DATUM *)list->data)->bound)
      list = list->next;

    /* calculate index in right table */
    k = (i+j)%max_token - (list->prev ? ((DATUM *)list->prev->data)->bound : 0);


    type = ((DATUM *)list->data)->type;

    switch (type) {
    case TYPE_IMAGE:
      result= g_strdup(imageList[k]);
      break;
    case TYPE_NUMBER:
      result = g_malloc0(2*sizeof(gunichar));
      g_utf8_strncpy(result, g_utf8_offset_to_pointer (numbers,k),1);
      break;
    case TYPE_UPPERCASE:
      result = g_malloc0(2*sizeof(gunichar));
      g_utf8_strncpy(result, g_utf8_offset_to_pointer (alphabet_uppercase,k),1);
      break;
    case TYPE_LOWERCASE:
      result = g_malloc0(2*sizeof(gunichar));
      g_utf8_strncpy(result, g_utf8_offset_to_pointer (alphabet_lowercase,k),1);
      break;
    case TYPE_SOUND:
      result = g_strdup(soundList[k]);
      break;
    case TYPE_ADD:
      {
	int i, j;
	i = k %  add_levelDescription[gcomprisBoard->level][0];
	j = k /  add_levelDescription[gcomprisBoard->level][0];
	result = g_strdup_printf("%d %s %d",i,op_add,j);
	second = g_strdup_printf("%d",i+j);;
	break;
      }
    case TYPE_MINUS:
      {
	int i, j;
	i = k %  minus_levelDescription[gcomprisBoard->level][0];
	j = k /  minus_levelDescription[gcomprisBoard->level][0];
	result = g_strdup_printf("%d %s %d",i+j,op_minus,i);
	second = g_strdup_printf("%d",j);;
	break;
      }
    case TYPE_MULT:
      {
	int i, j;
	i = k %  mult_levelDescription[gcomprisBoard->level][0];
	j = k /  mult_levelDescription[gcomprisBoard->level][0];
	result = g_strdup_printf("%d %s %d",i,op_mult,j);
	second = g_strdup_printf("%d",i*j);;
	break;
      }
    case TYPE_DIV:
      {
	int i1, i2;
	i1 = k %  div_levelDescription[gcomprisBoard->level][0];
	if (i1==0) skip=TRUE;
	i2 = k /  div_levelDescription[gcomprisBoard->level][0];
	result = g_strdup_printf("%d %s %d",i1*i2,op_div,i1);
	second = g_strdup_printf("%d",i2);
	break;
      }
    case TYPE_ENUMERATE:
      {
      result = g_malloc0(2*sizeof(gunichar));
      g_utf8_strncpy(result, g_utf8_offset_to_pointer (numbers,k),1);
      second = g_strdup(enumerateList[k]);
      break;
      }
    case TYPE_WORDNUMBER:
      {
      result = g_malloc0(2*sizeof(gunichar));
      g_utf8_strncpy(result, g_utf8_offset_to_pointer (numbers,k),1);
      second = g_strdup(gettext(wordnumberList[k]));
      break;
      }
    default:
      /* should never append */
      g_error("never !");
      break;
    }

  } while (skip || ((j < max_token )
	   && (passed_token && result && g_list_find_custom(passed_token, result, (GCompareFunc)strcmp))));

  g_assert (j < max_token);

  passed_token = g_list_append( passed_token, result);

  *returned_type = type;

  *string = result;

  if (second_value)
    *second_value = second;

  for (list = data; list != NULL; list=list->next)
    g_free(list->data);

  g_list_free(data);

}
Beispiel #5
0
static void start_board (GcomprisBoard *agcomprisBoard)
{

  if(agcomprisBoard!=NULL)
    {
      gcomprisBoard=agcomprisBoard;

      gcomprisBoard->level = 1;
      gcomprisBoard->maxlevel = 9;
      gc_bar_set(GC_BAR_LEVEL);

      /* Default mode */

      if(!gcomprisBoard->mode){
	currentMode=MODE_NORMAL;
	currentUiMode=UIMODE_NORMAL;
	currentBoardMode=BOARDMODE_NORMAL;
      } else {
	if(g_ascii_strcasecmp(gcomprisBoard->mode, "tux")==0){
	  currentMode=MODE_TUX;
	  currentUiMode=UIMODE_NORMAL;
	  currentBoardMode=BOARDMODE_NORMAL;
	} else {
	  if(g_ascii_strcasecmp(gcomprisBoard->mode, "sound")==0){
	    currentMode=MODE_NORMAL;
	    currentUiMode=UIMODE_SOUND;
	    currentBoardMode=BOARDMODE_SOUND;
	  } else {
	    if(g_ascii_strcasecmp(gcomprisBoard->mode, "sound_tux")==0){
	      currentMode=MODE_TUX;
	      currentUiMode=UIMODE_SOUND;
	      currentBoardMode=BOARDMODE_SOUND;
	    } else {
	      if(g_ascii_strcasecmp(gcomprisBoard->mode, "add")==0){
		currentMode=MODE_NORMAL;
		currentUiMode=UIMODE_NORMAL;
		currentBoardMode=BOARDMODE_ADD;
	      } else {
		if(g_ascii_strcasecmp(gcomprisBoard->mode, "add_tux")==0){
		  currentMode=MODE_TUX;
		  currentUiMode=UIMODE_NORMAL;
		  currentBoardMode=BOARDMODE_ADD;
		} else {
		  if(g_ascii_strcasecmp(gcomprisBoard->mode, "minus")==0){
		    currentMode=MODE_NORMAL;
		    currentUiMode=UIMODE_NORMAL;
		    currentBoardMode=BOARDMODE_MINUS;
		  } else {
		    if(g_ascii_strcasecmp(gcomprisBoard->mode, "minus_tux")==0){
		      currentMode=MODE_TUX;
		      currentUiMode=UIMODE_NORMAL;
		      currentBoardMode=BOARDMODE_MINUS;
		    } else {
		      if(g_ascii_strcasecmp(gcomprisBoard->mode, "mult")==0){
			currentMode=MODE_NORMAL;
			currentUiMode=UIMODE_NORMAL;
			currentBoardMode=BOARDMODE_MULT;
		      } else {
			if(g_ascii_strcasecmp(gcomprisBoard->mode, "mult_tux")==0){
			  currentMode=MODE_TUX;
			  currentUiMode=UIMODE_NORMAL;
			  currentBoardMode=BOARDMODE_MULT;
			} else {
			  if(g_ascii_strcasecmp(gcomprisBoard->mode, "div")==0){
			    currentMode=MODE_NORMAL;
			    currentUiMode=UIMODE_NORMAL;
			    currentBoardMode=BOARDMODE_DIV;
			  } else {
			    if(g_ascii_strcasecmp(gcomprisBoard->mode, "div_tux")==0){
			      currentMode=MODE_TUX;
			      currentUiMode=UIMODE_NORMAL;
			      currentBoardMode=BOARDMODE_DIV;
			    } else {
			      if(g_ascii_strcasecmp(gcomprisBoard->mode, "add_minus")==0){
				currentMode=MODE_NORMAL;
				currentUiMode=UIMODE_NORMAL;
				currentBoardMode=BOARDMODE_ADD_MINUS;
			      } else {
				if(g_ascii_strcasecmp(gcomprisBoard->mode, "add_minus_tux")==0){
				  currentMode=MODE_TUX;
				  currentUiMode=UIMODE_NORMAL;
				  currentBoardMode=BOARDMODE_ADD_MINUS;
				} else {
				  if(g_ascii_strcasecmp(gcomprisBoard->mode, "mult_div")==0){
				    currentMode=MODE_NORMAL;
				    currentUiMode=UIMODE_NORMAL;
				    currentBoardMode=BOARDMODE_MULT_DIV;
				  } else {
				    if(g_ascii_strcasecmp(gcomprisBoard->mode, "mult_div_tux")==0){
				      currentMode=MODE_TUX;
				      currentUiMode=UIMODE_NORMAL;
				      currentBoardMode=BOARDMODE_MULT_DIV;
				    } else {
				      if(g_ascii_strcasecmp(gcomprisBoard->mode, "add_minus_mult_div")==0){
					currentMode=MODE_NORMAL;
					currentUiMode=UIMODE_NORMAL;
					currentBoardMode=BOARDMODE_ADD_MINUS_MULT_DIV;
				      } else {
					if(g_ascii_strcasecmp(gcomprisBoard->mode, "add_minus_mult_div_tux")==0){
					  currentMode=MODE_TUX;
					  currentUiMode=UIMODE_NORMAL;
					  currentBoardMode=BOARDMODE_ADD_MINUS_MULT_DIV;
					} else {
					  if(g_ascii_strcasecmp(gcomprisBoard->mode, "enumerate")==0){
					    currentMode=MODE_NORMAL;
					    currentUiMode=UIMODE_NORMAL;
					    currentBoardMode=BOARDMODE_ENUMERATE;
					  } else {
					    if(g_ascii_strcasecmp(gcomprisBoard->mode, "enumerate_tux")==0){
					      currentMode=MODE_TUX;
					      currentUiMode=UIMODE_NORMAL;
					      currentBoardMode=BOARDMODE_ENUMERATE;
					    } else {
				              if(g_ascii_strcasecmp(gcomprisBoard->mode, "wordnumber")==0){
						currentMode=MODE_NORMAL;
						currentUiMode=UIMODE_NORMAL;
						currentBoardMode=BOARDMODE_WORDNUMBER;
					      } else {
						if(g_ascii_strcasecmp(gcomprisBoard->mode, "wordnumber_tux")==0){
					          currentMode=MODE_TUX;
						  currentUiMode=UIMODE_NORMAL;
						  currentBoardMode=BOARDMODE_WORDNUMBER;
						} else {
						  currentMode=MODE_NORMAL;
						  currentUiMode=UIMODE_NORMAL;
						  currentBoardMode=BOARDMODE_NORMAL;
						  g_warning("Fallback mode set to images");
						}
					      }
					    }
					  }
					}
				      }
				    }
				  }
				}
			      }
			    }
			  }
			}
		      }
		    }
		  }
		}
	      }
	    }
	  }
	}
      }


      if (currentUiMode == UIMODE_SOUND)
	{
	  GcomprisProperties	*properties = gc_prop_get();

	  gc_sound_bg_pause();

	  /* initial state to restore */
	  sound_policy = gc_sound_policy_get();

	  // Will set the PLAY_AND_INTERRUPT policy on first
	  // user click so that intro sounds is not

	  gc_set_background(goo_canvas_get_root_item(gcomprisBoard->canvas),
			    "memory/gcompris_band.svg");
	  base_x1 = BASE_SOUND_X1;
	  base_y1 = BASE_SOUND_Y1;
	  base_x2 = BASE_SOUND_X2;
	  base_y2 = BASE_SOUND_Y2;
	  base_x1_tux = BASE_SOUND_X1_TUX;

	  if(!properties->fx) {
	    gc_dialog(_("Error: this activity cannot be played with the\n"
			"sound effects disabled.\nGo to the configuration dialog to\n"
			"enable the sound"), gc_board_stop);
	    return;
	  }

	}
      else
	{
        if ((currentBoardMode==BOARDMODE_ENUMERATE)||(currentBoardMode==BOARDMODE_WORDNUMBER))
	    {
             gcomprisBoard->maxlevel = 6;
	    }

	  gc_set_background(goo_canvas_get_root_item(gcomprisBoard->canvas),
			    "memory/scenery_background.png");
	  base_x1 = BASE_CARD_X1;
	  base_y1 = BASE_CARD_Y1;
	  base_x2 = BASE_CARD_X2;
	  base_y2 = BASE_CARD_Y2;
	  base_x1_tux = BASE_CARD_X1_TUX;
	}


      /* TRANSLATORS: Put here the numbers in your language */
      numbers=_("0123456789");
      g_assert(g_utf8_validate(numbers,-1,NULL)); // require by all utf8-functions

      /* TRANSLATORS: Put here the alphabet lowercase in your language */
      alphabet_lowercase=_("abcdefghijklmnopqrstuvwxyz");
      g_assert(g_utf8_validate(alphabet_lowercase,-1,NULL)); // require by all utf8-functions

      g_warning("Using lowercase %s", alphabet_lowercase);

      /* TRANSLATORS: Put here the alphabet uppercase in your language */
      alphabet_uppercase=_("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
      g_assert(g_utf8_validate(alphabet_uppercase,-1,NULL)); // require by all utf8-functions
      g_warning("Using uppercase %s", alphabet_uppercase);

      /* TRANSLATORS: Put here the mathematical operators '+-x/' for  your language. */
      operators=_("+-×÷");
      g_assert(g_utf8_validate(operators,-1,NULL)); // require by all utf8-functions
      g_warning("Using operators %s", operators);

      op_add = g_malloc0(2*sizeof(gunichar));
      g_utf8_strncpy(op_add, g_utf8_offset_to_pointer (operators,0),1);

      op_minus = g_malloc0(2*sizeof(gunichar));
      g_utf8_strncpy(op_minus, g_utf8_offset_to_pointer (operators,1),1);

      op_mult = g_malloc0(2*sizeof(gunichar));
      g_utf8_strncpy(op_mult, g_utf8_offset_to_pointer (operators,2),1);

      op_div = g_malloc0(2*sizeof(gunichar));
      g_utf8_strncpy(op_div, g_utf8_offset_to_pointer (operators,3),1);


      g_warning("Using operators %s %s %s %s", op_add, op_minus,
		                               op_mult, op_div);

      if (currentMode == MODE_TUX){
	tux_memory_size = tux_memory_sizes[gcomprisBoard->level];
	tux_memory = g_queue_new ();
      }

      Paused = FALSE;

      memory_next_level();
    }
}
Beispiel #6
0
gboolean	ly_mdh_new_with_uri_full_bus_cb	(GstBus *bus, GstMessage *message, gpointer data)
{
	LyMdhMetadata *md=data;

	char *tag_codec=NULL;
	char *tag_title=NULL;
	char *tag_artist=NULL;
	char *tag_album=NULL;
	char *tag_comment=NULL;
	char *tag_genre=NULL;
	guint tag_bitrate=0;
	guint tag_track=0;
	GstBuffer *tag_cover=NULL;

	if(md==NULL) return TRUE;
	if(md->uri==NULL) return TRUE;

	switch(GST_MESSAGE_TYPE(message))
	{
		case GST_MESSAGE_EOS:
		{
			ly_mdh_md_eos=TRUE;
			return TRUE;
		}
		case GST_MESSAGE_ERROR:
		{
			ly_mdh_md_eos=TRUE;
			return TRUE;
		}
		case GST_MESSAGE_TAG:
		{
			GstTagList *tags;
			gst_message_parse_tag(message,&tags);
			//codec
			if(gst_tag_list_get_string(tags,GST_TAG_AUDIO_CODEC,&tag_codec))
			{
				if(tag_codec!=NULL)
					g_strlcpy(md->codec, tag_codec, sizeof(md->codec));
			}
			//title
			if(gst_tag_list_get_string(tags,GST_TAG_TITLE,&tag_title))
			{
				if(g_utf8_validate(tag_title,-1,NULL))
				{
					g_utf8_strncpy((char *)(md->title),tag_title, sizeof(md->title));
				}
				g_free(tag_title);
			}
			//artist
			if(gst_tag_list_get_string(tags,GST_TAG_ARTIST,&tag_artist))
			{
				if(g_utf8_validate(tag_artist,-1,NULL))
				{
					g_utf8_strncpy((char *)(md->artist), tag_artist, sizeof(md->artist));
				}
				g_free(tag_artist);
			}
			//album
			if(gst_tag_list_get_string(tags,GST_TAG_ALBUM,&tag_album))
			{
				if(g_utf8_validate(tag_album,-1,NULL))
				{
					g_utf8_strncpy((char *)(md->album), tag_album, sizeof(md->album));
				}
				g_free(tag_album);
			}
			//comment
			if(gst_tag_list_get_string(tags,GST_TAG_COMMENT,&tag_comment))
			{
				if(g_utf8_validate(tag_comment,-1,NULL))
				{
					g_utf8_strncpy((char *)(md->comment), tag_comment, sizeof(md->comment));
				}
				g_free(tag_comment);
			}
			//bitrate
			if(gst_tag_list_get_uint(tags, GST_TAG_BITRATE, &tag_bitrate))
			{
				md->bitrate = tag_bitrate;
			}
			//track_number
			if(gst_tag_list_get_uint(tags, GST_TAG_TRACK_NUMBER, &tag_track))
			{
				md->track = tag_track;
			}
			//genre
			if(gst_tag_list_get_string(tags, GST_TAG_GENRE,&tag_genre))
			{
				if(g_utf8_validate(tag_genre,-1,NULL))
				{
					g_utf8_strncpy((char *)(md->genre), tag_genre, sizeof(md->genre));
				}
				g_free(tag_genre);
			}
			//album cover
 			if(gst_tag_list_get_buffer(tags, GST_TAG_IMAGE, &tag_cover))
 			{
 				if(md->cover!=NULL)
 					gst_buffer_unref(md->cover);
				md->cover=tag_cover;
			}
			gst_tag_list_free(tags);
			return TRUE;
			break;
		}
		case GST_MESSAGE_ELEMENT:
			break;
		default:
			break;
	}
	return FALSE;
}
Beispiel #7
0
void
build_table(charpick_data *p_curr_data)
{
  GtkWidget *box, *button_box, **row_box;
  GtkWidget *button, *arrow;
  gint i = 0, len = g_utf8_strlen (p_curr_data->charlist, -1);
  GtkWidget **toggle_button;
  gchar *charlist;
  gint max_width=1, max_height=1;
  gint size_ratio;

  toggle_button = g_new (GtkWidget *, len);
  
  if (p_curr_data->box)
    gtk_widget_destroy(p_curr_data->box);
    
  if (p_curr_data->panel_vertical)
    box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  else 
    box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  gtk_widget_show (box);
  p_curr_data->box = box;
  
  button = gtk_button_new ();
  if (g_list_length (p_curr_data->chartable) != 1)
  {
    gtk_widget_set_tooltip_text (button, _("Available palettes"));
  
    switch (mate_panel_applet_get_orient (MATE_PANEL_APPLET (p_curr_data->applet))) {
       	case MATE_PANEL_APPLET_ORIENT_DOWN:
          	arrow = gtk_image_new_from_icon_name ("pan-down-symbolic", GTK_ICON_SIZE_MENU);
       		break;
       	case MATE_PANEL_APPLET_ORIENT_UP:
          	arrow = gtk_image_new_from_icon_name ("pan-up-symbolic", GTK_ICON_SIZE_MENU);
       		break;
       	case MATE_PANEL_APPLET_ORIENT_LEFT:
       		arrow = gtk_image_new_from_icon_name ("pan-start-symbolic", GTK_ICON_SIZE_MENU);
  		break;
       	case MATE_PANEL_APPLET_ORIENT_RIGHT:
       		arrow = gtk_image_new_from_icon_name ("pan-end-symbolic", GTK_ICON_SIZE_MENU);
  		break;
    default:
  	  g_assert_not_reached ();
    }
    gtk_container_add (GTK_CONTAINER (button), arrow);
    gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
    /* FIXME : evil hack (see force_no_focus_padding) */
#if GTK_CHECK_VERSION (3, 20, 0)
    force_no_button_padding (button);
#else
    force_no_focus_padding (button);
#endif
    gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
    g_signal_connect (G_OBJECT (button), "clicked",
                              G_CALLBACK (chooser_button_clicked),
			      p_curr_data);
    g_signal_connect (G_OBJECT (button), "button_press_event",
                               G_CALLBACK (button_press_hack),
			       p_curr_data->applet);
  
  }
  
  charlist = g_strdup (p_curr_data->charlist);
  for (i = 0; i < len; i++) {
    gchar label[7];
    GtkRequisition req;
    gchar *atk_desc;
    gchar *name;
    
    g_utf8_strncpy (label, charlist, 1);
    charlist = g_utf8_next_char (charlist);

#ifdef HAVE_GUCHARMAP
    /* TRANSLATOR: This sentance reads something like 'Insert "PILCROW SIGN"'
     *             hopefully, the name of the unicode character has already
     *             been translated.
     */
    name = g_strdup_printf (_("Insert \"%s\""),
		    gucharmap_get_unicode_name (g_utf8_get_char (label)));
#else
    name = g_strdup (_("Insert special character"));
#endif
   
    toggle_button[i] = gtk_toggle_button_new_with_label (label);
    atk_desc =  g_strdup_printf (_("insert special character %s"), label);
    set_atk_name_description (toggle_button[i], NULL, atk_desc);
    g_free (atk_desc);
    gtk_widget_show (toggle_button[i]);
    gtk_button_set_relief(GTK_BUTTON(toggle_button[i]), GTK_RELIEF_NONE);
    /* FIXME : evil hack (see force_no_focus_padding) */
#if GTK_CHECK_VERSION (3, 20, 0)
    force_no_button_padding (toggle_button[i]);
#else
    force_no_focus_padding (toggle_button[i]);
#endif
    gtk_widget_set_tooltip_text (toggle_button[i], name);
    g_free (name);

    gtk_widget_get_preferred_size (toggle_button[i], NULL, &req);
    
    max_width = MAX (max_width, req.width);
    max_height = MAX (max_height, req.height-2);
  
    g_object_set_data (G_OBJECT (toggle_button[i]), "unichar", 
				GINT_TO_POINTER(g_utf8_get_char (label)));
    g_signal_connect (G_OBJECT (toggle_button[i]), "toggled",
		      G_CALLBACK (toggle_button_toggled_cb),
                        p_curr_data);
    g_signal_connect (G_OBJECT (toggle_button[i]), "button_press_event", 
                      G_CALLBACK (button_press_hack), p_curr_data->applet);
  }
  
  if (p_curr_data->panel_vertical) {
    size_ratio = p_curr_data->panel_size / max_width;
    button_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  } else {
    size_ratio = p_curr_data->panel_size / max_height;
    button_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  }

  gtk_box_set_homogeneous (GTK_BOX (button_box), TRUE);
  gtk_box_pack_start (GTK_BOX (box), button_box, TRUE, TRUE, 0);
  
  size_ratio = MAX (size_ratio, 1);
  row_box = g_new0 (GtkWidget *, size_ratio);
  for (i=0; i < size_ratio; i++) {
	if (!p_curr_data->panel_vertical) row_box[i] = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	else row_box[i] = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	gtk_box_set_homogeneous (GTK_BOX (row_box[i]), TRUE);
  	gtk_box_pack_start (GTK_BOX (button_box), row_box[i], TRUE, TRUE, 0);
  }
  
  for (i = 0; i <len; i++) {  	
  	int delta = len/size_ratio;
  	int index;
  
	if (delta > 0)
	  	index = i / delta;
	else
		index = i;

	index = CLAMP (index, 0, size_ratio-1);	
  	gtk_box_pack_start (GTK_BOX (row_box[index]), toggle_button[i], TRUE, TRUE, 0);
  }
 
  g_free (toggle_button);
  
  gtk_container_add (GTK_CONTAINER(p_curr_data->applet), box);
  gtk_widget_show_all (p_curr_data->box);

  p_curr_data->last_index = NO_LAST_INDEX;
  p_curr_data->last_toggle_button = NULL;
  
}
Beispiel #8
0
gchar* set_typing_msg(gchar* input, gint interval){
  gchar *p, *p1, *ret;
  gint i,j,num;
  
  p = input;
  ret=my_strbuf(NULL);

  while (*p) {
    gunichar ch, ch1;
    gchar tmp[64];

    ch= g_utf8_get_char (p);
    
    if (ch == '%'){
      num=0;
      i=0;
      p1=p;
      for(;;){
	p1=g_utf8_next_char (p1);
	ch1= g_utf8_get_char (p1);
	if((ch1 == 'c')||(ch1 == 'a')||(ch1 == 'n')||(ch1 == 'p')){
	  i++;
	  break;
	}
	else if(isdigit(ch1)){
	  i++;
	}
	else{
	  i=0;
	  break;
	}
      }

      if(i!=0){
	ret=my_strbuf("%");
	for(j=0;j<i;j++){
	  p = g_utf8_next_char (p);
	  g_utf8_strncpy(tmp,p,1);
	  ret=my_strbuf(tmp);
	}
      }
      else{
	sprintf(tmp,"%%%%%%%dc",interval);
	ret=my_strbuf(tmp);
      }
    }
    else{
      g_utf8_strncpy(tmp,p,1);
      ret=my_strbuf(tmp);
      sprintf(tmp,"%%%dc",interval);
      ret=my_strbuf(tmp);
    }
    
    
    p = g_utf8_next_char (p);
  }
  //fprintf(stderr,"%s\n",ret);
  //fflush(stderr);

  return(ret);
}
Beispiel #9
0
static void
_win_print_wrapped(WINDOW *win, const char *const message, size_t indent, int pad_indent)
{
    int starty = getcury(win);
    int wordi = 0;
    char *word = malloc(strlen(message) + 1);

    gchar *curr_ch = g_utf8_offset_to_pointer(message, 0);

    while (*curr_ch != '\0') {

        // handle space
        if (*curr_ch == ' ') {
            waddch(win, ' ');
            curr_ch = g_utf8_next_char(curr_ch);

        // handle newline
        } else if (*curr_ch == '\n') {
            waddch(win, '\n');
            _win_indent(win, indent + pad_indent);
            curr_ch = g_utf8_next_char(curr_ch);

        // handle word
        } else {
            wordi = 0;
            int wordlen = 0;
            while (*curr_ch != ' ' && *curr_ch != '\n' && *curr_ch != '\0') {
                size_t ch_len = mbrlen(curr_ch, MB_CUR_MAX, NULL);
                if ((ch_len == (size_t)-2) || (ch_len == (size_t)-1)) {
                    curr_ch++;
                    continue;
                }
                int offset = 0;
                while (offset < ch_len) {
                    word[wordi++] = curr_ch[offset++];
                }
                curr_ch = g_utf8_next_char(curr_ch);
            }
            word[wordi] = '\0';
            wordlen = utf8_display_len(word);

            int curx = getcurx(win);
            int cury = getcury(win);
            int maxx = getmaxx(win);

            // wrap required
            if (curx + wordlen > maxx) {
                int linelen = maxx - (indent + pad_indent);

                // word larger than line
                if (wordlen > linelen) {
                    gchar *word_ch = g_utf8_offset_to_pointer(word, 0);
                    while(*word_ch != '\0') {
                        curx = getcurx(win);
                        cury = getcury(win);
                        gboolean firstline = cury == starty;

                        if (firstline && curx < indent) {
                            _win_indent(win, indent);
                        }
                        if (!firstline && curx < (indent + pad_indent)) {
                            _win_indent(win, indent + pad_indent);
                        }

                        gchar copy[wordi+1];
                        g_utf8_strncpy(copy, word_ch, 1);
                        waddstr(win, copy);

                        word_ch = g_utf8_next_char(word_ch);
                    }

                // newline and print word
                } else {
                    waddch(win, '\n');
                    curx = getcurx(win);
                    cury = getcury(win);
                    gboolean firstline = cury == starty;

                    if (firstline && curx < indent) {
                        _win_indent(win, indent);
                    }
                    if (!firstline && curx < (indent + pad_indent)) {
                        _win_indent(win, indent + pad_indent);
                    }
                    waddstr(win, word);
                }

            // no wrap required
            } else {
                curx = getcurx(win);
                cury = getcury(win);
                gboolean firstline = cury == starty;

                if (firstline && curx < indent) {
                    _win_indent(win, indent);
                }
                if (!firstline && curx < (indent + pad_indent)) {
                    _win_indent(win, indent + pad_indent);
                }
                waddstr(win, word);
            }
        }

        // consume first space of next line
        int curx = getcurx(win);
        int cury = getcury(win);
        gboolean firstline = (cury == starty);

        if (!firstline && curx == 0 && *curr_ch == ' ') {
            curr_ch = g_utf8_next_char(curr_ch);
        }
    }

    free(word);
}
Beispiel #10
0
void
login_connect_cb(gpointer data, PurpleSslConnection *gsc,
				 PurpleInputCondition cond)
{
	MsnNexus *nexus;
	MsnSession *session;
	char *username, *password, *encpass;
	char *request_str, *head, *tail;
	char *buffer = NULL;
	guint32 ctint;

	nexus = data;
	g_return_if_fail(nexus != NULL);

	session = nexus->session;
	g_return_if_fail(session != NULL);

	msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE);

	username =
		g_strdup(purple_url_encode(purple_account_get_username(session->account)));

	password = g_utf8_strncpy(g_strdup(purple_connection_get_password(session->account->gc)),
							  purple_connection_get_password(session->account->gc), 16);
	encpass = g_strdup(purple_url_encode(password));
	g_free(password);

	ctint = strtoul((char *)g_hash_table_lookup(nexus->challenge_data, "ct"), NULL, 10) + 200;

	head = g_strdup_printf(
		"GET %s HTTP/1.1\r\n"
		"Authorization: Passport1.4 OrgVerb=GET,OrgURL=%s,sign-in=%s",
		nexus->login_path,
		(char *)g_hash_table_lookup(nexus->challenge_data, "ru"),
		username);

	tail = g_strdup_printf(
		"lc=%s,id=%s,tw=%s,fs=%s,ru=%s,ct=%" G_GUINT32_FORMAT ",kpp=%s,kv=%s,ver=%s,tpf=%s\r\n"
		"User-Agent: MSMSGS\r\n"
		"Host: %s\r\n"
		"Connection: Keep-Alive\r\n"
		"Cache-Control: no-cache\r\n",
		nexus_challenge_data_lookup(nexus->challenge_data, "lc"),
		nexus_challenge_data_lookup(nexus->challenge_data, "id"),
		nexus_challenge_data_lookup(nexus->challenge_data, "tw"),
		nexus_challenge_data_lookup(nexus->challenge_data, "fs"),
		nexus_challenge_data_lookup(nexus->challenge_data, "ru"),
		ctint,
		nexus_challenge_data_lookup(nexus->challenge_data, "kpp"),
		nexus_challenge_data_lookup(nexus->challenge_data, "kv"),
		nexus_challenge_data_lookup(nexus->challenge_data, "ver"),
		nexus_challenge_data_lookup(nexus->challenge_data, "tpf"),
		nexus->login_host);

	buffer = g_strdup_printf("%s,pwd=XXXXXXXX,%s\r\n", head, tail);
	request_str = g_strdup_printf("%s,pwd=%s,%s\r\n", head, encpass, tail);

	purple_debug_misc("msn", "Sending: {%s}\n", buffer);

	g_free(buffer);
	g_free(head);
	g_free(tail);
	g_free(username);
	g_free(encpass);

	nexus->write_buf = request_str;
	nexus->written_len = 0;

	nexus->read_len = 0;

	nexus->written_cb = nexus_login_written_cb;

	nexus->input_handler = purple_input_add(gsc->fd, PURPLE_INPUT_WRITE,
		nexus_write_cb, nexus);

	nexus_write_cb(nexus, gsc->fd, PURPLE_INPUT_WRITE);

	return;


}
Beispiel #11
0
static char *plus_nick_changed_cb(PurpleBuddy *buddy)
{
	char * ret = NULL;
	gboolean setting;
	purple_debug_misc("plusblist","Screename is \"%s\", server alias is \"%s\"\n",buddy->name,buddy->server_alias);

	setting = purple_blist_node_get_bool(&buddy->node, "disable_plus");
	if(!setting)
	{
		/* get an escaped version of the alias */
		char *esc, *p;
		GString *buf;
		int gradientIndexFG, gradientIndexBG, ncharsFG, ncharsBG;
		int begColorFG[3], endColorFG[3], deltaColorFG[3];
		int begColorBG[3], endColorBG[3], deltaColorBG[3];
		unsigned char gradientBG, gradientFG, insideTag;

		/* Colorization on alias, if set. */
		if (buddy->alias != NULL)
			esc = g_strdup(buddy->alias);
		else
			esc = g_strdup(buddy->server_alias);

		purple_debug_misc("plusblist","Parsing tags to \"%s\"\n",esc);
		if(!esc) return NULL;	/* oops... */

		gradientBG = gradientFG = insideTag = FALSE;
		ncharsBG = ncharsFG = gradientIndexBG = gradientIndexFG = 0;
		p = esc;

		/* Ciclo di lettura caratteri */
		buf = g_string_new("");
		for (;*p;p = g_utf8_next_char(p)) {
			if (*p == '[') {
				/* Controllo tag */

				/* Faccio un fast forward per cercare il corrispondente ],
				 * determinando quindi se si tratta di un tag oppure no. */
				int i;
				for(i = 1; i < 12; i++) {
					if (p[i] == ']') {
						char *replace;
						char tagCharLowerCase, tagCharUpperCase;
						char gradientTag = FALSE;

						/* Ho trovato la fine del tag, sono dentro! */

						/* Controllo gradiente */

						/* Try to unificate c/a*/
						tagCharLowerCase = tagCharUpperCase = 0;
						if (p[1] == 'c' || p[1] == 'C') {
							tagCharLowerCase = 'c';
							tagCharUpperCase = 'C';
						}
						else if (p[1] == 'a' || p[1] == 'A') {
							tagCharLowerCase = 'a';
							tagCharUpperCase = 'A';
						}
						else if (p[1] == 'b' || p[1] == 'B' || p[1] == 'i' || p[1] == 'I' ||
							p[1] == 'u' || p[1] == 'U' || p[1] == 's' || p[1] == 'S' || p[1] == '/') {
							/* sarebbe carino fargli skippare la parte di controllo gradiente */
						}
						else {
							break;
						}
						insideTag = TRUE;

						if ((p[1] == tagCharLowerCase || p[1] == tagCharUpperCase) && p[2] == '=') {
							gchar *iter = p + i + 1;
							char insideTagFastForward = FALSE;
							int fastForwardCharCounter = 0;

							if (tagCharLowerCase == 'c') {
								gradientFG = FALSE; /* TODO: necessario? */
								ncharsFG = 0;
							}
							else {
								gradientBG = FALSE; /* TODO: necessario? */
								ncharsBG = 0;
							}

							/* Vado avanti e cerco il finale corrispondente */
							for (;*iter;iter = g_utf8_next_char(iter)) {

								if (iter[0] == '[' && iter[1] == '/' &&
									(iter[2] == tagCharLowerCase || iter[2] == tagCharUpperCase)
								) {
									purple_debug_misc("plusblist", "Gradient end found.\n");
									if (iter[3] == '=') {
										char *initialColor, *finalColor;
										int j;

										gradientTag = TRUE;
										/*  */
										initialColor = findColor(p + 3);
										finalColor = findColor(iter + 4);
										if (!initialColor || !finalColor) break;

										purple_debug_misc("plusblist", "Beginning color: %s\n", initialColor);

										for (j = 0;j <= 2;j++) {
											if (tagCharLowerCase == 'c') {
												begColorFG[j] = hexDec(initialColor + 2 * j, 2);
												endColorFG[j] = hexDec(finalColor + 2 * j, 2);
												deltaColorFG[j] = endColorFG[j] - begColorFG[j];
											}
											else {
												begColorBG[j] = hexDec(initialColor + 2 * j, 2);
												endColorBG[j] = hexDec(finalColor + 2 * j, 2);
												deltaColorBG[j] = endColorBG[j] - begColorBG[j];
											}
										}

										purple_debug_misc("plusblist", "Ending color: %s\n", finalColor);
										g_free(initialColor);
										g_free(finalColor);

										if (tagCharLowerCase == 'c') {
											gradientFG = TRUE;
											gradientIndexFG = 0;
											purple_debug_misc("plusblist", "Number of chars inside the gradient: %i\n", ncharsFG);
										}
										else {
											gradientBG = TRUE;
											gradientIndexBG = 0;
											purple_debug_misc("plusblist", "Number of chars inside the gradient: %i\n", ncharsBG);
										}
										/* Calcolare il numero di caratteri effettivi (escludendo i tag),
										 * e suddividere il Delta R, G, B diviso il numero di caratteri,
										 * ottenendo l'incremento da aggiungere (o sottrarre)
										 * ad ogni carattere.
										 * Subito PRIMA dell'ultimo carattere, mettere il colore finale.
										 */
									}
									break;
								}
								else {
									if (tagCharLowerCase == 'c') ncharsFG++;
									else ncharsBG++;

								}

								if (iter[0] == '[') {
									/* sono FORSE all'interno di un tag*/
									if (iter[1] == 'b' || iter[1] == 'B' ||
										iter[1] == 'i' || iter[1] == 'I' ||
										iter[1] == 'u' || iter[1] == 'U' ||
										iter[1] == 's' || iter[1] == 'S' ||
										iter[1] == 'a' || iter[1] == 'A' ||
										iter[1] == 'c' || iter[1] == 'C' ||
										iter[1] == '/') {
											insideTagFastForward = TRUE; /* TODO: non e' vero, limite massimo caratteri */
											fastForwardCharCounter = 0;
									}
								}
								else if (iter[0] == ']' && insideTagFastForward) {
									/* ero all'interno di un tag ed ora l'ho chiuso */
									insideTagFastForward = FALSE;
									if (tagCharLowerCase == 'c')
										ncharsFG -= (fastForwardCharCounter + 2); /* 2 = squares []*/
									else
										ncharsBG -=  (fastForwardCharCounter + 2); /* 2 = squares []*/
								}
								else if (insideTagFastForward) {
									fastForwardCharCounter++;
								}

							}
						} /* fine controllo gradiente */

						/* Non devo tradurre il tag di fine gradiente: */
						if (p[1] == '/' && p[3] == '=') {
							gradientTag = TRUE;
							if (tagCharLowerCase == 'c')
								gradientFG = FALSE;
							else if (tagCharLowerCase == 'a')
								gradientBG = FALSE;
						}

						/* Tag convertito ed aggiunto solo se non sono in un gradiente.
						 * Infatti in questo caso viene gestito dopo. */
						if (!gradientTag) {
							purple_debug_misc("plusblist", "Translating tag %s\n", g_strndup(p + 1, i - 1));
							replace = convert_tag(g_strndup(p + 1, i - 1));
							if (replace) {
								g_string_append(buf, replace);
							}
							g_free(replace);
						}
						break; /* Ne ho trovata una, non cerco le seguenti. */
					} /* Fine if p = ] */
				} /* Fine ciclo for per cercare la fine del tag ] */





			}
			else if (*p == ']' && insideTag) {
				insideTag = FALSE;
				continue;
			}

			if (!insideTag) {
				/* Get the next character (using utf-8) */
				gchar *thischar_unescaped, *thischar;
				thischar_unescaped = g_new0(char, 10);
				g_utf8_strncpy(thischar_unescaped, p, 1);
				thischar = g_markup_escape_text(thischar_unescaped, -1);
				g_free(thischar_unescaped);

				if (gradientFG || gradientBG) {
					/* Aggiungo i caratteri colorati del gradiente */

					int j;
					int color[3];
					char *tag, *fgAttribute = NULL, *bgAttribute = NULL;
					if (gradientFG) {
						for (j = 0; j <= 2; j++) {
							int delta = 0;
							if (ncharsFG > 1)
								delta = deltaColorFG[j] * gradientIndexFG / (ncharsFG - 1);
							color[j] = begColorFG[j] + delta;
						}
						fgAttribute = g_strdup_printf(" foreground=\"#%02x%02x%02x\"", color[0], color[1], color[2]);
					}
					else fgAttribute = g_strdup("");

					if (gradientBG) {
						for (j = 0; j <= 2; j++) {
							int delta = 0;
							if (ncharsBG > 1)
								delta = deltaColorBG[j] * gradientIndexBG / (ncharsBG - 1);
							color[j] = begColorBG[j] + delta;
						}
						bgAttribute = g_strdup_printf(" background=\"#%02x%02x%02x\"", color[0], color[1], color[2]);
					}
					else bgAttribute = g_strdup("");

					tag = g_strdup_printf("<span%s%s>%s</span>", fgAttribute, bgAttribute, thischar);
					g_free(fgAttribute);
					g_free(bgAttribute);

					g_string_append(buf, tag);
					g_free(tag);
					if (gradientFG) gradientIndexFG++;
					if (gradientBG) gradientIndexBG++;
					if (gradientIndexFG >= ncharsFG) gradientFG = FALSE;
					if (gradientIndexBG >= ncharsBG) gradientBG = FALSE;
				}
				else {
					/* Carattere normale, senza essere in un gradiente */
					g_string_append(buf, thischar);
				}
				g_free(thischar);
			}
		}
Beispiel #12
0
gboolean ly_ppl_bus_cb(GstBus *bus,GstMessage *message,gpointer data)
{
	char *tag_codec=NULL;
//	char *tag_title=NULL;
//	char *tag_artist=NULL;
//	char *tag_album=NULL;
	char *tag_comment=NULL;
	char *tag_genre=NULL;
	char *tag_lrc=NULL;
	guint tag_bitrate=0;
	guint tag_track=0;
	GstBuffer *tag_cover=NULL;
	LyMdhMetadata *md=ly_pqm_get_current_md();
	if(!md)
		return TRUE;
	
	GstTagList* tags;
	
	switch (message->type)
	{
		case GST_MESSAGE_EOS:
			ly_mbs_put("ppl_eos", "core:ppl", NULL);
			break;
		case GST_MESSAGE_TAG:
		{	
			gst_message_parse_tag(message,&tags);
			
			//codec
			if(gst_tag_list_get_string(tags,GST_TAG_AUDIO_CODEC,&tag_codec))
			{
				if(tag_codec!=NULL)
					g_strlcpy(md->codec, tag_codec, sizeof(md->codec));
				ly_mbs_put("meta_update", "core:ppl", "codec");
			}
			//comment
			if(gst_tag_list_get_string(tags,GST_TAG_COMMENT,&tag_comment))
			{
				if(g_utf8_validate(tag_comment,-1,NULL))
				{
					g_utf8_strncpy((char *)(md->comment), tag_comment, sizeof(md->comment));
				}
				g_free(tag_comment);
				ly_mbs_put("meta_update", "core:ppl", "comment");
			}
			//bitrate
			if(gst_tag_list_get_uint(tags, GST_TAG_BITRATE, &tag_bitrate))
			{
				md->bitrate = tag_bitrate;
				ly_mbs_put("meta_update", "core:ppl", "bitrate");
			}
			//track_number
			if(gst_tag_list_get_uint(tags, GST_TAG_TRACK_NUMBER, &tag_track))
			{
				md->track = tag_track;
				ly_mbs_put("meta_update", "core:ppl", "track");
			}
			//genre
			if(gst_tag_list_get_string(tags,GST_TAG_GENRE, &tag_genre))
			{
				if(g_utf8_validate(tag_genre,-1,NULL))
				{
					g_utf8_strncpy((gchar *)(md->genre),tag_genre, sizeof(md->genre));
				}
				g_free(tag_genre);
				ly_mbs_put("meta_update", "core:ppl", "genre");
			}
			//album cover
 			if(gst_tag_list_get_buffer(tags,GST_TAG_IMAGE, &tag_cover))
 			{
 				if(md->cover)
 					gst_buffer_unref(md->cover);
 				md->cover=tag_cover;
 				ly_mbs_put("meta_update", "core:ppl", "cover");
			}
			//lyrics
			if(gst_tag_list_get_string(tags,GST_TAG_LYRICS, &tag_lrc))
			{
				if(g_utf8_validate(tag_lrc,-1,NULL))
				{
					g_utf8_strncpy((gchar *)(md->lrc), tag_lrc, sizeof(md->lrc));
				}
				g_free(tag_lrc);
				ly_mbs_put("meta_update", "core:ppl", "lrc");
			}
			
			break;
			
		}
		default:
		break;
	}	
	return TRUE;
}
Beispiel #13
0
int main(int argc, char *argv[]) {
    char *p = argv[1];

    int gradientIndexFG, gradientIndexBG, ncharsFG, ncharsBG;
    int begColorFG[3], endColorFG[3], deltaColorFG[3];
    int begColorBG[3], endColorBG[3], deltaColorBG[3];
    unsigned char gradientBG = FALSE, gradientFG = FALSE, insideTag = FALSE;

    /* Ciclo di lettura caratteri */
    GString *buf = g_string_new("");
    for (; *p; p = g_utf8_next_char(p)) {
#ifdef PLUS_DEBUG
        // printf("Leggo il carattere %c\n", *p);
#endif
        if (*p == '[') {
            /* Controllo tag */

            /* Faccio un fast forward per cercare il corrispondente ],
             * determinando quindi se si tratta di un tag oppure no. */
            int i;
            for(i = 1; i < 12; i++) {
                if (p[i] == ']') {
                    char *replace;
                    char gradientTag = FALSE;

                    /* Ho trovato la fine del tag, sono dentro! */
#ifdef PLUS_DEBUG
                    printf("Primo carattere del tag: %c\n", p[1]);
#endif
                    /* Controllo gradiente */

                    /* Try to unificate c/a*/
                    char tagCharLowerCase = 0, tagCharUpperCase = 0;
                    if (p[1] == 'c' || p[1] == 'C') {
                        tagCharLowerCase = 'c';
                        tagCharUpperCase = 'C';
                    }
                    else if (p[1] == 'a' || p[1] == 'A') {
                        tagCharLowerCase = 'a';
                        tagCharUpperCase = 'A';
                    }
                    else if (p[1] == 'b' || p[1] == 'B' || p[1] == 'i' || p[1] == 'I' ||
                             p[1] == 'u' || p[1] == 'U' || p[1] == 's' || p[1] == 'S' || p[1] == '/') {
                        /* sarebbe carino fargli skippare la parte di controllo gradiente */
                    }
                    else {
                        break;
                    }
                    insideTag = TRUE;


                    if ((p[1] == tagCharLowerCase || p[1] == tagCharUpperCase) && p[2] == '=') {
                        gchar *iter = p + i + 1;
                        char insideTagFastForward = FALSE;
                        int fastForwardCharCounter = 0;
#ifdef PLUS_DEBUG
                        printf("Controllo gradienti.\n");
#endif
                        if (tagCharLowerCase == 'c') {
                            gradientFG = FALSE; /* TODO: necessario? */
                            ncharsFG = 0;
                        }
                        else {
                            gradientBG = FALSE; /* TODO: necessario? */
                            ncharsBG = 0;
                        }

                        /* Vado avanti e cerco il finale corrispondente */
                        for (; *iter; iter = g_utf8_next_char(iter)) {

                            if (iter[0] == '[' && iter[1] == '/' &&
                                    (iter[2] == tagCharLowerCase || iter[2] == tagCharUpperCase)
                               ) {
#ifdef PLUS_DEBUG
                                printf("ho trovato un finale\n");
#endif
                                if (iter[3] == '=') {
                                    gradientTag = TRUE;
                                    /*  */
                                    char *initialColor = findColor(p + 3);
                                    char *finalColor = findColor(iter + 4);
                                    if (!initialColor || !finalColor) break;

#ifdef PLUS_DEBUG
                                    printf("Colore iniziale: %s\n", initialColor);
#endif
                                    int j;
                                    for (j = 0; j <= 2; j++) {
                                        if (tagCharLowerCase == 'c') {
                                            begColorFG[j] = hexDec(initialColor + 2 * j, 2);
                                            endColorFG[j] = hexDec(finalColor + 2 * j, 2);
                                            deltaColorFG[j] = endColorFG[j] - begColorFG[j];
                                        }
                                        else {
                                            begColorBG[j] = hexDec(initialColor + 2 * j, 2);
                                            endColorBG[j] = hexDec(finalColor + 2 * j, 2);
                                            deltaColorBG[j] = endColorBG[j] - begColorBG[j];
                                        }
                                    }

#ifdef PLUS_DEBUG
                                    printf("Colore finale: %s\n", finalColor);
#endif
                                    g_free(initialColor);
                                    g_free(finalColor);

                                    if (tagCharLowerCase == 'c') {
                                        gradientFG = TRUE;
                                        gradientIndexFG = 0;
#ifdef PLUS_DEBUG
                                        printf("numero caratteri: %i\n", ncharsFG);
#endif
                                    }
                                    else {
                                        gradientBG = TRUE;
                                        gradientIndexBG = 0;
#ifdef PLUS_DEBUG
                                        printf("numero caratteri: %i\n", ncharsBG);
#endif
                                    }
                                    // Calcolare il numero di caratteri effettivi (escludendo i tag),
                                    // e suddividere il Delta R, G, B diviso il numero di caratteri,
                                    // ottenendo l'incremento da aggiungere (o sottrarre)
                                    // ad ogni carattere.
                                    // Subito PRIMA dell'ultimo carattere, mettere il colore finale.


#ifdef PLUS_DEBUG
                                    printf("gradiente\n");
#endif
                                }
                                else {
#ifdef PLUS_DEBUG
                                    printf("non gradiente\n");
#endif
                                }
                                break;
                            }
                            else {
                                if (tagCharLowerCase == 'c') ncharsFG++; // TODO: devono essere effettivi, non cosi'.
                                else ncharsBG++;
                            }

                            if (iter[0] == '[') {
                                /* sono FORSE all'interno di un tag*/
                                if (iter[1] == 'b' || iter[1] == 'B' ||
                                        iter[1] == 'i' || iter[1] == 'I' ||
                                        iter[1] == 'u' || iter[1] == 'U' ||
                                        iter[1] == 's' || iter[1] == 'S' ||
                                        iter[1] == 'a' || iter[1] == 'A' ||
                                        iter[1] == 'c' || iter[1] == 'C' ||
                                        iter[1] == '/') {
                                    insideTagFastForward = TRUE; /* TODO: non e' vero, limite massimo caratteri */
                                    fastForwardCharCounter = 0;
                                }
                            }
                            else if (iter[0] == ']' && insideTagFastForward) {
                                /* ero all'interno di un tag ed ora l'ho chiuso */
                                insideTagFastForward = FALSE;
                                if (tagCharLowerCase == 'c')
                                    ncharsFG -= (fastForwardCharCounter + 2); /* 2 = squares []*/
                                else
                                    ncharsBG -=  (fastForwardCharCounter + 2); /* 2 = squares []*/
                            }
                            else if (insideTagFastForward) {
                                fastForwardCharCounter++;
                            }

                        }
                    } /* fine controllo gradiente */

                    /* Non devo tradurre il tag di fine gradiente: */
                    if (p[1] == '/' && p[3] == '=') {
                        gradientTag = TRUE;
                        if (tagCharLowerCase == 'c')
                            gradientFG = FALSE;
                        else if (tagCharLowerCase == 'a')
                            gradientBG = FALSE;
                    }

                    /* Tag convertito ed aggiunto solo se non sono in un gradiente.
                     * Infatti in questo caso viene gestito dopo. */
                    if (!gradientTag) {
#ifdef PLUS_DEBUG
                        printf("Provo il tag %s\n", g_strndup(p + 1, i - 1));
#endif
                        replace = convert_tag(g_strndup(p + 1, i - 1));
                        if (replace) {
                            g_string_append(buf, replace);
                        }
                        g_free(replace);
                    }
                    break; /* Ne ho trovata una, non cerco le seguenti. */
                } /* Fine if p = ] */
            } /* Fine ciclo for per cercare la fine del tag ] */





        }
        else if (*p == ']' && insideTag) {
            insideTag = FALSE;
            continue;
        }

        if (!insideTag) {
            gchar *thischar_unescaped, *thischar;
            thischar_unescaped = g_new0(char, 10);
            g_utf8_strncpy(thischar_unescaped, p, 1);
            thischar = g_markup_escape_text(thischar_unescaped, -1);
            g_free(thischar_unescaped);

            if (gradientFG || gradientBG) {
                /* Aggiungo i caratteri colorati del gradiente */

                int j;
                int color[3];
                char *tag, *fgAttribute = NULL, *bgAttribute = NULL;
                if (gradientFG) {
                    for (j = 0; j <= 2; j++) {
                        int delta = 0;
                        if (ncharsFG > 1)
                            delta = deltaColorFG[j] * gradientIndexFG / (ncharsFG - 1);
                        color[j] = begColorFG[j] + delta;
#ifdef PLUS_DEBUG
//					printf("Deltacolor: %i; delta=%i; color[%i]=%i\n", deltaColor[j], delta, j, color[j]);
//					printf("delta[%i] = %i\n", j, delta);
#endif
                    }
                    fgAttribute = g_strdup_printf(" foreground=\"#%02x%02x%02x\"", color[0], color[1], color[2]);
                }
                else fgAttribute = g_strdup("");

                if (gradientBG) {
                    for (j = 0; j <= 2; j++) {
                        int delta = 0;
                        if (ncharsBG > 1)
                            delta = deltaColorBG[j] * gradientIndexBG / (ncharsBG - 1);
                        color[j] = begColorBG[j] + delta;
#ifdef PLUS_DEBUG
//					printf("Deltacolor: %i; delta=%i; color[%i]=%i\n", deltaColor[j], delta, j, color[j]);
//					printf("delta[%i] = %i\n", j, delta);
#endif
                    }
                    bgAttribute = g_strdup_printf(" background=\"#%02x%02x%02x\"", color[0], color[1], color[2]);
                }
                else bgAttribute = g_strdup("");
#ifdef PLUS_DEBUG
                // printf("%s\n", g_utf8_offset_to_pointer(p, 2));
#endif

                tag = g_strdup_printf("<span%s%s>%s</span>", fgAttribute, bgAttribute, thischar);

                g_free(fgAttribute);
                g_free(bgAttribute);

                g_string_append(buf, tag);
                g_free(tag);
                if (gradientFG) gradientIndexFG++;
                if (gradientBG) gradientIndexBG++;
                if (gradientIndexFG >= ncharsFG) gradientFG = FALSE;
                if (gradientIndexBG >= ncharsBG) gradientBG = FALSE;
            }
            else {
                /* Carattere normale, senza essere in un gradiente */
                g_string_append(buf, thischar);
            }
            g_free(thischar);
        }
    }
Beispiel #14
0
gboolean
nimf_libhangul_filter_event (NimfEngine    *engine,
                             NimfServiceIC *target,
                             NimfEvent     *event)
{
  g_debug (G_STRLOC ": %s", G_STRFUNC);

  guint    keyval;
  gboolean retval = FALSE;

  NimfLibhangul *hangul = NIMF_LIBHANGUL (engine);

  if (event->key.type   == NIMF_EVENT_KEY_RELEASE ||
      event->key.keyval == NIMF_KEY_Shift_L       ||
      event->key.keyval == NIMF_KEY_Shift_R)
    return FALSE;

  if (event->key.state & (NIMF_CONTROL_MASK | NIMF_MOD1_MASK))
  {
    nimf_libhangul_reset (engine, target);
    return FALSE;
  }

  if (G_UNLIKELY (nimf_event_matches (event,
                  (const NimfKey **) hangul->hanja_keys)))
  {
    if (nimf_candidatable_is_visible (hangul->candidatable) == FALSE)
    {
      gchar item[4];
      const char *key = hangul->preedit_string;
      gboolean use_preedit;

      if (hangul->preedit_string[0] == 0)
      {
        gchar *text;
        gint   cursor_pos;

        nimf_engine_get_surrounding (engine, target, &text, &cursor_pos);

        if (text && cursor_pos > 0)
        {
          gchar *p = g_utf8_offset_to_pointer (text, cursor_pos - 1);
          g_utf8_strncpy (item, p, 1);

          if (g_utf8_validate (item, -1, NULL))
            key = item;
        }

        g_free (text);
      }

      hanja_list_delete (hangul->hanja_list);
      nimf_candidatable_clear (hangul->candidatable, target);
      hangul->hanja_list = hanja_table_match_exact (nimf_libhangul_hanja_table, key);

      if (hangul->hanja_list == NULL)
        hangul->hanja_list = hanja_table_match_exact (nimf_libhangul_symbol_table, key);

      hangul->n_pages = (hanja_list_get_size (hangul->hanja_list) + 9) / 10;
      hangul->current_page = 1;
      nimf_libhangul_update_page (engine, target);
      use_preedit = nimf_service_ic_get_use_preedit (target);

      if (!use_preedit)
        nimf_candidatable_set_auxiliary_text (hangul->candidatable,
                                              key, g_utf8_strlen (key, -1));

      nimf_candidatable_show (hangul->candidatable, target, !use_preedit);
      nimf_candidatable_select_first_item_in_page (hangul->candidatable);
    }
    else
    {
      nimf_candidatable_hide (hangul->candidatable);
      nimf_candidatable_clear (hangul->candidatable, target);
      hanja_list_delete (hangul->hanja_list);
      hangul->hanja_list = NULL;
      hangul->current_page = 0;
      hangul->n_pages = 0;
    }

    return TRUE;
  }

  if (nimf_candidatable_is_visible (hangul->candidatable))
  {
    switch (event->key.keyval)
    {
      case NIMF_KEY_Return:
      case NIMF_KEY_KP_Enter:
        {
          gchar *text;

          text = nimf_candidatable_get_selected_text (hangul->candidatable);
          on_candidate_clicked (engine, target, text, -1);

          g_free (text);
        }
        break;
      case NIMF_KEY_Up:
      case NIMF_KEY_KP_Up:
        nimf_candidatable_select_previous_item (hangul->candidatable);
        break;
      case NIMF_KEY_Down:
      case NIMF_KEY_KP_Down:
        nimf_candidatable_select_next_item (hangul->candidatable);
        break;
      case NIMF_KEY_Page_Up:
      case NIMF_KEY_KP_Page_Up:
        nimf_libhangul_page_up (engine, target);
        break;
      case NIMF_KEY_Page_Down:
      case NIMF_KEY_KP_Page_Down:
        nimf_libhangul_page_down (engine, target);
        break;
      case NIMF_KEY_Home:
        nimf_libhangul_page_home (engine, target);
        break;
      case NIMF_KEY_End:
        nimf_libhangul_page_end (engine, target);
        break;
      case NIMF_KEY_Escape:
        nimf_candidatable_hide (hangul->candidatable);
        break;
      case NIMF_KEY_0:
      case NIMF_KEY_1:
      case NIMF_KEY_2:
      case NIMF_KEY_3:
      case NIMF_KEY_4:
      case NIMF_KEY_5:
      case NIMF_KEY_6:
      case NIMF_KEY_7:
      case NIMF_KEY_8:
      case NIMF_KEY_9:
      case NIMF_KEY_KP_0:
      case NIMF_KEY_KP_1:
      case NIMF_KEY_KP_2:
      case NIMF_KEY_KP_3:
      case NIMF_KEY_KP_4:
      case NIMF_KEY_KP_5:
      case NIMF_KEY_KP_6:
      case NIMF_KEY_KP_7:
      case NIMF_KEY_KP_8:
      case NIMF_KEY_KP_9:
        {
          if (hangul->hanja_list == NULL || hangul->current_page < 1)
            break;

          gint i, n;
          gint list_len = hanja_list_get_size (hangul->hanja_list);

          if (event->key.keyval >= NIMF_KEY_0 &&
              event->key.keyval <= NIMF_KEY_9)
            n = (event->key.keyval - NIMF_KEY_0 + 9) % 10;
          else if (event->key.keyval >= NIMF_KEY_KP_0 &&
                   event->key.keyval <= NIMF_KEY_KP_9)
            n = (event->key.keyval - NIMF_KEY_KP_0 + 9) % 10;
          else
            break;

          i = (hangul->current_page - 1) * 10 + n;

          if (i < MIN (hangul->current_page * 10, list_len))
          {
            const Hanja *hanja = hanja_list_get_nth (hangul->hanja_list, i);
            const char  *text = hanja_get_value (hanja);
            on_candidate_clicked (engine, target, (gchar *) text, -1);
          }
        }
        break;
      default:
        break;
    }

    return TRUE;
  }

  const ucschar *ucs_commit;
  const ucschar *ucs_preedit;

  if (G_UNLIKELY (event->key.keyval == NIMF_KEY_BackSpace))
  {
    retval = hangul_ic_backspace (hangul->context);

    if (retval)
    {
      ucs_preedit = hangul_ic_get_preedit_string (hangul->context);
      gchar *new_preedit = g_ucs4_to_utf8 (ucs_preedit, -1, NULL, NULL, NULL);
      nimf_libhangul_update_preedit (engine, target, new_preedit);
    }

    return retval;
  }

  if (G_UNLIKELY (g_strcmp0 (hangul->method, "ro") == 0))
    keyval = event->key.keyval;
  else
    keyval = nimf_event_keycode_to_qwerty_keyval (event);

  if (!hangul->is_double_consonant_rule &&
      (g_strcmp0 (hangul->method, "2") == 0) &&
      nimf_libhangul_filter_leading_consonant (engine, target, keyval))
    return TRUE;

  retval = hangul_ic_process (hangul->context, keyval);

  ucs_commit  = hangul_ic_get_commit_string  (hangul->context);
  ucs_preedit = hangul_ic_get_preedit_string (hangul->context);

  gchar *new_commit  = g_ucs4_to_utf8 (ucs_commit,  -1, NULL, NULL, NULL);

  if (ucs_commit[0] != 0)
    nimf_libhangul_emit_commit (engine, target, new_commit);

  g_free (new_commit);

  gchar *new_preedit = g_ucs4_to_utf8 (ucs_preedit, -1, NULL, NULL, NULL);
  nimf_libhangul_update_preedit (engine, target, new_preedit);

  return retval;
}
Beispiel #15
0
static int
key_action_tab_comp (GtkWidget *t, GdkEventKey *entry, char *d1, char *d2,
							struct session *sess)
{
	int len = 0, elen = 0, i = 0, cursor_pos, ent_start = 0, comp = 0, prefix_len, skip_len = 0;
	gboolean is_nick = FALSE, is_cmd = FALSE, found = FALSE, has_nick_prefix = FALSE;
	char ent[CHANLEN], *postfix = NULL, *result, *ch;
	GList *list = NULL, *tmp_list = NULL;
	const char *text;
	GCompletion *gcomp = NULL;
	GString *buf;

	/* force the IM Context to reset */
	SPELL_ENTRY_SET_EDITABLE (t, FALSE);
	SPELL_ENTRY_SET_EDITABLE (t, TRUE);

	text = SPELL_ENTRY_GET_TEXT (t);
	if (text[0] == 0)
		return 1;

	len = g_utf8_strlen (text, -1); /* must be null terminated */

	cursor_pos = SPELL_ENTRY_GET_POS (t);

	/* handle "nick: " or "nick " or "#channel "*/
	ch = g_utf8_find_prev_char(text, g_utf8_offset_to_pointer(text,cursor_pos));
	if (ch && ch[0] == ' ')
	{
		skip_len++;
		ch = g_utf8_find_prev_char(text, ch);
		if (!ch)
			return 2;

		cursor_pos = g_utf8_pointer_to_offset(text, ch);
		if (cursor_pos && (g_utf8_get_char_validated(ch, -1) == ':' || 
					g_utf8_get_char_validated(ch, -1) == ',' ||
					g_utf8_get_char_validated (ch, -1) == g_utf8_get_char_validated (prefs.hex_completion_suffix, -1)))
		{
			skip_len++;
		}
		else
			cursor_pos = g_utf8_pointer_to_offset(text, g_utf8_offset_to_pointer(ch, 1));
	}

	comp = skip_len;
	
	/* store the text following the cursor for reinsertion later */
	if ((cursor_pos + skip_len) < len)
		postfix = g_utf8_offset_to_pointer(text, cursor_pos + skip_len);

	for (ent_start = cursor_pos; ; --ent_start)
	{
		if (ent_start == 0)
			break;
		ch = g_utf8_offset_to_pointer(text, ent_start - 1);
		if (ch && ch[0] == ' ')
			break;
	}

	if (ent_start == 0 && text[0] == prefs.hex_input_command_char[0])
	{
		ent_start++;
		is_cmd = TRUE;
	}
	else if (strchr (sess->server->chantypes, text[ent_start]) == NULL)
	{
		is_nick = TRUE;
		if (strchr (sess->server->nick_prefixes, text[ent_start]) != NULL)
		{
			if (ent_start == 0)
				has_nick_prefix = TRUE;
			ent_start++;
		}
	}

	prefix_len = ent_start;
	elen = cursor_pos - ent_start;

	g_utf8_strncpy (ent, g_utf8_offset_to_pointer (text, prefix_len), elen);
	
	if (sess->type == SESS_DIALOG && is_nick)
	{
		/* tab in a dialog completes the other person's name */
		if (rfc_ncasecmp (sess->channel, ent, elen) == 0)
		{
			result =  sess->channel;
			is_nick = FALSE;
		}
		else
			return 2;
	}
	else
	{
		if (is_nick)
		{
			gcomp = g_completion_new((GCompletionFunc)gcomp_nick_func);
			tmp_list = userlist_double_list(sess); /* create a temp list so we can free the memory */
			if (prefs.hex_completion_sort == 1)	/* sort in last-talk order? */
				tmp_list = g_list_sort (tmp_list, (void *)talked_recent_cmp);
		}
		else
		{
			gcomp = g_completion_new (NULL);
			if (is_cmd)
			{
				tmp_list = cmdlist_double_list (command_list);
				for(i = 0; xc_cmds[i].name != NULL ; i++)
				{
					tmp_list = g_list_prepend (tmp_list, xc_cmds[i].name);
				}
				tmp_list = plugin_command_list(tmp_list);
			}
			else
				tmp_list = chanlist_double_list (sess_list);
		}
		tmp_list = g_list_reverse(tmp_list); /* make the comp entries turn up in the right order */
		g_completion_set_compare (gcomp, (GCompletionStrncmpFunc)rfc_ncasecmp);
		if (tmp_list)
		{
			g_completion_add_items (gcomp, tmp_list);
			g_list_free (tmp_list);
		}

		if (comp && !(rfc_ncasecmp(old_gcomp.data, ent, old_gcomp.elen) == 0))
		{
			key_action_tab_clean ();
			comp = 0;
		}
	
		list = g_completion_complete_utf8 (gcomp, comp ? old_gcomp.data : ent, &result);
		
		if (result == NULL) /* No matches found */
		{
			g_completion_free(gcomp);
			return 2;
		}

		if (comp) /* existing completion */
		{
			while(list) /* find the current entry */
			{
				if(rfc_ncasecmp(list->data, ent, elen) == 0)
				{
					found = TRUE;
					break;
				}
				list = list->next;
			}

			if (found)
			{
				if (!(d1 && d1[0])) /* not holding down shift */
				{
					if (g_list_next(list) == NULL)
						list = g_list_first(list);
					else
						list = g_list_next(list);
				}
				else
				{
					if (g_list_previous(list) == NULL)
						list = g_list_last(list);
					else
						list = g_list_previous(list);
				}
				g_free(result);
				result = (char*)list->data;
			}
			else
			{
				g_free(result);
				g_completion_free(gcomp);
				return 2;
			}
		}
		else
		{
			strcpy(old_gcomp.data, ent);
			old_gcomp.elen = elen;

			/* Get the first nick and put out the data for future nickcompletes */
			if (prefs.hex_completion_amount > 0 && g_list_length (list) <= (guint) prefs.hex_completion_amount)
			{
				g_free(result);
				result = (char*)list->data;
			}
			else
			{
				/* bash style completion */
				if (g_list_next(list) != NULL)
				{
					buf = g_string_sized_new (MAX(COMP_BUF, len + NICKLEN));
					if (strlen (result) > elen) /* the largest common prefix is larger than nick, change the data */
					{
						if (prefix_len)
							g_string_append_len (buf, text, offset_to_len (text, prefix_len));
						g_string_append (buf, result);
						cursor_pos = buf->len;
						g_free(result);
						if (postfix)
						{
							g_string_append_c (buf, ' ');
							g_string_append (buf, postfix);
						}
						SPELL_ENTRY_SET_TEXT (t, buf->str);
						SPELL_ENTRY_SET_POS (t, len_to_offset (buf->str, cursor_pos));
						g_string_erase (buf, 0, -1);
					}
					else
						g_free(result);

					while (list)
					{
						len = buf->len;
						elen = strlen (list->data);	/* next item to add */
						if (len + elen + 2 >= COMP_BUF) /* +2 is space + null */
						{
							PrintText (sess, buf->str);
							g_string_erase (buf, 0, -1);
						}
						g_string_append (buf, (char*)list->data);
						g_string_append_c (buf, ' ');
						list = list->next;
					}
					PrintText (sess, buf->str);
					g_completion_free(gcomp);
					g_string_free (buf, TRUE);
					return 2;
				}
				/* Only one matching entry */
				g_free(result);
				result = list->data;
			}
		}
	}
	
	if(result)
	{
		buf = g_string_sized_new (len + NICKLEN);
		if (prefix_len)
			g_string_append_len (buf, text, offset_to_len (text, prefix_len));
		g_string_append (buf, result);
		if((!prefix_len || has_nick_prefix) && is_nick && prefs.hex_completion_suffix[0] != '\0')
			g_string_append_unichar (buf, g_utf8_get_char_validated (prefs.hex_completion_suffix, -1));
		g_string_append_c (buf, ' ');
		cursor_pos = buf->len;
		if (postfix)
			g_string_append (buf, postfix);
		SPELL_ENTRY_SET_TEXT (t, buf->str);
		SPELL_ENTRY_SET_POS (t, len_to_offset (buf->str, cursor_pos));
		g_string_free (buf, TRUE);
	}
	if (gcomp)
		g_completion_free(gcomp);
	return 2;
}
MYX_GRT_VALUE * query_print(MYX_GRT_VALUE *param, void *data)
{
  MYX_GRT *grt= (MYX_GRT *)data;
  MYX_GRT_VALUE *value, *error;
  const char *sql;

  MYX_GRT_CONNECTION *mysql_conn;
  MYSQL_RES *res;

  /*unsigned int i, field_count;
  char *s, *s2;*/

  unsigned int off;
  MYSQL_ROW cur;
  MYSQL_FIELD *field;
  unsigned int line_width= 4;
  char *line_sep;
  char *line;
  char *buf;
  int do_break= FALSE;
  char *tmp_utf8= g_malloc(MAX_COLUMN_LENGTH*2+1);
  unsigned long row_nr= 0;

  if (myx_grt_list_item_count(param) != 2)
    return make_return_value_error("This function takes (db.query.mysql.Connection, sql) as parameters.", "");

  value= myx_grt_list_item_get(param, 0);
  sql= myx_grt_list_item_get_as_string(param, 1);

  // retrieve MYSQL * from the bridge_data_object
  mysql_conn= myx_grt_value_bridge_data_object_get(value);

  if (!mysql_conn)
    return make_return_value_error("The connection has not been established. Use Rdbms:connect() to open the connection.", "");

  error= grt_mysql_execute(mysql_conn->mysql, &res, sql, "Could not execute the given statement.");
  if (error)
  {
    myx_grt_messages_stack_add(grt, 0, myx_grt_dict_item_get_as_string(error, "error"), NULL, 0, -1);
    myx_grt_messages_stack_add(grt, 0, myx_grt_dict_item_get_as_string(error, "detail"), NULL, 0, -1);

    myx_grt_messages_stack_flush(grt, 0);

    return error;
  }

  // ------------------------------------------
  // print fields

  // calc line width
  while ((field= mysql_fetch_field(res)))
  {
#if MYSQL_VERSION_ID < 40100
    unsigned int length= (field->name != 0 ? strnlen(field->name, field->max_length) : 0);
#else
    unsigned int length= field->name_length;
#endif

    length= MAX(length,field->max_length);
    length*= 2; //consider UTF8 2-byte chars
    if (length < 4 && !IS_NOT_NULL(field->flags))
      length=4;                                 // Room for "NULL"
    field->max_length=length+1;

    line_width+= length+3;
  }

  // build line separator
  line_sep= g_malloc(sizeof(char)*(line_width+1));
  strcpy(line_sep, "+");
  mysql_field_seek(res, 0);
  while ((field= mysql_fetch_field(res)))
  {
    fill_char(line_sep+strlen(line_sep), '-', MIN((int)field->max_length+1, MAX_COLUMN_LENGTH+1));
    strcat(line_sep,"+");
  }
  myx_grt_messages_stack_add(grt, 0, line_sep, NULL, 0, -1);

  // output column names
  mysql_field_seek(res,0);

  line= g_strdup("|");
  buf= g_malloc(MAX_COLUMN_LENGTH * 2 + 1);

  while ((field= mysql_fetch_field(res)))
  {
    char *field_name= myx_convert_dbstr_utf8(mysql_conn->mysql, field->name, field->name_length);

    sprintf(buf, " %-*s|", MIN((int)field->max_length, MAX_COLUMN_LENGTH),
              field_name);

    line= str_g_append(line, buf);

    g_free(field_name);
  }

  g_free(buf);

  myx_grt_messages_stack_add(grt, 0, line, NULL, 0, -1);

  g_free(line);

  myx_grt_messages_stack_add(grt, 0, line_sep, NULL, 0, -1);


  line= g_malloc(sizeof(char)*(line_width+1));
  
  // output rows
  while ((cur= mysql_fetch_row(res)) && (!do_break))
  {
    char *line_end= line;
    strcpy(line, "|");
    line_end++;

    mysql_field_seek(res, 0);
    for (off= 0; off < mysql_num_fields(res); off++)
    {
      unsigned int length, u8length, clength;
      char *field_value;
      
      if(cur[off])
        field_value= myx_convert_dbstr_utf8(mysql_conn->mysql, cur[off], -1);
      else
        field_value= g_strdup("NULL");

      field_value= str_g_replace(field_value, "\r\n", "\xc2\xab\xc2\xb6");
      field_value= str_g_replace(field_value, "\n", "\xc2\xb6");

      field= mysql_fetch_field(res);
      length= field->max_length;
      
      // compensage difference between bytecount and utf8 char count
      clength= (unsigned int)strlen(field_value);
      u8length= g_utf8_strlen(field_value, clength);
      length+= clength-u8length;

      if (u8length > MAX_COLUMN_LENGTH)
      {
        //Clear buffer
        memset(tmp_utf8, 0, MAX_COLUMN_LENGTH*2+1);

        tmp_utf8= g_utf8_strncpy(tmp_utf8, field_value, MAX_COLUMN_LENGTH-1);

        strcpy(line_end, " ");
        line_end++;
        g_utf8_strncpy(line_end, field_value, MAX_COLUMN_LENGTH-1);
        line_end+= strlen(tmp_utf8);
        strcpy(line_end, ">|");
        line_end+= 2;
      }
      else
      {
        line_end+= sprintf(line_end, IS_NUM(field->type) ? "%*s |" : " %-*s|",
                MIN(length, MAX_COLUMN_LENGTH+clength-u8length), field_value);
        //line_end+= strlen(line_end);
      }

      g_free(field_value);
    }

    myx_grt_messages_stack_add(grt, 0, line, NULL, 0, -1);

    row_nr++;

    if (row_nr % 20 == 0)
      myx_grt_messages_stack_flush(grt, 0);
  }

  if(!do_break)
    myx_grt_messages_stack_add(grt, 0, line_sep, NULL, 0, -1);
  else
  {
    myx_grt_messages_stack_add(grt, 0, "Ctrl+C pressed, cleaning up buffer ...\n", NULL, 0, -1);

    //Finish fetching rows
    while ((cur= mysql_fetch_row(res)))
      ;

    myx_grt_messages_stack_add(grt, 0, "Buffer cleaned up.", NULL, 0, -1);
  }
  g_free(line_sep);
  g_free(tmp_utf8);

  myx_grt_messages_stack_flush(grt, 0);

  return NULL;
}
Beispiel #17
0
int dt_control_key_pressed_override(guint key, guint state)
{
  dt_control_accels_t *accels = &darktable.control->accels;

  // TODO: if darkroom mode
  // did a : vim-style command start?
  static GList *autocomplete = NULL;
  static char vimkey_input[256];
  if(darktable.control->vimkey_cnt)
  {
    guchar unichar = gdk_keyval_to_unicode(key);
    if(key == GDK_KEY_Return)
    {
      if(!strcmp(darktable.control->vimkey, ":q"))
      {
        dt_control_quit();
      }
      else
      {
        dt_bauhaus_vimkey_exec(darktable.control->vimkey);
      }
      darktable.control->vimkey[0] = 0;
      darktable.control->vimkey_cnt = 0;
      dt_control_log_ack_all();
      g_list_free(autocomplete);
      autocomplete = NULL;
    }
    else if(key == GDK_KEY_Escape)
    {
      darktable.control->vimkey[0] = 0;
      darktable.control->vimkey_cnt = 0;
      dt_control_log_ack_all();
      g_list_free(autocomplete);
      autocomplete = NULL;
    }
    else if(key == GDK_KEY_BackSpace)
    {
      darktable.control->vimkey_cnt
          -= (darktable.control->vimkey + darktable.control->vimkey_cnt)
             - g_utf8_prev_char(darktable.control->vimkey + darktable.control->vimkey_cnt);
      darktable.control->vimkey[darktable.control->vimkey_cnt] = 0;
      if(darktable.control->vimkey_cnt == 0)
        dt_control_log_ack_all();
      else
        dt_control_log("%s", darktable.control->vimkey);
      g_list_free(autocomplete);
      autocomplete = NULL;
    }
    else if(key == GDK_KEY_Tab)
    {
      // TODO: also support :preset and :get?
      // auto complete:
      if(darktable.control->vimkey_cnt < 5)
      {
        g_strlcpy(darktable.control->vimkey, ":set ", sizeof(darktable.control->vimkey));
        darktable.control->vimkey_cnt = 5;
      }
      else if(!autocomplete)
      {
        // TODO: handle '.'-separated things separately
        // this is a static list, and tab cycles through the list
        g_strlcpy(vimkey_input, darktable.control->vimkey + 5, sizeof(vimkey_input));
        autocomplete = dt_bauhaus_vimkey_complete(darktable.control->vimkey + 5);
        autocomplete = g_list_append(autocomplete, vimkey_input); // remember input to cycle back
      }
      if(autocomplete)
      {
        // pop first.
        // the paths themselves are owned by bauhaus,
        // no free required.
        snprintf(darktable.control->vimkey, sizeof(darktable.control->vimkey), ":set %s",
                 (char *)autocomplete->data);
        autocomplete = g_list_remove(autocomplete, autocomplete->data);
        darktable.control->vimkey_cnt = strlen(darktable.control->vimkey);
      }
      dt_control_log("%s", darktable.control->vimkey);
    }
    else if(g_unichar_isprint(unichar)) // printable unicode character
    {
      gchar utf8[6];
      gint char_width = g_unichar_to_utf8(unichar, utf8);
      if(darktable.control->vimkey_cnt + 1 + char_width < 256)
      {
        g_utf8_strncpy(darktable.control->vimkey + darktable.control->vimkey_cnt, utf8, 1);
        darktable.control->vimkey_cnt += char_width;
        darktable.control->vimkey[darktable.control->vimkey_cnt] = 0;
        dt_control_log("%s", darktable.control->vimkey);
        g_list_free(autocomplete);
        autocomplete = NULL;
      }
    }
    else if(key == GDK_KEY_Up)
    {
      // TODO: step history up and copy to vimkey
    }
    else if(key == GDK_KEY_Down)
    {
      // TODO: step history down and copy to vimkey
    }
    return 1;
  }
  else if(key == ':' && darktable.control->key_accelerators_on)
  {
    darktable.control->vimkey[0] = ':';
    darktable.control->vimkey[1] = 0;
    darktable.control->vimkey_cnt = 1;
    dt_control_log("%s", darktable.control->vimkey);
    return 1;
  }

  /* check if key accelerators are enabled*/
  if(darktable.control->key_accelerators_on != 1) return 0;

  if(key == accels->global_sideborders.accel_key && state == accels->global_sideborders.accel_mods)
  {
    /* toggle panel viewstate */
    dt_ui_toggle_panels_visibility(darktable.gui->ui);

    /* trigger invalidation of centerview to reprocess pipe */
    dt_dev_invalidate(darktable.develop);
    gtk_widget_queue_draw(dt_ui_center(darktable.gui->ui));
    return 1;
  }
  else if(key == accels->global_header.accel_key && state == accels->global_header.accel_mods)
  {
    char param[512];
    const dt_view_t *cv = dt_view_manager_get_current_view(darktable.view_manager);

    /* do nothing if in collapse panel state
       TODO: reconsider adding this check to ui api */
    g_snprintf(param, sizeof(param), "%s/ui/panel_collaps_state", cv->module_name);
    if(dt_conf_get_int(param)) return 0;

    /* toggle the header visibility state */
    g_snprintf(param, sizeof(param), "%s/ui/show_header", cv->module_name);
    gboolean header = !dt_conf_get_bool(param);
    dt_conf_set_bool(param, header);

    /* show/hide the actual header panel */
    dt_ui_panel_show(darktable.gui->ui, DT_UI_PANEL_TOP, header, TRUE);
    gtk_widget_queue_draw(dt_ui_center(darktable.gui->ui));
    return 1;
  }
  return 0;
}
Beispiel #18
0
gboolean	ly_mdh_new_with_uri_bus_cb	(GstBus *bus, GstMessage *message, gpointer data)
{
	LyMdhMetadata *md=data;

	char *tag_title=NULL;
	char *tag_artist=NULL;
	char *tag_album=NULL;

	if(md==NULL) return TRUE;
	if(md->uri==NULL) return TRUE;

	switch(GST_MESSAGE_TYPE(message))
	{
		case GST_MESSAGE_EOS:
		{
			ly_mdh_md_eos=TRUE;
			return TRUE;
		}
		case GST_MESSAGE_ERROR:
		{
			ly_mdh_md_eos=TRUE;
			return TRUE;
		}
		case GST_MESSAGE_TAG:
		{
			GstTagList *tags;
			gst_message_parse_tag(message,&tags);
			//title
			if(gst_tag_list_get_string(tags,GST_TAG_TITLE,&tag_title))
			{
				if(g_utf8_validate(tag_title,-1,NULL))
				{
					g_utf8_strncpy((char *)(md->title),tag_title, sizeof(md->title));
				}
				g_free(tag_title);
			}
			//artist
			if(gst_tag_list_get_string(tags,GST_TAG_ARTIST,&tag_artist))
			{
				if(g_utf8_validate(tag_artist,-1,NULL))
				{
					g_utf8_strncpy((char *)(md->artist), tag_artist, sizeof(md->artist));
				}
				g_free(tag_artist);
			}
			//album
			if(gst_tag_list_get_string(tags,GST_TAG_ALBUM,&tag_album))
			{
				if(g_utf8_validate(tag_album,-1,NULL))
				{
					g_utf8_strncpy((char *)(md->album), tag_album, sizeof(md->album));
				}
				g_free(tag_album);
			}
			gst_tag_list_free(tags);
			return TRUE;
			break;
		}
		case GST_MESSAGE_ELEMENT:
			break;
		default:
			break;
	}
	return FALSE;
}