Added 'info' system; PXML.xml can now cause a .desktop to be created, that will launc...
authorskeezix <skeezix@flotsam-vm.(none)>
Thu, 11 Mar 2010 20:47:07 +0000 (15:47 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Thu, 11 Mar 2010 20:47:07 +0000 (15:47 -0500)
an info page in the pnd-file

apps/pndnotifyd.c
deployment/etc/pandora/conf/desktop
include/pnd_desktop.h
lib/pnd_apps.c
lib/pnd_desktop.c
testdata/conf/desktop
testdata/menuapps/sampleapp9/PXML.xml

index 134bcc5..a883cd6 100644 (file)
@@ -57,6 +57,7 @@ char *desktop_appspath = NULL;
 char *menu_dotdesktoppath = NULL;
 char *menu_iconpath = NULL;
 char *menu_appspath = NULL;
+char *info_dotdesktoppath = NULL;
 // pnd runscript
 char *run_searchpath; // searchpath to find pnd_run.sh
 char *run_script;     // name of pnd_run.sh script from config
@@ -67,6 +68,7 @@ char g_username [ 128 ]; // since we have to wait for login (!!), store username
 // notifier handle
 pnd_notify_handle nh = 0;
 pnd_dbusnotify_handle dbh = 0;
+unsigned char g_info_p = 0; // spit out info .desktops
 
 // constants
 #define PNDNOTIFYD_LOGLEVEL "pndnotifyd.loglevel"
@@ -229,6 +231,7 @@ int main ( int argc, char *argv[] ) {
   pnd_log ( pndn_rem, "Apps searchpath is '%s'\n", menu_appspath );
   pnd_log ( pndn_rem, ".desktop files emit to '%s'\n", menu_dotdesktoppath );
   pnd_log ( pndn_rem, ".desktop icon files emit to '%s'\n", menu_iconpath );
+  pnd_log ( pndn_rem, ".desktop info files emit to '%s'\n", info_dotdesktoppath ? info_dotdesktoppath : "n/a" );
 
   /* set up signal handler
    */
@@ -401,6 +404,7 @@ void consume_configuration ( void ) {
     desktop_dotdesktoppath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_DOTDESKTOP_PATH_KEY );
     desktop_iconpath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_ICONS_PATH_KEY );
     desktop_appspath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_SEARCH_KEY );
+    info_dotdesktoppath = pnd_conf_get_as_char ( desktoph, "info.dotdesktoppath" );
   }
 
   if ( ! desktop_dotdesktoppath ) {
@@ -422,6 +426,11 @@ void consume_configuration ( void ) {
     menu_appspath = pnd_conf_get_as_char ( desktoph, PND_MENU_SEARCH_KEY );
   }
 
+  // info
+  if ( desktoph ) {
+    g_info_p = pnd_conf_get_as_int_d ( desktoph, "info.emit_info", 0 );
+  }
+
   /* try to locate a runscript and optional hupscript
    */
 
@@ -557,6 +566,11 @@ void consume_configuration ( void ) {
   mkdir ( desktop_dotdesktoppath, 0777 );
   mkdir ( desktop_iconpath, 0777 );
 
+  if ( info_dotdesktoppath ) {
+    info_dotdesktoppath = pnd_expand_tilde ( strdup ( info_dotdesktoppath ) );
+    mkdir ( info_dotdesktoppath, 0777 );
+  }
+
   if ( menu_dotdesktoppath ) {
     menu_dotdesktoppath = pnd_expand_tilde ( strdup ( menu_dotdesktoppath ) );
     mkdir ( menu_dotdesktoppath, 0777 );
@@ -705,6 +719,15 @@ void process_discoveries ( pnd_box_handle applist, char *emitdesktoppath, char *
       pnd_log ( pndn_rem, "ERROR: Error creating .desktop file for app: %s\n", pnd_box_get_key ( d ) );
     }
 
+    // info .desktop
+    if ( g_info_p && info_dotdesktoppath ) {
+      if ( pnd_emit_dotinfo ( info_dotdesktoppath, pndrun, d ) ) {
+       // nada
+      } else {
+       pnd_log ( pndn_rem, "ERROR: Error creating info .desktop file for app: %s\n", pnd_box_get_key ( d ) );
+      }
+    }
+
     // does this object request any mkdir's?
     if ( d -> mkdir_sp ) {
 
index aa2b205..62e5c3e 100644 (file)
@@ -17,3 +17,10 @@ iconpath     /tmp    # path for pndnotifyd to drop icons into (can be same as dotdeskto
 # if it is uncommented, pndnotifyd will attempt to invoke the hupscript after emitting .desktop files
 # (the hupscript exists to hup the WMs to redisplay .desktop apps)
 #hupscript     pnd_hup.sh
+
+[info]
+emit_info      1                       # 0->no info .desktop; !0->yes to info .desktop
+dotdesktoppath /usr/share/applications # path for pndnotifyd to spit .desktop files into
+viewer         ../../../usr/bin/midori # sh-script or prog to run. Use wrapper sh if needed.
+viewer_args    -a                      # args. <- plus filename will be passed. ie: "-a filename.html"
+category       Documentation           # freedesktop standard category to use
index 367e38b..d9c52e9 100644 (file)
@@ -15,6 +15,12 @@ extern "C" {
 #define PND_DOTDESKTOP_SOURCE "X-Pandora-Source=libpnd"
 unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t *p );
 
+// emit_dotinfo() will spit out a .desktop 'info entry', similar to the way emit_dotdesktop does its thing
+// - rather than slide this into emit_dotdesktop(), we wish to allow apps to do this or not by calling this
+//   function, and also let them specify an alternate path to emit to.. without adding all these
+//   extra fields to emit_dotdesktop()'s function and breaking apps, or annoying callers down the road
+unsigned char pnd_emit_dotinfo ( char *targetpath, char *pndrun, pnd_disco_t *p );
+
 // emit_icon() will attempt to copy the icon from a PXML directory, or from a pnd file if appended,
 // to the given directory; returns 1 on sucess, otherwise is a fail.
 unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p );
index 33b72c8..73a78e3 100644 (file)
@@ -96,6 +96,7 @@ unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id,
     unsigned char i;
     bzero ( apps_exec_runline, 1024 );
     //pnd_log ( PND_LOG_DEFAULT, "Norun %u\n", f );
+    unsigned char quotenext = 0;
     for ( i = 0; i < ( f - 1 ); i++ ) {
       //pnd_log ( PND_LOG_DEFAULT, "Norun %u: %s\n", i, argv [ i ] );
 
@@ -104,19 +105,30 @@ unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id,
        strncat ( apps_exec_runline, " ", 1000 );
       }
 
-      // if this is for -a, we need to wrap with quotes
-      if ( i > 0 && strcmp ( argv [ i - 1 ], "-a" ) == 0 ) {
+      // quoting
+      if ( quotenext ) {
        strncat ( apps_exec_runline, "\"", 1000 );
       }
 
+      // arg
       strncat ( apps_exec_runline, argv [ i ], 1000 );
 
-      // if this is for -a, we need to wrap with quotes
-      if ( i > 0 && strcmp ( argv [ i - 1 ], "-a" ) == 0 ) {
+      // unquoting
+      if ( quotenext ) {
        strncat ( apps_exec_runline, "\"", 1000 );
       }
 
-    }
+      // clear quoting
+      if ( quotenext ) {
+       quotenext = 0;
+      } else {
+       // if this is for -a, we need to wrap with quotes
+       if ( strcmp ( argv [ i ], "-a" ) == 0 ) {
+         quotenext = 1;
+       }
+      }
+
+    } // for
     return ( 1 );
   }
 
index a222b8f..da1b01d 100644 (file)
@@ -83,7 +83,7 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t
   }
 #endif
 
-#if 0 // we let pnd_run.sh handle this
+#if 0 // we let pnd_run.sh command line handle this instead of in .desktop
   if ( p -> startdir ) {
     snprintf ( buffer, 1020, "Path=%s\n", p -> startdir );
     fprintf ( f, "%s", buffer );
@@ -118,8 +118,9 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t
 
     // args
     if ( p -> execargs ) {
-      strncat ( buffer, " -a ", 1020 );
-      strncat ( buffer, p -> execargs, 1020 );
+      char argbuf [ 1024 ];
+      snprintf ( argbuf, 1000, " -a \"%s\"", p -> execargs );
+      strncat ( buffer, argbuf, 1020 );
     }
 
     // clockspeed
@@ -191,6 +192,147 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t
   return ( 1 );
 }
 
+unsigned char pnd_emit_dotinfo ( char *targetpath, char *pndrun, pnd_disco_t *p ) {
+  char filename [ FILENAME_MAX ];
+  char buffer [ 1024 ];
+  FILE *f;
+  char *viewer, *searchpath;
+  pnd_conf_handle desktoph;
+
+  // specification
+  // http://standards.freedesktop.org/desktop-entry-spec
+
+  // validation
+  //
+
+  // viewer
+  searchpath = pnd_conf_query_searchpath();
+
+  desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
+
+  if ( ! desktoph ) {
+    return ( 0 );
+  }
+
+  viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
+
+  if ( ! viewer ) {
+    return ( 0 ); // no way to view the file
+  }
+
+  // etc
+  if ( ! p -> unique_id ) {
+    pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing unique-id\n", targetpath );
+    return ( 0 );
+  }
+
+  if ( ! p -> info_filename ) {
+    pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing info_filename\n", targetpath );
+    return ( 0 );
+  }
+
+  if ( ! p -> info_name ) {
+    pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing info_name\n", targetpath );
+    return ( 0 );
+  }
+
+  if ( ! targetpath ) {
+    pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing target path\n", targetpath );
+    return ( 0 );
+  }
+
+  if ( ! pndrun ) {
+    pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing pnd_run.sh\n", targetpath );
+    return ( 0 );
+  }
+
+  // set up
+
+  sprintf ( filename, "%s/%s#info.desktop", targetpath, p -> unique_id );
+
+  // emit
+
+  f = fopen ( filename, "w" );
+
+  if ( ! f ) {
+    return ( 0 );
+  }
+
+  fprintf ( f, "%s\n", PND_DOTDESKTOP_HEADER );
+
+  if ( p -> info_name ) {
+    snprintf ( buffer, 1020, "Name=%s\n", p -> info_name );
+    fprintf ( f, "%s", buffer );
+  }
+
+  fprintf ( f, "Type=Application\n" );
+  fprintf ( f, "Version=1.0\n" );
+
+#if 0
+  if ( p -> icon ) {
+    snprintf ( buffer, 1020, "Icon=%s\n", p -> icon );
+    fprintf ( f, "%s", buffer );
+  }
+#endif
+
+  if ( p -> unique_id ) {
+    fprintf ( f, "X-Pandora-UID=%s\n", p -> unique_id );
+  }
+
+  if ( p -> title_en && p -> title_en [ 0 ] ) {
+    snprintf ( buffer, 1020, "Comment=Automatic menu info entry for %s\n", p -> title_en );
+    fprintf ( f, "%s", buffer );
+  }
+
+#if 0 // we let pnd_run.sh command line handle this instead of in .desktop
+  if ( p -> startdir ) {
+    snprintf ( buffer, 1020, "Path=%s\n", p -> startdir );
+    fprintf ( f, "%s", buffer );
+  } else {
+    fprintf ( f, "Path=%s\n", PND_DEFAULT_WORKDIR );
+  }
+#endif
+
+  // exec line
+  char args [ 1001 ];
+  char *pargs = args;
+  if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
+    snprintf ( pargs, 1001, "%s %s",
+              pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
+  } else {
+    pargs = NULL;
+  }
+
+  char pndfile [ 1024 ];
+  if ( p -> object_type == pnd_object_type_directory ) {
+    // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
+    strncpy ( pndfile, p -> object_path, 1000 );
+  } else if ( p -> object_type == pnd_object_type_pnd ) {
+    // pnd_run.sh wants the full path and filename for the .pnd file
+    snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
+  }
+
+  if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
+                        p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
+  {
+    return ( 0 );
+  }
+
+  fprintf ( f, "Exec=%s\n", pnd_apps_exec_runline() );
+
+  if ( pnd_conf_get_as_char ( desktoph, "info.category" ) ) {
+    fprintf ( f, "Categories=%s\n", pnd_conf_get_as_char ( desktoph, "info.category" ) );
+  } else {
+    fprintf ( f, "Categories=Documentation\n" );
+  }
+
+  fprintf ( f, "%s\n", PND_DOTDESKTOP_SOURCE ); // should we need to know 'who' created the file during trimming
+
+  fclose ( f );
+
+  return ( 1 );
+}
+
 unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) {
   //#define BITLEN (8*1024)
 #define BITLEN (64*1024)
index 6e3d6ca..0da72c0 100644 (file)
@@ -14,3 +14,10 @@ iconpath     ./testdata/menuicons    # path for pndnotifyd to drop icons into (can be s
 
 [launcher]
 hupscript      pnd_hup.sh
+
+[info]
+emit_info      1                       # 0->no info .desktop; !0->yes to info .desktop
+dotdesktoppath ./testdata/menu         # path for pndnotifyd to spit .desktop files into
+viewer         midori                  # sh-script or prog to run. Use wrapper sh if needed.
+viewer_args    -a                      # args. <- plus filename will be passed. ie: "-a filename.html"
+category       Documentation           # freedesktop standard category to use
index 2d59722..33e137f 100644 (file)
@@ -6,6 +6,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="jeff.sample.9" xsi:noN
 
   <exec background="true" startdir="/usr/share/icons/" standalone="true" command="program.exe"/>
 
+  <info name="Sample9 info" type="text/html" src="index.html">
+
   <description lang="en_US">This is the English Description of the file.</description>
   <description lang="de_DE">This would be the German description.</description>