X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=config%2Futil%2Fdolconf.c;h=7a8b2fa87f545ddc080fe495271e7f004cde63c7;hb=42aa110f8f5706c799ff96df0ed4b41327c70b26;hp=a63790936a6f1b654e0a44d54fd1fe16ec9ae885;hpb=7df0ddad481bb2e644bba361d0d3defdbd68494e;p=doldaconnect.git diff --git a/config/util/dolconf.c b/config/util/dolconf.c index a637909..7a8b2fa 100644 --- a/config/util/dolconf.c +++ b/config/util/dolconf.c @@ -58,28 +58,10 @@ GtkListStore *shares; int state, dirty = 1; int ignoreclose = 0; -void astcancel(GtkWidget *widget, gpointer uudata); -void astupdate(GtkWidget *widget, GtkWidget *page, gpointer uudata); -void cb_ast_wnd_apply(GtkWidget *widget, gpointer uudata); -void cb_ast_nick_changed(GtkWidget *widget, gpointer uudata); -void cb_ast_shareadd_clicked(GtkWidget *widget, gpointer uudata); -void cb_ast_sharerem_clicked(GtkWidget *widget, gpointer uudata); -void cb_ast_checkports(GtkWidget *widget, gpointer uudata); -void cb_ast_mode_nat_toggled(GtkWidget *widget, gpointer uudata); -void cb_cfw_mode_act_toggled(GtkWidget *widget, gpointer uudata); -void cb_cfw_orport_toggled(GtkWidget *widget, gpointer uudata); -void cb_cfw_oraddr_toggled(GtkWidget *widget, gpointer uudata); -void cb_cfw_uinet_toggled(GtkWidget *widget, gpointer uudata); -void cb_cfw_save_activate(GtkWidget *widget, gpointer uudata); -void cb_cfw_hup_activate(GtkWidget *widget, gpointer uudata); -void cb_cfw_quit_activate(GtkWidget *widget, gpointer uudata); -void cb_cfw_shareadd_clicked(GtkWidget *widget, gpointer uudata); -void cb_cfw_sharerem_clicked(GtkWidget *widget, gpointer uudata); - #define _(text) gettext(text) -#include "dolconf-assistant.gtk" -#include "dolconf-wnd.gtk" +#include "dolconf-assistant.gtkh" +#include "dolconf-wnd.gtkh" int v_nonempty(const char *val) { @@ -251,7 +233,7 @@ char *getword(char **p) p2 = *p + strlen(*p); len = p2 - *p - ((*p2 == '\"')?1:0); buf = smalloc(len + 1); - memcpy(buf, *p, len); + memcpy(buf, *p + ((delim == '\"')?1:0), len); buf[len] = 0; *p = p2 + ((*p2 == '\"')?1:0); for(p2 = buf; *p2; p2++, len--) { @@ -364,7 +346,7 @@ int readconfig(void) return(rv); } -void writeconfig(void) +int writeconfig(void) { FILE *cf; struct cfvar *var; @@ -373,7 +355,7 @@ void writeconfig(void) if((cf = fopen(cfname, "w")) == NULL) { msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Could not open the configuration file for writing: %s"), strerror(errno)); - return; + return(-1); } fputs("# This file was generated by dolconf v" VERSION "\n\n", cf); for(var = config; var->name != NULL; var++) { @@ -412,6 +394,7 @@ void writeconfig(void) } fclose(cf); dirty = 0; + return(0); } void fillcfw(void) @@ -657,7 +640,8 @@ void cb_ast_shareadd_clicked(GtkWidget *widget, gpointer uudata) void cb_cfw_shareadd_clicked(GtkWidget *widget, gpointer uudata) { - shareadd(); + if(shareadd()) + dirty = 1; } void cb_ast_sharerem_clicked(GtkWidget *widget, gpointer uudata) @@ -674,8 +658,10 @@ void cb_cfw_sharerem_clicked(GtkWidget *widget, gpointer uudata) { GtkTreeIter iter; - if(gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(cfw_sharelist)), NULL, &iter)) + if(gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(cfw_sharelist)), NULL, &iter)) { gtk_list_store_remove(shares, &iter); + dirty = 1; + } } void cb_ast_checkports(GtkWidget *widget, gpointer uudata) @@ -719,27 +705,52 @@ void cb_cfw_uinet_toggled(GtkWidget *widget, gpointer uudata) gtk_widget_set_sensitive(GTK_WIDGET(cfw_uibox), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); } -void cb_cfw_hup_activate(GtkWidget *widget, gpointer uudata) +int hupserver(int disperr) { - int tag; + int tag, ret; struct dc_response *resp; if(dc_connectsync2(dc_srv_local, DC_LATEST) < 0) { - msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server")); - return; + if(disperr) + msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server")); + return(-1); } if(dc_login(NULL, 1, dc_convnone, NULL) != DC_LOGIN_ERR_SUCCESS) { dc_disconnect(); - msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server")); - return; + if(disperr) + msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server")); + return(-1); } + ret = 0; tag = dc_queuecmd(NULL, NULL, L"hup", NULL); if((resp = dc_gettaggedrespsync(tag)) != NULL) { - if(resp->code != 200) - msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server")); + if(resp->code != 200) { + if(disperr) + msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server")); + ret = -1; + } dc_freeresp(resp); } dc_disconnect(); + return(ret); +} + +int saveconfig(void) +{ + struct cfvar *cv; + + cfw2conf(); + if((cv = cfwvalid()) != NULL) { + msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, cv->vld->invmsg, cv->rname); + return(-1); + } + return(writeconfig()); +} + +/* +void cb_cfw_hup_activate(GtkWidget *widget, gpointer uudata) +{ + hupserver(1); } void cb_cfw_save_activate(GtkWidget *widget, gpointer uudata) @@ -764,6 +775,29 @@ void cb_cfw_quit_activate(GtkWidget *widget, gpointer uudata) gtk_main_quit(); state = -1; } +*/ + +void cb_cfw_ok_clicked(GtkWidget *widget, gpointer uudata) +{ + if(saveconfig()) + return; + hupserver(0); + gtk_main_quit(); + state = -1; +} + +void cb_cfw_cancel_clicked(GtkWidget *widget, gpointer uudata) +{ + gtk_main_quit(); + state = -1; +} + +void cb_cfw_apply_clicked(GtkWidget *widget, gpointer uudata) +{ + if(saveconfig()) + return; + hupserver(1); +} int main(int argc, char **argv) { @@ -778,7 +812,7 @@ int main(int argc, char **argv) gtk_init(&argc, &argv); state = -1; - while((c = getopt(argc, argv, "haw")) != -1) { + while((c = getopt(argc, argv, "hawV")) != -1) { switch(c) { case 'a': state = 1; @@ -791,9 +825,13 @@ int main(int argc, char **argv) printf("\t-h\tDisplay this help message\n"); printf("\t-a\tGo directly to the assistant\n"); printf("\t-w\tGo directly to the standard window\n"); + printf("\t-V\tDisplay version info and exit\n"); + exit(0); + case 'V': + printf("%s", RELEASEINFO); exit(0); default: - fprintf(stderr, "usage: dolconf [-haw]\n"); + fprintf(stderr, "usage: dolconf [-hawV]\n"); exit(1); } } @@ -855,8 +893,8 @@ int main(int argc, char **argv) } else if(state == 2) { for(i = 3; i < FD_SETSIZE; i++) close(i); - execlp("dolcon", "dolcon", NULL); - perror("dolcon"); + execlp("dolcon-launch", "dolcon-launch", NULL); + perror("dolcon-launch"); exit(127); } else { msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Internal error (Unknown state)")); @@ -865,3 +903,6 @@ int main(int argc, char **argv) } return(0); } + +#include "dolconf-assistant.gtk" +#include "dolconf-wnd.gtk"