[patch] sawfish.wm.ext.fdo-menu



Instead of doing a complete file-verification of potential .desktop
files, I added a fdo-exile function that will, if a critical key:value
combination is not found, i.e. Categories (as with spout), Exec, and
Name.  

Now, if either of those three values are not in existence in the
.desktop file (or if they are in the wrong format) then the fdo-exile
function will add values for it, namely, Categories=Exile,
NoDisplay=true, Coment="Warning", and possibly a Name=Unknown, and
possibly an Exec="sawfish-client -c 'display-errors'".  

This will both keep it from crashing on a mangled .desktop file and 
allow you to inspect those bad files if you set 'ignore-no-display to 
non-nil. 

diff --git a/lisp/sawfish/wm/ext/fdo-menu.jl b/lisp/sawfish/wm/ext/fdo-menu.jl
index cbc2ab2..dbf5d8f 100644
--- a/lisp/sawfish/wm/ext/fdo-menu.jl
+++ b/lisp/sawfish/wm/ext/fdo-menu.jl
@@ -61,10 +61,13 @@
 
     (defun get-key-break (instring key)
       (if instring
-	  (do ((mcount 0 (1+ mcount))) 
-	      ((or (string= (substring instring mcount (+ mcount 1)) "\n")
-		   (string= (substring instring mcount (+ mcount 1)) key)
-		   (= mcount 398)) mcount))))
+	  (let ((mlength (length instring)))
+	    (do ((mcount 0 (1+ mcount))) 
+		((or (string= (substring instring mcount (+ mcount 1)) "\n")
+		     (string= (substring instring mcount (+ mcount 1)) "\012")
+		     (string= (substring instring mcount (+ mcount 1)) key)
+		     (= mcount (- mlength 2))
+		     (= mcount 398)) mcount)))))
 
     (defun get-desktop-key (instring)
       (if (> (length instring) 3)
@@ -93,9 +96,8 @@
 	    (parse-desktop-file-line infile))))
 
     (defun parse-desktop-file (infile)
-      (unless (not (desktop-file-p infile))
-	(let ((d-file (open-file infile 'read)))
-	  (parse-desktop-file-line d-file))))
+      (let ((d-file (open-file infile 'read)))
+	(parse-desktop-file-line d-file)))
 
     ;; generic functions
     
@@ -206,7 +208,8 @@
 			  "FileManager" "X-FileSystemMount" "Compression"))
 	("System" . ("X-SystemSchedule" "System" "X-SystemMemory" \
 		     "TerminalEmulator" "Dictionary" "Puppy" "Printing" "Monitor" "Security"))
-	("Settings" . ("Settings" "HardwareSettings" "PackageManager"))))
+	("Settings" . ("Settings" "HardwareSettings" "PackageManager"))
+	("Exiles" . ("Exile"))))
 
     ;; Get the correct Name value based on language settings
     (defun find-lang-in-desktop-file (fdo-list)
@@ -265,12 +268,40 @@
 		      (sort (cdr (car saw-menu)) string<)) 
 		(alphabetize-entries (cdr saw-menu)))))
 
+    (defun fdo-exile (fdo-list)
+      (setq fdo-list 
+	    (append fdo-list (cons (cons "fdo-Comment" "This .desktop file was exiled, use with caution, file may be corrupt.\n"))))
+      (if (assoc "NoDisplay" fdo-list)
+	  (rplacd (assoc "NoDisplay" fdo-list) "true\n")
+	(setq fdo-list (append fdo-list (cons (cons "NoDisplay" "true\n")))))
+      (if (not (assoc "Exec" fdo-list))
+	  (setq fdo-list (append fdo-list (cons (cons "Exec" "sawfish-client -c 'display-errors'\n")))))
+      (if (and (not (assoc "Name" fdo-list))
+	       (not (assoc (concat name-string my-lang-string "]") fdo-list)))
+	  (setq fdo-list (append fdo-list (cons (cons "Name" "Unknown\n")))))
+      (if (assoc "Categories" fdo-list)
+	  (rplacd (assoc "Categories" fdo-list) "Exile\n")
+	(setq fdo-list (append fdo-list (cons (cons "Categories" "Exile\n"))))))
+
+    (defun fdo-check-exile (fdo-list)
+      (if fdo-list
+       (if (or (not (assoc "Categories" fdo-list))
+	       (not (assoc "Exec" fdo-list))
+	       (and (not (assoc "Name" fdo-list))
+		    (not (assoc (concat name-string my-lang-string "]") fdo-list))))
+	   (fdo-exile fdo-list)
+	 fdo-list)))
+
     ;; generate a saw-fish menu entry from a .desktop file
     (defun generate-menu-entry (desk-file)
       (if (and (not (file-directory-p desk-file))
 	       (desktop-file-p desk-file))
-	  (let ((fdo-list (parse-desktop-file desk-file)))
-	    (if (not (string= (cdr (assoc "NoDisplay" fdo-list)) "true\n"))
+	  (let ((fdo-list (fdo-check-exile (parse-desktop-file desk-file))))
+	    (if ignore-no-display
+		(if (assoc "NoDisplay" fdo-list)
+		    (rplacd (assoc "NoDisplay" fdo-list) "false\n")
+		  (setq fdo-list (append fdo-list (cons (cons "NoDisplay" "false\n"))))))
+       	    (if (not (string= (cdr (assoc "NoDisplay" fdo-list)) "true\n"))
 		(cons (parse-cat-list (build-cat-list (trim-end (cdr (assoc "Categories" fdo-list)))))
 		      (cons (trim-end (cdr (assoc (find-lang-in-desktop-file fdo-list) fdo-list)))
 			    (if (string= (cdr (assoc "Terminal" fdo-list)) "true\012")
-- 
Matthew Love



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]