/* Copyright 2003 Rikard Björklind, Mikael Gransell This file is part of dc-qt. dc-qt 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. dc-qt 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 dc-qt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "userlist.h" #include "user.h" #include "debugdlg.h" #include "util.h" #include "dc_settings.h" #include "mainwdgt.h" #include "chatedit.h" #include #include #include #include #include #include #include using namespace std; // Userlist constructor. // chated - pointer to the chat-edit instance UserList::UserList( QWidget* parent, const char* name, ChatEdit *ced ) : QListView( parent, name ), chated(ced) { uInfosRequested = false; addColumn( "Nick" ); addColumn( "Share" ); addColumn( "Con" ); addColumn( "Description" ); addColumn( "Email"); setShowSortIndicator(true); useTimer = false; timer = new QTimer(this); //connect(timer,SIGNAL(timeout()),this,SLOT(getUinfos())); menu = new QPopupMenu(this, "user_lv_menu"); menu->insertItem( "Get File List", this, SLOT(getUserFiles()) ); menu->insertItem( "Send Message", this, SLOT(dispChatDlg()) ); menu->insertItem("Info",this,SLOT(popupInfo())); connect( this, SIGNAL(rightButtonClicked(QListViewItem *, const QPoint &, int)), this, SLOT(dispMenu(QListViewItem *, const QPoint &, int)) ); //connect( this, SIGNAL(onItem ( QListViewItem *)),this,SLOT(enterItem(QListViewItem* ))); connect( this, SIGNAL(doubleClicked(QListViewItem* )),SLOT(dispChatDlg())); infodlg = new QDialog(this,"infodlg",true); QGridLayout *gl = new QGridLayout(infodlg,1,1); userToolTip = new QLabel(infodlg,"infolbl"); gl->addWidget(userToolTip,0,0); /*userToolTip = new QLabel(0,0,Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_StaysOnTop); userToolTip->move(0,0); userToolTip->setFrameStyle( QFrame::NoFrame ); userToolTip->setAlignment(Qt::AlignTop | Qt::AlignLeft); userToolTip->setFrameStyle(QFrame::Plain | QFrame::Box); */ //toolTipTimer = new QTimer(this); //connect(toolTipTimer,SIGNAL(timeout()),SLOT(popupInfo())); lastUser = 0; } void UserList::popupInfo() { QString s = "

" + lastUser->getName() + lastUser->getAway() + "

" + lastUser->getClient() + "
" + lastUser->getMode() + "
" + lastUser->getNSlots() + "
"+lastUser->getNHubs() + "
" + lastUser->getDLimit() + "
"; userToolTip->setText(s); infodlg->exec(); } void UserList::enterItem(QListViewItem *i) { // Hide the tooltip if showing userToolTip->hide(); // (re)start the timer for the given item. toolTipTimer->start(1000,true); lastUser = (User*)i; } /*void UserList::leaveEvent( QEvent *e ) { toolTipTimer->stop(); userToolTip->hide(); }*/ void UserList::getUinfos() { if(uInfosRequested==false) { QListViewItem *i = firstChild(); while(i) { if(i->text(0)!=settings.get_setting("nick")) emit getUserInfo( i->text(0) ); i = i->nextSibling(); } uInfosRequested = true; } } void UserList::addUser( const QString& name, const QString& share, const QString& con, const QString& email, const QString& desc,bool away ) { // Parse the description and remove all tags. Save the information from // the tags (to be used in the future). QString tags = desc.section("<",1); QString desc2 = desc.section("<",0,0); QString client = QString::null; float version =0; QChar mode = '?'; int nslots = -1; int numHubs = -1; int dLimit = -1; while( tags!=QString::null ) { if(tags.startsWith("++")) {client="DC++";} else if(tags.startsWith("DCGUI")) {client = "DCGUI";} else if(tags.startsWith("DCTC")) {client = "DCTC";} else if(tags.startsWith("oDC")) {client = "oDC";} else if(tags.startsWith("DC")) {client = "DC";} tags=tags.section(' ',1); tags.truncate(tags.length()-1); // remove trailing > QStringList l = QStringList::split(',',tags); for(unsigned int i=0;isetShare(sh); if(client!=QString::null) u->setClient(client); u->setTagInfo(version,mode,nslots,numHubs,dLimit); // add this user's nick as possible completion for chatedit if (chated!=NULL) chated->addCompletion( name ); } else { bool ok; double sh = share.toDouble(&ok); if(ok) user->setShare(sh); user->setText(1,bytes_to_units(share)); user->setText(2,con); user->setText(3,desc2); user->setText(4,email); if(client!=QString::null) user->setClient(client); user->setTagInfo(version,mode,nslots,numHubs,dLimit); } } void UserList::addUser( const QString& name, bool usercmd ) { QListViewItem* user = findItem(name,0); if(!user) { new User( this, name ); if (chated!=NULL) chated->addCompletion( name ); } if(usercmd && useTimer) { timer->start(1000,true); } } void UserList::addUsers(const QStringList& users) { QString self = settings.get_setting("nick"); for ( QStringList::ConstIterator it = users.begin(); it != users.end(); ++it ) { if(*it!=self) { new User(this,*it); if (chated!=NULL) chated->addCompletion( *it ); } } } void UserList::removeUser( const QString& name ) { QListViewItem* user = findItem( name, 0 ); if(user) delete user; if (chated!=NULL) chated->removeCompletion( name ); } void UserList::dispMenu( QListViewItem* item, const QPoint& p, int column ) { if( !item ) // We didn't click an item but somewhere else in the list return; // Popup the menu lastUser = (User*)item; menu->popup( p ); } void UserList::getUserFiles() { QListViewItem* item = currentItem(); if( !item ) // No highlighted item return; QString nick = item->text( 0 ); // Get the nick of this user emit getUserFiles( nick ); } void UserList::dispChatDlg() { QListViewItem* item = currentItem(); if( !item ) // No highlighted item return; emit activateChat( item->text(0) ); } void UserList::setOp(const QString& user) { User* u = (User*)findItem( user, 0 ); if(u) u->setIsOp(true); } /* * * $Log: userlist.cc,v $ * Revision 1.13 2004/06/01 11:39:47 olof * small fixes * * Revision 1.12 2004/05/28 13:39:12 estrato * Tab completion of nicks in public chat * * Revision 1.11 2004/05/25 23:48:02 olof * connected the op signal * * Revision 1.10 2004/05/19 14:54:06 olof * Fixed userlist share sorting * * Revision 1.9 2004/02/29 22:40:25 olof * dslkjfhsldhl * not working * * Revision 1.8 2004/02/25 00:13:41 olof * fisbuggen nr 1 * * Revision 1.6 2004/02/23 20:37:09 olof * Userinfo popup * * Revision 1.5 2004/01/26 22:46:13 olof * kossa mu * * Revision 1.4 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.3 2003/12/21 01:46:51 olof * connect to running works except file transfers * * Revision 1.1.1.1 2003/06/24 10:16:18 olof * remake of cvs tree * * Revision 1.7 2003/06/06 11:34:11 olof * mu * * Revision 1.6 2003/05/12 22:28:02 olof * shit * * Revision 1.5 2003/05/08 12:34:14 olof * GPL header added * * Revision 1.4 2003/03/17 17:31:46 olof * file transfer fixes * * Revision 1.3 2003/03/15 00:53:00 olof * lots of updates * * Revision 1.2 2003/03/13 14:31:29 olof * userlist grejs * * Revision 1.1 2003/03/04 22:10:43 olof * dcqt2 creation * * Revision 1.3 2003/02/23 16:54:49 ribj4077 * Added some features * * Revision 1.2 2003/02/18 15:48:11 migr8915 * Dont know what ive done * * */