void callback_analyzer_button_analyze (GtkWidget * widget, gpointer user_data) { const char *str; GstAnalyzerVideoInfo *analyzer_vinfo; guint i, j, k; gtk_widget_set_sensitive (ui->analyze_button, FALSE); gtk_widget_set_sensitive (ui->cancel_button, TRUE); gtk_widget_set_sensitive (ui->child_vbox3, TRUE); g_signal_emit_by_name (ui->numframes_chooser, "activate", NULL, NULL); str = gtk_entry_get_text ((GtkEntry *) ui->numframes_chooser); /* initialize the back-end */ if (!gst_analyzer) { GstAnalyzerStatus status; gst_analyzer = g_slice_new0 (GstAnalyzer); status = gst_analyzer_init (gst_analyzer, ui->uri); if (status != GST_ANALYZER_STATUS_SUCCESS) { const gchar *msg; reset_analyzer_ui (); msg = gst_analyzer_status_get_name (status); display_error_dialog (msg); gtk_widget_set_sensitive (ui->analyze_button, TRUE); gtk_widget_set_sensitive (ui->cancel_button, FALSE); gtk_widget_set_sensitive (ui->child_vbox3, FALSE); if (gst_analyzer) gst_analyzer_destroy (gst_analyzer); gst_analyzer = NULL; goto done; } } /* reset the necessary UI components for each Analysis */ reset_analyzer_ui (); ui->num_frames = atoi (str); if (gst_analyzer->codec_name) ui->codec_name = g_strdup (gst_analyzer->codec_name); if (ui->file_name) gst_analyzer_set_file_name (gst_analyzer, ui->file_name); if (ui->num_frames) gst_analyzer_set_num_frames (gst_analyzer, ui->num_frames); if (ui->analyzer_home) gst_analyzer_set_destination_dir_path (gst_analyzer, ui->analyzer_home); gst_analyzer_start (gst_analyzer); analyzer_display_general_stream_info (gst_analyzer->video_info); ui->analyze_idle_id = g_idle_add ((GSourceFunc) analyze_idle_callback, NULL); done:{ } }
// Get and send a fortune. void send_fortune () { std::string fortune; try { fortune = get_fortune (); } catch (int e) { display_error_dialog ("Could not get output of 'fortune'.\n" "Please verify you have it installed in your system."); return; } send_notify (fortune, settings.getTimeout ()); }
int main(int argc, char* argv[]) { int persistent = 0; // wipe away any previous err file unlink("/tmp/err"); char histFile[256]; sprintf(histFile, "/home/%s/.obrun_history", getenv("USER")); // open history file FILE* logFp = fopen(histFile, "r"); gtk_init(NULL, NULL); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); // main window combo = gtk_combo_new(); // editable box with dropdown menu GList* histLines = NULL; char line[356]; gchar* newLine = NULL; int lc = 0; // add in the history items, if the file was found if (logFp != NULL) { while (fgets(line, sizeof(line), logFp) != NULL) // read a line { line[strlen(line)-1] = '\0'; // almighty null-terminator newLine = g_strdup(line); // g_list_append apparently cant just be run in a loop #if DEBUG printf("Adding line (%s) to lines...\n", newLine); #endif histLines = g_list_prepend(histLines, newLine); lc++; } histLines = g_list_prepend(histLines, ""); // empty to start with if (histLines != NULL) { #if DEBUG printf("%d histLines found\n", lc); #endif gtk_combo_set_popdown_strings(GTK_COMBO(combo), histLines); g_list_free(histLines); } } else { // just create it #if DEBUG printf("Creating new history file...\n"); #endif logFp = fopen(histFile, "w"); } g_free(newLine); // we're done with this file for now fclose(logFp); // how do we want to sort? sort_mode = "size"; if (argc > 1) { int ai; for (ai=0; ai<argc; ai++) { if (strcmp(argv[ai], "-a") == 0) { sort_mode = "alpha"; } if (strcmp(argv[ai], "-p") == 0) { persistent = 1; } } } gtk_window_set_title(GTK_WINDOW(window), "Run..."); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_container_add(GTK_CONTAINER(window), combo); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); gtk_widget_set_size_request(GTK_COMBO(combo)->entry, 200, 20); gtk_combo_disable_activate(GTK_COMBO(combo)); // don't show dropdown when enter // listen for X button g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(die), NULL); // listen for key up events: for typing g_signal_connect(window, "key_release_event", G_CALLBACK(check_key_up), NULL); // listen for key down events: for autocomplete, esc g_signal_connect(window, "key_press_event", G_CALLBACK(check_key_down), NULL); // listen for enter g_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "activate", G_CALLBACK(gtk_main_quit), NULL); G_START: gtk_widget_show_all(window); gtk_main(); gchar *orig_str = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry))); gchar *exec_str = g_strdup_printf("%s 2> /tmp/err &", gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry))); if (strcmp(orig_str, "(null)") == 0 || strcmp(orig_str, "") == 0) // user didnt enter anything { die(); } g_printf("Executing %s...\n", exec_str); int result = system(exec_str); // before anything else, has this comand already been recorded? int already_present = in_file(histFile, orig_str, 0); if (!already_present) { // now lets check our error file for a bash error "command not found" char not_found_str[256]; sprintf(not_found_str, "sh: %s: command not found", orig_str); int not_found = in_file("/tmp/err", not_found_str, 1); #if DEBUG printf("already_present: %d\n", already_present); printf("not_found: %d\n", not_found); #endif if (not_found) { char* err_msg = malloc((strlen(orig_str) + strlen(": Command not found!") + 1) * sizeof(char)); sprintf(err_msg, "%s: Command not found!", orig_str); display_error_dialog(err_msg); // wipe out the entry field gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), ""); free(err_msg); goto G_START; // don't exit, move back up to where widgets are shown } if (result == 0 && !already_present && !not_found) { FILE* logFp = fopen(histFile, "a"); if (logFp == NULL) { logFp = fopen(histFile, "w"); } #if DEBUG printf("Adding %s to historyFile...\n", orig_str); #endif fprintf(logFp, "%s\n", orig_str); fclose(logFp); } } #if DEBUG printf("persistent: %d\n", persistent); #endif if (persistent == 1) { goto G_START; } g_free(orig_str); g_free(exec_str); g_list_free(matches); die(); return 0; }