Subject: x2gogetapps should ignore NoDisplay=true desktop application entries

From: Jason Alavaliant <[email-masked]>
Date: Tue, 10 Mar 2015 21:30:47 +1300

Package: x2goserver
Version: 4.0.1.19
Tags: patch

Currently the x2gogetapps command prints out all .desktop application 
files irrespective of if they have the value NoDisplay=true set in the 
file or not.

This results in the hosted applications list becoming filled with 
entries that weren't intended to be listed in an application menu 
normally.    For example on my system I have;

/usr/share/applications/kde4/okularApplication_comicbook.desktop 
/usr/share/applications/kde4/okularApplication_ooo.desktop
/usr/share/applications/kde4/okularApplication_dvi.desktop 
/usr/share/applications/kde4/okularApplication_pdf.desktop
/usr/share/applications/kde4/okularApplication_fax.desktop 
/usr/share/applications/kde4/okularApplication_plucker.desktop
/usr/share/applications/kde4/okularApplication_fb.desktop 
/usr/share/applications/kde4/okularApplication_txt.desktop
/usr/share/applications/kde4/okularApplication_ghostview.desktop 
/usr/share/applications/kde4/okularApplication_xps.desktop
/usr/share/applications/kde4/okularApplication_kimgio.desktop 
/usr/share/applications/kde4/okular.desktop
/usr/share/applications/kde4/okularApplication_mobi.desktop

All of them except okular.desktop  have NoDisplay=true  set in the 
file,     a normal desktop environment menu has one entry for okular 
shown since it doesn't list all of those other entries.    The x2go 
application list currently has 13 entries for okular since it displays 
every single one of the entries.

The attached patch updates the x2gogetapps command to check the file to 
see if NoDisplay=true is set and if so doesn't print out the contents of 
that file removing all the duplicates and other entries not intended to 
be listed in a normal application launch menu.

Thanks
Jason
--- old/x2gogetapps	2015-03-10 20:41:23.067019460 +1300
+++ new/x2gogetapps	2015-03-10 21:17:48.550954759 +1300
@@ -118,53 +118,68 @@
 	my $file=shift;
 	if (open(F,"<$file"))
 	{
-		print("<desktop>\n");
-		my $is_desktop_entry = 0;
+		my @all_lines;
+		my $nodisplay = 0;
 		while(!eof(F))
 		{
 			my $line=<F>;
-			if ( $line=~m/^\[Desktop Entry\] */ )
+			push(@all_lines, $line);
+			if ( $line=~m/NoDisplay=true/ )
 			{
-				$is_desktop_entry = 1;
-				next;
+				$nodisplay = 1;
 			}
-			if ( ! $is_desktop_entry )
-			{
-				next;
-			}
-			if ( $line=~m/^\[.*\] */ )
-			{
-				$is_desktop_entry = 0;
-				next;
-			}
-			if( $line=~m/^Categories/i || $line=~m/^Name/i || $line=~m/^Terminal/i || $line=~m/^Comment/i ||  $line=~m/^Exec/i)
-			{
-				print $line;
-			}
-			if( $line =~ m/^Icon/ )
+		}
+		close(F);
+		
+		if ( $nodisplay == 0 )
+		{
+			print("<desktop>\n");
+			my $is_desktop_entry = 0;
+			my $line = '';
+			foreach $line (@all_lines)
 			{
-				my $icon=$line;
-				$icon =~ s/Icon=//;
-				chop($icon);
-				#$line is absolute path
-				if($icon =~ m/\//)
+				if ( $line=~m/^\[Desktop Entry\] */ )
+				{
+					$is_desktop_entry = 1;
+					next;
+				}
+				if ( ! $is_desktop_entry )
+				{
+					next;
+				}
+				if ( $line=~m/^\[.*\] */ )
 				{
-					$icon=$icon;
+					$is_desktop_entry = 0;
+					next;
 				}
-				#$line have format ext.
-				elsif ($line =~ m/\./)
+				if( $line=~m/^Categories/i || $line=~m/^Name/i || $line=~m/^Terminal/i || $line=~m/^Comment/i ||  $line=~m/^Exec/i)
 				{
-					$icon=findicon_ext($icon);
+					print $line;
 				}
-				else
+				if( $line =~ m/^Icon/ )
 				{
-					$icon=findicon($icon);
+					my $icon=$line;
+					$icon =~ s/Icon=//;
+					chop($icon);
+					#$line is absolute path
+					if($icon =~ m/\//)
+					{
+						$icon=$icon;
+					}
+					#$line have format ext.
+					elsif ($line =~ m/\./)
+					{
+						$icon=findicon_ext($icon);
+					}
+					else
+					{
+						$icon=findicon($icon);
+					}
+					printicon($icon);
 				}
-				printicon($icon);
 			}
+			print("</desktop>\n");
 		}
-		close (F);
-		print("</desktop>\n");
 	}
 	else
 	{

---

From: Mihai Moldovan <[email-masked]>
Date: Wed, 11 Mar 2015 21:14:25 +0100

Hi Jason,

On 10.03.2015 09:30 AM, Jason Alavaliant wrote:
> [...]
> The attached patch updates the x2gogetapps command to check the file
> to see if NoDisplay=true is set and if so doesn't print out the
> contents of that file removing all the duplicates and other entries
> not intended to be listed in a normal application launch menu.

Thank you for the patch!

I've reviewed your patch and re-implemented it.

First, there's also a "Hidden" key which indicates that the application
shall be regarded as deleted (and not show up either.) We didn't respect
that either, previously.

Further, there's no need to read the whole file once we stumble upon
Hidden or NoDisplay. We can stop processing there. The same goes when
finding a non-Desktop Entry group after a Desktop Entry group.

The new patch can be seen here:

http://code.x2go.org/gitweb?p=x2goserver.git;a=commitdiff;h=e617a5baec4b8971606bf37f5cef76c29ccd7423

or downloaded here:

http://code.x2go.org/gitweb?p=x2goserver.git;a=blobdiff_plain;f=x2goserver/bin/x2gogetapps;h=84a5779c317299618b7308a48e07d4bc2e550dc8;hp=43a2fec7d606a834d828def79e49f5a2e74ad899;hb=e617a5baec4b8971606bf37f5cef76c29ccd7423;hpb=bbad5d6593df3e5659f561d2345a99ef571b30d1

Can you please test if my patch fixes your problem, too? I'd rather
commit this more complete patch to the main branches.

Mihai

---

From: Mihai Moldovan <[email-masked]>
Date: Wed, 11 Mar 2015 21:34:50 +0100

On 11.03.2015 09:14 PM, Mihai Moldovan wrote:
> [oldurl]
> [oldurl]

And of course, I messed up while moving stuff around...

Corrected new patch:

http://code.x2go.org/gitweb?p=x2goserver.git;a=commitdiff;h=6ec2dcd7e9fdc7787a6e012fdfebf117ff407918;hp=e68165a741cd234f45af286397926d1d97f3b8c5

Download URL:

http://code.x2go.org/gitweb?p=x2goserver.git;a=blobdiff_plain;f=x2goserver/bin/x2gogetapps;h=b118898b3900423e07cbb3803cc5bd4afc5eacb1;hp=43a2fec7d606a834d828def79e49f5a2e74ad899;hb=6ec2dcd7e9fdc7787a6e012fdfebf117ff407918;hpb=bbad5d6593df3e5659f561d2345a99ef571b30d1

Sorry for the confusion.

Mihai