Refactor to use new protocol module and sipo.
[bertos.git] / wizard / qvariant_converter_4_6.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of bertos.
5 #
6 # Slimqc is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 #
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction.  Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License.  This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
28 #
29 # Copyright 2009 Develer S.r.l. (http://www.develer.com/)
30 #
31 #
32 # Author: Lorenzo Berni <duplo@develer.com>
33 #
34
35 from PyQt4.QtCore import *
36
37 def getString(qvariant):
38     if type(qvariant) != QVariant:
39         return qvariant
40     string = unicode(qvariant.toString())
41     return string
42
43 def convertString(string):
44     return QVariant(string)
45
46 def getStringList(qvariant):
47     if type(qvariant) == QVariant:
48         tmp = qvariant.toPyObject()
49     else:
50         tmp = qvariant
51     string_list = []
52     if tmp:
53         string_list = [unicode(string) for string in tmp]
54     return string_list
55
56 def convertStringList(string_list):
57     return QVariant(string_list)
58
59 def getStringDict(qvariant):
60     dict_str_str = {}
61     try:
62         for key, value in qvariant.toPyObject().items():
63             dict_str_str[unicode(key)] = unicode(value)
64     except:
65         pass
66     return dict_str_str
67
68 def convertStringDict(string_dict):
69     return QVariant(string_dict)
70
71 def getBool(qvariant):
72     return qvariant.toBool()
73
74 def convertBool(boolean):
75     return QVariant(boolean)
76
77 def getBoolDict(qvariant):
78     dict_str_bool = {}
79     try:
80         for key, value in qvariant.toPyObject().items():
81             dict_str_bool[unicode(key)] = value
82     except:
83         pass
84     return dict_str_bool
85
86 def convertBoolDict(dict_str_bool):
87     return QVariant(dict_str_bool)
88
89 def getDict(qvariant):
90     dict_str_variant = {}
91     try:
92         for key, value in qvariant.toMap().items():
93             dict_str_variant[unicode(key)] = value
94     except:
95         pass
96     return dict_str_variant
97
98 def convertDict(dict_str_variant):
99     result_dict = {}
100     for key, value in dict_str_variant.items():
101         result_dict[QString(key)] = QVariant(value)
102     return QVariant(result_dict)