• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
config_python.cpp
1 /****************************************************************************
2 * config_python.cpp - Functions for config python api
3 *
4 * Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
5 * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
6 * Copyright (c) 2004 Petri Damstén <damu@iki.fi>
7 *
8 * This file is part of SuperKaramba.
9 *
10 * SuperKaramba is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * SuperKaramba is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with SuperKaramba; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 ****************************************************************************/
24 
25 #ifdef _XOPEN_SOURCE
26 #undef _XOPEN_SOURCE
27 #endif
28 
29 #include <Python.h>
30 #include <tqobject.h>
31 #include "karamba.h"
32 #include "meter.h"
33 #include "meter_python.h"
34 #include "config_python.h"
35 
36 // API-Function addMenuConfigOption
37 long addMenuConfigOption(long widget, TQString key, TQString name)
38 {
39  karamba* currTheme = (karamba*)widget;
40 
41  currTheme -> addMenuConfigOption(key, name);
42 
43  return 1;
44 }
45 
46 PyObject* py_add_menu_config_option(PyObject *, PyObject *args)
47 {
48  long widget;
49  char* key;
50  PyObject* name;
51 
52  if (!PyArg_ParseTuple(args, (char*)"lsO:addMenuConfigOption", &widget, &key, &name))
53  return NULL;
54  if (!checkKaramba(widget))
55  return NULL;
56 
57  TQString k, n;
58  k.setAscii(key);
59  n = PyString2TQString(name);
60 
61  return Py_BuildValue((char*)"l", addMenuConfigOption(widget, k, n));
62 }
63 
64 long setMenuConfigOption(long widget, TQString key, bool value)
65 {
66  karamba* currTheme = (karamba*)widget;
67 
68  return currTheme -> setMenuConfigOption(key, value);
69 }
70 
71 PyObject* py_set_menu_config_option(PyObject *, PyObject *args)
72 {
73  long widget;
74  char* key;
75  int value;
76 
77  if (!PyArg_ParseTuple(args, (char*)"lsi:setMenuConfigOption", &widget, &key, &value))
78  return NULL;
79  if (!checkKaramba(widget))
80  return NULL;
81 
82  TQString k;
83  k.setAscii(key);
84 
85  return Py_BuildValue((char*)"l", setMenuConfigOption(widget, k, (bool)value));
86 }
87 
88 long readMenuConfigOption(long widget, TQString key)
89 {
90  karamba* currTheme = (karamba*)widget;
91 
92  return currTheme -> readMenuConfigOption(key);
93 }
94 
95 PyObject* py_read_menu_config_option(PyObject *, PyObject *args)
96 {
97  long widget;
98  char* key;
99 
100  if (!PyArg_ParseTuple(args, (char*)"ls:readMenuConfigOption", &widget, &key))
101  return NULL;
102  if (!checkKaramba(widget))
103  return NULL;
104 
105  TQString k;
106  k.setAscii(key);
107 
108  return Py_BuildValue((char*)"l", readMenuConfigOption(widget, k));
109 }
110 
111 // API-Function writeConfigEntry
112 long writeConfigEntry(long widget, TQString key, TQString value)
113 {
114  karamba* currTheme = (karamba*)widget;
115 
116  currTheme -> config -> setGroup("theme");
117  currTheme -> config -> writeEntry(key, value);
118 
119  return 1;
120 }
121 
122 PyObject* py_write_config_entry(PyObject *, PyObject *args)
123 {
124  long widget;
125  char* key;
126  char* value;
127 
128  if (!PyArg_ParseTuple(args, (char*)"lss:writeConfigEntry", &widget, &key, &value))
129  return NULL;
130  if (!checkKaramba(widget))
131  return NULL;
132  TQString k, v;
133  k.setAscii(key);
134  v.setAscii(value);
135 
136  return Py_BuildValue((char*)"l", writeConfigEntry(widget, k, value));
137 }
138 
139 // API-Function readConfigEntry
140 TQVariant readConfigEntry(long widget, TQString key)
141 {
142  karamba* currTheme = (karamba*)widget;
143 
144  currTheme -> config -> setGroup("theme");
145  return currTheme -> config -> readEntry(key);
146 }
147 
148 PyObject* py_read_config_entry(PyObject *, PyObject *args)
149 {
150  long widget;
151  char* key;
152  if (!PyArg_ParseTuple(args, (char*)"ls:readConfigEntry", &widget, &key))
153  return NULL;
154  if (!checkKaramba(widget))
155  return NULL;
156  TQString k;
157  k.setAscii(key);
158 
159  TQVariant entry = readConfigEntry(widget, k);
160  TQString type;
161  type.setAscii(entry.typeName());
162 
163  if (type == "Bool")
164  {
165  return Py_BuildValue((char*)"l", (int)entry.toBool());
166  }
167 
168  bool isint = false;
169  int i = entry.toInt(&isint);
170  if (isint)
171  {
172  return Py_BuildValue((char*)"l", i);
173  }
174 
175  if (type == "TQString")
176  {
177  return Py_BuildValue((char*)"s", entry.toString().ascii());
178  }
179  // Add more types if needed
180  return NULL;
181 }
182 

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.8.13
This website is maintained by Timothy Pearson.