Chris Cromer 5 months ago
parent
commit
9c5c7f1e7d
Signed by: Chris Cromer <chris@cromer.cl> GPG Key ID: 39CC813FF3C8708A

+ 0
- 14
build_linux_package.sh View File

@@ -1,14 +0,0 @@
1
-#!/bin/sh -eu
2
-
3
-curdir=`pwd`
4
-rm -rf buildtmp
5
-mkdir buildtmp
6
-LDFLAGS=-static-libstdc++ meson buildtmp -D bundle_libs=false -D valadocs_deps=false --buildtype=release --prefix=/tmp/sernatur --libdir=lib --strip
7
-ninja -C buildtmp install
8
-rm -rf buildtmp
9
-cp README.md /tmp/sernatur
10
-cp LICENSE /tmp/sernatur
11
-cd /tmp/
12
-tar czf sernatur.tar.gz sernatur
13
-mv sernatur.tar.gz "$curdir"
14
-rm -rf sernatur

+ 0
- 1
data/etc/meson.build View File

@@ -1 +0,0 @@
1
-install_data('sernatur.conf', install_dir: join_paths(get_option('prefix'), get_option('sysconfdir'), 'sernatur'))

+ 0
- 9
data/etc/sernatur.conf View File

@@ -1,9 +0,0 @@
1
-database : {
2
-	host = "localhost";
3
-	port = 5432;
4
-	options = "";
5
-	gtty = "";
6
-	db_name = "bdd";
7
-	login = "bdd";
8
-	pwd = "bdd";
9
-};

+ 35
- 0
data/gschema/cl.cromer.ubb.sernatur.gschema.xml View File

@@ -14,5 +14,40 @@
14 14
 				Port number to use
15 15
 			</description>
16 16
 		</key>
17
+		<key name="options" type="s">
18
+			<default>""</default>
19
+			<summary>Options to use</summary>
20
+			<description>
21
+				Options to use
22
+			</description>
23
+		</key>
24
+		<key name="tty" type="s">
25
+			<default>""</default>
26
+			<summary>tty to send debug info (ignored)</summary>
27
+			<description>
28
+				tty to send debug info (ignored)
29
+			</description>
30
+		</key>
31
+		<key name="database" type="s">
32
+			<default>"bdd"</default>
33
+			<summary>Database to use</summary>
34
+			<description>
35
+				Database to use
36
+			</description>
37
+		</key>
38
+		<key name="username" type="s">
39
+			<default>"bdd"</default>
40
+			<summary>Username to use</summary>
41
+			<description>
42
+				Username to use
43
+			</description>
44
+		</key>
45
+		<key name="password" type="s">
46
+			<default>"bdd"</default>
47
+			<summary>Password to use</summary>
48
+			<description>
49
+				Password to use
50
+			</description>
51
+		</key>
17 52
 	</schema>
18 53
 </schemalist>

+ 0
- 1
data/meson.build View File

@@ -1,5 +1,4 @@
1 1
 subdir('ui')
2
-subdir('etc')
3 2
 subdir('gschema')
4 3
 subdir('desktop')
5 4
 subdir('icons')

+ 170
- 167
data/ui/sernatur.window.ui View File

@@ -1,5 +1,5 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<!-- Generated with glade 3.22.1
2
+<!-- Generated with glade 3.22.1 
3 3
 
4 4
 Copyright 2018 Chris Cromer
5 5
 
@@ -17,185 +17,188 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 17
 <interface>
18 18
   <requires lib="gtk+" version="3.10"/>
19 19
   <template class="SernaturMainWindow" parent="GtkApplicationWindow">
20
-  <property name="can_focus">False</property>
21
-  <property name="title">SERNATUR</property>
22
-  <property name="icon_name">sernatur</property>
23
-  <property name="show_menubar">False</property>
24
-  <child>
25
-    <object class="GtkBox" id="mainbox">
26
-    <property name="visible">True</property>
27 20
     <property name="can_focus">False</property>
28
-    <property name="orientation">vertical</property>
21
+    <property name="title">SERNATUR</property>
22
+    <property name="icon_name">sernatur</property>
23
+    <property name="show_menubar">False</property>
29 24
     <child>
30
-      <object class="GtkMenuBar" id="menubar">
31
-      <property name="visible">True</property>
32
-      <property name="can_focus">False</property>
33
-      <child>
34
-        <object class="GtkMenuItem">
35
-        <property name="visible">True</property>
36
-        <property name="can_focus">False</property>
37
-        <property name="label" translatable="yes">_File</property>
38
-        <property name="use_underline">True</property>
39
-        <child type="submenu">
40
-          <object class="GtkMenu">
41
-          <property name="visible">True</property>
42
-          <property name="can_focus">False</property>
43
-          <child>
44
-            <object class="GtkImageMenuItem">
45
-            <property name="label">gtk-new</property>
46
-            <property name="visible">True</property>
47
-            <property name="can_focus">False</property>
48
-            <property name="use_underline">True</property>
49
-            <property name="use_stock">True</property>
50
-            </object>
51
-          </child>
52
-          <child>
53
-            <object class="GtkImageMenuItem">
54
-            <property name="label">gtk-open</property>
55
-            <property name="visible">True</property>
56
-            <property name="can_focus">False</property>
57
-            <property name="use_underline">True</property>
58
-            <property name="use_stock">True</property>
59
-            </object>
60
-          </child>
61
-          <child>
62
-            <object class="GtkImageMenuItem">
63
-            <property name="label">gtk-save</property>
64
-            <property name="visible">True</property>
65
-            <property name="can_focus">False</property>
66
-            <property name="use_underline">True</property>
67
-            <property name="use_stock">True</property>
68
-            </object>
69
-          </child>
70
-          <child>
71
-            <object class="GtkImageMenuItem">
72
-            <property name="label">gtk-save-as</property>
73
-            <property name="visible">True</property>
74
-            <property name="can_focus">False</property>
75
-            <property name="use_underline">True</property>
76
-            <property name="use_stock">True</property>
77
-            </object>
78
-          </child>
79
-          <child>
80
-            <object class="GtkSeparatorMenuItem">
81
-            <property name="visible">True</property>
82
-            <property name="can_focus">False</property>
83
-            </object>
84
-          </child>
85
-          <child>
86
-            <object class="GtkImageMenuItem">
87
-            <property name="label">gtk-quit</property>
88
-            <property name="visible">True</property>
89
-            <property name="can_focus">False</property>
90
-            <property name="use_underline">True</property>
91
-            <property name="use_stock">True</property>
92
-            </object>
93
-          </child>
94
-          </object>
95
-        </child>
96
-        </object>
97
-      </child>
98
-      <child>
99
-        <object class="GtkMenuItem">
25
+      <placeholder/>
26
+    </child>
27
+    <child>
28
+      <object class="GtkBox" id="mainbox">
100 29
         <property name="visible">True</property>
101 30
         <property name="can_focus">False</property>
102
-        <property name="label" translatable="yes">_Edit</property>
103
-        <property name="use_underline">True</property>
104
-        <child type="submenu">
105
-          <object class="GtkMenu">
106
-          <property name="visible">True</property>
107
-          <property name="can_focus">False</property>
108
-          <child>
109
-            <object class="GtkImageMenuItem">
110
-            <property name="label">gtk-cut</property>
111
-            <property name="visible">True</property>
112
-            <property name="can_focus">False</property>
113
-            <property name="use_underline">True</property>
114
-            <property name="use_stock">True</property>
115
-            </object>
116
-          </child>
117
-          <child>
118
-            <object class="GtkImageMenuItem">
119
-            <property name="label">gtk-copy</property>
120
-            <property name="visible">True</property>
121
-            <property name="can_focus">False</property>
122
-            <property name="use_underline">True</property>
123
-            <property name="use_stock">True</property>
124
-            </object>
125
-          </child>
126
-          <child>
127
-            <object class="GtkImageMenuItem">
128
-            <property name="label">gtk-paste</property>
129
-            <property name="visible">True</property>
130
-            <property name="can_focus">False</property>
131
-            <property name="use_underline">True</property>
132
-            <property name="use_stock">True</property>
133
-            </object>
134
-          </child>
135
-          <child>
136
-            <object class="GtkImageMenuItem">
137
-            <property name="label">gtk-delete</property>
31
+        <property name="orientation">vertical</property>
32
+        <child>
33
+          <object class="GtkMenuBar" id="menubar">
138 34
             <property name="visible">True</property>
139 35
             <property name="can_focus">False</property>
140
-            <property name="use_underline">True</property>
141
-            <property name="use_stock">True</property>
142
-            </object>
143
-          </child>
36
+            <child>
37
+              <object class="GtkMenuItem">
38
+                <property name="visible">True</property>
39
+                <property name="can_focus">False</property>
40
+                <property name="label" translatable="yes">_File</property>
41
+                <property name="use_underline">True</property>
42
+                <child type="submenu">
43
+                  <object class="GtkMenu">
44
+                    <property name="visible">True</property>
45
+                    <property name="can_focus">False</property>
46
+                    <child>
47
+                      <object class="GtkImageMenuItem">
48
+                        <property name="label">gtk-new</property>
49
+                        <property name="visible">True</property>
50
+                        <property name="can_focus">False</property>
51
+                        <property name="use_underline">True</property>
52
+                        <property name="use_stock">True</property>
53
+                      </object>
54
+                    </child>
55
+                    <child>
56
+                      <object class="GtkImageMenuItem">
57
+                        <property name="label">gtk-open</property>
58
+                        <property name="visible">True</property>
59
+                        <property name="can_focus">False</property>
60
+                        <property name="use_underline">True</property>
61
+                        <property name="use_stock">True</property>
62
+                      </object>
63
+                    </child>
64
+                    <child>
65
+                      <object class="GtkImageMenuItem">
66
+                        <property name="label">gtk-save</property>
67
+                        <property name="visible">True</property>
68
+                        <property name="can_focus">False</property>
69
+                        <property name="use_underline">True</property>
70
+                        <property name="use_stock">True</property>
71
+                      </object>
72
+                    </child>
73
+                    <child>
74
+                      <object class="GtkImageMenuItem">
75
+                        <property name="label">gtk-save-as</property>
76
+                        <property name="visible">True</property>
77
+                        <property name="can_focus">False</property>
78
+                        <property name="use_underline">True</property>
79
+                        <property name="use_stock">True</property>
80
+                      </object>
81
+                    </child>
82
+                    <child>
83
+                      <object class="GtkSeparatorMenuItem">
84
+                        <property name="visible">True</property>
85
+                        <property name="can_focus">False</property>
86
+                      </object>
87
+                    </child>
88
+                    <child>
89
+                      <object class="GtkImageMenuItem">
90
+                        <property name="label">gtk-quit</property>
91
+                        <property name="visible">True</property>
92
+                        <property name="can_focus">False</property>
93
+                        <property name="use_underline">True</property>
94
+                        <property name="use_stock">True</property>
95
+                      </object>
96
+                    </child>
97
+                  </object>
98
+                </child>
99
+              </object>
100
+            </child>
101
+            <child>
102
+              <object class="GtkMenuItem">
103
+                <property name="visible">True</property>
104
+                <property name="can_focus">False</property>
105
+                <property name="label" translatable="yes">_Edit</property>
106
+                <property name="use_underline">True</property>
107
+                <child type="submenu">
108
+                  <object class="GtkMenu">
109
+                    <property name="visible">True</property>
110
+                    <property name="can_focus">False</property>
111
+                    <child>
112
+                      <object class="GtkImageMenuItem">
113
+                        <property name="label">gtk-cut</property>
114
+                        <property name="visible">True</property>
115
+                        <property name="can_focus">False</property>
116
+                        <property name="use_underline">True</property>
117
+                        <property name="use_stock">True</property>
118
+                      </object>
119
+                    </child>
120
+                    <child>
121
+                      <object class="GtkImageMenuItem">
122
+                        <property name="label">gtk-copy</property>
123
+                        <property name="visible">True</property>
124
+                        <property name="can_focus">False</property>
125
+                        <property name="use_underline">True</property>
126
+                        <property name="use_stock">True</property>
127
+                      </object>
128
+                    </child>
129
+                    <child>
130
+                      <object class="GtkImageMenuItem">
131
+                        <property name="label">gtk-paste</property>
132
+                        <property name="visible">True</property>
133
+                        <property name="can_focus">False</property>
134
+                        <property name="use_underline">True</property>
135
+                        <property name="use_stock">True</property>
136
+                      </object>
137
+                    </child>
138
+                    <child>
139
+                      <object class="GtkImageMenuItem">
140
+                        <property name="label">gtk-delete</property>
141
+                        <property name="visible">True</property>
142
+                        <property name="can_focus">False</property>
143
+                        <property name="use_underline">True</property>
144
+                        <property name="use_stock">True</property>
145
+                      </object>
146
+                    </child>
147
+                  </object>
148
+                </child>
149
+              </object>
150
+            </child>
151
+            <child>
152
+              <object class="GtkMenuItem">
153
+                <property name="visible">True</property>
154
+                <property name="can_focus">False</property>
155
+                <property name="label" translatable="yes">_View</property>
156
+                <property name="use_underline">True</property>
157
+              </object>
158
+            </child>
159
+            <child>
160
+              <object class="GtkMenuItem">
161
+                <property name="visible">True</property>
162
+                <property name="can_focus">False</property>
163
+                <property name="label" translatable="yes">_Help</property>
164
+                <property name="use_underline">True</property>
165
+                <child type="submenu">
166
+                  <object class="GtkMenu">
167
+                    <property name="visible">True</property>
168
+                    <property name="can_focus">False</property>
169
+                    <child>
170
+                      <object class="GtkImageMenuItem">
171
+                        <property name="label">gtk-about</property>
172
+                        <property name="visible">True</property>
173
+                        <property name="can_focus">False</property>
174
+                        <property name="use_underline">True</property>
175
+                        <property name="use_stock">True</property>
176
+                      </object>
177
+                    </child>
178
+                  </object>
179
+                </child>
180
+              </object>
181
+            </child>
144 182
           </object>
183
+          <packing>
184
+            <property name="expand">False</property>
185
+            <property name="fill">True</property>
186
+            <property name="position">0</property>
187
+          </packing>
145 188
         </child>
146
-        </object>
147
-      </child>
148
-      <child>
149
-        <object class="GtkMenuItem">
150
-        <property name="visible">True</property>
151
-        <property name="can_focus">False</property>
152
-        <property name="label" translatable="yes">_View</property>
153
-        <property name="use_underline">True</property>
154
-        </object>
155
-      </child>
156
-      <child>
157
-        <object class="GtkMenuItem">
158
-        <property name="visible">True</property>
159
-        <property name="can_focus">False</property>
160
-        <property name="label" translatable="yes">_Help</property>
161
-        <property name="use_underline">True</property>
162
-        <child type="submenu">
163
-          <object class="GtkMenu">
164
-          <property name="visible">True</property>
165
-          <property name="can_focus">False</property>
166
-          <child>
167
-            <object class="GtkImageMenuItem">
168
-            <property name="label">gtk-about</property>
189
+        <child>
190
+          <object class="GtkImage" id="logo">
169 191
             <property name="visible">True</property>
170 192
             <property name="can_focus">False</property>
171
-            <property name="use_underline">True</property>
172
-            <property name="use_stock">True</property>
173
-            </object>
174
-          </child>
193
+            <property name="resource">/cl/cromer/ubb/sernatur/pixdata/logo-sernatur.svg</property>
175 194
           </object>
195
+          <packing>
196
+            <property name="expand">True</property>
197
+            <property name="fill">True</property>
198
+            <property name="position">1</property>
199
+          </packing>
176 200
         </child>
177
-        </object>
178
-      </child>
179
-      </object>
180
-      <packing>
181
-      <property name="expand">False</property>
182
-      <property name="fill">True</property>
183
-      <property name="position">0</property>
184
-      </packing>
185
-    </child>
186
-    <child>
187
-      <object class="GtkImage" id="logo">
188
-      <property name="visible">True</property>
189
-      <property name="can_focus">False</property>
190
-      <property name="resource">/cl/cromer/ubb/sernatur/pixdata/logo-sernatur.svg</property>
191 201
       </object>
192
-      <packing>
193
-      <property name="expand">True</property>
194
-      <property name="fill">True</property>
195
-      <property name="position">1</property>
196
-      </packing>
197 202
     </child>
198
-    </object>
199
-  </child>
200 203
   </template>
201 204
 </interface>

+ 0
- 1
doc/meson.build View File

@@ -5,7 +5,6 @@ if docs_enabled
5 5
 	valadocs_deps = get_option('valadocs_deps')
6 6
 	docs_deps = ['--pkg=gtk+-3.0']
7 7
 	docs_deps += ['--pkg=libpq']
8
-	docs_deps += ['--pkg=libconfig']
9 8
 	docs_deps += ['--pkg=posix']
10 9
 	if valadocs_deps
11 10
 		docs_deps += ['--deps']

+ 0
- 4
meson_options.txt View File

@@ -6,10 +6,6 @@ option('valadocs_deps',
6 6
 	type: 'boolean',
7 7
 	value: false,
8 8
 	description: 'Build the valadocs of the deps of sernatur')
9
-option('bundle_libs',
10
-	type: 'boolean',
11
-	value: false,
12
-	description: 'Bundle the libs that the executable is linked against')
13 9
 option('install_translations',
14 10
 	type: 'boolean',
15 11
 	value: true,

+ 0
- 15
script/linux_bundler.sh View File

@@ -1,15 +0,0 @@
1
-#!/bin/sh -eu
2
-
3
-libdir="${MESON_INSTALL_DESTDIR_PREFIX}/lib"
4
-mkdir -p $libdir
5
-
6
-#libfile=`ldd ${MESON_INSTALL_DESTDIR_PREFIX}/bin/sernatur | grep libpq | cut -d ' ' -f 3`
7
-#cp $libfile "${libdir}"
8
-#strip "${libdir}/libpq"*
9
-
10
-if [ -f "${MESON_INSTALL_DESTDIR_PREFIX}"/bin/sernatur ]; then
11
-	echo "Copying linked dynamic libs..."
12
-	ldd "${MESON_INSTALL_DESTDIR_PREFIX}"/bin/sernatur | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' "${libdir}"
13
-fi
14
-echo "Stripping libs..."
15
-strip --strip-debug "${libdir}/"*

+ 0
- 5
script/meson.build View File

@@ -1,7 +1,2 @@
1
-bundle_libs = get_option('bundle_libs')
2
-if bundle_libs
3
-	install_data('sernatur.sh', install_dir: '.')
4
-	meson.add_install_script('linux_bundler.sh')
5
-endif
6 1
 valadoc = find_program('glib-compile-schemas')
7 2
 meson.add_install_script('compile_schemas.sh')

+ 0
- 7
script/sernatur.sh View File

@@ -1,7 +0,0 @@
1
-#!/bin/bash
2
-
3
-cd "${0%/*}"
4
-
5
-export LD_LIBRARY_PATH="`pwd`/lib"
6
-export GSETTINGS_SCHEMA_DIR="`pwd`/share/glib-2.0/schemas"
7
-bin/sernatur

+ 1
- 5
src/meson.build View File

@@ -6,10 +6,6 @@ gmodule_dep = dependency('gmodule-2.0', version: '>=2.0')
6 6
 pq_dep = dependency('libpq', version: '>=10.0')
7 7
 posix_dep = meson.get_compiler('vala').find_library('posix')
8 8
 
9
-libconfig_lib = meson.get_compiler('c').find_library('libconfig')
10
-libconfig_vapi = meson.get_compiler('vala').find_library('libconfig', dirs: join_paths(meson.current_source_dir(), 'vapi'))
11
-libconfig_dep = declare_dependency(dependencies: [libconfig_lib, libconfig_vapi], version: '1.5')
12
-
13 9
 # this is how to link against a c lib
14 10
 #libsystemd_lib = meson.get_compiler('c').find_library('libsystemd')
15 11
 
@@ -39,5 +35,5 @@ vala_args += ['--gresources='+join_paths(meson.source_root(),'data/ui/sernatur.g
39 35
 exe = executable('sernatur',
40 36
 	sources,
41 37
 	vala_args: vala_args,
42
-	dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, libconfig_dep, posix_dep],
38
+	dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, posix_dep],
43 39
 	install: true)

+ 8
- 35
src/sernatur-window.vala View File

@@ -17,7 +17,6 @@
17 17
  */
18 18
 namespace Sernatur {
19 19
 	using Postgres;
20
-	using LibConfig;
21 20
 
22 21
 	/**
23 22
 	 * The MainWindow class
@@ -33,42 +32,16 @@ namespace Sernatur {
33 32
 			GLib.Object (application: application);
34 33
 			Database conn;
35 34
 
36
-			var file = File.new_for_path ("/etc/sernatur/sernatur.conf");
37
-			if (!file.query_exists ()) {
38
-				stderr.printf (dgettext (null, "The file '%s' doesn't exist.\n"), file.get_path ());
39
-				application.quit ();
40
-				return;
41
-			}
42
-
43
-			// TODO: if config file does not exist, then fallback to gsettings schemas
44
-
45
-			Config config = Config();
46
-			if (!config.read_file ("/etc/sernatur/sernatur.conf")) {
47
-				stderr.printf ("%s\n", config.error_message ());
48
-				application.quit ();
49
-				return;
50
-			}
51
-
52
-			Setting setting = config.lookup("database");
53
-			string* host;
54
-			int port;
55
-			string* options;
56
-			string* gtty;
57
-			string* db_name;
58
-			string* login;
59
-			string* pwd;
60
-			setting.lookup_string("host", out host);
61
-			setting.lookup_int("port", out port);
62
-			setting.lookup_string("options", out options);
63
-			setting.lookup_string("gtty", out gtty);
64
-			setting.lookup_string("db_name", out db_name);
65
-			setting.lookup_string("login", out login);
66
-			setting.lookup_string("pwd", out pwd);
67
-
68 35
 			Settings settings = new Settings ("cl.cromer.ubb.sernatur");
69
-			var host2 = settings.get_string ("host");
36
+			string host = settings.get_string ("host");
37
+			string port = settings.get_string ("port");
38
+			string options = settings.get_string ("options");
39
+			string tty = settings.get_string ("tty");
40
+			string database = settings.get_string ("database");
41
+			string username = settings.get_string ("username");
42
+			string password = settings.get_string ("password");
70 43
 
71
-			conn = set_db_login (host2, port.to_string (), options, gtty, db_name, login, pwd);
44
+			conn = set_db_login (host, port, options, tty, database, username, password);
72 45
 			if (conn.get_status () != ConnectionStatus.OK) {
73 46
 				stderr.printf ("%s\n", conn.get_error_message ());
74 47
 				Gtk.MessageDialog msg = new Gtk.MessageDialog (this,

+ 8
- 0
src/sernatur.vala View File

@@ -16,6 +16,8 @@
16 16
  * The main Sernatur namespace
17 17
  */
18 18
 namespace Sernatur {
19
+	using Gtk;
20
+
19 21
 	/**
20 22
 	 * The application class
21 23
 	 */
@@ -38,6 +40,12 @@ namespace Sernatur {
38 40
 		public override void activate () {
39 41
 			window = new MainWindow (this);
40 42
 			//window.maximize ();
43
+			try {
44
+				window.icon = IconTheme.get_default ().load_icon ("sernatur", 48, 0);
45
+			}
46
+			catch (Error e) {
47
+				stderr.printf ("Could not load application icon: %s\n", e.message);
48
+			}
41 49
 			window.present ();
42 50
 		}
43 51
 

+ 0
- 224
src/vapi/libconfig.vapi View File

@@ -1,224 +0,0 @@
1
-/*
2
- * Copyright 2018 Chris Cromer
3
- *
4
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
- *
6
- * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
- *
8
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
- *
10
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
- *
12
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13
- */
14
-
15
-[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "libconfig.h")]
16
-namespace LibConfig {
17
-	using Posix; // Needed for Posix.FILE
18
-
19
-	[CCode (cname = "uint", cprefix = "LIBCONFIG_VER_", has_type_id = false)]
20
-	public enum Version {
21
-		MAJOR,
22
-		MINOR,
23
-		REVISION;
24
-		/**
25
-		 * Convert the enum value into a string with a version number
26
-		 * This method is here to override default enum to_string which will print the enum variable name by default
27
-		 * @return string with version number
28
-		 */
29
-		public string to_string () {
30
-			int x_value = this;
31
-			return x_value.to_string();
32
-		}
33
-	}
34
-
35
-	[CCode (cname = "int", cprefix = "CONFIG_ERR_", has_type_id = false)]
36
-	public enum ConfigError {
37
-		NONE = 0,
38
-		FILE_IO = 1,
39
-		PARSE = 2
40
-	}
41
-
42
-	[CCode (cname = "int", cprefix = "CONFIG_OPTION_", has_type_id = false)]
43
-	[Flags]
44
-	public enum ConfigOption {
45
-		AUTOCONVERT = 0x01,
46
-		SEMICOLON_SEPARATORS = 0x02,
47
-		COLON_ASSIGNMENT_FOR_GROUPS = 0x04,
48
-		COLON_ASSIGNMENT_FOR_NON_GROUPS = 0x08,
49
-		OPEN_BRACE_ON_SEPARATE_LINE = 0x10,
50
-		[Version (since = "1.7")]
51
-		ALLOW_SCIENTIFIC_NOTATION = 0x20,
52
-		[Version (since = "1.7.1")]
53
-		FSYNC = 0x40
54
-	}
55
-
56
-	[CCode (cname = "int", cprefix = "CONFIG_TYPE_", has_type_id = false)]
57
-	public enum ConfigType {
58
-		NONE = 0,
59
-		GROUP = 1,
60
-		INT = 2,
61
-		INT64 = 3,
62
-		FLOAT = 4,
63
-		STRING = 5,
64
-		BOOL = 6,
65
-		ARRAY = 7,
66
-		LIST = 8
67
-	}
68
-
69
-	[CCode (cname = "int", cprefix = "CONFIG_FORMAT_", has_type_id = false)]
70
-	public enum ConfigFormat {
71
-		DEFAULT = 0,
72
-		HEX = 1
73
-	}
74
-
75
-	[CCode (cname = "config_t", cprefix = "config_", destroy_function = "config_destroy", has_type_id = false)]
76
-	public struct Config {
77
-		[CCode (cname = "config_init")]
78
-		public Config();
79
-
80
-		[Version (since = "1.7")]
81
-		public void clear ();
82
-
83
-		public bool read (FILE stream);
84
-		public bool read_file (string filename);
85
-		public bool read_string (string str);
86
-
87
-		public void write (FILE stream);
88
-		public bool write_file (string filename);
89
-
90
-		public void set_include_dir (string include_dir);
91
-		public string get_include_dir ();
92
-
93
-		//[Version (since = "1.7")]
94
-		//void config_set_include_func (config_include_fn_t func)
95
-
96
-		[Version (since = "1.6")]
97
-		public ushort get_float_precision ();
98
-		[Version (since = "1.6")]
99
-		public void set_float_precision (ushort digits);
100
-
101
-		public ConfigOption get_options ();
102
-		public void set_options (ConfigOption options);
103
-
104
-		[Version (since = "1.7")]
105
-		public ConfigOption get_option (int option);
106
-		[Version (since = "1.7")]
107
-		public void set_option (ConfigOption option, int flag);
108
-
109
-		[Version (deprecated  = true, replacement = "get_option")]
110
-		public int get_auto_convert ();
111
-		[Version (deprecated  = true, replacement = "set_option")]
112
-		public void set_auto_convert (int flag);
113
-
114
-		public ConfigFormat get_default_format ();
115
-		public void set_default_format (ConfigFormat format);
116
-
117
-		public ushort get_tab_width ();
118
-		public void set_tab_width (ushort width);
119
-
120
-		public bool lookup_int (string path, out int x_value);
121
-		public bool lookup_int64 (string path, out int64 x_value);
122
-		public bool lookup_float (string path, out float x_value);
123
-		public bool lookup_bool (string path, out bool x_value);
124
-		public bool lookup_string (string path, out string x_value);
125
-
126
-		public Setting? lookup (string path);
127
-
128
-		public Setting root_setting ();
129
-
130
-		[CCode (simple_generics = true)]
131
-		[Version (since = "1.7")]
132
-		public void set_hook<T> (T hook);
133
-
134
-		[CCode (simple_generics = true)]
135
-		[Version (since = "1.7")]
136
-		public T get_hook<T> ();
137
-
138
-		//[CCode (simple_generics = true)]
139
-		//public void set_destructor<T> (T void (* destructor));
140
-
141
-		public unowned string error_text ();
142
-		public unowned string? error_file ();
143
-		public int error_line ();
144
-		public ConfigError error_type ();
145
-
146
-		public string error_message () {
147
-			return this.error_file () + ":" + this.error_line ().to_string() + " - " + this.error_text ();
148
-		}
149
-
150
-		public string version() {
151
-			return Version.MAJOR.to_string () + "." + Version.MINOR.to_string () + "." + Version.REVISION.to_string ();
152
-		}
153
-	}
154
-
155
-	[CCode (cname = "config_setting_t", cprefix = "config_setting_", free_function = "", has_type_id = false, has_target = false)]
156
-	[Compact]
157
-	public class Setting {
158
-		public Setting? lookup (string path);
159
-
160
-		public int? get_int ();
161
-		public int64? get_int64 ();
162
-		public float? get_float ();
163
-		public bool? get_bool ();
164
-		public unowned string? get_string ();
165
-
166
-		public bool set_int (int x_value);
167
-		public bool set_int64 (int64 x_value);
168
-		public bool set_float (float x_value);
169
-		public bool set_bool (bool x_value);
170
-		public bool set_string (string x_value);
171
-
172
-		public bool lookup_int (string name, out int x_value);
173
-		public bool lookup_int64 (string name, out int64 x_value);
174
-		public bool lookup_float (string name, out float x_value);
175
-		public bool lookup_bool (string name, out bool x_value);
176
-		public bool lookup_string (string name, out string x_value);
177
-
178
-		public ConfigFormat get_format ();
179
-		public bool set_format (ConfigFormat format);
180
-
181
-		public Setting? get_member (string name);
182
-
183
-		public Setting? get_elem (uint index);
184
-
185
-		public int? get_int_elem (int index);
186
-		public int64? get_int64_elem (int index);
187
-		public float? get_float_elem (int index);
188
-		public bool? get_bool_elem (int index);
189
-		public unowned string? get_string_elem (int index);
190
-
191
-		public Setting? set_int_elem (int index, int x_value);
192
-		public Setting? set_int64_elem (int index, int64 x_value);
193
-		public Setting? set_float_elem (int index, float x_value);
194
-		public Setting? set_bool_elem (int index, bool x_value);
195
-		public Setting? set_string_elem (int index, string x_value);
196
-
197
-		public Setting? add (Setting parent, string? name, ConfigType type);
198
-		public bool remove (Setting parent, string name);
199
-		public int remove_elem (Setting parent, uint index);
200
-
201
-		public unowned string? name ();
202
-		public Setting? parent ();
203
-
204
-		public bool is_root ();
205
-
206
-		public int index ();
207
-
208
-		public int length ();
209
-
210
-		public ConfigType type ();
211
-
212
-		public bool is_group ();
213
-		public bool is_array ();
214
-		public bool is_list ();
215
-
216
-		public bool is_aggregate ();
217
-		public bool is_scalar ();
218
-		public bool is_number ();
219
-
220
-		public unowned string? source_file ();
221
-
222
-		public uint source_line ();
223
-	}
224
-}

Loading…
Cancel
Save