[go: up one dir, main page]

File: machine.cpp

package info (click to toggle)
qtsmbstatus 2.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,292 kB
  • ctags: 522
  • sloc: cpp: 4,273; sh: 131; makefile: 9
file content (133 lines) | stat: -rw-r--r-- 3,926 bytes parent folder | download | duplicates (3)
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
/***************************************************************************
 *   Copyright (C) 2004 by Daniel Rocher                                   *
 *   daniel.rocher@adella.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.,                                       *
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
 ***************************************************************************/

 /**
	\class machine
	\brief Class of machine items
	\date 2008-11-08
	\version 2.0
	\author Daniel Rocher
	\sa server user service

	'machine' is parent of 'user' and child of 'server'
 */


#include <QtGui>

#include "machine.h"

extern QList<QTreeWidgetItem *> QTreeWidgetItemList;
extern void debugQt(const QString & message);

int machine::compteur_objet=0;


machine::machine(QTreeWidgetItem * parent,const QString & PID,const QString & Username, const QString & Group,const QString & MachineName, const QString & MachineIP) : QTreeWidgetItem(parent)
{
	debugQt("Object machine : "+QString::number(++compteur_objet));
	QTreeWidgetItemList.append(this);
	mark=true;
	machine_name=MachineName;
	machine_ip=MachineIP;
	QIcon icon;
	icon.addPixmap(QPixmap(":/icons/machine.png"), QIcon::Normal, QIcon::Off);
	this->setIcon( 0, icon ); //icone
	this->setText ( 0, machine_name) ;
	// add new user
	new user(this,PID,Username,Group);
}

machine::~machine(){
	debugQt("Object machine : "+QString::number(--compteur_objet));
	QTreeWidgetItemList.removeAll (this);
}

/**
	Add user if not exist
*/
void machine::append_user(const QString & PID,const QString & Name,const QString & Group)
{
	bool exist=false;
	for (int i=0;  i < this->childCount (); ++i )
	{
		user * Child= dynamic_cast<user *>(this->child (i) );
		if (!Child) break;
		// If exist
		if  (Child->pid==PID)
		{
			exist=true;
			// Mark this object
			Child->mark=true;
			// replace nobody by real name
			if   ((Child->username=="nobody") && (Name!="nobody"))
			{
				Child->username=Name;
				Child->group=Group;
				Child->setText(0,Name);
			}
			return; // exit loop
		}
	}
	// if not exist add user
	if (!exist) new user (this,PID,Name,Group);
}


/**
	Refresh view. Delete obsolete objects (mark = false).
	\sa mark_childs
*/
void machine::refresh_childs()
{
	for (int i=0;  i < this->childCount (); ++i )
	{
		user * Child= dynamic_cast<user *>(this->child (i) );
		if (!Child) break;
		
		// if child doesn't exist any more
		if (!Child->mark)
		{
			delete Child;  // delete item and his children
			--i;
			continue;
		}
		// if child exist
		Child->refresh_childs();
	}
}


/**
	Mark all children.
 	- mark = true -> exist
 	- mark = false -> obsolete
	\sa refresh_childs
 */
void machine::mark_childs()
{
	for (int i=0;  i < this->childCount (); ++i )
	{
		user * Child= dynamic_cast<user *>(this->child (i) );
		if (!Child) break;
		Child->mark=false;
		Child->mark_childs();
	}
}