~ubuntu-branches/ubuntu/maverick/qgo/maverick

« back to all changes in this revision

Viewing changes to src/mainwin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin A. Godisch
  • Date: 2005-01-01 23:07:10 UTC
  • Revision ID: james.westby@ubuntu.com-20050101230710-fhng6yidm47xlb2i
Tags: upstream-1.0.0-r2
ImportĀ upstreamĀ versionĀ 1.0.0-r2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   mainwin.cpp - qGoClient's main window (cont. in tables.cpp)
 
3
 */
 
4
#include "clientwindow_gui.h"
 
5
#include "mainwin.h"
 
6
#include "defines.h"
 
7
#include "maintable.h"
 
8
#include "playertable.h"
 
9
#include "gamestable.h"
 
10
#include "gamedialog.h"
 
11
#include "qgo_interface.h"
 
12
#include "komispinbox.h"
 
13
#include "icons.h"
 
14
#include "igsconnection.h"
 
15
#include "mainwindow.h"
 
16
#include "qnewgamedlg.h"
 
17
#include "./pics/clientpics.h"
 
18
#include <qaction.h>
 
19
#include <qdir.h>
 
20
#include <qcombobox.h>
 
21
#include <qcheckbox.h>
 
22
#include <qtabwidget.h>
 
23
#include <qlabel.h>
 
24
#include <qlineedit.h>
 
25
#include <qevent.h>
 
26
#include <qstatusbar.h>
 
27
#include <qmainwindow.h>
 
28
#include <qtooltip.h>
 
29
#include <qwhatsthis.h>
 
30
#include <qvaluelist.h>
 
31
#include <qpopupmenu.h>
 
32
#include <qtextstream.h>
 
33
#include <qeucjpcodec.h> 
 
34
#include <qjiscodec.h> 
 
35
#include <qsjiscodec.h>
 
36
#include <qgbkcodec.h>
 
37
#include <qeuckrcodec.h>
 
38
#include <qtsciicodec.h>
 
39
#include <qpalette.h>
 
40
#include <qaccel.h>
 
41
#include <qtoolbutton.h>
 
42
#include <qiconset.h>
 
43
#include <qpixmap.h>
 
44
#include <qbuttongroup.h> 
 
45
#include <qobjectlist.h> 
 
46
 
 
47
#ifndef QGO_NOSTYLES
 
48
#include <qplatinumstyle.h>
 
49
#include <qmotifstyle.h>
 
50
#include <qmotifplusstyle.h>
 
51
#include <qcdestyle.h>
 
52
#include <qsgistyle.h>
 
53
#endif
 
54
 
 
55
#include <qptrlist.h>
 
56
 
 
57
 
 
58
/*
 
59
 *   Clientwindow = MainWidget
 
60
 */
 
61
 
 
62
 
 
63
ClientWindow::ClientWindow(QMainWindow *parent, const char* name, WFlags fl)
 
64
        : ClientWindowGui( parent, name, fl ), Misc<QString>()
 
65
{
 
66
 
 
67
 
 
68
        prefsIcon= QPixmap::QPixmap(qembed_findImage("package_settings"));//QPixmap(ICON_PREFS);
 
69
//      infoIcon= QPixmap(ICON_GAMEINFO);
 
70
        exitIcon =  QPixmap::QPixmap(qembed_findImage("exit"));//QPixmap(ICON_EXIT);
 
71
        fileNewboardIcon = QPixmap::QPixmap(qembed_findImage("newboard"));//QPixmap(ICON_FILENEWBOARD);
 
72
        fileNewIcon = QPixmap::QPixmap(qembed_findImage("filenew"));//QPixmap(ICON_FILENEW);
 
73
        fileOpenIcon = QPixmap::QPixmap(qembed_findImage("fileopen"));//QPixmap(ICON_FILEOPEN);
 
74
//      fileSaveIcon = QPixmap(ICON_FILESAVE);
 
75
//      fileSaveAsIcon = QPixmap(ICON_FILESAVEAS);
 
76
//      transformIcon = QPixmap(ICON_TRANSFORM);
 
77
//      charIcon = QPixmap(ICON_CHARSET);
 
78
        manualIcon = QPixmap::QPixmap(qembed_findImage("help"));//QPixmap(ICON_MANUAL);
 
79
//      autoplayIcon = QPixmap(ICON_AUTOPLAY);
 
80
        connectedIcon = QPixmap::QPixmap(qembed_findImage("connected"));//QPixmap(ICON_CONNECTED);             
 
81
        disconnectedIcon = QPixmap::QPixmap(qembed_findImage("connect_no"));//QPixmap(ICON_DISCONNECTED);       
 
82
        OpenIcon = QPixmap::QPixmap(qembed_findImage("open"));//QPixmap(ICON_OPEN);              
 
83
        LookingIcon = QPixmap::QPixmap(qembed_findImage("looking"));//QPixmap(ICON_LOOKING);
 
84
        QuietIcon= QPixmap::QPixmap(qembed_findImage("quiet"));//QPixmap(ICON_QUIET);
 
85
        NotOpenIcon = QPixmap::QPixmap(qembed_findImage("not_open"));//QPixmap(ICON_NOT_OPEN);
 
86
        NotLookingIcon = QPixmap::QPixmap(qembed_findImage("not_looking"));//QPixmap(ICON_NOT_LOOKING);
 
87
        NotQuietIcon= QPixmap::QPixmap(qembed_findImage("not_quiet"));//QPixmap(ICON_NOT_QUIET);       
 
88
        RefreshPlayersIcon = QPixmap::QPixmap(qembed_findImage("refresh_players"));//QPixmap(ICON_REFRESH_PLAYERS);    
 
89
        RefreshGamesIcon = QPixmap::QPixmap(qembed_findImage("refresh_games"));//QPixmap(ICON_REFRESH_GAMES);        
 
90
        ComputerPlayIcon = QPixmap::QPixmap(qembed_findImage("computerplay"));//QPixmap(ICON_COMPUTER_PLAY);
 
91
        qgoIcon = QPixmap::QPixmap(qembed_findImage("Bowl"));//QPixmap(ICON_COMPUTER_PLAY);  
 
92
 
 
93
 
 
94
 
 
95
 
 
96
        // init
 
97
 
 
98
 
 
99
        DODEBUG = false;
 
100
        DD = 0;
 
101
        setting->cw = this;
 
102
        setIcon(setting->image0);
 
103
        myAccount = new Account(this);
 
104
 
 
105
  defaultStyle = qApp->style().name() ;
 
106
  // this is very dirty : we do this because there seem to be no clean way to backtrack from MainWindow to the defaultStyle :-(
 
107
  setting->writeEntry("DEFAULT_STYLE",defaultStyle ) ;
 
108
  
 
109
        hostlist.setAutoDelete(true);
 
110
        cmd_count = 0;
 
111
 
 
112
        sendBuffer.setAutoDelete(true);
 
113
  currentCommand = new sendBuf("",0);
 
114
  
 
115
        resetCounter();
 
116
        cmd_valid = false;
 
117
        tn_ready = false;
 
118
        tn_wait_for_tn_ready = false;
 
119
//      tn_active = false;
 
120
        extUserInfo = false;
 
121
        youhavemsg = false;
 
122
        playerListEmpty = true;
 
123
        gamesListSteadyUpdate = false;
 
124
        playerListSteadyUpdate = false;
 
125
        autoAwayMessage = false;
 
126
        watch = ";" + setting->readEntry("WATCH") + ";";
 
127
        exclude = ";" + setting->readEntry("EXCLUDE") + ";";
 
128
        // statistics
 
129
        bytesIn = 0;
 
130
        bytesOut = 0;
 
131
//      toolConnect = 0;
 
132
 
 
133
        // set focus, clear entry field
 
134
        cb_cmdLine->setFocus();
 
135
        cb_cmdLine->clear();
 
136
        cb_cmdLine->insertItem("");
 
137
 
 
138
        // create instance of telnetConnection
 
139
        telnetConnection = new TelnetConnection(this);
 
140
 
 
141
        // create parser and connect signals
 
142
        parser = new Parser();
 
143
        connect(parser, SIGNAL(signal_player(Player*, bool)), SLOT(slot_player(Player*, bool)));
 
144
        connect(parser, SIGNAL(signal_statsPlayer(Player*)), SLOT(slot_statsPlayer(Player*)));
 
145
        connect(parser, SIGNAL(signal_game(Game*)), SLOT(slot_game(Game*)));
 
146
        connect(parser, SIGNAL(signal_message(QString)), SLOT(slot_message(QString)));
 
147
        connect(parser, SIGNAL(signal_svname(GSName&)), SLOT(slot_svname(GSName&)));
 
148
        connect(parser, SIGNAL(signal_accname(QString&)), SLOT(slot_accname(QString&)));
 
149
        connect(parser, SIGNAL(signal_status(Status)), SLOT(slot_status(Status)));
 
150
        connect(parser, SIGNAL(signal_connclosed()), SLOT(slot_connclosed()));
 
151
        connect(parser, SIGNAL(signal_talk(const QString&, const QString&, bool)), SLOT(slot_talk(const QString&, const QString&, bool)));
 
152
        connect(parser, SIGNAL(signal_checkbox(int, bool)), SLOT(slot_checkbox(int, bool)));
 
153
        connect(parser, SIGNAL(signal_addToObservationList(int)), SLOT(slot_addToObservationList(int)));
 
154
        connect(parser, SIGNAL(signal_channelinfo(int, const QString&)), SLOT(slot_channelinfo(int, const QString&)));
 
155
        connect(parser, SIGNAL(signal_matchrequest(const QString&, bool)), this, SLOT(slot_matchrequest(const QString&, bool)));
 
156
  connect(parser, SIGNAL(signal_matchCanceled(const QString&)), this, SLOT(slot_matchCanceled(const QString&)));
 
157
        connect(parser, SIGNAL(signal_shout(const QString&, const QString&)), SLOT(slot_shout(const QString&, const QString&)));
 
158
 
 
159
        // connect mouse to games table/player table
 
160
        connect(ListView_games, SIGNAL(contextMenuRequested(QListViewItem*, const QPoint&, int)),
 
161
                                SLOT(slot_menu_games(QListViewItem*, const QPoint&, int)));
 
162
 
 
163
        // doubleclick
 
164
        connect(ListView_games, SIGNAL(doubleClicked(QListViewItem*)),
 
165
                                                        SLOT(slot_click_games(QListViewItem*)));
 
166
 
 
167
        // move
 
168
/*      connect(ListView_games, SIGNAL(onViewport()),
 
169
                                                        SLOT(slot_moveOver_games()));
 
170
*/
 
171
  
 
172
        connect(ListView_players, SIGNAL(contextMenuRequested(QListViewItem*, const QPoint&, int)),
 
173
                                                        SLOT(slot_menu_players(QListViewItem*, const QPoint&, int)));
 
174
 
 
175
        // doubleclick
 
176
        connect(ListView_players, SIGNAL(doubleClicked(QListViewItem*)),
 
177
                                                        SLOT(slot_click_players(QListViewItem*)));
 
178
 
 
179
        // move
 
180
/*      connect(ListView_players, SIGNAL(onViewport()),
 
181
                                                        SLOT(slot_moveOver_players()));
 
182
*/
 
183
 
 
184
        // restore last setting
 
185
        if (!setting)
 
186
        {
 
187
                setting = new Setting();
 
188
                setting->loadSettings();
 
189
        }
 
190
 
 
191
        // View Statusbar                          
 
192
        initStatusBar(this);
 
193
        // Sets actions
 
194
        initActions();
 
195
        // Set menus
 
196
        initmenus(this);
 
197
        // Sets toolbar
 
198
        initToolBar();                              //end add eb 5
 
199
 
 
200
        int i;
 
201
        QString s;
 
202
// ----
 
203
// BEGIN find outdated keys:
 
204
// ----
 
205
 
 
206
        if (setting->readIntEntry("VERSION") < SETTING_VERSION)
 
207
        {
 
208
                // version settings are not actual
 
209
                int s_v = setting->readIntEntry("VERSION");
 
210
 
 
211
                switch (s_v)
 
212
                {
 
213
                        case 0:
 
214
                                for (i = 1; i < 5; i++)
 
215
                                {
 
216
                                        s = setting->readEntry("USER" + QString::number(i));
 
217
                                        if (s.length() > 0)
 
218
                                        {
 
219
                                                QString i_ = QString::number(i);
 
220
                                                setting->writeEntry("USER" + i_ + "_1", element(s, 0, DELIMITER));
 
221
                                                setting->writeEntry("USER" + i_ + "_2", element(s, 1, DELIMITER));
 
222
                                                setting->writeEntry("USER" + i_ + "_3", element(s, 2, DELIMITER));
 
223
                                                // delete old label
 
224
                                                setting->writeEntry("USER" + i_, 0);
 
225
                                        }
 
226
                                }
 
227
                                setting->writeEntry("HOSTWINDOW", 0);
 
228
 
 
229
                                i = 0;
 
230
                                while ((s = setting->readEntry("HOST" + QString::number(++i))) != NULL)
 
231
                                {
 
232
                                        // check if 4 delimiters in s
 
233
                                        if (s.contains(DELIMITER) == 4)
 
234
                                        {
 
235
                                                setting->writeEntry("HOST" + QString::number(i) + "a", element(s, 0, DELIMITER));
 
236
                                                setting->writeEntry("HOST" + QString::number(i) + "b", element(s, 1, DELIMITER));
 
237
                                                setting->writeIntEntry("HOST" + QString::number(i) + "c", element(s, 2, DELIMITER).toInt());
 
238
                                                setting->writeEntry("HOST" + QString::number(i) + "d", element(s, 3, DELIMITER));
 
239
                                                setting->writeEntry("HOST" + QString::number(i) + "e", element(s, 4, DELIMITER));
 
240
                                        }
 
241
                                        // delete old hosts
 
242
                                        setting->writeEntry("HOST" + QString::number(i), QString());
 
243
                                }
 
244
                                break;
 
245
 
 
246
                        default:
 
247
                                break;
 
248
                }
 
249
        }
 
250
// ----
 
251
// END find
 
252
// ----
 
253
 
 
254
        // restore: hostlist
 
255
        i = 0;
 
256
        while ((s = setting->readEntry("HOST" + QString::number(++i) + "a")) != NULL)
 
257
        {
 
258
                hostlist.inSort(new Host(setting->readEntry("HOST" + QString::number(i) + "a"),
 
259
                                             setting->readEntry("HOST" + QString::number(i) + "b"),
 
260
                                             setting->readIntEntry("HOST" + QString::number(i) + "c"),
 
261
                                             setting->readEntry("HOST" + QString::number(i) + "d"),
 
262
                                             setting->readEntry("HOST" + QString::number(i) + "e")));
 
263
        }
 
264
 
 
265
        // run slot command to initialize combobox and set host
 
266
        QString w = setting->readEntry("ACTIVEHOST");
 
267
        // int cb_connect
 
268
        slot_cbconnect(QString());
 
269
        if (w)
 
270
                // set host if available
 
271
                slot_cbconnect(w);
 
272
 
 
273
  //restore user buttons list
 
274
  i = 0;
 
275
  QToolButton *b;
 
276
  QPixmap p;
 
277
  userButtonGroup = new   QButtonGroup(this);
 
278
  userButtonGroup->hide();
 
279
  connect( userButtonGroup, SIGNAL(clicked(int)), SLOT(slotUserButtonClicked(int)) );
 
280
  
 
281
        while ((s = setting->readEntry("USER" + QString::number(++i) + "_1")) != NULL)
 
282
        {
 
283
    b=new QToolButton(UserToolbar) ;
 
284
    b->setText(setting->readEntry("USER" + QString::number(i) + "_1"));   //label of the button : for display
 
285
    b->setTextLabel(setting->readEntry("USER" + QString::number(i) + "_1"));   //duplicated  for storage
 
286
    b->setCaption(setting->readEntry("USER" + QString::number(i) + "_2")); //dirty but handy
 
287
    QToolTip::add(b,setting->readEntry("USER" + QString::number(i) + "_3"));
 
288
    b->setIconText(setting->readEntry("USER" + QString::number(i) + "_4"));  //dirty but handy    
 
289
    b->setMinimumWidth(25);
 
290
    if (p.load(b->iconText()))
 
291
      b->setPixmap(p);
 
292
    userButtonGroup->insert(b,-1);
 
293
        }
 
294
 
 
295
  //restore players list filters
 
296
  whoBox1->setCurrentItem(setting->readIntEntry("WHO_1"));
 
297
  whoBox2->setCurrentItem(setting->readIntEntry("WHO_2"));
 
298
  whoOpenCheck->setChecked(setting->readIntEntry("WHO_CB"));
 
299
 
 
300
    
 
301
        // restore size of client window
 
302
        s = setting->readEntry("CLIENTWINDOW");
 
303
        if (s.length() > 5)
 
304
        {
 
305
                QPoint p;
 
306
                p.setX(element(s, 0, DELIMITER).toInt());
 
307
                p.setY(element(s, 1, DELIMITER).toInt());
 
308
                QSize sz;
 
309
                sz.setWidth(element(s, 2, DELIMITER).toInt());
 
310
                sz.setHeight(element(s, 3, DELIMITER).toInt());
 
311
                resize(sz);
 
312
                move(p);
 
313
        }
 
314
 
 
315
        // restore splitter in client window
 
316
        s = setting->readEntry("CLIENTSPLITTER");
 
317
        if (s.length() > 5)
 
318
        {
 
319
                QValueList<int> w1, h1, w2;
 
320
                w1 << element(s, 0, DELIMITER).toInt() << element(s, 1, DELIMITER).toInt();
 
321
                h1 << element(s, 2, DELIMITER).toInt() << element(s, 3, DELIMITER).toInt();
 
322
                w2 << element(s, 4, DELIMITER).toInt() << element(s, 5, DELIMITER).toInt();
 
323
                //mainTable->s1->setSizes(w1);
 
324
    s1->setSizes(w1);
 
325
                s2->setSizes(h1);
 
326
                s3->setSizes(w2);
 
327
        }
 
328
 
 
329
        // restore size of debug window
 
330
        s = setting->readEntry("DEBUGWINDOW");
 
331
        if (s.length() > 5)
 
332
        {
 
333
                view_p.setX(element(s, 0, DELIMITER).toInt());
 
334
                view_p.setY(element(s, 1, DELIMITER).toInt());
 
335
                view_s.setWidth(element(s, 2, DELIMITER).toInt());
 
336
                view_s.setHeight(element(s, 3, DELIMITER).toInt());
 
337
        }
 
338
        else
 
339
        {
 
340
                view_p = QPoint();
 
341
                view_s = QSize();
 
342
        }
 
343
 
 
344
        // restore size of menu window
 
345
        s = setting->readEntry("MENUWINDOW");
 
346
        if (s.length() > 5)
 
347
        {
 
348
                menu_p.setX(element(s, 0, DELIMITER).toInt());
 
349
                menu_p.setY(element(s, 1, DELIMITER).toInt());
 
350
                menu_s.setWidth(element(s, 2, DELIMITER).toInt());
 
351
                menu_s.setHeight(element(s, 3, DELIMITER).toInt());
 
352
        }
 
353
        else
 
354
        {
 
355
                menu_p = QPoint();
 
356
                menu_s = QSize();
 
357
        }
 
358
 
 
359
        // restore size of preferences window
 
360
        s = setting->readEntry("PREFWINDOW");
 
361
        if (s.length() > 5)
 
362
        {
 
363
                pref_p.setX(element(s, 0, DELIMITER).toInt());
 
364
                pref_p.setY(element(s, 1, DELIMITER).toInt());
 
365
                pref_s.setWidth(element(s, 2, DELIMITER).toInt());
 
366
                pref_s.setHeight(element(s, 3, DELIMITER).toInt());
 
367
        }
 
368
        else
 
369
        {
 
370
                pref_p = QPoint();
 
371
                pref_s = QSize();
 
372
        }
 
373
 
 
374
        // 'user' cmd instead of 'who'?
 
375
        setColumnsForExtUserInfo();
 
376
 
 
377
        // create qGo Interface for board handling
 
378
        qgoif = new qGoIF(this);
 
379
        // qGo Interface
 
380
        connect(parser, SIGNAL(signal_move(GameInfo*)), qgoif, SLOT(slot_move(GameInfo*)));
 
381
        connect(parser, SIGNAL(signal_move(Game*)), qgoif, SLOT(slot_move(Game*)));
 
382
        connect(parser, SIGNAL(signal_kibitz(int, const QString&, const QString&)), qgoif, SLOT(slot_kibitz(int, const QString&, const QString&)));
 
383
        connect(parser, SIGNAL(signal_title(const QString&)), qgoif, SLOT(slot_title(const QString&)));
 
384
        connect(parser, SIGNAL(signal_komi(const QString&, const QString&, bool)), qgoif, SLOT(slot_komi(const QString&, const QString&, bool)));
 
385
        connect(parser, SIGNAL(signal_freegame(bool)), qgoif, SLOT(slot_freegame(bool)));
 
386
        connect(parser, SIGNAL(signal_matchcreate(const QString&, const QString&)), qgoif, SLOT(slot_matchcreate(const QString&, const QString&)));
 
387
        connect(parser, SIGNAL(signal_removestones(const QString&, const QString&)), qgoif, SLOT(slot_removestones(const QString&, const QString&)));
 
388
        connect(parser, SIGNAL(signal_undo(const QString&, const QString&)), qgoif, SLOT(slot_undo(const QString&, const QString&)));
 
389
        connect(parser, SIGNAL(signal_result(const QString&, const QString&, bool, const QString&)), qgoif, SLOT(slot_result(const QString&, const QString&, bool, const QString&)));
 
390
        connect(parser, SIGNAL(signal_requestDialog(const QString&, const QString&, const QString&, const QString&)), qgoif, SLOT(slot_requestDialog(const QString&, const QString&, const QString&, const QString&)));
 
391
        connect(this, SIGNAL(signal_move(Game*)), qgoif, SLOT(slot_move(Game*)));
 
392
        connect(this, SIGNAL(signal_computer_game(QNewGameDlg*)), qgoif, SLOT(slot_computer_game(QNewGameDlg*)));//SL added eb 12
 
393
        connect(qgoif, SIGNAL(signal_sendcommand(const QString&, bool)), this, SLOT(slot_sendcommand(const QString&, bool)));
 
394
        connect(qgoif, SIGNAL(signal_addToObservationList(int)), this, SLOT(slot_addToObservationList(int)));
 
395
        connect(qgoif->get_qgo(), SIGNAL(signal_updateFont()), this, SLOT(slot_updateFont()));
 
396
        connect(parser, SIGNAL(signal_timeAdded(int, bool)), qgoif, SLOT(slot_timeAdded(int, bool)));
 
397
 
 
398
        //gamestable
 
399
//      connect(ListView_players, SIGNAL(contentsMoving(int, int)), this, SLOT(slot_playerContentsMoving(int, int)));
 
400
        connect(ListView_games, SIGNAL(contentsMoving(int, int)), this, SLOT(slot_gamesContentsMoving(int, int)));
 
401
 
 
402
        // add menu bar and status bar
 
403
//      MainAppWidgetLayout->addWidget(menuBar, 0, 0);
 
404
 
 
405
 
 
406
 
 
407
#ifndef QGO_NOSTYLES
 
408
        // set style - same as set up a board with qgoif
 
409
        int style = setting->readEntry("STYLE").toInt();
 
410
        if (style < 0 || style > 6)
 
411
        {
 
412
                setting->writeEntry("STYLE", "0");
 
413
                style = 0;
 
414
        }
 
415
 
 
416
 
 
417
  
 
418
        switch (style)
 
419
        {
 
420
    case 0:
 
421
      //qApp->setStyle(NULL);
 
422
                  break;
 
423
    
 
424
                case 1:
 
425
                        qApp->setStyle(new QWindowsStyle);
 
426
                        break;
 
427
 
 
428
                case 2:
 
429
                        qApp->setStyle(new QPlatinumStyle);
 
430
                        break;
 
431
 
 
432
                case 3:
 
433
                        qApp->setStyle(new QMotifStyle);
 
434
                        break;
 
435
 
 
436
                case 4:
 
437
                        qApp->setStyle(new QMotifPlusStyle);
 
438
                        break;
 
439
 
 
440
#ifdef Q_WS_WIN
 
441
// there seems to be a problem within X11...
 
442
                case 5:
 
443
                        qApp->setStyle(new QCDEStyle);
 
444
                        break;
 
445
 
 
446
                case 6:
 
447
                        qApp->setStyle(new QSGIStyle);
 
448
                        break;
 
449
#endif
 
450
/*
 
451
                case 6:
 
452
#if (QT_VERSION > 0x030102)
 
453
                        qApp->setStyle(new QWindowsXPStyle);
 
454
#else
 
455
                        qApp->setStyle(new QWindowsStyle);
 
456
#endif
 
457
                        break;
 
458
*/
 
459
 
 
460
                default:
 
461
                        qWarning("Unrecognized style!");
 
462
        }
 
463
#endif
 
464
 
 
465
        slot_updateFont();
 
466
 
 
467
        QToolTip::setGloballyEnabled(true);
 
468
 
 
469
        // install an event filter
 
470
        qApp->installEventFilter(this);
 
471
}
 
472
 
 
473
ClientWindow::~ClientWindow()
 
474
{
 
475
/*      delete qgoif;
 
476
        delete setting;
 
477
        delete telnetConnection;
 
478
        delete parser;
 
479
        delete statusUsers;
 
480
        delete statusBar;
 
481
*/
 
482
}
 
483
 
 
484
void ClientWindow::initStatusBar(QWidget* /*parent*/)
 
485
{
 
486
//      statusBar = new QStatusBar(parent);
 
487
//      statusBar->resize(-1, 20);
 
488
        statusBar()->show();
 
489
        statusBar()->setSizeGripEnabled(false);
 
490
        statusBar()->message(tr("Ready."));  // Normal indicator
 
491
 
 
492
        // Standard Text instead of "message" cause WhatsThisButten overlaps
 
493
        statusMessage = new QLabel(statusBar());
 
494
        statusMessage->setAlignment(AlignCenter | SingleLine);
 
495
        statusMessage->setText("");
 
496
        statusBar()->addWidget(statusMessage, 0, true);  // Permanent indicator
 
497
/*
 
498
        // What's this
 
499
        statusWhatsThis = new QLabel(statusBar);
 
500
        statusWhatsThis->setAlignment(AlignCenter | SingleLine);
 
501
        statusWhatsThis->setText("WHATSTHIS");
 
502
        statusBar->addWidget(statusWhatsThis, 0, true);  // Permanent indicator
 
503
        QWhatsThis::whatsThisButton(statusWhatsThis);
 
504
*/
 
505
        // The users widget
 
506
        statusUsers = new QLabel(statusBar());
 
507
        statusUsers->setAlignment(AlignCenter | SingleLine);
 
508
        statusUsers->setText(" P: 0 / 0 ");
 
509
        statusBar()->addWidget(statusUsers, 0, true);  // Permanent indicator
 
510
        QToolTip::add(statusUsers, tr("Current online players / watched players"));
 
511
        QWhatsThis::add(statusUsers, tr("Displays the number of current online players\nand the number of online players you are watching.\nA player you are watching has an entry in the 'watch player:' field."));
 
512
 
 
513
        // The games widget
 
514
        statusGames = new QLabel(statusBar());
 
515
        statusGames->setAlignment(AlignCenter | SingleLine);
 
516
        statusGames->setText(" G: 0 / 0 ");
 
517
        statusBar()->addWidget(statusGames, 0, true);  // Permanent indicator
 
518
        QToolTip::add(statusGames, tr("Current online games / observed games + matches"));
 
519
        QWhatsThis::add(statusGames, tr("Displays the number of games currently played on this server and the number of games you are observing or playing"));
 
520
 
 
521
        // The server widget
 
522
        statusServer = new QLabel(statusBar());
 
523
        statusServer->setAlignment(AlignCenter | SingleLine);
 
524
        statusServer->setText(" OFFLINE ");
 
525
        statusBar()->addWidget(statusServer, 0, true);  // Permanent indicator
 
526
        QToolTip::add(statusServer, tr("Current server"));
 
527
        QWhatsThis::add(statusServer, tr("Displays the current server's name or OFFLINE if you are not connected to the internet."));
 
528
 
 
529
        // The channel widget
 
530
        statusChannel = new QLabel(statusBar());
 
531
        statusChannel->setAlignment(AlignCenter | SingleLine);
 
532
        statusChannel->setText("");
 
533
        statusBar()->addWidget(statusChannel, 0, true);  // Permanent indicator
 
534
        QToolTip::add(statusChannel, tr("Current channels and users"));
 
535
        QWhatsThis::add(statusChannel, tr("Displays the current channels you are in and the number of users inthere.\nThe tooltip text contains the channels' title and users' names"));
 
536
 
 
537
        // Online Time
 
538
        statusOnlineTime = new QLabel(statusBar());
 
539
        statusOnlineTime->setAlignment(AlignCenter | SingleLine);
 
540
        statusOnlineTime->setText(" 00:00 ");
 
541
        statusBar()->addWidget(statusOnlineTime, 0, true);  // Permanent indicator
 
542
        QToolTip::add(statusOnlineTime, tr("Online Time"));
 
543
        QWhatsThis::add(statusOnlineTime, tr("Displays the current online time.\n(A) -> auto answer\n(Hold) -> hold the line"));
 
544
}
 
545
 
 
546
void ClientWindow::timerEvent(QTimerEvent*)
 
547
{
 
548
        // some variables for forcing send buffer and keep line established
 
549
//      static int counter = 3599;
 
550
        static int holdTheLine = true;
 
551
        static int tnwait = 0;
 
552
        static int statusCnt = 0;
 
553
        static QString statusTxt = QString();
 
554
 
 
555
        if (tn_ready)
 
556
        {
 
557
                // case: ready to send
 
558
                tnwait = 0;
 
559
        }
 
560
        else if (tnwait < 2)
 
561
        {
 
562
//qDebug(QString("%1: HoldTheLine SET: something has been sent").arg(statusOnlineTime->text()));
 
563
                // case: not ready to send, but maybe waiting for READY message
 
564
                tnwait++;
 
565
                // something was sent, so reset counter
 
566
                resetCounter();
 
567
                holdTheLine = true;
 
568
                autoAwayMessage = false;
 
569
        }
 
570
/*      else if (!tn_active)
 
571
        {
 
572
                qDebug("---> sending forced!!!");
 
573
                // case: not ready to send, waiting too long -> force sending
 
574
                tnwait = 0;
 
575
                set_tn_ready();
 
576
        }
 
577
        else
 
578
                qDebug("---> not forced because of tn_active");
 
579
*/
 
580
        // show status bar text for 5 seconds
 
581
/*      if (statusTxt != statusMessage->text())
 
582
        {
 
583
                statusTxt = statusMessage->text();
 
584
                statusCnt = 5;
 
585
        }
 
586
        if (statusCnt-- == 0)
 
587
                statusMessage->setText("");
 
588
*/
 
589
        if (counter % 300 == 0)
 
590
        {
 
591
                // 5 mins away -> set auto answering
 
592
                autoAwayMessage = true;
 
593
                if (counter == 0)
 
594
                {
 
595
                        // send "ayt" every half hour anyway
 
596
                        // new: reset timer after one hour of idle state
 
597
                        //      -> if not observing a game!
 
598
      //qDebug(QString("%1 -> HoldTheLine: status = %2").arg(statusOnlineTime->text()).arg(holdTheLine));
 
599
                        if (holdTheLine)
 
600
                                sendcommand("ayt", false);
 
601
 
 
602
                        // 12*5 min
 
603
                        resetCounter();
 
604
 
 
605
                        if (myAccount->num_observedgames == 0)
 
606
                        {
 
607
                                // nothing observing
 
608
                                holdTheLine = false;
 
609
//qDebug(QString("%1: HoldTheLine END!").arg(statusOnlineTime->text()));
 
610
                        }
 
611
                        else
 
612
                        {
 
613
//qDebug(QString("%1: HoldTheLine LENGTHENED: observing game...").arg(statusOnlineTime->text()));
 
614
                        }
 
615
                }
 
616
                else if (myAccount->get_gsname() == IGS && holdTheLine)
 
617
                {
 
618
                        sendcommand("ayt", false);
 
619
                        qDebug(QString("%1 -> ayt").arg(statusOnlineTime->text()));
 
620
                }
 
621
        }
 
622
 
 
623
        counter--;
 
624
 
 
625
        // display online time
 
626
        onlineCount++;
 
627
        int hr = onlineCount/3600;
 
628
        int min = (onlineCount % 3600)/60;
 
629
        int sec = onlineCount % 60;
 
630
        QString pre = " ";
 
631
        QString min_;
 
632
        QString sec_;
 
633
 
 
634
        if (min < 10)
 
635
                min_ = "0" + QString::number(min);
 
636
        else
 
637
                min_ = QString::number(min);
 
638
 
 
639
        if (sec < 10)
 
640
                sec_ = "0" + QString::number(sec);
 
641
        else
 
642
                sec_ = QString::number(sec);
 
643
 
 
644
        if (hr)
 
645
                pre += QString::number(hr) + "h ";
 
646
 
 
647
        statusOnlineTime->setText(pre + min_ + ":" + sec_ + " ");
 
648
 
 
649
        // some statistics
 
650
        QToolTip::remove(statusServer);
 
651
        QToolTip::add(statusServer, tr("Current server") + "\n" +
 
652
                tr("Bytes in:") + " " + QString::number(bytesIn) + "\n" +
 
653
                tr("Bytes out:") + " " + QString::number(bytesOut));
 
654
//      LineEdit_bytesIn->setText(QString::number(bytesIn));
 
655
//      LineEdit_bytesOut->setText(QString::number(bytesOut));
 
656
 
 
657
// DEBUG ONLY BEGIN ****
 
658
        // DEBUG display remaining time
 
659
        hr = counter/3600;
 
660
        min = (counter % 3600)/60;
 
661
        sec = counter % 60;
 
662
        if (autoAwayMessage)
 
663
                pre = "(A) ";
 
664
        else
 
665
                pre = " ";
 
666
 
 
667
        if (min < 10)
 
668
                min_ = "0" + QString::number(min);
 
669
        else
 
670
                min_ = QString::number(min);
 
671
 
 
672
        if (sec < 10)
 
673
                sec_ = "0" + QString::number(sec);
 
674
        else
 
675
                sec_ = QString::number(sec);
 
676
 
 
677
        if (hr)
 
678
                pre += QString::number(hr) + "h ";
 
679
 
 
680
        statusMessage->setText(pre + min_ + ":" + sec_ + (holdTheLine ? " Hold" : 
 
681
" "));
 
682
// DEBUG ONLY END ****
 
683
}
 
684
 
 
685
// slot_connect: emitted when connect button has toggled
 
686
void ClientWindow::slot_connect(bool b)
 
687
{
 
688
qDebug("connect",b);
 
689
        if (b)
 
690
        {
 
691
                // create instance of telnetConnection
 
692
                if (!telnetConnection)
 
693
                        qFatal("No telnetConnection!");
 
694
 
 
695
                // connect to selected host
 
696
                telnetConnection->slotHostConnect();
 
697
        }
 
698
        else
 
699
        {
 
700
                // disconnect
 
701
                telnetConnection->slotHostQuit();
 
702
        }
 
703
}
 
704
 
 
705
// connection closed
 
706
void ClientWindow::slot_connclosed()
 
707
{
 
708
        // no Timers in offline mode!
 
709
        killTimers();
 
710
 
 
711
        // set to offline:
 
712
        myAccount->set_offline();
 
713
        //pb_connect->setOn(FALSE);
 
714
        toolConnect->setOn(FALSE);       //SL added eb 5
 
715
 
 
716
        // clear channel
 
717
        prepare_tables(CHANNELS);
 
718
 
 
719
        // remove boards
 
720
        qgoif->set_initIF();
 
721
 
 
722
        qDebug("slot_connclosed()");
 
723
        qDebug(QString("%1 -> slot_connclosed()").arg(statusOnlineTime->text()));
 
724
 
 
725
        qgoif->get_qgo()->playConnectSound();
 
726
 
 
727
        // show current Server name in status bar
 
728
        statusServer->setText(" OFFLINE ");
 
729
 
 
730
        // set menu
 
731
        Connect->setEnabled(true);
 
732
        Disconnect->setEnabled(false);
 
733
        toolConnect->setOn(false);
 
734
        toolConnect->setPixmap(disconnectedIcon);
 
735
        QToolTip::remove(toolConnect);
 
736
        QToolTip::add(toolConnect, tr("Connect with") + " " + cb_connect->currentText());
 
737
}
 
738
 
 
739
// close application
 
740
void ClientWindow::saveSettings()
 
741
{
 
742
        // save setting
 
743
        int i = 0;
 
744
        for (Host *h = hostlist.first(); h != 0; h = hostlist.next())
 
745
        {
 
746
                i++;
 
747
                setting->writeEntry("HOST" + QString::number(i) + "a", h->title());
 
748
                setting->writeEntry("HOST" + QString::number(i) + "b", h->host());
 
749
                setting->writeIntEntry("HOST" + QString::number(i) + "c", h->port());
 
750
                setting->writeEntry("HOST" + QString::number(i) + "d", h->loginName());
 
751
                setting->writeEntry("HOST" + QString::number(i) + "e", h->password());
 
752
        }
 
753
        while (setting->readEntry("HOST" + QString::number(++i) + "a"))
 
754
        {
 
755
                // delete unused entries
 
756
                setting->writeEntry("HOST" + QString::number(i) + "a", QString());
 
757
                setting->writeEntry("HOST" + QString::number(i) + "b", QString());
 
758
                setting->writeEntry("HOST" + QString::number(i) + "c", QString());
 
759
                setting->writeEntry("HOST" + QString::number(i) + "d", QString());
 
760
                setting->writeEntry("HOST" + QString::number(i) + "e", QString());
 
761
        }
 
762
 
 
763
   // set the user toolbar list
 
764
   i=0 ; 
 
765
   QObjectList *bl = UserToolbar->queryList( "QToolButton" ,NULL,true,false);
 
766
   QToolButton *b0 ;
 
767
 
 
768
         for ( b0 = (QToolButton*)bl->first(); b0 != 0; b0 = (QToolButton*)bl->next())
 
769
      {
 
770
        i++ ;
 
771
        setting->writeEntry("USER" + QString::number(i) + "_1",b0->textLabel());
 
772
        setting->writeEntry("USER" + QString::number(i) + "_2",b0->caption());
 
773
                          setting->writeEntry("USER" + QString::number(i) + "_3",QToolTip::textFor (b0) );
 
774
        setting->writeEntry("USER" + QString::number(i) + "_4",b0->iconText());
 
775
      }   
 
776
 
 
777
    while (setting->readEntry("USER" + QString::number(++i) + "_1"))
 
778
            {
 
779
        setting->writeEntry("USER" + QString::number(i) + "_1",QString());
 
780
        setting->writeEntry("USER" + QString::number(i) + "_2",QString());
 
781
                          setting->writeEntry("USER" + QString::number(i) + "_3",QString());
 
782
        setting->writeEntry("USER" + QString::number(i) + "_4",QString());
 
783
      }   
 
784
 
 
785
        
 
786
        // save current connection if at least one host exists
 
787
        if (!hostlist.isEmpty())
 
788
                setting->writeEntry("ACTIVEHOST",cb_connect->currentText());
 
789
 
 
790
        setting->writeEntry("CLIENTWINDOW",
 
791
                QString::number(pos().x()) + DELIMITER +
 
792
                QString::number(pos().y()) + DELIMITER +
 
793
                QString::number(size().width()) + DELIMITER +
 
794
                QString::number(size().height()));
 
795
 
 
796
        setting->writeEntry("CLIENTSPLITTER",
 
797
                QString::number(s1->sizes().first()) + DELIMITER +
 
798
                QString::number(s1->sizes().last()) + DELIMITER +
 
799
                QString::number(s2->sizes().first()) + DELIMITER +
 
800
                QString::number(s2->sizes().last()) + DELIMITER +
 
801
                QString::number(s3->sizes().first()) + DELIMITER +
 
802
                QString::number(s3->sizes().last()));
 
803
 
 
804
        if (DD)
 
805
                setting->writeEntry("DEBUGWINDOW",
 
806
                        QString::number(DD->pos().x()) + DELIMITER +
 
807
                        QString::number(DD->pos().y()) + DELIMITER +
 
808
                        QString::number(DD->size().width()) + DELIMITER +
 
809
                        QString::number(DD->size().height()));
 
810
//      DD = 0;
 
811
 
 
812
        if (menu_s.width() > 0)
 
813
                setting->writeEntry("MENUWINDOW",
 
814
                        QString::number(menu_p.x()) + DELIMITER +
 
815
                        QString::number(menu_p.y()) + DELIMITER +
 
816
                        QString::number(menu_s.width()) + DELIMITER +
 
817
                        QString::number(menu_s.height()));
 
818
 
 
819
        if (pref_s.width() > 0)
 
820
                setting->writeEntry("PREFWINDOW",
 
821
                        QString::number(pref_p.x()) + DELIMITER +
 
822
                        QString::number(pref_p.y()) + DELIMITER +
 
823
                        QString::number(pref_s.width()) + DELIMITER +
 
824
                        QString::number(pref_s.height()));
 
825
 
 
826
        setting->writeBoolEntry("EXTUSERINFO", extUserInfo);
 
827
 
 
828
  setting->writeIntEntry("WHO_1", whoBox1->currentItem());
 
829
  setting->writeIntEntry("WHO_2", whoBox2->currentItem());
 
830
  setting->writeBoolEntry("WHO_CB", whoOpenCheck->isChecked());
 
831
  
 
832
        // write settings to file
 
833
        setting->saveSettings();
 
834
}
 
835
 
 
836
// close application
 
837
void ClientWindow::quit()
 
838
{
 
839
        saveSettings();
 
840
        qApp->quit();
 
841
}
 
842
 
 
843
// distribute text from telnet session and local commands to tables
 
844
void ClientWindow::sendTextToApp(const QString &txt)
 
845
{
 
846
#if (QT_VERSION > 0x030006)
 
847
        static int store_sort_col = -1;
 
848
        static int store_games_sort_col = -1;
 
849
#endif
 
850
        static bool player7active = false;
 
851
/*
 
852
 
 
853
 
 
854
        // set codec
 
855
        QString buf;
 
856
        QTextStream t(&buf, IO_WriteOnly);
 
857
        if (textCodec)
 
858
                t.setCodec(textCodec);
 
859
        QString tx = textFromHost;
 
860
        t << tx;
 
861
        QString txt;
 
862
        if (!t.eof())
 
863
                txt = t.read();
 
864
qDebug("#" + buf);
 
865
        if (txt == 0)
 
866
        {
 
867
                qDebug("##buffer empty");
 
868
                return;
 
869
        }
 
870
//*/
 
871
        // put text to parser
 
872
        InfoType it_ = parser->put_line(QString::fromLocal8Bit(txt));
 
873
 
 
874
        // some statistics
 
875
        setBytesIn(txt.length()+2);
 
876
 
 
877
//      if (it_ != READY)
 
878
                // a input is being parsed -> wait until tn_active == false before sending new cmd
 
879
//              tn_active = true;
 
880
 
 
881
        // GAME7_END emulation:
 
882
        if (player7active && it_ != GAME7)
 
883
        {
 
884
                player7active = false;
 
885
                if (store_games_sort_col != -1)
 
886
                        ListView_games->setSorting(store_games_sort_col);
 
887
                store_games_sort_col = -1;
 
888
 
 
889
                ListView_games->sort();
 
890
        }
 
891
 
 
892
        switch (it_)
 
893
        {
 
894
                case READY:
 
895
                        // ok, telnet is ready to receive commands
 
896
//                      tn_active = false;
 
897
                        currentCommand->txt="";
 
898
                        if (!tn_wait_for_tn_ready && !tn_ready)
 
899
                        {
 
900
                                QTimer::singleShot(200, this, SLOT(set_tn_ready()));
 
901
                                tn_wait_for_tn_ready = true;
 
902
                        }
 
903
                        sendTextFromApp(NULL);
 
904
                case WS:
 
905
                        // ready or white space -> return
 
906
//      currentCommand->txt="";
 
907
                        return;
 
908
                        break;
 
909
 
 
910
                // echo entered command
 
911
                // echo server enter line
 
912
                case CMD:
 
913
                        slot_message(txt);
 
914
                        break;
 
915
 
 
916
                // set client mode
 
917
                case NOCLIENTMODE:
 
918
                        set_sessionparameter("client", true);
 
919
                        break;
 
920
 
 
921
                case YOUHAVEMSG:
 
922
                        // normally no connection -> wait until logged in
 
923
                youhavemsg = true;
 
924
                        break;
 
925
 
 
926
                case SERVERNAME:
 
927
                        slot_message(txt);
 
928
                        // clear send buffer
 
929
                        do
 
930
                        {
 
931
                                // enable sending
 
932
                                set_tn_ready();
 
933
                        } while (sendTextFromApp(NULL) != 0);
 
934
 
 
935
                        // check if tables are sorted
 
936
#if (QT_VERSION > 0x030006)
 
937
                        if (ListView_players->sortColumn() == -1)
 
938
                                ListView_players->setSorting(2);
 
939
                        if (ListView_games->sortColumn() == -1)
 
940
                                ListView_games->setSorting(2);
 
941
#endif
 
942
 
 
943
                        switch(myAccount->get_gsname())
 
944
                        {
 
945
                                case IGS:
 
946
                                {
 
947
                                        // IGS - check if client mode
 
948
                                        bool ok;
 
949
                                        /*int cmd_nr =*/ element(txt, 0, " ").toInt(&ok);
 
950
                                        if (!ok)
 
951
                                                set_sessionparameter("client", true);
 
952
 
 
953
                                        // set quiet false; refresh players, games
 
954
                                        //if (myAccount->get_status() == GUEST)
 
955
                                                set_sessionparameter("quiet", false);
 
956
                                        //else
 
957
                                                // set id - only available if registerd; who knows why...
 
958
                                                sendcommand("id qGo " + QString(VERSION), true);
 
959
 
 
960
                                        slot_refresh(11);
 
961
                                        slot_refresh(10);
 
962
                                        break;
 
963
                                }
 
964
                                        
 
965
                                default:
 
966
                                        set_sessionparameter("client", true);
 
967
                                        // set quiet false; refresh players, games
 
968
                                        //if (myAccount->get_status() == GUEST)
 
969
                                                set_sessionparameter("quiet", false);
 
970
                                        slot_refresh(11);
 
971
                                        if (myAccount->get_gsname() != CWS)
 
972
                                                slot_refresh(10);
 
973
                                        break;
 
974
                        }
 
975
 
 
976
                        // set menu
 
977
                        Connect->setEnabled(false);
 
978
                        Disconnect->setEnabled(true);
 
979
                        toolConnect->setOn(true);
 
980
                        toolConnect->setPixmap(connectedIcon);
 
981
                        QToolTip::remove(toolConnect);
 
982
                        QToolTip::add(toolConnect, tr("Disconnect from") + " " + cb_connect->currentText());
 
983
 
 
984
                        // quiet mode? if yes do clear table before refresh
 
985
                        gamesListSteadyUpdate = ! setQuietMode->isOn(); 
 
986
                        playerListSteadyUpdate = ! setQuietMode->isOn(); 
 
987
//!CheckBox_quiet->isChecked();
 
988
 
 
989
                        // enable extended user info features
 
990
                        setColumnsForExtUserInfo();
 
991
 
 
992
                        // check for messages
 
993
                        if (youhavemsg)
 
994
                                sendcommand("message", false);
 
995
 
 
996
                        // let qgo know which server
 
997
                        qgoif->set_gsName(myAccount->get_gsname());
 
998
                        // show current Server name in status bar
 
999
                        statusServer->setText(" " + myAccount->svname + " ");
 
1000
 
 
1001
                        // start timer: event every second
 
1002
                        onlineCount = 0;
 
1003
                        startTimer(1000);
 
1004
                        // init shouts
 
1005
                        slot_talk("Shouts*", 0, true);
 
1006
                        qgoif->get_qgo()->playConnectSound();
 
1007
                        break;
 
1008
 
 
1009
                // end of 'who'/'user' cmd
 
1010
                case PLAYER42_END:
 
1011
                case PLAYER27_END:
 
1012
                        // anyway, end of fast filling
 
1013
                        if (store_sort_col != -1)
 
1014
                                ListView_players->setSorting(store_sort_col);
 
1015
 
 
1016
                        store_sort_col = -1;
 
1017
                        ListView_players->sort();
 
1018
                        playerListEmpty = false;
 
1019
                        break;
 
1020
 
 
1021
                // skip table if initial table is to be loaded
 
1022
                case PLAYER27_START:
 
1023
                case PLAYER42_START:
 
1024
                        // disable sorting for fast operation; store sort column index
 
1025
                        store_sort_col = ListView_players->sortColumn();
 
1026
                        ListView_players->setSorting(-1);
 
1027
 
 
1028
                        if (playerListEmpty)
 
1029
                                prepare_tables(WHO);
 
1030
                        break;
 
1031
 
 
1032
                case GAME7_START:
 
1033
                        // "emulate" GAME7_END
 
1034
                        player7active = true;
 
1035
                        // disable sorting for fast operation; store sort column index
 
1036
                        // unfortunately there is not GAME7_END cmd, thus, it's emulated
 
1037
                        if (playerListEmpty)
 
1038
                        {
 
1039
                                // only if playerListEmpty, else PLAYERXX_END would not arise
 
1040
                                store_games_sort_col = ListView_games->sortColumn();
 
1041
                                ListView_games->setSorting(-1);
 
1042
                        }
 
1043
                        break;
 
1044
 
 
1045
                case ACCOUNT:
 
1046
                        // let qgo and parser know which account in case of setting something for own games
 
1047
                        qgoif->set_myName(myAccount->acc_name);
 
1048
                        parser->set_myname(myAccount->acc_name);
 
1049
                        break;
 
1050
 
 
1051
 
 
1052
    case STATS:
 
1053
        // we just received a players name as first line of stats -> create the dialog tab
 
1054
        currentCommand->txt="stats";
 
1055
 
 
1056
        if (!talklist.current())
 
1057
            slot_talk( parser->get_statsPlayer()->name,0,true);
 
1058
        
 
1059
        else if (parser->get_statsPlayer()->name != talklist.current()->get_name())
 
1060
            slot_talk( parser->get_statsPlayer()->name,0,true);
 
1061
 
 
1062
      break;
 
1063
      
 
1064
                case BEEP:
 
1065
//                      QApplication::beep();
 
1066
                        break;
 
1067
 
 
1068
                default:
 
1069
                        break;
 
1070
        }
 
1071
/*
 
1072
        // skip player list and game list
 
1073
        if (!DODEBUG)
 
1074
                switch (it_)
 
1075
                {
 
1076
                        case PLAYER42:
 
1077
                                if (!extUserInfo || myAccount->get_gsname() != IGS)
 
1078
                                        slot_message(txt);
 
1079
                        case PLAYER:
 
1080
                        case GAME:
 
1081
//                      case WS:
 
1082
                        case READY:
 
1083
                        case GAME7:
 
1084
                        case PLAYER27:
 
1085
                        case MOVE:
 
1086
                        case SHOUT:
 
1087
                        case BEEP:
 
1088
                        case KIBITZ:
 
1089
                                return;
 
1090
                                break;
 
1091
 
 
1092
                        default:
 
1093
                                break;
 
1094
                }
 
1095
 
 
1096
        // show all in messages window, but players and games
 
1097
        // Scroll at bottom of text, set cursor to end of line
 
1098
        MultiLineEdit_messages->insertLine(txt);
 
1099
*/
 
1100
        if (DODEBUG)
 
1101
                qDebug(txt);
 
1102
}
 
1103
 
 
1104
// used for singleShot actions
 
1105
void ClientWindow::set_tn_ready()
 
1106
{
 
1107
        tn_ready = true;
 
1108
        tn_wait_for_tn_ready = false;
 
1109
        sendTextFromApp(0);
 
1110
}
 
1111
 
 
1112
// send text via telnet session; skipping empty string!
 
1113
int ClientWindow::sendTextFromApp(const QString &txt, bool localecho)
 
1114
{
 
1115
        // implements a simple buffer
 
1116
        int valid = txt.length();
 
1117
 
 
1118
        // some statistics
 
1119
        if (valid)
 
1120
                setBytesOut(valid+2);
 
1121
 
 
1122
        if (myAccount->get_status() == OFFLINE)
 
1123
        {
 
1124
                // skip all commands while not telnet connection
 
1125
                sendTextToApp("Command skipped - no telnet connection: " + txt);
 
1126
                // reset buffer
 
1127
                sendBuffer.clear();
 
1128
                return 0;
 
1129
        }
 
1130
 
 
1131
        // check if telnet ready
 
1132
        if (tn_ready)
 
1133
        {
 
1134
                sendBuf *s = sendBuffer.getFirst();
 
1135
 
 
1136
                if (s)
 
1137
                {
 
1138
                        // send buffer cmd first; then put current cmd to buffer
 
1139
                        telnetConnection->sendTextFromApp(s->get_txt());
 
1140
//qDebug("SENDBUFFER send: " + s->get_txt());
 
1141
 
 
1142
                        // hold the line if cmd is sent; 'ayt' is autosend cmd
 
1143
                        if (s->get_txt().find("ayt") != -1)
 
1144
                                resetCounter();
 
1145
                        if (s->get_localecho())
 
1146
                                sendTextToApp(CONSOLECMDPREFIX + QString(" ") + s->get_txt());
 
1147
                        tn_ready = false;
 
1148
 
 
1149
                        // delete sent command from buffer 
 
1150
      //currentCommand->txt = s->get_txt();
 
1151
      sendBuffer.removeFirst();
 
1152
 
 
1153
      
 
1154
                        if (valid)
 
1155
                        {
 
1156
                                // append current command to send as soon as possible
 
1157
                                sendBuffer.append(new sendBuf(txt, localecho));
 
1158
//qDebug("SENDBUFFER added: " + txt);
 
1159
                        }
 
1160
                }
 
1161
                else if (valid)
 
1162
                {
 
1163
                        // buffer empty -> send direct
 
1164
                        telnetConnection->sendTextFromApp(txt);
 
1165
      //currentCommand->txt = txt;
 
1166
      
 
1167
                        if (!txt.contains("ayt"))
 
1168
                                resetCounter();
 
1169
                        if (localecho)
 
1170
                                sendTextToApp(CONSOLECMDPREFIX + QString(" ") + txt);
 
1171
                        tn_ready = false;
 
1172
 
 
1173
//qDebug("SENDBUFFER send direct: " + txt);
 
1174
                }
 
1175
        }
 
1176
        else if (valid)
 
1177
        {
 
1178
//qDebug("SENDBUFFER added: " + txt);
 
1179
                sendBuffer.append(new sendBuf(txt, localecho));
 
1180
        }
 
1181
 
 
1182
        return sendBuffer.count();
 
1183
}
 
1184
 
 
1185
// show command, send it, and tell parser
 
1186
void ClientWindow::sendcommand(const QString &cmd, bool localecho)
 
1187
 {
 
1188
        QString testcmd = cmd;
 
1189
 
 
1190
        // for testing
 
1191
        if (cmd.find("#") == 0)
 
1192
        {
 
1193
                qDebug("detected TEST (#) command");
 
1194
                testcmd = testcmd.remove(0, 1).stripWhiteSpace();
 
1195
 
 
1196
                // help
 
1197
                if (testcmd.length() <= 1)
 
1198
                {
 
1199
                        sendTextToApp("local cmds available:\n"
 
1200
                                "#+dbgwin\t#+dbg\t\t#-dbg\n");
 
1201
                        return;
 
1202
                }
 
1203
 
 
1204
                // detect internal commands
 
1205
                if (testcmd.contains("+dbgwin"))
 
1206
                {
 
1207
                        // show debug window
 
1208
                        DD->show();
 
1209
                        this->setActiveWindow();
 
1210
                }
 
1211
                else if (testcmd.contains("+dbg"))
 
1212
                {
 
1213
                        // show debug window and activate debug mode
 
1214
                        qDebug("*** set Debug on ***");
 
1215
                        DD->show();
 
1216
                        DODEBUG = true;
 
1217
                        this->setActiveWindow();
 
1218
                }
 
1219
                else if (testcmd.contains("-dbg"))
 
1220
                {
 
1221
                        // hide debug window and deactivate debug mode
 
1222
                        qDebug("*** set Debug off ***");
 
1223
                        DODEBUG = false;
 
1224
                        DD->hide();
 
1225
                }
 
1226
 
 
1227
                sendTextToApp(testcmd);
 
1228
                return;
 
1229
        }
 
1230
 
 
1231
        // echo
 
1232
        if (localecho)
 
1233
        {
 
1234
                // add to Messages, anyway
 
1235
                // Scroll at bottom of text, set cursor to end of line
 
1236
                if (DODEBUG)
 
1237
                        qDebug(cmd);
 
1238
    slot_message(cmd,Qt::blue);
 
1239
        }
 
1240
 
 
1241
        // send to Host
 
1242
        sendTextFromApp(cmd, localecho);
 
1243
}
 
1244
 
 
1245
// howver, sendcommand is no slot...
 
1246
void ClientWindow::slot_sendcommand(const QString &cmd, bool localecho)
 
1247
{
 
1248
        sendcommand(cmd, localecho);
 
1249
}
 
1250
 
 
1251
void ClientWindow::slot_toolbaractivated(const QString &cmd)
 
1252
{
 
1253
        // do some cmd lind checks for toolbar too
 
1254
        bool valid_marker = cmd_valid;
 
1255
        cmd_valid = true;
 
1256
        slot_cmdactivated(cmd);
 
1257
        cmd_valid = valid_marker;
 
1258
}
 
1259
 
 
1260
// return pressed in edit line -> command to send
 
1261
void ClientWindow::slot_cmdactivated(const QString &cmd)
 
1262
{
 
1263
        if (!cmd)
 
1264
                return;
 
1265
 
 
1266
qDebug("cmd_valid: ", cmd_valid);
 
1267
        // check if valid cmd -> cmd number risen
 
1268
        if (cmd_valid)
 
1269
        {
 
1270
                // clear field, and restore the blank line at top
 
1271
    cb_cmdLine->removeItem(1);
 
1272
    cb_cmdLine->insertItem("",0);
 
1273
    cb_cmdLine->clearEdit();
 
1274
    
 
1275
                // echo & send
 
1276
                QString cmdLine = cmd;
 
1277
                sendcommand(cmdLine.stripWhiteSpace(),true);
 
1278
                cmd_valid = false;
 
1279
 
 
1280
                // check for known commands
 
1281
                if (cmdLine.mid(0,2).contains("ob"))
 
1282
                {
 
1283
                        QString testcmd;
 
1284
 
 
1285
                        qDebug("found cmd: observe");
 
1286
                        testcmd = element(cmdLine, 1, " ");
 
1287
                        if (testcmd)
 
1288
                        {
 
1289
                                qgoif->set_observe(testcmd);
 
1290
                                sendcommand("games " + testcmd);
 
1291
                        }
 
1292
                }
 
1293
                if (cmdLine.mid(0,3).contains("who"))
 
1294
                {
 
1295
                        // clear table if manually entered
 
1296
                        prepare_tables(WHO);
 
1297
                        playerListSteadyUpdate = false;
 
1298
                }
 
1299
                if (cmdLine.mid(0,5).contains("; \\-1") && myAccount->get_gsname() == IGS)
 
1300
                {
 
1301
                        // exit all channels
 
1302
                        prepare_tables(CHANNELS);
 
1303
                }
 
1304
        }
 
1305
}
 
1306
 
 
1307
// number of activated cmd
 
1308
void ClientWindow::slot_cmdactivated_int(int i)
 
1309
{
 
1310
        if (cb_cmdLine->count() > cmd_count)
 
1311
        {
 
1312
                cmd_count = cb_cmdLine->count();
 
1313
                cmd_valid = true;
 
1314
        }
 
1315
        else
 
1316
                cmd_valid = false;
 
1317
}
 
1318
 
 
1319
// set session parameter
 
1320
void ClientWindow::set_sessionparameter(QString par, bool val)
 
1321
{
 
1322
        QString value;
 
1323
        if (val)
 
1324
                value = " true";
 
1325
        else
 
1326
                value = " false";
 
1327
 
 
1328
        switch(myAccount->get_gsname())
 
1329
        {
 
1330
                // only toggling...
 
1331
                case IGS:
 
1332
                        sendcommand("toggle " + par + value);
 
1333
                        break;
 
1334
                        
 
1335
                default:
 
1336
                        sendcommand("set " + par + value);
 
1337
                        break;
 
1338
        }
 
1339
}
 
1340
 
 
1341
// select connection or create new one - combobox connection
 
1342
void ClientWindow::slot_cbconnect(const QString &txt)
 
1343
{
 
1344
        QString text = txt;
 
1345
        Host *h = NULL;
 
1346
        int i=1;
 
1347
 
 
1348
        if (!text)
 
1349
        {
 
1350
                // txt empty: update combobox - server table has been edited...
 
1351
                // keep current host
 
1352
                text = cb_connect->currentText();
 
1353
 
 
1354
                // refill combobox
 
1355
                cb_connect->clear();
 
1356
                for (Host *h_ = hostlist.first(); h_ != NULL; h_ = hostlist.next())
 
1357
                {
 
1358
                        cb_connect->insertItem(h_->title());
 
1359
                        if (h_->title() == text)
 
1360
                        {
 
1361
                                                i = cb_connect->count();
 
1362
                                                h = h_;
 
1363
                        }
 
1364
                }
 
1365
        }
 
1366
        else
 
1367
        {
 
1368
                // view active host in cb_connect
 
1369
                h = hostlist.first();
 
1370
                while (h != NULL && h->title() != text)
 
1371
                {
 
1372
                        h = hostlist.next();
 
1373
                        i++;
 
1374
                }
 
1375
        }
 
1376
 
 
1377
        // view selected host
 
1378
        cb_connect->setCurrentItem(i-1);
 
1379
 
 
1380
        // check if host exists
 
1381
        if (!h && !(h = hostlist.getFirst()))
 
1382
                return;
 
1383
 
 
1384
        // inform telnet about selected host
 
1385
        QString lg = h->loginName();
 
1386
        QString pw = h->password();
 
1387
        telnetConnection->setHost(h->host(), lg, pw, h->port());
 
1388
        if (toolConnect)
 
1389
        {
 
1390
                QToolTip::remove(toolConnect);
 
1391
                QToolTip::add(toolConnect, tr("Connect with") + " " + cb_connect->currentText());
 
1392
        }
 
1393
/*
 
1394
                // set up codec
 
1395
                qDebug("setting up codec...");
 
1396
//                      QTextCodec *tc = textCodec;
 
1397
                textCodec = new QGbkCodec();
 
1398
                textStream->setEncoding(QTextStream::Locale);
 
1399
                textStream->setCodec(textCodec);
 
1400
//*/
 
1401
}
 
1402
 
 
1403
// set checkbox status because of server info or because menu / checkbok toggled
 
1404
void ClientWindow::slot_checkbox(int nr, bool val)
 
1405
{
 
1406
        // set checkbox (nr) to val
 
1407
        switch (nr)
 
1408
        {
 
1409
                // open
 
1410
                case 0:
 
1411
                        //toolOpen->setOn(val); 
 
1412
                        setOpenMode->setOn(val);
 
1413
                        break;
 
1414
 
 
1415
                // looking
 
1416
                case 1:
 
1417
                        //toolLooking->setOn(val); 
 
1418
                        setLookingMode->setOn(val);
 
1419
                        break;
 
1420
 
 
1421
                // quiet
 
1422
                case 2:
 
1423
                        //toolQuiet->setOn(val); 
 
1424
                        setQuietMode->setOn(val);
 
1425
                        break;
 
1426
 
 
1427
                default:
 
1428
                        qWarning("checkbox doesn't exist");
 
1429
                        break;
 
1430
        }
 
1431
}
 
1432
 
 
1433
// checkbox looking cklicked
 
1434
void ClientWindow::slot_cblooking()
 
1435
{
 
1436
        bool val = setLookingMode->isOn(); 
 
1437
//      setLookingMode->setOn(val);
 
1438
        set_sessionparameter("looking", val);
 
1439
        if (val)
 
1440
                // if looking then set open
 
1441
                set_sessionparameter("open", true);
 
1442
}
 
1443
 
 
1444
 
 
1445
// checkbox open clicked
 
1446
void ClientWindow::slot_cbopen()
 
1447
{
 
1448
        bool val = setOpenMode->isOn(); 
 
1449
//      setOpenMode->setOn(val);
 
1450
        set_sessionparameter("open", val);
 
1451
        if (!val)
 
1452
                // if not open then set close
 
1453
                set_sessionparameter("looking", false);
 
1454
}
 
1455
 
 
1456
// checkbox quiet clicked
 
1457
void ClientWindow::slot_cbquiet()
 
1458
{
 
1459
        bool val = setQuietMode->isOn(); 
 
1460
        //setQuietMode->setOn(val);
 
1461
  //qDebug("bouton %b",toolQuiet->isOn());
 
1462
        set_sessionparameter("quiet", val);
 
1463
 
 
1464
        if (val)
 
1465
        {
 
1466
                // if 'quiet' button is once set to true the list is not reliable any longer
 
1467
                gamesListSteadyUpdate = false;
 
1468
                playerListSteadyUpdate = false;
 
1469
        }
 
1470
}
 
1471
 
 
1472
 
 
1473
// switch between 'who' and 'user' cmds
 
1474
void ClientWindow::setColumnsForExtUserInfo()
 
1475
{
 
1476
        if (!extUserInfo || (myAccount->get_gsname() != IGS))
 
1477
        {
 
1478
                // set player table's columns to 'who' mode
 
1479
                ListView_players->removeColumn(11);
 
1480
                ListView_players->removeColumn(10);
 
1481
                ListView_players->removeColumn(9);
 
1482
                ListView_players->removeColumn(8);
 
1483
                ListView_players->removeColumn(7);
 
1484
        }
 
1485
        else
 
1486
        {
 
1487
                // set player table's columns to 'user' mode
 
1488
                // first: remove invisible column
 
1489
                ListView_players->removeColumn(7);
 
1490
                // second: add new columns
 
1491
                ListView_players->addColumn(tr("Info"));
 
1492
                ListView_players->addColumn(tr("Won"));
 
1493
                ListView_players->addColumn(tr("Lost"));
 
1494
                ListView_players->addColumn(tr("Country"));
 
1495
                ListView_players->addColumn(tr("Lang"));
 
1496
                ListView_players->setColumnAlignment(7, AlignRight);
 
1497
                ListView_players->setColumnAlignment(8, AlignRight);
 
1498
                ListView_players->setColumnAlignment(9, AlignRight);
 
1499
        }
 
1500
}
 
1501
 
 
1502
// switch between 'who' and 'user' cmds
 
1503
void ClientWindow::slot_cbExtUserInfo()
 
1504
{
 
1505
        extUserInfo = setting->readBoolEntry("EXTUSERINFO");
 
1506
        setColumnsForExtUserInfo();
 
1507
}
 
1508
 
 
1509
void ClientWindow::slot_updateFont()
 
1510
{
 
1511
        // lists
 
1512
        ListView_players->setFont(setting->fontLists);
 
1513
        ListView_games->setFont(setting->fontLists);
 
1514
        cb_connect->setFont(setting->fontLists);
 
1515
 
 
1516
        // comment fields
 
1517
  MultiLineEdit2->selectAll(true);
 
1518
        MultiLineEdit2->setCurrentFont(setting->fontConsole);
 
1519
  MultiLineEdit2->selectAll(false);
 
1520
  MultiLineEdit3->setCurrentFont(setting->fontComments); 
 
1521
        cb_cmdLine->setFont(setting->fontComments);
 
1522
 
 
1523
        // standard
 
1524
        setFont(setting->fontStandard);
 
1525
 
 
1526
        // set some colors
 
1527
        QPalette pal = MultiLineEdit2->palette();
 
1528
        pal.setColor(QColorGroup::Base, setting->colorBackground);
 
1529
        MultiLineEdit2->setPalette(pal);
 
1530
        MultiLineEdit3->setPalette(pal);
 
1531
        // talklist
 
1532
        Talk *dlg;
 
1533
        for (dlg = talklist.first(); dlg != 0; dlg = talklist.next())
 
1534
                dlg->setTalkWindowColor(pal);
 
1535
        pal = cb_cmdLine->palette();
 
1536
        pal.setColor(QColorGroup::Base, setting->colorBackground);
 
1537
        cb_cmdLine->setPalette(pal);
 
1538
        pal = ListView_players->palette();
 
1539
        pal.setColor(QColorGroup::Base, setting->colorBackground);
 
1540
        ListView_players->setPalette(pal);
 
1541
        ListView_games->setPalette(pal);
 
1542
        pal = cb_connect->palette();
 
1543
        pal.setColor(QColorGroup::Base, setting->colorBackground);
 
1544
        cb_connect->setPalette(pal);
 
1545
 
 
1546
        // init menu
 
1547
        viewToolBar->setOn(setting->readBoolEntry("MAINTOOLBAR"));
 
1548
  viewUserToolBar->setOn(setting->readBoolEntry("USERTOOLBAR"));
 
1549
        if (setting->readBoolEntry("MAINMENUBAR"))
 
1550
        {
 
1551
                viewMenuBar->setOn(false);
 
1552
                viewMenuBar->setOn(true);
 
1553
        }
 
1554
        viewStatusBar->setOn(setting->readBoolEntry("MAINSTATUSBAR"));
 
1555
 
 
1556
//      slot_userDefinedKeysTextChanged();
 
1557
}
 
1558
 
 
1559
// refresh button clicked
 
1560
void ClientWindow::slot_refresh(int i)
 
1561
{
 
1562
 
 
1563
  QString wparam = "" ;
 
1564
        // refresh depends on selected page
 
1565
        switch (i)
 
1566
        {
 
1567
                case 10:
 
1568
                        prepare_tables(WHO);
 
1569
                case 0:
 
1570
                        // send "WHO" command
 
1571
      //set the params of "who command"
 
1572
      if ((whoBox1->currentItem() >1)  || (whoBox2->currentItem() >1))
 
1573
        {
 
1574
             wparam.append(whoBox1->currentItem()==1 ? "9p" : whoBox1->currentText());
 
1575
             if ((whoBox1->currentItem())  && (whoBox2->currentItem()))
 
1576
                wparam.append("-");
 
1577
             wparam.append(whoBox2->currentItem()==1 ? "9p" : whoBox2->currentText());
 
1578
         }
 
1579
      else if ((whoBox1->currentItem())  || (whoBox2->currentItem()))
 
1580
           wparam.append("1p-9p");
 
1581
 
 
1582
      
 
1583
      if (whoOpenCheck->isChecked())
 
1584
          wparam.append(" o");
 
1585
 
 
1586
                  
 
1587
                        if (myAccount->get_gsname() == IGS && extUserInfo)
 
1588
                                sendcommand(wparam.prepend("user "));
 
1589
                        else
 
1590
                                sendcommand(wparam.prepend("who "));
 
1591
 
 
1592
      prepare_tables(WHO);
 
1593
                        break;
 
1594
 
 
1595
                case 11:
 
1596
                        prepare_tables(GAMES);
 
1597
                case 1:
 
1598
                        // send "GAMES" command
 
1599
                        sendcommand("games");
 
1600
//                      prepare_tables(GAMES);
 
1601
                        // which games are watched right now
 
1602
                        // don't work correct at IGS !!!!
 
1603
//                      sendcommand("watching");
 
1604
                        break;
 
1605
 
 
1606
                default:
 
1607
                        break;
 
1608
        }
 
1609
 
 
1610
}
 
1611
 
 
1612
// refresh games
 
1613
void ClientWindow::slot_pbrefreshgames()
 
1614
{
 
1615
        if (gamesListSteadyUpdate)
 
1616
                slot_refresh(1);
 
1617
        else
 
1618
        {
 
1619
                // clear table in case of quiet mode
 
1620
                slot_refresh(11);
 
1621
                gamesListSteadyUpdate = !setQuietMode->isOn(); //!CheckBox_quiet->isChecked();
 
1622
        }
 
1623
}
 
1624
 
 
1625
// refresh players
 
1626
void ClientWindow::slot_pbrefreshplayers()
 
1627
{
 
1628
        if (playerListSteadyUpdate)
 
1629
                slot_refresh(0);
 
1630
        else
 
1631
        {
 
1632
                // clear table in case of quiet mode
 
1633
                slot_refresh(10);
 
1634
                playerListSteadyUpdate = !setQuietMode->isOn(); //!CheckBox_quiet->isChecked();
 
1635
        }
 
1636
}
 
1637
 
 
1638
void ClientWindow::slot_gamesPopup(int i)
 
1639
{
 
1640
        switch (i)
 
1641
        {
 
1642
                case 1:
 
1643
                        // observe
 
1644
                        if (lv_popupGames)
 
1645
                        {
 
1646
                                // set up game for observing
 
1647
                                if (qgoif->set_observe(lv_popupGames->text(0)))
 
1648
                                {
 
1649
                                        QString gameID = lv_popupGames->text(0);
 
1650
                                        // if game is set up new -> get moves
 
1651
                                        //   set game to observe
 
1652
                                        sendcommand("observe " + gameID);
 
1653
 
 
1654
                                        // check if enough data here
 
1655
                                        if (lv_popupGames->text(7).length() == 0)
 
1656
                                        {
 
1657
                                                // LGS sends the needed information, anyway
 
1658
                                                if (myAccount->get_gsname() != LGS)
 
1659
                                                        sendcommand("games " + gameID);
 
1660
                                        }
 
1661
                                        else
 
1662
                                        {
 
1663
                                                //   complete game info
 
1664
                                                Game g;
 
1665
                                                g.nr = lv_popupGames->text(0);
 
1666
                                                g.wname = lv_popupGames->text(1);
 
1667
                                                g.wrank = lv_popupGames->text(2);
 
1668
                                                g.bname = lv_popupGames->text(3);
 
1669
                                                g.brank = lv_popupGames->text(4);
 
1670
                                                g.mv = lv_popupGames->text(5);
 
1671
                                                g.Sz = lv_popupGames->text(6);
 
1672
                                                g.H = lv_popupGames->text(7);
 
1673
                                                g.K = lv_popupGames->text(8);
 
1674
                                                g.By = lv_popupGames->text(9);
 
1675
                                                g.FR = lv_popupGames->text(10);
 
1676
                                                g.ob = lv_popupGames->text(11);
 
1677
                                                g.running = true;
 
1678
            g.oneColorGo = false;
 
1679
            
 
1680
 
 
1681
                                                emit signal_move(&g);
 
1682
                                        }
 
1683
                                }
 
1684
                        }
 
1685
                break;
 
1686
 
 
1687
                case 2:
 
1688
                        // stats
 
1689
                        slot_sendcommand("stats " + lv_popupGames->text(1), false);
 
1690
                        break;
 
1691
 
 
1692
                case 3:
 
1693
                        // stats
 
1694
                        slot_sendcommand("stats " + lv_popupGames->text(3), false);
 
1695
                        break;
 
1696
 
 
1697
                default:
 
1698
                        break;
 
1699
        }
 
1700
}
 
1701
 
 
1702
// doubleclick actions...
 
1703
void ClientWindow::slot_click_games(QListViewItem *lv)
 
1704
{
 
1705
        // do actions if button clicked on item
 
1706
        slot_mouse_games(3, lv, QPoint(), 0);
 
1707
qDebug("games list double clicked");
 
1708
}
 
1709
// move over ListView
 
1710
/*
 
1711
void ClientWindow::slot_moveOver_games()
 
1712
{
 
1713
        qDebug("move over games list...");
 
1714
} */
 
1715
// doubleclick actions...
 
1716
void ClientWindow::slot_menu_games(QListViewItem *lv, const QPoint &pt, int 
 
1717
/*column*/)
 
1718
{
 
1719
        // emulate right button
 
1720
        slot_mouse_games(2, lv, pt, 0);
 
1721
qDebug("games list double clicked");
 
1722
}
 
1723
// mouse click on ListView_games
 
1724
void ClientWindow::slot_mouse_games(int button, QListViewItem *lv, const QPoint &pt, int /*column*/)
 
1725
{
 
1726
        static QPopupMenu *puw = 0;
 
1727
        
 
1728
        // create popup window
 
1729
        if (!puw)
 
1730
        {
 
1731
                puw = new QPopupMenu(0, 0);
 
1732
                puw->insertItem(tr("observe"), this, SLOT(slot_gamesPopup(int)), 0, 1);
 
1733
                puw->insertItem(tr("stats W"), this, SLOT(slot_gamesPopup(int)), 0, 2);
 
1734
                puw->insertItem(tr("stats B"), this, SLOT(slot_gamesPopup(int)), 0, 3);
 
1735
        }
 
1736
        //puw->hide();
 
1737
 
 
1738
        // do actions if button clicked on item
 
1739
        switch (button)
 
1740
        {
 
1741
                // left
 
1742
                case 1:
 
1743
                        break;
 
1744
 
 
1745
                // right
 
1746
                case 2:
 
1747
                        if (lv)
 
1748
                        {
 
1749
                                //puw->move(pt);
 
1750
                                //puw->show();
 
1751
        puw->popup( QCursor::pos() );
 
1752
                                // store selected lv
 
1753
                                lv_popupGames = static_cast<GamesTableItem*>(lv);
 
1754
                        }
 
1755
                        break;
 
1756
 
 
1757
                // first menue item if doubleclick
 
1758
                case 3:
 
1759
                        if (lv)
 
1760
                        {
 
1761
                                // store selected lv
 
1762
                                lv_popupGames = static_cast<GamesTableItem*>(lv);
 
1763
 
 
1764
                                slot_gamesPopup(1);
 
1765
                        }
 
1766
                        break;
 
1767
 
 
1768
                default:
 
1769
                        break;
 
1770
        }
 
1771
}
 
1772
 
 
1773
 
 
1774
void ClientWindow::slot_matchCanceled(const QString &opponent)
 
1775
{
 
1776
        // set up match dialog
 
1777
        // match_dialog()
 
1778
        GameDialog *dlg = NULL;
 
1779
 
 
1780
 
 
1781
        // seek dialog
 
1782
                // look for same opponent
 
1783
        dlg = matchlist.first();
 
1784
        while (dlg && dlg->playerWhiteEdit->text() != opponent && dlg->playerBlackEdit->text() != opponent)
 
1785
                dlg = matchlist.next();
 
1786
 
 
1787
        if (dlg)
 
1788
    {
 
1789
    matchlist.remove();
 
1790
    delete dlg;
 
1791
    }
 
1792
}   
 
1793
 
 
1794
 
 
1795
  
 
1796
void ClientWindow::slot_matchrequest(const QString &line, bool myrequest)
 
1797
{
 
1798
        // set up match dialog
 
1799
        // match_dialog()
 
1800
        GameDialog *dlg = NULL;
 
1801
        QString opponent;
 
1802
 
 
1803
        // seek dialog
 
1804
        if (!myrequest)
 
1805
        {
 
1806
                // match xxxx B 19 1 10
 
1807
                opponent = element(line, 1, " ");
 
1808
 
 
1809
                // play sound
 
1810
                qgoif->get_qgo()->playMatchSound();
 
1811
        }
 
1812
        else
 
1813
        {
 
1814
                // xxxxx 4k*
 
1815
                opponent = element(line, 0, " ");
 
1816
        }
 
1817
 
 
1818
        // look for same opponent
 
1819
        dlg = matchlist.first();
 
1820
        while (dlg && dlg->playerWhiteEdit->text() != opponent && dlg->playerBlackEdit->text() != opponent)
 
1821
                dlg = matchlist.next();
 
1822
 
 
1823
        if (!dlg)
 
1824
        {
 
1825
                matchlist.insert(0, new GameDialog(0, tr("New Game"), false));
 
1826
                dlg = matchlist.current();
 
1827
                
 
1828
                if (myAccount->get_gsname() == NNGS ||
 
1829
                        myAccount->get_gsname() == LGS)
 
1830
                {
 
1831
                        // now connect suggest signal
 
1832
                        connect(parser,
 
1833
                                SIGNAL(signal_suggest(const QString&, const QString&, const QString&, const QString&, int)),
 
1834
                                dlg,
 
1835
                                SLOT(slot_suggest(const QString&, const QString&, const QString&, const QString&, int)));
 
1836
                }
 
1837
                
 
1838
                connect(dlg,
 
1839
                        SIGNAL(signal_sendcommand(const QString&, bool)),
 
1840
                        this,
 
1841
                        SLOT(slot_sendcommand(const QString&, bool)));
 
1842
                connect(parser,
 
1843
                        SIGNAL(signal_matchcreate(const QString&, const QString&)),
 
1844
                        dlg,
 
1845
                        SLOT(slot_matchcreate(const QString&, const QString&)));
 
1846
                connect(parser,
 
1847
                        SIGNAL(signal_notopen(const QString&)),
 
1848
                        dlg,
 
1849
                        SLOT(slot_notopen(const QString&)));
 
1850
                connect(parser,
 
1851
                        SIGNAL(signal_komirequest(const QString&, int, int, bool)),
 
1852
                        dlg,
 
1853
                        SLOT(slot_komirequest(const QString&, int, int, bool)));
 
1854
                connect(parser,
 
1855
                        SIGNAL(signal_opponentopen(const QString&)),
 
1856
                        dlg,
 
1857
                        SLOT(slot_opponentopen(const QString&)));
 
1858
                connect(dlg,
 
1859
                        SIGNAL(signal_matchsettings(const QString&, const QString&, const QString&, assessType)),
 
1860
                        qgoif,
 
1861
                        SLOT(slot_matchsettings(const QString&, const QString&, const QString&, assessType)));
 
1862
        }
 
1863
 
 
1864
        if (myrequest)
 
1865
        {
 
1866
                QString rk = element(line, 1, " ");
 
1867
 
 
1868
                // set values
 
1869
                dlg->playerWhiteEdit->setText(myAccount->acc_name);
 
1870
                dlg->playerWhiteEdit->setReadOnly(true);
 
1871
                dlg->playerBlackEdit->setText(opponent);
 
1872
                dlg->playerBlackEdit->setReadOnly(false);
 
1873
 
 
1874
                // set my and opponent's rank for suggestion
 
1875
                dlg->set_oppRk(rk);
 
1876
                dlg->playerBlackRkEdit->setText(rk);
 
1877
                rk = myAccount->get_rank();
 
1878
                dlg->set_myRk(rk);
 
1879
                dlg->playerWhiteRkEdit->setText(rk);
 
1880
                dlg->set_gsName(myAccount->get_gsname());
 
1881
                
 
1882
                dlg->buttonDecline->setDisabled(true);
 
1883
 
 
1884
                // my request: free/rated game is also requested
 
1885
                //dlg->cb_free->setChecked(true);
 
1886
 
 
1887
                // teaching game:
 
1888
                if (dlg->playerWhiteEdit->text() == dlg->playerBlackEdit->text())
 
1889
                        dlg->buttonOffer->setText(tr("Teaching"));
 
1890
 
 
1891
                //default settings
 
1892
                dlg->boardSizeSpin->setValue(setting->readIntEntry("DEFAULT_SIZE"));
 
1893
                dlg->timeSpin->setValue(setting->readIntEntry("DEFAULT_TIME"));
 
1894
                dlg->byoTimeSpin->setValue(setting->readIntEntry("DEFAULT_BY"));
 
1895
                dlg->komiSpin->setValue(setting->readIntEntry("DEFAULT_KOMI")*10+5);
 
1896
        }
 
1897
        else
 
1898
        {
 
1899
                // match xxxx B 19 1 10 - using this line means: I am black!
 
1900
                bool opp_plays_white = (element(line, 2, " ") == "B");//QString(tr("B")));
 
1901
                QString size = element(line, 3, " ");
 
1902
                QString time = element(line, 4, " ");
 
1903
                QString byotime = element(line, 5, " ");
 
1904
 
 
1905
                QString rk = getPlayerRk(opponent);
 
1906
                dlg->set_oppRk(rk);
 
1907
                QString myrk = myAccount->get_rank();
 
1908
                dlg->set_myRk(myrk);
 
1909
 
 
1910
                if (opp_plays_white)
 
1911
                {
 
1912
                        dlg->playerBlackEdit->setText(myAccount->acc_name);
 
1913
                        dlg->playerBlackEdit->setReadOnly(true);
 
1914
                        dlg->playerBlackRkEdit->setText(myAccount->get_rank());
 
1915
                        dlg->playerWhiteEdit->setText(opponent);
 
1916
                        dlg->playerWhiteEdit->setReadOnly(false);
 
1917
                        dlg->playerWhiteRkEdit->setText(rk);
 
1918
                }
 
1919
                else
 
1920
                {
 
1921
                        dlg->playerWhiteEdit->setText(myAccount->acc_name);
 
1922
                        dlg->playerWhiteEdit->setReadOnly(true);
 
1923
                        dlg->playerWhiteRkEdit->setText(myAccount->get_rank());
 
1924
                        dlg->playerBlackEdit->setText(opponent);
 
1925
                        dlg->playerBlackEdit->setReadOnly(false);
 
1926
                        dlg->playerBlackRkEdit->setText(rk);
 
1927
                }
 
1928
 
 
1929
                dlg->buttonDecline->setEnabled(true);
 
1930
                dlg->buttonOffer->setText(tr("Accept"));
 
1931
                dlg->buttonCancel->setDisabled(true);
 
1932
                dlg->boardSizeSpin->setValue(size.toInt());
 
1933
                dlg->timeSpin->setValue(time.toInt());
 
1934
                dlg->byoTimeSpin->setValue(byotime.toInt());
 
1935
        }
 
1936
 
 
1937
        dlg->slot_changed();
 
1938
        dlg->show();
 
1939
        dlg->setActiveWindow();
 
1940
        dlg->raise();
 
1941
}
 
1942
 
 
1943
// result of player popup
 
1944
void ClientWindow::slot_playerPopup(int i)
 
1945
{
 
1946
        if (!lv_popupPlayer)
 
1947
        {
 
1948
                qWarning("*** programming error - no item selected");
 
1949
                return;
 
1950
        }
 
1951
 
 
1952
  // some invited players on IGS get a * after their name
 
1953
  QString player_name = (lv_popupPlayer->text(1).right(1) == "*" ? lv_popupPlayer->text(1).left( lv_popupPlayer->text(1).length() -1 ):lv_popupPlayer->text(1));
 
1954
  
 
1955
  
 
1956
        switch (i)
 
1957
        {
 
1958
                case 1:
 
1959
                        // match
 
1960
                        slot_matchrequest(player_name + " " + lv_popupPlayer->text(2), true);
 
1961
                        break;
 
1962
 
 
1963
                case 2:
 
1964
                case 3:
 
1965
                        // talk and stats at the same time
 
1966
                        slot_talk(player_name, 0, true);
 
1967
                        //slot_sendcommand("stats " + lv_popupPlayer->text(1), false);
 
1968
                        break;
 
1969
 
 
1970
                //case 3:
 
1971
                        // stats
 
1972
                        //slot_sendcommand("stats " + lv_popupPlayer->text(1), false);
 
1973
                        //break;
 
1974
 
 
1975
                case 4:
 
1976
                        // stored games
 
1977
                        slot_sendcommand("stored " + player_name, false);
 
1978
                        break;
 
1979
 
 
1980
                case 5:
 
1981
                        // results
 
1982
                        slot_sendcommand("result " + player_name, false);
 
1983
                        break;
 
1984
 
 
1985
                case 6:
 
1986
                {
 
1987
                        // toggle watch list
 
1988
                        QString cpy = ";" + setting->readEntry("WATCH").simplifyWhiteSpace() + ";";
 
1989
                        QString line;
 
1990
                        QString name;
 
1991
                        bool found = false;
 
1992
                        int cnt = cpy.contains(';') + 1;
 
1993
                        for (int i = 0; i < cnt; i++)
 
1994
                        {
 
1995
                                name = element(cpy, i, ";");
 
1996
                                if (name)
 
1997
                                {
 
1998
                                        if (name == lv_popupPlayer->text(1))
 
1999
                                                // skip player if found
 
2000
                                                found = true;
 
2001
                                        else
 
2002
                                                line += name + ";";
 
2003
                                }
 
2004
                        }
 
2005
 
 
2006
                        if (!found)
 
2007
                        {
 
2008
                                // not found -> add to list
 
2009
                                line += lv_popupPlayer->text(1);
 
2010
                                // update player list
 
2011
                                if (lv_popupPlayer->text(6) != "M")
 
2012
                                {
 
2013
                                        myAccount->num_watchedplayers++;
 
2014
                                        lv_popupPlayer->setText(6, "W");
 
2015
                                }
 
2016
                        }
 
2017
                        else if (line.length() > 0)
 
2018
                        {
 
2019
                                // skip one ";"
 
2020
                                line.truncate(line.length() - 1);
 
2021
                        }
 
2022
 
 
2023
                        if (found)
 
2024
                        {
 
2025
                                if (lv_popupPlayer->text(6) != "M")
 
2026
                                {
 
2027
                                        myAccount->num_watchedplayers--;
 
2028
                                        lv_popupPlayer->setText(6, "");
 
2029
                                }
 
2030
                        }
 
2031
 
 
2032
                        setting->writeEntry("WATCH", line);
 
2033
 
 
2034
                        lv_popupPlayer->ownRepaint();
 
2035
                        ListView_players->sort();
 
2036
                        statusUsers->setText(" P: " + QString::number(myAccount->num_players) + " / " + QString::number(myAccount->num_watchedplayers) + " ");
 
2037
                }
 
2038
                        break;
 
2039
 
 
2040
                case 7:
 
2041
                        // toggle exclude list
 
2042
                {
 
2043
                        // toggle watch list
 
2044
                        QString cpy = ";" + setting->readEntry("EXCLUDE").simplifyWhiteSpace() + ";";
 
2045
                        QString line;
 
2046
                        QString name;
 
2047
                        bool found = false;
 
2048
                        int cnt = cpy.contains(';') + 1;
 
2049
                        for (int i = 0; i < cnt; i++)
 
2050
                        {
 
2051
                                name = element(cpy, i, ";");
 
2052
                                if (name)
 
2053
                                {
 
2054
                                        if (name == lv_popupPlayer->text(1))
 
2055
                                                // skip player if found
 
2056
                                                found = true;
 
2057
                                        else
 
2058
                                                line += name + ";";
 
2059
                                }
 
2060
                        }
 
2061
 
 
2062
                        if (!found)
 
2063
                        {
 
2064
                                // not found -> add to list
 
2065
                                line += lv_popupPlayer->text(1);
 
2066
                                if (lv_popupPlayer->text(6) != "M")
 
2067
                                        lv_popupPlayer->setText(6, "X");
 
2068
                        }
 
2069
                        else if (line.length() > 0)
 
2070
                        {
 
2071
                                // skip one ";"
 
2072
                                line.truncate(line.length() - 1);
 
2073
                        }
 
2074
 
 
2075
                        if (found)
 
2076
                        {
 
2077
                                if (lv_popupPlayer->text(6) != "M")
 
2078
                                        lv_popupPlayer->setText(6, "");
 
2079
                        }
 
2080
 
 
2081
                        setting->writeEntry("EXCLUDE", line);
 
2082
 
 
2083
                        lv_popupPlayer->ownRepaint();
 
2084
                        ListView_players->sort();
 
2085
                }
 
2086
                        break;
 
2087
 
 
2088
                case 8:
 
2089
                        // rating
 
2090
                        if (myAccount->get_gsname() == IGS)
 
2091
                                slot_sendcommand("prob " + player_name, false);
 
2092
                        else
 
2093
                                slot_sendcommand("rating " + player_name,false);
 
2094
                        break;
 
2095
 
 
2096
                case 9:
 
2097
                {
 
2098
                        // observe game
 
2099
 
 
2100
                        bool found = false;
 
2101
 
 
2102
                        // emulate mouse click
 
2103
                        QListViewItemIterator lv(ListView_games);
 
2104
                        for (QListViewItem *lvi; lvi = lv.current();)
 
2105
                        {
 
2106
                                // compare game ids
 
2107
                                if (lv_popupPlayer->text(3) == lvi->text(0))
 
2108
                                {
 
2109
                                        // emulate mouse button - doubleclick on games
 
2110
                                        slot_mouse_games(3, lvi, QPoint(), 0);
 
2111
                                        found = true;
 
2112
                                        break;
 
2113
                                }
 
2114
                                lv++;
 
2115
                        }
 
2116
 
 
2117
                        if (!found)
 
2118
                        {
 
2119
                                // if not found -> load new data
 
2120
                                Game g;
 
2121
                                g.nr = lv_popupPlayer->text(3);
 
2122
//                              g.running = true;
 
2123
//                              slot_game(&g);
 
2124
 
 
2125
                                // observe
 
2126
                                if (qgoif->set_observe(g.nr))
 
2127
                                        sendcommand("observe " + g.nr, false);
 
2128
//                              sendcommand("games " + g.nr, false);
 
2129
                        }
 
2130
 
 
2131
                        break;
 
2132
                }
 
2133
 
 
2134
                default:   
 
2135
                        break;
 
2136
        }
 
2137
}
 
2138
 
 
2139
// doubleclick...
 
2140
void ClientWindow::slot_click_players(QListViewItem *lv)
 
2141
{
 
2142
        // emulate right button
 
2143
        slot_mouse_players(3, lv, QPoint(), 0);
 
2144
}
 
2145
// move over ListView
 
2146
/*void ClientWindow::slot_moveOver_players()
 
2147
{
 
2148
        qDebug("move over player list...");
 
2149
} */
 
2150
// mouse menus
 
2151
void ClientWindow::slot_menu_players(QListViewItem *lv, const QPoint& pt, int)
 
2152
{
 
2153
        // emulate right button
 
2154
        slot_mouse_players(2, lv, pt, 0);
 
2155
}
 
2156
// mouse click on ListView_players
 
2157
void ClientWindow::slot_mouse_players(int button, QListViewItem *lv, const QPoint& pt, int /*column*/)
 
2158
{
 
2159
        static QPopupMenu *puw = 0;
 
2160
        
 
2161
        // create popup window
 
2162
        if (!puw)
 
2163
        {
 
2164
                puw = new QPopupMenu(0, 0);
 
2165
                puw->insertItem(tr("match"), this, SLOT(slot_playerPopup(int)), 0, 1);
 
2166
                puw->insertItem(tr("talk"), this, SLOT(slot_playerPopup(int)), 0, 2);
 
2167
                puw->insertSeparator();
 
2168
                puw->insertItem(tr("stats"), this, SLOT(slot_playerPopup(int)), 0, 3);
 
2169
                puw->insertItem(tr("stored games"), this, SLOT(slot_playerPopup(int)), 0, 4);
 
2170
                puw->insertItem(tr("results"), this, SLOT(slot_playerPopup(int)), 0, 5);
 
2171
                puw->insertItem(tr("rating"), this, SLOT(slot_playerPopup(int)), 0, 8);
 
2172
                puw->insertItem(tr("observe game"), this, SLOT(slot_playerPopup(int)), 0, 9);
 
2173
                puw->insertSeparator();
 
2174
                puw->insertItem(tr("toggle watch list"), this, SLOT(slot_playerPopup(int)), 0, 6);
 
2175
                puw->insertItem(tr("toggle exclude list"), this, SLOT(slot_playerPopup(int)), 0, 7);
 
2176
 
 
2177
  }
 
2178
        //puw->hide();
 
2179
 
 
2180
        // do actions if button clicked on item
 
2181
        switch (button)
 
2182
        {
 
2183
                // left button
 
2184
                case 1:
 
2185
                        if (lv)
 
2186
                        {
 
2187
                        }
 
2188
                        break;
 
2189
 
 
2190
                // right button
 
2191
                case 2:
 
2192
                        if (lv)
 
2193
                        {
 
2194
                                /*QRect r = ListView_players->geometry();
 
2195
                                QPoint p = r.topLeft() + pt;
 
2196
                                puw->move(p);
 
2197
                                puw->show();*/
 
2198
                                puw->popup( QCursor::pos() );
 
2199
                                // store selected lv
 
2200
                                lv_popupPlayer = static_cast<PlayerTableItem*>(lv);
 
2201
                        }
 
2202
                        break;
 
2203
 
 
2204
                // first menu item if doubleclick
 
2205
                case 3:
 
2206
                        if (lv)
 
2207
                        {
 
2208
                                // store selected lv
 
2209
                                lv_popupPlayer = static_cast<PlayerTableItem*>(lv);
 
2210
 
 
2211
                                slot_playerPopup(1);
 
2212
                        }
 
2213
                        break;
 
2214
 
 
2215
                default:
 
2216
                        break;
 
2217
        }
 
2218
}
 
2219
 
 
2220
// release Talk Tabs
 
2221
void ClientWindow::slot_pbRelTabs()
 
2222
{
 
2223
        // seek dialog
 
2224
        Talk *dlg = talklist.first();
 
2225
        while (dlg)
 
2226
        {
 
2227
                if (dlg->get_name().find('*') == -1)
 
2228
                {
 
2229
                        TabWidget_mini_2->removePage(dlg->get_tabWidget());
 
2230
                        dlg->pageActive = false;
 
2231
                }
 
2232
                dlg = talklist.next();
 
2233
        }
 
2234
}
 
2235
 
 
2236
// release Talk Tabs
 
2237
void ClientWindow::slot_pbRelOneTab(QWidget *w)
 
2238
{
 
2239
        // seek dialog
 
2240
        Talk *dlg = talklist.first();
 
2241
        while (dlg)
 
2242
        {
 
2243
                if (dlg->get_tabWidget() == w)
 
2244
                {
 
2245
                        TabWidget_mini_2->removePage(w);
 
2246
                        dlg->pageActive = false;
 
2247
                        return;
 
2248
                }
 
2249
                dlg = talklist.next();
 
2250
        }
 
2251
}
 
2252
 
 
2253
 // handle chat boxes in a list
 
2254
void ClientWindow::slot_talk(const QString &name, const QString &text, bool isplayer)
 
2255
{
 
2256
        static Talk *dlg;
 
2257
        QString txt;
 
2258
        bool bonus = false;
 
2259
        bool autoAnswer = true;
 
2260
 
 
2261
        if (text && text != "@@@")
 
2262
                // text given or player logged in
 
2263
                txt = text;
 
2264
        else if (text == "@@@" && isplayer)
 
2265
        {
 
2266
                // player logged out -> iplayer == false
 
2267
                txt = tr("USER NOT LOGGED IN.");
 
2268
                autoAnswer = false;
 
2269
        }
 
2270
        else
 
2271
        {
 
2272
                txt = "";
 
2273
                autoAnswer = false;
 
2274
        }
 
2275
 
 
2276
        // dialog recently used?
 
2277
        if (dlg && dlg->get_name() == name)
 
2278
                dlg->write(txt);
 
2279
        else if (!name.isEmpty() && name != tr("msg*"))
 
2280
        {
 
2281
                // seek dialog
 
2282
                dlg = talklist.first();
 
2283
                while (dlg != NULL && dlg->get_name() != name)
 
2284
                        dlg = talklist.next();
 
2285
 
 
2286
                // not found -> create new dialog
 
2287
                if (!dlg)
 
2288
                {
 
2289
                        talklist.insert(0, new Talk(name, 0, isplayer));     
 
2290
                        dlg = talklist.current();
 
2291
                        connect(dlg, SIGNAL(signal_talkto(QString&, QString&)), this, SLOT(slot_talkto(QString&, QString&)));
 
2292
      connect(dlg, SIGNAL(signal_matchrequest(const QString&,bool)), this, SLOT(slot_matchrequest(const QString&,bool)));
 
2293
      
 
2294
                        // make new multiline field
 
2295
                        //mainTable->TabWidget_mini_2->addTab(dlg->get_tabWidget(), dlg->get_name());
 
2296
      TabWidget_mini_2->addTab(dlg->get_tabWidget(), dlg->get_name());
 
2297
      TabWidget_mini_2->showPage(dlg->get_tabWidget());
 
2298
                        dlg->pageActive = true;
 
2299
                        connect(dlg->get_le(), SIGNAL(returnPressed()), dlg, SLOT(slot_returnPressed()));
 
2300
                        connect(dlg, SIGNAL(signal_pbRelOneTab(QWidget*)), this, SLOT(slot_pbRelOneTab(QWidget*)));
 
2301
 
 
2302
                        QPalette pal = dlg->get_mle()->palette();
 
2303
                        pal.setColor(QColorGroup::Base, setting->colorBackground);
 
2304
                        dlg->get_mle()->setPalette(pal);
 
2305
                        dlg->get_le()->setPalette(pal);
 
2306
 
 
2307
      if (!name.isEmpty() && name != tr("Shouts*") && currentCommand->get_txt() !="stats")
 
2308
        slot_sendcommand("stats " + name, false);    // automatically request stats
 
2309
      
 
2310
                }
 
2311
 
 
2312
                CHECK_PTR(dlg);
 
2313
                dlg->write(txt);
 
2314
 
 
2315
                // play sound on new created dialog
 
2316
                bonus = true;
 
2317
        }
 
2318
 
 
2319
        // check if it was a channel message
 
2320
        if (autoAnswer &= (isplayer && autoAwayMessage && !name.contains('*') && text[0] == '>'))
 
2321
        {
 
2322
                // send when qGo is NOT the active application - TO DO
 
2323
                sendcommand("tell " + name + " [I'm away right now]");
 
2324
        }
 
2325
 
 
2326
        if (!dlg->pageActive)
 
2327
        {
 
2328
          TabWidget_mini_2->addTab(dlg->get_tabWidget(), dlg->get_name());
 
2329
                dlg->pageActive = true;
 
2330
        }
 
2331
 
 
2332
        // play a sound - not for shouts
 
2333
        if ((text[0] == '>' && bonus || !dlg->get_le()->hasFocus()) && !name.contains('*'))
 
2334
        {
 
2335
                qgoif->get_qgo()->playTalkSound();
 
2336
 
 
2337
                // set cursor to last line
 
2338
                //dlg->get_mle()->setCursorPosition(dlg->get_mle()->lines(), 999); //eb16
 
2339
                dlg->get_mle()->append("");                                        //eb16
 
2340
                //dlg->get_mle()->removeParagraph(dlg->get_mle()->paragraphs()-2);   //eb16
 
2341
 
 
2342
                // write time stamp
 
2343
                MultiLineEdit3->append(statusOnlineTime->text() + " " + name + (autoAnswer ? " (A)" : ""));
 
2344
        }
 
2345
        else if (name == tr("msg*"))
 
2346
        {
 
2347
                qgoif->get_qgo()->playTalkSound();
 
2348
 
 
2349
                // set cursor to last line
 
2350
//              dlg->get_mle()->setCursorPosition(dlg->get_mle()->numLines(), 999); //eb16
 
2351
                dlg->get_mle()->append(""); //eb16
 
2352
//              dlg->get_mle()->removeParagraph(dlg->get_mle()->paragraphs()-2);   //eb16
 
2353
 
 
2354
                // write time stamp
 
2355
                MultiLineEdit3->append(tr("Message") + ": " + text);
 
2356
        }
 
2357
}
 
2358
 
 
2359
// talk dialog -> return pressed
 
2360
void ClientWindow::slot_talkto(QString &receiver, QString &txt)
 
2361
{
 
2362
        // echo
 
2363
        if (txt.length())
 
2364
        {
 
2365
                switch (myAccount->get_gsname())
 
2366
                {
 
2367
                        case IGS:
 
2368
                        {
 
2369
                                bool ok;
 
2370
                                // test if it's a number -> channel
 
2371
                                /*int nr =*/ receiver.toInt(&ok);
 
2372
                                if (ok)
 
2373
                                        // yes, channel talk
 
2374
                                        sendcommand("yell " + txt, false);
 
2375
                                else if (receiver.contains('*'))
 
2376
                                        sendcommand("shout " + txt, false);
 
2377
                                else
 
2378
                                        sendcommand("tell " + receiver + " " + txt, false);
 
2379
                        }
 
2380
                                break;
 
2381
 
 
2382
                        default:
 
2383
                                // send tell command w/o echo
 
2384
                                if (receiver.contains('*'))
 
2385
                                        sendcommand("shout " + txt, false);
 
2386
                                else
 
2387
                                        sendcommand("tell " + receiver + " " + txt, false);
 
2388
                                break;
 
2389
                }
 
2390
 
 
2391
                // lokal echo in talk window
 
2392
                slot_talk(receiver, "-> " + txt, true);
 
2393
        }
 
2394
}
 
2395
 
 
2396
// set players to be watched
 
2397
void ClientWindow::slot_watchplayer(const QString &txt)
 
2398
{
 
2399
        if (txt.length() > 0)
 
2400
        {
 
2401
                watch = ";" + txt + ";";
 
2402
        }
 
2403
        else
 
2404
                watch = QString();
 
2405
}
 
2406
 
 
2407
// set players to be excluded
 
2408
void ClientWindow::slot_excludeplayer(const QString &txt)
 
2409
{
 
2410
        if (txt.length() > 0)
 
2411
        {
 
2412
                exclude = ";" + txt + ";";
 
2413
        }
 
2414
        else
 
2415
                exclude = QString();
 
2416
}
 
2417
 
 
2418
// open a local board       ??? Do we need this ?
 
2419
void ClientWindow::slot_localBoard()
 
2420
{
 
2421
        openLocalBoard();
 
2422
}
 
2423
 
 
2424
// open a local board, size 19x19, skip questions
 
2425
void ClientWindow::slot_local19()
 
2426
{
 
2427
        openLocalBoard("/19/");
 
2428
}
 
2429
 
 
2430
// open a local board
 
2431
void ClientWindow::slot_preferences()
 
2432
{
 
2433
        qgoif->openPreferences();
 
2434
}
 
2435
 
 
2436
void ClientWindow::reStoreWindowSize(QString strKey, bool store)
 
2437
{
 
2438
        if (store)
 
2439
        {
 
2440
                // ALT-<num>
 
2441
                setting->writeEntry("CLIENTWINDOW_" + strKey,
 
2442
                        QString::number(pos().x()) + DELIMITER +
 
2443
                        QString::number(pos().y()) + DELIMITER +
 
2444
                        QString::number(size().width()) + DELIMITER +
 
2445
                        QString::number(size().height()));
 
2446
 
 
2447
                setting->writeEntry("CLIENTSPLITTER_" + strKey,
 
2448
                        QString::number(s1->sizes().first()) + DELIMITER +
 
2449
                        QString::number(s1->sizes().last()) + DELIMITER +
 
2450
                        QString::number(s2->sizes().first()) + DELIMITER +
 
2451
                        QString::number(s2->sizes().last()) + DELIMITER +
 
2452
                        QString::number(s3->sizes().first()) + DELIMITER +
 
2453
                        QString::number(s3->sizes().last()));
 
2454
      //QString::number(mainTable->s3->sizes().last()));
 
2455
      
 
2456
                statusBar()->message(tr("Window size saved.") + " (" + strKey + ")");
 
2457
        }
 
2458
        else
 
2459
        {
 
2460
                // restore size of client window
 
2461
                QString s = setting->readEntry("CLIENTWINDOW_" + strKey);
 
2462
                if (s.length() > 5)
 
2463
                {
 
2464
                        QPoint p;
 
2465
                        p.setX(element(s, 0, DELIMITER).toInt());
 
2466
                        p.setY(element(s, 1, DELIMITER).toInt());
 
2467
                        QSize sz;
 
2468
                        sz.setWidth(element(s, 2, DELIMITER).toInt());
 
2469
                        sz.setHeight(element(s, 3, DELIMITER).toInt());
 
2470
                        resize(sz);
 
2471
                        move(p);
 
2472
                }
 
2473
 
 
2474
                // restore splitter in client window
 
2475
                s = setting->readEntry("CLIENTSPLITTER_" + strKey);
 
2476
                if (s.length() > 5)
 
2477
                {
 
2478
                        QValueList<int> w1, h1, w2;
 
2479
                        w1 << element(s, 0, DELIMITER).toInt() << element(s, 1, DELIMITER).toInt();
 
2480
                        h1 << element(s, 2, DELIMITER).toInt() << element(s, 3, DELIMITER).toInt();
 
2481
                        w2 << element(s, 4, DELIMITER).toInt() << element(s, 5, DELIMITER).toInt();
 
2482
                        s1->setSizes(w1);
 
2483
                        s2->setSizes(h1);
 
2484
                        s3->setSizes(w2);
 
2485
                }
 
2486
 
 
2487
                statusBar()->message(tr("Window size restored.") + " (" + strKey + ")");
 
2488
        }
 
2489
}
 
2490
/*
 
2491
// set Cursor to last position
 
2492
void ClientWindow::slot_tabWidgetMainChanged(QWidget *w)
 
2493
{
 
2494
        if (w->child("MultiLineEdit_messages"))
 
2495
        {
 
2496
                MultiLineEdit_messages->setCursorPosition(MultiLineEdit_messages->numLines(), 999);
 
2497
                MultiLineEdit_messages->insertLine("");
 
2498
                MultiLineEdit_messages->removeLine(MultiLineEdit_messages->numLines()-2);
 
2499
                return;
 
2500
        }
 
2501
        if (w->child("MultiLineEdit2"))
 
2502
        {
 
2503
                MultiLineEdit2->setCursorPosition(MultiLineEdit2->numLines(), 999);
 
2504
                MultiLineEdit2->insertLine("");
 
2505
                MultiLineEdit2->removeLine(MultiLineEdit2->numLines()-2);
 
2506
        }
 
2507
}
 
2508
*/
 
2509
bool ClientWindow::eventFilter(QObject *obj, QEvent *ev)
 
2510
{
 
2511
        if (ev->type() == QEvent::KeyPress)
 
2512
        {
 
2513
//qDebug(QString("eventFilter: %1").arg(ev->type()));
 
2514
//qDebug(QString("eventFilter: obj = %1, class = %2, parent = %3").arg(obj->name()).arg(obj->className()).arg(obj->parent() ? obj->parent()->name() : "0"));
 
2515
            QKeyEvent *keyEvent = (QKeyEvent *) ev;
 
2516
            int key = keyEvent->key();
 
2517
 
 
2518
//qDebug(QString("eventFilter: keyPress %1").arg(key));
 
2519
 
 
2520
                if (key >= Key_0 && key <= Key_9)
 
2521
                {
 
2522
//qDebug("eventFilter: keyPress -> 0..9");
 
2523
                        QString strKey = QString::number(key - Key_0);
 
2524
 
 
2525
                        if (obj == cb_cmdLine || obj->parent() && obj->parent() == cb_cmdLine || obj == this)
 
2526
                        {
 
2527
                                if (keyEvent->state() & AltButton)
 
2528
                                {
 
2529
qDebug("eventFilter: keyPress -> Alt + 0..9");
 
2530
                                        // store sizes
 
2531
                                        reStoreWindowSize(strKey, true);
 
2532
                                        return true;
 
2533
                                }
 
2534
                                else if (keyEvent->state() & ControlButton)
 
2535
                                {
 
2536
qDebug("eventFilter: keyPress -> Control + 0..9");
 
2537
                                        // restore sizes
 
2538
                                        reStoreWindowSize(strKey, false);
 
2539
                                        return true;
 
2540
                                }
 
2541
                        }
 
2542
                }
 
2543
                else if (key == Key_F1)
 
2544
                {
 
2545
                        // help
 
2546
                        qgoif->get_qgo()->openManual();
 
2547
                }
 
2548
        }
 
2549
 
 
2550
        return false;
 
2551
}
 
2552
 
 
2553
/*
 
2554
void ClientWindow::keyReleaseEvent(QKeyEvent *e)
 
2555
{
 
2556
        if (!(e->state() & AltButton || e->state() & ControlButton))
 
2557
        {
 
2558
                // release Keyboard
 
2559
                releaseKeyboard();
 
2560
        }
 
2561
}
 
2562
*/
 
2563
 
 
2564
// key pressed
 
2565
void ClientWindow::keyPressEvent(QKeyEvent *e)
 
2566
{
 
2567
/*
 
2568
        if (e->state() & AltButton && e->state() & ControlButton)
 
2569
        {
 
2570
                // AltGr Key
 
2571
//              releaseKeyboard();
 
2572
        }
 
2573
        else if (e->state() & AltButton || e->state() & ControlButton)
 
2574
        {
 
2575
                // get all keystrokes until both alt and control button release
 
2576
//              grabKeyboard();
 
2577
        }
 
2578
 
 
2579
        // check for window resize command = number button
 
2580
        if (e->key() >= Key_0 && e->key() <= Key_9)
 
2581
        {
 
2582
                QString strKey = QString::number(e->key() - Key_0);
 
2583
 
 
2584
                if (e->state() & AltButton)
 
2585
                {
 
2586
                        // store sizes
 
2587
                        reStoreWindowSize(strKey, true);
 
2588
                }
 
2589
                else if (e->state() & ControlButton)
 
2590
                {
 
2591
                        // restore sizes
 
2592
                        reStoreWindowSize(strKey, false);
 
2593
                }
 
2594
/*
 
2595
                // cut last digit from cb_cmdLine
 
2596
                if (e->state() & ControlButton || e->state() & AltButton)
 
2597
                {
 
2598
                        QString tmpTxt = cb_cmdLine->currentText();
 
2599
                        tmpTxt.truncate(tmpTxt.length() - 1);
 
2600
                        cb_cmdLine->changeItem(tmpTxt, cb_cmdLine->currentItem());
 
2601
                }
 
2602
 
 
2603
                e->accept();
 
2604
                return;
 
2605
        }
 
2606
*/
 
2607
        switch (e->key())
 
2608
        {
 
2609
                case Key_Up:  // Scroll up in history
 
2610
                        qDebug("UP");
 
2611
/*                      if (historyCounter > 0)
 
2612
                                historyCounter --;
 
2613
                        if (historyCounter > historyList->count())
 
2614
                                historyCounter = historyList->count();
 
2615
                        LineEdit1->setText(historyList->operator[](historyCounter));
 
2616
*/                      break;
 
2617
 
 
2618
                case Key_Down:  // Scroll down in history
 
2619
                        qDebug("DOWN");
 
2620
/*                      historyCounter ++;
 
2621
                        if (historyCounter > historyList->count())
 
2622
                                historyCounter = historyList->count();
 
2623
                        LineEdit1->setText(historyList->operator[](historyCounter));
 
2624
*/                      break;
 
2625
 
 
2626
                case Key_PageUp:
 
2627
                        qDebug("PAGE UP");
 
2628
                        // TODO: pageUp/pageDown are protected.  :(
 
2629
                        // MultiLineEdit1->pageUp(); 
 
2630
                        break;
 
2631
 
 
2632
                case Key_PageDown:
 
2633
                        qDebug("PAGE DOWN");
 
2634
                        // MultiLineEdit1->pageDown();
 
2635
                        break;
 
2636
 
 
2637
                case Key_F1:
 
2638
                        // help
 
2639
                        qgoif->get_qgo()->openManual();
 
2640
                        break;
 
2641
 
 
2642
                case Key_Escape:
 
2643
                        cb_cmdLine->setFocus();
 
2644
                        cb_cmdLine->setCurrentItem(0);
 
2645
                        break;
 
2646
 
 
2647
                default:
 
2648
                        e->ignore();
 
2649
                        break;
 
2650
        }
 
2651
        e->accept();
 
2652
 
2653
 
 
2654
 
 
2655
void ClientWindow::initmenus(QWidget *parent)                              
 
2656
 
2657
}
 
2658
 
 
2659
void ClientWindow::initActions()
 
2660
{
 
2661
 
 
2662
// signals and slots connections
 
2663
        connect( cb_cmdLine, SIGNAL( activated(int) ), this, SLOT( slot_cmdactivated_int(int) ) );
 
2664
        connect( cb_cmdLine, SIGNAL( activated(const QString&) ), this, SLOT( slot_cmdactivated(const QString&) ) );
 
2665
 
 
2666
        QWhatsThis::add(ListView_games, tr("Table of games\n\n"
 
2667
                "right click to observe\n\n"
 
2668
                "Symbol explanation: (click on tab to sort by)\n"
 
2669
                "Id\tgame number\n"
 
2670
                "White/WR\twhite player's name and rank\n"
 
2671
                "Black/BR\tblack player's name and rank\n"
 
2672
                "Mv\tnumber of moves at last refresh\n"
 
2673
                "Sz\tboard size\n"
 
2674
                "H\thandicap\n"
 
2675
                "K\tkomi\n"
 
2676
                "By\tbyoyomi time\n"
 
2677
                "FR\tfree (FI), rated (I) or teach (TI) game\n"
 
2678
                "(Ob)\tnumber of observers at last refresh\n\n"
 
2679
                "This table can be updated by 'Refresh games'"));
 
2680
 
 
2681
        QWhatsThis::add(ListView_players, tr("Table of players\n\n"
 
2682
                "right click for menu\n\n"
 
2683
                "Symbol explanation: (click on tab to sort by)\n"
 
2684
                "Stat\tplayer's stats:\n"
 
2685
                "\tX...close\n"
 
2686
                "\t!...looking = wants to play a game\n"
 
2687
                "\tQ...quiet = doesn't receive system messages\n"
 
2688
                "\tS...shout = can't receive shouts\n"
 
2689
                "\t??...unknown - player entered after last table update\n"
 
2690
                "name\tplayer's name\n"
 
2691
                "Rk\tplayer's rank\n"
 
2692
                "pl\tplaying game (only one game visible)\n"
 
2693
                "ob\tobserving game (only one game visible)\n"
 
2694
                "Idle\tidle time\n"
 
2695
                "X\tprivate info:\n"
 
2696
                "\tM..me\n"
 
2697
                "\tX..excluded from shout\n"
 
2698
                "\tW..watched (sort: X entries, then Rk)\n"
 
2699
                "and, if extended player info (Toolbox) is active (IGS only):\n"
 
2700
                "Info\tplayer's info string\n"
 
2701
                "Won\tnumber of games won by player\n"
 
2702
                "Lost\tnumber of games lost by player\n"
 
2703
                "Country\torigin of player (from e-mail address)\n"
 
2704
                "Lang\tpreferred language\n\n"
 
2705
                "This table can be updated by 'Refresh players'\n\n"
 
2706
                "Menu entries (right click):\n"
 
2707
                "match\trequest for match (dialog arises)\n"
 
2708
                "talk\ttalk to player (tab arises)\n"
 
2709
                "----\n"
 
2710
                "stats\t\tshow player's stats\n"
 
2711
                "stored games\tshow stored games\n"
 
2712
                "results\t\tshow results\n"
 
2713
                "rating\t\tshow rating (NNGS/IGS only)\n"
 
2714
                "observe game\tshow game currently played by player\n"
 
2715
                "----\n"
 
2716
                "toggle watch list\t\tput/remove player to/from watch list - make 'W' entry at 'X' column; entry/leave sounds are activated\n"
 
2717
                "toggle exclude list\tsimilar to watch - make 'X' entry; player's shouts are no longer shown"));
 
2718
 
 
2719
 
 
2720
        /*
 
2721
        * Menu File
 
2722
        */
 
2723
        connect(fileNewBoard, SIGNAL(activated()), this, SLOT(slotFileNewBoard()));
 
2724
        connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNewGame()));
 
2725
        connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
 
2726
        connect(computerPlay, SIGNAL(activated()), this, SLOT(slotComputerPlay()));
 
2727
        connect(fileQuit, SIGNAL(activated()), this, SLOT(quit()));
 
2728
 
 
2729
        /*
 
2730
        * Menu Connexion
 
2731
        */
 
2732
        connect(Connect, SIGNAL(activated()), this, SLOT(slotMenuConnect()));
 
2733
        connect(Disconnect, SIGNAL(activated()), this, SLOT(slotMenuDisconnect()));
 
2734
        Disconnect->setEnabled(false);
 
2735
        connect(editServers, SIGNAL(activated()), this, SLOT(slotMenuEditServers()));
 
2736
  
 
2737
        /*
 
2738
        * Menu Settings
 
2739
        */
 
2740
        connect(setPreferences, SIGNAL(activated()), this, SLOT(slot_preferences()));
 
2741
 
 
2742
        /*
 
2743
        * Menu View
 
2744
        */
 
2745
        connect(viewToolBar, SIGNAL(toggled(bool)), this, SLOT(slotViewToolBar(bool)));
 
2746
  connect(viewUserToolBar, SIGNAL(toggled(bool)), this, SLOT(slotViewUserToolBar(bool)));
 
2747
        connect(viewMenuBar, SIGNAL(toggled(bool)), this, SLOT(slotViewMenuBar(bool)));
 
2748
        viewStatusBar->setWhatsThis(tr("Statusbar\n\nEnables/disables the statusbar."));
 
2749
        connect(viewStatusBar, SIGNAL(toggled(bool)), this, SLOT(slotViewStatusBar(bool)));
 
2750
        
 
2751
        /*
 
2752
        * Menu Help
 
2753
        */
 
2754
        connect(helpManual, SIGNAL(activated()), this, SLOT(slotHelpManual()));
 
2755
        connect(helpSoundInfo, SIGNAL(activated()), this, SLOT(slotHelpSoundInfo()));
 
2756
        connect(helpAboutApp, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
 
2757
        connect(helpAboutQt, SIGNAL(activated()), this, SLOT(slotHelpAboutQt()));
 
2758
}
 
2759
  
 
2760
void ClientWindow::initToolBar()
 
2761
{
 
2762
 
 
2763
        QToolButton *tb;
 
2764
 
 
2765
 
 
2766
        connect( cb_connect, SIGNAL( activated(const QString&) ), this, SLOT( slot_cbconnect(const QString&) ) );
 
2767
 
 
2768
//  toolConnect->setText(tr("Connect with") + " " + cb_connect->currentText()); 
 
2769
        connect( toolConnect, SIGNAL( toggled(bool) ), this, SLOT( slot_connect(bool) ) );  //end add eb 5
 
2770
  
 
2771
    
 
2772
        QIconSet  OIC,OIC2 ;//= new QIconSet;
 
2773
 
 
2774
  
 
2775
        OIC.setPixmap ( NotOpenIcon, QIconSet::Automatic, QIconSet::Normal, QIconSet::Off);
 
2776
        OIC.setPixmap ( OpenIcon, QIconSet::Automatic, QIconSet::Normal, QIconSet::On );
 
2777
 
 
2778
        setOpenMode->setIconSet(OIC);
 
2779
 
 
2780
 
 
2781
        OIC2.setPixmap (NotLookingIcon, QIconSet::Automatic, QIconSet::Normal, QIconSet::Off);
 
2782
        OIC2.setPixmap (LookingIcon, QIconSet::Automatic, QIconSet::Normal, QIconSet::On );
 
2783
        setLookingMode->setIconSet(OIC2);
 
2784
  
 
2785
 
 
2786
        OIC.setPixmap ( NotQuietIcon, QIconSet::Automatic, QIconSet::Normal, QIconSet::Off);
 
2787
        OIC.setPixmap ( QuietIcon, QIconSet::Automatic, QIconSet::Normal, QIconSet::On);
 
2788
        setQuietMode->setIconSet(OIC);
 
2789
  
 
2790
        tb = QWhatsThis::whatsThisButton(Toolbar);
 
2791
        //tb->setProperty( "geometry", QRect(0, 0, 20, 20));
 
2792
 
 
2793
        //added the icons
 
2794
        refreshPlayers->setIconSet(QIconSet::QIconSet(RefreshPlayersIcon));
 
2795
        refreshGames->setIconSet(QIconSet::QIconSet(RefreshGamesIcon));
 
2796
        fileNew->setIconSet(QIconSet::QIconSet(fileNewIcon));
 
2797
        fileNewBoard->setIconSet(QIconSet::QIconSet(fileNewboardIcon));
 
2798
        fileOpen->setIconSet(QIconSet::QIconSet(fileOpenIcon));
 
2799
        fileQuit->setIconSet(QIconSet::QIconSet(exitIcon));
 
2800
        computerPlay->setIconSet(QIconSet::QIconSet(ComputerPlayIcon));
 
2801
        Connect->setIconSet(QIconSet::QIconSet(connectedIcon));
 
2802
        Disconnect->setIconSet(QIconSet::QIconSet(disconnectedIcon));
 
2803
        helpManual->setIconSet(QIconSet::QIconSet(manualIcon));
 
2804
        setPreferences->setIconSet(QIconSet::QIconSet(prefsIcon));
 
2805
        setIcon(qgoIcon);
 
2806
 
 
2807
  UserToolbar->show();
 
2808
    
 
2809
}
 
2810
// SLOTS
 
2811
 
 
2812
 
 
2813
void ClientWindow::slotHelpManual()
 
2814
{
 
2815
        setting->qgo->openManual();
 
2816
}
 
2817
 
 
2818
void ClientWindow::slotHelpSoundInfo()
 
2819
{
 
2820
        // show info
 
2821
        setting->qgo->testSound(true);
 
2822
}
 
2823
 
 
2824
void ClientWindow::slotHelpAbout()
 
2825
{
 
2826
        setting->qgo->slotHelpAbout();
 
2827
}
 
2828
 
 
2829
void ClientWindow::slotHelpAboutQt()
 
2830
{
 
2831
        QMessageBox::aboutQt(this);
 
2832
}
 
2833
 
 
2834
void ClientWindow::slotFileNewBoard()
 
2835
{
 
2836
        setting->qgo->addBoardWindow();
 
2837
}
 
2838
 
 
2839
void ClientWindow::slotFileNewGame()
 
2840
{   
 
2841
  MainWindow *w = setting->qgo->addBoardWindow() ;
 
2842
        w->slotFileNewGame();
 
2843
}
 
2844
 
 
2845
void ClientWindow::slotFileOpen()
 
2846
{
 
2847
        //if (!checkModified())
 
2848
        //      return;
 
2849
        QString fileName(QFileDialog::getOpenFileName(setting->readEntry("LAST_DIR"),
 
2850
                tr("SGF Files (*.sgf);;MGT Files (*.mgt);;XML Files (*.xml);;All Files (*)"), this));
 
2851
        if (fileName.isEmpty())
 
2852
                return;
 
2853
 
 
2854
        MainWindow *w = setting->qgo->addBoardWindow() ; 
 
2855
        w->doOpen(fileName, w->getFileExtension(fileName));
 
2856
}
 
2857
 
 
2858
void ClientWindow::slotComputerPlay()
 
2859
{
 
2860
        QString s =  setting->readEntry("COMPUTER_PATH");
 
2861
 
 
2862
        if (setting->readEntry("COMPUTER_PATH").isNull() ||
 
2863
        setting->readEntry("COMPUTER_PATH").isEmpty())
 
2864
        {
 
2865
                QMessageBox::warning(this, PACKAGE, tr("You did not set the Computer program path !"));
 
2866
                qgoif->openPreferences(3);
 
2867
                return;
 
2868
        }
 
2869
 
 
2870
        QNewGameDlg * dlg = new QNewGameDlg(this);
 
2871
        if(!(dlg->exec()== QDialog::Accepted))
 
2872
                return;
 
2873
 
 
2874
        emit signal_computer_game(dlg);
 
2875
}
 
2876
 
 
2877
 
 
2878
void ClientWindow::slotMenuConnect()
 
2879
{
 
2880
        // push button
 
2881
        toolConnect->toggle();             //SL added eb 5
 
2882
}    
 
2883
 
 
2884
void ClientWindow::slotMenuDisconnect()
 
2885
{
 
2886
        // push button
 
2887
        toolConnect->toggle();              //SL added eb 5
 
2888
}
 
2889
 
 
2890
void ClientWindow::slotMenuEditServers()
 
2891
{
 
2892
        qgoif->openPreferences(4);
 
2893
 
2894
 
 
2895
void ClientWindow::slotViewStatusBar(bool toggle)
 
2896
{
 
2897
        if (!toggle)
 
2898
                statusBar()->hide();
 
2899
        else
 
2900
                statusBar()->show();
 
2901
 
 
2902
        setting->writeBoolEntry("MAINSTATUSBAR", toggle);
 
2903
 
 
2904
        statusBar()->message(tr("Ready."));
 
2905
}
 
2906
 
 
2907
void ClientWindow::slotViewMenuBar(bool toggle)
 
2908
{
 
2909
        if (!toggle)
 
2910
                menuBar->hide();
 
2911
        else
 
2912
                menuBar->show();
 
2913
 
 
2914
        setting->writeBoolEntry("MAINMENUBAR", toggle);
 
2915
 
 
2916
        statusBar()->message(tr("Ready."));
 
2917
}
 
2918
 
 
2919
void ClientWindow::slotViewToolBar(bool toggle)  
 
2920
{
 
2921
        if (!toggle)
 
2922
                Toolbar->hide();
 
2923
        else
 
2924
                Toolbar->show();
 
2925
 
 
2926
        setting->writeBoolEntry("MAINTOOLBAR", toggle);
 
2927
 
 
2928
        statusBar()->message(tr("Ready."));
 
2929
}
 
2930
 
 
2931
void ClientWindow::slotViewUserToolBar(bool toggle)
 
2932
{
 
2933
        if (!toggle)
 
2934
                UserToolbar->hide();
 
2935
        else
 
2936
                UserToolbar->show();
 
2937
 
 
2938
        setting->writeBoolEntry("USERTOOLBAR", toggle);
 
2939
 
 
2940
        statusBar()->message(tr("Ready."));
 
2941
}
 
2942
 
 
2943
 
 
2944
 
 
2945
void ClientWindow::slotUserButtonClicked(int i)
 
2946
{
 
2947
  slot_toolbaractivated(userButtonGroup->find(i)->caption());
 
2948
}  
 
2949
 
 
2950
void ClientWindow::slot_statsPlayer(Player *p)
 
2951
{
 
2952
         Talk *dlg;
 
2953
  
 
2954
  if (!p->name.isEmpty())
 
2955
          {
 
2956
                // seek dialog
 
2957
                  dlg = talklist.first();
 
2958
                  while (dlg != NULL && dlg->get_name() != p->name)
 
2959
                        dlg = talklist.next();
 
2960
 
 
2961
                //  found 
 
2962
                if (dlg)
 
2963
        {
 
2964
         dlg->stats_rating->setText(p->rank);
 
2965
         dlg->stats_info->setText(p->info);
 
2966
         dlg->stats_default->setText(p->extInfo);
 
2967
         dlg->stats_wins->setText(p->won);
 
2968
         dlg->stats_loss->setText(p->lost );
 
2969
         dlg->stats_country->setText(p->country);
 
2970
         dlg->stats_playing->setText(p->play_str);
 
2971
         dlg->stats_rated->setText(p->rated);
 
2972
         dlg->stats_address->setText(p->address);
 
2973
         
 
2974
         // stored either idle time or last access       
 
2975
         dlg->stats_idle->setText(p->idle);
 
2976
        dlg->Label_Idle->setText(p->idle.at(0).isDigit() ? "Idle :": "Last log :");
 
2977
 
 
2978
         
 
2979
        }   
 
2980
    }
 
2981
 
 
2982
 
 
2983
  
 
2984
}  
 
2985