Logo Search packages:      
Sourcecode: gadmin-dhcpd version File versions  Download package

create_main_window.c

/* GADMIN-DHCPD - An easy to use GTK+ frontend for ISC DHCPD.
 * Copyright (C) 2004 - 2008 Magnus Loef <magnus-swe@telia.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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
*/



#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
#include "widgets.h"
#include "gettext.h"
#include "locate_icons.h"
#include "activate_button_clicked.h"
#include "deactivate_button_clicked.h"
#include "reread_button_clicked.h"
#include "settings_window.h"
#include "show_help.h"
#include "credits_window.h"
#include "set_dhcpd_version.h"
#include "loadbalance_window.h"



void create_main_window(struct w *widgets)
{
    gchar *info, *pixmap_directory;
    GtkCellRenderer *pixbuf_cell_renderer;
    GdkPixbuf *pixbuf;

    /* Create the main window */    
    widgets->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW (widgets->main_window), GTK_WIN_POS_CENTER);
    gtk_widget_set_size_request(widgets->main_window, -1, 500);

    /* Set window information */
    info = g_strdup_printf("GADMIN-DHCPD %s", VERSION);
    gtk_window_set_title(GTK_WINDOW(widgets->main_window), info);
    g_free(info);

    /* Set the main window icon */    
    pixmap_directory = g_strdup_printf("%s/pixmaps/gadmin-dhcpd", PACKAGE_DATA_DIR);
    add_pixmap_directory(pixmap_directory);
    g_free(pixmap_directory);

    pixbuf_cell_renderer = gtk_cell_renderer_pixbuf_new();    
    pixbuf = create_pixbuf("gadmin-dhcpd.png");
    g_object_set(pixbuf_cell_renderer, "pixbuf", pixbuf, NULL); 
    gtk_window_set_icon(GTK_WINDOW(widgets->main_window), pixbuf);
    gdk_pixbuf_unref(pixbuf);

    widgets->main_vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add (GTK_CONTAINER (widgets->main_window), widgets->main_vbox);

    /* Hboxes (down) */
    GtkWidget *toolbar_hbox = gtk_hbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(widgets->main_vbox), toolbar_hbox, FALSE, FALSE, 0);

    GtkWidget *status_hbox = gtk_hbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(widgets->main_vbox), status_hbox, FALSE, FALSE, 0);

    GtkWidget *status_hsep_hbox = gtk_hbox_new(TRUE, 0);
    gtk_box_pack_start(GTK_BOX(widgets->main_vbox), status_hsep_hbox, FALSE, TRUE, 0);

    GtkWidget *notebook_hbox = gtk_hbox_new(TRUE, 0);
    gtk_box_pack_start(GTK_BOX(widgets->main_vbox), notebook_hbox, TRUE, TRUE, 0);

    /* Create the main toolbar */
    GtkWidget *main_toolbar = gtk_toolbar_new();
    gtk_box_pack_start(GTK_BOX(toolbar_hbox), main_toolbar, TRUE, TRUE, 0);

    gtk_toolbar_set_style(GTK_TOOLBAR(main_toolbar), GTK_TOOLBAR_BOTH);

    /* Activate button */    
    GtkWidget *toolbar_icon_yes = gtk_image_new_from_stock("gtk-yes", 
                                  gtk_toolbar_get_icon_size(GTK_TOOLBAR(main_toolbar)));
    GtkWidget *activate_button = gtk_toolbar_append_element(GTK_TOOLBAR(main_toolbar),
                                                          GTK_TOOLBAR_CHILD_BUTTON,
                                            NULL, _("Activate"), 
                                            NULL, NULL,
                                            toolbar_icon_yes, NULL, NULL);
    g_signal_connect_swapped(G_OBJECT(activate_button), "clicked", 
                             G_CALLBACK(activate_button_clicked), widgets);
    /* Deactivate button */
    GtkWidget *toolbar_icon_no = gtk_image_new_from_stock("gtk-no", 
                                 gtk_toolbar_get_icon_size(GTK_TOOLBAR(main_toolbar)));
    GtkWidget *deactivate_button = gtk_toolbar_append_element(GTK_TOOLBAR(main_toolbar),
                                                          GTK_TOOLBAR_CHILD_BUTTON,
                                            NULL, _("Deactivate"),
                                            NULL, NULL,
                                            toolbar_icon_no, NULL, NULL);
    g_signal_connect_swapped(G_OBJECT(deactivate_button), "clicked", 
                             G_CALLBACK(deactivate_button_clicked), widgets);
    /* Reread button */
    GtkWidget *toolbar_icon_refresh = gtk_image_new_from_stock("gtk-refresh", 
                                      gtk_toolbar_get_icon_size(GTK_TOOLBAR(main_toolbar)));
    GtkWidget *reread_button = gtk_toolbar_append_element(GTK_TOOLBAR(main_toolbar),
                                                          GTK_TOOLBAR_CHILD_BUTTON,
                                            NULL, _("Reread"),
                                            NULL, NULL,
                                            toolbar_icon_refresh, NULL, NULL);
    g_signal_connect_swapped(G_OBJECT(reread_button), "clicked", 
                             G_CALLBACK(reread_button_clicked), widgets);

    /* Settings button */
    GtkWidget *toolbar_icon_settings = gtk_image_new_from_stock("gtk-index", 
                                      gtk_toolbar_get_icon_size(GTK_TOOLBAR(main_toolbar)));
    GtkWidget *settings_button = gtk_toolbar_append_element(GTK_TOOLBAR(main_toolbar),
                                                          GTK_TOOLBAR_CHILD_BUTTON,
                                            NULL, _("Settings"),
                                            NULL, NULL,
                                            toolbar_icon_settings, NULL, NULL);
    g_signal_connect_swapped(G_OBJECT(settings_button), "clicked", 
                             G_CALLBACK(show_settings_window), widgets);


    /* Loadbalance button */
    GtkWidget *toolbar_icon_loadbalance = gtk_image_new_from_stock("gtk-convert", 
                                  gtk_toolbar_get_icon_size(GTK_TOOLBAR(main_toolbar)));
    GtkWidget *loadbalance_button = gtk_toolbar_append_element(GTK_TOOLBAR(main_toolbar),
                                                          GTK_TOOLBAR_CHILD_BUTTON,
                                            NULL, _("Loadbalance"), 
                                            NULL, NULL,
                                            toolbar_icon_loadbalance, NULL, NULL);
    g_signal_connect_swapped(G_OBJECT(loadbalance_button), "clicked", 
                             G_CALLBACK(show_loadbalance_window), widgets);




    /* Help button */
    GtkWidget *toolbar_icon_help = gtk_image_new_from_stock("gtk-help", 
                                   gtk_toolbar_get_icon_size(GTK_TOOLBAR(main_toolbar)));
    GtkWidget *help_button = gtk_toolbar_append_element(GTK_TOOLBAR(main_toolbar),
                                                          GTK_TOOLBAR_CHILD_BUTTON,
                                            NULL, _("Help"),
                                            NULL, NULL,
                                            toolbar_icon_help, NULL, NULL);
    g_signal_connect_swapped(G_OBJECT(help_button), "clicked", 
                             G_CALLBACK(show_help), widgets);


    /* Credits button */
    GtkWidget *toolbar_icon_credits = gtk_image_new_from_stock("gtk-justify-center", 
                                      gtk_toolbar_get_icon_size(GTK_TOOLBAR(main_toolbar)));
    GtkWidget *credits_button = gtk_toolbar_append_element(GTK_TOOLBAR(main_toolbar),
                                                          GTK_TOOLBAR_CHILD_BUTTON,
                                            NULL, _("Credits"),
                                            NULL, NULL,
                                            toolbar_icon_credits, NULL, NULL);
    g_signal_connect_swapped(G_OBJECT(credits_button), "clicked", 
                             G_CALLBACK(show_credits), widgets);


    /* Quit button */
    GtkWidget *toolbar_icon_quit = gtk_image_new_from_stock("gtk-quit", 
                                   gtk_toolbar_get_icon_size(GTK_TOOLBAR(main_toolbar)));
    GtkWidget *quit_button = gtk_toolbar_append_element(GTK_TOOLBAR(main_toolbar),
                                                          GTK_TOOLBAR_CHILD_BUTTON,
                                            NULL, _("Quit"),
                                            NULL, NULL,
                                            toolbar_icon_quit, NULL, NULL);
    g_signal_connect_swapped(G_OBJECT(quit_button), "clicked", 
                             G_CALLBACK(gtk_main_quit), NULL);

    /* The notebook */
    GtkWidget *notebook_vbox = gtk_vbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(notebook_hbox), notebook_vbox, TRUE, TRUE, 0);

    widgets->notebook_vbox1 = gtk_vbox_new(FALSE, 0);
    widgets->notebook_vbox2 = gtk_vbox_new(FALSE, 0);
    widgets->notebook_vbox3 = gtk_vbox_new(FALSE, 0);
    widgets->notebook_vbox4 = gtk_vbox_new(FALSE, 0);

    GtkWidget *main_notebook = gtk_notebook_new();
    gtk_box_pack_start(GTK_BOX(notebook_vbox), main_notebook, TRUE, TRUE, 0);
    gtk_notebook_set_show_border(GTK_NOTEBOOK(main_notebook), TRUE);
    gtk_widget_show(main_notebook);

    GtkWidget *scope_label = gtk_label_new(_("Scopes"));
    GtkWidget *single_hosts_label = gtk_label_new(_("Single hosts"));
    GtkWidget *leases_label = gtk_label_new(_("Leases"));
    GtkWidget *verify_label = gtk_label_new(_("Verify"));

    gtk_notebook_insert_page(GTK_NOTEBOOK(main_notebook), widgets->notebook_vbox1, scope_label, 0);
    gtk_notebook_insert_page(GTK_NOTEBOOK(main_notebook), widgets->notebook_vbox2, single_hosts_label, 1);
    gtk_notebook_insert_page(GTK_NOTEBOOK(main_notebook), widgets->notebook_vbox3, leases_label, 2);
    gtk_notebook_insert_page(GTK_NOTEBOOK(main_notebook), widgets->notebook_vbox4, verify_label, 3);

    /* Set version and status labels */
    widgets->dhcpd_version_label = gtk_label_new(_("Information: cant read version"));
    gtk_box_pack_start(GTK_BOX(status_hbox), widgets->dhcpd_version_label, FALSE, FALSE, 0);
    gtk_misc_set_alignment(GTK_MISC(widgets->dhcpd_version_label), 0, 0);

    /* Set dhcpd version */
    set_dhcpd_version(widgets);

    GtkWidget *status_spacer_label = gtk_label_new("");
    gtk_box_pack_start(GTK_BOX(status_hbox), status_spacer_label, TRUE, TRUE, 0);
    gtk_misc_set_alignment (GTK_MISC (status_spacer_label), 0, 0);

    widgets->onoff_label = gtk_label_new(_("Status: unknown"));
    gtk_box_pack_start(GTK_BOX(status_hbox), widgets->onoff_label, FALSE, FALSE, 0);
    gtk_misc_set_alignment (GTK_MISC (widgets->onoff_label), 0, 0);

    GtkWidget *status_hseparator = gtk_hseparator_new();
    gtk_box_pack_start(GTK_BOX(status_hsep_hbox), status_hseparator, TRUE, TRUE, 0);
    gtk_widget_set_size_request(status_hseparator, 10, 10);
}

Generated by  Doxygen 1.6.0   Back to index