예제 #1
0
파일: test.c 프로젝트: Zebu78/perso
int main(void)
{
	CURL		*curl;
	char 		*buffer = malloc(10000);
	time_t		curtime;
	char		*date = malloc(100);
	char		url[1000];
	jsmntok_t	tokens[MAX_TOK];
	t_calendar	*lst = NULL;
	t_conf		*conf = malloc(sizeof(t_conf));
	t_serv		udp_serv;

	/* INIT */
	time(&curtime);
	bzero(&udp_serv, sizeof(t_serv));
	curl = curl_easy_init();
	get_time(&date, curtime);
	conf_update(conf, url, date);
	curl_easy_setopt(curl, CURLOPT_URL, url);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
	init_serveur_udp(&udp_serv);


	if(!curl)
		exit(0);
	while(1)
	{
		if (check_notif(&udp_serv))
		{
			if (udp_serv.mesg[0] == 'U')
				printf("i'll update calendar\n");
			else if (udp_serv.mesg[0] == 'P')
				printf("Someone is looking for me PING MODE on\n");
			printf("{%s}\n",udp_serv.mesg);
			curl_easy_perform(curl);				/* getting info from webservice with curl */
			json_parse(buffer, tokens);				/* parsing data from curl's buffer in the tokken's struct */
			//clean_calendar(lst);
			lst = update_calendar(buffer, tokens);	/* on clean l'ancien calendar et on update un nouveau */
			break ;
		}
		usleep(500000);
	}


	printf("%s\n\n",buffer);
	print_lst(lst);
	printf(" %lu\n", curtime);
	curl_easy_cleanup(curl);
	return 0;
}
void
tpaw_calendar_button_set_date (TpawCalendarButton *self,
    GDate *date)
{
  if (date == self->priv->date)
    return;

  tp_clear_pointer (&self->priv->date, g_date_free);

  if (date != NULL)
    {
      /* There is no g_date_copy()... */
      self->priv->date = g_date_new_dmy (date->day, date->month, date->year);
    }

  update_label (self);
  update_calendar (self);

  g_signal_emit (self, signals[DATE_CHANGED], 0, self->priv->date);
}
static void
tpaw_calendar_button_date_clicked (GtkButton *button,
    TpawCalendarButton *self)
{
  if (self->priv->dialog == NULL)
    {
      GtkWidget *parent, *content;

      parent = gtk_widget_get_toplevel (GTK_WIDGET (button));

      self->priv->dialog = gtk_dialog_new_with_buttons (NULL,
          GTK_WINDOW (parent), GTK_DIALOG_MODAL,
          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
          _("_Select"), GTK_RESPONSE_OK,
          NULL);

      gtk_window_set_transient_for (GTK_WINDOW (self->priv->dialog),
          GTK_WINDOW (parent));

      self->priv->calendar = gtk_calendar_new ();

      update_calendar (self);

      content = gtk_dialog_get_content_area (GTK_DIALOG (self->priv->dialog));

      gtk_box_pack_start (GTK_BOX (content), self->priv->calendar, TRUE, TRUE,
          6);
      gtk_widget_show (self->priv->calendar);

      g_signal_connect (self->priv->dialog, "response",
          G_CALLBACK (dialog_response), self);
      g_signal_connect (self->priv->dialog, "destroy",
          G_CALLBACK (dialog_destroy), self);
    }

  gtk_window_present (GTK_WINDOW (self->priv->dialog));
}