[Frugalware-git] frugal-tweak: *added group for a user * http://dors.frugalware.org/users.png :p

bouleetbil bouleetbil at frogdev.info
Sat Nov 13 12:26:05 CET 2010


Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=frugal-tweak.git;a=commitdiff;h=178f38ee3b2d8445bcbb2f755545ad69e9b31dc3

commit 178f38ee3b2d8445bcbb2f755545ad69e9b31dc3
Author: bouleetbil <bouleetbil at frogdev.info>
Date:   Sat Nov 13 12:22:06 2010 +0100

*added group for a user
* http://dors.frugalware.org/users.png :p

diff --git a/frugal-mono-tools/Group.cs b/frugal-mono-tools/Group.cs
index 8f6e630..0f53709 100644
--- a/frugal-mono-tools/Group.cs
+++ b/frugal-mono-tools/Group.cs
@@ -64,6 +64,13 @@ namespace frugalmonotools
try
{
this.Id=Convert.ToInt32(line.Split(':')[2]);
+						//now find users
+						string[] ch_Users = line.Split(':')[3].ToString().Split(',');
+						foreach (string ch_User in ch_Users)
+		   				{
+							User user = new User(ch_User);
+							this._users.Add(user);
+						}
}
catch{}
break;
diff --git a/frugal-mono-tools/Groups.cs b/frugal-mono-tools/Groups.cs
index 7951ec5..57e855c 100644
--- a/frugal-mono-tools/Groups.cs
+++ b/frugal-mono-tools/Groups.cs
@@ -20,7 +20,12 @@ using System.Collections;
using System.Collections.Generic;

namespace frugalmonotools
-{
+{
+	public struct GroupUser
+	{
+		public Group TheGroup;
+		public bool Into;
+	}
public static class Groups
{
public static string cch_FileUser = @"/etc/passwd";
@@ -41,7 +46,38 @@ namespace frugalmonotools
}
return users;
}
-
+
+		public static List<GroupUser> GetGroup(string username)
+		{
+			List<GroupUser> groupsUser = new List<GroupUser>();
+
+			string ch_ContentsFileGroup=Outils.ReadFile(Groups.cch_FileGroup);
+			string[] lines = ch_ContentsFileGroup.Split('\n');
+			foreach (string line in lines)
+		    {
+				//storage::30:hald,gaetan
+				if(line.Split(':')[0].ToString().Trim()!="")
+				{
+					Group Agroup = new Group(line.Split(':')[0]);
+					GroupUser groupUser = new GroupUser();
+					groupUser.TheGroup=Agroup;
+					//extract users from this group
+					bool bo_Into = false;
+					string[] userNames = line.Split(':')[3].ToString().Split(',');
+					foreach (string name in userNames)
+					{
+						if(name==username)
+						{
+							bo_Into=true;
+							break;
+						}
+					}
+					groupUser.Into=bo_Into;
+					groupsUser.Add(groupUser);
+				}
+			}
+			return groupsUser;
+		}
}
}

diff --git a/frugal-mono-tools/Pictures/WID_Users.cs b/frugal-mono-tools/Pictures/WID_Users.cs
index e408195..463f2fc 100644
--- a/frugal-mono-tools/Pictures/WID_Users.cs
+++ b/frugal-mono-tools/Pictures/WID_Users.cs
@@ -23,15 +23,19 @@ namespace frugalmonotools
[System.ComponentModel.ToolboxItem(true)]
public partial class WID_Users : Gtk.Bin
{
+		private const int columnSelected = 0;
+
private Gtk.TreeIter iter;
-		ListStore ListStoreUser = new Gtk.ListStore (typeof (string));
+		ListStore ListStoreUser = new Gtk.ListStore (typeof (string));
+		ListStore ListStoreUserGroup = new Gtk.ListStore (typeof (bool),typeof (string));
public WID_Users ()
{
this.Build ();
}
public void InitUsers()
{
-			// Create a column for the package name
+			#region treeview users
+			// Create a column for the name
Gtk.TreeViewColumn ColumnUser = new Gtk.TreeViewColumn ();
ColumnUser.Title = "Users";
Gtk.CellRendererText NameCellUser = new Gtk.CellRendererText ();
@@ -48,7 +52,41 @@ namespace frugalmonotools
TREE_Users.Model=ListStoreUser;
// Event on treeview
TREE_Users.Selection.Changed += OnSelectionUser;
+			#endregion
+
+			#region treeview user groups
+			Gtk.TreeViewColumn ColumnCheck = new Gtk.TreeViewColumn ();
+			ColumnCheck.Title = "";
+			Gtk.CellRendererToggle NameCellCheck= new Gtk.CellRendererToggle ();
+			NameCellCheck.Activatable = true;
+			NameCellCheck.Toggled += new ToggledHandler (SelectToggled);
+			// Add the cell to the column
+			ColumnCheck.PackStart (NameCellCheck, true);
+			TREE_UserGroup.AppendColumn (ColumnCheck);
+			ColumnCheck.AddAttribute (NameCellCheck, "active", 0);
+
+
+			// Create a column for the package name
+			Gtk.TreeViewColumn ColumnGroup = new Gtk.TreeViewColumn ();
+			ColumnGroup.Title = "Group";
+			Gtk.CellRendererText NameCellGroup= new Gtk.CellRendererText ();
+			// Add the cell to the column
+			ColumnGroup.PackStart (NameCellGroup, true);
+			TREE_UserGroup.AppendColumn (ColumnGroup);
+			ColumnGroup.AddAttribute (NameCellGroup, "text", 1);
+			TREE_UserGroup.Model=ListStoreUserGroup;
+			#endregion
+
}
+		private void SelectToggled (object sender, ToggledArgs args)
+	    {
+	       TreeIter iter;
+	      if (ListStoreUserGroup.GetIterFromString (out iter, args.Path)) {
+	         bool val = (bool) ListStoreUserGroup.GetValue (iter, columnSelected);
+	         ListStoreUserGroup.SetValue (iter, columnSelected, !val);
+	       }
+	    }
+
protected void OnSelectionUser (object o, EventArgs args)
{
try
@@ -62,11 +100,25 @@ namespace frugalmonotools
SAI_Comment.Text=user.Comment;
SAI_Shell.Text=user.Shell;
SAI_Home.Text=user.Home;
+					SAI_Pass.Text="";
+					FindGroupUser(user.Name);
}
}
catch{}
}
-
+		private void FindGroupUser(string name)
+		{
+			ListStoreUserGroup.Clear();
+			List<GroupUser> groupsUser = Groups.GetGroup(name);
+			foreach (GroupUser groupUser in groupsUser)
+		    {
+				if(groupUser.Into)
+					ListStoreUserGroup.AppendValues (true,groupUser.TheGroup.Name);
+				else
+					ListStoreUserGroup.AppendValues (false,groupUser.TheGroup.Name);
+			}
+
+		}
}
}

diff --git a/frugal-mono-tools/User.cs b/frugal-mono-tools/User.cs
index c03666a..0e5da34 100644
--- a/frugal-mono-tools/User.cs
+++ b/frugal-mono-tools/User.cs
@@ -28,10 +28,20 @@ namespace frugalmonotools
private string _comment="";
private string _shell="";
private string _home="";
+		private string _pass="";
private List<Group> _groups = new List<Group>();
#endregion

#region public
+		public string Pass {
+			get {
+				return this._pass;
+			}
+			set {
+				_pass = value;
+			}
+		}
+
public string Comment {
get {
return this._comment;
@@ -128,11 +138,17 @@ namespace frugalmonotools
}
public List<Group> GetGroups()
{
-			if ((this.Name=="") && (this.Id==0))
-			{
+			if (this.Name=="")
return null;
+			_groups.Clear();
+			//read group
+			string ch_ContentsFileUsers=Outils.ReadFile(Groups.cch_FileGroup);
+			string[] lines = ch_ContentsFileUsers.Split('\n');
+			foreach (string line in lines)
+		    {
+				//storage::30:hald,gaetan
}
-			return null;
+			return _groups;
}

}
diff --git a/frugal-mono-tools/gtk-gui/frugalmonotools.WID_Users.cs b/frugal-mono-tools/gtk-gui/frugalmonotools.WID_Users.cs
index de56ca8..0c3529d 100644
--- a/frugal-mono-tools/gtk-gui/frugalmonotools.WID_Users.cs
+++ b/frugal-mono-tools/gtk-gui/frugalmonotools.WID_Users.cs
@@ -28,7 +28,15 @@ namespace frugalmonotools

private global::Gtk.Entry SAI_Home;

-		private global::Gtk.Entry SAI_Groups;
+		private global::Gtk.HBox hbox5;
+
+		private global::Gtk.Label label3;
+
+		private global::Gtk.Entry SAI_Pass;
+
+		private global::Gtk.ScrolledWindow GtkScrolledWindow2;
+
+		private global::Gtk.TreeView TREE_UserGroup;

private global::Gtk.HBox hbox2;

@@ -152,16 +160,46 @@ namespace frugalmonotools
w10.Expand = false;
w10.Fill = false;
// Container child vbox2.Gtk.Box+BoxChild
-			this.SAI_Groups = new global::Gtk.Entry ();
-			this.SAI_Groups.CanFocus = true;
-			this.SAI_Groups.Name = "SAI_Groups";
-			this.SAI_Groups.IsEditable = true;
-			this.SAI_Groups.InvisibleChar = '•';
-			this.vbox2.Add (this.SAI_Groups);
-			global::Gtk.Box.BoxChild w11 = ((global::Gtk.Box.BoxChild)(this.vbox2[this.SAI_Groups]));
-			w11.Position = 4;
+			this.hbox5 = new global::Gtk.HBox ();
+			this.hbox5.Name = "hbox5";
+			this.hbox5.Spacing = 6;
+			// Container child hbox5.Gtk.Box+BoxChild
+			this.label3 = new global::Gtk.Label ();
+			this.label3.Name = "label3";
+			this.label3.LabelProp = global::Mono.Unix.Catalog.GetString ("Password :");
+			this.hbox5.Add (this.label3);
+			global::Gtk.Box.BoxChild w11 = ((global::Gtk.Box.BoxChild)(this.hbox5[this.label3]));
+			w11.Position = 0;
w11.Expand = false;
w11.Fill = false;
+			// Container child hbox5.Gtk.Box+BoxChild
+			this.SAI_Pass = new global::Gtk.Entry ();
+			this.SAI_Pass.TooltipMarkup = "Password";
+			this.SAI_Pass.CanFocus = true;
+			this.SAI_Pass.Name = "SAI_Pass";
+			this.SAI_Pass.IsEditable = true;
+			this.SAI_Pass.Visibility = false;
+			this.SAI_Pass.InvisibleChar = '•';
+			this.hbox5.Add (this.SAI_Pass);
+			global::Gtk.Box.BoxChild w12 = ((global::Gtk.Box.BoxChild)(this.hbox5[this.SAI_Pass]));
+			w12.Position = 1;
+			this.vbox2.Add (this.hbox5);
+			global::Gtk.Box.BoxChild w13 = ((global::Gtk.Box.BoxChild)(this.vbox2[this.hbox5]));
+			w13.Position = 4;
+			w13.Expand = false;
+			w13.Fill = false;
+			// Container child vbox2.Gtk.Box+BoxChild
+			this.GtkScrolledWindow2 = new global::Gtk.ScrolledWindow ();
+			this.GtkScrolledWindow2.Name = "GtkScrolledWindow2";
+			this.GtkScrolledWindow2.ShadowType = ((global::Gtk.ShadowType)(1));
+			// Container child GtkScrolledWindow2.Gtk.Container+ContainerChild
+			this.TREE_UserGroup = new global::Gtk.TreeView ();
+			this.TREE_UserGroup.CanFocus = true;
+			this.TREE_UserGroup.Name = "TREE_UserGroup";
+			this.GtkScrolledWindow2.Add (this.TREE_UserGroup);
+			this.vbox2.Add (this.GtkScrolledWindow2);
+			global::Gtk.Box.BoxChild w15 = ((global::Gtk.Box.BoxChild)(this.vbox2[this.GtkScrolledWindow2]));
+			w15.Position = 5;
// Container child vbox2.Gtk.Box+BoxChild
this.hbox2 = new global::Gtk.HBox ();
this.hbox2.Name = "hbox2";
@@ -172,83 +210,83 @@ namespace frugalmonotools
this.BTN_AddUser.Name = "BTN_AddUser";
this.BTN_AddUser.UseUnderline = true;
// Container child BTN_AddUser.Gtk.Container+ContainerChild
-			global::Gtk.Alignment w12 = new global::Gtk.Alignment (0.5f, 0.5f, 0f, 0f);
+			global::Gtk.Alignment w16 = new global::Gtk.Alignment (0.5f, 0.5f, 0f, 0f);
// Container child GtkAlignment.Gtk.Container+ContainerChild
-			global::Gtk.HBox w13 = new global::Gtk.HBox ();
-			w13.Spacing = 2;
+			global::Gtk.HBox w17 = new global::Gtk.HBox ();
+			w17.Spacing = 2;
// Container child GtkHBox.Gtk.Container+ContainerChild
-			global::Gtk.Image w14 = new global::Gtk.Image ();
-			w14.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-add", global::Gtk.IconSize.Menu);
-			w13.Add (w14);
+			global::Gtk.Image w18 = new global::Gtk.Image ();
+			w18.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-add", global::Gtk.IconSize.Menu);
+			w17.Add (w18);
// Container child GtkHBox.Gtk.Container+ContainerChild
-			global::Gtk.Label w16 = new global::Gtk.Label ();
-			w16.LabelProp = global::Mono.Unix.Catalog.GetString ("Add user");
-			w16.UseUnderline = true;
-			w13.Add (w16);
-			w12.Add (w13);
-			this.BTN_AddUser.Add (w12);
+			global::Gtk.Label w20 = new global::Gtk.Label ();
+			w20.LabelProp = global::Mono.Unix.Catalog.GetString ("Add user");
+			w20.UseUnderline = true;
+			w17.Add (w20);
+			w16.Add (w17);
+			this.BTN_AddUser.Add (w16);
this.hbox2.Add (this.BTN_AddUser);
-			global::Gtk.Box.BoxChild w20 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.BTN_AddUser]));
-			w20.Position = 0;
-			w20.Expand = false;
-			w20.Fill = false;
+			global::Gtk.Box.BoxChild w24 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.BTN_AddUser]));
+			w24.Position = 0;
+			w24.Expand = false;
+			w24.Fill = false;
// Container child hbox2.Gtk.Box+BoxChild
this.BTN_Remove = new global::Gtk.Button ();
this.BTN_Remove.CanFocus = true;
this.BTN_Remove.Name = "BTN_Remove";
this.BTN_Remove.UseUnderline = true;
// Container child BTN_Remove.Gtk.Container+ContainerChild
-			global::Gtk.Alignment w21 = new global::Gtk.Alignment (0.5f, 0.5f, 0f, 0f);
+			global::Gtk.Alignment w25 = new global::Gtk.Alignment (0.5f, 0.5f, 0f, 0f);
// Container child GtkAlignment.Gtk.Container+ContainerChild
-			global::Gtk.HBox w22 = new global::Gtk.HBox ();
-			w22.Spacing = 2;
+			global::Gtk.HBox w26 = new global::Gtk.HBox ();
+			w26.Spacing = 2;
// Container child GtkHBox.Gtk.Container+ContainerChild
-			global::Gtk.Image w23 = new global::Gtk.Image ();
-			w23.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-delete", global::Gtk.IconSize.Menu);
-			w22.Add (w23);
+			global::Gtk.Image w27 = new global::Gtk.Image ();
+			w27.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-delete", global::Gtk.IconSize.Menu);
+			w26.Add (w27);
// Container child GtkHBox.Gtk.Container+ContainerChild
-			global::Gtk.Label w25 = new global::Gtk.Label ();
-			w25.LabelProp = global::Mono.Unix.Catalog.GetString ("Remove user");
-			w25.UseUnderline = true;
-			w22.Add (w25);
-			w21.Add (w22);
-			this.BTN_Remove.Add (w21);
+			global::Gtk.Label w29 = new global::Gtk.Label ();
+			w29.LabelProp = global::Mono.Unix.Catalog.GetString ("Remove user");
+			w29.UseUnderline = true;
+			w26.Add (w29);
+			w25.Add (w26);
+			this.BTN_Remove.Add (w25);
this.hbox2.Add (this.BTN_Remove);
-			global::Gtk.Box.BoxChild w29 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.BTN_Remove]));
-			w29.Position = 1;
-			w29.Expand = false;
-			w29.Fill = false;
+			global::Gtk.Box.BoxChild w33 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.BTN_Remove]));
+			w33.Position = 1;
+			w33.Expand = false;
+			w33.Fill = false;
// Container child hbox2.Gtk.Box+BoxChild
this.BTN_Apply = new global::Gtk.Button ();
this.BTN_Apply.CanFocus = true;
this.BTN_Apply.Name = "BTN_Apply";
this.BTN_Apply.UseUnderline = true;
// Container child BTN_Apply.Gtk.Container+ContainerChild
-			global::Gtk.Alignment w30 = new global::Gtk.Alignment (0.5f, 0.5f, 0f, 0f);
+			global::Gtk.Alignment w34 = new global::Gtk.Alignment (0.5f, 0.5f, 0f, 0f);
// Container child GtkAlignment.Gtk.Container+ContainerChild
-			global::Gtk.HBox w31 = new global::Gtk.HBox ();
-			w31.Spacing = 2;
+			global::Gtk.HBox w35 = new global::Gtk.HBox ();
+			w35.Spacing = 2;
// Container child GtkHBox.Gtk.Container+ContainerChild
-			global::Gtk.Image w32 = new global::Gtk.Image ();
-			w32.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-apply", global::Gtk.IconSize.Menu);
-			w31.Add (w32);
+			global::Gtk.Image w36 = new global::Gtk.Image ();
+			w36.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-apply", global::Gtk.IconSize.Menu);
+			w35.Add (w36);
// Container child GtkHBox.Gtk.Container+ContainerChild
-			global::Gtk.Label w34 = new global::Gtk.Label ();
-			w34.LabelProp = global::Mono.Unix.Catalog.GetString ("Apply");
-			w34.UseUnderline = true;
-			w31.Add (w34);
-			w30.Add (w31);
-			this.BTN_Apply.Add (w30);
+			global::Gtk.Label w38 = new global::Gtk.Label ();
+			w38.LabelProp = global::Mono.Unix.Catalog.GetString ("Apply");
+			w38.UseUnderline = true;
+			w35.Add (w38);
+			w34.Add (w35);
+			this.BTN_Apply.Add (w34);
this.hbox2.Add (this.BTN_Apply);
-			global::Gtk.Box.BoxChild w38 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.BTN_Apply]));
-			w38.Position = 2;
-			w38.Expand = false;
-			w38.Fill = false;
+			global::Gtk.Box.BoxChild w42 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.BTN_Apply]));
+			w42.Position = 2;
+			w42.Expand = false;
+			w42.Fill = false;
this.vbox2.Add (this.hbox2);
-			global::Gtk.Box.BoxChild w39 = ((global::Gtk.Box.BoxChild)(this.vbox2[this.hbox2]));
-			w39.Position = 6;
-			w39.Expand = false;
-			w39.Fill = false;
+			global::Gtk.Box.BoxChild w43 = ((global::Gtk.Box.BoxChild)(this.vbox2[this.hbox2]));
+			w43.Position = 6;
+			w43.Expand = false;
+			w43.Fill = false;
this.notebook1.Add (this.vbox2);
// Notebook tab
this.label1 = new global::Gtk.Label ();
@@ -270,11 +308,11 @@ namespace frugalmonotools
this.TREE_Groups.Name = "TREE_Groups";
this.GtkScrolledWindow1.Add (this.TREE_Groups);
this.vbox3.Add (this.GtkScrolledWindow1);
-			global::Gtk.Box.BoxChild w42 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.GtkScrolledWindow1]));
-			w42.Position = 0;
+			global::Gtk.Box.BoxChild w46 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.GtkScrolledWindow1]));
+			w46.Position = 0;
this.notebook1.Add (this.vbox3);
-			global::Gtk.Notebook.NotebookChild w43 = ((global::Gtk.Notebook.NotebookChild)(this.notebook1[this.vbox3]));
-			w43.Position = 1;
+			global::Gtk.Notebook.NotebookChild w47 = ((global::Gtk.Notebook.NotebookChild)(this.notebook1[this.vbox3]));
+			w47.Position = 1;
// Notebook tab
this.label2 = new global::Gtk.Label ();
this.label2.Name = "label2";
diff --git a/frugal-mono-tools/gtk-gui/gui.stetic b/frugal-mono-tools/gtk-gui/gui.stetic
index d4a8faf..cf86381 100644
--- a/frugal-mono-tools/gtk-gui/gui.stetic
+++ b/frugal-mono-tools/gtk-gui/gui.stetic
@@ -3472,7 +3472,7 @@ Public License instead of this License.
</widget>
</child>
</widget>
-  <widget class="Gtk.Bin" id="frugalmonotools.WID_Users" design-size="346 327">
+  <widget class="Gtk.Bin" id="frugalmonotools.WID_Users" design-size="346 377">
<property name="MemberName" />
<property name="Visible">False</property>
<child>
@@ -3614,11 +3614,35 @@ Public License instead of this License.
</packing>
</child>
<child>
-              <widget class="Gtk.Entry" id="SAI_Groups">
+              <widget class="Gtk.HBox" id="hbox5">
<property name="MemberName" />
-                <property name="CanFocus">True</property>
-                <property name="IsEditable">True</property>
-                <property name="InvisibleChar">•</property>
+                <property name="Spacing">6</property>
+                <child>
+                  <widget class="Gtk.Label" id="label3">
+                    <property name="MemberName" />
+                    <property name="LabelProp" translatable="yes">Password :</property>
+                  </widget>
+                  <packing>
+                    <property name="Position">0</property>
+                    <property name="AutoSize">True</property>
+                    <property name="Expand">False</property>
+                    <property name="Fill">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="Gtk.Entry" id="SAI_Pass">
+                    <property name="MemberName" />
+                    <property name="Tooltip" translatable="yes">Password</property>
+                    <property name="CanFocus">True</property>
+                    <property name="IsEditable">True</property>
+                    <property name="Visibility">False</property>
+                    <property name="InvisibleChar">•</property>
+                  </widget>
+                  <packing>
+                    <property name="Position">1</property>
+                    <property name="AutoSize">True</property>
+                  </packing>
+                </child>
</widget>
<packing>
<property name="Position">4</property>
@@ -3628,7 +3652,21 @@ Public License instead of this License.
</packing>
</child>
<child>
-              <placeholder />
+              <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow2">
+                <property name="MemberName" />
+                <property name="ShadowType">In</property>
+                <child>
+                  <widget class="Gtk.TreeView" id="TREE_UserGroup">
+                    <property name="MemberName" />
+                    <property name="CanFocus">True</property>
+                    <property name="ShowScrollbars">True</property>
+                  </widget>
+                </child>
+              </widget>
+              <packing>
+                <property name="Position">5</property>
+                <property name="AutoSize">True</property>
+              </packing>
</child>
<child>
<widget class="Gtk.HBox" id="hbox2">


More information about the Frugalware-git mailing list