Preliminary addition of mimetype handling for file associations; not yet tested much
[pandora-libraries.git] / lib / pnd_desktop.c
index 168ae74..fb875ff 100644 (file)
@@ -115,6 +115,29 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t
   if ( p -> alt_category2 ) {
     fprintf ( f, "X-Pandora-AltCategory2=%s\n", p -> alt_category2 );
   }
+  if ( p -> info_filename ) {
+    fprintf ( f, "X-Pandora-Info-Filename=%s\n", p -> info_filename );
+  }
+  if ( p -> info_name ) {
+    fprintf ( f, "X-Pandora-Info-Name=%s\n", p -> info_name );
+  }
+
+  if ( p -> associationitem1_name || p -> associationitem2_name || p -> associationitem3_name ) {
+    fprintf ( f, "MimeType=" );
+    if ( p -> associationitem1_name ) {
+      fprintf ( f, "%s;", p -> associationitem1_filetype );
+      pnd_log ( PND_LOG_DEFAULT, "App %s is handling mimetype %s [1]\n", p -> title_en, p -> associationitem1_filetype );
+    }
+    if ( p -> associationitem2_name ) {
+      fprintf ( f, "%s;", p -> associationitem2_filetype );
+      pnd_log ( PND_LOG_DEFAULT, "App %s is handling mimetype %s [2]\n", p -> title_en, p -> associationitem2_filetype );
+    }
+    if ( p -> associationitem3_name ) {
+      fprintf ( f, "%s;", p -> associationitem3_filetype );
+      pnd_log ( PND_LOG_DEFAULT, "App %s is handling mimetype %s [3]\n", p -> title_en, p -> associationitem3_filetype );
+    }
+    fprintf ( f, "\n" );
+  }
 
 #if 0 // we let pnd_run.sh command line handle this instead of in .desktop
   if ( p -> startdir ) {
@@ -804,10 +827,13 @@ pnd_disco_t *pnd_parse_dotdesktop ( char *ddpath, unsigned int flags ) {
   }
 
   if ( strstr ( ddpath, ".desktop" ) == NULL ) {
-    return ( NULL );
+    return ( NULL ); // no .desktop in filename, must be something else... skip!
   }
 
   if ( strstr ( ddpath, "info.desktop" ) != NULL ) {
+    // ".....info.desktop" is the 'document help' (README) emitted from a pnd, not an actual app; minimenu rather
+    // expects the doc-info as part of the main app, not a separate app.. so lets drop it here, to avoid doubling up
+    // the number of applications, needlessly..
     return ( NULL );
   }
 
@@ -888,6 +914,11 @@ pnd_disco_t *pnd_parse_dotdesktop ( char *ddpath, unsigned int flags ) {
     } else if ( strncmp ( dd, "X-Pandora-AltCategory2=", 23 ) == 0 ) {
       p -> alt_category2 = strdup ( dd + 23 );
 
+    } else if ( strncmp ( dd, "X-Pandora-Info-Filename=", 24 ) == 0 ) {
+      p -> info_filename = strdup ( dd + 24 );
+    } else if ( strncmp ( dd, "X-Pandora-Info-Name=", 20 ) == 0 ) {
+      p -> info_name = strdup ( dd + 20 );
+
     } else if ( strncmp ( dd, "Comment=", 8 ) == 0 ) {
       p -> desc_en = strdup ( dd + 8 );
     } else if ( strncmp ( dd, "Comment[en]=", 12 ) == 0 ) {
@@ -1008,6 +1039,14 @@ pnd_disco_t *pnd_parse_dotdesktop ( char *ddpath, unsigned int flags ) {
   }
 #endif
 
+  // lame guards, in case of lazy consumers and broken .desktop files
+  if ( p -> object_path == NULL ) {
+    p -> object_path = strdup ( "/tmp" );
+  }
+  if ( p -> object_filename == NULL ) {
+    p -> object_filename = strdup ( "" ); // force bad filename
+  }
+
   // return disco-t
   return ( p );
 }