2008-05-05 07:46:19 +00:00
//
// C++ Implementation: mycardspixmaplabel
//
// Description:
//
//
// Author: FThauer FHammer <f.thauer@web.de>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
2009-04-22 22:32:45 +00:00
#include "myavatarlabel.h"
2008-05-05 07:46:19 +00:00
#include "gametableimpl.h"
2008-10-17 19:39:27 +00:00
#include "session.h"
#include "playerinterface.h"
#include "game.h"
2010-03-31 20:12:44 +00:00
#include "mymessagedialogimpl.h"
#include "chattools.h"
2008-05-05 07:46:19 +00:00
using namespace std ;
MyAvatarLabel :: MyAvatarLabel ( QGroupBox * parent )
2010-03-31 20:12:44 +00:00
: QLabel ( parent ), voteRunning ( FALSE ), transparent ( FALSE )
2008-05-05 07:46:19 +00:00
{
2010-03-31 20:12:44 +00:00
myContextMenu = new QMenu ;
action_VoteForKick = new QAction ( QIcon ( ":/gfx/list_remove_user.png" ), tr ( "Start vote to kick this player" ), myContextMenu );
myContextMenu -> addAction ( action_VoteForKick );
action_IgnorePlayer = new QAction ( QIcon ( ":/gfx/im-ban-user.png" ), tr ( "Ignore Player" ), myContextMenu );
myContextMenu -> addAction ( action_IgnorePlayer );
2011-01-03 21:55:35 +00:00
action_ReportBadAvatar = new QAction ( QIcon ( ":/gfx/emblem-important.png" ), tr ( "Report inappropriate avatar" ), myContextMenu );
2010-12-11 00:58:40 +00:00
myContextMenu -> addAction ( action_ReportBadAvatar );
2008-05-05 07:46:19 +00:00
2010-03-31 20:12:44 +00:00
connect ( action_VoteForKick , SIGNAL ( triggered () ), this , SLOT ( sendTriggerVoteOnKickSignal () ) );
connect ( action_IgnorePlayer , SIGNAL ( triggered () ), this , SLOT ( putPlayerOnIgnoreList () ) );
2010-12-11 00:58:40 +00:00
connect ( action_ReportBadAvatar , SIGNAL ( triggered () ), this , SLOT ( reportBadAvatar () ) );
2008-05-05 07:46:19 +00:00
}
MyAvatarLabel ::~ MyAvatarLabel ()
{
}
2008-09-23 08:15:33 +00:00
void MyAvatarLabel :: contextMenuEvent ( QContextMenuEvent * event ) {
2008-05-05 07:46:19 +00:00
2010-03-31 20:12:44 +00:00
assert ( myW -> getSession () -> getCurrentGame ());
2011-01-03 21:26:49 +00:00
if ( myW -> getSession () -> isNetworkClientRunning ()) {
2008-12-07 21:47:53 +00:00
2010-03-31 20:12:44 +00:00
PlayerListIterator it = myW -> getSession () -> getCurrentGame () -> getSeatsList () -> begin ();
//only active players are allowed to start a vote
if (( * it ) -> getMyActiveStatus ()) {
2008-10-17 19:39:27 +00:00
2011-01-03 21:55:35 +00:00
// if(myW->getGuestMode()) {
2011-01-03 21:26:49 +00:00
//excpetions for client is logged in as guest
2009-04-22 22:32:45 +00:00
2011-01-03 21:55:35 +00:00
//TODO diese RIESENSAUEREI aufräumen!!!
2010-08-07 21:48:19 +00:00
2011-01-03 21:55:35 +00:00
// Game *currentGame = myW->getSession()->getCurrentGame();
// PlayerListConstIterator it_c;
// int activePlayerCounter=0;
2009-04-22 22:32:45 +00:00
2011-01-03 21:55:35 +00:00
// setVoteOnKickContextMenuEnabled(FALSE);
// action_IgnorePlayer->setEnabled(FALSE);
2010-03-31 20:12:44 +00:00
2011-01-03 21:55:35 +00:00
// if(myW->getSession()->getGameType() == Session::GAME_TYPE_INTERNET) {
// action_ReportBadAvatar->setVisible(TRUE);
// }
// else {
// action_ReportBadAvatar->setVisible(FALSE);
// }
2010-03-31 20:12:44 +00:00
2011-01-03 21:55:35 +00:00
// int i=0;
// for (it_c=currentGame->getSeatsList()->begin(); it_c!=currentGame->getSeatsList()->end(); it_c++) {
2010-03-31 20:12:44 +00:00
2011-01-03 21:55:35 +00:00
// //also inactive player which stays on table can be voted to kick
// if(myContextMenuEnabled && myId != 0 && myId == i && (*it_c)->getMyType() != PLAYER_TYPE_COMPUTER && ( (*it_c)->getMyActiveStatus() || (*it_c)->getMyStayOnTableStatus() ) && !(QString::fromUtf8((*it_c)->getMyAvatar().c_str()).isEmpty()) )
// showContextMenu(event->globalPos());
// i++;
// }
// }
// else {
2011-01-03 21:26:49 +00:00
//normal player mode in internet game
2010-12-24 16:51:46 +00:00
2011-01-03 21:55:35 +00:00
Game * currentGame = myW -> getSession () -> getCurrentGame ();
PlayerListConstIterator it_c ;
int activePlayerCounter = 0 ;
2011-01-03 21:26:49 +00:00
2011-01-03 21:55:35 +00:00
for ( it_c = currentGame -> getSeatsList () -> begin (); it_c != currentGame -> getSeatsList () -> end (); it_c ++ ) {
if (( * it_c ) -> getMyActiveStatus ()) activePlayerCounter ++ ;
2011-01-03 21:26:49 +00:00
}
2011-01-03 21:55:35 +00:00
GameInfo info ( myW -> getSession () -> getClientGameInfo ( myW -> getSession () -> getClientCurrentGameId ()));
if ( activePlayerCounter > 2 && ! voteRunning && info . data . gameType != GAME_TYPE_RANKING && ! myW -> getGuestMode ()) {
setVoteOnKickContextMenuEnabled ( TRUE );
}
else {
setVoteOnKickContextMenuEnabled ( FALSE );
}
action_IgnorePlayer -> setEnabled ( true );
int j = 0 ;
for ( it_c = currentGame -> getSeatsList () -> begin (); it_c != currentGame -> getSeatsList () -> end (); it_c ++ ) {
if ( myId == j && myW -> getSession () -> getClientPlayerInfo (( * it_c ) -> getMyUniqueID ()). isGuest ) {
action_IgnorePlayer -> setDisabled ( true );
}
j ++ ;
}
2011-01-03 22:00:37 +00:00
if ( myW -> getSession () -> getGameType () == Session :: GAME_TYPE_INTERNET && ! ( QString :: fromUtf8 (( * it_c ) -> getMyAvatar (). c_str ()). isEmpty ()) ) {
2011-01-03 21:55:35 +00:00
action_ReportBadAvatar -> setVisible ( TRUE );
}
else {
action_ReportBadAvatar -> setVisible ( FALSE );
}
int i = 0 ;
for ( it_c = currentGame -> getSeatsList () -> begin (); it_c != currentGame -> getSeatsList () -> end (); it_c ++ ) {
//also inactive player which stays on table can be voted to kick
2011-01-03 22:00:37 +00:00
if ( myContextMenuEnabled && myId != 0 && myId == i && ( * it_c ) -> getMyType () != PLAYER_TYPE_COMPUTER && ( ( * it_c ) -> getMyActiveStatus () || ( * it_c ) -> getMyStayOnTableStatus () ) )
2011-01-03 21:55:35 +00:00
showContextMenu ( event -> globalPos ());
i ++ ;
}
2009-04-22 22:32:45 +00:00
}
2010-03-31 20:12:44 +00:00
}
2008-05-05 07:46:19 +00:00
}
2008-09-23 08:15:33 +00:00
void MyAvatarLabel :: showContextMenu ( const QPoint & pos ) {
2008-05-05 07:46:19 +00:00
2010-03-31 20:12:44 +00:00
myContextMenu -> popup ( pos );
2008-09-23 08:15:33 +00:00
}
2008-10-12 19:36:46 +00:00
void MyAvatarLabel :: sendTriggerVoteOnKickSignal ()
2008-09-23 08:15:33 +00:00
{
2010-03-31 20:12:44 +00:00
myW -> triggerVoteOnKick ( myId );
2008-10-12 19:36:46 +00:00
}
void MyAvatarLabel :: setEnabledContextMenu ( bool b )
{
2010-03-31 20:12:44 +00:00
myContextMenuEnabled = b ;
2008-05-05 07:46:19 +00:00
}
2008-11-17 16:02:11 +00:00
void MyAvatarLabel :: setVoteOnKickContextMenuEnabled ( bool b )
{
2010-03-31 20:12:44 +00:00
action_VoteForKick -> setEnabled ( b );
2009-04-22 22:32:45 +00:00
}
void MyAvatarLabel :: setPixmap ( const QPixmap & pix , const bool trans ) {
2010-03-31 20:12:44 +00:00
myPixmap = pix . scaled ( 50 , 50 , Qt :: IgnoreAspectRatio , Qt :: SmoothTransformation );
transparent = trans ;
update ();
2009-04-22 22:32:45 +00:00
}
2010-10-26 17:31:41 +00:00
void MyAvatarLabel :: setPixmapAndCountry ( const QPixmap & pix , QString countryString , int seatPlace , const bool trans ) {
QPixmap resultAvatar ( pix . scaled ( 50 , 50 , Qt :: IgnoreAspectRatio , Qt :: SmoothTransformation ));
QPainter painter ( & resultAvatar );
int showCountryFlags = myW -> getMyConfig () -> readConfigInt ( "ShowCountryFlagInAvatar" );
if ( showCountryFlags && ! countryString . isEmpty ())
{
2010-12-11 00:58:40 +00:00
if ( seatPlace <= 2 || seatPlace >= 8 )
2010-10-26 17:31:41 +00:00
{
2010-12-11 00:58:40 +00:00
painter . drawPixmap ( resultAvatar . width () - ( QPixmap ( countryString )). width (), resultAvatar . height () - ( QPixmap ( countryString )). height (), QPixmap ( countryString ));
2010-10-26 17:31:41 +00:00
}
else
{
2010-12-11 00:58:40 +00:00
painter . drawPixmap ( resultAvatar . width () - ( QPixmap ( countryString )). width (), 0 , QPixmap ( countryString ));
2010-10-26 17:31:41 +00:00
}
}
painter . end ();
myPixmap = resultAvatar ;
transparent = trans ;
update ();
}
2009-04-22 22:32:45 +00:00
void MyAvatarLabel :: paintEvent ( QPaintEvent * ) {
2010-03-31 20:12:44 +00:00
QPainter painter ( this );
if ( transparent )
painter . setOpacity ( 0.4 );
else
painter . setOpacity ( 1.0 );
2009-04-22 22:32:45 +00:00
2010-03-31 20:12:44 +00:00
painter . drawPixmap ( 0 , 0 , myPixmap );
2009-04-22 22:32:45 +00:00
}
2010-03-31 20:12:44 +00:00
bool MyAvatarLabel :: playerIsOnIgnoreList ( QString playerName ) {
list < std :: string > playerIgnoreList = myW -> getMyConfig () -> readConfigStringList ( "PlayerIgnoreList" );
list < std :: string >:: iterator it1 ;
for ( it1 = playerIgnoreList . begin (); it1 != playerIgnoreList . end (); it1 ++ ) {
if ( playerName == QString :: fromUtf8 ( it1 -> c_str ())) {
return true ;
}
}
return false ;
}
void MyAvatarLabel :: putPlayerOnIgnoreList () {
QStringList list ;
PlayerListConstIterator it_c ;
for ( it_c = myW -> getSession () -> getCurrentGame () -> getSeatsList () -> begin (); it_c != myW -> getSession () -> getCurrentGame () -> getSeatsList () -> end (); it_c ++ ) {
list << QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ());
}
if ( ! playerIsOnIgnoreList ( list . at ( myId ))) {
myMessageDialogImpl dialog ( myW -> getMyConfig (), this );
2010-07-27 08:30:55 +00:00
if ( dialog . exec ( 4 , tr ( "You will no longer receive chat messages or game invitations from this user.<br>Do you really want to put player <b>%1</b> on ignore list?" ). arg ( list . at ( myId )), tr ( "PokerTH - Question" ), QPixmap ( ":/gfx/im-ban-user_64.png" ), QDialogButtonBox :: Yes | QDialogButtonBox :: No , false ) == QDialog :: Accepted ) {
2010-03-31 20:12:44 +00:00
std :: list < std :: string > playerIgnoreList = myW -> getMyConfig () -> readConfigStringList ( "PlayerIgnoreList" );
playerIgnoreList . push_back ( list . at ( myId ). toUtf8 (). constData ());
myW -> getMyConfig () -> writeConfigStringList ( "PlayerIgnoreList" , playerIgnoreList );
myW -> getMyConfig () -> writeBuffer ();
myW -> getMyChat () -> refreshIgnoreList ();
}
}
}
2010-12-11 00:58:40 +00:00
void MyAvatarLabel :: reportBadAvatar () {
Game * currentGame = myW -> getSession () -> getCurrentGame ();
int j = 0 ;
PlayerListConstIterator it_c ;
for ( it_c = currentGame -> getSeatsList () -> begin (); it_c != currentGame -> getSeatsList () -> end (); it_c ++ ) {
if ( myId == j ) {
QString avatar = QString :: fromUtf8 (( * it_c ) -> getMyAvatar (). c_str ());
if ( ! avatar . isEmpty ()) {
QString nick = QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ());
int ret = QMessageBox :: question ( this , tr ( "PokerTH - Question" ),
tr ( "Are you sure you want to report the avatar of \" %1 \" as inappropriate?" ). arg ( nick ),
QMessageBox :: Yes | QMessageBox :: No );
2010-12-14 21:14:49 +00:00
if ( ret ) {
QFileInfo fi ( avatar );
2010-12-24 16:51:46 +00:00
myW -> getSession () -> reportBadAvatar (( * it_c ) -> getMyUniqueID (), fi . baseName (). toStdString ());
2010-12-14 21:14:49 +00:00
}
2010-12-11 00:58:40 +00:00
}
break ;
}
j ++ ;
}
}