1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/***************************************************************************
* *
* Copyright (C) 2004 Luke Kenneth Casson Leighton <lkcl@lkcl.net> *
* *
* contains code from kickermenu: *
* *
* Copyright (C) 2004 by Tommy Brander *
* tbr00001@student.mdh.se *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif
#include <Python.h>
#include "task_python.h"
#include <tqobject.h>
#include <kservicegroup.h>
#include "karamba.h"
#include "svcgrp_python.h"
static PyObject *get_svc_grp(KServiceGroup::Ptr const& g)
{
//Avoid adding empty groups.
KServiceGroup::Ptr subMenuRoot = KServiceGroup::group(g->relPath());
if (subMenuRoot->childCount() == 0)
return NULL;
// Ignore dotfiles.
if ((g->name().at(0) == '.'))
return NULL;
PyObject *tuple = PyTuple_New(2);
PyObject *dict = PyDict_New();
PyDict_SetItem(dict, PyBytes_FromString("caption"),
PyBytes_FromString(g->caption().ascii()));
if (g->comment() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("comment"),
PyBytes_FromString(g->comment().ascii()));
if (g->icon() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("icon"),
PyBytes_FromString(g->icon().ascii()));
PyDict_SetItem(dict, PyBytes_FromString("relpath"),
PyBytes_FromString(g->relPath().ascii()));
PyTuple_SET_ITEM(tuple, 0, Py_BuildValue((char*)"l", 0));
PyTuple_SET_ITEM(tuple, 1, dict);
return tuple;
}
static PyObject *get_svc(KService::Ptr const& g)
{
PyObject *tuple = PyTuple_New(2);
PyObject *dict = PyDict_New();
if (g->exec() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("exec"),
PyBytes_FromString(g->exec().ascii()));
if (g->menuId() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("menuid"),
PyBytes_FromString(g->menuId().ascii()));
if (g->name() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("name"),
PyBytes_FromString(g->name().ascii()));
if (g->path() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("path"),
PyBytes_FromString(g->path().ascii()));
if (g->icon() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("icon"),
PyBytes_FromString(g->icon().ascii()));
if (g->library() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("library"),
PyBytes_FromString(g->library().ascii()));
if (g->comment() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("comment"),
PyBytes_FromString(g->comment().ascii()));
if (g->type() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("type"),
PyBytes_FromString(g->type().ascii()));
if (g->genericName() != NULL)
PyDict_SetItem(dict, PyBytes_FromString("genericname"),
PyBytes_FromString(g->genericName().ascii()));
/*
PyDict_SetItem(dict, PyBytes_FromString("terminal"),
Py_BuildValue("l", g->terminal()));
PyDict_SetItem(dict, PyBytes_FromString("type"),
PyBytes_FromString(g->type().ascii()));
PyDict_SetItem(dict, PyBytes_FromString("username"),
PyBytes_FromString(g->username().ascii()));
PyDict_SetItem(dict, PyBytes_FromString("substuid"),
Py_BuildValue("l", g->substituteUid()));
PyDict_SetItem(dict, PyBytes_FromString("path"),
PyBytes_FromString(g->path().ascii()));
*/
PyTuple_SET_ITEM(tuple, 0, Py_BuildValue((char*)"l", 1));
PyTuple_SET_ITEM(tuple, 1, dict);
return tuple;
}
static PyObject *getServiceGroups(const char *rel_path)
{
PyObject *list = PyList_New(0);
// We ask KSycoca to give us all services (sorted).
KServiceGroup::Ptr root = KServiceGroup::group(rel_path);
if (!root || !root->isValid())
return list;
bool excludeNoDisplay_ = true;
bool detailed_ = false;
bool detailedNamesFirst_ = false;
KServiceGroup::List sl = root->entries(true, excludeNoDisplay_, true, detailed_ && !detailedNamesFirst_);
TQStringList suppressGenericNames = root->suppressGenericNames();
KServiceGroup::List::ConstIterator it = sl.begin();
for (; it != sl.end(); ++it)
{
KSycocaEntry * e = *it;
PyObject *tuple = NULL;
if (e->isType(KST_KServiceGroup)) {
KServiceGroup::Ptr g(static_cast<KServiceGroup *>(e));
tuple = get_svc_grp(g);
}
else if (e->isType(KST_KService)) {
KService::Ptr g(static_cast<KService *>(e));
tuple = get_svc(g);
}
if (tuple != NULL)
PyList_Append(list, tuple);
}
return list;
}
PyObject* py_get_service_groups(PyObject *, PyObject *args)
{
char *rel_path;
if (!PyArg_ParseTuple(args, (char*)"s:getServiceGroup", &rel_path))
return NULL;
return getServiceGroups(rel_path);
}
|