This commit is contained in:
Chris Cromer 2018-12-23 15:52:08 -03:00
parent 7f24927c95
commit 9c5c7f1e7d
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
15 changed files with 230 additions and 496 deletions

View File

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

View File

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

View File

@ -1,9 +0,0 @@
database : {
host = "localhost";
port = 5432;
options = "";
gtty = "";
db_name = "bdd";
login = "bdd";
pwd = "bdd";
};

View File

@ -14,5 +14,40 @@
Port number to use Port number to use
</description> </description>
</key> </key>
<key name="options" type="s">
<default>""</default>
<summary>Options to use</summary>
<description>
Options to use
</description>
</key>
<key name="tty" type="s">
<default>""</default>
<summary>tty to send debug info (ignored)</summary>
<description>
tty to send debug info (ignored)
</description>
</key>
<key name="database" type="s">
<default>"bdd"</default>
<summary>Database to use</summary>
<description>
Database to use
</description>
</key>
<key name="username" type="s">
<default>"bdd"</default>
<summary>Username to use</summary>
<description>
Username to use
</description>
</key>
<key name="password" type="s">
<default>"bdd"</default>
<summary>Password to use</summary>
<description>
Password to use
</description>
</key>
</schema> </schema>
</schemalist> </schemalist>

View File

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

View File

@ -21,6 +21,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<property name="title">SERNATUR</property> <property name="title">SERNATUR</property>
<property name="icon_name">sernatur</property> <property name="icon_name">sernatur</property>
<property name="show_menubar">False</property> <property name="show_menubar">False</property>
<child>
<placeholder/>
</child>
<child> <child>
<object class="GtkBox" id="mainbox"> <object class="GtkBox" id="mainbox">
<property name="visible">True</property> <property name="visible">True</property>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,6 @@
*/ */
namespace Sernatur { namespace Sernatur {
using Postgres; using Postgres;
using LibConfig;
/** /**
* The MainWindow class * The MainWindow class
@ -33,42 +32,16 @@ namespace Sernatur {
GLib.Object (application: application); GLib.Object (application: application);
Database conn; Database conn;
var file = File.new_for_path ("/etc/sernatur/sernatur.conf");
if (!file.query_exists ()) {
stderr.printf (dgettext (null, "The file '%s' doesn't exist.\n"), file.get_path ());
application.quit ();
return;
}
// TODO: if config file does not exist, then fallback to gsettings schemas
Config config = Config();
if (!config.read_file ("/etc/sernatur/sernatur.conf")) {
stderr.printf ("%s\n", config.error_message ());
application.quit ();
return;
}
Setting setting = config.lookup("database");
string* host;
int port;
string* options;
string* gtty;
string* db_name;
string* login;
string* pwd;
setting.lookup_string("host", out host);
setting.lookup_int("port", out port);
setting.lookup_string("options", out options);
setting.lookup_string("gtty", out gtty);
setting.lookup_string("db_name", out db_name);
setting.lookup_string("login", out login);
setting.lookup_string("pwd", out pwd);
Settings settings = new Settings ("cl.cromer.ubb.sernatur"); Settings settings = new Settings ("cl.cromer.ubb.sernatur");
var host2 = settings.get_string ("host"); string host = settings.get_string ("host");
string port = settings.get_string ("port");
string options = settings.get_string ("options");
string tty = settings.get_string ("tty");
string database = settings.get_string ("database");
string username = settings.get_string ("username");
string password = settings.get_string ("password");
conn = set_db_login (host2, port.to_string (), options, gtty, db_name, login, pwd); conn = set_db_login (host, port, options, tty, database, username, password);
if (conn.get_status () != ConnectionStatus.OK) { if (conn.get_status () != ConnectionStatus.OK) {
stderr.printf ("%s\n", conn.get_error_message ()); stderr.printf ("%s\n", conn.get_error_message ());
Gtk.MessageDialog msg = new Gtk.MessageDialog (this, Gtk.MessageDialog msg = new Gtk.MessageDialog (this,

View File

@ -16,6 +16,8 @@
* The main Sernatur namespace * The main Sernatur namespace
*/ */
namespace Sernatur { namespace Sernatur {
using Gtk;
/** /**
* The application class * The application class
*/ */
@ -38,6 +40,12 @@ namespace Sernatur {
public override void activate () { public override void activate () {
window = new MainWindow (this); window = new MainWindow (this);
//window.maximize (); //window.maximize ();
try {
window.icon = IconTheme.get_default ().load_icon ("sernatur", 48, 0);
}
catch (Error e) {
stderr.printf ("Could not load application icon: %s\n", e.message);
}
window.present (); window.present ();
} }

View File

@ -1,224 +0,0 @@
/*
* Copyright 2018 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 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.
*
* 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.
*
* 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.
*/
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "libconfig.h")]
namespace LibConfig {
using Posix; // Needed for Posix.FILE
[CCode (cname = "uint", cprefix = "LIBCONFIG_VER_", has_type_id = false)]
public enum Version {
MAJOR,
MINOR,
REVISION;
/**
* Convert the enum value into a string with a version number
* This method is here to override default enum to_string which will print the enum variable name by default
* @return string with version number
*/
public string to_string () {
int x_value = this;
return x_value.to_string();
}
}
[CCode (cname = "int", cprefix = "CONFIG_ERR_", has_type_id = false)]
public enum ConfigError {
NONE = 0,
FILE_IO = 1,
PARSE = 2
}
[CCode (cname = "int", cprefix = "CONFIG_OPTION_", has_type_id = false)]
[Flags]
public enum ConfigOption {
AUTOCONVERT = 0x01,
SEMICOLON_SEPARATORS = 0x02,
COLON_ASSIGNMENT_FOR_GROUPS = 0x04,
COLON_ASSIGNMENT_FOR_NON_GROUPS = 0x08,
OPEN_BRACE_ON_SEPARATE_LINE = 0x10,
[Version (since = "1.7")]
ALLOW_SCIENTIFIC_NOTATION = 0x20,
[Version (since = "1.7.1")]
FSYNC = 0x40
}
[CCode (cname = "int", cprefix = "CONFIG_TYPE_", has_type_id = false)]
public enum ConfigType {
NONE = 0,
GROUP = 1,
INT = 2,
INT64 = 3,
FLOAT = 4,
STRING = 5,
BOOL = 6,
ARRAY = 7,
LIST = 8
}
[CCode (cname = "int", cprefix = "CONFIG_FORMAT_", has_type_id = false)]
public enum ConfigFormat {
DEFAULT = 0,
HEX = 1
}
[CCode (cname = "config_t", cprefix = "config_", destroy_function = "config_destroy", has_type_id = false)]
public struct Config {
[CCode (cname = "config_init")]
public Config();
[Version (since = "1.7")]
public void clear ();
public bool read (FILE stream);
public bool read_file (string filename);
public bool read_string (string str);
public void write (FILE stream);
public bool write_file (string filename);
public void set_include_dir (string include_dir);
public string get_include_dir ();
//[Version (since = "1.7")]
//void config_set_include_func (config_include_fn_t func)
[Version (since = "1.6")]
public ushort get_float_precision ();
[Version (since = "1.6")]
public void set_float_precision (ushort digits);
public ConfigOption get_options ();
public void set_options (ConfigOption options);
[Version (since = "1.7")]
public ConfigOption get_option (int option);
[Version (since = "1.7")]
public void set_option (ConfigOption option, int flag);
[Version (deprecated = true, replacement = "get_option")]
public int get_auto_convert ();
[Version (deprecated = true, replacement = "set_option")]
public void set_auto_convert (int flag);
public ConfigFormat get_default_format ();
public void set_default_format (ConfigFormat format);
public ushort get_tab_width ();
public void set_tab_width (ushort width);
public bool lookup_int (string path, out int x_value);
public bool lookup_int64 (string path, out int64 x_value);
public bool lookup_float (string path, out float x_value);
public bool lookup_bool (string path, out bool x_value);
public bool lookup_string (string path, out string x_value);
public Setting? lookup (string path);
public Setting root_setting ();
[CCode (simple_generics = true)]
[Version (since = "1.7")]
public void set_hook<T> (T hook);
[CCode (simple_generics = true)]
[Version (since = "1.7")]
public T get_hook<T> ();
//[CCode (simple_generics = true)]
//public void set_destructor<T> (T void (* destructor));
public unowned string error_text ();
public unowned string? error_file ();
public int error_line ();
public ConfigError error_type ();
public string error_message () {
return this.error_file () + ":" + this.error_line ().to_string() + " - " + this.error_text ();
}
public string version() {
return Version.MAJOR.to_string () + "." + Version.MINOR.to_string () + "." + Version.REVISION.to_string ();
}
}
[CCode (cname = "config_setting_t", cprefix = "config_setting_", free_function = "", has_type_id = false, has_target = false)]
[Compact]
public class Setting {
public Setting? lookup (string path);
public int? get_int ();
public int64? get_int64 ();
public float? get_float ();
public bool? get_bool ();
public unowned string? get_string ();
public bool set_int (int x_value);
public bool set_int64 (int64 x_value);
public bool set_float (float x_value);
public bool set_bool (bool x_value);
public bool set_string (string x_value);
public bool lookup_int (string name, out int x_value);
public bool lookup_int64 (string name, out int64 x_value);
public bool lookup_float (string name, out float x_value);
public bool lookup_bool (string name, out bool x_value);
public bool lookup_string (string name, out string x_value);
public ConfigFormat get_format ();
public bool set_format (ConfigFormat format);
public Setting? get_member (string name);
public Setting? get_elem (uint index);
public int? get_int_elem (int index);
public int64? get_int64_elem (int index);
public float? get_float_elem (int index);
public bool? get_bool_elem (int index);
public unowned string? get_string_elem (int index);
public Setting? set_int_elem (int index, int x_value);
public Setting? set_int64_elem (int index, int64 x_value);
public Setting? set_float_elem (int index, float x_value);
public Setting? set_bool_elem (int index, bool x_value);
public Setting? set_string_elem (int index, string x_value);
public Setting? add (Setting parent, string? name, ConfigType type);
public bool remove (Setting parent, string name);
public int remove_elem (Setting parent, uint index);
public unowned string? name ();
public Setting? parent ();
public bool is_root ();
public int index ();
public int length ();
public ConfigType type ();
public bool is_group ();
public bool is_array ();
public bool is_list ();
public bool is_aggregate ();
public bool is_scalar ();
public bool is_number ();
public unowned string? source_file ();
public uint source_line ();
}
}