main.h File Reference


Detailed Description

Temporary home for common routines.

Author:
Copyright 2006, 2007 Neil Williams <linux@codehelp.co.uk>

Copyright 1999 Robert Lissner

Definition in file main.h.

Go to the source code of this file.

Data Structures

struct  QlContext
 The QuickList Context. More...
struct  QlTabData
 Context for each notebook tab. More...

Defines

#define QLCONTEXT   "QuickListContextID"
#define CHECK_RANGE   if (tab->view->sel_range.col0 > tab->file->last_field) return
#define CHECK_CHANGED(x)   if (check_if_changed (x)) return
#define MAX_DATE_BUFFER   256
New QuickList standard formats
Automatically translated using strftime, parsed by GDate and directly compatible with XML and xsd:date. The new formats allow dates (and times) to be handled internally in a consistent manner and displayed to the user in standard formats. This list can be easily extended.

#define QL_DF_ISO99   "%m/%d/%y"
#define QL_DF_UK   "%d/%m/%y"
#define QL_DF_ISO8601   "%Y-%m-%d"
#define QL_DF_RFC822   "%a, %d %b %Y"
#define QL_DF_CE   "%d.%m.%Y"
#define QL_DF_US   "%m.%d.%Y"
#define QL_DF_LOCALE   "%x"
New QuickList standard formats
Automatically translated using strftime, parsed by GDate and directly compatible with XML and xsd:time. The new formats allow dates (and times) to be handled internally in a consistent manner and displayed to the user in standard formats. This list can be easily extended.

#define QL_TF_LOCALE   "%X"
#define QL_TF_SECS   "%s"
New specifiers
Todo:
Like the new date and time specifiers - work out how to fold these into the options in the New dialogue, once a suitable file format is available. QLF cannot support these specifiers, yet.


#define QL_NF_PAR_CUR_GRP   "%(n"
#define QL_NF_PAR_CUR   "%^(n"
#define QL_NF_PAR_GRP   "%(!i"
#define QL_NF_INT_GRP   "%i"
#define QL_NF_PAR_INT_GRP   "%i("
#define QL_NF_PAR_INT   "%^i("
#define QL_NF_INT   "%^i"

Enumerations

enum  QlDateFormat {
  QL_DF_USSHORT = 0, QL_DF_USLONG, QL_DF_USSHORT_2, QL_DF_USLONG_2,
  QL_DF_LOCAL_MONTH, QL_DF_LONGYEAR, QL_DF_LOCAL_DAY, QL_DF_EURSHORT,
  QL_DF_EURLONG, QL_DF_LAST
}
 Replacement QuickList date formats. More...
enum  QlTimeFormat {
  QL_TF_12P = 0, QL_TF_24, QL_TF_DOT24, QL_TF_24P,
  QL_TF_T, QL_TF_12TP, QL_TF_LAST
}
 Replacement QuickList time formats. More...
enum  QlCurrFormat {
  QL_NF_GRP = 0, QL_NF_OLD_A, QL_NF, QL_NF_OLD_B,
  QL_NF_CURR, QL_NF_PERCENT, QL_NF_OLD_C, QL_NF_LAST
}
 Replacement QuickList currency formats. More...

Functions

const gchar * convert_old_df (QlDateFormat df)
 compatibility function
const gchar * convert_old_tf (QlTimeFormat tf)
const gchar * convert_old_cf (QlCurrFormat cf)
gchar * display_date (GDate *gd, const gchar *fmt)
 Display dates using old and new types.
gchar * display_time (GTimeVal *gt, const gchar *fmt)
GDate * parse_date (const gchar *string, const gchar *format)
 Parse an incoming date string - any type.
QlContextql_context_init (void)
void add1row (QlTabData *tab)
void big_draw_start (QlTabData *tab)
void big_draw_end (QlTabData *tab)
gboolean check_if_changed (QlTabData *tab)
gint check_entry (QlTabData *tab, gchar *entry)
void connect_signals (QlTabData *tab)
gint d2qls (gchar *texto, gdouble input, QlFieldType type, QlDateFormat formatting, gint dec_places)
 old compatibility function
void close_dlg (GtkWidget *w, gpointer data)
void front_is_changed (QlTabData *tab)
 notebook-aware dirty flag
void get_window_size_loc (GtkWidget *win)
void level1_error (QlTabData *tab, gchar *message)
void level2_error (QlTabData *tab, gchar *message)
void make_basic_dialog1 (void)
gdouble qls2d (const gchar *input, gint type, gint formatting)
void reset_col_to_field (QlTabData *tab)
void set_window_size_loc (GtkWidget *win)
void unselect (QlTabData *tab)


Define Documentation

#define MAX_DATE_BUFFER   256

Maximum length of a date string.

Definition at line 212 of file main.h.

#define QL_DF_CE   "%d.%m.%Y"

31.12.2006 d.m.Y

Definition at line 87 of file main.h.

#define QL_DF_ISO8601   "%Y-%m-%d"

1999-12-31 same as F - also used by xsd:date

Definition at line 83 of file main.h.

#define QL_DF_ISO99   "%m/%d/%y"

12/31/99 - same as QL_DF_USSHORT

Definition at line 79 of file main.h.

#define QL_DF_LOCALE   "%x"

Locale-specific x - for en_GB this is: 31/12/06

Definition at line 91 of file main.h.

#define QL_DF_RFC822   "%a, %d %b %Y"

Sat, 11 Nov 2006 a, d b Y

Definition at line 85 of file main.h.

#define QL_DF_UK   "%d/%m/%y"

31/12/99 d/m/y

Definition at line 81 of file main.h.

#define QL_DF_US   "%m.%d.%Y"

12.31.2006 m.d.Y

Definition at line 89 of file main.h.

#define QL_NF_INT   "%^i"

^i 12345.99GBP

Definition at line 203 of file main.h.

#define QL_NF_INT_GRP   "%i"

i 12,345.99GBP

Definition at line 194 of file main.h.

#define QL_NF_PAR_CUR   "%^(n"

^(n (£12345.99)

Definition at line 188 of file main.h.

#define QL_NF_PAR_CUR_GRP   "%(n"

%(n (£12,345.99)

Definition at line 185 of file main.h.

#define QL_NF_PAR_GRP   "%(!i"

%(!i (12,345.99)

Definition at line 191 of file main.h.

#define QL_NF_PAR_INT   "%^i("

^i( (12345.99)GBP

Definition at line 200 of file main.h.

#define QL_NF_PAR_INT_GRP   "%i("

i( (12,345.99)GBP

Definition at line 197 of file main.h.


Enumeration Type Documentation

enum QlCurrFormat

Replacement QuickList currency formats.

These seven formats exist for compatibility with QuickList prior to v0.8.6 - subsequent versions use standard strmon formats and are all therefore localised.

Old style QLF files use the old formats but the values are now converted internally.

The names should be descriptive, according to this formula: QL_NF prefix OLD if the format is deprecated and only used with .qlf files PAR if negative values are enclosed in parentheses CUR if the national currency symbol is used e.g. $ or £ INT if the international currency symbol is used e.g. USD or GBP GRP if thousands separators are used (grouping), e.g. 1234.56 vs 1,234.56

Enumerator:
QL_NF_GRP  1,234.56 %!i simple grouped double
QL_NF_OLD_A  1.234,56 used for files only
QL_NF  1234.56 %^!i ungrouped double
QL_NF_OLD_B  "1234,56" used for files only
QL_NF_CURR  $1,234.56 default monetary display (%n)
QL_NF_PERCENT  1,234.56% %!i%% default percentage display
QL_NF_OLD_C  1.234,56% used for files only
QL_NF_LAST  unused check value

Definition at line 154 of file main.h.

00155 {
00157     QL_NF_GRP = 0,
00159     QL_NF_OLD_A,
00161     QL_NF,
00163     QL_NF_OLD_B,
00165     QL_NF_CURR,
00167     QL_NF_PERCENT,
00169     QL_NF_OLD_C,
00171     QL_NF_LAST
00172 }QlCurrFormat;

enum QlDateFormat

Replacement QuickList date formats.

These seven formats exist for compatibility with QuickList prior to v0.8.6 - subsequent versions use standard strftime formats and are therefore localised.

Old style QLF files use the old formats but the values are now converted to GDate internally.

Enumerator:
QL_DF_USSHORT  12/31/99 %m/%d%y New : QL_DF_ISO99 OLD: "M /D0/Y2"
QL_DF_USLONG  12/31/1999 %m/%d/%Y QL_DF_USLONG OLD: "M /D0/Y4"
QL_DF_USSHORT_2  12.31.99 %m.%d.%y QL_DF_USSHORT_2 OLD: "M .D0.Y2"
QL_DF_USLONG_2  12.31.1999 %m.%d.%Y QL_DF_USLONG_2 OLD: "M .D0.Y4"
QL_DF_LOCAL_MONTH  Dec 31 1999 %b %m %y QL_DF_LOCAL_MONTH OLD: "MA D Y4"
QL_DF_LONGYEAR  1999-12-31 %Y-%m-%d QL_DF_UTC OLD: "Y4-M0-D0"
QL_DF_LOCAL_DAY  31 Dec 1999 %m %b %Y QL_DF_LOCAL_DAY OLD: "D MA Y4"
QL_DF_EURSHORT  31/12/99 %d/%m/%y QL_DF_EURSHORT OLD: "D /M0/Y2"
QL_DF_EURLONG  31/12/1999 %d/%m/%Y QL_DF_EURLONG OLD: "D /M0/Y4"
QL_DF_LAST  unused check value

Definition at line 43 of file main.h.

00044 {
00045     /* % symbols need to be escaped for doxygen */
00047     QL_DF_USSHORT = 0,
00049     QL_DF_USLONG,
00051     QL_DF_USSHORT_2,
00053     QL_DF_USLONG_2,
00055     QL_DF_LOCAL_MONTH,
00057     QL_DF_LONGYEAR,
00059     QL_DF_LOCAL_DAY,
00061     QL_DF_EURSHORT,
00063     QL_DF_EURLONG,
00065     QL_DF_LAST
00066 } QlDateFormat;

enum QlTimeFormat

Replacement QuickList time formats.

These six formats exist for compatibility with QuickList prior to v0.8.6 - subsequent versions use standard strftime formats and are therefore localised.

Old style QLF files use the old formats but the values are now converted to GDate internally.

Enumerator:
QL_TF_12P  "6:00 PM" %l:%M %p
QL_TF_24  "18:00" %R
QL_TF_DOT24  "18.00" %H.%M
QL_TF_24P  "18:00pm %H:%M%P
QL_TF_T  "23:53:37" %T
QL_TF_12TP  "11:53:37 PM %l:%M:%S %p
QL_TF_LAST  unused check value

Definition at line 104 of file main.h.

00105 {
00107     QL_TF_12P = 0,
00109     QL_TF_24,
00111     QL_TF_DOT24,
00113     QL_TF_24P,
00115     QL_TF_T,
00117     QL_TF_12TP,
00119     QL_TF_LAST
00120 }QlTimeFormat;


Function Documentation

gboolean check_if_changed ( QlTabData tab  ) 

<

Bug:
remove the static buffer

Todo:
replace with safe_strcmp from QOF

Definition at line 305 of file main.c.

00306 {
00307     gint fieldx;
00308     gdouble temp_double;
00309     gchar linebuf[40]; 
00310     gchar *newtext;
00311     QlFieldInfo * field;
00312 
00313     g_return_val_if_fail (tab, FALSE);
00314     /* initial vals */
00315     if (tab->view->activate_row < 0 || tab->view->activate_col < 0)
00316         return FALSE;
00317     if (!tab->view->sheet)
00318         return FALSE;
00319     if (tab->file->changed)
00320         return TRUE;
00321     newtext = gtk_sheet_cell_get_text (tab->view->sheet,
00322         tab->view->activate_row, tab->view->activate_col);
00323 
00325     /* both zero */
00326     if (!tab->view->activate_text && !newtext)
00327         return FALSE;
00328 
00329     if (tab->view->activate_text && newtext)
00330         if (!(strcmp (newtext, tab->view->activate_text)))
00331         return FALSE;
00332 
00333     /* entries clearly don't match */
00334     front_is_changed (tab);
00335     if (!newtext)
00336         return FALSE;
00337 
00338     /* check that input is valid in non-text fields */
00339     fieldx = tab->file->col_to_field[tab->view->activate_col];
00340     field = ql_get_fieldinfo (tab, fieldx);
00341     if (field->type != FIELD_TYPE_TEXT)
00342     {
00343         temp_double = qls2d (newtext, field->type,
00344             field->formatting);
00345 
00346         if (temp_double >= HUGE_VAL)
00347         {
00348             level2_error (tab, _("The cell contents are not valid."));
00349             return (TRUE);
00350         }
00351         d2qls (linebuf, temp_double, field->type,
00352             field->formatting,
00353             field->decimal_places);
00354         gtk_sheet_set_cell_text (tab->view->sheet,
00355             tab->view->activate_row, tab->view->activate_col, linebuf);
00356     }
00357     return TRUE;
00358 }                               /* end of check_if_changed () */

const gchar* convert_old_cf ( QlCurrFormat  cf  ) 

old values are mapped to the new

unused check value

Definition at line 95 of file main.c.

00096 {
00097     switch (cf)
00098     {
00099         /* "1,234.56" %! formatting style for formatting == 0 */
00100         case QL_NF_GRP :   { return "%!i"; break;  }
00101         /* "1.234,56" used for files only */
00102         case QL_NF_OLD_A : { return "%!i"; break;  }
00103         /* "1234.56"  %^! */
00104         case QL_NF :       { return "%^!i"; break; }
00105         /* "1234,56" used for files only */
00106         case QL_NF_OLD_B : { return "%^!i"; break; }
00107         /* "$1,234.56"  default (%n) */
00108         case QL_NF_CURR :  { return "%n"; break;  }
00109         /* "1,234.56%" used for files only */
00110         case QL_NF_OLD_C : { return "%!i%%"; break;  }
00111         /* "1.234,56%" used for files only */
00112         case QL_NF_PERCENT : { return "%!i%%"; break;  }
00114         case QL_NF_LAST :  { return NULL; }
00115     }
00116     return NULL;
00117 }

const gchar* convert_old_df ( QlDateFormat  df  ) 

compatibility function

Converts old-style QlDateFormat values into strftime-compatible format strings.

Parameters:
df Old style QlDateFormat value to convert.
Returns:
A strftime-compatible format string for the specified QlDateFormat
compatibility function

Since:
0.9.0
Previous versions had limited date support, v0.9.0 starts a wider progression to a more comprehensive date, time and number formatting options.

Definition at line 59 of file main.c.

00060 {
00061     switch (df)
00062     {
00063         case QL_DF_USSHORT     : { return QL_DF_ISO99;   break; }
00064         case QL_DF_USLONG      : { return "%m/%d/%Y";    break; }
00065         case QL_DF_USSHORT_2   : { return "%m.%d.%y";    break; }
00066         case QL_DF_USLONG_2    : { return QL_DF_US;      break; }
00067         case QL_DF_LOCAL_MONTH : { return "%b %m %y";    break; }
00068         case QL_DF_LONGYEAR    : { return QL_DF_ISO8601; break; }
00069         case QL_DF_LOCAL_DAY   : { return "%m %b %Y";    break; }
00070         case QL_DF_EURSHORT    : { return QL_DF_UK;      break; }
00071         case QL_DF_EURLONG     : { return "%d/%m/%Y";    break; }
00072         case QL_DF_LAST : { return NULL; }
00073     }
00074     return NULL;
00075 }

gint d2qls ( gchar *  texto,
gdouble  input,
QlFieldType  type,
QlDateFormat  formatting,
gint  dec_places 
)

old compatibility function

Converts an internal double to an old quicklist string.

Bug:
formatting is overridden for use by QlCurrFormat as well.

Todo:
check why this is empty.

Definition at line 368 of file main.c.

00370 {
00371     /* these are for numeric conversions */
00372     gboolean is_negative;
00373     gboolean is_currency;
00374     gboolean is_percent;
00375     gchar * texti;
00376     gdouble temp_val;
00377 
00378     /* these are for date conversion */
00379     GDateYear year;
00380     GDateMonth month;
00381     GDateDay day;
00382 
00383     /* these are for time conversions */
00384     gint hour;
00385     gint min;
00386 
00387     temp_val = input;
00388     if (temp_val >= HUGE_VAL)
00389     {
00390         texto = g_strdup ("######");
00391         return 6;
00392     }
00393     switch (type)
00394     {
00395         case FIELD_TYPE_NUMERIC:
00396         {
00397             is_negative = FALSE;
00398             if (temp_val < 0)
00399                 is_negative = TRUE;
00400             is_percent = FALSE;
00401             is_currency = FALSE;
00402             switch (formatting)
00403             {
00404             case 0:
00405                 {
00406 //                  use_for_comma = ',';
00407                     break;
00408                 }
00409             case 1:
00410                 {
00411 //                  use_for_comma = '.';
00412 //                  use_for_decimal = ',';
00413                     break;
00414                 }
00416             case 2:
00417                 break;
00418             case 3:
00419                 {
00420 //                  use_for_decimal = ',';
00421                     break;
00422                 }
00423             case 4:
00424                 {
00425 //                  use_for_currency = '$';
00426 //                  use_for_comma = ',';
00427                     break;
00428                 }
00429             case 5:
00430                 {
00431 //                  use_for_comma = ',';
00432 //                  is_percent = TRUE;
00433                     break;
00434                 }
00435                 /* this would be case 6 */
00436             default:
00437                 {
00438 //                  use_for_comma = '.';
00439 //                  use_for_decimal = ',';
00440                     is_percent = TRUE;
00441                 }
00442             }
00443         }
00444         if (is_percent)
00445             temp_val = temp_val * 100;
00446         switch (dec_places)
00447         {
00448             case 0:
00449             {
00450                 texti = g_strdup_printf ("%.0f", temp_val);
00451                 break;
00452             }
00453             case 1:
00454             {
00455                 texti = g_strdup_printf ("%.1f", temp_val);
00456                 break;
00457             }
00458             case 2:
00459             {
00460                 texti = g_strdup_printf ("%.2f", temp_val);
00461                 break;
00462             }
00463             case 3:
00464             {
00465                 texti = g_strdup_printf ("%.3f", temp_val);
00466                 break;
00467             }
00468             case 4:
00469             {
00470                 texti = g_strdup_printf ("%.4f", temp_val);
00471                 break;
00472             }
00473             case 5:
00474             {
00475                 texti = g_strdup_printf ("%.5f", temp_val);
00476                 break;
00477             }
00478             case 6:
00479             {
00480                 texti = g_strdup_printf ("%.6f", temp_val);
00481                 break;
00482             }
00483             case 7:
00484             {
00485                 texti = g_strdup_printf ("%.7f", temp_val);
00486                 break;
00487             }
00488             case 8:
00489             {
00490                 texti = g_strdup_printf ("%.8f", temp_val);
00491                 break;
00492             }
00493             /* this would be case 9 */
00494             default:
00495             {
00496                 texti = g_strdup_printf ("%.9f", temp_val);
00497                 break;
00498             }
00499         }
00500 
00501         /* now count the digits before the decimal place or the end */
00502 /*      if (use_for_comma)
00503             for (inx = 0; inx < 40; inx++)
00504             {
00505                 if (texti[inx] >= '0' && texti[inx] <= '9')
00506                     digits_so_far++;
00507                 else if (!texti[inx] || texti[inx] == '.')
00508                     break;
00509             }
00510 */
00511         /* have counted places in front of decimal.  Now set
00512            up counter of how many digits to skip before inserting
00513            a comma */
00514 /*      digits_so_far %= 3;
00515         if (!digits_so_far)
00516             digits_so_far = 3;
00517 */
00518         /* start formatting output */
00519 /*      outx = 0;
00520         if (use_for_currency)
00521         {
00522             if (is_negative)
00523                 texto[outx++] = '(';
00524             texto[outx++] = use_for_currency;
00525         }
00526         else if (is_negative)
00527             texto[outx++] = '-';
00528         for (inx = 0; inx < 40; inx++)
00529         {
00530             if (texti[inx] >= '0' && texti[inx] <= '9')
00531             {
00532                 if (use_for_comma && !digits_so_far)
00533                 {
00534                     texto[outx++] = use_for_comma;
00535                     digits_so_far = 3;
00536                 }
00537                 texto[outx++] = texti[inx];
00538                 digits_so_far--;
00539             }
00540             else if (texti[inx] == '.')
00541             {
00542 */              /* turn off commas past decimal point */
00543 /*              use_for_comma = '\0';
00544                 texto[outx++] = use_for_decimal;
00545             }
00546             else if (!texti[inx])
00547                 break;
00548         }
00549 */
00550         /* finished moving everything.  Put percent or minus on end */
00551 /*      if (use_for_currency && is_negative)
00552             texto[outx++] = ')';
00553         if (is_percent)
00554             texto[outx++] = '%';
00555         texto[outx] = '\0';*/
00556         texto = texti;
00557         return 0;
00558         break;                  /* end of FIELD_TYPE_NUMERIC */
00559 
00560         case FIELD_TYPE_DATE:
00561         {
00562             GDate * gd;
00563             const gchar * fmt;
00564             fmt = convert_old_df (formatting);
00565             year = (gint) temp_val / 10000;
00566             month = (gint) temp_val / 100 % 100;
00567             day = (gint) temp_val % 100;
00568             if (g_date_valid_dmy (day, month, year))
00569             {
00570                 gd = g_date_new_dmy (day, month, year);
00571                 strcpy (texto, display_date (gd, fmt));
00572                 return strlen (texto);
00573             }
00574             return 0;
00575             break;
00576         }
00577         /* FIELD_TYPE_TIME */
00578         default:
00579         {
00580             hour = temp_val / 60;
00581             min = (gint) temp_val % 60;
00582             if (!formatting)
00583             {                   /* 0 is 7:15 PM */
00584                 if (!hour)
00585                     hour = 12;
00586                 if (hour > 12)
00587                     hour -= 12;
00588                 if (temp_val > 719) /* half a day */
00589                     return (sprintf (texto, "%u:%u%u PM", hour, min / 10,
00590                             min % 10));
00591                 else
00592                     return (sprintf (texto, "%u:%u%u AM", hour, min / 10,
00593                             min % 10));
00594             }
00595 
00596             if (formatting == 1)
00597                 return (sprintf (texto, "%u%u:%u%u", hour / 10, hour % 10,
00598                         min / 10, min % 10));
00599 
00600             /* all that remains is 18.00 */
00601             return (sprintf (texto, "%u.%u%u", hour, min / 10, min % 10));
00602             break;
00603         }
00604     }
00605     return 0;
00606 }                               /* end of d2qls */

gchar* display_date ( GDate *  gd,
const gchar *  fmt 
)

Display dates using old and new types.

Parameters:
gd A valid GDate containing the date to display.
df An old style QlDateFormat or zero.
fmt A new style strftime-compatible format string or NULL.
When using an old style QlDateFormat, pass a NULL fmt string.

When using a new style format string, df is ignored.

Returns:
A newly allocated string containing the formatted date or NULL on error.
Bug:
replace with QofDate

Definition at line 121 of file main.c.

00122 {
00123     gchar buf[MAX_DATE_BUFFER];
00124     struct tm tm;
00125     gsize len;
00126 
00127     g_return_val_if_fail (g_date_valid (gd), NULL);
00128     g_return_val_if_fail (fmt, NULL);
00129     buf[0] = '\1';
00130     g_date_to_struct_tm (gd, &tm);
00131     len  = strftime (buf, MAX_DATE_BUFFER, fmt, &tm);
00132     if (len == 0 && buf[0] != '\0')
00133         return NULL;
00134     return g_strdup (buf);
00135 }

gchar* display_time ( GTimeVal *  gt,
const gchar *  fmt 
)

Bug:
replace with QofTime

Definition at line 139 of file main.c.

00140 {
00141     gchar buf[MAX_DATE_BUFFER];
00142     struct tm tm;
00143     gsize len;
00144 
00145     g_return_val_if_fail (gt, NULL);
00146     g_return_val_if_fail (fmt, NULL);
00147     buf[0] = '\1';
00148     tm = *localtime_r (&gt->tv_sec, &tm);
00149     len  = strftime (buf, MAX_DATE_BUFFER, fmt, &tm);
00150     if (len == 0 && buf[0] != '\0')
00151         return NULL;
00152     return g_strdup (buf);
00153 }

void front_is_changed ( QlTabData tab  ) 

notebook-aware dirty flag

Todo:
Rename function to indicate the move away from a static 'front' to a notebook tab, as used internally.

Definition at line 629 of file main.c.

00630 {
00631     if (tab->file->changed)
00632         return;
00633     tab->file->changed = TRUE;
00634     dim_list_file_menu (tab->qlc);
00635 }

void get_window_size_loc ( GtkWidget *  win  ) 

Save the x and y and height and width of window

Todo:
retain for next session using GConf

Definition at line 640 of file main.c.

00641 {
00642     gint x, y;
00643     QlContext * qlc;
00644     QlTabData * tab;
00645 
00646     qlc = ql_get_context (GTK_WIDGET(win));
00647     tab = ql_get_tabdata (qlc);
00648 
00649     tab->view->width = win->allocation.width;
00650     tab->view->height = win->allocation.height;
00651     gdk_window_get_deskrelative_origin (win->window, &x, &y);
00652     tab->view->x = x;
00653     tab->view->y = y;
00654 }

void level2_error ( QlTabData tab,
gchar *  message 
)

Error dialog box when there's already a dialogue on the screen, and it has to stay

Bug:
pointless function.

Definition at line 677 of file main.c.

00678 {
00679     GtkWidget * dlg;
00680 
00681     dlg = gtk_message_dialog_new (GTK_WINDOW(tab->qlc->parent),
00682         GTK_DIALOG_DESTROY_WITH_PARENT,
00683         GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
00684         "%s", message);
00685     gtk_dialog_run (GTK_DIALOG (dlg));
00686     gtk_widget_destroy (dlg);
00687 }                               /* level2_error */

void make_basic_dialog1 ( void   ) 

Todo:
replace with custom dialog functions

Definition at line 691 of file main.c.

00692 {
00693     GtkWidget * dialog1_win;
00694     dialog1_win = gtk_dialog_new ();
00695     gtk_window_set_modal (GTK_WINDOW (dialog1_win), TRUE);
00696     gtk_window_set_position (GTK_WINDOW (dialog1_win), GTK_WIN_POS_CENTER);
00697     gtk_window_set_resizable (GTK_WINDOW (dialog1_win), TRUE);
00698     gtk_container_set_border_width (GTK_CONTAINER (dialog1_win), 5);
00699 }

GDate* parse_date ( const gchar *  string,
const gchar *  format 
)

Parse an incoming date string - any type.

Tries to parse any date string (time values are not supported) to create a GDate.

Parameters:
string A user-specified or QuickList file date string.
Returns:
a valid GDate containing the parsed date or NULL on error.
Parse an incoming date string - any type.

Since:
0.9.0
Due to be extended further with QofDate from the Query Object Framework but currently using GDate.

Bug:
improve this handling with QofDate

Definition at line 163 of file main.c.

00164 {
00165     GDate * gd;
00166     g_return_val_if_fail (string, NULL);
00167     if (strlen (string) >= MAX_DATE_BUFFER)
00168         return NULL;
00169     gd = g_date_new ();
00170     g_date_set_parse (gd, string);
00171     if (g_date_valid (gd))
00172         return gd;
00173     else
00174     {
00176         const gchar *cp;
00177         struct tm tm;
00178         time_t now;
00179         now = time (NULL);
00180         gmtime_r (&now, &tm);
00181         cp = strptime (string, format, &tm);
00182         g_date_set_dmy (gd, tm.tm_mday, tm.tm_mon + 1, tm.tm_year);
00183         return gd;
00184     }
00185 }

QlContext* ql_context_init ( void   ) 

initialise the context

initialise a table of notebook tab data

Definition at line 111 of file dialog_initial.c.

00112 {
00113     QlContext * qlc;
00114 
00115     qlc = g_new0 (QlContext, 1);
00116     qlc->tab_table = g_hash_table_new (g_direct_hash, g_direct_equal);
00117     return qlc;
00118 }

gdouble qls2d ( const gchar *  input,
gint  type,
gint  formatting 
)

converts a quicklist string (1,234.56) to double.

Bug:
Have to check for NULL and newlines at end of line because of reading input files.
Todo:
replace with QOF/GLib functions.

Bug:
default format is day/month/year
parse_date is locale sensitive, default was not.

Bug:
another failing comparison

Definition at line 708 of file main.c.

00709 {
00710     gdouble temp_double;
00711     gint inx;
00712 
00713     /* these are for time conversion */
00714     gchar before_char[15];
00715     gint beforex;
00716     gchar after_char[15];
00717     gint afterx;
00718     gboolean got_sep;
00719     gboolean got_pm;
00720     gboolean got_am;
00721 
00722     if (!input || !input[0])
00723         return HUGE_VAL;
00724     for (inx = 0; input[inx] == ' '; inx++);
00725     if (!input[inx])
00726         return HUGE_VAL;
00727 
00728     if (type == FIELD_TYPE_NUMERIC)
00729     {
00730         gchar *tail;
00731 
00732         temp_double = strtod (input, &tail);
00733         if (errno)
00734             return HUGE_VAL;
00735         return temp_double;
00736     }
00737     else if (type == FIELD_TYPE_DATE)
00738     {
00739         GDate * gd;
00740         GDateDay day = 20;
00741         GDateMonth month = 3;
00742         GDateYear year = 2004;
00743         gdouble retval;
00744 
00748         gd = parse_date (input, convert_old_df (formatting));
00749         if (!gd)
00750         {
00751             fprintf (stderr, "null gdate\n");
00752             fprintf (stderr, "format=%s\n",
00753                 convert_old_df (formatting));
00754             retval = year * 10000 + month * 100 + day;
00755             fprintf (stderr, "val=%f\n", retval);
00756             return retval;
00757         }
00758         if (g_date_valid (gd))
00759         {
00760             day = g_date_get_day (gd);
00761             month = g_date_get_month (gd);
00762             year = g_date_get_year (gd);
00763         }
00764         retval = year * 10000 + month * 100 + day;
00765     return retval;
00766     }
00767 
00768     else
00769     {
00770         /* this would be FIELD_TYPE_TIME */
00771         beforex = afterx = 0;
00772         got_sep = got_pm = got_am = FALSE;
00773         for (; inx < 15; inx++)
00774         {
00775             if (input[inx] >= '0' && input[inx] <= '9')
00776             {
00777                 if (got_sep)
00778                     after_char[afterx++] = input[inx];
00779                 else
00780                     before_char[beforex++] = input[inx];
00781             }
00782             /* for efficient typists */
00783             else if (input[inx] == ':' || input[inx] == ';'
00784                 || input[inx] == '.')
00785                 got_sep = TRUE;
00786             else if (input[inx] == ' ')
00787             {
00788                 if (beforex && !afterx)
00789                     got_sep = TRUE;
00790             }
00791             else if ((input[inx] == 'P' || input[inx] == 'p')
00792                 && !got_am && !got_pm)
00793                 got_pm = TRUE;
00794             else if ((input[inx] == 'A' || input[inx] == 'a')
00795                 && !got_am && !got_pm)
00796                 got_am = TRUE;
00797             else if (input[inx] == 'm' || input[inx] == 'M');
00798             else if (input[inx] < ' ')  /* end of string */
00799                 break;
00800             else
00801                 return HUGE_VAL;    /* invalid characters */
00802         }
00803         /* wrap up the time conversion */
00804         if (!beforex)
00805             return HUGE_VAL;    /* ie, no data at all */
00806         before_char[beforex] = '\0';
00807         temp_double = atof (before_char) * 60;
00809         if ((glong)temp_double == 720   /* 12:00 */
00810             && got_am)
00811             temp_double = 0;
00812         if (afterx)
00813         {
00814             after_char[afterx] = '\0';
00815             temp_double += atof (after_char);
00816         }
00817         /* for 4:00 pm type formatting, change an entry of 4 to 4:00 pm */
00818         if (got_pm && temp_double < 720)
00819             temp_double += 720; /* 720 minutes is half a day */
00820         if (!got_am && temp_double < 419 && !formatting)
00821             temp_double += 720; /* if 1:00 to 6:59 make it pm by default */
00822         if (temp_double < 1440)
00823             return temp_double;
00824     }
00825     return HUGE_VAL;
00826 }                               /* end of qls2d */

void reset_col_to_field ( QlTabData tab  ) 

Resets the table point at fields from columns

Definition at line 830 of file main.c.

00831 {
00832     gint fieldx;
00833     gint colx;
00834     QlFieldInfo * field;
00835     for (fieldx = 0; fieldx <= tab->file->last_field; fieldx++)
00836     {
00837         field = ql_get_fieldinfo (tab, fieldx);
00838         if (!field)
00839             continue;
00840         colx = field->sheet_column;
00841         tab->file->col_to_field[colx] = fieldx;
00842     }
00843 }

void set_window_size_loc ( GtkWidget *  win  ) 

Force the size of the window we just opened

Definition at line 847 of file main.c.

00848 {
00849     QlContext * qlc;
00850     QlTabData * tab;
00851 
00852     qlc = ql_get_context (GTK_WIDGET(win));
00853     tab = ql_get_tabdata (qlc);
00854     gtk_widget_set_size_request (win, tab->view->width, tab->view->height);
00855 }


Generated on Mon Jan 28 22:02:11 2008 for quicklist by  doxygen 1.5.4