addressbook-config.c 5.94 KB
Newer Older
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
/*
 *  Copyright (C) 2009 Savoir-Faire Linux inc.
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
 *  
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  This program 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 General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "addressbook-config.h"

void addressbook_load_parameters (AddressBook_Config **settings) {

    GHashTable *_params = NULL;
    AddressBook_Config *_settings;

    // Allocate a struct
    _settings = g_new0 (AddressBook_Config, 1);
    
    // Fetch the settings from D-Bus
    _params = (GHashTable*) dbus_get_addressbook_settings ();

    if (_params == NULL) {
        _settings->max_results = 30;
        _settings->display_contact_photo = 0;
36 37 38
        _settings->search_phone_business = 1;
        _settings->search_phone_home = 1;
        _settings->search_phone_mobile = 1;
39 40 41 42
    }
    else {
        _settings->max_results =  (guint)(g_hash_table_lookup (_params, "ADDRESSBOOK_MAX_RESULTS"));
        _settings->display_contact_photo = (guint) (g_hash_table_lookup (_params, "ADDRESSBOOK_DISPLAY_CONTACT_PHOTO"));
43 44 45
        _settings->search_phone_business = (guint) (g_hash_table_lookup (_params, "ADDRESSBOOK_SEARCH_PHONE_BUSINESS"));
        _settings->search_phone_home = (guint) (g_hash_table_lookup (_params, "ADDRESSBOOK_SEARCH_PHONE_HOME"));
        _settings->search_phone_mobile = (guint) (g_hash_table_lookup (_params, "ADDRESSBOOK_SEARCH_PHONE_MOBILE"));
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    }
    
    *settings = _settings;
}

static void max_results_cb (GtkRange* scale, gpointer user_data) {

    AddressBook_Config *settings = (AddressBook_Config*)user_data;
    settings->max_results = (guint) gtk_range_get_value (GTK_RANGE (scale));
}

static void display_contact_photo_cb (GtkWidget *widget, gpointer user_data) {

    AddressBook_Config *settings = (AddressBook_Config*)user_data;
    settings->display_contact_photo = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
}

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
static void search_phone_business_cb (GtkWidget *widget, gpointer user_data) {

    AddressBook_Config *settings = (AddressBook_Config*)user_data;
    settings->search_phone_business = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
}

static void search_phone_home_cb (GtkWidget *widget, gpointer user_data) {

    AddressBook_Config *settings = (AddressBook_Config*)user_data;
    settings->search_phone_home = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
}

static void search_phone_mobile_cb (GtkWidget *widget, gpointer user_data) {

    AddressBook_Config *settings = (AddressBook_Config*)user_data;
    settings->search_phone_mobile = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
}
80 81 82

GtkWidget* create_addressbook_settings () {
    
83
    GtkWidget *ret, *result_frame, *box, *value, *label, *photo, *item;
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    AddressBook_Config *settings;

    // Load the user value
    addressbook_load_parameters (&settings);

    ret = gtk_vbox_new(FALSE, 10);
    gtk_container_set_border_width(GTK_CONTAINER(ret), 10);

    result_frame = gtk_frame_new(_("Search Parameters"));
    gtk_box_pack_start(GTK_BOX(ret), result_frame, FALSE, FALSE, 0);
    gtk_widget_show (result_frame);

    box = gtk_vbox_new( FALSE , 1);
    gtk_widget_show (box);
    gtk_container_add (GTK_CONTAINER(result_frame) , box);

    // SCALE BUTTON - NUMBER OF RESULTS
    label = gtk_label_new (_("Maximum result number for a request: "));
    gtk_box_pack_start (GTK_BOX(box) , label , FALSE , FALSE , 1);
    value = gtk_hscale_new_with_range (0.0 , 50.0 , 5.0);
    gtk_label_set_mnemonic_widget (GTK_LABEL (label), value);
    gtk_scale_set_digits (GTK_SCALE(value) , 0);
    gtk_scale_set_value_pos (GTK_SCALE(value) , GTK_POS_RIGHT); 
    gtk_range_set_value (GTK_RANGE( value ) , settings->max_results);
    gtk_box_pack_start (GTK_BOX(box) , value , TRUE , TRUE , 0);
    g_signal_connect (G_OBJECT (value) , "value-changed" , G_CALLBACK(max_results_cb) , settings);

    // PHOTO DISPLAY
    photo = gtk_check_button_new_with_mnemonic( _("_Display contact photo if available"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(photo), settings->display_contact_photo);
    g_signal_connect (G_OBJECT(photo) , "clicked" , G_CALLBACK (display_contact_photo_cb) , settings);
    gtk_box_pack_start (GTK_BOX(box) , photo , TRUE , TRUE , 1);
     
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    label = gtk_label_new (_("Search for and display: "));
    gtk_box_pack_start (GTK_BOX(box) , label , FALSE , FALSE , 1);
    
    item = gtk_check_button_new_with_mnemonic( _("_Business phone"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item), settings->search_phone_business);
    g_signal_connect (G_OBJECT(item) , "clicked" , G_CALLBACK (search_phone_business_cb) , settings);
    gtk_box_pack_start (GTK_BOX(box) , item , TRUE , TRUE , 1);
     
    item = gtk_check_button_new_with_mnemonic( _("_Home phone"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item), settings->search_phone_home);
    g_signal_connect (G_OBJECT(item) , "clicked" , G_CALLBACK (search_phone_home_cb) , settings);
    gtk_box_pack_start (GTK_BOX(box) , item , TRUE , TRUE , 1);
     
    item = gtk_check_button_new_with_mnemonic( _("_Mobile phone"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item), settings->search_phone_mobile);
    g_signal_connect (G_OBJECT(item) , "clicked" , G_CALLBACK (search_phone_mobile_cb) , settings);
    gtk_box_pack_start (GTK_BOX(box) , item , TRUE , TRUE , 1);
     
135 136 137 138 139
    gtk_widget_show_all(ret);

    return ret;

}