Debian Codegraph @

src/connectionwidget.cpp

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009- by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21 #include "connectionwidget.h"
22 #include "ui_connectionwidget.h"
23
24 #include "defines.h"
25 #include "network/networkconnection.h"
26 #include "network/talk.h"
27 #include "network/gamedialog.h"
28 #include "listviews.h"
29 #include "playergamelistings.h" //FIXME should be moved out
30 #include "network/consoledispatch.h" //FIXME for channel chat
31 #include "messages.h"
32 #include "room.h"
33 #include "friendslistdialog.h"
34
35 ConnectionWidget::ConnectionWidget(QWidget *parent) :
36 QWidget(parent),
37 ui(new Ui::ConnectionWidget)
38 {
39 connection = 0;
40 room = NULL;
41 ui->setupUi(this);
42 connectionWidget = this; // FIXME: remove this global variable
43 gamesListProxyModel = new GamesListSortFilterProxyModel(this);
44 ui->gamesView->setModel(gamesListProxyModel);
45 playerListProxyModel = new PlayerListSortFilterProxyModel(this);
46 ui->playerView->setModel(playerListProxyModel);
47 connect(ui->filterOpenCheckBox, &QCheckBox::toggled, playerListProxyModel, &PlayerListSortFilterProxyModel::setFilterOpen);
48 connect(ui->filterFriendsCheckBox, &QCheckBox::toggled, playerListProxyModel, &PlayerListSortFilterProxyModel::setFilterFriends);
49 connect(ui->filterWatchesCheckBox, &QCheckBox::toggled, playerListProxyModel, &PlayerListSortFilterProxyModel::setFilterFans);
50 connect(ui->filterWatchesCheckBox, &QCheckBox::toggled, gamesListProxyModel, &GamesListSortFilterProxyModel::setFilterWatch);
51 connect(ui->playerListFilterLineEdit, &QLineEdit::textChanged, playerListProxyModel, &PlayerListSortFilterProxyModel::setFilterWildcard);
52
53 QSettings settings;
54 QVariant var = settings.value("LOWRANKFILTER");
55 ui->playerView->setAlternatingRowColors(settings.value("ALTERNATELISTCOLORS",QVariant(false)).toBool());
56 ui->gamesView->setAlternatingRowColors(settings.value("ALTERNATELISTCOLORS",QVariant(false)).toBool());
57 connect(ui->filterRank1ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ConnectionWidget::setRankSpreadView);
58 connect(ui->filterRank2ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ConnectionWidget::setRankSpreadView);
59 if(var != QVariant())
60 {
61 ui->filterRank1ComboBox->setCurrentIndex(var.toInt());
62 ui->filterRank2ComboBox->setCurrentIndex(settings.value("HIGHRANKFILTER").toInt());
63 } else {
64 ui->filterRank1ComboBox->setCurrentIndex(0);
65 ui->filterRank2ComboBox->setCurrentIndex(0);
66 }
67
68 ui->filterOpenCheckBox->setChecked(settings.value("OPENFILTER").toBool());
69 ui->filterFriendsCheckBox->setChecked(settings.value("FRIENDSFILTER").toBool());
70 ui->filterWatchesCheckBox->setChecked(settings.value("WATCHESFILTER").toBool());
71
72 ui->changeServerButton->hide();
73 connect(ui->changeServerButton, &QPushButton::clicked, this, &ConnectionWidget::slot_changeServer);
74
75 ui->createRoomButton->hide();
76 connect(ui->createRoomButton, &QPushButton::clicked, this, &ConnectionWidget::slot_createRoom);
77
78 connect(ui->connectButton, &QPushButton::clicked, this, &ConnectionWidget::disconnectFromServer);
79
80 /* We need to integrate this room list with the new room code FIXME */
81 connect(ui->roomComboBox, QOverload<const QString&>::of(&QComboBox::currentIndexChanged), this, &ConnectionWidget::slot_roomListClicked);
82 connect(ui->channelComboBox, QOverload<const QString&>::of(&QComboBox::currentIndexChanged), this, &ConnectionWidget::slot_channelListClicked);
83
84 //creates the connection code
85 seekMenu = new QMenu();
86 ui->seekToolButton->setMenu(seekMenu);
87
88 connect(seekMenu, &QMenu::triggered, this, QOverload<QAction*>::of(&ConnectionWidget::slot_seek));
89 connect(ui->seekToolButton, &QToolButton::toggled, this, QOverload<bool>::of(&ConnectionWidget::slot_seek));
90
91 connect(ui->commandLineComboBox, QOverload<const QString&>::of(&QComboBox::activated), this, &ConnectionWidget::slot_cmdactivated);
92
93 // connecting the server tab buttons
94 connect(ui->quietCheckBox, &QCheckBox::clicked, this, &ConnectionWidget::slot_cbquiet);
95 connect(ui->openCheckBox, &QCheckBox::clicked, this, &ConnectionWidget::slot_cbopen);
96 connect(ui->lookingCheckBox, &QCheckBox::clicked, this, &ConnectionWidget::setLooking);
97 connect(ui->editFriendsWatchesButton, &QPushButton::pressed, this, &ConnectionWidget::slot_editFriendsWatchesList);
98
99 bool ok;
100 int sort_column, sort_order_int;
101 Qt::SortOrder sort_order;
102 sort_column = settings.value("PlayerListSortColumn").toInt(&ok);
103 if ((sort_column <= 0) || (sort_column >= P_TOTALCOLUMNS) || (!ok))
104 sort_column = PC_NAME; // default value
105 sort_order_int = settings.value("PlayerListSortOrder").toInt(&ok);
106 if ((sort_order_int < 0) || (sort_order_int > 1) || (!ok))
107 sort_order = Qt::AscendingOrder; // default value
108 else
109 sort_order = static_cast<Qt::SortOrder>(sort_order_int);
110 ui->playerView->sortByColumn(sort_column,sort_order);
111
112 sort_column = settings.value("GamesListSortColumn").toInt(&ok);
113 if ((sort_column <= 0) || (sort_column >= G_TOTALCOLUMNS) || (!ok))
114 sort_column = GC_ID; // default value
115 sort_order_int = settings.value("GamesListSortOrder").toInt(&ok);
116 if ((sort_order_int < 0) || (sort_order_int > 1) || (!ok))
117 sort_order = Qt::AscendingOrder; // default value
118 else
119 sort_order = static_cast<Qt::SortOrder>(sort_order_int);
120 ui->gamesView->sortByColumn(sort_column,sort_order);
121
122 QFont monospaceFont("Monospace");
123 monospaceFont.setStyleHint(QFont::TypeWriter);
124 ui->MultiLineEdit2->setFont(monospaceFont);
125 }
126
127 ConnectionWidget::~ConnectionWidget()
128 {
129 QSettings settings;
130 settings.setValue("LOWRANKFILTER", ui->filterRank1ComboBox->currentIndex());
131 settings.setValue("HIGHRANKFILTER", ui->filterRank2ComboBox->currentIndex());
132
133 settings.setValue("OPENFILTER", ui->filterOpenCheckBox->isChecked());
134 settings.setValue("FRIENDSFILTER", ui->filterFriendsCheckBox->isChecked());
135 settings.setValue("WATCHESFILTER", ui->filterWatchesCheckBox->isChecked());
136
137 settings.setValue("PlayerListSortColumn",QVariant(playerListProxyModel->sortColumn()));
138 settings.setValue("PlayerListSortOrder",QVariant(playerListProxyModel->sortOrder()));
139 settings.setValue("GamesListSortColumn",QVariant(gamesListProxyModel->sortColumn()));
140 settings.setValue("GamesListSortOrder",QVariant(gamesListProxyModel->sortOrder()));
141 delete ui;
142 cleanupServerData();
143 }
144
145 void ConnectionWidget::cleanupServerData(void)
146 {
147 //delete serverliststorage; no header, done in mainwindow FIXME awkward
148 qDeleteAll(roomList);
149 qDeleteAll(channelList);
150 }
151 /*
152 * return pressed in edit line -> command to send
153 */
154
155 void ConnectionWidget::slot_cmdactivated(const QString &cmd)
156 {
157 if(connection->consoleIsChat())
158 {
159 connection->sendMsg((unsigned int)0, cmd);
160 ui->commandLineComboBox->clearEditText();
161 return;
162 }
163 if (cmd.trimmed().isEmpty())
164 return;
165 if (cmd.mid(0,2).contains("ob"))
166 {
167 QString cmd2 = cmd;
168 int number = cmd2.replace(QRegExp("[\\S]+\\s"), "").toInt();
169 if (room && number)
170 {
171 GameListing * g = room->getGameListing(number);
172 connection->sendObserve(g);
173 }
174 }
175 else if (cmd.mid(0,4).contains("yell") || cmd.mid(0,1) == ";")
176 {
177 QString cmd2 = cmd;
178 cmd2.replace(QRegExp("^[\\S]+\\s"), "");
179 connection->getConsoleDispatch()->recvText(cmd2); //copy back since otherwise doesn't appear
180 connection->sendConsoleText(cmd.toLatin1().constData());
181 ui->commandLineComboBox->clearEditText();
182 }
183 else
184 {
185 connection->sendConsoleText(cmd.toLatin1().constData());
186 ui->commandLineComboBox->clearEditText();
187 }
188 }
189
190 void ConnectionWidget::setNetworkConnection(NetworkConnection * conn)
191 {
192 if (connection != NULL)
193 connection->disconnect(this);
194 connection = conn;
195 connectionEstablished = QDateTime::currentDateTime();
196 if (connection != NULL)
197 {
198 connect(connection, &NetworkConnection::ready, this, &ConnectionWidget::loadConnectionSettings);
199 unsigned long flags = connection->getPlayerListColumns();
200 if(flags & PL_NOWINSLOSSES)
201 {
202 ui->playerView->hideColumn(PC_WINS);
203 ui->playerView->hideColumn(PC_LOSSES);
204 }
205 if(flags & PL_NOMATCHPREFS)
206 {
207 ui->playerView->hideColumn(PC_MATCHPREFS);
208 }
209 setRankSpreadView();
210 }
211 }
212
213 void ConnectionWidget::loadConnectionSettings(void)
214 {
215 QSettings settings;
216 const bool looking = settings.value("LOOKING_FOR_GAMES").toBool();
217 ui->lookingCheckBox->setChecked(looking);
218
219 const bool open = settings.value("OPEN_FOR_GAMES").toBool();
220 ui->openCheckBox->setChecked(open);
221
222 if (connection != NULL)
223 {
224 connection->sendToggle("looking", looking);
225 connection->sendToggle("open", open);
226 }
227 }
228
229
230 /*
231 * slot_connect: emitted when connect button has toggled
232 */
233 void ConnectionWidget::disconnectFromServer(void)
234 {
235 if(!connection)
236 return;
237 /* There was definitely a crash from disconnecting
238 * with a logindialog open because the logindialog kept
239 * calling network connection code. What doesn't make
240 * sense is that the logindialog is modal, so its like
241 * the server list allowed the hitting of the connect
242 * button, breaking the modality of the logindialog and
243 * allowing a crash here... FIXME But we should never
244 * get here. */
245 // For the time being just made the dialog modal
246 if (closeConnection() == 0)
247 this->setEnabled(false);
248 }
249
250 /* FIXME I feel like all the UI elements below that hide
251 * should hide on destruction of connection, not on
252 * reconnect to another service. At the same time,
253 * ORO reconnects as part of its session so that would
254 * be a bit tricky. We'll leave it here for now. */
255 void ConnectionWidget::setupButtons(void)
256 {
257 unsigned long rs_flags = connection->getRoomStructureFlags();
258 if(rs_flags & RS_NOROOMLIST)
259 {
260 ui->roomComboBox->hide();
261 ui->roomsLabel->hide();
262 }
263 else if(rs_flags & RS_SHORTROOMLIST)
264 {
265 ui->roomComboBox->show();
266 ui->roomsLabel->show();
267 }
268 else if(rs_flags & RS_LONGROOMLIST)
269 {
270 /* Here, FIXME, we'd want to replace
271 * the menu with a button that brings
272 * up a window with a tree list, to join
273 * different rooms */
274 }
275
276 ui->changeServerButton->setVisible(connection->supportsServerChange());
277 ui->createRoomButton->setVisible(connection->supportsCreateRoom());
278 ui->refreshPlayersButton->setEnabled(connection->supportsRefreshListsButtons());
279 ui->refreshGamesButton->setEnabled(connection->supportsRefreshListsButtons());
280
281 if(connection->supportsSeek())
282 {
283 ui->seekToolButton->show();
284 ui->handicapComboBox->show();
285 }
286 else
287 {
288 ui->seekToolButton->hide();
289 ui->handicapComboBox->hide();
290 }
291 if(connection->supportsChannels())
292 {
293 ui->channelsLabel->show();
294 ui->channelComboBox->show();
295 }
296 else
297 {
298 ui->channelsLabel->hide();
299 ui->channelComboBox->hide();
300 }
301
302 /* FIXME Also need away message and maybe game/player refresh */
303 #ifdef FIXME
304 // quiet mode? if yes do clear table before refresh
305 gamesListSteadyUpdate = ! ui->quietCheckBox->isChecked();
306 playerListSteadyUpdate = ! ui->quietCheckBox->isChecked();
307
308 // enable extended user info features
309 setColumnsForExtUserInfo();
310
311 // check for messages
312 if (youhavemsg)
313 sendcommand("message", false);
314 // init shouts (TODO)
315
316 // show current Server name in status bar
317 statusServer->setText(" " + myAccount->svname + " ");
318 #endif //FIXME
319 }
320
321 /* Shouldn't be here. FIXME */
322 /* Maybe it should be here? */
323 void ConnectionWidget::onConnectionError(void)
324 {
325 qDebug("ConnectionWidget::onConnectionError(void)");
326 closeConnection(true); //probably don't care about return here since connection is likely dead.
327 //could be a crash here though or maybe shouldn't be here at all doublecheck FIXME
328 /* FIXME this can get stuck open if we get a connection error on connect, like the app doesn't quit when
329 * the main window is closed */
330 this->setEnabled(false);
331 }
332
333 int ConnectionWidget::closeConnection(bool error)
334 {
335 if(connection)
336 {
337 if(!error && connection->checkForOpenBoards() < 0)
338 return -1;
339 NetworkConnection * c = connection;
340 connection = 0;
341 ui->connectButton->blockSignals(true);
342 ui->connectButton->setChecked(false); //doublecheck all this?
343 ui->connectButton->blockSignals(false);
344 delete c;
345 }
346 return 0;
347 }
348
349 /*
350 * connection closed - triggered by parser signal
351 */
352 void ConnectionWidget::slot_connexionClosed()
353 {
354 qDebug("slot_connexionClosed");
355 // no Timers in offline mode!
356
357 #ifdef FIXME
358 /* We may need to set somet status somewhere or like the
359 * OFFLINE text, but that needs to be somewhere else.
360 * This is just a reminder. */
361 // set to offline:
362 myAccount->set_offline();
363 #endif //FIXME
364 ui->connectButton->blockSignals(true);
365 ui->connectButton->setChecked(false);
366 ui->connectButton->blockSignals(false);
367 seekMenu->clear();
368
369 #ifdef FIXME
370 /* FIXME FIXME seeking */
371 slot_cancelSeek();
372 #endif //FIXME
373
374
375 // qDebug("slot_connclosed()");
376 // qDebug(QString("%1 -> slot_connclosed()").arg(statusOnlineTime->text()));
377
378 }
379
380 void ConnectionWidget::slot_changeServer(void)
381 {
382 if(connection)
383 connection->changeServer();
384 }
385
386 void ConnectionWidget::slot_createRoom(void)
387 {
388 QMessageBox::information(this, tr("Not available"), tr("This feature will be in a later version"));
389 #ifdef FIXME
390 connection->createRoom();
391 #endif //FIXME
392 }
393
394 // used for singleShot actions
395 void ConnectionWidget::set_tn_ready()
396 {
397 tn_ready = true;
398 tn_wait_for_tn_ready = false;
399 //sendTextFromApp(0);
400 }
401
402 // tell, say, kibitz...
403 void ConnectionWidget::slot_message(QString txt, QColor c)
404 {
405 ui->MultiLineEdit2->setTextColor(c);
406 if(txt.length() - 2 >= 0 &&
407 txt[txt.length() - 1] == '\n' && txt[txt.length() - 2] == '\n')
408 txt.truncate(txt.length() - 1);
409 // Scroll at bottom of text, set cursor to end of line
410 if (! (ui->MultiLineEdit2->toPlainText().endsWith('\n') && txt == "\n"))
411 ui->MultiLineEdit2->append(txt);
412
413 ui->MultiLineEdit2->setTextColor(Qt::black);
414 }
415
416 /* We're going to leave this as is until we figure out what other
417 * protocols might use for it. But obviously its necessary even
418 * for the other text protocols.*/
419 // set session parameter
420 void ConnectionWidget::set_sessionparameter(QString par, bool val)
421 {
422 QString value;
423 if(!connection)
424 return;
425
426
427 //connection->sendText("toggle " + par + value);
428 connection->sendToggle(par, val);
429 /*switch(myAccount->get_gsname())
430 {
431 // only toggling...
432 case IGS:
433 connection->sendText("toggle " + par + value);
434 break;
435
436 default:
437 connection->sendText("set " + par + value);
438 break;
439 }*/
440 }
441
442 void ConnectionWidget::slot_roomListClicked(const QString& text)
443 {
444 if(!connection)
445 return;
446 for(int i=0; i < roomList.length(); i++)
447 {
448 if(roomList[i]->name == text)
449 {
450 connection->sendJoinRoom(*(roomList[i]));
451 connection->getDefaultRoom()->slot_refreshPlayers();
452 connection->getDefaultRoom()->slot_refreshGames();
453 return;
454 }
455 }
456 qDebug("Can't find room %s", text.toLatin1().constData());
457 }
458
459 void ConnectionWidget::slot_channelListClicked(const QString& text)
460 {
461 if(!connection)
462 return;
463 if(text == "No Channel"/* || text == "Leave"*/)
464 {
465
466 return;
467 }
468 if(text == "Create")
469 {
470
471 return;
472 }
473 for(int i=0; i < channelList.length(); i++)
474 {
475 if(text.contains(QString::number(channelList[i]->number)))
476 {
477 connection->sendJoinChannel(*(channelList[i]));
478 return;
479 }
480 }
481 qDebug("Can't find channel %s", text.toLatin1().constData());
482 }
483 #ifdef FIXME
484
485
486
487
488
489 /* Same thing as the slot above that we can probably remove
490 * but just in case */
491 // prepare tables (clear, ...)
492 void ConnectionWidget::prepareTables(InfoType cmd)
493 {
494 switch (cmd)
495 {
496 case WHO: // delete player table
497 {
498 // QListViewItemIterator lv(ListView_players);
499 // for (QListViewItem *lvi; (lvi = lv.current());)
500 // {
501 // lv++;
502 // delete lvi;
503 // }
504 #ifdef FIXME
505 ui->ListView_players->clear();
506 #endif //FIXME
507
508 // set number of players to 0
509 myAccount->num_players = 0;
510 myAccount->num_watchedplayers = 0;
511 // use this for fast filling
512 playerListEmpty = true;
513 statusUsers->setText(" P: 0");// / 0 ");
514 break;
515 }
516
517 case GAMES: // delete games table
518 {
519 // QListViewItemIterator lv(ListView_games);
520 // for (QListViewItem *lvi; (lvi = lv.current());)
521 // {
522 // lv++;
523 // delete lvi;
524 // }
525 #ifdef FIXME
526 ui->ListView_games->clear();
527 #endif //FIXME
528
529 // set number of games to 0
530 myAccount->num_games = 0;
531 statusGames->setText(" G: 0"); //(" G: 0 / 0 ");
532 break;
533 }
534
535 case CHANNELS:
536 {
537 // delete channel info
538 // channellist.clear();
539 // statusChannel->setText("");
540
541 // delete tooltips too
542 // QToolTip::remove(statusChannel);
543 // QToolTip::add(statusChannel, tr("Current channels and users"));
544
545 //We prepare the rooms list as well here
546 while (ui->roomComboBox->count() > 1)
547 ui->roomComboBox->removeItem(1);
548
549 break;
550 }
551
552 default: // unknown command???
553 qWarning("unknown Command in 'prepare_tables()'");
554 break;
555
556 }
557 }
558 #endif //FIXME
559
560
561 #ifdef FIXME
562 /* Below, again, could be helpful and such column changes DO need to be
563 * done, but they're specific to the connection */
564 /*
565 * sets the columns for specific IGS infos
566 */
567 void ConnectionWidget::setColumnsForExtUserInfo()
568 {
569
570 if (/* !extUserInfo || */(myAccount->get_gsname() != IGS) )
571 {
572 // set player table's columns to 'who' mode
573 #ifdef FIXME
574 /* We'll have to test this on other servers?
575 * Actually the columns should be there or not
576 * but we just might leave them blank or "-"*/
577 ui->ListView_players->setColumnHidden(11,TRUE);
578 ui->ListView_players->setColumnHidden(10,TRUE);
579 ui->ListView_players->setColumnHidden(9,TRUE);
580 ui->ListView_players->setColumnHidden(8,TRUE);
581 ui->ListView_players->setColumnHidden(7,TRUE);
582 #endif //FIXME
583 }
584 else// if ( ui->ListView_players->columns() < 9 )
585 {
586 // set player table's columns to 'user' mode
587 // first: remove invisible column
588 // ui->ListView_players->removeColumn(7);
589 // second: add new columns
590 // ui->ListView_players->addColumn(tr("Info"));
591 // ui->ListView_players->addColumn(tr("Won"));
592 // ui->ListView_players->addColumn(tr("Lost"));
593 // ui->ListView_players->addColumn(tr("Country"));
594 // ui->ListView_players->addColumn(tr("Match prefs"));
595 // ui->ListView_players->setColumnAlignment(7, Qt::AlignRight);
596 // ui->ListView_players->setColumnAlignment(8, AlignRight);
597 // ui->ListView_players->setColumnAlignment(9, AlignRight);
598 #ifdef FIXME
599 ui->ListView_players->setColumnHidden(11,FALSE);
600 ui->ListView_players->setColumnHidden(10,FALSE);
601 #endif //FIXME
602 // ui->ListView_players->setColumnHidden(9,FALSE);
603 // ui->ListView_players->setColumnHidden(8,FALSE);
604 // ui->ListView_players->setColumnHidden(7,FALSE);
605 }
606 }
607
608 /*
609 * server name found by parser
610 */
611 void ConnectionWidget::slot_svname(GSName &gs)
612 {
613 // save local at 'gsname'
614 // and change caption
615 myAccount->set_gsname(gs);
616 myAccount->set_caption();
617 }
618
619
620 /*
621 * account name found by parser
622 */
623 void ConnectionWidget::slot_accname(QString &name)
624 {
625 // save local at 'gsname'
626 // and change caption
627 myAccount->set_accname(name);
628 myAccount->set_caption();
629 }
630
631 #endif //FIXME
632
633 void ConnectionWidget::recvSeekCondition(class SeekCondition * s)
634 {
635 if(!s)
636 seekMenu->clear();
637 else
638 {
639 QString time_condition;
640
641 time_condition = QString::number((s->maintime / 60)) + " min + " + QString::number(int(s->periodtime / 60)) + " min / " + QString::number(s->periods) + " stones";
642
643 QAction *act = seekMenu->addAction(time_condition);// , this, slot_seek(QAction*)));//, 0, a.toInt());
644 act->setData(s->number);
645 delete s;
646 }
647 }
648
649 void ConnectionWidget::recvSeekCancel(void)
650 {
651 ui->seekToolButton->setChecked(false);
652 ui->seekToolButton->setMenu(seekMenu);
653 // ui->seekToolButton->setPopupDelay(1);
654 ui->seekToolButton->setIcon(QIcon(":/resources/pics/not_seeking.png"));
655 killTimer(seekButtonTimer);
656 seekButtonTimer = 0;
657
658 }
659
660 /* FIXME This is for IGS, needs to be added it */
661 void ConnectionWidget::recvSeekPlayer(QString /*player*/, QString /*condition*/)
662 {
663 #ifdef FIXME
664 QString Rk;
665
666 QTreeWidgetItemIterator lv(ui->ListView_players);
667 QTreeWidgetItem *lvi;
668 for (; (*lv); lv++)
669 {
670 lvi = *lv;
671 // compare names
672 if (lvi->text(1) == player)
673 {
674 Rk = lvi->text(2);
675 break;
676 }
677 }
678
679
680 // QString Rk = getPlayerRk(player);
681 QString hop = Rk.right(1);
682 if ((Rk.right(1) != "?") && (Rk.right(1) != "+"))
683 Rk.append(" ");
684
685 slot_message(player.leftJustified(15,' ',true) + Rk.rightJustified(5) + " : " + condition, Qt::darkRed);
686 #endif //FIXME
687 }
688
689 /*
690 * the 'seek' button was pressed
691 */
692 void ConnectionWidget::slot_seek(bool b)
693 {
694 //qDebug("seek button pressed : status %i", (int)b);
695
696 //if the button was just pressed on, we have already used the popup menu : nothing to do
697 if (b)
698 return;
699 if(connection)
700 connection->sendSeekCancel();
701 }
702
703 /*
704 * seek button : menu entry (time conditions) selected
705 */
706 void ConnectionWidget::slot_seek(QAction *act)
707 {
708 ui->seekToolButton->setChecked(true);
709 ui->seekToolButton->setMenu(NULL);
710
711 //childish, but we want to have an animated icon there
712 seekButtonTimer = startTimer(200);
713
714 SeekCondition * s = new SeekCondition();
715 s->number = act->data().toInt();
716 qDebug("preparing to send seek");
717 switch (ui->handicapComboBox->currentIndex())
718 {
719 case 0 :
720 s->strength_wished = "1 1 0";
721 break ;
722
723 case 1 :
724 s->strength_wished = "2 2 0";
725 break ;
726
727 case 2 :
728 s->strength_wished = "5 5 0";
729 break ;
730
731 case 3 :
732 s->strength_wished = "9 9 0";
733 break ;
734
735 case 4 :
736 s->strength_wished = "0 9 0";
737 break ;
738
739 case 5 :
740 s->strength_wished = "9 0 0";
741 break ;
742 }
743 connection->sendSeek(s);
744 delete s;
745 }
746
747 /* FIXME FIXME FIXME
748 * Same thing here, room changes, as in channels, should be fixed.. but I'm
749 * thinking, no console and tabbed chat rooms FIXME FIXME */
750 /*
751 * room string received after 'room' command
752 */
753 void ConnectionWidget::recvRoomListing(const RoomListing & room, bool b)
754 {
755 unsigned long rf = connection->getRoomStructureFlags();
756 /* FIXME, either way, we should keep a list of RoomListings
757 * some where */
758 //qDebug("Recv room listing %d %s", room.number, room.name.toLatin1().constData());
759 for(int i=0; i < roomList.length(); i++)
760 {
761 if(roomList[i]->name == room.name)
762 {
763 if(!b)
764 {
765 //room has been removed
766 roomList.removeAt(i);
767 if(rf & RS_SHORTROOMLIST)
768 {
769 //remove item from list
770 }
771 else if(rf & RS_LONGROOMLIST)
772 {
773
774 }
775 }
776 return;
777 }
778 }
779 if(!b)
780 return; //removed room not found
781 roomList.append(&room);
782
783 if(rf & RS_SHORTROOMLIST)
784 {
785 //do we already have the same room number in list ?
786 //if (ui->roomComboBox->findText(room.name.left(3), Qt::MatchStartsWith )!= -1)
787 // return;
788 //so far, we just create the room if it is open
789 //if(b)
790 ui->roomComboBox->addItem(room.name);
791 }
792 else if(rf & RS_LONGROOMLIST)
793 {
794 //FIXME update that window tree view we would add
795 }
796 }
797
798 void ConnectionWidget::recvChannelListing(const ChannelListing & channel, bool b)
799 {
800 for(int i=0; i < channelList.length(); i++)
801 {
802 if(channelList[i]->name.contains(QString::number(channel.number)))
803 {
804 if(!b)
805 {
806 //channel has been removed
807 channelList.removeAt(i);
808 }
809 return;
810 }
811 }
812 if(!b)
813 return; //removed channel not found
814 channelList.append(&channel);
815 if(channel.number == 0)
816 ui->channelComboBox->addItem(channel.name);
817 else
818 ui->channelComboBox->addItem(QString::number(channel.number) + " " + channel.name);
819 }
820
821 void ConnectionWidget::changeChannel(const QString & s)
822 {
823 for(int i = 0; i < ui->channelComboBox->count(); i++)
824 {
825 if(ui->channelComboBox->itemText(i).contains(s))
826 {
827 ui->channelComboBox->setCurrentIndex(i);
828 return;
829 }
830 }
831 }
832
833 /* I think we still use this, it needs to move moved to somewhere
834 * or kept here but... reconciled with new code or something FIXME */
835 void ConnectionWidget::talkOpened(Talk * d)
836 {
837 int index = ui->talkTabs->indexOf(d);
838 if (index == -1)
839 index = ui->talkTabs->addTab(d, d->get_name());
840 ui->talkTabs->setCurrentIndex(index);
841 }
842
843 /*
844 * set checkbox status because of server info or because menu / checkbok toggled
845 */
846 void ConnectionWidget::slot_checkbox(int nr, bool val)
847 {
848 // QCheckBox::ToggleState v = (val ?
849
850 // set checkbox (nr) to val
851 switch (nr)
852 {
853 // open
854 case 0:
855 //toolOpen->setOn(val);
856 ui->openCheckBox->setChecked(val);
857 break;
858
859 // looking
860 case 1:
861 //toolLooking->setOn(val);
862 ui->lookingCheckBox->setChecked(val);
863 break;
864
865 // quiet
866 case 2:
867 //toolQuiet->setOn(val);
868 ui->quietCheckBox->setChecked(val);
869 break;
870
871 default:
872 qWarning("checkbox doesn't exist");
873 break;
874 }
875 }
876
877 /*
878 * checkbox looking cklicked
879 */
880 void ConnectionWidget::setLooking(bool val)
881 {
882 set_sessionparameter("looking", val);
883
884 if (val)
885 // if looking then set open
886 set_sessionparameter("open", true);
887 }
888
889 /*
890 * checkbox open clicked
891 */
892 void ConnectionWidget::slot_cbopen()
893 {
894 bool val = ui->openCheckBox->isChecked();
895 set_sessionparameter("open", val);
896 qDebug("Setting session open: %d", val);
897 if (!val)
898 // if not open then set close
899 set_sessionparameter("looking", false);
900 /* See above comment. */
901 /*QSettings settings;
902 settings.setValue("OPEN_FOR_GAMES", val);
903 if(!val)
904 settings.setValue("LOOKING_FOR_GAMES", false);*/
905 }
906
907 /*
908 * checkbox quiet clicked
909 */
910 void ConnectionWidget::slot_cbquiet()
911 {
912 bool val = ui->quietCheckBox->isChecked();
913 set_sessionparameter("quiet", val);
914
915 /* FIXME periodic list refreshes may not be necessary, set quiet true does a lot */
916 /*if (val)
917 {
918 if(connection)
919 connection->periodicListRefreshes(false);
920 // if 'quiet' button is once set to true the list is not reliable any longer
921 }
922 else
923 {
924 if(connection)
925 connection->periodicListRefreshes(true);
926 }*/
927 }
928
929 void ConnectionWidget::timerEvent(QTimerEvent* e)
930 {
931 // some variables for forcing send buffer and keep line established
932 static int counter = 899;
933 static int tnwait = 0;
934 static int imagecounter = 0;
935
936 //qDebug( "timer event, id %d", e->timerId() );
937
938 if (e->timerId() == seekButtonTimer)
939 {
940 imagecounter = (imagecounter+1) % 4;
941 QString ic = ":/resources/pics/seeking" + QString::number(imagecounter + 1) +".png";
942 ui->seekToolButton->setIcon(QIcon(ic));
943 return;
944 }
945 // else its the mainServerTimer
946 if (tn_ready)
947 {
948 // case: ready to send
949 tnwait = 0;
950 }
951 else if (tnwait < 2)
952 {
953 //qDebug(QString("%1: HoldTheLine SET: something has been sent").arg(statusOnlineTime->text()));
954 // case: not ready to send, but maybe waiting for READY message
955 tnwait++;
956 // something was sent, so reset counter
957 counter = 899;//resetCounter();
958 autoAwayMessage = false;
959 }
960
961 if (counter % 300 == 0)
962 {
963 // 5 mins away -> set auto answering
964 autoAwayMessage = true;
965 if (counter == 0)
966 {
967 // send "ayt" every half hour anyway
968 // new: reset timer after one hour of idle state
969 // -> if not observing a game!
970 //qDebug(QString("%1 -> HoldTheLine: status = %2").arg(statusOnlineTime->text()).arg(holdTheLine));
971 #ifdef FIXME
972 if (holdTheLine)
973 sendcommand("ayt", false);
974 #endif //FIXME
975 // 12*5 min
976 counter = 899;// resetCounter();
977 #ifdef FIXME
978 if (myAccount->num_observedgames == 0)
979 {
980 // nothing observing
981 holdTheLine = false;
982 //qDebug(QString("%1: HoldTheLine END!").arg(statusOnlineTime->text()));
983 }
984 else
985 {
986 //qDebug(QString("%1: HoldTheLine LENGTHENED: observing game...").arg(statusOnlineTime->text()));
987 }
988 #endif //FIXME
989 }
990 #ifdef FIXME
991 else if (myAccount->get_gsname() == IGS && holdTheLine)
992 {
993 sendcommand("gamelist", false);
994 qDebug(QString("%1 -> gamelist").arg(statusOnlineTime->text()).toLatin1().constData());
995 }
996 #endif //FIXME
997 }
998
999 counter--;
1000 }
1001
1002 /*
1003 * The parser has sent a message to be put in the messages box
1004 */
1005 void ConnectionWidget::slot_msgBox(const QString& msg)
1006 {
1007 qDebug("slot_msgBox\n");
1008 ui->talkTabs->setCurrentIndex(1);
1009 ui->msgTextEdit->append(msg);
1010 }
1011
1012 bool ConnectionWidget::isConnected(void)
1013 {
1014 return (connection != NULL);
1015 }
1016
1017 /* This code was taken from mainwindow_server.cpp
1018 * I guess it figures out which is min and which
1019 * is max?? */
1020 void ConnectionWidget::setRankSpreadView(void)
1021 {
1022 QString rkMin, rkMax;
1023
1024 if ((ui->filterRank1ComboBox->currentIndex() == 0) && (ui->filterRank2ComboBox->currentIndex() == 0))
1025 {
1026 rkMin = "NR";
1027 rkMax = "9p";
1028 }
1029
1030 else if ( ((ui->filterRank1ComboBox->currentIndex() == 0) && (ui->filterRank2ComboBox->currentIndex() == 1)) ||
1031 ((ui->filterRank1ComboBox->currentIndex() == 1) && (ui->filterRank2ComboBox->currentIndex() == 0)) ||
1032 ((ui->filterRank1ComboBox->currentIndex() == 1) && (ui->filterRank2ComboBox->currentIndex() ==1)) )
1033 {
1034 rkMin = "1p";
1035 rkMax = "9p";
1036 }
1037
1038 else if ((ui->filterRank1ComboBox->currentIndex() == 0) && (ui->filterRank2ComboBox->currentIndex() > 1))
1039 {
1040 rkMin = ui->filterRank2ComboBox->currentText();
1041 rkMax = ui->filterRank2ComboBox->currentText();
1042 }
1043
1044
1045 else if ((ui->filterRank1ComboBox->currentIndex() > 1) && (ui->filterRank2ComboBox->currentIndex() == 0))
1046 {
1047 rkMin = ui->filterRank1ComboBox->currentText();
1048 rkMax = ui->filterRank1ComboBox->currentText();
1049 }
1050
1051 else if ((ui->filterRank1ComboBox->currentIndex() > 1) && (ui->filterRank2ComboBox->currentIndex() == 1))
1052 {
1053 rkMin = ui->filterRank1ComboBox->currentText();
1054 rkMax = "9p";
1055 }
1056
1057 else if ((ui->filterRank1ComboBox->currentIndex() == 1) && (ui->filterRank2ComboBox->currentIndex() > 1))
1058 {
1059 rkMin = ui->filterRank2ComboBox->currentText();
1060 rkMax = "9p";
1061 }
1062
1063
1064 else if ((ui->filterRank2ComboBox->currentIndex() >= ui->filterRank1ComboBox->currentIndex() ))
1065 {
1066 rkMin = ui->filterRank2ComboBox->currentText();
1067 rkMax = ui->filterRank1ComboBox->currentText();
1068 }
1069 else
1070 {
1071 rkMin = ui->filterRank1ComboBox->currentText();
1072 rkMax = ui->filterRank2ComboBox->currentText();
1073 }
1074
1075 if (connection)
1076 {
1077 playerListProxyModel->setFilterMinRank(connection->rankToScore(rkMin));
1078 playerListProxyModel->setFilterMaxRank(connection->rankToScore(rkMax));
1079 }
1080 qDebug( "rank spread : %s - %s" , rkMin.toLatin1().constData() , rkMax.toLatin1().constData());
1081 }
1082
1083 void ConnectionWidget::slot_editFriendsWatchesList(void)
1084 {
1085 //does this crash if we do it too soon?
1086 if (connection == NULL)
1087 return;
1088 FriendsListDialog * fld = new FriendsListDialog(connection,room);
1089 fld->exec();
1090 fld->deleteLater();
1091 }