How can I put my GTK application in the desktop menus? - linux

I started with programming a little time ago and I created my first running application with GTK 3.0. I did not use Glade, I do not know if worth highlight it. My code is working perfectly, but now I have a doubt, how can I make my own desktop menu application? I mean, I want that my application running up without compile in a terminal with GTK 3.0 compiler, but yes with a double click.
I have been seen these examples provided by GNOME Developer Center, but I confess that did not understand it: https://developer.gnome.org/integration-guide/stable/desktop-files.html.en#ex-sample-desktop-file
The idea is to create a file containing this sequence of lines:
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Sample Application Name
Comment=A sample application
Exec=application
Icon=application.png
Terminal=false
This file is my executable or it is a different file which points to my executable? If it is my executable, where can I insert it?
Thank you!

So basically this file will create a desktop entry for those configurations you provide for the corresponding directives in the file. Judging by your question, you are unable to find where to place your application executable in that directive.
Exec="/absolute/path/to/your/executable/file"
And the Name directive will hold the information of your application name. This is the one you will be querying for in your gnome applications search (which appears when you press the windows key).
This file will contain a .desktop extension. And this file itself is not executable. This will point to your application, making the gnome/ubuntu system understand that such application exists.
This will not directly create a desktop shortcut as in Windows, rather this will index your application which you can run from the application menu (ubuntu or gnome)
If you aren't sure where to place the file here's a hint from the documentation you linked.
Place this file in the /usr/share/applications directory so that it is accessible by everyone, or in ~/.local/share/applications if you only wish to make it accessible to a single user

Related

Linux - recommended apps to open a file

In Ubuntu Linux, let's say I create a simple text file. When I right click that file, there is option to open with other application. It will show a list of recommeded applications which could open a text file.
My question is that how does the OS know which app can open that file ? What does the app developer have to do to make it a candidate ?
Edit : What I also want to ask is that does the OS verify this in any way (that the developer has specified the app to open a particular file format) ; for e.g. a video playing application could mention itself to open a text file, but when the user tries to use it, there will be a problem.
Try creating Your app's .desktop file for showing your app in the Open with other application dialog. the .desktop file should look something like this
[Desktop Entry]
Encoding=UTF-8
Name=<appName>
Comment= some detail about the app
Exec=<appName> %u
Terminal=true
Type=Application
Icon=/usr/share/pixmaps/<appName>.svg
Categories=Application;Utility;TextEditor;
StartupNotify=true
MimeType=text/plain;
NoDisplay=true
Save this as ~/.local/share/applications/<appName>.desktop and the application will be automatically shown on Open with other application to be selected as default application.
The options for the .desktop files are many but its important to know what they mean.
nautilus-actions.org supplies a very good guide and explanations for creating your .desktop files and all the possible parameters that you can use on them so if you have any doubts about creating a special .desktop file you can visit the site and look at the examples there.
Note:- not sure if OS verifies if its a video playing application or not, but even if it would it will verify with MimeType and if the app have txt/plain and it a video player it would fail, but again i'm not sure on this.

Desktop icon in linux ubuntu qt [duplicate]

This question already has an answer here:
Qt Creator - how to set application icon for ubuntu linux?
(1 answer)
Closed 8 years ago.
Can someone give me a strait up answer on how to set up application icon in linux.
I have an application developed in Qt and I wont to show it on desktop but I wont to change it's default icon. I know that in linux I can't make icon as part of binary but how to connect icon with application?
Thanks...
Unix binaries don’t know about the concept resources of icons. Instead, a desktop entry file is used to describe each application. These files have the file name extension of desktop and are usually stored in $XDG_DATA_DIRS/applications or /usr/share/applications.
An Example of a .desktop file:
[Desktop Entry]
Type=Application
Name=My Application
Exec=myapplication %F
MimeType=image/x-mydata;
Icon=/install/path/myicon.png
The line reading [Desktop Entry] tells you that what follows is an entry for a desktop entry. Next is Type, which tells you that the entry will describe an application. According to Name, the application is called My Application. The Exec line tells the desktop what command to issue to start the application; in this case, it is myapplication. The %F part tells the desktop where to list the file names if a user starts the application by trying to open one or more data files. The connection between these data files and the application is handled using the MimeType entry that defines the mime type; that is, the file type that the application handles. The last line, Icon, tells you which icon to use. The easiest way is to specify an absolute path to the icon. If you specify only the file name, you must determine where to store the icon file so that the desktop environment can find it.
When installing applications on Unix, it is common to support the make target install,
which enables the user to type make install to copy the application files to a global location.
This is supported by QMake using install sets.

Creating a menu item generically in Linux

For part of a large university project I have built a large java based application. To make "installation" cleaner I am aiming to write a script to copy the jar to a hidden file in the users home directory then add a menu &/Or desktop launcher.
Since I do not know what platform the markers shall be using it seems sensible to make this generic so I was going to build a shell script and a batch file.
The shell script starts off simple, check the directory doesnt already exist, make it and copy the file accross.
Then it comes to making a launcher of some kind. I presume each desktop environment shall do things differently.
After 10 minutes with google it seems everything suggested is autotools but since I have no knowledge of this it seems a bit overkill.
Is there an easy way to achieve what i need?
Thanks
These days, basically all of the desktop environments uses desktop files. For the specification for those files, see the Desktop Entry Specification.
Normally, they're put in /usr/share/applications on the system. Those files are then read and used to construct the menu.
If you have the ability to write to the system /usr/share/applications directory, that's obviously simplest, but if you had that, you would probably be putting the JAR file somewhere other than a hidden directory in the user's home directory.
If not, the path that's supposed to be honored is ~/.local/share/applications. If you drop a desktop file in there, it should show up for the user. (This is somewhat newer; I don't think GNOME 2 supports, it for example. Older desktop environments had various special places for these files.)
Then, the problem basically reduces to figuring out what to write for the Exec line in the desktop file. (See the desktop files on your system in /usr/share/applications for some examples.) If you're lucky, you can get away with just sticking a java command in there, but the details will depend on your application.

Can i merge icon with executable application in linux?

if you made up an application in linux you will get a blank ugly icon
but if i wanted to add an icon without going and make a desktop entry , is it possible ?
if i uploaded my portable app to the internet i would like that users see the icon merged to my portable app ! :)
Thanks
For scripts probably not, but for ELF binaries seen under Gnome (nautilus) you can try
elfres
http://www.compholio.com/elfres/
Most desktop environments on Linux follow the freedesktop.org Desktop Entry Specification for application descriptions and icons. You'll need a separate .desktop file in one of the XDG directories (specifically, applications within one of $XDG_DATA_DIRS) which will list an icon (which is an image file in another directory).

Running a Qt application at startup

I wrote a Qt application that is going to run on Linux. It supposed to run at startup.
It's supposed to run on every Linux- Suse, RedHat etc.
What script should I write and Where to put it?
I don't know how to write scripts at all, so I would appreciate it if you will attach an example.
You need to create a desktop entry file for your application (see here) and to put it in user's $HOME/.config/autostart directory.
Any desktop entry file in that dir will get executed when a Window Manager starts up (see here).
To do this, usually you'll need to create your desktop entry file by hand (that's it, not via C++ code/script) and to just install in that directory via C++ code.

Resources