/*
 * baseDir should be freed by user.
 */
static gboolean isFromSameDirectory(GSList* list, gchar** baseDir) {

    GSList *it = list;
    gchar* prevDir = NULL;
    gboolean isAllDirsSame = TRUE;

    while (it) {
        gchar* dir = fp_g_path_get_dirname((gchar*) it->data);

        if (prevDir && strcmp(prevDir, dir) != 0) {
            isAllDirsSame = FALSE;
            fp_g_free(dir);
            break;
        }

        if (!prevDir) {
            prevDir = strdup(dir);
        }
        fp_g_free(dir);

        it = it->next;
    }

    if (isAllDirsSame) {
        *baseDir = prevDir;
    } else {
        free(prevDir);
        *baseDir = strdup("/");
    }

    return isAllDirsSame;
}
static void handle_response(GtkWidget* aDialog, gint responseId, gpointer obj)
{
    JNIEnv *env;
    char *current_folder;
    GSList *filenames;
    jclass cx;
    jstring jcurrent_folder;
    jobjectArray jfilenames;

    env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
    current_folder = NULL;
    filenames = NULL;

    if (responseId == GTK_RESPONSE_ACCEPT) {
        current_folder = fp_gtk_file_chooser_get_current_folder(
                GTK_FILE_CHOOSER(aDialog));
        filenames = fp_gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(aDialog));
    }

    jcurrent_folder = (*env)->NewStringUTF(env, current_folder);
    jfilenames = toFilenamesArray(env, filenames);

    (*env)->CallVoidMethod(env, obj, setFileInternalMethodID, jcurrent_folder,
            jfilenames);
    fp_g_free(current_folder);

    quit(env, (jobject)obj, TRUE);
}