Beispiel #1
0
int sample_selector_show(int id, GtkWidget* parent_window,
                                 SampleTab* sampletab)
{
    enum {  RESPONSE_LOAD = 1,  RESPONSE_PREVIEW = 2 };

    GtkWidget* dialog;
    raw_box* rawbox;
    global_settings* settings = settings_get();

    last_sample = sample_new();
    patch = id;
    dialog = gtk_file_chooser_dialog_new("Load Sample",
                                          GTK_WINDOW(parent_window),
                                          GTK_FILE_CHOOSER_ACTION_OPEN,
                                          GTK_STOCK_CANCEL,
                                          GTK_RESPONSE_CANCEL,
                                          GTK_STOCK_OPEN,
                                          GTK_RESPONSE_ACCEPT, NULL);
    if ((rawbox = raw_box_new(dialog)))
    {
        gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog),
                                                            rawbox->box);
    }

    create_filters(dialog);

    sample_shallow_copy(last_sample, patch_sample_data(patch));

    if (last_sample->filename &&
        strcmp(last_sample->filename, "Default") != 0)
    {
        gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),
                                last_sample->filename);
        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
                         g_path_get_dirname(last_sample->filename));
    } 
    else {
        if ( settings->last_sample_dir) 
            gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
                                          settings->last_sample_dir);
    }

    gtk_dialog_add_button(GTK_DIALOG(dialog),
                                "Loa_d", RESPONSE_LOAD);

    gtk_dialog_add_button(GTK_DIALOG(dialog),
                                "Pre_view", RESPONSE_PREVIEW);

    /*  we don't always want to auto-preview when the "selection-changed"
        signal is emitted on a) when the dialog is created, b) when the
        current-folder is changed.
     */
    rawbox->dont_preview = true;
    g_timeout_add(250, timeout_cancel_dont_preview, rawbox);

    g_signal_connect(rawbox->dialog, "current-folder-changed",
                                G_CALLBACK(folder_changed_cb), rawbox);

    g_signal_connect(rawbox->dialog, "selection-changed",
                                G_CALLBACK(selection_changed_cb), rawbox);

again:

    switch(gtk_dialog_run(GTK_DIALOG(dialog)))
    {
    case GTK_RESPONSE_ACCEPT:
        cb_load(rawbox);
        break;

    case RESPONSE_LOAD:
        cb_load(rawbox);
        sample_tab_update_waveforms(sampletab);
        goto again;

    case RESPONSE_PREVIEW:
        cb_preview(rawbox);
        goto again;

    case GTK_RESPONSE_CANCEL:
        cb_cancel();
    default:
        break;
    }

    gtk_widget_destroy(dialog);
    sample_free(last_sample);
    last_sample = 0;

    return 0;
}
Beispiel #2
0
int main(int argc, char *argv[]){
    /* Read config file */
    clit_config *config = malloc(sizeof(clit_config));
    parse_config(config);
    printf("key:%s,secret:%s\n",config->key,config->secret);
    /* If no user info exists, intialize oauth process */
    init_oauth(config->key,config->secret);

    create_filters();

    home = malloc(sizeof(statuses));
    home->count = 0;

    setlocale(LC_ALL,"");
    CDKSCREEN *cdkscreen = 0;
    CDKSCROLL *home_scroll = 0;
    WINDOW *cursesWin = 0;
    char *title = "<C><\5>Home";
    char **home_items = 0;
    int selection,count;

    char *tmpfile = get_home();
    count = load_timeline(tmpfile,home);
    printf("count:%d\n",count);
    home_items = malloc(count*sizeof(char *));

    CDK_PARAMS params;
    CDKparseParams (argc, argv, &params, "cs:t:" CDK_CLI_PARAMS);

    cursesWin = initscr();
    cdkscreen = initCDKScreen(cursesWin);
    initCDKColor();

    status *p = home->head;
    for(int i=0;i<count;++i){
        if(p){
            home_items[i] = p->text;
            p = p->next;
        }
        else break;
    }
//    count = CDKgetDirectoryContents (".", &home_items);

    home_scroll = newCDKScroll(cdkscreen,
                               CDKparamValue (&params, 'X', CENTER),
                               CDKparamValue (&params, 'Y', CENTER),
                               CDKparsePosition(CDKparamString2(&params, 's', "RIGHT")),
                               CDKparamValue (&params, 'H', 0),
                               CDKparamValue (&params, 'W', 0),
                               CDKparamString2(&params, 't', title),
                               CDKparamNumber(&params, 'c') ? 0 : home_items,
                               CDKparamNumber(&params, 'c') ? 0 : count,
                               TRUE,
                               A_REVERSE,
                               CDKparamValue (&params, 'N', TRUE),
                               CDKparamValue (&params, 'S', FALSE));
    if(home_scroll == 0){
        destroyCDKScreen(cdkscreen);
        endCDK();
        exit(EXIT_FAILURE);
    }
    if (CDKparamNumber(&params, 'c')){
        setCDKScrollItems (home_scroll, home_items, count, TRUE);
    }
    selection = activateCDKScroll (home_scroll, 0);

    char ch = '\0';
    while((ch = getch()) != 'q'){
        switch(ch){
            case 'n':
                break;
        }
    }

    //CDKfreeStrings (home_items);
    destroyCDKScroll(home_scroll);
    destroyCDKScreen(cdkscreen);
    endCDK();
    exit(EXIT_SUCCESS);
}