void dialog_ok(GnomeDialog *dialog,gint id,gpointer data) { gnome_dialog_close(dialog); }
void on_connectdbok_clicked(GtkWidget *widget, gpointer user_data) { gchar *host; gchar *user; gchar *password; gchar *dbname; gchar dbquery[200]; gchar dbstatus[1000]; int broken,found; xmlNodePtr node; host=gtk_entry_get_text((GtkEntry *)gnome_entry_gtk_entry(connectdb_host)); user=gtk_entry_get_text((GtkEntry *)gnome_entry_gtk_entry(connectdb_user)); password=gtk_entry_get_text(connectdb_password); dbname=gtk_entry_get_text((GtkEntry *)gnome_entry_gtk_entry(connectdb_database)); broken=FALSE; mysql=mysql_init(NULL); if (!mysql_real_connect(mysql,host,user,password,NULL,0,NULL,0)) { error_dialog("Could not connect to Database"); fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); mysql_close(mysql); mysql=NULL; } else { sprintf(dbquery,"use %s",dbname); mysql_query(mysql,dbquery); if (mysql_errno(mysql)!=0) { switch (ok_cancel_dialog("The database does not exist.\nCreate a new one?")) { case 0: g_message("Creating new Database %s.\n",dbname); sprintf(dbquery,"create database %s",dbname); if (mysql_query(mysql,dbquery)!=0) { fprintf(stderr, "Failed to create database: Error: %s\n", mysql_error(mysql)); } sprintf(dbquery,"use %s",dbname); if (mysql_query(mysql,dbquery)!=0) { fprintf(stderr, "Failed to use database: Error: %s\n", mysql_error(mysql)); } break; case 1: broken=TRUE; break; default: broken=TRUE; break; } } if (broken==FALSE) { sprintf(dbquery,"create table _TableNames (Name Text,TName Text,Comment Text)"); mysql_query(mysql,dbquery); name_cache=g_hash_table_new(g_str_hash,g_str_equal); tname_cache=g_hash_table_new(g_str_hash,g_str_equal); sprintf(dbstatus,"Database: %s\nuser: %s\nhost: %s",dbname,user,host); gtk_label_set_text(database_status_label,dbstatus); // ------------------------------- found=FALSE; node=global_configs_doc->children; while (node) { if (strcmp(node->name,"configurations")==0) { node=node->children; break; } node=node->next; } if (node) { while (node) { if (strcmp(node->name,"dbconfig")==0) { if (strcmp(xmlGetProp(node,"dbname"),dbname)==0) { found=TRUE; db_global_configs_node=node; break; } } node=node->next; } } if (!found) { db_global_configs_node=xmlNewNode(NULL,"dbconfig"); xmlSetProp(db_global_configs_node,"dbname",dbname); xmlAddChild(global_configs_doc->children,db_global_configs_node); } // --------------------------------- found=FALSE; node=local_configs_doc->children; while (node) { if (strcmp(node->name,"configurations")==0) { node=node->children; break; } node=node->next; } if (node) { while (node) { if (strcmp(node->name,"dbconfig")==0) { if (strcmp(xmlGetProp(node,"dbname"),dbname)==0) { found=TRUE; db_local_configs_node=node; break; } } node=node->next; } } if (!found) { db_local_configs_node=xmlNewNode(NULL,"dbconfig"); xmlSetProp(db_local_configs_node,"dbname",xmlEncodeEntitiesReentrant(local_configs_doc,dbname)); xmlAddChild(local_configs_doc->children,db_local_configs_node); } else { gtk_widget_set_sensitive(GTK_WIDGET(connect_button),FALSE); gtk_widget_set_sensitive(GTK_WIDGET(disconnect_button),TRUE); gtk_widget_set_sensitive(GTK_WIDGET(add_category_button),TRUE); } // --------------------------------- gnome_dialog_close(connectdb_dialog); update_tablelist(mysql); } } }
void ghack_settings_dialog() { int i; static GtkWidget* dialog; static GtkWidget* swin; static GtkWidget* frame1; dialog = gnome_dialog_new (_("GnomeHack Settings"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); gnome_dialog_close_hides (GNOME_DIALOG (dialog), FALSE); gtk_signal_connect (GTK_OBJECT (dialog), "key_press_event", GTK_SIGNAL_FUNC (opt_sel_key_hit), tilesets ); frame1 = gtk_frame_new (_("Choose one of the following tilesets:")); gtk_object_set_data (GTK_OBJECT (dialog), "frame1", frame1); gtk_widget_show (frame1); gtk_container_border_width (GTK_CONTAINER (frame1), 3); swin = gtk_scrolled_window_new (NULL, NULL); clist = gtk_clist_new (2); gtk_clist_column_titles_hide (GTK_CLIST (clist)); gtk_widget_set_usize (GTK_WIDGET (clist), 100, 180); gtk_container_add (GTK_CONTAINER (swin), clist); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_signal_connect (GTK_OBJECT (clist), "select_row", GTK_SIGNAL_FUNC (opt_sel_row_selected), NULL ); gtk_container_add (GTK_CONTAINER (frame1), swin); gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG (dialog)->vbox), frame1); /* Add the tilesets into the list here... */ for (i=0; i < no_tilesets; i++) { gchar accelBuf[BUFSZ]; const char *text[3]={accelBuf, tilesets[i].name,NULL}; if ((tilesets[i].flags & ~TILESET_TRANSPARENT) != 0) continue; /* Unsupported flag set */ sprintf( accelBuf, "%c ", tolower(tilesets[i].name[0])); gtk_clist_insert (GTK_CLIST (clist), i, (char**)text); } gtk_clist_columns_autosize (GTK_CLIST (clist)); gtk_widget_show_all (swin); /* Center the dialog over over parent */ gnome_dialog_set_default( GNOME_DIALOG(dialog), 0); gtk_window_set_modal( GTK_WINDOW(dialog), TRUE); gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (ghack_get_main_window ()) ); /* Run the dialog -- returning whichever button was pressed */ i = gnome_dialog_run (GNOME_DIALOG (dialog)); gnome_dialog_close (GNOME_DIALOG (dialog)); /* They hit Quit or error */ if (i != 0 ) { return; } if (gn_tileset < no_tilesets) { if (tilesets[gn_tileset].file[0] != '/') { char *path; path = (char *)alloc(strlen(TILESETDIR) + strlen(tilesets[gn_tileset].file) + 2); sprintf(path, TILESETDIR "/%s", tilesets[gn_tileset].file); ghack_free_glyphs(); if (ghack_init_glyphs(path)) g_error ("ERROR: Could not initialize glyphs.\n"); free(path); } else { ghack_free_glyphs(); if (ghack_init_glyphs(tilesets[gn_tileset].file)) g_error ("ERROR: Could not initialize glyphs.\n"); } ghack_reinit_map_window(); } else { /* This shouldn't happen */ g_warning("This shouldn't happen\n"); } }
void on_connectdbcancel_clicked(GtkWidget *widget, gpointer user_data) { gnome_dialog_close(connectdb_dialog); }