aboutsummaryrefslogtreecommitdiffstats
path: root/comms/cqrlog/Makefile
blob: e68adba534f25bf1343d4df85908351c06d32b2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Created by: Stephen Hurd <shurd@FreeBSD.org>
# $FreeBSD$

PORTNAME=   cqrlog
PORTVERSION=    2.3.0
DISTVERSIONPREFIX=  v
PORTREVISION=   2
CATEGORIES= comms hamradio
PKGNAMESUFFIX=  ${LAZARUS_PKGNAMESUFFIX}

MAINTAINER= hamradio@FreeBSD.org
COMMENT=    Amateur Radio logging application

LICENSE=    GPLv2

LIB_DEPENDS=    libhamlib.so:comms/hamlib

USES=       fpc lazarus:flavors shebangfix ssl:run dos2unix mysql
USE_GITHUB= yes
GH_ACCOUNT= ok2cqr

LLD_UNSAFE= yes
SHEBANG_FILES=  tools/cqrlog-apparmor-fix \
        voice_keyer/voice_keyer.sh
USE_FPC=    cairo fcl-base chm fcl-db fcl-image fcl-json fcl-net fcl-web \
        fcl-registry rtl-extra fcl-xml mysql numlib opengl openssl \
        pasjpeg regexpr x11

ALL_TARGET= ${PORTNAME}

MAKE_ENV+=  LAZBUILD_CMD="${LAZBUILD_CMD}" \
        LAZBUILD_ARGS="${LAZBUILD_ARGS}" \
        LCL_PLATFORM="${LCL_PLATFORM}" \
        LAZARUS_DIR="${LAZARUS_DIR}"

USE_XORG+=  x11
NO_LAZBUILD=    yes
LAZBUILD_ARGS=  -d --pcp=.
LAZARUS_NO_FLAVORS=qt5
INSTALLS_ICONS= yes
DOS2UNIX_WRKSRC=${WRKSRC}/src/synapse/

post-extract:
    @${RM} -r ${WRKSRC}/src/lnet/lib/openssl.pas

post-patch:
    @${SED} -e s!%%LOCALBASE%%!${LOCALBASE}!g \
        -e s!%%MAKE_CMD%%!${MAKE_CMD}!g \
        -e s!%%LAZARUSDIR%%!${LAZARUS_DIR}!g \
        ${FILESDIR}/environmentoptions.xml.in \
        > ${WRKSRC}/environmentoptions.xml
    ${REINPLACE_CMD} -e s!%%LOCALBASE%%!${LOCALBASE}!g \
        ${WRKSRC}/help/cwd.html ${WRKSRC}/help/h1.html \
        ${WRKSRC}/src/cqrlog.lpi ${WRKSRC}/src/dData.pas \
        ${WRKSRC}/src/dUtils.pas \
        ${WRKSRC}/src/fLoTWExport.pas ${WRKSRC}/src/fLoTWExport.lfm \
        ${WRKSRC}/src/fPreferences.pas ${WRKSRC}/src/fRotControl.pas \
        ${WRKSRC}/src/fTRXControl.pas ${WRKSRC}/src/fGrayline.pas \
        ${WRKSRC}/src/fPreferences.lfm ${WRKSRC}/src/fPreferences.pas
    ${REINPLACE_CMD} -e s!%%DATADIR%%!${DATADIR}!g \
        ${WRKSRC}/src/dData.pas ${WRKSRC}/src/fGrayline.pas
    ${REINPLACE_CMD} -e s!Linux!FreeBSD!g \
        ${WRKSRC}/src/fMain.lfm
    ${REINPLACE_CMD} -e s!%%OPENSSLLIB%%!${OPENSSLLIB}!g \
        ${WRKSRC}/src/synapse/ssl_openssl_lib.pas
    ${RM} -r ${WRKSRC}/src/mysql

.include <bsd.port.mk>
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* eel-gconf-extensions.c - Stuff to make GConf easier to use.

   Copyright © 2000, 2001 Eazel, Inc.

   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.

   Authors: Ramiro Estrugo <ramiro@eazel.com>

*/

#include "config.h"

#include "eel-gconf-extensions.h"

#include <glib/gi18n.h>

#include <gconf/gconf-client.h>
#include <gconf/gconf.h>
#include <string.h>

static GConfClient *global_gconf_client = NULL;

static void
global_client_free (void)
{
    if (global_gconf_client == NULL) {
        return;
    }
    
    g_object_unref (global_gconf_client);
    global_gconf_client = NULL;
}

/* Public */
GConfClient *
eel_gconf_client_get_global (void)
{
    if (global_gconf_client == NULL) {
        global_gconf_client = gconf_client_get_default ();
        g_atexit (global_client_free);
    }
    
    return global_gconf_client;
}

gboolean
eel_gconf_handle_error (GError **error)
{
    g_return_val_if_fail (error != NULL, FALSE);

    if (*error != NULL) {
        g_warning (_("GConf error:\n  %s"), (*error)->message);
        g_error_free (*error);
        *error = NULL;

        return TRUE;
    }

    return FALSE;
}

void
eel_gconf_set_boolean (const char *key,
                gboolean boolean_value)
{
    GConfClient *client;
    GError *error = NULL;
    
    g_return_if_fail (key != NULL);

    client = eel_gconf_client_get_global ();
    g_return_if_fail (client != NULL);
    
    gconf_client_set_bool (client, key, boolean_value, &error);
    eel_gconf_handle_error (&error);
}

gboolean
eel_gconf_get_boolean (const char *key)
{
    gboolean result;
    GConfClient *client;
    GError *error = NULL;
    
    g_return_val_if_fail (key != NULL, FALSE);
    
    client = eel_gconf_client_get_global ();
    g_return_val_if_fail (client != NULL, FALSE);
    
    result = gconf_client_get_bool (client, key, &error);
    
    if (eel_gconf_handle_error (&error)) {
        result = FALSE;
    }
    
    return result;
}

void
eel_gconf_set_integer (const char *key,
                int int_value)
{
    GConfClient *client;
    GError *error = NULL;

    g_return_if_fail (key != NULL);

    client = eel_gconf_client_get_global ();
    g_return_if_fail (client != NULL);

    gconf_client_set_int (client, key, int_value, &error);
    eel_gconf_handle_error (&error);
}

int
eel_gconf_get_integer (const char *key)
{
    int result;
    GConfClient *client;
    GError *error = NULL;
    
    g_return_val_if_fail (key != NULL, 0);
    
    client = eel_gconf_client_get_global ();
    g_return_val_if_fail (client != NULL, 0);
    
    result = gconf_client_get_int (client, key, &error);

    if (eel_gconf_handle_error (&error)) {
        result = 0;
    }

    return result;
}

void
eel_gconf_set_string (const char *key,
               const char *string_value)
{
    GConfClient *client;
    GError *error = NULL;

    g_return_if_fail (key != NULL);

    client = eel_gconf_client_get_global ();
    g_return_if_fail (client != NULL);
    
    gconf_client_set_string (client, key, string_value, &error);
    eel_gconf_handle_error (&error);
}

char *
eel_gconf_get_string (const char *key)
{
    char *result;
    GConfClient *client;
    GError *error = NULL;
    
    g_return_val_if_fail (key != NULL, NULL);
    
    client = eel_gconf_client_get_global ();
    g_return_val_if_fail (client != NULL, NULL);
    
    result = gconf_client_get_string (client, key, &error);
    
    if (eel_gconf_handle_error (&error)) {
        result = g_strdup ("");
    }
    
    return result;
}

void
eel_gconf_set_string_list (const char *key,
                const GSList *slist)
{
    GConfClient *client;
    GError *error;

    g_return_if_fail (key != NULL);

    client = eel_gconf_client_get_global ();
    g_return_if_fail (client != NULL);

    error = NULL;
    gconf_client_set_list (client, key, GCONF_VALUE_STRING,
                   /* Need cast cause of GConf api bug */
                   (GSList *) slist,
                   &error);
    eel_gconf_handle_error (&error);
}

GSList *
eel_gconf_get_string_list (const char *key)
{
    GSList *slist;
    GConfClient *client;
    GError *error;
    
    g_return_val_if_fail (key != NULL, NULL);
    
    client = eel_gconf_client_get_global ();
    g_return_val_if_fail (client != NULL, NULL);
    
    error = NULL;
    slist = gconf_client_get_list (client, key, GCONF_VALUE_STRING, &error);
    if (eel_gconf_handle_error (&error)) {
        slist = NULL;
    }

    return slist;
}

gboolean
eel_gconf_is_default (const char *key)
{
    gboolean result;
    GConfValue *value;
    GError *error = NULL;
    
    g_return_val_if_fail (key != NULL, FALSE);
    
    value = gconf_client_get_without_default  (eel_gconf_client_get_global (), key, &error);

    if (eel_gconf_handle_error (&error)) {
        if (value != NULL) {
            gconf_value_free (value);
        }
        return FALSE;
    }

    result = (value == NULL);
    eel_gconf_value_free (value);
    return result;
}

gboolean
eel_gconf_key_is_writable (const char *key)
{
    gboolean result;
    GError *error = NULL;
    
    g_return_val_if_fail (key != NULL, FALSE);
    
    result = gconf_client_key_is_writable  (eel_gconf_client_get_global (), key, &error);

    if (eel_gconf_handle_error (&error)) {
        return result;
    }

    return result;
}

gboolean
eel_gconf_monitor_add (const char *directory)
{
    GError *error = NULL;
    GConfClient *client;

    g_return_val_if_fail (directory != NULL, FALSE);

    client = gconf_client_get_default ();
    g_return_val_if_fail (client != NULL, FALSE);

    gconf_client_add_dir (client,
                  directory,
                  GCONF_CLIENT_PRELOAD_NONE,
                  &error);
    
    if (eel_gconf_handle_error (&error)) {
        return FALSE;
    }

    return TRUE;
}

gboolean
eel_gconf_monitor_remove (const char *directory)
{
    GError *error = NULL;
    GConfClient *client;

    if (directory == NULL) {
        return FALSE;
    }

    client = gconf_client_get_default ();
    g_return_val_if_fail (client != NULL, FALSE);
    
    gconf_client_remove_dir (client,
                 directory,
                 &error);
    
    if (eel_gconf_handle_error (&error)) {
        return FALSE;
    }
    
    return TRUE;
}

void
eel_gconf_preload_cache (const char             *directory,
             GConfClientPreloadType  preload_type)
{
    GError *error = NULL;
    GConfClient *client;

    if (directory == NULL) {
        return;
    }

    client = gconf_client_get_default ();
    g_return_if_fail (client != NULL);
    
    gconf_client_preload (client,
                  directory,
                  preload_type,
                  &error);
    
    eel_gconf_handle_error (&error);
}

void
eel_gconf_suggest_sync (void)
{
    GConfClient *client;
    GError *error = NULL;

    client = eel_gconf_client_get_global ();
    g_return_if_fail (client != NULL);
    
    gconf_client_suggest_sync (client, &error);
    eel_gconf_handle_error (&error);
}

GConfValue*
eel_gconf_get_value (const char *key)
{
    GConfValue *value = NULL;
    GConfClient *client;
    GError *error = NULL;

    g_return_val_if_fail (key != NULL, NULL);

    client = eel_gconf_client_get_global ();
    g_return_val_if_fail (client != NULL, NULL);

    value = gconf_client_get (client, key, &error);
    
    if (eel_gconf_handle_error (&error)) {
        if (value != NULL) {
            gconf_value_free (value);
            value = NULL;
        }
    }

    return value;
}

GConfValue*
eel_gconf_get_default_value (const char *key)
{
    GConfValue *value = NULL;
    GConfClient *client;
    GError *error = NULL;
    
    g_return_val_if_fail (key != NULL, NULL);

    client = eel_gconf_client_get_global ();
    g_return_val_if_fail (client != NULL, NULL);

    value = gconf_client_get_default_from_schema (client, key, &error);
    
    if (eel_gconf_handle_error (&error)) {
        if (value != NULL) {
            gconf_value_free (value);
            value = NULL;
        }
    }

    return value;
}

static int
eel_strcmp (const char *string_a, const char *string_b)
{
    /* FIXME bugzilla.eazel.com 5450: Maybe we need to make this
     * treat 'NULL < ""', or have a flavor that does that. If we
     * didn't have code that already relies on 'NULL == ""', I
     * would change it right now.
     */
    return strcmp (string_a == NULL ? "" : string_a,
               string_b == NULL ? "" : string_b);
}

static gboolean
eel_str_is_equal (const char *string_a, const char *string_b)
{
    /* FIXME bugzilla.eazel.com 5450: Maybe we need to make this
     * treat 'NULL != ""', or have a flavor that does that. If we
     * didn't have code that already relies on 'NULL == ""', I
     * would change it right now.
     */
    return eel_strcmp (string_a, string_b) == 0;
}

static gboolean
simple_value_is_equal (const GConfValue *a,
               const GConfValue *b)
{
    g_return_val_if_fail (a != NULL, FALSE);
    g_return_val_if_fail (b != NULL, FALSE);

    switch (a->type) {
    case GCONF_VALUE_STRING:
        return eel_str_is_equal (gconf_value_get_string (a),
                     gconf_value_get_string (b));
        break;

    case GCONF_VALUE_INT:
        return gconf_value_get_int (a) ==
            gconf_value_get_int (b);
        break;

    case GCONF_VALUE_FLOAT:
        return gconf_value_get_float (a) ==
            gconf_value_get_float (b);
        break;

    case GCONF_VALUE_BOOL:
        return gconf_value_get_bool (a) ==
            gconf_value_get_bool (b);
        break;
    default:
        g_assert_not_reached ();
    }
    
    return FALSE;
}

gboolean
eel_gconf_value_is_equal (const GConfValue *a,
                   const GConfValue *b)
{
    GSList *node_a;
    GSList *node_b;

    if (a == NULL && b == NULL) {
        return TRUE;
    }

    if (a == NULL || b == NULL) {
        return FALSE;
    }

    if (a->type != b->type) {
        return FALSE;
    }

    switch (a->type) {
    case GCONF_VALUE_STRING:
    case GCONF_VALUE_INT:
    case GCONF_VALUE_FLOAT:
    case GCONF_VALUE_BOOL:
        return simple_value_is_equal (a, b);
        break;
        
    case GCONF_VALUE_LIST:
        if (gconf_value_get_list_type (a) !=
            gconf_value_get_list_type (b)) {
            return FALSE;
        }

        node_a = gconf_value_get_list (a);
        node_b = gconf_value_get_list (b);
        
        if (node_a == NULL && node_b == NULL) {
            return TRUE;
        }

        if (g_slist_length (node_a) !=
            g_slist_length (node_b)) {
            return FALSE;
        }
        
        for (;
             node_a != NULL && node_b != NULL;
             node_a = node_a->next, node_b = node_b->next) {
            g_assert (node_a->data != NULL);
            g_assert (node_b->data != NULL);
            if (!simple_value_is_equal (node_a->data, node_b->data)) {
                return FALSE;
            }
        }
        
        return TRUE;
    default:
        /* FIXME: pair ? */
        g_assert (0);
    }
    
    g_assert_not_reached ();
    return FALSE;
}

void
eel_gconf_value_free (GConfValue *value)
{
    if (value == NULL) {
        return;
    }
    
    gconf_value_free (value);
}

guint
eel_gconf_notification_add (const char *key,
                 GConfClientNotifyFunc notification_callback,
                 gpointer callback_data)
{
    guint notification_id;
    GConfClient *client;
    GError *error = NULL;
    
    g_return_val_if_fail (key != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
    g_return_val_if_fail (notification_callback != NULL, EEL_GCONF_UNDEFINED_CONNECTION);

    client = eel_gconf_client_get_global ();
    g_return_val_if_fail (client != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
    
    notification_id = gconf_client_notify_add (client,
                           key,
                           notification_callback,
                           callback_data,
                           NULL,
                           &error);
    
    if (eel_gconf_handle_error (&error)) {
        if (notification_id != EEL_GCONF_UNDEFINED_CONNECTION) {
            gconf_client_notify_remove (client, notification_id);
            notification_id = EEL_GCONF_UNDEFINED_CONNECTION;
        }
    }
    
    return notification_id;
}

void
eel_gconf_notification_remove (guint notification_id)
{
    GConfClient *client;

    if (notification_id == EEL_GCONF_UNDEFINED_CONNECTION) {
        return;
    }
    
    client = eel_gconf_client_get_global ();
    g_return_if_fail (client != NULL);

    gconf_client_notify_remove (client, notification_id);
}

GSList *
eel_gconf_value_get_string_list (const GConfValue *value)
{
    GSList *result;
    const GSList *slist;
    const GSList *node;
    const char *string;
    const GConfValue *next_value;

    if (value == NULL) {
        return NULL;
    }

    g_return_val_if_fail (value->type == GCONF_VALUE_LIST, NULL);
    g_return_val_if_fail (gconf_value_get_list_type (value) == GCONF_VALUE_STRING, NULL);

    slist = gconf_value_get_list (value);
    result = NULL;
    for (node = slist; node != NULL; node = node->next) {
        next_value = node->data;
        g_return_val_if_fail (next_value != NULL, NULL);
        g_return_val_if_fail (next_value->type == GCONF_VALUE_STRING, NULL);
        string = gconf_value_get_string (next_value);
        result = g_slist_append (result, g_strdup (string));
    }
    return result;
}

void
eel_gconf_value_set_string_list (GConfValue *value,
                 const GSList *string_list)
{
    const GSList *node;
    GConfValue *next_value;
    GSList *value_list;

    g_return_if_fail (value->type == GCONF_VALUE_LIST);
    g_return_if_fail (gconf_value_get_list_type (value) == GCONF_VALUE_STRING);

    value_list = NULL;
    for (node = string_list; node != NULL; node = node->next) {
        next_value = gconf_value_new (GCONF_VALUE_STRING);
        gconf_value_set_string (next_value, node->data);
        value_list = g_slist_append (value_list, next_value);
    }

    gconf_value_set_list (value, value_list);

    for (node = value_list; node != NULL; node = node->next) {
        gconf_value_free (node->data);
    }
    g_slist_free (value_list);
}

void
eel_gconf_set_float (const char *key,
                gfloat float_value)
{
    GConfClient *client;
    GError *error = NULL;

    g_return_if_fail (key != NULL);

    client = eel_gconf_client_get_global ();
    g_return_if_fail (client != NULL);

    gconf_client_set_float (client, key, float_value, &error);
    eel_gconf_handle_error (&error);
}

gfloat
eel_gconf_get_float (const char *key)
{
    gfloat result;
    GConfClient *client;
    GError *error = NULL;
    
    g_return_val_if_fail (key != NULL, 0);
    
    client = eel_gconf_client_get_global ();
    g_return_val_if_fail (client != NULL, 0);
    
    result = gconf_client_get_float (client, key, &error);

    if (eel_gconf_handle_error (&error)) {
        result = 0;
    }

    return result;
}

static char *
tilde_compress (const char *path)
{
    const char *home;

    if (path == NULL) return NULL;

    home = g_get_home_dir ();
    if (home == NULL) return g_strdup (path);

    if (g_str_has_prefix (path, home))
    {
        return g_strconcat ("~", path + strlen (home), NULL);
    }

    return g_strdup (path);
}

void
eel_gconf_set_path (const char *key,
            const char *value)
{
    char *tilde_path;
    char *converted;
    
    tilde_path = tilde_compress (value);
    converted = g_filename_to_utf8 (tilde_path, -1, NULL, NULL, NULL);
    eel_gconf_set_string (key, converted);

    g_free (tilde_path);
    g_free (converted);
}

void
eel_gconf_unset_key (const char *key)
{
    GConfClient *client;
    GError *error = NULL;

    client = eel_gconf_client_get_global ();
    g_return_if_fail (client != NULL);

    gconf_client_unset (client, key, &error);
    eel_gconf_handle_error (&error);
}

void
eel_gconf_notify (const char *key)
{
    GConfClient *client;

    client = eel_gconf_client_get_global ();
    g_return_if_fail (client != NULL);

    gconf_client_notify (client, key);
}