int import_read_file(Logbook *logbook) { GPid pid; int fdin, fdout, fderr; FILE *fin=NULL, *fout=NULL, *ferr=NULL; GError *error=NULL; char *txt; GtkWidget *view; GtkTreeModel *treemod; int nrow=0; gchar *argv[32] = {0}; argv[0] = scripter_get_script_filename(logbook->import_scripter); scripter_get_parameter_values(logbook->import_scripter, argv+1); int i; for (i=0; argv[i]; i++); argv[i] = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(logbook->import_input_file)); if (g_spawn_async_with_pipes(NULL, argv, NULL, 0, NULL, NULL, &pid, &fdin, &fdout, &fderr, &error)) { if (!((fin = fdopen(fdin, "ab")) && (fout = fdopen(fdout, "rb")) && (ferr = fdopen(fderr, "rb")))) { fprintf(stderr, "spawn_script fdopen failed\n"); exit(1); } txt = text_view_get_text(GTK_TEXT_VIEW(logbook->import_input_text)); assert(fin); fputs(txt, fin); fclose(fin); assert(fout); nrow = build_table_from_csv_fh(fout, &view, &treemod, NULL); fclose(fout); assert(ferr); fclose(ferr); g_spawn_close_pid(pid); if (logbook->import_interpreted_treeview) gtk_widget_destroy(logbook->import_interpreted_treeview); logbook->import_interpreted_treeview = view; logbook->import_interpreted_treemodel = treemod; gtk_container_add(GTK_CONTAINER(logbook->import_interpreted_sw), view); gtk_widget_show(view); } else { fprintf(stderr, "Can't open import script\n"); } return nrow; }
static void send_btn_clicked_cb(GtkButton *button, gpointer user_data) { gchar *text; Chat *c = (Chat *)user_data; text = text_view_get_text(GTK_TEXT_VIEW(c->input)); if (strlen(text) != 0) { win_chat_append(c->id, text, TRUE, NULL); o2_send_chat(c->id, text); } g_free(text); text_view_clear(GTK_TEXT_VIEW(c->input)); }
static gboolean input_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data) { Chat *c = user_data; gchar *text; switch(event->keyval) { case GDK_Return: case GDK_KP_Enter: if (o2_is_connected() == FALSE) { puts("NOT CONNECTED"); return TRUE; } if (c->enter_sends == FALSE) break; text = text_view_get_text(GTK_TEXT_VIEW(widget)); if (strlen(text) != 0) { win_chat_append(c->id, text, TRUE, NULL); o2_send_chat(c->id, text); win_main_reset_autoaway_timer(); } g_free(text); text_view_clear(GTK_TEXT_VIEW(widget)); c->need_blinking = FALSE; c->notify_sent = FALSE; return TRUE; break; case GDK_Escape: gtk_widget_hide_all(GTK_WIDGET(c->win)); break; default: if (isascii(event->keyval) && c->notify_sent == FALSE) { c->notify_sent = TRUE; o2_send_notify(c->id, TLEN_NOTIFY_TYPING); puts("sending notify"); } break; } return FALSE; }