$OpenBSD: patch-src_main_c,v 1.16 2012/01/23 16:14:40 dcoppa Exp $

Fix problem with directory vs dvd detection
(upstream svn revision r2201)

Enable dark theme only when using GTK+3
(upstream svn revision r2205)

--- src/main.c.orig	Fri Dec 16 20:55:51 2011
+++ src/main.c	Mon Jan 23 17:06:45 2012
@@ -658,7 +658,10 @@ int main(int argc, char *argv[])
     gdouble volume = 100.0;
     gchar *accelerator_keys;
     gchar **parse;
+#ifdef GTK3_ENABLED
     GtkSettings *gtk_settings;
+#endif
+    int stat_result;
 
 #ifndef OS_WIN32
     struct sigaction sa;
@@ -1053,10 +1056,12 @@ int main(int argc, char *argv[])
                            G_TYPE_FLOAT, G_TYPE_FLOAT, G_TYPE_BOOLEAN);
 
     // only use dark theme if not embedded, otherwise use the default theme                                       
+#ifdef GTK3_ENABLED
     if (embed_window <= 0) {
         gtk_settings = gtk_settings_get_default();
         g_object_set(G_OBJECT(gtk_settings), "gtk-application-prefer-dark-theme", TRUE, NULL);
     }
+#endif
 
     create_window(embed_window);
 
@@ -1078,14 +1083,15 @@ int main(int argc, char *argv[])
             g_object_unref(file);
         }
         filename = g_filename_from_uri(uri, NULL, NULL);
-        g_stat(filename, &buf);
+        stat_result = g_stat(filename, &buf);
         g_free(filename);
 #else
-        g_stat(argv[fileindex], &buf);
+        stat_result = g_stat(argv[fileindex], &buf);
 #endif
 
         if (verbose) {
             printf("opening %s\n", argv[fileindex]);
+            printf("stat_result = %i\n", stat_result);
             printf("is block %i\n", S_ISBLK(buf.st_mode));
             printf("is character %i\n", S_ISCHR(buf.st_mode));
             printf("is reg %i\n", S_ISREG(buf.st_mode));
@@ -1093,7 +1099,7 @@ int main(int argc, char *argv[])
             printf("playlist %i\n", playlist);
             printf("embedded in window id 0x%x\n", embed_window);
         }
-        if (S_ISBLK(buf.st_mode)) {
+        if (stat_result == 0 && S_ISBLK(buf.st_mode)) {
             // might have a block device, so could be a DVD
 
 #ifdef HAVE_SYS_MOUNT_H
@@ -1148,11 +1154,11 @@ int main(int argc, char *argv[])
                     playiter = TRUE;
                 }
             }
-        } else if (S_ISDIR(buf.st_mode)) {
+        } else if (stat_result == 0 && S_ISDIR(buf.st_mode)) {
             uri = g_strdup_printf("%s/VIDEO_TS", argv[fileindex]);
-            stat(uri, &buf);
+            stat_result = g_stat(uri, &buf);
             g_free(uri);
-            if (S_ISDIR(buf.st_mode)) {
+            if (stat_result == 0 && S_ISDIR(buf.st_mode)) {
                 add_item_to_playlist("dvdnav://", 0);
                 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter);
                 gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_DVD);
