2
* tables.cpp = part of mainwindow
8
#include "playertable.h"
9
#include "gamestable.h"
10
#include "gs_globals.h"
11
#include <qlineedit.h>
12
//#include <qmultilineedit.h>
13
//#include <qtextedit.h>
14
#include <qtextbrowser.h>
22
// prepare tables (clear, ...)
23
void ClientWindow::prepare_tables(InfoType cmd)
27
case WHO: // delete player table
29
QListViewItemIterator lv(ListView_players);
30
for (QListViewItem *lvi; (lvi = lv.current());)
36
// set number of players to 0
37
myAccount->num_players = 0;
38
myAccount->num_watchedplayers = 0;
39
// use this for fast filling
40
playerListEmpty = true;
41
statusUsers->setText(" P: 0 / 0 ");
45
case GAMES: // delete games table
47
QListViewItemIterator lv(ListView_games);
48
for (QListViewItem *lvi; (lvi = lv.current());)
54
// set number of games to 0
55
myAccount->num_games = 0;
56
statusGames->setText(" G: 0 / 0 ");
62
// delete channel info
64
statusChannel->setText("");
65
/* QListViewItemIterator lv(ListView_ch);
66
for (QListViewItem *lvi; (lvi = lv.current());)
71
// delete tooltips too
72
QToolTip::remove(statusChannel);
73
QToolTip::add(statusChannel, tr("Current channels and users"));
77
default: // unknown command???
78
qWarning("unknown Command in 'prepare_tables()'");
84
// return the rank of a given name
85
QString ClientWindow::getPlayerRk(QString player)
87
QListViewItemIterator lvp(ListView_players);
90
// look for players in playerlist
91
for (; (lvpi = lvp.current()); lvp++)
93
// check if names are identical
94
if (lvpi->text(1) == player)
103
// check for exclude list entry of a given name
104
QString ClientWindow::getPlayerExcludeListEntry(QString player)
106
QListViewItemIterator lvp(ListView_players);
110
qDebug(QString("getPlayerExcludeListEntry(%1)").arg(player));
112
// look for players in playerlist
113
for (; (lvpi = lvp.current()); lvp++)
115
// check if names are identical
116
if (lvpi->text(1) == player)
119
qDebug(QString("text(1) = %1, player = %2").arg(lvpi->text(1)).arg(player));
121
return lvpi->text(6);
128
// take a new game from parser
129
void ClientWindow::slot_game(Game* g)
131
// insert into ListView
132
QListViewItemIterator lv(ListView_games);
137
GamesTableItem *lvi_mem = NULL;
139
// check if game already exists
140
if (!playerListEmpty)
142
QListViewItemIterator lvii = lv;
143
for (GamesTableItem *lvi; (lvi = static_cast<GamesTableItem*>(lvii.current())) && !found;)
147
if (lvi->text(0) == g->nr)
154
else if (!g->H && !myAccount->num_games)
156
// skip games until initial table has loaded
157
qDebug("game skipped because no init table");
161
QString excludeMark = "";
162
QString myMark = "B";
164
// check if exclude entry is done later
165
if (g->H) //g->status.length() > 1)
171
emw = getPlayerExcludeListEntry(g->wname);
172
emb = getPlayerExcludeListEntry(g->bname);
174
// ensure that my game is listed first
175
if (emw && emw == "M" || emb && emb == "M")
180
// I'm playing, thus I'm open, except teaching games
181
if (emw && emw && (emw != "M" || emb != "M"))
184
slot_checkbox(0, true);
187
else if (emw && emw == "W" || emb && emb == "W")
196
//lvi_mem->setText(0, g->nr);
197
lvi_mem->setText(1, g->wname);
198
lvi_mem->setText(2, g->wrank);
199
lvi_mem->setText(3, g->bname);
200
lvi_mem->setText(4, g->brank);
201
lvi_mem->setText(5, g->mv);
202
lvi_mem->setText(6, g->Sz);
203
lvi_mem->setText(7, g->H);
204
lvi_mem->setText(8, g->K);
205
lvi_mem->setText(9, g->By);
206
lvi_mem->setText(10, g->FR);
207
lvi_mem->setText(11, g->ob);
208
// lvi_mem->setText(6, g->status + " (" + g->ob + ")");
209
lvi_mem->setText(12, myMark + rkToKey(g->wrank) + g->wname.lower() + ":" + excludeMark);
211
lvi_mem->ownRepaint();
215
// from GAMES command or game info{...}
219
lv = new GamesTableItem(ListView_games,
235
lv = new GamesTableItem(ListView_games,
245
lv.current()->setText(12, myMark + rkToKey(g->wrank) + g->wname.lower() + ":" + excludeMark);
247
static_cast<GamesTableItem*>(lv.current())->ownRepaint();
249
// increase number of games
250
myAccount->num_games++;
251
statusGames->setText(" G: " + QString::number(myAccount->num_games) + " / " + QString::number(myAccount->num_observedgames) + " ");
254
// update player info if this is not a 'who'-result or if it's me
255
if (!g->H || myMark == "A") //g->status.length() < 2)
257
QListViewItemIterator lvp(ListView_players);
261
// look for players in playerlist
262
for (; (lvpi = lvp.current()) && found < 2;)
264
// check if names are identical
265
if (lvpi->text(1) == g->wname || lvpi->text(1) == g->bname)
267
lvpi->setText(3, g->nr);
270
// check if players has a rank
271
if (g->wrank == "??" || g->brank == "??")
273
// no rank given in case of continued game -> set rank in games table
274
if (lvpi->text(1) == g->wname)
276
lv.current()->setText(2, lvpi->text(2));
277
// correct sorting of col 2 -> set col 12
278
lv.current()->setText(12, myMark + rkToKey(lvpi->text(2)) + lvpi->text(1).lower() + ":" + excludeMark);
281
// no else case! bplayer could be identical to wplayer!
282
if (lvpi->text(1) == g->bname)
283
lv.current()->setText(4, lvpi->text(2));
285
static_cast<GamesTableItem*>(lv.current())->ownRepaint();
292
ListView_games->sort();
297
// from game info {...}
303
for (QListViewItem *lvi; (lvi = lv.current()) && !found;)
307
if (lvi->text(0) == g->nr)
315
// used for player update below
320
for (QListViewItem *lvi; (lvi = lv.current()) && !found;)
324
if (lvi->text(1) == myAccount->acc_name ||
325
lvi->text(3) == myAccount->acc_name)
327
// used for player update below
328
game_id = lvi->text(0);
338
qWarning("game not found");
341
// decrease number of games
342
myAccount->num_games--;
343
statusGames->setText(" G: " + QString::number(myAccount->num_games) + " / " + QString::number(myAccount->num_observedgames) + " ");
345
QListViewItemIterator lvp(ListView_players);
349
// look for players in playerlist
350
for (; (lvpi = lvp.current()) && found < 2;)
352
// check if numbers are identical
353
if (lvpi->text(3) == game_id)
355
lvpi->setText(3, "-");
365
// take a new player from parser
366
void ClientWindow::slot_player(Player *p, bool cmdplayers)
368
// insert into ListView
370
QListViewItemIterator lv(ListView_players);
373
QListViewItem *topViewItem = ListView_players->itemAt(pp);
374
bool deleted_topViewItem = false;
378
// check if it's an empty list, i.e. all items deleted before
379
if (cmdplayers && !playerListEmpty)
381
for (PlayerTableItem *lvi; (lvi = static_cast<PlayerTableItem*>(lv.current()));)
385
if (lvi->text(1) == p->name)
387
// check if new player info is less than old
390
// new entry has more info
391
lvi->setText(0, p->info);
393
lvi->setText(2, p->rank);
394
lvi->setText(3, p->play_str);
395
lvi->setText(4, p->obs_str);
396
lvi->setText(5, p->idle);
398
lvi->setText(12, rkToKey(p->rank) + p->name.lower());
400
if (extUserInfo && myAccount->get_gsname() == IGS)
402
lvi->setText(7, p->extInfo);
403
lvi->setText(8, p->won);
404
lvi->setText(9, p->lost);
405
lvi->setText(10, p->country);
406
lvi->setText(11, p->language);
412
if (p->name == myAccount->acc_name)
414
qDebug("updating my account info... (1)");
416
bool b = (p->info.contains('X') == 0);
418
// checkbox looking - don't set if closed
419
if (p->info.contains('!') != 0)
421
slot_checkbox(1, true);
423
// "!" not found && open
424
slot_checkbox(1, false);
426
// NOT CORRECT REPORTED BY SERVER!
427
//b = (p->info.contains('Q') != 0);
428
//slot_checkbox(2, b);
430
if (p->info.contains('Q') != 0)
431
slot_checkbox(2, true);
433
// get rank to calc handicap when matching
434
myAccount->set_rank(p->rank);
441
else if (!cmdplayers && !myAccount->num_players)
443
qDebug("player skipped because no init table");
444
// skip players until initial table has loaded
451
// check for watched players
452
if (watch && watch.contains(";" + p->name + ";"))
456
// sound for entering - no sound while "who" cmd is executing
458
qgoif->get_qgo()->playEnterSound();
459
else if (p->name == myAccount->acc_name)
461
// - only possible if 'who'/'user' cmd is executing
462
// - I am on the watchlist, however
464
myAccount->num_watchedplayers--;
466
myAccount->num_watchedplayers++;
468
// check for excluded players
469
else if (exclude && exclude.contains(";" + p->name + ";"))
474
// check for open/looking state
477
if (p->name == myAccount->acc_name)
479
qDebug("updating my account info...(2)");
481
bool b = (p->info.contains('X') == 0);
484
b = (p->info.contains('!') != 0);
487
// NOT CORRECT REPORTED BY SERVER!
488
//b = (p->info.contains('Q') != 0);
489
//slot_checkbox(2, b);
491
if (p->info.contains('Q') != 0)
492
slot_checkbox(2, true);
494
// get rank to calc handicap when matching
495
myAccount->set_rank(p->rank);
501
// from WHO command or {... has connected}
502
if (extUserInfo && myAccount->get_gsname() == IGS)
504
lv = new PlayerTableItem(ListView_players,
517
lv.current()->setText(12, rkToKey(p->rank) + p->name.lower());
521
lv = new PlayerTableItem(ListView_players,
529
lv.current()->setText(12, rkToKey(p->rank) + p->name.lower());
532
// increase number of players
533
myAccount->num_players++;
534
statusUsers->setText(" P: " + QString::number(myAccount->num_players) + " / " + QString::number(myAccount->num_watchedplayers) + " ");
538
// ListView_players->sort() ;
543
// {... has disconnected}
545
for (QListViewItem *lvi; (lvi = lv.current()) && !found;)
549
if (lvi->text(1) == p->name)
551
// check if it was a watched player
552
if (lvi->text(6) == "W")
554
qgoif->get_qgo()->playLeaveSound();
555
myAccount->num_watchedplayers--;
559
if (lvi == topViewItem) // are we trying to delete the 'anchor' of the list viewport ?
560
deleted_topViewItem = true ;
564
// decrease number of players
565
myAccount->num_players--;
566
statusUsers->setText(" P: " + QString::number(myAccount->num_players) + " / " + QString::number(myAccount->num_watchedplayers) + " ");
571
qWarning("disconnected player not found: " + p->name);
574
if (! deleted_topViewItem) //don't try to refer to a deleted element ...
576
int ip = topViewItem->itemPos();
577
ListView_players->setContentsPos(0,ip);
581
void ClientWindow::slot_addToObservationList(int flag)
585
if (myAccount->num_observedgames != 0)
586
myAccount->num_observedgames--;
589
myAccount->num_observedgames++;
591
myAccount->num_observedgames = flag;
594
statusGames->setText(" G: " + QString::number(myAccount->num_games) + " / " + QString::number(myAccount->num_observedgames) + " ");
597
// get channelinfo: ch nr + people
598
void ClientWindow::slot_channelinfo(int nr, const QString &txt)
600
qDebug("slot_channelinfo(): " + txt);
605
// check if entering a channel
606
if (txt == QString("*on*"))
608
switch (myAccount->get_gsname())
611
sendcommand("channel");
615
sendcommand("inchannel " + QString::number(nr), false);
620
else if (txt == QString("*off*"))
622
// check if channel exists in list
624
for (h = channellist.first(); h != 0 && !found; h = channellist.next())
627
if (h->get_nr() == nr)
630
channellist.remove();
635
// check if I'm in given channel
637
if (txt.contains(myAccount->acc_name) && !txt.contains("Topic:") && !txt.contains("Title:"))
643
statusChannel->setText("");
645
// check if channel exists in list
647
for (h = channellist.first(); h != 0 && !found; h = channellist.next())
650
if (h->get_nr() == nr)
657
// if not found insert channel at it's sorted position
661
ch = new Channel(nr);
662
channellist.inSort(ch);
665
// now insert channel to list
668
QString text = txt.simplifyWhiteSpace();
669
int count = text.contains(" ") + 1;
670
// set user list and user count
671
ch->set_channel(nr, QString(), txt, count);
673
else if (txt.contains("Topic:") || txt.contains("Title:"))
675
// set channel's title
676
ch->set_channel(nr, txt);
680
QToolTip::remove(statusChannel);
683
for (h = channellist.first(); h != 0; h = channellist.next())
685
if (h->get_users().length() > 2)
687
// check if users are available; skipped if only title
690
tipstring += QString("%1: %2\n%3: %4").arg(h->get_nr()).arg(h->get_title()).arg(h->get_nr()).arg(h->get_users());
691
if (statusChannel->text().length() > 2)
692
statusChannel->setText(QString("%1 / CH%2:%3").arg(statusChannel->text()).arg(h->get_nr()).arg(h->get_count()));
694
statusChannel->setText(QString("CH%1:%2").arg(h->get_nr()).arg(h->get_count()));
698
QToolTip::add(statusChannel, tipstring);
702
void ClientWindow::slot_pbuser1()
704
slot_toolbaractivated(setting->readEntry("USER1_2"));
706
void ClientWindow::slot_pbuser2()
708
slot_toolbaractivated(setting->readEntry("USER2_2"));
710
void ClientWindow::slot_pbuser3()
712
slot_toolbaractivated(setting->readEntry("USER3_2"));
714
void ClientWindow::slot_pbuser4()
716
slot_toolbaractivated(setting->readEntry("USER4_2"));
719
// tell, say, kibitz...
720
void ClientWindow::slot_message(QString txt, QColor c)
722
//QColor c0 = MultiLineEdit2->color();
723
MultiLineEdit2->setColor(c);
725
MultiLineEdit2->setColor(Qt::black);
729
void ClientWindow::slot_message(QString txt)
731
// Scroll at bottom of text, set cursor to end of line
732
if (MultiLineEdit2->text().endsWith("\n") && txt == "\n")
735
MultiLineEdit2->append(txt);
739
void ClientWindow::slot_shout(const QString &player, const QString &txt)
741
if (getPlayerExcludeListEntry(player) == "X")
744
// check if send to a special handle:
745
if (player.length() && player.contains('*'))
746
slot_talk(player, txt, true);
748
slot_talk("Shouts*", txt, true);
752
void ClientWindow::slot_svname(GSName &gs)
754
// save local at 'gsname'
755
// and change caption
756
myAccount->set_gsname(gs);
757
myAccount->set_caption();
760
// account name found
761
void ClientWindow::slot_accname(QString &name)
763
// save local at 'gsname'
764
// and change caption
765
myAccount->set_accname(name);
766
myAccount->set_caption();
770
void ClientWindow::slot_status(Status s)
772
myAccount->set_status(s);
773
myAccount->set_caption();
777
void ClientWindow::slot_playerContentsMoving(int /*x*/, int /*y*/)
780
QListViewItem *i = ListView_players->itemAt(p);
784
ListView_players->clearSelection();
785
ListView_players->setSelected(i, true);
786
ListView_players->clearSelection();
791
void ClientWindow::slot_gamesContentsMoving(int /*x*/, int /*y*/)
794
QListViewItem *i = ListView_games->itemAt(p);
798
ListView_games->clearSelection();
799
ListView_games->setSelected(i, true);
800
ListView_games->clearSelection();
809
Account::Account(QWidget* parent)
812
this->parent = parent;
813
standard.sprintf(PACKAGE + QString("V") + VERSION);
823
void Account::set_caption()
825
if ((gsName == GS_UNKNOWN) ||
828
// server unknown or no account name
829
// -> standard caption
830
parent->setCaption(standard);
835
parent->setCaption(svname + " - " + acc_name + " (guest)");
837
parent->setCaption(svname + " - " + acc_name);
841
// set go server name
842
void Account::set_gsname(GSName gs)
846
// now we know which server
849
case IGS: svname.sprintf("IGS");
852
case NNGS: svname.sprintf("NNGS");
855
case LGS: svname.sprintf("LGS");
858
case WING: svname.sprintf("WING");
861
case CTN: svname.sprintf("CTN");
864
case CWS: svname.sprintf("CWS");
867
default: svname.sprintf("unknown Server");
874
// acc_name should be set...
875
acc_name.sprintf("Lulu");
876
qWarning("set_gsname() - acc_name not found!");
879
if (status == OFFLINE)
880
status = (enum Status) REGISTERED;
884
void Account::set_accname(QString &name)
890
void Account::set_status(Status s)
895
// set to offline mode
896
void Account::set_offline()
899
svname = (QString) NULL;
900
acc_name = (QString) NULL;
906
num_watchedplayers = 0;
907
num_observedgames = 0;
911
// get some variables
912
Status Account::get_status()
917
GSName Account::get_gsname()
924
* Host - Class to save Host info
927
Host::Host(const QString &title, const QString &host, const unsigned int port, const QString &login, const QString &pass)
937
* List to help keeping things sorted
940
int HostList::compareItems(Item d1, Item d2)
942
Host *s1 = static_cast<Host*>(d1);
943
Host *s2 = static_cast<Host*>(d2);
957
int ChannelList::compareItems(Item d1, Item d2)
959
Channel *s1 = static_cast<Channel*>(d1);
960
Channel *s2 = static_cast<Channel*>(d2);
976
* Talk - Class to handle Talk Dialog Windows
979
int Talk::counter = 0;
981
Talk::Talk(const QString &playername, QWidget *parent, bool /*isplayer*/)
987
/*widget = new QWidget(parent);
988
TalkDialogWidgetLayout = new QGridLayout(widget);
989
TalkDialogWidgetLayout->setSpacing(6);
990
TalkDialogWidgetLayout->setMargin(0); */
992
//MultiLineEdit1 = new QTextEdit(widget, "MultiLineEdit1_" + QString::number(++counter));
994
QString s = "MultiLineEdit1_" + QString::number(++counter);
995
MultiLineEdit1->setName(s.ascii()) ;
997
MultiLineEdit1->setCurrentFont(setting->fontComments); //eb16
998
/*MultiLineEdit1->setProperty("focusPolicy", (int)QTextEdit::NoFocus); //eb16
999
MultiLineEdit1->setProperty("wordWrap", (int)QTextEdit::WidgetWidth);//eb16
1000
MultiLineEdit1->setProperty("readOnly", QVariant( TRUE, 0));
1002
TalkDialogWidgetLayout->addWidget(MultiLineEdit1, 0, 0);
1004
//LineEdit1 = new QLineEdit(widget, "LineEdit1_" + QString::number(counter));
1005
s = "LineEdit1_" + QString::number(++counter);
1006
LineEdit1->setName(s.ascii());
1007
LineEdit1->setFont(setting->fontComments);
1009
// do not add a button for shouts* tab
1010
if (name.find('*') != -1)
1012
/*buttonLayout = new QHBoxLayout();
1013
buttonLayout->addWidget(LineEdit1);
1014
pb_releaseTalkTab = new QPushButton(tr("close"), widget, "SkipAllTalkTabs");
1015
connect(pb_releaseTalkTab, SIGNAL(clicked()), this, SLOT(slot_pbRelTab()));
1017
buttonLayout->addWidget(pb_releaseTalkTab);
1018
TalkDialogWidgetLayout->addItem(buttonLayout, 1, 0);
1020
delete pb_releaseTalkTab;
1022
delete stats_layout;
1025
// TalkDialogWidgetLayout->addWidget(LineEdit1, 1, 0 );
1033
// release current Tab
1034
void Talk::slot_pbRelTab()
1036
emit signal_pbRelOneTab(this);
1039
void Talk::slot_returnPressed()
1042
QString txt = LineEdit1->text();
1043
emit signal_talkto(name, txt);
1047
void Talk::slot_match()
1049
QString txt= name+ " " + stats_rating->text();
1050
emit signal_matchrequest(txt,true);
1055
// write to txt field in dialog
1056
// if null string -> check edit field
1057
void Talk::write(const QString &text) const
1061
// check which text to display
1065
else if (LineEdit1->text())
1067
// take txt of edit field
1068
txt = LineEdit1->text();
1077
// Scroll at bottom of text, set cursor to end of line
1078
MultiLineEdit1->append(txt); //eb16
1081
void Talk::setTalkWindowColor(QPalette pal)
1083
MultiLineEdit1->setPalette(pal);
1084
LineEdit1->setPalette(pal);