~ubuntu-branches/ubuntu/trusty/gadmin-samba/trusty

« back to all changes in this revision

Viewing changes to src/populate_shell_combo.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-05-04 15:03:00 UTC
  • Revision ID: james.westby@ubuntu.com-20080504150300-cwpi1c1j49dxmbv3
Tags: upstream-0.2.4
ImportĀ upstreamĀ versionĀ 0.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GADMIN-SAMBA, an easy to use GTK+ frontend for the SAMBA file and print server.
 
2
 * Copyright (C) 2006, 2007, 2008 Magnus Loef <magnus-swe@telia.com> 
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 3 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
12
 * See the GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
*/
 
19
 
 
20
 
 
21
 
 
22
#include "../config.h"
 
23
#include <gtk/gtk.h>
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
#include <string.h>
 
27
#include "widgets.h"
 
28
#include "gettext.h"
 
29
#include "allocate.h"
 
30
#include "commands.h"
 
31
#include "show_info.h"
 
32
#include "populate_shell_combo.h"
 
33
 
 
34
 
 
35
 
 
36
void populate_shell_combo(GtkWidget *shell_combo)
 
37
{
 
38
    FILE *fp;
 
39
    long conf_size;
 
40
    int shell_found = 0;
 
41
    char *line, *new_buf;
 
42
    gchar *utf8=NULL;
 
43
    gchar *combo_text=NULL;
 
44
    gchar *info;
 
45
 
 
46
    /* Append a /dev/null shell first and select it */
 
47
    combo_text = g_strdup_printf("/dev/null");
 
48
    utf8 = g_locale_to_utf8(combo_text, strlen(combo_text), NULL, NULL, NULL);
 
49
    gtk_combo_box_append_text(GTK_COMBO_BOX(shell_combo), utf8);    
 
50
    gtk_combo_box_set_active(GTK_COMBO_BOX(shell_combo), 0);
 
51
    g_free(combo_text);
 
52
 
 
53
    if((fp=fopen(SHELLS_FILE, "r"))==NULL)
 
54
    {
 
55
        info = g_strdup_printf(_("Cant find the shells file here:\n%s\n"), SHELLS_FILE);
 
56
        show_info(info);
 
57
        g_free(info);
 
58
        return;
 
59
    }
 
60
    fseek(fp, 0, SEEK_END);
 
61
    conf_size = ftell(fp);
 
62
    rewind(fp);
 
63
 
 
64
    line = allocate(conf_size+2);
 
65
    new_buf = allocate(conf_size+2);
 
66
 
 
67
    if( conf_size > 1 )
 
68
    while(fgets(line, conf_size, fp)!=NULL)
 
69
    {
 
70
        /* Append all other shells but not /dev/null */
 
71
        if( strlen(line) > 3 && ! strstr(line, "#") && ! strstr(line, "/dev/null") )
 
72
        {
 
73
            shell_found = 1;
 
74
            strcpy(new_buf, line);
 
75
            utf8 = g_locale_to_utf8(new_buf, strlen(new_buf)-1, NULL, NULL, NULL);
 
76
            gtk_combo_box_append_text(GTK_COMBO_BOX(shell_combo), utf8);
 
77
        }
 
78
    }
 
79
    fclose(fp);
 
80
    free(line);
 
81
    free(new_buf);
 
82
 
 
83
    if( utf8!=NULL )
 
84
      g_free(utf8);
 
85
}