00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "../config.h"
00023
00024 #include <string.h>
00025
00026 #include "buf.h"
00027 #include "db_connect_dlg.h"
00028 #include "dialogs.h"
00029 #include "gui.h"
00030 #include "guiapi.h"
00031 #include "interface.h"
00032 #include "luaif.h"
00033 #include "queries.h"
00034 #include "query_import_dlg.h"
00035 #include "query_save_dlg.h"
00036 #include "support.h"
00037 #include "tables.h"
00038 #include "workspace.h"
00039
00040 extern void disconnect_callback(void *data);
00041
00042 void on_mainWindow_destroy(GtkObject * object, gpointer user_data)
00043 {
00044 DBConnection *conn = gui_get_connection();
00045 if (conn != NULL)
00046 disconnect_callback(user_data);
00047
00048 gtk_main_quit();
00049 }
00050
00052 void on_queryLoad_activate(GtkMenuItem * menuitem, gpointer user_data)
00053 {
00054 query_add();
00055 query_import();
00056 }
00057
00059 void on_queryImport_activate(GtkMenuItem * menuitem, gpointer user_data)
00060 {
00061 query_import();
00062 }
00063
00065 void on_querySave_activate(GtkMenuItem * menuitem, gpointer user_data)
00066 {
00067 query_save(NULL);
00068 }
00069
00071 void on_querySaveAs_activate(GtkMenuItem * menuitem, gpointer user_data)
00072 {
00073 query_save_as(NULL);
00074 }
00075
00076 void on_resultExport_activate(GtkMenuItem * menuitem, gpointer user_data)
00077 {
00078
00079 }
00080
00081 void on_quit_activate(GtkMenuItem * menuitem, gpointer user_data)
00082 {
00083 if (gui_connection_ok())
00084 disconnect_callback(user_data);
00085
00086 gtk_main_quit();
00087 }
00088
00089
00093 void on_databaseConnect_activate(GtkMenuItem * menuitem, gpointer user_data)
00094 {
00095 db_connect_dialog_show();
00096 }
00097
00098
00100 void on_databaseDisconnect_activate(GtkMenuItem * menuitem,
00101 gpointer user_data)
00102 {
00104 #define SURE_S " Are you sure you want \n to disconnect from database %s ? "
00105 GtkWidget *dialog;
00106 DBConnection *conn = gui_get_connection();
00107 ABuf *buf = buf_new(strlen(SURE_S) + strlen(conn->DBget_db_name(conn)));
00108 if (!buf) {
00109 g_warning("disconnect() could not allocate memory for a buffer\n");
00110 return;
00111 }
00112
00113 if (conn == NULL) {
00114 display_error("Internal error",
00115 "Internal error : trying to disconnect "
00116 "with no current connection");
00117 return;
00118 }
00119
00120 snprintf(buf->b_dat, buf->b_len, SURE_S, conn->DBget_db_name(conn));
00121
00122 dialog =
00123 create_standard_dialog("Disconnect", buf->b_dat, 2, NULL, "Ok",
00124 disconnect_callback, "Cancel", NULL, NULL);
00125 gtk_widget_show(dialog);
00126 buf_free(buf);
00127 }
00128
00130 void on_querySend_activate(GtkMenuItem * menuitem, gpointer user_data)
00131 {
00132 gui_send_query();
00133 }
00134
00136 void on_queryNew_activate(GtkMenuItem * menuitem, gpointer user_data)
00137 {
00138 query_add();
00139 }
00140
00144 void on_queryClear_activate(GtkMenuItem * menuitem, gpointer user_data)
00145 {
00146 query_clear();
00147 }
00148
00150 void on_queryClose_activate(GtkMenuItem * menuitem, gpointer user_data)
00151 {
00152 int nb_query;
00153
00154 nb_query = query_close();
00155
00156 if (nb_query == 0) {
00157 update_button_sensitivity();
00158 }
00159 }
00160
00162 void on_tableRefresh_activate(GtkMenuItem * menuitem, gpointer user_data)
00163 {
00164 tables_connection_closed();
00165 tables_new_connection();
00166 }
00167
00168 void on_configOptions_activate(GtkMenuItem * menuitem, gpointer user_data)
00169 {
00170
00171 }
00172
00173 void on_helpAbout_activate(GtkMenuItem * menuitem, gpointer user_data)
00174 {
00176 #define VERSION_S "\n " APPNAME " Version " VERSION "\n " \
00177 "Configured " CONFDATE "\n"
00178 ABuf *buf = NULL;
00179 GtkLabel *lbl;
00180
00181 if (aboutDialog == NULL) {
00182 aboutDialog = create_aboutDlg();
00183 buf = buf_strcpy(NULL, "");
00184
00185 #ifdef USE_POSTGRESQL
00186 buf = buf_strcat(buf, " PostgreSQL driver Installed \n");
00187 #endif
00188 #ifdef USE_MYSQL
00189 buf = buf_strcat(buf, " MySQL driver installed \n");
00190 #endif
00191 #ifdef USE_XPATH
00192 buf = buf_strcat(buf, " XPath driver installed \n");
00193 #endif
00194
00195 lbl =
00196 GTK_LABEL(lookup_widget
00197 (GTK_WIDGET(aboutDialog), "aboutVersionLabel"));
00198 if (lbl != NULL)
00199 gtk_label_set_text(GTK_LABEL(lbl), VERSION_S);
00200
00201 lbl =
00202 GTK_LABEL(lookup_widget
00203 (GTK_WIDGET(aboutDialog), "aboutDriversLabel"));
00204 if (lbl != NULL)
00205 gtk_label_set_text(GTK_LABEL(lbl), buf->b_dat);
00206
00207 buf_free(buf);
00208 }
00209 gtk_widget_show(aboutDialog);
00210 }
00211
00212 void on_fileQuit_activate(GtkMenuItem * menuitem, gpointer user_data)
00213 {
00214 if (gui_connection_ok())
00215 disconnect_callback(user_data);
00216
00217 gtk_main_quit();
00218 }
00219
00223 void on_querySaveDlgOkBtn_clicked(GtkButton * button, gpointer user_data)
00224 {
00225 char *filename;
00226 if (querySaveData.query == NULL)
00227 querySaveData.query = query_get_current();
00228
00229 if (querySaveData.qdata == NULL)
00230 querySaveData.qdata = query_get_querydata(querySaveData.query);
00231
00232
00233 filename =
00234 gtk_file_selection_get_filename(GTK_FILE_SELECTION(querySaveDialog));
00235 querydata_set_filename(querySaveData.qdata, filename);
00236 query_save_to_file(querySaveData.query, filename);
00237 query_save_dialog_hide();
00238 }
00239
00243 void on_querySaveDlgCancelBtn_clicked(GtkButton * button, gpointer user_data)
00244 {
00245 query_save_dialog_hide();
00246 }
00247
00251 void on_queryImportDlgOkBtn_clicked(GtkButton * button, gpointer user_data)
00252 {
00253 char *filename, *raw_filename;
00254 ABuf *buf = buf_new(256);
00255 FILE *fp;
00256 GtkWidget *cq = query_get_current();
00257 QueryData *qd = gtk_object_get_data(GTK_OBJECT(cq), QDATA_KEY);
00258
00259 query_clear();
00260
00261
00262 filename =
00263 gtk_file_selection_get_filename(GTK_FILE_SELECTION
00264 (queryImportDialog));
00265 raw_filename =
00266 gtk_entry_get_text(GTK_ENTRY(queryImportDialog->selection_entry));
00267
00268 gtk_text_freeze(GTK_TEXT(cq));
00269 fp = fopen(filename, "r");
00270 if (fp != NULL) {
00271 while (fgets(buf->b_dat, buf->b_len, fp) != NULL)
00272 gtk_text_insert(GTK_TEXT(cq), NULL, NULL, NULL, buf->b_dat, -1);
00273
00274 fclose(fp);
00275 querydata_set_filename(qd, filename);
00276 querydata_set_unchanged(qd);
00277 gui_set_query_name(filename);
00278 }
00279 gtk_text_thaw(GTK_TEXT(cq));
00280 buf_free(buf);
00281 query_import_dialog_hide();
00282 }
00283
00287 void on_queryImportDlgCancelBtn_clicked(GtkButton * button,
00288 gpointer user_data)
00289 {
00290 query_import_dialog_hide();
00291 }
00292
00293 void on_aboutOKBtn_clicked(GtkButton * button, gpointer user_data)
00294 {
00295 gtk_widget_hide(aboutDialog);
00296 }
00297
00298 void on_scriptLoadDlgOKBtn_clicked(GtkButton * button, gpointer user_data)
00299 {
00300 #ifdef USE_LUA
00301 char *filename;
00302 gtk_widget_hide(GTK_WIDGET(scriptOpenDialog));
00303
00304
00305 filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(scriptOpenDialog));
00306 luaif_runfile(filename);
00307 #endif
00308 }
00309
00310 void on_scriptLoadDlgCancelBtn_clicked(GtkButton * button, gpointer user_data)
00311 {
00312 gtk_widget_hide(GTK_WIDGET(scriptOpenDialog));
00313 }
00314
00315 void on_scriptSaveDlgOKBtn_clicked(GtkButton *button, gpointer user_data)
00316 {
00317 #ifdef USE_LUA
00318 char *filename;
00319 gtk_widget_hide(GTK_WIDGET(scriptSaveDialog));
00320
00321
00322 filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(scriptSaveDialog));
00323 ws_save_file(filename);
00324 #endif
00325 }
00326
00327 void on_scriptSaveDlgCancelBtn_clicked(GtkButton *button, gpointer user_data)
00328 {
00329 gtk_widget_hide(GTK_WIDGET(scriptSaveDialog));
00330 }
00331
00332 void on_scriptSaveAs_activate(GtkMenuItem *menuitem, gpointer user_data)
00333 {
00334 if (scriptSaveDialog == NULL) {
00335 scriptSaveDialog = create_scriptSaveDlg();
00336
00337 if (scriptSaveDialog == NULL) {
00338 g_warning("Could not initialise Script Save Dialog\n");
00339 return;
00340 }
00341 else {
00342 gtk_file_selection_complete(GTK_FILE_SELECTION(scriptSaveDialog), "*.lua");
00343 }
00344 }
00345
00346 gtk_widget_show(GTK_WIDGET(scriptSaveDialog));
00347 }
00348
00349 void on_fileScriptLoad_activate(GtkMenuItem *menuitem, gpointer user_data)
00350 {
00351 if (scriptOpenDialog == NULL) {
00352 scriptOpenDialog = create_scriptOpenDlg();
00353
00354 if (scriptOpenDialog == NULL) {
00355 g_warning("Could not initialise Script Open Dialog\n");
00356 return;
00357 }
00358 else {
00359 gtk_file_selection_complete(GTK_FILE_SELECTION(scriptOpenDialog), "*.lua");
00360 }
00361 }
00362 gtk_widget_show(GTK_WIDGET(scriptOpenDialog));
00363 }