Пример #1
0
/**
 * pk_iso8601_to_date: (skip)
 * @iso_date: The ISO8601 date to convert
 *
 * Return value: If valid then a new %GDate, else NULL
 *
 * Since: 0.5.2
 **/
GDate *
pk_iso8601_to_date (const gchar *iso_date)
{
	gboolean ret = FALSE;
	guint retval;
	guint d = 0;
	guint m = 0;
	guint y = 0;
	GTimeVal time_val;
	GDate *date = NULL;

	if (iso_date == NULL || iso_date[0] == '\0')
		goto out;

	/* try to parse complete ISO8601 date */
	if (g_strstr_len (iso_date, -1, " ") != NULL)
		ret = g_time_val_from_iso8601 (iso_date, &time_val);
	if (ret && time_val.tv_sec != 0) {
		g_debug ("Parsed %s %i", iso_date, ret);
		date = g_date_new ();
		g_date_set_time_val (date, &time_val);
		goto out;
	}

	/* g_time_val_from_iso8601() blows goats and won't
	 * accept a valid ISO8601 formatted date without a
	 * time value - try and parse this case */
	retval = sscanf (iso_date, "%u-%u-%u", &y, &m, &d);
	if (retval != 3)
		goto out;

	/* check it's valid */
	ret = g_date_valid_dmy (d, m, y);
	if (!ret)
		goto out;

	/* create valid object */
	date = g_date_new_dmy (d, m, y);
out:
	return date;
}
Пример #2
0
static void date_changed_cb (AnnumShellWindow *self,
			     GnomeCalendarViewType view,
			     AnnumShellView *shell_view)
{
	const char *view_id;
	ECalendar *date_navigator;
	GDate *today;
	GDate start;
	GDate end;

	if (view != GNOME_CAL_DAY_VIEW)
		return;

	/* Week_View also uses GNOME_CAL_DAY_VIEW, so make sure */
	view_id = e_shell_view_get_view_id (E_SHELL_VIEW (shell_view));
	if (!g_strcmp0 (view_id, "Week_View"))
		return;

	/* DAY_VIEW is treated specially, because we only want to have
	 * the button toggled if we are showing today, not any other
	 * day
	 */

	date_navigator = annum_shell_sidebar_get_date_navigator (ANNUM_SHELL_SIDEBAR (self->priv->sidebar));

	today = g_date_new ();
	g_date_set_time_t (today, time (NULL));

	e_calendar_item_get_selection (date_navigator->calitem,
				       &start, &end);

	if (g_date_compare (today, &start) || g_date_compare (&start, &end)) {
		GtkAction *action = gtk_action_group_get_action (self->priv->action_group,
								 "ShowDay");
		gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action),
						    ANNUM_VIEW_DAY);
	}

	g_date_free (today);
}
Пример #3
0
GncDenseCalStore*
gnc_dense_cal_store_new(int num_marks)
{
    GncDenseCalStore *model = g_object_new(GNC_TYPE_DENSE_CAL_STORE, NULL);
    model->num_marks = num_marks;
    model->cal_marks = g_new0(GDate*, num_marks);
    {
        int i = 0;
        for (i = 0; i < model->num_marks; i++)
        {
            model->cal_marks[i] = g_date_new();
        }
    }
    model->num_real_marks = 0;
    g_date_clear(&model->start_date, 1);
    gnc_gdate_set_today (&model->start_date);
    model->end_type = NEVER_END;
    g_date_clear(&model->end_date, 1);
    gnc_gdate_set_today (&model->end_date);
    model->n_occurrences = 0;
    return model;
}
Пример #4
0
gboolean before_date(time_t msg_mtime, const gchar* before) {
    gchar*      pos = NULL;
    GDate*      date;
    GDate*      file_t;
    gboolean    res;
#if !GLIB_CHECK_VERSION(2,10,0)
    GTime       gtime;
#endif

    debug_print("Cut-off date: %s\n", before);
    if ((date = iso2GDate(before)) == NULL) {
        g_warning("Bad date format: %s\n", before);
        return FALSE;
    }

    file_t = g_date_new();
#if GLIB_CHECK_VERSION(2,10,0)
    g_date_set_time_t(file_t, msg_mtime);
#else
    gtime = (GTime) msg_mtime;
    g_date_set_time(file_t, gtime);
#endif

    if (debug_get_mode()) {
        pos = g_new0(char, 100);
        g_date_strftime(pos, 100, "%F", file_t);
        fprintf(stderr, "File date: %s\n", pos);
        g_free(pos);
    }

    if (! g_date_valid(file_t)) {
        g_warning("Invalid msg date\n");
        return FALSE;
    }

    res = (g_date_compare(file_t, date) >= 0) ? FALSE : TRUE;
    g_date_free(file_t);
    return res;
}
//LOGGER USER QUERIES
int create_dir()
{
  char tek_day_dir[ 11 ];
  GDate *date = g_date_new();
  const time_t timestamp = time( NULL );
  g_date_set_time_t( date, timestamp );

  if( g_mkdir_with_parents( PATH_TO_LOG_USER_QUERIES, 0755 ) == 0 )
  {
    if( g_chdir( PATH_TO_LOG_USER_QUERIES ) == 0 )
    {
      sprintf( tek_day_dir, "%d-%d-%d", g_date_get_year( date ), g_date_get_month( date ), g_date_get_day( date ) );
      if( g_mkdir_with_parents( tek_day_dir, 0755 ) == 0 )
      {
        g_date_free( date );
        if( g_chdir( tek_day_dir ) == 0 ) return 1;
      }
    }
  }
  g_date_free( date );
  return 0;
}
Пример #6
0
static void
on_calendar_entry_activated(GtkWidget *widget, GtkWidget *calendar)
{
    GDate *date;
    const gchar *text;

    date = g_date_new();

    text = gtk_entry_get_text(GTK_ENTRY(widget));
    g_date_set_parse(date, text);

    if (g_date_valid(date)) {
	gtk_calendar_freeze(GTK_CALENDAR(calendar));
	gtk_calendar_select_month(GTK_CALENDAR(calendar),
				  g_date_get_month(date) - 1,
				  g_date_get_year(date));
	gtk_calendar_select_day(GTK_CALENDAR(calendar),
				g_date_get_day(date));
	gtk_calendar_thaw(GTK_CALENDAR(calendar));
    }
    g_date_free(date);
}
Пример #7
0
static void
bt_song_info_init (BtSongInfo * self)
{
  time_t now = time (NULL);
  const gchar *user_name;

  self->priv =
      G_TYPE_INSTANCE_GET_PRIVATE (self, BT_TYPE_SONG_INFO, BtSongInfoPrivate);
  self->priv->taglist = gst_tag_list_new_empty ();

  user_name = g_get_real_name ();
  if (!user_name || !user_name[0]) {
    user_name = g_get_user_name ();
  }

  self->priv->name = g_strdup (DEFAULT_SONG_NAME);
  self->priv->author = g_strdup (user_name);
  // @idea alternate bpm's a little at new_song (user defined range?)
  self->priv->beats_per_minute = 125;   // 1..1000
  self->priv->ticks_per_beat = 4;       // 1..128
  self->priv->bars = 16;        // 1..16
  bt_song_info_tempo_changed (self);
  // init dates 'YYYY-MM-DDThh:mm:ssZ'
  self->priv->create_dts = g_new (gchar, DTS_LEN + 1);
  self->priv->change_dts = g_new (gchar, DTS_LEN + 1);
  strftime (self->priv->create_dts, DTS_LEN + 1, "%FT%TZ", gmtime (&now));
  strncpy (self->priv->change_dts, self->priv->create_dts, DTS_LEN + 1);
  GST_DEBUG ("date initialized as %s", self->priv->change_dts);

  // init taglist
  self->priv->tag_date = g_date_new ();
  g_date_set_time_t (self->priv->tag_date, now);
  gst_tag_list_add (self->priv->taglist, GST_TAG_MERGE_REPLACE,
      GST_TAG_TITLE, self->priv->name,
      GST_TAG_ARTIST, self->priv->author,
      GST_TAG_DATE, self->priv->tag_date,
      GST_TAG_BEATS_PER_MINUTE, (gdouble) self->priv->beats_per_minute, NULL);
}
Пример #8
0
int main(int argc, char** argv)
{
  GDate* d;
  guint32 j;
  GDateMonth m;
  GDateYear y, prev_y;
  GDateDay day;
  gchar buf[101];
  gchar* loc;
  /* Try to get all the leap year cases. */
  GDateYear check_years[] = { 
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
    11, 12, 13, 14, 98, 99, 100, 101, 102, 103, 397, 
    398, 399, 400, 401, 402, 403, 404, 405, 406,
    1598, 1599, 1600, 1601, 1602, 1650, 1651,
    1897, 1898, 1899, 1900, 1901, 1902, 1903, 
    1961, 1962, 1963, 1964, 1965, 1967,
    1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976,
    1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 
    1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 
    1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 
    2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
    3000, 3001, 3002, 3998, 3999, 4000, 4001, 4002, 4003
  };
  guint n_check_years = sizeof(check_years)/sizeof(GDateYear);
  guint i;
  gboolean discontinuity;

  g_print("checking GDate...");
  
  TEST("sizeof(GDate) is not more than 8 bytes on this platform", sizeof(GDate) < 9);

  d = g_date_new();

  TEST("Empty constructor produces invalid date", !g_date_valid(d));

  g_date_free(d);

  d = g_date_new_dmy(1,1,1);

  TEST("January 1, Year 1 created and valid", g_date_valid(d));

  j = g_date_get_julian(d);
  
  TEST("January 1, Year 1 is Julian date 1", j == 1);

  TEST("Returned month is January", g_date_get_month(d) == G_DATE_JANUARY);
  TEST("Returned day is 1", g_date_get_day(d) == 1);
  TEST("Returned year is 1", g_date_get_year(d) == 1);

  TEST("Bad month is invalid", !g_date_valid_month(G_DATE_BAD_MONTH));
  TEST("Month 13 is invalid",  !g_date_valid_month(13));
  TEST("Bad day is invalid",   !g_date_valid_day(G_DATE_BAD_DAY));
  TEST("Day 32 is invalid",     !g_date_valid_day(32));
  TEST("Bad year is invalid",  !g_date_valid_year(G_DATE_BAD_YEAR));
  TEST("Bad julian is invalid", !g_date_valid_julian(G_DATE_BAD_JULIAN));
  TEST("Bad weekday is invalid", !g_date_valid_weekday(G_DATE_BAD_WEEKDAY));
  TEST("Year 2000 is a leap year", g_date_is_leap_year(2000));
  TEST("Year 1999 is not a leap year", !g_date_is_leap_year(1999));
  TEST("Year 1996 is a leap year", g_date_is_leap_year(1996));
  TEST("Year 1600 is a leap year", g_date_is_leap_year(1600));
  TEST("Year 2100 is not a leap year", !g_date_is_leap_year(2100));
  TEST("Year 1800 is not a leap year", !g_date_is_leap_year(1800));

  g_date_free(d);
  
  loc = setlocale(LC_ALL,"");
  if (loc) 
    g_print("\nLocale set to %s\n", loc);
  else 
    g_print("\nLocale unchanged\n");

  d = g_date_new();
  g_date_set_time(d, time(NULL));
  TEST("Today is valid", g_date_valid(d));

  g_date_strftime(buf,100,"Today is a %A, %x\n", d);
  g_print("%s", buf);

  g_date_set_time(d, 1);
  TEST("Beginning of Unix epoch is valid", g_date_valid(d));

  g_date_strftime(buf,100,"1 second into the Unix epoch it was a %A, in the month of %B, %x\n", d);
  g_print("%s", buf);

  g_date_set_julian(d, 1);
  TEST("GDate's \"Julian\" epoch's first day is valid", g_date_valid(d));

  g_date_strftime(buf,100,"Our \"Julian\" epoch begins on a %A, in the month of %B, %x\n",
		  d);
  g_print("%s", buf);

  g_date_set_dmy(d, 10, 1, 2000);

  g_date_strftime(buf,100,"%x", d);

  g_date_set_parse(d, buf);
  /* Note: this test will hopefully work, but no promises. */
  TEST("Successfully parsed a %x-formatted string", 
       g_date_valid(d) && 
       g_date_get_month(d) == 1 && 
       g_date_get_day(d) == 10 && 
       g_date_get_year(d) == 2000);
  if (failed)
    g_date_debug_print(d);
  
  g_date_free(d);

  j = G_DATE_BAD_JULIAN;

  i = 0;
  discontinuity = TRUE;
  y      = check_years[0];
  prev_y = G_DATE_BAD_YEAR;
  while (i < n_check_years) 
    {
      guint32 first_day_of_year = G_DATE_BAD_JULIAN;
      guint16 days_in_year = g_date_is_leap_year(y) ? 366 : 365;
      guint   sunday_week_of_year = 0;
      guint   sunday_weeks_in_year = g_date_get_sunday_weeks_in_year(y);
      guint   monday_week_of_year = 0;
      guint   monday_weeks_in_year = g_date_get_monday_weeks_in_year(y);
      guint   iso8601_week_of_year = 0;

      if (discontinuity)
        g_print(" (Break in sequence of requested years to check)\n");

      g_print("Checking year %u", y);

      TEST("Year is valid", g_date_valid_year(y));

      TEST("Number of Sunday weeks in year is 52 or 53", 
	   sunday_weeks_in_year == 52 || sunday_weeks_in_year == 53);
      
      TEST("Number of Monday weeks in year is 52 or 53", 
	   monday_weeks_in_year == 52 || monday_weeks_in_year == 53);
	   
      m = 1;
      while (m < 13) 
	{
	  guint8 dim = g_date_get_days_in_month(m,y);
	  GDate days[31];         /* This is the fast way, no allocation */

	  TEST("Sensible number of days in month", (dim > 0 && dim < 32));

	  TEST("Month between 1 and 12 is valid", g_date_valid_month(m));

	  day = 1;

	  g_date_clear(days, 31);

	  while (day <= dim) 
	    {
	      guint i;
              GDate tmp;

	      TEST("DMY triplet is valid", g_date_valid_dmy(day,m,y));

	      /* Create GDate with triplet */
	      
	      d = &days[day-1];

	      TEST("Cleared day is invalid", !g_date_valid(d));

	      g_date_set_dmy(d,day,m,y);

	      TEST("Set day is valid", g_date_valid(d));

	      if (m == G_DATE_JANUARY && day == 1) 
		{
		  first_day_of_year = g_date_get_julian(d);
		}

	      g_assert(first_day_of_year != G_DATE_BAD_JULIAN);

	      TEST("Date with DMY triplet is valid", g_date_valid(d));
	      TEST("Month accessor works", g_date_get_month(d) == m);
	      TEST("Year accessor works", g_date_get_year(d) == y);
	      TEST("Day of month accessor works", g_date_get_day(d) == day);

	      TEST("Day of year is consistent with Julian dates",
		   ((g_date_get_julian(d) + 1 - first_day_of_year) ==
		    (g_date_get_day_of_year(d))));

	      if (failed) 
		{
		  g_print("first day: %u this day: %u day of year: %u\n", 
			  first_day_of_year, 
			  g_date_get_julian(d),
			  g_date_get_day_of_year(d));
		}
	      
	      if (m == G_DATE_DECEMBER && day == 31) 
		{
		  TEST("Last day of year equals number of days in year", 
		       g_date_get_day_of_year(d) == days_in_year);
		  if (failed) 
		    {
		      g_print("last day: %u days in year: %u\n", 
			      g_date_get_day_of_year(d), days_in_year);
		    }
		}

	      TEST("Day of year is not more than number of days in the year",
		   g_date_get_day_of_year(d) <= days_in_year);

	      TEST("Monday week of year is not more than number of weeks in the year",
		   g_date_get_monday_week_of_year(d) <= monday_weeks_in_year);
	      if (failed)
		{
		  g_print("Weeks in year: %u\n", monday_weeks_in_year);
		  g_date_debug_print(d);
		}
	      TEST("Monday week of year is >= than last week of year",
		   g_date_get_monday_week_of_year(d) >= monday_week_of_year);

	      if (g_date_get_weekday(d) == G_DATE_MONDAY) 
		{
		  
		  TEST("Monday week of year on Monday 1 more than previous day's week of year",
		       (g_date_get_monday_week_of_year(d) - monday_week_of_year) == 1);
		  if ((m == G_DATE_JANUARY && day <= 4) ||
		      (m == G_DATE_DECEMBER && day >= 29)) {
		    TEST("ISO 8601 week of year on Monday Dec 29 - Jan 4 is 1",
			 (g_date_get_iso8601_week_of_year(d) == 1));
		  } else {
		    TEST("ISO 8601 week of year on Monday 1 more than previous day's week of year",
			 (g_date_get_iso8601_week_of_year(d) - iso8601_week_of_year) == 1);
		  }
		}
	      else 
		{
		  TEST("Monday week of year on non-Monday 0 more than previous day's week of year",
		       (g_date_get_monday_week_of_year(d) - monday_week_of_year) == 0);
		  if (!(day == 1 && m == G_DATE_JANUARY)) {
		    TEST("ISO 8601 week of year on non-Monday 0 more than previous day's week of year (",
			 (g_date_get_iso8601_week_of_year(d) - iso8601_week_of_year) == 0);
		  }
		}


	      monday_week_of_year = g_date_get_monday_week_of_year(d);
	      iso8601_week_of_year = g_date_get_iso8601_week_of_year(d);


	      TEST("Sunday week of year is not more than number of weeks in the year",
		   g_date_get_sunday_week_of_year(d) <= sunday_weeks_in_year);
	      if (failed)
		{
		  g_date_debug_print(d);
		}
	      TEST("Sunday week of year is >= than last week of year",
		   g_date_get_sunday_week_of_year(d) >= sunday_week_of_year);

	      if (g_date_get_weekday(d) == G_DATE_SUNDAY) 
		{
		  TEST("Sunday week of year on Sunday 1 more than previous day's week of year",
		       (g_date_get_sunday_week_of_year(d) - sunday_week_of_year) == 1);
		}
	      else 
		{
		  TEST("Sunday week of year on non-Sunday 0 more than previous day's week of year",
		       (g_date_get_sunday_week_of_year(d) - sunday_week_of_year) == 0);
		}

	      sunday_week_of_year = g_date_get_sunday_week_of_year(d);

	      TEST("Date is equal to itself",
		   g_date_compare(d,d) == 0);


	      /*************** Increments ***********/

              i = 1;
              while (i < 402) /* Need to get 400 year increments in */ 
                {
	      
                  /***** Days ******/
                  tmp = *d;
                  g_date_add_days(d, i);

                  TEST("Adding days gives a value greater than previous",
                       g_date_compare(d, &tmp) > 0);

                  g_date_subtract_days(d, i);
                  TEST("Forward days then backward days returns us to current day",
                       g_date_get_day(d) == day);

                  if (failed) 
                    {
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
                      g_date_debug_print(d);
                    }

                  TEST("Forward days then backward days returns us to current month",
                       g_date_get_month(d) == m);

                  if (failed) 
                    {
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
                      g_date_debug_print(d);
                    }

                  TEST("Forward days then backward days returns us to current year",
                       g_date_get_year(d) == y);

                  if (failed) 
                    {
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
                      g_date_debug_print(d);
                    }

                  /******* Months ********/

                  tmp = *d;
                  g_date_add_months(d, i);
                  TEST("Adding months gives a larger value",
                       g_date_compare(d, &tmp) > 0);
                  g_date_subtract_months(d, i);

                  TEST("Forward months then backward months returns us to current month",
                       g_date_get_month(d) == m);

                  if (failed) 
                    {
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
                      g_date_debug_print(d);
                    }

                  TEST("Forward months then backward months returns us to current year",
                       g_date_get_year(d) == y);

                  if (failed) 
                    {
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
                      g_date_debug_print(d);
                    }

		  
                  if (day < 29) 
                    {
                      /* Day should be unchanged */
		      
                      TEST("Forward months then backward months returns us to current day",
                           g_date_get_day(d) == day);
		      
                      if (failed) 
                        {
                          g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
                          g_date_debug_print(d);
                        }
                    }
                  else 
                    {
                      /* reset the day for later tests */
                      g_date_set_day(d, day);
                    }

                  /******* Years ********/

                  tmp = *d;
                  g_date_add_years(d, i);

                  TEST("Adding years gives a larger value",
                       g_date_compare(d,&tmp) > 0);
		      
                  g_date_subtract_years(d, i);

                  TEST("Forward years then backward years returns us to current month",
                       g_date_get_month(d) == m);

                  if (failed) 
                    {
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
                      g_date_debug_print(d);
                    }

                  TEST("Forward years then backward years returns us to current year",
                       g_date_get_year(d) == y);

                  if (failed) 
                    {
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
                      g_date_debug_print(d);
                    }

                  if (m != 2 && day != 29) 
                    {
                      TEST("Forward years then backward years returns us to current day",
                           g_date_get_day(d) == day);
		      
                      if (failed) 
                        {
                          g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
                          g_date_debug_print(d);
                        }
                    }
                  else 
                    {
                      g_date_set_day(d, day); /* reset */
                    }

                  i += 10;
                }

	      /*****  increment test relative to our local Julian count */

              if (!discontinuity) {

                /* We can only run sequence tests between sequential years */
                
                TEST("Julians are sequential with increment 1",
                     j+1 == g_date_get_julian(d));
                if (failed) 
                  {
                    g_print("Out of sequence, prev: %u expected: %u got: %u\n",
                            j, j+1, g_date_get_julian(d));
                  }

                g_date_add_days(d,1);
                TEST("Next day has julian 1 higher",
                     g_date_get_julian(d) == j + 2);
                g_date_subtract_days(d, 1);
                
                if (j != G_DATE_BAD_JULIAN) 
                  {
                    g_date_subtract_days(d, 1);
                    
                    TEST("Previous day has julian 1 lower",
                         g_date_get_julian(d) == j);
                    
                    g_date_add_days(d, 1); /* back to original */
                  }
              }    
              discontinuity = FALSE; /* goes away now */            

              fflush(stdout);
              fflush(stderr);

	      j = g_date_get_julian(d); /* inc current julian */

	      ++day;
	    } 
	  ++m;
	}
      g_print(" done\n");
      ++i;
      prev_y = y;
      y = check_years[i];
      if (prev_y == G_DATE_BAD_YEAR || 
          (prev_y + 1) != y) discontinuity = TRUE;
    }
  
  
  g_print("\n%u tests passed, %u failed\n",passed, notpassed);

  return 0;
}
Пример #9
0
void
calendar_create_fullyear_window (GUI *appGUI)
{
GtkWidget   *vbox1, *vbox2;
GtkWidget   *hseparator;
GtkWidget   *hbuttonbox;
GtkWidget   *close_button;
GtkWidget   *hbox1;
GtkWidget   *prev_button;
GtkWidget   *info_button;
GtkObject   *fy_spinbutton_adj;
GtkWidget   *next_button;
GtkWidget   *fycal_scrolledwindow;
GtkWidget   *fycal_viewport;
GtkWidget   *fycal_alternative_view_checkbutton;
GtkWidget   *vseparator;
GtkWidget   *label;
GtkWidget   *fycal_label, *fycal_vbox;
#ifdef HAVE_LIBICAL
GtkWidget   *button;
#endif  /* HAVE_LIBICAL */
gchar       tmpbuf[BUFFER_SIZE], buffer[BUFFER_SIZE];
gint        i, j, x, y, idx;
GDate       *cdate;
guint       month, year;

	cdate = g_date_new ();
	g_return_if_fail (cdate != NULL);
	g_date_set_time_t (cdate, time (NULL));

	appGUI->cal->fullyear_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (appGUI->cal->fullyear_window), _("Full-year calendar"));
	gtk_window_set_position (GTK_WINDOW (appGUI->cal->fullyear_window), GTK_WIN_POS_CENTER_ALWAYS);
	gtk_window_set_default_size (GTK_WINDOW (appGUI->cal->fullyear_window), config.fy_window_size_x, config.fy_window_size_y);
	gtk_window_set_modal (GTK_WINDOW (appGUI->cal->fullyear_window), TRUE);
	g_signal_connect (G_OBJECT (appGUI->cal->fullyear_window), "delete_event",
	                  G_CALLBACK (fullyear_window_close_cb), appGUI);
	gtk_window_set_transient_for (GTK_WINDOW (appGUI->cal->fullyear_window), GTK_WINDOW (appGUI->main_window));
	gtk_container_set_border_width (GTK_CONTAINER (appGUI->cal->fullyear_window), 8);
	g_signal_connect (G_OBJECT (appGUI->cal->fullyear_window), "key_press_event",
	                  G_CALLBACK (fullyear_key_press_cb), appGUI);

	vbox1 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox1);
	gtk_container_add (GTK_CONTAINER (appGUI->cal->fullyear_window), vbox1);

	hbox1 = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (hbox1);
	gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 4);

	g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Year"));
	label = gtk_label_new (tmpbuf);
	gtk_widget_show (label);
	gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, TRUE, 0);
	gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
	gtk_misc_set_padding (GTK_MISC (label), 0, 4);

	fy_spinbutton_adj = gtk_adjustment_new (get_gdate_current_year (), JULIAN_GREGORIAN_YEAR, 9999, 1, 10, 10);
	appGUI->cal->fy_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (fy_spinbutton_adj), 1, 0);
	gtk_widget_show (appGUI->cal->fy_spinbutton);
	g_signal_connect(appGUI->cal->fy_spinbutton, "value-changed", G_CALLBACK(change_year_spin_button_cb), appGUI);
	gtk_box_pack_start (GTK_BOX (hbox1), appGUI->cal->fy_spinbutton, FALSE, FALSE, 8);
	gtk_widget_set_size_request (appGUI->cal->fy_spinbutton, 80, -1);
	gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (appGUI->cal->fy_spinbutton), TRUE);
	gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (appGUI->cal->fy_spinbutton), GTK_UPDATE_IF_VALID);

	if (config.default_stock_icons) {
		info_button = gui_stock_button (GTK_STOCK_INFO, FALSE);
	} else {
		info_button = gui_stock_button (OSMO_STOCK_BUTTON_INFO, FALSE);
	}
	GTK_WIDGET_UNSET_FLAGS(info_button, GTK_CAN_FOCUS);
	gtk_widget_show (info_button);
	g_signal_connect (info_button, "clicked", G_CALLBACK (year_info_cb), appGUI);
	gtk_tooltips_set_tip (appGUI->osmo_tooltips, info_button, _("Year info"), NULL);
	gtk_button_set_relief (GTK_BUTTON (info_button), GTK_RELIEF_NONE);
	gtk_box_pack_start (GTK_BOX (hbox1), info_button, FALSE, FALSE, 2);

	vseparator = gtk_vseparator_new ();
	gtk_widget_show (vseparator);
	gtk_box_pack_start (GTK_BOX (hbox1), vseparator, FALSE, FALSE, 8);

	if (config.default_stock_icons) {
		prev_button = gui_stock_button (GTK_STOCK_GO_BACK, FALSE);
	} else {
		prev_button = gui_stock_button (OSMO_STOCK_BUTTON_PREV_YEAR, FALSE);
	}
	GTK_WIDGET_UNSET_FLAGS (prev_button, GTK_CAN_FOCUS);
	gtk_widget_show (prev_button);
	g_signal_connect (prev_button, "clicked", G_CALLBACK (change_to_previous_year_cb), appGUI);
	gtk_tooltips_set_tip (appGUI->osmo_tooltips, prev_button, _("Previous year"), NULL);
	gtk_button_set_relief (GTK_BUTTON (prev_button), GTK_RELIEF_NONE);
	gtk_box_pack_start (GTK_BOX (hbox1), prev_button, FALSE, FALSE, 2);

	if (config.default_stock_icons) {
		appGUI->cal->cyear_button = gui_stock_button (GTK_STOCK_HOME, FALSE);
	} else {
		appGUI->cal->cyear_button = gui_stock_button (OSMO_STOCK_BUTTON_TODAY, FALSE);
	}
	GTK_WIDGET_UNSET_FLAGS (appGUI->cal->cyear_button, GTK_CAN_FOCUS);
	gtk_widget_show (appGUI->cal->cyear_button);
	g_signal_connect (appGUI->cal->cyear_button, "clicked", G_CALLBACK (change_to_current_year_cb), appGUI);
	gtk_tooltips_set_tip (appGUI->osmo_tooltips, appGUI->cal->cyear_button, _("Current year"), NULL);
	gtk_button_set_relief (GTK_BUTTON (appGUI->cal->cyear_button), GTK_RELIEF_NONE);
	gtk_box_pack_start (GTK_BOX (hbox1), appGUI->cal->cyear_button, FALSE, FALSE, 2);

	if (config.default_stock_icons) {
		next_button = gui_stock_button (GTK_STOCK_GO_FORWARD, FALSE);
	} else {
		next_button = gui_stock_button (OSMO_STOCK_BUTTON_NEXT_YEAR, FALSE);
	}
	GTK_WIDGET_UNSET_FLAGS(next_button, GTK_CAN_FOCUS);
	gtk_widget_show (next_button);
	g_signal_connect (next_button, "clicked", G_CALLBACK (change_to_next_year_cb), appGUI);
	gtk_tooltips_set_tip (appGUI->osmo_tooltips, next_button, _("Next year"), NULL);
	gtk_button_set_relief (GTK_BUTTON (next_button), GTK_RELIEF_NONE);
	gtk_box_pack_start (GTK_BOX (hbox1), next_button, FALSE, FALSE, 2);

	vseparator = gtk_vseparator_new ();
	gtk_widget_show (vseparator);
	gtk_box_pack_start (GTK_BOX (hbox1), vseparator, FALSE, FALSE, 8);

	fycal_alternative_view_checkbutton = gtk_check_button_new_with_mnemonic (_("Alternative view"));
	GTK_WIDGET_UNSET_FLAGS (fycal_alternative_view_checkbutton, GTK_CAN_FOCUS);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fycal_alternative_view_checkbutton), config.fy_alternative_view);
	g_signal_connect (G_OBJECT (fycal_alternative_view_checkbutton), "toggled",
	                  G_CALLBACK (alternative_view_cb), appGUI);
	gtk_box_pack_start (GTK_BOX (hbox1), fycal_alternative_view_checkbutton, FALSE, FALSE, 2);
	gtk_widget_show (fycal_alternative_view_checkbutton);

#ifdef HAVE_LIBICAL

	if (appGUI->calendar_only == FALSE) {
		button = gtk_button_new_with_label (_("Browse iCal events"));
		GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
		gtk_widget_show (button);
		gtk_box_pack_end (GTK_BOX (hbox1), button, FALSE, FALSE, 2);
		g_signal_connect (button, "clicked", G_CALLBACK (browse_ical_events_cb), appGUI);
	}

#endif  /* HAVE_LIBICAL */

	fycal_scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_show (fycal_scrolledwindow);
	gtk_box_pack_start (GTK_BOX (vbox1), fycal_scrolledwindow, TRUE, TRUE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (fycal_scrolledwindow), 4);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (fycal_scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	fycal_viewport = gtk_viewport_new (NULL, NULL);
	gtk_widget_show (fycal_viewport);
	gtk_container_add (GTK_CONTAINER (fycal_scrolledwindow), fycal_viewport);

	vbox2 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox2);
	gtk_container_add (GTK_CONTAINER (fycal_viewport), vbox2);

	/*-------------------------------------------------------------------------------------*/
	/* First view */

	if (config.fy_simple_view == TRUE) {
		appGUI->cal->fycal_table_1 = gtk_table_new (MAX_MONTHS + 2, FULL_YEAR_COLS + 1, FALSE);
	} else {
		appGUI->cal->fycal_table_1 = gtk_table_new (MAX_MONTHS + 4, FULL_YEAR_COLS + 3, FALSE);
	}

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fycal_alternative_view_checkbutton)) == FALSE) {
		gtk_widget_show (appGUI->cal->fycal_table_1);
	}
	gtk_box_pack_start (GTK_BOX (vbox2), appGUI->cal->fycal_table_1, TRUE, TRUE, 0);

	vseparator = gtk_vseparator_new ();
	gtk_widget_show (vseparator);
	if (config.fy_simple_view == TRUE) {
		gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), vseparator, 1, 2, 0, 14,
		                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
	} else {
		gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), vseparator, 1, 2, 0, 16,
		                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
	}

	hseparator = gtk_hseparator_new ();
	gtk_widget_show (hseparator);
	gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, 2, 39, 1, 2,
	                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
	                  (GtkAttachOptions) (GTK_FILL), 0, 0);

	hseparator = gtk_hseparator_new ();
	gtk_widget_show (hseparator);
	gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, 0, 1, 1, 2,
	                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
	                  (GtkAttachOptions) (GTK_FILL), 0, 0);

	if (config.fy_simple_view == FALSE) {

		vseparator = gtk_vseparator_new ();
		gtk_widget_show (vseparator);
		gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), vseparator, FULL_YEAR_COLS + 2, FULL_YEAR_COLS + 3, 0, 16,
		                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
		hseparator = gtk_hseparator_new ();
		gtk_widget_show (hseparator);
		gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, 2, 39, MAX_MONTHS + 2, MAX_MONTHS + 3,
		                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		                  (GtkAttachOptions) (GTK_FILL), 0, 0);
		hseparator = gtk_hseparator_new ();
		gtk_widget_show (hseparator);
		gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, 0, 1, MAX_MONTHS + 2, MAX_MONTHS + 3,
		                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		                  (GtkAttachOptions) (GTK_FILL), 0, 0);
		hseparator = gtk_hseparator_new ();
		gtk_widget_show (hseparator);
		gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, FULL_YEAR_COLS + 3, FULL_YEAR_COLS + 4, 1, 2,
		                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		                  (GtkAttachOptions) (GTK_FILL), 0, 0);
		hseparator = gtk_hseparator_new ();
		gtk_widget_show (hseparator);
		gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, FULL_YEAR_COLS + 3, FULL_YEAR_COLS + 4,
		                  MAX_MONTHS + 2, MAX_MONTHS + 3,
		                  (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		                  (GtkAttachOptions) (GTK_FILL), 0, 0);
	}

	g_date_set_day (cdate, 1);

	for (month = G_DATE_JANUARY; month <= G_DATE_DECEMBER; month++) {

		g_date_set_month (cdate, month);
		g_date_strftime (buffer, BUFFER_SIZE, config.fy_simple_view ? "%b" : "%B", cdate);
		g_snprintf (tmpbuf, BUFFER_SIZE, (month % 2) ? "%s" : "<span foreground='medium blue'>%s</span>", buffer);

		label = gtk_label_new (NULL);
		gtk_widget_show (label);
		gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), label, 0, 1, month + 1, month + 2,
		                  (GtkAttachOptions) (GTK_FILL),
		                  (GtkAttachOptions) (0), 0, 0);

		gtk_misc_set_padding (GTK_MISC (label), 8, 0);
		gtk_label_set_markup (GTK_LABEL (label), tmpbuf);

		if (config.fy_simple_view == FALSE) {
			label = gtk_label_new (NULL);
			gtk_widget_show (label);
			gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), label,
			                  FULL_YEAR_COLS + 3, FULL_YEAR_COLS + 4, month + 1, month + 2,
			                  (GtkAttachOptions) (GTK_FILL),
			                  (GtkAttachOptions) (0), 0, 0);

			gtk_misc_set_padding (GTK_MISC (label), 8, 0);
			gtk_label_set_markup (GTK_LABEL (label), tmpbuf);
		}
	}

	/* start with monday */
	g_date_set_dmy (cdate, 1, 1, 2007);

	for (i = 0; i < FULL_YEAR_COLS; i++) {

		g_date_set_day (cdate, (i % DAYS_PER_WEEK) + 1);
		g_date_strftime (buffer, BUFFER_SIZE, "%a", cdate);

		if (i % 7 + 1 == G_DATE_SATURDAY || i % 7 + 1 == G_DATE_SUNDAY) {
			g_snprintf (tmpbuf, BUFFER_SIZE, "<span foreground='firebrick'>%s</span>", buffer);
		} else {
			g_snprintf (tmpbuf, BUFFER_SIZE, "%s", buffer);
		}

		label = gtk_label_new (NULL);
		gtk_widget_show (label);
		gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), label, i + 2, i + 3, 0, 1,
		                  (GtkAttachOptions) (GTK_FILL),
		                  (GtkAttachOptions) (0), 0, 0);
		gtk_misc_set_padding (GTK_MISC (label), 4, 0);
		gtk_label_set_angle (GTK_LABEL (label), 90);
		gtk_label_set_markup (GTK_LABEL (label), tmpbuf);

		if (config.fy_simple_view == FALSE) {
			label = gtk_label_new (NULL);
			gtk_widget_show (label);
			gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), label, i + 2, i + 3, MAX_MONTHS + 3, MAX_MONTHS + 4,
			                  (GtkAttachOptions) (GTK_FILL),
			                  (GtkAttachOptions) (0), 0, 0);
			gtk_misc_set_padding (GTK_MISC (label), 4, 0);
			gtk_label_set_angle (GTK_LABEL (label), 90);
			gtk_label_set_markup (GTK_LABEL (label), tmpbuf);
		}
	}

	for (month = G_DATE_JANUARY; month <= G_DATE_DECEMBER; month++) {

		for (j = 0; j < FULL_YEAR_COLS; j++) {

			i = month - 1;
			idx = i * FULL_YEAR_COLS + j;

			appGUI->cal->calendar_buttons[idx] = gtk_button_new ();
			GTK_WIDGET_UNSET_FLAGS (appGUI->cal->calendar_buttons[idx], GTK_CAN_FOCUS);
			gtk_button_set_relief (GTK_BUTTON (appGUI->cal->calendar_buttons[idx]), GTK_RELIEF_NONE);
			gtk_widget_show (appGUI->cal->calendar_buttons[idx]);
			gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), appGUI->cal->calendar_buttons[idx], j+2, j+3, i+2, i+3,
			                  (GtkAttachOptions) (GTK_FILL),
			                  (GtkAttachOptions) (0), 0, 0);
		}
	}

	display_calendar (get_current_year (), appGUI);
	gtk_widget_set_sensitive (appGUI->cal->cyear_button, FALSE);

	/*-------------------------------------------------------------------------------------*/
	/* Second view */

	appGUI->cal->fycal_table_2 = gtk_table_new (3, 4, FALSE);

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fycal_alternative_view_checkbutton)) == TRUE) {
		gtk_widget_show (appGUI->cal->fycal_table_2);
	}
	gtk_box_pack_start (GTK_BOX (vbox2), appGUI->cal->fycal_table_2, TRUE, TRUE, 0);

	for (i = y = 0; y < 3; y++) {

		for (x = 0; x < 4; x++, i++) {

			fycal_vbox = gtk_vbox_new (FALSE, 0);
			gtk_widget_show (fycal_vbox);
			gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_2), fycal_vbox, x, x + 1, y, y + 1,
			                  (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
			                  (GtkAttachOptions) (0), 0, 0);
			fycal_label = gtk_label_new (NULL);
			gtk_widget_show (fycal_label);
			gtk_box_pack_start (GTK_BOX (fycal_vbox), fycal_label, FALSE, FALSE, 0);
			appGUI->cal->fy_calendars[i] = gui_calendar_new ();
			gtk_widget_show (appGUI->cal->fy_calendars[i]);
			GTK_WIDGET_UNSET_FLAGS (appGUI->cal->fy_calendars[i], GTK_CAN_FOCUS);
			gui_calendar_set_display_options (GUI_CALENDAR (appGUI->cal->fy_calendars[i]),
			                                  (config.display_options & (GUI_CALENDAR_SHOW_DAY_NAMES |
			                                  GUI_CALENDAR_WEEK_START_MONDAY)) | GUI_CALENDAR_NO_MONTH_CHANGE);
			gui_calendar_enable_cursor (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), FALSE);
			gui_calendar_set_event_marker_type (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.event_marker_type);
			gui_calendar_set_event_marker_color (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.mark_color);
			gui_calendar_set_selector_color (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.selection_color);
			gui_calendar_set_header_color (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.header_color);
			gui_calendar_set_weekend_color (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.weekend_color);
			gui_calendar_set_day_note_marker_type (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.day_note_marker);
			gui_calendar_set_today_marker_type (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.today_marker_type);
			gui_calendar_set_today_marker_color (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.mark_current_day_color);
			gui_calendar_set_today_marker_alpha (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.mark_current_day_alpha);

			year = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (appGUI->cal->fy_spinbutton));
			month = i + 1;

			gui_calendar_select_month (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), month - 1, year);
			mark_events (appGUI->cal->fy_calendars[i], month - 1, year, appGUI);
			g_date_set_dmy (cdate, 1, month, year);
			g_date_strftime (buffer, BUFFER_SIZE, "%B", cdate);
			gtk_label_set_text (GTK_LABEL (fycal_label), buffer);
			gtk_box_pack_start (GTK_BOX (fycal_vbox), appGUI->cal->fy_calendars[i], FALSE, FALSE, 0);
		}
	}

	/*-------------------------------------------------------------------------------------*/

	hseparator = gtk_hseparator_new ();
	gtk_widget_show (hseparator);
	gtk_box_pack_start (GTK_BOX (vbox1), hseparator, FALSE, TRUE, 4);

	hbuttonbox = gtk_hbutton_box_new ();
	gtk_widget_show (hbuttonbox);
	gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox, FALSE, TRUE, 0);
	gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
	gtk_box_set_spacing (GTK_BOX (hbuttonbox), 4);

	if (config.default_stock_icons) {
		close_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
	} else {
		close_button = gtk_button_new_from_stock (OSMO_STOCK_BUTTON_CLOSE);
	}
	gtk_widget_show (close_button);
	g_signal_connect (close_button, "clicked", G_CALLBACK (button_fullyear_window_close_cb), appGUI);
	gtk_container_add (GTK_CONTAINER (hbuttonbox), close_button);

	gtk_widget_show (appGUI->cal->fullyear_window);
}
Пример #10
0
/**
 * Parse XML transaction node and fill a ImportTransaction with results.
 *
 * \param transaction_node	XML transaction node to parse.
 */
void recuperation_donnees_gnucash_transaction ( xmlNodePtr transaction_node )
{
  struct ImportTransaction * transaction;
  struct ImportAccount * account = NULL;
  struct gnucash_split * split;
  gchar * date_string, *space, *tiers;
  GDate * date;
  xmlNodePtr splits, split_node, date_node;
  GSList * split_list = NULL;
  GsbReal total = { 0 , 0 };

  /* Transaction amount, category, account, etc.. */
  splits = get_child ( transaction_node, "splits" );
  split_node = splits -> children;

  while ( split_node )
    {
      struct ImportAccount * split_account = NULL;
      struct gnucash_category * categ = NULL;
      gint p_r = OPERATION_NORMALE;
      GsbReal amount;

      /**
       * Gnucash transactions are in fact "splits", much like grisbi's
       * splits of transactions.  We need to parse all splits and
       * see whether they are transfers to real accounts or transfers
       * to category accounts.  In that case, we only create one
       * transactions.  The other is discarded as grisbi is not a
       * double part financial engine.
       */
      if ( node_strcmp ( split_node, "split" ) )
	{
	  gchar * account_name = NULL, * categ_name = NULL;

	  split_account = find_imported_account_by_uid ( child_content ( split_node,
									"account" ) );
	  categ = find_imported_categ_by_uid ( child_content ( split_node, "account" ) );
	  amount = gnucash_value ( child_content(split_node, "value") );

	  if ( categ )
	    categ_name = categ -> name;
	  if ( split_account )
	    {
	      /* All of this stuff is here since we are dealing with
		 the account split, not the category one */
	      account_name = split_account -> nom_de_compte;
	      total = gsb_real_add ( total,
				     amount );
	      if ( strcmp(child_content(split_node, "reconciled-state"), "n") )
		p_r = OPERATION_RAPPROCHEE;
	    }

	  split = find_split ( split_list, amount, split_account, categ );
	  if ( split )
	    {
	      update_split ( split, amount, account_name, categ_name );
	    }
	  else
	    {
	      split = new_split ( amount, account_name, categ_name );
	      split_list = g_slist_append ( split_list, split );
	      split -> notes = child_content(split_node, "memo");
	    }
	  if ( p_r != OPERATION_NORMALE )
	      split -> p_r = p_r;
	}

      split_node = split_node -> next;
    }

  if ( ! split_list )
    return;

  /* Transaction date */
  date_node = get_child ( transaction_node, "date-posted" );
  date_string = child_content (date_node, "date");
  space = strchr ( date_string, ' ' );
  if ( space )
    *space = 0;
  date = g_date_new ();
  g_date_set_parse ( date, date_string );
  if ( !g_date_valid ( date ))
    fprintf ( stderr, "grisbi: Can't parse date %s\n", date_string );

  /* Tiers */
  tiers = child_content ( transaction_node, "description" );

  /* Create transaction */
  split = split_list -> data;
  transaction = new_transaction_from_split ( split, tiers, date );
  transaction -> operation_ventilee = 0;
  transaction -> ope_de_ventilation = 0;
  account = find_imported_account_by_name ( split -> account );
  if ( account )
    account -> operations_importees = g_slist_append ( account -> operations_importees, transaction );

  /** Splits of transactions are handled the same way, we process
      them if we find more than one split in transaction node. */
  if ( g_slist_length ( split_list ) > 1 )
    {
      transaction -> operation_ventilee = 1;
      transaction -> montant = total;

      while ( split_list )
	{
	  split = split_list -> data;
	  account = NULL;

	  transaction = new_transaction_from_split ( split, tiers, date );
	  transaction -> ope_de_ventilation = 1;

	  account = find_imported_account_by_name ( split -> account );
	  if ( account )
	    account -> operations_importees = g_slist_append ( account -> operations_importees, transaction );

	  split_list = split_list -> next;
	}
    }
}
Пример #11
0
void
contacts_create_birthdays_window (GUI *appGUI)
{
GtkWidget           *vbox1;
GtkWidget           *hseparator;
GtkWidget           *hbuttonbox;
GtkWidget           *close_button;
GtkTreeViewColumn   *column;
GtkCellRenderer     *renderer;
GtkWidget           *scrolledwindow;
gint i, n, id, age;
guint32 date;
gchar *text, buffer[BUFFER_SIZE], buff[BUFFER_SIZE];
GtkTreeIter iter, n_iter;
GDate *cdate_birthday, *cdate_current;
guint b_day, b_month, b_year;
guint c_day, c_month, c_year;
gboolean flag, leap;

	cdate_birthday = g_date_new ();
	g_return_if_fail (cdate_birthday != NULL);

	cdate_current = g_date_new ();
	g_return_if_fail (cdate_current != NULL);

	i = n = 0;
	while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, NULL, i++)) {
		gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_BIRTH_DAY_DATE, &date, -1);
		if (date) n++;
	}

	if (n == 0) {
		gui_create_dialog (GTK_MESSAGE_INFO, _("No birthdays defined"), GTK_WINDOW (appGUI->main_window));
		return;
	}

	appGUI->cnt->birthdays_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (appGUI->cnt->birthdays_window), _("Birthdays list"));
	gtk_window_set_position (GTK_WINDOW (appGUI->cnt->birthdays_window), GTK_WIN_POS_CENTER_ON_PARENT);
	gtk_window_set_default_size (GTK_WINDOW (appGUI->cnt->birthdays_window), 
                                 config.contacts_birthdays_win_w, config.contacts_birthdays_win_h);
	gtk_window_set_modal (GTK_WINDOW (appGUI->cnt->birthdays_window), TRUE);
	g_signal_connect (G_OBJECT (appGUI->cnt->birthdays_window), "delete_event",
	                  G_CALLBACK (birthdays_window_close_cb), appGUI);
	gtk_window_set_transient_for (GTK_WINDOW (appGUI->cnt->birthdays_window), GTK_WINDOW (appGUI->main_window));
	gtk_container_set_border_width (GTK_CONTAINER (appGUI->cnt->birthdays_window), 8);
	g_signal_connect (G_OBJECT (appGUI->cnt->birthdays_window), "key_press_event",
	                  G_CALLBACK (birthdays_key_press_cb), appGUI);

	vbox1 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox1);
	gtk_container_add (GTK_CONTAINER (appGUI->cnt->birthdays_window), vbox1);

	scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_show (scrolledwindow);
	gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow, TRUE, TRUE, 0);

	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	appGUI->cnt->birthdays_list_store = gtk_list_store_new (BIRTHDAYS_NUM_COLUMNS,
	                                                        G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING,
	                                                        G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);

	appGUI->cnt->birthdays_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (appGUI->cnt->birthdays_list_store));
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), config.contacts_rules_hint);
	gtk_widget_show (appGUI->cnt->birthdays_list);
	GTK_WIDGET_SET_FLAGS (appGUI->cnt->birthdays_list, GTK_CAN_DEFAULT);
	gtk_container_add (GTK_CONTAINER (scrolledwindow), appGUI->cnt->birthdays_list);

	appGUI->cnt->birthdays_list_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (appGUI->cnt->birthdays_list));

	g_signal_connect (G_OBJECT (appGUI->cnt->birthdays_list), "button_press_event",
	                  G_CALLBACK (birthdays_list_dbclick_cb), appGUI);

	/* create columns */
	renderer = gtk_cell_renderer_text_new ();
	g_object_set (G_OBJECT (renderer), "xpad", 8, NULL);
	column = gtk_tree_view_column_new_with_attributes (_("Name"), renderer, "text", B_COLUMN_NAME, NULL);
	gtk_tree_view_column_set_visible (column, TRUE);
	gtk_tree_view_column_set_expand (column, TRUE);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);
	gtk_tree_view_column_set_sort_column_id (column, B_COLUMN_NAME);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("Days to birthday"), renderer, "text", B_COLUMN_DAYS_NUM, NULL);
	gtk_tree_view_column_set_visible (column, FALSE);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);

	renderer = gtk_cell_renderer_text_new ();
	g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL);
	g_object_set (G_OBJECT (renderer), "xpad", 8, NULL);
	column = gtk_tree_view_column_new_with_attributes (_("Days to birthday"), renderer, "text", B_COLUMN_DAYS, NULL);
	gtk_tree_view_column_set_visible (column, TRUE);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);
	gtk_tree_view_column_set_sort_column_id (column, B_COLUMN_DAYS_NUM);
	g_signal_emit_by_name (column, "clicked");

	column = gtk_tree_view_column_new_with_attributes (_("Age"), renderer, "text", B_COLUMN_AGE, NULL);
	gtk_tree_view_column_set_visible (column, config.visible_age_column);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);
	gtk_tree_view_column_set_sort_column_id (column, B_COLUMN_AGE);

	column = gtk_tree_view_column_new_with_attributes (_("Birthday date"), renderer, "text", B_COLUMN_DATE, NULL);
	gtk_tree_view_column_set_visible (column, config.visible_birthday_date_column);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("Zodiac sign"), renderer, "text", B_COLUMN_ZODIAC, NULL);
	gtk_tree_view_column_set_visible (column, config.visible_zodiac_sign_column);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes ("ID", renderer, "text", B_COLUMN_ID, NULL);
	gtk_tree_view_column_set_visible (column, FALSE);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);

	gtk_tree_view_set_enable_search (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), FALSE);

	i = 0;

	g_date_set_julian (cdate_current, utl_get_current_julian ());
	c_day = g_date_get_day (cdate_current);
	c_month = g_date_get_month (cdate_current);
	c_year = g_date_get_year (cdate_current);

	while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, NULL, i++)) {
		gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_BIRTH_DAY_DATE, &date, -1);

		if (g_date_valid_julian (date)) {

			/* calculate age */
			g_date_set_julian (cdate_birthday, date);
			b_day = g_date_get_day (cdate_birthday);
			b_month = g_date_get_month (cdate_birthday);
			b_year = g_date_get_year (cdate_birthday);

			age = (gint) c_year - b_year;
			if (b_month < c_month || (b_month == c_month && b_day < c_day)) age++;

			if (age < 1) continue;

			/* name */
			flag = FALSE;
			g_snprintf (buff, BUFFER_SIZE, "(%s)", _("None"));

			gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_LAST_NAME, &text, -1);
			if (text != NULL) {
				flag = TRUE;
				if (strcmp (text, buff) == 0) {
					text[0] = '\0';
					flag = FALSE;
				}
				g_strlcpy (buffer, text, BUFFER_SIZE);
				g_free (text);
			}

			gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_FIRST_NAME, &text, -1);
			if (text != NULL) {
				if (strcmp (text, buff) == 0) {
					text[0] = '\0';
				}
				if (flag == TRUE) {
					g_strlcat (buffer, " ", BUFFER_SIZE);
					g_strlcat (buffer, text, BUFFER_SIZE);
				} else {
					g_strlcpy (buffer, text, BUFFER_SIZE);
				}
				g_free (text);
			}

			gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_ID, &id, -1);
			gtk_list_store_append (appGUI->cnt->birthdays_list_store, &n_iter);
			gtk_list_store_set (appGUI->cnt->birthdays_list_store, &n_iter,
			                    B_COLUMN_ID, id, B_COLUMN_NAME, buffer, B_COLUMN_AGE, age, -1);

			/* calculate days to birthday */
			b_year = c_year;
			if ((b_month < c_month) || (b_month == c_month && b_day < c_day)) b_year++;

			leap = FALSE;
			if (g_date_valid_dmy (b_day, b_month, b_year) == FALSE) {
				g_date_set_day (cdate_birthday, b_day - 1);
				leap = TRUE;
			}
			g_date_set_year (cdate_birthday, b_year);

			date = g_date_days_between (cdate_current, cdate_birthday);
			if (date == 0) {
				g_snprintf (buffer, BUFFER_SIZE, "%s", _("today"));
			} else {
				g_snprintf (buffer, BUFFER_SIZE, leap ? "%d + 1" : "%d", date);
			}

			g_date_strftime (buff, BUFFER_SIZE, "%A, ", cdate_birthday);
			g_strlcat (buff, julian_to_str (g_date_get_julian (cdate_birthday), config.date_format), BUFFER_SIZE);

			gtk_list_store_set (appGUI->cnt->birthdays_list_store, &n_iter,
			                    B_COLUMN_DAYS_NUM, date, B_COLUMN_DAYS, buffer,
			                    B_COLUMN_DATE, buff, B_COLUMN_ZODIAC, utl_get_zodiac_name (b_day, b_month), -1);
		}

	}
	g_date_free (cdate_birthday);
	g_date_free (cdate_current);

	hseparator = gtk_hseparator_new ();
	gtk_widget_show (hseparator);
	gtk_box_pack_start (GTK_BOX (vbox1), hseparator, FALSE, TRUE, 4);

	hbuttonbox = gtk_hbutton_box_new ();
	gtk_widget_show (hbuttonbox);
	gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox, FALSE, TRUE, 0);
	gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
	gtk_box_set_spacing (GTK_BOX (hbuttonbox), 4);

	if (config.default_stock_icons) {
		close_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
	} else {
		close_button = gtk_button_new_from_stock (OSMO_STOCK_BUTTON_CLOSE);
	}
	gtk_widget_show (close_button);
	g_signal_connect (close_button, "clicked", G_CALLBACK (button_birthdays_window_close_cb), appGUI);
	gtk_container_add (GTK_CONTAINER (hbuttonbox), close_button);

	gtk_widget_show (appGUI->cnt->birthdays_window);
	gtk_widget_grab_focus (close_button);
}
Пример #12
0
void
cal_read_notes (GUI *appGUI)
{
xmlDocPtr doc;
xmlChar *key, *prop;
xmlNodePtr node, cnode, category_node;
GtkTreeIter iter;
GdkPixbuf *image;
guint32 julian;
gint day, month, year;
gchar *color_str, *note;
GDate *date;

	appGUI->cal->notes_list = NULL;

	date = g_date_new ();
	g_return_if_fail (date != NULL);

	if (g_file_test (prefs_get_config_filename (CALENDAR_NOTES_FILENAME, appGUI), G_FILE_TEST_IS_REGULAR) == FALSE)
		return;

	if ((doc = xmlParseFile (prefs_get_config_filename (CALENDAR_NOTES_FILENAME, appGUI)))) {

		if (!(node = xmlDocGetRootElement (doc))) return;

		if (!xmlStrcmp (node->name, (xmlChar *) CALENDAR_NOTES_NAME)) {

			/* read note */
			node = node->xmlChildrenNode;

			while (node != NULL) {

				if (!xmlStrcmp (node->name, (xmlChar *) CALENDAR_DAY_CATEGORIES_NAME)) {
					category_node = node->xmlChildrenNode;

					while (category_node != NULL) {

						if ((!xmlStrcmp (category_node->name, (const xmlChar *) "name"))) {
							key = xmlNodeListGetString (doc, category_node->xmlChildrenNode, 1);
							prop = xmlGetProp (category_node, (const xmlChar *) "color");
							if (key != NULL) {
								image = gui_create_color_swatch ((gchar *) prop);
								gtk_list_store_append (appGUI->opt->calendar_category_store, &iter);
								gtk_list_store_set (appGUI->opt->calendar_category_store, &iter, 0, image,
								                    1, prop, 2, (gchar *) key, -1);
								g_object_unref (image);
								xmlFree (key);
							}
						}

						category_node = category_node->next;
					}

				}

				if (!xmlStrcmp (node->name, (xmlChar *) "note")) {
					cnode = node->xmlChildrenNode;
					julian = 0;
					day = month = year = 0;
					color_str = NULL;
					note = NULL;

					while (cnode != NULL) {
						utl_xml_get_int ("day", &day, cnode, doc);
						utl_xml_get_int ("month", &month, cnode, doc);
						utl_xml_get_int ("year", &year, cnode, doc);
						utl_xml_get_uint ("date", &julian, cnode, doc);
						utl_xml_get_str ("color", &color_str, cnode, doc);
						utl_xml_get_str ("message", &note, cnode, doc);
						cnode = cnode->next;
					}

					if (note != NULL && (g_date_valid_dmy (day, month, year) || g_date_valid_julian (julian))) {
						if (g_date_valid_julian (julian)) g_date_set_julian (date, julian);
						else g_date_set_dmy (date, day, month, year);

						cal_add_note (date, color_str, note, appGUI);
						if (color_str != NULL) g_free (color_str);
						g_free (note);
					}
				}

				node = node->next;
			}

		}

		xmlFree (node);
		xmlFreeDoc (doc);
	}

	g_date_free (date);
}
Пример #13
0
static void
load_chain (PatrolDialogWindow *self, PatrolDialogRecord *r,
            guint idx, GtkWidget *container)
{
    /* build tree model */
    GtkTreeStore *tree_store = gtk_tree_store_new(COLS_NUM, G_TYPE_STRING,
                                                  G_TYPE_BOOLEAN, G_TYPE_INT,
                                                  G_TYPE_POINTER, G_TYPE_POINTER);

    GtkTreeIter *parent = NULL, iter;
    gint i, num_certs = gcr_certificate_chain_get_length(r->chain);
    GcrCertificate *cert = NULL;

    for (i = num_certs - 1; i >= 0; i--) {
        cert = gcr_certificate_chain_get_certificate(r->chain, i);
        gchar *label = gcr_certificate_get_subject_name(cert);

        gtk_tree_store_append(tree_store, &iter, parent);
        gtk_tree_store_set(tree_store, &iter,
                           COL_NAME, label,
                           COL_PIN, i == r->pin_level,
                           COL_PIN_LEVEL, i,
                           COL_CERT, cert,
                           COL_REC, r,
                           -1);
        parent = &iter;
        g_free(label);
    }

    /* set hierarchy title */
    GtkWidget *title_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_box_pack_start(GTK_BOX(container), title_box, FALSE, FALSE, 0);
    gchar *text, *str;
    GtkWidget *label = gtk_label_new(NULL);
    GtkWidget *value;

    if (idx == 0) {
        switch (self->pv->result) {
        case  PATROL_VERIFY_NEW:
        case  PATROL_VERIFY_CHANGE:
            text = g_strdup_printf("<b>%s</b>", _("New Certificate"));
            break;
        case  PATROL_VERIFY_REJECT:
            text = g_strdup_printf("<b>%s</b>", _("Rejected Certificate"));
            break;
        default:
            text = g_strdup_printf("<b>%s</b>", _("Selected Certificate"));
            break;
        }
    } else {
        text = g_strdup_printf("<b>%s #%d</b>", _("Stored Certificate"), idx);
        gtk_widget_set_margin_bottom(GTK_WIDGET(label), 2);
    }

    gtk_label_set_markup(GTK_LABEL(label), text);
    g_free(text);
    gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
    gtk_box_pack_start(GTK_BOX(title_box), label, FALSE, FALSE, 0);

    GtkWidget *grid = gtk_grid_new();
    gtk_widget_set_margin_left(GTK_WIDGET(grid), 5);
    gtk_box_pack_start(GTK_BOX(title_box), grid, FALSE, FALSE, 0);

    label = gtk_label_new(NULL);
    gtk_label_set_text(GTK_LABEL(label), _("Seen: "));
    str = g_strdup_printf("%" G_GINT64_FORMAT, r->rec.count_seen);
    text = g_strdup_printf(g_dngettext(textdomain(NULL),
                                       "%s time", "%s times",
                                       r->rec.count_seen), str);
    g_free(str);
    value = gtk_label_new(NULL);
    gtk_label_set_text(GTK_LABEL(value), text);
    g_free(text);
    gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
    gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START);
    gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(grid), value, 1, 0, 1, 1);

    label = gtk_label_new(NULL);
    gtk_label_set_text(GTK_LABEL(label), _("First seen: "));
    GDateTime *dtime = g_date_time_new_from_unix_local(r->rec.first_seen);
    text = g_date_time_format(dtime, "%c");
    g_date_time_unref(dtime);
    value = gtk_label_new(NULL);
    gtk_label_set_text(GTK_LABEL(value), text);
    g_free(text);
    gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
    gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START);
    gtk_grid_attach(GTK_GRID(grid), label, 0, 1, 1, 1);
    gtk_grid_attach(GTK_GRID(grid), value, 1, 1, 1, 1);

    if (r->rec.first_seen != r->rec.last_seen) {
        label = gtk_label_new(NULL);
        gtk_label_set_text(GTK_LABEL(label), _("Last seen: "));
        dtime = g_date_time_new_from_unix_local(r->rec.last_seen);
        text = g_date_time_format(dtime, "%c");
        g_date_time_unref(dtime);
        value = gtk_label_new(NULL);
        gtk_label_set_text(GTK_LABEL(value), text);
        g_free(text);
        gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
        gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START);
        gtk_grid_attach(GTK_GRID(grid), label, 0, 2, 1, 1);
        gtk_grid_attach(GTK_GRID(grid), value, 1, 2, 1, 1);
    }

    if (cert) {
        label = gtk_label_new(NULL);
        gtk_label_set_text(GTK_LABEL(label), _("Validity: "));

        GDate *expiry = gcr_certificate_get_expiry_date(cert);
        GDate *now = g_date_new();
        g_date_set_time_t(now, time(NULL));
        gint diff = g_date_days_between(now, expiry);
        g_date_free(now);
        g_date_free(expiry);

        if (diff > 0) {
            text = g_strdup_printf(g_dngettext(textdomain(NULL),
                                               "Certificate is valid for %d more day",
                                               "Certificate is valid for %d more days",
                                               diff), diff);
        } else if (diff < 0) {
            diff = abs(diff);
            text = g_strdup_printf(g_dngettext(textdomain(NULL),
                                               "Certificate <b>expired</b> %d day ago",
                                               "Certificate <b>expired</b> %d days ago",
                                               diff), diff);
        } else {
            text = g_strdup_printf("Certificate expires today");
        }

        value = gtk_label_new(NULL);
        gtk_label_set_markup(GTK_LABEL(value), text);
        g_free(text);

        gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
        gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START);
        gtk_grid_attach(GTK_GRID(grid), label, 0, 3, 1, 1);
        gtk_grid_attach(GTK_GRID(grid), value, 1, 3, 1, 1);
    }

    gtk_widget_show_all(title_box);

    /* build tree view */
    GtkWidget *tree_view;
    tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));
    gtk_tree_view_expand_all(GTK_TREE_VIEW(tree_view));
    gtk_box_pack_start(GTK_BOX(container), tree_view, FALSE, FALSE, 0);
    gtk_widget_show(tree_view);

    g_signal_connect(tree_view, "focus-in-event",
                     G_CALLBACK(on_tree_view_focus), self);
    g_signal_connect(self->pv->renderer, "data-changed",
                     G_CALLBACK(on_cert_changed), tree_view);
    GtkTreeSelection *tree_sel
        = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
    g_signal_connect(tree_sel, "changed", 
                     G_CALLBACK(on_tree_selection_changed), self);

    if (idx == 0) // new chain
        gtk_tree_selection_select_iter(tree_sel, &iter);

    /* first column */
    GtkCellRenderer *tree_renderer = gtk_cell_renderer_text_new();
    GtkTreeViewColumn *tree_column
        = gtk_tree_view_column_new_with_attributes(_("Certificate Hierarchy"),
                                                   tree_renderer, "text",
                                                   COL_NAME, NULL);
    gtk_tree_view_column_set_expand (tree_column, TRUE);
    gtk_tree_view_insert_column (GTK_TREE_VIEW (tree_view), tree_column, -1);

    /* second column */
    GtkCellRenderer *toggle_renderer = gtk_cell_renderer_toggle_new();
    g_signal_connect(toggle_renderer, "toggled",
                     G_CALLBACK(on_radio_toggled), tree_store);
    gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(toggle_renderer),
                                       TRUE);

    gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view), -1,
                                                _("Pin"), toggle_renderer,
                                                "active", COL_PIN, NULL);
    g_object_unref(tree_store);
}
Пример #14
0
void hb_export_pdf_listview(GtkTreeView *treeview, gchar *filepath, gchar *accname)
{
cairo_surface_t *surf;
cairo_t *cr;
PdfPrintContext ppc;
PangoFontDescription *desc;
PangoLayout *layout;
GtkTreeModel *model;
GtkTreeIter	iter;
gboolean valid;
gint i, col;

	
	DB( g_print("[gtk-chart] export to pdf\n") );

	model = gtk_tree_view_get_model(treeview);
	
	papersize(&ppc);

	//gchar *filename = "/home/max/Desktop/hb-txn-export.pdf";
	double width;	//=210 * 2.83;
	double height;	//=297 * 2.83;
	
	width  = ppc.w;
	height = ppc.h;

	surf = cairo_pdf_surface_create (filepath, width, height);
	
	if( cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS )
	//todo: manage error later on
		return;

	
	cr = cairo_create (surf);
	//cairo_pdf_surface_set_size(surf, width * 2.83, height * 2.83);

	//g_print("width=%d\n", cairo_image_surface_get_width( surf));
	double x1, x2, y1, y2;
	cairo_clip_extents (cr, &x1, &y1, &x2, &y2);

	DB( g_print("surface w=%f, h=%f\n", x2 - x1, y2 - y1) );
	double pwidth = x2 - x1;
	
	
	/* Create a PangoLayout, set the font and text */
	layout = pango_cairo_create_layout (cr);

	/* get and copy the font from the treeview widget */
	gtk_style_context_get(gtk_widget_get_style_context(GTK_WIDGET(treeview)), GTK_STATE_FLAG_NORMAL, "font", &desc, NULL);
	ppc.desc = pango_font_description_copy(desc);

	DB( g_print("family: %s\n", pango_font_description_get_family(desc)) );
	DB( g_print("size: %d (%d)\n", pango_font_description_get_size (desc), pango_font_description_get_size (desc )/PANGO_SCALE) );


	
	/* header is 1 line for date page number at top, then a title in bold, then 2 empty lines */
	gint header_height = PDF_FONT_NORMAL * 2 + PDF_FONT_TITLE;
	gint nb_lines = gtk_tree_model_iter_n_children(model, NULL);

	/* should include here the headertitle line */
	
	gint lpp = floor ((height-header_height-ppc.mt-ppc.mb) / (PDF_FONT_NORMAL + PDF_LINE_MARGIN));
	gint page, num_pages = (nb_lines - 1) / lpp + 1;

	DB( g_print("\n - should pdf %d lines, lpp=%d, num_pages=%d\n", nb_lines, lpp, num_pages) );


	gint tot_lines = 0;
	gint cur_page_line = 1;

	gchar dbuffer[255];
	gchar amtbuf[G_ASCII_DTOSTR_BUF_SIZE];
	gchar balbuf[G_ASCII_DTOSTR_BUF_SIZE];

	GDate *date = g_date_new ();

	//cairo_set_font_size(cr, PDF_FONT_NORMAL);
	pango_font_description_set_absolute_size(ppc.desc, PDF_FONT_NORMAL * PANGO_SCALE);
	pango_layout_set_font_description (layout, ppc.desc);
	
	/* reset struct */
	hb_pdf_set_col_title(&ppc);
	
	for(col=0;col<PDF_NUMCOL;col++)
	{
	int tw, th;

		ppc.column_width[col] = 0;
		pango_layout_set_text (layout, ppc.column_txt[col], -1);
		pango_layout_get_size (layout, &tw, &th);
		ppc.column_width[col] = MAX(ppc.column_width[col], tw / PANGO_SCALE);
	}


	DB( g_print(" - compute width\n") );

	/* first pass to get max width */
	valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
	while (valid)
	{
	Transaction *txn;
	int tw, th;
			
		gtk_tree_model_get (model, &iter, LST_DSPOPE_DATAS, &txn, -1);

		i = 0;
		g_date_set_julian (date, txn->date);
		g_date_strftime (dbuffer, 255-1, "%x", date);
		pango_layout_set_text (layout, dbuffer, -1);
		pango_layout_get_size (layout, &tw, &th);
		ppc.column_width[i] = MAX(ppc.column_width[i], tw / PANGO_SCALE);
		
		i = 1;
		if(txn->info != NULL && strlen(txn->info) > 0)
		{
			pango_layout_set_text (layout, txn->info, -1);
			pango_layout_get_size (layout, &tw, &th);
			ppc.column_width[i] = MAX(ppc.column_width[i], tw / PANGO_SCALE);
		}
		
		i = 4;
		hb_strfnum(amtbuf, G_ASCII_DTOSTR_BUF_SIZE-1, txn->amount, txn->kcur, GLOBALS->minor);
		pango_layout_set_text (layout, amtbuf, -1);
		pango_layout_get_size (layout, &tw, &th);
		ppc.column_width[i] = MAX(ppc.column_width[i], tw / PANGO_SCALE);

		i = 5;
		pango_layout_set_text (layout, "R", -1);
		pango_layout_get_size (layout, &tw, &th);
		ppc.column_width[i] = MAX(ppc.column_width[i], tw / PANGO_SCALE);

		i = 6;
		hb_strfnum(balbuf, G_ASCII_DTOSTR_BUF_SIZE-1, txn->balance, txn->kcur, GLOBALS->minor);
		pango_layout_set_text (layout, balbuf, -1);
		pango_layout_get_size (layout, &tw, &th);
		ppc.column_width[i] = MAX(ppc.column_width[i], tw / PANGO_SCALE);

		valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
	}

	/* distribute remaining size */
	gdouble tmp = pwidth - ppc.ml - ppc.mr - (PDF_COL_MARGIN*PDF_NUMCOL);


	DB( g_print(" page width=%f, remain width=%f\n", pwidth, tmp) );
	
	tmp -= ppc.column_width[0];
	tmp -= ppc.column_width[4];
	tmp -= ppc.column_width[5];
	tmp -= ppc.column_width[6];
	
	/* info=1/4 payee=1/4 memo=2/4 */
	ppc.column_width[1] = tmp / 4;;
	ppc.column_width[2] = tmp / 4;
	ppc.column_width[3] = 2*tmp / 4;

	DB( g_print(" page width=%f, remain width=%f\n", width, tmp) );
	
	#if MYDEBUG == 1
	for(i=0;i<PDF_NUMCOL;i++)
		g_print(" col%d=%g ", i, ppc.column_width[i]);

	g_print("\n");
	#endif

	DB( g_print("\n - start printing\n") );
	
	gint y;
	page = 1;
	valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
	while (valid)
	{
	Transaction *txn;
	int tw, th;
			
		gtk_tree_model_get (model, &iter, LST_DSPOPE_DATAS, &txn, -1);

		//DB( g_print(" - %d, %d, %s\n", x, y, txn->memo) );
		if(cur_page_line == 1)
		{
			//helpdraw
			#if HELPDRAW == 1
			//page with margin
			hb_pdf_draw_help_rect(cr, 0xFF0000FF, ppc.ml+0.5, ppc.mt+0.5, width-(ppc.ml+ppc.mr), height - (ppc.mt+ppc.mb));
			hb_pdf_draw_help_rect(cr, 0xFF00FFFF, ppc.ml+0.5, ppc.mt+0.5, width-(ppc.ml+ppc.mr), header_height);
			#endif

			cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);

			// draw account title
			pango_font_description_set_absolute_size(ppc.desc, PDF_FONT_TITLE * PANGO_SCALE);
			pango_layout_set_font_description (layout, ppc.desc);

			pango_layout_set_text (layout, accname, -1);
			pango_layout_get_pixel_size (layout, &tw, &th);
			cairo_move_to(cr, pwidth/2 - (tw/2), ppc.mt);
			pango_cairo_show_layout (cr, layout);

			// draw column titles
			pango_font_description_set_absolute_size(ppc.desc, PDF_FONT_NORMAL * PANGO_SCALE);
			pango_layout_set_font_description (layout, ppc.desc);

			g_sprintf(dbuffer, "Page %d/%d", page, num_pages);
			pango_layout_set_text (layout, dbuffer, -1);
			pango_layout_get_pixel_size (layout, &tw, &th);
			cairo_move_to(cr, pwidth - ppc.mr - tw, ppc.mt);
			pango_cairo_show_layout (cr, layout);

			//x = ppc.ml;
			y = ppc.mt + header_height - (PDF_FONT_NORMAL + PDF_LINE_MARGIN);
			hb_pdf_set_col_title(&ppc);

			hb_pdf_draw_line(&ppc, cr, y, TRUE, FALSE);
		}

		/* print a single line */
		//x = ppc.ml;
		y = ppc.mt + header_height + (cur_page_line * (PDF_FONT_NORMAL + PDF_LINE_MARGIN));



		/* reset struct */
		for(i=0;i<PDF_NUMCOL;i++)
		{
			ppc.column_txt[i] = NULL;
		}
		
		i = 0;
		g_date_set_julian (date, txn->date);
		g_date_strftime (dbuffer, 255-1, "%x", date);
		ppc.column_txt[i] = dbuffer;
		
		i = 1;
		ppc.column_txt[i] = txn->info;

		i = 2;
		Payee *p = da_pay_get(txn->kpay);
		if(p)
			ppc.column_txt[i] = p->name;

		i = 3;
		/*Category *c = da_cat_get(txn->kcat);
		if(c)
			ppc.column_txt[i] = da_cat_get_fullname(c);*/
		ppc.column_txt[i] = txn->memo;
			
		i = 4;
		hb_strfnum(amtbuf, G_ASCII_DTOSTR_BUF_SIZE-1, txn->amount, txn->kcur, GLOBALS->minor);
		ppc.column_txt[i] = amtbuf;

		i = 5;
		ppc.column_txt[i] = "";
		if(txn->status == TXN_STATUS_CLEARED)
			ppc.column_txt[i] = "c";
		else
		if(txn->status == TXN_STATUS_RECONCILED)
			ppc.column_txt[i] = "R";
		
		i = 6;
		hb_strfnum(balbuf, G_ASCII_DTOSTR_BUF_SIZE-1, txn->balance, txn->kcur, GLOBALS->minor);
		ppc.column_txt[i] = balbuf;

		hb_pdf_draw_line(&ppc, cr, y, FALSE, (cur_page_line % 2));
		
		/* free any fullcat name */
		/*if(ppc.column_txt[3] != NULL)
			g_free(ppc.column_txt[3]);*/
		
		/* export page */		
		if(cur_page_line >= lpp)
		{
			DB( g_print("\n - next page %d\n", page) );
			
			cairo_show_page(cr);
			cur_page_line = 0;
			page++;
		}

		cur_page_line++;
		tot_lines++;
		valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
	}

	g_date_free(date);

	g_object_unref (layout);
	pango_font_description_free (ppc.desc);

	cairo_destroy (cr);
	cairo_surface_destroy (surf);

}
Пример #15
0
/**
 * ephy_web_application_get_application_list:
 *
 * Gets a list of the currently installed web applications.
 * Free the returned GList with
 * ephy_web_application_free_application_list.
 *
 * Returns: (transfer-full): a #GList of #EphyWebApplication objects
 **/
GList *
ephy_web_application_get_application_list ()
{
  GFileEnumerator *children = NULL;
  GFileInfo *info;
  GList *applications = NULL;
  GFile *dot_dir;

  dot_dir = g_file_new_for_path (ephy_dot_dir ());
  children = g_file_enumerate_children (dot_dir,
                                        "standard::name",
                                        0, NULL, NULL);
  g_object_unref (dot_dir);

  info = g_file_enumerator_next_file (children, NULL, NULL);
  while (info) {
    EphyWebApplication *app;
    const char *name;
    glong prefix_length = g_utf8_strlen (EPHY_WEB_APP_PREFIX, -1);

    name = g_file_info_get_name (info);
    if (g_str_has_prefix (name, EPHY_WEB_APP_PREFIX)) {
      char *profile_dir;
      guint64 created;
      GDate *date;
      char *desktop_file, *desktop_file_path;
      char *contents;
      GFileInfo *desktop_info;

      app = g_slice_new0 (EphyWebApplication);

      profile_dir = g_build_filename (ephy_dot_dir (), name, NULL);
      app->icon_url = g_build_filename (profile_dir, EPHY_WEB_APP_ICON_NAME, NULL);

      desktop_file = g_strconcat (name + prefix_length, ".desktop", NULL);
      desktop_file_path = g_build_filename (profile_dir, desktop_file, NULL);
      app->desktop_file = g_strdup (desktop_file);

      if (g_file_get_contents (desktop_file_path, &contents, NULL, NULL)) {
        char *exec;
        char **strings;
        GKeyFile *key;
        int i;
        GFile *file;

        key = g_key_file_new ();
        g_key_file_load_from_data (key, contents, -1, 0, NULL);
        app->name = g_key_file_get_string (key, "Desktop Entry", "Name", NULL);
        exec = g_key_file_get_string (key, "Desktop Entry", "Exec", NULL);
        strings = g_strsplit (exec, " ", -1);

        for (i = 0; strings[i]; i++);
        app->url = g_strdup (strings[i - 1]);

        g_strfreev (strings);
        g_free (exec);
        g_key_file_free (key);

        file = g_file_new_for_path (desktop_file_path);

        /* FIXME: this should use TIME_CREATED but it does not seem to be working. */
        desktop_info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL);
        created = g_file_info_get_attribute_uint64 (desktop_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);

        date = g_date_new ();
        g_date_set_time_t (date, (time_t)created);
        g_date_strftime (app->install_date, 127, "%x", date);

        g_date_free (date);
        g_object_unref (file);
        g_object_unref (desktop_info);

        applications = g_list_append (applications, app);
      }

      g_free (contents);
      g_free (desktop_file);
      g_free (profile_dir);
      g_free (desktop_file_path);
    }

    g_object_unref (info);

    info = g_file_enumerator_next_file (children, NULL, NULL);
  }

  g_object_unref (children);

  return applications;
}
Пример #16
0
static void
draw_info_header (GtkPrintContext *context,
                  cairo_t         *cr,
                  PrintData       *data)
{
  PangoLayout          *layout;
  PangoFontDescription *desc;
  gdouble               text_height;
  gdouble               text_width;
  gdouble               fname_text_width;
  gint                  layout_height;
  gint                  layout_width;
  gchar                 date_buffer[100];
  GDate                *date;
  const gchar          *name_str;
  GimpParasite         *parasite;
  const gchar          *end_ptr;
  gchar                *filename;
  gdouble               cr_width;

  cairo_save (cr);

  cr_width  = gtk_print_context_get_width (context);
  cairo_rectangle (cr, 0, 0, cr_width, HEADER_HEIGHT);
  cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
  cairo_fill_preserve (cr);

  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_set_line_width (cr, 1);
  cairo_stroke (cr);

  layout = gtk_print_context_create_pango_layout (context);

  desc = pango_font_description_from_string ("sans 14");
  pango_layout_set_font_description (layout, desc);
  pango_font_description_free (desc);

  pango_layout_set_width (layout, -1);
  pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);

  /* image name */
  pango_layout_set_text (layout, gimp_image_get_name (data->image_id), -1);

  pango_layout_get_size (layout, &layout_width, &layout_height);
  text_height = (gdouble) layout_height / PANGO_SCALE;

  cairo_move_to (cr, 0.02 * cr_width,  (HEADER_HEIGHT - text_height) / 5);
  pango_cairo_show_layout (cr, layout);

  /* user name */
  name_str = g_get_real_name ();
  if (name_str && g_utf8_validate (name_str, -1, &end_ptr))
    {
      pango_layout_set_text (layout, name_str, -1);

      pango_layout_get_size (layout, &layout_width, &layout_height);
      text_height = (gdouble) layout_height / PANGO_SCALE;
      text_width = (gdouble) layout_width / PANGO_SCALE;

      cairo_move_to (cr, 0.5 * cr_width - 0.5 * text_width,
                     (HEADER_HEIGHT - text_height) / 5);
      pango_cairo_show_layout (cr, layout);
    }

  /* date */
  date = g_date_new ();
  g_date_set_time_t (date, time (NULL));
  g_date_strftime (date_buffer, 100, "%x", date);
  g_date_free (date);
  pango_layout_set_text (layout, date_buffer, -1);

  pango_layout_get_size (layout, &layout_width, &layout_height);
  text_height = (gdouble) layout_height / PANGO_SCALE;
  text_width = (gdouble) layout_width / PANGO_SCALE;

  cairo_move_to (cr,
                 0.98 * cr_width - text_width,
                 (HEADER_HEIGHT - text_height) / 5);
  pango_cairo_show_layout (cr, layout);

  /* file name if any */
  filename = gimp_image_get_filename (data->image_id);

  if (filename)
    {
      pango_layout_set_text (layout,
                             gimp_filename_to_utf8 (filename), -1);
      g_free (filename);

      pango_layout_get_size (layout, &layout_width, &layout_height);
      text_height = (gdouble) layout_height / PANGO_SCALE;
      fname_text_width = (gdouble) layout_width / PANGO_SCALE;

      cairo_move_to (cr,
                     0.02 * cr_width,  4 * (HEADER_HEIGHT - text_height) / 5);
      pango_cairo_show_layout (cr, layout);
    }
  else
    {
      fname_text_width = 0;
    }

  /* image comment if it is short */
  parasite = gimp_image_parasite_find (data->image_id, "gimp-comment");

  if (parasite)
    {
      pango_layout_set_text (layout, gimp_parasite_data (parasite), -1);

      pango_layout_get_size (layout, &layout_width, &layout_height);
      text_height = (gdouble) layout_height / PANGO_SCALE;
      text_width = (gdouble) layout_width / PANGO_SCALE;

      if (fname_text_width + text_width < 0.8 * cr_width &&
          text_height < 0.5 * HEADER_HEIGHT)
        {
          cairo_move_to (cr, 0.98 * cr_width - text_width,
                         4 * (HEADER_HEIGHT - text_height) / 5);
          pango_cairo_show_layout (cr, layout);
        }

      gimp_parasite_free (parasite);
    }

  g_object_unref (layout);

  cairo_restore (cr);
}
Пример #17
0
static gboolean rc_plugin_tag_data_save_cb()
{
    const gchar *title, *artist, *album, *track, *genre;
    const gchar *year, *comment, *rg, *format, *path_uri;
    guint year_value, track_value;
    gdouble rg_value;
    GDate *date;
    GstTagList *tag_list;
    gchar *src_path, *target_path;
    gboolean flag = FALSE;
    path_uri = gtk_entry_get_text(GTK_ENTRY(tag_ui.path_entry));
    if(path_uri==NULL || strlen(path_uri)==0) return FALSE;
    if(working_flag) return FALSE;
    title = gtk_entry_get_text(GTK_ENTRY(tag_ui.title_entry));
    artist = gtk_entry_get_text(GTK_ENTRY(tag_ui.artist_entry));
    album = gtk_entry_get_text(GTK_ENTRY(tag_ui.album_entry));
    track = gtk_entry_get_text(GTK_ENTRY(tag_ui.track_entry));
    genre = gtk_entry_get_text(GTK_ENTRY(tag_ui.genre_entry));
    year = gtk_entry_get_text(GTK_ENTRY(tag_ui.year_entry));
    comment = gtk_entry_get_text(GTK_ENTRY(tag_ui.comment_entry));
    rg = gtk_entry_get_text(GTK_ENTRY(tag_ui.rg_entry));
    format = gtk_label_get_text(GTK_LABEL(tag_ui.format_entry));
    tag_list = gst_tag_list_new();
    gst_tag_list_add(tag_list, GST_TAG_MERGE_REPLACE_ALL, GST_TAG_TITLE,
        title, GST_TAG_ARTIST, artist, GST_TAG_ALBUM, album, GST_TAG_GENRE,
        genre, GST_TAG_COMMENT, comment, NULL);
    if(sscanf(track, "%u", &track_value)>=1)
    {
        gst_tag_list_add(tag_list, GST_TAG_MERGE_REPLACE,
            GST_TAG_TRACK_NUMBER, track_value, NULL);
    }
    if(sscanf(year, "%u", &year_value)>=1)
    {
        date = g_date_new();
        g_date_set_year(date, year_value);
        gst_tag_list_add(tag_list, GST_TAG_MERGE_REPLACE,
            GST_TAG_DATE, date, NULL);
        g_date_free(date);
    }
    if(sscanf(rg, "%lf", &rg_value)>=1)
    {
        gst_tag_list_add(tag_list, GST_TAG_MERGE_REPLACE,
            GST_TAG_TRACK_GAIN, rg_value, NULL);
    }
    src_path = g_filename_from_uri(path_uri, NULL, NULL);
    target_path = g_strdup_printf("%s.newname", src_path);
    flag = TRUE;
    if(g_strcmp0(format, "FLAC")==0)
        flag = rc_plugin_tag_flac_change(src_path, target_path, tag_list);
    else if(g_strcmp0(format, "MPEG 1 Audio, Layer 3 (MP3)")==0)
        flag = rc_plugin_tag_mp3_change(src_path, target_path, tag_list);
    else if(g_strcmp0(format, "Vorbis")==0)
        flag = rc_plugin_tag_vorbis_change(src_path, target_path, tag_list);
    else if(strncmp(format, "Windows Media Audio", 20)==0)
        flag = rc_plugin_tag_wma_change(src_path, target_path, tag_list);
    else if(g_strcmp0(format, "MPEG-4 AAC audio")==0)
        flag = rc_plugin_tag_m4a_change(src_path, target_path, tag_list);
    else if(g_strcmp0(format, "Monkey's Audio")==0)
        flag = rc_plugin_tag_ape_change(src_path, target_path, tag_list);
    else
    {
        rc_debug_perror("TagEditor-ERROR: Unsupported format!\n");
        flag = FALSE;
    }
    gst_tag_list_free(tag_list);
    if(flag)
    {
        gtk_widget_set_sensitive(tag_ui.save_button, FALSE);
        working_flag = TRUE;
        if(tag_src_path!=NULL) g_free(tag_src_path);
        tag_src_path = g_strdup(src_path);
        if(tag_target_path!=NULL) g_free(tag_target_path);
        tag_target_path = g_strdup(target_path);
    }
    g_free(src_path);
    g_free(target_path);
    return FALSE;
}
Пример #18
0
/**
 * table_output:
 *
 * Update the given widgets table with the values from the track stats
 */
static void table_output ( track_stats ts, GtkWidget *content[], gboolean extended )
{
	int cnt = 0;

	gchar tmp_buf[64];
	g_snprintf ( tmp_buf, sizeof(tmp_buf), "%d", ts.count );
	gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

	if ( ts.count == 0 ) {
		// Blank all other fields
		g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		for ( cnt = 1; cnt < G_N_ELEMENTS(label_texts); cnt++ )
			gtk_label_set_text ( GTK_LABEL(content[cnt]), tmp_buf );
		return;
	}

	// Check for potential date range
	// Test if the same day by comparing the date string of the timestamp
	GDate* gdate_start = g_date_new ();
	g_date_set_time_t ( gdate_start, ts.start_time );
	gchar time_start[32];
	g_date_strftime ( time_start, sizeof(time_start), "%x", gdate_start );
	g_date_free ( gdate_start );

	GDate* gdate_end = g_date_new ();
	g_date_set_time_t ( gdate_end, ts.end_time );
	gchar time_end[32];
	g_date_strftime ( time_end, sizeof(time_end), "%x", gdate_end );
	g_date_free ( gdate_end );

	if ( ts.start_time == ts.end_time )
		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("No Data") );
	else if ( strncmp(time_start, time_end, 32) )
		g_snprintf ( tmp_buf, sizeof(tmp_buf), "%s --> %s", time_start, time_end );
	else
		g_snprintf ( tmp_buf, sizeof(tmp_buf), "%s", time_start );

	gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

	switch (a_vik_get_units_distance ()) {
	case VIK_UNITS_DISTANCE_MILES:
		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.1f miles"), VIK_METERS_TO_MILES(ts.length) );
		break;
	case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.1f NM"), VIK_METERS_TO_NAUTICAL_MILES(ts.length) );
		break;
	default:
		//VIK_UNITS_DISTANCE_KILOMETRES
		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.1f km"), ts.length/1000.0 );
		break;
	}
	gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

	switch (a_vik_get_units_distance ()) {
	case VIK_UNITS_DISTANCE_MILES:
		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.2f miles"), (VIK_METERS_TO_MILES(ts.length)/ts.count) );
		break;
	case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.2f NM"), (VIK_METERS_TO_NAUTICAL_MILES(ts.length)/ts.count) );
		break;
	default:
		//VIK_UNITS_DISTANCE_KILOMETRES
		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.2f km"), ts.length/(1000.0*ts.count) );
		break;
	}
	gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

	if ( extended ) {
		// Note that this currently is a simplified approach to calculate the Eddington number.
		// In that a per track value is used, rather than trying to work out a length per day.
		//  (i.e. doesn't combine multiple tracks for a single day or split very long tracks into days)
		tracks_stats[TS_TRACKS].e_list = g_list_sort ( tracks_stats[TS_TRACKS].e_list, rsort_by_distance );
		guint Eddington = 0;
		guint position = 0;
		for (GList *iter = g_list_first (tracks_stats[TS_TRACKS].e_list); iter != NULL; iter = g_list_next (iter)) {
			position++;
			gdouble *num = (gdouble*)iter->data;
			if ( *num > position )
				Eddington = position;
		}
		g_snprintf ( tmp_buf, sizeof(tmp_buf), ("%d"), Eddington );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
	} else
		cnt++;

	// I'm sure this could be cleaner...
	g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
	switch (a_vik_get_units_speed()) {
	case VIK_UNITS_SPEED_MILES_PER_HOUR:
		if ( ts.max_speed > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.1f mph"), (double)VIK_MPS_TO_MPH(ts.max_speed) );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
		if ( ts.duration > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), ("%.1f mph"), (double)VIK_MPS_TO_MPH(ts.length/ts.duration) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		break;
	case VIK_UNITS_SPEED_METRES_PER_SECOND:
		if ( ts.max_speed > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.2f m/s"), (double)ts.max_speed );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
		if ( ts.duration > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), ("%.2f m/s"), (double)(ts.length/ts.duration) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		break;
	case VIK_UNITS_SPEED_KNOTS:
		if ( ts.max_speed > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.2f knots"), (double)VIK_MPS_TO_KNOTS(ts.max_speed) );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
		if ( ts.duration > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.2f knots"), (double)VIK_MPS_TO_KNOTS(ts.length/ts.duration) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		break;
	case VIK_UNITS_SPEED_SECONDS_PER_KM:
		if ( ts.max_speed > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d s/km"), (int)VIK_MPS_TO_PACE_SPK(ts.max_speed) );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
		if ( ts.duration > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d s/km"), (int)VIK_MPS_TO_PACE_SPK(ts.length/ts.duration) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		break;

	case VIK_UNITS_SPEED_MINUTES_PER_KM:
		if ( ts.max_speed > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.1f min/km"), (double)VIK_MPS_TO_PACE_MPK(ts.max_speed) );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
		if ( ts.duration > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.1f min/km"), (double)VIK_MPS_TO_PACE_MPK(ts.length/ts.duration) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		break;

	case VIK_UNITS_SPEED_SECONDS_PER_MILE:
		if ( ts.max_speed > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d sec/mi"), (int)VIK_MPS_TO_PACE_SPM(ts.max_speed) );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
		if ( ts.duration > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d sec/mi"), (int)VIK_MPS_TO_PACE_SPM(ts.length/ts.duration) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		break;

	case VIK_UNITS_SPEED_MINUTES_PER_MILE:
		if ( ts.max_speed > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.1f min/mi"), (double)VIK_MPS_TO_PACE_MPM(ts.max_speed) );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
		if ( ts.duration > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.1f min/mi"), (double)VIK_MPS_TO_PACE_MPM(ts.length/ts.duration) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		break;

	default:
		//VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
		if ( ts.max_speed > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.2f km/h"), (double)VIK_MPS_TO_KPH(ts.max_speed) );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
		if ( ts.duration > 0 )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%.2f km/h"), (double)VIK_MPS_TO_KPH(ts.length/ts.duration) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		break;
	}
	gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

	switch ( a_vik_get_units_height() ) {
		// Note always round off height value output since sub unit accuracy is overkill
	case VIK_UNITS_HEIGHT_FEET:
		if ( ts.min_alt != VIK_VAL_MIN_ALT )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d feet"), (int)round(VIK_METERS_TO_FEET(ts.min_alt)) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

		if ( ts.max_alt != VIK_VAL_MAX_ALT )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d feet"), (int)round(VIK_METERS_TO_FEET(ts.max_alt)) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d feet / %d feet"), (int)round(VIK_METERS_TO_FEET(ts.elev_gain)), (int)round(VIK_METERS_TO_FEET(ts.elev_loss)) );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d feet / %d feet"), (int)round(VIK_METERS_TO_FEET(ts.elev_gain/ts.count)), (int)round(VIK_METERS_TO_FEET(ts.elev_loss/ts.count)) );
		break;
	default:
		//VIK_UNITS_HEIGHT_METRES
		if ( ts.min_alt != VIK_VAL_MIN_ALT )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d m"), (int)round(ts.min_alt) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

		if ( ts.max_alt != VIK_VAL_MAX_ALT )
			g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d m"), (int)round(ts.max_alt) );
		else
			g_snprintf ( tmp_buf, sizeof(tmp_buf), "--" );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d m / %d m"), (int)round(ts.elev_gain), (int)round(ts.elev_loss) );
		gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
		g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d m / %d m"), (int)round(ts.elev_gain/ts.count), (int)round(ts.elev_loss/ts.count) );
		break;
	}
	gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

	gint hours;
	gint minutes;
	gint days;
	// Total Duration
	days    = (gint)(ts.duration / (60*60*24));
	hours   = (gint)floor((ts.duration - (days*60*60*24)) / (60*60));
	minutes = (gint)((ts.duration - (days*60*60*24) - (hours*60*60)) / 60);
	g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d:%02d:%02d days:hrs:mins"), days, hours, minutes );
	gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );

	// Average Duration
	gint avg_dur = ts.duration / ts.count;
	hours   = (gint)floor(avg_dur / (60*60));
	minutes = (gint)((avg_dur - (hours*60*60)) / 60);
	g_snprintf ( tmp_buf, sizeof(tmp_buf), _("%d:%02d hrs:mins"), hours, minutes );
	gtk_label_set_text ( GTK_LABEL(content[cnt++]), tmp_buf );
}
Пример #19
0
void
cal_print_get_events (gchar *buffer, guint32 julian, GUI *appGUI)
{
	GtkTreePath *path;
	GtkTreeIter iter;
	GtkTreeModel *model;
	GSList *lnode;
	struct note *a;
	gint i;

	gchar *wbuf1, *wbuf2;
	gchar buf1[BUFFER_SIZE], buf2[BUFFER_SIZE];
	GDate *date, *sdate;
	gint age, syear;
	guint32 tsk_julian;
	gint time;
	gint max_event_length;
	GRegex *reg;

	buffer[0] = '\0';
	max_event_length = (config.cal_print_event_length + 2 > BUFFER_SIZE) ? BUFFER_SIZE : config.cal_print_event_length + 2;


#ifdef TASKS_ENABLED

	/* tasks */
	if (config.cal_print_tasks) {

		model = GTK_TREE_MODEL (appGUI->tsk->tasks_list_store);
		g_return_if_fail (model != NULL);

		path = gtk_tree_path_new_first ();

		while (gtk_tree_model_get_iter (model, &iter, path) == TRUE) {
			gtk_tree_model_get (model, &iter, TA_COLUMN_DUE_DATE_JULIAN, &tsk_julian, TA_COLUMN_CATEGORY, &wbuf1, -1);

			if (tsk_julian == julian && tasks_category_get_state (wbuf1, STATE_CALENDAR, appGUI) == TRUE) {
				gtk_tree_model_get (model, &iter, TA_COLUMN_DUE_TIME, &time, TA_COLUMN_SUMMARY, &wbuf2, -1);

				if (time >= 0) {
					g_snprintf (buf1, max_event_length, "\n[%02d:%02d] %s", time / 3600, time / 60 % 60, wbuf2);
				} else {
					g_snprintf (buf1, max_event_length, "\n%s", wbuf2);
				}

				g_strlcat (buffer, buf1, BUFFER_SIZE);
				g_free (wbuf2);
			}

			g_free (wbuf1);
			gtk_tree_path_next (path);
		}

		gtk_tree_path_free (path);

	}

#endif  /* TASKS_ENABLED */

#ifdef CONTACTS_ENABLED

	/* birthdays */
	if (config.cal_print_birthdays) {

		model = GTK_TREE_MODEL (appGUI->cnt->contacts_list_store);
		g_return_if_fail (model != NULL);

		date = g_date_new ();
		g_return_if_fail (date != NULL);

		sdate = g_date_new_julian (julian);
		g_return_if_fail (sdate != NULL);

		syear = g_date_get_year (sdate);
		path = gtk_tree_path_new_first ();

		while (gtk_tree_model_get_iter (model, &iter, path) == TRUE) {
			gtk_tree_model_get (model, &iter, COLUMN_BIRTH_DAY_DATE, &tsk_julian, -1);

			if (g_date_valid_julian (tsk_julian)) {
				g_date_set_julian (date, tsk_julian);
				age = syear - g_date_get_year (date);

				if (age >= 0) {

					if (g_date_valid_dmy (g_date_get_day (date), g_date_get_month (date), syear) == FALSE) {
						g_date_subtract_days (date, 1);
					}
					g_date_set_year (date, syear);

					if (g_date_compare (date, sdate) == 0) {

						gtk_tree_model_get (model, &iter, COLUMN_FIRST_NAME, &wbuf1, COLUMN_LAST_NAME, &wbuf2, -1);
						utl_name_strcat (wbuf1, wbuf2, buf2);

						g_snprintf (buf1, max_event_length, "\n%s (%d)", buf2, age);
						g_strlcat (buffer, buf1, BUFFER_SIZE);
					}
				}
			}
			gtk_tree_path_next (path);
		}

		gtk_tree_path_free (path);
		g_date_free (sdate);
		g_date_free (date);

	}

	/* name days */
	if (config.cal_print_namedays) {

		model = GTK_TREE_MODEL (appGUI->cnt->contacts_list_store);
		g_return_if_fail (model != NULL);

		date = NULL;
		date = g_date_new ();
		g_return_if_fail (date != NULL);

		sdate = NULL;
		sdate = g_date_new_julian (julian);
		g_return_if_fail (sdate != NULL);

		syear = g_date_get_year (sdate);
		path = gtk_tree_path_new_first ();

		while (gtk_tree_model_get_iter (model, &iter, path) == TRUE) {
			gtk_tree_model_get (model, &iter, COLUMN_NAME_DAY_DATE, &tsk_julian, -1);

			if (g_date_valid_julian (tsk_julian)) {
				g_date_set_julian (date, tsk_julian);

				if (g_date_valid_dmy (g_date_get_day (date), g_date_get_month (date), syear) == TRUE) {
					g_date_set_year (date, syear);

					if (g_date_compare (date, sdate) == 0) {

						gtk_tree_model_get (model, &iter, COLUMN_FIRST_NAME, &wbuf1, COLUMN_LAST_NAME, &wbuf2, -1);
						utl_name_strcat (wbuf1, wbuf2, buf1);

						g_snprintf (buf2, max_event_length, "\n%s (%s)", buf1, _("Name day"));
						g_strlcat (buffer, buf2, BUFFER_SIZE);
					}
				}
			}
			gtk_tree_path_next (path);
		}

		gtk_tree_path_free (path);
		g_date_free (sdate);
		g_date_free (date);

	}

#endif  /* CONTACTS_ENABLED */

	/* day note */
	if (config.cal_print_day_notes) {

		if (appGUI->cal->notes_list != NULL) {

			wbuf1 = NULL;
			reg = g_regex_new ("\n", 0, 0, NULL);

			for (i = 0, lnode = appGUI->cal->notes_list; lnode != NULL; lnode = lnode->next, i++) {
				a = g_slist_nth_data (appGUI->cal->notes_list, i);

				if (a->date == julian) {
					wbuf1 = g_regex_replace_literal (reg, a->note, -1, 0, " ", 0, NULL);
					break;
				}
			}

			g_regex_unref (reg);
		}

		if (wbuf1 != NULL) {
			g_strstrip (wbuf1);
			g_snprintf (buf1, max_event_length, "\n%s", wbuf1);
			g_strlcat (buffer, buf1, BUFFER_SIZE);
			g_free (wbuf1);
		}

	}

#ifdef HAVE_LIBICAL

	/* ical */
	if (config.cal_print_ical) {


	}

#endif  /* HAVE_LIBICAL */

	g_strstrip (buffer);

}
Пример #20
0
Файл: main.c Проект: rosedu/osmo
int main(int argc, char **argv) {

GUI *appGUI = NULL;
CALENDAR *cal = NULL;
TASKS *tsk = NULL;
CONTACTS *cnt = NULL;
NOTES *nte = NULL;
OPTIONS *opt = NULL;
GtkWidget *info_dialog;
gchar tmpbuf[BUFFER_SIZE];
gint response = -1;
struct flock *s_lock = NULL;
int fhandle;

GOptionContext *cmd_context;
gboolean cmd_calendar = FALSE;
gboolean cmd_check_events = FALSE;
gint cmd_check_ndays_events = 0;
gchar *cmd_cfg_path = NULL;
gboolean cmd_tiny_gui = FALSE;

GOptionEntry cmd_options[] = {
    { "calendar",   'c', 0, G_OPTION_ARG_NONE, &cmd_calendar, N_("Show small calendar window"), NULL  },
    { "check",      'e', 0, G_OPTION_ARG_NONE, &cmd_check_events, N_("Check for events since last run"), NULL  },
    { "days",       'd', 0, G_OPTION_ARG_INT, &cmd_check_ndays_events, N_("Number of days to check forward for events (default: 0)"), NULL  },
    { "config",     's', 0, G_OPTION_ARG_STRING, &cmd_cfg_path, N_("Set absolute path for settings and data files"), "PATH"  },
    { "tinygui",    't', 0, G_OPTION_ARG_NONE, &cmd_tiny_gui, N_("Modify GUI to use Osmo on low resolutions"), NULL  },
    { NULL }
};

    appGUI = g_new0 (GUI, 1);
    g_return_val_if_fail (appGUI != NULL, -1);

    cal = g_new0 (CALENDAR, 1);
    g_return_val_if_fail (cal != NULL, -1);
    tsk = g_new0 (TASKS, 1);
    g_return_val_if_fail (tsk != NULL, -1);
    cnt = g_new0 (CONTACTS, 1);
    g_return_val_if_fail (cnt != NULL, -1);
    nte = g_new0 (NOTES, 1);
    g_return_val_if_fail (nte != NULL, -1);

    opt = g_new0 (OPTIONS, 1);
    g_return_val_if_fail (opt != NULL, -1);

    /* register modules */
    appGUI->cal = cal;
    appGUI->tsk = tsk;
    appGUI->cnt = cnt;
    appGUI->nte = nte;
    appGUI->opt = opt;

    appGUI->run_date = utl_get_current_julian ();
    appGUI->run_time = get_seconds_for_today ();
    appGUI->key_counter = 0;

    /* default values */
    appGUI->hovering_over_link = FALSE;
    appGUI->hand_cursor = NULL;
    appGUI->regular_cursor = NULL;
    appGUI->gui_url_tag = NULL;
    appGUI->trayicon_popup_menu = NULL;

    appGUI->calendar_only = FALSE;
    appGUI->check_events = FALSE;
    appGUI->tiny_gui = FALSE;
    appGUI->save_status = 0;
    appGUI->print_font_size = 10;

	appGUI->cal->date = g_date_new ();
	g_return_val_if_fail (appGUI->cal->date != NULL, -1);
	g_date_set_time_t (appGUI->cal->date, time (NULL));

    appGUI->tsk->id_counter = 0;
    appGUI->tsk->tasks_panel_status = FALSE;
    appGUI->tsk->tasks_filter_disabled = FALSE;
    appGUI->tsk->tasks_list_store = NULL;
    appGUI->tsk->notifications = NULL;

    appGUI->cnt->photo_image = NULL;
    appGUI->cnt->contacts_uim_widget = NULL;
    appGUI->cnt->contacts_panel_status = FALSE;
    appGUI->cnt->contacts_filter_disabled = TRUE;
    appGUI->cnt->export_button = NULL;
    appGUI->cnt->output_file_entry = NULL;

    appGUI->opt->options_counter = 0;

    setlocale (LC_ALL, "");
    bindtextdomain (PACKAGE, LOCALEDIR);
    bind_textdomain_codeset (PACKAGE, "UTF-8");
    textdomain (PACKAGE);

    if (argc == 2 && (!strncmp(argv[1], "--help", 6) || (argv[1][0] == '-' && argv[1][1] == '?'))) {
        fprintf(stderr, "\nOSMO v%s - %s\n", VERSION, _("a handy personal organizer"));
        fprintf(stderr, "Copyright (c) 2007-2008 Tomasz Maka <*****@*****.**>\n\n");
    }

    cmd_context = g_option_context_new(NULL);
    g_option_context_add_main_entries(cmd_context, cmd_options, TRANSLATION_DOMAIN);
    g_option_context_parse(cmd_context, &argc, &argv, NULL);
    g_option_context_free(cmd_context);

    appGUI->calendar_only = cmd_calendar;
    appGUI->check_events = cmd_check_events;
    appGUI->check_ndays_events = cmd_check_ndays_events;
    appGUI->config_path = cmd_cfg_path;
    appGUI->tiny_gui = cmd_tiny_gui;

    if (prefs_get_config_filename (CONFIG_FILENAME, appGUI) == NULL) {
        fprintf(stderr, "%s\n", _("ERROR: Cannot create config files"));
        goto finish;
    }

    s_lock = g_new0 (struct flock, 1);
	s_lock->l_type = F_WRLCK;
	s_lock->l_whence = SEEK_SET;
	s_lock->l_start = 0;
	s_lock->l_len = 0;

    prefs_read_config (appGUI);

    close(creat(prefs_get_config_filename (RUN_FLAG_FILE, appGUI), S_IRUSR | S_IWUSR));     /* create lock file */

    gtk_init (&argc, &argv);

    fhandle = open(prefs_get_config_filename (RUN_FLAG_FILE, appGUI), O_RDWR);

    if (fhandle) {
		if (fcntl(fhandle, F_SETLK, s_lock) == -1) {
            close (fhandle);

            g_snprintf (tmpbuf, BUFFER_SIZE, "%s %s\n\n%s",
                        _("Another copy of OSMO is already running."),
                        _("Simultaneously use two or more copies of OSMO can be a cause of data loss."),
                        _("Do you really want to continue?"));

            info_dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW_TOPLEVEL, GTK_DIALOG_MODAL,
                                                  GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, tmpbuf);

            gtk_window_set_title(GTK_WINDOW(info_dialog), _("Warning"));
            gtk_window_set_position(GTK_WINDOW(info_dialog), GTK_WIN_POS_CENTER);
            gtk_widget_show (info_dialog);

            response = gtk_dialog_run(GTK_DIALOG(info_dialog));
            gtk_widget_destroy(info_dialog);

            if (response == GTK_RESPONSE_NO || response == GTK_RESPONSE_DELETE_EVENT) {
                goto finish;
            }
        }
    }

	notify_init("Osmo notification");

    if (appGUI->calendar_only != TRUE) {

        /* setup timer at 1000ms (1s) interval */
		g_timeout_add (1000, (GtkFunction) time_handler, appGUI);

    }

    config.run_counter++;

    if (gui_create_window (appGUI) == TRUE) {
        gtk_main ();
    }

    if (appGUI->calendar_only == FALSE) {
        config.lastrun_date = utl_get_current_julian ();
        config.lastrun_time = get_seconds_for_today();
    }

    if (appGUI->check_events == FALSE) {
        prefs_write_config (appGUI);
    }

    if (fhandle) {
    	s_lock->l_type = F_UNLCK;
    	fcntl(fhandle, F_SETLK, s_lock);
        close (fhandle);
    }

finish:
	g_date_free (appGUI->cal->date);
	g_free (opt);
	g_free (nte);
	g_free (cnt);
	g_free (tsk);
	g_free (cal);
	g_free (appGUI);
	g_free (s_lock);
	return 0;
}
Пример #21
0
void
display_calendar (guint year, GUI *appGUI)
{
static MESSAGE selected_date[MAX_MONTHS * FULL_YEAR_COLS];

GDate *cdate;
gint calendar_table[MAX_MONTHS * FULL_YEAR_COLS];
guint current_day, current_month, current_year;
guint month;
gint i, idx, day, first_day, days;
gchar tmpbuf[BUFFER_SIZE], tmpbuf2[BUFFER_SIZE];

	for (i = 0; i < MAX_MONTHS * FULL_YEAR_COLS; i++) {
		calendar_table[i] = -1;
	}

	cdate = g_date_new ();
	g_return_if_fail (cdate != NULL);

	for (month = G_DATE_JANUARY; month <= G_DATE_DECEMBER; month++) {
		g_date_set_dmy (cdate, 1, month, year);
		first_day = g_date_get_weekday (cdate);
		days = g_date_get_days_in_month (month, year);

		for (i = 1; i <= days; i++) {
			calendar_table[(month - 1) * FULL_YEAR_COLS + first_day + i - 2] = i;
		}
	}

	g_date_set_time_t (cdate, time (NULL));
	current_day = g_date_get_day (cdate);
	current_month = g_date_get_month (cdate);
	current_year = g_date_get_year (cdate);

	for (month = G_DATE_JANUARY; month <= G_DATE_DECEMBER; month++) {

		for (i = 0; i < FULL_YEAR_COLS; i++) {

			idx = (month - 1) * FULL_YEAR_COLS + i;
			g_signal_handlers_disconnect_by_func (G_OBJECT (appGUI->cal->calendar_buttons[idx]),
			                                      G_CALLBACK (select_date_day_cb), &selected_date[idx]);
			day = calendar_table[idx];

			if (day > 0) {

				if (day == current_day && month == current_month && year == current_year) {
					g_snprintf (tmpbuf2, BUFFER_SIZE, "<b><u>%2d</u></b>", day);
				} else {
					g_snprintf (tmpbuf2, BUFFER_SIZE, "%2d", day);
				}

				if (i % 7 + 1 == G_DATE_SATURDAY || i % 7 + 1 == G_DATE_SUNDAY) {
					g_snprintf (tmpbuf, BUFFER_SIZE, "<span foreground='firebrick'>%s</span>", tmpbuf2);
				} else if (month % 2 == 0) {
					g_snprintf (tmpbuf, BUFFER_SIZE, "<span foreground='medium blue'>%s</span>", tmpbuf2);
				} else {
					g_strlcpy (tmpbuf, tmpbuf2, BUFFER_SIZE);
				}

				g_date_set_dmy (cdate, (GDateDay) day, month,
				                (GDateYear) gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (appGUI->cal->fy_spinbutton)));
				selected_date[idx].data = (gpointer) g_date_get_julian (cdate);
				selected_date[idx].appGUI = appGUI;
				g_signal_connect (G_OBJECT (appGUI->cal->calendar_buttons[idx]), "clicked",
				                  G_CALLBACK (select_date_day_cb), &selected_date[idx]);
				gtk_button_set_label (GTK_BUTTON (appGUI->cal->calendar_buttons[idx]), "");
				gtk_label_set_markup (GTK_LABEL (GTK_BIN (appGUI->cal->calendar_buttons[idx])->child), tmpbuf);
				gtk_widget_show (appGUI->cal->calendar_buttons[idx]);

			} else {

				gtk_button_set_label (GTK_BUTTON (appGUI->cal->calendar_buttons[idx]), "");
				gtk_widget_hide (GTK_WIDGET (appGUI->cal->calendar_buttons[idx]));

			}
		}
	}

	g_date_free (cdate);
}
Пример #22
0
gboolean
e_reap_trash_directory_sync (GFile *trash_directory,
                             gint expiry_in_days,
                             GCancellable *cancellable,
                             GError **error)
{
	GFileEnumerator *file_enumerator;
	GQueue directories = G_QUEUE_INIT;
	GFile *reaping_directory;
	GFileInfo *file_info;
	const gchar *attributes;
	gboolean success = TRUE;
	GError *local_error = NULL;

	g_return_val_if_fail (G_IS_FILE (trash_directory), FALSE);
	g_return_val_if_fail (expiry_in_days > 0, FALSE);

	reaping_directory = g_file_get_child (
		trash_directory, REAPING_DIRECTORY_NAME);

	attributes =
		G_FILE_ATTRIBUTE_STANDARD_NAME ","
		G_FILE_ATTRIBUTE_STANDARD_TYPE ","
		G_FILE_ATTRIBUTE_TIME_MODIFIED;

	file_enumerator = g_file_enumerate_children (
		trash_directory, attributes,
		G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
		cancellable, error);

	if (file_enumerator == NULL)
		return FALSE;

	file_info = g_file_enumerator_next_file (
		file_enumerator, cancellable, &local_error);

	while (file_info != NULL) {
		GFileType file_type;
		GTimeVal mtime;
		GDate *date_now;
		GDate *date_mtime;
		const gchar *name;
		gboolean reap_it;
		gint days_old;

		name = g_file_info_get_name (file_info);
		file_type = g_file_info_get_file_type (file_info);
		g_file_info_get_modification_time (file_info, &mtime);

		/* Calculate how many days ago the file was modified. */
		date_now = g_date_new ();
		g_date_set_time_t (date_now, time (NULL));
		date_mtime = g_date_new ();
		g_date_set_time_val (date_mtime, &mtime);
		days_old = g_date_days_between (date_mtime, date_now);
		g_date_free (date_mtime);
		g_date_free (date_now);

		reap_it =
			(file_type == G_FILE_TYPE_DIRECTORY) &&
			(days_old >= expiry_in_days);

		if (reap_it) {
			GFile *child;

			child = g_file_get_child (trash_directory, name);

			/* If we find an unfinished reaping directory, put
			 * it on the head of the queue so we reap it first. */
			if (g_file_equal (child, reaping_directory))
				g_queue_push_head (&directories, child);
			else
				g_queue_push_tail (&directories, child);
		}

		g_object_unref (file_info);

		file_info = g_file_enumerator_next_file (
			file_enumerator, cancellable, &local_error);
	}

	if (local_error != NULL) {
		g_propagate_error (error, local_error);
		success = FALSE;
	}

	g_object_unref (file_enumerator);

	/* Now delete the directories we've queued up. */
	while (success && !g_queue_is_empty (&directories)) {
		GFile *directory;

		directory = g_queue_pop_head (&directories);

		/* First we rename the directory to prevent it
		 * from being recovered while being deleted. */
		if (!g_file_equal (directory, reaping_directory))
			success = g_file_move (
				directory, reaping_directory,
				G_FILE_COPY_NONE, cancellable,
				NULL, NULL, error);

		if (success)
			success = e_file_recursive_delete_sync (
				reaping_directory, cancellable, error);

		g_object_unref (directory);
	}

	/* Flush the queue in case we aborted on an error. */
	while (!g_queue_is_empty (&directories))
		g_object_unref (g_queue_pop_head (&directories));

	g_object_unref (reaping_directory);

	return success;
}
Пример #23
0
/*
 * gda_ldap_attr_value_to_g_value:
 * Converts a #BerValue to a new #GValue
 *
 * Returns: a new #GValue, or %NULL on error
 */
GValue *
gda_ldap_attr_value_to_g_value (LdapConnectionData *cdata, GType type, BerValue *bv)
{
	GValue *value = NULL;
	if ((type == G_TYPE_DATE_TIME) ||
	    (type == G_TYPE_DATE)) {
		/* see ftp://ftp.rfc-editor.org/in-notes/rfc4517.txt,
		 * section 3.3.13: Generalized Time
		 */
		GTimeVal tv;
		gboolean conv;
		if (! (conv = g_time_val_from_iso8601 (bv->bv_val,
						       &tv))) {
			/* Add the 'T' char */
			gchar *tmp, *str;
			gint i, len;
			str = bv->bv_val;
			len = strlen (str);
			if (len > 8) {
				tmp = g_new (gchar, len + 2);
				for (i = 0; i < 8; i++)
					tmp[i] = str[i];
				tmp [8] = 'T';
				for (i = 9; str[i]; i++)
					tmp[i] = str[i-1];
				tmp[i] = 0;
				conv = g_time_val_from_iso8601 (tmp, &tv);
				g_free (tmp);
			}
		}
		if (conv) {
			struct tm *ptm;
#ifdef HAVE_LOCALTIME_R
			struct tm tmpstm;
			ptm = localtime_r (&(tv.tv_sec), &tmpstm);
#elif HAVE_LOCALTIME_S
			struct tm tmpstm;
			if (localtime_s (&tmpstm, &(tv.tv_sec)) == 0)
				ptm = &tmpstm;
			else
				ptm = NULL;
#else
			ptm = localtime (&(tv.tv_sec));
#endif

			if (!ptm)
				return NULL;

			if (g_type_is_a (type, G_TYPE_DATE_TIME)) {
				GTimeZone *tz = g_time_zone_new ("Z"); // UTC
				GDateTime *ts = g_date_time_new (tz,
																				 ptm->tm_year + 1900,
																				 ptm->tm_mon + 1,
																				 ptm->tm_mday,
																				 ptm->tm_hour,
																				 ptm->tm_min,
																				 ptm->tm_sec);
				value = gda_value_new (G_TYPE_DATE_TIME);
				g_value_set_boxed (value, ts);
				g_date_time_unref (ts);
			}
			else {
				GDate *date;
				date = g_date_new ();
				g_date_set_time_val (date, &tv);
				value = gda_value_new (type);
				g_value_take_boxed (value, date);
			}
		}
	}
	else if (type == GDA_TYPE_BINARY) {
		guchar *data;
		data = g_new (guchar, bv->bv_len);
		memcpy (data, bv->bv_val, sizeof (guchar) * bv->bv_len);
		value = gda_value_new_binary (data, bv->bv_len);
	}
	else
		value = gda_value_new_from_string (bv->bv_val, type);

	return value;
}
static char *
format_last_used (guint64 timestamp)
{
	GTimeVal now_tv;
	GDate *now, *last;
	char *last_used = NULL;

	if (!timestamp)
		return g_strdup (_("never"));

	g_get_current_time (&now_tv);
	now = g_date_new ();
	g_date_set_time_val (now, &now_tv);

	last = g_date_new ();
	g_date_set_time_t (last, (time_t) timestamp);

	/* timestamp is now or in the future */
	if (now_tv.tv_sec <= timestamp) {
		last_used = g_strdup (_("now"));
		goto out;
	}

	if (g_date_compare (now, last) <= 0) {
		guint minutes, hours;

		/* Same day */

		minutes = (now_tv.tv_sec - timestamp) / 60;
		if (minutes == 0) {
			last_used = g_strdup (_("now"));
			goto out;
		}

		hours = (now_tv.tv_sec - timestamp) / 3600;
		if (hours == 0) {
			/* less than an hour ago */
			last_used = g_strdup_printf (ngettext ("%d minute ago", "%d minutes ago", minutes), minutes);
			goto out;
		}

		last_used = g_strdup_printf (ngettext ("%d hour ago", "%d hours ago", hours), hours);
	} else {
		guint days, months, years;

		days = g_date_get_julian (now) - g_date_get_julian (last);
		if (days == 0) {
			last_used = g_strdup ("today");
			goto out;
		}

		months = days / 30;
		if (months == 0) {
			last_used = g_strdup_printf (ngettext ("%d day ago", "%d days ago", days), days);
			goto out;
		}

		years = days / 365;
		if (years == 0) {
			last_used = g_strdup_printf (ngettext ("%d month ago", "%d months ago", months), months);
			goto out;
		}

		last_used = g_strdup_printf (ngettext ("%d year ago", "%d years ago", years), years);
	}

out:
	g_date_free (now);
	g_date_free (last);
	return last_used;
}
Пример #25
0
GDate *
gnc_accounting_period_end_gdate (GncAccountingPeriod which,
                                 const GDate *fy_end,
                                 const GDate *contains)
{
    GDate *date;

    if (contains)
    {
        date = g_date_new_dmy(g_date_get_day(contains),
                              g_date_get_month(contains),
                              g_date_get_year(contains));
    }
    else
    {
        date = g_date_new ();
        gnc_gdate_set_today (date);
    }

    switch (which)
    {
    default:
        g_message("Undefined relative time constant %d", which);
        g_date_free(date);
        return 0;

    case GNC_ACCOUNTING_PERIOD_TODAY:
        /* Already have today's date */
        break;

    case GNC_ACCOUNTING_PERIOD_MONTH:
        gnc_gdate_set_month_end(date);
        break;

    case GNC_ACCOUNTING_PERIOD_MONTH_PREV:
        gnc_gdate_set_prev_month_end(date);
        break;

    case GNC_ACCOUNTING_PERIOD_QUARTER:
        gnc_gdate_set_quarter_end(date);
        break;

    case GNC_ACCOUNTING_PERIOD_QUARTER_PREV:
        gnc_gdate_set_prev_quarter_end(date);
        break;

    case GNC_ACCOUNTING_PERIOD_CYEAR:
        gnc_gdate_set_year_end(date);
        break;

    case GNC_ACCOUNTING_PERIOD_CYEAR_PREV:
        gnc_gdate_set_prev_year_end(date);
        break;

    case GNC_ACCOUNTING_PERIOD_FYEAR:
        if (fy_end == NULL)
        {
            g_message("Request for fisal year value but no fiscal year end value provided.");
            g_date_free(date);
            return 0;
        }
        gnc_gdate_set_fiscal_year_end(date, fy_end);
        break;

    case GNC_ACCOUNTING_PERIOD_FYEAR_PREV:
        if (fy_end == NULL)
        {
            g_message("Request for fisal year value but no fiscal year end value provided.");
            g_date_free(date);
            return 0;
        }
        gnc_gdate_set_prev_fiscal_year_end(date, fy_end);
        break;
    }

    return date;
}
Пример #26
0
static void
gtk_dateentry_init (GtkDateEntry * dateentry)
{
GtkWidget *widget;
GtkWidget *arrow;

	DB( g_print(" (dateentry) init\n") );

	widget=GTK_WIDGET(dateentry);

	GTK_BOX(widget)->homogeneous = FALSE;

	dateentry->date = g_date_new();
	/* today's date */
	g_date_set_time_t(dateentry->date, time(NULL));

	g_date_set_dmy(&dateentry->mindate, 1, 1, 1900);
	g_date_set_dmy(&dateentry->maxdate, 31, 12, 2200);
	
	dateentry->entry = gtk_entry_new ();
	gtk_widget_set_size_request(dateentry->entry, 90, -1);
	gtk_box_pack_start (GTK_BOX (dateentry), dateentry->entry, TRUE, TRUE, 0);

	dateentry->arrow = gtk_toggle_button_new ();
	arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
	gtk_container_add (GTK_CONTAINER (dateentry->arrow), arrow);
	gtk_box_pack_end (GTK_BOX (dateentry), dateentry->arrow, FALSE, FALSE, 0);

	gtk_widget_show (dateentry->entry);
	gtk_widget_show (dateentry->arrow);

	g_signal_connect (GTK_OBJECT (dateentry->arrow), "toggled",
				G_CALLBACK (gtk_dateentry_arrow_press), dateentry);

	g_signal_connect (GTK_OBJECT (dateentry->entry), "activate",
				G_CALLBACK (gtk_dateentry_entry_new), dateentry);

	g_signal_connect (GTK_OBJECT (dateentry->entry), "focus-out-event",
				G_CALLBACK (gtk_dateentry_focus), dateentry);


	g_signal_connect (GTK_OBJECT (dateentry->entry), "key_press_event",
				G_CALLBACK (gtk_dateentry_entry_key), dateentry);

    /* our popup window */
	dateentry->popwin = gtk_window_new (GTK_WINDOW_POPUP);
	gtk_widget_set_events (dateentry->popwin,
				gtk_widget_get_events(dateentry->popwin) | GDK_KEY_PRESS_MASK);

	dateentry->frame = gtk_frame_new (NULL);
	gtk_container_add (GTK_CONTAINER (dateentry->popwin), dateentry->frame);
	gtk_frame_set_shadow_type (GTK_FRAME (dateentry->frame), GTK_SHADOW_OUT);
	gtk_widget_show (dateentry->frame);

	dateentry->calendar = gtk_calendar_new ();
	gtk_container_add (GTK_CONTAINER (dateentry->frame), dateentry->calendar);
	gtk_widget_show (dateentry->calendar);


	g_signal_connect (GTK_OBJECT (dateentry->popwin), "key_press_event",
				G_CALLBACK (key_press_popup), dateentry);


	g_signal_connect (GTK_OBJECT (dateentry->popwin), "button_press_event",
				G_CALLBACK (gtk_dateentry_button_press), dateentry);

	g_signal_connect (GTK_OBJECT (dateentry->calendar), "prev-year",
				G_CALLBACK (gtk_dateentry_calendar_year), dateentry);
	g_signal_connect (GTK_OBJECT (dateentry->calendar), "next-year",
				G_CALLBACK (gtk_dateentry_calendar_year), dateentry);
	g_signal_connect (GTK_OBJECT (dateentry->calendar), "prev-month",
				G_CALLBACK (gtk_dateentry_calendar_year), dateentry);
	g_signal_connect (GTK_OBJECT (dateentry->calendar), "next-month",
				G_CALLBACK (gtk_dateentry_calendar_year), dateentry);


	
	g_signal_connect (GTK_OBJECT (dateentry->calendar), "day-selected",
				G_CALLBACK (gtk_dateentry_calendar_getfrom), dateentry);

	g_signal_connect (GTK_OBJECT (dateentry->calendar), "day-selected-double-click",
				G_CALLBACK (gtk_dateentry_calendar_select), dateentry);

	gtk_dateentry_calendar_getfrom(NULL, dateentry);
}
Пример #27
0
static GtkWidget*
create_window1 (void)
{
	GtkWidget *window, *button1; 
	GtkImage *imageClient, *imageWellth, *imageBG;	
	GError** error = NULL;
	GTimeVal  time;
	GDate    *date_heap;
	
	GDate     date_stack;
	gchar     tmp_buffer[256];

	g_get_current_time( &time );
	date_heap = g_date_new();

	GDate* mod_date = g_date_new ();
	
	g_date_set_time_val( date_heap, &time );
	g_date_strftime( tmp_buffer, 256, "%x", date_heap );
	g_print( "Current date (heap):  %s\n", tmp_buffer );

	//g_date_set_year (mod_date, atoi (parts[2]));
	
	g_date_free( date_heap );
	
	/* Load UI from file */
	MainBuilder = gtk_builder_new ();
	if (!gtk_builder_add_from_file (MainBuilder, UI_FILE, error))
	{
		g_critical ("Couldn't load builder file: %s", (*error)->message);
		g_error_free (*error);
	}

	/* Auto-connect signal handlers */
	gtk_builder_connect_signals (MainBuilder, NULL);

	/* Get the window object from the ui file */
	window = GTK_WIDGET (gtk_builder_get_object (MainBuilder, TOP_WINDOW));
        if (!window)
        {
                g_critical ("Widget \"%s\" is missing in file %s.",
				TOP_WINDOW,
				UI_FILE);
        }

	//GdkPixbufAnimation * pixbufclntanm = gdk_pixbuf_animation_new_from_file(CLIENT_LOGO, error);
	GdkPixbufAnimation * pixbufwlthanm = gdk_pixbuf_animation_new_from_file(WELLTH_LOGO, error);
	//imageClient = (GtkImage *) GTK_WIDGET (gtk_builder_get_object (MainBuilder, "clnt_logo"));
	imageWellth = (GtkImage *) GTK_WIDGET (gtk_builder_get_object (MainBuilder, "wellth_logo"));
	//gtk_image_set_from_animation(GTK_IMAGE(imageClient), pixbufclntanm);
	gtk_image_set_from_animation (GTK_IMAGE(imageWellth), pixbufwlthanm);

	//GdkPixbufAnimation * pixbufBGanm = gdk_pixbuf_animation_new_from_file(BG1, error);
	imageBG = (GtkImage *) GTK_WIDGET (gtk_builder_get_object (MainBuilder, "image1"));
	gtk_image_set_from_animation(GTK_IMAGE(imageBG), pixbufBGanm);
#ifdef DISPLAY_ADD
	GdkPixbufAnimation * pixbufaddanm = gdk_pixbuf_animation_new_from_file(ADDS2, error);
	GtkImage *add = (GtkImage *) GTK_WIDGET (gtk_builder_get_object (MainBuilder, "adds"));
	gtk_image_set_from_animation(GTK_IMAGE(add), pixbufaddanm);
#endif
	button1 = GTK_WIDGET (gtk_builder_get_object (MainBuilder, "main_start_btn"));
 	 g_signal_connect (G_OBJECT (button1), "clicked", G_CALLBACK (start_button_clicked), NULL);

		
	
	priv = g_malloc (sizeof (struct _Private));
	/* ANJUTA: Widgets initialization for WindowMain.ui - DO NOT REMOVE */

	//g_object_unref (MainBuilder);
	
	return window;
}
Пример #28
0
static void hb_export_qif_elt_txn(GIOChannel *io, Account *acc)
{
GString *elt;
GList *list;
GDate *date;
char amountbuf[G_ASCII_DTOSTR_BUF_SIZE];
gchar *sbuf;
gint count, i;

	elt = g_string_sized_new(255);

	date = g_date_new ();
	
	list = g_queue_peek_head_link(acc->txn_queue);
	while (list != NULL)
	{
	Transaction *txn = list->data;
	Payee *payee;
	Category *cat;
	gchar *txt;

		g_date_set_julian (date, txn->date);
		//#1270876
		switch(PREFS->dtex_datefmt)
		{
			case 0: //"m-d-y"  
				g_string_append_printf (elt, "D%02d/%02d/%04d\n", 
					g_date_get_month(date),
					g_date_get_day(date),
					g_date_get_year(date)
					);
				break;
			case 1: //"d-m-y"
				g_string_append_printf (elt, "D%02d/%02d/%04d\n", 
					g_date_get_day(date),
					g_date_get_month(date),
					g_date_get_year(date)
					);
				break;
			case 2: //"y-m-d"
				g_string_append_printf (elt, "D%04d/%02d/%02d\n", 
					g_date_get_year(date),
					g_date_get_month(date),
					g_date_get_day(date)
					);
				break;
		}			

		//g_ascii_dtostr (amountbuf, sizeof (amountbuf), txn->amount);
		g_ascii_formatd (amountbuf, sizeof (amountbuf), "%.2f", txn->amount);
		g_string_append_printf (elt, "T%s\n", amountbuf);

		sbuf = "";
		if(txn->status == TXN_STATUS_CLEARED)
			sbuf = "c";
		else
		if(txn->status == TXN_STATUS_RECONCILED)
			sbuf = "R";

		g_string_append_printf (elt, "C%s\n", sbuf);

		if( txn->paymode == PAYMODE_CHECK)
			g_string_append_printf (elt, "N%s\n", txn->info);

		//Ppayee
		payee = da_pay_get(txn->kpay);
		if(payee)
			g_string_append_printf (elt, "P%s\n", payee->name);

		// Mmemo
		g_string_append_printf (elt, "M%s\n", txn->memo);

		// LCategory of transaction
		// L[Transfer account name]
		// LCategory of transaction/Class of transaction
		// L[Transfer account]/Class of transaction
		if( txn->paymode == PAYMODE_INTXFER && txn->kacc == acc->key)
		{
		//#579260
			Account *dstacc = da_acc_get(txn->kxferacc);
			if(dstacc)
				g_string_append_printf (elt, "L[%s]\n", dstacc->name);
		}
		else
		{
			cat = da_cat_get(txn->kcat);
			if(cat)
			{
				txt = da_cat_get_fullname(cat);
				g_string_append_printf (elt, "L%s\n", txt);
				g_free(txt);
			}
		}

		// splits
		count = da_splits_count(txn->splits);
		for(i=0;i<count;i++)
		{
		Split *s = txn->splits[i];
				
			cat = da_cat_get(s->kcat);
			if(cat)
			{
				txt = da_cat_get_fullname(cat);
				g_string_append_printf (elt, "S%s\n", txt);
				g_free(txt);
			}	
				
			g_string_append_printf (elt, "E%s\n", s->memo);
			
			g_ascii_formatd (amountbuf, sizeof (amountbuf), "%.2f", s->amount);
			g_string_append_printf (elt, "$%s\n", amountbuf);
		}
		
		g_string_append (elt, "^\n");


		list = g_list_next(list);
	}

	g_io_channel_write_chars(io, elt->str, -1, NULL, NULL);
	
	g_string_free(elt, TRUE);

	g_date_free(date);
	
}