gboolean put_stringlist(GFile * file, GList * which_list, gboolean is_arraylist) { /*return put_stringlist_limited(file,which_list, -1, is_arraylist);*/ gchar *buf; GError *gerror=NULL; if (is_arraylist) { buf = arraylist_to_string(which_list, "\n"); } else { buf = stringlist_to_string(which_list, "\n"); } g_file_replace_contents(file,buf,strlen(buf) ,NULL,FALSE,G_FILE_CREATE_PRIVATE,NULL,NULL,&gerror); if (gerror) { g_warning("save stringlist error %d %s\n",gerror->code,gerror->message); g_error_free(gerror); return FALSE; } g_free(buf); return TRUE; }
static Tcolsel *colsel_dialog(Tbfwin *bfwin,const gchar *setcolor, gint modal, gint startpos, gint endpos) { Tcolsel *csd; GtkWidget *vbox, *hbox, *but; GdkColor gcolor; const gchar *this_color=setcolor; csd = g_new0(Tcolsel, 1); /* warning: bfwin might be NULL if this dialog is started by return_color() */ csd->bfwin = bfwin; csd->is_modal = modal; csd->startpos = startpos; csd->endpos = endpos; csd->returnval = setcolor ? g_strdup(setcolor) : g_strdup(""); DEBUG_MSG("colsel_dialog, malloced at %p, setcolor=%s\n", csd, setcolor); csd->win = window_full2(_("Bluefish: Select color"), GTK_WIN_POS_CENTER, 12, G_CALLBACK(colsel_destroy_lcb), csd, TRUE, bfwin?bfwin->main_window:NULL); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(csd->win), vbox); csd->csel = gtk_color_selection_new(); gtk_color_selection_set_has_opacity_control(GTK_COLOR_SELECTION(csd->csel), FALSE); if (this_color) { if (gdk_color_parse(this_color, &gcolor)) { gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(csd->csel), &gcolor); } else { this_color=NULL; } } gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(csd->csel), TRUE); gtk_box_pack_start(GTK_BOX(vbox), csd->csel, TRUE, TRUE, 0); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 12); #if GTK_CHECK_VERSION(3,0,0) hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); #else hbox = gtk_hbutton_box_new(); #endif gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END); gtk_box_set_spacing(GTK_BOX(hbox), 12); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); but = bf_stock_cancel_button(G_CALLBACK(colsel_cancel_clicked_lcb), csd); gtk_box_pack_start(GTK_BOX(hbox), but, TRUE, TRUE, 0); but = bf_stock_ok_button(G_CALLBACK(colsel_ok_clicked_lcb), csd); gtk_window_set_default(GTK_WINDOW(csd->win), but); gtk_box_pack_start(GTK_BOX(hbox), but, TRUE, TRUE, 0); if (bfwin && bfwin->session->colorlist) { GtkSettings* gtksettings; /* Note that this function can only be called when the GtkWidget is attached to a toplevel, since the settings object is specific to a particular GdkScreen. */ gtksettings = gtk_widget_get_settings(GTK_WIDGET(csd->csel)); if (gtksettings) { gchar *strings; DEBUG_MSG("pallette list=%d\n",g_list_length(bfwin->session->colorlist)); bfwin->session->colorlist = limit_stringlist(bfwin->session->colorlist, 20, TRUE); DEBUG_MSG("pallette list=%d\n",g_list_length(bfwin->session->colorlist)); strings = stringlist_to_string(bfwin->session->colorlist, ":"); strings[strlen(strings)-1] = '\0'; /* this property may contain max 20 colors, otherwise gtk will crash */ g_object_set(G_OBJECT(gtksettings), "gtk-color-palette", strings, NULL); g_free(strings); } /* DEBUG_MSG("colsel_dialog, setting palette from %s\n", strings); if (gtk_color_selection_palette_from_string(strings, &gcolorarr, &num)) { DEBUG_MSG("num=%d, gcolorarr=%p\n",num,gcolorarr); } else { DEBUG_MSG("hmm, failed to parse our string :(\n"); } */ } gtk_widget_show_all(csd->win); DEBUG_MSG("colsel_dialog, finished\n"); return csd; }
/** * msg_queue_check: * * checks the queue for any messages * this is called by the master program, usually by gtk_timeout_add() * the messages it will listen to are the types: * - MSG_QUEUE_ASK_ALIVE - we should respond with a type MSG_QUEUE_SEND_ALIVE * - MSG_QUEUE_OPENFILE - open a filename * - MSG_QUEUE_OPENPROJECT - open a filename as project * - MSG_QUEUE_OPENNEWWIN - open a new window */ static gboolean msg_queue_check(gint started_by_gtk_timeout) { struct msgbuf { long mtype; char mtext[MSQ_QUEUE_SIZE]; } msgp; gint retval; if (main_v->bfwinlist == NULL || BFWIN(main_v->bfwinlist->data)->documentlist == NULL) { DEBUG_MSG("msg_queue_check, no documentlist yet, so we do not continue\n"); return TRUE; } if (msg_queue.msgid == -1) { return FALSE; } retval = msgrcv(msg_queue.msgid, &msgp, MSQ_QUEUE_SIZE, -MSG_QUEUE_OPENFILE, IPC_NOWAIT); if (retval != -1) { DEBUG_MSG("msg_queue_check, found type %ld\n", msgp.mtype); if (msgp.mtype == MSG_QUEUE_ASK_ALIVE) { struct small_msgbuf { long mtype; char mtext[MSQ_QUEUE_SMALL_SIZE]; } small_msgp; DEBUG_MSG("msg_queue_check, a keepalive is asked from %s, sending!\n", msgp.mtext); small_msgp.mtype = MSG_QUEUE_SEND_ALIVE; strncpy(small_msgp.mtext, msgp.mtext, MSQ_QUEUE_SMALL_SIZE - 1); msgsnd(msg_queue.msgid, (void *) &small_msgp, MSQ_QUEUE_SMALL_SIZE * sizeof(char), IPC_NOWAIT); } else if (msgp.mtype == MSG_QUEUE_OPENFILE) { GList *lastlist = g_list_last(main_v->bfwinlist); gboolean delay_activate = TRUE; if (g_list_length(BFWIN(lastlist->data)->documentlist) < 2 && doc_is_empty_non_modified_and_nameless(BFWIN(lastlist->data)->current_document)) { delay_activate = FALSE; } DEBUG_MSG("msg_queue_check, a filename %s is received\n", msgp.mtext); if (!doc_new_with_file(BFWIN(lastlist->data),msgp.mtext, delay_activate, FALSE)) { msg_queue.file_error_list = g_list_append(msg_queue.file_error_list, g_strdup(msgp.mtext)); } msg_queue_check(0); /* call myself again, there may have been multiple files */ if (started_by_gtk_timeout) { if (msg_queue.file_error_list) { gchar *message, *tmp; tmp = stringlist_to_string(msg_queue.file_error_list, "\n"); free_stringlist(msg_queue.file_error_list); msg_queue.file_error_list = NULL; message = g_strconcat(_("These files were not opened:\n"), tmp, NULL); g_free(tmp); warning_dialog(BFWIN(main_v->bfwinlist->data)->main_window,_("Unable to open file(s)\n"), message); g_free(message); } /* gtk_notebook_set_page(GTK_NOTEBOOK(main_v->notebook),g_list_length(main_v->documentlist) - 1); notebook_changed(-1);*/ } } else if (msgp.mtype == MSG_QUEUE_OPENPROJECT) { GList *lastlist = g_list_last(main_v->bfwinlist); DEBUG_MSG("msg_queue_check, a project %s is received\n", msgp.mtext); project_open_from_file(BFWIN(lastlist->data), msgp.mtext); msg_queue_check(0); /* call myself again, there may have been multiple projects */ } else if (msgp.mtype == MSG_QUEUE_OPENNEWWIN) { /* now check if this is indeed send by another process if the message queue was dead during the startup of this process, it might be started by this very process */ int otherpid = atoi(msgp.mtext); DEBUG_MSG("msg_queue_check, a new window is requested by PID=%d\n",otherpid); if (otherpid != (int) getpid()) { DEBUG_MSG("msg_queue_check, the PID is not ours, opening new window\n"); gui_new_window(NULL, NULL); } } #ifdef DEBUG else { DEBUG_MSG("msg_queue_check, unknown message queue type %ld\n", msgp.mtype); } #endif } else { #ifdef MSG_QUEUE_DEBUG DEBUG_MSG("msg_queue_check, found errno(%d)=%s\n", errno, g_strerror(errno)); #endif /* 43 = Identifier removed */ if (errno == 22 || errno == 43) { DEBUG_MSG("msg_queue_check, re-opening message queue ?!?!?\n"); /* the msg_queue was removed !?!?! */ if (msg_queue_open()) { DEBUG_MSG("msg_queue_check, another process has opened the message_queue, stopping server\n"); msg_queue.server = FALSE; return FALSE; } } } return TRUE; }