src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c

Print this page




 154 
 155     array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls,
 156             NULL);
 157     if (array == NULL) {
 158         JNU_ThrowInternalError(env, "Could not instantiate array files array");
 159         return NULL;
 160     }
 161 
 162     i = 0;
 163     for (iterator = list; iterator; iterator = iterator->next) {
 164         entry = (char*) iterator->data;
 165         entry = strrchr(entry, '/') + 1;
 166         str = (*env)->NewStringUTF(env, entry);
 167         (*env)->SetObjectArrayElement(env, array, i, str);
 168         i++;
 169     }
 170 
 171     return array;
 172 }
 173 












































 174 static void handle_response(GtkWidget* aDialog, gint responseId, gpointer obj)
 175 {
 176     JNIEnv *env;
 177     char *current_folder;
 178     GSList *filenames;
 179     jclass cx;
 180     jstring jcurrent_folder;
 181     jobjectArray jfilenames;
 182 
 183     env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
 184     current_folder = NULL;
 185     filenames = NULL;

 186 
 187     if (responseId == GTK_RESPONSE_ACCEPT) {
 188         current_folder = fp_gtk_file_chooser_get_current_folder(
 189                 GTK_FILE_CHOOSER(aDialog));



 190         filenames = fp_gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(aDialog));
 191     }





 192 

 193     jcurrent_folder = (*env)->NewStringUTF(env, current_folder);
 194     jfilenames = toFilenamesArray(env, filenames);
 195 
 196     (*env)->CallVoidMethod(env, obj, setFileInternalMethodID, jcurrent_folder,
 197             jfilenames);
 198     fp_g_free(current_folder);
 199 
 200     quit(env, (jobject)obj, TRUE);
 201 }
 202 
 203 /*
 204  * Class:     sun_awt_X11_GtkFileDialogPeer
 205  * Method:    run
 206  * Signature: (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/io/FilenameFilter;ZII)V
 207  */
 208 JNIEXPORT void JNICALL
 209 Java_sun_awt_X11_GtkFileDialogPeer_run(JNIEnv * env, jobject jpeer,
 210         jstring jtitle, jint mode, jstring jdir, jstring jfile,
 211         jobject jfilter, jboolean multiple, int x, int y)
 212 {
 213     GtkWidget *dialog = NULL;
 214     GtkFileFilter *filter;
 215 




 154 
 155     array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls,
 156             NULL);
 157     if (array == NULL) {
 158         JNU_ThrowInternalError(env, "Could not instantiate array files array");
 159         return NULL;
 160     }
 161 
 162     i = 0;
 163     for (iterator = list; iterator; iterator = iterator->next) {
 164         entry = (char*) iterator->data;
 165         entry = strrchr(entry, '/') + 1;
 166         str = (*env)->NewStringUTF(env, entry);
 167         (*env)->SetObjectArrayElement(env, array, i, str);
 168         i++;
 169     }
 170 
 171     return array;
 172 }
 173 
 174 /**
 175  * Convert a GSList to an array of filenames (with the parent folder)
 176  */
 177 static jobjectArray toPathAndFilenamesArray(JNIEnv *env, GSList* list)
 178 {
 179     jstring str;
 180     jclass stringCls;
 181     GSList *iterator;
 182     jobjectArray array;
 183     int i;
 184     char* entry;
 185 
 186 
 187     if (NULL == list) {
 188         return NULL;
 189     }
 190 
 191     stringCls = (*env)->FindClass(env, "java/lang/String");
 192     if (stringCls == NULL) {
 193         JNU_ThrowInternalError(env, "Could not get java.lang.String class");
 194         return NULL;
 195     }
 196 
 197     array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls,
 198             NULL);
 199     if (array == NULL) {
 200         JNU_ThrowInternalError(env, "Could not instantiate array files array");
 201         return NULL;
 202     }
 203 
 204     i = 0;
 205     for (iterator = list; iterator; iterator = iterator->next) {
 206         entry = (char*) iterator->data;
 207         //check for leading slash.
 208         if( (entry-strchr(entry, '/')) == 0) entry++;
 209         
 210         str = (*env)->NewStringUTF(env, entry);
 211         (*env)->SetObjectArrayElement(env, array, i, str);
 212         i++;
 213     }
 214 
 215     return array;
 216 }
 217 
 218 static void handle_response(GtkWidget* aDialog, gint responseId, gpointer obj)
 219 {
 220     JNIEnv *env;
 221     char *current_folder;
 222     GSList *filenames;
 223     jclass cx;
 224     jstring jcurrent_folder;
 225     jobjectArray jfilenames;
 226 
 227     env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
 228     current_folder = NULL;
 229     filenames = NULL;
 230     gboolean full_path_names = FALSE;
 231     
 232     if (responseId == GTK_RESPONSE_ACCEPT) {
 233         current_folder = fp_gtk_file_chooser_get_current_folder(
 234                 GTK_FILE_CHOOSER(aDialog));
 235         if(NULL == current_folder){
 236             full_path_names=TRUE;
 237         }
 238         filenames = fp_gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(aDialog));
 239     }
 240     if(full_path_names){
 241         //This is a hack for use with "Recent Folders" in gtk where each
 242         //file could have its own directory.
 243         jcurrent_folder = (*env)->NewStringUTF(env, "/");
 244         jfilenames = toPathAndFilenamesArray(env, filenames);
 245     
 246     } else{
 247         jcurrent_folder = (*env)->NewStringUTF(env, current_folder);
 248         jfilenames = toFilenamesArray(env, filenames);
 249     }
 250     (*env)->CallVoidMethod(env, obj, setFileInternalMethodID, jcurrent_folder,
 251             jfilenames);
 252     fp_g_free(current_folder);
 253 
 254     quit(env, (jobject)obj, TRUE);
 255 }
 256 
 257 /*
 258  * Class:     sun_awt_X11_GtkFileDialogPeer
 259  * Method:    run
 260  * Signature: (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/io/FilenameFilter;ZII)V
 261  */
 262 JNIEXPORT void JNICALL
 263 Java_sun_awt_X11_GtkFileDialogPeer_run(JNIEnv * env, jobject jpeer,
 264         jstring jtitle, jint mode, jstring jdir, jstring jfile,
 265         jobject jfilter, jboolean multiple, int x, int y)
 266 {
 267     GtkWidget *dialog = NULL;
 268     GtkFileFilter *filter;
 269