[jp] Rudimentary plucker plugin available

Ludovic Rousseau ludovic.rousseau at free.fr
Fri Jun 6 17:31:18 EDT 2003


Le jeudi 05 juin 2003 à 16:24:45, Jason Day a écrit:
> There has been a good bit of discussion in the past couple of weeks
> about running scripts inside of J-Pilot, and most of it seemed to be for
> the purpose of running the plucker distiller.  Well, here ya go :)

Wonderful. That is what I was also writting but far better :-)

Suggestions:
1. use plugin_pre_sync_pre_connect() instead of plugin_pre_sync() as Judd
  just included this in CVS
2. remove the .pdb files in plugin_post_sync() or allow to start another
  script to do this (and maybe other things)
3. add a button to start a file selector and select the "distiller
  command" and a button for the "install from" directory
4. this is no plucker specific (except the .pdb auto installation part)
  so maybe jpilot-script is a better name (especially if you have both
  pre and post script execution)

I did suggestions 1 and 3 (patch included).
Maybe suggestion 2 is not a good idea.

Bye,

-- 
 Dr. Ludovic Rousseau                        Ludovic.Rousseau at free.fr
 -- Normaliser Unix c'est comme pasteuriser le camembert, L.R. --
-------------- next part --------------
diff -ru jpilot-plucker-0.01/src/gui.c jpilot-plucker-0.02/src/gui.c
--- jpilot-plucker-0.01/src/gui.c	Thu Jun  5 04:13:41 2003
+++ jpilot-plucker-0.02/src/gui.c	Fri Jun  6 23:25:14 2003
@@ -33,18 +33,26 @@
 
 static const char RCSID[] = "$Id: gui.c,v 1.6 2003/06/05 02:13:41 jday Exp $";
 
+#define SELECT_DISTILLER_COMMAND 1
+#define SELECT_INSTALL_DIR 2
+
 
 /* Global variables */
 static GtkWidget *distiller_cmd_entry;
 static GtkWidget *terminal_cmd_entry;
 static GtkWidget *terminal_label;
 static GtkWidget *install_dir_entry;
+static GtkWidget *FileSelector = NULL;
+static int Selection;
 
 /* Local static functions */
 static void cb_toggle_button (GtkWidget *widget, gpointer data);
 static void cb_save (GtkWidget *widget, gpointer data);
 static void cb_run_distiller (GtkWidget *widget, gpointer data);
 static void cb_use_term (GtkWidget *widget, gpointer data);
+static void file_select(GtkWidget *widget, gpointer data);
+static void file_cancel(void);
+static void file_ok_sel(GtkWidget *w, GtkFileSelection *fs);
 
 
 int init_gui (GtkWidget *vbox, GtkWidget *hbox, unsigned int unique_id) {
@@ -57,6 +65,21 @@
 
     jp_logf(JP_LOG_DEBUG, "Plucker: plugin gui started\n");
 
+	if (FileSelector == NULL)
+	{
+		FileSelector = gtk_file_selection_new ("File selection");
+
+		/* Connect the ok_button to file_ok_sel function */
+		gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (FileSelector)->ok_button),
+			"clicked", (GtkSignalFunc) file_ok_sel, FileSelector );
+
+		gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (FileSelector)->cancel_button),
+			"clicked", (GtkSignalFunc) file_cancel, 0);
+
+		/* Set as modal */
+		gtk_window_set_modal (GTK_WINDOW(FileSelector),TRUE);
+	}
+
     vbox1 = gtk_vbox_new (FALSE, 0);
     gtk_box_pack_start (GTK_BOX(hbox), vbox1, TRUE, FALSE, 0);
 
@@ -129,8 +152,11 @@
     /* distiller command */
     temp_hbox = gtk_hbox_new (FALSE, 0);
 
-    label = gtk_label_new ("Distiller command:");
-    gtk_box_pack_start (GTK_BOX(temp_hbox), label, FALSE, FALSE, 5);
+    button = gtk_button_new_with_label ("Distiller command:");
+    gtk_box_pack_start (GTK_BOX(temp_hbox), button, FALSE, FALSE, 5);
+	gtk_signal_connect(GTK_OBJECT(button), "clicked",
+		GTK_SIGNAL_FUNC(file_select),
+		GINT_TO_POINTER(SELECT_DISTILLER_COMMAND));
 
     distiller_cmd_entry = gtk_entry_new();
     plucker_get_pref (DISTILLER_CMD, NULL, &svalue);
@@ -169,8 +195,11 @@
     /* install from dir */
     temp_hbox = gtk_hbox_new (FALSE, 0);
 
-    label = gtk_label_new ("Install from:");
-    gtk_box_pack_start (GTK_BOX(temp_hbox), label, FALSE, FALSE, 5);
+    button = gtk_button_new_with_label ("Install from:");
+    gtk_box_pack_start (GTK_BOX(temp_hbox), button, FALSE, FALSE, 5);
+	gtk_signal_connect(GTK_OBJECT(button), "clicked",
+		GTK_SIGNAL_FUNC(file_select),
+		GINT_TO_POINTER(SELECT_INSTALL_DIR));
 
     install_dir_entry = gtk_entry_new();
     plucker_get_pref (INSTALL_DIR, NULL, &svalue);
@@ -290,4 +319,51 @@
     gtk_widget_set_sensitive (terminal_label, enabled);
     gtk_widget_set_sensitive (terminal_cmd_entry, enabled);
 }
+
+void file_select(GtkWidget *widget, gpointer data)
+{
+	/* Use the current file as default filename */
+	Selection = GPOINTER_TO_INT(data);
+	switch (Selection)
+	{
+		case SELECT_DISTILLER_COMMAND:
+			gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSelector),
+				gtk_entry_get_text(GTK_ENTRY(distiller_cmd_entry)));
+			break;
+
+		case SELECT_INSTALL_DIR:
+			gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSelector),
+				gtk_entry_get_text(GTK_ENTRY(install_dir_entry)));
+			break;
+
+		default:
+			return;
+	}
+
+	gtk_widget_show(FileSelector);
+} /* file_select */
+
+void file_cancel(void)
+{
+	gtk_widget_hide(FileSelector);
+} /* file_cancel */
+
+/* Get the selected filename and print it to the console */
+void file_ok_sel(GtkWidget *w, GtkFileSelection *fs)
+{
+	switch (Selection)
+	{
+		case SELECT_DISTILLER_COMMAND:
+			gtk_entry_set_text(GTK_ENTRY(distiller_cmd_entry),
+				gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
+			break;
+
+		case SELECT_INSTALL_DIR:
+			gtk_entry_set_text(GTK_ENTRY(install_dir_entry),
+				gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
+			break;
+	}
+
+	gtk_widget_hide(FileSelector);
+} /* file_ok_sel */
 
diff -ru jpilot-plucker-0.01/src/plugin.c jpilot-plucker-0.02/src/plugin.c
--- jpilot-plucker-0.01/src/plugin.c	Thu Jun  5 04:13:41 2003
+++ jpilot-plucker-0.02/src/plugin.c	Fri Jun  6 22:56:29 2003
@@ -100,8 +100,8 @@
     return 0;
 }
 
-int plugin_pre_sync() {
-    jp_logf (JP_LOG_DEBUG, "Plucker: plugin_pre_sync\n");
+int plugin_pre_sync_pre_connect() {
+    jp_logf (JP_LOG_DEBUG, "Plucker: plugin_pre_syncc_pre_connect\n");
 
     /*
      * Load the prefs file again. Note that we have to do this because the
@@ -117,30 +117,13 @@
         jp_logf (JP_LOG_DEBUG, "Plucker: loaded preferences from " PREFS_FILE "\n");
     }
 
-    return 0;
-}
-
-int plugin_sync (int sd) {
-    DIR *dir;
-    struct dirent *entry;
-    long ivalue;
-    const char *svalue;
-    time_t ltime;
-    char path[NAME_MAX];
-
     /*
-     * Running the distiller really belongs in plugin_pre_sync.  Despite the
-     * name, however, plugin_pre_sync is called *after* J-Pilot opens the
-     * connection to the palm, but the socket descriptor is not passed in.
-     * This means we can't call pi_watchdog from plugin_pre_sync, which in
-     * turn means that the distiller process will almost certainly cause the
-     * palm connection to timeout.  So we do it here.
+	 * run the distiller or the script the user defined
      */
     if (should_run_distiller()) {
         const gchar *cmd;
         const gchar *terminal_cmd;
-
-        pi_watchdog (sd, 10);   /* prevent the palm from timing out */
+        long ivalue;
 
         plucker_get_pref (DISTILLER_CMD, 0, &cmd);
         jp_logf (JP_LOG_DEBUG, "distiller command: [%s]\n", cmd);
@@ -154,9 +137,17 @@
         else {
             run_distiller (cmd, TRUE);
         }
-
-        pi_watchdog (sd, 0);   /* back to normal */
     }
+
+    return 0;
+}
+
+int plugin_sync (int sd) {
+    DIR *dir;
+    struct dirent *entry;
+    const char *svalue;
+    time_t ltime;
+    char path[NAME_MAX];
 
     /* get the "install from" directory */
     plucker_get_pref (INSTALL_DIR, 0, &svalue);


More information about the Jpilot mailing list