00001 #ifdef HAVE_CONFIG_H
00002 # include <config.h>
00003 #endif
00004
00005 #include <gnome.h>
00006
00007 #include "callbacks.h"
00008 #include "interface.h"
00009 #include "support.h"
00010
00011 #include "fmaps.h"
00012
00013 #include "gtkfmaps.h"
00014
00015 #ifndef LIBPQ_H
00016 # include "libpq-fe.h"
00017 # define LIBPQ_H
00018 #endif
00019
00020
00021 void
00022 FM_Init_MetaData (GtkWidget *metadatawindow)
00023 {
00024 GtkWidget *widget;
00025 static gchar* spatial_rep_type_code0[1]={"none"};
00026 static gchar* spatial_rep_type_code1[1]={"text"};
00027 static gchar* spatial_rep_type_code2[1]={"vector"};
00028 static gchar* spatial_rep_type_code3[1]={"raster"};
00029 static gchar* spatial_rep_type_code4[1]={"image"};
00030
00031 g_return_if_fail(metadatawindow!=NULL);
00032
00033 widget=lookup_widget(metadatawindow,"spatial_rep_type_code");
00034 gtk_clist_append(GTK_CLIST(widget),spatial_rep_type_code0);
00035 gtk_clist_append(GTK_CLIST(widget),spatial_rep_type_code1);
00036 gtk_clist_append(GTK_CLIST(widget),spatial_rep_type_code2);
00037 gtk_clist_append(GTK_CLIST(widget),spatial_rep_type_code3);
00038 gtk_clist_append(GTK_CLIST(widget),spatial_rep_type_code4);
00039
00040 }
00041
00042 void
00043 FM_Display_MetaData (GtkWidget *metadatawindow,
00044 gchar *tablename)
00045 {
00046
00047 gchar *buffer;
00048 PGresult *qryResult;
00049 gint nbtuples;
00050 GtkWidget *widget;
00051 gchar *oid=NULL;
00052 gint i;
00053
00054 g_return_if_fail(metadatawindow!=NULL);
00055
00056
00057 buffer=g_strdup_printf("SELECT OID,* from f_catalogue WHERE meta_file_id='%s' ",tablename);
00058 qryResult = PQexec(conn,buffer);
00059 g_free(buffer);
00060
00061 nbtuples = PQntuples(qryResult);
00062 if (nbtuples>0)
00063 {
00064 buffer = PQgetvalue(qryResult,0,0);
00065 widget=lookup_widget(metadatawindow,"oid");
00066 gtk_entry_set_text(GTK_ENTRY(widget),buffer);
00067 oid=g_strdup(buffer);
00068
00069 buffer = PQgetvalue(qryResult,0,1);
00070 widget=lookup_widget(metadatawindow,"meta_file_id");
00071 gtk_entry_set_text(GTK_ENTRY(widget),buffer);
00072 widget=lookup_widget(metadatawindow,"global_meta_file_id");
00073 gtk_entry_set_text(GTK_ENTRY(widget),buffer);
00074
00075 buffer = PQgetvalue(qryResult,0,2);
00076 widget=lookup_widget(metadatawindow,"meta_parent_id");
00077 gtk_entry_set_text(GTK_ENTRY(widget),buffer);
00078
00079 buffer = PQgetvalue(qryResult,0,3);
00080 widget=lookup_widget(metadatawindow,"title");
00081 gtk_entry_set_text(GTK_ENTRY(widget),buffer);
00082
00083 buffer = PQgetvalue(qryResult,0,4);
00084 widget=lookup_widget(metadatawindow,"edition");
00085 gtk_entry_set_text(GTK_ENTRY(widget),buffer);
00086
00087 buffer = PQgetvalue(qryResult,0,5);
00088 widget=lookup_widget(metadatawindow,"series");
00089 gtk_entry_set_text(GTK_ENTRY(widget),buffer);
00090
00091 buffer = PQgetvalue(qryResult,0,6);
00092 widget=lookup_widget(metadatawindow,"issue_id");
00093 gtk_entry_set_text(GTK_ENTRY(widget),buffer);
00094
00095 }
00096 PQclear(qryResult);
00097
00098
00099
00100 buffer=g_strdup_printf("SELECT OID,* from f_catalogue_spatial_rep_type_code WHERE CID=%s ",oid);
00101 qryResult = PQexec(conn,buffer);
00102 g_free(buffer);
00103
00104 nbtuples = PQntuples(qryResult);
00105 if (nbtuples>0)
00106 {
00107 widget=lookup_widget(metadatawindow,"spatial_rep_type_code");
00108 for (i=0;i<nbtuples;i++)
00109 {
00110 buffer = PQgetvalue(qryResult,i,2);
00111 gtk_clist_select_row(GTK_CLIST(widget),atoi(buffer),0);
00112 }
00113
00114
00115 }
00116 PQclear(qryResult);
00117
00118
00119
00120 g_free(oid);
00121 return;
00122 }
00123
00124 void
00125 FM_Save_MetaData (GtkWidget *metadatawindow)
00126 {
00127 gchar *buffer;
00128 gchar *buffer2;
00129 gchar *text;
00130 PGresult *qryResult;
00131 GtkWidget *widget;
00132 gboolean boid;
00133 gchar *oid;
00134
00135 g_return_if_fail(metadatawindow!=NULL);
00136
00137 widget=lookup_widget(metadatawindow,"oid");
00138 text=gtk_entry_get_text(GTK_ENTRY(widget));
00139
00140 if (strcmp(text,"")==0)
00141 {
00142 boid=FALSE;
00143 } else
00144 {
00145 boid=TRUE;
00146 }
00147 oid=g_strdup(text);
00148
00149 widget=lookup_widget(metadatawindow,"meta_file_id");
00150 text=gtk_entry_get_text(GTK_ENTRY(widget));
00151 if (boid)
00152 {
00153 buffer=g_strdup_printf("meta_file_id = '%s',",text);
00154 } else
00155 {
00156 buffer=g_strdup_printf("'%s',",text);
00157 }
00158
00159 widget=lookup_widget(metadatawindow,"meta_parent_id");
00160 text=gtk_entry_get_text(GTK_ENTRY(widget));
00161 if (boid)
00162 {
00163 buffer2=g_strdup_printf("%s meta_parent_id = '%s',",buffer,text);
00164 } else
00165 {
00166 buffer2=g_strdup_printf("%s'%s',",buffer,text);
00167 }
00168 g_free(buffer);
00169
00170 widget=lookup_widget(metadatawindow,"title");
00171 text=gtk_entry_get_text(GTK_ENTRY(widget));
00172 if (boid)
00173 {
00174 buffer=g_strdup_printf("%s title = '%s',",buffer2,text);
00175 } else
00176 {
00177 buffer=g_strdup_printf("%s'%s',",buffer2,text);
00178 }
00179 g_free(buffer2);
00180
00181 widget=lookup_widget(metadatawindow,"edition");
00182 text=gtk_entry_get_text(GTK_ENTRY(widget));
00183 if (boid)
00184 {
00185 buffer2=g_strdup_printf("%s edition = '%s',",buffer,text);
00186 } else
00187 {
00188 buffer2=g_strdup_printf("%s'%s',",buffer,text);
00189 }
00190 g_free(buffer);
00191
00192 widget=lookup_widget(metadatawindow,"series");
00193 text=gtk_entry_get_text(GTK_ENTRY(widget));
00194 if (boid)
00195 {
00196 buffer=g_strdup_printf("%s series = '%s',",buffer2,text);
00197 } else
00198 {
00199 buffer=g_strdup_printf("%s'%s',",buffer2,text);
00200 }
00201 g_free(buffer2);
00202
00203 widget=lookup_widget(metadatawindow,"issue_id");
00204 text=gtk_entry_get_text(GTK_ENTRY(widget));
00205 if (boid)
00206 {
00207 buffer2=g_strdup_printf("%s issue_id = '%s'",buffer,text);
00208 } else
00209 {
00210 buffer2=g_strdup_printf("%s'%s'",buffer,text);
00211 }
00212 g_free(buffer);
00213
00214 if (boid)
00215 {
00216
00217 buffer=g_strdup_printf("UPDATE f_catalogue SET %s WHERE oid=%s",buffer2,oid);
00218 } else
00219 {
00220 buffer=g_strdup_printf("INSERT INTO f_catalogue (meta_file_id,meta_parent_id,title,edition,series,issue_id) VALUES (%s)",buffer2);
00221 }
00222 qryResult = PQexec(conn,buffer);
00223
00224
00225 if (!(g_str_equal(PQresultErrorMessage(qryResult),"")))
00226 {
00227 g_warning("%s : %s",buffer, PQresultErrorMessage(qryResult));
00228 }
00229
00230 if (!boid)
00231 {
00232 text = (gchar *) PQoidStatus(qryResult);
00233 widget = lookup_widget(metadatawindow,"oid");
00234 gtk_entry_set_text(GTK_ENTRY(widget),text);
00235 }
00236
00237 g_free(buffer);
00238 PQclear(qryResult);
00239
00240 g_free(buffer2);
00241
00242 g_free(oid);
00243
00244 return;
00245 }