File: procview.c

package info (click to toggle)
gtop 0.28.1-5
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,324 kB
  • ctags: 890
  • sloc: ansic: 6,141; sh: 4,766; cpp: 355; makefile: 281; sed: 93
file content (1471 lines) | stat: -rw-r--r-- 36,539 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
#include <config.h>

#include <string.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>

#include <glibtop.h>
#include <glibtop/xmalloc.h>
#include <glibtop/union.h>

#include <gnome.h>

#include "procview.h"
#include "fromtop.h"
#include "procbar.h"
#include "proc.h"
#include "details.h"
#include "global.h"

#include "asc.xpm"
#include "dsc.xpm"

#include "cpu.xpm"
#include "mem.xpm"
#include "swap.xpm"

#define CF ((proc_field *)c->data)
#define CG (*((gint *)g->data))

static GtkWidget *nLabel;
static GtkWidget *clist;
static GtkWidget *clist_menu;
static GtkWidget *vbox;
static GtkWidget *handle_box;
static GtkWidget *summary;

static gint cfg_summary;
static ProcInfo summary_info;

gint cfg_show_summary;
gint cfg_show_summary_cpu;
gint cfg_show_summary_mem;
gint cfg_show_summary_swap;
gint cfg_has_swap;

GtkWidget *summary_cpu;
GtkWidget *summary_mem;
GtkWidget *summary_swap = NULL;

static GList *field_list = NULL;
static GList *geometry_list = NULL;
static GtkWidget *sort_asc, *sort_dsc;
static gint field_list_length;
static gint select_pid = -1;

static gint read_proc_mask = 0;
static gint read_proc_method = GLIBTOP_KERN_PROC_ALL;
static gint read_proc_arg = 0;
static uid_t user_uid;

/* procview idle run or frozen */
static gint cfg_run;
static gint run_tag = -1;
static gint cfg_sf, cfg_order;

static GtkWidget *xpm_run;
static GtkWidget *xpm_stop;

static GtkWidget *xpm_cpu;
static GtkWidget *xpm_mem;
static GtkWidget *xpm_swap;

static gint p_current_time;
static time_t p_time;
static float p_elapsed_time;
static unsigned long p_total_time;

/* cumulative mode */
static gint p_cl_sum = 0;

static unsigned long p_gl_main_mem;

/* static proc_t **proc_tab = NULL; */
static unsigned *proc_tab = NULL;
static int prev_count = 0;

ProcProcData **proc_data = NULL;

static gint first = 1;

static gint procview_update ();
static void procview_init (gchar *, gchar *);
static void procview_open_details ();
static GtkWidget * procview_clist_prepare ();

static GtkWidget     * renice_dialog = NULL;
static GtkAdjustment * renice_aj;
static GtkWidget     * renice_msg;

static void procview_cfg_read ();

static gchar *cpu_texts [4] = {
	N_("User"),  N_("Nice"),   N_("System"),  N_("Idle")
};

static gchar *mem_texts [4] =  {
	N_("Other"), N_("Shared"), N_("Buffers"), N_("Free")
};

static gchar *swap_texts [2] = {
	N_("Used"),  N_("Free")
};

static const gchar *cpu_defaults [4] = {
	"#ffffffff4fff", "#dfffdfffdfff",
	"#afffafffafff", "#000000000000"
};

static const gchar *mem_defaults [4] = {
	"#bfffbfff4fff", "#efffefff4fff",
	"#afffafffafff", "#00008fff0000"
};

static const gchar *swap_defaults [2] = {
	"#cfff5fff5fff", "#00008fff0000"
};

static void procview_properties_init (GTopPropertiesHook *hook, GtkWidget *win);
static void procview_properties_update (GTopPropertiesHook *hook);
static void procview_properties_load (GTopPropertiesHook *hook);
static void procview_properties_save (GTopPropertiesHook *hook);

static void summary_properties_init (GTopPropertiesHook *hook, GtkWidget *win);
static void summary_properties_update (GTopPropertiesHook *hook);
static void summary_properties_load (GTopPropertiesHook *hook);
static void summary_properties_save (GTopPropertiesHook *hook);

GTopPropertiesHook ProcViewPropertiesHook = {
	procview_properties_init,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL
};

GTopPropertiesHook SummaryColorsPropertiesHook = {
	summary_properties_init,
	NULL,
	summary_properties_update,
	summary_properties_load,
	summary_properties_save,
	NULL
};

#define CMP_DINT(NAME) \
\
static int cmp_ ## NAME (const ProcProcData **P, const ProcProcData **Q) \
{ \
	  return sort_order * ((*P)-> ## NAME - (*Q)-> ## NAME); \
}

#define CMP_INT(NAME) \
\
static int cmp_ ## NAME (const ProcProcData **P, const ProcProcData **Q) \
{ \
	  return sort_order * ((*P)->p-> ## NAME - (*Q)->p-> ## NAME); \
}

#define CMP_INT2(NAME,V1,V2) \
\
static int cmp_ ## NAME (const ProcProcData **P, const ProcProcData **Q) \
{ \
	  return sort_order * ((*P)->p-> ## V1 + (*P)->p-> ## V2 - (\
                               (*Q)->p-> ## V1 + (*Q)->p-> ## V2)); \
}

#define CMP_STR(NAME) \
\
static int cmp_ ## NAME (const ProcProcData **P, const ProcProcData **Q) \
{ \
	  return sort_order * strcasecmp ((*P)->p-> ## NAME, (*Q)->p-> ## NAME); \
}

#define SORT_ASC 1
#define SORT_DSC -1

static int sort_field = -1;
static int sort_order = SORT_ASC;

CMP_INT (stime)
CMP_INT (utime)
CMP_INT2 (time, stime, utime)
CMP_INT (pid)
CMP_DINT (pcpu)
CMP_DINT (pmem)
CMP_INT (size)
CMP_INT (rss)
CMP_INT (resident)
CMP_INT (nice)
CMP_INT (priority)
CMP_INT (share)

CMP_STR (user)
CMP_STR (cmd)

proc_field p_fields [] = {

	{ N_("PID"), N_("Process ID"),
	  P_PID, cmp_pid, SORT_ASC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("User"), N_("User name"),
	  P_USER, cmp_user, SORT_ASC, PROC_FILLUSR, GTK_JUSTIFY_LEFT, NULL},
	{ N_("Pri"), N_("Priority"),
	  P_PRIORITY, cmp_priority, SORT_ASC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("Ni"), N_("Nice"),
	  P_NICE, cmp_nice, SORT_ASC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("Size"), N_("Used memory size"),
	  P_SIZE, cmp_size, SORT_DSC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("RSS"), N_("Resident memory set size"),
	  P_RSS, cmp_rss, SORT_DSC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("Share"), N_("Shared memory size"),
	  P_SHARE, cmp_share, SORT_DSC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("Stat"), N_("Process state"),
	  P_STATE, NULL, SORT_ASC, 0, GTK_JUSTIFY_LEFT, NULL},
	{ N_("CPU"), N_("Percent CPU usage"),
	  P_PCPU, cmp_pcpu, SORT_DSC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("MEM"), N_("Percent memory usage"),
	  P_PMEM, cmp_pmem, SORT_DSC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("Time"), N_("Time consumed"),
	  P_TIME, cmp_time, SORT_DSC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("UTime"), N_("User time consumed"),
	  P_UTIME, cmp_utime, SORT_DSC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("STime"), N_("System time consumed"),
	  P_STIME, cmp_stime, SORT_DSC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ N_("Cmd"), N_("Command"),
	  P_CMD, cmp_cmd, SORT_ASC, PROC_FILLCMD, GTK_JUSTIFY_LEFT, NULL},
	{ N_("Resident"), N_("Resident memory size"),
	  P_RESIDENT, cmp_resident, SORT_DSC, 0, GTK_JUSTIFY_RIGHT, NULL},
	{ NULL, NULL, 0, NULL, 0, 0, 0, NULL},
};

struct _gtop_signal {
	gchar *name;
	gint sig_num;
} gtop_signals [] = {
	{"SIGHUP", SIGHUP},
	{"SIGINT", SIGINT},
	{"SIGQUIT", SIGQUIT},
	{"SIGILL", SIGILL},
	{"SIGTRAP", SIGTRAP},
	{"SIGABRT", SIGABRT},
	{"SIGIOT", SIGIOT},
	{"SIGBUS", SIGBUS},
	{"SIGFPE", SIGFPE},
	{"SIGKILL", SIGKILL},
	{"SIGUSR1", SIGUSR1},
	{"SIGSEGV", SIGSEGV},
	{"SIGUSR2", SIGUSR2},
	{"SIGPIPE", SIGPIPE},
	{"SIGALRM", SIGALRM},
	{"SIGTERM", SIGTERM},
#ifdef SIGSTKFLT
	{"SIGSTKFLT", SIGSTKFLT},
#endif
	{"SIGCHLD", SIGCHLD},
	{"SIGCONT", SIGCONT},
	{"SIGSTOP", SIGSTOP},
	{"SIGTSTP", SIGTSTP},
	{"SIGTTIN", SIGTTIN},
	{"SIGTTOU", SIGTTOU},
	{"SIGURG", SIGURG},
	{"SIGXCPU", SIGXCPU},
	{"SIGXFSZ", SIGXFSZ},
	{"SIGVTALRM", SIGVTALRM},
	{"SIGPROF", SIGPROF},
	{"SIGWINCH", SIGWINCH},
	{"SIGIO", SIGIO},
#ifdef SIGUNUSED
	{"SIGUNUSED", SIGUNUSED},
#endif
	{NULL, 0},
};

static void procview_click_column (GtkCList *cl, gint n);
void procview_handler (GtkNotebook *, GtkNotebookPage *, GTopPageSignal);

void
procview_all_procs ()
{
	read_proc_method = GLIBTOP_KERN_PROC_ALL;
	read_proc_mask = 0;
	read_proc_arg = 0;

	procview_update ();
}

void
procview_tty_procs ()
{
	read_proc_mask |= GLIBTOP_EXCLUDE_NOTTY;

	procview_update ();
}

void
procview_user_procs ()
{
	read_proc_method = GLIBTOP_KERN_PROC_UID;
	read_proc_arg = getuid ();

	procview_update ();
}

void
procview_start_stop (gint start)
{
	/* char **pd = (cfg_run) ? tb_timer_stopped_xpm : tb_timer_xpm; */

	if (!start) {
		if (run_tag != -1) {
			gtk_timeout_remove (run_tag);
			run_tag = -1;
		}

	} else {

		if (run_tag != -1)
			return;

		procview_update ();
		run_tag = gtk_timeout_add (3000, procview_update, NULL);
	}

	gnome_stock_set_icon ((GnomeStock *) (TBC (RUN)->icon),
			      (start) ? GNOME_STOCK_PIXMAP_TIMER :
			      GNOME_STOCK_PIXMAP_TIMER_STOP);

	gtk_widget_queue_draw (GTK_WIDGET (TBC (RUN)->widget));
}

static void
procview_tbar_time (GtkWidget *w, gpointer gp)
{
	cfg_run = !cfg_run;
	procview_start_stop (cfg_run);
}

GnomeUIInfo procViewMenu [] = {
  {GNOME_APP_UI_ITEM, N_("All processes"), NULL, procview_all_procs, NULL, NULL,
   GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL},
  {GNOME_APP_UI_ITEM, N_("User processes"), NULL, procview_user_procs, NULL, NULL,
   GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL},
  {GNOME_APP_UI_ITEM, N_("TTY processes"), NULL, procview_tty_procs, NULL, NULL,
   GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL},
  GNOMEUIINFO_END
};

gint
procview_cpu ()
{
	proc_read_cpu (&summary_info);
	gnome_proc_bar_set_values (GNOME_PROC_BAR (summary_cpu), summary_info.cpu);

	return TRUE;
}

gint
procview_mem ()
{
	proc_read_mem (&summary_info);
	gnome_proc_bar_set_values (GNOME_PROC_BAR (summary_mem), summary_info.mem);
	if (summary_swap)
		gnome_proc_bar_set_values (GNOME_PROC_BAR (summary_swap), summary_info.swap);

	return TRUE;
}

static GtkWidget *
procview_summary ()
{
	GtkWidget *hbox;

	hbox = gtk_hbox_new (TRUE, GNOME_PAD_SMALL);

	proc_read_mem (&summary_info);
	summary_cpu = gnome_proc_bar_new
		(xpm_cpu, PROC_CPU_SIZE-1,
		 gtop_properties.summary_cpu, procview_cpu);

	summary_mem = gnome_proc_bar_new
		(xpm_mem, PROC_MEM_SIZE-2,
		 gtop_properties.summary_mem, procview_mem);

	cfg_has_swap = (summary_info.swap [PROC_SWAP_TOTAL]);

	summary_swap = gnome_proc_bar_new
		(xpm_swap, PROC_SWAP_SIZE-1,
		 gtop_properties.summary_swap, NULL);

	gtk_box_pack_start_defaults (GTK_BOX (hbox), summary_cpu);
	gtk_box_pack_start_defaults (GTK_BOX (hbox), summary_mem);
	if (cfg_has_swap)
		gtk_box_pack_start_defaults (GTK_BOX (hbox), summary_swap);

	if (cfg_show_summary_cpu)
		gtk_widget_show (summary_cpu);

	if (cfg_has_swap && cfg_show_summary_mem)
		gtk_widget_show (summary_mem);

	if (cfg_show_summary_swap && cfg_has_swap)
		gtk_widget_show (summary_swap);

	return hbox;
}

#define PIX(x) widget = gnome_pixmap_new_from_xpm_d (x ## _xpm); \
                        gtk_widget_ref (widget);
               

void *
addProcessesView ()
{
	GtkWidget *widget;

	procview_cfg_read ();

	sort_asc = PIX (asc);
	sort_dsc = PIX (dsc);

	xpm_run = PIX (tb_timer);
	xpm_stop = PIX (tb_timer_stopped);

	xpm_cpu = PIX (cpu);
	xpm_mem = PIX (mem);
	xpm_swap = PIX (swap);

	procview_init (gnome_config_get_string
		       ("/gtop/procview/fields=0,1,2,3,4,5,6,7,8,9,10,13"),
		       gnome_config_get_string
		       ("/gtop/procview/geometry"
			"=50,80,30,30,50,50,50,50,60,60,60,200"));	

	nLabel = gtk_label_new (_("Processes"));
	clist = procview_clist_prepare ();

	procview_click_column (GTK_CLIST (clist), cfg_sf);

	summary = procview_summary ();
	handle_box = gtk_handle_box_new ();
	vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);

	/* GTK_HANDLE_BOX (handle_box)->shrink_on_detach = 0; */
#if 0
	GTK_HANDLE_BOX (handle_box)->shadow_type = GTK_SHADOW_NONE;
#endif
	gtk_container_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL);

	gtk_container_add (GTK_CONTAINER (handle_box), summary);
	gtk_box_pack_start (GTK_BOX (vbox), handle_box, FALSE, TRUE, 0);
	gtk_box_pack_start_defaults (GTK_BOX (vbox), clist);

	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox, nLabel);

	if (cfg_show_summary)
		gtk_widget_show (summary);

	gtk_widget_show (nLabel);
	gtk_widget_show (clist);
	gtk_widget_show (handle_box);
	gtk_widget_show (vbox);
	
	/* pt = openproc (PROC_FILLUSR); */
	/* when I don't call meminfo, nice & priority values are malformed */
	/* don't know why ?!? */
	/* meminfo (); */

	procview_update ();

	return procview_handler;
}

static void
procview_cfg_read ()
{
	printf ("proview_cfg_read\n");

	cfg_run = gnome_config_get_int ("/gtop/procview/run=1");

	cfg_show_summary = gnome_config_get_int ("/gtop/procview/show_summary=1");
	cfg_show_summary_cpu  = gnome_config_get_int ("/gtop/procview/show_summary_cpu=1");
	cfg_show_summary_mem  = gnome_config_get_int ("/gtop/procview/show_summary_mem=1");
	cfg_show_summary_swap = gnome_config_get_int ("/gtop/procview/show_summary_swap=1");

	cfg_sf    = gnome_config_get_int ("/gtop/procview/sort_field=8");
	cfg_order = gnome_config_get_int ("/gtop/procview/sort_order=1");

	p_fields [cfg_sf].order = (cfg_order) ? SORT_DSC : SORT_ASC;
}

static void
procview_cfg_save ()
{
	/* printf ("proview_cfg_save\n"); */

	gnome_config_set_int ("/gtop/procview/run", cfg_run);
	gnome_config_set_int ("/gtop/procview/show_summary", cfg_show_summary);
	gnome_config_set_int ("/gtop/procview/show_summary_cpu", cfg_show_summary_cpu);
	gnome_config_set_int ("/gtop/procview/show_summary_mem", cfg_show_summary_mem);
	gnome_config_set_int ("/gtop/procview/show_summary_swap", cfg_show_summary_swap);

	gnome_config_sync ();
}

void
procview_handler (GtkNotebook *notebook, GtkNotebookPage *page, GTopPageSignal s)
{
	/*printf ("procview handler %x %x\n", page->child, vbox);*/

	/* check if it is for me */
	if (page->child == vbox) {

		switch (s) {

		case GTOP_PAGE_CFG_READ:

			procview_cfg_read ();
			break;

		case GTOP_PAGE_CFG_SAVE:

			procview_cfg_save ();
			break;

		case GTOP_PAGE_ENTER:

			/*printf ("procview page entered\n");*/
			/* cfg_run = !cfg_run_save; */

			gtop_time_cb = procview_tbar_time;
			procview_start_stop (cfg_run);

			if (!cfg_summary) {
				gnome_proc_bar_start (GNOME_PROC_BAR (summary_cpu), 200);
				gnome_proc_bar_start (GNOME_PROC_BAR (summary_mem), 200);
			}

			gnome_app_menu_show (GNOME_APP(window),
					     GTOP_MENU_VIEW, -1);

			break;

		case GTOP_PAGE_LEAVE:

			/*printf ("procview page leaved\n");*/
			gtop_time_cb = NULL;
			procview_start_stop (0);

			if (!cfg_summary) {
				gnome_proc_bar_stop (GNOME_PROC_BAR (summary_cpu));
				gnome_proc_bar_stop (GNOME_PROC_BAR (summary_mem));
			}

			gnome_app_menu_hide (GNOME_APP(window),
					     GTOP_MENU_VIEW, -1);
			break;
		}
	}
}

static void
procview_click_column (GtkCList *cl, gint n)
{
	GtkWidget *arrow;
	GList *c = g_list_nth (field_list, n);
	gint nsf = CF - p_fields;

	/* has compare function ??*/
	if (!CF->compare)
		return;

	if (sort_field >= 0) {

		arrow = (p_fields [sort_field].order == SORT_ASC) ? sort_asc : sort_dsc;

		gtk_widget_hide (arrow);
		gtk_widget_unrealize (arrow);
		gtk_widget_hide (p_fields [sort_field].hb);
		gtk_container_remove (GTK_CONTAINER (p_fields [sort_field].hb),
				      arrow);
		gtk_widget_show (p_fields [sort_field].hb);
	}

	if (nsf == sort_field)

		CF->order = (CF->order == SORT_ASC) ?
			SORT_DSC : SORT_ASC;
	
	cfg_sf = n;
	cfg_order = CF->order;
	sort_field = nsf;
	arrow = (CF->order == SORT_ASC) ? sort_asc : sort_dsc;
	gtk_box_pack_start (GTK_BOX (CF->hb), arrow,
			    FALSE, FALSE, 2);
	gtk_widget_show (arrow);
	procview_update ();
}

static void
procview_un_select_row (GtkCList *cl, gint row, gint col, GdkEventButton * e, gpointer gp)
{
	gint i = (gint)gp;

	/* printf ("select_row: %d col: %d pid: %d\n", row, col, proc_data [row]->p->pid); */
	if (row < prev_count)
		if (!i)
			select_pid = proc_data [row]->p->pid;
		else
			select_pid = -1;

	if (e)
		if (e->button == 1 && (dwin || e->type == GDK_2BUTTON_PRESS))
			procview_open_details ();
}

static void
procview_clist_button_press (GtkCList *cl, GdkEventButton *e)
{
	/*printf ("clist button press\n");*/
	/*printf ("type: %u button: %u\n", e->type, e->button);*/

	if (e->button != 1)
		gtk_signal_emit_stop_by_name (GTK_OBJECT (cl), "button_press_event");

	if (select_pid != -1 && e->button == 3)
		gtk_menu_popup(GTK_MENU (clist_menu), NULL, NULL, NULL,
			       NULL, e->button, time(NULL));
}

static void
procview_send_signal (GtkWidget *w, gint s)
{
	if (select_pid != -1)
		kill (select_pid, s);
}

static void
procview_open_details ()
{
	if (select_pid != -1)
		procview_details (select_pid);
}

static void
renice_destroy ()
{
	renice_dialog = NULL;
}

static void
renice_cb (GtkWidget *w, gint n)
{
	if (n!=2) {
		gint  rv, nv = renice_aj->value;
		gchar *msg, tmp [256];

		/* printf ("set priotiry of process %d to %d\n", select_pid, nv); */

		rv = setpriority (PRIO_PROCESS, select_pid, nv);

		msg = NULL; /* keep gcc happy */

		if (rv == -1) {
			switch (errno) {
			case ESRCH:
				g_snprintf (tmp, 256, _("Cannot locate process %d"), select_pid);
				msg = tmp;
				break;
			case EACCES:
				msg = _("Only root can set negative priority");
				break;
			case EPERM:
				msg = _("Permission denied");
				break;
			}
			n = 1;
		} else {
			procview_update ();
			msg = "";
		}

		/* printf ("renice msg: %s\n", msg); */

		gtk_label_set (GTK_LABEL (renice_msg), msg);
	}

	if (n==2 || !n)
		gtk_widget_destroy (renice_dialog);
}

static void
procview_renice ()
{
	if (!renice_dialog) {

		GtkWidget *hs;
		GtkWidget *lb;

		renice_dialog = gnome_dialog_new (_("Renice"),
						  GNOME_STOCK_BUTTON_OK,
						  GNOME_STOCK_BUTTON_APPLY,
						  GNOME_STOCK_BUTTON_CANCEL,
						  NULL);
		renice_aj = (GtkAdjustment *) gtk_adjustment_new (getpriority (PRIO_PROCESS,
									       select_pid),
						-20, 20, 1, 1, 0);
		hs = gtk_hscale_new (renice_aj);
		gtk_scale_set_digits (GTK_SCALE (hs), 0);
		lb = gtk_label_new (_("Set priority"));
		renice_msg = gtk_label_new ("");
		gtk_misc_set_alignment (GTK_MISC (lb), 0, 1);
		gtk_misc_set_alignment (GTK_MISC (renice_msg), 0, 1);

		gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (renice_dialog)->vbox),
					     lb, TRUE, TRUE, 0);
		gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG (renice_dialog)->vbox),
					     hs);
		gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (renice_dialog)->vbox),
					     renice_msg, TRUE, TRUE, 0);

		gnome_dialog_button_connect (GNOME_DIALOG (renice_dialog),
					     0, (GtkSignalFunc) renice_cb, (gpointer) 0);
		gnome_dialog_button_connect (GNOME_DIALOG (renice_dialog),
					     1, (GtkSignalFunc) renice_cb, (gpointer) 1);
		gnome_dialog_button_connect (GNOME_DIALOG (renice_dialog),
					     2, (GtkSignalFunc) renice_cb, (gpointer) 2);
		gtk_signal_connect (GTK_OBJECT (renice_dialog), "destroy",
				    (GtkSignalFunc) renice_destroy, NULL);

		gtk_widget_show (lb);
		gtk_widget_show (hs);
		gtk_widget_show (renice_msg);
		gtk_widget_show (renice_dialog);
	}
}

static GtkWidget *
procview_clist_menu_prepare ()
{
	GtkWidget *menu;
	GtkWidget *smenu;
	GtkWidget *mi;
	gint i;

	menu = gtk_menu_new ();
	mi = gtk_menu_item_new_with_label (_("Send"));
	gtk_menu_append (GTK_MENU (menu), mi);
	gtk_widget_show (mi);

	smenu = gtk_menu_new ();
	gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), smenu);

	for (i=0; gtop_signals [i].name; i++) {
		mi = gtk_menu_item_new_with_label (_(gtop_signals [i].name));
		gtk_signal_connect (GTK_OBJECT (mi), "activate",
				    GTK_SIGNAL_FUNC (procview_send_signal),
				    (gpointer) gtop_signals [i].sig_num);
		gtk_menu_append (GTK_MENU (smenu), mi);
		gtk_widget_show (mi);

		if (!((i+1) % 17)) {
			/* separator */
			mi = gtk_menu_item_new ();
			gtk_menu_append (GTK_MENU (smenu), mi);
			gtk_widget_show (mi);

			mi = gtk_menu_item_new_with_label (_("More ..."));
			gtk_menu_append (GTK_MENU (smenu), mi);
			gtk_widget_show (mi);

			smenu = gtk_menu_new ();
			gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), smenu);
		}
	}

	/* separator */
	mi = gtk_menu_item_new ();
	gtk_menu_append (GTK_MENU (menu), mi);
	gtk_widget_show (mi);

	mi = gtk_menu_item_new_with_label (_("SIGTERM"));
	gtk_signal_connect (GTK_OBJECT (mi), "activate",
			    GTK_SIGNAL_FUNC (procview_send_signal),
			    (gpointer) SIGTERM);
	gtk_menu_append (GTK_MENU (menu), mi);
	gtk_widget_show (mi);

	mi = gtk_menu_item_new_with_label (_("SIGKILL"));
	gtk_signal_connect (GTK_OBJECT (mi), "activate",
			    GTK_SIGNAL_FUNC (procview_send_signal),
			    (gpointer) SIGKILL);
	gtk_menu_append (GTK_MENU (menu), mi);
	gtk_widget_show (mi);

	/* separator */
	mi = gtk_menu_item_new ();
	gtk_menu_append (GTK_MENU (menu), mi);
	gtk_widget_show (mi);

	mi = gtk_menu_item_new_with_label (_("Renice ..."));
	gtk_signal_connect (GTK_OBJECT (mi), "activate",
			    GTK_SIGNAL_FUNC (procview_renice),
			    NULL);
	gtk_menu_append (GTK_MENU (menu), mi);
	gtk_widget_show (mi);

	mi = gtk_menu_item_new_with_label (_("Details ..."));
	gtk_signal_connect (GTK_OBJECT (mi), "activate",
			    GTK_SIGNAL_FUNC (procview_open_details),
			    NULL);
	gtk_menu_append (GTK_MENU (menu), mi);
	gtk_widget_show (mi);

	return menu;
}

static GtkWidget *
procview_clist_prepare ()
{
	GtkWidget *cl;
	gint i=0;
	GList *c = field_list;
	GList *g = geometry_list;
	gchar **text = g_new (gchar *, field_list_length);
	GtkWidget *l;
	GtkTooltips *tips;

	cl = gtk_clist_new (field_list_length);
	gtk_clist_column_titles_show (GTK_CLIST (cl));
	gtk_widget_set_name (cl, "ProcessList");

	tips = gtk_tooltips_new ();
	gtk_object_set_data (GTK_OBJECT (window), "tooltips", tips);

	while (c) {
		l = gtk_label_new (_(CF->label));
		gtk_label_set_justify (GTK_LABEL (l), CF->justification);
		gtk_widget_show (l);
		gtk_tooltips_set_tip (tips, l,
				      CF->long_info, "tip");
		CF->hb = gtk_hbox_new (FALSE, 0);
		gtk_box_pack_start_defaults (GTK_BOX (CF->hb), l);
		gtk_widget_show (CF->hb);
		gtk_clist_set_column_widget (GTK_CLIST (cl), i, CF->hb);

		i++;
		c = c->next;
	}

	clist_menu = procview_clist_menu_prepare ();

	gtk_clist_set_policy (GTK_CLIST (cl),
			      GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_signal_connect (GTK_OBJECT (cl), "click_column",
			    GTK_SIGNAL_FUNC (procview_click_column), NULL);
	gtk_signal_connect (GTK_OBJECT (cl), "select_row",
			    GTK_SIGNAL_FUNC (procview_un_select_row), (gpointer) 0);
	gtk_signal_connect (GTK_OBJECT (cl), "unselect_row",
			    GTK_SIGNAL_FUNC (procview_un_select_row), (gpointer) 1);
	gtk_signal_connect (GTK_OBJECT (cl), "button_press_event",
			    GTK_SIGNAL_FUNC (procview_clist_button_press), NULL);
        

	g_free (text);

	c = field_list;
	i = 0;
	while (c) {
		gtk_clist_set_column_justification (GTK_CLIST (cl), i,
						    CF->justification);
		gtk_clist_set_column_width (GTK_CLIST (cl), i++, CG);
		c = c->next;
		g = g->next;
	}

	gtk_tooltips_set_tip (tips, cl,
			      "tip", "tip");

	return cl;
}

void
procview_init (gchar *s, gchar *g)
{
	gchar *c = g_strdup (s);
	gchar *t;
	gchar *gc = g_strdup (g);
	gchar *gt;
	gchar *cc=c;
	gchar *gcc=gc;
	gint ndx;
	gint *ip;

	/*printf ("procview init: %s\n", s);*/

	user_uid = getuid ();

	field_list_length = 0;
	do {
		t=strchr (c, ',');
		if (c && *c) {
			if (t)
				*t=0;
			ndx = atoi (c);
			/*printf ("%s %d: %s\n", s, ndx, p_fields [ndx].label);*/
			field_list = g_list_append (field_list, p_fields+ndx);
			field_list_length++;
			if (t)
				c=t+1;
		}	     

		gt=strchr (gc, ',');
		if (gc && *gc) {
			if (gt)
				*gt=0;
			ip = g_new (gint, 1);
			*ip = atoi (gc);
			/*printf ("%s %d\n", g, *ip);*/
			geometry_list = g_list_append (geometry_list, ip);
			if (gt)
				gc=gt+1;
		}	     
	} while (t && gt);

	g_free (cc);
	g_free (gcc);
}

gchar *
sprint_fmt (ProcProcData *d, p_fmt fmt)
{
	proc_t *t = d->p;
	gchar tmp[256];
	gchar *rv;

	switch (fmt) {
	case P_TIME:
	case P_UTIME:
	case P_STIME:
	case P_PID:
	case P_PRIORITY:
	case P_NICE:
	case P_RSS:
	case P_SIZE:
	case P_SHARE:
	case P_PCPU:
	case P_PMEM:
	case P_RESIDENT:
		switch (fmt) {
		case P_TIME:
			sprint_time (tmp, t->utime + t->stime, t->hz);
			break;
		case P_UTIME:
			sprint_time (tmp, t->utime, t->hz);
			break;
		case P_STIME:
			sprint_time (tmp, t->stime, t->hz);
			break;
		case P_PID:
			sprintf (tmp, "%d", t->pid);
			break;
		case P_PRIORITY:
			sprintf (tmp, "%d", t->priority);
			break;
		case P_NICE:
			sprintf (tmp, "%d", t->nice);
			break;
		case P_RSS:
			sprintf (tmp, "%ld", t->rss);
			break;
		case P_SIZE:
			sprintf (tmp, "%ld", t->size);
			break;
		case P_SHARE:
			sprintf (tmp, "%ld", t->share);
			break;
		case P_PCPU:
			sprintf (tmp, "%2d.%1d", d->pcpu / 10, d->pcpu % 10);
			break;
		case P_PMEM:
			sprintf (tmp, "%2d.%1d", d->pmem / 10, d->pmem % 10);
			break;
		case P_RESIDENT:
			sprintf (tmp, "%ld", t->resident);
			break;
		default:
			break;
		}
		rv = tmp;
		break;
	case P_STATE:
		rv = status (t);
		break;
	case P_USER:
		rv = t->user;
		break;
	case P_CMD:
		rv = t->cmd;
		break;
	default:
		rv = "?";
	}

	return g_strdup (rv);
}

int
procview_clist_thaw (gpointer p)
{
	gtk_clist_thaw (GTK_CLIST (clist));

	return FALSE;
}

void
procview_update_clist (ProcProcData **pd)
{
	gint i=0;
	gint j, k;
	gchar **text = g_new (gchar *, field_list_length);
	ProcProcData *d;
	GList *c;
	float old_adj_hval = GTK_SCROLLBAR (GTK_CLIST (clist)->hscrollbar)
		->range.adjustment->value;
	float old_adj_vval = GTK_SCROLLBAR (GTK_CLIST (clist)->vscrollbar)
		->range.adjustment->value;
	gint old_hoffset = GTK_CLIST (clist)->hoffset;
	gint old_voffset = GTK_CLIST (clist)->voffset;
	gint row = -1;
	
	gtk_clist_freeze (GTK_CLIST (clist));
	gtk_clist_clear (GTK_CLIST (clist));

	while ((d = pd [i])) {
		i++;
		c = field_list;
		j = 0;

		while (c) {
			text [j] = sprint_fmt (d, CF->fmt);
			j++;
			c = c->next;
		}
		gtk_clist_append (GTK_CLIST (clist), text);

		for (k=0; k<j; k++)
			g_free (text [k]);
	}

	/* keep old view position - somewhat ughly, but works now */
	GTK_SCROLLBAR (GTK_CLIST (clist)->hscrollbar)
		->range.adjustment->value = old_adj_hval;
	GTK_SCROLLBAR (GTK_CLIST (clist)->vscrollbar)
		->range.adjustment->value = old_adj_vval;

	GTK_CLIST (clist)->hoffset = old_hoffset;
	GTK_CLIST (clist)->voffset = old_voffset;

	for (i=0; i < prev_count; i++)
		if (pd [i]->p->pid == select_pid)
			row = i;
	if (row >= 0)
		gtk_clist_select_row (GTK_CLIST (clist), row, -1);

	gtk_clist_thaw (GTK_CLIST (clist));

	g_free (text);
}

gint
procview_update ()
{
	/* printf ("procview update\n");*/

	static struct save_hist save_history [NR_TASKS];
	struct save_hist new_save_hist [NR_TASKS];
	glibtop_proclist proclist;
	glibtop_proc_state procstate;
	glibtop_proc_time proctime;
	glibtop_proc_mem procmem;
	glibtop_proc_uid procuid;
	glibtop_uptime uptime;
	glibtop_cpu cpu;
	glibtop_mem mem;
	struct passwd *pwd;
	int stime, utime;

	ProcProcData *d;
	proc_t *p;
	gint i, j, n=0;

	if (proc_tab)
		glibtop_free (proc_tab);

	glibtop_get_uptime (&uptime);
	p_current_time = uptime.uptime;
	p_time = time (NULL);
	p_elapsed_time = get_elapsed_time ();

#if 0
	fprintf (stderr, "START: %f - %ld - %ld - %f\n", p_elapsed_time,
		 (long) p_current_time, (long) p_time,
		 (double) p_elapsed_time);
#endif
	
	glibtop_get_mem (&mem);
	p_gl_main_mem = mem.total >> 10;

	proc_tab = glibtop_get_proclist (&proclist, read_proc_method |
					 read_proc_mask, read_proc_arg);

	if (proc_data) {
		for (i = 0; i < prev_count; i++)
			g_free (proc_data [i]);
		g_free (proc_data);
	}

	n = proclist.number;

	proc_data = (ProcProcData **) g_new (ProcProcData *, n+1);
	proc_data [n] = NULL;

	for (i = 0; i < n; i++) {
		/* allocate proc_data */
		d = proc_data [i] = (ProcProcData *) g_new (ProcProcData, 1);
		memset (&d->_p, 0, sizeof (d->_p));
		p = d->p = &d->_p;

		p->pid = proc_tab [i];

		glibtop_get_proc_state (&procstate, p->pid);
		
		p->cmd = glibtop_strdup (procstate.cmd);

		p->state = procstate.state;

		pwd = getpwuid (procstate.uid);
		if (pwd)
			p->user = glibtop_strdup (pwd->pw_name);
		else
			p->user = glibtop_strdup (_("<unknown>"));

		glibtop_get_proc_uid (&procuid, p->pid);

		p->nice     = procuid.nice;
		p->priority = procuid.priority;

		glibtop_get_proc_mem (&procmem, p->pid);

		p->size     = (unsigned long) procmem.size >> 10;
		p->rss      = (unsigned long) procmem.rss >> 10;
		p->resident = (unsigned long) procmem.resident >> 10;
		p->share    = (unsigned long) procmem.share >> 10;

		glibtop_get_proc_time (&proctime, p->pid);

#if 0
		fprintf (stderr, "TIME: %lu - (%lu, %lu) - (%lu, %lu)\n",
			 (unsigned long) proctime.start_time,
			 (unsigned long) proctime.utime,
			 (unsigned long) proctime.stime,
			 (unsigned long) proctime.cutime,
			 (unsigned long) proctime.cstime);
#endif

		p->hz = proctime.frequency ? proctime.frequency : 1000000;

		p->utime  = ((unsigned long) (proctime.utime * 100) / p->hz);
		p->stime  = ((unsigned long) (proctime.stime * 100) / p->hz);
		p->cutime = ((unsigned long) (proctime.cutime * 100) / p->hz);
		p->cstime = ((unsigned long) (proctime.cstime * 100) / p->hz);

		p->start_time =
			((unsigned long) (proctime.start_time * 100) / p->hz);

		/* compute some own fields for proc_data */
		/* PCPU */
		p_total_time = (p->utime + p->stime +
				(p_cl_sum ? p->cutime + p->cstime : 0));

#if 0
		fprintf (stderr, "Timings (%ld): %ld - %ld - %ld - "
			 "(%ld, %ld) - (%ld, %ld)\n",
			 p->pid, p_total_time, p->start_time, p_current_time,
			 p->utime, p->stime,
			 p->cutime, p->cstime);
#endif

		/* history */
		new_save_hist[i].ticks = p_total_time;
		new_save_hist[i].pid = p->pid;
		stime = p->stime;
		utime = p->utime;
		new_save_hist[i].stime = stime;
		new_save_hist[i].utime = utime;

		/* find matching entry from previous pass */
		j = 0;
		while (!first && j < MIN (prev_count, NR_TASKS)) {
			if (save_history[j].pid == p->pid) {
				p_total_time -= save_history[j].ticks;
				stime -= save_history[j].stime;
				utime -= save_history[j].utime;

				j = NR_TASKS;
			}
			j++;
		}

		if (first) {
			p_elapsed_time = (p_current_time*100 -
					  p->start_time)/HZ;
#if 0
			fprintf (stderr, "TIME2 (%ld): %d %d %f\n", p->pid,
				 HZ, p_current_time, p_elapsed_time);
#endif
		}

		d->pcpu = (p_elapsed_time > 0.001) ? (unsigned int)
			((float) (p_total_time * 10) / p_elapsed_time) : 0;

#if 0
		if (p_total_time && (p_elapsed_time > 0.001))
			fprintf (stderr, "CPU: %f - %ld - %d - %f - %s\n",
				 p_elapsed_time, p_total_time, (int) d->pcpu,
				 (float) (p_total_time * 10) / p_elapsed_time,
				 p->cmd);
#endif

		if (d->pcpu > 999)
			d->pcpu = 999;
		/* PMEM */
		d->pmem = p->rss * 1000 / p_gl_main_mem;

	}

	/* copy the relevant info for the next pass */
	for (i = 0; i < n; i++) {
		save_history[i].pid = new_save_hist[i].pid;
		save_history[i].ticks = new_save_hist[i].ticks;
		save_history[i].stime = new_save_hist[i].stime;
		save_history[i].utime = new_save_hist[i].utime;
	}

	prev_count = n;

	if (p_fields [sort_field].compare) {
		sort_order = p_fields [sort_field].order;
		qsort (proc_data, n, sizeof (ProcProcData *),
		       (int (*)(const void *, const void *))
		       p_fields [sort_field].compare);
	}

	/* update screen*/
	procview_update_clist (proc_data);
	first = 0;

	if (dwin)
		procview_open_details ();

	return TRUE;
}

static void
procview_properties_init (GTopPropertiesHook *hook, GtkWidget *win)
{
	GtkWidget *vb, *vbox, *frame, *label, *button, *spin, *table;
	GSList *group;
	gint i;

	vb    = gtk_vbox_new (FALSE, 0);
	gtk_container_border_width (GTK_CONTAINER (vb), GNOME_PAD_SMALL);
	vbox  = gtk_vbox_new (FALSE, 0);

	frame = gtk_frame_new (_("Update times (ms)"));
	table = gtk_table_new (2, 2, FALSE);
	gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD_SMALL);
	gtk_container_border_width (GTK_CONTAINER (table), GNOME_PAD_SMALL);

	label = gtk_label_new (_("Processes list"));
	gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
	gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1);

	spin = gtk_spin_button_new (NULL, 1, 0);
	gtk_table_attach_defaults (GTK_TABLE (table), spin, 1, 2, 0, 1);

	label = gtk_label_new (_("Summary"));
	gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
	gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2);

	spin = gtk_spin_button_new (NULL, 1, 0);
	gtk_table_attach_defaults (GTK_TABLE (table), spin, 1, 2, 1, 2);

	gtk_container_add (GTK_CONTAINER (frame), table);
	gtk_box_pack_start_defaults (GTK_BOX (vb), frame);

	frame = gtk_frame_new ("");
	table = gtk_table_new (2, 4, FALSE);
	gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD << 2);

	label = gtk_check_button_new_with_label (_("Show graphical summary"));
	gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 2, 0, 1);

	label = gtk_check_button_new_with_label (_("Show cpu usage"));
	gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 1, 2);
	label = gtk_check_button_new_with_label (_("Show physical memory usage"));
	gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 2, 3);
	label = gtk_check_button_new_with_label (_("Show swap memory usage"));
	gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 3, 4);

	gtk_container_add (GTK_CONTAINER (frame), table);
	gtk_box_pack_start_defaults (GTK_BOX (vb), frame);

	frame = gtk_frame_new ("");
	table = gtk_table_new (2, 3, FALSE);
	gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD << 2);

	label = gtk_check_button_new_with_label (_("Show text summary"));
	gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 2, 0, 1);

	label = gtk_check_button_new_with_label (_("Show uptime"));
	gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 1, 2);
	label = gtk_check_button_new_with_label (_("Show processes counts"));
	gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 2, 3);

	gtk_container_add (GTK_CONTAINER (frame), table);
	gtk_box_pack_start_defaults (GTK_BOX (vb), frame);

	gtk_notebook_append_page
	  (GTK_NOTEBOOK (GNOME_PROPERTY_BOX (win)->notebook),
	   vb, gtk_label_new (_("Processes")));
}

static void
summary_properties_update (GTopPropertiesHook *hook)
{
	gnome_proc_bar_update (GNOME_PROC_BAR (summary_cpu),
			       gtop_properties.summary_cpu);

	gnome_proc_bar_update (GNOME_PROC_BAR (summary_mem),
			       gtop_properties.summary_mem);

	gnome_proc_bar_update (GNOME_PROC_BAR (summary_swap),
			       gtop_properties.summary_swap);
}

static void
summary_properties_init (GTopPropertiesHook *hook, GtkWidget *win)
{
	GtkWidget *vb, *vbox, *frame, *label, *button, *spin, *table;
	GSList *group;
	gint i;

	vb = gtk_vbox_new (FALSE, 0);
	gtk_container_border_width (GTK_CONTAINER (vb), GNOME_PAD_SMALL);
	
	frame = gtk_frame_new (_("Summary CPU"));
	gtk_container_add (GTK_CONTAINER (frame),
			   gnome_proc_bar_properties
			   (4, gtop_temp_properties.summary_cpu, cpu_texts));
	gtk_box_pack_start (GTK_BOX (vb), frame, FALSE, TRUE, 0);

	frame = gtk_frame_new (_("Summary physical memory"));
	gtk_container_add (GTK_CONTAINER (frame),
			   gnome_proc_bar_properties
			   (4, gtop_temp_properties.summary_mem, mem_texts));
	gtk_box_pack_start (GTK_BOX (vb), frame, FALSE, TRUE, 0);

	frame = gtk_frame_new (_("Summary swap memory"));
	gtk_container_add (GTK_CONTAINER (frame),
			   gnome_proc_bar_properties
			   (2, gtop_temp_properties.summary_swap, swap_texts));
	gtk_box_pack_start (GTK_BOX (vb), frame, FALSE, TRUE, 0);

	gtk_notebook_append_page
	  (GTK_NOTEBOOK (GNOME_PROPERTY_BOX (win)->notebook),
	   vb, gtk_label_new (_("Summary colors")));
}

static void
summary_properties_load (GTopPropertiesHook *hook)
{
	char name [BUFSIZ], *tmp;
	gint i;

	for (i=0; i<4; i++) {
		GdkColor *color = &(gtop_properties.summary_cpu [i]);

		sprintf (name, "gtop/summary_cpu/color%d=%s", i,
			 cpu_defaults [i]);

		tmp = gnome_config_get_string (name);
		gdk_color_parse (tmp, color);
		g_free (tmp);
	}

	for (i=0; i<4; i++) {
		GdkColor *color = &(gtop_properties.summary_mem [i]);

		sprintf (name, "gtop/summary_mem/color%d=%s", i,
			 mem_defaults [i]);

		tmp = gnome_config_get_string (name);
		gdk_color_parse (tmp, color);
		g_free (tmp);
	}

	for (i=0; i<2; i++) {
		GdkColor *color = &(gtop_properties.summary_swap [i]);

		sprintf (name, "gtop/summary_swap/color%d=%s", i,
			 swap_defaults [i]);

		tmp = gnome_config_get_string (name);
		gdk_color_parse (tmp, color);
		g_free (tmp);
	}
}

static void
summary_properties_save (GTopPropertiesHook *hook)
{
	char name [BUFSIZ], tmp [BUFSIZ];
	gint i;

	for (i=0; i<4; i++) {
		GdkColor *color = &(gtop_properties.summary_cpu [i]);
		
		sprintf (tmp, "#%04x%04x%04x",
			 color->red, color->green, color->blue);

		sprintf (name, "gtop/summary_cpu/color%d", i);
		gnome_config_set_string (name, tmp);
	}

	for (i=0; i<4; i++) {
		GdkColor *color = &(gtop_properties.summary_mem [i]);

		sprintf (tmp, "#%04x%04x%04x",
			 color->red, color->green, color->blue);

		sprintf (name, "gtop/summary_mem/color%d", i);
		gnome_config_set_string (name, tmp);
	}

	for (i=0; i<2; i++) {
		GdkColor *color = &(gtop_properties.summary_swap [i]);

		sprintf (tmp, "#%04x%04x%04x",
			 color->red, color->green, color->blue);

		sprintf (name, "gtop/summary_swap/color%d", i);
		gnome_config_set_string (name, tmp);
	}
}