superkaramba
svcgrp_python.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifdef _XOPEN_SOURCE
00017 #undef _XOPEN_SOURCE
00018 #endif
00019
00020 #include <Python.h>
00021 #include "task_python.h"
00022 #include <tqobject.h>
00023 #include <kservicegroup.h>
00024 #include "karamba.h"
00025 #include "svcgrp_python.h"
00026
00027 static PyObject *get_svc_grp(KServiceGroup::Ptr const& g)
00028 {
00029
00030 KServiceGroup::Ptr subMenuRoot = KServiceGroup::group(g->relPath());
00031 if (subMenuRoot->childCount() == 0)
00032 return NULL;
00033
00034 if ((g->name().at(0) == '.'))
00035 return NULL;
00036
00037 PyObject *tuple = PyTuple_New(2);
00038 PyObject *dict = PyDict_New();
00039
00040 PyDict_SetItem(dict, PyBytes_FromString("caption"),
00041 PyBytes_FromString(g->caption().ascii()));
00042 if (g->comment() != NULL)
00043 PyDict_SetItem(dict, PyBytes_FromString("comment"),
00044 PyBytes_FromString(g->comment().ascii()));
00045 if (g->icon() != NULL)
00046 PyDict_SetItem(dict, PyBytes_FromString("icon"),
00047 PyBytes_FromString(g->icon().ascii()));
00048 PyDict_SetItem(dict, PyBytes_FromString("relpath"),
00049 PyBytes_FromString(g->relPath().ascii()));
00050
00051 PyTuple_SET_ITEM(tuple, 0, Py_BuildValue((char*)"l", 0));
00052 PyTuple_SET_ITEM(tuple, 1, dict);
00053
00054 return tuple;
00055 }
00056
00057
00058 static PyObject *get_svc(KService::Ptr const& g)
00059 {
00060 PyObject *tuple = PyTuple_New(2);
00061 PyObject *dict = PyDict_New();
00062
00063 if (g->exec() != NULL)
00064 PyDict_SetItem(dict, PyBytes_FromString("exec"),
00065 PyBytes_FromString(g->exec().ascii()));
00066 if (g->menuId() != NULL)
00067 PyDict_SetItem(dict, PyBytes_FromString("menuid"),
00068 PyBytes_FromString(g->menuId().ascii()));
00069 if (g->name() != NULL)
00070 PyDict_SetItem(dict, PyBytes_FromString("name"),
00071 PyBytes_FromString(g->name().ascii()));
00072 if (g->path() != NULL)
00073 PyDict_SetItem(dict, PyBytes_FromString("path"),
00074 PyBytes_FromString(g->path().ascii()));
00075 if (g->icon() != NULL)
00076 PyDict_SetItem(dict, PyBytes_FromString("icon"),
00077 PyBytes_FromString(g->icon().ascii()));
00078 if (g->library() != NULL)
00079 PyDict_SetItem(dict, PyBytes_FromString("library"),
00080 PyBytes_FromString(g->library().ascii()));
00081 if (g->comment() != NULL)
00082 PyDict_SetItem(dict, PyBytes_FromString("comment"),
00083 PyBytes_FromString(g->comment().ascii()));
00084 if (g->type() != NULL)
00085 PyDict_SetItem(dict, PyBytes_FromString("type"),
00086 PyBytes_FromString(g->type().ascii()));
00087 if (g->genericName() != NULL)
00088 PyDict_SetItem(dict, PyBytes_FromString("genericname"),
00089 PyBytes_FromString(g->genericName().ascii()));
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 PyTuple_SET_ITEM(tuple, 0, Py_BuildValue((char*)"l", 1));
00104 PyTuple_SET_ITEM(tuple, 1, dict);
00105
00106 return tuple;
00107 }
00108
00109 static PyObject *getServiceGroups(const char *rel_path)
00110 {
00111 PyObject *list = PyList_New(0);
00112
00113
00114 KServiceGroup::Ptr root = KServiceGroup::group(rel_path);
00115
00116 if (!root || !root->isValid())
00117 return list;
00118
00119 bool excludeNoDisplay_ = true;
00120 bool detailed_ = false;
00121 bool detailedNamesFirst_ = false;
00122
00123 KServiceGroup::List sl = root->entries(true, excludeNoDisplay_, true, detailed_ && !detailedNamesFirst_);
00124
00125 TQStringList suppressGenericNames = root->suppressGenericNames();
00126
00127 KServiceGroup::List::ConstIterator it = sl.begin();
00128 for (; it != sl.end(); ++it)
00129 {
00130 KSycocaEntry * e = *it;
00131
00132 PyObject *tuple = NULL;
00133 if (e->isType(KST_KServiceGroup)) {
00134 KServiceGroup::Ptr g(static_cast<KServiceGroup *>(e));
00135 tuple = get_svc_grp(g);
00136 }
00137 else if (e->isType(KST_KService)) {
00138 KService::Ptr g(static_cast<KService *>(e));
00139 tuple = get_svc(g);
00140 }
00141
00142 if (tuple != NULL)
00143 PyList_Append(list, tuple);
00144 }
00145
00146 return list;
00147 }
00148
00149 PyObject* py_get_service_groups(PyObject *, PyObject *args)
00150 {
00151 char *rel_path;
00152 if (!PyArg_ParseTuple(args, (char*)"s:getServiceGroup", &rel_path))
00153 return NULL;
00154 return getServiceGroups(rel_path);
00155 }
00156