6
#include "helpviewer.h"
8
#include "mainwindow.h"
12
#include <qmessagebox.h>
15
#include <qmessagebox.h>
16
#include <qlineedit.h>
19
#include <CoreFoundation/CFString.h>
20
#include <CoreFoundation/CFBundle.h>
23
qGo::qGo() : QObject()
25
boardList = new QPtrList<MainWindow>;
26
boardList->setAutoDelete(false);
55
emit signal_leave_qgo();
57
if ((check = checkModified()) == 1 ||
59
!QMessageBox::warning(0, PACKAGE,
60
tr("At least one board is modified.\n"
61
"If you exit the application now, all changes will be lost!"
63
tr("Yes"), tr("No"), QString::null,
67
qDebug("Program quits now...");
70
// emit signal_leave_qgo();
73
MainWindow* qGo::addBoardWindow(MainWindow *w)
77
qWarning("*** BOARD HAS NO PARENT");
78
w = new MainWindow(0, PACKAGE);
79
w->getInterfaceHandler()->toggleMode();
80
w->getInterfaceHandler()->toggleMode();
88
void qGo::removeBoardWindow(MainWindow *w)
92
qWarning("qGo::removeBoardWindow(QWidget *w) - paramter w is 0!");
96
if (!boardList->removeRef(w))
97
qWarning("Failed to remove board from list.");
100
void qGo::openManual()
102
if (helpViewer == NULL)
103
helpViewer = new HelpViewer(0, "helpviewer");
109
int qGo::checkModified()
111
// Just closed the last board?
112
if (boardList->isEmpty())
115
// One board, same as closing a single window
116
if (boardList->count() == 1)
117
return ((MainWindow*)(boardList->first()))->checkModified(true);
119
// Several boards. Check if one is modified.
121
for (b=boardList->first(); b != 0; b=boardList->next())
122
if (!((MainWindow*)b)->checkModified(false))
128
void qGo::updateAllBoardSettings()
130
for (QWidget *w=boardList->first(); w != 0; w=boardList->next())
131
((MainWindow*)w)->updateBoard();
134
void qGo::updateFont()
136
for (QWidget *w=boardList->first(); w != 0; w=boardList->next())
137
((MainWindow*)w)->updateFont();
139
emit signal_updateFont();
142
bool qGo::testSound(bool showmsg)
144
// qDebug("qGo::testSound()");
146
// Sound system supported?
147
if (!QSound::available())
152
QMessageBox::information(0, PACKAGE, tr("No sound available."));
155
#elif defined (Q_OS_MACX)
156
QMessageBox::information(0, PACKAGE, tr("No sound available. Qt on Mac uses QuickTime sound."));
158
QMessageBox::information(0, PACKAGE, tr("You are not running the Network Audio sytem.\n"
159
"If you have the `au' command, run it in the background before this program. The latest release of the Network Audio System can be obtained from:\n\n"
160
"ftp.ncd.com:/pub/ncd/technology/src/nas\n"
161
"ftp.x.org:/contrib/audio/nas\n\n"
162
"Release 1.2 of NAS is also included with the X11R6 contrib distribution. After installing NAS, you will then need to reconfigure Qt with NAS sound support.\n\n"
163
"Nevertheless, if you have oss, sound should be working and directed to /dev/dsp"));
169
QMessageBox::information(0, PACKAGE, tr("Sound available."));
173
// qDebug("Sound available, checking for sound files...");
175
// Sound files found?
178
ASSERT(setting->program_dir);
181
list << applicationPath + "/sounds"
182
<< setting->program_dir + "/sounds"
183
<< "C:/Program Files/qGo/sounds"
184
<< "D:/Program Files/qGo/sounds"
185
<< "E:/Program Files/qGo/sounds"
186
<< "C:/Programme/qGo/sounds"
187
<< "D:/Programme/qGo/sounds"
188
<< "E:/Programme/qGo/sounds"
190
#elif defined(Q_OS_MACX)
191
//get the bundle path and find our resources like sounds
192
CFURLRef bundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
193
CFStringRef bundlePath = CFURLCopyFileSystemPath(bundleRef, kCFURLPOSIXPathStyle);
194
list << (QString)CFStringGetCStringPtr(bundlePath, CFStringGetSystemEncoding())
195
+ "/Contents/Resources";
197
list << setting->program_dir + "/sounds"
198
<< "./share/" PACKAGE "/sounds"
199
<< "/usr/share/" PACKAGE "/sounds"
200
<< "/usr/local/share/" PACKAGE "/sounds"
203
<< "./src/sounds"; //SL added eb 7
206
for (QStringList::Iterator it = list.begin(); it != list.end(); ++it)
211
QString s = (QString)(*it);
212
s.append("/stone.wav");
213
if (QFile::exists(s))
214
clickSound = new QSound(s);
216
qDebug("stone.wav not found...");
219
s.append("/talk.wav");
220
if (QFile::exists(s))
221
talkSound = new QSound(s);
223
qDebug("talk.wav not found...");
226
s.append("/match.wav");
227
if (QFile::exists(s))
228
matchSound = new QSound(s);
230
qDebug("match.wav not found...");
233
s.append("/pass.wav");
234
if (QFile::exists(s))
235
passSound = new QSound(s);
237
qDebug("pass.wav not found...");
240
s.append("/gameend.wav");
241
if (QFile::exists(s))
242
gameEndSound = new QSound(s);
244
qDebug("gameend.wav not found...");
247
s.append("/tictoc.wav");
248
if (QFile::exists(s))
249
timeSound = new QSound(s);
251
qDebug("tictoc.wav not found...");
254
s.append("/say.wav");
255
if (QFile::exists(s))
256
saySound = new QSound(s);
258
qDebug("say.wav not found...");
261
s.append("/enter.wav");
262
if (QFile::exists(s))
263
enterSound = new QSound(s);
265
qDebug("enter.wav not found...");
268
s.append("/leave.wav");
269
if (QFile::exists(s))
270
leaveSound = new QSound(s);
272
qDebug("leave.wav not found...");
275
s.append("/connect.wav");
276
if (QFile::exists(s))
277
connectSound = new QSound(s);
279
qDebug("connect.wav not found...");
281
// QMessageBox::information(0, "SOUND OK", s);
282
// qDebug("Sound Ok. Soundfile: %s", s.latin1());
284
if (!applicationPath)
285
applicationPath = s.left(s.find("/sounds"));
286
// QMessageBox::information(0, "SAVING", applicationPath);
293
QMessageBox::information(0, PACKAGE, tr("No sound files in bundle, strange.\n"));
294
#elif ! defined(Q_WS_WIN)
295
QMessageBox::information(0, PACKAGE, tr("Sound files not found.") + "\n" +
296
tr("Please check for the directories") + " /usr/local/share/" + PACKAGE + "/sounds/ " + tr("or") +
297
" /usr/share/" + PACKAGE + "/sounds/, " + tr("depending on your installation."));
300
if (applicationPath = setting->readEntry("PATH_SOUND"))
301
return testSound(false);
303
QMessageBox::information(0, PACKAGE, tr("Sound files not found.") + "\n" +
304
tr("You can navigate to the main qGo directory (for example:") + " C:\\Program Files\\" + PACKAGE + " .\n" +
305
tr("If the directory was given correctly, this data will be saved and you won't"
306
"be asked\nanymore except you install qGo again into a different directory.\n"
307
"To abort this procedure, click 'Cancel' in the following dialog."));
309
applicationPath = QFileDialog::getExistingDirectory(NULL, NULL, "appdir", tr("qGo directory"), true);
311
if (applicationPath.isNull() || applicationPath.isEmpty())
313
QMessageBox::warning(0, PACKAGE, tr("No valid directory was given. Sound is not available."));
318
setting->writeEntry("PATH_SOUND", applicationPath);
320
// QMessageBox::information(0, "TRYING AGAIN", applicationPath);
321
return testSound(false);
326
void qGo::playClick()
328
if (setting->readBoolEntry("SOUND_STONE") && clickSound)
331
if (!clickSound->isAvailable())
332
play(clickSound->fileName().latin1());
339
void qGo::playAutoPlayClick()
341
if (setting->readBoolEntry("SOUND_AUTOPLAY") && clickSound)
344
if (!clickSound->isAvailable())
345
play(clickSound->fileName().latin1());
352
void qGo::playTalkSound()
354
if (setting->readBoolEntry("SOUND_TALK") && talkSound)
357
if (!talkSound->isAvailable())
358
play(talkSound->fileName().latin1());
365
void qGo::playMatchSound()
367
if (setting->readBoolEntry("SOUND_MATCH") && matchSound)
370
if (!matchSound->isAvailable())
371
play(matchSound->fileName().latin1());
378
void qGo::playPassSound()
380
if (setting->readBoolEntry("SOUND_PASS") && passSound)
383
if (!passSound->isAvailable())
384
play(passSound->fileName().latin1());
391
void qGo::playGameEndSound()
393
if (setting->readBoolEntry("SOUND_GAMEEND") && gameEndSound)
396
if (!gameEndSound->isAvailable())
397
play(gameEndSound->fileName().latin1());
400
gameEndSound->play();
404
void qGo::playTimeSound()
406
if (setting->readBoolEntry("SOUND_TIME") && timeSound)
409
if (!timeSound->isAvailable())
410
play(timeSound->fileName().latin1());
417
void qGo::playSaySound()
419
if (setting->readBoolEntry("SOUND_SAY") && saySound)
422
if (!saySound->isAvailable())
423
play(saySound->fileName().latin1());
430
void qGo::playEnterSound()
432
if (setting->readBoolEntry("SOUND_ENTER") && enterSound)
435
if (!enterSound->isAvailable())
436
play(enterSound->fileName().latin1());
443
void qGo::playLeaveSound()
445
if (setting->readBoolEntry("SOUND_LEAVE") && leaveSound)
448
if (!leaveSound->isAvailable())
449
play(leaveSound->fileName().latin1());
456
void qGo::playConnectSound()
460
if (setting->readBoolEntry("SOUND_CONNECT") && connectSound)
463
if (!connectSound->isAvailable())
464
play(connectSound->fileName().latin1());
467
connectSound->play();
471
void qGo::playDisConnectSound()
473
if (setting->readBoolEntry("SOUND_DISCONNECT") && connectSound)
476
if (!connectSound->isAvailable())
477
play(connectSound->fileName().latin1());
480
connectSound->play();
484
void qGo::slotHelpAbout()
486
QString txt = PACKAGE " " VERSION
487
"\n\nCopyright (c) 2001-2004\nPeter Strempel <pstrempel@t-online.de>\nJohannes Mesa <frosla@gmx.at>\nEmmanuel Beranger <e2@beranger.com.fr>\n\n" +
488
tr("GTP code from Goliath, thanks to:") + "\nPALM Thomas\nDINTILHAC Florian\nHIVERT Anthony\nPIOC Sebastien";
490
QString translation = tr("English translation by:\nPeter Strempel\nJohannes Mesa\nEmmanuel Beranger", "Please set your own language and your name! Use your own language!");
491
if (translation != "English translation by:\nPeter Strempel\nJohannes Mesa\nEmmanuel Beranger")
492
txt += "\n\n" + translation;
494
QMessageBox::about(0, tr("About..."), txt);