#ifndef _USER_H_ #define _USER_H_ #include #include "util.h" class User : public QListViewItem { public: /*! Sets name to nick and calls QListViewItem with all parameters \param parent QLisstView this item shoulf be displayed in \param nick Nickname of the user \param share The filesize of the users shared files \param con The connection type os the user \param enail The users email \param desc The users desription \param a If the user is away */ User( QListView* parent, QString nick, QString share="n/a", QString con="n/a", QString email="n/a",QString desc="n/a",bool a=false ) : QListViewItem( parent, nick, share, con, desc, email ), name(nick) , away(a) { client = "Unknown client"; v = 0; m = '?'; nslots = -1; numhubs = -1; dlimit = -1; op = false; } /* /// custom width for user mode icon column virtual int width( const QFontMetrics & fm, const QListView * lv, int c ) const { if (c!=0) return QListViewItem::width(fm, lv, c); else return 16; } */ /// custom paint cell for user mode icon column virtual void paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align ); /// Sets the cliet void setClient(const QString& c) { client=c; } /*! Returns the users nick name */ QString getName() { return name; } /*! Checks if the user u has the same nick as this user \param u */ bool operator==( User u ) { return u.getName()==name; } virtual int compare( QListViewItem * i, int col, bool ascending ) const { if(col == 0) // nickname column { if (op == ((User *)i)->isOp()) // if both are ops or both are not ops return QListViewItem::compare(i,col,ascending); else // only one of the users is op return (op ? -1 : 1); } else if(col == 1) // share column { if( text(col)=="n/a" ) return -1; // n/a items always less if( i->text(col)=="n/a") return 1; if( share < ((User*)i)->getShare()) return -1; else return 1; return 0; } else return QListViewItem::compare(i,col,ascending); } void setTagInfo(float av,char mode,int aslots,int anumhubs,int adlimit) { v = av; m = mode; nslots = aslots; numhubs = anumhubs; dlimit = adlimit; } const QString getClient() { if(v!=0) return client + " " + QString::number(v); else return client; } const QString getAway() { if(away) return QString("(away)"); else return QString::null; } const QString getMode() { if(m=='P') return QString("Mode: Passive"); if(m=='A') return QString("Mode: Active"); if(m=='5') return QString("Mode: Socks5"); return QString("Mode: n/a"); } const QString getNSlots() { if(nslots==-1) return QString("Slots: n/a"); return QString("Slots: ") + QString::number(nslots); } const QString getNHubs() { if(numhubs==-1) return QString::null; return QString("Connected to ") + QString::number(numhubs) + " hubs"; } const QString getDLimit() { if(dlimit==-1) return QString("Download limit: n/a"); return QString("Download limit: ") + QString::number(dlimit); } void setIsOp(bool yes) {op = yes;} bool isOp() {return op;} void setShare(double s) {share = s;} double getShare() {return share;} private: /*! This users nick name */ QString name; /// What client the user is using QString client; /*! If the user is away */ bool away; float v; char m; int nslots; int numhubs; int dlimit; bool op; double share; QString tag; }; #endif /* * * $Log: user.h,v $ * Revision 1.8 2004/05/26 16:00:23 estrato * Sorting userlist with ops first * * Revision 1.6 2004/05/19 14:54:06 olof * Fixed userlist share sorting * * Revision 1.5 2004/05/17 14:21:30 olof * Fixed the double op bug * * Revision 1.4 2004/02/23 20:37:09 olof * Userinfo popup * * Revision 1.3 2004/01/26 22:46:13 olof * kossa mu * * Revision 1.2 2004/01/09 22:02:54 olof * Fixed used description bug and added support for description tags. * There is still some work to be done though. * * Revision 1.1.1.1 2003/06/24 10:16:18 olof * remake of cvs tree * * Revision 1.3 2003/06/06 11:34:11 olof * mu * * Revision 1.2 2003/03/13 14:31:29 olof * userlist grejs * * Revision 1.1 2003/03/04 22:10:42 olof * dcqt2 creation * * Revision 1.3 2003/02/18 15:48:11 migr8915 * Dont know what ive done * * */