|
|
1.1 ! root 1: #include <gtk/gtk.h> ! 2: #include <glade/glade.h> ! 3: ! 4: #include "sbbs.h" ! 5: #include "dirwrap.h" ! 6: ! 7: #include "events.h" ! 8: #include "gtkuseredit.h" ! 9: ! 10: scfg_t cfg; ! 11: user_t user; ! 12: GladeXML *xml; ! 13: int totalusers=0; ! 14: int current_user=0; ! 15: char glade_path[MAX_PATH+1]; ! 16: ! 17: /* Refreshes global variables... ie: Number of users */ ! 18: int refresh_globals(void) ! 19: { ! 20: char str[1024]; ! 21: GtkWidget *cCommandShell; ! 22: GtkWidget *cExternalEditor; ! 23: GtkWidget *cDefaultDownloadProtocol; ! 24: GtkWidget *cTempQWKFileType; ! 25: GtkWidget *w; ! 26: int i; ! 27: ! 28: /* Clear out old combo boxes */ ! 29: cCommandShell=glade_xml_get_widget(xml, "cCommandShell"); ! 30: if(w==NULL) { ! 31: fprintf(stderr,"Cannot get the command shell widget\n"); ! 32: return(-1); ! 33: } ! 34: for(i=0; i<cfg.total_shells; i++) ! 35: gtk_combo_box_remove_text(GTK_COMBO_BOX(cCommandShell), 0); ! 36: cExternalEditor=glade_xml_get_widget(xml, "cExternalEditor"); ! 37: if(w==NULL) { ! 38: fprintf(stderr,"Cannot get the external editor widget\n"); ! 39: return(-1); ! 40: } ! 41: for(i=0; i<cfg.total_xedits; i++) ! 42: gtk_combo_box_remove_text(GTK_COMBO_BOX(cExternalEditor), 0); ! 43: cDefaultDownloadProtocol=glade_xml_get_widget(xml, "cDefaultDownloadProtocol"); ! 44: if(w==NULL) { ! 45: fprintf(stderr,"Cannot get the default download protocol widget\n"); ! 46: return(-1); ! 47: } ! 48: for(i=0; i<cfg.total_prots; i++) ! 49: gtk_combo_box_remove_text(GTK_COMBO_BOX(cDefaultDownloadProtocol), 0); ! 50: cTempQWKFileType=glade_xml_get_widget(xml, "cTempQWKFileType"); ! 51: if(w==NULL) { ! 52: fprintf(stderr,"Cannot get the temp/QWK file type widget\n"); ! 53: return(-1); ! 54: } ! 55: for(i=0; i<cfg.total_fcomps; i++) ! 56: gtk_combo_box_remove_text(GTK_COMBO_BOX(cTempQWKFileType), 0); ! 57: ! 58: /* Read .cfg files here */ ! 59: if(!load_cfg(&cfg, NULL, TRUE, str)) { ! 60: fprintf(stderr,"Cannot load configuration data\n"); ! 61: return(-1); ! 62: } ! 63: ! 64: /* Re-add combobox values */ ! 65: for(i=0; i<cfg.total_shells; i++) ! 66: gtk_combo_box_append_text(GTK_COMBO_BOX(cCommandShell), cfg.shell[i]->name); ! 67: gtk_combo_box_append_text(GTK_COMBO_BOX(cExternalEditor), "Internal Editor"); ! 68: for(i=0; i<cfg.total_xedits; i++) ! 69: gtk_combo_box_append_text(GTK_COMBO_BOX(cExternalEditor), cfg.xedit[i]->name); ! 70: gtk_combo_box_append_text(GTK_COMBO_BOX(cDefaultDownloadProtocol), "Not Specified"); ! 71: for(i=0; i<cfg.total_prots; i++) ! 72: gtk_combo_box_append_text(GTK_COMBO_BOX(cDefaultDownloadProtocol), cfg.prot[i]->name); ! 73: for(i=0; i<cfg.total_fcomps; i++) ! 74: gtk_combo_box_append_text(GTK_COMBO_BOX(cTempQWKFileType), cfg.fcomp[i]->ext); ! 75: ! 76: totalusers=lastuser(&cfg); ! 77: sprintf(str,"of %d",totalusers); ! 78: w=glade_xml_get_widget(xml, "lTotalUsers"); ! 79: if(w==NULL) { ! 80: fprintf(stderr,"Cannot get the total users widget\n"); ! 81: return(-1); ! 82: } ! 83: gtk_label_set_text(GTK_LABEL(w), str); ! 84: ! 85: return(0); ! 86: } ! 87: ! 88: /* Initializes global stuff, loads first user etc */ ! 89: int read_config(void) ! 90: { ! 91: char ctrl_dir[MAX_PATH+1]; ! 92: char str[1024]; ! 93: char *p; ! 94: ! 95: p=getenv("SBBSCTRL"); ! 96: if(p==NULL) { ! 97: fprintf(stderr,"SBBSCTRL not set\n"); ! 98: return(-1); ! 99: } ! 100: SAFECOPY(ctrl_dir, p); ! 101: prep_dir("",ctrl_dir,sizeof(ctrl_dir)); ! 102: if(!isdir(ctrl_dir)) { ! 103: fprintf(stderr,"SBBSCTRL does not point to a directory\n"); ! 104: return(-1); ! 105: } ! 106: memset(&cfg,0,sizeof(cfg)); ! 107: cfg.size=sizeof(cfg); ! 108: SAFECOPY(cfg.ctrl_dir,ctrl_dir); ! 109: ! 110: /* ! 111: * The following are to make up for Glade hacks... we want a text list ! 112: * in the combo boxes... Galde does this *if* there's predefined text. ! 113: * So, we need to remove it during the refresh. ! 114: */ ! 115: cfg.total_shells=1; ! 116: cfg.total_xedits=1; ! 117: cfg.total_prots=1; ! 118: cfg.total_fcomps=1; ! 119: ! 120: if(refresh_globals()) ! 121: return(-1); ! 122: if(totalusers > 0) ! 123: update_current_user(1); ! 124: return(0); ! 125: } ! 126: ! 127: int main(int argc, char *argv[]) { ! 128: ! 129: gtk_init(&argc, &argv); ! 130: glade_init(); ! 131: ! 132: /* load the interface */ ! 133: strcpy(glade_path, argv[0]); ! 134: strcpy(getfname(glade_path), "gtkuseredit.glade"); ! 135: xml = glade_xml_new(glade_path, "MainWindow", NULL); ! 136: /* connect the signals in the interface */ ! 137: glade_xml_signal_autoconnect(xml); ! 138: /* Set up the global config stuff. */ ! 139: if(read_config()) ! 140: return(1); ! 141: ! 142: if(argc>1) { ! 143: if(atoi(argv[1])) ! 144: update_current_user(atoi(argv[1])); ! 145: else { ! 146: unsigned int nu; ! 147: nu=matchuser(&cfg, argv[1], TRUE); ! 148: if(nu) ! 149: update_current_user(nu); ! 150: else { ! 151: GladeXML *cxml; ! 152: cxml = glade_xml_new(glade_path, "NotFoundWindow", NULL); ! 153: glade_xml_signal_autoconnect(cxml); ! 154: gtk_window_present(GTK_WINDOW(glade_xml_get_widget(cxml, "NotFoundWindow"))); ! 155: } ! 156: } ! 157: } ! 158: ! 159: /* start the event loop */ ! 160: gtk_main(); ! 161: return 0; ! 162: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.