コード例 #1
0
ファイル: gtk.c プロジェクト: kytvi2p/uTox
static void gtk_opensendthread(void *args) {
    uint16_t fid = (size_t)args;

    void *dialog = gtk_file_chooser_dialog_new((const char *)S(SEND_FILE), NULL, 0, "gtk-cancel", -6, "gtk-open", -3, NULL);
    gtk_file_chooser_set_select_multiple(dialog, 1);
    int result = gtk_dialog_run(dialog);
    if(result == -3) {
        char *out = malloc(65536), *outp = out;
        g_list *list = gtk_file_chooser_get_filenames(dialog), *p = list;
        while(p) {
            outp = stpcpy(outp, p->data);
            *outp++ = '\n';
            g_free_utox(p->data);
            p = p->next;
        }
        *outp = 0;
        g_slist_free_utox(list);
        debug("files: %s\n", out);

        //dont call this from this thread
        tox_postmessage(TOX_FILE_SEND_NEW, fid, 0xFFFF, out);
    }

    gtk_widget_destroy(dialog);
    while(gtk_events_pending()) {
        gtk_main_iteration();
    }

    gtk_open = 0;
}
コード例 #2
0
ファイル: gtk.c プロジェクト: Chuongv/uTox
static void gtk_openavatarthread(void *UNUSED(args)) {
    void *dialog = gtk_file_chooser_dialog_new((const char *)S(SELECT_AVATAR_TITLE), NULL,
            GTK_FILE_CHOOSER_ACTION_OPEN,
            "_Cancel", GTK_RESPONSE_CANCEL,
            "_Open", GTK_RESPONSE_ACCEPT,
            NULL);
    void *filter = gtk_file_filter_new();
    gtk_file_filter_add_mime_type(filter, "image/jpeg");
    gtk_file_filter_add_mime_type(filter, "image/png");
    gtk_file_filter_add_mime_type(filter, "image/bmp");
    gtk_file_filter_add_mime_type(filter, "image/gif");
    gtk_file_chooser_set_filter(dialog, filter);

    void *preview = gtk_image_new();
    gtk_file_chooser_set_preview_widget(dialog, preview);
    g_signal_connect_data(dialog, "update-preview", update_image_preview, preview, NULL, 0);

    while (gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT) {
        char *filename = gtk_file_chooser_get_filename(dialog);
        int size;

        int width, height, bpp;
        uint8_t *img = stbi_load(filename, &width, &height, &bpp, 0);
        uint8_t *file_data = stbi_write_png_to_mem(img, 0, width, height, bpp, &size);
        free(img);

        g_free_utox(filename);
        if (!file_data) {
            void *message_dialog = gtk_message_dialog_new(dialog, 0, 1, 2, (const char *)S(CANT_FIND_FILE_OR_EMPTY));
            gtk_dialog_run(message_dialog);
            gtk_widget_destroy(message_dialog);
        } else if (size > UTOX_AVATAR_MAX_DATA_LENGTH) {
            free(file_data);
            char_t size_str[16];
            int len = sprint_humanread_bytes(size_str, sizeof(size_str), UTOX_AVATAR_MAX_DATA_LENGTH);
            void *message_dialog = gtk_message_dialog_new(dialog, 0, 1, 2, "%s%.*s.", S(AVATAR_TOO_LARGE_MAX_SIZE_IS), len, size_str);
            gtk_dialog_run(message_dialog);
            gtk_widget_destroy(message_dialog);
        } else {
            postmessage(SELF_AVATAR_SET, size, 0, file_data);
            break;
        }
    }

    gtk_widget_destroy(dialog);
    while(gtk_events_pending()) {
        gtk_main_iteration();
    }

    gtk_open = false;
}
コード例 #3
0
ファイル: gtk.c プロジェクト: Chuongv/uTox
static void update_image_preview(void *filechooser, void *image) {
#define MAX_PREVIEW_SIZE 256
    char *filename = gtk_file_chooser_get_preview_filename(filechooser);
    if (!filename)
        return;

    // load preview
    void *pixbuf = gdk_pixbuf_new_from_file(filename, NULL);

    if (!pixbuf) {
        g_free_utox(filename);
        gtk_file_chooser_set_preview_widget_active(filechooser, false);
        return;
    }

    // if preview too big load smaller
    if (gdk_pixbuf_get_width(pixbuf) > MAX_PREVIEW_SIZE || gdk_pixbuf_get_height(pixbuf) > MAX_PREVIEW_SIZE) {
        g_object_unref(pixbuf);
        pixbuf = gdk_pixbuf_new_from_file_at_size(filename, MAX_PREVIEW_SIZE, MAX_PREVIEW_SIZE, NULL);
    }

    g_free_utox(filename);

    if (!pixbuf) {
        gtk_file_chooser_set_preview_widget_active(filechooser, false);
        return;
    }

    // pad to MAX_PREVIEW_SIZE + 3px margins
    int margin = (MAX_PREVIEW_SIZE + 6 - gdk_pixbuf_get_width(pixbuf)) / 2;
    gtk_widget_set_margin_left(image, margin);
    gtk_widget_set_margin_right(image, margin);

    // set preview
    gtk_image_set_from_pixbuf(image, pixbuf);
    g_object_unref(pixbuf);
    gtk_file_chooser_set_preview_widget_active(filechooser, true);
}
コード例 #4
0
ファイル: gtk.c プロジェクト: Chuongv/uTox
static void gtk_opensendthread(void *args) {
    uint16_t fid = (size_t)args;

    void *dialog = gtk_file_chooser_dialog_new((const char *)S(SEND_FILE), NULL,
            GTK_FILE_CHOOSER_ACTION_OPEN,
            "_Cancel", GTK_RESPONSE_CANCEL,
            "_Open", GTK_RESPONSE_ACCEPT,
            NULL);
    gtk_file_chooser_set_select_multiple(dialog, true);

    void *preview = gtk_image_new();
    gtk_file_chooser_set_preview_widget(dialog, preview);
    g_signal_connect_data(dialog, "update-preview", update_image_preview, preview, NULL, 0);

    int result = gtk_dialog_run(dialog);
    if(result == GTK_RESPONSE_ACCEPT) {
        char *out = malloc(65536), *outp = out;
        GSList *list = gtk_file_chooser_get_filenames(dialog), *p = list;
        while(p) {
            outp = stpcpy(outp, p->data);
            *outp++ = '\n';
            g_free_utox(p->data);
            p = p->next;
        }
        *outp = 0;
        g_slist_free_utox(list);
        debug("files: %s\n", out);

        //dont call this from this thread
        postmessage_toxcore(TOX_FILE_SEND_NEW, fid, 0xFFFF, out);
    }

    gtk_widget_destroy(dialog);
    while(gtk_events_pending()) {
        gtk_main_iteration();
    }

    gtk_open = false;
}
コード例 #5
0
ファイル: gtk.c プロジェクト: PKRoma/uTox
static void gtk_openavatarthread(void *UNUSED(args))
{
    void *dialog = gtk_file_chooser_dialog_new(S(SELECT_AVATAR_TITLE), NULL, 0, "gtk-cancel", -6, "gtk-open", -3, NULL);
    void *filter = gtk_file_filter_new();
    gtk_file_filter_add_mime_type(filter, "image/png");
    gtk_file_chooser_set_filter(dialog, filter);

    while (gtk_dialog_run(dialog) == -3) { // -3 means user selected an image
        char *filename = gtk_file_chooser_get_filename(dialog);
        uint32_t size;

        void *file_data = file_raw(filename, &size);
        g_free_utox(filename);
        if (!file_data) {
            void *message_dialog = gtk_message_dialog_new(dialog, 0, 1, 2, (const char *)S(CANT_FIND_FILE_OR_EMPTY));
            gtk_dialog_run(message_dialog);
            gtk_widget_destroy(message_dialog);
        } else if (size > UTOX_AVATAR_MAX_DATA_LENGTH) {
            free(file_data);
            char_t size_str[16];
            int len = sprint_bytes(size_str, sizeof(size_str), UTOX_AVATAR_MAX_DATA_LENGTH);
            void *message_dialog = gtk_message_dialog_new(dialog, 0, 1, 2, "%s%.*s.", S(AVATAR_TOO_LARGE_MAX_SIZE_IS), len, size_str);
            gtk_dialog_run(message_dialog);
            gtk_widget_destroy(message_dialog);
        } else {
            postmessage(SET_AVATAR, size, 0, file_data);
            break;
        }
    }

    gtk_widget_destroy(dialog);
    while(gtk_events_pending()) {
        gtk_main_iteration();
    }

    gtk_open = 0;
}