This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[SOLVED] Retrieve items in the Kmenu

Tags: None
(comma "," separated)
User avatar
darkman
Registered Member
Posts
13
Karma
0
OS

[SOLVED] Retrieve items in the Kmenu

Sun Feb 22, 2009 11:21 am
ok, another question.

I would like to retrieive the items in the kmenu with my application (and also all the submenus).

I searched everywhere (api, tutorial, documentation, source code of some plasma-application) but I found absolutely nothing about this (a lot of source code of plasma-application is NOT well commented :-( , and this makes reading the code very difficult).

what kind of object in the api i have to use?
thanks in advance


My belly is full of theory but when I play I forget it all - Al di Meola
--------------
darkman, proud to be a member of KDE forums since 2008-Nov.
User avatar
beermad
Registered Member
Posts
104
Karma
0
OS
darkman wrote:I would like to retrieive the items in the kmenu with my application (and also all the submenus).


The contents of ~/.config/menus/applications-kmenuedit.menu MIGHT be what you're looking for.


User avatar
darkman
Registered Member
Posts
13
Karma
0
OS

[SOLVED] Retrieve items in the Kmenu

Sun Feb 22, 2009 11:39 pm
beermad wrote:The contents of ~/.config/menus/applications-kmenuedit.menu MIGHT be what you're looking for.


no, it's not what i'm looking for... atch! this file doesn't have the information that i'm looking for.
i'm trying to create an alternative applet-menu with plasma. so i would like to retrieve the structure of the menù in kde (and visualize them).
for example... this may be a structure of my menu:

Multimedia
-->amarok
-->mplayer
...
Office
-->oowriter
-->acroread
Wine
-->somethingelse

and so on.
Ok, i'll try to explain me in other words. If i take a look at my menu (i'm using lancelot) in kde i see that there is a "structure". all applications can be found within a few submenus. If I try to use any other menu (for example, the standard in kde) I see that the "structure" remains unchanged. So, I assume that there is a way to read this "structure" in the menu. I think that there is an object or a query that gives me these informations.
uhm .. it is clear what I'm looking for?


My belly is full of theory but when I play I forget it all - Al di Meola
--------------
darkman, proud to be a member of KDE forums since 2008-Nov.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You would probably use KDesktopFile to read the information from the files.
KServiceTypeTrader can probably help you with retrieving the list of all the applicable files.

Real Usage of them can be found through lxr.kde.org
The Documentation is available from api.kde.org

Last edited by bcooksley on Mon Feb 23, 2009 6:01 am, edited 1 time in total.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
darkman
Registered Member
Posts
13
Karma
0
OS
bcooksley wrote:You would probably use KDesktopFile to read the information from the files.
KServiceTypeTrader can probably help you with retrieving the list of all the applicable files.


Thank you. it's exactly what i was looking for!

Code: Select all
/*I make a query to kde and i recieve the list of the applications in kmenu*/
  KService::List offers = KServiceTypeTrader::self()->query("Application");
 
  /*now i'll take all the elements in the list*/
  foreach (const KService::Ptr &service, offers)
  {
    KPluginInfo description(service);
   
    QString runnerName = description.name();
    QString categoryName = description.category();
 
    std::cout query("Application");

Last edited by darkman on Tue Feb 24, 2009 7:41 pm, edited 1 time in total.


My belly is full of theory but when I play I forget it all - Al di Meola
--------------
darkman, proud to be a member of KDE forums since 2008-Nov.
User avatar
darkman
Registered Member
Posts
13
Karma
0
OS
i think it's a bit complicated, but it works.... (if someone of you have a better idea, please tell me :-) )
hope it will be usefull

Code: Select all
  /*I make a query to kde and i recieve the list of the applications in kmenu*/
  KService::List offers = KServiceTypeTrader::self()->query("Application");
 
  /*now i'll take all the elements in the list*/
  foreach (const KService::Ptr service, offers)
  {
    /*i create an object to take the information of the result*/
    KPluginInfo plugin(service);
    /*i'll take the name Of the Object*/
    QString runnerName = plugin.name();
    /*extraction the full path*/
    QString categoryName = plugin.entryPath();
    /*taked the full path, i'll create a kdesktop file to catch the category information*/
    KDesktopFile desktopFile(categoryName);
    /*this is the category of the program*/
    QString nome = desktopFile.desktopGroup().readEntry("Categories");


Well, the categories that this code returns it exactly what the filed "Categories" says in the .dektop files. Sometimes this field has many cateogies instead of only one. Often these categories don't match with the category in the kmenu.. ufff...
uff... how can i do?
For example:
The application the program says that Ardour is in the category Audio (and something else), but in ALL kmenus it's located under "Multimedia". Maybe i don't have to look at "category" field, but where can i find the information i want?

Last edited by darkman on Tue Feb 24, 2009 10:46 pm, edited 1 time in total.


My belly is full of theory but when I play I forget it all - Al di Meola
--------------
darkman, proud to be a member of KDE forums since 2008-Nov.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Maybe categories themselves have "Categories"?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
darkman
Registered Member
Posts
13
Karma
0
OS

[SOLVED] Retrieve items in the Kmenu

Wed Feb 25, 2009 11:31 pm
uhm... boh!
i don't know, i don't understood too much. the field "category" doesn't have more informations.
I took a look at the application "kmenuedit" and "kickoff". i read a lot of its code (uncommented :-@) but i haven't yet found nothing that may help me.
both applications don't use any "query" as i do, so i think that i have to search elsewhere the solution of my problem.

[ot]
ps: why people that develop application for kde don't make comments in the source code? :-@ [/ot]

----------------------------------------------------------------------------------------------------------
taking a look at kickoff source code i found:
Code: Select all
(from ApplicationModelPrivate)
00108         systemApplications = Kickoff::systemApplicationList();
.....
(from models.h)
00152 QStringList Kickoff::systemApplicationList()
00153 {
00154     KConfigGroup appsGroup = componentData().config()->group("SystemApplications");
00155     QStringList apps;
00156     apps group("SystemApplications");
  QStringList name;
  name = appsGroup.readEntry("DesktopFiles", name);
   kDebug()group("SystemApplications");
  QStringList name;
  name = appsGroup.readEntry("DesktopFiles", name);
  /*if you chanfe QString() with QString("Multimedia/") you recive all the application and folders inside the folder menu Multimedia */
  KServiceGroup::Ptr root = KServiceGroup::group(QString());

  KServiceGroup::List list = root->entries(true /* sorted */,
                                                    true /* exclude no display entries */,
                                                    false /* allow separators */,
                                                    false);
   
 for (KServiceGroup::List::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it)
{

  KSycocaEntry::Ptr p = (*it);
QString icon;
         QString appName;
         QString genericName;
         QString relPath = QString();
         QString desktopEntry;

KService::Ptr service = KService::Ptr::staticCast(p);
icon = service->icon();
              appName = service->name();
               desktopEntry = service->entryPath();
    kDebug()<< appName+","+desktopEntry;
}



Don't ask me the meaning of what i've done... i don't know, but it works! :-D
Hope this helps

Last edited by darkman on Thu Feb 26, 2009 9:36 am, edited 1 time in total.


My belly is full of theory but when I play I forget it all - Al di Meola
--------------
darkman, proud to be a member of KDE forums since 2008-Nov.


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell