File: session.cpp

package info (click to toggle)
dc-qt 0.2.0.alpha-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,936 kB
  • ctags: 5,361
  • sloc: cpp: 28,936; makefile: 19
file content (117 lines) | stat: -rw-r--r-- 2,569 bytes parent folder | download | duplicates (4)
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
//
// C++ Implementation: session
//
// Description: 
//
//
// Author: Rikard Bjorklind <olof@users.sourceforge.net>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "session.h"
#include "userlistmodel.h"
#include <QtGui>
#include <QMenu>

Session::Session(int aId,
				 QWidget *parent)
: QWidget(parent),
  contextMenu(new QMenu(this)), 
  myId(aId)
{
	ui.setupUi(this);
	userModel = new UserListModel;
	ui.userView->setModel(userModel);

	ui.userView->header()->setClickable(true);
    ui.userView->header()->setSortIndicatorShown(true);
	
	createMenu();
}


Session::~Session()
{
	delete userModel;
}

void Session::onFailed( const QString &reason )
{
	ui.mainChat->append(reason);
}

void Session::onPrivateChatMessage( const QString & /*from*/, const QString & msg )
{
	ui.mainChat->append(QString(tr("Private Message: ")) + msg);
}

void Session::onUsersUpdated( QList<User*> users )
{
	userModel->enableUpdateSignals( false );
	for(int i=0;i < users.size();i++)
		userModel->setUser( users[i] );	
	userModel->enableUpdateSignals( true );
	userModel->signalLayoutChanged();
}

void Session::onUserRemoved( int id )
{
	userModel->removeUser(id);
}

void Session::onChatMessage( const QString &msg )
{
	ui.mainChat->append(msg);
}

void Session::onHubStats( qint64 totshared )
{
	shared = totshared;
}

void Session::onGetFileList()
{
	QModelIndexList selected = ui.userView->selectionModel()->selectedIndexes();
	// We should only have one selected item
	getFileList(selected.front());
}

void Session::on_chatEdit_returnPressed( )
{
	if( ui.chatEdit->text().length() > 0 )
		emit sendChat(myId,ui.chatEdit->text());
	ui.chatEdit->clear();
}

void Session::on_userView_doubleClicked( const QModelIndex& index )
{
	getFileList( index );
}

void Session::on_userView_customContextMenuRequested( const QPoint& pos )
{
	// Show the menu
	contextMenu->popup( ui.userView->mapToGlobal(pos) );
}

void Session::createMenu()
{	
	QAction* getFileListAct = contextMenu->addAction( tr("Get file list") );
	connect( getFileListAct, SIGNAL(triggered()), this, SLOT(onGetFileList()) );
	
	QAction* sendMsgAct = contextMenu->addAction( tr("Open private chat") );
	connect( sendMsgAct, SIGNAL(triggered()), this, SLOT(onOpenChat()) );
	
	QAction* addFavUserAct = contextMenu->addAction( tr("Add to favourites") );
	connect( addFavUserAct, SIGNAL(triggered()), this, SLOT( onAddFav() ) );
}


void Session::getFileList( const QModelIndex& index )
{
	if( index.isValid() ) {
		emit getUserFileList(userModel->getUser(index)->id);
	}	
}