File: userinfo.cc

package info (click to toggle)
gps 0.9.4-1.woody2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 964 kB
  • ctags: 928
  • sloc: cpp: 10,822; sh: 381; makefile: 307; ansic: 227; perl: 17
file content (150 lines) | stat: -rw-r--r-- 3,977 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* $Id: userinfo.cc,v 1.5 2000/02/20 21:45:37 bergo Exp $ */

/*

    GPS - Graphical Process Statistics
    Copyright (C) 1999-2000 Felipe Paulo Guazzi Bergo
    bergo@seul.org

    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 2 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
#include <sys/types.h>
#include <gtk/gtk.h>
#include "transient.h"

#include "msgbox.h"
#include "userinfo.h"
#include "importglobals.h"

GtkWidget *nfo=NULL;

void uinfo_pop(char *username) {
  GtkWidget *v1,*t,*lw[20],*hs,*h1,*bt;
  char title[256],bz[64];
  int i;
  struct passwd *pss;
  struct group  *gss;

  if (nfo!=NULL)
    return;

  pss=getpwnam(username);
  gss=NULL;
  if (pss!=NULL)
    gss=getgrgid(pss->pw_gid);

  if ((pss==NULL)||(gss==NULL)) {
    message_box(MainWindow,
		"User database lookup failed.",
		"Failure",
		MSGBOX_OK,
		MSGBOX_ICON_ERROR);
    return;
  }

  nfo=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_transient_for(GTK_WINDOW(nfo),MainWindow);
  gtk_window_set_position(GTK_WINDOW(nfo),GTK_WIN_POS_CENTER);
  gtk_widget_realize(nfo);
  gtk_window_set_policy(GTK_WINDOW(nfo),TRUE,TRUE,TRUE);
  gethostname(bz,256);
  sprintf(title,"User Info (%s)",bz);
  gtk_window_set_title(GTK_WINDOW(nfo),title);
  gtk_container_set_border_width(GTK_CONTAINER(nfo),4);

  v1=gtk_vbox_new(FALSE,2);
  gtk_container_add(GTK_CONTAINER(nfo),v1);

  t=gtk_table_new(7,2,FALSE);
  gtk_box_pack_start(GTK_BOX(v1),t,TRUE,TRUE,2);

  lw[0]=boxed_label_new("Username");
  lw[1]=boxed_label_new("Real Name");
  lw[2]=boxed_label_new("UID");
  lw[3]=boxed_label_new("GID");
  lw[4]=boxed_label_new("Group");
  lw[5]=boxed_label_new("Home");
  lw[6]=boxed_label_new("Shell");

  lw[7]=boxed_label_new(pss->pw_name);
  lw[8]=boxed_label_new(pss->pw_gecos);
  sprintf(bz,"%d",(int)(pss->pw_uid));
  lw[9]=boxed_label_new(bz);
  sprintf(bz,"%d",(int)(pss->pw_gid));
  lw[10]=boxed_label_new(bz);
  lw[11]=boxed_label_new(gss->gr_name);
  lw[12]=boxed_label_new(pss->pw_dir);
  lw[13]=boxed_label_new(pss->pw_shell);
  
  for(i=0;i<7;i++) {
    gtk_table_attach_defaults(GTK_TABLE(t),lw[i],0,1,i,i+1);
    gtk_table_attach_defaults(GTK_TABLE(t),lw[i+7],1,2,i,i+1);
  }

  hs=gtk_hseparator_new();
  gtk_box_pack_start(GTK_BOX(v1),hs,FALSE,TRUE,2);

  h1=gtk_hbox_new(FALSE,2);
  gtk_box_pack_start(GTK_BOX(v1),h1,FALSE,TRUE,2);

  bt=gtk_button_new_with_label("   Dismiss   ");
  gtk_box_pack_end(GTK_BOX(h1),bt,FALSE,FALSE,2);

  gtk_signal_connect(GTK_OBJECT(bt),"clicked",
		     GTK_SIGNAL_FUNC(close_user_info),NULL);
  gtk_signal_connect (GTK_OBJECT (nfo), "destroy",
		      GTK_SIGNAL_FUNC (destroy_user_info), NULL);

  gtk_widget_show(v1);
  gtk_widget_show(h1);
  gtk_widget_show(hs);
  gtk_widget_show(bt);

  for(i=0;i<14;i++)
    gtk_widget_show(lw[i]);

  gtk_widget_show(t);
  gtk_widget_show(nfo);
  gtk_grab_add(nfo);
}

void close_user_info(GtkWidget *w, gpointer data) {
  gtk_grab_remove(nfo);
  gtk_widget_destroy(nfo);
  nfo=NULL;
}

void destroy_user_info(GtkWidget *w,gpointer data) {
  nfo=NULL;
}

GtkWidget *boxed_label_new(char *s) {
  GtkWidget *a,*b;

  a=gtk_hbox_new(FALSE,5);
  b=gtk_label_new(s);
  gtk_box_pack_start(GTK_BOX(a),b,FALSE,FALSE,4);
  gtk_widget_show(b);
  return(a);
}