static void update_widgets (void) { gtk_spin_button_set_value((GtkSpinButton *)widgets->latitude, config->latitude); gtk_spin_button_set_value((GtkSpinButton *)widgets->longitude, config->longitude); gtk_entry_set_text((GtkEntry *)widgets->city, config->city); gtk_spin_button_set_value((GtkSpinButton *)widgets->correction, config->correction); gtk_combo_box_set_active((GtkComboBox *)widgets->method, config->method-1); gtk_toggle_button_set_active((GtkToggleButton *)widgets->notification, config->notification); gtk_spin_button_set_value((GtkSpinButton *)widgets->notification_time, config->notification_time); gtk_toggle_button_set_active((GtkToggleButton *)widgets->start_hidden, config->start_hidden); //TODO: gtk_toggle_button_set_active((GtkToggleButton *)widgets->close_closes, config->close_closes); gtk_toggle_button_set_active((GtkToggleButton *) widgets->athan_enabled, config->athan_enabled); if (valid_file(config->athan_subh)) { gtk_file_chooser_set_filename ((GtkFileChooser*)widgets->athan_subh, (const gchar *) config->athan_subh); } if (valid_file(config->athan_normal)) { gtk_file_chooser_set_filename ((GtkFileChooser*)widgets->athan_normal, (const gchar *) config->athan_normal); } }
static GimpPDBStatusType save_image (const gchar *uri, gint32 image_ID, gint32 drawable_ID, gint32 run_mode, GError **error) { GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR; gchar *tmpname; tmpname = get_temp_name (uri, NULL); if (gimp_file_save (run_mode, image_ID, drawable_ID, tmpname, tmpname) && valid_file (tmpname)) { if (uri_backend_save_image (uri, tmpname, run_mode, error)) { status = GIMP_PDB_SUCCESS; } } else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s", gimp_get_pdb_error ()); } g_unlink (tmpname); g_free (tmpname); return status; }
void Save_Screenshot( void ) { char filename[20]; for( unsigned int i = 1; i < 1000; i++ ) { sprintf( filename, "screenshots/%03d.bmp", i ); if( !valid_file( filename ) ) { // Todo : save it as png ! SDL_SaveBMP( screen, filename ); string snumber; snumber = filename; snumber.erase( 0, 12 ); snumber.erase( snumber.length() - 4, 4 ); sprintf( debugdisplay->text, "Screenshot %d saved\n", i ); debugdisplay->counter = DESIRED_FPS * 2.5; return; } } }
static GimpPDBStatusType save_image (const gchar *uri, gint32 image_ID, gint32 drawable_ID, gint32 run_mode, GError **error) { GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR; gchar *tmpname; gboolean mapped = FALSE; tmpname = uri_backend_map_image (uri, run_mode); if (tmpname) mapped = TRUE; else tmpname = get_temp_name (uri, NULL); if (gimp_file_save (run_mode, image_ID, drawable_ID, tmpname, tmpname)) { if (mapped) { status = GIMP_PDB_SUCCESS; } else if (valid_file (tmpname)) { if (uri_backend_save_image (uri, tmpname, run_mode, error)) { status = GIMP_PDB_SUCCESS; } } else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Failed to save to temporary file '%s'"), gimp_filename_to_utf8 (tmpname)); } } else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s", gimp_get_pdb_error ()); } if (! mapped) g_unlink (tmpname); g_free (tmpname); return status; }
static void uninitStdHandles() { if (!initialisedStdHandles) return; if (g_childData != NULL) { delete g_childData; g_childData = NULL; } if (valid_file(STDIN)) fclose(stdin); if (valid_file(STDOUT)) fclose(stdout); if (valid_file(STDERR)) fclose(stderr); if (valid_fd(STDIN)) close(STDIN); if (valid_fd(STDOUT)) close(STDOUT); if (valid_fd(STDERR)) close(STDERR); initialisedStdHandles = false; }
static GimpPDBStatusType save_image (const gchar *filename, gint32 image_ID, gint32 drawable_ID, gint32 run_mode) { GimpPDBStatusType status = GIMP_PDB_SUCCESS; gchar *ext; gchar *tmpname; gchar *mailcmd[3]; GPid mailpid; FILE *mailpipe; GError *error = NULL; ext = find_extension (filename); if (ext == NULL) return GIMP_PDB_CALLING_ERROR; /* get a temp name with the right extension and save into it. */ tmpname = gimp_temp_name (ext + 1); /* construct the "sendmail user@location" line */ mailcmd[0] = SENDMAIL; mailcmd[1] = mail_info.receipt; mailcmd[2] = NULL; /* create a pipe to sendmail */ mailpipe = sendmail_pipe (mailcmd, &mailpid); if (mailpipe == NULL) return GIMP_PDB_EXECUTION_ERROR; create_headers (mailpipe); fflush (mailpipe); if (! (gimp_file_save (run_mode, image_ID, drawable_ID, tmpname, tmpname) && valid_file (tmpname))) { goto error; } if (! to64 (tmpname, mailpipe, &error)) { g_message ("%s", error->message); g_error_free (error); goto error; } fprintf (mailpipe, "\n--GUMP-MIME-boundary--\n"); goto cleanup; error: /* stop sendmail from doing anything */ kill (mailpid, SIGINT); status = GIMP_PDB_EXECUTION_ERROR; cleanup: /* close out the sendmail process */ fclose (mailpipe); waitpid (mailpid, NULL, 0); g_spawn_close_pid (mailpid); /* delete the tmpfile that was generated */ g_unlink (tmpname); g_free (tmpname); return status; }
/* * Read a character from the given window. Handle repainting here (to simplify * things in the calling application). Also, if input-callback(s) are set up, * poll the corresponding files and handle the updates, e.g., for displaying a * tailbox. */ int dlg_getc(WINDOW *win, int *fkey) { WINDOW *save_win = win; int ch = ERR; int before_chr; int before_fkey; int result; bool done = FALSE; bool literal = FALSE; DIALOG_CALLBACK *p = 0; int interval = (dialog_vars.timeout_secs * 1000); time_t expired = time((time_t *) 0) + dialog_vars.timeout_secs; time_t current; if (may_handle_inputs()) wtimeout(win, WTIMEOUT_VAL); else if (interval > 0) wtimeout(win, interval); while (!done) { bool handle_others = FALSE; /* * If there was no pending file-input, check the keyboard. */ ch = really_getch(win, fkey); if (literal) { done = TRUE; continue; } before_chr = ch; before_fkey = *fkey; ch = dlg_lookup_key(win, ch, fkey); dlg_trace_chr(ch, *fkey); current = time((time_t *) 0); /* * If we acquired a fkey value, then it is one of dialog's builtin * codes such as DLGK_HELPFILE. */ if (!*fkey || *fkey != before_fkey) { switch (ch) { case CHR_LITERAL: literal = TRUE; keypad(win, FALSE); continue; case CHR_REPAINT: (void) touchwin(win); (void) wrefresh(curscr); break; case ERR: /* wtimeout() in effect; check for file I/O */ if (interval > 0 && current >= expired) { dlg_exiterr("timeout"); } if (!valid_file(stdin) || !valid_file(dialog_state.screen_output)) { ch = ESC; done = TRUE; } else if (check_inputs()) { if (handle_inputs(win)) dlg_raise_window(win); else done = TRUE; } else { done = (interval <= 0); } break; case DLGK_HELPFILE: if (dialog_vars.help_file) { int yold, xold; getyx(win, yold, xold); dialog_helpfile("HELP", dialog_vars.help_file, 0, 0); dlg_raise_window(win); wmove(win, yold, xold); } continue; case DLGK_FIELD_PREV: /* FALLTHRU */ case KEY_BTAB: /* FALLTHRU */ case DLGK_FIELD_NEXT: /* FALLTHRU */ case TAB: /* Handle tab/backtab as a special case for traversing between * the nominal "current" window, and other windows having * callbacks. If the nominal (control) window closes, we'll * close the windows with callbacks. */ if (dialog_state.getc_callbacks != 0 && (isBeforeChr(TAB) || isBeforeFkey(KEY_BTAB))) { p = (isBeforeChr(TAB) ? next_callback(p) : prev_callback(p)); if ((dialog_state.getc_redirect = p) != 0) { win = p->win; } else { win = save_win; } dlg_raise_window(win); break; } /* FALLTHRU */ default: #ifdef NO_LEAKS if (isBeforeChr(DLG_CTRL('P'))) { /* for testing, ^P closes the connection */ close(0); close(1); close(2); break; } #endif handle_others = TRUE; break; #ifdef HAVE_DLG_TRACE case CHR_TRACE: dlg_trace_win(win); break; #endif } } else { handle_others = TRUE; } if (handle_others) { if ((p = dialog_state.getc_redirect) != 0) { if (!(p->handle_getc(p, ch, *fkey, &result))) { done = (p->win == save_win) && (!p->keep_win); dlg_remove_callback(p); dialog_state.getc_redirect = 0; win = save_win; } } else { done = TRUE; } } } if (literal) keypad(win, TRUE); return ch; }
int show_html(char *browser, char *docs) { char buf[PATHBUF + 2], buf2[PATHBUF]; int i=-1; #ifdef WIN32 char *r; if (!docs || !docs[0]) { /* Use default path relative to installdir */ docs = buf + 1; i = GetModuleFileNameA(NULL, docs, PATHBUF); if (!i) return (-1); r = strrchr(docs, '\\'); if (!r) return (-1); r[1] = 0; strnncat(docs, HANDBOOK_LOCATION_WIN, PATHBUF); } #else /* Linux */ char *argv[5]; if (!docs || !docs[0]) { docs = HANDBOOK_LOCATION2; //FIXME // if (valid_file(docs) < 0) docs = HANDBOOK_LOCATION2; } #endif else docs = gtkncpy(buf + 1, docs, PATHBUF); if ((valid_file(docs) < 0)) { alert_box( _("Error"), _("I am unable to find the documentation. Either you need to download the mtPaint Handbook from the web site and install it, or you need to set the correct location in the Preferences window."), NULL); return (-1); } #ifdef WIN32 if (browser && !browser[0]) browser = NULL; if (browser) { /* Quote the filename */ i = strlen(docs); buf[0] = docs[i] = '"'; docs[i + 1] = '\0'; /* Rearrange parameters */ docs = gtkncpy(buf2, browser, PATHBUF); browser = buf; } if ((unsigned int)ShellExecuteA(NULL, "open", docs, browser, NULL, SW_SHOW) <= 32) i = -1; else i = 0; #else argv[1] = docs; argv[2] = NULL; /* Try to use default browser */ if (!browser || !browser[0]) { argv[0] = "xdg-open"; i = spawn_process(argv, NULL); if (!i) return (0); // System has xdg-utils installed // No xdg-utils - try "BROWSER" variable then browser = getenv("BROWSER"); } else browser = gtkncpy(buf2, browser, PATHBUF); if (!browser) browser = HANDBOOK_BROWSER; argv[0] = browser; i = spawn_process(argv, NULL); #endif if (i) alert_box( _("Error"), _("There was a problem running the HTML browser. You need to set the correct program name in the Preferences window."), NULL); return (i); }
int cAudio :: PlayMusic( string filename, int loops, bool force, unsigned int FadeInms ) { if( !bMusic || !bInitialised ) { return 0; } if( !valid_file( filename ) ) { printf( "Couldn't find music file : %s\n", filename.c_str() ); return 0; } ResumeMusic(); if( !isMusicPlaying() || force ) { if( Music ) { if( force ) { HaltMusic(); } Mix_FreeMusic( Music ); Music = NULL; } Music = Mix_LoadMUS( filename.c_str() ); if( Music ) { Music_Played++; if( !FadeInms ) // No Fading { Mix_PlayMusic( Music, loops ); } else // Fade the Music in { Mix_FadeInMusic( Music, loops, FadeInms ); } } else { if( bDebug ) { printf( "PlayMusic couldn't play music file : %s\n", filename.c_str() ); } return 0; } } else { Music = Mix_LoadMUS( filename.c_str() ); } return 1; }
int cAudio :: PlaySound( string filename, int channel /* = -1 */, int Volume /* = -1 */ ) { if( !bSounds || !bInitialised ) { return 0; } if( channel > 128 ) // new { printf( "PlaySound channel is out of range : %d\n", channel ); return 0; } if( !valid_file( filename ) ) { printf( "Couldn't find sound file : %s\n", filename.c_str() ); return 0; } SCounter++; if( SCounter == AUDIO_MAX_SOUNDS ) { SCounter = 0; } if( Sound[SCounter] ) { Mix_FreeChunk( Sound[SCounter] ); Sound[SCounter] = NULL; } Sound[SCounter] = Mix_LoadWAV( filename.c_str() ); int channel_used = Mix_PlayChannel( channel, Sound[SCounter], 0 ); if( channel_used == -1 ) { if( bDebug ) { printf( "Couldn't play sound file : %s\n", filename.c_str() ); } return 0; } else { Sounds_Played++; if( Volume != -1 ) // new { if( Volume > 128 || Volume < 0 ) { printf( "PlaySound Volume out is of range : %d\n", Volume ); Volume = Sound_Volume; } Mix_Volume( channel_used, Volume ); } else { Mix_Volume( channel_used, Sound_Volume ); } } return 1; }