From: John Darrington Date: Tue, 12 Jun 2007 01:59:00 +0000 (+0000) Subject: Improved the encapsulation of PsppireCaseFile X-Git-Tag: v0.6.0~429 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c9e32859d6da9505e1904d5b0f95cfd276a734e;p=pspp-builds.git Improved the encapsulation of PsppireCaseFile --- diff --git a/src/ui/gui/psppire-case-file.c b/src/ui/gui/psppire-case-file.c index 9d3e3a14..ee31c013 100644 --- a/src/ui/gui/psppire-case-file.c +++ b/src/ui/gui/psppire-case-file.c @@ -133,7 +133,8 @@ psppire_case_file_finalize (GObject *object) { PsppireCaseFile *cf = PSPPIRE_CASE_FILE (object); - datasheet_destroy (cf->datasheet); + if ( cf->accessible) + datasheet_destroy (cf->datasheet); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -142,6 +143,7 @@ static void psppire_case_file_init (PsppireCaseFile *cf) { cf->datasheet = NULL; + cf->accessible = FALSE; } @@ -152,24 +154,17 @@ psppire_case_file_init (PsppireCaseFile *cf) * Creates a new #PsppireCaseFile. */ PsppireCaseFile* -psppire_case_file_new (void) +psppire_case_file_new (struct casereader *reader) { PsppireCaseFile *cf = g_object_new (G_TYPE_PSPPIRE_CASE_FILE, NULL); - cf->datasheet = datasheet_create (NULL); + cf->datasheet = datasheet_create (reader); + cf->accessible = TRUE; return cf; } -void -psppire_case_file_replace_datasheet (PsppireCaseFile *cf, struct datasheet *ds) -{ - cf->datasheet = ds; -} - - - gboolean psppire_case_file_delete_cases (PsppireCaseFile *cf, gint n_cases, gint first) { @@ -234,6 +229,7 @@ inline gint psppire_case_file_get_case_count (const PsppireCaseFile *cf) { g_return_val_if_fail (cf, FALSE); + g_return_val_if_fail (cf->accessible, FALSE); if ( ! cf->datasheet) return 0; @@ -354,6 +350,7 @@ psppire_case_file_insert_values (PsppireCaseFile *cf, { union value *values; g_return_val_if_fail (cf, FALSE); + g_return_val_if_fail (cf->accessible, FALSE); if ( ! cf->datasheet ) cf->datasheet = datasheet_create (NULL); @@ -377,3 +374,14 @@ psppire_case_file_get_case (const PsppireCaseFile *cf, gint casenum, return datasheet_get_row (cf->datasheet, casenum, c); } + + + +struct casereader * +psppire_case_file_make_reader (PsppireCaseFile *cf) +{ + struct casereader *r = datasheet_make_reader (cf->datasheet); + cf->accessible = FALSE; + return r; +} + diff --git a/src/ui/gui/psppire-case-file.h b/src/ui/gui/psppire-case-file.h index b3fdfcda..f274624f 100644 --- a/src/ui/gui/psppire-case-file.h +++ b/src/ui/gui/psppire-case-file.h @@ -49,14 +49,15 @@ typedef struct _PsppireCaseFile PsppireCaseFile; typedef struct _PsppireCaseFileClass PsppireCaseFileClass; struct ccase; -struct flexifile; -struct casefile; +struct casereader; struct _PsppireCaseFile { GObject parent; + /* */ struct datasheet *datasheet; + gboolean accessible; }; @@ -69,7 +70,7 @@ struct _PsppireCaseFileClass /* -- PsppireCaseFile --- */ GType psppire_case_file_get_type (void); -PsppireCaseFile *psppire_case_file_new (void); +PsppireCaseFile *psppire_case_file_new (struct casereader *); gboolean psppire_case_file_insert_case (PsppireCaseFile *cf, struct ccase *c, gint row); @@ -98,16 +99,12 @@ gboolean psppire_case_file_delete_cases (PsppireCaseFile *cf, gint n_rows, gboolean psppire_case_file_insert_values (PsppireCaseFile *cf, gint n_values, gint before); struct case_ordering; + void psppire_case_file_sort (PsppireCaseFile *cf, struct case_ordering *); gboolean psppire_case_file_get_case (const PsppireCaseFile *cf, gint casenum, struct ccase *c); -void psppire_case_file_replace_datasheet (PsppireCaseFile *, - struct datasheet *); - - - G_END_DECLS #endif /* __PSPPIRE_CASE_FILE_H__ */ diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index d3843177..f711162f 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -373,29 +373,16 @@ psppire_data_store_new (PsppireDict *dict) } - -/** - * psppire_data_store_replace_set_dictionary: - * @data_store: The variable store - * @dict: The dictionary to set - * - * If a dictionary is already associated with the data-store, then it will be - * destroyed. - **/ void -psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *dict) +psppire_data_store_set_case_file (PsppireDataStore *data_store, + PsppireCaseFile *cf) { - data_store->dict = dict; - if ( data_store->case_file) { g_object_unref (data_store->case_file); - data_store->case_file = 0; } - data_store->case_file = psppire_case_file_new (); - - + data_store->case_file = cf; g_signal_connect (data_store->case_file, "cases-deleted", G_CALLBACK (delete_cases_callback), @@ -409,6 +396,22 @@ psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *di g_signal_connect (data_store->case_file, "case-changed", G_CALLBACK (changed_case_callback), data_store); +} + + + +/** + * psppire_data_store_replace_set_dictionary: + * @data_store: The variable store + * @dict: The dictionary to set + * + * If a dictionary is already associated with the data-store, then it will be + * destroyed. + **/ +void +psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *dict) +{ + data_store->dict = dict; g_signal_connect (dict, "variable-inserted", G_CALLBACK (insert_variable_callback), diff --git a/src/ui/gui/psppire-data-store.h b/src/ui/gui/psppire-data-store.h index 1974aed8..9b480c98 100644 --- a/src/ui/gui/psppire-data-store.h +++ b/src/ui/gui/psppire-data-store.h @@ -84,8 +84,11 @@ struct _PsppireDataStoreClass inline GType psppire_data_store_get_type (void) G_GNUC_CONST; PsppireDataStore *psppire_data_store_new (PsppireDict *dict); +void psppire_data_store_set_case_file (PsppireDataStore *data_store, + PsppireCaseFile *cf); + void psppire_data_store_set_dictionary (PsppireDataStore *data_store, - PsppireDict *dict); + PsppireDict *dict); void psppire_data_store_set_font (PsppireDataStore *store, const PangoFontDescription *fd); diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c index d636ab49..06b14887 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -68,10 +68,9 @@ replace_dictionary (struct dictionary *d) static void replace_casereader (struct casereader *s) { - struct datasheet *datasheet = datasheet_create (s); + PsppireCaseFile *pcf = psppire_case_file_new (s); - psppire_case_file_replace_datasheet (the_data_store->case_file, - datasheet); + psppire_data_store_set_case_file (the_data_store, pcf); } void @@ -100,11 +99,12 @@ initialize (void) the_dataset = create_dataset (replace_casereader, replace_dictionary); + + message_dialog_init (the_source_stream); - dictionary = psppire_dict_new_from_dict ( - dataset_dict (the_dataset) - ); + dictionary = psppire_dict_new_from_dict (dataset_dict (the_dataset)); + bind_textdomain_codeset (PACKAGE, "UTF-8"); @@ -113,10 +113,7 @@ initialize (void) the_var_store = psppire_var_store_new (dictionary); the_data_store = psppire_data_store_new (dictionary); - - - proc_set_active_file_data (the_dataset, - datasheet_make_reader (the_data_store->case_file->datasheet)); + replace_casereader (NULL); create_icon_factory ();