~vcs-imports/qtsmbstatus/trunk

« back to all changes in this revision

Viewing changes to client/user.cpp

  • Committer: rocher.daniel
  • Date: 2011-01-25 14:07:01 UTC
  • Revision ID: rocher.daniel-20110125140701-w9cvywjrdl9aqp9g
Add a warning file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2004 by Daniel Rocher                                   *
3
 
 *   daniel.rocher@adella.org                                              *
4
 
 *                                                                         *
5
 
 *   This program is free software; you can redistribute it and/or modify  *
6
 
 *   it under the terms of the GNU General Public License as published by  *
7
 
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 
 *   (at your option) any later version.                                   *
9
 
 *                                                                         *
10
 
 *   This program is distributed in the hope that it will be useful,       *
11
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 
 *   GNU General Public License for more details.                          *
14
 
 *                                                                         *
15
 
 *   You should have received a copy of the GNU General Public License     *
16
 
 *   along with this program; if not, write to the                         *
17
 
 *   Free Software Foundation, Inc.,                                       *
18
 
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
19
 
 ***************************************************************************/
20
 
 
21
 
 /**
22
 
        \class user
23
 
        \brief Class of user items
24
 
        \date 2008-11-08
25
 
        \version 2.0
26
 
        \author Daniel Rocher
27
 
        \sa server machine service
28
 
 
29
 
        'user' is parent of 'service' and child of 'machine'
30
 
 */
31
 
 
32
 
#include <QtGui>
33
 
 
34
 
#include "user.h"
35
 
 
36
 
extern void debugQt(const QString & message);
37
 
extern QList<QTreeWidgetItem *> QTreeWidgetItemList;
38
 
 
39
 
int user::compteur_objet=0;
40
 
 
41
 
user::user(QTreeWidgetItem * parent,const QString & PID,const QString & Username, const QString & Group) : QTreeWidgetItem(parent)
42
 
{
43
 
        debugQt("Object user : "+QString::number(++compteur_objet));
44
 
        QTreeWidgetItemList.append(this);
45
 
        mark=true;
46
 
        username=Username;
47
 
        pid=PID;
48
 
        group=Group;
49
 
        QIcon icon;
50
 
        icon.addPixmap(QPixmap(":/icons/user.png"), QIcon::Normal, QIcon::Off);
51
 
        this->setIcon( 0, icon ); //icon
52
 
        this->setText ( 0, Username) ;
53
 
}
54
 
 
55
 
user::~user(){
56
 
        debugQt("Object user : "+QString::number(--compteur_objet));
57
 
        QTreeWidgetItemList.removeAll (this);
58
 
}
59
 
 
60
 
/**
61
 
        add share if not exist
62
 
        \retval true already exist
63
 
        \retval false is new
64
 
*/
65
 
bool user::append_share(const QString & PID,const QString & Share,const QString & DateOpen)
66
 
{
67
 
        bool exist=false;
68
 
        for (int i=0;  i < this->childCount (); ++i )
69
 
        {
70
 
                service * Child= dynamic_cast<service *>(this->child (i) );
71
 
                if (!Child) break;
72
 
                // if child exist
73
 
                if  ((Child->pid==PID) && (Child->share==Share) )
74
 
                {
75
 
                        exist=true;
76
 
                        // Mark this object
77
 
                        Child->mark=true;
78
 
                        return true; // exit loop
79
 
                }
80
 
        }
81
 
        // if not exist add it
82
 
        if (!exist) new service (this,PID,Share,DateOpen);
83
 
        return false;
84
 
}
85
 
 
86
 
/**
87
 
        add lockedfile if not exist
88
 
        \retval true already exist
89
 
        \retval false is new
90
 
*/
91
 
bool user::append_lockedfile(const QString & PID,const QString & File,const QString & DenyMode,const QString & RW,const QString & Oplock,const QString & DateOpen)
92
 
{
93
 
        bool exist=false;
94
 
        for (int i=0;  i < this->childCount (); ++i )
95
 
        {
96
 
                service * Child= dynamic_cast<service *>(this->child (i) );
97
 
                if (!Child) break;
98
 
                // if child exist
99
 
                if  ((Child->pid==PID) && (Child->filename==File) && (Child->denymode==DenyMode)  && (Child->rw==RW) && (Child->oplock==Oplock) && (Child->dateopen==DateOpen) )
100
 
                {
101
 
                        exist=true;
102
 
                        // Mark this object
103
 
                        Child->mark=true;
104
 
                        return true;  // exit loop
105
 
                }
106
 
        }
107
 
        // if not exist add it
108
 
        if (!exist) new service (this,PID,File,DenyMode,RW,Oplock,DateOpen);
109
 
        return false;
110
 
}
111
 
 
112
 
/**
113
 
        Refresh view. Delete obsolete objects (mark = false).
114
 
        \sa mark_childs
115
 
*/
116
 
void user::refresh_childs()
117
 
{
118
 
        for (int i=0;  i < this->childCount (); ++i )
119
 
        {
120
 
                service * Child= dynamic_cast<service *>(this->child (i) );
121
 
                if (!Child) break;
122
 
                // if child doesn't exist any more
123
 
                if (!Child->mark)
124
 
                {
125
 
                        delete Child;  // delete item and his children
126
 
                        --i;
127
 
                        continue;
128
 
                }
129
 
        }
130
 
}
131
 
 
132
 
 
133
 
/**
134
 
        Mark all children.
135
 
        - mark = true -> exist
136
 
        - mark = false -> obsolete
137
 
        \sa refresh_childs
138
 
 */
139
 
void user::mark_childs()
140
 
{
141
 
        for (int i=0;  i < this->childCount (); ++i )
142
 
        {
143
 
                service * Child= dynamic_cast<service *>(this->child (i) );
144
 
                if (!Child) break;
145
 
                Child->mark=false;
146
 
        }
147
 
}