Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » Linux "start" equivalent (Need to launch an executable?)
Linux "start" equivalent [message #44062] Sun, 21 December 2014 10:55 Go to next message
rainbowsally is currently offline  rainbowsally
Messages: 29
Registered: December 2014
Promising Member
I was having problems with functions4u in linux. And I still am, but it seems like this should be pretty simple to fix.

Linux has a 'start.exe' equivalent that will sort out the desktop environment and user-preferences for each user and the mime-linkage to applications for different file types.

It's xdg-open <file>

It discovers the user's DE and if necessary the mime-type and looks up the desktop file and extracts the "Exec=" value.

Functions4U doesn't work in linux, unfortunately, though launching the spreadsheet is quite simple.

xdg-open <name>.xls


You don't need the name of the exact binary executable that ends up being run. Might be OpenOffice -calc. Might be LibreOffice --calc. Might be a wine application. Might even be a upp output file in your home folder.

Just FYI, in case any of you linux guys didn't know that or had forgotten about it.

Re: Linux "start" equivalent [message #44077 is a reply to message #44062] Mon, 22 December 2014 21:06 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Hello rainbowsally

This is the implementation of LaunchFile() in Functions4U:

bool LaunchFile(const char *_file) {
	String file = UnixPath(_file);
	int ret;
	if (GetDesktopManagerNew() == "gnome") 
		ret = system("gnome-open \"" + String(file) + "\"");
	else if (GetDesktopManagerNew() == "kde") 
		ret = system("kfmclient exec \"" + String(file) + "\" &"); 
	else if (GetDesktopManagerNew() == "enlightenment") {
		String mime = GetExtExecutable(GetFileExt(file));
		String program = mime.Left(mime.Find("."));		// Left side of mime executable is the program to run
		ret = system(program + " \"" + String(file) + "\" &"); 
	} else 
		ret = system("xdg-open \"" + String(file) + "\"");
	return (ret >= 0);
}


Please post the details of the system where you find the problems.


Best regards
Iñaki
Re: Linux "start" equivalent [message #44080 is a reply to message #44077] Tue, 23 December 2014 09:51 Go to previous messageGo to next message
rainbowsally is currently offline  rainbowsally
Messages: 29
Registered: December 2014
Promising Member
Hi koldo.

koldo wrote on Mon, 22 December 2014 21:06
Hello rainbowsally

This is the implementation of LaunchFile() in Functions4U:

bool LaunchFile(const char *_file) {
	String file = UnixPath(_file);
	int ret;
	if (GetDesktopManagerNew() == "gnome") 
		ret = system("gnome-open \"" + String(file) + "\"");
	else if (GetDesktopManagerNew() == "kde") 
		ret = system("kfmclient exec \"" + String(file) + "\" &"); 
	else if (GetDesktopManagerNew() == "enlightenment") {
		String mime = GetExtExecutable(GetFileExt(file));
		String program = mime.Left(mime.Find("."));		// Left side of mime executable is the program to run
		ret = system(program + " \"" + String(file) + "\" &"); 
	} else 
		ret = system("xdg-open \"" + String(file) + "\"");
	return (ret >= 0);
}


Please post the details of the system where you find the problems.


I'm using Linux Mint/KDE (but also have XFCE, no gnome at present).

I think you'll find that Fuctions4U is written by a Windows user guessing at how to make it work in Linux.

First of all, the /etc/mime.cfg or whatever it is doesn't exist in Mint nor in Open[sic]SUSE, and even if it did it would ignore the USER's preferences.

I hate launching Dolphin when I need Konqueror, for example.

It's just a suggestion. Both "start.exe %s" and "xdg-open %s..." could greatly simplify the code and it would work better.
Re: Linux "start" equivalent [message #44097 is a reply to message #44080] Wed, 24 December 2014 13:45 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Hello rainbowsally

You can make me a favor Smile : please tell me the way to identify your desktop system and the best way to launch a program in your system. I mean:

- The way to identify your system
For example: environment variables (GNOME_DESKTOP_SESSION_ID in gnome, KDE_FULL_SESSION in KDE) or some text in xprop output.

- The best way to launch a program in your system
For example:
    system("kfmclient exec \"" + String(file) + "\" &"); 
    system("xdg-open \"" + String(file) + "\"");


Best regards
Iñaki
Re: Linux "start" equivalent [message #44108 is a reply to message #44097] Thu, 25 December 2014 14:08 Go to previous messageGo to next message
rainbowsally is currently offline  rainbowsally
Messages: 29
Registered: December 2014
Promising Member
Hi koldo.

koldo wrote on Wed, 24 December 2014 13:45
Hello rainbowsally

You can make me a favor Smile : please tell me the way to identify your desktop system and the best way to launch a program in your system. I mean:

- The way to identify your system
For example: environment variables (GNOME_DESKTOP_SESSION_ID in gnome, KDE_FULL_SESSION in KDE) or some text in xprop output.

- The best way to launch a program in your system
For example:
    system("kfmclient exec \"" + String(file) + "\" &"); 
    system("xdg-open \"" + String(file) + "\"");



The best way is just as you wrote above. At least for KDE. The environment variables generally have some clue as to the desktop being used.

But you may not realize this but both of the commands above do the same thing. That is kfmclient and xdg-open will both launch the same file but the xdg-open is "generic". Probably works on your Ubuntu, no?

If you like you can take a look at xdg-open. It's a script so you can pretty much tell the extents it goes to in order to figure out everything.

If Ubuntu has xdg-open, so does Mint and so does open[sic]suse.

I may also have the sources for kfmclient for kde 4.6, if you're curious about that one.

PS. xprop is for reading the "atoms" (flags and misc stuff) and icon bitmaps and things like that found in running applications. Very cool, but not much help here.

Also, if this remains important to you, let me know. I THINK we can scan the environment variables for strings containing "DE" at the end of a key OR a value (in a key-value pair) to find, or at the very least to get strong clues, about a user's current desktop environment.

I'm willing to do you a favor. Smile It just might not be necessary. Let me know.

[Updated on: Thu, 25 December 2014 14:18]

Report message to a moderator

Re: Linux "start" equivalent [message #44115 is a reply to message #44108] Thu, 25 December 2014 19:14 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Hello rainbowsally

All you say is true. However not always the standards are complied. In fact after testing some times some Linux distributions, I decided to be pragmatic and use the code that works better than use the standards.

Coming to LaunchFile(), it uses kfmclient in case of KDE and xdg-open in other cases so, is the problem that KDE is not detected by LaunchFile() in Mint?


Best regards
Iñaki
Re: Linux "start" equivalent [message #44123 is a reply to message #44115] Fri, 26 December 2014 13:37 Go to previous messageGo to next message
rainbowsally is currently offline  rainbowsally
Messages: 29
Registered: December 2014
Promising Member
Hi koldo.

[Edited a third time.]

koldo wrote on Thu, 25 December 2014 19:14


Coming to LaunchFile(), it uses kfmclient in case of KDE and xdg-open in other cases so, is the problem that KDE is not detected by LaunchFile() in Mint?


I recently realized that I was not doing MT right. I thought the "build" I had to enable that in was when I compiled the ide.

Edit #1.

To make sure UPP doesn't get blamed if a user launches a UPP application from the commandline, it's probably a good idea to use "kfmclient exec <filename> 2>/dev/null" to silence the commandline noise.

Edit #2.

Controls4U:

Wow! Okay. Smile

Now... Using Linux/Mint15/KDE though I think I'm using GTK instead of QT, if that makes any sense to you.

I'm pretty confused. I'm not sure if this is one of the apps that wouldn't run before or not, but it's pretty cool. Smile [Edit #3: Yes, it's the one.]

However...

1. The experimental file browser thinks text files are directories and says that the directory "does not exist or is not available". The problem is that the treeview in the left panel should not show files at all. The files show in the right panel.

2. Meter and Knob.

Wow! Smile

3. JB Controls. Beautiful. I like the progress bar (contrast between the text and the background).

4. Static Clock. I'd like to see the highlight fade to transparent a little more when the 'image' background is used, but very very nice!

[Edit #3: or maybe no highlight at all.]

5. Static Image and Edit file.. The file browser isn't working. That is, when I click on the right arrow, it returns immediately saying "file not found".

[Edit #3: The folder icon on the left is the active control. Not sure what the arrow on the right is for, but I was hitting the arrow.]

...

Functions 4U samples. Aha! That's what the 'functions' were. Not program functions.

Having probs with the file/download or whatever buttons on that page too. This one also has big buttons you can hit to get path and apply patch. These are not working (yet) on my system. I don't use Firefox as the default browser, but I doubt that's the problem. (??)

[Edit #3: probably the same issue. Haven't checked. Looking for MT issues that might be causing somewhat jerky movement. I noticed a Sleep(1) in the MT code for the GUI but it doesn't appear to be used.]

Wow. Just wow. Smile

Thank you koldo.

[Updated on: Fri, 26 December 2014 16:06]

Report message to a moderator

Re: Linux "start" equivalent [message #44125 is a reply to message #44123] Sat, 27 December 2014 16:03 Go to previous message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Hello rainbowsally

Thank you for the review.


Best regards
Iñaki
Previous Topic: Problems with OfficeAutomation (Solved)
Next Topic: Docking files in bazaar and uppsrc differ
Goto Forum:
  


Current Time: Tue Oct 26 15:16:31 CEST 2021

Total time taken to generate the page: 0.01156 seconds