示例#1
0
文件: main.c 项目: RCcola310/mutter
/**
 * meta_print_self_identity:
 *
 * Prints the version number, the current timestamp (not the
 * build date), the locale, the character encoding, and a list
 * of configure script options that were used to build this
 * copy of Mutter. This is actually always called
 * on startup, but it's all no-op unless we're in verbose mode
 * (see meta_set_verbose()).
 */
static void
meta_print_self_identity (void)
{
  char buf[256];
  GDate d;
  const char *charset;

  /* Version and current date. */
  g_date_clear (&d, 1);
  g_date_set_time_t (&d, time (NULL));
  g_date_strftime (buf, sizeof (buf), "%x", &d);
  meta_verbose ("Mutter version %s running on %s\n",
    VERSION, buf);
  
  /* Locale and encoding. */
  g_get_charset (&charset);
  meta_verbose ("Running in locale \"%s\" with encoding \"%s\"\n",
    setlocale (LC_ALL, NULL), charset);

  /* Compilation settings. */
  meta_print_compilation_info ();
}
示例#2
0
文件: main.c 项目: mate-desktop/marco
/**
 * Prints the version notice. This is shown when Marco is called
 * with the --version switch.
 */
static void
version (void)
{
  const int latest_year = 2009;
  char yearbuffer[256];
  GDate date;

  /* this is all so the string to translate stays constant.
   * see how much we love the translators.
   */
  g_date_set_dmy (&date, 1, G_DATE_JANUARY, latest_year);
  if (g_date_strftime (yearbuffer, sizeof (yearbuffer), "%Y", &date)==0)
    /* didn't work?  fall back to decimal representation */
    g_sprintf (yearbuffer, "%d", latest_year);

  g_print (_("marco %s\n"
             "Copyright (C) 2001-%s Havoc Pennington, Red Hat, Inc., and others\n"
             "This is free software; see the source for copying conditions.\n"
             "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
           VERSION, yearbuffer);
  exit (0);
}
示例#3
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;
}
示例#4
0
guint
month_name_to_number (gchar *month_str) {

GDate *cdate;
gint i;
gboolean found;
char tmpbuf[BUFFER_SIZE];

    found = FALSE;
    cdate = g_date_new_dmy (1, 1, 1);
	g_return_val_if_fail (cdate != NULL, -1);

	for (i = G_DATE_JANUARY; i <= G_DATE_DECEMBER; i++) {
		g_date_set_month (cdate, i);
		g_date_strftime (tmpbuf, BUFFER_SIZE, "%B", cdate);
		if (!strcmp (month_str, tmpbuf)) {
			found = TRUE;
			break;
		}
	}
	g_date_free (cdate);
	return (found == TRUE ? i : -1);
}
示例#5
0
static void
accum_time_attribute (GString *buffer,
                      EContact *contact,
                      const gchar *html_label,
                      EContactField field,
                      const gchar *icon,
                      guint html_flags)
{
	EContactDate *date;
	GDate *gdate = NULL;
	gchar sdate[100];

	date = e_contact_get (contact, field);
	if (date) {
		gdate = g_date_new_dmy (
			date->day,
			date->month,
			date->year);
		g_date_strftime (sdate, 100, "%x", gdate);
		g_date_free (gdate);
		render_table_row (buffer, html_label, sdate, icon, html_flags);
		e_contact_date_free (date);
	}
}
示例#6
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;
}
示例#7
0
gchar *etats_titre ( gint report_number)
{
    gchar *titre;
    GDate *today_date;

    titre = gsb_data_report_get_report_name (report_number);
    today_date = gdate_today ();

    if ( gsb_data_report_get_use_financial_year (report_number))
    {
	GSList *tmp_list;
	gint fyear_number;
	gint last_fyear_number;

	switch (gsb_data_report_get_financial_year_type (report_number))
	{
	    case 0:
		/* all the financial years */

		titre = g_strconcat ( titre,
				      ", ", _("all financial years"),
				      NULL );
		break;

	    case 1:
		/* current financial year */
		fyear_number = gsb_data_fyear_get_from_date (today_date);

		if (fyear_number)
		    titre = g_strconcat ( titre,
					  ", ", _("current financial year") , " (",
					  gsb_data_fyear_get_name (fyear_number),
					  ")",
					  NULL );
		else
		    titre = g_strconcat ( titre,
					  ", ", _("current financial year"),
					  NULL );
		break;

	    case 2:
		/* last financial year */

		fyear_number = gsb_data_fyear_get_from_date (today_date);
		last_fyear_number = 0;

		tmp_list = gsb_data_fyear_get_fyears_list ();
		while (tmp_list)
		{
		    gint tmp_fyear_number;

		    tmp_fyear_number = gsb_data_fyear_get_no_fyear (tmp_list -> data);

		    if (gsb_data_fyear_compare (fyear_number, tmp_fyear_number) == 1)
		    {
			if (last_fyear_number)
			{
			    if (gsb_data_fyear_compare (last_fyear_number, tmp_fyear_number) == -1)
				last_fyear_number = tmp_fyear_number;
			}
			else
			{
			    last_fyear_number = tmp_fyear_number;
			}
		    }
		    tmp_list = tmp_list -> next;
		}

		/* here, last_fyear_number is on the last financial year */

		if (last_fyear_number)
		    titre = g_strconcat ( titre,
					  ", ", _("former financial year") , " (",
					  gsb_data_fyear_get_name (last_fyear_number),
					  ")",
					  NULL );
		else
		    titre = g_strconcat ( titre,
					  ", ", _("former financial year"),
					  NULL );
		break;

	    case 3:
		/* personal selection of financial years */

		tmp_list = gsb_data_report_get_financial_year_list (report_number);

		if ( g_slist_length ( tmp_list ) > 1 )
		    titre = g_strconcat ( titre,
					  ", ", _("financial years"), " ",
					  NULL );
		else
		    titre = g_strconcat ( titre,
					  ", ", _("financial year"), " ",
					  NULL );

		while ( tmp_list )
		{
		    gint fyear_number;

		    fyear_number = GPOINTER_TO_INT (tmp_list -> data);

		    if ( tmp_list == g_slist_last (gsb_data_report_get_financial_year_list (report_number)))
			titre = g_strconcat ( titre,
					      gsb_data_fyear_get_name (fyear_number),
					      NULL );
		    else
			titre = g_strconcat ( titre,
					      gsb_data_fyear_get_name (fyear_number),
					      ", ",
					      NULL );
		    tmp_list = tmp_list -> next;
		}
		break;
	}
    }
    else
    {
	/* c'est une plage de dates qui a été entrée */

	gchar buffer_date[15];
	gchar buffer_date_2[15];
	GDate *date_tmp;

	switch ( gsb_data_report_get_date_type (report_number))
	{
	    case 0:
		/* toutes */

		titre = g_strconcat ( titre,
				      ", ",
				      _("all dates"),
				      NULL );
		break;

	    case 1:
		/* plage perso */

		if ( gsb_data_report_get_personal_date_start (report_number)
		     &&
		     gsb_data_report_get_personal_date_end (report_number))
		    titre = g_strconcat ( titre,
					  ", ",
					  g_strdup_printf ( _("Result from %s to %s"),
							    gsb_format_gdate ( gsb_data_report_get_personal_date_start (report_number)),
							    gsb_format_gdate ( gsb_data_report_get_personal_date_end (report_number)) ),
					  NULL );
		else
		    titre = g_strconcat ( titre,
					  ", ", _("Custom dates ranges not filled"),
					  NULL );
		break;

	    case 2:
		/* cumul à ce jour */

		titre = g_strconcat ( titre,
				      ", ",
				      g_strdup_printf ( _("total at %s"),
							gsb_format_gdate (today_date)),
				      NULL );
		break;

	    case 3:
		/* mois en cours */

		g_date_strftime ( buffer_date,
				  14,
				  "%B",
				  today_date );

		titre = g_strconcat ( titre,
				      ", ",
				      g_strdup_printf ( _("%s %d"),
							buffer_date,
							g_date_get_year (today_date)),
				      NULL );
		break;

	    case 4:
		/* année en cours */

		titre = g_strconcat ( titre,
				      ", ", g_strdup_printf ( _("year %d"),
							      g_date_get_year (today_date)),
				      NULL );
		break;

	    case 5:
		/* cumul mensuel */

		titre = g_strconcat ( titre,
				      ", ",
				      g_strdup_printf ( _("month total at %s"),
							gsb_format_gdate (today_date)),
				      NULL );
		break;

	    case 6:
		/* cumul annuel */

		titre = g_strconcat ( titre,
				      ", ",
				      g_strdup_printf ( _("year total at %s"),
							gsb_format_gdate (today_date)),
				      NULL );
		break;

	    case 7:
		/* mois précédent */

		g_date_subtract_months ( today_date,
					 1 );
		g_date_strftime ( buffer_date,
				  14,
				  "%B",
				  today_date );

		titre = g_strconcat ( titre,
				      ", ",
				      g_strdup_printf ( _("%s %d"),
							buffer_date,
							g_date_get_year (today_date)),
				      NULL );
		break;

	    case 8:
		/* année précédente */

		titre = g_strconcat ( titre,
				      ", ", g_strdup_printf ( _("year %d"),
							      g_date_get_year (today_date) - 1),
				      NULL );
		break;

	    case 9:
		/* 30 derniers jours */

		date_tmp = gdate_today ( );

		g_date_subtract_days ( date_tmp,
				       30 );

		titre = g_strconcat ( titre,
				      ", ",
				      g_strdup_printf ( _("Result from %s to %s"),
							gsb_format_gdate ( date_tmp ),
							gsb_format_gdate (today_date)),
				      NULL );
		break;

	    case 10:
		/* 3 derniers mois */

		date_tmp = gdate_today ( );
		g_date_subtract_months ( date_tmp,
					 3 );
		g_date_strftime ( buffer_date_2,
				  14,
				  "%B",
				  date_tmp );
		g_date_strftime ( buffer_date,
				  14,
				  "%B",
				  today_date);

		titre = g_strconcat ( titre,
				      ", ",
				      g_strdup_printf ( _("from %s %d"),
							buffer_date_2,
							g_date_get_year ( date_tmp )),
				      " ",
				      g_strdup_printf ( _("to %s %d"),
							buffer_date,
							g_date_get_year (today_date)),
				      NULL );
		break;

	    case 11:
		/* 6 derniers mois */

		date_tmp = gdate_today ( );
		g_date_subtract_months ( date_tmp,
					 6 );
		g_date_strftime ( buffer_date_2,
				  14,
				  "%B",
				  date_tmp );
		g_date_strftime ( buffer_date,
				  14,
				  "%B",
				  today_date);


		titre = g_strconcat ( titre,
				      ", ",
				      g_strdup_printf ( _("from %s %d"),
							buffer_date_2,
							g_date_get_year ( date_tmp )),
				      " ",
				      g_strdup_printf ( _("to %s %d"),
							buffer_date,
							g_date_get_year (today_date)),
				      NULL );
		break;

	    case 12:
		/* 12 derniers mois */

		date_tmp = gdate_today ( );
		g_date_subtract_months ( date_tmp,
					 12 );
		g_date_strftime ( buffer_date_2,
				  14,
				  "%B",
				  date_tmp );
		g_date_strftime ( buffer_date,
				  14,
				  "%B",
				  today_date);

		titre = g_strconcat ( titre,
				      ", ",
				      g_strdup_printf ( _("from %s %d"),
							buffer_date_2,
							g_date_get_year ( date_tmp )),
				      " ",
				      g_strdup_printf ( _("to %s %d"),
							buffer_date,
							g_date_get_year (today_date)),
				      NULL );
		break;
	}
    }

    return titre;
}
示例#8
0
void
gnc_frequency_setup(GncFrequency *gf, GList *recurrences, const GDate *start_date)
{
    gboolean made_changes = FALSE;

    // setup start-date, if present
    if (start_date != NULL
            && g_date_valid(start_date))
    {
        gnc_date_edit_set_gdate(gf->startDate, start_date);
        made_changes = TRUE;
    }

    if (recurrences == NULL)
    {
        goto maybe_signal;
        // return...
    }

    if (g_list_length(recurrences) > 1)
    {
        if (recurrenceListIsWeeklyMultiple(recurrences))
        {
            for (; recurrences != NULL; recurrences = recurrences->next)
            {
                _setup_weekly_recurrence(gf, (Recurrence*)recurrences->data);
            }

            gtk_notebook_set_current_page(gf->nb, PAGE_WEEKLY);
            gtk_combo_box_set_active(gf->freqComboBox, PAGE_WEEKLY);
        }
        else if (recurrenceListIsSemiMonthly(recurrences))
        {
            Recurrence *first, *second;
            GtkWidget *multiplier_spin;
            GtkWidget *dom_combobox;

            first = (Recurrence*)g_list_nth_data(recurrences, 0);
            second = (Recurrence*)g_list_nth_data(recurrences, 1);

            multiplier_spin = glade_xml_get_widget(gf->gxml, "semimonthly_spin");
            gtk_spin_button_set_value(GTK_SPIN_BUTTON(multiplier_spin), recurrenceGetMultiplier(first));

            dom_combobox = glade_xml_get_widget(gf->gxml, "semimonthly_first");
            gtk_combo_box_set_active(GTK_COMBO_BOX(dom_combobox), _get_monthly_combobox_index(first));
            dom_combobox = glade_xml_get_widget(gf->gxml, "semimonthly_first_weekend");
            gtk_combo_box_set_active(GTK_COMBO_BOX(dom_combobox), recurrenceGetWeekendAdjust(first));
            dom_combobox = glade_xml_get_widget(gf->gxml, "semimonthly_second");
            gtk_combo_box_set_active(GTK_COMBO_BOX(dom_combobox), _get_monthly_combobox_index(second));
            dom_combobox = glade_xml_get_widget(gf->gxml, "semimonthly_second_weekend");
            gtk_combo_box_set_active(GTK_COMBO_BOX(dom_combobox), recurrenceGetWeekendAdjust(second));

            gtk_notebook_set_current_page(gf->nb, PAGE_SEMI_MONTHLY);
            gtk_combo_box_set_active(gf->freqComboBox, PAGE_SEMI_MONTHLY);
        }
        else
        {
            g_error("unknown composite recurrence with [%d] entries", g_list_length(recurrences));
        }
    }
    else
    {
        Recurrence *r = (Recurrence*)recurrences->data;
        g_debug("recurrence period [%d]", recurrenceGetPeriodType(r));
        switch (recurrenceGetPeriodType(r))
        {
        case PERIOD_ONCE:
        {
            GDate recurrence_date = recurrenceGetDate(r);
            if (g_date_compare(start_date, &recurrence_date) != 0)
            {
                char start_date_str[128], recur_date_str[128];
                g_date_strftime(start_date_str, 127, "%x", start_date);
                g_date_strftime(recur_date_str, 127, "%x", &recurrence_date);
                g_critical("start_date [%s] != recurrence_date [%s]", start_date_str, recur_date_str);
            }

            gtk_notebook_set_current_page(gf->nb, PAGE_ONCE);
            gtk_combo_box_set_active(gf->freqComboBox, PAGE_ONCE);
        }
        break;
        case PERIOD_DAY:
        {
            guint multiplier;
            GtkWidget *spin_button;

            multiplier = recurrenceGetMultiplier(r);
            spin_button = glade_xml_get_widget(gf->gxml, "daily_spin");
            gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button), multiplier);
            made_changes = TRUE;

            gtk_notebook_set_current_page(gf->nb, PAGE_DAILY);
            gtk_combo_box_set_active(gf->freqComboBox, PAGE_DAILY);
        }
        break;
        case PERIOD_WEEK:
        {
            _setup_weekly_recurrence(gf, r);
            gtk_notebook_set_current_page(gf->nb, PAGE_WEEKLY);
            gtk_combo_box_set_active(gf->freqComboBox, PAGE_WEEKLY);
        }
        break;
        case PERIOD_END_OF_MONTH:
        case PERIOD_MONTH:
        case PERIOD_YEAR:
        case PERIOD_LAST_WEEKDAY:
        case PERIOD_NTH_WEEKDAY:
        {
            guint multiplier;
            GtkWidget *multipler_spin, *day_of_month, *weekend_mode;

            multipler_spin = glade_xml_get_widget(gf->gxml, "monthly_spin");
            multiplier = recurrenceGetMultiplier(r);
            if (recurrenceGetPeriodType(r) == PERIOD_YEAR)
                multiplier *= 12;
            gtk_spin_button_set_value(GTK_SPIN_BUTTON(multipler_spin), multiplier);

            day_of_month = glade_xml_get_widget(gf->gxml, "monthly_day");
            gtk_combo_box_set_active(GTK_COMBO_BOX(day_of_month), _get_monthly_combobox_index(r));
            weekend_mode = glade_xml_get_widget(gf->gxml, "monthly_weekend");
            gtk_combo_box_set_active(GTK_COMBO_BOX(weekend_mode), recurrenceGetWeekendAdjust(r));

            gtk_notebook_set_current_page(gf->nb, PAGE_MONTHLY);
            gtk_combo_box_set_active(gf->freqComboBox, PAGE_MONTHLY);
        }
        break;
        default:
            g_error("unknown recurrence period type [%d]", recurrenceGetPeriodType(r));
            break;
        }
    }

maybe_signal:
    if (made_changes)
        g_signal_emit_by_name(gf, "changed");
}
示例#9
0
static void
zenity_forms_dialog_output (ZenityFormsData *forms_data)
{
  GSList *tmp, *tmp2;
  guint day, year, month;
  GDate *date = NULL;
  gchar time_string[128];
  gchar *combo_value = NULL;
  GtkTreeSelection *selection;
  GtkListStore *list_store;
  GtkTreeIter iter;

  for (tmp = forms_data->list; tmp; tmp = tmp->next) {
    ZenityFormsValue *zenity_value = (ZenityFormsValue *) tmp->data;
    switch (zenity_value->type) {
      case ZENITY_FORMS_PASSWORD:
      case ZENITY_FORMS_ENTRY:
        g_print("%s", gtk_entry_get_text (GTK_ENTRY (zenity_value->forms_widget)));
        break;
      case ZENITY_FORMS_LIST:
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_bin_get_child (GTK_BIN (zenity_value->forms_widget))));
        gtk_tree_selection_selected_foreach (selection,
                                            (GtkTreeSelectionForeachFunc) zenity_forms_dialog_get_selected,
                                            GTK_TREE_VIEW (gtk_bin_get_child (GTK_BIN (zenity_value->forms_widget))));

        for (tmp2 = selected; tmp2; tmp2 = tmp2->next) {
          if (tmp->next != NULL) {
            g_print ("%s,", (gchar *) tmp2->data);
          }
          else
            g_print ("%s", (gchar *) tmp2->data);
        }

        g_slist_foreach (selected, (GFunc) g_free, NULL);
        selected = NULL;

        break;
      case ZENITY_FORMS_CALENDAR:
        gtk_calendar_get_date (GTK_CALENDAR (zenity_value->forms_widget), &day, &month, &year);
        date = g_date_new_dmy (year, month + 1, day);
        g_date_strftime (time_string, 127, forms_data->date_format, date);
        g_print ("%s", time_string);
        break;
      case ZENITY_FORMS_COMBO:
        if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (zenity_value->forms_widget), &iter)) {
          list_store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (zenity_value->forms_widget)));
          gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter, 0, &combo_value, -1);
          g_object_unref (G_OBJECT (list_store));
 
          g_print ("%s", combo_value);
          g_free (combo_value);
        } else
          g_print (" ");
         break;
        
    }
    if (tmp->next != NULL)
      g_print("%s", forms_data->separator);
  }
  g_print("\n");
}
示例#10
0
//! \brief try to fix some common errors in the csv representation of invoices
//! * corrects the date format
//! * corrects ambigous values in multi line invoices
//! * ensures customer exists
//! * if quantity is unset, set to 1
//! * if price is unset, delete row
void
gnc_bi_import_fix_bis (GtkListStore * store, guint * fixed, guint * deleted,
                       GString * info, gchar *type)
{
    GtkTreeIter iter;
    gboolean valid, row_deleted, row_fixed;
    gchar *id, *date_opened, *date_posted, *due_date, *owner_id, *date, *quantity, *price;
    GString *prev_id, *prev_date_opened, *prev_date_posted, *prev_owner_id, *prev_date;	// needed to fix multi line invoices
    guint dummy;
    gint row = 1;
    const gchar* date_format_string = qof_date_format_get_string (qof_date_format_get()); // Get the user set date format string
    
    
    //date_format_string = qof_date_format_get_string (qof_date_format_get());	

    DEBUG("date_format_string: %s",date_format_string);
    // allow the call to this function with only GtkListeStore* specified
    if (!fixed)
        fixed = &dummy;
    if (!deleted)
        deleted = &dummy;

    *fixed = 0;
    *deleted = 0;

    // init strings
    prev_id = g_string_new ("");
    prev_date_opened = g_string_new ("");
    prev_date_posted = g_string_new ("");
    prev_owner_id = g_string_new ("");
    prev_date = g_string_new ("");

    valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
    while (valid)
    {
        row_deleted = FALSE;
        row_fixed = FALSE;

        // Walk through the list, reading each row
        gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
                            ID, &id,
                            DATE_OPENED, &date_opened,
                            DATE_POSTED, &date_posted,
                            DUE_DATE, &due_date,
                            OWNER_ID, &owner_id,
                            DATE, &date,
                            QUANTITY, &quantity, PRICE, &price, -1);

        if (strlen (price) == 0)
        {
            // invalid row (no price given)
            // no fix possible -> delete row
            valid = gtk_list_store_remove (store, &iter);
            row_deleted = TRUE;
            g_string_append_printf (info,
                                    _("ROW %d DELETED, PRICE_NOT_SET: id=%s\n"),
                                    row, id);
        }
        // TODO: QTY get set to 1 later if field is empty.  Delete this section?
        else if (strlen (quantity) == 0)
        {
            // invalid row (no quantity given)
            // no fix possible -> delete row
            valid = gtk_list_store_remove (store, &iter);
            row_deleted = TRUE;
            g_string_append_printf (info, _("ROW %d DELETED, QTY_NOT_SET: id=%s\n"),
                                    row, id);
        }
        else
        {   // TODO: If id is empty get the next one in the series.  Bug 731105 
            if (strlen (id) == 0)
            {
                // no invoice id specified
                if (prev_id->len == 0)
                {
                    // cannot fix -> delete row
                    valid = gtk_list_store_remove (store, &iter);
                    row_deleted = TRUE;
                    g_string_append_printf (info,
                                            _("ROW %d DELETED, ID_NOT_SET\n"), row);
                }
                else
                {
                    // this is a fixable multi line invoice
                    gtk_list_store_set (store, &iter, ID, prev_id->str, -1);
                    row_fixed = TRUE;
                }
            }
            else
            {
                // remember invoice id (to be able to fix multi line invoices)
                g_string_assign (prev_id, id);
                // new invoice => reset all other fixable entries
                g_string_assign (prev_date_opened, "");
                g_string_assign (prev_date_posted, "");
                g_string_assign (prev_owner_id, "");
                g_string_assign (prev_date, "");
            }
        }

        if (!row_deleted)
        {
            // the row is valid (price and id are valid)

            if(!isDateValid(date_opened))
            {
                if (prev_date_opened->len == 0)
                {
                    // fix this by using the current date
                    gchar temp[20];
                    GDate date;
                    g_date_clear (&date, 1);
                    gnc_gdate_set_today (&date);
                    g_date_strftime (temp, 20, date_format_string, &date);	// Create a user specified date string.
                    g_string_assign (prev_date_opened, temp);
                }
                // fix this by using the previous date_opened value (multi line invoice)
                gtk_list_store_set (store, &iter, DATE_OPENED,
                                    prev_date_opened->str, -1);
                row_fixed = TRUE;
            }
            else
            {
                // remember date_opened (to be able to fix multi line invoices)
                g_string_assign (prev_date_opened, date_opened);
            }

            // date_opened is valid

             if(!isDateValid(date_posted))
             {
                if (prev_date_posted->len == 0)
                {
                    // this invoice will have to get posted manually
                }
                else
                {
                    // multi line invoice => fix it
                    gtk_list_store_set (store, &iter, DATE_POSTED,
                                        prev_date_posted->str, -1);
                    row_fixed = TRUE;
                }
            }
            else
            {
                // remember date_opened (to be able to fix multi line invoices)
                g_string_assign (prev_date_posted, date_posted);
            }

            // date_posted is valid
            /*
            // Check if due date is valid.  Set it to date_posted if not valid or missing.
            if(!isDateValid(due_date))
            {
                gtk_list_store_set (store, &iter, DUE_DATE,
                                        date_posted, -1);
                row_fixed = TRUE;
                
            }
            
            // due_date is valid
            */
            if (strlen (quantity) == 0)
            {
                // quantity is unset => set to 1
                gtk_list_store_set (store, &iter, QUANTITY, "1", -1);
                row_fixed = TRUE;
            }
            

            // quantity is valid

            if (strlen (owner_id) == 0)
            {
                if (prev_owner_id->len == 0)
                {
                    // no customer given and not fixable => delete row
                    valid = gtk_list_store_remove (store, &iter);
                    row_deleted = TRUE;
                    g_string_append_printf (info,
                                            _("ROW %d DELETED, OWNER_NOT_SET: id=%s\n"),
                                            row, id);
                }
                else
                {
                    gtk_list_store_set (store, &iter, owner_id,
                                        prev_owner_id->str, -1);
                    row_fixed = TRUE;
                }
            }
            else
            {
                // remember owner_id
                g_string_assign (prev_owner_id, owner_id);
            }
            if (g_ascii_strcasecmp (type, "BILL") == 0)
            {
                // BILL: check, if vendor exists
                if (!gnc_search_vendor_on_id
                        (gnc_get_current_book (), prev_owner_id->str))
                {
                    // vendor not found => delete row
                    valid = gtk_list_store_remove (store, &iter);
                    row_deleted = TRUE;
                    g_string_append_printf (info,
                                            _("ROW %d DELETED, VENDOR_DOES_NOT_EXIST: id=%s\n"),
                                            row, id);
                }
            }
            else if (g_ascii_strcasecmp (type, "INVOICE") == 0)
            {
                // INVOICE: check, if customer exists
                if (!gnc_search_customer_on_id
                        (gnc_get_current_book (), prev_owner_id->str))
                {
                    // customer not found => delete row
                    valid = gtk_list_store_remove (store, &iter);
                    row_deleted = TRUE;
                    g_string_append_printf (info,
                                            _("ROW %d DELETED, CUSTOMER_DOES_NOT_EXIST: id=%s\n"),
                                            row, id);
                }
            }

            // owner_id is valid
        }

        g_free (id);
        g_free (date_opened);
        g_free (date_posted);
        g_free (owner_id);
        g_free (date);
        g_free (quantity);
        g_free (price);
        if (row_deleted)
        {
            (*deleted)++;
            // reset all remembered values
            g_string_assign (prev_id, "");
            g_string_assign (prev_date_opened, "");
            g_string_assign (prev_date_posted, "");
            g_string_assign (prev_owner_id, "");
            g_string_assign (prev_date, "");
        }
        else if (row_fixed)
            (*fixed)++;

        if (!row_deleted)
            valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);

        row++;
    }

    // deallocate strings
    g_string_free (prev_id, TRUE);
    g_string_free (prev_date_opened, TRUE);
    g_string_free (prev_date_posted, TRUE);
    g_string_free (prev_owner_id, TRUE);
    g_string_free (prev_date, TRUE);

    if (info && (info->len > 0))
    {
        g_string_prepend (info, "\n\n");
        g_string_prepend (info, _("These rows were deleted:"));
    }
}
示例#11
0
static void
add_metadata_from_tag (GFileInfo         *info,
		       const GstTagList  *list,
		       const char        *tag,
		       const char        *tag_key)
{
	GType tag_type;

	tag_type = gst_tag_get_type (tag);

	if (tag_type == G_TYPE_BOOLEAN) {
		gboolean ret;
		if (gst_tag_list_get_boolean (list, tag, &ret)) {
			if (ret)
				add_metadata (info, tag_key, g_strdup ("TRUE"), NULL);
			else
				add_metadata (info, tag_key, g_strdup ("FALSE"), NULL);
		}
	}

	if (tag_type == G_TYPE_STRING) {
		char *ret = NULL;
		if (gst_tag_list_get_string (list, tag, &ret))
			add_metadata (info, tag_key, ret, NULL);
	}

        if (tag_type == G_TYPE_UCHAR) {
                guint ret = 0;
                if (gst_tag_list_get_uint (list, tag, &ret))
                        add_metadata (info, tag_key, g_strdup_printf ("%u", ret), NULL);
        }

        if (tag_type == G_TYPE_CHAR) {
                int ret = 0;
                if (gst_tag_list_get_int (list, tag, &ret))
                        add_metadata (info, tag_key, g_strdup_printf ("%d", ret), NULL);
        }

        if (tag_type == G_TYPE_UINT) {
                guint ret = 0;
                if (gst_tag_list_get_uint (list, tag, &ret))
                        add_metadata (info, tag_key, g_strdup_printf ("%u", ret), NULL);
        }

        if (tag_type == G_TYPE_INT) {
                gint ret = 0;
                if (gst_tag_list_get_int (list, tag, &ret))
                        add_metadata (info, tag_key, g_strdup_printf ("%d", ret), NULL);
        }

        if (tag_type == G_TYPE_ULONG) {
                guint64 ret = 0;
                if (gst_tag_list_get_uint64 (list, tag, &ret))
                        add_metadata (info, tag_key, g_strdup_printf ("%" G_GUINT64_FORMAT, ret), NULL);
        }

        if (tag_type == G_TYPE_LONG) {
                gint64 ret = 0;
                if (gst_tag_list_get_int64 (list, tag, &ret))
                        add_metadata (info, tag_key, g_strdup_printf ("%" G_GINT64_FORMAT, ret), NULL);
        }

        if (tag_type == G_TYPE_INT64) {
                gint64 ret = 0;
                if (gst_tag_list_get_int64 (list, tag, &ret))
                        add_metadata (info, tag_key, g_strdup_printf ("%" G_GINT64_FORMAT, ret), NULL);
        }

        if (tag_type == G_TYPE_UINT64) {
                guint64 ret = 0;
                if (gst_tag_list_get_uint64 (list, tag, &ret))
                        add_metadata (info, tag_key, g_strdup_printf ("%" G_GUINT64_FORMAT, ret), NULL);
        }

        if (tag_type == G_TYPE_DOUBLE) {
                gdouble ret = 0;
                if (gst_tag_list_get_double (list, tag, &ret))
                        add_metadata (info, tag_key, g_strdup_printf ("%f", ret), NULL);
        }

        if (tag_type == G_TYPE_FLOAT) {
                gfloat ret = 0;
                if (gst_tag_list_get_float (list, tag, &ret))
                        add_metadata (info, tag_key, g_strdup_printf ("%f", ret), NULL);
        }

        if (tag_type == G_TYPE_DATE) {
                GDate *ret = NULL;
                if (gst_tag_list_get_date (list, tag, &ret)) {
			if (ret != NULL) {
				char  buf[128];
				char *raw;
				char *formatted;

				g_date_strftime (buf, 10, "%F %T", ret);
				raw = g_strdup (buf);

				g_date_strftime (buf, 10, "%x %X", ret);
				formatted = g_strdup (buf);
				add_metadata (info, tag_key, raw, formatted);
			}
			g_free (ret);
		}
        }
}
示例#12
0
void
calendar_draw_page (GtkPrintOperation *operation, GtkPrintContext *context, gint npage, gpointer user_data)
{
	PangoLayout *layout;
	PangoFontDescription *month_name_font, *day_name_font, *day_num_font, *event_font;
	cairo_t *cr;
	GDate *date;
	gdouble page_width, page_height, day_width, day_height;
	gint text_width, text_height, header_height, event_height, mnf_height, dnf_height, duf_height;
	gint day, month, i, j;
	guint32 julian;
	gboolean monday, actual;

	gchar buffer[BUFFER_SIZE];

	gint padding = config.cal_print_padding;

	GUI *appGUI = (GUI *) user_data;

	date = g_date_new_julian (g_date_get_julian (appGUI->cal->date));
	g_return_if_fail (date != NULL);

	cr = gtk_print_context_get_cairo_context (context);
	layout = gtk_print_context_create_pango_layout (context);

	month_name_font = pango_font_description_from_string (config.cal_print_month_name_font);
	day_name_font = pango_font_description_from_string (config.cal_print_day_name_font);
	day_num_font = pango_font_description_from_string (config.cal_print_day_num_font);
	event_font = pango_font_description_from_string (config.cal_print_event_font);

	pango_layout_set_text (layout, "Aj", -1);

	pango_layout_set_font_description (layout, month_name_font);
	pango_layout_get_pixel_size (layout, NULL, &mnf_height);
	mnf_height *= 1.2;

	pango_layout_set_font_description (layout, day_name_font);
	pango_layout_get_pixel_size (layout, NULL, &dnf_height);
	dnf_height *= 1.2;

	pango_layout_set_font_description (layout, day_num_font);
	pango_layout_get_pixel_size (layout, NULL, &duf_height);

	page_width = gtk_print_context_get_width (context);
	day_width = page_width / 7;

	page_height = gtk_print_context_get_height (context);
	header_height = mnf_height + dnf_height;
	day_height = (page_height - header_height) / 6;
	event_height = day_height - duf_height - padding * 3;

	cairo_set_line_width (cr, 1);
	monday = (config.display_options & GUI_CALENDAR_WEEK_START_MONDAY) ? TRUE : FALSE;


	/* Month and year */
	pango_layout_set_font_description (layout, month_name_font);
	g_date_strftime (buffer, BUFFER_SIZE, "%B %Y", date);
	pango_layout_set_text (layout, buffer, -1);
	pango_layout_get_pixel_size (layout, &text_width, NULL);

	cairo_move_to (cr, (page_width - text_width) / 2, 0);
	pango_cairo_show_layout (cr, layout);


	/* Day names */
	pango_layout_set_font_description (layout, day_name_font);

	for (i = 0; i < 7; i++) {
		g_snprintf (buffer, BUFFER_SIZE, "%s", utl_get_day_name (i + 7 + monday, FALSE));
		pango_layout_set_text (layout, buffer, -1);
		pango_layout_get_pixel_size (layout, &text_width, NULL);
		cairo_move_to (cr, day_width * i + (day_width - text_width) / 2, mnf_height);
		pango_cairo_show_layout (cr, layout);
	}


	/* Day */
	g_date_set_day (date, 1);
	day = g_date_get_weekday (date);
	month = g_date_get_month (date);

	day = monday ? day - 1 : day % 7;

	if (day > 0)
		g_date_subtract_days (date, day);

	day = g_date_get_day (date);
	julian = g_date_get_julian (date);

	pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
	pango_layout_set_width (layout, (day_width - padding * 2) * PANGO_SCALE);
	pango_layout_set_height (layout, event_height * PANGO_SCALE);
	pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
	pango_layout_set_indent (layout, -4 * PANGO_SCALE);

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

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

			actual = (month == g_date_get_month (date)) ? TRUE : FALSE;
			day = g_date_get_day (date);

			cairo_rectangle (cr, day_width * j, header_height + day_height * i, day_width, day_height);

			if (actual) {
				cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
			} else {
				cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
			}

			cairo_fill_preserve (cr);
			cairo_set_source_rgb (cr, 0, 0, 0);
			cairo_stroke (cr);

			pango_layout_set_font_description (layout, day_num_font);

			if (actual) {

				cairo_move_to (cr, day_width * j + padding, header_height + day_height * i + padding);

				if ((j == 0 && !monday) || (j == 5 && monday) || j == 6) {
					g_snprintf (buffer, BUFFER_SIZE, "<span color=\"red\">%d</span>", day);
				} else {
					g_snprintf (buffer, BUFFER_SIZE, "%d", day);
				}

				pango_layout_set_markup (layout, buffer, -1);
				pango_cairo_show_layout (cr, layout);

				cal_print_get_events (buffer, julian, appGUI);

				pango_layout_set_markup (layout, "", -1);
				pango_layout_set_text (layout, buffer, -1);
				pango_layout_set_font_description (layout, event_font);
				pango_layout_get_pixel_size (layout, NULL, &text_height);
				cairo_move_to (cr, day_width * j + padding, header_height + day_height * (i + 1) - text_height - padding);
				pango_cairo_show_layout (cr, layout);

			} else {

				cairo_move_to (cr, day_width * j + padding, header_height + day_height * i + padding);
				g_snprintf (buffer, BUFFER_SIZE, "<span color=\"white\">%d</span>", day);
				pango_layout_set_markup (layout, buffer, -1);
				pango_cairo_show_layout (cr, layout);

			}

			g_date_add_days (date, 1);
			julian++;

		}
	}

	g_date_free (date);
	pango_font_description_free (month_name_font);
	pango_font_description_free (day_name_font);
	pango_font_description_free (day_num_font);
	pango_font_description_free (event_font);
	g_object_unref (layout);
}
示例#13
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;
}
示例#14
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 );
}
示例#15
0
文件: gdate.c 项目: thewb/mokoiax
/* HOLDS: g_date_global_lock */
static void
g_date_prepare_to_parse (const gchar      *str, 
                         GDateParseTokens *pt)
{
  const gchar *locale = setlocale (LC_TIME, NULL);
  gboolean recompute_localeinfo = FALSE;
  GDate d;
  
  g_return_if_fail (locale != NULL); /* should not happen */
  
  g_date_clear (&d, 1);              /* clear for scratch use */
  
  if ( (current_locale == NULL) || (strcmp (locale, current_locale) != 0) ) 
    recompute_localeinfo = TRUE;  /* Uh, there used to be a reason for the temporary */
  
  if (recompute_localeinfo)
    {
      int i = 1;
      GDateParseTokens testpt;
      gchar buf[128];
      
      g_free (current_locale); /* still works if current_locale == NULL */
      
      current_locale = g_strdup (locale);
      
      short_month_names[0] = "Error";
      long_month_names[0] = "Error";

      while (i < 13) 
        {
	  gchar *casefold;
	  
          g_date_set_dmy (&d, 1, i, 1);
	  
          g_return_if_fail (g_date_valid (&d));
	  
          g_date_strftime (buf, 127, "%b", &d);

	  casefold = g_utf8_casefold (buf, -1);
          g_free (short_month_names[i]);
          short_month_names[i] = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
	  g_free (casefold);
	  
          g_date_strftime (buf, 127, "%B", &d);
	  casefold = g_utf8_casefold (buf, -1);
          g_free (long_month_names[i]);
          long_month_names[i] = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
	  g_free (casefold);
          
          ++i;
        }
      
      /* Determine DMY order */
      
      /* had to pick a random day - don't change this, some strftimes
       * are broken on some days, and this one is good so far. */
      g_date_set_dmy (&d, 4, 7, 1976);
      
      g_date_strftime (buf, 127, "%x", &d);
      
      g_date_fill_parse_tokens (buf, &testpt);
      
      i = 0;
      while (i < testpt.num_ints)
        {
          switch (testpt.n[i])
            {
            case 7:
              dmy_order[i] = G_DATE_MONTH;
              break;
            case 4:
              dmy_order[i] = G_DATE_DAY;
              break;
            case 76:
              using_twodigit_years = TRUE; /* FALL THRU */
            case 1976:
              dmy_order[i] = G_DATE_YEAR;
              break;
            default:
              /* assume locale era */
              locale_era_adjust = 1976 - testpt.n[i];
              dmy_order[i] = G_DATE_YEAR;
              break;
            }
          ++i;
        }
      
#ifdef G_ENABLE_DEBUG
      DEBUG_MSG (("**GDate prepared a new set of locale-specific parse rules."));
      i = 1;
      while (i < 13) 
        {
          DEBUG_MSG (("  %s   %s", long_month_names[i], short_month_names[i]));
          ++i;
        }
      if (using_twodigit_years)
	DEBUG_MSG (("**Using twodigit years with cutoff year: %u", twodigit_start_year));
      { 
        gchar *strings[3];
        i = 0;
        while (i < 3)
          {
            switch (dmy_order[i])
              {
              case G_DATE_MONTH:
                strings[i] = "Month";
                break;
              case G_DATE_YEAR:
                strings[i] = "Year";
                break;
              case G_DATE_DAY:
                strings[i] = "Day";
                break;
              default:
                strings[i] = NULL;
                break;
              }
            ++i;
          }
        DEBUG_MSG (("**Order: %s, %s, %s", strings[0], strings[1], strings[2]));
        DEBUG_MSG (("**Sample date in this locale: `%s'", buf));
      }
#endif
    }
  
  g_date_fill_parse_tokens (str, pt);
}
示例#16
0
std::string eServiceMP3::getInfoString(int w)
{
	if ( !m_stream_tags && w < sUser && w > 26 )
		return "";
	const gchar *tag = 0;
	switch (w)
	{
	case sTagTitle:
		tag = GST_TAG_TITLE;
		break;
	case sTagArtist:
		tag = GST_TAG_ARTIST;
		break;
	case sTagAlbum:
		tag = GST_TAG_ALBUM;
		break;
	case sTagTitleSortname:
		tag = GST_TAG_TITLE_SORTNAME;
		break;
	case sTagArtistSortname:
		tag = GST_TAG_ARTIST_SORTNAME;
		break;
	case sTagAlbumSortname:
		tag = GST_TAG_ALBUM_SORTNAME;
		break;
	case sTagDate:
		GDate *date;
		if (gst_tag_list_get_date(m_stream_tags, GST_TAG_DATE, &date))
		{
			gchar res[5];
 			g_date_strftime (res, sizeof(res), "%Y-%M-%D", date); 
			return (std::string)res;
		}
		break;
	case sTagComposer:
		tag = GST_TAG_COMPOSER;
		break;
	case sTagGenre:
		tag = GST_TAG_GENRE;
		break;
	case sTagComment:
		tag = GST_TAG_COMMENT;
		break;
	case sTagExtendedComment:
		tag = GST_TAG_EXTENDED_COMMENT;
		break;
	case sTagLocation:
		tag = GST_TAG_LOCATION;
		break;
	case sTagHomepage:
		tag = GST_TAG_HOMEPAGE;
		break;
	case sTagDescription:
		tag = GST_TAG_DESCRIPTION;
		break;
	case sTagVersion:
		tag = GST_TAG_VERSION;
		break;
	case sTagISRC:
		tag = GST_TAG_ISRC;
		break;
	case sTagOrganization:
		tag = GST_TAG_ORGANIZATION;
		break;
	case sTagCopyright:
		tag = GST_TAG_COPYRIGHT;
		break;
	case sTagCopyrightURI:
		tag = GST_TAG_COPYRIGHT_URI;
		break;
	case sTagContact:
		tag = GST_TAG_CONTACT;
		break;
	case sTagLicense:
		tag = GST_TAG_LICENSE;
		break;
	case sTagLicenseURI:
		tag = GST_TAG_LICENSE_URI;
		break;
	case sTagCodec:
		tag = GST_TAG_CODEC;
		break;
	case sTagAudioCodec:
		tag = GST_TAG_AUDIO_CODEC;
		break;
	case sTagVideoCodec:
		tag = GST_TAG_VIDEO_CODEC;
		break;
	case sTagEncoder:
		tag = GST_TAG_ENCODER;
		break;
	case sTagLanguageCode:
		tag = GST_TAG_LANGUAGE_CODE;
		break;
	case sTagKeywords:
		tag = GST_TAG_KEYWORDS;
		break;
	case sTagChannelMode:
		tag = "channel-mode";
		break;
	case sUser+12:
		return m_errorInfo.error_message;
	default:
		return "";
	}
	if ( !tag )
		return "";
	gchar *value;
	if (m_stream_tags && gst_tag_list_get_string(m_stream_tags, tag, &value))
	{
		std::string res = value;
		g_free(value);
		return res;
	}
	return "";
}
示例#17
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);
}
static void
refresh_display (GcrCertificateDetailsWidget *self)
{
	GtkTextIter start, iter;
	const guchar *data, *value;
	gsize n_data, n_value;
	const gchar *text;
	gulong version;
	guint index, size, n_bits;
	gchar *display;
	guchar *bits;
	GNode *asn;
	GQuark oid;
	GDate date;

	gtk_text_buffer_get_start_iter (self->pv->buffer, &start);
	gtk_text_buffer_get_end_iter (self->pv->buffer, &iter);
	gtk_text_buffer_delete (self->pv->buffer, &start, &iter);
	
	if (!self->pv->certificate)
		return;
	
	data = gcr_certificate_get_der_data (self->pv->certificate, &n_data);
	g_return_if_fail (data);

	asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", data, n_data);
	g_return_if_fail (asn);

	/* The subject */
	append_heading (self, _("Subject Name"));
	egg_dn_parse (egg_asn1x_node (asn, "tbsCertificate", "subject", "rdnSequence", NULL), on_parsed_dn_part, self);

	/* The Issuer */
	append_heading (self, _("Issuer Name"));
	egg_dn_parse (egg_asn1x_node (asn, "tbsCertificate", "issuer", "rdnSequence", NULL), on_parsed_dn_part, self);

	/* The Issued Parameters */
	append_heading (self, _("Issued Certificate"));

	if (!egg_asn1x_get_integer_as_ulong (egg_asn1x_node (asn, "tbsCertificate", "version", NULL), &version))
		g_return_if_reached ();
	display = g_strdup_printf ("%lu", version + 1);
	append_field_and_value (self, _("Version"), display, FALSE);
	g_free (display);

	value = egg_asn1x_get_raw_value (egg_asn1x_node (asn, "tbsCertificate", "serialNumber", NULL), &n_value);
	g_return_if_fail (value);
	display = egg_hex_encode_full (value, n_value, TRUE, ' ', 1);
	append_field_and_value (self, _("Serial Number"), display, TRUE);
	g_free (display);
	
	display = g_malloc0 (128);
	if (egg_asn1x_get_time_as_date (egg_asn1x_node (asn, "tbsCertificate", "validity", "notBefore", NULL), &date)) {
		if (!g_date_strftime (display, 128, "%Y-%m-%d", &date))
			g_return_if_reached ();
		append_field_and_value (self, _("Not Valid Before"), display, FALSE);
	}
	if (egg_asn1x_get_time_as_date (egg_asn1x_node (asn, "tbsCertificate", "validity", "notAfter", NULL), &date)) {
		if (!g_date_strftime (display, 128, "%Y-%m-%d", &date))
			g_return_if_reached ();
		append_field_and_value (self, _("Not Valid After"), display, FALSE);
	}
	g_free (display);
	
	/* Signature */
	append_heading (self, _("Signature"));

	oid = egg_asn1x_get_oid_as_quark (egg_asn1x_node (asn, "signatureAlgorithm", "algorithm", NULL));
	text = egg_oid_get_description (oid);
	append_field_and_value (self, _("Signature Algorithm"), text, FALSE);

	value = egg_asn1x_get_raw_value (egg_asn1x_node (asn, "signatureAlgorithm", "parameters", NULL), &n_value);
	if (value && n_value) {
		display = egg_hex_encode_full (value, n_value, TRUE, ' ', 1);
		append_field_and_value (self, _("Signature Parameters"), display, TRUE);
		g_free (display);
	}
	
	value = egg_asn1x_get_raw_value (egg_asn1x_node (asn, "signature", NULL), &n_value);
	g_return_if_fail (value);
	display = egg_hex_encode_full (value, n_value, TRUE, ' ', 1);
	append_field_and_value (self, _("Signature"), display, TRUE);
	g_free (display);

	/* Public Key Info */
	append_heading (self, _("Public Key Info"));

	oid = egg_asn1x_get_oid_as_quark (egg_asn1x_node (asn, "tbsCertificate", "subjectPublicKeyInfo", "algorithm", "algorithm", NULL));
	text = egg_oid_get_description (oid);
	append_field_and_value (self, _("Key Algorithm"), text, FALSE);

	value = egg_asn1x_get_raw_value (egg_asn1x_node (asn, "tbsCertificate", "subjectPublicKeyInfo", "algorithm", "parameters", NULL), &n_value);
	if (value && n_value) {
		display = egg_hex_encode_full (value, n_value, TRUE, ' ', 1);
		append_field_and_value (self, _("Key Parameters"), display, TRUE);
		g_free (display);
	}

	size = gcr_certificate_get_key_size (self->pv->certificate);
	if (size > 0) {
		display = g_strdup_printf ("%u", size); 
		append_field_and_value (self, _("Key Size"), display, FALSE);
		g_free (display);
	}

	bits = egg_asn1x_get_bits_as_raw (egg_asn1x_node (asn, "tbsCertificate", "subjectPublicKeyInfo", "subjectPublicKey", NULL), NULL, &n_bits);
	g_return_if_fail (bits);
	display = egg_hex_encode_full (bits, n_bits / 8, TRUE, ' ', 1);
	append_field_and_value (self, _("Public Key"), display, TRUE);
	g_free (display);
	g_free (bits);

	/* Fingerprints */
	append_heading (self, _("Fingerprints"));
	
	append_fingerprint (self, data, n_data, "SHA1", G_CHECKSUM_SHA1);
	append_fingerprint (self, data, n_data, "MD5", G_CHECKSUM_MD5);
	
	/* Extensions */
	for (index = 1; TRUE; ++index) {
		if (!append_extension (self, asn, data, n_data, index))
			break;
	}

	egg_asn1x_destroy (asn);
}
示例#19
0
//! \brief try to fix some common errors in the csv representation of invoices
//! * corrects the date format
//! * corrects ambigous values in multi line invoices
//! * ensures customer exists
//! * if quantity is unset, set to 1
//! * if price is unset, delete row
void
gnc_bi_import_fix_bis (GtkListStore * store, guint * fixed, guint * deleted,
                       GString * info, gchar *type)
{
    GtkTreeIter iter;
    gboolean valid, row_deleted, row_fixed;
    gchar *id, *date_opened, *date_posted, *owner_id, *date, *quantity, *price;
    GString *prev_id, *prev_date_opened, *prev_date_posted, *prev_owner_id, *prev_date;	// needed to fix multi line invoices
    guint dummy;

    // allow the call to this function with only GtkListeStore* specified
    if (!fixed)
        fixed = &dummy;
    if (!deleted)
        deleted = &dummy;

    *fixed = 0;
    *deleted = 0;

    // init strings
    prev_id = g_string_new ("");
    prev_date_opened = g_string_new ("");
    prev_date_posted = g_string_new ("");
    prev_owner_id = g_string_new ("");
    prev_date = g_string_new ("");

    valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
    while (valid)
    {
        row_deleted = FALSE;
        row_fixed = FALSE;

        // Walk through the list, reading each row
        gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
                            ID, &id,
                            DATE_OPENED, &date_opened,
                            DATE_POSTED, &date_posted,
                            OWNER_ID, &owner_id,
                            DATE, &date,
                            QUANTITY, &quantity, PRICE, &price, -1);

        if (strlen (price) == 0)
        {
            // invalid row (no price given)
            // no fix possible -> delete row
            gtk_list_store_remove (store, &iter);
            row_deleted = TRUE;
            g_string_append_printf (info,
                                    _("ROW DELETED, PRICE_NOT_SET: id=%s\n"),
                                    id);
        }
        else if (strlen (quantity) == 0)
        {
            // invalid row (no quantity given)
            // no fix possible -> delete row
            gtk_list_store_remove (store, &iter);
            row_deleted = TRUE;
            g_string_append_printf (info, _("ROW DELETED, QTY_NOT_SET: id=%s\n"),
                                    id);
        }
        else
        {
            if (strlen (id) == 0)
            {
                // no invoice id specified
                if (prev_id->len == 0)
                {
                    // cannot fix -> delete row
                    gtk_list_store_remove (store, &iter);
                    row_deleted = TRUE;
                    g_string_append_printf (info,
                                            _("ROW DELETED, ID_NOT_SET\n"));
                }
                else
                {
                    // this is a fixable multi line invoice
                    gtk_list_store_set (store, &iter, ID, prev_id->str, -1);
                    row_fixed = TRUE;
                }
            }
            else
            {
                // remember invoice id (to be able to fix multi line invoices)
                g_string_assign (prev_id, id);
                // new invoice => reset all other fixable entries
                g_string_assign (prev_date_opened, "");
                g_string_assign (prev_date_posted, "");
                g_string_assign (prev_owner_id, "");
                g_string_assign (prev_date, "");
            }
        }

        if (!row_deleted)
        {
            // the row is valid (price and id are valid)

            if (strlen (date_opened) == 0)
            {
                if (prev_date_opened->len == 0)
                {
                    // fix this by using the current date (why is this so complicated?)
                    gchar temp[20];
                    GDate *date;
                    time_t secs;
                    struct tm now;
                    time (&secs);
                    localtime_r (&secs, &now);
                    date =
                        g_date_new_dmy (now.tm_mday, now.tm_mon + 1,
                                        now.tm_year + 1900);
                    g_date_strftime (temp, 20, "%x", date);	// create a locale specific date string
                    g_string_assign (prev_date_opened, temp);
                    g_date_free (date);
                }
                // fix this by using the previous date_opened value (multi line invoice)
                gtk_list_store_set (store, &iter, DATE_OPENED,
                                    prev_date_opened->str, -1);
                row_fixed = TRUE;
            }
            else
            {
                // remember date_opened (to be able to fix multi line invoices)
                g_string_assign (prev_date_opened, date_opened);
            }

            // date_opened is valid

            if (strlen (date_posted) == 0)
            {
                if (prev_date_posted->len == 0)
                {
                    // this invoice will have to get posted manually
                }
                else
                {
                    // multi line invoice => fix it
                    gtk_list_store_set (store, &iter, DATE_POSTED,
                                        prev_date_posted->str, -1);
                    row_fixed = TRUE;
                }
            }
            else
            {
                // remember date_opened (to be able to fix multi line invoices)
                g_string_assign (prev_date_posted, date_posted);
            }

            // date_posted is valid

            if (strlen (quantity) == 0)
            {
                // quantity is unset => set to 1
                gtk_list_store_set (store, &iter, QUANTITY, "1", -1);
                row_fixed = TRUE;
            }

            // quantity is valid

            if (strlen (owner_id) == 0)
            {
                if (prev_owner_id->len == 0)
                {
                    // no customer given and not fixable => delete row
                    gtk_list_store_remove (store, &iter);
                    row_deleted = TRUE;
                    g_string_append_printf (info,
                                            _("ROW DELETED, OWNER_NOT_SET: id=%s\n"),
                                            id);
                }
                else
                {
                    gtk_list_store_set (store, &iter, owner_id,
                                        prev_owner_id->str, -1);
                    row_fixed = TRUE;
                }
            }
            else
            {
                // remember owner_id
                g_string_assign (prev_owner_id, owner_id);
            }
            if (g_ascii_strcasecmp (type, "BILL") == 0)
            {
                // BILL: check, if vendor exists
                if (!gnc_search_vendor_on_id
                        (gnc_get_current_book (), prev_owner_id->str))
                {
                    // vendor not found => delete row
                    gtk_list_store_remove (store, &iter);
                    row_deleted = TRUE;
                    g_string_append_printf (info,
                                            _("ROW DELETED, VENDOR_DOES_NOT_EXIST: id=%s\n"),
                                            id);
                }
            }
            else if (g_ascii_strcasecmp (type, "INVOICE") == 0)
            {
                // INVOICE: check, if customer exists
                if (!gnc_search_customer_on_id
                        (gnc_get_current_book (), prev_owner_id->str))
                {
                    // customer not found => delete row
                    gtk_list_store_remove (store, &iter);
                    row_deleted = TRUE;
                    g_string_append_printf (info,
                                            _("ROW DELETED, CUSTOMER_DOES_NOT_EXIST: id=%s\n"),
                                            id);
                }
            }

            // owner_id is valid
        }

        g_free (id);
        g_free (date_opened);
        g_free (date_posted);
        g_free (owner_id);
        g_free (date);
        g_free (quantity);
        g_free (price);
        if (row_deleted)
        {
            (*deleted)++;
            // reset all remembered values
            g_string_assign (prev_id, "");
            g_string_assign (prev_date_opened, "");
            g_string_assign (prev_date_posted, "");
            g_string_assign (prev_owner_id, "");
            g_string_assign (prev_date, "");
        }
        else if (row_fixed)
            (*fixed)++;
        valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
    }

    // deallocate strings
    g_string_free (prev_id, TRUE);
    g_string_free (prev_date_opened, TRUE);
    g_string_free (prev_date_posted, TRUE);
    g_string_free (prev_owner_id, TRUE);
    g_string_free (prev_date, TRUE);

    if (info && (info->len > 0))
    {
        g_string_prepend (info, "\n\n");
        g_string_prepend (info, _("These rows were deleted:"));
    }
}
示例#20
0
static void
log_manager_searched_new_cb (GObject *manager,
                             GAsyncResult *result,
                             gpointer user_data)
{
	GList               *hits;
	GList               *l;
	GtkTreeIter          iter;
	GtkListStore        *store = user_data;
	GError              *error = NULL;

	if (log_window == NULL)
		return;

	if (!tpl_log_manager_search_finish (TPL_LOG_MANAGER (manager), result,
		&hits, &error)) {
			DEBUG ("%s. Aborting", error->message);
			g_error_free (error);
			return;
	}

	for (l = hits; l; l = l->next) {
			TplLogSearchHit *hit;
			const gchar         *account_name;
			const gchar         *account_icon;
			gchar               date_readable[255];
			gchar               tmp[255];

			hit = l->data;

			/* Protect against invalid data (corrupt or old log files. */
			if (hit->account == NULL || hit->chat_id == NULL) {
					continue;
			}

			g_date_strftime (date_readable, sizeof (date_readable),
				EMPATHY_DATE_FORMAT_DISPLAY_SHORT, hit->date);

			g_date_strftime (tmp, sizeof (tmp),
				"%Y%m%d", hit->date);

			account_name = tp_account_get_display_name (hit->account);
			account_icon = tp_account_get_icon_name (hit->account);

			gtk_list_store_append (store, &iter);
			gtk_list_store_set (store, &iter,
					COL_FIND_ACCOUNT_ICON, account_icon,
					COL_FIND_ACCOUNT_NAME, account_name,
					COL_FIND_ACCOUNT, hit->account,
					COL_FIND_CHAT_NAME, hit->chat_id, /* FIXME */
					COL_FIND_CHAT_ID, hit->chat_id,
					COL_FIND_IS_CHATROOM, hit->is_chatroom,
					COL_FIND_DATE, tmp,
					COL_FIND_DATE_READABLE, date_readable,
					-1);

			/* FIXME: Update COL_FIND_CHAT_NAME */
			if (hit->is_chatroom) {
			} else {
			}
	}

	if (hits != NULL) {
			tpl_log_manager_search_free (hits);
	}
}
示例#21
0
/** Create the preferences dialog.  This function first reads the
 *  dialog-preferences.glade file to obtain the content and then
 *  the dialog is created with a set of common preferences.  It then
 *  runs the list of add-ins, calling a helper function to add each full/partial
 *  page to this dialog, Finally it builds the "interesting widgets"
 *  table that is used for connecting the widgets up to callback functions.
 *
 *  @internal
 *
 *  @return A pointer to the newly created dialog.
 */
static GtkWidget *
gnc_preferences_dialog_create(void)
{
    GtkBuilder *builder;
    GtkWidget *dialog, *notebook, *label, *image;
    GtkWidget *box, *date, *period, *currency;
    GHashTable *prefs_table;
    GDate* gdate = NULL;
    gchar buf[128];
    GtkListStore *store;
    GtkTreePath *path;
    GtkTreeIter iter;
    gnc_commodity *locale_currency;
    const gchar *currency_name;
    QofBook *book;
    KvpFrame *book_frame;
    gint64 month, day;
    GDate fy_end;
    gboolean date_is_valid = FALSE;

    ENTER("");
    DEBUG("Opening dialog-preferences.glade:");
    builder = gtk_builder_new();

    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "auto_decimal_places_adj");
    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "autosave_interval_minutes_adj");
    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "save_on_close_adj");
    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "date_backmonth_adj");
    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "max_transactions_adj");
    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "key_length_adj");
    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "new_search_limit_adj");
    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "retain_days_adj");
    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "tab_width_adj");
    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "date_formats");
    gnc_builder_add_from_file (builder, "dialog-preferences.glade", "GnuCash Preferences");

    dialog = GTK_WIDGET(gtk_builder_get_object (builder, "GnuCash Preferences"));

#ifndef REGISTER2_ENABLED
    /* Hide preferences that are related to register2 */
    box = GTK_WIDGET (gtk_builder_get_object (builder, "label14"));
    gtk_widget_hide (box);
    box = GTK_WIDGET (gtk_builder_get_object (builder, "pref/general.register/key-length"));
    gtk_widget_hide (box);
    box = GTK_WIDGET (gtk_builder_get_object (builder, "pref/general.register/show-extra-dates"));
    gtk_widget_hide (box);
    box = GTK_WIDGET (gtk_builder_get_object (builder, "pref/general.register/show-calendar-buttons"));
    gtk_widget_hide (box);
    box = GTK_WIDGET (gtk_builder_get_object (builder, "pref/general.register/selection-to-blank-on-expand"));
    gtk_widget_hide (box);
    box = GTK_WIDGET (gtk_builder_get_object (builder, "pref/general.register/show-extra-dates-on-selection"));
    gtk_widget_hide (box);
#endif

    label = GTK_WIDGET(gtk_builder_get_object (builder, "sample_account"));
    g_object_set_data(G_OBJECT(dialog), "sample_account", label);

    image = GTK_WIDGET(gtk_builder_get_object (builder, "separator_error"));
    g_object_set_data(G_OBJECT(dialog), "separator_error", image);

    DEBUG("autoconnect");
    gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, dialog);

    DEBUG("done");

    notebook = GTK_WIDGET(gtk_builder_get_object (builder, "notebook1"));
    prefs_table = g_hash_table_new(g_str_hash, g_str_equal);
    g_object_set_data(G_OBJECT(dialog), NOTEBOOK, notebook);
    g_object_set_data_full(G_OBJECT(dialog), PREFS_WIDGET_HASH,
                           prefs_table, (GDestroyNotify)g_hash_table_destroy);


    book = gnc_get_current_book();
    g_date_clear (&fy_end, 1);
    qof_instance_get (QOF_INSTANCE (book),
		      "fy-end", &fy_end,
		      NULL);
    box = GTK_WIDGET(gtk_builder_get_object (builder,
                     "pref/" GNC_PREFS_GROUP_ACCT_SUMMARY "/" GNC_PREF_START_PERIOD));
    period = gnc_period_select_new(TRUE);
    gtk_widget_show (period);
    gtk_box_pack_start (GTK_BOX (box), period, TRUE, TRUE, 0);
    if (date_is_valid)
        gnc_period_select_set_fy_end(GNC_PERIOD_SELECT (period), &fy_end);

    box = GTK_WIDGET(gtk_builder_get_object (builder,
                     "pref/" GNC_PREFS_GROUP_ACCT_SUMMARY "/" GNC_PREF_END_PERIOD));
    period = gnc_period_select_new(FALSE);
    gtk_widget_show (period);
    gtk_box_pack_start (GTK_BOX (box), period, TRUE, TRUE, 0);
    if (date_is_valid)
        gnc_period_select_set_fy_end(GNC_PERIOD_SELECT (period), &fy_end);

    box = GTK_WIDGET(gtk_builder_get_object (builder,
                     "pref/" GNC_PREFS_GROUP_ACCT_SUMMARY "/" GNC_PREF_START_DATE));
    date = gnc_date_edit_new(gnc_time (NULL), FALSE, FALSE);
    gtk_widget_show (date);
    gtk_box_pack_start (GTK_BOX (box), date, TRUE, TRUE, 0);

    box = GTK_WIDGET(gtk_builder_get_object (builder,
                     "pref/" GNC_PREFS_GROUP_ACCT_SUMMARY "/" GNC_PREF_END_DATE));
    date = gnc_date_edit_new(gnc_time (NULL), FALSE, FALSE);
    gtk_widget_show (date);
    gtk_box_pack_start (GTK_BOX (box), date, TRUE, TRUE, 0);

    box = GTK_WIDGET(gtk_builder_get_object (builder,
                     "pref/" GNC_PREFS_GROUP_GENERAL "/" GNC_PREF_CURRENCY_OTHER));
    currency = gnc_currency_edit_new();
    gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(currency), gnc_default_currency());
    gtk_widget_show (currency);
    gtk_box_pack_start(GTK_BOX (box), currency, TRUE, TRUE, 0);

    box = GTK_WIDGET(gtk_builder_get_object (builder,
                     "pref/" GNC_PREFS_GROUP_GENERAL_REPORT "/" GNC_PREF_CURRENCY_OTHER));
    currency = gnc_currency_edit_new();
    gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(currency), gnc_default_currency());
    gtk_widget_show (currency);
    gtk_box_pack_start(GTK_BOX (box), currency, TRUE, TRUE, 0);


    /* Add to the list of interesting widgets */
    gnc_prefs_build_widget_table(builder, dialog);

    g_slist_foreach(add_ins, gnc_preferences_build_page, dialog);

    /* Sort tabs alphabetically */
    gnc_prefs_sort_pages(GTK_NOTEBOOK(notebook));
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);

    DEBUG("We have the following interesting widgets:");
    g_hash_table_foreach(prefs_table, (GHFunc)gnc_prefs_connect_one, dialog);
    DEBUG("Done with interesting widgets.");

    /* Other stuff */
    gdate = g_date_new_dmy(31, G_DATE_JULY, 2013);
    g_date_strftime(buf, sizeof(buf), "%x", gdate);
    store = GTK_LIST_STORE(gtk_builder_get_object (builder, "date_formats"));
    path = gtk_tree_path_new_from_indices (QOF_DATE_FORMAT_LOCALE, -1);
    if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
            gtk_list_store_set (store, &iter, 1, buf, -1);
    g_date_free(gdate);

    locale_currency = gnc_locale_default_currency ();
    currency_name = gnc_commodity_get_printname(locale_currency);
    label = GTK_WIDGET(gtk_builder_get_object (builder, "locale_currency"));
    gtk_label_set_label(GTK_LABEL(label), currency_name);
    label = GTK_WIDGET(gtk_builder_get_object (builder, "locale_currency2"));
    gtk_label_set_label(GTK_LABEL(label), currency_name);

    g_object_unref(G_OBJECT(builder));

    LEAVE("dialog %p", dialog);
    return dialog;
}
/* Construct the status bar widget. */
static GtkWidget *
libre_impuesto_window_construct_headerbar (LibreImpuestoWindow *impuesto_window)
{
  gint size;
  time_t secs;
  GDate *today;
  struct tm *tm;
  GtkStateFlags state;
  GtkWidget *headerbar;
  gchar buffer[100] = "";
  GtkWidget *header_area;
  GtkWidget *grid_layout;
  GtkStyleContext *context;
  PangoFontDescription *font_desc;
  GtkWidget *label_libre_impuesto, *label_software_libre, *label_date;


  secs = time (NULL);
  tm = localtime (&secs);

  header_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
  g_object_bind_property (
		impuesto_window, "headerbar-visible",
		header_area, "visible",
		G_BINDING_SYNC_CREATE);

  headerbar = gtk_event_box_new();
  gtk_box_pack_start (GTK_BOX (header_area), 
		      headerbar, FALSE, FALSE, 0);

  gtk_widget_set_name (headerbar, "libre-impuesto-header");
  gtk_widget_set_size_request (headerbar, -1, 56);

  grid_layout = gtk_grid_new ();
  gtk_container_add (GTK_CONTAINER (headerbar), grid_layout);
  gtk_grid_set_column_homogeneous (GTK_GRID(grid_layout), TRUE);
  gtk_grid_set_row_homogeneous (GTK_GRID (grid_layout), TRUE);

  label_libre_impuesto = gtk_label_new (_("Libre Impuestos"));
  gtk_grid_attach (GTK_GRID (grid_layout), label_libre_impuesto, 0, 0, 1, 1);  

  context = gtk_widget_get_style_context (label_libre_impuesto);
  state = gtk_widget_get_state_flags (label_libre_impuesto);
  size = pango_font_description_get_size (gtk_style_context_get_font (
								      context, 
								      state));
  font_desc = pango_font_description_new ();
  pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
  pango_font_description_set_size (font_desc, size * PANGO_SCALE_X_LARGE);
  gtk_widget_override_font (label_libre_impuesto, font_desc);
  pango_font_description_free (font_desc);

  gtk_misc_set_alignment (GTK_MISC (label_libre_impuesto), 0.2, 0.4);
  gtk_widget_show (label_libre_impuesto);

  label_software_libre = gtk_label_new (_("www.softwarelibre.org.bo"));
  gtk_grid_attach (GTK_GRID (grid_layout), label_software_libre, 1, 0, 1, 1);  
  gtk_misc_set_alignment (GTK_MISC (label_software_libre), 0.5, 0.8);
  gtk_widget_show (label_software_libre);

  today = g_date_new_dmy((gint)tm->tm_mday, 
			 (gint)tm->tm_mon + 1, 
			 1900 + tm->tm_year);

  g_date_strftime (buffer, 100-1, "%A, %d de %B de %Y", today);
  label_date = gtk_label_new (g_ascii_strup (buffer,100-1));
  g_date_free(today);

  gtk_grid_attach (GTK_GRID (grid_layout), label_date, 2, 0, 1, 1);  
  gtk_misc_set_alignment (GTK_MISC (label_date), 0.9, 0.5);

  return header_area;
}
示例#23
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);
}
示例#24
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);
}
示例#25
0
文件: edit.c 项目: bsdcat/palcal
gchar* pal_edit_get_field_val(int i, PalEvent *event, GDate *d)
{
    gchar *buf = NULL;

    switch(i)
    {
	case 0:
	    return g_strdup(event->text);
	case 1:
	    return event->eventtype->get_descr( d );
	case 2:
	    buf = g_malloc(sizeof(gchar)*128);
	    snprintf(buf, 128, "%d", event->period_count);
	    return buf;
	case 3:
	    if(event->start_date == NULL)
		return g_strdup(_("None"));

	    buf = g_malloc(sizeof(gchar)*128);
	    g_date_strftime(buf, 128,
			    settings->date_fmt, event->start_date);
	    return buf;

	case 4:
	    if(event->end_date == NULL)
		return g_strdup(_("None"));

	    buf = g_malloc(sizeof(gchar)*128);
	    g_date_strftime(buf, 128,
			    settings->date_fmt, event->end_date);
	    return buf;
	case 5:
	    if(event->start_time == NULL)
		return g_strdup(_("None"));

	    buf = g_malloc(sizeof(gchar)*128);
	    snprintf(buf, 128, "%02d:%02d",
		     event->start_time->hour,
		     event->start_time->min);
	    return buf;
	case 6:
	    if(event->end_time == NULL)
		return g_strdup(_("None"));

	    buf = g_malloc(sizeof(gchar)*128);
	    snprintf(buf, 128, "%02d:%02d",
		     event->end_time->hour,
		     event->end_time->min);
	    return buf;
	case 7:
	    return g_strdup(event->key);
	case 8:
	    return g_strdup(event->date_string);
	case 9:
	    return g_strdup(event->file_name);
	case 10:
	    buf = g_malloc(sizeof(gchar)*128);
	    snprintf(buf, 128, "%c%c",
		     event->start, event->end);
	    return buf;
	case 11:
	    if(event->color == -1)
		return string_color_of(settings->event_color);
	    return string_color_of(settings->event_color);
	default:
	    return g_strdup("NOT IMPLEMENTED");
    }

}
示例#26
0
文件: remind.c 项目: bsdcat/palcal
static void pal_remind_event(void)
{
    PalEvent* remind_event = NULL;
    GDate* event_date = NULL;
    gchar* at_string;
    gchar tmp_name[] = "/tmp/pal-XXXXXX";
    FILE* tmp_stream;
    int return_val;
    gchar* email_add;
    G_CONST_RETURN gchar *charset;
    at_string = g_malloc(1024*sizeof(gchar));

    pal_output_fg(BRIGHT, GREEN, "* * * ");
    pal_output_attr(BRIGHT, _("Event reminder"));
    pal_output_fg(BRIGHT, GREEN, " * * *\n");

    pal_output_fg(BRIGHT, GREEN, "> ");
    pal_output_wrap(_("This feature allows you to select one event and have an email sent to you about the event at a date/time that you provide.  If the event is recurring, you will only receive one reminder.  You MUST have atd, crond and sendmail installed and working for this feature to work."),2,2);

    g_print("\n");

    remind_event = pal_rl_get_event(&event_date, TRUE);
    g_print("\n");

    if(remind_event->start_time != NULL)
    {
	snprintf(at_string, 1024, "%02d:%02d %04d-%02d-%02dW",
		 remind_event->start_time->hour,
		 remind_event->start_time->min,
		 g_date_get_year(event_date),
		 g_date_get_month(event_date),
		 g_date_get_day(event_date));

    }
    else
    {
	snprintf(at_string, 1024, "%02d:%02d %04d-%02d-%02d", 0,0,
		 g_date_get_year(event_date),
		 g_date_get_month(event_date),
		 g_date_get_day(event_date));

    }


#if 0
    pal_rl_default_text = at_string;
    rl_pre_input_hook = (rl_hook_func_t*) pal_rl_default_text_fn;
    at_string = pal_rl_get_line(_("Remind me on (HH:MM YYYY-MM-DD): "), settings->term_rows-2, 0);
    rl_pre_input_hook = NULL;
#endif

    at_string = pal_rl_get_line_default(_("Remind me on (HH:MM YYYY-MM-DD): "), settings->term_rows-2, 0, at_string);

#if 0
    pal_rl_default_text = g_strdup(g_get_user_name());
    rl_pre_input_hook = (rl_hook_func_t*) pal_rl_default_text_fn;
    email_add = pal_rl_get_line(_("Username on local machine or email address: "), settings->term_rows-2, 0);
    rl_pre_input_hook = NULL;
#endif
    
    email_add = pal_rl_get_line_default(_("Username on local machine or email address: "), settings->term_rows-2, 0, g_strdup(g_get_user_name()));

    mkstemp(tmp_name);
    tmp_stream = fopen(tmp_name, "w");

    fputs("echo \"", tmp_stream);
    fputs("From: \"pal\" <pal>\n", tmp_stream);
    fputs("To: ", tmp_stream);
    fputs(email_add, tmp_stream);
    fputs("\n", tmp_stream);

    g_get_charset(&charset);
    fputs("Content-Type: text/plain; charset=", tmp_stream);
    fputs(charset, tmp_stream);
    fputs("\n", tmp_stream);

    fputs("Subject: [pal] ", tmp_stream);
    pal_remind_escape(g_strndup(remind_event->text, 128), tmp_stream);
    fputs("\n\n", tmp_stream);

    fputs(_("Event: "), tmp_stream);
    pal_remind_escape(remind_event->text, tmp_stream);
    fputs("\n", tmp_stream);

    fputs(_("Event date: "), tmp_stream);

    {
	gchar pretty_date[128];
	g_date_strftime(pretty_date, 128, settings->date_fmt, event_date);
	fputs(pretty_date, tmp_stream);
    }
    fputs("\n", tmp_stream);

    fputs(_("Event type: "), tmp_stream);
    pal_remind_escape(remind_event->type, tmp_stream);
    fputs("\n", tmp_stream);
    fputs("\"| /usr/sbin/sendmail ", tmp_stream);
    fputs(email_add, tmp_stream);

    fclose(tmp_stream);

    pal_output_fg(BRIGHT, GREEN, "> ");
    g_print(_("Attempting to run 'at'...\n"));
    g_print("at -f %s %s\n", tmp_name, at_string);
    return_val = system(g_strconcat("at -f ", tmp_name, " ", at_string, NULL));

    if(return_val != 0)
	pal_output_error(_("ERROR: Date string was invalid or could not run 'at'.  Is 'atd' running?"));
    else
    {
	pal_output_fg(BRIGHT, GREEN, ">>> ");
	g_print(_("Successfully added event to the 'at' queue.\n"));
    }

    remove(tmp_name);
}
示例#27
0
文件: main.c 项目: wellth/Demo-02
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
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);

}