Definition in file main.c.
#include "config.h"
#include <errno.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <ctype.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <gtkextra/gtksheet.h>
#include <libgnomevfs/gnome-vfs.h>
#include "types.h"
#include "dialog_initial.h"
#include "dim_list_menu.h"
#include "edit.h"
#include "filein.h"
#include "fileout.h"
#include "main.h"
Go to the source code of this file.
Functions | |
const gchar * | convert_old_df (QlDateFormat df) |
convert old quicklist date formats to new | |
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) |
general purpose date parser | |
void | close_dlg (GtkWidget G_GNUC_UNUSED *w, gpointer data) |
int | main (int argc, char **argv) |
void | add1row (QlTabData *tab) |
void | big_draw_start (QlTabData *tab) |
void | big_draw_end (QlTabData *tab) |
gint | check_entry (QlTabData *tab, gchar *entry) |
gboolean | check_if_changed (QlTabData *tab) |
gint | d2qls (gchar *texto, gdouble input, QlFieldType type, QlDateFormat formatting, gint dec_places) |
old compatibility function | |
void | connect_signals (QlTabData *tab) |
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) |
gboolean check_if_changed | ( | QlTabData * | tab | ) |
<
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 | ) |
convert old quicklist date formats to new
compatibility function
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.
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.
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 | |||
) |
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 (>->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
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
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
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 | ) |
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 | |||
) |
general purpose date parser
Parse an incoming date string - any type.
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 }
gdouble qls2d | ( | const gchar * | input, | |
gint | type, | |||
gint | formatting | |||
) |
converts a quicklist string (1,234.56) to double.
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 }