summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/dictionary/dictionary.pro14
-rw-r--r--noncore/apps/dictionary/dicttool.cpp59
-rw-r--r--noncore/apps/dictionary/dicttool.h46
-rw-r--r--noncore/apps/dictionary/dicttoolbase.ui412
-rw-r--r--noncore/apps/dictionary/main.cpp31
-rw-r--r--noncore/apps/tableviewer/.cvsignore5
-rw-r--r--noncore/apps/tableviewer/Makefile.in330
-rw-r--r--noncore/apps/tableviewer/README29
-rw-r--r--noncore/apps/tableviewer/browsekeyentry.cpp242
-rw-r--r--noncore/apps/tableviewer/db.xmlt6279
-rw-r--r--noncore/apps/tableviewer/db/.cvsignore3
-rw-r--r--noncore/apps/tableviewer/db/common.cpp1470
-rw-r--r--noncore/apps/tableviewer/db/common.h285
-rw-r--r--noncore/apps/tableviewer/db/csvsource.cpp207
-rw-r--r--noncore/apps/tableviewer/db/csvsource.h53
-rw-r--r--noncore/apps/tableviewer/db/datacache.cpp293
-rw-r--r--noncore/apps/tableviewer/db/datacache.h130
-rw-r--r--noncore/apps/tableviewer/db/xmlsource.cpp295
-rw-r--r--noncore/apps/tableviewer/db/xmlsource.h119
-rw-r--r--noncore/apps/tableviewer/keyentry.cw55
-rw-r--r--noncore/apps/tableviewer/main.cpp32
-rw-r--r--noncore/apps/tableviewer/qpe-tableviewer.control10
-rw-r--r--noncore/apps/tableviewer/tableviewer.cpp455
-rw-r--r--noncore/apps/tableviewer/tableviewer.h109
-rw-r--r--noncore/apps/tableviewer/tableviewer.pro36
-rw-r--r--noncore/apps/tableviewer/ui/.cvsignore8
-rw-r--r--noncore/apps/tableviewer/ui/browsekeyentry.cpp206
-rw-r--r--noncore/apps/tableviewer/ui/browsekeyentry.h75
-rw-r--r--noncore/apps/tableviewer/ui/commonwidgets.cpp209
-rw-r--r--noncore/apps/tableviewer/ui/commonwidgets.h98
-rw-r--r--noncore/apps/tableviewer/ui/filterkeyentry.cpp208
-rw-r--r--noncore/apps/tableviewer/ui/filterkeyentry.h96
-rw-r--r--noncore/apps/tableviewer/ui/tvbrowseview.cpp122
-rw-r--r--noncore/apps/tableviewer/ui/tvbrowseview.h55
-rw-r--r--noncore/apps/tableviewer/ui/tveditview.cpp235
-rw-r--r--noncore/apps/tableviewer/ui/tveditview.h62
-rw-r--r--noncore/apps/tableviewer/ui/tvfilterview.cpp304
-rw-r--r--noncore/apps/tableviewer/ui/tvfilterview.h88
-rw-r--r--noncore/apps/tableviewer/ui/tvkeyedit.cpp254
-rw-r--r--noncore/apps/tableviewer/ui/tvkeyedit.h56
-rw-r--r--noncore/apps/tableviewer/ui/tvkeyedit_gen.ui239
-rw-r--r--noncore/apps/tableviewer/ui/tvlistview.cpp315
-rw-r--r--noncore/apps/tableviewer/ui/tvlistview.h92
-rw-r--r--noncore/comm/keypebble/.cvsignore5
-rw-r--r--noncore/comm/keypebble/LICENSE.GPL286
-rw-r--r--noncore/comm/keypebble/Makefile.in286
-rw-r--r--noncore/comm/keypebble/README.html206
-rw-r--r--noncore/comm/keypebble/d3des.c439
-rw-r--r--noncore/comm/keypebble/d3des.h50
-rw-r--r--noncore/comm/keypebble/keypebble.pro38
-rw-r--r--noncore/comm/keypebble/krfbbuffer.cpp163
-rw-r--r--noncore/comm/keypebble/krfbbuffer.h62
-rw-r--r--noncore/comm/keypebble/krfbcanvas.cpp169
-rw-r--r--noncore/comm/keypebble/krfbcanvas.h54
-rw-r--r--noncore/comm/keypebble/krfbconnection.cpp242
-rw-r--r--noncore/comm/keypebble/krfbconnection.h152
-rw-r--r--noncore/comm/keypebble/krfbdecoder.cpp839
-rw-r--r--noncore/comm/keypebble/krfbdecoder.h134
-rw-r--r--noncore/comm/keypebble/krfblogin.cpp255
-rw-r--r--noncore/comm/keypebble/krfblogin.h62
-rw-r--r--noncore/comm/keypebble/krfboptions.cpp52
-rw-r--r--noncore/comm/keypebble/krfboptions.h31
-rw-r--r--noncore/comm/keypebble/krfbserverinfo.h42
-rw-r--r--noncore/comm/keypebble/kvnc.cpp191
-rw-r--r--noncore/comm/keypebble/kvnc.h56
-rw-r--r--noncore/comm/keypebble/kvncconnectdlg.cpp79
-rw-r--r--noncore/comm/keypebble/kvncconnectdlg.h39
-rw-r--r--noncore/comm/keypebble/kvncoptionsdlg.cpp53
-rw-r--r--noncore/comm/keypebble/kvncoptionsdlg.h30
-rw-r--r--noncore/comm/keypebble/main.cpp18
-rw-r--r--noncore/comm/keypebble/qpe-keypebble.control10
-rw-r--r--noncore/comm/keypebble/vncauth.c160
-rw-r--r--noncore/comm/keypebble/vncauth.h30
-rw-r--r--noncore/comm/keypebble/vncoptionsbase.ui270
-rw-r--r--noncore/games/chess/Makefile.in134
-rw-r--r--noncore/games/chess/boardview.cw23
-rw-r--r--noncore/games/chess/chess.cpp358
-rw-r--r--noncore/games/chess/chess.db2
-rw-r--r--noncore/games/chess/chess.h128
-rw-r--r--noncore/games/chess/chess.pro14
-rw-r--r--noncore/games/chess/main.cpp51
-rw-r--r--noncore/games/chess/mainwindow.ui220
-rw-r--r--noncore/games/chess/pieces.pngbin0 -> 5696 bytes
-rw-r--r--noncore/games/chess/qpe-chess.control9
-rw-r--r--noncore/games/chess/simple-l.pngbin0 -> 16143 bytes
-rw-r--r--noncore/games/fifteen/.cvsignore2
-rw-r--r--noncore/games/fifteen/Makefile.in118
-rw-r--r--noncore/games/fifteen/fifteen.cpp364
-rw-r--r--noncore/games/fifteen/fifteen.h83
-rw-r--r--noncore/games/fifteen/fifteen.pro10
-rw-r--r--noncore/games/fifteen/main.cpp33
-rw-r--r--noncore/games/fifteen/qpe-fifteen.control11
-rw-r--r--noncore/games/go/.cvsignore2
-rw-r--r--noncore/games/go/Makefile.in158
-rw-r--r--noncore/games/go/README3
-rw-r--r--noncore/games/go/README.AMIGO42
-rw-r--r--noncore/games/go/README.XAMIGO26
-rw-r--r--noncore/games/go/amigo.c656
-rw-r--r--noncore/games/go/amigo.h146
-rw-r--r--noncore/games/go/go.h81
-rw-r--r--noncore/games/go/go.pro19
-rw-r--r--noncore/games/go/goplayer.c1499
-rw-r--r--noncore/games/go/goplayutils.c1317
-rw-r--r--noncore/games/go/goplayutils.h85
-rw-r--r--noncore/games/go/gowidget.cpp449
-rw-r--r--noncore/games/go/gowidget.h111
-rw-r--r--noncore/games/go/killable.c373
-rw-r--r--noncore/games/go/main.cpp35
-rw-r--r--noncore/games/go/qpe-go.control9
-rw-r--r--noncore/games/mindbreaker/.cvsignore4
-rw-r--r--noncore/games/mindbreaker/Makefile.in117
-rw-r--r--noncore/games/mindbreaker/main.cpp35
-rw-r--r--noncore/games/mindbreaker/mindbreaker.cpp818
-rw-r--r--noncore/games/mindbreaker/mindbreaker.h122
-rw-r--r--noncore/games/mindbreaker/mindbreaker.pro12
-rw-r--r--noncore/games/mindbreaker/qpe-mindbreaker.control9
-rw-r--r--noncore/games/minesweep/.cvsignore2
-rw-r--r--noncore/games/minesweep/Makefile.in134
-rw-r--r--noncore/games/minesweep/main.cpp34
-rw-r--r--noncore/games/minesweep/minefield.cpp623
-rw-r--r--noncore/games/minesweep/minefield.h87
-rw-r--r--noncore/games/minesweep/minesweep.cpp390
-rw-r--r--noncore/games/minesweep/minesweep.h67
-rw-r--r--noncore/games/minesweep/minesweep.pro14
-rw-r--r--noncore/games/minesweep/qpe-minesweep.control9
-rw-r--r--noncore/games/parashoot/.cvsignore3
-rw-r--r--noncore/games/parashoot/Makefile.in203
-rw-r--r--noncore/games/parashoot/base.cpp71
-rw-r--r--noncore/games/parashoot/base.h38
-rw-r--r--noncore/games/parashoot/bullet.cpp142
-rw-r--r--noncore/games/parashoot/bullet.h51
-rw-r--r--noncore/games/parashoot/cannon.cpp140
-rw-r--r--noncore/games/parashoot/cannon.h58
-rw-r--r--noncore/games/parashoot/codes.h25
-rw-r--r--noncore/games/parashoot/helicopter.cpp114
-rw-r--r--noncore/games/parashoot/helicopter.h45
-rw-r--r--noncore/games/parashoot/interface.cpp247
-rw-r--r--noncore/games/parashoot/interface.h79
-rw-r--r--noncore/games/parashoot/main.cpp36
-rw-r--r--noncore/games/parashoot/man.cpp174
-rw-r--r--noncore/games/parashoot/man.h52
-rw-r--r--noncore/games/parashoot/parashoot.pro11
-rw-r--r--noncore/games/parashoot/qpe-parashoot.control9
-rw-r--r--noncore/games/qasteroids/.cvsignore2
-rw-r--r--noncore/games/qasteroids/Makefile.in155
-rw-r--r--noncore/games/qasteroids/ledmeter.cpp135
-rw-r--r--noncore/games/qasteroids/ledmeter.h72
-rw-r--r--noncore/games/qasteroids/main.cpp36
-rw-r--r--noncore/games/qasteroids/qasteroids.pro11
-rw-r--r--noncore/games/qasteroids/qpe-qasteroids.control9
-rw-r--r--noncore/games/qasteroids/sprites.h147
-rw-r--r--noncore/games/qasteroids/toplevel.cpp514
-rw-r--r--noncore/games/qasteroids/toplevel.h99
-rw-r--r--noncore/games/qasteroids/view.cpp884
-rw-r--r--noncore/games/qasteroids/view.h156
-rw-r--r--noncore/games/snake/.cvsignore3
-rw-r--r--noncore/games/snake/Makefile.in159
-rw-r--r--noncore/games/snake/codes.h20
-rw-r--r--noncore/games/snake/interface.cpp224
-rw-r--r--noncore/games/snake/interface.h69
-rw-r--r--noncore/games/snake/main.cpp35
-rw-r--r--noncore/games/snake/obstacle.cpp51
-rw-r--r--noncore/games/snake/obstacle.h30
-rw-r--r--noncore/games/snake/qpe-snake.control9
-rw-r--r--noncore/games/snake/snake.cpp246
-rw-r--r--noncore/games/snake/snake.h64
-rw-r--r--noncore/games/snake/snake.pro11
-rw-r--r--noncore/games/snake/target.cpp77
-rw-r--r--noncore/games/snake/target.h37
-rw-r--r--noncore/games/solitaire/.cvsignore3
-rw-r--r--noncore/games/solitaire/Makefile.in235
-rw-r--r--noncore/games/solitaire/canvascard.cpp282
-rw-r--r--noncore/games/solitaire/canvascard.h82
-rw-r--r--noncore/games/solitaire/canvascardgame.cpp380
-rw-r--r--noncore/games/solitaire/canvascardgame.h95
-rw-r--r--noncore/games/solitaire/canvascardwindow.cpp227
-rw-r--r--noncore/games/solitaire/canvascardwindow.h70
-rw-r--r--noncore/games/solitaire/canvasshapes.cpp92
-rw-r--r--noncore/games/solitaire/canvasshapes.h55
-rw-r--r--noncore/games/solitaire/card.cpp53
-rw-r--r--noncore/games/solitaire/card.h84
-rw-r--r--noncore/games/solitaire/carddeck.cpp81
-rw-r--r--noncore/games/solitaire/carddeck.h49
-rw-r--r--noncore/games/solitaire/cardgame.cpp35
-rw-r--r--noncore/games/solitaire/cardgame.h45
-rw-r--r--noncore/games/solitaire/cardgamelayout.cpp61
-rw-r--r--noncore/games/solitaire/cardgamelayout.h42
-rw-r--r--noncore/games/solitaire/cardpile.cpp114
-rw-r--r--noncore/games/solitaire/cardpile.h101
-rw-r--r--noncore/games/solitaire/freecellcardgame.cpp137
-rw-r--r--noncore/games/solitaire/freecellcardgame.h152
-rw-r--r--noncore/games/solitaire/main.cpp36
-rw-r--r--noncore/games/solitaire/patiencecardgame.cpp234
-rw-r--r--noncore/games/solitaire/patiencecardgame.h206
-rw-r--r--noncore/games/solitaire/qpe-solitaire.control9
-rwxr-xr-xnoncore/games/solitaire/solitaire.pro18
-rw-r--r--noncore/games/tetrix/.cvsignore3
-rw-r--r--noncore/games/tetrix/Makefile.in157
-rw-r--r--noncore/games/tetrix/gtetrix.cpp514
-rw-r--r--noncore/games/tetrix/gtetrix.h104
-rw-r--r--noncore/games/tetrix/main.cpp33
-rw-r--r--noncore/games/tetrix/qpe-tetrix.control10
-rw-r--r--noncore/games/tetrix/qtetrix.cpp170
-rw-r--r--noncore/games/tetrix/qtetrix.h78
-rw-r--r--noncore/games/tetrix/qtetrixb.cpp251
-rw-r--r--noncore/games/tetrix/qtetrixb.h80
-rw-r--r--noncore/games/tetrix/tetrix.pro17
-rw-r--r--noncore/games/tetrix/tpiece.cpp201
-rw-r--r--noncore/games/tetrix/tpiece.h62
-rw-r--r--noncore/games/wordgame/.cvsignore6
-rw-r--r--noncore/games/wordgame/Makefile.in168
-rwxr-xr-xnoncore/games/wordgame/calcdist27
-rw-r--r--noncore/games/wordgame/main.cpp34
-rw-r--r--noncore/games/wordgame/newgamebase.ui337
-rw-r--r--noncore/games/wordgame/qpe-wordgame.control10
-rw-r--r--noncore/games/wordgame/rulesbase.ui274
-rw-r--r--noncore/games/wordgame/wordgame.cpp1476
-rw-r--r--noncore/games/wordgame/wordgame.h376
-rw-r--r--noncore/games/wordgame/wordgame.pro13
-rw-r--r--noncore/multimedia/showimg/.cvsignore2
-rw-r--r--noncore/multimedia/showimg/Makefile.in119
-rw-r--r--noncore/multimedia/showimg/README14
-rw-r--r--noncore/multimedia/showimg/main.cpp33
-rw-r--r--noncore/multimedia/showimg/qpe-showimg.control10
-rw-r--r--noncore/multimedia/showimg/showimg.cpp557
-rw-r--r--noncore/multimedia/showimg/showimg.h143
-rw-r--r--noncore/multimedia/showimg/showimg.pro19
-rw-r--r--noncore/settings/.cvsignore13
-rw-r--r--noncore/settings/language/.cvsignore4
-rw-r--r--noncore/settings/language/Makefile.in135
-rw-r--r--noncore/settings/language/language.cpp150
-rw-r--r--noncore/settings/language/language.pro12
-rw-r--r--noncore/settings/language/languagesettingsbase.ui51
-rw-r--r--noncore/settings/language/main.cpp36
-rw-r--r--noncore/settings/language/qpe-language.control9
-rw-r--r--noncore/settings/language/settings.h58
-rw-r--r--noncore/settings/sound/.cvsignore5
-rw-r--r--noncore/settings/sound/Makefile.in135
-rw-r--r--noncore/settings/sound/main.cpp36
-rw-r--r--noncore/settings/sound/qpe-sound.control10
-rw-r--r--noncore/settings/sound/sound.pro10
-rw-r--r--noncore/settings/sound/soundsettings.cpp64
-rw-r--r--noncore/settings/sound/soundsettings.h44
-rw-r--r--noncore/settings/sound/soundsettingsbase.ui281
-rw-r--r--noncore/settings/sysinfo/.cvsignore3
-rw-r--r--noncore/settings/sysinfo/Makefile.in193
-rw-r--r--noncore/settings/sysinfo/graph.cpp183
-rw-r--r--noncore/settings/sysinfo/graph.h89
-rw-r--r--noncore/settings/sysinfo/load.cpp207
-rw-r--r--noncore/settings/sysinfo/load.h60
-rw-r--r--noncore/settings/sysinfo/main.cpp34
-rw-r--r--noncore/settings/sysinfo/memory.cpp94
-rw-r--r--noncore/settings/sysinfo/memory.h48
-rw-r--r--noncore/settings/sysinfo/qpe-sysinfo.control9
-rw-r--r--noncore/settings/sysinfo/storage.cpp220
-rw-r--r--noncore/settings/sysinfo/storage.h87
-rw-r--r--noncore/settings/sysinfo/sysinfo.cpp53
-rw-r--r--noncore/settings/sysinfo/sysinfo.h29
-rw-r--r--noncore/settings/sysinfo/sysinfo.pro25
-rw-r--r--noncore/settings/sysinfo/versioninfo.cpp109
-rw-r--r--noncore/settings/sysinfo/versioninfo.h34
-rw-r--r--noncore/tools/calc2/Makefile138
-rw-r--r--noncore/tools/calc2/binary/Makefile146
-rw-r--r--noncore/tools/calc2/binary/README1
-rw-r--r--noncore/tools/calc2/binary/binary.pro16
-rw-r--r--noncore/tools/calc2/binary/binary.ui177
-rw-r--r--noncore/tools/calc2/binary/binaryfactory.cpp51
-rw-r--r--noncore/tools/calc2/binary/binaryfactory.h46
-rw-r--r--noncore/tools/calc2/binary/binaryimpl.cpp110
-rw-r--r--noncore/tools/calc2/binary/binaryimpl.h50
-rw-r--r--noncore/tools/calc2/calc.cpp104
-rw-r--r--noncore/tools/calc2/calc.h69
-rw-r--r--noncore/tools/calc2/calc.pro11
-rw-r--r--noncore/tools/calc2/engine.cpp214
-rw-r--r--noncore/tools/calc2/engine.h111
-rw-r--r--noncore/tools/calc2/instruction.h69
-rw-r--r--noncore/tools/calc2/main.cpp34
-rw-r--r--noncore/tools/calc2/plugininterface.h45
-rw-r--r--noncore/tools/calc2/simple/README1
-rw-r--r--noncore/tools/calc2/simple/simple.pro14
-rw-r--r--noncore/tools/calc2/simple/simple.ui704
-rw-r--r--noncore/tools/calc2/simple/simplefactory.cpp51
-rw-r--r--noncore/tools/calc2/simple/simplefactory.h46
-rw-r--r--noncore/tools/calc2/simple/simpleimpl.cpp120
-rw-r--r--noncore/tools/calc2/simple/simpleimpl.h65
-rw-r--r--noncore/tools/calc2/stdinstructions.h125
-rw-r--r--noncore/tools/calculator/.cvsignore4
-rw-r--r--noncore/tools/calculator/Makefile.in139
-rw-r--r--noncore/tools/calculator/calculator.pro13
-rw-r--r--noncore/tools/calculator/calculator.ui1026
-rw-r--r--noncore/tools/calculator/calculatorimpl.cpp601
-rw-r--r--noncore/tools/calculator/calculatorimpl.h135
-rw-r--r--noncore/tools/calculator/main.cpp35
-rw-r--r--noncore/tools/calculator/qpe-calculator.control10
-rw-r--r--noncore/tools/clock/.cvsignore2
-rw-r--r--noncore/tools/clock/Makefile.in118
-rw-r--r--noncore/tools/clock/clock.cpp319
-rw-r--r--noncore/tools/clock/clock.h87
-rw-r--r--noncore/tools/clock/clock.pro13
-rw-r--r--noncore/tools/clock/main.cpp34
-rw-r--r--noncore/tools/clock/qpe-clock.control9
-rw-r--r--noncore/unsupported/filebrowser/.cvsignore2
-rw-r--r--noncore/unsupported/filebrowser/Makefile.in136
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.cpp850
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.h141
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.pro12
-rw-r--r--noncore/unsupported/filebrowser/inlineedit.cpp30
-rw-r--r--noncore/unsupported/filebrowser/inlineedit.h39
-rw-r--r--noncore/unsupported/filebrowser/main.cpp41
-rw-r--r--noncore/unsupported/filebrowser/qpe-filebrowser.control9
-rw-r--r--noncore/unsupported/oipkg/.cvsignore10
-rw-r--r--noncore/unsupported/oipkg/Makefile.in203
-rw-r--r--noncore/unsupported/oipkg/ipkg/available2256
-rw-r--r--noncore/unsupported/oipkg/ipkg/status418
-rw-r--r--noncore/unsupported/oipkg/main.cpp33
-rw-r--r--noncore/unsupported/oipkg/packagemanager.cpp897
-rw-r--r--noncore/unsupported/oipkg/packagemanager.h94
-rw-r--r--noncore/unsupported/oipkg/packagemanagerbase.ui268
-rw-r--r--noncore/unsupported/oipkg/pkdesc.ui96
-rw-r--r--noncore/unsupported/oipkg/pkfind.ui51
-rw-r--r--noncore/unsupported/oipkg/pksettings.ui176
-rw-r--r--noncore/unsupported/oipkg/qipkg.pro13
-rw-r--r--noncore/unsupported/oipkg/qpe-qipkg.control9
323 files changed, 53678 insertions, 0 deletions
diff --git a/noncore/apps/dictionary/dictionary.pro b/noncore/apps/dictionary/dictionary.pro
new file mode 100644
index 0000000..e829e68
--- a/dev/null
+++ b/noncore/apps/dictionary/dictionary.pro
@@ -0,0 +1,14 @@
1 TEMPLATE= app
2 CONFIG += qt warn_on release
3 DESTDIR = ../bin
4
5 HEADERS= dicttool.h
6 SOURCES= dicttool.cpp main.cpp
7
8 INTERFACES= dicttoolbase.ui
9
10INCLUDEPATH += $(QPEDIR)/include
11 DEPENDPATH+= $(QPEDIR)/include
12LIBS += -lqpe
13
14 TARGET = dictionary
diff --git a/noncore/apps/dictionary/dicttool.cpp b/noncore/apps/dictionary/dicttool.cpp
new file mode 100644
index 0000000..a0f2f9d
--- a/dev/null
+++ b/noncore/apps/dictionary/dicttool.cpp
@@ -0,0 +1,59 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "dicttool.h"
21#include "global.h"
22#include <qstringlist.h>
23#include <qlineedit.h>
24
25DictTool::DictTool( QWidget* parent, const char* name, bool modal, WFlags fl )
26 : DictToolBase( parent, name, modal, fl )
27{
28}
29
30DictTool::~DictTool()
31{
32}
33
34void DictTool::setDictionary(int d)
35{
36 dict = (DictType)d;
37}
38
39void DictTool::setPattern(const QString& s)
40{
41 qWarning( "DictTool::setPattern(const QString&) not yet implemented!" );
42}
43
44void DictTool::setPickboardSet(const QString& s)
45{
46 QStringList sets = QStringList::split(" ",s);
47 qWarning( "DictTool::setPickboardSet(const QString&) not yet implemented!" );
48}
49
50void DictTool::addWord()
51{
52 Global::addWords(word->text());
53}
54
55void DictTool::removeWord()
56{
57 qWarning( "DictTool::removeWord() not yet implemented!" );
58}
59
diff --git a/noncore/apps/dictionary/dicttool.h b/noncore/apps/dictionary/dicttool.h
new file mode 100644
index 0000000..702b772
--- a/dev/null
+++ b/noncore/apps/dictionary/dicttool.h
@@ -0,0 +1,46 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef DICTTOOL_H
21#define DICTTOOL_H
22#include "dicttoolbase.h"
23
24class DictTool : public DictToolBase
25{
26 Q_OBJECT
27
28public:
29 DictTool( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
30 ~DictTool();
31
32public slots:
33 void setDictionary(int);
34 void setPattern(const QString&);
35 void setPickboardSet(const QString&);
36
37private slots:
38 void addWord();
39 void removeWord();
40
41private:
42 enum DictType { All, Local, System };
43 DictType dict;
44};
45
46#endif // DICTTOOL_H
diff --git a/noncore/apps/dictionary/dicttoolbase.ui b/noncore/apps/dictionary/dicttoolbase.ui
new file mode 100644
index 0000000..25ef00e
--- a/dev/null
+++ b/noncore/apps/dictionary/dicttoolbase.ui
@@ -0,0 +1,412 @@
1<!DOCTYPE UI><UI>
2<class>DictToolBase</class><comment>*********************************************************************
3** Copyright (C) 2000 Trolltech AS. All rights reserved.
4**
5** This file is part of Qtopia Environment.
6**
7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file.
11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16**
17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you.
19**
20*********************************************************************</comment>
21<widget>
22 <class>QDialog</class>
23 <property stdset="1">
24 <name>name</name>
25 <cstring>dicttoolbase</cstring>
26 </property>
27 <property stdset="1">
28 <name>geometry</name>
29 <rect>
30 <x>0</x>
31 <y>0</y>
32 <width>258</width>
33 <height>375</height>
34 </rect>
35 </property>
36 <property stdset="1">
37 <name>caption</name>
38 <string>MyDialog1</string>
39 </property>
40 <property stdset="1">
41 <name>sizeGripEnabled</name>
42 <bool>true</bool>
43 </property>
44 <property>
45 <name>layoutMargin</name>
46 </property>
47 <property>
48 <name>layoutSpacing</name>
49 </property>
50 <vbox>
51 <property stdset="1">
52 <name>margin</name>
53 <number>5</number>
54 </property>
55 <property stdset="1">
56 <name>spacing</name>
57 <number>2</number>
58 </property>
59 <widget>
60 <class>QComboBox</class>
61 <item>
62 <property>
63 <name>text</name>
64 <string>All dictionaries</string>
65 </property>
66 </item>
67 <item>
68 <property>
69 <name>text</name>
70 <string>Personal dictionary</string>
71 </property>
72 </item>
73 <item>
74 <property>
75 <name>text</name>
76 <string>System dictionary (English)</string>
77 </property>
78 </item>
79 <property stdset="1">
80 <name>name</name>
81 <cstring>dictionary_choice</cstring>
82 </property>
83 <property>
84 <name>whatsThis</name>
85 <string>Selects the dictionary to manipulate.</string>
86 </property>
87 </widget>
88 <widget>
89 <class>QTabWidget</class>
90 <property stdset="1">
91 <name>name</name>
92 <cstring>tabWidget</cstring>
93 </property>
94 <property>
95 <name>layoutMargin</name>
96 </property>
97 <widget>
98 <class>QWidget</class>
99 <property stdset="1">
100 <name>name</name>
101 <cstring>Widget4</cstring>
102 </property>
103 <attribute>
104 <name>title</name>
105 <string>Search</string>
106 </attribute>
107 <vbox>
108 <property stdset="1">
109 <name>margin</name>
110 <number>5</number>
111 </property>
112 <property stdset="1">
113 <name>spacing</name>
114 <number>6</number>
115 </property>
116 <widget>
117 <class>QGroupBox</class>
118 <property stdset="1">
119 <name>name</name>
120 <cstring>GroupBox3</cstring>
121 </property>
122 <property stdset="1">
123 <name>title</name>
124 <string>Pattern</string>
125 </property>
126 <vbox>
127 <property stdset="1">
128 <name>margin</name>
129 <number>11</number>
130 </property>
131 <property stdset="1">
132 <name>spacing</name>
133 <number>6</number>
134 </property>
135 <widget>
136 <class>QLineEdit</class>
137 <property stdset="1">
138 <name>name</name>
139 <cstring>pattern</cstring>
140 </property>
141 <property>
142 <name>whatsThis</name>
143 <string>Enter your search pattern here. You may use &lt;big&gt;&lt;tt&gt;?&lt;/tt&gt;&lt;/big&gt; to represent any one letter, &lt;big&gt;&lt;tt&gt;*&lt;/tt&gt;&lt;/big&gt; to represent zero or more arbitrary letters, or &lt;big&gt;&lt;tt&gt;[&lt;i&gt;abc&lt;/i&gt;]&lt;/tt&gt;&lt;/big&gt; to represent any one of the letters &lt;big&gt;&lt;tt&gt;&lt;i&gt;abc&lt;/i&gt;&lt;/tt&gt;&lt;/big&gt;.</string>
144 </property>
145 </widget>
146 </vbox>
147 </widget>
148 <widget>
149 <class>QGroupBox</class>
150 <property stdset="1">
151 <name>name</name>
152 <cstring>GroupBox4</cstring>
153 </property>
154 <property stdset="1">
155 <name>title</name>
156 <string>Matches</string>
157 </property>
158 <vbox>
159 <property stdset="1">
160 <name>margin</name>
161 <number>11</number>
162 </property>
163 <property stdset="1">
164 <name>spacing</name>
165 <number>6</number>
166 </property>
167 <widget>
168 <class>QListBox</class>
169 <property stdset="1">
170 <name>name</name>
171 <cstring>output</cstring>
172 </property>
173 </widget>
174 </vbox>
175 </widget>
176 </vbox>
177 </widget>
178 <widget>
179 <class>QWidget</class>
180 <property stdset="1">
181 <name>name</name>
182 <cstring>Widget5</cstring>
183 </property>
184 <attribute>
185 <name>title</name>
186 <string>Pickboard</string>
187 </attribute>
188 <vbox>
189 <property stdset="1">
190 <name>margin</name>
191 <number>5</number>
192 </property>
193 <property stdset="1">
194 <name>spacing</name>
195 <number>6</number>
196 </property>
197 <widget>
198 <class>QGroupBox</class>
199 <property stdset="1">
200 <name>name</name>
201 <cstring>GroupBox1</cstring>
202 </property>
203 <property stdset="1">
204 <name>title</name>
205 <string>Letter sets</string>
206 </property>
207 <vbox>
208 <property stdset="1">
209 <name>margin</name>
210 <number>11</number>
211 </property>
212 <property stdset="1">
213 <name>spacing</name>
214 <number>6</number>
215 </property>
216 <widget>
217 <class>QLineEdit</class>
218 <property stdset="1">
219 <name>name</name>
220 <cstring>sets</cstring>
221 </property>
222 <property>
223 <name>whatsThis</name>
224 <string>Enter sets of letters here, seperated by spaces in the same way as the sets of letters appear at the bottom of the Pickboard. The list below will show the largest sets of words that could be typed ambiguously. This information helps you tune the letter sets for your dictionary.</string>
225 </property>
226 </widget>
227 </vbox>
228 </widget>
229 <widget>
230 <class>QGroupBox</class>
231 <property stdset="1">
232 <name>name</name>
233 <cstring>GroupBox2</cstring>
234 </property>
235 <property stdset="1">
236 <name>title</name>
237 <string>Longest ambiguities</string>
238 </property>
239 <vbox>
240 <property stdset="1">
241 <name>margin</name>
242 <number>11</number>
243 </property>
244 <property stdset="1">
245 <name>spacing</name>
246 <number>6</number>
247 </property>
248 <widget>
249 <class>QListBox</class>
250 <property stdset="1">
251 <name>name</name>
252 <cstring>ambiguities</cstring>
253 </property>
254 </widget>
255 </vbox>
256 </widget>
257 </vbox>
258 </widget>
259 <widget>
260 <class>QWidget</class>
261 <property stdset="1">
262 <name>name</name>
263 <cstring>tab</cstring>
264 </property>
265 <attribute>
266 <name>title</name>
267 <string>Edit words</string>
268 </attribute>
269 <vbox>
270 <property stdset="1">
271 <name>margin</name>
272 <number>11</number>
273 </property>
274 <property stdset="1">
275 <name>spacing</name>
276 <number>6</number>
277 </property>
278 <widget>
279 <class>QLineEdit</class>
280 <property stdset="1">
281 <name>name</name>
282 <cstring>word</cstring>
283 </property>
284 </widget>
285 <widget>
286 <class>QLayoutWidget</class>
287 <property stdset="1">
288 <name>name</name>
289 <cstring>Layout3</cstring>
290 </property>
291 <hbox>
292 <property stdset="1">
293 <name>margin</name>
294 <number>0</number>
295 </property>
296 <property stdset="1">
297 <name>spacing</name>
298 <number>6</number>
299 </property>
300 <widget>
301 <class>QPushButton</class>
302 <property stdset="1">
303 <name>name</name>
304 <cstring>add</cstring>
305 </property>
306 <property stdset="1">
307 <name>text</name>
308 <string>Add</string>
309 </property>
310 </widget>
311 <widget>
312 <class>QPushButton</class>
313 <property stdset="1">
314 <name>name</name>
315 <cstring>remove</cstring>
316 </property>
317 <property stdset="1">
318 <name>text</name>
319 <string>Remove</string>
320 </property>
321 </widget>
322 </hbox>
323 </widget>
324 <widget>
325 <class>QLabel</class>
326 <property stdset="1">
327 <name>name</name>
328 <cstring>readonly_message</cstring>
329 </property>
330 <property stdset="1">
331 <name>text</name>
332 <string>This dictionary is read-only.</string>
333 </property>
334 <property stdset="1">
335 <name>alignment</name>
336 <set>AlignCenter</set>
337 </property>
338 <property>
339 <name>hAlign</name>
340 </property>
341 </widget>
342 <spacer>
343 <property>
344 <name>name</name>
345 <cstring>Spacer1</cstring>
346 </property>
347 <property stdset="1">
348 <name>orientation</name>
349 <enum>Vertical</enum>
350 </property>
351 <property stdset="1">
352 <name>sizeType</name>
353 <enum>Expanding</enum>
354 </property>
355 <property>
356 <name>sizeHint</name>
357 <size>
358 <width>20</width>
359 <height>20</height>
360 </size>
361 </property>
362 <property>
363 <name>sizeHint</name>
364 <size>
365 <width>20</width>
366 <height>20</height>
367 </size>
368 </property>
369 </spacer>
370 </vbox>
371 </widget>
372 </widget>
373 </vbox>
374</widget>
375<connections>
376 <connection>
377 <sender>pattern</sender>
378 <signal>textChanged(const QString&amp;)</signal>
379 <receiver>dicttoolbase</receiver>
380 <slot>setPattern(const QString&amp;)</slot>
381 </connection>
382 <connection>
383 <sender>dictionary_choice</sender>
384 <signal>activated(int)</signal>
385 <receiver>dicttoolbase</receiver>
386 <slot>setDictionary(int)</slot>
387 </connection>
388 <connection>
389 <sender>sets</sender>
390 <signal>textChanged(const QString&amp;)</signal>
391 <receiver>dicttoolbase</receiver>
392 <slot>setPickboardSet(const QString&amp;)</slot>
393 </connection>
394 <connection>
395 <sender>add</sender>
396 <signal>clicked()</signal>
397 <receiver>dicttoolbase</receiver>
398 <slot>addWord()</slot>
399 </connection>
400 <connection>
401 <sender>remove</sender>
402 <signal>clicked()</signal>
403 <receiver>dicttoolbase</receiver>
404 <slot>removeWord()</slot>
405 </connection>
406 <slot access="protected">addWord()</slot>
407 <slot access="protected">removeWord()</slot>
408 <slot access="public">setDictionary(int)</slot>
409 <slot access="public">setPattern(const QString&amp;)</slot>
410 <slot access="public">setPickboardSet(const QString&amp;)</slot>
411</connections>
412</UI>
diff --git a/noncore/apps/dictionary/main.cpp b/noncore/apps/dictionary/main.cpp
new file mode 100644
index 0000000..7e9d8c1
--- a/dev/null
+++ b/noncore/apps/dictionary/main.cpp
@@ -0,0 +1,31 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qpeapplication.h>
21#include "dicttool.h"
22
23main(int argc, char** argv)
24{
25 QPEApplication a(argc,argv);
26
27 DictTool m;
28 a.showMainWidget(&m);
29
30 return a.exec();
31}
diff --git a/noncore/apps/tableviewer/.cvsignore b/noncore/apps/tableviewer/.cvsignore
new file mode 100644
index 0000000..93eb983
--- a/dev/null
+++ b/noncore/apps/tableviewer/.cvsignore
@@ -0,0 +1,5 @@
1moc_*
2Makefile
3tvbrowseview_gen.h
4tvfilterview_gen.h
5tvkeyedit_gen.h
diff --git a/noncore/apps/tableviewer/Makefile.in b/noncore/apps/tableviewer/Makefile.in
new file mode 100644
index 0000000..8c5dc26
--- a/dev/null
+++ b/noncore/apps/tableviewer/Makefile.in
@@ -0,0 +1,330 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I../library
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= tableviewer
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =tableviewer.h \
27 ui/commonwidgets.h \
28 ui/tvbrowseview.h \
29 ui/tvlistview.h \
30 ui/tvfilterview.h \
31 ui/tveditview.h \
32 ui/browsekeyentry.h \
33 ui/filterkeyentry.h \
34 ui/tvkeyedit.h \
35 db/datacache.h \
36 db/common.h \
37 db/xmlsource.h \
38 db/csvsource.h
39 SOURCES =main.cpp \
40 tableviewer.cpp \
41 ui/commonwidgets.cpp \
42 ui/tvbrowseview.cpp \
43 ui/tvfilterview.cpp \
44 ui/browsekeyentry.cpp \
45 ui/filterkeyentry.cpp \
46 ui/tvlistview.cpp \
47 ui/tveditview.cpp \
48 ui/tvkeyedit.cpp \
49 db/datacache.cpp \
50 db/xmlsource.cpp \
51 db/csvsource.cpp \
52 db/common.cpp
53 OBJECTS =main.o \
54 tableviewer.o \
55 ui/commonwidgets.o \
56 ui/tvbrowseview.o \
57 ui/tvfilterview.o \
58 ui/browsekeyentry.o \
59 ui/filterkeyentry.o \
60 ui/tvlistview.o \
61 ui/tveditview.o \
62 ui/tvkeyedit.o \
63 db/datacache.o \
64 db/xmlsource.o \
65 db/csvsource.o \
66 db/common.o \
67 ui/tvkeyedit_gen.o
68INTERFACES = ui/tvkeyedit_gen.ui
69UICDECLS = ui/tvkeyedit_gen.h
70UICIMPLS = ui/tvkeyedit_gen.cpp
71 SRCMOC =moc_tableviewer.cpp \
72 ui/moc_commonwidgets.cpp \
73 ui/moc_tvbrowseview.cpp \
74 ui/moc_tvlistview.cpp \
75 ui/moc_tvfilterview.cpp \
76 ui/moc_tveditview.cpp \
77 ui/moc_browsekeyentry.cpp \
78 ui/moc_filterkeyentry.cpp \
79 ui/moc_tvkeyedit.cpp \
80 ui/moc_tvkeyedit_gen.cpp
81 OBJMOC =moc_tableviewer.o \
82 ui/moc_commonwidgets.o \
83 ui/moc_tvbrowseview.o \
84 ui/moc_tvlistview.o \
85 ui/moc_tvfilterview.o \
86 ui/moc_tveditview.o \
87 ui/moc_browsekeyentry.o \
88 ui/moc_filterkeyentry.o \
89 ui/moc_tvkeyedit.o \
90 ui/moc_tvkeyedit_gen.o
91
92
93####### Implicit rules
94
95.SUFFIXES: .cpp .cxx .cc .C .c
96
97.cpp.o:
98 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
99
100.cxx.o:
101 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
102
103.cc.o:
104 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
105
106.C.o:
107 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
108
109.c.o:
110 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
111
112####### Build rules
113
114
115all: $(DESTDIR)$(TARGET)
116
117$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
118 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
119
120moc: $(SRCMOC)
121
122tmake: Makefile.in
123
124Makefile.in: tableviewer.pro
125 tmake tableviewer.pro -o Makefile.in
126
127clean:
128 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
129 -rm -f *~ core
130 -rm -f allmoc.cpp
131
132####### Extension Modules
133
134listpromodules:
135 @echo
136
137listallmodules:
138 @echo
139
140listaddonpromodules:
141 @echo
142
143listaddonentmodules:
144 @echo
145
146
147REQUIRES=
148
149####### Sub-libraries
150
151
152###### Combined headers
153
154
155
156####### Compile
157
158main.o: main.cpp \
159 tableviewer.h \
160 db/common.h \
161 ../library/fileselector.h \
162 ../library/filemanager.h \
163 ../library/applnk.h \
164 ../library/qpeapplication.h \
165 ../library/qpedecoration_qws.h
166
167tableviewer.o: tableviewer.cpp \
168 tableviewer.h \
169 db/common.h \
170 ../library/fileselector.h \
171 ../library/filemanager.h \
172 ../library/applnk.h \
173 ui/tvbrowseview.h \
174 ui/tvfilterview.h \
175 ui/tvlistview.h \
176 ui/tveditview.h \
177 ui/tvkeyedit.h \
178 tvkeyedit_gen.h \
179 db/datacache.h \
180 ../library/resource.h
181
182ui/commonwidgets.o: ui/commonwidgets.cpp \
183 ../library/datebookmonth.h \
184 ../library/organizer.h \
185 ../library/xmlreader.h \
186 ../library/calendar.h \
187 ui/commonwidgets.h
188
189ui/tvbrowseview.o: ui/tvbrowseview.cpp \
190 ui/tvbrowseview.h \
191 ui/../db/common.h \
192 ui/browsekeyentry.h
193
194ui/tvfilterview.o: ui/tvfilterview.cpp \
195 ui/tvfilterview.h \
196 ui/filterkeyentry.h \
197 ui/../db/common.h
198
199ui/browsekeyentry.o: ui/browsekeyentry.cpp \
200 ui/browsekeyentry.h \
201 ui/../db/common.h \
202 ui/commonwidgets.h
203
204ui/filterkeyentry.o: ui/filterkeyentry.cpp \
205 ui/filterkeyentry.h \
206 ui/../db/common.h \
207 ui/commonwidgets.h
208
209ui/tvlistview.o: ui/tvlistview.cpp \
210 ui/tvlistview.h \
211 ui/../db/common.h
212
213ui/tveditview.o: ui/tveditview.cpp \
214 ui/tveditview.h \
215 ui/../db/common.h \
216 ui/commonwidgets.h
217
218ui/tvkeyedit.o: ui/tvkeyedit.cpp \
219 ui/tvkeyedit.h \
220 tvkeyedit_gen.h \
221 ui/../db/common.h
222
223db/datacache.o: db/datacache.cpp \
224 db/datacache.h \
225 db/common.h \
226 db/xmlsource.h \
227 db/csvsource.h
228
229db/xmlsource.o: db/xmlsource.cpp \
230 db/xmlsource.h \
231 db/datacache.h \
232 db/common.h
233
234db/csvsource.o: db/csvsource.cpp \
235 db/csvsource.h \
236 db/datacache.h \
237 db/common.h
238
239db/common.o: db/common.cpp \
240 ../library/timestring.h \
241 db/common.h \
242 db/datacache.h
243
244ui/tvkeyedit_gen.h: ui/tvkeyedit_gen.ui
245 $(UIC) ui/tvkeyedit_gen.ui -o $(INTERFACE_DECL_PATH)/ui/tvkeyedit_gen.h
246
247tvkeyedit_gen.h: ui/tvkeyedit_gen.ui
248 $(UIC) ui/tvkeyedit_gen.ui -o tvkeyedit_gen.h
249
250ui/tvkeyedit_gen.cpp: ui/tvkeyedit_gen.ui
251 $(UIC) ui/tvkeyedit_gen.ui -i tvkeyedit_gen.h -o ui/tvkeyedit_gen.cpp
252
253ui/tvkeyedit_gen.o: ui/tvkeyedit_gen.cpp \
254 ui/tvkeyedit_gen.h \
255 ui/tvkeyedit_gen.ui
256
257moc_tableviewer.o: moc_tableviewer.cpp \
258 tableviewer.h \
259 db/common.h \
260 ../library/fileselector.h \
261 ../library/filemanager.h \
262 ../library/applnk.h
263
264ui/moc_commonwidgets.o: ui/moc_commonwidgets.cpp \
265 ui/commonwidgets.h
266
267ui/moc_tvbrowseview.o: ui/moc_tvbrowseview.cpp \
268 ui/tvbrowseview.h \
269 ui/../db/common.h
270
271ui/moc_tvlistview.o: ui/moc_tvlistview.cpp \
272 ui/tvlistview.h \
273 ui/../db/common.h
274
275ui/moc_tvfilterview.o: ui/moc_tvfilterview.cpp \
276 ui/tvfilterview.h \
277 ui/filterkeyentry.h \
278 ui/../db/common.h
279
280ui/moc_tveditview.o: ui/moc_tveditview.cpp \
281 ui/tveditview.h \
282 ui/../db/common.h
283
284ui/moc_browsekeyentry.o: ui/moc_browsekeyentry.cpp \
285 ui/browsekeyentry.h \
286 ui/../db/common.h
287
288ui/moc_filterkeyentry.o: ui/moc_filterkeyentry.cpp \
289 ui/filterkeyentry.h \
290 ui/../db/common.h
291
292ui/moc_tvkeyedit.o: ui/moc_tvkeyedit.cpp \
293 ui/tvkeyedit.h \
294 tvkeyedit_gen.h \
295 ui/../db/common.h
296
297ui/moc_tvkeyedit_gen.o: ui/moc_tvkeyedit_gen.cpp \
298 ui/tvkeyedit_gen.h
299
300moc_tableviewer.cpp: tableviewer.h
301 $(MOC) tableviewer.h -o moc_tableviewer.cpp
302
303ui/moc_commonwidgets.cpp: ui/commonwidgets.h
304 $(MOC) ui/commonwidgets.h -o ui/moc_commonwidgets.cpp
305
306ui/moc_tvbrowseview.cpp: ui/tvbrowseview.h
307 $(MOC) ui/tvbrowseview.h -o ui/moc_tvbrowseview.cpp
308
309ui/moc_tvlistview.cpp: ui/tvlistview.h
310 $(MOC) ui/tvlistview.h -o ui/moc_tvlistview.cpp
311
312ui/moc_tvfilterview.cpp: ui/tvfilterview.h
313 $(MOC) ui/tvfilterview.h -o ui/moc_tvfilterview.cpp
314
315ui/moc_tveditview.cpp: ui/tveditview.h
316 $(MOC) ui/tveditview.h -o ui/moc_tveditview.cpp
317
318ui/moc_browsekeyentry.cpp: ui/browsekeyentry.h
319 $(MOC) ui/browsekeyentry.h -o ui/moc_browsekeyentry.cpp
320
321ui/moc_filterkeyentry.cpp: ui/filterkeyentry.h
322 $(MOC) ui/filterkeyentry.h -o ui/moc_filterkeyentry.cpp
323
324ui/moc_tvkeyedit.cpp: ui/tvkeyedit.h
325 $(MOC) ui/tvkeyedit.h -o ui/moc_tvkeyedit.cpp
326
327ui/moc_tvkeyedit_gen.cpp: ui/tvkeyedit_gen.h
328 $(MOC) ui/tvkeyedit_gen.h -o ui/moc_tvkeyedit_gen.cpp
329
330
diff --git a/noncore/apps/tableviewer/README b/noncore/apps/tableviewer/README
new file mode 100644
index 0000000..cd479e5
--- a/dev/null
+++ b/noncore/apps/tableviewer/README
@@ -0,0 +1,29 @@
1Table Viewer;
2
3This application is still in development, very buggy and leaks memory like
4a sieve. There are still a few major features/design work to be done. Once
5The app has settled (i.e. implementation of initial design completed) the
6focus will switch from features to making the code worthy of Trolltech.
7This means finding all the memory leaks, possibly some restructoring of code
8for future maintainability and ensuring that the code is readable
9(reasonable names for classes and vars.)
10
11For convenience there is a db.xml file included that is generated from the
12CIA World fact book, 11-May-01. The current version of this file should always work with the current version of the tableviewer application
13
14Major design work yet to be completed
15
16* ensure that only reasonable controls are enabled.
17* implement delete item & delete keys
18* loading dialogs
19* filterview -> dialog
20* only do sensible things if no keys set. includes;
21 No list view,
22 No filter view,
23 No edit item.
24* Tool bar in both 'views'
25* only build widgets as needed
26* click on scrollview to change key type, (remove key dialog)
27* fix navigate buttons
28
29This README will also be removed once the major design work is done.
diff --git a/noncore/apps/tableviewer/browsekeyentry.cpp b/noncore/apps/tableviewer/browsekeyentry.cpp
new file mode 100644
index 0000000..04e7902
--- a/dev/null
+++ b/noncore/apps/tableviewer/browsekeyentry.cpp
@@ -0,0 +1,242 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "browsekeyentry.h"
21
22#include <qtoolbutton.h>
23#include <qwidgetstack.h>
24#include <qlayout.h>
25#include <qlineedit.h>
26#include <qpushbutton.h>
27#include <qpopupmenu.h>
28#include <qhbox.h>
29#include <qdatetime.h>
30
31//#include <iostream.h>
32#include <qheader.h>
33// For qWarning(const char *)
34
35/*!
36 \class TVBrowseKeyEntry
37 \brief a Widget used enter keys into the TVBrowseViewWidget
38
39 The TVBrowseKeyEntry Widget provides the facility to enter
40 various key types to be search on in the table. The key can be changed
41 and the entry field will update to the correct sort of widget appropriately
42*/
43
44/*!
45 Constructs the widget
46*/
47TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f)
48 : QWidget(parent, name, f)
49{
50 int stack_elem = 0;
51 QHBoxLayout *h_layout = new QHBoxLayout(this);
52
53 textKey = new QLineEdit(this, 0);
54
55 dateKey = new QHBox(this, 0);
56 dayKey = new QLineEdit(dateKey, 0);
57 monthKey = new QLineEdit(dateKey, 0);
58 yearKey = new QLineEdit(dateKey, 0);
59
60 timeKey = new QHBox(this, 0);
61 hourKey = new QLineEdit(timeKey, 0);
62 minuteKey = new QLineEdit(timeKey, 0);
63 secondKey = new QLineEdit(timeKey, 0);
64
65 resetButton = new QPushButton(this, "reset");
66 resetButton->setMinimumSize(QSize(50, 0));
67 resetButton->setText(tr("Reset"));
68
69 changeKeyButton = new QToolButton(this, "changekey");
70 // TODO The icon stuff.
71 changeKeyButton->setText(tr("key"));
72
73 totalKeys = 0;
74 ts = 0;
75 keyMenu = new QPopupMenu(this, "keymenu");
76
77 ws = new QWidgetStack(this, 0);
78 ws->addWidget(textKey, stack_elem++);
79 ws->addWidget(timeKey, stack_elem++);
80 ws->addWidget(dateKey, stack_elem++);
81
82 ws->raiseWidget(0);
83
84 // TODO connect slots and signals....
85 connect(changeKeyButton, SIGNAL(clicked()),
86 this, SLOT(changeKeyMenuSlot()));
87 connect(resetButton, SIGNAL(clicked()),
88 this, SLOT(resetKeySlot()));
89
90 connect(textKey, SIGNAL(textChanged(const QString&)),
91 this, SLOT(searchOnText()));
92
93 connect(dayKey, SIGNAL(textChanged(const QString&)),
94 this, SLOT(searchOnText()));
95 connect(monthKey, SIGNAL(textChanged(const QString&)),
96 this, SLOT(searchOnText()));
97 connect(yearKey, SIGNAL(textChanged(const QString&)),
98 this, SLOT(searchOnText()));
99
100 connect(secondKey, SIGNAL(textChanged(const QString&)),
101 this, SLOT(searchOnText()));
102 connect(minuteKey, SIGNAL(textChanged(const QString&)),
103 this, SLOT(searchOnText()));
104 connect(hourKey, SIGNAL(textChanged(const QString&)),
105 this, SLOT(searchOnText()));
106
107 h_layout->addWidget(ws);
108 h_layout->addWidget(resetButton);
109 h_layout->addWidget(changeKeyButton);
110}
111
112/*!
113 Destructs the widget
114*/
115TVBrowseKeyEntry::~TVBrowseKeyEntry()
116{
117}
118
119/*!
120 Changes which key the user intends to search on
121
122 \param id_param the index of the key future searches should be base on
123*/
124void TVBrowseKeyEntry::changeKeySlot(int id_param)
125{
126 emit sortChanged(id_param);
127 switch(ts->kRep->getKeyType(ts->current_column)) {
128 /* work out what to raise */
129 case kt_string:
130 case kt_int:
131 ws->raiseWidget(0);
132 break;
133 case kt_time:
134 ws->raiseWidget(1);
135 break;
136 case kt_date:
137 ws->raiseWidget(2);
138 break;
139 default:
140 return;
141 }
142}
143
144/*!
145 Opens the change key menu
146*/
147void TVBrowseKeyEntry::changeKeyMenuSlot()
148{
149 if(ts)
150 keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0)));
151}
152/*!
153 Blanks the key entry widget
154 \TODO the actual implmentation
155*/
156void TVBrowseKeyEntry::resetKeySlot() {
157 ;
158}
159
160void TVBrowseKeyEntry::setTableState(TableState *t) {
161 int i;
162 ts = t;
163
164 /* clear the old */
165 keyMenu->clear();
166
167 for (i = 0; i < t->kRep->getNumFields(); i++) {
168 keyMenu->insertItem(ts->kRep->getKeyName(i), this,
169 SLOT(changeKeySlot(int)), 0, i);
170 keyMenu->setItemParameter(i, i);
171 }
172}
173
174/*!
175 Searches on the current value of the key entry provided that the
176 current key is of type text WARNING, TODO fix memory leaks
177*/
178void TVBrowseKeyEntry::searchOnText()
179{
180 void *sendkey;
181 int tmp;
182
183 switch(ts->kRep->getKeyType(ts->current_column)) {
184 /* work out what to raise */
185 case kt_string:
186 sendkey = (void *)new QString(textKey->text());
187 break;
188 case kt_int: {
189 bool ok;
190 tmp = textKey->text().toInt(&ok);
191 sendkey = &tmp;
192 if (!ok)
193 return;
194 break;
195 }
196 case kt_time: {
197 bool ok;
198 int s,m,h;
199 s = secondKey->text().toInt(&ok);
200 if (!ok)
201 return;
202 m = minuteKey->text().toInt(&ok);
203 if (!ok)
204 return;
205 h = hourKey->text().toInt(&ok);
206 if (!ok)
207 return;
208 if(!QTime::isValid(h, m, s))
209 return;
210 sendkey = (void *) new QTime(h, m, s);
211 break;
212 }
213 case kt_date: {
214 bool ok;
215 int d,m,y;
216 d = dayKey->text().toInt(&ok);
217 if (!ok)
218 return;
219 m = monthKey->text().toInt(&ok);
220 if (!ok)
221 return;
222 y = yearKey->text().toInt(&ok);
223 if (!ok)
224 return;
225 if(!QDate::isValid(y, m, d))
226 return;
227 sendkey = (void *) new QDate(y, m, d);
228 break;
229 }
230 default:
231 qWarning("TVBrowseKeyEntry::searchOnText() "
232 "cannot work out data type");
233 return;
234 }
235 emit searchOnKey(ts->current_column, sendkey);
236}
237
238/*! \fn void TVBrowseKeyEntry::searchOnKey(int currentKeyId, void *v)
239
240 This signal indicates that a search on key index currentKeyId should be
241 done searching for the value v.
242*/
diff --git a/noncore/apps/tableviewer/db.xmlt b/noncore/apps/tableviewer/db.xmlt
new file mode 100644
index 0000000..d7734f6
--- a/dev/null
+++ b/noncore/apps/tableviewer/db.xmlt
@@ -0,0 +1,6279 @@
1<database name="World fact book">
2<header>
3<key name="Location" type="String">Location</key>
4<key name="Geographiccoordinates" type="String">Geographic coordinates</key>
5<key name="Area" type="Int">Area</key>
6<key name="Climate" type="String">Climate</key>
7<key name="Naturalresources" type="String">Natural resources</key>
8<key name="Population" type="Int">Population</key>
9<key name="Populationgrowthrate" type="String">Population growth rate</key>
10<key name="Sexratio" type="String">Sex ratio</key>
11<key name="Religions" type="String">Religions</key>
12<key name="Countryname" type="String">Country name</key>
13<key name="Capital" type="String">Capital</key>
14<key name="Flagdescription" type="String">Flag description</key>
15<key name="GDP" type="String">GDP</key>
16<key name="Industries" type="String">Industries</key>
17<key name="Exports" type="String">Exports</key>
18<key name="Imports" type="String">Imports</key>
19<key name="Currency" type="String">Currency</key>
20<key name="Airports" type="String">Airports</key>
21<key name="Illicitdrugs" type="String">Illicit drugs</key>
22</header>
23<record>
24<Location>Caribbean, island in the Caribbean Sea, north of Venezuela</Location>
25<Geographiccoordinates>12 30 N, 69 58 W</Geographiccoordinates>
26<Area>193</Area>
27<Climate>tropical marine; little seasonal temperature variation</Climate>
28<Naturalresources>NEGL; white sandy beaches</Naturalresources>
29<Population>69539</Population>
30<Populationgrowthrate>0.7% (2000 est.)</Populationgrowthrate>
31<Sexratio>
32at birth: 1.05 male(s)/female
33under 15 years: 1.08 male(s)/female
3415-64 years: 0.92 male(s)/female
3565 years and over: 0.71 male(s)/female
36total population: 0.93 male(s)/female (2000 est.)</Sexratio>
37<Religions>Roman Catholic 82%, Protestant 8%, Hindu, Muslim, Confucian, Jewish</Religions>
38<Countryname>Aruba </Countryname>
39<Capital>Oranjestad</Capital>
40<Flagdescription>blue, with two narrow, horizontal, yellow stripes across the lower portion and a red, four-pointed star outlined in white in the upper hoist-side corner</Flagdescription>
41<GDP>purchasing power parity - $1.6 billion (1998 est.)</GDP>
42<Industries>tourism, transshipment facilities, oil refining</Industries>
43<Exports>$1.17 billion (including oil reexports)(1998)</Exports>
44<Imports>$1.52 billion (1998)</Imports>
45<Currency>1 Aruban florin (Af.) = 100 cents</Currency>
46<Airports>2 (1999 est.)</Airports>
47<Illicitdrugs>drug-money-laundering center and transit point for narcotics bound for the US and Europe</Illicitdrugs>
48</record>
49<record>
50<Location>Caribbean, islands between the Caribbean Sea and the North Atlantic Ocean, east-southeast of Puerto Rico</Location>
51<Geographiccoordinates>17 03 N, 61 48 W</Geographiccoordinates>
52<Area>442</Area>
53<Climate>tropical marine; little seasonal temperature variation</Climate>
54<Naturalresources>NEGL; pleasant climate fosters tourism</Naturalresources>
55<Population>66422</Population>
56<Populationgrowthrate>0.73% (2000 est.)</Populationgrowthrate>
57<Sexratio>
58at birth: 1.05 male(s)/female
59under 15 years: 1.03 male(s)/female
6015-64 years: 0.99 male(s)/female
6165 years and over: 0.73 male(s)/female
62total population: 0.99 male(s)/female (2000 est.)</Sexratio>
63<Religions>Anglican (predominant), other Protestant, some Roman Catholic</Religions>
64<Countryname>Antigua and Barbuda </Countryname>
65<Capital>Saint John's</Capital>
66<Flagdescription>red, with an inverted isosceles triangle based on the top edge of the flag; the triangle contains three horizontal bands of black (top), light blue, and white, with a yellow rising sun in the black band</Flagdescription>
67<GDP>purchasing power parity - $524 million (1999 est.)</GDP>
68<Industries>tourism, construction, light manufacturing (clothing, alcohol, household appliances)</Industries>
69<Exports>$38 million (1998)</Exports>
70<Imports>$330 million (1998)</Imports>
71<Currency>1 East Caribbean dollar (EC$) = 100 cents</Currency>
72<Airports>3 (1999 est.)</Airports>
73<Illicitdrugs>considered a minor transshipment point for narcotics bound for the US and Europe; more significant as a drug-money-laundering center</Illicitdrugs>
74</record>
75<record>
76<Location>Southern Asia, north and west of Pakistan, east of Iran</Location>
77<Geographiccoordinates>33 00 N, 65 00 E</Geographiccoordinates>
78<Area>652000</Area>
79<Climate>arid to semiarid; cold winters and hot summers</Climate>
80<Naturalresources>natural gas, petroleum, coal, copper, chromite, talc, barites, sulfur, lead, zinc, iron ore, salt, precious and semiprecious stones</Naturalresources>
81<Population>25838797</Population>
82<Populationgrowthrate>3.54% (2000 est.)
83note: this rate reflects the continued return of refugees from Iran</Populationgrowthrate>
84<Sexratio>
85at birth: 1.05 male(s)/female
86under 15 years: 1.04 male(s)/female
8715-64 years: 1.08 male(s)/female
8865 years and over: 1.12 male(s)/female
89total population: 1.06 male(s)/female (2000 est.)</Sexratio>
90<Religions>Sunni Muslim 84%, Shi'a Muslim 15%, other 1%</Religions>
91<Countryname>Afghanistan </Countryname>
92<Capital>Kabul</Capital>
93<Flagdescription>three equal horizontal bands of green (top), white, and black with a gold emblem centered on the three bands; the emblem features a temple-like structure with Islamic inscriptions above and below, encircled by a wreath on the left and right and by a bolder Islamic inscription above, all of which are encircled by two crossed scimitars
94note: the Taliban uses a plain white flag</Flagdescription>
95<GDP>purchasing power parity - $21 billion (1999 est.)</GDP>
96<Industries>small-scale production of textiles, soap, furniture, shoes, fertilizer, and cement; handwoven carpets; natural gas, oil, coal, copper</Industries>
97<Exports>$80 million (does not include opium) (1996 est.)</Exports>
98<Imports>$150 million (1996 est.)</Imports>
99<Currency>1 afghani (AF) = 100 puls</Currency>
100<Airports>46 (1999 est.)</Airports>
101<Illicitdrugs>world's largest illicit opium producer, surpassing Burma (potential production in 1999 - 1,670 metric tons; cultivation in 1999 - 51,500 hectares, a 23% increase over 1998); a major source of hashish; increasing number of heroin-processing laboratories being set up in the country; major political factions in the country profit from drug trade</Illicitdrugs>
102</record>
103<record>
104<Location>Northern Africa, bordering the Mediterranean Sea, between Morocco and Tunisia</Location>
105<Geographiccoordinates>28 00 N, 3 00 E</Geographiccoordinates>
106<Area>2381740</Area>
107<Climate>arid to semiarid; mild, wet winters with hot, dry summers along coast; drier with cold winters and hot summers on high plateau; sirocco is a hot, dust/sand-laden wind especially common in summer</Climate>
108<Naturalresources>petroleum, natural gas, iron ore, phosphates, uranium, lead, zinc</Naturalresources>
109<Population>31193917</Population>
110<Populationgrowthrate>1.74% (2000 est.)</Populationgrowthrate>
111<Sexratio>
112at birth: 1.04 male(s)/female
113under 15 years: 1.04 male(s)/female
11415-64 years: 1.02 male(s)/female
11565 years and over: 0.86 male(s)/female
116total population: 1.02 male(s)/female (2000 est.)</Sexratio>
117<Religions>Sunni Muslim (state religion) 99%, Christian and Jewish 1%</Religions>
118<Countryname>Algeria </Countryname>
119<Capital>Algiers</Capital>
120<Flagdescription>two equal vertical bands of green (hoist side) and white with a red, five-pointed star within a red crescent; the crescent, star, and color green are traditional symbols of Islam (the state religion)</Flagdescription>
121<GDP>purchasing power parity - $147.6 billion (1999 est.)</GDP>
122<Industries>petroleum, natural gas, light industries, mining, electrical, petrochemical, food processing</Industries>
123<Exports>$13.7 billion (f.o.b., 1999 est.)</Exports>
124<Imports>$9.3 billion (f.o.b., 1999 est.)</Imports>
125<Currency>1 Algerian dinar (DA) = 100 centimes</Currency>
126<Airports>137 (1999 est.)</Airports>
127</record>
128<record>
129<Location>Southwestern Asia, bordering the Caspian Sea, between Iran and Russia</Location>
130<Geographiccoordinates>40 30 N, 47 30 E</Geographiccoordinates>
131<Area>86600</Area>
132<Climate>dry, semiarid steppe</Climate>
133<Naturalresources>petroleum, natural gas, iron ore, nonferrous metals, alumina</Naturalresources>
134<Population>7748163</Population>
135<Populationgrowthrate>0.27% (2000 est.)</Populationgrowthrate>
136<Sexratio>
137at birth: 1.05 male(s)/female
138under 15 years: 1.04 male(s)/female
13915-64 years: 0.95 male(s)/female
14065 years and over: 0.65 male(s)/female
141total population: 0.95 male(s)/female (2000 est.)</Sexratio>
142<Religions>Muslim 93.4%, Russian Orthodox 2.5%, Armenian Orthodox 2.3%, other 1.8% (1995 est.)
143note: religious affiliation is still nominal in Azerbaijan; percentages for actual practicing adherents are much lower</Religions>
144<Countryname>Azerbaijan </Countryname>
145<Capital>Baku (Baki)</Capital>
146<Flagdescription>three equal horizontal bands of blue (top), red, and green; a crescent and eight-pointed star in white are centered in red band</Flagdescription>
147<GDP>purchasing power parity - $14 billion (1999 est.)</GDP>
148<Industries>petroleum and natural gas, petroleum products, oilfield equipment; steel, iron ore, cement; chemicals and petrochemicals; textiles</Industries>
149<Exports>$885 million (f.o.b., 1999 est.)</Exports>
150<Imports>$1.62 billion (c.i.f., 1999 est.)</Imports>
151<Currency>1 manat = 100 gopiks</Currency>
152<Airports>69 (1996 est.)</Airports>
153<Illicitdrugs>limited illicit cultivation of cannabis and opium poppy, mostly for CIS consumption; limited government eradication program; transshipment point for opiates via Iran, Central Asia, and Russia to Western Europe</Illicitdrugs>
154</record>
155<record>
156<Location>Southeastern Europe, bordering the Adriatic Sea and Ionian Sea, between Greece and Serbia and Montenegro</Location>
157<Geographiccoordinates>41 00 N, 20 00 E</Geographiccoordinates>
158<Area>28748</Area>
159<Climate>mild temperate; cool, cloudy, wet winters; hot, clear, dry summers; interior is cooler and wetter</Climate>
160<Naturalresources>petroleum, natural gas, coal, chromium, copper, timber, nickel, hydropower</Naturalresources>
161<Population>3490435</Population>
162<Populationgrowthrate>0.26% (2000 est.)</Populationgrowthrate>
163<Sexratio>
164at birth: 1.08 male(s)/female
165under 15 years: 1.07 male(s)/female
16615-64 years: 0.93 male(s)/female
16765 years and over: 0.77 male(s)/female
168total population: 0.96 male(s)/female (2000 est.)</Sexratio>
169<Religions>Muslim 70%, Albanian Orthodox 20%, Roman Catholic 10%
170note: all mosques and churches were closed in 1967 and religious observances prohibited; in November 1990, Albania began allowing private religious practice</Religions>
171<Countryname>Albania </Countryname>
172<Capital>Tirana</Capital>
173<Flagdescription>red with a black two-headed eagle in the center</Flagdescription>
174<GDP>purchasing power parity - $5.6 billion (1999 est.)</GDP>
175<Industries>food processing, textiles and clothing; lumber, oil, cement, chemicals, mining, basic metals, hydropower</Industries>
176<Exports>$242 million (f.o.b., 1999 est.)</Exports>
177<Imports>$925 million (f.o.b., 1999 est.)</Imports>
178<Currency>1 lek (L) = 100 qintars</Currency>
179<Airports>10 (1999 est.)</Airports>
180<Illicitdrugs>increasingly active transshipment point for Southwest Asian opiates, hashish, and cannabis transiting the Balkan route and - to a far lesser extent - cocaine from South America destined for Western Europe; limited opium and cannabis production; ethnic Albanian narcotrafficking organizations active and rapidly expanding in Europe</Illicitdrugs>
181</record>
182<record>
183<Location>Southwestern Asia, east of Turkey</Location>
184<Geographiccoordinates>40 00 N, 45 00 E</Geographiccoordinates>
185<Area>29800</Area>
186<Climate>highland continental, hot summers, cold winters</Climate>
187<Naturalresources>small deposits of gold, copper, molybdenum, zinc, alumina</Naturalresources>
188<Population>3344336</Population>
189<Populationgrowthrate>-0.28% (2000 est.)</Populationgrowthrate>
190<Sexratio>
191at birth: 1.05 male(s)/female
192under 15 years: 1.04 male(s)/female
19315-64 years: 0.96 male(s)/female
19465 years and over: 0.71 male(s)/female
195total population: 0.95 male(s)/female (2000 est.)</Sexratio>
196<Religions>Armenian Orthodox 94%</Religions>
197<Countryname>Armenia </Countryname>
198<Capital>Yerevan</Capital>
199<Flagdescription>three equal horizontal bands of red (top), blue, and orange</Flagdescription>
200<GDP>purchasing power parity - $9.9 billion (1999 est.)</GDP>
201<Industries>metal-cutting machine tools, forging-pressing machines, electric motors, tires, knitted wear, hosiery, shoes, silk fabric, washing machines, chemicals, trucks, watches, instruments, microelectronics</Industries>
202<Exports>$240 million (1999 est.)</Exports>
203<Imports>$782 million (1999 est.)</Imports>
204<Currency>1 dram = 100 luma</Currency>
205<Airports>11 (1996 est.)</Airports>
206<Illicitdrugs>illicit cultivator of cannabis mostly for domestic consumption; increasingly used as a transshipment point for illicit drugs - mostly opium and hashish - to Western Europe and the US via Iran, Central Asia, and Russia</Illicitdrugs>
207</record>
208<record>
209<Location>Southwestern Europe, between France and Spain</Location>
210<Geographiccoordinates>42 30 N, 1 30 E</Geographiccoordinates>
211<Area>468</Area>
212<Climate>temperate; snowy, cold winters and warm, dry summers</Climate>
213<Naturalresources>hydropower, mineral water, timber, iron ore, lead</Naturalresources>
214<Population>66824</Population>
215<Populationgrowthrate>1.22% (2000 est.)</Populationgrowthrate>
216<Sexratio>
217at birth: 1.06 male(s)/female
218under 15 years: 1.1 male(s)/female
21915-64 years: 1.11 male(s)/female
22065 years and over: 1.01 male(s)/female
221total population: 1.1 male(s)/female (2000 est.)</Sexratio>
222<Religions>Roman Catholic (predominant)</Religions>
223<Countryname>Andorra </Countryname>
224<Capital>Andorra la Vella</Capital>
225<Flagdescription>three equal vertical bands of blue (hoist side), yellow, and red with the national coat of arms centered in the yellow band; the coat of arms features a quartered shield; similar to the flags of Chad and Romania, which do not have a national coat of arms in the center, and the flag of Moldova, which does bear a national emblem</Flagdescription>
226<GDP>purchasing power parity - $1.2 billion (1996 est.)</GDP>
227<Industries>tourism (particularly skiing), cattle raising, timber, tobacco, banking</Industries>
228<Exports>$58 million (f.o.b., 1998)</Exports>
229<Imports>$1.077 billion (c.i.f., 1998)</Imports>
230<Currency>1 French franc (F) = 100 centimes; 1 peseta (Pta) = 100 centimos; the French and Spanish currencies are used</Currency>
231<Airports>none</Airports>
232</record>
233<record>
234<Location>Southern Africa, bordering the South Atlantic Ocean, between Namibia and Democratic Republic of the Congo</Location>
235<Geographiccoordinates>12 30 S, 18 30 E</Geographiccoordinates>
236<Area>1246700</Area>
237<Climate>semiarid in south and along coast to Luanda; north has cool, dry season (May to October) and hot, rainy season (November to April)</Climate>
238<Naturalresources>petroleum, diamonds, iron ore, phosphates, copper, feldspar, gold, bauxite, uranium</Naturalresources>
239<Population>10145267</Population>
240<Populationgrowthrate>2.15% (2000 est.)</Populationgrowthrate>
241<Sexratio>
242at birth: 1.05 male(s)/female
243under 15 years: 1.02 male(s)/female
24415-64 years: 1.04 male(s)/female
24565 years and over: 0.84 male(s)/female
246total population: 1.02 male(s)/female (2000 est.)</Sexratio>
247<Religions>indigenous beliefs 47%, Roman Catholic 38%, Protestant 15% (1998 est.)</Religions>
248<Countryname>Angola </Countryname>
249<Capital>Luanda</Capital>
250<Flagdescription>two equal horizontal bands of red (top) and black with a centered yellow emblem consisting of a five-pointed star within half a cogwheel crossed by a machete (in the style of a hammer and sickle)</Flagdescription>
251<GDP>purchasing power parity - $11.6 billion (1999 est.)</GDP>
252<Industries>petroleum; diamonds, iron ore, phosphates, feldspar, bauxite, uranium, and gold; cement; basic metal products; fish processing; food processing; brewing; tobacco products; sugar; textiles</Industries>
253<Exports>$5 billion (f.o.b., 1999 est.)</Exports>
254<Imports>$3 billion (f.o.b., 1999 est.)</Imports>
255<Currency>1 kwanza (NKz) = 100 lwei</Currency>
256<Airports>249 (1999 est.)</Airports>
257<Illicitdrugs>increasingly used as a transshipment point for cocaine and heroin destined for Western Europe and other African states</Illicitdrugs>
258</record>
259<record>
260<Location>Oceania, group of islands in the South Pacific Ocean, about one-half of the way from Hawaii to New Zealand</Location>
261<Geographiccoordinates>14 20 S, 170 00 W</Geographiccoordinates>
262<Area>199</Area>
263<Climate>tropical marine, moderated by southeast trade winds; annual rainfall averages about 3 m; rainy season from November to April, dry season from May to October; little seasonal temperature variation</Climate>
264<Naturalresources>pumice, pumicite</Naturalresources>
265<Population>65446</Population>
266<Populationgrowthrate>2.53% (2000 est.)</Populationgrowthrate>
267<Sexratio>
268at birth: 1.06 male(s)/female
269under 15 years: 1.06 male(s)/female
27015-64 years: 0.99 male(s)/female
27165 years and over: 1.1 male(s)/female
272total population: 1.02 male(s)/female (2000 est.)</Sexratio>
273<Religions>Christian Congregationalist 50%, Roman Catholic 20%, Protestant and other 30%</Religions>
274<Countryname>American Samoa </Countryname>
275<Capital>Pago Pago</Capital>
276<Flagdescription>blue, with a white triangle edged in red that is based on the outer side and extends to the hoist side; a brown and white American bald eagle flying toward the hoist side is carrying two traditional Samoan symbols of authority, a staff and a war club</Flagdescription>
277<GDP>purchasing power parity - $150 million (1995 est.)</GDP>
278<Industries>tuna canneries (largely dependent on foreign fishing vessels), handicrafts</Industries>
279<Exports>$313 million (1996)</Exports>
280<Imports>$471 million (1996)</Imports>
281<Currency>1 US dollar (US$) = 100 cents</Currency>
282<Airports>4 (1999 est.)</Airports>
283</record>
284<record>
285<Location>Southern South America, bordering the South Atlantic Ocean, between Chile and Uruguay</Location>
286<Geographiccoordinates>34 00 S, 64 00 W</Geographiccoordinates>
287<Area>2766890</Area>
288<Climate>mostly temperate; arid in southeast; subantarctic in southwest</Climate>
289<Naturalresources>fertile plains of the pampas, lead, zinc, tin, copper, iron ore, manganese, petroleum, uranium</Naturalresources>
290<Population>36955182</Population>
291<Populationgrowthrate>1.16% (2000 est.)</Populationgrowthrate>
292<Sexratio>
293at birth: 1.05 male(s)/female
294under 15 years: 1.05 male(s)/female
29515-64 years: 1 male(s)/female
29665 years and over: 0.71 male(s)/female
297total population: 0.98 male(s)/female (2000 est.)</Sexratio>
298<Religions>nominally Roman Catholic 92% (less than 20% practicing), Protestant 2%, Jewish 2%, other 4%</Religions>
299<Countryname>Argentina </Countryname>
300<Capital>Buenos Aires</Capital>
301<Flagdescription>three equal horizontal bands of light blue (top), white, and light blue; centered in the white band is a radiant yellow sun with a human face known as the Sun of May</Flagdescription>
302<GDP>purchasing power parity - $367 billion (1999 est.)</GDP>
303<Industries>food processing, motor vehicles, consumer durables, textiles, chemicals and petrochemicals, printing, metallurgy, steel</Industries>
304<Exports>$23 billion (f.o.b., 1999 est.)</Exports>
305<Imports>$25 billion (c.i.f., 1999 est.)</Imports>
306<Currency>1 peso = 100 centavos</Currency>
307<Airports>1,359 (1999 est.)</Airports>
308<Illicitdrugs>increasing use as a transshipment country for cocaine headed for Europe and the US; increasing use as a money-laundering center; domestic consumption of drugs has skyrocketed</Illicitdrugs>
309</record>
310<record>
311<Location>Oceania, continent between the Indian Ocean and the South Pacific Ocean</Location>
312<Geographiccoordinates>27 00 S, 133 00 E</Geographiccoordinates>
313<Area>7686850</Area>
314<Climate>generally arid to semiarid; temperate in south and east; tropical in north</Climate>
315<Naturalresources>bauxite, coal, iron ore, copper, tin, silver, uranium, nickel, tungsten, mineral sands, lead, zinc, diamonds, natural gas, petroleum</Naturalresources>
316<Population>19169083</Population>
317<Populationgrowthrate>1.02% (2000 est.)</Populationgrowthrate>
318<Sexratio>
319at birth: 1.06 male(s)/female
320under 15 years: 1.05 male(s)/female
32115-64 years: 1.02 male(s)/female
32265 years and over: 0.78 male(s)/female
323total population: 0.99 male(s)/female (2000 est.)</Sexratio>
324<Religions>Anglican 26.1%, Roman Catholic 26%, other Christian 24.3%, non-Christian 11%</Religions>
325<Countryname>Australia </Countryname>
326<Capital>Canberra</Capital>
327<Flagdescription>blue with the flag of the UK in the upper hoist-side quadrant and a large seven-pointed star in the lower hoist-side quadrant; the remaining half is a representation of the Southern Cross constellation in white with one small five-pointed star and four, larger, seven-pointed stars</Flagdescription>
328<GDP>purchasing power parity - $416.2 billion (1999 est.)</GDP>
329<Industries>mining, industrial and transportation equipment, food processing, chemicals, steel</Industries>
330<Exports>$58 billion (f.o.b., 1999 est.)</Exports>
331<Imports>$67 billion (f.o.b., 1999 est.)</Imports>
332<Currency>1 Australian dollar ($A) = 100 cents</Currency>
333<Airports>408 (1999 est.)</Airports>
334<Illicitdrugs>Tasmania is one of the world's major suppliers of licit opiate products; government maintains strict controls over areas of opium poppy cultivation and output of poppy straw concentrate</Illicitdrugs>
335</record>
336<record>
337<Location>Southeastern Asia, islands in the Indian Ocean, northwest of Australia</Location>
338<Geographiccoordinates>12 14 S, 123 05 E</Geographiccoordinates>
339<Area>5</Area>
340<Climate>tropical</Climate>
341<Naturalresources>fish</Naturalresources>
342<Population></Population>
343<Countryname>Ashmore and Cartier Islands </Countryname>
344<Flagdescription>the flag of Australia is used</Flagdescription>
345</record>
346<record>
347<Location>Central Europe, north of Italy and Slovenia</Location>
348<Geographiccoordinates>47 20 N, 13 20 E</Geographiccoordinates>
349<Area>83858</Area>
350<Climate>temperate; continental, cloudy; cold winters with frequent rain in lowlands and snow in mountains; cool summers with occasional showers</Climate>
351<Naturalresources>iron ore, oil, timber, magnesite, lead, coal, lignite, copper, hydropower</Naturalresources>
352<Population>8131111</Population>
353<Populationgrowthrate>0.25% (2000 est.)</Populationgrowthrate>
354<Sexratio>
355at birth: 1.05 male(s)/female
356under 15 years: 1.05 male(s)/female
35715-64 years: 1.02 male(s)/female
35865 years and over: 0.61 male(s)/female
359total population: 0.95 male(s)/female (2000 est.)</Sexratio>
360<Religions>Roman Catholic 78%, Protestant 5%, Muslim and other 17%</Religions>
361<Countryname>Austria </Countryname>
362<Capital>Vienna</Capital>
363<Flagdescription>three equal horizontal bands of red (top), white, and red</Flagdescription>
364<GDP>purchasing power parity - $190.6 billion (1999 est.)</GDP>
365<Industries>construction, machinery, vehicles and parts, food, chemicals, lumber and wood processing, paper and paperboard, communications equipment, tourism (1997)</Industries>
366<Exports>$62.9 billion (1999 est.)</Exports>
367<Imports>$69.9 billion (1999 est.)</Imports>
368<Currency>1 Austrian schilling (AS) = 100 groschen</Currency>
369<Airports>55 (1999 est.)</Airports>
370<Illicitdrugs>transshipment point for Southwest Asian heroin and South American cocaine destined for Western Europe</Illicitdrugs>
371</record>
372<record>
373<Location>Caribbean, island in the Caribbean Sea, east of Puerto Rico</Location>
374<Geographiccoordinates>18 15 N, 63 10 W</Geographiccoordinates>
375<Area>91</Area>
376<Climate>tropical; moderated by northeast trade winds</Climate>
377<Naturalresources>salt, fish, lobster</Naturalresources>
378<Population>11797</Population>
379<Populationgrowthrate>2.93% (2000 est.)</Populationgrowthrate>
380<Sexratio>
381at birth: 1.03 male(s)/female
382under 15 years: 1.03 male(s)/female
38315-64 years: 1.05 male(s)/female
38465 years and over: 0.79 male(s)/female
385total population: 1.03 male(s)/female (2000 est.)</Sexratio>
386<Religions>Anglican 40%, Methodist 33%, Seventh-Day Adventist 7%, Baptist 5%, Roman Catholic 3%, other 12%</Religions>
387<Countryname>Anguilla </Countryname>
388<Capital>The Valley</Capital>
389<Flagdescription>blue, with the flag of the UK in the upper hoist-side quadrant and the Anguillan coat of arms centered in the outer half of the flag; the coat of arms depicts three orange dolphins in an interlocking circular design on a white background with blue wavy water below</Flagdescription>
390<GDP>purchasing power parity - $88 million (1998 est.)</GDP>
391<Industries>tourism, boat building, offshore financial services</Industries>
392<Exports>$4.5 million (1998)</Exports>
393<Imports>$57.6 million (1998)</Imports>
394<Currency>1 East Caribbean dollar (EC$) = 100 cents</Currency>
395<Airports>3 (1999 est.)</Airports>
396</record>
397<record>
398<Location>continent mostly south of the Antarctic Circle</Location>
399<Geographiccoordinates>90 00 S, 0 00 E</Geographiccoordinates>
400<Area>14000000</Area>
401<Climate>severe low temperatures vary with latitude, elevation, and distance from the ocean; East Antarctica is colder than West Antarctica because of its higher elevation; Antarctic Peninsula has the most moderate climate; higher temperatures occur in January along the coast and average slightly below freezing</Climate>
402<Naturalresources>none presently exploited; iron ore, chromium, copper, gold, nickel, platinum and other minerals, and coal and hydrocarbons have been found in small, uncommercial quantities</Naturalresources>
403<Population></Population>
404<Countryname>Antarctica </Countryname>
405<Airports>18
406note: 27 stations, operated by 16 national governments party to the Antarctic Treaty, have landing facilities for either helicopters and/or fixed-wing aircraft; commercial enterprises operate two additional air facilities; helicopter pads are available at 27 stations; runways at 15 locations are gravel, sea-ice, blue-ice, or compacted snow suitable for landing wheeled, fixed-wing aircraft; of these, 1 is greater than 3 km in length, 6 are between 2 km and 3 km in length, 3 are between 1 km and 2 km in length, 3 are less than 1 km in length, and 2 are of unknown length; snow surface skiways, limited to use by ski-equipped, fixed-wing aircraft,are available at another 15 locations; of these, 4 are greater than 3 km in length, 3 are between 2 km and 3 km in length, 2 are between 1 km and 2 km in length, 2 are less than 1 km in length, and 4 are of unknown length; airports generally subject to severe restrictions and limitations resulting from extreme seasonal and geographic conditions; airports do not meet ICAO standards; advance approval from the respective governmental or nongovernmental operating organization required for landing (1999 est.)</Airports>
407</record>
408<record>
409<Location>Middle East, archipelago in the Persian Gulf, east of Saudi Arabia</Location>
410<Geographiccoordinates>26 00 N, 50 33 E</Geographiccoordinates>
411<Area>620</Area>
412<Climate>arid; mild, pleasant winters; very hot, humid summers</Climate>
413<Naturalresources>oil, associated and nonassociated natural gas, fish</Naturalresources>
414<Population>634137</Population>
415<Populationgrowthrate>1.78% (2000 est.)</Populationgrowthrate>
416<Sexratio>
417at birth: 1.03 male(s)/female
418under 15 years: 1.03 male(s)/female
41915-64 years: 1.46 male(s)/female
42065 years and over: 1.04 male(s)/female
421total population: 1.3 male(s)/female (2000 est.)</Sexratio>
422<Religions>Shi'a Muslim 75%, Sunni Muslim 25%</Religions>
423<Countryname>Bahrain </Countryname>
424<Capital>Manama</Capital>
425<Flagdescription>red with a white serrated band (eight white points) on the hoist side</Flagdescription>
426<GDP>purchasing power parity - $8.6 billion (1999 est.)</GDP>
427<Industries>petroleum processing and refining, aluminum smelting, offshore banking, ship repairing; tourism</Industries>
428<Exports>$3.3 billion (f.o.b., 1998)</Exports>
429<Imports>$3.5 billion (f.o.b., 1998)</Imports>
430<Currency>1 Bahraini dinar (BD) = 1,000 fils</Currency>
431<Airports>3 (1999 est.)</Airports>
432</record>
433<record>
434<Location>Caribbean, island between the Caribbean Sea and the North Atlantic Ocean, northeast of Venezuela</Location>
435<Geographiccoordinates>13 10 N, 59 32 W</Geographiccoordinates>
436<Area>430</Area>
437<Climate>tropical; rainy season (June to October)</Climate>
438<Naturalresources>petroleum, fish, natural gas</Naturalresources>
439<Population>274540</Population>
440<Populationgrowthrate>0.55% (2000 est.)</Populationgrowthrate>
441<Sexratio>
442at birth: 1.03 male(s)/female
443under 15 years: 1.02 male(s)/female
44415-64 years: 0.95 male(s)/female
44565 years and over: 0.63 male(s)/female
446total population: 0.93 male(s)/female (2000 est.)</Sexratio>
447<Religions>Protestant 67% (Anglican 40%, Pentecostal 8%, Methodist 7%, other 12%), Roman Catholic 4%, none 17%, other 12%</Religions>
448<Countryname>Barbados </Countryname>
449<Capital>Bridgetown</Capital>
450<Flagdescription>three equal vertical bands of blue (hoist side), gold, and blue with the head of a black trident centered on the gold band; the trident head represents independence and a break with the past (the colonial coat of arms contained a complete trident)</Flagdescription>
451<GDP>purchasing power parity - $2.9 billion (1998 est.)</GDP>
452<Industries>tourism, sugar, light manufacturing, component assembly for export</Industries>
453<Exports>$211.2 million (1998)</Exports>
454<Imports>$1.01 billion (1998)</Imports>
455<Currency>1 Barbadian dollar (Bds$) = 100 cents</Currency>
456<Airports>1 (1999 est.)</Airports>
457<Illicitdrugs>one of many Caribbean transshipment points for narcotics bound for the US and Europe</Illicitdrugs>
458</record>
459<record>
460<Location>Southern Africa, north of South Africa</Location>
461<Geographiccoordinates>22 00 S, 24 00 E</Geographiccoordinates>
462<Area>600370</Area>
463<Climate>semiarid; warm winters and hot summers</Climate>
464<Naturalresources>diamonds, copper, nickel, salt, soda ash, potash, coal, iron ore, silver</Naturalresources>
465<Population>1576470</Population>
466<Populationgrowthrate>0.76% (2000 est.)</Populationgrowthrate>
467<Sexratio>
468at birth: 1.03 male(s)/female
469under 15 years: 1.01 male(s)/female
47015-64 years: 0.92 male(s)/female
47165 years and over: 0.69 male(s)/female
472total population: 0.94 male(s)/female (2000 est.)</Sexratio>
473<Religions>indigenous beliefs 50%, Christian 50%</Religions>
474<Countryname>Botswana </Countryname>
475<Capital>Gaborone</Capital>
476<Flagdescription>light blue with a horizontal white-edged black stripe in the center</Flagdescription>
477<GDP>purchasing power parity - $5.7 billion (1999 est.)</GDP>
478<Industries>diamonds, copper, nickel, coal, salt, soda ash, potash; livestock processing</Industries>
479<Exports>$2.36 billion (f.o.b., 1999 est.)</Exports>
480<Imports>$2.05 billion (f.o.b., 1999 est.)</Imports>
481<Currency>1 pula (P) = 100 thebe</Currency>
482<Airports>92 (1999 est.)</Airports>
483</record>
484<record>
485<Location>North America, group of islands in the North Atlantic Ocean, east of North Carolina (US)</Location>
486<Geographiccoordinates>32 20 N, 64 45 W</Geographiccoordinates>
487<Area>58</Area>
488<Climate>subtropical; mild, humid; gales, strong winds common in winter</Climate>
489<Naturalresources>limestone, pleasant climate fostering tourism</Naturalresources>
490<Population>62997</Population>
491<Populationgrowthrate>0.75% (2000 est.)</Populationgrowthrate>
492<Sexratio>
493at birth: 1.05 male(s)/female
494under 15 years: 0.98 male(s)/female
49515-64 years: 0.98 male(s)/female
49665 years and over: 0.76 male(s)/female
497total population: 0.95 male(s)/female (2000 est.)</Sexratio>
498<Religions>non-Anglican Protestant 39%, Anglican 27%, Roman Catholic 15%, other 19%</Religions>
499<Countryname>Bermuda </Countryname>
500<Capital>Hamilton</Capital>
501<Flagdescription>red, with the flag of the UK in the upper hoist-side quadrant and the Bermudian coat of arms (white and blue shield with a red lion holding a scrolled shield showing the sinking of the ship Sea Venture off Bermuda in 1609) centered on the outer half of the flag</Flagdescription>
502<GDP>purchasing power parity - $2 billion (1999 est.)</GDP>
503<Industries>tourism, finance, insurance, structural concrete products, paints, perfumes, pharmaceuticals, ship repairing</Industries>
504<Exports>$32 million (1998 est.)</Exports>
505<Imports>$624 million (1998 est.)</Imports>
506<Currency>1 Bermudian dollar (Bd$) = 100 cents</Currency>
507<Airports>1 (1999 est.)</Airports>
508</record>
509<record>
510<Location>Western Europe, bordering the North Sea, between France and the Netherlands</Location>
511<Geographiccoordinates>50 50 N, 4 00 E</Geographiccoordinates>
512<Area>30510</Area>
513<Climate>temperate; mild winters, cool summers; rainy, humid, cloudy</Climate>
514<Naturalresources>coal, natural gas</Naturalresources>
515<Population>10241506</Population>
516<Populationgrowthrate>0.18% (2000 est.)</Populationgrowthrate>
517<Sexratio>
518at birth: 1.05 male(s)/female
519under 15 years: 1.05 male(s)/female
52015-64 years: 1.02 male(s)/female
52165 years and over: 0.69 male(s)/female
522total population: 0.96 male(s)/female (2000 est.)</Sexratio>
523<Religions>Roman Catholic 75%, Protestant or other 25%</Religions>
524<Countryname>Belgium </Countryname>
525<Capital>Brussels</Capital>
526<Flagdescription>three equal vertical bands of black (hoist side), yellow, and red; the design was based on the flag of France</Flagdescription>
527<GDP>purchasing power parity - $243.4 billion (1999 est.)</GDP>
528<Industries>engineering and metal products, motor vehicle assembly, processed food and beverages, chemicals, basic metals, textiles, glass, petroleum, coal</Industries>
529<Exports>$187.3 billion (f.o.b., 1999)</Exports>
530<Imports>$172.8 billion (f.o.b., 1999)</Imports>
531<Currency>1 Belgian franc (BF) = 100 centimes</Currency>
532<Airports>42 (1999 est.)</Airports>
533<Illicitdrugs>source of precursor chemicals for South American cocaine processors; transshipment point for cocaine, heroin, hashish, and marijuana entering Western Europe</Illicitdrugs>
534</record>
535<record>
536<Location>Caribbean, chain of islands in the North Atlantic Ocean, southeast of Florida</Location>
537<Geographiccoordinates>24 15 N, 76 00 W</Geographiccoordinates>
538<Area>13940</Area>
539<Climate>tropical marine; moderated by warm waters of Gulf Stream</Climate>
540<Naturalresources>salt, aragonite, timber</Naturalresources>
541<Population>294982</Population>
542<Populationgrowthrate>1.01% (2000 est.)</Populationgrowthrate>
543<Sexratio>
544at birth: 1.02 male(s)/female
545under 15 years: 1.02 male(s)/female
54615-64 years: 0.96 male(s)/female
54765 years and over: 0.72 male(s)/female
548total population: 0.96 male(s)/female (2000 est.)</Sexratio>
549<Religions>Baptist 32%, Anglican 20%, Roman Catholic 19%, Methodist 6%, Church of God 6%, other Protestant 12%, none or unknown 3%, other 2%</Religions>
550<Countryname>The Bahamas </Countryname>
551<Capital>Nassau</Capital>
552<Flagdescription>three equal horizontal bands of aquamarine (top), gold, and aquamarine, with a black equilateral triangle based on the hoist side</Flagdescription>
553<GDP>purchasing power parity - $5.58 billion (1998 est.)</GDP>
554<Industries>tourism, banking, cement, oil refining and transshipment, salt, rum, aragonite, pharmaceuticals, spiral-welded steel pipe</Industries>
555<Exports>$362.8 million (1998)</Exports>
556<Imports>$1.74 billion (1998)</Imports>
557<Currency>1 Bahamian dollar (B$) = 100 cents</Currency>
558<Airports>62 (1999 est.)</Airports>
559<Illicitdrugs>transshipment point for cocaine and marijuana bound for US and Europe; banking industry vulnerable to money laundering</Illicitdrugs>
560</record>
561<record>
562<Location>Southern Asia, bordering the Bay of Bengal, between Burma and India</Location>
563<Geographiccoordinates>24 00 N, 90 00 E</Geographiccoordinates>
564<Area>144000</Area>
565<Climate>tropical; cool, dry winter (October to March); hot, humid summer (March to June); cool, rainy monsoon (June to October)</Climate>
566<Naturalresources>natural gas, arable land, timber</Naturalresources>
567<Population>129194224</Population>
568<Populationgrowthrate>1.59% (2000 est.)</Populationgrowthrate>
569<Sexratio>
570at birth: 1.06 male(s)/female
571under 15 years: 1.05 male(s)/female
57215-64 years: 1.05 male(s)/female
57365 years and over: 1.19 male(s)/female
574total population: 1.05 male(s)/female (2000 est.)</Sexratio>
575<Religions>Muslim 88.3%, Hindu 10.5%, other 1.2%</Religions>
576<Countryname>Bangladesh </Countryname>
577<Capital>Dhaka</Capital>
578<Flagdescription>green with a large red disk slightly to the hoist side of center; the red sun of freedom represents the blood shed to achieve independence; the green field symbolizes the lush countryside, and secondarily, the traditional color of Islam</Flagdescription>
579<GDP>purchasing power parity - $187 billion (1999 est.)</GDP>
580<Industries>cotton textiles, jute, garments, tea processing, paper newsprint, cement, chemical fertilizer, light engineering, sugar</Industries>
581<Exports>$5.1 billion (1998)</Exports>
582<Imports>$8.01 billion (1998)</Imports>
583<Currency>1 taka (Tk) = 100 poisha</Currency>
584<Airports>16 (1999 est.)</Airports>
585<Illicitdrugs>transit country for illegal drugs produced in neighboring countries</Illicitdrugs>
586</record>
587<record>
588<Location>Middle America, bordering the Caribbean Sea, between Guatemala and Mexico</Location>
589<Geographiccoordinates>17 15 N, 88 45 W</Geographiccoordinates>
590<Area>22960</Area>
591<Climate>tropical; very hot and humid; rainy season (May to February)</Climate>
592<Naturalresources>arable land potential, timber, fish, hydropower</Naturalresources>
593<Population>249183</Population>
594<Populationgrowthrate>2.75% (2000 est.)</Populationgrowthrate>
595<Sexratio>
596at birth: 1.05 male(s)/female
597under 15 years: 1.04 male(s)/female
59815-64 years: 1.03 male(s)/female
59965 years and over: 0.95 male(s)/female
600total population: 1.03 male(s)/female (2000 est.)</Sexratio>
601<Religions>Roman Catholic 62%, Protestant 30% (Anglican 12%, Methodist 6%, Mennonite 4%, Seventh-Day Adventist 3%, Pentecostal 2%, Jehovah's Witnesses 1%, other 2%), none 2%, other 6% (1980)</Religions>
602<Countryname>Belize </Countryname>
603<Capital>Belmopan</Capital>
604<Flagdescription>blue with a narrow red stripe along the top and the bottom edges; centered is a large white disk bearing the coat of arms; the coat of arms features a shield flanked by two workers in front of a mahogany tree with the related motto SUB UMBRA FLOREO (I Flourish in the Shade) on a scroll at the bottom, all encircled by a green garland</Flagdescription>
605<GDP>purchasing power parity - $740 million (1999 est.)</GDP>
606<Industries>garment production, food processing, tourism, construction</Industries>
607<Exports>$150 million (f.o.b., 1998)</Exports>
608<Imports>$320 million (c.i.f., 1998)</Imports>
609<Currency>1 Belizean dollar (Bz$) = 100 cents</Currency>
610<Airports>44 (1999 est.)</Airports>
611<Illicitdrugs>transshipment point for cocaine; small-scale illicit producer of cannabis for the international drug trade; minor money-laundering center</Illicitdrugs>
612</record>
613<record>
614<Location>Southeastern Europe, bordering the Adriatic Sea and Croatia</Location>
615<Geographiccoordinates>44 00 N, 18 00 E</Geographiccoordinates>
616<Area>51129</Area>
617<Climate>hot summers and cold winters; areas of high elevation have short, cool summers and long, severe winters; mild, rainy winters along coast</Climate>
618<Naturalresources>coal, iron, bauxite, manganese, forests, copper, chromium, lead, zinc, hydropower</Naturalresources>
619<Population>3835777</Population>
620<Populationgrowthrate>3.1% (2000 est.)</Populationgrowthrate>
621<Sexratio>
622at birth: 1.07 male(s)/female
623under 15 years: 1.06 male(s)/female
62415-64 years: 1.06 male(s)/female
62565 years and over: 0.73 male(s)/female
626total population: 1.03 male(s)/female (2000 est.)</Sexratio>
627<Religions>Muslim 40%, Orthodox 31%, Roman Catholic 15%, Protestant 4%, other 10%</Religions>
628<Countryname>Bosnia and Herzegovina </Countryname>
629<Capital>Sarajevo</Capital>
630<Flagdescription>a wide medium blue vertical band on the fly side with a yellow isosceles triangle abutting the band and the top of the flag; the remainder of the flag is medium blue with seven full five-pointed white stars and two half stars top and bottom along the hypotenuse of the triangle</Flagdescription>
631<GDP>purchasing power parity - $6.2 billion (1999 est.)</GDP>
632<Industries>steel, coal, iron ore, lead, zinc, manganese, bauxite, vehicle assembly, textiles, tobacco products, wooden furniture, tank and aircraft assembly, domestic appliances, oil refining (much of capacity damaged or shut down) (1995)</Industries>
633<Exports>$450 million (1997 est.)</Exports>
634<Imports>$2.95 billion (1997 est.)</Imports>
635<Currency>1 convertible marka (KM) = 100 convertible pfenniga</Currency>
636<Airports>27 (1999 est.)</Airports>
637<Illicitdrugs>minor transit point for marijuana and opiate trafficking routes to Western Europe</Illicitdrugs>
638</record>
639<record>
640<Location>Central South America, southwest of Brazil</Location>
641<Geographiccoordinates>17 00 S, 65 00 W</Geographiccoordinates>
642<Area>1098580</Area>
643<Climate>varies with altitude; humid and tropical to cold and semiarid</Climate>
644<Naturalresources>tin, natural gas, petroleum, zinc, tungsten, antimony, silver, iron, lead, gold, timber, hydropower</Naturalresources>
645<Population>8152620</Population>
646<Populationgrowthrate>1.83% (2000 est.)</Populationgrowthrate>
647<Sexratio>
648at birth: 1.05 male(s)/female
649under 15 years: 1.04 male(s)/female
65015-64 years: 0.96 male(s)/female
65165 years and over: 0.82 male(s)/female
652total population: 0.98 male(s)/female (2000 est.)</Sexratio>
653<Religions>Roman Catholic 95%, Protestant (Evangelical Methodist)</Religions>
654<Countryname>Bolivia </Countryname>
655<Capital>La Paz (seat of government); Sucre (legal capital and seat of judiciary)</Capital>
656<Flagdescription>three equal horizontal bands of red (top), yellow, and green with the coat of arms centered on the yellow band; similar to the flag of Ghana, which has a large black five-pointed star centered in the yellow band</Flagdescription>
657<GDP>purchasing power parity - $24.2 billion (1999 est.)</GDP>
658<Industries>mining, smelting, petroleum, food and beverages, tobacco, handicrafts, clothing</Industries>
659<Exports>$1.1 billion (f.o.b., 1999 est.)</Exports>
660<Imports>$1.6 billion (c.i.f., 1999 est.)</Imports>
661<Currency>1 boliviano ($B) = 100 centavos</Currency>
662<Airports>1,109 (1999 est.)</Airports>
663<Illicitdrugs>world's third-largest cultivator of coca (after Peru and Colombia) with an estimated 21,800 hectares under cultivation in 1999, a 45% decrease in overall cultivation of coca from 1998 levels; intermediate coca products and cocaine exported to or through Colombia, Brazil, Argentina, and Chile to the US and other international drug markets; alternative crop program aims to reduce illicit coca cultivation</Illicitdrugs>
664</record>
665<record>
666<Location>Southeastern Asia, bordering the Andaman Sea and the Bay of Bengal, between Bangladesh and Thailand</Location>
667<Geographiccoordinates>22 00 N, 98 00 E</Geographiccoordinates>
668<Area>678500</Area>
669<Climate>tropical monsoon; cloudy, rainy, hot, humid summers (southwest monsoon, June to September); less cloudy, scant rainfall, mild temperatures, lower humidity during winter (northeast monsoon, December to April)</Climate>
670<Naturalresources>petroleum, timber, tin, antimony, zinc, copper, tungsten, lead, coal, some marble, limestone, precious stones, natural gas, hydropower</Naturalresources>
671<Population>41734853</Population>
672<Populationgrowthrate>0.64% (2000 est.)</Populationgrowthrate>
673<Sexratio>
674at birth: 1.06 male(s)/female
675under 15 years: 1.04 male(s)/female
67615-64 years: 0.99 male(s)/female
67765 years and over: 0.81 male(s)/female
678total population: 0.99 male(s)/female (2000 est.)</Sexratio>
679<Religions>Buddhist 89%, Christian 4% (Baptist 3%, Roman Catholic 1%), Muslim 4%, animist 1%, other 2%</Religions>
680<Countryname>Burma </Countryname>
681<Capital>Rangoon (regime refers to the capital as Yangon)</Capital>
682<Flagdescription>red with a blue rectangle in the upper hoist-side corner bearing, all in white, 14 five-pointed stars encircling a cogwheel containing a stalk of rice; the 14 stars represent the 14 administrative divisions</Flagdescription>
683<GDP>purchasing power parity - $59.4 billion (1999 est.)</GDP>
684<Industries>agricultural processing; textiles and footwear; wood and wood products; copper, tin, tungsten, iron; construction materials; pharmaceuticals; fertilizer</Industries>
685<Exports>$1.2 billion (1998)</Exports>
686<Imports>$2.5 billion (1998)</Imports>
687<Currency>1 kyat (K) = 100 pyas</Currency>
688<Airports>80 (1999 est.)</Airports>
689<Illicitdrugs>world's second largest producer of illicit opium, after Afghanistan (potential production in 1999 - 1,090 metric tons, down 38% due to drought; cultivation in 1999 - 89,500 hectares, a 31% decline from 1998); surrender of drug warlord KHUN SA's Mong Tai Army in January 1996 was hailed by Rangoon as a major counternarcotics success, but lack of government will and ability to take on major narcotrafficking groups and lack of serious commitment against money laundering continues to hinder the overall antidrug effort; becoming a major source of methamphetamines for regional consumption</Illicitdrugs>
690</record>
691<record>
692<Location>Western Africa, bordering the North Atlantic Ocean, between Nigeria and Togo</Location>
693<Geographiccoordinates>9 30 N, 2 15 E</Geographiccoordinates>
694<Area>112620</Area>
695<Climate>tropical; hot, humid in south; semiarid in north</Climate>
696<Naturalresources>small offshore oil deposits, limestone, marble, timber</Naturalresources>
697<Population>6395919</Population>
698<Populationgrowthrate>3.03% (2000 est.)</Populationgrowthrate>
699<Sexratio>
700at birth: 1.03 male(s)/female
701under 15 years: 1.02 male(s)/female
70215-64 years: 0.93 male(s)/female
70365 years and over: 0.76 male(s)/female
704total population: 0.97 male(s)/female (2000 est.)</Sexratio>
705<Religions>indigenous beliefs 70%, Muslim 15%, Christian 15%</Religions>
706<Countryname>Benin </Countryname>
707<Capital>Porto-Novo is the official capital; Cotonou is the seat of government</Capital>
708<Flagdescription>two equal horizontal bands of yellow (top) and red with a vertical green band on the hoist side</Flagdescription>
709<GDP>purchasing power parity - $8.1 billion (1999 est.)</GDP>
710<Industries>textiles, cigarettes; beverages, food; construction materials, petroleum</Industries>
711<Exports>$396 million (f.o.b., 1999)</Exports>
712<Imports>$566 million (f.o.b., 1999)</Imports>
713<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
714<Airports>5 (1999 est.)</Airports>
715<Illicitdrugs>transshipment point for narcotics associated with Nigerian trafficking organizations and most commonly destined for Western Europe and the US</Illicitdrugs>
716</record>
717<record>
718<Location>Eastern Europe, east of Poland</Location>
719<Geographiccoordinates>53 00 N, 28 00 E</Geographiccoordinates>
720<Area>207600</Area>
721<Climate>cold winters, cool and moist summers; transitional between continental and maritime</Climate>
722<Naturalresources>forests, peat deposits, small quantities of oil and natural gas</Naturalresources>
723<Population>10366719</Population>
724<Populationgrowthrate>-0.17% (2000 est.)</Populationgrowthrate>
725<Sexratio>
726at birth: 1.05 male(s)/female
727under 15 years: 1.04 male(s)/female
72815-64 years: 0.94 male(s)/female
72965 years and over: 0.49 male(s)/female
730total population: 0.88 male(s)/female (2000 est.)</Sexratio>
731<Religions>Eastern Orthodox 80%, other (including Roman Catholic, Protestant, Jewish, and Muslim) 20% (1997 est.)</Religions>
732<Countryname>Belarus </Countryname>
733<Capital>Minsk</Capital>
734<Flagdescription>red horizontal band (top) and green horizontal band one-half the width of the red band; a white vertical stripe on the hoist side bears the Belarusian national ornament in red</Flagdescription>
735<GDP>purchasing power parity - $55.2 billion (1999 est.)</GDP>
736<Industries>metal-cutting machine tools, tractors, trucks, earth movers, motorcycles, TV sets, chemical fibers, fertilizer, textiles, radios, refrigerators</Industries>
737<Exports>$6 billion (f.o.b., 1999)</Exports>
738<Imports>$6.4 billion (c.i.f., 1999)</Imports>
739<Currency>Belarusian rubel (BR)</Currency>
740<Airports>118 (1996 est.)</Airports>
741<Illicitdrugs>limited cultivation of opium poppy and cannabis, mostly for the domestic market; transshipment point for illicit drugs to and via Russia, and to the Baltics and Western Europe</Illicitdrugs>
742</record>
743<record>
744<Location>Oceania, group of islands in the South Pacific Ocean, east of Papua New Guinea</Location>
745<Geographiccoordinates>8 00 S, 159 00 E</Geographiccoordinates>
746<Area>28450</Area>
747<Climate>tropical monsoon; few extremes of temperature and weather</Climate>
748<Naturalresources>fish, forests, gold, bauxite, phosphates, lead, zinc, nickel</Naturalresources>
749<Population>466194</Population>
750<Populationgrowthrate>3.04% (2000 est.)</Populationgrowthrate>
751<Sexratio>
752at birth: 1.05 male(s)/female
753under 15 years: 1.04 male(s)/female
75415-64 years: 1.03 male(s)/female
75565 years and over: 0.97 male(s)/female
756total population: 1.03 male(s)/female (2000 est.)</Sexratio>
757<Religions>Anglican 34%, Roman Catholic 19%, Baptist 17%, United (Methodist/Presbyterian) 11%, Seventh-Day Adventist 10%, other Protestant 5%, indigenous beliefs 4%</Religions>
758<Countryname>Solomon Islands </Countryname>
759<Capital>Honiara</Capital>
760<Flagdescription>divided diagonally by a thin yellow stripe from the lower hoist-side corner; the upper triangle (hoist side) is blue with five white five-pointed stars arranged in an X pattern; the lower triangle is green</Flagdescription>
761<GDP>purchasing power parity - $1.21 billion (1999 est.)</GDP>
762<Industries>fish (tuna), mining, timber</Industries>
763<Exports>$142 million (f.o.b., 1998 est.)</Exports>
764<Imports>$160 million (c.i.f., 1998 est.)</Imports>
765<Currency>1 Solomon Islands dollar (SI$) = 100 cents</Currency>
766<Airports>33 (1999 est.)</Airports>
767</record>
768<record>
769<Location>Caribbean, island in the Caribbean Sea, about one-fourth of the way from Haiti to Jamaica</Location>
770<Geographiccoordinates>18 25 N, 75 02 W</Geographiccoordinates>
771<Area>5</Area>
772<Climate>marine, tropical</Climate>
773<Naturalresources>guano</Naturalresources>
774<Population></Population>
775<Countryname>Navassa Island </Countryname>
776<Flagdescription>the flag of the US is used</Flagdescription>
777</record>
778<record>
779<Location>Eastern South America, bordering the Atlantic Ocean</Location>
780<Geographiccoordinates>10 00 S, 55 00 W</Geographiccoordinates>
781<Area>8511965</Area>
782<Climate>mostly tropical, but temperate in south</Climate>
783<Naturalresources>bauxite, gold, iron ore, manganese, nickel, phosphates, platinum, tin, uranium, petroleum, hydropower, timber</Naturalresources>
784<Population>172860370</Population>
785<Populationgrowthrate>0.94% (2000 est.)</Populationgrowthrate>
786<Sexratio>
787at birth: 1.05 male(s)/female
788under 15 years: 1.04 male(s)/female
78915-64 years: 0.97 male(s)/female
79065 years and over: 0.68 male(s)/female
791total population: 0.97 male(s)/female (2000 est.)</Sexratio>
792<Religions>Roman Catholic (nominal) 80%</Religions>
793<Countryname>Brazil </Countryname>
794<Capital>Brasilia</Capital>
795<Flagdescription>green with a large yellow diamond in the center bearing a blue celestial globe with 27 white five-pointed stars (one for each state and the Federal District) arranged in the same pattern as the night sky over Brazil; the globe has a white equatorial band with the motto ORDEM E PROGRESSO (Order and Progress)</Flagdescription>
796<GDP>purchasing power parity - $1.057 trillion (1999 est.)</GDP>
797<Industries>textiles, shoes, chemicals, cement, lumber, iron ore, tin, steel, aircraft, motor vehicles and parts, other machinery and equipment</Industries>
798<Exports>$46.9 billion (f.o.b., 1999)</Exports>
799<Imports>$48.7 billion (f.o.b., 1999)</Imports>
800<Currency>1 real (R$) = 100 centavos</Currency>
801<Airports>3,277 (1999 est.)</Airports>
802<Illicitdrugs>limited illicit producer of cannabis, minor coca cultivation in the Amazon region, mostly used for domestic consumption; government has a large-scale eradication program to control cannabis; important transshipment country for Bolivian, Colombian, and Peruvian cocaine headed for the US and Europe; increasingly used by traffickers as a way station for narcotics air transshipments between Peru and Colombia; upsurge in drug-related violence and weapons smuggling</Illicitdrugs>
803</record>
804<record>
805<Location>Southern Africa, islands in the southern Mozambique Channel, about one-half of the way from Madagascar to Mozambique</Location>
806<Geographiccoordinates>21 30 S, 39 50 E</Geographiccoordinates>
807<Area>0</Area>
808<Climate>tropical</Climate>
809<Naturalresources>none</Naturalresources>
810<Population></Population>
811<Countryname>Bassas da India </Countryname>
812<Flagdescription>the flag of France is used</Flagdescription>
813</record>
814<record>
815<Location>Southern Asia, between China and India</Location>
816<Geographiccoordinates>27 30 N, 90 30 E</Geographiccoordinates>
817<Area>47000</Area>
818<Climate>varies; tropical in southern plains; cool winters and hot summers in central valleys; severe winters and cool summers in Himalayas</Climate>
819<Naturalresources>timber, hydropower, gypsum, calcium carbide</Naturalresources>
820<Population>2005222</Population>
821<Populationgrowthrate>2.19% (2000 est.)</Populationgrowthrate>
822<Sexratio>
823at birth: 1.05 male(s)/female
824under 15 years: 1.08 male(s)/female
82515-64 years: 1.06 male(s)/female
82665 years and over: 1.03 male(s)/female
827total population: 1.07 male(s)/female (2000 est.)</Sexratio>
828<Religions>Lamaistic Buddhist 75%, Indian- and Nepalese-influenced Hinduism 25%</Religions>
829<Countryname>Bhutan </Countryname>
830<Capital>Thimphu</Capital>
831<Flagdescription>divided diagonally from the lower hoist side corner; the upper triangle is yellow and the lower triangle is orange; centered along the dividing line is a large black and white dragon facing away from the hoist side</Flagdescription>
832<GDP>purchasing power parity - $2.1 billion (1999 est.)</GDP>
833<Industries>cement, wood products, processed fruits, alcoholic beverages, calcium carbide</Industries>
834<Exports>$111 million (f.o.b., 1998)</Exports>
835<Imports>$136 million (c.i.f., 1998)</Imports>
836<Currency>1 ngultrum (Nu) = 100 chetrum; note - Indian currency is also legal tender</Currency>
837<Airports>2 (1999 est.)</Airports>
838</record>
839<record>
840<Location>Southeastern Europe, bordering the Black Sea, between Romania and Turkey</Location>
841<Geographiccoordinates>43 00 N, 25 00 E</Geographiccoordinates>
842<Area>110910</Area>
843<Climate>temperate; cold, damp winters; hot, dry summers</Climate>
844<Naturalresources>bauxite, copper, lead, zinc, coal, timber, arable land</Naturalresources>
845<Population>7796694</Population>
846<Populationgrowthrate>-1.16% (2000 est.)</Populationgrowthrate>
847<Sexratio>
848at birth: 1.06 male(s)/female
849under 15 years: 1.05 male(s)/female
85015-64 years: 0.97 male(s)/female
85165 years and over: 0.74 male(s)/female
852total population: 0.94 male(s)/female (2000 est.)</Sexratio>
853<Religions>Bulgarian Orthodox 83.5%, Muslim 13%, Roman Catholic 1.5%, Jewish 0.8%, Uniate Catholic 0.2%, Protestant, Gregorian-Armenian, and other 1% (1998)</Religions>
854<Countryname>Bulgaria </Countryname>
855<Capital>Sofia</Capital>
856<Flagdescription>three equal horizontal bands of white (top), green, and red; the national emblem formerly on the hoist side of the white stripe has been removed - it contained a rampant lion within a wreath of wheat ears below a red five-pointed star and above a ribbon bearing the dates 681 (first Bulgarian state established) and 1944 (liberation from Nazi control)</Flagdescription>
857<GDP>purchasing power parity - $34.9 billion (1999 est.)</GDP>
858<Industries>machine building and metal working, food processing, chemicals, construction materials, ferrous and nonferrous metals, nuclear fuel</Industries>
859<Exports>$3.8 billion (f.o.b., 1999 est.)</Exports>
860<Imports>$5.3 billion (f.o.b., 1999 est.)</Imports>
861<Currency>1 lev (Lv) = 100 stotinki</Currency>
862<Airports>216 (1999 est.)</Airports>
863<Illicitdrugs>major European transshipment point for Southwest Asian heroin and, to a lesser degree, South American cocaine for the European market; limited producer of precursor chemicals</Illicitdrugs>
864</record>
865<record>
866<Location>Southern Africa, island in the South Atlantic Ocean, south-southwest of the Cape of Good Hope (South Africa)</Location>
867<Geographiccoordinates>54 26 S, 3 24 E</Geographiccoordinates>
868<Area>58</Area>
869<Climate>antarctic</Climate>
870<Naturalresources>none</Naturalresources>
871<Population></Population>
872<Countryname>Bouvet Island </Countryname>
873<Flagdescription>the flag of Norway is used</Flagdescription>
874</record>
875<record>
876<Location>Southeastern Asia, bordering the South China Sea and Malaysia</Location>
877<Geographiccoordinates>4 30 N, 114 40 E</Geographiccoordinates>
878<Area>5770</Area>
879<Climate>tropical; hot, humid, rainy</Climate>
880<Naturalresources>petroleum, natural gas, timber</Naturalresources>
881<Population>336376</Population>
882<Populationgrowthrate>2.17% (2000 est.)</Populationgrowthrate>
883<Sexratio>
884at birth: 1.06 male(s)/female
885under 15 years: 1.04 male(s)/female
88615-64 years: 1.14 male(s)/female
88765 years and over: 0.94 male(s)/female
888total population: 1.1 male(s)/female (2000 est.)</Sexratio>
889<Religions>Muslim (official) 67%, Buddhist 13%, Christian 10%, indigenous beliefs and other 10%</Religions>
890<Countryname>Brunei </Countryname>
891<Capital>Bandar Seri Begawan</Capital>
892<Flagdescription>yellow with two diagonal bands of white (top, almost double width) and black starting from the upper hoist side; the national emblem in red is superimposed at the center; the emblem includes a swallow-tailed flag on top of a winged column within an upturned crescent above a scroll and flanked by two upraised hands</Flagdescription>
893<GDP>purchasing power parity - $5.6 billion (1999 est.)</GDP>
894<Industries>petroleum, petroleum refining, liquefied natural gas, construction</Industries>
895<Exports>$2.04 billion (f.o.b., 1998 est.)</Exports>
896<Imports>$1.38 billion (c.i.f., 1998 est.)</Imports>
897<Currency>1 Bruneian dollar (B$) = 100 cents</Currency>
898<Airports>2 (1999 est.)</Airports>
899</record>
900<record>
901<Location>Central Africa, east of Democratic Republic of the Congo</Location>
902<Geographiccoordinates>3 30 S, 30 00 E</Geographiccoordinates>
903<Area>27830</Area>
904<Climate>equatorial; high plateau with considerable altitude variation (772 m to 2,670 m); average annual temperature varies with altitude from 23 to 17 degrees centigrade but is generally moderate as the average altitude is about 1,700 m; average annual rainfall is about 150 cm; wet seasons from February to May and September to November, and dry seasons from June to August and December to January</Climate>
905<Naturalresources>nickel, uranium, rare earth oxides, peat, cobalt, copper, platinum (not yet exploited), vanadium, arable land, hydropower</Naturalresources>
906<Population>6054714</Population>
907<Populationgrowthrate>3.15% (2000 est.)</Populationgrowthrate>
908<Sexratio>
909at birth: 1.03 male(s)/female
910under 15 years: 1.02 male(s)/female
91115-64 years: 0.96 male(s)/female
91265 years and over: 0.71 male(s)/female
913total population: 0.98 male(s)/female (2000 est.)</Sexratio>
914<Religions>Christian 67% (Roman Catholic 62%, Protestant 5%), indigenous beliefs 23%, Muslim 10%</Religions>
915<Countryname>Burundi </Countryname>
916<Capital>Bujumbura</Capital>
917<Flagdescription>divided by a white diagonal cross into red panels (top and bottom) and green panels (hoist side and outer side) with a white disk superimposed at the center bearing three red six-pointed stars outlined in green arranged in a triangular design (one star above, two stars below)</Flagdescription>
918<GDP>purchasing power parity - $4.2 billion (1999 est.)</GDP>
919<Industries>light consumer goods such as blankets, shoes, soap; assembly of imported components; public works construction; food processing</Industries>
920<Exports>$56 million (f.o.b., 1999)</Exports>
921<Imports>$108 million (f.o.b., 1999)</Imports>
922<Currency>1 Burundi franc (FBu) = 100 centimes</Currency>
923<Airports>4 (1999 est.)</Airports>
924</record>
925<record>
926<Location>Northern North America, bordering the North Atlantic Ocean and North Pacific Ocean, north of the conterminous US</Location>
927<Geographiccoordinates>60 00 N, 95 00 W</Geographiccoordinates>
928<Area>9976140</Area>
929<Climate>varies from temperate in south to subarctic and arctic in north</Climate>
930<Naturalresources>iron ore, nickel, zinc, copper, gold, lead, molybdenum, potash, silver, fish, timber, wildlife, coal, petroleum, natural gas, hydropower</Naturalresources>
931<Population>31281092</Population>
932<Populationgrowthrate>1.02% (2000 est.)</Populationgrowthrate>
933<Sexratio>
934at birth: 1.05 male(s)/female
935under 15 years: 1.05 male(s)/female
93615-64 years: 1.01 male(s)/female
93765 years and over: 0.74 male(s)/female
938total population: 0.98 male(s)/female (2000 est.)</Sexratio>
939<Religions>Roman Catholic 42%, Protestant 40%, other 18%</Religions>
940<Countryname>Canada </Countryname>
941<Capital>Ottawa</Capital>
942<Flagdescription>three vertical bands of red (hoist side), white (double width, square), and red with a red maple leaf centered in the white band</Flagdescription>
943<GDP>purchasing power parity - $722.3 billion (1999 est.)</GDP>
944<Industries>processed and unprocessed minerals, food products, wood and paper products, transportation equipment, chemicals, fish products, petroleum and natural gas</Industries>
945<Exports>$277 billion (f.o.b., 1999 est.)</Exports>
946<Imports>$259.3 billion (f.o.b., 1999 est.)</Imports>
947<Currency>1 Canadian dollar (Can$) = 100 cents</Currency>
948<Airports>1,411 (1999 est.)</Airports>
949<Illicitdrugs>illicit producer of cannabis for the domestic drug market; use of hydroponics technology permits growers to plant large quantities of high-quality marijuana indoors; growing role as a transit point for heroin and cocaine entering the US market</Illicitdrugs>
950</record>
951<record>
952<Location>Southeastern Asia, bordering the Gulf of Thailand, between Thailand, Vietnam, and Laos</Location>
953<Geographiccoordinates>13 00 N, 105 00 E</Geographiccoordinates>
954<Area>181040</Area>
955<Climate>tropical; rainy, monsoon season (May to November); dry season (December to April); little seasonal temperature variation</Climate>
956<Naturalresources>timber, gemstones, some iron ore, manganese, phosphates, hydropower potential</Naturalresources>
957<Population>12212306</Population>
958<Populationgrowthrate>2.27% (2000 est.)</Populationgrowthrate>
959<Sexratio>
960at birth: 1.05 male(s)/female
961under 15 years: 1.04 male(s)/female
96215-64 years: 0.88 male(s)/female
96365 years and over: 0.7 male(s)/female
964total population: 0.94 male(s)/female (2000 est.)</Sexratio>
965<Religions>Theravada Buddhist 95%, other 5%</Religions>
966<Countryname>Cambodia </Countryname>
967<Capital>Phnom Penh</Capital>
968<Flagdescription>three horizontal bands of blue (top), red (double width), and blue with a white three-towered temple representing Angkor Wat outlined in black in the center of the red band</Flagdescription>
969<GDP>purchasing power parity - $8.2 billion (1999 est.)</GDP>
970<Industries>garments, rice milling, fishing, wood and wood products, rubber, cement, gem mining, textiles</Industries>
971<Exports>$821 million (f.o.b., 1999 est.)</Exports>
972<Imports>$1.2 billion (f.o.b., 1999 est.)</Imports>
973<Currency>1 new riel (CR) = 100 sen</Currency>
974<Airports>19 (1999 est.)</Airports>
975<Illicitdrugs>transshipment site for Golden Triangle heroin; possible money laundering; narcotics-related corruption reportedly involving some in the government, military, and police; possible small-scale opium, heroin, and amphetamine production; large producer of cannabis for the international market</Illicitdrugs>
976</record>
977<record>
978<Location>Central Africa, south of Libya</Location>
979<Geographiccoordinates>15 00 N, 19 00 E</Geographiccoordinates>
980<Area>1000000</Area>
981<Climate>tropical in south, desert in north</Climate>
982<Naturalresources>petroleum (unexploited but exploration under way), uranium, natron, kaolin, fish (Lake Chad)</Naturalresources>
983<Population>8424504</Population>
984<Populationgrowthrate>3.31% (2000 est.)</Populationgrowthrate>
985<Sexratio>
986at birth: 1.04 male(s)/female
987under 15 years: 1.01 male(s)/female
98815-64 years: 0.89 male(s)/female
98965 years and over: 0.72 male(s)/female
990total population: 0.94 male(s)/female (2000 est.)</Sexratio>
991<Religions>Muslim 50%, Christian 25%, indigenous beliefs (mostly animism) 25%</Religions>
992<Countryname>Chad </Countryname>
993<Capital>N'Djamena</Capital>
994<Flagdescription>three equal vertical bands of blue (hoist side), yellow, and red; similar to the flag of Romania; also similar to the flags of Andorra and Moldova, both of which have a national coat of arms centered in the yellow band; design was based on the flag of France</Flagdescription>
995<GDP>purchasing power parity - $7.6 billion (1999 est.)</GDP>
996<Industries>cotton textiles, meat packing, beer brewing, natron (sodium carbonate), soap, cigarettes, construction materials</Industries>
997<Exports>$288 million (f.o.b., 1999 est.)</Exports>
998<Imports>$359 million (f.o.b., 1999 est.)</Imports>
999<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
1000<Airports>49 (1999 est.)</Airports>
1001</record>
1002<record>
1003<Location>Southern Asia, island in the Indian Ocean, south of India</Location>
1004<Geographiccoordinates>7 00 N, 81 00 E</Geographiccoordinates>
1005<Area>65610</Area>
1006<Climate>tropical monsoon; northeast monsoon (December to March); southwest monsoon (June to October)</Climate>
1007<Naturalresources>limestone, graphite, mineral sands, gems, phosphates, clay, hydropower</Naturalresources>
1008<Population>19238575</Population>
1009<Populationgrowthrate>0.89% (2000 est.)</Populationgrowthrate>
1010<Sexratio>
1011at birth: 1.05 male(s)/female
1012under 15 years: 1.05 male(s)/female
101315-64 years: 0.95 male(s)/female
101465 years and over: 0.93 male(s)/female
1015total population: 0.97 male(s)/female (2000 est.)</Sexratio>
1016<Religions>Buddhist 70%, Hindu 15%, Christian 8%, Muslim 7% (1999)</Religions>
1017<Countryname>Sri Lanka </Countryname>
1018<Capital>Colombo</Capital>
1019<Flagdescription>yellow with two panels; the smaller hoist-side panel has two equal vertical bands of green (hoist side) and orange; the other panel is a large dark red rectangle with a yellow lion holding a sword, and there is a yellow bo leaf in each corner; the yellow field appears as a border that goes around the entire flag and extends between the two panels</Flagdescription>
1020<GDP>purchasing power parity - $50.5 billion (1999 est.)</GDP>
1021<Industries>processing of rubber, tea, coconuts, and other agricultural commodities; clothing, cement, petroleum refining, textiles, tobacco</Industries>
1022<Exports>$4.7 billion (f.o.b., 1998)</Exports>
1023<Imports>$5.3 billion (f.o.b., 1998)</Imports>
1024<Currency>1 Sri Lankan rupee (SLRe) = 100 cents</Currency>
1025<Airports>14 (1999 est.)</Airports>
1026</record>
1027<record>
1028<Location>Western Africa, bordering the South Atlantic Ocean, between Angola and Gabon</Location>
1029<Geographiccoordinates>1 00 S, 15 00 E</Geographiccoordinates>
1030<Area>342000</Area>
1031<Climate>tropical; rainy season (March to June); dry season (June to October); constantly high temperatures and humidity; particularly enervating climate astride the Equator</Climate>
1032<Naturalresources>petroleum, timber, potash, lead, zinc, uranium, copper, phosphates, natural gas, hydropower</Naturalresources>
1033<Population>2830961</Population>
1034<Populationgrowthrate>2.23% (2000 est.)</Populationgrowthrate>
1035<Sexratio>
1036at birth: 1.03 male(s)/female
1037under 15 years: 1.01 male(s)/female
103815-64 years: 0.95 male(s)/female
103965 years and over: 0.67 male(s)/female
1040total population: 0.97 male(s)/female (2000 est.)</Sexratio>
1041<Religions>Christian 50%, animist 48%, Muslim 2%</Religions>
1042<Countryname>Republic of the Congo </Countryname>
1043<Capital>Brazzaville</Capital>
1044<Flagdescription>divided diagonally from the lower hoist side by a yellow band; the upper triangle (hoist side) is green and the lower triangle is red; uses the popular pan-African colors of Ethiopia</Flagdescription>
1045<GDP>purchasing power parity - $4.15 billion (1999 est.)</GDP>
1046<Industries>petroleum extraction, cement kilning, lumbering, brewing, sugar milling, palm oil, soap, cigarette making</Industries>
1047<Exports>$1.7 billion (f.o.b., 1999)</Exports>
1048<Imports>$770 million (f.o.b., 1999)</Imports>
1049<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
1050<Airports>36 (1999 est.)</Airports>
1051</record>
1052<record>
1053<Location>Central Africa, northeast of Angola</Location>
1054<Geographiccoordinates>0 00 N, 25 00 E</Geographiccoordinates>
1055<Area>2345410</Area>
1056<Climate>tropical; hot and humid in equatorial river basin; cooler and drier in southern highlands; cooler and wetter in eastern highlands; north of Equator - wet season April to October, dry season December to February; south of Equator - wet season November to March, dry season April to October</Climate>
1057<Naturalresources>cobalt, copper, cadmium, petroleum, industrial and gem diamonds, gold, silver, zinc, manganese, tin, germanium, uranium, radium, bauxite, iron ore, coal, hydropower, timber</Naturalresources>
1058<Population>51964999</Population>
1059<Populationgrowthrate>3.19% (2000 est.)</Populationgrowthrate>
1060<Sexratio>
1061at birth: 1.03 male(s)/female
1062under 15 years: 1.01 male(s)/female
106315-64 years: 0.96 male(s)/female
106465 years and over: 0.74 male(s)/female
1065total population: 0.98 male(s)/female (2000 est.)</Sexratio>
1066<Religions>Roman Catholic 50%, Protestant 20%, Kimbanguist 10%, Muslim 10%, other syncretic sects and indigenous beliefs 10%</Religions>
1067<Countryname>Democratic Republic of the Congo </Countryname>
1068<Capital>Kinshasa</Capital>
1069<Flagdescription>light blue with a large yellow five-pointed star in the center and a columnar arrangement of six small yellow five-pointed stars along the hoist side</Flagdescription>
1070<GDP>purchasing power parity - $35.7 billion (1999 est.)</GDP>
1071<Industries>mining, mineral processing, consumer products (including textiles, footwear, cigarettes, processed foods and beverages), cement, diamonds</Industries>
1072<Exports>$530 million (f.o.b., 1998 est.)</Exports>
1073<Imports>$460 million (f.o.b., 1998 est.)</Imports>
1074<Currency>Congolese franc (CF)</Currency>
1075<Airports>232 (1999 est.)</Airports>
1076<Illicitdrugs>illicit producer of cannabis, mostly for domestic consumption</Illicitdrugs>
1077</record>
1078<record>
1079<Location>Eastern Asia, bordering the East China Sea, Korea Bay, Yellow Sea, and South China Sea, between North Korea and Vietnam</Location>
1080<Geographiccoordinates>35 00 N, 105 00 E</Geographiccoordinates>
1081<Area>9596960</Area>
1082<Climate>extremely diverse; tropical in south to subarctic in north</Climate>
1083<Naturalresources>coal, iron ore, petroleum, natural gas, mercury, tin, tungsten, antimony, manganese, molybdenum, vanadium, magnetite, aluminum, lead, zinc, uranium, hydropower potential (world's largest)</Naturalresources>
1084<Population>1261832482</Population>
1085<Populationgrowthrate>0.9% (2000 est.)</Populationgrowthrate>
1086<Sexratio>
1087at birth: 1.15 male(s)/female
1088under 15 years: 1.1 male(s)/female
108915-64 years: 1.06 male(s)/female
109065 years and over: 0.88 male(s)/female
1091total population: 1.06 male(s)/female (2000 est.)</Sexratio>
1092<Religions>Daoist (Taoist), Buddhist, Muslim 2%-3%, Christian 1% (est.)
1093note: officially atheist</Religions>
1094<Countryname>China </Countryname>
1095<Capital>Beijing</Capital>
1096<Flagdescription>red with a large yellow five-pointed star and four smaller yellow five-pointed stars (arranged in a vertical arc toward the middle of the flag) in the upper hoist-side corner</Flagdescription>
1097<GDP>purchasing power parity - $4.8 trillion (1999 est.)</GDP>
1098<Industries>iron and steel, coal, machine building, armaments, textiles and apparel, petroleum, cement, chemical fertilizers, footwear, toys, food processing, automobiles, consumer electronics, telecommunications</Industries>
1099<Exports>$194.9 billion (f.o.b., 1999)</Exports>
1100<Imports>$165.8 billion (c.i.f., 1999)</Imports>
1101<Currency>1 yuan = 10 jiao</Currency>
1102<Airports>206 (1996 est.)</Airports>
1103<Illicitdrugs>major transshipment point for heroin produced in the Golden Triangle; growing domestic drug abuse problem</Illicitdrugs>
1104</record>
1105<record>
1106<Location>Southern South America, bordering the South Atlantic Ocean and South Pacific Ocean, between Argentina and Peru</Location>
1107<Geographiccoordinates>30 00 S, 71 00 W</Geographiccoordinates>
1108<Area>756950</Area>
1109<Climate>temperate; desert in north; Mediterranean in central region; cool and damp in south</Climate>
1110<Naturalresources>copper, timber, iron ore, nitrates, precious metals, molybdenum, hydropower</Naturalresources>
1111<Population>15153797</Population>
1112<Populationgrowthrate>1.17% (2000 est.)</Populationgrowthrate>
1113<Sexratio>
1114at birth: 1.05 male(s)/female
1115under 15 years: 1.05 male(s)/female
111615-64 years: 0.99 male(s)/female
111765 years and over: 0.71 male(s)/female
1118total population: 0.98 male(s)/female (2000 est.)</Sexratio>
1119<Religions>Roman Catholic 89%, Protestant 11%, Jewish NEGL</Religions>
1120<Countryname>Chile </Countryname>
1121<Capital>Santiago</Capital>
1122<Flagdescription>two equal horizontal bands of white (top) and red; there is a blue square the same height as the white band at the hoist-side end of the white band; the square bears a white five-pointed star in the center; design was based on the US flag</Flagdescription>
1123<GDP>purchasing power parity - $185.1 billion (1999 est.)</GDP>
1124<Industries>copper, other minerals, foodstuffs, fish processing, iron and steel, wood and wood products, transport equipment, cement, textiles</Industries>
1125<Exports>$15.6 billion (f.o.b., 1999)</Exports>
1126<Imports>$13.9 billion (c.i.f., 1999)</Imports>
1127<Currency>1 Chilean peso (Ch$) = 100 centavos</Currency>
1128<Airports>370 (1999 est.)</Airports>
1129<Illicitdrugs>a growing transshipment country for cocaine destined for the US and Europe; economic prosperity has made Chile more attractive to traffickers seeking to launder drug profits; imported precursors passed on to Bolivia; domestic cocaine consumption is rising</Illicitdrugs>
1130</record>
1131<record>
1132<Location>Caribbean, island group in Caribbean Sea, nearly one-half of the way from Cuba to Honduras</Location>
1133<Geographiccoordinates>19 30 N, 80 30 W</Geographiccoordinates>
1134<Area>259</Area>
1135<Climate>tropical marine; warm, rainy summers (May to October) and cool, relatively dry winters (November to April)</Climate>
1136<Naturalresources>fish, climate and beaches that foster tourism</Naturalresources>
1137<Population>34763</Population>
1138<Populationgrowthrate>2.22% (2000 est.)</Populationgrowthrate>
1139<Sexratio>
1140at birth: 0.86 male(s)/female
1141under 15 years: 0.94 male(s)/female
114215-64 years: 0.96 male(s)/female
114365 years and over: 0.85 male(s)/female
1144total population: 0.94 male(s)/female (2000 est.)</Sexratio>
1145<Religions>United Church (Presbyterian and Congregational), Anglican, Baptist, Roman Catholic, Church of God, other Protestant</Religions>
1146<Countryname>Cayman Islands </Countryname>
1147<Capital>George Town</Capital>
1148<Flagdescription>blue, with the flag of the UK in the upper hoist-side quadrant and the Caymanian coat of arms on a white disk centered on the outer half of the flag; the coat of arms includes a pineapple and turtle above a shield with three stars (representing the three islands) and a scroll at the bottom bearing the motto HE HATH FOUNDED IT UPON THE SEAS</Flagdescription>
1149<GDP>purchasing power parity - $930 million (1997 est.)</GDP>
1150<Industries>tourism, banking, insurance and finance, construction, construction materials, furniture</Industries>
1151<Exports>$2.17 million (1997)</Exports>
1152<Imports>$432 million (1997)</Imports>
1153<Currency>1 Caymanian dollar (CI$) = 100 cents</Currency>
1154<Airports>3 (1999 est.)</Airports>
1155<Illicitdrugs>vulnerable to drug money laundering and drug transshipment</Illicitdrugs>
1156</record>
1157<record>
1158<Location>Southeastern Asia, group of islands in the Indian Ocean, south of Indonesia, about one-half of the way from Australia to Sri Lanka</Location>
1159<Geographiccoordinates>12 30 S, 96 50 E</Geographiccoordinates>
1160<Area>14</Area>
1161<Climate>pleasant, modified by the southeast trade winds for about nine months of the year; moderate rainfall</Climate>
1162<Naturalresources>fish</Naturalresources>
1163<Population>635</Population>
1164<Populationgrowthrate>-0.21% (2000 est.)</Populationgrowthrate>
1165<Religions>Sunni Muslim 57%, Christian 22%, other 21% (1981 est.)</Religions>
1166<Countryname>Cocos (Keeling) Islands </Countryname>
1167<Capital>West Island</Capital>
1168<Flagdescription>the flag of Australia is used</Flagdescription>
1169<GDP>purchasing power parity - $NA</GDP>
1170<Industries>copra products and tourism</Industries>
1171<Exports>$NA</Exports>
1172<Imports>$NA</Imports>
1173<Currency>1 Australian dollar ($A) = 100 cents</Currency>
1174<Airports>1 (1999 est.)</Airports>
1175</record>
1176<record>
1177<Location>Western Africa, bordering the Bight of Biafra, between Equatorial Guinea and Nigeria</Location>
1178<Geographiccoordinates>6 00 N, 12 00 E</Geographiccoordinates>
1179<Area>475440</Area>
1180<Climate>varies with terrain, from tropical along coast to semiarid and hot in north</Climate>
1181<Naturalresources>petroleum, bauxite, iron ore, timber, hydropower</Naturalresources>
1182<Population>15421937</Population>
1183<Populationgrowthrate>2.47% (2000 est.)</Populationgrowthrate>
1184<Sexratio>
1185at birth: 1.03 male(s)/female
1186under 15 years: 1.02 male(s)/female
118715-64 years: 1.01 male(s)/female
118865 years and over: 0.86 male(s)/female
1189total population: 1.01 male(s)/female (2000 est.)</Sexratio>
1190<Religions>indigenous beliefs 40%, Christian 40%, Muslim 20%</Religions>
1191<Countryname>Cameroon </Countryname>
1192<Capital>Yaounde</Capital>
1193<Flagdescription>three equal vertical bands of green (hoist side), red, and yellow with a yellow five-pointed star centered in the red band; uses the popular pan-African colors of Ethiopia</Flagdescription>
1194<GDP>purchasing power parity - $31.5 billion (1999 est.)</GDP>
1195<Industries>petroleum production and refining, food processing, light consumer goods, textiles, lumber</Industries>
1196<Exports>$2 billion (f.o.b., 1999)</Exports>
1197<Imports>$1.5 billion (f.o.b., 1999)</Imports>
1198<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
1199<Airports>50 (1999 est.)</Airports>
1200</record>
1201<record>
1202<Location>Southern Africa, group of islands in the Mozambique Channel, about two-thirds of the way between northern Madagascar and northern Mozambique</Location>
1203<Geographiccoordinates>12 10 S, 44 15 E</Geographiccoordinates>
1204<Area>2170</Area>
1205<Climate>tropical marine; rainy season (November to May)</Climate>
1206<Naturalresources>NEGL</Naturalresources>
1207<Population>578400</Population>
1208<Populationgrowthrate>3.05% (2000 est.)</Populationgrowthrate>
1209<Sexratio>
1210at birth: 1.03 male(s)/female
1211under 15 years: 1.01 male(s)/female
121215-64 years: 0.97 male(s)/female
121365 years and over: 0.91 male(s)/female
1214total population: 0.99 male(s)/female (2000 est.)</Sexratio>
1215<Religions>Sunni Muslim 98%, Roman Catholic 2%</Religions>
1216<Countryname>Comoros </Countryname>
1217<Capital>Moroni</Capital>
1218<Flagdescription>green with a white crescent in the center of the field, its points facing downward; there are four white five-pointed stars placed in a line between the points of the crescent; the crescent, stars, and color green are traditional symbols of Islam; the four stars represent the four main islands of the archipelago - Mwali, Njazidja, Nzwani, and Mayotte (a territorial collectivity of France, but claimed by Comoros); the design, the most recent of several, is described in the constitution approved by referendum on 7 June 1992</Flagdescription>
1219<GDP>purchasing power parity - $410 million (1998 est.)</GDP>
1220<Industries>tourism, perfume distillation, textiles, furniture, jewelry, construction materials, soft drinks</Industries>
1221<Exports>$9.3 million (f.o.b., 1998 est.)</Exports>
1222<Imports>$49.5 million (f.o.b., 1998 est.)</Imports>
1223<Currency>1 Comoran franc (CF) = 100 centimes</Currency>
1224<Airports>4 (1999 est.)</Airports>
1225</record>
1226<record>
1227<Location>Northern South America, bordering the Caribbean Sea, between Panama and Venezuela, and bordering the North Pacific Ocean, between Ecuador and Panama</Location>
1228<Geographiccoordinates>4 00 N, 72 00 W</Geographiccoordinates>
1229<Area>1138910</Area>
1230<Climate>tropical along coast and eastern plains; cooler in highlands</Climate>
1231<Naturalresources>petroleum, natural gas, coal, iron ore, nickel, gold, copper, emeralds, hydropower</Naturalresources>
1232<Population>39685655</Population>
1233<Populationgrowthrate>1.68% (2000 est.)</Populationgrowthrate>
1234<Sexratio>
1235at birth: 1.03 male(s)/female
1236under 15 years: 1.02 male(s)/female
123715-64 years: 0.95 male(s)/female
123865 years and over: 0.82 male(s)/female
1239total population: 0.97 male(s)/female (2000 est.)</Sexratio>
1240<Religions>Roman Catholic 90%</Religions>
1241<Countryname>Colombia </Countryname>
1242<Capital>Bogota</Capital>
1243<Flagdescription>three horizontal bands of yellow (top, double-width), blue, and red; similar to the flag of Ecuador, which is longer and bears the Ecuadorian coat of arms superimposed in the center</Flagdescription>
1244<GDP>purchasing power parity - $245.1 billion (1999 est.)</GDP>
1245<Industries>textiles, food processing, oil, clothing and footwear, beverages, chemicals, cement; gold, coal, emeralds</Industries>
1246<Exports>$11.5 billion (f.o.b., 1999 est.)</Exports>
1247<Imports>$10 billion (f.o.b., 1999 est.)</Imports>
1248<Currency>1 Colombian peso (Col$) = 100 centavos</Currency>
1249<Airports>1,101 (1999 est.)</Airports>
1250<Illicitdrugs>illicit producer of coca, opium poppies, and cannabis; world's leading coca cultivator (cultivation of coca in 1998 - 101,500 hectares, a 28% increase over 1997); cultivation of opium in 1998 remained steady at 6,600 hectares; potential production of opium in 1997 - 66 metric tons, a 5% increase over 1996; the world's largest processor of coca derivatives into cocaine; supplier of cocaine to the US and other international drug markets, and an important supplier of heroin to the US market; active aerial eradication program</Illicitdrugs>
1251</record>
1252<record>
1253<Location>Oceania, islands in the North Pacific Ocean, about three-quarters of the way from Hawaii to the Philippines</Location>
1254<Geographiccoordinates>15 12 N, 145 45 E</Geographiccoordinates>
1255<Area>477</Area>
1256<Climate>tropical marine; moderated by northeast trade winds, little seasonal temperature variation; dry season December to June, rainy season July to October</Climate>
1257<Naturalresources>arable land, fish</Naturalresources>
1258<Population>71912</Population>
1259<Populationgrowthrate>3.75% (2000 est.)</Populationgrowthrate>
1260<Sexratio>
1261at birth: 1.06 male(s)/female
1262under 15 years: 1.03 male(s)/female
126315-64 years: 0.9 male(s)/female
126465 years and over: 0.96 male(s)/female
1265total population: 0.93 male(s)/female (2000 est.)</Sexratio>
1266<Religions>Christian (Roman Catholic majority, although traditional beliefs and taboos may still be found)</Religions>
1267<Countryname>Northern Mariana Islands </Countryname>
1268<Capital>Saipan</Capital>
1269<Flagdescription>blue, with a white, five-pointed star superimposed on the gray silhouette of a latte stone (a traditional foundation stone used in building) in the center, surrounded by a wreath</Flagdescription>
1270<GDP>purchasing power parity - $524 million (1996 est.)
1271note: GDP numbers reflect US spending</GDP>
1272<Industries>tourism, construction, garments, handicrafts</Industries>
1273<Exports>$1 billion (1998)</Exports>
1274<Imports>$NA</Imports>
1275<Currency>1 United States dollar (US$) = 100 cents</Currency>
1276<Airports>6 (1999 est.)</Airports>
1277</record>
1278<record>
1279<Location>Oceania, islands in the Coral Sea, northeast of Australia</Location>
1280<Geographiccoordinates>18 00 S, 152 00 E</Geographiccoordinates>
1281<Area></Area>
1282<Climate>tropical</Climate>
1283<Naturalresources>NEGL</Naturalresources>
1284<Population></Population>
1285<Countryname>Coral Sea Islands </Countryname>
1286<Flagdescription>the flag of Australia is used</Flagdescription>
1287</record>
1288<record>
1289<Location>Middle America, bordering both the Caribbean Sea and the North Pacific Ocean, between Nicaragua and Panama</Location>
1290<Geographiccoordinates>10 00 N, 84 00 W</Geographiccoordinates>
1291<Area>51100</Area>
1292<Climate>tropical and subtropical; dry season (December to April); rainy season (May to November); cooler in highlands</Climate>
1293<Naturalresources>hydropower</Naturalresources>
1294<Population>3710558</Population>
1295<Populationgrowthrate>1.69% (2000 est.)</Populationgrowthrate>
1296<Sexratio>
1297at birth: 1.05 male(s)/female
1298under 15 years: 1.05 male(s)/female
129915-64 years: 1.02 male(s)/female
130065 years and over: 0.87 male(s)/female
1301total population: 1.02 male(s)/female (2000 est.)</Sexratio>
1302<Religions>Roman Catholic 85%, Evangelical Protestant, approximately 14%, other less than 1%</Religions>
1303<Countryname>Costa Rica </Countryname>
1304<Capital>San Jose</Capital>
1305<Flagdescription>five horizontal bands of blue (top), white, red (double width), white, and blue, with the coat of arms in a white disk on the hoist side of the red band</Flagdescription>
1306<GDP>purchasing power parity - $26 billion (1999 est.)</GDP>
1307<Industries>microprocessors, food processing, textiles and clothing, construction materials, fertilizer, plastic products</Industries>
1308<Exports>$6.4 billion (f.o.b., 1999 est.)</Exports>
1309<Imports>$6.5 billion (c.i.f., 1999 est.)</Imports>
1310<Currency>1 Costa Rican colon (C) = 100 centimos</Currency>
1311<Airports>155 (1999 est.)</Airports>
1312<Illicitdrugs>transshipment country for cocaine and heroin from South America; illicit production of cannabis on small, scattered plots; domestic cocaine consumption has risen</Illicitdrugs>
1313</record>
1314<record>
1315<Location>Central Africa, north of Democratic Republic of the Congo</Location>
1316<Geographiccoordinates>7 00 N, 21 00 E</Geographiccoordinates>
1317<Area>622984</Area>
1318<Climate>tropical; hot, dry winters; mild to hot, wet summers</Climate>
1319<Naturalresources>diamonds, uranium, timber, gold, oil, hydropower</Naturalresources>
1320<Population>3512751</Population>
1321<Populationgrowthrate>1.77% (2000 est.)</Populationgrowthrate>
1322<Sexratio>
1323at birth: 1.03 male(s)/female
1324under 15 years: 1.01 male(s)/female
132515-64 years: 0.96 male(s)/female
132665 years and over: 0.8 male(s)/female
1327total population: 0.98 male(s)/female (2000 est.)</Sexratio>
1328<Religions>indigenous beliefs 24%, Protestant 25%, Roman Catholic 25%, Muslim 15%, other 11%
1329note: animistic beliefs and practices strongly influence the Christian majority</Religions>
1330<Countryname>Central African Republic </Countryname>
1331<Capital>Bangui</Capital>
1332<Flagdescription>four equal horizontal bands of blue (top), white, green, and yellow with a vertical red band in center; there is a yellow five-pointed star on the hoist side of the blue band</Flagdescription>
1333<GDP>purchasing power parity - $5.8 billion (1999 est.)</GDP>
1334<Industries>diamond mining, sawmills, breweries, textiles, footwear, assembly of bicycles and motorcycles</Industries>
1335<Exports>$195 million (f.o.b., 1999)</Exports>
1336<Imports>$170 million (f.o.b., 1999)</Imports>
1337<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
1338<Airports>52 (1999 est.)</Airports>
1339</record>
1340<record>
1341<Location>Caribbean, island between the Caribbean Sea and the North Atlantic Ocean, south of Florida</Location>
1342<Geographiccoordinates>21 30 N, 80 00 W</Geographiccoordinates>
1343<Area>110860</Area>
1344<Climate>tropical; moderated by trade winds; dry season (November to April); rainy season (May to October)</Climate>
1345<Naturalresources>cobalt, nickel, iron ore, copper, manganese, salt, timber, silica, petroleum, arable land</Naturalresources>
1346<Population>11141997</Population>
1347<Populationgrowthrate>0.39% (2000 est.)</Populationgrowthrate>
1348<Sexratio>
1349at birth: 1.06 male(s)/female
1350under 15 years: 1.06 male(s)/female
135115-64 years: 1.01 male(s)/female
135265 years and over: 0.87 male(s)/female
1353total population: 1 male(s)/female (2000 est.)</Sexratio>
1354<Religions>nominally 85% Roman Catholic prior to CASTRO assuming power; Protestants, Jehovah's Witnesses, Jews, and Santeria are also represented</Religions>
1355<Countryname>Cuba </Countryname>
1356<Capital>Havana</Capital>
1357<Flagdescription>five equal horizontal bands of blue (top and bottom) alternating with white; a red equilateral triangle based on the hoist side bears a white, five-pointed star in the center</Flagdescription>
1358<GDP>purchasing power parity - $18.6 billion (1999 est.)</GDP>
1359<Industries>sugar, petroleum, food, tobacco, textiles, chemicals, paper and wood products, metals (particularly nickel), cement, fertilizers, consumer goods, agricultural machinery</Industries>
1360<Exports>$1.4 billion (f.o.b., 1999 est.)</Exports>
1361<Imports>$3.2 billion (c.i.f., 1999 est.)</Imports>
1362<Currency>1 Cuban peso (Cu$) = 100 centavos</Currency>
1363<Airports>170 (1999 est.)</Airports>
1364<Illicitdrugs>territorial waters and air space serve as transshipment zone for cocaine bound for the US and Europe; established the death penalty for certain drug-related crimes in 1999</Illicitdrugs>
1365</record>
1366<record>
1367<Location>Western Africa, group of islands in the North Atlantic Ocean, west of Senegal</Location>
1368<Geographiccoordinates>16 00 N, 24 00 W</Geographiccoordinates>
1369<Area>4033</Area>
1370<Climate>temperate; warm, dry summer; precipitation meager and very erratic</Climate>
1371<Naturalresources>salt, basalt rock, pozzuolana (a siliceous volcanic ash used to produce hydraulic cement), limestone, kaolin, fish</Naturalresources>
1372<Population>401343</Population>
1373<Populationgrowthrate>0.98% (2000 est.)</Populationgrowthrate>
1374<Sexratio>
1375at birth: 1.03 male(s)/female
1376under 15 years: 1.02 male(s)/female
137715-64 years: 0.9 male(s)/female
137865 years and over: 0.65 male(s)/female
1379total population: 0.93 male(s)/female (2000 est.)</Sexratio>
1380<Religions>Roman Catholic (infused with indigenous beliefs); Protestant (mostly Church of the Nazarene)</Religions>
1381<Countryname>Cape Verde </Countryname>
1382<Capital>Praia</Capital>
1383<Flagdescription>three horizontal bands of light blue (top, double width), white (with a horizontal red stripe in the middle third), and light blue; a circle of 10 yellow five-pointed stars is centered on the hoist end of the red stripe and extends into the upper and lower blue bands</Flagdescription>
1384<GDP>purchasing power parity - $618 million (1999 est.)</GDP>
1385<Industries>food and beverages, fish processing, shoes and garments, salt mining, ship repair</Industries>
1386<Exports>$38 million (f.o.b., 1999 est.)</Exports>
1387<Imports>$225 million (f.o.b., 1999 est.)</Imports>
1388<Currency>1 Cape Verdean escudo (CVEsc) = 100 centavos</Currency>
1389<Airports>6 (1999 est.)</Airports>
1390<Illicitdrugs>used as a transshipment point for illicit drugs moving from Latin America and Africa destined for Western Europe</Illicitdrugs>
1391</record>
1392<record>
1393<Location>Oceania, group of islands in the South Pacific Ocean, about one-half of the way from Hawaii to New Zealand</Location>
1394<Geographiccoordinates>21 14 S, 159 46 W</Geographiccoordinates>
1395<Area>240</Area>
1396<Climate>tropical; moderated by trade winds</Climate>
1397<Naturalresources>NEGL</Naturalresources>
1398<Population>20407</Population>
1399<Populationgrowthrate>1.6% (2000 est.)</Populationgrowthrate>
1400<Religions>Christian (majority of populace are members of the Cook Islands Christian Church)</Religions>
1401<Countryname>Cook Islands </Countryname>
1402<Capital>Avarua</Capital>
1403<Flagdescription>blue, with the flag of the UK in the upper hoist-side quadrant and a large circle of 15 white five-pointed stars (one for every island) centered in the outer half of the flag</Flagdescription>
1404<GDP>purchasing power parity - $112 million (1998 est.)</GDP>
1405<Industries>fruit processing, tourism</Industries>
1406<Exports>$4.2 million (f.o.b., 1994 est.)</Exports>
1407<Imports>$85 million (c.i.f., 1994)</Imports>
1408<Currency>1 New Zealand dollar (NZ$) = 100 cents</Currency>
1409<Airports>7 (1999 est.)</Airports>
1410</record>
1411<record>
1412<Location>Middle East, island in the Mediterranean Sea, south of Turkey</Location>
1413<Geographiccoordinates>35 00 N, 33 00 E</Geographiccoordinates>
1414<Area>9250</Area>
1415<Climate>temperate, Mediterranean with hot, dry summers and cool, winters</Climate>
1416<Naturalresources>copper, pyrites, asbestos, gypsum, timber, salt, marble, clay earth pigment</Naturalresources>
1417<Population>758363</Population>
1418<Populationgrowthrate>0.6% (2000 est.)</Populationgrowthrate>
1419<Sexratio>
1420at birth: 1.05 male(s)/female
1421under 15 years: 1.05 male(s)/female
142215-64 years: 1.02 male(s)/female
142365 years and over: 0.77 male(s)/female
1424total population: 1 male(s)/female (2000 est.)</Sexratio>
1425<Religions>Greek Orthodox 78%, Muslim 18%, Maronite, Armenian Apostolic, and other 4%</Religions>
1426<Countryname>Cyprus </Countryname>
1427<Capital>Nicosia
1428note: the Turkish Cypriot area's capital is Lefkosa (Nicosia)</Capital>
1429<Flagdescription>white with a copper-colored silhouette of the island (the name Cyprus is derived from the Greek word for copper) above two green crossed olive branches in the center of the flag; the branches symbolize the hope for peace and reconciliation between the Greek and Turkish communities
1430note: the Turkish Cypriot flag has a horizontal red stripe at the top and bottom between which is a red crescent and red star on a white field</Flagdescription>
1431<GDP>Greek Cypriot area: purchasing power parity - $9 billion; Turkish Cypriot area: purchasing power parity - $820 million (1998 est.)</GDP>
1432<Industries>food, beverages, textiles, chemicals, metal products, tourism, wood products</Industries>
1433<Exports>Greek Cypriot area: $1.1 billion (f.o.b., 1998 est.); Turkish Cypriot area: $63.9 million (f.o.b., 1998)</Exports>
1434<Imports>Greek Cypriot area: $3.5 billion (f.o.b., 1998 est.); Turkish Cypriot area: $374 million (f.o.b., 1997)</Imports>
1435<Currency>Greek Cypriot area: 1 Cypriot pound = 100 cents; Turkish Cypriot area: 1 Turkish lira (TL) = 100 kurus</Currency>
1436<Airports>15 (1999 est.)</Airports>
1437<Illicitdrugs>minor transit point for heroin and hashish via air routes and container traffic to Europe, especially from Lebanon and Turkey; some cocaine transits as well</Illicitdrugs>
1438</record>
1439<record>
1440<Location>Northern Europe, bordering the Baltic Sea and the North Sea, on a peninsula north of Germany</Location>
1441<Geographiccoordinates>56 00 N, 10 00 E</Geographiccoordinates>
1442<Area>43094</Area>
1443<Climate>temperate; humid and overcast; mild, windy winters and cool summers</Climate>
1444<Naturalresources>petroleum, natural gas, fish, salt, limestone, stone, gravel and sand</Naturalresources>
1445<Population>5336394</Population>
1446<Populationgrowthrate>0.31% (2000 est.)</Populationgrowthrate>
1447<Sexratio>
1448at birth: 1.05 male(s)/female
1449under 15 years: 1.05 male(s)/female
145015-64 years: 1.03 male(s)/female
145165 years and over: 0.71 male(s)/female
1452total population: 0.98 male(s)/female (2000 est.)</Sexratio>
1453<Religions>Evangelical Lutheran 97%, other Protestant and Roman Catholic, other</Religions>
1454<Countryname>Denmark </Countryname>
1455<Capital>Copenhagen</Capital>
1456<Flagdescription>red with a white cross that extends to the edges of the flag; the vertical part of the cross is shifted to the hoist side, and that design element of the Dannebrog (Danish flag) was subsequently adopted by the other Nordic countries of Finland, Iceland, Norway, and Sweden</Flagdescription>
1457<GDP>purchasing power parity - $127.7 billion (1999 est.)</GDP>
1458<Industries>food processing, machinery and equipment, textiles and clothing, chemical products, electronics, construction, furniture, and other wood products, shipbuilding</Industries>
1459<Exports>$49.5 billion (f.o.b., 1999)</Exports>
1460<Imports>$43.9 billion (f.o.b., 1999)</Imports>
1461<Currency>1 Danish krone (DKr) = 100 oere</Currency>
1462<Airports>118 (1999 est.)</Airports>
1463</record>
1464<record>
1465<Location>Eastern Africa, bordering the Gulf of Aden and the Red Sea, between Eritrea and Somalia</Location>
1466<Geographiccoordinates>11 30 N, 43 00 E</Geographiccoordinates>
1467<Area>22000</Area>
1468<Climate>desert; torrid, dry</Climate>
1469<Naturalresources>geothermal areas</Naturalresources>
1470<Population>451442</Population>
1471<Populationgrowthrate>1.45% (2000 est.)</Populationgrowthrate>
1472<Sexratio>
1473at birth: 1.03 male(s)/female
1474under 15 years: 1 male(s)/female
147515-64 years: 1.12 male(s)/female
147665 years and over: 1.08 male(s)/female
1477total population: 1.07 male(s)/female (2000 est.)</Sexratio>
1478<Religions>Muslim 94%, Christian 6%</Religions>
1479<Countryname>Djibouti </Countryname>
1480<Capital>Djibouti</Capital>
1481<Flagdescription>two equal horizontal bands of light blue (top) and light green with a white isosceles triangle based on the hoist side bearing a red five-pointed star in the center</Flagdescription>
1482<GDP>purchasing power parity - $550 million (1999 est.)</GDP>
1483<Industries>limited to a few small-scale enterprises, such as dairy products and mineral-water bottling</Industries>
1484<Exports>$260 million (f.o.b., 1999 est.)</Exports>
1485<Imports>$440 million (f.o.b., 1999 est.)</Imports>
1486<Currency>1 Djiboutian franc (DF) = 100 centimes</Currency>
1487<Airports>12 (1999 est.)</Airports>
1488</record>
1489<record>
1490<Location>Caribbean, island between the Caribbean Sea and the North Atlantic Ocean, about one-half of the way from Puerto Rico to Trinidad and Tobago</Location>
1491<Geographiccoordinates>15 25 N, 61 20 W</Geographiccoordinates>
1492<Area>754</Area>
1493<Climate>tropical; moderated by northeast trade winds; heavy rainfall</Climate>
1494<Naturalresources>timber, hydropower, arable land</Naturalresources>
1495<Population>71540</Population>
1496<Populationgrowthrate>-1.14% (2000 est.)</Populationgrowthrate>
1497<Sexratio>
1498at birth: 1.05 male(s)/female
1499under 15 years: 1.03 male(s)/female
150015-64 years: 1.05 male(s)/female
150165 years and over: 0.69 male(s)/female
1502total population: 1.01 male(s)/female (2000 est.)</Sexratio>
1503<Religions>Roman Catholic 77%, Protestant 15% (Methodist 5%, Pentecostal 3%, Seventh-Day Adventist 3%, Baptist 2%, other 2%), none 2%, other 6%</Religions>
1504<Countryname>Dominica </Countryname>
1505<Capital>Roseau</Capital>
1506<Flagdescription>green, with a centered cross of three equal bands - the vertical part is yellow (hoist side), black, and white and the horizontal part is yellow (top), black, and white; superimposed in the center of the cross is a red disk bearing a sisserou parrot encircled by 10 green, five-pointed stars edged in yellow; the 10 stars represent the 10 administrative divisions (parishes)</Flagdescription>
1507<GDP>purchasing power parity - $225 million (1998 est.)</GDP>
1508<Industries>soap, coconut oil, tourism, copra, furniture, cement blocks, shoes</Industries>
1509<Exports>$60.8 million (1998)</Exports>
1510<Imports>$120.4 million (1998)</Imports>
1511<Currency>1 East Caribbean dollar (EC$) = 100 cents</Currency>
1512<Airports>2 (1999 est.)</Airports>
1513<Illicitdrugs>transshipment point for narcotics bound for the US and Europe; minor cannabis producer; banking industry is vulnerable to money laundering</Illicitdrugs>
1514</record>
1515<record>
1516<Location>Oceania, island in the South Pacific Ocean, about one-half of the way from Hawaii to the Cook Islands</Location>
1517<Geographiccoordinates>0 22 S, 160 03 W</Geographiccoordinates>
1518<Area>4</Area>
1519<Climate>tropical; scant rainfall, constant wind, burning sun</Climate>
1520<Naturalresources>guano (deposits worked until late 1800s)</Naturalresources>
1521<Population></Population>
1522<Countryname>Jarvis Island </Countryname>
1523<Flagdescription>the flag of the US is used</Flagdescription>
1524</record>
1525<record>
1526<Location>Caribbean, eastern two-thirds of the island of Hispaniola, between the Caribbean Sea and the North Atlantic Ocean, east of Haiti</Location>
1527<Geographiccoordinates>19 00 N, 70 40 W</Geographiccoordinates>
1528<Area>48730</Area>
1529<Climate>tropical maritime; little seasonal temperature variation; seasonal variation in rainfall</Climate>
1530<Naturalresources>nickel, bauxite, gold, silver</Naturalresources>
1531<Population>8442533</Population>
1532<Populationgrowthrate>1.64% (2000 est.)</Populationgrowthrate>
1533<Sexratio>
1534at birth: 1.05 male(s)/female
1535under 15 years: 1.04 male(s)/female
153615-64 years: 1.04 male(s)/female
153765 years and over: 0.91 male(s)/female
1538total population: 1.03 male(s)/female (2000 est.)</Sexratio>
1539<Religions>Roman Catholic 95%</Religions>
1540<Countryname>Dominican Republic </Countryname>
1541<Capital>Santo Domingo</Capital>
1542<Flagdescription>a centered white cross that extends to the edges divides the flag into four rectangles - the top ones are blue (hoist side) and red, and the bottom ones are red (hoist side) and blue; a small coat of arms is at the center of the cross</Flagdescription>
1543<GDP>purchasing power parity - $43.7 billion (1999 est.)</GDP>
1544<Industries>tourism, sugar processing, ferronickel and gold mining, textiles, cement, tobacco</Industries>
1545<Exports>$5.1 billion (f.o.b., 1999)</Exports>
1546<Imports>$8.2 billion (f.o.b., 1999)</Imports>
1547<Currency>1 Dominican peso (RD$) = 100 centavos</Currency>
1548<Airports>28 (1999 est.)</Airports>
1549<Illicitdrugs>transshipment point for South American drugs destined for the US and Europe</Illicitdrugs>
1550</record>
1551<record>
1552<Location>Western South America, bordering the Pacific Ocean at the Equator, between Colombia and Peru</Location>
1553<Geographiccoordinates>2 00 S, 77 30 W</Geographiccoordinates>
1554<Area>283560</Area>
1555<Climate>tropical along coast, becoming cooler inland at higher elevations; tropical in Amazonian jungle lowlands</Climate>
1556<Naturalresources>petroleum, fish, timber, hydropower</Naturalresources>
1557<Population>12920092</Population>
1558<Populationgrowthrate>2.04% (2000 est.)</Populationgrowthrate>
1559<Sexratio>
1560at birth: 1.05 male(s)/female
1561under 15 years: 1.03 male(s)/female
156215-64 years: 0.98 male(s)/female
156365 years and over: 0.87 male(s)/female
1564total population: 0.99 male(s)/female (2000 est.)</Sexratio>
1565<Religions>Roman Catholic 95%</Religions>
1566<Countryname>Ecuador </Countryname>
1567<Capital>Quito</Capital>
1568<Flagdescription>three horizontal bands of yellow (top, double width), blue, and red with the coat of arms superimposed at the center of the flag; similar to the flag of Colombia which is shorter and does not bear a coat of arms</Flagdescription>
1569<GDP>purchasing power parity - $54.5 billion (1999 est.)</GDP>
1570<Industries>petroleum, food processing, textiles, metal work, paper products, wood products, chemicals, plastics, fishing, lumber</Industries>
1571<Exports>$4.1 billion (f.o.b., 1999)</Exports>
1572<Imports>$2.8 billion (c.i.f., 1999)</Imports>
1573<Currency>1 sucre (S/) = 100 centavos</Currency>
1574<Airports>182 (1999 est.)</Airports>
1575<Illicitdrugs>significant transit country for cocaine and derivatives of coca originating in Colombia and Peru; importer of precursor chemicals used in production of illicit narcotics; important money-laundering hub; increased activity on frontiers by trafficking groups and Colombian insurgents</Illicitdrugs>
1576</record>
1577<record>
1578<Location>Northern Africa, bordering the Mediterranean Sea, between Libya and the Gaza Strip</Location>
1579<Geographiccoordinates>27 00 N, 30 00 E</Geographiccoordinates>
1580<Area>1001450</Area>
1581<Climate>desert; hot, dry summers with moderate winters</Climate>
1582<Naturalresources>petroleum, natural gas, iron ore, phosphates, manganese, limestone, gypsum, talc, asbestos, lead, zinc</Naturalresources>
1583<Population>68359979</Population>
1584<Populationgrowthrate>1.72% (2000 est.)</Populationgrowthrate>
1585<Sexratio>
1586at birth: 1.05 male(s)/female
1587under 15 years: 1.05 male(s)/female
158815-64 years: 1.02 male(s)/female
158965 years and over: 0.79 male(s)/female
1590total population: 1.02 male(s)/female (2000 est.)</Sexratio>
1591<Religions>Muslim (mostly Sunni) 94%, Coptic Christian and other 6%</Religions>
1592<Countryname>Egypt </Countryname>
1593<Capital>Cairo</Capital>
1594<Flagdescription>three equal horizontal bands of red (top), white, and black with the national emblem (a shield superimposed on a golden eagle facing the hoist side above a scroll bearing the name of the country in Arabic) centered in the white band; similar to the flag of Yemen, which has a plain white band; also similar to the flag of Syria, which has two green stars, and to the flag of Iraq, which has three green stars (plus an Arabic inscription) in a horizontal line centered in the white band</Flagdescription>
1595<GDP>purchasing power parity - $200 billion (1999 est.)</GDP>
1596<Industries>textiles, food processing, tourism, chemicals, petroleum, construction, cement, metals</Industries>
1597<Exports>$4.6 billion (f.o.b., 1999 est.)</Exports>
1598<Imports>$15.8 billion (f.o.b., 1999 est.)</Imports>
1599<Currency>1 Egyptian pound = 100 piasters</Currency>
1600<Airports>90 (1999 est.)</Airports>
1601<Illicitdrugs>a transit point for Southwest Asian and Southeast Asian heroin and opium moving to Europe, Africa, and the US; popular transit stop for Nigerian couriers</Illicitdrugs>
1602</record>
1603<record>
1604<Location>Western Europe, occupying five-sixths of the island of Ireland in the North Atlantic Ocean, west of Great Britain</Location>
1605<Geographiccoordinates>53 00 N, 8 00 W</Geographiccoordinates>
1606<Area>70280</Area>
1607<Climate>temperate maritime; modified by North Atlantic Current; mild winters, cool summers; consistently humid; overcast about half the time</Climate>
1608<Naturalresources>zinc, lead, natural gas, barite, copper, gypsum, limestone, dolomite, peat, silver</Naturalresources>
1609<Population>3797257</Population>
1610<Populationgrowthrate>1.16% (2000 est.)</Populationgrowthrate>
1611<Sexratio>
1612at birth: 1.07 male(s)/female
1613under 15 years: 1.06 male(s)/female
161415-64 years: 1 male(s)/female
161565 years and over: 0.76 male(s)/female
1616total population: 0.98 male(s)/female (2000 est.)</Sexratio>
1617<Religions>Roman Catholic 91.6%, Church of Ireland 2.5%, other 5.9% (1998)</Religions>
1618<Countryname>Ireland </Countryname>
1619<Capital>Dublin</Capital>
1620<Flagdescription>three equal vertical bands of green (hoist side), white, and orange; similar to the flag of Cote d'Ivoire, which is shorter and has the colors reversed - orange (hoist side), white, and green; also similar to the flag of Italy, which is shorter and has colors of green (hoist side), white, and red</Flagdescription>
1621<GDP>purchasing power parity - $73.7 billion (1999 est.)</GDP>
1622<Industries>food products, brewing, textiles, clothing; chemicals, pharmaceuticals, machinery, transportation equipment, glass and crystal; software</Industries>
1623<Exports>$66 billion (f.o.b., 1999 est.)</Exports>
1624<Imports>$44 billion (c.i.f., 1999 est.)</Imports>
1625<Currency>1 Irish pound = 100 pence</Currency>
1626<Airports>44 (1999 est.)</Airports>
1627<Illicitdrugs>transshipment point for and consumer of hashish from North Africa to the UK and Netherlands and of European-produced synthetic drugs; minor transshipment point for heroin and cocaine destined for Western Europe</Illicitdrugs>
1628</record>
1629<record>
1630<Location>Western Africa, bordering the Bight of Biafra, between Cameroon and Gabon</Location>
1631<Geographiccoordinates>2 00 N, 10 00 E</Geographiccoordinates>
1632<Area>28051</Area>
1633<Climate>tropical; always hot, humid</Climate>
1634<Naturalresources>oil, petroleum, timber, small unexploited deposits of gold, manganese, uranium</Naturalresources>
1635<Population>474214</Population>
1636<Populationgrowthrate>2.47% (2000 est.)</Populationgrowthrate>
1637<Sexratio>
1638at birth: 1.03 male(s)/female
1639under 15 years: 1.01 male(s)/female
164015-64 years: 0.91 male(s)/female
164165 years and over: 0.81 male(s)/female
1642total population: 0.95 male(s)/female (2000 est.)</Sexratio>
1643<Religions>nominally Christian and predominantly Roman Catholic, pagan practices</Religions>
1644<Countryname>Equatorial Guinea </Countryname>
1645<Capital>Malabo</Capital>
1646<Flagdescription>three equal horizontal bands of green (top), white, and red with a blue isosceles triangle based on the hoist side and the coat of arms centered in the white band; the coat of arms has six yellow six-pointed stars (representing the mainland and five offshore islands) above a gray shield bearing a silk-cotton tree and below which is a scroll with the motto UNIDAD, PAZ, JUSTICIA (Unity, Peace, Justice)</Flagdescription>
1647<GDP>purchasing power parity - $960 million (1999 est.)</GDP>
1648<Industries>petroleum, fishing, sawmilling, natural gas</Industries>
1649<Exports>$555 million (f.o.b., 1999)</Exports>
1650<Imports>$300 million (f.o.b., 1999)</Imports>
1651<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
1652<Airports>3 (1999 est.)</Airports>
1653</record>
1654<record>
1655<Location>Eastern Europe, bordering the Baltic Sea and Gulf of Finland, between Latvia and Russia</Location>
1656<Geographiccoordinates>59 00 N, 26 00 E</Geographiccoordinates>
1657<Area>45226</Area>
1658<Climate>maritime, wet, moderate winters, cool summers</Climate>
1659<Naturalresources>shale oil (kukersite), peat, phosphorite, amber, cambrian blue clay, limestone, dolomite, arable land</Naturalresources>
1660<Population>1431471</Population>
1661<Populationgrowthrate>-0.59% (2000 est.)</Populationgrowthrate>
1662<Sexratio>
1663at birth: 1.05 male(s)/female
1664under 15 years: 1.04 male(s)/female
166515-64 years: 0.93 male(s)/female
166665 years and over: 0.48 male(s)/female
1667total population: 0.87 male(s)/female (2000 est.)</Sexratio>
1668<Religions>Evangelical Lutheran, Russian Orthodox, Estonian Orthodox, Baptist, Methodist, Seventh-Day Adventist, Roman Catholic, Pentecostal, Word of Life, Jewish</Religions>
1669<Countryname>Estonia </Countryname>
1670<Capital>Tallinn</Capital>
1671<Flagdescription>pre-1940 flag restored by Supreme Soviet in May 1990 - three equal horizontal bands of blue (top), black, and white</Flagdescription>
1672<GDP>purchasing power parity - $7.9 billion (1999 est.)</GDP>
1673<Industries>oil shale, shipbuilding, phosphates, electric motors, excavators, cement, furniture, clothing, textiles, paper, shoes, apparel</Industries>
1674<Exports>$2.5 billion (f.o.b., 1999)</Exports>
1675<Imports>$3.4 billion (f.o.b., 1999)</Imports>
1676<Currency>1 Estonian kroon (EEK) = 100 sents</Currency>
1677<Airports>5 (1997 est.)</Airports>
1678<Illicitdrugs>transshipment point for opiates and cannabis from Southwest Asia and the Caucasus via Russia, cocaine from Latin America to Western Europe and Scandinavia, and synthetic drugs from Western Europe to Scandinavia; possible precursor manufacturing and/or trafficking</Illicitdrugs>
1679</record>
1680<record>
1681<Location>Eastern Africa, bordering the Red Sea, between Djibouti and Sudan</Location>
1682<Geographiccoordinates>15 00 N, 39 00 E</Geographiccoordinates>
1683<Area>121320</Area>
1684<Climate>hot, dry desert strip along Red Sea coast; cooler and wetter in the central highlands (up to 61 cm of rainfall annually); semiarid in western hills and lowlands; rainfall heaviest during June-September except in coastal desert</Climate>
1685<Naturalresources>gold, potash, zinc, copper, salt, possibly oil and natural gas, fish</Naturalresources>
1686<Population>4135933</Population>
1687<Populationgrowthrate>3.86% (2000 est.)</Populationgrowthrate>
1688<Sexratio>
1689at birth: 1.03 male(s)/female
1690under 15 years: 1.01 male(s)/female
169115-64 years: 0.98 male(s)/female
169265 years and over: 1.04 male(s)/female
1693total population: 0.99 male(s)/female (2000 est.)</Sexratio>
1694<Religions>Muslim, Coptic Christian, Roman Catholic, Protestant</Religions>
1695<Countryname>Eritrea </Countryname>
1696<Capital>Asmara (formerly Asmera)</Capital>
1697<Flagdescription>red isosceles triangle (based on the hoist side) dividing the flag into two right triangles; the upper triangle is green, the lower one is blue; a gold wreath encircling a gold olive branch is centered on the hoist side of the red triangle</Flagdescription>
1698<GDP>purchasing power parity - $2.9 billion (1999 est.)</GDP>
1699<Industries>food processing, beverages, clothing and textiles</Industries>
1700<Exports>$52.9 million (f.o.b., 1997)</Exports>
1701<Imports>$489.4 million (c.i.f., 1997)</Imports>
1702<Currency>1 nafka = 100 cents</Currency>
1703<Airports>21 (1999 est.)</Airports>
1704</record>
1705<record>
1706<Location>Middle America, bordering the North Pacific Ocean, between Guatemala and Honduras</Location>
1707<Geographiccoordinates>13 50 N, 88 55 W</Geographiccoordinates>
1708<Area>21040</Area>
1709<Climate>tropical; rainy season (May to October); dry season (November to April); tropical on coast; temperate in uplands</Climate>
1710<Naturalresources>hydropower, geothermal power, petroleum, arable land</Naturalresources>
1711<Population>6122515</Population>
1712<Populationgrowthrate>1.87% (2000 est.)</Populationgrowthrate>
1713<Sexratio>
1714at birth: 1.05 male(s)/female
1715under 15 years: 1.04 male(s)/female
171615-64 years: 0.9 male(s)/female
171765 years and over: 0.83 male(s)/female
1718total population: 0.95 male(s)/female (2000 est.)</Sexratio>
1719<Religions>Roman Catholic 86%
1720note: there is extensive activity by Protestant groups throughout the country; by the end of 1992, there were an estimated 1 million Protestant evangelicals in El Salvador</Religions>
1721<Countryname>El Salvador </Countryname>
1722<Capital>San Salvador</Capital>
1723<Flagdescription>three equal horizontal bands of blue (top), white, and blue with the national coat of arms centered in the white band; the coat of arms features a round emblem encircled by the words REPUBLICA DE EL SALVADOR EN LA AMERICA CENTRAL; similar to the flag of Nicaragua, which has a different coat of arms centered in the white band - it features a triangle encircled by the words REPUBLICA DE NICARAGUA on top and AMERICA CENTRAL on the bottom; also similar to the flag of Honduras, which has five blue stars arranged in an X pattern centered in the white band</Flagdescription>
1724<GDP>purchasing power parity - $18.1 billion (1999 est.)</GDP>
1725<Industries>food processing, beverages, petroleum, chemicals, fertilizer, textiles, furniture, light metals</Industries>
1726<Exports>$2.5 billion (f.o.b., 1999)</Exports>
1727<Imports>$4.15 billion (c.i.f., 1999)</Imports>
1728<Currency>1 Salvadoran colon (C) = 100 centavos</Currency>
1729<Airports>85 (1999 est.)</Airports>
1730<Illicitdrugs>transshipment point for cocaine; marijuana produced for local consumption; domestic drug abuse on the rise</Illicitdrugs>
1731</record>
1732<record>
1733<Location>Eastern Africa, west of Somalia</Location>
1734<Geographiccoordinates>8 00 N, 38 00 E</Geographiccoordinates>
1735<Area>1127127</Area>
1736<Climate>tropical monsoon with wide topographic-induced variation</Climate>
1737<Naturalresources>small reserves of gold, platinum, copper, potash, natural gas, hydropower</Naturalresources>
1738<Population>64117452</Population>
1739<Populationgrowthrate>2.76% (2000 est.)</Populationgrowthrate>
1740<Sexratio>
1741at birth: 1.03 male(s)/female
1742under 15 years: 1.01 male(s)/female
174315-64 years: 1.01 male(s)/female
174465 years and over: 0.84 male(s)/female
1745total population: 1.01 male(s)/female (2000 est.)</Sexratio>
1746<Religions>Muslim 45%-50%, Ethiopian Orthodox 35%-40%, animist 12%, other 3%-8%</Religions>
1747<Countryname>Ethiopia </Countryname>
1748<Capital>Addis Ababa</Capital>
1749<Flagdescription>three equal horizontal bands of green (top), yellow, and red with a yellow pentagram and single yellow rays emanating from the angles between the points on a light blue disk centered on the three bands; Ethiopia is the oldest independent country in Africa, and the colors of her flag were so often adopted by other African countries upon independence that they became known as the pan-African colors</Flagdescription>
1750<GDP>purchasing power parity - $33.3 billion (1999 est.)</GDP>
1751<Industries>food processing, beverages, textiles, chemicals, metals processing, cement</Industries>
1752<Exports>$420 million (f.o.b., 1998)</Exports>
1753<Imports>$1.25 billion (f.o.b., 1998 est.)</Imports>
1754<Currency>1 birr (Br) = 100 cents</Currency>
1755<Airports>85 (1999 est.)</Airports>
1756<Illicitdrugs>transit hub for heroin originating in Southwest and Southeast Asia and destined for Europe and North America as well as cocaine destined for markets in southern Africa; cultivates qat (chat) for local use and regional export, principally to Djibouti and Somalia</Illicitdrugs>
1757</record>
1758<record>
1759<Location>Southern Africa, island in the Mozambique Channel, about one-half of the way from southern Madagascar to southern Mozambique</Location>
1760<Geographiccoordinates>22 20 S, 40 22 E</Geographiccoordinates>
1761<Area>28</Area>
1762<Climate>tropical</Climate>
1763<Naturalresources>NEGL</Naturalresources>
1764<Population></Population>
1765<Countryname>Europa Island </Countryname>
1766<Flagdescription>the flag of France is used</Flagdescription>
1767<Airports>1 (1999 est.)</Airports>
1768</record>
1769<record>
1770<Location>Central Europe, southeast of Germany</Location>
1771<Geographiccoordinates>49 45 N, 15 30 E</Geographiccoordinates>
1772<Area>78866</Area>
1773<Climate>temperate; cool summers; cold, cloudy, humid winters</Climate>
1774<Naturalresources>hard coal, soft coal, kaolin, clay, graphite, timber</Naturalresources>
1775<Population>10272179</Population>
1776<Populationgrowthrate>-0.08% (2000 est.)</Populationgrowthrate>
1777<Sexratio>
1778at birth: 1.05 male(s)/female
1779under 15 years: 1.05 male(s)/female
178015-64 years: 1 male(s)/female
178165 years and over: 0.62 male(s)/female
1782total population: 0.95 male(s)/female (2000 est.)</Sexratio>
1783<Religions>atheist 39.8%, Roman Catholic 39.2%, Protestant 4.6%, Orthodox 3%, other 13.4%</Religions>
1784<Countryname>Czech Republic </Countryname>
1785<Capital>Prague</Capital>
1786<Flagdescription>two equal horizontal bands of white (top) and red with a blue isosceles triangle based on the hoist side (almost identical to the flag of the former Czechoslovakia)</Flagdescription>
1787<GDP>purchasing power parity - $120.8 billion (1999 est.)</GDP>
1788<Industries>fuels, ferrous metallurgy, machinery and equipment, coal, motor vehicles, glass, armaments</Industries>
1789<Exports>$26.9 billion (f.o.b., 1999)</Exports>
1790<Imports>$29 billion (f.o.b., 1999)</Imports>
1791<Currency>1 koruna (Kc) = 100 haleru</Currency>
1792<Airports>114 (1999 est.)</Airports>
1793<Illicitdrugs>major transshipment point for Southwest Asian heroin and minor transit point for Latin American cocaine to Western Europe; domestic consumption - especially of locally produced synthetic drugs - on the rise</Illicitdrugs>
1794</record>
1795<record>
1796<Location>Southern South America, islands in the South Atlantic Ocean, east of southern Argentina</Location>
1797<Geographiccoordinates>51 45 S, 59 00 W</Geographiccoordinates>
1798<Area>12173</Area>
1799<Climate>cold marine; strong westerly winds, cloudy, humid; rain occurs on more than half of days in year; occasional snow all year, except in January and February, but does not accumulate</Climate>
1800<Naturalresources>fish, wildlife</Naturalresources>
1801<Population>2826</Population>
1802<Populationgrowthrate>2.44% (2000 est.)</Populationgrowthrate>
1803<Religions>primarily Anglican, Roman Catholic, United Free Church, Evangelist Church, Jehovah's Witnesses, Lutheran, Seventh-Day Adventist</Religions>
1804<Countryname>Falkland Islands (Islas Malvinas) </Countryname>
1805<Capital>Stanley</Capital>
1806<Flagdescription>blue with the flag of the UK in the upper hoist-side quadrant and the Falkland Island coat of arms in a white disk centered on the outer half of the flag; the coat of arms contains a white ram (sheep raising is the major economic activity) above the sailing ship Desire (whose crew discovered the islands) with a scroll at the bottom bearing the motto DESIRE THE RIGHT</Flagdescription>
1807<GDP>purchasing power parity - $NA</GDP>
1808<Industries>wool and fish processing; sale of stamps and coins</Industries>
1809<Exports>$7.6 million (1995)</Exports>
1810<Imports>$24.7 million (1995)</Imports>
1811<Currency>1 Falkland pound = 100 pence</Currency>
1812<Airports>5 (1999 est.)</Airports>
1813</record>
1814<record>
1815<Location>Northern South America, bordering the North Atlantic Ocean, between Brazil and Suriname</Location>
1816<Geographiccoordinates>4 00 N, 53 00 W</Geographiccoordinates>
1817<Area>91000</Area>
1818<Climate>tropical; hot, humid; little seasonal temperature variation</Climate>
1819<Naturalresources>bauxite, timber, gold (widely scattered), cinnabar, kaolin, fish</Naturalresources>
1820<Population>172605</Population>
1821<Populationgrowthrate>2.93% (2000 est.)</Populationgrowthrate>
1822<Sexratio>
1823at birth: 1.05 male(s)/female
1824under 15 years: 1.05 male(s)/female
182515-64 years: 1.18 male(s)/female
182665 years and over: 1.02 male(s)/female
1827total population: 1.13 male(s)/female (2000 est.)</Sexratio>
1828<Religions>Roman Catholic</Religions>
1829<Countryname>French Guiana </Countryname>
1830<Capital>Cayenne</Capital>
1831<Flagdescription>the flag of France is used</Flagdescription>
1832<GDP>purchasing power parity - $1 billion (1998 est.)</GDP>
1833<Industries>construction, shrimp processing, forestry products, rum, gold mining</Industries>
1834<Exports>$155 million (f.o.b., 1997)</Exports>
1835<Imports>$625 million (c.i.f., 1997)</Imports>
1836<Currency>1 French franc (F) = 100 centimes</Currency>
1837<Airports>11 (1999 est.)</Airports>
1838<Illicitdrugs>small amount of marijuana grown for local consumption; minor transshipment point to Europe</Illicitdrugs>
1839</record>
1840<record>
1841<Location>Northern Europe, bordering the Baltic Sea, Gulf of Bothnia, and Gulf of Finland, between Sweden and Russia</Location>
1842<Geographiccoordinates>64 00 N, 26 00 E</Geographiccoordinates>
1843<Area>337030</Area>
1844<Climate>cold temperate; potentially subarctic, but comparatively mild because of moderating influence of the North Atlantic Current, Baltic Sea, and more than 60,000 lakes</Climate>
1845<Naturalresources>timber, copper, zinc, iron ore, silver</Naturalresources>
1846<Population>5167486</Population>
1847<Populationgrowthrate>0.17% (2000 est.)</Populationgrowthrate>
1848<Sexratio>
1849at birth: 1.04 male(s)/female
1850under 15 years: 1.04 male(s)/female
185115-64 years: 1.02 male(s)/female
185265 years and over: 0.62 male(s)/female
1853total population: 0.95 male(s)/female (2000 est.)</Sexratio>
1854<Religions>Evangelical Lutheran 89%, Greek Orthodox 1%, none 9%, other 1%</Religions>
1855<Countryname>Finland </Countryname>
1856<Capital>Helsinki</Capital>
1857<Flagdescription>white with a blue cross that extends to the edges of the flag; the vertical part of the cross is shifted to the hoist side in the style of the Dannebrog (Danish flag)</Flagdescription>
1858<GDP>purchasing power parity - $108.6 billion (1999 est.)</GDP>
1859<Industries>metal products, shipbuilding, pulp and paper, copper refining, foodstuffs, chemicals, textiles, clothing</Industries>
1860<Exports>$43 billion (f.o.b., 1998)</Exports>
1861<Imports>$30.7 billion (f.o.b., 1998)</Imports>
1862<Currency>1 markka (FMk) or Finmark = 100 pennia</Currency>
1863<Airports>157 (1999 est.)</Airports>
1864</record>
1865<record>
1866<Location>Oceania, island group in the South Pacific Ocean, about two-thirds of the way from Hawaii to New Zealand</Location>
1867<Geographiccoordinates>18 00 S, 175 00 E</Geographiccoordinates>
1868<Area>18270</Area>
1869<Climate>tropical marine; only slight seasonal temperature variation</Climate>
1870<Naturalresources>timber, fish, gold, copper, offshore oil potential, hydropower</Naturalresources>
1871<Population>832494</Population>
1872<Populationgrowthrate>1.41% (2000 est.)</Populationgrowthrate>
1873<Sexratio>
1874at birth: 1.05 male(s)/female
1875under 15 years: 1.04 male(s)/female
187615-64 years: 1 male(s)/female
187765 years and over: 0.88 male(s)/female
1878total population: 1.01 male(s)/female (2000 est.)</Sexratio>
1879<Religions>Christian 52% (Methodist 37%, Roman Catholic 9%), Hindu 38%, Muslim 8%, other 2%
1880note: Fijians are mainly Christian, Indians are Hindu, and there is a Muslim minority (1986)</Religions>
1881<Countryname>Fiji </Countryname>
1882<Capital>Suva</Capital>
1883<Flagdescription>light blue with the flag of the UK in the upper hoist-side quadrant and the Fijian shield centered on the outer half of the flag; the shield depicts a yellow lion above a white field quartered by the cross of Saint George featuring stalks of sugarcane, a palm tree, bananas, and a white dove</Flagdescription>
1884<GDP>purchasing power parity - $5.9 billion (1999 est.)</GDP>
1885<Industries>tourism, sugar, clothing, copra, gold, silver, lumber, small cottage industries</Industries>
1886<Exports>$393 million (f.o.b., 1998)</Exports>
1887<Imports>$612 million (f.o.b., 1998)</Imports>
1888<Currency>1 Fijian dollar (F$) = 100 cents</Currency>
1889<Airports>25 (1999 est.)</Airports>
1890</record>
1891<record>
1892<Location>Oceania, island group in the North Pacific Ocean, about three-quarters of the way from Hawaii to Indonesia</Location>
1893<Geographiccoordinates>6 55 N, 158 15 E</Geographiccoordinates>
1894<Area>702</Area>
1895<Climate>tropical; heavy year-round rainfall, especially in the eastern islands; located on southern edge of the typhoon belt with occasionally severe damage</Climate>
1896<Naturalresources>forests, marine products, deep-seabed minerals</Naturalresources>
1897<Population>133144</Population>
1898<Populationgrowthrate>3.28% (2000 est.)</Populationgrowthrate>
1899<Religions>Roman Catholic 50%, Protestant 47%, other and none 3%</Religions>
1900<Countryname>Federated States of Micronesia </Countryname>
1901<Capital>Palikir</Capital>
1902<Flagdescription>light blue with four white five-pointed stars centered; the stars are arranged in a diamond pattern</Flagdescription>
1903<GDP>purchasing power parity - $240 million (1997 est.)
1904note: GDP is supplemented by grant aid, averaging perhaps $100 million annually</GDP>
1905<Industries>tourism, construction, fish processing, craft items from shell, wood, and pearls</Industries>
1906<Exports>$73 million (f.o.b., 1996 est.)</Exports>
1907<Imports>$168 million (c.i.f., 1996 est.)</Imports>
1908<Currency>1 United States dollar (US$) = 100 cents</Currency>
1909<Airports>6 (1999 est.)</Airports>
1910</record>
1911<record>
1912<Location>Northern Europe, island group between the Norwegian Sea and the north Atlantic Ocean, about one-half of the way from Iceland to Norway</Location>
1913<Geographiccoordinates>62 00 N, 7 00 W</Geographiccoordinates>
1914<Area>1399</Area>
1915<Climate>mild winters, cool summers; usually overcast; foggy, windy</Climate>
1916<Naturalresources>fish, whales, hydropower</Naturalresources>
1917<Population>45296</Population>
1918<Populationgrowthrate>0.83% (2000 est.)</Populationgrowthrate>
1919<Sexratio>
1920at birth: 1.05 male(s)/female
1921under 15 years: 1.01 male(s)/female
192215-64 years: 1.14 male(s)/female
192365 years and over: 0.81 male(s)/female
1924total population: 1.06 male(s)/female (2000 est.)</Sexratio>
1925<Religions>Evangelical Lutheran</Religions>
1926<Countryname>Faroe Islands </Countryname>
1927<Capital>Torshavn</Capital>
1928<Flagdescription>white with a red cross outlined in blue that extends to the edges of the flag; the vertical part of the cross is shifted to the hoist side in the style of the Dannebrog (Danish flag)</Flagdescription>
1929<GDP>purchasing power parity - $700 million (1996 est.)</GDP>
1930<Industries>fishing, shipbuilding, construction, handicrafts</Industries>
1931<Exports>$362 million (f.o.b., 1995)</Exports>
1932<Imports>$315.6 million (c.i.f., 1995)</Imports>
1933<Currency>1 Danish krone (DKr) = 100 oere</Currency>
1934<Airports>1 (1999 est.)</Airports>
1935</record>
1936<record>
1937<Location>Oceania, archipelago in the South Pacific Ocean, about one-half of the way from South America to Australia</Location>
1938<Geographiccoordinates>15 00 S, 140 00 W</Geographiccoordinates>
1939<Area>4167</Area>
1940<Climate>tropical, but moderate</Climate>
1941<Naturalresources>timber, fish, cobalt, hydropower</Naturalresources>
1942<Population>249110</Population>
1943<Populationgrowthrate>1.78% (2000 est.)</Populationgrowthrate>
1944<Sexratio>
1945at birth: 1.05 male(s)/female
1946under 15 years: 1.04 male(s)/female
194715-64 years: 1.09 male(s)/female
194865 years and over: 1.01 male(s)/female
1949total population: 1.07 male(s)/female (2000 est.)</Sexratio>
1950<Religions>Protestant 54%, Roman Catholic 30%, other 16%</Religions>
1951<Countryname>French Polynesia </Countryname>
1952<Capital>Papeete</Capital>
1953<Flagdescription>two narrow red horizontal bands encase a wide white band; centered on the white band is a disk with blue and white wave pattern on the lower half and gold and white ray pattern on the upper half; a stylized red, blue and white ship rides on the wave pattern; the French flag is used for official occasions</Flagdescription>
1954<GDP>purchasing power parity - $2.6 billion (1997 est.)</GDP>
1955<Industries>tourism, pearls, agricultural processing, handicrafts</Industries>
1956<Exports>$212 million (f.o.b., 1996)</Exports>
1957<Imports>$860 million (c.i.f., 1996)</Imports>
1958<Currency>1 Comptoirs Francais du Pacifique franc (CFPF) = 100 centimes</Currency>
1959<Airports>45 (1999 est.)</Airports>
1960</record>
1961<record>
1962<Location>Oceania, atoll in the North Pacific Ocean, about one-half of the way from Hawaii to Australia</Location>
1963<Geographiccoordinates>0 13 N, 176 31 W</Geographiccoordinates>
1964<Area>1</Area>
1965<Climate>equatorial; scant rainfall, constant wind, burning sun</Climate>
1966<Naturalresources>guano (deposits worked until 1891)</Naturalresources>
1967<Population></Population>
1968<Countryname>Baker Island </Countryname>
1969<Flagdescription>the flag of the US is used</Flagdescription>
1970<Airports>1 abandoned World War II runway of 1,665 m, completely covered with vegetation and unusable</Airports>
1971</record>
1972<record>
1973<Location>Western Europe, bordering the Bay of Biscay and English Channel, between Belgium and Spain, southeast of the UK; bordering the Mediterranean Sea, between Italy and Spain</Location>
1974<Geographiccoordinates>46 00 N, 2 00 E</Geographiccoordinates>
1975<Area>547030</Area>
1976<Climate>generally cool winters and mild summers, but mild winters and hot summers along the Mediterranean</Climate>
1977<Naturalresources>coal, iron ore, bauxite, fish, timber, zinc, potash</Naturalresources>
1978<Population>59329691</Population>
1979<Populationgrowthrate>0.38% (2000 est.)</Populationgrowthrate>
1980<Sexratio>
1981at birth: 1.05 male(s)/female
1982under 15 years: 1.05 male(s)/female
198315-64 years: 1 male(s)/female
198465 years and over: 0.68 male(s)/female
1985total population: 0.95 male(s)/female (2000 est.)</Sexratio>
1986<Religions>Roman Catholic 90%, Protestant 2%, Jewish 1%, Muslim (North African workers) 1%, unaffiliated 6%</Religions>
1987<Countryname>France </Countryname>
1988<Capital>Paris</Capital>
1989<Flagdescription>three equal vertical bands of blue (hoist side), white, and red; known as the French Tricouleur (Tricolor); the design and colors are similar to a number of other flags, including those of Belgium, Chad, Ireland, Cote d'Ivoire, and Luxembourg; the official flag for all French dependent areas</Flagdescription>
1990<GDP>purchasing power parity - $1.373 trillion (1999 est.)</GDP>
1991<Industries>steel, machinery, chemicals, automobiles, metallurgy, aircraft, electronics, mining; textiles, food processing; tourism</Industries>
1992<Exports>$304.7 billion (f.o.b., 1999)</Exports>
1993<Imports>$280.8 billion (f.o.b., 1999)</Imports>
1994<Currency>1 French franc (F) = 100 centimes</Currency>
1995<Airports>474 (1999 est.)</Airports>
1996<Illicitdrugs>transshipment point for and consumer of South American cocaine and Southwest Asian heroin</Illicitdrugs>
1997</record>
1998<record>
1999<Location>south of Africa, islands in the southern Indian Ocean, about equidistant between Africa, Antarctica, and Australia; note - French Southern and Antarctic Lands includes Ile Amsterdam, Ile Saint-Paul, Iles Crozet, and Iles Kerguelen in the southern Indian Ocean, along with the French-claimed sector of Antarctica, "Adelie Land"; the US does not recognize the French claim to "Adelie Land"</Location>
2000<Geographiccoordinates>43 00 S, 67 00 E</Geographiccoordinates>
2001<Area>7781</Area>
2002<Climate>antarctic</Climate>
2003<Naturalresources>fish, crayfish</Naturalresources>
2004<Population></Population>
2005<Countryname>French Southern and Antarctic Lands </Countryname>
2006<Flagdescription>the flag of France is used</Flagdescription>
2007<Airports>none</Airports>
2008</record>
2009<record>
2010<Location>Western Africa, bordering the North Atlantic Ocean and Senegal</Location>
2011<Geographiccoordinates>13 28 N, 16 34 W</Geographiccoordinates>
2012<Area>11300</Area>
2013<Climate>tropical; hot, rainy season (June to November); cooler, dry season (November to May)</Climate>
2014<Naturalresources>fish</Naturalresources>
2015<Population>1367124</Population>
2016<Populationgrowthrate>3.2% (2000 est.)</Populationgrowthrate>
2017<Sexratio>
2018at birth: 1.03 male(s)/female
2019under 15 years: 1.01 male(s)/female
202015-64 years: 0.98 male(s)/female
202165 years and over: 1.11 male(s)/female
2022total population: 1 male(s)/female (2000 est.)</Sexratio>
2023<Religions>Muslim 90%, Christian 9%, indigenous beliefs 1%</Religions>
2024<Countryname>The Gambia </Countryname>
2025<Capital>Banjul</Capital>
2026<Flagdescription>three equal horizontal bands of red (top), blue with white edges, and green</Flagdescription>
2027<GDP>purchasing power parity - $1.4 billion (1999 est.)</GDP>
2028<Industries>processing peanuts, fish, and hides; tourism; beverages; agricultural machinery assembly, woodworking, metalworking; clothing</Industries>
2029<Exports>$132 million (f.o.b., 1998)</Exports>
2030<Imports>$201 million (f.o.b., 1998)</Imports>
2031<Currency>1 dalasi (D) = 100 butut</Currency>
2032<Airports>1 (1999 est.)</Airports>
2033</record>
2034<record>
2035<Location>Western Africa, bordering the Atlantic Ocean at the Equator, between Republic of the Congo and Equatorial Guinea</Location>
2036<Geographiccoordinates>1 00 S, 11 45 E</Geographiccoordinates>
2037<Area>267667</Area>
2038<Climate>tropical; always hot, humid</Climate>
2039<Naturalresources>petroleum, manganese, uranium, gold, timber, iron ore, hydropower</Naturalresources>
2040<Population>1208436</Population>
2041<Populationgrowthrate>1.08% (2000 est.)</Populationgrowthrate>
2042<Sexratio>
2043at birth: 1.03 male(s)/female
2044under 15 years: 1 male(s)/female
204515-64 years: 1.02 male(s)/female
204665 years and over: 0.98 male(s)/female
2047total population: 1.01 male(s)/female (2000 est.)</Sexratio>
2048<Religions>Christian 55%-75%, Muslim less than 1%, animist</Religions>
2049<Countryname>Gabon </Countryname>
2050<Capital>Libreville</Capital>
2051<Flagdescription>three equal horizontal bands of green (top), yellow, and blue</Flagdescription>
2052<GDP>purchasing power parity - $7.9 billion (1999 est.)</GDP>
2053<Industries>food and beverage; textile; lumbering and plywood; cement; petroleum extraction and refining; manganese, uranium, and gold mining; chemicals; ship repair</Industries>
2054<Exports>$2.4 billion (f.o.b., 1999 est.)</Exports>
2055<Imports>$1.2 billion (f.o.b., 1999 est.)</Imports>
2056<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
2057<Airports>61 (1999 est.)</Airports>
2058</record>
2059<record>
2060<Location>Southwestern Asia, bordering the Black Sea, between Turkey and Russia</Location>
2061<Geographiccoordinates>42 00 N, 43 30 E</Geographiccoordinates>
2062<Area>69700</Area>
2063<Climate>warm and pleasant; Mediterranean-like on Black Sea coast</Climate>
2064<Naturalresources>forests, hydropower, manganese deposits, iron ore, copper, minor coal and oil deposits; coastal climate and soils allow for important tea and citrus growth</Naturalresources>
2065<Population>5019538</Population>
2066<Populationgrowthrate>-0.62% (2000 est.)</Populationgrowthrate>
2067<Sexratio>
2068at birth: 1.05 male(s)/female
2069under 15 years: 1.04 male(s)/female
207015-64 years: 0.93 male(s)/female
207165 years and over: 0.63 male(s)/female
2072total population: 0.91 male(s)/female (2000 est.)</Sexratio>
2073<Religions>Georgian Orthodox 65%, Muslim 11%, Russian Orthodox 10%, Armenian Apostolic 8%, unknown 6%</Religions>
2074<Countryname>Georgia </Countryname>
2075<Capital>T'bilisi</Capital>
2076<Flagdescription>maroon field with small rectangle in upper hoist side corner; rectangle divided horizontally with black on top, white below</Flagdescription>
2077<GDP>purchasing power parity - $11.7 billion (1999 est.)</GDP>
2078<Industries>steel, aircraft, machine tools, electric locomotives, trucks, tractors, textiles, shoes, chemicals, wood products, wine</Industries>
2079<Exports>$330 million (1999 est.)</Exports>
2080<Imports>$840 million (1999 est.)</Imports>
2081<Currency>1 lari (GEL) = 100 tetri</Currency>
2082<Airports>28 (1994 est.)</Airports>
2083<Illicitdrugs>limited cultivation of cannabis and opium poppy, mostly for domestic consumption; used as transshipment point for opiates via Central Asia to Western Europe and Russia</Illicitdrugs>
2084</record>
2085<record>
2086<Location>Western Africa, bordering the Gulf of Guinea, between Cote d'Ivoire and Togo</Location>
2087<Geographiccoordinates>8 00 N, 2 00 W</Geographiccoordinates>
2088<Area>238540</Area>
2089<Climate>tropical; warm and comparatively dry along southeast coast; hot and humid in southwest; hot and dry in north</Climate>
2090<Naturalresources>gold, timber, industrial diamonds, bauxite, manganese, fish, rubber, hydropower</Naturalresources>
2091<Population>19533560</Population>
2092<Populationgrowthrate>1.87% (2000 est.)</Populationgrowthrate>
2093<Sexratio>
2094at birth: 1.03 male(s)/female
2095under 15 years: 1.01 male(s)/female
209615-64 years: 0.98 male(s)/female
209765 years and over: 0.91 male(s)/female
2098total population: 0.99 male(s)/female (2000 est.)</Sexratio>
2099<Religions>indigenous beliefs 38%, Muslim 30%, Christian 24%, other 8%</Religions>
2100<Countryname>Ghana </Countryname>
2101<Capital>Accra</Capital>
2102<Flagdescription>three equal horizontal bands of red (top), yellow, and green with a large black five-pointed star centered in the yellow band; uses the popular pan-African colors of Ethiopia; similar to the flag of Bolivia, which has a coat of arms centered in the yellow band</Flagdescription>
2103<GDP>purchasing power parity - $35.5 billion (1999 est.)</GDP>
2104<Industries>mining, lumbering, light manufacturing, aluminum smelting, food processing</Industries>
2105<Exports>$1.7 billion (f.o.b., 1999)</Exports>
2106<Imports>$2.5 billion (f.o.b., 1999)</Imports>
2107<Currency>1 new cedi (C) = 100 pesewas</Currency>
2108<Airports>12 (1999 est.)</Airports>
2109<Illicitdrugs>illicit producer of cannabis for the international drug trade; transit hub for Southwest and Southeast Asian heroin and South American cocaine destined for Europe and the US</Illicitdrugs>
2110</record>
2111<record>
2112<Location>Southwestern Europe, bordering the Strait of Gibraltar, which links the Mediterranean Sea and the North Atlantic Ocean, on the southern coast of Spain</Location>
2113<Geographiccoordinates>36 11 N, 5 22 W</Geographiccoordinates>
2114<Area>6</Area>
2115<Climate>Mediterranean with mild winters and warm summers</Climate>
2116<Naturalresources>NEGL</Naturalresources>
2117<Population>29481</Population>
2118<Populationgrowthrate>0.91% (2000 est.)</Populationgrowthrate>
2119<Sexratio>
2120at birth: 1.05 male(s)/female
2121under 15 years: 1.05 male(s)/female
212215-64 years: 1.14 male(s)/female
212365 years and over: 0.72 male(s)/female
2124total population: 1.05 male(s)/female (2000 est.)</Sexratio>
2125<Religions>Roman Catholic 76.9%, Church of England 6.9%, Muslim 6.9%, Jewish 2.3%, none or other 7% (1991)</Religions>
2126<Countryname>Gibraltar </Countryname>
2127<Capital>Gibraltar</Capital>
2128<Flagdescription>two horizontal bands of white (top, double width) and red with a three-towered red castle in the center of the white band; hanging from the castle gate is a gold key centered in the red band</Flagdescription>
2129<GDP>purchasing power parity - $500 million (1997 est.)</GDP>
2130<Industries>tourism, banking and finance, ship-building and repairing; support to large UK naval and air bases; tobacco, mineral water, beer, canned fish</Industries>
2131<Exports>$81.1 million (f.o.b., 1997)</Exports>
2132<Imports>$492 million (c.i.f., 1997)</Imports>
2133<Currency>1 Gibraltar pound = 100 pence</Currency>
2134<Airports>1 (1999 est.)</Airports>
2135</record>
2136<record>
2137<Location>Caribbean, island between the Caribbean Sea and Atlantic Ocean, north of Trinidad and Tobago</Location>
2138<Geographiccoordinates>12 07 N, 61 40 W</Geographiccoordinates>
2139<Area>340</Area>
2140<Climate>tropical; tempered by northeast trade winds</Climate>
2141<Naturalresources>timber, tropical fruit, deepwater harbors</Naturalresources>
2142<Population>89018</Population>
2143<Populationgrowthrate>-0.36% (2000 est.)</Populationgrowthrate>
2144<Sexratio>
2145at birth: 1.02 male(s)/female
2146under 15 years: 1.03 male(s)/female
214715-64 years: 1.12 male(s)/female
214865 years and over: 0.83 male(s)/female
2149total population: 1.07 male(s)/female (2000 est.)</Sexratio>
2150<Religions>Roman Catholic 53%, Anglican 13.8%, other Protestant 33.2%</Religions>
2151<Countryname>Grenada </Countryname>
2152<Capital>Saint George's</Capital>
2153<Flagdescription>a rectangle divided diagonally into yellow triangles (top and bottom) and green triangles (hoist side and outer side), with a red border around the flag; there are seven yellow, five-pointed stars with three centered in the top red border, three centered in the bottom red border, and one on a red disk superimposed at the center of the flag; there is also a symbolic nutmeg pod on the hoist-side triangle (Grenada is the world's second-largest producer of nutmeg, after Indonesia); the seven stars represent the seven administrative divisions</Flagdescription>
2154<GDP>purchasing power parity - $360 million (1999 est.)</GDP>
2155<Industries>food and beverages, textiles, light assembly operations, tourism, construction</Industries>
2156<Exports>$26.8 million (1998)</Exports>
2157<Imports>$200 million (1998)</Imports>
2158<Currency>1 East Caribbean dollar (EC$) = 100 cents</Currency>
2159<Airports>3 (1999 est.)</Airports>
2160<Illicitdrugs>small-scale cannabis cultivation; lesser transshipment point for marijuana and cocaine to US</Illicitdrugs>
2161</record>
2162<record>
2163<Location>Western Europe, islands in the English Channel, northwest of France</Location>
2164<Geographiccoordinates>49 28 N, 2 35 W</Geographiccoordinates>
2165<Area>194</Area>
2166<Climate>temperate with mild winters and cool summers; about 50% of days are overcast</Climate>
2167<Naturalresources>cropland</Naturalresources>
2168<Population>64080</Population>
2169<Populationgrowthrate>0.42% (2000 est.)</Populationgrowthrate>
2170<Sexratio>
2171at birth: 1.04 male(s)/female
2172under 15 years: 1.03 male(s)/female
217315-64 years: 0.98 male(s)/female
217465 years and over: 0.7 male(s)/female
2175total population: 0.93 male(s)/female (2000 est.)</Sexratio>
2176<Religions>Anglican, Roman Catholic, Presbyterian, Baptist, Congregational, Methodist</Religions>
2177<Countryname>Guernsey </Countryname>
2178<Capital>Saint Peter Port</Capital>
2179<Flagdescription>white with the red cross of Saint George (patron saint of England) extending to the edges of the flag and a yellow equal-armed cross of William the Conqueror superimposed on the Saint George cross</Flagdescription>
2180<GDP>purchasing power parity - $1.15 billion (1997 est.)</GDP>
2181<Industries>tourism, banking</Industries>
2182<Exports>$NA</Exports>
2183<Imports>$NA</Imports>
2184<Currency>1 Guernsey pound = 100 pence</Currency>
2185<Airports>2 (1999 est.)</Airports>
2186</record>
2187<record>
2188<Location>Northern North America, island between the Arctic Ocean and the North Atlantic Ocean, northeast of Canada</Location>
2189<Geographiccoordinates>72 00 N, 40 00 W</Geographiccoordinates>
2190<Area>2175600</Area>
2191<Climate>arctic to subarctic; cool summers, cold winters</Climate>
2192<Naturalresources>zinc, lead, iron ore, coal, molybdenum, gold, platinum, uranium, fish, seals, whales</Naturalresources>
2193<Population>56309</Population>
2194<Populationgrowthrate>0.09% (2000 est.)</Populationgrowthrate>
2195<Sexratio>
2196at birth: 1 male(s)/female
2197under 15 years: 1.03 male(s)/female
219815-64 years: 1.21 male(s)/female
219965 years and over: 0.81 male(s)/female
2200total population: 1.13 male(s)/female (2000 est.)</Sexratio>
2201<Religions>Evangelical Lutheran</Religions>
2202<Countryname>Greenland </Countryname>
2203<Capital>Nuuk (Godthab)</Capital>
2204<Flagdescription>two equal horizontal bands of white (top) and red with a large disk slightly to the hoist side of center - the top half of the disk is red, the bottom half is white</Flagdescription>
2205<GDP>purchasing power parity - $945 million (1997 est.)</GDP>
2206<Industries>fish processing (mainly shrimp), handicrafts, furs, small shipyards</Industries>
2207<Exports>$363.4 million (f.o.b., 1995)</Exports>
2208<Imports>$421 million (c.i.f., 1995)</Imports>
2209<Currency>1 Danish krone (DKr) = 100 oere</Currency>
2210<Airports>14 (1999 est.)</Airports>
2211</record>
2212<record>
2213<Location>Central Europe, bordering the Baltic Sea and the North Sea, between the Netherlands and Poland, south of Denmark</Location>
2214<Geographiccoordinates>51 00 N, 9 00 E</Geographiccoordinates>
2215<Area>357021</Area>
2216<Climate>temperate and marine; cool, cloudy, wet winters and summers; occasional warm foehn wind</Climate>
2217<Naturalresources>iron ore, coal, potash, timber, lignite, uranium, copper, natural gas, salt, nickel, arable land</Naturalresources>
2218<Population>82797408</Population>
2219<Populationgrowthrate>0.29% (2000 est.)</Populationgrowthrate>
2220<Sexratio>
2221at birth: 1.06 male(s)/female
2222under 15 years: 1.05 male(s)/female
222315-64 years: 1.03 male(s)/female
222465 years and over: 0.62 male(s)/female
2225total population: 0.96 male(s)/female (2000 est.)</Sexratio>
2226<Religions>Protestant 38%, Roman Catholic 34%, Muslim 1.7%, unaffiliated or other 26.3%</Religions>
2227<Countryname>Germany </Countryname>
2228<Capital>Berlin</Capital>
2229<Flagdescription>three equal horizontal bands of black (top), red, and gold</Flagdescription>
2230<GDP>purchasing power parity - $1.864 trillion (1999 est.)</GDP>
2231<Industries>among world's largest and technologically advanced producers of iron, steel, coal, cement, chemicals, machinery, vehicles, machine tools, electronics, food and beverages; shipbuilding; textiles</Industries>
2232<Exports>$610 billion (f.o.b., 1999 est.)</Exports>
2233<Imports>$587 billion (f.o.b., 1999 est.)</Imports>
2234<Currency>1 deutsche mark (DM) = 100 pfennige</Currency>
2235<Airports>615 (1999 est.)</Airports>
2236<Illicitdrugs>source of precursor chemicals for South American cocaine processors; transshipment point for and consumer of Southwest Asian heroin, Latin American cocaine, and European-produced synthetic drugs</Illicitdrugs>
2237</record>
2238<record>
2239<Location>Southern Africa, group of islands in the Indian Ocean, northwest of Madagascar</Location>
2240<Geographiccoordinates>11 30 S, 47 20 E</Geographiccoordinates>
2241<Area>5</Area>
2242<Climate>tropical</Climate>
2243<Naturalresources>guano, coconuts</Naturalresources>
2244<Population></Population>
2245<Countryname>Glorioso Islands </Countryname>
2246<Flagdescription>the flag of France is used</Flagdescription>
2247<Airports>1 (1999 est.)</Airports>
2248</record>
2249<record>
2250<Location>Caribbean, islands in the eastern Caribbean Sea, southeast of Puerto Rico</Location>
2251<Geographiccoordinates>16 15 N, 61 35 W</Geographiccoordinates>
2252<Area>1780</Area>
2253<Climate>subtropical tempered by trade winds; moderately high humidity</Climate>
2254<Naturalresources>cultivable land, beaches and climate that foster tourism</Naturalresources>
2255<Population>426493</Population>
2256<Populationgrowthrate>1.11% (2000 est.)</Populationgrowthrate>
2257<Sexratio>
2258at birth: 1.05 male(s)/female
2259under 15 years: 1.04 male(s)/female
226015-64 years: 0.98 male(s)/female
226165 years and over: 0.73 male(s)/female
2262total population: 0.97 male(s)/female (2000 est.)</Sexratio>
2263<Religions>Roman Catholic 95%, Hindu and pagan African 4%, Protestant 1%</Religions>
2264<Countryname>Guadeloupe </Countryname>
2265<Capital>Basse-Terre</Capital>
2266<Flagdescription>three horizontal bands, a narrow green band (top), a wide red band, and a narrow green band; the green bands are separated from the red band by two narrow white stripes; a gold five-pointed star is centered in the red band toward the hoist side; the flag of France is used for official occasions</Flagdescription>
2267<GDP>purchasing power parity - $3.7 billion (1996 est.)</GDP>
2268<Industries>construction, cement, rum, sugar, tourism</Industries>
2269<Exports>$140 million (f.o.b., 1997)</Exports>
2270<Imports>$1.7 billion (c.i.f., 1997)</Imports>
2271<Currency>1 French franc (F) = 100 centimes</Currency>
2272<Airports>9 (1999 est.)</Airports>
2273</record>
2274<record>
2275<Location>Oceania, island in the North Pacific Ocean, about three-quarters of the way from Hawaii to the Philippines</Location>
2276<Geographiccoordinates>13 28 N, 144 47 E</Geographiccoordinates>
2277<Area>541</Area>
2278<Climate>tropical marine; generally warm and humid, moderated by northeast trade winds; dry season from January to June, rainy season from July to December; little seasonal temperature variation</Climate>
2279<Naturalresources>fishing (largely undeveloped), tourism (especially from Japan)</Naturalresources>
2280<Population>154623</Population>
2281<Populationgrowthrate>1.67% (2000 est.)</Populationgrowthrate>
2282<Sexratio>
2283at birth: 1.14 male(s)/female
2284under 15 years: 1.1 male(s)/female
228515-64 years: 1.11 male(s)/female
228665 years and over: 1.01 male(s)/female
2287total population: 1.1 male(s)/female (2000 est.)</Sexratio>
2288<Religions>Roman Catholic 85%, other 15% (1999 est.)</Religions>
2289<Countryname>Guam </Countryname>
2290<Capital>Hagatna (Agana)</Capital>
2291<Flagdescription>territorial flag is dark blue with a narrow red border on all four sides; centered is a red-bordered, pointed, vertical ellipse containing a beach scene, outrigger canoe with sail, and a palm tree with the word GUAM superimposed in bold red letters; US flag is the national flag</Flagdescription>
2292<GDP>purchasing power parity - $3 billion (1996 est.)</GDP>
2293<Industries>US military, tourism, construction, transshipment services, concrete products, printing and publishing, food processing, textiles</Industries>
2294<Exports>$86.1 million (f.o.b., 1992)</Exports>
2295<Imports>$202.4 million (c.i.f., 1992)</Imports>
2296<Currency>1 United States dollar (US$) = 100 cents</Currency>
2297<Airports>5 (1999 est.)</Airports>
2298</record>
2299<record>
2300<Location>Southern Europe, bordering the Aegean Sea, Ionian Sea, and the Mediterranean Sea, between Albania and Turkey</Location>
2301<Geographiccoordinates>39 00 N, 22 00 E</Geographiccoordinates>
2302<Area>131940</Area>
2303<Climate>temperate; mild, wet winters; hot, dry summers</Climate>
2304<Naturalresources>bauxite, lignite, magnesite, petroleum, marble, hydropower</Naturalresources>
2305<Population>10601527</Population>
2306<Populationgrowthrate>0.21% (2000 est.)</Populationgrowthrate>
2307<Sexratio>
2308at birth: 1.07 male(s)/female
2309under 15 years: 1.06 male(s)/female
231015-64 years: 1 male(s)/female
231165 years and over: 0.8 male(s)/female
2312total population: 0.97 male(s)/female (2000 est.)</Sexratio>
2313<Religions>Greek Orthodox 98%, Muslim 1.3%, other 0.7%</Religions>
2314<Countryname>Greece </Countryname>
2315<Capital>Athens</Capital>
2316<Flagdescription>nine equal horizontal stripes of blue alternating with white; there is a blue square in the upper hoist-side corner bearing a white cross; the cross symbolizes Greek Orthodoxy, the established religion of the country</Flagdescription>
2317<GDP>purchasing power parity - $149.2 billion (1999 est.)</GDP>
2318<Industries>tourism; food and tobacco processing, textiles; chemicals, metal products; mining, petroleum</Industries>
2319<Exports>$12.4 billion (f.o.b., 1998)</Exports>
2320<Imports>$27.7 billion (c.i.f., 1998)</Imports>
2321<Currency>1 drachma (Dr) = 100 lepta</Currency>
2322<Airports>80 (1999 est.)</Airports>
2323<Illicitdrugs>a gateway to Europe for traffickers smuggling cannabis and heroin from the Middle East and Southwest Asia to the West and precursor chemicals to the East; some South American cocaine transits or is consumed in Greece</Illicitdrugs>
2324</record>
2325<record>
2326<Location>Middle America, bordering the Caribbean Sea, between Honduras and Belize and bordering the North Pacific Ocean, between El Salvador and Mexico</Location>
2327<Geographiccoordinates>15 30 N, 90 15 W</Geographiccoordinates>
2328<Area>108890</Area>
2329<Climate>tropical; hot, humid in lowlands; cooler in highlands</Climate>
2330<Naturalresources>petroleum, nickel, rare woods, fish, chicle, hydropower</Naturalresources>
2331<Population>12639939</Population>
2332<Populationgrowthrate>2.63% (2000 est.)</Populationgrowthrate>
2333<Sexratio>
2334at birth: 1.05 male(s)/female
2335under 15 years: 1.04 male(s)/female
233615-64 years: 1 male(s)/female
233765 years and over: 0.88 male(s)/female
2338total population: 1.01 male(s)/female (2000 est.)</Sexratio>
2339<Religions>Roman Catholic, Protestant, indigenous Mayan beliefs</Religions>
2340<Countryname>Guatemala </Countryname>
2341<Capital>Guatemala</Capital>
2342<Flagdescription>three equal vertical bands of light blue (hoist side), white, and light blue with the coat of arms centered in the white band; the coat of arms includes a green and red quetzal (the national bird) and a scroll bearing the inscription LIBERTAD 15 DE SEPTIEMBRE DE 1821 (the original date of independence from Spain) all superimposed on a pair of crossed rifles and a pair of crossed swords and framed by a wreath</Flagdescription>
2343<GDP>purchasing power parity - $47.9 billion (1999 est.)</GDP>
2344<Industries>sugar, textiles and clothing, furniture, chemicals, petroleum, metals, rubber, tourism</Industries>
2345<Exports>$2.4 billion (f.o.b., 1999)</Exports>
2346<Imports>$4.5 billion (c.i.f., 1999)</Imports>
2347<Currency>1 quetzal (Q) = 100 centavos</Currency>
2348<Airports>477 (1999 est.)</Airports>
2349<Illicitdrugs>transit country for cocaine shipments; minor producer of illicit opium poppy and cannabis for the international drug trade; active eradication program in 1996 effectively eliminated the cannabis crop; proximity to Mexico makes Guatemala a major staging area for drugs (cocaine shipments)</Illicitdrugs>
2350</record>
2351<record>
2352<Location>Western Africa, bordering the North Atlantic Ocean, between Guinea-Bissau and Sierra Leone</Location>
2353<Geographiccoordinates>11 00 N, 10 00 W</Geographiccoordinates>
2354<Area>245857</Area>
2355<Climate>generally hot and humid; monsoonal-type rainy season (June to November) with southwesterly winds; dry season (December to May) with northeasterly harmattan winds</Climate>
2356<Naturalresources>bauxite, iron ore, diamonds, gold, uranium, hydropower, fish</Naturalresources>
2357<Population>7466200</Population>
2358<Populationgrowthrate>1.95% (2000 est.)</Populationgrowthrate>
2359<Sexratio>
2360at birth: 1.03 male(s)/female
2361under 15 years: 1 male(s)/female
236215-64 years: 0.95 male(s)/female
236365 years and over: 0.7 male(s)/female
2364total population: 0.96 male(s)/female (2000 est.)</Sexratio>
2365<Religions>Muslim 85%, Christian 8%, indigenous beliefs 7%</Religions>
2366<Countryname>Guinea </Countryname>
2367<Capital>Conakry</Capital>
2368<Flagdescription>three equal vertical bands of red (hoist side), yellow, and green; uses the popular pan-African colors of Ethiopia; similar to the flag of Rwanda, which has a large black letter R centered in the yellow band</Flagdescription>
2369<GDP>purchasing power parity - $9.2 billion (1999 est.)</GDP>
2370<Industries>bauxite, gold, diamonds; alumina refining; light manufacturing and agricultural processing industries</Industries>
2371<Exports>$695 million (f.o.b., 1998 est.)</Exports>
2372<Imports>$560 million (f.o.b., 1998 est.)</Imports>
2373<Currency>1 Guinean franc (FG) = 100 centimes</Currency>
2374<Airports>15 (1999 est.)</Airports>
2375</record>
2376<record>
2377<Location>Northern South America, bordering the North Atlantic Ocean, between Suriname and Venezuela</Location>
2378<Geographiccoordinates>5 00 N, 59 00 W</Geographiccoordinates>
2379<Area>214970</Area>
2380<Climate>tropical; hot, humid, moderated by northeast trade winds; two rainy seasons (May to mid-August, mid-November to mid-January)</Climate>
2381<Naturalresources>bauxite, gold, diamonds, hardwood timber, shrimp, fish</Naturalresources>
2382<Population>697286</Population>
2383<Populationgrowthrate>-0.1% (2000 est.)</Populationgrowthrate>
2384<Sexratio>
2385at birth: 1.05 male(s)/female
2386under 15 years: 1.04 male(s)/female
238715-64 years: 1.01 male(s)/female
238865 years and over: 0.81 male(s)/female
2389total population: 1.01 male(s)/female (2000 est.)</Sexratio>
2390<Religions>Christian 50%, Hindu 33%, Muslim 9%, other 8%</Religions>
2391<Countryname>Guyana </Countryname>
2392<Capital>Georgetown</Capital>
2393<Flagdescription>green, with a red isosceles triangle (based on the hoist side) superimposed on a long, yellow arrowhead; there is a narrow, black border between the red and yellow, and a narrow, white border between the yellow and the green</Flagdescription>
2394<GDP>purchasing power parity - $1.86 billion (1999 est.)</GDP>
2395<Industries>bauxite, sugar, rice milling, timber, fishing (shrimp), textiles, gold mining</Industries>
2396<Exports>$574 million (f.o.b., 1999 est.)</Exports>
2397<Imports>$620 million (c.i.f., 1999 est.)</Imports>
2398<Currency>1 Guyanese dollar (G$) = 100 cents</Currency>
2399<Airports>51 (1999 est.)</Airports>
2400<Illicitdrugs>transshipment point for narcotics from South America - primarily Venezuela - to Europe and the US; producer of cannabis</Illicitdrugs>
2401</record>
2402<record>
2403<Location>Middle East, bordering the Mediterranean Sea, between Egypt and Israel</Location>
2404<Geographiccoordinates>31 25 N, 34 20 E</Geographiccoordinates>
2405<Area>360</Area>
2406<Climate>temperate, mild winters, dry and warm to hot summers</Climate>
2407<Naturalresources>arable land</Naturalresources>
2408<Population>1132063</Population>
2409<Populationgrowthrate>3.97% (2000 est.)</Populationgrowthrate>
2410<Sexratio>
2411at birth: 1.05 male(s)/female
2412under 15 years: 1.05 male(s)/female
241315-64 years: 1.03 male(s)/female
241465 years and over: 0.76 male(s)/female
2415total population: 1.03 male(s)/female (2000 est.)</Sexratio>
2416<Religions>Muslim (predominantly Sunni) 98.7%, Christian 0.7%, Jewish 0.6%</Religions>
2417<Countryname>Gaza Strip </Countryname>
2418<GDP>purchasing power parity - $1.17 billion (1999 est.)</GDP>
2419<Industries>generally small family businesses that produce textiles, soap, olive-wood carvings, and mother-of-pearl souvenirs; the Israelis have established some small-scale modern industries in an industrial center</Industries>
2420<Exports>$682 million (includes West Bank) (f.o.b., 1998 est.)</Exports>
2421<Imports>$2.5 billion (c.i.f., 1998 est.) (includes West Bank)</Imports>
2422<Currency>1 new Israeli shekel (NIS) = 100 new agorot</Currency>
2423<Airports>2 (1999 est.)
2424note: includes Gaza International Airport that opened on 24 November 1998 as part of agreements stipulated in the September 1995 Oslo II Accord and the 23 October 1998 Wye River Memorandum</Airports>
2425</record>
2426<record>
2427<Location>Caribbean, western one-third of the island of Hispaniola, between the Caribbean Sea and the North Atlantic Ocean, west of the Dominican Republic</Location>
2428<Geographiccoordinates>19 00 N, 72 25 W</Geographiccoordinates>
2429<Area>27750</Area>
2430<Climate>tropical; semiarid where mountains in east cut off trade winds</Climate>
2431<Naturalresources>bauxite, copper, calcium carbonate, gold, marble, hydropower</Naturalresources>
2432<Population>6867995</Population>
2433<Populationgrowthrate>1.39% (2000 est.)</Populationgrowthrate>
2434<Sexratio>
2435at birth: 1.05 male(s)/female
2436under 15 years: 1.03 male(s)/female
243715-64 years: 0.93 male(s)/female
243865 years and over: 0.95 male(s)/female
2439total population: 0.97 male(s)/female (2000 est.)</Sexratio>
2440<Religions>Roman Catholic 80%, Protestant 16% (Baptist 10%, Pentecostal 4%, Adventist 1%, other 1%), none 1%, other 3% (1982)
2441note: roughly one-half of the population also practices Voodoo</Religions>
2442<Countryname>Haiti </Countryname>
2443<Capital>Port-au-Prince</Capital>
2444<Flagdescription>two equal horizontal bands of blue (top) and red with a centered white rectangle bearing the coat of arms, which contains a palm tree flanked by flags and two cannons above a scroll bearing the motto L'UNION FAIT LA FORCE (Union Makes Strength)</Flagdescription>
2445<GDP>purchasing power parity - $9.2 billion (1999 est.)</GDP>
2446<Industries>sugar refining, flour milling, textiles, cement, tourism, light assembly industries based on imported parts</Industries>
2447<Exports>$322 million (f.o.b., 1999)</Exports>
2448<Imports>$762 million (c.i.f., 1999)</Imports>
2449<Currency>1 gourde (G) = 100 centimes</Currency>
2450<Airports>13 (1999 est.)</Airports>
2451<Illicitdrugs>major Caribbean transshipment point for cocaine en route to the US and Europe</Illicitdrugs>
2452</record>
2453<record>
2454<Location>Eastern Asia, bordering the South China Sea and China</Location>
2455<Geographiccoordinates>22 15 N, 114 10 E</Geographiccoordinates>
2456<Area>1092</Area>
2457<Climate>tropical monsoon; cool and humid in winter, hot and rainy from spring through summer, warm and sunny in fall</Climate>
2458<Naturalresources>outstanding deepwater harbor, feldspar</Naturalresources>
2459<Population>7116302</Population>
2460<Populationgrowthrate>1.35% (2000 est.)</Populationgrowthrate>
2461<Sexratio>
2462at birth: 1.07 male(s)/female
2463under 15 years: 1.12 male(s)/female
246415-64 years: 0.98 male(s)/female
246565 years and over: 0.84 male(s)/female
2466total population: 0.99 male(s)/female (2000 est.)</Sexratio>
2467<Religions>eclectic mixture of local religions 90%, Christian 10%</Religions>
2468<Countryname>Hong Kong </Countryname>
2469<Flagdescription>red with a stylized, white, five-petal bauhinia flower in the center</Flagdescription>
2470<GDP>purchasing power parity - $158.2 billion (1999 est.)</GDP>
2471<Industries>textiles, clothing, tourism, electronics, plastics, toys, watches, clocks</Industries>
2472<Exports>$169.98 billion (including reexports; f.o.b., 1999 est.)</Exports>
2473<Imports>$174.4 billion (c.i.f., 1999)</Imports>
2474<Currency>1 Hong Kong dollar (HK$) = 100 cents</Currency>
2475<Airports>3 (1999 est.)</Airports>
2476<Illicitdrugs>a hub for Southeast Asian heroin trade; transshipment and money-laundering center; increasing indigenous amphetamine abuse</Illicitdrugs>
2477</record>
2478<record>
2479<Location>Southern Africa, islands in the Indian Ocean, about two-thirds of the way from Madagascar to Antarctica</Location>
2480<Geographiccoordinates>53 06 S, 72 31 E</Geographiccoordinates>
2481<Area>412</Area>
2482<Climate>antarctic</Climate>
2483<Naturalresources>none</Naturalresources>
2484<Population></Population>
2485<Countryname>Heard Island and McDonald Islands </Countryname>
2486<Flagdescription>the flag of Australia is used</Flagdescription>
2487</record>
2488<record>
2489<Location>Middle America, bordering the Caribbean Sea, between Guatemala and Nicaragua and bordering the North Pacific Ocean, between El Salvador and Nicaragua</Location>
2490<Geographiccoordinates>15 00 N, 86 30 W</Geographiccoordinates>
2491<Area>112090</Area>
2492<Climate>subtropical in lowlands, temperate in mountains</Climate>
2493<Naturalresources>timber, gold, silver, copper, lead, zinc, iron ore, antimony, coal, fish, hydropower</Naturalresources>
2494<Population>6249598</Population>
2495<Populationgrowthrate>2.52% (2000 est.)</Populationgrowthrate>
2496<Sexratio>
2497at birth: 1.05 male(s)/female
2498under 15 years: 1.04 male(s)/female
249915-64 years: 0.98 male(s)/female
250065 years and over: 0.9 male(s)/female
2501total population: 1 male(s)/female (2000 est.)</Sexratio>
2502<Religions>Roman Catholic 97%, Protestant minority</Religions>
2503<Countryname>Honduras </Countryname>
2504<Capital>Tegucigalpa</Capital>
2505<Flagdescription>three equal horizontal bands of blue (top), white, and blue with five blue five-pointed stars arranged in an X pattern centered in the white band; the stars represent the members of the former Federal Republic of Central America - Costa Rica, El Salvador, Guatemala, Honduras, and Nicaragua; similar to the flag of El Salvador, which features a round emblem encircled by the words REPUBLICA DE EL SALVADOR EN LA AMERICA CENTRAL centered in the white band; also similar to the flag of Nicaragua, which features a triangle encircled by the word REPUBLICA DE NICARAGUA on top and AMERICA CENTRAL on the bottom, centered in the white band</Flagdescription>
2506<GDP>purchasing power parity - $14.1 billion (1999 est.)</GDP>
2507<Industries>sugar, coffee, textiles, clothing, wood products</Industries>
2508<Exports>$1.6 billion (f.o.b., 1999 est.)</Exports>
2509<Imports>$2.7 billion (f.o.b., 1999 est.)</Imports>
2510<Currency>1 lempira (L) = 100 centavos</Currency>
2511<Airports>119 (1999 est.)</Airports>
2512<Illicitdrugs>transshipment point for drugs and narcotics; illicit producer of cannabis, cultivated on small plots and used principally for local consumption; corruption is a major problem</Illicitdrugs>
2513</record>
2514<record>
2515<Location>Oceania, island in the North Pacific Ocean, about one-half of the way from Hawaii to Australia</Location>
2516<Geographiccoordinates>0 48 N, 176 38 W</Geographiccoordinates>
2517<Area>1</Area>
2518<Climate>equatorial; scant rainfall, constant wind, burning sun</Climate>
2519<Naturalresources>guano (deposits worked until late 1800s)</Naturalresources>
2520<Population></Population>
2521<Countryname>Howland Island </Countryname>
2522<Flagdescription>the flag of the US is used</Flagdescription>
2523<Airports>airstrip constructed in 1937 for scheduled refueling stop on the round-the-world flight of Amelia EARHART and Fred NOONAN - they left Lae, New Guinea, for Howland Island, but were never seen again; the airstrip is no longer serviceable</Airports>
2524</record>
2525<record>
2526<Location>Southeastern Europe, bordering the Adriatic Sea, between Bosnia and Herzegovina and Slovenia</Location>
2527<Geographiccoordinates>45 10 N, 15 30 E</Geographiccoordinates>
2528<Area>56538</Area>
2529<Climate>Mediterranean and continental; continental climate predominant with hot summers and cold winters; mild winters, dry summers along coast</Climate>
2530<Naturalresources>oil, some coal, bauxite, low-grade iron ore, calcium, natural asphalt, silica, mica, clays, salt, hydropower</Naturalresources>
2531<Population>4282216</Population>
2532<Populationgrowthrate>0.93% (2000 est.)</Populationgrowthrate>
2533<Sexratio>
2534at birth: 1.07 male(s)/female
2535under 15 years: 1.05 male(s)/female
253615-64 years: 1.02 male(s)/female
253765 years and over: 0.59 male(s)/female
2538total population: 0.94 male(s)/female (2000 est.)</Sexratio>
2539<Religions>Roman Catholic 76.5%, Orthodox 11.1%, Muslim 1.2%, Protestant 0.4%, others and unknown 10.8% (1991)</Religions>
2540<Countryname>Croatia </Countryname>
2541<Capital>Zagreb</Capital>
2542<Flagdescription>red, white, and blue horizontal bands with Croatian coat of arms (red and white checkered)</Flagdescription>
2543<GDP>purchasing power parity - $23.9 billion (1999 est.)</GDP>
2544<Industries>chemicals and plastics, machine tools, fabricated metal, electronics, pig iron and rolled steel products, aluminum, paper, wood products, construction materials, textiles, shipbuilding, petroleum and petroleum refining, food and beverages; tourism</Industries>
2545<Exports>$4.5 billion (f.o.b., 1998)</Exports>
2546<Imports>$8.4 billion (c.i.f., 1998)</Imports>
2547<Currency>1 Croatian kuna (HRK) = 100 lipas</Currency>
2548<Airports>67 (1999 est.)</Airports>
2549<Illicitdrugs>transit point along the Balkan route for Southwest Asian heroin to Western Europe; a minor transit point for maritime shipments of South American cocaine bound for Western Europe</Illicitdrugs>
2550</record>
2551<record>
2552<Location>Central Europe, northwest of Romania</Location>
2553<Geographiccoordinates>47 00 N, 20 00 E</Geographiccoordinates>
2554<Area>93030</Area>
2555<Climate>temperate; cold, cloudy, humid winters; warm summers</Climate>
2556<Naturalresources>bauxite, coal, natural gas, fertile soils, arable land</Naturalresources>
2557<Population>10138844</Population>
2558<Populationgrowthrate>-0.33% (2000 est.)</Populationgrowthrate>
2559<Sexratio>
2560at birth: 1.05 male(s)/female
2561under 15 years: 1.05 male(s)/female
256215-64 years: 0.96 male(s)/female
256365 years and over: 0.59 male(s)/female
2564total population: 0.91 male(s)/female (2000 est.)</Sexratio>
2565<Religions>Roman Catholic 67.5%, Calvinist 20%, Lutheran 5%, atheist and other 7.5%</Religions>
2566<Countryname>Hungary </Countryname>
2567<Capital>Budapest</Capital>
2568<Flagdescription>three equal horizontal bands of red (top), white, and green</Flagdescription>
2569<GDP>purchasing power parity - $79.4 billion (1999 est.)</GDP>
2570<Industries>mining, metallurgy, construction materials, processed foods, textiles, chemicals (especially pharmaceuticals), motor vehicles</Industries>
2571<Exports>$22.6 billion (f.o.b., 1999)</Exports>
2572<Imports>$25.1 billion (f.o.b., 1999)</Imports>
2573<Currency>1 forint (Ft) = 100 filler</Currency>
2574<Airports>43 (1999 est.)</Airports>
2575<Illicitdrugs>major transshipment point for Southwest Asian heroin and cannabis and transit point for South American cocaine destined for Western Europe; limited producer of precursor chemicals, particularly for amphetamines and methamphetamines</Illicitdrugs>
2576</record>
2577<record>
2578<Location>Northern Europe, island between the Greenland Sea and the North Atlantic Ocean, northwest of the UK</Location>
2579<Geographiccoordinates>65 00 N, 18 00 W</Geographiccoordinates>
2580<Area>103000</Area>
2581<Climate>temperate; moderated by North Atlantic Current; mild, windy winters; damp, cool summers</Climate>
2582<Naturalresources>fish, hydropower, geothermal power, diatomite</Naturalresources>
2583<Population>276365</Population>
2584<Populationgrowthrate>0.57% (2000 est.)</Populationgrowthrate>
2585<Sexratio>
2586at birth: 1.06 male(s)/female
2587under 15 years: 1.06 male(s)/female
258815-64 years: 1.02 male(s)/female
258965 years and over: 0.81 male(s)/female
2590total population: 1 male(s)/female (2000 est.)</Sexratio>
2591<Religions>Evangelical Lutheran 91%, other Protestant and Roman Catholic, none (1997)</Religions>
2592<Countryname>Iceland </Countryname>
2593<Capital>Reykjavik</Capital>
2594<Flagdescription>blue with a red cross outlined in white that extends to the edges of the flag; the vertical part of the cross is shifted to the hoist side in the style of the Dannebrog (Danish flag)</Flagdescription>
2595<GDP>purchasing power parity - $6.42 billion (1999 est.)</GDP>
2596<Industries>fish processing; aluminum smelting, ferrosilicon production, geothermal power; tourism</Industries>
2597<Exports>$1.9 billion (f.o.b., 1998)</Exports>
2598<Imports>$2.4 billion (f.o.b., 1998)</Imports>
2599<Currency>1 Icelandic krona (IKr) = 100 aurar</Currency>
2600<Airports>86 (1999 est.)</Airports>
2601</record>
2602<record>
2603<Location>Southeastern Asia, archipelago between the Indian Ocean and the Pacific Ocean</Location>
2604<Geographiccoordinates>5 00 S, 120 00 E</Geographiccoordinates>
2605<Area>1919440</Area>
2606<Climate>tropical; hot, humid; more moderate in highlands</Climate>
2607<Naturalresources>petroleum, tin, natural gas, nickel, timber, bauxite, copper, fertile soils, coal, gold, silver</Naturalresources>
2608<Population>224784210</Population>
2609<Populationgrowthrate>1.63% (2000 est.)</Populationgrowthrate>
2610<Sexratio>
2611at birth: 1.05 male(s)/female
2612under 15 years: 1.03 male(s)/female
261315-64 years: 1 male(s)/female
261465 years and over: 0.78 male(s)/female
2615total population: 1 male(s)/female (2000 est.)</Sexratio>
2616<Religions>Muslim 88%, Protestant 5%, Roman Catholic 3%, Hindu 2%, Buddhist 1%, other 1% (1998)</Religions>
2617<Countryname>Indonesia </Countryname>
2618<Capital>Jakarta</Capital>
2619<Flagdescription>two equal horizontal bands of red (top) and white; similar to the flag of Monaco, which is shorter; also similar to the flag of Poland, which is white (top) and red</Flagdescription>
2620<GDP>purchasing power parity - $610 billion (1999 est.)</GDP>
2621<Industries>petroleum and natural gas; textiles, apparel, and footwear; mining, cement, chemical fertilizers, plywood; rubber; food; tourism</Industries>
2622<Exports>$48 billion (f.o.b., 1999 est.)</Exports>
2623<Imports>$24 billion (c.i.f., 1999 est.)</Imports>
2624<Currency>Indonesian rupiah (Rp) = 100 sen</Currency>
2625<Airports>446 (1999 est.)</Airports>
2626<Illicitdrugs>illicit producer of cannabis largely for domestic use; possible growing role as transshipment point for Golden Triangle heroin</Illicitdrugs>
2627</record>
2628<record>
2629<Location>Western Europe, island in the Irish Sea, between Great Britain and Ireland</Location>
2630<Geographiccoordinates>54 15 N, 4 30 W</Geographiccoordinates>
2631<Area>572</Area>
2632<Climate>cool summers and mild winters; temperate; overcast about one-third of the time</Climate>
2633<Naturalresources>none</Naturalresources>
2634<Population>73117</Population>
2635<Populationgrowthrate>0.52% (2000 est.)</Populationgrowthrate>
2636<Sexratio>
2637at birth: 1.05 male(s)/female
2638under 15 years: 1.04 male(s)/female
263915-64 years: 1.01 male(s)/female
264065 years and over: 0.66 male(s)/female
2641total population: 0.94 male(s)/female (2000 est.)</Sexratio>
2642<Religions>Anglican, Roman Catholic, Methodist, Baptist, Presbyterian, Society of Friends</Religions>
2643<Countryname>Isle of Man </Countryname>
2644<Capital>Douglas</Capital>
2645<Flagdescription>red with the Three Legs of Man emblem (Trinacria), in the center; the three legs are joined at the thigh and bent at the knee; in order to have the toes pointing clockwise on both sides of the flag, a two-sided emblem is used</Flagdescription>
2646<GDP>purchasing power parity - $1.2 billion (1998 est.)</GDP>
2647<Industries>financial services, light manufacturing, tourism</Industries>
2648<Exports>$NA</Exports>
2649<Imports>$NA</Imports>
2650<Currency>1 Manx pound = 100 pence</Currency>
2651<Airports>1 (1999 est.)</Airports>
2652</record>
2653<record>
2654<Location>Southern Asia, bordering the Arabian Sea and the Bay of Bengal, between Burma and Pakistan</Location>
2655<Geographiccoordinates>20 00 N, 77 00 E</Geographiccoordinates>
2656<Area>3287590</Area>
2657<Climate>varies from tropical monsoon in south to temperate in north</Climate>
2658<Naturalresources>coal (fourth-largest reserves in the world), iron ore, manganese, mica, bauxite, titanium ore, chromite, natural gas, diamonds, petroleum, limestone, arable land</Naturalresources>
2659<Population>1014003817</Population>
2660<Populationgrowthrate>1.58% (2000 est.)</Populationgrowthrate>
2661<Sexratio>
2662at birth: 1.05 male(s)/female
2663under 15 years: 1.06 male(s)/female
266415-64 years: 1.08 male(s)/female
266565 years and over: 1.03 male(s)/female
2666total population: 1.07 male(s)/female (2000 est.)</Sexratio>
2667<Religions>Hindu 80%, Muslim 14%, Christian 2.4%, Sikh 2%, Buddhist 0.7%, Jains 0.5%, other 0.4%</Religions>
2668<Countryname>India </Countryname>
2669<Capital>New Delhi</Capital>
2670<Flagdescription>three equal horizontal bands of orange (top), white, and green with a blue chakra (24-spoked wheel) centered in the white band; similar to the flag of Niger, which has a small orange disk centered in the white band</Flagdescription>
2671<GDP>purchasing power parity - $1.805 trillion (1999 est.)</GDP>
2672<Industries>textiles, chemicals, food processing, steel, transportation equipment, cement, mining, petroleum, machinery</Industries>
2673<Exports>$36.3 billion (f.o.b., 1999 est.)</Exports>
2674<Imports>$50.2 billion (f.o.b., 1999 est.)</Imports>
2675<Currency>1 Indian rupee (Re) = 100 paise</Currency>
2676<Airports>346 (1999 est.)</Airports>
2677<Illicitdrugs>world's largest producer of licit opium for the pharmaceutical trade, but an undetermined quantity of opium is diverted to illicit international drug markets; major transit country for illicit narcotics produced in neighboring countries; illicit producer of hashish and methaqualone</Illicitdrugs>
2678</record>
2679<record>
2680<Location>Southern Asia, archipelago in the Indian Ocean, about one-half the way from Africa to Indonesia</Location>
2681<Geographiccoordinates>6 00 S, 71 30 E</Geographiccoordinates>
2682<Area>60</Area>
2683<Climate>tropical marine; hot, humid, moderated by trade winds</Climate>
2684<Naturalresources>coconuts, fish</Naturalresources>
2685<Population></Population>
2686<Countryname>British Indian Ocean Territory </Countryname>
2687<Flagdescription>white with six blue wavy horizontal stripes; the flag of the UK is in the upper hoist-side quadrant; the striped section bears a palm tree and yellow crown centered on the outer half of the flag</Flagdescription>
2688<Airports>1 (1999 est.)</Airports>
2689</record>
2690<record>
2691<Location>Middle America, atoll in the North Pacific Ocean, 1,120 km southwest of Mexico</Location>
2692<Geographiccoordinates>10 17 N, 109 13 W</Geographiccoordinates>
2693<Area>7</Area>
2694<Climate>tropical, humid, average temperature 20-32 degrees C, rains May-October</Climate>
2695<Naturalresources>none</Naturalresources>
2696<Population></Population>
2697<Countryname>Clipperton Island </Countryname>
2698<Flagdescription>the flag of France is used</Flagdescription>
2699</record>
2700<record>
2701<Location>Middle East, bordering the Gulf of Oman, the Persian Gulf, and the Caspian Sea, between Iraq and Pakistan</Location>
2702<Geographiccoordinates>32 00 N, 53 00 E</Geographiccoordinates>
2703<Area>1000000</Area>
2704<Climate>mostly arid or semiarid, subtropical along Caspian coast</Climate>
2705<Naturalresources>petroleum, natural gas, coal, chromium, copper, iron ore, lead, manganese, zinc, sulfur</Naturalresources>
2706<Population>65619636</Population>
2707<Populationgrowthrate>0.83% (2000 est.)</Populationgrowthrate>
2708<Sexratio>
2709at birth: 1.05 male(s)/female
2710under 15 years: 1.05 male(s)/female
271115-64 years: 1.01 male(s)/female
271265 years and over: 1.12 male(s)/female
2713total population: 1.03 male(s)/female (2000 est.)</Sexratio>
2714<Religions>Shi'a Muslim 89%, Sunni Muslim 10%, Zoroastrian, Jewish, Christian, and Baha'i 1%</Religions>
2715<Countryname>Iran </Countryname>
2716<Capital>Tehran</Capital>
2717<Flagdescription>three equal horizontal bands of green (top), white, and red; the national emblem (a stylized representation of the word Allah) in red is centered in the white band; ALLAH AKBAR (God is Great) in white Arabic script is repeated 11 times along the bottom edge of the green band and 11 times along the top edge of the red band</Flagdescription>
2718<GDP>purchasing power parity - $347.6 billion (1999 est.)</GDP>
2719<Industries>petroleum, petrochemicals, textiles, cement and other construction materials, food processing (particularly sugar refining and vegetable oil production), metal fabricating, armaments</Industries>
2720<Exports>$12.2 billion (f.o.b., 1998 est.)</Exports>
2721<Imports>$13.8 billion (f.o.b., 1998 est.)</Imports>
2722<Currency>10 Iranian rials (IR) = 1 toman; note - domestic figures are generally referred to in terms of the toman</Currency>
2723<Airports>288 (1999 est.)</Airports>
2724<Illicitdrugs>despite substantial interdiction efforts, Iran remains a key transshipment point for Southwest Asian heroin to Europe; domestic consumption of narcotics remains a persistent problem and Iranian press reports estimate that there are at least 1.2 million drug users in the country</Illicitdrugs>
2725</record>
2726<record>
2727<Location>Middle East, bordering the Mediterranean Sea, between Egypt and Lebanon</Location>
2728<Geographiccoordinates>31 30 N, 34 45 E</Geographiccoordinates>
2729<Area>20770</Area>
2730<Climate>temperate; hot and dry in southern and eastern desert areas</Climate>
2731<Naturalresources>copper, phosphates, bromide, potash, clay, sand, sulfur, asphalt, manganese, small amounts of natural gas and crude oil</Naturalresources>
2732<Population>5842454</Population>
2733<Populationgrowthrate>1.67% (2000 est.)</Populationgrowthrate>
2734<Sexratio>
2735at birth: 1.05 male(s)/female
2736under 15 years: 1.05 male(s)/female
273715-64 years: 1.01 male(s)/female
273865 years and over: 0.75 male(s)/female
2739total population: 0.99 male(s)/female (2000 est.)</Sexratio>
2740<Religions>Jewish 80.1%, Muslim 14.6% (mostly Sunni Muslim), Christian 2.1%, other 3.2% (1996 est.)</Religions>
2741<Countryname>Israel </Countryname>
2742<Capital>Jerusalem
2743note: Israel proclaimed Jerusalem as its capital in 1950, but the US, like nearly all other countries, maintains its Embassy in Tel Aviv</Capital>
2744<Flagdescription>white with a blue hexagram (six-pointed linear star) known as the Magen David (Shield of David) centered between two equal horizontal blue bands near the top and bottom edges of the flag</Flagdescription>
2745<GDP>purchasing power parity - $105.4 billion (1999 est.)</GDP>
2746<Industries>food processing, diamond cutting and polishing, textiles and apparel, chemicals, metal products, military equipment, transport equipment, electrical equipment, potash mining, high-technology electronics, tourism</Industries>
2747<Exports>$23.5 billion (f.o.b., 1999)</Exports>
2748<Imports>$30.6 billion (f.o.b., 1999)</Imports>
2749<Currency>1 new Israeli shekel (NIS) = 100 new agorot</Currency>
2750<Airports>58 (1999 est.)</Airports>
2751<Illicitdrugs>increasingly concerned about cocaine and heroin abuse; drugs arrive in country from Lebanon and increasingly Jordan</Illicitdrugs>
2752</record>
2753<record>
2754<Location>Southern Europe, a peninsula extending into the central Mediterranean Sea, northeast of Tunisia</Location>
2755<Geographiccoordinates>42 50 N, 12 50 E</Geographiccoordinates>
2756<Area>301230</Area>
2757<Climate>predominantly Mediterranean; Alpine in far north; hot, dry in south</Climate>
2758<Naturalresources>mercury, potash, marble, sulfur, dwindling natural gas and crude oil reserves, fish, coal, arable land</Naturalresources>
2759<Population>57634327</Population>
2760<Populationgrowthrate>0.09% (2000 est.)</Populationgrowthrate>
2761<Sexratio>
2762at birth: 1.06 male(s)/female
2763under 15 years: 1.06 male(s)/female
276415-64 years: 0.99 male(s)/female
276565 years and over: 0.7 male(s)/female
2766total population: 0.94 male(s)/female (2000 est.)</Sexratio>
2767<Religions>predominately Roman Catholic with mature Protestant and Jewish communities and a growing Muslim immigrant community</Religions>
2768<Countryname>Italy </Countryname>
2769<Capital>Rome</Capital>
2770<Flagdescription>three equal vertical bands of green (hoist side), white, and red; similar to the flag of Ireland, which is longer and is green (hoist side), white, and orange; also similar to the flag of the Cote d'Ivoire, which has the colors reversed - orange (hoist side), white, and green
2771note: inspired by the French flag brought to Italy by Napoleon in 1797</Flagdescription>
2772<GDP>purchasing power parity - $1.212 trillion (1999 est.)</GDP>
2773<Industries>tourism, machinery, iron and steel, chemicals, food processing, textiles, motor vehicles, clothing, footwear, ceramics</Industries>
2774<Exports>$242.6 billion (f.o.b., 1998)</Exports>
2775<Imports>$206.9 billion (f.o.b., 1998)</Imports>
2776<Currency>1 Italian lira (Lit) = 100 centesimi</Currency>
2777<Airports>136 (1999 est.)</Airports>
2778<Illicitdrugs>important gateway for and consumer of Latin American cocaine and Southwest Asian heroin entering the European market</Illicitdrugs>
2779</record>
2780<record>
2781<Location>Western Africa, bordering the North Atlantic Ocean, between Ghana and Liberia</Location>
2782<Geographiccoordinates>8 00 N, 5 00 W</Geographiccoordinates>
2783<Area>322460</Area>
2784<Climate>tropical along coast, semiarid in far north; three seasons - warm and dry (November to March), hot and dry (March to May), hot and wet (June to October)</Climate>
2785<Naturalresources>petroleum, diamonds, manganese, iron ore, cobalt, bauxite, copper, hydropower</Naturalresources>
2786<Population>15980950</Population>
2787<Populationgrowthrate>2.58% (2000 est.)</Populationgrowthrate>
2788<Sexratio>
2789at birth: 1.03 male(s)/female
2790under 15 years: 1.01 male(s)/female
279115-64 years: 1.06 male(s)/female
279265 years and over: 1 male(s)/female
2793total population: 1.03 male(s)/female (2000 est.)</Sexratio>
2794<Religions>Muslim 60%, Christian 22%, indigenous 18% (some of these are also numbered among the Christians and Muslims)</Religions>
2795<Countryname>Cote d'Ivoire </Countryname>
2796<Capital>Yamoussoukro
2797note: although Yamoussoukro has been the capital since 1983, Abidjan remains the administrative center; the US, like other countries, maintains its Embassy in Abidjan</Capital>
2798<Flagdescription>three equal vertical bands of orange (hoist side), white, and green; similar to the flag of Ireland, which is longer and has the colors reversed - green (hoist side), white, and orange; also similar to the flag of Italy, which is green (hoist side), white, and red; design was based on the flag of France</Flagdescription>
2799<GDP>purchasing power parity - $25.7 billion (1999 est.)</GDP>
2800<Industries>foodstuffs, beverages; wood products, oil refining, automobile assembly, textiles, fertilizer, construction materials, electricity</Industries>
2801<Exports>$3.9 billion (f.o.b., 1999 est.)</Exports>
2802<Imports>$2.6 billion (f.o.b., 1999 est.)</Imports>
2803<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
2804<Airports>36 (1999 est.)</Airports>
2805<Illicitdrugs>illicit producer of cannabis, mostly for local consumption; minor transshipment point for Southwest and Southeast Asian heroin to Europe and occasionally to the US, and for Latin American cocaine destined for Europe</Illicitdrugs>
2806</record>
2807<record>
2808<Location>Middle East, bordering the Persian Gulf, between Iran and Kuwait</Location>
2809<Geographiccoordinates>33 00 N, 44 00 E</Geographiccoordinates>
2810<Area>437072</Area>
2811<Climate>mostly desert; mild to cool winters with dry, hot, cloudless summers; northern mountainous regions along Iranian and Turkish borders experience cold winters with occasionally heavy snows that melt in early spring, sometimes causing extensive flooding in central and southern Iraq</Climate>
2812<Naturalresources>petroleum, natural gas, phosphates, sulfur</Naturalresources>
2813<Population>22675617</Population>
2814<Populationgrowthrate>2.86% (2000 est.)</Populationgrowthrate>
2815<Sexratio>
2816at birth: 1.05 male(s)/female
2817under 15 years: 1.03 male(s)/female
281815-64 years: 1.02 male(s)/female
281965 years and over: 0.88 male(s)/female
2820total population: 1.02 male(s)/female (2000 est.)</Sexratio>
2821<Religions>Muslim 97% (Shi'a 60%-65%, Sunni 32%-37%), Christian or other 3%</Religions>
2822<Countryname>Iraq </Countryname>
2823<Capital>Baghdad</Capital>
2824<Flagdescription>three equal horizontal bands of red (top), white, and black with three green five-pointed stars in a horizontal line centered in the white band; the phrase ALLAHU AKBAR (God is Great) in green Arabic script - Allahu to the right of the middle star and Akbar to the left of the middle star - was added in January 1991 during the Persian Gulf crisis; similar to the flag of Syria which has two stars but no script and the flag of Yemen which has a plain white band; also similar to the flag of Egypt which has a symbolic eagle centered in the white band</Flagdescription>
2825<GDP>purchasing power parity - $59.9 billion (1999 est.)</GDP>
2826<Industries>petroleum, chemicals, textiles, construction materials, food processing</Industries>
2827<Exports>$12.7 billion (1999 est.)</Exports>
2828<Imports>$8.9 billion (1999 est.)</Imports>
2829<Currency>1 Iraqi dinar (ID) = 1,000 fils</Currency>
2830<Airports>113 (1999 est.)</Airports>
2831</record>
2832<record>
2833<Location>Eastern Asia, island chain between the North Pacific Ocean and the Sea of Japan, east of the Korean Peninsula</Location>
2834<Geographiccoordinates>36 00 N, 138 00 E</Geographiccoordinates>
2835<Area>377835</Area>
2836<Climate>varies from tropical in south to cool temperate in north</Climate>
2837<Naturalresources>negligible mineral resources, fish</Naturalresources>
2838<Population>126549976</Population>
2839<Populationgrowthrate>0.18% (2000 est.)</Populationgrowthrate>
2840<Sexratio>
2841at birth: 1.05 male(s)/female
2842under 15 years: 1.05 male(s)/female
284315-64 years: 1.01 male(s)/female
284465 years and over: 0.72 male(s)/female
2845total population: 0.96 male(s)/female (2000 est.)</Sexratio>
2846<Religions>observe both Shinto and Buddhist 84%, other 16% (including Christian 0.7%)</Religions>
2847<Countryname>Japan </Countryname>
2848<Capital>Tokyo</Capital>
2849<Flagdescription>white with a large red disk (representing the sun without rays) in the center</Flagdescription>
2850<GDP>purchasing power parity - $2.95 trillion (1999 est.)</GDP>
2851<Industries>among world's largest and technologically advanced producers of motor vehicles, electronic equipment, machine tools, steel and nonferrous metals, ships, chemicals; textiles, processed foods</Industries>
2852<Exports>$413 billion (f.o.b., 1999 est.)</Exports>
2853<Imports>$306 billion (c.i.f., 1999 est.)</Imports>
2854<Currency>yen</Currency>
2855<Airports>171 (1999 est.)</Airports>
2856</record>
2857<record>
2858<Location>Western Europe, island in the English Channel, northwest of France</Location>
2859<Geographiccoordinates>49 15 N, 2 10 W</Geographiccoordinates>
2860<Area>116</Area>
2861<Climate>temperate; mild winters and cool summers</Climate>
2862<Naturalresources>arable land</Naturalresources>
2863<Population>88915</Population>
2864<Populationgrowthrate>0.52% (2000 est.)</Populationgrowthrate>
2865<Sexratio>
2866at birth: 1.11 male(s)/female
2867under 15 years: 1.08 male(s)/female
286815-64 years: 0.99 male(s)/female
286965 years and over: 0.74 male(s)/female
2870total population: 0.96 male(s)/female (2000 est.)</Sexratio>
2871<Religions>Anglican, Roman Catholic, Baptist, Congregational New Church, Methodist, Presbyterian</Religions>
2872<Countryname>Jersey </Countryname>
2873<Capital>Saint Helier</Capital>
2874<Flagdescription>white with a diagonal red cross extending to the corners of the flag and in the upper quadrant, surmounted by a yellow crown, a red shield holding the three lions of England in yellow</Flagdescription>
2875<GDP>purchasing power parity - $2.2 billion (1999 est.)</GDP>
2876<Industries>tourism, banking and finance, dairy</Industries>
2877<Exports>$NA</Exports>
2878<Imports>$NA</Imports>
2879<Currency>1 Jersey pound = 100 pence</Currency>
2880<Airports>1 (1999 est.)</Airports>
2881</record>
2882<record>
2883<Location>Caribbean, island in the Caribbean Sea, south of Cuba</Location>
2884<Geographiccoordinates>18 15 N, 77 30 W</Geographiccoordinates>
2885<Area>10990</Area>
2886<Climate>tropical; hot, humid; temperate interior</Climate>
2887<Naturalresources>bauxite, gypsum, limestone</Naturalresources>
2888<Population>2652689</Population>
2889<Populationgrowthrate>0.46% (2000 est.)</Populationgrowthrate>
2890<Sexratio>
2891at birth: 1.05 male(s)/female
2892under 15 years: 1.05 male(s)/female
289315-64 years: 0.99 male(s)/female
289465 years and over: 0.81 male(s)/female
2895total population: 1 male(s)/female (2000 est.)</Sexratio>
2896<Religions>Protestant 61.3% (Church of God 21.2%, Baptist 8.8%, Anglican 5.5%, Seventh-Day Adventist 9%, Pentecostal 7.6%, Methodist 2.7%, United Church 2.7%, Brethren 1.1%, Jehovah's Witness 1.6%, Moravian 1.1%), Roman Catholic 4%, other, including some spiritual cults 34.7%</Religions>
2897<Countryname>Jamaica </Countryname>
2898<Capital>Kingston</Capital>
2899<Flagdescription>diagonal yellow cross divides the flag into four triangles - green (top and bottom) and black (hoist side and outer side)</Flagdescription>
2900<GDP>purchasing power parity - $8.8 billion (1999 est.)</GDP>
2901<Industries>tourism, bauxite, textiles, food processing, light manufactures, rum, cement, metal, paper, chemical products</Industries>
2902<Exports>$1.4 billion (f.o.b., 1999 est.)</Exports>
2903<Imports>$2.7 billion (f.o.b., 1999 est.)</Imports>
2904<Currency>1 Jamaican dollar (J$) = 100 cents</Currency>
2905<Airports>36 (1999 est.)</Airports>
2906<Illicitdrugs>transshipment point for cocaine from Central and South America to North America and Europe; illicit cultivation of cannabis; government has an active manual cannabis eradication program</Illicitdrugs>
2907</record>
2908<record>
2909<Location>Northern Europe, island between the Greenland Sea and the Norwegian Sea, northeast of Iceland</Location>
2910<Geographiccoordinates>71 00 N, 8 00 W</Geographiccoordinates>
2911<Area>373</Area>
2912<Climate>arctic maritime with frequent storms and persistent fog</Climate>
2913<Naturalresources>none</Naturalresources>
2914<Population></Population>
2915<Countryname>Jan Mayen </Countryname>
2916<Flagdescription>the flag of Norway is used</Flagdescription>
2917<Airports>1 (1999 est.)</Airports>
2918</record>
2919<record>
2920<Location>Middle East, northwest of Saudi Arabia</Location>
2921<Geographiccoordinates>31 00 N, 36 00 E</Geographiccoordinates>
2922<Area>89213</Area>
2923<Climate>mostly arid desert; rainy season in west (November to April)</Climate>
2924<Naturalresources>phosphates, potash, shale oil</Naturalresources>
2925<Population>4998564</Population>
2926<Populationgrowthrate>3.1% (2000 est.)</Populationgrowthrate>
2927<Sexratio>
2928at birth: 1.06 male(s)/female
2929under 15 years: 1.05 male(s)/female
293015-64 years: 1.14 male(s)/female
293165 years and over: 0.98 male(s)/female
2932total population: 1.1 male(s)/female (2000 est.)</Sexratio>
2933<Religions>Sunni Muslim 96%, Christian 4% (1997 est.)</Religions>
2934<Countryname>Jordan </Countryname>
2935<Capital>Amman</Capital>
2936<Flagdescription>three equal horizontal bands of black (top), white, and green with a red isosceles triangle based on the hoist side bearing a small white seven-pointed star; the seven points on the star represent the seven fundamental laws of the Koran</Flagdescription>
2937<GDP>purchasing power parity - $16 billion (1999 est.)</GDP>
2938<Industries>phosphate mining, petroleum refining, cement, potash, light manufacturing, tourism</Industries>
2939<Exports>$1.8 billion (f.o.b., 1999 est.)</Exports>
2940<Imports>$3.3 billion (c.i.f., 1999 est.)</Imports>
2941<Currency>1 Jordanian dinar (JD) = 1,000 fils</Currency>
2942<Airports>20 (1999 est.)</Airports>
2943</record>
2944<record>
2945<Location>Oceania, atoll in the North Pacific Ocean, about one-third of the way from Hawaii to the Marshall Islands</Location>
2946<Geographiccoordinates>16 45 N, 169 30 W</Geographiccoordinates>
2947<Area>2</Area>
2948<Climate>tropical, but generally dry; consistent northeast trade winds with little seasonal temperature variation</Climate>
2949<Naturalresources>NA; guano deposits worked until depletion about 1890</Naturalresources>
2950<Population></Population>
2951<Countryname>Johnston Atoll </Countryname>
2952<Flagdescription>the flag of the US is used</Flagdescription>
2953<Airports>1 (1999 est.)</Airports>
2954</record>
2955<record>
2956<Location>Southern Africa, island in the Mozambique Channel, about one-third of the way between Madagascar and Mozambique</Location>
2957<Geographiccoordinates>17 03 S, 42 45 E</Geographiccoordinates>
2958<Area>4</Area>
2959<Climate>tropical</Climate>
2960<Naturalresources>guano deposits and other fertilizers</Naturalresources>
2961<Population></Population>
2962<Countryname>Juan de Nova Island </Countryname>
2963<Flagdescription>the flag of France is used</Flagdescription>
2964<Airports>1 (1999 est.)</Airports>
2965</record>
2966<record>
2967<Location>Eastern Africa, bordering the Indian Ocean, between Somalia and Tanzania</Location>
2968<Geographiccoordinates>1 00 N, 38 00 E</Geographiccoordinates>
2969<Area>582650</Area>
2970<Climate>varies from tropical along coast to arid in interior</Climate>
2971<Naturalresources>gold, limestone, soda ash, salt barites, rubies, fluorspar, garnets, wildlife, hydropower</Naturalresources>
2972<Population>30339770</Population>
2973<Populationgrowthrate>1.53% (2000 est.)</Populationgrowthrate>
2974<Sexratio>
2975at birth: 1.03 male(s)/female
2976under 15 years: 1.02 male(s)/female
297715-64 years: 1.01 male(s)/female
297865 years and over: 0.79 male(s)/female
2979total population: 1.01 male(s)/female (2000 est.)</Sexratio>
2980<Religions>Protestant 38%, Roman Catholic 28%, indigenous beliefs 26%, Muslim 7%, other 1%</Religions>
2981<Countryname>Kenya </Countryname>
2982<Capital>Nairobi</Capital>
2983<Flagdescription>three equal horizontal bands of black (top), red, and green; the red band is edged in white; a large warrior's shield covering crossed spears is superimposed at the center</Flagdescription>
2984<GDP>purchasing power parity - $45.1 billion (1999 est.)</GDP>
2985<Industries>small-scale consumer goods (plastic, furniture, batteries, textiles, soap, cigarettes, flour), agricultural products processing; oil refining, cement; tourism</Industries>
2986<Exports>$2.2 billion (f.o.b., 1999 est.)</Exports>
2987<Imports>$3.3 billion (f.o.b., 1999 est.)</Imports>
2988<Currency>1 Kenyan shilling (KSh) = 100 cents</Currency>
2989<Airports>230 (1999 est.)</Airports>
2990<Illicitdrugs>widespread harvesting of small, wild plots of marijuana and qat (chat); transit country for South Asian heroin destined for Europe and, sometimes, North America; Indian methaqualone also transits on way to South Africa</Illicitdrugs>
2991</record>
2992<record>
2993<Location>Central Asia, west of China</Location>
2994<Geographiccoordinates>41 00 N, 75 00 E</Geographiccoordinates>
2995<Area>198500</Area>
2996<Climate>dry continental to polar in high Tien Shan; subtropical in southwest (Fergana Valley); temperate in northern foothill zone</Climate>
2997<Naturalresources>abundant hydropower; significant deposits of gold and rare earth metals; locally exploitable coal, oil, and natural gas; other deposits of nepheline, mercury, bismuth, lead, and zinc</Naturalresources>
2998<Population>4685230</Population>
2999<Populationgrowthrate>1.43% (2000 est.)</Populationgrowthrate>
3000<Sexratio>
3001at birth: 1.05 male(s)/female
3002under 15 years: 1.02 male(s)/female
300315-64 years: 0.96 male(s)/female
300465 years and over: 0.6 male(s)/female
3005total population: 0.95 male(s)/female (2000 est.)</Sexratio>
3006<Religions>Muslim 75%, Russian Orthodox 20%, other 5%</Religions>
3007<Countryname>Kyrgyzstan </Countryname>
3008<Capital>Bishkek</Capital>
3009<Flagdescription>red field with a yellow sun in the center having 40 rays representing the 40 Kirghiz tribes; on the obverse side the rays run counterclockwise, on the reverse, clockwise; in the center of the sun is a red ring crossed by two sets of three lines, a stylized representation of the roof of the traditional Kirghiz yurt</Flagdescription>
3010<GDP>purchasing power parity - $10.3 billion (1999 est.)</GDP>
3011<Industries>small machinery, textiles, food processing, cement, shoes, sawn logs, refrigerators, furniture, electric motors, gold, rare earth metals</Industries>
3012<Exports>$515 million (1999 est.)</Exports>
3013<Imports>$590 million (1999 est.)</Imports>
3014<Currency>1 Kyrgyzstani som (KGS) = 100 tyiyn</Currency>
3015<Airports>54 (1994 est.)</Airports>
3016<Illicitdrugs>limited illicit cultivator of cannabis and opium poppy, mostly for CIS consumption; limited government eradication program; increasingly used as transshipment point for illicit drugs to Russia and Western Europe from Southwest Asia</Illicitdrugs>
3017</record>
3018<record>
3019<Location>Eastern Asia, northern half of the Korean Peninsula bordering the Korea Bay and the Sea of Japan, between China and South Korea</Location>
3020<Geographiccoordinates>40 00 N, 127 00 E</Geographiccoordinates>
3021<Area>120540</Area>
3022<Climate>temperate with rainfall concentrated in summer</Climate>
3023<Naturalresources>coal, lead, tungsten, zinc, graphite, magnesite, iron ore, copper, gold, pyrites, salt, fluorspar, hydropower</Naturalresources>
3024<Population>21687550</Population>
3025<Populationgrowthrate>1.35% (2000 est.)</Populationgrowthrate>
3026<Sexratio>
3027at birth: 1.05 male(s)/female
3028under 15 years: 1.05 male(s)/female
302915-64 years: 0.96 male(s)/female
303065 years and over: 0.46 male(s)/female
3031total population: 0.94 male(s)/female (2000 est.)</Sexratio>
3032<Religions>traditionally Buddhist and Confucianist, some Christian and syncretic Chondogyo (Religion of the Heavenly Way)
3033note: autonomous religious activities now almost nonexistent; government-sponsored religious groups exist to provide illusion of religious freedom</Religions>
3034<Countryname>North Korea </Countryname>
3035<Capital>P'yongyang</Capital>
3036<Flagdescription>three horizontal bands of blue (top), red (triple width), and blue; the red band is edged in white; on the hoist side of the red band is a white disk with a red five-pointed star</Flagdescription>
3037<GDP>purchasing power parity - $22.6 billion (1999 est.)</GDP>
3038<Industries>military products; machine building, electric power, chemicals; mining (coal, iron ore, magnesite, graphite, copper, zinc, lead, and precious metals), metallurgy; textiles, food processing; tourism</Industries>
3039<Exports>$680 million (f.o.b., 1998 est.)</Exports>
3040<Imports>$954 million (c.i.f., 1998 est.)</Imports>
3041<Currency>1 North Korean won (Wn) = 100 chon</Currency>
3042<Airports>49 (1994 est.)</Airports>
3043</record>
3044<record>
3045<Location>Oceania, reef in the North Pacific Ocean, about one-half of the way from Hawaii to American Samoa</Location>
3046<Geographiccoordinates>6 24 N, 162 24 W</Geographiccoordinates>
3047<Area>1</Area>
3048<Climate>tropical, but moderated by prevailing winds</Climate>
3049<Naturalresources>none</Naturalresources>
3050<Population></Population>
3051<Countryname>Kingman Reef </Countryname>
3052<Flagdescription>the flag of the US is used</Flagdescription>
3053<Airports>lagoon was used as a halfway station between Hawaii and American Samoa by Pan American Airways for flying boats in 1937 and 1938</Airports>
3054</record>
3055<record>
3056<Location>Oceania, group of islands in the Pacific Ocean, straddling the equator, about one-half of the way from Hawaii to Australia; note - on 1 January 1995, Kiribati unilaterally moved the International Date Line from the middle of the country to include its easternmost islands and make it the same day throughout the country</Location>
3057<Geographiccoordinates>1 25 N, 173 00 E</Geographiccoordinates>
3058<Area>717</Area>
3059<Climate>tropical; marine, hot and humid, moderated by trade winds</Climate>
3060<Naturalresources>phosphate (production discontinued in 1979)</Naturalresources>
3061<Population>91985</Population>
3062<Populationgrowthrate>2.34% (2000 est.)</Populationgrowthrate>
3063<Sexratio>
3064at birth: 1.05 male(s)/female
3065under 15 years: 1.03 male(s)/female
306615-64 years: 0.97 male(s)/female
306765 years and over: 0.75 male(s)/female
3068total population: 0.99 male(s)/female (2000 est.)</Sexratio>
3069<Religions>Roman Catholic 53%, Protestant (Congregational) 41%, Seventh-Day Adventist, Baha'i, Church of God, Mormon 6% (1985 est.)</Religions>
3070<Countryname>Kiribati </Countryname>
3071<Capital>Tarawa</Capital>
3072<Flagdescription>the upper half is red with a yellow frigate bird flying over a yellow rising sun, and the lower half is blue with three horizontal wavy white stripes to represent the ocean</Flagdescription>
3073<GDP>purchasing power parity - $74 million (1999 est.), supplemented by a nearly equal amount from external sources</GDP>
3074<Industries>fishing, handicrafts</Industries>
3075<Exports>$6 million (f.o.b., 1998)</Exports>
3076<Imports>$37 million (c.i.f., 1998)</Imports>
3077<Currency>1 Australian dollar ($A) = 100 cents</Currency>
3078<Airports>21 (1999 est.)</Airports>
3079</record>
3080<record>
3081<Location>Eastern Asia, southern half of the Korean Peninsula bordering the Sea of Japan and the Yellow Sea</Location>
3082<Geographiccoordinates>37 00 N, 127 30 E</Geographiccoordinates>
3083<Area>98480</Area>
3084<Climate>temperate, with rainfall heavier in summer than winter</Climate>
3085<Naturalresources>coal, tungsten, graphite, molybdenum, lead, hydropower potential</Naturalresources>
3086<Population>47470969</Population>
3087<Populationgrowthrate>0.93% (2000 est.)</Populationgrowthrate>
3088<Sexratio>
3089at birth: 1.13 male(s)/female
3090under 15 years: 1.12 male(s)/female
309115-64 years: 1.03 male(s)/female
309265 years and over: 0.63 male(s)/female
3093total population: 1.01 male(s)/female (2000 est.)</Sexratio>
3094<Religions>Christian 49%, Buddhist 47%, Confucianist 3%, Shamanist, Chondogyo (Religion of the Heavenly Way), and other 1%</Religions>
3095<Countryname>South Korea </Countryname>
3096<Capital>Seoul</Capital>
3097<Flagdescription>white with a red (top) and blue yin-yang symbol in the center; there is a different black trigram from the ancient I Ching (Book of Changes) in each corner of the white field</Flagdescription>
3098<GDP>purchasing power parity - $625.7 billion (1999 est.)</GDP>
3099<Industries>electronics, automobile production, chemicals, shipbuilding, steel, textiles, clothing, footwear, food processing</Industries>
3100<Exports>$144 billion (f.o.b., 1999)</Exports>
3101<Imports>$116 billion (c.i.f., 1999)</Imports>
3102<Currency>1 South Korean won (W) = 100 chun (theoretical)</Currency>
3103<Airports>103 (1999 est.)</Airports>
3104</record>
3105<record>
3106<Location>Southeastern Asia, island in the Indian Ocean, south of Indonesia</Location>
3107<Geographiccoordinates>10 30 S, 105 40 E</Geographiccoordinates>
3108<Area>135</Area>
3109<Climate>tropical; heat and humidity moderated by trade winds</Climate>
3110<Naturalresources>phosphate</Naturalresources>
3111<Population>2564</Population>
3112<Populationgrowthrate>7.77% (2000 est.)</Populationgrowthrate>
3113<Religions>Buddhist 55%, Christian 15%, Muslim 10%, other 20% (1991)</Religions>
3114<Countryname>Christmas Island </Countryname>
3115<Capital>The Settlement</Capital>
3116<Flagdescription>the flag of Australia is used</Flagdescription>
3117<GDP>purchasing power parity - $NA</GDP>
3118<Industries>tourism, phosphate extraction (near depletion)</Industries>
3119<Exports>$NA</Exports>
3120<Imports>$NA</Imports>
3121<Currency>1 Australian dollar ($A) = 100 cents</Currency>
3122<Airports>1 (1999 est.)</Airports>
3123</record>
3124<record>
3125<Location>Middle East, bordering the Persian Gulf, between Iraq and Saudi Arabia</Location>
3126<Geographiccoordinates>29 30 N, 45 45 E</Geographiccoordinates>
3127<Area>17820</Area>
3128<Climate>dry desert; intensely hot summers; short, cool winters</Climate>
3129<Naturalresources>petroleum, fish, shrimp, natural gas</Naturalresources>
3130<Population>1973572</Population>
3131<Populationgrowthrate>3.44% (2000 est.)
3132note: this rate reflects a return to pre-Gulf crisis immigration of expatriates</Populationgrowthrate>
3133<Sexratio>
3134at birth: 1.04 male(s)/female
3135under 15 years: 1.04 male(s)/female
313615-64 years: 1.76 male(s)/female
313765 years and over: 1.82 male(s)/female
3138total population: 1.5 male(s)/female (2000 est.)</Sexratio>
3139<Religions>Muslim 85% (Sunni 45%, Shi'a 40%), Christian, Hindu, Parsi, and other 15%</Religions>
3140<Countryname>Kuwait </Countryname>
3141<Capital>Kuwait</Capital>
3142<Flagdescription>three equal horizontal bands of green (top), white, and red with a black trapezoid based on the hoist side</Flagdescription>
3143<GDP>purchasing power parity - $44.8 billion (1999 est.)</GDP>
3144<Industries>petroleum, petrochemicals, desalination, food processing, construction materials, salt, construction</Industries>
3145<Exports>$13.5 billion (f.o.b., 1999 est.)</Exports>
3146<Imports>$8.1 billion (f.o.b., 1999 est.)</Imports>
3147<Currency>1 Kuwaiti dinar (KD) = 1,000 fils</Currency>
3148<Airports>7 (1999 est.)</Airports>
3149</record>
3150<record>
3151<Location>Central Asia, northwest of China</Location>
3152<Geographiccoordinates>48 00 N, 68 00 E</Geographiccoordinates>
3153<Area>2717300</Area>
3154<Climate>continental, cold winters and hot summers, arid and semiarid</Climate>
3155<Naturalresources>major deposits of petroleum, natural gas, coal, iron ore, manganese, chrome ore, nickel, cobalt, copper, molybdenum, lead, zinc, bauxite, gold, uranium</Naturalresources>
3156<Population>16733227</Population>
3157<Populationgrowthrate>-0.05% (2000 est.)</Populationgrowthrate>
3158<Sexratio>
3159at birth: 1.05 male(s)/female
3160under 15 years: 1.03 male(s)/female
316115-64 years: 0.94 male(s)/female
316265 years and over: 0.51 male(s)/female
3163total population: 0.93 male(s)/female (2000 est.)</Sexratio>
3164<Religions>Muslim 47%, Russian Orthodox 44%, Protestant 2%, other 7%</Religions>
3165<Countryname>Kazakhstan </Countryname>
3166<Capital>Astana
3167note: the government moved from Almaty to Astana in December 1998</Capital>
3168<Flagdescription>sky blue background representing the endless sky and a gold sun with 32 rays soaring above a golden steppe eagle in the center; on the hoist side is a "national ornamentation" in gold</Flagdescription>
3169<GDP>purchasing power parity - $54.5 billion (1999 est.)</GDP>
3170<Industries>oil, coal, iron ore, manganese, chromite, lead, zinc, copper, titanium, bauxite, gold, silver, phosphates, sulfur, iron and steel, nonferrous metal, tractors and other agricultural machinery, electric motors, construction materials</Industries>
3171<Exports>$5.2 billion (1999 est.)</Exports>
3172<Imports>$4.8 billion (1999 est.)</Imports>
3173<Currency>1 Kazakhstani tenge = 100 tiyn</Currency>
3174<Airports>10 (1997 est.)</Airports>
3175<Illicitdrugs>significant illicit cultivation of cannabis and limited cultivation of opium poppy and ephedra (for the drug ephedrone); limited government eradication program; cannabis consumed largely in the CIS; used as transshipment point for illicit drugs to Russia, North America, and Western Europe from Southwest Asia</Illicitdrugs>
3176</record>
3177<record>
3178<Location>Southeastern Asia, northeast of Thailand, west of Vietnam</Location>
3179<Geographiccoordinates>18 00 N, 105 00 E</Geographiccoordinates>
3180<Area>236800</Area>
3181<Climate>tropical monsoon; rainy season (May to November); dry season (December to April)</Climate>
3182<Naturalresources>timber, hydropower, gypsum, tin, gold, gemstones</Naturalresources>
3183<Population>5497459</Population>
3184<Populationgrowthrate>2.5% (2000 est.)</Populationgrowthrate>
3185<Sexratio>
3186at birth: 1.05 male(s)/female
3187under 15 years: 1.02 male(s)/female
318815-64 years: 0.97 male(s)/female
318965 years and over: 0.85 male(s)/female
3190total population: 0.98 male(s)/female (2000 est.)</Sexratio>
3191<Religions>Buddhist 60% (in October 1999, the regime proposed a constitutional amendment making Buddhism the state religion; the National Assembly is expected to vote on the amendment sometime in 2000), animist and other 40%</Religions>
3192<Countryname>Laos </Countryname>
3193<Capital>Vientiane</Capital>
3194<Flagdescription>three horizontal bands of red (top), blue (double width), and red with a large white disk centered in the blue band</Flagdescription>
3195<GDP>purchasing power parity - $7 billion (1999 est.)</GDP>
3196<Industries>tin and gypsum mining, timber, electric power, agricultural processing, construction, garments</Industries>
3197<Exports>$271 million (f.o.b., 1999 est.)</Exports>
3198<Imports>$497 million (f.o.b., 1999 est.)</Imports>
3199<Currency>1 new kip (NK) = 100 at</Currency>
3200<Airports>52 (1999 est.)</Airports>
3201<Illicitdrugs>world's third-largest illicit opium producer (estimated cultivation in 1999 - 21,800 hectares, a 16% decrease over 1998; estimated potential production in 1999 - 140 metric tons, about the same as in 1998); potential heroin producer; transshipment point for heroin and methamphetamines produced in Burma; illicit producer of cannabis</Illicitdrugs>
3202</record>
3203<record>
3204<Location>Middle East, bordering the Mediterranean Sea, between Israel and Syria</Location>
3205<Geographiccoordinates>33 50 N, 35 50 E</Geographiccoordinates>
3206<Area>10400</Area>
3207<Climate>Mediterranean; mild to cool, wet winters with hot, dry summers; Lebanon mountains experience heavy winter snows</Climate>
3208<Naturalresources>limestone, iron ore, salt, water-surplus state in a water-deficit region, arable land</Naturalresources>
3209<Population>3578036</Population>
3210<Populationgrowthrate>1.38% (2000 est.)</Populationgrowthrate>
3211<Sexratio>
3212at birth: 1.05 male(s)/female
3213under 15 years: 1.04 male(s)/female
321415-64 years: 0.91 male(s)/female
321565 years and over: 0.84 male(s)/female
3216total population: 0.94 male(s)/female (2000 est.)</Sexratio>
3217<Religions>Muslim 70% (5 legally recognized Islamic groups - Shi'a, Sunni, Druze, Isma'ilite, Alawite or Nusayri), Christian 30% (11 legally recognized Christian groups - 4 Orthodox Christian, 6 Catholic, 1 Protestant), Jewish NEGL%</Religions>
3218<Countryname>Lebanon </Countryname>
3219<Capital>Beirut</Capital>
3220<Flagdescription>three horizontal bands of red (top), white (double width), and red with a green and brown cedar tree centered in the white band</Flagdescription>
3221<GDP>purchasing power parity - $16.2 billion (1999 est.)</GDP>
3222<Industries>banking; food processing; jewelry; cement; textiles; mineral and chemical products; wood and furniture products; oil refining; metal fabricating</Industries>
3223<Exports>$866 million (f.o.b., 1999 est.)</Exports>
3224<Imports>$5.7 billion (f.o.b., 1999 est.)</Imports>
3225<Currency>1 Lebanese pound = 100 piasters</Currency>
3226<Airports>9 (1999 est.)</Airports>
3227<Illicitdrugs>inconsequential producer of hashish; some heroin processing mostly in the Bekaa valley; a Lebanese/Syrian eradication campaign started in the early 1990s has practically eliminated the opium and cannabis crops</Illicitdrugs>
3228</record>
3229<record>
3230<Location>Eastern Europe, bordering the Baltic Sea, between Estonia and Lithuania</Location>
3231<Geographiccoordinates>57 00 N, 25 00 E</Geographiccoordinates>
3232<Area>64589</Area>
3233<Climate>maritime; wet, moderate winters</Climate>
3234<Naturalresources>minimal; amber, peat, limestone, dolomite, hydropower, arable land</Naturalresources>
3235<Population>2404926</Population>
3236<Populationgrowthrate>-0.84% (2000 est.)</Populationgrowthrate>
3237<Sexratio>
3238at birth: 1.05 male(s)/female
3239under 15 years: 1.04 male(s)/female
324015-64 years: 0.91 male(s)/female
324165 years and over: 0.48 male(s)/female
3242total population: 0.85 male(s)/female (2000 est.)</Sexratio>
3243<Religions>Lutheran, Roman Catholic, Russian Orthodox</Religions>
3244<Countryname>Latvia </Countryname>
3245<Capital>Riga</Capital>
3246<Flagdescription>three horizontal bands of maroon (top), white (half-width), and maroon</Flagdescription>
3247<GDP>purchasing power parity - $9.8 billion (1999 est.)</GDP>
3248<Industries>buses, vans, street and railroad cars, synthetic fibers, agricultural machinery, fertilizers, washing machines, radios, electronics, pharmaceuticals, processed foods, textiles; dependent on imports for energy, raw materials, and intermediate products</Industries>
3249<Exports>$1.9 billion (f.o.b., 1999)</Exports>
3250<Imports>$2.8 billion (f.o.b., 1998)</Imports>
3251<Currency>1 Latvian lat (LVL) = 100 santims</Currency>
3252<Airports>50 (1994 est.)</Airports>
3253<Illicitdrugs>transshipment point for opiates and cannabis from Central and Southwest Asia to Western Europe and Scandinavia and Latin American cocaine and some synthetics from Western Europe to CIS; limited production of illicit amphetamines, ephedrine, and ecstasy for export</Illicitdrugs>
3254</record>
3255<record>
3256<Location>Eastern Europe, bordering the Baltic Sea, between Latvia and Russia</Location>
3257<Geographiccoordinates>56 00 N, 24 00 E</Geographiccoordinates>
3258<Area>65200</Area>
3259<Climate>transitional, between maritime and continental; wet, moderate winters and summers</Climate>
3260<Naturalresources>peat, arable land</Naturalresources>
3261<Population>3620756</Population>
3262<Populationgrowthrate>-0.29% (2000 est.)</Populationgrowthrate>
3263<Sexratio>
3264at birth: 1.05 male(s)/female
3265under 15 years: 1.04 male(s)/female
326615-64 years: 0.93 male(s)/female
326765 years and over: 0.51 male(s)/female
3268total population: 0.88 male(s)/female (2000 est.)</Sexratio>
3269<Religions>Roman Catholic (primarily), Lutheran, Russian Orthodox, Protestant, evangelical Christian Baptist, Muslim, Jewish</Religions>
3270<Countryname>Lithuania </Countryname>
3271<Capital>Vilnius</Capital>
3272<Flagdescription>three equal horizontal bands of yellow (top), green, and red</Flagdescription>
3273<GDP>purchasing power parity - $17.3 billion (1999 est.)</GDP>
3274<Industries>metal-cutting machine tools, electric motors, television sets, refrigerators and freezers, petroleum refining, shipbuilding (small ships), furniture making, textiles, food processing, fertilizers, agricultural machinery, optical equipment, electronic components, computers, amber</Industries>
3275<Exports>$3.3 billion (f.o.b., 1999)</Exports>
3276<Imports>$4.5 billion (f.o.b., 1999)</Imports>
3277<Currency>1 Lithuanian litas = 100 centas</Currency>
3278<Airports>96 (1994 est.)</Airports>
3279<Illicitdrugs>transshipment point for opiates and other illicit drugs from Southwest Asia, Latin America, and Western Europe to Western Europe and Scandinavia</Illicitdrugs>
3280</record>
3281<record>
3282<Location>Western Africa, bordering the North Atlantic Ocean, between Cote d'Ivoire and Sierra Leone</Location>
3283<Geographiccoordinates>6 30 N, 9 30 W</Geographiccoordinates>
3284<Area>111370</Area>
3285<Climate>tropical; hot, humid; dry winters with hot days and cool to cold nights; wet, cloudy summers with frequent heavy showers</Climate>
3286<Naturalresources>iron ore, timber, diamonds, gold, hydropower</Naturalresources>
3287<Population>3164156</Population>
3288<Populationgrowthrate>1.94% (2000 est.)</Populationgrowthrate>
3289<Sexratio>
3290at birth: 1.03 male(s)/female
3291under 15 years: 1 male(s)/female
329215-64 years: 0.95 male(s)/female
329365 years and over: 1.01 male(s)/female
3294total population: 0.98 male(s)/female (2000 est.)</Sexratio>
3295<Religions>indigenous beliefs 40%, Christian 40%, Muslim 20%</Religions>
3296<Countryname>Liberia </Countryname>
3297<Capital>Monrovia</Capital>
3298<Flagdescription>11 equal horizontal stripes of red (top and bottom) alternating with white; there is a white five-pointed star on a blue square in the upper hoist-side corner; the design was based on the US flag</Flagdescription>
3299<GDP>purchasing power parity - $2.85 billion (1999 est.)</GDP>
3300<Industries>rubber processing, palm oil processing, diamonds</Industries>
3301<Exports>$39 million (f.o.b., 1998 est.)</Exports>
3302<Imports>$142 million (f.o.b., 1998 est.)</Imports>
3303<Currency>1 Liberian dollar (L$) = 100 cents</Currency>
3304<Airports>45 (1999 est.)</Airports>
3305<Illicitdrugs>increasingly a transshipment point for Southeast and Southwest Asian heroin and South American cocaine for the European and US markets</Illicitdrugs>
3306</record>
3307<record>
3308<Location>Central Europe, south of Poland</Location>
3309<Geographiccoordinates>48 40 N, 19 30 E</Geographiccoordinates>
3310<Area>48845</Area>
3311<Climate>temperate; cool summers; cold, cloudy, humid winters</Climate>
3312<Naturalresources>brown coal and lignite; small amounts of iron ore, copper and manganese ore; salt; arable land</Naturalresources>
3313<Population>5407956</Population>
3314<Populationgrowthrate>0.12% (2000 est.)</Populationgrowthrate>
3315<Sexratio>
3316at birth: 1.05 male(s)/female
3317under 15 years: 1.05 male(s)/female
331815-64 years: 0.99 male(s)/female
331965 years and over: 0.62 male(s)/female
3320total population: 0.95 male(s)/female (2000 est.)</Sexratio>
3321<Religions>Roman Catholic 60.3%, atheist 9.7%, Protestant 8.4%, Orthodox 4.1%, other 17.5%</Religions>
3322<Countryname>Slovakia </Countryname>
3323<Capital>Bratislava</Capital>
3324<Flagdescription>three equal horizontal bands of white (top), blue, and red superimposed with the Slovak cross in a shield centered on the hoist side; the cross is white centered on a background of red and blue</Flagdescription>
3325<GDP>purchasing power parity - $45.9 billion (1999 est.)</GDP>
3326<Industries>metal and metal products; food and beverages; electricity, gas, coke, oil, nuclear fuel; chemicals and manmade fibers; machinery; paper and printing; earthenware and ceramics; transport vehicles; textiles; electrical and optical apparatus; rubber products</Industries>
3327<Exports>$10.1 billion (f.o.b., 1999 est.)</Exports>
3328<Imports>$11.2 billion (f.o.b., 1999 est.)</Imports>
3329<Currency>1 koruna (Sk) = 100 halierov</Currency>
3330<Airports>36 (1999 est.)</Airports>
3331<Illicitdrugs>transshipment point for Southwest Asian heroin bound for Western Europe</Illicitdrugs>
3332</record>
3333<record>
3334<Location>Oceania, atoll in the North Pacific Ocean, about one-half of the way from Hawaii to American Samoa</Location>
3335<Geographiccoordinates>5 52 N, 162 06 W</Geographiccoordinates>
3336<Area>11</Area>
3337<Climate>equatorial, hot, and very rainy</Climate>
3338<Naturalresources>none</Naturalresources>
3339<Population></Population>
3340<Countryname>Palmyra Atoll </Countryname>
3341<Flagdescription>the flag of the US is used</Flagdescription>
3342<Airports>1 (1999 est.)</Airports>
3343</record>
3344<record>
3345<Location>Central Europe, between Austria and Switzerland</Location>
3346<Geographiccoordinates>47 10 N, 9 32 E</Geographiccoordinates>
3347<Area>160</Area>
3348<Climate>continental; cold, cloudy winters with frequent snow or rain; cool to moderately warm, cloudy, humid summers</Climate>
3349<Naturalresources>hydroelectric potential, arable land</Naturalresources>
3350<Population>32207</Population>
3351<Populationgrowthrate>1.02% (2000 est.)</Populationgrowthrate>
3352<Sexratio>
3353at birth: 1.04 male(s)/female
3354under 15 years: 0.99 male(s)/female
335515-64 years: 1 male(s)/female
335665 years and over: 0.66 male(s)/female
3357total population: 0.96 male(s)/female (2000 est.)</Sexratio>
3358<Religions>Roman Catholic 80%, Protestant 7.4%, unknown 7.7%, other 4.9% (1996)</Religions>
3359<Countryname>Liechtenstein </Countryname>
3360<Capital>Vaduz</Capital>
3361<Flagdescription>two equal horizontal bands of blue (top) and red with a gold crown on the hoist side of the blue band</Flagdescription>
3362<GDP>purchasing power parity - $730 million (1998 est.)</GDP>
3363<Industries>electronics, metal manufacturing, textiles, ceramics, pharmaceuticals, food products, precision instruments, tourism</Industries>
3364<Exports>$2.47 billion (1996)</Exports>
3365<Imports>$917.3 million (1996)</Imports>
3366<Currency>1 Swiss franc, franken, or franco (SFR) = 100 centimes, rappen, or centesimi</Currency>
3367<Airports>none</Airports>
3368</record>
3369<record>
3370<Location>Southern Africa, an enclave of South Africa</Location>
3371<Geographiccoordinates>29 30 S, 28 30 E</Geographiccoordinates>
3372<Area>30355</Area>
3373<Climate>temperate; cool to cold, dry winters; hot, wet summers</Climate>
3374<Naturalresources>water, agricultural and grazing land, some diamonds and other minerals</Naturalresources>
3375<Population>2143141</Population>
3376<Populationgrowthrate>1.65% (2000 est.)</Populationgrowthrate>
3377<Sexratio>
3378at birth: 1.03 male(s)/female
3379under 15 years: 1.01 male(s)/female
338015-64 years: 0.93 male(s)/female
338165 years and over: 0.73 male(s)/female
3382total population: 0.95 male(s)/female (2000 est.)</Sexratio>
3383<Religions>Christian 80%, indigenous beliefs 20%</Religions>
3384<Countryname>Lesotho </Countryname>
3385<Capital>Maseru</Capital>
3386<Flagdescription>divided diagonally from the lower hoist side corner; the upper half is white, bearing the brown silhouette of a large shield with crossed spear and club; the lower half is a diagonal blue band with a green triangle in the corner</Flagdescription>
3387<GDP>purchasing power parity - $4.7 billion (1998 est.)</GDP>
3388<Industries>food, beverages, textiles, handicrafts; construction; tourism</Industries>
3389<Exports>$235 million (f.o.b., 1998 est.)</Exports>
3390<Imports>$700 million (f.o.b., 1998 est.)</Imports>
3391<Currency>1 loti (L) = 100 lisente; note - maloti (M) is the plural form of loti</Currency>
3392<Airports>29 (1999 est.)</Airports>
3393</record>
3394<record>
3395<Location>Western Europe, between France and Germany</Location>
3396<Geographiccoordinates>49 45 N, 6 10 E</Geographiccoordinates>
3397<Area>2586</Area>
3398<Climate>modified continental with mild winters, cool summers</Climate>
3399<Naturalresources>iron ore (no longer exploited), arable land</Naturalresources>
3400<Population>437389</Population>
3401<Populationgrowthrate>1.27% (2000 est.)</Populationgrowthrate>
3402<Sexratio>
3403at birth: 1.03 male(s)/female
3404under 15 years: 1.06 male(s)/female
340515-64 years: 1.02 male(s)/female
340665 years and over: 0.66 male(s)/female
3407total population: 0.97 male(s)/female (2000 est.)</Sexratio>
3408<Religions>Roman Catholic 97%, Protestant and Jewish 3%</Religions>
3409<Countryname>Luxembourg </Countryname>
3410<Capital>Luxembourg</Capital>
3411<Flagdescription>three equal horizontal bands of red (top), white, and light blue; similar to the flag of the Netherlands, which uses a darker blue and is shorter; design was based on the flag of France</Flagdescription>
3412<GDP>purchasing power parity - $14.7 billion (1999 est.)</GDP>
3413<Industries>banking, iron and steel, food processing, chemicals, metal products, engineering, tires, glass, aluminum</Industries>
3414<Exports>$7.5 billion (f.o.b., 1998)</Exports>
3415<Imports>$9.6 billion (c.i.f., 1998)</Imports>
3416<Currency>1 Luxembourg franc (LuxF) = 100 centimes; note - centimes no longer in use</Currency>
3417<Airports>2 (1999 est.)</Airports>
3418</record>
3419<record>
3420<Location>Northern Africa, bordering the Mediterranean Sea, between Egypt and Tunisia</Location>
3421<Geographiccoordinates>25 00 N, 17 00 E</Geographiccoordinates>
3422<Area>1759540</Area>
3423<Climate>Mediterranean along coast; dry, extreme desert interior</Climate>
3424<Naturalresources>petroleum, natural gas, gypsum</Naturalresources>
3425<Population>5115450</Population>
3426<Populationgrowthrate>2.42% (2000 est.)</Populationgrowthrate>
3427<Sexratio>
3428at birth: 1.05 male(s)/female
3429under 15 years: 1.04 male(s)/female
343015-64 years: 1.07 male(s)/female
343165 years and over: 0.98 male(s)/female
3432total population: 1.06 male(s)/female (2000 est.)</Sexratio>
3433<Religions>Sunni Muslim 97%</Religions>
3434<Countryname>Libya </Countryname>
3435<Capital>Tripoli</Capital>
3436<Flagdescription>plain green; green is the traditional color of Islam (the state religion)</Flagdescription>
3437<GDP>purchasing power parity - $39.3 billion (1999 est.)</GDP>
3438<Industries>petroleum, food processing, textiles, handicrafts, cement</Industries>
3439<Exports>$6.6 billion (f.o.b., 1998 est.)</Exports>
3440<Imports>$7 billion (f.o.b., 1998 est.)</Imports>
3441<Currency>1 Libyan dinar (LD) = 1,000 dirhams</Currency>
3442<Airports>142 (1999 est.)</Airports>
3443</record>
3444<record>
3445<Location>Southern Africa, island in the Indian Ocean, east of Mozambique</Location>
3446<Geographiccoordinates>20 00 S, 47 00 E</Geographiccoordinates>
3447<Area>587040</Area>
3448<Climate>tropical along coast, temperate inland, arid in south</Climate>
3449<Naturalresources>graphite, chromite, coal, bauxite, salt, quartz, tar sands, semiprecious stones, mica, fish, hydropower</Naturalresources>
3450<Population>15506472</Population>
3451<Populationgrowthrate>3.02% (2000 est.)</Populationgrowthrate>
3452<Sexratio>
3453at birth: 1.03 male(s)/female
3454under 15 years: 1.01 male(s)/female
345515-64 years: 0.98 male(s)/female
345665 years and over: 0.89 male(s)/female
3457total population: 0.99 male(s)/female (2000 est.)</Sexratio>
3458<Religions>indigenous beliefs 52%, Christian 41%, Muslim 7%</Religions>
3459<Countryname>Madagascar </Countryname>
3460<Capital>Antananarivo</Capital>
3461<Flagdescription>two equal horizontal bands of red (top) and green with a vertical white band of the same width on hoist side</Flagdescription>
3462<GDP>purchasing power parity - $11.5 billion (1999 est.)</GDP>
3463<Industries>meat processing, soap, breweries, tanneries, sugar, textiles, glassware, cement, automobile assembly plant, paper, petroleum, tourism</Industries>
3464<Exports>$600 million (f.o.b., 1998 est.)</Exports>
3465<Imports>$881 million (c.i.f., 1998 est.)</Imports>
3466<Currency>1 Malagasy franc (FMG) = 100 centimes</Currency>
3467<Airports>133 (1999 est.)</Airports>
3468<Illicitdrugs>illicit producer of cannabis (cultivated and wild varieties) used mostly for domestic consumption; transshipment point for heroin</Illicitdrugs>
3469</record>
3470<record>
3471<Location>Caribbean, island in the Caribbean Sea, north of Trinidad and Tobago</Location>
3472<Geographiccoordinates>14 40 N, 61 00 W</Geographiccoordinates>
3473<Area>1100</Area>
3474<Climate>tropical; moderated by trade winds; rainy season (June to October); vulnerable to devastating cyclones (hurricanes) every eight years on average; average temperature 17.3 degrees C; humid</Climate>
3475<Naturalresources>coastal scenery and beaches, cultivable land</Naturalresources>
3476<Population>414516</Population>
3477<Populationgrowthrate>0.96% (2000 est.)</Populationgrowthrate>
3478<Sexratio>
3479at birth: 1.02 male(s)/female
3480under 15 years: 1.03 male(s)/female
348115-64 years: 0.99 male(s)/female
348265 years and over: 0.8 male(s)/female
3483total population: 0.98 male(s)/female (2000 est.)</Sexratio>
3484<Religions>Roman Catholic 95%, Hindu and pagan African 5%</Religions>
3485<Countryname>Martinique </Countryname>
3486<Capital>Fort-de-France</Capital>
3487<Flagdescription>a light blue background is divided into four quadrants by a white cross; in the center of each rectangle is a white snake; the flag of France is used for official occasions</Flagdescription>
3488<GDP>purchasing power parity - $4.24 billion (1996 est.)</GDP>
3489<Industries>construction, rum, cement, oil refining, sugar, tourism</Industries>
3490<Exports>$250 million (f.o.b., 1997)</Exports>
3491<Imports>$2 billion (c.i.f., 1997)</Imports>
3492<Currency>1 French franc (F) = 100 centimes</Currency>
3493<Airports>2 (1999 est.)</Airports>
3494<Illicitdrugs>transshipment point for cocaine and marijuana bound for the US and Europe</Illicitdrugs>
3495</record>
3496<record>
3497<Location>Eastern Asia, bordering the South China Sea and China</Location>
3498<Geographiccoordinates>22 10 N, 113 33 E</Geographiccoordinates>
3499<Area>21</Area>
3500<Climate>subtropical; marine with cool winters, warm summers</Climate>
3501<Naturalresources>NEGL</Naturalresources>
3502<Population>445594</Population>
3503<Populationgrowthrate>1.83% (2000 est.)</Populationgrowthrate>
3504<Sexratio>
3505at birth: 1.05 male(s)/female
3506under 15 years: 1.07 male(s)/female
350715-64 years: 0.9 male(s)/female
350865 years and over: 0.68 male(s)/female
3509total population: 0.92 male(s)/female (2000 est.)</Sexratio>
3510<Religions>Buddhist 50%, Roman Catholic 15%, none and other 35% (1997 est.)</Religions>
3511<Countryname>Macau </Countryname>
3512<Flagdescription>light green with a lotus flower above a stylized bridge and water in white, beneath an arc of five gold, five-pointed stars: one large in center of arc and four smaller</Flagdescription>
3513<GDP>purchasing power parity - $7.65 billion (1998 est.)</GDP>
3514<Industries>clothing, textiles, toys, electronics, footwear, tourism, gambling</Industries>
3515<Exports>$1.7 billion (f.o.b., 1999)</Exports>
3516<Imports>$1.5 billion (c.i.f., 1999)</Imports>
3517<Currency>1 pataca (P) = 100 avos</Currency>
3518<Airports>1 (1999 est.)</Airports>
3519</record>
3520<record>
3521<Location>Eastern Europe, northeast of Romania</Location>
3522<Geographiccoordinates>47 00 N, 29 00 E</Geographiccoordinates>
3523<Area>33843</Area>
3524<Climate>moderate winters, warm summers</Climate>
3525<Naturalresources>lignite, phosphorites, gypsum, arable land</Naturalresources>
3526<Population>4430654</Population>
3527<Populationgrowthrate>-0% (2000 est.)</Populationgrowthrate>
3528<Sexratio>
3529at birth: 1.05 male(s)/female
3530under 15 years: 1.04 male(s)/female
353115-64 years: 0.92 male(s)/female
353265 years and over: 0.59 male(s)/female
3533total population: 0.91 male(s)/female (2000 est.)</Sexratio>
3534<Religions>Eastern Orthodox 98.5%, Jewish 1.5%, Baptist (only about 1,000 members) (1991)</Religions>
3535<Countryname>Moldova </Countryname>
3536<Capital>Chisinau</Capital>
3537<Flagdescription>same color scheme as Romania - three equal vertical bands of blue (hoist side), yellow, and red; emblem in center of flag is of a Roman eagle of gold outlined in black with a red beak and talons carrying a yellow cross in its beak and a green olive branch in its right talons and a yellow scepter in its left talons; on its breast is a shield divided horizontally red over blue with a stylized ox head, star, rose, and crescent all in black-outlined yellow</Flagdescription>
3538<GDP>purchasing power parity - $9.7 billion (1999 est.)</GDP>
3539<Industries>food processing, agricultural machinery, foundry equipment, refrigerators and freezers, washing machines, hosiery, sugar, vegetable oil, shoes, textiles</Industries>
3540<Exports>$470 million (f.o.b., 1999)</Exports>
3541<Imports>$560 million (f.o.b., 1999)</Imports>
3542<Currency>Moldovan leu (MLD) (plural lei)</Currency>
3543<Airports>26 (1994 est.)</Airports>
3544<Illicitdrugs>limited cultivation of opium poppy and cannabis, mostly for CIS consumption; transshipment point for illicit drugs from Southwest Asia via Central Asia to Russia, Western Europe and possibly the US</Illicitdrugs>
3545</record>
3546<record>
3547<Location>Southern Africa, island in the Mozambique Channel, about one-half of the way from northern Madagascar to northern Mozambique</Location>
3548<Geographiccoordinates>12 50 S, 45 10 E</Geographiccoordinates>
3549<Area>374</Area>
3550<Climate>tropical; marine; hot, humid, rainy season during northeastern monsoon (November to May); dry season is cooler (May to November)</Climate>
3551<Naturalresources>NEGL</Naturalresources>
3552<Population>155911</Population>
3553<Populationgrowthrate>4.76% (2000 est.)</Populationgrowthrate>
3554<Sexratio>
3555at birth: 1.03 male(s)/female
3556under 15 years: 1.01 male(s)/female
355715-64 years: 1.2 male(s)/female
355865 years and over: 0.98 male(s)/female
3559total population: 1.1 male(s)/female (2000 est.)</Sexratio>
3560<Religions>Muslim 97%, Christian (mostly Roman Catholic)</Religions>
3561<Countryname>Mayotte </Countryname>
3562<Capital>Mamoutzou</Capital>
3563<Flagdescription>the flag of France is used</Flagdescription>
3564<GDP>purchasing power parity - $85 million (1998 est.)</GDP>
3565<Industries>newly created lobster and shrimp industry, construction</Industries>
3566<Exports>$3.44 million (f.o.b., 1997)</Exports>
3567<Imports>$141.3 million (f.o.b., 1997)</Imports>
3568<Currency>1 French franc (F) = 100 centimes</Currency>
3569<Airports>1 (1999 est.)</Airports>
3570</record>
3571<record>
3572<Location>Northern Asia, between China and Russia</Location>
3573<Geographiccoordinates>46 00 N, 105 00 E</Geographiccoordinates>
3574<Area>1000000</Area>
3575<Climate>desert; continental (large daily and seasonal temperature ranges)</Climate>
3576<Naturalresources>oil, coal, copper, molybdenum, tungsten, phosphates, tin, nickel, zinc, wolfram, fluorspar, gold</Naturalresources>
3577<Population>2650952</Population>
3578<Populationgrowthrate>1.54% (2000 est.)</Populationgrowthrate>
3579<Sexratio>
3580at birth: 1.05 male(s)/female
3581under 15 years: 1.03 male(s)/female
358215-64 years: 1 male(s)/female
358365 years and over: 0.76 male(s)/female
3584total population: 1 male(s)/female (2000 est.)</Sexratio>
3585<Religions>predominantly Tibetan Buddhist, Muslim 4%
3586note: previously limited religious activity because of communist regime</Religions>
3587<Countryname>Mongolia </Countryname>
3588<Capital>Ulaanbaatar</Capital>
3589<Flagdescription>three equal, vertical bands of red (hoist side), blue, and red; centered on the hoist-side red band in yellow is the national emblem ("soyombo" - a columnar arrangement of abstract and geometric representation for fire, sun, moon, earth, water, and the yin-yang symbol)</Flagdescription>
3590<GDP>purchasing power parity - $6.1 billion (1999 est.)</GDP>
3591<Industries>construction materials, mining (particularly coal and copper); food and beverages, processing of animal products</Industries>
3592<Exports>$316.8 million (f.o.b., 1998)</Exports>
3593<Imports>$472.4 million (f.o.b., 1998)</Imports>
3594<Currency>1 tughrik (Tug) = 100 mongos</Currency>
3595<Airports>34 (1994 est.)</Airports>
3596</record>
3597<record>
3598<Location>Caribbean, island in the Caribbean Sea, southeast of Puerto Rico</Location>
3599<Geographiccoordinates>16 45 N, 62 12 W</Geographiccoordinates>
3600<Area>100</Area>
3601<Climate>tropical; little daily or seasonal temperature variation</Climate>
3602<Naturalresources>NEGL</Naturalresources>
3603<Population>6409</Population>
3604<Populationgrowthrate>20.53% (2000 est.)</Populationgrowthrate>
3605<Sexratio>
3606at birth: 1.04 male(s)/female
3607under 15 years: 1 male(s)/female
360815-64 years: 0.92 male(s)/female
360965 years and over: 1.15 male(s)/female
3610total population: 0.96 male(s)/female (2000 est.)</Sexratio>
3611<Religions>Anglican, Methodist, Roman Catholic, Pentecostal, Seventh-Day Adventist, other Christian denominations</Religions>
3612<Countryname>Montserrat </Countryname>
3613<Capital>Plymouth (abandoned in 1997 due to volcanic activity; interim government buildings have been built at Brades, in the Carr's Bay/Little Bay vicinity at the northwest end of Montserrat)</Capital>
3614<Flagdescription>blue, with the flag of the UK in the upper hoist-side quadrant and the Montserratian coat of arms centered in the outer half of the flag; the coat of arms features a woman standing beside a yellow harp with her arm around a black cross</Flagdescription>
3615<GDP>purchasing power parity - $31 million (1998 est.)</GDP>
3616<Industries>tourism, rum, textiles, electronic appliances</Industries>
3617<Exports>$1.5 million (1998)</Exports>
3618<Imports>$26 million (1998)</Imports>
3619<Currency>1 East Caribbean dollar (EC$) = 100 cents</Currency>
3620<Airports>1 (1999 est.)</Airports>
3621</record>
3622<record>
3623<Location>Southern Africa, east of Zambia</Location>
3624<Geographiccoordinates>13 30 S, 34 00 E</Geographiccoordinates>
3625<Area>118480</Area>
3626<Climate>sub-tropical; rainy season (November to May); dry season (May to November)</Climate>
3627<Naturalresources>limestone, arable land, hydropower, unexploited deposits of uranium, coal, and bauxite</Naturalresources>
3628<Population>10385849</Population>
3629<Populationgrowthrate>1.61% (2000 est.)</Populationgrowthrate>
3630<Sexratio>
3631at birth: 1.03 male(s)/female
3632under 15 years: 1 male(s)/female
363315-64 years: 0.97 male(s)/female
363465 years and over: 0.69 male(s)/female
3635total population: 0.97 male(s)/female (2000 est.)</Sexratio>
3636<Religions>Protestant 55%, Roman Catholic 20%, Muslim 20%, indigenous beliefs</Religions>
3637<Countryname>Malawi </Countryname>
3638<Capital>Lilongwe</Capital>
3639<Flagdescription>three equal horizontal bands of black (top), red, and green with a radiant, rising, red sun centered in the black band</Flagdescription>
3640<GDP>purchasing power parity - $9.4 billion (1999 est.)</GDP>
3641<Industries>tobacco, tea, sugar, sawmill products, cement, consumer goods</Industries>
3642<Exports>$510 million (f.o.b., 1999)</Exports>
3643<Imports>$512 million (f.o.b., 1999)</Imports>
3644<Currency>1 Malawian kwacha (MK) = 100 tambala</Currency>
3645<Airports>44 (1999 est.)</Airports>
3646</record>
3647<record>
3648<Location>Southeastern Europe, north of Greece</Location>
3649<Geographiccoordinates>41 50 N, 22 00 E</Geographiccoordinates>
3650<Area>25333</Area>
3651<Climate>warm, dry summers and autumns and relatively cold winters with heavy snowfall</Climate>
3652<Naturalresources>chromium, lead, zinc, manganese, tungsten, nickel, low-grade iron ore, asbestos, sulfur, timber, arable land</Naturalresources>
3653<Population>2041467</Population>
3654<Populationgrowthrate>0.04% (2000 est.)</Populationgrowthrate>
3655<Sexratio>
3656at birth: 1.08 male(s)/female
3657under 15 years: 1.08 male(s)/female
365815-64 years: 1.01 male(s)/female
365965 years and over: 0.8 male(s)/female
3660total population: 1 male(s)/female (2000 est.)</Sexratio>
3661<Religions>Macedonian Orthodox 67%, Muslim 30%, other 3%</Religions>
3662<Countryname>The Former Yugoslav Republic of Macedonia </Countryname>
3663<Capital>Skopje</Capital>
3664<Flagdescription>a rising yellow sun with eight rays extending to the edges of the red field</Flagdescription>
3665<GDP>purchasing power parity - $7.6 billion (1999 est.)</GDP>
3666<Industries>coal, metallic chromium, lead, zinc, ferronickel, textiles, wood products, tobacco</Industries>
3667<Exports>$1.2 billion (f.o.b., 1999 est.)</Exports>
3668<Imports>$1.56 billion (f.o.b., 1999 est.)</Imports>
3669<Currency>1 Macedonian denar (MKD) = 100 deni</Currency>
3670<Airports>16 (1999 est.)</Airports>
3671<Illicitdrugs>increasing transshipment point for Southwest Asian heroin and hashish; minor transit point for South American cocaine destined for Europe</Illicitdrugs>
3672</record>
3673<record>
3674<Location>Western Africa, southwest of Algeria</Location>
3675<Geographiccoordinates>17 00 N, 4 00 W</Geographiccoordinates>
3676<Area>1000000</Area>
3677<Climate>subtropical to arid; hot and dry February to June; rainy, humid, and mild June to November; cool and dry November to February</Climate>
3678<Naturalresources>gold, phosphates, kaolin, salt, limestone, uranium, hydropower
3679note: bauxite, iron ore, manganese, tin, and copper deposits are known but not exploited</Naturalresources>
3680<Population>10685948</Population>
3681<Populationgrowthrate>2.98% (2000 est.)</Populationgrowthrate>
3682<Sexratio>
3683at birth: 1.03 male(s)/female
3684under 15 years: 1.01 male(s)/female
368515-64 years: 0.91 male(s)/female
368665 years and over: 0.89 male(s)/female
3687total population: 0.95 male(s)/female (2000 est.)</Sexratio>
3688<Religions>Muslim 90%, indigenous beliefs 9%, Christian 1%</Religions>
3689<Countryname>Mali </Countryname>
3690<Capital>Bamako</Capital>
3691<Flagdescription>three equal vertical bands of green (hoist side), yellow, and red; uses the popular pan-African colors of Ethiopia</Flagdescription>
3692<GDP>purchasing power parity - $8.5 billion (1999 est.)</GDP>
3693<Industries>minor local consumer goods production and food processing; construction; phosphate and gold mining</Industries>
3694<Exports>$640 million (f.o.b., 1999 est.)</Exports>
3695<Imports>$650 million (f.o.b., 1999 est.)</Imports>
3696<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
3697<Airports>28 (1999 est.)</Airports>
3698</record>
3699<record>
3700<Location>Western Europe, bordering the Mediterranean Sea, on the southern coast of France, near the border with Italy</Location>
3701<Geographiccoordinates>43 44 N, 7 24 E</Geographiccoordinates>
3702<Area>1</Area>
3703<Climate>Mediterranean with mild, wet winters and hot, dry summers</Climate>
3704<Naturalresources>none</Naturalresources>
3705<Population>31693</Population>
3706<Populationgrowthrate>0.48% (2000 est.)</Populationgrowthrate>
3707<Sexratio>
3708at birth: 1.05 male(s)/female
3709under 15 years: 1.05 male(s)/female
371015-64 years: 0.97 male(s)/female
371165 years and over: 0.69 male(s)/female
3712total population: 0.91 male(s)/female (2000 est.)</Sexratio>
3713<Religions>Roman Catholic 90%</Religions>
3714<Countryname>Monaco </Countryname>
3715<Capital>Monaco</Capital>
3716<Flagdescription>two equal horizontal bands of red (top) and white; similar to the flag of Indonesia which is longer and the flag of Poland which is white (top) and red</Flagdescription>
3717<GDP>purchasing power parity - $870 million (1999 est.)</GDP>
3718<Industries>tourism, construction, small-scale industrial and consumer products</Industries>
3719<Exports>$NA; full customs integration with France, which collects and rebates Monegasque trade duties; also participates in EU market system through customs union with France</Exports>
3720<Imports>$NA; full customs integration with France, which collects and rebates Monegasque trade duties; also participates in EU market system through customs union with France</Imports>
3721<Currency>1 French franc (F) = 100 centimes</Currency>
3722<Airports>linked to airport in Nice, France, by helicopter service</Airports>
3723</record>
3724<record>
3725<Location>Northern Africa, bordering the North Atlantic Ocean and the Mediterranean Sea, between Algeria and Western Sahara</Location>
3726<Geographiccoordinates>32 00 N, 5 00 W</Geographiccoordinates>
3727<Area>446550</Area>
3728<Climate>Mediterranean, becoming more extreme in the interior</Climate>
3729<Naturalresources>phosphates, iron ore, manganese, lead, zinc, fish, salt</Naturalresources>
3730<Population>30122350</Population>
3731<Populationgrowthrate>1.74% (2000 est.)</Populationgrowthrate>
3732<Sexratio>
3733at birth: 1.05 male(s)/female
3734under 15 years: 1.04 male(s)/female
373515-64 years: 0.98 male(s)/female
373665 years and over: 0.84 male(s)/female
3737total population: 1 male(s)/female (2000 est.)</Sexratio>
3738<Religions>Muslim 98.7%, Christian 1.1%, Jewish 0.2%</Religions>
3739<Countryname>Morocco </Countryname>
3740<Capital>Rabat</Capital>
3741<Flagdescription>red with a green pentacle (five-pointed, linear star) known as Solomon's seal in the center of the flag; green is the traditional color of Islam</Flagdescription>
3742<GDP>purchasing power parity - $108 billion (1999 est.)</GDP>
3743<Industries>phosphate rock mining and processing, food processing, leather goods, textiles, construction, tourism</Industries>
3744<Exports>$7.1 billion (f.o.b., 1998)</Exports>
3745<Imports>$9.5 billion (f.o.b., 1998)</Imports>
3746<Currency>1 Moroccan dirham (DH) = 100 centimes</Currency>
3747<Airports>70 (1999 est.)</Airports>
3748<Illicitdrugs>illicit producer of hashish; trafficking on the increase for both domestic and international drug markets; shipments of hashish mostly directed to Western Europe; transit point for cocaine from South America destined for Western Europe</Illicitdrugs>
3749</record>
3750<record>
3751<Location>Southern Africa, island in the Indian Ocean, east of Madagascar</Location>
3752<Geographiccoordinates>20 17 S, 57 33 E</Geographiccoordinates>
3753<Area>1860</Area>
3754<Climate>tropical, modified by southeast trade winds; warm, dry winter (May to November); hot, wet, humid summer (November to May)</Climate>
3755<Naturalresources>arable land, fish</Naturalresources>
3756<Population>1179368</Population>
3757<Populationgrowthrate>0.89% (2000 est.)</Populationgrowthrate>
3758<Sexratio>
3759at birth: 1 male(s)/female
3760under 15 years: 1.03 male(s)/female
376115-64 years: 0.99 male(s)/female
376265 years and over: 0.67 male(s)/female
3763total population: 0.98 male(s)/female (2000 est.)</Sexratio>
3764<Religions>Hindu 52%, Christian 28.3% (Roman Catholic 26%, Protestant 2.3%), Muslim 16.6%, other 3.1%</Religions>
3765<Countryname>Mauritius </Countryname>
3766<Capital>Port Louis</Capital>
3767<Flagdescription>four equal horizontal bands of red (top), blue, yellow, and green</Flagdescription>
3768<GDP>purchasing power parity - $12.3 billion (1999 est.)</GDP>
3769<Industries>food processing (largely sugar milling), textiles, clothing; chemicals, metal products, transport equipment, nonelectrical machinery; tourism</Industries>
3770<Exports>$1.7 billion (f.o.b., 1999)</Exports>
3771<Imports>$2.1 billion (f.o.b., 1998)</Imports>
3772<Currency>1 Mauritian rupee (MauR) = 100 cents</Currency>
3773<Airports>5 (1999 est.)</Airports>
3774<Illicitdrugs>minor consumer and transshipment point for heroin from South Asia; small amounts of cannabis produced and consumed locally</Illicitdrugs>
3775</record>
3776<record>
3777<Location>Oceania, atoll in the North Pacific Ocean, about one-third of the way from Honolulu to Tokyo</Location>
3778<Geographiccoordinates>28 13 N, 177 22 W</Geographiccoordinates>
3779<Area>6</Area>
3780<Climate>subtropical, but moderated by prevailing easterly winds</Climate>
3781<Naturalresources>wildlife, terrestrial and aquatic</Naturalresources>
3782<Population></Population>
3783<Countryname>Midway Islands </Countryname>
3784<Capital>none; administered from Washington, DC</Capital>
3785<Flagdescription>the flag of the US is used</Flagdescription>
3786<Airports>3 (1999 est.)</Airports>
3787</record>
3788<record>
3789<Location>Northern Africa, bordering the North Atlantic Ocean, between Senegal and Western Sahara</Location>
3790<Geographiccoordinates>20 00 N, 12 00 W</Geographiccoordinates>
3791<Area>1030700</Area>
3792<Climate>desert; constantly hot, dry, dusty</Climate>
3793<Naturalresources>iron ore, gypsum, fish, copper, phosphate</Naturalresources>
3794<Population>2667859</Population>
3795<Populationgrowthrate>2.94% (2000 est.)</Populationgrowthrate>
3796<Sexratio>
3797at birth: 1.03 male(s)/female
3798under 15 years: 1 male(s)/female
379915-64 years: 0.97 male(s)/female
380065 years and over: 0.71 male(s)/female
3801total population: 0.98 male(s)/female (2000 est.)</Sexratio>
3802<Religions>Muslim 100%</Religions>
3803<Countryname>Mauritania </Countryname>
3804<Capital>Nouakchott</Capital>
3805<Flagdescription>green with a yellow five-pointed star above a yellow, horizontal crescent; the closed side of the crescent is down; the crescent, star, and color green are traditional symbols of Islam</Flagdescription>
3806<GDP>purchasing power parity - $4.9 billion (1999 est.)</GDP>
3807<Industries>fish processing, mining of iron ore and gypsum</Industries>
3808<Exports>$425 million (f.o.b., 1997)</Exports>
3809<Imports>$444 million (f.o.b., 1997)</Imports>
3810<Currency>1 ouguiya (UM) = 5 khoums</Currency>
3811<Airports>26 (1999 est.)</Airports>
3812</record>
3813<record>
3814<Location>Southern Europe, islands in the Mediterranean Sea, south of Sicily (Italy)</Location>
3815<Geographiccoordinates>35 50 N, 14 35 E</Geographiccoordinates>
3816<Area>316</Area>
3817<Climate>Mediterranean with mild, rainy winters and hot, dry summers</Climate>
3818<Naturalresources>limestone, salt, arable land</Naturalresources>
3819<Population>391670</Population>
3820<Populationgrowthrate>0.74% (2000 est.)</Populationgrowthrate>
3821<Sexratio>
3822at birth: 1.06 male(s)/female
3823under 15 years: 1.07 male(s)/female
382415-64 years: 1.01 male(s)/female
382565 years and over: 0.72 male(s)/female
3826total population: 0.98 male(s)/female (2000 est.)</Sexratio>
3827<Religions>Roman Catholic 91%</Religions>
3828<Countryname>Malta </Countryname>
3829<Capital>Valletta</Capital>
3830<Flagdescription>two equal vertical bands of white (hoist side) and red; in the upper hoist-side corner is a representation of the George Cross, edged in red</Flagdescription>
3831<GDP>purchasing power parity - $5.3 billion (1999 est.)</GDP>
3832<Industries>tourism; electronics, ship building and repair, construction; food and beverages, textiles, footwear, clothing, tobacco</Industries>
3833<Exports>$1.8 billion (f.o.b., 1998)</Exports>
3834<Imports>$2.7 billion (f.o.b., 1998)</Imports>
3835<Currency>1 Maltese lira (LM) = 100 cents</Currency>
3836<Airports>1 (1999 est.)</Airports>
3837<Illicitdrugs>minor transshipment point for hashish from North Africa to Western Europe</Illicitdrugs>
3838</record>
3839<record>
3840<Location>Middle East, bordering the Arabian Sea, Gulf of Oman, and Persian Gulf, between Yemen and UAE</Location>
3841<Geographiccoordinates>21 00 N, 57 00 E</Geographiccoordinates>
3842<Area>212460</Area>
3843<Climate>dry desert; hot, humid along coast; hot, dry interior; strong southwest summer monsoon (May to September) in far south</Climate>
3844<Naturalresources>petroleum, copper, asbestos, some marble, limestone, chromium, gypsum, natural gas</Naturalresources>
3845<Population>2533389</Population>
3846<Populationgrowthrate>3.46% (2000 est.)</Populationgrowthrate>
3847<Sexratio>
3848at birth: 1.05 male(s)/female
3849under 15 years: 1.04 male(s)/female
385015-64 years: 1.58 male(s)/female
385165 years and over: 1.11 male(s)/female
3852total population: 1.31 male(s)/female (2000 est.)</Sexratio>
3853<Religions>Ibadhi Muslim 75%, Sunni Muslim, Shi'a Muslim, Hindu</Religions>
3854<Countryname>Oman </Countryname>
3855<Capital>Muscat</Capital>
3856<Flagdescription>three horizontal bands of white, red, and green of equal width with a broad, vertical, red band on the hoist side; the national emblem (a khanjar dagger in its sheath superimposed on two crossed swords in scabbards) in white is centered at the top of the vertical band</Flagdescription>
3857<GDP>purchasing power parity - $19.6 billion (1999 est.)</GDP>
3858<Industries>crude oil production and refining, natural gas production, construction, cement, copper</Industries>
3859<Exports>$7.2 billion (f.o.b., 1999 est.)</Exports>
3860<Imports>$5.4 billion (f.o.b., 1999 est.)</Imports>
3861<Currency>1 Omani rial (RO) = 1,000 baiza</Currency>
3862<Airports>142 (1999 est.)</Airports>
3863</record>
3864<record>
3865<Location>Southern Asia, group of atolls in the Indian Ocean, south-southwest of India</Location>
3866<Geographiccoordinates>3 15 N, 73 00 E</Geographiccoordinates>
3867<Area>300</Area>
3868<Climate>tropical; hot, humid; dry, northeast monsoon (November to March); rainy, southwest monsoon (June to August)</Climate>
3869<Naturalresources>fish</Naturalresources>
3870<Population>301475</Population>
3871<Populationgrowthrate>3.06% (2000 est.)</Populationgrowthrate>
3872<Sexratio>
3873at birth: 1.05 male(s)/female
3874under 15 years: 1.06 male(s)/female
387515-64 years: 1.04 male(s)/female
387665 years and over: 1.09 male(s)/female
3877total population: 1.05 male(s)/female (2000 est.)</Sexratio>
3878<Religions>Sunni Muslim</Religions>
3879<Countryname>Maldives </Countryname>
3880<Capital>Male</Capital>
3881<Flagdescription>red with a large green rectangle in the center bearing a vertical white crescent; the closed side of the crescent is on the hoist side of the flag</Flagdescription>
3882<GDP>purchasing power parity - $540 million (1999 est.)</GDP>
3883<Industries>fish processing, tourism, shipping, boat building, coconut processing, garments, woven mats, rope, handicrafts, coral and sand mining</Industries>
3884<Exports>$98 million (f.o.b., 1998)</Exports>
3885<Imports>$312 million (f.o.b., 1998)</Imports>
3886<Currency>1 rufiyaa (Rf) = 100 laari</Currency>
3887<Airports>5 (1999 est.)</Airports>
3888</record>
3889<record>
3890<Location>Middle America, bordering the Caribbean Sea and the Gulf of Mexico, between Belize and the US and bordering the North Pacific Ocean, between Guatemala and the US</Location>
3891<Geographiccoordinates>23 00 N, 102 00 W</Geographiccoordinates>
3892<Area>1972550</Area>
3893<Climate>varies from tropical to desert</Climate>
3894<Naturalresources>petroleum, silver, copper, gold, lead, zinc, natural gas, timber</Naturalresources>
3895<Population>100349766</Population>
3896<Populationgrowthrate>1.53% (2000 est.)</Populationgrowthrate>
3897<Sexratio>
3898at birth: 1.05 male(s)/female
3899under 15 years: 1.04 male(s)/female
390015-64 years: 0.95 male(s)/female
390165 years and over: 0.81 male(s)/female
3902total population: 0.97 male(s)/female (2000 est.)</Sexratio>
3903<Religions>nominally Roman Catholic 89%, Protestant 6%, other 5%</Religions>
3904<Countryname>Mexico </Countryname>
3905<Capital>Mexico</Capital>
3906<Flagdescription>three equal vertical bands of green (hoist side), white, and red; the coat of arms (an eagle perched on a cactus with a snake in its beak) is centered in the white band</Flagdescription>
3907<GDP>purchasing power parity - $865.5 billion (1999 est.)</GDP>
3908<Industries>food and beverages, tobacco, chemicals, iron and steel, petroleum, mining, textiles, clothing, motor vehicles, consumer durables, tourism</Industries>
3909<Exports>$136.8 billion (f.o.b., 1999), includes in-bond industries (assembly plant operations with links to US companies)</Exports>
3910<Imports>$142.1 billion (f.o.b., 1999), includes in-bond industries (assembly plant operations with links to US companies)</Imports>
3911<Currency>1 New Mexican peso (Mex$) = 100 centavos</Currency>
3912<Airports>1,806 (1999 est.)</Airports>
3913<Illicitdrugs>illicit cultivation of opium poppy (cultivation in 1998 - 5,500 hectares; potential production - 60 metric tons) and cannabis cultivation in 1998 - 4,600 hectares; government eradication efforts have been key in keeping illicit crop levels low; major supplier of heroin and marijuana to the US market; continues as the primary transshipment country for US-bound cocaine from South America; involved in the production and distribution of methamphetamines; upsurge in drug-related violence and official corruption; major drug syndicates growing more powerful</Illicitdrugs>
3914</record>
3915<record>
3916<Location>Southeastern Asia, peninsula and northern one-third of the island of Borneo, bordering Indonesia and the South China Sea, south of Vietnam</Location>
3917<Geographiccoordinates>2 30 N, 112 30 E</Geographiccoordinates>
3918<Area>329750</Area>
3919<Climate>tropical; annual southwest (April to October) and northeast (October to February) monsoons</Climate>
3920<Naturalresources>tin, petroleum, timber, copper, iron ore, natural gas, bauxite</Naturalresources>
3921<Population>21793293</Population>
3922<Populationgrowthrate>2.01% (2000 est.)</Populationgrowthrate>
3923<Sexratio>
3924at birth: 1.06 male(s)/female
3925under 15 years: 1.06 male(s)/female
392615-64 years: 1 male(s)/female
392765 years and over: 0.78 male(s)/female
3928total population: 1.01 male(s)/female (2000 est.)</Sexratio>
3929<Religions>Islam, Buddhism, Daoism, Hinduism, Christianity, Sikhism; note - in addition, Shamanism is practiced in East Malaysia</Religions>
3930<Countryname>Malaysia </Countryname>
3931<Capital>Kuala Lumpur</Capital>
3932<Flagdescription>14 equal horizontal stripes of red (top) alternating with white (bottom); there is a blue rectangle in the upper hoist-side corner bearing a yellow crescent and a yellow fourteen-pointed star; the crescent and the star are traditional symbols of Islam; the design was based on the flag of the US</Flagdescription>
3933<GDP>purchasing power parity - $229.1 billion (1999 est.)</GDP>
3934<Industries>Peninsular Malaysia - rubber and oil palm processing and manufacturing, light manufacturing industry, electronics, tin mining and smelting, logging and processing timber; Sabah - logging, petroleum production; Sarawak - agriculture processing, petroleum production and refining, logging</Industries>
3935<Exports>$83.5 billion (1999 est.)</Exports>
3936<Imports>$61.5 billion (1999 est.)</Imports>
3937<Currency>1 ringgit (M$) = 100 sen</Currency>
3938<Airports>115 (1999 est.)</Airports>
3939<Illicitdrugs>transit point for some illicit drugs going to Western markets; drug trafficking prosecuted vigorously and carries severe penalties</Illicitdrugs>
3940</record>
3941<record>
3942<Location>Southern Africa, bordering the Mozambique Channel, between South Africa and Tanzania</Location>
3943<Geographiccoordinates>18 15 S, 35 00 E</Geographiccoordinates>
3944<Area>801590</Area>
3945<Climate>tropical to subtropical</Climate>
3946<Naturalresources>coal, titanium, natural gas, hydropower</Naturalresources>
3947<Population>19104696</Population>
3948<Populationgrowthrate>1.47% (2000 est.)</Populationgrowthrate>
3949<Sexratio>
3950at birth: 1.03 male(s)/female
3951under 15 years: 0.99 male(s)/female
395215-64 years: 0.97 male(s)/female
395365 years and over: 0.71 male(s)/female
3954total population: 0.97 male(s)/female (2000 est.)</Sexratio>
3955<Religions>indigenous beliefs 50%, Christian 30%, Muslim 20%</Religions>
3956<Countryname>Mozambique </Countryname>
3957<Capital>Maputo</Capital>
3958<Flagdescription>three equal horizontal bands of green (top), black, and yellow with a red isosceles triangle based on the hoist side; the black band is edged in white; centered in the triangle is a yellow five-pointed star bearing a crossed rifle and hoe in black superimposed on an open white book</Flagdescription>
3959<GDP>purchasing power parity - $18.7 billion (1999 est.)</GDP>
3960<Industries>food, beverages, chemicals (fertilizer, soap, paints), petroleum products, textiles, cement, glass, asbestos, tobacco</Industries>
3961<Exports>$300 million (f.o.b., 1999 est.)</Exports>
3962<Imports>$1.6 billion (c.i.f., 1999 est.)</Imports>
3963<Currency>1 metical (Mt) = 100 centavos</Currency>
3964<Airports>170 (1999 est.)</Airports>
3965<Illicitdrugs>Southern African transit hub for South American cocaine probably destined for the European and US markets; producer of hashish and methaqualone</Illicitdrugs>
3966</record>
3967<record>
3968<Location>Oceania, islands in the South Pacific Ocean, east of Australia</Location>
3969<Geographiccoordinates>21 30 S, 165 30 E</Geographiccoordinates>
3970<Area>19060</Area>
3971<Climate>tropical; modified by southeast trade winds; hot, humid</Climate>
3972<Naturalresources>nickel, chrome, iron, cobalt, manganese, silver, gold, lead, copper</Naturalresources>
3973<Population>201816</Population>
3974<Populationgrowthrate>1.52% (2000 est.)</Populationgrowthrate>
3975<Sexratio>
3976at birth: 1.05 male(s)/female
3977under 15 years: 1.04 male(s)/female
397815-64 years: 1.02 male(s)/female
397965 years and over: 0.9 male(s)/female
3980total population: 1.02 male(s)/female (2000 est.)</Sexratio>
3981<Religions>Roman Catholic 60%, Protestant 30%, other 10%</Religions>
3982<Countryname>New Caledonia </Countryname>
3983<Capital>Noumea</Capital>
3984<Flagdescription>the flag of France is used</Flagdescription>
3985<GDP>purchasing power parity - $3 billion (1998 est.)</GDP>
3986<Industries>nickel mining and smelting</Industries>
3987<Exports>$381 million (f.o.b., 1998)</Exports>
3988<Imports>$922 million (c.i.f., 1998)</Imports>
3989<Currency>1 Comptoirs Francais du Pacifique franc (CFPF) = 100 centimes</Currency>
3990<Airports>28 (1999 est.)</Airports>
3991</record>
3992<record>
3993<Location>Oceania, island in the South Pacific Ocean, east of Tonga</Location>
3994<Geographiccoordinates>19 02 S, 169 52 W</Geographiccoordinates>
3995<Area>260</Area>
3996<Climate>tropical; modified by southeast trade winds</Climate>
3997<Naturalresources>fish, arable land</Naturalresources>
3998<Population>2113</Population>
3999<Populationgrowthrate>0.47% (2000 est.)</Populationgrowthrate>
4000<Religions>Ekalesia Niue (Niuean Church - a Protestant church closely related to the London Missionary Society) 75%, Latter-Day Saints 10%, other 15% (mostly Roman Catholic, Jehovah's Witnesses, Seventh-Day Adventist)</Religions>
4001<Countryname>Niue </Countryname>
4002<Capital>Alofi</Capital>
4003<Flagdescription>yellow with the flag of the UK in the upper hoist-side quadrant; the flag of the UK bears five yellow five-pointed stars - a large one on a blue disk in the center and a smaller one on each arm of the bold red cross</Flagdescription>
4004<GDP>purchasing power parity - $4.5 million (1994 est.)</GDP>
4005<Industries>tourism, handicrafts, food processing</Industries>
4006<Exports>$117,500 (f.o.b., 1989)</Exports>
4007<Imports>$4.1 million (c.i.f., 1989)</Imports>
4008<Currency>1 New Zealand dollar (NZ$) = 100 cents</Currency>
4009<Airports>1 (1999 est.)</Airports>
4010</record>
4011<record>
4012<Location>Oceania, island in the South Pacific Ocean, east of Australia</Location>
4013<Geographiccoordinates>29 02 S, 167 57 E</Geographiccoordinates>
4014<Area>34</Area>
4015<Climate>subtropical, mild, little seasonal temperature variation</Climate>
4016<Naturalresources>fish</Naturalresources>
4017<Population>1892</Population>
4018<Populationgrowthrate>-0.68% (2000 est.)</Populationgrowthrate>
4019<Religions>Anglican 39%, Roman Catholic 11.7%, Uniting Church in Australia 16.4%, Seventh-Day Adventist 4.4%, none 9.2%, unknown 16.9%, other 2.4% (1986)</Religions>
4020<Countryname>Norfolk Island </Countryname>
4021<Capital>Kingston</Capital>
4022<Flagdescription>three vertical bands of green (hoist side), white, and green with a large green Norfolk Island pine tree centered in the slightly wider white band</Flagdescription>
4023<GDP>purchasing power parity - $NA</GDP>
4024<Industries>tourism</Industries>
4025<Exports>$1.5 million (f.o.b., FY91/92)</Exports>
4026<Imports>$17.9 million (c.i.f., FY91/92)</Imports>
4027<Currency>1 Australian dollar ($A) = 100 cents</Currency>
4028<Airports>1 (1999 est.)</Airports>
4029</record>
4030<record>
4031<Location>Western Africa, southeast of Algeria</Location>
4032<Geographiccoordinates>16 00 N, 8 00 E</Geographiccoordinates>
4033<Area>1000000</Area>
4034<Climate>desert; mostly hot, dry, dusty; tropical in extreme south</Climate>
4035<Naturalresources>uranium, coal, iron ore, tin, phosphates, gold, petroleum</Naturalresources>
4036<Population>10075511</Population>
4037<Populationgrowthrate>2.75% (2000 est.)</Populationgrowthrate>
4038<Sexratio>
4039at birth: 1.03 male(s)/female
4040under 15 years: 1.04 male(s)/female
404115-64 years: 0.95 male(s)/female
404265 years and over: 1.11 male(s)/female
4043total population: 1 male(s)/female (2000 est.)</Sexratio>
4044<Religions>Muslim 80%, remainder indigenous beliefs and Christians</Religions>
4045<Countryname>Niger </Countryname>
4046<Capital>Niamey</Capital>
4047<Flagdescription>three equal horizontal bands of orange (top), white, and green with a small orange disk (representing the sun) centered in the white band; similar to the flag of India, which has a blue spoked wheel centered in the white band</Flagdescription>
4048<GDP>purchasing power parity - $9.6 billion (1999 est.)</GDP>
4049<Industries>uranium mining, cement, brick, textiles, food processing, chemicals, slaughterhouses</Industries>
4050<Exports>$269 million (f.o.b., 1997)</Exports>
4051<Imports>$295 million (c.i.f., 1997)</Imports>
4052<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
4053<Airports>27 (1999 est.)</Airports>
4054</record>
4055<record>
4056<Location>Oceania, group of islands in the South Pacific Ocean, about three-quarters of the way from Hawaii to Australia</Location>
4057<Geographiccoordinates>16 00 S, 167 00 E</Geographiccoordinates>
4058<Area>14760</Area>
4059<Climate>tropical; moderated by southeast trade winds</Climate>
4060<Naturalresources>manganese, hardwood forests, fish</Naturalresources>
4061<Population>189618</Population>
4062<Populationgrowthrate>1.74% (2000 est.)</Populationgrowthrate>
4063<Sexratio>
4064at birth: 1.05 male(s)/female
4065under 15 years: 1.04 male(s)/female
406615-64 years: 1.05 male(s)/female
406765 years and over: 1.18 male(s)/female
4068total population: 1.05 male(s)/female (2000 est.)</Sexratio>
4069<Religions>Presbyterian 36.7%, Anglican 15%, Roman Catholic 15%, indigenous beliefs 7.6%, Seventh-Day Adventist 6.2%, Church of Christ 3.8%, other 15.7%</Religions>
4070<Countryname>Vanuatu </Countryname>
4071<Capital>Port-Vila</Capital>
4072<Flagdescription>two equal horizontal bands of red (top) and green with a black isosceles triangle (based on the hoist side) all separated by a black-edged yellow stripe in the shape of a horizontal Y (the two points of the Y face the hoist side and enclose the triangle); centered in the triangle is a boar's tusk encircling two crossed namele leaves, all in yellow</Flagdescription>
4073<GDP>purchasing power parity - $245 million (1999 est.)</GDP>
4074<Industries>food and fish freezing, wood processing, meat canning</Industries>
4075<Exports>$33.8 million (f.o.b., 1998)</Exports>
4076<Imports>$76.2 million (f.o.b., 1998)</Imports>
4077<Currency>1 vatu (VT) = 100 centimes</Currency>
4078<Airports>32 (1999 est.)</Airports>
4079</record>
4080<record>
4081<Location>Western Africa, bordering the Gulf of Guinea, between Benin and Cameroon</Location>
4082<Geographiccoordinates>10 00 N, 8 00 E</Geographiccoordinates>
4083<Area>923768</Area>
4084<Climate>varies; equatorial in south, tropical in center, arid in north</Climate>
4085<Naturalresources>petroleum, tin, columbite, iron ore, coal, limestone, lead, zinc, natural gas, hydropower, arable land</Naturalresources>
4086<Population>123337822</Population>
4087<Populationgrowthrate>2.67% (2000 est.)</Populationgrowthrate>
4088<Sexratio>
4089at birth: 1.03 male(s)/female
4090under 15 years: 1.01 male(s)/female
409115-64 years: 1.04 male(s)/female
409265 years and over: 1 male(s)/female
4093total population: 1.02 male(s)/female (2000 est.)</Sexratio>
4094<Religions>Muslim 50%, Christian 40%, indigenous beliefs 10%</Religions>
4095<Countryname>Nigeria </Countryname>
4096<Capital>Abuja
4097note: on 12 December 1991 the capital was officially moved from Lagos to Abuja; many government offices remain in Lagos pending completion of facilities in Abuja</Capital>
4098<Flagdescription>three equal vertical bands of green (hoist side), white, and green</Flagdescription>
4099<GDP>purchasing power parity - $110.5 billion (1999 est.)</GDP>
4100<Industries>crude oil, coal, tin, columbite, palm oil, peanuts, cotton, rubber, wood, hides and skins, textiles, cement and other construction materials, food products, footwear, chemicals, fertilizer, printing, ceramics, steel</Industries>
4101<Exports>$13.1 billion (f.o.b., 1999)</Exports>
4102<Imports>$10 billion (f.o.b., 1999)</Imports>
4103<Currency>1 naira (N) = 100 kobo</Currency>
4104<Airports>71 (1999 est.)</Airports>
4105<Illicitdrugs>facilitates movement of heroin en route from Southeast and Southwest Asia to Western Europe and North America; increasingly a transit route for cocaine from South America intended for European, East Asian, and North American markets</Illicitdrugs>
4106</record>
4107<record>
4108<Location>Western Europe, bordering the North Sea, between Belgium and Germany</Location>
4109<Geographiccoordinates>52 30 N, 5 45 E</Geographiccoordinates>
4110<Area>41532</Area>
4111<Climate>temperate; marine; cool summers and mild winters</Climate>
4112<Naturalresources>natural gas, petroleum, arable land</Naturalresources>
4113<Population>15892237</Population>
4114<Populationgrowthrate>0.57% (2000 est.)</Populationgrowthrate>
4115<Sexratio>
4116at birth: 1.05 male(s)/female
4117under 15 years: 1.05 male(s)/female
411815-64 years: 1.03 male(s)/female
411965 years and over: 0.69 male(s)/female
4120total population: 0.98 male(s)/female (2000 est.)</Sexratio>
4121<Religions>Roman Catholic 34%, Protestant 25%, Muslim 3%, other 2%, unaffiliated 36% (1991)</Religions>
4122<Countryname>Netherlands </Countryname>
4123<Capital>Amsterdam; The Hague is the seat of government</Capital>
4124<Flagdescription>three equal horizontal bands of red (top), white, and blue; similar to the flag of Luxembourg, which uses a lighter blue and is longer</Flagdescription>
4125<GDP>purchasing power parity - $365.1 billion (1999 est.)</GDP>
4126<Industries>agroindustries, metal and engineering products, electrical machinery and equipment, chemicals, petroleum, construction, microelectronics, fishing</Industries>
4127<Exports>$169 billion (f.o.b., 1998)</Exports>
4128<Imports>$152 billion (f.o.b., 1998)</Imports>
4129<Currency>1 Netherlands guilder, gulden, or florin (f.) = 100 cents; note - to be replaced by the euro on 1 January 2002</Currency>
4130<Airports>28 (1999 est.)</Airports>
4131<Illicitdrugs>major European producer of illicit amphetamines and other synthetic drugs; important gateway for cocaine, heroin, and hashish entering Europe</Illicitdrugs>
4132</record>
4133<record>
4134<Location>Northern Europe, bordering the North Sea and the North Atlantic Ocean, west of Sweden</Location>
4135<Geographiccoordinates>62 00 N, 10 00 E</Geographiccoordinates>
4136<Area>324220</Area>
4137<Climate>temperate along coast, modified by North Atlantic Current; colder interior; rainy year-round on west coast</Climate>
4138<Naturalresources>petroleum, copper, natural gas, pyrites, nickel, iron ore, zinc, lead, fish, timber, hydropower</Naturalresources>
4139<Population>4481162</Population>
4140<Populationgrowthrate>0.5% (2000 est.)</Populationgrowthrate>
4141<Sexratio>
4142at birth: 1.06 male(s)/female
4143under 15 years: 1.06 male(s)/female
414415-64 years: 1.03 male(s)/female
414565 years and over: 0.71 male(s)/female
4146total population: 0.98 male(s)/female (2000 est.)</Sexratio>
4147<Religions>Evangelical Lutheran 86% (state church), other Protestant and Roman Catholic 3%, other 1%, none and unknown 10% (1997)</Religions>
4148<Countryname>Norway </Countryname>
4149<Capital>Oslo</Capital>
4150<Flagdescription>red with a blue cross outlined in white that extends to the edges of the flag; the vertical part of the cross is shifted to the hoist side in the style of the Dannebrog (Danish flag)</Flagdescription>
4151<GDP>purchasing power parity - $111.3 billion (1999 est.)</GDP>
4152<Industries>petroleum and gas, food processing, shipbuilding, pulp and paper products, metals, chemicals, timber, mining, textiles, fishing</Industries>
4153<Exports>$47.3 billion (f.o.b., 1999 est.)</Exports>
4154<Imports>$38.6 billion (f.o.b., 1999 est.)</Imports>
4155<Currency>1 Norwegian krone (NKr) = 100 oere</Currency>
4156<Airports>103 (1999 est.)</Airports>
4157</record>
4158<record>
4159<Location>Southern Asia, between China and India</Location>
4160<Geographiccoordinates>28 00 N, 84 00 E</Geographiccoordinates>
4161<Area>140800</Area>
4162<Climate>varies from cool summers and severe winters in north to subtropical summers and mild winters in south</Climate>
4163<Naturalresources>quartz, water, timber, hydropower, scenic beauty, small deposits of lignite, copper, cobalt, iron ore</Naturalresources>
4164<Population>24702119</Population>
4165<Populationgrowthrate>2.34% (2000 est.)</Populationgrowthrate>
4166<Sexratio>
4167at birth: 1.05 male(s)/female
4168under 15 years: 1.07 male(s)/female
416915-64 years: 1.05 male(s)/female
417065 years and over: 0.99 male(s)/female
4171total population: 1.05 male(s)/female (2000 est.)</Sexratio>
4172<Religions>Hindu 90%, Buddhist 5%, Muslim 3%, other 2% (1981)
4173note: only official Hindu state in the world</Religions>
4174<Countryname>Nepal </Countryname>
4175<Capital>Kathmandu</Capital>
4176<Flagdescription>red with a blue border around the unique shape of two overlapping right triangles; the smaller, upper triangle bears a white stylized moon and the larger, lower triangle bears a white 12-pointed sun</Flagdescription>
4177<GDP>purchasing power parity - $27.4 billion (1999 est.)</GDP>
4178<Industries>tourism, carpet, textile; small rice, jute, sugar, and oilseed mills; cigarette; cement and brick production</Industries>
4179<Exports>$485 million (f.o.b., 1998), but does not include unrecorded border trade with India</Exports>
4180<Imports>$1.2 billion (f.o.b., 1998)</Imports>
4181<Currency>1 Nepalese rupee (NR) = 100 paisa</Currency>
4182<Airports>45 (1999 est.)</Airports>
4183<Illicitdrugs>illicit producer of cannabis for the domestic and international drug markets; transit point for opiates from Southeast Asia to the West</Illicitdrugs>
4184</record>
4185<record>
4186<Location>Oceania, island in the South Pacific Ocean, south of the Marshall Islands</Location>
4187<Geographiccoordinates>0 32 S, 166 55 E</Geographiccoordinates>
4188<Area>21</Area>
4189<Climate>tropical; monsoonal; rainy season (November to February)</Climate>
4190<Naturalresources>phosphates</Naturalresources>
4191<Population>11845</Population>
4192<Populationgrowthrate>2.05% (2000 est.)</Populationgrowthrate>
4193<Sexratio>
4194at birth: 1.05 male(s)/female
4195under 15 years: 1.06 male(s)/female
419615-64 years: 0.99 male(s)/female
419765 years and over: 1 male(s)/female
4198total population: 1.02 male(s)/female (2000 est.)</Sexratio>
4199<Religions>Christian (two-thirds Protestant, one-third Roman Catholic)</Religions>
4200<Countryname>Nauru </Countryname>
4201<Capital>no official capital; government offices in Yaren District</Capital>
4202<Flagdescription>blue with a narrow, horizontal, yellow stripe across the center and a large white 12-pointed star below the stripe on the hoist side; the star indicates the country's location in relation to the Equator (the yellow stripe) and the 12 points symbolize the 12 original tribes of Nauru</Flagdescription>
4203<GDP>purchasing power parity - $100 million (1993 est.)</GDP>
4204<Industries>phosphate mining, financial services, coconut products</Industries>
4205<Exports>$25.3 million (f.o.b., 1991)</Exports>
4206<Imports>$21.1 million (c.i.f., 1991)</Imports>
4207<Currency>1 Australian dollar ($A) = 100 cents</Currency>
4208<Airports>1 (1999 est.)</Airports>
4209</record>
4210<record>
4211<Location>Northern South America, bordering the North Atlantic Ocean, between French Guiana and Guyana</Location>
4212<Geographiccoordinates>4 00 N, 56 00 W</Geographiccoordinates>
4213<Area>163270</Area>
4214<Climate>tropical; moderated by trade winds</Climate>
4215<Naturalresources>timber, hydropower, fish, kaolin, shrimp, bauxite, gold, and small amounts of nickel, copper, platinum, iron ore</Naturalresources>
4216<Population>431303</Population>
4217<Populationgrowthrate>0.65% (2000 est.)</Populationgrowthrate>
4218<Sexratio>
4219at birth: 1.05 male(s)/female
4220under 15 years: 1.05 male(s)/female
422115-64 years: 1.04 male(s)/female
422265 years and over: 0.84 male(s)/female
4223total population: 1.03 male(s)/female (2000 est.)</Sexratio>
4224<Religions>Hindu 27.4%, Muslim 19.6%, Roman Catholic 22.8%, Protestant 25.2% (predominantly Moravian), indigenous beliefs 5%</Religions>
4225<Countryname>Suriname </Countryname>
4226<Capital>Paramaribo</Capital>
4227<Flagdescription>five horizontal bands of green (top, double width), white, red (quadruple width), white, and green (double width); there is a large, yellow, five-pointed star centered in the red band</Flagdescription>
4228<GDP>purchasing power parity - $1.48 billion (1999 est.)</GDP>
4229<Industries>bauxite and gold mining, alumina and aluminum production, lumbering, food processing, fishing</Industries>
4230<Exports>$406.1 million (f.o.b., 1998)</Exports>
4231<Imports>$461.4 million (f.o.b., 1998)</Imports>
4232<Currency>1 Surinamese guilder, gulden, or florin (Sf.) = 100 cents</Currency>
4233<Airports>46 (1999 est.)</Airports>
4234<Illicitdrugs>transshipment point for South American drugs destined mostly for Europe</Illicitdrugs>
4235</record>
4236<record>
4237<Location>Caribbean, two island groups in the Caribbean Sea - one includes Curacao and Bonaire north of Venezuela and the other is east of the Virgin Islands</Location>
4238<Geographiccoordinates>12 15 N, 68 45 W</Geographiccoordinates>
4239<Area>960</Area>
4240<Climate>tropical; ameliorated by northeast trade winds</Climate>
4241<Naturalresources>phosphates (Curacao only), salt (Bonaire only)</Naturalresources>
4242<Population>210134</Population>
4243<Populationgrowthrate>1.01% (2000 est.)</Populationgrowthrate>
4244<Sexratio>
4245at birth: 1.05 male(s)/female
4246under 15 years: 1.04 male(s)/female
424715-64 years: 0.9 male(s)/female
424865 years and over: 0.71 male(s)/female
4249total population: 0.92 male(s)/female (2000 est.)</Sexratio>
4250<Religions>Roman Catholic, Protestant, Jewish, Seventh-Day Adventist</Religions>
4251<Countryname>Netherlands Antilles </Countryname>
4252<Capital>Willemstad</Capital>
4253<Flagdescription>white, with a horizontal blue stripe in the center superimposed on a vertical red band, also centered; five white, five-pointed stars are arranged in an oval pattern in the center of the blue band; the five stars represent the five main islands of Bonaire, Curacao, Saba, Sint Eustatius, and Sint Maarten</Flagdescription>
4254<GDP>purchasing power parity - $2.4 billion (1998 est.)</GDP>
4255<Industries>tourism (Curacao, Sint Maarten, and Bonaire), petroleum refining (Curacao), petroleum transshipment facilities (Curacao and Bonaire), light manufacturing (Curacao)</Industries>
4256<Exports>$303 million (f.o.b., 1998)</Exports>
4257<Imports>$1.3 billion (c.i.f., 1998)</Imports>
4258<Currency>1 Netherlands Antillean guilder, gulden, or florin (NAf.) = 100 cents</Currency>
4259<Airports>5 (1999 est.)</Airports>
4260<Illicitdrugs>money-laundering center; transshipment point for South American drugs bound for the US and Europe</Illicitdrugs>
4261</record>
4262<record>
4263<Location>Middle America, bordering both the Caribbean Sea and the North Pacific Ocean, between Costa Rica and Honduras</Location>
4264<Geographiccoordinates>13 00 N, 85 00 W</Geographiccoordinates>
4265<Area>129494</Area>
4266<Climate>tropical in lowlands, cooler in highlands</Climate>
4267<Naturalresources>gold, silver, copper, tungsten, lead, zinc, timber, fish</Naturalresources>
4268<Population>4812569</Population>
4269<Populationgrowthrate>2.2% (2000 est.)</Populationgrowthrate>
4270<Sexratio>
4271at birth: 1.04 male(s)/female
4272under 15 years: 1.04 male(s)/female
427315-64 years: 0.99 male(s)/female
427465 years and over: 0.77 male(s)/female
4275total population: 1 male(s)/female (2000 est.)</Sexratio>
4276<Religions>Roman Catholic 85%, Protestant</Religions>
4277<Countryname>Nicaragua </Countryname>
4278<Capital>Managua</Capital>
4279<Flagdescription>three equal horizontal bands of blue (top), white, and blue with the national coat of arms centered in the white band; the coat of arms features a triangle encircled by the words REPUBLICA DE NICARAGUA on the top and AMERICA CENTRAL on the bottom; similar to the flag of El Salvador, which features a round emblem encircled by the words REPUBLICA DE EL SALVADOR EN LA AMERICA CENTRAL centered in the white band; also similar to the flag of Honduras, which has five blue stars arranged in an X pattern centered in the white band</Flagdescription>
4280<GDP>purchasing power parity - $12.5 billion (1999 est.)</GDP>
4281<Industries>food processing, chemicals, machinery and metal products, textiles, clothing, petroleum refining and distribution, beverages, footwear, wood</Industries>
4282<Exports>$573 million (f.o.b., 1998 est.)</Exports>
4283<Imports>$1.5 billion (c.i.f., 1999 est.)</Imports>
4284<Currency>1 gold cordoba (C$) = 100 centavos</Currency>
4285<Airports>182 (1999 est.)</Airports>
4286<Illicitdrugs>transshipment point for cocaine destined for the US and transshipment point for arms-for-drugs dealing</Illicitdrugs>
4287</record>
4288<record>
4289<Location>Oceania, islands in the South Pacific Ocean, southeast of Australia</Location>
4290<Geographiccoordinates>41 00 S, 174 00 E</Geographiccoordinates>
4291<Area>268680</Area>
4292<Climate>temperate with sharp regional contrasts</Climate>
4293<Naturalresources>natural gas, iron ore, sand, coal, timber, hydropower, gold, limestone</Naturalresources>
4294<Population>3819762</Population>
4295<Populationgrowthrate>1.17% (2000 est.)</Populationgrowthrate>
4296<Sexratio>
4297at birth: 1.05 male(s)/female
4298under 15 years: 1.05 male(s)/female
429915-64 years: 1.01 male(s)/female
430065 years and over: 0.77 male(s)/female
4301total population: 0.99 male(s)/female (2000 est.)</Sexratio>
4302<Religions>Anglican 24%, Presbyterian 18%, Roman Catholic 15%, Methodist 5%, Baptist 2%, other Protestant 3%, unspecified or none 33% (1986)</Religions>
4303<Countryname>New Zealand </Countryname>
4304<Capital>Wellington</Capital>
4305<Flagdescription>blue with the flag of the UK in the upper hoist-side quadrant with four red five-pointed stars edged in white centered in the outer half of the flag; the stars represent the Southern Cross constellation</Flagdescription>
4306<GDP>purchasing power parity - $63.8 billion (1999 est.)</GDP>
4307<Industries>food processing, wood and paper products, textiles, machinery, transportation equipment, banking and insurance, tourism, mining</Industries>
4308<Exports>$12.2 billion (f.o.b., 1998 est.)</Exports>
4309<Imports>$11.2 billion (f.o.b., 1998 est.)</Imports>
4310<Currency>1 New Zealand dollar (NZ$) = 100 cents</Currency>
4311<Airports>111 (1999 est.)</Airports>
4312</record>
4313<record>
4314<Location>body of water between 60 degrees south latitude and Antarctica</Location>
4315<Geographiccoordinates>65 00 S, 0 00 E (nominally), but the Southern Ocean has the unique distinction of being a large circumpolar body of water totally encircling the continent of Antarctica; this ring of water lies between 60 degrees south latitude and the coast of Antarctica, and encompasses 360 degrees of longitude</Geographiccoordinates>
4316<Area>20000000</Area>
4317<Climate>sea temperatures vary from about 10 degrees Centigrade to -2 degrees Centigrade; cyclonic storms travel eastward around the continent and frequently are intense because of the temperature contrast between ice and open ocean; the ocean area from about latitude 40 south to the Antarctic Circle has the strongest average winds found anywhere on Earth; in winter the ocean freezes outward to 65 degrees south latitude in the Pacific sector and 55 degrees south latitude in the Atlantic sector, lowering surface temperatures well below 0 degrees Centigrade; at some coastal points intense persistent drainage winds from the interior keep the shoreline ice-free throughout the winter</Climate>
4318<Naturalresources>probable large and possible giant oil and gas fields on the continental margin, manganese nodules, possible placer deposits, sand and gravel, fresh water as icebergs, squid, whales, and seals - none exploited; krill, fishes</Naturalresources>
4319</record>
4320<record>
4321<Location>Central South America, northeast of Argentina</Location>
4322<Geographiccoordinates>23 00 S, 58 00 W</Geographiccoordinates>
4323<Area>406750</Area>
4324<Climate>subtropical to temperate; substantial rainfall in the eastern portions, becoming semiarid in the far west</Climate>
4325<Naturalresources>hydropower, timber, iron ore, manganese, limestone</Naturalresources>
4326<Population>5585828</Population>
4327<Populationgrowthrate>2.64% (2000 est.)</Populationgrowthrate>
4328<Sexratio>
4329at birth: 1.05 male(s)/female
4330under 15 years: 1.03 male(s)/female
433115-64 years: 1.01 male(s)/female
433265 years and over: 0.85 male(s)/female
4333total population: 1.01 male(s)/female (2000 est.)</Sexratio>
4334<Religions>Roman Catholic 90%, Mennonite, and other Protestant</Religions>
4335<Countryname>Paraguay </Countryname>
4336<Capital>Asuncion</Capital>
4337<Flagdescription>three equal, horizontal bands of red (top), white, and blue with an emblem centered in the white band; unusual flag in that the emblem is different on each side; the obverse (hoist side at the left) bears the national coat of arms (a yellow five-pointed star within a green wreath capped by the words REPUBLICA DEL PARAGUAY, all within two circles); the reverse (hoist side at the right) bears the seal of the treasury (a yellow lion below a red Cap of Liberty and the words Paz y Justicia (Peace and Justice) capped by the words REPUBLICA DEL PARAGUAY, all within two circles)</Flagdescription>
4338<GDP>purchasing power parity - $19.9 billion (1999 est.)</GDP>
4339<Industries>sugar, cement, textiles, beverages, wood products</Industries>
4340<Exports>$3.1 billion (f.o.b., 1999 est.)</Exports>
4341<Imports>$3.2 billion (f.o.b., 1999 est.)</Imports>
4342<Currency>1 guarani (G) = 100 centimos</Currency>
4343<Airports>937 (1999 est.)</Airports>
4344<Illicitdrugs>illicit producer of cannabis, most or all of which is consumed in South America; transshipment country for Bolivian cocaine headed for Southern Cone markets and Europe and a limited amount to the US</Illicitdrugs>
4345</record>
4346<record>
4347<Location>Oceania, islands in the South Pacific Ocean, about one-half of the way from Peru to New Zealand</Location>
4348<Geographiccoordinates>25 04 S, 130 06 W</Geographiccoordinates>
4349<Area>47</Area>
4350<Climate>tropical, hot, humid; modified by southeast trade winds; rainy season (November to March)</Climate>
4351<Naturalresources>miro trees (used for handicrafts), fish
4352note: manganese, iron, copper, gold, silver, and zinc have been discovered offshore</Naturalresources>
4353<Population>54</Population>
4354<Populationgrowthrate>-2.06% (2000 est.)</Populationgrowthrate>
4355<Religions>Seventh-Day Adventist 100%</Religions>
4356<Countryname>Pitcairn Islands </Countryname>
4357<Capital>Adamstown</Capital>
4358<Flagdescription>blue with the flag of the UK in the upper hoist-side quadrant and the Pitcairn Islander coat of arms centered on the outer half of the flag; the coat of arms is yellow, green, and light blue with a shield featuring a yellow anchor</Flagdescription>
4359<GDP>purchasing power parity - $NA</GDP>
4360<Industries>postage stamps, handicrafts</Industries>
4361<Exports>$NA</Exports>
4362<Imports>$NA</Imports>
4363<Currency>1 New Zealand dollar (NZ$) = 100 cents</Currency>
4364<Airports>none</Airports>
4365</record>
4366<record>
4367<Location>Western South America, bordering the South Pacific Ocean, between Chile and Ecuador</Location>
4368<Geographiccoordinates>10 00 S, 76 00 W</Geographiccoordinates>
4369<Area>1285220</Area>
4370<Climate>varies from tropical in east to dry desert in west; temperate to frigid in Andes</Climate>
4371<Naturalresources>copper, silver, gold, petroleum, timber, fish, iron ore, coal, phosphate, potash, hydropower</Naturalresources>
4372<Population>27012899</Population>
4373<Populationgrowthrate>1.75% (2000 est.)</Populationgrowthrate>
4374<Sexratio>
4375at birth: 1.05 male(s)/female
4376under 15 years: 1.03 male(s)/female
437715-64 years: 1.01 male(s)/female
437865 years and over: 0.85 male(s)/female
4379total population: 1.01 male(s)/female (2000 est.)</Sexratio>
4380<Religions>Roman Catholic 90%</Religions>
4381<Countryname>Peru </Countryname>
4382<Capital>Lima</Capital>
4383<Flagdescription>three equal, vertical bands of red (hoist side), white, and red with the coat of arms centered in the white band; the coat of arms features a shield bearing a llama, cinchona tree (the source of quinine), and a yellow cornucopia spilling out gold coins, all framed by a green wreath</Flagdescription>
4384<GDP>purchasing power parity - $116 billion (1999 est.)</GDP>
4385<Industries>mining of metals, petroleum, fishing, textiles, clothing, food processing, cement, auto assembly, steel, shipbuilding, metal fabrication</Industries>
4386<Exports>$5.9 billion (f.o.b., 1999 est.)</Exports>
4387<Imports>$8.4 billion (c.i.f., 1999 est.)</Imports>
4388<Currency>1 nuevo sol (S/.) = 100 centimos</Currency>
4389<Airports>234 (1999 est.)</Airports>
4390<Illicitdrugs>until recently the world's largest coca leaf producer, Peru has reduced the area of coca under cultivation by 24% to 38,700 hectares at the end of 1999; most of cocaine base is shipped to neighboring Colombia, Bolivia, and Brazil for processing into cocaine for the international drug market, but exports of finished cocaine are increasing by maritime conveyance to Mexico, US, and Europe</Illicitdrugs>
4391</record>
4392<record>
4393<Location>Southeastern Asia, group of small islands and reefs in the South China Sea, about one-third of the way from central Vietnam to the northern Philippines</Location>
4394<Geographiccoordinates>16 30 N, 112 00 E</Geographiccoordinates>
4395<Area></Area>
4396<Climate>tropical</Climate>
4397<Naturalresources>none</Naturalresources>
4398<Population></Population>
4399<Countryname>Paracel Islands </Countryname>
4400<Airports>1 (1999 est.)</Airports>
4401</record>
4402<record>
4403<Location>Southeastern Asia, group of reefs and islands in the South China Sea, about two-thirds of the way from southern Vietnam to the southern Philippines</Location>
4404<Geographiccoordinates>8 38 N, 111 55 E</Geographiccoordinates>
4405<Area></Area>
4406<Climate>tropical</Climate>
4407<Naturalresources>fish, guano, undetermined oil and natural gas potential</Naturalresources>
4408<Population></Population>
4409<Countryname>Spratly Islands </Countryname>
4410<Airports>4 (1999 est.)</Airports>
4411</record>
4412<record>
4413<Location>Southern Asia, bordering the Arabian Sea, between India on the east and Iran and Afghanistan on the west and China in the north</Location>
4414<Geographiccoordinates>30 00 N, 70 00 E</Geographiccoordinates>
4415<Area>803940</Area>
4416<Climate>mostly hot, dry desert; temperate in northwest; arctic in north</Climate>
4417<Naturalresources>land, extensive natural gas reserves, limited petroleum, poor quality coal, iron ore, copper, salt, limestone</Naturalresources>
4418<Population>141553775</Population>
4419<Populationgrowthrate>2.17% (2000 est.)</Populationgrowthrate>
4420<Sexratio>
4421at birth: 1.05 male(s)/female
4422under 15 years: 1.06 male(s)/female
442315-64 years: 1.05 male(s)/female
442465 years and over: 0.97 male(s)/female
4425total population: 1.05 male(s)/female (2000 est.)</Sexratio>
4426<Religions>Muslim 97% (Sunni 77%, Shi'a 20%), Christian, Hindu, and other 3%</Religions>
4427<Countryname>Pakistan </Countryname>
4428<Capital>Islamabad</Capital>
4429<Flagdescription>green with a vertical white band (symbolizing the role of religious minorities) on the hoist side; a large white crescent and star are centered in the green field; the crescent, star, and color green are traditional symbols of Islam</Flagdescription>
4430<GDP>purchasing power parity - $282 billion (1999 est.)</GDP>
4431<Industries>textiles, food processing, beverages, construction materials, clothing, paper products, shrimp</Industries>
4432<Exports>$8.4 billion (f.o.b., 1999)</Exports>
4433<Imports>$9.8 billion (f.o.b., 1999)</Imports>
4434<Currency>1 Pakistani rupee (PRe) = 100 paisa</Currency>
4435<Airports>118 (1999 est.)</Airports>
4436<Illicitdrugs>producer of illicit opium and hashish for the international drug trade (poppy cultivation in 1999 - 1,570 hectares, a 48% drop from 1998 because of eradication and alternative development); key transit area for Southwest Asian heroin moving to Western markets; narcotics still move from Afghanistan into Balochistan Province</Illicitdrugs>
4437</record>
4438<record>
4439<Location>Central Europe, east of Germany</Location>
4440<Geographiccoordinates>52 00 N, 20 00 E</Geographiccoordinates>
4441<Area>312685</Area>
4442<Climate>temperate with cold, cloudy, moderately severe winters with frequent precipitation; mild summers with frequent showers and thundershowers</Climate>
4443<Naturalresources>coal, sulfur, copper, natural gas, silver, lead, salt, arable land</Naturalresources>
4444<Population>38646023</Population>
4445<Populationgrowthrate>-0.04% (2000 est.)</Populationgrowthrate>
4446<Sexratio>
4447at birth: 1.06 male(s)/female
4448under 15 years: 1.05 male(s)/female
444915-64 years: 0.99 male(s)/female
445065 years and over: 0.62 male(s)/female
4451total population: 0.95 male(s)/female (2000 est.)</Sexratio>
4452<Religions>Roman Catholic 95% (about 75% practicing), Eastern Orthodox, Protestant, and other 5%</Religions>
4453<Countryname>Poland </Countryname>
4454<Capital>Warsaw</Capital>
4455<Flagdescription>two equal horizontal bands of white (top) and red; similar to the flags of Indonesia and Monaco which are red (top) and white</Flagdescription>
4456<GDP>purchasing power parity - $276.5 billion (1999 est.)</GDP>
4457<Industries>machine building, iron and steel, coal mining, chemicals, shipbuilding, food processing, glass, beverages, textiles</Industries>
4458<Exports>$27.8 billion (f.o.b., 1999)</Exports>
4459<Imports>$40.8 billion (f.o.b., 1999)</Imports>
4460<Currency>1 zloty (Zl) = 100 groszy</Currency>
4461<Airports>123 (1999 est.)</Airports>
4462<Illicitdrugs>major illicit producer of amphetamines for the international market; minor transshipment point for Asian and Latin American illicit drugs to Western Europe</Illicitdrugs>
4463</record>
4464<record>
4465<Location>Middle America, bordering both the Caribbean Sea and the North Pacific Ocean, between Colombia and Costa Rica</Location>
4466<Geographiccoordinates>9 00 N, 80 00 W</Geographiccoordinates>
4467<Area>78200</Area>
4468<Climate>tropical maritime; hot, humid, cloudy; prolonged rainy season (May to January), short dry season (January to May)</Climate>
4469<Naturalresources>copper, mahogany forests, shrimp, hydropower</Naturalresources>
4470<Population>2808268</Population>
4471<Populationgrowthrate>1.34% (2000 est.)</Populationgrowthrate>
4472<Sexratio>
4473at birth: 1.04 male(s)/female
4474under 15 years: 1.04 male(s)/female
447515-64 years: 1.03 male(s)/female
447665 years and over: 0.92 male(s)/female
4477total population: 1.02 male(s)/female (2000 est.)</Sexratio>
4478<Religions>Roman Catholic 85%, Protestant 15%</Religions>
4479<Countryname>Panama </Countryname>
4480<Capital>Panama</Capital>
4481<Flagdescription>divided into four, equal rectangles; the top quadrants are white (hoist side) with a blue five-pointed star in the center and plain red; the bottom quadrants are plain blue (hoist side) and white with a red five-pointed star in the center</Flagdescription>
4482<GDP>purchasing power parity - $21 billion (1999 est.)</GDP>
4483<Industries>construction, petroleum refining, brewing, cement and other construction materials, sugar milling</Industries>
4484<Exports>$4.7 billion (f.o.b., 1999 est.)</Exports>
4485<Imports>$6.4 billion (f.o.b., 1999 est.)</Imports>
4486<Currency>1 balboa (B) = 100 centesimos</Currency>
4487<Airports>105 (1999 est.)</Airports>
4488<Illicitdrugs>major cocaine transshipment point and major drug-money-laundering center; no recent signs of coca cultivation; monitoring of financial transactions is improving, yet Panama has failed to prosecute anyone for money laundering - official corruption remains a major problem</Illicitdrugs>
4489</record>
4490<record>
4491<Location>Southwestern Europe, bordering the North Atlantic Ocean, west of Spain</Location>
4492<Geographiccoordinates>39 30 N, 8 00 W</Geographiccoordinates>
4493<Area>92391</Area>
4494<Climate>maritime temperate; cool and rainy in north, warmer and drier in south</Climate>
4495<Naturalresources>fish, forests (cork), tungsten, iron ore, uranium ore, marble, arable land, hydro power</Naturalresources>
4496<Population>10048232</Population>
4497<Populationgrowthrate>0.18% (2000 est.)</Populationgrowthrate>
4498<Sexratio>
4499at birth: 1.06 male(s)/female
4500under 15 years: 1.06 male(s)/female
450115-64 years: 0.96 male(s)/female
450265 years and over: 0.68 male(s)/female
4503total population: 0.92 male(s)/female (2000 est.)</Sexratio>
4504<Religions>Roman Catholic 94%, Protestant (1995)</Religions>
4505<Countryname>Portugal </Countryname>
4506<Capital>Lisbon</Capital>
4507<Flagdescription>two vertical bands of green (hoist side, two-fifths) and red (three-fifths) with the Portuguese coat of arms centered on the dividing line</Flagdescription>
4508<GDP>purchasing power parity - $151.4 billion (1999 est.)</GDP>
4509<Industries>textiles and footwear; wood pulp, paper, and cork; metalworking; oil refining; chemicals; fish canning; wine; tourism</Industries>
4510<Exports>$25 billion (f.o.b., 1998)</Exports>
4511<Imports>$34.9 billion (f.o.b., 1998)</Imports>
4512<Currency>1 Portuguese escudo (Esc) = 100 centavos</Currency>
4513<Airports>66 (1999 est.)</Airports>
4514<Illicitdrugs>important gateway country for Latin American cocaine entering the European market; transshipment point for hashish from North Africa to Europe; consumer of Southwest Asian heroin</Illicitdrugs>
4515</record>
4516<record>
4517<Location>Southeastern Asia, group of islands including the eastern half of the island of New Guinea between the Coral Sea and the South Pacific Ocean, east of Indonesia</Location>
4518<Geographiccoordinates>6 00 S, 147 00 E</Geographiccoordinates>
4519<Area>462840</Area>
4520<Climate>tropical; northwest monsoon (December to March), southeast monsoon (May to October); slight seasonal temperature variation</Climate>
4521<Naturalresources>gold, copper, silver, natural gas, timber, oil, fisheries</Naturalresources>
4522<Population>4926984</Population>
4523<Populationgrowthrate>2.47% (2000 est.)</Populationgrowthrate>
4524<Sexratio>
4525at birth: 1.05 male(s)/female
4526under 15 years: 1.03 male(s)/female
452715-64 years: 1.08 male(s)/female
452865 years and over: 0.9 male(s)/female
4529total population: 1.05 male(s)/female (2000 est.)</Sexratio>
4530<Religions>Roman Catholic 22%, Lutheran 16%, Presbyterian/Methodist/London Missionary Society 8%, Anglican 5%, Evangelical Alliance 4%, Seventh-Day Adventist 1%, other Protestant 10%, indigenous beliefs 34%</Religions>
4531<Countryname>Papua New Guinea </Countryname>
4532<Capital>Port Moresby</Capital>
4533<Flagdescription>divided diagonally from upper hoist-side corner; the upper triangle is red with a soaring yellow bird of paradise centered; the lower triangle is black with five white five-pointed stars of the Southern Cross constellation centered</Flagdescription>
4534<GDP>purchasing power parity - $11.6 billion (1999 est.)</GDP>
4535<Industries>copra crushing, palm oil processing, plywood production, wood chip production; mining of gold, silver, and copper; crude oil production; construction, tourism</Industries>
4536<Exports>$1.9 billion (f.o.b., 1999 est.)</Exports>
4537<Imports>$1 billion (f.o.b., 1999 est.)</Imports>
4538<Currency>1 kina (K) = 100 toea</Currency>
4539<Airports>492 (1999 est.)</Airports>
4540</record>
4541<record>
4542<Location>Oceania, group of islands in the North Pacific Ocean, southeast of the Philippines</Location>
4543<Geographiccoordinates>7 30 N, 134 30 E</Geographiccoordinates>
4544<Area>458</Area>
4545<Climate>wet season May to November; hot and humid</Climate>
4546<Naturalresources>forests, minerals (especially gold), marine products, deep-seabed minerals</Naturalresources>
4547<Population>18766</Population>
4548<Populationgrowthrate>1.75% (2000 est.)</Populationgrowthrate>
4549<Sexratio>
4550at birth: 1.06 male(s)/female
4551under 15 years: 1.06 male(s)/female
455215-64 years: 1.21 male(s)/female
455365 years and over: 0.89 male(s)/female
4554total population: 1.15 male(s)/female (2000 est.)</Sexratio>
4555<Religions>Christian (Catholics, Seventh-Day Adventists, Jehovah's Witnesses, the Assembly of God, the Liebenzell Mission, and Latter-Day Saints), Modekngei religion (one-third of the population observes this religion which is indigenous to Palau)</Religions>
4556<Countryname>Palau </Countryname>
4557<Capital>Koror
4558note: a new capital is being built about 20 km northeast of Koror</Capital>
4559<Flagdescription>light blue with a large yellow disk (representing the moon) shifted slightly to the hoist side</Flagdescription>
4560<GDP>purchasing power parity - $160 million (1997 est.)
4561note: GDP numbers reflect US spending</GDP>
4562<Industries>tourism, craft items (from shell, wood, pearls), construction, garment making</Industries>
4563<Exports>$14.3 million (f.o.b., 1996)</Exports>
4564<Imports>$72.4 million (f.o.b., 1996)</Imports>
4565<Currency>1 United States dollar (US$) = 100 cents</Currency>
4566<Airports>3 (1999 est.)</Airports>
4567</record>
4568<record>
4569<Location>Western Africa, bordering the North Atlantic Ocean, between Guinea and Senegal</Location>
4570<Geographiccoordinates>12 00 N, 15 00 W</Geographiccoordinates>
4571<Area>36120</Area>
4572<Climate>tropical; generally hot and humid; monsoonal-type rainy season (June to November) with southwesterly winds; dry season (December to May) with northeasterly harmattan winds</Climate>
4573<Naturalresources>fish, timber, phosphates, bauxite, unexploited deposits of petroleum</Naturalresources>
4574<Population>1285715</Population>
4575<Populationgrowthrate>2.4% (2000 est.)</Populationgrowthrate>
4576<Sexratio>
4577at birth: 1.03 male(s)/female
4578under 15 years: 1 male(s)/female
457915-64 years: 0.9 male(s)/female
458065 years and over: 0.83 male(s)/female
4581total population: 0.94 male(s)/female (2000 est.)</Sexratio>
4582<Religions>indigenous beliefs 50%, Muslim 45%, Christian 5%</Religions>
4583<Countryname>Guinea-Bissau </Countryname>
4584<Capital>Bissau</Capital>
4585<Flagdescription>two equal horizontal bands of yellow (top) and green with a vertical red band on the hoist side; there is a black five-pointed star centered in the red band; uses the popular pan-African colors of Ethiopia</Flagdescription>
4586<GDP>purchasing power parity - $1.1 billion (1999 est.)</GDP>
4587<Industries>agricultural products processing, beer, soft drinks</Industries>
4588<Exports>$26.8 million (f.o.b., 1998)</Exports>
4589<Imports>$22.9 million (f.o.b., 1998)</Imports>
4590<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
4591<Airports>30 (1999 est.)</Airports>
4592</record>
4593<record>
4594<Location>Middle East, peninsula bordering the Persian Gulf and Saudi Arabia</Location>
4595<Geographiccoordinates>25 30 N, 51 15 E</Geographiccoordinates>
4596<Area>11437</Area>
4597<Climate>desert; hot, dry; humid and sultry in summer</Climate>
4598<Naturalresources>petroleum, natural gas, fish</Naturalresources>
4599<Population>744483</Population>
4600<Populationgrowthrate>3.35% (2000 est.)</Populationgrowthrate>
4601<Sexratio>
4602at birth: 1.05 male(s)/female
4603under 15 years: 1.04 male(s)/female
460415-64 years: 2.48 male(s)/female
460565 years and over: 2.43 male(s)/female
4606total population: 1.93 male(s)/female (2000 est.)</Sexratio>
4607<Religions>Muslim 95%</Religions>
4608<Countryname>Qatar </Countryname>
4609<Capital>Doha</Capital>
4610<Flagdescription>maroon with a broad white serrated band (nine white points) on the hoist side</Flagdescription>
4611<GDP>purchasing power parity - $12.3 billion (1999 est.)</GDP>
4612<Industries>crude oil production and refining, fertilizers, petrochemicals, steel reinforcing bars, cement</Industries>
4613<Exports>$6.7 billion (f.o.b., 1999 est.)</Exports>
4614<Imports>$4.2 billion (f.o.b., 1999 est.)</Imports>
4615<Currency>1 Qatari riyal (QR) = 100 dirhams</Currency>
4616<Airports>4 (1999 est.)</Airports>
4617</record>
4618<record>
4619<Location>Southern Africa, island in the Indian Ocean, east of Madagascar</Location>
4620<Geographiccoordinates>21 06 S, 55 36 E</Geographiccoordinates>
4621<Area>2512</Area>
4622<Climate>tropical, but temperature moderates with elevation; cool and dry from May to November, hot and rainy from November to April</Climate>
4623<Naturalresources>fish, arable land, hydropower</Naturalresources>
4624<Population>720934</Population>
4625<Populationgrowthrate>1.63% (2000 est.)</Populationgrowthrate>
4626<Sexratio>
4627at birth: 1.05 male(s)/female
4628under 15 years: 1.05 male(s)/female
462915-64 years: 0.97 male(s)/female
463065 years and over: 0.68 male(s)/female
4631total population: 0.97 male(s)/female (2000 est.)</Sexratio>
4632<Religions>Roman Catholic 86%, Hindu, Muslim, Buddhist (1995)</Religions>
4633<Countryname>Reunion </Countryname>
4634<Capital>Saint-Denis</Capital>
4635<Flagdescription>the flag of France is used</Flagdescription>
4636<GDP>purchasing power parity - $3.4 billion (1998 est.)</GDP>
4637<Industries>sugar, rum, cigarettes, handicraft items, flower oil extraction</Industries>
4638<Exports>$214.162 million (f.o.b., 1997)</Exports>
4639<Imports>$2.5 billion (c.i.f., 1997)</Imports>
4640<Currency>1 French franc (F) = 100 centimes</Currency>
4641<Airports>2 (1999 est.)</Airports>
4642</record>
4643<record>
4644<Location>Oceania, group of atolls and reefs in the North Pacific Ocean, about one-half of the way from Hawaii to Papua New Guinea</Location>
4645<Geographiccoordinates>9 00 N, 168 00 E</Geographiccoordinates>
4646<Area>181</Area>
4647<Climate>wet season from May to November; hot and humid; islands border typhoon belt</Climate>
4648<Naturalresources>phosphate deposits, marine products, deep seabed minerals</Naturalresources>
4649<Population>68126</Population>
4650<Populationgrowthrate>3.88% (2000 est.)</Populationgrowthrate>
4651<Sexratio>
4652at birth: 1.05 male(s)/female
4653under 15 years: 1.04 male(s)/female
465415-64 years: 1.04 male(s)/female
465565 years and over: 0.9 male(s)/female
4656total population: 1.04 male(s)/female (2000 est.)</Sexratio>
4657<Religions>Christian (mostly Protestant)</Religions>
4658<Countryname>Marshall Islands </Countryname>
4659<Capital>Majuro</Capital>
4660<Flagdescription>blue with two stripes radiating from the lower hoist-side corner - orange (top) and white; there is a white star with four large rays and 20 small rays on the hoist side above the two stripes</Flagdescription>
4661<GDP>purchasing power parity - $105 million (1998 est.), supplemented by approximately $65 million annual US aid</GDP>
4662<Industries>copra, fish, tourism, craft items from shell, wood, and pearls, offshore banking (embryonic)</Industries>
4663<Exports>$28 million (f.o.b., 1997 est.)</Exports>
4664<Imports>$58 million (f.o.b., 1997 est.)</Imports>
4665<Currency>1 United States dollar (US$) = 100 cents</Currency>
4666<Airports>16 (1999 est.)</Airports>
4667</record>
4668<record>
4669<Location>Southeastern Europe, bordering the Black Sea, between Bulgaria and Ukraine</Location>
4670<Geographiccoordinates>46 00 N, 25 00 E</Geographiccoordinates>
4671<Area>237500</Area>
4672<Climate>temperate; cold, cloudy winters with frequent snow and fog; sunny summers with frequent showers and thunderstorms</Climate>
4673<Naturalresources>petroleum (reserves declining), timber, natural gas, coal, iron ore, salt, arable land, hydro power</Naturalresources>
4674<Population>22411121</Population>
4675<Populationgrowthrate>-0.21% (2000 est.)</Populationgrowthrate>
4676<Sexratio>
4677at birth: 1.05 male(s)/female
4678under 15 years: 1.05 male(s)/female
467915-64 years: 0.99 male(s)/female
468065 years and over: 0.71 male(s)/female
4681total population: 0.95 male(s)/female (2000 est.)</Sexratio>
4682<Religions>Romanian Orthodox 70%, Roman Catholic 6% (of which 3% are Uniate), Protestant 6%, unaffiliated 18%</Religions>
4683<Countryname>Romania </Countryname>
4684<Capital>Bucharest</Capital>
4685<Flagdescription>three equal vertical bands of blue (hoist side), yellow, and red; the national coat of arms that used to be centered in the yellow band has been removed; now similar to the flag of Chad, also resembles the flags of Andorra and Moldova</Flagdescription>
4686<GDP>purchasing power parity - $87.4 billion (1999 est.)</GDP>
4687<Industries>mining, timber, construction materials, metallurgy, chemicals, machine building, food processing, petroleum production and refining</Industries>
4688<Exports>$8.4 billion (f.o.b., 1999 est.)</Exports>
4689<Imports>$9.6 billion (f.o.b., 1999 est.)</Imports>
4690<Currency>1 leu (L) = 100 bani</Currency>
4691<Airports>62 (1999 est.)</Airports>
4692<Illicitdrugs>important transshipment point for Southwest Asian heroin transiting the Balkan route and small amounts of Latin American cocaine bound for Western Europe</Illicitdrugs>
4693</record>
4694<record>
4695<Location>Southeastern Asia, archipelago between the Philippine Sea and the South China Sea, east of Vietnam</Location>
4696<Geographiccoordinates>13 00 N, 122 00 E</Geographiccoordinates>
4697<Area>300000</Area>
4698<Climate>tropical marine; northeast monsoon (November to April); southwest monsoon (May to October)</Climate>
4699<Naturalresources>timber, petroleum, nickel, cobalt, silver, gold, salt, copper</Naturalresources>
4700<Population>81159644</Population>
4701<Populationgrowthrate>2.07% (2000 est.)</Populationgrowthrate>
4702<Sexratio>
4703at birth: 1.05 male(s)/female
4704under 15 years: 1.04 male(s)/female
470515-64 years: 0.98 male(s)/female
470665 years and over: 0.8 male(s)/female
4707total population: 0.99 male(s)/female (2000 est.)</Sexratio>
4708<Religions>Roman Catholic 83%, Protestant 9%, Muslim 5%, Buddhist and other 3%</Religions>
4709<Countryname>Philippines </Countryname>
4710<Capital>Manila</Capital>
4711<Flagdescription>two equal horizontal bands of blue (top) and red with a white equilateral triangle based on the hoist side; in the center of the triangle is a yellow sun with eight primary rays (each containing three individual rays) and in each corner of the triangle is a small yellow five-pointed star</Flagdescription>
4712<GDP>purchasing power parity - $282 billion (1999 est.)</GDP>
4713<Industries>textiles, pharmaceuticals, chemicals, wood products, food processing, electronics assembly, petroleum refining, fishing</Industries>
4714<Exports>$34.8 billion (f.o.b., 1999 est.)</Exports>
4715<Imports>$30.7 billion (f.o.b., 1999 est.)</Imports>
4716<Currency>1 Philippine peso (P) = 100 centavos</Currency>
4717<Airports>266 (1999 est.)</Airports>
4718<Illicitdrugs>exports locally produced marijuana and hashish to East Asia, the US, and other Western markets; serves as a transit point for heroin and crystal methamphetamine</Illicitdrugs>
4719</record>
4720<record>
4721<Location>Caribbean, island between the Caribbean Sea and the North Atlantic Ocean, east of the Dominican Republic</Location>
4722<Geographiccoordinates>18 15 N, 66 30 W</Geographiccoordinates>
4723<Area>9104</Area>
4724<Climate>tropical marine, mild; little seasonal temperature variation</Climate>
4725<Naturalresources>some copper and nickel; potential for onshore and offshore oil</Naturalresources>
4726<Population>3915798</Population>
4727<Populationgrowthrate>0.56% (2000 est.)</Populationgrowthrate>
4728<Sexratio>
4729at birth: 1.06 male(s)/female
4730under 15 years: 1.05 male(s)/female
473115-64 years: 0.92 male(s)/female
473265 years and over: 0.75 male(s)/female
4733total population: 0.93 male(s)/female (2000 est.)</Sexratio>
4734<Religions>Roman Catholic 85%, Protestant and other 15%</Religions>
4735<Countryname>Puerto Rico </Countryname>
4736<Capital>San Juan</Capital>
4737<Flagdescription>five equal horizontal bands of red (top and bottom) alternating with white; a blue isosceles triangle based on the hoist side bears a large, white, five-pointed star in the center; design based on the US flag</Flagdescription>
4738<GDP>purchasing power parity - $38.1 billion (1999 est.)</GDP>
4739<Industries>pharmaceuticals, electronics, apparel, food products; tourism</Industries>
4740<Exports>$34.9 billion (f.o.b., 1999)</Exports>
4741<Imports>$25.3 billion (c.i.f., 1999)</Imports>
4742<Currency>1 US dollar (US$) = 100 cents</Currency>
4743<Airports>30 (1999 est.)</Airports>
4744</record>
4745<record>
4746<Location>Northern Asia (that part west of the Urals is sometimes included with Europe), bordering the Arctic Ocean, between Europe and the North Pacific Ocean</Location>
4747<Geographiccoordinates>60 00 N, 100 00 E</Geographiccoordinates>
4748<Area>17075200</Area>
4749<Climate>ranges from steppes in the south through humid continental in much of European Russia; subarctic in Siberia to tundra climate in the polar north; winters vary from cool along Black Sea coast to frigid in Siberia; summers vary from warm in the steppes to cool along Arctic coast</Climate>
4750<Naturalresources>wide natural resource base including major deposits of oil, natural gas, coal, and many strategic minerals, timber
4751note: formidable obstacles of climate, terrain, and distance hinder exploitation of natural resources</Naturalresources>
4752<Population>146001176</Population>
4753<Populationgrowthrate>-0.38% (2000 est.)</Populationgrowthrate>
4754<Sexratio>
4755at birth: 1.05 male(s)/female
4756under 15 years: 1.04 male(s)/female
475715-64 years: 0.94 male(s)/female
475865 years and over: 0.46 male(s)/female
4759total population: 0.88 male(s)/female (2000 est.)</Sexratio>
4760<Religions>Russian Orthodox, Muslim, other</Religions>
4761<Countryname>Russia </Countryname>
4762<Capital>Moscow</Capital>
4763<Flagdescription>three equal horizontal bands of white (top), blue, and red</Flagdescription>
4764<GDP>purchasing power parity - $620.3 billion (1999 est.)</GDP>
4765<Industries>complete range of mining and extractive industries producing coal, oil, gas, chemicals, and metals; all forms of machine building from rolling mills to high-performance aircraft and space vehicles; shipbuilding; road and rail transportation equipment; communications equipment; agricultural machinery, tractors, and construction equipment; electric power generating and transmitting equipment; medical and scientific instruments; consumer durables, textiles, foodstuffs, handicrafts</Industries>
4766<Exports>$75.4 billion (1999 est.)</Exports>
4767<Imports>$48.2 billion (1999 est.)</Imports>
4768<Currency>1 ruble (R) = 100 kopeks</Currency>
4769<Airports>2,517 (1994 est.)</Airports>
4770<Illicitdrugs>limited cultivation of illicit cannabis and opium poppy and producer of amphetamines, mostly for domestic consumption; government has active eradication program; increasingly used as transshipment point for Southwest and Southeast Asian opiates and cannabis and Latin American cocaine to Western Europe, possibly to the US, and growing domestic market; major source of heroin precursor chemicals</Illicitdrugs>
4771</record>
4772<record>
4773<Location>Central Africa, east of Democratic Republic of the Congo</Location>
4774<Geographiccoordinates>2 00 S, 30 00 E</Geographiccoordinates>
4775<Area>26338</Area>
4776<Climate>temperate; two rainy seasons (February to April, November to January); mild in mountains with frost and snow possible</Climate>
4777<Naturalresources>gold, cassiterite (tin ore), wolframite (tungsten ore), methane, hydropower, arable land</Naturalresources>
4778<Population>7229129</Population>
4779<Populationgrowthrate>1.14% (2000 est.)</Populationgrowthrate>
4780<Sexratio>
4781at birth: 1.03 male(s)/female
4782under 15 years: 1.01 male(s)/female
478315-64 years: 0.99 male(s)/female
478465 years and over: 0.68 male(s)/female
4785total population: 0.98 male(s)/female (2000 est.)</Sexratio>
4786<Religions>Roman Catholic 65%, Protestant 9%, Muslim 1%, indigenous beliefs and other 25%</Religions>
4787<Countryname>Rwanda </Countryname>
4788<Capital>Kigali</Capital>
4789<Flagdescription>three equal vertical bands of red (hoist side), yellow, and green with a large black letter R centered in the yellow band; uses the popular pan-African colors of Ethiopia; similar to the flag of Guinea, which has a plain yellow band</Flagdescription>
4790<GDP>purchasing power parity - $5.9 billion (1999 est.)</GDP>
4791<Industries>cement, agricultural products, small-scale beverages, soap, furniture, shoes, plastic goods, textiles, cigarettes</Industries>
4792<Exports>$70.8 million (f.o.b., 1999 est.)</Exports>
4793<Imports>$242 million (f.o.b., 1999 est.)</Imports>
4794<Currency>1 Rwandan franc (RF) = 100 centimes</Currency>
4795<Airports>8 (1999 est.)</Airports>
4796</record>
4797<record>
4798<Location>Middle East, bordering the Persian Gulf and the Red Sea, north of Yemen</Location>
4799<Geographiccoordinates>25 00 N, 45 00 E</Geographiccoordinates>
4800<Area>1960582</Area>
4801<Climate>harsh, dry desert with great extremes of temperature</Climate>
4802<Naturalresources>petroleum, natural gas, iron ore, gold, copper</Naturalresources>
4803<Population>22023506</Population>
4804<Populationgrowthrate>3.28% (2000 est.)</Populationgrowthrate>
4805<Sexratio>
4806at birth: 1.05 male(s)/female
4807under 15 years: 1.04 male(s)/female
480815-64 years: 1.43 male(s)/female
480965 years and over: 1.18 male(s)/female
4810total population: 1.24 male(s)/female (2000 est.)</Sexratio>
4811<Religions>Muslim 100%</Religions>
4812<Countryname>Saudi Arabia </Countryname>
4813<Capital>Riyadh</Capital>
4814<Flagdescription>green with large white Arabic script (that may be translated as There is no God but God; Muhammad is the Messenger of God) above a white horizontal saber (the tip points to the hoist side); green is the traditional color of Islam</Flagdescription>
4815<GDP>purchasing power parity - $191 billion (1999 est.)</GDP>
4816<Industries>crude oil production, petroleum refining, basic petrochemicals, cement, construction, fertilizer, plastics</Industries>
4817<Exports>$48 billion (f.o.b., 1999)</Exports>
4818<Imports>$28 billion (f.o.b., 1999)</Imports>
4819<Currency>1 Saudi riyal (SR) = 100 halalah</Currency>
4820<Airports>205 (1999 est.)</Airports>
4821<Illicitdrugs>death penalty for traffickers; increasing consumption of heroin and cocaine</Illicitdrugs>
4822</record>
4823<record>
4824<Location>Northern North America, islands in the North Atlantic Ocean, south of Newfoundland (Canada)</Location>
4825<Geographiccoordinates>46 50 N, 56 20 W</Geographiccoordinates>
4826<Area>242</Area>
4827<Climate>cold and wet, with much mist and fog; spring and autumn are windy</Climate>
4828<Naturalresources>fish, deepwater ports</Naturalresources>
4829<Population>6896</Population>
4830<Populationgrowthrate>0.49% (2000 est.)</Populationgrowthrate>
4831<Sexratio>
4832at birth: 1.04 male(s)/female
4833under 15 years: 1.05 male(s)/female
483415-64 years: 1.04 male(s)/female
483565 years and over: 0.73 male(s)/female
4836total population: 1.01 male(s)/female (2000 est.)</Sexratio>
4837<Religions>Roman Catholic 99%</Religions>
4838<Countryname>Saint Pierre and Miquelon </Countryname>
4839<Capital>Saint-Pierre</Capital>
4840<Flagdescription>a yellow sailing ship facing the hoist side rides on a dark blue background with a black wave line under the ship; on the hoist side, a vertical band is divided into three parts: the top part is red with a green diagonal cross extending to the corners overlaid by a white cross dividing the square into four sections; the middle part has a white background with an ermine pattern; the third part has a red background with two stylized yellow lions outlined in black, one on top of the other; the flag of France is used for official occasions</Flagdescription>
4841<GDP>purchasing power parity - $74 million (1996 est.); supplemented by annual payments from France of about $65 million</GDP>
4842<Industries>fish processing and supply base for fishing fleets; tourism</Industries>
4843<Exports>$5 million (f.o.b., 1997)</Exports>
4844<Imports>$66 million (c.i.f., 1997 est.)</Imports>
4845<Currency>1 French franc (F) = 100 centimes</Currency>
4846<Airports>2 (1999 est.)</Airports>
4847</record>
4848<record>
4849<Location>Caribbean, islands in the Caribbean Sea, about one-third of the way from Puerto Rico to Trinidad and Tobago</Location>
4850<Geographiccoordinates>17 20 N, 62 45 W</Geographiccoordinates>
4851<Area>261</Area>
4852<Climate>tropical tempered by constant sea breezes; little seasonal temperature variation; rainy season (May to November)</Climate>
4853<Naturalresources>arable land</Naturalresources>
4854<Population>38819</Population>
4855<Populationgrowthrate>-0.22% (2000 est.)</Populationgrowthrate>
4856<Sexratio>
4857at birth: 1.06 male(s)/female
4858under 15 years: 1.04 male(s)/female
485915-64 years: 0.99 male(s)/female
486065 years and over: 0.7 male(s)/female
4861total population: 0.98 male(s)/female (2000 est.)</Sexratio>
4862<Religions>Anglican, other Protestant, Roman Catholic</Religions>
4863<Countryname>Saint Kitts and Nevis </Countryname>
4864<Capital>Basseterre</Capital>
4865<Flagdescription>divided diagonally from the lower hoist side by a broad black band bearing two white, five-pointed stars; the black band is edged in yellow; the upper triangle is green, the lower triangle is red</Flagdescription>
4866<GDP>purchasing power parity - $244 million (1998 est.)</GDP>
4867<Industries>sugar processing, tourism, cotton, salt, copra, clothing, footwear, beverages</Industries>
4868<Exports>$42 million (1998)</Exports>
4869<Imports>$160 million (1998)</Imports>
4870<Currency>1 East Caribbean dollar (EC$) = 100 cents</Currency>
4871<Airports>2 (1999 est.)</Airports>
4872<Illicitdrugs>transshipment point for South American drugs destined for the US and Europe</Illicitdrugs>
4873</record>
4874<record>
4875<Location>Eastern Africa, group of islands in the Indian Ocean, northeast of Madagascar</Location>
4876<Geographiccoordinates>4 35 S, 55 40 E</Geographiccoordinates>
4877<Area>455</Area>
4878<Climate>tropical marine; humid; cooler season during southeast monsoon (late May to September); warmer season during northwest monsoon (March to May)</Climate>
4879<Naturalresources>fish, copra, cinnamon trees</Naturalresources>
4880<Population>79326</Population>
4881<Populationgrowthrate>0.49% (2000 est.)</Populationgrowthrate>
4882<Sexratio>
4883at birth: 1.03 male(s)/female
4884under 15 years: 1.01 male(s)/female
488515-64 years: 0.95 male(s)/female
488665 years and over: 0.51 male(s)/female
4887total population: 0.93 male(s)/female (2000 est.)</Sexratio>
4888<Religions>Roman Catholic 90%, Anglican 8%, other 2%</Religions>
4889<Countryname>Seychelles </Countryname>
4890<Capital>Victoria</Capital>
4891<Flagdescription>five oblique bands of blue (hoist side), yellow, red, white, and green (bottom) radiating from the bottom of the hoist side</Flagdescription>
4892<GDP>purchasing power parity - $590 million (1999 est.)</GDP>
4893<Industries>fishing; tourism; processing of coconuts and vanilla, coir (coconut fiber) rope, boat building, printing, furniture; beverages</Industries>
4894<Exports>$91 million (f.o.b., 1998)</Exports>
4895<Imports>$403 million (c.i.f., 1998)</Imports>
4896<Currency>1 Seychelles rupee (SRe) = 100 cents</Currency>
4897<Airports>14 (1999 est.)</Airports>
4898</record>
4899<record>
4900<Location>Southern Africa, at the southern tip of the continent of Africa</Location>
4901<Geographiccoordinates>29 00 S, 24 00 E</Geographiccoordinates>
4902<Area>1219912</Area>
4903<Climate>mostly semiarid; subtropical along east coast; sunny days, cool nights</Climate>
4904<Naturalresources>gold, chromium, antimony, coal, iron ore, manganese, nickel, phosphates, tin, uranium, gem diamonds, platinum, copper, vanadium, salt, natural gas</Naturalresources>
4905<Population>43421021</Population>
4906<Populationgrowthrate>0.5% (2000 est.)</Populationgrowthrate>
4907<Sexratio>
4908at birth: 1.02 male(s)/female
4909under 15 years: 1.01 male(s)/female
491015-64 years: 0.93 male(s)/female
491165 years and over: 0.61 male(s)/female
4912total population: 0.94 male(s)/female (2000 est.)</Sexratio>
4913<Religions>Christian 68% (includes most whites and Coloreds, about 60% of blacks and about 40% of Indians), Muslim 2%, Hindu 1.5% (60% of Indians), indigenous beliefs and animist 28.5%</Religions>
4914<Countryname>South Africa </Countryname>
4915<Capital>Pretoria; note - Cape Town is the legislative center and Bloemfontein the judicial center</Capital>
4916<Flagdescription>two equal width horizontal bands of red (top) and blue separated by a central green band which splits into a horizontal Y, the arms of which end at the corners of the hoist side; the Y embraces a black isosceles triangle from which the arms are separated by narrow yellow bands; the red and blue bands are separated from the green band and its arms by narrow white stripes
4917note: prior to 26 April 1994, the flag was actually four flags in one - three miniature flags reproduced in the center of the white band of the former flag of the Netherlands, which has three equal horizontal bands of orange (top), white, and blue; the miniature flags are a vertically hanging flag of the old Orange Free State with a horizontal flag of the UK adjoining on the hoist side and a horizontal flag of the old Transvaal Republic adjoining on the other side</Flagdescription>
4918<GDP>purchasing power parity - $296.1 billion (1999 est.)</GDP>
4919<Industries>mining (world's largest producer of platinum, gold, chromium), automobile assembly, metalworking, machinery, textile, iron and steel, chemicals, fertilizer, foodstuffs</Industries>
4920<Exports>$28 billion (f.o.b., 1999 est.)</Exports>
4921<Imports>$26 billion (f.o.b., 1999 est.)</Imports>
4922<Currency>1 rand (R) = 100 cents</Currency>
4923<Airports>744 (1999 est.)</Airports>
4924<Illicitdrugs>transshipment center for heroin and cocaine; cocaine consumption on the rise; world's largest market for illicit methaqualone, usually imported illegally from India through various east African countries; illicit cultivation of marijuana</Illicitdrugs>
4925</record>
4926<record>
4927<Location>Western Africa, bordering the North Atlantic Ocean, between Guinea-Bissau and Mauritania</Location>
4928<Geographiccoordinates>14 00 N, 14 00 W</Geographiccoordinates>
4929<Area>196190</Area>
4930<Climate>tropical; hot, humid; rainy season (May to November) has strong southeast winds; dry season (December to April) dominated by hot, dry, harmattan wind</Climate>
4931<Naturalresources>fish, phosphates, iron ore</Naturalresources>
4932<Population>9987494</Population>
4933<Populationgrowthrate>2.94% (2000 est.)</Populationgrowthrate>
4934<Sexratio>
4935at birth: 1.03 male(s)/female
4936under 15 years: 1.01 male(s)/female
493715-64 years: 0.92 male(s)/female
493865 years and over: 1 male(s)/female
4939total population: 0.96 male(s)/female (2000 est.)</Sexratio>
4940<Religions>Muslim 92%, indigenous beliefs 6%, Christian 2% (mostly Roman Catholic)</Religions>
4941<Countryname>Senegal </Countryname>
4942<Capital>Dakar</Capital>
4943<Flagdescription>three equal vertical bands of green (hoist side), yellow, and red with a small green five-pointed star centered in the yellow band; uses the popular pan-African colors of Ethiopia</Flagdescription>
4944<GDP>purchasing power parity - $16.6 billion (1999 est.)</GDP>
4945<Industries>agricultural and fish processing, phosphate mining, fertilizer production, petroleum refining, construction materials</Industries>
4946<Exports>$925 million (f.o.b., 1998)</Exports>
4947<Imports>$1.2 billion (f.o.b., 1998)</Imports>
4948<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
4949<Airports>20 (1999 est.)</Airports>
4950<Illicitdrugs>transshipment point for Southwest and Southeast Asian heroin moving to Europe and North America; illicit cultivator of cannabis</Illicitdrugs>
4951</record>
4952<record>
4953<Location>islands in the South Atlantic Ocean, about mid-way between South America and Africa</Location>
4954<Geographiccoordinates>15 56 S, 5 42 W</Geographiccoordinates>
4955<Area>410</Area>
4956<Climate>Saint Helena - tropical; marine; mild, tempered by trade winds; Tristan da Cunha - temperate; marine, mild, tempered by trade winds (tends to be cooler than Saint Helena)</Climate>
4957<Naturalresources>fish</Naturalresources>
4958<Population>7212</Population>
4959<Populationgrowthrate>0.76% (2000 est.)</Populationgrowthrate>
4960<Sexratio>
4961at birth: 1.06 male(s)/female
4962under 15 years: 1.02 male(s)/female
496315-64 years: 1.09 male(s)/female
496465 years and over: 0.72 male(s)/female
4965total population: 1.04 male(s)/female (2000 est.)</Sexratio>
4966<Religions>Anglican (majority), Baptist, Seventh-Day Adventist, Roman Catholic</Religions>
4967<Countryname>Saint Helena </Countryname>
4968<Capital>Jamestown</Capital>
4969<Flagdescription>blue with the flag of the UK in the upper hoist-side quadrant and the Saint Helenian shield centered on the outer half of the flag; the shield features a rocky coastline and three-masted sailing ship</Flagdescription>
4970<GDP>purchasing power parity - $13.9 million (FY94/95 est.)</GDP>
4971<Industries>construction, crafts (furniture, lacework, fancy woodwork), fishing</Industries>
4972<Exports>$704,000 (f.o.b., 1995)</Exports>
4973<Imports>$14.434 million (c.i.f., 1995)</Imports>
4974<Currency>1 Saint Helenian pound = 100 pence</Currency>
4975<Airports>1 (1999 est.)</Airports>
4976</record>
4977<record>
4978<Location>Southeastern Europe, eastern Alps bordering the Adriatic Sea, between Austria and Croatia</Location>
4979<Geographiccoordinates>46 00 N, 15 00 E</Geographiccoordinates>
4980<Area>20253</Area>
4981<Climate>Mediterranean climate on the coast, continental climate with mild to hot summers and cold winters in the plateaus and valleys to the east</Climate>
4982<Naturalresources>lignite coal, lead, zinc, mercury, uranium, silver, hydropower</Naturalresources>
4983<Population>1927593</Population>
4984<Populationgrowthrate>0.12% (2000 est.)</Populationgrowthrate>
4985<Sexratio>
4986at birth: 1.06 male(s)/female
4987under 15 years: 1.05 male(s)/female
498815-64 years: 1.03 male(s)/female
498965 years and over: 0.57 male(s)/female
4990total population: 0.95 male(s)/female (2000 est.)</Sexratio>
4991<Religions>Roman Catholic 70.8% (including Uniate 2%), Lutheran 1%, Muslim 1%, atheist 4.3%, other 22.9%</Religions>
4992<Countryname>Slovenia </Countryname>
4993<Capital>Ljubljana</Capital>
4994<Flagdescription>three equal horizontal bands of white (top), blue, and red, with the Slovenian seal (a shield with the image of Triglav, Slovenia's highest peak, in white against a blue background at the center; beneath it are two wavy blue lines depicting seas and rivers, and above it are three six-pointed stars arranged in an inverted triangle which are taken from the coat of arms of the Counts of Celje, the great Slovene dynastic house of the late 14th and early 15th centuries); the seal is located in the upper hoist side of the flag centered in the white and blue bands</Flagdescription>
4995<GDP>purchasing power parity - $21.4 billion (1999 est.)</GDP>
4996<Industries>ferrous metallurgy and rolling mill products, aluminum reduction and rolled products, lead and zinc smelting, electronics (including military electronics), trucks, electric power equipment, wood products, textiles, chemicals, machine tools</Industries>
4997<Exports>$8.4 billion (f.o.b., 1999)</Exports>
4998<Imports>$9.7 billion (f.o.b., 1999)</Imports>
4999<Currency>1 tolar (SlT) = 100 stotins</Currency>
5000<Airports>14 (1999 est.)</Airports>
5001<Illicitdrugs>minor transit point for Southwest Asian heroin bound for Western Europe, and for precursor chemicals</Illicitdrugs>
5002</record>
5003<record>
5004<Location>Western Africa, bordering the North Atlantic Ocean, between Guinea and Liberia</Location>
5005<Geographiccoordinates>8 30 N, 11 30 W</Geographiccoordinates>
5006<Area>71740</Area>
5007<Climate>tropical; hot, humid; summer rainy season (May to December); winter dry season (December to April)</Climate>
5008<Naturalresources>diamonds, titanium ore, bauxite, iron ore, gold, chromite</Naturalresources>
5009<Population>5232624</Population>
5010<Populationgrowthrate>3.67% (2000 est.)</Populationgrowthrate>
5011<Sexratio>
5012at birth: 1.03 male(s)/female
5013under 15 years: 0.96 male(s)/female
501415-64 years: 0.92 male(s)/female
501565 years and over: 1 male(s)/female
5016total population: 0.94 male(s)/female (2000 est.)</Sexratio>
5017<Religions>Muslim 60%, indigenous beliefs 30%, Christian 10%</Religions>
5018<Countryname>Sierra Leone </Countryname>
5019<Capital>Freetown</Capital>
5020<Flagdescription>three equal horizontal bands of light green (top), white, and light blue</Flagdescription>
5021<GDP>purchasing power parity - $2.5 billion (1999 est.)</GDP>
5022<Industries>mining (diamonds); small-scale manufacturing (beverages, textiles, cigarettes, footwear); petroleum refining</Industries>
5023<Exports>$41 million (f.o.b., 1998)</Exports>
5024<Imports>$166 million (f.o.b., 1998)</Imports>
5025<Currency>1 leone (Le) = 100 cents</Currency>
5026<Airports>10 (1999 est.)</Airports>
5027</record>
5028<record>
5029<Location>Southern Europe, an enclave in central Italy</Location>
5030<Geographiccoordinates>43 46 N, 12 25 E</Geographiccoordinates>
5031<Area>60</Area>
5032<Climate>Mediterranean; mild to cool winters; warm, sunny summers</Climate>
5033<Naturalresources>building stone</Naturalresources>
5034<Population>26937</Population>
5035<Populationgrowthrate>1.49% (2000 est.)</Populationgrowthrate>
5036<Sexratio>
5037at birth: 1 male(s)/female
5038under 15 years: 1.07 male(s)/female
503915-64 years: 0.95 male(s)/female
504065 years and over: 0.75 male(s)/female
5041total population: 0.94 male(s)/female (2000 est.)</Sexratio>
5042<Religions>Roman Catholic</Religions>
5043<Countryname>San Marino </Countryname>
5044<Capital>San Marino</Capital>
5045<Flagdescription>two equal horizontal bands of white (top) and light blue with the national coat of arms superimposed in the center; the coat of arms has a shield (featuring three towers on three peaks) flanked by a wreath, below a crown and above a scroll bearing the word LIBERTAS (Liberty)</Flagdescription>
5046<GDP>purchasing power parity - $500 million (1997 est.)</GDP>
5047<Industries>tourism, banking, textiles, electronics, ceramics, cement, wine</Industries>
5048<Exports>trade data are included with the statistics for Italy</Exports>
5049<Imports>trade data are included with the statistics for Italy</Imports>
5050<Currency>1 Italian lira (Lit) = 100 centesimi; note - also mints its own coins</Currency>
5051<Airports>none</Airports>
5052</record>
5053<record>
5054<Location>Southeastern Asia, islands between Malaysia and Indonesia</Location>
5055<Geographiccoordinates>1 22 N, 103 48 E</Geographiccoordinates>
5056<Area>647</Area>
5057<Climate>tropical; hot, humid, rainy; no pronounced rainy or dry seasons; thunderstorms occur on 40% of all days (67% of days in April)</Climate>
5058<Naturalresources>fish, deepwater ports</Naturalresources>
5059<Population>4151264</Population>
5060<Populationgrowthrate>3.54% (2000 est.)</Populationgrowthrate>
5061<Sexratio>
5062at birth: 1.08 male(s)/female
5063under 15 years: 1.07 male(s)/female
506415-64 years: 0.96 male(s)/female
506565 years and over: 0.78 male(s)/female
5066total population: 0.96 male(s)/female (2000 est.)</Sexratio>
5067<Religions>Buddhist (Chinese), Muslim (Malays), Christian, Hindu, Sikh, Taoist, Confucianist</Religions>
5068<Countryname>Singapore </Countryname>
5069<Capital>Singapore</Capital>
5070<Flagdescription>two equal horizontal bands of red (top) and white; near the hoist side of the red band, there is a vertical, white crescent (closed portion is toward the hoist side) partially enclosing five white five-pointed stars arranged in a circle</Flagdescription>
5071<GDP>purchasing power parity - $98 billion (1999 est.)</GDP>
5072<Industries>electronics, financial services, oil drilling equipment, petroleum refining, rubber processing and rubber products, processed food and beverages, ship repair, entrepot trade, biotechnology</Industries>
5073<Exports>$114 billion (1999)</Exports>
5074<Imports>$111 billion (1999)</Imports>
5075<Currency>1 Singapore dollar (S$) = 100 cents</Currency>
5076<Airports>9 (1999 est.)</Airports>
5077<Illicitdrugs>transit point for Golden Triangle heroin going to North America, Western Europe, and the Third World; also a money-laundering center</Illicitdrugs>
5078</record>
5079<record>
5080<Location>Eastern Africa, bordering the Gulf of Aden and the Indian Ocean, east of Ethiopia</Location>
5081<Geographiccoordinates>10 00 N, 49 00 E</Geographiccoordinates>
5082<Area>637657</Area>
5083<Climate>principally desert; December to February - northeast monsoon, moderate temperatures in north and very hot in south; May to October - southwest monsoon, torrid in the north and hot in the south, irregular rainfall, hot and humid periods (tangambili) between monsoons</Climate>
5084<Naturalresources>uranium and largely unexploited reserves of iron ore, tin, gypsum, bauxite, copper, salt</Naturalresources>
5085<Population>7253137</Population>
5086<Populationgrowthrate>2.9% (2000 est.)</Populationgrowthrate>
5087<Sexratio>
5088at birth: 1.03 male(s)/female
5089under 15 years: 1 male(s)/female
509015-64 years: 1.02 male(s)/female
509165 years and over: 0.81 male(s)/female
5092total population: 1.01 male(s)/female (2000 est.)</Sexratio>
5093<Religions>Sunni Muslim</Religions>
5094<Countryname>Somalia </Countryname>
5095<Capital>Mogadishu</Capital>
5096<Flagdescription>light blue with a large white five-pointed star in the center; design based on the flag of the UN (Italian Somaliland was a UN trust territory)</Flagdescription>
5097<GDP>purchasing power parity - $4.3 billion (1999 est.)</GDP>
5098<Industries>a few small industries, including sugar refining, textiles, petroleum refining (mostly shut down)</Industries>
5099<Exports>$187 million (f.o.b., 1998 est.)</Exports>
5100<Imports>$327 million (f.o.b., 1998 est.)</Imports>
5101<Currency>1 Somali shilling (So. Sh.) = 100 cents</Currency>
5102<Airports>61 (1999 est.)</Airports>
5103</record>
5104<record>
5105<Location>Southwestern Europe, bordering the Bay of Biscay, Mediterranean Sea, North Atlantic Ocean, and Pyrenees Mountains, southwest of France</Location>
5106<Geographiccoordinates>40 00 N, 4 00 W</Geographiccoordinates>
5107<Area>504782</Area>
5108<Climate>temperate; clear, hot summers in interior, more moderate and cloudy along coast; cloudy, cold winters in interior, partly cloudy and cool along coast</Climate>
5109<Naturalresources>coal, lignite, iron ore, uranium, mercury, pyrites, fluorspar, gypsum, zinc, lead, tungsten, copper, kaolin, potash, hydropower, arable land</Naturalresources>
5110<Population>39996671</Population>
5111<Populationgrowthrate>0.11% (2000 est.)</Populationgrowthrate>
5112<Sexratio>
5113at birth: 1.07 male(s)/female
5114under 15 years: 1.06 male(s)/female
511515-64 years: 1.01 male(s)/female
511665 years and over: 0.72 male(s)/female
5117total population: 0.96 male(s)/female (2000 est.)</Sexratio>
5118<Religions>Roman Catholic 99%, other 1%</Religions>
5119<Countryname>Spain </Countryname>
5120<Capital>Madrid</Capital>
5121<Flagdescription>three horizontal bands of red (top), yellow (double width), and red with the national coat of arms on the hoist side of the yellow band; the coat of arms includes the royal seal framed by the Pillars of Hercules, which are the two promontories (Gibraltar and Ceuta) on either side of the eastern end of the Strait of Gibraltar</Flagdescription>
5122<GDP>purchasing power parity - $677.5 billion (1999 est.)</GDP>
5123<Industries>textiles and apparel (including footwear), food and beverages, metals and metal manufactures, chemicals, shipbuilding, automobiles, machine tools, tourism</Industries>
5124<Exports>$112.3 billion (f.o.b., 1999 est.)</Exports>
5125<Imports>$137.5 billion (f.o.b., 1999 est.)</Imports>
5126<Currency>1 peseta (Pta) = 100 centimos</Currency>
5127<Airports>105 (1999 est.)</Airports>
5128<Illicitdrugs>key European gateway country for Latin American cocaine and North African hashish entering the European market; transshipment point for and consumer of Southwest Asian heroin</Illicitdrugs>
5129</record>
5130<record>
5131<Location>Southeastern Europe, bordering the Adriatic Sea, between Albania and Bosnia and Herzegovina</Location>
5132<Geographiccoordinates>44 00 N, 21 00 E</Geographiccoordinates>
5133<Area>102350</Area>
5134<Climate>in the north, continental climate (cold winters and hot, humid summers with well distributed rainfall); central portion, continental and Mediterranean climate; to the south, Adriatic climate along the coast, hot, dry summers and autumns and relatively cold winters with heavy snowfall inland</Climate>
5135<Naturalresources>oil, gas, coal, antimony, copper, lead, zinc, nickel, gold, pyrite, chrome, hydro power</Naturalresources>
5136<Population>10662087</Population>
5137<Populationgrowthrate>Serbia - 0.739%; Montenegro - -12.22% (2000 est.)</Populationgrowthrate>
5138<Sexratio>
5139at birth: Serbia - 1.08 male(s)/female; Montenegro - 1.09 male(s)/female
5140under 15 years: Serbia - 1.07 male(s)/female; Montenegro - 1.07 male(s)/female
514115-64 years: Serbia - 0.96 male(s)/female; Montenegro - 0.97 male(s)/female
514265 years and over: Serbia - 0.76 male(s)/female; Montenegro - 0.68 male(s)/female
5143total population: Serbia - 0.95 male(s)/female; Montenegro - 0.95 male(s)/female (2000 est.)</Sexratio>
5144<Religions>Orthodox 65%, Muslim 19%, Roman Catholic 4%, Protestant 1%, other 11%</Religions>
5145<Countryname>Serbia and Montenegro </Countryname>
5146<Capital>Belgrade (Serbia), Podgorica (Montenegro)</Capital>
5147<GDP>purchasing power parity - $20.6 billion (1999 est.)</GDP>
5148<Industries>machine building (aircraft, trucks, and automobiles; tanks and weapons; electrical equipment; agricultural machinery); metallurgy (steel, aluminum, copper, lead, zinc, chromium, antimony, bismuth, cadmium); mining (coal, bauxite, nonferrous ore, iron ore, limestone); consumer goods (textiles, footwear, foodstuffs, appliances); electronics, petroleum products, chemicals, and pharmaceuticals</Industries>
5149<Exports>$1.5 billion (1999)</Exports>
5150<Imports>$3.3 billion (1999)</Imports>
5151<Currency>1 Yugoslav New Dinar (YD) = 100 paras; Montenegro made the German deutsche mark (1 deutsche mark (DM) = 100 pfennige) legal tender alongside the Yugoslav dinar (1999)</Currency>
5152<Airports>48 (Serbia 43, Montenegro 5) (1999 est.)</Airports>
5153<Illicitdrugs>transshipment point for Southwest Asian heroin moving to Western Europe on the Balkan route</Illicitdrugs>
5154</record>
5155<record>
5156<Location>Caribbean, island between the Caribbean Sea and North Atlantic Ocean, north of Trinidad and Tobago</Location>
5157<Geographiccoordinates>13 53 N, 60 68 W</Geographiccoordinates>
5158<Area>620</Area>
5159<Climate>tropical, moderated by northeast trade winds; dry season from January to April, rainy season from May to August</Climate>
5160<Naturalresources>forests, sandy beaches, minerals (pumice), mineral springs, geothermal potential</Naturalresources>
5161<Population>156260</Population>
5162<Populationgrowthrate>1.21% (2000 est.)</Populationgrowthrate>
5163<Sexratio>
5164at birth: 1.07 male(s)/female
5165under 15 years: 1.04 male(s)/female
516615-64 years: 0.96 male(s)/female
516765 years and over: 0.6 male(s)/female
5168total population: 0.96 male(s)/female (2000 est.)</Sexratio>
5169<Religions>Roman Catholic 90%, Protestant 7%, Anglican 3%</Religions>
5170<Countryname>Saint Lucia </Countryname>
5171<Capital>Castries</Capital>
5172<Flagdescription>blue, with a gold isosceles triangle below a black arrowhead; the upper edges of the arrowhead have a white border</Flagdescription>
5173<GDP>purchasing power parity - $656 million (1998 est.)</GDP>
5174<Industries>clothing, assembly of electronic components, beverages, corrugated cardboard boxes, tourism, lime processing, coconut processing</Industries>
5175<Exports>$75 million (1998)</Exports>
5176<Imports>$290 million (1998)</Imports>
5177<Currency>1 East Caribbean dollar (EC$) = 100 cents</Currency>
5178<Airports>2 (1999 est.)</Airports>
5179<Illicitdrugs>transit point for South American drugs destined for the US and Europe</Illicitdrugs>
5180</record>
5181<record>
5182<Location>Northern Africa, bordering the Red Sea, between Egypt and Eritrea</Location>
5183<Geographiccoordinates>15 00 N, 30 00 E</Geographiccoordinates>
5184<Area>2505810</Area>
5185<Climate>tropical in south; arid desert in north; rainy season (April to October)</Climate>
5186<Naturalresources>petroleum; small reserves of iron ore, copper, chromium ore, zinc, tungsten, mica, silver, gold, hydropower</Naturalresources>
5187<Population>35079814</Population>
5188<Populationgrowthrate>2.84% (2000 est.)</Populationgrowthrate>
5189<Sexratio>
5190at birth: 1.05 male(s)/female
5191under 15 years: 1.05 male(s)/female
519215-64 years: 1 male(s)/female
519365 years and over: 1.33 male(s)/female
5194total population: 1.03 male(s)/female (2000 est.)</Sexratio>
5195<Religions>Sunni Muslim 70% (in north), indigenous beliefs 25%, Christian 5% (mostly in south and Khartoum)</Religions>
5196<Countryname>Sudan </Countryname>
5197<Capital>Khartoum</Capital>
5198<Flagdescription>three equal horizontal bands of red (top), white, and black with a green isosceles triangle based on the hoist side</Flagdescription>
5199<GDP>purchasing power parity - $32.6 billion (1999 est.)</GDP>
5200<Industries>cotton ginning, textiles, cement, edible oils, sugar, soap distilling, shoes, petroleum refining</Industries>
5201<Exports>$580 million (f.o.b., 1999 est.)</Exports>
5202<Imports>$1.4 billion (c.i.f., 1999 est.)</Imports>
5203<Currency>1 Sudanese dinar (SD) = 100 piastres; note - in July 1999 the Sudanese Central Bank made the formal declaration that all dealings with the Sudanese pound should stop</Currency>
5204<Airports>61 (1999 est.)</Airports>
5205</record>
5206<record>
5207<Location>Northern Europe, islands between the Arctic Ocean, Barents Sea, Greenland Sea, and Norwegian Sea, north of Norway</Location>
5208<Geographiccoordinates>78 00 N, 20 00 E</Geographiccoordinates>
5209<Area>62049</Area>
5210<Climate>arctic, tempered by warm North Atlantic Current; cool summers, cold winters; North Atlantic Current flows along west and north coasts of Spitsbergen, keeping water open and navigable most of the year</Climate>
5211<Naturalresources>coal, copper, iron ore, phosphate, zinc, wildlife, fish</Naturalresources>
5212<Population>2416</Population>
5213<Populationgrowthrate>-3.55% (2000 est.)</Populationgrowthrate>
5214<Countryname>Svalbard (sometimes referred to as Spitzbergen) </Countryname>
5215<Capital>Longyearbyen</Capital>
5216<Flagdescription>the flag of Norway is used</Flagdescription>
5217<GDP>$NA</GDP>
5218<Exports>$NA</Exports>
5219<Imports>$NA</Imports>
5220<Currency>1 Norwegian krone (NKr) = 100 oere</Currency>
5221<Airports>4 (1999 est.)</Airports>
5222</record>
5223<record>
5224<Location>Northern Europe, bordering the Baltic Sea, Gulf of Bothnia, Kattegat, and Skagerrak, between Finland and Norway</Location>
5225<Geographiccoordinates>62 00 N, 15 00 E</Geographiccoordinates>
5226<Area>449964</Area>
5227<Climate>temperate in south with cold, cloudy winters and cool, partly cloudy summers; subarctic in north</Climate>
5228<Naturalresources>zinc, iron ore, lead, copper, silver, timber, uranium, hydropower</Naturalresources>
5229<Population>8873052</Population>
5230<Populationgrowthrate>0.02% (2000 est.)</Populationgrowthrate>
5231<Sexratio>
5232at birth: 1.05 male(s)/female
5233under 15 years: 1.05 male(s)/female
523415-64 years: 1.03 male(s)/female
523565 years and over: 0.73 male(s)/female
5236total population: 0.98 male(s)/female (2000 est.)</Sexratio>
5237<Religions>Lutheran 87%, Roman Catholic, Orthodox, Baptist, Muslim, Jewish, Buddhist</Religions>
5238<Countryname>Sweden </Countryname>
5239<Capital>Stockholm</Capital>
5240<Flagdescription>blue with a yellow cross that extends to the edges of the flag; the vertical part of the cross is shifted to the hoist side in the style of the Dannebrog (Danish flag)</Flagdescription>
5241<GDP>purchasing power parity - $184 billion (1999 est.)</GDP>
5242<Industries>iron and steel, precision equipment (bearings, radio and telephone parts, armaments), wood pulp and paper products, processed foods, motor vehicles</Industries>
5243<Exports>$85.7 billion (f.o.b., 1999)</Exports>
5244<Imports>$67.9 billion (f.o.b., 1999)</Imports>
5245<Currency>1 Swedish krona (SKr) = 100 oere</Currency>
5246<Airports>256 (1999 est.)</Airports>
5247</record>
5248<record>
5249<Location>Southern South America, islands in the South Atlantic Ocean, east of the tip of South America</Location>
5250<Geographiccoordinates>54 30 S, 37 00 W</Geographiccoordinates>
5251<Area>4066</Area>
5252<Climate>variable, with mostly westerly winds throughout the year interspersed with periods of calm; nearly all precipitation falls as snow</Climate>
5253<Naturalresources>fish</Naturalresources>
5254<Population></Population>
5255<Countryname>South Georgia and the South Sandwich Islands </Countryname>
5256<Capital>none; Grytviken on South Georgia is the garrison town</Capital>
5257<Flagdescription>the flag of the UK is used</Flagdescription>
5258<Airports>none</Airports>
5259</record>
5260<record>
5261<Location>Middle East, bordering the Mediterranean Sea, between Lebanon and Turkey</Location>
5262<Geographiccoordinates>35 00 N, 38 00 E</Geographiccoordinates>
5263<Area>185180</Area>
5264<Climate>mostly desert; hot, dry, sunny summers (June to August) and mild, rainy winters (December to February) along coast; cold weather with snow or sleet periodically hitting Damascus</Climate>
5265<Naturalresources>petroleum, phosphates, chrome and manganese ores, asphalt, iron ore, rock salt, marble, gypsum, hydropower</Naturalresources>
5266<Population>16305659</Population>
5267<Populationgrowthrate>2.58% (2000 est.)</Populationgrowthrate>
5268<Sexratio>
5269at birth: 1.05 male(s)/female
5270under 15 years: 1.06 male(s)/female
527115-64 years: 1.05 male(s)/female
527265 years and over: 0.96 male(s)/female
5273total population: 1.05 male(s)/female (2000 est.)</Sexratio>
5274<Religions>Sunni Muslim 74%, Alawite, Druze, and other Muslim sects 16%, Christian (various sects) 10%, Jewish (tiny communities in Damascus, Al Qamishli, and Aleppo)</Religions>
5275<Countryname>Syria </Countryname>
5276<Capital>Damascus</Capital>
5277<Flagdescription>three equal horizontal bands of red (top), white, and black, with two small green five-pointed stars in a horizontal line centered in the white band; similar to the flag of Yemen, which has a plain white band, and of Iraq, which has three green stars (plus an Arabic inscription) in a horizontal line centered in the white band; also similar to the flag of Egypt, which has a heraldic eagle centered in the white band</Flagdescription>
5278<GDP>purchasing power parity - $42.2 billion (1999 est.)</GDP>
5279<Industries>petroleum, textiles, food processing, beverages, tobacco, phosphate rock mining</Industries>
5280<Exports>$3.3 billion (f.o.b., 1999 est.)</Exports>
5281<Imports>$3.2 billion (f.o.b., 1999 est.)</Imports>
5282<Currency>1 Syrian pound = 100 piastres</Currency>
5283<Airports>104 (1999 est.)</Airports>
5284<Illicitdrugs>a transit point for opiates and hashish bound for regional and Western markets</Illicitdrugs>
5285</record>
5286<record>
5287<Location>Central Europe, east of France, north of Italy</Location>
5288<Geographiccoordinates>47 00 N, 8 00 E</Geographiccoordinates>
5289<Area>41290</Area>
5290<Climate>temperate, but varies with altitude; cold, cloudy, rainy/snowy winters; cool to warm, cloudy, humid summers with occasional showers</Climate>
5291<Naturalresources>hydropower potential, timber, salt</Naturalresources>
5292<Population>7262372</Population>
5293<Populationgrowthrate>0.3% (2000 est.)</Populationgrowthrate>
5294<Sexratio>
5295at birth: 1.05 male(s)/female
5296under 15 years: 1.05 male(s)/female
529715-64 years: 1.03 male(s)/female
529865 years and over: 0.68 male(s)/female
5299total population: 0.97 male(s)/female (2000 est.)</Sexratio>
5300<Religions>Roman Catholic 46.1%, Protestant 40%, other 5%, none 8.9% (1990)</Religions>
5301<Countryname>Switzerland </Countryname>
5302<Capital>Bern</Capital>
5303<Flagdescription>red square with a bold, equilateral white cross in the center that does not extend to the edges of the flag</Flagdescription>
5304<GDP>purchasing power parity - $197 billion (1999 est.)</GDP>
5305<Industries>machinery, chemicals, watches, textiles, precision instruments</Industries>
5306<Exports>$98.5 billion (f.o.b., 1999)</Exports>
5307<Imports>$99 billion (f.o.b., 1999)</Imports>
5308<Currency>1 Swiss franc, franken, or franco (SFR) = 100 centimes, rappen, or centesimi</Currency>
5309<Airports>67 (1999 est.)</Airports>
5310<Illicitdrugs>because of more stringent government regulations, used significantly less as a money-laundering center; transit country for and consumer of South American cocaine and Southwest Asian heroin</Illicitdrugs>
5311</record>
5312<record>
5313<Location>Middle East, bordering the Gulf of Oman and the Persian Gulf, between Oman and Saudi Arabia</Location>
5314<Geographiccoordinates>24 00 N, 54 00 E</Geographiccoordinates>
5315<Area>82880</Area>
5316<Climate>desert; cooler in eastern mountains</Climate>
5317<Naturalresources>petroleum, natural gas</Naturalresources>
5318<Population>2369153</Population>
5319<Populationgrowthrate>1.61% (2000 est.)</Populationgrowthrate>
5320<Sexratio>
5321at birth: 1.05 male(s)/female
5322under 15 years: 1.04 male(s)/female
532315-64 years: 1.77 male(s)/female
532465 years and over: 2.26 male(s)/female
5325total population: 1.51 male(s)/female (2000 est.)</Sexratio>
5326<Religions>Muslim 96% (Shi'a 16%), Christian, Hindu, and other 4%</Religions>
5327<Countryname>United Arab Emirates </Countryname>
5328<Capital>Abu Dhabi</Capital>
5329<Flagdescription>three equal horizontal bands of green (top), white, and black with a thicker vertical red band on the hoist side</Flagdescription>
5330<GDP>purchasing power parity - $41.5 billion (1999 est.)</GDP>
5331<Industries>petroleum, fishing, petrochemicals, construction materials, some boat building, handicrafts, pearling</Industries>
5332<Exports>$34 billion (f.o.b., 1999 est.)</Exports>
5333<Imports>$27.5 billion (f.o.b., 1999 est.)</Imports>
5334<Currency>1 Emirian dirham (Dh) = 100 fils</Currency>
5335<Airports>40 (1999 est.)</Airports>
5336<Illicitdrugs>growing role as heroin transshipment and money-laundering center due to its proximity to southwest Asian producing countries and the bustling free trade zone in Dubai</Illicitdrugs>
5337</record>
5338<record>
5339<Location>Caribbean, islands between the Caribbean Sea and the North Atlantic Ocean, northeast of Venezuela</Location>
5340<Geographiccoordinates>11 00 N, 61 00 W</Geographiccoordinates>
5341<Area>5128</Area>
5342<Climate>tropical; rainy season (June to December)</Climate>
5343<Naturalresources>petroleum, natural gas, asphalt</Naturalresources>
5344<Population>1175523</Population>
5345<Populationgrowthrate>-0.49% (2000 est.)</Populationgrowthrate>
5346<Sexratio>
5347at birth: 1.03 male(s)/female
5348under 15 years: 1.04 male(s)/female
534915-64 years: 1.05 male(s)/female
535065 years and over: 0.8 male(s)/female
5351total population: 1.03 male(s)/female (2000 est.)</Sexratio>
5352<Religions>Roman Catholic 29.4%, Hindu 23.8%, Anglican 10.9%, Muslim 5.8%, Presbyterian 3.4%, other 26.7%</Religions>
5353<Countryname>Trinidad and Tobago </Countryname>
5354<Capital>Port-of-Spain</Capital>
5355<Flagdescription>red with a white-edged black diagonal band from the upper hoist side</Flagdescription>
5356<GDP>purchasing power parity - $9.41 billion (1999 est.)</GDP>
5357<Industries>petroleum, chemicals, tourism, food processing, cement, beverage, cotton textiles</Industries>
5358<Exports>$2.4 billion (f.o.b., 1998)</Exports>
5359<Imports>$3 billion (c.i.f., 1998)</Imports>
5360<Currency>1 Trinidad and Tobago dollar (TT$) = 100 cents</Currency>
5361<Airports>6 (1999 est.)</Airports>
5362<Illicitdrugs>transshipment point for South American drugs destined for the US and Europe; producer of cannabis</Illicitdrugs>
5363</record>
5364<record>
5365<Location>Southern Africa, island in the Indian Ocean, east of Madagascar</Location>
5366<Geographiccoordinates>15 52 S, 54 25 E</Geographiccoordinates>
5367<Area>1</Area>
5368<Climate>tropical</Climate>
5369<Naturalresources>fish</Naturalresources>
5370<Population></Population>
5371<Countryname>Tromelin Island </Countryname>
5372<Flagdescription>the flag of France is used</Flagdescription>
5373<Airports>1 (1999 est.)</Airports>
5374</record>
5375<record>
5376<Location>Southeastern Asia, bordering the Andaman Sea and the Gulf of Thailand, southeast of Burma</Location>
5377<Geographiccoordinates>15 00 N, 100 00 E</Geographiccoordinates>
5378<Area>514000</Area>
5379<Climate>tropical; rainy, warm, cloudy southwest monsoon (mid-May to September); dry, cool northeast monsoon (November to mid-March); southern isthmus always hot and humid</Climate>
5380<Naturalresources>tin, rubber, natural gas, tungsten, tantalum, timber, lead, fish, gypsum, lignite, fluorite, arable land</Naturalresources>
5381<Population>61230874</Population>
5382<Populationgrowthrate>0.93% (2000 est.)</Populationgrowthrate>
5383<Sexratio>
5384at birth: 1.05 male(s)/female
5385under 15 years: 1.04 male(s)/female
538615-64 years: 0.97 male(s)/female
538765 years and over: 0.79 male(s)/female
5388total population: 0.97 male(s)/female (2000 est.)</Sexratio>
5389<Religions>Buddhism 95%, Muslim 3.8%, Christianity 0.5%, Hinduism 0.1%, other 0.6% (1991)</Religions>
5390<Countryname>Thailand </Countryname>
5391<Capital>Bangkok</Capital>
5392<Flagdescription>five horizontal bands of red (top), white, blue (double width), white, and red</Flagdescription>
5393<GDP>purchasing power parity - $388.7 billion (1999 est.)</GDP>
5394<Industries>tourism; textiles and garments, agricultural processing, beverages, tobacco, cement, light manufacturing, such as jewelry; electric appliances and components, computers and parts, integrated circuits, furniture, plastics; world's second-largest tungsten producer and third-largest tin producer</Industries>
5395<Exports>$58.5 billion (f.o.b., 1999 est.)</Exports>
5396<Imports>$45 billion (f.o.b., 1999 est.)</Imports>
5397<Currency>1 baht (B) = 100 satang</Currency>
5398<Airports>106 (1999 est.)</Airports>
5399<Illicitdrugs>a minor producer of opium, heroin, and marijuana; major illicit transit point for heroin en route to the international drug market from Burma and Laos; eradication efforts have reduced the area of cannabis cultivation and shifted some production to neighboring countries; opium poppy cultivation has been reduced by eradication efforts; also a drug money-laundering center; minor role in amphetamine production for regional consumption; increasing indigenous abuse of methamphetamines and heroin</Illicitdrugs>
5400</record>
5401<record>
5402<Location>Central Asia, west of China</Location>
5403<Geographiccoordinates>39 00 N, 71 00 E</Geographiccoordinates>
5404<Area>143100</Area>
5405<Climate>midlatitude continental, hot summers, mild winters; semiarid to polar in Pamir Mountains</Climate>
5406<Naturalresources>hydropower, some petroleum, uranium, mercury, brown coal, lead, zinc, antimony, tungsten</Naturalresources>
5407<Population>6440732</Population>
5408<Populationgrowthrate>2.12% (2000 est.)</Populationgrowthrate>
5409<Sexratio>
5410at birth: 1.05 male(s)/female
5411under 15 years: 1.02 male(s)/female
541215-64 years: 0.99 male(s)/female
541365 years and over: 0.76 male(s)/female
5414total population: 0.99 male(s)/female (2000 est.)</Sexratio>
5415<Religions>Sunni Muslim 80%, Shi'a Muslim 5%</Religions>
5416<Countryname>Tajikistan </Countryname>
5417<Capital>Dushanbe</Capital>
5418<Flagdescription>three horizontal stripes of red (top), a wider stripe of white, and green; a gold crown surmounted by seven gold, five-pointed stars is located in the center of the white stripe</Flagdescription>
5419<GDP>purchasing power parity - $6.2 billion (1999 est.)</GDP>
5420<Industries>aluminum, zinc, lead, chemicals and fertilizers, cement, vegetable oil, metal-cutting machine tools, refrigerators and freezers</Industries>
5421<Exports>$634 million (1999 est.)</Exports>
5422<Imports>$770 million (1999 est.)</Imports>
5423<Currency>Tajikistani ruble (TJR) = 100 tanga</Currency>
5424<Airports>59 (1994 est.)</Airports>
5425<Illicitdrugs>limited illicit cultivation of cannabis, mostly for domestic consumption; opium poppy cultivation negligible in 1998 because of government eradication program; major transshipment point for illicit drugs from Southwest Asia to Russia and Western Europe</Illicitdrugs>
5426</record>
5427<record>
5428<Location>Caribbean, two island groups in the North Atlantic Ocean, southeast of The Bahamas</Location>
5429<Geographiccoordinates>21 45 N, 71 35 W</Geographiccoordinates>
5430<Area>430</Area>
5431<Climate>tropical; marine; moderated by trade winds; sunny and relatively dry</Climate>
5432<Naturalresources>spiny lobster, conch</Naturalresources>
5433<Population>17502</Population>
5434<Populationgrowthrate>3.55% (2000 est.)</Populationgrowthrate>
5435<Sexratio>
5436at birth: 1.05 male(s)/female
5437under 15 years: 1.03 male(s)/female
543815-64 years: 1.11 male(s)/female
543965 years and over: 0.81 male(s)/female
5440total population: 1.07 male(s)/female (2000 est.)</Sexratio>
5441<Religions>Baptist 41.2%, Methodist 18.9%, Anglican 18.3%, Seventh-Day Adventist 1.7%, other 19.9% (1980)</Religions>
5442<Countryname>Turks and Caicos Islands </Countryname>
5443<Capital>Cockburn Town (on Grand Turk)</Capital>
5444<Flagdescription>blue, with the flag of the UK in the upper hoist-side quadrant and the colonial shield centered on the outer half of the flag; the shield is yellow and contains a conch shell, lobster, and cactus</Flagdescription>
5445<GDP>purchasing power parity - $117 million (1997 est.)</GDP>
5446<Industries>tourism, offshore financial services</Industries>
5447<Exports>$4.7 million (1993)</Exports>
5448<Imports>$46.6 million (1993)</Imports>
5449<Currency>1 United States dollar (US$) = 100 cents</Currency>
5450<Airports>7 (1999 est.)</Airports>
5451<Illicitdrugs>transshipment point for South American narcotics destined for the US</Illicitdrugs>
5452</record>
5453<record>
5454<Location>Oceania, group of three islands in the South Pacific Ocean, about one-half of the way from Hawaii to New Zealand</Location>
5455<Geographiccoordinates>9 00 S, 172 00 W</Geographiccoordinates>
5456<Area>10</Area>
5457<Climate>tropical; moderated by trade winds (April to November)</Climate>
5458<Naturalresources>NEGL</Naturalresources>
5459<Population>1458</Population>
5460<Populationgrowthrate>-0.89% (2000 est.)</Populationgrowthrate>
5461<Religions>Congregational Christian Church 70%, Roman Catholic 28%, other 2%
5462note: on Atafu, all Congregational Christian Church of Samoa; on Nukunonu, all Roman Catholic; on Fakaofo, both denominations, with the Congregational Christian Church predominant</Religions>
5463<Countryname>Tokelau </Countryname>
5464<Capital>none; each atoll has its own administrative center</Capital>
5465<Flagdescription>the flag of New Zealand is used</Flagdescription>
5466<GDP>purchasing power parity - $1.5 million (1993 est.)</GDP>
5467<Industries>small-scale enterprises for copra production, wood work, plaited craft goods; stamps, coins; fishing</Industries>
5468<Exports>$98,000 (f.o.b., 1983)</Exports>
5469<Imports>$323,400 (c.i.f., 1983)</Imports>
5470<Currency>1 New Zealand dollar (NZ$) = 100 cents</Currency>
5471<Airports>none; lagoon landings by amphibious aircraft from Samoa</Airports>
5472</record>
5473<record>
5474<Location>Oceania, archipelago in the South Pacific Ocean, about two-thirds of the way from Hawaii to New Zealand</Location>
5475<Geographiccoordinates>20 00 S, 175 00 W</Geographiccoordinates>
5476<Area>748</Area>
5477<Climate>tropical; modified by trade winds; warm season (December to May), cool season (May to December)</Climate>
5478<Naturalresources>fish, fertile soil</Naturalresources>
5479<Population>102321</Population>
5480<Populationgrowthrate>1.91% (2000 est.)</Populationgrowthrate>
5481<Sexratio>
5482at birth: 1.05 male(s)/female
5483under 15 years: 1.04 male(s)/female
548415-64 years: 0.97 male(s)/female
548565 years and over: 0.83 male(s)/female
5486total population: 0.99 male(s)/female (2000 est.)</Sexratio>
5487<Religions>Christian (Free Wesleyan Church claims over 30,000 adherents)</Religions>
5488<Countryname>Tonga </Countryname>
5489<Capital>Nuku'alofa</Capital>
5490<Flagdescription>red with a bold red cross on a white rectangle in the upper hoist-side corner</Flagdescription>
5491<GDP>purchasing power parity - $238 million (1998 est.)</GDP>
5492<Industries>tourism, fishing</Industries>
5493<Exports>$8 million (f.o.b., 1998)</Exports>
5494<Imports>$69 million (f.o.b., 1998)</Imports>
5495<Currency>1 pa'anga (T$) = 100 seniti</Currency>
5496<Airports>6 (1999 est.)</Airports>
5497</record>
5498<record>
5499<Location>Western Africa, bordering the Bight of Benin, between Benin and Ghana</Location>
5500<Geographiccoordinates>8 00 N, 1 10 E</Geographiccoordinates>
5501<Area>56785</Area>
5502<Climate>tropical; hot, humid in south; semiarid in north</Climate>
5503<Naturalresources>phosphates, limestone, marble, arable land</Naturalresources>
5504<Population>5018502</Population>
5505<Populationgrowthrate>2.7% (2000 est.)</Populationgrowthrate>
5506<Sexratio>
5507at birth: 1.03 male(s)/female
5508under 15 years: 1.01 male(s)/female
550915-64 years: 0.95 male(s)/female
551065 years and over: 0.78 male(s)/female
5511total population: 0.97 male(s)/female (2000 est.)</Sexratio>
5512<Religions>indigenous beliefs 70%, Christian 20%, Muslim 10%</Religions>
5513<Countryname>Togo </Countryname>
5514<Capital>Lome</Capital>
5515<Flagdescription>five equal horizontal bands of green (top and bottom) alternating with yellow; there is a white five-pointed star on a red square in the upper hoist-side corner; uses the popular pan-African colors of Ethiopia</Flagdescription>
5516<GDP>purchasing power parity - $8.6 billion (1999 est.)</GDP>
5517<Industries>phosphate mining, agricultural processing, cement; handicrafts, textiles, beverages</Industries>
5518<Exports>$400 million (f.o.b., 1999)</Exports>
5519<Imports>$450 million (f.o.b., 1999)</Imports>
5520<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
5521<Airports>9 (1999 est.)</Airports>
5522<Illicitdrugs>transit hub for Nigerian heroin and cocaine traffickers</Illicitdrugs>
5523</record>
5524<record>
5525<Location>Western Africa, islands in the Gulf of Guinea, straddling the Equator, west of Gabon</Location>
5526<Geographiccoordinates>1 00 N, 7 00 E</Geographiccoordinates>
5527<Area>1001</Area>
5528<Climate>tropical; hot, humid; one rainy season (October to May)</Climate>
5529<Naturalresources>fish, hydropower</Naturalresources>
5530<Population>159883</Population>
5531<Populationgrowthrate>3.16% (2000 est.)</Populationgrowthrate>
5532<Sexratio>
5533at birth: 1.03 male(s)/female
5534under 15 years: 1.03 male(s)/female
553515-64 years: 0.93 male(s)/female
553665 years and over: 0.84 male(s)/female
5537total population: 0.97 male(s)/female (2000 est.)</Sexratio>
5538<Religions>Christian 80% (Roman Catholic, Evangelical Protestant, Seventh-Day Adventist)</Religions>
5539<Countryname>Sao Tome and Principe </Countryname>
5540<Capital>Sao Tome</Capital>
5541<Flagdescription>three horizontal bands of green (top), yellow (double width), and green with two black five-pointed stars placed side by side in the center of the yellow band and a red isosceles triangle based on the hoist side; uses the popular pan-African colors of Ethiopia</Flagdescription>
5542<GDP>purchasing power parity - $169 million (1999 est.)</GDP>
5543<Industries>light construction, textiles, soap, beer; fish processing; timber</Industries>
5544<Exports>$4.9 million (f.o.b., 1999 est.)</Exports>
5545<Imports>$19.5 million (f.o.b., 1999 est.)</Imports>
5546<Currency>1 dobra (Db) = 100 centimos</Currency>
5547<Airports>2 (1999 est.)</Airports>
5548</record>
5549<record>
5550<Location>Northern Africa, bordering the Mediterranean Sea, between Algeria and Libya</Location>
5551<Geographiccoordinates>34 00 N, 9 00 E</Geographiccoordinates>
5552<Area>163610</Area>
5553<Climate>temperate in north with mild, rainy winters and hot, dry summers; desert in south</Climate>
5554<Naturalresources>petroleum, phosphates, iron ore, lead, zinc, salt, arable land</Naturalresources>
5555<Population>9593402</Population>
5556<Populationgrowthrate>1.17% (2000 est.)</Populationgrowthrate>
5557<Sexratio>
5558at birth: 1.08 male(s)/female
5559under 15 years: 1.07 male(s)/female
556015-64 years: 1 male(s)/female
556165 years and over: 1.01 male(s)/female
5562total population: 1.02 male(s)/female (2000 est.)</Sexratio>
5563<Religions>Muslim 98%, Christian 1%, Jewish and other 1%</Religions>
5564<Countryname>Tunisia </Countryname>
5565<Capital>Tunis</Capital>
5566<Flagdescription>red with a white disk in the center bearing a red crescent nearly encircling a red five-pointed star; the crescent and star are traditional symbols of Islam</Flagdescription>
5567<GDP>purchasing power parity - $52.6 billion (1999 est.)</GDP>
5568<Industries>petroleum, mining (particularly phosphate and iron ore), tourism, textiles, footwear, food, beverages</Industries>
5569<Exports>$5.8 billion (f.o.b., 1999 est.)</Exports>
5570<Imports>$8.3 billion (c.i.f., 1999 est.)</Imports>
5571<Currency>1 Tunisian dinar (TD) = 1,000 millimes</Currency>
5572<Airports>32 (1999 est.)</Airports>
5573</record>
5574<record>
5575<Geographiccoordinates>39 00 N, 35 00 E</Geographiccoordinates>
5576<Area>780580</Area>
5577<Climate>temperate; hot, dry summers with mild, wet winters; harsher in interior</Climate>
5578<Naturalresources>antimony, coal, chromium, mercury, copper, borate, sulfur, iron ore, arable land, hydropower</Naturalresources>
5579<Population>65666677</Population>
5580<Populationgrowthrate>1.27% (2000 est.)</Populationgrowthrate>
5581<Sexratio>
5582at birth: 1.05 male(s)/female
5583under 15 years: 1.04 male(s)/female
558415-64 years: 1.03 male(s)/female
558565 years and over: 0.85 male(s)/female
5586total population: 1.02 male(s)/female (2000 est.)</Sexratio>
5587<Religions>Muslim 99.8% (mostly Sunni), other 0.2% (Christian and Jews)</Religions>
5588<Countryname>Turkey </Countryname>
5589<Capital>Ankara</Capital>
5590<Flagdescription>red with a vertical white crescent (the closed portion is toward the hoist side) and white five-pointed star centered just outside the crescent opening</Flagdescription>
5591<GDP>purchasing power parity - $409.4 billion (1999 est.)</GDP>
5592<Industries>textiles, food processing, autos, mining (coal, chromite, copper, boron), steel, petroleum, construction, lumber, paper</Industries>
5593<Exports>$26 billion (f.o.b., 1999 est.)</Exports>
5594<Imports>$40 billion (c.i.f., 1999 est.)</Imports>
5595<Currency>Turkish lira (TL) = 100 kurus (theoretical)</Currency>
5596<Airports>118 (1999 est.)</Airports>
5597<Illicitdrugs>key transit route for Southwest Asian heroin to Western Europe and - to a far lesser extent the US - via air, land, and sea routes; major Turkish, Iranian, and other international trafficking organizations operate out of Istanbul; laboratories to convert imported morphine base into heroin are in remote regions of Turkey as well as near Istanbul; government maintains strict controls over areas of legal opium poppy cultivation and output of poppy straw concentrate</Illicitdrugs>
5598</record>
5599<record>
5600<Location>Oceania, island group consisting of nine coral atolls in the South Pacific Ocean, about one-half of the way from Hawaii to Australia</Location>
5601<Geographiccoordinates>8 00 S, 178 00 E</Geographiccoordinates>
5602<Area>26</Area>
5603<Climate>tropical; moderated by easterly trade winds (March to November); westerly gales and heavy rain (November to March)</Climate>
5604<Naturalresources>fish</Naturalresources>
5605<Population>10838</Population>
5606<Populationgrowthrate>1.41% (2000 est.)</Populationgrowthrate>
5607<Sexratio>
5608at birth: 1.05 male(s)/female
5609under 15 years: 1.04 male(s)/female
561015-64 years: 0.91 male(s)/female
561165 years and over: 0.75 male(s)/female
5612total population: 0.94 male(s)/female (2000 est.)</Sexratio>
5613<Religions>Church of Tuvalu (Congregationalist) 97%, Seventh-Day Adventist 1.4%, Baha'i 1%, other 0.6%</Religions>
5614<Countryname>Tuvalu </Countryname>
5615<Capital>Funafuti</Capital>
5616<Flagdescription>light blue with the flag of the UK in the upper hoist-side quadrant; the outer half of the flag represents a map of the country with nine yellow five-pointed stars symbolizing the nine islands</Flagdescription>
5617<GDP>purchasing power parity - $7.8 million (1995 est.)</GDP>
5618<Industries>fishing, tourism, copra</Industries>
5619<Exports>$165,000 (f.o.b., 1989)</Exports>
5620<Imports>$4.4 million (c.i.f., 1989)</Imports>
5621<Currency>1 Tuvaluan dollar ($T) or 1 Australian dollar ($A) = 100 cents</Currency>
5622<Airports>1 (1999 est.)</Airports>
5623</record>
5624<record>
5625<Location>Eastern Asia, islands bordering the East China Sea, Philippine Sea, South China Sea, and Taiwan Strait, north of the Philippines, off the southeastern coast of China</Location>
5626<Geographiccoordinates>23 30 N, 121 00 E</Geographiccoordinates>
5627<Area>35980</Area>
5628<Climate>tropical; marine; rainy season during southwest monsoon (June to August); cloudiness is persistent and extensive all year</Climate>
5629<Naturalresources>small deposits of coal, natural gas, limestone, marble, and asbestos</Naturalresources>
5630<Population>22191087</Population>
5631<Populationgrowthrate>0.81% (2000 est.)</Populationgrowthrate>
5632<Sexratio>
5633at birth: 1.08 male(s)/female
5634under 15 years: 1.08 male(s)/female
563515-64 years: 1.03 male(s)/female
563665 years and over: 1.12 male(s)/female
5637total population: 1.05 male(s)/female (2000 est.)</Sexratio>
5638<Religions>mixture of Buddhist, Confucian, and Taoist 93%, Christian 4.5%, other 2.5%</Religions>
5639<Countryname>Taiwan </Countryname>
5640<Capital>Taipei</Capital>
5641<Flagdescription>red with a dark blue rectangle in the upper hoist-side corner bearing a white sun with 12 triangular rays</Flagdescription>
5642<GDP>purchasing power parity - $357 billion (1999 est.)</GDP>
5643<Industries>electronics, petroleum refining, chemicals, textiles, iron and steel, machinery, cement, food processing</Industries>
5644<Exports>$121.6 billion (f.o.b., 1999)</Exports>
5645<Imports>$101.7 billion (c.i.f., 1999)</Imports>
5646<Currency>1 New Taiwan dollar (NT$) = 100 cents</Currency>
5647<Airports>38 (1999 est.)</Airports>
5648<Illicitdrugs>considered an important heroin transit point; major problem with domestic consumption of methamphetamines and heroin</Illicitdrugs>
5649</record>
5650<record>
5651<Location>Central Asia, bordering the Caspian Sea, between Iran and Kazakhstan</Location>
5652<Geographiccoordinates>40 00 N, 60 00 E</Geographiccoordinates>
5653<Area>488100</Area>
5654<Climate>subtropical desert</Climate>
5655<Naturalresources>petroleum, natural gas, coal, sulfur, salt</Naturalresources>
5656<Population>4518268</Population>
5657<Populationgrowthrate>1.87% (2000 est.)</Populationgrowthrate>
5658<Sexratio>
5659at birth: 1.05 male(s)/female
5660under 15 years: 1.04 male(s)/female
566115-64 years: 0.97 male(s)/female
566265 years and over: 0.62 male(s)/female
5663total population: 0.98 male(s)/female (2000 est.)</Sexratio>
5664<Religions>Muslim 89%, Eastern Orthodox 9%, unknown 2%</Religions>
5665<Countryname>Turkmenistan </Countryname>
5666<Capital>Ashgabat</Capital>
5667<Flagdescription>green field with a vertical red stripe near the hoist side, containing five carpet guls (designs used in producing rugs) stacked above two crossed olive branches similar to the olive branches on the UN flag; a white crescent moon and five white stars appear in the upper corner of the field just to the fly side of the red stripe</Flagdescription>
5668<GDP>purchasing power parity - $7.7 billion (1999 est.)</GDP>
5669<Industries>natural gas, oil, petroleum products, textiles, food processing</Industries>
5670<Exports>$1.1 billion (1999 est.)</Exports>
5671<Imports>$1.25 billion (1999 est.)</Imports>
5672<Currency>1 Turkmen manat (TMM) = 100 tenesi</Currency>
5673<Airports>64 (1994 est.)</Airports>
5674<Illicitdrugs>limited illicit cultivator of opium poppy, mostly for domestic consumption; limited government eradication program; increasingly used as transshipment point for illicit drugs from Southwest Asia to Russia and Western Europe; also a transshipment point for acetic anhydride destined for Afghanistan</Illicitdrugs>
5675</record>
5676<record>
5677<Location>Eastern Africa, bordering the Indian Ocean, between Kenya and Mozambique</Location>
5678<Geographiccoordinates>6 00 S, 35 00 E</Geographiccoordinates>
5679<Area>945087</Area>
5680<Climate>varies from tropical along coast to temperate in highlands</Climate>
5681<Naturalresources>hydropower, tin, phosphates, iron ore, coal, diamonds, gemstones, gold, natural gas, nickel</Naturalresources>
5682<Population>35306126</Population>
5683<Populationgrowthrate>2.57% (2000 est.)</Populationgrowthrate>
5684<Sexratio>
5685at birth: 1.03 male(s)/female
5686under 15 years: 1.01 male(s)/female
568715-64 years: 0.98 male(s)/female
568865 years and over: 0.84 male(s)/female
5689total population: 0.99 male(s)/female (2000 est.)</Sexratio>
5690<Religions>mainland - Christian 45%, Muslim 35%, indigenous beliefs 20%; Zanzibar - more than 99% Muslim</Religions>
5691<Countryname>Tanzania </Countryname>
5692<Capital>Dar es Salaam
5693note: some government offices have been transferred to Dodoma, which is planned as the new national capital; the National Assembly now meets there on regular basis</Capital>
5694<Flagdescription>divided diagonally by a yellow-edged black band from the lower hoist-side corner; the upper triangle (hoist side) is green and the lower triangle is blue</Flagdescription>
5695<GDP>purchasing power parity - $23.3 billion (1999 est.)</GDP>
5696<Industries>primarily agricultural processing (sugar, beer, cigarettes, sisal twine), diamond and gold mining, oil refining, shoes, cement, textiles, wood products, fertilizer, salt</Industries>
5697<Exports>$828 million (f.o.b., 1999 est.)</Exports>
5698<Imports>$1.44 billion (f.o.b., 1999 est.)</Imports>
5699<Currency>1 Tanzanian shilling (TSh) = 100 cents</Currency>
5700<Airports>129 (1999 est.)</Airports>
5701<Illicitdrugs>growing role in transshipment of Southwest and Southeast Asian heroin and South American cocaine destined for European and US markets and of South Asian methaqualone bound for Southern Africa</Illicitdrugs>
5702</record>
5703<record>
5704<Location>Eastern Africa, west of Kenya</Location>
5705<Geographiccoordinates>1 00 N, 32 00 E</Geographiccoordinates>
5706<Area>236040</Area>
5707<Climate>tropical; generally rainy with two dry seasons (December to February, June to August); semiarid in northeast</Climate>
5708<Naturalresources>copper, cobalt, hydropower, limestone, salt, arable land</Naturalresources>
5709<Population>23317560</Population>
5710<Populationgrowthrate>2.72% (2000 est.)</Populationgrowthrate>
5711<Sexratio>
5712at birth: 1.03 male(s)/female
5713under 15 years: 1.01 male(s)/female
571415-64 years: 1 male(s)/female
571565 years and over: 0.92 male(s)/female
5716total population: 1 male(s)/female (2000 est.)</Sexratio>
5717<Religions>Roman Catholic 33%, Protestant 33%, Muslim 16%, indigenous beliefs 18%</Religions>
5718<Countryname>Uganda </Countryname>
5719<Capital>Kampala</Capital>
5720<Flagdescription>six equal horizontal bands of black (top), yellow, red, black, yellow, and red; a white disk is superimposed at the center and depicts a red-crested crane (the national symbol) facing the hoist side</Flagdescription>
5721<GDP>purchasing power parity - $24.2 billion (1999 est.)</GDP>
5722<Industries>sugar, brewing, tobacco, cotton textiles, cement</Industries>
5723<Exports>$471 million (f.o.b., 1999)</Exports>
5724<Imports>$1.1 billion (f.o.b., 1999)</Imports>
5725<Currency>1 Ugandan shilling (USh) = 100 cents</Currency>
5726<Airports>26 (1999 est.)</Airports>
5727</record>
5728<record>
5729<Location>Western Europe, islands including the northern one-sixth of the island of Ireland between the North Atlantic Ocean and the North Sea, northwest of France</Location>
5730<Geographiccoordinates>54 00 N, 2 00 W</Geographiccoordinates>
5731<Area>244820</Area>
5732<Climate>temperate; moderated by prevailing southwest winds over the North Atlantic Current; more than one-half of the days are overcast</Climate>
5733<Naturalresources>coal, petroleum, natural gas, tin, limestone, iron ore, salt, clay, chalk, gypsum, lead, silica, arable land</Naturalresources>
5734<Population>59511464</Population>
5735<Populationgrowthrate>0.25% (2000 est.)</Populationgrowthrate>
5736<Sexratio>
5737at birth: 1.05 male(s)/female
5738under 15 years: 1.05 male(s)/female
573915-64 years: 1.02 male(s)/female
574065 years and over: 0.71 male(s)/female
5741total population: 0.97 male(s)/female (2000 est.)</Sexratio>
5742<Religions>Anglican 27 million, Roman Catholic 9 million, Muslim 1 million, Presbyterian 800,000, Methodist 760,000, Sikh 400,000, Hindu 350,000, Jewish 300,000 (1991 est.)</Religions>
5743<Countryname>United Kingdom </Countryname>
5744<Capital>London</Capital>
5745<Flagdescription>blue with the red cross of Saint George (patron saint of England) edged in white superimposed on the diagonal red cross of Saint Patrick (patron saint of Ireland) and which is superimposed on the diagonal white cross of Saint Andrew (patron saint of Scotland); known as the Union Flag or Union Jack; the design and colors (especially the Blue Ensign) have been the basis for a number of other flags including other Commonwealth countries and their constituent states or provinces, as well as British overseas territories</Flagdescription>
5746<GDP>purchasing power parity - $1.29 trillion (1999 est.)</GDP>
5747<Industries>production machinery including machine tools, electric power equipment, automation equipment, railroad equipment, shipbuilding, aircraft, motor vehicles and parts, electronics and communications equipment, metals, chemicals, coal, petroleum, paper and paper products, food processing, textiles, clothing, and other consumer goods</Industries>
5748<Exports>$271 billion (f.o.b., 1998)</Exports>
5749<Imports>$305.9 billion (f.o.b., 1998)</Imports>
5750<Currency>1 British pound = 100 pence</Currency>
5751<Airports>498 (1999 est.)</Airports>
5752<Illicitdrugs>gateway country for Latin American cocaine entering the European market; producer and major consumer of synthetic drugs, synthetic precursor chemicals; major consumer of Southwest Asian heroin; money-laundering center</Illicitdrugs>
5753</record>
5754<record>
5755<Location>Eastern Europe, bordering the Black Sea, between Poland and Russia</Location>
5756<Geographiccoordinates>49 00 N, 32 00 E</Geographiccoordinates>
5757<Area>603700</Area>
5758<Climate>temperate continental; Mediterranean only on the southern Crimean coast; precipitation disproportionately distributed, highest in west and north, lesser in east and southeast; winters vary from cool along the Black Sea to cold farther inland; summers are warm across the greater part of the country, hot in the south</Climate>
5759<Naturalresources>iron ore, coal, manganese, natural gas, oil, salt, sulfur, graphite, titanium, magnesium, kaolin, nickel, mercury, timber, arable land</Naturalresources>
5760<Population>49153027</Population>
5761<Populationgrowthrate>-0.83% (2000 est.)</Populationgrowthrate>
5762<Sexratio>
5763at birth: 1.05 male(s)/female
5764under 15 years: 1.04 male(s)/female
576515-64 years: 0.91 male(s)/female
576665 years and over: 0.49 male(s)/female
5767total population: 0.86 male(s)/female (2000 est.)</Sexratio>
5768<Religions>Ukrainian Orthodox - Moscow Patriarchate, Ukrainian Orthodox - Kiev Patriarchate, Ukrainian Autocephalous Orthodox, Ukrainian Catholic (Uniate), Protestant, Jewish</Religions>
5769<Countryname>Ukraine </Countryname>
5770<Capital>Kiev (Kyyiv)</Capital>
5771<Flagdescription>two equal horizontal bands of azure (top) and golden yellow represent grainfields under a blue sky</Flagdescription>
5772<GDP>purchasing power parity - $109.5 billion (1999 est.)</GDP>
5773<Industries>coal, electric power, ferrous and nonferrous metals, machinery and transport equipment, chemicals, food-processing (especially sugar)</Industries>
5774<Exports>$11.6 billion (1999 est.)</Exports>
5775<Imports>$11.8 billion (1999 est.)</Imports>
5776<Currency>1 hryvna = 100 kopiykas</Currency>
5777<Airports>706 (1994 est.)</Airports>
5778<Illicitdrugs>limited cultivation of cannabis and opium poppy, mostly for CIS consumption; some synthetic drug production for export to West; limited government eradication program; used as transshipment point for opiates and other illicit drugs from Africa, Latin America, and Turkey, and to Europe and Russia; drug-related money laundering a minor, but growing, problem</Illicitdrugs>
5779</record>
5780<record>
5781<Location>North America, bordering both the North Atlantic Ocean and the North Pacific Ocean, between Canada and Mexico</Location>
5782<Geographiccoordinates>38 00 N, 97 00 W</Geographiccoordinates>
5783<Area>9629091</Area>
5784<Climate>mostly temperate, but tropical in Hawaii and Florida, arctic in Alaska, semiarid in the great plains west of the Mississippi River, and arid in the Great Basin of the southwest; low winter temperatures in the northwest are ameliorated occasionally in January and February by warm chinook winds from the eastern slopes of the Rocky Mountains</Climate>
5785<Naturalresources>coal, copper, lead, molybdenum, phosphates, uranium, bauxite, gold, iron, mercury, nickel, potash, silver, tungsten, zinc, petroleum, natural gas, timber</Naturalresources>
5786<Population>275562673</Population>
5787<Populationgrowthrate>0.91% (2000 est.)</Populationgrowthrate>
5788<Sexratio>
5789at birth: 1.05 male(s)/female
5790under 15 years: 1.05 male(s)/female
579115-64 years: 0.98 male(s)/female
579265 years and over: 0.71 male(s)/female
5793total population: 0.96 male(s)/female (2000 est.)</Sexratio>
5794<Religions>Protestant 56%, Roman Catholic 28%, Jewish 2%, other 4%, none 10% (1989)</Religions>
5795<Countryname>United States </Countryname>
5796<Capital>Washington, DC</Capital>
5797<Flagdescription>thirteen equal horizontal stripes of red (top and bottom) alternating with white; there is a blue rectangle in the upper hoist-side corner bearing 50 small, white, five-pointed stars arranged in nine offset horizontal rows of six stars (top and bottom) alternating with rows of five stars; the 50 stars represent the 50 states, the 13 stripes represent the 13 original colonies; known as Old Glory; the design and colors have been the basis for a number of other flags, including Chile, Liberia, Malaysia, and Puerto Rico</Flagdescription>
5798<GDP>purchasing power parity - $9.255 trillion (1999 est.)</GDP>
5799<Industries>leading industrial power in the world, highly diversified and technologically advanced; petroleum, steel, motor vehicles, aerospace, telecommunications, chemicals, electronics, food processing, consumer goods, lumber, mining</Industries>
5800<Exports>$663 billion (f.o.b., 1998 est.)</Exports>
5801<Imports>$912 billion (c.i.f., 1998 est.)</Imports>
5802<Currency>1 United States dollar (US$) = 100 cents</Currency>
5803<Airports>14,572 (1999 est.)</Airports>
5804<Illicitdrugs>consumer of cocaine shipped from Colombia through Mexico and the Caribbean; consumer of heroin, marijuana, and increasingly methamphetamines from Mexico; consumer of high-quality Southeast Asian heroin; illicit producer of cannabis, marijuana, depressants, stimulants, hallucinogens, and methamphetamines; drug-money-laundering center</Illicitdrugs>
5805</record>
5806<record>
5807<Location>Western Africa, north of Ghana</Location>
5808<Geographiccoordinates>13 00 N, 2 00 W</Geographiccoordinates>
5809<Area>274200</Area>
5810<Climate>tropical; warm, dry winters; hot, wet summers</Climate>
5811<Naturalresources>manganese, limestone, marble; small deposits of gold, antimony, copper, nickel, bauxite, lead, phosphates, zinc, silver</Naturalresources>
5812<Population>11946065</Population>
5813<Populationgrowthrate>2.71% (2000 est.)</Populationgrowthrate>
5814<Sexratio>
5815at birth: 1.03 male(s)/female
5816under 15 years: 1.02 male(s)/female
581715-64 years: 0.91 male(s)/female
581865 years and over: 0.74 male(s)/female
5819total population: 0.95 male(s)/female (2000 est.)</Sexratio>
5820<Religions>indigenous beliefs 40%, Muslim 50%, Christian (mainly Roman Catholic) 10%</Religions>
5821<Countryname>Burkina Faso </Countryname>
5822<Capital>Ouagadougou</Capital>
5823<Flagdescription>two equal horizontal bands of red (top) and green with a yellow five-pointed star in the center; uses the popular pan-African colors of Ethiopia</Flagdescription>
5824<GDP>purchasing power parity - $12.4 billion (1999 est.)</GDP>
5825<Industries>cotton lint, beverages, agricultural processing, soap, cigarettes, textiles, gold</Industries>
5826<Exports>$311 million (f.o.b., 1998 est.)</Exports>
5827<Imports>$572 million (f.o.b., 1998 est.)</Imports>
5828<Currency>1 Communaute Financiere Africaine franc (CFAF) = 100 centimes</Currency>
5829<Airports>33 (1999 est.)</Airports>
5830</record>
5831<record>
5832<Location>Southern South America, bordering the South Atlantic Ocean, between Argentina and Brazil</Location>
5833<Geographiccoordinates>33 00 S, 56 00 W</Geographiccoordinates>
5834<Area>176220</Area>
5835<Climate>warm temperate; freezing temperatures almost unknown</Climate>
5836<Naturalresources>arable land, hydropower, minor minerals, fisheries</Naturalresources>
5837<Population>3334074</Population>
5838<Populationgrowthrate>0.77% (2000 est.)</Populationgrowthrate>
5839<Sexratio>
5840at birth: 1.06 male(s)/female
5841under 15 years: 1.05 male(s)/female
584215-64 years: 0.97 male(s)/female
584365 years and over: 0.7 male(s)/female
5844total population: 0.95 male(s)/female (2000 est.)</Sexratio>
5845<Religions>Roman Catholic 66% (less than one-half of the adult population attends church regularly), Protestant 2%, Jewish 2%, nonprofessing or other 30%</Religions>
5846<Countryname>Uruguay </Countryname>
5847<Capital>Montevideo</Capital>
5848<Flagdescription>nine equal horizontal stripes of white (top and bottom) alternating with blue; there is a white square in the upper hoist-side corner with a yellow sun bearing a human face known as the Sun of May and 16 rays alternately triangular and wavy</Flagdescription>
5849<GDP>purchasing power parity - $28 billion (1999 est.)</GDP>
5850<Industries>food processing, electrical machinery, transportation equipment, petroleum products, textiles, chemicals, beverages</Industries>
5851<Exports>$2.1 billion (f.o.b., 1999 est.)</Exports>
5852<Imports>$3.4 billion (f.o.b., 1999 est.)</Imports>
5853<Currency>1 Uruguayan peso ($Ur) = 100 centesimos</Currency>
5854<Airports>65 (1999 est.)</Airports>
5855</record>
5856<record>
5857<Location>Central Asia, north of Afghanistan</Location>
5858<Geographiccoordinates>41 00 N, 64 00 E</Geographiccoordinates>
5859<Area>447400</Area>
5860<Climate>mostly midlatitude desert, long, hot summers, mild winters; semiarid grassland in east</Climate>
5861<Naturalresources>natural gas, petroleum, coal, gold, uranium, silver, copper, lead and zinc, tungsten, molybdenum</Naturalresources>
5862<Population>24755519</Population>
5863<Populationgrowthrate>1.6% (2000 est.)</Populationgrowthrate>
5864<Sexratio>
5865at birth: 1.05 male(s)/female
5866under 15 years: 1.03 male(s)/female
586715-64 years: 0.98 male(s)/female
586865 years and over: 0.66 male(s)/female
5869total population: 0.98 male(s)/female (2000 est.)</Sexratio>
5870<Religions>Muslim 88% (mostly Sunnis), Eastern Orthodox 9%, other 3%</Religions>
5871<Countryname>Uzbekistan </Countryname>
5872<Capital>Tashkent (Toshkent)</Capital>
5873<Flagdescription>three equal horizontal bands of blue (top), white, and green separated by red fimbriations with a white crescent moon and 12 white stars in the upper hoist-side quadrant</Flagdescription>
5874<GDP>purchasing power parity - $59.3 billion (1999 est.)</GDP>
5875<Industries>textiles, food processing, machine building, metallurgy, natural gas</Industries>
5876<Exports>$2.9 billion (1999 est.)</Exports>
5877<Imports>$3.1 billion (1999 est.)</Imports>
5878<Currency>Uzbekistani som (UKS)</Currency>
5879<Airports>3 (1997 est.)</Airports>
5880<Illicitdrugs>limited illicit cultivation of cannabis and very small amounts of opium poppy, mostly for domestic consumption, almost entirely eradicated by an effective government eradication program; increasingly used as transshipment point for illicit drugs from Afghanistan to Russia and Western Europe and for acetic anhydride destined for Afghanistan</Illicitdrugs>
5881</record>
5882<record>
5883<Location>Caribbean, islands in the Caribbean Sea, north of Trinidad and Tobago</Location>
5884<Geographiccoordinates>13 15 N, 61 12 W</Geographiccoordinates>
5885<Area>389</Area>
5886<Climate>tropical; little seasonal temperature variation; rainy season (May to November)</Climate>
5887<Naturalresources>hydropower, cropland</Naturalresources>
5888<Population>115461</Population>
5889<Populationgrowthrate>0.43% (2000 est.)</Populationgrowthrate>
5890<Sexratio>
5891at birth: 1.03 male(s)/female
5892under 15 years: 1.04 male(s)/female
589315-64 years: 1.05 male(s)/female
589465 years and over: 0.75 male(s)/female
5895total population: 1.02 male(s)/female (2000 est.)</Sexratio>
5896<Religions>Anglican 47%, Methodist 28%, Roman Catholic 13%, Seventh-Day Adventist, Hindu, other Protestant</Religions>
5897<Countryname>Saint Vincent and the Grenadines </Countryname>
5898<Capital>Kingstown</Capital>
5899<Flagdescription>three vertical bands of blue (hoist side), gold (double width), and green; the gold band bears three green diamonds arranged in a V pattern</Flagdescription>
5900<GDP>purchasing power parity - $309 million (1999 est.)</GDP>
5901<Industries>food processing, cement, furniture, clothing, starch</Industries>
5902<Exports>$47.8 million (1998 est.)</Exports>
5903<Imports>$180 million (1998 est.)</Imports>
5904<Currency>1 East Caribbean dollar (EC$) = 100 cents</Currency>
5905<Airports>6 (1999 est.)</Airports>
5906<Illicitdrugs>transshipment point for South American drugs destined for the US and Europe</Illicitdrugs>
5907</record>
5908<record>
5909<Location>Northern South America, bordering the Caribbean Sea and the North Atlantic Ocean, between Colombia and Guyana</Location>
5910<Geographiccoordinates>8 00 N, 66 00 W</Geographiccoordinates>
5911<Area>912050</Area>
5912<Climate>tropical; hot, humid; more moderate in highlands</Climate>
5913<Naturalresources>petroleum, natural gas, iron ore, gold, bauxite, other minerals, hydropower, diamonds</Naturalresources>
5914<Population>23542649</Population>
5915<Populationgrowthrate>1.6% (2000 est.)</Populationgrowthrate>
5916<Sexratio>
5917at birth: 1.08 male(s)/female
5918under 15 years: 1.07 male(s)/female
591915-64 years: 1.01 male(s)/female
592065 years and over: 0.84 male(s)/female
5921total population: 1.02 male(s)/female (2000 est.)</Sexratio>
5922<Religions>nominally Roman Catholic 96%, Protestant 2%</Religions>
5923<Countryname>Venezuela </Countryname>
5924<Capital>Caracas</Capital>
5925<Flagdescription>three equal horizontal bands of yellow (top), blue, and red with the coat of arms on the hoist side of the yellow band and an arc of seven white five-pointed stars centered in the blue band</Flagdescription>
5926<GDP>purchasing power parity - $182.8 billion (1999 est.)</GDP>
5927<Industries>petroleum, iron ore mining, construction materials, food processing, textiles, steel, aluminum, motor vehicle assembly</Industries>
5928<Exports>$20.9 billion (f.o.b., 1999)</Exports>
5929<Imports>$11.8 billion (f.o.b., 1999)</Imports>
5930<Currency>1 bolivar (Bs) = 100 centimos</Currency>
5931<Airports>366 (1999 est.)</Airports>
5932<Illicitdrugs>illicit producer of opium for the international drug trade on a small scale; however, large quantities of cocaine and heroin transit the country from Colombia bound for US and Europe; important money-laundering hub; active eradication program primarily targeting opium; increasing signs of drug-related activities by Colombian insurgents on border</Illicitdrugs>
5933</record>
5934<record>
5935<Location>Caribbean, between the Caribbean Sea and the North Atlantic Ocean, east of Puerto Rico</Location>
5936<Geographiccoordinates>18 30 N, 64 30 W</Geographiccoordinates>
5937<Area>150</Area>
5938<Climate>subtropical; humid; temperatures moderated by trade winds</Climate>
5939<Naturalresources>NEGL</Naturalresources>
5940<Population>19615</Population>
5941<Populationgrowthrate>2.34% (2000 est.)</Populationgrowthrate>
5942<Sexratio>
5943at birth: 1.05 male(s)/female
5944under 15 years: 1.02 male(s)/female
594515-64 years: 1.06 male(s)/female
594665 years and over: 1.2 male(s)/female
5947total population: 1.06 male(s)/female (2000 est.)</Sexratio>
5948<Religions>Protestant 86% (Methodist 45%, Anglican 21%, Church of God 7%, Seventh-Day Adventist 5%, Baptist 4%, Jehovah's Witnesses 2%, other 2%), Roman Catholic 6%, none 2%, other 6% (1981)</Religions>
5949<Countryname>British Virgin Islands </Countryname>
5950<Capital>Road Town</Capital>
5951<Flagdescription>blue, with the flag of the UK in the upper hoist-side quadrant and the Virgin Islander coat of arms centered in the outer half of the flag; the coat of arms depicts a woman flanked on either side by a vertical column of six oil lamps above a scroll bearing the Latin word VIGILATE (Be Watchful)</Flagdescription>
5952<GDP>purchasing power parity - $287 million (1999 est.)</GDP>
5953<Industries>tourism, light industry, construction, rum, concrete block, offshore financial center</Industries>
5954<Exports>$6 million (1998)</Exports>
5955<Imports>$175 million (1998)</Imports>
5956<Currency>1 United States dollar (US$) = 100 cents</Currency>
5957<Airports>3 (1999 est.)</Airports>
5958</record>
5959<record>
5960<Location>Southeastern Asia, bordering the Gulf of Thailand, Gulf of Tonkin, and South China Sea, alongside China, Laos, and Cambodia</Location>
5961<Geographiccoordinates>16 00 N, 106 00 E</Geographiccoordinates>
5962<Area>329560</Area>
5963<Climate>tropical in south; monsoonal in north with hot, rainy season (mid-May to mid-September) and warm, dry season (mid-October to mid-March)</Climate>
5964<Naturalresources>phosphates, coal, manganese, bauxite, chromate, offshore oil and gas deposits, forests, hydropower</Naturalresources>
5965<Population>78773873</Population>
5966<Populationgrowthrate>1.49% (2000 est.)</Populationgrowthrate>
5967<Sexratio>
5968at birth: 1.06 male(s)/female
5969under 15 years: 1.07 male(s)/female
597015-64 years: 0.95 male(s)/female
597165 years and over: 0.66 male(s)/female
5972total population: 0.97 male(s)/female (2000 est.)</Sexratio>
5973<Religions>Buddhist, Taoist, Roman Catholic, indigenous beliefs, Muslim, Protestant, Cao Dai, Hoa Hao</Religions>
5974<Countryname>Vietnam </Countryname>
5975<Capital>Hanoi</Capital>
5976<Flagdescription>red with a large yellow five-pointed star in the center</Flagdescription>
5977<GDP>purchasing power parity - $143.1 billion (1999 est.)</GDP>
5978<Industries>food processing, garments, shoes, machine building, mining, cement, chemical fertilizer, glass, tires, oil, coal, steel, paper</Industries>
5979<Exports>$11.5 billion (f.o.b., 1999 est.)</Exports>
5980<Imports>$11.6 billion (f.o.b., 1999 est.)</Imports>
5981<Currency>1 new dong (D) = 100 xu</Currency>
5982<Airports>48 (1999 est.)</Airports>
5983<Illicitdrugs>minor producer of opium poppy with 2,100 hectares cultivated in 1999, capable of producing 11 metric tons of opium; probably minor transit point for Southeast Asian heroin destined for the US and Europe; growing opium/heroin addiction; possible small-scale heroin production</Illicitdrugs>
5984</record>
5985<record>
5986<Location>Caribbean, islands between the Caribbean Sea and the North Atlantic Ocean, east of Puerto Rico</Location>
5987<Geographiccoordinates>18 20 N, 64 50 W</Geographiccoordinates>
5988<Area>352</Area>
5989<Climate>subtropical, tempered by easterly trade winds, relatively low humidity, little seasonal temperature variation; rainy season May to November</Climate>
5990<Naturalresources>sun, sand, sea, surf</Naturalresources>
5991<Population>120917</Population>
5992<Populationgrowthrate>1.07% (2000 est.)</Populationgrowthrate>
5993<Sexratio>
5994at birth: 1.06 male(s)/female
5995under 15 years: 1.06 male(s)/female
599615-64 years: 0.83 male(s)/female
599765 years and over: 0.76 male(s)/female
5998total population: 0.88 male(s)/female (2000 est.)</Sexratio>
5999<Religions>Baptist 42%, Roman Catholic 34%, Episcopalian 17%, other 7%</Religions>
6000<Countryname>Virgin Islands </Countryname>
6001<Capital>Charlotte Amalie</Capital>
6002<Flagdescription>white, with a modified US coat of arms in the center between the large blue initials V and I; the coat of arms shows a yellow eagle holding an olive branch in one talon and three arrows in the other with a superimposed shield of vertical red and white stripes below a blue panel</Flagdescription>
6003<GDP>purchasing power parity - $1.8 billion (1999 est.)</GDP>
6004<Industries>tourism, petroleum refining, watch assembly, rum distilling, construction, pharmaceuticals, textiles, electronics</Industries>
6005<Exports>$NA</Exports>
6006<Imports>$NA</Imports>
6007<Currency>1 United States dollar (US$) = 100 cents</Currency>
6008<Airports>2
6009note: international airports on Saint Thomas and Saint Croix (1999 est.)</Airports>
6010</record>
6011<record>
6012<Location>Southern Europe, an enclave of Rome (Italy)</Location>
6013<Geographiccoordinates>41 54 N, 12 27 E</Geographiccoordinates>
6014<Area>0</Area>
6015<Climate>temperate; mild, rainy winters (September to mid-May) with hot, dry summers (May to September)</Climate>
6016<Naturalresources>none</Naturalresources>
6017<Population>880</Population>
6018<Populationgrowthrate>1.15% (2000 est.)</Populationgrowthrate>
6019<Religions>Roman Catholic</Religions>
6020<Countryname>Holy See (Vatican City) </Countryname>
6021<Capital>Vatican City</Capital>
6022<Flagdescription>two vertical bands of yellow (hoist side) and white with the crossed keys of Saint Peter and the papal miter centered in the white band</Flagdescription>
6023<Industries>printing and production of a small amount of mosaics and staff uniforms; worldwide banking and financial activities</Industries>
6024<Currency>1 Vatican lira (VLit) = 100 centesimi</Currency>
6025<Airports>none</Airports>
6026</record>
6027<record>
6028<Location>Southern Africa, bordering the South Atlantic Ocean, between Angola and South Africa</Location>
6029<Geographiccoordinates>22 00 S, 17 00 E</Geographiccoordinates>
6030<Area>825418</Area>
6031<Climate>desert; hot, dry; rainfall sparse and erratic</Climate>
6032<Naturalresources>diamonds, copper, uranium, gold, lead, tin, lithium, cadmium, zinc, salt, vanadium, natural gas, hydropower, fish
6033note: suspected deposits of oil, coal, and iron ore</Naturalresources>
6034<Population>1771327</Population>
6035<Populationgrowthrate>1.57% (2000 est.)</Populationgrowthrate>
6036<Sexratio>
6037at birth: 1.03 male(s)/female
6038under 15 years: 1.03 male(s)/female
603915-64 years: 0.99 male(s)/female
604065 years and over: 0.76 male(s)/female
6041total population: 0.99 male(s)/female (2000 est.)</Sexratio>
6042<Religions>Christian 80% to 90% (Lutheran 50% at least), indigenous beliefs 10% to 20%</Religions>
6043<Countryname>Namibia </Countryname>
6044<Capital>Windhoek</Capital>
6045<Flagdescription>a large blue triangle with a yellow sunburst fills the upper left section and an equal green triangle (solid) fills the lower right section; the triangles are separated by a red stripe that is contrasted by two narrow white-edge borders</Flagdescription>
6046<GDP>purchasing power parity - $7.1 billion (1999 est.)</GDP>
6047<Industries>meat packing, fish processing, dairy products; mining (diamond, lead, zinc, tin, silver, tungsten, uranium, copper)</Industries>
6048<Exports>$1.4 billion (f.o.b., 1999 est.)</Exports>
6049<Imports>$1.5 billion (f.o.b., 1999 est.)</Imports>
6050<Currency>1 Namibian dollar (N$) = 100 cents</Currency>
6051<Airports>135 (1999 est.)</Airports>
6052</record>
6053<record>
6054<Location>Middle East, west of Jordan</Location>
6055<Geographiccoordinates>32 00 N, 35 15 E</Geographiccoordinates>
6056<Area>5860</Area>
6057<Climate>temperate, temperature and precipitation vary with altitude, warm to hot summers, cool to mild winters</Climate>
6058<Naturalresources>arable land</Naturalresources>
6059<Population>2020298</Population>
6060<Populationgrowthrate>3.38% (2000 est.)</Populationgrowthrate>
6061<Sexratio>
6062at birth: 1.05 male(s)/female
6063under 15 years: 1.05 male(s)/female
606415-64 years: 1.04 male(s)/female
606565 years and over: 0.78 male(s)/female
6066total population: 1.03 male(s)/female (2000 est.)</Sexratio>
6067<Religions>Muslim 75% (predominantly Sunni), Jewish 17%, Christian and other 8%</Religions>
6068<Countryname>West Bank </Countryname>
6069<GDP>purchasing power parity - $3.3 billion (1999 est.)</GDP>
6070<Industries>generally small family businesses that produce cement, textiles, soap, olive-wood carvings, and mother-of-pearl souvenirs; the Israelis have established some small-scale, modern industries in the settlements and industrial centers</Industries>
6071<Exports>$682 million (includes Gaza Strip) (f.o.b., 1998 est.)</Exports>
6072<Imports>$2.5 billion (includes Gaza Strip) (c.i.f., 1998 est.)</Imports>
6073<Currency>1 new Israeli shekel (NIS) = 100 new agorot; 1 Jordanian dinar (JD) = 1,000 fils</Currency>
6074<Airports>2 (1999 est.)</Airports>
6075</record>
6076<record>
6077<Location>Oceania, islands in the South Pacific Ocean, about two-thirds of the way from Hawaii to New Zealand</Location>
6078<Geographiccoordinates>13 18 S, 176 12 W</Geographiccoordinates>
6079<Area>274</Area>
6080<Climate>tropical; hot, rainy season (November to April); cool, dry season (May to October); rains 2,500-3,000 mm per year (80% humidity); average temperature 26.6 degrees C</Climate>
6081<Naturalresources>NEGL</Naturalresources>
6082<Population>15283</Population>
6083<Populationgrowthrate>NA%</Populationgrowthrate>
6084<Religions>Roman Catholic 100%</Religions>
6085<Countryname>Wallis and Futuna </Countryname>
6086<Capital>Mata-Utu (on Ile Uvea)</Capital>
6087<Flagdescription>a large white modified Maltese cross centered on a red background; the flag of France outlined in white on two sides is in the upper hoist quadrant; the flag of France is used for official occasions</Flagdescription>
6088<GDP>purchasing power parity - $28.7 million (1995 est.)</GDP>
6089<Industries>copra, handicrafts, fishing, lumber</Industries>
6090<Exports>$370,000 (f.o.b., 1995 est.)</Exports>
6091<Imports>$13.5 million (c.i.f., 1995 est.)</Imports>
6092<Currency>1 Comptoirs Francais du Pacifique franc (CFPF) = 100 centimes</Currency>
6093<Airports>2 (1999 est.)</Airports>
6094</record>
6095<record>
6096<Location>Northern Africa, bordering the North Atlantic Ocean, between Mauritania and Morocco</Location>
6097<Geographiccoordinates>24 30 N, 13 00 W</Geographiccoordinates>
6098<Area>266000</Area>
6099<Climate>hot, dry desert; rain is rare; cold offshore air currents produce fog and heavy dew</Climate>
6100<Naturalresources>phosphates, iron ore</Naturalresources>
6101<Population>244943</Population>
6102<Populationgrowthrate>2.29% (2000 est.)</Populationgrowthrate>
6103<Religions>Muslim</Religions>
6104<Countryname>Western Sahara </Countryname>
6105<Capital>none</Capital>
6106<GDP>purchasing power parity - $NA</GDP>
6107<Industries>phosphate mining, handicrafts</Industries>
6108<Exports>$NA</Exports>
6109<Imports>$NA</Imports>
6110<Currency>1 Moroccan dirham (DH) = 100 centimes</Currency>
6111<Airports>12 (1999 est.)</Airports>
6112</record>
6113<record>
6114<Location>Oceania, atoll in the North Pacific Ocean, about two-thirds of the way from Hawaii to the Northern Mariana Islands</Location>
6115<Geographiccoordinates>19 17 N, 166 36 E</Geographiccoordinates>
6116<Area>6</Area>
6117<Climate>tropical</Climate>
6118<Naturalresources>none</Naturalresources>
6119<Population></Population>
6120<Countryname>Wake Island </Countryname>
6121<Flagdescription>the flag of the US is used</Flagdescription>
6122<Airports>1 (1999 est.)</Airports>
6123</record>
6124<record>
6125<Location>Oceania, group of islands in the South Pacific Ocean, about one-half of the way from Hawaii to New Zealand</Location>
6126<Geographiccoordinates>13 35 S, 172 20 W</Geographiccoordinates>
6127<Area>2860</Area>
6128<Climate>tropical; rainy season (October to March), dry season (May to October)</Climate>
6129<Naturalresources>hardwood forests, fish, hydropower</Naturalresources>
6130<Population>179466</Population>
6131<Populationgrowthrate>-0.22% (2000 est.)</Populationgrowthrate>
6132<Sexratio>
6133at birth: 1.05 male(s)/female
6134under 15 years: 1.03 male(s)/female
613515-64 years: 1.72 male(s)/female
613665 years and over: 0.88 male(s)/female
6137total population: 1.39 male(s)/female (2000 est.)</Sexratio>
6138<Religions>Christian 99.7% (about one-half of population associated with the London Missionary Society; includes Congregational, Roman Catholic, Methodist, Latter-Day Saints, Seventh-Day Adventist)</Religions>
6139<Countryname>Samoa </Countryname>
6140<Capital>Apia</Capital>
6141<Flagdescription>red with a blue rectangle in the upper hoist-side quadrant bearing five white five-pointed stars representing the Southern Cross constellation</Flagdescription>
6142<GDP>purchasing power parity - $485 million (1998 est.)</GDP>
6143<Industries>timber, tourism, food processing, fishing</Industries>
6144<Exports>$20.3 million (f.o.b., 1998)</Exports>
6145<Imports>$96.6 million (f.o.b., 1998)</Imports>
6146<Currency>1 tala (WS$) = 100 sene</Currency>
6147<Airports>3 (1999 est.)</Airports>
6148</record>
6149<record>
6150<Location>Southern Africa, between Mozambique and South Africa</Location>
6151<Geographiccoordinates>26 30 S, 31 30 E</Geographiccoordinates>
6152<Area>17363</Area>
6153<Climate>varies from tropical to near temperate</Climate>
6154<Naturalresources>asbestos, coal, clay, cassiterite, hydropower, forests, small gold and diamond deposits, quarry stone, and talc</Naturalresources>
6155<Population>1083289</Population>
6156<Populationgrowthrate>2.02% (2000 est.)</Populationgrowthrate>
6157<Sexratio>
6158at birth: 1.03 male(s)/female
6159under 15 years: 0.99 male(s)/female
616015-64 years: 0.93 male(s)/female
616165 years and over: 0.7 male(s)/female
6162total population: 0.95 male(s)/female (2000 est.)</Sexratio>
6163<Religions>Christian 60%, indigenous beliefs 40%</Religions>
6164<Countryname>Swaziland </Countryname>
6165<Capital>Mbabane; note - Lobamba is the royal and legislative capital</Capital>
6166<Flagdescription>three horizontal bands of blue (top), red (triple width), and blue; the red band is edged in yellow; centered in the red band is a large black and white shield covering two spears and a staff decorated with feather tassels, all placed horizontally</Flagdescription>
6167<GDP>purchasing power parity - $4.2 billion (1999 est.)</GDP>
6168<Industries>mining (coal and asbestos), wood pulp, sugar, soft drink concentrates</Industries>
6169<Exports>$825 million (f.o.b., 1999)</Exports>
6170<Imports>$1.05 billion (f.o.b., 1999)</Imports>
6171<Currency>1 lilangeni (E) = 100 cents</Currency>
6172<Airports>18 (1999 est.)</Airports>
6173</record>
6174<record>
6175<Location>body of water between Africa, the Southern Ocean, Asia, and Australia</Location>
6176<Geographiccoordinates>20 00 S, 80 00 E</Geographiccoordinates>
6177<Area>68000000</Area>
6178<Climate>northeast monsoon (December to April), southwest monsoon (June to October); tropical cyclones occur during May/June and October/November in the northern Indian Ocean and January/February in the southern Indian Ocean</Climate>
6179<Naturalresources>oil and gas fields, fish, shrimp, sand and gravel aggregates, placer deposits, polymetallic nodules</Naturalresources>
6180</record>
6181<record>
6182<Location>body of water mostly north of the Arctic Circle</Location>
6183<Geographiccoordinates>90 00 N, 0 00 E</Geographiccoordinates>
6184<Area>14000000</Area>
6185<Climate>polar climate characterized by persistent cold and relatively narrow annual temperature ranges; winters characterized by continuous darkness, cold and stable weather conditions, and clear skies; summers characterized by continuous daylight, damp and foggy weather, and weak cyclones with rain or snow</Climate>
6186<Naturalresources>sand and gravel aggregates, placer deposits, polymetallic nodules, oil and gas fields, fish, marine mammals (seals and whales)</Naturalresources>
6187</record>
6188<record>
6189<Location>Middle East, bordering the Arabian Sea, Gulf of Aden, and Red Sea, between Oman and Saudi Arabia</Location>
6190<Geographiccoordinates>15 00 N, 48 00 E</Geographiccoordinates>
6191<Area>527970</Area>
6192<Climate>mostly desert; hot and humid along west coast; temperate in western mountains affected by seasonal monsoon; extraordinarily hot, dry, harsh desert in east</Climate>
6193<Naturalresources>petroleum, fish, rock salt, marble, small deposits of coal, gold, lead, nickel, and copper, fertile soil in west</Naturalresources>
6194<Population>17479206</Population>
6195<Populationgrowthrate>3.36% (2000 est.)</Populationgrowthrate>
6196<Sexratio>
6197at birth: 1.05 male(s)/female
6198under 15 years: 1.04 male(s)/female
619915-64 years: 1.05 male(s)/female
620065 years and over: 1.04 male(s)/female
6201total population: 1.04 male(s)/female (2000 est.)</Sexratio>
6202<Religions>Muslim including Shaf'i (Sunni) and Zaydi (Shi'a), small numbers of Jewish, Christian, and Hindu</Religions>
6203<Countryname>Yemen </Countryname>
6204<Capital>Sanaa</Capital>
6205<Flagdescription>three equal horizontal bands of red (top), white, and black; similar to the flag of Syria which has two green stars and of Iraq which has three green stars (plus an Arabic inscription) in a horizontal line centered in the white band; also similar to the flag of Egypt which has a heraldic eagle centered in the white band</Flagdescription>
6206<GDP>purchasing power parity - $12.7 billion (1999 est.)</GDP>
6207<Industries>crude oil production and petroleum refining; small-scale production of cotton textiles and leather goods; food processing; handicrafts; small aluminum products factory; cement</Industries>
6208<Exports>$2 billion (f.o.b., 1999 est.)</Exports>
6209<Imports>$2.3 billion (f.o.b., 1999 est.)</Imports>
6210<Currency>Yemeni rial (YER) = 100 fils</Currency>
6211<Airports>50 (1999 est.)</Airports>
6212</record>
6213<record>
6214<Location>Southern Africa, east of Angola</Location>
6215<Geographiccoordinates>15 00 S, 30 00 E</Geographiccoordinates>
6216<Area>752614</Area>
6217<Climate>tropical; modified by altitude; rainy season (October to April)</Climate>
6218<Naturalresources>copper, cobalt, zinc, lead, coal, emeralds, gold, silver, uranium, hydropower</Naturalresources>
6219<Population>9582418</Population>
6220<Populationgrowthrate>1.95% (2000 est.)</Populationgrowthrate>
6221<Sexratio>
6222at birth: 1.03 male(s)/female
6223under 15 years: 1.01 male(s)/female
622415-64 years: 0.98 male(s)/female
622565 years and over: 0.79 male(s)/female
6226total population: 0.99 male(s)/female (2000 est.)</Sexratio>
6227<Religions>Christian 50%-75%, Muslim and Hindu 24%-49%, indigenous beliefs 1%</Religions>
6228<Countryname>Zambia </Countryname>
6229<Capital>Lusaka</Capital>
6230<Flagdescription>green with a panel of three vertical bands of red (hoist side), black, and orange below a soaring orange eagle, on the outer edge of the flag</Flagdescription>
6231<GDP>purchasing power parity - $8.5 billion (1999 est.)</GDP>
6232<Industries>copper mining and processing, construction, foodstuffs, beverages, chemicals, textiles, fertilizer</Industries>
6233<Exports>$900 million (f.o.b., 1999 est.)</Exports>
6234<Imports>$1.15 billion (f.o.b., 1999 est.)</Imports>
6235<Currency>1 Zambian kwacha (ZK) = 100 ngwee</Currency>
6236<Airports>112 (1999 est.)</Airports>
6237<Illicitdrugs>transshipment point for methaqualone, heroin, and cocaine bound for Southern Africa and Europe; regional money-laundering center</Illicitdrugs>
6238</record>
6239<record>
6240<Location>body of water between Africa, Europe, the Southern Ocean, and the Western Hemisphere</Location>
6241<Geographiccoordinates>0 00 N, 25 00 W</Geographiccoordinates>
6242<Area>76000000</Area>
6243<Climate>tropical cyclones (hurricanes) develop off the coast of Africa near Cape Verde and move westward into the Caribbean Sea; hurricanes can occur from May to December, but are most frequent from August to November</Climate>
6244<Naturalresources>oil and gas fields, fish, marine mammals (seals and whales), sand and gravel aggregates, placer deposits, polymetallic nodules, precious stones</Naturalresources>
6245</record>
6246<record>
6247<Location>Southern Africa, between South Africa and Zambia</Location>
6248<Geographiccoordinates>20 00 S, 30 00 E</Geographiccoordinates>
6249<Area>390580</Area>
6250<Climate>tropical; moderated by altitude; rainy season (November to March)</Climate>
6251<Naturalresources>coal, chromium ore, asbestos, gold, nickel, copper, iron ore, vanadium, lithium, tin, platinum group metals</Naturalresources>
6252<Population>11342521</Population>
6253<Populationgrowthrate>0.26% (2000 est.)</Populationgrowthrate>
6254<Sexratio>
6255at birth: 1.03 male(s)/female
6256under 15 years: 1.02 male(s)/female
625715-64 years: 1.02 male(s)/female
625865 years and over: 1.03 male(s)/female
6259total population: 1.02 male(s)/female (2000 est.)</Sexratio>
6260<Religions>syncretic (part Christian, part indigenous beliefs) 50%, Christian 25%, indigenous beliefs 24%, Muslim and other 1%</Religions>
6261<Countryname>Zimbabwe </Countryname>
6262<Capital>Harare</Capital>
6263<Flagdescription>seven equal horizontal bands of green, yellow, red, black, red, yellow, and green with a white isosceles triangle edged in black with its base on the hoist side; a yellow Zimbabwe bird is superimposed on a red five-pointed star in the center of the triangle</Flagdescription>
6264<GDP>purchasing power parity - $26.5 billion (1999 est.)</GDP>
6265<Industries>mining (coal, gold, copper, nickel, tin, clay, numerous metallic and nonmetallic ores), steel, wood products, cement, chemicals, fertilizer, clothing and footwear, foodstuffs, beverages</Industries>
6266<Exports>$2 billion (f.o.b., 1999 est.)</Exports>
6267<Imports>$2 billion (f.o.b., 1998 est.)</Imports>
6268<Currency>1 Zimbabwean dollar (Z$) = 100 cents</Currency>
6269<Airports>459 (1999 est.)</Airports>
6270<Illicitdrugs>significant transit point for African cannabis and South Asian heroin, mandrax, and methamphetamines destined for the South African and European markets</Illicitdrugs>
6271</record>
6272<record>
6273<Location>body of water between the Southern Ocean, Asia, Australia, and the Western Hemisphere</Location>
6274<Geographiccoordinates>0 00 N, 160 00 W</Geographiccoordinates>
6275<Area>155000000</Area>
6276<Climate>planetary air pressure systems and resultant wind patterns exhibit remarkable uniformity in the south and east; trade winds and westerly winds are well-developed patterns, modified by seasonal fluctuations; tropical cyclones (hurricanes) may form south of Mexico from June to October and affect Mexico and Central America; continental influences cause climatic uniformity to be much less pronounced in the eastern and western regions at the same latitude in the North Pacific Ocean; the western Pacific is monsoonal - a rainy season occurs during the summer months, when moisture-laden winds blow from the ocean over the land, and a dry season during the winter months, when dry winds blow from the Asian landmass back to the ocean; tropical cyclones (typhoons) may strike southeast and east Asia from May to December</Climate>
6277<Naturalresources>oil and gas fields, polymetallic nodules, sand and gravel aggregates, placer deposits, fish</Naturalresources>
6278</record>
6279</database>
diff --git a/noncore/apps/tableviewer/db/.cvsignore b/noncore/apps/tableviewer/db/.cvsignore
new file mode 100644
index 0000000..a433295
--- a/dev/null
+++ b/noncore/apps/tableviewer/db/.cvsignore
@@ -0,0 +1,3 @@
1moc_*
2Makefile
3
diff --git a/noncore/apps/tableviewer/db/common.cpp b/noncore/apps/tableviewer/db/common.cpp
new file mode 100644
index 0000000..4c70e54
--- a/dev/null
+++ b/noncore/apps/tableviewer/db/common.cpp
@@ -0,0 +1,1470 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <stdlib.h>
21#include <qstring.h>
22#include <qheader.h>
23#include <qvector.h>
24#include <qdatetime.h>
25#include <timestring.h>
26#include "common.h"
27#include "datacache.h"
28#include <assert.h>
29
30static const int del_flag = 0x1;
31static const int new_flag = 0x2;
32
33/* Helper function */
34
35int parseNextNumber(QString *q) {
36 QChar c;
37 uint i;
38 int result = 0;
39
40 bool found_digits = FALSE;
41 for(i = 0; i < q->length(); i++) {
42 c = q->at(i);
43 if (c.isDigit()) {
44 if (found_digits)
45 result *= 10;
46 found_digits = TRUE;
47 result += c.digitValue();
48 } else {
49 if (found_digits)
50 break;
51 /* just skip this char */
52 }
53 }
54 /* now truncate q */
55 if (found_digits)
56 q->remove(0, i);
57 return result;
58}
59
60/*!
61 \class QStringVector
62 \brief A Vector of QStrings that can be sorted and searched
63
64 Implmented in order to allow reverse lookup on the string name
65
66*/
67
68/*!
69 This function implements the compare function in order to allow the
70 searching and sorting of the QStringVector to occur
71
72 \returns an int which is either
73 <UL>
74 <LI> < 0 if the first string is smaller than the second,</LI>
75 <LI> > 0 if the first string is bigger then the second,</LI>
76 <LI> == 0 if the first string is equal to the second.</LI>
77 </UL>
78*/
79int QStringVector::compareItems(Item a, Item b)
80{
81 QString *qa = (QString *)a;
82 QString *qb = (QString *)b;
83
84 return QString::compare(*qa, *qb);
85}
86
87/*!
88 \class TVVariant
89 A way of abstracting void * and keeping information on
90 the keytypes and behaviours in one place
91*/
92
93TVVariantPrivate::TVVariantPrivate()
94{
95 typ = TVVariant::Invalid;
96}
97
98TVVariantPrivate::TVVariantPrivate( TVVariantPrivate *d)
99{
100 switch(d->typ)
101 {
102 case TVVariant::Invalid:
103 break;
104 case TVVariant::String:
105 value.ptr = new QString(*((QString *)d->value.ptr));
106 break;
107 case TVVariant::Date:
108 value.ptr = new QDate(*((QDate *)d->value.ptr));
109 break;
110 case TVVariant::Time:
111 value.ptr = new QTime(*((QTime *)d->value.ptr));
112 break;
113 case TVVariant::Int:
114 value.i = d->value.i;
115 break;
116 default:
117 ASSERT( 0 );
118 }
119
120 typ = d->typ;
121}
122
123TVVariantPrivate::~TVVariantPrivate()
124{
125 clear();
126}
127
128void TVVariantPrivate::clear()
129{
130 switch( typ )
131 {
132 case TVVariant::String:
133 delete (QString *)value.ptr;
134 break;
135 case TVVariant::Date:
136 delete (QDate *)value.ptr;
137 break;
138 case TVVariant::Time:
139 delete (QTime *)value.ptr;
140 break;
141 case TVVariant::Invalid:
142 case TVVariant::Int:
143 break;
144 }
145
146 typ = TVVariant::Invalid;
147}
148
149/*!
150 \class TVVariant
151 blah
152*/
153
154TVVariant::TVVariant()
155{
156 d = new TVVariantPrivate;
157}
158
159TVVariant::~TVVariant()
160{
161 if (d->deref())
162 delete d;
163}
164
165TVVariant::TVVariant(const TVVariant& p)
166{
167 d = new TVVariantPrivate;
168 *this = p;
169}
170
171TVVariant::TVVariant(QDataStream& s)
172{
173 d = new TVVariantPrivate;
174 s >> *this;
175}
176
177TVVariant::TVVariant(const QString &val)
178{
179 d = new TVVariantPrivate;
180 d->typ = String;
181 d->value.ptr = new QString(val);
182}
183
184TVVariant::TVVariant(const QDate &val)
185{
186 d = new TVVariantPrivate;
187 d->typ = Date;
188 d->value.ptr = new QDate(val);
189}
190
191TVVariant::TVVariant(const QTime &val)
192{
193 d = new TVVariantPrivate;
194 d->typ = Time;
195 d->value.ptr = new QTime(val);
196}
197
198TVVariant::TVVariant( int val )
199{
200 d = new TVVariantPrivate;
201 d->typ = Int;
202 d->value.i = val;
203}
204
205TVVariant& TVVariant::operator=(const TVVariant& variant )
206{
207 TVVariant& other = (TVVariant&) variant;
208
209 other.d->ref();
210 if ( d->deref() )
211 delete d;
212
213 d = other.d;
214
215 return *this;
216}
217
218void TVVariant::detach()
219{
220 if (d->count == 1)
221 return;
222
223 d->deref();
224 d = new TVVariantPrivate(d);
225}
226
227const QString TVVariant::typeName() const
228{
229 return typeToName(d->typ);
230}
231
232void TVVariant::clear()
233{
234 if (d->count > 1)
235 {
236 d->deref();
237 d = new TVVariantPrivate;
238 return;
239 }
240
241 d->clear();
242}
243
244const QString TVVariant::typeToName(KeyType typ)
245{
246 switch(typ) {
247 case String:
248 return QString("String");
249 case Date:
250 return QString("Date");
251 case Time:
252 return QString("Time");
253 case Int:
254 return QString("Int");
255 case Invalid:
256 default:
257 return QString("Invalid");
258 }
259 return QString("Invalid");
260}
261
262TVVariant::KeyType TVVariant::nameToType(const QString &name)
263{
264 if(!qstrcmp("String", name))
265 return String;
266 if(!qstrcmp("Date", name))
267 return Date;
268 if(!qstrcmp("Time", name))
269 return Time;
270 if(!qstrcmp("Int", name))
271 return Int;
272
273 return Invalid;
274}
275
276void TVVariant::load(QDataStream &s )
277{
278 KeyType t;
279 s >> t;
280
281 d->typ = t;
282 switch(t) {
283 case Invalid:
284 d->typ = t;
285 break;
286 case String:
287 {
288 QString *x = new QString;
289 s >> *x;
290 d->value.ptr = x;
291 }
292 break;
293 case Time:
294 {
295 QTime *x = new QTime;
296 s >> *x;
297 d->value.ptr = x;
298 }
299 break;
300 case Date:
301 {
302 QDate *x = new QDate;
303 s >> *x;
304 d->value.ptr = x;
305 }
306 break;
307 case Int:
308 {
309 int x;
310 s >> x;
311 d->value.i = x;
312 }
313 break;
314 default:
315 qFatal("Unrecognized data type");
316 }
317}
318
319void TVVariant::save( QDataStream &s ) const
320{
321 s << type();
322
323 switch( d->typ ) {
324 case String:
325 s << *((QString *)d->value.ptr);
326 break;
327 case Date:
328 s << *((QDate *)d->value.ptr);
329 break;
330 case Time:
331 s << *((QTime *)d->value.ptr);
332 break;
333 case Int:
334 s << d->value.i;
335 break;
336 case Invalid:
337 break;
338 }
339}
340
341QDataStream& operator>>(QDataStream& s, TVVariant& p)
342{
343 p.load( s );
344 return s;
345}
346
347QDataStream& operator<<(QDataStream &s, const TVVariant& p)
348{
349 p.save( s );
350 return s;
351}
352
353QDataStream& operator>> (QDataStream &s, TVVariant::KeyType& p)
354{
355 Q_UINT8 u = 0;
356 s >> u;
357 p = (TVVariant::KeyType) u;
358
359 return s;
360}
361
362QDataStream& operator<< (QDataStream& s, const TVVariant::KeyType& p)
363{
364 s << (Q_UINT8)p;
365 return s;
366}
367
368const QString TVVariant::toString() const
369{
370 switch(d->typ) {
371 case String:
372 return *((QString*)d->value.ptr);
373 case Date:
374 return ((QDate*)d->value.ptr)->toString();
375 case Time:
376 return ((QTime*)d->value.ptr)->toString();
377 case Int:
378 return QString::number(d->value.i);
379 case Invalid:
380 default:
381 return QString::null;
382 }
383 return QString::null;
384}
385
386// TODO DO, this properly, */
387int TVVariant::toInt() const
388{
389 if(d->typ == Int)
390 return d->value.i;
391
392 if(d->typ == String) {
393 QString tmpq(*(QString *)d->value.ptr);
394 return parseNextNumber(&tmpq);
395 }
396
397 return 0;
398}
399
400const QDate TVVariant::toDate() const
401{
402 if(d->typ == Date)
403 return *((QDate *)d->value.ptr);
404
405 if(d->typ == String) {
406 QString q = toString();
407
408 /* date format is day mon d yyyy */
409 /* ignore the first three letters, read the next
410 three for month.. etc */
411
412 int day = parseNextNumber(&q);
413 int month = parseNextNumber(&q);
414 int year = parseNextNumber(&q);
415 if (!QDate::isValid(year, month, day))
416 return QDate();
417 return QDate(year, month, day);
418 }
419
420
421 return QDate();
422}
423
424const QTime TVVariant::toTime() const
425{
426 if(d->typ == Time)
427 return *((QTime *)d->value.ptr);
428
429 if(d->typ == String) {
430 QString q = toString();
431 int hour = parseNextNumber(&q);
432 int minute = parseNextNumber(&q);
433 int second = parseNextNumber(&q);
434 int msecond = parseNextNumber(&q);
435 if (!QTime::isValid(hour, minute, second, msecond))
436 return QTime();
437 return QTime(hour, minute, second, msecond);
438 }
439
440 return QTime();
441}
442
443#define TV_VARIANT_AS( f ) Q##f& TVVariant::as##f() { \
444 if ( d->typ != f ) \
445 *this = TVVariant( to##f() ); \
446 else \
447 detach(); \
448 return *((Q##f*)d->value.ptr); }
449
450TV_VARIANT_AS(String)
451TV_VARIANT_AS(Date)
452TV_VARIANT_AS(Time)
453
454#undef TV_VARIANT_AS
455
456int& TVVariant::asInt()
457{
458 detach();
459 if (d->typ != Int) {
460 d->value.i = toInt();
461 d->typ = Int;
462 }
463 return d->value.i;
464}
465
466/*!
467 valid cast is
468 anything to String
469 same to same
470*/
471bool TVVariant::canCast(KeyType t) const
472{
473 if(d->typ == t)
474 return TRUE;
475
476 if(t == String)
477 return TRUE;
478
479 if(t == Int) {
480 if (d->typ == Date)
481 return TRUE;
482 if (d->typ == Time)
483 return TRUE;
484 if (d->typ == String)
485 return TRUE;
486 }
487
488 return FALSE;
489}
490
491bool TVVariant::operator==( const TVVariant &v ) const
492{
493 switch(d->typ) {
494 case String:
495 return v.toString() == toString();
496 case Date:
497 return v.toDate() == toDate();
498 case Time:
499 return v.toTime() == toTime();
500 case Int:
501 return v.toInt() == toInt();
502 case Invalid:
503 break;
504 }
505
506 return FALSE;
507}
508
509bool TVVariant::operator!=( const TVVariant &v ) const
510{
511 return !( v == *this);
512}
513
514bool TVVariant::operator<( const TVVariant &v ) const
515{
516 switch(d->typ) {
517 case String:
518 return toString().lower() < v.toString().lower();
519 case Date:
520 return toDate() < v.toDate();
521 case Time:
522 return toTime() < v.toTime();
523 case Int:
524 return toInt() < v.toInt();
525 case Invalid:
526 default:
527 break;
528 }
529 return FALSE;
530}
531
532bool TVVariant::operator>( const TVVariant &v ) const
533{
534 switch(d->typ) {
535 case String:
536 return toString().lower() > v.toString().lower();
537 case Date:
538 return toDate() > v.toDate();
539 case Time:
540 return toTime() > v.toTime();
541 case Int:
542 return toInt() > v.toInt();
543 case Invalid:
544 default:
545 break;
546 }
547 return FALSE;
548}
549
550/*! True if n is closer to this than o */
551bool TVVariant::closer(TVVariant n, TVVariant o)
552{
553 /* Nothing is close to an invalid, so nothing can be closer */
554 if(d->typ == Invalid)
555 return FALSE;
556
557 /* can't be closer if of different type */
558 if(n.type() != type())
559 return FALSE;
560
561 /* if new shares type, and old doesn't, then new is closer */
562 if(o.type() != type())
563 return TRUE;
564
565 switch(type()){
566 case String: {
567 /* case for strings is close is a substring.. closer is
568 * earlier alphabetically */
569 QString qs1 = n.toString().lower();
570 QString qs2 = o.toString().lower();
571 QString qsv = toString().lower();
572
573 if (!qs1.startsWith(qsv))
574 return FALSE;
575
576 /* contains sub-str, if later than is not closer */
577 if(QString::compare(qs1, qs2) > 0)
578 return FALSE;
579 return TRUE;
580 }
581 case Int: {
582 /* case for int is smallest absolute difference */
583 int i1 = n.toInt();
584 int i2 = o.toInt();
585 int iv = toInt();
586
587 int diff1 = (i1 - iv);
588 if (diff1 < 0)
589 diff1 = -diff1;
590 int diff2 = (i2 - iv);
591 if (diff2 < 0)
592 diff2 = -diff2;
593
594 if (diff1 < diff2)
595 return TRUE;
596 return FALSE;
597 }
598 case Date: {
599 QDate i1 = n.toDate();
600 QDate i2 = o.toDate();
601 QDate iv = toDate();
602
603 /* definition of closer is the least difference in days */
604 int diff1 = i1.daysTo(iv);
605 if (diff1 < 0)
606 diff1 = -diff1;
607 int diff2 = i2.daysTo(iv);
608 if (diff2 < 0)
609 diff2 = -diff2;
610
611 if (diff1 < diff2)
612 return TRUE;
613 return FALSE;
614 }
615 case Time: {
616 QTime i1 = n.toTime();
617 QTime i2 = o.toTime();
618 QTime iv = toTime();
619
620 /* definition of closer is the least difference in days */
621 int diff1 = i1.msecsTo(iv);
622 if (diff1 < 0)
623 diff1 = -diff1;
624 int diff2 = i2.msecsTo(iv);
625 if (diff2 < 0)
626 diff2 = -diff2;
627 if (diff1 < diff2)
628 return TRUE;
629 return FALSE;
630 }
631 default:
632 /* don't know how to do 'closer' on this type, hence never closer
633 * or even close */
634 break;
635 }
636 return FALSE;
637}
638
639/*! True if n is close to this */
640bool TVVariant::close(TVVariant n)
641{
642 /* Nothing is close to an invalid, so nothing can be closer */
643 if(type() == Invalid)
644 return FALSE;
645
646 /* can't be close if of different type */
647 if(n.type() != type())
648 return FALSE;
649
650 switch(type()){
651 case String: {
652 /* case for strings is close is a substring.. closer is
653 * earlier alphabetically */
654 QString qs1 = n.toString().lower();
655 QString qsv = toString().lower();
656
657 if (!qs1.startsWith(qsv))
658 return FALSE;
659 return TRUE;
660 }
661 case Int:
662 case Date:
663 case Time:
664 return TRUE;
665 default:
666 /* don't know how to do 'closer' on this type, hence never closer
667 * or even close */
668 break;
669 }
670 return FALSE;
671}
672
673/*!
674 \class Key
675 \brief document me!
676
677 document me!
678*/
679
680Key::Key() : kname(), kexample(), kflags(0) { }
681
682Key::Key(QString name, TVVariant example, int flags = 0) :
683 kname(name), kexample(example), kflags(flags) { }
684
685Key::Key(const Key &other)
686{
687 kname = other.kname;
688 kexample = other.kexample;
689 kflags = other.kflags;
690}
691
692Key& Key::operator=(const Key& key)
693{
694 kname = key.kname;
695 kexample = key.kexample;
696 kflags = key.kflags;
697 return *this;
698}
699
700QString Key::name() const
701{
702 return QString(kname);
703}
704
705TVVariant Key::example() const
706{
707 return TVVariant(kexample);
708}
709
710TVVariant::KeyType Key::type() const
711{
712 return kexample.type();
713}
714
715void Key::setName(const QString &name)
716{
717 kname = QString(name);
718}
719
720void Key::setExample(const TVVariant &e)
721{
722 kexample = TVVariant(e);
723}
724
725int Key::flags() const
726{
727 return kflags;
728}
729
730void Key::setFlags(int fl)
731{
732 kflags = fl;
733}
734
735bool Key::delFlag() const
736{
737 if(kflags & del_flag)
738 return TRUE;
739 return FALSE;
740}
741
742bool Key::newFlag() const
743{
744 if(kflags & new_flag)
745 return TRUE;
746 return FALSE;
747}
748
749void Key::setDelFlag(bool v)
750{
751 if(delFlag() != v)
752 kflags = kflags ^ del_flag;
753}
754
755void Key::setNewFlag(bool v)
756{
757 if(newFlag() != v)
758 kflags = kflags ^ new_flag;
759}
760
761/*!
762 \class KeyList
763 \brief A represntation of keys used for a table.
764
765 The KeyList class is used to store the representation of keys used in table
766 headings by DBStore. It stores the names and types of the keys
767*/
768
769/*!
770 Constructs a KeyList
771*/
772KeyList::KeyList() : QIntDict<Key>(20)
773{
774 setAutoDelete(TRUE);
775}
776
777/* Should be deep copy, but isn't */
778KeyList::KeyList(const KeyList &k) : QIntDict<Key>(k)
779{
780 KeyListIterator it(k);
781 while(it.current()) {
782 replace(it.currentKey(), new Key(*it.current()));
783 ++it;
784 }
785
786 setAutoDelete(TRUE);
787}
788
789/*!
790 Destroys a KeyList
791*/
792KeyList::~KeyList() {
793}
794
795/* Do a comparision base on Keys */
796bool KeyList::operator!=(const KeyList &other)
797{
798 KeyListIterator it(*this);
799
800 if (other.getNumFields() != getNumFields())
801 return TRUE;
802
803 while(it.current()) {
804 //it.currentKey(), it.current();
805 if (other.getKeyName(it.currentKey()) != getKeyName(it.currentKey()))
806 return TRUE;
807 if (other.getKeyType(it.currentKey()) != getKeyType(it.currentKey()))
808 return TRUE;
809 ++it;
810 }
811 return FALSE;
812}
813
814/*!
815 Returns the number of keys stored in the KeyList
816*/
817int KeyList::getNumFields() const
818{
819 return count();
820}
821
822/*!
823 Adds a new key to the KeyList
824
825 \param name the name of the new key
826 \param type the type of the new key
827*/
828int KeyList::addKey(QString name, TVVariant example)
829{
830 int i = count();
831 while(find(i) && (i > -1))
832 i--;
833 replace(i, new Key(name, example, 0));
834 return i;
835}
836
837int KeyList::addKey(QString name, TVVariant::KeyType type)
838{
839 /* generate a valid type for the example? */
840 TVVariant e = TVVariant("0");
841 switch(type) {
842 case TVVariant::String:
843 return addKey(name, TVVariant("<undefined>").asString());
844 break;
845 case TVVariant::Date:
846 return addKey(name, TVVariant(QDate::currentDate()).asDate());
847 break;
848 case TVVariant::Time:
849 return addKey(name, TVVariant(QTime(0,0,0)).toTime());
850 break;
851 case TVVariant::Int:
852 return addKey(name, TVVariant(0).toInt());
853 break;
854 default:
855 qWarning(QObject::tr("KeyList::addKey() Cannot make default "
856 "value for type %1, Key not added.").arg(type));
857 break;
858 }
859 return -1;
860}
861
862void KeyList::setKeyFlags(int i, int flag)
863{
864 if(find(i))
865 find(i)->setFlags(flag);
866}
867
868int KeyList::getKeyFlags(int i) const
869{
870 if(find(i))
871 return find(i)->flags();
872 return 0;
873}
874
875bool KeyList::checkNewFlag(int i) const
876{
877 if (find(i))
878 return find(i)->newFlag();
879 return false;
880}
881
882void KeyList::setNewFlag(int i, bool f)
883{
884 if(!find(i))
885 return;
886 find(i)->setNewFlag(f);
887}
888
889bool KeyList::checkDeleteFlag(int i) const
890{
891 if (find(i))
892 return find(i)->delFlag();
893 return false;
894}
895
896void KeyList::setDeleteFlag(int i, bool f)
897{
898 if(!find(i))
899 return;
900 find(i)->setDelFlag(f);
901}
902
903/*!
904 Returns the name of the key at index i
905*/
906QString KeyList::getKeyName(int i) const
907{
908 if (find (i))
909 return find(i)->name();
910 return QString();
911}
912
913void KeyList::setKeyName(int i, const QString &n)
914{
915 if(find(i))
916 find(i)->setName(n);
917}
918
919/*!
920 Returns the type of the key at index i
921*/
922TVVariant::KeyType KeyList::getKeyType(int i) const
923{
924 if(find(i))
925 return find(i)->type();
926 return TVVariant::Invalid;
927}
928
929void KeyList::setKeyType(int i, TVVariant::KeyType t)
930{
931 if(!find(i))
932 return;
933 switch(t) {
934 case TVVariant::String:
935 find(i)->setExample(TVVariant(QString("default")));
936 return;
937 case TVVariant::Int:
938 find(i)->setExample(TVVariant(int(0)));
939 return;
940 case TVVariant::Date:
941 find(i)->setExample(TVVariant(QDate::currentDate()));
942 return;
943 case TVVariant::Time:
944 find(i)->setExample(TVVariant(QTime(0,0,0,0)));
945 return;
946 default:
947 break;
948 }
949 return;
950}
951
952TVVariant KeyList::getKeyExample(int i) const
953{
954 if(find(i))
955 return find(i)->example();
956 return TVVariant();
957}
958
959void KeyList::setKeyExample(int i, TVVariant example)
960{
961 if(find(i))
962 find(i)->setExample(example);
963}
964
965/*!
966 Returns the index of the key with name q
967*/
968int KeyList::getKeyIndex(QString q) const
969{
970 KeyListIterator it(*this);
971
972 while(it.current()) {
973 if(it.current()->name() == q)
974 return it.currentKey();
975 ++it;
976 }
977 return -1;
978}
979
980bool KeyList::validIndex(int i) const
981{
982 if(!find(i))
983 return FALSE;
984 if(find(i)->delFlag())
985 return FALSE;
986 return TRUE;
987}
988
989QDataStream &operator<<( QDataStream &s, const KeyList &k)
990{
991 s << k.getNumFields();
992
993 KeyListIterator it(k);
994
995 while(it.current()) {
996 s << (Q_UINT16)it.currentKey();
997 s << it.current()->name();
998 s << it.current()->example();
999 s << (Q_UINT16)it.current()->flags();
1000 ++it;
1001 }
1002 return s;
1003}
1004
1005QDataStream &operator>>( QDataStream &s, KeyList &k)
1006{
1007 int i;
1008 int size;
1009 int index = 0;
1010 int flags = 0;
1011 TVVariant type = TVVariant();
1012 QString name;
1013
1014 s >> size;
1015
1016 for (i=0; i < size; i++) {
1017 s >> (Q_UINT16 &)index;
1018 s >> name;
1019 s >> type;
1020 s >> (Q_UINT16 &)flags;
1021 k.replace(index, new Key(name, type, flags));
1022 }
1023 return s;
1024}
1025
1026/*!
1027 \class DataElem
1028 \brief A class representing a single row or element of a table in a DBStore
1029
1030 This class holds the data of a row in a table.
1031*/
1032
1033
1034/*!
1035 Constructs a DataElem. This function needs a container because the
1036 size, types of keys and primary key are all defined by the containing
1037 database
1038*/
1039DataElem::DataElem(DBStore *c) : values(20)
1040{
1041 int size;
1042 contained = c;
1043 size = c->getNumFields();
1044 values.setAutoDelete(TRUE);
1045}
1046
1047/*!
1048 Destroys a DataElem and frees memory used by the DataElem
1049*/
1050DataElem::~DataElem() {
1051}
1052
1053
1054
1055QDataStream &operator<<( QDataStream &s, const DataElem &d)
1056{
1057 int size = d.getNumFields();
1058
1059 s << size; /* redundent data but makes streaming easier */
1060 KeyList k = d.getKeys();
1061
1062 KeyListIterator it(k);
1063
1064 while(it.current()) {
1065 s << (Q_UINT16)it.currentKey();
1066 s << d.getField(it.currentKey());
1067 ++it;
1068 }
1069 return s;
1070}
1071
1072QDataStream &operator>>( QDataStream &s, DataElem &d)
1073{
1074 int i;
1075 int size;
1076 TVVariant t;
1077 int index = 0;
1078
1079 s >> size; /* redundent data but makes streaming easier */
1080 if (size != d.getNumFields()) {
1081 qWarning("DataSize mis-match");
1082 return s; /* sanity check failed.. don't load */
1083 }
1084
1085 for(i = 0; i < size; i++) {
1086 s >> (Q_UINT16)index;
1087 s >> t;
1088 d.setField(index, t);
1089 }
1090 return s;
1091}
1092
1093/*! Returns the number of possible (not valid) fields in the data element */
1094int DataElem::getNumFields() const
1095{
1096 return contained->getNumFields();
1097}
1098
1099KeyList DataElem::getKeys() const
1100{
1101 return *(contained->getKeys());
1102}
1103
1104/*!
1105 This function determines whether field index i of the element has been
1106 set yet.
1107
1108 \return A boolean value that is TRUE if the specfied field of this
1109 element has been set and FALSE if the field has not yet been set
1110*/
1111bool DataElem::hasValidValue(int i) const
1112{
1113 if(!values.find(i))
1114 return FALSE;
1115 if(!contained->getKeys()->validIndex(i))
1116 return FALSE;
1117 return values.find(i)->isValid();
1118}
1119
1120/*!
1121 This function determines whether field name qs of the element has been
1122 set yet.
1123
1124 \return A boolean value that is TRUE if the specfied field of this
1125 element has been set and FALSE if the field has not yet been set
1126*/
1127bool DataElem::hasValidValue(QString qs) const
1128{
1129 int i = contained->getKeyIndex(qs);
1130 return hasValidValue(i);
1131}
1132
1133/*! returns the type of the field specified by index i */
1134TVVariant::KeyType DataElem::getFieldType(int i) const
1135{
1136 return contained->getKeyType(i);
1137}
1138
1139/*! returns the type of the field specified by name qs */
1140TVVariant::KeyType DataElem::getFieldType(QString qs) const
1141{
1142 int i = contained->getKeyIndex(qs);
1143 return contained->getKeyType(i);
1144}
1145
1146/*!
1147 returns a pointer to the data stored in field index i for this
1148 data element, (value may not be valid)
1149*/
1150TVVariant DataElem::getField(int i) const
1151{
1152 if(hasValidValue(i))
1153 return TVVariant(*values.find(i));
1154 return TVVariant();
1155}
1156
1157/*!
1158 returns a pointer to the data stored in field name qs for this
1159 data element, (value may not be valid)
1160*/
1161TVVariant DataElem::getField(QString qs) const
1162{
1163 int i = contained->getKeyIndex(qs);
1164 return getField(i);
1165}
1166
1167/*!
1168 Sets the value of the elements field index i to the value represented in
1169 the QString q.
1170
1171 \param i index of the field to set
1172 \param q a string that can be parsed to get the value to be set
1173*/
1174void DataElem::setField(int i, QString q)
1175{
1176 /* from the type of the field, parse q and store */
1177 TVVariant::KeyType kt = contained->getKeyType(i);
1178
1179 TVVariant t = TVVariant(q);
1180
1181 switch(kt) {
1182 case TVVariant::Int: {
1183 t.asInt();
1184 setField(i, t);
1185 return;
1186 }
1187 case TVVariant::String: {
1188 t.asString();
1189 setField(i, t);
1190 return;
1191 }
1192 case TVVariant::Date: {
1193 t.asDate();
1194 setField(i, t);
1195 return;
1196 }
1197 case TVVariant::Time: {
1198 t.asTime();
1199 setField(i, t);
1200 return;
1201 }
1202 default:
1203 qWarning(
1204 QObject::tr("DataElem::setField(%1, %2) No valid type found").arg(i).arg(q)
1205 );
1206 }
1207}
1208
1209/*!
1210 Sets the value of the elements field index i to the value at the pointer
1211 value.
1212
1213 \param i index of the field to set
1214 \param value a pointer to the (already allocated) value to set
1215*/
1216void DataElem::setField(int i, TVVariant value)
1217{
1218 if (value.isValid()) {
1219 values.remove(i);
1220 values.replace(i, new TVVariant(value));
1221 }
1222}
1223
1224/*!
1225 Sets the value of the elements field name qs to the value represented in
1226 the QString q.
1227
1228 \param qs name of the field to set
1229 \param q a string that can be parsed to get the value to be set
1230*/
1231void DataElem::setField(QString qs, QString q)
1232{
1233 /* from the type of the field, parse q and store */
1234 int i = contained->getKeyIndex(qs);
1235 setField(i, qs);
1236}
1237
1238/*!
1239 Sets the value of the elements field name qs to the value at the pointer
1240 value.
1241
1242 \param qs name of the field to set
1243 \param value a pointer to the (already allocated) value to set
1244*/
1245void DataElem::setField(QString qs, TVVariant value)
1246{
1247 int i = contained->getKeyIndex(qs);
1248 setField(i, value);
1249}
1250
1251void DataElem::unsetField(int i) {
1252 values.remove(i);
1253}
1254
1255void DataElem::unsetField(QString qs)
1256{
1257 int i = contained->getKeyIndex(qs);
1258 unsetField(i);
1259}
1260
1261/*!
1262 Converts the data element to a Rich Text QString
1263*/
1264QString DataElem::toQString() const
1265{
1266 /* lets make an attempt at this function */
1267 int i;
1268 QString scratch = "";
1269
1270 QIntDictIterator<TVVariant> it(values);
1271
1272 while (it.current()) {
1273 i = it.currentKey();
1274 if(hasValidValue(i)) {
1275 scratch += "<B>" + contained->getKeyName(i) + ":</B> ";
1276 scratch += getField(i).toString();
1277 scratch += "<br>";
1278 }
1279 ++it;
1280 }
1281 return scratch;
1282}
1283
1284/*! formats individual fields to strings so can be displayed */
1285QString DataElem::toQString(int i) const
1286{
1287 if(hasValidValue(i)) {
1288 return getField(i).toString();
1289 }
1290 return "";
1291}
1292/*! formats individual fields to strings so can be sorted by QListView */
1293QString DataElem::toSortableQString(int i) const
1294{
1295 QString scratch = "";
1296 if(hasValidValue(i)) {
1297 switch (contained->getKeyType(i)) {
1298 case TVVariant::String: {
1299 scratch += getField(i).toString();
1300 break;
1301 }
1302 case TVVariant::Int: {
1303 scratch.sprintf("%08d", getField(i).toInt());
1304 break;
1305 }
1306 case TVVariant::Date: {
1307 static QDate epochD(1800, 1, 1);
1308 scratch.sprintf("%08d",
1309 epochD.daysTo(getField(i).toDate()));
1310 break;
1311 }
1312 case TVVariant::Time: {
1313 static QTime epochT(0, 0, 0);
1314 scratch.sprintf("%08d",
1315 epochT.msecsTo(getField(i).toTime()));
1316 break;
1317 }
1318 default:
1319 scratch += "Unknown type";
1320 break;
1321 }
1322 }
1323 return scratch;
1324}
1325
1326/* compare functions */
1327
1328bool DataElem::lessThan(int i, TVVariant v) const
1329{
1330 if (!hasValidValue(i)) return FALSE;
1331
1332 if (getField(i).type() != v.type())
1333 return FALSE;
1334
1335 return (getField(i) < v);
1336}
1337
1338bool DataElem::moreThan(int i, TVVariant v) const
1339{
1340 if (!hasValidValue(i)) return FALSE;
1341
1342 if (getField(i).type() != v.type())
1343 return FALSE;
1344
1345 return (getField(i) > v);
1346}
1347
1348bool DataElem::equalTo(int i, TVVariant v) const
1349{
1350 if (!hasValidValue(i)) return FALSE;
1351
1352 if (getField(i).type() != v.type())
1353 return FALSE;
1354
1355 return (getField(i) == v);
1356}
1357
1358bool DataElem::contains(int i, TVVariant v) const
1359{
1360 if (!hasValidValue(i)) return FALSE;
1361
1362 if (getField(i).type() != v.type())
1363 return FALSE;
1364
1365 switch(getField(i).type()) {
1366 case TVVariant::String: {
1367 QString qs1 = getField(i).toString().lower();
1368 QString qs2 = v.toString().lower();
1369 if (qs1.contains(qs2) > 0) return TRUE;
1370 break;
1371 }
1372 /* meaningless for ints */
1373 /* meaningless for time */
1374 /* meaningless for dates */
1375 case TVVariant::Int:
1376 case TVVariant::Time:
1377 case TVVariant::Date:
1378 break;
1379 default:
1380 qWarning("Tried to compare unknown data type");
1381 }
1382 return FALSE;
1383}
1384
1385bool DataElem::startsWith(int i, TVVariant v) const
1386{
1387 if (!hasValidValue(i)) return FALSE;
1388
1389 if (getField(i).type() != v.type())
1390 return FALSE;
1391
1392 switch(getField(i).type()) {
1393 case TVVariant::String: {
1394 QString qs1 = getField(i).toString().lower();
1395 QString qs2 = v.toString().lower();
1396 return qs1.startsWith(qs2);
1397 }
1398 /* meaningless for ints */
1399 /* meaningless for time */
1400 /* meaningless for dates */
1401 case TVVariant::Int:
1402 case TVVariant::Time:
1403 case TVVariant::Date:
1404 return FALSE;
1405 default:
1406 qWarning("Tried to compare unknown data type");
1407 }
1408 return FALSE;
1409}
1410
1411bool DataElem::endsWith(int i, TVVariant v) const
1412{
1413 if (!hasValidValue(i)) return FALSE;
1414
1415 if (getField(i).type() != v.type())
1416 return FALSE;
1417
1418 switch(getField(i).type()) {
1419 case TVVariant::String: {
1420 QString qs1 = getField(i).toString().lower();
1421 QString qs2 = v.toString().lower();
1422 return qs1.startsWith(qs2);
1423 }
1424 /* meaningless for ints */
1425 /* meaningless for time */
1426 /* meaningless for dates */
1427 case TVVariant::Int:
1428 case TVVariant::Time:
1429 case TVVariant::Date:
1430 return FALSE;
1431 default:
1432 qWarning("Tried to compare unknown data type");
1433 }
1434 return FALSE;
1435}
1436
1437/*!
1438 Determins which of the first to parameters are closer to the third, target
1439 parameter.
1440
1441 \return
1442 <UL>
1443 <LI>TRUE if the first element is a closer match to the target than the
1444 second element</LI>
1445 <LI>FALSE if the first element is not a closer match to the target than
1446 the second element</LI>
1447 </UL>
1448*/
1449bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column)
1450{
1451 int type;
1452
1453 if(!d1) return FALSE;
1454
1455 if (!d1->hasValidValue(column)) return FALSE;
1456
1457 if(!target.isValid()) return FALSE;
1458
1459 type = d1->getField(column).type();
1460
1461 if(d2) {
1462 if (type != d2->getField(column).type()) {
1463 /* can't do compare */
1464 qWarning("Tried to compare two incompatable types");
1465 return FALSE;
1466 }
1467 return target.closer(d1->getField(column), d2->getField(column));
1468 }
1469 return target.close(d1->getField(column));
1470}
diff --git a/noncore/apps/tableviewer/db/common.h b/noncore/apps/tableviewer/db/common.h
new file mode 100644
index 0000000..bb0a953
--- a/dev/null
+++ b/noncore/apps/tableviewer/db/common.h
@@ -0,0 +1,285 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22/* This file represents shared data structures that will be passed
23 * around often.
24 */
25#ifndef __SHAREDDATA_H__
26#define __SHAREDDATA_H__
27
28// TODO rename this to a sensable class name
29
30#include <qvector.h>
31#include <qstring.h>
32#include <qdatetime.h>
33#include <qcstring.h>
34#include <qdatastream.h>
35#include <qintdict.h>
36
37class DBStore;
38
39/* helper classes to common classes */
40class QStringVector : public QVector<QString>
41{
42public:
43 int compareItems(Item a, Item b);
44};
45
46/* in QT 2.3, dates and times not supported int QVariant. So.....
47 * for now use my special Variant type which is basically identical
48 * except that does it for my types. TODO replace with QVariant when
49 * qvariant supports all the types we require */
50
51class TVVariantPrivate;
52
53class TVVariant
54{
55public:
56 enum KeyType {
57 Invalid = 0,
58 Int,
59 String,
60 Date,
61 Time,
62 };
63
64 TVVariant();
65 ~TVVariant();
66
67 TVVariant(const TVVariant&);
68 TVVariant(QDataStream&);
69
70 TVVariant(const QString &);
71 TVVariant(const int);
72 TVVariant(const QDate &);
73 TVVariant(const QTime &);
74
75 TVVariant& operator=(const TVVariant& );
76 bool operator==(const TVVariant&) const;
77 bool operator!=(const TVVariant&) const;
78 bool operator<(const TVVariant&) const;
79 bool operator>(const TVVariant&) const;
80
81 bool closer(TVVariant, TVVariant);
82 bool close(TVVariant);
83
84 KeyType type() const;
85 const QString typeName() const;
86 int numTypes() const;
87
88 const QString typeName(KeyType) const;
89 bool canCast(KeyType) const;
90 bool isValid() const;
91 void clear();
92
93 const QString toString() const;
94 const QDate toDate() const;
95 const QTime toTime() const;
96 int toInt() const;
97
98 QString& asString();
99 QDate& asDate();
100 QTime& asTime();
101 int& asInt();
102
103 void load(QDataStream&);
104 void save(QDataStream&) const;
105
106 static const QString typeToName(KeyType typ);
107 static KeyType nameToType(const QString &);
108private:
109 void detach();
110
111 TVVariantPrivate *d;
112};
113
114class TVVariantPrivate : public QShared
115{
116 public:
117 TVVariantPrivate();
118 TVVariantPrivate(TVVariantPrivate *);
119
120 ~TVVariantPrivate();
121
122 void clear();
123
124 TVVariant::KeyType typ;
125
126 union {
127 int i;
128 void *ptr;
129 } value;
130};
131
132inline TVVariant::KeyType TVVariant::type() const
133{
134 return d->typ;
135}
136
137inline bool TVVariant::isValid() const
138{
139 return (d->typ != Invalid);
140}
141
142inline int TVVariant::numTypes() const
143{
144 return 4;
145}
146
147class Key {
148public:
149 Key();
150 Key(QString name, TVVariant example, int flags = 0);
151 Key(const Key &);
152 Key& operator=(const Key& );
153
154 QString name() const;
155 TVVariant example() const;
156 TVVariant::KeyType type() const;
157 int flags() const;
158
159 void setName(const QString &);
160 void setExample(const TVVariant &);
161 void setFlags(int);
162
163 bool delFlag() const;
164 bool newFlag() const;
165
166 void setDelFlag(bool);
167 void setNewFlag(bool);
168
169private:
170 QString kname;
171 TVVariant kexample;
172 int kflags;
173};
174
175class KeyList : public QIntDict<Key> {
176public:
177 KeyList();
178 KeyList(const KeyList&);
179
180 ~KeyList();
181
182 bool operator!=(const KeyList &);
183
184 int getNumFields() const;
185
186 int addKey(QString KeyName, TVVariant example);
187 int addKey(QString KeyName, TVVariant::KeyType type);
188
189 TVVariant getKeyExample(int ) const;
190 void setKeyExample(int, TVVariant e);
191
192 QString getKeyName(int i) const;
193 void setKeyName(int i, const QString &n);
194
195 TVVariant::KeyType getKeyType(int i) const;
196 void setKeyType(int i, TVVariant::KeyType);
197
198 int getKeyIndex(QString q) const;
199
200 int getKeyFlags(int i) const;
201 void setKeyFlags(int i, int flag);
202
203 /* Below should be abstracted a bit more */
204 bool checkNewFlag(int i) const;
205 void setNewFlag(int i, bool f);
206 bool checkDeleteFlag(int i) const;
207 void setDeleteFlag(int i, bool f);
208
209 bool validIndex(int) const;
210};
211
212class KeyListIterator : public QIntDictIterator<Key>
213{
214public:
215 KeyListIterator(const KeyList &k) : QIntDictIterator<Key>(k) {};
216};
217
218/* TODO start using this */
219class DataElem {
220public:
221 DataElem(DBStore *container);
222 ~DataElem();
223
224 int getNumFields() const;
225 KeyList getKeys() const;
226
227 bool hasValidValue(int) const;
228 bool hasValidValue(QString) const;
229 TVVariant::KeyType getFieldType(int) const;
230 TVVariant::KeyType getFieldType(QString) const;
231 TVVariant getField(int) const;
232 TVVariant getField(QString) const;
233
234 void setField(int, QString);
235 void setField(int, TVVariant);
236 void setField(QString, QString);
237 void setField(QString, TVVariant);
238 void unsetField(int);
239 void unsetField(QString);
240
241 QString toQString() const;
242 QString toQString(int i) const;
243 QString toSortableQString(int i) const;
244
245 /* compare functions */
246 bool lessThan(int i, TVVariant) const;
247 bool moreThan(int i, TVVariant) const;
248 bool equalTo(int i, TVVariant) const;
249 bool contains(int i, TVVariant) const;
250 bool startsWith(int i, TVVariant) const;
251 bool endsWith(int i, TVVariant) const;
252
253 /* class functions... Compare is based of the primary key, which
254 is determined by the containing DBStores of each element. */
255 static int compare(const TVVariant, const TVVariant, int i);
256
257 /* False, second element's primary key is closer to target.
258 * True, first element's primary key is a closer match to target */
259 static bool closer(DataElem*, DataElem *, TVVariant, int column);
260private:
261 QIntDict<TVVariant> values;
262 DBStore *contained;
263};
264
265typedef struct _TableState {
266 int current_column;
267 KeyList *kRep;
268 DataElem *current_elem;
269} TableState;
270
271/* Stream functions */
272#ifndef QT_NO_DATASTREAM
273Q_EXPORT QDataStream &operator<<( QDataStream &, const KeyList & );
274Q_EXPORT QDataStream &operator<<( QDataStream &, const DataElem & );
275Q_EXPORT QDataStream &operator>>( QDataStream &, KeyList & );
276Q_EXPORT QDataStream &operator>>( QDataStream &, DataElem & );
277
278
279Q_EXPORT QDataStream &operator>>( QDataStream &, TVVariant & );
280Q_EXPORT QDataStream &operator<<( QDataStream &, const TVVariant & );
281Q_EXPORT QDataStream &operator>>( QDataStream &, TVVariant::KeyType& );
282Q_EXPORT QDataStream &operator<<( QDataStream &, const TVVariant::KeyType& );
283#endif
284
285#endif
diff --git a/noncore/apps/tableviewer/db/csvsource.cpp b/noncore/apps/tableviewer/db/csvsource.cpp
new file mode 100644
index 0000000..2561b4b
--- a/dev/null
+++ b/noncore/apps/tableviewer/db/csvsource.cpp
@@ -0,0 +1,207 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "csvsource.h"
21#include "common.h"
22#include "datacache.h"
23#include <qtextstream.h>
24#include <qstringlist.h>
25#include <qmap.h>
26#include <qregexp.h>
27
28DBCsv::DBCsv(DBStore *d)
29{
30 dstore = d;
31}
32
33DBCsv::~DBCsv()
34{
35}
36
37QString DBCsv::type()
38{
39 return "csv";
40}
41
42QStringList readElem(QString in)
43{
44 QStringList out;
45
46 if (in.isEmpty())
47 return out;
48
49 bool firstChar = TRUE;
50 bool quotedElem = FALSE;
51 uint index = 0;
52 while(index < in.length()) {
53 if(firstChar) {
54 /* skip whitespace */
55 while(index < in.length() && in[index] == ' ')
56 index++;
57 if(in[index] == '"') {
58 quotedElem = TRUE;
59 index++;
60 }
61 }
62 /* real first char */
63 QString elem;
64 if(quotedElem) {
65 while(index < in.length() && in[index] != '"') {
66 /* check for escape character */
67 if (in[index] == '\\') {
68 if (index++ < in.length()) {
69 elem.append(in[index]);
70 index++;
71 }
72 } else {
73 elem.append(in[index]);
74 index++;
75 }
76 }
77 } else {
78 while(index < in.length() && in[index] != ',') {
79 if (in[index] == '\\') {
80 if (index++ < in.length()) {
81 elem.append(in[index]);
82 index++;
83 }
84 } else {
85 elem.append(in[index]);
86 index++;
87 }
88 }
89 }
90 /* we have our current elem */
91 out << elem.stripWhiteSpace();
92 firstChar = TRUE;
93 quotedElem = FALSE;
94 /* skip till a , or end of line */
95 while (index < in.length() && in[index] != ',') index++;
96 if(index == in.length())
97 return out;
98 else
99 index++;
100 }
101}
102
103bool DBCsv::openSource(QIODevice *inDev)
104{
105 QTextStream tsIn(inDev);
106 QString in = tsIn.readLine().stripWhiteSpace();
107 QStringList keys;
108
109 keys = readElem(in);
110
111 QMap<int,int> keyIndexes;
112
113 KeyList *keyR = new KeyList();
114 QStringList::Iterator i = keys.begin();
115
116 uint fileIndex = 0;
117 while(i != keys.end()) {
118 if ((*i).isEmpty())
119 keyIndexes.insert(fileIndex, keyR->addKey("Unamed", TVVariant::String));
120 else
121 keyIndexes.insert(fileIndex, keyR->addKey(*i, TVVariant::String));
122 i++;
123 fileIndex++;
124 }
125 dstore->setKeys(keyR);
126
127 in = tsIn.readLine().stripWhiteSpace();
128 while(!in.isNull()) {
129 QStringList elems = readElem(in);
130
131 i = elems.begin();
132 fileIndex = 0;
133 DataElem *current_data = new DataElem(dstore);
134 while(i != elems.end()) {
135 if(!(*i).isEmpty()) {
136 current_data->setField(keyIndexes[fileIndex], *i);
137 }
138 fileIndex++;
139 i++;
140 }
141 dstore->addItem(current_data);
142 in = tsIn.readLine().stripWhiteSpace();
143 }
144
145 return TRUE;
146}
147
148bool DBCsv::saveSource(QIODevice *outDev)
149{
150 /* try not to use the escape character when possible. */
151 int i;
152 DataElem *elem;
153 KeyList *k;
154 QTextStream outstream(outDev);
155
156 k = dstore->getKeys();
157 KeyListIterator it(*k);
158 while(it.current()) {
159 if(!it.current()->delFlag()) {
160 QString name = it.current()->name();
161
162 name.replace(QRegExp("\\"), "\\\\");
163 name.replace(QRegExp("\""), "\\\"");
164 if(name.find(',') != -1) {
165 name.prepend('\"');
166 name.append('\"');
167 }
168
169 outstream << name;
170 }
171 ++it;
172 if(it.current())
173 outstream << ", ";
174 }
175 outstream << "\n";
176
177 dstore->first();
178
179 do {
180 elem = dstore->getCurrentData();
181 if(!elem)
182 break;
183 it.toFirst();
184 while(it.current()) {
185 i = it.currentKey();
186 if (elem->hasValidValue(i)) {
187 QString name = elem->toQString(i);
188
189 name.replace(QRegExp("\\"), "\\\\");
190 name.replace(QRegExp("\""), "\\\"");
191 if(name.find(',') != -1) {
192 name.prepend('\"');
193 name.append('\"');
194 }
195
196 outstream << name;
197 }
198 ++it;
199 if(it.current())
200 outstream << ", ";
201 }
202 outstream << "\n";
203 } while (dstore->next());
204
205 return TRUE;
206}
207
diff --git a/noncore/apps/tableviewer/db/csvsource.h b/noncore/apps/tableviewer/db/csvsource.h
new file mode 100644
index 0000000..691234c
--- a/dev/null
+++ b/noncore/apps/tableviewer/db/csvsource.h
@@ -0,0 +1,53 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21/* A Class to parse an comma seperated values docment of the form
22
23"Displayed Name", key2name, key 3 name, key name 4
24value1, , value 3, "value 4"
25value1, , value 3, "value 4"
26
27 * '\' is the escape character. Basically \", \' and \\ escape the ", ' or \
28 * into the actual value of the field.
29 * Before any other character will have the effect of dropping the '\'.
30 *
31 * Currently there is no support for comments. */
32
33#ifndef __CSVSOURCE_H__
34#define __CSVSOURCE_H__
35
36#include <qstring.h>
37#include "datacache.h"
38#include "common.h"
39
40
41class DBCsv : public DBAccess
42{
43public:
44 /* create connection and either open or initialize */
45 DBCsv(DBStore *d);
46 QString type();
47 bool openSource(QIODevice *);
48 bool saveSource(QIODevice *);
49 /* does a db write */
50 ~DBCsv();
51};
52
53#endif
diff --git a/noncore/apps/tableviewer/db/datacache.cpp b/noncore/apps/tableviewer/db/datacache.cpp
new file mode 100644
index 0000000..7c14eef
--- a/dev/null
+++ b/noncore/apps/tableviewer/db/datacache.cpp
@@ -0,0 +1,293 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20/*
21 * This file is used to load the xml files that represent the database.
22 * The main requirment for said file is each data entry must contain a key,
23 * otherwise any other data headings are allowed.
24 */
25
26#include "datacache.h"
27#include "xmlsource.h"
28#include "csvsource.h"
29#include <stdlib.h>
30#include <qheader.h>
31
32#define INIT_TABLE_SIZE 128
33
34/*!
35 \class DBStore datastore.h
36
37 \brief The DBStore class is the class responsible for storing, sorting and
38 searching the data loaded by the application
39
40*/
41
42/*!
43 Constructs a DBStore item
44*/
45DBStore::DBStore()
46{
47 name = "";
48 number_elems = 0;
49 full = false;
50 kRep = new KeyList();
51 master_table.resize(INIT_TABLE_SIZE);
52 table_size = INIT_TABLE_SIZE;
53
54 current_elem = 0;
55 archive = 0;
56}
57
58//TODO
59/*!
60 Reinitializes the table to empty (include a resize of the master table,
61 which should free some memory)
62*/
63void DBStore::freeTable()
64{
65 name = "";
66 if(archive) {
67 delete archive;
68 archive = 0;
69 }
70 kRep->clear(); /* clear the current key list */
71
72 number_elems = 0;
73 table_size = INIT_TABLE_SIZE;
74 master_table.resize(table_size);
75 full = false;
76 current_elem = 0;
77}
78
79/*!
80 Removes all items from the DBStore and destroys the DBStore
81*/
82DBStore::~DBStore()
83{
84 freeTable();
85}
86
87/*!
88 This function opens the given xml file, loads it and sets up the
89 appropriate data structures.
90
91 \param file_name A string representing the name of the file to be opened
92 \return true if successful, false otherwise.
93*/
94bool DBStore::openSource(QIODevice *inDev, const QString &source) {
95
96 /* first check if db is already open, if contains data.. then clear */
97 if(number_elems > 0) {
98 freeTable();
99 }
100
101 if (source == "text/x-xml-tableviewer") {
102 archive = new DBXml(this);
103 } else if (source == "text/csv") {
104 archive = new DBCsv(this);
105 } else
106 return false;
107
108 return (archive->openSource(inDev));
109}
110
111bool DBStore::saveSource(QIODevice *outDev, const QString &source)
112{
113 /* saving a new file */
114 if(!archive) {
115 if (source == "text/x-xml-tableviewer") {
116 archive = new DBXml(this);
117 } else if (source == "text/x-xml-tableviewer") {
118 archive = new DBCsv(this);
119 } else
120 return false;
121 }
122
123 /* changing file type */
124 if(archive->type() != source) {
125 delete archive;
126 if (source == "text/x-xml-tableviewer") {
127 archive = new DBXml(this);
128 } else if (source == "text/x-xml-tableviewer") {
129 archive = new DBCsv(this);
130 } else
131 return false;
132 }
133
134 return (archive->saveSource(outDev));
135}
136
137/*!
138 This function is used to add new elements to the database. If the database
139 has already reached the maximum allowable size this function does not alter
140 the database.
141
142 \param delm An already allocated and initialized data element to be added
143*/
144void DBStore::addItem(DataElem *delem)
145{
146 addItemInternal(delem);
147}
148
149void DBStore::addItemInternal(DataElem *delem)
150{
151 /* if already full, don't over fill, do a qWarning though */
152 if (full) {
153 qWarning("Attempted to add items to already full table");
154 return;
155 }
156
157 master_table.insert(number_elems, delem);
158
159 current_elem = number_elems;
160 number_elems++;
161
162 if(number_elems >= table_size) {
163 /* filled current table, double if we can */
164 table_size = table_size << 1;
165
166 /* check that the new table size is still valid, i.e. that we didn't
167 just shift the 1 bit of the end of the int. */
168 if (!table_size) {
169 full = true;
170 /* no point in doing antying else. */
171 return;
172 }
173 master_table.resize(table_size);
174 }
175}
176
177void DBStore::removeItem(DataElem *r)
178{
179 int position = master_table.findRef(r);
180 if(position != -1) {
181 /* there is at least one item, this is it */
182 /* replace this with the last element, decrease the element count */
183 master_table.insert(position, master_table.at(--number_elems));
184 master_table.remove(number_elems);
185 delete r;
186 }
187}
188
189/*!
190 Sets the name of the database
191
192 \param n A string representing the new name of the database.
193*/
194void DBStore::setName(const QString &n)
195{
196 name = n;
197}
198
199/*!
200 Gets the name of the database
201
202 \return A string representing the name of the database.
203*/
204QString DBStore::getName()
205{
206 return name;
207}
208
209/*!
210 Retrieves a pointer to the key representation of the database for
211 other classes to use as reference.
212
213 \return a pointer to the databases key representaion
214*/
215KeyList *DBStore::getKeys()
216{
217 return kRep;
218}
219
220/*!
221 sets the database's key representation the passed pointer
222 \param a pointer to a key representaton
223*/
224void DBStore::setKeys(KeyList *k)
225{
226 kRep = k;
227}
228
229/*!
230 Sets the current element to the first element of the database
231*/
232void DBStore::first()
233{
234 current_elem = 0;
235}
236
237/*!
238 Sets the current element to the last element of the database
239*/
240void DBStore::last()
241{
242 current_elem = number_elems - 1;
243}
244
245/*!
246 Sets the current element to the next element of the database if
247 there exists an element after the current one.
248*/
249bool DBStore::next()
250{
251 unsigned int new_current_elem = current_elem + 1;
252 if (current_elem < number_elems)
253 /* was valid before inc (it is possible but unlikely that inc current
254 elem will change it from invalid to valid) */
255 if (new_current_elem < number_elems) {
256 /* is valid after inc */
257 current_elem = new_current_elem;
258 return true;
259 }
260 return false;
261}
262
263/*!
264 Sets the current element to the previous element of the database if
265 there exists an element before the current one.
266*/
267bool DBStore::previous()
268{
269 unsigned int new_current_elem = current_elem -1;
270 if (current_elem < number_elems)
271 /* was valid */
272 if (new_current_elem < number_elems) {
273 /* still is (if was 0, then now -1, but as is unsigned will wrap
274 and hence be invalid */
275 current_elem = new_current_elem;
276 return true;
277 }
278 return false;
279}
280
281/*!
282 Returns the current data element in the database. Which element is current
283 is affected by newly added items, findItem, next, previous, first and
284 last functions
285
286 \return a pointer to the current data element
287*/
288DataElem *DBStore::getCurrentData()
289{
290 if (current_elem >= number_elems)
291 return NULL;
292 return master_table[current_elem];
293}
diff --git a/noncore/apps/tableviewer/db/datacache.h b/noncore/apps/tableviewer/db/datacache.h
new file mode 100644
index 0000000..c5dc637
--- a/dev/null
+++ b/noncore/apps/tableviewer/db/datacache.h
@@ -0,0 +1,130 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21/*
22 * This file is used to load the xml files that represent the database.
23 * The main requirment for said file is each data entry must contain a key,
24 * otherwise any other data headings are allowed.
25 */
26
27#ifndef __DATACACHE_H__
28#define __DATACACHE_H__
29
30#include <qstring.h>
31#include <qvector.h>
32#include "common.h"
33
34class DBStore;
35
36/*! Abstract class that defines how database stuff can be accessed */
37class DBAccess {
38public:
39
40// DBAccess(DBStore *d) { dstore = d; }
41 virtual ~DBAccess() {}
42
43 virtual QString type() {
44 return QString();
45 }
46
47 virtual bool openSource(QIODevice *) {
48 qWarning("DBAccess::openSource not yet implemented");
49 return false;
50 }
51
52 virtual bool saveSource(QIODevice *) {
53 qWarning("DBAccess::saveSource(QString) not yet implemented");
54 return false;
55 }
56
57protected:
58 DBStore *dstore;
59 QString source_name;
60};
61
62class DBStore {
63public:
64 DBStore();
65 ~DBStore();
66
67 bool openSource(QIODevice *, const QString &source);
68 bool saveSource(QIODevice *, const QString &source);
69
70 // Add an item
71 void addItem(DataElem *);
72 void addItemInternal(DataElem *);
73 void removeItem(DataElem *);
74
75 // Set the name of the database
76 void setName(const QString &name);
77
78 // Get the name of the database
79 QString getName();
80
81 KeyList *getKeys();
82 void setKeys(KeyList *);
83
84 /*! gets the number of fields defined in the database */
85 inline int getNumFields() {
86 return kRep->getNumFields();
87 }
88
89 /*! gets the index of a key given its name */
90 inline int getKeyIndex(QString qs) {
91 return kRep->getKeyIndex(qs);
92 }
93
94 /*! gets the type of a key given its index */
95 inline TVVariant::KeyType getKeyType(int i) {
96 return kRep->getKeyType(i);
97 }
98
99 /*! gets the name of a key given its index */
100 inline QString getKeyName(int i) {
101 return kRep->getKeyName(i);
102 }
103
104// Access functions.. iterator type stuff
105
106 void first();
107 void last();
108
109 bool next();
110 bool previous();
111
112 DataElem* getCurrentData();
113
114private:
115 /* does the work of freeing used memory */
116 void freeTable();
117 QString name;
118
119 QVector<DataElem> master_table;
120 DBAccess *archive;
121
122 KeyList *kRep;
123
124 unsigned int number_elems;
125 unsigned int table_size; /* should always be a power of 2 */
126 bool full; /* since because we are using an int for indexing there is
127 an upper limit on the number of items we can store. */
128 unsigned int current_elem;
129};
130#endif
diff --git a/noncore/apps/tableviewer/db/xmlsource.cpp b/noncore/apps/tableviewer/db/xmlsource.cpp
new file mode 100644
index 0000000..7418a85
--- a/dev/null
+++ b/noncore/apps/tableviewer/db/xmlsource.cpp
@@ -0,0 +1,295 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "xmlsource.h"
21#include <qdict.h>
22#include <stdlib.h>
23#include <qtextstream.h>
24
25
26DBXml::DBXml(DBStore *d)
27{
28 dstore = d;
29}
30
31QString DBXml::type()
32{
33 return "xml";
34}
35
36bool DBXml::openSource(QIODevice *inDev)
37{
38 bool ok;
39
40 DBXmlHandler h(dstore);
41
42 QTextStream tsIn(inDev);
43 QXmlInputSource source(tsIn);
44 QXmlSimpleReader reader;
45 reader.setContentHandler(&h);
46 reader.setErrorHandler(&h);
47 ok = reader.parse(source);
48
49 return ok;
50}
51
52bool DBXml::saveSource(QIODevice *outDev)
53{
54 int i;
55 DataElem *elem;
56 KeyList *k;
57
58 QTextStream outstream(outDev);
59
60 outstream << "<database name=\"" << dstore->getName() << "\">" << endl;
61 outstream << "<header>" << endl;
62
63 k = dstore->getKeys();
64 KeyListIterator it(*k);
65 while(it.current()) {
66 if (!it.current()->delFlag()) {
67 outstream << "<key name=\"KEYID" << it.currentKey() << "\" ";
68 outstream << "type=\""
69 << TVVariant::typeToName(it.current()->type())
70 << "\">";
71 outstream << it.current()->name() << "</key>" << endl;
72 }
73 ++it;
74 }
75
76 outstream << "</header>" << endl;
77
78 dstore->first();
79
80 do {
81 elem = dstore->getCurrentData();
82 if (!elem)
83 break;
84 outstream << "<record>" << endl;
85 it.toFirst();
86 while (it.current()) {
87 i = it.currentKey();
88 if (elem->hasValidValue(i)) {
89 outstream << "<KEYID" << i << ">";
90 if (dstore->getKeyType(i) == TVVariant::Date) {
91 // dates in files are different from displayed dates
92 QDate date = elem->getField(i).toDate();
93 outstream << date.day() << "/"
94 << date.month() << "/"
95 << date.year();
96 } else {
97 outstream << elem->toQString(i);
98 }
99 outstream << "</KEYID" << i << ">" << endl;
100 }
101 ++it;
102 }
103 outstream << "</record>" << endl;
104 } while(dstore->next());
105
106 outstream << "</database>" << endl;
107 return TRUE;
108}
109
110DBXml::~DBXml() {}
111
112/*!
113 \class DBXmlHandler
114 \brief An Xml parser for flat tables.
115
116 An xml parser for parsing the files used by the table viewer application.
117
118 The format of the xml files can be found at the front of the file
119 dataparser.h
120*/
121
122/*!
123 Constructs a new DBXmlHandler, and sets that the table should be
124 constructed in the DBStore pointed to by ds.
125*/
126DBXmlHandler::DBXmlHandler(DBStore *ds)
127{
128 data_store = ds;
129 current_keyrep = 0;
130}
131
132/*!
133 Destroys the DBXmlHandler
134*/
135DBXmlHandler::~DBXmlHandler()
136{
137}
138
139QString DBXmlHandler::errorProtocol()
140{
141 qWarning("Error reading file");
142 return errorProt;
143}
144
145bool DBXmlHandler::startDocument()
146{
147 errorProt = "";
148 state = StateInit;
149 return TRUE;
150}
151
152bool DBXmlHandler::startElement(const QString&, const QString&,
153 const QString& qName, const QXmlAttributes& atts)
154{
155 if (state == StateInit && qName == "database") {
156 // First thing it expects is a <document name="..."> tag
157 state = StateDocument;
158 data_store->setName(atts.value("name"));
159 return TRUE;
160 }
161 if (state == StateDocument && qName == "header") {
162 state = StateHeader;
163 if (current_keyrep) delete current_keyrep;
164 current_keyrep = new KeyList();
165 return TRUE;
166 }
167 if (state == StateHeader && qName == "key") {
168 /* Ok, adding a new key to our KeyList TODO */
169 state = StateKey;
170 last_key_type = TVVariant::String;
171 key = atts.value("name");
172 if (key.isEmpty()) {
173 qWarning("empty key name");
174 return FALSE;
175 }
176 if(!atts.value("type").isEmpty())
177 last_key_type = TVVariant::nameToType(atts.value("type"));
178 return TRUE;
179 }
180 if (state == StateDocument && qName == "record") {
181 state = StateRecord;
182 current_data = new DataElem(data_store);
183 // Now expecting a <record> tag
184 return TRUE;
185 }
186 if (state == StateRecord) {
187 state = StateField;
188 /* the qName is the name of a key */
189 if (!keyIndexList[qName]) {
190 /* invalid key, we failed */
191 qWarning("Invalid key in record");
192 return FALSE;
193 }
194 keyIndex = *keyIndexList[qName];
195 return TRUE;
196 }
197 qWarning("Unable to determine tag type");
198 return FALSE;
199}
200
201bool DBXmlHandler::endElement(const QString&, const QString&,
202 const QString& qName)
203{
204 switch(state) {
205 case StateField:
206 // TODO checks 'could' be done of the popped value
207 state = StateRecord;
208 break;
209 case StateKey:
210 // TODO checks 'could' be done of the popped value
211 state = StateHeader;
212 break;
213 case StateHeader:
214 data_store->setKeys(current_keyrep);
215 state = StateDocument;
216 break;
217 case StateRecord:
218 data_store->addItem(current_data);
219 state = StateDocument;
220 break;
221 case StateDocument:
222 // we are done...
223 break;
224 default:
225 // should only get a 'endElement' from one of the above states.
226 qWarning("Invalid end tag");
227 return FALSE;
228 break;
229 }
230 return TRUE;
231}
232
233bool DBXmlHandler::characters(const QString& ch)
234{
235 // this is where the 'between tag' stuff happens.
236 // e.g. the stuff between tags.
237 QString ch_simplified = ch.simplifyWhiteSpace();
238
239 if (ch_simplified.isEmpty())
240 return TRUE;
241
242 if (state == StateKey) {
243 int *tmp_val = new int;
244 /* We just grabbed the display name of a key */
245 *tmp_val = current_keyrep->addKey(ch_simplified, last_key_type);
246 keyIndexList.insert(key, tmp_val);
247 return TRUE;
248 }
249 if (state == StateField) {
250 /* Ok, need to add data here */
251 current_data->setField(keyIndex, ch_simplified);
252 return TRUE;
253 }
254
255 qWarning("Junk characters found... ignored");
256 return TRUE;
257}
258
259QString DBXmlHandler::errorString()
260{
261 return "the document is not in the expected file format";
262}
263
264bool DBXmlHandler::warning(const QXmlParseException& exception)
265{
266 errorProt += QString("warning parsing error: %1 in line %2, column %3\n" )
267 .arg(exception.message())
268 .arg(exception.lineNumber())
269 .arg(exception.columnNumber());
270
271 qWarning(errorProt);
272 return QXmlDefaultHandler::fatalError(exception);
273}
274
275bool DBXmlHandler::error(const QXmlParseException& exception)
276{
277 errorProt += QString("error parsing error: %1 in line %2, column %3\n" )
278 .arg(exception.message())
279 .arg(exception.lineNumber())
280 .arg(exception.columnNumber());
281
282 qWarning(errorProt);
283 return QXmlDefaultHandler::fatalError(exception);
284}
285
286bool DBXmlHandler::fatalError(const QXmlParseException& exception)
287{
288 errorProt += QString("fatal parsing error: %1 in line %2, column %3\n" )
289 .arg(exception.message())
290 .arg(exception.lineNumber())
291 .arg(exception.columnNumber());
292
293 qWarning(errorProt);
294 return QXmlDefaultHandler::fatalError(exception);
295}
diff --git a/noncore/apps/tableviewer/db/xmlsource.h b/noncore/apps/tableviewer/db/xmlsource.h
new file mode 100644
index 0000000..ec267a6
--- a/dev/null
+++ b/noncore/apps/tableviewer/db/xmlsource.h
@@ -0,0 +1,119 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21/* A Class to parse an xml docment of the form
22 * <database name="...">
23 * <header>
24 * <key name=key_name type=String>Displayed Name</key>
25 * <key name=key2name>key2name</key>
26 * <key name=key3name type=Date>Key 3</key>
27 * <key name=key4name type=Int>key 4</key>
28 * </header>
29 * <record>
30 * <key_name>string</key_name>
31 * <key4name>int</key4name>
32 * <key2name>string</key2name>
33 * </record>
34 * <record>
35 * ....
36 * </record>
37 * ....
38 * </database>
39 *
40 * There is some room for improvment mostly around using better checking
41 * and the use of more advanced xml features.
42 */
43
44#ifndef __XMLSOURCE_H__
45#define __XMLSOURCE_H__
46
47#include <qxml.h>
48#include <qstring.h>
49#include <qstringlist.h>
50#include <qstack.h>
51#include <qdict.h>
52#include "datacache.h"
53#include "common.h"
54
55
56class DBXml : public DBAccess
57{
58public:
59 /* create connection and either open or initialize */
60 DBXml(DBStore *d);
61 QString type();
62 bool openSource(QIODevice *);
63 bool saveSource(QIODevice *);
64 /* does a db write */
65 ~DBXml();
66};
67
68
69class DBXmlHandler : public QXmlDefaultHandler
70{
71
72public:
73 DBXmlHandler(DBStore *ds);
74 virtual ~DBXmlHandler();
75
76 // return the error protocol if parsing failed
77 QString errorProtocol();
78
79 // overloaded handler functions
80 bool startDocument();
81 bool startElement(const QString& namespaceURI, const QString& localName,
82 const QString& qName, const QXmlAttributes& atts);
83 bool endElement(const QString& namespaceURI, const QString& localName,
84 const QString& qName);
85 bool characters(const QString& ch);
86
87 QString errorString();
88
89 bool warning(const QXmlParseException& exception);
90 bool error(const QXmlParseException& exception);
91 bool fatalError(const QXmlParseException& exception);
92
93private:
94
95 QStack<QString> stack;
96 KeyList *current_keyrep;
97 DataElem *current_data;
98 TVVariant::KeyType last_key_type;
99
100 QString errorProt;
101 DBStore *data_store;
102
103 enum State {
104 StateInit,
105 StateHeader,
106 StateKey,
107 StateDocument,
108 StateRecord,
109 StateField
110 };
111
112 State state;
113
114 QDict<int> keyIndexList;
115 int keyIndex;
116 QString key;
117};
118
119#endif
diff --git a/noncore/apps/tableviewer/keyentry.cw b/noncore/apps/tableviewer/keyentry.cw
new file mode 100644
index 0000000..e46da90
--- a/dev/null
+++ b/noncore/apps/tableviewer/keyentry.cw
@@ -0,0 +1,55 @@
1<!DOCTYPE CW><CW>
2<customwidgets>
3 <customwidget>
4 <class>TVBrowseKeyEntry</class>
5 <header location="local">browsekeyentry.h</header>
6 <sizehint>
7 <width>6</width>
8 <height>4</height>
9 </sizehint>
10 <container>1</container>
11 <sizepolicy>
12 <hordata>5</hordata>
13 <verdata>5</verdata>
14 </sizepolicy>
15 <pixmap>
16 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
17 </pixmap>
18 </customwidget>
19 <customwidget>
20 <class>TVListViewPrivate</class>
21 <header location="local">tvlistview.h</header>
22 <sizehint>
23 <width>10</width>
24 <height>10</height>
25 </sizehint>
26 <container>0</container>
27 <sizepolicy>
28 <hordata>5</hordata>
29 <verdata>5</verdata>
30 </sizepolicy>
31 <pixmap>
32 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data>
33 </pixmap>
34 <signal>sortChanged(int)</signal>
35 <signal>currentChanged(QListViewItem *)</signal>
36 </customwidget>
37 <customwidget>
38 <class>TVFilterKeyEntry</class>
39 <header location="local">filterkeyentry.h</header>
40 <sizehint>
41 <width>10</width>
42 <height>10</height>
43 </sizehint>
44 <container>1</container>
45 <sizepolicy>
46 <hordata>5</hordata>
47 <verdata>5</verdata>
48 </sizepolicy>
49 <pixmap>
50 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data>
51 </pixmap>
52 <signal>valueChanged()</signal>
53 </customwidget>
54</customwidgets>
55</CW>
diff --git a/noncore/apps/tableviewer/main.cpp b/noncore/apps/tableviewer/main.cpp
new file mode 100644
index 0000000..736e1cf
--- a/dev/null
+++ b/noncore/apps/tableviewer/main.cpp
@@ -0,0 +1,32 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "tableviewer.h"
21#include <qpeapplication.h>
22
23int main( int argc, char ** argv )
24{
25 QPEApplication a( argc, argv );
26
27 TableViewerWindow * mw = new TableViewerWindow;
28 mw->setCaption( TableViewerWindow::tr("Table Viewer") );
29 a.showMainWidget(mw);
30
31 return a.exec();
32}
diff --git a/noncore/apps/tableviewer/qpe-tableviewer.control b/noncore/apps/tableviewer/qpe-tableviewer.control
new file mode 100644
index 0000000..86d0342
--- a/dev/null
+++ b/noncore/apps/tableviewer/qpe-tableviewer.control
@@ -0,0 +1,10 @@
1Files: EXCLUDED bin/tableviewer apps/Applications/tableviewer.desktop
2Priority: optional
3Section: qpe/applications
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Arch: iPAQ
7Version: $QPE_VERSION-3
8Depends: qpe-base ($QPE_VERSION)
9Description: XML database browsers
10 A table/database viewer for the Qtopia environment.
diff --git a/noncore/apps/tableviewer/tableviewer.cpp b/noncore/apps/tableviewer/tableviewer.cpp
new file mode 100644
index 0000000..0d4a412
--- a/dev/null
+++ b/noncore/apps/tableviewer/tableviewer.cpp
@@ -0,0 +1,455 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21/* local includes */
22#include "tableviewer.h"
23#include "ui/tvbrowseview.h"
24#include "ui/tvfilterview.h"
25#include "ui/tvlistview.h"
26#include "ui/tveditview.h"
27#include "ui/tvkeyedit.h"
28#include "db/datacache.h"
29
30/* QPE includes */
31#include "fileselector.h"
32#include "resource.h"
33
34/* QTE includes */
35#include <qpe/qpemenubar.h>
36#include <qpopupmenu.h>
37#include <qapplication.h>
38#include <qwidgetstack.h>
39#include <qlayout.h>
40#include <qbuffer.h>
41
42/*!
43 \class TableViewerWindow
44 \brief The main window widget of the application
45
46 This is the main widget of the table viewer application.
47 It is the co-ordination point.
48*/
49
50/*!
51 Constructs a new TableViewerWindow
52*/
53TableViewerWindow::TableViewerWindow(QWidget *parent, const char *name, WFlags f)
54 : QMainWindow(parent, name, f)
55{
56 setCaption(tr("Table Viewer"));
57
58/* Build data */
59 ds = new DBStore();
60 doc.setType("text/x-xml-tableviewer");
61 doc.setName("table");
62
63 dirty = FALSE;
64 ts.current_column = 0;
65 ts.kRep = ds->getKeys();
66
67/* build menus */
68 menu = new QPEMenuBar(this, 0);
69
70 QPopupMenu *file_menu = new QPopupMenu;
71 file_menu->insertItem("New", this, SLOT(newDocument()));
72
73 file_menu->insertItem("Open", this, SLOT(selectDocument()));
74 file_menu->insertSeparator();
75 file_menu->insertItem("Properties");
76
77 /* later will want to set this up to clean up first via this, SLOT(quit) */
78 menu->insertItem("Document", file_menu);
79
80 QPopupMenu *edit_menu = new QPopupMenu;
81 edit_menu->insertItem("Edit Item", this, SLOT(editItemSlot()));
82 edit_menu->insertItem("Edit Keys", this, SLOT(editKeysSlot()));
83 edit_menu->insertItem("Edit filters", this, SLOT(filterViewSlot()));
84 menu->insertItem("Edit", edit_menu);
85
86 QPopupMenu *view_menu = new QPopupMenu;
87 view_menu->insertItem("Browse View", this, SLOT(browseViewSlot()));
88 view_menu->insertItem("List View", this, SLOT(listViewSlot()));
89 menu->insertItem("View", view_menu);
90
91 QVBoxLayout *main_layout = new QVBoxLayout;
92
93 /* Build tool bar */
94 navigation = new QPEToolBar(this, "navigation");
95 QToolButton *newItemButton = new QToolButton(
96 QIconSet(Resource::loadImage("new")), "New Item", QString::null,
97 this, SLOT(newItemSlot()), navigation, "New Item");
98 QToolButton *editItemButton = new QToolButton(
99 QIconSet(Resource::loadImage("edit")), "Edit Item", QString::null,
100 this, SLOT(editItemSlot()), navigation, "Edit Item");
101 QToolButton *deleteItemButton = new QToolButton(
102 QIconSet(Resource::loadImage("trash")), "Delete Item",
103 QString::null, this,
104 SLOT(deleteItemSlot()), navigation, "Delete Item");
105
106 navigation->addSeparator();
107
108 QToolButton *firstItemButton = new QToolButton(
109 QIconSet(Resource::loadImage("fastback")), "First Item",
110 QString::null, this,
111 SLOT(firstItem()), navigation, "First Item");
112 QToolButton *previousItemButton = new QToolButton(
113 QIconSet(Resource::loadImage("back")), "Previous Item",
114 QString::null, this,
115 SLOT(previousItem()), navigation, "Previous Item");
116 QToolButton *nextItemButton = new QToolButton(
117 QIconSet(Resource::loadImage("forward")), "Next Item",
118 QString::null, this,
119 SLOT(nextItem()), navigation, "Next Item");
120 QToolButton *lastItemButton = new QToolButton(
121 QIconSet(Resource::loadImage("fastforward")), "Last Item",
122 QString::null, this,
123 SLOT(lastItem()), navigation, "Last Item");
124
125 navigation->addSeparator();
126 QToolButton *browseButton = new QToolButton(
127 QIconSet(Resource::loadImage("day")), "View Single Item",
128 QString::null, this,
129 SLOT(browseViewSlot()), navigation, "View Single Item");
130 QToolButton *listButton = new QToolButton(
131 QIconSet(Resource::loadImage("month")), "View Multiple Items",
132 QString::null, this,
133 SLOT(listViewSlot()), navigation, "View Multiple Items");
134
135 setToolBarsMovable(FALSE);
136 setToolBarsMovable(FALSE);
137 setToolBarsMovable(FALSE);
138
139/* Build widgets */
140 browseView = new TVBrowseView(&ts, this, 0);
141 listView = new TVListView(&ts, this, 0);
142 filterView = new TVFilterView(&ts, this, 0);
143 fileSelector = new FileSelector("text/csv;text/x-xml-tableviewer",
144 this, "fileselector");
145 fileSelector->setNewVisible(FALSE);
146 fileSelector->setCloseVisible(FALSE);
147
148 cw = new QWidgetStack(this, 0);
149 cw->addWidget(listView, ListState);
150 cw->addWidget(browseView, BrowseState);
151 cw->addWidget(filterView, FilterState);
152 cw->addWidget(fileSelector, FileState);
153
154 current_view = FileState;
155 cw->raiseWidget(current_view);
156 fileSelector->reread();
157
158 connect(browseView, SIGNAL(searchOnKey(int, TVVariant)),
159 this, SLOT(searchOnKey(int, TVVariant)));
160 connect(browseView, SIGNAL(sortChanged(int)),
161 this, SLOT(setPrimaryKey(int)));
162
163 connect(fileSelector, SIGNAL(closeMe()), this, SLOT(browseViewSlot()));
164 connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)),
165 this, SLOT(openDocument(const DocLnk &)));
166
167 main_layout->addWidget(menu);
168 main_layout->addWidget(cw);
169
170 setCentralWidget(cw);
171
172}
173
174/*!
175 Destroys the TableViewerWindow
176*/
177TableViewerWindow::~TableViewerWindow()
178{
179 if(dirty)
180 saveDocument();
181}
182
183/*!
184 Opens a file dialog and loads the file specified by the dialog
185*/
186void TableViewerWindow::selectDocument()
187{
188 if(dirty)
189 saveDocument();
190 current_view = FileState;
191 cw->raiseWidget(current_view);
192 fileSelector->reread();
193}
194
195void TableViewerWindow::saveDocument()
196{
197 if(!dirty)
198 return;
199
200 FileManager fm;
201 QIODevice *dev = fm.saveFile(doc);
202
203 if(!ds->saveSource(dev, doc.type())){
204 qWarning("Save unsuccessful");
205 return;
206 }
207 dev->close();
208 dirty = FALSE;
209}
210
211void TableViewerWindow::newDocument()
212{
213 DocLnk nf;
214 nf.setType("text/x-xml-tableviewer");
215 nf.setName("table");
216
217 delete ds;
218 ds = new DBStore();
219
220 ts.current_column = 0;
221 ts.kRep = ds->getKeys();
222 browseView->reset();
223 listView->reset();
224 filterView->reset();
225
226 doc = nf;
227 dirty = FALSE;
228
229 current_view = BrowseState;
230 cw->raiseWidget(current_view);
231
232 /* now set up for editing the keys */
233 ts.kRep->addKey("key", TVVariant::String);
234 editKeysSlot();
235}
236
237void TableViewerWindow::openDocument(const DocLnk &f)
238{
239
240 if (!f.isValid())
241 return;
242
243 FileManager fm;
244 QIODevice *dev = fm.openFile(f);
245 doc = f;
246
247 if(ds->openSource(dev, doc.type())) {
248 DataElem *d;
249
250 browseView->reset();
251 listView->reset();
252 filterView->reset();
253
254 current_view = BrowseState;
255 cw->raiseWidget(current_view);
256
257 /* set up new table state and ensure sub widgets have a reference */
258 ts.current_column = 0;
259 ts.kRep = ds->getKeys();
260 browseView->rebuildKeys();
261 listView->rebuildKeys();
262 filterView->rebuildKeys();
263
264 ds->first();
265 /* set up the list view */
266 listView->clearItems();
267 do {
268 d = ds->getCurrentData();
269 if(d)
270 listView->addItem(d);
271 } while(ds->next());
272
273 /* Set up browse view, Will be based of structure of listView */
274 listView->first();
275 ts.current_elem = listView->getCurrentData();
276 browseView->rebuildData();
277 listView->rebuildData();
278
279 QString scratch = "Table Viewer";/* later take from constant */
280 scratch += " - ";
281 scratch += ds->getName();
282 setCaption(tr(scratch));
283
284 dirty = FALSE;
285 } else {
286 qWarning(tr("could not load Document"));
287 }
288 dev->close();
289}
290
291/*!
292 Moves to the next item of the current table
293*/
294void TableViewerWindow::nextItem()
295{
296 listView->next();
297 ts.current_elem = listView->getCurrentData();
298 browseView->rebuildData();
299}
300
301/*!
302 Moves to the previous item of the current table
303*/
304void TableViewerWindow::previousItem()
305{
306 listView->previous();
307 ts.current_elem = listView->getCurrentData();
308 browseView->rebuildData();
309}
310
311/*!
312 Raises the List View. This is a mode change for the application.
313*/
314void TableViewerWindow::listViewSlot()
315{
316 if(current_view == FilterState)
317 applyFilter();
318 current_view = ListState;
319 cw->raiseWidget(current_view);
320}
321
322void TableViewerWindow::applyFilter()
323{
324 DataElem *d;
325
326 listView->clearItems();
327 ds->first();
328 do {
329 d = ds->getCurrentData();
330 if(d)
331 if(filterView->passesFilter(d))
332 listView->addItem(d);
333 } while(ds->next());
334 listView->first();
335 listView->rebuildData();
336}
337
338/*!
339 Raises the Browse View. This is a mode change for the application.
340*/
341void TableViewerWindow::browseViewSlot()
342{
343 if(current_view == FilterState)
344 applyFilter();
345
346 ts.current_elem = listView->getCurrentData();
347 browseView->rebuildData();
348
349 current_view = BrowseState;
350 cw->raiseWidget(current_view);
351}
352
353/*!
354 Raises the List View. This is a mode change for the application.
355*/
356void TableViewerWindow::filterViewSlot()
357{
358 current_view = FilterState;
359 cw->raiseWidget(current_view);
360}
361
362
363
364
365void TableViewerWindow::editItemSlot()
366{
367 if(TVEditView::openEditItemDialog(&ts, ts.current_elem, this)) {
368 listView->rebuildData();
369 browseView->rebuildData();
370 dirty = TRUE;
371 }
372}
373
374void TableViewerWindow::newItemSlot()
375{
376 DataElem *d = new DataElem(ds);
377 if (TVEditView::openEditItemDialog(&ts, d, this)) {
378
379 ds->addItem(d);
380 ts.current_elem = d;
381 applyFilter();
382 listView->rebuildData();
383 browseView->rebuildData();
384 dirty = TRUE;
385 }
386}
387
388void TableViewerWindow::deleteItemSlot()
389{
390 /* delete the actual item, then do a 'filter' */
391 DataElem *to_remove = ts.current_elem;
392
393 if(!to_remove)
394 return;
395
396 listView->removeItem();
397 ds->removeItem(to_remove);
398
399 applyFilter();
400 listView->rebuildData();
401 browseView->rebuildData();
402 dirty = TRUE;
403}
404
405void TableViewerWindow::editKeysSlot()
406{
407 DataElem *d;
408 KeyList *k = TVKeyEdit::openEditKeysDialog(&ts, this);
409
410 if(k) {
411 /* set as new keys */
412 ds->setKeys(k);
413
414 ts.current_column = 0;
415 ts.kRep = k;
416
417 browseView->reset();
418 listView->reset();
419 filterView->reset();
420
421 browseView->rebuildKeys();
422 listView->rebuildKeys();
423 filterView->rebuildKeys();
424
425 ds->first();
426 /* set up the list view */
427 listView->clearItems();
428 do {
429 d = ds->getCurrentData();
430 if(d)
431 listView->addItem(d);
432 } while(ds->next());
433
434 /* Set up browse view, Will be based of structure of listView */
435 dirty = TRUE;
436 }
437}
438
439/*!
440 A Slot that allows for widgets above to indicate a search should be
441 done on a specified key index for a specified value
442*/
443void TableViewerWindow::searchOnKey(int i, TVVariant v)
444{
445 listView->findItem(i, v);
446 ts.current_elem = listView->getCurrentData();
447 browseView->rebuildData();
448}
449
450void TableViewerWindow::setPrimaryKey(int i)
451{
452 ts.current_column = i;
453 listView->rebuildData();
454 browseView->rebuildData();
455}
diff --git a/noncore/apps/tableviewer/tableviewer.h b/noncore/apps/tableviewer/tableviewer.h
new file mode 100644
index 0000000..2d4686a
--- a/dev/null
+++ b/noncore/apps/tableviewer/tableviewer.h
@@ -0,0 +1,109 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef Tableviewer_H
21#define Tableviewer_H
22
23#include <qmainwindow.h>
24#include "db/common.h"
25#include "fileselector.h"
26
27/* Forward class declarations */
28class QWidgetStack;
29class QDialog;
30class QMenuBar;
31
32class TVListView;
33class TVBrowseView;
34class TVFilterView;
35class TVEditView;
36
37class DBStore;
38
39class TableViewerWindow: public QMainWindow
40{
41 Q_OBJECT
42public:
43 TableViewerWindow( QWidget *parent = 0,
44 const char *name = 0, WFlags f = 0 );
45 ~TableViewerWindow();
46
47public slots:
48 void selectDocument();
49
50 void newDocument();
51 void saveDocument();
52 void openDocument(const DocLnk &);
53
54 void nextItem();
55 void previousItem();
56
57 void listViewSlot();
58 void browseViewSlot();
59 void filterViewSlot();
60
61 void editItemSlot();
62 void newItemSlot();
63 void deleteItemSlot();
64
65 void editKeysSlot();
66
67 /* reveiw the sig. for this function TODO */
68 void searchOnKey(int, TVVariant);
69 void setPrimaryKey(int);
70
71/* TODO add new event */
72protected:
73
74/* TODO add new slots */
75private slots:
76
77/* TODO add other widgets used here */
78private:
79 bool dirty;
80
81 QMenuBar *menu;
82 QToolBar *navigation;
83
84 TVListView *listView;
85 TVBrowseView *browseView;
86 TVFilterView *filterView;
87 TVEditView *editView;
88 FileSelector *fileSelector;
89
90 DocLnk doc;
91
92 QWidgetStack *cw;
93 DBStore *ds;
94 TableState ts; /* not a pointer.. this class keeps the state */
95
96 enum UserState {
97 BrowseState = 0,
98 ListState,
99 FilterState,
100 EditState,
101 FileState,
102 };
103
104 UserState current_view;
105
106 void applyFilter();
107};
108
109#endif
diff --git a/noncore/apps/tableviewer/tableviewer.pro b/noncore/apps/tableviewer/tableviewer.pro
new file mode 100644
index 0000000..edd41c5
--- a/dev/null
+++ b/noncore/apps/tableviewer/tableviewer.pro
@@ -0,0 +1,36 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on debug
3 DESTDIR = ../bin
4 SUBDIRS = db ui
5 HEADERS = tableviewer.h \
6 ui/commonwidgets.h \
7 ui/tvbrowseview.h \
8 ui/tvlistview.h \
9 ui/tvfilterview.h \
10 ui/tveditview.h \
11 ui/browsekeyentry.h \
12 ui/filterkeyentry.h \
13 ui/tvkeyedit.h \
14 db/datacache.h \
15 db/common.h \
16 db/xmlsource.h \
17 db/csvsource.h
18 SOURCES = main.cpp \
19 tableviewer.cpp \
20 ui/commonwidgets.cpp \
21 ui/tvbrowseview.cpp \
22 ui/tvfilterview.cpp \
23 ui/browsekeyentry.cpp \
24 ui/filterkeyentry.cpp \
25 ui/tvlistview.cpp \
26 ui/tveditview.cpp \
27 ui/tvkeyedit.cpp \
28 db/datacache.cpp \
29 db/xmlsource.cpp \
30 db/csvsource.cpp \
31 db/common.cpp
32 INTERFACES= ui/tvkeyedit_gen.ui
33 TARGET = tableviewer
34INCLUDEPATH += $(QPEDIR)/include
35DEPENDPATH += $(QPEDIR)/include
36 LIBS += -lqpe
diff --git a/noncore/apps/tableviewer/ui/.cvsignore b/noncore/apps/tableviewer/ui/.cvsignore
new file mode 100644
index 0000000..183c939
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/.cvsignore
@@ -0,0 +1,8 @@
1moc_*
2Makefile
3tvbrowseview_gen.h
4tvfilterview_gen.h
5tvkeyedit_gen.h
6tvbrowseview_gen.cpp
7tvfilterview_gen.cpp
8tvkeyedit_gen.cpp
diff --git a/noncore/apps/tableviewer/ui/browsekeyentry.cpp b/noncore/apps/tableviewer/ui/browsekeyentry.cpp
new file mode 100644
index 0000000..42e24dd
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/browsekeyentry.cpp
@@ -0,0 +1,206 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "browsekeyentry.h"
21#include "commonwidgets.h"
22
23#include <qtoolbutton.h>
24#include <qwidgetstack.h>
25#include <qlayout.h>
26#include <qlineedit.h>
27#include <qpushbutton.h>
28#include <qpopupmenu.h>
29#include <qhbox.h>
30#include <qdatetime.h>
31
32#include <qheader.h>
33// For qWarning(const char *)
34
35/*!
36 \class TVBrowseKeyEntry
37 \brief a Widget used enter keys into the TVBrowseViewWidget
38
39 The TVBrowseKeyEntry Widget provides the facility to enter
40 various key types to be search on in the table. The key can be changed
41 and the entry field will update to the correct sort of widget appropriately
42*/
43
44/*!
45 Constructs the widget
46*/
47TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f)
48 : QWidget(parent, name, f)
49{
50 QHBoxLayout *h_layout = new QHBoxLayout(this);
51
52 textKey = new QLineEdit(this, 0);
53 intKey = new IntEdit(this, 0);
54 dateKey = new DateEdit(this, 0);
55 timeKey = new TimeEdit(this, 0);
56
57 resetButton = new QPushButton(this, "reset");
58 resetButton->setMinimumSize(QSize(50, 0));
59 resetButton->setText(tr("Reset"));
60
61 changeKeyButton = new QToolButton(this, "changekey");
62 // TODO The icon stuff.
63 changeKeyButton->setText(tr("key"));
64
65 totalKeys = 0;
66 ts = 0;
67 keyMenu = new QPopupMenu(this, "keymenu");
68
69 ws = new QWidgetStack(this, 0);
70 ws->addWidget(textKey, TVVariant::String);
71 ws->addWidget(intKey, TVVariant::Int);
72 ws->addWidget(timeKey, TVVariant::Time);
73 ws->addWidget(dateKey, TVVariant::Date);
74
75 ws->raiseWidget(TVVariant::String);
76
77 // TODO connect slots and signals....
78 connect(changeKeyButton, SIGNAL(clicked()),
79 this, SLOT(changeKeyMenuSlot()));
80
81 connect(resetButton, SIGNAL(clicked()),
82 textKey, SLOT(clear()));
83 connect(resetButton, SIGNAL(clicked()),
84 intKey, SLOT(clear()));
85 connect(resetButton, SIGNAL(clicked()),
86 dateKey, SLOT(clear()));
87 connect(resetButton, SIGNAL(clicked()),
88 timeKey, SLOT(clear()));
89
90 h_layout->addWidget(ws);
91 h_layout->addWidget(resetButton);
92 h_layout->addWidget(changeKeyButton);
93
94 connect(textKey, SIGNAL(textChanged(const QString&)),
95 this, SLOT(searchOnText()));
96 connect(intKey, SIGNAL(valueChanged(int)),
97 this, SLOT(searchOnText()));
98 connect(dateKey, SIGNAL(valueChanged(const QDate&)),
99 this, SLOT(searchOnText()));
100 connect(timeKey, SIGNAL(valueChanged(const QTime&)),
101 this, SLOT(searchOnText()));
102}
103
104/*!
105 Destructs the widget
106*/
107TVBrowseKeyEntry::~TVBrowseKeyEntry()
108{
109}
110
111/*!
112 Changes which key the user intends to search on
113
114 \param id_param the index of the key future searches should be base on
115*/
116void TVBrowseKeyEntry::changeKeySlot(int id_param)
117{
118 if(ts) {
119 emit sortChanged(id_param);
120 ws->raiseWidget(ts->kRep->getKeyType(ts->current_column));
121 }
122}
123
124/*!
125 Opens the change key menu
126*/
127void TVBrowseKeyEntry::changeKeyMenuSlot()
128{
129 if(ts)
130 keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0)));
131}
132
133
134void TVBrowseKeyEntry::setTableState(TableState *t) {
135 ts = t;
136}
137
138void TVBrowseKeyEntry::rebuildKeys() {
139 int i;
140 if (!ts) return;
141 if (!ts->kRep) return;
142
143 /* clear the old */
144 keyMenu->clear();
145
146 KeyListIterator it(*ts->kRep);
147
148 for (i = 0; i < ts->kRep->getNumFields(); i++) {
149 keyMenu->insertItem(it.current()->name(), this,
150 SLOT(changeKeySlot(int)), 0, i);
151 keyMenu->setItemParameter(i, it.currentKey());
152 ++it;
153 }
154}
155
156void TVBrowseKeyEntry::reset()
157{
158 textKey->clear();
159 intKey->clear();
160 dateKey->clear();
161 timeKey->clear();
162
163 keyMenu->clear();
164}
165/*!
166 Searches on the current value of the key entry provided that the
167 current key is of type text WARNING, TODO fix memory leaks
168*/
169void TVBrowseKeyEntry::searchOnText()
170{
171 TVVariant sendkey;
172
173 if (!ts)
174 return;
175
176 switch(ts->kRep->getKeyType(ts->current_column)) {
177 case TVVariant::String:
178 sendkey = TVVariant(QString(textKey->text()));
179 break;
180 case TVVariant::Int: {
181 sendkey = TVVariant(intKey->value());
182 break;
183 }
184 case TVVariant::Time: {
185 sendkey = TVVariant(QTime(timeKey->time()));
186 break;
187 }
188 case TVVariant::Date: {
189 sendkey = TVVariant(QDate(dateKey->date()));
190 break;
191 }
192 case TVVariant::Invalid:
193 break;
194 default:
195 qWarning("TVBrowseKeyEntry::searchOnText() "
196 "cannot work out data type");
197 return;
198 }
199 emit searchOnKey(ts->current_column, sendkey);
200}
201
202/*! \fn void TVBrowseKeyEntry::searchOnKey(int currentKeyId, TVVariant)
203
204 This signal indicates that a search on key index currentKeyId should be
205 done searching for the value v.
206*/
diff --git a/noncore/apps/tableviewer/ui/browsekeyentry.h b/noncore/apps/tableviewer/ui/browsekeyentry.h
new file mode 100644
index 0000000..220bf6a
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/browsekeyentry.h
@@ -0,0 +1,75 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef BrowseKeyEntry_H
21#define BrowseKeyEntry_H
22
23#include <qwidget.h>
24#include "../db/common.h"
25
26/* Forward class declarations */
27class QWidgetStack;
28class QToolButton;
29class QPushButton;
30class QLineEdit;
31class DateEdit;
32class TimeEdit;
33class IntEdit;
34class QPopupMenu;
35class QHBox;
36
37class TVBrowseKeyEntry: public QWidget
38{
39 Q_OBJECT
40public:
41 TVBrowseKeyEntry( QWidget *parent = 0,
42 const char *name = 0, WFlags f = 0 );
43 ~TVBrowseKeyEntry();
44
45 void setTableState(TableState *t);
46 void rebuildKeys();
47 void reset();
48
49signals:
50 void searchOnKey(int keyIndex, TVVariant keyData);
51 void sortChanged(int i);
52
53private slots:
54 void changeKeySlot(int);
55 void changeKeyMenuSlot();
56 void searchOnText();
57
58private:
59 QPushButton *resetButton;
60 QToolButton *changeKeyButton;
61 QPopupMenu *keyMenu;
62 int totalKeys;
63 TableState *ts;
64
65 /* each type of possible data entry will be put on the stack */
66 QWidgetStack *ws;
67
68 /* include widgets for each type of data entry you need here. */
69 QLineEdit *textKey;
70 IntEdit *intKey;
71 DateEdit *dateKey;
72 TimeEdit *timeKey;
73};
74
75#endif
diff --git a/noncore/apps/tableviewer/ui/commonwidgets.cpp b/noncore/apps/tableviewer/ui/commonwidgets.cpp
new file mode 100644
index 0000000..0b4f3c2
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/commonwidgets.cpp
@@ -0,0 +1,209 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qlineedit.h>
22#include <qlayout.h>
23#include <qlabel.h>
24#include <qcombobox.h>
25#include <datebookmonth.h>
26#include <qpopupmenu.h>
27#include <qspinbox.h>
28#include "commonwidgets.h"
29
30DateEdit::DateEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 )
31 : QToolButton(parent, name)
32{
33 QPopupMenu *m1 = new QPopupMenu(this);
34 dateSelector = new DateBookMonth(m1, 0, TRUE);
35 m1->insertItem(dateSelector);
36 setPopup(m1);
37 setPopupDelay(0);
38
39 connect(dateSelector, SIGNAL(dateClicked(int, int, int)),
40 this, SLOT(subValueChanged()));
41
42 setText(dateSelector->selectedDate().toString());
43}
44
45
46DateEdit::~DateEdit() {}
47
48QDate DateEdit::date() const
49{
50 return dateSelector->selectedDate();
51}
52
53void DateEdit::setDate(QDate d)
54{
55 dateSelector->setDate(d.year(), d.month(), d.day());
56 setText(d.toString());
57}
58
59QSizePolicy DateEdit::sizePolicy() const
60{
61 QSizePolicy sp;
62 sp.setHorData(QToolButton::sizePolicy().horData());
63 sp.setVerData(QSizePolicy::Fixed);
64
65 return sp;
66}
67
68void DateEdit::clear()
69{
70 QDate today = QDate::currentDate();
71
72 dateSelector->setDate(today.year(), today.month(), today.day());
73 setText(today.toString());
74}
75
76void DateEdit::subValueChanged()
77{
78 QDate current = dateSelector->selectedDate();
79
80 setText(current.toString());
81 emit valueChanged(current);
82}
83
84TimeEdit::TimeEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 )
85 : QWidget(parent, name, f)
86{
87 QHBoxLayout *layout = new QHBoxLayout(this, 0);
88
89 layout->addWidget(hourKey = new QSpinBox(1, 12, 1, this));
90 hourKey->setWrapping(true);
91 hourKey->setMinimumWidth(30);
92 hourKey->setMaximumWidth(35);
93
94 layout->addWidget(new QLabel(" : ", this));
95 layout->addWidget(minuteKey = new QSpinBox(0, 59, 1, this));
96 minuteKey->setWrapping(true);
97 minuteKey->setMinimumWidth(30);
98 minuteKey->setMaximumWidth(35);
99
100 layout->addWidget(new QLabel(" : ", this));
101 layout->addWidget(secondKey = new QSpinBox(0, 59, 1, this, 0));
102 secondKey->setWrapping(true);
103 secondKey->setMinimumWidth(30);
104 secondKey->setMaximumWidth(35);
105
106 layout->addWidget(ampm = new QComboBox(this));
107 ampm->insertItem("AM");
108 ampm->insertItem("PM");
109
110 layout->addStretch(-1);
111
112 clear();
113
114 connect(secondKey, SIGNAL(valueChanged(const QString&)),
115 this, SLOT(subValueChanged()));
116 connect(minuteKey, SIGNAL(valueChanged(const QString&)),
117 this, SLOT(subValueChanged()));
118 connect(hourKey, SIGNAL(valueChanged(const QString&)),
119 this, SLOT(subValueChanged()));
120 connect(ampm, SIGNAL(activated(int)),
121 this, SLOT(subValueChanged()));
122}
123
124
125TimeEdit::~TimeEdit() {}
126
127QTime TimeEdit::time() const
128{
129 int s,m,h;
130
131 s = secondKey->text().toInt();
132 m = minuteKey->text().toInt();
133 h = hourKey->text().toInt();
134
135 if(ampm->currentItem() == 1) {
136 /* pm */
137 h = h + 12;
138 }
139 /* hour now ranges 1->24 */
140
141 if (h == 12)
142 h = 0;
143 if (h == 24)
144 h = 12;
145
146 if(QTime::isValid(h, m, s))
147 return QTime(h, m, s);
148 return QTime(0, 0, 0);
149}
150
151void TimeEdit::setTime(QTime t)
152{
153 int h = t.hour();
154 secondKey->setValue(t.second());
155 minuteKey->setValue(t.minute());
156
157 /* h 0..23 */
158 if (h > 11) {
159 h -= 12;
160 ampm->setCurrentItem(1);
161 } else {
162 ampm->setCurrentItem(0);
163 }
164
165 if (h == 0) h = 12;
166 hourKey->setValue(h);
167}
168
169QSizePolicy TimeEdit::sizePolicy() const
170{
171 QSizePolicy sp;
172 sp.setHorData(QSizePolicy::Preferred);
173 sp.setVerData(QSizePolicy::Fixed);
174
175 return sp;
176}
177
178void TimeEdit::clear()
179{
180 secondKey->setValue(0);
181 minuteKey->setValue(0);
182 hourKey->setValue(12);
183
184 ampm->setCurrentItem(0);
185}
186
187void TimeEdit::subValueChanged()
188{
189 emit valueChanged(time());
190}
191
192IntEdit::IntEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 )
193 : QSpinBox(INT_MIN, INT_MAX, 1, parent, name)
194{
195 setValue(0);
196}
197
198
199IntEdit::~IntEdit() {}
200
201int IntEdit::value()
202{
203 return cleanText().toInt();
204}
205
206void IntEdit::clear()
207{
208 setValue(0);
209}
diff --git a/noncore/apps/tableviewer/ui/commonwidgets.h b/noncore/apps/tableviewer/ui/commonwidgets.h
new file mode 100644
index 0000000..2a9691f
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/commonwidgets.h
@@ -0,0 +1,98 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef Dateedit_H
21#define Dateedit_H
22
23#include <qwidget.h>
24#include <qdatetime.h>
25
26/* inherited classes */
27#include <qtoolbutton.h>
28#include <qspinbox.h>
29
30class DateBookMonth;
31class QComboBox;
32
33class DateEdit : public QToolButton
34{
35 Q_OBJECT
36
37public:
38 DateEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
39 ~DateEdit();
40
41 QDate date() const;
42 void setDate(QDate);
43
44 QSizePolicy sizePolicy() const;
45signals:
46 void valueChanged(const QDate &);
47
48public slots:
49 void clear();
50private slots:
51 void subValueChanged();
52
53private:
54 DateBookMonth *dateSelector;
55};
56
57class TimeEdit : public QWidget
58{
59 Q_OBJECT
60
61public:
62 TimeEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
63 ~TimeEdit();
64
65 QTime time() const;
66 void setTime(QTime);
67
68 QSizePolicy sizePolicy() const;
69signals:
70 void valueChanged(const QTime &);
71
72public slots:
73 void clear();
74private slots:
75 void subValueChanged();
76
77private:
78 QSpinBox *secondKey;
79 QSpinBox *minuteKey;
80 QSpinBox *hourKey;
81 QComboBox *ampm;
82};
83
84/* more for consistency than need */
85class IntEdit : public QSpinBox
86{
87 Q_OBJECT
88
89public:
90 IntEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
91 ~IntEdit();
92
93 int value();
94
95public slots:
96 void clear();
97};
98#endif
diff --git a/noncore/apps/tableviewer/ui/filterkeyentry.cpp b/noncore/apps/tableviewer/ui/filterkeyentry.cpp
new file mode 100644
index 0000000..d108fbd
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/filterkeyentry.cpp
@@ -0,0 +1,208 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "filterkeyentry.h"
21#include "commonwidgets.h"
22
23#include <qwidgetstack.h>
24#include <qcombobox.h>
25#include <qlayout.h>
26#include <qlineedit.h>
27#include <qsizepolicy.h>
28#include <qdatetime.h>
29#include <qhbox.h>
30
31TVFilterKeyEntry::TVFilterKeyEntry(QWidget *parent, const char *name, WFlags f)
32 : QWidget(parent, name, f)
33{
34 int stack_elem = 0;
35
36 layout = new QHBoxLayout(this, 0);
37 layout->setSpacing(0);
38 layout->setMargin(0);
39
40 textEntry = new QHBox(this, 0);
41 textEntry->setSpacing(0);
42 textEntry->setMargin(0);
43
44 intEntry = new QHBox(this, 0);
45 intEntry->setSpacing(0);
46 intEntry->setMargin(0);
47
48 timeEntry = new QHBox(this, 0);
49 timeEntry->setSpacing(0);
50 timeEntry->setMargin(0);
51
52 dateEntry = new QHBox(this, 0);
53 dateEntry->setSpacing(0);
54 dateEntry->setMargin(0);
55
56 textCombo = new QComboBox(textEntry, 0);
57 textKey = new QLineEdit(textEntry, 0);
58
59 /* Build the text combo list */
60 textCombo->insertItem("less than");
61 textCombo->insertItem("more than");
62 textCombo->insertItem("equal to");
63 textCombo->insertItem("containing");
64 textCombo->insertItem("starting with");
65 textCombo->insertItem("ending with");
66
67 intCombo = new QComboBox(intEntry, 0);
68 intKey = new IntEdit(intEntry, 0);
69
70 /* Build the int combo list */
71 intCombo->insertItem("less than");
72 intCombo->insertItem("more than");
73 intCombo->insertItem("equal to");
74
75 timeCombo = new QComboBox(timeEntry, 0);
76 timeKey = new TimeEdit(timeEntry, 0);
77
78 /* Build the time combo list */
79 timeCombo->insertItem("less than");
80 timeCombo->insertItem("more than");
81 timeCombo->insertItem("equal to");
82
83 dateCombo = new QComboBox(dateEntry, 0);
84 dateKey = new DateEdit(dateEntry, 0);
85
86 /* Build the date combo list */
87 dateCombo->insertItem("less than");
88 dateCombo->insertItem("more than");
89 dateCombo->insertItem("equal to");
90
91 ts = 0;
92
93 ws = new QWidgetStack(this, 0);
94 ws->setMargin(0);
95 ws->addWidget(textEntry, TVVariant::String);
96 ws->addWidget(intEntry, TVVariant::Int);
97 ws->addWidget(timeEntry, TVVariant::Time);
98 ws->addWidget(dateEntry, TVVariant::Date);
99
100 /* connect the signals down */
101 connect(textKey, SIGNAL(textChanged(const QString&)),
102 this, SIGNAL(valueChanged()));
103 connect(intKey, SIGNAL(valueChanged(int)),
104 this, SIGNAL(valueChanged()));
105 connect(dateKey, SIGNAL(valueChanged(const QDate&)),
106 this, SIGNAL(valueChanged()));
107 connect(timeKey, SIGNAL(valueChanged(const QTime&)),
108 this, SIGNAL(valueChanged()));
109
110 connect(intCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
111 connect(textCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
112 connect(timeCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
113 connect(dateCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
114
115 ws->raiseWidget(TVVariant::String);
116 layout->addWidget(ws);
117
118 current_type = TVVariant::String;
119}
120
121/*!
122 Destructs the widget
123*/
124TVFilterKeyEntry::~TVFilterKeyEntry()
125{
126}
127
128void TVFilterKeyEntry::setKey(int i)
129{
130
131 if (!ts) return;
132 if (!ts->kRep) return;
133
134 /* set up to raise appropriate widget set */
135 if (current_type != ts->kRep->getKeyType(i)) {
136 current_type = ts->kRep->getKeyType(i);
137 ws->raiseWidget(current_type);
138 }
139}
140
141void TVFilterKeyEntry::setTableState(TableState *t) {
142 int i;
143 ts = t;
144 if(!t) return;
145 if (!t->kRep)
146 return;
147 if (t->kRep->getNumFields() < 1)
148 return;
149 setKey(0);
150 /* set up the the menu stuff.. */
151}
152
153CmpType TVFilterKeyEntry::getCompareType()
154{
155
156 switch(current_type) {
157 case TVVariant::String: {
158 CmpType k = (CmpType) textCombo->currentItem();
159 return k;
160 }
161 case TVVariant::Int: {
162 CmpType k = (CmpType) intCombo->currentItem();
163 return k;
164 }
165 case TVVariant::Time: {
166 CmpType k = (CmpType) timeCombo->currentItem();
167 return k;
168 }
169 case TVVariant::Date: {
170 CmpType k = (CmpType) dateCombo->currentItem();
171 return k;
172 }
173 default:
174 break;
175 }
176 return ct_equal;
177}
178
179/* MUST return a valid pointer */
180TVVariant TVFilterKeyEntry::getCompareValue()
181{
182 TVVariant sendkey;
183 int tmp;
184
185 switch(current_type) {
186 case TVVariant::String:
187 sendkey = TVVariant(QString(textKey->text()));
188 break;
189 case TVVariant::Int: {
190 sendkey = TVVariant(intKey->value());
191 break;
192 }
193 case TVVariant::Time: {
194 sendkey = TVVariant(QTime(timeKey->time()));
195 break;
196 }
197 case TVVariant::Date: {
198 sendkey = TVVariant(QDate(dateKey->date()));
199 break;
200 }
201 default: {
202 sendkey = TVVariant(0);
203 qWarning("TVFilterKeyEntry::getCompareValue() "
204 "cannot work out data type");
205 }
206 }
207 return sendkey;
208}
diff --git a/noncore/apps/tableviewer/ui/filterkeyentry.h b/noncore/apps/tableviewer/ui/filterkeyentry.h
new file mode 100644
index 0000000..260e250
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/filterkeyentry.h
@@ -0,0 +1,96 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef FilterKeyEntry_H
21#define FilterKeyEntry_H
22
23#include <qwidget.h>
24#include <qhbox.h>
25#include <qlayout.h>
26#include "../db/common.h"
27
28/* Forward class declarations */
29class QWidgetStack;
30class QToolButton;
31class QLineEdit;
32class DateEdit;
33class TimeEdit;
34class IntEdit;
35class QPopupMenu;
36class QComboBox;
37
38typedef enum _CmpType {
39 ct_less = 0,
40 ct_more,
41 ct_equal,
42 ct_contains,
43 ct_startswith,
44 ct_endswith
45} CmpType;
46
47
48class TVFilterKeyEntry: public QWidget
49{
50 Q_OBJECT
51public:
52 TVFilterKeyEntry( QWidget *parent = 0,
53 const char *name = 0, WFlags f = 0 );
54 ~TVFilterKeyEntry();
55
56 void setTableState(TableState *t);
57 void setKey(int i);
58
59 CmpType getCompareType();
60 TVVariant getCompareValue();
61
62signals:
63 void valueChanged();
64
65private:
66 /* include widgets for each type of data entry you need here. */
67 QLineEdit *textKey;
68 QComboBox *textCombo;
69 QHBox *textEntry;
70
71 IntEdit *intKey;
72 QComboBox *intCombo;
73 QHBox *intEntry;
74
75 TimeEdit *timeKey;
76 QComboBox *timeCombo;
77 QHBox *timeEntry;
78
79 DateEdit *dateKey;
80 QComboBox *dateCombo;
81 QHBox *dateEntry;
82
83 TableState *ts;
84
85 /* each type of possible data entry will be put on the stack */
86 QWidgetStack *ws;
87
88 /* This allows for the inherited functions dealing with prefered size
89 * etc to simply get the information from the layout.
90 */
91 QHBoxLayout *layout;
92
93 TVVariant::KeyType current_type;
94};
95
96#endif
diff --git a/noncore/apps/tableviewer/ui/tvbrowseview.cpp b/noncore/apps/tableviewer/ui/tvbrowseview.cpp
new file mode 100644
index 0000000..f6da7b1
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvbrowseview.cpp
@@ -0,0 +1,122 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "tvbrowseview.h"
21#include "browsekeyentry.h"
22#include <qtoolbutton.h>
23#include <qtextview.h>
24#include <qtextbrowser.h>
25#include <qlayout.h>
26
27/*!
28 \class TVBrowseView
29 \brief The widget describing how to draw the browse view user interface
30
31 This widget allows for the user to browse through the table, one element
32 at a time, or search on a single key. Its main goal is to show a
33 single element in a readable format and make it easy for the user to
34 rapidly find specific elements in the table.
35*/
36
37/*!
38 Constructs a new TVBrowseView widget
39*/
40TVBrowseView::TVBrowseView(TableState *t, QWidget* parent = 0, const char *name = 0,
41 WFlags fl =0)
42{
43 if (!name)
44 setName("BrowseView");
45
46 setSizePolicy(QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding, 0, 0, sizePolicy().hasHeightForWidth() ) );
47 QVBoxLayout *vlayout = new QVBoxLayout(this);
48 textViewDisplay = new QTextBrowser(this, "textViewDisplay");
49 vlayout->addWidget( textViewDisplay );
50
51 keyEntry = new TVBrowseKeyEntry(this, "keyEntry");
52 vlayout->addWidget( keyEntry );
53
54 /* connect the signals down */
55
56 connect(keyEntry, SIGNAL(searchOnKey(int, TVVariant)),
57 this, SIGNAL(searchOnKey(int, TVVariant)));
58 connect(keyEntry, SIGNAL(sortChanged(int)),
59 this, SIGNAL(sortChanged(int)));
60
61 ts = t;
62 keyEntry->setTableState(t);
63}
64
65/*!
66 Destroys the TVBrowseView widget
67*/
68TVBrowseView::~TVBrowseView()
69{
70}
71
72void TVBrowseView::rebuildData()
73{
74 if(!ts)
75 return;
76 if(!ts->current_elem) {
77 /* also disable buttons */
78 textViewDisplay->setText("");
79 return;
80 }
81
82 setDisplayText(ts->current_elem);
83}
84
85/* Reset to initial state */
86void TVBrowseView::reset()
87{
88 textViewDisplay->setText("");
89 keyEntry->reset();
90}
91
92/*!
93 sets the data element to be displayed to element
94*/
95void TVBrowseView::setDisplayText(const DataElem *element)
96{
97 QString rep = "";
98
99 KeyListIterator it(*ts->kRep);
100
101 while (it.current()) {
102 if (element->hasValidValue(it.currentKey())) {
103 if(it.currentKey() == ts->current_column) {
104 rep += "<A name=\"ckey\"></A><B><FONT COLOR=#FF0000>"
105 + it.current()->name()
106 + ":</FONT></B> ";
107 } else {
108 rep += "<B>" + it.current()->name() + ":</B> ";
109 }
110 rep += element->toQString(it.currentKey()) + "<BR>";
111 }
112 ++it;
113 }
114
115 textViewDisplay->setText(rep);
116 textViewDisplay->scrollToAnchor("ckey");
117}
118
119void TVBrowseView::rebuildKeys()
120{
121 keyEntry->rebuildKeys();
122}
diff --git a/noncore/apps/tableviewer/ui/tvbrowseview.h b/noncore/apps/tableviewer/ui/tvbrowseview.h
new file mode 100644
index 0000000..1daff1c
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvbrowseview.h
@@ -0,0 +1,55 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef Tvbrowseview_H
21#define Tvbrowseview_H
22
23#include "../db/common.h"
24#include <qwidget.h>
25
26class QTextBrowser;
27class TVBrowseKeyEntry;
28
29class TVBrowseView : public QWidget
30{
31 Q_OBJECT
32
33signals:
34 void searchOnKey(int keyIndex, TVVariant keyValue);
35 void sortChanged(int);
36
37public:
38 TVBrowseView(TableState *t, QWidget* parent = 0,
39 const char* name = 0, WFlags fl = 0);
40 ~TVBrowseView();
41
42 /* Access Methods */
43 void setDisplayText(const DataElem *);
44 void rebuildKeys();
45 void rebuildData();
46 void reset();
47
48private:
49 TableState *ts;
50
51 QTextBrowser* textViewDisplay;
52 TVBrowseKeyEntry *keyEntry;
53};
54
55#endif
diff --git a/noncore/apps/tableviewer/ui/tveditview.cpp b/noncore/apps/tableviewer/ui/tveditview.cpp
new file mode 100644
index 0000000..ba2bd06
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tveditview.cpp
@@ -0,0 +1,235 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22/* The edit view widget. For each key in the DB display an
23 * appropriate edit box, and a 'key' button to change that particular
24 * key information (delete or edit).
25 *
26 * Bottem line should be a 'new key' button. Should be able to scroll
27 * in both directions.
28 */
29
30#include "tveditview.h"
31#include "commonwidgets.h"
32
33#include <qlayout.h>
34#include <qgrid.h>
35#include <qvbox.h>
36#include <qlineedit.h>
37#include <qcheckbox.h>
38#include <qlist.h>
39#include <qlabel.h>
40#include <qscrollview.h>
41#include <qsignalmapper.h>
42
43TVEditView::TVEditView(TableState *s, DataElem *d, QWidget* parent = 0,
44 const char *name = 0, WFlags fl =0) : QDialog(parent, name, true, fl)
45{
46 if (!name)
47 setName("TVEditView");
48
49 QVBoxLayout *layout = new QVBoxLayout(this, 0); /* only so that will resize
50 correctly in other
51 widgets */
52
53 toggles = new QSignalMapper(this);
54 QScrollView *sv = new QScrollView(this, 0);
55 sv->setResizePolicy(QScrollView::AutoOneFit);
56
57 layout->addWidget(sv);
58
59 editDisplay = new QGrid(3, sv, 0);
60 editDisplay->setSpacing(3);
61 sv->addChild(editDisplay);
62
63 connect(toggles, SIGNAL(mapped(int)), this, SLOT(toggleEnabled(int)));
64
65 setData(s, d);
66#ifdef Q_WS_QWS
67 showMaximized();
68#endif
69}
70
71TVEditView::~TVEditView()
72{
73}
74
75/*! set up the widgets in the grid, Set up initial values */
76void TVEditView::setData(TableState *t, DataElem *d)
77{
78
79 /* TODO need to somehow clear old children... a delete of each
80 * child? */
81 keyIds.clear();
82
83 KeyListIterator it(*t->kRep);
84
85 int i = 0;
86 while(it.current()) {
87 if (t->kRep->validIndex(it.currentKey())) {
88 new QLabel(it.current()->name(), editDisplay);
89 keyIds.insert(i, it.currentKey());
90 if (d->hasValidValue(it.currentKey())) {
91 switch(it.current()->type()) {
92 case TVVariant::String: {
93 QLineEdit *edit = new QLineEdit(editDisplay, 0);
94 edit->setText(d->getField(it.currentKey()).toString());
95 edits.append(edit);
96 break;
97 }
98 case TVVariant::Int: {
99 IntEdit *edit = new IntEdit(editDisplay, 0);
100 edit->setValue(d->getField(it.currentKey()).toInt());
101 edits.append(edit);
102 break;
103 }
104 case TVVariant::Time: {
105 TimeEdit *edit = new TimeEdit(editDisplay, 0);
106 edit->setTime(d->getField(it.currentKey()).toTime());
107 edits.append(edit);
108 break;
109 }
110 case TVVariant::Date: {
111 DateEdit *edit = new DateEdit(editDisplay, 0);
112 edit->setDate(d->getField(it.currentKey()).toDate());
113 edits.append(edit);
114 break;
115 }
116 default:
117 edits.append(new QLabel("<B><I>Uknown key type</I></B>", editDisplay));
118 }
119 QCheckBox *tb = new QCheckBox(editDisplay);
120 tb->setChecked(TRUE);
121 toggles->setMapping(tb, i);
122 connect(tb, SIGNAL(clicked()), toggles, SLOT(map()));
123 buttons.append(tb);
124 } else {
125 /* No valid value.. set to null */
126 switch(it.current()->type()) {
127 case TVVariant::String: {
128 QLineEdit *edit = new QLineEdit(editDisplay, 0);
129 edit->setEnabled(false);
130 edits.append(edit);
131 break;
132 }
133 case TVVariant::Int: {
134 IntEdit *edit = new IntEdit(editDisplay, 0);
135 edit->setEnabled(false);
136 edits.append(edit);
137 break;
138 }
139 case TVVariant::Time: {
140 TimeEdit *edit = new TimeEdit(editDisplay, 0);
141 edit->setEnabled(false);
142 edits.append(edit);
143 break;
144 }
145 case TVVariant::Date: {
146 DateEdit *edit = new DateEdit(editDisplay, 0);
147 edit->setEnabled(false);
148 edits.append(edit);
149 break;
150 }
151 default:
152 edits.append(new QLabel("<B><I>Uknown key type</I></B>", editDisplay));
153 }
154 QCheckBox *tb = new QCheckBox(editDisplay);
155 tb->setChecked(FALSE);
156 toggles->setMapping(tb, i);
157 connect(tb, SIGNAL(clicked()), toggles, SLOT(map()));
158 buttons.append(tb);
159 }
160 i++;
161 }
162 ++it;
163 }
164 num_edits = i;
165}
166
167void TVEditView::toggleEnabled(int i) {
168
169 if(edits.at(i)->isEnabled()) {
170 edits.at(i)->setEnabled(false);
171 buttons.at(i)->setChecked(FALSE);
172 } else {
173 edits.at(i)->setEnabled(true);
174 buttons.at(i)->setChecked(TRUE);
175 }
176}
177
178bool TVEditView::openEditItemDialog(TableState *ts, DataElem *d,
179 QWidget *parent)
180{
181 int i;
182 int keyId;
183
184 if(!ts) return 0;
185 if(!d) return 0;
186 if(!ts->kRep) return 0;
187
188 TVEditView *dlg = new TVEditView(ts, d, parent);
189
190 if (dlg->exec() == QDialog::Accepted ) {
191 /* update the element, basically for each
192 edits, if isEnabled, set Value, else unsetField */
193
194 for(i = 0; i < dlg->num_edits; i++) {
195 keyId = dlg->keyIds[i];
196 if(dlg->edits.at(i)->isEnabled()) {
197 switch(d->getFieldType(keyId)) {
198 case TVVariant::String: {
199 TVVariant value = TVVariant(
200 ((QLineEdit *)dlg->edits.at(i))->text());
201 d->setField(keyId, value);
202 break;
203 }
204 case TVVariant::Int: {
205 TVVariant value = TVVariant(
206 ((IntEdit *)dlg->edits.at(i))->value());
207 d->setField(keyId, value);
208 break;
209 }
210 case TVVariant::Time: {
211 TVVariant value = TVVariant(
212 ((TimeEdit *)dlg->edits.at(i))->time());
213 d->setField(keyId, value);
214 break;
215 }
216 case TVVariant::Date: {
217 TVVariant value = TVVariant(
218 ((DateEdit *)dlg->edits.at(i))->date());
219 d->setField(keyId, value);
220 break;
221 }
222 default:
223 break;
224 }
225 } else {
226 /* unset the field */
227 d->unsetField(keyId);
228 }
229 }
230 delete dlg;
231 return TRUE;
232 }
233
234 return FALSE;
235}
diff --git a/noncore/apps/tableviewer/ui/tveditview.h b/noncore/apps/tableviewer/ui/tveditview.h
new file mode 100644
index 0000000..94c51d9
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tveditview.h
@@ -0,0 +1,62 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef Tveditview_H
22#define Tveditview_H
23
24#include <qwidget.h>
25#include <qlist.h>
26#include <qdialog.h>
27#include <qmap.h>
28#include "../db/common.h"
29
30class QGrid;
31class QSignalMapper;
32class QCheckBox;
33
34class TVEditView : public QDialog
35{
36 Q_OBJECT
37
38public:
39 TVEditView(TableState *s, DataElem *d, QWidget* parent = 0,
40 const char* name = 0, WFlags fl = 0);
41 ~TVEditView();
42
43 static bool openEditItemDialog(TableState *s, DataElem *d, QWidget *parent);
44
45protected slots:
46 void toggleEnabled(int);
47
48protected:
49
50 void setData(TableState *s, DataElem *d);
51
52 QGrid *editDisplay;
53 QList<QWidget> edits;
54 QList<QCheckBox> buttons;
55 QSignalMapper *toggles;
56
57 QMap<int,int> keyIds;
58
59 int num_edits;
60};
61
62#endif
diff --git a/noncore/apps/tableviewer/ui/tvfilterview.cpp b/noncore/apps/tableviewer/ui/tvfilterview.cpp
new file mode 100644
index 0000000..72d39d6
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvfilterview.cpp
@@ -0,0 +1,304 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "tvfilterview.h"
21#include <qtoolbutton.h>
22#include <qcombobox.h>
23#include <qlistview.h>
24#include <qlayout.h>
25#include <qheader.h>
26#include <qpushbutton.h>
27#include <qlabel.h>
28
29TVFilterView::TVFilterView(TableState *t, QWidget* parent = 0,
30 const char *name = 0, WFlags fl =0) : QDialog(parent, name, TRUE, fl)
31{
32 if ( !name )
33 setName( "Filter View" );
34
35 QVBoxLayout *vlayout = new QVBoxLayout(this);
36
37 display = new QListView(this, "display");
38 display->addColumn("Key");
39 display->addColumn("Constraint");
40 display->addColumn("Value");
41 display->header()->setClickEnabled(FALSE);
42 display->header()->setResizeEnabled(FALSE);
43
44 vlayout->addWidget(display);
45
46 QHBoxLayout *hlayout = new QHBoxLayout;
47 hlayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
48
49 newFilterButton = new QPushButton(this, "new Filter");
50 newFilterButton->setMaximumSize(QSize(50, 32767));
51 newFilterButton->setText("New");
52 hlayout->addWidget(newFilterButton);
53
54 deleteFilterButton = new QPushButton(this, "delete Filter");
55 deleteFilterButton->setMaximumSize(QSize(50, 32767));
56 deleteFilterButton->setText("Delete");
57 hlayout->addWidget(deleteFilterButton);
58
59 clearFilterButton = new QPushButton(this, "delete Filter");
60 clearFilterButton->setMaximumSize(QSize(60, 32767));
61 clearFilterButton->setText("Clear All");
62 hlayout->addWidget(clearFilterButton);
63
64 vlayout->addLayout(hlayout);
65
66 QHBoxLayout *hlayout2 = new QHBoxLayout;
67
68 keyNameCombo = new QComboBox(FALSE, this, "key name");
69 keyNameCombo->setEnabled(FALSE);
70 hlayout2->addWidget(keyNameCombo);
71
72 QLabel *label = new QLabel(this);
73 label->setText("has value");
74 hlayout2->addWidget(label);
75
76 keyEntry = new TVFilterKeyEntry(this, "key entry");
77 keyEntry->setEnabled(FALSE);
78
79 vlayout->addLayout(hlayout2);
80 vlayout->addWidget(keyEntry);
81
82 connect(newFilterButton, SIGNAL( clicked() ), this, SLOT( newTerm() ));
83 connect(deleteFilterButton, SIGNAL( clicked() ), this, SLOT( deleteTerm()));
84 connect(clearFilterButton, SIGNAL( clicked() ), this, SLOT( clearTerms()));
85
86 connect(keyEntry, SIGNAL(valueChanged()), this, SLOT( updateTerm() ));
87 connect(keyNameCombo, SIGNAL(activated(int)), this, SLOT( updateTerm() ));
88
89 connect(display, SIGNAL(selectionChanged(QListViewItem*)), this,
90 SLOT(setTerm(QListViewItem *)));
91
92 ts = t;
93 current = 0;
94 terms.setAutoDelete(true);
95 do_filter = false;
96
97#ifdef Q_WS_QWS
98 showMaximized();
99#endif
100}
101
102/*!
103 Destroys the TVFilterView widget
104*/
105TVFilterView::~TVFilterView()
106{
107}
108
109void TVFilterView::rebuildData()
110{
111}
112
113void TVFilterView::reset()
114{
115 keyNameCombo->clear();
116 keyIds.clear();
117}
118
119void TVFilterView::rebuildKeys()
120{
121 int i;
122
123 if (!ts) return;
124 if(!ts->kRep) return;
125 keyEntry->setTableState(ts);
126
127 /* set up the list of keys that can be compared on */
128 keyNameCombo->clear();
129 KeyListIterator it(*ts->kRep);
130
131 i = 0;
132 while(it.current()) {
133 if(ts->kRep->validIndex(it.currentKey())) {
134 keyNameCombo->insertItem(it.current()->name());
135 keyIds.insert(i, it.currentKey());
136 ++i;
137 }
138 ++it;
139 }
140}
141
142bool TVFilterView::passesFilter(DataElem *d) {
143 if (!filterActive()) return true;
144
145
146 FilterTerm *t;
147
148 for (t = terms.first(); t != 0; t = terms.next() ) {
149 /* check against filter */
150 switch(t->ct) {
151 case ct_less:
152 if (!d->lessThan(t->keyIndex, t->value))
153 return false;
154 break;
155 case ct_more:
156 if (!d->moreThan(t->keyIndex, t->value))
157 return false;
158 break;
159 case ct_equal:
160 if (!d->equalTo(t->keyIndex, t->value))
161 return false;
162 break;
163 case ct_contains:
164 if (!d->contains(t->keyIndex, t->value))
165 return false;
166 break;
167 case ct_startswith:
168 if (!d->startsWith(t->keyIndex, t->value))
169 return false;
170 break;
171 case ct_endswith:
172 if (!d->endsWith(t->keyIndex, t->value))
173 return false;
174 break;
175 default:
176 qWarning("TVFilterView::passesFilter() "
177 "unrecognized filter type");
178 return false;
179 }
180 }
181 return true;
182}
183
184bool TVFilterView::filterActive() const
185{
186 /* when button operated, also check the do_filter value
187 return do_filter;
188 */
189 if (terms.isEmpty())
190 return false;
191 return true;
192}
193
194/* SLOTS */
195void TVFilterView::newTerm()
196{
197 if (!ts) return;
198
199 FilterTerm *term = new FilterTerm;
200 current = term;
201
202 term->view = 0;
203
204 updateTerm();
205
206 display->setSelected(term->view, true);
207 terms.append(term);
208
209 keyEntry->setEnabled(true);
210 keyNameCombo->setEnabled(true);
211}
212
213void TVFilterView::updateTerm()
214{
215 FilterTerm *term;
216 /* Read the widget values (keyname, compare type, value)
217 * and build the lists */
218 if (!ts) return;
219 if (!current) return;
220
221 QString keyString;
222 QString cmpString;
223 QString vString;
224
225 term = current;
226
227 /* create new list item, set initial values, enable widgets */
228 term->keyIndex = keyIds[keyNameCombo->currentItem()];
229 keyEntry->setKey(term->keyIndex); /* so the next two items make sense */
230 term->ct = keyEntry->getCompareType(),
231 term->value = keyEntry->getCompareValue();
232
233 keyString = keyNameCombo->currentText();
234
235 switch(term->ct) {
236 case ct_less:
237 cmpString = " less than ";
238 break;
239 case ct_more:
240 cmpString = " more than ";
241 break;
242 case ct_equal:
243 cmpString = " equal to ";
244 break;
245 case ct_contains:
246 cmpString = " containing ";
247 break;
248 case ct_startswith:
249 cmpString = " starting with ";
250 break;
251 case ct_endswith:
252 cmpString = " ending with ";
253 break;
254 default:
255 cmpString = " ERROR ";
256 }
257
258 vString = term->value.toString();
259
260 /* remove old view */
261 if (term->view)
262 delete(term->view);
263 term->view = new QListViewItem(display, 0, keyString, cmpString, vString);
264 display->setSelected(term->view, true);
265}
266
267/* deletes current term */
268void TVFilterView::deleteTerm()
269{
270 if(!current) return;
271 if (current->view)
272 delete(current->view);
273
274 terms.removeRef(current);
275
276 current = terms.first();
277
278 if(terms.isEmpty()) {
279 keyEntry->setEnabled(false);
280 keyNameCombo->setEnabled(false);
281 }
282}
283
284/* clears all terminations */
285void TVFilterView::clearTerms()
286{
287 while(current)
288 deleteTerm();
289}
290
291void TVFilterView::setTerm(QListViewItem *target)
292{
293 /* Iterate through the list to find item with view=target..
294 * set as current, delete */
295 FilterTerm *term = current;
296
297 for (current = terms.first(); current != 0; current = terms.next() )
298 if (current->view == target)
299 break;
300
301 if (!current) {
302 current = term;
303 }
304}
diff --git a/noncore/apps/tableviewer/ui/tvfilterview.h b/noncore/apps/tableviewer/ui/tvfilterview.h
new file mode 100644
index 0000000..5de87b9
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvfilterview.h
@@ -0,0 +1,88 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef Tvfilterview_H
21#define Tvfilterview_H
22
23#include "filterkeyentry.h"
24#include "../db/common.h"
25#include <qlist.h>
26#include <qmap.h>
27#include <qdialog.h>
28
29class QListViewItem;
30class QPushButton;
31class QListView;
32class TVFilterKeyEntry;
33
34class TVFilterView : public QDialog
35{
36 Q_OBJECT
37
38signals:
39 void editView();
40 void listView();
41 void browseView();
42 void loadFile();
43
44protected slots:
45 void newTerm();
46 void deleteTerm();
47 void clearTerms();
48 void updateTerm();
49 void setTerm(QListViewItem *);
50
51public:
52 TVFilterView(TableState *t, QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
53 ~TVFilterView();
54
55 /* Access Methods */
56 void rebuildKeys();
57 void rebuildData();
58 void reset();
59
60 bool passesFilter(DataElem *d);
61 bool filterActive() const; /* return true if and only if filtering is on */
62
63 QListView* display;
64 QPushButton* newFilterButton;
65 QPushButton* deleteFilterButton;
66 QPushButton* clearFilterButton;
67 QComboBox* keyNameCombo;
68
69 TVFilterKeyEntry* keyEntry;
70private:
71
72 typedef struct _FilterTerm {
73 int keyIndex;
74 CmpType ct;
75 TVVariant value;
76 QListViewItem *view;
77 } FilterTerm;
78
79 QList<FilterTerm> terms;
80 FilterTerm *current;
81 bool do_filter;
82
83 TableState *ts;
84
85 QMap<int, int> keyIds;
86};
87
88#endif
diff --git a/noncore/apps/tableviewer/ui/tvkeyedit.cpp b/noncore/apps/tableviewer/ui/tvkeyedit.cpp
new file mode 100644
index 0000000..fb7b7fe
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvkeyedit.cpp
@@ -0,0 +1,254 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "tvkeyedit.h"
21#include <qtoolbutton.h>
22#include <qlineedit.h>
23#include <qcombobox.h>
24#include <qlistview.h>
25#include <qmessagebox.h>
26#include <stdlib.h>
27#include <qpushbutton.h>
28
29/* QList view item... ?? that can store and update the values that I will
30 * be changing */
31
32class TVKEListViewItem : public QListViewItem
33{
34public:
35 TVKEListViewItem(QString n, TVVariant::KeyType kt, int p, QListView *parent) :
36 QListViewItem(parent)
37 {
38 name = n;
39 keyType = kt;
40 position = p;
41 }
42
43 QString text(int i) const
44 {
45 if(i) {
46 return TVVariant::typeToName(keyType);
47 }
48 return name;
49 }
50
51 /* always sort by key index, ignore i */
52 QString key(int, bool) const
53 {
54 return QString().sprintf("%08d", position);
55 }
56
57 void setText(int i, const QString &)
58 {
59 ;
60 }
61
62 QString getName() const
63 {
64 return name;
65 }
66
67 void setName(QString n)
68 {
69 name = n;
70 repaint();
71 }
72
73 TVVariant::KeyType getKeyType() const
74 {
75 return keyType;
76 }
77
78 void setKeyType(TVVariant::KeyType k)
79 {
80 keyType = k;
81 repaint();
82 }
83
84 inline int getPos() const
85 {
86 return position;
87 }
88
89private:
90 QString name;
91 TVVariant::KeyType keyType;
92 int position;
93};
94
95TVKeyEdit::TVKeyEdit(TableState *t, QWidget* parent = 0, const char *name = 0,
96 WFlags fl = 0) : TVKeyEdit_gen(parent, name, true, fl)
97{
98 int i;
99 ts = t;
100
101 if(!ts) return;
102 if(!ts->kRep) return;
103
104 working_state = *ts->kRep;
105
106 i = 1;
107 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
108 i++;
109 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
110 i++;
111 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
112 i++;
113 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
114
115 KeyListIterator it(*ts->kRep);
116 while(it.current()) {
117 if(t->kRep->validIndex(it.currentKey())) {
118 new TVKEListViewItem(it.current()->name(),
119 it.current()->type(),
120 it.currentKey(),
121 display);
122 }
123 ++it;
124 }
125 num_keys = ts->kRep->getNumFields();
126 if(display->childCount() > 0) {
127 display->setCurrentItem(display->firstChild());
128 setTerm(display->currentItem());
129 } else {
130 deleteKeyButton->setEnabled(FALSE);
131 clearKeysButton->setEnabled(FALSE);
132 keyNameEdit->setEnabled(FALSE);
133 keyTypeEdit->setEnabled(FALSE);
134 }
135
136 display->setSorting(0);
137#ifdef Q_WS_QWS
138 showMaximized();
139#endif
140}
141
142/*!
143 Destroys the TVKeyEdit widget
144*/
145TVKeyEdit::~TVKeyEdit()
146{
147}
148
149/* SLOTS */
150void TVKeyEdit::newTerm()
151{
152 /* new item, make current Item */
153 int i;
154
155 i = working_state.addKey("<New Key>", TVVariant::String);
156 //working_state.setNewFlag(i, TRUE);
157 TVKEListViewItem *nItem = new TVKEListViewItem("<New Key>",
158 TVVariant::String,
159 i,
160 display);
161 display->setCurrentItem(nItem);
162 setTerm(nItem);
163
164 num_keys++;
165 if(display->childCount() == 1) {
166 deleteKeyButton->setEnabled(TRUE);
167 clearKeysButton->setEnabled(TRUE);
168 keyNameEdit->setEnabled(TRUE);
169 keyTypeEdit->setEnabled(TRUE);
170 }
171}
172
173void TVKeyEdit::updateTerm(const QString &newName)
174{
175 /* TODO if name matches a deleted term, prompt for
176 renewing old data instead */
177 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
178 if(i) {
179 i->setName(newName);
180 working_state.setKeyName(i->getPos(), newName);
181 }
182}
183
184void TVKeyEdit::updateTerm(int t)
185{
186 /* t is an index to a combo in a menu, NOT a type */
187 t++; /* menu counts from 0, types count from 1 */
188 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
189 if (i) {
190 i->setKeyType((TVVariant::KeyType)t);
191 working_state.setKeyType(i->getPos(), (TVVariant::KeyType)t);
192 }
193}
194
195/* deletes current term
196 * really just marks key as deleted so is now invalid.
197 * the actual delete will happen when data is 'cleaned'
198 * or when file is saved.
199 */
200
201void TVKeyEdit::deleteTerm()
202{
203 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
204 if (i) {
205 working_state.setDeleteFlag(i->getPos(), TRUE);
206 delete i;
207 }
208 if(!display->childCount()) {
209 /* disable the delete and clear buttons, etc */
210 deleteKeyButton->setEnabled(FALSE);
211 clearKeysButton->setEnabled(FALSE);
212 keyNameEdit->setEnabled(FALSE);
213 keyTypeEdit->setEnabled(FALSE);
214 }
215}
216
217/* clears all terminations */
218void TVKeyEdit::clearTerms()
219{
220 /* should pop up a warning */
221 if (QMessageBox::warning(this, "Delete all keys",
222 "Are you sure you want to\ndelete all the keys?",
223 "Yes", "No") == 0)
224 {
225 while(display->currentItem())
226 deleteTerm();
227 }
228}
229
230void TVKeyEdit::setTerm(QListViewItem *target)
231{
232 /* need to update the widgets to show keys values */
233 keyNameEdit->setText(((TVKEListViewItem *)target)->getName());
234 int t = (int)(((TVKEListViewItem *)target)->getKeyType());
235 t--;
236 keyTypeEdit->setCurrentItem(t);
237}
238
239KeyList* TVKeyEdit::openEditKeysDialog(TableState *t, QWidget *parent = 0)
240{
241 if(!t)
242 return 0;
243 if(!t->kRep)
244 return 0;
245
246 TVKeyEdit *dlg = new TVKeyEdit(t, parent);
247
248 if ((dlg->exec() == QDialog::Accepted) &&
249 (dlg->working_state != *t->kRep))
250 {
251 return (new KeyList(dlg->working_state));
252 }
253 return 0;
254}
diff --git a/noncore/apps/tableviewer/ui/tvkeyedit.h b/noncore/apps/tableviewer/ui/tvkeyedit.h
new file mode 100644
index 0000000..5e80b66
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvkeyedit.h
@@ -0,0 +1,56 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef Tvkeyedit_H
21#define Tvkeyedit_H
22
23#include "tvkeyedit_gen.h"
24#include "../db/common.h"
25
26class TVKeyEdit : public TVKeyEdit_gen
27{
28 Q_OBJECT
29
30signals:
31 void listView();
32 void browseView();
33
34protected slots:
35 void newTerm();
36 void deleteTerm();
37 void clearTerms();
38 void updateTerm(int);
39 void updateTerm(const QString &);
40 void setTerm(QListViewItem *);
41
42public:
43 TVKeyEdit(TableState *ts, QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
44 ~TVKeyEdit();
45
46
47 static KeyList *openEditKeysDialog(TableState *ts, QWidget *parent);
48
49private:
50
51 TableState *ts;
52 int num_keys;
53 KeyList working_state;
54};
55
56#endif
diff --git a/noncore/apps/tableviewer/ui/tvkeyedit_gen.ui b/noncore/apps/tableviewer/ui/tvkeyedit_gen.ui
new file mode 100644
index 0000000..5c19d06
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvkeyedit_gen.ui
@@ -0,0 +1,239 @@
1<!DOCTYPE UI><UI>
2<class>TVKeyEdit_gen</class>
3<comment>Dialog for editing the keys and key types</comment>
4<author>Ian Walters</author>
5<forward>class QListViewItem;</forward>
6<widget>
7 <class>QDialog</class>
8 <property stdset="1">
9 <name>name</name>
10 <cstring>TVKeyEdit_gen</cstring>
11 </property>
12 <property stdset="1">
13 <name>geometry</name>
14 <rect>
15 <x>0</x>
16 <y>0</y>
17 <width>194</width>
18 <height>418</height>
19 </rect>
20 </property>
21 <property stdset="1">
22 <name>caption</name>
23 <string>TableViewer - Edit Keys</string>
24 </property>
25 <vbox>
26 <property stdset="1">
27 <name>margin</name>
28 <number>0</number>
29 </property>
30 <property stdset="1">
31 <name>spacing</name>
32 <number>0</number>
33 </property>
34 <widget>
35 <class>QListView</class>
36 <column>
37 <property>
38 <name>text</name>
39 <string>Key Name</string>
40 </property>
41 <property>
42 <name>clickable</name>
43 <bool>false</bool>
44 </property>
45 <property>
46 <name>resizeable</name>
47 <bool>false</bool>
48 </property>
49 </column>
50 <column>
51 <property>
52 <name>text</name>
53 <string>Key Type</string>
54 </property>
55 <property>
56 <name>clickable</name>
57 <bool>false</bool>
58 </property>
59 <property>
60 <name>resizeable</name>
61 <bool>false</bool>
62 </property>
63 </column>
64 <property stdset="1">
65 <name>name</name>
66 <cstring>display</cstring>
67 </property>
68 </widget>
69 <widget>
70 <class>QLayoutWidget</class>
71 <property stdset="1">
72 <name>name</name>
73 <cstring>Layout4</cstring>
74 </property>
75 <hbox>
76 <property stdset="1">
77 <name>margin</name>
78 <number>0</number>
79 </property>
80 <property stdset="1">
81 <name>spacing</name>
82 <number>6</number>
83 </property>
84 <spacer>
85 <property>
86 <name>name</name>
87 <cstring>Spacer2</cstring>
88 </property>
89 <property stdset="1">
90 <name>orientation</name>
91 <enum>Horizontal</enum>
92 </property>
93 <property stdset="1">
94 <name>sizeType</name>
95 <enum>Expanding</enum>
96 </property>
97 <property>
98 <name>sizeHint</name>
99 <size>
100 <width>20</width>
101 <height>20</height>
102 </size>
103 </property>
104 </spacer>
105 <widget>
106 <class>QPushButton</class>
107 <property stdset="1">
108 <name>name</name>
109 <cstring>newKeyButton</cstring>
110 </property>
111 <property stdset="1">
112 <name>maximumSize</name>
113 <size>
114 <width>50</width>
115 <height>32767</height>
116 </size>
117 </property>
118 <property stdset="1">
119 <name>text</name>
120 <string>New</string>
121 </property>
122 </widget>
123 <widget>
124 <class>QPushButton</class>
125 <property stdset="1">
126 <name>name</name>
127 <cstring>deleteKeyButton</cstring>
128 </property>
129 <property stdset="1">
130 <name>maximumSize</name>
131 <size>
132 <width>50</width>
133 <height>32767</height>
134 </size>
135 </property>
136 <property stdset="1">
137 <name>text</name>
138 <string>Delete</string>
139 </property>
140 </widget>
141 <widget>
142 <class>QPushButton</class>
143 <property stdset="1">
144 <name>name</name>
145 <cstring>clearKeysButton</cstring>
146 </property>
147 <property stdset="1">
148 <name>maximumSize</name>
149 <size>
150 <width>60</width>
151 <height>32767</height>
152 </size>
153 </property>
154 <property stdset="1">
155 <name>text</name>
156 <string>Clear All</string>
157 </property>
158 </widget>
159 </hbox>
160 </widget>
161 <widget>
162 <class>QLayoutWidget</class>
163 <property stdset="1">
164 <name>name</name>
165 <cstring>Layout3</cstring>
166 </property>
167 <hbox>
168 <property stdset="1">
169 <name>margin</name>
170 <number>0</number>
171 </property>
172 <property stdset="1">
173 <name>spacing</name>
174 <number>6</number>
175 </property>
176 <widget>
177 <class>QLineEdit</class>
178 <property stdset="1">
179 <name>name</name>
180 <cstring>keyNameEdit</cstring>
181 </property>
182 </widget>
183 <widget>
184 <class>QComboBox</class>
185 <property stdset="1">
186 <name>name</name>
187 <cstring>keyTypeEdit</cstring>
188 </property>
189 </widget>
190 </hbox>
191 </widget>
192 </vbox>
193</widget>
194<connections>
195 <connection>
196 <sender>newKeyButton</sender>
197 <signal>clicked()</signal>
198 <receiver>TVKeyEdit_gen</receiver>
199 <slot>newTerm()</slot>
200 </connection>
201 <connection>
202 <sender>deleteKeyButton</sender>
203 <signal>clicked()</signal>
204 <receiver>TVKeyEdit_gen</receiver>
205 <slot>deleteTerm()</slot>
206 </connection>
207 <connection>
208 <sender>clearKeysButton</sender>
209 <signal>clicked()</signal>
210 <receiver>TVKeyEdit_gen</receiver>
211 <slot>clearTerms()</slot>
212 </connection>
213 <connection>
214 <sender>display</sender>
215 <signal>selectionChanged(QListViewItem*)</signal>
216 <receiver>TVKeyEdit_gen</receiver>
217 <slot>setTerm(QListViewItem *)</slot>
218 </connection>
219 <connection>
220 <sender>keyNameEdit</sender>
221 <signal>textChanged(const QString&amp;)</signal>
222 <receiver>TVKeyEdit_gen</receiver>
223 <slot>updateTerm(const QString &amp;)</slot>
224 </connection>
225 <connection>
226 <sender>keyTypeEdit</sender>
227 <signal>activated(int)</signal>
228 <receiver>TVKeyEdit_gen</receiver>
229 <slot>updateTerm(int)</slot>
230 </connection>
231 <slot access="protected">clearTerms()</slot>
232 <slot access="protected">deleteTerm()</slot>
233 <slot access="protected">newTerm()</slot>
234 <slot access="public">new_slot()</slot>
235 <slot access="protected">setTerm(QListViewItem *)</slot>
236 <slot access="protected">updateTerm(int)</slot>
237 <slot access="protected">updateTerm(const QString &amp;)</slot>
238</connections>
239</UI>
diff --git a/noncore/apps/tableviewer/ui/tvlistview.cpp b/noncore/apps/tableviewer/ui/tvlistview.cpp
new file mode 100644
index 0000000..82d67c6
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvlistview.cpp
@@ -0,0 +1,315 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "tvlistview.h"
21#include "../db/common.h"
22#include <qtoolbutton.h>
23#include <qlistview.h>
24#include <qlayout.h>
25
26void TVListViewPrivate::setColumnWidth(int column, int width)
27{
28 if(width > 70) width = 70;
29 QListView::setColumnWidth(column, width);
30}
31
32void TVListViewPrivate::setSorting(int column, bool increasing)
33{
34 emit sortChanged(column);
35 QListView::setSorting(column, increasing);
36}
37
38TVListViewPrivate::TVListViewPrivate(QWidget *parent, const char* name,
39 WFlags fl) : QListView(parent, name, fl) {
40 ;
41}
42
43class TVListViewItem : public QListViewItem
44{
45public:
46
47 TVListViewItem(QListView *parent, DataElem *d);
48 ~TVListViewItem();
49
50 QString text(int i) const
51 {
52 return data_reference->toQString(i);
53 }
54
55 /* Do nothing... all data for this item should be generated */
56 void setText(int i, const QString &)
57 {
58 ;
59 }
60 QString key(int i, bool a) const
61 {
62 return data_reference->toSortableQString(i);
63 }
64
65 void setDataElem(DataElem *d)
66 {
67 data_reference = d;
68 }
69
70 DataElem *getDataElem() {
71 return data_reference;
72 }
73private:
74 DataElem *data_reference;
75};
76
77TVListViewItem::TVListViewItem(QListView *parent, DataElem *d)
78 : QListViewItem(parent)
79{
80 data_reference = d;
81}
82
83TVListViewItem::~TVListViewItem()
84{
85 data_reference = 0;
86}
87
88TVListView::TVListView(TableState *t, QWidget* parent = 0,
89 const char *name = 0, WFlags fl =0) : QWidget(parent, name, fl)
90{
91 if (!name)
92 setName("TVListView");
93
94 // the next two lines need to be rationalized.
95 resize(318,457);
96 setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
97 (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth()));
98 setCaption(tr("List View"));
99
100 QVBoxLayout *layout = new QVBoxLayout(this);
101 layout->setSpacing(0);
102 layout->setMargin(0);
103
104 listViewDisplay = new TVListViewPrivate(this, "listViewDisplay");
105 layout->addWidget(listViewDisplay);
106
107 connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem *)), this,
108 SLOT(setCurrent(QListViewItem *)));
109 connect(listViewDisplay, SIGNAL(sortChanged(int)), this,
110 SLOT(setSorting(int)));
111
112 listViewDisplay->setShowSortIndicator(true);
113
114 it = new QListViewItemIterator(listViewDisplay);
115 ts = t;
116}
117
118TVListView::~TVListView()
119{
120}
121
122void TVListView::addItem(DataElem *d)
123{
124 TVListViewItem *i = new TVListViewItem(listViewDisplay, d);
125
126 delete it;
127 it = new QListViewItemIterator(i);
128}
129
130/* remove current (it) item */
131void TVListView::removeItem()
132{
133 QListViewItemIterator other(*it);
134
135 QListViewItemIterator tmp = *it;
136 (*it)++;
137 if (!it->current()) {
138 *it = tmp;
139 (*it)--;
140 if (!it->current()) {
141 delete it;
142 it = 0;
143 }
144 }
145
146 delete other.current();
147}
148
149void TVListView::clearItems()
150{
151 /* This is ok since the destructor for TVListItem does not know about
152 the data_reference pointer.. and hence will leave it alone */
153 listViewDisplay->clear();
154 delete it;
155 it = new QListViewItemIterator(listViewDisplay);
156}
157
158void TVListView::first()
159{
160 delete it;
161 it = new QListViewItemIterator(listViewDisplay);
162}
163
164void TVListView::last()
165{
166 qWarning("TVListView::last not yet implemented");
167}
168
169void TVListView::next()
170{
171 QListViewItemIterator tmp = *it;
172 (*it)++;
173 if (!it->current()) {
174 *it = tmp;
175 }
176}
177
178void TVListView::previous()
179{
180 QListViewItemIterator tmp = *it;
181 (*it)--;
182 if (!it->current()) {
183 *it = tmp;
184 }
185}
186
187DataElem *TVListView::getCurrentData() {
188 if (it->current()) {
189 return ((TVListViewItem *)it->current())->getDataElem();
190 }
191 return NULL;
192}
193
194/*! Now to implement the closest match function */
195void TVListView::findItem(int keyId, TVVariant value)
196{
197 QListViewItem *i;
198 TVListViewItem *best_so_far = NULL;
199 /* start at the beginning... go through till find the closest elem */
200 i = listViewDisplay->firstChild();
201 while (i) {
202 /* search stuff */
203 if(best_so_far) {
204 if (DataElem::closer(
205 ((TVListViewItem *)i)->getDataElem(),
206 best_so_far->getDataElem(), value, keyId))
207 best_so_far = (TVListViewItem *)i;
208 } else {
209 if (DataElem::closer(
210 ((TVListViewItem *)i)->getDataElem(),
211 NULL, value, keyId))
212 best_so_far = (TVListViewItem *)i;
213 }
214
215 i = i->itemBelow();
216 }
217 if (best_so_far) {
218 /* set best_so_far to current element */
219 delete it;
220 it = new QListViewItemIterator(best_so_far);
221 }
222}
223
224void TVListView::rebuildKeys()
225{
226 int i;
227 if(!ts) return;
228 if(!ts->kRep) return;
229
230 i = listViewDisplay->columns();
231
232 while(i > 0)
233 listViewDisplay->removeColumn(--i);
234
235 KeyListIterator kit(*ts->kRep);
236 i = 0;
237 while(kit.current()) {
238 if(!kit.current()->delFlag()) {
239 listViewDisplay->addColumn(kit.current()->name());
240 keyIds.insert(i, kit.currentKey());
241 ++i;
242 }
243 ++kit;
244 }
245}
246
247
248void TVListView::setSorting(int column)
249{
250 /* Without table state can't do anything */
251 if (ts == 0)
252 return;
253 if (keyIds[column] != ts->current_column) {
254 ts->current_column = keyIds[column];
255 }
256}
257
258void TVListView::rebuildData() {
259 int i;
260 QMap<int, int>::Iterator kit;
261 /* Need to set sort order */
262 if(!ts)
263 return;
264
265 /* revers lookup the column */
266 i = -1;
267 for(kit = keyIds.begin(); kit != keyIds.end(); ++kit) {
268 if (kit.data() == ts->current_column) {
269 i = kit.key();
270 break;
271 }
272 }
273 if (i == -1)
274 return;
275
276 listViewDisplay->setSorting(i);
277 listViewDisplay->sort();
278
279 /* reset current element */
280 listViewDisplay->setCurrentItem(it->current());
281 listViewDisplay->setSelected(it->current(), true);
282 listViewDisplay->ensureItemVisible(it->current());
283}
284
285void TVListView::reset()
286{
287 int i;
288 listViewDisplay->clear();
289
290 i = listViewDisplay->columns();
291 while (i > 0)
292 listViewDisplay->removeColumn(--i);
293
294 keyIds.clear();
295}
296
297void TVListView::setCurrent(QListViewItem *i)
298{
299 /* cast */
300 TVListViewItem *t = (TVListViewItem *)i;
301
302 if(!t) {
303 /* set current to null */
304 ts->current_elem = 0;
305 return;
306 }
307
308 ts->current_elem = t->getDataElem();
309 /* now also set up the iterator */
310
311 delete it;
312 it = new QListViewItemIterator(i);
313
314 //emit browseView();
315}
diff --git a/noncore/apps/tableviewer/ui/tvlistview.h b/noncore/apps/tableviewer/ui/tvlistview.h
new file mode 100644
index 0000000..26bc299
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvlistview.h
@@ -0,0 +1,92 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef Tvlistview_H
22#define Tvlistview_H
23
24#include "../db/common.h"
25#include <qlistview.h>
26#include <qmap.h>
27
28class QListViewItemIterator;
29
30class TVListViewPrivate : public QListView
31{
32 Q_OBJECT
33
34signals:
35 void sortChanged(int i);
36
37public:
38 TVListViewPrivate( QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
39
40 void setColumnWidth(int c, int w);
41 void setSorting(int i, bool increasing=true);
42};
43
44class TVListView : public QWidget
45{
46 Q_OBJECT
47
48signals:
49 void loadFile();
50 void browseView();
51 void filterView();
52 void editView();
53
54protected slots:
55 void setSorting(int);
56 void setCurrent(QListViewItem *);
57
58public:
59 TVListView(TableState *t, QWidget* parent = 0,
60 const char* name = 0, WFlags fl = 0);
61 ~TVListView();
62
63 /* to be used for setting up the list */
64 void addItem(DataElem *);
65 void removeItem(); // remove from list, not from program
66 void clearItems();
67
68 /* DBStore clone functions */
69 void first();
70 void last();
71 void next();
72 void previous();
73
74 void rebuildKeys();
75 void rebuildData();
76 void reset();
77
78 DataElem *getCurrentData();
79
80 void findItem(int i, TVVariant v);
81
82protected:
83 QListViewItemIterator *it;
84 TableState *ts;
85
86 TVListViewPrivate *listViewDisplay;
87
88 QMap<int, int> keyIds;
89
90};
91
92#endif
diff --git a/noncore/comm/keypebble/.cvsignore b/noncore/comm/keypebble/.cvsignore
new file mode 100644
index 0000000..c4782a1
--- a/dev/null
+++ b/noncore/comm/keypebble/.cvsignore
@@ -0,0 +1,5 @@
1moc_*
2*.moc
3Makefile
4vncoptionsbase.cpp
5vncoptionsbase.h
diff --git a/noncore/comm/keypebble/LICENSE.GPL b/noncore/comm/keypebble/LICENSE.GPL
new file mode 100644
index 0000000..ec5dad8
--- a/dev/null
+++ b/noncore/comm/keypebble/LICENSE.GPL
@@ -0,0 +1,286 @@
1NOTE! The GPL below is copyrighted by the Free Software Foundation, but
2the instance of code that it refers to (the kde programs) are copyrighted
3by the authors who actually wrote it.
4
5---------------------------------------------------------------------------
6
7 GNU GENERAL PUBLIC LICENSE
8 Version 2, June 1991
9
10 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
11 675 Mass Ave, Cambridge, MA 02139, USA
12 Everyone is permitted to copy and distribute verbatim copies
13 of this license document, but changing it is not allowed.
14
15 Preamble
16
17 The licenses for most software are designed to take away your
18freedom to share and change it. By contrast, the GNU General Public
19License is intended to guarantee your freedom to share and change free
20software--to make sure the software is free for all its users. This
21General Public License applies to most of the Free Software
22Foundation's software and to any other program whose authors commit to
23using it. (Some other Free Software Foundation software is covered by
24the GNU Library General Public License instead.) You can apply it to
25your programs, too.
26
27 When we speak of free software, we are referring to freedom, not
28price. Our General Public Licenses are designed to make sure that you
29have the freedom to distribute copies of free software (and charge for
30this service if you wish), that you receive source code or can get it
31if you want it, that you can change the software or use pieces of it
32in new free programs; and that you know you can do these things.
33
34 To protect your rights, we need to make restrictions that forbid
35anyone to deny you these rights or to ask you to surrender the rights.
36These restrictions translate to certain responsibilities for you if you
37distribute copies of the software, or if you modify it.
38
39 For example, if you distribute copies of such a program, whether
40gratis or for a fee, you must give the recipients all the rights that
41you have. You must make sure that they, too, receive or can get the
42source code. And you must show them these terms so they know their
43rights.
44
45 We protect your rights with two steps: (1) copyright the software, and
46(2) offer you this license which gives you legal permission to copy,
47distribute and/or modify the software.
48
49 Also, for each author's protection and ours, we want to make certain
50that everyone understands that there is no warranty for this free
51software. If the software is modified by someone else and passed on, we
52want its recipients to know that what they have is not the original, so
53that any problems introduced by others will not reflect on the original
54authors' reputations.
55
56 Finally, any free program is threatened constantly by software
57patents. We wish to avoid the danger that redistributors of a free
58program will individually obtain patent licenses, in effect making the
59program proprietary. To prevent this, we have made it clear that any
60patent must be licensed for everyone's free use or not licensed at all.
61
62 The precise terms and conditions for copying, distribution and
63modification follow.
64
65 GNU GENERAL PUBLIC LICENSE
66 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
67
68 0. This License applies to any program or other work which contains
69a notice placed by the copyright holder saying it may be distributed
70under the terms of this General Public License. The "Program", below,
71refers to any such program or work, and a "work based on the Program"
72means either the Program or any derivative work under copyright law:
73that is to say, a work containing the Program or a portion of it,
74either verbatim or with modifications and/or translated into another
75language. (Hereinafter, translation is included without limitation in
76the term "modification".) Each licensee is addressed as "you".
77
78Activities other than copying, distribution and modification are not
79covered by this License; they are outside its scope. The act of
80running the Program is not restricted, and the output from the Program
81is covered only if its contents constitute a work based on the
82Program (independent of having been made by running the Program).
83Whether that is true depends on what the Program does.
84
85 1. You may copy and distribute verbatim copies of the Program's
86source code as you receive it, in any medium, provided that you
87conspicuously and appropriately publish on each copy an appropriate
88copyright notice and disclaimer of warranty; keep intact all the
89notices that refer to this License and to the absence of any warranty;
90and give any other recipients of the Program a copy of this License
91along with the Program.
92
93You may charge a fee for the physical act of transferring a copy, and
94you may at your option offer warranty protection in exchange for a fee.
95
96 2. You may modify your copy or copies of the Program or any portion
97of it, thus forming a work based on the Program, and copy and
98distribute such modifications or work under the terms of Section 1
99above, provided that you also meet all of these conditions:
100
101 a) You must cause the modified files to carry prominent notices
102 stating that you changed the files and the date of any change.
103
104 b) You must cause any work that you distribute or publish, that in
105 whole or in part contains or is derived from the Program or any
106 part thereof, to be licensed as a whole at no charge to all third
107 parties under the terms of this License.
108
109 c) If the modified program normally reads commands interactively
110 when run, you must cause it, when started running for such
111 interactive use in the most ordinary way, to print or display an
112 announcement including an appropriate copyright notice and a
113 notice that there is no warranty (or else, saying that you provide
114 a warranty) and that users may redistribute the program under
115 these conditions, and telling the user how to view a copy of this
116 License. (Exception: if the Program itself is interactive but
117 does not normally print such an announcement, your work based on
118 the Program is not required to print an announcement.)
119
120These requirements apply to the modified work as a whole. If
121identifiable sections of that work are not derived from the Program,
122and can be reasonably considered independent and separate works in
123themselves, then this License, and its terms, do not apply to those
124sections when you distribute them as separate works. But when you
125distribute the same sections as part of a whole which is a work based
126on the Program, the distribution of the whole must be on the terms of
127this License, whose permissions for other licensees extend to the
128entire whole, and thus to each and every part regardless of who wrote it.
129
130Thus, it is not the intent of this section to claim rights or contest
131your rights to work written entirely by you; rather, the intent is to
132exercise the right to control the distribution of derivative or
133collective works based on the Program.
134
135In addition, mere aggregation of another work not based on the Program
136with the Program (or with a work based on the Program) on a volume of
137a storage or distribution medium does not bring the other work under
138the scope of this License.
139
140 3. You may copy and distribute the Program (or a work based on it,
141under Section 2) in object code or executable form under the terms of
142Sections 1 and 2 above provided that you also do one of the following:
143
144 a) Accompany it with the complete corresponding machine-readable
145 source code, which must be distributed under the terms of Sections
146 1 and 2 above on a medium customarily used for software interchange; or,
147
148 b) Accompany it with a written offer, valid for at least three
149 years, to give any third party, for a charge no more than your
150 cost of physically performing source distribution, a complete
151 machine-readable copy of the corresponding source code, to be
152 distributed under the terms of Sections 1 and 2 above on a medium
153 customarily used for software interchange; or,
154
155 c) Accompany it with the information you received as to the offer
156 to distribute corresponding source code. (This alternative is
157 allowed only for noncommercial distribution and only if you
158 received the program in object code or executable form with such
159 an offer, in accord with Subsection b above.)
160
161The source code for a work means the preferred form of the work for
162making modifications to it. For an executable work, complete source
163code means all the source code for all modules it contains, plus any
164associated interface definition files, plus the scripts used to
165control compilation and installation of the executable. However, as a
166special exception, the source code distributed need not include
167anything that is normally distributed (in either source or binary
168form) with the major components (compiler, kernel, and so on) of the
169operating system on which the executable runs, unless that component
170itself accompanies the executable.
171
172If distribution of executable or object code is made by offering
173access to copy from a designated place, then offering equivalent
174access to copy the source code from the same place counts as
175distribution of the source code, even though third parties are not
176compelled to copy the source along with the object code.
177
178 4. You may not copy, modify, sublicense, or distribute the Program
179except as expressly provided under this License. Any attempt
180otherwise to copy, modify, sublicense or distribute the Program is
181void, and will automatically terminate your rights under this License.
182However, parties who have received copies, or rights, from you under
183this License will not have their licenses terminated so long as such
184parties remain in full compliance.
185
186 5. You are not required to accept this License, since you have not
187signed it. However, nothing else grants you permission to modify or
188distribute the Program or its derivative works. These actions are
189prohibited by law if you do not accept this License. Therefore, by
190modifying or distributing the Program (or any work based on the
191Program), you indicate your acceptance of this License to do so, and
192all its terms and conditions for copying, distributing or modifying
193the Program or works based on it.
194
195 6. Each time you redistribute the Program (or any work based on the
196Program), the recipient automatically receives a license from the
197original licensor to copy, distribute or modify the Program subject to
198these terms and conditions. You may not impose any further
199restrictions on the recipients' exercise of the rights granted herein.
200You are not responsible for enforcing compliance by third parties to
201this License.
202
203 7. If, as a consequence of a court judgment or allegation of patent
204infringement or for any other reason (not limited to patent issues),
205conditions are imposed on you (whether by court order, agreement or
206otherwise) that contradict the conditions of this License, they do not
207excuse you from the conditions of this License. If you cannot
208distribute so as to satisfy simultaneously your obligations under this
209License and any other pertinent obligations, then as a consequence you
210may not distribute the Program at all. For example, if a patent
211license would not permit royalty-free redistribution of the Program by
212all those who receive copies directly or indirectly through you, then
213the only way you could satisfy both it and this License would be to
214refrain entirely from distribution of the Program.
215
216If any portion of this section is held invalid or unenforceable under
217any particular circumstance, the balance of the section is intended to
218apply and the section as a whole is intended to apply in other
219circumstances.
220
221It is not the purpose of this section to induce you to infringe any
222patents or other property right claims or to contest validity of any
223such claims; this section has the sole purpose of protecting the
224integrity of the free software distribution system, which is
225implemented by public license practices. Many people have made
226generous contributions to the wide range of software distributed
227through that system in reliance on consistent application of that
228system; it is up to the author/donor to decide if he or she is willing
229to distribute software through any other system and a licensee cannot
230impose that choice.
231
232This section is intended to make thoroughly clear what is believed to
233be a consequence of the rest of this License.
234
235 8. If the distribution and/or use of the Program is restricted in
236certain countries either by patents or by copyrighted interfaces, the
237original copyright holder who places the Program under this License
238may add an explicit geographical distribution limitation excluding
239those countries, so that distribution is permitted only in or among
240countries not thus excluded. In such case, this License incorporates
241the limitation as if written in the body of this License.
242
243 9. The Free Software Foundation may publish revised and/or new versions
244of the General Public License from time to time. Such new versions will
245be similar in spirit to the present version, but may differ in detail to
246address new problems or concerns.
247
248Each version is given a distinguishing version number. If the Program
249specifies a version number of this License which applies to it and "any
250later version", you have the option of following the terms and conditions
251either of that version or of any later version published by the Free
252Software Foundation. If the Program does not specify a version number of
253this License, you may choose any version ever published by the Free Software
254Foundation.
255
256 10. If you wish to incorporate parts of the Program into other free
257programs whose distribution conditions are different, write to the author
258to ask for permission. For software which is copyrighted by the Free
259Software Foundation, write to the Free Software Foundation; we sometimes
260make exceptions for this. Our decision will be guided by the two goals
261of preserving the free status of all derivatives of our free software and
262of promoting the sharing and reuse of software generally.
263
264 NO WARRANTY
265
266 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
267FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
268OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
269PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
270OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
271MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
272TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
273PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
274REPAIR OR CORRECTION.
275
276 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
277WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
278REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
279INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
280OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
281TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
282YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
283PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
284POSSIBILITY OF SUCH DAMAGES.
285
286 END OF TERMS AND CONDITIONS
diff --git a/noncore/comm/keypebble/Makefile.in b/noncore/comm/keypebble/Makefile.in
new file mode 100644
index 0000000..1dbd5d2
--- a/dev/null
+++ b/noncore/comm/keypebble/Makefile.in
@@ -0,0 +1,286 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= keypebble
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =d3des.h \
27 krfbbuffer.h \
28 krfbcanvas.h \
29 krfbconnection.h \
30 krfbdecoder.h \
31 krfblogin.h \
32 krfboptions.h \
33 krfbserverinfo.h \
34 kvnc.h \
35 kvncconnectdlg.h \
36 kvncoptionsdlg.h \
37 version.h \
38 vncauth.h
39 SOURCES =d3des.c \
40 vncauth.c \
41 krfbbuffer.cpp \
42 krfbcanvas.cpp \
43 krfbconnection.cpp \
44 krfbdecoder.cpp \
45 krfblogin.cpp \
46 krfboptions.cpp \
47 kvnc.cpp \
48 kvncconnectdlg.cpp \
49 kvncoptionsdlg.cpp \
50 main.cpp
51 OBJECTS =d3des.o \
52 vncauth.o \
53 krfbbuffer.o \
54 krfbcanvas.o \
55 krfbconnection.o \
56 krfbdecoder.o \
57 krfblogin.o \
58 krfboptions.o \
59 kvnc.o \
60 kvncconnectdlg.o \
61 kvncoptionsdlg.o \
62 main.o \
63 vncoptionsbase.o
64INTERFACES = vncoptionsbase.ui
65UICDECLS = vncoptionsbase.h
66UICIMPLS = vncoptionsbase.cpp
67 SRCMOC =moc_krfbbuffer.cpp \
68 moc_krfbcanvas.cpp \
69 moc_krfbconnection.cpp \
70 moc_krfbdecoder.cpp \
71 moc_krfblogin.cpp \
72 moc_kvnc.cpp \
73 moc_kvncconnectdlg.cpp \
74 moc_kvncoptionsdlg.cpp \
75 moc_vncoptionsbase.cpp
76 OBJMOC =moc_krfbbuffer.o \
77 moc_krfbcanvas.o \
78 moc_krfbconnection.o \
79 moc_krfbdecoder.o \
80 moc_krfblogin.o \
81 moc_kvnc.o \
82 moc_kvncconnectdlg.o \
83 moc_kvncoptionsdlg.o \
84 moc_vncoptionsbase.o
85
86
87####### Implicit rules
88
89.SUFFIXES: .cpp .cxx .cc .C .c
90
91.cpp.o:
92 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
93
94.cxx.o:
95 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
96
97.cc.o:
98 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
99
100.C.o:
101 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
102
103.c.o:
104 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
105
106####### Build rules
107
108
109all: $(DESTDIR)$(TARGET)
110
111$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
112 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
113
114moc: $(SRCMOC)
115
116tmake:
117 tmake keypebble.pro
118
119clean:
120 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
121 -rm -f *~ core
122 -rm -f allmoc.cpp
123
124####### Extension Modules
125
126listpromodules:
127 @echo
128
129listallmodules:
130 @echo
131
132listaddonpromodules:
133 @echo
134
135listaddonentmodules:
136 @echo
137
138
139REQUIRES=
140
141####### Sub-libraries
142
143
144###### Combined headers
145
146
147
148####### Compile
149
150d3des.o: d3des.c \
151 d3des.h
152
153vncauth.o: vncauth.c \
154 vncauth.h \
155 d3des.h
156
157krfbbuffer.o: krfbbuffer.cpp \
158 krfbdecoder.h \
159 krfbbuffer.h \
160 krfbserverinfo.h
161
162krfbcanvas.o: krfbcanvas.cpp \
163 kvncconnectdlg.h \
164 krfbconnection.h \
165 krfbcanvas.h \
166 krfboptions.h \
167 krfbbuffer.h \
168 $(QPEDIR)/include/qpe/config.h
169
170krfbconnection.o: krfbconnection.cpp \
171 krfbconnection.h \
172 krfblogin.h \
173 krfboptions.h \
174 krfbdecoder.h \
175 krfbbuffer.h
176
177krfbdecoder.o: krfbdecoder.cpp \
178 krfbconnection.h \
179 krfboptions.h \
180 krfbserverinfo.h \
181 krfbdecoder.h \
182 krfbbuffer.h \
183 $(QPEDIR)/include/qpe/qpeapplication.h
184
185krfblogin.o: krfblogin.cpp \
186 vncauth.h \
187 krfblogin.h \
188 krfbconnection.h
189
190krfboptions.o: krfboptions.cpp \
191 $(QPEDIR)/include/qpe/config.h \
192 $(QPEDIR)/include/qpe/qpeapplication.h \
193 krfboptions.h
194
195kvnc.o: kvnc.cpp \
196 $(QPEDIR)/include/qpe/qpemenubar.h \
197 $(QPEDIR)/include/qpe/qpetoolbar.h \
198 $(QPEDIR)/include/qpe/qpeapplication.h \
199 $(QPEDIR)/include/qpe/global.h \
200 kvnc.h \
201 krfbcanvas.h \
202 kvncoptionsdlg.h \
203 vncoptionsbase.h \
204 krfbconnection.h
205
206kvncconnectdlg.o: kvncconnectdlg.cpp \
207 krfbconnection.h \
208 kvncoptionsdlg.h \
209 vncoptionsbase.h \
210 kvncconnectdlg.h
211
212kvncoptionsdlg.o: kvncoptionsdlg.cpp \
213 krfboptions.h \
214 kvncoptionsdlg.h \
215 vncoptionsbase.h
216
217main.o: main.cpp \
218 $(QPEDIR)/include/qpe/qpeapplication.h \
219 kvnc.h
220
221vncoptionsbase.h: vncoptionsbase.ui
222 $(UIC) vncoptionsbase.ui -o $(INTERFACE_DECL_PATH)/vncoptionsbase.h
223
224vncoptionsbase.cpp: vncoptionsbase.ui
225 $(UIC) vncoptionsbase.ui -i vncoptionsbase.h -o vncoptionsbase.cpp
226
227vncoptionsbase.o: vncoptionsbase.cpp \
228 vncoptionsbase.h \
229 vncoptionsbase.ui
230
231moc_krfbbuffer.o: moc_krfbbuffer.cpp \
232 krfbbuffer.h
233
234moc_krfbcanvas.o: moc_krfbcanvas.cpp \
235 krfbcanvas.h
236
237moc_krfbconnection.o: moc_krfbconnection.cpp \
238 krfbconnection.h
239
240moc_krfbdecoder.o: moc_krfbdecoder.cpp \
241 krfbdecoder.h
242
243moc_krfblogin.o: moc_krfblogin.cpp \
244 krfblogin.h
245
246moc_kvnc.o: moc_kvnc.cpp \
247 kvnc.h
248
249moc_kvncconnectdlg.o: moc_kvncconnectdlg.cpp \
250 kvncconnectdlg.h
251
252moc_kvncoptionsdlg.o: moc_kvncoptionsdlg.cpp \
253 kvncoptionsdlg.h \
254 vncoptionsbase.h
255
256moc_vncoptionsbase.o: moc_vncoptionsbase.cpp \
257 vncoptionsbase.h
258
259moc_krfbbuffer.cpp: krfbbuffer.h
260 $(MOC) krfbbuffer.h -o moc_krfbbuffer.cpp
261
262moc_krfbcanvas.cpp: krfbcanvas.h
263 $(MOC) krfbcanvas.h -o moc_krfbcanvas.cpp
264
265moc_krfbconnection.cpp: krfbconnection.h
266 $(MOC) krfbconnection.h -o moc_krfbconnection.cpp
267
268moc_krfbdecoder.cpp: krfbdecoder.h
269 $(MOC) krfbdecoder.h -o moc_krfbdecoder.cpp
270
271moc_krfblogin.cpp: krfblogin.h
272 $(MOC) krfblogin.h -o moc_krfblogin.cpp
273
274moc_kvnc.cpp: kvnc.h
275 $(MOC) kvnc.h -o moc_kvnc.cpp
276
277moc_kvncconnectdlg.cpp: kvncconnectdlg.h
278 $(MOC) kvncconnectdlg.h -o moc_kvncconnectdlg.cpp
279
280moc_kvncoptionsdlg.cpp: kvncoptionsdlg.h
281 $(MOC) kvncoptionsdlg.h -o moc_kvncoptionsdlg.cpp
282
283moc_vncoptionsbase.cpp: vncoptionsbase.h
284 $(MOC) vncoptionsbase.h -o moc_vncoptionsbase.cpp
285
286
diff --git a/noncore/comm/keypebble/README.html b/noncore/comm/keypebble/README.html
new file mode 100644
index 0000000..def766b
--- a/dev/null
+++ b/noncore/comm/keypebble/README.html
@@ -0,0 +1,206 @@
1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2<html>
3 <head>
4 <title>Keystone README</title>
5 </head>
6
7 <body>
8 <h1>Keystone README</h1>
9 <div align="justify"> <!-- #BeginEditable "Body" -->
10 <h3>Contents</h3>
11 <ul>
12 <li><a href="#whatisvnc">What is Keystone?</a></li>
13 <li><a href="#servers">Servers</a></li>
14 <li><a href="#status">Status</a></li>
15 <li><a href="#bugs">Bugs</a></li>
16 <li><a href="#download">Download</a></li>
17 <li><a href="#faq">FAQs</a></li>
18 <li><a href="#todo">Todo</a></li>
19 <li><a href="#credits">Credits</a></li>
20 <li><a href="#references">References</a></li>
21 </ul>
22 <h3><a name="whatiskvnc">What is Keystone?</a></h3>
23 <p>Keystone is a tool for <a href="http://www.kde.org/">KDE</a> that
24 allows you to remotely access the desktops of machines using the cross-platform
25 VNC system. Keystone can access machines running a variety of operating
26 systems (including most UNIX systems and Windows 95/98/NT/2000) providing
27 they are running a VNC server. Note that Keystone is only a client
28 program, you will need to download a server separately in order to
29 use it.</p>
30 <p>The protocol used by Keystone (called RFB) was developed, and released
31 as GPL by ORL (now the UK branch of AT&amp;T research), they also
32 wrote and maintain GPL servers for several platforms. You can find
33 both information about the protocol and links to servers for a range
34 of platforms on their <a href="http://www.uk.research.att.com/vnc/">website</a>.</p>
35 <p>Keystone started life as a port of Markus Wuebben's kvncviewer program
36 to KDE 2, but in the course porting the code, I have rewritten and
37 redesigned most of the system. The new implementation builds on several
38 new facilities that were not available in KDE 1, such as KPixmapIO
39 and QSocket. There is so little of the original code left that I have
40 decided on a name change, and to put the version number back to 0.1.</p>
41 <p>You can see a few screenshots of <a href="http://www.ipso-facto.demon.co.uk/keystone/screenshots.html">Keystone
42 in action</a> on my screenshots page. The screenshots may or may not
43 reflect the look of the current version as I have some look and feel
44 improvements planned.</p>
45 <h3><a name="servers">Servers</a></h3>
46 <p>Most Linux distributions include the standard Xvnc server (usually
47 run via the <i>vncserver</i> script), you can also download this and
48 servers for other platforms such as MS Windows from the <a href="http://www.uk.research.att.com/vnc/">VNC
49 website</a>. If you have a problem with setting up a server then you
50 should read the <a href="http://www.uk.research.att.com/vnc/faq.html">VNC
51 FAQ</a>, and if that does not help join the VNC mailing list. Do not
52 mail me on this topic - I can't help and won't even reply.</p>
53 <p>I may in future write a server that operates in the same manner as
54 the Win32 server for KDE. The Win32 server differs from the X11 server
55 in that it does not virtualise the entire desktop. This has both advantages
56 and disadvatages, it means that you can make an existing session available
57 over the network, but only allows you to run a single server. I may
58 also put a GUI together that makes it easy to configure the ORL server.</p>
59 <h3><a name="status">Status</a></h3>
60 <p><font color="#000000">The current version is 0.4, and the following
61 are now working:</font></p>
62 <p>
63 <ul>
64 <li><b>0.1</b>
65 <ul>
66 <li>Non-blocking socket handling</li>
67 <li>Authentication and logon</li>
68 <li>KDE 2 user interface</li>
69 <li>Raw and CopyRect encodings</li>
70 <li>Full screen mode</li>
71 <li>Grab keyboard mode</li>
72 <li>Graphics</li>
73 <li>Taking screenshots of the remote desktop</li>
74 <li>Event dispatching</li>
75 <li>Konqueror helper application support (you can run Keystone
76 by entering a vnc: URL anywhere in KDE).</li>
77 <li>Options, login, password and about dialogs</li>
78 </ul>
79 </li>
80 <li><b>0.2</b>
81 <ul>
82 <li>XSHM support using KPixmapIO</li>
83 <li>Now uses KXMLGUI (thanks to Kurt)</li>
84 <li>Tru64 patch from Tom Leitner</li>
85 <li>Status reporting improvements</li>
86 <li>Config handling fixed</li>
87 <li>Recent connections list implemented</li>
88 <li>Update frequency respected</li>
89 </ul>
90 </li>
91 <li><b>0.3 [KDE 2.0]</b>
92 <ul>
93 <li>Portability fixes for FreeBSD (and maybe others)</li>
94 </ul>
95 </li>
96 <li><b>0.4</b>
97 <ul>
98 <li>Icons for the full screen mode now reflect the current state</li>
99 <li>Added a toolbar (optional of course)</li>
100 <li>Added support for the clipboard (you can cut and paste between the
101 local and remote machines)</li>
102 <li>Added some what's this help to the options dialog</li>
103 </ul>
104 </li>
105 </ul>
106 <h3><a name="bugs">Bugs</a></h3>
107 <p>Version 0.4 contains the following known bugs:
108 <ul>
109 <li><b>Custom about dialog is not shown</b><br>
110 I can't see a clean way to fix this without creating a complete custom
111 help menu. For now I've left the standard about dialog in place.
112 </li>
113 <li><b>Crash when you connect to a non-existant server</b><br>
114 I can reproduce this every time, but I can't figure out what's wrong
115 other developers have reported similar problems and they seem to be
116 down to QSocket. The only known fix so far is to use KSocket instead.
117 I'd prefer to fix the problem at the source, but I'm having no luck and
118 I suspect QSocket may also be causing some other weird network issues
119 I've seen, so if I can't track down the bug soon I'll give in and switch
120 to KSocket like everyone else.
121 </li>
122 </ul>
123 </p>
124 <h3><a name="download"></a>Download</h3>
125 <p>Keystone is available in the kdenetwork module of the
126 <a href="http://www.kde.org/anoncvs.html">KDE CVS</a>, and
127 is included in the KDE 2.0 release. The current version is 0.4.
128 Note that Keystone <b>requires KDE 2</b>, you cannot use KDE 1.x.</p>
129 <h3><a name="faq"></a>FAQs</h3>
130 <p>
131 <ul>
132 <li><b>Why don't the shortcut keys work in full screen mode?</b><br>
133 When you're in full screen mode Keystone grabs the keyboard to send
134 every key press to the remote screen. This means that you can send key
135 combinations that are used by Keystone or KDE to the remote screen. If
136 you really hate it, then you can add -nograb to the command line
137 arguments to disable all keyboard grabs. I will add an option to allow
138 this behaviour to be overridden in a future release.
139 </li>
140 <li><b>Why is Keystone so slow?</b><br>
141 Currently only the simplest of the RFB encodings are supported, this
142 means that Keystone is only useful on fairly fast networks. This is
143 a serious bug and is being addressed.
144 </ul>
145 </p>
146 <h3><a name="todo">Todo</a></h3>
147 These are the things I'm hoping to add to future versions of Keystone.
148 They're vaguely sorted in order of importance.
149 <p>
150 <ul>
151 <li>RRE encoding.<br>
152 I've started this, but the implementation has some
153 bugs so it did not make the cut for Keystone 0.3.</li>
154 <li>CoRRE and Hextile encodings</li>
155 <li>Session management</li>
156 <li>Support for Windows Terminal Server.<br>
157 There is now a GPL implementation
158 of the protocol, and the author is happy for me to use the code. If someone
159 can offer me an account to test it on then this is possible.</li>
160 <li>Zoom support.<br>
161 This will be handled using the same protocol extension
162 as is used in the Palm client, this will allow you to make use of
163 server side scaling to reduce the amount of network traffic. You
164 will also be able to do client side zooms, but in this case the
165 full screen needs to transmitted over the network.</li>
166 <li>Macros</li>
167 <li>Monitor mode (thumbnails of several machines)</li>
168 <li>ZLib extension support</li>
169 <li>Bookmarks</li>
170 <li>URL specific settings</li>
171 <li>Possibly a DnD extension using a mechanism based on mulitpart
172 MIME attachments.</li>
173 </ul>
174 <h3>Credits<a name="credits"></a></h3>
175 <p>Keystone owes a lot to Markus Wuebben's kvncviewer which some of
176 the code is derived from. Thanks are also due to Espen Sand the author
177 of khexedit from which I borrowed some code for the about dialog.
178 Alison Burch drew the bridge image used in the background of this
179 page (and in future versions of Keystone too of course). Finally thanks
180 go to ORL for making the RFB protocol and servers GPL.</p>
181 <h3><a name="references">References</a><br>
182 </h3>
183 <p>
184 <ul>
185 <li>The Keystone homepage<br>
186 <a href="http://www.ipso-facto.demon.co.uk/keystone/">http://www.ipso-facto.demon.co.uk/keystone/</a></li>
187 <li>The VNC Homepage<br>
188 <a href="http://www.uk.research.att.com/vnc/">http://www.uk.research.att.com/vnc/</a></li>
189 <li>The VNC FAQ<br>
190 <a href="http://www.uk.research.att.com/vnc/faq.html">http://www.uk.research.att.com/vnc/faq.html</a></li>
191 <li>The KDE Homepage<br>
192 <a href="http://www.kde.org/">http://www.kde.org/</a> </li>
193 </ul>
194 <p></p>
195 <!-- #EndEditable --> </div>
196
197
198
199 <hr>
200 <address><a href="mailto:rich@kde.org">Richard Moore</a></address>
201<!-- Created: Tue Dec 5 01:35:56 GMT 2000 -->
202<!-- hhmts start -->
203Last modified: Tue Dec 5 01:37:17 GMT 2000
204<!-- hhmts end -->
205 </body>
206</html>
diff --git a/noncore/comm/keypebble/d3des.c b/noncore/comm/keypebble/d3des.c
new file mode 100644
index 0000000..b0f065e
--- a/dev/null
+++ b/noncore/comm/keypebble/d3des.c
@@ -0,0 +1,439 @@
1/*
2 * This is D3DES (V5.09) by Richard Outerbridge with the double and
3 * triple-length support removed for use in VNC. Also the bytebit[] array
4 * has been reversed so that the most significant bit in each byte of the
5 * key is ignored, not the least significant.
6 *
7 * These changes are Copyright (C) 1998 Olivetti & Oracle Research Laboratory
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 */
13
14/* D3DES (V5.09) -
15 *
16 * A portable, public domain, version of the Data Encryption Standard.
17 *
18 * Written with Symantec's THINK (Lightspeed) C by Richard Outerbridge.
19 * Thanks to: Dan Hoey for his excellent Initial and Inverse permutation
20 * code; Jim Gillogly & Phil Karn for the DES key schedule code; Dennis
21 * Ferguson, Eric Young and Dana How for comparing notes; and Ray Lau,
22 * for humouring me on.
23 *
24 * Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge.
25 * (GEnie : OUTER; CIS : [71755,204]) Graven Imagery, 1992.
26 */
27
28#include "d3des.h"
29
30static void scrunch(unsigned char *, unsigned long *);
31static void unscrun(unsigned long *, unsigned char *);
32static void desfunc(unsigned long *, unsigned long *);
33static void cookey(unsigned long *);
34
35static unsigned long KnL[32] = { 0L };
36static unsigned long KnR[32] = { 0L };
37static unsigned long Kn3[32] = { 0L };
38static unsigned char Df_Key[24] = {
39 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
40 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
41 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67 };
42
43 static unsigned short bytebit[8]= {
44 01, 02, 04, 010, 020, 040, 0100, 0200 };
45
46static unsigned long bigbyte[24] = {
47 0x800000L, 0x400000L, 0x200000L,0x100000L,
48 0x80000L, 0x40000L, 0x20000L,0x10000L,
49 0x8000L, 0x4000L, 0x2000L,0x1000L,
50 0x800L, 0x400L, 0x200L, 0x100L,
51 0x80L, 0x40L, 0x20L, 0x10L,
52 0x8L, 0x4L, 0x2L, 0x1L};
53
54/* Use the key schedule specified in the Standard (ANSI X3.92-1981). */
55
56static unsigned char pc1[56] = {
57 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,
58 9, 1, 58, 50, 42, 34, 26,18, 10, 2, 59, 51, 43, 35,
59 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21,
60 13, 5, 60, 52, 44, 36, 28,20, 12, 4, 27, 19, 11, 3 };
61
62static unsigned char totrot[16] = {
63 1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28 };
64
65static unsigned char pc2[48] = {
66 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9,
67 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,
68 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,
69 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 };
70
71 void deskey(key, edf)/* Thanks to James Gillogly & Phil Karn! */
72unsigned char *key;
73short edf;
74{
75 register int i, j, l, m, n;
76 unsigned char pc1m[56], pcr[56];
77 unsigned long kn[32];
78
79 for ( j = 0; j < 56; j++ ) {
80 l = pc1[j];
81 m = l & 07;
82 pc1m[j] = (key[l >> 3] & bytebit[m]) ? 1 : 0;
83 }
84 for( i = 0; i < 16; i++ ) {
85 if( edf == DE1 ) m = (15 - i) << 1;
86 else m = i << 1;
87 n = m + 1;
88 kn[m] = kn[n] = 0L;
89 for( j = 0; j < 28; j++ ) {
90 l = j + totrot[i];
91 if( l < 28 ) pcr[j] = pc1m[l];
92 else pcr[j] = pc1m[l - 28];
93 }
94 for( j = 28; j < 56; j++ ) {
95 l = j + totrot[i];
96 if( l < 56 ) pcr[j] = pc1m[l];
97 else pcr[j] = pc1m[l - 28];
98 }
99 for( j = 0; j < 24; j++ ) {
100 if( pcr[pc2[j]] ) kn[m] |= bigbyte[j];
101 if( pcr[pc2[j+24]] ) kn[n] |= bigbyte[j];
102 }
103 }
104 cookey(kn);
105 return;
106 }
107
108static void cookey(raw1)
109register unsigned long *raw1;
110{
111 register unsigned long *cook, *raw0;
112 unsigned long dough[32];
113 register int i;
114
115 cook = dough;
116 for( i = 0; i < 16; i++, raw1++ ) {
117 raw0 = raw1++;
118 *cook = (*raw0 & 0x00fc0000L) << 6;
119 *cook|= (*raw0 & 0x00000fc0L) << 10;
120 *cook|= (*raw1 & 0x00fc0000L) >> 10;
121 *cook++ |= (*raw1 & 0x00000fc0L) >> 6;
122 *cook = (*raw0 & 0x0003f000L) << 12;
123 *cook|= (*raw0 & 0x0000003fL) << 16;
124 *cook|= (*raw1 & 0x0003f000L) >> 4;
125 *cook++ |= (*raw1 & 0x0000003fL);
126 }
127 usekey(dough);
128 return;
129 }
130
131void cpkey(into)
132register unsigned long *into;
133{
134 register unsigned long *from, *endp;
135
136 from = KnL, endp = &KnL[32];
137 while( from < endp ) *into++ = *from++;
138 return;
139 }
140
141void usekey(from)
142register unsigned long *from;
143{
144 register unsigned long *to, *endp;
145
146 to = KnL, endp = &KnL[32];
147 while( to < endp ) *to++ = *from++;
148 return;
149 }
150
151void des(inblock, outblock)
152unsigned char *inblock, *outblock;
153{
154 unsigned long work[2];
155
156 scrunch(inblock, work);
157 desfunc(work, KnL);
158 unscrun(work, outblock);
159 return;
160 }
161
162static void scrunch(outof, into)
163register unsigned char *outof;
164register unsigned long *into;
165{
166 *into = (*outof++ & 0xffL) << 24;
167 *into|= (*outof++ & 0xffL) << 16;
168 *into|= (*outof++ & 0xffL) << 8;
169 *into++ |= (*outof++ & 0xffL);
170 *into = (*outof++ & 0xffL) << 24;
171 *into|= (*outof++ & 0xffL) << 16;
172 *into|= (*outof++ & 0xffL) << 8;
173 *into|= (*outof & 0xffL);
174 return;
175 }
176
177static void unscrun(outof, into)
178register unsigned long *outof;
179register unsigned char *into;
180{
181 *into++ = (*outof >> 24) & 0xffL;
182 *into++ = (*outof >> 16) & 0xffL;
183 *into++ = (*outof >> 8) & 0xffL;
184 *into++ = *outof++ & 0xffL;
185 *into++ = (*outof >> 24) & 0xffL;
186 *into++ = (*outof >> 16) & 0xffL;
187 *into++ = (*outof >> 8) & 0xffL;
188 *into = *outof & 0xffL;
189 return;
190 }
191
192static unsigned long SP1[64] = {
193 0x01010400L, 0x00000000L, 0x00010000L, 0x01010404L,
194 0x01010004L, 0x00010404L, 0x00000004L, 0x00010000L,
195 0x00000400L, 0x01010400L, 0x01010404L, 0x00000400L,
196 0x01000404L, 0x01010004L, 0x01000000L, 0x00000004L,
197 0x00000404L, 0x01000400L, 0x01000400L, 0x00010400L,
198 0x00010400L, 0x01010000L, 0x01010000L, 0x01000404L,
199 0x00010004L, 0x01000004L, 0x01000004L, 0x00010004L,
200 0x00000000L, 0x00000404L, 0x00010404L, 0x01000000L,
201 0x00010000L, 0x01010404L, 0x00000004L, 0x01010000L,
202 0x01010400L, 0x01000000L, 0x01000000L, 0x00000400L,
203 0x01010004L, 0x00010000L, 0x00010400L, 0x01000004L,
204 0x00000400L, 0x00000004L, 0x01000404L, 0x00010404L,
205 0x01010404L, 0x00010004L, 0x01010000L, 0x01000404L,
206 0x01000004L, 0x00000404L, 0x00010404L, 0x01010400L,
207 0x00000404L, 0x01000400L, 0x01000400L, 0x00000000L,
208 0x00010004L, 0x00010400L, 0x00000000L, 0x01010004L };
209
210static unsigned long SP2[64] = {
211 0x80108020L, 0x80008000L, 0x00008000L, 0x00108020L,
212 0x00100000L, 0x00000020L, 0x80100020L, 0x80008020L,
213 0x80000020L, 0x80108020L, 0x80108000L, 0x80000000L,
214 0x80008000L, 0x00100000L, 0x00000020L, 0x80100020L,
215 0x00108000L, 0x00100020L, 0x80008020L, 0x00000000L,
216 0x80000000L, 0x00008000L, 0x00108020L, 0x80100000L,
217 0x00100020L, 0x80000020L, 0x00000000L, 0x00108000L,
218 0x00008020L, 0x80108000L, 0x80100000L, 0x00008020L,
219 0x00000000L, 0x00108020L, 0x80100020L, 0x00100000L,
220 0x80008020L, 0x80100000L, 0x80108000L, 0x00008000L,
221 0x80100000L, 0x80008000L, 0x00000020L, 0x80108020L,
222 0x00108020L, 0x00000020L, 0x00008000L, 0x80000000L,
223 0x00008020L, 0x80108000L, 0x00100000L, 0x80000020L,
224 0x00100020L, 0x80008020L, 0x80000020L, 0x00100020L,
225 0x00108000L, 0x00000000L, 0x80008000L, 0x00008020L,
226 0x80000000L, 0x80100020L, 0x80108020L, 0x00108000L };
227
228static unsigned long SP3[64] = {
229 0x00000208L, 0x08020200L, 0x00000000L, 0x08020008L,
230 0x08000200L, 0x00000000L, 0x00020208L, 0x08000200L,
231 0x00020008L, 0x08000008L, 0x08000008L, 0x00020000L,
232 0x08020208L, 0x00020008L, 0x08020000L, 0x00000208L,
233 0x08000000L, 0x00000008L, 0x08020200L, 0x00000200L,
234 0x00020200L, 0x08020000L, 0x08020008L, 0x00020208L,
235 0x08000208L, 0x00020200L, 0x00020000L, 0x08000208L,
236 0x00000008L, 0x08020208L, 0x00000200L, 0x08000000L,
237 0x08020200L, 0x08000000L, 0x00020008L, 0x00000208L,
238 0x00020000L, 0x08020200L, 0x08000200L, 0x00000000L,
239 0x00000200L, 0x00020008L, 0x08020208L, 0x08000200L,
240 0x08000008L, 0x00000200L, 0x00000000L, 0x08020008L,
241 0x08000208L, 0x00020000L, 0x08000000L, 0x08020208L,
242 0x00000008L, 0x00020208L, 0x00020200L, 0x08000008L,
243 0x08020000L, 0x08000208L, 0x00000208L, 0x08020000L,
244 0x00020208L, 0x00000008L, 0x08020008L, 0x00020200L };
245
246static unsigned long SP4[64] = {
247 0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
248 0x00802080L, 0x00800081L, 0x00800001L, 0x00002001L,
249 0x00000000L, 0x00802000L, 0x00802000L, 0x00802081L,
250 0x00000081L, 0x00000000L, 0x00800080L, 0x00800001L,
251 0x00000001L, 0x00002000L, 0x00800000L, 0x00802001L,
252 0x00000080L, 0x00800000L, 0x00002001L, 0x00002080L,
253 0x00800081L, 0x00000001L, 0x00002080L, 0x00800080L,
254 0x00002000L, 0x00802080L, 0x00802081L, 0x00000081L,
255 0x00800080L, 0x00800001L, 0x00802000L, 0x00802081L,
256 0x00000081L, 0x00000000L, 0x00000000L, 0x00802000L,
257 0x00002080L, 0x00800080L, 0x00800081L, 0x00000001L,
258 0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
259 0x00802081L, 0x00000081L, 0x00000001L, 0x00002000L,
260 0x00800001L, 0x00002001L, 0x00802080L, 0x00800081L,
261 0x00002001L, 0x00002080L, 0x00800000L, 0x00802001L,
262 0x00000080L, 0x00800000L, 0x00002000L, 0x00802080L };
263
264static unsigned long SP5[64] = {
265 0x00000100L, 0x02080100L, 0x02080000L, 0x42000100L,
266 0x00080000L, 0x00000100L, 0x40000000L, 0x02080000L,
267 0x40080100L, 0x00080000L, 0x02000100L, 0x40080100L,
268 0x42000100L, 0x42080000L, 0x00080100L, 0x40000000L,
269 0x02000000L, 0x40080000L, 0x40080000L, 0x00000000L,
270 0x40000100L, 0x42080100L, 0x42080100L, 0x02000100L,
271 0x42080000L, 0x40000100L, 0x00000000L, 0x42000000L,
272 0x02080100L, 0x02000000L, 0x42000000L, 0x00080100L,
273 0x00080000L, 0x42000100L, 0x00000100L, 0x02000000L,
274 0x40000000L, 0x02080000L, 0x42000100L, 0x40080100L,
275 0x02000100L, 0x40000000L, 0x42080000L, 0x02080100L,
276 0x40080100L, 0x00000100L, 0x02000000L, 0x42080000L,
277 0x42080100L, 0x00080100L, 0x42000000L, 0x42080100L,
278 0x02080000L, 0x00000000L, 0x40080000L, 0x42000000L,
279 0x00080100L, 0x02000100L, 0x40000100L, 0x00080000L,
280 0x00000000L, 0x40080000L, 0x02080100L, 0x40000100L };
281
282static unsigned long SP6[64] = {
283 0x20000010L, 0x20400000L, 0x00004000L, 0x20404010L,
284 0x20400000L, 0x00000010L, 0x20404010L, 0x00400000L,
285 0x20004000L, 0x00404010L, 0x00400000L, 0x20000010L,
286 0x00400010L, 0x20004000L, 0x20000000L, 0x00004010L,
287 0x00000000L, 0x00400010L, 0x20004010L, 0x00004000L,
288 0x00404000L, 0x20004010L, 0x00000010L, 0x20400010L,
289 0x20400010L, 0x00000000L, 0x00404010L, 0x20404000L,
290 0x00004010L, 0x00404000L, 0x20404000L, 0x20000000L,
291 0x20004000L, 0x00000010L, 0x20400010L, 0x00404000L,
292 0x20404010L, 0x00400000L, 0x00004010L, 0x20000010L,
293 0x00400000L, 0x20004000L, 0x20000000L, 0x00004010L,
294 0x20000010L, 0x20404010L, 0x00404000L, 0x20400000L,
295 0x00404010L, 0x20404000L, 0x00000000L, 0x20400010L,
296 0x00000010L, 0x00004000L, 0x20400000L, 0x00404010L,
297 0x00004000L, 0x00400010L, 0x20004010L, 0x00000000L,
298 0x20404000L, 0x20000000L, 0x00400010L, 0x20004010L };
299
300static unsigned long SP7[64] = {
301 0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L,
302 0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L,
303 0x04200802L, 0x00200000L, 0x00000000L, 0x04000002L,
304 0x00000002L, 0x04000000L, 0x04200002L, 0x00000802L,
305 0x04000800L, 0x00200802L, 0x00200002L, 0x04000800L,
306 0x04000002L, 0x04200000L, 0x04200800L, 0x00200002L,
307 0x04200000L, 0x00000800L, 0x00000802L, 0x04200802L,
308 0x00200800L, 0x00000002L, 0x04000000L, 0x00200800L,
309 0x04000000L, 0x00200800L, 0x00200000L, 0x04000802L,
310 0x04000802L, 0x04200002L, 0x04200002L, 0x00000002L,
311 0x00200002L, 0x04000000L, 0x04000800L, 0x00200000L,
312 0x04200800L, 0x00000802L, 0x00200802L, 0x04200800L,
313 0x00000802L, 0x04000002L, 0x04200802L, 0x04200000L,
314 0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L,
315 0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L,
316 0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L };
317
318static unsigned long SP8[64] = {
319 0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L,
320 0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L,
321 0x00040040L, 0x10040000L, 0x10041040L, 0x00041000L,
322 0x10041000L, 0x00041040L, 0x00001000L, 0x00000040L,
323 0x10040000L, 0x10000040L, 0x10001000L, 0x00001040L,
324 0x00041000L, 0x00040040L, 0x10040040L, 0x10041000L,
325 0x00001040L, 0x00000000L, 0x00000000L, 0x10040040L,
326 0x10000040L, 0x10001000L, 0x00041040L, 0x00040000L,
327 0x00041040L, 0x00040000L, 0x10041000L, 0x00001000L,
328 0x00000040L, 0x10040040L, 0x00001000L, 0x00041040L,
329 0x10001000L, 0x00000040L, 0x10000040L, 0x10040000L,
330 0x10040040L, 0x10000000L, 0x00040000L, 0x10001040L,
331 0x00000000L, 0x10041040L, 0x00040040L, 0x10000040L,
332 0x10040000L, 0x10001000L, 0x10001040L, 0x00000000L,
333 0x10041040L, 0x00041000L, 0x00041000L, 0x00001040L,
334 0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L };
335
336static void desfunc(block, keys)
337register unsigned long *block, *keys;
338{
339 register unsigned long fval, work, right, leftt;
340 register int round;
341
342 leftt = block[0];
343 right = block[1];
344 work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;
345 right ^= work;
346 leftt ^= (work << 4);
347 work = ((leftt >> 16) ^ right) & 0x0000ffffL;
348 right ^= work;
349 leftt ^= (work << 16);
350 work = ((right >> 2) ^ leftt) & 0x33333333L;
351 leftt ^= work;
352 right ^= (work << 2);
353 work = ((right >> 8) ^ leftt) & 0x00ff00ffL;
354 leftt ^= work;
355 right ^= (work << 8);
356 right = ((right << 1) | ((right >> 31) & 1L)) & 0xffffffffL;
357 work = (leftt ^ right) & 0xaaaaaaaaL;
358 leftt ^= work;
359 right ^= work;
360 leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL;
361
362 for( round = 0; round < 8; round++ ) {
363 work = (right << 28) | (right >> 4);
364 work ^= *keys++;
365 fval = SP7[ work & 0x3fL];
366 fval |= SP5[(work >> 8) & 0x3fL];
367 fval |= SP3[(work >> 16) & 0x3fL];
368 fval |= SP1[(work >> 24) & 0x3fL];
369 work = right ^ *keys++;
370 fval |= SP8[ work & 0x3fL];
371 fval |= SP6[(work >> 8) & 0x3fL];
372 fval |= SP4[(work >> 16) & 0x3fL];
373 fval |= SP2[(work >> 24) & 0x3fL];
374 leftt ^= fval;
375 work = (leftt << 28) | (leftt >> 4);
376 work ^= *keys++;
377 fval = SP7[ work & 0x3fL];
378 fval |= SP5[(work >> 8) & 0x3fL];
379 fval |= SP3[(work >> 16) & 0x3fL];
380 fval |= SP1[(work >> 24) & 0x3fL];
381 work = leftt ^ *keys++;
382 fval |= SP8[ work & 0x3fL];
383 fval |= SP6[(work >> 8) & 0x3fL];
384 fval |= SP4[(work >> 16) & 0x3fL];
385 fval |= SP2[(work >> 24) & 0x3fL];
386 right ^= fval;
387 }
388
389 right = (right << 31) | (right >> 1);
390 work = (leftt ^ right) & 0xaaaaaaaaL;
391 leftt ^= work;
392 right ^= work;
393 leftt = (leftt << 31) | (leftt >> 1);
394 work = ((leftt >> 8) ^ right) & 0x00ff00ffL;
395 right ^= work;
396 leftt ^= (work << 8);
397 work = ((leftt >> 2) ^ right) & 0x33333333L;
398 right ^= work;
399 leftt ^= (work << 2);
400 work = ((right >> 16) ^ leftt) & 0x0000ffffL;
401 leftt ^= work;
402 right ^= (work << 16);
403 work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL;
404 leftt ^= work;
405 right ^= (work << 4);
406 *block++ = right;
407 *block = leftt;
408 return;
409 }
410
411/* Validation sets:
412 *
413 * Single-length key, single-length plaintext -
414 * Key : 0123 4567 89ab cdef
415 * Plain : 0123 4567 89ab cde7
416 * Cipher : c957 4425 6a5e d31d
417 *
418 * Double-length key, single-length plaintext -
419 * Key : 0123 4567 89ab cdef fedc ba98 7654 3210
420 * Plain : 0123 4567 89ab cde7
421 * Cipher : 7f1d 0a77 826b 8aff
422 *
423 * Double-length key, double-length plaintext -
424 * Key : 0123 4567 89ab cdef fedc ba98 7654 3210
425 * Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
426 * Cipher : 27a0 8440 406a df60 278f 47cf 42d6 15d7
427 *
428 * Triple-length key, single-length plaintext -
429 * Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567
430 * Plain : 0123 4567 89ab cde7
431 * Cipher : de0b 7c06 ae5e 0ed5
432 *
433 * Triple-length key, double-length plaintext -
434 * Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567
435 * Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
436 * Cipher : ad0d 1b30 ac17 cf07 0ed1 1c63 81e4 4de5
437 *
438 * d3des V5.0a rwo 9208.07 18:44 Graven Imagery
439 **********************************************************************/
diff --git a/noncore/comm/keypebble/d3des.h b/noncore/comm/keypebble/d3des.h
new file mode 100644
index 0000000..5da6013
--- a/dev/null
+++ b/noncore/comm/keypebble/d3des.h
@@ -0,0 +1,50 @@
1/*
2 * This is D3DES (V5.09) by Richard Outerbridge with the double and
3 * triple-length support removed for use in VNC.
4 *
5 * These changes are Copyright (C) 1998 Olivetti & Oracle Research Laboratory
6 *
7 * This software is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11
12/* d3des.h -
13 *
14 *Headers and defines for d3des.c
15 *Graven Imagery, 1992.
16 *
17 * Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge
18 *(GEnie : OUTER; CIS : [71755,204])
19 */
20
21 #define EN0 0/* MODE == encrypt */
22 #define DE1 1/* MODE == decrypt */
23
24extern void deskey(unsigned char *, short);
25 /* hexkey[8] MODE
26 * Sets the internal key register according to the hexadecimal
27 * key contained in the 8 bytes of hexkey, according to the DES,
28 * for encryption or decryption according to MODE.
29 */
30
31extern void usekey(unsigned long *);
32 /* cookedkey[32]
33 * Loads the internal key register with the data in cookedkey.
34 */
35
36extern void cpkey(unsigned long *);
37 /* cookedkey[32]
38 * Copies the contents of the internal key register into the storage
39 * located at &cookedkey[0].
40 */
41
42extern void des(unsigned char *, unsigned char *);
43 /* from[8] to[8]
44 * Encrypts/Decrypts (according to the key currently loaded in the
45 * internal key register) one block of eight bytes at address 'from'
46 * into the block at address 'to'. They can be the same.
47 */
48
49/* d3des.h V5.09 rwo 9208.04 15:06 Graven Imagery
50 ********************************************************************/
diff --git a/noncore/comm/keypebble/keypebble.pro b/noncore/comm/keypebble/keypebble.pro
new file mode 100644
index 0000000..6b11801
--- a/dev/null
+++ b/noncore/comm/keypebble/keypebble.pro
@@ -0,0 +1,38 @@
1TEMPLATE = app
2
3CONFIG += qt warn_on release
4DESTDIR = ../bin
5
6 HEADERS = d3des.h \
7 krfbbuffer.h \
8 krfbcanvas.h \
9 krfbconnection.h \
10 krfbdecoder.h \
11 krfblogin.h \
12 krfboptions.h \
13 krfbserverinfo.h \
14 kvnc.h \
15 kvncconnectdlg.h \
16 kvncoptionsdlg.h \
17 version.h \
18 vncauth.h
19
20 SOURCES = d3des.c \
21 vncauth.c \
22 krfbbuffer.cpp \
23 krfbcanvas.cpp \
24 krfbconnection.cpp \
25 krfbdecoder.cpp \
26 krfblogin.cpp \
27 krfboptions.cpp \
28 kvnc.cpp \
29 kvncconnectdlg.cpp \
30 kvncoptionsdlg.cpp \
31 main.cpp
32 INTERFACES= vncoptionsbase.ui
33TARGET = keypebble
34
35INCLUDEPATH += $(QPEDIR)/include
36DEPENDPATH += $(QPEDIR)/include
37LIBS += -lqpe
38
diff --git a/noncore/comm/keypebble/krfbbuffer.cpp b/noncore/comm/keypebble/krfbbuffer.cpp
new file mode 100644
index 0000000..4885261
--- a/dev/null
+++ b/noncore/comm/keypebble/krfbbuffer.cpp
@@ -0,0 +1,163 @@
1#include <assert.h>
2#include <qpixmap.h>
3#include <qbrush.h>
4#include <qimage.h>
5#include <qpainter.h>
6#include <qapplication.h>
7#include "krfbdecoder.h"
8#include "krfbbuffer.h"
9#include "krfbserverinfo.h"
10
11//
12// Endian stuff
13//
14#ifndef KDE_USE_FINAL
15const int endianTest = 1;
16#endif
17
18#define Swap16IfLE(s) \
19 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
20
21#define Swap32IfLE(l) \
22 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \
23 (((l) & 0x00ff0000) >> 8) | \
24 (((l) & 0x0000ff00) << 8) | \
25 (((l) & 0x000000ff) << 24)) : (l))
26
27KRFBBuffer::KRFBBuffer( KRFBDecoder *decoder,
28 QObject *parent, const char *name )
29 : QObject( parent, name )
30{
31 assert( decoder );
32 this->decoder = decoder;
33 pix = new QPixmap();
34}
35
36KRFBBuffer::~KRFBBuffer()
37{
38 delete pix;
39}
40
41void KRFBBuffer::resize( int w, int h )
42{
43 qWarning( "Resizing buffer" );
44
45 pix->resize( w, h );
46
47 QPalette pal = qApp->palette();
48 pix->fill( pal.active().base() );
49
50 emit sizeChanged( w, h );
51}
52
53void KRFBBuffer::soundBell()
54{
55 emit bell();
56}
57
58void KRFBBuffer::mouseEvent( QMouseEvent *e )
59{
60 decoder->sendMouseEvent( e );
61}
62
63void KRFBBuffer::keyPressEvent( QKeyEvent *e )
64{
65 qWarning( "Buffer got a key" );
66
67 decoder->sendKeyPressEvent( e );
68}
69
70void KRFBBuffer::keyReleaseEvent( QKeyEvent *e )
71{
72 decoder->sendKeyReleaseEvent( e );
73}
74
75void KRFBBuffer::copyRect( int srcX, int srcY,
76 int destX, int destY, int w, int h )
77{
78// qWarning( "Got copy rect" );
79 bitBlt( pix, destX, destY, pix, srcX, srcY, w, h, CopyROP );
80
81 emit updated( destX, destY, w, h );
82}
83
84void KRFBBuffer::drawRawRectChunk( void *data,
85 int x, int y, int w, int h )
86{
87 QImage img( w, h, 32 );
88
89 int redMax = Swap16IfLE( decoder->format->redMax );
90 int greenMax = Swap16IfLE( decoder->format->greenMax );
91 int blueMax = Swap16IfLE( decoder->format->blueMax );
92
93 QPainter p( pix );
94
95 if ( decoder->format->bpp == 8 ) {
96 uchar *d = (unsigned char *) data;
97
98 uint r,g,b;
99
100 for ( int j = 0; j < h; j++ ) {
101 for ( int i = 0; i < w ; i++ ) {
102 r = d[ j * w + i ];
103 r = r >> decoder->format->redShift;
104 r = r & redMax;
105
106 g = d[ j * w + i ];
107 g = g >> decoder->format->greenShift;
108 g = g & greenMax;
109
110 b = d[ j * w + i ];
111 b = b >> decoder->format->blueShift;
112 b = b & blueMax;
113
114 r = ( r * 255 ) / redMax;
115 g = ( g * 255 ) / greenMax;
116 b = ( b * 255 ) / blueMax;
117
118 uint *p = ( uint * ) img.scanLine( j ) + i;
119 *p = qRgb( r,g,b );
120 }
121 }
122 }
123 else if ( decoder->format->bpp == 32 ) {
124 ulong *d = (ulong *) data;
125
126 ulong r,g,b;
127
128 for ( int j = 0; j < h; j++ ) {
129 for ( int i = 0; i < w ; i++ ) {
130 ulong pixel = d[ j * w + i ];
131 pixel = Swap32IfLE( pixel );
132
133 r = pixel;
134 r = r >> decoder->format->redShift;
135 r = r & redMax;
136
137 g = pixel;
138 g = g >> decoder->format->greenShift;
139 g = g & greenMax;
140
141 b = pixel;
142 b = b >> decoder->format->blueShift;
143 b = b & blueMax;
144
145 r = ( r * 255 ) / redMax;
146 g = ( g * 255 ) / greenMax;
147 b = ( b * 255 ) / blueMax;
148
149 uint *p = ( uint * ) img.scanLine( j ) + i;
150 *p = qRgb( r,g,b );
151 }
152 }
153 }
154 else {
155 p.setBrush( QBrush( Qt::black ) );
156 p.drawRect( x, y, w, h );
157 }
158
159 p.drawImage( x, y, img );
160
161 emit updated( x, y, w, h );
162}
163
diff --git a/noncore/comm/keypebble/krfbbuffer.h b/noncore/comm/keypebble/krfbbuffer.h
new file mode 100644
index 0000000..1116d00
--- a/dev/null
+++ b/noncore/comm/keypebble/krfbbuffer.h
@@ -0,0 +1,62 @@
1// -*- c++ -*-
2
3#ifndef KRFBBUFFER_H
4#define KRFBBUFFER_H
5
6#include <qobject.h>
7
8class QPixmap;
9class KRFBDecoder;
10class QMouseEvent;
11class QKeyEvent;
12
13/**
14 * A wrapper around QPixmap that knows how to implement the RFB
15 * drawing primitives. If possible it makes use of the MIT XSHM
16 * extension to optimise the drawing operations.
17 */
18class KRFBBuffer : public QObject
19{
20 Q_OBJECT
21
22public:
23 KRFBBuffer( KRFBDecoder *decoder, QObject *parent, const char *name=0 );
24 ~KRFBBuffer();
25
26 QPixmap *pixmap() const { return pix; };
27
28 /**
29 * Draw a chunk of a raw encoded rectangle.
30 */
31 void drawRawRectChunk( void *data, int x, int y, int w, int h );
32
33 void copyRect( int srcX, int srcY,
34 int destX, int destY, int w, int h );
35
36 void fillRect( int ,int , int , int , unsigned long ) {};
37
38 void resize( int w, int h );
39
40 void mouseEvent( QMouseEvent *e );
41
42 void keyPressEvent( QKeyEvent *e );
43 void keyReleaseEvent( QKeyEvent *e );
44
45 void soundBell();
46
47signals:
48 /**
49 * Emitted when the size of the buffer changes.
50 */
51 void sizeChanged( int w, int h );
52
53 void updated( int x, int y, int w, int h );
54
55 void bell();
56
57private:
58 KRFBDecoder *decoder;
59 QPixmap *pix;
60};
61
62#endif // KRFBBUFFER_H
diff --git a/noncore/comm/keypebble/krfbcanvas.cpp b/noncore/comm/keypebble/krfbcanvas.cpp
new file mode 100644
index 0000000..f74ab7b
--- a/dev/null
+++ b/noncore/comm/keypebble/krfbcanvas.cpp
@@ -0,0 +1,169 @@
1#include "kvncconnectdlg.h"
2#include "krfbconnection.h"
3#include "krfbcanvas.h"
4#include "krfboptions.h"
5#include "krfbbuffer.h"
6
7#include <qpe/config.h>
8
9#include <qapplication.h>
10#include <qclipboard.h>
11#include <qaction.h>
12#include <qpixmap.h>
13#include <qapplication.h>
14#include <qmainwindow.h>
15#include <qiconset.h>
16
17KRFBCanvas::KRFBCanvas( QWidget *parent, const char *name )
18 : QScrollView( parent, name )
19{
20 connection_ = new KRFBConnection();
21 connect( connection_, SIGNAL( passwordRequired( KRFBConnection * ) ),
22 this, SLOT( passwordRequired( KRFBConnection * ) ) );
23 connect( connection_, SIGNAL( loggedIn() ),
24 this, SLOT( loggedIn() ) );
25
26 loggedIn_ = false;
27
28 viewport()->setFocusPolicy( QWidget::StrongFocus );
29 viewport()->setFocus();
30}
31
32KRFBCanvas::~KRFBCanvas()
33{
34}
35
36void KRFBCanvas::openConnection()
37{
38 KVNCConnectDlg dlg( connection_, this, "connect dialog" );
39 if ( dlg.exec() ) {
40 QCString host = dlg.hostname().latin1();
41 password = dlg.password();
42 connection_->connectTo( host, dlg.display() );
43 }
44}
45
46void KRFBCanvas::openURL( const QUrl &url )
47{
48 if ( loggedIn_ ) {
49 qWarning( "openURL invoked when logged in\n" );
50 return;
51 }
52
53 QCString host = url.host().latin1();
54 int display = url.port();
55 if ( url.hasPassword() )
56 connection_->setPassword( url.password().latin1() );
57
58 connection_->connectTo( host, display );
59}
60
61void KRFBCanvas::closeConnection()
62{
63 loggedIn_ = false;
64 connection_->disconnect();
65
66 viewport()->setMouseTracking( false );
67 viewport()->setBackgroundMode( PaletteDark );
68 setBackgroundMode( PaletteDark );
69 update();
70}
71
72void KRFBCanvas::passwordRequired( KRFBConnection *con )
73{
74 con->setPassword( password.latin1() );
75}
76
77void KRFBCanvas::bell()
78{
79 if ( connection_->options()->deIconify ) {
80 topLevelWidget()->raise();
81 topLevelWidget()->show();
82 }
83}
84
85void KRFBCanvas::loggedIn()
86{
87 qWarning( "Ok, we're logged in" );
88
89 //
90 // Get ready for action
91 //
92 loggedIn_ = true;
93 viewport()->setMouseTracking( true );
94 viewport()->setBackgroundMode( NoBackground );
95 setBackgroundMode( NoBackground );
96
97 // Start using the buffer
98 connect( connection_->buffer(), SIGNAL( sizeChanged( int, int ) ),
99 this, SLOT( resizeContents(int,int) ) );
100 connect( connection_->buffer(), SIGNAL( updated( int, int, int, int ) ),
101 this, SLOT( viewportUpdate(int,int,int,int) ) );
102 connect( connection_->buffer(), SIGNAL( bell() ),
103 this, SLOT( bell() ) );
104 connect( qApp->clipboard(), SIGNAL( dataChanged() ),
105 this, SLOT( clipboardChanged() ) );
106}
107
108void KRFBCanvas::viewportPaintEvent( QPaintEvent *e )
109{
110 QRect r = e->rect();
111
112 if ( loggedIn_ ) {
113 bitBlt( viewport(), r.x(), r.y(),
114 connection_->buffer()->pixmap(),
115 r.x() + contentsX(), r.y() + contentsY(),
116 r.width(), r.height() );
117 }
118 else {
119 QScrollView::viewportPaintEvent( e );
120 }
121}
122
123void KRFBCanvas::viewportUpdate( int x, int y, int w, int h )
124{
125 updateContents( x, y, w, h );
126}
127
128void KRFBCanvas::contentsMousePressEvent( QMouseEvent *e )
129{
130 if ( loggedIn_ )
131 connection_->buffer()->mouseEvent( e );
132}
133
134void KRFBCanvas::contentsMouseReleaseEvent( QMouseEvent *e )
135{
136 if ( loggedIn_ )
137 connection_->buffer()->mouseEvent( e );
138}
139
140void KRFBCanvas::contentsMouseMoveEvent( QMouseEvent *e )
141{
142 if ( loggedIn_ )
143 connection_->buffer()->mouseEvent( e );
144}
145
146void KRFBCanvas::keyPressEvent( QKeyEvent *e )
147{
148 if ( loggedIn_ )
149 connection_->buffer()->keyPressEvent( e );
150}
151
152void KRFBCanvas::keyReleaseEvent( QKeyEvent *e )
153{
154 if ( loggedIn_ )
155 connection_->buffer()->keyReleaseEvent( e );
156}
157
158void KRFBCanvas::refresh()
159{
160 if ( loggedIn_ )
161 connection_->refresh();
162}
163
164void KRFBCanvas::clipboardChanged()
165{
166 if ( loggedIn_ ) {
167 connection_->sendCutText( qApp->clipboard()->text() );
168 }
169}
diff --git a/noncore/comm/keypebble/krfbcanvas.h b/noncore/comm/keypebble/krfbcanvas.h
new file mode 100644
index 0000000..7864f1c
--- a/dev/null
+++ b/noncore/comm/keypebble/krfbcanvas.h
@@ -0,0 +1,54 @@
1// -*- c++ -*-
2
3#ifndef KRFBCANVAS_H
4#define KRFBCANVAS_H
5
6#include <qscrollview.h>
7#include <qurl.h>
8
9class KRFBConnection;
10
11/**
12 * Displays data from an KRFBDecoder, and sends events to the
13 * KRFBConnection.
14 */
15class KRFBCanvas : public QScrollView
16{
17 Q_OBJECT
18public:
19 KRFBCanvas( QWidget *parent, const char *name=0 );
20 ~KRFBCanvas();
21
22 void setConnection( KRFBConnection * );
23 KRFBConnection *connection() { return connection_; };
24
25public slots:
26 void openConnection();
27 void openURL( const QUrl & );
28 void closeConnection();
29 void passwordRequired( KRFBConnection * );
30
31 void refresh();
32 void bell();
33
34protected:
35 virtual void keyPressEvent( QKeyEvent * );
36 virtual void keyReleaseEvent( QKeyEvent * );
37 virtual void contentsMousePressEvent( QMouseEvent * );
38 virtual void contentsMouseReleaseEvent( QMouseEvent * );
39 virtual void contentsMouseMoveEvent( QMouseEvent * );
40
41 virtual void viewportPaintEvent( QPaintEvent *e );
42
43protected slots:
44 void loggedIn();
45 void viewportUpdate( int x, int y, int w, int h );
46 void clipboardChanged();
47
48private:
49 KRFBConnection *connection_;
50 QString password;
51 bool loggedIn_;
52};
53
54#endif // KRFBCANVAS_H
diff --git a/noncore/comm/keypebble/krfbconnection.cpp b/noncore/comm/keypebble/krfbconnection.cpp
new file mode 100644
index 0000000..c413186
--- a/dev/null
+++ b/noncore/comm/keypebble/krfbconnection.cpp
@@ -0,0 +1,242 @@
1#include <assert.h>
2#include <qsocket.h>
3#include <qtimer.h>
4#include <string.h>
5
6#include "krfbconnection.h"
7#include "krfblogin.h"
8#include "krfboptions.h"
9#include "krfbdecoder.h"
10#include "krfbbuffer.h"
11
12KRFBConnection::KRFBConnection( QObject *parent )
13 : QObject( parent, "KRFBConnection" )
14{
15 portBase_ = 5900;
16 currentState_ = Disconnected;
17 sock = 0;
18 minData_ = 0;
19 options_ = new KRFBOptions();
20 updater = 0;
21 decoder_ = 0;
22 buffer_ = 0;
23}
24
25KRFBConnection::~KRFBConnection()
26{
27 if ( ( currentState_ != Disconnected ) && ( currentState_ != Disconnecting ) && sock ) {
28 disconnectDone();
29 }
30 delete options_;
31}
32
33void KRFBConnection::connectTo( const QCString &host, int display )
34{
35 if ( currentState_ != Disconnected );
36 disconnect();
37
38 this->host_= host;
39 this->display_ = display;
40
41 sock = new QSocket( this, "rfbSocket" );
42 CHECK_PTR( sock );
43
44 // Connect to something to notice connection or error
45 connect( sock, SIGNAL( error( int ) ), SLOT( gotSocketError( int ) ) );
46 connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) );
47
48 qWarning( "Connecting..." );
49
50 currentState_ = Connecting;
51 sock->connectToHost( host_, portBase_ + display_ );
52}
53
54void KRFBConnection::disconnect()
55{
56 qWarning( "Disconnecting from server" );
57
58 if ( ( currentState_ != Disconnected )
59 && ( currentState_ != Disconnecting )
60 && sock ) {
61 currentState_ = Disconnecting;
62
63 connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) );
64 sock->close();
65
66 if ( sock->state() != QSocket::Closing )
67 disconnectDone();
68 }
69}
70
71void KRFBConnection::disconnectDone()
72{
73 qWarning( "KRFBConnection disconnected" );
74 currentState_ = Disconnected;
75 delete sock;
76 sock = 0;
77 minData_ = 0;
78 delete updater;
79 delete decoder_;
80 delete buffer_;
81 emit disconnected();
82}
83
84void KRFBConnection::gotSocketConnection()
85{
86 currentState_ = LoggingIn;
87
88 qWarning( "Connected, logging in..." );
89
90 static QString statusMsg = tr( "Connected" );
91 emit statusChanged( statusMsg );
92
93 // Do some login stuff
94 login = new KRFBLogin( this );
95}
96
97void KRFBConnection::gotRFBConnection()
98{
99 qWarning( "Logged into server" );
100
101 currentState_ = Connected;
102 emit connected();
103
104 // Create the decoder and start doing stuff
105 decoder_ = new KRFBDecoder( this );
106 CHECK_PTR( decoder_ );
107
108 buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" );
109 CHECK_PTR( buffer_ );
110 decoder_->setBuffer( buffer_ );
111
112 connect( decoder_, SIGNAL( status( const QString & ) ),
113 this, SIGNAL( statusChanged( const QString & ) ) );
114 emit loggedIn();
115
116 decoder_->start();
117
118 updater = new QTimer;
119 connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) );
120 updater->start( options_->updateRate );
121}
122
123void KRFBConnection::gotSocketError( int errno )
124{
125 currentState_ = Error;
126
127 // Do some error handling stuff
128 qWarning( "KRFBConnection: Socket error %d", errno );
129
130 static QString refused = tr( "Connection Refused" );
131 static QString host = tr( "Host not found" );
132 static QString read = tr( "Read Error: QSocket reported an error reading\n"
133 "data, the remote host has probably dropped the\n"
134 "connection." );
135 static QString confused = tr( "QSocket reported an invalid error code" );
136
137 QString msg;
138 switch ( errno ) {
139 case QSocket::ErrConnectionRefused:
140 msg = refused;
141 break;
142 case QSocket::ErrHostNotFound:
143 msg = host;
144 break;
145 case QSocket::ErrSocketRead:
146 msg = read;
147 break;
148 default:
149 msg = confused;
150 };
151
152 QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) );
153 delete sock;
154 sock = 0;
155 currentState_ = Disconnected;
156
157 emit error( msg );
158}
159
160void KRFBConnection::gotMoreData()
161{
162 assert( minData_ > 0 );
163
164 if ( sock->size() >= minData_ ) {
165 minData_ = 0;
166 QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) );
167 emit gotEnoughData();
168 }
169}
170
171void KRFBConnection::waitForData( unsigned int sz )
172{
173 assert( minData_ == 0 );
174 assert( sz > 0 );
175 assert( currentState_ != Error );
176
177 if ( sock->size() >= sz ) {
178 // qWarning( "No need to wait for data" );
179 emit gotEnoughData();
180 }
181 else {
182 // qWarning( "Waiting for %u bytes", sz );
183
184 minData_ = sz;
185 connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) );
186 }
187}
188
189int KRFBConnection::read( void *buf, int sz )
190{
191 return sock->readBlock( (char *) buf, sz );
192}
193
194int KRFBConnection::write( void *buf, int sz )
195{
196 return sock->writeBlock( (const char *) buf, sz );
197}
198
199KRFBConnection::State KRFBConnection::state() const
200{
201 return currentState_;
202}
203
204void KRFBConnection::setPortBase( int base )
205{
206 portBase_ = base;
207}
208
209int KRFBConnection::portBase() const
210{
211 return portBase_;
212}
213
214void KRFBConnection::setPassword( const QCString &pass )
215{
216 this->pass_ = pass;
217}
218
219void KRFBConnection::updateTimer()
220{
221 decoder_->sendUpdateRequest( true );
222}
223
224void KRFBConnection::refresh()
225{
226 decoder_->sendUpdateRequest( false );
227}
228
229void KRFBConnection::sendCutText( const QString &text )
230{
231 decoder_->sendCutEvent( text );
232}
233
234const QUrl &KRFBConnection::url()
235{
236 url_.setProtocol( "vnc" );
237 url_.setPort( display() );
238 url_.setHost( host() );
239 url_.setPath( "/" );
240
241 return url_;
242}
diff --git a/noncore/comm/keypebble/krfbconnection.h b/noncore/comm/keypebble/krfbconnection.h
new file mode 100644
index 0000000..fe477c1
--- a/dev/null
+++ b/noncore/comm/keypebble/krfbconnection.h
@@ -0,0 +1,152 @@
1// -*- c++ -*-
2
3#ifndef KRFBCONNECTION_H
4#define KRFBCONNECTION_H
5
6#include <qobject.h>
7#include <qstring.h>
8#include <qcstring.h>
9#include <qurl.h>
10
11class KRFBLogin;
12class KRBUpdateHandler;
13class KRFBOptions;
14class QSocket;
15class KRFBDecoder;
16class KRFBBuffer;
17class QTimer;
18
19/**
20 * Encapsulates the RFB socket.
21 *
22 */
23class KRFBConnection : public QObject
24{
25 Q_OBJECT
26
27public:
28 friend class KRFBLogin;
29 friend class KRFBDecoder;
30
31 //* The state of the connection.
32 enum State {
33 Connecting,
34 LoggingIn,
35 Connected,
36 Disconnecting,
37 Disconnected,
38 Error
39 };
40
41 KRFBConnection( QObject *parent = 0 );
42 ~KRFBConnection();
43
44 //* Get the state of a connection.
45 State state() const;
46
47 //* Get the options for this connection
48 KRFBOptions *options() const { return options_; };
49
50 KRFBBuffer *buffer() const { return buffer_; };
51
52 KRFBDecoder *decoder() const { return decoder_; };
53
54 //* Set the base from which the port for a given display will be calculated.
55 void setPortBase( int base );
56
57 //* Get the base from which the port for a given display is calculated.
58 int portBase() const;
59
60 //* Set the password which will be used to login
61 void setPassword( const QCString &pass );
62
63 //* Open a connection
64 void connectTo( const QCString &host, int display );
65
66 //* Close the connection
67 void disconnect();
68
69 //* Get the host
70 const QCString host() const { return host_; };
71
72 //* Get the display
73 int display() const { return display_; };
74
75 //* Get the current host/display as a URL
76 const QUrl &url();
77
78 //* Reload the display
79 void refresh();
80
81 //* Send text to the remote clipboard
82 void sendCutText( const QString & );
83
84protected slots:
85 //* When the shit hits the fan
86 void gotSocketError( int );
87
88 //* When we have an open socket
89 void gotSocketConnection();
90
91 //* When we have logged in
92 void gotRFBConnection();
93
94 //* When some more data arrived
95 void gotMoreData();
96
97 void updateTimer();
98
99 void disconnectDone();
100
101signals:
102 //* Emitted when the status of the connection changes.
103 void statusChanged( const QString & );
104
105 /**
106 * Emitted when we *really* need a password. If the password
107 * was specified before you tried to connect then you won't
108 * see this.
109 */
110 void passwordRequired( KRFBConnection * );
111
112 //* When we have a working RFB connection
113 void connected();
114
115 void loggedIn();
116
117 void disconnected();
118
119 //* What happened?
120 void error( const QString &msg );
121
122 //* Emitted in response to a waitForData() call.
123 void gotEnoughData();
124
125private:
126 //
127 // The following are called by our friends.
128 //
129
130 void waitForData( unsigned int );
131
132 int read( void *buf, int sz );
133 int write( void *buf, int sz );
134
135private:
136 QCString host_;
137 int portBase_;
138 int display_;
139 QCString pass_;
140 QSocket *sock;
141 State currentState_;
142 unsigned int minData_;
143 QTimer *updater;
144 KRFBLogin *login;
145 KRFBDecoder *decoder_;
146 KRFBOptions *options_;
147 KRFBBuffer *buffer_;
148 QUrl url_;
149};
150
151#endif // KRFBCONNECTION_H
152
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp
new file mode 100644
index 0000000..174dd7b
--- a/dev/null
+++ b/noncore/comm/keypebble/krfbdecoder.cpp
@@ -0,0 +1,839 @@
1#include "krfbconnection.h"
2#include "krfboptions.h"
3#include "krfbserverinfo.h"
4#include "krfbdecoder.h"
5#include "krfbbuffer.h"
6
7#include <qpe/qpeapplication.h>
8
9#include <qpixmap.h>
10#include <qsocket.h>
11#include <qevent.h>
12#include <qstring.h>
13#include <qclipboard.h>
14
15#include <assert.h>
16
17//
18// Endian stuff
19//
20#ifndef KDE_USE_FINAL
21const int endianTest = 1;
22#endif
23
24#define Swap16IfLE(s) \
25 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
26
27#define Swap32IfLE(l) \
28 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \
29 (((l) & 0x00ff0000) >> 8) | \
30 (((l) & 0x0000ff00) << 8) | \
31 (((l) & 0x000000ff) << 24)) : (l))
32
33//
34// The lengths of the messages we need to wait for
35//
36const int ServerInitLength = 24;
37const int UpdateHeaderLength = 4;
38const int RectHeaderLength = 12;
39const int RectChunkSize = 4;
40const int CopyRectPosLength = 4;
41const int ServerCutLenLength = 7;
42
43//
44// Client -> Server Message Identifiers
45//
46static CARD8 SetPixelFormatId = 0;
47//static CARD8 FixColourMapEntriesId = 1; // Not used
48static CARD8 SetEncodingsId = 2;
49static CARD8 UpdateRequestId = 3;
50static CARD8 KeyEventId = 4;
51static CARD8 PointerEventId = 5;
52static CARD8 ClientCutTextId = 6;
53
54//
55// Server -> Client Message Identifiers
56//
57static CARD8 UpdateId = 0;
58static CARD8 BellId = 2;
59static CARD8 ServerCutId = 3;
60
61//
62// Encoding identifiers
63//
64static CARD32 RawEncoding = Swap32IfLE( 0 );
65static CARD32 CopyRectEncoding = Swap32IfLE(1 );
66static CARD32 RreEncoding = Swap32IfLE( 2 );
67static CARD32 CorreEncoding = Swap32IfLE( 4 );
68static CARD32 HexTileEncoding = Swap32IfLE( 5 );
69
70static struct {
71 int keysym;
72 int keycode;
73} keyMap[] = {
74 { 0xff08, Qt::Key_Backspace },
75 { 0xff09, Qt::Key_Tab },
76 { 0xff0d, Qt::Key_Return },
77 { 0xff1b, Qt::Key_Escape },
78 { 0xff63, Qt::Key_Insert },
79 { 0xffff, Qt::Key_Delete },
80 { 0xff50, Qt::Key_Home },
81 { 0xff57, Qt::Key_End },
82 { 0xff55, Qt::Key_Prior },
83 { 0xff56, Qt::Key_Next },
84 { 0xff51, Qt::Key_Left },
85 { 0xff52, Qt::Key_Up },
86 { 0xff53, Qt::Key_Right },
87 { 0xff54, Qt::Key_Down },
88 { 0xffbe, Qt::Key_F1 },
89 { 0xffbf, Qt::Key_F2 },
90 { 0xffc0, Qt::Key_F3 },
91 { 0xffc1, Qt::Key_F4 },
92 { 0xffc2, Qt::Key_F5 },
93 { 0xffc3, Qt::Key_F6 },
94 { 0xffc4, Qt::Key_F7 },
95 { 0xffc5, Qt::Key_F8 },
96 { 0xffc6, Qt::Key_F9 },
97 { 0xffc7, Qt::Key_F10 },
98 { 0xffc8, Qt::Key_F11 },
99 { 0xffc9, Qt::Key_F12 },
100 { 0xffe1, Qt::Key_Shift },
101 { 0xffe2, Qt::Key_Shift },
102 { 0xffe3, Qt::Key_Control },
103 { 0xffe4, Qt::Key_Control },
104 { 0xffe7, Qt::Key_Meta },
105 { 0xffe8, Qt::Key_Meta },
106 { 0xffe9, Qt::Key_Alt },
107 { 0xffea, Qt::Key_Alt },
108 { 0, 0 }
109};
110
111
112KRFBDecoder::KRFBDecoder( KRFBConnection *con )
113 : QObject( con, "RFB Decoder" )
114{
115 assert( con );
116 assert( con->state() == KRFBConnection::Connected );
117
118 this->con = con;
119 this->buf = 0;
120 this->info = 0;
121 this->format = 0;
122 this->buttonMask = 0;
123 currentState = Idle;
124}
125
126KRFBDecoder::~KRFBDecoder()
127{
128 if ( info )
129 delete info;
130 if ( format )
131 delete format;
132}
133
134void KRFBDecoder::start()
135{
136 sendClientInit();
137}
138
139void KRFBDecoder::sendClientInit()
140{
141 con->write( &( con->options()->shared ), 1 );
142
143 // Wait for server init
144 qWarning( "Waiting for server init" );
145
146 static QString statusMsg = tr( "Waiting for server initialisation..." );
147 emit status( statusMsg );
148
149 currentState = AwaitingServerInit;
150 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) );
151 con->waitForData( ServerInitLength );
152}
153
154void KRFBDecoder::gotServerInit()
155{
156 qWarning( "Got server init" );
157 disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) );
158
159 if ( info )
160 delete info;
161 info = new KRFBServerInfo;
162 CHECK_PTR( info );
163
164 con->read( &(info->width), 2 );
165 info->width = Swap16IfLE( info->width );
166 con->read( &info->height, 2 );
167 info->height = Swap16IfLE( info->height );
168
169 con->read( &(info->bpp), 1 );
170 con->read( &(info->depth), 1 );
171 con->read( &(info->bigEndian), 1 );
172 con->read( &(info->trueColor), 1 );
173
174 con->read( &(info->redMax), 2 );
175 info->redMax = Swap16IfLE( info->redMax );
176 con->read( &(info->greenMax), 2 );
177 info->greenMax = Swap16IfLE( info->greenMax );
178 con->read( &(info->blueMax), 2 );
179 info->blueMax = Swap16IfLE( info->blueMax );
180
181 con->read( &(info->redShift), 1 );
182 con->read( &(info->greenShift), 1 );
183 con->read( &(info->blueShift), 1 );
184
185 con->read( info->padding, 3 );
186
187 con->read( &(info->nameLength), 4 );
188 info->nameLength = Swap32IfLE( info->nameLength );
189
190 qWarning( "Width = %d, Height = %d", info->width, info->height );
191 qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d",
192 info->bpp, info->depth, info->bigEndian, info->trueColor );
193 qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d",
194 info->redMax, info->greenMax, info->blueMax );
195 qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d",
196 info->redShift, info->greenShift,info-> blueShift );
197
198 buf->resize( info->width, info->height );
199
200 // Wait for desktop name
201 qWarning( "Waiting for desktop name" );
202
203 static QString statusMsg = tr( "Waiting for desktop name..." );
204 emit status( statusMsg );
205
206 currentState = AwaitingDesktopName;
207 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) );
208 con->waitForData( info->nameLength );
209}
210
211void KRFBDecoder::gotDesktopName()
212{
213 assert( info );
214 assert( currentState == AwaitingDesktopName );
215
216 qWarning( "Got desktop name" );
217
218 disconnect( con, SIGNAL( gotEnoughData() ),
219 this, SLOT( gotDesktopName() ) );
220
221 char *buf = new char[ info->nameLength + 1 ];
222 CHECK_PTR( buf );
223
224 con->read( buf, info->nameLength );
225 buf[ info->nameLength ] = '\0';
226 info->name = buf;
227
228 qWarning( "Desktop: %s", info->name.latin1() );
229
230 delete buf;
231
232 // Get the format we'll really use and tell the server
233 decidePixelFormat();
234 sendPixelFormat();
235 sendAllowedEncodings();
236 currentState = Idle;
237
238 QString msg;
239 msg = tr( "Connected to %1" );
240 msg = msg.arg( info->name );
241 emit status( msg );
242
243 sendUpdateRequest( false );
244}
245
246void KRFBDecoder::decidePixelFormat()
247{
248 assert( info );
249
250 if ( format )
251 delete format;
252 format = new KRFBPixelFormat;
253 CHECK_PTR( format );
254
255 // What depth do we want?
256 //
257 // We'll use the minimum of the remote and local depths, UNLESS an
258 // eight bit session has been specifically requested by the user.
259 int screenDepth = QPixmap::defaultDepth();
260 int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth;
261 int chosenDepth;
262
263 if ( con->options()->colors256 )
264 chosenDepth = 8;
265 else
266 chosenDepth = bestDepth;
267
268 qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \
269 "eight bit %d, chosenDepth=%d",
270 screenDepth,
271 info->depth,
272 bestDepth,
273 con->options()->colors256, chosenDepth );
274
275 format->depth = chosenDepth;
276
277 // If we're using the servers native depth
278 if ( chosenDepth == info->depth ) {
279 // Use the servers native format
280 format->bpp = info->bpp;
281 // format->bigEndian = info->bigEndian;
282 format->bigEndian = true;
283 format->trueColor = info->trueColor;
284 format->redMax = info->redMax;
285 format->greenMax = info->greenMax;
286 format->blueMax = info->blueMax;
287 format->redShift = info->redShift;
288 format->greenShift = info->greenShift;
289 format->blueShift = info->blueShift;
290 }
291 else {
292 if ( chosenDepth == 8 ) {
293 format->bpp = 8;
294 format->bigEndian = true;
295 format->trueColor = true;
296 format->redMax = 7;
297 format->greenMax = 7;
298 format->blueMax = 3;
299 format->redShift = 0;
300 format->greenShift = 3;
301 format->blueShift = 6;
302 }
303 }
304
305 format->redMax = Swap16IfLE( format->redMax );
306 format->greenMax = Swap16IfLE( format->greenMax );
307 format->blueMax = Swap16IfLE( format->blueMax );
308}
309
310void KRFBDecoder::sendPixelFormat()
311{
312 static char padding[3];
313 con->write( &SetPixelFormatId, 1 );
314 con->write( padding, 3 );
315
316 con->write( &(format->bpp), 1 );
317 con->write( &(format->depth), 1 );
318 con->write( &(format->bigEndian), 1 );
319 con->write( &(format->trueColor), 1 );
320
321 con->write( &(format->redMax), 2 );
322 con->write( &(format->greenMax), 2 );
323 con->write( &(format->blueMax), 2 );
324
325 con->write( &(format->redShift), 1 );
326 con->write( &(format->greenShift), 1 );
327 con->write( &(format->blueShift), 1 );
328 con->write( format->padding, 3 ); // Padding
329}
330
331void KRFBDecoder::sendAllowedEncodings()
332{
333 static CARD8 padding[1];
334 con->write( &SetEncodingsId, 1 );
335 con->write( padding, 1 );
336
337 static CARD16 noEncodings = con->options()->encodings();
338 noEncodings = Swap16IfLE( noEncodings );
339 con->write( &noEncodings, 2 );
340
341 if ( con->options()->corre )
342 con->write( &CorreEncoding, 4 );
343 if ( con->options()->hexTile )
344 con->write( &HexTileEncoding, 4 );
345 if ( con->options()->rre )
346 con->write( &RreEncoding, 4 );
347 if ( con->options()->copyrect )
348 con->write( &CopyRectEncoding, 4 );
349 // We always support this
350 con->write( &RawEncoding, 4 );
351}
352
353void KRFBDecoder::sendUpdateRequest( bool incremental )
354{
355 if ( currentState != Idle )
356 return;
357
358 con->write( &UpdateRequestId, 1 );
359 con->write( &incremental, 1 );
360
361 static CARD16 x = 0, y = 0;
362 static CARD16 w = Swap16IfLE( info->width );
363 static CARD16 h = Swap16IfLE( info->height );
364
365 con->write( &x, 2 );
366 con->write( &y, 2 );
367 con->write( &w, 2 );
368 con->write( &h, 2 );
369
370 // Now wait for the update
371 currentState = AwaitingUpdate;
372 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
373 con->waitForData( UpdateHeaderLength );
374}
375
376void KRFBDecoder::gotUpdateHeader()
377{
378 assert( currentState == AwaitingUpdate );
379
380 // qWarning( "Got update header" );
381
382 disconnect( con, SIGNAL( gotEnoughData() ),
383 this, SLOT( gotUpdateHeader() ) );
384
385 CARD8 msgType;
386 con->read( &msgType, 1 );
387
388 if ( msgType != UpdateId ) {
389 // We might have a bell or server cut
390 if ( msgType == ServerCutId ) {
391 oldState = currentState;
392 gotServerCut();
393 }
394 else if ( msgType == BellId ) {
395 oldState = currentState;
396 gotBell();
397 }
398 else {
399 int msg = msgType;
400 QString protocolError = tr( "Protocol Error: Message Id %1 was "
401 "found when expecting an update "
402 "message." ).arg( msg );
403 currentState = Error;
404 emit error( protocolError );
405 }
406 return;
407 }
408
409 CARD8 padding;
410 con->read( &padding, 1 );
411
412 con->read( &noRects, 2 );
413 noRects = Swap16IfLE( noRects );
414
415 // qWarning( "Expecting %d rects", noRects );
416
417 // Now wait for the data
418 currentState = AwaitingRectHeader;
419 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
420 con->waitForData( RectHeaderLength );
421}
422
423void KRFBDecoder::gotRectHeader()
424{
425 assert( currentState == AwaitingRectHeader );
426
427 // qWarning( "Got rect header" );
428
429 disconnect( con, SIGNAL( gotEnoughData() ),
430 this, SLOT( gotRectHeader() ) );
431
432 con->read( &x, 2 );
433 x = Swap16IfLE( x );
434 con->read( &y, 2 );
435 y = Swap16IfLE( y );
436
437 con->read( &w, 2 );
438 w = Swap16IfLE( w );
439 con->read( &h, 2 );
440 h = Swap16IfLE( h );
441
442 con->read( &encoding, 4 );
443
444 // CARD32 encodingLocal = Swap32IfLE( encoding );
445 // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld",
446 // x, y, w, h, encodingLocal );
447
448 //
449 // Each encoding needs to be handled differently. Some require
450 // waiting for more data, but others like a copyrect do not.
451 // Our constants have already been byte swapped, so we use
452 // the remote value as is.
453 //
454 if ( encoding == RawEncoding ) {
455 // qWarning( "Raw encoding" );
456 handleRawRect();
457 }
458 else if ( encoding == CopyRectEncoding ) {
459// qWarning( "CopyRect encoding" );
460 handleCopyRect();
461 }
462 else if ( encoding == RreEncoding ) {
463 qWarning( "RRE encoding" );
464 handleRRERect();
465 }
466 else if ( encoding == CorreEncoding ) {
467 qWarning( "CoRRE encoding" );
468 handleCoRRERect();
469 }
470 else if ( encoding == HexTileEncoding ) {
471 qWarning( "HexTile encoding" );
472 handleHexTileRect();
473 }
474 else {
475 int msg = Swap32IfLE( encoding );
476 QString protocolError = tr( "Protocol Error: An unknown encoding was "
477 "used by the server %1" ).arg( msg );
478 currentState = Error;
479 qWarning( "Unknown encoding, %d", msg );
480 emit error( protocolError );
481 return;
482 }
483}
484
485//
486// Raw Encoding
487//
488
489void KRFBDecoder::handleRawRect()
490{
491 // We need something a bit cleverer here to handle large
492 // rectanges nicely. The chunking should be based on the
493 // overall size (but has to be in complete lines).
494
495 // qWarning( "Handling a raw rect chunk" );
496
497 // CARD32 lineCount = w * format->bpp / 8;
498
499 if ( h > RectChunkSize ) {
500 // if ( con->sock->size() / lineCount ) {
501 // getRawRectChunk( con->sock->size() / lineCount );
502 // }
503 // else {
504 getRawRectChunk( RectChunkSize );
505 // }
506 }
507 else {
508 getRawRectChunk( h );
509 }
510}
511
512void KRFBDecoder::getRawRectChunk( int lines )
513{
514 this->lines = lines;
515 CARD32 count = lines * w * format->bpp / 8;
516
517 // Wait for server init
518 // qWarning( "Waiting for raw rect chunk, %ld", count );
519
520 currentState = AwaitingRawRectChunk;
521 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) );
522 con->waitForData( count );
523}
524
525void KRFBDecoder::gotRawRectChunk()
526{
527 assert( currentState == AwaitingRawRectChunk );
528
529 disconnect( con, SIGNAL( gotEnoughData() ),
530 this, SLOT( gotRawRectChunk() ) );
531
532 // qWarning( "Got raw rect chunk" );
533
534 //
535 // Read the rect data and copy it to the buffer.
536 //
537
538 // TODO: Replace this!
539 int count = lines * w * format->bpp / 8;
540 char *hack = new char[ count ];
541 con->read( hack, count );
542 buf->drawRawRectChunk( hack, x, y, w, lines );
543 delete hack;
544 // /TODO:
545
546 h = h - lines;
547 y = y + lines;
548
549 if ( h > 0 ) {
550 handleRawRect();
551 }
552 else {
553 noRects--;
554
555 // qWarning( "There are %d rects left", noRects );
556
557 if ( noRects ) {
558 currentState = AwaitingRectHeader;
559 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
560 con->waitForData( RectHeaderLength );
561 }
562 else
563 currentState = Idle;
564 }
565}
566
567//
568// Copy Rectangle Encoding
569//
570
571void KRFBDecoder::handleCopyRect()
572{
573 currentState = AwaitingCopyRectPos;
574 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) );
575 con->waitForData( CopyRectPosLength );
576}
577
578void KRFBDecoder::gotCopyRectPos()
579{
580 disconnect( con, SIGNAL( gotEnoughData() ),
581 this, SLOT( gotCopyRectPos() ) );
582
583 CARD16 srcX;
584 CARD16 srcY;
585
586 con->read( &srcX, 2 );
587 con->read( &srcY, 2 );
588
589 srcX = Swap16IfLE( srcX );
590 srcY = Swap16IfLE( srcY );
591
592 buf->copyRect( srcX, srcY, x, y, w, h );
593
594 noRects--;
595
596 // qWarning( "There are %d rects left", noRects );
597
598 if ( noRects ) {
599 currentState = AwaitingRectHeader;
600 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
601 con->waitForData( RectHeaderLength );
602 }
603 else
604 currentState = Idle;
605}
606
607void KRFBDecoder::handleRRERect()
608{
609 qWarning( "RRE not implemented" );
610}
611
612void KRFBDecoder::handleCoRRERect()
613{
614 qWarning( "CoRRE not implemented" );
615}
616
617void KRFBDecoder::handleHexTileRect()
618{
619 qWarning( "HexTile not implemented" );
620}
621
622void KRFBDecoder::sendMouseEvent( QMouseEvent *e )
623{
624 // Deal with the buttons
625 if ( e->type() != QEvent::MouseMove ) {
626 buttonMask = 0;
627 if ( e->type() == QEvent::MouseButtonPress ) {
628 if ( e->button() & LeftButton )
629 buttonMask |= 0x01;
630 if ( e->button() & MidButton )
631 buttonMask |= 0x04;
632 if ( e->button() & RightButton )
633 buttonMask |= 0x02;
634 }
635 else if ( e->type() == QEvent::MouseButtonRelease ) {
636 if ( e->button() & LeftButton )
637 buttonMask &= 0x06;
638 if ( e->button() & MidButton )
639 buttonMask |= 0x03;
640 if ( e->button() & RightButton )
641 buttonMask |= 0x05;
642 }
643 }
644
645 CARD16 x = Swap16IfLE( e->x() );
646 CARD16 y = Swap16IfLE( e->y() );
647
648 con->write( &PointerEventId, 1 );
649 con->write( &buttonMask, 1 );
650 con->write( &x, 2 );
651 con->write( &y, 2 );
652}
653
654
655void KRFBDecoder::sendCutEvent( const QString &unicode )
656{
657 //
658 // Warning: There is a bug in the RFB protocol because there is no way to find
659 // out the codepage in use on the remote machine. This could be fixed by requiring
660 // the remote server to use utf8 etc. but for now we have to assume they're the
661 // same. I've reported this problem to the ORL guys, but they apparantly have no
662 // immediate plans to fix the issue. :-( (rich)
663 //
664
665 CARD8 padding[3];
666 QCString text = unicode.local8Bit();
667 CARD32 length = text.length();
668 length = Swap32IfLE( length );
669
670 con->write( &ClientCutTextId, 1 );
671 con->write( &padding, 3 );
672 con->write( &length, 4 );
673 con->write( text.data(), length );
674}
675
676void KRFBDecoder::gotServerCut()
677{
678 qWarning( "Got server cut" );
679
680 currentState = AwaitingServerCutLength;
681 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) );
682 con->waitForData( ServerCutLenLength );
683}
684
685void KRFBDecoder::gotServerCutLength()
686{
687 assert( currentState = AwaitingServerCutLength );
688 disconnect( con, SIGNAL( gotEnoughData() ),
689 this, SLOT( gotServerCutLength() ) );
690
691 CARD8 padding[3];
692 con->read( padding, 3 );
693
694 con->read( &serverCutTextLen, 4 );
695 serverCutTextLen = Swap32IfLE( serverCutTextLen );
696
697 currentState = AwaitingServerCutText;
698 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) );
699 con->waitForData( serverCutTextLen );
700}
701
702void KRFBDecoder::gotServerCutText()
703{
704 assert( currentState = AwaitingServerCutText );
705
706 disconnect( con, SIGNAL( gotEnoughData() ),
707 this, SLOT( gotServerCutText() ) );
708
709 //
710 // Warning: There is a bug in the RFB protocol because there is no way to find
711 // out the codepage in use on the remote machine. This could be fixed by requiring
712 // the remote server to use utf8 etc. but for now we have to assume they're the
713 // same. I've reported this problem to the ORL guys, but they apparantly have no
714 // immediate plans to fix the issue. :-( (rich)
715 //
716
717 char *cutbuf = new char[ serverCutTextLen + 1 ];
718 CHECK_PTR( cutbuf );
719
720 con->read( cutbuf, serverCutTextLen );
721 cutbuf[ serverCutTextLen ] = '\0';
722
723 qWarning( "Server cut: %s", cutbuf );
724
725 QString cutText( cutbuf ); // DANGER!!
726 qApp->clipboard()->setText( cutText );
727
728 delete cutbuf;
729
730 // Now wait for the update (again)
731 if ( oldState == AwaitingUpdate ) {
732 currentState = AwaitingUpdate;
733 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
734 con->waitForData( UpdateHeaderLength );
735 }
736 else if ( oldState == Idle ) {
737 currentState = Idle;
738 }
739 else {
740 qWarning( "Async handled in weird state" );
741 currentState = oldState;
742 };
743}
744
745void KRFBDecoder::gotBell()
746{
747 qWarning( "Got server bell" );
748 buf->soundBell();
749
750 // Now wait for the update (again)
751 if ( oldState == AwaitingUpdate ) {
752 currentState = AwaitingUpdate;
753 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
754 con->waitForData( UpdateHeaderLength );
755 }
756 else if ( oldState == Idle ) {
757 currentState = Idle;
758 }
759 else {
760 qWarning( "Async handled in weird state" );
761 currentState = oldState;
762 };
763}
764
765void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event )
766{
767 int key;
768 key = toKeySym( event );
769 if ( key ) {
770 key = Swap32IfLE( key );
771
772 CARD8 mask = true;
773
774 CARD16 padding = 0;
775 con->write( &KeyEventId, 1 );
776 con->write( &mask, 1 );
777 con->write( &padding, 2 );
778 con->write( &key, 4 );
779 }
780}
781
782void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event )
783{
784 int key;
785 key = toKeySym( event );
786 if ( key ) {
787 key = Swap32IfLE( key );
788
789 CARD8 mask = false;
790
791 CARD16 padding = 0;
792 con->write( &KeyEventId, 1 );
793 con->write( &mask, 1 );
794 con->write( &padding, 2 );
795 con->write( &key, 4 );
796 }
797}
798
799int KRFBDecoder::toKeySym( QKeyEvent *k )
800{
801 int ke = 0;
802
803 ke = k->ascii();
804 // Markus: Crappy hack. I dont know why lower case letters are
805 // not defined in qkeydefs.h. The key() for e.g. 'l' == 'L'.
806 // This sucks. :-(
807
808 if ( (ke == 'a') || (ke == 'b') || (ke == 'c') || (ke == 'd')
809 || (ke == 'e') || (ke == 'f') || (ke == 'g') || (ke == 'h')
810 || (ke == 'i') || (ke == 'j') || (ke == 'k') || (ke == 'l')
811 || (ke == 'm') || (ke == 'n') || (ke == 'o') || (ke == 'p')
812 || (ke == 'q') || (ke == 'r') || (ke == 's') || (ke == 't')
813 || (ke == 'u') || (ke == 'v') ||( ke == 'w') || (ke == 'x')
814 || (ke == 'y') || (ke == 'z') ) {
815 ke = k->key();
816 ke = ke + 0x20;
817 return ke;
818 }
819
820 // qkeydefs = xkeydefs! :-)
821 if ( ( k->key() >= 0x0a0 ) && k->key() <= 0x0ff )
822 return k->key();
823
824 if ( ( k->key() >= 0x20 ) && ( k->key() <= 0x7e ) )
825 return k->key();
826
827 // qkeydefs != xkeydefs! :-(
828 // This is gonna suck :-(
829
830 int i = 0;
831 while ( keyMap[i].keycode ) {
832 if ( k->key() == keyMap[i].keycode )
833 return keyMap[i].keysym;
834 i++;
835 }
836
837 return 0;
838}
839
diff --git a/noncore/comm/keypebble/krfbdecoder.h b/noncore/comm/keypebble/krfbdecoder.h
new file mode 100644
index 0000000..4ba0185
--- a/dev/null
+++ b/noncore/comm/keypebble/krfbdecoder.h
@@ -0,0 +1,134 @@
1// -*- c++ -*-
2
3#ifndef KRFBDECODER_H
4#define KRFBDECODER_H
5
6#include <qobject.h>
7
8class KRFBConnection;
9class KRFBServerInfo;
10class KRFBPixelFormat;
11class KRFBBuffer;
12
13
14typedef unsigned char CARD8;
15typedef unsigned short CARD16;
16typedef unsigned long CARD32;
17
18/**
19 * Negotiates the pixel format to be used then decodes the resulting
20 * data stream.
21 *
22 * @author Richard Moore, rich@kde.org
23 */
24class KRFBDecoder : public QObject
25{
26 Q_OBJECT
27
28public:
29 friend class KRFBBuffer;
30
31 enum State {
32 AwaitingServerInit,
33 AwaitingDesktopName,
34 AwaitingUpdate,
35 AwaitingRectHeader,
36 AwaitingRawRectChunk,
37 AwaitingCopyRectPos,
38 AwaitingServerCutLength,
39 AwaitingServerCutText,
40 Idle,
41 Error
42 };
43
44 /**
45 * Create a KRFBDecoder that reads data from a logged in KRFBConnection
46 * and sends its output to a KRFBBuffer.
47 */
48 KRFBDecoder( KRFBConnection *con );
49 ~KRFBDecoder();
50
51 void setBuffer( KRFBBuffer *buf ) { this->buf = buf; };
52 void start();
53
54 int toKeySym( QKeyEvent *k );
55
56 //
57 // Client -> Server messages
58 //
59 void sendUpdateRequest( bool incremental );
60 void sendMouseEvent( QMouseEvent *e );
61 void sendKeyPressEvent( QKeyEvent *e );
62 void sendKeyReleaseEvent( QKeyEvent *e );
63 void sendCutEvent( const QString &text );
64
65protected:
66 //
67 // Initial format negotiation
68 //
69 void decidePixelFormat();
70 void sendPixelFormat();
71 void sendClientInit();
72 void sendAllowedEncodings();
73
74 //
75 // Rectange processing
76 //
77 void handleRawRect();
78 void handleCopyRect();
79 void handleRRERect();
80 void handleCoRRERect();
81 void handleHexTileRect();
82
83 void getRawRectChunk( int lines );
84
85protected slots:
86 void gotServerInit();
87 void gotDesktopName();
88 void gotUpdateHeader();
89 void gotRectHeader();
90 void gotRawRectChunk();
91 void gotCopyRectPos();
92 void gotServerCut();
93 void gotServerCutLength();
94 void gotServerCutText();
95 void gotBell();
96
97signals:
98 void error( const QString & );
99 void status( const QString & );
100
101private:
102 State currentState;
103
104 // Used to store the state we were in before a cut or bell msg
105 State oldState;
106
107 // The number of rects we're expecting
108 CARD16 noRects;
109
110 //
111 // Info about the current rect.
112 //
113 CARD16 x, y, w, h;
114 int lines;
115 CARD32 encoding;
116
117 CARD32 serverCutTextLen;
118
119 /** Where we draw the data (and the source of our events). */
120 KRFBBuffer *buf;
121 /** The connection to the server. */
122 KRFBConnection *con;
123
124 /** Info about the RFB server. */
125 KRFBServerInfo *info;
126 /** The pixel format we want. */
127 KRFBPixelFormat *format;
128
129 CARD8 buttonMask;
130};
131
132#endif // KRFBDECODER_H
133
134
diff --git a/noncore/comm/keypebble/krfblogin.cpp b/noncore/comm/keypebble/krfblogin.cpp
new file mode 100644
index 0000000..073ba0e
--- a/dev/null
+++ b/noncore/comm/keypebble/krfblogin.cpp
@@ -0,0 +1,255 @@
1#include <assert.h>
2
3
4extern "C" {
5#include "vncauth.h"
6}
7
8#include "krfblogin.h"
9#include "krfbconnection.h"
10#include <qtimer.h>
11
12// The length of the various messages (used to decide how many bytes to
13// wait for).
14const int ServerVersionLength = 12;
15const int ClientVersionLength = 12;
16const int AuthSchemeLength = 4;
17const int FailureReasonSizeLength = 4;
18const int ChallengeLength = 16;
19const int AuthResultLength = 4;
20
21// Authentication results
22enum AuthResult {
23 AuthOk,
24 AuthFailed,
25 AuthTooMany
26};
27
28typedef unsigned char CARD8;
29typedef unsigned short CARD16;
30typedef unsigned long CARD32;
31
32const int endianTest = 1;
33
34// Endian stuff
35#define Swap16IfLE(s) \
36 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
37
38#define Swap32IfLE(l) \
39 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \
40 (((l) & 0x00ff0000) >> 8) | \
41 (((l) & 0x0000ff00) << 8) | \
42 (((l) & 0x000000ff) << 24)) : (l))
43
44KRFBLogin::KRFBLogin( KRFBConnection *con )
45 : QObject( con, "RFB login manager" )
46{
47 assert( con );
48 this->con = con;
49 currentState = AwaitingServerVersion;
50
51 connect( this, SIGNAL( error( const QString & ) ),
52 con, SIGNAL( error( const QString & ) ) );
53
54 connect( this, SIGNAL( passwordRequired( KRFBConnection * ) ),
55 con, SIGNAL( passwordRequired( KRFBConnection * ) ) );
56
57 qWarning( "Waiting for server version..." );
58
59 static QString statusMsg = tr( "Waiting for server version..." );
60 emit status( statusMsg );
61
62 // Kick off the state machine
63 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerVersion() ) );
64 con->waitForData( ServerVersionLength );
65}
66
67KRFBLogin::~KRFBLogin()
68{
69
70}
71
72KRFBLogin::State KRFBLogin::state() const
73{
74 return currentState;
75}
76
77void KRFBLogin::gotServerVersion()
78{
79 qWarning( "Got server version" );
80
81 disconnect( con, SIGNAL( gotEnoughData() ),
82 this, SLOT( gotServerVersion() ) );
83
84 // Read the server's version message
85 char serverVersion[ ServerVersionLength + 1 ];
86 con->read( serverVersion, ServerVersionLength );
87 serverVersion[ ServerVersionLength ] = '\0';
88
89 QCString rfbString( serverVersion, ServerVersionLength + 1 );
90 versionString = rfbString;
91
92 QRegExp regexp( "RFB [0-9][0-9][0-9]\\.[0-9][0-9][0-9]\n" );
93
94 if ( rfbString.find( regexp ) == -1 ) {
95 static QString msg = tr( "Error: Invalid server version, %1" ).arg( rfbString );
96
97 qWarning( msg );
98 emit error( msg );
99 currentState = Error;
100 return;
101 }
102
103 // Calculate the actual version number
104 serverMajor = (serverVersion[4] - '0') * 100
105 + (serverVersion[5] - '0') * 10
106 + (serverVersion[6] - '0');
107 serverMinor = (serverVersion[8] - '0') * 100
108 + (serverVersion[9] - '0') * 10
109 + (serverVersion[10] - '0');
110
111 qWarning("Server Version: %03d.%03d", serverMajor, serverMinor );
112
113 if ( serverMajor != 3 ) {
114 QString msg = tr( "Error: Unsupported server version, %1" )
115 .arg( rfbString );
116
117 qWarning( msg );
118 emit error( msg );
119 currentState = Error;
120 return;
121 }
122
123 if ( serverMinor != 3 ) {
124 qWarning( "Minor version mismatch: %d", serverMinor );
125 }
126
127 // Setup for the next state
128 sendClientVersion();
129
130 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthScheme() ) );
131 con->waitForData( AuthSchemeLength );
132}
133
134void KRFBLogin::gotAuthScheme()
135{
136 disconnect( con, SIGNAL( gotEnoughData() ),
137 this, SLOT( gotAuthScheme() ) );
138
139 // Got data
140 CARD32 scheme;
141 con->read( &scheme, AuthSchemeLength );
142 scheme = Swap32IfLE( scheme );
143
144 static QString statusMsgOk = tr( "Logged in" );
145
146 switch ( scheme ) {
147 case 0:
148 qWarning( "Failed" );
149 // Handle failure
150 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotFailureReasonSize() ) );
151 con->waitForData( FailureReasonSizeLength );
152 break;
153 case 1:
154 // Handle no auth
155 emit status( statusMsgOk );
156 con->gotRFBConnection();
157 break;
158 case 2:
159 // Handle VNC auth
160 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotChallenge() ) );
161 con->waitForData( ChallengeLength );
162 break;
163 default:
164 qWarning( "Unknown authentication scheme, 0x%08lx", scheme );
165 currentState = Error;
166 break;
167 };
168}
169
170void KRFBLogin::gotChallenge()
171{
172 disconnect( con, SIGNAL( gotEnoughData() ),
173 this, SLOT( gotChallenge() ) );
174
175 QTimer::singleShot( 0, this, SLOT(getPassword()) );
176}
177
178void KRFBLogin::getPassword()
179{
180 // Got data
181 CARD8 challenge[ ChallengeLength ];
182 con->read( challenge, ChallengeLength );
183
184 // Last chance to enter a password
185 if ( con->pass_.isNull() ) {
186 qWarning( "krfblogin needs a password" );
187 emit passwordRequired( con );
188 }
189
190 if ( con->pass_.isNull() ) {
191 QString msg = tr( "Error: This server requires a password, but none "
192 "has been specified.\n" );
193
194 emit error( msg );
195 return;
196 }
197
198 vncEncryptBytes( (unsigned char *) challenge, con->pass_.data() );
199 con->write( challenge, ChallengeLength );
200
201 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthResult() ) );
202 con->waitForData( AuthResultLength );
203}
204
205void KRFBLogin::gotFailureReasonSize()
206{
207 disconnect( con, SIGNAL( gotEnoughData() ), this,
208 SLOT( gotFailureReasonSize() ) );
209}
210
211void KRFBLogin::gotAuthResult()
212{
213 // Got data
214 disconnect( con, SIGNAL( gotEnoughData() ), this,
215 SLOT( gotAuthResult() ) );
216
217 long result;
218 con->read( &result, AuthResultLength );
219 result = Swap32IfLE( result );
220
221 qWarning( "Authentication Result is 0x%08lx", result );
222
223 static QString failed = tr( "Error: The password you specified was incorrect." );
224 static QString tooMany = tr( "Error: Too many invalid login attempts have been made\n"
225 "to this account, please try later." );
226
227 static QString statusMsgOk = tr( "Logged in" );
228 static QString statusMsgFailed = tr( "Login Failed" );
229 static QString statusMsgTooMany = tr( "Too many failures" );
230
231 switch( result ) {
232 case AuthOk:
233 emit status( statusMsgOk );
234 con->gotRFBConnection();
235 break;
236 case AuthFailed:
237 qWarning( "Dammit" );
238 emit status( statusMsgFailed );
239 emit error( failed );
240 break;
241 case AuthTooMany:
242 emit status( statusMsgTooMany );
243 emit error( tooMany );
244 break;
245 default:
246 qWarning( "Invalid authentication result, %lx", result );
247 break;
248 }
249}
250
251void KRFBLogin::sendClientVersion()
252{
253 qWarning( "Sending client version" );
254 con->write( (void*)"RFB 003.003\n", ClientVersionLength );
255}
diff --git a/noncore/comm/keypebble/krfblogin.h b/noncore/comm/keypebble/krfblogin.h
new file mode 100644
index 0000000..5208210
--- a/dev/null
+++ b/noncore/comm/keypebble/krfblogin.h
@@ -0,0 +1,62 @@
1// -*- c++ -*-
2
3#ifndef KRFBLOGIN_H
4#define KRFBLOGIN_H
5
6#include <qobject.h>
7
8class KRFBConnection;
9
10/**
11 * Handles logging into the RFB server.
12 *
13 * @version $Id$
14 * @author Richard Moore, rich@kde.org
15 */
16class KRFBLogin : QObject
17{
18 Q_OBJECT
19
20public:
21 enum State {
22 AwaitingServerVersion,
23 AwaitingAuthScheme,
24 AwaitingChallenge,
25 WaitingForResponse,
26 Authenticated,
27 Ready,
28 Failed,
29 Error
30 };
31
32 KRFBLogin( KRFBConnection *con );
33 ~KRFBLogin();
34
35 KRFBLogin::State state() const;
36
37protected:
38 void sendClientVersion();
39
40protected slots:
41 void getPassword();
42 void gotServerVersion();
43 void gotAuthScheme();
44 void gotChallenge();
45 void gotAuthResult();
46 void gotFailureReasonSize();
47
48signals:
49 void passwordRequired( KRFBConnection * );
50 void error( const QString & );
51 void status( const QString & );
52
53private:
54 KRFBConnection *con;
55 State currentState;
56 QCString versionString;
57 int serverMajor;
58 int serverMinor;
59};
60
61#endif // KRFBLOGIN_H
62
diff --git a/noncore/comm/keypebble/krfboptions.cpp b/noncore/comm/keypebble/krfboptions.cpp
new file mode 100644
index 0000000..9daf3f0
--- a/dev/null
+++ b/noncore/comm/keypebble/krfboptions.cpp
@@ -0,0 +1,52 @@
1#include <qpe/config.h>
2#include <qpe/qpeapplication.h>
3#include "krfboptions.h"
4
5KRFBOptions::KRFBOptions()
6{
7 Config config( "keypebble" );
8 readSettings( &config );
9}
10
11KRFBOptions::~KRFBOptions()
12{
13 Config config( "keypebble" );
14 writeSettings( &config );
15}
16
17void KRFBOptions::readSettings( Config *config )
18{
19 hexTile = config->readBoolEntry( "HexTile" );
20 corre = config->readBoolEntry( "CORRE" );
21 rre = config->readBoolEntry( "RRE" );
22 copyrect = config->readBoolEntry( "CopyRect", true );
23 colors256 = config->readBoolEntry( "Colors256" );
24 shared = config->readBoolEntry( "Shared" );
25 readOnly = config->readBoolEntry( "ReadOnly" );
26 updateRate = config->readNumEntry( "UpdateRate", 50 );
27}
28
29void KRFBOptions::writeSettings( Config *config )
30{
31 config->writeEntry( "HexTile", hexTile );
32 config->writeEntry( "CORRE", corre );
33 config->writeEntry( "RRE", rre );
34 config->writeEntry( "CopyRect", copyrect );
35 config->writeEntry( "Colors256", colors256 );
36 config->writeEntry( "Shared", shared );
37 config->writeEntry( "ReadOnly", readOnly );
38 config->writeEntry( "UpdateRate", updateRate );
39}
40
41int KRFBOptions::encodings()
42{
43 // Initially one because we always support raw encoding
44 int count = 1;
45
46 count += hexTile ? 1 : 0;
47 count += corre ? 1 : 0;
48 count += rre ? 1 : 0;
49 count += copyrect ? 1 : 0;
50
51 return count;
52}
diff --git a/noncore/comm/keypebble/krfboptions.h b/noncore/comm/keypebble/krfboptions.h
new file mode 100644
index 0000000..41cea35
--- a/dev/null
+++ b/noncore/comm/keypebble/krfboptions.h
@@ -0,0 +1,31 @@
1// -*- c++ -*-
2
3#ifndef KRFBOPTIONS_H
4#define KRFBOPTIONS_H
5
6class Config;
7
8class KRFBOptions
9{
10public:
11 KRFBOptions();
12 ~KRFBOptions();
13
14 int encodings();
15 void readSettings( Config *config );
16 void writeSettings( Config *config );
17
18 bool hexTile;
19 bool corre;
20 bool rre;
21 bool copyrect;
22
23 bool colors256;
24 bool shared;
25 bool readOnly;
26 bool deIconify;
27
28 int updateRate;
29};
30
31#endif // KRFBOPTIONS_H
diff --git a/noncore/comm/keypebble/krfbserverinfo.h b/noncore/comm/keypebble/krfbserverinfo.h
new file mode 100644
index 0000000..7449da9
--- a/dev/null
+++ b/noncore/comm/keypebble/krfbserverinfo.h
@@ -0,0 +1,42 @@
1// -*- c++ -*-
2
3#ifndef KRFBSERVERINFO_H
4#define KRFBSERVERINFO_H
5
6#include <qstring.h>
7
8typedef unsigned char CARD8;
9typedef unsigned short CARD16;
10typedef unsigned long CARD32;
11
12class KRFBPixelFormat
13{
14public:
15 CARD8 bpp;
16 CARD8 depth;
17 CARD8 bigEndian;
18 CARD8 trueColor;
19 CARD16 redMax;
20 CARD16 greenMax;
21 CARD16 blueMax;
22 CARD8 redShift;
23 CARD8 greenShift;
24 CARD8 blueShift;
25 CARD8 padding[3]; // 3 bytes padding
26};
27
28/**
29 * Information sent by the server in its init message.
30 */
31class KRFBServerInfo : public KRFBPixelFormat
32{
33public:
34 CARD16 width;
35 CARD16 height;
36 CARD32 nameLength;
37 QString name;
38};
39
40#endif // KRFBSERVERINFO_H
41
42
diff --git a/noncore/comm/keypebble/kvnc.cpp b/noncore/comm/keypebble/kvnc.cpp
new file mode 100644
index 0000000..bb18999
--- a/dev/null
+++ b/noncore/comm/keypebble/kvnc.cpp
@@ -0,0 +1,191 @@
1#include <qiconset.h>
2#include <qdialog.h>
3#include <qpixmap.h>
4#include <qdom.h>
5#include <qaction.h>
6#include <qpe/qpemenubar.h>
7#include <qstatusbar.h>
8#include <qpopupmenu.h>
9#include <qpushbutton.h>
10#include <qpe/qpetoolbar.h>
11#include <qtimer.h>
12#include <qmessagebox.h>
13#include <qpe/qpeapplication.h>
14#include <qpe/global.h>
15#include <assert.h>
16
17#include "kvnc.h"
18#include "krfbcanvas.h"
19#include "kvncoptionsdlg.h"
20#include "krfbconnection.h"
21
22
23/* XPM */
24static char * menu_xpm[] = {
25"12 12 5 1",
26 " c None",
27 ".c #000000",
28 "+c #FFFDAD",
29 "@c #FFFF00",
30 "#c #E5E100",
31" ",
32" ",
33" ......... ",
34" .+++++++. ",
35" .+@@@@#. ",
36" .+@@@#. ",
37" .+@@#. ",
38" .+@#. ",
39" .+#. ",
40" .+. ",
41" .. ",
42" "};
43
44const int StatusTextId = 0;
45
46KVNC::KVNC( const char *name ) : QMainWindow( 0, name )
47{
48 setCaption( tr("VNC Viewer") );
49 fullscreen = false;
50
51 canvas = new KRFBCanvas( this, "canvas" );
52 setCentralWidget( canvas );
53
54 connect( canvas->connection(), SIGNAL(statusChanged(const QString &)),
55 this, SLOT(statusMessage(const QString &)) );
56 connect( canvas->connection(), SIGNAL(error(const QString &)),
57 this, SLOT(error(const QString &)) );
58 connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) );
59 connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) );
60 connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) );
61
62 setupActions();
63
64 cornerButton = new QPushButton( this );
65 cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) );
66 connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) );
67 canvas->setCornerWidget( cornerButton );
68
69 QTimer::singleShot( 0, canvas, SLOT(openConnection()) );
70}
71
72KVNC::~KVNC()
73{
74
75}
76
77void KVNC::openURL( const QUrl &url )
78{
79 canvas->openURL( url );
80}
81
82void KVNC::setupActions()
83{
84 cornerMenu = new QPopupMenu( this );
85
86 fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 );
87 connect( fullScreenAction, SIGNAL(activated()),
88 this, SLOT( toggleFullScreen() ) );
89 fullScreenAction->addTo( cornerMenu );
90 fullScreenAction->setEnabled( false );
91
92 optionsAction = new QAction( tr("Settings"), QString::null, 0, 0 );
93 connect( optionsAction, SIGNAL(activated()), this, SLOT( showOptions() ) );
94 optionsAction->addTo( cornerMenu );
95
96 connectAction = new QAction( tr("Connect..."), QString::null, 0, 0 );
97 connect( connectAction, SIGNAL(activated()),
98 canvas, SLOT( openConnection() ) );
99 connectAction->addTo( cornerMenu );
100
101 disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 );
102 connect( disconnectAction, SIGNAL(activated()),
103 this, SLOT( closeConnection() ) );
104 disconnectAction->addTo( cornerMenu );
105 disconnectAction->setEnabled( false );
106}
107
108void KVNC::toggleFullScreen()
109{
110 if ( fullscreen ) {
111 canvas->releaseKeyboard();
112 canvas->reparent( this, 0, QPoint(0,0), false );
113 canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken );
114 setCentralWidget( canvas );
115 canvas->show();
116 fullScreenAction->setText( tr("Full Screen") );
117 } else {
118 canvas->setFrameStyle( QFrame::NoFrame );
119 canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop,
120 QPoint(0,0),false);
121 canvas->resize(qApp->desktop()->width(), qApp->desktop()->height());
122 canvas->raise();
123 canvas->setFocus();
124 canvas->grabKeyboard();
125 canvas->show();
126
127 fullScreenAction->setText( tr("Stop Full Screen") );
128 }
129
130 fullscreen = !fullscreen;
131}
132
133void KVNC::closeConnection()
134{
135 if ( fullscreen )
136 toggleFullScreen();
137 canvas->closeConnection();
138}
139
140void KVNC::showMenu()
141{
142 QPoint pt = mapToGlobal(cornerButton->pos());
143 QSize s = cornerMenu->sizeHint();
144 pt.ry() -= s.height();
145 pt.rx() -= s.width();
146 cornerMenu->popup( pt );
147}
148
149void KVNC::connected()
150{
151 static QString msg = tr( "Connected to remote host" );
152 statusMessage( msg );
153 connectAction->setEnabled( false );
154 disconnectAction->setEnabled( true );
155 fullScreenAction->setEnabled( true );
156}
157
158void KVNC::loggedIn()
159{
160 static QString msg = tr( "Logged in to remote host" );
161 statusMessage( msg );
162}
163
164void KVNC::disconnected()
165{
166 static QString msg = tr( "Connection closed" );
167 statusMessage( msg );
168 connectAction->setEnabled( true );
169 disconnectAction->setEnabled( false );
170 fullScreenAction->setEnabled( false );
171}
172
173void KVNC::statusMessage( const QString &m )
174{
175 Global::statusMessage( m );
176}
177
178void KVNC::error( const QString &msg )
179{
180 statusMessage( msg );
181 QMessageBox::warning( this, tr("VNC Viewer"), msg );
182}
183
184void KVNC::showOptions()
185{
186 KVNCOptionsDlg *wdg = new KVNCOptionsDlg( canvas->connection()->options(), this );
187 wdg->showMaximized();
188 wdg->exec();
189 delete wdg;
190}
191
diff --git a/noncore/comm/keypebble/kvnc.h b/noncore/comm/keypebble/kvnc.h
new file mode 100644
index 0000000..92666c5
--- a/dev/null
+++ b/noncore/comm/keypebble/kvnc.h
@@ -0,0 +1,56 @@
1// -*- c++ -*-
2
3#ifndef KVNC_H
4#define KVNC_H
5
6#include <qmainwindow.h>
7#include <qurl.h>
8
9class QAction;
10class KRFBCanvas;
11class QPushButton;
12class QToolBar;
13
14/**
15 * Top level window for Keystone.
16 *
17 * @author Richard Moore, rich@kde.org
18 * @version $Id$
19 */
20class KVNC : public QMainWindow
21{
22 Q_OBJECT
23public:
24 KVNC( const char *name = 0 );
25 ~KVNC();
26
27public slots:
28 void toggleFullScreen();
29 void openURL( const QUrl & );
30 void closeConnection();
31 void showOptions();
32
33protected:
34 void setupActions();
35
36protected slots:
37 void showMenu();
38
39 void connected();
40 void loggedIn();
41 void disconnected();
42 void statusMessage( const QString & );
43 void error( const QString & );
44
45private:
46 bool fullscreen;
47 KRFBCanvas *canvas;
48 QPopupMenu *cornerMenu;
49 QPushButton *cornerButton;
50 QAction *fullScreenAction;
51 QAction *optionsAction;
52 QAction *disconnectAction;
53 QAction *connectAction;
54};
55
56#endif // KVNC_H
diff --git a/noncore/comm/keypebble/kvncconnectdlg.cpp b/noncore/comm/keypebble/kvncconnectdlg.cpp
new file mode 100644
index 0000000..467cebf
--- a/dev/null
+++ b/noncore/comm/keypebble/kvncconnectdlg.cpp
@@ -0,0 +1,79 @@
1#include <qstring.h>
2#include <qlayout.h>
3#include <qframe.h>
4#include <qspinbox.h>
5#include <qcombobox.h>
6#include <qlabel.h>
7#include <qfont.h>
8
9#include <assert.h>
10
11#include "krfbconnection.h"
12#include "kvncoptionsdlg.h"
13#include "kvncconnectdlg.h"
14
15
16KVNCConnectDlg::KVNCConnectDlg( KRFBConnection *con,
17 QWidget *parent, const char *name )
18 : QDialog( parent, name, true )
19{
20 setCaption( tr("Connect to VNC server") );
21 assert( con );
22 this->con = con;
23
24 QGridLayout *inner = new QGridLayout( this, 3, 2, 6 );
25
26 QLabel *label = new QLabel( tr("Host Name:"),
27 this , "hostLabel");
28 hostNameCombo = new QComboBox( true, this );
29 hostNameCombo->setInsertionPolicy( QComboBox::AtTop );
30 hostNameCombo->setMaxCount( 10 );
31 hostNameCombo->insertItem( "localhost" );
32 hostNameCombo->setFocus();
33
34 inner->addWidget( label, 0, 0 );
35 inner->addWidget( hostNameCombo, 0, 1 );
36
37 label = new QLabel( tr("Display Number:"), this, "displayNumber" );
38 displayNumberEdit = new QSpinBox( this );
39
40 inner->addWidget( label, 1, 0 );
41 inner->addWidget( displayNumberEdit, 1, 1 );
42
43 // if ( viewer->display() != -1 ) {
44 // displayNumberEdit->setValue( viewer->display() );
45 displayNumberEdit->setValue( 1 );
46 // }
47
48 label = new QLabel( tr("Password:"), this );
49 inner->addWidget( label, 2, 0 );
50
51 passwordEdit = new QLineEdit( this );
52 passwordEdit->setEchoMode( QLineEdit::Password );
53 inner->addWidget( passwordEdit, 2, 1 );
54
55 inner->setColStretch( 0, 0 );
56 inner->setColStretch( 1, 15 );
57}
58
59
60void KVNCConnectDlg::accept()
61{
62 int dis;
63 // viewer->setHost(hostNameCombo->currentText());
64 QString temp = displayNumberEdit->text();
65 if(temp.isEmpty())
66 dis = -1;
67 else
68 dis = temp.toUInt();
69 // viewer->setDisplay(dis);
70 QDialog::accept();
71}
72
73void KVNCConnectDlg::options()
74{
75 KVNCOptionsDlg *wdg = new KVNCOptionsDlg( con->options(), this );
76 wdg->exec();
77 delete wdg;
78}
79
diff --git a/noncore/comm/keypebble/kvncconnectdlg.h b/noncore/comm/keypebble/kvncconnectdlg.h
new file mode 100644
index 0000000..cf34aab
--- a/dev/null
+++ b/noncore/comm/keypebble/kvncconnectdlg.h
@@ -0,0 +1,39 @@
1// -*- c++ -*-
2
3#ifndef KVNCCONNECTDLG_H
4#define KVNCCONNECTDLG_H
5
6#include <qdialog.h>
7#include <qspinbox.h>
8#include <qcombobox.h>
9#include <qlineedit.h>
10#include <qurl.h>
11
12class KRFBConnection;
13
14class KVNCConnectDlg : public QDialog
15{
16 Q_OBJECT
17
18public:
19 KVNCConnectDlg( KRFBConnection *con,
20 QWidget *parent = 0, const char *name = 0 );
21
22 QString hostname() { return hostNameCombo->currentText(); };
23 int display() { return displayNumberEdit->value(); };
24 QString password() const { return passwordEdit->text(); }
25
26protected:
27 void accept();
28
29protected slots:
30 void options();
31
32private:
33 QComboBox *hostNameCombo;
34 QSpinBox *displayNumberEdit;
35 QLineEdit *passwordEdit;
36 KRFBConnection *con;
37};
38
39#endif // KVNCCONNECTDLG_H
diff --git a/noncore/comm/keypebble/kvncoptionsdlg.cpp b/noncore/comm/keypebble/kvncoptionsdlg.cpp
new file mode 100644
index 0000000..b9f57d1
--- a/dev/null
+++ b/noncore/comm/keypebble/kvncoptionsdlg.cpp
@@ -0,0 +1,53 @@
1#include <qframe.h>
2#include <qvbox.h>
3#include <qcheckbox.h>
4#include <qspinbox.h>
5#include <qlabel.h>
6#include <qlayout.h>
7#include <qwhatsthis.h>
8#include <qapplication.h>
9#include "krfboptions.h"
10
11#include "kvncoptionsdlg.h"
12
13KVNCOptionsDlg::KVNCOptionsDlg( KRFBOptions *options,
14 QWidget *parent, char *name, bool modal )
15 : VncOptionsBase( parent, name, modal )
16{
17 this->options = options;
18
19 hex->setChecked( options->hexTile );
20 corre->setChecked( options->corre );
21 rre->setChecked( options->rre );
22 copyRect->setChecked( options->copyrect );
23
24 // TODO
25 hex->setEnabled( false );
26 corre->setEnabled( false );
27 rre->setEnabled( false );
28 // /TODO
29
30 deIconify->setChecked( options->deIconify );
31 bit->setChecked( options->colors256 );
32 shared->setChecked( options->shared );
33 timeBox->setValue( options->updateRate );
34}
35
36KVNCOptionsDlg::~KVNCOptionsDlg()
37{
38}
39
40void KVNCOptionsDlg::accept()
41{
42 options->hexTile = hex->isChecked();
43 options->corre = corre->isChecked();
44 options->rre = rre->isChecked();
45 options->copyrect = copyRect->isChecked();
46 options->deIconify = deIconify->isChecked();
47 options->colors256 = bit->isChecked();
48 options->shared = shared->isChecked();
49 options->updateRate = timeBox->value();
50
51 QDialog::accept();
52}
53
diff --git a/noncore/comm/keypebble/kvncoptionsdlg.h b/noncore/comm/keypebble/kvncoptionsdlg.h
new file mode 100644
index 0000000..a166490
--- a/dev/null
+++ b/noncore/comm/keypebble/kvncoptionsdlg.h
@@ -0,0 +1,30 @@
1// -*- c++ -*-
2
3#ifndef KVNCOPTIONSDIALOG_H
4#define KVNCOPTIONSDIALOG_H
5
6#include "vncoptionsbase.h"
7
8class KRFBOptions;
9
10class KVNCOptionsDlg : public VncOptionsBase
11{
12Q_OBJECT
13
14public:
15 KVNCOptionsDlg( KRFBOptions *options,
16 QWidget *parent = 0, char *name = 0, bool modal = true );
17 ~KVNCOptionsDlg();
18
19protected:
20 void accept();
21
22private:
23 KRFBOptions *options;
24};
25
26#endif // KVNCOPTIONSDIALOG_H
27
28
29
30
diff --git a/noncore/comm/keypebble/main.cpp b/noncore/comm/keypebble/main.cpp
new file mode 100644
index 0000000..a32a368
--- a/dev/null
+++ b/noncore/comm/keypebble/main.cpp
@@ -0,0 +1,18 @@
1
2
3#include <qurl.h>
4#include <qpe/qpeapplication.h>
5#include "kvnc.h"
6
7int main( int argc, char **argv )
8{
9 QPEApplication app( argc, argv );
10 KVNC *view = new KVNC( "Keypebble" );
11 app.showMainWidget( view );
12
13 if ( argc > 1 )
14 view->openURL( QUrl(argv[1]) );
15
16 return app.exec();
17}
18
diff --git a/noncore/comm/keypebble/qpe-keypebble.control b/noncore/comm/keypebble/qpe-keypebble.control
new file mode 100644
index 0000000..75c1b9f
--- a/dev/null
+++ b/noncore/comm/keypebble/qpe-keypebble.control
@@ -0,0 +1,10 @@
1Files: bin/keypebble apps/Applications/keypebble.desktop pics/vnc.png
2Priority: optional
3Section: qpe/applications
4Maintainer: Martin Jones <mjones@trolltech.com>
5Architecture: arm
6Arch: iPAQ
7Version: $QPE_VERSION-2
8Depends: qpe-base ($QPE_VERSION)
9Description: VNC Viewer
10 Virtual Network Computing (VNC) viewer
diff --git a/noncore/comm/keypebble/vncauth.c b/noncore/comm/keypebble/vncauth.c
new file mode 100644
index 0000000..dc276bf
--- a/dev/null
+++ b/noncore/comm/keypebble/vncauth.c
@@ -0,0 +1,160 @@
1/*
2 * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
3 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20/*
21 * vncauth.c - Functions for VNC password management and authentication.
22 */
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <time.h>
30#include "vncauth.h"
31#include "d3des.h"
32
33
34/*
35 * We use a fixed key to store passwords, since we assume that our local
36 * file system is secure but nonetheless don't want to store passwords
37 * as plaintext.
38 */
39
40unsigned char fixedkey[8] = {23,82,107,6,35,78,88,7};
41
42
43/*
44 * Encrypt a password and store it in a file. Returns 0 if successful,
45 * 1 if the file could not be written.
46 */
47
48int
49vncEncryptAndStorePasswd(char *passwd, char *fname)
50{
51 FILE *fp;
52 int i;
53 unsigned char encryptedPasswd[8];
54
55 if ((fp = fopen(fname,"w")) == NULL) return 1;
56
57 chmod(fname, S_IRUSR|S_IWUSR);
58
59 /* pad password with nulls */
60
61 for (i = 0; i < 8; i++) {
62 if (i < strlen(passwd)) {
63 encryptedPasswd[i] = passwd[i];
64 } else {
65 encryptedPasswd[i] = 0;
66 }
67 }
68
69 /* Do encryption in-place - this way we overwrite our copy of the plaintext
70 password */
71
72 deskey(fixedkey, EN0);
73 des(encryptedPasswd, encryptedPasswd);
74
75 for (i = 0; i < 8; i++) {
76 putc(encryptedPasswd[i], fp);
77 }
78
79 fclose(fp);
80 return 0;
81}
82
83
84/*
85 * Decrypt a password from a file. Returns a pointer to a newly allocated
86 * string containing the password or a null pointer if the password could
87 * not be retrieved for some reason.
88 */
89
90char *
91vncDecryptPasswdFromFile(char *fname)
92{
93 FILE *fp;
94 int i, ch;
95 unsigned char *passwd = (unsigned char *)malloc(9);
96
97 if ((fp = fopen(fname,"r")) == NULL) return NULL;
98
99 for (i = 0; i < 8; i++) {
100 ch = getc(fp);
101 if (ch == EOF) {
102 fclose(fp);
103 return NULL;
104 }
105 passwd[i] = ch;
106 }
107
108 deskey(fixedkey, DE1);
109 des(passwd, passwd);
110
111 passwd[8] = 0;
112
113 return (char *)passwd;
114}
115
116
117/*
118 * Generate CHALLENGESIZE random bytes for use in challenge-response
119 * authentication.
120 */
121
122void
123vncRandomBytes(unsigned char *bytes)
124{
125 int i;
126 unsigned int seed = (unsigned int) time(0);
127
128 srandom(seed);
129 for (i = 0; i < CHALLENGESIZE; i++) {
130 bytes[i] = (unsigned char)(random() & 255);
131 }
132}
133
134
135/*
136 * Encrypt CHALLENGESIZE bytes in memory using a password.
137 */
138
139void
140vncEncryptBytes(unsigned char *bytes, char *passwd)
141{
142 unsigned char key[8];
143 int i;
144
145 /* key is simply password padded with nulls */
146
147 for (i = 0; i < 8; i++) {
148 if (i < strlen(passwd)) {
149 key[i] = passwd[i];
150 } else {
151 key[i] = 0;
152 }
153 }
154
155 deskey(key, EN0);
156
157 for (i = 0; i < CHALLENGESIZE; i += 8) {
158 des(bytes+i, bytes+i);
159 }
160}
diff --git a/noncore/comm/keypebble/vncauth.h b/noncore/comm/keypebble/vncauth.h
new file mode 100644
index 0000000..38b289e
--- a/dev/null
+++ b/noncore/comm/keypebble/vncauth.h
@@ -0,0 +1,30 @@
1/*
2 * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
3 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20/*
21 * vncauth.h - describes the functions provided by the vncauth library.
22 */
23
24#define MAXPWLEN 8
25#define CHALLENGESIZE 16
26
27extern int vncEncryptAndStorePasswd(char *passwd, char *fname);
28extern char *vncDecryptPasswdFromFile(char *fname);
29extern void vncRandomBytes(unsigned char *bytes);
30extern void vncEncryptBytes(unsigned char *bytes, char *passwd);
diff --git a/noncore/comm/keypebble/vncoptionsbase.ui b/noncore/comm/keypebble/vncoptionsbase.ui
new file mode 100644
index 0000000..d049a79
--- a/dev/null
+++ b/noncore/comm/keypebble/vncoptionsbase.ui
@@ -0,0 +1,270 @@
1<!DOCTYPE UI><UI>
2<class>VncOptionsBase</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>VncOptionsBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>234</width>
15 <height>221</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>VNC Viewer Options</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <vbox>
26 <property stdset="1">
27 <name>margin</name>
28 <number>0</number>
29 </property>
30 <property stdset="1">
31 <name>spacing</name>
32 <number>6</number>
33 </property>
34 <widget>
35 <class>QTabWidget</class>
36 <property stdset="1">
37 <name>name</name>
38 <cstring>TabWidget3</cstring>
39 </property>
40 <widget>
41 <class>QWidget</class>
42 <property stdset="1">
43 <name>name</name>
44 <cstring>tab</cstring>
45 </property>
46 <attribute>
47 <name>title</name>
48 <string>Data Encoding</string>
49 </attribute>
50 <vbox>
51 <property stdset="1">
52 <name>margin</name>
53 <number>11</number>
54 </property>
55 <property stdset="1">
56 <name>spacing</name>
57 <number>6</number>
58 </property>
59 <widget>
60 <class>QLabel</class>
61 <property stdset="1">
62 <name>name</name>
63 <cstring>TextLabel1</cstring>
64 </property>
65 <property stdset="1">
66 <name>text</name>
67 <string>Check for screen updates every:</string>
68 </property>
69 </widget>
70 <widget>
71 <class>QLayoutWidget</class>
72 <property stdset="1">
73 <name>name</name>
74 <cstring>Layout2</cstring>
75 </property>
76 <hbox>
77 <property stdset="1">
78 <name>margin</name>
79 <number>0</number>
80 </property>
81 <property stdset="1">
82 <name>spacing</name>
83 <number>6</number>
84 </property>
85 <widget>
86 <class>QSpinBox</class>
87 <property stdset="1">
88 <name>name</name>
89 <cstring>timeBox</cstring>
90 </property>
91 <property stdset="1">
92 <name>maxValue</name>
93 <number>500</number>
94 </property>
95 <property stdset="1">
96 <name>minValue</name>
97 <number>1</number>
98 </property>
99 </widget>
100 <widget>
101 <class>QLabel</class>
102 <property stdset="1">
103 <name>name</name>
104 <cstring>TextLabel2</cstring>
105 </property>
106 <property stdset="1">
107 <name>text</name>
108 <string>Milliseconds</string>
109 </property>
110 </widget>
111 </hbox>
112 </widget>
113 <widget>
114 <class>QCheckBox</class>
115 <property stdset="1">
116 <name>name</name>
117 <cstring>bit</cstring>
118 </property>
119 <property stdset="1">
120 <name>text</name>
121 <string>Request 8-bit session</string>
122 </property>
123 </widget>
124 <widget>
125 <class>QCheckBox</class>
126 <property stdset="1">
127 <name>name</name>
128 <cstring>deIconify</cstring>
129 </property>
130 <property stdset="1">
131 <name>text</name>
132 <string>Raise on bell</string>
133 </property>
134 </widget>
135 <widget>
136 <class>QCheckBox</class>
137 <property stdset="1">
138 <name>name</name>
139 <cstring>shared</cstring>
140 </property>
141 <property stdset="1">
142 <name>text</name>
143 <string>Request shared session</string>
144 </property>
145 </widget>
146 <spacer>
147 <property>
148 <name>name</name>
149 <cstring>Spacer2</cstring>
150 </property>
151 <property stdset="1">
152 <name>orientation</name>
153 <enum>Vertical</enum>
154 </property>
155 <property stdset="1">
156 <name>sizeType</name>
157 <enum>Expanding</enum>
158 </property>
159 <property>
160 <name>sizeHint</name>
161 <size>
162 <width>20</width>
163 <height>20</height>
164 </size>
165 </property>
166 </spacer>
167 </vbox>
168 </widget>
169 <widget>
170 <class>QWidget</class>
171 <property stdset="1">
172 <name>name</name>
173 <cstring>tab</cstring>
174 </property>
175 <attribute>
176 <name>title</name>
177 <string>Connection</string>
178 </attribute>
179 <vbox>
180 <property stdset="1">
181 <name>margin</name>
182 <number>11</number>
183 </property>
184 <property stdset="1">
185 <name>spacing</name>
186 <number>6</number>
187 </property>
188 <widget>
189 <class>QCheckBox</class>
190 <property stdset="1">
191 <name>name</name>
192 <cstring>hex</cstring>
193 </property>
194 <property stdset="1">
195 <name>enabled</name>
196 <bool>false</bool>
197 </property>
198 <property stdset="1">
199 <name>text</name>
200 <string>Hextile encoding</string>
201 </property>
202 </widget>
203 <widget>
204 <class>QCheckBox</class>
205 <property stdset="1">
206 <name>name</name>
207 <cstring>corre</cstring>
208 </property>
209 <property stdset="1">
210 <name>enabled</name>
211 <bool>false</bool>
212 </property>
213 <property stdset="1">
214 <name>text</name>
215 <string>CoRRE encoding</string>
216 </property>
217 </widget>
218 <widget>
219 <class>QCheckBox</class>
220 <property stdset="1">
221 <name>name</name>
222 <cstring>rre</cstring>
223 </property>
224 <property stdset="1">
225 <name>enabled</name>
226 <bool>false</bool>
227 </property>
228 <property stdset="1">
229 <name>text</name>
230 <string>RRE encoding</string>
231 </property>
232 </widget>
233 <widget>
234 <class>QCheckBox</class>
235 <property stdset="1">
236 <name>name</name>
237 <cstring>copyRect</cstring>
238 </property>
239 <property stdset="1">
240 <name>text</name>
241 <string>Copy rectangle encoding</string>
242 </property>
243 </widget>
244 <spacer>
245 <property>
246 <name>name</name>
247 <cstring>Spacer3</cstring>
248 </property>
249 <property stdset="1">
250 <name>orientation</name>
251 <enum>Vertical</enum>
252 </property>
253 <property stdset="1">
254 <name>sizeType</name>
255 <enum>Expanding</enum>
256 </property>
257 <property>
258 <name>sizeHint</name>
259 <size>
260 <width>20</width>
261 <height>20</height>
262 </size>
263 </property>
264 </spacer>
265 </vbox>
266 </widget>
267 </widget>
268 </vbox>
269</widget>
270</UI>
diff --git a/noncore/games/chess/Makefile.in b/noncore/games/chess/Makefile.in
new file mode 100644
index 0000000..7354d76
--- a/dev/null
+++ b/noncore/games/chess/Makefile.in
@@ -0,0 +1,134 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) -DQCONFIG=\"qpe\"
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS) -DQCONFIG=\"qpe\"
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= chess
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =chess.h
27 SOURCES =chess.cpp \
28 main.cpp
29 OBJECTS =chess.o \
30 main.o \
31 mainwindow.o
32INTERFACES = mainwindow.ui
33UICDECLS = mainwindow.h
34UICIMPLS = mainwindow.cpp
35 SRCMOC =moc_chess.cpp \
36 moc_mainwindow.cpp
37 OBJMOC =moc_chess.o \
38 moc_mainwindow.o
39
40
41####### Implicit rules
42
43.SUFFIXES: .cpp .cxx .cc .C .c
44
45.cpp.o:
46 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
47
48.cxx.o:
49 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
50
51.cc.o:
52 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
53
54.C.o:
55 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
56
57.c.o:
58 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
59
60####### Build rules
61
62
63all: $(DESTDIR)$(TARGET)
64
65$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
66 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
67
68moc: $(SRCMOC)
69
70tmake:
71 tmake chess.pro
72
73clean:
74 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
75 -rm -f *~ core
76 -rm -f allmoc.cpp
77
78####### Extension Modules
79
80listpromodules:
81 @echo
82
83listallmodules:
84 @echo
85
86listaddonpromodules:
87 @echo
88
89listaddonentmodules:
90 @echo
91
92
93REQUIRES=
94
95####### Sub-libraries
96
97
98###### Combined headers
99
100
101
102####### Compile
103
104chess.o: chess.cpp \
105 $(QPEDIR)/include/qpe/config.h \
106 $(QPEDIR)/include/qpe/resource.h \
107 chess.h
108
109main.o: main.cpp \
110 mainwindow.h
111
112mainwindow.h: mainwindow.ui
113 $(UIC) mainwindow.ui -o $(INTERFACE_DECL_PATH)/mainwindow.h
114
115mainwindow.cpp: mainwindow.ui
116 $(UIC) mainwindow.ui -i mainwindow.h -o mainwindow.cpp
117
118mainwindow.o: mainwindow.cpp \
119 mainwindow.h \
120 mainwindow.ui
121
122moc_chess.o: moc_chess.cpp \
123 chess.h
124
125moc_mainwindow.o: moc_mainwindow.cpp \
126 mainwindow.h
127
128moc_chess.cpp: chess.h
129 $(MOC) chess.h -o moc_chess.cpp
130
131moc_mainwindow.cpp: mainwindow.h
132 $(MOC) mainwindow.h -o moc_mainwindow.cpp
133
134
diff --git a/noncore/games/chess/boardview.cw b/noncore/games/chess/boardview.cw
new file mode 100644
index 0000000..020af96
--- a/dev/null
+++ b/noncore/games/chess/boardview.cw
@@ -0,0 +1,23 @@
1<!DOCTYPE CW><CW>
2<customwidgets>
3 <customwidget>
4 <class>BoardView</class>
5 <header location="global">/home/luke/depot/qpe/chess/chess.h</header>
6 <sizehint>
7 <width>-1</width>
8 <height>-1</height>
9 </sizehint>
10 <container>0</container>
11 <sizepolicy>
12 <hordata>5</hordata>
13 <verdata>5</verdata>
14 </sizepolicy>
15 <pixmap>
16 <data format="XPM.GZ" length="4605">789c6dd7d96ee33a1206e0fb7e8aa0ebae31a863c9966d613017d9e3ecce9e0ce6a228c94b6c67f192d83998771f9af517e10493b4daf89a25b258a428f75f7fb61e2ecfb6fefcf56b3697f9b0d82a0632ddfa532e2693d5bffff3afbf7ffd4ed3adf027d94a7fffe3d76ff7b9556c9dbfbe5401ef9bf8d8c464136f9b186ee27513cf9bd8dec47c13d30d74bfb52c3d28cdd322a9058fd6aee7f5a29e047f697bbd96b483573fe2173ffc82fbdbb87fb0762389fdcdd6ee859fe0716ccfd7e6def7fed8c5f1d5c5f77c58c2788959ea70230dfd3982dba9de7f6ff9693b757ee4dbb7f9a3fdf5473d7aea464dfb23fa3e3fdafe319f3d75a3a1edbc0fb7913f9991df8b19f7977081f1ae83c5da89cd8dd0bf34601bffceaced14facfd22c53f36db484f95570a9e3398ed6f1c27ec8c4e239877378d79c85bd4f477089f117d1219ee666c4d7d4cd04fddd98d1de5ebb995abc3ca863fb04467eb26746fc398c7ce5c0aced7c1dade3bfc2983f5766acf7be19f59f466b3d4b752bc1fd9a9f58ffd28311cf6d33f2b9323735ff17752bc17855b4f697c119f2cbcd884fe15cd757d6c711b5ea2dd48766708efd959871ffb319f53c86ad1e67d1fafc89ba9d60bcaf68edffca8ce7ab8033c4b7a2b57e3bc1ae95b7eac1db70091fa9db895a6e61ab472b3af4277730e6cb5d33e69bc3781e6865c6f31ce6d3f6f9b75c881738d3f5e2b119ed27708ef655b4aedf0d6cf5fc50e709f27d84510fb930e3f94a615bdf6bb3f627f7b0cd47f3f5f36d877a5103b67af6cddace23759e20fe00b6e77da016acb77370a6e71df5cc18bf1fadfb610c0bcef304ae6aeab619ef83f57b92f286e5c3cfd1a1de3c803378095bbd9bea98cf305af7430b16d47319adf53f34637daee00af9f7d52ed57c692f5acf7fbdbfc8f3bc113c834be43b35a37d185d84feeed482fd47e77086fdbf0b57d81f75b54b311f8ad6f95e9a319f1adc44fed3689ddf132c589f8e59e385a3b5fdcc8cf1bb30d697a2311eea53a07e1cce7b6948a2f52007676ad956bb14e7e53e6cebb382adff67339eb7a5dac6930f33ce87266cf5388dd6f50ccf83f87a8baed77bb4aed78edaa5c877085738ff3fcdd89f13b58d4f68b7f1e5d48cfd589a118ff10bd49b9ea235fe12aef0fc55669c6fe17c718d42701ececcfafea2118cfb3935e3bcf98cd6f18ecc785fbd99f1beabab4bab77c38cef2b613d5c5908ced357b8c2799aa9637c12ade32dcc787fedc04d7c1fb935e33c7b8cd6f509df578aac10acef02aef0bc76ccbade7caeb6fb656ec6fe1c98f1fc5ec2a82f9f9931bf5ab4e67b0263bf70d80f455956e8efc6acf9d185ba4a51bfb119e779789f97be7f9d1fbda9637b19adf73b33e21fe026ea7162c6f31ad6a7acaad4e9fe1fc1d6be1badf53b36a39e4fb0e5771f1dda257c7fa89a668a76657013b6f509eb5bf99f225bbb3b5fff32b1b0e3c25fffefb3d4288de78a7bdce7010ffdf5cca38dabef7fc73ce1177fcf6b8c77fcc6ef3cf56d6f3ce3392ff8833f79c92bfee26ddef1f1bbbcc785c6f3be8f3be0433ef2b11d3ee6133ee5333ee70bbee42e5ff135dff02ddff13d5388179fc5d4f7f4c08ffcc4354e38e53a3738f39f4d6e719b73ce898958d7a7c74312725450491537a9477d1ad0909e69e4e39b34a609bdf01dbdb2d6abf0fd3ff8e8377aa729cd684e8b704de8833e69e97f57f4e5fbdf8efd3fd30eed724a7bb44f733ff6fa3ae0aebf6be5a30f7d2f473ebe8378f1f1c77442a77416fb3ea70bba0c77f47c465dbaa2eb6ffddfd0adefddfabea37b7aa0477aa21a25beff25a5a17fcbff994a4ea88ebe1b9451d3d734a116b529f7d15df1cbefe71bfbe753ba145af72d224e7ca5f84c4aa9bc7b7edca5f4bfe72f03df3ea485f83b652463bf0a19d765e2df012febfcb9f53d7f79f5f16ff22e5399c95c16f2219f7ec512ffe9eb232bf9fa96ff48b67ddb8eecca9eef719fbb72208772b45ee175fda523c7dff2efcb899cfad57a973339478de672219721ba2b573fea3fe61db9f6792eb9292c37722b77d4926558dbaecfa62ff73eff4eec7fc2d7f2208f612dfde5ef3c44e493cfa523354924953af22fa5e1f7f7adaf9dff4f9d5fcb25aeae7468202d1fdd96dcb123ddcfe179d9f3fbef3a5c95131abbf54fc1fe0deb3771e9a32bd7e35e7cbefc4e757d377043f78c6be4af71f87be25edcab7b73ef6eaaf16eb67e92dddc2ddc87fbf4ff6e9f9ffe73e93f57eecb6dfb081ff7fbbffffcf53f54dd2532</data>
17 </pixmap>
18 <slot access="public">newGame()</slot>
19 <slot access="public">swapSides()</slot>
20 <slot access="public">setTheme(QString)</slot>
21 </customwidget>
22</customwidgets>
23</CW>
diff --git a/noncore/games/chess/chess.cpp b/noncore/games/chess/chess.cpp
new file mode 100644
index 0000000..96a838a
--- a/dev/null
+++ b/noncore/games/chess/chess.cpp
@@ -0,0 +1,358 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22// human is not offered a promotion yet
23
24#include <qcanvas.h>
25#include <qmainwindow.h>
26#include <qlist.h>
27#include <qimage.h>
28#include <qpainter.h>
29#include <qmessagebox.h>
30#include <qregexp.h>
31
32#include <qpe/config.h>
33#include <qpe/resource.h>
34
35#include "chess.h"
36
37#define CHESS_DEBUG
38
39int pieceSize = 40;
40static QVector < QImage > imgList;
41int timeMoves, timeTime;
42
43int BoardView::convertToRank(int r)
44{
45 r = r / pieceSize;
46 if (humanSide == sideWhite)
47 r = 8 - r;
48 else
49 r++;
50 return r;
51}
52
53char BoardView::convertToFile(int f)
54{
55 f = f / pieceSize;
56 if (humanSide == sideWhite)
57 return f + 'a';
58 else
59 return 'h' - f;
60}
61
62int BoardView::convertFromFile(char f)
63{
64 if (humanSide == sideWhite)
65 f = f - 'a';
66 else
67 f = 'h' - f;
68 return f * pieceSize;
69}
70
71int BoardView::convertFromRank(int r)
72{
73 if (humanSide == sideWhite)
74 r = 8 - r;
75 else
76 r--;
77 return r * pieceSize;
78}
79
80// Pieces
81Piece::Piece(QCanvas * canvas, int t):QCanvasRectangle(canvas)
82{
83 type = t;
84 setSize(pieceSize, pieceSize);
85 show();
86}
87
88Piece *BoardView::newPiece(int t, char f, int r)
89{
90 Piece *tmpPiece = new Piece(canvas(), t);
91 tmpPiece->move(convertFromFile(f), convertFromRank(r));
92 list.append(tmpPiece);
93 return tmpPiece;
94}
95
96void BoardView::deletePiece(Piece * p)
97{
98 list.remove(p);
99 canvas()->update();
100}
101
102void Piece::drawShape(QPainter & p)
103{
104 p.drawImage(int (x()), int (y()), *(imgList[type]));
105}
106
107void BoardView::buildImages(QImage theme)
108{
109 imgList.resize(12);
110 int x;
111 int y = 0;
112
113 for (int j = 0; j < 2; j++) {
114 x = 0;
115 for (int i = 0; i < 6; i++) {
116 imgList.insert(i + (j * 6),
117 new QImage(theme.
118 copy(x, y, pieceSize, pieceSize)));
119 x += pieceSize;
120 }
121 y += pieceSize;
122 }
123}
124
125void BoardView::readStdout()
126{
127 QString input( crafty->readStdout() );
128#ifdef CHESS_DEBUG
129 qDebug("received this string from crafty->\n%s\n", input.latin1());
130#endif
131
132 int startPosition = input.find("setboard");
133 if (startPosition != -1)
134 decodePosition(input.remove(0, startPosition + 9));
135
136 if (input.contains("Black mates")) {
137 playingGame = FALSE;
138 emit(showMessage("Black mates"));
139 } else if (input.contains("White mates")) {
140 playingGame = FALSE;
141 emit(showMessage("White mates"));
142 } else if (input.contains(" resigns")) {
143 playingGame = FALSE;
144 emit(showMessage("Computer resigns"));
145 } else if (input.contains("Draw")) {
146 playingGame = FALSE;
147 emit(showMessage("Draw"));
148 }
149}
150
151// this is pretty close to getting done right
152// maybe dont use sprites and just draw a picture
153// there'll be lots of drawing done anyway
154// eg creating pictures for the webpages,
155// and presenting options for promotions
156void BoardView::decodePosition(const QString & t)
157{
158 qDebug("decode copped %s \n", t.latin1());
159
160 int count = 0;
161 int stringPos = 0;
162 for (int file = 0; file < 8; file++) {
163 for (int rank = 0; rank < 8; rank++) {
164 if (count)
165 count--;
166 else {
167 if (t.at(stringPos).isNumber())
168 count = t.at(stringPos).digitValue();
169 else {
170 newPiece(t.at(stringPos).latin1(), 'a' + file,
171 rank + 1);
172 }
173 }
174 }
175 }
176}
177
178void BoardView::undo()
179{
180 crafty->writeToStdin("undo\n");
181 crafty->writeToStdin("savepos\nclock\n");
182}
183
184void BoardView::emitErrorMessage()
185{
186 if (activeSide != humanSide)
187 emit(showMessage("Not your move"));
188 else
189 emit(showMessage("You are not playing a game"));
190}
191
192void BoardView::annotateGame()
193{
194 crafty->
195 writeToStdin
196 ("savegame game.save\nannotateh game.save bw 0 1.0 1\n");
197 emit(showMessage("Annotating game"));
198}
199
200Piece *BoardView::findPiece(char f, int r)
201{
202 QListIterator < Piece > it(list);
203 Piece *tmpPiece;
204 for (; it.current(); ++it) {
205 tmpPiece = it.current();
206 if (convertToRank(tmpPiece->x()) == r
207 && convertToFile(tmpPiece->y()) == f)
208 return tmpPiece;
209 }
210 return 0;
211}
212
213void BoardView::newGame()
214{
215 activeSide = sideWhite;
216 emit(showMessage("New game"));
217 crafty->writeToStdin("new\n");
218 crafty->writeToStdin("savepos\n");
219 crafty->writeToStdin("time " +
220 QString::number(timeMoves) +
221 "/" + QString::number(timeTime) + "\n");
222 activeSide = sideWhite;
223 if (humanSide == sideBlack)
224 crafty->writeToStdin("go\n");
225}
226
227void BoardView::setTheme(QString filename)
228{
229 QImage theme = Resource::loadImage(QString("chess/") + filename);
230 pieceSize = theme.height() / 2;
231 setFrameStyle(QFrame::Plain);
232 setFixedSize(8 * pieceSize, 8 * pieceSize);
233 canvas()->setBackgroundColor(Qt::red);
234 canvas()->resize(8 * pieceSize, 8 * pieceSize);
235 whiteSquare = theme.copy(6 * pieceSize, 0, pieceSize, pieceSize);
236 activeWhiteSquare = theme.copy(7 * pieceSize, 0, pieceSize, pieceSize);
237 blackSquare =
238 theme.copy(6 * pieceSize, pieceSize, pieceSize, pieceSize);
239 activeBlackSquare =
240 theme.copy(7 * pieceSize, pieceSize, pieceSize, pieceSize);
241 buildImages(theme);
242 drawBackgroundImage(QPoint(-1, -1));
243}
244
245
246// sets the bg to the default background image for the current theme
247// also resposible for drawing the "active" marker
248void BoardView::drawBackgroundImage(QPoint activeSquare)
249{
250 bg = QPixmap(8 * pieceSize, 8 * pieceSize);
251 QPainter p(&bg);
252 bool col = FALSE;
253 for (int i = 0; i < 8; i++) {
254 for (int j = 0; j < 8; j++) {
255 QPoint point(i * pieceSize, j * pieceSize);
256 if (col) {
257 if (point.x() == activeSquare.x()
258 && point.y() == activeSquare.y())
259 p.drawImage(point, activeBlackSquare);
260 else
261 p.drawImage(point, blackSquare);
262 col = FALSE;
263 } else {
264 if (point.x() == activeSquare.x()
265 && point.y() == activeSquare.y())
266 p.drawImage(point, activeWhiteSquare);
267 else
268 p.drawImage(point, whiteSquare);
269 col = TRUE;
270 }
271 }
272 col = !col;
273 }
274 canvas()->setBackgroundPixmap(bg);
275 canvas()->update();
276}
277
278
279// Board view widget
280void BoardView::contentsMousePressEvent(QMouseEvent * e)
281{
282 QCanvasItemList cList = canvas()->collisions(e->pos());
283 if (activeSide == humanSide && playingGame) {
284 if (!activePiece) {
285 if (cList.count()) {
286 activePiece = (Piece *) (*(cList.at(0)));
287 drawBackgroundImage(QPoint
288 (activePiece->x(), activePiece->y()));
289 }
290 } else {
291 if (!(activePiece == (Piece *) (*(cList.at(0))))) {
292 char fromFile = convertToFile(activePiece->x());
293 int fromRank = convertToRank(activePiece->y());
294 char toFile = convertToFile(e->pos().x());
295 int toRank = convertToRank(e->pos().y());
296 QString moveS;
297 moveS.append(fromFile);
298 moveS.append(moveS.number(fromRank));
299 moveS.append(toFile);
300 moveS.append(moveS.number(toRank));
301 if ((activePiece->type == wPawn
302 && fromRank == 7 && toRank == 8)
303 || (activePiece->type == bPawn
304 && fromRank == 2 && toRank == 1)) {
305 // offer a promotion
306 emit(showMessage
307 ("you are meant to be offered a promotion here"));
308 char promoteTo = wQueen;// doesnt matter for now
309 moveS.append(promoteTo);
310 moveS.append("\n");
311 crafty->writeToStdin(moveS.latin1());
312 }
313 }
314 activePiece = 0;
315 drawBackgroundImage(QPoint(-1, -1));
316 }
317 }
318
319 else {
320 emitErrorMessage();
321 }
322}
323
324void BoardView::swapSides()
325{
326 if (activeSide == humanSide && playingGame) {
327 humanSide = !humanSide;
328 crafty->writeToStdin("savepos\ngo\n");
329 } else
330 emitErrorMessage();
331}
332
333BoardView::BoardView(QCanvas *c, QWidget *w, const char *name)
334 : QCanvasView(c, w, name) {
335 humanSide = sideWhite;
336 activeSide = sideWhite;
337 playingGame = TRUE;
338 activePiece = 0;
339 list.setAutoDelete(TRUE);
340 setCanvas(new QCanvas());
341 Config c("Chess", Config::User);
342 c.setGroup("Theme");
343 QString theme = c.readEntry("imagefile", "simple-28");
344 setTheme(theme);
345 crafty = new CraftyProcess(this);
346 crafty->addArgument("crafty");
347 if (!crafty->start()) {
348 QMessageBox::critical(0,
349 tr("Could not find crafty chess engine"),
350 tr("Quit"));
351 exit(-1);
352 }
353
354 connect(crafty, SIGNAL(readyReadStdout()), this, SLOT(readStdout()));
355 connect(crafty, SIGNAL(processExited()), this, SLOT(craftyDied()));
356// crafty->writeToStdin("xboard\nics\nkibitz=2\n");
357 newGame();
358}
diff --git a/noncore/games/chess/chess.db b/noncore/games/chess/chess.db
new file mode 100644
index 0000000..b520b30
--- a/dev/null
+++ b/noncore/games/chess/chess.db
@@ -0,0 +1,2 @@
1<!DOCTYPE DB><DB version="1.0">
2</DB>
diff --git a/noncore/games/chess/chess.h b/noncore/games/chess/chess.h
new file mode 100644
index 0000000..067b2f8
--- a/dev/null
+++ b/noncore/games/chess/chess.h
@@ -0,0 +1,128 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19** $Id$
20**
21**********************************************************************/
22#ifndef CHESS_H
23#define CHESS_H
24
25#include <qwidget.h>
26#include <qcanvas.h>
27#include <qmainwindow.h>
28#include <qpixmap.h>
29#include <qimage.h>
30#include <qstack.h>
31#include <qvector.h>
32#include <qpe/process.h>
33
34#define wPawn 'P'
35 #definewKnight 'N'
36#define wBishop 'B'
37#define wRook 'R'
38#define wQueen 'Q'
39#define wKing 'K'
40#define bPawn 'p'
41#define bKnight 'n'
42#define bBishop 'b'
43#define bRook 'r'
44#define bQueen 'q'
45#define bKing 'k'
46#define NONE N
47
48#define sideWhite 0
49#define sideBlack 1
50
51
52class Piece:public QCanvasRectangle {
53 public:
54 Piece(QCanvas *, int);
55 ~Piece() {
56 };
57
58 char type;
59
60 protected:
61 void drawShape(QPainter &);
62};
63
64
65class CraftyProcess : public Process {
66 public:
67 CraftyProcess(QObject *parent) : Process( parent ) { qDebug("CraftyProcess functions not implemented"); }
68 ~CraftyProcess() { }
69 bool start() { qDebug("CraftyProcess functions not implemented"); return FALSE; }
70 const char *readStdout() { qDebug("CraftyProcess functions not implemented"); return "Blah"; }
71 void writeToStdin(const char *) { qDebug("CraftyProcess functions not implemented"); }
72};
73
74
75class BoardView:public QCanvasView {
76 Q_OBJECT public:
77 BoardView(QCanvas *, QWidget *, const char *);
78 ~BoardView() {
79 };
80
81 protected:
82 void contentsMousePressEvent(QMouseEvent *);
83
84 signals:
85 void showMessage(const QString &);
86
87 public slots:void readStdout();
88 void craftyDied() {
89 qFatal("Crafty died unexpectedly\n");
90 };
91 void newGame();
92 void setTheme(QString);
93 void swapSides();
94 void undo();
95 void annotateGame();
96
97 private:
98 CraftyProcess * crafty;
99 QList < Piece > list;
100 Piece *activePiece;
101
102 void revertLastMove();
103 void emitErrorMessage();
104 void drawBackgroundImage(QPoint activeSquare);
105
106 void buildImages(QImage);
107
108 char convertToFile(int);
109 int convertToRank(int);
110 int convertFromFile(char);
111 int convertFromRank(int);
112
113 void decodePosition(const QString & t);
114
115 Piece *findPiece(char f, int r);
116 Piece *newPiece(int, char, int);
117 void deletePiece(Piece *);
118
119 int pieceSize;
120 QPixmap bg;
121 QImage whiteSquare, blackSquare, activeWhiteSquare, activeBlackSquare;
122
123 bool humanSide;
124 bool activeSide;
125 bool playingGame;
126};
127
128#endif
diff --git a/noncore/games/chess/chess.pro b/noncore/games/chess/chess.pro
new file mode 100644
index 0000000..f6650a0
--- a/dev/null
+++ b/noncore/games/chess/chess.pro
@@ -0,0 +1,14 @@
1 SOURCES+= chess.cpp main.cpp
2 HEADERS+= chess.h
3DESTDIR = ../bin
4TARGET = chess
5 DEPENDPATH+= $(QPEDIR)/include
6INTERFACES = mainwindow.ui
7 IMAGES= images/new.png images/repeat.png images/txt.png images/back.png
8 TEMPLATE=app
9 CONFIG+= qt warn_on release
10INCLUDEPATH += $(QPEDIR)/include
11 LIBS+= -lqpe
12 DBFILE= chess.db
13 LANGUAGE= C++
14 CPP_ALWAYS_CREATE_SOURCE= TRUE
diff --git a/noncore/games/chess/main.cpp b/noncore/games/chess/main.cpp
new file mode 100644
index 0000000..a56913f
--- a/dev/null
+++ b/noncore/games/chess/main.cpp
@@ -0,0 +1,51 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19** $Id$
20**
21**********************************************************************/
22#include <qpe/qpeapplication.h>
23#include <qpe/qpetoolbar.h>
24#include <qmainwindow.h>
25#include <qcanvas.h>
26#include "chess.h"
27
28
29class CanvasMainWindow : public QMainWindow {
30public:
31 CanvasMainWindow(QWidget* parent=0, const char* name=0, WFlags f=0)
32 : QMainWindow(parent,name,f), canvas(232, 258) {
33 view = new BoardView(&canvas, this, 0);
34 setToolBarsMovable( FALSE );
35 QPEToolBar* toolbar = new QPEToolBar(this);
36 toolbar->setHorizontalStretchable( TRUE );
37 }
38
39private:
40 QCanvas canvas;
41 BoardView *view;
42};
43
44
45int main( int argc, char **argv ) {
46 QPEApplication a(argc,argv);
47 CanvasMainWindow *mw = new CanvasMainWindow();
48 a.showMainWidget( mw );
49 return a.exec();
50}
51
diff --git a/noncore/games/chess/mainwindow.ui b/noncore/games/chess/mainwindow.ui
new file mode 100644
index 0000000..dc3ae0f
--- a/dev/null
+++ b/noncore/games/chess/mainwindow.ui
@@ -0,0 +1,220 @@
1<!DOCTYPE UI><UI version="3.0" stdsetdef="1">
2<class>MainWindow</class>
3<widget class="QMainWindow">
4 <property name="name">
5 <cstring>MainWindow</cstring>
6 </property>
7 <property name="geometry">
8 <rect>
9 <x>0</x>
10 <y>0</y>
11 <width>256</width>
12 <height>338</height>
13 </rect>
14 </property>
15 <property name="caption">
16 <string>Chess</string>
17 </property>
18 <widget class="QLabel">
19 <property name="name">
20 <cstring>TextLabel1</cstring>
21 </property>
22 <property name="geometry">
23 <rect>
24 <x>10</x>
25 <y>236</y>
26 <width>221</width>
27 <height>31</height>
28 </rect>
29 </property>
30 <property name="text">
31 <string>TextLabel1</string>
32 </property>
33 </widget>
34 <widget class="BoardView">
35 <property name="name">
36 <cstring>ChessBoard</cstring>
37 </property>
38 <property name="geometry">
39 <rect>
40 <x>10</x>
41 <y>10</y>
42 <width>224</width>
43 <height>224</height>
44 </rect>
45 </property>
46 <property name="sizePolicy">
47 <sizepolicy>
48 <hsizetype>1</hsizetype>
49 <vsizetype>1</vsizetype>
50 <horstretch>0</horstretch>
51 <verstretch>0</verstretch>
52 </sizepolicy>
53 </property>
54 <property name="minimumSize">
55 <size>
56 <width>224</width>
57 <height>224</height>
58 </size>
59 </property>
60 </widget>
61</widget>
62<menubar>
63 <property name="name">
64 <cstring>menubar</cstring>
65 </property>
66 <item text="Game" name="PopupMenu_2">
67 <action name="newGame"/>
68 <action name="annotateGame"/>
69 </item>
70 <item text="Position" name="PopupMenu_3">
71 <action name="swapSides"/>
72 <action name="undo"/>
73 </item>
74</menubar>
75<toolbars>
76</toolbars>
77<customwidgets>
78 <customwidget>
79 <class>BoardView</class>
80 <header location="global">/home/luke/depot/qpe/chess/chess.h</header>
81 <sizehint>
82 <width>-1</width>
83 <height>-1</height>
84 </sizehint>
85 <container>0</container>
86 <sizepolicy>
87 <hordata>5</hordata>
88 <verdata>5</verdata>
89 <horstretch>0</horstretch>
90 <verstretch>0</verstretch>
91 </sizepolicy>
92 <pixmap>image0</pixmap>
93 <signal>showMessage(const QString&amp;)</signal>
94 <slot access="public" specifier="">newGame()</slot>
95 <slot access="public" specifier="">swapSides()</slot>
96 <slot access="public" specifier="">setTheme(QString)</slot>
97 <slot access="public" specifier="">undo()</slot>
98 <slot access="public" specifier="">annotateGame()</slot>
99 </customwidget>
100</customwidgets>
101<actions>
102 <actiongroup>
103 <property name="name">
104 <cstring>gameActions</cstring>
105 </property>
106 <property name="text">
107 <string>ActionGroup</string>
108 </property>
109 <property name="usesDropDown">
110 <bool>false</bool>
111 </property>
112 <action>
113 <property name="name">
114 <cstring>newGame</cstring>
115 </property>
116 <property name="iconSet">
117 <iconset>new.png</iconset>
118 </property>
119 <property name="text">
120 <string>New Game</string>
121 </property>
122 <property name="menuText">
123 <string>New Game</string>
124 </property>
125 <property name="toolTip">
126 <string>New Game</string>
127 </property>
128 </action>
129 <action>
130 <property name="name">
131 <cstring>swapSides</cstring>
132 </property>
133 <property name="iconSet">
134 <iconset>repeat.png</iconset>
135 </property>
136 <property name="text">
137 <string>Swap sides</string>
138 </property>
139 <property name="toolTip">
140 <string>Swap sides</string>
141 </property>
142 </action>
143 <action>
144 <property name="name">
145 <cstring>annotateGame</cstring>
146 </property>
147 <property name="iconSet">
148 <iconset>txt.png</iconset>
149 </property>
150 <property name="text">
151 <string>Annotate game</string>
152 </property>
153 <property name="toolTip">
154 <string>Annotate game</string>
155 </property>
156 </action>
157 <action>
158 <property name="name">
159 <cstring>undo</cstring>
160 </property>
161 <property name="iconSet">
162 <iconset>back.png</iconset>
163 </property>
164 <property name="text">
165 <string>Undo move</string>
166 </property>
167 <property name="toolTip">
168 <string>Undo move</string>
169 </property>
170 </action>
171 <action>
172 <property name="name">
173 <cstring>saveGame</cstring>
174 </property>
175 <property name="text">
176 <string>Action</string>
177 </property>
178 </action>
179 </actiongroup>
180</actions>
181<images>
182 <image name="image0">
183 <data format="XPM.GZ" length="3456">789ce5d35d5313491406e07b7e458abea3b68e99cfccd4d65ee0079ac8a720a2d65ef474cf2424229004152dffbba7cf795941182a59bcd8aa6548524fbafb9d9ed3278fd63a47bb5b9db5472bb3b99d1fbb8e1bd96967cd5f9c9c5cbefffbaf6f2bab49dce1ff5eaf13affeb1b24aa6e33aa62b7f620fa7b01517ec423c850bb571b0c3f8bbe0a8db7591ae1fa9c3257e0aa7b0ac8f0ab6aeefc305bc073b783d38ee462ed6f5953a5ce20d38859f894b7629de820bb519c20ee3af829328764924be50275d7806a76a732c2ed9ba7e08176a33811d2cf548a3c4a59a97a9d3aedad4708af153b1655bf14bb880bfc00e3e0fcee2ac9be9f926629b65998eefc21e3e0acee3cce73affb33acfe037ff58e737629b97f026ece128b897e4be9788bfaa7b119cc319fc445cb12bf1215caa8d813d2cfd59243d5fe8faaeb82ab242d7d770097f803d2ce751a66554a6e28f70a636d24fa5633b191fc325fc1cf6f049b04d6d6435ef139cc16fc5ce5aabf3b7e11ade09ae525b573a7f5f5dc5f00bb1aff2ca8b07b0559b315c63fc20d86555ed32f15ced62f812ce61e95fe7d99a67610b3770ada65eb0e776f1bafe4c5cb36bf16bd8c245709dd7719d8b5371cddfc8b821d8aa290e6e78b4d1f9a5ba89e1c7e2a6b14d13bc37879b2bdf7f91b9fffadf65d8df90519123ffc08c9a1a1ad2a86d3ff767d0318d69421fe8843ed229a72c9d4167742ef79ed28ce69c7471f713b567d027beef675ea733bfd0257da5f5bb52da32e8313de18ca7f48c67add30657f539bde07df597c818d04bdae41a84593557654a5bb44d3bb44b7bbfeea53563c2ab467c1a61569f77123e5fd13e1d704a7533a535e3351dd21b3afa65dfeb9cf09677f86ec19a7679e64cea71f3daa788ebb45846cccf93dcaae1942bbb793be38e339ff2b34f28e5f7ab6f4e29e33a8c68f3f6dd5a320cdf29a7deb58c824aeeb31d434b64f48de1351b5736b6fd17d192e1a9321577d5cfe73e5c32c31ac79db16dfccf3e30f55219533e8b53634c73bd3bcc90e285332cf7f21177f51977d9f046775d2e9e6146fc8bbdabcab816c89872270f1e98e1f909c6b4c5cf7f71f5e2f7637e9fe9e742f5e8d3399feb3e0dcc9877744083f613693d174b23befbcc4ccc84b2f0fa1719d7d37c783d28a3b58affd18cef7faefc007d894af5</data>
184 </image>
185</images>
186<connections>
187 <connection>
188 <sender>newGame</sender>
189 <signal>activated()</signal>
190 <receiver>ChessBoard</receiver>
191 <slot>newGame()</slot>
192 </connection>
193 <connection>
194 <sender>swapSides</sender>
195 <signal>activated()</signal>
196 <receiver>ChessBoard</receiver>
197 <slot>swapSides()</slot>
198 </connection>
199 <connection>
200 <sender>annotateGame</sender>
201 <signal>activated()</signal>
202 <receiver>ChessBoard</receiver>
203 <slot>annotateGame()</slot>
204 </connection>
205 <connection>
206 <sender>undo</sender>
207 <signal>activated()</signal>
208 <receiver>ChessBoard</receiver>
209 <slot>undo()</slot>
210 </connection>
211 <connection>
212 <sender>ChessBoard</sender>
213 <signal>showMessage(const QString&amp;)</signal>
214 <receiver>TextLabel1</receiver>
215 <slot>setText(const QString&amp;)</slot>
216 </connection>
217</connections>
218<pixmapinproject/>
219<layoutdefaults spacing="6" margin="11"/>
220</UI>
diff --git a/noncore/games/chess/pieces.png b/noncore/games/chess/pieces.png
new file mode 100644
index 0000000..4baeb4a
--- a/dev/null
+++ b/noncore/games/chess/pieces.png
Binary files differ
diff --git a/noncore/games/chess/qpe-chess.control b/noncore/games/chess/qpe-chess.control
new file mode 100644
index 0000000..2a7d2d2
--- a/dev/null
+++ b/noncore/games/chess/qpe-chess.control
@@ -0,0 +1,9 @@
1Files: bin/chess apps/Games/chess.desktop
2Priority: optional
3Section: qpe/games
4Maintainer: Luke Graham <luke@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Crafty GUI
9 A GUI for the crafty chess engine
diff --git a/noncore/games/chess/simple-l.png b/noncore/games/chess/simple-l.png
new file mode 100644
index 0000000..908e2e1
--- a/dev/null
+++ b/noncore/games/chess/simple-l.png
Binary files differ
diff --git a/noncore/games/fifteen/.cvsignore b/noncore/games/fifteen/.cvsignore
new file mode 100644
index 0000000..6fe2396
--- a/dev/null
+++ b/noncore/games/fifteen/.cvsignore
@@ -0,0 +1,2 @@
1moc_*
2Makefile
diff --git a/noncore/games/fifteen/Makefile.in b/noncore/games/fifteen/Makefile.in
new file mode 100644
index 0000000..23c7334
--- a/dev/null
+++ b/noncore/games/fifteen/Makefile.in
@@ -0,0 +1,118 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= fifteen
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =fifteen.h
27 SOURCES =fifteen.cpp \
28 main.cpp
29 OBJECTS =fifteen.o \
30 main.o
31INTERFACES =
32UICDECLS =
33UICIMPLS =
34 SRCMOC =moc_fifteen.cpp
35 OBJMOC =moc_fifteen.o
36
37
38####### Implicit rules
39
40.SUFFIXES: .cpp .cxx .cc .C .c
41
42.cpp.o:
43 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
44
45.cxx.o:
46 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
47
48.cc.o:
49 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
50
51.C.o:
52 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
53
54.c.o:
55 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
56
57####### Build rules
58
59
60all: $(DESTDIR)$(TARGET)
61
62$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
63 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
64
65moc: $(SRCMOC)
66
67tmake:
68 tmake fifteen.pro
69
70clean:
71 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
72 -rm -f *~ core
73 -rm -f allmoc.cpp
74
75####### Extension Modules
76
77listpromodules:
78 @echo
79
80listallmodules:
81 @echo
82
83listaddonpromodules:
84 @echo
85
86listaddonentmodules:
87 @echo
88
89
90REQUIRES=
91
92####### Sub-libraries
93
94
95###### Combined headers
96
97
98
99####### Compile
100
101fifteen.o: fifteen.cpp \
102 fifteen.h \
103 $(QPEDIR)/include/qpe/resource.h \
104 $(QPEDIR)/include/qpe/config.h \
105 $(QPEDIR)/include/qpe/qpetoolbar.h \
106 $(QPEDIR)/include/qpe/qpemenubar.h
107
108main.o: main.cpp \
109 fifteen.h \
110 $(QPEDIR)/include/qpe/qpeapplication.h
111
112moc_fifteen.o: moc_fifteen.cpp \
113 fifteen.h
114
115moc_fifteen.cpp: fifteen.h
116 $(MOC) fifteen.h -o moc_fifteen.cpp
117
118
diff --git a/noncore/games/fifteen/fifteen.cpp b/noncore/games/fifteen/fifteen.cpp
new file mode 100644
index 0000000..293cd65
--- a/dev/null
+++ b/noncore/games/fifteen/fifteen.cpp
@@ -0,0 +1,364 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "fifteen.h"
22
23#include <qpe/resource.h>
24#include <qpe/config.h>
25
26#include <qvbox.h>
27#include <qaction.h>
28#include <qlayout.h>
29#include <qpainter.h>
30#include <qpopupmenu.h>
31#include <qmessagebox.h>
32#include <qpe/qpetoolbar.h>
33#include <qpe/qpemenubar.h>
34#include <qstringlist.h>
35#include <qapplication.h>
36
37#include <stdlib.h>
38#include <time.h>
39
40FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name)
41 : QMainWindow( parent, name )
42{
43 // random seed
44 srand(time(0));
45
46 setToolBarsMovable( FALSE );
47 QVBox *vbox = new QVBox( this );
48 PiecesTable *table = new PiecesTable( vbox );
49 setCentralWidget(vbox);
50
51 QPEToolBar *toolbar = new QPEToolBar(this);
52 toolbar->setHorizontalStretchable( TRUE );
53 addToolBar(toolbar);
54
55 QPEMenuBar *menubar = new QPEMenuBar( toolbar );
56 menubar->setMargin(0);
57
58 QPopupMenu *game = new QPopupMenu( this );
59
60 QWidget *spacer = new QWidget( toolbar );
61 spacer->setBackgroundMode( PaletteButton );
62 toolbar->setStretchableWidget( spacer );
63
64 QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ),
65 QString::null, 0, this, 0 );
66 connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) );
67 a->addTo( game );
68 a->addTo( toolbar );
69
70 a = new QAction( tr( "Solve" ), Resource::loadPixmap( "repeat" ),
71 QString::null, 0, this, 0 );
72 connect( a, SIGNAL( activated() ), table, SLOT( slotReset() ) );
73 a->addTo( game );
74 a->addTo( toolbar );
75
76 menubar->insertItem( tr( "Game" ), game );
77}
78
79PiecesTable::PiecesTable(QWidget* parent, const char* name )
80 : QTableView(parent, name), _menu(0), _randomized(false)
81{
82 // setup table view
83 setFrameStyle(StyledPanel | Sunken);
84 setBackgroundMode(NoBackground);
85 setMouseTracking(true);
86
87 setNumRows(4);
88 setNumCols(4);
89
90 // init arrays
91 initMap();
92 readConfig();
93 initColors();
94
95 // set font
96 QFont f = font();
97 f.setPixelSize(18);
98 f.setBold( TRUE );
99 setFont(f);
100}
101
102PiecesTable::~PiecesTable()
103{
104 writeConfig();
105}
106
107void PiecesTable::writeConfig()
108{
109 Config cfg("Fifteen");
110 cfg.setGroup("Game");
111 QStringList map;
112 for (unsigned int i = 0; i < 16; i++)
113 map.append( QString::number( _map[i] ) );
114 cfg.writeEntry("Map", map, '-');
115 cfg.writeEntry("Randomized", _randomized );
116}
117
118void PiecesTable::readConfig()
119{
120 Config cfg("Fifteen");
121 cfg.setGroup("Game");
122 QStringList map = cfg.readListEntry("Map", '-');
123 _randomized = cfg.readBoolEntry( "Randomized", FALSE );
124 unsigned int i = 0;
125 for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) {
126 _map[i] = (*it).toInt();
127 i++;
128 if ( i > 15 ) break;
129 }
130}
131
132void PiecesTable::paintCell(QPainter *p, int row, int col)
133{
134 int w = cellWidth();
135 int h = cellHeight();
136 int x2 = w - 1;
137 int y2 = h - 1;
138
139 int number = _map[col + row * numCols()] + 1;
140
141 // draw cell background
142 if(number == 16)
143 p->setBrush(colorGroup().background());
144 else
145 p->setBrush(_colors[number-1]);
146 p->setPen(NoPen);
147 p->drawRect(0, 0, w, h);
148
149 // draw borders
150 if (height() > 40) {
151 p->setPen(colorGroup().text());
152 if(col < numCols()-1)
153 p->drawLine(x2, 0, x2, y2); // right border line
154
155 if(row < numRows()-1)
156 p->drawLine(0, y2, x2, y2); // bottom boder line
157 }
158
159 // draw number
160 if (number == 16) return;
161 p->setPen(black);
162 p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(number));
163}
164
165void PiecesTable::resizeEvent(QResizeEvent *e)
166{
167 QTableView::resizeEvent(e);
168
169 setCellWidth(contentsRect().width()/ numRows());
170 setCellHeight(contentsRect().height() / numCols());
171}
172
173void PiecesTable::initColors()
174{
175 _colors.resize(numRows() * numCols());
176 for (int r = 0; r < numRows(); r++)
177 for (int c = 0; c < numCols(); c++)
178 _colors[c + r *numCols()] = QColor(255 - 70 * c,255 - 70 * r, 150);
179}
180
181void PiecesTable::initMap()
182{
183 _map.resize(16);
184 for (unsigned int i = 0; i < 16; i++)
185 _map[i] = i;
186
187 _randomized = false;
188}
189
190void PiecesTable::randomizeMap()
191{
192 initMap();
193 _randomized = true;
194 // find the free position
195 int pos = _map.find(15);
196
197 int move = 0;
198 while ( move < 333 ) {
199
200 int frow = pos / numCols();
201 int fcol = pos - frow * numCols();
202
203 // find click position
204 int row = rand()%4;
205 int col = rand()%4;
206
207 // sanity check
208 if ( row < 0 || row >= numRows() ) continue;
209 if ( col < 0 || col >= numCols() ) continue;
210 if ( row != frow && col != fcol ) continue;
211
212 move++;
213
214 // rows match -> shift pieces
215 if(row == frow) {
216
217 if (col < fcol) {
218 for(int c = fcol; c > col; c--) {
219 _map[c + row * numCols()] = _map[ c-1 + row *numCols()];
220 }
221 }
222 else if (col > fcol) {
223 for(int c = fcol; c < col; c++) {
224 _map[c + row * numCols()] = _map[ c+1 + row *numCols()];
225 }
226 }
227 }
228 // cols match -> shift pieces
229 else if (col == fcol) {
230
231 if (row < frow) {
232 for(int r = frow; r > row; r--) {
233 _map[col + r * numCols()] = _map[ col + (r-1) *numCols()];
234 }
235 }
236 else if (row > frow) {
237 for(int r = frow; r < row; r++) {
238 _map[col + r * numCols()] = _map[ col + (r+1) *numCols()];
239 }
240 }
241 }
242 // move free cell to click position
243 _map[pos=(col + row * numCols())] = 15;
244 repaint();
245 }
246}
247
248void PiecesTable::checkwin()
249{
250 if(!_randomized) return;
251
252 int i;
253 for (i = 0; i < 16; i++)
254 if(i != _map[i])
255 break;
256
257 if (i == 16) {
258 QMessageBox::information(this, tr("Fifteen Pieces"),
259 tr("Congratulations!\nYou win the game!"));
260 _randomized = FALSE;
261 }
262
263}
264
265void PiecesTable::slotRandomize()
266{
267 randomizeMap();
268}
269
270void PiecesTable::slotReset()
271{
272 initMap();
273 repaint();
274}
275
276void PiecesTable::mousePressEvent(QMouseEvent* e)
277{
278 QTableView::mousePressEvent(e);
279
280 if (e->button() == RightButton) {
281
282 // setup RMB pupup menu
283 if(!_menu) {
284 _menu = new QPopupMenu(this);
285 _menu->insertItem(tr("R&andomize Pieces"), mRandomize);
286 _menu->insertItem(tr("&Reset Pieces"), mReset);
287 _menu->adjustSize();
288 }
289
290 // execute RMB popup and check result
291 switch(_menu->exec(mapToGlobal(e->pos()))) {
292 case mRandomize:
293 randomizeMap();
294 break;
295 case mReset:
296 initMap();
297 repaint();
298 break;
299 default:
300 break;
301 }
302 }
303 else {
304 // GAME LOGIC
305
306 // find the free position
307 int pos = _map.find(15);
308 if(pos < 0) return;
309
310 int frow = pos / numCols();
311 int fcol = pos - frow * numCols();
312
313 // find click position
314 int row = findRow(e->y());
315 int col = findCol(e->x());
316
317 // sanity check
318 if (row < 0 || row >= numRows()) return;
319 if (col < 0 || col >= numCols()) return;
320 if ( row != frow && col != fcol ) return;
321
322 // valid move?
323 if(row != frow && col != fcol) return;
324
325 // rows match -> shift pieces
326 if(row == frow) {
327
328 if (col < fcol) {
329 for(int c = fcol; c > col; c--) {
330 _map[c + row * numCols()] = _map[ c-1 + row *numCols()];
331 updateCell(row, c, false);
332 }
333 }
334 else if (col > fcol) {
335 for(int c = fcol; c < col; c++) {
336 _map[c + row * numCols()] = _map[ c+1 + row *numCols()];
337 updateCell(row, c, false);
338 }
339 }
340 }
341 // cols match -> shift pieces
342 else if (col == fcol) {
343
344 if (row < frow) {
345 for(int r = frow; r > row; r--) {
346 _map[col + r * numCols()] = _map[ col + (r-1) *numCols()];
347 updateCell(r, col, false);
348 }
349 }
350 else if (row > frow) {
351 for(int r = frow; r < row; r++) {
352 _map[col + r * numCols()] = _map[ col + (r+1) *numCols()];
353 updateCell(r, col, false);
354 }
355 }
356 }
357 // move free cell to click position
358 _map[col + row * numCols()] = 15;
359 updateCell(row, col, false);
360
361 // check if the player wins with this move
362 checkwin();
363 }
364}
diff --git a/noncore/games/fifteen/fifteen.h b/noncore/games/fifteen/fifteen.h
new file mode 100644
index 0000000..703a8a7
--- a/dev/null
+++ b/noncore/games/fifteen/fifteen.h
@@ -0,0 +1,83 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef __fifteenapplet_h__
22#define __fifteenapplet_h__
23
24#include <qmainwindow.h>
25#include <qtableview.h>
26#include <qarray.h>
27
28class QPopupMenu;
29
30class PiecesTable : public QTableView
31{
32 Q_OBJECT
33
34 public:
35 PiecesTable(QWidget* parent = 0, const char* name = 0);
36 ~PiecesTable();
37
38 protected slots:
39 void slotRandomize();
40 void slotReset();
41
42 protected:
43 void resizeEvent(QResizeEvent*);
44 void mousePressEvent(QMouseEvent*);
45
46 void paintCell(QPainter *, int row, int col);
47
48 void initMap();
49 void initColors();
50 void randomizeMap();
51 void checkwin();
52 void readConfig();
53 void writeConfig();
54
55 private:
56 QArray<int> _map;
57 QArray<QColor> _colors;
58 QPopupMenu *_menu;
59 bool _randomized;
60
61 enum MenuOp { mRandomize = 1, mReset = 2 };
62};
63
64class FifteenWidget : public QWidget
65{
66 Q_OBJECT
67
68public:
69 FifteenWidget(QWidget *parent = 0, const char *name = 0);
70
71private:
72 PiecesTable *_table;
73};
74
75class FifteenMainWindow : public QMainWindow
76{
77 Q_OBJECT
78
79public:
80 FifteenMainWindow(QWidget *parent=0, const char* name=0);
81};
82
83#endif
diff --git a/noncore/games/fifteen/fifteen.pro b/noncore/games/fifteen/fifteen.pro
new file mode 100644
index 0000000..167f4f8
--- a/dev/null
+++ b/noncore/games/fifteen/fifteen.pro
@@ -0,0 +1,10 @@
1 DESTDIR = ../bin
2 TEMPLATE= app
3 CONFIG = qt warn_on release
4 HEADERS = fifteen.h
5 SOURCES = fifteen.cpp \
6 main.cpp
7INCLUDEPATH += $(QPEDIR)/include
8 DEPENDPATH+= $(QPEDIR)/include
9LIBS += -lqpe
10 TARGET = fifteen
diff --git a/noncore/games/fifteen/main.cpp b/noncore/games/fifteen/main.cpp
new file mode 100644
index 0000000..4838a36
--- a/dev/null
+++ b/noncore/games/fifteen/main.cpp
@@ -0,0 +1,33 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "fifteen.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char ** argv)
26{
27 QPEApplication app( argc, argv );
28
29 FifteenMainWindow mw;
30 mw.setCaption( FifteenMainWindow::tr("Fifteen Pieces") );
31 app.showMainWidget( &mw );
32 return app.exec();
33}
diff --git a/noncore/games/fifteen/qpe-fifteen.control b/noncore/games/fifteen/qpe-fifteen.control
new file mode 100644
index 0000000..d77eb32
--- a/dev/null
+++ b/noncore/games/fifteen/qpe-fifteen.control
@@ -0,0 +1,11 @@
1Files: bin/fifteen apps/Games/fifteen.desktop pics/Fifteen.png
2Priority: optional
3Section: qpe/games
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Arch: iPAQ
7Version: $QPE_VERSION-4
8Depends: qpe-base ($QPE_VERSION)
9Description: Fifteen pieces game
10 A game for the Qtopia environment
11.
diff --git a/noncore/games/go/.cvsignore b/noncore/games/go/.cvsignore
new file mode 100644
index 0000000..6fe2396
--- a/dev/null
+++ b/noncore/games/go/.cvsignore
@@ -0,0 +1,2 @@
1moc_*
2Makefile
diff --git a/noncore/games/go/Makefile.in b/noncore/games/go/Makefile.in
new file mode 100644
index 0000000..27304f1
--- a/dev/null
+++ b/noncore/games/go/Makefile.in
@@ -0,0 +1,158 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= go
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =amigo.h \
27 go.h \
28 goplayutils.h \
29 gowidget.h
30 SOURCES =amigo.c \
31 goplayer.c \
32 goplayutils.c \
33 killable.c \
34 gowidget.cpp \
35 main.cpp
36 OBJECTS =amigo.o \
37 goplayer.o \
38 goplayutils.o \
39 killable.o \
40 gowidget.o \
41 main.o
42INTERFACES =
43UICDECLS =
44UICIMPLS =
45 SRCMOC =moc_gowidget.cpp
46 OBJMOC =moc_gowidget.o
47
48
49####### Implicit rules
50
51.SUFFIXES: .cpp .cxx .cc .C .c
52
53.cpp.o:
54 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
55
56.cxx.o:
57 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
58
59.cc.o:
60 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
61
62.C.o:
63 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
64
65.c.o:
66 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
67
68####### Build rules
69
70
71all: $(DESTDIR)$(TARGET)
72
73$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
74 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
75
76moc: $(SRCMOC)
77
78tmake:
79 tmake go.pro
80
81clean:
82 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
83 -rm -f *~ core
84 -rm -f allmoc.cpp
85
86####### Extension Modules
87
88listpromodules:
89 @echo
90
91listallmodules:
92 @echo
93
94listaddonpromodules:
95 @echo
96
97listaddonentmodules:
98 @echo
99
100
101REQUIRES=
102
103####### Sub-libraries
104
105
106###### Combined headers
107
108
109
110####### Compile
111
112amigo.o: amigo.c \
113 go.h \
114 goplayutils.h \
115 amigo.h
116
117goplayer.o: goplayer.c \
118 go.h \
119 goplayutils.h \
120 amigo.h
121
122goplayutils.o: goplayutils.c \
123 goplayutils.h \
124 amigo.h \
125 go.h
126
127killable.o: killable.c \
128 go.h \
129 goplayutils.h \
130 amigo.h
131
132gowidget.o: gowidget.cpp \
133 gowidget.h \
134 amigo.h \
135 go.h \
136 goplayutils.h \
137 $(QPEDIR)/include/qpe/config.h \
138 $(QPEDIR)/include/qpe/resource.h \
139 $(QPEDIR)/include/qpe/qpetoolbar.h \
140 $(QPEDIR)/include/qpe/qpemenubar.h
141
142main.o: main.cpp \
143 gowidget.h \
144 amigo.h \
145 go.h \
146 goplayutils.h \
147 $(QPEDIR)/include/qpe/qpeapplication.h
148
149moc_gowidget.o: moc_gowidget.cpp \
150 gowidget.h \
151 amigo.h \
152 go.h \
153 goplayutils.h
154
155moc_gowidget.cpp: gowidget.h
156 $(MOC) gowidget.h -o moc_gowidget.cpp
157
158
diff --git a/noncore/games/go/README b/noncore/games/go/README
new file mode 100644
index 0000000..c6fa1f5
--- a/dev/null
+++ b/noncore/games/go/README
@@ -0,0 +1,3 @@
1This Go player For Qtopia is based on Xamigo, which in turn was
2based on Amigo. The original README files are included as README.XAMIGO
3and README.AMIGO.
diff --git a/noncore/games/go/README.AMIGO b/noncore/games/go/README.AMIGO
new file mode 100644
index 0000000..03978e7
--- a/dev/null
+++ b/noncore/games/go/README.AMIGO
@@ -0,0 +1,42 @@
1 This is version 1.0 of AmiGo --- a Go board and player for the Amiga.
2The Amiga interface and board manager were written by Todd R. Johnson.
3The player is a C port of a Pascal player written by Stoney Ballard.
4The interface allows you to play human vs. human, human vs. Amiga, or
5Amiga vs. Amiga.
6
7 The board manager and player could both use some work. Currently,
8you cannot save/load games, take back a move, or automatically score a
9game. It is also limited to a 19 by 19 board. I'm releasing AmiGo
10now because 1) I'm in the final phases of my dissertation and probably
11won't have much time to do any further work on AmiGo, and 2) a lot of
12people have been asking for an Amiga Go player. I am also releasing
13all of the source code so that others can add to and modify AmiGo.
14Note that all of my code in this release is public domain, while the
15ported go player retains the original copyright.
16
17 If you distribute AmiGo, I urge you to include the source
18code. If anyone makes changes, I would appreciate a copy. In fact, I
19am willing to act as a clearinghouse for AmiGo changes.
20
21Todd R. Johnson
22tj@cis.ohio-state.edu
238/8/89
24
25Here is the message attached to the original USENET posting of Stoney
26Ballard's Pascal code. Note that the board manager mentioned here is
27not included in this distribution.
28
29This go board manager and rudimentary go player was written by
30Stoney Ballard at Perq Systems in 1983-1984. It is written in
31Perq Pascal and utilizes some Perq libraries for I/O. The code
32is offered here if someone is interested to convert it to Unix.
33
34The wonderful part about it is that a game is recorded as a tree
35and can be played forward or backward, branching at any point
36where there were alternate moves.
37
38For some time, this program was also used to generate the go
39boards displayed in the American Go Journal. For this it used
40some large font digits which are now lost.
41
42Fred Hansen
diff --git a/noncore/games/go/README.XAMIGO b/noncore/games/go/README.XAMIGO
new file mode 100644
index 0000000..219b25f
--- a/dev/null
+++ b/noncore/games/go/README.XAMIGO
@@ -0,0 +1,26 @@
1
2 Xamigo 1.1
3
4This is an alpha release of xamigo --- a port (read: quick hack) of the
5Amiga Go program AmiGo. I don't have time to get it real nice now,
6but will spend some more time on it when my thesis is out of the way.
7Sadly this is the second time I've said that :-)
8
9The `readme' from the original distribution is included as README.AMIGO
10
11An Imakefile is included, so you should be able to type
12 xmkmf
13 make
14to build xamigo. Let me know if you have problems with the Imakefile,
15preferably with fixes :-)
16
17You *have* to install the app-defaults file (Xamigo.ad) before you use
18xamigo. This should either go in /usr/lib/X11/app-defaults,
19or in your own app-defaults directory, as file Xamigo (ie lose the '.ad')
20If you do the latter, you have to:
21 setenv XAPPLRESDIR <full path of your app-defaults directory>
22
23Feel free to mail me any comments and suggestions for improvements.
24
25Neil
26neilb@scs.leeds.ac.uk
diff --git a/noncore/games/go/amigo.c b/noncore/games/go/amigo.c
new file mode 100644
index 0000000..cd61013
--- a/dev/null
+++ b/noncore/games/go/amigo.c
@@ -0,0 +1,656 @@
1/* Go started 4/17/88 by Todd R. Johnson */
2/* 8/8/89 cleaned up for first release */
3/* Public Domain */
4
5#include "go.h"
6#include "goplayutils.h"
7#include "amigo.h"
8
9
10 extern char*playReason;
11 extern shortplayLevel, showTrees;
12
13 struct bRec goboard[19][19]; /*-- The main go board --*/
14
15 struct Group GroupList[MAXGROUPS]; /*-- The list of Groups --*/
16 short DeletedGroups[4]; /*-- Codes of deleted groups--*/
17
18 short GroupCount = 0; /*-- The total number of groups--*/
19 short DeletedGroupCount; /*-- The total number of groups--*/
20 /*-- deleted on a move --*/
21 short ko, koX, koY;
22 short blackTerritory,whiteTerritory;
23 short blackPrisoners, whitePrisoners;
24 short showMoveReason= FALSE,
25 groupInfo= FALSE,
26 whitePassed= FALSE,
27 blackPassed= FALSE;
28
29
30/* Arrays for use when checking around a point */
31 short xVec[4] = {0, 1, 0, -1};
32 short yVec[4] = {-1, 0, 1, 0};
33
34short
35member(group, grouplist, cnt)
36 short group;
37 short grouplist[4];
38 short cnt;
39{
40 unsigned shorti;
41
42
43 for (i = 0; i < cnt; i++)
44 if (grouplist[i] == group)
45 return TRUE;
46 return FALSE;
47}
48
49/* Does a stone at x, y connect to any groups of color? */
50short
51Connect( color, x, y, fGroups, fCnt, eGroups, eCnt)
52 enum bValcolor;
53 short x, y;
54 short fGroups[4], eGroups[4];
55 short *fCnt, *eCnt;
56{
57 unsigned shortpoint = 0;
58 short tx, ty, total = 0;
59 enum bValopcolor = WHITE;
60
61
62 *fCnt = 0;
63 *eCnt = 0;
64 if (color == WHITE)
65 opcolor = BLACK;
66 for (point = 0; point <= 3; point++ )
67 {
68 tx = x + xVec[point];
69 ty = y + yVec[point];
70 if (!LegalPoint(tx,ty))
71 continue;
72 if (goboard[tx][ty].Val == color)
73 {
74 total++;
75 if (!member(goboard[tx][ty].GroupNum, fGroups, *fCnt))
76 fGroups[(*fCnt)++] = goboard[tx][ty].GroupNum;
77 }
78 else if (goboard[tx][ty].Val == opcolor)
79 {
80 total++;
81 if (!member(goboard[tx][ty].GroupNum, eGroups, *eCnt))
82 eGroups[(*eCnt)++] = goboard[tx][ty].GroupNum;
83 }
84 }
85 return total;
86}
87
88/* Returns the maximum number of liberties for a given intersection */
89short
90Maxlibs(x, y)
91 shortx, y;
92{
93 shortcnt = 4;
94
95
96 if (x == 0 || x == 18)
97 cnt--;
98 if (y == 0 || y == 18)
99 cnt--;
100 return cnt;
101}
102
103DeleteGroupFromStone(x,y)
104 shortx,y;
105{
106 if (goboard[x][y].Val != EMPTY)
107 GroupCapture(goboard[x][y].GroupNum);
108}
109
110/* Determine whether x, y is suicide for color */
111short
112Suicide(color, x, y)
113 enum bValcolor;
114 short x, y;
115{
116 enum bValopcolor = BLACK;
117 short friendlycnt, friendlygroups[4],
118 enemycnt, enemygroups[4],
119 total;
120 short maxlibs, i, libcnt = 0;
121
122
123 if (color == BLACK)
124 opcolor = WHITE;
125 maxlibs = Maxlibs( x, y);
126 total = Connect(color, x, y, friendlygroups, &friendlycnt,
127 enemygroups, &enemycnt);
128
129 if (total < maxlibs)
130 return FALSE;
131
132 /* Check for a capture */
133 for (i = 0; i < enemycnt; i++)
134 if (GroupList[enemygroups[i]].liberties == 1)
135 return FALSE;
136 for (i = 0; i < friendlycnt; i++)
137 libcnt += (GroupList[friendlygroups[i]].liberties - 1);
138 if (libcnt != 0)
139 return FALSE;
140 return TRUE;
141}
142
143/* Returns the number of liberties for x, y */
144short
145StoneLibs(x, y)
146 short x, y;
147{
148 short cnt = 0, tx, ty;
149 unsigned shortpoint;
150
151
152 for (point = 0; point <= 3; point++)
153 {
154 tx = x + xVec[point];
155 ty = y + yVec[point];
156 if (LegalPoint(tx,ty) && goboard[tx][ty].Val == EMPTY)
157 cnt++;
158 }
159 return cnt;
160}
161
162void
163EraseMarks()
164{
165 register short i;
166 register struct bRec *gpt= &goboard[0][0];
167
168
169 for (i=0; i<361; gpt++,i++)
170 gpt->marked = FALSE;
171}
172
173/* Place a stone of color at x, y */
174short
175GoPlaceStone(color, x, y)
176 enum bValcolor;
177 short x, y;
178{
179 short fgroups[4], egroups[4];/* group codes surrounding stone */
180 shortfcnt, ecnt, i;
181 shortlowest = GroupCount + 1;
182
183
184 DeletedGroupCount = 0;
185 if (goboard[x][y].Val != EMPTY || Suicide(color,x,y))
186 return FALSE;
187
188 if (ko && koX == x && koY == y)
189 return FALSE;
190
191 ko = FALSE;
192 placestone(color, x, y);
193 goboard[x][y].Val = color;
194 /* Does the new stone connect to any friendly stone(s)? */
195 Connect(color, x, y, fgroups, &fcnt, egroups, &ecnt);
196 if (fcnt)
197 {
198 /* Find the connecting friendly group with the lowest code */
199 for (i = 0; i < fcnt; i++)
200 if (fgroups[i] <= lowest)
201 lowest = fgroups[i];
202 /*-- Renumber resulting group --*/
203 /*-- Raise the stone count of the lowest by one to account --*/
204 /*-- for new stone --*/
205 goboard[x][y].GroupNum = lowest;
206 GroupList[lowest].count++;
207 for (i = 0; i < fcnt; i++)
208 if (fgroups[i] != lowest)
209 MergeGroups(lowest, fgroups[i]);
210 /* Fix the liberties of the resulting group */
211 CountLiberties(lowest);
212 }
213 else
214 {
215 /* Isolated stone. Create new group. */
216 GroupCount++;
217 lowest = GroupCount;
218 GroupList[lowest].color = color;
219 GroupList[lowest].count = 1;
220 GroupList[lowest].internal = 0;
221 GroupList[lowest].external = StoneLibs( x, y);
222 GroupList[lowest].liberties = GroupList[lowest].external;
223 GroupList[lowest].eyes = 0;
224 GroupList[lowest].alive = 0;
225 GroupList[lowest].territory = 0;
226 goboard[x][y].GroupNum = lowest;
227 }
228 /* Now fix the liberties of enemy groups adjacent to played stone */
229 FixLibs(color, x, y, PLACED); /* Fix the liberties of opcolor */
230 ReEvalGroups(color, x, y, lowest);
231 RelabelGroups();
232 return TRUE;
233}
234
235/* Remove a stone from the board */
236void
237GoRemoveStone(x, y)
238 shortx, y;
239{
240 goboard[x][y].Val = EMPTY;
241 goboard[x][y].GroupNum = 0;
242 removestone( x, y);
243}
244
245/* Merges two groups -- Renumbers stones and deletes second group from
246list. Fixes stone count of groups. This does not fix anything else.
247FixLibs must be called to fix liberties, etc. */
248void
249MergeGroups(g1, g2)
250 shortg1, g2;
251{
252 shortx, y;
253
254
255 ForeachPoint(y,x)
256 if (goboard[x][y].GroupNum == g2)
257 goboard[x][y].GroupNum = g1;
258 GroupList[g1].count += GroupList[g2].count;
259 DeleteGroup( g2 ); /* Removes group from GroupList */
260}
261
262/* Stores a group code to be deleted */
263void
264DeleteGroup(code)
265 shortcode;
266{
267 DeletedGroups[DeletedGroupCount++] = code;
268}
269
270/* Re-evaluate the groups given the last move. This assumes that the
271last move has been merged into adjoining groups and all liberty counts
272are correct. Handles capture. Checks for Ko. Keeps track of captured
273stones. code is the group number of the stone just played. */
274void
275ReEvalGroups(color, x, y, code)
276 enum bValcolor;
277 short x, y, code;
278{
279 short fgroups[4], egroups[4],
280 fcnt, ecnt, i, killcnt = 0, count = 0;
281 enum bValopcolor = BLACK;
282
283 if (color == BLACK)
284 opcolor = WHITE;
285 /* Check for capture */
286 Connect( color, x, y, fgroups, &fcnt, egroups, &ecnt);
287 if (ecnt)
288 {
289 /* See if any of the groups have no liberties */
290 for (i = 0; i < ecnt; i++)
291 if (GroupList[egroups[i]].liberties == 0)
292 {
293 killcnt++;
294 count = GroupList[egroups[i]].count;
295 GroupCapture( egroups[i]);
296 }
297 }
298 /* Check for ko. koX and koY are set in GroupCapture above. */
299 if (killcnt == 1 && count == 1 && GroupList[ code ].count == 1
300 && GroupList[ code ].liberties == 1)
301 {
302 ko = TRUE;
303 }
304 if (killcnt)
305 intrPrisonerReport( blackPrisoners, whitePrisoners);
306 /* Set eye count for groups */
307 CountEyes();
308}
309
310/* Remove a captured group from the board and fix the liberties of any
311 adjacent groups. Fixes prisoner count. Sets KoX and KoY */
312/*-- update display of captured stones -neilb --*/
313void
314GroupCapture(code)
315 shortcode;
316{
317 shortx, y;
318
319 if (GroupList[code].color == BLACK)
320 blackPrisoners += GroupList[code].count;
321 else
322 whitePrisoners += GroupList[code].count;
323 intrPrisonerReport(blackPrisoners, whitePrisoners);
324 ForeachPoint(y,x)
325 if (goboard[x][y].GroupNum == code)
326 {
327 FixLibs(GroupList[code].color,x,y,REMOVED);
328 GoRemoveStone(x, y);
329 koX = x;
330 koY = y;
331 }
332 DeleteGroup( code);
333}
334
335/* Fix the liberties of groups adjacent to x, y. move indicates
336 whether a stone of color was placed or removed at x, y
337 This does not change liberty counts of friendly groups when a stone
338 is placed. Does not do captures. */
339void
340FixLibs( color, x, y, move)
341 enumbVal color;
342 shortx, y, move;
343{
344 shortfgroups[4], fcnt, egroups[4], ecnt, i;
345 enumbVal opcolor = BLACK;
346
347 if (color == BLACK)
348 opcolor = WHITE;
349 Connect( color, x, y, fgroups, &fcnt, egroups, &ecnt);
350 if (move == PLACED)
351 for (i = 0; i < ecnt; i++)
352 GroupList[egroups[i]].liberties--;
353 else /* Stone removed so increment opcolor */
354 for (i = 0; i < ecnt; i++)
355 GroupList[egroups[i]].liberties++;
356}
357
358void
359goSetHandicap(handicap)
360 int handicap;
361{
362 if (handicap < 2)
363 return;
364
365 GoPlaceStone(BLACK,3,3);
366 GoPlaceStone(BLACK,15,15);
367
368 if (handicap >= 3)
369 GoPlaceStone(BLACK,15,3);
370 if (handicap >= 4)
371 GoPlaceStone(BLACK,3,15);
372 if (handicap == 5 || handicap == 7 || handicap == 9)
373 GoPlaceStone(BLACK,9,9);
374 if (handicap >= 6)
375 {
376 GoPlaceStone(BLACK,15,9);
377 GoPlaceStone(BLACK,3,9);
378 }
379 if (handicap >= 8)
380 {
381 GoPlaceStone(BLACK,9,15);
382 GoPlaceStone(BLACK,9,3);
383 }
384}
385
386void
387goRestart(handicap)
388 inthandicap;
389{
390 register short i;
391 register struct bRec *gpt= &goboard[0][0];
392
393
394 GroupCount = 0;
395 ko = FALSE;
396 blackPrisoners = whitePrisoners = 0;
397 intrPrisonerReport(0, 0);
398 for (i=0; i<361; gpt++,i++)
399 {
400 gpt->Val = EMPTY;
401 gpt->GroupNum = 0;
402 }
403 goSetHandicap(handicap);
404}
405
406
407/* if any groups have been deleted as a result of the last move, this
408 routine will delete the old group numbers from GroupList and
409 reassign group numbers. */
410void
411RelabelGroups()
412{
413 unsignedshort i, j, x, y;
414
415 for (i = 0; i < DeletedGroupCount; i++)
416 {
417 /* Relabel all higher groups */
418 ForeachPoint(y,x)
419 if (goboard[x][y].GroupNum > DeletedGroups[i])
420 goboard[x][y].GroupNum--;
421 /* Move the groups down */
422 for (y = DeletedGroups[i]; y < GroupCount; y++)
423 GroupList[y] = GroupList[y+1];
424 /* fix the group numbers stored in the deleted list */
425 for (j = i+1; j < DeletedGroupCount; j++)
426 if (DeletedGroups[j] > DeletedGroups[i])
427 DeletedGroups[j]--;
428 GroupCount--;
429 }
430}
431
432/* Returns liberty count for x, y intersection. Sets marked to true
433 for each liberty */
434short
435CountAndMarkLibs( x, y)
436 shortx, y;
437{
438 shorttx,ty,i;
439 shortcnt = 0;
440
441
442 for (i=0;i<4;i++)
443 {
444 tx = x + xVec[i];
445 ty = y + yVec[i];
446 if (LegalPoint(tx,ty) && goboard[tx][ty].Val == EMPTY
447 && goboard[tx][ty].marked == FALSE)
448 {
449 cnt++;
450 goboard[tx][ty].marked = TRUE;
451 }
452 }
453 return cnt;
454}
455
456/* Determine the number of liberties for a group given the group code
457 num */
458void
459CountLiberties( code)
460 shortcode;
461{
462 shortx, y, libcnt = 0;
463
464 ForeachPoint(y,x)
465 if (goboard[x][y].GroupNum == code)
466 libcnt += CountAndMarkLibs( x, y);
467 EraseMarks();
468 GroupList[code].liberties = libcnt;
469}
470
471void
472CheckForEye( x, y, groups, cnt, recheck)
473 shortx, y, groups[4], cnt, *recheck;
474{
475 shorti;
476
477 for (i = 0; i < (cnt-1); i++)
478 if (groups[i] != groups[i+1])
479 {
480 /* Mark liberty for false eye check */
481 goboard[x][y].marked = TRUE;
482 (*recheck)++;
483 return;
484 }
485 /* It is an eye */
486 GroupList[groups[i]].eyes += 1;
487}
488
489/* Set the eye count for the groups */
490void CountEyes()
491{
492 shorti, x, y,
493 wgroups[4], bgroups[4], wcnt, bcnt, max, cnt, recheck = 0, eye;
494
495 for (i = 1; i <= GroupCount; i++)
496 GroupList[i].eyes = 0;
497
498 ForeachPoint(y,x)
499 {
500 if (goboard[x][y].Val != EMPTY)
501 continue;
502 cnt = Connect(WHITE,x,y,wgroups,&wcnt,bgroups,&bcnt);
503 max = Maxlibs( x, y);
504 if (cnt == max && wcnt == 1 && bcnt == 0)
505 GroupList[wgroups[0]].eyes++;
506 else if (cnt == max && bcnt == 1 && wcnt == 0)
507 GroupList[bgroups[0]].eyes++;
508 else if (cnt == max && ( bcnt == 0 || wcnt == 0 ))
509 {
510 goboard[x][y].marked = TRUE;
511 recheck++;
512 }
513 }
514
515 /*-- Now recheck marked liberties to see if two or more one eye --*/
516 /*-- groups contribute to a false eye */
517 if (recheck == 0)
518 return;
519
520 ForeachPoint(y,x)
521 if (goboard[x][y].marked)
522 {
523 recheck--;
524 goboard[x][y].marked = FALSE;
525 Connect( WHITE, x, y, wgroups, &wcnt, bgroups, &bcnt);
526 /* If all the groups have at least one eye then all the
527 groups are safe from capture because of the common
528 liberty at x, y */
529 eye = TRUE;
530 for (i = 0; i < wcnt; i++)
531 if (GroupList[wgroups[i]].eyes == 0)
532 eye = FALSE;
533 if (eye)
534 for (i = 0; i < wcnt; i++)
535 GroupList[wgroups[i]].eyes++;
536 for (i = 0; i < bcnt; i++)
537 if (GroupList[bgroups[i]].eyes == 0)
538 eye = FALSE;
539 if (eye)
540 for (i = 0; i < bcnt; i++)
541 GroupList[bgroups[i]].eyes++;
542 if (recheck == 0)
543 return;
544 }
545}
546
547
548 shortfoo[19][19];
549
550/*----------------------------------------------------------------
551 -- CountUp() --
552 -- Count up final scores at the end of the game. --
553----------------------------------------------------------------*/
554CountUp( wtotal, btotal )
555 int *wtotal, *btotal;
556{
557 shortx,y;
558 shortCountFromPoint();
559 shortvv;
560 charbuff[512];
561
562
563 blackTerritory = whiteTerritory = 0;
564 ForeachPoint(y,x)
565 {
566 goboard[x][y].marked = FALSE;
567 foo[x][y] = CNT_UNDECIDED;
568 }
569 ForeachPoint(y,x)
570 if (goboard[x][y].Val==EMPTY && foo[x][y]==CNT_UNDECIDED)
571 {
572 FillPoints(x,y,CountFromPoint(x,y));
573 }
574
575 *wtotal = whiteTerritory + blackPrisoners;
576 *btotal = blackTerritory + whitePrisoners;
577 /*
578 sprintf(buff,"White : %3d territory + %3d prisoners = %d\n\
579Black : %3d territory + %3d prisoners = %d\n\n%s.\n",
580 whiteTerritory,blackPrisoners,*wtotal,
581 blackTerritory,whitePrisoners,*btotal,
582 (*btotal>*wtotal?"Black wins":(*wtotal>*btotal?"White wins":
583 "A draw")));
584
585
586
587 XtVaSetValues(message,XtNstring,buff,0);
588 printf( "CountUp() %s", buff );
589 */
590}
591
592FillPoints(x,y,val)
593 shortx,y,val;
594{
595 inti;
596 shorttx,ty;
597
598
599 if ((foo[x][y] = val) == CNT_BLACK_TERR)
600 blackTerritory++;
601 else if (val == CNT_WHITE_TERR)
602 whiteTerritory++;
603 for (i=0;i<4;i++)
604 {
605 tx = x + xVec[i];
606 ty = y + yVec[i];
607 if (!LegalPoint(tx,ty))
608 continue;
609 if (goboard[tx][ty].Val==EMPTY && foo[tx][ty]==CNT_UNDECIDED)
610 FillPoints(tx,ty,val);
611 }
612}
613
614short
615CountFromPoint(x,y)
616 shortx,y;
617{
618 inti;
619 shorttx,ty;
620 shortblkcnt=0,whtcnt=0;
621 shortbaz;
622
623
624 goboard[x][y].marked = TRUE;
625 for (i=0;i<4;i++)
626 {
627 tx = x + xVec[i];
628 ty = y + yVec[i];
629 if (!LegalPoint(tx,ty))
630 continue;
631 if (goboard[tx][ty].Val == BLACK)
632 blkcnt++;
633 else if (goboard[tx][ty].Val == WHITE)
634 whtcnt++;
635 else
636 {
637 if (goboard[tx][ty].marked)
638 continue;
639 baz = CountFromPoint(tx,ty);
640 if (baz == CNT_NOONE)
641 return CNT_NOONE;
642 else if (baz == CNT_BLACK_TERR)
643 blkcnt++;
644 else if (baz == CNT_WHITE_TERR)
645 whtcnt++;
646 }
647 if (blkcnt && whtcnt)
648 return CNT_NOONE;
649 }
650 if (blkcnt && !whtcnt)
651 return CNT_BLACK_TERR;
652 else if (whtcnt && !blkcnt)
653 return CNT_WHITE_TERR;
654 else
655 return CNT_UNDECIDED;
656}
diff --git a/noncore/games/go/amigo.h b/noncore/games/go/amigo.h
new file mode 100644
index 0000000..5150ac0
--- a/dev/null
+++ b/noncore/games/go/amigo.h
@@ -0,0 +1,146 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20/*=========================================================================
21 === ===
22 === FILE amigo.h ===
23 === ===
24 === CONTENTS prototypes for the various AmiGo routines. ===
25 === added by neilb ===
26 === ===
27=========================================================================*/
28
29#ifndef __amigo_h
30#define __amigo_h
31
32#include "go.h"
33#include "goplayutils.h"
34
35#ifdef __STDC__
36 #define PROTO(fp)fp
37#else
38 #define PROTO(fp)()
39#endif
40
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/* From goplayer.c */
47
48
49
50/* Procedures from amigo.c */
51
52 shortConnect PROTO((enum bVal, short, short, short[4], short[4], short *, short * ));
53 shortMaxlibs PROTO((short, short));
54 shortSuicide PROTO((enum bVal, short, short));
55 shortStoneLibs PROTO((short, short));
56 voidEraseMarks PROTO(());
57 shortGoPlaceStone PROTO((enum bVal, short, short));
58 voidGoRemoveStone PROTO((short, short));
59 voidMergeGroups PROTO((short, short));
60 voidDeleteGroup PROTO((short));
61 voidReEvalGroups PROTO((enum bVal, short, short, short));
62 voidGroupCapture PROTO((short));
63 voidFixLibs PROTO((enum bVal, short, short, short));
64 intCountUp PROTO((int*, int*));
65 /*voidmain PROTO(());*/
66 voidgoRestart PROTO((int));
67 voidRelabelGroups PROTO(());
68 shortCountAndMarkLibs PROTO((short, short));
69 voidCountLiberties PROTO((short));
70 voidCheckForEye PROTO((short, short, short[4], short, short *));
71 voidCountEyes PROTO(());
72 voidprintGroupReport PROTO((short, short));
73
74
75/* killable.c */
76
77 inttryPlay PROTO(( short, short, short ));
78 intsSpanGroup PROTO(( short, short, sPointList * ));
79 intspanGroup PROTO(( short, short, pointList *));
80 intpause PROTO(());
81
82 intgenState PROTO(());
83 intinitGPUtils PROTO(());
84 intgenBord PROTO((enum bVal));
85
86 shortgenMove PROTO(( enum bVal, short *, short * ));
87 shortcheckPos PROTO(( short, short, short ));
88 shorttakeCorner PROTO(( short *, short * ));
89 shortextend PROTO(( short *, short * ));
90 shortnoNbrs PROTO(( short, short ));
91 shortextend2 PROTO(( short *, short * ));
92 shortlookForSave PROTO(( short *, short * ));
93 shortlookForSaveN PROTO(( short *, short * ));
94 shortlookForKill PROTO(( short *, short * ));
95 shortdoubleAtari PROTO(( short *, short * ));
96 shortlookForAttack PROTO(( short *, short * ));
97 shortthreaten PROTO(( short *, short * ));
98 shortconnectCut PROTO(( short *, short * ));
99 shortheCanCut PROTO(( short, short ));
100 shortsafeMove PROTO(( short, short ));
101 shortextendWall PROTO(( short *, short * ));
102 shortfindAttack2 PROTO(( short *, short * ));
103 shortblockCut PROTO(( short *, short * ));
104 shortcutHim PROTO(( short *, short * ));
105 shortatariAnyway PROTO(( short *, short * ));
106 shortunderCut PROTO(( short *, short * ));
107 shortdropToEdge PROTO(( short *, short * ));
108 shortpushWall PROTO(( short *, short * ));
109 shortreduceHisLiberties PROTO(( short *, short * ));
110 shortdropToEdge2 PROTO(( short *, short * ));
111
112
113/* goplayutils.c */
114
115 shortsaveable PROTO((short, short, short *, short *));
116 shortkillable PROTO((short, short, short *, short *));
117 intinitBoolBoard PROTO((boolBoard));
118 intintersectPlist PROTO((pointList *, pointList *, pointList *));
119 intinitArray PROTO((intBoard));
120 intinitState PROTO(());
121 intcopyArray PROTO((intBoard, intBoard));
122 intstake PROTO(());
123 intspread PROTO(());
124 intrespreicen PROTO(());
125 inttryPlay PROTO((short, short, short));
126 intsaveState PROTO(());
127 intrestoreState PROTO(());
128 shorttencen PROTO((short, short));
129 intgenConnects PROTO(());
130 intsortLibs PROTO(());
131
132
133/*-- from xinterface.c --*/
134 voidremovestone PROTO((short, short));
135 voidplacestone PROTO((enum bVal, short, short));
136
137 voidintrMoveReport PROTO((enum bVal,char *,char *));
138 voidintrPrisonerReport PROTO(( short, short ));
139
140
141#ifdef __cplusplus
142}
143#endif
144
145
146#endif
diff --git a/noncore/games/go/go.h b/noncore/games/go/go.h
new file mode 100644
index 0000000..9aa644b
--- a/dev/null
+++ b/noncore/games/go/go.h
@@ -0,0 +1,81 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20/* AmiGo Include */
21/* MSG types for getinput() */
22
23#ifndef __go_h
24#define __go_h
25
26
27 #define INTERSECTIONMSG 1/* User buttoned an intersection */
28 #define QUITMSG 2 /* User buttoned QUIT icon */
29#define PLAYMSG 3
30#define RESTARTMSG 4
31#define PASSMSG 5
32
33#define TRUE 1
34#define FALSE 0
35
36#define MAXGROUPS 100
37
38#define PLACED 0
39#define REMOVED 1
40
41#define numPoints 19
42#define maxPoint numPoints - 1
43
44/*-- definitions used when counting up --*/
45
46 #define CNT_UNDECIDED0
47 #define CNT_BLACK_TERR1
48 #define CNT_WHITE_TERR2
49 #define CNT_NOONE3
50
51/*-- macro functions --*/
52
53 #define LegalPoint(x,y) (x>=0 && x<=18 && y>=0 && y<=18)
54 #define ForeachPoint(a,b)for(a=0;a<19;a++) for (b=0;b<19;b++)
55
56enum bVal {BLACK, WHITE, EMPTY};
57typedef enum bVal sType;
58struct Group
59{
60 enum bVal color;/* The color of the group */
61 short code, /* The code used to mark stones in the group */
62 count, /* The number of stones in the group */
63 internal,/* The number of internal liberties */
64 external,/* The number of external liberties */
65 liberties,/* The total number of liberties */
66 eyes, /* The number of eyes */
67 alive, /* A judgement of how alive this group is */
68 territory;/* The territory this group controls */
69};
70
71struct bRec
72{
73 enum bVal Val;/* What is at this intersection */
74 short xOfs,
75 yOfs;
76 short mNum;
77 short GroupNum;/* What group the stone belongs to */
78 short marked;/* TRUE or FALSE */
79};
80
81#endif
diff --git a/noncore/games/go/go.pro b/noncore/games/go/go.pro
new file mode 100644
index 0000000..deb90c5
--- a/dev/null
+++ b/noncore/games/go/go.pro
@@ -0,0 +1,19 @@
1 DESTDIR = ../bin
2 TEMPLATE= app
3 CONFIG = qt warn_on release
4 HEADERS = amigo.h \
5 go.h \
6 goplayutils.h \
7 gowidget.h
8 SOURCES = amigo.c \
9 goplayer.c \
10 goplayutils.c \
11 killable.c \
12 gowidget.cpp \
13 main.cpp
14INCLUDEPATH += $(QPEDIR)/include
15 DEPENDPATH+= $(QPEDIR)/include
16LIBS += -lqpe
17 TARGET = go
18
19TRANSLATIONS = ../i18n/de/go.ts \ No newline at end of file
diff --git a/noncore/games/go/goplayer.c b/noncore/games/go/goplayer.c
new file mode 100644
index 0000000..88c0f61
--- a/dev/null
+++ b/noncore/games/go/goplayer.c
@@ -0,0 +1,1499 @@
1/* The go player */
2/* Ported from Pascal to C by Todd R. Johnson 4/17/88 */
3/* From the original pascal file:
4Go Move Generator
5Copyright (c) 1983 by Three Rivers Computer Corp.
6
7Written: January 17, 1983 by Stoney Ballard
8Edit History:
9*/
10
11#include "go.h"
12#include "goplayutils.h"
13#include "amigo.h"
14
15 #define BIGGEST 32767/* maximum value for short */
16
17/* From go.c */
18extern struct bRec goboard[19][19];
19extern short ko, koX, koY;
20
21/* From goplayutils.c */
22extern intBoard bord;
23extern intBoard ndbord;
24extern intBoard claim;
25extern intBoard legal;
26extern intBoard connectMap;
27extern intBoard threatBord;
28extern short maxGroupID;
29extern short treeLibLim;
30extern short killFlag;
31extern short depthLimit;
32extern short showTrees;
33extern short utilPlayLevel;
34extern groupRec gList[maxGroup];
35extern short sGlist[maxGroup + 1];
36extern pointList pList;
37extern pointList pList1;
38extern pointList plist2;
39extern pointList plist3;
40extern intBoard groupIDs;
41extern intBoard protPoints;
42extern sType mySType;
43
44
45short saveNLibs;
46pointList dapList1, dapList2, dapList3;
47char *playReason;
48short maxPlayLevel = 7;
49short playLevel = 7;
50
51genBord(color)
52 enum bValcolor;
53{
54 short x, y, nomoves = TRUE;
55 char mv[8];
56
57 maxPlayLevel = 7;
58 utilPlayLevel = playLevel;
59 mySType = color;
60 if (playLevel < 2)
61 treeLibLim = 2;
62 else
63 treeLibLim = 3;
64 depthLimit = 100;
65 for (y = 0; y <= 18; y++)
66 for (x = 0; x <= 18; x++)
67 if (goboard[x][y].Val == color)
68 {
69 bord[x][y] = 1;
70 legal[x][y] = FALSE;
71 nomoves = FALSE;
72 }
73 else if (goboard[x][y].Val == EMPTY)
74 {
75 bord[x][y] = 0;
76 legal[x][y] = TRUE;
77 }
78 else
79 {
80 bord[x][y] = -1;
81 legal[x][y] = FALSE;
82 nomoves = FALSE;
83 }
84 if (ko)
85 {
86 legal[koX][koY] = FALSE;
87 }
88
89 if (! nomoves)
90 genState();
91 else
92 initGPUtils();
93}
94
95
96short getMove( x, y )
97short *x, *y;
98{
99 if (takeCorner(x, y)) return TRUE;
100 if (lookForSave(x, y)) return TRUE;
101 if (lookForSaveN(x, y)) return TRUE;
102 if (extend(x, y)) return TRUE;
103 if (lookForKill(x, y)) return TRUE;
104 if (doubleAtari(x, y)) return TRUE;
105 if (lookForAttack(x, y)) return TRUE;
106 if (threaten(x, y)) return TRUE;
107 if (extend2(x, y)) return TRUE;
108 if (connectCut(x, y)) return TRUE;
109 if (blockCut(x, y)) return TRUE;
110 if (cutHim(x, y)) return TRUE;
111 if (extendWall(x, y)) return TRUE;
112 if (findAttack2(x, y)) return TRUE;
113 if (atariAnyway(x, y)) return TRUE;
114 if (underCut(x, y)) return TRUE;
115 if (dropToEdge(x, y)) return TRUE;
116 if (pushWall(x, y)) return TRUE;
117 if (reduceHisLiberties(x, y)) return TRUE;
118 if (dropToEdge2(x, y)) return TRUE;
119 return FALSE;
120}
121
122short genMove( color, x, y )
123enum bVal color;
124short *x, *y;
125{
126 if (playLevel > 2)
127 saveNLibs = TRUE;
128 else
129 saveNLibs = FALSE;
130 genBord(color);
131 if (getMove(x, y))
132 return TRUE;
133 return FALSE;
134}
135
136short checkPos(x, y, field)
137short x, y, field;
138{
139 short ok;
140 ok = (((field == 0) && (claim[x][y] == 0)) ||
141 ((field > 0) &&
142 (claim[x][y] >= 0) && (claim[x][y] <= field)) ||
143 ((field < 0) &&
144 (claim[x][y] <= 0) && (claim[x][y] >= field))) &&
145 (bord[x-1][y] == 0) &&
146 (bord[x+1][y] == 0) &&
147 (bord[x][y-1] == 0) &&
148 (bord[x][y+1] == 0);
149 if (ok) return TRUE; else return FALSE;
150}
151
152short takeCorner( x, y )
153short *x, *y;
154{
155 short field = -1, i;
156 i = 18 - 3;
157 playReason = "takeCorner";
158 while (field != -4)
159 {
160 if (field == -1) field = 0;
161 else if (field == 0) field = 4;
162 else field = -4;
163 if (checkPos(2, 3, field)) { *x = 2; *y = 3; return TRUE; }
164 if (checkPos(3, 2, field)) { *x = 3; *y = 2; return TRUE; }
165 if (checkPos(2, i, field)) { *x = 2; *y = i; return TRUE; }
166 if (checkPos(3, i + 1, field)) { *x = 3; *y = i+1; return TRUE; }
167 if (checkPos(i, i + 1, field)) { *x = i; *y = i+1; return TRUE; }
168 if (checkPos(i + 1, i, field)) { *x = i+1; *y = i; return TRUE; }
169 if (checkPos(i, 2, field)) { *x = i; *y = 2; return TRUE; }
170 if (checkPos(i + 1, 3, field)) { *x = i+1; *y = 3; return TRUE; }
171 if (checkPos(2, 4, field)) { *x = 2; *y = 4; return TRUE; }
172 if (checkPos(4, 2, field)) { *x = 4; *y = 2; return TRUE; }
173 if (checkPos(2, i - 1, field)) { *x = 2; *y = i-1; return TRUE; }
174 if (checkPos(4, i + 1, field)) { *x = 4; *y = i+1; return TRUE; }
175 if (checkPos(i - 1, i + 1, field)) { *x = i-1; *y = i+1; return TRUE; }
176 if (checkPos(i + 1, i - 1, field)) { *x = i+1; *y = i-1; return TRUE; }
177 if (checkPos(i + 1, 4, field)) { *x = i+1; *y = 4; return TRUE; }
178 if (checkPos(i - 1, 2, field)) { *x = i-1; *y = 2; return TRUE; }
179 }
180 return FALSE;
181}
182
183printBoard(brd, name)
184intBoard brd;
185char *name;
186{
187 short x, y;
188 printf( "%s\n", name );
189 for (y = 0; y <= 18; y++)
190 {
191 for (x = 0; x <= 18; x++)
192 printf("%d ", brd[x][y]);
193 printf("\n");
194 }
195}
196
197short noNbrs( x, y )
198short x, y;
199{
200 if (x > 0 && bord[x-1][y] != 0) return FALSE;
201 if (x < 18 && bord[x+1][y] != 0) return FALSE;
202 if (y > 0 && bord[x][y-1] != 0) return FALSE;
203 if (y < 18 && bord[x][y+1] != 0) return FALSE;
204 return TRUE;
205}
206
207short extend(x, y)
208short *x, *y;
209{
210 short i;
211 playReason = "extend";
212 for (i = 2; i <= 18-2; i++)
213 if (claim[2][i] == 0 && noNbrs( 2, i ))
214 {
215 *x = 2;
216 *y = i;
217 return TRUE;
218 }
219 for (i = 2; i <= 18-2; i++)
220 if (claim[i][18-2] == 0 && noNbrs( 2, i ))
221 {
222 *x = i;
223 *y = 18-2;
224 return TRUE;
225 }
226 for (i = 18-2; i >= 2; i--)
227 if (claim[18-2][i] == 0 && noNbrs( 18-2, i ))
228 {
229 *x = 18-2;
230 *y = i;
231 return TRUE;
232 }
233 for (i = 18-2; i >= 2; i--)
234 if (claim[i][2] == 0 && noNbrs( i, 2 ))
235 {
236 *x = i;
237 *y = 2;
238 return TRUE;
239 }
240 return FALSE;
241}
242
243short extend2( x, y )
244short *x, *y;
245{
246 short i, lowest = BIGGEST, value;
247 playReason = "extend2";
248 for (i = 3; i <= 18-3; i++)
249 if (legal[2][i]) /* if there is nobody there */
250 {
251 value = claim[2][i]; /* get influence */
252 if ((value < 7) && /* a reasonable hole in my wall */
253 (value > -5) && /* or a reasonable gap in his */
254 (bord[2][i + 1] == 0) && /* not in contact with any stones */
255 (bord[2][i - 1] == 0))
256 if (value < lowest)
257 {
258 lowest = value; /* lowest gets the smallest value */
259 *x = 2; /* that was seen along all the 3-lines */
260 *y = i; /* x and y save that location */
261 }
262 }
263 for (i = 3; i <= 18-3; i++)
264 if (legal[i][2])
265 {
266 value = claim[i][2];
267 if ((value < 7) &&
268 (value > -5) &&
269 (bord[i + 1][2] == 0) &&
270 (bord[i - 1][2] == 0))
271 if (value < lowest)
272 {
273 lowest = value;
274 *x = i;
275 *y = 2;
276 }
277 }
278 for (i = 18-3; i >= 3; i--)
279 if (legal[18 - 2][i])
280 {
281 value = claim[18 - 2][i];
282 if ((value < 7) &&
283 (value > -5) &&
284 (bord[18 - 2][i + 1] == 0) &&
285 (bord[18 - 2][i - 1] == 0))
286 if (value < lowest)
287 {
288 lowest = value;
289 *x = 18 - 2;
290 *y = i;
291 }
292 }
293 for (i = 3; i <= 18-3; i++)
294 if (legal[i][18 - 2])
295 {
296 value = claim[i][18 - 2];
297 if ((value < 7) &&
298 (value > -5) &&
299 (bord[i + 1][18 - 2] == 0) &&
300 (bord[i - 1][18 - 2] == 0))
301 if (value < lowest)
302 {
303 lowest = value;
304 *x = i;
305 *y = 18 - 2;
306 }
307 }
308 if (lowest == BIGGEST) return FALSE;
309 return TRUE;
310}
311
312 /*
313 check to see if I can save anything in atari
314 */
315short lookForSave(x, y)
316short *x, *y;
317 { /* lookForSave */
318 short i;
319 playReason = "lookForSave";
320 for (i = 1; i <= maxGroupID; i++) /* scan the group list */
321 if ((gList[i].libC == 1) &&
322 (ndbord[gList[i].lx][gList[i].ly] == 1))
323 if (saveable(gList[i].lx, gList[i].ly, x, y)) /* see if I can save it */
324 return TRUE;
325 return FALSE;
326 } /* lookForSave */
327
328 /*
329 check to see if I can save anything with n libs
330 */
331short lookForSaveN(x, y)
332short *x, *y;
333 { /* lookForSaveN */
334 short i;
335 if (saveNLibs)
336 {
337 playReason = "lookForSaveN";
338 for (i = 1; i <= maxGroupID; i++) /* scan the group list */
339 if ((gList[i].libC > 1) &&
340 (gList[i].libC <= treeLibLim) &&
341 (ndbord[gList[i].lx][gList[i].ly] == 1))
342 {
343 if (killable(gList[i].lx, gList[i].ly, x, y))
344 if (saveable(gList[i].lx, gList[i].ly, x, y)) /* see if I can save it */
345 return TRUE;
346 }
347 }
348 return FALSE;
349 } /* lookForSaveN */
350
351
352/*----------------------------------------------------------------
353 -- lookForKill() --
354 -- check to see if I can kill anything. --
355----------------------------------------------------------------*/
356short
357lookForKill(x, y)
358 short*x, *y;
359{
360 shorti;
361 charmv[8];
362
363 playReason = "lookForKill";
364 for (i = 1; i <= maxGroupID; i++) /* scan the group list */
365 if ((gList[i].libC == 1) &&
366 (ndbord[gList[i].lx][gList[i].ly] == -1))
367 { /* we found a live enemy group with one liberty */
368 /* find the liberty */
369 spanGroup(gList[i].lx, gList[i].ly, &pList);
370 *x = pList.p[1].px;
371 *y = pList.p[1].py;
372 if (legal[*x][*y])
373 {
374 return TRUE;
375 }
376 }
377 return FALSE;
378}
379
380short doubleAtari(x, y)
381short *x, *y;
382 { /* doubleAtari */
383 short i, j;
384 playReason = "doubleAtari";
385 for (i = 1; i <= maxGroupID - 1; i++)
386 if ((gList[i].libC == 2) &&
387 (ndbord[gList[i].lx][gList[i].ly] == -1)) /* found an atariable group of his */
388 {
389 spanGroup(gList[i].lx, gList[i].ly, &dapList1);
390 for (j = i + 1; j <= maxGroupID; j++)
391 if ((gList[j].libC == 2) &&
392 (ndbord[gList[j].lx][gList[j].ly] == -1))
393 {
394 spanGroup(gList[j].lx, gList[j].ly, &dapList2);
395 intersectPlist(&dapList1, &dapList2, &dapList3);
396 if (dapList3.indx > 0)
397 if (legal[dapList3.p[1].px][dapList3.p[1].py])
398 {
399 tryPlay(dapList3.p[1].px, dapList3.p[1].py, 1);
400 if (gList[groupIDs[dapList3.p[1].px][
401 dapList3.p[1].py]].libC > 1)
402 {
403 *x = dapList3.p[1].px;
404 *y = dapList3.p[1].py;
405 restoreState();
406 return TRUE;
407 }
408 restoreState();
409 }
410 }
411 }
412 return FALSE;
413 } /* doubleAtari */
414
415short lookForAttack(x, y)
416short *x, *y;
417 { /* lookForAttack */
418 short tx, ty, i;
419 playReason = "lookForAttack";
420 for (i = 1; i <= maxGroupID; i++) /* scan the group list */
421 if ((! gList[i].isLive) &&
422 (gList[i].libC > 1) &&
423 (gList[i].libC <= (treeLibLim + 1)) &&
424 (ndbord[gList[i].lx][gList[i].ly] == -1))
425 {
426 if (killable(gList[i].lx, gList[i].ly, &tx, &ty)) /* can we kill it? */
427 {
428 *x = tx; /* yep - do so */
429 *y = ty;
430 return TRUE;
431 }
432 }
433 return FALSE;
434 } /* lookForAttack */
435
436 /*
437 Plays a move that requires a response on the opponent's part
438 */
439short threaten(x, y)
440short *x, *y;
441 { /* threaten */
442 short i, j, gx, gy, tNum;
443 playReason = "threaten";
444 initArray(threatBord);
445 for (i = 1; i <= maxGroupID; i++)
446 if ((! gList[i].isLive) &&
447 (ndbord[gList[i].lx][gList[i].ly] == -1))
448 {
449 spanGroup(gList[i].lx, gList[i].ly, &pList);
450 for (j = 1; j <= pList.indx; j++)
451 if (legal[pList.p[j].px][pList.p[j].py])
452 {
453 tryPlay(pList.p[j].px, pList.p[j].py, 1);
454 if (gList[groupIDs[pList.p[j].px][pList.p[j].py]].libC > 1)
455 if (killable(gList[i].lx, gList[i].ly, &gx, &gy))
456 threatBord[pList.p[j].px][pList.p[j].py] += 1;
457 restoreState();
458 }
459 }
460 tNum = 0;
461 for (i = 0; i <= maxPoint; i++)
462 for (j = 0; j <= maxPoint; j++)
463 if ((threatBord[i][j] > tNum) &&
464 ((threatBord[i][j] > 1) ||
465 (connectMap[i][j] > 0)))
466 {
467 tNum = threatBord[i][j];
468 *x = i;
469 *y = j;
470 }
471 if (tNum > 0) return TRUE;
472 else return FALSE;
473 } /* threaten */
474
475 /*
476 connects against enemy cuts
477 */
478short connectCut(x, y)
479short *x, *y;
480 { /* connectCut */
481 short i, j, nap, gid, infl;
482 playReason = "connectCut";
483 for (i = 0; i <= maxPoint; i++)
484 for (j = 0; j <= maxPoint; j++)
485 if (legal[i][j] &&
486 (protPoints[i][j] == 0)) /* not a protected point */
487 {
488 nap = 0; /* how many of my stones am I adjacent to? */
489 if ((i > 0) && (bord[i - 1][j] == 1))
490 {
491 nap = nap + 1;
492 pList.p[nap].px = i - 1;
493 pList.p[nap].py = j;
494 }
495 if ((j > 0) && (bord[i][j - 1] == 1))
496 {
497 nap = nap + 1;
498 pList.p[nap].px = i;
499 pList.p[nap].py = j - 1;
500 }
501 if ((i < maxPoint) && (bord[i + 1][j] == 1))
502 {
503 nap = nap + 1;
504 pList.p[nap].px = i + 1;
505 pList.p[nap].py = j;
506 }
507 if ((j < maxPoint) && (bord[i][j + 1] == 1))
508 {
509 nap = nap + 1;
510 pList.p[nap].px = i;
511 pList.p[nap].py = j + 1;
512 }
513 if (nap == 1) /* possible knight's || 2-point extention */
514 {
515 gid = groupIDs[pList.p[1].px][pList.p[1].py];
516 if ((i > 0) && (i < maxPoint) &&
517 (ndbord[i - 1][j] == 1) &&
518 (ndbord[i + 1][j] == 0)) /* contact on left */
519 {
520 if (((j > 0) && (ndbord[i][j - 1] == -1) &&
521 (ndbord[i + 1][j - 1] == 1) &&
522 (gid != groupIDs[i + 1][j - 1])) ||
523 ((j < maxPoint) && (ndbord[i][j + 1] == -1) &&
524 (ndbord[i + 1][j + 1] == 1) &&
525 (gid != groupIDs[i + 1][j + 1])) ||
526 ((((j > 0) && (ndbord[i][j - 1] == -1)) ||
527 ((j < maxPoint) && (ndbord[i][j + 1] == -1))) &&
528 (i < (maxPoint - 1)) &&
529 (ndbord[i + 2][j] == 1) &&
530 (gid != groupIDs[i + 2][j])))
531 {
532 *x = i;
533 *y = j;
534 if (safeMove(*x, *y))
535 return TRUE;
536 }
537 }
538 else if ((i < maxPoint) && (i > 0) &&
539 (ndbord[i + 1][j] == 1) &&
540 (ndbord[i - 1][j] == 0)) /* r */
541 {
542 if (((j > 0) && (ndbord[i][j - 1] == -1) &&
543 (ndbord[i - 1][j - 1] == 1) &&
544 (gid != groupIDs[i - 1][j - 1])) ||
545 ((j < maxPoint) && (ndbord[i][j + 1] == -1) &&
546 (ndbord[i - 1][j + 1] == 1) &&
547 (gid != groupIDs[i - 1][j + 1])) ||
548 ((((j > 0) && (ndbord[i][j - 1] == -1)) ||
549 ((j < maxPoint) && (ndbord[i][j + 1] == -1))) &&
550 (i > 1) &&
551 (ndbord[i - 2][j] == 1) &&
552 (gid != groupIDs[i - 2][j])))
553 {
554 *x = i;
555 *y = j;
556 if (safeMove(*x, *y))
557 return TRUE;
558 }
559 }
560 else if ((j > 0) && (j < maxPoint) &&
561 (ndbord[i][j - 1] == 1) &&
562 (ndbord[i][j + 1] == 0)) /* top */
563 {
564 if (((i > 0) && (ndbord[i - 1][j] == -1) &&
565 (ndbord[i - 1][j + 1] == 1) &&
566 (gid != groupIDs[i - 1][j + 1])) ||
567 ((i < maxPoint) && (ndbord[i + 1][j] == -1) &&
568 (ndbord[i + 1][j + 1] == 1) &&
569 (gid != groupIDs[i + 1][j + 1])) ||
570 ((((i > 0) && (ndbord[i - 1][j] == -1)) ||
571 ((i < maxPoint) && (ndbord[i + 1][j] == -1))) &&
572 (j < (maxPoint - 1)) &&
573 (ndbord[i][j + 2] == 1) &&
574 (gid != groupIDs[i][j + 2])))
575 {
576 *x = i;
577 *y = j;
578 if (safeMove(*x, *y))
579 return TRUE;
580 }
581 }
582 else if ((j > 0) && (j < maxPoint) &&
583 (ndbord[i][j + 1] == 1) &&
584 (ndbord[i][j - 1] == 0)) /* bottom */
585 {
586 if (((i > 0) && (ndbord[i - 1][j] == -1) &&
587 (ndbord[i - 1][j - 1] == 1) &&
588 (gid != groupIDs[i - 1][j - 1])) ||
589 ((i < maxPoint) && (ndbord[i + 1][j] == -1) &&
590 (ndbord[i + 1][j - 1] == 1) &&
591 (gid != groupIDs[i + 1][j - 1])) ||
592 ((((i > 0) && (ndbord[i - 1][j] == -1)) ||
593 ((i < maxPoint) && (ndbord[i + 1][j] == -1))) &&
594 (j > 1) &&
595 (ndbord[i][j - 2] == 1) &&
596 (gid != groupIDs[i][j - 2])))
597 {
598 *x = i;
599 *y = j;
600 if (safeMove(*x, *y))
601 return TRUE;
602 }
603 }
604 }
605 else if (nap == 2) /* diagonal or 1-point extention */
606 {
607 if (groupIDs[pList.p[1].px][pList.p[1].py] !=
608 groupIDs[pList.p[2].px][pList.p[2].py])
609 {
610 if ((pList.p[1].px != pList.p[2].px) &&
611 (pList.p[1].py != pList.p[2].py)) /* diag */
612 {
613 spanGroup(pList.p[1].px,
614 pList.p[1].py, &pList1);
615 spanGroup(pList.p[2].px,
616 pList.p[2].py, &plist2);
617 intersectPlist(&pList1, &plist2, &plist3);
618 if (plist3.indx == 1)
619 if ((i > 0) && (ndbord[i - 1][j] == -1) ||
620 (i < maxPoint) && (ndbord[i + 1][j] == -1) ||
621 (j > 0) && (ndbord[i][j - 1] == -1) ||
622 (j < maxPoint) && (ndbord[i][j + 1] == -1))
623 { /* must make direct connection */
624 *x = i;
625 *y = j;
626 if (heCanCut(*x, *y))
627 if (safeMove(*x, *y))
628 return TRUE;
629 }
630 else if (heCanCut(i, j))
631 { /* protect point if possible */
632 infl = 1000;
633 if ((i > 0) && legal[i - 1][j] &&
634 ((i == 1) || (ndbord[i - 2][j] == 0)) &&
635 ((j == 0) || (ndbord[i - 1][j - 1] == 0)) &&
636 ((j == maxPoint) ||
637 (ndbord[i - 1][j + 1] == 0)))
638 if (safeMove(i - 1, j))
639 if (claim[i - 1][j] < infl)
640 {
641 *x = i - 1;
642 *y = j;
643 infl = claim[i - 1][j];
644 }
645 if ((j > 0) && legal[i][j - 1] &&
646 ((j == 1) || (ndbord[i][j - 2] == 0)) &&
647 ((i == 0) || (ndbord[i - 1][j - 1] == 0)) &&
648 ((i == maxPoint) ||
649 (ndbord[i + 1][j - 1] == 0)))
650 if (safeMove(i, j - 1))
651 if (claim[i][j - 1] < infl)
652 {
653 *x = i;
654 *y = j - 1;
655 infl = claim[i][j - 1];
656 }
657 if ((i < maxPoint) && legal[i + 1][j] &&
658 ((i == (maxPoint - 1)) ||
659 (ndbord[i + 2][j] == 0)) &&
660 ((j == 0) || (ndbord[i + 1][j - 1] == 0)) &&
661 ((j == maxPoint) ||
662 (ndbord[i + 1][j + 1] == 0)))
663 if (safeMove(i + 1, j))
664 if (claim[i + 1][j] < infl)
665 {
666 *x = i + 1;
667 *y = j;
668 infl = claim[i + 1][j];
669 }
670 if ((j < maxPoint) && legal[i][j + 1] &&
671 ((j == (maxPoint - 1)) ||
672 (ndbord[i][j + 2] == 0)) &&
673 ((i == 0) || (ndbord[i - 1][j + 1] == 0)) &&
674 ((i == maxPoint) ||
675 (ndbord[i + 1][j + 1] == 0)))
676 if (safeMove(i, j + 1))
677 if (claim[i][j + 1] < infl)
678 {
679 *x = i;
680 *y = j + 1;
681 infl = claim[i][j + 1];
682 }
683 if (infl < 1000)
684 return TRUE;
685 *x = i; /* direct connection */
686 *y = j;
687 if (safeMove(*x, *y))
688 return TRUE;
689 }
690 }
691 else /* 1-point extension, only protect if threatened */
692 {
693 if ((i > 0) && (ndbord[i - 1][j] == -1) ||
694 (j > 0) && (ndbord[i][j - 1] == -1) ||
695 (i < maxPoint) && (ndbord[i + 1][j] == -1) ||
696 (j < maxPoint) && (ndbord[i][j + 1] == -1))
697 {
698 *x = i;
699 *y = j;
700 if (heCanCut(*x, *y))
701 if (safeMove(*x, *y))
702 return TRUE;
703 }
704 }
705 }
706 }
707 else if (nap == 3) /* unprotected, but me on 3 sides */
708 {
709 if ((groupIDs[pList.p[1].px][pList.p[1].py] !=
710 groupIDs[pList.p[2].px][pList.p[2].py]) ||
711 (groupIDs[pList.p[1].px][pList.p[1].py] !=
712 groupIDs[pList.p[3].px][pList.p[3].py]) ||
713 (groupIDs[pList.p[3].px][pList.p[3].py] !=
714 groupIDs[pList.p[2].px][pList.p[2].py]))
715 {
716 spanGroup(pList.p[1].px, pList.p[1].py, &pList1);
717 spanGroup(pList.p[2].px, pList.p[2].py, &plist2);
718 intersectPlist(&pList1, &plist2, &plist3);
719 spanGroup(pList.p[3].px, pList.p[3].py, &plist2);
720 intersectPlist(&plist2, &plist3, &pList1);
721 if (pList1.indx == 1) /* a common connect point */
722 if (heCanCut(i, j))
723 if (safeMove(i, j))
724 {
725 *x = i;
726 *y = j;
727 return TRUE;
728 }
729 }
730 }
731 }
732 return FALSE;
733 } /* connectCut */
734
735short heCanCut(x, y)
736short x, y;
737 { /* heCanCut */
738 short gx, gy, result;
739 if (playLevel > 3)
740 {
741 tryPlay(x, y, -1); /* try his cut */
742 result = ! killable(x, y, &gx, &gy);
743 restoreState();
744 return result;
745 }
746 else
747 return FALSE;
748 } /* heCanCut */
749
750 /*
751 Checks out a move.
752 If my stone is not killable then true.
753 */
754short safeMove(x, y)
755short x, y;
756 { /* safeMove */
757 short gbx, gby, result;
758 tryPlay(x, y, 1); /* try playing at point */
759 if (killFlag) /* I shouldn't kill if lookForKill didn't */
760 result = FALSE;
761 else if (gList[groupIDs[x][y]].libC < 2)
762 { /* if it is in atari or dead */
763 result = FALSE; /* reject it */
764 }
765 else if (gList[groupIDs[x][y]].libC <= treeLibLim) /* see if killable */
766 if (playLevel > 0)
767 result = ! killable(x, y, &gbx, &gby);
768 else
769 result = TRUE;
770 else
771 result = TRUE;
772 restoreState();
773 return result;
774 } /* safeMove */
775
776 /*
777 Extends walls in a connected fashion.
778 Finds the lowest influence (mine) point that is connected to one
779 of my groups.
780 Only looks in the center of the board.
781 */
782short extendWall(x, y)
783short *x, *y;
784 { /* extendWall */
785 short infl, i, j;
786 playReason = "extendWall";
787 *x = iNil;
788 *y = iNil;
789 infl = 11;
790 for (i = 2; i <= maxPoint - 2; i++)
791 for (j = 2; j <= maxPoint - 2; j++)
792 if (legal[i][j])
793 if (connectMap[i][j] > 0)
794 if ((claim[i][j] < infl) &&
795 (ndbord[i - 1][j] < 1) &&
796 (ndbord[i + 1][j] < 1) &&
797 (ndbord[i][j - 1] < 1) &&
798 (ndbord[i][j + 1] < 1) &&
799 ((claim[i - 1][j] < 0) ||
800 (claim[i + 1][j] < 0) ||
801 (claim[i][j - 1] < 0) ||
802 (claim[i][j + 1] < 0)))
803 if (safeMove(i, j))
804 {
805 infl = claim[i][j];
806 *x = i;
807 *y = j;
808 }
809 if (*x != iNil) return TRUE;
810 return FALSE;
811 } /* extendWall */
812
813
814 /*
815 check to see if I can attack one of his groups
816 uses limited depth search so that it can work on larger lib counts
817 */
818short findAttack2(x, y)
819short *x, *y;
820 { /* findAttack2 */
821 short tx, ty, i, otll;
822 if (playLevel < 7)
823 return FALSE;
824 playReason = "findAttack2";
825 depthLimit = 8;
826 otll = treeLibLim;
827 for (i = 1; i <= maxGroupID; i++) /* scan the group list */
828 if ((! gList[i].isLive) &&
829 (ndbord[gList[i].lx][gList[i].ly] == -1) &&
830 (gList[i].libC > 1))
831 {
832 treeLibLim = 6;
833 if (killable(gList[i].lx, gList[i].ly, &tx, &ty)) /* can we kill it? */
834 {
835 *x = tx; /* yep - do so */
836 *y = ty;
837 return TRUE;
838 }
839 treeLibLim = otll;
840 }
841 depthLimit = 100;
842 return FALSE;
843 } /* findAttack2 */
844
845
846 /*
847 blocks enemy cuts thru 1-point extensions
848 */
849short blockCut(x, y)
850short *x, *y;
851 { /* blockCut */
852 short i, j;
853 playReason = "blockCut";
854 for (i = 0; i <= maxPoint; i++)
855 for (j = 0; j <= maxPoint; j++)
856 if (legal[i][j])
857 {
858 if ((i > 0) && (j > 0) && (j < maxPoint))
859 {
860 if ((ndbord[i - 1][j] == -1) &&
861 (ndbord[i - 1][j - 1] == 1) &&
862 (ndbord[i - 1][j + 1] == 1) &&
863 (groupIDs[i - 1][j - 1] != groupIDs[i - 1][j + 1]))
864 {
865 *x = i;
866 *y = j;
867 if (heCanCut(*x, *y))
868 if (safeMove(*x, *y))
869 return TRUE;
870 }
871 }
872 if ((i < maxPoint) && (j > 0) && (j < maxPoint))
873 {
874 if ((ndbord[i + 1][j] == -1) &&
875 (ndbord[i + 1][j - 1] == 1) &&
876 (ndbord[i + 1][j + 1] == 1) &&
877 (groupIDs[i + 1][j - 1] != groupIDs[i + 1][j + 1]))
878 {
879 *x = i;
880 *y = j;
881 if (heCanCut(*x, *y))
882 if (safeMove(*x, *y))
883 return TRUE;
884 }
885 }
886 if ((j > 0) && (i > 0) && (i < maxPoint))
887 {
888 if ((ndbord[i][j - 1] == -1) &&
889 (ndbord[i - 1][j - 1] == 1) &&
890 (ndbord[i + 1][j - 1] == 1) &&
891 (groupIDs[i - 1][j - 1] != groupIDs[i + 1][j - 1]))
892 {
893 *x = i;
894 *y = j;
895 if (heCanCut(*x, *y))
896 if (safeMove(*x, *y))
897 return TRUE;
898 }
899 }
900 if ((j < maxPoint) && (i > 0) && (i < maxPoint))
901 {
902 if ((ndbord[i][j + 1] == -1) &&
903 (ndbord[i - 1][j + 1] == 1) &&
904 (ndbord[i + 1][j + 1] == 1) &&
905 (groupIDs[i - 1][j + 1] != groupIDs[i + 1][j + 1]))
906 {
907 *x = i;
908 *y = j;
909 if (heCanCut(*x, *y))
910 if (safeMove(*x, *y))
911 return TRUE;
912 }
913 }
914 }
915 return FALSE;
916 } /* blockCut */
917
918
919 /*
920 cuts the enemy
921 */
922short cutHim(x, y)
923short *x, *y;
924 { /* cutHim */
925 short i, j, nap, gid;
926 playReason = "cutHim";
927 for (i = 0; i <= maxPoint; i++)
928 for (j = 0; j <= maxPoint; j++)
929 if (legal[i][j])
930 {
931 nap = 0; /* how many of his stones am I adjacent to? */
932 if ((i > 0) && (ndbord[i - 1][j] == -1))
933 {
934 nap = nap + 1;
935 pList.p[nap].px = i - 1;
936 pList.p[nap].py = j;
937 }
938 if ((j > 0) && (ndbord[i][j - 1] == -1))
939 {
940 nap = nap + 1;
941 pList.p[nap].px = i;
942 pList.p[nap].py = j - 1;
943 }
944 if ((i < maxPoint) && (ndbord[i + 1][j] == -1))
945 {
946 nap = nap + 1;
947 pList.p[nap].px = i + 1;
948 pList.p[nap].py = j;
949 }
950 if ((j < maxPoint) && (ndbord[i][j + 1] == -1))
951 {
952 nap = nap + 1;
953 pList.p[nap].px = i;
954 pList.p[nap].py = j + 1;
955 }
956 if (nap == 1) /* possible knight's or 2-point extention */
957 {
958 gid = groupIDs[pList.p[1].px][pList.p[1].py];
959 if ((i > 0) && (i < maxPoint) &&
960 (ndbord[i - 1][j] == -1) &&
961 (connectMap[i][j] > 0)) /* contact on left */
962 {
963 if (((j > 0) &&
964 (ndbord[i + 1][j - 1] == -1) &&
965 (gid != groupIDs[i + 1][j - 1])) ||
966 ((j < maxPoint) &&
967 (ndbord[i + 1][j + 1] == -1) &&
968 (gid != groupIDs[i + 1][j + 1])) ||
969 ((i < (maxPoint - 1)) &&
970 (ndbord[i + 1][j] == 0) &&
971 (ndbord[i + 2][j] == -1) &&
972 (gid != groupIDs[i + 2][j])))
973 {
974 *x = i;
975 *y = j;
976 if (safeMove(*x, *y))
977 return TRUE;
978 }
979 }
980 else if ((i < maxPoint) && (i > 0) &&
981 (ndbord[i + 1][j] == -1) &&
982 (connectMap[i][j] > 0)) /* r */
983 {
984 if (((j > 0) &&
985 (ndbord[i - 1][j - 1] == -1) &&
986 (gid != groupIDs[i - 1][j - 1])) ||
987 ((j < maxPoint) &&
988 (ndbord[i - 1][j + 1] == -1) &&
989 (gid != groupIDs[i - 1][j + 1])) ||
990 ((i > 1) &&
991 (ndbord[i - 1][j] == 0) &&
992 (ndbord[i - 2][j] == -1) &&
993 (gid != groupIDs[i - 2][j])))
994 {
995 *x = i;
996 *y = j;
997 if (safeMove(*x, *y))
998 return TRUE;
999 }
1000 }
1001 else if ((j > 0) && (j < maxPoint) &&
1002 (ndbord[i][j - 1] == -1) &&
1003 (connectMap[i][j] > 0)) /* top */
1004 {
1005 if (((i > 0) &&
1006 (ndbord[i - 1][j + 1] == -1) &&
1007 (gid != groupIDs[i - 1][j + 1])) ||
1008 ((i < maxPoint) &&
1009 (ndbord[i + 1][j + 1] == -1) &&
1010 (gid != groupIDs[i + 1][j + 1])) ||
1011 ((j < (maxPoint - 1)) &&
1012 (ndbord[i][j + 1] == 0) &&
1013 (ndbord[i][j + 2] == -1) &&
1014 (gid != groupIDs[i][j + 2])))
1015 {
1016 *x = i;
1017 *y = j;
1018 if (safeMove(*x, *y))
1019 return TRUE;
1020 }
1021 }
1022 else if ((j > 0) && (j < maxPoint) &&
1023 (ndbord[i][j + 1] == -1) &&
1024 (connectMap[i][j] > 0)) /* bottom */
1025 {
1026 if (((i > 0) &&
1027 (ndbord[i - 1][j - 1] == -1) &&
1028 (gid != groupIDs[i - 1][j - 1])) ||
1029 ((i < maxPoint) &&
1030 (ndbord[i + 1][j - 1] == -1) &&
1031 (gid != groupIDs[i + 1][j - 1])) ||
1032 ((j > 1) &&
1033 (ndbord[i][j - 1] == 0) &&
1034 (ndbord[i][j - 2] == -1) &&
1035 (gid != groupIDs[i][j - 2])))
1036 {
1037 *x = i;
1038 *y = j;
1039 if (safeMove(*x, *y))
1040 return TRUE;
1041 }
1042 }
1043 }
1044 else if (nap == 2) /* diagonal or 1-point extention */
1045 {
1046 if (groupIDs[pList.p[1].px][pList.p[1].py] !=
1047 groupIDs[pList.p[2].px][pList.p[2].py])
1048 {
1049 if ((pList.p[1].px != pList.p[2].px) &&
1050 (pList.p[1].py != pList.p[2].py)) /* diag */
1051 {
1052 spanGroup(pList.p[1].px,
1053 pList.p[1].py, &pList1);
1054 spanGroup(pList.p[2].px,
1055 pList.p[2].py, &plist2);
1056 intersectPlist(&pList1, &plist2, &plist3);
1057 if (plist3.indx == 1)
1058 {
1059 *x = i;
1060 *y = j;
1061 if (safeMove(*x, *y))
1062 return TRUE;
1063 }
1064 }
1065 else /* 1-point extension, only cut if connected */
1066 {
1067 if (connectMap[i][j] > 0)
1068 {
1069 *x = i;
1070 *y = j;
1071 if (safeMove(*x, *y))
1072 return TRUE;
1073 }
1074 }
1075 }
1076 }
1077 else if (nap == 3) /* unprotected, but him on 3 sides */
1078 {
1079 if ((groupIDs[pList.p[1].px][pList.p[1].py] !=
1080 groupIDs[pList.p[2].px][pList.p[2].py]) ||
1081 (groupIDs[pList.p[1].px][pList.p[1].py] !=
1082 groupIDs[pList.p[3].px][pList.p[3].py]) ||
1083 (groupIDs[pList.p[3].px][pList.p[3].py] !=
1084 groupIDs[pList.p[2].px][pList.p[2].py]))
1085 {
1086 spanGroup(pList.p[1].px, pList.p[1].py, &pList1);
1087 spanGroup(pList.p[2].px, pList.p[2].py, &plist2);
1088 intersectPlist(&pList1, &plist2, &plist3);
1089 spanGroup(pList.p[3].px, pList.p[3].py, &plist2);
1090 intersectPlist(&plist2, &plist3, &pList1);
1091 if (pList1.indx == 1) /* a common connect point */
1092 if (safeMove(i, j))
1093 {
1094 *x = i;
1095 *y = j;
1096 return TRUE;
1097 }
1098 }
1099 }
1100 }
1101 return FALSE;
1102 } /* cutHim */
1103
1104
1105 /*
1106 ataris a group just for the hell of it
1107 */
1108short atariAnyway(x, y)
1109short *x, *y;
1110 { /* atariAnyway */
1111 short i;
1112 playReason = "atariAnyway";
1113 for (i = 1; i <= maxGroupID; i++) /* scan the group list */
1114 if ((gList[i].libC == 2) &&
1115 (ndbord[gList[i].lx][gList[i].ly] == -1))
1116 {
1117 spanGroup(gList[i].lx, gList[i].ly, &pList);
1118 if (legal[pList.p[1].px][pList.p[1].py] &&
1119 ((connectMap[pList.p[1].px][pList.p[1].py] > 0) ||
1120 ((pList.p[1].px > 0) &&
1121 (connectMap[pList.p[1].px - 1][pList.p[1].py] > 0)) ||
1122 ((pList.p[1].px < maxPoint) &&
1123 (connectMap[pList.p[1].px + 1][pList.p[1].py] > 0)) ||
1124 ((pList.p[1].py > 0) &&
1125 (connectMap[pList.p[1].px][pList.p[1].py - 1] > 0)) ||
1126 ((pList.p[1].py < maxPoint) &&
1127 (connectMap[pList.p[1].px][pList.p[1].py + 1] > 0))))
1128 if (safeMove(pList.p[1].px, pList.p[1].py))
1129 {
1130 *x = pList.p[1].px;
1131 *y = pList.p[1].py;
1132 return TRUE;
1133 }
1134 if (legal[pList.p[2].px][pList.p[2].py] &&
1135 ((connectMap[pList.p[2].px][pList.p[2].py] > 0) ||
1136 ((pList.p[2].px > 0) &&
1137 (connectMap[pList.p[2].px - 1][pList.p[2].py] > 0)) ||
1138 ((pList.p[2].px < maxPoint) &&
1139 (connectMap[pList.p[2].px + 1][pList.p[2].py] > 0)) ||
1140 ((pList.p[2].py > 0) &&
1141 (connectMap[pList.p[2].px][pList.p[2].py - 1] > 0)) ||
1142 ((pList.p[2].py < maxPoint) &&
1143 (connectMap[pList.p[2].px][pList.p[2].py + 1] > 0))))
1144 if (safeMove(pList.p[2].px, pList.p[2].py))
1145 {
1146 *x = pList.p[2].px;
1147 *y = pList.p[2].py;
1148 return TRUE;
1149 }
1150 }
1151 return FALSE;
1152 } /* atariAnyway */
1153
1154
1155 /*
1156 undercuts his groups
1157 */
1158short underCut(x, y)
1159short *x, *y;
1160 { /* underCut */
1161 short i, j;
1162 playReason = "underCut";
1163 for (i = 1; i <= maxPoint - 1; i++)
1164 {
1165 if (legal[0][i])
1166 {
1167 if (ndbord[1][i] == -1)
1168 if (safeMove(0, i))
1169 {
1170 *x = 0;
1171 *y = i;
1172 return TRUE;
1173 }
1174 }
1175 if (legal[maxPoint][i])
1176 {
1177 if (ndbord[maxPoint - 1][i] == -1)
1178 if (safeMove(maxPoint, i))
1179 {
1180 *x = maxPoint;
1181 *y = i;
1182 return TRUE;
1183 }
1184 }
1185 if (legal[i][0])
1186 {
1187 if (ndbord[i][1] == -1)
1188 if (safeMove(i, 0))
1189 {
1190 *x = i;
1191 *y = 0;
1192 return TRUE;
1193 }
1194 }
1195 if (legal[i][maxPoint])
1196 {
1197 if (ndbord[i][maxPoint - 1] == -1)
1198 if (safeMove(i, maxPoint))
1199 {
1200 *x = i;
1201 *y = maxPoint;
1202 return TRUE;
1203 }
1204 }
1205 }
1206 return FALSE;
1207 } /* underCut */
1208
1209 /*
1210 drops to the edge of the board if threatened
1211 */
1212short dropToEdge(x, y)
1213short *x, *y;
1214 { /* dropToEdge */
1215 short i;
1216 playReason = "dropToEdge";
1217 for (i = 1; i <= maxPoint - 1; i++)
1218 {
1219 if (legal[1][i])
1220 if ((ndbord[2][i] == 1) &&
1221 (ndbord[0][i] == 0) &&
1222 (ndbord[1][i - 1] < 1) &&
1223 (ndbord[1][i + 1] < 1) &&
1224 ((ndbord[2][i - 1] == -1) ||
1225 (ndbord[2][i + 1] == -1) ||
1226 (ndbord[1][i - 1] == -1) ||
1227 (ndbord[1][i + 1] == -1)))
1228 {
1229 *x = 1;
1230 *y = i;
1231 if (safeMove(*x, *y))
1232 return TRUE;
1233 }
1234 if (legal[maxPoint - 1][i])
1235 if ((ndbord[maxPoint - 2][i] == 1) &&
1236 (ndbord[maxPoint][i] == 0) &&
1237 (ndbord[maxPoint - 1][i - 1] < 1) &&
1238 (ndbord[maxPoint - 1][i + 1] < 1) &&
1239 ((ndbord[maxPoint - 2][i - 1] == -1) ||
1240 (ndbord[maxPoint - 2][i + 1] == -1) ||
1241 (ndbord[maxPoint - 1][i - 1] == -1) ||
1242 (ndbord[maxPoint - 1][i + 1] == -1)))
1243 {
1244 *x = maxPoint - 1;
1245 *y = i;
1246 if (safeMove(*x, *y))
1247 return TRUE;
1248 }
1249 if (legal[i][1])
1250 if ((ndbord[i][2] == 1) &&
1251 (ndbord[i][0] == 0) &&
1252 (ndbord[i - 1][1] < 1) &&
1253 (ndbord[i + 1][1] < 1) &&
1254 ((ndbord[i - 1][2] == -1) ||
1255 (ndbord[i + 1][2] == -1) ||
1256 (ndbord[i - 1][1] == -1) ||
1257 (ndbord[i + 1][1] == -1)))
1258 {
1259 *x = i;
1260 *y = 1;
1261 if (safeMove(*x, *y))
1262 return TRUE;
1263 }
1264 if (legal[i][maxPoint - 1])
1265 if ((ndbord[i][maxPoint - 2] == 1) &&
1266 (ndbord[i][maxPoint] == 0) &&
1267 (ndbord[i - 1][maxPoint - 1] < 1) &&
1268 (ndbord[i + 1][maxPoint - 1] < 1) &&
1269 ((ndbord[i - 1][maxPoint - 2] == -1) ||
1270 (ndbord[i + 1][maxPoint - 2] == -1) ||
1271 (ndbord[i - 1][maxPoint - 1] == -1) ||
1272 (ndbord[i + 1][maxPoint - 1] == -1)))
1273 {
1274 *x = i;
1275 *y = maxPoint - 1;
1276 if (safeMove(*x, *y))
1277 return TRUE;
1278 }
1279 if (legal[0][i])
1280 if ((ndbord[1][i] == 1) &&
1281 (ndbord[0][i - 1] < 1) &&
1282 (ndbord[0][i + 1] < 1) &&
1283 (((ndbord[1][i - 1] == -1) &&
1284 (ndbord[1][i + 1] == -1)) ||
1285 (ndbord[0][i - 1] == -1) ||
1286 (ndbord[0][i + 1] == -1)))
1287 {
1288 *x = 0;
1289 *y = i;
1290 if (safeMove(*x, *y))
1291 return TRUE;
1292 }
1293 if (legal[maxPoint][i])
1294 if ((ndbord[maxPoint - 1][i] == 1) &&
1295 (ndbord[maxPoint][i - 1] < 1) &&
1296 (ndbord[maxPoint][i + 1] < 1) &&
1297 (((ndbord[maxPoint - 1][i - 1] == -1) &&
1298 (ndbord[maxPoint - 1][i + 1] == -1)) ||
1299 (ndbord[maxPoint][i - 1] == -1) ||
1300 (ndbord[maxPoint][i + 1] == -1)))
1301 {
1302 *x = maxPoint;
1303 *y = i;
1304 if (safeMove(*x, *y))
1305 return TRUE;
1306 }
1307 if (legal[i][0])
1308 if ((ndbord[i][1] == 1) &&
1309 (ndbord[i - 1][0] < 1) &&
1310 (ndbord[i + 1][0] < 1) &&
1311 (((ndbord[i - 1][1] == -1) &&
1312 (ndbord[i + 1][1] == -1)) ||
1313 (ndbord[i - 1][0] == -1) ||
1314 (ndbord[i + 1][0] == -1)))
1315 {
1316 *x = i;
1317 *y = 0;
1318 if (safeMove(*x, *y))
1319 return TRUE;
1320 }
1321 if (legal[i][maxPoint])
1322 if ((ndbord[i][maxPoint - 1] == 1) &&
1323 (ndbord[i - 1][maxPoint] < 1) &&
1324 (ndbord[i + 1][maxPoint] < 1) &&
1325 (((ndbord[i - 1][maxPoint - 1] == -1) &&
1326 (ndbord[i + 1][maxPoint - 1] == -1)) ||
1327 (ndbord[i - 1][maxPoint] == -1) ||
1328 (ndbord[i + 1][maxPoint] == -1)))
1329 {
1330 *x = i;
1331 *y = maxPoint;
1332 if (safeMove(*x, *y))
1333 return TRUE;
1334 }
1335 }
1336 return FALSE;
1337 } /* dropToEdge */
1338
1339 /*
1340 Pushes walls in a tightly connected fashion.
1341 Finds the lowest influence (mine) point that is connected to one
1342 of my groups.
1343 */
1344short pushWall(x, y)
1345short *x, *y;
1346 { /* pushWall */
1347 short infl, i, j, na;
1348 playReason = "pushWall";
1349 *x = iNil;
1350 *y = iNil;
1351 infl = 11;
1352 for (i = 0; i <= maxPoint; i++)
1353 for (j = 0; j <= maxPoint; j++)
1354 if (legal[i][j])
1355 if (connectMap[i][j] > 0)
1356 if ((claim[i][j] < infl) &&
1357 (((i > 0) && (ndbord[i - 1][j] == 1)) ||
1358 ((i < maxPoint) && (ndbord[i + 1][j] == 1)) ||
1359 ((j > 0) && (ndbord[i][j - 1] == 1)) ||
1360 ((j < maxPoint) && (ndbord[i][j + 1] == 1)) ||
1361 ((i > 0) && (j > 0) && (ndbord[i - 1][j - 1] == 1)) ||
1362 ((i < maxPoint) && (j > 0) && (ndbord[i + 1][j - 1] == 1)) ||
1363 ((i > 0) && (j < maxPoint) && (ndbord[i - 1][j + 1] == 1)) ||
1364 ((i < maxPoint) && (j < maxPoint) &&
1365 (ndbord[i + 1][j + 1] == 1))) &&
1366 (((i > 0) && (claim[i - 1][j] < 0)) ||
1367 ((i < maxPoint) && (claim[i + 1][j] < 0)) ||
1368 ((j > 0) && (claim[i][j - 1] < 0)) ||
1369 ((j < maxPoint) && (claim[i][j + 1] < 0))))
1370 {
1371 na = 0;
1372 if ((i > 0) && (ndbord[i - 1][j] != 0))
1373 na = na + 1;
1374 if ((i < maxPoint) && (ndbord[i + 1][j] != 0))
1375 na = na + 1;
1376 if ((j > 0) && (ndbord[i][j - 1] != 0))
1377 na = na + 1;
1378 if ((j < maxPoint) && (ndbord[i][j + 1] != 0))
1379 na = na + 1;
1380 if (na < 3)
1381 if (safeMove(i, j))
1382 {
1383 infl = claim[i][j];
1384 *x = i;
1385 *y = j;
1386 }
1387 }
1388 if (*x != iNil) return TRUE;
1389 return FALSE;
1390 } /* pushWall */
1391
1392
1393 /*
1394 reduces the liberty count of one of his groups
1395 */
1396short reduceHisLiberties(x, y)
1397short *x, *y;
1398 { /* reduceHisLiberties */
1399 short i, j;
1400 playReason = "reduceHisLiberties";
1401 sortLibs();
1402 for (i = 1; i <= maxGroupID; i++)
1403 if ((! gList[sGlist[i]].isLive) &&
1404 (gList[sGlist[i]].libC > 2) &&
1405 (ndbord[gList[sGlist[i]].lx][gList[sGlist[i]].ly] == -1))
1406 {
1407 spanGroup(gList[sGlist[i]].lx, gList[sGlist[i]].ly, &pList);
1408 for (j = 1; j <= pList.indx; j++)
1409 if (legal[pList.p[j].px][pList.p[j].py] &&
1410 (connectMap[pList.p[j].px][pList.p[j].py] > 0))
1411 if (safeMove(pList.p[j].px, pList.p[j].py))
1412 {
1413 *x = pList.p[j].px;
1414 *y = pList.p[j].py;
1415 return TRUE;
1416 }
1417 }
1418 return FALSE;
1419 } /* reduceHisLiberties */
1420
1421
1422 /*
1423 connects a group to the edge
1424 */
1425short dropToEdge2(x, y)
1426short *x, *y;
1427 { /* dropToEdge2 */
1428 short i;
1429 playReason = "dropToEdge2";
1430 for (i = 1; i <= maxPoint - 1; i++)
1431 {
1432 if (legal[i][0])
1433 {
1434 if ((ndbord[i][1] == 1) &&
1435 ((ndbord[i - 1][0] < 1) ||
1436 (groupIDs[i - 1][0] != groupIDs[i][1])) &&
1437 ((ndbord[i + 1][0] < 1) ||
1438 (groupIDs[i + 1][0] != groupIDs[i][1])) &&
1439 ((ndbord[i - 1][1] == -1) ||
1440 (ndbord[i + 1][1] == -1)))
1441 {
1442 *x = i;
1443 *y = 0;
1444 if (safeMove(*x, *y))
1445 return TRUE;
1446 }
1447 }
1448 if (legal[0][i])
1449 {
1450 if ((ndbord[1][i] == 1) &&
1451 ((ndbord[0][i - 1] < 1) ||
1452 (groupIDs[0][i - 1] != groupIDs[1][i])) &&
1453 ((ndbord[0][i + 1] < 1) ||
1454 (groupIDs[0][i + 1] != groupIDs[1][i])) &&
1455 ((ndbord[1][i - 1] == -1) ||
1456 (ndbord[1][i + 1] == -1)))
1457 {
1458 *x = 0;
1459 *y = i;
1460 if (safeMove(*x, *y))
1461 return TRUE;
1462 }
1463 }
1464 if (legal[i][maxPoint])
1465 {
1466 if ((ndbord[i][maxPoint - 1] == 1) &&
1467 ((ndbord[i - 1][maxPoint] < 1) ||
1468 (groupIDs[i - 1][maxPoint] != groupIDs[i][maxPoint - 1])) &&
1469 ((ndbord[i + 1][maxPoint] < 1) ||
1470 (groupIDs[i + 1][maxPoint] != groupIDs[i][maxPoint - 1])) &&
1471 ((ndbord[i - 1][maxPoint - 1] == -1) ||
1472 (ndbord[i + 1][maxPoint - 1] == -1)))
1473 {
1474 *x = i;
1475 *y = maxPoint;
1476 if (safeMove(*x, *y))
1477 return TRUE;
1478 }
1479 }
1480 if (legal[maxPoint][i])
1481 {
1482 if ((ndbord[maxPoint - 1][i] == 1) &&
1483 ((ndbord[maxPoint][i - 1] < 1) ||
1484 (groupIDs[maxPoint][i - 1] != groupIDs[maxPoint - 1][i])) &&
1485 ((ndbord[maxPoint][i + 1] < 1) ||
1486 (groupIDs[maxPoint][i + 1] != groupIDs[maxPoint - 1][i])) &&
1487 ((ndbord[maxPoint - 1][i - 1] == -1) ||
1488 (ndbord[maxPoint - 1][i + 1] == -1)))
1489 {
1490 *x = maxPoint;
1491 *y = i;
1492 if (safeMove(*x, *y))
1493 return TRUE;
1494 }
1495 }
1496 }
1497 return FALSE;
1498 } /* dropToEdge2 */
1499
diff --git a/noncore/games/go/goplayutils.c b/noncore/games/go/goplayutils.c
new file mode 100644
index 0000000..9e2ce4c
--- a/dev/null
+++ b/noncore/games/go/goplayutils.c
@@ -0,0 +1,1317 @@
1/* The go player utilities */
2/* Ported from Pascal to C by Todd R. Johnson */
3/* From the original Pascal file:
4Copyright (c) 1983 by Three Rivers Computer Corp.
5
6Written: January 17, 1983 by Stoney Ballard
7*/
8
9#include "goplayutils.h"
10#include "amigo.h"
11#include "go.h"
12
13extern struct bRec goboard[19][19];
14
15intBoard claim, extra, bord, ndbord, sGroups, threatBord,
16 groupIDs, connectMap, protPoints;
17boolBoard groupSeen, legal;
18short maxGroupID;
19pointList pList, pList1, plist2, plist3, pPlist;
20intList nlcGroup, aList;
21sgRec sList[401];
22groupRec gList[maxGroup];
23short killFlag,
24 numCapt,
25 utilPlayLevel,
26 treeLibLim;
27sType mySType;
28short showTrees;
29short sGlist[maxGroup+1];
30short depthLimit;
31intBoard markBoard;
32short marker;
33
34short adjInAtari, adj2Libs,
35 intersectNum, spanNum, libMark;
36playRec playStack[1025];
37short playMark,
38 newGID,
39 tryLevel,
40 grpMark,
41 gMap[maxGroup];
42short dbStop, inGenState;
43
44 pause()
45{ /* pause */
46/* if (dbStop and ! inGenState)
47 {
48 while ! tabswitch do;
49 repeat
50 if (tabYellow)
51 dbStop = false;
52 until ! tabswitch;
53 } */
54} /* pause */
55
56sstone(w, x, y, numb)
57short w, x, y, numb;
58{ /* sstone */
59 if (w == 1)
60 placestone(mySType, x, y);
61 else if (mySType == WHITE)
62 placestone(BLACK, x, y);
63 else
64 placestone(WHITE, x, y);
65} /* sstone */
66
67rstone(x, y)
68short x, y;
69{ /* rstone */
70 removestone(x, y);
71} /* rstone */
72
73initBoolBoard(bb)
74boolBoard bb;
75{ /* initBoolBoard */
76 short i, j;
77#ifdef DEBUG
78 printf( "initBoolBoard\n" );
79#endif
80 for (i = 0; i <= maxPoint; i++)
81 for (j = 0; j <= maxPoint; j++)
82 bb[i][j] = FALSE;
83} /* initBoolBoard */
84
85sortLibs()
86{ /* sortLibs */
87 short i, j, t;
88#ifdef DEBUG
89 printf( "sortLibs\n" );
90#endif
91 for (i = 1; i <= maxGroupID; i++)
92 sGlist[i] = i;
93 for (i = 1; i < maxGroupID; i++)
94 for (j = i + 1; j <= maxGroupID; j++)
95 if (gList[sGlist[i]].libC > gList[sGlist[j]].libC)
96 {
97 t = sGlist[i];
98 sGlist[i] = sGlist[j];
99 sGlist[j] = t;
100 }
101} /* sortLibs */
102
103spanGroupspan(x, y, libs, lookFor)
104short x, y, lookFor;
105pointList *libs;
106 { /* span */
107 markBoard[x][y] = marker;
108 if (bord[x][y] == 0)
109 {
110 libs->indx = libs->indx + 1;
111 libs->p[libs->indx].px = x;
112 libs->p[libs->indx].py = y;
113 }
114 else if (bord[x][y] == lookFor)
115 {
116 groupSeen[x][y] = TRUE;
117 if ((x > 0) && (markBoard[x - 1][y] != marker))
118 spanGroupspan(x - 1, y, libs, lookFor);
119 if ((y > 0) && (markBoard[x][y - 1] != marker))
120 spanGroupspan(x, y - 1, libs, lookFor);
121 if ((x < maxPoint) && (markBoard[x + 1][y] != marker))
122 spanGroupspan(x + 1, y, libs, lookFor);
123 if ((y < maxPoint) && (markBoard[x][y + 1] != marker))
124 spanGroupspan(x, y + 1, libs, lookFor);
125 }
126 else if (gList[gMap[groupIDs[x][y]]].libC == 1)
127 adjInAtari = TRUE;
128 else if ((gList[gMap[groupIDs[x][y]]].libC == 2) &&
129 (! gList[gMap[groupIDs[x][y]]].isLive))
130 adj2Libs = TRUE;
131 } /* span */
132
133spanGroup(x, y, libs)
134short x, y;
135pointList *libs;
136{ /* spanGroup */
137 short lookFor;
138#ifdef DEBUG
139 printf( "spanGroup\n" );
140#endif
141 marker = marker + 1;
142 if (marker == 0)
143 {
144 initArray(markBoard);
145 marker = 1;
146 }
147 adjInAtari = FALSE;
148 adj2Libs = FALSE;
149 lookFor = bord[x][y];
150 libs->indx = 0;
151 spanGroupspan(x, y, libs, lookFor);
152} /* spanGroup */
153
154sSpanGroupspan(x, y, libs, lookFor)
155short x, y, lookFor;
156sPointList *libs;
157 { /* span */
158 markBoard[x][y] = marker;
159 if (bord[x][y] == 0)
160 {
161 libs->indx += 1;
162 if (libs->indx <= maxSPoint)
163 {
164 libs->p[libs->indx].px = x;
165 libs->p[libs->indx].py = y;
166 }
167 }
168 else if (bord[x][y] == lookFor)
169 {
170 groupSeen[x][y] = TRUE;
171 if ((x > 0) && (markBoard[x - 1][y] != marker))
172 sSpanGroupspan(x - 1, y, libs, lookFor);
173 if ((y > 0) && (markBoard[x][y - 1] != marker))
174 sSpanGroupspan(x, y - 1, libs, lookFor);
175 if ((x < maxPoint) && (markBoard[x + 1][y] != marker))
176 sSpanGroupspan(x + 1, y, libs, lookFor);
177 if ((y < maxPoint) && (markBoard[x][y + 1] != marker))
178 sSpanGroupspan(x, y + 1, libs, lookFor);
179 }
180 else if (gList[gMap[groupIDs[x][y]]].libC == 1)
181 adjInAtari = TRUE;
182 else if ((gList[gMap[groupIDs[x][y]]].libC == 2) &&
183 (! gList[gMap[groupIDs[x][y]]].isLive))
184 adj2Libs = TRUE;
185 } /* span */
186
187sSpanGroup(x, y, libs)
188short x, y;
189sPointList *libs;
190{ /* sSpanGroup */
191 short lookFor;
192#ifdef DEBUG
193 printf( "sSpanGroup\n" );
194#endif
195 marker = marker + 1;
196 if (marker == 0)
197 {
198 initArray(markBoard);
199 marker = 1;
200 }
201 adjInAtari = FALSE;
202 adj2Libs = FALSE;
203 lookFor = bord[x][y];
204 libs->indx = 0;
205 sSpanGroupspan(x, y, libs, lookFor);
206} /* sSpanGroup */
207
208LAspan(x, y, me, him, iL)
209short x, y, me, him;
210intList *iL;
211 { /* span */
212#ifdef DEBUG
213 printf( "LAspan\n" );
214#endif
215 markBoard[x][y] = marker;
216 if (bord[x][y] == me)
217 {
218 if ((x > 0) && (markBoard[x - 1][y] != marker))
219 LAspan(x - 1, y, me, him, iL);
220 if ((x < maxPoint) && (markBoard[x + 1][y] != marker))
221 LAspan(x + 1, y, me, him, iL);
222 if ((y > 0) && (markBoard[x][y - 1] != marker))
223 LAspan(x, y - 1, me, him, iL);
224 if ((y < maxPoint) && (markBoard[x][y + 1] != marker))
225 LAspan(x, y + 1, me, him, iL);
226 }
227 else if (bord[x][y] == him)
228 if (gList[gMap[groupIDs[x][y]]].groupMark != grpMark)
229 {
230 gList[gMap[groupIDs[x][y]]].groupMark = grpMark;
231 iL->indx = iL->indx + 1;
232 iL->v[iL->indx] = gMap[groupIDs[x][y]];
233 }
234 } /* span */
235
236listAdjacents(x, y, iL)
237short x, y;
238intList *iL;
239{ /* listAdjacents */
240 short me, him;
241#ifdef DEBUG
242 printf( "listAdjacents\n" );
243#endif
244 grpMark = grpMark + 1;
245 marker = marker + 1;
246 if (marker == 0)
247 {
248 initArray(markBoard);
249 marker = 1;
250 }
251 iL->indx = 0;
252 me = bord[x][y];
253 him = -me;
254 LAspan(x, y, me , him, iL);
255} /* listAdjacents */
256
257LDspan(x, y, me, diags)
258short x, y, me;
259sPointList *diags;
260 { /* span */
261#ifdef DEBUG
262 printf( "LDspan\n" );
263#endif
264 markBoard[x][y] = marker;
265 if ((x > 0) && (y > 0) &&
266 (bord[x - 1][y - 1] == 0) &&
267 (bord[x][y - 1] != me) &&
268 (bord[x - 1][y] != me) &&
269 (markBoard[x - 1][y - 1] != marker))
270 {
271 markBoard[x - 1][y - 1] = marker;
272 diags->indx = diags->indx + 1;
273 if (diags->indx <= maxSPoint)
274 {
275 diags->p[diags->indx].px = x - 1;
276 diags->p[diags->indx].py = y - 1;
277 }
278 }
279 if ((x < maxPoint) && (y > 0) &&
280 (bord[x + 1][y - 1] == 0) &&
281 (bord[x][y - 1] != me) &&
282 (bord[x + 1][y] != me) &&
283 (markBoard[x + 1][y - 1] != marker))
284 {
285 markBoard[x + 1][y - 1] = marker;
286 diags->indx = diags->indx + 1;
287 if (diags->indx <= maxSPoint)
288 {
289 diags->p[diags->indx].px = x + 1;
290 diags->p[diags->indx].py = y - 1;
291 }
292 }
293 if ((x > 0) && (y < maxPoint) &&
294 (bord[x - 1][y + 1] == 0) &&
295 (bord[x][y + 1] != me) &&
296 (bord[x - 1][y] != me) &&
297 (markBoard[x - 1][y + 1] != marker))
298 {
299 markBoard[x - 1][y + 1] = marker;
300 diags->indx = diags->indx + 1;
301 if (diags->indx <= maxSPoint)
302 {
303 diags->p[diags->indx].px = x - 1;
304 diags->p[diags->indx].py = y + 1;
305 }
306 }
307 if ((x < maxPoint) && (y < maxPoint) &&
308 (bord[x + 1][y + 1] == 0) &&
309 (bord[x][y + 1] != me) &&
310 (bord[x + 1][y] != me) &&
311 (markBoard[x + 1][y + 1] != marker))
312 {
313 markBoard[x + 1][y + 1] = marker;
314 diags->indx = diags->indx + 1;
315 if (diags->indx <= maxSPoint)
316 {
317 diags->p[diags->indx].px = x + 1;
318 diags->p[diags->indx].py = y + 1;
319 }
320 }
321 if ((x > 0) && (bord[x - 1][y] == me) &&
322 (markBoard[x - 1][y] != marker))
323 LDspan(x - 1, y, me, diags);
324 if ((x < maxPoint) && (bord[x + 1][y] == me) &&
325 (markBoard[x + 1][y] != marker))
326 LDspan(x + 1, y, me, diags);
327 if ((y > 0) && (bord[x][y - 1] == me) &&
328 (markBoard[x][y - 1] != marker))
329 LDspan(x, y - 1, me, diags);
330 if ((y < maxPoint) && (bord[x][y + 1] == me) &&
331 (markBoard[x][y + 1] != marker))
332 LDspan(x, y + 1, me , diags);
333} /* span */
334
335listDiags(x, y, diags)
336short x, y;
337sPointList *diags;
338{ /* listDiags */
339 short me;
340#ifdef DEBUG
341 printf( "listDiags\n" );
342#endif
343 me = bord[x][y];
344 diags->indx = 0;
345 marker = marker + 1;
346 if (marker == 0)
347 {
348 initArray(markBoard);
349 marker = 1;
350 }
351 LDspan(x, y, me, diags);
352} /* listDiags */
353
354intersectPlist(p1, p2, pr)
355pointList *p1, *p2, *pr;
356{ /* intersectPlist */
357 short i, j, k;
358#ifdef DEBUG
359 printf( "intersectPlist\n" );
360#endif
361 marker = marker + 1;
362 if (marker == 0)
363 {
364 initArray(markBoard);
365 marker = 1;
366 }
367 pr->indx = 0;
368 for (i = 1; i <= p1->indx; i++)
369 markBoard[p1->p[i].px][p1->p[i].py] = marker;
370 j = 0;
371 for (i = 1; i <= p2->indx; i++)
372 if (markBoard[p2->p[i].px][p2->p[i].py] == marker)
373 {
374 j = j + 1;
375 pr->p[j] = p2->p[i];
376 }
377 pr->indx = j;
378} /* intersectPlist */
379
380initArray(ary)
381intBoard ary;
382{ /* initArray */
383 short i, j;
384 for (i = 0; i <= maxPoint; i++)
385 for (j = 0; j <= maxPoint; j++)
386 ary[i][j] = 0;
387} /* initArray */
388
389initState()
390{ /* initState */
391 short i, j;
392 for (i = 0; i <= maxPoint; i++)
393 for (j = 0; j <= maxPoint; j++)
394 {
395 extra[i][j] = 0;
396 claim[i][j] = 0;
397 groupIDs[i][j] = 0;
398 connectMap[i][j] = 0;
399 protPoints[i][j] = 0;
400 }
401} /* initState */
402
403copyArray( dest, src )
404intBoard dest, src;
405{
406 short x, y;
407 for (y = 0; y <= maxPoint; y++)
408 for (x = 0; x <= maxPoint; x++)
409 dest[x][y] = src[x][y];
410}
411
412/*
413 generates a one-point spread in the force field array (claim)
414
415 the spread from a single point after four calls is:
416
417 1
418 2 2 2
419 2 4 6 4 2
420 2 4 8 10 8 4 2
421 1 2 6 10 62 10 6 2 1
422 2 4 8 10 8 4 2
423 2 4 6 4 2
424 2 2 2
425 1
426
427*/
428stake()
429{
430 short x, y;
431 initArray( extra );
432 for (y = 0; y <= maxPoint; y++)
433 for (x = 0; x <= maxPoint; x++)
434 {
435 extra[x][y] = extra[x][y] + claim[x][y];
436 if (claim[x][y] > 0)
437 {
438 if (x > 0) extra[x-1][y] += 1;
439 if (y > 0) extra[x][y-1] += 1;
440 if (x < maxPoint) extra[x+1][y] += 1;
441 if (y < maxPoint) extra[x][y+1] += 1;
442 }
443 else if (claim[x][y] < 0)
444 {
445 if (x > 0) extra[x-1][y] -= 1;
446 if (y > 0) extra[x][y-1] -= 1;
447 if (x < maxPoint) extra[x+1][y] -= 1;
448 if (y < maxPoint) extra[x][y+1] -= 1;
449 }
450 }
451 copyArray( claim, extra );
452} /* stake */
453
454/*
455 sets up claim from the current board position
456*/
457spread()
458{
459 short x, y;
460 for (y = 0; y <= maxPoint; y++)
461 for (x = 0; x <= maxPoint; x++)
462 claim[x][y] = ndbord[x][y] * 50;
463 stake();
464 stake();
465 stake();
466 stake();
467} /* spread */
468
469/*
470 gList is initialized with the size, loc, and libCount of each group
471 groupIDs contains the serial numbers of the groups.
472*/
473Resspan(x, y, gID, gSize, libCount, who)
474short x, y, gID, *gSize, *libCount, who;
475 { /* span */
476 if ((bord[x][y] == 0) &&
477 (markBoard[x][y] != marker)) /* a liberty */
478 {
479 markBoard[x][y] = marker;
480 *libCount = *libCount + 1;
481 }
482 else if ((bord[x][y] == who) &&
483 (groupIDs[x][y] == 0))
484 {
485 groupIDs[x][y] = gID;
486 *gSize = *gSize + 1;
487 if (x > 0)
488 Resspan(x - 1, y, gID, gSize, libCount, who);
489 if (x < maxPoint)
490 Resspan(x + 1, y, gID, gSize, libCount, who);
491 if (y > 0)
492 Resspan(x, y - 1, gID, gSize, libCount, who);
493 if (y < maxPoint)
494 Resspan(x, y + 1, gID, gSize, libCount, who);
495 }
496 } /* span */
497
498respreicen()
499{ /* respreicen */
500 short i, j, gID, libCount, gSize, who;
501 gID = 0;
502#ifdef DEBUG
503 printf( "respreicen\n" );
504#endif
505 for (i = 0; i <= maxPoint; i++)
506 for (j = 0; j <= maxPoint; j++)
507 groupIDs[i][j] = 0;
508 for (i = 0; i <= maxPoint; i++)
509 for (j = 0; j <= maxPoint; j++)
510 if ((bord[i][j] != 0) && /* a stone there */
511 (groupIDs[i][j] == 0)) /* not seen yet */
512 {
513 marker = marker + 1;
514 if (marker == 0)
515 {
516 initArray(markBoard);
517 marker = 1;
518 }
519 gID = gID + 1;
520 libCount = 0;
521 gSize = 0;
522 who = bord[i][j];
523 Resspan(i, j, gID, &gSize, &libCount, who); /* span the group, collecting info */
524 gList[gID].groupMark = 0;
525 gList[gID].atLevel = 0;
526 gList[gID].isLive = FALSE; /* we don't know yet */
527 gList[gID].isDead = FALSE;
528 gList[gID].numEyes = -1;
529 gList[gID].size = gSize;
530 gList[gID].libC = libCount;
531 gList[gID].lx = i;
532 gList[gID].ly = j;
533 gMap[gID] = gID; /* set up identity map */
534 }
535 maxGroupID = gID;
536 newGID = gID;
537 grpMark = 0;
538} /* respreicen */
539
540/*
541 play z at [x, y].
542 killFlag is set true if anything is killed.
543*/
544killGroup(x, y, me, him)
545short x, y, me, him;
546 { /* killGroup */
547#ifdef DEBUG
548 printf( "killGroup\n" );
549#endif
550 playMark = playMark + 1;
551 /* record this kill */
552 playStack[playMark].kind = rem;
553 playStack[playMark].uval.rem.who = him;
554 playStack[playMark].uval.rem.xl = x;
555 playStack[playMark].uval.rem.yl = y;
556 playStack[playMark].gID = groupIDs[x][y];
557 playStack[playMark].uval.rem.sNumber = goboard[x][y].mNum;
558 if (showTrees)
559 rstone(x, y);
560 numCapt = numCapt + 1;
561 bord[x][y] = 0;
562 groupIDs[x][y] = 0;
563 if (x > 0)
564 {
565 if (bord[x - 1][y] == me)
566 {
567 nlcGroup.indx = nlcGroup.indx + 1;
568 nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x - 1][y]];
569 }
570 else if (bord[x - 1][y] == him)
571 killGroup(x - 1, y, me , him);
572 }
573 if (x < maxPoint)
574 {
575 if (bord[x + 1][y] == me)
576 {
577 nlcGroup.indx = nlcGroup.indx + 1;
578 nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x + 1][y]];
579 }
580 else if (bord[x + 1][y] == him)
581 killGroup(x + 1, y, me, him);
582 }
583 if (y > 0)
584 {
585 if (bord[x][y - 1] == me)
586 {
587 nlcGroup.indx = nlcGroup.indx + 1;
588 nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x][y - 1]];
589 }
590 else if (bord[x][y - 1] == him)
591 killGroup(x, y - 1, me, him);
592 }
593 if (y < maxPoint)
594 {
595 if (bord[x][y + 1] == me)
596 {
597 nlcGroup.indx = nlcGroup.indx + 1;
598 nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x][y + 1]];
599 }
600 else if (bord[x][y + 1] == him)
601 killGroup(x, y + 1, me, him);
602 }
603 } /* killGroup */
604
605mergeGroup(sGID, myGID)
606short sGID, myGID;
607 { /* mergeGroup */
608 short i;
609#ifdef DEBUG
610 printf( "mergeGroup\n" );
611#endif
612 for (i = 1; i <= newGID; i++)
613 if (gMap[i] == sGID)
614 {
615 playMark = playMark + 1;
616 playStack[playMark].kind = reMap;
617 playStack[playMark].gID = i;
618 playStack[playMark].uval.reMap.oldGID = sGID;
619 gMap[i] = myGID;
620 }
621 } /* mergeGroup */
622
623tryPlay(x, y, z)
624short x, y, z;
625{ /* plei */
626 short i, me, him, myGID;
627 short isNew;
628#ifdef DEBUG
629 printf( "tryPlay\n" );
630#endif
631 me = z;
632 him = -me;
633 killFlag = FALSE; /* set true if something is killed */
634 numCapt = 0;
635 tryLevel = tryLevel + 1;
636 isNew = FALSE;
637 bord[x][y] = z; /* play the stone */
638 if ((x > 0) && (bord[x - 1][y] == me)) /* connect to adjacent group */
639 myGID = gMap[groupIDs[x - 1][y]];
640 else if ((x < maxPoint) && (bord[x + 1][y] == me))
641 myGID = gMap[groupIDs[x + 1][y]];
642 else if ((y > 0) && (bord[x][y - 1] == me))
643 myGID = gMap[groupIDs[x][y - 1]];
644 else if ((y < maxPoint) && (bord[x][y + 1] == me))
645 myGID = gMap[groupIDs[x][y + 1]];
646 else /* nobody to connect to */
647 {
648 newGID = newGID + 1;
649 isNew = TRUE;
650 myGID = newGID;
651 gList[myGID].groupMark = 0;
652 gList[myGID].atLevel = tryLevel;
653 gList[myGID].isLive = FALSE;
654 gList[myGID].numEyes = -1;
655 gList[myGID].size = -1;
656 gList[myGID].lx = x;
657 gList[myGID].ly = y;
658 gMap[myGID] = myGID;
659 }
660 groupIDs[x][y] = myGID;
661 playMark = playMark + 1;
662 /* record this move */
663 playStack[playMark].kind = add;
664 playStack[playMark].uval.add.who = me;
665 playStack[playMark].uval.add.xl = x;
666 playStack[playMark].uval.add.yl = y;
667 playStack[playMark].gID = myGID;
668 playStack[playMark].uval.add.sNumber = 0;
669 if (isNew)
670 playStack[playMark].uval.add.nextGID = newGID - 1;
671 else
672 playStack[playMark].uval.add.nextGID = newGID;
673 if (showTrees)
674 sstone(me, x, y, 0);
675 /* merge adjacent groups */
676 if ((x > 0) && (bord[x - 1][y] == me) &&
677 (gMap[groupIDs[x - 1][y]] != myGID))
678 mergeGroup(gMap[groupIDs[x - 1][y]], myGID);
679 if ((x < maxPoint) && (bord[x + 1][y] == me) &&
680 (gMap[groupIDs[x + 1][y]] != myGID))
681 mergeGroup(gMap[groupIDs[x + 1][y]], myGID);
682 if ((y > 0) && (bord[x][y - 1] == me) &&
683 (gMap[groupIDs[x][y - 1]] != myGID))
684 mergeGroup(gMap[groupIDs[x][y - 1]], myGID);
685 if ((y < maxPoint) && (bord[x][y + 1] == me) &&
686 (gMap[groupIDs[x][y + 1]] != myGID))
687 mergeGroup(gMap[groupIDs[x][y + 1]], myGID);
688 /* kill opposing groups, listing affected groups */
689 nlcGroup.indx = 1;
690 nlcGroup.v[1] = myGID; /* init list to include me */
691 if ((x > 0) && (bord[x - 1][y] == him) &&
692 (gList[gMap[groupIDs[x - 1][y]]].libC == 1))
693 {
694 killFlag = TRUE;
695 killGroup(x - 1, y, me, him);
696 }
697 if ((x < maxPoint) && (bord[x + 1][y] == him) &&
698 (gList[gMap[groupIDs[x + 1][y]]].libC == 1))
699 {
700 killFlag = TRUE;
701 killGroup(x + 1, y, me, him);
702 }
703 if ((y > 0) && (bord[x][y - 1] == him) &&
704 (gList[gMap[groupIDs[x][y - 1]]].libC == 1))
705 {
706 killFlag = TRUE;
707 killGroup(x, y - 1, me, him);
708 }
709 if ((y < maxPoint) && (bord[x][y + 1] == him) &&
710 (gList[gMap[groupIDs[x][y + 1]]].libC == 1))
711 {
712 killFlag = TRUE;
713 killGroup(x, y + 1, me, him);
714 }
715 /* list groups adjacent to me */
716 if ((x > 0) && (bord[x - 1][y] == him))
717 {
718 nlcGroup.indx = nlcGroup.indx + 1;
719 nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x - 1][y]];
720 }
721 if ((x < maxPoint) && (bord[x + 1][y] == him))
722 {
723 nlcGroup.indx = nlcGroup.indx + 1;
724 nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x + 1][y]];
725 }
726 if ((y > 0) && (bord[x][y - 1] == him))
727 {
728 nlcGroup.indx = nlcGroup.indx + 1;
729 nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x][y - 1]];
730 }
731 if ((y < maxPoint) && (bord[x][y + 1] == him))
732 {
733 nlcGroup.indx = nlcGroup.indx + 1;
734 nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x][y + 1]];
735 }
736 /* fix liberty count for affected groups */
737 grpMark = grpMark + 1;
738 for (i = 1; i <= nlcGroup.indx; i++)
739 if (gList[nlcGroup.v[i]].groupMark != grpMark)
740 {
741 if (gList[nlcGroup.v[i]].atLevel != tryLevel)
742 {
743 playMark = playMark + 1;
744 playStack[playMark].kind = chLib;
745 playStack[playMark].gID = nlcGroup.v[i];
746 playStack[playMark].uval.chLib.oldLevel =
747 gList[nlcGroup.v[i]].atLevel;
748 playStack[playMark].uval.chLib.oldLC =
749 gList[nlcGroup.v[i]].libC;
750 }
751 gList[nlcGroup.v[i]].groupMark = grpMark;
752 gList[nlcGroup.v[i]].atLevel = tryLevel;
753 spanGroup(gList[nlcGroup.v[i]].lx, gList[nlcGroup.v[i]].ly, &pPlist);
754 gList[nlcGroup.v[i]].libC = pPlist.indx;
755 }
756} /* plei */
757
758saveState()
759{ /* saveState */
760 playMark = 0;
761 tryLevel = 0;
762 newGID = maxGroupID;
763} /* saveState */
764
765/*
766 undoes a move sequence back to uMark
767*/
768undoTo(uMark)
769short uMark;
770{ /* undoTo */
771 short i, xl, yl;
772#ifdef DEBUG
773 printf( "undoTo\n" );
774#endif
775 for (i = playMark; i >= uMark + 1; i--)
776 if (playStack[i].kind == rem)
777 {
778 xl = playStack[i].uval.rem.xl;
779 yl = playStack[i].uval.rem.yl;
780 bord[xl][yl] = playStack[i].uval.rem.who;
781 groupIDs[xl][yl] = playStack[i].gID;
782 if (showTrees)
783 sstone(playStack[i].uval.rem.who, xl, yl,
784 playStack[i].uval.rem.sNumber);
785 }
786 else if (playStack[i].kind == add)
787 {
788 xl = playStack[i].uval.add.xl;
789 yl = playStack[i].uval.add.yl;
790 bord[xl][yl] = 0;
791 groupIDs[xl][yl] = 0;
792 tryLevel = tryLevel - 1;
793 newGID = playStack[i].uval.add.nextGID;
794 if (showTrees)
795 rstone(xl, yl);
796 }
797 else if (playStack[i].kind == reMap)
798 gMap[playStack[i].gID] = playStack[i].uval.reMap.oldGID;
799 else /* change libs of group - gID is pre-mapped */
800 {
801 gList[playStack[i].gID].libC = playStack[i].uval.chLib.oldLC;
802 gList[playStack[i].gID].atLevel = playStack[i].uval.chLib.oldLevel;
803 }
804 playMark = uMark;
805} /* undoTo */
806
807/*
808 restores the state of the world after trying a move sequence
809*/
810restoreState()
811{ /* restoreState */
812#ifdef DEBUG
813 printf( "restoreState\n" );
814#endif
815 if (playMark > 0)
816 {
817 undoTo(0);
818 playMark = 0;
819 tryLevel = 0;
820 }
821} /* restoreState */
822
823/* exception bpt; */
824
825
826/*
827 returns true if (the group (at gx, gy) is saveable.
828 if so, returns the point to play at in savex, savey
829*/
830short saveable(gx, gy, savex, savey)
831short gx, gy, *savex, *savey;
832{ /* saveable */
833 short me, him, gx1, gx2, i, j, smark, mark2, tl, result;
834 char sChar;
835 sPointList dList;
836 point tp;
837 short libList[maxSPoint+1];
838#ifdef DEBUG
839 printf( "saveable\n" );
840#endif
841 dbStop = TRUE;
842 me = bord[gx][gy];
843 him = -me;
844 if (me == 1)
845 sChar = '|';
846 else
847 sChar = '>';
848/* write(sChar); */
849 spanGroup(gx, gy, &plist3); /* find my liberties */
850 if (adjInAtari) /* one of my options is to kill */
851 {
852 listAdjacents(gx, gy, &aList);
853 for (i = 1; i <= aList.indx; i++)
854 if (gList[aList.v[i]].libC == 1)
855 {
856 spanGroup(gList[aList.v[i]].lx, gList[aList.v[i]].ly,
857 &pList1); /* find it's liberty */
858 plist3.indx = plist3.indx + 1;
859 plist3.p[plist3.indx].px = pList1.p[1].px;
860 plist3.p[plist3.indx].py = pList1.p[1].py;
861 }
862 }
863 for (i = 1; i <= maxSPoint; i++)
864 libList[i] = -1;
865 if ((utilPlayLevel > 4) &&
866 (gList[gMap[groupIDs[gx][gy]]].libC > 1)) /* account for diags */
867 {
868 listDiags(gx, gy, &dList);
869 j = 0;
870 i = plist3.indx;
871 while ((j < dList.indx) &&
872 (i < maxSPoint))
873 {
874 j = j + 1;
875 i = i + 1;
876 libList[i] = 100;
877 plist3.p[i].px = dList.p[j].px;
878 plist3.p[i].py = dList.p[j].py;
879 }
880 plist3.indx = i;
881 }
882 if (plist3.indx > 1) /* sort by decreasing lib count */
883 {
884 for (i = 1; i <= plist3.indx; i++)
885 if (libList[i] != 100)
886 {
887 mark2 = playMark;
888 tryPlay(plist3.p[i].px, plist3.p[i].py, me);
889 libList[i] = gList[gMap[groupIDs[gx][gy]]].libC;
890 if (libList[i] > treeLibLim) /* i'm safe */
891 {
892 *savex = plist3.p[i].px;
893 *savey = plist3.p[i].py;
894 result = TRUE;
895 goto one;
896 }
897 undoTo(mark2);
898 }
899 for (i = 1; i <= plist3.indx - 1; i++)
900 for (j = i + 1; j <= plist3.indx; j++)
901 if (libList[i] < libList[j])
902 {
903 tl = libList[i];
904 libList[i] = libList[j];
905 libList[j] = tl;
906 tp = plist3.p[i];
907 plist3.p[i] = plist3.p[j];
908 plist3.p[j] = tp;
909 }
910 }
911 for (i = 1; i <= plist3.indx; i++)
912 {
913 *savex = plist3.p[i].px;
914 *savey = plist3.p[i].py;
915 if (legal[*savex][*savey])
916 {
917 smark = playMark;
918 tryPlay(*savex, *savey, me);
919 pause();
920 if (gList[gMap[groupIDs[*savex][*savey]]].libC > 1)
921 if (gList[gMap[groupIDs[gx][gy]]].libC > treeLibLim)
922 {
923 restoreState();
924/* sClearChar(sChar, rXor); */
925 return TRUE;
926 }
927 else if (gList[gMap[groupIDs[gx][gy]]].libC > 1)
928 if (! killable(gx, gy, &gx1, &gx2))
929 {
930 restoreState();
931/* sClearChar(sChar, rXor); */
932 return TRUE;
933 }
934 undoTo(smark);
935 }
936 }
937 result = FALSE;
938one:
939 restoreState();
940/* sClearChar(sChar, rXor); */
941 return result;
942} /* saveable */
943
944/*
945 marks unsavable groups as dead
946*/
947markDead()
948{ /* markDead */
949 short i, j, gx, gy, result;
950#ifdef DEBUG
951 printf( "markDead\n" );
952#endif
953 for (i = 1; i <= maxGroupID; i++)
954 if (killable(gList[i].lx, gList[i].ly, &gx, &gy))
955 result = ! saveable(gList[i].lx, gList[i].ly, &gx, &gy);
956 else
957 result = FALSE;
958 for (i = 0; i <= maxPoint; i++)
959 for (j = 0; j <= maxPoint; j++)
960 if (bord[i][j] == 0)
961 ndbord[i][j] = 0;
962 else if (gList[groupIDs[i][j]].isDead)
963 ndbord[i][j] = 0;
964 else
965 ndbord[i][j] = bord[i][j];
966} /* markDead */
967
968/*
969 marks groups with two eyes as live
970*/
971MLspan(x, y, saw1, sawm1, size, sMark)
972short x, y, *saw1, *sawm1, *size, sMark;
973 { /* span */
974 if (ndbord[x][y] == 1)
975 *saw1 = TRUE;
976 else if (ndbord[x][y] == -1)
977 *sawm1 = TRUE;
978 else if (sGroups[x][y] == 0)
979 {
980 sGroups[x][y] = sMark;
981 *size = *size + 1;
982 if (x > 0)
983 MLspan(x - 1, y, saw1, sawm1, size, sMark);
984 if (x < maxPoint)
985 MLspan(x + 1, y, saw1, sawm1, size, sMark);
986 if (y > 0)
987 MLspan(x, y - 1, saw1, sawm1, size, sMark);
988 if (y < maxPoint)
989 MLspan(x, y + 1, saw1, sawm1, size, sMark);
990 }
991 } /* span */
992
993short CLspan(x, y, numEyes, who)
994short x, y, *numEyes, who;
995 { /* span */
996 markBoard[x][y] = marker;
997 if (ndbord[x][y] == 0)
998 {
999 if ((sList[sGroups[x][y]].sm != marker) &&
1000 (sList[sGroups[x][y]].w == who))
1001 {
1002 sList[sGroups[x][y]].sm = marker;
1003 if (sList[sGroups[x][y]].s > 6)
1004 return TRUE;
1005 *numEyes = *numEyes + 1;
1006 if (*numEyes > 1)
1007 return TRUE;
1008 }
1009 }
1010 else if (bord[x][y] == who)
1011 {
1012 if ((x > 0) &&
1013 (markBoard[x - 1][y] != marker))
1014 if (CLspan(x - 1, y, numEyes, who)) return TRUE;
1015 if ((x < maxPoint) &&
1016 (markBoard[x + 1][y] != marker))
1017 if (CLspan(x + 1, y, numEyes, who)) return TRUE;
1018 if ((y > 0) &&
1019 (markBoard[x][y - 1] != marker))
1020 if (CLspan(x, y - 1, numEyes, who)) return TRUE;
1021 if ((y < maxPoint) &&
1022 (markBoard[x][y + 1] != marker))
1023 if (CLspan(x, y + 1, numEyes, who)) return TRUE;
1024 }
1025 return FALSE;
1026 } /* span */
1027
1028short checkLive(x, y)
1029short x, y;
1030 { /* checkLive */
1031 short numEyes, who;
1032#ifdef DEBUG
1033 printf( "checkLive\n" );
1034#endif
1035 numEyes = 0;
1036 who = bord[x][y];
1037 marker = marker + 1;
1038 return CLspan(x, y, &numEyes, who);
1039 } /* checkLive */
1040
1041markLive()
1042{ /* markLive */
1043 short i, j, size, sMark = 0;
1044 short saw1, sawm1;
1045#ifdef DEBUG
1046 printf( "markLive\n" );
1047#endif
1048 initArray(sGroups);
1049 for (i = 0; i <= maxPoint; i++)
1050 for (j = 0; j <= maxPoint; j++)
1051 if ((sGroups[i][j] == 0) &&
1052 (ndbord[i][j] == 0))
1053 {
1054 size = 0;
1055 sMark = sMark + 1;
1056 sawm1 = FALSE;
1057 saw1 = FALSE;
1058 MLspan(i, j, &saw1, &sawm1, &size, sMark);
1059 sList[sMark].s = size;
1060 sList[sMark].sm = 0;
1061 if (sawm1)
1062 if (saw1)
1063 sList[sMark].w = 0;
1064 else
1065 sList[sMark].w = -1;
1066 else if (saw1)
1067 sList[sMark].w = 1;
1068 else
1069 sList[sMark].w = 0;
1070 }
1071 for (i = 1; i <= maxGroupID; i++)
1072 if (! gList[i].isDead)
1073 gList[i].isLive = checkLive(gList[i].lx, gList[i].ly);
1074} /* markLive */
1075
1076/*
1077 generates the connection map and the protected point map.
1078*/
1079genConnects()
1080{ /* genConnects */
1081 short x, y, numStones;
1082#ifdef DEBUG
1083 printf( "genConnects\n" );
1084#endif
1085 for (x = 0; x <= maxPoint; x++)
1086 for (y = 0; y <= maxPoint; y++)
1087 {
1088 connectMap[x][y] = 0;
1089 protPoints[x][y] = 0;
1090 }
1091 for (x = 0; x <= maxPoint; x++)
1092 for (y = 0; y <= maxPoint; y++)
1093 if (bord[x][y] == 1) /* map connections to this stone */
1094 {
1095 if (x > 0) /* direct connection */
1096 connectMap[x - 1][y] += 1;
1097 if (x < maxPoint)
1098 connectMap[x + 1][y] += 1;
1099 if (y > 0)
1100 connectMap[x][y - 1] += 1;
1101 if (y < maxPoint)
1102 connectMap[x][y + 1] += 1;
1103 if ((x > 0) && (y > 0) && /* diagonal connection */
1104 (bord[x - 1][y] == 0) && (bord[x][y - 1] == 0))
1105 connectMap[x - 1][y - 1] += 1;
1106 if ((x < maxPoint) && (y > 0) &&
1107 (bord[x + 1][y] == 0) && (bord[x][y - 1] == 0))
1108 connectMap[x + 1][y - 1] += 1;
1109 if ((x < maxPoint) && (y < maxPoint) &&
1110 (bord[x + 1][y] == 0) && (bord[x][y + 1] == 0))
1111 connectMap[x + 1][y + 1] += 1;
1112 if ((x > 0) && (y < maxPoint) &&
1113 (bord[x - 1][y] == 0) && (bord[x][y + 1] == 0))
1114 connectMap[x - 1][y + 1] += 1;
1115 if ((x > 1) && (claim[x - 1][y] > 3)) /* one point jump */
1116 connectMap[x - 2][y] += 1;
1117 if ((x < (maxPoint - 1)) && (claim[x + 1][y] > 3))
1118 connectMap[x + 2][y] += 1;
1119 if ((y > 1) && (claim[x][y - 1] > 3))
1120 connectMap[x][y - 2] += 1;
1121 if ((y < (maxPoint - 1)) && (claim[x][y + 1] > 3))
1122 connectMap[x][y + 2] += 1;
1123 if ((x > 1) && (y > 0) && /* knight's move */
1124 (claim[x - 1][y] > 3) && (claim[x - 1][y - 1] > 3))
1125 connectMap[x - 2][y - 1] += 1;
1126 if ((x > 0) && (y > 1) &&
1127 (claim[x][y - 1] > 3) && (claim[x - 1][y - 1] > 3))
1128 connectMap[x - 1][y - 2] += 1;
1129 if ((x < (maxPoint - 1)) && (y > 0) &&
1130 (claim[x + 1][y] > 3) && (claim[x + 1][y - 1] > 3))
1131 connectMap[x + 2][y - 1] += 1;
1132 if ((x < maxPoint) && (y > 1) &&
1133 (claim[x][y - 1] > 3) && (claim[x + 1][y - 1] > 3))
1134 connectMap[x + 1][y - 2] += 1;
1135 if ((x > 1) && (y < maxPoint) &&
1136 (claim[x - 1][y] > 3) && (claim[x - 1][y + 1] > 3))
1137 connectMap[x - 2][y + 1] += 1;
1138 if ((x > 0) && (y < (maxPoint - 1)) &&
1139 (claim[x][y + 1] > 3) && (claim[x - 1][y + 1] > 3))
1140 connectMap[x - 1][y + 2] += 1;
1141 if ((x < (maxPoint - 1)) && (y < maxPoint) &&
1142 (claim[x + 1][y] > 3) && (claim[x + 1][y + 1] > 3))
1143 connectMap[x + 2][y + 1] += 1;
1144 if ((x < maxPoint) && (y < (maxPoint - 1)) &&
1145 (claim[x][y + 1] > 3) && (claim[x + 1][y + 1] > 3))
1146 connectMap[x + 1][y + 2] += 1;
1147 }
1148 else if (bord[x][y] == 0) /* see if protected point */
1149 {
1150 numStones = 0;
1151 if (x == 0)
1152 numStones = numStones + 1;
1153 if (y == 0)
1154 numStones = numStones + 1;
1155 if (x == maxPoint)
1156 numStones = numStones + 1;
1157 if (y == maxPoint)
1158 numStones = numStones + 1;
1159 if ((x > 0) && (bord[x - 1][y] == 1))
1160 numStones = numStones + 1;
1161 if ((y > 0) && (bord[x][y - 1] == 1))
1162 numStones = numStones + 1;
1163 if ((x < maxPoint) && (bord[x + 1][y] == 1))
1164 numStones = numStones + 1;
1165 if ((y < maxPoint) && (bord[x][y + 1] == 1))
1166 numStones = numStones + 1;
1167 if (numStones == 4)
1168 protPoints[x][y] = 1;
1169 else if (numStones == 3)
1170 {
1171 if ((x > 0) &&
1172 ((bord[x - 1][y] == 0) ||
1173 ((bord[x - 1][y] == -1) &&
1174 (gList[groupIDs[x - 1][y]].libC == 1))))
1175 protPoints[x][y] = 1;
1176 else if ((x < maxPoint) &&
1177 ((bord[x + 1][y] == 0) ||
1178 ((bord[x + 1][y] == -1) &&
1179 (gList[groupIDs[x + 1][y]].libC == 1))))
1180 protPoints[x][y] = 1;
1181 else if ((y > 0) &&
1182 ((bord[x][y - 1] == 0) ||
1183 ((bord[x][y - 1] == -1) &&
1184 (gList[groupIDs[x][y - 1]].libC == 1))))
1185 protPoints[x][y] = 1;
1186 else if ((y < maxPoint) &&
1187 ((bord[x][y + 1] == 0) ||
1188 ((bord[x][y + 1] == -1) &&
1189 (gList[groupIDs[x][y + 1]].libC == 1))))
1190 protPoints[x][y] = 1;
1191 }
1192 }
1193 for (x = 0; x <= maxPoint; x++)
1194 for (y = 0; y <= maxPoint; y++)
1195 if (bord[x][y] != 0)
1196 {
1197 connectMap[x][y] = 0;
1198 protPoints[x][y] = 0;
1199 }
1200} /* genConnects */
1201
1202/*
1203 generates the whole state of the game.
1204*/
1205genState()
1206{ /* genState */
1207#ifdef DEBUG
1208 printf( "genState\n" );
1209#endif
1210 inGenState = TRUE;
1211 respreicen();
1212 markDead();
1213 markLive();
1214 spread();
1215 genConnects();
1216#ifdef DEBUG
1217/* printBoard( claim, "claim" ); */
1218/* printBoard( bord, "bord" ); */
1219/* printBoard( ndbord, "ndbord" );
1220 printBoard( sGroups, "sGroups" );
1221 printBoard( groupIDs, "groupIDs" );
1222 printBoard( connectMap, "connectMap" );
1223 printBoard( protPoints, "protPoints" ); */
1224#endif
1225 inGenState = FALSE;
1226} /* genState */
1227
1228/*
1229 generates a value for the [x, y] location that appears to get larger
1230 for points that are saddle points in the influence graph (klein)
1231*/
1232short tencen(x, y)
1233short x, y;
1234{ /* tencen */
1235 short a, b, c, d, w, z;
1236#ifdef DEBUG
1237 printf( "tencen\n" );
1238#endif
1239 if (claim[x][y] > -1) /* if (he does not influence this area, return 50 */
1240 {
1241 return 50;
1242 }
1243 w = claim[x][y]; /* w <= -1 */
1244 a = iNil;
1245 if (x > 0)
1246 if (claim[x - 1][y] > -1) /* if (neighbor is not influenced by him */
1247 a = claim[x - 1][y] - w; /* score is sum of his influence on central */
1248 b = iNil; /* point and my influence on this neighbor */
1249 if (y > 0)
1250 if (claim[x][y - 1] > -1)
1251 b = claim[x][y - 1] - w;
1252 c = iNil;
1253 if (x < maxPoint)
1254 if (claim[x + 1][y] > -1)
1255 c = claim[x + 1][y] - w;
1256 d = iNil;
1257 if (y < maxPoint)
1258 if (claim[x][y + 1] > -1)
1259 d = claim[x][y + 1] - w;
1260 z = a; /* z = max(a, b, c, d) */
1261 if (z != iNil)
1262 {
1263 if ((b != iNil) &&
1264 (b > z))
1265 z = b;
1266 }
1267 else
1268 z = b;
1269 if (z != iNil)
1270 {
1271 if ((c != iNil) &&
1272 (c > z))
1273 z = c;
1274 }
1275 else
1276 z = c;
1277 if (z != iNil)
1278 {
1279 if ((d != iNil) &&
1280 (d > z))
1281 z = d;
1282 }
1283 else
1284 z = d;
1285 if ((z != iNil) &&
1286 ((x == 0) ||
1287 (y == 0) ||
1288 (x == maxPoint) ||
1289 (y == maxPoint)))
1290 z = z * 2; /* double z if (on the edge of the board ?? */
1291 if (z != iNil)
1292 return z;
1293 else
1294 return 50;
1295} /* tencen */
1296
1297initGPUtils()
1298{ /* initGPUtils */
1299#ifdef DEBUG
1300 printf( "initGPUtils\n" );
1301#endif
1302 initArray(markBoard);
1303 initState();
1304 marker = 0;
1305 playMark = 0;
1306 gList[0].isLive = FALSE;
1307 gList[0].isDead = FALSE;
1308 gList[0].libC = 0;
1309 gList[0].size = 0;
1310 gList[0].numEyes = 0;
1311 gList[0].lx = -1;
1312 gList[0].ly = -1;
1313 gMap[0] = 0;
1314 dbStop = FALSE;
1315 inGenState = FALSE;
1316} /* initGPUtils */
1317
diff --git a/noncore/games/go/goplayutils.h b/noncore/games/go/goplayutils.h
new file mode 100644
index 0000000..11ab658
--- a/dev/null
+++ b/noncore/games/go/goplayutils.h
@@ -0,0 +1,85 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef __goplayutils_h
21#define __goplayutils_h
22
23#define iNil 32767 /* a distinguished value like nil */
24#define maxGroup 512
25#define maxSPoint 16
26#define tryLimit 300
27
28typedef short intBoard[19][19]; /* these were -2 to maxPoint + 2 */
29
30typedef short boolBoard[19][19];
31
32typedef struct
33{
34 short px, py;
35} point;
36
37typedef struct
38{
39 point p[401];
40 short indx;
41} pointList;
42
43typedef struct
44{
45 point p[maxSPoint+1];
46 short indx;
47} sPointList;
48
49typedef struct
50{
51 short indx,
52 v[401];
53} intList;
54
55typedef struct { short w, s, sm; } sgRec;
56
57typedef struct
58{
59 short groupMark,
60 atLevel,
61 isLive,
62 isDead,
63 libC,
64 numEyes,
65 size,
66 lx, ly;
67} groupRec;
68
69typedef enum {rem, add, chLib, reMap} playType;
70
71typedef struct { short who, xl, yl, nextGID, sNumber; } remAddRec;
72typedef struct { short oldLC, oldLevel; } chLibRec;
73typedef struct { short oldGID; } reMapRec;
74typedef struct
75{
76 short gID;
77 playType kind;
78 union {
79 remAddRec rem, add;
80 chLibRec chLib;
81 reMapRec reMap;
82 } uval;
83} playRec;
84
85#endif
diff --git a/noncore/games/go/gowidget.cpp b/noncore/games/go/gowidget.cpp
new file mode 100644
index 0000000..fca9797
--- a/dev/null
+++ b/noncore/games/go/gowidget.cpp
@@ -0,0 +1,449 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "gowidget.h"
22
23#include <qpe/config.h>
24#include <qpe/resource.h>
25
26#include <qpainter.h>
27#include <qpixmap.h>
28#include <qpe/qpetoolbar.h>
29#include <qpe/qpemenubar.h>
30#include <qpopupmenu.h>
31#include <qaction.h>
32#include <qapplication.h> //processEvents()
33#include <qlabel.h>
34
35//#include <stdio.h>
36
37#include "amigo.h"
38#include "goplayutils.h"
39
40static const enum bVal computer_color = BLACK;
41
42static int current_handicap = 1;
43
44static QBrush *goBrush;
45//static QImage *newBlackStone;
46//static QImage *blackStone;
47//static QImage *whiteStone;
48static QPixmap *newBlackStone;
49static QPixmap *blackStone;
50static QPixmap *whiteStone;
51
52GoMainWidget::GoMainWidget( QWidget *parent, const char* name) :
53 QMainWindow( parent, name )
54{
55 setToolBarsMovable( FALSE );
56 GoWidget *go = new GoWidget(this);
57
58 setCentralWidget(go);
59 toolbar = new QPEToolBar(this);
60 toolbar->setHorizontalStretchable( TRUE );
61 addToolBar(toolbar);
62
63 QPEMenuBar *mb = new QPEMenuBar( toolbar );
64 mb->setMargin(0);
65 QPopupMenu *file = new QPopupMenu( this );
66
67 QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 );
68 connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) );
69 a->addTo( file );
70
71 a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 );
72 connect( a, SIGNAL( activated() ), go, SLOT( pass() ) );
73 a->addTo( file );
74 a->addTo( toolbar );
75
76
77 a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 );
78 connect( a, SIGNAL( activated() ), go, SLOT( resign() ) );
79 a->addTo( file );
80
81 a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 );
82 a->setToggleAction( TRUE );
83 connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) );
84 a->addTo( file );
85
86 mb->insertItem( tr( "Game" ), file );
87
88 QLabel *turnLabel = new QLabel( toolbar );
89 turnLabel->setBackgroundMode( PaletteButton );
90 connect( go, SIGNAL(showTurn(const QPixmap&)),
91 turnLabel, SLOT(setPixmap(const QPixmap&)) );
92
93
94 QLabel * scoreLabel = new QLabel( toolbar );
95 scoreLabel->setBackgroundMode( PaletteButton );
96 connect( go, SIGNAL(showScore(const QString&)),
97 scoreLabel, SLOT(setText(const QString&)) );
98
99 toolbar->setStretchableWidget( scoreLabel );
100
101 go->readConfig();
102}
103
104void GoMainWidget::resizeEvent( QResizeEvent * )
105{
106 //### this won't work because of the text label...
107 /*
108 if ( width() > height() )
109 moveToolBar( toolbar, Left );
110 else
111 moveToolBar( toolbar, Top );
112 */
113}
114
115GoWidget *GoWidget::self = 0;
116
117GoWidget::GoWidget( QWidget *parent, const char* name) :
118 QWidget( parent, name )
119{
120 if ( self )
121 fatal( "Only one Go widget allowed" );
122 self = this;
123 twoplayer = FALSE;
124
125
126 d = bx = by = 1;
127
128 QPixmap pix = Resource::loadPixmap( "pine" );
129 goBrush = new QBrush( black, pix );
130 /*
131 QString fn = Resource::findPixmap("Go-black");
132 blackStone = new QImage( fn );
133 fn = Resource::findPixmap("Go-black-highlight");
134 newBlackStone = new QImage( fn );
135 fn = Resource::findPixmap("Go-white");
136 whiteStone = new QImage( fn );
137 */
138 blackStone = new QPixmap(Resource::loadPixmap( "Go-black" ));
139 whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" ));
140 newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" ));
141
142 init();
143}
144
145GoWidget::~GoWidget()
146{
147 writeConfig();
148}
149
150void GoWidget::writeConfig()
151{
152 Config cfg("Go");
153 cfg.setGroup("Game");
154 cfg.writeEntry("TwoPlayer", twoplayer);
155 cfg.writeEntry("CurrentPlayer", currentPlayer);
156 cfg.writeEntry("NPassed", nPassed);
157 QString b;
158 for (int i=0; i<19; i++)
159 for (int j=0; j<19; j++)
160 b += board[i][j] == BLACK ? 'B' : board[i][j] == WHITE ? 'W' : '.';
161 cfg.writeEntry("Board", b);
162 cfg.writeEntry("LastX", lastX);
163 cfg.writeEntry("LastY", lastY);
164 extern int blackPrisoners, whitePrisoners;
165 cfg.writeEntry("BlackPrisoners", blackPrisoners);
166 cfg.writeEntry("WhitePrisoners", whitePrisoners);
167}
168
169void GoWidget::readConfig()
170{
171 init();
172 Config cfg("Go");
173 cfg.setGroup("Game");
174 twoplayer = cfg.readBoolEntry("TwoPlayer");
175 currentPlayer = (bVal)cfg.readNumEntry("CurrentPlayer",1);
176 nPassed = cfg.readNumEntry("NPassed",0);
177 QString b = cfg.readEntry("Board");
178 if ( b.length() == 19*19 )
179 for (int i=0; i<19; i++)
180 for (int j=0; j<19; j++) {
181 QChar ch = b[j+19*i];
182 if ( ch != '.' )
183 GoPlaceStone( ch == 'B' ? BLACK : WHITE, i, j );
184 }
185 lastX = cfg.readNumEntry("LastX");
186 lastY = cfg.readNumEntry("LastY");
187 extern int blackPrisoners, whitePrisoners;
188 blackPrisoners = cfg.readNumEntry("BlackPrisoners",0);
189 whitePrisoners = cfg.readNumEntry("WhitePrisoners",0);
190 reportPrisoners(blackPrisoners,whitePrisoners);
191 emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone );
192}
193
194void GoWidget::resizeEvent( QResizeEvent * )
195{
196 d = QMIN(width(),height())/19;
197 // int r = (d/2-1);
198 bx = (width() - 18*d)/2 ;
199 by = (height() - 18*d)/2 ;
200}
201
202void GoWidget::init()
203{
204 lastX = lastY = newX = newY = -1;
205 nPassed = 0;
206 for ( int i = 0; i < 19; i++ )
207 for ( int j = 0; j < 19; j++ )
208 board[i][j]=-1;
209 gameActive = TRUE;
210 goRestart(current_handicap);
211
212 if ( twoplayer ) {
213 currentPlayer = BLACK;
214 } else {
215 doComputerMove();
216 currentPlayer = WHITE;
217 }
218 emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone );
219}
220
221void GoWidget::paintEvent( QPaintEvent *e )
222{
223 int i,j;
224
225 int r = whiteStone->width()/2;
226
227 QPainter p(this);
228 p.fillRect( bx - d/2, by - d/2, 19*d, 19*d, *goBrush );
229
230 int xMin = QMAX( x2board(e->rect().left()), 0 );
231 int xMax = QMIN( x2board(e->rect().right()), 18 );
232 int yMin = QMAX( y2board(e->rect().top()), 0 );
233 int yMax = QMIN( y2board(e->rect().bottom()), 18 );
234
235 QColor pine( 255, 186, 89 );
236 p.setPen( pine.dark() );
237
238 for ( i = xMin; i < xMax+1 ; i ++ ) {
239 p.drawLine( bx+i*d, by, bx+i*d, by+18*d );
240 }
241 for ( j = yMin; j < yMax+1 ; j ++ ) {
242 p.drawLine( bx, by+j*d, bx+18*d, by+j*d);
243 }
244
245 // dots are at (3,3), (3,9), (3,15) and so on
246 p.setBrush( black );
247 for ( i = 3; i < xMax+1; i+=6 )
248 for ( j = 3; j < yMax+1; j+=6 )
249 p.drawEllipse( bx+i*d-2, by+j*d-2, 5, 5 );
250
251
252 for ( i = xMin; i < xMax+1; i++ )
253 for ( j = yMin; j < yMax+1; j++ ) {
254 if ( board[i][j] == WHITE ||
255 currentPlayer==WHITE && newX == i && newY == j )
256 p.drawPixmap( bx+i*d - r, by+j*d - r, *whiteStone );
257 else if ( i == lastX && j == lastY )
258 p.drawPixmap( bx+i*d - r, by+j*d - r, *newBlackStone );
259 else if ( board[i][j] == BLACK ||
260 currentPlayer==BLACK && newX == i && newY == j)
261 p.drawPixmap( bx+i*d - r, by+j*d - r, *blackStone );
262 }
263}
264
265void GoWidget::doMove( int x, int y )
266{
267
268 if ( !GoPlaceStone( currentPlayer, x, y ) ) {
269 //printf( "Illegal move (%d,%d)\n", x, y );
270 return;
271 }
272 //printf( "you do (%d,%d)\n", x, y );
273 nPassed = 0;
274 if ( twoplayer )
275 currentPlayer = (currentPlayer==WHITE) ? BLACK : WHITE;
276 else
277 doComputerMove();
278
279 emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone );
280
281}
282
283void GoWidget::pass()
284{
285 if ( !gameActive )
286 return;
287 nPassed++;
288 if ( nPassed >= 2 )
289 endGame();
290 else if ( !twoplayer )
291 doComputerMove();
292}
293
294void GoWidget::resign()
295{
296 if ( gameActive )
297 endGame();
298}
299
300
301void GoWidget::newGame()
302{
303 init();
304 update();
305}
306
307
308void GoWidget::endGame()
309{
310 gameActive = FALSE;
311
312 int w,b;
313 CountUp( &w, &b);
314 QString s = tr("White %1, Black %2. ").arg(w).arg(b);
315 if ( w > b )
316 s += tr("White wins.");
317 else if ( w < b )
318 s += tr("Black wins.");
319 else
320 s += tr("A draw.");
321 emit showScore( s );
322}
323
324void GoWidget::doComputerMove()
325{
326 int ox = lastX;
327 int oy = lastY;
328 lastX = lastY = -1;
329 emit showTurn( *blackStone );
330 refresh( ox, oy);
331 qApp->processEvents();
332 short int x,y;
333 if ( genMove( computer_color, &x, &y ) ) {
334 lastX = x;
335 lastY = y;
336 //printf( "I do (%d,%d)\n", x, y );
337 GoPlaceStone(computer_color,x,y);
338 nPassed = 0;
339 } else {
340 emit showScore( tr("I pass") );
341 nPassed++;
342 if ( nPassed >= 2 )
343 endGame();
344 }
345}
346
347void GoWidget::mousePressEvent( QMouseEvent *me )
348{
349 if ( !gameActive )
350 return;
351 int x = x2board(me->x());
352 int y = y2board(me->y());
353 showStone(x,y,currentPlayer);
354}
355
356void GoWidget::mouseMoveEvent( QMouseEvent *me )
357{
358 if ( !gameActive )
359 return;
360 int x = x2board(me->x());
361 int y = y2board(me->y());
362 if ( x != newX || y != newY )
363 showStone(x,y,currentPlayer);
364}
365
366void GoWidget::showStone( int x, int y, enum bVal c )
367{
368
369 if ( newX > -1 ) {
370 refresh( newX, newY );
371 newY = newX = -1;
372 }
373 if ( x < 0 || x > 18 || y < 0 || y > 18 ) {
374 newX = newY = -1;
375 return;
376 }
377 if ( board[x][y] == -1 && !Suicide( c, x, y ) ) {
378 newX = x;
379 newY = y;
380 refresh(x,y);
381 }
382
383}
384
385void GoWidget::mouseReleaseEvent( QMouseEvent * )
386{
387 if ( gameActive && newX > -1 )
388 doMove( newX, newY );
389 newX = newY = -1;
390}
391
392void GoWidget::refresh( int x, int y )
393{
394 update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 );
395}
396
397void GoWidget::removeStone(short x, short y)
398{
399 board[x][y]=-1;
400 refresh( x, y );
401}
402
403void GoWidget::placeStone (enum bVal c, short x, short y )
404{
405 board[x][y]=c;
406 refresh( x, y );
407}
408
409void GoWidget::reportPrisoners( int blackcnt, int whitecnt )
410{
411 QString s = tr( "Prisoners: black %1, white %2" ).arg(blackcnt).arg(whitecnt);
412 emit showScore( s );
413}
414
415void GoWidget::setTwoplayer( bool b )
416{
417 twoplayer = b;
418}
419
420void GoWidget::setHandicap( int h )
421{
422 current_handicap = h;
423}
424
425
426extern "C" {
427
428 voidremovestone(short x, short y)
429{
430 GoWidget::self->removeStone(x,y);
431}
432
433 voidplacestone (enum bVal c, short x, short y )
434{
435 GoWidget::self->placeStone(c,x,y);
436}
437
438 voidintrMoveReport(enum bVal c ,char *coord ,char *reason )
439{
440 qDebug( "intrMoveReport colour %d, %s %s", c, coord, reason );
441}
442
443 voidintrPrisonerReport( short blackcnt, short whitecnt )
444{
445 GoWidget::self->reportPrisoners(blackcnt,whitecnt);
446}
447
448}
449
diff --git a/noncore/games/go/gowidget.h b/noncore/games/go/gowidget.h
new file mode 100644
index 0000000..94de2cc
--- a/dev/null
+++ b/noncore/games/go/gowidget.h
@@ -0,0 +1,111 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef GOWIDGET_H
22#define GOWIDGET_H
23
24#include <qmainwindow.h>
25#include "amigo.h"
26
27
28class QToolBar;
29
30class GoMainWidget : public QMainWindow
31{
32 Q_OBJECT
33public:
34 GoMainWidget( QWidget *parent=0, const char* name=0);
35protected:
36 void resizeEvent( QResizeEvent * );
37private:
38 QToolBar *toolbar;
39
40};
41
42
43class QLabel;
44class GoWidget : public QWidget
45{
46 Q_OBJECT
47public:
48 GoWidget( QWidget *parent=0, const char* name=0);
49 ~GoWidget();
50
51 void doMove( int x, int y );
52 void doComputerMove();
53
54 void readConfig();
55 void writeConfig();
56
57public slots:
58 void pass();
59 void resign();
60 void newGame();
61 void setTwoplayer( bool );
62 void setHandicap( int );
63signals:
64 void showScore( const QString& );
65 void showTurn( const QPixmap& );
66
67protected:
68 void paintEvent( QPaintEvent * );
69 void mousePressEvent( QMouseEvent * );
70 void mouseMoveEvent( QMouseEvent * );
71 void mouseReleaseEvent( QMouseEvent * );
72 void resizeEvent( QResizeEvent * );
73private:
74 void init();
75 void removeStone(short x, short y);
76 void placeStone (enum bVal c, short x, short y );
77
78 void refresh( int x, int y );
79 void showStone( int x, int y, enum bVal );
80 void reportPrisoners(int,int);
81
82 inline int x2board( int x ) { return (x-bx+d/2)/d; }
83 inline int y2board( int y ) { return (y-by+d/2)/d; }
84
85 void endGame();
86
87 bool twoplayer;
88 enum bVal currentPlayer;
89 bool gameActive;
90 int nPassed;
91 signed char board[19][19];
92
93 int d; //distance between lines
94 int bx; //vertical baseline
95 int by; //horizontal baseline
96
97 int lastX,lastY;
98 int newX,newY;
99
100 static GoWidget *self;
101
102 friend void removestone(short x, short y);
103 friend voidintrPrisonerReport( short, short );
104 friend void placestone(enum bVal c, short x, short y );
105};
106
107
108
109
110
111#endif
diff --git a/noncore/games/go/killable.c b/noncore/games/go/killable.c
new file mode 100644
index 0000000..3ed2d2e
--- a/dev/null
+++ b/noncore/games/go/killable.c
@@ -0,0 +1,373 @@
1/* By Stoney Ballard */
2/* Ported from Pascal to C by Todd R. Johnson */
3
4#include "go.h"
5#include "goplayutils.h"
6#include "amigo.h"
7
8extern intBoard bord, groupIDs;
9extern boolBoard legal;
10extern groupRec gList[maxGroup];
11extern short gMap[maxGroup], adjInAtari, adj2Libs, playMark, treeLibLim,
12 utilPlayLevel, killFlag, depthLimit, dbStop, showTrees;
13extern pointList plist2;
14
15/*
16 returns true if the group (at x, y) is killable.
17 if so, returns the point to play at in killx, killy.
18*/
19
20 short me, him, depth, i, j, tryCount, tl, topMark, tkMark, mark2;
21 char sChar;
22 sPointList lList, dList;
23 point tp;
24 short libList[maxSPoint+1];
25 short esc;
26
27short mtNbrs(x, y)
28short x, y;
29 { /* mtNbrs */
30 short n = 0;
31 if ((x > 0) && (bord[x - 1][y] == 0))
32 n = n + 1;
33 if ((x < maxPoint) && (bord[x + 1][y] == 0))
34 n = n + 1;
35 if ((y > 0) && (bord[x][y - 1] == 0))
36 n = n + 1;
37 if ((y < maxPoint) && (bord[x][y + 1] == 0))
38 n = n + 1;
39 return n;
40 } /* mtNbrs */
41
42short killTree(tx, ty, gx, gy, escape, tkMark)
43short tx, ty, gx, gy, *escape, tkMark;
44 { /* killTree */
45 short curMark, mark2, mark3, i, j, k, tl, dStart, result;
46 sPointList lList1, lList2;
47 short libList[maxSPoint+1];
48 point tp;
49 short esc = FALSE;
50 tryCount = tryCount + 1;
51 if (tryCount > tryLimit)
52 {
53 undoTo(tkMark);
54/* for (i = 1; i <= depth - 1; i++)
55 {
56 sClearChar(sChar, rXor);
57 } */
58 depth = 1;
59 return FALSE;
60 }
61/* write(sChar); */
62 depth = depth + 1;
63 curMark = playMark;
64 tryPlay(tx, ty, me); /* try my move */
65 pause();
66 if (gList[gMap[groupIDs[tx][ty]]].libC == 0) /* I'm dead */
67 {
68 result = FALSE;
69 goto one;
70 }
71 else if (killFlag) /* I killed something of his */
72 {
73 result = TRUE;
74 goto one;
75 }
76 else if (gList[gMap[groupIDs[gx][gy]]].libC > treeLibLim) /* safe */
77 {
78 result = FALSE;
79 goto one;
80 }
81 else
82 {
83 sSpanGroup(gx, gy, &lList1); /* find his liberties */
84 if (gList[gMap[groupIDs[tx][ty]]].libC == 1) /* he can kill me */
85 {
86 if (lList1.indx < maxSPoint) /* add that option to his list */
87 {
88 lList1.indx = lList1.indx + 1;
89 spanGroup(tx, ty, &plist2); /* find my liberty */
90 lList1.p[lList1.indx].px = plist2.p[1].px;
91 lList1.p[lList1.indx].py = plist2.p[1].py;
92 }
93 else
94 {
95 result = FALSE;
96 goto one;
97 }
98 }
99 for (i = 1; i <= maxSPoint; i++) /* init liblist so diags can be marked */
100 libList[i] = -1;
101 if ((utilPlayLevel > 4) &&
102 (lList1.indx > 1) &&
103 (gList[gMap[groupIDs[gx][gy]]].libC > 1)) /* try diags */
104 {
105 listDiags(gx, gy, &dList);
106 j = 0;
107 i = lList1.indx;
108 while ((j < dList.indx) &&
109 (i < maxSPoint))
110 {
111 j = j + 1;
112 i = i + 1;
113 libList[i] = 0; /* mark this as a diag */
114 lList1.p[i].px = dList.p[j].px;
115 lList1.p[i].py = dList.p[j].py;
116 }
117 lList1.indx = i;
118 }
119 if (lList1.indx > 1) /* sort by decreasing lib count */
120 {
121 for (i = 1; i <= lList1.indx; i++)
122 if (libList[i] != 0) /* diags are tried last */
123 {
124 mark2 = playMark;
125 tryPlay(lList1.p[i].px, lList1.p[i].py, him);
126 libList[i] = gList[gMap[groupIDs[gx][gy]]].libC;
127 if ((libList[i] > treeLibLim) ||
128 ((libList[i] > (depthLimit - depth)) &&
129 (libList[i] > 2)))
130 {
131 *escape = TRUE;
132 result = FALSE;
133 goto one;
134 }
135 undoTo(mark2);
136 }
137 for (i = 1; i <= lList1.indx - 1; i++)
138 for (j = i + 1; j <= lList1.indx; j++)
139 if (libList[i] < libList[j])
140 {
141 tl = libList[i];
142 libList[i] = libList[j];
143 libList[j] = tl;
144 tp = lList1.p[i];
145 lList1.p[i] = lList1.p[j];
146 lList1.p[j] = tp;
147 }
148 }
149 for (i = 1; i <= lList1.indx + 1; i++) /* try his responses */
150 {
151 mark2 = playMark;
152 if (i <= lList1.indx) /* try his move */
153 {
154 tryPlay(lList1.p[i].px, lList1.p[i].py, him); /* play his response */
155 pause();
156 if (gList[gMap[groupIDs[lList1.p[i].px]
157 [lList1.p[i].py]]].libC < 2)
158 goto two; /* a bogus move */
159 }
160 else if (gList[gMap[groupIDs[gx][gy]]].libC <= 1)
161 {
162 result = TRUE;
163 goto one;
164 }
165 if (gList[gMap[groupIDs[gx][gy]]].libC > treeLibLim)
166 {
167 *escape = TRUE;
168 result = FALSE;
169 goto one;
170 }
171 if (gList[gMap[groupIDs[gx][gy]]].libC > 1)
172 { /* look at my responses */
173 sSpanGroup(gx, gy, &lList2); /* list his liberties */
174 dStart = lList2.indx + 1;
175 if (adjInAtari) /* he wins */
176 {
177 result = FALSE;
178 goto one;
179 }
180 if ((lList2.indx > 2) && adj2Libs) /* he wins */
181 {
182 result = FALSE;
183 goto one;
184 }
185 for (k = 1; k <= maxSPoint; k++)
186 libList[k] = -1;
187 if (utilPlayLevel > 4) /* account for diagonal moves */
188 {
189 listDiags(gx, gy, &dList);
190 j = 0;
191 k = lList2.indx;
192 while ((j < dList.indx) &&
193 (k < maxSPoint))
194 {
195 j = j + 1;
196 k = k + 1;
197 libList[k] = 100;
198 lList2.p[k].px = dList.p[j].px;
199 lList2.p[k].py = dList.p[j].py;
200 }
201 lList2.indx = k;
202 }
203 if (lList2.indx > 1) /* sort by increasing lib count */
204 {
205 for (k = 1; k <= lList2.indx; k++)
206 if (libList[k] != 100) /* diags go last */
207 {
208 mark3 = playMark;
209 tryPlay(lList2.p[k].px, lList2.p[k].py, me);
210 libList[k] = gList[gMap[groupIDs[gx][gy]]].libC;
211 undoTo(mark3);
212 }
213 for (k = 1; k <= lList2.indx - 1; k++)
214 for (j = k + 1; j <= lList2.indx; j++)
215 if (libList[k] > libList[j])
216 {
217 tl = libList[k];
218 libList[k] = libList[j];
219 libList[j] = tl;
220 tp = lList2.p[k];
221 lList2.p[k] = lList2.p[j];
222 lList2.p[j] = tp;
223 }
224 else if ((libList[k] == libList[j]) &&
225 (libList[k] == 1))
226 if (mtNbrs(lList2.p[k].px, lList2.p[k].py) <
227 mtNbrs(lList2.p[j].px, lList2.p[j].py))
228 {
229 tl = libList[k];
230 libList[k] = libList[j];
231 libList[j] = tl;
232 tp = lList2.p[k];
233 lList2.p[k] = lList2.p[j];
234 lList2.p[j] = tp;
235 }
236 }
237 for (j = 1; j <= lList2.indx; j++)
238 {
239 if (killTree(lList2.p[j].px, lList2.p[j].py, gx,
240 gy, &esc, tkMark))
241 goto two; /* this kills him */
242 if (esc && (j >= dStart))
243 {
244 result = FALSE;
245 goto one; /* don't bother with more diags if escapes */
246 }
247 }
248 result = FALSE; /* none of my responses kills him */
249 goto one;
250 }
251 two:
252 undoTo(mark2);
253 }
254 result = TRUE; /* none of his responses saves him */
255 }
256 one:
257 undoTo(curMark);
258/* sClearChar(sChar, rXor); */
259 depth = depth - 1;
260 return result;
261 } /* killTree */
262
263short tKillTree(tx, ty, gx, gy)
264short tx, ty, gx, gy;
265 { /* tKillTree */
266 short tkMark, escape;
267 tryCount = 0;
268 tkMark = playMark;
269 return killTree(tx, ty, gx, gy, &escape, tkMark);
270 } /* tKillTree */
271
272short killable(gx, gy, killx, killy)
273short gx, gy, *killx, *killy;
274{ /* killable */
275#ifdef DEBUG
276 printf( "killable\n" );
277 showTrees = TRUE;
278#endif
279 dbStop = TRUE;
280 him = bord[gx][gy]; /* find out who I am */
281 me = -him;
282/* if (me == 1)
283 sChar = '>';
284 else
285 sChar = '|'; */
286/* write(sChar); */
287 depth = 1;
288 topMark = playMark;
289 sSpanGroup(gx, gy, &lList); /* find his liberties */
290 if (lList.indx == 1)
291 {
292 *killx = lList.p[1].px;
293 *killy = lList.p[1].py;
294 return TRUE;
295 }
296 else if (lList.indx > treeLibLim)
297 return FALSE;
298 else if (adjInAtari)
299 return FALSE;
300 else if ((lList.indx > 2) && adj2Libs)
301 return FALSE;
302 else
303 {
304 for (i = 1; i <= maxSPoint; i++)
305 libList[i] = -1;
306 if (utilPlayLevel > 4) /* account for diagonal moves */
307 {
308 listDiags(gx, gy, &dList);
309 j = 0;
310 i = lList.indx;
311 while ((j < dList.indx) &&
312 (i < maxSPoint))
313 {
314 j = j + 1;
315 i = i + 1;
316 libList[i] = 100;
317 lList.p[i].px = dList.p[j].px;
318 lList.p[i].py = dList.p[j].py;
319 }
320 lList.indx = i;
321 }
322 if (lList.indx > 1) /* sort by increasing lib count */
323 {
324 for (i = 1; i <= lList.indx; i++)
325 if (libList[i] != 100) /* diags go last */
326 {
327 mark2 = playMark;
328 tryPlay(lList.p[i].px, lList.p[i].py, me);
329 libList[i] = gList[gMap[groupIDs[gx][gy]]].libC;
330 undoTo(mark2);
331 }
332 for (i = 1; i <= lList.indx - 1; i++)
333 for (j = i + 1; j <= lList.indx; j++)
334 if (libList[i] > libList[j])
335 {
336 tl = libList[i];
337 libList[i] = libList[j];
338 libList[j] = tl;
339 tp = lList.p[i];
340 lList.p[i] = lList.p[j];
341 lList.p[j] = tp;
342 }
343 else if ((libList[i] == libList[j]) &&
344 (libList[i] == 1))
345 if (mtNbrs(lList.p[i].px, lList.p[i].py) <
346 mtNbrs(lList.p[j].px, lList.p[j].py))
347 {
348 tl = libList[i];
349 libList[i] = libList[j];
350 libList[j] = tl;
351 tp = lList.p[i];
352 lList.p[i] = lList.p[j];
353 lList.p[j] = tp;
354 }
355 }
356 for (i = 1; i <= lList.indx; i++)
357 {
358 if (legal[lList.p[i].px][lList.p[i].py])
359 {
360 *killx = lList.p[i].px;
361 *killy = lList.p[i].py;
362 if (tKillTree(*killx, *killy, gx, gy))
363 {
364/* sClearChar(sChar, rXor); */
365 return TRUE;
366 }
367 }
368 }
369 return FALSE;
370 }
371/* sClearChar(sChar, rXor); */
372} /* killable */
373
diff --git a/noncore/games/go/main.cpp b/noncore/games/go/main.cpp
new file mode 100644
index 0000000..c7e2669
--- a/dev/null
+++ b/noncore/games/go/main.cpp
@@ -0,0 +1,35 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "gowidget.h"
22
23#include <qpe/qpeapplication.h>
24
25#include <stdio.h>
26
27int main( int argc, char ** argv)
28{
29 QPEApplication app( argc, argv );
30
31 GoMainWidget m;
32 m.setCaption( GoWidget::tr("Go") );
33 app.showMainWidget( &m );
34 return app.exec();
35}
diff --git a/noncore/games/go/qpe-go.control b/noncore/games/go/qpe-go.control
new file mode 100644
index 0000000..edc106b
--- a/dev/null
+++ b/noncore/games/go/qpe-go.control
@@ -0,0 +1,9 @@
1Files: bin/go apps/Games/go.desktop
2Priority: optional
3Section: qpe/games
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: The game of Go
9 A game for the Qtopia environment.
diff --git a/noncore/games/mindbreaker/.cvsignore b/noncore/games/mindbreaker/.cvsignore
new file mode 100644
index 0000000..415ec09
--- a/dev/null
+++ b/noncore/games/mindbreaker/.cvsignore
@@ -0,0 +1,4 @@
1Makefile
2moc_*
3helpdialog.cpp
4helpdialog.h
diff --git a/noncore/games/mindbreaker/Makefile.in b/noncore/games/mindbreaker/Makefile.in
new file mode 100644
index 0000000..88f6fb1
--- a/dev/null
+++ b/noncore/games/mindbreaker/Makefile.in
@@ -0,0 +1,117 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= mindbreaker
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =mindbreaker.h
27 SOURCES =main.cpp \
28 mindbreaker.cpp
29 OBJECTS =main.o \
30 mindbreaker.o
31INTERFACES =
32UICDECLS =
33UICIMPLS =
34 SRCMOC =moc_mindbreaker.cpp
35 OBJMOC =moc_mindbreaker.o
36
37
38####### Implicit rules
39
40.SUFFIXES: .cpp .cxx .cc .C .c
41
42.cpp.o:
43 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
44
45.cxx.o:
46 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
47
48.cc.o:
49 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
50
51.C.o:
52 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
53
54.c.o:
55 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
56
57####### Build rules
58
59
60all: $(DESTDIR)$(TARGET)
61
62$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
63 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
64
65moc: $(SRCMOC)
66
67tmake:
68 tmake mindbreaker.pro
69
70clean:
71 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
72 -rm -f *~ core
73 -rm -f allmoc.cpp
74
75####### Extension Modules
76
77listpromodules:
78 @echo
79
80listallmodules:
81 @echo
82
83listaddonpromodules:
84 @echo
85
86listaddonentmodules:
87 @echo
88
89
90REQUIRES=
91
92####### Sub-libraries
93
94
95###### Combined headers
96
97
98
99####### Compile
100
101main.o: main.cpp \
102 mindbreaker.h \
103 $(QPEDIR)/include/qpe/qpeapplication.h
104
105mindbreaker.o: mindbreaker.cpp \
106 mindbreaker.h \
107 $(QPEDIR)/include/qpe/resource.h \
108 $(QPEDIR)/include/qpe/config.h \
109 $(QPEDIR)/include/qpe/qpetoolbar.h
110
111moc_mindbreaker.o: moc_mindbreaker.cpp \
112 mindbreaker.h
113
114moc_mindbreaker.cpp: mindbreaker.h
115 $(MOC) mindbreaker.h -o moc_mindbreaker.cpp
116
117
diff --git a/noncore/games/mindbreaker/main.cpp b/noncore/games/mindbreaker/main.cpp
new file mode 100644
index 0000000..8ba0fde
--- a/dev/null
+++ b/noncore/games/mindbreaker/main.cpp
@@ -0,0 +1,35 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "mindbreaker.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char **argv )
26{
27 QPEApplication a( argc, argv );
28
29 MindBreaker w(0, "new window");
30 w.setCaption("Mind Breaker");
31 QPEApplication::setInputMethodHint( &w, QPEApplication::AlwaysOff );
32 a.showMainWidget(&w);
33
34 return a.exec();
35}
diff --git a/noncore/games/mindbreaker/mindbreaker.cpp b/noncore/games/mindbreaker/mindbreaker.cpp
new file mode 100644
index 0000000..b0e4d88
--- a/dev/null
+++ b/noncore/games/mindbreaker/mindbreaker.cpp
@@ -0,0 +1,818 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "mindbreaker.h"
22
23#include <qpe/resource.h>
24#include <qpe/config.h>
25
26#include <qpainter.h>
27#include <qpixmap.h>
28#include <qpe/qpetoolbar.h>
29#include <qtoolbutton.h>
30#include <qpushbutton.h>
31#include <qmessagebox.h>
32#include <qlabel.h>
33#include <qstyle.h>
34
35#include <stdlib.h>
36#include <sys/time.h>
37#include <unistd.h>
38
39static int pegRTTI = 3393393;
40
41/* helper class, */
42class Peg : public QCanvasRectangle
43{
44public:
45 Peg(QCanvas *canvas, int type, int go = -1, int pos = -1);
46 int rtti() const {return pegRTTI; }
47 void advance(int phase);
48
49 bool hit( const QPoint &) const;
50
51/* a placed peg is one that has been set down on the board correctly and
52 should not be moved, only copied */
53 bool placed() const;
54 void setPlaced(bool);
55
56 int pegGo() const;
57 int pegPos() const;
58 void setPegPos(int);
59
60 int type() const;
61
62 static void buildImages();
63 static QImage imageForType(int t);
64
65 static int eggLevel;
66
67protected:
68 void drawShape(QPainter &);
69private:
70 static QVector<QImage> normalPegs;
71 static QVector<QImage> specialPegs;
72
73 bool isplaced;
74 int pegtype;
75 int peg_go;
76 int peg_pos;
77
78 int aniStep;
79};
80
81int Peg::eggLevel = 0;
82QVector<QImage> Peg::normalPegs;
83QVector<QImage> Peg::specialPegs;
84
85void Peg::buildImages()
86{
87
88 QImage pegs = Resource::loadImage("mindbreaker/pegs");
89 int x = 0;
90 int y = 0;
91 int i;
92 eggLevel = 0;
93 normalPegs.resize(10);
94 for (i = 0; i < 6; i++) {
95 normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size)));
96 x += peg_size;
97 }
98 specialPegs.resize(5);
99 for (i = 0; i < 5; i++) {
100 specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size)));
101 x += peg_size;
102 }
103
104 QImage image = Resource::loadImage("mindbreaker/mindbreaker");
105 /* copy from master image to functional images */
106 x = 0;
107 y = panel_height;
108 normalPegs.insert(8,
109 new QImage(image.copy(x, y, panel_width, panel_height)));
110 y += panel_height;
111 y += title_height;
112 normalPegs.insert(9,
113 new QImage(image.copy(x, y, title_width, title_height)));
114 y += title_height;
115
116 x = 6 * peg_size;
117 normalPegs.insert(6,
118 new QImage(image.copy(x, y, answerpeg_size, answerpeg_size)));
119 x += answerpeg_size;
120 normalPegs.insert(7,
121 new QImage(image.copy(x, y, answerpeg_size, answerpeg_size)));
122}
123
124QImage Peg::imageForType(int t)
125{
126 if (eggLevel > t ) {
127 if( t < 5) {
128 return *specialPegs[t];
129 } else {
130 return *normalPegs[rand() % 6];
131 }
132 }
133 return *normalPegs[t];
134}
135
136Peg::Peg(QCanvas *canvas , int t, int g = -1, int p = -1)
137 : QCanvasRectangle(canvas)
138{
139 setSize(normalPegs[t]->width(), normalPegs[t]->height() );
140 pegtype = t;
141 isplaced = FALSE;
142 peg_pos = p;
143 peg_go = g;
144 aniStep = rand() % 6;
145 setAnimated(TRUE);
146}
147
148void Peg::advance(int phase) {
149 if (phase == 0)
150 aniStep = (++aniStep) % 6;
151 else {
152 hide();
153 show();
154 }
155}
156
157void Peg::drawShape(QPainter &p )
158{
159 if ((pegtype == 5) && eggLevel > 5) {
160 p.drawImage(x(), y(), *normalPegs[aniStep]);
161 } else
162 p.drawImage(x(), y(), imageForType(pegtype));
163}
164
165bool Peg::hit( const QPoint &p ) const
166{
167 int ix = p.x() - int(x());
168 int iy = p.y() - int(y());
169 if (!normalPegs[pegtype]->valid(ix, iy))
170 return FALSE;
171 QRgb pixel = normalPegs[pegtype]->pixel(ix, iy);
172 return (qAlpha(pixel ) != 0);
173}
174
175inline bool Peg::placed() const
176{
177 return isplaced;
178}
179
180inline int Peg::pegGo() const
181{
182 return peg_go;
183}
184
185inline int Peg::pegPos() const
186{
187 return peg_pos;
188}
189
190inline void Peg::setPegPos(int p)
191{
192 peg_pos = p;
193}
194
195inline void Peg::setPlaced(bool p)
196{
197 isplaced = p;
198}
199
200inline int Peg::type() const
201{
202 return pegtype;
203}
204
205/* Load the main image, copy from it the pegs, the board, and the answer image
206 * and use these to create the tray, answer and board
207 */
208MindBreaker::MindBreaker( QWidget *parent=0, const char *name=0, int wFlags=0 )
209: QMainWindow(parent, name, wFlags),
210 canvas(board_height, board_width)
211{
212 MindBreakerBoard *m = new MindBreakerBoard(canvas, this);
213 setCentralWidget(m);
214
215 setToolBarsMovable( FALSE );
216
217 QPEToolBar *tb = new QPEToolBar(this);
218 tb->setHorizontalStretchable( TRUE );
219
220 QPixmap newicon = Resource::loadPixmap("new");
221 new QToolButton(newicon, tr("New Game"), 0,
222 m, SLOT(clear()), tb, "NewGame");
223
224 score = new QToolButton(tb);
225 score->setText("");
226 score->setMaximumHeight(20);
227 score->setUsesTextLabel(TRUE);
228 tb->setStretchableWidget(score);
229
230 connect(m, SIGNAL(scoreChanged(int, int)), this, SLOT(setScore(int, int)));
231 connect(score, SIGNAL(clicked()), m, SLOT(resetScore()));
232
233 int a, b;
234 m->getScore(&a, &b);
235 setScore(a,b);
236}
237
238void MindBreaker::setScore(int turns, int games)
239{
240 double average;
241 double total_turns = turns;
242 double total_games = games;
243
244 if(total_games > 0)
245 average = total_turns / total_games;
246 else
247 average = 0.0;
248
249 score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games));
250}
251
252
253MindBreakerBoard::MindBreakerBoard( QCanvas &c, QWidget *parent=0,
254 const char *name=0, int wFlags=0 )
255 : QCanvasView(&c, parent, name, wFlags)
256{
257 int i, x, y;
258 struct timeval tv;
259
260 current_go = 0;
261 gettimeofday(&tv, 0);
262
263 srand(tv.tv_usec);
264
265 canvas()->setAdvancePeriod(500);
266
267 QImage image = Resource::loadImage("mindbreaker/mindbreaker");
268
269 /* copy from master image to functional images */
270 x = 0;
271 y = 0;
272 panelImage = image.copy(x,y, panel_width, panel_height);
273 y += panel_height;
274 y += panel_height;
275
276 titleImage = image.copy(x, y, title_width, title_height);
277
278 Peg::buildImages(); // must be done BEFORE any pegs are made
279
280 current_highlight = new Peg(canvas(), 8);
281 current_highlight->setPlaced(TRUE);
282 current_highlight->setX(0);
283 current_highlight->setY(board_height - ((current_go + 1) * panel_height));
284 current_highlight->setZ(0);
285 current_highlight->show();
286
287
288 /* set up the game */
289 Config c("MindBreaker", Config::User);
290 c.setGroup("Board");
291 game_over = FALSE;
292 if (c.readNumEntry("Answer0") < 0) {
293 for (i = 0; i < 4; i++) {
294 answer[i] = rand() % 6;
295 current_guess[i] = 6;
296 }
297 total_turns = 0;
298 total_games = 0;
299 } else {
300 int j;
301 c.setGroup("Score");
302 total_turns = c.readNumEntry("Turns");
303 total_games = c.readNumEntry("Games");
304 if(total_turns < 0)
305 total_turns = 0;
306 if(total_games < 0)
307 total_games = 0;
308
309
310 checkScores();
311 c.setGroup("Board");
312 for(i = 0; i < 4; i++)
313 answer[i] = c.readNumEntry(QString("Answer%1").arg(i));
314 /* read, and parse past guesses */
315 current_go = 0;
316 for(j=0; j < 9; j++) {
317 current_guess[0] = c.readNumEntry(QString("Go%1p0").arg(j));
318 if (current_guess[0] < 0)
319 break;
320 placeGuessPeg(0, current_guess[0]);
321 current_guess[1] = c.readNumEntry(QString("Go%1p1").arg(j));
322 placeGuessPeg(1, current_guess[1]);
323 current_guess[2] = c.readNumEntry(QString("Go%1p2").arg(j));
324 placeGuessPeg(2, current_guess[2]);
325 current_guess[3] = c.readNumEntry(QString("Go%1p3").arg(j));
326 placeGuessPeg(3, current_guess[3]);
327 checkGuess();
328 }
329 for(i = 0; i < 4; i++) {
330 current_guess[i] = c.readNumEntry(QString("CurrentGo%1").arg(i));
331 if (current_guess[i] != 6)
332 placeGuessPeg(i, current_guess[i]);
333 }
334 }
335
336 /* draw initial screen */
337 drawBackground();
338 canvas()->update();
339}
340
341MindBreakerBoard::~MindBreakerBoard()
342{
343 int i, j;
344 if (game_over) {
345 current_go = 0;
346 /* clear the answer, clear the guess */
347 for (i = 0; i < 4; i++) {
348 answer[i] = rand() % 6;
349 current_guess[i] = 6;
350 }
351 }
352
353 Config c("MindBreaker", Config::User);
354 c.setGroup("Board");
355 c.clearGroup();
356 /* write the board */
357 for (i = 0; i < current_go; i++) {
358 for(j = 0; j < 4; j++)
359 c.writeEntry(tr("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]);
360 }
361 for(j = 0; j < 4; j++)
362 c.writeEntry(tr("CurrentGo%1").arg(j), current_guess[j]);
363 for(j = 0; j < 4; j++)
364 c.writeEntry(tr("Answer%1").arg(j), answer[j]);
365
366 c.setGroup("Score");
367 /* write the score */
368
369 c.writeEntry("Turns", total_turns);
370 c.writeEntry("Games", total_games);
371}
372
373void MindBreakerBoard::getScore(int *a, int *b)
374{
375 *a = total_turns;
376 *b = total_games;
377 return;
378}
379
380void MindBreakerBoard::placeGuessPeg(int pos, int pegId)
381{
382 int x = first_peg_x_diff + (pos * peg_spacing);
383 int y = board_height - ((current_go + 1) * panel_height)
384 + first_peg_y_diff;
385
386 Peg *peg = new Peg(canvas(), pegId, current_go, pos);
387 peg->setPegPos(pos);
388 peg->setPlaced(TRUE);
389 peg->setX(x);
390 peg->setY(y);
391 peg->setZ(2);
392 peg->show();
393}
394
395void MindBreakerBoard::drawBackground()
396{
397 int i, j, x, y, x_gap, y_gap;
398 QPixmap background = QPixmap(canvas()->width(), canvas()->height());
399
400 QPainter painter(&background);
401
402 painter.fillRect(0, 0, canvas()->width(), canvas()->height(), QColor(0,0,0));
403 /* very first thing is to draw the bins, as everything else needs
404 * to be drawn over them */
405
406 QPen pen(QColor(85, 45, 27), 4);
407 painter.setPen(pen);
408 x_gap = canvas()->width() - (panel_width + (2 * bin_margin));
409 //x_gap += peg_size >> 1;
410 if (x_gap < 1)
411 x_gap = 1;
412
413 y_gap = board_height / 6;
414 y_gap -= (2 * bin_margin);
415 //y_gap += peg_size >> 1;
416 if (y_gap < 1)
417 y_gap = 1;
418 x = panel_width + bin_margin - (peg_size >> 1);
419 y = bin_margin - (peg_size >> 1) + 2;
420
421 for (i = 0; i < 6; i++) {
422 for (j = 0; j < 10; j++) {
423 int rx = x + (rand() % x_gap);
424 int ry = y + (rand() % y_gap);
425 painter.drawImage(rx,ry, Peg::imageForType(i));
426 }
427 y += board_height / 6;
428 }
429 /* now draw the surrounding boxes */
430 x_gap = canvas()->width() - panel_width;
431 if (x_gap < 1) x_gap = 1;
432 y_gap = board_height / 6;
433 x = panel_width;
434 y = 1;
435
436 for (i = 0; i < 6; i++) {
437 painter.drawRect(x, y, x_gap, y_gap);
438 y += y_gap;
439 }
440
441 x = 0;
442 y = 0;
443
444 painter.drawImage(x,y, titleImage);
445 y = title_height;
446 /* now nine gues panels */
447 for (i = 0; i < 9; i ++) {
448 painter.drawImage(x, y, panelImage);
449 y += panel_height;
450 }
451
452 painter.flush();
453 canvas()->setBackgroundPixmap(background);
454}
455
456void MindBreakerBoard::checkGuess()
457{
458 int i,j;
459 int num_white = 0;
460 int num_black = 0;
461 int copy_answer[4];
462 int copy_guess[4];
463
464 for(i = 0; i < 4; i++) {
465 copy_answer[i] = answer[i];
466 copy_guess[i] = current_guess[i];
467 if (current_guess[i] == 6)
468 return;
469 if (answer[i] == current_guess[i]) {
470 num_black++;
471 copy_answer[i] = 6;
472 copy_guess[i] = 7;
473 }
474 }
475
476 /* now sure that user has completed a 'guess' */
477 for (i = 0; i < 4; i++) {
478 if (copy_guess[i] == 7)
479 continue; // already marked for a black
480 for (j = 0; j < 4; j++) {
481 if(copy_guess[i] == copy_answer[j]) {
482 copy_answer[j] = 6;
483 num_white++;
484 break;
485 }
486 }
487 }
488
489 int x = answerpegx;
490 int y = (board_height - ((current_go + 1) * panel_height)) + answerpegy;
491
492 if (num_black == 4)
493 game_over = TRUE;
494
495 while(num_black > 0) {
496 Peg *p = new Peg(canvas(), 7);
497 p->setPlaced(TRUE);
498 p->setX(x);
499 p->setY(y);
500 p->setZ(1);
501 p->show();
502 num_black--;
503
504 if (x == answerpegx)
505 x = answerpegx + answerpeg_diff;
506 else {
507 x = answerpegx;
508 y += answerpeg_diff;
509 }
510 }
511 while(num_white > 0){
512 Peg *p = new Peg(canvas(), 6);
513 p->setPlaced(TRUE);
514 p->setX(x);
515 p->setY(y);
516 p->setZ(1);
517 p->show();
518 num_white--;
519
520 if (x == answerpegx)
521 x = answerpegx + answerpeg_diff;
522 else {
523 x = answerpegx;
524 y += answerpeg_diff;
525 }
526 }
527 /* move to next go */
528 for(i = 0; i < 4; i++) {
529 past_guesses[4*current_go+i] = current_guess[i];
530 current_guess[i] = 6;
531 }
532
533 current_go++;
534 if((current_go > 8) || game_over) {
535 total_games++;
536 if(!game_over)
537 total_turns += 10;
538 else
539 total_turns += current_go;
540
541 emit scoreChanged(total_turns, total_games);
542 Peg *p = new Peg(canvas(), 9);
543 game_over = TRUE;
544 p->setPlaced(TRUE);
545 p->setX(0);
546 p->setY(0);
547 p->setZ(0);
548 p->show();
549
550 for (i = 0; i < 4; i++) {
551 p = new Peg(canvas(), answer[i], -1);
552 p->setX(first_peg_x_diff + (i * peg_spacing));
553 p->setY(5);
554 p->setZ(3);
555 p->show();
556 }
557 } else {
558 current_highlight->setY(board_height - ((current_go + 1) * panel_height));
559 }
560 canvas()->update();
561}
562
563void MindBreakerBoard::clear()
564{
565 if(!game_over) {
566 total_games++;
567 total_turns += 10;
568 emit scoreChanged(total_turns, total_games);
569 }
570 int i;
571 /* reset the game board */
572 game_over = FALSE;
573 /* clear the answer, clear the guess */
574 for (i = 0; i < 4; i++) {
575 answer[i] = rand() % 6;
576 current_guess[i] = 6;
577 }
578 current_go = 0;
579
580 QCanvasItemList list = canvas()->allItems();
581 QCanvasItemList::Iterator it = list.begin();
582 for (; it != list.end(); ++it) {
583 if (*it == current_highlight)
584 continue;
585 if (*it)
586 delete *it;
587 }
588
589 current_highlight->setY(board_height - ((current_go + 1) * panel_height));
590 checkScores();
591 drawBackground();
592 canvas()->update();
593}
594
595void MindBreakerBoard::resetScore()
596{
597 /* are u sure */
598
599 if (QMessageBox::information(this, tr( "Reset Statistics" ),
600 tr( "Reset the win ratio?" ),
601 tr( "OK" ), tr( "Cancel" ) ) == 0) {
602 total_turns = 0;
603 total_games = 0;
604 Peg::eggLevel = 0;
605 drawBackground();
606 canvas()->update();
607 emit scoreChanged(total_turns, total_games);
608 }
609}
610
611/* EVENTS */
612
613void MindBreakerBoard::contentsMousePressEvent(QMouseEvent *e)
614{
615 copy_press = FALSE;
616 null_press = FALSE;
617 /* ok, first work out if it is one of the bins that
618 got clicked */
619 if (e->x() > panel_width) {
620 /* its a bin, but which bin */
621 if(e->y() > board_height)
622 return; // missed everything
623 int bin = (e->y() + 2) / (board_height / 6);
624
625 /* make new peg... set it moving */
626 moving_pos = e->pos();
627 moving = new Peg(canvas(), bin, current_go);
628 moving->setX(e->x() - (peg_size >> 1));
629 moving->setY(e->y() - (peg_size >> 1));
630 moving->setZ(5);
631 moving->show();
632 canvas()->update();
633 return;
634 }
635
636 QCanvasItemList l = canvas()->collisions(e->pos());
637 for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) {
638 if ( (*it)->rtti() == pegRTTI ) {
639 Peg *item = (Peg *)(*it);
640 if (!item->hit(e->pos()))
641 continue;
642 if (item->type() > 5) {
643 null_press = TRUE;
644 null_point = e->pos();
645 continue; /* not a color peg */
646 }
647 if (item->placed()) {
648 /* copy */
649 if(item->pegGo() == -1)
650 return;
651 if(item->pegGo() == current_go) {
652 copy_press = TRUE;
653 copy_peg = item;
654 }
655 moving = new Peg(canvas(),
656 item->type(), current_go);
657 moving->setX(e->x() - (peg_size >> 1));
658 moving->setY(e->y() - (peg_size >> 1));
659 moving->setZ(5);
660 moving->show();
661 moving_pos = QPoint(e->x(), e->y());
662 canvas()->update();
663 return;
664 }
665 moving = (Peg *)*it;
666 moving_pos = e->pos();
667 canvas()->update();
668 return;
669 }
670 }
671 null_press = TRUE;
672 null_point = e->pos();
673 moving = 0;
674}
675
676void MindBreakerBoard::contentsMouseMoveEvent(QMouseEvent* e)
677{
678 if (moving ) {
679 moving->moveBy(e->pos().x() - moving_pos.x(),
680 e->pos().y() - moving_pos.y());
681 moving_pos = e->pos();
682 canvas()->update();
683 return;
684 }
685}
686
687void MindBreakerBoard::contentsMouseReleaseEvent(QMouseEvent* e)
688{
689 /* time to put down the peg */
690 if(moving) {
691 if(copy_press) {
692 /* check if collided with original. if so, delete both */
693 copy_press = FALSE;
694 QCanvasItemList l = canvas()->collisions(e->pos());
695 for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) {
696 if (*it == copy_peg)
697 copy_press = TRUE;
698 }
699 if (copy_press) {
700 current_guess[copy_peg->pegPos()] = 6;
701 delete copy_peg;
702 delete moving;
703 copy_press = FALSE;
704 moving = 0;
705 copy_peg = 0;
706 canvas()->update();
707 return;
708 }
709 }
710
711 /* first work out if in y */
712 if (e->y() > (board_height - (current_go * panel_height))) {
713 delete moving;
714 moving = 0;
715 canvas()->update();
716 return;
717 }
718 if (e->y() < (board_height - ((current_go + 1) * panel_height))) {
719 delete moving;
720 moving = 0;
721 canvas()->update();
722 return;
723 }
724 /* ok, a valid go, but which peg */
725 int x_bar = first_peg_x_diff - (peg_size >> 1);
726 x_bar += peg_spacing;
727 int pos = 0;
728 if (e->x() > x_bar)
729 pos = 1;
730 x_bar += peg_spacing;
731 if (e->x() > x_bar)
732 pos = 2;
733 x_bar += peg_spacing;
734 if (e->x() > x_bar)
735 pos = 3;
736 x_bar += peg_spacing;
737
738 if (e->x() > x_bar) {
739 /* invalid x */
740 delete moving;
741 moving = 0;
742 canvas()->update();
743 return;
744 }
745
746 int x = first_peg_x_diff + (pos * peg_spacing);
747 int y = board_height - ((current_go + 1) * panel_height)
748 + first_peg_y_diff;
749 moving->setPegPos(pos);
750 moving->setX(x);
751 moving->setY(y);
752 moving->setZ(2);
753
754 /* remove all other pegs from this position */
755 QCanvasItemList l = canvas()->collisions(QPoint(x,y));
756 for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) {
757 if ( (*it)->rtti() == pegRTTI ) {
758 Peg *item = (Peg *)(*it);
759 if ((item != moving) && (item != current_highlight))
760 delete item;
761 }
762 }
763 current_guess[pos] = ((Peg *)moving)->type();
764
765 ((Peg *)moving)->setPlaced(true);
766 canvas()->update();
767 return;
768 }
769 moving = 0;
770 null_point -= e->pos();
771 if(null_point.manhattanLength() < 6) {
772 if (game_over)
773 clear();
774 else
775 checkGuess();
776 }
777}
778
779void MindBreakerBoard::resizeEvent(QResizeEvent *e)
780{
781 QSize s = e->size();
782 int fw = style().defaultFrameWidth();
783 s.setWidth(s.width() - fw);
784 s.setHeight(s.height() - fw);
785
786 /* min size is 200 x 260 */
787 if (s.width() < board_width)
788 s.setWidth(board_width);
789
790 if (s.height() < board_height)
791 s.setHeight(board_height);
792
793 canvas()->resize(s.width() - fw, s.height() - fw);
794 drawBackground();
795}
796
797
798/* Easter egg function... beat the clock */
799void MindBreakerBoard::checkScores()
800{
801 double games = total_games;
802 double turns = total_turns;
803 double g = games / 10.0;
804 Peg::eggLevel = 0;
805
806 double break_even = 5.0;
807 if (g < 1.0)
808 return;
809 double avg = turns / games;
810 g--;
811 while (break_even >= 0.0) {
812 if (avg >= (break_even + g))
813 return;
814 // score a peg.
815 break_even -= 1.0;
816 Peg::eggLevel = int(5.0 - break_even);
817 }
818}
diff --git a/noncore/games/mindbreaker/mindbreaker.h b/noncore/games/mindbreaker/mindbreaker.h
new file mode 100644
index 0000000..fca649a
--- a/dev/null
+++ b/noncore/games/mindbreaker/mindbreaker.h
@@ -0,0 +1,122 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef MINDBREAKER_H
22#define MINDBREAKER_H
23
24#include <qwidget.h>
25#include <qmainwindow.h>
26#include <qimage.h>
27#include <qvector.h>
28#include <qcanvas.h>
29#include <qlabel.h>
30
31static const int panel_height = 26;
32static const int panel_width = 180;
33
34static const int title_height = 25;
35static const int title_width = 180;
36
37static const int bin_margin = 10;
38static const int peg_size = 20;
39static const int answerpeg_size = 13;
40
41static const int first_peg_x_diff = 21;
42static const int first_peg_y_diff = ((panel_height - peg_size) >> 1);
43static const int peg_spacing = 30;
44
45static const int answerpegx = 152;
46static const int answerpegy = 2;
47static const int answerpeg_diff = 9;
48
49static const int board_height = (title_height + (panel_height * 9));
50static const int board_width = (panel_width + (bin_margin * 2) + peg_size);
51
52class Peg;
53class QToolButton;
54
55class MindBreakerBoard : public QCanvasView // QWidget
56{
57 Q_OBJECT
58public:
59 MindBreakerBoard(QCanvas &c, QWidget *parent=0, const char *name=0, int wFlags=0 );
60 ~MindBreakerBoard();
61
62 void getScore(int *, int *);
63signals:
64 void scoreChanged(int, int);
65
66public slots:
67 void clear();
68 void resetScore();
69
70protected:
71 void contentsMousePressEvent(QMouseEvent *);
72 void contentsMouseMoveEvent(QMouseEvent *);
73 void contentsMouseReleaseEvent(QMouseEvent *);
74 void resizeEvent(QResizeEvent *);
75
76private:
77 void drawBackground();
78 void checkGuess();
79 void checkScores();
80 void placeGuessPeg(int pos, int pegId);
81
82 QImage panelImage;
83 QImage titleImage;
84
85 Peg *moving;
86 Peg *current_highlight;
87 QPoint moving_pos;
88
89 // the game stuff
90 int answer[4];
91 int current_guess[4];
92 int past_guesses[4*9];
93 int current_go;
94
95 int null_press;
96 QPoint null_point;
97 bool copy_press;
98 Peg *copy_peg;
99 bool game_over;
100
101 int total_turns;
102 int total_games;
103};
104
105class MindBreaker : public QMainWindow // QWidget
106{
107 Q_OBJECT
108public:
109 MindBreaker(QWidget *parent=0, const char *name=0, int wFlags=0 );
110
111public slots:
112 void setScore(int, int);
113
114private:
115 QCanvas canvas;
116 MindBreakerBoard *board;
117 QToolButton *score;
118
119};
120
121
122#endif
diff --git a/noncore/games/mindbreaker/mindbreaker.pro b/noncore/games/mindbreaker/mindbreaker.pro
new file mode 100644
index 0000000..12944d1
--- a/dev/null
+++ b/noncore/games/mindbreaker/mindbreaker.pro
@@ -0,0 +1,12 @@
1TEMPLATE = app
2CONFIG += qt warn_on release
3DESTDIR = $(QPEDIR)/bin
4 HEADERS = mindbreaker.h
5 SOURCES = main.cpp \
6 mindbreaker.cpp
7TARGET = mindbreaker
8INCLUDEPATH += $(QPEDIR)/include
9DEPENDPATH += $(QPEDIR)/include
10LIBS += -lqpe
11
12TRANSLATIONS = ../i18n/de/mindbreaker.ts
diff --git a/noncore/games/mindbreaker/qpe-mindbreaker.control b/noncore/games/mindbreaker/qpe-mindbreaker.control
new file mode 100644
index 0000000..3bad93d
--- a/dev/null
+++ b/noncore/games/mindbreaker/qpe-mindbreaker.control
@@ -0,0 +1,9 @@
1Files: bin/mindbreaker apps/Games/mindbreaker.desktop pics/mindbreaker
2Priority: optional
3Section: qpe/games
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Game: crack the coloured code
9 A game for the Qtopia environment.
diff --git a/noncore/games/minesweep/.cvsignore b/noncore/games/minesweep/.cvsignore
new file mode 100644
index 0000000..6fe2396
--- a/dev/null
+++ b/noncore/games/minesweep/.cvsignore
@@ -0,0 +1,2 @@
1moc_*
2Makefile
diff --git a/noncore/games/minesweep/Makefile.in b/noncore/games/minesweep/Makefile.in
new file mode 100644
index 0000000..9ed6234
--- a/dev/null
+++ b/noncore/games/minesweep/Makefile.in
@@ -0,0 +1,134 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= minesweep
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =minefield.h \
27 minesweep.h
28 SOURCES =main.cpp \
29 minefield.cpp \
30 minesweep.cpp
31 OBJECTS =main.o \
32 minefield.o \
33 minesweep.o
34INTERFACES =
35UICDECLS =
36UICIMPLS =
37 SRCMOC =moc_minefield.cpp \
38 moc_minesweep.cpp
39 OBJMOC =moc_minefield.o \
40 moc_minesweep.o
41
42
43####### Implicit rules
44
45.SUFFIXES: .cpp .cxx .cc .C .c
46
47.cpp.o:
48 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
49
50.cxx.o:
51 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
52
53.cc.o:
54 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
55
56.C.o:
57 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
58
59.c.o:
60 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
61
62####### Build rules
63
64
65all: $(DESTDIR)$(TARGET)
66
67$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
68 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
69
70moc: $(SRCMOC)
71
72tmake:
73 tmake minesweep.pro
74
75clean:
76 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
77 -rm -f *~ core
78 -rm -f allmoc.cpp
79
80####### Extension Modules
81
82listpromodules:
83 @echo
84
85listallmodules:
86 @echo
87
88listaddonpromodules:
89 @echo
90
91listaddonentmodules:
92 @echo
93
94
95REQUIRES=
96
97####### Sub-libraries
98
99
100###### Combined headers
101
102
103
104####### Compile
105
106main.o: main.cpp \
107 minesweep.h \
108 $(QPEDIR)/include/qpe/qpeapplication.h
109
110minefield.o: minefield.cpp \
111 minefield.h \
112 $(QPEDIR)/include/qpe/config.h
113
114minesweep.o: minesweep.cpp \
115 minesweep.h \
116 minefield.h \
117 $(QPEDIR)/include/qpe/resource.h \
118 $(QPEDIR)/include/qpe/config.h \
119 $(QPEDIR)/include/qpe/qpetoolbar.h \
120 $(QPEDIR)/include/qpe/qpemenubar.h
121
122moc_minefield.o: moc_minefield.cpp \
123 minefield.h
124
125moc_minesweep.o: moc_minesweep.cpp \
126 minesweep.h
127
128moc_minefield.cpp: minefield.h
129 $(MOC) minefield.h -o moc_minefield.cpp
130
131moc_minesweep.cpp: minesweep.h
132 $(MOC) minesweep.h -o moc_minesweep.cpp
133
134
diff --git a/noncore/games/minesweep/main.cpp b/noncore/games/minesweep/main.cpp
new file mode 100644
index 0000000..83de9a3
--- a/dev/null
+++ b/noncore/games/minesweep/main.cpp
@@ -0,0 +1,34 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "minesweep.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char** argv )
26{
27 QPEApplication a( argc, argv );
28
29 MineSweep ms;
30 QPEApplication::setInputMethodHint( &ms, QPEApplication::AlwaysOff );
31 a.showMainWidget( &ms );
32
33 return a.exec();
34}
diff --git a/noncore/games/minesweep/minefield.cpp b/noncore/games/minesweep/minefield.cpp
new file mode 100644
index 0000000..be2f9a3
--- a/dev/null
+++ b/noncore/games/minesweep/minefield.cpp
@@ -0,0 +1,623 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "minefield.h"
21
22#include <qpe/config.h>
23
24#include <qpainter.h>
25#include <qdrawutil.h>
26#include <qpixmap.h>
27#include <qimage.h>
28#include <qtimer.h>
29
30#include <stdlib.h>
31
32static const char *pix_flag[]={
33"13 13 3 1",
34"# c #000000",
35"x c #ff0000",
36". c None",
37".............",
38".............",
39".....#xxxxxx.",
40".....#xxxxxx.",
41".....#xxxxxx.",
42".....#xxxxxx.",
43".....#.......",
44".....#.......",
45".....#.......",
46".....#.......",
47"...#####.....",
48"..#######....",
49"............."};
50
51static const char *pix_mine[]={
52"13 13 3 1",
53"# c #000000",
54". c None",
55"a c #ffffff",
56"......#......",
57"......#......",
58"..#.#####.#..",
59"...#######...",
60"..##aa#####..",
61"..##aa#####..",
62"#############",
63"..#########..",
64"..#########..",
65"...#######...",
66"..#.#####.#..",
67"......#......",
68"......#......"};
69
70class Mine : public QTableItem
71{
72public:
73 enum MineState {
74 Hidden = 0,
75 Empty,
76 Mined,
77 Flagged,
78#ifdef MARK_UNSURE
79 Unsure,
80#endif
81 Exploded,
82 Wrong
83 };
84
85 Mine( QTable* );
86 void paint( QPainter * p, const QColorGroup & cg, const QRect & cr, bool selected );
87 EditType editType() const { return Never; }
88 QSize sizeHint() const { return QSize( 12, 12 ); }
89
90 void activate( bool sure = TRUE );
91 void setHint( int );
92
93 void setState( MineState );
94 MineState state() const { return st; }
95
96 bool isMined() const { return mined; }
97 void setMined( bool m ) { mined = m; }
98
99 static void paletteChange();
100
101private:
102 bool mined;
103 int hint;
104
105 MineState st;
106
107 static QPixmap* knownField;
108 static QPixmap* unknownField;
109 static QPixmap* flag_pix;
110 static QPixmap* mine_pix;
111};
112
113QPixmap* Mine::knownField = 0;
114QPixmap* Mine::unknownField = 0;
115QPixmap* Mine::flag_pix = 0;
116QPixmap* Mine::mine_pix = 0;
117
118Mine::Mine( QTable *t )
119: QTableItem( t, Never, QString::null )
120{
121 mined = FALSE;
122 st = Hidden;
123 hint = 0;
124}
125
126void Mine::activate( bool sure )
127{
128 if ( !sure ) {
129 switch ( st ) {
130 case Hidden:
131 setState( Flagged );
132 break;
133 case Flagged:
134#ifdef MARK_UNSURE
135 setState( Unsure );
136 break;
137 case Unsure:
138#endif
139 setState( Hidden );
140 default:
141 break;
142 }
143 } else if ( st == Flagged ) {
144 return;
145 } else {
146 if ( mined ) {
147 setState( Exploded );
148 } else {
149 setState( Empty );
150 }
151 }
152}
153
154void Mine::setState( MineState s )
155{
156 st = s;
157}
158
159void Mine::setHint( int h )
160{
161 hint = h;
162}
163
164void Mine::paletteChange()
165{
166 delete knownField;
167 knownField = 0;
168 delete unknownField;
169 unknownField = 0;
170 delete mine_pix;
171 mine_pix = 0;
172 delete flag_pix;
173 flag_pix = 0;
174}
175
176void Mine::paint( QPainter* p, const QColorGroup &cg, const QRect& cr, bool )
177{
178 if ( !knownField ) {
179 knownField = new QPixmap( cr.width(), cr.height() );
180 QPainter pp( knownField );
181 QBrush br( cg.button().dark(115) );
182 qDrawWinButton( &pp, QRect(0,0,cr.width(), cr.height())/*cr*/, cg, TRUE, &br );
183 }
184
185 const int pmmarg=cr.width()/5;
186
187 if ( !unknownField ) {
188 unknownField = new QPixmap( cr.width(), cr.height() );
189 QPainter pp( unknownField );
190 QBrush br( cg.button() );
191 qDrawWinButton( &pp, QRect(0,0,cr.width(), cr.height())/*cr*/, cg, FALSE, &br );
192 }
193
194 if ( !flag_pix ) {
195 flag_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 );
196 flag_pix->convertFromImage( QImage(pix_flag).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) );
197 }
198
199 if ( !mine_pix ) {
200 mine_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 );
201 mine_pix->convertFromImage( QImage(pix_mine).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) );
202 }
203
204 p->save();
205
206 switch(st) {
207 case Hidden:
208 p->drawPixmap( 0, 0, *unknownField );
209 break;
210 case Empty:
211 p->drawPixmap( 0, 0, *knownField );
212 if ( hint > 0 ) {
213 switch( hint ) {
214 case 1:
215 p->setPen( blue );
216 break;
217 case 2:
218 p->setPen( green );
219 case 3:
220 p->setPen( red );
221 break;
222 default:
223 p->setPen( darkMagenta );
224 break;
225 }
226 p->drawText( QRect( 0, 0, cr.width(), cr.height() ), AlignHCenter | AlignVCenter, QString().setNum( hint ) );
227 }
228 break;
229 case Mined:
230 p->drawPixmap( 0, 0, *knownField );
231 p->drawPixmap( pmmarg, pmmarg, *mine_pix );
232 break;
233 case Exploded:
234 p->drawPixmap( 0, 0, *knownField );
235 p->drawPixmap( pmmarg, pmmarg, *mine_pix );
236 p->setPen( red );
237 p->drawText( QRect( 0, 0, cr.width(), cr.height() ), AlignHCenter | AlignVCenter, "X" );
238 break;
239 case Flagged:
240 p->drawPixmap( 0, 0, *unknownField );
241 p->drawPixmap( pmmarg, pmmarg, *flag_pix );
242 break;
243#ifdef MARK_UNSURE
244 case Unsure:
245 p->drawPixmap( 0, 0, *unknownField );
246 p->drawText( QRect( 0, 0, cr.width(), cr.height() ), AlignHCenter | AlignVCenter, "?" );
247 break;
248#endif
249 case Wrong:
250 p->drawPixmap( 0, 0, *unknownField );
251 p->drawPixmap( pmmarg, pmmarg, *flag_pix );
252 p->setPen( red );
253 p->drawText( QRect( 0, 0, cr.width(), cr.height() ), AlignHCenter | AlignVCenter, "X" );
254 break;
255 }
256
257 p->restore();
258}
259
260/*
261 MineField implementation
262*/
263
264MineField::MineField( QWidget* parent, const char* name )
265: QTable( parent, name )
266{
267 setState( GameOver );
268 setShowGrid( FALSE );
269 horizontalHeader()->hide();
270 verticalHeader()->hide();
271 setTopMargin( 0 );
272 setLeftMargin( 0 );
273
274 setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) );
275
276 setSelectionMode( QTable::NoSelection );
277 setFocusPolicy( QWidget::NoFocus );
278
279 setCurrentCell( -1, -1 );
280
281 connect( this, SIGNAL( pressed( int, int, int, const QPoint& ) ), this, SLOT( cellPressed( int, int ) ) );
282 connect( this, SIGNAL( clicked( int, int, int, const QPoint& ) ), this, SLOT( cellClicked( int, int ) ) );
283
284 holdTimer = new QTimer( this );
285 connect( holdTimer, SIGNAL( timeout() ), this, SLOT( held() ) );
286
287 flagAction = NoAction;
288 ignoreClick = FALSE;
289 currRow = currCol = 0;
290 minecount=0;
291 mineguess=0;
292 nonminecount=0;
293}
294
295MineField::~MineField()
296{
297}
298
299void MineField::setState( State st )
300{
301 stat = st;
302}
303
304
305void MineField::setup( int level )
306{
307 lev = level;
308 setState( Waiting );
309 viewport()->setUpdatesEnabled( FALSE );
310
311 int cellsize;
312
313 int x;
314 int y;
315 for ( x = 0; x < numCols(); x++ )
316 for ( y = 0; y < numRows(); y++ )
317 clearCell( y, x );
318
319 switch( lev ) {
320 case 1:
321 setNumRows( 9 );
322 setNumCols( 9 );
323 minecount = 12;
324 cellsize = 21;
325 break;
326 case 2:
327 setNumRows( 16 );
328 setNumCols( 16 );
329 minecount = 45;
330 cellsize = 14;
331 break;
332 case 3:
333 setNumRows( 18 );
334 setNumCols( 18 );
335 minecount = 66 ;
336 cellsize = 12;
337 break;
338 }
339 nonminecount = numRows()*numCols() - minecount;
340 mineguess = minecount;
341 emit mineCount( mineguess );
342 Mine::paletteChange();
343
344 for ( y = 0; y < numRows(); y++ )
345 setRowHeight( y, cellsize );
346 for ( x = 0; x < numCols(); x++ )
347 setColumnWidth( x, cellsize );
348 for ( x = 0; x < numCols(); x++ )
349 for ( y = 0; y < numRows(); y++ )
350 setItem( y, x, new Mine( this ) );
351
352 updateGeometry();
353 viewport()->setUpdatesEnabled( TRUE );
354 viewport()->repaint( TRUE );
355}
356
357
358void MineField::placeMines()
359{
360 int mines = minecount;
361 while ( mines ) {
362 int col = int((double(rand()) / double(RAND_MAX)) * numCols());
363 int row = int((double(rand()) / double(RAND_MAX)) * numRows());
364
365 Mine* mine = (Mine*)item( row, col );
366
367 if ( mine && !mine->isMined() && mine->state() == Mine::Hidden ) {
368 mine->setMined( TRUE );
369 mines--;
370 }
371 }
372}
373
374void MineField::paintFocus( QPainter*, const QRect& )
375{
376}
377
378void MineField::viewportMousePressEvent( QMouseEvent* e )
379{
380 QTable::viewportMousePressEvent( e );
381}
382
383void MineField::viewportMouseReleaseEvent( QMouseEvent* e )
384{
385 QTable::viewportMouseReleaseEvent( e );
386 if ( flagAction == FlagNext ) {
387 flagAction = NoAction;
388 }
389}
390
391void MineField::keyPressEvent( QKeyEvent* e )
392{
393#if defined(Q_WS_QWS) || defined(_WS_QWS_)
394 flagAction = ( e->key() == Key_Up ) ? FlagOn : NoAction;
395#else
396 flagAction = ( ( e->state() & ShiftButton ) == ShiftButton ) ? FlagOn : NoAction;
397#endif
398}
399
400void MineField::keyReleaseEvent( QKeyEvent* )
401{
402 flagAction = NoAction;
403}
404
405int MineField::getHint( int row, int col )
406{
407 int hint = 0;
408 for ( int c = col-1; c <= col+1; c++ )
409 for ( int r = row-1; r <= row+1; r++ ) {
410 Mine* mine = (Mine*)item( r, c );
411 if ( mine && mine->isMined() )
412 hint++;
413 }
414
415 return hint;
416}
417
418void MineField::setHint( Mine* mine )
419{
420 if ( !mine )
421 return;
422
423 int row = mine->row();
424 int col = mine->col();
425 int hint = getHint( row, col );
426
427 if ( !hint ) {
428 for ( int c = col-1; c <= col+1; c++ )
429 for ( int r = row-1; r <= row+1; r++ ) {
430 Mine* mine = (Mine*)item( r, c );
431 if ( mine && mine->state() == Mine::Hidden ) {
432 mine->activate( TRUE );
433 nonminecount--;
434 setHint( mine );
435 updateCell( r, c );
436 }
437 }
438 }
439
440 mine->setHint( hint );
441 updateCell( row, col );
442}
443
444/*
445 state == Waiting means no "hold"
446
447
448*/
449void MineField::cellPressed( int row, int col )
450{
451 if ( state() == GameOver )
452 return;
453 currRow = row;
454 currCol = col;
455 if ( state() == Playing )
456 holdTimer->start( 150, TRUE );
457}
458
459void MineField::held()
460{
461 flagAction = FlagNext;
462 updateMine( currRow, currCol );
463 ignoreClick = TRUE;
464}
465
466/*
467 Only place mines after first click, since it is pointless to
468 kill the player before the game has started.
469*/
470
471void MineField::cellClicked( int row, int col )
472{
473 if ( state() == GameOver )
474 return;
475 if ( state() == Waiting ) {
476 Mine* mine = (Mine*)item( row, col );
477 if ( !mine )
478 return;
479 mine->setState( Mine::Empty );
480 nonminecount--;
481 placeMines();
482 setState( Playing );
483 emit gameStarted();
484 updateMine( row, col );
485 } else { // state() == Playing
486 holdTimer->stop();
487 if ( ignoreClick )
488 ignoreClick = FALSE;
489 else
490 updateMine( row, col );
491 }
492}
493
494void MineField::updateMine( int row, int col )
495{
496 Mine* mine = (Mine*)item( row, col );
497 if ( !mine )
498 return;
499
500 bool wasFlagged = mine->state() == Mine::Flagged;
501 bool wasEmpty = mine->state() == Mine::Empty;
502
503 mine->activate( flagAction == NoAction );
504
505 if ( mine->state() == Mine::Exploded ) {
506 emit gameOver( FALSE );
507 setState( GameOver );
508 return;
509 } else if ( mine->state() == Mine::Empty ) {
510 setHint( mine );
511 if ( !wasEmpty )
512 nonminecount--;
513 }
514
515 if ( flagAction != NoAction ) {
516 if ( mine->state() == Mine::Flagged ) {
517 --mineguess;
518 emit mineCount( mineguess );
519 if ( mine->isMined() )
520 --minecount;
521 } else if ( wasFlagged ) {
522 ++mineguess;
523 emit mineCount( mineguess );
524 if ( mine->isMined() )
525 ++minecount;
526 }
527 }
528
529 updateCell( row, col );
530
531 if ( !minecount && !mineguess || !nonminecount ) {
532 emit gameOver( TRUE );
533 setState( GameOver );
534 }
535}
536
537void MineField::showMines()
538{
539 for ( int c = 0; c < numCols(); c++ )
540 for ( int r = 0; r < numRows(); r++ ) {
541 Mine* mine = (Mine*)item( r, c );
542 if ( !mine )
543 continue;
544 if ( mine->isMined() && mine->state() == Mine::Hidden )
545 mine->setState( Mine::Mined );
546 if ( !mine->isMined() && mine->state() == Mine::Flagged )
547 mine->setState( Mine::Wrong );
548
549 updateCell( r, c );
550 }
551}
552
553void MineField::paletteChange( const QPalette &o )
554{
555 Mine::paletteChange();
556 QTable::paletteChange( o );
557}
558
559void MineField::writeConfig(Config& cfg) const
560{
561 cfg.setGroup("Field");
562 cfg.writeEntry("Level",lev);
563 QString grid="";
564 if ( stat == Playing ) {
565 for ( int x = 0; x < numCols(); x++ )
566 for ( int y = 0; y < numRows(); y++ ) {
567 char code='A'+(x*17+y*101)%21; // Reduce the urge to cheat
568 Mine* mine = (Mine*)item( y, x );
569 int st = (int)mine->state(); if ( mine->isMined() ) st+=5;
570 grid += code + st;
571 }
572 }
573 cfg.writeEntry("Grid",grid);
574}
575
576void MineField::readConfig(Config& cfg)
577{
578 cfg.setGroup("Field");
579 lev = cfg.readNumEntry("Level",1);
580 setup(lev);
581 flagAction = NoAction;
582 ignoreClick = FALSE;
583 currRow = currCol = 0;
584 QString grid = cfg.readEntry("Grid");
585 if ( !grid.isEmpty() ) {
586 int i=0;
587 minecount=0;
588 mineguess=0;
589 for ( int x = 0; x < numCols(); x++ ) {
590 for ( int y = 0; y < numRows(); y++ ) {
591 char code='A'+(x*17+y*101)%21; // Reduce the urge to cheat
592 int st = (char)(QChar)grid[i++]-code;
593 Mine* mine = (Mine*)item( y, x );
594 if ( st >= 5 ) {
595 st-=5;
596 mine->setMined(TRUE);
597 minecount++;
598 mineguess++;
599 }
600 mine->setState((Mine::MineState)st);
601 switch ( mine->state() ) {
602 case Mine::Flagged:
603 if (mine->isMined())
604 minecount--;
605 mineguess--;
606 break;
607 case Mine::Empty:
608 --nonminecount;
609 }
610 }
611 }
612 for ( int x = 0; x < numCols(); x++ ) {
613 for ( int y = 0; y < numRows(); y++ ) {
614 Mine* mine = (Mine*)item( y, x );
615 if ( mine->state() == Mine::Empty )
616 mine->setHint(getHint(y,x));
617 }
618 }
619 }
620 setState( Playing );
621 emit mineCount( mineguess );
622}
623
diff --git a/noncore/games/minesweep/minefield.h b/noncore/games/minesweep/minefield.h
new file mode 100644
index 0000000..4ede435
--- a/dev/null
+++ b/noncore/games/minesweep/minefield.h
@@ -0,0 +1,87 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef MINEFIELD_H
21#define MINEFIELD_H
22
23#include <qtable.h>
24
25class Mine;
26class Config;
27
28class MineField : public QTable
29{
30 Q_OBJECT
31public:
32 MineField( QWidget* parent = 0, const char* name = 0 );
33 ~MineField();
34
35 enum State { Waiting, Playing, GameOver };
36
37 State state() const { return stat; }
38
39 void readConfig(Config&);
40 void writeConfig(Config&) const;
41
42 int level() const { return lev; }
43
44public slots:
45 void setup( int level );
46
47 void showMines();
48
49signals:
50 void gameOver( bool won );
51 void gameStarted();
52 void mineCount( int );
53
54protected:
55 void paintFocus( QPainter*, const QRect& );
56 void viewportMousePressEvent( QMouseEvent* );
57 void viewportMouseReleaseEvent( QMouseEvent* );
58 void keyPressEvent( QKeyEvent* );
59 void keyReleaseEvent( QKeyEvent* );
60
61 int getHint( int row, int col );
62 void setHint( Mine* );
63 void updateMine( int row, int col );
64 void paletteChange( const QPalette & );
65
66protected slots:
67 void cellPressed( int row, int col );
68 void cellClicked( int row, int col );
69 void held();
70
71private:
72 State stat;
73 void MineField::setState( State st );
74 void MineField::placeMines();
75 enum FlagAction { NoAction, FlagOn, FlagNext };
76 FlagAction flagAction;
77 bool ignoreClick;
78 int currRow;
79 int currCol;
80 int minecount;
81 int mineguess;
82 int nonminecount;
83 int lev;
84 QTimer *holdTimer;
85};
86
87#endif // MINEFIELD_H
diff --git a/noncore/games/minesweep/minesweep.cpp b/noncore/games/minesweep/minesweep.cpp
new file mode 100644
index 0000000..6492462
--- a/dev/null
+++ b/noncore/games/minesweep/minesweep.cpp
@@ -0,0 +1,390 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "minesweep.h"
22#include "minefield.h"
23
24#include <qpe/resource.h>
25#include <qpe/config.h>
26
27#include <qpe/qpetoolbar.h>
28#include <qpe/qpemenubar.h>
29#include <qpopupmenu.h>
30#include <qpushbutton.h>
31#include <qlcdnumber.h>
32#include <qmessagebox.h>
33#include <qtimer.h>
34#include <qpalette.h>
35#include <qapplication.h>
36#include <qlayout.h>
37#include <qlabel.h>
38
39#include <stdlib.h>
40#include <time.h>
41
42
43
44
45static const char *pix_new[]={
46"20 20 3 1",
47" c None",
48"# c #00FF00",
49". c #000000",
50" ",
51" ...... ",
52" ..######.. ",
53" .##########. ",
54" .############. ",
55" .##############. ",
56" .##############. ",
57" .################. ",
58" .################. ",
59" .################. ",
60" .################. ",
61" .################. ",
62" .################. ",
63" .##############. ",
64" .##############. ",
65" .############. ",
66" .##########. ",
67" ..######.. ",
68" ...... ",
69" "};
70
71
72/* XPM */
73static const char * happy_xpm[] = {
74"20 20 3 1",
75 " c None",
76 ".c #ffff3f ",
77 "#c #000000",
78" ",
79" ###### ",
80" ##......## ",
81" #..........# ",
82" #............# ",
83" #..............# ",
84" #..............# ",
85" #....##....##....# ",
86" #....##....##....# ",
87" #................# ",
88" #................# ",
89" #................# ",
90" #...#........#...# ",
91" #.##........##.# ",
92" #...########...# ",
93" #...######...# ",
94" #..........# ",
95" ##......## ",
96" ###### ",
97" "};
98
99
100/* XPM */
101static const char * worried_xpm[] = {
102"20 20 3 1",
103 " c None",
104 ".c #ffff3f",
105 "#c #000000",
106" ",
107" ###### ",
108" ##......## ",
109" #..........# ",
110" #............# ",
111" #..............# ",
112" #..............# ",
113" #....##....##....# ",
114" #....##....##....# ",
115" #................# ",
116" #................# ",
117" #................# ",
118" #................# ",
119" #....######....# ",
120" #..............# ",
121" #............# ",
122" #..........# ",
123" ##......## ",
124" ###### ",
125" "};
126
127
128/* XPM */
129static const char * dead_xpm[] = {
130"20 20 3 1",
131 " c None",
132 ".c #ffff3f",
133 "#c #000000",
134" ",
135" ###### ",
136" ##......## ",
137" #..........# ",
138" #............# ",
139" #..............# ",
140" #..#.#...#.#...# ",
141" #....#.....#.....# ",
142" #...#.#...#.#....# ",
143" #................# ",
144" #................# ",
145" #................# ",
146" #......####......# ",
147" #....# #....# ",
148" #...#......#...# ",
149" #............# ",
150" #..........# ",
151" ##......## ",
152" ###### ",
153" "};
154
155
156class ResultIndicator : private QLabel
157{
158public:
159 static void showResult( QWidget *ref, bool won );
160private:
161 ResultIndicator( QWidget *parent, const char *name, WFlags f)
162 :QLabel( parent, name, f ) {}
163
164 void timerEvent( QTimerEvent *);
165 void center();
166 bool twoStage;
167 int timerId;
168};
169
170void ResultIndicator::showResult( QWidget *ref, bool won )
171{
172 ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel );
173
174 r->setAlignment( AlignCenter );
175 r->setFrameStyle( Sunken|StyledPanel );
176 if ( won ) {
177 r->setText( MineSweep::tr("You won!") );
178 r->center();
179 r->show();
180 r->twoStage = FALSE;
181 r->timerId = r->startTimer(1500);
182 } else {
183 QPalette p( red );
184 r->setPalette( p );
185 r->setText( MineSweep::tr("You exploded!") );
186 r->resize( ref->size() );
187 r->move( ref->mapToGlobal(QPoint(0,0)) );
188 r->show();
189 r->twoStage = TRUE;
190 r->timerId =r->startTimer(200);
191 }
192}
193
194void ResultIndicator::center()
195{
196 QWidget *w = parentWidget();
197
198 QPoint pp = w->mapToGlobal( QPoint(0,0) );
199 QSize s = sizeHint()*3;
200 pp = QPoint( pp.x() + w->width()/2 - s.width()/2,
201 pp.y() + w->height()/ 2 - s.height()/2 );
202
203 setGeometry( QRect(pp, s) );
204
205}
206
207void ResultIndicator::timerEvent( QTimerEvent *te )
208{
209 if ( te->timerId() != timerId )
210 return;
211 killTimer( timerId );
212 if ( twoStage ) {
213 center();
214 twoStage = FALSE;
215 timerId = startTimer( 1000 );
216 } else {
217 delete this;
218 }
219}
220
221
222MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
223: QMainWindow( parent, name, f )
224{
225 srand(::time(0));
226 setCaption( tr("Mine Hunt") );
227 setIcon( Resource::loadPixmap( "minesweep_icon" ) );
228
229 QPEToolBar *menuToolBar = new QPEToolBar( this );
230 QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar );
231
232 QPopupMenu *gameMenu = new QPopupMenu( this );
233 gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) );
234 gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) );
235 gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) );
236
237 menuBar->insertItem( tr("Game"), gameMenu );
238
239 QPEToolBar *toolBar = new QPEToolBar( this );
240 toolBar->setHorizontalStretchable( TRUE );
241
242 guessLCD = new QLCDNumber( toolBar );
243 toolBar->setStretchableWidget( guessLCD );
244
245 QPalette lcdPal( red );
246 lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() );
247 lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() );
248
249// guessLCD->setPalette( lcdPal );
250 guessLCD->setSegmentStyle( QLCDNumber::Flat );
251 guessLCD->setFrameStyle( QFrame::NoFrame );
252 guessLCD->setNumDigits( 2 );
253 guessLCD->setBackgroundMode( PaletteButton );
254 newGameButton = new QPushButton( toolBar );
255 newGameButton->setPixmap( QPixmap( pix_new ) );
256 newGameButton->setFocusPolicy(QWidget::NoFocus);
257 connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) );
258
259 timeLCD = new QLCDNumber( toolBar );
260// timeLCD->setPalette( lcdPal );
261 timeLCD->setSegmentStyle( QLCDNumber::Flat );
262 timeLCD->setFrameStyle( QFrame::NoFrame );
263 timeLCD->setNumDigits( 5 ); // "mm:ss"
264 timeLCD->setBackgroundMode( PaletteButton );
265
266 setToolBarsMovable ( FALSE );
267
268 addToolBar( menuToolBar );
269 addToolBar( toolBar );
270
271 QFrame *mainframe = new QFrame( this );
272 mainframe->setFrameShape( QFrame::Box );
273 mainframe->setFrameShadow( QFrame::Raised );
274 mainframe->setMargin(5);
275 mainframe->setLineWidth(2);
276 QBoxLayout *box = new QVBoxLayout( mainframe );
277 field = new MineField( mainframe );
278 box->addWidget( field, 0, AlignCenter );
279 QFont fnt = field->font();
280 fnt.setBold( TRUE );
281 field->setFont( QFont( fnt ) );
282 field->setFocus();
283 setCentralWidget( mainframe );
284
285 connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) );
286 connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) );
287 connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) );
288
289 timer = new QTimer( this );
290
291 connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) );
292
293 readConfig();
294}
295
296MineSweep::~MineSweep()
297{
298 writeConfig();
299}
300
301void MineSweep::gameOver( bool won )
302{
303 field->showMines();
304 if ( won ) {
305 newGameButton->setPixmap( QPixmap( happy_xpm ) );
306 } else {
307 newGameButton->setPixmap( QPixmap( dead_xpm ) );
308 }
309 ResultIndicator::showResult( this, won );
310 timer->stop();
311}
312
313void MineSweep::newGame()
314{
315 newGame(field->level());
316}
317
318void MineSweep::newGame(int level)
319{
320 timeLCD->display( "0:00" );
321 field->setup( level );
322 newGameButton->setPixmap( QPixmap( pix_new ) );
323 timer->stop();
324}
325
326void MineSweep::startPlaying()
327{
328 newGameButton->setPixmap( QPixmap( worried_xpm ) );
329 starttime = QDateTime::currentDateTime();
330 timer->start( 1000 );
331}
332
333void MineSweep::beginner()
334{
335 newGame(1);
336}
337
338void MineSweep::advanced()
339{
340 newGame(2);
341}
342
343void MineSweep::expert()
344{
345 newGame(3);
346}
347
348void MineSweep::setCounter( int c )
349{
350 if ( !guessLCD )
351 return;
352
353 guessLCD->display( c );
354}
355
356void MineSweep::updateTime()
357{
358 if ( !timeLCD )
359 return;
360
361 int s = starttime.secsTo(QDateTime::currentDateTime());
362 if ( s/60 > 99 )
363 timeLCD->display( "-----" );
364 else
365 timeLCD->display( QString().sprintf("%2d:%02d",s/60,s%60) );
366}
367
368void MineSweep::writeConfig() const
369{
370 Config cfg("MineSweep");
371 cfg.setGroup("Panel");
372 cfg.writeEntry("Time",
373 timer->isActive() ? starttime.secsTo(QDateTime::currentDateTime()) : -1);
374 field->writeConfig(cfg);
375}
376
377void MineSweep::readConfig()
378{
379 Config cfg("MineSweep");
380 field->readConfig(cfg);
381 cfg.setGroup("Panel");
382 int s = cfg.readNumEntry("Time",-1);
383 if ( s<0 ) {
384 newGame();
385 } else {
386 startPlaying();
387 starttime = QDateTime::currentDateTime().addSecs(-s);
388 updateTime();
389 }
390}
diff --git a/noncore/games/minesweep/minesweep.h b/noncore/games/minesweep/minesweep.h
new file mode 100644
index 0000000..e860573
--- a/dev/null
+++ b/noncore/games/minesweep/minesweep.h
@@ -0,0 +1,67 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef MINESWEEP_H
21#define MINESWEEP_H
22
23#include <qmainwindow.h>
24#include <qdatetime.h>
25
26class MineField;
27class QLCDNumber;
28class QPushButton;
29
30class MineSweep : public QMainWindow
31{
32 Q_OBJECT
33public:
34 MineSweep( QWidget* parent = 0, const char* name = 0, WFlags f = 0 );
35 ~MineSweep();
36
37public slots:
38 void gameOver( bool won );
39 void newGame();
40
41protected slots:
42 void setCounter( int );
43 void updateTime();
44
45 void beginner();
46 void advanced();
47 void expert();
48
49private slots:
50 void startPlaying();
51
52private:
53 void readConfig();
54 void writeConfig() const;
55
56 void newGame(int);
57 MineField* field;
58 QLCDNumber* guessLCD;
59 QLCDNumber* timeLCD;
60 QPushButton* newGameButton;
61
62 QDateTime starttime;
63 QTimer* timer;
64};
65
66#endif // MINESWEEP_H
67
diff --git a/noncore/games/minesweep/minesweep.pro b/noncore/games/minesweep/minesweep.pro
new file mode 100644
index 0000000..87484bc
--- a/dev/null
+++ b/noncore/games/minesweep/minesweep.pro
@@ -0,0 +1,14 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 DESTDIR = $(QPEDIR)/bin
4 HEADERS = minefield.h \
5 minesweep.h
6 SOURCES = main.cpp \
7 minefield.cpp \
8 minesweep.cpp
9INCLUDEPATH += $(QPEDIR)/include
10 DEPENDPATH+= $(QPEDIR)/include
11LIBS += -lqpe
12 INTERFACES=
13
14TRANSLATIONS = ../i18n/de/minesweep.ts
diff --git a/noncore/games/minesweep/qpe-minesweep.control b/noncore/games/minesweep/qpe-minesweep.control
new file mode 100644
index 0000000..36bc221
--- a/dev/null
+++ b/noncore/games/minesweep/qpe-minesweep.control
@@ -0,0 +1,9 @@
1Files: bin/minesweep apps/Games/minesweep.desktop
2Priority: optional
3Section: qpe/games
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Game: find the mines
9 A game for the Qtopia environment.
diff --git a/noncore/games/parashoot/.cvsignore b/noncore/games/parashoot/.cvsignore
new file mode 100644
index 0000000..edfa921
--- a/dev/null
+++ b/noncore/games/parashoot/.cvsignore
@@ -0,0 +1,3 @@
1moc_*
2*.moc
3Makefile
diff --git a/noncore/games/parashoot/Makefile.in b/noncore/games/parashoot/Makefile.in
new file mode 100644
index 0000000..ff7397e
--- a/dev/null
+++ b/noncore/games/parashoot/Makefile.in
@@ -0,0 +1,203 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= parashoot
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =interface.h \
27 man.h \
28 cannon.h \
29 base.h \
30 bullet.h \
31 helicopter.h
32 SOURCES =main.cpp \
33 interface.cpp \
34 man.cpp \
35 cannon.cpp \
36 base.cpp \
37 bullet.cpp \
38 helicopter.cpp
39 OBJECTS =main.o \
40 interface.o \
41 man.o \
42 cannon.o \
43 base.o \
44 bullet.o \
45 helicopter.o
46INTERFACES =
47UICDECLS =
48UICIMPLS =
49 SRCMOC =moc_interface.cpp \
50 moc_cannon.cpp \
51 moc_bullet.cpp
52 OBJMOC =moc_interface.o \
53 moc_cannon.o \
54 moc_bullet.o
55
56
57####### Implicit rules
58
59.SUFFIXES: .cpp .cxx .cc .C .c
60
61.cpp.o:
62 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
63
64.cxx.o:
65 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
66
67.cc.o:
68 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
69
70.C.o:
71 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
72
73.c.o:
74 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
75
76####### Build rules
77
78
79all: $(DESTDIR)$(TARGET)
80
81$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
82 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
83
84moc: $(SRCMOC)
85
86tmake:
87 tmake parashoot.pro
88
89clean:
90 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
91 -rm -f *~ core
92 -rm -f allmoc.cpp
93
94####### Extension Modules
95
96listpromodules:
97 @echo
98
99listallmodules:
100 @echo
101
102listaddonpromodules:
103 @echo
104
105listaddonentmodules:
106 @echo
107
108
109REQUIRES=
110
111####### Sub-libraries
112
113
114###### Combined headers
115
116
117
118####### Compile
119
120main.o: main.cpp \
121 interface.h \
122 cannon.h \
123 bullet.h \
124 $(QPEDIR)/include/qpe/sound.h \
125 base.h \
126 helicopter.h \
127 $(QPEDIR)/include/qpe/qpeapplication.h
128
129interface.o: interface.cpp \
130 interface.h \
131 cannon.h \
132 bullet.h \
133 $(QPEDIR)/include/qpe/sound.h \
134 base.h \
135 helicopter.h \
136 man.h \
137 $(QPEDIR)/include/qpe/resource.h \
138 $(QPEDIR)/include/qpe/qpetoolbar.h
139
140man.o: man.cpp \
141 codes.h \
142 man.h \
143 $(QPEDIR)/include/qpe/sound.h \
144 base.h \
145 $(QPEDIR)/include/qpe/resource.h
146
147cannon.o: cannon.cpp \
148 $(QPEDIR)/include/qpe/resource.h \
149 codes.h \
150 cannon.h \
151 bullet.h \
152 $(QPEDIR)/include/qpe/sound.h
153
154base.o: base.cpp \
155 codes.h \
156 base.h \
157 $(QPEDIR)/include/qpe/sound.h \
158 man.h \
159 $(QPEDIR)/include/qpe/resource.h
160
161bullet.o: bullet.cpp \
162 codes.h \
163 bullet.h \
164 $(QPEDIR)/include/qpe/sound.h \
165 man.h \
166 helicopter.h \
167 $(QPEDIR)/include/qpe/resource.h \
168 $(QPEDIR)/include/qpe/qmath.h
169
170helicopter.o: helicopter.cpp \
171 helicopter.h \
172 $(QPEDIR)/include/qpe/sound.h \
173 man.h \
174 codes.h \
175 $(QPEDIR)/include/qpe/resource.h
176
177moc_interface.o: moc_interface.cpp \
178 interface.h \
179 cannon.h \
180 bullet.h \
181 $(QPEDIR)/include/qpe/sound.h \
182 base.h \
183 helicopter.h
184
185moc_cannon.o: moc_cannon.cpp \
186 cannon.h \
187 bullet.h \
188 $(QPEDIR)/include/qpe/sound.h
189
190moc_bullet.o: moc_bullet.cpp \
191 bullet.h \
192 $(QPEDIR)/include/qpe/sound.h
193
194moc_interface.cpp: interface.h
195 $(MOC) interface.h -o moc_interface.cpp
196
197moc_cannon.cpp: cannon.h
198 $(MOC) cannon.h -o moc_cannon.cpp
199
200moc_bullet.cpp: bullet.h
201 $(MOC) bullet.h -o moc_bullet.cpp
202
203
diff --git a/noncore/games/parashoot/base.cpp b/noncore/games/parashoot/base.cpp
new file mode 100644
index 0000000..c03802f
--- a/dev/null
+++ b/noncore/games/parashoot/base.cpp
@@ -0,0 +1,71 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "codes.h"
21#include "base.h"
22#include "man.h"
23
24#include <qpe/resource.h>
25
26#include <qregexp.h>
27
28int damage;
29
30Base::Base(QCanvas* canvas) :
31 QCanvasSprite(0, canvas),
32 kaboom("landmine"),
33 ohdear("crmble01")
34{
35 basearray = new QCanvasPixmapArray();
36 QString b0 = Resource::findPixmap("parashoot/b0001");
37 b0.replace(QRegExp("0001"),"%1");
38 basearray->readPixmaps(b0, 4);
39 setSequence(basearray);
40 setFrame(0);
41 move(2, canvas->height()-50);
42 setZ(10);
43 show();
44 damage = 0;
45}
46
47void Base::damageBase()
48{
49 damage++;
50
51 switch(damage) {
52 case 1: setFrame(1); ohdear.play(); break;
53 case 2: setFrame(2); ohdear.play(); break;
54 case 3: setFrame(3); kaboom.play(); break;
55 }
56 show();
57}
58
59bool Base::baseDestroyed()
60{
61 return (damage >= 3);
62}
63
64Base::~Base()
65{
66}
67
68int Base::rtti() const
69{
70 return base_rtti;
71}
diff --git a/noncore/games/parashoot/base.h b/noncore/games/parashoot/base.h
new file mode 100644
index 0000000..ee7f166
--- a/dev/null
+++ b/noncore/games/parashoot/base.h
@@ -0,0 +1,38 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpe/sound.h>
22
23#include <qcanvas.h>
24
25class Base : public QCanvasSprite
26{
27
28public:
29 Base(QCanvas*);
30 ~Base();
31 void damageBase();
32 int rtti() const;
33 static bool baseDestroyed();
34
35private:
36 QCanvasPixmapArray* basearray;
37 Sound kaboom, ohdear;
38};
diff --git a/noncore/games/parashoot/bullet.cpp b/noncore/games/parashoot/bullet.cpp
new file mode 100644
index 0000000..584f564
--- a/dev/null
+++ b/noncore/games/parashoot/bullet.cpp
@@ -0,0 +1,142 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "codes.h"
22#include "bullet.h"
23#include "man.h"
24#include "helicopter.h"
25
26#include <qpe/resource.h>
27#include <qpe/qmath.h>
28
29
30int limit;
31int shotcount;
32int nobullets;
33
34Bullet::Bullet(QCanvas* canvas, double angle, int cannonx, int cannony) :
35 QCanvasSprite(0, canvas),
36 bang("collide01")
37{
38 QCanvasPixmapArray* bulletarray = new QCanvasPixmapArray(Resource::findPixmap("parashoot/bullet"));
39 setSequence(bulletarray);
40 if (nobullets < limit) {
41 nobullets++;
42 move(cannonx, cannony);
43 dy = 0;
44 dx = 0;
45 show();
46 setXY(angle);
47 setVelocity(-dx, -dy);
48 bang.play();
49 } else
50 return;
51}
52
53void Bullet::setXY(double angle)
54{
55 double ang = angle;
56 if ( (y() < 0) || (x() < 0) || (y() > canvas()->height()) ||
57 (x() > canvas()->width()) )
58 delete this;
59 else {
60 double radians = 0;
61 radians = ang * 3.14159265/180;
62 dx = (qCos(radians)) *7;
63 dy = (qSin(radians)) *7;
64 }
65}
66
67void Bullet::setLimit(int amount)
68{
69 limit = amount;
70}
71
72void Bullet::setNobullets(int amount)
73{
74 nobullets = amount;
75}
76
77void Bullet::checkCollision()
78{
79 QCanvasItem* item;
80 QCanvasItemList l=collisions(FALSE);
81 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
82 item = *it;
83 if ( (item->rtti()== 1500) && (item->collidesWith(this)) ) {
84 Man* deadman = (Man*)item;
85 if (deadman->frame() != 5) return;
86 deadman->done();
87 emit score(10);
88 setShotCount(shotcount+1);
89 setAnimated(false);
90 nobullets--;
91 delete this;
92 return;
93 }
94 else if ( (item->rtti()==1900) && (item->collidesWith(this)) ) {
95 Helicopter* deadchopper = (Helicopter*) item;
96 deadchopper->done();
97 emit score(50);
98 setAnimated(false);
99 nobullets--;
100 delete this;
101 return;
102 }
103 }
104 //check shot is not out of bounds
105 if ( (y() < 0) || (x() < 0) ||
106 (y() > canvas()->height()) ||
107 ( x() > canvas()->width())) {
108 setAnimated(false);
109 nobullets--;
110 delete this;
111 return;
112 }
113}
114
115void Bullet::advance(int phase)
116{
117 QCanvasSprite::advance(phase);
118
119 if (phase == 0)
120 checkCollision();
121
122}
123
124int Bullet::getShotCount()
125{
126 return shotcount;
127}
128
129void Bullet::setShotCount(int amount)
130{
131 shotcount = amount;
132}
133
134Bullet::~Bullet()
135{
136
137}
138
139int Bullet::rtti() const
140{
141 return bullet_rtti;
142}
diff --git a/noncore/games/parashoot/bullet.h b/noncore/games/parashoot/bullet.h
new file mode 100644
index 0000000..7d15899
--- a/dev/null
+++ b/noncore/games/parashoot/bullet.h
@@ -0,0 +1,51 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpe/sound.h>
22
23#include <qtimer.h>
24#include <qcanvas.h>
25
26#include <math.h>
27
28class Bullet : public QObject, public QCanvasSprite
29{
30 Q_OBJECT
31public:
32 Bullet(QCanvas*, double angle, int cannonx, int cannony);
33 ~Bullet();
34 void setXY(double angle);
35 void checkCollision();
36 void advance(int phase);
37 int rtti() const;
38 static int getShotCount();
39 static void setShotCount(int amount);
40 static void setLimit(int amount);
41 static void setNobullets(int amount);
42
43signals:
44 void score(int);
45
46private:
47 double dx;
48 double dy;
49 int damage;
50 Sound bang;
51};
diff --git a/noncore/games/parashoot/cannon.cpp b/noncore/games/parashoot/cannon.cpp
new file mode 100644
index 0000000..3c0a5fe
--- a/dev/null
+++ b/noncore/games/parashoot/cannon.cpp
@@ -0,0 +1,140 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpe/resource.h>
22
23#include <qregexp.h>
24
25#include "codes.h"
26#include "cannon.h"
27
28Cannon::Cannon(QCanvas* canvas) :
29 QCanvasSprite(0, canvas)
30{
31shotsfired=0;
32 index = 8;
33 cannonx = 0;
34 cannony = 0;
35 cannonarray = new QCanvasPixmapArray();
36 QString c0 = Resource::findPixmap("parashoot/can0001");
37 c0.replace(QRegExp("0001"),"%1");
38 cannonarray->readPixmaps(c0,17);
39 setSequence(cannonarray);
40 setFrame(index);
41 move(canvas->width()/2-20, canvas->height()-32);
42 // co ords for barrel of cannon when upright
43 barrelypos = canvas->height()-32;
44 barrelxpos = canvas->width()/2;
45 movedir = NoDir;
46 moveDelay = 0;
47 setAnimated(TRUE);
48 show();
49}
50
51void Cannon::advance(int stage)
52{
53 if ( stage == 1 && moveDelay-- == 0 ) {
54 if (movedir == Left) {
55 if (index > 0) {
56 setFrame(index-1);
57 index--;
58 }
59 }
60 if (movedir == Right) {
61 if (index < 16) {
62 setFrame(index+1);
63 index++;
64 }
65 }
66 moveDelay = 0;
67 }
68}
69
70void Cannon::pointCannon(Direction dir)
71{
72 movedir = dir;
73 moveDelay = 0;
74 advance(1);
75 moveDelay = 1;
76}
77
78void Cannon::setCoords()
79{
80 switch(index) {
81 case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break;
82 case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break;
83 case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break;
84 case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break;
85 case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break;
86 case 5: cannonx = barrelxpos-19; cannony = barrelypos; break;
87 case 6: cannonx = barrelxpos-15; cannony = barrelypos; break;
88 case 7: cannonx = barrelxpos-10; cannony = barrelypos; break;
89 case 8: cannonx = barrelxpos; cannony = barrelypos; break;
90 case 9: cannonx = barrelxpos+2; cannony = barrelypos; break;
91 case 10: cannonx = barrelxpos+6; cannony = barrelypos; break;
92 case 11: cannonx = barrelxpos+8; cannony = barrelypos; break;
93 case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break;
94 case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break;
95 case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break;
96 case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break;
97 case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break;
98 }
99}
100
101double Cannon::shootAngle()
102{
103 switch(index) {
104 case 0: return 30.0;
105 case 1: return 37.5;
106 case 2: return 45.0;
107 case 3: return 52.5;
108 case 4: return 60.0;
109 case 5: return 67.5;
110 case 6: return 75.0;
111 case 7: return 82.5;
112 case 8: return 90.0;
113 case 9: return 97.5;
114 case 10: return 105.0;
115 case 11: return 112.5;
116 case 12: return 120.0;
117 case 13: return 127.5;
118 case 14: return 135.0;
119 case 15: return 142.5;
120 case 16: return 150.0;
121 }
122 return 0;
123}
124
125void Cannon::shoot()
126{
127 setCoords();
128 Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony);
129 connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int)));
130 shotsfired++;
131}
132
133Cannon::~Cannon()
134{
135}
136
137int Cannon::rtti() const
138{
139 return cannon_rtti;
140}
diff --git a/noncore/games/parashoot/cannon.h b/noncore/games/parashoot/cannon.h
new file mode 100644
index 0000000..44d0c65
--- a/dev/null
+++ b/noncore/games/parashoot/cannon.h
@@ -0,0 +1,58 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qcanvas.h>
21
22#include "bullet.h"
23
24class Cannon : public QObject, public QCanvasSprite
25{
26 Q_OBJECT
27
28public:
29 Cannon(QCanvas*); //create cannon
30 ~Cannon(); //destroy cannon
31
32 enum Direction{ Left, Right, NoDir };
33
34 void pointCannon(Direction dir);
35 void setCoords();
36 double shootAngle();
37 void shoot();
38 int rtti() const;
39
40int shotsFired() { return shotsfired; };
41
42protected:
43 void advance(int stage);
44
45signals:
46 void score(int);
47
48private:
49 QCanvasPixmapArray* cannonarray;
50 int index;
51 int cannonx;
52 int cannony;
53 int barrelxpos;
54 int barrelypos;
55 int moveDelay;
56 Direction movedir;
57 int shotsfired;
58};
diff --git a/noncore/games/parashoot/codes.h b/noncore/games/parashoot/codes.h
new file mode 100644
index 0000000..68acb3f
--- a/dev/null
+++ b/noncore/games/parashoot/codes.h
@@ -0,0 +1,25 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21const int man_rtti = 1500;
22const int bullet_rtti = 1600;
23const int cannon_rtti = 1700;
24const int base_rtti = 1800;
25const int helicopter_rtti = 1900;
diff --git a/noncore/games/parashoot/helicopter.cpp b/noncore/games/parashoot/helicopter.cpp
new file mode 100644
index 0000000..0923124
--- a/dev/null
+++ b/noncore/games/parashoot/helicopter.cpp
@@ -0,0 +1,114 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "helicopter.h"
22#include "man.h"
23#include "codes.h"
24
25#include <qpe/resource.h>
26
27#include <qregexp.h>
28
29static QList<Helicopter> all;
30
31Helicopter::Helicopter(QCanvas* canvas) :
32 QCanvasSprite(0, canvas),
33 chikachika("aland01")
34{
35 all.append(this);
36 hits = 0;
37 QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray();
38 QString h0 = Resource::findPixmap("parashoot/helicopter0001");
39 h0.replace(QRegExp("0001"),"%1");
40 helicopterarray->readPixmaps(h0,3 );
41 setSequence(helicopterarray);
42 setAnimated(true);
43 move(canvas->width(), 5);
44 setVelocity(-2, 0);
45 chikachika.playLoop();
46 show();
47}
48
49Helicopter::~Helicopter()
50{
51 all.remove(this);
52}
53
54int fr = 0;
55
56void Helicopter::advance(int phase)
57{
58 QCanvasSprite::advance(phase);
59 if (phase == 0) {
60 setFrame(fr%3);
61 fr++;
62 checkCollision();
63 }
64}
65
66void Helicopter::checkCollision()
67{
68 if (x() == 6) {
69 setAnimated(false); //setVelocity(0, 0);
70 dropman();
71 }
72 if (x() < 0)
73 done();
74}
75
76void Helicopter::dropman()
77{
78 (void)new Man(canvas(), 15, 25);
79 (void)new Man(canvas(), 35, 25);
80 takeOff();
81}
82
83void Helicopter::done()
84{
85 hits++;
86 if (hits >= 2) {
87 setAnimated(false);
88 delete this;
89 }
90}
91
92void Helicopter::takeOff()
93{
94 setVelocity(-1, 0);
95}
96
97int Helicopter::rtti() const
98{
99 return helicopter_rtti;
100}
101
102void Helicopter::silenceAll()
103{
104 for (Helicopter* h = all.first(); h; h = all.next())
105 h->chikachika.stop();
106}
107
108void Helicopter::deleteAll()
109{
110 Helicopter* h;
111 while ((h = all.first()))
112 delete h;
113}
114
diff --git a/noncore/games/parashoot/helicopter.h b/noncore/games/parashoot/helicopter.h
new file mode 100644
index 0000000..5cb92de
--- a/dev/null
+++ b/noncore/games/parashoot/helicopter.h
@@ -0,0 +1,45 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpe/sound.h>
22
23#include <qcanvas.h>
24
25class Helicopter : public QCanvasSprite
26{
27
28public:
29 Helicopter(QCanvas*);
30 ~Helicopter();
31 void advance(int phase);
32 void checkCollision();
33 void dropman();
34 void takeOff();
35 void done();
36
37 static void silenceAll();
38 static void deleteAll();
39
40 int rtti() const;
41
42private:
43 int hits;
44 Sound chikachika;
45};
diff --git a/noncore/games/parashoot/interface.cpp b/noncore/games/parashoot/interface.cpp
new file mode 100644
index 0000000..84e5e60
--- a/dev/null
+++ b/noncore/games/parashoot/interface.cpp
@@ -0,0 +1,247 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "interface.h"
22#include "man.h"
23
24#include <qpe/resource.h>
25
26#include <qlabel.h>
27#include <qmessagebox.h>
28#include <qapplication.h>
29#include <qstyle.h>
30#include <qpe/qpetoolbar.h>
31#include <qtoolbutton.h>
32
33ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) :
34 QMainWindow(parent,name,f),
35 canvas(232, 258),
36 fanfare("level_up"),
37 score(0)
38{
39 canvas.setAdvancePeriod(80);
40 QPixmap bg = Resource::loadPixmap("parashoot/sky");
41 canvas.setBackgroundPixmap(bg);
42
43 pb = new QCanvasView(&canvas, this);
44 pb->setFocus();
45
46 setToolBarsMovable( FALSE );
47
48 QPEToolBar* toolbar = new QPEToolBar(this);
49 toolbar->setHorizontalStretchable( TRUE );
50
51 setCaption( tr("ParaShoot") );
52 QPixmap newicon = Resource::loadPixmap("parashoot/manicon");
53 setIcon(newicon);
54 new QToolButton(newicon, tr("New Game"), 0,
55 this, SLOT(newGame()), toolbar, "New Game");
56
57 levelscore = new QLabel(toolbar);
58 levelscore->setBackgroundMode( PaletteButton );
59 levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs );
60 toolbar->setStretchableWidget( levelscore );
61 showScore(0,0);
62
63 setCentralWidget(pb);
64
65 autoDropTimer = new QTimer(this);
66 connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) );
67
68 pauseTimer = new QTimer(this);
69 connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) );
70
71 setFocusPolicy(StrongFocus);
72
73 newGame();
74}
75
76
77void ParaShoot::resizeEvent(QResizeEvent *)
78{
79 QSize s = centralWidget()->size();
80 int fw = style().defaultFrameWidth();
81 canvas.resize( s.width() - fw - 2, s.height() - fw - 2);
82}
83
84
85void ParaShoot::showScore( int score, int level )
86{
87 levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) );
88}
89
90
91void ParaShoot::newGame()
92{
93 clear();
94 if (pauseTimer->isActive())
95 pauseTimer->stop();
96 clear();
97 Man::setManCount(0);
98 score = 0;
99 Bullet::setShotCount(0);
100 Bullet::setNobullets(0);
101 nomen = 2;
102 Bullet::setLimit(nomen);
103 level = 0;
104 updatespeed = 80;
105 showScore(0,0);
106 gamestopped = false;
107 Helicopter::deleteAll();
108 waitover = true;
109 base = new Base(&canvas);
110 cannon = new Cannon(&canvas);
111 connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int)));
112 autoDropTimer->start(100);
113}
114
115
116void ParaShoot::clear()
117{
118 autoDropTimer->stop();
119// QCanvasItem* item;
120 QCanvasItemList l = canvas.allItems();
121 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
122 delete *it;
123 }
124}
125
126void ParaShoot::gameOver()
127{
128 QCanvasItem* item;
129 QCanvasItemList l = canvas.allItems();
130 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
131 item = *it;
132 if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900)
133 item->setAnimated(false);
134 }
135 autoDropTimer->stop();
136 Helicopter::silenceAll();
137
138 int shots = Bullet::getShotCount();
139
140 int shotsFired = cannon->shotsFired();
141 if ( shotsFired == 0 )
142 shotsFired = 1;
143 QCanvasText* gameover = new QCanvasText(
144 tr( " GAME OVER!\n"
145 " Your Score: %1\n"
146 " Parachuters Killed: %2\n"
147 " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ),
148 &canvas);
149 gameover->setColor(red);
150 gameover->setFont( QFont("times", 18, QFont::Bold) );
151 gameover->move(canvas.width()/2 -110, canvas.height()/2 -50);
152 gameover->setZ(500);
153 gameover->show();
154 gamestopped = true;
155 waitover = false;
156 pauseTimer->start(3000);
157}
158
159void ParaShoot::wait()
160{
161 waitover = true;
162 pauseTimer->stop();
163}
164
165void ParaShoot::play()
166{
167 if (Man::getManCount() < nomen ) {
168 new Man(&canvas);
169 }
170 if (Base::baseDestroyed()) {
171 gameOver();
172 return;
173 }
174}
175
176void ParaShoot::increaseScore(int x)
177{
178 score += x;
179 if ( score / 150 != (score-x) / 150 )
180 levelUp();
181 showScore(level,score);
182}
183
184void ParaShoot::levelUp()
185{
186 level++;
187 int stage = level % 3;
188 switch(stage) {
189 case 0:
190 nomen++;
191 Bullet::setLimit(nomen);
192 fanfare.play();
193 break;
194 case 1:
195 new Helicopter(&canvas);
196 break;
197 case 2:
198 moveFaster();
199 fanfare.play();
200 break;
201 default: return;
202 }
203}
204
205void ParaShoot::moveFaster()
206{
207 if (updatespeed > 50)
208 updatespeed = updatespeed-5;
209 else
210 updatespeed = updatespeed-3;
211 canvas.setAdvancePeriod(updatespeed);
212}
213
214void ParaShoot::keyPressEvent(QKeyEvent* event)
215{
216 if (gamestopped) {
217 if (waitover)
218 newGame();
219 else
220 return;
221 } else {
222 switch(event->key()) {
223 case Key_Up:
224 case Key_F1:
225 case Key_F9:
226 case Key_Space:
227 cannon->shoot();
228 break;
229 case Key_Left:
230 cannon->pointCannon(Cannon::Left);
231 lastcannonkey=Key_Left;
232 break;
233 case Key_Right:
234 cannon->pointCannon(Cannon::Right);
235 lastcannonkey=Key_Right;
236 break;
237 default:
238 return;
239 }
240 }
241}
242
243void ParaShoot::keyReleaseEvent(QKeyEvent* event)
244{
245 if ( lastcannonkey == event->key() )
246 cannon->pointCannon(Cannon::NoDir);
247}
diff --git a/noncore/games/parashoot/interface.h b/noncore/games/parashoot/interface.h
new file mode 100644
index 0000000..3f36d0b
--- a/dev/null
+++ b/noncore/games/parashoot/interface.h
@@ -0,0 +1,79 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "cannon.h"
22#include "base.h"
23#include "helicopter.h"
24
25#include <qpe/sound.h>
26
27#include <qmainwindow.h>
28#include <qtimer.h>
29#include <qlabel.h>
30
31class QCanvas;
32class Helicopter;
33
34//enum Direction{
35// left, right, up, down };
36
37class ParaShoot : public QMainWindow {
38 Q_OBJECT
39
40public:
41 ParaShoot(QWidget* parent=0, const char* name=0, WFlags f=0);
42
43 void clear();
44 void gameOver();
45 int mancount;
46 void levelUp();
47 void moveFaster();
48
49protected:
50 virtual void keyPressEvent(QKeyEvent*);
51 virtual void keyReleaseEvent(QKeyEvent*);
52 virtual void resizeEvent(QResizeEvent *e);
53
54private slots:
55 void increaseScore(int);
56 void newGame();
57 void play();
58 void wait();
59
60private:
61 void showScore( int score, int level );
62 QCanvasView* pb;
63 QCanvas canvas;
64 Cannon* cannon;
65 Base* base;
66 QCanvasText* gameover;
67 QLabel* levelscore;
68 int nomen;
69 int level;
70 int oldscore;
71 int updatespeed;
72 QTimer* autoDropTimer;
73 QTimer* pauseTimer;
74 bool gamestopped;
75 bool waitover;
76 Sound fanfare;
77 int score;
78 int lastcannonkey;
79};
diff --git a/noncore/games/parashoot/main.cpp b/noncore/games/parashoot/main.cpp
new file mode 100644
index 0000000..60eea18
--- a/dev/null
+++ b/noncore/games/parashoot/main.cpp
@@ -0,0 +1,36 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "interface.h"
22
23#include <qpe/qpeapplication.h>
24
25int main(int argc, char **argv)
26{
27 QPEApplication app(argc,argv);
28
29 QPEApplication::grabKeyboard();
30
31 ParaShoot m;
32 QPEApplication::setInputMethodHint( &m, QPEApplication::AlwaysOff );
33 app.showMainWidget(&m);
34
35 return app.exec();
36}
diff --git a/noncore/games/parashoot/man.cpp b/noncore/games/parashoot/man.cpp
new file mode 100644
index 0000000..8435572
--- a/dev/null
+++ b/noncore/games/parashoot/man.cpp
@@ -0,0 +1,174 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "codes.h"
22#include "man.h"
23#include "base.h"
24
25#include <qpe/resource.h>
26
27#include <qregexp.h>
28
29int mancount;
30
31Man::Man(QCanvas* canvas) :
32 QCanvasSprite(0, canvas),
33 splat("lose")
34{
35 manarray = new QCanvasPixmapArray();
36 QString m0 = Resource::findPixmap("parashoot/man0001");
37 m0.replace(QRegExp("0001"),"%1");
38 manarray->readPixmaps(m0, 7);
39 setSequence(manarray);
40 setAnimated(true);
41 mancount++;
42 dead = false;
43 start();
44}
45
46Man::Man(QCanvas* canvas, int x, int y) :
47 QCanvasSprite(0, canvas),
48 splat("bang")
49{
50 manarray = new QCanvasPixmapArray();
51 QString m0 = Resource::findPixmap("parashoot/man0001");
52 m0.replace(QString("0001"),"%1");
53 manarray->readPixmaps(m0, 7);
54 setSequence(manarray);
55 move(x, y);
56 setFrame(5);
57 setZ(300);
58 show();
59
60 static bool first_time = TRUE;
61 if (first_time) {
62 first_time = FALSE;
63 QTime midnight(0, 0, 0);
64 srand(midnight.secsTo(QTime::currentTime()) );
65 }
66 int yfallspeed = 0;
67 yfallspeed = (rand() % 3) + 1;
68 setVelocity(0, yfallspeed);
69
70 mancount++;
71 dead = false;
72}
73int f = 0;
74
75void Man::advance(int phase)
76{
77 QCanvasSprite::advance(phase);
78 if (phase == 0) {
79 checkCollision();
80 if (dead) {
81 if (count < 10) {
82 setFrame(6);
83 setVelocity(0,0);
84 count++;
85 } else {
86 delete this;
87 return;
88 }
89 }
90 if (y() > canvas()->height()-43) {
91 setFrame(f%5);
92 f++;
93 move(x(), canvas()->height()-26);
94 setVelocity(-2, 0);
95 }
96 }
97}
98
99void Man::setInitialCoords()
100{
101 static bool first_time = TRUE;
102 if (first_time) {
103 first_time = FALSE;
104 QTime midnight(0, 0, 0);
105 srand(midnight.secsTo(QTime::currentTime()) );
106 }
107 dx = rand() % (canvas()->width()-16);
108 dy = -43; //height of a man off the screen
109}
110
111//check if man has reached the base
112void Man::checkCollision()
113{
114 if ( (x() < 23) && (y() == canvas()->height()-26)) {
115 QCanvasItem* item;
116 QCanvasItemList l=collisions(FALSE);
117 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
118 item = *it;
119 if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) {
120 Base* base = (Base*) item;
121 base->damageBase();
122 start();
123 }
124 }
125 }
126}
127
128void Man::start()
129{
130 setInitialCoords();
131 move(dx, dy);
132 setFrame(5);
133 setZ(300);
134 show();
135
136 static bool first_time = TRUE;
137 if (first_time) {
138 first_time = FALSE;
139 QTime midnight(0, 0, 0);
140 srand(midnight.secsTo(QTime::currentTime()) );
141 }
142 int yfallspeed = 0;
143 yfallspeed = (rand() % 3) + 1;
144 setVelocity(0, yfallspeed);
145}
146
147void Man::done()
148{
149 splat.play();
150 count = 0;
151 dead = true;
152 setFrame(6);
153}
154
155int Man::getManCount()
156{
157 return mancount;
158}
159
160void Man::setManCount(int count)
161{
162 mancount = count;
163}
164
165
166int Man::rtti() const
167{
168 return man_rtti;
169}
170
171Man::~Man()
172{
173 mancount--;
174}
diff --git a/noncore/games/parashoot/man.h b/noncore/games/parashoot/man.h
new file mode 100644
index 0000000..e48fc20
--- a/dev/null
+++ b/noncore/games/parashoot/man.h
@@ -0,0 +1,52 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpe/sound.h>
22
23#include <qcanvas.h>
24#include <qdatetime.h>
25
26#include <stdlib.h>
27
28class Man : public QCanvasSprite
29{
30
31public:
32 Man (QCanvas*);
33 Man (QCanvas*, int x, int y);
34 ~Man();
35 void advance(int phase);
36 void setInitialCoords();
37 void checkCollision();
38 void start();
39 void done();
40 static int getManCount();
41 static void setManCount(int count);
42 int rtti() const;
43// int mancount;
44
45private:
46 QCanvasPixmapArray* manarray;
47 int dx;
48 int dy;
49 bool dead;
50 int count;
51 Sound splat;
52};
diff --git a/noncore/games/parashoot/parashoot.pro b/noncore/games/parashoot/parashoot.pro
new file mode 100644
index 0000000..631560b
--- a/dev/null
+++ b/noncore/games/parashoot/parashoot.pro
@@ -0,0 +1,11 @@
1 TEMPLATE= app
2 CONFIG += qt warn_on release
3 DESTDIR = $(QPEDIR)/bin
4 HEADERS = interface.h man.h cannon.h base.h bullet.h helicopter.h
5 SOURCES = main.cpp interface.cpp man.cpp cannon.cpp base.cpp bullet.cpp helicopter.cpp
6 TARGET = parashoot
7INCLUDEPATH += $(QPEDIR)/include
8 DEPENDPATH+= $(QPEDIR)/include
9LIBS += -lqpe
10
11TRANSLATIONS = ../i18n/de/parashoot.ts
diff --git a/noncore/games/parashoot/qpe-parashoot.control b/noncore/games/parashoot/qpe-parashoot.control
new file mode 100644
index 0000000..82e9421
--- a/dev/null
+++ b/noncore/games/parashoot/qpe-parashoot.control
@@ -0,0 +1,9 @@
1Files: bin/parashoot apps/Games/parashoot.desktop pics/parashoot
2Priority: optional
3Section: qpe/games
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Game: shoot the parachutists
9 A game for the Qtopia environment.
diff --git a/noncore/games/qasteroids/.cvsignore b/noncore/games/qasteroids/.cvsignore
new file mode 100644
index 0000000..c152c55
--- a/dev/null
+++ b/noncore/games/qasteroids/.cvsignore
@@ -0,0 +1,2 @@
1moc_*.cpp
2Makefile
diff --git a/noncore/games/qasteroids/Makefile.in b/noncore/games/qasteroids/Makefile.in
new file mode 100644
index 0000000..7312743
--- a/dev/null
+++ b/noncore/games/qasteroids/Makefile.in
@@ -0,0 +1,155 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= qasteroids
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =ledmeter.h \
27 sprites.h \
28 toplevel.h \
29 view.h
30 SOURCES =ledmeter.cpp \
31 toplevel.cpp \
32 view.cpp \
33 main.cpp
34 OBJECTS =ledmeter.o \
35 toplevel.o \
36 view.o \
37 main.o
38INTERFACES =
39UICDECLS =
40UICIMPLS =
41 SRCMOC =moc_ledmeter.cpp \
42 moc_toplevel.cpp \
43 moc_view.cpp
44 OBJMOC =moc_ledmeter.o \
45 moc_toplevel.o \
46 moc_view.o
47
48
49####### Implicit rules
50
51.SUFFIXES: .cpp .cxx .cc .C .c
52
53.cpp.o:
54 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
55
56.cxx.o:
57 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
58
59.cc.o:
60 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
61
62.C.o:
63 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
64
65.c.o:
66 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
67
68####### Build rules
69
70
71all: $(DESTDIR)$(TARGET)
72
73$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
74 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
75
76moc: $(SRCMOC)
77
78tmake:
79 tmake qasteroids.pro
80
81clean:
82 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
83 -rm -f *~ core
84 -rm -f allmoc.cpp
85
86####### Extension Modules
87
88listpromodules:
89 @echo
90
91listallmodules:
92 @echo
93
94listaddonpromodules:
95 @echo
96
97listaddonentmodules:
98 @echo
99
100
101REQUIRES=
102
103####### Sub-libraries
104
105
106###### Combined headers
107
108
109
110####### Compile
111
112ledmeter.o: ledmeter.cpp \
113 ledmeter.h
114
115toplevel.o: toplevel.cpp \
116 toplevel.h \
117 view.h \
118 sprites.h \
119 ledmeter.h \
120 $(QPEDIR)/include/qpe/qpeapplication.h \
121 $(QPEDIR)/include/qpe/resource.h
122
123view.o: view.cpp \
124 view.h \
125 sprites.h \
126 $(QPEDIR)/include/qpe/resource.h
127
128main.o: main.cpp \
129 toplevel.h \
130 view.h \
131 sprites.h \
132 $(QPEDIR)/include/qpe/qpeapplication.h
133
134moc_ledmeter.o: moc_ledmeter.cpp \
135 ledmeter.h
136
137moc_toplevel.o: moc_toplevel.cpp \
138 toplevel.h \
139 view.h \
140 sprites.h
141
142moc_view.o: moc_view.cpp \
143 view.h \
144 sprites.h
145
146moc_ledmeter.cpp: ledmeter.h
147 $(MOC) ledmeter.h -o moc_ledmeter.cpp
148
149moc_toplevel.cpp: toplevel.h
150 $(MOC) toplevel.h -o moc_toplevel.cpp
151
152moc_view.cpp: view.h
153 $(MOC) view.h -o moc_view.cpp
154
155
diff --git a/noncore/games/qasteroids/ledmeter.cpp b/noncore/games/qasteroids/ledmeter.cpp
new file mode 100644
index 0000000..f4d4d1a
--- a/dev/null
+++ b/noncore/games/qasteroids/ledmeter.cpp
@@ -0,0 +1,135 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************//*
20 * KAsteroids - Copyright (c) Martin R. Jones 1997
21 *
22 * Part of the KDE project
23 */
24
25#include <qpainter.h>
26#include "ledmeter.h"
27
28KALedMeter::KALedMeter( QWidget *parent ) : QFrame( parent )
29{
30 mCRanges.setAutoDelete( TRUE );
31 mRange = 100;
32 mCount = 20;
33 mCurrentCount = 0;
34 mValue = 0;
35 setMinimumWidth( mCount * 2 + frameWidth() );
36}
37
38void KALedMeter::setRange( int r )
39{
40 mRange = r;
41 if ( mRange < 1 )
42 mRange = 1;
43 setValue( mValue );
44 update();
45}
46
47void KALedMeter::setCount( int c )
48{
49 mCount = c;
50 if ( mCount < 1 )
51 mCount = 1;
52 setMinimumWidth( mCount * 2 + frameWidth() );
53 calcColorRanges();
54 setValue( mValue );
55 update();
56}
57
58void KALedMeter::setValue( int v )
59{
60 mValue = v;
61 if ( mValue > mRange )
62 mValue = mRange;
63 else if ( mValue < 0 )
64 mValue = 0;
65 int c = ( mValue + mRange / mCount - 1 ) * mCount / mRange;
66 if ( c != mCurrentCount )
67 {
68 mCurrentCount = c;
69 update();
70 }
71}
72
73void KALedMeter::addColorRange( int pc, const QColor &c )
74{
75 ColorRange *cr = new ColorRange;
76 cr->mPc = pc;
77 cr->mColor = c;
78 mCRanges.append( cr );
79 calcColorRanges();
80}
81
82void KALedMeter::resizeEvent( QResizeEvent *e )
83{
84 QFrame::resizeEvent( e );
85 int w = ( width() - frameWidth() - 2 ) / mCount * mCount;
86 w += frameWidth() + 2;
87 setFrameRect( QRect( 0, 0, w, height() ) );
88}
89
90void KALedMeter::drawContents( QPainter *p )
91{
92 QRect b = contentsRect();
93
94 unsigned cidx = 0;
95 int ncol = mCount;
96 QColor col = colorGroup().foreground();
97
98 if ( !mCRanges.isEmpty() )
99 {
100 col = mCRanges.at( cidx )->mColor;
101 ncol = mCRanges.at( cidx )->mValue;
102 }
103 p->setBrush( col );
104 p->setPen( col );
105
106 int lw = b.width() / mCount;
107 int lx = b.left() + 1;
108 for ( int i = 0; i < mCurrentCount; i++, lx += lw )
109 {
110 if ( i > ncol )
111 {
112 if ( ++cidx < mCRanges.count() )
113 {
114 col = mCRanges.at( cidx )->mColor;
115 ncol = mCRanges.at( cidx )->mValue;
116 p->setBrush( col );
117 p->setPen( col );
118 }
119 }
120
121 p->drawRect( lx, b.top() + 1, lw - 1, b.height() - 2 );
122 }
123}
124
125void KALedMeter::calcColorRanges()
126{
127 int prev = 0;
128 ColorRange *cr;
129 for ( cr = mCRanges.first(); cr; cr = mCRanges.next() )
130 {
131 cr->mValue = prev + cr->mPc * mCount / 100;
132 prev = cr->mValue;
133 }
134}
135
diff --git a/noncore/games/qasteroids/ledmeter.h b/noncore/games/qasteroids/ledmeter.h
new file mode 100644
index 0000000..b2f06c1
--- a/dev/null
+++ b/noncore/games/qasteroids/ledmeter.h
@@ -0,0 +1,72 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************//*
20 * KAsteroids - Copyright (c) Martin R. Jones 1997
21 *
22 * Part of the KDE project
23 */
24
25#ifndef __LEDMETER_H__
26#define __LEDMETER_H__
27
28#include <qframe.h>
29#include <qlist.h>
30
31#define QPtrList QList
32
33class KALedMeter : public QFrame
34{
35 Q_OBJECT
36public:
37 KALedMeter( QWidget *parent );
38
39 int range() const { return mRange; }
40 void setRange( int r );
41
42 int count() const { return mCount; }
43 void setCount( int c );
44
45 int value () const { return mValue; }
46
47 void addColorRange( int pc, const QColor &c );
48
49public slots:
50 void setValue( int v );
51
52protected:
53 virtual void resizeEvent( QResizeEvent * );
54 virtual void drawContents( QPainter * );
55 void calcColorRanges();
56
57protected:
58 struct ColorRange
59 {
60 int mPc;
61 int mValue;
62 QColor mColor;
63 };
64
65 int mRange;
66 int mCount;
67 int mCurrentCount;
68 int mValue;
69 QPtrList<ColorRange> mCRanges;
70};
71
72#endif
diff --git a/noncore/games/qasteroids/main.cpp b/noncore/games/qasteroids/main.cpp
new file mode 100644
index 0000000..7d1682c
--- a/dev/null
+++ b/noncore/games/qasteroids/main.cpp
@@ -0,0 +1,36 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "toplevel.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char *argv[] )
26{
27 QPEApplication app( argc, argv );
28
29 QPEApplication::grabKeyboard();
30
31 KAstTopLevel *mainWidget = new KAstTopLevel();
32 app.showMainWidget( mainWidget );
33
34 app.exec();
35}
36
diff --git a/noncore/games/qasteroids/qasteroids.pro b/noncore/games/qasteroids/qasteroids.pro
new file mode 100644
index 0000000..14a0901
--- a/dev/null
+++ b/noncore/games/qasteroids/qasteroids.pro
@@ -0,0 +1,11 @@
1 TEMPLATE= app
2 CONFIG += qt warn_on release
3 DESTDIR = $(QPEDIR)/bin
4 HEADERS = ledmeter.h sprites.h toplevel.h view.h
5 SOURCES = ledmeter.cpp toplevel.cpp view.cpp main.cpp
6 TARGET = qasteroids
7INCLUDEPATH += $(QPEDIR)/include
8 DEPENDPATH+= $(QPEDIR)/include
9LIBS += -lqpe
10
11TRANSLATIONS = ../i18n/de/qasteroids.ts
diff --git a/noncore/games/qasteroids/qpe-qasteroids.control b/noncore/games/qasteroids/qpe-qasteroids.control
new file mode 100644
index 0000000..c1b328e
--- a/dev/null
+++ b/noncore/games/qasteroids/qpe-qasteroids.control
@@ -0,0 +1,9 @@
1Files: bin/qasteroids apps/Games/qasteroids.desktop pics/qasteroids pics/Asteroids.png
2Priority: optional
3Section: qpe/games
4Maintainer: Martin Jones <mjones@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Game: shoot the asteroids
9 A game for the Qtopia environment.
diff --git a/noncore/games/qasteroids/sprites.h b/noncore/games/qasteroids/sprites.h
new file mode 100644
index 0000000..0827821
--- a/dev/null
+++ b/noncore/games/qasteroids/sprites.h
@@ -0,0 +1,147 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************//*
20 * KAsteroids - Copyright (c) Martin R. Jones 1997
21 *
22 * Part of the KDE project
23 */
24
25#ifndef __SPRITES_H__
26#define __SPRITES_H__
27
28#include <qcanvas.h>
29
30#define ID_ROCK_LARGE 1024
31#define ID_ROCK_MEDIUM 1025
32#define ID_ROCK_SMALL 1026
33
34#define ID_MISSILE 1030
35
36#define ID_BIT 1040
37#define ID_EXHAUST 1041
38
39#define ID_ENERGY_POWERUP 1310
40#define ID_TELEPORT_POWERUP 1311
41#define ID_BRAKE_POWERUP 1312
42#define ID_SHIELD_POWERUP 1313
43#define ID_SHOOT_POWERUP 1314
44
45#define ID_SHIP 1350
46#define ID_SHIELD 1351
47
48#define MAX_SHIELD_AGE 350
49#define MAX_POWERUP_AGE 500
50#define MAX_MISSILE_AGE 20
51
52class KMissile : public QCanvasSprite
53{
54public:
55 KMissile( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c )
56 { myAge = 0; }
57
58 virtual int rtti() const { return ID_MISSILE; }
59
60 void growOlder() { myAge++; }
61 bool expired() { return myAge > MAX_MISSILE_AGE; }
62
63private:
64 int myAge;
65};
66
67class KBit : public QCanvasSprite
68{
69public:
70 KBit( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c )
71 { death = 7; }
72
73 virtual int rtti() const { return ID_BIT; }
74
75 void setDeath( int d ) { death = d; }
76 void growOlder() { death--; }
77 bool expired() { return death <= 0; }
78
79private:
80 int death;
81};
82
83class KExhaust : public QCanvasSprite
84{
85public:
86 KExhaust( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c )
87 { death = 1; }
88
89 virtual int rtti() const { return ID_EXHAUST; }
90
91 void setDeath( int d ) { death = d; }
92 void growOlder() { death--; }
93 bool expired() { return death <= 0; }
94
95private:
96 int death;
97};
98
99class KPowerup : public QCanvasSprite
100{
101public:
102 KPowerup( QCanvasPixmapArray *s, QCanvas *c, int t ) : QCanvasSprite( s, c ),
103 myAge( 0 ), type(t) { }
104
105 virtual int rtti() const { return type; }
106
107 void growOlder() { myAge++; }
108 bool expired() const { return myAge > MAX_POWERUP_AGE; }
109
110protected:
111 int myAge;
112 int type;
113};
114
115class KRock : public QCanvasSprite
116{
117public:
118 KRock (QCanvasPixmapArray *s, QCanvas *c, int t, int sk, int st) : QCanvasSprite( s, c )
119 { type = t; skip = cskip = sk; step = st; }
120
121 void nextFrame()
122 {
123 if (cskip-- <= 0) {
124 setFrame( (frame()+step+frameCount())%frameCount() );
125 cskip = QABS(skip);
126 }
127 }
128
129 virtual int rtti() const { return type; }
130
131private:
132 int type;
133 int skip;
134 int cskip;
135 int step;
136};
137
138class KShield : public QCanvasSprite
139{
140public:
141 KShield( QCanvasPixmapArray *s, QCanvas *c )
142 : QCanvasSprite( s, c ) {}
143
144 virtual int rtti() const { return ID_SHIELD; }
145};
146
147#endif
diff --git a/noncore/games/qasteroids/toplevel.cpp b/noncore/games/qasteroids/toplevel.cpp
new file mode 100644
index 0000000..57242a0
--- a/dev/null
+++ b/noncore/games/qasteroids/toplevel.cpp
@@ -0,0 +1,514 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************//*
20 * KAsteroids - Copyright (c) Martin R. Jones 1997
21 *
22 * Part of the KDE project
23 */
24 //--- toplevel.cpp ---
25
26#include "toplevel.h"
27#include "ledmeter.h"
28
29#include <qpe/qpeapplication.h>
30#include <qpe/resource.h>
31
32#include <qaccel.h>
33#include <qlabel.h>
34#include <qlayout.h>
35#include <qlcdnumber.h>
36#include <qpushbutton.h>
37
38
39 #define SB_SCORE1
40 #define SB_LEVEL2
41 #define SB_SHIPS3
42
43struct SLevel
44{
45 int nrocks;
46 double rockSpeed;
47};
48
49 #define MAX_LEVELS16
50
51SLevel levels[MAX_LEVELS] =
52{
53 { 1, 0.4 },
54 { 1, 0.6 },
55 { 2, 0.5 },
56 { 2, 0.7 },
57 { 2, 0.8 },
58 { 3, 0.6 },
59 { 3, 0.7 },
60 { 3, 0.8 },
61 { 4, 0.6 },
62 { 4, 0.7 },
63 { 4, 0.8 },
64 { 5, 0.7 },
65 { 5, 0.8 },
66 { 5, 0.9 },
67 { 5, 1.0 }
68};
69
70const char *soundEvents[] =
71{
72 "ShipDestroyed",
73 "RockDestroyed",
74 0
75};
76
77const char *soundDefaults[] =
78{
79 "Explosion.wav",
80 "ploop.wav",
81 0
82};
83
84
85KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name )
86 : QMainWindow( parent, name )
87{
88 setCaption( tr("Asteroids") );
89 QWidget *border = new QWidget( this );
90 border->setBackgroundColor( black );
91 setCentralWidget( border );
92
93 QVBoxLayout *borderLayout = new QVBoxLayout( border );
94
95 QWidget *mainWin = new QWidget( border );
96 borderLayout->addWidget( mainWin, 2, AlignHCenter );
97
98 view = new KAsteroidsView( mainWin );
99 connect( view, SIGNAL( shipKilled() ), SLOT( slotShipKilled() ) );
100 connect( view, SIGNAL( rockHit(int) ), SLOT( slotRockHit(int) ) );
101 connect( view, SIGNAL( rocksRemoved() ), SLOT( slotRocksRemoved() ) );
102 connect( view, SIGNAL( updateVitals() ), SLOT( slotUpdateVitals() ) );
103
104 QVBoxLayout *vb = new QVBoxLayout( mainWin );
105 QHBoxLayout *hb = new QHBoxLayout;
106 QHBoxLayout *hbd = new QHBoxLayout;
107 vb->addLayout( hb );
108
109 QFont labelFont( "helvetica", 12 );
110 QColorGroup grp( darkGreen, black, QColor( 128, 128, 128 ),
111 QColor( 64, 64, 64 ), black, darkGreen, black );
112 QPalette pal( grp, grp, grp );
113
114 mainWin->setPalette( pal );
115
116 QLabel *label;
117 label = new QLabel( tr("Score"), mainWin );
118 label->setFont( labelFont );
119 label->setPalette( pal );
120// label->setFixedWidth( label->sizeHint().width() );
121 hb->addWidget( label );
122
123 scoreLCD = new QLCDNumber( 5, mainWin );
124 scoreLCD->setFrameStyle( QFrame::NoFrame );
125 scoreLCD->setSegmentStyle( QLCDNumber::Flat );
126 scoreLCD->setFixedHeight( 16 );
127 scoreLCD->setPalette( pal );
128 hb->addWidget( scoreLCD );
129 hb->addStretch( 1 );
130
131 label = new QLabel( tr("Level"), mainWin );
132 label->setFont( labelFont );
133 label->setPalette( pal );
134// label->setFixedWidth( label->sizeHint().width() );
135 hb->addWidget( label );
136
137 levelLCD = new QLCDNumber( 2, mainWin );
138 levelLCD->setFrameStyle( QFrame::NoFrame );
139 levelLCD->setSegmentStyle( QLCDNumber::Flat );
140 levelLCD->setFixedHeight( 16 );
141 levelLCD->setPalette( pal );
142 hb->addWidget( levelLCD );
143 hb->addStretch( 1 );
144
145 label = new QLabel( tr("Ships"), mainWin );
146 label->setFont( labelFont );
147// label->setFixedWidth( label->sizeHint().width() );
148 label->setPalette( pal );
149 hb->addWidget( label );
150
151 shipsLCD = new QLCDNumber( 1, mainWin );
152 shipsLCD->setFrameStyle( QFrame::NoFrame );
153 shipsLCD->setSegmentStyle( QLCDNumber::Flat );
154 shipsLCD->setFixedHeight( 16 );
155 shipsLCD->setPalette( pal );
156 hb->addWidget( shipsLCD );
157
158// hb->addStrut( 14 );
159
160 vb->addWidget( view, 10 );
161
162// -- bottom layout:
163 vb->addLayout( hbd );
164
165 QFont smallFont( "helvetica", 12 );
166 hbd->addSpacing( 5 );
167
168/*
169 label = new QLabel( tr( "T" ), mainWin );
170 label->setFont( smallFont );
171 label->setFixedWidth( label->sizeHint().width() );
172 label->setPalette( pal );
173 hbd->addWidget( label );
174
175 teleportsLCD = new QLCDNumber( 1, mainWin );
176 teleportsLCD->setFrameStyle( QFrame::NoFrame );
177 teleportsLCD->setSegmentStyle( QLCDNumber::Flat );
178 teleportsLCD->setPalette( pal );
179 teleportsLCD->setFixedHeight( 18 );
180 hbd->addWidget( teleportsLCD );
181
182 hbd->addSpacing( 10 );
183*/
184 label = new QLabel( mainWin );
185 label->setPixmap( Resource::loadPixmap("qasteroids/powerups/brake.png") );
186 label->setFixedWidth( 16 );
187 label->setPalette( pal );
188 hbd->addWidget( label );
189
190 brakesLCD = new QLCDNumber( 1, mainWin );
191 brakesLCD->setFrameStyle( QFrame::NoFrame );
192 brakesLCD->setSegmentStyle( QLCDNumber::Flat );
193 brakesLCD->setPalette( pal );
194 brakesLCD->setFixedHeight( 16 );
195 hbd->addWidget( brakesLCD );
196
197 hbd->addSpacing( 5 );
198
199 label = new QLabel( mainWin );
200 label->setPixmap( Resource::loadPixmap("qasteroids/powerups/shield.png") );
201 label->setFixedWidth( 16 );
202 label->setPalette( pal );
203 hbd->addWidget( label );
204
205 shieldLCD = new QLCDNumber( 1, mainWin );
206 shieldLCD->setFrameStyle( QFrame::NoFrame );
207 shieldLCD->setSegmentStyle( QLCDNumber::Flat );
208 shieldLCD->setPalette( pal );
209 shieldLCD->setFixedHeight( 16 );
210 hbd->addWidget( shieldLCD );
211
212 hbd->addSpacing( 5 );
213
214 label = new QLabel( mainWin );
215 label->setPixmap( Resource::loadPixmap("qasteroids/powerups/shoot.png") );
216 label->setFixedWidth( 16 );
217 label->setPalette( pal );
218 hbd->addWidget( label );
219
220 shootLCD = new QLCDNumber( 1, mainWin );
221 shootLCD->setFrameStyle( QFrame::NoFrame );
222 shootLCD->setSegmentStyle( QLCDNumber::Flat );
223 shootLCD->setPalette( pal );
224 shootLCD->setFixedHeight( 16 );
225 hbd->addWidget( shootLCD );
226
227 hbd->addStretch( 1 );
228
229 label = new QLabel( tr( "Fuel" ), mainWin );
230 label->setFont( smallFont );
231 label->setFixedWidth( label->sizeHint().width() + 5 );
232 label->setPalette( pal );
233 hbd->addWidget( label );
234
235 powerMeter = new KALedMeter( mainWin );
236 powerMeter->setFrameStyle( QFrame::Box | QFrame::Plain );
237 powerMeter->setRange( MAX_POWER_LEVEL );
238 powerMeter->addColorRange( 10, darkRed );
239 powerMeter->addColorRange( 20, QColor(160, 96, 0) );
240 powerMeter->addColorRange( 70, darkGreen );
241 powerMeter->setCount( 15 );
242 powerMeter->setPalette( pal );
243 powerMeter->setFixedSize( 60, 12 );
244 hbd->addWidget( powerMeter );
245
246 shipsRemain = 3;
247 showHiscores = FALSE;
248
249 actions.insert( Qt::Key_Up, Thrust );
250 actions.insert( Qt::Key_Left, RotateLeft );
251 actions.insert( Qt::Key_Right, RotateRight );
252 actions.insert( Qt::Key_Enter, Shoot );
253 actions.insert( Qt::Key_Z, Teleport );
254 actions.insert( Qt::Key_Down, Brake );
255 actions.insert( Qt::Key_P, Pause );
256 actions.insert( Key_F12, Launch );
257 actions.insert( Key_F11, Shield );
258 actions.insert( Key_F9, NewGame );
259
260// actions.insert( Qt::Key_S, Shield );
261// actions.insert( Qt::Key_X, Brake );
262// actions.insert( Qt::Key_L, Launch );
263 actions.insert( Qt::Key_Space, Shoot );
264
265 view->showText( tr( "Press Calendar to start playing" ), yellow );
266
267 setFocusPolicy( StrongFocus );
268
269 slotNewGame();
270}
271
272KAstTopLevel::~KAstTopLevel()
273{
274}
275
276void KAstTopLevel::playSound( const char * )
277{
278}
279
280void KAstTopLevel::keyPressEvent( QKeyEvent *event )
281{
282 if ( event->isAutoRepeat() || !actions.contains( event->key() ) )
283 {
284 event->ignore();
285 return;
286 }
287
288 Action a = actions[ event->key() ];
289
290 switch ( a )
291 {
292 case RotateLeft:
293 view->rotateLeft( TRUE );
294 break;
295
296 case RotateRight:
297 view->rotateRight( TRUE );
298 break;
299
300 case Thrust:
301 view->thrust( TRUE );
302 break;
303
304 case Shoot:
305 view->shoot( TRUE );
306 break;
307
308 case Shield:
309 view->setShield( TRUE );
310 break;
311
312 case Teleport:
313 view->teleport( TRUE );
314 break;
315
316 case Brake:
317 view->brake( TRUE );
318 break;
319
320 default:
321 event->ignore();
322 return;
323 }
324 event->accept();
325}
326
327void KAstTopLevel::keyReleaseEvent( QKeyEvent *event )
328{
329 if ( event->isAutoRepeat() || !actions.contains( event->key() ) )
330 {
331 event->ignore();
332 return;
333 }
334
335 Action a = actions[ event->key() ];
336
337 switch ( a )
338 {
339 case RotateLeft:
340 view->rotateLeft( FALSE );
341 break;
342
343 case RotateRight:
344 view->rotateRight( FALSE );
345 break;
346
347 case Thrust:
348 view->thrust( FALSE );
349 break;
350
351 case Shoot:
352 view->shoot( FALSE );
353 break;
354
355 case Brake:
356 view->brake( FALSE );
357 break;
358
359 case Shield:
360 view->setShield( FALSE );
361 break;
362
363 case Teleport:
364 view->teleport( FALSE );
365 break;
366
367 case Launch:
368 if ( waitShip )
369 {
370 view->newShip();
371 waitShip = FALSE;
372 view->hideText();
373 }
374 else
375 {
376 event->ignore();
377 return;
378 }
379 break;
380
381 case NewGame:
382 slotNewGame();
383 break;
384/*
385 case Pause:
386 {
387 view->pause( TRUE );
388 QMessageBox::information( this,
389 tr("KAsteroids is paused"),
390 tr("Paused") );
391 view->pause( FALSE );
392 }
393 break;
394*/
395 default:
396 event->ignore();
397 return;
398 }
399
400 event->accept();
401}
402
403void KAstTopLevel::showEvent( QShowEvent *e )
404{
405 QMainWindow::showEvent( e );
406 view->pause( FALSE );
407 setFocus();
408}
409
410void KAstTopLevel::hideEvent( QHideEvent *e )
411{
412 QMainWindow::hideEvent( e );
413 view->pause( TRUE );
414}
415
416void KAstTopLevel::focusInEvent( QFocusEvent * )
417{
418 view->pause( FALSE );
419 setFocus();
420}
421
422void KAstTopLevel::focusOutEvent( QFocusEvent * )
423{
424 view->pause( TRUE );
425}
426
427void KAstTopLevel::slotNewGame()
428{
429 shipsRemain = 3;
430 score = 0;
431 scoreLCD->display( 0 );
432 level = 0;
433 levelLCD->display( level+1 );
434 shipsLCD->display( shipsRemain-1 );
435 view->newGame();
436 view->setRockSpeed( levels[0].rockSpeed );
437 view->addRocks( levels[0].nrocks );
438 view->newShip();
439 waitShip = FALSE;
440 view->hideText();
441 isPaused = FALSE;
442}
443
444void KAstTopLevel::slotShipKilled()
445{
446 shipsRemain--;
447 shipsLCD->display( shipsRemain-1 );
448
449 playSound( "ShipDestroyed" );
450
451 if ( shipsRemain > 0 )
452 {
453 waitShip = TRUE;
454 view->showText( tr( "Ship Destroyed.\nPress Launch/Home key."), yellow );
455 }
456 else
457 {
458 view->endGame();
459 doStats();
460 }
461}
462
463void KAstTopLevel::slotRockHit( int size )
464{
465 switch ( size )
466 {
467 case 0:
468 score += 10;
469 break;
470
471 case 1:
472 score += 20;
473 break;
474
475 default:
476 score += 40;
477 }
478
479 playSound( "RockDestroyed" );
480
481 scoreLCD->display( score );
482}
483
484void KAstTopLevel::slotRocksRemoved()
485{
486 level++;
487
488 if ( level >= MAX_LEVELS )
489 level = MAX_LEVELS - 1;
490
491 view->setRockSpeed( levels[level-1].rockSpeed );
492 view->addRocks( levels[level-1].nrocks );
493
494 levelLCD->display( level+1 );
495}
496
497void KAstTopLevel::doStats()
498{
499 QString r( "0.00" );
500 if ( view->shots() )
501 r = QString::number( (double)view->hits() / view->shots() * 100.0,
502 'g', 2 );
503
504 view->showText( tr( "Game Over.\nPress Calendar for a new game." ), yellow, FALSE );
505}
506
507void KAstTopLevel::slotUpdateVitals()
508{
509 brakesLCD->display( view->brakeCount() );
510 shieldLCD->display( view->shieldCount() );
511 shootLCD->display( view->shootCount() );
512// teleportsLCD->display( view->teleportCount() );
513 powerMeter->setValue( view->power() );
514}
diff --git a/noncore/games/qasteroids/toplevel.h b/noncore/games/qasteroids/toplevel.h
new file mode 100644
index 0000000..4e1ac9c
--- a/dev/null
+++ b/noncore/games/qasteroids/toplevel.h
@@ -0,0 +1,99 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************//*
20 * KAsteroids - Copyright (c) Martin R. Jones 1997
21 *
22 * Part of the KDE project
23 */
24
25#ifndef __KAST_TOPLEVEL_H__
26#define __KAST_TOPLEVEL_H__
27
28#include <qmainwindow.h>
29#include <qdict.h>
30#include <qmap.h>
31
32#include "view.h"
33
34
35class KALedMeter;
36class QLCDNumber;
37
38class KAstTopLevel : public QMainWindow
39{
40 Q_OBJECT
41public:
42 KAstTopLevel( QWidget *parent=0, const char *name=0 );
43 virtual ~KAstTopLevel();
44
45private:
46 void playSound( const char *snd );
47 void readSoundMapping();
48 void doStats();
49
50protected:
51 virtual void showEvent( QShowEvent * );
52 virtual void hideEvent( QHideEvent * );
53 virtual void keyPressEvent( QKeyEvent *event );
54 virtual void keyReleaseEvent( QKeyEvent *event );
55 virtual void focusInEvent( QFocusEvent *event );
56 virtual void focusOutEvent( QFocusEvent *event );
57
58private slots:
59 void slotNewGame();
60
61 void slotShipKilled();
62 void slotRockHit( int size );
63 void slotRocksRemoved();
64
65 void slotUpdateVitals();
66
67private:
68 KAsteroidsView *view;
69 QLCDNumber *scoreLCD;
70 QLCDNumber *levelLCD;
71 QLCDNumber *shipsLCD;
72
73 QLCDNumber *teleportsLCD;
74// QLCDNumber *bombsLCD;
75 QLCDNumber *brakesLCD;
76 QLCDNumber *shieldLCD;
77 QLCDNumber *shootLCD;
78 KALedMeter *powerMeter;
79
80 bool sound;
81 QDict<QString> soundDict;
82
83 // waiting for user to press Enter to launch a ship
84 bool waitShip;
85 bool isPaused;
86
87 int shipsRemain;
88 int score;
89 int level;
90 bool showHiscores;
91
92 enum Action { Launch, Thrust, RotateLeft, RotateRight, Shoot, Teleport,
93 Brake, Shield, Pause, NewGame };
94
95 QMap<int,Action> actions;
96};
97
98#endif
99
diff --git a/noncore/games/qasteroids/view.cpp b/noncore/games/qasteroids/view.cpp
new file mode 100644
index 0000000..ef08343
--- a/dev/null
+++ b/noncore/games/qasteroids/view.cpp
@@ -0,0 +1,884 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************//*
20 * KAsteroids - Copyright (c) Martin R. Jones 1997
21 *
22 * Part of the KDE project
23 */
24
25#include "view.h"
26
27#include <qpe/resource.h>
28
29#include <qapplication.h>
30#include <qkeycode.h>
31#include <qaccel.h>
32
33#include <stdlib.h>
34#include <math.h>
35
36#define IMG_BACKGROUND "qasteroids/bg.png"
37
38#define REFRESH_DELAY 33
39#define SHIP_SPEED 0.3
40#define MISSILE_SPEED 10.0
41#define SHIP_STEPS 64
42#define ROTATE_RATE 2
43#define SHIELD_ON_COST 1
44#define SHIELD_HIT_COST 30
45#define BRAKE_ON_COST 4
46
47#define MAX_ROCK_SPEED 2.5
48#define MAX_POWERUP_SPEED 1.5
49 #define MAX_SHIP_SPEED 8
50#define MAX_BRAKES 5
51#define MAX_SHIELDS 5
52 #define MAX_FIREPOWER 5
53
54#define TEXT_SPEED 4
55
56#define PI_X_2 6.283185307
57#ifndef M_PI
58#define M_PI 3.141592654
59#endif
60
61struct
62{
63 int id;
64 const char *path;
65 int frames;
66}
67kas_animations [] =
68{
69// { ID_ROCK_LARGE, "rock1/rock1\%1.png", 32 },
70 { ID_ROCK_MEDIUM, "rock2/rock2\%1.png", 32 },
71 { ID_ROCK_SMALL, "rock3/rock3\%1.png", 32 },
72 { ID_SHIP, "ship/ship\%1.png", 32 },
73 { ID_MISSILE, "missile/missile.png", 1 },
74 { ID_BIT, "bits/bits\%1.png", 16 },
75 { ID_EXHAUST, "exhaust/exhaust.png", 1 },
76 { ID_ENERGY_POWERUP, "powerups/energy.png", 1 },
77// { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 },
78 { ID_BRAKE_POWERUP, "powerups/brake.png", 1 },
79 { ID_SHIELD_POWERUP, "powerups/shield.png", 1 },
80 { ID_SHOOT_POWERUP, "powerups/shoot.png", 1 },
81 { ID_SHIELD, "shield/shield\%1.png", 6 },
82 { 0, 0, 0 }
83};
84
85
86
87KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name )
88 : QWidget( parent, name ),
89 field(200, 200),
90 view(&field,this)
91{
92 view.setVScrollBarMode( QScrollView::AlwaysOff );
93 view.setHScrollBarMode( QScrollView::AlwaysOff );
94 rocks.setAutoDelete( TRUE );
95 missiles.setAutoDelete( TRUE );
96 bits.setAutoDelete( TRUE );
97 powerups.setAutoDelete( TRUE );
98 exhaust.setAutoDelete( TRUE );
99
100 QPixmap pm( Resource::loadPixmap(IMG_BACKGROUND) );
101 field.setBackgroundPixmap( pm );
102
103 textSprite = new QCanvasText( &field );
104 QFont font( "helvetica", 14 );
105 textSprite->setFont( font );
106
107 shield = 0;
108 shieldOn = FALSE;
109 refreshRate = REFRESH_DELAY;
110
111 readSprites();
112
113 shieldTimer = new QTimer( this );
114 connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) );
115 mTimerId = -1;
116
117 shipPower = MAX_POWER_LEVEL;
118 vitalsChanged = TRUE;
119 can_destroy_powerups = FALSE;
120
121 mPaused = TRUE;
122}
123
124// - - -
125
126KAsteroidsView::~KAsteroidsView()
127{
128}
129
130// - - -
131
132void KAsteroidsView::reset()
133{
134 rocks.clear();
135 missiles.clear();
136 bits.clear();
137 powerups.clear();
138 exhaust.clear();
139
140 shotsFired = 0;
141 shotsHit = 0;
142
143 rockSpeed = 1.0;
144 powerupSpeed = 1.0;
145 mFrameNum = 0;
146 mPaused = FALSE;
147
148 ship->hide();
149 shield->hide();
150/*
151 if ( mTimerId >= 0 ) {
152 killTimer( mTimerId );
153 mTimerId = -1;
154 }
155*/
156}
157
158// - --
159
160void KAsteroidsView::newGame()
161{
162 if ( shieldOn )
163 {
164 shield->hide();
165 shieldOn = FALSE;
166 }
167 reset();
168 if ( mTimerId < 0 )
169 mTimerId = startTimer( REFRESH_DELAY );
170 emit updateVitals();
171}
172
173// - - -
174
175void KAsteroidsView::endGame()
176{
177}
178
179void KAsteroidsView::pause( bool p )
180{
181 if ( !mPaused && p ) {
182 if ( mTimerId >= 0 ) {
183 killTimer( mTimerId );
184 mTimerId = -1;
185 }
186 } else if ( mPaused && !p )
187 mTimerId = startTimer( REFRESH_DELAY );
188 mPaused = p;
189}
190
191// - - -
192
193void KAsteroidsView::newShip()
194{
195 ship->move( field.width()/2, field.height()/2, 0 );
196 shield->move( field.width()/2, field.height()/2, 0 );
197 ship->setVelocity( 0.0, 0.0 );
198 shipDx = 0;
199 shipDy = 0;
200 shipAngle = 0;
201 rotateL = FALSE;
202 rotateR = FALSE;
203 thrustShip = FALSE;
204 shootShip = FALSE;
205 brakeShip = FALSE;
206 teleportShip = FALSE;
207 shieldOn = TRUE;
208 shootDelay = 0;
209 shipPower = MAX_POWER_LEVEL;
210 rotateRate = ROTATE_RATE;
211 rotateSlow = 0;
212
213 mBrakeCount = 0;
214 mTeleportCount = 0;
215 mShootCount = 0;
216
217 ship->show();
218 shield->show();
219 mShieldCount = 1; // just in case the ship appears on a rock.
220 shieldTimer->start( 1000, TRUE );
221}
222
223void KAsteroidsView::setShield( bool s )
224{
225 if ( shieldTimer->isActive() && !s ) {
226 shieldTimer->stop();
227 hideShield();
228 } else {
229 shieldOn = s && mShieldCount;
230 }
231}
232
233void KAsteroidsView::brake( bool b )
234{
235 if ( mBrakeCount )
236 {
237 if ( brakeShip && !b )
238 {
239 rotateL = FALSE;
240 rotateR = FALSE;
241 thrustShip = FALSE;
242 rotateRate = ROTATE_RATE;
243 }
244
245 brakeShip = b;
246 }
247}
248
249// - - -
250
251void KAsteroidsView::readSprites()
252{
253 QString sprites_prefix = Resource::findPixmap( IMG_BACKGROUND );
254 int sep = sprites_prefix.findRev( "/" );
255
256 sprites_prefix.truncate( sep );
257
258 int i = 0;
259 while ( kas_animations[i].id )
260 {
261 animation.insert( kas_animations[i].id,
262 new QCanvasPixmapArray( sprites_prefix + "/" + kas_animations[i].path,
263 kas_animations[i].frames ) );
264 i++;
265 }
266
267 ship = new QCanvasSprite( animation[ID_SHIP], &field );
268 ship->hide();
269
270 shield = new KShield( animation[ID_SHIELD], &field );
271 shield->hide();
272}
273
274// - - -
275
276void KAsteroidsView::addRocks( int num )
277{
278 for ( int i = 0; i < num; i++ )
279 {
280 KRock *rock = new KRock( animation[ID_ROCK_MEDIUM], &field,
281 ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 );
282 double dx = (2.0 - randDouble()*4.0) * rockSpeed;
283 double dy = (2.0 - randDouble()*4.0) * rockSpeed;
284 rock->setVelocity( dx, dy );
285 rock->setFrame( randInt( rock->frameCount() ) );
286 if ( dx > 0 )
287 {
288 if ( dy > 0 )
289 rock->move( 5, 5, 0 );
290 else
291 rock->move( 5, field.height() - 25, 0 );
292 }
293 else
294 {
295 if ( dy > 0 )
296 rock->move( field.width() - 25, 5, 0 );
297 else
298 rock->move( field.width() - 25, field.height() - 25, 0 );
299 }
300 rock->show( );
301 rocks.append( rock );
302 }
303}
304
305// - - -
306
307void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll )
308{
309 textSprite->setTextFlags( AlignLeft | AlignVCenter );
310 textSprite->setText( text );
311 textSprite->setColor( color );
312
313 if ( scroll ) {
314 textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2,
315 -textSprite->boundingRect().height() );
316 textDy = TEXT_SPEED;
317 } else {
318 textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2,
319 (field.height()-textSprite->boundingRect().height()) / 2 );
320 textDy = 0;
321 }
322 textSprite->show();
323}
324
325// - - -
326
327void KAsteroidsView::hideText()
328{
329 textDy = -TEXT_SPEED;
330}
331
332// - - -
333
334void KAsteroidsView::resizeEvent(QResizeEvent* event)
335{
336 QWidget::resizeEvent(event);
337 field.resize(width()-4, height()-4);
338 view.resize(width(),height());
339}
340
341// - - -
342
343void KAsteroidsView::timerEvent( QTimerEvent * )
344{
345 field.advance();
346
347 QCanvasSprite *rock;
348
349 // move rocks forward
350 for ( rock = rocks.first(); rock; rock = rocks.next() ) {
351 ((KRock *)rock)->nextFrame();
352 wrapSprite( rock );
353 }
354
355 wrapSprite( ship );
356
357 // check for missile collision with rocks.
358 processMissiles();
359
360 // these are generated when a ship explodes
361 for ( KBit *bit = bits.first(); bit; bit = bits.next() )
362 {
363 if ( bit->expired() )
364 {
365 bits.removeRef( bit );
366 }
367 else
368 {
369 bit->growOlder();
370 bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() );
371 }
372 }
373
374 for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() )
375 exhaust.removeRef( e );
376
377 // move / rotate ship.
378 // check for collision with a rock.
379 processShip();
380
381 // move powerups and check for collision with player and missiles
382 processPowerups();
383
384 if ( textSprite->visible() )
385 {
386 if ( textDy < 0 &&
387 textSprite->boundingRect().y() <= -textSprite->boundingRect().height() ) {
388 textSprite->hide();
389 } else {
390 textSprite->moveBy( 0, textDy );
391 }
392 if ( textSprite->boundingRect().y() > (field.height()-textSprite->boundingRect().height())/2 )
393 textDy = 0;
394 }
395
396 if ( vitalsChanged && !(mFrameNum % 10) ) {
397 emit updateVitals();
398 vitalsChanged = FALSE;
399 }
400
401 mFrameNum++;
402}
403
404void KAsteroidsView::wrapSprite( QCanvasItem *s )
405{
406 int x = int(s->x() + s->boundingRect().width() / 2);
407 int y = int(s->y() + s->boundingRect().height() / 2);
408
409 if ( x > field.width() )
410 s->move( s->x() - field.width(), s->y() );
411 else if ( x < 0 )
412 s->move( field.width() + s->x(), s->y() );
413
414 if ( y > field.height() )
415 s->move( s->x(), s->y() - field.height() );
416 else if ( y < 0 )
417 s->move( s->x(), field.height() + s->y() );
418}
419
420// - - -
421
422void KAsteroidsView::rockHit( QCanvasItem *hit )
423{
424 KPowerup *nPup = 0;
425 int rnd = static_cast<int>(randDouble()*30.0) % 30;
426 switch( rnd )
427 {
428 case 4:
429 case 5:
430 nPup = new KPowerup( animation[ID_ENERGY_POWERUP], &field,
431 ID_ENERGY_POWERUP );
432 break;
433 case 10:
434// nPup = new KPowerup( animation[ID_TELEPORT_POWERUP], &field,
435// ID_TELEPORT_POWERUP );
436 break;
437 case 15:
438 nPup = new KPowerup( animation[ID_BRAKE_POWERUP], &field,
439 ID_BRAKE_POWERUP );
440 break;
441 case 20:
442 nPup = new KPowerup( animation[ID_SHIELD_POWERUP], &field,
443 ID_SHIELD_POWERUP );
444 break;
445 case 24:
446 case 25:
447 nPup = new KPowerup( animation[ID_SHOOT_POWERUP], &field,
448 ID_SHOOT_POWERUP );
449 break;
450 }
451 if ( nPup )
452 {
453 double r = 0.5 - randDouble();
454 nPup->move( hit->x(), hit->y(), 0 );
455 nPup->setVelocity( hit->xVelocity() + r, hit->yVelocity() + r );
456 nPup->show( );
457 powerups.append( nPup );
458 }
459
460 if ( hit->rtti() == ID_ROCK_LARGE || hit->rtti() == ID_ROCK_MEDIUM )
461 {
462 // break into smaller rocks
463 double addx[4] = { 1.0, 1.0, -1.0, -1.0 };
464 double addy[4] = { -1.0, 1.0, -1.0, 1.0 };
465
466 double dx = hit->xVelocity();
467 double dy = hit->yVelocity();
468
469 double maxRockSpeed = MAX_ROCK_SPEED * rockSpeed;
470 if ( dx > maxRockSpeed )
471 dx = maxRockSpeed;
472 else if ( dx < -maxRockSpeed )
473 dx = -maxRockSpeed;
474 if ( dy > maxRockSpeed )
475 dy = maxRockSpeed;
476 else if ( dy < -maxRockSpeed )
477 dy = -maxRockSpeed;
478
479 QCanvasSprite *nrock;
480
481 for ( int i = 0; i < 4; i++ )
482 {
483 double r = rockSpeed/2 - randDouble()*rockSpeed;
484 if ( hit->rtti() == ID_ROCK_LARGE )
485 {
486 nrock = new KRock( animation[ID_ROCK_MEDIUM], &field,
487 ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 );
488 emit rockHit( 0 );
489 }
490 else
491 {
492 nrock = new KRock( animation[ID_ROCK_SMALL], &field,
493 ID_ROCK_SMALL, randInt(2), randInt(2) ? -1 : 1 );
494 emit rockHit( 1 );
495 }
496
497 nrock->move( hit->x(), hit->y(), 0 );
498 nrock->setVelocity( dx+addx[i]*rockSpeed+r, dy+addy[i]*rockSpeed+r );
499 nrock->setFrame( randInt( nrock->frameCount() ) );
500 nrock->show( );
501 rocks.append( nrock );
502 }
503 }
504 else if ( hit->rtti() == ID_ROCK_SMALL )
505 emit rockHit( 2 );
506 rocks.removeRef( (QCanvasSprite *)hit );
507 if ( rocks.count() == 0 )
508 emit rocksRemoved();
509}
510
511void KAsteroidsView::reducePower( int val )
512{
513 shipPower -= val;
514 if ( shipPower <= 0 )
515 {
516 shipPower = 0;
517 thrustShip = FALSE;
518 if ( shieldOn )
519 {
520 shieldOn = FALSE;
521 shield->hide();
522 }
523 }
524 vitalsChanged = TRUE;
525}
526
527void KAsteroidsView::addExhaust( double x, double y, double dx,
528 double dy, int count )
529{
530 for ( int i = 0; i < count; i++ )
531 {
532 KExhaust *e = new KExhaust( animation[ID_EXHAUST], &field );
533 e->move( x + 2 - randDouble()*4, y + 2 - randDouble()*4 );
534 e->setVelocity( dx, dy );
535 e->show( );
536 exhaust.append( e );
537 }
538}
539
540void KAsteroidsView::processMissiles()
541{
542 KMissile *missile;
543
544 // if a missile has hit a rock, remove missile and break rock into smaller
545 // rocks or remove completely.
546 QPtrListIterator<KMissile> it(missiles);
547
548 for ( ; it.current(); ++it )
549 {
550 missile = it.current();
551 missile->growOlder();
552
553 if ( missile->expired() )
554 {
555 missiles.removeRef( missile );
556 continue;
557 }
558
559 wrapSprite( missile );
560
561 QCanvasItemList hits = missile->collisions( TRUE );
562 QCanvasItemList::Iterator hit;
563 for ( hit = hits.begin(); hit != hits.end(); ++hit )
564 {
565 if ( (*hit)->rtti() >= ID_ROCK_LARGE &&
566 (*hit)->rtti() <= ID_ROCK_SMALL )
567 {
568 shotsHit++;
569 rockHit( *hit );
570 missiles.removeRef( missile );
571 break;
572 }
573 }
574 }
575}
576
577// - - -
578
579void KAsteroidsView::processShip()
580{
581 if ( ship->visible() )
582 {
583 if ( shieldOn )
584 {
585 shield->show();
586 reducePower( SHIELD_ON_COST );
587 static int sf = 0;
588 sf++;
589
590 if ( sf % 2 )
591 shield->setFrame( (shield->frame()+1) % shield->frameCount() );
592 shield->move( ship->x() - 5, ship->y() - 5 );
593
594 QCanvasItemList hits = shield->collisions( TRUE );
595 QCanvasItemList::Iterator it;
596 for ( it = hits.begin(); it != hits.end(); ++it )
597 {
598 if ( (*it)->rtti() >= ID_ROCK_LARGE &&
599 (*it)->rtti() <= ID_ROCK_SMALL )
600 {
601 int factor;
602 switch ( (*it)->rtti() )
603 {
604 case ID_ROCK_LARGE:
605 factor = 3;
606 break;
607
608 case ID_ROCK_MEDIUM:
609 factor = 2;
610 break;
611
612 default:
613 factor = 1;
614 }
615
616 if ( factor > mShieldCount )
617 {
618 // shield not strong enough
619 shieldOn = FALSE;
620 break;
621 }
622 rockHit( *it );
623 // the more shields we have the less costly
624 reducePower( factor * (SHIELD_HIT_COST - mShieldCount*2) );
625 }
626 }
627 }
628
629 if ( !shieldOn )
630 {
631 shield->hide();
632 QCanvasItemList hits = ship->collisions( TRUE );
633 QCanvasItemList::Iterator it;
634 for ( it = hits.begin(); it != hits.end(); ++it )
635 {
636 if ( (*it)->rtti() >= ID_ROCK_LARGE &&
637 (*it)->rtti() <= ID_ROCK_SMALL )
638 {
639 KBit *bit;
640 for ( int i = 0; i < 8; i++ )
641 {
642 bit = new KBit( animation[ID_BIT], &field );
643 bit->move( ship->x() + 5 - randDouble() * 10,
644 ship->y() + 5 - randDouble() * 10,
645 randInt(bit->frameCount()) );
646 bit->setVelocity( 1-randDouble()*2,
647 1-randDouble()*2 );
648 bit->setDeath( 60 + randInt(60) );
649 bit->show( );
650 bits.append( bit );
651 }
652 ship->hide();
653 shield->hide();
654 emit shipKilled();
655 break;
656 }
657 }
658 }
659
660
661 if ( rotateSlow )
662 rotateSlow--;
663
664 if ( rotateL )
665 {
666 shipAngle -= rotateSlow ? 1 : rotateRate;
667 if ( shipAngle < 0 )
668 shipAngle += SHIP_STEPS;
669 }
670
671 if ( rotateR )
672 {
673 shipAngle += rotateSlow ? 1 : rotateRate;
674 if ( shipAngle >= SHIP_STEPS )
675 shipAngle -= SHIP_STEPS;
676 }
677
678 double angle = shipAngle * PI_X_2 / SHIP_STEPS;
679 double cosangle = cos( angle );
680 double sinangle = sin( angle );
681
682 if ( brakeShip )
683 {
684 thrustShip = FALSE;
685 rotateL = FALSE;
686 rotateR = FALSE;
687 rotateRate = ROTATE_RATE;
688 if ( fabs(shipDx) < 2.5 && fabs(shipDy) < 2.5 )
689 {
690 shipDx = 0.0;
691 shipDy = 0.0;
692 ship->setVelocity( shipDx, shipDy );
693 brakeShip = FALSE;
694 }
695 else
696 {
697 double motionAngle = atan2( -shipDy, -shipDx );
698 if ( angle > M_PI )
699 angle -= PI_X_2;
700 double angleDiff = angle - motionAngle;
701 if ( angleDiff > M_PI )
702 angleDiff = PI_X_2 - angleDiff;
703 else if ( angleDiff < -M_PI )
704 angleDiff = PI_X_2 + angleDiff;
705 double fdiff = fabs( angleDiff );
706 if ( fdiff > 0.08 )
707 {
708 if ( angleDiff > 0 )
709 rotateL = TRUE;
710 else if ( angleDiff < 0 )
711 rotateR = TRUE;
712 if ( fdiff > 0.6 )
713 rotateRate = mBrakeCount + 1;
714 else if ( fdiff > 0.4 )
715 rotateRate = 2;
716 else
717 rotateRate = 1;
718
719 if ( rotateRate > 5 )
720 rotateRate = 5;
721 }
722 else if ( fabs(shipDx) > 1 || fabs(shipDy) > 1 )
723 {
724 thrustShip = TRUE;
725 // we'll make braking a bit faster
726 shipDx += cosangle/6 * (mBrakeCount - 1);
727 shipDy += sinangle/6 * (mBrakeCount - 1);
728 reducePower( BRAKE_ON_COST );
729 addExhaust( ship->x() + 10 - cosangle*11,
730 ship->y() + 10 - sinangle*11,
731 shipDx-cosangle, shipDy-sinangle,
732 mBrakeCount+1 );
733 }
734 }
735 }
736
737 if ( thrustShip )
738 {
739 // The ship has a terminal velocity, but trying to go faster
740 // still uses fuel (can go faster diagonally - don't care).
741 double thrustx = cosangle/8;
742 double thrusty = sinangle/8;
743 if ( fabs(shipDx + thrustx) < MAX_SHIP_SPEED )
744 shipDx += thrustx;
745 if ( fabs(shipDy + thrusty) < MAX_SHIP_SPEED )
746 shipDy += thrusty;
747 ship->setVelocity( shipDx, shipDy );
748 reducePower( 1 );
749 addExhaust( ship->x() + 10 - cosangle*10,
750 ship->y() + 10 - sinangle*10,
751 shipDx-cosangle, shipDy-sinangle, 3 );
752 }
753
754 ship->setFrame( shipAngle >> 1 );
755
756 if ( shootShip )
757 {
758 if ( !shootDelay && (int)missiles.count() < mShootCount + 2 )
759 {
760 KMissile *missile = new KMissile( animation[ID_MISSILE], &field );
761 missile->move( 11+ship->x()+cosangle*11,
762 11+ship->y()+sinangle*11, 0 );
763 missile->setVelocity( shipDx + cosangle*MISSILE_SPEED,
764 shipDy + sinangle*MISSILE_SPEED );
765 missile->show( );
766 missiles.append( missile );
767 shotsFired++;
768 reducePower( 1 );
769
770 shootDelay = 5;
771 }
772
773 if ( shootDelay )
774 shootDelay--;
775 }
776
777 if ( teleportShip )
778 {
779 int ra = rand() % 10;
780 if( ra == 0 )
781 ra += rand() % 20;
782 int xra = ra * 60 + ( (rand() % 20) * (rand() % 20) );
783 int yra = ra * 50 - ( (rand() % 20) * (rand() % 20) );
784 ship->move( xra, yra );
785 }
786
787 vitalsChanged = TRUE;
788 }
789}
790
791// - - -
792
793void KAsteroidsView::processPowerups()
794{
795 if ( !powerups.isEmpty() )
796 {
797 // if player gets the powerup remove it from the screen, if option
798 // "Can destroy powerups" is enabled and a missile hits the powerup
799 // destroy it
800
801 KPowerup *pup;
802 QPtrListIterator<KPowerup> it( powerups );
803
804 for( ; it.current(); ++it )
805 {
806 pup = it.current();
807 pup->growOlder();
808
809 if( pup->expired() )
810 {
811 powerups.removeRef( pup );
812 continue;
813 }
814
815 wrapSprite( pup );
816
817 QCanvasItemList hits = pup->collisions( TRUE );
818 QCanvasItemList::Iterator it;
819 for ( it = hits.begin(); it != hits.end(); ++it )
820 {
821 if ( (*it) == ship )
822 {
823 switch( pup->rtti() )
824 {
825 case ID_ENERGY_POWERUP:
826 shipPower += 150;
827 if ( shipPower > MAX_POWER_LEVEL )
828 shipPower = MAX_POWER_LEVEL;
829 break;
830 case ID_TELEPORT_POWERUP:
831 mTeleportCount++;
832 break;
833 case ID_BRAKE_POWERUP:
834 if ( mBrakeCount < MAX_BRAKES )
835 mBrakeCount++;
836 break;
837 case ID_SHIELD_POWERUP:
838 if ( mShieldCount < MAX_SHIELDS )
839 mShieldCount++;
840 break;
841 case ID_SHOOT_POWERUP:
842 if ( mShootCount < MAX_FIREPOWER )
843 mShootCount++;
844 break;
845 }
846
847 powerups.removeRef( pup );
848 vitalsChanged = TRUE;
849 }
850 else if ( (*it) == shield )
851 {
852 powerups.removeRef( pup );
853 }
854 else if ( (*it)->rtti() == ID_MISSILE )
855 {
856 if ( can_destroy_powerups )
857 {
858 powerups.removeRef( pup );
859 }
860 }
861 }
862 }
863 } // -- if( powerups.isEmpty() )
864}
865
866// - - -
867
868void KAsteroidsView::hideShield()
869{
870 shield->hide();
871 mShieldCount = 0;
872 shieldOn = FALSE;
873}
874
875double KAsteroidsView::randDouble()
876{
877 int v = rand();
878 return (double)v / (double)RAND_MAX;
879}
880
881int KAsteroidsView::randInt( int range )
882{
883 return rand() % range;
884}
diff --git a/noncore/games/qasteroids/view.h b/noncore/games/qasteroids/view.h
new file mode 100644
index 0000000..0a7902b
--- a/dev/null
+++ b/noncore/games/qasteroids/view.h
@@ -0,0 +1,156 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************//*
20 * KAsteroids - Copyright (c) Martin R. Jones 1997
21 *
22 * Part of the KDE project
23 */
24
25#ifndef __AST_VIEW_H__
26#define __AST_VIEW_H__
27
28#include <qwidget.h>
29#include <qlist.h>
30#include <qintdict.h>
31#include <qtimer.h>
32#include <qcanvas.h>
33#include "sprites.h"
34
35#define QPtrList QList
36#define QPtrListIterator QListIterator
37
38#define MAX_POWER_LEVEL 1000
39
40class KAsteroidsView : public QWidget
41{
42 Q_OBJECT
43public:
44 KAsteroidsView( QWidget *parent = 0, const char *name = 0 );
45 virtual ~KAsteroidsView();
46
47 int refreshRate;
48
49 void reset();
50 void setRockSpeed( double rs ) { rockSpeed = rs; }
51 void addRocks( int num );
52 void newGame();
53 void endGame();
54 void newShip();
55
56 void rotateLeft( bool r ) { rotateL = r; rotateSlow = 5; }
57 void rotateRight( bool r ) { rotateR = r; rotateSlow = 5; }
58 void thrust( bool t ) { thrustShip = t && shipPower > 0; }
59 void shoot( bool s ) { shootShip = s; shootDelay = 0; }
60 void setShield( bool s );
61 void teleport( bool te) { teleportShip = te && mTeleportCount; }
62 void brake( bool b );
63 void pause( bool p);
64
65 void showText( const QString &text, const QColor &color, bool scroll=TRUE );
66 void hideText();
67
68 int shots() const { return shotsFired; }
69 int hits() const { return shotsHit; }
70 int power() const { return shipPower; }
71
72 int teleportCount() const { return mTeleportCount; }
73 int brakeCount() const { return mBrakeCount; }
74 int shieldCount() const { return mShieldCount; }
75 int shootCount() const { return mShootCount; }
76
77signals:
78 void shipKilled();
79 void rockHit( int size );
80 void rocksRemoved();
81 void updateVitals();
82
83private slots:
84 void hideShield();
85
86protected:
87 void readSprites();
88 void wrapSprite( QCanvasItem * );
89 void rockHit( QCanvasItem * );
90 void reducePower( int val );
91 void addExhaust( double x, double y, double dx, double dy, int count );
92 void processMissiles();
93 void processShip();
94 void processPowerups();
95 void processShield();
96 double randDouble();
97 int randInt( int range );
98
99 virtual void resizeEvent( QResizeEvent *event );
100 virtual void timerEvent( QTimerEvent * );
101
102private:
103 QCanvas field;
104 QCanvasView view;
105 QIntDict<QCanvasPixmapArray> animation;
106 QPtrList<QCanvasSprite> rocks;
107 QPtrList<KMissile> missiles;
108 QPtrList<KBit> bits;
109 QPtrList<KExhaust> exhaust;
110 QPtrList<KPowerup> powerups;
111 KShield *shield;
112 QCanvasSprite *ship;
113 QCanvasText *textSprite;
114
115 bool rotateL;
116 bool rotateR;
117 bool thrustShip;
118 bool shootShip;
119 bool teleportShip;
120 bool brakeShip;
121 bool pauseShip;
122 bool shieldOn;
123
124 bool vitalsChanged;
125
126 int shipAngle;
127 int rotateSlow;
128 int rotateRate;
129 int shipPower;
130
131 int shotsFired;
132 int shotsHit;
133 int shootDelay;
134
135 int mBrakeCount;
136 int mShieldCount;
137 int mTeleportCount;
138 int mShootCount;
139
140 double shipDx;
141 double shipDy;
142
143 int textDy;
144 int mFrameNum;
145 bool mPaused;
146 int mTimerId;
147
148 double rockSpeed;
149 double powerupSpeed;
150
151 bool can_destroy_powerups;
152
153 QTimer *shieldTimer;
154};
155
156#endif
diff --git a/noncore/games/snake/.cvsignore b/noncore/games/snake/.cvsignore
new file mode 100644
index 0000000..edfa921
--- a/dev/null
+++ b/noncore/games/snake/.cvsignore
@@ -0,0 +1,3 @@
1moc_*
2*.moc
3Makefile
diff --git a/noncore/games/snake/Makefile.in b/noncore/games/snake/Makefile.in
new file mode 100644
index 0000000..8179b6f
--- a/dev/null
+++ b/noncore/games/snake/Makefile.in
@@ -0,0 +1,159 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= snake
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =snake.h \
27 target.h \
28 obstacle.h \
29 interface.h \
30 codes.h
31 SOURCES =snake.cpp \
32 target.cpp \
33 obstacle.cpp \
34 interface.cpp \
35 main.cpp
36 OBJECTS =snake.o \
37 target.o \
38 obstacle.o \
39 interface.o \
40 main.o
41INTERFACES =
42UICDECLS =
43UICIMPLS =
44 SRCMOC =moc_snake.cpp \
45 moc_interface.cpp
46 OBJMOC =moc_snake.o \
47 moc_interface.o
48
49
50####### Implicit rules
51
52.SUFFIXES: .cpp .cxx .cc .C .c
53
54.cpp.o:
55 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
56
57.cxx.o:
58 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
59
60.cc.o:
61 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
62
63.C.o:
64 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
65
66.c.o:
67 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
68
69####### Build rules
70
71
72all: $(DESTDIR)$(TARGET)
73
74$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
75 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
76
77moc: $(SRCMOC)
78
79tmake:
80 tmake snake.pro
81
82clean:
83 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
84 -rm -f *~ core
85 -rm -f allmoc.cpp
86
87####### Extension Modules
88
89listpromodules:
90 @echo
91
92listallmodules:
93 @echo
94
95listaddonpromodules:
96 @echo
97
98listaddonentmodules:
99 @echo
100
101
102REQUIRES=
103
104####### Sub-libraries
105
106
107###### Combined headers
108
109
110
111####### Compile
112
113snake.o: snake.cpp \
114 snake.h \
115 target.h \
116 codes.h \
117 $(QPEDIR)/include/qpe/resource.h
118
119target.o: target.cpp \
120 target.h \
121 codes.h \
122 $(QPEDIR)/include/qpe/resource.h
123
124obstacle.o: obstacle.cpp \
125 obstacle.h \
126 codes.h \
127 $(QPEDIR)/include/qpe/resource.h
128
129interface.o: interface.cpp \
130 interface.h \
131 snake.h \
132 target.h \
133 obstacle.h \
134 $(QPEDIR)/include/qpe/resource.h \
135 $(QPEDIR)/include/qpe/qpetoolbar.h
136
137main.o: main.cpp \
138 interface.h \
139 snake.h \
140 target.h \
141 obstacle.h \
142 $(QPEDIR)/include/qpe/qpeapplication.h
143
144moc_snake.o: moc_snake.cpp \
145 snake.h
146
147moc_interface.o: moc_interface.cpp \
148 interface.h \
149 snake.h \
150 target.h \
151 obstacle.h
152
153moc_snake.cpp: snake.h
154 $(MOC) snake.h -o moc_snake.cpp
155
156moc_interface.cpp: interface.h
157 $(MOC) interface.h -o moc_interface.cpp
158
159
diff --git a/noncore/games/snake/codes.h b/noncore/games/snake/codes.h
new file mode 100644
index 0000000..3b5e4d0
--- a/dev/null
+++ b/noncore/games/snake/codes.h
@@ -0,0 +1,20 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/const int target_rtti = 1500;
20const int obstacle_rtti = 1600;
diff --git a/noncore/games/snake/interface.cpp b/noncore/games/snake/interface.cpp
new file mode 100644
index 0000000..c9b4931
--- a/dev/null
+++ b/noncore/games/snake/interface.cpp
@@ -0,0 +1,224 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "interface.h"
22
23#include <qpe/resource.h>
24
25#include <qpe/qpetoolbar.h>
26#include <qtoolbutton.h>
27#include <qstyle.h>
28#include <qapplication.h>
29#include <qmessagebox.h>
30
31SnakeGame::SnakeGame(QWidget* parent, const char* name, WFlags f) :
32 QMainWindow(parent,name,f),
33 canvas(232, 258)
34{
35 setCaption( tr("Snake") );
36 QPixmap bg = Resource::loadPixmap("grass");
37 canvas.setBackgroundPixmap(bg);
38 canvas.setUpdatePeriod(100);
39 snake = 0;
40
41 cv = new QCanvasView(&canvas, this);
42
43 pauseTimer = new QTimer(this);
44 connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) );
45
46 setToolBarsMovable( FALSE );
47
48 QPEToolBar* toolbar = new QPEToolBar( this);
49 toolbar->setHorizontalStretchable( TRUE );
50
51 QPixmap newicon = Resource::loadPixmap("ksnake");
52 setIcon(newicon);
53 (void)new QToolButton(newicon, tr("New Game"), 0,
54 this, SLOT(newGame()), toolbar, "New Game");
55
56 scorelabel = new QLabel(toolbar);
57 showScore(0);
58 scorelabel->setBackgroundMode( PaletteButton );
59 scorelabel->setAlignment( AlignRight | AlignVCenter | ExpandTabs );
60 toolbar->setStretchableWidget( scorelabel );
61
62 setFocusPolicy(StrongFocus);
63
64 setCentralWidget(cv);
65
66 welcomescreen();
67 gamestopped = true;
68 waitover = true;
69}
70
71SnakeGame::~SnakeGame()
72{
73 delete snake;
74}
75
76void SnakeGame::resizeEvent(QResizeEvent *)
77{
78 QSize s = centralWidget()->size();
79 int fw = style().defaultFrameWidth();
80 canvas.resize( s.width() - fw - 2, s.height() - fw - 2);
81}
82
83void SnakeGame::welcomescreen()
84{
85 QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas);
86 title->setColor(yellow);
87 title->setFont( QFont("times", 18, QFont::Bold) );
88 int w = title->boundingRect().width();
89 title->move(canvas.width()/2 -w/2, canvas.height()/2-110);
90 title->show();
91 QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("title"));
92 QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas);
93 titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85);
94 titlepic->show();
95 QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n"
96 "snake to eat the mouse. You must not\n"
97 "crash into the walls, edges or its tail."),
98 &canvas);
99 w = instr->boundingRect().width();
100 instr->move(canvas.width()/2-w/2, canvas.height()/2-20);
101 instr->setColor(white);
102 instr->show();
103 QCanvasText* cont = new QCanvasText(tr("Press Any Key To Start"), &canvas);
104 w = cont->boundingRect().width();
105 cont->move(canvas.width()/2-w/2, canvas.height()/2+80);
106 cont->setColor(yellow);
107 cont->show();
108
109}
110
111void SnakeGame::newGame()
112{
113 clear();
114 snake = new Snake(&canvas);
115 connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) );
116 connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) );
117 connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) );
118 connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) );
119 last = 0;
120 targetamount = 1;
121 notargets = 1;
122 level = 1;
123 stage = 1;
124 showScore(0);
125 gamestopped = false;
126 waitover = true;
127 int x = canvas.width()/2 - 70;
128 x = x - x % 16;
129 int y = canvas.height()-50;
130 y = y - y % 16;
131 (void)new Obstacle(&canvas, x, 32);
132 (void)new Obstacle(&canvas, x, y);
133 createTargets();
134}
135
136
137void SnakeGame::showScore(int score)
138{
139 scorelabel->setText(tr(" Score : %1 ").arg(score) );
140}
141
142
143void SnakeGame::scoreInc()
144{
145 showScore( snake->getScore() );
146}
147
148void SnakeGame::levelUp()
149{
150 notargets--;
151 if (notargets == 0) {
152 stage++;
153 if (stage == 3) {
154 level++;
155 emit moveFaster();
156 targetamount++;
157 stage = 0;
158 }
159 createTargets();
160 }
161}
162
163void SnakeGame::createTargets()
164{
165 for (int i = 0; i < targetamount; i++)
166 (void)new Target(&canvas);
167 notargets = targetamount;
168}
169
170void SnakeGame::clear()
171{
172 delete snake;
173 snake = 0;
174 QCanvasItemList l = canvas.allItems();
175 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
176 delete *it;
177 }
178}
179
180void SnakeGame::gameOver()
181{
182 int score = snake->getScore();
183 QString scoreoutput="";
184 scoreoutput.setNum(score);
185 QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas);
186
187 gameover->setZ(100);
188 gameover->setColor(yellow);
189 gameover->setFont( QFont("times", 18, QFont::Bold) );
190 int w = gameover->boundingRect().width();
191 gameover->move(canvas.width()/2 -w/2, canvas.height()/2 -50);
192 gameover->show();
193 gamestopped = true;
194 waitover = false;
195 pauseTimer->start(2500);
196}
197
198void SnakeGame::wait()
199{
200 waitover = true;
201 pauseTimer->stop();
202 QCanvasText* cont = new QCanvasText(tr("Press Any Key to Begin a New Game."),
203 &canvas);
204 cont->setZ(100);
205 cont->setColor(white);
206 int w = cont->boundingRect().width();
207 cont->move(canvas.width()/2 -w/2, canvas.height()/2);
208 cont->show();
209}
210
211void SnakeGame::keyPressEvent(QKeyEvent* event)
212{
213 if (gamestopped) {
214 if (waitover)
215 newGame();
216 else
217 return;
218 }
219 else {
220 int newkey = event->key();
221 snake->go(newkey);
222 }
223}
224
diff --git a/noncore/games/snake/interface.h b/noncore/games/snake/interface.h
new file mode 100644
index 0000000..30c7f84
--- a/dev/null
+++ b/noncore/games/snake/interface.h
@@ -0,0 +1,69 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qmainwindow.h>
21#include <qcanvas.h>
22#include <qlabel.h>
23
24#include "snake.h"
25#include "target.h"
26#include "obstacle.h"
27
28// class QCanvas;
29
30class SnakeGame : public QMainWindow {
31 Q_OBJECT
32
33public:
34 SnakeGame(QWidget* parent=0, const char* name=0, WFlags f=0);
35 ~SnakeGame();
36
37 void clear();
38 void createTargets();
39 void welcomescreen();
40
41protected:
42 virtual void keyPressEvent(QKeyEvent*);
43 virtual void resizeEvent(QResizeEvent *e);
44
45signals:
46 void moveFaster();
47
48private slots:
49 void newGame();
50 void gameOver();
51 void wait();
52 void levelUp();
53 void scoreInc();
54
55private:
56 void showScore(int);
57 QCanvasView* cv;
58 QLabel* scorelabel;
59 QCanvas canvas;
60 QTimer* pauseTimer;
61 Snake* snake;
62 int last;
63 int level;
64 int stage;
65 int targetamount;
66 int notargets;
67 bool waitover;
68 bool gamestopped;
69};
diff --git a/noncore/games/snake/main.cpp b/noncore/games/snake/main.cpp
new file mode 100644
index 0000000..90a93b7
--- a/dev/null
+++ b/noncore/games/snake/main.cpp
@@ -0,0 +1,35 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "interface.h"
22
23#include <qpe/qpeapplication.h>
24
25
26int main(int argc, char **argv)
27{
28 QPEApplication app(argc,argv);
29
30 SnakeGame* m = new SnakeGame;
31 QPEApplication::setInputMethodHint( m, QPEApplication::AlwaysOff );
32 app.showMainWidget(m);
33
34 return app.exec();
35}
diff --git a/noncore/games/snake/obstacle.cpp b/noncore/games/snake/obstacle.cpp
new file mode 100644
index 0000000..2d07fe7
--- a/dev/null
+++ b/noncore/games/snake/obstacle.cpp
@@ -0,0 +1,51 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "obstacle.h"
22#include "codes.h"
23
24#include <qpe/resource.h>
25
26Obstacle::Obstacle(QCanvas* canvas, int x, int y)
27 : QCanvasSprite(0, canvas)
28{
29 newObstacle(x, y);
30}
31
32void Obstacle::newObstacle(int x, int y)
33{
34 QCanvasPixmapArray* obstaclearray = new QCanvasPixmapArray(Resource::findPixmap("snake/wall.png"));
35
36 setSequence(obstaclearray);
37
38 move(x, y);
39
40 show();
41 canvas()->update();
42}
43
44int Obstacle::rtti() const
45{
46 return obstacle_rtti;
47}
48
49Obstacle::~Obstacle()
50{
51}
diff --git a/noncore/games/snake/obstacle.h b/noncore/games/snake/obstacle.h
new file mode 100644
index 0000000..838917f
--- a/dev/null
+++ b/noncore/games/snake/obstacle.h
@@ -0,0 +1,30 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qcanvas.h>
21
22class Obstacle : public QCanvasSprite
23{
24
25public:
26 Obstacle(QCanvas*, int x, int y);
27 ~Obstacle();
28 void newObstacle(int x, int y);
29 int rtti() const;
30};
diff --git a/noncore/games/snake/qpe-snake.control b/noncore/games/snake/qpe-snake.control
new file mode 100644
index 0000000..489e642
--- a/dev/null
+++ b/noncore/games/snake/qpe-snake.control
@@ -0,0 +1,9 @@
1Files: bin/snake apps/Games/snake.desktop pics/snake
2Priority: optional
3Section: qpe/games
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Game: control the snake
9 A game for the Qtopia environment.
diff --git a/noncore/games/snake/snake.cpp b/noncore/games/snake/snake.cpp
new file mode 100644
index 0000000..9f19841
--- a/dev/null
+++ b/noncore/games/snake/snake.cpp
@@ -0,0 +1,246 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "snake.h"
22#include "target.h"
23#include "codes.h"
24
25#include <qpe/resource.h>
26
27#include <qregexp.h>
28
29static int Piecekey[4][4] = { {6, 0, 4, 3 }, {0, 6, 2, 1 }, { 1, 3, 5, 0 }, {2, 4, 0, 5 } };
30
31Snake::Snake(QCanvas* c)
32{
33 canvas = c;
34 score = 0;
35 snakelist.setAutoDelete(true);
36 autoMoveTimer = new QTimer(this);
37 connect( autoMoveTimer, SIGNAL(timeout()), this, SLOT(moveSnake()) );
38 createSnake();
39}
40
41void Snake::createSnake()
42{
43 snakeparts = new QCanvasPixmapArray();
44 QString s0 = Resource::findPixmap("snake/s0001");
45 s0.replace(QRegExp("0001"),"%1");
46 snakeparts->readPixmaps(s0, 15);
47
48 grow = 0;
49 last = Key_Right;
50
51 QCanvasSprite* head = new QCanvasSprite(snakeparts, canvas );
52 head->setFrame(7);
53 snakelist.insert(0, head);
54 head->show();
55 head->move(34, 16);
56
57 QCanvasSprite* body = new QCanvasSprite(snakeparts, canvas );
58 body->setFrame(6);
59 snakelist.append( body );
60 body->show();
61 body->move(18, 16);
62
63 QCanvasSprite* end = new QCanvasSprite(snakeparts, canvas );
64 end->setFrame(11);
65 snakelist.append( end );
66 end->show();
67 end->move(2, 16);
68
69 currentdir = right;
70 speed = 250;
71 autoMoveTimer->start(speed);
72 moveSnake();
73}
74
75void Snake::increaseSpeed()
76{
77 if (speed > 150)
78 speed = speed - 5;
79 autoMoveTimer->start(speed);
80}
81
82void Snake::go(int newkey)
83{
84 // check key is a direction
85 if (!( (newkey == Key_Up) || (newkey == Key_Left) ||
86 (newkey == Key_Right) || (newkey == Key_Down) ))
87 return;
88 // check move is possible
89 if ( ((currentdir == left) && ((newkey == Key_Right) || (newkey == Key_Left)) ) ||
90 ((currentdir == right) && ((newkey == Key_Left) || (newkey == Key_Right)) ) ||
91 ((currentdir == up) && ((newkey == Key_Down) || (newkey == Key_Up)) ) ||
92 ((currentdir == down) && ((newkey == Key_Up) || (newkey == Key_Down)) ) )
93 return;
94 else {
95 Snake::changeHead(newkey);
96 Snake::moveSnake();
97 }
98}
99
100void Snake::move(Direction dir)
101{
102 autoMoveTimer->start(speed);
103 int x = 0;
104 int y = 0;
105 newdir = dir;
106 switch (dir) {
107 case right: x = 16; break;
108 case left: x = -16; break;
109 case down: y = 16; break;
110 case up: y = -16; break;
111 }
112 int index = lookUpPiece(currentdir, newdir);
113 QCanvasSprite* sprite = new QCanvasSprite(snakeparts, canvas );
114 sprite->setFrame(index);
115 snakelist.insert(1, sprite);
116 sprite->move(snakelist.first()->x(), snakelist.first()->y() );
117
118 snakelist.first()->moveBy(x, y);
119 if (grow <= 0)
120 changeTail();
121 else
122 grow--;
123 sprite->show();
124
125 currentdir = dir;
126}
127
128void Snake::changeTail()
129{
130 snakelist.removeLast();
131
132 double lastx = snakelist.last()->x();
133 double prevx = snakelist.prev()->x();
134 int index = 0;
135
136 if ( prevx == lastx ) { //vertical
137 if ( snakelist.prev()->y() > snakelist.last()->y() )
138 index = 13;
139 else
140 index = 14;
141 } else { //horizontal
142 if (snakelist.prev()->x() > snakelist.last()->x() )
143 index = 11;
144 else
145 index = 12;
146 }
147
148 snakelist.last()->setFrame(index);
149}
150
151void Snake::changeHead(int lastkey)
152{
153 int index = 0;
154 last = lastkey;
155
156 switch (last)
157 {
158 case Key_Up: index = 10; break;
159 case Key_Left: index = 8; break;
160 case Key_Right: index = 7; break;
161 case Key_Down: index = 9; break;
162 }
163
164 if (index) {
165 snakelist.first()->setFrame(index);
166 }
167}
168
169// returns an integer corresponding to a particular type of snake piece
170int Snake::lookUpPiece(Direction currentdir, Direction newdir)
171{
172 return Piecekey[currentdir][newdir];
173}
174
175void Snake::extendSnake()
176{
177 grow++;
178}
179
180void Snake::moveSnake()
181{
182 switch (last)
183 {
184 case Key_Up: move(up); break;
185 case Key_Left: move(left); break;
186 case Key_Right: move(right); break;
187 case Key_Down: move(down); break;
188 }
189 detectCrash();
190}
191
192void Snake::detectCrash()
193{
194 QCanvasSprite* head = snakelist.first();
195 QCanvasItem* item;
196 QCanvasItemList l=head->collisions(FALSE);
197 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
198 item = *it;
199 // check if snake hit target
200 if ( (item->rtti()== 1500 ) && (item->collidesWith(head)) ) {
201 Target* target = (Target*) item;
202 target->done();
203 emit targethit();
204 extendSnake();
205 setScore(5);
206 return;
207 }
208 // check if snake hit obstacles
209 if ( (item->rtti()==1600) && (item->collidesWith(head)) ) {
210 emit dead();
211 autoMoveTimer->stop();
212 return;
213 }
214 }
215 //check if snake hit itself
216 for (uint i = 3; i < snakelist.count(); i++) {
217 if (head->collidesWith(snakelist.at(i)) ) {
218 emit dead();
219 autoMoveTimer->stop();
220 return;
221 }
222 }
223 //check if snake hit edge
224 if ( (head->x() > canvas->width()-5) || (head->y() > canvas->height()-10)
225 || (head->x() <2) || (head->y() <-5) ) {
226 emit dead();
227 autoMoveTimer->stop();
228 return;
229 }
230}
231
232void Snake::setScore(int amount)
233{
234 score = score + amount;
235 emit scorechanged();
236}
237
238int Snake::getScore()
239{
240 return score;
241}
242
243Snake::~Snake()
244{
245 autoMoveTimer->stop();
246}
diff --git a/noncore/games/snake/snake.h b/noncore/games/snake/snake.h
new file mode 100644
index 0000000..5725343
--- a/dev/null
+++ b/noncore/games/snake/snake.h
@@ -0,0 +1,64 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qcanvas.h>
21#include <qtimer.h>
22
23class Snake : public QObject
24{
25 Q_OBJECT
26
27public:
28 enum Direction{ left, right, up, down};
29
30 Snake(QCanvas*);
31 ~Snake();
32 void go(int newkey);
33 void move(Direction dir);
34 void changeHead(int last);
35 void changeTail();
36 void detectCrash();
37 void createSnake();
38 void extendSnake();
39 int lookUpPiece(Direction currentdir, Direction newdir);
40 void setScore(int amount);
41 int getScore();
42
43signals:
44 void dead();
45 void targethit();
46 void scorechanged();
47
48private slots:
49 void moveSnake();
50 void increaseSpeed();
51
52private:
53 QCanvasPixmapArray* snakeparts;
54 QList<QCanvasSprite>snakelist;
55 QTimer* autoMoveTimer;
56 QCanvas* canvas;
57 int grow;
58 int last;
59 int speed;
60 int score;
61 Direction currentdir;
62 Direction newdir;
63};
64
diff --git a/noncore/games/snake/snake.pro b/noncore/games/snake/snake.pro
new file mode 100644
index 0000000..6dacdbd
--- a/dev/null
+++ b/noncore/games/snake/snake.pro
@@ -0,0 +1,11 @@
1 TEMPLATE= app
2 CONFIG += qt warn_on release
3 DESTDIR = $(QPEDIR)/bin
4 HEADERS = snake.h target.h obstacle.h interface.h codes.h
5 SOURCES = snake.cpp target.cpp obstacle.cpp interface.cpp main.cpp
6 TARGET = snake
7INCLUDEPATH += $(QPEDIR)/include
8 DEPENDPATH+= $(QPEDIR)/include
9LIBS += -lqpe
10
11TRANSLATIONS = ../i18n/de/snake.ts
diff --git a/noncore/games/snake/target.cpp b/noncore/games/snake/target.cpp
new file mode 100644
index 0000000..a09af69
--- a/dev/null
+++ b/noncore/games/snake/target.cpp
@@ -0,0 +1,77 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "target.h"
22#include "codes.h"
23
24#include <qpe/resource.h>
25
26#include <stdlib.h>
27
28Target::Target(QCanvas* canvas)
29 : QCanvasSprite(0, canvas)
30{
31 mouse = new QCanvasPixmapArray(Resource::findPixmap("snake/mouse"));
32 setSequence(mouse);
33 newTarget();
34}
35
36void Target::newTarget()
37{
38 static bool first_time = TRUE;
39 if (first_time) {
40 first_time = FALSE;
41 QTime midnight(0, 0, 0);
42 srand(midnight.secsTo(QTime::currentTime()) );
43 }
44 do {
45 int x = rand() % (canvas()->width()-10);
46 x = x - (x % 16) + 2;
47 int y = rand() % (canvas()->height()-10);
48 y = y - (y % 16) + 2;
49 move(x, y);
50 } while (onTop());
51 show();
52}
53
54bool Target::onTop()
55{
56 QCanvasItem* item;
57 QCanvasItemList l= canvas()->allItems(); //collisions(FALSE);
58 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
59 item = *it;
60 if (item != this && item->collidesWith(this)) return true;
61 }
62 return false;
63}
64
65void Target::done()
66{
67 delete this;
68}
69
70int Target::rtti() const
71{
72 return target_rtti;
73}
74
75Target::~Target()
76{
77}
diff --git a/noncore/games/snake/target.h b/noncore/games/snake/target.h
new file mode 100644
index 0000000..a6da37c
--- a/dev/null
+++ b/noncore/games/snake/target.h
@@ -0,0 +1,37 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qcanvas.h>
21#include <qdatetime.h>
22
23class Target : public QCanvasSprite
24{
25
26public:
27 Target(QCanvas*);
28 ~Target();
29 void newTarget();
30 void done();
31 void createMouse();
32 bool onTop();
33 int rtti() const;
34
35private:
36 QCanvasPixmapArray* mouse;
37};
diff --git a/noncore/games/solitaire/.cvsignore b/noncore/games/solitaire/.cvsignore
new file mode 100644
index 0000000..edfa921
--- a/dev/null
+++ b/noncore/games/solitaire/.cvsignore
@@ -0,0 +1,3 @@
1moc_*
2*.moc
3Makefile
diff --git a/noncore/games/solitaire/Makefile.in b/noncore/games/solitaire/Makefile.in
new file mode 100644
index 0000000..3c50345
--- a/dev/null
+++ b/noncore/games/solitaire/Makefile.in
@@ -0,0 +1,235 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= patience
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =canvascard.h \
27 canvasshapes.h \
28 cardgame.h \
29 cardgamelayout.h \
30 cardpile.h \
31 card.h \
32 carddeck.h \
33 canvascardgame.h \
34 freecellcardgame.h \
35 patiencecardgame.h \
36 canvascardwindow.h
37 SOURCES =canvascard.cpp \
38 canvasshapes.cpp \
39 cardgame.cpp \
40 cardgamelayout.cpp \
41 cardpile.cpp \
42 card.cpp \
43 carddeck.cpp \
44 canvascardgame.cpp \
45 freecellcardgame.cpp \
46 patiencecardgame.cpp \
47 canvascardwindow.cpp \
48 main.cpp
49 OBJECTS =canvascard.o \
50 canvasshapes.o \
51 cardgame.o \
52 cardgamelayout.o \
53 cardpile.o \
54 card.o \
55 carddeck.o \
56 canvascardgame.o \
57 freecellcardgame.o \
58 patiencecardgame.o \
59 canvascardwindow.o \
60 main.o
61INTERFACES =
62UICDECLS =
63UICIMPLS =
64 SRCMOC =moc_canvascardwindow.cpp
65 OBJMOC =moc_canvascardwindow.o
66
67
68####### Implicit rules
69
70.SUFFIXES: .cpp .cxx .cc .C .c
71
72.cpp.o:
73 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
74
75.cxx.o:
76 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
77
78.cc.o:
79 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
80
81.C.o:
82 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
83
84.c.o:
85 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
86
87####### Build rules
88
89
90all: $(DESTDIR)$(TARGET)
91
92$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
93 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
94
95moc: $(SRCMOC)
96
97tmake:
98 tmake solitaire.pro
99
100clean:
101 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
102 -rm -f *~ core
103 -rm -f allmoc.cpp
104
105####### Extension Modules
106
107listpromodules:
108 @echo
109
110listallmodules:
111 @echo
112
113listaddonpromodules:
114 @echo
115
116listaddonentmodules:
117 @echo
118
119
120REQUIRES=patience
121
122####### Sub-libraries
123
124
125###### Combined headers
126
127
128
129####### Compile
130
131canvascard.o: canvascard.cpp \
132 cardgame.h \
133 card.h \
134 cardpile.h \
135 carddeck.h \
136 cardgamelayout.h \
137 canvascard.h \
138 $(QPEDIR)/include/qpe/resource.h
139
140canvasshapes.o: canvasshapes.cpp \
141 canvasshapes.h
142
143cardgame.o: cardgame.cpp \
144 cardgame.h \
145 card.h \
146 cardpile.h \
147 carddeck.h \
148 cardgamelayout.h
149
150cardgamelayout.o: cardgamelayout.cpp \
151 cardgamelayout.h \
152 cardpile.h
153
154cardpile.o: cardpile.cpp \
155 cardpile.h \
156 card.h \
157 $(QPEDIR)/include/qpe/config.h
158
159card.o: card.cpp \
160 card.h \
161 $(QPEDIR)/include/qpe/config.h
162
163carddeck.o: carddeck.cpp \
164 card.h \
165 carddeck.h
166
167canvascardgame.o: canvascardgame.cpp \
168 cardgame.h \
169 card.h \
170 cardpile.h \
171 carddeck.h \
172 cardgamelayout.h \
173 canvasshapes.h \
174 canvascard.h \
175 canvascardgame.h \
176 $(QPEDIR)/include/qpe/resource.h \
177 $(QPEDIR)/include/qpe/config.h \
178 $(QPEDIR)/include/qpe/qpemenubar.h
179
180freecellcardgame.o: freecellcardgame.cpp \
181 freecellcardgame.h \
182 patiencecardgame.h \
183 canvascardgame.h \
184 cardgame.h \
185 card.h \
186 cardpile.h \
187 carddeck.h \
188 cardgamelayout.h \
189 canvasshapes.h \
190 canvascard.h \
191 $(QPEDIR)/include/qpe/resource.h \
192 $(QPEDIR)/include/qpe/config.h \
193 $(QPEDIR)/include/qpe/qpemenubar.h
194
195patiencecardgame.o: patiencecardgame.cpp \
196 patiencecardgame.h \
197 canvascardgame.h \
198 cardgame.h \
199 card.h \
200 cardpile.h \
201 carddeck.h \
202 cardgamelayout.h \
203 canvasshapes.h \
204 canvascard.h \
205 $(QPEDIR)/include/qpe/resource.h \
206 $(QPEDIR)/include/qpe/config.h \
207 $(QPEDIR)/include/qpe/qpemenubar.h
208
209canvascardwindow.o: canvascardwindow.cpp \
210 canvascardwindow.h \
211 patiencecardgame.h \
212 canvascardgame.h \
213 cardgame.h \
214 card.h \
215 cardpile.h \
216 carddeck.h \
217 cardgamelayout.h \
218 canvasshapes.h \
219 canvascard.h \
220 $(QPEDIR)/include/qpe/resource.h \
221 $(QPEDIR)/include/qpe/config.h \
222 $(QPEDIR)/include/qpe/qpemenubar.h \
223 freecellcardgame.h
224
225main.o: main.cpp \
226 canvascardwindow.h \
227 $(QPEDIR)/include/qpe/qpeapplication.h
228
229moc_canvascardwindow.o: moc_canvascardwindow.cpp \
230 canvascardwindow.h
231
232moc_canvascardwindow.cpp: canvascardwindow.h
233 $(MOC) canvascardwindow.h -o moc_canvascardwindow.cpp
234
235
diff --git a/noncore/games/solitaire/canvascard.cpp b/noncore/games/solitaire/canvascard.cpp
new file mode 100644
index 0000000..ae3c859
--- a/dev/null
+++ b/noncore/games/solitaire/canvascard.cpp
@@ -0,0 +1,282 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "cardgame.h"
22#include "canvascard.h"
23
24#include <qpe/resource.h>
25
26#include <qpainter.h>
27#include <qimage.h>
28#include <qpaintdevice.h>
29#include <qbitmap.h>
30
31#include <math.h>
32
33#if defined( QT_QWS_CASSIOPEIA )
34#define SLOW_HARDWARE
35#endif
36
37// Seems to be fast enough to me even without Transformations in the library
38//#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ )
39//#define SLOW_HARDWARE
40//#endif
41
42
43QBitmap *Create180RotatedBitmap(QBitmap *srcBitmap)
44{
45#ifdef QT_NO_TRANSFORMATIONS
46 int w = srcBitmap->width();
47 int h = srcBitmap->height();
48 QBitmap *dstBitmap = new QBitmap( w, h );
49 // ### this is very poorly implemented and probably could be much faster
50 for (int i = 0; i < w; i++)
51 for (int j = 0; j < h; j++)
52 bitBlt( dstBitmap, i, j, srcBitmap, w - i - 1, h - j - 1, 1, 1 );
53 return dstBitmap;
54#else
55 QWMatrix m;
56 m.rotate( 180.0 );
57 return new QBitmap( srcBitmap->xForm( m ) );
58#endif
59}
60
61
62QPixmap *CreateScaledPixmap(QPixmap *srcPixmap, double scaleX, double scaleY)
63{
64#ifdef QT_NO_TRANSFORMATIONS
65 int w = srcPixmap->width();
66 int h = srcPixmap->height();
67 int newW = (int)(w * scaleX);
68 int newH = (int)(h * scaleY);
69 QPixmap *dstPixmap = new QPixmap( newW, newH );
70 // ### this is very poorly implemented and probably could be much faster
71 for (int i = 0; i < newW; i++) {
72 int srcX = w * i / newW;
73 if (newH == h) {
74 // Optimise for scaleing in the X-axis only
75 bitBlt( dstPixmap, i, 0, srcPixmap, srcX, 0, 1, h );
76 } else {
77 for (int j = 0; j < newH; j++) {
78 int srcY = h * j / newH;
79 bitBlt( dstPixmap, i, j, srcPixmap, srcX, srcY, 1, 1 );
80 }
81 }
82 }
83 return dstPixmap;
84#else
85 QWMatrix s;
86 s.scale( scaleX, scaleY );
87 return new QPixmap( srcPixmap->xForm( s ) );
88#endif
89}
90
91
92// Initialise static member variables to NULL
93QPixmap *CanvasCard::cardsFaces = NULL;
94QPixmap *CanvasCard::cardsBacks = NULL;
95QBitmap *CanvasCard::cardsChars = NULL;
96QBitmap *CanvasCard::cardsSuits = NULL;
97QBitmap *CanvasCard::cardsCharsUpsideDown = NULL;
98QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL;
99
100
101CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) :
102 Card(v, s, f), QCanvasRectangle( 0, 0, 1, 1, canvas ), cardBack(1), scaleX(1.0), scaleY(1.0)
103{
104 if ( !cardsFaces ) {
105 cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) );
106 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) );
107 cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) );
108 cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) );
109 cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars );
110 cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits );
111 }
112 xOff = cardsFaces->width() / 2;
113 yOff = cardsFaces->height() / 2;
114 setSize( cardsFaces->width(), cardsFaces->height() );
115 setPen( NoPen );
116 flipping = FALSE;
117}
118
119
120void CanvasCard::setCardBack(int b)
121{
122 if ( cardBack != b ) {
123
124 cardBack = b;
125
126 if ( cardsBacks )
127 delete cardsBacks;
128
129 switch (cardBack) {
130 case 0:
131 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break;
132 case 1:
133 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break;
134 case 2:
135 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break;
136 case 3:
137 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break;
138 case 4:
139 cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break;
140 }
141
142 if ( !isFacing() )
143 redraw();
144 }
145}
146
147
148void CanvasCard::draw(QPainter &painter)
149{
150 int ix = (int)x(), iy = (int)y();
151
152 QPainter *p = &painter;
153 QPixmap *unscaledCard = NULL;
154
155 if ((scaleX <= 0.98) || (scaleY <= 0.98))
156 {
157 p = new QPainter();
158 unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() );
159 p->begin(unscaledCard);
160 ix = 0;
161 iy = 0;
162 }
163
164 if ( isFacing() ) {
165
166/*
167 // Now add the joker and card backs to the list of pixmaps
168 QPixmap *CardsBack = new QPixmap( Resource::loadPixmap( "cards/card_joker.png" ) );
169 QPoint *newBackHotspot = new QPoint( 0, 0 );
170 pixmaps->append((const QPixmap *)CardsBack);
171 hotspots->append((const QPoint *)newBackHotspot);
172*/
173
174 int w = cardsFaces->width(), h = cardsFaces->height();
175
176 //p->setBrush( NoBrush );
177 p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) );
178
179 if ( isRed() == TRUE )
180 p->setPen( QColor( 0xFF, 0, 0 ) );
181 else
182 p->setPen( QColor( 0, 0, 0 ) );
183
184 p->drawPixmap( ix + 0, iy + 0, *cardsFaces );
185 p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 );
186 p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 );
187 p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 );
188 p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 );
189
190 } else {
191
192 p->drawPixmap( ix, iy, *cardsBacks );
193
194 }
195
196 if (p != &painter)
197 {
198 p->end();
199 QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY );
200 int xoff = scaledCard->width() / 2;
201 int yoff = scaledCard->height() / 2;
202 painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard );
203 delete p;
204 delete unscaledCard;
205 delete scaledCard;
206 }
207}
208
209
210static const double flipLift = 1.5;
211
212
213void CanvasCard::flipTo(int x2, int y2, int steps)
214{
215 flipSteps = steps;
216
217#ifdef SLOW_HARDWARE
218 move(x2,y2);
219 Card::flipTo(x2,y2,steps);
220#else
221 int x1 = (int)x();
222 int y1 = (int)y();
223 double dx = x2 - x1;
224 double dy = y2 - y1;
225
226 flipping = TRUE;
227 destX = x2;
228 destY = y2;
229 animSteps = flipSteps;
230 setVelocity(dx/animSteps, dy/animSteps-flipLift);
231 setAnimated(TRUE);
232#endif
233}
234
235
236void CanvasCard::advance(int stage)
237{
238 if ( stage==1 ) {
239 if ( animSteps-- <= 0 ) {
240 scaleX = 1.0;
241 scaleY = 1.0;
242 flipping = FALSE;
243 setVelocity(0,0);
244 setAnimated(FALSE);
245 move(destX,destY); // exact
246 } else {
247 if ( flipping ) {
248 if ( animSteps > flipSteps / 2 ) {
249 // animSteps = flipSteps .. flipSteps/2 (flip up) -> 1..0
250 scaleX = ((double)animSteps/flipSteps-0.5)*2;
251 } else {
252 // animSteps = flipSteps/2 .. 0 (flip down) -> 0..1
253 scaleX = 1-((double)animSteps/flipSteps)*2;
254 }
255 if ( animSteps == flipSteps / 2-1 ) {
256 setYVelocity(yVelocity()+flipLift*2);
257 setFace( !isFacing() );
258 }
259 }
260 }
261 }
262 QCanvasRectangle::advance(stage);
263}
264
265
266void CanvasCard::animatedMove(int x2, int y2, int steps)
267{
268 destX = x2;
269 destY = y2;
270
271 double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1;
272
273 // Ensure a good speed
274 while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 )
275 steps--;
276
277 setAnimated(TRUE);
278 setVelocity(dx/steps, dy/steps);
279
280 animSteps = steps;
281}
282
diff --git a/noncore/games/solitaire/canvascard.h b/noncore/games/solitaire/canvascard.h
new file mode 100644
index 0000000..cd9691f
--- a/dev/null
+++ b/noncore/games/solitaire/canvascard.h
@@ -0,0 +1,82 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CANVAS_CARD_H
21#define CANVAS_CARD_H
22
23
24#include <qpainter.h>
25#include <qbitmap.h>
26#include <qpixmap.h>
27#include <qpoint.h>
28#include <qcanvas.h>
29#include "cardgame.h"
30
31
32// ### Just made the number up, is that what you do???
33static const int canvasCardId = 2434321;
34
35
36class CanvasCard : public Card, public QCanvasRectangle
37{
38public:
39 CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas );
40 virtual ~CanvasCard() { canvas()->removeItem(this); }
41
42 int rtti () const { return canvasCardId; }
43 void move(QPoint p) { QCanvasItem::move( p.x(), p.y() ); }
44 void move(int x, int y) { QCanvasItem::move( x, y ); }
45 void animatedMove(int x, int y, int steps = 10);
46 void animatedMove() { animatedMove(savedX, savedY); }
47 void savePos(void) { savedX = (int)x(); savedY = (int)y(); }
48 void moveToPile(int p) { Q_UNUSED(p); }
49 void setCardBack(int b);
50
51 /*virtual*/ void flipTo(int x, int y, int steps = 8);
52 /*virtual*/ void setPos( int x, int y, int z ) { setX( x ); setY( y ); setZ( z ); }
53 /*virtual*/ void showCard(void) { show(); }
54 /*virtual*/ void redraw(void) { hide(); show(); }
55 /*virtual*/ void draw(QPainter &p);
56
57 void advance(int stage);
58
59protected:
60 /*virtual*/ void flip(void) { redraw(); }
61
62private:
63 int destX, destY;
64 int animSteps;
65 int flipSteps;
66 bool flipping;
67 int savedX, savedY;
68 int cardBack;
69 int oldCardBack;
70 double scaleX, scaleY;
71 int xOff, yOff;
72 static QPixmap *cardsFaces;
73 static QPixmap *cardsBacks;
74 static QBitmap *cardsChars;
75 static QBitmap *cardsSuits;
76 static QBitmap *cardsCharsUpsideDown;
77 static QBitmap *cardsSuitsUpsideDown;
78};
79
80
81#endif
82
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp
new file mode 100644
index 0000000..32635a0
--- a/dev/null
+++ b/noncore/games/solitaire/canvascardgame.cpp
@@ -0,0 +1,380 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "cardgame.h"
22#include "canvasshapes.h"
23#include "canvascard.h"
24#include "canvascardgame.h"
25
26#include <qpe/resource.h>
27#include <qpe/config.h>
28
29#include <qmainwindow.h>
30#include <qpe/qpemenubar.h>
31#include <qpainter.h>
32
33#include <stdlib.h>
34#include <limits.h>
35#include <time.h>
36#include <math.h>
37
38
39extern int highestZ;
40
41
42class CanvasCardPile : public QCanvasRectangle
43{
44public:
45 CanvasCardPile( CanvasCardGame *ccg, QCanvas *canvas ) : QCanvasRectangle( canvas ), parent( ccg ) {
46 pile = new QPixmap( 0, 0 );
47 pileHeight = 0;
48 firstCard = NULL;
49 }
50
51 void addCard( CanvasCard *card );
52 void advance(int stage);
53 void animatedMove() { animatedMove(savedX, savedY); }
54 void savePos(void) { savedX = (int)x(); savedY = (int)y(); }
55 void animatedMove(int x2, int y2, int steps = 7 );
56
57protected:
58 virtual void draw( QPainter& p );
59
60private:
61 CanvasCardGame *parent;
62 QPixmap *pile;
63 QImage tempImage32;
64 CanvasCard *firstCard;
65 int pileHeight;
66 int destX, destY;
67 int savedX, savedY;
68 int animSteps;
69};
70
71
72void CanvasCardPile::addCard( CanvasCard *card )
73{
74 if ( !firstCard )
75 firstCard = card;
76
77 int height = 36 + pileHeight * 13;
78 setSize( 23, height );
79 pile->resize( 23, height );
80 QPainter p( pile );
81 p.translate( -card->x(), -card->y() + pileHeight * 13 );
82 card->draw( p );
83 pileHeight++;
84
85 QImage tempImage;
86 tempImage = *pile;
87 tempImage32 = tempImage.convertDepth( 32 );
88 tempImage32.setAlphaBuffer( TRUE );
89 for ( int i = 0; i < tempImage32.width(); i++ )
90 for ( int j = 0; j < tempImage32.height(); j++ ) {
91 QRgb col = tempImage32.pixel( i, j );
92 int a = 255-j*220/tempImage32.height();
93 QRgb alpha = qRgba( qRed( col ), qGreen( col ), qBlue( col ), a );
94 tempImage32.setPixel( i, j, alpha );
95 }
96
97 QRgb alpha = qRgba( 0, 0, 0, 0 );
98 tempImage32.setPixel( 1, 0, alpha );
99 tempImage32.setPixel( 0, 0, alpha );
100 tempImage32.setPixel( 0, 1, alpha );
101
102 tempImage32.setPixel( 21, 0, alpha );
103 tempImage32.setPixel( 22, 0, alpha );
104 tempImage32.setPixel( 22, 1, alpha );
105 height--;
106 tempImage32.setPixel( 1, height, alpha );
107 tempImage32.setPixel( 0, height - 1, alpha );
108 tempImage32.setPixel( 0, height, alpha );
109
110 tempImage32.setPixel( 21, height, alpha );
111 tempImage32.setPixel( 22, height, alpha );
112 tempImage32.setPixel( 22, height - 1, alpha );
113}
114
115
116void CanvasCardPile::advance(int stage)
117{
118 if ( stage==1 ) {
119 if ( animSteps-- <= 0 ) {
120 CanvasCard *item = firstCard;
121 while (item) {
122 item->show();
123 item = (CanvasCard *)item->getCardPile()->cardInfront(item);
124 }
125 setVelocity(0,0);
126 setAnimated(FALSE);
127 parent->cancelMoving();
128 hide();
129 move(destX,destY); // exact
130 }
131 }
132 QCanvasRectangle::advance(stage);
133}
134
135
136void CanvasCardPile::animatedMove(int x2, int y2, int steps = 7 )
137{
138 destX = x2;
139 destY = y2;
140
141 double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1;
142
143 // Ensure a good speed
144 while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 )
145 steps--;
146
147 setAnimated(TRUE);
148 setVelocity(dx/steps, dy/steps);
149
150 animSteps = steps;
151}
152
153
154void CanvasCardPile::draw( QPainter& p )
155{
156 int ix = (int)x(), iy = (int)y();
157 p.drawImage( ix, iy, tempImage32 );
158}
159
160
161CanvasCardGame::~CanvasCardGame() {
162 // the deletion stuff should be fixed now and only deletes
163 // items created by this CardGame. I haven't verified there are zero
164 // memory leaks yet
165 if ( alphaCardPile )
166 delete alphaCardPile;
167}
168
169
170void CanvasCardGame::gameWon() {
171
172 srand(time(NULL));
173
174 QCanvasItemList list = canvas()->allItems();
175 QCanvasItemList::Iterator it = list.begin();
176
177 for (; it != list.end(); ++it) {
178 if ( (*it)->rtti() == canvasCardId ) {
179 // disperse the cards everywhere
180 int x = 300 - rand() % 1000;
181 int y = 300 + rand() % 200;
182 ((CanvasCard *)*it)->animatedMove( x, y, 50 );
183 }
184 }
185}
186
187
188void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) {
189
190 if ( moving )
191 return;
192
193 QCanvasItemList l = canvas()->collisions( e->pos() );
194
195 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
196
197 if ( (*it)->rtti() == canvasCardId ) {
198
199 moving = (CanvasCard *)*it;
200
201 if ( moving->animated() )
202 return;
203
204 cardXOff = (int)(e->pos().x() - moving->x());
205 cardYOff = (int)(e->pos().y() - moving->y());
206
207 if ( !mousePressCard( moving, e->pos() ) ) {
208 CanvasCard *card = moving;
209
210 if ( alphaCardPile )
211 delete alphaCardPile;
212
213 alphaCardPile = new CanvasCardPile( this, canvas() );
214 alphaCardPile->move( card->x(), card->y() );
215 alphaCardPile->savePos();
216 alphaCardPile->show();
217
218 while (card) {
219 alphaCardPile->addCard( card );
220 card->hide();
221 card = (CanvasCard *)card->getCardPile()->cardInfront(card);
222 }
223
224 alphaCardPile->setZ( INT_MAX );
225
226 moved = TRUE;
227 } else {
228 if ( alphaCardPile )
229 alphaCardPile->hide();
230 }
231 return;
232 }
233 }
234
235 mousePress( e->pos() );
236}
237
238/*
239//
240// Should have some intelligent way to make double clicking on a
241// card send it to the most appropriate pile
242//
243void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) {
244 QCanvasItemList l = canvas()->collisions( e->pos() );
245 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
246 if ( (*it)->rtti() == canvasCardId ) {
247 CanvasCard *card = (CanvasCard *)*it;
248
249 if ( card->animated() )
250 return;
251
252 if ( card->getCardPile()->isAllowedToBeMoved(card) ) {
253 if (card->getCardPile()->cardInfront(card) == NULL) {
254 CardPile *pile = first();
255 if (pile && pile->isAllowedOnTop(card)) {
256 // move card to this pile
257 return;
258 }
259 }
260 }
261 }
262 }
263}
264*/
265
266void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) {
267
268 QPoint p = e->pos();
269
270 if ( moving ) {
271
272 moved = TRUE;
273
274 if (moving->isFacing() != TRUE)
275 return;
276
277 int tx = (int)p.x() - cardXOff;
278 int ty = (int)p.y() - cardYOff;
279
280 if (snapOn == TRUE) {
281 CardPile *pile = closestPile( tx, ty, 50 );
282 if ( pile && pile->isAllowedOnTop( moving ) ) {
283 QPoint p = pile->getHypertheticalNextCardPos();
284 if ( alphaCardPile )
285 alphaCardPile->move( p.x(), p.y() );
286 return;
287 }
288 }
289
290 if ( alphaCardPile )
291 alphaCardPile->move( tx, ty );
292 }
293
294}
295
296
297void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e)
298{
299 QPoint p = e->pos();
300
301 Q_UNUSED(p);
302
303 if ( moving ) {
304
305 CanvasCard *item = moving;
306
307 if ( item->animated() )
308 return;
309
310 if ( alphaCardPile )
311 if ( moved ) {
312
313 CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30);
314
315 if (pile && pile->isAllowedOnTop(item)) {
316 CardPile *oldPile = item->getCardPile();
317 Card *c = NULL;
318 if ( oldPile != pile) {
319 while ( item ) {
320 item->show();
321 if ( oldPile ) {
322 c = oldPile->cardInfront(item);
323 oldPile->removeCard(item);
324 }
325 pile->addCardToTop(item);
326 item->setCardPile(pile);
327 //item->move( pile->getCardPos(item) );
328 QPoint p = pile->getCardPos(item);
329 item->setPos( p.x(), p.y(), highestZ );
330 highestZ++;
331
332 if (item->getValue() == king && haveWeWon()) {
333 alphaCardPile->hide();
334 gameWon();
335 moving = NULL;
336 return;
337 }
338
339 if (oldPile) {
340 item = (CanvasCard *)c;
341 } else {
342 item = NULL;
343 }
344 }
345 alphaCardPile->hide();
346 moving = NULL;
347 return;
348 }
349 }
350
351 alphaCardPile->animatedMove();
352 }
353 }
354
355 moved = FALSE;
356}
357
358
359void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ )
360{
361 cfg.setGroup( name );
362 int numberOfCards = cfg.readNumEntry("NumberOfCards", 0);
363 Card *card = NULL;
364 for ( int i = 0; i < numberOfCards; i++ ) {
365 QString cardStr;
366 cardStr.sprintf( "%i", i );
367 int val = cfg.readNumEntry( "Card" + cardStr );
368 bool facing = cfg.readBoolEntry( "CardFacing" + cardStr );
369 card = cards[ val ];
370 card->setFace(facing);
371 pile->addCardToTop(card);
372 card->setCardPile(pile);
373 QPoint p = pile->getCardPos( card );
374 card->setPos( p.x(), p.y(), highestZ );
375 card->showCard();
376 highestZ++;
377 }
378}
379
380
diff --git a/noncore/games/solitaire/canvascardgame.h b/noncore/games/solitaire/canvascardgame.h
new file mode 100644
index 0000000..4d32014
--- a/dev/null
+++ b/noncore/games/solitaire/canvascardgame.h
@@ -0,0 +1,95 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CANVAS_CARD_GAME_H
21#define CANVAS_CARD_GAME_H
22
23#include "cardgame.h"
24#include "canvasshapes.h"
25#include "canvascard.h"
26
27#include <qpe/resource.h>
28#include <qpe/config.h>
29
30#include <qmainwindow.h>
31#include <qpe/qpemenubar.h>
32#include <qpainter.h>
33
34#include <stdlib.h>
35#include <time.h>
36
37
38class CanvasCardPile;
39
40
41class CanvasCardGame : public QCanvasView, public CardGame
42{
43public:
44 CanvasCardGame(QCanvas &c, bool snap, QWidget *parent = 0, const char *name = 0, WFlags f = 0) :
45 QCanvasView( &c, parent, name, f ),
46 moved(FALSE),
47 moving(NULL),
48 alphaCardPile( NULL ),
49 cardXOff(0), cardYOff(0),
50 snapOn(snap),
51 numberToDraw(1) { }
52
53 virtual ~CanvasCardGame();
54
55 virtual Card *newCard( eValue v, eSuit s, bool f ) {
56 return new CanvasCard( v, s, f, canvas() );
57 }
58
59 virtual void readConfig( Config& cfg ) { Q_UNUSED( cfg ); }
60 virtual void writeConfig( Config& cfg ) { Q_UNUSED( cfg ); }
61
62 virtual void gameWon();
63 virtual bool haveWeWon() { return FALSE; }
64
65 virtual bool mousePressCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); return FALSE; }
66 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
67
68 void cancelMoving() { moving = NULL; }
69 void toggleSnap() { snapOn = (snapOn == TRUE) ? FALSE : TRUE; }
70 void toggleCardsDrawn() { numberToDraw = (numberToDraw == 1) ? 3 : 1; }
71 int cardsDrawn() { return numberToDraw; }
72 void setNumberToDraw(int numToDraw) { this->numberToDraw = numToDraw; }
73
74 void readPile( Config& cfg, CardPile *pile, QString name, int& highestZ );
75
76protected:
77 void contentsMousePressEvent(QMouseEvent *e);
78 void contentsMouseReleaseEvent(QMouseEvent *e);
79 void contentsMouseMoveEvent(QMouseEvent *e);
80
81protected:
82 // Mouse event state variables
83 bool moved;
84 CanvasCard *moving;
85 CanvasCardPile *alphaCardPile;
86 int cardXOff, cardYOff;
87
88private:
89 bool snapOn;
90 int numberToDraw;
91};
92
93
94#endif
95
diff --git a/noncore/games/solitaire/canvascardwindow.cpp b/noncore/games/solitaire/canvascardwindow.cpp
new file mode 100644
index 0000000..4c365a5
--- a/dev/null
+++ b/noncore/games/solitaire/canvascardwindow.cpp
@@ -0,0 +1,227 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "canvascardwindow.h"
22#include "patiencecardgame.h"
23#include "freecellcardgame.h"
24
25#include <qpe/resource.h>
26
27#include <qmainwindow.h>
28#include <qpopupmenu.h>
29#include <qstyle.h>
30
31
32CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) :
33 QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0),
34 cardGame(NULL)
35{
36 setIcon( Resource::loadPixmap( "cards" ) );
37
38 // Create Playing Area for Games
39 if ( QPixmap::defaultDepth() < 12 ) {
40// canvas.setBackgroundColor(QColor(0x51, 0x74, 0x6B));
41 //canvas.setBackgroundColor(QColor(0x20, 0xb0, 0x50));
42 canvas.setBackgroundColor(QColor(0x08, 0x98, 0x2D));
43 } else {
44 QPixmap bg;
45 bg.convertFromImage( Resource::loadImage( "table_pattern" ), ThresholdDither );
46 canvas.setBackgroundPixmap(bg);
47 }
48
49#if defined( QT_QWS_CASSIOPEIA )
50 canvas.setAdvancePeriod(70);
51#else
52 canvas.setAdvancePeriod(30);
53#endif
54
55
56#ifdef _PATIENCE_USE_ACCELS_
57 QPEMenuBar* menu = menuBar();
58
59 QPopupMenu* file = new QPopupMenu;
60 file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F);
61 file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F);
62 menu->insertItem(tr("&Game"), file);
63
64 menu->insertSeparator();
65
66 settings = new QPopupMenu;
67 settings->insertItem(tr("&Change Card Backs"), this, SLOT(changeCardBacks()), Key_F2);
68 snap_id = settings->insertItem(tr("&Snap To Position"), this, SLOT(snapToggle()), Key_F3);
69 settings->setCheckable(TRUE);
70 menu->insertItem(tr("&Settings"),settings);
71
72 menu->insertSeparator();
73
74 QPopupMenu* help = new QPopupMenu;
75 help->insertItem(tr("&About"), this, SLOT(help()), Key_F1);
76 help->setItemChecked(dbf_id, TRUE);
77 menu->insertItem(tr("&Help"),help);
78#else
79 QMenuBar* menu = menuBar();
80
81 QPopupMenu* file = new QPopupMenu;
82 file->insertItem(tr("Patience"), this, SLOT(initPatience()));
83 file->insertItem(tr("Freecell"), this, SLOT(initFreecell()));
84 menu->insertItem(tr("Play"), file);
85
86 menu->insertSeparator();
87
88 settings = new QPopupMenu;
89 settings->setCheckable(TRUE);
90 settings->insertItem(tr("Change Card Backs"), this, SLOT(changeCardBacks()));
91 snap_id = settings->insertItem(tr("Snap To Position"), this, SLOT(snapToggle()));
92 QString m;
93
94 drawId = settings->insertItem(tr("Turn One Card"), this, SLOT(drawnToggle()));
95 menu->insertItem(tr("Settings"),settings);
96
97#endif
98
99 menu->show();
100
101 Config cfg( "Patience" );
102 cfg.setGroup( "GlobalSettings" );
103 snapOn = cfg.readBoolEntry( "SnapOn", TRUE);
104 settings->setItemChecked(snap_id, snapOn);
105 gameType = cfg.readNumEntry( "GameType", -1 );
106 drawThree = cfg.readBoolEntry( "DrawThree", TRUE);
107 if ( gameType == 0 ) {
108 cardGame = new PatienceCardGame( &canvas, snapOn, this );
109 cardGame->setNumberToDraw(drawThree ? 3 : 1);
110 setCaption(tr("Patience"));
111 setCentralWidget(cardGame);
112 cardGame->readConfig( cfg );
113 setCardBacks();
114 } else if ( gameType == 1 ) {
115 cardGame = new FreecellCardGame( &canvas, snapOn, this );
116 setCaption(tr("Freecell"));
117 setCentralWidget(cardGame);
118 //cardGame->newGame(); // Until we know how to handle reading freecell config
119 cardGame->readConfig( cfg );
120 setCardBacks();
121 } else {
122 // Probably there isn't a config file or it is broken
123 // Start a new game
124 initPatience();
125 }
126
127 updateDraw();
128}
129
130
131CanvasCardWindow::~CanvasCardWindow()
132{
133 if (cardGame) {
134 Config cfg("Patience");
135 cfg.setGroup( "GlobalSettings" );
136 cfg.writeEntry( "GameType", gameType );
137 cfg.writeEntry( "SnapOn", snapOn );
138 cfg.writeEntry( "DrawThree", drawThree);
139 cardGame->writeConfig( cfg );
140 delete cardGame;
141 }
142}
143
144
145void CanvasCardWindow::resizeEvent(QResizeEvent *)
146{
147 QSize s = centralWidget()->size();
148 int fw = style().defaultFrameWidth();
149 canvas.resize( s.width() - fw - 2, s.height() - fw - 2);
150}
151
152
153void CanvasCardWindow::initPatience()
154{
155 // Create New Game
156 if ( cardGame )
157 delete cardGame;
158 cardGame = new PatienceCardGame( &canvas, snapOn, this );
159 cardGame->setNumberToDraw(drawThree ? 3 : 1);
160 gameType = 0;
161 setCaption(tr("Patience"));
162 setCentralWidget(cardGame);
163 cardGame->newGame();
164 setCardBacks();
165 updateDraw();
166}
167
168
169void CanvasCardWindow::initFreecell()
170{
171 // Create New Game
172 if ( cardGame ) {
173 delete cardGame;
174 }
175 cardGame = new FreecellCardGame( &canvas, snapOn, this );
176 gameType = 1;
177 setCaption(tr("Freecell"));
178 setCentralWidget(cardGame);
179 cardGame->newGame();
180 setCardBacks();
181}
182
183
184void CanvasCardWindow::snapToggle()
185{
186 snapOn = !snapOn;
187 settings->setItemChecked(snap_id, snapOn);
188 cardGame->toggleSnap();
189}
190
191
192void CanvasCardWindow::drawnToggle()
193{
194 cardGame->toggleCardsDrawn();
195 updateDraw();
196}
197
198void CanvasCardWindow::updateDraw() {
199 if(cardGame->cardsDrawn() == 3)
200 settings->changeItem(drawId, tr("Turn One Card"));
201 else
202 settings->changeItem(drawId, tr("Turn Three Cards"));
203}
204
205
206void CanvasCardWindow::setCardBacks()
207{
208 QCanvasItemList l = canvas.allItems();
209
210 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
211 if ( (*it)->rtti() == canvasCardId )
212 ((CanvasCard *)(*it))->setCardBack( cardBack );
213 }
214}
215
216
217void CanvasCardWindow::changeCardBacks()
218{
219 cardBack++;
220
221 if (cardBack == 5)
222 cardBack = 0;
223
224 setCardBacks();
225}
226
227
diff --git a/noncore/games/solitaire/canvascardwindow.h b/noncore/games/solitaire/canvascardwindow.h
new file mode 100644
index 0000000..b75d40a
--- a/dev/null
+++ b/noncore/games/solitaire/canvascardwindow.h
@@ -0,0 +1,70 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CANVAS_CARD_WINDOW_H
21#define CANVAS_CARD_WINDOW_H
22
23
24#include <qmainwindow.h>
25#include <qcanvas.h>
26
27
28class CanvasCardGame;
29class QPopupMenu;
30
31
32class CanvasCardWindow : public QMainWindow {
33 Q_OBJECT
34
35public:
36 CanvasCardWindow(QWidget* parent=0, const char* name=0, WFlags f=0);
37 virtual ~CanvasCardWindow();
38
39public slots:
40 void setCardBacks();
41 void changeCardBacks();
42 void snapToggle();
43 void drawnToggle();
44
45private slots:
46 void initFreecell();
47 void initPatience();
48
49protected:
50 virtual void resizeEvent(QResizeEvent *e);
51
52 void updateDraw();
53private:
54 QCanvas canvas;
55 bool snapOn;
56 bool drawThree;
57 int drawId;
58 int cardBack;
59 int gameType;
60 CanvasCardGame *cardGame;
61
62 QPopupMenu* options;
63 QPopupMenu* settings;
64 int dbf_id;
65 int snap_id;
66};
67
68
69#endif
70
diff --git a/noncore/games/solitaire/canvasshapes.cpp b/noncore/games/solitaire/canvasshapes.cpp
new file mode 100644
index 0000000..28d0b4e
--- a/dev/null
+++ b/noncore/games/solitaire/canvasshapes.cpp
@@ -0,0 +1,92 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qpainter.h>
21#include <qcanvas.h>
22#include "canvasshapes.h"
23
24
25CanvasRoundRect::CanvasRoundRect(int x, int y, QCanvas *canvas) :
26 QCanvasRectangle( x, y, 23, 36, canvas)
27{
28 setZ(0);
29 show();
30}
31
32
33void CanvasRoundRect::redraw()
34{
35 hide();
36 show();
37}
38
39
40void CanvasRoundRect::drawShape(QPainter &p)
41{
42 p.drawRoundRect( (int)x(), (int)y(), 23, 36);
43}
44
45
46CanvasCircleOrCross::CanvasCircleOrCross(int x, int y, QCanvas *canvas) :
47 QCanvasRectangle( x, y, 21, 21, canvas), circleShape(TRUE)
48{
49 show();
50}
51
52
53void CanvasCircleOrCross::redraw()
54{
55 hide();
56 show();
57}
58
59
60void CanvasCircleOrCross::setCircle()
61{
62 circleShape = TRUE;
63 redraw();
64}
65
66
67void CanvasCircleOrCross::setCross()
68{
69 circleShape = FALSE;
70 redraw();
71}
72
73
74void CanvasCircleOrCross::drawShape(QPainter &p)
75{
76 int x1 = (int)x(), y1 = (int)y();
77 // Green circle
78 if (circleShape == TRUE) {
79 p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) );
80 p.drawEllipse( x1 - 1, y1 - 1, 21, 21);
81 p.drawEllipse( x1 - 1, y1 - 0, 21, 19);
82 p.drawEllipse( x1 + 0, y1 + 0, 19, 19);
83 p.drawEllipse( x1 + 1, y1 + 0, 17, 19);
84 p.drawEllipse( x1 + 1, y1 + 1, 17, 17);
85 // Red cross
86 } else {
87 p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 5 ) );
88 p.drawLine( x1, y1, x1 + 20, y1 + 20);
89 p.drawLine( x1 + 20, y1, x1, y1 + 20);
90 }
91}
92
diff --git a/noncore/games/solitaire/canvasshapes.h b/noncore/games/solitaire/canvasshapes.h
new file mode 100644
index 0000000..72acf6b
--- a/dev/null
+++ b/noncore/games/solitaire/canvasshapes.h
@@ -0,0 +1,55 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CANVAS_SHAPES_H
21#define CANVAS_SHAPES_H
22
23
24#include <qcanvas.h>
25
26
27class QPainter;
28
29
30class CanvasRoundRect : QCanvasRectangle
31{
32public:
33 CanvasRoundRect(int x, int y, QCanvas *canvas);
34 void redraw();
35protected:
36 void drawShape(QPainter &p);
37};
38
39
40class CanvasCircleOrCross : QCanvasRectangle
41{
42public:
43 CanvasCircleOrCross(int x, int y, QCanvas *canvas);
44 void redraw();
45 void setCircle();
46 void setCross();
47protected:
48 void drawShape(QPainter &p);
49private:
50 bool circleShape;
51};
52
53
54#endif
55
diff --git a/noncore/games/solitaire/card.cpp b/noncore/games/solitaire/card.cpp
new file mode 100644
index 0000000..609e280
--- a/dev/null
+++ b/noncore/games/solitaire/card.cpp
@@ -0,0 +1,53 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "card.h"
22
23#include <qpe/config.h>
24
25#include <qpoint.h>
26#include <qlist.h>
27
28/*
29Card( eValue v, eSuit s, bool f ) :
30 val(v), suit(s), faceUp(f), showing(FALSE), ix(0), iy(0), iz(0), cardPile(NULL) { }
31virtual ~Card() { }
32eValue getValue() { return val; }
33eSuit getSuit() { return suit; }
34CardPile *getCardPile() { return cardPile; }
35bool isFacing() { return faceUp; }
36bool isShowing() { return showing; }
37bool isRed() { return ((suit == diamonds) || (suit == hearts)); }
38int getX(void) { return ix; }
39int getY(void) { return iy; }
40int getZ(void) { return iz; }
41void setCardPile(CardPile *p) { cardPile = p; }
42void setFace(bool f) { faceUp = f; }
43void flip(void) { flipTo(getX(), getY()); }
44virtual void setPos(int x, int y, int z) { ix = x; iy = y; iz = z; }
45virtual void move(int x, int y) { ix = x; iy = y; }
46virtual void move(QPoint p) { ix = p.x(); iy = p.y(); }
47virtual void flipTo(int x, int y, int steps = 8) { ix = x; iy = y; faceUp = !faceUp; redraw(); Q_UNUSED(steps); }
48virtual void showCard(void) { showing = TRUE; }
49virtual void hideCard(void) { showing = FALSE; }
50virtual void redraw(void) { }
51*/
52
53
diff --git a/noncore/games/solitaire/card.h b/noncore/games/solitaire/card.h
new file mode 100644
index 0000000..eb30d30
--- a/dev/null
+++ b/noncore/games/solitaire/card.h
@@ -0,0 +1,84 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CARD_H
21#define CARD_H
22
23
24#include <qpoint.h>
25
26
27class CardPile;
28
29
30enum eSuit {
31 jokerSuit = 0, clubs, spades, diamonds, hearts
32};
33
34
35enum eValue {
36 jokerVal = 0, ace, two, three, four, five,
37 six, seven, eight, nine, ten, jack, queen, king
38};
39
40
41class Card
42{
43public:
44 Card( eValue v, eSuit s, bool f ) :
45 val(v), suit(s), faceUp(f), showing(FALSE), ix(0), iy(0), iz(0), cardPile(NULL) { }
46 virtual ~Card() { }
47
48 eValue getValue() { return val; }
49 eSuit getSuit() { return suit; }
50
51 void setCardPile(CardPile *p) { cardPile = p; }
52 CardPile *getCardPile() { return cardPile; }
53
54 void setFace(bool f) { faceUp = f; /* flip(); */ }
55 bool isFacing() { return faceUp; }
56
57 bool isShowing() { return showing; }
58 bool isRed() { return ((suit == diamonds) || (suit == hearts)); }
59
60 int getX(void) { return ix; }
61 int getY(void) { return iy; }
62 int getZ(void) { return iz; }
63 void flip(void) { flipTo(getX(), getY()); }
64
65 virtual void setPos(int x, int y, int z) { ix = x; iy = y; iz = z; }
66 virtual void move(int x, int y) { ix = x; iy = y; }
67 virtual void move(QPoint p) { ix = p.x(); iy = p.y(); }
68 virtual void flipTo(int x, int y, int steps = 8) { ix = x; iy = y; faceUp = !faceUp; redraw(); Q_UNUSED(steps); }
69 virtual void showCard(void) { showing = TRUE; }
70 virtual void hideCard(void) { showing = FALSE; }
71protected:
72 virtual void redraw(void) { }
73private:
74 eValue val;
75 eSuit suit;
76 bool faceUp;
77 bool showing;
78 int ix, iy, iz;
79 CardPile *cardPile;
80};
81
82
83#endif
84
diff --git a/noncore/games/solitaire/carddeck.cpp b/noncore/games/solitaire/carddeck.cpp
new file mode 100644
index 0000000..87c043a
--- a/dev/null
+++ b/noncore/games/solitaire/carddeck.cpp
@@ -0,0 +1,81 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <stdlib.h>
21#include <time.h>
22#include "card.h"
23#include "carddeck.h"
24
25
26CardDeck::CardDeck(int jokers) : numberOfJokers(jokers), deckCreated(FALSE)
27{
28 cards = new (Card *)[getNumberOfCards()];
29}
30
31
32CardDeck::~CardDeck()
33{
34 for (int i = 0; i < getNumberOfCards(); i++)
35 delete cards[i];
36 delete cards;
37}
38
39
40void CardDeck::createDeck()
41{
42 if (!deckCreated) {
43 for (int i = 0; i < 52; i++)
44 cards[i] = newCard( (eValue)((i % 13) + 1), (eSuit)((i / 13) + 1), FALSE );
45 for (int i = 0; i < getNumberOfJokers(); i++)
46 cards[52 + i] = newCard( jokerVal, jokerSuit, FALSE );
47 deckCreated = TRUE;
48 }
49}
50
51
52void CardDeck::shuffle()
53{
54 srand(time(NULL));
55 for (int i = 0; i < getNumberOfCards(); i++) {
56 int index = rand() % getNumberOfCards();
57 Card *tmpCard = cards[i];
58 cards[i] = cards[index];
59 cards[index] = tmpCard;
60 }
61}
62
63
64int CardDeck::getNumberOfCards()
65{
66 return 52 + getNumberOfJokers();
67}
68
69
70int CardDeck::getNumberOfJokers()
71{
72 return numberOfJokers;
73}
74
75
76Card *CardDeck::newCard( eValue v, eSuit s, bool f )
77{
78 return new Card(v, s, f);
79}
80
81
diff --git a/noncore/games/solitaire/carddeck.h b/noncore/games/solitaire/carddeck.h
new file mode 100644
index 0000000..9ad35a9
--- a/dev/null
+++ b/noncore/games/solitaire/carddeck.h
@@ -0,0 +1,49 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CARD_DECK_H
21#define CARD_DECK_H
22
23
24class Card;
25
26
27class CardDeck
28{
29public:
30 CardDeck(int jokers = 0);
31 virtual ~CardDeck();
32
33 void createDeck();
34 void shuffle();
35 int getNumberOfCards();
36 int getNumberOfJokers();
37
38 virtual Card *newCard( eValue v, eSuit s, bool f );
39 virtual void deal() { }
40
41 Card **cards;
42private:
43 int numberOfJokers;
44 bool deckCreated;
45};
46
47
48#endif
49
diff --git a/noncore/games/solitaire/cardgame.cpp b/noncore/games/solitaire/cardgame.cpp
new file mode 100644
index 0000000..b19aeef
--- a/dev/null
+++ b/noncore/games/solitaire/cardgame.cpp
@@ -0,0 +1,35 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "cardgame.h"
21
22
23void CardGame::newGame()
24{
25 // Create Cards
26 createDeck();
27
28 // Shuffle Cards
29 shuffle();
30
31 // Deal Cards
32 deal();
33}
34
35
diff --git a/noncore/games/solitaire/cardgame.h b/noncore/games/solitaire/cardgame.h
new file mode 100644
index 0000000..dd7efab
--- a/dev/null
+++ b/noncore/games/solitaire/cardgame.h
@@ -0,0 +1,45 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CARD_GAME_H
21#define CARD_GAME_H
22
23
24#include <qpoint.h>
25#include "card.h"
26#include "cardpile.h"
27#include "carddeck.h"
28#include "cardgamelayout.h"
29
30
31class CardGame : public CardGameLayout, public CardDeck
32{
33public:
34 CardGame(int numOfJokers = 0) : CardGameLayout(), CardDeck(numOfJokers) { }
35 virtual ~CardGame() { }
36 virtual void newGame();
37 virtual void mousePress(QPoint p) { Q_UNUSED(p); }
38 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
39 virtual void mouseMove(QPoint p) { Q_UNUSED(p); }
40private:
41};
42
43
44#endif
45
diff --git a/noncore/games/solitaire/cardgamelayout.cpp b/noncore/games/solitaire/cardgamelayout.cpp
new file mode 100644
index 0000000..1ceee8d
--- a/dev/null
+++ b/noncore/games/solitaire/cardgamelayout.cpp
@@ -0,0 +1,61 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "cardgamelayout.h"
21
22
23CardGameLayout::~CardGameLayout()
24{
25 // Should I just do setAutoDelete( TRUE ); ?
26 for (CardPile *p = first(); p != NULL; p = next())
27 delete p;
28}
29
30
31CardPile *CardGameLayout::closestPile(int x, int y, int maxDistance)
32{
33 int closestDistance = maxDistance * maxDistance;
34 CardPile *closestPile = NULL;
35
36 for (CardPile *p = first(); p != NULL; p = next()) {
37 int d = p->distanceFromNextPos(x, y);
38 if (d < closestDistance) {
39 closestDistance = d;
40 closestPile = p;
41 }
42 }
43
44 return closestPile;
45}
46
47
48void CardGameLayout::beginDealing()
49{
50 for (CardPile *p = first(); p != NULL; p = next())
51 p->beginDealing();
52}
53
54
55void CardGameLayout::endDealing()
56{
57 for (CardPile *p = first(); p != NULL; p = next())
58 p->endDealing();
59}
60
61
diff --git a/noncore/games/solitaire/cardgamelayout.h b/noncore/games/solitaire/cardgamelayout.h
new file mode 100644
index 0000000..bb36e6b
--- a/dev/null
+++ b/noncore/games/solitaire/cardgamelayout.h
@@ -0,0 +1,42 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CARD_GAME_LAYOUT_H
21#define CARD_GAME_LAYOUT_H
22
23
24#include <qlist.h>
25#include "cardpile.h"
26
27
28class CardGameLayout : public QList<CardPile>
29{
30public:
31 CardGameLayout() { }
32 virtual ~CardGameLayout();
33
34 void addCardPile(CardPile *pile) { append((const CardPile *)pile); }
35 CardPile *closestPile(int x, int y, int maxDistance);
36 void beginDealing();
37 void endDealing();
38};
39
40
41#endif
42
diff --git a/noncore/games/solitaire/cardpile.cpp b/noncore/games/solitaire/cardpile.cpp
new file mode 100644
index 0000000..0b738d2
--- a/dev/null
+++ b/noncore/games/solitaire/cardpile.cpp
@@ -0,0 +1,114 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "cardpile.h"
22#include "card.h"
23
24#include <qpe/config.h>
25#include <qpoint.h>
26
27#include <qlist.h>
28
29
30CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE) {
31 pileWidth = 0;
32 pileHeight = 0;
33 pileNextX = pileX;
34 pileNextY = pileY;
35 pileCenterX = x + pileWidth / 2;
36 pileCenterY = y + pileHeight / 2;
37 pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight;
38}
39
40
41int CardPile::distanceFromPile(int x, int y) {
42 return (pileCenterX-x)*(pileCenterX-x)+(pileCenterY-y)*(pileCenterY-y);
43}
44
45
46int CardPile::distanceFromNextPos(int x, int y) {
47 return (pileNextX-x)*(pileNextX-x)+(pileNextY-y)*(pileNextY-y);
48}
49
50
51Card *CardPile::cardInfront(Card *c) {
52 CardPile *p = c->getCardPile();
53 if (p) {
54 p->at(p->find(c));
55 return p->next();
56 } else {
57 return NULL;
58 }
59}
60
61
62bool CardPile::kingOnTop() {
63 Card *top = cardOnTop();
64 return top && top->getValue() == king;
65}
66
67
68bool CardPile::addCardToTop(Card *c) {
69 if (dealing || isAllowedOnTop(c)) {
70 append((const Card *)c);
71 cardAddedToTop(c);
72 return TRUE;
73 }
74 return FALSE;
75}
76
77
78bool CardPile::addCardToBottom(Card *c) {
79 if (dealing || isAllowedOnBottom(c)) {
80 prepend((const Card *)c);
81 cardAddedToBottom(c);
82 return TRUE;
83 }
84 return FALSE;
85}
86
87
88bool CardPile::removeCard(Card *c) {
89 if (dealing || isAllowedToBeMoved(c)) {
90 take(find(c));
91 cardRemoved(c);
92 return TRUE;
93 }
94 return FALSE;
95}
96
97
98void CardPile::writeConfig( Config& cfg, QString name ) {
99 int numberOfCards = 0;
100 cfg.setGroup( name );
101 Card *card = cardOnBottom();
102 while ( card ) {
103 QString cardStr;
104 cardStr.sprintf( "%i", numberOfCards );
105 int val = (int)card->getValue() - 1 + ( (int)card->getSuit() - 1 ) * 13;
106 cfg.writeEntry( "Card" + cardStr, val );
107 cfg.writeEntry( "CardFacing" + cardStr, card->isFacing() );
108 card = cardInfront( card );
109 numberOfCards++;
110 }
111 cfg.writeEntry("NumberOfCards", numberOfCards);
112}
113
114
diff --git a/noncore/games/solitaire/cardpile.h b/noncore/games/solitaire/cardpile.h
new file mode 100644
index 0000000..c515bbc
--- a/dev/null
+++ b/noncore/games/solitaire/cardpile.h
@@ -0,0 +1,101 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CARD_PILE_H
21#define CARD_PILE_H
22
23
24#include <qpoint.h>
25#include <qlist.h>
26
27
28enum ePileStackingType {
29 pileCascades = 0, pileStacks, pileCascadesOrStacks
30};
31
32
33enum ePileFaceingType {
34 pileFaceUp = 0, pileFaceDown, pileFaceUpOrDown
35};
36
37
38class Card;
39class Config;
40
41
42class CardPile : public QList<Card>
43{
44public:
45 CardPile(int x, int y);
46 virtual ~CardPile() { }
47
48 int getX() { return pileX; }
49 int getY() { return pileY; }
50 int getNextX() { return pileNextX; }
51 int getNextY() { return pileNextY; }
52 int getWidth() { return pileWidth; }
53 int getHeight() { return pileHeight; }
54
55 void setX(int x) { pileX = x; }
56 void setY(int y) { pileY = y; }
57 void setNextX(int x) { pileNextX = x; }
58 void setNextY(int y) { pileNextY = y; }
59 void setWidth(int width) { pileWidth = width; }
60 void setHeight(int height) { pileHeight = height; }
61
62 void beginDealing() { dealing = TRUE; }
63 void endDealing() { dealing = FALSE; }
64 bool isDealing() { return dealing; }
65
66 int distanceFromPile(int x, int y);
67 int distanceFromNextPos(int x, int y);
68
69 Card *cardOnTop() { return getLast(); }
70 Card *cardOnBottom() { return getFirst(); }
71 Card *cardInfront(Card *c);
72 bool kingOnTop();
73
74 bool addCardToTop(Card *c);
75 bool addCardToBottom(Card *c);
76 bool removeCard(Card *c);
77
78 virtual void cardAddedToTop(Card *) { }
79 virtual void cardAddedToBottom(Card *) { }
80 virtual void cardRemoved(Card *) { }
81 virtual bool isAllowedOnTop(Card *) { return FALSE; }
82 virtual bool isAllowedOnBottom(Card *) { return FALSE; }
83 virtual bool isAllowedToBeMoved(Card *) { return FALSE; }
84 virtual QPoint getCardPos(Card *) { return QPoint(pileX, pileY); }
85 virtual QPoint getHypertheticalNextCardPos() { return QPoint(pileX, pileY); }
86
87 void writeConfig( Config& cfg, QString name );
88
89protected:
90 int pileX, pileY;
91 int pileNextX, pileNextY;
92 int pileWidth, pileHeight;
93 int pileCenterX, pileCenterY;
94 int pileRadius;
95private:
96 bool dealing;
97};
98
99
100#endif
101
diff --git a/noncore/games/solitaire/freecellcardgame.cpp b/noncore/games/solitaire/freecellcardgame.cpp
new file mode 100644
index 0000000..e82afd4
--- a/dev/null
+++ b/noncore/games/solitaire/freecellcardgame.cpp
@@ -0,0 +1,137 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "freecellcardgame.h"
21
22
23extern int highestZ;
24int numberOfFreeCells = 4;
25
26
27FreecellCardGame::FreecellCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent)
28{
29 numberOfFreeCells = 4;
30 highestZ = 0;
31
32 for (int i = 0; i < 4; i++) {
33 freecellPiles[i] = new FreecellFreecellPile( 5 + i * 28, 10, canvas() );
34 addCardPile(freecellPiles[i]);
35 }
36 for (int i = 0; i < 4; i++) {
37 discardPiles[i] = new FreecellDiscardPile( 125 + i * 28, 10, canvas() );
38 addCardPile(discardPiles[i]);
39 }
40 for (int i = 0; i < 8; i++) {
41 workingPiles[i] = new FreecellWorkingPile( 10 + i * 28, 50, canvas() );
42 addCardPile(workingPiles[i]);
43 }
44}
45
46
47void FreecellCardGame::deal(void)
48{
49 highestZ = 1;
50
51 beginDealing();
52
53 for (int i = 0; i < 52; i++) {
54 Card *card = cards[i];
55 card->setFace( TRUE );
56 card->setPos( 0, 0, highestZ );
57 card->setCardPile( workingPiles[i%8] );
58 workingPiles[i%8]->addCardToTop( card );
59 card->move( workingPiles[i%8]->getCardPos( card ) );
60 card->showCard();
61 highestZ++;
62 }
63
64 endDealing();
65}
66
67
68bool FreecellCardGame::mousePressCard( Card *c, QPoint p )
69{
70 Q_UNUSED(p);
71
72 if ( !c->getCardPile()->isAllowedToBeMoved(c) ) {
73 moving = NULL;
74 return TRUE;
75 }
76
77 return FALSE;
78}
79
80
81void FreecellCardGame::readConfig( Config& cfg )
82{
83 cfg.setGroup("GameState");
84
85 // Create Cards, but don't shuffle or deal them yet
86 createDeck();
87
88 // Move the cards to their piles (deal them to their previous places)
89 beginDealing();
90
91 highestZ = 1;
92
93 for (int k = 0; k < 4; k++) {
94 QString pile;
95 pile.sprintf( "FreeCellPile%i", k );
96 readPile( cfg, freecellPiles[k], pile, highestZ );
97 }
98
99 for (int k = 0; k < 4; k++) {
100 QString pile;
101 pile.sprintf( "DiscardPile%i", k );
102 readPile( cfg, discardPiles[k], pile, highestZ );
103 }
104
105 for (int k = 0; k < 8; k++) {
106 QString pile;
107 pile.sprintf( "WorkingPile%i", k );
108 readPile( cfg, workingPiles[k], pile, highestZ );
109 }
110
111 highestZ++;
112
113 endDealing();
114}
115
116
117void FreecellCardGame::writeConfig( Config& cfg )
118{
119 cfg.setGroup("GameState");
120 for ( int i = 0; i < 4; i++ ) {
121 QString pile;
122 pile.sprintf( "FreeCellPile%i", i );
123 freecellPiles[i]->writeConfig( cfg, pile );
124 }
125 for ( int i = 0; i < 4; i++ ) {
126 QString pile;
127 pile.sprintf( "DiscardPile%i", i );
128 discardPiles[i]->writeConfig( cfg, pile );
129 }
130 for ( int i = 0; i < 8; i++ ) {
131 QString pile;
132 pile.sprintf( "WorkingPile%i", i );
133 workingPiles[i]->writeConfig( cfg, pile );
134 }
135}
136
137
diff --git a/noncore/games/solitaire/freecellcardgame.h b/noncore/games/solitaire/freecellcardgame.h
new file mode 100644
index 0000000..f1b09ab
--- a/dev/null
+++ b/noncore/games/solitaire/freecellcardgame.h
@@ -0,0 +1,152 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef FREECELL_CARD_GAME_H
21#define FREECELL_CARD_GAME_H
22
23
24#include "patiencecardgame.h"
25
26
27extern int numberOfFreeCells;
28
29
30class FreecellDiscardPile : public PatienceDiscardPile
31{
32public:
33 FreecellDiscardPile(int x, int y, QCanvas *canvas) :
34 PatienceDiscardPile(x, y, canvas) { }
35
36};
37
38
39class FreecellWorkingPile : public PatienceWorkingPile
40{
41public:
42 FreecellWorkingPile(int x, int y, QCanvas *canvas) :
43 PatienceWorkingPile(x, y, canvas) { }
44
45 virtual bool isAllowedOnTop(Card *card) {
46 if ( cardOnBottom() == NULL ) {
47 int numberOfCardsBeingMoved = 0;
48 Card *tempCard = card;
49
50 while ((tempCard != NULL)) {
51 numberOfCardsBeingMoved++;
52 tempCard = cardInfront(tempCard);
53 }
54
55 if (numberOfCardsBeingMoved > numberOfFreeCells)
56 return FALSE;
57 }
58
59 if ( card->isFacing() &&
60 cardOnTop() == NULL )
61 return TRUE;
62 return PatienceWorkingPile::isAllowedOnTop( card );
63 }
64
65 virtual bool isAllowedToBeMoved(Card *card) {
66 int nextExpectedValue = (int)card->getValue();
67 bool nextExpectedColor = card->isRed();
68 int numberOfCardsBeingMoved = 0;
69
70 while ((card != NULL)) {
71 numberOfCardsBeingMoved++;
72 if ( (int)card->getValue() != nextExpectedValue )
73 return FALSE;
74 if ( card->isRed() != nextExpectedColor )
75 return FALSE;
76 nextExpectedValue--;;
77 nextExpectedColor = !nextExpectedColor;
78 card = cardInfront(card);
79 }
80
81 if (numberOfCardsBeingMoved <= (numberOfFreeCells + 1))
82 return TRUE;
83
84 return FALSE;
85 }
86 virtual void cardRemoved(Card *card) {
87 if ( !isDealing() && !cardOnTop() )
88 numberOfFreeCells++;
89 PatienceWorkingPile::cardRemoved( card );
90 }
91 virtual void cardAddedToTop(Card *card) {
92 if ( !isDealing() && cardOnBottom() == card )
93 numberOfFreeCells--;
94 PatienceWorkingPile::cardAddedToTop( card );
95 }
96};
97
98
99class FreecellFreecellPile : public CardPile, public CanvasRoundRect
100{
101public:
102 FreecellFreecellPile(int x, int y, QCanvas *canvas)
103 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
104 virtual bool isAllowedOnTop(Card *card) {
105 if ( ( cardOnTop() == NULL ) && ( card->getCardPile()->cardInfront(card) == NULL ) )
106 return TRUE;
107 return FALSE;
108 }
109 virtual bool isAllowedToBeMoved(Card *card) {
110 Q_UNUSED(card);
111 return TRUE;
112 }
113 virtual void cardAddedToTop(Card *card) {
114 Q_UNUSED(card);
115 numberOfFreeCells--;
116 }
117 virtual void cardRemoved(Card *card) {
118 Q_UNUSED(card);
119 numberOfFreeCells++;
120 }
121};
122
123
124class FreecellCardGame : public CanvasCardGame
125{
126public:
127 FreecellCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
128 virtual void deal(void);
129 virtual bool haveWeWon() {
130 return ( discardPiles[0]->kingOnTop() &&
131 discardPiles[1]->kingOnTop() &&
132 discardPiles[2]->kingOnTop() &&
133 discardPiles[3]->kingOnTop() );
134 }
135 virtual void mousePress(QPoint p) { Q_UNUSED(p); }
136 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
137// virtual void mouseMove(QPoint p);
138 virtual bool mousePressCard(Card *card, QPoint p);
139 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
140// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
141 void readConfig( Config& cfg );
142 void writeConfig( Config& cfg );
143 bool snapOn;
144private:
145 FreecellFreecellPile *freecellPiles[8];
146 FreecellWorkingPile *workingPiles[8];
147 FreecellDiscardPile *discardPiles[4];
148};
149
150
151#endif
152
diff --git a/noncore/games/solitaire/main.cpp b/noncore/games/solitaire/main.cpp
new file mode 100644
index 0000000..f81aa3c
--- a/dev/null
+++ b/noncore/games/solitaire/main.cpp
@@ -0,0 +1,36 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "canvascardwindow.h"
22
23#include <qpe/qpeapplication.h>
24
25
26int main( int argc, char ** argv )
27{
28 QPEApplication a( argc, argv );
29
30 CanvasCardWindow m;
31 m.setCaption( CanvasCardWindow::tr("Patience") );
32 a.showMainWidget( &m );
33
34 return a.exec();
35}
36
diff --git a/noncore/games/solitaire/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp
new file mode 100644
index 0000000..5a9326a
--- a/dev/null
+++ b/noncore/games/solitaire/patiencecardgame.cpp
@@ -0,0 +1,234 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "patiencecardgame.h"
21
22
23int highestZ = 0;
24
25
26PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent)
27{
28 numberOfTimesThroughDeck = 0;
29 highestZ = 0;
30
31 circleCross = new CanvasCircleOrCross( 7, 18, canvas() );
32 rectangle = new CanvasRoundRect( 35, 10, canvas() );
33
34 for (int i = 0; i < 4; i++) {
35 discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() );
36 addCardPile(discardPiles[i]);
37 }
38 for (int i = 0; i < 7; i++) {
39 workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() );
40 addCardPile(workingPiles[i]);
41 }
42 faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
43 faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() );
44}
45
46
47PatienceCardGame::~PatienceCardGame()
48{
49 delete circleCross;
50 delete rectangle;
51 delete faceDownDealingPile;
52 delete faceUpDealingPile;
53}
54
55
56void PatienceCardGame::deal(void)
57{
58 highestZ = 1;
59 int t = 0;
60
61 beginDealing();
62
63 for (int i = 0; i < 7; i++) {
64 cards[t]->setFace(TRUE);
65 for (int k = i; k < 7; k++, t++) {
66 Card *card = cards[t];
67 workingPiles[k]->addCardToTop(card);
68 card->setCardPile( workingPiles[k] );
69 QPoint p = workingPiles[k]->getCardPos( card );
70 card->setPos( p.x(), p.y(), highestZ );
71 card->showCard();
72 highestZ++;
73 }
74 }
75
76 for ( ; t < 52; t++) {
77 Card *card = cards[t];
78 faceDownDealingPile->addCardToTop(card);
79 card->setCardPile( faceDownDealingPile );
80 QPoint p = faceDownDealingPile->getCardPos( card );
81 card->setPos( p.x(), p.y(), highestZ );
82 card->showCard();
83 highestZ++;
84 }
85
86 endDealing();
87}
88
89
90void PatienceCardGame::readConfig( Config& cfg )
91{
92 cfg.setGroup("GameState");
93
94 // Do we have a config file to read in?
95 if ( !cfg.hasKey("numberOfTimesThroughDeck") ) {
96 // if not, create a new game
97 newGame();
98 return;
99 }
100 // We have a config file, lets read it in and use it
101
102 // Create Cards, but don't shuffle or deal them yet
103 createDeck();
104
105 // How many times through the deck have we been
106 numberOfTimesThroughDeck = cfg.readNumEntry("NumberOfTimesThroughDeck");
107
108 // restore state to the circle/cross under the dealing pile
109 if ( canTurnOverDeck() )
110 circleCross->setCircle();
111 else
112 circleCross->setCross();
113
114 // Move the cards to their piles (deal them to their previous places)
115 beginDealing();
116
117 highestZ = 1;
118
119 for (int k = 0; k < 7; k++) {
120 QString pile;
121 pile.sprintf( "WorkingPile%i", k );
122 readPile( cfg, workingPiles[k], pile, highestZ );
123 }
124
125 for (int k = 0; k < 4; k++) {
126 QString pile;
127 pile.sprintf( "DiscardPile%i", k );
128 readPile( cfg, discardPiles[k], pile, highestZ );
129 }
130
131 readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ );
132 readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ );
133
134 highestZ++;
135
136 endDealing();
137}
138
139
140void PatienceCardGame::writeConfig( Config& cfg )
141{
142 cfg.setGroup("GameState");
143 cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck);
144
145 for ( int i = 0; i < 7; i++ ) {
146 QString pile;
147 pile.sprintf( "WorkingPile%i", i );
148 workingPiles[i]->writeConfig( cfg, pile );
149 }
150 for ( int i = 0; i < 4; i++ ) {
151 QString pile;
152 pile.sprintf( "DiscardPile%i", i );
153 discardPiles[i]->writeConfig( cfg, pile );
154 }
155 faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" );
156 faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" );
157}
158
159
160bool PatienceCardGame::mousePressCard( Card *card, QPoint p )
161{
162 Q_UNUSED(p);
163
164 CanvasCard *item = (CanvasCard *)card;
165 if (item->isFacing() != TRUE) {
166 // From facedown stack
167 if ((item->x() == 5) && ((int)item->y() == 10)) {
168 item->setZ(highestZ);
169 highestZ++;
170
171 // Added Code
172 faceDownDealingPile->removeCard(item);
173 faceUpDealingPile->addCardToTop(item);
174 item->setCardPile( faceUpDealingPile );
175
176 item->flipTo( 35, (int)item->y() );
177 }
178 moving = NULL;
179 moved = FALSE;
180
181 // move two other cards if we flip three at a time
182 int flipped = 1;
183 QCanvasItemList l = canvas()->collisions( p );
184 for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) {
185 if ( (*it)->rtti() == canvasCardId ) {
186 CanvasCard *item = (CanvasCard *)*it;
187 if (item->animated())
188 continue;
189 item->setZ(highestZ);
190 highestZ++;
191 flipped++;
192
193 // Added Code
194 faceDownDealingPile->removeCard(item);
195 faceUpDealingPile->addCardToTop(item);
196 item->setCardPile( faceUpDealingPile );
197
198 item->flipTo( 35, (int)item->y(), 8 * flipped );
199 }
200 }
201
202 return TRUE;
203 }
204
205 return FALSE;
206}
207
208
209void PatienceCardGame::mousePress(QPoint p)
210{
211 if ( canTurnOverDeck() &&
212 (p.x() > 5) && (p.x() < 28) &&
213 (p.y() > 10) && (p.y() < 46) ) {
214
215 beginDealing();
216 Card *card = faceUpDealingPile->cardOnTop();
217 while ( card ) {
218 card->setPos( 5, 10, highestZ );
219 card->setFace( FALSE );
220 faceUpDealingPile->removeCard( card );
221 faceDownDealingPile->addCardToTop( card );
222 card->setCardPile( faceDownDealingPile );
223 card = faceUpDealingPile->cardOnTop();
224 highestZ++;
225 }
226 endDealing();
227
228 throughDeck();
229
230 moved = TRUE;
231 }
232}
233
234
diff --git a/noncore/games/solitaire/patiencecardgame.h b/noncore/games/solitaire/patiencecardgame.h
new file mode 100644
index 0000000..c4f6c48
--- a/dev/null
+++ b/noncore/games/solitaire/patiencecardgame.h
@@ -0,0 +1,206 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef PATIENCE_CARD_GAME_H
21#define PATIENCE_CARD_GAME_H
22
23
24#include <qpopupmenu.h>
25#include <qmainwindow.h>
26#include <qintdict.h>
27#include <qcanvas.h>
28// #include "canvascardshapes.h"
29// #include "canvascard.h"
30#include "canvascardgame.h"
31
32
33class PatienceFaceDownDeck : public CardPile, public CanvasRoundRect
34{
35public:
36 PatienceFaceDownDeck(int x, int y, QCanvas *canvas)
37 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
38 virtual bool isAllowedOnTop(Card *card) {
39 Q_UNUSED(card);
40 // Need to check it is from the faceUpDealingPile
41 return TRUE;
42 }
43 virtual bool isAllowedToBeMoved(Card *card) {
44 Q_UNUSED(card);
45 //if ( ( !card->isFacing() ) && ( card == cardOnTop() ) )
46 if ( card == cardOnTop() )
47 return TRUE;
48 return FALSE;
49 }
50};
51
52
53class PatienceFaceUpDeck : public CardPile, public CanvasRoundRect
54{
55public:
56 PatienceFaceUpDeck(int x, int y, QCanvas *canvas)
57 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
58 virtual bool isAllowedOnTop(Card *card) {
59 Q_UNUSED(card);
60 // Need to check it is from the faceDownDealingPile
61 return TRUE;
62 }
63 virtual bool isAllowedToBeMoved(Card *card) {
64 Q_UNUSED(card);
65 //if ( ( card->isFacing() ) && ( card == cardOnTop() ) )
66 if ( card == cardOnTop() )
67 return TRUE;
68 return FALSE;
69 }
70};
71
72
73class PatienceDiscardPile : public CardPile, public CanvasRoundRect
74{
75public:
76 PatienceDiscardPile(int x, int y, QCanvas *canvas)
77 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
78 virtual bool isAllowedOnTop(Card *card) {
79 if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) &&
80 ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) ||
81 ( ( cardOnTop() != NULL ) &&
82 ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) &&
83 ( card->getSuit() == cardOnTop()->getSuit() ) ) ) )
84 return TRUE;
85 return FALSE;
86 }
87 virtual bool isAllowedToBeMoved(Card *card) {
88 if ( card->isFacing() && ( card == cardOnTop() ) )
89 return TRUE;
90 return FALSE;
91 }
92};
93
94
95class PatienceWorkingPile : public CardPile, public CanvasRoundRect
96{
97public:
98 PatienceWorkingPile(int x, int y, QCanvas *canvas)
99 : CardPile(x, y), CanvasRoundRect(x, y, canvas), top(x, y) { }
100 virtual bool isAllowedOnTop(Card *card) {
101 if ( card->isFacing() &&
102 ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) ||
103 ( ( cardOnTop() != NULL ) &&
104 ( (int)card->getValue() + 1 == (int)cardOnTop()->getValue() ) &&
105 ( card->isRed() != cardOnTop()->isRed() ) ) ) )
106 return TRUE;
107 return FALSE;
108 }
109 virtual bool isAllowedToBeMoved(Card *card) {
110 if ( card->isFacing() )
111 return TRUE;
112 return FALSE;
113 }
114 virtual void cardAddedToTop(Card *card) {
115 Q_UNUSED(card);
116 top = getCardPos(NULL);
117 setNextX( top.x() );
118 setNextY( top.y() );
119 }
120 virtual void cardRemoved(Card *card) {
121 Q_UNUSED(card);
122
123 Card *newTopCard = cardOnTop();
124
125 if ( !newTopCard ) {
126 top = QPoint( pileX, pileY );
127 setNextX( pileX );
128 setNextY( pileY );
129 return;
130 } else {
131 top = getCardPos(NULL);
132 if ( newTopCard->isFacing() == FALSE ) {
133 // correct the position taking in to account the card is not
134 // yet flipped, but will become flipped
135 top = QPoint( top.x() - 1, top.y() - 3 );
136 newTopCard->flipTo( top.x(), top.y() );
137 top = QPoint( top.x(), top.y() + 13 );
138 }
139 setNextX( top.x() );
140 setNextY( top.y() );
141 }
142 }
143 virtual QPoint getCardPos(Card *c) {
144 int x = pileX, y = pileY;
145 Card *card = cardOnBottom();
146 while ((card != c) && (card != NULL)) {
147 if (card->isFacing()) {
148 y += 13;
149 } else {
150 x += 1;
151 y += 3;
152 }
153 card = cardInfront(card);
154 }
155 return QPoint( x, y );
156 }
157 virtual QPoint getHypertheticalNextCardPos(void) {
158 return top;
159 // return QPoint( getNextX(), getNextY() );
160 }
161private:
162 QPoint top;
163
164};
165
166
167class PatienceCardGame : public CanvasCardGame
168{
169public:
170 PatienceCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
171 virtual ~PatienceCardGame();
172 virtual void deal(void);
173 virtual bool haveWeWon() {
174 return ( discardPiles[0]->kingOnTop() &&
175 discardPiles[1]->kingOnTop() &&
176 discardPiles[2]->kingOnTop() &&
177 discardPiles[3]->kingOnTop() );;
178 }
179 virtual void mousePress(QPoint p);
180 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
181// virtual void mouseMove(QPoint p);
182 virtual bool mousePressCard(Card *card, QPoint p);
183 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
184// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
185 bool canTurnOverDeck(void) { return (numberOfTimesThroughDeck != 3); }
186 void throughDeck(void) {
187 numberOfTimesThroughDeck++;
188 if (numberOfTimesThroughDeck == 3)
189 circleCross->setCross();
190 }
191 bool snapOn;
192 virtual void writeConfig( Config& cfg );
193 virtual void readConfig( Config& cfg );
194private:
195 CanvasCircleOrCross *circleCross;
196 CanvasRoundRect *rectangle;
197 PatienceWorkingPile *workingPiles[7];
198 PatienceDiscardPile *discardPiles[4];
199 PatienceFaceDownDeck *faceDownDealingPile;
200 PatienceFaceUpDeck *faceUpDealingPile;
201 int numberOfTimesThroughDeck;
202};
203
204
205#endif
206
diff --git a/noncore/games/solitaire/qpe-solitaire.control b/noncore/games/solitaire/qpe-solitaire.control
new file mode 100644
index 0000000..71abb0c
--- a/dev/null
+++ b/noncore/games/solitaire/qpe-solitaire.control
@@ -0,0 +1,9 @@
1Files: bin/patience apps/Games/patience.desktop pics/cards
2Priority: optional
3Section: qpe/games
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Game: solitaire card games
9 A solitaire game for the Qtopia environment.
diff --git a/noncore/games/solitaire/solitaire.pro b/noncore/games/solitaire/solitaire.pro
new file mode 100755
index 0000000..8617cab
--- a/dev/null
+++ b/noncore/games/solitaire/solitaire.pro
@@ -0,0 +1,18 @@
1 TEMPLATE= app
2
3 CONFIG += qt warn_on release
4 DESTDIR = $(QPEDIR)/bin
5
6 HEADERS = canvascard.h canvasshapes.h cardgame.h cardgamelayout.h cardpile.h card.h carddeck.h canvascardgame.h freecellcardgame.h patiencecardgame.h canvascardwindow.h
7
8 SOURCES = canvascard.cpp canvasshapes.cpp cardgame.cpp cardgamelayout.cpp cardpile.cpp card.cpp carddeck.cpp canvascardgame.cpp freecellcardgame.cpp patiencecardgame.cpp canvascardwindow.cpp main.cpp
9
10 TARGET = patience
11
12INCLUDEPATH += $(QPEDIR)/include
13 DEPENDPATH+= $(QPEDIR)/include
14LIBS += -lqpe
15
16 REQUIRES= patience
17
18TRANSLATIONS = ../i18n/de/patience.ts
diff --git a/noncore/games/tetrix/.cvsignore b/noncore/games/tetrix/.cvsignore
new file mode 100644
index 0000000..edfa921
--- a/dev/null
+++ b/noncore/games/tetrix/.cvsignore
@@ -0,0 +1,3 @@
1moc_*
2*.moc
3Makefile
diff --git a/noncore/games/tetrix/Makefile.in b/noncore/games/tetrix/Makefile.in
new file mode 100644
index 0000000..3a74fdc
--- a/dev/null
+++ b/noncore/games/tetrix/Makefile.in
@@ -0,0 +1,157 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= tetrix
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =minefield.h \
27 gtetrix.h \
28 qtetrix.h \
29 qtetrixb.h \
30 tpiece.h
31 SOURCES =main.cpp \
32 gtetrix.cpp \
33 qtetrix.cpp \
34 qtetrixb.cpp \
35 tpiece.cpp
36 OBJECTS =main.o \
37 gtetrix.o \
38 qtetrix.o \
39 qtetrixb.o \
40 tpiece.o
41INTERFACES =
42UICDECLS =
43UICIMPLS =
44 SRCMOC =moc_qtetrix.cpp \
45 moc_qtetrixb.cpp
46 OBJMOC =moc_qtetrix.o \
47 moc_qtetrixb.o
48
49
50####### Implicit rules
51
52.SUFFIXES: .cpp .cxx .cc .C .c
53
54.cpp.o:
55 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
56
57.cxx.o:
58 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
59
60.cc.o:
61 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
62
63.C.o:
64 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
65
66.c.o:
67 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
68
69####### Build rules
70
71
72all: $(DESTDIR)$(TARGET)
73
74$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
75 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
76
77moc: $(SRCMOC)
78
79tmake:
80 tmake tetrix.pro
81
82clean:
83 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
84 -rm -f *~ core
85 -rm -f allmoc.cpp
86
87####### Extension Modules
88
89listpromodules:
90 @echo
91
92listallmodules:
93 @echo
94
95listaddonpromodules:
96 @echo
97
98listaddonentmodules:
99 @echo
100
101
102REQUIRES=
103
104####### Sub-libraries
105
106
107###### Combined headers
108
109
110
111####### Compile
112
113main.o: main.cpp \
114 qtetrix.h \
115 qtetrixb.h \
116 gtetrix.h \
117 tpiece.h \
118 $(QPEDIR)/include/qpe/qpeapplication.h
119
120gtetrix.o: gtetrix.cpp \
121 gtetrix.h \
122 tpiece.h
123
124qtetrix.o: qtetrix.cpp \
125 qtetrix.h \
126 qtetrixb.h \
127 gtetrix.h \
128 tpiece.h \
129 $(QPEDIR)/include/qpe/resource.h
130
131qtetrixb.o: qtetrixb.cpp \
132 qtetrixb.h \
133 gtetrix.h \
134 tpiece.h \
135 qtetrix.h
136
137tpiece.o: tpiece.cpp \
138 tpiece.h
139
140moc_qtetrix.o: moc_qtetrix.cpp \
141 qtetrix.h \
142 qtetrixb.h \
143 gtetrix.h \
144 tpiece.h
145
146moc_qtetrixb.o: moc_qtetrixb.cpp \
147 qtetrixb.h \
148 gtetrix.h \
149 tpiece.h
150
151moc_qtetrix.cpp: qtetrix.h
152 $(MOC) qtetrix.h -o moc_qtetrix.cpp
153
154moc_qtetrixb.cpp: qtetrixb.h
155 $(MOC) qtetrixb.h -o moc_qtetrixb.cpp
156
157
diff --git a/noncore/games/tetrix/gtetrix.cpp b/noncore/games/tetrix/gtetrix.cpp
new file mode 100644
index 0000000..d1f38b1
--- a/dev/null
+++ b/noncore/games/tetrix/gtetrix.cpp
@@ -0,0 +1,514 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#include "gtetrix.h"
23
24#include <string.h>
25
26GenericTetrix::GenericTetrix(int boardWidth,int boardHeight)
27{
28 int i,j;
29
30 width = boardWidth;
31 height = boardHeight;
32 boardPtr = new int[height*width]; // Note the order, this makes it easier
33 // to remove full lines.
34 for(i = 0 ; i < height ; i++)
35 for(j = 0 ; j < width ; j++)
36 board(j,i) = 0;
37 currentLine = -1; // -1 if no falling piece.
38 currentPos = 0;
39 showNext = 0; // FALSE
40 nLinesRemoved = 0;
41 nPiecesDropped = 0;
42 score = 0;
43 level = 1;
44 gameID = 0;
45 nClearLines = height;
46}
47
48GenericTetrix::~GenericTetrix()
49{
50 delete[] boardPtr;
51}
52
53
54void GenericTetrix::clearBoard(int fillRandomLines)
55{
56 int i,j;
57
58 if (fillRandomLines >= height)
59 fillRandomLines = height - 1;
60
61 erasePiece();
62 for(i = height - nClearLines - 1 ; i >= fillRandomLines ; i--)
63 for(j = 0 ; j < width ; j++)
64 if (board(j,i) != 0) {
65 draw(j,i,0);
66 board(j,i) = 0;
67 }
68 if (fillRandomLines != 0)
69 for (i = 0 ; i < fillRandomLines ; i++) {
70 fillRandom(i);
71 }
72 nClearLines = height - fillRandomLines;
73}
74
75void GenericTetrix::showBoard()
76{
77 int i,j;
78
79 showPiece();
80 for(i = height - nClearLines - 1 ; i >= 0 ; i--)
81 for(j = 0 ; j < width ; j++)
82 if (board(j,i) != 0)
83 draw(j,i,board(j,i));
84}
85
86void GenericTetrix::hideBoard()
87{
88 int i,j;
89
90 erasePiece();
91 for(i = height - nClearLines - 1 ; i >= 0 ; i--)
92 for(j = 0 ; j < width ; j++)
93 if (board(j,i) != 0)
94 draw(j,i,0);
95}
96
97void GenericTetrix::startGame(int gameType,int fillRandomLines)
98{
99 gameID = gameType;
100 clearBoard(fillRandomLines);
101 nLinesRemoved = 0;
102 updateRemoved(nLinesRemoved);
103 nClearLines = height;
104 nPiecesDropped = 0;
105 score = 0;
106 updateScore(score);
107 level = 1;
108 updateLevel(level);
109 newPiece();
110}
111
112void GenericTetrix::revealNextPiece(int revealIt)
113{
114 if (showNext == revealIt)
115 return;
116 showNext = revealIt;
117 if (!showNext)
118 eraseNextPiece();
119 else
120 showNextPiece();
121}
122
123void GenericTetrix::updateBoard(int x1,int y1,int x2, int y2,
124 int dontUpdateBlanks)
125{
126 int i,j;
127 int tmp;
128
129 if (x1 > x2) {
130 tmp = x2;
131 x2 = x1;
132 x1 = tmp;
133 }
134 if (y1 > y2) {
135 tmp = y2;
136 y2 = y1;
137 y1 = tmp;
138 }
139 if (x1 < 0)
140 x1 = 0;
141 if (x2 >= width)
142 x2 = width - 1;
143 if (y1 < 0)
144 y1 = 0;
145 if (y2 >= height)
146 y2 = height - 1;
147 for(i = y1 ; i <= y2 ; i++)
148 for(j = x1 ; j <= x2 ; j++)
149 if (!dontUpdateBlanks || board(j,height - i - 1) != 0)
150 draw(j,height - i - 1,board(j,height - i - 1));
151 showPiece(); // Remember to update piece correctly!!!!
152}
153
154
155void GenericTetrix::fillRandom(int line)
156{
157 int i,j;
158 int holes;
159
160 for(i = 0 ; i < width ; i++)
161 board(i,line) = TetrixPiece::randomValue(7);
162 holes = 0;
163 for(i = 0 ; i < width ; i++)
164 if (board(i,line) == 0) // Count holes in the line.
165 holes++;
166 if (holes == 0) // Full line, make a random hole:
167 board(TetrixPiece::randomValue(width),line) = 0;
168 if (holes == width) // Empty line, make a random square:
169 board(TetrixPiece::randomValue(width),line) =
170 TetrixPiece::randomValue(6) + 1;
171 for(j = 0 ; j < width ; j++)
172 draw(j,i,board(j,i));
173}
174
175void GenericTetrix::moveLeft(int steps)
176{
177 while(steps) {
178 if (!canMoveTo(currentPos - 1,currentLine))
179 return;
180 moveTo(currentPos - 1,currentLine);
181 steps--;
182 }
183}
184
185void GenericTetrix::moveRight(int steps)
186{
187 while(steps) {
188 if (!canMoveTo(currentPos + 1,currentLine))
189 return;
190 moveTo(currentPos + 1,currentLine);
191 steps--;
192 }
193}
194
195void GenericTetrix::rotateLeft()
196{
197 TetrixPiece tmp(currentPiece);
198
199 tmp.rotateLeft();
200 if (!canPosition(tmp))
201 return;
202 position(tmp);
203 currentPiece = tmp;
204}
205
206void GenericTetrix::rotateRight()
207{
208 TetrixPiece tmp(currentPiece);
209
210 tmp.rotateRight();
211 if (!canPosition(tmp))
212 return;
213 position(tmp);
214 currentPiece = tmp;
215}
216
217void GenericTetrix::dropDown()
218{
219 if (currentLine == -1)
220 return;
221
222 int dropHeight = 0;
223 int newLine = currentLine;
224 while(newLine) {
225 if (!canMoveTo(currentPos,newLine - 1))
226 break;
227 newLine--;
228 dropHeight++;
229 }
230 if (dropHeight != 0)
231 moveTo(currentPos,newLine);
232 internalPieceDropped(dropHeight);
233}
234
235void GenericTetrix::oneLineDown()
236{
237 if (currentLine == -1)
238 return;
239 if (canMoveTo(currentPos,currentLine - 1)) {
240 moveTo(currentPos,currentLine - 1);
241 } else {
242 internalPieceDropped(0);
243 }
244}
245
246void GenericTetrix::newPiece()
247{
248 currentPiece = nextPiece;
249 if (showNext)
250 eraseNextPiece();
251 nextPiece.setRandomType();
252 if (showNext)
253 showNextPiece();
254 currentLine = height - 1 + currentPiece.getMinY();
255 currentPos = width/2 + 1;
256 if (!canMoveTo(currentPos,currentLine)) {
257 currentLine = -1;
258 gameOver();
259 } else {
260 showPiece();
261 }
262}
263
264void GenericTetrix::removePiece()
265{
266 erasePiece();
267 currentLine = -1;
268}
269
270void GenericTetrix::drawNextSquare(int,int,int)
271{
272
273}
274
275void GenericTetrix::pieceDropped(int)
276{
277 newPiece();
278}
279
280void GenericTetrix::updateRemoved(int)
281{
282}
283
284void GenericTetrix::updateScore(int)
285{
286}
287
288void GenericTetrix::updateLevel(int)
289{
290}
291
292void GenericTetrix::removeFullLines()
293{
294 int i,j,k;
295 int nFullLines;
296
297 for(i = 0 ; i < height - nClearLines ; i++) {
298 for(j = 0 ; j < width ; j++)
299 if (board(j,i) == 0)
300 break;
301 if (j == width) {
302 nFullLines = 1;
303 for(k = i + 1 ; k < height - nClearLines ; k++) {
304 for(j = 0 ; j < width ; j++)
305 if (board(j,k) == 0)
306 break;
307 if (j == width) {
308 nFullLines++;
309 } else {
310 for(j = 0 ; j < width ; j++) {
311 if (board(j,k - nFullLines) != board(j,k)) {
312 board(j,k - nFullLines) = board(j,k);
313 draw( j,k - nFullLines,
314 board(j,k - nFullLines));
315 }
316 }
317 }
318 }
319 nClearLines = nClearLines + nFullLines;
320 nLinesRemoved = nLinesRemoved + nFullLines;
321 updateRemoved(nLinesRemoved);
322 score = score + 10*nFullLines; // updateScore must be
323 // called by caller!
324 for (i = height - nClearLines ;
325 i < height - nClearLines + nFullLines ;
326 i++)
327 for(j = 0 ; j < width ; j++)
328 if (board(j,i) != 0) {
329 draw(j,i,0);
330 board(j,i) = 0;
331 }
332 }
333 }
334}
335
336void GenericTetrix::showPiece()
337{
338 int x,y;
339
340 if (currentLine == -1)
341 return;
342
343 for(int i = 0 ; i < 4 ; i++) {
344 currentPiece.getCoord(i,x,y);
345 draw(currentPos + x,currentLine - y,currentPiece.getType());
346 }
347}
348
349void GenericTetrix::erasePiece()
350{
351 int x,y;
352
353 if (currentLine == -1)
354 return;
355
356 for(int i = 0 ; i < 4 ; i++) {
357 currentPiece.getCoord(i,x,y);
358 draw(currentPos + x,currentLine - y,0);
359 }
360}
361
362void GenericTetrix::internalPieceDropped(int dropHeight)
363{
364 gluePiece();
365 nPiecesDropped++;
366 if (nPiecesDropped % 25 == 0) {
367 level++;
368 updateLevel(level);
369 }
370 score = score + 7 + dropHeight;
371 removeFullLines();
372 updateScore(score);
373 pieceDropped(dropHeight);
374}
375
376void GenericTetrix::gluePiece()
377{
378 int x,y;
379 int min;
380
381 if (currentLine == -1)
382 return;
383
384 for(int i = 0 ; i < 4 ; i++) {
385 currentPiece.getCoord(i,x,y);
386 board(currentPos + x,currentLine - y) = currentPiece.getType();
387 }
388 min = currentPiece.getMinY();
389 if (currentLine - min >= height - nClearLines)
390 nClearLines = height - currentLine + min - 1;
391}
392
393void GenericTetrix::showNextPiece(int erase)
394{
395 int x,y;
396 int minX = nextPiece.getMinX();
397 int minY = nextPiece.getMinY();
398 int maxX = nextPiece.getMaxX();
399 int maxY = nextPiece.getMaxY();
400
401 int xOffset = (3 - (maxX - minX))/2;
402 int yOffset = (3 - (maxY - minY))/2;
403
404 for(int i = 0 ; i < 4 ; i++) {
405 nextPiece.getCoord(i,x,y);
406 if (erase)
407 drawNextSquare(x + xOffset - minX,
408 y + yOffset - minY,0);
409 else
410 drawNextSquare(x + xOffset - minX,
411 y + yOffset - minY,nextPiece.getType());
412 }
413}
414
415int GenericTetrix::canPosition(TetrixPiece &piece)
416{
417 if (currentLine == -1)
418 return 0;
419
420 int x,y;
421
422 for(int i = 0 ; i < 4 ; i++) {
423 piece.getCoord(i,x,y);
424 x = currentPos + x;
425 y = currentLine - y; // Board and pieces have inverted y-coord. systems.
426 if (x < 0 || x >= width || y < 0 || y >= height)
427 return 0; // Outside board, cannot put piece here.
428 if (board(x,y) != 0)
429 return 0; // Over a non-zero square, cannot put piece here.
430 }
431 return 1; // Inside board and no non-zero squares underneath.
432
433}
434
435int GenericTetrix::canMoveTo(int xPosition,int line)
436{
437 if (currentLine == -1)
438 return 0;
439
440 int x,y;
441
442 for(int i = 0 ; i < 4 ; i++) {
443 currentPiece.getCoord(i,x,y);
444 x = xPosition + x;
445 y = line - y; // Board and pieces have inverted y-coord. systems.
446 if (x < 0 || x >= width || y < 0 || y >= height)
447 return 0; // Outside board, cannot put piece here.
448 if (board(x,y) != 0)
449 return 0; // Over a non-zero square, cannot put piece here.
450 }
451 return 1; // Inside board and no non-zero squares underneath.
452}
453
454void GenericTetrix::moveTo(int xPosition,int line)
455{
456 if (currentLine == -1)
457 return;
458 optimizedMove(xPosition,line,currentPiece);
459 currentPos = xPosition;
460 currentLine = line;
461}
462
463void GenericTetrix::position(TetrixPiece &piece)
464{
465 if (currentLine == -1)
466 return;
467
468 optimizedMove(currentPos,currentLine,piece);
469}
470
471void GenericTetrix::optimizedMove(int newPos, int newLine,
472 TetrixPiece &newPiece)
473{
474 int updates [8][3];
475 int nUpdates;
476 int value;
477 int x,y;
478 int i,j;
479
480 for(i = 0 ; i < 4 ; i++) { // Put the erasing coords into updates
481 currentPiece.getCoord(i,x,y);
482 updates[i][0] = currentPos + x;
483 updates[i][1] = currentLine - y;
484 updates[i][2] = 0;
485 }
486 nUpdates = 4;
487 for(i = 0 ; i < 4 ; i++) { // Any drawing coord same as an erasing one?
488 newPiece.getCoord(i,x,y);
489 x = newPos + x;
490 y = newLine - y;
491 for (j = 0 ; j < 4 ; j++)
492 if (updates[j][0] == x && updates[j][1] == y) { // Same coord,
493 // don't have to erase
494 if (currentPiece.getType() == newPiece.getType())
495 updates[j][2] = -1; // Correct on screen, no update!
496 else
497 updates[j][2] = newPiece.getType();
498 break;
499 }
500 if (j == 4) { // This coord does not overlap an erasing one
501 updates[nUpdates][0] = x;
502 updates[nUpdates][1] = y;
503 updates[nUpdates][2] = newPiece.getType();
504 nUpdates++;
505 }
506 }
507 for (i = 0 ; i < nUpdates ; i++) { // Do the updating
508 x = updates[i][0];
509 y = updates[i][1];
510 value = updates[i][2];
511 if (value != -1) // Only update if new value != current
512 draw(x,y,value);
513 }
514}
diff --git a/noncore/games/tetrix/gtetrix.h b/noncore/games/tetrix/gtetrix.h
new file mode 100644
index 0000000..520dd89
--- a/dev/null
+++ b/noncore/games/tetrix/gtetrix.h
@@ -0,0 +1,104 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#ifndef GTETRIX_H
23#define GTETRIX_H
24
25#include "tpiece.h"
26
27
28class GenericTetrix
29{
30public:
31 GenericTetrix(int boardWidth = 10,int boardHeight = 22);
32 virtual ~GenericTetrix();
33
34 void clearBoard(int fillRandomLines = 0);
35 void revealNextPiece(int revealIt);
36 void updateBoard(int x1,int y1,int x2,int y2,int dontUpdateBlanks = 0);
37 void updateNext(){if (showNext) showNextPiece();}
38 void hideBoard();
39 void showBoard();
40 void fillRandom(int line);
41
42 void moveLeft(int steps = 1);
43 void moveRight(int steps = 1);
44 void rotateLeft();
45 void rotateRight();
46 void dropDown();
47 void oneLineDown();
48 void newPiece();
49 void removePiece();
50
51 int noOfClearLines() {return nClearLines;}
52 int getLinesRemoved() {return nLinesRemoved;}
53 int getPiecesDropped() {return nPiecesDropped;}
54 int getScore() {return score;}
55 int getLevel() {return level;}
56 int boardHeight() {return height;}
57 int boardWidth() {return width;}
58
59 virtual void drawSquare(int x,int y,int value) = 0;
60 virtual void gameOver() = 0;
61
62 virtual void startGame(int gameType = 0,int fillRandomLines = 0);
63 virtual void drawNextSquare(int x,int y,int value);
64 virtual void pieceDropped(int dropHeight);
65 virtual void updateRemoved(int noOfLines);
66 virtual void updateScore(int newScore);
67 virtual void updateLevel(int newLevel);
68
69private:
70 void draw(int x, int y, int value){drawSquare(x,height - y,value);}
71 void removeFullLines();
72 void removeLine(int line);
73 void showPiece();
74 void erasePiece();
75 void internalPieceDropped(int dropHeight);
76 void gluePiece();
77 void showNextPiece(int erase = 0);
78 void eraseNextPiece(){showNextPiece(1);};
79 int canPosition(TetrixPiece &piece); // Returns a boolean value.
80 int canMoveTo(int xPosition, int line); // Returns a boolean value.
81 void moveTo(int xPosition,int line);
82 void position(TetrixPiece &piece);
83 void optimizedMove(int newPos, int newLine,TetrixPiece &newPiece);
84
85 int &board(int x,int y){return boardPtr[width*y + x];}
86
87 TetrixPiece currentPiece;
88 TetrixPiece nextPiece;
89 int currentLine;
90 int currentPos;
91 int showNext; // Boolean variable.
92 int nLinesRemoved;
93 int nPiecesDropped;
94 int score;
95 int level;
96 int gameID;
97 int nClearLines;
98 int width;
99 int height;
100 int *boardPtr;
101};
102
103
104#endif
diff --git a/noncore/games/tetrix/main.cpp b/noncore/games/tetrix/main.cpp
new file mode 100644
index 0000000..e36d52d
--- a/dev/null
+++ b/noncore/games/tetrix/main.cpp
@@ -0,0 +1,33 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "qtetrix.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char **argv )
26{
27 QPEApplication a(argc,argv);
28
29 QTetrix *tetrix = new QTetrix;
30 a.showMainWidget(tetrix);
31
32 return a.exec();
33}
diff --git a/noncore/games/tetrix/qpe-tetrix.control b/noncore/games/tetrix/qpe-tetrix.control
new file mode 100644
index 0000000..46dfdf5
--- a/dev/null
+++ b/noncore/games/tetrix/qpe-tetrix.control
@@ -0,0 +1,10 @@
1Files: bin/tetrix apps/Games/tetrix.desktop
2Priority: optional
3Section: qpe/games
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Arch: iPAQ
7Version: $QPE_VERSION-3
8Depends: qpe-base ($QPE_VERSION)
9Description: Game: control falling blocks
10 A game for the Qtopia environment.
diff --git a/noncore/games/tetrix/qtetrix.cpp b/noncore/games/tetrix/qtetrix.cpp
new file mode 100644
index 0000000..f649894
--- a/dev/null
+++ b/noncore/games/tetrix/qtetrix.cpp
@@ -0,0 +1,170 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#include "qtetrix.h"
23
24#include <qpe/resource.h>
25
26#include <qapplication.h>
27#include <qlabel.h>
28#include <qdatetime.h>
29#include <qlayout.h>
30
31
32
33void drawTetrixButton( QPainter *p, int x, int y, int w, int h,
34 const QColor *color )
35{
36 QColor fc;
37 if ( color ) {
38 QPointArray a;
39 a.setPoints( 3, x,y+h-1, x,y, x+w-1,y );
40 p->setPen( color->light() );
41 p->drawPolyline( a );
42 a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 );
43 p->setPen( color->dark() );
44 p->drawPolyline( a );
45 x++;
46 y++;
47 w -= 2;
48 h -= 2;
49 fc = *color;
50 }
51 else
52 fc = p->backgroundColor();
53 p->fillRect( x, y, w, h, fc );
54}
55
56
57ShowNextPiece::ShowNextPiece( QWidget *parent, const char *name )
58 : QFrame( parent, name )
59{
60 setFrameStyle( QFrame::Panel | QFrame::Sunken );
61 xOffset = -1; // -1 until first resizeEvent.
62}
63
64void ShowNextPiece::resizeEvent( QResizeEvent *e )
65{
66 QSize sz = e->size();
67 blockWidth = (sz.width() - 3)/5;
68 blockHeight = (sz.height() - 3)/6;
69 xOffset = (sz.width() - 3)/5;
70 yOffset = (sz.height() - 3)/6;
71}
72
73
74void ShowNextPiece::paintEvent( QPaintEvent * )
75{
76 QPainter p( this );
77 drawFrame( &p );
78 p.end(); // explicit end() so any slots can paint too
79 emit update();
80}
81
82
83void ShowNextPiece::drawNextSquare(int x, int y,QColor *color)
84{
85 if (xOffset == -1) // Before first resizeEvent?
86 return;
87
88 QPainter paint;
89 paint.begin(this);
90 drawTetrixButton( &paint, xOffset+x*blockWidth, yOffset+y*blockHeight,
91 blockWidth, blockHeight, color );
92 paint.end();
93}
94
95
96QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f )
97 : QMainWindow( parent, name, f )
98{
99 setIcon( Resource::loadPixmap( "tetrix_icon" ) );
100 setCaption( tr("Tetrix" ) );
101
102 QTime t = QTime::currentTime();
103 TetrixPiece::setRandomSeed( (((double)t.hour())+t.minute()+t.second())/
104 (24+60+60) );
105
106 QWidget *gameArea = new QWidget( this );
107 setCentralWidget( gameArea );
108
109 QGridLayout *gl = new QGridLayout( gameArea, 5, 3, 8 );
110
111 QLabel *l;
112 l = new QLabel( tr("Next"), gameArea );
113 gl->addWidget( l, 0, 0 );
114 showNext = new ShowNextPiece(gameArea);
115 showNext->setBackgroundColor(QColor(0,0,0));
116 gl->addWidget( showNext, 0, 1 );
117
118 l = new QLabel( tr("Score"), gameArea );
119 gl->addWidget( l, 1, 0 );
120 showScore = new QLabel(gameArea);
121 gl->addWidget( showScore, 1, 1 );
122 l = new QLabel( tr("Level"), gameArea );
123 gl->addWidget( l, 2, 0 );
124 showLevel = new QLabel(gameArea);
125 gl->addWidget( showLevel, 2, 1 );
126 l = new QLabel( tr("Removed"), gameArea );
127 gl->addWidget( l, 3, 0 );
128 showLines = new QLabel(gameArea);
129 gl->addWidget( showLines, 3, 1 );
130
131 board = new QTetrixBoard(gameArea);
132 board->setBackgroundColor(QColor(0,0,0));
133 board->setFixedWidth( 124 );
134 gl->addMultiCellWidget( board, 0, 4, 2, 2 );
135 gl->addColSpacing( 2, 100 );
136 gl->addColSpacing( 1, 35 );
137 gl->addRowSpacing( 0, 35 );
138
139 QPushButton *pb = new QPushButton( tr("Start"), gameArea );
140 pb->setFocusPolicy( NoFocus );
141 connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) );
142 gl->addMultiCellWidget( pb, 4, 4, 0, 1 );
143
144 connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) );
145 connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), showNext,
146 SLOT(drawNextSquare(int,int,QColor*)) );
147 connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) );
148 connect( board, SIGNAL(updateScoreSignal(int)), showScore,
149 SLOT(setNum(int)) );
150 connect( board, SIGNAL(updateLevelSignal(int)), showLevel,
151 SLOT(setNum(int)));
152 connect( board, SIGNAL(updateRemovedSignal(int)), showLines,
153 SLOT(setNum(int)));
154
155 showScore->setNum( 0 );
156 showLevel->setNum( 0 );
157 showLines->setNum( 0 );
158 board->revealNextPiece(TRUE);
159 board->setFocusPolicy( StrongFocus );
160}
161
162void QTetrix::gameOver()
163{
164}
165
166
167void QTetrix::quit()
168{
169 close();
170}
diff --git a/noncore/games/tetrix/qtetrix.h b/noncore/games/tetrix/qtetrix.h
new file mode 100644
index 0000000..b6e058a
--- a/dev/null
+++ b/noncore/games/tetrix/qtetrix.h
@@ -0,0 +1,78 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#ifndef QTETRIX_H
23#define QTETRIX_H
24
25#include "qtetrixb.h"
26#include <qframe.h>
27#include <qlcdnumber.h>
28#include <qpushbutton.h>
29#include <qpainter.h>
30#include <qmainwindow.h>
31
32class QLabel;
33
34class ShowNextPiece : public QFrame
35{
36 Q_OBJECT
37 friend class QTetrix;
38public:
39 ShowNextPiece( QWidget *parent=0, const char *name=0 );
40public slots:
41 void drawNextSquare( int x, int y,QColor *color );
42signals:
43 void update();
44private:
45 void paintEvent( QPaintEvent * );
46 void resizeEvent( QResizeEvent * );
47
48 int blockWidth,blockHeight;
49 int xOffset,yOffset;
50};
51
52
53class QTetrix : public QMainWindow
54{
55 Q_OBJECT
56public:
57 QTetrix( QWidget *parent=0, const char *name=0, WFlags f=0 );
58 void startGame() { board->startGame(); }
59
60public slots:
61 void gameOver();
62 void quit();
63private:
64 void keyPressEvent( QKeyEvent *e ) { board->keyPressEvent(e); }
65
66 QTetrixBoard *board;
67 ShowNextPiece *showNext;
68 QLabel *showScore;
69 QLabel *showLevel;
70 QLabel *showLines;
71};
72
73
74void drawTetrixButton( QPainter *, int x, int y, int w, int h,
75 const QColor *color );
76
77
78#endif
diff --git a/noncore/games/tetrix/qtetrixb.cpp b/noncore/games/tetrix/qtetrixb.cpp
new file mode 100644
index 0000000..521f171
--- a/dev/null
+++ b/noncore/games/tetrix/qtetrixb.cpp
@@ -0,0 +1,251 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#include "qtetrixb.h"
23#include "qtetrix.h"
24#include <qtimer.h>
25#include <qkeycode.h>
26#include <qpainter.h>
27
28const int waitAfterLineTime = 500;
29
30QTetrixBoard::QTetrixBoard( QWidget *p, const char *name )
31 : QFrame( p, name )
32{
33 setFrameStyle( QFrame::Panel | QFrame::Sunken );
34 paint = 0;
35 timer = new QTimer(this);
36 connect( timer, SIGNAL(timeout()), SLOT(timeout()) );
37
38 colors[0].setRgb(200,100,100);
39 colors[1].setRgb(100,200,100);
40 colors[2].setRgb(100,100,200);
41 colors[3].setRgb(200,200,100);
42 colors[4].setRgb(200,100,200);
43 colors[5].setRgb(100,200,200);
44 colors[6].setRgb(218,170, 0);
45
46 xOffset = -1; // -1 until a resizeEvent is received.
47 blockWidth = 20;
48 yOffset = 30;
49 blockHeight = 20;
50 noGame = TRUE;
51 isPaused = FALSE;
52 waitingAfterLine = FALSE;
53 updateTimeoutTime(); // Sets timeoutTime
54}
55
56void QTetrixBoard::startGame(int gameType,int fillRandomLines)
57{
58 if ( isPaused )
59 return; // ignore if game is paused
60 noGame = FALSE;
61 GenericTetrix::startGame( gameType, fillRandomLines );
62 // Note that the timer is started by updateLevel!
63}
64
65
66void QTetrixBoard::pause()
67{
68 if ( noGame ) // game not active
69 return;
70 isPaused = !isPaused;
71 if ( isPaused ) {
72 timer->stop();
73 hideBoard();
74 }
75 else
76 timer->start(timeoutTime);
77 update();
78}
79
80
81void QTetrixBoard::drawSquare(int x,int y,int value)
82{
83 if (xOffset == -1) // Before first resizeEvent?
84 return;
85
86 const int X = xOffset + x*blockWidth;
87 const int Y = yOffset + (y - 1)*blockHeight;
88
89 bool localPainter = paint == 0;
90 QPainter *p;
91 if ( localPainter )
92 p = new QPainter( this );
93 else
94 p = paint;
95 drawTetrixButton( p, X, Y, blockWidth, blockHeight,
96 value == 0 ? 0 : &colors[value-1] );
97 /*
98 if ( value != 0 ) {
99 QColor tc, bc;
100 tc = colors[value-1].light();
101 bc = colors[value-1].dark();
102 p->drawShadePanel( X, Y, blockWidth, blockHeight,
103 tc, bc, 1, colors[value-1], TRUE );
104 }
105 else
106 p->fillRect( X, Y, blockWidth, blockHeight, backgroundColor() );
107 */
108 if ( localPainter )
109 delete p;
110}
111
112void QTetrixBoard::drawNextSquare( int x, int y, int value )
113{
114 if ( value == 0 )
115 emit drawNextSquareSignal (x, y, 0 );
116 else
117 emit drawNextSquareSignal( x, y, &colors[value-1] );
118}
119
120void QTetrixBoard::updateRemoved( int noOfLines )
121{
122 if ( noOfLines > 0 ) {
123 timer->stop();
124 timer->start( waitAfterLineTime );
125 waitingAfterLine = TRUE;
126 }
127 emit updateRemovedSignal( noOfLines );
128}
129
130void QTetrixBoard::updateScore( int newScore )
131{
132 emit updateScoreSignal( newScore );
133}
134
135void QTetrixBoard::updateLevel( int newLevel )
136{
137 timer->stop();
138 updateTimeoutTime();
139 timer->start( timeoutTime );
140 emit updateLevelSignal( newLevel );
141}
142
143void QTetrixBoard::pieceDropped(int)
144{
145 if ( waitingAfterLine ) // give player a break if a line has been removed
146 return;
147 newPiece();
148}
149
150void QTetrixBoard::gameOver()
151{
152 timer->stop();
153 noGame = TRUE;
154 emit gameOverSignal();
155}
156
157void QTetrixBoard::timeout()
158{
159 if ( waitingAfterLine ) {
160 timer->stop();
161 waitingAfterLine = FALSE;
162 newPiece();
163 timer->start( timeoutTime );
164 } else {
165 oneLineDown();
166 }
167}
168
169void QTetrixBoard::drawContents( QPainter *p )
170{
171 const char *text = "Press \"Pause\"";
172 QRect r = contentsRect();
173 paint = p; // set widget painter
174 if ( isPaused ) {
175 p->drawText( r, AlignCenter | AlignVCenter, text );
176 return;
177 }
178 int x1,y1,x2,y2;
179 x1 = (r.left() - xOffset) / blockWidth;
180 if (x1 < 0)
181 x1 = 0;
182 if (x1 >= boardWidth())
183 x1 = boardWidth() - 1;
184
185 x2 = (r.right() - xOffset) / blockWidth;
186 if (x2 < 0)
187 x2 = 0;
188 if (x2 >= boardWidth())
189 x2 = boardWidth() - 1;
190
191 y1 = (r.top() - yOffset) / blockHeight;
192 if (y1 < 0)
193 y1 = 0;
194 if (y1 >= boardHeight())
195 y1 = boardHeight() - 1;
196
197 y2 = (r.bottom() - yOffset) / blockHeight;
198 if (y2 < 0)
199 y2 = 0;
200 if (y2 >= boardHeight())
201 y2 = boardHeight() - 1;
202
203 updateBoard( x1, y1, x2, y2, TRUE );
204 paint = 0; // reset widget painter
205 return;
206}
207
208void QTetrixBoard::resizeEvent(QResizeEvent *e)
209{
210 QSize sz = e->size();
211 blockWidth = (sz.width() - 2)/10;
212 blockHeight = (sz.height() - 2)/22;
213 xOffset = 1;
214 //yOffset = 1;
215 yOffset = (sz.height() - 2) - (blockHeight *22);
216}
217
218void QTetrixBoard::keyPressEvent( QKeyEvent *e )
219{
220 if ( noGame || isPaused || waitingAfterLine )
221 return;
222 switch( e->key() ) {
223 case Key_Left :
224 moveLeft();
225 break;
226 case Key_Right :
227 moveRight();
228 break;
229 case Key_Down :
230 // rotateRight();
231 dropDown();
232 break;
233 case Key_Up :
234 rotateLeft();
235 break;
236 case Key_Space :
237 dropDown();
238 break;
239 case Key_D :
240 oneLineDown();
241 break;
242 default:
243 return;
244 }
245 e->accept();
246}
247
248void QTetrixBoard::updateTimeoutTime()
249{
250 timeoutTime = 1000/(1 + getLevel());
251}
diff --git a/noncore/games/tetrix/qtetrixb.h b/noncore/games/tetrix/qtetrixb.h
new file mode 100644
index 0000000..4134a84
--- a/dev/null
+++ b/noncore/games/tetrix/qtetrixb.h
@@ -0,0 +1,80 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#ifndef QTETRIXB_H
23#define QTETRIXB_H
24
25#include "gtetrix.h"
26#include <qframe.h>
27
28class QTimer;
29
30class QTetrixBoard : public QFrame, public GenericTetrix
31{
32 Q_OBJECT
33public:
34 QTetrixBoard( QWidget *parent=0, const char *name=0 );
35
36 void gameOver();
37 void startGame(int gameType = 0,int fillRandomLines = 0);
38
39public slots:
40 void timeout();
41 void updateNext(){ GenericTetrix::updateNext(); }
42 void key(QKeyEvent *e) { keyPressEvent(e); }
43 void start() { startGame(); }
44 void pause();
45
46signals:
47 void gameOverSignal();
48 void drawNextSquareSignal(int x,int y,QColor *color1);
49 void updateRemovedSignal(int noOfLines);
50 void updateScoreSignal(int score);
51 void updateLevelSignal(int level);
52
53public: // until we have keyboard focus, should be protected
54 void keyPressEvent( QKeyEvent * );
55
56private:
57 void drawContents( QPainter * );
58 void resizeEvent( QResizeEvent * );
59 void drawSquare(int x,int y,int value);
60 void drawNextSquare(int x,int y,int value);
61 void updateRemoved(int noOfLines);
62 void updateScore(int newScore);
63 void updateLevel(int newLlevel);
64 void pieceDropped(int dropHeight);
65 void updateTimeoutTime();
66
67 QTimer *timer;
68
69 int xOffset,yOffset;
70 int blockWidth,blockHeight;
71 int timeoutTime;
72 bool noGame;
73 bool isPaused;
74 bool waitingAfterLine;
75
76 QColor colors[7];
77 QPainter *paint;
78};
79
80#endif
diff --git a/noncore/games/tetrix/tetrix.pro b/noncore/games/tetrix/tetrix.pro
new file mode 100644
index 0000000..1160585
--- a/dev/null
+++ b/noncore/games/tetrix/tetrix.pro
@@ -0,0 +1,17 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 DESTDIR = ../bin
4 HEADERS = minefield.h \
5 gtetrix.h \
6 qtetrix.h \
7 qtetrixb.h \
8 tpiece.h
9 SOURCES = main.cpp \
10 gtetrix.cpp \
11 qtetrix.cpp \
12 qtetrixb.cpp \
13 tpiece.cpp
14INCLUDEPATH += $(QPEDIR)/include
15 DEPENDPATH+= $(QPEDIR)/include
16LIBS += -lqpe
17 INTERFACES=
diff --git a/noncore/games/tetrix/tpiece.cpp b/noncore/games/tetrix/tpiece.cpp
new file mode 100644
index 0000000..fe8b766
--- a/dev/null
+++ b/noncore/games/tetrix/tpiece.cpp
@@ -0,0 +1,201 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#include "tpiece.h"
23#include "qstring.h"
24#include <stdlib.h>
25#include <time.h>
26
27void TetrixPiece::rotateLeft()
28{
29 if ( pieceType == 5 ) // don't rotate square piece type
30 return;
31 int tmp;
32 for (int i = 0 ; i < 4 ; i++) {
33 tmp = getXCoord(i);
34 setXCoord(i,getYCoord(i));
35 setYCoord(i,-tmp);
36 }
37}
38
39void TetrixPiece::rotateRight()
40{
41 if ( pieceType == 5 ) // don't rotate square piece type
42 return;
43 int tmp;
44 for (int i = 0 ; i < 4 ; i++) {
45 tmp = getXCoord(i);
46 setXCoord(i,-getYCoord(i));
47 setYCoord(i,tmp);
48 }
49}
50
51int TetrixPiece::getMinX()
52{
53 int tmp = coordinates[0][0];
54 for(int i = 1 ; i < 4 ; i++)
55 if (tmp > coordinates[i][0])
56 tmp = coordinates[i][0];
57 return tmp;
58}
59
60int TetrixPiece::getMaxX()
61{
62 int tmp = coordinates[0][0];
63 for(int i = 1 ; i < 4 ; i++)
64 if (tmp < coordinates[i][0])
65 tmp = coordinates[i][0];
66 return tmp;
67
68}
69
70int TetrixPiece::getMinY()
71{
72 int tmp = coordinates[0][1];
73 for(int i = 1 ; i < 4 ; i++)
74 if (tmp > coordinates[i][1])
75 tmp = coordinates[i][1];
76 return tmp;
77}
78
79int TetrixPiece::getMaxY()
80{
81 int tmp = coordinates[0][1];
82 for(int i = 1 ; i < 4 ; i++)
83 if (tmp < coordinates[i][1])
84 tmp = coordinates[i][1];
85 return tmp;
86}
87
88void TetrixPiece::initialize(int type)
89{
90 static int pieceTypes[7][4][2] = {{{ 0,-1},
91 { 0, 0},
92 {-1, 0},
93 {-1, 1}},
94
95 {{ 0,-1},
96 { 0, 0},
97 { 1, 0},
98 { 1, 1}},
99
100 {{ 0,-1},
101 { 0, 0},
102 { 0, 1},
103 { 0, 2}},
104
105 {{-1, 0},
106 { 0, 0},
107 { 1, 0},
108 { 0, 1}},
109
110 {{ 0, 0},
111 { 1, 0},
112 { 0, 1},
113 { 1, 1}},
114
115 {{-1,-1},
116 { 0,-1},
117 { 0, 0},
118 { 0, 1}},
119
120 {{ 1,-1},
121 { 0,-1},
122 { 0, 0},
123 { 0, 1}}};
124 if (type < 1 || type > 7)
125 type = 1;
126 pieceType = type;
127 for(int i = 0 ; i < 4 ; i++) {
128 coordinates[i][0] = pieceTypes[type - 1][i][0];
129 coordinates[i][1] = pieceTypes[type - 1][i][1];
130 }
131}
132
133
134/*
135 *Sigh, oh beautiful nostalgia! This random algorithm has
136 *been taken from the book "Adventures with your pocket calculator"
137 *and I used it in my first implemented and machine-
138 *run program of any size to speak of. Imagine how hungry I
139 *was after having programmed BASIC on paper for
140 *half a year?!!?!?!?!?!? The first program I typed in was a
141 *slot machine game and was made in BASIC on a SHARP
142 *PC-1211 with 1,47 KB RAM (one point four seven kilobytes) and
143 *a one-line LCD-display (I think it had 32 characters) in the
144 *year of our lord 1981. The man I had bought the machine from worked
145 *as a COBOL programmer and was amazed and impressed
146 *when I demonstrated the program 2 days after I had
147 *bought the machine, quote: "Gees, I have been looking so long
148 *for a "random" command in that BASIC, what is it called?"
149 *Oh, how I still get a thrill out of the thought of the
150 *explanation I then gave him...
151 */
152
153/*
154 *Sukk, aa vakre nostalgi! Denne random algoritmen er
155 *tatt fra boka "Adventures with your pocket calculator"
156 *og den brukte jeg i mitt foerste implementerte og maskin-
157 *kjoerte program av nevneverdig stoerrelse. Tror du jeg var
158 *noe sulten etter aa ha programmert BASIC paa papir i et
159 *halvt aar?!!?!?!?!?!? Programmet jeg tasta inn foerst var et
160 *"enarmet banditt" spill og ble laget i BASIC paa en SHARP
161 *PC-1211 med 1,47 KB RAM (en komma foertisju kilobyte) og
162 *et en-linjers LCD-display (tror det hadde 32 karakterer) i det
163 *herrens aar 1981. Mannen jeg kjoepte maskinen av jobbet til
164 *daglig med COBOL programmering og var forbloeffet og imponert
165 *da jeg demonstrerte programmet 2 dager etter at jeg hadde
166 *kjoept maskinen, sitat: "Joess, jeg som har leita saa lenge
167 *etter en random kommando i den BASICen, hva var det den
168 *het?" Aa, jeg frydes ennaa ved tanken paa forklaringen jeg
169 *deretter ga ham...
170 */
171
172double TetrixPiece::randomSeed = 0.33333;
173
174void TetrixPiece::setRandomSeed(double seed)
175{
176#ifdef __MIPSEL__
177 srand( clock() );
178#else
179 QCString buffer;
180 if (seed < 0)
181 seed = - seed;
182 if (seed >= 1)
183 seed = seed - (double) ((int) seed);
184 buffer.sprintf("%1.5f",(float) seed);
185 for (int i = 0 ; i < 5 ; i++)
186 if ((buffer[i + 2] - '0') % 2 == 0)
187 buffer[i + 2]++;
188 randomSeed = atof(buffer);
189#endif
190}
191
192int TetrixPiece::randomValue(int maxPlusOne)
193{
194#ifdef __MIPSEL__
195 return rand() % maxPlusOne;
196#else
197 randomSeed = randomSeed*147;
198 randomSeed = randomSeed - (double) ((int) randomSeed);
199 return (int) (randomSeed*maxPlusOne);
200#endif
201}
diff --git a/noncore/games/tetrix/tpiece.h b/noncore/games/tetrix/tpiece.h
new file mode 100644
index 0000000..9c1c629
--- a/dev/null
+++ b/noncore/games/tetrix/tpiece.h
@@ -0,0 +1,62 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#ifndef TPIECE_H
23#define TPIECE_H
24
25class TetrixPiece
26{
27public:
28 TetrixPiece() {setRandomType();}
29 TetrixPiece(int type) {initialize(type % 7 + 1);}
30
31 void setRandomType() {initialize(randomValue(7) + 1);}
32
33 void rotateLeft();
34 void rotateRight();
35
36 int getType() {return pieceType;}
37 int getXCoord(int index) {return coordinates[index][0];}
38 int getYCoord(int index) {return coordinates[index][1];}
39 void getCoord(int index,int &x,int&y){x = coordinates[index][0];
40 y = coordinates[index][1];}
41 int getMinX();
42 int getMaxX();
43 int getMinY();
44 int getMaxY();
45
46 static void setRandomSeed(double seed);
47 static int randomValue(int maxPlusOne);
48
49private:
50 void setXCoord(int index,int value) {coordinates[index][0] = value;}
51 void setYCoord(int index,int value) {coordinates[index][1] = value;}
52 void setCoords(int index,int x,int y){coordinates[index][0] = x;
53 coordinates[index][1] = y;}
54 void initialize(int type);
55
56 int pieceType;
57 int coordinates[4][2];
58
59 static double randomSeed;
60};
61
62#endif
diff --git a/noncore/games/wordgame/.cvsignore b/noncore/games/wordgame/.cvsignore
new file mode 100644
index 0000000..d498858
--- a/dev/null
+++ b/noncore/games/wordgame/.cvsignore
@@ -0,0 +1,6 @@
1moc_*
2Makefile
3newgamebase.h
4rulesbase.h
5newgamebase.cpp
6rulesbase.cpp
diff --git a/noncore/games/wordgame/Makefile.in b/noncore/games/wordgame/Makefile.in
new file mode 100644
index 0000000..5627414
--- a/dev/null
+++ b/noncore/games/wordgame/Makefile.in
@@ -0,0 +1,168 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= wordgame
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =wordgame.h
27 SOURCES =main.cpp \
28 wordgame.cpp
29 OBJECTS =main.o \
30 wordgame.o \
31 newgamebase.o \
32 rulesbase.o
33INTERFACES = newgamebase.ui \
34 rulesbase.ui
35UICDECLS = newgamebase.h \
36 rulesbase.h
37UICIMPLS = newgamebase.cpp \
38 rulesbase.cpp
39 SRCMOC =moc_wordgame.cpp \
40 moc_newgamebase.cpp \
41 moc_rulesbase.cpp
42 OBJMOC =moc_wordgame.o \
43 moc_newgamebase.o \
44 moc_rulesbase.o
45
46
47####### Implicit rules
48
49.SUFFIXES: .cpp .cxx .cc .C .c
50
51.cpp.o:
52 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
53
54.cxx.o:
55 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
56
57.cc.o:
58 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
59
60.C.o:
61 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
62
63.c.o:
64 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
65
66####### Build rules
67
68
69all: $(DESTDIR)$(TARGET)
70
71$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
72 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
73
74moc: $(SRCMOC)
75
76tmake:
77 tmake wordgame.pro
78
79clean:
80 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
81 -rm -f *~ core
82 -rm -f allmoc.cpp
83
84####### Extension Modules
85
86listpromodules:
87 @echo
88
89listallmodules:
90 @echo
91
92listaddonpromodules:
93 @echo
94
95listaddonentmodules:
96 @echo
97
98
99REQUIRES=
100
101####### Sub-libraries
102
103
104###### Combined headers
105
106
107
108####### Compile
109
110main.o: main.cpp \
111 wordgame.h \
112 newgamebase.h \
113 rulesbase.h \
114 $(QPEDIR)/include/qpe/qdawg.h \
115 $(QPEDIR)/include/qpe/applnk.h \
116 $(QPEDIR)/include/qpe/qpeapplication.h
117
118wordgame.o: wordgame.cpp \
119 wordgame.h \
120 newgamebase.h \
121 rulesbase.h \
122 $(QPEDIR)/include/qpe/qdawg.h \
123 $(QPEDIR)/include/qpe/applnk.h \
124 $(QPEDIR)/include/qpe/global.h \
125 $(QPEDIR)/include/qpe/filemanager.h \
126 $(QPEDIR)/include/qpe/resource.h \
127 $(QPEDIR)/include/qpe/config.h \
128 $(QPEDIR)/include/qpe/qpetoolbar.h
129
130newgamebase.h: newgamebase.ui
131 $(UIC) newgamebase.ui -o $(INTERFACE_DECL_PATH)/newgamebase.h
132
133newgamebase.cpp: newgamebase.ui
134 $(UIC) newgamebase.ui -i newgamebase.h -o newgamebase.cpp
135
136rulesbase.h: rulesbase.ui
137 $(UIC) rulesbase.ui -o $(INTERFACE_DECL_PATH)/rulesbase.h
138
139rulesbase.cpp: rulesbase.ui
140 $(UIC) rulesbase.ui -i rulesbase.h -o rulesbase.cpp
141
142newgamebase.o: newgamebase.cpp
143
144rulesbase.o: rulesbase.cpp
145
146moc_wordgame.o: moc_wordgame.cpp \
147 wordgame.h \
148 newgamebase.h \
149 rulesbase.h \
150 $(QPEDIR)/include/qpe/qdawg.h \
151 $(QPEDIR)/include/qpe/applnk.h
152
153moc_newgamebase.o: moc_newgamebase.cpp \
154 newgamebase.h
155
156moc_rulesbase.o: moc_rulesbase.cpp \
157 rulesbase.h
158
159moc_wordgame.cpp: wordgame.h
160 $(MOC) wordgame.h -o moc_wordgame.cpp
161
162moc_newgamebase.cpp: newgamebase.h
163 $(MOC) newgamebase.h -o moc_newgamebase.cpp
164
165moc_rulesbase.cpp: rulesbase.h
166 $(MOC) rulesbase.h -o moc_rulesbase.cpp
167
168
diff --git a/noncore/games/wordgame/calcdist b/noncore/games/wordgame/calcdist
new file mode 100755
index 0000000..faf31f1
--- a/dev/null
+++ b/noncore/games/wordgame/calcdist
@@ -0,0 +1,27 @@
1#!/usr/bin/perl
2
3# Usage: cat dictionaries | grep -v '[^a-z]' | calcdist n score
4#
5# Given a lot of words, find an appropriate distribution
6# into n tiles with tile values proportional to the square root
7# of the ratio of score to the tile's frequency.
8
9$n = shift;
10$score = shift;
11
12while (<>) {
13 chomp;
14 for $c ( split "", $_ ) {
15 $freq{$c}++;
16 $t++;
17 }
18}
19
20for $c ( sort { $freq{$a} <=> $freq{$b} } keys %freq ) {
21 #print "$c: $freq{$c}\n";
22 $need = int($freq{$c}*$n/$t+0.5) || 1;
23 $value = int(sqrt($score/($freq{$c}*$n/$t))+0.5) || 1;
24 $t -= $freq{$c};
25 $n -= $need;
26 print "$need $c $value\n";
27}
diff --git a/noncore/games/wordgame/main.cpp b/noncore/games/wordgame/main.cpp
new file mode 100644
index 0000000..cd4600e
--- a/dev/null
+++ b/noncore/games/wordgame/main.cpp
@@ -0,0 +1,34 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "wordgame.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char ** argv )
26{
27 QPEApplication a( argc, argv );
28
29 WordGame mw;
30 //QPEApplication::setInputMethodHint( &mw, QPEApplication::AlwaysOff );
31 a.showMainWidget(&mw);
32
33 return a.exec();
34}
diff --git a/noncore/games/wordgame/newgamebase.ui b/noncore/games/wordgame/newgamebase.ui
new file mode 100644
index 0000000..3b6570b
--- a/dev/null
+++ b/noncore/games/wordgame/newgamebase.ui
@@ -0,0 +1,337 @@
1<!DOCTYPE UI><UI>
2<class>NewGameBase</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>Form1</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>290</width>
15 <height>443</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Form1</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>8</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>3</number>
36 </property>
37 <widget>
38 <class>QGroupBox</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>GroupBox1</cstring>
42 </property>
43 <property stdset="1">
44 <name>title</name>
45 <string>Players</string>
46 </property>
47 <property>
48 <name>layoutMargin</name>
49 </property>
50 <property>
51 <name>layoutSpacing</name>
52 </property>
53 <vbox>
54 <property stdset="1">
55 <name>margin</name>
56 <number>7</number>
57 </property>
58 <property stdset="1">
59 <name>spacing</name>
60 <number>2</number>
61 </property>
62 <widget>
63 <class>QComboBox</class>
64 <item>
65 <property>
66 <name>text</name>
67 <string></string>
68 </property>
69 </item>
70 <item>
71 <property>
72 <name>text</name>
73 <string>AI3: Smart AI player</string>
74 </property>
75 </item>
76 <property stdset="1">
77 <name>name</name>
78 <cstring>player0</cstring>
79 </property>
80 <property stdset="1">
81 <name>editable</name>
82 <bool>true</bool>
83 </property>
84 </widget>
85 <widget>
86 <class>QComboBox</class>
87 <item>
88 <property>
89 <name>text</name>
90 <string></string>
91 </property>
92 </item>
93 <item>
94 <property>
95 <name>text</name>
96 <string>AI3: Smart AI player</string>
97 </property>
98 </item>
99 <property stdset="1">
100 <name>name</name>
101 <cstring>player1</cstring>
102 </property>
103 <property stdset="1">
104 <name>editable</name>
105 <bool>true</bool>
106 </property>
107 </widget>
108 <widget>
109 <class>QComboBox</class>
110 <item>
111 <property>
112 <name>text</name>
113 <string></string>
114 </property>
115 </item>
116 <item>
117 <property>
118 <name>text</name>
119 <string>AI3: Smart AI player</string>
120 </property>
121 </item>
122 <property stdset="1">
123 <name>name</name>
124 <cstring>player2</cstring>
125 </property>
126 <property stdset="1">
127 <name>editable</name>
128 <bool>true</bool>
129 </property>
130 </widget>
131 <widget>
132 <class>QComboBox</class>
133 <item>
134 <property>
135 <name>text</name>
136 <string></string>
137 </property>
138 </item>
139 <item>
140 <property>
141 <name>text</name>
142 <string>AI3: Smart AI player</string>
143 </property>
144 </item>
145 <property stdset="1">
146 <name>name</name>
147 <cstring>player3</cstring>
148 </property>
149 <property stdset="1">
150 <name>editable</name>
151 <bool>true</bool>
152 </property>
153 </widget>
154 <widget>
155 <class>QComboBox</class>
156 <item>
157 <property>
158 <name>text</name>
159 <string></string>
160 </property>
161 </item>
162 <item>
163 <property>
164 <name>text</name>
165 <string>AI3: Smart AI player</string>
166 </property>
167 </item>
168 <property stdset="1">
169 <name>name</name>
170 <cstring>player4</cstring>
171 </property>
172 <property stdset="1">
173 <name>editable</name>
174 <bool>true</bool>
175 </property>
176 </widget>
177 <widget>
178 <class>QComboBox</class>
179 <item>
180 <property>
181 <name>text</name>
182 <string></string>
183 </property>
184 </item>
185 <item>
186 <property>
187 <name>text</name>
188 <string>AI3: Smart AI player</string>
189 </property>
190 </item>
191 <property stdset="1">
192 <name>name</name>
193 <cstring>player5</cstring>
194 </property>
195 <property stdset="1">
196 <name>editable</name>
197 <bool>true</bool>
198 </property>
199 </widget>
200 </vbox>
201 </widget>
202 <widget>
203 <class>QGroupBox</class>
204 <property stdset="1">
205 <name>name</name>
206 <cstring>GroupBox2</cstring>
207 </property>
208 <property stdset="1">
209 <name>title</name>
210 <string>Rules</string>
211 </property>
212 <property>
213 <name>layoutMargin</name>
214 </property>
215 <property>
216 <name>layoutSpacing</name>
217 </property>
218 <hbox>
219 <property stdset="1">
220 <name>margin</name>
221 <number>7</number>
222 </property>
223 <property stdset="1">
224 <name>spacing</name>
225 <number>2</number>
226 </property>
227 <widget>
228 <class>QComboBox</class>
229 <property stdset="1">
230 <name>name</name>
231 <cstring>rules</cstring>
232 </property>
233 <property stdset="1">
234 <name>sizePolicy</name>
235 <sizepolicy>
236 <hsizetype>3</hsizetype>
237 <vsizetype>0</vsizetype>
238 </sizepolicy>
239 </property>
240 </widget>
241 </hbox>
242 </widget>
243 <spacer>
244 <property>
245 <name>name</name>
246 <cstring>Spacer1</cstring>
247 </property>
248 <property stdset="1">
249 <name>orientation</name>
250 <enum>Vertical</enum>
251 </property>
252 <property stdset="1">
253 <name>sizeType</name>
254 <enum>Expanding</enum>
255 </property>
256 <property>
257 <name>sizeHint</name>
258 <size>
259 <width>20</width>
260 <height>20</height>
261 </size>
262 </property>
263 <property>
264 <name>sizeHint</name>
265 <size>
266 <width>20</width>
267 <height>20</height>
268 </size>
269 </property>
270 </spacer>
271 <widget>
272 <class>QLayoutWidget</class>
273 <property stdset="1">
274 <name>name</name>
275 <cstring>Layout1</cstring>
276 </property>
277 <hbox>
278 <property stdset="1">
279 <name>margin</name>
280 <number>0</number>
281 </property>
282 <property stdset="1">
283 <name>spacing</name>
284 <number>6</number>
285 </property>
286 <spacer>
287 <property>
288 <name>name</name>
289 <cstring>Horizontal Spacing2</cstring>
290 </property>
291 <property stdset="1">
292 <name>orientation</name>
293 <enum>Horizontal</enum>
294 </property>
295 <property stdset="1">
296 <name>sizeType</name>
297 <enum>Expanding</enum>
298 </property>
299 <property>
300 <name>sizeHint</name>
301 <size>
302 <width>20</width>
303 <height>20</height>
304 </size>
305 </property>
306 <property>
307 <name>sizeHint</name>
308 <size>
309 <width>20</width>
310 <height>20</height>
311 </size>
312 </property>
313 </spacer>
314 <widget>
315 <class>QPushButton</class>
316 <property stdset="1">
317 <name>name</name>
318 <cstring>buttonOk</cstring>
319 </property>
320 <property stdset="1">
321 <name>text</name>
322 <string>&amp;Start</string>
323 </property>
324 <property stdset="1">
325 <name>autoDefault</name>
326 <bool>true</bool>
327 </property>
328 <property stdset="1">
329 <name>default</name>
330 <bool>true</bool>
331 </property>
332 </widget>
333 </hbox>
334 </widget>
335 </vbox>
336</widget>
337</UI>
diff --git a/noncore/games/wordgame/qpe-wordgame.control b/noncore/games/wordgame/qpe-wordgame.control
new file mode 100644
index 0000000..2293f52
--- a/dev/null
+++ b/noncore/games/wordgame/qpe-wordgame.control
@@ -0,0 +1,10 @@
1Files: bin/wordgame apps/Games/wordgame.desktop
2Priority: optional
3Section: qpe/games
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Crossword game
9 A crossword game for the Qtopia environment.
10 Play against the computer or human opponents.
diff --git a/noncore/games/wordgame/rulesbase.ui b/noncore/games/wordgame/rulesbase.ui
new file mode 100644
index 0000000..31cc402
--- a/dev/null
+++ b/noncore/games/wordgame/rulesbase.ui
@@ -0,0 +1,274 @@
1<!DOCTYPE UI><UI>
2<class>RulesBase</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>RulesBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>283</width>
15 <height>264</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Game Rules</string>
21 </property>
22 <property stdset="1">
23 <name>sizeGripEnabled</name>
24 <bool>false</bool>
25 </property>
26 <vbox>
27 <property stdset="1">
28 <name>margin</name>
29 <number>11</number>
30 </property>
31 <property stdset="1">
32 <name>spacing</name>
33 <number>6</number>
34 </property>
35 <widget>
36 <class>QLayoutWidget</class>
37 <property stdset="1">
38 <name>name</name>
39 <cstring>Layout3</cstring>
40 </property>
41 <hbox>
42 <property stdset="1">
43 <name>margin</name>
44 <number>0</number>
45 </property>
46 <property stdset="1">
47 <name>spacing</name>
48 <number>6</number>
49 </property>
50 <widget>
51 <class>QLabel</class>
52 <property stdset="1">
53 <name>name</name>
54 <cstring>TextLabel1</cstring>
55 </property>
56 <property stdset="1">
57 <name>text</name>
58 <string>Name:</string>
59 </property>
60 </widget>
61 <widget>
62 <class>QLineEdit</class>
63 <property stdset="1">
64 <name>name</name>
65 <cstring>gamename</cstring>
66 </property>
67 </widget>
68 </hbox>
69 </widget>
70 <widget>
71 <class>QGroupBox</class>
72 <property stdset="1">
73 <name>name</name>
74 <cstring>GroupBox3</cstring>
75 </property>
76 <property stdset="1">
77 <name>title</name>
78 <string>Board</string>
79 </property>
80 <property>
81 <name>layoutMargin</name>
82 </property>
83 <property>
84 <name>layoutSpacing</name>
85 </property>
86 <hbox>
87 <property stdset="1">
88 <name>margin</name>
89 <number>5</number>
90 </property>
91 <property stdset="1">
92 <name>spacing</name>
93 <number>4</number>
94 </property>
95 <widget>
96 <class>QLabel</class>
97 <property stdset="1">
98 <name>name</name>
99 <cstring>TextLabel2</cstring>
100 </property>
101 <property stdset="1">
102 <name>sizePolicy</name>
103 <sizepolicy>
104 <hsizetype>0</hsizetype>
105 <vsizetype>1</vsizetype>
106 </sizepolicy>
107 </property>
108 <property stdset="1">
109 <name>text</name>
110 <string>Size:</string>
111 </property>
112 </widget>
113 <widget>
114 <class>QSpinBox</class>
115 <property stdset="1">
116 <name>name</name>
117 <cstring>width</cstring>
118 </property>
119 <property stdset="1">
120 <name>maxValue</name>
121 <number>15</number>
122 </property>
123 <property stdset="1">
124 <name>minValue</name>
125 <number>3</number>
126 </property>
127 <property stdset="1">
128 <name>value</name>
129 <number>15</number>
130 </property>
131 </widget>
132 <widget>
133 <class>QSpinBox</class>
134 <property stdset="1">
135 <name>name</name>
136 <cstring>height</cstring>
137 </property>
138 <property stdset="1">
139 <name>maxValue</name>
140 <number>15</number>
141 </property>
142 <property stdset="1">
143 <name>minValue</name>
144 <number>3</number>
145 </property>
146 <property stdset="1">
147 <name>value</name>
148 <number>15</number>
149 </property>
150 </widget>
151 <widget>
152 <class>QPushButton</class>
153 <property stdset="1">
154 <name>name</name>
155 <cstring>editboard</cstring>
156 </property>
157 <property stdset="1">
158 <name>text</name>
159 <string>Edit...</string>
160 </property>
161 </widget>
162 </hbox>
163 </widget>
164 <widget>
165 <class>QTable</class>
166 <property stdset="1">
167 <name>name</name>
168 <cstring>tiletable</cstring>
169 </property>
170 </widget>
171 <widget>
172 <class>QLayoutWidget</class>
173 <property stdset="1">
174 <name>name</name>
175 <cstring>Layout3</cstring>
176 </property>
177 <hbox>
178 <property stdset="1">
179 <name>margin</name>
180 <number>0</number>
181 </property>
182 <property stdset="1">
183 <name>spacing</name>
184 <number>6</number>
185 </property>
186 <widget>
187 <class>QPushButton</class>
188 <property stdset="1">
189 <name>name</name>
190 <cstring>buttonDelete</cstring>
191 </property>
192 <property stdset="1">
193 <name>text</name>
194 <string>Delete</string>
195 </property>
196 <property stdset="1">
197 <name>autoDefault</name>
198 <bool>true</bool>
199 </property>
200 </widget>
201 <spacer>
202 <property>
203 <name>name</name>
204 <cstring>Horizontal Spacing2</cstring>
205 </property>
206 <property stdset="1">
207 <name>orientation</name>
208 <enum>Horizontal</enum>
209 </property>
210 <property stdset="1">
211 <name>sizeType</name>
212 <enum>Expanding</enum>
213 </property>
214 <property>
215 <name>sizeHint</name>
216 <size>
217 <width>20</width>
218 <height>20</height>
219 </size>
220 </property>
221 </spacer>
222 <widget>
223 <class>QPushButton</class>
224 <property stdset="1">
225 <name>name</name>
226 <cstring>buttonOk</cstring>
227 </property>
228 <property stdset="1">
229 <name>text</name>
230 <string>&amp;OK</string>
231 </property>
232 <property stdset="1">
233 <name>autoDefault</name>
234 <bool>true</bool>
235 </property>
236 <property stdset="1">
237 <name>default</name>
238 <bool>true</bool>
239 </property>
240 </widget>
241 <widget>
242 <class>QPushButton</class>
243 <property stdset="1">
244 <name>name</name>
245 <cstring>buttonCancel</cstring>
246 </property>
247 <property stdset="1">
248 <name>text</name>
249 <string>&amp;Cancel</string>
250 </property>
251 <property stdset="1">
252 <name>autoDefault</name>
253 <bool>true</bool>
254 </property>
255 </widget>
256 </hbox>
257 </widget>
258 </vbox>
259</widget>
260<connections>
261 <connection>
262 <sender>buttonOk</sender>
263 <signal>clicked()</signal>
264 <receiver>RulesBase</receiver>
265 <slot>accept()</slot>
266 </connection>
267 <connection>
268 <sender>buttonCancel</sender>
269 <signal>clicked()</signal>
270 <receiver>RulesBase</receiver>
271 <slot>reject()</slot>
272 </connection>
273</connections>
274</UI>
diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp
new file mode 100644
index 0000000..ca4352d
--- a/dev/null
+++ b/noncore/games/wordgame/wordgame.cpp
@@ -0,0 +1,1476 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#include "wordgame.h"
23
24#include <qpe/applnk.h>
25#include <qpe/global.h>
26#include <qpe/filemanager.h>
27#include <qpe/resource.h>
28#include <qpe/config.h>
29
30#include <qapplication.h>
31#include <qmessagebox.h>
32#include <qcombobox.h>
33#include <qdatetime.h>
34#include <qfileinfo.h>
35#include <qfile.h>
36#include <qdir.h>
37#include <qiconset.h>
38#include <qlabel.h>
39#include <qlineedit.h>
40#include <qpushbutton.h>
41#include <qtextstream.h>
42#include <qtimer.h>
43#include <qpe/qpetoolbar.h>
44#include <qtoolbutton.h>
45#include <qvbox.h>
46#include <qwidgetstack.h>
47#include <qpainter.h>
48#include <qlayout.h>
49#include <qregexp.h>
50
51#include <stdlib.h>
52#include <unistd.h>
53#include <pwd.h>
54#include <sys/types.h>
55
56enum RuleEffects {
57 Multiplier=15,
58 MultiplyAll=64,
59 Start=128
60};
61
62static const int rack_tiles=7;
63
64const char* sampleWGR=
65 "wordgame_shapes\n"
66 "15 15\n"
67 "400001040100004\n"
68 "030000000000030\n"
69 "002002000200200\n"
70 "000300020003000\n"
71 "000020000020000\n"
72 "102001000100201\n"
73 "000000202000000\n"
74 "400200050002004\n"
75 "000000202000000\n"
76 "102001000100201\n"
77 "000020000020000\n"
78 "000300020003000\n"
79 "002002000200200\n"
80 "030000000000030\n"
81 "400001040100004\n"
82 "1 2 3 66 67 194 100 0\n"
83 "1 j 8\n"
84 "1 q 7\n"
85 "1 x 6\n"
86 "1 z 6\n"
87 "1 w 4\n"
88 "1 k 4\n"
89 "1 v 3\n"
90 "1 f 3\n"
91 "2 y 3\n"
92 "2 h 2\n"
93 "2 b 2\n"
94 "2 m 2\n"
95 "3 p 2\n"
96 "3 g 2\n"
97 "3 u 2\n"
98 "4 d 2\n"
99 "4 c 2\n"
100 "5 l 1\n"
101 "5 o 1\n"
102 "7 t 1\n"
103 "7 n 1\n"
104 "7 a 1\n"
105 "7 r 1\n"
106 "8 s 1\n"
107 "8 i 1\n"
108 "11 e 1\n"
109 "0\n";
110
111WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) :
112 QMainWindow(parent, name, fl)
113{
114 setIcon( Resource::loadPixmap( "wordgame" ) );
115 setCaption( tr("Word Game") );
116
117 setToolBarsMovable( FALSE );
118 vbox = new QVBox(this);
119
120 setCentralWidget(vbox);
121 toolbar = new QPEToolBar(this);
122 addToolBar(toolbar, Bottom);
123 reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar);
124 done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar);
125 scoreinfo = new ScoreInfo(toolbar);
126 scoreinfo->setFont(QFont("Helvetica",10));
127 new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar);
128 toolbar->setStretchableWidget(scoreinfo);
129
130 cpu = 0;
131 board = 0;
132 bag = 0;
133 racks = 0;
134
135 aiheart = new QTimer(this);
136 connect(aiheart, SIGNAL(timeout()), this, SLOT(think()));
137
138 readConfig();
139}
140
141WordGame::~WordGame()
142{
143 writeConfig();
144}
145
146void WordGame::writeConfig()
147{
148 Config cfg("WordGame");
149 cfg.setGroup("Game");
150 cfg.writeEntry("NameList",namelist,';');
151 cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1);
152 if ( !gameover ) {
153 cfg.writeEntry("Rules",rules);
154 bag->writeConfig(cfg);
155 board->writeConfig(cfg);
156 scoreinfo->writeConfig(cfg);
157 }
158 for (int p=0; p<nplayers; p++) {
159 cfg.setGroup("Player"+QString::number(p+1));
160 if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg);
161 }
162}
163
164void WordGame::readConfig()
165{
166 Config cfg("WordGame");
167 cfg.setGroup("Game");
168 int currentplayer = cfg.readNumEntry("CurrentPlayer",0);
169 QStringList pnames = cfg.readListEntry("NameList",';');
170 if ( currentplayer ) {
171 gameover = FALSE;
172 rules = cfg.readEntry("Rules");
173 if ( rules.find("x-wordgamerules") >= 0 ) {
174 // rules files moved
175 rules = "Sample.rules";
176 }
177 if ( loadRules(rules) ) {
178 startGame(pnames);
179 bag->readConfig(cfg);
180 board->readConfig(cfg);
181 scoreinfo->readConfig(cfg);
182 for (int p=0; p<nplayers; p++) {
183 cfg.setGroup("Player"+QString::number(p+1));
184 rack(p)->readConfig(cfg);
185 }
186 player=currentplayer-1;
187 readyRack(player);
188 return;
189 }
190 }
191 // fall-back
192 openGameSelector(pnames);
193}
194
195void WordGame::openGameSelector(const QStringList& initnames)
196{
197 toolbar->hide();
198 gameover = FALSE;
199
200 delete board;
201 board = 0;
202 delete racks;
203 racks = 0;
204
205 delete cpu;
206 cpu = 0;
207
208 newgame = new NewGame(vbox);
209
210 //Rules rules(this);
211 //connect(game.editrules, SIGNAL(clicked()), &rules, SLOT(editRules()));
212 //connect(&rules, SIGNAL(rulesChanged()), &game, SLOT(updateRuleSets()));
213 struct passwd* n = getpwuid(getuid());
214 QString playername = n ? n->pw_name : "";
215 if ( playername.isEmpty() ) {
216 playername = "Player";
217 }
218 newgame->player0->changeItem(playername,0);
219 newgame->player1->setCurrentItem(1);
220 newgame->updateRuleSets();
221 newgame->show();
222
223 connect(newgame->buttonOk, SIGNAL(clicked()), this, SLOT(startGame()));
224}
225
226void WordGame::startGame()
227{
228 rules = newgame->ruleslist[newgame->rules->currentItem()];
229 if ( loadRules(rules) ) {
230 QStringList names;
231 names.append(newgame->player0->currentText());
232 names.append(newgame->player1->currentText());
233 names.append(newgame->player2->currentText());
234 names.append(newgame->player3->currentText());
235 names.append(newgame->player4->currentText());
236 names.append(newgame->player5->currentText());
237 delete newgame;
238 startGame(names);
239 } else {
240 // error...
241 delete newgame;
242 close();
243 }
244}
245
246void WordGame::startGame(const QStringList& playerlist)
247{
248 toolbar->show();
249 racks = new QWidgetStack(vbox);
250 namelist.clear();
251 nplayers=0;
252 for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it)
253 addPlayer(*it);
254 scoreinfo->init(namelist);
255
256 if ( nplayers ) {
257 player=0;
258 readyRack(player);
259 }
260
261 board->show();
262 racks->show();
263}
264
265bool WordGame::loadRules(const QString &name)
266{
267 QString filename = Global::applicationFileName( "wordgame", name );
268 QFile file( filename );
269 if ( !file.open( IO_ReadOnly ) )
270 return FALSE;
271
272 QTextStream ts( &file );
273
274 QString title = name;
275 title.truncate( title.length() - 6 );
276 setCaption( title );
277
278 QString shapepixmap;
279 ts >> shapepixmap;
280 int htiles,vtiles;
281 ts >> htiles >> vtiles;
282
283 if ( htiles < 3 || vtiles < 3 )
284 return FALSE;
285
286 QPixmap bgshapes = Resource::loadPixmap(shapepixmap);
287 QString rule_shapes;
288 for (int i=0; i<vtiles; i++) {
289 QString line;
290 ts >> line;
291 rule_shapes += line;
292 }
293 static int rule_effects[12];
294 int re=0,e;
295 ts >> e;
296 while ( e && re < 10 ) {
297 rule_effects[re] = e;
298 if ( re++ < 10 ) ts >> e;
299 }
300 rule_effects[re++] = 100; // default bonus
301 board = new Board(bgshapes, htiles, vtiles, vbox);
302 board->setRules(rule_shapes, rule_effects);
303 connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int)));
304
305 bag = new Bag;
306
307 int count;
308 ts >> count;
309 while ( count ) {
310 QString text;
311 int value;
312 ts >> text >> value;
313 if ( text == "_" )
314 text = "";
315
316 Tile t(text, value);
317 for (int n=count; n--; )
318 bag->add(t);
319
320 ts >> count;
321 }
322
323 return TRUE;
324}
325
326
327NewGame::NewGame(QWidget* parent) :
328 NewGameBase(parent)
329{
330}
331
332void NewGame::updateRuleSets()
333{
334 rules->clear();
335
336 QString rulesDir = Global::applicationFileName( "wordgame", "" );
337 QDir dir( rulesDir, "*.rules" );
338 ruleslist = dir.entryList();
339 if ( ruleslist.isEmpty() ) {
340 // Provide a sample
341 QFile file( rulesDir + "Sample.rules" );
342 if ( file.open( IO_WriteOnly ) ) {
343 file.writeBlock( sampleWGR, strlen(sampleWGR) );
344 file.close();
345 updateRuleSets();
346 }
347 return;
348 }
349 int newest=0;
350 int newest_age=INT_MAX;
351 QDateTime now = QDateTime::currentDateTime();
352 QStringList::Iterator it;
353 for ( it = ruleslist.begin(); it != ruleslist.end(); ++it ) {
354 QFileInfo fi((*it));
355 int age = fi.lastModified().secsTo(now);
356 QString name = *it;
357 name.truncate( name.length()-6 ); // remove extension
358 rules->insertItem( name );
359 if ( age < newest_age ) {
360 newest_age = age;
361 newest = rules->count()-1;
362 }
363 }
364 rules->setCurrentItem(newest);
365}
366
367Rules::Rules(QWidget* parent) :
368 RulesBase(parent,0,TRUE)
369{
370}
371
372void Rules::editRules()
373{
374 if ( exec() ) {
375 // ### create a new set of rules
376 emit rulesChanged();
377 }
378}
379
380void Rules::deleteRuleSet()
381{
382 // ### delete existing rule set
383 emit rulesChanged();
384}
385
386void WordGame::addPlayer(const QString& name)
387{
388 if ( !name.isEmpty() ) {
389 int colon = name.find(':');
390 int cpu = (colon >=0 && name.left(2) == "AI") ? name.mid(2,1).toInt() : 0;
391 addPlayer(name,cpu);
392 }
393}
394
395void WordGame::addPlayer(const QString& name, int cpu)
396{
397 Rack* r = new Rack(rack_tiles,racks);
398 r->setPlayerName(name);
399 r->setComputerization(cpu);
400 racks->addWidget(r, nplayers);
401 refillRack(nplayers);
402 namelist.append(name);
403
404 ++nplayers;
405}
406
407void WordGame::nextPlayer()
408{
409 if ( !refillRack(player) ) {
410 endGame();
411 } else {
412 player = (player+1)%nplayers;
413 scoreinfo->setBoldOne(player);
414 readyRack(player);
415 }
416}
417
418bool WordGame::mayEndGame()
419{
420 int out=-1;
421 int i;
422 for (i=0; i<nplayers; i++)
423 if ( !rack(i)->count() )
424 out = i;
425 if ( out<0 ) {
426 if ( QMessageBox::warning(this,tr("End game"),
427 tr("Do you want to end the game early?"),
428 tr("Yes"), tr("No") )!=0 )
429 {
430 return FALSE;
431 }
432 }
433 return TRUE;
434}
435
436void WordGame::endGame()
437{
438 if ( gameover ) {
439 close();
440 return;
441 }
442
443 if ( !mayEndGame() )
444 return;
445 int out=-1;
446 int totalleft=0;
447 int i;
448 for (i=0; i<nplayers; i++) {
449 Rack* r = rack(i);
450 int c = r->count();
451 if ( c ) {
452 int lose=0;
453 for ( int j=0; j<c; j++ )
454 lose += r->tileRef(j)->value();
455 totalleft += lose;
456 scoreinfo->addScore(i,-lose);
457 } else {
458 out = i;
459 }
460 }
461 int highest=0;
462 int winner=0;
463 for (i=0; i<nplayers; i++) {
464 int s = scoreinfo->playerScore(i);
465 if ( s > highest ) {
466 highest = s;
467 winner = i;
468 }
469 }
470 if ( out >= 0 )
471 scoreinfo->addScore(out,totalleft);
472 scoreinfo->setBoldOne(winner);
473 gameover = TRUE;
474 done->setEnabled(TRUE);
475 reset->setEnabled(FALSE);
476}
477
478void WordGame::endTurn()
479{
480 if ( gameover ) {
481 openGameSelector(namelist);
482 } else {
483 if ( board->checkTurn() ) {
484 if ( board->turnScore() >= 0 ) {
485 scoreinfo->addScore(player,board->turnScore());
486 board->finalizeTurn();
487 } else {
488 QApplication::beep();
489 }
490 nextPlayer();
491 }
492 }
493}
494
495void WordGame::resetTurn()
496{
497 board->resetRack();
498}
499
500void WordGame::passTurn()
501{
502 // ######## trade?
503 nextPlayer();
504}
505
506bool WordGame::refillRack(int i)
507{
508 Rack* r = rack(i);
509 while ( !bag->isEmpty() && !r->isFull() ) {
510 r->addTile(bag->takeRandom());
511 }
512 return r->count() != 0;
513}
514
515void WordGame::readyRack(int i)
516{
517 Rack* r = rack(i);
518 racks->raiseWidget(i);
519 board->setCurrentRack(r);
520
521 done->setEnabled( !r->computerized() );
522 reset->setEnabled( !r->computerized() );
523
524 if ( r->computerized() ) {
525 cpu = new ComputerPlayer(board, r);
526 aiheart->start(0);
527 }
528}
529
530Rack* WordGame::rack(int i) const
531{
532 return (Rack*)racks->widget(i);
533}
534
535void WordGame::think()
536{
537 if ( !cpu->step() ) {
538 delete cpu;
539 cpu = 0;
540 aiheart->stop();
541 if ( board->turnScore() < 0 )
542 passTurn();
543 else
544 endTurn();
545 }
546}
547
548ComputerPlayer::ComputerPlayer(Board* b, Rack* r) :
549 board(b), rack(r), best(new const Tile*[rack_tiles]),
550 best_blankvalues(new Tile[rack_tiles])
551{
552 best_score = -1;
553 across=FALSE;
554 dict=0;
555}
556
557ComputerPlayer::~ComputerPlayer()
558{
559 delete [] best;
560 delete [] best_blankvalues;
561}
562
563bool ComputerPlayer::step()
564{
565 const QDawg::Node* root = dict ? Global::dawg("WordGame").root()
566 : Global::fixedDawg().root();
567 QPoint d = across ? QPoint(1,0) : QPoint(0,1);
568 const Tile* tiles[99]; // ### max board size
569 uchar nletter[4095]; // QDawg only handles 0..4095
570 memset(nletter,0,4096);
571 for (int i=0; i<rack->count(); i++) {
572 const Tile* r = rack->tileRef(i);
573 if ( r->isBlank() )
574 nletter[0]++;
575 else
576 nletter[r->text()[0].unicode()]++;
577 }
578 Tile blankvalues[99]; // ### max blanks
579 findBest(current, d, root, 0, nletter, tiles, 0, blankvalues, 0);
580 if ( ++current.rx() == board->xTiles() ) {
581 current.rx() = 0;
582 if ( ++current.ry() == board->yTiles() ) {
583 if ( across ) {
584 if ( dict == 1 ) {
585 if ( best_score >= 0 ) {
586 rack->arrangeTiles(best,best_n);
587 rack->setBlanks(best_blankvalues);
588 board->scoreTurn(best_start, best_n, best_dir);
589 board->showTurn();
590 }
591 return FALSE;
592 }
593 dict++;
594 across = FALSE;
595 current = QPoint(0,0);
596 } else {
597 across = TRUE;
598 current = QPoint(0,0);
599 }
600 }
601 }
602 return TRUE;
603}
604
605void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar* nletter, const Tile** tiles, int n, Tile* blankvalues, int blused)
606{
607 if ( !node )
608 return;
609 QChar l = node->letter();
610 const Tile* cur = board->tile(at);
611 if ( cur ) {
612 if ( cur->text()[0] == l ) {
613 bool nextok = board->contains(at+d);
614 if ( node->isWord() && n && (!nextok || !board->tile(at+d)) )
615 noteChoice(tiles,n,d,blankvalues,blused);
616 if ( nextok )
617 findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused);
618 // #### text()[1]...
619 }
620 } else {
621 if ( nletter[l.unicode()] || nletter[0] ) {
622 int rc = rack->count();
623 ulong msk = 1;
624 for ( int x=0; x<rc; x++ ) {
625 if ( !(used&msk) ) {
626 const Tile* t = rack->tileRef(x);
627 if ( t->isBlank() || t->text() == l ) { // #### multi-char value()s
628 bool nextok = board->contains(at+d);
629 tiles[n++] = t;
630 if ( t->isBlank() )
631 blankvalues[blused++] = Tile(l,0);
632 if ( node->isWord() && (!nextok || !board->tile(at+d)) )
633 noteChoice(tiles,n,d,blankvalues,blused);
634 used |= msk; // mark
635 nletter[t->text()[0].unicode()]--;
636 if ( nextok )
637 findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused);
638 n--;
639 nletter[t->text()[0].unicode()]++;
640 if ( t->isBlank() ) {
641 // keep looking
642 blused--;
643 used &= ~msk; // unmark
644 } else {
645 break;
646 }
647 }
648 }
649 msk <<= 1;
650 }
651 }
652 // #### text()[1]...
653 }
654 findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused);
655}
656
657void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused)
658{
659 int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0);
660/*
661if (s>0 || current==QPoint(5,1)){
662QString st;
663for ( int i=0; i<n; i++ )
664 st += tiles[i]->text();
665qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s);
666}
667*/
668 if ( s > best_score ) {
669 int i;
670 for ( i=0; i<n; i++ )
671 best[i] = tiles[i];
672 for ( i=0; i<blused; i++ )
673 best_blankvalues[i] = blankvalues[i];
674 best_n = n;
675 best_blused = blused;
676 best_score = s;
677 best_dir = d;
678 best_start = current;
679 }
680}
681
682int TileItem::smallWidth()
683{
684 return 16;
685}
686
687int TileItem::smallHeight()
688{
689 return 16;
690}
691
692int TileItem::bigWidth()
693{
694 return 22;
695}
696
697int TileItem::bigHeight()
698{
699 return 22;
700}
701
702void TileItem::setState( State state )
703{
704 hide();
705 s = state;
706 show(); // ### use update() in Qt 3.0
707}
708
709void TileItem::setTile(const Tile& tile)
710{
711 hide();
712 t = tile;
713 show(); // ### use update() in Qt 3.0
714}
715
716void TileItem::setBig(bool b)
717{
718 big = b;
719}
720
721void TileItem::drawShape(QPainter& p)
722{
723 static QFont value_font("heletica",8);
724 static QFont big_font("smoothtimes",17);
725 static QFont small_font("smoothtimes",10);
726
727 QRect area(x(),y(),width(),height());
728 p.setBrush(s == Floating ? yellow/*lightGray*/ : white);
729 p.drawRect(area);
730 if ( big ) {
731 p.setFont(value_font);
732 QString n = QString::number(t.value());
733 int w = p.fontMetrics().width('1');
734 int h = p.fontMetrics().height();
735 w *= n.length();
736 QRect valuearea(x()+width()-w-2,y()+height()-h+1,w,h);
737 p.drawText(valuearea,AlignCenter,n);
738 p.setFont(big_font);
739 area = QRect(x(),y(),width()-2,height()-1);
740 } else {
741 p.setFont(small_font);
742 area = QRect(x(),y()+2,width(),height()-2);
743 }
744 if ( t.value() == 0 )
745 p.setPen(darkGray);
746 p.drawText(area,AlignCenter,t.text().upper());
747}
748
749Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) :
750 QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()),
751 parent)
752{
753 grid = new TileItem*[w*h];
754 memset(grid,0,w*h*sizeof(TileItem*));
755 setFrameStyle(0);
756 setHScrollBarMode(AlwaysOff);
757 setVScrollBarMode(AlwaysOff);
758 current_rack = 0;
759 shown_n = 0;
760}
761
762Board::~Board()
763{
764 delete canvas();
765}
766
767void Board::writeConfig(Config& cfg)
768{
769 QStringList t;
770 int n=canvas()->tilesHorizontally()*canvas()->tilesVertically();
771 for (int i=0; i<n; i++)
772 t.append( grid[i] ? grid[i]->tile().key() : QString(".") );
773 cfg.writeEntry("Board",t,';');
774}
775
776void Board::readConfig(Config& cfg)
777{
778 clear();
779 QStringList t = cfg.readListEntry("Board",';');
780 int i=0;
781 int h=canvas()->tilesHorizontally();
782 for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it) {
783 if ( *it != "." ) {
784 QPoint p(i%h,i/h);
785 setTile(p,Tile(*it));
786 }
787 i++;
788 }
789 canvas()->update();
790}
791
792void Board::clear()
793{
794 int n=canvas()->tilesHorizontally()*canvas()->tilesVertically();
795 for (int i=0; i<n; i++) {
796 delete grid[i];
797 grid[i]=0;
798 }
799}
800
801
802void Board::setCurrentRack(Rack* r)
803{
804 turn_score = -1;
805 current_rack = r;
806}
807
808void Board::resetRack()
809{
810 unshowTurn();
811 canvas()->update();
812}
813
814void Board::contentsMousePressEvent(QMouseEvent* e)
815{
816 dragstart = e->pos();
817}
818
819void Board::contentsMouseMoveEvent(QMouseEvent* e)
820{
821 if ( current_rack && !current_rack->computerized() ) {
822 QPoint d = e->pos() - dragstart;
823 if ( d.x() <= 0 && d.y() <= 0 ) {
824 // None
825 resetRack();
826 } else {
827 int n;
828 QPoint start=boardPos(dragstart);
829 QPoint end=boardPos(e->pos());
830 QPoint diff=end-start;
831 QPoint dir;
832 if ( d.x() > d.y() ) {
833 n = diff.x()+1;
834 dir = QPoint(1,0);
835 } else {
836 n = diff.y()+1;
837 dir = QPoint(0,1);
838 }
839
840 unshowTurn();
841
842 // Subtract existing tiles from n
843 QPoint t = start;
844 for ( int i=n; i--; ) {
845 if ( contains(t) && tile(t) )
846 n--;
847 t += dir;
848 }
849
850 // Move start back to real start
851 while (contains(start-dir) && tile(start-dir))
852 start -= dir;
853
854 scoreTurn(start, n, dir);
855 showTurn();
856 }
857 }
858}
859
860void Board::finalizeTurn()
861{
862 int i=0;
863 QPoint at = shown_at;
864 while ( i<shown_n && contains(at) ) {
865 if ( item(at) && item(at)->state() == TileItem::Floating ) {
866 current_rack->remove(item(at)->tile());
867 setTileState(at,TileItem::Firm);
868 i++;
869 }
870 at += shown_step;
871 }
872 canvas()->update();
873}
874
875void Board::unshowTurn()
876{
877 int i=0;
878 QPoint at = shown_at;
879 while ( i<shown_n && i<current_rack->count() && contains(at) ) {
880 if ( item(at) && item(at)->state() == TileItem::Floating ) {
881 unsetTile(at);
882 i++;
883 }
884 at += shown_step;
885 }
886}
887
888void Board::showTurn()
889{
890 unshowTurn();
891 QPoint at = shown_at;
892 int i=0;
893 while ( i<shown_n && i<current_rack->count() && contains(at) ) {
894 if ( !tile(at) ) {
895 Tile t = current_rack->tile(i);
896 setTile(at,t);
897 setTileState(at,TileItem::Floating);
898 i++;
899 }
900 at += shown_step;
901 }
902 canvas()->update();
903}
904
905int Board::bonussedValue(const QPoint& at, int base, int& all_mult) const
906{
907 int rule = rule_shape[idx(at)]-'0';
908 int effect = rule_effect[rule];
909 int mult = effect&Multiplier;
910 if ( effect & MultiplyAll ) {
911 all_mult *= mult;
912 return base;
913 } else {
914 return base * mult;
915 }
916}
917
918bool Board::isStart(const QPoint& at) const
919{
920 int rule = rule_shape[idx(at)]-'0';
921 int effect = rule_effect[rule];
922 return effect&Start;
923}
924
925bool Board::checkTurn()
926{
927 if ( current_rack->computerized() )
928 return TRUE; // computer doesn't cheat, and has already set blanks.
929
930 QPoint at = shown_at;
931 int n = shown_n;
932 QPoint d = shown_step;
933 const Tile* tiles[99];
934 Tile blankvalues[99];
935 if ( n > current_rack->count() )
936 n = current_rack->count();
937
938 QDialog check(this,0,TRUE);
939 (new QVBoxLayout(&check))->setAutoAdd(TRUE);
940
941 QHBox mw(&check);
942 new QLabel(tr("Blanks: "),&mw);
943
944 int bl=0;
945 QLineEdit* le[99];
946 for (int i=0; i<n; i++) {
947 tiles[i] = current_rack->tileRef(i);
948 if ( tiles[i]->isBlank() ) {
949 QLineEdit *l = new QLineEdit(&mw);
950 le[bl++] = l;
951 l->setMaxLength(1);
952 l->setFixedSize(l->minimumSizeHint());
953 }
954 }
955
956 QHBox btns(&check);
957 connect(new QPushButton(tr("OK"),&btns), SIGNAL(clicked()), &check, SLOT(accept()));
958 connect(new QPushButton(tr("Cancel"),&btns), SIGNAL(clicked()), &check, SLOT(reject()));
959
960 if ( bl ) {
961retry:
962 if ( !check.exec() ) {
963 unshowTurn();
964 canvas()->update();
965 return FALSE;
966 }
967
968 for (int b=0; b<bl; b++) {
969 QString v = le[b]->text();
970 blankvalues[b]=Tile(v,0);
971 if ( v.length() != 1 )
972 goto retry;
973 }
974 }
975
976 QStringList words;
977 unshowTurn();
978 turn_score = score(at,tiles,n,blankvalues,d,FALSE,&words);
979 showTurn();
980 QStringList to_add;
981 for (QStringList::Iterator it=words.begin(); it!=words.end(); ++it) {
982 if ( !Global::fixedDawg().contains(*it)
983 && !Global::dawg("WordGame").contains(*it) ) {
984 switch (QMessageBox::warning(this, tr("Unknown word"),
985 tr("<p>The word \"%1\" is not in the dictionary.").arg(*it),
986 tr("Add"), tr("Ignore"), tr("Cancel")))
987 {
988 case 0:
989 // ####### add to wordgame dictionary
990 to_add.append(*it);
991 break;
992 case 1:
993 break;
994 case 2:
995 unshowTurn();
996 canvas()->update();
997 return FALSE;
998 }
999 }
1000 }
1001 if ( to_add.count() )
1002 Global::addWords("WordGame",to_add);
1003 return TRUE;
1004}
1005
1006void Board::scoreTurn(const QPoint& at, int n, const QPoint& d)
1007{
1008 unshowTurn();
1009 shown_at = at;
1010 shown_n = n;
1011 shown_step = d;
1012 const Tile* tiles[99];
1013 if ( n > current_rack->count() )
1014 n = current_rack->count();
1015 for (int i=0; i<n; i++)
1016 tiles[i] = current_rack->tileRef(i);
1017 turn_score = score(at,tiles,n,0,d,FALSE,0);
1018 emit temporaryScore(turn_score);
1019}
1020
1021int Board::score(QPoint at, const Tile** tiles, int n, const Tile* blankvalue, const QPoint& d, bool checkdict, QStringList* words) const
1022{
1023 int total=0;
1024 int totalsidetotal=0;
1025
1026 // words gets filled with words made
1027
1028 // mainword==0 ->
1029 // Checks side words, but not main word
1030
1031 // -1 means words not in dict, or illegally positioned (eg. not connected)
1032
1033 // text is assumed to fit on board.
1034
1035 if ( words ) *words=QStringList();
1036
1037 QPoint otherd(d.y(), d.x());
1038
1039 int all_mult = 1;
1040 int bl=0;
1041
1042 bool connected = FALSE;
1043
1044 QString mainword="";
1045
1046 if ( contains(at-d) && tile(at-d) ) {
1047 return -1; // preceeding tiles
1048 }
1049
1050 const Tile* t;
1051 for (int i=0; contains(at) && ((t=tile(at)) || i<n); ) {
1052 if ( t ) {
1053 if ( checkdict || words ) mainword += t->text();
1054 total += t->value();
1055 connected = TRUE;
1056 } else {
1057 QString sideword;
1058 QString tt;
1059 if ( tiles[i]->isBlank() ) {
1060 if ( blankvalue )
1061 tt = blankvalue[bl++].text();
1062 } else {
1063 tt = tiles[i]->text();
1064 }
1065 sideword=tt;
1066 if ( checkdict || words ) mainword += tt;
1067 int side_mult = 1;
1068 int tilevalue = bonussedValue(at,tiles[i]->value(),side_mult);
1069 all_mult *= side_mult;
1070 if ( !connected && isStart(at) )
1071 connected = TRUE;
1072 total += tilevalue;
1073 int sidetotal = tilevalue;
1074 {
1075 QPoint side = at-otherd;
1076
1077 while ( contains(side) && (t=tile(side)) ) {
1078 sidetotal += t->value();
1079 sideword.prepend(t->text());
1080 side -= otherd;
1081 }
1082 }
1083 {
1084 QPoint side = at+otherd;
1085 while ( contains(side) && (t=tile(side)) ) {
1086 sidetotal += t->value();
1087 sideword.append(t->text());
1088 side += otherd;
1089 }
1090 }
1091 if ( sideword.length() > 1 ) {
1092 if ( words )
1093 words->append(sideword);
1094 if ( checkdict && !Global::fixedDawg().contains(sideword)
1095 && !Global::dawg("WordGame").contains(sideword) )
1096 return -1;
1097 totalsidetotal += sidetotal * side_mult;
1098 connected = TRUE;
1099 }
1100 i++;
1101 }
1102 at += d;
1103 }
1104
1105 if ( words )
1106 words->append(mainword);
1107 if ( checkdict && !Global::fixedDawg().contains(mainword)
1108 && !Global::dawg("WordGame").contains(mainword) )
1109 return -1;
1110
1111 if ( n == rack_tiles )
1112 totalsidetotal += rack_tiles_bonus;
1113
1114 return connected ? totalsidetotal + total * all_mult : -1;
1115}
1116
1117QPoint Board::boardPos(const QPoint& p) const
1118{
1119 return QPoint(p.x()/canvas()->tileWidth(), p.y()/canvas()->tileHeight());
1120}
1121
1122void Board::contentsMouseReleaseEvent(QMouseEvent*)
1123{
1124 if ( current_rack ) {
1125 }
1126}
1127
1128
1129void Board::setRules(const QString& shapes, const int* effects)
1130{
1131 rule_shape=shapes; rule_effect=effects;
1132 int i=0;
1133 int maxre=0;
1134 for (int y=0; y<yTiles(); y++) {
1135 for (int x=0; x<xTiles(); x++) {
1136 int re = shapes[i++]-'0';
1137 if ( re > maxre ) maxre = re;
1138 canvas()->setTile(x,y,re);
1139 }
1140 }
1141 rack_tiles_bonus=effects[maxre+1];
1142}
1143
1144void Board::unsetTile(const QPoint& p)
1145{
1146 delete item(p);
1147 grid[idx(p)] = 0;
1148}
1149
1150void Board::setTile(const QPoint& p, const Tile& t)
1151{
1152 TileItem* it=item(p);
1153 if ( !it ) {
1154 it = grid[idx(p)] = new TileItem(t,FALSE,canvas());
1155 it->move(p.x()*canvas()->tileWidth(), p.y()*canvas()->tileHeight());
1156 it->show();
1157 } else {
1158 it->setTile(t);
1159 }
1160}
1161
1162Rack::Rack(int ntiles, QWidget* parent) : QCanvasView(
1163 new QCanvas(ntiles*TileItem::bigWidth(),TileItem::bigHeight()),
1164 parent),
1165 item(ntiles)
1166{
1167 setLineWidth(1);
1168 setFixedHeight(sizeHint().height());
1169 n = 0;
1170 for (int i=0; i<ntiles; i++)
1171 item[i]=0;
1172 setHScrollBarMode(AlwaysOff);
1173 setVScrollBarMode(AlwaysOff);
1174 canvas()->setBackgroundColor(gray);
1175 dragging = 0;
1176}
1177
1178Rack::~Rack()
1179{
1180 clear();
1181 delete canvas();
1182}
1183
1184void Rack::clear()
1185{
1186 for (int i=0; i<n; i++)
1187 delete item[i];
1188 n=0;
1189}
1190
1191void Rack::writeConfig(Config& cfg)
1192{
1193 QStringList l;
1194 for (int i=0; i<n; i++)
1195 l.append(tile(i).key());
1196 cfg.writeEntry("Tiles",l,';');
1197}
1198
1199void Rack::readConfig(Config& cfg)
1200{
1201 clear();
1202 int x=0;
1203 QStringList l = cfg.readListEntry("Tiles",';');
1204 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
1205 TileItem *i = new TileItem(Tile(*it),TRUE,canvas());
1206 i->move(x++,0);
1207 i->show();
1208 item[n++] = i;
1209 }
1210 layoutTiles();
1211}
1212
1213static int cmp_tileitem(const void *a, const void *b)
1214{
1215 const TileItem* ia = *(TileItem**)a;
1216 const TileItem* ib = *(TileItem**)b;
1217 return int(ia->x() - ib->x());
1218}
1219
1220void Rack::layoutTiles()
1221{
1222 int w = TileItem::bigWidth()+2;
1223
1224 if ( dragging ) dragging->moveBy(dragging_adj,0);
1225 qsort(item.data(), n, sizeof(TileItem*), cmp_tileitem);
1226 if ( dragging ) dragging->moveBy(-dragging_adj,0);
1227
1228 for (int i=0; i<n ;i++)
1229 if ( item[i] == dragging ) {
1230 item[i]->setZ(1);
1231 } else {
1232 item[i]->move(i*w, 0);
1233 item[i]->setZ(0);
1234 }
1235 canvas()->update();
1236}
1237
1238void Rack::setBlanks(const Tile* bv)
1239{
1240 for (int j=0; j<n; j++) {
1241 Tile tt = item[j]->tile();
1242 if ( tt.isBlank() ) {
1243 tt.setText(bv->text());
1244 item[j]->setTile(tt);
1245 bv++;
1246 }
1247 }
1248}
1249
1250bool Rack::arrangeTiles(const Tile** s, int sn)
1251{
1252 bool could = TRUE;
1253 for (int j=0; j<n; j++) {
1254 Tile tt = item[j]->tile();
1255 int f=-1;
1256 for (int i=0; i<sn && f<0; i++) {
1257 if (s[i] && *s[i] == tt ) {
1258 s[i]=0;
1259 f=i;
1260 }
1261 }
1262 if ( f >= 0 ) {
1263 item[j]->move(f-999,0);
1264 } else {
1265 could = FALSE;
1266 }
1267 }
1268 layoutTiles();
1269 return could;
1270}
1271
1272void Rack::addTile(const Tile& t)
1273{
1274 TileItem *i = new TileItem(t,TRUE,canvas());
1275 i->show();
1276 item[n++] = i;
1277 layoutTiles();
1278}
1279
1280void Rack::remove(Tile t)
1281{
1282 for (int i=0; i<n ;i++)
1283 if ( item[i]->tile() == t ) {
1284 remove(i);
1285 return;
1286 }
1287}
1288
1289void Rack::remove(int i)
1290{
1291 delete item[i];
1292 n--;
1293 for (;i<n;i++)
1294 item[i]=item[i+1];
1295 layoutTiles();
1296}
1297
1298void Rack::resizeEvent(QResizeEvent* e)
1299{
1300 canvas()->resize(width()-frameWidth()*2,height()-frameWidth()*2);
1301 QCanvasView::resizeEvent(e);
1302}
1303
1304void Rack::contentsMousePressEvent(QMouseEvent* e)
1305{
1306 if ( computerized() )
1307 return;
1308 QCanvasItemList list = canvas()->collisions(e->pos());
1309 if (list.count()) {
1310 dragging = list.first();
1311 dragstart = e->pos()-QPoint(int(dragging->x()),int(dragging->y()));
1312 } else {
1313 dragging = 0;
1314 }
1315}
1316
1317void Rack::contentsMouseMoveEvent(QMouseEvent* e)
1318{
1319 if ( computerized() )
1320 return;
1321 //int w = TileItem::bigWidth()+2;
1322 if ( dragging ) {
1323 dragging_adj = TileItem::bigWidth()/2;
1324 if ( dragging->x() > e->x()-dragstart.x() )
1325 dragging_adj = -dragging_adj;
1326 dragging->move(e->x()-dragstart.x(),0);
1327 layoutTiles();
1328 }
1329}
1330
1331void Rack::contentsMouseReleaseEvent(QMouseEvent* e)
1332{
1333 if ( computerized() )
1334 return;
1335 if ( dragging ) {
1336 dragging=0;
1337 layoutTiles();
1338 }
1339}
1340
1341Tile::Tile(const QString& key)
1342{
1343 int a=key.find('@');
1344 txt = key.left(a);
1345 val = key.mid(a+1).toInt();
1346 blank = txt.isEmpty();
1347}
1348
1349QString Tile::key() const
1350{
1351 return txt+"@"+QString::number(val);
1352}
1353
1354Bag::Bag()
1355{
1356 tiles.setAutoDelete(TRUE);
1357}
1358
1359void Bag::writeConfig(Config& cfg)
1360{
1361 QStringList t;
1362 for (QListIterator<Tile> it(tiles); it; ++it)
1363 t.append((*it)->key());
1364 cfg.writeEntry("Tiles",t,';');
1365}
1366
1367void Bag::readConfig(Config& cfg)
1368{
1369 tiles.clear();
1370 QStringList t = cfg.readListEntry("Tiles",';');
1371 for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it )
1372 add(Tile(*it));
1373}
1374
1375void Bag::add(const Tile& t)
1376{
1377 tiles.append(new Tile(t));
1378}
1379
1380Tile Bag::takeRandom()
1381{
1382 Tile* rp = tiles.take(random()%tiles.count());
1383 Tile r=*rp;
1384 return r;
1385}
1386
1387ScoreInfo::ScoreInfo( QWidget* parent, const char* name, WFlags fl ) :
1388 QLabel("<P>",parent,name,fl)
1389{
1390 score=0;
1391 msgtimer = new QTimer(this);
1392 connect(msgtimer, SIGNAL(timeout()), this, SLOT(showScores()));
1393 setBackgroundMode( PaletteButton );
1394}
1395
1396ScoreInfo::~ScoreInfo()
1397{
1398 if ( score ) delete [] score;
1399}
1400
1401void ScoreInfo::writeConfig(Config& cfg)
1402{
1403 QStringList l;
1404 for (int i=0; i<(int)names.count(); i++)
1405 l.append(QString::number(score[i]));
1406 cfg.writeEntry("Scores",l,';');
1407}
1408
1409void ScoreInfo::readConfig(Config& cfg)
1410{
1411 QStringList l = cfg.readListEntry("Scores",';');
1412 int i=0;
1413 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it )
1414 score[i++]=(*it).toInt();
1415 showScores();
1416}
1417
1418
1419QSize ScoreInfo::sizeHint() const
1420{
1421 return QSize(QLabel::sizeHint().width(),fontMetrics().height());
1422}
1423
1424void ScoreInfo::init(const QStringList& namelist)
1425{
1426 names = namelist;
1427 if ( score ) delete [] score;
1428 score = new int[names.count()];
1429 memset(score,0,sizeof(int)*names.count());
1430 boldone = -1;
1431 showScores();
1432}
1433
1434void ScoreInfo::addScore(int player, int change)
1435{
1436 score[player] += change;
1437 showScores();
1438}
1439
1440void ScoreInfo::setBoldOne(int b)
1441{
1442 boldone=b;
1443 showScores();
1444}
1445
1446void ScoreInfo::showScores()
1447{
1448 QString r="<p>";
1449 int i=0;
1450 //int spl=(names.count()+1)/2; // 2 lines
1451 for (QStringList::ConstIterator it=names.begin(); it!=names.end(); ) {
1452 if ( i==boldone ) r += "<b>";
1453 QString n = *it;
1454 n.replace(QRegExp(":.*"),"");
1455 r += n;
1456 r += ":";
1457 r += QString::number(score[i]);
1458 if ( i==boldone ) r += "</b>";
1459
1460 ++i;
1461 ++it;
1462 if ( it != names.end() )
1463 r += " ";
1464 }
1465 setText(r);
1466}
1467
1468void ScoreInfo::showTemporaryScore(int amount)
1469{
1470 if ( amount < 0 )
1471 setText(tr("<P>Invalid move"));
1472 else
1473 setText(tr("<P>Score: ")+QString::number(amount));
1474 msgtimer->start(3000,TRUE);
1475}
1476
diff --git a/noncore/games/wordgame/wordgame.h b/noncore/games/wordgame/wordgame.h
new file mode 100644
index 0000000..0ffa56a
--- a/dev/null
+++ b/noncore/games/wordgame/wordgame.h
@@ -0,0 +1,376 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef WORDGAME_H
21#define WORDGAME_H
22
23#include "newgamebase.h"
24#include "rulesbase.h"
25
26#include <qpe/qdawg.h>
27#include <qpe/applnk.h>
28
29#include <qmainwindow.h>
30#include <qcanvas.h>
31#include <qlabel.h>
32
33class QVBox;
34class QLabel;
35class QWidgetStack;
36class QToolButton;
37class Config;
38
39class Tile {
40public:
41 Tile() {}
42
43 Tile(const Tile& t)
44 {
45 txt = t.txt;
46 val = t.val;
47 blank = t.blank;
48 }
49
50 Tile(QString text, int value)
51 {
52 txt = text;
53 val = value;
54 blank = txt.isEmpty();
55 }
56
57 Tile(const QString& key);
58
59 int value() const { return val; }
60 bool isBlank() const { return blank; }
61 QString text() const { return txt; }
62 void setText(const QString& t)
63 {
64 txt = t;
65 }
66
67 int operator==(const Tile& o) const
68 { return o.txt == txt && o.val == val && o.blank == blank; }
69 int operator!=(const Tile& o) const
70 { return !operator==(o); }
71 Tile& operator=(const Tile& o)
72 { txt=o.txt; val=o.val; blank=o.blank; return *this; }
73
74 QString key() const;
75
76private:
77 QString txt;
78 int val;
79 bool blank;
80};
81
82class Bag {
83public:
84 Bag();
85
86 void readConfig(Config&);
87 void writeConfig(Config&);
88
89 void add(const Tile&);
90 bool isEmpty() const { return tiles.isEmpty(); }
91 Tile takeRandom();
92private:
93 QList<Tile> tiles;
94};
95
96class TileItem : public QCanvasRectangle {
97public:
98 TileItem(const Tile& tile, bool b, QCanvas* c) :
99 QCanvasRectangle(0,0,
100 b?bigWidth():smallWidth(),
101 b?bigHeight():smallHeight(),c),
102 t(tile), big(b), s(Firm)
103 {
104 }
105
106 static int smallWidth();
107 static int smallHeight();
108 static int bigWidth();
109 static int bigHeight();
110
111 enum State { Firm, Floating };
112 void setState( State state );
113 State state() const { return s; }
114 const Tile& tile() const { return t; }
115 void setTile(const Tile&);
116 void setBig(bool);
117
118protected:
119 void drawShape(QPainter&);
120
121private:
122 Tile t;
123 bool big;
124 State s;
125};
126
127class Rack : public QCanvasView {
128public:
129 Rack(int ntiles, QWidget* parent);
130 ~Rack();
131
132 void readConfig(Config&);
133 void writeConfig(Config&);
134
135 bool isFull() const { return count()==max(); }
136 int max() const { return item.count(); }
137 int count() const { return n; }
138 void addTile(const Tile& t);
139 Tile tile(int i) const { return item[i]->tile(); }
140 const Tile* tileRef(int i) const { return &item[i]->tile(); }
141 void remove(int i);
142 void remove(Tile);
143 bool arrangeTiles(const Tile** s, int sn);
144 void setBlanks(const Tile*);
145
146 void setPlayerName(const QString& name) { nm = name; }
147 QString playerName() const { return nm; }
148 void setComputerization(int level) { cpu=level; }
149 bool computerized() const { return cpu>0; }
150
151protected:
152 void resizeEvent(QResizeEvent*e);
153 void contentsMousePressEvent(QMouseEvent*);
154 void contentsMouseMoveEvent(QMouseEvent*);
155 void contentsMouseReleaseEvent(QMouseEvent*);
156
157private:
158 void clear();
159 void layoutTiles();
160 int n;
161 QArray<TileItem*> item;
162 int dragging_adj;
163 QPoint dragstart;
164 QCanvasItem* dragging;
165 QString nm;
166 int cpu;
167};
168
169class Board : public QCanvasView {
170 Q_OBJECT
171public:
172 Board(QPixmap bgshapes, int w, int h, QWidget* parent);
173 ~Board();
174
175 void readConfig(Config&);
176 void writeConfig(Config&);
177
178 int xTiles() const { return canvas()->tilesHorizontally(); }
179 int yTiles() const { return canvas()->tilesVertically(); }
180
181 bool contains(const QPoint& p) const
182 { return p.x() >= 0 && p.y() >= 0
183 && p.x() < canvas()->tilesHorizontally()
184 && p.y() < canvas()->tilesVertically(); }
185 const Tile* tile(const QPoint& p) const
186 { TileItem* it=item(p); return it ? &it->tile() : 0; }
187
188 void setRules(const QString& shapes, const int* effects);
189
190 void clear();
191 void unsetTile(const QPoint& p);
192 void setTile(const QPoint& p, const Tile& t);
193
194 void setTileState(const QPoint& p, TileItem::State s)
195 {
196 TileItem* it=item(p);
197 if (it) it->setState(s);
198 }
199
200 void setCurrentRack(Rack*);
201 void resetRack();
202 void finalizeTurn();
203 void showTurn();
204 void scoreTurn(const QPoint& at, int n, const QPoint& d);
205 bool checkTurn();
206 int score(QPoint at, const Tile** tiles, int n,
207 const Tile* blankvalue,
208 const QPoint& d, bool ignoredict, QStringList* words) const;
209 int bonussedValue(const QPoint& at, int base, int& all_mult) const;
210 bool isStart(const QPoint& at) const;
211
212 int turnScore() const { return turn_score; }
213
214signals:
215 void temporaryScore(int);
216
217protected:
218 void contentsMousePressEvent(QMouseEvent*);
219 void contentsMouseMoveEvent(QMouseEvent*);
220 void contentsMouseReleaseEvent(QMouseEvent*);
221
222private:
223 int idx(const QPoint& p) const
224 { return p.x()+p.y()*canvas()->tilesHorizontally(); }
225 TileItem*& item(const QPoint& p) const
226 { return grid[idx(p)]; }
227 TileItem **grid;
228 QString rule_shape;
229 const int* rule_effect;
230 int rack_tiles_bonus;
231 Rack* current_rack;
232 QPoint boardPos(const QPoint&) const;
233 QPoint dragstart;
234 QPoint shown_at;
235 int shown_n;
236 QPoint shown_step;
237 void unshowTurn();
238 int turn_score;
239};
240
241class ComputerPlayer
242{
243 Board* board;
244 Rack* rack;
245
246 bool across;
247 int dict;
248 QPoint current;
249
250 const Tile** best;
251 int best_n;
252 Tile* best_blankvalues;
253 int best_blused;
254 int best_score;
255 QPoint best_dir;
256 QPoint best_start;
257
258public:
259 ComputerPlayer(Board* b, Rack* r);
260 ~ComputerPlayer();
261
262 bool step();
263
264private:
265 void findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar *nletter, const Tile** tiles, int n, Tile* blankvalues, int blused);
266 void noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused);
267};
268
269class ScoreInfo : public QLabel {
270 Q_OBJECT
271public:
272 ScoreInfo( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
273 ~ScoreInfo();
274
275 void init(const QStringList&);
276 void addScore(int player, int change);
277 int playerScore(int player) const { return score[player]; }
278 void setShowWinner(bool);
279 void setBoldOne(int);
280
281 void readConfig(Config&);
282 void writeConfig(Config&);
283
284protected:
285 QSize sizeHint() const;
286
287public slots:
288 void showTemporaryScore(int amount);
289
290private slots:
291 void showScores();
292
293private:
294 QStringList names;
295 int *score;
296 QTimer* msgtimer;
297 bool showwinner;
298 int boldone;
299};
300
301class NewGame;
302
303class WordGame : public QMainWindow {
304 Q_OBJECT
305public:
306 WordGame( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
307 ~WordGame();
308
309private slots:
310 void endTurn();
311 void resetTurn();
312 void passTurn();
313 void think();
314 void endGame();
315 void startGame();
316
317private:
318 void writeConfig();
319 void readConfig();
320
321 void startGame(const QStringList& pnames);
322 bool mayEndGame();
323 void openGameSelector(const QStringList& initnames);
324 bool loadRules(const QString& filename);
325 void addPlayer(const QString& name);
326 void addPlayer(const QString& name, int cpu);
327 void nextPlayer();
328 bool refillRack(int i);
329 void readyRack(int i);
330 Rack* rack(int i) const;
331
332 QWidgetStack *racks;
333 QToolBar* toolbar;
334 QVBox *vbox;
335 Board *board;
336 Bag *bag;
337 ScoreInfo *scoreinfo;
338 QToolButton *done;
339 QToolButton *reset;
340 QTimer* aiheart;
341 ComputerPlayer *cpu;
342 int player;
343 int nplayers;
344 QStringList namelist;
345 bool gameover;
346 QString rules;
347 NewGame* newgame;
348};
349
350class NewGame : public NewGameBase {
351 Q_OBJECT
352public:
353 NewGame(QWidget* parent);
354 QStringList ruleslist;
355
356public slots:
357 void updateRuleSets();
358};
359
360class Rules : public RulesBase {
361 Q_OBJECT
362
363public:
364 Rules(QWidget* parent);
365
366signals:
367 void rulesChanged();
368
369public slots:
370 void editRules();
371
372private:
373 void deleteRuleSet();
374};
375
376#endif // WORDGAME_H
diff --git a/noncore/games/wordgame/wordgame.pro b/noncore/games/wordgame/wordgame.pro
new file mode 100644
index 0000000..7feacf9
--- a/dev/null
+++ b/noncore/games/wordgame/wordgame.pro
@@ -0,0 +1,13 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 DESTDIR = $(QPEDIR)/bin
4 HEADERS = wordgame.h
5 SOURCES = main.cpp \
6 wordgame.cpp
7 INTERFACES= newgamebase.ui rulesbase.ui
8 TARGET = wordgame
9INCLUDEPATH += $(QPEDIR)/include
10 DEPENDPATH+= $(QPEDIR)/include
11LIBS += -lqpe
12
13TRANSLATIONS = ../i18n/de/wordgame.ts
diff --git a/noncore/multimedia/showimg/.cvsignore b/noncore/multimedia/showimg/.cvsignore
new file mode 100644
index 0000000..f0a4beb
--- a/dev/null
+++ b/noncore/multimedia/showimg/.cvsignore
@@ -0,0 +1,2 @@
1Makefile
2moc_*
diff --git a/noncore/multimedia/showimg/Makefile.in b/noncore/multimedia/showimg/Makefile.in
new file mode 100644
index 0000000..9255b2d
--- a/dev/null
+++ b/noncore/multimedia/showimg/Makefile.in
@@ -0,0 +1,119 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= showimg
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =showimg.h
27 SOURCES =main.cpp \
28 showimg.cpp
29 OBJECTS =main.o \
30 showimg.o
31INTERFACES =
32UICDECLS =
33UICIMPLS =
34 SRCMOC =moc_showimg.cpp
35 OBJMOC =moc_showimg.o
36
37
38####### Implicit rules
39
40.SUFFIXES: .cpp .cxx .cc .C .c
41
42.cpp.o:
43 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
44
45.cxx.o:
46 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
47
48.cc.o:
49 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
50
51.C.o:
52 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
53
54.c.o:
55 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
56
57####### Build rules
58
59
60all: $(DESTDIR)$(TARGET)
61
62$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
63 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
64
65moc: $(SRCMOC)
66
67tmake:
68 tmake showimg.pro
69
70clean:
71 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
72 -rm -f *~ core
73 -rm -f allmoc.cpp
74
75####### Extension Modules
76
77listpromodules:
78 @echo
79
80listallmodules:
81 @echo
82
83listaddonpromodules:
84 @echo
85
86listaddonentmodules:
87 @echo
88
89
90REQUIRES=showimg
91
92####### Sub-libraries
93
94
95###### Combined headers
96
97
98
99####### Compile
100
101main.o: main.cpp \
102 showimg.h \
103 $(QPEDIR)/include/qpe/qpeapplication.h
104
105showimg.o: showimg.cpp \
106 showimg.h \
107 $(QPEDIR)/include/qpe/resource.h \
108 $(QPEDIR)/include/qpe/fileselector.h \
109 $(QPEDIR)/include/qpe/applnk.h \
110 $(QPEDIR)/include/qpe/qpemenubar.h \
111 $(QPEDIR)/include/qpe/qpetoolbar.h
112
113moc_showimg.o: moc_showimg.cpp \
114 showimg.h
115
116moc_showimg.cpp: showimg.h
117 $(MOC) showimg.h -o moc_showimg.cpp
118
119
diff --git a/noncore/multimedia/showimg/README b/noncore/multimedia/showimg/README
new file mode 100644
index 0000000..a6c9ca9
--- a/dev/null
+++ b/noncore/multimedia/showimg/README
@@ -0,0 +1,14 @@
1This example demonstrates how to read in and display images, and the
2conversion facilities available. The CuteWidget can read a file into
3a pixmap and resizes the displayed pixmap when the widget is resized.
4
5Note that the function CuteWidget::paintEvent uses the drawPixmap function
6of QPainter to display the pixmap, the bitBlt function can also be used to
7display pixmaps.
8
9If you have installed the Qt imageio extension (see extensions/imageio
10in your Qt directory), you can build using that extension.
11
12Some of the conversion options will have no effect, depending on the
13display hardware used. Generally, these are disabled.
14
diff --git a/noncore/multimedia/showimg/main.cpp b/noncore/multimedia/showimg/main.cpp
new file mode 100644
index 0000000..c28cc85
--- a/dev/null
+++ b/noncore/multimedia/showimg/main.cpp
@@ -0,0 +1,33 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "showimg.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char **argv )
26{
27 QPEApplication a( argc, argv );
28
29 ImageViewer w(0, "new window", Qt::WResizeNoErase );
30 a.showMainDocumentWidget(&w);
31
32 return a.exec();
33}
diff --git a/noncore/multimedia/showimg/qpe-showimg.control b/noncore/multimedia/showimg/qpe-showimg.control
new file mode 100644
index 0000000..8189048
--- a/dev/null
+++ b/noncore/multimedia/showimg/qpe-showimg.control
@@ -0,0 +1,10 @@
1Files: bin/showimg apps/Applications/showimg.desktop
2Priority: optional
3Section: qpe/applications
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Image Viewer
9 The image viewer for the Qtopia environment. Supports
10 Whichever formats are compiled into Qt/Embedded (eg. PNG).
diff --git a/noncore/multimedia/showimg/showimg.cpp b/noncore/multimedia/showimg/showimg.cpp
new file mode 100644
index 0000000..c56994d
--- a/dev/null
+++ b/noncore/multimedia/showimg/showimg.cpp
@@ -0,0 +1,557 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21//
22// Full-screen and rotation options contributed by Robert Wittams <robert@wittams.com>
23//
24
25#include "showimg.h"
26
27#include <qpe/resource.h>
28#include <qpe/fileselector.h>
29#include <qpe/applnk.h>
30
31#include <qpe/qpemenubar.h>
32#include <qwidgetstack.h>
33#include <qpe/qpetoolbar.h>
34#include <qaction.h>
35#include <qfiledialog.h>
36#include <qmessagebox.h>
37#include <qpopupmenu.h>
38#include <qlabel.h>
39#include <qpainter.h>
40#include <qkeycode.h>
41#include <qapplication.h>
42#include <qclipboard.h>
43#include <qtimer.h>
44
45
46ImagePane::ImagePane( QWidget *parent=0 ) : QWidget( parent )
47{
48 vb = new QVBoxLayout( this );
49
50 image = new ImageWidget( this );
51 connect(image, SIGNAL( clicked() ), this, SLOT( imageClicked() ));
52
53 vb->addWidget( image );
54
55 status = new QLabel( this );
56 status->setFixedHeight( fontMetrics().height() + 4 );
57 vb->addWidget( status );
58}
59
60void ImagePane::setPixmap( const QPixmap &pm )
61{
62 image->setPixmap( pm );
63 image->repaint( false );
64}
65
66void ImagePane::imageClicked()
67{
68 emit clicked();
69}
70
71void ImagePane::showStatus()
72{
73 delete vb;
74 vb = new QVBoxLayout( this );
75 vb->addWidget( image );
76 status->show();
77 vb->addWidget( status );
78}
79
80
81void ImagePane::hideStatus()
82{
83 delete vb;
84 vb = new QVBoxLayout( this );
85 vb->addWidget( image );
86 status->hide();
87}
88
89//===========================================================================
90/*
91 Draws the portion of the scaled pixmap that needs to be updated
92*/
93
94void ImageWidget::paintEvent( QPaintEvent *e )
95{
96 QPainter painter(this);
97
98 painter.setClipRect(e->rect());
99 painter.setBrush( black );
100 painter.drawRect( 0, 0, width(), height() );
101
102 if ( pixmap.size() != QSize( 0, 0 ) ) { // is an image loaded?
103 painter.drawPixmap((width() - pixmap.width()) / 2, (height() - pixmap.height()) / 2, pixmap);
104 }
105}
106
107void ImageWidget::mouseReleaseEvent(QMouseEvent *)
108{
109 emit clicked();
110}
111
112
113//===========================================================================
114
115ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
116 : QMainWindow( parent, name, wFlags ), filename( 0 ),
117 pickx( -1 ), picky( -1 ), clickx( -1 ), clicky( -1 ), bFromDocView( FALSE )
118{
119 setCaption( tr("Image Viewer") );
120 setIcon( Resource::loadPixmap( "ImageViewer" ) );
121
122 isFullScreen = FALSE;
123
124 setToolBarsMovable( FALSE );
125
126 toolBar = new QPEToolBar( this );
127 toolBar->setHorizontalStretchable( TRUE );
128
129 menubar = new QPEMenuBar( toolBar );
130
131 QStrList fmt = QImage::outputFormats();
132
133 QPopupMenu *edit = new QPopupMenu( menubar );
134 QPopupMenu *view = new QPopupMenu( menubar );
135
136 menubar->insertItem( "Edit", edit );
137 menubar->insertItem( "View", view );
138
139 edit->insertItem(tr("Horizontal flip"), this, SLOT(hFlip()), 0);
140 edit->insertItem(tr("Vertical flip"), this, SLOT(vFlip()), 0);
141
142 stack = new QWidgetStack( this );
143 stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
144 setCentralWidget( stack );
145
146 imagePanel = new ImagePane( stack );
147 connect(imagePanel, SIGNAL(clicked()), this, SLOT(normalView()));
148
149 fileSelector = new FileSelector("image/*", stack, "fs");
150 fileSelector->setNewVisible(FALSE);
151 fileSelector->setCloseVisible(FALSE);
152 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( closeFileSelector() ) );
153 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) );
154
155 toolBar = new QPEToolBar( this );
156
157 QAction *a;
158
159 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
160 connect( a, SIGNAL( activated() ), this, SLOT( open() ) );
161 a->addTo( toolBar );
162
163 a = new QAction( tr( "Rotate 180" ), Resource::loadPixmap( "repeat" ), QString::null, 0, this, 0 );
164 connect( a, SIGNAL( activated() ), this, SLOT( rot180() ) );
165 a->addTo( toolBar );
166 a->addTo( edit );
167
168 a = new QAction( tr( "Rotate 90"), Resource::loadPixmap( "rotate90" ), QString::null, 0, this, 0);
169 connect( a, SIGNAL( activated() ), this, SLOT( rot90() ) );
170 a->addTo( toolBar );
171 a->addTo( edit );
172
173 a = new QAction( tr( "Fullscreen" ), Resource::loadPixmap( "fullscreen" ), QString::null, 0, this, 0 );
174 connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) );
175 a->addTo( toolBar );
176 a->addTo( view);
177
178 stack->raiseWidget( fileSelector );
179
180 setMouseTracking( TRUE );
181}
182
183ImageViewer::~ImageViewer()
184{
185 delete imagePanel; // in case it is fullscreen
186}
187
188void ImageViewer::setDocument(const QString& fileref)
189{
190 delayLoad = fileref;
191 stack->raiseWidget(imagePanel);
192 QTimer::singleShot( 0, this, SLOT(doDelayedLoad()) );
193}
194
195void ImageViewer::doDelayedLoad()
196{
197 show(delayLoad);
198}
199
200void ImageViewer::show()
201{
202 normalView();
203 QMainWindow::show();
204}
205
206void ImageViewer::show(const QString& fileref)
207{
208 bFromDocView = TRUE;
209 closeFileSelector();
210 DocLnk link(fileref);
211 if ( link.isValid() ) {
212 openFile(link);
213 } else {
214 filename = fileref;
215 updateCaption( fileref );
216 loadImage( fileref );
217 }
218}
219
220void ImageViewer::openFile( const DocLnk &file )
221{
222 closeFileSelector();
223 DocLnk link(file);
224 updateCaption( link.name() );
225 loadImage( link.file() );
226}
227
228void ImageViewer::open()
229{
230 stack->raiseWidget(fileSelector);
231}
232
233void ImageViewer::closeFileSelector()
234{
235 stack->raiseWidget(imagePanel);
236}
237
238void ImageViewer::updateCaption( QString name )
239{
240 int sep = name.findRev( '/' );
241 if ( sep >= 0 )
242 name = name.mid( sep+1 );
243 setCaption( name + tr(" - Image Viewer") );
244}
245
246/*
247 This function loads an image from a file.
248*/
249
250void ImageViewer::loadImage( const char *fileName )
251{
252 filename = fileName;
253 if ( filename ) {
254 QApplication::setOverrideCursor( waitCursor ); // this might take time
255 imagePanel->statusLabel()->setText( tr("Loading image...") );
256 qApp->processEvents();
257 bool ok = image.load(filename, 0);
258 pickx = -1;
259 clickx = -1;
260 if ( ok )
261 ok = reconvertImage();
262 if ( !ok ) {
263 pm.resize(0,0); // couldn't load image
264 update();
265 }
266 QApplication::restoreOverrideCursor();// restore original cursor
267 }
268 updateStatus();
269 imagePanel->setPixmap( pmScaled );
270 stack->raiseWidget(imagePanel);
271}
272
273bool ImageViewer::loadSelected()
274{
275 bool ok = false;
276 if ( stack->visibleWidget() == fileSelector ) {
277 const DocLnk *link = fileSelector->selected();
278 if ( link ) {
279 if ( link->file() != filename ) {
280 updateCaption( link->name() );
281 filename = link->file();
282 imagePanel->statusLabel()->setText( tr("Loading image...") );
283 qApp->processEvents();
284 ok = image.load(filename, 0);
285 if ( ok )
286 ok = reconvertImage();
287 if ( !ok )
288 pm.resize(0,0);
289 }
290 }
291 }
292 if ( !image.isNull() ) {
293 ok = true;
294 closeFileSelector();
295 }
296
297 return ok;
298}
299
300bool ImageViewer::reconvertImage()
301{
302 bool success = FALSE;
303
304 if ( image.isNull() ) return FALSE;
305
306 QApplication::setOverrideCursor( waitCursor ); // this might take time
307 if ( pm.convertFromImage(image /*, conversion_flags */ ) )
308 {
309 pmScaled = QPixmap();
310 scale();
311 success = TRUE; // load successful
312 } else {
313 pm.resize(0,0); // couldn't load image
314 }
315 QApplication::restoreOverrideCursor();// restore original cursor
316
317 return success; // TRUE if loaded OK
318}
319
320
321int ImageViewer::calcHeight()
322{
323 if ( !isFullScreen)
324 return height() - menubar->heightForWidth( width() )
325 - imagePanel->statusLabel()->height();
326 else
327 return qApp->desktop()->height();
328}
329/*
330 This functions scales the pixmap in the member variable "pm" to fit the
331 widget size and puts the resulting pixmap in the member variable "pmScaled".
332*/
333
334void ImageViewer::scale()
335{
336 int h = calcHeight();
337 if ( image.isNull() ) return;
338
339 QApplication::setOverrideCursor( waitCursor ); // this might take time
340 if ( width() == pm.width() && h == pm.height() ) { // no need to scale if widget
341 pmScaled = pm; // size equals pixmap size
342 } else {
343 double hs = (double)h / (double)image.height();
344 double ws = (double)width() / (double)image.width();
345 double scaleFactor = (hs > ws) ? ws : hs;
346 int smoothW = (int)(scaleFactor * image.width());
347 int smoothH = (int)(scaleFactor * image.height());
348
349 pmScaled.convertFromImage( image.smoothScale( smoothW, smoothH ) /*, conversion_flags */ );
350 }
351 QApplication::restoreOverrideCursor();// restore original cursor
352}
353
354/*
355 The resize event handler, if a valid pixmap was loaded it will call
356 scale() to fit the pixmap to the new widget size.
357*/
358
359void ImageViewer::resizeEvent( QResizeEvent * )
360{
361 imagePanel->statusLabel()->setGeometry(0, height() - imagePanel->statusLabel()->height(),
362 width(), imagePanel->statusLabel()->height());
363
364 if ( pm.size() == QSize( 0, 0 ) ) // we couldn't load the image
365 return;
366
367 int h = calcHeight();
368
369 if ( width() != pmScaled.width() || h != pmScaled.height())
370 { // if new size,
371 scale(); // scale pmScaled to window
372 updateStatus();
373 }
374 if ( image.hasAlphaBuffer() )
375 erase();
376}
377
378void ImageViewer::convertEvent( QMouseEvent* e, int& x, int& y)
379{
380 if ( pm.size() != QSize( 0, 0 ) ) {
381 int h = height() - menubar->heightForWidth( width() ) - imagePanel->statusLabel()->height();
382 int nx = e->x() * image.width() / width();
383 int ny = (e->y()-menubar->heightForWidth( width() )) * image.height() / h;
384 if (nx != x || ny != y ) {
385 x = nx;
386 y = ny;
387 updateStatus();
388 }
389 }
390}
391
392void ImageViewer::mousePressEvent( QMouseEvent *e )
393{
394 convertEvent(e, clickx, clicky);
395}
396
397void ImageViewer::mouseMoveEvent( QMouseEvent *e )
398{
399 convertEvent( e, pickx, picky );
400}
401
402void ImageViewer::hFlip()
403{
404 if ( loadSelected() )
405 setImage(image.mirror(TRUE,FALSE));
406}
407
408void ImageViewer::vFlip()
409{
410 if ( loadSelected() )
411 setImage(image.mirror(FALSE,TRUE));
412}
413
414void ImageViewer::rot180()
415{
416 if ( loadSelected() )
417 setImage(image.mirror(TRUE,TRUE));
418}
419
420void ImageViewer::rot90()
421{
422 if ( loadSelected() ) {
423 QImage oldimage, newimage;
424 uchar *oldbits, *newbits;
425 int i, j, p;
426 int w, h;
427
428 oldimage = image.convertDepth(32);
429 w = oldimage.height();
430 h = oldimage.width();
431 newimage = QImage( w, h, 32);
432
433 oldbits = oldimage.bits();
434 newbits = newimage.bits();
435
436 for (i=0; i < w ; i++)
437 for (j=0; j < h; j++)
438 for (p = 0 ; p < 4 ; p++)
439 newbits[(j * w + i) * 4 + p] = oldbits[ ((i + 1) * h - j ) * 4 + p];
440
441 setImage(newimage);
442 }
443}
444
445
446
447void ImageViewer::normalView()
448{
449 if ( !imagePanel->parentWidget() ) {
450 isFullScreen = FALSE;
451 stack->addWidget( imagePanel, 1 );
452 //imagePanel->reparent(stack,0,QPoint(0,0),FALSE);
453 //imagePanel->resize(width(), calcHeight());
454 scale();
455 updateStatus();
456 imagePanel->setPixmap( pmScaled );
457 imagePanel->showStatus();
458 //imagePanel->show();
459 stack->raiseWidget( imagePanel );
460 }
461}
462
463void ImageViewer::fullScreen()
464{
465 // Full-screen and rotation options
466 // contributed by Robert Wittams <robert@wittams.com>
467
468 if ( imagePanel->parentWidget() && loadSelected() ) {
469 isFullScreen = TRUE;
470 imagePanel->reparent(0,QPoint(0,0));
471 imagePanel->resize(qApp->desktop()->width(), qApp->desktop()->height());
472
473 scale();
474 updateStatus();
475 imagePanel->hideStatus();
476 imagePanel->setPixmap( pmScaled );
477 imagePanel->showFullScreen();
478 }
479}
480
481void ImageViewer::setImage(const QImage& newimage)
482{
483 image = newimage;
484 pickx = -1;
485 clickx = -1;
486 reconvertImage();
487 imagePanel->setPixmap( pmScaled );
488 updateStatus();
489}
490
491void ImageViewer::updateStatus()
492{
493 if ( pm.size() == QSize( 0, 0 ) ) {
494 if ( filename )
495 imagePanel->statusLabel()->setText( tr("Could not load image") );
496 else
497 imagePanel->statusLabel()->setText( tr("No image - select Open from File menu.") );
498 } else {
499 QString message("%1x%2");
500 message = message.arg(image.width()).arg(image.height());
501 if ( pm.size() != pmScaled.size() )
502 message += QString(" [%1x%2]").arg(pmScaled.width()).arg(pmScaled.height());
503 if (image.valid(pickx,picky)) {
504 QString moremsg;
505 moremsg.sprintf("(%d,%d)=#%0*x ",
506 pickx, picky,
507 image.hasAlphaBuffer() ? 8 : 6,
508 image.pixel(pickx,picky));
509 message += moremsg;
510 }
511 if ( image.numColors() > 0 ) {
512 if (image.valid(pickx,picky)) {
513 message += tr(", %1/%2 colors")
514 .arg(image.pixelIndex(pickx,picky))
515 .arg(image.numColors());
516 } else {
517 message += tr(", %1 colors").arg(image.numColors());
518 }
519 } else if ( image.depth() >= 16 ) {
520 message += tr(" True color");
521 }
522 if ( image.hasAlphaBuffer() ) {
523 if ( image.depth() == 8 ) {
524 int i;
525 bool alpha[256];
526 int nalpha=0;
527
528 for (i=0; i<256; i++)
529 alpha[i] = FALSE;
530
531 for (i=0; i<image.numColors(); i++) {
532 int alevel = image.color(i) >> 24;
533 if (!alpha[alevel]) {
534 alpha[alevel] = TRUE;
535 nalpha++;
536 }
537 }
538 message += tr(", %1 alpha levels").arg(nalpha);
539 } else {
540 // Too many pixels to bother counting.
541 message += tr(", 8-bit alpha channel");
542 }
543 }
544 imagePanel->statusLabel()->setText(message);
545 }
546}
547
548void ImageViewer::closeEvent( QCloseEvent *e )
549{
550 if ( stack->visibleWidget() == imagePanel && !bFromDocView ) {
551 e->ignore();
552 open();
553 } else {
554 bFromDocView = FALSE;
555 e->accept();
556 }
557}
diff --git a/noncore/multimedia/showimg/showimg.h b/noncore/multimedia/showimg/showimg.h
new file mode 100644
index 0000000..71003b1
--- a/dev/null
+++ b/noncore/multimedia/showimg/showimg.h
@@ -0,0 +1,143 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef SHOWIMG_H
22#define SHOWIMG_H
23
24#include <qwidget.h>
25#include <qmainwindow.h>
26#include <qimage.h>
27#include <qlabel.h>
28#include <qlayout.h>
29
30
31class QMenuBar;
32class QPopupMenu;
33class QWidgetStack;
34class FileSelector;
35class DocLnk;
36
37
38class ImageWidget : public QWidget
39{
40 Q_OBJECT
41public:
42 ImageWidget( QWidget *parent=0 ) : QWidget( parent ) { }
43 ~ImageWidget() { }
44
45 void setPixmap( const QPixmap &pm ) { pixmap = pm; }
46
47signals:
48 void clicked();
49
50protected:
51 void paintEvent( QPaintEvent * );
52 void mouseReleaseEvent(QMouseEvent* event);
53
54private:
55 QPixmap pixmap;
56};
57
58
59class ImagePane : public QWidget
60{
61 Q_OBJECT
62public:
63 ImagePane( QWidget *parent=0 );
64 ~ImagePane() { }
65
66 void showStatus();
67 void hideStatus();
68 QLabel *statusLabel() { return status; }
69 void setPixmap( const QPixmap &pm );
70
71signals:
72 void clicked();
73
74private:
75 ImageWidget*image;
76 QLabel*status;
77 QVBoxLayout *vb;
78
79private slots:
80 void imageClicked();
81};
82
83
84class ImageViewer : public QMainWindow
85{
86 Q_OBJECT
87public:
88 ImageViewer( QWidget *parent=0, const char *name=0, int wFlags=0 );
89 ~ImageViewer();
90
91 void loadImage( const char *fileName );
92 void show(const QString& fileref);
93 void show();
94
95protected:
96 void resizeEvent( QResizeEvent * );
97 void mousePressEvent( QMouseEvent * );
98 void mouseMoveEvent( QMouseEvent * );
99 void closeEvent( QCloseEvent * );
100
101private:
102 void updateCaption( QString name );
103 bool loadSelected();
104 void scale();
105 void convertEvent( QMouseEvent* e, int& x, int& y );
106 bool reconvertImage();
107 int calcHeight();
108 void setImage(const QImage& newimage);
109 void updateStatus();
110
111private slots:
112 void setDocument(const QString& fileref);
113 void doDelayedLoad();
114 void openFile( const DocLnk &file );
115 void open();
116 void closeFileSelector();
117 void hFlip();
118 void vFlip();
119 void rot180();
120 void rot90();
121 void normalView();
122 void fullScreen();
123
124private:
125 QString filename;
126 QString delayLoad;
127 QImage image; // the loaded image
128 QPixmap pm; // the converted pixmap
129 QPixmap pmScaled; // the scaled pixmap
130 QMenuBar *menubar;
131 ImagePane *imagePanel;
132 QToolBar *toolBar;
133 QWidgetStack *stack;
134 FileSelector *fileSelector;
135 int pickx, picky;
136 int clickx, clicky;
137 bool isFullScreen;
138 bool bFromDocView; // a flag to indicate whether or not we were
139 // launched from the document view...
140};
141
142
143#endif // SHOWIMG_H
diff --git a/noncore/multimedia/showimg/showimg.pro b/noncore/multimedia/showimg/showimg.pro
new file mode 100644
index 0000000..a372f62
--- a/dev/null
+++ b/noncore/multimedia/showimg/showimg.pro
@@ -0,0 +1,19 @@
1TEMPLATE = app
2
3CONFIG += qt warn_on release
4DESTDIR = $(QPEDIR)/bin
5
6 HEADERS = showimg.h
7
8 SOURCES = main.cpp \
9 showimg.cpp
10
11TARGET = showimg
12
13INCLUDEPATH += $(QPEDIR)/include
14DEPENDPATH += $(QPEDIR)/include
15LIBS += -lqpe
16
17REQUIRES = showimg
18
19TRANSLATIONS = ../i18n/de/showimg.ts
diff --git a/noncore/settings/.cvsignore b/noncore/settings/.cvsignore
new file mode 100644
index 0000000..e3d8c4b
--- a/dev/null
+++ b/noncore/settings/.cvsignore
@@ -0,0 +1,13 @@
1moc_*
2*.moc
3Makefile
4appearancesettingsbase.h
5soundsettingsbase.h
6lightsettingsbase.h
7languagesettingsbase.cpp
8rotationsettingsbase.cpp
9appearancesettingsbase.cpp
10lightsettingsbase.cpp
11languagesettingsbase.h
12rotationsettingsbase.h
13soundsettingsbase.cpp
diff --git a/noncore/settings/language/.cvsignore b/noncore/settings/language/.cvsignore
new file mode 100644
index 0000000..30ff791
--- a/dev/null
+++ b/noncore/settings/language/.cvsignore
@@ -0,0 +1,4 @@
1moc_*
2Makefile
3languagesettingsbase.h
4languagesettingsbase.cpp
diff --git a/noncore/settings/language/Makefile.in b/noncore/settings/language/Makefile.in
new file mode 100644
index 0000000..2babf6e
--- a/dev/null
+++ b/noncore/settings/language/Makefile.in
@@ -0,0 +1,135 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../../bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= language
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =settings.h
27 SOURCES =language.cpp \
28 main.cpp
29 OBJECTS =language.o \
30 main.o \
31 languagesettingsbase.o
32INTERFACES = languagesettingsbase.ui
33UICDECLS = languagesettingsbase.h
34UICIMPLS = languagesettingsbase.cpp
35 SRCMOC =moc_settings.cpp \
36 moc_languagesettingsbase.cpp
37 OBJMOC =moc_settings.o \
38 moc_languagesettingsbase.o
39
40
41####### Implicit rules
42
43.SUFFIXES: .cpp .cxx .cc .C .c
44
45.cpp.o:
46 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
47
48.cxx.o:
49 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
50
51.cc.o:
52 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
53
54.C.o:
55 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
56
57.c.o:
58 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
59
60####### Build rules
61
62
63all: $(DESTDIR)$(TARGET)
64
65$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
66 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
67
68moc: $(SRCMOC)
69
70tmake:
71 tmake language.pro
72
73clean:
74 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
75 -rm -f *~ core
76 -rm -f allmoc.cpp
77
78####### Extension Modules
79
80listpromodules:
81 @echo
82
83listallmodules:
84 @echo
85
86listaddonpromodules:
87 @echo
88
89listaddonentmodules:
90 @echo
91
92
93REQUIRES=
94
95####### Sub-libraries
96
97
98###### Combined headers
99
100
101
102####### Compile
103
104language.o: language.cpp \
105 settings.h \
106 languagesettingsbase.h
107
108main.o: main.cpp \
109 settings.h \
110 languagesettingsbase.h
111
112languagesettingsbase.h: languagesettingsbase.ui
113 $(UIC) languagesettingsbase.ui -o $(INTERFACE_DECL_PATH)/languagesettingsbase.h
114
115languagesettingsbase.cpp: languagesettingsbase.ui
116 $(UIC) languagesettingsbase.ui -i languagesettingsbase.h -o languagesettingsbase.cpp
117
118languagesettingsbase.o: languagesettingsbase.cpp \
119 languagesettingsbase.h \
120 languagesettingsbase.ui
121
122moc_settings.o: moc_settings.cpp \
123 settings.h \
124 languagesettingsbase.h
125
126moc_languagesettingsbase.o: moc_languagesettingsbase.cpp \
127 languagesettingsbase.h
128
129moc_settings.cpp: settings.h
130 $(MOC) settings.h -o moc_settings.cpp
131
132moc_languagesettingsbase.cpp: languagesettingsbase.h
133 $(MOC) languagesettingsbase.h -o moc_languagesettingsbase.cpp
134
135
diff --git a/noncore/settings/language/language.cpp b/noncore/settings/language/language.cpp
new file mode 100644
index 0000000..397d372
--- a/dev/null
+++ b/noncore/settings/language/language.cpp
@@ -0,0 +1,150 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "settings.h"
22
23#include <qpe/global.h>
24#include <qpe/fontmanager.h>
25#include <qpe/config.h>
26#include <qpe/applnk.h>
27#include <qpe/qpedialog.h>
28#include <qpe/qpeapplication.h>
29#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
30#include <qpe/qcopenvelope_qws.h>
31#endif
32
33#include <qlabel.h>
34#include <qcheckbox.h>
35#include <qradiobutton.h>
36#include <qtabwidget.h>
37#include <qslider.h>
38#include <qfile.h>
39#include <qtextstream.h>
40#include <qdatastream.h>
41#include <qmessagebox.h>
42#include <qcombobox.h>
43#include <qspinbox.h>
44#include <qlistbox.h>
45#include <qdir.h>
46#if QT_VERSION >= 300
47#include <qstylefactory.h>
48#endif
49
50#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
51#include <unistd.h>
52#include <linux/fb.h>
53#include <sys/types.h>
54#include <sys/stat.h>
55#include <fcntl.h>
56#include <sys/ioctl.h>
57#endif
58#include <stdlib.h>
59
60
61LanguageSettings::LanguageSettings( QWidget* parent, const char* name, WFlags fl )
62 : LanguageSettingsBase( parent, name, TRUE, fl )
63{
64 if ( FontManager::hasUnicodeFont() )
65 languages->setFont(FontManager::unicodeFont(FontManager::Proportional));
66
67 QString tfn = QPEApplication::qpeDir()+"/i18n/";
68 QDir langDir = tfn;
69 QStringList list = langDir.entryList("*", QDir::Dirs );
70
71 QStringList::Iterator it;
72
73 for( it = list.begin(); it != list.end(); ++it ) {
74 QString name = (*it);
75 QFileInfo desktopFile( tfn + "/" + name + "/.directory" );
76 if( desktopFile.exists() ) {
77 langAvail.append(name);
78 Config conf( desktopFile.filePath(), Config::File );
79 QString langName = conf.readEntry( "Name" );
80 QString ownName = conf.readEntryDirect( "Name["+name+"]" );
81 if ( ownName.isEmpty() )
82 ownName = conf.readEntryDirect( "Name" );
83 if ( !ownName.isEmpty() && ownName != langName )
84 langName = langName + " [" + ownName + "]";
85 languages->insertItem( langName );
86
87 }
88 }
89
90 dl = new QPEDialogListener(this);
91 reset();
92}
93
94LanguageSettings::~LanguageSettings()
95{
96}
97
98void LanguageSettings::accept()
99{
100 applyLanguage();
101 QDialog::accept();
102}
103
104void LanguageSettings::applyLanguage()
105{
106 QString lang = langAvail.at( languages->currentItem() );
107 setLanguage( lang );
108}
109
110
111void LanguageSettings::reject()
112{
113 reset();
114 QDialog::reject();
115}
116
117void LanguageSettings::reset()
118{
119 QString l = getenv("LANG");
120 Config config("language");
121 l = config.readEntry( "Language", l );
122 if(l.isEmpty()) l = "en";
123 actualLanguage = l;
124
125 int n = langAvail.find( l );
126 languages->setCurrentItem( n );
127}
128
129QString LanguageSettings::actualLanguage;
130
131void LanguageSettings::setLanguage(const QString& lang)
132{
133 if( lang != actualLanguage ) {
134 Config config("locale");
135 config.setGroup( "Language" );
136 config.writeEntry( "Language", lang );
137 config.write();
138
139#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
140 QCopEnvelope e("QPE/System","language(QString)");
141 e << lang;
142#endif
143 }
144}
145
146void LanguageSettings::done(int r)
147{
148 QDialog::done(r);
149 close();
150}
diff --git a/noncore/settings/language/language.pro b/noncore/settings/language/language.pro
new file mode 100644
index 0000000..d1f1bf0
--- a/dev/null
+++ b/noncore/settings/language/language.pro
@@ -0,0 +1,12 @@
1 TEMPLATE= app
2 CONFIG += qt warn_on release
3 DESTDIR = ../../bin
4 HEADERS = settings.h
5 SOURCES = language.cpp main.cpp
6 INTERFACES= languagesettingsbase.ui
7INCLUDEPATH += $(QPEDIR)/include
8 DEPENDPATH+= ../$(QPEDIR)/include
9LIBS += -lqpe
10 TARGET = language
11
12TRANSLATIONS = ../../i18n/de/language.ts
diff --git a/noncore/settings/language/languagesettingsbase.ui b/noncore/settings/language/languagesettingsbase.ui
new file mode 100644
index 0000000..62bdafa
--- a/dev/null
+++ b/noncore/settings/language/languagesettingsbase.ui
@@ -0,0 +1,51 @@
1<!DOCTYPE UI><UI>
2<class>LanguageSettingsBase</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>LanguageSettingsBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>369</width>
15 <height>492</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Language</string>
21 </property>
22 <vbox>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget>
32 <class>QLabel</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>TextLabel1</cstring>
36 </property>
37 <property stdset="1">
38 <name>text</name>
39 <string>Select language</string>
40 </property>
41 </widget>
42 <widget>
43 <class>QListBox</class>
44 <property stdset="1">
45 <name>name</name>
46 <cstring>languages</cstring>
47 </property>
48 </widget>
49 </vbox>
50</widget>
51</UI>
diff --git a/noncore/settings/language/main.cpp b/noncore/settings/language/main.cpp
new file mode 100644
index 0000000..a760ff3
--- a/dev/null
+++ b/noncore/settings/language/main.cpp
@@ -0,0 +1,36 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "settings.h"
22
23#include <qpe/qpeapplication.h>
24
25
26int main(int argc, char** argv)
27{
28 QPEApplication a(argc,argv);
29
30 LanguageSettings dlg;
31
32 a.showMainWidget(&dlg);
33
34 return a.exec();
35}
36
diff --git a/noncore/settings/language/qpe-language.control b/noncore/settings/language/qpe-language.control
new file mode 100644
index 0000000..b33c947
--- a/dev/null
+++ b/noncore/settings/language/qpe-language.control
@@ -0,0 +1,9 @@
1Files: bin/language apps/Settings/Language.desktop
2Priority: optional
3Section: qpe/settings
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Language settings dialog
9 For the Qtopia environment.
diff --git a/noncore/settings/language/settings.h b/noncore/settings/language/settings.h
new file mode 100644
index 0000000..22cc987
--- a/dev/null
+++ b/noncore/settings/language/settings.h
@@ -0,0 +1,58 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef SETTINGS_H
21#define SETTINGS_H
22
23
24#include <qstrlist.h>
25#include <qasciidict.h>
26#include "languagesettingsbase.h"
27
28class QPEDialogListener;
29
30class LanguageSettings : public LanguageSettingsBase
31{
32 Q_OBJECT
33
34public:
35 LanguageSettings( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
36 ~LanguageSettings();
37
38protected:
39 void accept();
40 void reject();
41 void done(int);
42
43 QStrList langAvail;
44
45private slots:
46 void applyLanguage();
47 void reset();
48
49private:
50 static void setLanguage(const QString&);
51 static QString actualLanguage;
52
53 QPEDialogListener *dl;
54};
55
56
57#endif // SETTINGS_H
58
diff --git a/noncore/settings/sound/.cvsignore b/noncore/settings/sound/.cvsignore
new file mode 100644
index 0000000..ba1f2fe
--- a/dev/null
+++ b/noncore/settings/sound/.cvsignore
@@ -0,0 +1,5 @@
1Makefile
2moc_*
3*.moc
4soundsettingsbase.cpp
5soundsettingsbase.h
diff --git a/noncore/settings/sound/Makefile.in b/noncore/settings/sound/Makefile.in
new file mode 100644
index 0000000..1772e12
--- a/dev/null
+++ b/noncore/settings/sound/Makefile.in
@@ -0,0 +1,135 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../../bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= sound
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =soundsettings.h
27 SOURCES =soundsettings.cpp \
28 main.cpp
29 OBJECTS =soundsettings.o \
30 main.o \
31 soundsettingsbase.o
32INTERFACES = soundsettingsbase.ui
33UICDECLS = soundsettingsbase.h
34UICIMPLS = soundsettingsbase.cpp
35 SRCMOC =moc_soundsettings.cpp \
36 moc_soundsettingsbase.cpp
37 OBJMOC =moc_soundsettings.o \
38 moc_soundsettingsbase.o
39
40
41####### Implicit rules
42
43.SUFFIXES: .cpp .cxx .cc .C .c
44
45.cpp.o:
46 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
47
48.cxx.o:
49 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
50
51.cc.o:
52 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
53
54.C.o:
55 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
56
57.c.o:
58 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
59
60####### Build rules
61
62
63all: $(DESTDIR)$(TARGET)
64
65$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
66 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
67
68moc: $(SRCMOC)
69
70tmake:
71 tmake sound.pro
72
73clean:
74 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
75 -rm -f *~ core
76 -rm -f allmoc.cpp
77
78####### Extension Modules
79
80listpromodules:
81 @echo
82
83listallmodules:
84 @echo
85
86listaddonpromodules:
87 @echo
88
89listaddonentmodules:
90 @echo
91
92
93REQUIRES=
94
95####### Sub-libraries
96
97
98###### Combined headers
99
100
101
102####### Compile
103
104soundsettings.o: soundsettings.cpp \
105 soundsettings.h \
106 soundsettingsbase.h
107
108main.o: main.cpp \
109 soundsettings.h \
110 soundsettingsbase.h
111
112soundsettingsbase.h: soundsettingsbase.ui
113 $(UIC) soundsettingsbase.ui -o $(INTERFACE_DECL_PATH)/soundsettingsbase.h
114
115soundsettingsbase.cpp: soundsettingsbase.ui
116 $(UIC) soundsettingsbase.ui -i soundsettingsbase.h -o soundsettingsbase.cpp
117
118soundsettingsbase.o: soundsettingsbase.cpp \
119 soundsettingsbase.h \
120 soundsettingsbase.ui
121
122moc_soundsettings.o: moc_soundsettings.cpp \
123 soundsettings.h \
124 soundsettingsbase.h
125
126moc_soundsettingsbase.o: moc_soundsettingsbase.cpp \
127 soundsettingsbase.h
128
129moc_soundsettings.cpp: soundsettings.h
130 $(MOC) soundsettings.h -o moc_soundsettings.cpp
131
132moc_soundsettingsbase.cpp: soundsettingsbase.h
133 $(MOC) soundsettingsbase.h -o moc_soundsettingsbase.cpp
134
135
diff --git a/noncore/settings/sound/main.cpp b/noncore/settings/sound/main.cpp
new file mode 100644
index 0000000..5d28a8c
--- a/dev/null
+++ b/noncore/settings/sound/main.cpp
@@ -0,0 +1,36 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "soundsettings.h"
22
23#include <qpe/qpeapplication.h>
24
25
26int main(int argc, char** argv)
27{
28 QPEApplication a(argc,argv);
29
30 SoundSettings dlg;
31
32 a.showMainWidget(&dlg);
33
34 return a.exec();
35}
36
diff --git a/noncore/settings/sound/qpe-sound.control b/noncore/settings/sound/qpe-sound.control
new file mode 100644
index 0000000..f7f1c4f
--- a/dev/null
+++ b/noncore/settings/sound/qpe-sound.control
@@ -0,0 +1,10 @@
1Files: bin/sound apps/Settings/Sound.desktop
2Priority: optional
3Section: qpe/settings
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Arch: iPAQ
7Version: $QPE_VERSION-1
8Depends: qpe-base ($QPE_VERSION)
9Description: Sound settings dialog
10 For the Qtopia environment.
diff --git a/noncore/settings/sound/sound.pro b/noncore/settings/sound/sound.pro
new file mode 100644
index 0000000..9028a44
--- a/dev/null
+++ b/noncore/settings/sound/sound.pro
@@ -0,0 +1,10 @@
1 TEMPLATE= app
2 CONFIG += qt warn_on release
3 DESTDIR = ../../bin
4 HEADERS = soundsettings.h
5 SOURCES = soundsettings.cpp main.cpp
6 INTERFACES= soundsettingsbase.ui
7INCLUDEPATH += $(QPEDIR)/include
8 DEPENDPATH+= ../$(QPEDIR)/include
9LIBS += -lqpe
10 TARGET = sound
diff --git a/noncore/settings/sound/soundsettings.cpp b/noncore/settings/sound/soundsettings.cpp
new file mode 100644
index 0000000..92281f8
--- a/dev/null
+++ b/noncore/settings/sound/soundsettings.cpp
@@ -0,0 +1,64 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "soundsettings.h"
21
22#include <qpe/config.h>
23#include <qpe/qcopenvelope_qws.h>
24
25#include <qslider.h>
26#include <qcheckbox.h>
27
28SoundSettings::SoundSettings( QWidget* parent, const char* name, WFlags fl )
29 : SoundSettingsBase( parent, name, TRUE, fl )
30{
31 Config config( "Sound" );
32
33 config.setGroup( "System" );
34 volume->setValue(100-config.readNumEntry("Volume"));
35 touchsound->setChecked(config.readBoolEntry("Touch"));
36 keysound->setChecked(config.readBoolEntry("Key"));
37
38 connect(volume, SIGNAL(valueChanged(int)), this, SLOT(setVolume(int)));
39}
40
41void SoundSettings::reject()
42{
43 Config config( "Sound" );
44 config.setGroup( "System" );
45 setVolume(100-config.readNumEntry("Volume"));
46
47 QDialog::reject();
48}
49
50void SoundSettings::accept()
51{
52 Config config( "Sound" );
53 config.setGroup( "System" );
54 config.writeEntry("Volume",100-volume->value());
55 config.writeEntry("Touch",touchsound->isChecked());
56 config.writeEntry("Key",keysound->isChecked());
57 setVolume(volume->value());
58 QDialog::accept();
59}
60
61void SoundSettings::setVolume(int v)
62{
63 QCopEnvelope( "QPE/System", "setVolume(int,int)" ) << 0 << 100-v;
64}
diff --git a/noncore/settings/sound/soundsettings.h b/noncore/settings/sound/soundsettings.h
new file mode 100644
index 0000000..b5c8cee
--- a/dev/null
+++ b/noncore/settings/sound/soundsettings.h
@@ -0,0 +1,44 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef SOUNDSETTINGS_H
21#define SOUNDSETTINGS_H
22
23
24#include "soundsettingsbase.h"
25
26
27class SoundSettings : public SoundSettingsBase
28{
29 Q_OBJECT
30
31public:
32 SoundSettings( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
33
34protected:
35 void accept();
36 void reject();
37
38private slots:
39 void setVolume(int);
40};
41
42
43#endif // SOUNDSETTINGS_H
44
diff --git a/noncore/settings/sound/soundsettingsbase.ui b/noncore/settings/sound/soundsettingsbase.ui
new file mode 100644
index 0000000..1aa4545
--- a/dev/null
+++ b/noncore/settings/sound/soundsettingsbase.ui
@@ -0,0 +1,281 @@
1<!DOCTYPE UI><UI>
2<class>SoundSettingsBase</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>SoundSettingsBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>246</width>
15 <height>299</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Sound Settings</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>7</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>1</number>
36 </property>
37 <widget>
38 <class>QCheckBox</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>keysound</cstring>
42 </property>
43 <property stdset="1">
44 <name>text</name>
45 <string>Keyboard sound</string>
46 </property>
47 </widget>
48 <widget>
49 <class>QCheckBox</class>
50 <property stdset="1">
51 <name>name</name>
52 <cstring>touchsound</cstring>
53 </property>
54 <property stdset="1">
55 <name>text</name>
56 <string>Screen sound</string>
57 </property>
58 </widget>
59 <widget>
60 <class>QLayoutWidget</class>
61 <property stdset="1">
62 <name>name</name>
63 <cstring>Layout10</cstring>
64 </property>
65 <hbox>
66 <property stdset="1">
67 <name>margin</name>
68 <number>0</number>
69 </property>
70 <property stdset="1">
71 <name>spacing</name>
72 <number>6</number>
73 </property>
74 <widget>
75 <class>QSlider</class>
76 <property stdset="1">
77 <name>name</name>
78 <cstring>volume</cstring>
79 </property>
80 <property stdset="1">
81 <name>maxValue</name>
82 <number>100</number>
83 </property>
84 <property stdset="1">
85 <name>value</name>
86 <number>50</number>
87 </property>
88 <property stdset="1">
89 <name>orientation</name>
90 <enum>Vertical</enum>
91 </property>
92 <property stdset="1">
93 <name>tickmarks</name>
94 <enum>Right</enum>
95 </property>
96 <property stdset="1">
97 <name>tickInterval</name>
98 <number>5</number>
99 </property>
100 </widget>
101 <widget>
102 <class>QLayoutWidget</class>
103 <property stdset="1">
104 <name>name</name>
105 <cstring>Layout9</cstring>
106 </property>
107 <vbox>
108 <property stdset="1">
109 <name>margin</name>
110 <number>0</number>
111 </property>
112 <property stdset="1">
113 <name>spacing</name>
114 <number>6</number>
115 </property>
116 <widget>
117 <class>QLayoutWidget</class>
118 <property stdset="1">
119 <name>name</name>
120 <cstring>Layout10_2</cstring>
121 </property>
122 <hbox>
123 <property stdset="1">
124 <name>margin</name>
125 <number>0</number>
126 </property>
127 <property stdset="1">
128 <name>spacing</name>
129 <number>6</number>
130 </property>
131 <widget>
132 <class>QLabel</class>
133 <property stdset="1">
134 <name>name</name>
135 <cstring>PixmapLabel1_2</cstring>
136 </property>
137 <property stdset="1">
138 <name>pixmap</name>
139 <pixmap>image0</pixmap>
140 </property>
141 <property stdset="1">
142 <name>scaledContents</name>
143 <bool>false</bool>
144 </property>
145 </widget>
146 <widget>
147 <class>QLabel</class>
148 <property stdset="1">
149 <name>name</name>
150 <cstring>TextLabel1_2</cstring>
151 </property>
152 <property stdset="1">
153 <name>text</name>
154 <string>Loud</string>
155 </property>
156 </widget>
157 <spacer>
158 <property>
159 <name>name</name>
160 <cstring>Spacer3_2</cstring>
161 </property>
162 <property stdset="1">
163 <name>orientation</name>
164 <enum>Horizontal</enum>
165 </property>
166 <property stdset="1">
167 <name>sizeType</name>
168 <enum>Expanding</enum>
169 </property>
170 <property>
171 <name>sizeHint</name>
172 <size>
173 <width>20</width>
174 <height>20</height>
175 </size>
176 </property>
177 </spacer>
178 </hbox>
179 </widget>
180 <spacer>
181 <property>
182 <name>name</name>
183 <cstring>Spacer5_2</cstring>
184 </property>
185 <property stdset="1">
186 <name>orientation</name>
187 <enum>Vertical</enum>
188 </property>
189 <property stdset="1">
190 <name>sizeType</name>
191 <enum>Expanding</enum>
192 </property>
193 <property>
194 <name>sizeHint</name>
195 <size>
196 <width>20</width>
197 <height>20</height>
198 </size>
199 </property>
200 </spacer>
201 <widget>
202 <class>QLayoutWidget</class>
203 <property stdset="1">
204 <name>name</name>
205 <cstring>Layout9_2</cstring>
206 </property>
207 <hbox>
208 <property stdset="1">
209 <name>margin</name>
210 <number>0</number>
211 </property>
212 <property stdset="1">
213 <name>spacing</name>
214 <number>6</number>
215 </property>
216 <widget>
217 <class>QLabel</class>
218 <property stdset="1">
219 <name>name</name>
220 <cstring>PixmapLabel2_2</cstring>
221 </property>
222 <property stdset="1">
223 <name>pixmap</name>
224 <pixmap>image1</pixmap>
225 </property>
226 <property stdset="1">
227 <name>scaledContents</name>
228 <bool>false</bool>
229 </property>
230 </widget>
231 <widget>
232 <class>QLabel</class>
233 <property stdset="1">
234 <name>name</name>
235 <cstring>TextLabel2_2</cstring>
236 </property>
237 <property stdset="1">
238 <name>text</name>
239 <string>Silent</string>
240 </property>
241 </widget>
242 <spacer>
243 <property>
244 <name>name</name>
245 <cstring>Spacer2_2</cstring>
246 </property>
247 <property stdset="1">
248 <name>orientation</name>
249 <enum>Horizontal</enum>
250 </property>
251 <property stdset="1">
252 <name>sizeType</name>
253 <enum>Expanding</enum>
254 </property>
255 <property>
256 <name>sizeHint</name>
257 <size>
258 <width>20</width>
259 <height>20</height>
260 </size>
261 </property>
262 </spacer>
263 </hbox>
264 </widget>
265 </vbox>
266 </widget>
267 </hbox>
268 </widget>
269 </vbox>
270</widget>
271<images>
272 <image>
273 <name>image0</name>
274 <data format="XPM.GZ" length="409">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523234530022630543251d2e253d856405bffcbc54103b11c856360003105719c44d4b8371f590803210638829a38b2983115c2c112a8224969808d60716868a2582c440aa94a1628960a00755a5ac8c2aa64c8118c23c6cf6c2dda787e23eb03f602af1fa17395c6aadb9008c9350cb</data>
275 </image>
276 <image>
277 <name>image1</name>
278 <data format="XPM.GZ" length="409">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523234530022630543251d2e253d856405bffcbc54105b19c856360003103711c44d4b8371f5d000c962ca9862ca9862ca60b1440806bb0a0c80dcc444304616030924a2a983a8d423a80ed93c6cf6e2701f567f100c835a6b2e0025ab4ee4</data>
279 </image>
280</images>
281</UI>
diff --git a/noncore/settings/sysinfo/.cvsignore b/noncore/settings/sysinfo/.cvsignore
new file mode 100644
index 0000000..edfa921
--- a/dev/null
+++ b/noncore/settings/sysinfo/.cvsignore
@@ -0,0 +1,3 @@
1moc_*
2*.moc
3Makefile
diff --git a/noncore/settings/sysinfo/Makefile.in b/noncore/settings/sysinfo/Makefile.in
new file mode 100644
index 0000000..1149304
--- a/dev/null
+++ b/noncore/settings/sysinfo/Makefile.in
@@ -0,0 +1,193 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= sysinfo
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =memory.h \
27 graph.h \
28 load.h \
29 storage.h \
30 versioninfo.h \
31 sysinfo.h
32 SOURCES =main.cpp \
33 memory.cpp \
34 graph.cpp \
35 load.cpp \
36 storage.cpp \
37 versioninfo.cpp \
38 sysinfo.cpp
39 OBJECTS =main.o \
40 memory.o \
41 graph.o \
42 load.o \
43 storage.o \
44 versioninfo.o \
45 sysinfo.o
46INTERFACES =
47UICDECLS =
48UICIMPLS =
49 SRCMOC =moc_memory.cpp \
50 moc_graph.cpp \
51 moc_load.cpp \
52 moc_storage.cpp \
53 moc_versioninfo.cpp \
54 moc_sysinfo.cpp
55 OBJMOC =moc_memory.o \
56 moc_graph.o \
57 moc_load.o \
58 moc_storage.o \
59 moc_versioninfo.o \
60 moc_sysinfo.o
61
62
63####### Implicit rules
64
65.SUFFIXES: .cpp .cxx .cc .C .c
66
67.cpp.o:
68 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
69
70.cxx.o:
71 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
72
73.cc.o:
74 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
75
76.C.o:
77 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
78
79.c.o:
80 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
81
82####### Build rules
83
84
85all: $(DESTDIR)$(TARGET)
86
87$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
88 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
89
90moc: $(SRCMOC)
91
92tmake:
93 tmake sysinfo.pro
94
95clean:
96 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
97 -rm -f *~ core
98 -rm -f allmoc.cpp
99
100####### Extension Modules
101
102listpromodules:
103 @echo
104
105listallmodules:
106 @echo
107
108listaddonpromodules:
109 @echo
110
111listaddonentmodules:
112 @echo
113
114
115REQUIRES=
116
117####### Sub-libraries
118
119
120###### Combined headers
121
122
123
124####### Compile
125
126main.o: main.cpp \
127 sysinfo.h \
128 $(QPEDIR)/include/qpe/qpeapplication.h
129
130memory.o: memory.cpp \
131 graph.h \
132 memory.h
133
134graph.o: graph.cpp \
135 graph.h
136
137load.o: load.cpp \
138 load.h
139
140storage.o: storage.cpp \
141 graph.h \
142 storage.h
143
144versioninfo.o: versioninfo.cpp \
145 $(QPEDIR)/include/qpe/resource.h \
146 $(QPEDIR)/include/qpe/version.h \
147 versioninfo.h
148
149sysinfo.o: sysinfo.cpp \
150 memory.h \
151 load.h \
152 storage.h \
153 versioninfo.h \
154 sysinfo.h \
155 $(QPEDIR)/include/qpe/resource.h
156
157moc_memory.o: moc_memory.cpp \
158 memory.h
159
160moc_graph.o: moc_graph.cpp \
161 graph.h
162
163moc_load.o: moc_load.cpp \
164 load.h
165
166moc_storage.o: moc_storage.cpp \
167 storage.h
168
169moc_versioninfo.o: moc_versioninfo.cpp \
170 versioninfo.h
171
172moc_sysinfo.o: moc_sysinfo.cpp \
173 sysinfo.h
174
175moc_memory.cpp: memory.h
176 $(MOC) memory.h -o moc_memory.cpp
177
178moc_graph.cpp: graph.h
179 $(MOC) graph.h -o moc_graph.cpp
180
181moc_load.cpp: load.h
182 $(MOC) load.h -o moc_load.cpp
183
184moc_storage.cpp: storage.h
185 $(MOC) storage.h -o moc_storage.cpp
186
187moc_versioninfo.cpp: versioninfo.h
188 $(MOC) versioninfo.h -o moc_versioninfo.cpp
189
190moc_sysinfo.cpp: sysinfo.h
191 $(MOC) sysinfo.h -o moc_sysinfo.cpp
192
193
diff --git a/noncore/settings/sysinfo/graph.cpp b/noncore/settings/sysinfo/graph.cpp
new file mode 100644
index 0000000..0b02bf7
--- a/dev/null
+++ b/noncore/settings/sysinfo/graph.cpp
@@ -0,0 +1,183 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpainter.h>
22#include <qpixmap.h>
23#include "graph.h"
24
25void GraphData::clear()
26{
27 names.clear();
28 values.resize(0);
29}
30
31void GraphData::addItem( const QString &name, int value )
32{
33 names.append( name );
34 values.resize( values.size() + 1 );
35 values[values.size()-1] = value;
36}
37
38Graph::Graph(QWidget *parent, const char *name, WFlags f )
39 : QFrame( parent, name, f )
40{
41}
42
43PieGraph::PieGraph(QWidget *parent, const char *name, WFlags f )
44 : Graph( parent, name, f )
45{
46}
47
48void PieGraph::drawContents( QPainter *p )
49{
50 int size = QMIN( contentsRect().width(), contentsRect().height() ) - 1;
51
52 int total = 0;
53 for ( unsigned i = 0; i < data->count(); i++ )
54 total += data->value(i);
55
56 int angle = 0;
57 for ( unsigned i = 0; i < data->count(); i++ ) {
58 int len;
59 if ( i == data->count() - 1 || !total )
60 len = 5760 - angle;
61 else
62 len = data->value(i) * 5760 / total;
63 QColor col;
64 col.setHsv( i * 360 / data->count(), 255, 255 );
65 p->setBrush( col );
66 p->drawPie ( contentsRect().x(), contentsRect().y(),
67 size, size, angle, len+32 );
68 angle += len;
69 }
70}
71
72BarGraph::BarGraph(QWidget *parent, const char *name, WFlags f )
73 : Graph( parent, name, f )
74{
75 setMinimumHeight( 10 );
76 setMaximumHeight( 45 );
77}
78
79void BarGraph::drawContents( QPainter *p )
80{
81 int h = contentsRect().height();
82 int y = contentsRect().top();
83
84 int total = 0;
85 for ( unsigned i = 0; i < data->count(); i++ )
86 total += data->value(i);
87
88 int pos = 0;
89 for ( unsigned i = 0; i < data->count(); i++ ) {
90 int len;
91 if ( i == data->count() - 1 || !total )
92 len = contentsRect().width() - pos;
93 else
94 len = data->value(i) * contentsRect().width() / total;
95 QColor col;
96 col.setHsv( i * 360 / data->count(), 255, 255 );
97 drawSegment( p, QRect(contentsRect().x() + pos, y, len, h), col );
98 pos += len;
99 }
100}
101
102void BarGraph::drawSegment( QPainter *p, const QRect &r, const QColor &c )
103{
104 if ( QPixmap::defaultDepth() > 8 ) {
105 QColor topgrad = c.light(170);
106 QColor botgrad = c.dark();
107
108 int h1, h2, s1, s2, v1, v2;
109 topgrad.hsv( &h1, &s1, &v1 );
110 botgrad.hsv( &h2, &s2, &v2 );
111 int ng = r.height();
112 for ( int j =0; j < ng; j++ ) {
113 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1),
114 s1 + ((s2-s1)*j)/(ng-1),
115 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
116 p->drawLine( r.x(), r.top()+j, r.x()+r.width(), r.top()+j );
117 }
118 } else {
119 p->fillRect( r.x(), r.top(), r.width(), r.height(), c );
120 }
121}
122
123
124GraphLegend::GraphLegend( QWidget *parent, const char *name, WFlags f )
125 : QFrame( parent, name, f )
126{
127 horz = FALSE;
128}
129
130void GraphLegend::setOrientation(Orientation o)
131{
132 horz = o == Horizontal;
133}
134
135void GraphLegend::drawContents( QPainter *p )
136{
137 int total = 0;
138 for ( unsigned i = 0; i < data->count(); i++ )
139 total += data->value(i);
140
141 int tw = width()/data->count()-1;
142 int th = height()/(horz ? 1 : data->count());
143 if ( th > p->fontMetrics().height() )
144 th = p->fontMetrics().height();
145 int x = 0;
146 int y = 0;
147 for ( unsigned i = 0; i < data->count(); i++ ) {
148 QColor col;
149 col.setHsv( i * 360 / data->count(), 255, 255 );
150 p->setBrush( col );
151 p->drawRect( x+1, y+1, th - 2, th - 2 );
152 p->drawText( x+th + 1, y + p->fontMetrics().ascent()+1, data->name(i) );
153 if ( horz ) {
154 x += tw;
155 } else {
156 y += th;
157 }
158 }
159}
160
161QSize GraphLegend::sizeHint() const
162{
163 int th = fontMetrics().height() + 2;
164 int maxw = 0;
165 for ( unsigned i = 0; i < data->count(); i++ ) {
166 int w = fontMetrics().width( data->name(i) );
167 if ( w > maxw )
168 maxw = w;
169 }
170 if ( 0 && horz ) {
171 return QSize( maxw * data->count(), th );
172 } else {
173 return QSize( maxw, th * data->count() );
174 }
175}
176
177void GraphLegend::setData( const GraphData *p )
178{
179 data = p;
180 int th = fontMetrics().height();
181 setMinimumHeight( th * ( horz ? 1 : data->count() ) );
182 updateGeometry();
183}
diff --git a/noncore/settings/sysinfo/graph.h b/noncore/settings/sysinfo/graph.h
new file mode 100644
index 0000000..5a65e79
--- a/dev/null
+++ b/noncore/settings/sysinfo/graph.h
@@ -0,0 +1,89 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qframe.h>
22#include <qarray.h>
23#include <qstringlist.h>
24
25class GraphData
26{
27public:
28 void clear();
29 void addItem( const QString &name, int value );
30
31 const QString &name( int i ) const { return names[i]; }
32 int value( int i ) const { return values[i]; }
33 unsigned count() const { return values.size(); }
34
35private:
36 QStringList names;
37 QArray<int> values;
38};
39
40class Graph : public QFrame
41{
42 Q_OBJECT
43public:
44 Graph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
45
46 void setData( const GraphData *p ) { data = p; }
47
48protected:
49 const GraphData *data;
50};
51
52class PieGraph : public Graph
53{
54 Q_OBJECT
55public:
56 PieGraph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
57
58protected:
59 virtual void drawContents( QPainter *p );
60};
61
62class BarGraph : public Graph
63{
64 Q_OBJECT
65public:
66 BarGraph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
67
68protected:
69 virtual void drawContents( QPainter *p );
70 void drawSegment( QPainter *p, const QRect &r, const QColor &c );
71};
72
73class GraphLegend : public QFrame
74{
75 Q_OBJECT
76public:
77 GraphLegend( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
78
79 void setData( const GraphData *p );
80 virtual QSize sizeHint() const;
81 void setOrientation(Orientation o);
82
83protected:
84 virtual void drawContents( QPainter *p );
85
86private:
87 const GraphData *data;
88 bool horz;
89};
diff --git a/noncore/settings/sysinfo/load.cpp b/noncore/settings/sysinfo/load.cpp
new file mode 100644
index 0000000..0fcfa6b
--- a/dev/null
+++ b/noncore/settings/sysinfo/load.cpp
@@ -0,0 +1,207 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <stdio.h>
22#include <qlayout.h>
23#include <qlabel.h>
24#include <qpainter.h>
25#include <qpixmap.h>
26#include <qtimer.h>
27#include <qfile.h>
28#include <qtextstream.h>
29#include "load.h"
30
31LoadInfo::LoadInfo( QWidget *parent, const char *name, WFlags f )
32 : QWidget( parent, name, f )
33{
34 QVBoxLayout *vb = new QVBoxLayout( this, 6 );
35
36 QString cpuInfo = getCpuInfo();
37 if ( !cpuInfo.isNull() )
38 vb->addWidget( new QLabel( cpuInfo, this ) );
39 vb->addWidget( new Load( this ), 100 );
40 QLabel *l = new QLabel( this );
41 l->setPixmap( makeLabel( red, tr("Application CPU usage (%)") ) );
42 vb->addWidget( l, 1 );
43 l = new QLabel( this );
44 l->setPixmap( makeLabel( green, tr("System CPU usage (%)") ) );
45 vb->addWidget( l, 1 );
46 vb->addStretch(50);
47}
48
49QPixmap LoadInfo::makeLabel( const QColor &col, const QString &text )
50{
51 int h = fontMetrics().height();
52 QPixmap pm( 20 + fontMetrics().width( text ), h );
53 QPainter p( &pm );
54 p.fillRect( pm.rect(), colorGroup().background() );
55 p.fillRect( 0, h/2-4, 18, h/2+3, black );
56 p.setPen( col );
57 p.drawLine( 2, h/2, 15, h/2 );
58 p.setPen( colorGroup().text() );
59 p.drawText( 20, fontMetrics().ascent(), text );
60
61 return pm;
62}
63
64QString LoadInfo::getCpuInfo()
65{
66 bool haveInfo = FALSE;
67 QString info = tr("Type: ");
68 QFile f( "/proc/cpuinfo" );
69 if ( f.open( IO_ReadOnly ) ) {
70 QTextStream ts( &f );
71
72 while ( !ts.atEnd() ) {
73 QString s = ts.readLine();
74 if ( s.find( "model name" ) == 0 ) {
75 info += s.mid( s.find( ':' ) + 2 );
76 haveInfo = TRUE;
77 } else if ( s.find( "cpu MHz" ) == 0 ) {
78 double mhz = s.mid( s.find( ':' ) + 2 ).toDouble();
79 info += " " + QString::number( mhz, 'f', 0 );
80 info += "MHz";
81 break;
82 } else if ( s.find( "Processor" ) == 0 ) {
83 info += s.mid( s.find( ':' ) + 2 );
84 haveInfo = TRUE;
85 break;
86#ifdef __MIPSEL__
87 } else if ( s.find( "cpu model" ) == 0 ) {
88 info += " " + s.mid( s.find( ':' ) + 2 );
89 break;
90 } else if ( s.find( "cpu" ) == 0 ) {
91 info += s.mid( s.find( ':' ) + 2 );
92 haveInfo = TRUE;
93#endif
94 }
95 }
96 }
97
98 if ( !haveInfo )
99 info = QString();
100
101 return info;
102}
103
104Load::Load( QWidget *parent, const char *name, WFlags f )
105 : QWidget( parent, name, f )
106{
107 setMinimumHeight( 30 );
108 setBackgroundColor( black );
109 points = 100;
110 setMinimumWidth( points );
111 userLoad = new double [points];
112 systemLoad = new double [points];
113 for ( int i = 0; i < points; i++ ) {
114 userLoad[i] = 0.0;
115 systemLoad[i] = 0.0;
116 }
117 maxLoad = 1.3;
118 QTimer *timer = new QTimer( this );
119 connect( timer, SIGNAL(timeout()), SLOT(timeout()) );
120 timer->start( 2000 );
121 gettimeofday( &last, 0 );
122 first = TRUE;
123 timeout();
124}
125
126void Load::paintEvent( QPaintEvent *ev )
127{
128 QPainter p( this );
129
130 int h = height() - 5;
131
132 int mult = (int)(h / maxLoad);
133
134 p.setPen( gray );
135 p.drawLine( 0, h - mult, width(), h - mult );
136 p.drawText( 0, h - mult, "100" );
137 p.drawText( 0, h, "0" );
138
139 p.setPen( green );
140 for ( int i = 1; i < points; i++ ) {
141 int x1 = (i - 1) * width() / points;
142 int x2 = i * width() / points;
143 p.drawLine( x1, h - systemLoad[i-1] * mult,
144 x2, h - systemLoad[i] * mult );
145 }
146
147 p.setPen( red );
148 for ( int i = 1; i < points; i++ ) {
149 int x1 = (i - 1) * width() / points;
150 int x2 = i * width() / points;
151 p.drawLine( x1, h - userLoad[i-1] * mult,
152 x2, h - userLoad[i] * mult );
153 }
154}
155
156void Load::timeout()
157{
158 int user;
159 int usernice;
160 int sys;
161 int idle;
162 FILE *fp;
163 fp = fopen( "/proc/stat", "r" );
164 fscanf( fp, "cpu %d %d %d %d", &user, &usernice, &sys, &idle );
165 fclose( fp );
166 struct timeval now;
167 gettimeofday( &now, 0 );
168 int tdiff = now.tv_usec - last.tv_usec;
169 tdiff += (now.tv_sec - last.tv_sec) * 1000000;
170 tdiff /= 10000;
171
172 int udiff = user - lastUser;
173 int sdiff = sys - lastSys;
174 if ( tdiff > 0 ) {
175 double uload = (double)udiff / (double)tdiff;
176 double sload = (double)sdiff / (double)tdiff;
177 if ( !first ) {
178 for ( int i = 1; i < points; i++ ) {
179 userLoad[i-1] = userLoad[i];
180 systemLoad[i-1] = systemLoad[i];
181 }
182 userLoad[points-1] = uload;
183 systemLoad[points-1] = sload;
184 // scroll( -width()/points, 0, QRect( 0, 0, width() - width()/points + 1, height() ) );
185 repaint( TRUE );
186 double ml = 1.3;
187 /*
188 for ( int i = 0; i < points; i++ ) {
189 if ( userLoad[i] > ml )
190 ml = userLoad[i];
191 }
192 */
193 if ( maxLoad != ml ) {
194 maxLoad = ml;
195 update();
196 }
197 }
198
199 last = now;
200 lastUser = user;
201 lastSys = sys;
202 first = FALSE;
203 } else if ( tdiff < 0 ) {
204 last = now;
205 }
206}
207
diff --git a/noncore/settings/sysinfo/load.h b/noncore/settings/sysinfo/load.h
new file mode 100644
index 0000000..e7f5388
--- a/dev/null
+++ b/noncore/settings/sysinfo/load.h
@@ -0,0 +1,60 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <sys/time.h>
22#include <qwidget.h>
23
24/*
25 Little load meter
26*/
27class Load : public QWidget {
28 Q_OBJECT
29public:
30 Load( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
31
32protected:
33 void paintEvent( QPaintEvent *ev );
34
35private slots:
36 void timeout();
37
38private:
39 int points;
40 double *userLoad;
41 double *systemLoad;
42 double maxLoad;
43 struct timeval last;
44 int lastUser;
45 int lastUsernice;
46 int lastSys;
47 int lastIdle;
48 bool first;
49};
50
51class LoadInfo : public QWidget
52{
53 Q_OBJECT
54public:
55 LoadInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
56
57private:
58 QPixmap makeLabel( const QColor &col, const QString &text );
59 QString getCpuInfo();
60};
diff --git a/noncore/settings/sysinfo/main.cpp b/noncore/settings/sysinfo/main.cpp
new file mode 100644
index 0000000..6e889db
--- a/dev/null
+++ b/noncore/settings/sysinfo/main.cpp
@@ -0,0 +1,34 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "sysinfo.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char *argv[] )
26{
27 QPEApplication a( argc, argv );
28
29 SystemInfo *si = new SystemInfo();
30 a.showMainWidget( si );
31
32 return a.exec();
33}
34
diff --git a/noncore/settings/sysinfo/memory.cpp b/noncore/settings/sysinfo/memory.cpp
new file mode 100644
index 0000000..781f0df
--- a/dev/null
+++ b/noncore/settings/sysinfo/memory.cpp
@@ -0,0 +1,94 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qlabel.h>
22#include <qtimer.h>
23#include <qfile.h>
24#include <qtextstream.h>
25#include <qlayout.h>
26#include "graph.h"
27#include "memory.h"
28
29MemoryInfo::MemoryInfo( QWidget *parent, const char *name, WFlags f )
30 : QWidget( parent, name, f )
31{
32 QVBoxLayout *vb = new QVBoxLayout( this, 5 );
33
34 totalMem = new QLabel( this );
35 vb->addWidget( totalMem );
36
37 data = new GraphData();
38// graph = new PieGraph( this );
39 graph = new BarGraph( this );
40 graph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
41 vb->addWidget( graph, 1 );
42 graph->setData( data );
43
44 legend = new GraphLegend( this );
45 vb->addWidget( legend );
46 legend->setData( data );
47
48 vb->addStretch( 1 );
49 updateData();
50
51 QTimer *t = new QTimer( this );
52 connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) );
53 t->start( 5000 );
54}
55
56MemoryInfo::~MemoryInfo()
57{
58 delete data;
59}
60
61void MemoryInfo::updateData()
62{
63 QFile file( "/proc/meminfo" );
64
65 if ( file.open( IO_ReadOnly ) ) {
66 QTextStream t( &file );
67 QString dummy = t.readLine();// title
68 t >> dummy;
69 int total, used, memfree, shared, buffers, cached;
70 t >> total;
71 total /= 1000;
72 t >> used;
73 used /= 1000;
74 t >> memfree;
75 memfree /= 1000;
76 t >> shared;
77 shared /= 1000;
78 t >> buffers;
79 buffers /= 1000;
80 t >> cached;
81 cached /= 1000;
82 int realUsed = total - ( buffers + cached + memfree );
83 data->clear();
84 data->addItem( tr("Used (%1 kB)").arg(realUsed), realUsed );
85 data->addItem( tr("Buffers (%1 kB)").arg(buffers), buffers );
86 data->addItem( tr("Cached (%1 kB)").arg(cached), cached );
87 data->addItem( tr("Free (%1 kB)").arg(memfree), memfree );
88 totalMem->setText( tr( "Total Memory: %1 kB" ).arg( total ) );
89 graph->repaint( FALSE );
90 legend->update();
91 }
92}
93
94
diff --git a/noncore/settings/sysinfo/memory.h b/noncore/settings/sysinfo/memory.h
new file mode 100644
index 0000000..696f97c
--- a/dev/null
+++ b/noncore/settings/sysinfo/memory.h
@@ -0,0 +1,48 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef MEMORY_H
22#define MEMORY_H
23
24#include <qwidget.h>
25
26class GraphData;
27class Graph;
28class GraphLegend;
29class QLabel;
30
31class MemoryInfo : public QWidget
32{
33 Q_OBJECT
34public:
35 MemoryInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
36 ~MemoryInfo();
37
38private slots:
39 void updateData();
40
41private:
42 QLabel *totalMem;
43 GraphData *data;
44 Graph *graph;
45 GraphLegend *legend;
46};
47
48#endif
diff --git a/noncore/settings/sysinfo/qpe-sysinfo.control b/noncore/settings/sysinfo/qpe-sysinfo.control
new file mode 100644
index 0000000..e5ed583
--- a/dev/null
+++ b/noncore/settings/sysinfo/qpe-sysinfo.control
@@ -0,0 +1,9 @@
1Files: bin/sysinfo apps/Applications/sysinfo.desktop pics/qpe-logo.png pics/tux-logo.png
2Priority: optional
3Section: qpe/applications
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: System Information dialog
9 For the Qtopia environment.
diff --git a/noncore/settings/sysinfo/storage.cpp b/noncore/settings/sysinfo/storage.cpp
new file mode 100644
index 0000000..4e81170
--- a/dev/null
+++ b/noncore/settings/sysinfo/storage.cpp
@@ -0,0 +1,220 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qlabel.h>
22#include <qlayout.h>
23#include <qtimer.h>
24#include <qlayout.h>
25#include "graph.h"
26#include "storage.h"
27
28#include <stdio.h>
29#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
30#include <sys/vfs.h>
31#include <mntent.h>
32#endif
33
34StorageInfo::StorageInfo( QWidget *parent, const char *name )
35 : QWidget( parent, name )
36{
37 vb = 0;
38 disks.setAutoDelete(TRUE);
39 lines.setAutoDelete(TRUE);
40 updateMounts();
41 startTimer( 5000 );
42}
43
44void StorageInfo::timerEvent(QTimerEvent*)
45{
46 updateMounts();
47}
48
49static bool isCF(const QString& m)
50{
51 FILE* f = fopen("/var/run/stab", "r");
52 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
53 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
54 if ( f ) {
55 char line[1024];
56 char devtype[80];
57 char devname[80];
58 while ( fgets( line, 1024, f ) ) {
59 // 0 ide ide-cs 0 hda 3 0
60 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
61 {
62 if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
63 fclose(f);
64 return TRUE;
65 }
66 }
67 }
68 fclose(f);
69 }
70 return FALSE;
71}
72
73void StorageInfo::updateMounts()
74{
75#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
76 struct mntent *me;
77 FILE *mntfp = setmntent( "/etc/mtab", "r" );
78 QStringList curdisks;
79 QStringList curfs;
80 bool rebuild = FALSE;
81 int n=0;
82 if ( mntfp ) {
83 while ( (me = getmntent( mntfp )) != 0 ) {
84 QString fs = me->mnt_fsname;
85 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
86 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" )
87 {
88 n++;
89 curdisks.append(fs);
90 QString d = me->mnt_dir;
91 curfs.append(d);
92 if ( !disks.find(d) )
93 rebuild = TRUE;
94 }
95 }
96 endmntent( mntfp );
97 }
98 if ( rebuild || n != (int)disks.count() ) {
99 disks.clear();
100 lines.clear();
101 delete vb;
102 vb = new QVBoxLayout( this, n > 3 ? 1 : 5 );
103 bool frst=TRUE;
104 QStringList::ConstIterator it=curdisks.begin();
105 QStringList::ConstIterator fsit=curfs.begin();
106 for (; it!=curdisks.end(); ++it, ++fsit) {
107 if ( !frst ) {
108 QFrame *f = new QFrame( this );
109 vb->addWidget(f);
110 f->setFrameStyle( QFrame::HLine | QFrame::Sunken );
111 lines.append(f);
112 f->show();
113 } frst=FALSE;
114 QString humanname=*it;
115 if ( isCF(humanname) )
116 humanname = tr("CF Card");
117 else if ( humanname == "/dev/hda1" )
118 humanname = tr("Hard Disk");
119 else if ( humanname.left(9) == "/dev/mmcd" )
120 humanname = tr("SD Card");
121 else if ( humanname.left(7) == "/dev/hd" )
122 humanname = tr("Hard Disk") + " " + humanname.mid(7);
123 else if ( humanname.left(7) == "/dev/sd" )
124 humanname = tr("SCSI Hard Disk") + " " + humanname.mid(7);
125 else if ( humanname == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
126 humanname = tr("Internal Storage");
127 else if ( humanname.left(14) == "/dev/mtdblock/" )
128 humanname = tr("Internal Storage") + " " + humanname.mid(14);
129 else if ( humanname.left(13) == "/dev/mtdblock" )
130 humanname = tr("Internal Storage") + " " + humanname.mid(13);
131 // etc.
132 MountInfo* mi = new MountInfo( *fsit, humanname, this );
133 vb->addWidget(mi);
134 disks.insert(*fsit,mi);
135 mi->show();
136 }
137 vb->addStretch();
138 } else {
139 // just update them
140 for (QDictIterator<MountInfo> i(disks); i.current(); ++i)
141 i.current()->updateData();
142 }
143#endif
144}
145
146
147MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent, const char *name )
148 : QWidget( parent, name ), title(ttl)
149{
150 fs = new FileSystem( path );
151 QVBoxLayout *vb = new QVBoxLayout( this, 3 );
152
153 totalSize = new QLabel( this );
154 vb->addWidget( totalSize );
155
156 data = new GraphData();
157 graph = new BarGraph( this );
158 graph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
159 vb->addWidget( graph, 1 );
160 graph->setData( data );
161
162 legend = new GraphLegend( this );
163 legend->setOrientation(Horizontal);
164 vb->addWidget( legend );
165 legend->setData( data );
166
167 updateData();
168}
169
170MountInfo::~MountInfo()
171{
172 delete data;
173 delete fs;
174}
175
176void MountInfo::updateData()
177{
178 fs->update();
179
180 long mult = fs->blockSize() / 1024;
181 long div = 1024 / fs->blockSize();
182 if ( !mult ) mult = 1;
183 if ( !div ) div = 1;
184 long total = fs->totalBlocks() * mult / div;
185 long avail = fs->availBlocks() * mult / div;
186 long used = total - avail;
187 totalSize->setText( title + tr(" total: %1 kB").arg( total ) );
188 data->clear();
189 data->addItem( tr("Used (%1 kB)").arg(used), used );
190 data->addItem( tr("Available (%1 kB)").arg(avail), avail );
191 graph->repaint( FALSE );
192 legend->update();
193 graph->show();
194 legend->show();
195}
196
197//---------------------------------------------------------------------------
198
199FileSystem::FileSystem( const QString &p )
200 : fspath( p ), blkSize(512), totalBlks(0), availBlks(0)
201{
202 update();
203}
204
205void FileSystem::update()
206{
207#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
208 struct statfs fs;
209 if ( !statfs( fspath.latin1(), &fs ) ) {
210 blkSize = fs.f_bsize;
211 totalBlks = fs.f_blocks;
212 availBlks = fs.f_bavail;
213 } else {
214 blkSize = 0;
215 totalBlks = 0;
216 availBlks = 0;
217 }
218#endif
219}
220
diff --git a/noncore/settings/sysinfo/storage.h b/noncore/settings/sysinfo/storage.h
new file mode 100644
index 0000000..3fa5b79
--- a/dev/null
+++ b/noncore/settings/sysinfo/storage.h
@@ -0,0 +1,87 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qwidget.h>
21#include <qframe.h>
22#include <qlist.h>
23#include <qdict.h>
24
25class QLabel;
26class GraphData;
27class Graph;
28class GraphLegend;
29class FileSystem;
30class MountInfo;
31class QVBoxLayout;
32
33
34class StorageInfo : public QWidget
35{
36 Q_OBJECT
37public:
38 StorageInfo( QWidget *parent=0, const char *name=0 );
39
40protected:
41 void timerEvent(QTimerEvent*);
42
43private:
44 void updateMounts();
45 QDict<MountInfo> disks;
46 QList<QFrame> lines;
47 QVBoxLayout *vb;
48};
49
50class MountInfo : public QWidget
51{
52 Q_OBJECT
53public:
54 MountInfo( const QString &path, const QString &ttl, QWidget *parent=0, const char *name=0 );
55 ~MountInfo();
56
57 void updateData();
58
59private:
60 QString title;
61 FileSystem *fs;
62 QLabel *totalSize;
63 GraphData *data;
64 Graph *graph;
65 GraphLegend *legend;
66};
67
68class FileSystem
69{
70public:
71 FileSystem( const QString &p );
72
73 void update();
74
75 const QString &path() const { return fspath; }
76 long blockSize() const { return blkSize; }
77 long totalBlocks() const { return totalBlks; }
78 long availBlocks() const { return availBlks; }
79
80private:
81 QString fspath;
82 long blkSize;
83 long totalBlks;
84 long availBlks;
85};
86
87
diff --git a/noncore/settings/sysinfo/sysinfo.cpp b/noncore/settings/sysinfo/sysinfo.cpp
new file mode 100644
index 0000000..bc483aa
--- a/dev/null
+++ b/noncore/settings/sysinfo/sysinfo.cpp
@@ -0,0 +1,53 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "memory.h"
22#include "load.h"
23#include "storage.h"
24//#include "graphics.h"
25#include "versioninfo.h"
26#include "sysinfo.h"
27
28
29#include <qpe/resource.h>
30
31#include <qtabwidget.h>
32#include <qlayout.h>
33
34SystemInfo::SystemInfo( QWidget *parent, const char *name, WFlags f )
35 : QWidget( parent, name, f )
36{
37 setIcon( Resource::loadPixmap( "system_icon" ) );
38 setCaption( tr("System Info") );
39 QVBoxLayout *lay = new QVBoxLayout( this );
40 QTabWidget *tab = new QTabWidget( this );
41 lay->addWidget( tab );
42 tab->addTab( new MemoryInfo( tab ), tr("Memory") );
43#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
44 tab->addTab( new StorageInfo( tab ), tr("Storage") );
45#endif
46 tab->addTab( new LoadInfo( tab ), tr("CPU") );
47// tab->addTab( new Graphics( tab ), tr("Graphics") );
48 tab->addTab( new VersionInfo( tab ), tr("Version") );
49
50 resize( 220, 180 );
51}
52
53
diff --git a/noncore/settings/sysinfo/sysinfo.h b/noncore/settings/sysinfo/sysinfo.h
new file mode 100644
index 0000000..abbf955
--- a/dev/null
+++ b/noncore/settings/sysinfo/sysinfo.h
@@ -0,0 +1,29 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qwidget.h>
22
23class SystemInfo : public QWidget
24{
25 Q_OBJECT
26public:
27 SystemInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
28};
29
diff --git a/noncore/settings/sysinfo/sysinfo.pro b/noncore/settings/sysinfo/sysinfo.pro
new file mode 100644
index 0000000..0c7d907
--- a/dev/null
+++ b/noncore/settings/sysinfo/sysinfo.pro
@@ -0,0 +1,25 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 DESTDIR = $(QPEDIR)/bin
4 HEADERS = memory.h \
5 graph.h \
6 load.h \
7 storage.h \
8 versioninfo.h \
9 sysinfo.h
10 SOURCES = main.cpp \
11 memory.cpp \
12 graph.cpp \
13 load.cpp \
14 storage.cpp \
15 versioninfo.cpp \
16 sysinfo.cpp
17 INTERFACES=
18
19INCLUDEPATH += $(QPEDIR)/include
20 DEPENDPATH+= $(QPEDIR)/include
21LIBS += -lqpe
22
23 TARGET = sysinfo
24
25TRANSLATIONS = ../i18n/de/sysinfo.ts
diff --git a/noncore/settings/sysinfo/versioninfo.cpp b/noncore/settings/sysinfo/versioninfo.cpp
new file mode 100644
index 0000000..d60a445
--- a/dev/null
+++ b/noncore/settings/sysinfo/versioninfo.cpp
@@ -0,0 +1,109 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpe/resource.h>
22#include <qpe/version.h>
23
24#include <qlabel.h>
25#include <qpixmap.h>
26#include <qpainter.h>
27#include <qimage.h>
28#include <qtimer.h>
29#include <qfile.h>
30#include <qtextstream.h>
31#include <qlayout.h>
32#include "versioninfo.h"
33
34VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
35 : QWidget( parent, name, f )
36{
37 setMinimumSize( 200, 150 );
38
39 QVBoxLayout *vb = new QVBoxLayout( this, 4 );
40
41 QString kernelVersionString;
42 QFile file( "/proc/version" );
43 if ( file.open( IO_ReadOnly ) ) {
44 QTextStream t( &file );
45 QString v;
46 t >> v; t >> v; t >> v;
47 v = v.left( 20 );
48 kernelVersionString = tr( "<b>Linux Kernel</b><p>Version: " ) + v + "<p>";
49 t >> v;
50 kernelVersionString += tr( "Compiled by: " ) + v;
51 file.close();
52 }
53
54 QString palmtopVersionString;
55 palmtopVersionString = tr( "<b>Qtopia</b><p>Version: " ) + QPE_VERSION + "<p>";
56#ifdef QPE_VENDOR
57 QString builder = QPE_VENDOR;
58#else
59 QString builder = "Unknown";
60#endif
61 palmtopVersionString += tr( "Compiled by: " ) + builder + "<p>";
62 palmtopVersionString += tr( "Built on: " ) + __DATE__;
63
64
65 QHBoxLayout *hb1 = new QHBoxLayout( vb );
66 hb1->setSpacing( 2 );
67
68 QLabel *palmtopLogo = new QLabel( this );
69 QImage logo1 = Resource::loadImage( "qpe-logo" );
70 logo1 = logo1.smoothScale( 50, 55 );
71 QPixmap logo1Pixmap;
72 logo1Pixmap.convertFromImage( logo1 );
73 palmtopLogo->setPixmap( logo1Pixmap );
74 palmtopLogo->setFixedSize( 60, 60 );
75 hb1->addWidget( palmtopLogo, 0, Qt::AlignTop + Qt::AlignLeft );
76
77 QLabel *palmtopVersion = new QLabel( this );
78 palmtopVersion->setText( palmtopVersionString );
79 hb1->addWidget( palmtopVersion, 1, Qt::AlignTop + Qt::AlignLeft );
80
81
82 QHBoxLayout *hb2 = new QHBoxLayout( vb );
83 hb1->setSpacing( 2 );
84
85 QLabel *linuxLogo = new QLabel( this );
86
87 // Need to do this extra qpainter code with this image becuase for some
88 // reason it doesn't alpha belnd if directly converted to a pixmap
89 QPixmap logo2Pixmap( 60, 60 );
90 QColor bgColor = colorGroup().background();
91 QPainter painter( &logo2Pixmap );
92 painter.fillRect( QRect( 0, 0, 60, 60 ), QBrush( bgColor ) );
93 QImage logo2 = Resource::loadImage( "tux-logo" );
94 logo2 = logo2.smoothScale( 40, 47 );
95 painter.drawImage( 0, 0, logo2 );
96 painter.end();
97 linuxLogo->setPixmap( logo2Pixmap );
98 linuxLogo->setFixedSize( 60, 60 );
99 hb2->addWidget( linuxLogo, 0, Qt::AlignTop + Qt::AlignLeft );
100
101 QLabel *kernelVersion = new QLabel( this );
102 kernelVersion->setText( kernelVersionString );
103 hb2->addWidget( kernelVersion, 1, Qt::AlignTop + Qt::AlignLeft );
104}
105
106VersionInfo::~VersionInfo()
107{
108}
109
diff --git a/noncore/settings/sysinfo/versioninfo.h b/noncore/settings/sysinfo/versioninfo.h
new file mode 100644
index 0000000..1b5c851
--- a/dev/null
+++ b/noncore/settings/sysinfo/versioninfo.h
@@ -0,0 +1,34 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef VERSIONINFO_H
22#define VERSIONINFO_H
23
24#include <qwidget.h>
25
26class VersionInfo : public QWidget
27{
28 Q_OBJECT
29public:
30 VersionInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
31 ~VersionInfo();
32};
33
34#endif
diff --git a/noncore/tools/calc2/Makefile b/noncore/tools/calc2/Makefile
new file mode 100644
index 0000000..1e31a2f
--- a/dev/null
+++ b/noncore/tools/calc2/Makefile
@@ -0,0 +1,138 @@
1#############################################################################
2# Makefile for building calc
3# Generated by tmake at 12:06, 2001/11/26
4# Project: calc
5# Template: app
6#############################################################################
7
8####### Compiler, tools and options
9
10 CC =gcc
11 CXX =g++
12 CFLAGS =-pipe -Wall -W -O2 -DNO_DEBUG
13 CXXFLAGS=-pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG
14 INCPATH =-I$(QPEDIR)/include -I$(QTDIR)/include
15 LINK =gcc
16 LFLAGS =
17 LIBS =$(SUBLIBS) -L$(QTDIR)/lib -lqpe -Wl,-export-dynamic -lqte
18 MOC =$(QTDIR)/bin/moc
19 UIC =$(QTDIR)/bin/uic
20
21 TAR =tar -cf
22 GZIP =gzip -9f
23
24####### Files
25
26 HEADERS =calc.h \
27 plugininterface.h \
28 instruction.h \
29 engine.h \
30 stdinstructions.h
31 SOURCES =calc.cpp \
32 main.cpp \
33 engine.cpp
34 OBJECTS =calc.o \
35 main.o \
36 engine.o
37 INTERFACES =
38 UICDECLS =
39 UICIMPLS =
40 SRCMOC =moc_calc.cpp \
41 moc_engine.cpp
42 OBJMOC =moc_calc.o \
43 moc_engine.o
44 DIST =
45 TARGET =calc
46INTERFACE_DECL_PATH = .
47
48####### Implicit rules
49
50.SUFFIXES: .cpp .cxx .cc .C .c
51
52.cpp.o:
53 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
54
55.cxx.o:
56 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
57
58.cc.o:
59 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
60
61.C.o:
62 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
63
64.c.o:
65 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
66
67####### Build rules
68
69
70all: $(TARGET)
71
72$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC)
73 $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
74
75moc: $(SRCMOC)
76
77tmake:
78 tmake calc.pro
79
80dist:
81 $(TAR) calc.tar calc.pro $(SOURCES) $(HEADERS) $(INTERFACES) $(DIST)
82 $(GZIP) calc.tar
83
84clean:
85 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) $(TARGET)
86 -rm -f *~ core
87
88####### Sub-libraries
89
90
91###### Combined headers
92
93
94####### Compile
95
96calc.o: calc.cpp \
97 /home/luke/builds/2.3.2-emb/qpe/include/qpe/qpeapplication.h \
98 calc.h \
99 /home/luke/builds/2.3.2-emb/qpe/include/qpe/qlibrary.h \
100 /home/luke/builds/2.3.2-emb/qpe/include/qpe/qcom.h \
101 /home/luke/builds/2.3.2-emb/qpe/include/qpe/quuid.h \
102 engine.h \
103 instruction.h \
104 plugininterface.h
105
106main.o: main.cpp \
107 /home/luke/builds/2.3.2-emb/qpe/include/qpe/qpeapplication.h \
108 calc.h \
109 /home/luke/builds/2.3.2-emb/qpe/include/qpe/qlibrary.h \
110 /home/luke/builds/2.3.2-emb/qpe/include/qpe/qcom.h \
111 /home/luke/builds/2.3.2-emb/qpe/include/qpe/quuid.h \
112 engine.h \
113 instruction.h \
114 plugininterface.h
115
116engine.o: engine.cpp \
117 engine.h \
118 instruction.h
119
120moc_calc.o: moc_calc.cpp \
121 calc.h \
122 /home/luke/builds/2.3.2-emb/qpe/include/qpe/qlibrary.h \
123 /home/luke/builds/2.3.2-emb/qpe/include/qpe/qcom.h \
124 /home/luke/builds/2.3.2-emb/qpe/include/qpe/quuid.h \
125 engine.h \
126 instruction.h \
127 plugininterface.h
128
129moc_engine.o: moc_engine.cpp \
130 engine.h \
131 instruction.h
132
133moc_calc.cpp: calc.h
134 $(MOC) calc.h -o moc_calc.cpp
135
136moc_engine.cpp: engine.h
137 $(MOC) engine.h -o moc_engine.cpp
138
diff --git a/noncore/tools/calc2/binary/Makefile b/noncore/tools/calc2/binary/Makefile
new file mode 100644
index 0000000..93cc0d5
--- a/dev/null
+++ b/noncore/tools/calc2/binary/Makefile
@@ -0,0 +1,146 @@
1#############################################################################
2# Makefile for building libbinary.so.1.0.0
3# Generated by tmake at 12:03, 2001/11/22
4# Project: binary
5# Template: lib
6#############################################################################
7
8####### Compiler, tools and options
9
10 CC =gcc
11 CXX =g++
12 CFLAGS =-pipe -Wall -W -O2 -fPIC -DNO_DEBUG
13 CXXFLAGS=-pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -fPIC -DNO_DEBUG
14 INCPATH =-I$(QPEDIR)/include -I$(QPEDIR)/calc2 -I$(QTDIR)/include
15 LINK =gcc
16 LFLAGS =-shared -Wl,-soname,libbinary.so.1
17 LIBS =$(SUBLIBS) -L$(QTDIR)/lib -lqte
18 AR =ar cqs
19 RANLIB =
20 MOC =$(QTDIR)/bin/moc
21 UIC =$(QTDIR)/bin/uic
22
23 TAR =tar -cf
24 GZIP =gzip -9f
25
26####### Files
27
28 HEADERS =binaryimpl.h \
29 binaryfactory.h
30 SOURCES =binaryimpl.cpp \
31 binaryfactory.cpp
32 OBJECTS =binaryimpl.o \
33 binaryfactory.o \
34 binary.o
35 INTERFACES =binary.ui
36 UICDECLS =binary.h
37 UICIMPLS =binary.cpp
38 SRCMOC =moc_binaryimpl.cpp \
39 moc_binary.cpp
40 OBJMOC =moc_binaryimpl.o \
41 moc_binary.o
42 DIST =
43 TARGET =libbinary.so.1.0.0
44 TARGETA =$(QPEDIR)/plugins/calculator/libbinary.a
45 TARGETD =libbinary.so.1.0.0
46 TARGET0 =libbinary.so
47 TARGET1 =libbinary.so.1
48 TARGET2 =libbinary.so.1.0
49INTERFACE_DECL_PATH = .
50
51####### Implicit rules
52
53.SUFFIXES: .cpp .cxx .cc .C .c
54
55.cpp.o:
56 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
57
58.cxx.o:
59 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
60
61.cc.o:
62 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
63
64.C.o:
65 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
66
67.c.o:
68 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
69
70####### Build rules
71
72
73all: $(QPEDIR)/plugins/calculator/libbinary.so.1.0.0
74
75$(QPEDIR)/plugins/calculator/libbinary.so.1.0.0: $(OBJECTS) $(OBJMOC) $(SUBLIBS)
76 -rm -f $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2)
77 $(LINK) $(LFLAGS) -o $(TARGETD) $(OBJECTS) $(OBJMOC) $(LIBS)
78 -ln -s $(TARGET) $(TARGET0)
79 -ln -s $(TARGET) $(TARGET1)
80 -ln -s $(TARGET) $(TARGET2)
81 -rm -f $(QPEDIR)/plugins/calculator/$(TARGET)
82 -rm -f $(QPEDIR)/plugins/calculator/$(TARGET0)
83 -rm -f $(QPEDIR)/plugins/calculator/$(TARGET1)
84 -rm -f $(QPEDIR)/plugins/calculator/$(TARGET2)
85 -mv $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2) $(QPEDIR)/plugins/calculator/
86
87staticlib: $(TARGETA)
88
89$(TARGETA): $(UICDECLS) $(OBJECTS) $(OBJMOC)
90 -rm -f $(TARGETA)
91 $(AR) $(TARGETA) $(OBJECTS) $(OBJMOC)
92
93moc: $(SRCMOC)
94
95tmake:
96 tmake binary.pro
97
98dist:
99 $(TAR) binary.tar binary.pro $(SOURCES) $(HEADERS) $(INTERFACES) $(DIST)
100 $(GZIP) binary.tar
101
102clean:
103 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) $(TARGET)
104 -rm -f $(TARGET0) $(TARGET1) $(TARGET2) $(TARGETA)
105 -rm -f *~ core
106
107####### Sub-libraries
108
109
110###### Combined headers
111
112
113####### Compile
114
115binaryimpl.o: binaryimpl.cpp \
116 binaryimpl.h \
117 binary.h
118
119binaryfactory.o: binaryfactory.cpp \
120 binaryfactory.h \
121 binaryimpl.h \
122 binary.h
123
124binary.h: binary.ui
125 $(UIC) binary.ui -o $(INTERFACE_DECL_PATH)/binary.h
126
127binary.cpp: binary.ui
128 $(UIC) binary.ui -i binary.h -o binary.cpp
129
130binary.o: binary.cpp \
131 binary.h \
132 binary.ui
133
134moc_binaryimpl.o: moc_binaryimpl.cpp \
135 binaryimpl.h \
136 binary.h
137
138moc_binary.o: moc_binary.cpp \
139 binary.h
140
141moc_binaryimpl.cpp: binaryimpl.h
142 $(MOC) binaryimpl.h -o moc_binaryimpl.cpp
143
144moc_binary.cpp: binary.h
145 $(MOC) binary.h -o moc_binary.cpp
146
diff --git a/noncore/tools/calc2/binary/README b/noncore/tools/calc2/binary/README
new file mode 100644
index 0000000..4937038
--- a/dev/null
+++ b/noncore/tools/calc2/binary/README
@@ -0,0 +1 @@
A binary interface with bitwise operations
diff --git a/noncore/tools/calc2/binary/binary.pro b/noncore/tools/calc2/binary/binary.pro
new file mode 100644
index 0000000..01ba6a4
--- a/dev/null
+++ b/noncore/tools/calc2/binary/binary.pro
@@ -0,0 +1,16 @@
1TEMPLATE = lib
2CONFIG -= moc
3CONFIG += qt release
4
5# Input
6INTERFACES += binary.ui
7HEADERS = binaryimpl.h \
8 binaryfactory.h
9SOURCES = binaryimpl.cpp \
10 binaryfactory.cpp
11
12INCLUDEPATH += $(QPEDIR)/include \
13 $(QPEDIR)/calc2
14DEPENDPATH += $(QPEDIR)/include
15
16DESTDIR = $(QPEDIR)/plugins/calculator
diff --git a/noncore/tools/calc2/binary/binary.ui b/noncore/tools/calc2/binary/binary.ui
new file mode 100644
index 0000000..26064d1
--- a/dev/null
+++ b/noncore/tools/calc2/binary/binary.ui
@@ -0,0 +1,177 @@
1<!DOCTYPE UI><UI>
2<class>FormBinary</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>FormBinary</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>332</width>
15 <height>114</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Binary</string>
21 </property>
22 <grid>
23 <property stdset="1">
24 <name>margin</name>
25 <number>0</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>0</number>
30 </property>
31 <widget row="1" column="0" >
32 <class>QPushButton</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>PB0</cstring>
36 </property>
37 <property stdset="1">
38 <name>maximumSize</name>
39 <size>
40 <width>80</width>
41 <height>80</height>
42 </size>
43 </property>
44 <property stdset="1">
45 <name>text</name>
46 <string>0</string>
47 </property>
48 </widget>
49 <widget row="1" column="1" >
50 <class>QPushButton</class>
51 <property stdset="1">
52 <name>name</name>
53 <cstring>PB1</cstring>
54 </property>
55 <property stdset="1">
56 <name>maximumSize</name>
57 <size>
58 <width>80</width>
59 <height>80</height>
60 </size>
61 </property>
62 <property stdset="1">
63 <name>text</name>
64 <string>1</string>
65 </property>
66 </widget>
67 <widget row="0" column="0" >
68 <class>QPushButton</class>
69 <property stdset="1">
70 <name>name</name>
71 <cstring>PBAnd</cstring>
72 </property>
73 <property stdset="1">
74 <name>maximumSize</name>
75 <size>
76 <width>80</width>
77 <height>80</height>
78 </size>
79 </property>
80 <property stdset="1">
81 <name>text</name>
82 <string>AND</string>
83 </property>
84 </widget>
85 <widget row="0" column="1" >
86 <class>QPushButton</class>
87 <property stdset="1">
88 <name>name</name>
89 <cstring>PBOr</cstring>
90 </property>
91 <property stdset="1">
92 <name>maximumSize</name>
93 <size>
94 <width>80</width>
95 <height>80</height>
96 </size>
97 </property>
98 <property stdset="1">
99 <name>text</name>
100 <string>OR</string>
101 </property>
102 </widget>
103 <widget row="0" column="2" >
104 <class>QPushButton</class>
105 <property stdset="1">
106 <name>name</name>
107 <cstring>PBNot</cstring>
108 </property>
109 <property stdset="1">
110 <name>maximumSize</name>
111 <size>
112 <width>80</width>
113 <height>80</height>
114 </size>
115 </property>
116 <property stdset="1">
117 <name>text</name>
118 <string>NOT</string>
119 </property>
120 </widget>
121 <widget row="1" column="2" >
122 <class>QPushButton</class>
123 <property stdset="1">
124 <name>name</name>
125 <cstring>PBSHL</cstring>
126 </property>
127 <property stdset="1">
128 <name>maximumSize</name>
129 <size>
130 <width>80</width>
131 <height>80</height>
132 </size>
133 </property>
134 <property stdset="1">
135 <name>text</name>
136 <string>&lt;-</string>
137 </property>
138 </widget>
139 <widget row="0" column="3" >
140 <class>QPushButton</class>
141 <property stdset="1">
142 <name>name</name>
143 <cstring>PBXor</cstring>
144 </property>
145 <property stdset="1">
146 <name>maximumSize</name>
147 <size>
148 <width>80</width>
149 <height>80</height>
150 </size>
151 </property>
152 <property stdset="1">
153 <name>text</name>
154 <string>XOR</string>
155 </property>
156 </widget>
157 <widget row="1" column="3" >
158 <class>QPushButton</class>
159 <property stdset="1">
160 <name>name</name>
161 <cstring>PBSHR</cstring>
162 </property>
163 <property stdset="1">
164 <name>maximumSize</name>
165 <size>
166 <width>80</width>
167 <height>80</height>
168 </size>
169 </property>
170 <property stdset="1">
171 <name>text</name>
172 <string>-&gt;</string>
173 </property>
174 </widget>
175 </grid>
176</widget>
177</UI>
diff --git a/noncore/tools/calc2/binary/binaryfactory.cpp b/noncore/tools/calc2/binary/binaryfactory.cpp
new file mode 100644
index 0000000..110334f
--- a/dev/null
+++ b/noncore/tools/calc2/binary/binaryfactory.cpp
@@ -0,0 +1,51 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** GNU General Public License version 2 as published by the Free Software
10** Foundation and appearing in the file LICENSE.GPL included in the
11** packaging of this file.
12**
13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15**
16** See http://www.trolltech.com/gpl/ for GPL licensing information.
17**
18** Contact info@trolltech.com if any conditions of this licensing are
19** not clear to you.
20**
21**********************************************************************/
22
23#include "binaryfactory.h"
24#include "binaryimpl.h"
25#include <engine.h>
26
27QWidget *BinaryInterface::getPlugin ( Engine *e, QWidget *parent ) {
28 if ( !input )
29 input = new FormBinaryImpl ( e, parent );
30 return input;
31}
32
33#ifndef QT_NO_COMPONENT
34QRESULT BinaryInterface::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
35{
36 *iface = 0;
37 if ( uuid == IID_QUnknown )
38 *iface = this;
39 else if ( uuid == IID_Calc )
40 *iface = this;
41
42 if ( *iface )
43 (*iface)->addRef();
44 return QS_OK;
45}
46
47Q_EXPORT_INTERFACE()
48{
49 Q_CREATE_INSTANCE( BinaryInterface )
50}
51#endif
diff --git a/noncore/tools/calc2/binary/binaryfactory.h b/noncore/tools/calc2/binary/binaryfactory.h
new file mode 100644
index 0000000..e015384
--- a/dev/null
+++ b/noncore/tools/calc2/binary/binaryfactory.h
@@ -0,0 +1,46 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef BINARYIMPL_H
22#define BINARYIMPL_H
23
24#include "binaryimpl.h"
25#include <plugininterface.h>
26#include <engine.h>
27
28class BinaryInterface : public CalcInterface
29{
30public:
31 BinaryInterface(){input = 0;};
32 virtual ~BinaryInterface(){};
33
34#ifndef QT_NO_COMPONENT
35 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
36 Q_REFCOUNT
37#endif
38
39 QWidget *getPlugin( Engine *, QWidget *parent );
40
41private:
42 FormBinaryImpl *input;
43 ulong ref;
44};
45
46#endif
diff --git a/noncore/tools/calc2/binary/binaryimpl.cpp b/noncore/tools/calc2/binary/binaryimpl.cpp
new file mode 100644
index 0000000..ffc56ad
--- a/dev/null
+++ b/noncore/tools/calc2/binary/binaryimpl.cpp
@@ -0,0 +1,110 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "binaryimpl.h"
22#include <instruction.h>
23
24class iXOR : public Instruction {
25public:
26 iXOR():Instruction(){};
27 ~iXOR(){};
28 Data eval(Data num) {
29 Data result;
30 result.i = num.i ^ acc.i;
31 return result;
32 };
33};
34class iAND : public Instruction {
35public:
36 iAND():Instruction(){};
37 ~iAND(){};
38 Data eval(Data num) {
39 Data result;
40 result.i = num.i & acc.i;
41 return result;
42 };
43};
44class iNOT : public Instruction {
45public:
46 iNOT():Instruction(){};
47 ~iNOT(){};
48 Data eval(Data num) {
49 Data result;
50 result.i = ~ num.i;
51 return result;
52 };
53};
54class iOR : public Instruction {
55public:
56 iOR():Instruction(){};
57 ~iOR(){};
58 Data eval(Data num) {
59 Data result;
60 result.i = num.i | acc.i;
61 return result;
62 };
63};
64class iLSH : public Instruction {
65public:
66 iLSH():Instruction(){};
67 ~iLSH(){};
68 Data eval(Data num) {
69 Data result;
70 result.i = num.i << 1;
71 return result;
72 };
73};
74class iRSH : public Instruction {
75public:
76 iRSH():Instruction(){};
77 ~iRSH(){};
78 Data eval(Data num) {
79 Data result;
80 result.i = num.i >> 1;
81 return result;
82 };
83};
84
85void FormBinaryImpl::val0Clicked() {
86 engine->pushValue('0');
87}
88
89void FormBinaryImpl::val1Clicked() {
90 engine->pushValue('1');
91}
92
93void FormBinaryImpl::XORClicked() {
94 engine->pushInstruction(new iXOR());
95}
96void FormBinaryImpl::ANDClicked() {
97 engine->pushInstruction(new iAND());
98}
99void FormBinaryImpl::NOTClicked() {
100 engine->immediateInstruction(new iNOT());
101}
102void FormBinaryImpl::ORClicked() {
103 engine->pushInstruction(new iOR());
104}
105void FormBinaryImpl::LSHClicked() {
106 engine->immediateInstruction(new iLSH());
107}
108void FormBinaryImpl::RSHClicked() {
109 engine->immediateInstruction(new iRSH());
110}
diff --git a/noncore/tools/calc2/binary/binaryimpl.h b/noncore/tools/calc2/binary/binaryimpl.h
new file mode 100644
index 0000000..bf9e3a7
--- a/dev/null
+++ b/noncore/tools/calc2/binary/binaryimpl.h
@@ -0,0 +1,50 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef FORMBINARYINPUTIMPL
21#define FORMBINARYINPUTIMPL
22
23#include "binary.h"
24#include <engine.h>
25
26class FormBinaryImpl : public FormBinary {
27Q_OBJECT
28public:
29 FormBinaryImpl(Engine *e,QWidget *p) : FormBinary (p,"Binary") {
30 engine = e;
31 engine->setRepresentation(rBin);
32 };
33 ~FormBinaryImpl(){};
34private:
35 Engine *engine;
36
37private slots:
38 void val0Clicked();
39 void val1Clicked();
40
41 void XORClicked();
42 void ANDClicked();
43 void NOTClicked();
44 void ORClicked();
45
46 void LSHClicked();
47 void RSHClicked();
48};
49
50#endif
diff --git a/noncore/tools/calc2/calc.cpp b/noncore/tools/calc2/calc.cpp
new file mode 100644
index 0000000..883ab33
--- a/dev/null
+++ b/noncore/tools/calc2/calc.cpp
@@ -0,0 +1,104 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qvaluelist.h>
22#include <qpe/qpeapplication.h>
23#include <qdir.h>
24#include <qwidgetstack.h>
25
26#include "calc.h"
27#include "plugininterface.h"
28
29calc::calc (QWidget * p = 0, const char *n = 0):QWidget (p, n)
30{
31 setCaption (tr ("Calculator"));
32
33// widgets
34 LCD = new QLCDNumber (this);
35 LCD->setMaximumSize (QSize (240, 30));
36 LCD->setNumDigits(12);
37LCD->setSegmentStyle(QLCDNumber::Filled);
38 pluginWidgetStack = new QWidgetStack (this);
39
40// layout widgets
41 calculatorLayout = new QVBoxLayout (this);
42 calculatorLayout->addWidget (LCD);
43 calculatorLayout->addWidget (pluginWidgetStack);
44
45// no formatting of display for now
46 connect (&engine, SIGNAL(display (double)), LCD, SLOT(display (double)));
47 connect (&engine, SIGNAL(display (const QString &)), LCD, SLOT(display (const QString &)));
48 connect (&engine, SIGNAL(setBinMode()), LCD, SLOT(setBinMode()));
49 connect (&engine, SIGNAL(setOctMode()), LCD, SLOT(setOctMode()));
50 connect (&engine, SIGNAL(setDecMode()), LCD, SLOT(setDecMode()));
51 connect (&engine, SIGNAL(setHexMode()), LCD, SLOT(setHexMode()));
52
53#ifndef NO_PLUGINS
54// load plugins
55 QValueList < Plugin >::Iterator mit;
56 for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) {
57 (*mit).interface->release ();
58 (*mit).library->unload ();
59 delete (*mit).library;
60 }
61 pluginList.clear ();
62
63 QString path = QPEApplication::qpeDir() + "/plugins/calculator";
64 QDir dir (path, "lib*.so");
65 QStringList list = dir.entryList ();
66
67 QStringList::Iterator it;
68 for (it = list.begin (); it != list.end (); ++it) {
69 CalcInterface *iface = 0;
70 QLibrary *lib = new QLibrary (path + "/" + *it);
71
72 Plugin plugin;
73 plugin.pluginWidget = 0;
74
75 if (lib->queryInterface (IID_Calc, (QUnknownInterface **) & iface) ==
76 QS_OK) {
77 plugin.library = lib;
78 plugin.interface = iface;
79 plugin.pluginWidget = plugin.interface->getPlugin(&engine,pluginWidgetStack);
80 if (plugin.pluginWidget)
81 pluginWidgetStack->addWidget (plugin.pluginWidget, pluginList.count());
82 pluginList.append (plugin);
83 } else {
84 delete lib;
85 }
86 }
87 setMode (1);
88#else
89// load simple interface
90#endif
91}
92
93calc::~calc ()
94{
95#ifndef NO_PLUGINS
96 QValueList < Plugin >::Iterator mit;
97 for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) {
98 (*mit).interface->release ();
99 (*mit).library->unload ();
100 delete (*mit).library;
101 }
102#endif
103}
104
diff --git a/noncore/tools/calc2/calc.h b/noncore/tools/calc2/calc.h
new file mode 100644
index 0000000..b52356d
--- a/dev/null
+++ b/noncore/tools/calc2/calc.h
@@ -0,0 +1,69 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef CALC_H
22#define CALC_H
23
24#ifdef QT_NO_COMPONENT
25#define NO_PLUGINS
26#endif
27
28#include <qlayout.h>
29#include <qwidgetstack.h>
30
31#ifndef NO_PLUGINS
32#include <qvaluelist.h>
33#include <qpe/qlibrary.h>
34#endif
35
36#include "engine.h"
37#include "plugininterface.h"
38
39struct Plugin {
40#ifndef NO_PLUGINS
41 QLibrary *library;
42#endif
43 QWidget *pluginWidget;
44 CalcInterface *interface;
45 QString name;
46};
47
48class calc:public QWidget {
49
50Q_OBJECT
51public:
52 calc (QWidget * p = 0, const char *n = 0);
53 ~calc ();
54
55private:
56#ifndef NO_PLUGINS
57 void loadPlugins ();
58 QValueList < Plugin > pluginList;
59#endif
60 QVBoxLayout *calculatorLayout;
61 QWidgetStack *pluginWidgetStack;
62 QLCDNumber *LCD;
63 Engine engine;
64
65public slots:
66 void setMode(int m){pluginWidgetStack->raiseWidget(m);};
67};
68
69#endif
diff --git a/noncore/tools/calc2/calc.pro b/noncore/tools/calc2/calc.pro
new file mode 100644
index 0000000..c10232a
--- a/dev/null
+++ b/noncore/tools/calc2/calc.pro
@@ -0,0 +1,11 @@
1TEMPLATE = app
2CONFIG += qt release
3
4# Input
5HEADERS += calc.h plugininterface.h instruction.h engine.h stdinstructions.h
6SOURCES += calc.cpp main.cpp engine.cpp
7
8INCLUDEPATH += $(QPEDIR)/include
9DEPENDPATH += $(QPEDIR)/include
10LIBS += -lqpe -Wl,-export-dynamic
11
diff --git a/noncore/tools/calc2/engine.cpp b/noncore/tools/calc2/engine.cpp
new file mode 100644
index 0000000..a9a47c4
--- a/dev/null
+++ b/noncore/tools/calc2/engine.cpp
@@ -0,0 +1,214 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "engine.h"
22#include <qstring.h>
23#include <math.h>
24#include <qlcdnumber.h>
25
26Data Engine::evalStack (Data num, bool inbrace = FALSE)
27{
28 if (state != sError) {
29 Instruction *i;
30
31// Pop the next op from the stack
32 while (!stack.isEmpty () && (braces || !inbrace)) {
33 i = stack.pop ();
34
35// Check this ops prec vs next ops prec
36 if (!stack.isEmpty ())
37 if (i->precedence <= stack.top()->precedence)
38 i->acc = evalStack (i->acc, inbrace);
39
40// Evaluate this instruction
41 num = i->eval (num);
42
43// Error-check ( change this to work for all types )
44 if (isnan (num.dbl) || isinf (num.dbl)) {
45 qDebug ("bad result from operation");
46 state = sError;
47 clearData(&num);
48 return num;
49 }
50 }
51 }
52 return num;
53}
54
55// Plugins call this to request the stack be evaluated
56void Engine::eval ()
57{
58 num = evalStack (num);
59 if (state != sError) {
60 displayData(num);
61 state = sStart;
62 }
63// if the user didnt close all their braces, its no big deal
64 braces = 0;
65}
66
67void Engine::immediateInstruction (Instruction * i)
68{
69 if (state != sError) {
70 i->setRep(currentRep);
71 num = i->eval (num);
72 displayData(num);
73 state = sStart;
74 }
75}
76
77void Engine::pushInstruction (Instruction * i)
78{
79 if (state != sError) {
80 i->setRep(currentRep);
81 i->acc = num;
82 stack.push (i);
83 state = sStart;
84 }
85}
86
87void Engine::pushValue (char v)
88{
89 if (state == sAppend) {
90 bool ok = FALSE;
91 switch (currentRep) {
92 case rDouble:
93 displayString.append(v);
94 num.dbl=displayString.toDouble(&ok);
95 break;
96 case rFraction:
97 break;
98 default:
99 displayString.append(v);
100 num.i=displayString.toInt(&ok, calcBase());
101 };
102 if (!ok) {
103 state = sError;
104 qDebug("pushValue() - num->string conversion");
105 } else {
106 const QString constString = displayString;
107 emit(display(constString));
108 };
109
110 } else if (state == sStart) {
111 softReset();
112 displayString.truncate(0);
113 state = sAppend;
114 pushValue (v);
115 } else if (state == sError) {
116 qDebug ("in error state");
117 return;
118 }
119}
120
121void Engine::del ()
122{
123 bool ok;
124 switch (currentRep) {
125 case rDouble:
126 displayString.truncate(displayString.length());
127 num.dbl=displayString.toDouble(&ok);
128 break;
129 case rFraction:
130 qDebug("not available");
131 break;
132 default:
133 displayString.truncate(displayString.length());
134 num.i = displayString.toInt(&ok, calcBase());
135 };
136
137 if (!ok) {
138 state = sError;
139 qDebug("del() - num->string conversion");
140 } else {
141 const QString constString = displayString;
142 emit(display(constString));
143 };
144}
145
146void Engine::displayData(Data d) {
147 switch (currentRep) {
148 case rDouble:
149 displayString.setNum(d.dbl);
150 break;
151 case rFraction:
152 qDebug("fractional display not yet impl");
153 break;
154 default:
155 displayString.setNum(d.i, calcBase());
156 break;
157 };
158 const QString constString= displayString;
159 emit(display(constString));
160}
161
162// Returns the base when Rep is an integer type
163int Engine::calcBase () {
164 switch (currentRep) {
165 case rBin:
166 return 2;
167 case rOct:
168 return 8;
169 case rDec:
170 return 10;
171 case rHex:
172 return 16;
173 default:
174 state = sError;
175 qDebug("Error - attempt to calc base for non-integer");
176 return 10;
177 };
178}
179
180// Special instruction for internal use only
181class iOpenBrace:public Instruction {
182 public:
183 iOpenBrace (Engine *e):Instruction (100) {engine = e;};
184 ~iOpenBrace () {};
185
186 Data eval (Data num) {
187 engine->decBraces();
188 return num;
189 };
190 private:
191 Engine *engine;
192};
193
194void Engine::openBrace() {
195 pushInstruction(new iOpenBrace(this));
196}
197
198void Engine::closeBrace() {
199 braces++;evalStack(num,TRUE);
200}
201
202// will need to show and hide display widgets
203void Engine::setRepresentation(Representation r) {
204 currentRep = r;
205 clearData(&num);
206 clearData(&mem);
207 state = sStart;
208}
209
210void Engine::clearData(Data *d) {
211 d->i = d->fraction.numerator = d->fraction.denominator = 0;
212 d->dbl = 0;
213}
214
diff --git a/noncore/tools/calc2/engine.h b/noncore/tools/calc2/engine.h
new file mode 100644
index 0000000..15c9aa1
--- a/dev/null
+++ b/noncore/tools/calc2/engine.h
@@ -0,0 +1,111 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef ENGINE_H
22#define ENGINE_H
23
24#include <qwidget.h>
25 #include <qstack.h>// Instruction stack
26 #include <qstring.h>// Display
27#include "instruction.h"
28
29// Possible states
30enum State {
31 sStart,// start inputting a new number
32 sAppend,// continue inputting a number
33 sError
34};
35
36// State machine
37class Engine:public QWidget {
38
39Q_OBJECT
40public:
41 Engine (QWidget * parent = 0, const char *name = 0):QWidget (parent, name) {
42 hardReset();
43 setRepresentation(rDec);
44 };
45
46 ~Engine () { };
47
48 void immediateInstruction (Instruction *);
49 void pushInstruction (Instruction *);
50 void eval ();
51
52 void pushValue (char);
53 void del ();
54
55 void openBrace ();
56 void closeBrace ();
57
58 void softReset () {// clears the number being inputted
59 decimalPlaces = -1;
60 clearData(&num);
61 displayData(num);
62 state = sStart;
63 };
64 void hardReset () {// a "real" reset of the stack
65 stack.clear ();
66 memClear();
67 braces = 0;
68 softReset ();
69 };
70
71 void memSave () {
72 mem = num;
73 };
74 void memRecall () {
75 num = mem;
76 state = sStart;
77 displayData(num);
78 };
79 void memClear () {
80 clearData(&mem);
81 };
82
83 // rFraction will require a special display enabled here
84 void setRepresentation(Representation);
85
86 // you dont want to call this
87 void decBraces(void){ braces--; };
88
89private:
90 void displayData(Data d);
91 void clearData(Data *d);
92 int calcBase();
93 Data evalStack (Data, bool);
94 Data num,mem;
95 State state;
96 QStack < Instruction > stack;
97 Representation currentRep;
98 int braces, decimalPlaces; // count of finishing 0's in num
99 QString displayString; // saves instatiating it over and over
100
101signals:
102 void display(const QString &);
103 void display(double); // could get rid of this and
104 // use a QLabel instead.
105 void setHexMode();
106 void setBinMode();
107 void setDecMode();
108 void setOctMode();
109};
110
111#endif
diff --git a/noncore/tools/calc2/instruction.h b/noncore/tools/calc2/instruction.h
new file mode 100644
index 0000000..6077bf0
--- a/dev/null
+++ b/noncore/tools/calc2/instruction.h
@@ -0,0 +1,69 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef INSTRUCTION_H
21#define INSTRUCTION_H
22
23/* Internal representation of data
24The first four types indicate an int,
25that is, Data.i, and are incompatible
26with the other two types.
27
28- Plugin is responsible for telling engine
29which Rep to use at any given time
30- Instructions from that plugin only
31have to handle that representation
32- Engine is responsible for error-checking
33according to its current rep and display */
34enum Representation {
35 rBin,
36 rOct,
37 rDec,
38 rHex,
39 rDouble,
40 rFraction
41};
42
43// An atom of data
44union Data {
45 int i;
46 double dbl;
47 struct Fraction {
48 int numerator, denominator;
49 } fraction;
50};
51
52// Instruction base class
53class Instruction {
54public:
55 Instruction (int p = 0) {
56 precedence = p;
57 };
58
59 virtual ~ Instruction () {};
60
61 virtual Data eval(Data) = 0;
62 void setRep(Representation r) { rep = r; };
63
64 Representation rep;
65 Data acc;
66 int precedence;
67};
68
69#endif
diff --git a/noncore/tools/calc2/main.cpp b/noncore/tools/calc2/main.cpp
new file mode 100644
index 0000000..ebfcc28
--- a/dev/null
+++ b/noncore/tools/calc2/main.cpp
@@ -0,0 +1,34 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qpe/qpeapplication.h>
21#include "calc.h"
22
23int main (int argc, char **argv)
24{
25 QPEApplication a (argc, argv);
26
27 calc mw;
28
29 QPEApplication::setInputMethodHint (&mw, QPEApplication::AlwaysOff);
30 mw.setCaption (calc::tr ("Calculator"));
31 a.showMainWidget (&mw);
32
33 return a.exec ();
34}
diff --git a/noncore/tools/calc2/plugininterface.h b/noncore/tools/calc2/plugininterface.h
new file mode 100644
index 0000000..df6db9d
--- a/dev/null
+++ b/noncore/tools/calc2/plugininterface.h
@@ -0,0 +1,45 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef CALCINTERFACE_H
22#define CALCINTERFACE_H
23
24#include <qnamespace.h>
25#include <qstring.h>
26#include <qlcdnumber.h>
27#include <qpe/qcom.h>
28
29#include "engine.h"
30
31#ifndef QT_NO_COMPONENT
32// {3CE88B66-B3FD-4580-9D04-77338A31A667}
33#ifndef IID_Calc
34#define IID_Calc QUuid( 0x3ce88b66, 0xb3fd, 0x4580, 0x9d, 0x04, 0x77, 0x33, 0x8a, 0x31, 0xa6, 0x67)
35#endif
36#endif
37
38class QWidget;
39class QObject;
40
41struct CalcInterface:public QUnknownInterface {
42 virtual QWidget *getPlugin (Engine *e, QWidget * parent) = 0;
43};
44
45#endif
diff --git a/noncore/tools/calc2/simple/README b/noncore/tools/calc2/simple/README
new file mode 100644
index 0000000..37acb64
--- a/dev/null
+++ b/noncore/tools/calc2/simple/README
@@ -0,0 +1 @@
A simple interface with no operator precedence.
diff --git a/noncore/tools/calc2/simple/simple.pro b/noncore/tools/calc2/simple/simple.pro
new file mode 100644
index 0000000..92378a6
--- a/dev/null
+++ b/noncore/tools/calc2/simple/simple.pro
@@ -0,0 +1,14 @@
1TEMPLATE = lib
2CONFIG -= moc
3CONFIG += qt release
4
5# Input
6INTERFACES += simple.ui
7HEADERS = simpleimpl.h simplefactory.h stdinstructions.h
8SOURCES = simpleimpl.cpp simplefactory.cpp
9
10INCLUDEPATH += $(QPEDIR)/include \
11 $(QPEDIR)/calc2
12DEPENDPATH += $(QPEDIR)/include
13
14DESTDIR = $(QPEDIR)/plugins/calculator
diff --git a/noncore/tools/calc2/simple/simple.ui b/noncore/tools/calc2/simple/simple.ui
new file mode 100644
index 0000000..af12905
--- a/dev/null
+++ b/noncore/tools/calc2/simple/simple.ui
@@ -0,0 +1,704 @@
1<!DOCTYPE UI><UI>
2<class>FormSimple</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>FormSimple</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>73</x>
13 <y>0</y>
14 <width>240</width>
15 <height>320</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>sizePolicy</name>
20 <sizepolicy>
21 <hsizetype>4</hsizetype>
22 <vsizetype>4</vsizetype>
23 </sizepolicy>
24 </property>
25 <property stdset="1">
26 <name>maximumSize</name>
27 <size>
28 <width>240</width>
29 <height>320</height>
30 </size>
31 </property>
32 <property stdset="1">
33 <name>baseSize</name>
34 <size>
35 <width>240</width>
36 <height>240</height>
37 </size>
38 </property>
39 <property stdset="1">
40 <name>caption</name>
41 <string>Simple</string>
42 </property>
43 <grid>
44 <property stdset="1">
45 <name>margin</name>
46 <number>0</number>
47 </property>
48 <property stdset="1">
49 <name>spacing</name>
50 <number>0</number>
51 </property>
52 <widget row="4" column="2" >
53 <class>QPushButton</class>
54 <property stdset="1">
55 <name>name</name>
56 <cstring>PBEval</cstring>
57 </property>
58 <property stdset="1">
59 <name>sizePolicy</name>
60 <sizepolicy>
61 <hsizetype>4</hsizetype>
62 <vsizetype>4</vsizetype>
63 </sizepolicy>
64 </property>
65 <property stdset="1">
66 <name>maximumSize</name>
67 <size>
68 <width>160</width>
69 <height>80</height>
70 </size>
71 </property>
72 <property stdset="1">
73 <name>text</name>
74 <string>=</string>
75 </property>
76 </widget>
77 <widget row="2" column="1" >
78 <class>QPushButton</class>
79 <property stdset="1">
80 <name>name</name>
81 <cstring>PB5</cstring>
82 </property>
83 <property stdset="1">
84 <name>sizePolicy</name>
85 <sizepolicy>
86 <hsizetype>4</hsizetype>
87 <vsizetype>4</vsizetype>
88 </sizepolicy>
89 </property>
90 <property stdset="1">
91 <name>maximumSize</name>
92 <size>
93 <width>80</width>
94 <height>80</height>
95 </size>
96 </property>
97 <property stdset="1">
98 <name>text</name>
99 <string>5</string>
100 </property>
101 </widget>
102 <widget row="4" column="0" >
103 <class>QPushButton</class>
104 <property stdset="1">
105 <name>name</name>
106 <cstring>PBDecimal</cstring>
107 </property>
108 <property stdset="1">
109 <name>sizePolicy</name>
110 <sizepolicy>
111 <hsizetype>4</hsizetype>
112 <vsizetype>4</vsizetype>
113 </sizepolicy>
114 </property>
115 <property stdset="1">
116 <name>maximumSize</name>
117 <size>
118 <width>80</width>
119 <height>80</height>
120 </size>
121 </property>
122 <property stdset="1">
123 <name>text</name>
124 <string>.</string>
125 </property>
126 </widget>
127 <widget row="3" column="2" >
128 <class>QPushButton</class>
129 <property stdset="1">
130 <name>name</name>
131 <cstring>PB3</cstring>
132 </property>
133 <property stdset="1">
134 <name>sizePolicy</name>
135 <sizepolicy>
136 <hsizetype>4</hsizetype>
137 <vsizetype>4</vsizetype>
138 </sizepolicy>
139 </property>
140 <property stdset="1">
141 <name>maximumSize</name>
142 <size>
143 <width>80</width>
144 <height>80</height>
145 </size>
146 </property>
147 <property stdset="1">
148 <name>text</name>
149 <string>3</string>
150 </property>
151 </widget>
152 <widget row="3" column="1" >
153 <class>QPushButton</class>
154 <property stdset="1">
155 <name>name</name>
156 <cstring>PB2</cstring>
157 </property>
158 <property stdset="1">
159 <name>sizePolicy</name>
160 <sizepolicy>
161 <hsizetype>4</hsizetype>
162 <vsizetype>4</vsizetype>
163 </sizepolicy>
164 </property>
165 <property stdset="1">
166 <name>maximumSize</name>
167 <size>
168 <width>80</width>
169 <height>80</height>
170 </size>
171 </property>
172 <property stdset="1">
173 <name>text</name>
174 <string>2</string>
175 </property>
176 </widget>
177 <widget row="2" column="0" >
178 <class>QPushButton</class>
179 <property stdset="1">
180 <name>name</name>
181 <cstring>PB4</cstring>
182 </property>
183 <property stdset="1">
184 <name>sizePolicy</name>
185 <sizepolicy>
186 <hsizetype>4</hsizetype>
187 <vsizetype>4</vsizetype>
188 </sizepolicy>
189 </property>
190 <property stdset="1">
191 <name>maximumSize</name>
192 <size>
193 <width>80</width>
194 <height>80</height>
195 </size>
196 </property>
197 <property stdset="1">
198 <name>text</name>
199 <string>4</string>
200 </property>
201 </widget>
202 <widget row="2" column="2" >
203 <class>QPushButton</class>
204 <property stdset="1">
205 <name>name</name>
206 <cstring>PB6</cstring>
207 </property>
208 <property stdset="1">
209 <name>sizePolicy</name>
210 <sizepolicy>
211 <hsizetype>4</hsizetype>
212 <vsizetype>4</vsizetype>
213 </sizepolicy>
214 </property>
215 <property stdset="1">
216 <name>maximumSize</name>
217 <size>
218 <width>80</width>
219 <height>80</height>
220 </size>
221 </property>
222 <property stdset="1">
223 <name>text</name>
224 <string>6</string>
225 </property>
226 </widget>
227 <widget row="3" column="3" >
228 <class>QPushButton</class>
229 <property stdset="1">
230 <name>name</name>
231 <cstring>PBMul</cstring>
232 </property>
233 <property stdset="1">
234 <name>sizePolicy</name>
235 <sizepolicy>
236 <hsizetype>4</hsizetype>
237 <vsizetype>4</vsizetype>
238 </sizepolicy>
239 </property>
240 <property stdset="1">
241 <name>maximumSize</name>
242 <size>
243 <width>80</width>
244 <height>80</height>
245 </size>
246 </property>
247 <property stdset="1">
248 <name>text</name>
249 <string>*</string>
250 </property>
251 </widget>
252 <widget row="2" column="3" >
253 <class>QPushButton</class>
254 <property stdset="1">
255 <name>name</name>
256 <cstring>PBSub</cstring>
257 </property>
258 <property stdset="1">
259 <name>sizePolicy</name>
260 <sizepolicy>
261 <hsizetype>4</hsizetype>
262 <vsizetype>4</vsizetype>
263 </sizepolicy>
264 </property>
265 <property stdset="1">
266 <name>maximumSize</name>
267 <size>
268 <width>80</width>
269 <height>80</height>
270 </size>
271 </property>
272 <property stdset="1">
273 <name>text</name>
274 <string>-</string>
275 </property>
276 </widget>
277 <widget row="1" column="3" >
278 <class>QPushButton</class>
279 <property stdset="1">
280 <name>name</name>
281 <cstring>PBAdd</cstring>
282 </property>
283 <property stdset="1">
284 <name>sizePolicy</name>
285 <sizepolicy>
286 <hsizetype>4</hsizetype>
287 <vsizetype>4</vsizetype>
288 </sizepolicy>
289 </property>
290 <property stdset="1">
291 <name>maximumSize</name>
292 <size>
293 <width>80</width>
294 <height>80</height>
295 </size>
296 </property>
297 <property stdset="1">
298 <name>text</name>
299 <string>+</string>
300 </property>
301 </widget>
302 <widget row="1" column="2" >
303 <class>QPushButton</class>
304 <property stdset="1">
305 <name>name</name>
306 <cstring>PB9</cstring>
307 </property>
308 <property stdset="1">
309 <name>sizePolicy</name>
310 <sizepolicy>
311 <hsizetype>4</hsizetype>
312 <vsizetype>4</vsizetype>
313 </sizepolicy>
314 </property>
315 <property stdset="1">
316 <name>maximumSize</name>
317 <size>
318 <width>80</width>
319 <height>80</height>
320 </size>
321 </property>
322 <property stdset="1">
323 <name>text</name>
324 <string>9</string>
325 </property>
326 </widget>
327 <widget row="1" column="0" >
328 <class>QPushButton</class>
329 <property stdset="1">
330 <name>name</name>
331 <cstring>PB7</cstring>
332 </property>
333 <property stdset="1">
334 <name>enabled</name>
335 <bool>true</bool>
336 </property>
337 <property stdset="1">
338 <name>sizePolicy</name>
339 <sizepolicy>
340 <hsizetype>4</hsizetype>
341 <vsizetype>4</vsizetype>
342 </sizepolicy>
343 </property>
344 <property stdset="1">
345 <name>maximumSize</name>
346 <size>
347 <width>80</width>
348 <height>80</height>
349 </size>
350 </property>
351 <property stdset="1">
352 <name>text</name>
353 <string>7</string>
354 </property>
355 </widget>
356 <widget row="3" column="0" >
357 <class>QPushButton</class>
358 <property stdset="1">
359 <name>name</name>
360 <cstring>PB1</cstring>
361 </property>
362 <property stdset="1">
363 <name>sizePolicy</name>
364 <sizepolicy>
365 <hsizetype>4</hsizetype>
366 <vsizetype>4</vsizetype>
367 </sizepolicy>
368 </property>
369 <property stdset="1">
370 <name>maximumSize</name>
371 <size>
372 <width>80</width>
373 <height>80</height>
374 </size>
375 </property>
376 <property stdset="1">
377 <name>text</name>
378 <string>1</string>
379 </property>
380 </widget>
381 <widget row="4" column="1" >
382 <class>QPushButton</class>
383 <property stdset="1">
384 <name>name</name>
385 <cstring>PB0</cstring>
386 </property>
387 <property stdset="1">
388 <name>sizePolicy</name>
389 <sizepolicy>
390 <hsizetype>4</hsizetype>
391 <vsizetype>4</vsizetype>
392 </sizepolicy>
393 </property>
394 <property stdset="1">
395 <name>maximumSize</name>
396 <size>
397 <width>160</width>
398 <height>80</height>
399 </size>
400 </property>
401 <property stdset="1">
402 <name>text</name>
403 <string>0</string>
404 </property>
405 </widget>
406 <widget row="4" column="3" >
407 <class>QPushButton</class>
408 <property stdset="1">
409 <name>name</name>
410 <cstring>PBDiv</cstring>
411 </property>
412 <property stdset="1">
413 <name>sizePolicy</name>
414 <sizepolicy>
415 <hsizetype>4</hsizetype>
416 <vsizetype>4</vsizetype>
417 </sizepolicy>
418 </property>
419 <property stdset="1">
420 <name>maximumSize</name>
421 <size>
422 <width>80</width>
423 <height>80</height>
424 </size>
425 </property>
426 <property stdset="1">
427 <name>text</name>
428 <string>/</string>
429 </property>
430 <property stdset="1">
431 <name>autoRepeat</name>
432 <bool>true</bool>
433 </property>
434 </widget>
435 <widget row="1" column="1" >
436 <class>QPushButton</class>
437 <property stdset="1">
438 <name>name</name>
439 <cstring>PB8</cstring>
440 </property>
441 <property stdset="1">
442 <name>sizePolicy</name>
443 <sizepolicy>
444 <hsizetype>4</hsizetype>
445 <vsizetype>4</vsizetype>
446 </sizepolicy>
447 </property>
448 <property stdset="1">
449 <name>maximumSize</name>
450 <size>
451 <width>80</width>
452 <height>80</height>
453 </size>
454 </property>
455 <property stdset="1">
456 <name>text</name>
457 <string>8</string>
458 </property>
459 </widget>
460 <widget row="0" column="0" >
461 <class>QPushButton</class>
462 <property stdset="1">
463 <name>name</name>
464 <cstring>PBMPlus</cstring>
465 </property>
466 <property stdset="1">
467 <name>sizePolicy</name>
468 <sizepolicy>
469 <hsizetype>4</hsizetype>
470 <vsizetype>4</vsizetype>
471 </sizepolicy>
472 </property>
473 <property stdset="1">
474 <name>maximumSize</name>
475 <size>
476 <width>80</width>
477 <height>80</height>
478 </size>
479 </property>
480 <property stdset="1">
481 <name>text</name>
482 <string>M+</string>
483 </property>
484 </widget>
485 <widget row="0" column="3" >
486 <class>QPushButton</class>
487 <property stdset="1">
488 <name>name</name>
489 <cstring>PBCE</cstring>
490 </property>
491 <property stdset="1">
492 <name>sizePolicy</name>
493 <sizepolicy>
494 <hsizetype>4</hsizetype>
495 <vsizetype>4</vsizetype>
496 </sizepolicy>
497 </property>
498 <property stdset="1">
499 <name>maximumSize</name>
500 <size>
501 <width>80</width>
502 <height>80</height>
503 </size>
504 </property>
505 <property stdset="1">
506 <name>text</name>
507 <string>CE</string>
508 </property>
509 </widget>
510 <widget row="0" column="2" >
511 <class>QPushButton</class>
512 <property stdset="1">
513 <name>name</name>
514 <cstring>PBMC</cstring>
515 </property>
516 <property stdset="1">
517 <name>sizePolicy</name>
518 <sizepolicy>
519 <hsizetype>4</hsizetype>
520 <vsizetype>4</vsizetype>
521 </sizepolicy>
522 </property>
523 <property stdset="1">
524 <name>maximumSize</name>
525 <size>
526 <width>80</width>
527 <height>80</height>
528 </size>
529 </property>
530 <property stdset="1">
531 <name>text</name>
532 <string>MC</string>
533 </property>
534 </widget>
535 <widget row="0" column="1" >
536 <class>QPushButton</class>
537 <property stdset="1">
538 <name>name</name>
539 <cstring>PBMR</cstring>
540 </property>
541 <property stdset="1">
542 <name>sizePolicy</name>
543 <sizepolicy>
544 <hsizetype>4</hsizetype>
545 <vsizetype>4</vsizetype>
546 </sizepolicy>
547 </property>
548 <property stdset="1">
549 <name>maximumSize</name>
550 <size>
551 <width>80</width>
552 <height>80</height>
553 </size>
554 </property>
555 <property stdset="1">
556 <name>text</name>
557 <string>MR</string>
558 </property>
559 </widget>
560 </grid>
561</widget>
562<connections>
563 <connection>
564 <sender>PB0</sender>
565 <signal>clicked()</signal>
566 <receiver>FormSimple</receiver>
567 <slot>val0Clicked()</slot>
568 </connection>
569 <connection>
570 <sender>PB1</sender>
571 <signal>clicked()</signal>
572 <receiver>FormSimple</receiver>
573 <slot>val1Clicked()</slot>
574 </connection>
575 <connection>
576 <sender>PB2</sender>
577 <signal>clicked()</signal>
578 <receiver>FormSimple</receiver>
579 <slot>val2Clicked()</slot>
580 </connection>
581 <connection>
582 <sender>PB3</sender>
583 <signal>clicked()</signal>
584 <receiver>FormSimple</receiver>
585 <slot>val3Clicked()</slot>
586 </connection>
587 <connection>
588 <sender>PB4</sender>
589 <signal>clicked()</signal>
590 <receiver>FormSimple</receiver>
591 <slot>val4Clicked()</slot>
592 </connection>
593 <connection>
594 <sender>PB5</sender>
595 <signal>clicked()</signal>
596 <receiver>FormSimple</receiver>
597 <slot>val5Clicked()</slot>
598 </connection>
599 <connection>
600 <sender>PB6</sender>
601 <signal>clicked()</signal>
602 <receiver>FormSimple</receiver>
603 <slot>val6Clicked()</slot>
604 </connection>
605 <connection>
606 <sender>PB7</sender>
607 <signal>clicked()</signal>
608 <receiver>FormSimple</receiver>
609 <slot>val7Clicked()</slot>
610 </connection>
611 <connection>
612 <sender>PB8</sender>
613 <signal>clicked()</signal>
614 <receiver>FormSimple</receiver>
615 <slot>val8Clicked()</slot>
616 </connection>
617 <connection>
618 <sender>PB9</sender>
619 <signal>clicked()</signal>
620 <receiver>FormSimple</receiver>
621 <slot>val9Clicked()</slot>
622 </connection>
623 <connection>
624 <sender>PBSub</sender>
625 <signal>clicked()</signal>
626 <receiver>FormSimple</receiver>
627 <slot>subClicked()</slot>
628 </connection>
629 <connection>
630 <sender>PBMul</sender>
631 <signal>clicked()</signal>
632 <receiver>FormSimple</receiver>
633 <slot>mulClicked()</slot>
634 </connection>
635 <connection>
636 <sender>PBDiv</sender>
637 <signal>clicked()</signal>
638 <receiver>FormSimple</receiver>
639 <slot>divClicked()</slot>
640 </connection>
641 <connection>
642 <sender>PBDecimal</sender>
643 <signal>clicked()</signal>
644 <receiver>FormSimple</receiver>
645 <slot>decimalClicked()</slot>
646 </connection>
647 <connection>
648 <sender>PBEval</sender>
649 <signal>clicked()</signal>
650 <receiver>FormSimple</receiver>
651 <slot>evalClicked()</slot>
652 </connection>
653 <connection>
654 <sender>PBMC</sender>
655 <signal>clicked()</signal>
656 <receiver>FormSimple</receiver>
657 <slot>MCClicked()</slot>
658 </connection>
659 <connection>
660 <sender>PBMPlus</sender>
661 <signal>clicked()</signal>
662 <receiver>FormSimple</receiver>
663 <slot>MPlusClicked()</slot>
664 </connection>
665 <connection>
666 <sender>PBMR</sender>
667 <signal>clicked()</signal>
668 <receiver>FormSimple</receiver>
669 <slot>MRClicked()</slot>
670 </connection>
671 <connection>
672 <sender>PBAdd</sender>
673 <signal>clicked()</signal>
674 <receiver>FormSimple</receiver>
675 <slot>addClicked()</slot>
676 </connection>
677 <connection>
678 <sender>PBCE</sender>
679 <signal>clicked()</signal>
680 <receiver>FormSimple</receiver>
681 <slot>CEClicked()</slot>
682 </connection>
683 <slot access="public">CEClicked()</slot>
684 <slot access="public">MCClicked()</slot>
685 <slot access="public">MPlusClicked()</slot>
686 <slot access="public">MRClicked()</slot>
687 <slot access="public">addClicked()</slot>
688 <slot access="public">decimalClicked()</slot>
689 <slot access="public">divClicked()</slot>
690 <slot access="public">evalClicked()</slot>
691 <slot access="public">mulClicked()</slot>
692 <slot access="public">subClicked()</slot>
693 <slot access="public">val0Clicked()</slot>
694 <slot access="public">val1Clicked()</slot>
695 <slot access="public">val2Clicked()</slot>
696 <slot access="public">val3Clicked()</slot>
697 <slot access="public">val4Clicked()</slot>
698 <slot access="public">val5Clicked()</slot>
699 <slot access="public">val6Clicked()</slot>
700 <slot access="public">val7Clicked()</slot>
701 <slot access="public">val8Clicked()</slot>
702 <slot access="public">val9Clicked()</slot>
703</connections>
704</UI>
diff --git a/noncore/tools/calc2/simple/simplefactory.cpp b/noncore/tools/calc2/simple/simplefactory.cpp
new file mode 100644
index 0000000..515418f
--- a/dev/null
+++ b/noncore/tools/calc2/simple/simplefactory.cpp
@@ -0,0 +1,51 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** GNU General Public License version 2 as published by the Free Software
10** Foundation and appearing in the file LICENSE.GPL included in the
11** packaging of this file.
12**
13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15**
16** See http://www.trolltech.com/gpl/ for GPL licensing information.
17**
18** Contact info@trolltech.com if any conditions of this licensing are
19** not clear to you.
20**
21**********************************************************************/
22
23#include "simplefactory.h"
24#include "simpleimpl.h"
25#include <engine.h>
26
27QWidget *SimpleInterface::getPlugin ( Engine *e, QWidget *parent ) {
28 if ( !input )
29 input = new FormSimpleImpl ( e, parent );
30 return input;
31}
32
33#ifndef QT_NO_COMPONENT
34QRESULT SimpleInterface::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
35{
36 *iface = 0;
37 if ( uuid == IID_QUnknown )
38 *iface = this;
39 else if ( uuid == IID_Calc )
40 *iface = this;
41
42 if ( *iface )
43 (*iface)->addRef();
44 return QS_OK;
45}
46
47Q_EXPORT_INTERFACE()
48{
49 Q_CREATE_INSTANCE( SimpleInterface )
50}
51#endif
diff --git a/noncore/tools/calc2/simple/simplefactory.h b/noncore/tools/calc2/simple/simplefactory.h
new file mode 100644
index 0000000..e1022fd
--- a/dev/null
+++ b/noncore/tools/calc2/simple/simplefactory.h
@@ -0,0 +1,46 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef BINARYIMPL_H
22#define BINARYIMPL_H
23
24#include "simpleimpl.h"
25#include <plugininterface.h>
26#include <engine.h>
27
28class SimpleInterface : public CalcInterface
29{
30public:
31 SimpleInterface(){input = 0;};
32 virtual ~SimpleInterface(){};
33
34#ifndef QT_NO_COMPONENT
35 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
36 Q_REFCOUNT
37#endif
38
39 QWidget *getPlugin( Engine *, QWidget *parent );
40
41private:
42 FormSimpleImpl *input;
43 ulong ref;
44};
45
46#endif
diff --git a/noncore/tools/calc2/simple/simpleimpl.cpp b/noncore/tools/calc2/simple/simpleimpl.cpp
new file mode 100644
index 0000000..f71f000
--- a/dev/null
+++ b/noncore/tools/calc2/simple/simpleimpl.cpp
@@ -0,0 +1,120 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpushbutton.h>
22#include <qlcdnumber.h>
23
24#include "simpleimpl.h"
25#include <stdinstructions.h>
26
27void FormSimpleImpl::CEClicked() {
28 engine->hardReset();
29}
30
31void FormSimpleImpl::MCClicked() {
32 engine->memClear();
33}
34
35void FormSimpleImpl::MRClicked() {
36 engine->memRecall();
37}
38
39void FormSimpleImpl::MPlusClicked() {
40 engine->memSave();
41}
42
43void FormSimpleImpl::evalClicked() {
44 engine->eval();
45}
46
47void FormSimpleImpl::addClicked ()
48{
49 engine->pushInstruction (new iAdd ());
50}
51
52void FormSimpleImpl::subClicked ()
53{
54 engine->pushInstruction (new iSub ());
55}
56
57void FormSimpleImpl::mulClicked ()
58{
59 engine->pushInstruction (new iMul ());
60}
61
62void FormSimpleImpl::divClicked ()
63{
64 engine->pushInstruction (new iDiv ());
65}
66
67void FormSimpleImpl::decimalClicked ()
68{
69 engine->pushValue ('.');
70}
71
72void FormSimpleImpl::val1Clicked ()
73{
74 engine->pushValue ('1');
75}
76
77void FormSimpleImpl::val2Clicked ()
78{
79 engine->pushValue ('2');
80}
81
82void FormSimpleImpl::val3Clicked ()
83{
84 engine->pushValue ('3');
85}
86
87void FormSimpleImpl::val4Clicked ()
88{
89 engine->pushValue ('4');
90}
91
92void FormSimpleImpl::val5Clicked ()
93{
94 engine->pushValue ('5');
95}
96
97void FormSimpleImpl::val6Clicked ()
98{
99 engine->pushValue ('6');
100}
101
102void FormSimpleImpl::val7Clicked ()
103{
104 engine->pushValue ('7');
105}
106
107void FormSimpleImpl::val8Clicked ()
108{
109 engine->pushValue ('8');
110}
111
112void FormSimpleImpl::val9Clicked ()
113{
114 engine->pushValue ('9');
115}
116
117void FormSimpleImpl::val0Clicked ()
118{
119 engine->pushValue ('0');
120}
diff --git a/noncore/tools/calc2/simple/simpleimpl.h b/noncore/tools/calc2/simple/simpleimpl.h
new file mode 100644
index 0000000..a2db154
--- a/dev/null
+++ b/noncore/tools/calc2/simple/simpleimpl.h
@@ -0,0 +1,65 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef STANDARDIMPL_H
22#define STANDARDIMPL_H
23
24#include <qpe/qmath.h>
25#include <qlcdnumber.h>
26
27#include "simple.h"
28#include "engine.h"
29#include "instruction.h"
30
31class FormSimpleImpl:public FormSimple {
32Q_OBJECT
33public:
34 FormSimpleImpl (Engine *e, QWidget * parent = 0, const char *name = 0)
35 :FormSimple (parent, name) {engine = e;engine->setRepresentation(rDouble);};
36
37 ~FormSimpleImpl () { };
38
39private:
40 Engine *engine;
41
42private slots:
43 void MPlusClicked();
44 void MCClicked();
45 void MRClicked();
46 void CEClicked();
47 void evalClicked();
48 void addClicked ();
49 void decimalClicked ();
50 void divClicked ();
51 void mulClicked ();
52 void subClicked ();
53 void val0Clicked ();
54 void val1Clicked ();
55 void val2Clicked ();
56 void val3Clicked ();
57 void val4Clicked ();
58 void val5Clicked ();
59 void val6Clicked ();
60 void val7Clicked ();
61 void val8Clicked ();
62 void val9Clicked ();
63};
64
65#endif
diff --git a/noncore/tools/calc2/stdinstructions.h b/noncore/tools/calc2/stdinstructions.h
new file mode 100644
index 0000000..a575968
--- a/dev/null
+++ b/noncore/tools/calc2/stdinstructions.h
@@ -0,0 +1,125 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef STDINSTRUCTION_H
22#define STDINSTRUCTION_H
23
24#include <qpe/qmath.h>
25#include "instruction.h"
26
27// Useful instructions for plugin writers
28// If you use them, take note of their precedence
29class iAdd:public Instruction {
30public:
31 iAdd ():Instruction (10) { };
32 ~iAdd () { };
33 Data eval (Data num) {
34 Data result;
35 switch (rep) {
36 case rDouble:
37 result.dbl = acc.dbl + num.dbl;
38 break;
39 default:
40 result.i = acc.i + num.i;
41 };
42 return result;
43 };
44};
45class iSub:public Instruction {
46public:
47 iSub ():Instruction (10) { };
48 ~iSub () { };
49 Data eval (Data num) {
50 Data result;
51 switch (rep) {
52 case rDouble:
53 result.dbl = acc.dbl - num.dbl;
54 break;
55 default:
56 result.i = acc.i - num.i;
57 };
58 return result;
59 };
60};
61class iMul:public Instruction {
62public:
63 iMul ():Instruction (20) { };
64 ~iMul () { };
65 Data eval (Data num) {
66 Data result;
67 switch (rep) {
68 case rDouble:
69 result.dbl = acc.dbl * num.dbl;
70 break;
71 default:
72 result.i = acc.i * num.i;
73 };
74 return result;
75 };
76};
77class iDiv:public Instruction {
78public:
79 iDiv ():Instruction (20) { };
80 ~iDiv () { };
81 Data eval (Data num) {
82 Data result;
83 switch (rep) {
84 case rDouble:
85 result.dbl = acc.dbl / num.dbl;
86 break;
87 default:
88 result.i = acc.i / num.i;
89 };
90 return result;
91 };
92};
93
94// Immediate double instructions only
95class iSin:public Instruction {
96public:
97 iSin ():Instruction () { };
98 ~iSin () { };
99 Data eval (Data num) {
100 Data result;
101 result.dbl = qSin(num.dbl);
102 return result;
103 };
104};
105class iCos:public Instruction {
106public:
107 iCos ():Instruction () { };
108 ~iCos () { };
109 Data eval (Data num) {
110 Data result;
111 result.dbl = qCos(num.dbl);
112 return result;
113 };
114};
115class iTan:public Instruction {
116public:
117 iTan ():Instruction () { };
118 ~iTan () {};
119 Data eval (Data num) {
120 Data result;
121 result.dbl = qTan(num.dbl);
122 return result;
123 };
124};
125#endif
diff --git a/noncore/tools/calculator/.cvsignore b/noncore/tools/calculator/.cvsignore
new file mode 100644
index 0000000..f5bf2df
--- a/dev/null
+++ b/noncore/tools/calculator/.cvsignore
@@ -0,0 +1,4 @@
1moc_*
2Makefile
3calculator.h
4calculator.cpp
diff --git a/noncore/tools/calculator/Makefile.in b/noncore/tools/calculator/Makefile.in
new file mode 100644
index 0000000..d62b046
--- a/dev/null
+++ b/noncore/tools/calculator/Makefile.in
@@ -0,0 +1,139 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= calculator
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =calculatorimpl.h
27 SOURCES =calculatorimpl.cpp \
28 main.cpp
29 OBJECTS =calculatorimpl.o \
30 main.o \
31 calculator.o
32INTERFACES = calculator.ui
33UICDECLS = calculator.h
34UICIMPLS = calculator.cpp
35 SRCMOC =moc_calculatorimpl.cpp \
36 moc_calculator.cpp
37 OBJMOC =moc_calculatorimpl.o \
38 moc_calculator.o
39
40
41####### Implicit rules
42
43.SUFFIXES: .cpp .cxx .cc .C .c
44
45.cpp.o:
46 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
47
48.cxx.o:
49 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
50
51.cc.o:
52 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
53
54.C.o:
55 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
56
57.c.o:
58 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
59
60####### Build rules
61
62
63all: $(DESTDIR)$(TARGET)
64
65$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
66 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
67
68moc: $(SRCMOC)
69
70tmake:
71 tmake calculator.pro
72
73clean:
74 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
75 -rm -f *~ core
76 -rm -f allmoc.cpp
77
78####### Extension Modules
79
80listpromodules:
81 @echo
82
83listallmodules:
84 @echo
85
86listaddonpromodules:
87 @echo
88
89listaddonentmodules:
90 @echo
91
92
93REQUIRES=
94
95####### Sub-libraries
96
97
98###### Combined headers
99
100
101
102####### Compile
103
104calculatorimpl.o: calculatorimpl.cpp \
105 calculatorimpl.h \
106 calculator.h \
107 $(QPEDIR)/include/qpe/resource.h \
108 $(QPEDIR)/include/qpe/qmath.h \
109 $(QPEDIR)/include/qpe/qpeapplication.h
110
111main.o: main.cpp \
112 calculatorimpl.h \
113 calculator.h \
114 $(QPEDIR)/include/qpe/qpeapplication.h
115
116calculator.h: calculator.ui
117 $(UIC) calculator.ui -o calculator.h
118
119calculator.cpp: calculator.ui
120 $(UIC) calculator.ui -i calculator.h -o calculator.cpp
121
122calculator.o: calculator.cpp \
123 calculator.h \
124 calculator.ui
125
126moc_calculatorimpl.o: moc_calculatorimpl.cpp \
127 calculatorimpl.h \
128 calculator.h
129
130moc_calculator.o: moc_calculator.cpp \
131 calculator.h
132
133moc_calculatorimpl.cpp: calculatorimpl.h
134 $(MOC) calculatorimpl.h -o moc_calculatorimpl.cpp
135
136moc_calculator.cpp: calculator.h
137 $(MOC) calculator.h -o moc_calculator.cpp
138
139
diff --git a/noncore/tools/calculator/calculator.pro b/noncore/tools/calculator/calculator.pro
new file mode 100644
index 0000000..1281fd5
--- a/dev/null
+++ b/noncore/tools/calculator/calculator.pro
@@ -0,0 +1,13 @@
1 DESTDIR = $(QPEDIR)/bin
2 TEMPLATE= app
3 CONFIG = qt warn_on release
4 HEADERS = calculatorimpl.h
5 SOURCES = calculatorimpl.cpp \
6 main.cpp
7INCLUDEPATH += $(QPEDIR)/include
8 DEPENDPATH+= $(QPEDIR)/include
9LIBS += -lqpe
10 INTERFACES= calculator.ui
11 TARGET = calculator
12
13TRANSLATIONS = ../i18n/de/calculator.ts
diff --git a/noncore/tools/calculator/calculator.ui b/noncore/tools/calculator/calculator.ui
new file mode 100644
index 0000000..e8218ab
--- a/dev/null
+++ b/noncore/tools/calculator/calculator.ui
@@ -0,0 +1,1026 @@
1<!DOCTYPE UI><UI>
2<class>Calculator</class>
3<comment>*********************************************************************
4** Copyright (C) 2000 Trolltech AS. All rights reserved.
5**
6** This file is part of Qt Palmtop Environment.
7**
8** This file may be distributed and/or modified under the terms of the
9** GNU General Public License version 2 as published by the Free Software
10** Foundation and appearing in the file LICENSE.GPL included in the
11** packaging of this file.
12**
13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15**
16** See http://www.trolltech.com/gpl/ for GPL licensing information.
17**
18** Contact info@trolltech.com if any conditions of this licensing are
19** not clear to you.
20**
21*********************************************************************</comment>
22<widget>
23 <class>QWidget</class>
24 <property stdset="1">
25 <name>name</name>
26 <cstring>Calculator</cstring>
27 </property>
28 <property stdset="1">
29 <name>geometry</name>
30 <rect>
31 <x>0</x>
32 <y>0</y>
33 <width>271</width>
34 <height>404</height>
35 </rect>
36 </property>
37 <property stdset="1">
38 <name>sizePolicy</name>
39 <sizepolicy>
40 <hsizetype>5</hsizetype>
41 <vsizetype>5</vsizetype>
42 </sizepolicy>
43 </property>
44 <property stdset="1">
45 <name>maximumSize</name>
46 <size>
47 <width>32767</width>
48 <height>32767</height>
49 </size>
50 </property>
51 <property stdset="1">
52 <name>baseSize</name>
53 <size>
54 <width>235</width>
55 <height>100</height>
56 </size>
57 </property>
58 <property stdset="1">
59 <name>caption</name>
60 <string>Experimental Calculator</string>
61 </property>
62 <property>
63 <name>layoutMargin</name>
64 </property>
65 <property>
66 <name>layoutSpacing</name>
67 </property>
68 <vbox>
69 <property stdset="1">
70 <name>margin</name>
71 <number>0</number>
72 </property>
73 <property stdset="1">
74 <name>spacing</name>
75 <number>0</number>
76 </property>
77 <widget>
78 <class>QLCDNumber</class>
79 <property stdset="1">
80 <name>name</name>
81 <cstring>LCD</cstring>
82 </property>
83 <property stdset="1">
84 <name>sizePolicy</name>
85 <sizepolicy>
86 <hsizetype>1</hsizetype>
87 <vsizetype>1</vsizetype>
88 </sizepolicy>
89 </property>
90 <property stdset="1">
91 <name>font</name>
92 <font>
93 <pointsize>7</pointsize>
94 </font>
95 </property>
96 <property stdset="1">
97 <name>numDigits</name>
98 <number>15</number>
99 </property>
100 <property stdset="1">
101 <name>segmentStyle</name>
102 <enum>Flat</enum>
103 </property>
104 </widget>
105 <widget>
106 <class>QLayoutWidget</class>
107 <property stdset="1">
108 <name>name</name>
109 <cstring>Layout4</cstring>
110 </property>
111 <hbox>
112 <property stdset="1">
113 <name>margin</name>
114 <number>0</number>
115 </property>
116 <property stdset="1">
117 <name>spacing</name>
118 <number>0</number>
119 </property>
120 <widget>
121 <class>QComboBox</class>
122 <property stdset="1">
123 <name>name</name>
124 <cstring>ComboBoxFunction</cstring>
125 </property>
126 <property stdset="1">
127 <name>sizePolicy</name>
128 <sizepolicy>
129 <hsizetype>1</hsizetype>
130 <vsizetype>1</vsizetype>
131 </sizepolicy>
132 </property>
133 </widget>
134 <widget>
135 <class>QPushButton</class>
136 <property stdset="1">
137 <name>name</name>
138 <cstring>PushButtonMPlus</cstring>
139 </property>
140 <property stdset="1">
141 <name>sizePolicy</name>
142 <sizepolicy>
143 <hsizetype>5</hsizetype>
144 <vsizetype>5</vsizetype>
145 </sizepolicy>
146 </property>
147 <property stdset="1">
148 <name>focusPolicy</name>
149 <enum>TabFocus</enum>
150 </property>
151 <property stdset="1">
152 <name>text</name>
153 <string>M+</string>
154 </property>
155 </widget>
156 <widget>
157 <class>QPushButton</class>
158 <property stdset="1">
159 <name>name</name>
160 <cstring>PushButtonMR</cstring>
161 </property>
162 <property stdset="1">
163 <name>sizePolicy</name>
164 <sizepolicy>
165 <hsizetype>5</hsizetype>
166 <vsizetype>5</vsizetype>
167 </sizepolicy>
168 </property>
169 <property stdset="1">
170 <name>focusPolicy</name>
171 <enum>TabFocus</enum>
172 </property>
173 <property stdset="1">
174 <name>text</name>
175 <string>MR</string>
176 </property>
177 </widget>
178 <widget>
179 <class>QPushButton</class>
180 <property stdset="1">
181 <name>name</name>
182 <cstring>PushButtonMC</cstring>
183 </property>
184 <property stdset="1">
185 <name>sizePolicy</name>
186 <sizepolicy>
187 <hsizetype>5</hsizetype>
188 <vsizetype>5</vsizetype>
189 </sizepolicy>
190 </property>
191 <property stdset="1">
192 <name>focusPolicy</name>
193 <enum>TabFocus</enum>
194 </property>
195 <property stdset="1">
196 <name>text</name>
197 <string>MC</string>
198 </property>
199 </widget>
200 <widget>
201 <class>QPushButton</class>
202 <property stdset="1">
203 <name>name</name>
204 <cstring>PushButtonCE</cstring>
205 </property>
206 <property stdset="1">
207 <name>sizePolicy</name>
208 <sizepolicy>
209 <hsizetype>5</hsizetype>
210 <vsizetype>5</vsizetype>
211 </sizepolicy>
212 </property>
213 <property stdset="1">
214 <name>focusPolicy</name>
215 <enum>TabFocus</enum>
216 </property>
217 <property stdset="1">
218 <name>text</name>
219 <string>CE</string>
220 </property>
221 </widget>
222 </hbox>
223 </widget>
224 <widget>
225 <class>QLayoutWidget</class>
226 <property stdset="1">
227 <name>name</name>
228 <cstring>Layout10</cstring>
229 </property>
230 <property>
231 <name>layoutSpacing</name>
232 </property>
233 <hbox>
234 <property stdset="1">
235 <name>margin</name>
236 <number>0</number>
237 </property>
238 <property stdset="1">
239 <name>spacing</name>
240 <number>0</number>
241 </property>
242 <widget>
243 <class>QPushButton</class>
244 <property stdset="1">
245 <name>name</name>
246 <cstring>PushButtonF6</cstring>
247 </property>
248 <property stdset="1">
249 <name>sizePolicy</name>
250 <sizepolicy>
251 <hsizetype>5</hsizetype>
252 <vsizetype>5</vsizetype>
253 </sizepolicy>
254 </property>
255 <property stdset="1">
256 <name>text</name>
257 <string></string>
258 </property>
259 </widget>
260 <widget>
261 <class>QPushButton</class>
262 <property stdset="1">
263 <name>name</name>
264 <cstring>PushButtonF7</cstring>
265 </property>
266 <property stdset="1">
267 <name>sizePolicy</name>
268 <sizepolicy>
269 <hsizetype>5</hsizetype>
270 <vsizetype>5</vsizetype>
271 </sizepolicy>
272 </property>
273 <property stdset="1">
274 <name>text</name>
275 <string></string>
276 </property>
277 </widget>
278 <widget>
279 <class>QPushButton</class>
280 <property stdset="1">
281 <name>name</name>
282 <cstring>PushButtonF8</cstring>
283 </property>
284 <property stdset="1">
285 <name>sizePolicy</name>
286 <sizepolicy>
287 <hsizetype>5</hsizetype>
288 <vsizetype>5</vsizetype>
289 </sizepolicy>
290 </property>
291 <property stdset="1">
292 <name>text</name>
293 <string>log</string>
294 </property>
295 </widget>
296 <widget>
297 <class>QPushButton</class>
298 <property stdset="1">
299 <name>name</name>
300 <cstring>PushButtonF9</cstring>
301 </property>
302 <property stdset="1">
303 <name>sizePolicy</name>
304 <sizepolicy>
305 <hsizetype>5</hsizetype>
306 <vsizetype>5</vsizetype>
307 </sizepolicy>
308 </property>
309 <property stdset="1">
310 <name>focusPolicy</name>
311 <enum>TabFocus</enum>
312 </property>
313 <property stdset="1">
314 <name>text</name>
315 <string>ln</string>
316 </property>
317 </widget>
318 <widget>
319 <class>QPushButton</class>
320 <property stdset="1">
321 <name>name</name>
322 <cstring>PushButtonF11</cstring>
323 </property>
324 <property stdset="1">
325 <name>sizePolicy</name>
326 <sizepolicy>
327 <hsizetype>5</hsizetype>
328 <vsizetype>5</vsizetype>
329 </sizepolicy>
330 </property>
331 <property stdset="1">
332 <name>text</name>
333 <string>(</string>
334 </property>
335 </widget>
336 <widget>
337 <class>QPushButton</class>
338 <property stdset="1">
339 <name>name</name>
340 <cstring>PushButtonF12</cstring>
341 </property>
342 <property stdset="1">
343 <name>sizePolicy</name>
344 <sizepolicy>
345 <hsizetype>5</hsizetype>
346 <vsizetype>5</vsizetype>
347 </sizepolicy>
348 </property>
349 <property stdset="1">
350 <name>text</name>
351 <string>)</string>
352 </property>
353 </widget>
354 </hbox>
355 </widget>
356 <widget>
357 <class>QLayoutWidget</class>
358 <property stdset="1">
359 <name>name</name>
360 <cstring>Layout11</cstring>
361 </property>
362 <property>
363 <name>layoutSpacing</name>
364 </property>
365 <hbox>
366 <property stdset="1">
367 <name>margin</name>
368 <number>0</number>
369 </property>
370 <property stdset="1">
371 <name>spacing</name>
372 <number>0</number>
373 </property>
374 <widget>
375 <class>QPushButton</class>
376 <property stdset="1">
377 <name>name</name>
378 <cstring>PushButtonF1</cstring>
379 </property>
380 <property stdset="1">
381 <name>sizePolicy</name>
382 <sizepolicy>
383 <hsizetype>5</hsizetype>
384 <vsizetype>5</vsizetype>
385 </sizepolicy>
386 </property>
387 <property stdset="1">
388 <name>focusPolicy</name>
389 <enum>TabFocus</enum>
390 </property>
391 <property stdset="1">
392 <name>text</name>
393 <string>sin</string>
394 </property>
395 </widget>
396 <widget>
397 <class>QPushButton</class>
398 <property stdset="1">
399 <name>name</name>
400 <cstring>PushButtonF2</cstring>
401 </property>
402 <property stdset="1">
403 <name>sizePolicy</name>
404 <sizepolicy>
405 <hsizetype>5</hsizetype>
406 <vsizetype>5</vsizetype>
407 </sizepolicy>
408 </property>
409 <property stdset="1">
410 <name>focusPolicy</name>
411 <enum>TabFocus</enum>
412 </property>
413 <property stdset="1">
414 <name>text</name>
415 <string>cos</string>
416 </property>
417 </widget>
418 <widget>
419 <class>QPushButton</class>
420 <property stdset="1">
421 <name>name</name>
422 <cstring>PushButtonF3</cstring>
423 </property>
424 <property stdset="1">
425 <name>sizePolicy</name>
426 <sizepolicy>
427 <hsizetype>5</hsizetype>
428 <vsizetype>5</vsizetype>
429 </sizepolicy>
430 </property>
431 <property stdset="1">
432 <name>focusPolicy</name>
433 <enum>TabFocus</enum>
434 </property>
435 <property stdset="1">
436 <name>text</name>
437 <string>tan</string>
438 </property>
439 </widget>
440 <widget>
441 <class>QPushButton</class>
442 <property stdset="1">
443 <name>name</name>
444 <cstring>PushButtonF4</cstring>
445 </property>
446 <property stdset="1">
447 <name>sizePolicy</name>
448 <sizepolicy>
449 <hsizetype>5</hsizetype>
450 <vsizetype>5</vsizetype>
451 </sizepolicy>
452 </property>
453 <property stdset="1">
454 <name>focusPolicy</name>
455 <enum>TabFocus</enum>
456 </property>
457 <property stdset="1">
458 <name>text</name>
459 <string></string>
460 </property>
461 </widget>
462 <widget>
463 <class>QPushButton</class>
464 <property stdset="1">
465 <name>name</name>
466 <cstring>PushButtonF5</cstring>
467 </property>
468 <property stdset="1">
469 <name>sizePolicy</name>
470 <sizepolicy>
471 <hsizetype>5</hsizetype>
472 <vsizetype>5</vsizetype>
473 </sizepolicy>
474 </property>
475 <property stdset="1">
476 <name>focusPolicy</name>
477 <enum>TabFocus</enum>
478 </property>
479 <property stdset="1">
480 <name>text</name>
481 <string>%</string>
482 </property>
483 </widget>
484 <widget>
485 <class>QPushButton</class>
486 <property stdset="1">
487 <name>name</name>
488 <cstring>PushButtonF10</cstring>
489 </property>
490 <property stdset="1">
491 <name>sizePolicy</name>
492 <sizepolicy>
493 <hsizetype>5</hsizetype>
494 <vsizetype>5</vsizetype>
495 </sizepolicy>
496 </property>
497 <property stdset="1">
498 <name>focusPolicy</name>
499 <enum>TabFocus</enum>
500 </property>
501 <property stdset="1">
502 <name>text</name>
503 <string>+/-</string>
504 </property>
505 </widget>
506 </hbox>
507 </widget>
508 <widget>
509 <class>QLayoutWidget</class>
510 <property stdset="1">
511 <name>name</name>
512 <cstring>Layout5</cstring>
513 </property>
514 <grid>
515 <property stdset="1">
516 <name>margin</name>
517 <number>0</number>
518 </property>
519 <property stdset="1">
520 <name>spacing</name>
521 <number>0</number>
522 </property>
523 <widget row="2" column="2" >
524 <class>QPushButton</class>
525 <property stdset="1">
526 <name>name</name>
527 <cstring>PushButton3</cstring>
528 </property>
529 <property stdset="1">
530 <name>sizePolicy</name>
531 <sizepolicy>
532 <hsizetype>5</hsizetype>
533 <vsizetype>5</vsizetype>
534 </sizepolicy>
535 </property>
536 <property stdset="1">
537 <name>font</name>
538 <font>
539 <family>adobe-helvetica</family>
540 <pointsize>24</pointsize>
541 </font>
542 </property>
543 <property stdset="1">
544 <name>focusPolicy</name>
545 <enum>TabFocus</enum>
546 </property>
547 <property stdset="1">
548 <name>text</name>
549 <string>3</string>
550 </property>
551 </widget>
552 <widget row="1" column="2" >
553 <class>QPushButton</class>
554 <property stdset="1">
555 <name>name</name>
556 <cstring>PushButton6</cstring>
557 </property>
558 <property stdset="1">
559 <name>sizePolicy</name>
560 <sizepolicy>
561 <hsizetype>5</hsizetype>
562 <vsizetype>5</vsizetype>
563 </sizepolicy>
564 </property>
565 <property stdset="1">
566 <name>font</name>
567 <font>
568 <family>adobe-helvetica</family>
569 <pointsize>24</pointsize>
570 </font>
571 </property>
572 <property stdset="1">
573 <name>focusPolicy</name>
574 <enum>TabFocus</enum>
575 </property>
576 <property stdset="1">
577 <name>text</name>
578 <string>6</string>
579 </property>
580 </widget>
581 <widget row="3" column="2" >
582 <class>QPushButton</class>
583 <property stdset="1">
584 <name>name</name>
585 <cstring>PushButtonEquals</cstring>
586 </property>
587 <property stdset="1">
588 <name>sizePolicy</name>
589 <sizepolicy>
590 <hsizetype>5</hsizetype>
591 <vsizetype>5</vsizetype>
592 </sizepolicy>
593 </property>
594 <property stdset="1">
595 <name>font</name>
596 <font>
597 <family>adobe-helvetica</family>
598 <pointsize>24</pointsize>
599 </font>
600 </property>
601 <property stdset="1">
602 <name>focusPolicy</name>
603 <enum>TabFocus</enum>
604 </property>
605 <property stdset="1">
606 <name>text</name>
607 <string>=</string>
608 </property>
609 </widget>
610 <widget row="3" column="0" >
611 <class>QPushButton</class>
612 <property stdset="1">
613 <name>name</name>
614 <cstring>PushButton0</cstring>
615 </property>
616 <property stdset="1">
617 <name>sizePolicy</name>
618 <sizepolicy>
619 <hsizetype>5</hsizetype>
620 <vsizetype>5</vsizetype>
621 </sizepolicy>
622 </property>
623 <property stdset="1">
624 <name>font</name>
625 <font>
626 <family>adobe-helvetica</family>
627 <pointsize>24</pointsize>
628 </font>
629 </property>
630 <property stdset="1">
631 <name>focusPolicy</name>
632 <enum>TabFocus</enum>
633 </property>
634 <property stdset="1">
635 <name>text</name>
636 <string>0</string>
637 </property>
638 </widget>
639 <widget row="1" column="3" >
640 <class>QPushButton</class>
641 <property stdset="1">
642 <name>name</name>
643 <cstring>PushButtonMinus</cstring>
644 </property>
645 <property stdset="1">
646 <name>sizePolicy</name>
647 <sizepolicy>
648 <hsizetype>5</hsizetype>
649 <vsizetype>5</vsizetype>
650 </sizepolicy>
651 </property>
652 <property stdset="1">
653 <name>font</name>
654 <font>
655 <family>adobe-helvetica</family>
656 <pointsize>24</pointsize>
657 </font>
658 </property>
659 <property stdset="1">
660 <name>focusPolicy</name>
661 <enum>TabFocus</enum>
662 </property>
663 <property stdset="1">
664 <name>text</name>
665 <string>-</string>
666 </property>
667 </widget>
668 <widget row="2" column="3" >
669 <class>QPushButton</class>
670 <property stdset="1">
671 <name>name</name>
672 <cstring>PushButtonTimes</cstring>
673 </property>
674 <property stdset="1">
675 <name>sizePolicy</name>
676 <sizepolicy>
677 <hsizetype>5</hsizetype>
678 <vsizetype>5</vsizetype>
679 </sizepolicy>
680 </property>
681 <property stdset="1">
682 <name>font</name>
683 <font>
684 <family>adobe-helvetica</family>
685 <pointsize>24</pointsize>
686 </font>
687 </property>
688 <property stdset="1">
689 <name>focusPolicy</name>
690 <enum>TabFocus</enum>
691 </property>
692 <property stdset="1">
693 <name>text</name>
694 <string>x</string>
695 </property>
696 </widget>
697 <widget row="1" column="0" >
698 <class>QPushButton</class>
699 <property stdset="1">
700 <name>name</name>
701 <cstring>PushButton4</cstring>
702 </property>
703 <property stdset="1">
704 <name>sizePolicy</name>
705 <sizepolicy>
706 <hsizetype>5</hsizetype>
707 <vsizetype>5</vsizetype>
708 </sizepolicy>
709 </property>
710 <property stdset="1">
711 <name>font</name>
712 <font>
713 <family>adobe-helvetica</family>
714 <pointsize>24</pointsize>
715 </font>
716 </property>
717 <property stdset="1">
718 <name>focusPolicy</name>
719 <enum>TabFocus</enum>
720 </property>
721 <property stdset="1">
722 <name>text</name>
723 <string>4</string>
724 </property>
725 </widget>
726 <widget row="0" column="1" >
727 <class>QPushButton</class>
728 <property stdset="1">
729 <name>name</name>
730 <cstring>PushButton8</cstring>
731 </property>
732 <property stdset="1">
733 <name>sizePolicy</name>
734 <sizepolicy>
735 <hsizetype>5</hsizetype>
736 <vsizetype>5</vsizetype>
737 </sizepolicy>
738 </property>
739 <property stdset="1">
740 <name>font</name>
741 <font>
742 <family>adobe-helvetica</family>
743 <pointsize>24</pointsize>
744 </font>
745 </property>
746 <property stdset="1">
747 <name>focusPolicy</name>
748 <enum>TabFocus</enum>
749 </property>
750 <property stdset="1">
751 <name>text</name>
752 <string>8</string>
753 </property>
754 </widget>
755 <widget row="3" column="3" >
756 <class>QPushButton</class>
757 <property stdset="1">
758 <name>name</name>
759 <cstring>PushButtonDivide</cstring>
760 </property>
761 <property stdset="1">
762 <name>sizePolicy</name>
763 <sizepolicy>
764 <hsizetype>5</hsizetype>
765 <vsizetype>5</vsizetype>
766 </sizepolicy>
767 </property>
768 <property stdset="1">
769 <name>font</name>
770 <font>
771 <family>adobe-helvetica</family>
772 <pointsize>24</pointsize>
773 </font>
774 </property>
775 <property stdset="1">
776 <name>focusPolicy</name>
777 <enum>TabFocus</enum>
778 </property>
779 <property stdset="1">
780 <name>text</name>
781 <string>/</string>
782 </property>
783 </widget>
784 <widget row="0" column="3" >
785 <class>QPushButton</class>
786 <property stdset="1">
787 <name>name</name>
788 <cstring>PushButtonAdd</cstring>
789 </property>
790 <property stdset="1">
791 <name>sizePolicy</name>
792 <sizepolicy>
793 <hsizetype>5</hsizetype>
794 <vsizetype>5</vsizetype>
795 </sizepolicy>
796 </property>
797 <property stdset="1">
798 <name>font</name>
799 <font>
800 <family>adobe-helvetica</family>
801 <pointsize>24</pointsize>
802 </font>
803 </property>
804 <property stdset="1">
805 <name>focusPolicy</name>
806 <enum>TabFocus</enum>
807 </property>
808 <property stdset="1">
809 <name>text</name>
810 <string>+</string>
811 </property>
812 </widget>
813 <widget row="2" column="0" >
814 <class>QPushButton</class>
815 <property stdset="1">
816 <name>name</name>
817 <cstring>PushButton1</cstring>
818 </property>
819 <property stdset="1">
820 <name>sizePolicy</name>
821 <sizepolicy>
822 <hsizetype>5</hsizetype>
823 <vsizetype>5</vsizetype>
824 </sizepolicy>
825 </property>
826 <property stdset="1">
827 <name>font</name>
828 <font>
829 <family>adobe-helvetica</family>
830 <pointsize>24</pointsize>
831 </font>
832 </property>
833 <property stdset="1">
834 <name>focusPolicy</name>
835 <enum>TabFocus</enum>
836 </property>
837 <property stdset="1">
838 <name>text</name>
839 <string>1</string>
840 </property>
841 </widget>
842 <widget row="3" column="1" >
843 <class>QPushButton</class>
844 <property stdset="1">
845 <name>name</name>
846 <cstring>PushButtonDecimal</cstring>
847 </property>
848 <property stdset="1">
849 <name>sizePolicy</name>
850 <sizepolicy>
851 <hsizetype>5</hsizetype>
852 <vsizetype>5</vsizetype>
853 </sizepolicy>
854 </property>
855 <property stdset="1">
856 <name>font</name>
857 <font>
858 <family>adobe-helvetica</family>
859 <pointsize>24</pointsize>
860 </font>
861 </property>
862 <property stdset="1">
863 <name>focusPolicy</name>
864 <enum>TabFocus</enum>
865 </property>
866 <property stdset="1">
867 <name>text</name>
868 <string>.</string>
869 </property>
870 </widget>
871 <widget row="1" column="1" >
872 <class>QPushButton</class>
873 <property stdset="1">
874 <name>name</name>
875 <cstring>PushButton5</cstring>
876 </property>
877 <property stdset="1">
878 <name>sizePolicy</name>
879 <sizepolicy>
880 <hsizetype>5</hsizetype>
881 <vsizetype>5</vsizetype>
882 </sizepolicy>
883 </property>
884 <property stdset="1">
885 <name>font</name>
886 <font>
887 <family>adobe-helvetica</family>
888 <pointsize>24</pointsize>
889 </font>
890 </property>
891 <property stdset="1">
892 <name>focusPolicy</name>
893 <enum>TabFocus</enum>
894 </property>
895 <property stdset="1">
896 <name>text</name>
897 <string>5</string>
898 </property>
899 </widget>
900 <widget row="0" column="0" >
901 <class>QPushButton</class>
902 <property stdset="1">
903 <name>name</name>
904 <cstring>PushButton7</cstring>
905 </property>
906 <property stdset="1">
907 <name>sizePolicy</name>
908 <sizepolicy>
909 <hsizetype>5</hsizetype>
910 <vsizetype>5</vsizetype>
911 </sizepolicy>
912 </property>
913 <property stdset="1">
914 <name>font</name>
915 <font>
916 <family>adobe-helvetica</family>
917 <pointsize>24</pointsize>
918 </font>
919 </property>
920 <property stdset="1">
921 <name>focusPolicy</name>
922 <enum>TabFocus</enum>
923 </property>
924 <property stdset="1">
925 <name>text</name>
926 <string>7</string>
927 </property>
928 </widget>
929 <widget row="0" column="2" >
930 <class>QPushButton</class>
931 <property stdset="1">
932 <name>name</name>
933 <cstring>PushButton9</cstring>
934 </property>
935 <property stdset="1">
936 <name>sizePolicy</name>
937 <sizepolicy>
938 <hsizetype>5</hsizetype>
939 <vsizetype>5</vsizetype>
940 </sizepolicy>
941 </property>
942 <property stdset="1">
943 <name>font</name>
944 <font>
945 <family>adobe-helvetica</family>
946 <pointsize>24</pointsize>
947 </font>
948 </property>
949 <property stdset="1">
950 <name>focusPolicy</name>
951 <enum>TabFocus</enum>
952 </property>
953 <property stdset="1">
954 <name>text</name>
955 <string>9</string>
956 </property>
957 </widget>
958 <widget row="2" column="1" >
959 <class>QPushButton</class>
960 <property stdset="1">
961 <name>name</name>
962 <cstring>PushButton2</cstring>
963 </property>
964 <property stdset="1">
965 <name>sizePolicy</name>
966 <sizepolicy>
967 <hsizetype>5</hsizetype>
968 <vsizetype>5</vsizetype>
969 </sizepolicy>
970 </property>
971 <property stdset="1">
972 <name>font</name>
973 <font>
974 <family>adobe-helvetica</family>
975 <pointsize>24</pointsize>
976 </font>
977 </property>
978 <property stdset="1">
979 <name>focusPolicy</name>
980 <enum>TabFocus</enum>
981 </property>
982 <property stdset="1">
983 <name>text</name>
984 <string>2</string>
985 </property>
986 </widget>
987 </grid>
988 </widget>
989 </vbox>
990</widget>
991<tabstops>
992 <tabstop>ComboBoxFunction</tabstop>
993 <tabstop>PushButtonMPlus</tabstop>
994 <tabstop>PushButtonMR</tabstop>
995 <tabstop>PushButtonMC</tabstop>
996 <tabstop>PushButtonCE</tabstop>
997 <tabstop>PushButtonF6</tabstop>
998 <tabstop>PushButtonF7</tabstop>
999 <tabstop>PushButtonF8</tabstop>
1000 <tabstop>PushButtonF9</tabstop>
1001 <tabstop>PushButtonF11</tabstop>
1002 <tabstop>PushButtonF12</tabstop>
1003 <tabstop>PushButtonF1</tabstop>
1004 <tabstop>PushButtonF2</tabstop>
1005 <tabstop>PushButtonF3</tabstop>
1006 <tabstop>PushButtonF4</tabstop>
1007 <tabstop>PushButtonF5</tabstop>
1008 <tabstop>PushButtonF10</tabstop>
1009 <tabstop>PushButton7</tabstop>
1010 <tabstop>PushButton8</tabstop>
1011 <tabstop>PushButton9</tabstop>
1012 <tabstop>PushButtonAdd</tabstop>
1013 <tabstop>PushButton4</tabstop>
1014 <tabstop>PushButton5</tabstop>
1015 <tabstop>PushButton6</tabstop>
1016 <tabstop>PushButtonMinus</tabstop>
1017 <tabstop>PushButton1</tabstop>
1018 <tabstop>PushButton2</tabstop>
1019 <tabstop>PushButton3</tabstop>
1020 <tabstop>PushButtonTimes</tabstop>
1021 <tabstop>PushButton0</tabstop>
1022 <tabstop>PushButtonDecimal</tabstop>
1023 <tabstop>PushButtonEquals</tabstop>
1024 <tabstop>PushButtonDivide</tabstop>
1025</tabstops>
1026</UI>
diff --git a/noncore/tools/calculator/calculatorimpl.cpp b/noncore/tools/calculator/calculatorimpl.cpp
new file mode 100644
index 0000000..2f7d7ce
--- a/dev/null
+++ b/noncore/tools/calculator/calculatorimpl.cpp
@@ -0,0 +1,601 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "calculatorimpl.h"
22
23#include <qpe/resource.h>
24#include <qpe/qmath.h>
25#include <qpe/qpeapplication.h>
26
27#include <qpushbutton.h>
28#include <qcombobox.h>
29#include <qlabel.h>
30#include <qfont.h>
31#include <qlayout.h>
32#include <qstringlist.h>
33#include <qfile.h>
34#include <qtextstream.h>
35#include <qmessagebox.h>
36#include <math.h>
37
38CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name,
39 WFlags f )
40 : Calculator( parent, name, f )
41{
42 xtopowerofy = Resource::loadPixmap("xtopowerofy");
43 ythrootofx = Resource::loadPixmap("ythrootofx");
44 oneoverx = Resource::loadPixmap("oneoverx");
45
46 memMark = new QLabel( "m", LCD );
47 memMark->setFont( QFont( "helvetica", 12, QFont::Bold, TRUE ) );
48 memMark->resize( 12, 12 );
49 memMark->move( 4, 2 );
50 memMark->hide();
51 mem = 0;
52
53 PushButtonMR->setEnabled( FALSE );
54
55 current_mode = max_mode = conversion_mode_count = 0;
56 last_conversion = -1;
57
58//bgr_command.insert( PushButtonFunction);
59 bgr_command.insert( PushButtonMPlus);
60 bgr_command.insert( PushButtonMR);
61 bgr_command.insert( PushButtonMC);
62 bgr_command.insert( PushButtonCE);
63 connect( &bgr_command, SIGNAL(clicked(int) ), this, SLOT(command_buttons(int)));
64
65 bgr_digits.insert(PushButton0);
66 bgr_digits.insert(PushButton1);
67 bgr_digits.insert(PushButton2);
68 bgr_digits.insert(PushButton3);
69 bgr_digits.insert(PushButton4);
70 bgr_digits.insert(PushButton5);
71 bgr_digits.insert(PushButton6);
72 bgr_digits.insert(PushButton7);
73 bgr_digits.insert(PushButton8);
74 bgr_digits.insert(PushButton9);
75 connect( &bgr_digits, SIGNAL(clicked(int) ), this, SLOT(enterNumber(int)));
76
77
78 bgr_std.insert(PushButtonEquals);
79 bgr_std.insert(PushButtonDecimal);
80 bgr_std.insert(PushButtonAdd);
81 bgr_std.insert(PushButtonMinus);
82 bgr_std.insert(PushButtonDivide);
83 bgr_std.insert(PushButtonTimes);
84 connect( &bgr_std, SIGNAL(clicked(int) ), this, SLOT(std_buttons(int)));
85
86// change the / to a proper division signal
87 PushButtonDivide->setText(QChar(0xF7));
88
89 func_buttons[0] = PushButtonF1;
90 func_buttons[1] = PushButtonF2;
91 func_buttons[2] = PushButtonF3;
92 func_buttons[3] = PushButtonF4;
93 func_buttons[4] = PushButtonF5;
94 func_buttons[5] = PushButtonF6;
95 func_buttons[6] = PushButtonF7;
96 func_buttons[7] = PushButtonF8;
97 func_buttons[8] = PushButtonF9;
98 func_buttons[9] = PushButtonF10;
99 func_buttons[10] = PushButtonF11;
100 func_buttons[11] = PushButtonF12;
101
102 for ( int x = 0 ; x < func_button_count ; x++ ) {
103 QPushButton* tmpbutton = func_buttons[x];
104 faces << tmpbutton->text();
105 bgr_function.insert(tmpbutton);
106 }
107 connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(do_convert(int) ) );
108 connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(std_funcs (int) ) );
109
110 connect(ComboBoxFunction, SIGNAL(activated(int) ), this, SLOT(function_button(int) ) );
111
112 captions.append("Standard");
113 ComboBoxFunction->insertItem(captions.last());
114
115 // now add in the conversion modes
116 // when the menu gets done, these should be in a submenu
117 QString tmp = QPEApplication::qpeDir();
118 tmp += "/etc/unit_conversion.dat";
119 QFile myfile(tmp);
120 if ( !myfile.open( IO_Translate | IO_ReadOnly ) ) {
121 // QMessageBox::warning(this, "Warning", "Data file\nunit_conversion.dat\nnot found\nNo conversion\nfeatures will\nbe available");
122 // disable the f button if no conv file available
123 ComboBoxFunction->setEnabled(FALSE);
124 }
125 else {
126 QString line, line2;
127 QTextStream ts(&myfile);
128
129 // first pass, see how many conversion types there are in order to allocate for them
130 while ( ! ts.eof() ) {
131 line = ts.readLine();
132 if ( line.contains ("STARTTYPE" ) )
133 conversion_mode_count++;
134 }
135
136 entry_list = new double[conversion_mode_count*func_button_count];
137
138 myfile.close();
139 myfile.open( IO_Translate | IO_ReadOnly );
140 QTextStream ts2(&myfile);
141
142 // second pass, read in values
143 int x = 0;
144 while ( ! ts2.eof() ) {
145 line = ts2.readLine();
146 if ( line.contains("STARTTYPE") ) {
147 captions << line.remove(0,10);
148 ComboBoxFunction->insertItem(captions.last());
149 while ( !line.contains("ENDTYPE") ) {
150 line = ts2.readLine();
151 if ( line.contains("NAME") ) {
152 faces << line.remove(0,5);
153 line2 = ts2.readLine();
154 line2.remove(0,6);
155 entry_list[x] = line2.toDouble();
156 x++;
157 }
158 }
159 }
160 }
161 }
162 myfile.close();
163 clear();
164 max_mode = pre_conv_modes_count + conversion_mode_count + post_conv_modes_count - 1;
165 display_pixmap_faces();
166
167 qApp->installEventFilter( this );
168}
169
170bool CalculatorImpl::eventFilter( QObject *o, QEvent *e )
171{
172 if ( e->type() == QEvent::KeyPress && state != sError ) {
173 QKeyEvent *k = (QKeyEvent*)e;
174 if ( k->key() >= Key_0 && k->key() <= Key_9 ) {
175 enterNumber( k->key() - Key_0 );
176 return true;
177 } else {
178 switch ( k->key() ) {
179 case Key_Equal:
180 std_buttons(0);
181 return true;
182 case Key_Period:
183 std_buttons(1);
184 return true;
185 case Key_Plus:
186 std_buttons(2);
187 return true;
188 case Key_Minus:
189 std_buttons(3);
190 return true;
191 case Key_Slash:
192 std_buttons(4);
193 return true;
194 case Key_Asterisk:
195 std_buttons(5);
196 return true;
197 case Key_Percent:
198 execOp( oPercent );
199 return true;
200 case Key_ParenLeft:
201 if ( current_mode < pre_conv_modes_count )
202 execOp( oOpenBrace );
203 return true;
204 case Key_ParenRight:
205 if ( current_mode < pre_conv_modes_count )
206 execOp( oCloseBrace );
207 return true;
208 default:
209 break;
210 }
211 }
212 }
213 return Calculator::eventFilter( o, e );
214}
215
216void CalculatorImpl::do_convert(int button) {
217 if ( state == sError )
218 return;
219 if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) &&
220 button < changeable_func_button_count ) {
221 if ( last_conversion > -1 ) {
222 if( state == sNewNumber ){
223 acc = num
224 / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion])
225 * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) ;
226 num = acc;
227 LCD->display( acc );
228 } else {
229 state = sNewNumber;
230 num = num
231 / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion])
232 * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) ;
233 LCD->display( num );
234 acc = num;
235 }
236 }
237 last_conversion = button;
238 }
239}
240
241
242void CalculatorImpl::function_button(int mode){
243 if ( state == sError )
244 clear();
245 // dont need the next line when using a popup menu
246 current_mode = mode;
247
248 // reset the last conv
249 last_conversion = -1;
250
251 // set the caption
252 this->setCaption( captions[current_mode] );
253
254 reset_conv();
255
256 for ( int x = 0 ; x < changeable_func_button_count ; x++ ) {
257 QPushButton* tmpbutton = func_buttons[x];
258
259 // if its a conversion , make it a toggle button
260 if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) {
261 tmpbutton->setToggleButton(TRUE);
262 } else {
263 tmpbutton->setToggleButton(FALSE);
264 }
265 tmpbutton->setText( faces[current_mode * func_button_count + x] );
266 }
267
268 if ( current_mode == 0 ) display_pixmap_faces();
269
270 if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) {
271 bgr_function.setExclusive(TRUE);
272 } else {
273 bgr_function.setExclusive(FALSE);
274 }
275}
276
277void CalculatorImpl::display_pixmap_faces() {
278 QPushButton* tmpbutton = func_buttons[5];
279 tmpbutton->setPixmap(xtopowerofy);
280
281 tmpbutton = func_buttons[6];
282 tmpbutton->setPixmap(ythrootofx);
283
284 tmpbutton = func_buttons[3];
285 tmpbutton->setPixmap(oneoverx);
286}
287
288void CalculatorImpl::clear() {
289 acc = num = 0;
290 operationStack.clear();
291 state = sStart;
292 numDecimals = 0;
293 numOpenBraces = 0;
294 flPoint = FALSE;
295 LCD->display( 0 );
296 fake = QString::null;
297
298 reset_conv();
299}
300
301void CalculatorImpl::reset_conv() {
302 for ( int x = 0 ; x < changeable_func_button_count ; x++ ) {
303 QPushButton* tmpbutton = func_buttons[x];
304
305 // dont carry any selections into the next mode
306 if ( tmpbutton->state() == QPushButton::On ) {
307 tmpbutton->toggle();
308 }
309 }
310
311 last_conversion = -1;
312}
313
314void CalculatorImpl::std_buttons(int button)
315{
316 if ( state == sError )
317 return;
318 execOp( (Operation)(button + oSum) );
319}
320
321void CalculatorImpl::std_funcs(int button) {
322 if ( state == sError )
323 return;
324 if ( current_mode < pre_conv_modes_count ||
325 button > changeable_func_button_count-1 ) {
326 Operation op;
327 if ( button < 10 )
328 op = (Operation)(button + oSin);
329 else if ( button == 10 )
330 op = oOpenBrace;
331 else
332 op = oCloseBrace;
333 execOp( op );
334 }
335}
336
337void CalculatorImpl::execOp( Operation i )
338{
339 switch (i) {
340 // these operators only affect the current number.
341 case oDivX:
342 case oLog:
343 case oLn:
344 case oSin:
345 case oCos:
346 case oTan:
347 num = evalExpr(i);
348 break;
349
350 case oAdd:
351 case oSub: {
352 processStack( oAdd );
353 Op op( num, i );
354 operationStack.push( op );
355 break;
356 }
357 case oDiv:
358 case oMult:
359 case oRoot:
360 case oXsquared: {
361 processStack( oDiv );
362 Op op( num, i );
363 operationStack.push( op );
364 break;
365 }
366 case oChSign:
367 num = -num;
368 LCD->display(num);
369 return;
370
371 case oOpenBrace: {
372 Op op( 0, oOpenBrace );
373 operationStack.push( op );
374 numOpenBraces++;
375 state = sNewNumber;
376 return;
377 }
378 case oCloseBrace: {
379 if ( numOpenBraces == 0 )
380 return;
381 processStack( oAdd );
382 if ( operationStack.top().operation != oOpenBrace )
383 qDebug( "Calculator: internal Error" );
384 operationStack.pop();
385 state = sNewNumber;
386 numOpenBraces--;
387 break;
388 }
389
390 case oPoint:
391 flPoint = TRUE;
392 return;
393
394 case oPercent:
395 processStack( oPercent );
396 break;
397
398
399 case oSum:
400 processStack( oSum );
401 break;
402
403 default:
404 return;
405 };
406
407 if ( state == sError ) {
408 LCD->display( "Error" );
409 return;
410 } else {
411 LCD->display(num);
412 }
413 state = sNewNumber;
414 numDecimals = 0;
415 flPoint = FALSE;
416}
417
418
419void CalculatorImpl::processStack( int op )
420{
421 //dubious percent hack, since the changeable operator precedences are
422 //pretty much hardwired to be less than the non-changeable
423 bool percent = FALSE;
424 if ( op == oPercent ) {
425 percent = TRUE;
426 op = oSum;
427 }
428 while( !operationStack.isEmpty() && operationStack.top().operation >= op ) {
429 Op operation = operationStack.pop();
430 acc = operation.number;
431 if ( percent ) {
432 if ( operation.operation == oAdd || operation.operation == oSub )
433 num = acc*num/100;
434 else
435 num = num / 100;
436 }
437 num = evalExpr( operation.operation );
438 percent = FALSE;
439 }
440}
441
442
443double CalculatorImpl::evalExpr( int op ) {
444 double sum = 0;
445
446 switch( op ){
447 case oPercent: sum = num / 100.; break;
448 case oDivX:
449 if (num == 0)
450 state = sError;
451 else
452 sum = 1 / num;
453 break;
454 case oXsquared:
455 sum = pow(acc,num);
456 break;
457 case oChSign: (state == sStart) ? sum = -num : sum = -acc; break;
458 case oSub: sum = acc - num; break;
459 case oMult: sum = acc * num; break;
460 case oAdd: sum = acc + num; break;
461 case oDiv: {
462 if (num == 0) {
463 state = sError;
464 } else {
465 sum = acc / num;
466 }
467 break;
468 }
469 case oRoot:
470 /* the linux library is dumb, and can't to -x to 1/n
471 when n is odd. (even and error of course is acceptable */
472 if((acc < 0) && (int(num) == num) && (int(num) % 2 == 1 )) {
473 sum = pow(-acc, 1 / num);
474 sum = -sum;
475 } else {
476 sum = pow(acc, 1 / num);
477 }
478 break;
479 case oLog:
480 sum = log10(num);
481 break;
482 case oLn:
483 sum = log(num);
484 break;
485 case oTan: sum = qTan(num);break;
486 case oSin: sum = qSin(num);break;
487 case oCos: sum = qCos(num);break;
488 default: sum = num; break;
489 }
490
491 if ( isinf( sum ) || isnan( sum ) )
492 state = sError;
493 return sum;
494}
495
496
497void CalculatorImpl::enterNumber( int n )
498{
499 if ( state == sError )
500 return;
501 if( state == sStart ){
502 if( LCD->value() > 0 ){
503 QString s = QString::number( LCD->value(), 'g', LCD->numDigits());
504 if( s.length() > (uint)(LCD->numDigits() - 2)) return;
505
506 } else if( (int)fake.length() >= LCD->numDigits() || numDecimals >=12 ){
507 return;
508 }
509 }
510
511 if( state == sNewNumber ){
512 state = sStart;
513 acc = 0;
514 if( flPoint ){
515 numDecimals = 1;
516 num = n / pow(10, numDecimals);
517 } else
518 num = n;
519 } else if( flPoint ){
520 numDecimals++;
521 if( num < 0 ){
522 num -= n / pow(10, numDecimals);
523 } else {
524 num += n / pow(10, numDecimals);
525 }
526 } else {
527 num *= 10;
528 if( num < 0 )
529 num -= n;
530 else
531 num += n;
532 }
533
534 // We need feedback in the calc display while entering fl.point zeros.
535 // This is a small hack to display sequences like: 0.000 and 1.100
536 double integer, fraction;
537 fraction = modf( num, &integer );
538 if( flPoint ){
539 QString is, fs, zeros;
540
541 is = QString::number( integer, 'g', 13 );
542 fs = QString::number( fraction, 'g', numDecimals );
543 if( fs.contains('e') ){
544 fs = QString::number( fraction, 'f', LCD->numDigits() );
545 }
546 fs = fs.mid( 2, numDecimals );
547
548 if( (integer == 0) && (fraction == 0) )
549 fake = "0.";
550 else if( (integer != 0) && (fraction == 0) )
551 fake = is + ".";
552 else
553 fake = is + "." + fs;
554
555 zeros.fill( '0', (numDecimals - fs.length()) );
556 fake += zeros;
557 // ### This code sets LCD->value() to zero since it sets a text
558 // ### Avoid getting the current value from LCD->value() for
559 // ### calculations.
560 LCD->display( fake );
561 } else
562 LCD->display( num );
563}
564
565void CalculatorImpl::command_buttons(int i) {
566 if ( state == sError && i != 3 )
567 return;
568 switch (i) {
569 case 0: // M+
570 mem += num;
571 if( mem != 0 ){
572 memMark->show();
573 PushButtonMR->setEnabled( TRUE ); };
574 state = sNewNumber;
575 break;
576 case 1: // MR
577 acc = num = mem;
578 state = sNewNumber;
579 LCD->display( mem );
580 break;
581 case 2: // MC
582 mem = 0;
583 memMark->hide();
584 PushButtonMR->setEnabled( FALSE );
585 break;
586 case 3: // CE
587 if ( state == sStart ) {
588 // clear the entered number on the first press
589 state = sNewNumber;
590 num = acc = 0;
591 flPoint = FALSE;
592 LCD->display( 0 );
593 fake = QString::null;
594 numDecimals = 0;
595 } else {
596 clear();
597 }
598 break;
599 };
600
601}
diff --git a/noncore/tools/calculator/calculatorimpl.h b/noncore/tools/calculator/calculatorimpl.h
new file mode 100644
index 0000000..bfb726f
--- a/dev/null
+++ b/noncore/tools/calculator/calculatorimpl.h
@@ -0,0 +1,135 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CALCULATORIMPL_H
21#define CALCULATORIMPL_H
22
23
24#include <qlcdnumber.h>
25#include "calculator.h"
26#include <qpushbutton.h>
27#include <qbuttongroup.h>
28#include <qvaluestack.h>
29
30// mode x functions
31enum Operation {
32 oNop,
33 oOpenBrace,
34 oCloseBrace,
35 oSum,
36 oPoint,
37 oAdd,
38 oSub,
39 oDiv,
40 oMult,
41
42// mode 0 functions
43 oSin,
44 oCos,
45 oTan,
46 oDivX,
47 oPercent,
48 oXsquared,
49 oRoot,
50 oLog,
51 oLn,
52 oChSign
53};
54
55// states
56#define sStart 0
57#define sNewNumber 1
58#define sError 2
59
60struct Op
61{
62 Op() { number = 0; operation = oNop; }
63 Op( double num, Operation op )
64 { number = num; operation = op; }
65 double number;
66 Operation operation;
67};
68
69class QLabel;
70class CalculatorImpl : public Calculator
71{
72 Q_OBJECT
73
74public:
75 CalculatorImpl( QWidget * parent = 0, const char * name = 0,
76 WFlags f = 0 );
77
78public slots:
79 void command_buttons(int);
80 void enterNumber(int i);
81 void std_buttons(int);
82 void std_funcs(int);
83 void do_convert(int);
84 void function_button(int);
85
86protected:
87 virtual bool eventFilter( QObject *o, QEvent *e );
88
89private:
90 void clear();
91
92 void reset_conv();
93
94 void processStack( int op );
95
96 QValueStack<Op> operationStack;
97 int state;
98
99 double acc, num, mem;
100 int numDecimals;
101 bool flPoint;
102 int numOpenBraces;
103
104 void execOp( Operation i );
105 double evalExpr( int op );
106 QLabel * memMark;
107 QString fake;
108
109 // useful values for conversion stuff
110 int current_mode, max_mode, conversion_mode_count, last_conversion;
111
112 // make adding new modes easier for ourselves
113 static const int pre_conv_modes_count = 1;
114 static const int post_conv_modes_count = 0;
115
116 // an array of pointers to the func buttons
117 static const int func_button_count = 12;
118 // this is an abomination
119 static const int changeable_func_button_count = 10;
120 QPushButton* func_buttons[func_button_count];
121
122 QButtonGroup bgr_function, bgr_digits, bgr_std, bgr_command;
123 QStringList faces, captions;
124
125 // an array of doubles holding the conversion ratios
126 double* entry_list;
127
128 QPixmap xtopowerofy;
129 QPixmap ythrootofx;
130 QPixmap oneoverx;
131
132 void display_pixmap_faces(void);
133};
134
135#endif
diff --git a/noncore/tools/calculator/main.cpp b/noncore/tools/calculator/main.cpp
new file mode 100644
index 0000000..74cd5d3
--- a/dev/null
+++ b/noncore/tools/calculator/main.cpp
@@ -0,0 +1,35 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "calculatorimpl.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char ** argv )
26{
27 QPEApplication a( argc, argv );
28
29 CalculatorImpl mw;
30 QPEApplication::setInputMethodHint( &mw, QPEApplication::AlwaysOff );
31 mw.setCaption( CalculatorImpl::tr("Calculator") );
32 a.showMainWidget( &mw );
33
34 return a.exec();
35}
diff --git a/noncore/tools/calculator/qpe-calculator.control b/noncore/tools/calculator/qpe-calculator.control
new file mode 100644
index 0000000..afef70b
--- a/dev/null
+++ b/noncore/tools/calculator/qpe-calculator.control
@@ -0,0 +1,10 @@
1Files: bin/calculator apps/Applications/calculator.desktop etc/unit_conversion.dat
2Priority: optional
3Section: qpe/applications
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Calculator
9 A multi-function calculator for the Qtopia environment.
10 Includes units conversion.
diff --git a/noncore/tools/clock/.cvsignore b/noncore/tools/clock/.cvsignore
new file mode 100644
index 0000000..6fe2396
--- a/dev/null
+++ b/noncore/tools/clock/.cvsignore
@@ -0,0 +1,2 @@
1moc_*
2Makefile
diff --git a/noncore/tools/clock/Makefile.in b/noncore/tools/clock/Makefile.in
new file mode 100644
index 0000000..adda9e6
--- a/dev/null
+++ b/noncore/tools/clock/Makefile.in
@@ -0,0 +1,118 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= clock
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =clock.h
27 SOURCES =clock.cpp \
28 main.cpp
29 OBJECTS =clock.o \
30 main.o
31INTERFACES =
32UICDECLS =
33UICIMPLS =
34 SRCMOC =moc_clock.cpp
35 OBJMOC =moc_clock.o
36
37
38####### Implicit rules
39
40.SUFFIXES: .cpp .cxx .cc .C .c
41
42.cpp.o:
43 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
44
45.cxx.o:
46 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
47
48.cc.o:
49 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
50
51.C.o:
52 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
53
54.c.o:
55 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
56
57####### Build rules
58
59
60all: $(DESTDIR)$(TARGET)
61
62$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
63 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
64
65moc: $(SRCMOC)
66
67tmake:
68 tmake clock.pro
69
70clean:
71 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
72 -rm -f *~ core
73 -rm -f allmoc.cpp
74
75####### Extension Modules
76
77listpromodules:
78 @echo
79
80listallmodules:
81 @echo
82
83listaddonpromodules:
84 @echo
85
86listaddonentmodules:
87 @echo
88
89
90REQUIRES=
91
92####### Sub-libraries
93
94
95###### Combined headers
96
97
98
99####### Compile
100
101clock.o: clock.cpp \
102 clock.h \
103 $(QPEDIR)/include/qpe/qpeapplication.h \
104 $(QPEDIR)/include/qpe/qcopenvelope_qws.h \
105 $(QPEDIR)/include/qpe/config.h \
106 $(QPEDIR)/include/qpe/timestring.h
107
108main.o: main.cpp \
109 clock.h \
110 $(QPEDIR)/include/qpe/qpeapplication.h
111
112moc_clock.o: moc_clock.cpp \
113 clock.h
114
115moc_clock.cpp: clock.h
116 $(MOC) clock.h -o moc_clock.cpp
117
118
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
new file mode 100644
index 0000000..ef93e11
--- a/dev/null
+++ b/noncore/tools/clock/clock.cpp
@@ -0,0 +1,319 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "clock.h"
22
23#include <qpe/qpeapplication.h>
24#include <qpe/qcopenvelope_qws.h>
25#include <qpe/config.h>
26#include <qpe/timestring.h>
27
28#include <qlcdnumber.h>
29#include <qlabel.h>
30#include <qlayout.h>
31#include <qtimer.h>
32#include <qpushbutton.h>
33#include <qradiobutton.h>
34#include <qbuttongroup.h>
35#include <qpainter.h>
36
37#include <math.h>
38
39 const double deg2rad = 0.017453292519943295769;// pi/180
40const int sw_prec = 2;
41
42static void toggleScreenSaver( bool on )
43{
44 QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" );
45 e << (on ? QPEApplication::Enable: QPEApplication::DisableSuspend );
46}
47
48Clock::Clock( QWidget * parent, const char * name, WFlags f )
49 : QVBox( parent, name , f )
50{
51 setSpacing( 4 );
52 setMargin( 1 );
53
54 Config config( "qpe" );
55 config.setGroup("Time");
56 ampm = config.readBoolEntry( "AMPM", TRUE );
57
58 aclock = new AnalogClock( this );
59 aclock->display( QTime::currentTime() );
60 aclock->setLineWidth( 2 );
61
62 QHBox *hb = new QHBox( this );
63 hb->setMargin( 0 );
64 QWidget *space = new QWidget( hb );
65 lcd = new QLCDNumber( hb );
66 lcd->setSegmentStyle( QLCDNumber::Flat );
67 lcd->setFrameStyle( QFrame::NoFrame );
68 lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
69 lcd->setFixedHeight( 23 );
70
71 ampmLabel = new QLabel( "PM", hb );
72 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
73 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) );
74 ampmLabel->setAlignment( AlignLeft | AlignBottom );
75 space = new QWidget( hb );
76
77 date = new QLabel( this );
78 date->setAlignment( AlignHCenter | AlignVCenter );
79 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
80 date->setText( TimeString::longDateString( QDate::currentDate() ) );
81
82 QWidget *controls = new QWidget( this );
83 QGridLayout *gl = new QGridLayout( controls, 2, 2, 6, 4 );
84
85 QButtonGroup *grp = new QButtonGroup( controls );
86 grp->setRadioButtonExclusive( true );
87 grp->hide();
88
89 clockRB = new QRadioButton ( tr( "Clock" ), controls );
90 gl->addWidget( clockRB, 0, 0 );
91 grp->insert( clockRB );
92
93 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls );
94 gl->addWidget( swatchRB, 1, 0 );
95 grp->insert( swatchRB );
96
97 connect( grp, SIGNAL(clicked(int)), this, SLOT(modeSelect(int)) );
98 grp->setButton( 0 );
99
100 set = new QPushButton ( controls );
101 gl->addWidget( set, 0, 1 );
102 set->setText( tr( "Start" ) );
103 set->setEnabled( FALSE );
104 grp->insert( set );
105
106 reset = new QPushButton ( controls );
107 gl->addWidget( reset, 1, 1 );
108 reset->setText( tr( "Reset" ) );
109 reset->setEnabled( FALSE );
110 grp->insert( reset );
111
112 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) );
113 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) );
114
115 t = new QTimer( this );
116 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) );
117 t->start( 1000 );
118
119 connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) );
120
121 swatch_running = FALSE;
122 swatch_totalms = 0;
123
124 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
125
126 QTimer::singleShot( 0, this, SLOT(updateClock()) );
127 modeSelect(0);
128}
129
130Clock::~Clock()
131{
132 toggleScreenSaver( true );
133}
134
135void Clock::updateClock()
136{
137 if ( clockRB->isChecked() ) {
138 QTime tm = QDateTime::currentDateTime().time();
139 QString s;
140 if ( ampm ) {
141 int hour = tm.hour();
142 if (hour == 0)
143 hour = 12;
144 if (hour > 12)
145 hour -= 12;
146 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() );
147 ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" );
148 ampmLabel->show();
149 } else {
150 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
151 ampmLabel->hide();
152 }
153 lcd->display( s );
154 lcd->repaint( FALSE );
155 aclock->display( QTime::currentTime() );
156 date->setText( TimeString::longDateString( QDate::currentDate() ) );
157 } else {
158 QTime swatch_time;
159 QString lcdtext;
160 int totalms = swatch_totalms;
161 if ( swatch_running )
162 totalms += swatch_start.elapsed();
163 swatch_time = QTime(0,0,0).addMSecs(totalms);
164 QString d = swatch_running ? QString(" ")
165 : QString::number(totalms%1000+1000);
166 lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec);
167 lcd->display( lcdtext );
168 lcd->repaint( FALSE );
169 aclock->display( swatch_time );
170 date->setText( TimeString::longDateString( QDate::currentDate() ) );
171 }
172}
173
174void Clock::changeClock( bool a )
175{
176 ampm = a;
177 updateClock();
178}
179
180void Clock::clearClock( void )
181{
182 lcd->display( QTime( 0,0,0 ).toString() );
183 aclock->display( QTime( 0,0,0 ) );
184}
185
186void Clock::slotSet()
187{
188 if ( t->isActive() ) {
189 swatch_totalms += swatch_start.elapsed();
190 set->setText( tr( "Start" ) );
191 t->stop();
192 swatch_running = FALSE;
193 toggleScreenSaver( TRUE );
194 updateClock();
195 } else {
196 swatch_start.start();
197 set->setText( tr( "Stop" ) );
198 t->start( 1000 );
199 swatch_running = TRUE;
200 // disable screensaver while stop watch is running
201 toggleScreenSaver( FALSE );
202 }
203}
204
205void Clock::slotReset()
206{
207 t->stop();
208 swatch_start.start();
209 swatch_totalms = 0;
210
211 if (swatch_running )
212 t->start(1000);
213
214 updateClock();
215}
216
217void Clock::modeSelect( int m )
218{
219 if ( m ) {
220 lcd->setNumDigits( 8+1+sw_prec );
221 lcd->setMinimumWidth( lcd->sizeHint().width() );
222 set->setEnabled( TRUE );
223 reset->setEnabled( TRUE );
224 ampmLabel->hide();
225
226 if ( !swatch_running )
227 t->stop();
228 } else {
229 lcd->setNumDigits( 5 );
230 lcd->setMinimumWidth( lcd->sizeHint().width() );
231 set->setEnabled( FALSE );
232 reset->setEnabled( FALSE );
233 t->start(1000);
234 }
235 updateClock();
236}
237
238QSizePolicy AnalogClock::sizePolicy() const
239{
240 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
241}
242
243void AnalogClock::drawContents( QPainter *p )
244{
245 QRect r = contentsRect();
246 QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 );
247
248 QPoint l1( r.x() + r.width() / 2, r.y() + 2 );
249 QPoint l2( r.x() + r.width() / 2, r.y() + 8 );
250
251 QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 );
252 QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
253
254 QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 8 );
255 QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
256
257 QPoint s1( r.x() + r.width() / 2, r.y() + 8 );
258 QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
259
260 QColor color( clear ? backgroundColor() : black );
261 QTime time = clear ? prevTime : currTime;
262
263 if ( clear && prevTime.secsTo(currTime) > 1 ) {
264 p->eraseRect( rect() );
265 return;
266 }
267
268 if ( !clear ) {
269 // draw ticks
270 p->setPen( QPen( color, 1 ) );
271 for ( int i = 0; i < 12; i++ )
272 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
273 }
274
275 if ( !clear || prevTime.minute() != currTime.minute() ||
276 prevTime.hour() != currTime.hour() ) {
277 // draw hour pointer
278 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
279 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
280 p->setPen( QPen( color, 3 ) );
281 p->drawLine( h1, h2 );
282 }
283
284 if ( !clear || prevTime.minute() != currTime.minute() ) {
285 // draw minute pointer
286 m1 = rotate( center, m1, time.minute() * 6 );
287 m2 = rotate( center, m2, time.minute() * 6 );
288 p->setPen( QPen( color, 2 ) );
289 p->drawLine( m1, m2 );
290 }
291
292 // draw second pointer
293 s1 = rotate( center, s1, time.second() * 6 );
294 s2 = rotate( center, s2, time.second() * 6 );
295 p->setPen( QPen( color, 1 ) );
296 p->drawLine( s1, s2 );
297
298 if ( !clear )
299 prevTime = currTime;
300}
301
302void AnalogClock::display( const QTime& t )
303{
304 currTime = t;
305 clear = true;
306 repaint( false );
307 clear = false;
308 repaint( false );
309}
310
311QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
312{
313 double angle = deg2rad * ( - a + 180 );
314 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
315 ( p.y() - c.y() ) * sin( angle );
316 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
317 ( p.x() - c.x() ) * sin( angle );
318 return QPoint( nx, ny );
319}
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h
new file mode 100644
index 0000000..6dbebf7
--- a/dev/null
+++ b/noncore/tools/clock/clock.h
@@ -0,0 +1,87 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CLOCK_H
21#define CLOCK_H
22
23#include <qdatetime.h>
24#include <qvbox.h>
25
26class QLCDNumber;
27class QLabel;
28class QTimer;
29class QRadioButton;
30class QPushButton;
31
32class AnalogClock : public QFrame
33{
34 Q_OBJECT
35
36public:
37 AnalogClock( QWidget * parent = 0, const char * name = 0 )
38 : QFrame( parent, name ), clear(false) {}
39
40 QSizePolicy sizePolicy() const;
41
42 void display( const QTime& time );
43
44protected:
45 void drawContents( QPainter *p );
46
47private:
48 QPoint rotate( QPoint center, QPoint p, int angle );
49
50 QTime currTime;
51 QTime prevTime;
52 bool clear;
53};
54
55class Clock : public QVBox
56{
57 Q_OBJECT
58
59public:
60 Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 );
61 ~Clock();
62
63private slots:
64 void slotSet();
65 void slotReset();
66 void modeSelect(int);
67 void updateClock();
68 void changeClock( bool );
69
70private:
71 void clearClock();
72
73 QTimer *t;
74 QLCDNumber *lcd;
75 QLabel *date;
76 QLabel *ampmLabel;
77 QPushButton *set, *reset;
78 QRadioButton *clockRB, *swatchRB;
79 AnalogClock *aclock;
80 QTime swatch_start;
81 int swatch_totalms;
82 bool swatch_running;
83 bool ampm;
84};
85
86#endif
87
diff --git a/noncore/tools/clock/clock.pro b/noncore/tools/clock/clock.pro
new file mode 100644
index 0000000..97f4d2c
--- a/dev/null
+++ b/noncore/tools/clock/clock.pro
@@ -0,0 +1,13 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 DESTDIR = $(QPEDIR)/bin
4 HEADERS = clock.h
5 SOURCES = clock.cpp \
6 main.cpp
7INCLUDEPATH += $(QPEDIR)/include
8 DEPENDPATH+= $(QPEDIR)/include
9LIBS += -lqpe
10 INTERFACES=
11 TARGET = clock
12
13TRANSLATIONS = ../i18n/de/clock.ts
diff --git a/noncore/tools/clock/main.cpp b/noncore/tools/clock/main.cpp
new file mode 100644
index 0000000..cbfb73b
--- a/dev/null
+++ b/noncore/tools/clock/main.cpp
@@ -0,0 +1,34 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "clock.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char ** argv )
26{
27 QPEApplication a( argc, argv );
28
29 Clock mw;
30 mw.setCaption( Clock::tr("Clock") );
31 a.showMainWidget( &mw );
32
33 return a.exec();
34}
diff --git a/noncore/tools/clock/qpe-clock.control b/noncore/tools/clock/qpe-clock.control
new file mode 100644
index 0000000..62f377f
--- a/dev/null
+++ b/noncore/tools/clock/qpe-clock.control
@@ -0,0 +1,9 @@
1Files: bin/clock apps/Applications/clock.desktop
2Priority: optional
3Section: qpe/applications
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Clock and stop-watch
9 A simple clock and stop-watch for the Qtopia environment.
diff --git a/noncore/unsupported/filebrowser/.cvsignore b/noncore/unsupported/filebrowser/.cvsignore
new file mode 100644
index 0000000..6fe2396
--- a/dev/null
+++ b/noncore/unsupported/filebrowser/.cvsignore
@@ -0,0 +1,2 @@
1moc_*
2Makefile
diff --git a/noncore/unsupported/filebrowser/Makefile.in b/noncore/unsupported/filebrowser/Makefile.in
new file mode 100644
index 0000000..c7238ea
--- a/dev/null
+++ b/noncore/unsupported/filebrowser/Makefile.in
@@ -0,0 +1,136 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= filebrowser
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =inlineedit.h \
27 filebrowser.h
28 SOURCES =filebrowser.cpp \
29 inlineedit.cpp \
30 main.cpp
31 OBJECTS =filebrowser.o \
32 inlineedit.o \
33 main.o
34INTERFACES =
35UICDECLS =
36UICIMPLS =
37 SRCMOC =moc_inlineedit.cpp \
38 moc_filebrowser.cpp
39 OBJMOC =moc_inlineedit.o \
40 moc_filebrowser.o
41
42
43####### Implicit rules
44
45.SUFFIXES: .cpp .cxx .cc .C .c
46
47.cpp.o:
48 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
49
50.cxx.o:
51 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
52
53.cc.o:
54 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
55
56.C.o:
57 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
58
59.c.o:
60 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
61
62####### Build rules
63
64
65all: $(DESTDIR)$(TARGET)
66
67$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
68 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
69
70moc: $(SRCMOC)
71
72tmake:
73 tmake filebrowser.pro
74
75clean:
76 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
77 -rm -f *~ core
78 -rm -f allmoc.cpp
79
80####### Extension Modules
81
82listpromodules:
83 @echo
84
85listallmodules:
86 @echo
87
88listaddonpromodules:
89 @echo
90
91listaddonentmodules:
92 @echo
93
94
95REQUIRES=
96
97####### Sub-libraries
98
99
100###### Combined headers
101
102
103
104####### Compile
105
106filebrowser.o: filebrowser.cpp \
107 inlineedit.h \
108 filebrowser.h \
109 $(QPEDIR)/include/qpe/resource.h \
110 $(QPEDIR)/include/qpe/global.h \
111 $(QPEDIR)/include/qpe/mimetype.h \
112 $(QPEDIR)/include/qpe/applnk.h \
113 $(QPEDIR)/include/qpe/qpetoolbar.h \
114 $(QPEDIR)/include/qpe/qpemenubar.h
115
116inlineedit.o: inlineedit.cpp \
117 inlineedit.h
118
119main.o: main.cpp \
120 filebrowser.h \
121 $(QPEDIR)/include/qpe/qpeapplication.h \
122 $(QPEDIR)/include/qpe/mimetype.h
123
124moc_inlineedit.o: moc_inlineedit.cpp \
125 inlineedit.h
126
127moc_filebrowser.o: moc_filebrowser.cpp \
128 filebrowser.h
129
130moc_inlineedit.cpp: inlineedit.h
131 $(MOC) inlineedit.h -o moc_inlineedit.cpp
132
133moc_filebrowser.cpp: filebrowser.h
134 $(MOC) filebrowser.h -o moc_filebrowser.cpp
135
136
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp
new file mode 100644
index 0000000..9439bb8
--- a/dev/null
+++ b/noncore/unsupported/filebrowser/filebrowser.cpp
@@ -0,0 +1,850 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "inlineedit.h"
22#include "filebrowser.h"
23
24#include <qpe/resource.h>
25#include <qpe/global.h>
26#include <qpe/mimetype.h>
27#include <qpe/applnk.h>
28
29#include <qcopchannel_qws.h>
30#include <qmessagebox.h>
31#include <qdir.h>
32#include <qregexp.h>
33#include <qheader.h>
34#include <qpe/qpetoolbar.h>
35#include <qpopupmenu.h>
36#include <qpe/qpemenubar.h>
37#include <qaction.h>
38#include <qstringlist.h>
39#include <qcursor.h>
40#include <qmultilineedit.h>
41#include <qfont.h>
42
43#include <unistd.h>
44#include <stdlib.h>
45#include <sys/stat.h>
46
47//
48// FileItem
49//
50FileItem::FileItem( QListView * parent, const QFileInfo & fi )
51 : QListViewItem( parent ),
52 fileInfo( fi )
53{
54 QDate d = fi.lastModified().date();
55
56 setText( 0, fi.fileName() );
57 setText( 1, sizeString( fi.size() ) + " " );
58 setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) );
59
60 MimeType mt(fi.filePath());
61
62 if( fi.isDir() )
63 setText( 3, "directory" );
64 else if( isLib() )
65 setText( 3, "library" );
66 else
67 setText( 3, mt.description() );
68
69 QPixmap pm;
70 if( fi.isDir() ){
71 if( !QDir( fi.filePath() ).isReadable() )
72 pm = Resource::loadPixmap( "lockedfolder" );
73 else
74 pm = Resource::loadPixmap( "folder" );
75 }
76 else if( !fi.isReadable() )
77 pm = Resource::loadPixmap( "locked" );
78 else if( isLib() )
79 pm = Resource::loadPixmap( "library" );
80 else
81 pm = mt.pixmap();
82 if ( pm.isNull() )
83 pm = Resource::loadPixmap("UnknownDocument-14");
84 setPixmap(0,pm);
85}
86
87QString FileItem::sizeString( unsigned int s )
88{
89 double size = s;
90
91 if ( size > 1024 * 1024 * 1024 )
92 return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G";
93 else if ( size > 1024 * 1024 )
94 return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M";
95 else if ( size > 1024 )
96 return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K";
97 else
98 return QString::number( size ) + "B";
99}
100
101QString FileItem::key( int column, bool ascending ) const
102{
103 QString tmp;
104
105 ascending = ascending;
106
107 if( (column == 0) && fileInfo.isDir() ){ // Sort by name
108 // We want the directories to appear at the top of the list
109 tmp = (char) 0;
110 return (tmp + text( column ).lower());
111 }
112 else if( column == 2 ) { // Sort by date
113 QDateTime epoch( QDate( 1980, 1, 1 ) );
114 tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) );
115 return tmp;
116 }
117 else if( column == 1 ) { // Sort by size
118 return tmp.sprintf( "%08d", fileInfo.size() );
119 }
120
121 return text( column ).lower();
122}
123
124bool FileItem::isLib()
125{
126 // This is of course not foolproof
127 if( !qstrncmp("lib", fileInfo.baseName(), 3) &&
128 ( fileInfo.extension().contains( "so" ) ||
129 fileInfo.extension().contains( "a" ) ) )
130 return TRUE;
131 else
132 return FALSE;
133}
134
135int FileItem::launch()
136{
137 DocLnk doc( fileInfo.filePath(), FALSE );
138 doc.execute();
139 listView()->clearSelection();
140 return 1;
141}
142
143bool FileItem::rename( const QString & name )
144{
145 QString oldpath, newpath;
146
147 if ( name.isEmpty() )
148 return FALSE;
149
150 if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) )
151 return FALSE;
152
153 oldpath = fileInfo.filePath();
154 newpath = fileInfo.dirPath() + "/" + name;
155
156 if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 )
157 return FALSE;
158 else
159 return TRUE;
160}
161
162//
163// FileView
164//
165FileView::FileView( const QString & dir, QWidget * parent,
166 const char * name )
167 : QListView( parent, name ),
168 menuTimer( this ),
169 le( NULL ),
170 itemToRename( NULL )
171{
172 addColumn( "Name" );
173 addColumn( "Date" );
174 addColumn( "Size" );
175 addColumn( "Type" );
176
177 setMultiSelection( TRUE );
178 header()->hide();
179
180 setColumnWidthMode( 0, Manual );
181 setColumnWidthMode( 3, Manual );
182
183 // right align yize column
184 setColumnAlignment( 1, AlignRight );
185
186 generateDir( dir );
187
188 connect( this, SIGNAL( clicked( QListViewItem * )),
189 SLOT( itemClicked( QListViewItem * )) );
190 connect( this, SIGNAL( doubleClicked( QListViewItem * )),
191 SLOT( itemDblClicked( QListViewItem * )) );
192 connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) );
193 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) );
194}
195
196void FileView::resizeEvent( QResizeEvent *e )
197{
198 setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) );
199
200 // hide type column, we use it for "sort by type" only
201 setColumnWidth( 3, 0 );
202 QListView::resizeEvent( e );
203}
204
205void FileView::updateDir()
206{
207 generateDir( currentDir );
208}
209
210void FileView::setDir( const QString & dir )
211{
212 if ( dir.startsWith( "/dev" ) ) {
213 QMessageBox::warning( this, tr( "File Manager" ),
214 tr( "Can't show /dev/ directory." ), tr( "&Ok" ) );
215 return;
216 }
217 dirHistory += currentDir;
218 generateDir( dir );
219}
220
221void FileView::generateDir( const QString & dir )
222{
223 QDir d( dir );
224
225 if( d.exists() && !d.isReadable() ) return;
226
227 currentDir = d.canonicalPath();
228
229 d.setFilter( QDir::Dirs | QDir::Files );
230 d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase |
231 QDir::Reversed );
232
233 const QFileInfoList * list = d.entryInfoList();
234 QFileInfoListIterator it( *list );
235 QFileInfo *fi;
236
237 clear();
238 while( (fi = it.current()) ){
239 if( (fi->fileName() == ".") || (fi->fileName() == "..") ){
240 ++it;
241 continue;
242 }
243 (void) new FileItem( (QListView *) this, *fi );
244 ++it;
245 }
246
247 emit dirChanged();
248}
249
250void FileView::rename()
251{
252 itemToRename = (FileItem *) currentItem();
253 const QPixmap * pm;
254 int pmw;
255
256 if( itemToRename == NULL ) return;
257
258 if( ( pm = itemToRename->pixmap( 0 ) ) == NULL )
259 pmw = 0;
260 else
261 pmw = pm->width();
262
263 ensureItemVisible( itemToRename );
264 horizontalScrollBar()->setValue( 0 );
265 horizontalScrollBar()->setEnabled( FALSE );
266 verticalScrollBar()->setEnabled( FALSE );
267
268 selected = isSelected( itemToRename );
269 setSelected( itemToRename, FALSE );
270
271 if( le == NULL ){
272 le = new InlineEdit( this );
273 le->setFrame( FALSE );
274 connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) );
275 }
276
277 QRect r = itemRect( itemToRename );
278 r.setTop( r.top() + frameWidth() + 1 );
279 r.setLeft( r.left() + frameWidth() + pmw );
280 r.setBottom( r.bottom() + frameWidth() );
281 r.setWidth( columnWidth( 0 ) - pmw );
282
283 le->setGeometry( r );
284 le->setText( itemToRename->text( 0 ) );
285 le->selectAll();
286 le->show();
287 le->setFocus();
288}
289
290void FileView::endRenaming()
291{
292 if( le && itemToRename ){
293 le->hide();
294 setSelected( itemToRename, selected );
295
296 if( !itemToRename->rename( le->text() ) ){
297 QMessageBox::warning( this, tr( "Rename file" ),
298 tr( "Rename failed!" ), tr( "&Ok" ) );
299 } else {
300 updateDir();
301 }
302 itemToRename = NULL;
303 horizontalScrollBar()->setEnabled( TRUE );
304 verticalScrollBar()->setEnabled( TRUE );
305 }
306}
307
308void FileView::copy()
309{
310 // dont keep cut files any longer than necessary
311 // ##### a better inmplementation might be to rename the CUT file
312 // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it.
313 system ( "rm -rf /tmp/qpemoving" );
314
315 FileItem * i;
316
317 if((i = (FileItem *) firstChild()) == 0) return;
318
319 flist.clear();
320 while( i ){
321 if( i->isSelected() /*&& !i->isDir()*/ ){
322 flist += i->getFilePath();
323 }
324 i = (FileItem *) i->nextSibling();
325 }
326}
327
328void FileView::paste()
329{
330 int i, err;
331 QString cmd, dest, basename, cd = currentDir;
332
333 if(cd == "/") cd = "";
334
335 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) {
336 basename = (*it).mid((*it).findRev("/") + 1, (*it).length());
337
338 dest = cd + "/" + basename;
339 if( QFile( dest ).exists() ){
340 i = 1;
341 dest = cd + "/Copy of " + basename;
342 while( QFile( dest ).exists() ){
343 dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++,
344 (const char *) basename );
345 }
346 }
347
348 //
349 // Copy a directory recursively using the "cp" command -
350 // may have to be changed
351 //
352 if( QFileInfo( (*it) ).isDir() ){
353 cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\"";
354 err = system( (const char *) cmd );
355 } else if( !copyFile( dest, (*it) ) ){
356 err = -1;
357 } else {
358 err = 0;
359 }
360
361 if ( err != 0 ) {
362 QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"),
363 tr("Ok") );
364 break;
365 } else {
366 updateDir();
367 QListViewItem * i = firstChild();
368 basename = dest.mid( dest.findRev("/") + 1, dest.length() );
369
370 while( i ){
371 if( i->text(0) == basename ){
372 setCurrentItem( i );
373 ensureItemVisible( i );
374 break;
375 }
376 i = i->nextSibling();
377 }
378 }
379 }
380}
381
382bool FileView::copyFile( const QString & dest, const QString & src )
383{
384 char bf[ 50000 ];
385 int bytesRead;
386 bool success = TRUE;
387 struct stat status;
388
389 QFile s( src );
390 QFile d( dest );
391
392 if( s.open( IO_ReadOnly | IO_Raw ) &&
393 d.open( IO_WriteOnly | IO_Raw ) )
394 {
395 while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) ==
396 sizeof( bf ) )
397 {
398 if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){
399 success = FALSE;
400 break;
401 }
402 }
403 if( success && (bytesRead > 0) ){
404 d.writeBlock( bf, bytesRead );
405 }
406 } else {
407 success = FALSE;
408 }
409
410 // Set file permissions
411 if( stat( (const char *) src, &status ) == 0 ){
412 chmod( (const char *) dest, status.st_mode );
413 }
414
415 return success;
416}
417
418void FileView::cut()
419{
420 int err;
421 // ##### a better inmplementation might be to rename the CUT file
422 // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it.
423 QString cmd, dest, basename, cd = "/tmp/qpemoving";
424 QStringList newflist;
425 newflist.clear();
426
427 cmd = "rm -rf " + cd;
428 system ( (const char *) cmd );
429 cmd = "mkdir " + cd;
430 system( (const char *) cmd );
431
432// get the names of the files to cut
433 FileItem * item;
434
435 if((item = (FileItem *) firstChild()) == 0) return;
436
437 flist.clear();
438 while( item ){
439 if( item->isSelected() /*&& !item->isDir()*/ ){
440 flist += item->getFilePath();
441 }
442 item = (FileItem *) item->nextSibling();
443 }
444
445// move these files into a tmp dir
446 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) {
447 basename = (*it).mid((*it).findRev("/") + 1, (*it).length());
448
449 dest = cd + "/" + basename;
450
451 newflist += dest;
452
453 cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\"";
454 err = system( (const char *) cmd );
455
456 if ( err != 0 ) {
457 QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"),
458 tr("Ok") );
459 break;
460 } else {
461 updateDir();
462 QListViewItem * im = firstChild();
463 basename = dest.mid( dest.findRev("/") + 1, dest.length() );
464
465 while( im ){
466 if( im->text(0) == basename ){
467 setCurrentItem( im );
468 ensureItemVisible( im );
469 break;
470 }
471 im = im->nextSibling();
472 }
473 }
474 }
475
476 // update the filelist to point to tmp dir so paste works nicely
477 flist = newflist;
478}
479
480void FileView::del()
481{
482 FileItem * i;
483 QStringList fl;
484 QString cmd;
485 int err;
486
487 if((i = (FileItem *) firstChild()) == 0) return;
488
489 while( i ){
490 if( i->isSelected() ){
491 fl += i->getFilePath();
492 }
493 i = (FileItem *) i->nextSibling();
494 }
495 if( fl.count() < 1 ) return;
496
497 if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"),
498 tr("Yes"), tr("No") ) == 0)
499 {
500 //
501 // Dependant upon the "rm" command - will probably have to be replaced
502 //
503 for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) {
504 cmd = "/bin/rm -rf \"" + (*it) + "\"";
505 err = system( (const char *) cmd );
506 if ( err != 0 ) {
507 QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"),
508 tr("Ok") );
509 break;
510 }
511 }
512 updateDir();
513 }
514}
515
516void FileView::newFolder()
517{
518 int t = 1;
519 FileItem * i;
520 QString nd = currentDir + "/NewFolder";
521
522 while( QFile( nd ).exists() ){
523 nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ );
524 }
525
526 if( mkdir( (const char *) nd, 0777 ) != 0){
527 QMessageBox::warning( this, tr( "New folder" ),
528 tr( "Folder creation failed!" ),
529 tr( "Ok" ) );
530 return;
531 }
532 updateDir();
533
534 if((i = (FileItem *) firstChild()) == 0) return;
535
536 while( i ){
537 if( i->isDir() && ( i->getFilePath() == nd ) ){
538 setCurrentItem( i );
539 rename();
540 break;
541 }
542 i = (FileItem *) i->nextSibling();
543 }
544}
545
546void FileView::viewAsText()
547{
548 FileItem * i = (FileItem *) currentItem();
549 Global::execute( "textedit -f ", i->getFilePath() );
550}
551
552void FileView::itemClicked( QListViewItem * i)
553{
554 FileItem * t = (FileItem *) i;
555
556 if( t == NULL ) return;
557 if( t->isDir() ){
558 setDir( t->getFilePath() );
559 }
560}
561
562void FileView::itemDblClicked( QListViewItem * i)
563{
564 FileItem * t = (FileItem *) i;
565
566 if(t == NULL) return;
567 if(t->launch() == -1){
568 QMessageBox::warning( this, tr( "Launch Application" ),
569 tr( "Launch failed!" ), tr( "Ok" ) );
570 }
571}
572
573void FileView::parentDir()
574{
575 setDir( currentDir + "./.." );
576}
577
578void FileView::lastDir()
579{
580 if( dirHistory.count() == 0 ) return;
581
582 QString newDir = dirHistory.last();
583 dirHistory.remove( dirHistory.last() );
584 generateDir( newDir );
585}
586
587void FileView::contentsMousePressEvent( QMouseEvent * e )
588{
589 QListView::contentsMousePressEvent( e );
590 menuTimer.start( 750, TRUE );
591}
592
593void FileView::contentsMouseReleaseEvent( QMouseEvent * e )
594{
595 QListView::contentsMouseReleaseEvent( e );
596 menuTimer.stop();
597}
598
599void FileView::cancelMenuTimer()
600{
601 if( menuTimer.isActive() )
602 menuTimer.stop();
603}
604
605void FileView::addToDocuments()
606{
607 FileItem * i = (FileItem *) currentItem();
608 DocLnk f;
609 QString n = i->text(0);
610 n.replace(QRegExp("\\..*"),"");
611 f.setName( n );
612 f.setFile( i->getFilePath() );
613 f.writeLink();
614}
615
616void FileView::run()
617{
618 FileItem * i = (FileItem *) currentItem();
619 i->launch();
620}
621
622void FileView::showFileMenu()
623{
624 FileItem * i = (FileItem *) currentItem();
625 if ( !i )
626 return;
627
628 QPopupMenu * m = new QPopupMenu( this );
629
630 if ( !i->isDir() ) {
631 m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) );
632 m->insertSeparator();
633 }
634
635 MimeType mt(i->getFilePath());
636 const AppLnk* app = mt.application();
637
638 if ( !i->isDir() ) {
639 if ( app )
640 m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) );
641 else if( i->isExecutable() )
642 m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) );
643
644 m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ),
645 this, SLOT( viewAsText() ) );
646
647 m->insertSeparator();
648 }
649
650 m->insertItem( tr( "Rename" ), this, SLOT( rename() ) );
651 m->insertItem( Resource::loadPixmap("cut"),
652 tr( "Cut" ), this, SLOT( cut() ) );
653 m->insertItem( Resource::loadPixmap("copy"),
654 tr( "Copy" ), this, SLOT( copy() ) );
655 m->insertItem( Resource::loadPixmap("paste"),
656 tr( "Paste" ), this, SLOT( paste() ) );
657 m->insertItem( tr( "Delete" ), this, SLOT( del() ) );
658 m->insertSeparator();
659 m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) );
660 m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) );
661 m->popup( QCursor::pos() );
662}
663
664//
665// FileBrowser
666//
667
668FileBrowser::FileBrowser( QWidget * parent,
669 const char * name, WFlags f ) :
670 QMainWindow( parent, name, f )
671{
672 init( QDir::current().canonicalPath() );
673}
674
675FileBrowser::FileBrowser( const QString & dir, QWidget * parent,
676 const char * name, WFlags f ) :
677 QMainWindow( parent, name, f )
678{
679 init( dir );
680}
681
682void FileBrowser::init(const QString & dir)
683{
684 setCaption( tr("File Manager") );
685 setIcon( Resource::loadPixmap( "filebrowser_icon" ) );
686
687 fileView = new FileView( dir, this );
688 fileView->setAllColumnsShowFocus( TRUE );
689
690 setCentralWidget( fileView );
691 setToolBarsMovable( FALSE );
692
693 QPEToolBar* toolBar = new QPEToolBar( this );
694 toolBar->setHorizontalStretchable( TRUE );
695
696 QPEMenuBar* menuBar = new QPEMenuBar( toolBar );
697
698 dirMenu = new QPopupMenu( this );
699 menuBar->insertItem( tr( "Dir" ), dirMenu );
700
701 sortMenu = new QPopupMenu( this );
702 menuBar->insertItem( tr( "Sort" ), sortMenu );
703 sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) );
704 sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) );
705 sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) );
706 sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) );
707 sortMenu->insertSeparator();
708 sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) );
709 sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE );
710 sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE );
711
712 toolBar = new QPEToolBar( this );
713
714 lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ),
715 QString::null, 0, this, 0 );
716 connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) );
717 lastAction->addTo( toolBar );
718 lastAction->setEnabled( FALSE );
719
720 upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ),
721 QString::null, 0, this, 0 );
722 connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) );
723 upAction->addTo( toolBar );
724
725 QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ),
726 QString::null, 0, this, 0 );
727 connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) );
728 a->addTo( toolBar );
729
730 a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ),
731 QString::null, 0, this, 0 );
732 connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) );
733 a->addTo( toolBar );
734
735 a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ),
736 QString::null, 0, this, 0 );
737 connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) );
738 a->addTo( toolBar );
739
740 pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ),
741 QString::null, 0, this, 0 );
742 connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) );
743 pasteAction->addTo( toolBar );
744
745
746 connect( fileView, SIGNAL( dirChanged() ), SLOT( updateDirMenu() ) );
747 updateDirMenu();
748
749 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this );
750 connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)),
751 this, SLOT(pcmciaMessage( const QCString &, const QByteArray &)) );
752}
753
754void FileBrowser::pcmciaMessage( const QCString &msg, const QByteArray &)
755{
756 if ( msg == "mtabChanged()" ) {
757 // ## Only really needed if current dir is on a card
758 fileView->updateDir();
759 }
760}
761
762void FileBrowser::dirSelected( int id )
763{
764 int i = 0, j;
765 QString dir;
766
767 // Bulid target dir from menu
768 while( (j = dirMenu->idAt( i )) != id ){
769 dir += dirMenu->text( j ).stripWhiteSpace();
770 if( dirMenu->text( j ) != "/" ) dir += "/";
771 i++;
772 }
773 dir += dirMenu->text( dirMenu->idAt( i ) ).stripWhiteSpace();
774
775 fileView->setDir( dir );
776}
777
778void FileBrowser::updateDirMenu()
779{
780 QString spc, cd = fileView->cd();
781 QStringList l = QStringList::split( "/", cd );
782 int i = 0;
783
784 dirMenu->clear();
785 dirMenu->insertItem( tr( "/" ), this, SLOT( dirSelected(int) ) );
786
787 for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) {
788 spc.fill( ' ', i++);
789 dirMenu->insertItem( spc + (*it), this,
790 SLOT( dirSelected(int) ) );
791 }
792 dirMenu->setItemChecked( dirMenu->idAt( l.count() ), TRUE );
793
794 lastAction->setEnabled( fileView->history().count() != 0 );
795 upAction->setEnabled( cd != "/" );
796}
797
798void FileBrowser::sortName()
799{
800 fileView->setSorting( 0, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
801 fileView->sort();
802 sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE );
803 sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE );
804 sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE );
805 sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE );
806}
807
808void FileBrowser::sortSize()
809{
810 fileView->setSorting( 1, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
811 fileView->sort();
812 sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE );
813 sortMenu->setItemChecked( sortMenu->idAt( 1 ), TRUE );
814 sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE );
815 sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE );
816}
817
818void FileBrowser::sortDate()
819{
820 fileView->setSorting( 2, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
821 fileView->sort();
822 sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE );
823 sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE );
824 sortMenu->setItemChecked( sortMenu->idAt( 2 ), TRUE );
825 sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE );
826}
827
828void FileBrowser::sortType()
829{
830 fileView->setSorting( 3, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
831 fileView->sort();
832 sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE );
833 sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE );
834 sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE );
835 sortMenu->setItemChecked( sortMenu->idAt( 3 ), TRUE );
836}
837
838void FileBrowser::updateSorting()
839{
840 sortMenu->setItemChecked( sortMenu->idAt( 5 ), !sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
841
842 if ( sortMenu->isItemChecked( sortMenu->idAt( 0 ) ) )
843 sortName();
844 else if ( sortMenu->isItemChecked( sortMenu->idAt( 1 ) ) )
845 sortSize();
846 else if ( sortMenu->isItemChecked( sortMenu->idAt( 2 ) ) )
847 sortDate();
848 else
849 sortType();
850}
diff --git a/noncore/unsupported/filebrowser/filebrowser.h b/noncore/unsupported/filebrowser/filebrowser.h
new file mode 100644
index 0000000..2e9e444
--- a/dev/null
+++ b/noncore/unsupported/filebrowser/filebrowser.h
@@ -0,0 +1,141 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef FILEBROWSER_H
21#define FILEBROWSER_H
22
23#include <qlistview.h>
24#include <qmainwindow.h>
25#include <qfileinfo.h>
26#include <qaction.h>
27#include <qtimer.h>
28#include <qstringlist.h>
29
30class InlineEdit;
31
32class FileItem : public QListViewItem
33{
34public:
35 FileItem( QListView * parent, const QFileInfo & fi );
36
37 QString key( int column, bool ascending = TRUE ) const;
38 QString getFilePath(){ return fileInfo.filePath(); }
39 QString getFileName(){ return fileInfo.fileName(); }
40 bool isDir(){ return fileInfo.isDir(); }
41 bool isExecutable(){ return fileInfo.isExecutable(); }
42 bool isLib();
43 int launch();
44 bool rename( const QString & name );
45private:
46 QString sizeString( unsigned int size );
47 QFileInfo fileInfo;
48};
49
50
51class FileView : public QListView
52{
53 Q_OBJECT
54
55public:
56 FileView( const QString & dir, QWidget * parent = 0,
57 const char * name = 0 );
58 void setDir( const QString & dir );
59 QString cd(){ return currentDir; }
60 QStringList history() const { return dirHistory; }
61
62public slots:
63 void updateDir();
64 void parentDir();
65 void lastDir();
66
67 void rename();
68 void copy();
69 void paste();
70 void del();
71 void cut();
72 void newFolder();
73 void viewAsText();
74
75protected:
76 void generateDir( const QString & dir );
77 void resizeEvent( QResizeEvent* );
78 void contentsMousePressEvent( QMouseEvent * e );
79 void contentsMouseReleaseEvent( QMouseEvent * e );
80
81protected slots:
82 void itemClicked( QListViewItem * i );
83 void itemDblClicked( QListViewItem * i );
84 void showFileMenu();
85 void cancelMenuTimer();
86 void selectAll(){ QListView::selectAll( TRUE ); }
87 void deselectAll(){ QListView::selectAll( FALSE ); }
88 void addToDocuments();
89 void run();
90 void endRenaming();
91
92private:
93 QString currentDir;
94 QStringList dirHistory, flist;
95 QTimer menuTimer;
96 InlineEdit * le;
97 FileItem * itemToRename;
98 bool selected;
99
100 bool copyFile( const QString & dest, const QString & src );
101
102signals:
103 void dirChanged();
104 void textViewActivated( QWidget * w );
105 void textViewDeactivated();
106};
107
108class FileBrowser : public QMainWindow
109{
110 Q_OBJECT
111
112public:
113 FileBrowser( QWidget * parent = 0,
114 const char * name = 0, WFlags f = 0 );
115 FileBrowser( const QString & dir, QWidget * parent = 0,
116 const char * name = 0, WFlags f = 0 );
117private:
118 void init(const QString & dir);
119 QString fileToCopy;
120 QPopupMenu * dirMenu, * sortMenu;
121 FileView * fileView;
122 QAction * pasteAction;
123 QAction*lastAction;
124 QAction*upAction;
125
126 bool copyFile( const QString & dest, const QString & src );
127
128private slots:
129 void pcmciaMessage( const QCString &msg, const QByteArray &);
130
131 void sortName();
132 void sortDate();
133 void sortSize();
134 void sortType();
135 void updateSorting();
136
137 void updateDirMenu();
138 void dirSelected( int id );
139};
140
141#endif
diff --git a/noncore/unsupported/filebrowser/filebrowser.pro b/noncore/unsupported/filebrowser/filebrowser.pro
new file mode 100644
index 0000000..34df79a
--- a/dev/null
+++ b/noncore/unsupported/filebrowser/filebrowser.pro
@@ -0,0 +1,12 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 DESTDIR = $(QPEDIR)/bin
4 HEADERS = inlineedit.h \
5 filebrowser.h
6 SOURCES = filebrowser.cpp \
7 inlineedit.cpp \
8 main.cpp
9INCLUDEPATH += $(QPEDIR)/include
10 DEPENDPATH+= $(QPEDIR)/include
11LIBS += -lqpe
12 INTERFACES=
diff --git a/noncore/unsupported/filebrowser/inlineedit.cpp b/noncore/unsupported/filebrowser/inlineedit.cpp
new file mode 100644
index 0000000..47c500a
--- a/dev/null
+++ b/noncore/unsupported/filebrowser/inlineedit.cpp
@@ -0,0 +1,30 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "inlineedit.h"
21
22InlineEdit::InlineEdit( QWidget * parent, const char * name )
23 : QLineEdit( parent, name )
24{
25}
26
27void InlineEdit::focusOutEvent( QFocusEvent * )
28{
29 emit lostFocus();
30}
diff --git a/noncore/unsupported/filebrowser/inlineedit.h b/noncore/unsupported/filebrowser/inlineedit.h
new file mode 100644
index 0000000..3fbfdd6
--- a/dev/null
+++ b/noncore/unsupported/filebrowser/inlineedit.h
@@ -0,0 +1,39 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef INLINEEDIT_H
21#define INLINEEDIT_H
22
23#include <qlineedit.h>
24
25class InlineEdit : public QLineEdit
26{
27 Q_OBJECT
28
29public:
30 InlineEdit( QWidget * parent = 0, const char * name = 0 );
31
32signals:
33 void lostFocus();
34
35protected:
36 void focusOutEvent( QFocusEvent * );
37};
38
39#endif
diff --git a/noncore/unsupported/filebrowser/main.cpp b/noncore/unsupported/filebrowser/main.cpp
new file mode 100644
index 0000000..7304786
--- a/dev/null
+++ b/noncore/unsupported/filebrowser/main.cpp
@@ -0,0 +1,41 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "filebrowser.h"
22
23#include <qpe/qpeapplication.h>
24#include <qpe/mimetype.h>
25
26#include <qmainwindow.h>
27#include <qfileinfo.h>
28#include <qdir.h>
29
30int main( int argc, char ** argv )
31{
32 QPEApplication a( argc, argv );
33
34 MimeType::updateApplications();
35 FileBrowser mw( QDir::current().canonicalPath() );
36 mw.resize( 240, 320 );
37 mw.setCaption( FileBrowser::tr("File Manager") );
38 a.showMainWidget( &mw );
39
40 return a.exec();
41}
diff --git a/noncore/unsupported/filebrowser/qpe-filebrowser.control b/noncore/unsupported/filebrowser/qpe-filebrowser.control
new file mode 100644
index 0000000..c55fe6a
--- a/dev/null
+++ b/noncore/unsupported/filebrowser/qpe-filebrowser.control
@@ -0,0 +1,9 @@
1Files: bin/filebrowser apps/Applications/filebrowser.desktop
2Priority: optional
3Section: qpe/applications
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Browse the file system
9 The filebrowser for the Qtopia environment.
diff --git a/noncore/unsupported/oipkg/.cvsignore b/noncore/unsupported/oipkg/.cvsignore
new file mode 100644
index 0000000..3791def
--- a/dev/null
+++ b/noncore/unsupported/oipkg/.cvsignore
@@ -0,0 +1,10 @@
1Makefile
2moc_*
3pkfind.cpp
4pkfind.h
5pksettings.cpp
6pksettings.h
7pkdesc.cpp
8pkdesc.h
9packagemanagerbase.cpp
10packagemanagerbase.h
diff --git a/noncore/unsupported/oipkg/Makefile.in b/noncore/unsupported/oipkg/Makefile.in
new file mode 100644
index 0000000..8dd7edb
--- a/dev/null
+++ b/noncore/unsupported/oipkg/Makefile.in
@@ -0,0 +1,203 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = $(QPEDIR)/bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= qipkg
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =packagemanager.h
27 SOURCES =packagemanager.cpp \
28 main.cpp
29 OBJECTS =packagemanager.o \
30 main.o \
31 packagemanagerbase.o \
32 pkdesc.o \
33 pkfind.o \
34 pksettings.o
35INTERFACES = packagemanagerbase.ui \
36 pkdesc.ui \
37 pkfind.ui \
38 pksettings.ui
39UICDECLS = packagemanagerbase.h \
40 pkdesc.h \
41 pkfind.h \
42 pksettings.h
43UICIMPLS = packagemanagerbase.cpp \
44 pkdesc.cpp \
45 pkfind.cpp \
46 pksettings.cpp
47 SRCMOC =moc_packagemanager.cpp \
48 moc_packagemanagerbase.cpp \
49 moc_pkdesc.cpp \
50 moc_pkfind.cpp \
51 moc_pksettings.cpp
52 OBJMOC =moc_packagemanager.o \
53 moc_packagemanagerbase.o \
54 moc_pkdesc.o \
55 moc_pkfind.o \
56 moc_pksettings.o
57
58
59####### Implicit rules
60
61.SUFFIXES: .cpp .cxx .cc .C .c
62
63.cpp.o:
64 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
65
66.cxx.o:
67 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
68
69.cc.o:
70 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
71
72.C.o:
73 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
74
75.c.o:
76 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
77
78####### Build rules
79
80
81all: $(DESTDIR)$(TARGET)
82
83$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
84 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
85
86moc: $(SRCMOC)
87
88tmake:
89 tmake qipkg.pro
90
91clean:
92 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
93 -rm -f *~ core
94 -rm -f allmoc.cpp
95
96####### Extension Modules
97
98listpromodules:
99 @echo
100
101listallmodules:
102 @echo
103
104listaddonpromodules:
105 @echo
106
107listaddonentmodules:
108 @echo
109
110
111REQUIRES=
112
113####### Sub-libraries
114
115
116###### Combined headers
117
118
119
120####### Compile
121
122packagemanager.o: packagemanager.cpp \
123 packagemanager.h \
124 packagemanagerbase.h \
125 pkdesc.h \
126 pkfind.h \
127 pksettings.h \
128 $(QPEDIR)/include/qpe/process.h \
129 $(QPEDIR)/include/qpe/resource.h \
130 $(QPEDIR)/include/qpe/stringutil.h \
131 $(QPEDIR)/include/qpe/qpeapplication.h \
132 $(QPEDIR)/include/qpe/qcopenvelope_qws.h \
133 $(QPEDIR)/include/qpe/applnk.h
134
135main.o: main.cpp \
136 packagemanager.h \
137 packagemanagerbase.h \
138 $(QPEDIR)/include/qpe/qpeapplication.h
139
140packagemanagerbase.h: packagemanagerbase.ui
141 $(UIC) packagemanagerbase.ui -o $(INTERFACE_DECL_PATH)/packagemanagerbase.h
142
143packagemanagerbase.cpp: packagemanagerbase.ui
144 $(UIC) packagemanagerbase.ui -i packagemanagerbase.h -o packagemanagerbase.cpp
145
146pkdesc.h: pkdesc.ui
147 $(UIC) pkdesc.ui -o $(INTERFACE_DECL_PATH)/pkdesc.h
148
149pkdesc.cpp: pkdesc.ui
150 $(UIC) pkdesc.ui -i pkdesc.h -o pkdesc.cpp
151
152pkfind.h: pkfind.ui
153 $(UIC) pkfind.ui -o $(INTERFACE_DECL_PATH)/pkfind.h
154
155pkfind.cpp: pkfind.ui
156 $(UIC) pkfind.ui -i pkfind.h -o pkfind.cpp
157
158pksettings.h: pksettings.ui
159 $(UIC) pksettings.ui -o $(INTERFACE_DECL_PATH)/pksettings.h
160
161pksettings.cpp: pksettings.ui
162 $(UIC) pksettings.ui -i pksettings.h -o pksettings.cpp
163
164packagemanagerbase.o: packagemanagerbase.cpp
165
166pkdesc.o: pkdesc.cpp
167
168pkfind.o: pkfind.cpp
169
170pksettings.o: pksettings.cpp
171
172moc_packagemanager.o: moc_packagemanager.cpp \
173 packagemanager.h \
174 packagemanagerbase.h
175
176moc_packagemanagerbase.o: moc_packagemanagerbase.cpp \
177 packagemanagerbase.h
178
179moc_pkdesc.o: moc_pkdesc.cpp \
180 pkdesc.h
181
182moc_pkfind.o: moc_pkfind.cpp \
183 pkfind.h
184
185moc_pksettings.o: moc_pksettings.cpp \
186 pksettings.h
187
188moc_packagemanager.cpp: packagemanager.h
189 $(MOC) packagemanager.h -o moc_packagemanager.cpp
190
191moc_packagemanagerbase.cpp: packagemanagerbase.h
192 $(MOC) packagemanagerbase.h -o moc_packagemanagerbase.cpp
193
194moc_pkdesc.cpp: pkdesc.h
195 $(MOC) pkdesc.h -o moc_pkdesc.cpp
196
197moc_pkfind.cpp: pkfind.h
198 $(MOC) pkfind.h -o moc_pkfind.cpp
199
200moc_pksettings.cpp: pksettings.h
201 $(MOC) pksettings.h -o moc_pksettings.cpp
202
203
diff --git a/noncore/unsupported/oipkg/ipkg/available b/noncore/unsupported/oipkg/ipkg/available
new file mode 100644
index 0000000..a9a8ddc
--- a/dev/null
+++ b/noncore/unsupported/oipkg/ipkg/available
@@ -0,0 +1,2256 @@
1Package: ae
2Priority: optional
3Section: editors
4Installed-Size: 144
5Debian-Maintainer: Dale Scheetz (Dwarf #1) <dwarf@polaris.net>
6Maintainer: Carl Worth <cworth@handhelds.org>
7Architecture: arm
8Version: 962-30
9Depends: libc6 (>= 2.2.1-2), slang1 (>> 1.3.0-0)
10Filename: ./ae_962-30_arm.ipk
11Size: 15635
12MD5Sum: 96f0a0a9e1c3edede3fbdd605fc4a2bb
13Description: Anthony's Editor -- a tiny full-screen editor
14 ae is a tiny full-screen text editor with both modal (vi-like)
15 and modeless (emacs-like) modes, determined by an ae.rc config file.
16
17Package: apmd
18Priority: extra
19Section: admin
20Installed-Size: 284
21Debian-Maintainer: Avery Pennarun <apenwarr@debian.org>
22Maintainer: Carl Worth <cworth@handhelds.org>
23Architecture: arm
24Version: 3.0final-1
25Depends: libc6 (>= 2.1.2), xlib6g (>= 3.3-5), xlib6g (>= 3.3.6)
26Filename: ./apmd_3.0final-1_arm.ipk
27Size: 6863
28MD5Sum: 3dcb9b6ae51b923058f0a167c7dcb680
29Description: Utilities for Advanced Power Management (APM) on laptops
30 On laptop computers, the Advanced Power Management (APM) support
31 provides access to battery status information and may help you to
32 conserve battery power, depending on your laptop and the APM
33 implementation. The apmd program also lets you run arbitrary programs
34 when APM events happen (for example, you can eject PCMCIA devices when
35 you suspend, or change hard drive timeouts when you connect the battery).
36 .
37 This package contains apmd(8), a daemon for logging and acting on APM
38 events, apm(1), a client that prints /proc/apm, xapm(1x), an X11 utility
39 that displays a little graph, on_ac_power(1), a program for shell scripts
40 to determine if wall power is connected, and tailf(1) which follows the
41 growth of a log file without writing to disk.
42 .
43 The Debian default kernel does *not* contain APM support, because it causes
44 problems on some computers. So, you need to recompile your kernel
45 and enable APM support during configuration; the corresponding questions
46 are in the 'Character devices' section.
47 .
48
49Package: ash
50Essential: yes
51Priority: required
52Section: shells
53Installed-Size: 152
54Debian-Maintainer: Herbert Xu <herbert@debian.org>
55Maintainer: Carl Worth <cworth@handhelds.org>
56Architecture: arm
57Version: 0.3.7-16
58Pre-Depends: libc6 (>= 2.2.1-2)
59Filename: ./ash_0.3.7-16_arm.ipk
60Size: 51495
61MD5Sum: 1d1f163c5655cee3c62c053b818aadb2
62Description: NetBSD /bin/sh
63 "ash" is a POSIX compliant shell that is much smaller than "bash".
64 We take advantage of that by making it the shell on the installation
65 root floppy, where space is at a premium.
66 .
67 It can be usefully installed as /bin/sh (because it executes scripts
68 somewhat faster than "bash"), or as the default shell either of root
69 or of a second user with a userid of 0 (because it depends on fewer
70 libraries, and is therefore less likely to be affected by an upgrade
71 problem or a disk failure). It is also useful for checking that a
72 script uses only POSIX syntax.
73 .
74 "bash" is a better shell for most users, since it has some nice
75 features absent from "ash", and is a required part of the system.
76
77Package: bash
78Version: 2.03-6
79Section: base
80Priority: required
81Architecture: arm
82Pre-Depends: libc6 (>= 2.1.2), libncurses5
83Depends: base-files (>= 2.1.12)
84Installed-Size: 748
85Debian-Maintainer: Matthias Klose <doko@debian.org>
86Maintainer: Carl Worth <cworth@handhelds.org>
87Filename: ./bash_2.03-6_arm.ipk
88Size: 224887
89MD5Sum: 07f98861afc6d22427dd35700b342c68
90Description: The GNU Bourne Again SHell
91 Bash is an sh-compatible command language interpreter that executes
92 commands read from the standard input or from a file. Bash also
93 incorporates useful features from the Korn and C shells (ksh and csh).
94 .
95 Bash is ultimately intended to be a conformant implementation of the
96 IEEE Posix Shell and Tools specification (IEEE Working Group 1003.2).
97
98Package: blackbox
99Priority: optional
100Version: 0.1
101Architecture: arm
102Maintainer: Alexander Guy <a7r@handhelds.org>
103Depends: libc6, xlibs, libfreetype6, libstdc++2.10-glibc2.2, libxft, libxrender
104Filename: ./blackbox_0.1_arm.ipk
105Size: 145909
106MD5Sum: 02648d34fdbe00260fcb692abc9e7705
107Description: blackbox window manager
108
109Package: checkers
110Priority: optional
111Version: 0.0
112Architecture: arm
113Maintainer: Carl Worth <cworth@handhelds.org>
114Depends: libc6, xlibs, libfreetype6, libstdc++2.10-glibc2.2, libfltk1
115Filename: ./checkers_0.0_arm.ipk
116Size: 20117
117MD5Sum: 45d08b5ead7c474711e77efcce6bff12
118Description: Play checkers against the computer
119
120Package: cpu-scale-2.4.3-rmk1-np2
121Priority: standard
122Version: 2.4.3rmk1np2
123Architecture: arm
124Maintainer: Carl Worth <cworth@handhelds.org>
125Depends: modutils
126Filename: ./cpu-scale-2.4.3-rmk1-np2_2.4.3rmk1np2_arm.ipk
127Size: 4068
128MD5Sum: d1b1f8bcfa511ef0a966b8435a61d69b
129Description: support for scaling the speed of the SA-1110 processor
130 This package contains a kernel module which will allow the speed of
131 the SA-1110 processor to be adjusted via /proc/scale
132
133Package: debianutils
134Essential: yes
135Priority: required
136Section: base
137Installed-Size: 172
138Debian-Maintainer: Guy Maor <maor@debian.org>
139Maintainer: Carl Worth <cworth@handhelds.org>
140Architecture: arm
141Version: 1.15
142Replaces: miscutils, cron (<=3.0pl1-31), debian-utils, tetex-bin (<< 1.0.6-1.1)
143Pre-Depends: libc6 (>= 2.1.97)
144Conflicts: debian-utils
145Filename: ./debianutils_1.15_arm.ipk
146Size: 9430
147MD5Sum: ce83af3644fd050fcd97988dc7074184
148Description: Miscellaneous utilities specific to Debian.
149 Debianutils includes installkernel mkboot mktemp readlink run-parts savelog
150 sensible-editor sensible-pager tempfile which.
151
152Package: dev-files
153Essential: yes
154Version: 0.4
155Priority: required
156Architecture: arm
157Maintainer: Carl Worth <cworth@handhelds.org>
158Filename: ./dev-files_0.4_arm.ipk
159Size: 2880
160MD5Sum: d4848a628a22fe664f35da48a56e98f4
161Description: devices files for /dev directory
162 This package contains a collection of devices files for /dev. I'm
163 not sure who came up with the list -- I just grabbed it from
164 familiar v0.4 bleeding. Perhaps we'll want to switch to devfs in
165 the kernel and eliminate this package?
166
167Package: diff
168Priority: optional
169Section: base
170Installed-Size: 276
171Debian-Maintainer: Santiago Vila <sanvila@debian.org>
172Maintainer: Carl Worth <cworth@handhelds.org>
173Architecture: arm
174Version: 2.7-24
175Pre-Depends: libc6 (>= 2.2.1-2)
176Filename: ./diff_2.7-24_arm.ipk
177Size: 35043
178MD5Sum: b016146c47582743d57144d13d5cb14c
179Description: File comparison utilities
180 `diff' shows differences between two files, or each corresponding file
181 in two directories.
182 .
183 The set of differences produced by `diff' can be used to distribute
184 updates to text files (such as program source code) to other people.
185 This method is especially useful when the differences are small compared
186 to the complete files. Given `diff' output, the `patch' program can
187 update, or "patch", a copy of the file.
188
189Package: dosfstools
190Priority: optional
191Section: otherosfs
192Installed-Size: 126
193Debian-Maintainer: Roman Hodek <roman@hodek.net>
194Maintainer: Carl Worth <cworth@handhelds.org>
195Architecture: arm
196Version: 2.8-1
197Replaces: mkdosfs
198Depends: libc6 (>= 2.2.1-2)
199Conflicts: mkdosfs
200Filename: ./dosfstools_2.8-1_arm.ipk
201Size: 14197
202MD5Sum: 8fe452f8337b43071f1fa9558b24ac0b
203Description: Utilities to create and check MS-DOS FAT filesystems
204 Inside of this package there are two utilities to create and to
205 check MS-DOS FAT filesystems on either harddisks or floppies under
206 Linux. This version uses the enhanced boot sector/superblock
207 format of DOS 3.3+ as well as provides a default dummy boot sector
208 code.
209
210Package: e2fsprogs
211Priority: required
212Section: base
213Installed-Size: 584
214Debian-Maintainer: Yann Dirson <dirson@debian.org>
215Maintainer: Carl Worth <cworth@handhelds.org>
216Architecture: arm
217Version: 1.19-4
218Replaces: e2fslibsg, ss2g, comerr2g
219Provides: libcomerr2, libss2, libext2fs2, libe2p2, libuuid1, e2fslibsg
220Pre-Depends: libc6 (>= 2.2.1-2)
221Suggests: gpart, parted
222Conflicts: e2fslibsg, dump (<< 0.4b4-4), quota (<< 1.55-8.1)
223Filename: ./e2fsprogs_1.19-4_arm.ipk
224Size: 135371
225MD5Sum: b61f3677ee894669d066d244969da387
226Description: The EXT2 file system utilities and libraries.
227 EXT2 stands for "Extended Filesystem", version 2. It's the main
228 filesystem type used for hard disks on Debian and other Linux systems.
229 .
230 This package contains programs for creating, checking, and maintaining EXT2
231 filesystems, and the generic `fsck' wrapper.
232
233Package: familiar-base
234Essential: yes
235Priority: required
236Version: 0.10
237Architecture: arm
238Maintainer: Alexander Guy <a7r@handhelds.org>
239Depends: sysvinit (>= 2.72)
240Pre-Depends: libc6 (>= 2.1.97)
241Filename: ./familiar-base_0.10_arm.ipk
242Size: 16749
243MD5Sum: f8da9c14594bbf9fd5350b5df072cfbd
244Description: essential files for a familiar installation
245 This package is a bit of a catch-all for files that need to be
246 installed with familiar, (I made this package from everything that
247 was still left over after I split off the rest of the files from
248 familiar v0.4 bleeding into their own packages) . Much of what it is
249 here is simply emty directories that must exist. Also, there are
250 some files here which may be created by scripts in Debian that we
251 are not yet runnging. There are probably several files here that
252 should move to other packages.
253
254Package: familiar-postinst
255Priority: optional
256Version: 0.1
257Architecture: arm
258Maintainer: Alexander Guy <a7r@handhelds.org>
259Depends: wget, ntpdate
260Filename: ./familiar-postinst_0.1_arm.ipk
261Size: 1022
262MD5Sum: f246e2efdcd8c798426e394426e327c1
263Description: A collection of shell scripts to do postinstall polishing.
264 These scripts download some of Microsoft's core True-Type Fonts,
265 as well as sync the handheld's time against a public NTP server.
266
267Package: fileutils
268Essential: yes
269Priority: required
270Section: base
271Installed-Size: 1892
272Debian-Maintainer: Michael Stone <mstone@debian.org>
273Maintainer: Carl Worth <cworth@handhelds.org>
274Architecture: arm
275Version: 4.0.43-1
276Replaces: color-ls, util-linux (<= 2.7.1-1)
277Pre-Depends: libc6 (>= 2.2.1-2)
278Conflicts: color-ls
279Filename: ./fileutils_4.0.43-1_arm.ipk
280Size: 244849
281MD5Sum: 96584322c797c44b0dc2171973b406c3
282Description: GNU file management utilities.
283 The utilities: chgrp chmod chown cp dd df dir dircolors du install ln
284 ls mkdir mkfifo mknod mv rm rmdir shred touch vdir sync.
285
286Package: fscrib
287Priority: optional
288Version: 0.0
289Architecture: arm
290Maintainer: Carl Worth <cworth@handhelds.org>
291Depends: libc6, xlibs, libxaw7
292Filename: ./fscrib_0.0_arm.ipk
293Size: 120261
294MD5Sum: 916dd41f2ed4b0fe3b4ea08d3a80633e
295Description: Full-screen character recognition
296
297Package: fstroke
298Priority: optional
299Version: 0.2-fam1
300Architecture: arm
301Maintainer: Carl Worth <cworth@handhelds.org>
302Depends: libc6, xlibs, libxaw7
303Filename: ./fstroke_0.2-fam1_arm.ipk
304Size: 16248
305MD5Sum: f4fba9d28f724936cca622f374ce9347
306Description: Full-screen modeless character recognizer
307
308Package: ftp
309Version: 0.10-3.1
310Section: net
311Priority: standard
312Architecture: arm
313Depends: libc6 (>= 2.1.2), libncurses5, libreadline4 (>= 4.1)
314Replaces: netstd
315Installed-Size: 156
316Debian-Maintainer: Herbert Xu <herbert@debian.org>
317Maintainer: Carl Worth <cworth@handhelds.org>
318Filename: ./ftp_0.10-3.1_arm.ipk
319Size: 33962
320MD5Sum: d8c10c5d6d03be0b84964c885927e077
321Description: The FTP client.
322 ftp is the user interface to the ARPANET standard File Transfer Protocol.
323 The program allows a user to transfer files to and from a remote network
324 site.
325Source: netkit-ftp
326
327Package: gdk-imlib1
328Priority: optional
329Section: libs
330Installed-Size: 372
331Debian-Maintainer: Ossama Othman <ossama@debian.org>
332Maintainer: Carl Worth <cworth@handhelds.org>
333Architecture: arm
334Source: imlib
335Version: 1.9.8.1-2
336Replaces: gdk-imlib-nonfree1, libgdk-imlib-nonfree1, libgdk-imlib1
337Provides: gdk-imlib, libgdk-imlib1
338Depends: imlib-base (>= 1.9.8.1-2), libc6 (>= 2.1.97), libglib1.2 (>= 1.2.0), libjpeg62, libpng2, libtiff3g, libungif3g (>= 3.0-2) | giflib3g (>= 3.0-5.2), zlib1g (>= 1:1.1.3)
339Suggests: imlib-progs, imagemagick, netpbm, libjpeg-progs
340Conflicts: gdk-imlib-nonfree1, libgdk-imlib-nonfree1, libgdk-imlib1
341Filename: ./gdk-imlib1_1.9.8.1-2_arm.ipk
342Size: 62912
343MD5Sum: 38e2feac77d8a95288de100ed3109454
344Description: Gdk-Imlib is an imaging library for use with gtk
345 Gdk-Imlib is a low-level gdk interface for gtk programmers. It allows easier
346 access to many graphics formats and can write to them as well.
347
348Package: grep
349Essential: yes
350Priority: required
351Section: base
352Installed-Size: 488
353Debian-Maintainer: Wichert Akkerman <wakkerma@debian.org>
354Maintainer: Carl Worth <cworth@handhelds.org>
355Architecture: arm
356Version: 2.4.2-1
357Provides: rgrep
358Pre-Depends: libc6 (>= 2.1.2)
359Conflicts: rgrep
360Filename: ./grep_2.4.2-1_arm.ipk
361Size: 119438
362MD5Sum: 67fa4cb756f951fda7b7a5d4da2ab523
363Description: GNU grep, egrep and fgrep.
364 The GNU family of grep utilities may be the "fastest grep in the west".
365 GNU grep is based on a fast lazy-state deterministic matcher (about
366 twice as fast as stock Unix egrep) hybridized with a Boyer-Moore-Gosper
367 search for a fixed string that eliminates impossible text from being
368 considered by the full regexp matcher without necessarily having to
369 look at every character. The result is typically many times faster
370 than Unix grep or egrep. (Regular expressions containing backreferencing
371 will run more slowly, however.)
372
373Package: gzip
374Essential: yes
375Priority: required
376Section: base
377Installed-Size: 130
378Debian-Maintainer: Bdale Garbee <bdale@gag.com>
379Maintainer: Carl Worth <cworth@handhelds.org>
380Architecture: arm
381Version: 1.2.4-33
382Depends: debianutils (>= 1.6)
383Pre-Depends: libc6 (>= 2.1)
384Filename: ./gzip_1.2.4-33_arm.ipk
385Size: 30103
386MD5Sum: e98844d058d1909781782abea0182887
387Description: The GNU compression utility.
388 This is the standard GNU file compression utility, which is also the default
389 compression tool for Debian. It typically operates on files with names
390 ending in '.gz'.
391 .
392 This package can also decompress '.Z' files created with 'compress'.
393
394Package: h3600-utils
395Priority: standard
396Version: 0.4
397Architecture: arm
398Maintainer: Carl Worth <cworth@handhelds.org>
399Depends: libc6
400Filename: ./h3600-utils_0.4_arm.ipk
401Size: 2736
402MD5Sum: 5071017b84fb30c7ae33e3da97dfad80
403Description: utilities for controlling hardware on Compaq iPAQ H3600 series computers
404 This package contains programs for controlling the backlight (sic)
405 as well as the leds on the Compaq iPAQ H3600 series of handheld
406 computers.
407
408Package: hostname
409Essential: yes
410Priority: required
411Section: base
412Installed-Size: 37
413Debian-Maintainer: Adam Heath <doogie@debian.org>
414Maintainer: Carl Worth <cworth@handhelds.org>
415Architecture: arm
416Version: 2.07
417Pre-Depends: libc6 (>= 2.1)
418Filename: ./hostname_2.07_arm.ipk
419Size: 5277
420MD5Sum: 2e3ed84ee965ed6bb7619b443b228d63
421Description: A utility to set/show the host name or domain name
422 The hostname command can be used to either set or display
423 the current host or domain name of the system. This name is
424 used by many of the networking programs to identify the machine.
425 The domain name is also used by NIS/YP.
426
427Package: ifupdown
428Priority: important
429Section: base
430Installed-Size: 168
431Debian-Maintainer: Anthony Towns <ajt@debian.org>
432Maintainer: Carl Worth <cworth@handhelds.org>
433Architecture: arm
434Version: 0.6.4-3
435Replaces: netbase (<< 4.00)
436Depends: net-tools, libc6 (>= 2.1.2)
437Suggests: iproute
438Filename: ./ifupdown_0.6.4-3_arm.ipk
439Size: 11654
440MD5Sum: 7d60dcafa9a3526aca1fa566024e6e42
441Description: High level tools to configure network interfaces
442 This package provides the tools ifup and ifdown which may be used to
443 configure (or, respectively, deconfigure) network interfaces, based on
444 the file /etc/network/interfaces.
445
446Package: intimateboot
447Priority: optional
448Section: extras
449Installed-Size: 40960
450Debian-Maintainer: Nicolás Lichtmaier <nick@debian.org>
451Maintainer: James Conner <jim@secret.org.uk>
452Architecture: arm
453Version: 050301
454Depends: reiserfs-module (= 2.4.1-rmk1-np1 )
455Filename: ./intimateboot_050301_arm.ipk
456Size: 2518
457MD5Sum: 92532bfa8875aae0746d6901192b3cd2
458Description: This package provides the necessary boot scripts to optionally make the intimate distribution boot up. If a valid boot image for intimate is not found, then the system will boot Familiar from flash as normal. The package provides an additional linuxrc script, which may be run as an alternative to the normal one. It also provides devfs support via a small script. Booting via microdrive or NFS is supported, but you must preconfigure NFS paths etc before starting. IMPORTANT : You will need to change the linuxargs in the bootloader after installing this package. This is done by entering... 'set linuxargs "noinited devfs=mount root=/dev/mtdblock3 init=/linuxrc.intimate console=ttySA0"' and 'params save' at the boot> prompt.
459
460
461Package: ion-nasty-hacks
462Priority: optional
463Version: 200102160-fam1
464Architecture: arm
465Maintainer: Carl Worth <cworth@handhelds.org>
466Depends: libc6, xlibs
467Filename: ./ion-nasty-hacks_200102160-fam1_arm.ipk
468Size: 58518
469MD5Sum: 79a39fcb686adf83942ad50ad32845f4
470Description: a text-editorish, keyboard/stylus friendly window manager
471
472Package: ipkg
473Essential: yes
474Priority: required
475Version: 0.4-fam1
476Architecture: all
477Maintainer: Carl Worth <cworth@handhelds.org>
478Depends: shellutils, textutils, sed, grep, gzip, tar, wget
479Filename: ./ipkg_0.4-fam1_all.ipk
480Size: 5306
481MD5Sum: 6502942cc864d29cf005925a168747cd
482Description: Lightweight package management system
483
484Package: irda-common
485Version: 0.9.14-3
486Section: misc
487Priority: optional
488Architecture: arm
489Depends: libc6 (>= 2.2.1-2)
490Conflicts: irda-utils
491Replaces: irda-utils
492Installed-Size: 100
493Debian-Maintainer: NOKUBI Takatsugu <knok@daionet.gr.jp>
494Maintainer: Alexander Guy <a7r@andern.org>
495Source: irda-utils
496Filename: ./irda-common_0.9.14-3_arm.ipk
497Size: 5259
498MD5Sum: d41a70d88dbf47b63bf601cbe176b121
499Description: IrDA management utilities
500 IrDA management utilities for Linux.
501 This package contains irmanager and irattach.
502
503Package: irda-modules-2.4.3-rmk2-np1
504Priority: extra
505Maintainer: Alexander Guy <a7r@andern.org>
506Depends: kernel-modules-2.4.3-rmk2-np1
507Version: fam3
508Architecture: arm
509Filename: ./irda-modules-2.4.3-rmk2-np1_fam3_arm.ipk
510Size: 194859
511MD5Sum: 7af6f1d272eb0cb135162fb9f9bb2c76
512Description: IrDA kernel modules
513 The entire suite of kernel modules required to use both SIR and FIR
514 IrDA. This includes IrCOMM, and IrLAN support.
515
516Package: iv
517Essential: yes
518Priority: required
519Version: 0.0
520Architecture: arm
521Maintainer: Carl Worth <cworth@handhelds.org>
522Provides: vi
523Depends: libc6
524Filename: ./iv_0.0_arm.ipk
525Size: 8364
526MD5Sum: 9cf155930e6db23ddece8705df27d99d
527Description: Lightweight reimplementation of vi <attribution?>
528
529Package: kernel-modules-2.4.3-rmk2-np1
530Essential: yes
531Priority: required
532Version: fam3
533Architecture: arm
534Maintainer: Alexander Guy <a7r@andern.org>
535Depends: modutils
536Filename: ./kernel-modules-2.4.3-rmk2-np1_fam3_arm.ipk
537Size: 585458
538MD5Sum: 2cd52706ce0157337664414bc6e75943
539Description: kernel modules for kernel 2.4.3-rmk2-np1
540 This package contains almost all of the kernel modules that might be
541 useful within familiar. Eventually I would like to split many of
542 these modules off into their own packages that would have dependency
543 links from the programs that need them. For example, e2fsprogs could
544 depend on e2fs-kernel-modules or something like that. I have already
545 split off cpu-scale and the pcmcia modules into their own packages.
546
547Package: less
548Version: 346-7
549Section: text
550Priority: standard
551Architecture: arm
552Depends: libc6 (>= 2.1.2), libncurses5, debianutils (>= 1.8)
553Installed-Size: 163
554Debian-Maintainer: Thomas Schoepf <schoepf@debian.org>
555Maintainer: Carl Worth <cworth@handhelds.org>
556Filename: ./less_346-7_arm.ipk
557Size: 41734
558MD5Sum: 617280f25bba9c4b03e631af7cd969b2
559Description: A file pager program, similar to more(1)
560 Less is a program similar to more (1), but which allows backward
561 movement in the file as well as forward movement. Also, less does not
562 have to read the entire input file before starting, so with large input
563 files it starts up faster than text editors like vi (1). Less uses
564 termcap (or terminfo on some systems), so it can run on a variety of
565 terminals. There is even limited support for hardcopy terminals.
566 .
567 Homepage: http://www.flash.net/~marknu/less/
568
569Package: libc6
570Priority: required
571Section: base
572Installed-Size: 13104
573Debian-Maintainer: Ben Collins <bcollins@debian.org>
574Maintainer: Carl Worth <cworth@handhelds.org>
575Architecture: arm
576Source: glibc
577Version: 2.2.2-1
578Replaces: ldso (<= 1.9.11-9), timezone, timezones, gconv-modules, libtricks
579Provides: gconv-modules, glibc2.2
580Suggests: locales, glibc-doc
581Conflicts: libdb2 (= 2:2.7.7-2.1), timezone, timezones, gconv-modules, libtricks, libc6-doc
582Filename: ./libc6_2.2.2-1_arm.ipk
583Size: 1100492
584MD5Sum: 4944634b673b732d4a9fc8ec87a1447c
585Description: GNU C Library: Shared libraries and Timezone data
586 Contains the standard libraries that are used by nearly all programs on
587 the system. This package includes shared versions of the standard C library
588 and the standard math library, as well as many others.
589 Timezone data is also included.
590
591Package: libdb2
592Priority: optional
593Section: libs
594Installed-Size: 388
595Debian-Maintainer: Ben Collins <bcollins@debian.org>
596Maintainer: Carl Worth <cworth@handhelds.org>
597Source: db
598Version: 2:2.7.7-3
599Architecture: arm
600Replaces: libdb2.6, lib-bdb2
601Depends: libc6 (>= 2.2.1-2)
602Conflicts: lib-bdb2
603Filename: ./libdb2_2.7.7-3_arm.ipk
604Size: 138089
605MD5Sum: ed771a8cdf8225b98db3c61b39a05d07
606Description: The Berkeley database routines (run-time files).
607 libdb2 is a library for manipulating database files, developed at
608 Berkeley and extended by Sleepycat Software Inc.
609 This is the stable version, also commercially supported.
610 .
611 It supports three kinds of file formats:
612 * btree. A representation of a sorted, balanced tree structure.
613 * hashed. An extensible, dynamic hashing scheme.
614 * UNIX file oriented. A byte stream file with fixed or variable
615 length records.
616 Other core database services:
617 * page cache management for fast access, clean page allocation.
618 * lock with multiple reader/writer granularity.
619 * nested transaction support with logging and rollback recovery
620 (two phase commit).
621 * Large set of utility, to dump/load/restore data and examine log.
622
623Package: libfltk1
624Priority: optional
625Section: libs
626Installed-Size: 370
627Debian-Maintainer: Fabrizio Polacco <fpolacco@debian.org>
628Maintainer: Carl Worth <cworth@handhelds.org>
629Architecture: arm
630Source: fltk
631Version: 1.0.9-1.1
632Depends: libc6 (>= 2.2.1-2), libgl1, libstdc++2.10-glibc2.2, xlibs (>= 4.0.1-11)
633Filename: ./libfltk1_1.0.9-1.1_arm.ipk
634Size: 186802
635MD5Sum: 59c552236fc0e89fd4fb7474d6fbfe0a
636Description: The Fast Light Toolkit, a GUI toolkit inspired by libForms
637 This is a very nice LGPL'd graphic user interface toolkit originally based on
638 libForms. Programs written using libForms will hopefully be ported to libfltk
639 in the future and will need this package to run.
640
641Package: libfreetype6
642Priority: optional
643Section: libs
644Installed-Size: 396
645Debian-Maintainer: Anthony Fok <foka@debian.org>
646Maintainer: Carl Worth <cworth@handhelds.org>
647Architecture: arm
648Source: freetype
649Version: 2.0.1.20010317-1
650Replaces: freetype0, freetype1
651Depends: libc6 (>= 2.2.1-2)
652Suggests: libfreetype6-dev
653Conflicts: freetype
654Filename: ./libfreetype6_2.0.1.20010317-1_arm.ipk
655Size: 106977
656MD5Sum: 639030e1e406cc87c44db49a70de9f34
657Description: FreeType 2 font engine, shared library files.
658 The FreeType project is a team of volunteers who develop free,
659 portable and high-quality software solutions for digital typography.
660 They specifically target embedded systems and focus on bringing small,
661 efficient and ubiquitous products.
662 .
663 The FreeType 2 library is their new software font engine. It has been
664 designed to provide the following important features:
665 * A universal and simple API to manage font files
666 * Support for several font formats through loadable modules
667 * High-quality anti-aliasing
668 * High portability & performance
669 .
670 Supported font formats include:
671 * TrueType files (.ttf) and collections (.ttc)
672 * Type 1 font files both in ASCII (.pfa) or binary (.pfb) format
673 * Type 1 Multiple Master fonts. The FreeType 2 API also provides
674 routines to manage design instances easily
675 * Type 1 CID-keyed fonts
676 * OpenType/CFF (.otf) fonts
677 * CFF/Type 2 fonts
678 * Adobe CEF fonts (.cef), used to embed fonts in SVG documents with
679 the Adobe SVG viewer plugin.
680 * Windows FNT/FON bitmap fonts
681 .
682 This package contains the files needed to run programs that use the
683 FreeType 2 library.
684 .
685 Home Page: http://www.freetype.org/
686 Authors: David Turner <david.turner@freetype.org>
687 Robert Wilhelm <robert.wilhelm@freetype.org>
688 Werner Lemberg <werner.lemberg@freetype.org>
689
690Package: libglade0
691Priority: optional
692Section: libs
693Installed-Size: 164
694Debian-Maintainer: Paolo Molaro <lupus@debian.org>
695Maintainer: Carl Worth <cworth@handhelds.org>
696Architecture: arm
697Source: libglade
698Version: 0.16-2
699Depends: libc6 (>= 2.2.1-2), libglib1.2 (>= 1.2.0), libgtk1.2 (>= 1.2.8-3), libxml1, xlibs (>= 4.0.1-11), zlib1g (>= 1:1.1.3)
700Filename: ./libglade0_0.16-2_arm.ipk
701Size: 35028
702MD5Sum: 26211c69d51e1f8abd45022eaadb25b1
703Description: Library to load .glade files at runtime.
704 This library allows you to load user interfaces in your program, which are
705 stored externally. This allows alteration of the interface without
706 recompilation of the program.
707 .
708 The interfaces can also be edited with GLADE.
709
710Package: libglib1.2
711Priority: optional
712Section: libs
713Installed-Size: 264
714Debian-Maintainer: Ben Gertzfield <che@debian.org>
715Maintainer: Carl Worth <cworth@handhelds.org>
716Architecture: arm
717Source: glib1.2
718Version: 1.2.10-1
719Replaces: libgtk-doc
720Depends: libc6 (>= 2.2.1-2)
721Suggests: libgtk1.2
722Filename: ./libglib1.2_1.2.10-1_arm.ipk
723Size: 68147
724MD5Sum: 1fe1ad635bc78331c9e3ae27406ddc12
725Description: The GLib library of C routines
726 GLib is a library containing many useful C routines for things such
727 as trees, hashes, and lists. GLib was previously distributed with
728 the GTK+ toolkit, but has been split off as of the developers' version
729 1.1.0.
730 .
731 You do not need to install this package if you have libgtk1 (note 1,
732 not 1.1 or 1.2) installed. libgtk1 included libglib in it. libgtk1.1
733 and libgtk1.2, however, do need libglib1.1 to be installed separately.
734
735Package: libgtk1.2
736Priority: optional
737Section: libs
738Installed-Size: 2184
739Debian-Maintainer: Ben Gertzfield <che@debian.org>
740Maintainer: Carl Worth <cworth@handhelds.org>
741Architecture: arm
742Source: gtk+1.2
743Version: 1.2.10-1
744Replaces: libgtk1.1.5, libgtk1.1.6, libgtk1.1.9, libgtk1.1.11, libgtk1.1.12, libgtk1.1.13, libgtk1.1.14, libgtk1.1.15, libgtk1.1.16
745Depends: libc6 (>= 2.2.1-2), libglib1.2 (>= 1.2.0), xlibs (>= 4.0.1-11)
746Pre-Depends: dpkg (>= 1.6.8)
747Conflicts: libgtk-dev (<< 1:1.0.2)
748Filename: ./libgtk1.2_1.2.10-1_arm.ipk
749Size: 602094
750MD5Sum: b0ff676813a80f1017876b125bb9bad0
751Description: The GIMP Toolkit set of widgets for X
752 The GIMP Toolkit is a freely available set of widgets for X.
753 GTK is easy to use, and has been implemented in such projects as
754 The GNU Image Manipulation Program (The GIMP), GNOME, a GNU
755 desktop set of utilities for X, and gzilla, a GNU web-browser.
756
757Package: libjpeg62
758Priority: optional
759Section: libs
760Installed-Size: 204
761Debian-Maintainer: Mark Mickan <mmickan@debian.org>
762Maintainer: Carl Worth <cworth@handhelds.org>
763Architecture: arm
764Source: libjpeg6b
765Version: 6b-1.3
766Replaces: libjpeg6b
767Provides: libjpeg6b
768Depends: libc6 (>= 2.2.1-2)
769Conflicts: libjpeg6b
770Filename: ./libjpeg62_6b-1.3_arm.ipk
771Size: 64434
772MD5Sum: 2cabfc091e7755c93a3d78b2dff48f0f
773Description: The Independent JPEG Group's JPEG runtime library [libc6]
774 This package contains the shared library.
775
776Package: libncurses5
777Version: 5.0-6.0potato1
778Section: base
779Priority: required
780Architecture: arm
781Depends: libc6 (>= 2.1.2), ncurses-base
782Installed-Size: 427
783Debian-Maintainer: Joel Klecker <ncurses-maint@debian.org>
784Maintainer: Carl Worth <cworth@handhelds.org>
785Filename: ./libncurses5_5.0-6.0potato1_arm.ipk
786Size: 101390
787MD5Sum: 6f1a19d05c5f8d312efb33e05318d714
788Description: Shared libraries for terminal handling
789 This package contains the shared libraries necessary to run programs
790 compiled with ncurses.
791Source: ncurses
792
793Package: libpam0g
794Priority: required
795Section: base
796Installed-Size: 152
797Debian-Maintainer: Sam Hartman <hartmans@debian.org>
798Maintainer: Carl Worth <cworth@handhelds.org>
799Architecture: arm
800Source: pam
801Version: 0.72-21
802Replaces: libpam0g-util
803Depends: libc6 (>= 2.2.1-2), libpam-runtime
804Suggests: libpam-doc
805Conflicts: libpam0 (<= 0.56-2), libpam
806Filename: ./libpam0g_0.72-21_arm.ipk
807Size: 18191
808MD5Sum: 21196b782a3327aa39382825db2d64f1
809Description: Pluggable Authentication Modules library
810 Contains the C shared library for Linux-PAM, a suite of shared
811 libraries that enable the local system administrator to choose how
812 applications authenticate users. In other words, without rewriting
813 or recompiling a PAM-aware application, it is possible to switch
814 between the authentication mechanism(s) it uses. One may entirely
815 upgrade the local authentication system without touching the
816 applications themselves.
817
818Package: libpam-modules
819Priority: required
820Section: base
821Installed-Size: 472
822Debian-Maintainer: Sam Hartman <hartmans@debian.org>
823Maintainer: Carl Worth <cworth@handhelds.org>
824Architecture: arm
825Source: pam
826Version: 0.72-21
827Replaces: libpam0g-util
828Provides: libpam-motd, libpam-mkhomedir
829Depends: libc6 (>= 2.2.1-2), libcap1, libdb3 (>= 3.2.9-1), libpam0g (>= 0.72-1)
830Conflicts: libpam0g-modules (= 0.66-1), libpam-motd, libpam-mkhomedir, suidmanager (<< 0.50)
831Filename: ./libpam-modules_0.72-21_arm.ipk
832Size: 20438
833MD5Sum: 23a98606804b0600dcc81ff26ad5772f
834Description: Pluggable Authentication Modules for PAM
835 This package completes the set of modules for PAM. It includes the
836 the pam_unix_*.so module as well as some specialty modules.
837
838Package: libpam-runtime
839Priority: required
840Section: base
841Installed-Size: 132
842Debian-Maintainer: Sam Hartman <hartmans@debian.org>
843Maintainer: Carl Worth <cworth@handhelds.org>
844Architecture: arm
845Source: pam
846Version: 0.72-21
847Replaces: libpam0g-util, libpam0g-dev
848Conflicts: libpam0g-util, libpam0g (<< 0.66-0)
849Filename: ./libpam-runtime_0.72-21_arm.ipk
850Size: 2495
851MD5Sum: 183d85691a48163576f7b62e8cc43184
852Description: Runtime support for the PAM library
853 Contains the base setup for libpam
854
855Package: libpng2
856Priority: standard
857Section: libs
858Installed-Size: 288
859Debian-Maintainer: Philippe Troin <phil@fifi.org>
860Maintainer: Carl Worth <cworth@handhelds.org>
861Architecture: arm
862Source: libpng
863Version: 1.0.8-1
864Depends: libc6 (>= 2.1.2), libz1
865Filename: ./libpng2_1.0.8-1_arm.ipk
866Size: 74734
867MD5Sum: ef8044db7824d9e486c6d9fb1c677168
868Description: PNG library - runtime
869 libpng is a library implementing an interface for reading and writing
870 PNG (Portable Network Graphics) format files.
871 .
872 This library is more recent than libpng0g, and you should use it rather
873 than libpng0g (which is for legacy packages).
874
875Package: libpopt0
876Priority: important
877Section: base
878Installed-Size: 92
879Debian-Maintainer: Joseph Carter <knghtbrd@debian.org>
880Maintainer: Carl Worth <cworth@handhelds.org>
881Architecture: arm
882Source: popt
883Version: 1.5-0.1
884Replaces: popt
885Depends: libc6 (>= 2.1.2)
886Conflicts: popt, libpopt-dev (<= 1.4-1)
887Filename: ./libpopt0_1.5-0.1_arm.ipk
888Size: 11129
889MD5Sum: 9a43286e1b181448f36a1939d4cea530
890Description: lib for parsing cmdline parameters
891 Popt was heavily influenced by the getopt() and getopt_long() functions,
892 but it allows more powerful argument expansion. It can parse arbitrary
893 argv[] style arrays and automatically set variables based on command
894 line arguments. It also allows command line arguments to be aliased via
895 configuration files and includes utility functions for parsing arbitrary
896 strings into argv[] arrays using shell-like rules.
897 .
898 This package contains the runtime library and locale data.
899
900Package: libreadline4
901Version: 4.1-1
902Section: base
903Priority: required
904Architecture: arm
905Depends: libc6 (>= 2.1.2), libncurses5
906Installed-Size: 260
907Debian-Maintainer: Matthias Klose <doko@debian.org>
908Maintainer: Carl Worth <cworth@handhelds.org>
909Filename: ./libreadline4_4.1-1_arm.ipk
910Size: 67959
911MD5Sum: bb6ad084c0b2b9b6251f43d5ddd2e28e
912Description: GNU readline and history libraries, run-time libraries.
913 The GNU readline library aids in the consistency of user interface
914 across discrete programs that need to provide a command line
915 interface.
916 .
917 The GNU history library provides a consistent user interface for
918 recalling lines of previously typed input.
919Source: readline4
920
921Package: libssl0.9.6
922Priority: optional
923Section: non-us/main
924Installed-Size: 1062
925Debian-Maintainer: Christoph Martin <christoph.martin@uni-mainz.de>
926Maintainer: Carl Worth <cworth@handhelds.org>
927Architecture: arm
928Source: openssl
929Version: 0.9.6a-1
930Replaces: libssl, libssl096
931Provides: libssl096
932Depends: libc6 (>= 2.2.1-2), libssl0.9.6
933Conflicts: ssleay (<< 0.9.2b), libssl, openssl (<< 0.9.6-2), libssl096, libssl096-dev (<< 0.9.6-2)
934Filename: ./libssl0.9.6_0.9.6a-1_arm.ipk
935Size: 309622
936MD5Sum: d1d6d8f48a48eb86f22e89f1a7f8dc06
937Description: SSL shared libraries
938 libssl and libcrypto shared libraries needed by programs like
939 apache-ssl, telnet-ssl and openssh.
940 .
941 It is part of the OpenSSL implementation of SSL.
942
943Package: libstdc++2.10-glibc2.2
944Priority: required
945Section: base
946Installed-Size: 328
947Debian-Maintainer: Debian GCC maintainers <gcc@packages.debian.org>
948Maintainer: Carl Worth <cworth@handhelds.org>
949Architecture: arm
950Source: gcc-2.95 (2.95.4.ds1-0.010407)
951Version: 1:2.95.4-0.010407
952Depends: libc6 (>= 2.2.1-2)
953Filename: ./libstdc++2.10-glibc2.2_2.95.4-0.010407_arm.ipk
954Size: 161222
955MD5Sum: 3d5c530f551cb14aaaccfcb2c221741f
956Description: The GNU stdc++ library
957 NOTE: This is not a final release, but taken from the CVS gcc-2_95-branch
958 (dated 20010407).
959 .
960 This package contains an additional runtime library for C++ programs
961 built with the GNU compiler.
962
963Package: libungif3g
964Priority: optional
965Section: graphics
966Installed-Size: 88
967Debian-Maintainer: Adam Heath <doogie@debian.org>
968Maintainer: Carl Worth <cworth@handhelds.org>
969Architecture: arm
970Source: libungif
971Version: 3.0-3
972Replaces: giflib3g
973Provides: giflib3g
974Depends: libc6 (>= 2.1.2), xlib6g (>= 3.3.6)
975Conflicts: libgif3g, libgif2, giflib3g
976Filename: ./libungif3g_3.0-3_arm.ipk
977Size: 16148
978MD5Sum: 65985228c87656161d3bdcfb1771185e
979Description: shared library for GIF images (runtime lib)
980 This is a shared library for working with GIF images.
981 .
982 The libungif library is a specially modified version of giflib which
983 is free of the Unisys LZW patent. It can read all GIFs, but only
984 write uncompressed GIFs. If you need to be able to write compressed
985 GIFs, you can install the non-free giflib packages instead (which may
986 not be available on CD).
987
988Package: libwrap0
989Priority: important
990Section: base
991Installed-Size: 136
992Debian-Maintainer: Anthony Towns <ajt@debian.org>
993Maintainer: Carl Worth <cworth@handhelds.org>
994Architecture: arm
995Source: tcp-wrappers
996Version: 7.6-7
997Depends: libc6 (>= 2.1.2)
998Recommends: tcpd
999Conflicts: netbase (<< 3.16-1)
1000Filename: ./libwrap0_7.6-7_arm.ipk
1001Size: 13202
1002MD5Sum: 18fd9d5e2f2e30652ee460aa1e97a5b1
1003Description: Wietse Venema's TCP wrappers library
1004 Wietse Venema's network logger, also known as TCPD or LOG_TCP.
1005 .
1006 These programs log the client host name of incoming telnet,
1007 ftp, rsh, rlogin, finger etc. requests. Security options are:
1008 access control per host, domain and/or service; detection of
1009 host name spoofing or host address spoofing; booby traps to
1010 implement an early-warning system.
1011
1012Package: libxaw6
1013Priority: optional
1014Section: libs
1015Installed-Size: 372
1016Debian-Maintainer: Branden Robinson <branden@debian.org>
1017Maintainer: Carl Worth <cworth@handhelds.org>
1018Architecture: arm
1019Source: xfree86
1020Version: 4.0.2-13
1021Replaces: xlib6g (<< 4.0)
1022Depends: libc6 (>= 2.2.1-2), xlibs (>= 4.0.1-11)
1023Conflicts: xlib6g (<< 4.0)
1024Filename: ./libxaw6_4.0.2-13_arm.ipk
1025Size: 125255
1026MD5Sum: e5b9dbfc091f69133156ae0c53e80f43
1027Description: X Athena widget set library (version 6)
1028 Xaw is a widget set based on the the Xt (X Toolkit Intrinsics) library.
1029 It provides a set of graphical user-interface elements ("widgets") such as
1030 menus, scrollbars, dialog boxes, text-input areas, and so forth. The X
1031 clients distributed with the X Window System itself, as well as many
1032 others, use the Athena widget set.
1033 .
1034 The version of the Athena widgets in this package corresponds to the
1035 X11R6.4 release of the X Window System. XFree86 has made significant
1036 enhancements to the Athena widget set; their version can be found in the
1037 libxaw7 package.
1038
1039Package: libxaw7
1040Priority: optional
1041Section: libs
1042Installed-Size: 484
1043Debian-Maintainer: Branden Robinson <branden@debian.org>
1044Maintainer: Carl Worth <cworth@handhelds.org>
1045Architecture: arm
1046Source: xfree86
1047Version: 4.0.2-13
1048Depends: libc6 (>= 2.2.1-2), xlibs (>= 4.0.1-11)
1049Filename: ./libxaw7_4.0.2-13_arm.ipk
1050Size: 176321
1051MD5Sum: 19b82bde7d895cf3227e5e5aa20c4222
1052Description: X Athena widget set library
1053 Xaw is a widget set based on the the Xt (X Toolkit Intrinsics) library.
1054 It provides a set of graphical user-interface elements ("widgets") such as
1055 menus, scrollbars, dialog boxes, text-input areas, and so forth. The X
1056 clients distributed with the X Window System itself, as well as many
1057 others, use the Athena widget set.
1058 .
1059 XFree86 has made a number of major improvements to the Athena widget set,
1060 resulting in version 7 -- this version features widgets customizable in
1061 appearance and event handling (a.k.a. "themes"); an extensible image
1062 loader (currently supports bitmaps, gradients, and pixmaps); numerous
1063 enhancements to the Text widget, text source and text sink objects; and
1064 multiple-column support in the SimpleMenu widget.
1065 .
1066 The older Athena widget library corresponding to version X11R6.4 of the X
1067 Window System can be found in the libxaw6 package.
1068
1069Package: libxft
1070Priority: optional
1071Version: 0.0
1072Architecture: arm
1073Maintainer: Carl Worth <cworth@handhelds.org>
1074Depends: libc6
1075Filename: ./libxft_0.0_arm.ipk
1076Size: 44433
1077MD5Sum: 5c9660cd2b8f1317a6ce677b094708ff
1078Description: libxft <needs better description here>
1079
1080Package: libxml1
1081Priority: optional
1082Section: libs
1083Installed-Size: 480
1084Debian-Maintainer: Fredrik Hallenberg <hallon@debian.org>
1085Maintainer: Carl Worth <cworth@handhelds.org>
1086Architecture: arm
1087Source: libxml
1088Version: 1:1.8.11-1
1089Replaces: libxml0
1090Provides: libxml0
1091Depends: libc6 (>= 2.1.97), zlib1g (>= 1:1.1.3)
1092Conflicts: libxml0
1093Filename: ./libxml1_1.8.11-1_arm.ipk
1094Size: 122515
1095MD5Sum: ffc5f30c0e229aec973ba2dedf8bf38a
1096Description: GNOME XML library
1097 XML is a metalanguage to let you design your own markup language.
1098 A regular markup language defines a way to describe information in
1099 a certain class of documents (eg HTML). XML lets you define your
1100 own customized markup languages for many classes of document. It
1101 can do this because it's written in SGML, the international standard
1102 metalanguage for markup languages.
1103
1104Package: libxmltok1
1105Priority: optional
1106Section: libs
1107Installed-Size: 176
1108Debian-Maintainer: Ardo van Rangelrooij <ardo@debian.org>
1109Maintainer: Carl Worth <cworth@handhelds.org>
1110Architecture: arm
1111Source: libxmltok
1112Version: 1.1-5
1113Depends: libc6 (>= 2.1.97)
1114Filename: ./libxmltok1_1.1-5_arm.ipk
1115Size: 36765
1116MD5Sum: 2669363932f3538598690504e8bd843b
1117Description: XML Parser Toolkit, runtime libraries
1118 Libraries for XML parsing in C, which contains the shared libraries,
1119 libxmltok and libxmlparser. These libraries are being used, for
1120 instance, for XML support to Netscape 5 and the Perl module,
1121 XML::Parser.
1122 .
1123 Author: James Clark <jjc@jclark.com>
1124 Homepage: http://www.jclark.com/xml/expat.html
1125
1126Package: libxrender
1127Priority: optional
1128Version: 0.0
1129Architecture: arm
1130Maintainer: Carl Worth <cworth@handhelds.org>
1131Depends: libc6
1132Filename: ./libxrender_0.0_arm.ipk
1133Size: 7748
1134MD5Sum: ddc4cf38278e868247db1daf82d3390d
1135Description: X rendering extension
1136
1137Package: loadmeter
1138Priority: optional
1139Version: 0.0
1140Architecture: arm
1141Maintainer: Carl Worth <cworth@handhelds.org>
1142Depends: libc6, xlibs
1143Filename: ./loadmeter_0.0_arm.ipk
1144Size: 17294
1145MD5Sum: 68863f7c94238b4902722e9555a40f52
1146Description: graphical CPU load montitoring
1147
1148Package: login
1149Essential: yes
1150Priority: required
1151Section: base
1152Installed-Size: 312
1153Debian-Maintainer: Ben Collins <bcollins@debian.org>
1154Maintainer: Carl Worth <cworth@handhelds.org>
1155Architecture: arm
1156Source: shadow
1157Version: 20000902-3.1
1158Replaces: shadow-login, shadow-passwd, shellutils (<< 2.0-2)
1159Depends: libpam-modules (>= 0.72-5)
1160Pre-Depends: libc6 (>= 2.2.1-2), libpam0g (>= 0.72-1)
1161Conflicts: shadow-login, pam-apps, secure-su, suidregister (<< 0.50)
1162Filename: ./login_20000902-3.1_arm.ipk
1163Size: 24402
1164MD5Sum: 7817225e43bb8e999f89c58152d23de4
1165Description: System login tools
1166 These tools are required to be able to login and use your system. The
1167 login program invokes you user shell and enables command execution. The
1168 newgrp program is used to change your effective group ID (useful for
1169 workgroup type situations). The su program allows changing your effective
1170 user ID (useful being able to execute commands as another user).
1171 .
1172 Also supplies a logout daemon that can place limits on when, from where,
1173 and for how long certain users can login to the system.
1174
1175Package: lrzsz
1176Essential: yes
1177Priority: required
1178Section: comm
1179Installed-Size: 264
1180Debian-Maintainer: Josip Rodin <jrodin@jagor.srce.hr>
1181Maintainer: Carl Worth <cworth@handhelds.org>
1182Architecture: arm
1183Version: 0.12.21-4
1184Depends: libc6 (>= 2.2.1-2)
1185Suggests: minicom
1186Filename: ./lrzsz_0.12.21-4_arm.ipk
1187Size: 64893
1188MD5Sum: 6f1a0ea3c0bc986b96c916192fe318ab
1189Description: Tools for zmodem/xmodem/ymodem file transfer
1190 Lrzsz is a cosmetically modified zmodem/ymodem/xmodem package built
1191 from the public-domain version of Chuck Forsberg's rzsz package.
1192 .
1193 These programs use error correcting protocols ({z,x,y}modem) to send
1194 (sz, sx, sb) and receive (rz, rx, rb) files over a dial-in serial port
1195 from a variety of programs running under various operating systems.
1196
1197Package: madplay
1198Priority: optional
1199Version: 0.0
1200Architecture: arm
1201Maintainer: Carl Worth <cworth@handhelds.org>
1202Depends: libc6
1203Filename: ./madplay_0.0_arm.ipk
1204Size: 70830
1205MD5Sum: 5ff68a920d656af9c8aaefaa1362a0f1
1206Description: Fast, high-quality, fixed-point MP3 player
1207
1208Package: mingle
1209Priority: optional
1210Version: 0.1
1211Architecture: arm
1212Maintainer: Gareth J. Greenaway <gareth@wiked.org>
1213Depends: python
1214Filename: ./mingle_0.1_arm.ipk
1215Size: 51136
1216MD5Sum: 5954457eb75f93c38f941d283ea05f50
1217Description: Mingle contact manager illustrating the use of the Familiar Framework project.
1218
1219Package: mixer
1220Priority: optional
1221Version: 0.0
1222Architecture: arm
1223Maintainer: Carl Worth <cworth@handhelds.org>
1224Depends: libc6, xlibs
1225Filename: ./mixer_0.0_arm.ipk
1226Size: 8729
1227MD5Sum: 50d2997c142037603450e53c6af14bf6
1228Description: control audio levels graphically
1229
1230Package: modutils
1231Priority: required
1232Section: base
1233Installed-Size: 564
1234Debian-Maintainer: Wichert Akkerman <wakkerma@debian.org>
1235Maintainer: Carl Worth <cworth@handhelds.org>
1236Architecture: arm
1237Version: 2.4.2-1
1238Replaces: manpages (<=1.15-3)
1239Depends: libc6 (>= 2.1.97), sysvinit (>=2.71-2)
1240Suggests: ksymoops
1241Filename: ./modutils_2.4.2-1_arm.ipk
1242Size: 113605
1243MD5Sum: 8046533303655791c7c1a16f76224346
1244Description: Linux module utilities.
1245 These utilities are intended to make a Linux modular kernel
1246 manageable for all users, administrators and distribution
1247 maintainers.
1248Origin: debian
1249Bugs: debbugs://bugs.debian.org/
1250
1251Package: mount
1252Essential: yes
1253Priority: required
1254Section: base
1255Installed-Size: 228
1256Debian-Maintainer: Adrian Bunk <bunk@fs.tum.de>
1257Maintainer: Carl Worth <cworth@handhelds.org>
1258Architecture: arm
1259Source: util-linux
1260Version: 2.11b-2
1261Pre-Depends: libc6 (>= 2.2.1-2)
1262Filename: ./mount_2.11b-2_arm.ipk
1263Size: 41072
1264MD5Sum: ddc0df15fb6d3aac711d0a77172df6c2
1265Description: Tools for mounting and manipulating filesystems.
1266 This package provides the mount(8), umount(8), swapon(8),
1267 swapoff(8), and losetup(8) commands.
1268
1269Package: ncurses-base
1270Priority: required
1271Section: base
1272Installed-Size: 222
1273Debian-Maintainer: Daniel Jacobowitz <ncurses-maint@debian.org>
1274Maintainer: Carl Worth <cworth@handhelds.org>
1275Architecture: all
1276Source: ncurses
1277Version: 5.2.20010318-1
1278Replaces: ncurses-term
1279Provides: ncurses-runtime
1280Conflicts: ncurses, ncurses-runtime
1281Filename: ./ncurses-base_5.2.20010318-1_all.ipk
1282Size: 8901
1283MD5Sum: 67746347774792cff7d97adf0ff4c272
1284Description: Descriptions of common terminal types
1285 This package contains what should be a reasonable subset of terminal
1286 definitions, including: ansi, dumb, linux, rxvt, screen, sun, vt100,
1287 vt102, vt220, vt52, and xterm.
1288
1289Package: netbase
1290Priority: important
1291Section: base
1292Installed-Size: 110
1293Debian-Maintainer: Anthony Towns <ajt@debian.org>
1294Maintainer: Carl Worth <cworth@handhelds.org>
1295Architecture: all
1296Version: 4.05
1297Depends: net-tools | iproute, ifupdown, ipchains | ipfwadm | iptables, netkit-inetd, tcpd, netkit-ping | iputils-ping
1298Suggests: debconf, ipmasqadm | ipautofw | iptables, portmap, netkit-rpc
1299Conflicts: xinetd (<= 2.2.1-8), netstd (<< 3.00), nfs-user-server (<< 2.2beta47-9), nis (<= 3.6-2), rstatd (<= 3.03-3), rwalld (<= 0.16-1), rusersd (<= 0.17-1), ugidd (<< 2.2beta47-9)
1300Filename: ./netbase_4.05_all.ipk
1301Size: 9502
1302MD5Sum: 029f1dffa57f6b23f97b08b5262dfc38
1303Description: Basic TCP/IP networking system
1304 This package provides the necessary infrastructure for basic TCP/IP based
1305 networking.
1306
1307Package: netcat
1308Priority: optional
1309Section: net
1310Installed-Size: 228
1311Debian-Maintainer: Decklin Foster <decklin@red-bean.com>
1312Maintainer: Carl Worth <cworth@handhelds.org>
1313Architecture: arm
1314Version: 1.10-17
1315Depends: libc6 (>= 2.2.1-2)
1316Filename: ./netcat_1.10-17_arm.ipk
1317Size: 12265
1318MD5Sum: 14101b949ee963abb64de99130725c6f
1319Description: TCP/IP swiss army knife
1320 A simple Unix utility which reads and writes data across network
1321 connections using TCP or UDP protocol. It is designed to be a reliable
1322 "back-end" tool that can be used directly or easily driven by other
1323 programs and scripts. At the same time it is a feature-rich network
1324 debugging and exploration tool, since it can create almost any kind of
1325 connection you would need and has several interesting built-in
1326 capabilities.
1327
1328Package: netkit-ping
1329Priority: important
1330Section: net
1331Installed-Size: 84
1332Debian-Maintainer: Anthony Towns <ajt@debian.org>
1333Maintainer: Carl Worth <cworth@handhelds.org>
1334Architecture: arm
1335Source: netkit-base
1336Version: 0.10-6.1
1337Replaces: netbase (<< 4.00)
1338Provides: ping
1339Depends: libc6 (>= 2.2.1-2)
1340Conflicts: ping
1341Filename: ./netkit-ping_0.10-6.1_arm.ipk
1342Size: 10418
1343MD5Sum: cdf51bd27a0e95867f1ee7ab7c328192
1344Description: The ping utility from netkit
1345 The ping command sends ICMP ECHO_REQUEST packets to a host in order to
1346 test if the host is reachable via the network.
1347
1348Package: net-tools
1349Priority: important
1350Section: net
1351Installed-Size: 676
1352Debian-Maintainer: Bernd Eckenfels <ecki@debian.org>
1353Maintainer: Carl Worth <cworth@handhelds.org>
1354Architecture: arm
1355Version: 1.59-1
1356Replaces: netbase (<< 4.00)
1357Depends: libc6 (>= 2.2.1-2)
1358Filename: ./net-tools_1.59-1_arm.ipk
1359Size: 100555
1360MD5Sum: 5f8cd79e32b953142faed78f46dd5625
1361Description: The NET-3 networking toolkit
1362 This package includes the important tools for controlling the network
1363 subsystem of the Linux kernel. This includes arp, ifconfig, netstat,
1364 rarp, nameif and route. Additionally, this package contains utilities
1365 relating to particular network hardware types (plipconfig, slattach) and
1366 advanced aspects of IP configuration (iptunnel, ipmaddr).
1367 .
1368 In the upstream package 'hostname' and friends are included. Those are
1369 not installed by this package, since there is a special "hostname*.deb".
1370
1371Package: ntpdate
1372Priority: optional
1373Section: net
1374Installed-Size: 132
1375Debian-Maintainer: Bdale Garbee <bdale@gag.com>
1376Maintainer: Carl Worth <cworth@handhelds.org>
1377Architecture: arm
1378Source: ntp
1379Version: 1:4.0.99g-3
1380Replaces: ntp (<< 4.0.98a),xntp,xntp3
1381Depends: libc6 (>= 2.2.1-2)
1382Suggests: ntp
1383Conflicts: ntp (<< 4.0.98a),chrony
1384Filename: ./ntpdate_4.0.99g-3_arm.ipk
1385Size: 22995
1386MD5Sum: 628963690db28b96a036356abcee8860
1387Description: The ntpdate client for setting system time from NTP servers.
1388 The ntpdate client allows a system's clock to be set to match the time
1389 obtained by communicating with one or more servers running the NTP protocol.
1390 .
1391 The use of ntpdate is optional if you're running the ntp package, it can help
1392 a system obtain lock if it starts with a time that's pretty close by using
1393 ntpdate before starting the daemon.
1394 .
1395 The ntpdate client by itself is useful for occasionally setting the time on
1396 machines that are not on the net full-time, such as laptops.
1397
1398Package: pcmcia-cs
1399Priority: extra
1400Version: 0.0-fam3
1401Architecture: arm
1402Maintainer: Carl Worth <cworth@handhelds.org>
1403Depends: libc6 (>= 2.2.1-2), modutils, psmisc
1404Suggests: pcmcia-modules, xlibs (>= 4.0.1-11)
1405Filename: ./pcmcia-cs_0.0-fam3_arm.ipk
1406Size: 57178
1407MD5Sum: 123d19e3199f7598e6517efe6e2a2080
1408Description: PCMCIA Card Services for Linux.
1409 NOTE: I couldn't find this package in Debian/arm so I just grabbed
1410 the control file from my Debian/i386 and combined it with the
1411 pcmcia-cs bits from familiar v0.4 bleeding. A better solution would
1412 be to rebuild the real .deb from the pcmcia-cs source.
1413 .
1414 PCMCIA cards are commonly used in laptops to provide expanded
1415 capabilities, such as modems, increased memory, etc. Some desktop PCs
1416 can accept PCMCIA cards as well, although this is rare.
1417 .
1418 Card Services for Linux is a complete PCMCIA support package. It
1419 includes a set of client drivers for specific cards, and a card
1420 manager daemon that can respond to card insertion and removal events,
1421 loading and unloading drivers on demand. It supports ``hot swapping''
1422 of PCMCIA cards, so cards can be inserted and ejected at any time.
1423 .
1424 The actual kernel modules required for this package are contained in
1425 the pcmcia-modules-<kernel version> package, where <kernel version> is
1426 the version of the kernel for which the modules have been compiled.
1427
1428Package: pcmcia-modules-2.4.3-rmk2-np1
1429Priority: extra
1430Maintainer: Alexander Guy <a7r@andern.org>
1431Depends: kernel-modules-2.4.3-rmk2-np1, pcmcia-cs
1432Version: fam3
1433Architecture: arm
1434Filename: ./pcmcia-modules-2.4.3-rmk2-np1_fam3_arm.ipk
1435Size: 111546
1436MD5Sum: 95da695ec0792cdb70b86aaf5eb48e7c
1437Description: PCMCIA kernel modules
1438 The full collection of PCMCIA kernel modules from pcmcia-cs. Install
1439 this if you will be plugging any Compact Flash or PCMCIA cards into
1440 your computer.
1441 .
1442 We may want to split these up into many fine-grained packages.
1443
1444Package: ppp
1445Priority: standard
1446Section: base
1447Installed-Size: 764
1448Debian-Maintainer: Michael Beattie <mjb@debian.org>
1449Maintainer: Carl Worth <cworth@handhelds.org>
1450Architecture: arm
1451Version: 2.4.0f-1
1452Replaces: ppp-pam
1453Depends: libc6 (>= 2.1.2), libpam0g, libpam-modules, netbase, sysvinit (>= 2.75-4)
1454Suggests: debconf
1455Conflicts: ppp-pam
1456Filename: ./ppp_2.4.0f-1_arm.ipk
1457Size: 96430
1458MD5Sum: 2bd0da8e83b6d609a4a5dc498564ce06
1459Description: Point-to-Point Protocol (PPP) daemon.
1460 The Point-to-Point Protocol (PPP) provides a standard way to transmit
1461 datagrams over a serial link, as well as a standard way for the machines
1462 at either end of the link (the "peers") to negotiate various optional
1463 characteristics of the link. Using PPP, a serial link can be used to
1464 transmit Internet Protocol (IP) datagrams, allowing TCP/IP connections
1465 between the peers.
1466 .
1467 This package contains pppd with PAM support built-in, so `ppp-pam'
1468 package is obsolete.
1469
1470Package: procps
1471Priority: required
1472Section: base
1473Installed-Size: 484
1474Debian-Maintainer: Craig Small <csmall@debian.org>
1475Maintainer: Carl Worth <cworth@handhelds.org>
1476Architecture: arm
1477Version: 1:2.0.7-4
1478Replaces: watch, bsdutils (<< 2.9x-1)
1479Provides: watch
1480Depends: libc6 (>= 2.2.1-2), libncurses5
1481Recommends: psmisc
1482Conflicts: watch, libproc-dev (<< 1:1.2.6-2), w-bassman (<< 1.0-3), procps-nonfree, pgrep (<< 3.3-5)
1483Filename: ./procps_2.0.7-4_arm.ipk
1484Size: 46669
1485MD5Sum: 374592eb63c1100ebded8c4129954cc3
1486Description: The /proc file system utilities.
1487 These are utilities to browse the /proc filesystem, which is not a real file
1488 system but a way for the kernel to provide information about the status of
1489 entries in its process table. (e.g. running, stopped or "zombie")
1490 Both command line and full screen utilities are provided. Ncurses is needed
1491 for the full screen utilities.
1492
1493Package: pump
1494Priority: optional
1495Section: base
1496Installed-Size: 144
1497Debian-Maintainer: Steve Dunham <dunham@debian.org>
1498Maintainer: Carl Worth <cworth@handhelds.org>
1499Architecture: arm
1500Version: 0.8.3-3
1501Replaces: pump-udeb
1502Depends: libc6 (>= 2.1.97)
1503Conflicts: dhcpcd, dhcpcd-sv, pump-udeb
1504Filename: ./pump_0.8.3-3_arm.ipk
1505Size: 25830
1506MD5Sum: 1f0b17323498f46c111531b03df1153d
1507Description: Simple DHCP/BOOTP client.
1508 This is the DHCP/BOOTP client written by RedHat.
1509
1510Package: pyditor
1511Priority: optional
1512Version: 0.0
1513Architecture: arm
1514Maintainer: Carl Worth <cworth@handhelds.org>
1515Depends: python
1516Filename: ./pyditor_0.0_arm.ipk
1517Size: 1444
1518MD5Sum: c7209f99c5036c9ece32918905086cc5
1519Description: python-based text editor
1520
1521Package: python
1522Priority: optional
1523Version: 0.0
1524Architecture: arm
1525Maintainer: Carl Worth <cworth@handhelds.org>
1526Depends: libc6, libdb2
1527Filename: ./python_0.0_arm.ipk
1528Size: 834371
1529MD5Sum: 30aaff82d29a7ed787f7d288c8743794
1530Description: python of course <needs real description>
1531
1532Package: qiv
1533Priority: extra
1534Section: graphics
1535Installed-Size: 86
1536Debian-Maintainer: Mitch Blevins <mblevin@debian.org>
1537Maintainer: Carl Worth <cworth@handhelds.org>
1538Architecture: arm
1539Version: 1.6-1
1540Depends: gdk-imlib1 (>= 1.9.8.1-2), libc6 (>= 2.1.97), libglib1.2 (>= 1.2.0), libgtk1.2 (>= 1.2.8-3), xlibs (>= 4.0.1-11)
1541Filename: ./qiv_1.6-1_arm.ipk
1542Size: 15767
1543MD5Sum: 877b1dc63c32b1f468a20a7ade4818f5
1544Description: a quick image viewer for X
1545 Quick Image Viewer (qiv) is a very small and pretty fast GDK/Imlib
1546 image viewer. Features include zoom, maxpect, scale down, fullscreen,
1547 brightness/contrast/gamma correction, slideshow, flip,
1548 horizontal/vertical, rotate left/right, delete (move to .qiv-trash/),
1549 jump to image x, jump forward/backward x images, filename filter and
1550 you can use qiv to set your X11-Desktop background.
1551
1552Package: reiserfs-module
1553Priority: optional
1554Section: kernel
1555Installed-Size: 249337
1556Debian-Maintainer: Nicolás Lichtmaier <nick@debian.org>
1557Maintainer: Carl Worth <cworth@handhelds.org>
1558Architecture: arm
1559Version: 2.4.3-rmk2-np1
1560Depends: kernel (= 2.4.3-rmk2-np1)
1561Filename: ./reiserfs-module_2.4.3-rmk2-np1_arm.ipk
1562Size: 106059
1563MD5Sum: f1975bedcc503d1ee66a9e627350b813
1564Description: Reiserfs is a journaling filesystem. This is the kernel module for it.
1565
1566Package: rsync
1567Priority: optional
1568Section: net
1569Installed-Size: 280
1570Debian-Maintainer: Philip Hands <phil@hands.com>
1571Maintainer: Carl Worth <cworth@handhelds.org>
1572Architecture: arm
1573Version: 2.4.6-1
1574Depends: libc6 (>= 2.1.2)
1575Suggests: ssh
1576Filename: ./rsync_2.4.6-1_arm.ipk
1577Size: 74003
1578MD5Sum: ce2d8f8672994f93bb03c38919fdb504
1579Description: fast remote file copy program (like rcp)
1580 rsync is a program that allows files to be copied to and from remote
1581 machines in much the same way as rcp. It has many more options than
1582 rcp, and uses the rsync remote-update protocol to greatly speedup
1583 file transfers when the destination file already exists.
1584 .
1585 The rsync remote-update protocol allows rsync to transfer just the
1586 differences between two sets of files across the network link.
1587
1588Package: rxvt
1589Priority: optional
1590Section: x11
1591Installed-Size: 580
1592Debian-Maintainer: Brian Mays <brian@debian.org>
1593Maintainer: Carl Worth <cworth@handhelds.org>
1594Architecture: arm
1595Version: 1:2.6.3-8-fam1
1596Provides: x-terminal-emulator
1597Depends: libc6 (>= 2.1.97), xlibs (>= 4.0.1-11), base-passwd (>= 2.0.3.4)
1598Conflicts: suidmanager (<< 0.50)
1599Filename: ./rxvt_2.6.3-8-fam1_arm.ipk
1600Size: 40759
1601MD5Sum: e514f9093a45e8a95db37123a193b974
1602Description: VT102 terminal emulator for the X Window System
1603 Rxvt is an 8-bit clean, color xterm replacement that uses significantly
1604 less memory than a conventional xterm, mostly since it doesn't support
1605 toolkit configurability or Tek graphics, but also since features can
1606 be removed at compile-time to reflect your needs.
1607 .
1608 The distribution also includes rclock, the smaller/better xclock
1609 replacement with appointment scheduling and xbiff functionality.
1610
1611Package: rxvt-aa
1612Priority: optional
1613Section: x11
1614Installed-Size: 580
1615Maintainer: Carl Worth <cworth@handhelds.org>
1616Architecture: arm
1617Version: 1:2.6.3-8
1618Provides: x-terminal-emulator
1619Depends: libc6 (>= 2.1.97), xlibs (>= 4.0.1-11), base-passwd (>= 2.0.3.4), libxft, libxrender
1620Conflicts: suidmanager (<< 0.50)
1621Filename: ./rxvt-aa_2.6.3-8_arm.ipk
1622Size: 42018
1623MD5Sum: c042c85c082d043aa5a58d4c62c67b70
1624Description: rxvt with support for anti-aliased fonts
1625 This package proves an rxvt terminal with support for anti-aliased fonts.
1626 .
1627 Rxvt is an 8-bit clean, color xterm replacement that uses significantly
1628 less memory than a conventional xterm, mostly since it doesn't support
1629 toolkit configurability or Tek graphics, but also since features can
1630 be removed at compile-time to reflect your needs.
1631 .
1632 The distribution also includes rclock, the smaller/better xclock
1633 replacement with appointment scheduling and xbiff functionality.
1634
1635Package: screen
1636Priority: optional
1637Version: 3.9.8
1638Architecture: arm
1639Maintainer: Brian Kearns <bdkearns@bdkearns.net>
1640Depends: ncurses-base, libncurses5, libc6
1641Filename: ./screen_3.9.8_arm.ipk
1642Size: 134749
1643MD5Sum: 80b9bb7de6b30ecdeadc04f0bcda875a
1644Description: Console manager
1645
1646Package: script-test
1647Priority: optional
1648Version: 0.0
1649Architecture: all
1650Maintainer: Carl Worth <cworth@handhelds.org>
1651Depends:
1652Filename: ./script-test_0.0_all.ipk
1653Size: 820
1654MD5Sum: ea6b272ff25bb69482a9907492b316a0
1655Description: Empty test for ipkg script support
1656
1657Package: sed
1658Priority: required
1659Section: base
1660Installed-Size: 180
1661Debian-Maintainer: Wichert Akkerman <wakkerma@debian.org>
1662Maintainer: Carl Worth <cworth@handhelds.org>
1663Architecture: arm
1664Version: 3.02-6
1665Pre-Depends: libc6 (>= 2.1.2)
1666Filename: ./sed_3.02-6_arm.ipk
1667Size: 12338
1668MD5Sum: c893daf6fef70813b566db8ed8c06950
1669Description: The GNU sed stream editor.
1670 sed reads the specified files or the standard input if no
1671 files are specified, makes editing changes according to a
1672 list of commands, and writes the results to the standard
1673 output.
1674
1675Package: shellutils
1676Essential: yes
1677Priority: required
1678Section: base
1679Installed-Size: 2152
1680Debian-Maintainer: Michael Stone <mstone@debian.org>
1681Maintainer: Carl Worth <cworth@handhelds.org>
1682Architecture: arm
1683Version: 2.0.11-5
1684Replaces: bsdutils (<= 3.0-2), util-linux (<< 2.9e-0.1)
1685Pre-Depends: libc6 (>= 2.2.1-2), login | hurd
1686Conflicts: login (<< 19990827-1)
1687Filename: ./shellutils_2.0.11-5_arm.ipk
1688Size: 123564
1689MD5Sum: a9a70a1fd2e2057ed43e5a069d521d0d
1690Description: The GNU shell programming utilities.
1691 The utilities: basename chroot date dirname echo env expr factor false groups
1692 hostid id logname nice nohup pathchk pinky printenv printf pwd seq sleep stty
1693 tee test true tty uname users who whoami yes.
1694
1695Package: slang1
1696Priority: optional
1697Section: libs
1698Installed-Size: 456
1699Debian-Maintainer: Jim Mintha <jmintha@debian.org>
1700Maintainer: Carl Worth <cworth@handhelds.org>
1701Architecture: arm
1702Source: slang
1703Version: 1.4.4-1
1704Depends: libc6 (>= 2.2.1-2)
1705Filename: ./slang1_1.4.4-1_arm.ipk
1706Size: 159766
1707MD5Sum: 775f054fdda315ef73afc9399612a7ad
1708Description: The S-Lang programming library - runtime version.
1709 S-Lang is a C programmer's library that includes routines for the rapid
1710 development of sophisticated, user friendly, multi-platform applications.
1711 .
1712 This package contains only the shared library libslang.so.* and copyright
1713 information. It is only necessary for programs that use this library (such
1714 as jed and slrn). If you plan on doing development with S-Lang, you will
1715 need the companion -dev package as well.
1716
1717
1718Package: ssh
1719Priority: optional
1720Section: non-US
1721Installed-Size: 1020
1722Debian-Maintainer: Philip Hands <phil@hands.com>
1723Maintainer: Carl Worth <cworth@handhelds.org>
1724Architecture: arm
1725Source: openssh
1726Version: 1:2.5.2p2-2
1727Depends: libc6 (>= 2.2.1-2), libpam0g (>= 0.72-1), libssl0.9.6, libwrap0, zlib1g (>= 1:1.1.3), libpam-modules (>= 0.72-9), libwrap0 (>= 7.6-1.1)
1728Suggests: ssh-askpass, debconf, xbase-clients, dpkg (>= 1.8.3.1)
1729Conflicts: ssh-nonfree, ssh-socks, ssh2, debconf (<< 0.2.17), debconf-tiny (<< 0.2.17), sftp, rsh-client (<< 0.16.1-1)
1730Filename: ./ssh_2.5.2p2-2_arm.ipk
1731Size: 210692
1732MD5Sum: 1fe9ccb1693d36d4388758f73f041d9b
1733Description: Secure rlogin/rsh/rcp replacement (OpenSSH)
1734 OpenSSH is derived from OpenBSD's version of ssh, which was in turn
1735 derived from ssh code from before the time when ssh's license was
1736 changed to be non-free.
1737 Ssh (Secure Shell) is a program for logging into a remote machine
1738 and for executing commands on a remote machine.
1739 It provides secure encrypted communications between two untrusted
1740 hosts over an insecure network. X11 connections and arbitrary TCP/IP
1741 ports can also be forwarded over the secure channel.
1742 It is intended as a replacement for rlogin, rsh and rcp, and can be
1743 used to provide rdist, and rsync with a secure communication channel.
1744 .
1745 --------------------------------------------------------------------
1746 .
1747 This software may be freely imported into the United States; however,
1748 the United States Government may consider re-exporting it a criminal
1749 offense. Thus, if you are outside the US, please retrieve this
1750 software from outside the US.
1751 In some countries, particularly Russia, Iraq, Pakistan, and France, it
1752 may be illegal to use any encryption at all without a special permit.
1753
1754Package: stowaway-h3600
1755Priority: optional
1756Version: 1.0
1757Architecture: arm
1758Maintainer: Carl Worth <cworth@handhelds.org>
1759Depends: libc6
1760Filename: ./stowaway-h3600_1.0_arm.ipk
1761Size: 15470
1762MD5Sum: 67c0f14bf6a5e523ed7a95b6fca02a79
1763Description: Support for the iPAQ H3600 series Stowaway keyboard
1764
1765Package: sysset
1766Priority: optional
1767Version: 0.0
1768Architecture: arm
1769Maintainer: Carl Worth <cworth@handhelds.org>
1770Depends: python
1771Filename: ./sysset_0.0_arm.ipk
1772Size: 2878
1773MD5Sum: 5124d246b5b7da481874f97fb86c859f
1774Description: python utility for configuring system settings
1775
1776Package: sysvinit
1777Essential: yes
1778Priority: required
1779Section: base
1780Installed-Size: 207
1781Debian-Maintainer: Miquel van Smoorenburg <miquels@cistron.nl>
1782Maintainer: Carl Worth <cworth@handhelds.org>
1783Architecture: arm
1784Version: 2.78-4
1785Replaces: last, bsdutils (<=2.0-2)
1786Depends: dpkg (>= 1.4.0.21), mount (>= 2.7i-1), util-linux (>= 2.9t-2), e2fsprogs (>= 1.15-1)
1787Pre-Depends: libc6 (>= 2.1.2)
1788Conflicts: last, file-rc (<= 0.4.2), kbd (<< 0.95-2), mdutils (<< 0.35-9)
1789Filename: ./sysvinit_2.78-4_arm.ipk
1790Size: 43771
1791MD5Sum: ebf719f849e02d9bdfd66f54e129398e
1792Description: System-V like init.
1793 Init is the first program to run after your system is booted, and
1794 continues to run as process number 1 until your system halts. Init's
1795 job is to start other programs that are essential to the operation of
1796 your system. All processes are descended from init. For more information,
1797 see the manual page init(8).
1798
1799Package: tar
1800Essential: yes
1801Priority: required
1802Section: base
1803Installed-Size: 1064
1804Debian-Maintainer: Bdale Garbee <bdale@gag.com>
1805Maintainer: Carl Worth <cworth@handhelds.org>
1806Architecture: arm
1807Version: 1.13.19-1
1808Pre-Depends: libc6 (>= 2.1.97)
1809Suggests: bzip2
1810Filename: ./tar_1.13.19-1_arm.ipk
1811Size: 67084
1812MD5Sum: 4f93d22d8645b86b6fb49c375254045e
1813Description: GNU tar
1814 Tar is a program for packaging a set of files as a single archive in tar
1815 format. The function it performs is conceptually similar to cpio, and to
1816 things like pkzip in the DOS world. It is heavily used by the Debian package
1817 management system, and is useful for performing system backups and exchanging
1818 sets of files with others.
1819
1820Package: task-bootstrap
1821Priority: optional
1822Version: 0.6
1823Architecture: arm
1824Maintainer: Alexander Guy <a7r@handhelds.org>
1825Depends: ssh, ppp, pcmcia-modules-2.4.3-rmk2-np1, wireless-tools, pump
1826Filename: ./task-bootstrap_0.6_arm.ipk
1827Size: 693
1828MD5Sum: 1dc75245df83987c0cb26f1953d2e9ec
1829Description: Everything you might need to bootstrap a minimal ipkg system.
1830
1831Package: task-familiar-complete
1832Priority: optional
1833Version: 0.5
1834Architecture: arm
1835Maintainer: Carl Worth <cworth@handhelds.org>
1836Depends: apmd, checkers, cpu-scale-2.4.3-rmk2-np1, dosfstools, fscrib, h3600-utils, libglade0, libpopt0, libxaw6, libxml1, libxmltok1, loadmeter, ncurses-base, netcat, ntpdate, pcmcia-modules-2.4.3-rmk2-np1, procps, ppp, pump, pyditor, qiv, rsync, ssh, sysset, xvkbd, task-mp3-player, task-games, task-wireless, task-x
1837Filename: ./task-familiar-complete_0.5_arm.ipk
1838Size: 808
1839MD5Sum: f117049d5863f2e70d9903f9bc83475e
1840Description: Task package for a complete familiar system
1841
1842Package: task-games
1843Priority: optional
1844Version: 0.0
1845Architecture: arm
1846Maintainer: Carl Worth <cworth@handhelds.org>
1847Depends: checkers
1848Filename: ./task-games_0.0_arm.ipk
1849Size: 994
1850MD5Sum: 48f5a22131a2f4aada009620b1242438
1851Description: Task package for a complete familiar system
1852
1853Package: task-mp3-player
1854Priority: optional
1855Version: 0.0
1856Architecture: arm
1857Maintainer: Carl Worth <cworth@handhelds.org>
1858Depends: madplay, mixer
1859Filename: ./task-mp3-player_0.0_arm.ipk
1860Size: 667
1861MD5Sum: aa5f5c85ccb22af9c4f6f677522df9e7
1862Description: Task package for a complete familiar system
1863
1864Package: task-wireless
1865Priority: optional
1866Version: 0.1
1867Architecture: arm
1868Maintainer: Carl Worth <cworth@handhelds.org>
1869Depends: wireless-tools, pcmcia-modules-2.4.3-rmk2-np1
1870Filename: ./task-wireless_0.1_arm.ipk
1871Size: 639
1872MD5Sum: 988d6d2960bf165b5ed324dbfb85d674
1873Description: Task package for wireless networking
1874
1875Package: task-x
1876Priority: optional
1877Version: 0.0
1878Architecture: arm
1879Maintainer: Carl Worth <cworth@handhelds.org>
1880Depends: xserver-tiny-h3600, xbase-clients, xfonts-base, xfonts-75dpi, xfonts-ttf, blackbox, rxvt-aa, xcalibrate
1881Filename: ./task-x_0.0_arm.ipk
1882Size: 739
1883MD5Sum: 78d7c74c9fdac90f3b58fba7231a4ff8
1884Description: Task package for a basic X system
1885
1886Package: textutils
1887Essential: yes
1888Priority: required
1889Section: base
1890Installed-Size: 1550
1891Debian-Maintainer: Herbert Xu <herbert@debian.org>
1892Maintainer: Carl Worth <cworth@handhelds.org>
1893Architecture: arm
1894Version: 2.0-3
1895Replaces: bsdmainutils (<= 4.5.2), ptx
1896Provides: ptx
1897Pre-Depends: libc6 (>= 2.1.2)
1898Conflicts: ptx
1899Filename: ./textutils_2.0-3_arm.ipk
1900Size: 156555
1901MD5Sum: fbdac4eb344aea6287461bc8dc613add
1902Description: The GNU text file processing utilities.
1903 The utilities: cat cksum comm csplit cut expand fmt fold head join md5sum
1904 nl od paste pr ptx sort split sum tac tail tr tsort unexpand uniq wc.
1905
1906Package: urlget
1907Priority: optional
1908Version: 0.3
1909Architecture: arm
1910Maintainer: Carl Worth <cworth@handhelds.org>
1911Depends: libc6, netbase
1912Filename: ./urlget_0.3_arm.ipk
1913Size: 2613
1914MD5Sum: 271ae2fbfd1e691d2b19d24ba1c01648
1915Description: Tiny package for retrieving files via HTTP
1916
1917Package: util-linux
1918Essential: yes
1919Priority: required
1920Section: base
1921Installed-Size: 840
1922Debian-Maintainer: Adrian Bunk <bunk@fs.tum.de>
1923Maintainer: Carl Worth <cworth@handhelds.org>
1924Architecture: arm
1925Version: 2.11b-2-fam2
1926Replaces: miscutils, setterm, getty, fdisk
1927Pre-Depends: libc6 (>= 2.2.1-2), libncurses5 (>= 5.2.20010310-1)
1928Recommends: util-linux-locales
1929Suggests: kbd | console-tools
1930Conflicts: setterm, getty, fdisk, kbd (<< 1.05-3), console-tools (<< 1:0.2.3-21)
1931Filename: ./util-linux_2.11b-2-fam2_arm.ipk
1932Size: 9771
1933MD5Sum: e1abcd568a156976ac95eff239dbb091
1934Description: Miscellaneous system utilities.
1935 A mixed bag of system utilities: arch chkdupexe cfdisk cytune dmesg
1936 fdisk fsck.minix getty getopt hwclock ipcrm ipcs mcookie mkfs mkfs.minix
1937 mkswap more namei pivot_root raw rdev setterm setsid tunelp whereis.
1938
1939Package: wget
1940Priority: optional
1941Section: web
1942Installed-Size: 1272
1943Debian-Maintainer: Nicolás Lichtmaier <nick@debian.org>
1944Maintainer: Carl Worth <cworth@handhelds.org>
1945Architecture: arm
1946Version: 1.6-2
1947Depends: libc6 (>= 2.2.1-2), netbase
1948Filename: ./wget_1.6-2_arm.ipk
1949Size: 62824
1950MD5Sum: bbc13feb01f63a86cb6a542bf629cc77
1951Description: utility to retrieve files from the WWW via HTTP and FTP
1952 Wget [formerly known as Geturl] is a freely available network utility
1953 to retrieve files from the World Wide Web using HTTP and FTP, the two
1954 most widely used Internet protocols. It works non-interactively, thus
1955 enabling work in the background, after having logged off.
1956 .
1957 The recursive retrieval of HTML pages, as well as FTP sites is
1958 supported -- you can use Wget to make mirrors of archives and home
1959 pages, or traverse the web like a WWW robot (Wget understands
1960 /robots.txt).
1961
1962Package: wireless-tools
1963Priority: optional
1964Section: net
1965Installed-Size: 120
1966Debian-Maintainer: Björn Andersson <bjorn@lifix.fi>
1967Maintainer: Carl Worth <cworth@handhelds.org>
1968Architecture: arm
1969Version: 20-1.1
1970Depends: libc6 (>= 2.2.1-2)
1971Filename: ./wireless-tools_20-1.1_arm.ipk
1972Size: 17032
1973MD5Sum: 695142d573351ca6e8ddffcfc77fa195
1974Description: Tools for manipulating Linux Wireless Extensions
1975 This package contains the Wireless tools, used to manipulate
1976 the Linux Wireless Extensions. The Wireless Extension is an interface
1977 allowing you to set Wireless LAN specific parameters and get the
1978 specific stats.
1979 .
1980 The tools in this package only work with kernel versions 2.2.14
1981 and above, and 2.3.24 and above.
1982
1983Package: xbase-clients
1984Priority: optional
1985Section: x11
1986Installed-Size: 3916
1987Debian-Maintainer: Branden Robinson <branden@debian.org>
1988Maintainer: Carl Worth <cworth@handhelds.org>
1989Architecture: arm
1990Source: xfree86
1991Version: 4.0.2-13
1992Replaces: xbase (<< 3.3.2.3a-2), xf86setup (<< 3.3.2.3a-9), xserver-common (<< 4.0), xmodmap, xcontrib, xpm4g-dev, xpm-bin, xsm
1993Provides: xmodmap, xcontrib, xpm-bin, xsm
1994Depends: debconf (>= 0.3.83), cpp, libc6 (>= 2.2.1-2), libfreetype6, libgl1, libncurses5 (>= 5.2.20010310-1), libxaw7 (>= 4.0.1-1), xlibs (>= 4.0.1-11)
1995Conflicts: xbase (<< 3.3.2.3a-2), xserver-common (<< 3.3.2.3a-9), xmodmap, xaw-wrappers (<< 0.90), xfonts-100dpi (<< 3.3.3.1-3), xfonts-75dpi (<< 3.3.3.1-3), xfonts-base (<< 3.3.3.1-3), xfonts-cyrillic (<< 3.3.3.1-3), xfonts-scalable (<< 3.3.3.1-3), xfnt100 (<= 3.3.2.3a-1), xfnt75 (<= 3.3.2.3a-1), xfntbase (<= 3.3.2.3a-1), xfntcyr (<= 3.3.2.3a-1), xfntscl (<= 3.3.2.3a-1), xdm (<< 4.0), xsm, xcontrib, xpm4g-dev, xpm-bin
1996Filename: ./xbase-clients_4.0.2-13_arm.ipk
1997Size: 205512
1998MD5Sum: 60ff8d6dfa873abf4c0d611fff7d268c
1999Description: miscellaneous X clients
2000 An X client is a program that interfaces with an X server (almost always
2001 via the X libraries), and thus with some input and output hardware like a
2002 graphics card, monitor, keyboard, and pointing device (such as a mouse).
2003 .
2004 This package provides a miscellaneous assortment of several dozen X
2005 clients that ship with the X Window System, including:
2006 - startx and xinit, which initialize X sessions from the command line;
2007 - xauth, a tool for controlling access to the X session;
2008 - xedit, a text editor;
2009 - xbiff, a tool which tells you when you have new email;
2010 - xcalc, a scientific calculator desktop accessory;
2011 - xclipboard, a tool to manage cut-and-pasted text selections;
2012 - xcutsel, which exchanges selection and cut buffer contents;
2013 - xconsole, which monitors system console messages;
2014 - xditview, a viewer for ditroff output;
2015 - xeyes, a demo program in which a pair of eyes track the pointer;
2016 - xfd, a tool that displays all the glyphs in a given X font;
2017 - xfontsel, a tool for browsing and selecting X fonts;
2018 - xhost, a very dangerous program that you should never use;
2019 - xkill, a tool for terminating misbehaving X clients;
2020 - xload, a monitor for the system load average;
2021 - xlogo, a demo program that displays the X logo;
2022 - xmag, which magnifies parts of the X screen;
2023 - xman, a manual page browser;
2024 - xmessage, a tool to display message or dialog boxes;
2025 - xrefresh, a tool that forces a redraw of the X screen;
2026 - xsetroot, a tool for tailoring the appearance of the root window;
2027 - xvidtune, a tool for customizing X server modelines for your monitor;
2028 - xwd, a utility for taking window dumps ("screenshots") of the X session;
2029 - xwud, a viewer for window dumps created by xwd;
2030 - oclock and xclock, graphical clocks;
2031 - beforelight, a screen saver;
2032 - bitmap, a monochrome bitmap file editor;
2033 - bmtoa, a tool that converts a monochrome bitmap to ASCII text;
2034 - cxpm and sxpm, tools for checking and viewing X pixmap files;
2035 - iceauth, a tool for manipulating ICE protocol authorization records;
2036 - xset, a tool for setting miscellaneous X server parameters;
2037 - xmodmap, a utility for modifying keymaps and pointer button mappings in X;
2038 - xsetmode and xsetpointer, tools for handling X Input devices;
2039 - setxkbmap, xkbbell, xkbcomp, xkbevd, xkbprint, xkbvleds, and xkbwatch,
2040 tools for managing the X keyboard extension (XKB);
2041 - xsm, a session manager for X sessions;
2042 - smproxy, a session manager proxy for X clients that do not use the X
2043 session manager protocol;
2044 - xgamma, a tool for querying and setting a monitor's gamma correction;
2045 - appres, editres, listres, viewres, and xrdb, which query and update the
2046 X resource database;
2047 - Xmark, x11perf, x11perfcomp, and xieperf, tools for benchmarking
2048 graphical operations under the X Window System;
2049 - fstobdf, which retrieves a font in BDF format from an X font server;
2050 - xcmsdb, a device color characteristic utility for the X Color Management
2051 System;
2052 - xstdcmap, a utility to selectively define standard colormap properties;
2053 - xev, an X event displayer;
2054 - xfindproxy, a tool to locate X proxy services;
2055 - xlsatoms, which lists interned atoms defined on an X server;
2056 - xlsclients, which lists client applications running on an X display;
2057 - xlsfonts, a server font list displayer;
2058 - xprop, a property displayer for X;
2059 - xdpyinfo, a display information utility for X;
2060 - xwininfo, a window information utility for X;
2061 - glxinfo, a GLX extension information utility for X;
2062 - xvinfo, an Xv extension information utility for X;
2063 - ico, an X graphics demo using an animated polyhedron;
2064 - dga, a demo program for the DGA extension; and
2065 - xgc, an (unfinished) X graphics demo program.
2066
2067Package: xcalibrate
2068Priority: optional
2069Version: 0.0
2070Architecture: arm
2071Maintainer: Carl Worth <cworth@handhelds.org>
2072Depends: libc6, xlibs
2073Filename: ./xcalibrate_0.0_arm.ipk
2074Size: 6641
2075MD5Sum: 1ff1b7f86d9ee3c4f9d261d6c69059be
2076Description: calibrate the iPAQ H3600 touch screen for X
2077
2078Package: xfonts-75dpi
2079Priority: optional
2080Section: x11
2081Installed-Size: 2912
2082Debian-Maintainer: Branden Robinson <branden@debian.org>
2083Maintainer: Carl Worth <cworth@handhelds.org>
2084Architecture: all
2085Source: xfree86
2086Version: 4.0.2-13
2087Replaces: xfnt75
2088Provides: xfnt75
2089Depends: xutils
2090Suggests: xfs | xserver
2091Conflicts: xfnt75, xbase-clients (<< 4.0)
2092Filename: ./xfonts-75dpi_4.0.2-13_all.ipk
2093Size: 173134
2094MD5Sum: b99622fecd62b08624fd4c0977b61cfd
2095Description: 75 dpi fonts for X
2096 xfonts-75dpi provides a set of bitmapped fonts at 75 dots per inch. In most
2097 cases it is desirable to have the X font server (xfs) and/or an X server
2098 installed to make the fonts available to X clients.
2099 .
2100 This package and xfonts-100dpi provide the same set of fonts, rendered at
2101 different resolutions; only one or the other is necessary, but both may be
2102 installed. xfonts-75dpi may be more suitable for small monitors and/or small
2103 screen resolutions (under 1024x768).
2104 .
2105 This package requires the xutils package to prepare the font directories
2106 for use by an X server or X font server.
2107
2108Package: xfonts-base
2109Priority: optional
2110Section: x11
2111Installed-Size: 7724
2112Debian-Maintainer: Branden Robinson <branden@debian.org>
2113Maintainer: Carl Worth <cworth@handhelds.org>
2114Architecture: all
2115Source: xfree86
2116Version: 4.0.2-13
2117Replaces: xfntbase, xfonts-cjk
2118Provides: xfntbase, xfonts-cjk
2119Depends: xutils
2120Suggests: xfs, xserver
2121Conflicts: xfntbase, xfonts-cjk, xbase-clients (<< 4.0)
2122Filename: ./xfonts-base_4.0.2-13_all.ipk
2123Size: 24879
2124MD5Sum: 26837af24947d47947962450480e9258
2125Description: standard fonts for X
2126 xfonts-base provides a standard set of low-resolution bitmapped fonts. In
2127 most cases it is desirable to have the X font server (xfs) and/or an X server
2128 installed to make the fonts available to X clients.
2129 .
2130 If you are not using a remote font server, you must install this package if
2131 you are installing an X server. It contains fonts without which X servers
2132 will not work.
2133 .
2134 This package also provides a set of files that can be used by the X or
2135 fonts server to transcode fonts from one encoding to another (e.g., KOI8-R
2136 to ISO-8859-5).
2137 .
2138 This package requires the xutils package to prepare the font directories
2139 for use by an X server or X font server.
2140
2141Package: xfonts-ttf
2142Priority: optional
2143Version: 0.0
2144Architecture: all
2145Maintainer: Carl Worth <cworth@handhelds.org>
2146Depends: xutils
2147Filename: ./xfonts-ttf_0.0_all.ipk
2148Size: 15567
2149MD5Sum: ec6912955eda9edf873f892677fae523
2150Description: free TrueType fonts to be used within X
2151
2152Package: xlibs
2153Priority: optional
2154Section: libs
2155Installed-Size: 4306
2156Debian-Maintainer: Branden Robinson <branden@debian.org>
2157Maintainer: Carl Worth <cworth@handhelds.org>
2158Architecture: arm
2159Source: xfree86
2160Version: 4.0.2-13
2161Replaces: xlib, xbase (<< 3.3.2.3a-2), xlib6 (<< 3.3.2.3-2), xbase-clients (<< 4.0), xlib6g (<< 4.0), xlib6g-dev (<< 4.0), xpm4g, fvwm-common, xcontrib
2162Provides: libxpm4
2163Depends: xfree86-common (>> 4.0), libc6 (>= 2.2.1-2), xlibs (>= 4.0.1-11)
2164Conflicts: xlib, xlib6 (<< 3.3.2.3-2), xlib6g (<< 4.0), xlib6g-dev (<< 4.0), xbase-clients (<< 4.0), xpm4g
2165Filename: ./xlibs_4.0.2-13_arm.ipk
2166Size: 820973
2167MD5Sum: ad9b6742385277d8cf63cfcdde41d4dc
2168Description: X Window System client libraries
2169 NOTE: I really want to break this package up into lots of little
2170 packages for familiar, (mainly so we can dump things like Xt if no
2171 binaries depend on them). - Carl Worth <cworth@handhelds.org>
2172 .
2173 The X libraries are an interface between X client programs and the
2174 hardware-oriented X servers, and consist of routines to read input from the
2175 keyboard and pointer, draw on the screen, etc., in an abstract manner that is
2176 independent of the particular characteristics of the hardware. The X
2177 libraries, and the programs that use them, communicate with X servers by
2178 means of the X protocol.
2179 .
2180 libX11 (a.k.a. Xlib) provides the low-level functionality, dealing mostly
2181 with the wire protocol and in terms of basic operations such as opening and
2182 closing the X protocol connection, creating graphics contexts, drawing
2183 graphics primitives such as lines, arcs, and glyphs, handling events, and so
2184 forth.
2185 .
2186 libXpm, the X pixmap library, is a set of routines used to store and retrieve
2187 X pixmaps (a data structure comprising a rectangular array of pixels) from
2188 files; the xpm file format is an extension of the monochrome bitmap file
2189 format in the X11 specification. (Traditionally, libXpm was maintained and
2190 distributed separately from the X Window System, but XFree86 has absorbed
2191 this library).
2192 .
2193 libXt, the X Toolkit Instrinsics, is an abstract widget library upon which
2194 graphical widget libraries (such as Athena and LessTif) may be developed; the
2195 Intrinsics provide a number of useful interfaces to X conventions and
2196 protocols, in many cases reducing a long series of Xlib calls to just a
2197 couple of Xt calls.
2198 .
2199 libXmu is a set of miscellaneous utility functions useful to client
2200 programmers.
2201 .
2202 The remainder of the libraries in this package implement the client side
2203 of various X protocol extensions:
2204 - libICE, the Inter-Client Exchange extension;
2205 - libPEX5, PEX, a 3D graphics extension now superseded by Mesa/OpenGL;
2206 - libSM, the Session Management extension;
2207 - libXIE, the X Image Extension;
2208 - libXext, a collection of several commonly-used extensions;
2209 - libXi, the X Input extension;
2210 - libXp, the X Printing extension; and
2211 - libXtst, the X Testing extension.
2212 .
2213 xlibs also contains the XKB keyboard parameter files, locale data, and a set
2214 of bitmap and pixmap image files commonly used by X clients.
2215
2216Package: xserver-tiny-h3600
2217Priority: optional
2218Version: 0.2
2219Architecture: arm
2220Maintainer: Alexander Guy <a7r@handhelds.org>
2221Depends: libc6, zlib1g, h3600-utils
2222Filename: ./xserver-tiny-h3600_0.2_arm.ipk
2223Size: 405916
2224MD5Sum: dbbc661d81cec5a8ac402ebbfd682c4d
2225Description: X server for the iPAQ H3600 display and touchscreen.
2226
2227Package: xvkbd
2228Priority: optional
2229Version: 0.0
2230Architecture: arm
2231Maintainer: Carl Worth <cworth@handhelds.org>
2232Depends: libc6, xlibs, libxaw6
2233Filename: ./xvkbd_0.0_arm.ipk
2234Size: 13591
2235MD5Sum: 45cd39eebf02283965268bbba5436528
2236Description: On-screen virtual keyboard for X
2237
2238Package: zlib1g
2239Priority: standard
2240Section: libs
2241Installed-Size: 144
2242Debian-Maintainer: Mark Brown <broonie@debian.org>
2243Maintainer: Carl Worth <cworth@handhelds.org>
2244Architecture: arm
2245Source: zlib
2246Version: 1:1.1.3-14
2247Provides: libz1
2248Depends: libc6 (>= 2.2.1-2)
2249Conflicts: zlib1 (<= 1:1.0.4-7)
2250Filename: ./zlib1g_1.1.3-14_arm.ipk
2251Size: 28970
2252MD5Sum: c7f98957d73220efb3e39ec75ac09c23
2253Description: compression library - runtime
2254 zlib is a library implementing the deflate compression method found
2255 in gzip and pkzip. This package includes the shared library.
2256
diff --git a/noncore/unsupported/oipkg/ipkg/status b/noncore/unsupported/oipkg/ipkg/status
new file mode 100644
index 0000000..ddcd5fa
--- a/dev/null
+++ b/noncore/unsupported/oipkg/ipkg/status
@@ -0,0 +1,418 @@
1Package: ash
2Status: install ok installed
3Essential: yes
4Version: 0.3.7-16
5
6Package: libc6
7Status: install ok installed
8Version: 2.2.2-1
9
10Package: debianutils
11Status: install ok installed
12Essential: yes
13Version: 1.15
14
15Package: dev-files
16Status: install ok installed
17Essential: yes
18Version: 0.4
19
20Package: dpkg
21Status: install ok installed
22Essential: yes
23Version: 1.8.3.1
24
25Package: libncurses5
26Status: install ok installed
27Version: 5.0-6.0potato1
28
29Package: libstdc++2.10-glibc2.2
30Status: install ok installed
31Version: 1:2.95.4-0.010407
32
33Package: e2fsprogs
34Status: install ok installed
35Version: 1.19-4
36
37Package: ncurses-base
38Status: install ok installed
39Conffiles: /etc/terminfo/a/ansi 6b60f35a7fb6122a53b1e74e56cba56e /etc/terminfo/d/dumb ca3b114f0727da81a9b957b553a9915d /etc/terminfo/l/linux 8d94e8037f878a0468b4a29a28e83933 /etc/terminfo/m/mach 215cacd84662e9e93e998833477da362 /etc/terminfo/m/mach-bold 2dfb5dc3b706cd29273ab25f20394ac8 /etc/terminfo/m/mach-color a4b356122e490897b411db4893c8483e /etc/terminfo/p/pcansi 8b97f1ea94e8d2942c8dcd2d943e1322 /etc/terminfo/r/rxvt 5fb0eff2f9d74b42ab9bf6532ae4b54b /etc/terminfo/r/rxvt-m fd21b1fd19f15558368fbfaca40c92ce /etc/terminfo/s/screen e6c11d68d1b4d1d754fd1024d7970251 /etc/terminfo/s/screen-w df1678735733b574d38d6dc08991b372 /etc/terminfo/s/sun c7ab8d7ab013eca15c6eb83a4c80a3d1 /etc/terminfo/v/vt100 ad245bbce8921ee045952390f57fae39 /etc/terminfo/v/vt102 c33de92a31aa93532f323d7b604f2060 /etc/terminfo/v/vt220 fb1504db6c5a5962d65c1e59ec3ee331 /etc/terminfo/v/vt52 2cfdf4dcc4a93c378d9c6bc01cb8f3c3 /etc/terminfo/x/xterm 8b85646c0ec7d05772e8893a0fe6c587 /etc/terminfo/x/xterm-color 582138668da3b0f586aeee0dab85ce64 /etc/terminfo/x/xterm-mono 894041962a58eb2c22ab75a510bfb9c8 /etc/terminfo/x/xterm-r5 edae3c5c9da23b6358a7362492fd17e8 /etc/terminfo/x/xterm-r6 ba7d833b34aa46016660e577c81644b2 /etc/terminfo/x/xterm-vt220 f7ee9373c6df206ee9b5f674a8748272 /etc/terminfo/x/xterm-xfree86 e3e10164f2a536129beeae0b1070513d
40Version: 5.2.20010318-1
41
42Package: fileutils
43Status: install ok installed
44Essential: yes
45Version: 4.0.43-1
46
47Package: grep
48Status: install ok installed
49Essential: yes
50Version: 2.4.2-1
51
52Package: gzip
53Status: install ok installed
54Essential: yes
55Version: 1.2.4-33
56
57Package: hostname
58Status: install ok installed
59Essential: yes
60Version: 2.07
61
62Package: sed
63Status: install ok installed
64Version: 3.02-6
65
66Package: urlget
67Status: install ok installed
68Version: 0.3
69
70Package: netbase
71Status: install ok installed
72Conffiles: /etc/init.d/networking e9ecbce88a3f5a296a216298e282270e /etc/protocols 9b4c76b625771acc5c8df17b3ed780bc /etc/services 1f73acd0620a72c63f34c14dff83774d
73Version: 4.05
74
75Package: ifupdown
76Status: install ok installed
77Version: 0.6.4-3
78
79Package: libpam-modules
80Status: install ok installed
81Version: 0.72-21
82
83Package: libpam0g
84Status: install ok installed
85Version: 0.72-21
86
87Package: net-tools
88Status: install ok installed
89Version: 1.59-1
90
91Package: netkit-ping
92Status: install ok installed
93Version: 0.10-6.1
94
95Package: libpam-runtime
96Status: install ok installed
97Conffiles: /etc/pam.conf c29f5bbea9887ff059b5973185c82212 /etc/pam.d/other 1ec5167fb7299a6b6b55b31c29a8b303
98Version: 0.72-21
99
100Package: modutils
101Status: install ok installed
102Conffiles: /etc/cron.daily/modutils 10fc6b90de70ffa3594d6c47ec9be935 /etc/init.d/modutils 0a8547ed5c4d6d98b729fa5a2603e7f4
103Version: 2.4.2-1
104
105Package: lrzsz
106Status: install ok installed
107Essential: yes
108Version: 0.12.21-4
109
110Package: mount
111Status: install ok installed
112Essential: yes
113Version: 2.11b-2
114
115Package: shellutils
116Status: install ok installed
117Essential: yes
118Version: 2.0.11-5
119
120Package: sysvinit
121Status: install ok installed
122Conffiles: /etc/init.d/bootmisc.sh e9418a2ae63ae39f02b3e4c32290b19d /etc/init.d/checkfs.sh 10e539a025742a6288f60651ae7613a1 /etc/init.d/checkroot.sh b73e84b9518933e9ea1195f9f707d24d /etc/init.d/halt 031ddd15603637361bca220953f21a55 /etc/init.d/hostname.sh cacd9a754d39665499db7f79dac4e212 /etc/init.d/mountall.sh ba7702a69890a12e91e7ea259c71150e /etc/init.d/reboot aff6c76c29e8daa1f7c47479024d51b2 /etc/init.d/rmnologin f84dc015574ab0e48fb0694dc70307b2 /etc/init.d/sendsigs 8c66184b264a2d86c18f34fff627b49f /etc/init.d/single 68031365ba0ce859ec96e5cc812c6d07 /etc/init.d/umountfs 1f2a624a32fee66cc5654261942aa6bb
123Essential: yes
124Version: 2.78-4
125
126Package: tar
127Status: install ok installed
128Essential: yes
129Version: 1.13.19-1
130
131Package: textutils
132Status: install ok installed
133Essential: yes
134Version: 2.0-3
135
136Package: task-bootstrap
137Status: install ok installed
138Version: 0.6
139
140Package: ppp
141Status: install ok installed
142Conffiles: /etc/ppp/options e85cc881e702d2f022e56fa48a877295
143Version: 2.4.0f-1
144
145Package: pump
146Status: install ok installed
147Version: 0.8.3-3
148
149Package: ssh
150Status: install ok installed
151Version: 1:2.5.2p2-2
152
153Package: wireless-tools
154Status: install ok installed
155Version: 20-1.1
156
157Package: libssl0.9.6
158Status: install ok installed
159Version: 0.9.6a-1
160
161Package: libwrap0
162Status: install ok installed
163Version: 7.6-7
164
165Package: zlib1g
166Status: install ok installed
167Version: 1:1.1.3-14
168
169Package: ntpdate
170Status: install ok installed
171Version: 1:4.0.99g-3
172
173Package: wget
174Status: install ok installed
175Version: 1.6-2
176
177Package: task-familiar-complete
178Status: install ok installed
179Version: 0.5
180
181Package: apmd
182Status: install ok installed
183Version: 3.0final-1
184
185Package: checkers
186Status: install ok installed
187Version: 0.0
188
189Package: dosfstools
190Status: install ok installed
191Version: 2.8-1
192
193Package: fscrib
194Status: install ok installed
195Version: 0.0
196
197Package: h3600-utils
198Status: install ok installed
199Version: 0.4
200
201Package: libglade0
202Status: install ok installed
203Version: 0.16-2
204
205Package: libpopt0
206Status: install ok installed
207Version: 1.5-0.1
208
209Package: libxaw6
210Status: install ok installed
211Version: 4.0.2-13
212
213Package: libxml1
214Status: install ok installed
215Version: 1:1.8.11-1
216
217Package: libxmltok1
218Status: install ok installed
219Version: 1.1-5
220
221Package: loadmeter
222Status: install ok installed
223Version: 0.0
224
225Package: netcat
226Status: install ok installed
227Version: 1.10-17
228
229Package: procps
230Status: install ok installed
231Version: 1:2.0.7-4
232
233Package: pyditor
234Status: install ok installed
235Version: 0.0
236
237Package: qiv
238Status: install ok installed
239Version: 1.6-1
240
241Package: rsync
242Status: install ok installed
243Version: 2.4.6-1
244
245Package: sysset
246Status: install ok installed
247Version: 0.0
248
249Package: task-games
250Status: install ok installed
251Version: 0.0
252
253Package: task-mp3-player
254Status: install ok installed
255Version: 0.0
256
257Package: task-wireless
258Status: install ok installed
259Version: 0.1
260
261Package: task-x
262Status: install ok installed
263Version: 0.0
264
265Package: xvkbd
266Status: install ok installed
267Version: 0.0
268
269Package: gdk-imlib1
270Status: install ok installed
271Version: 1.9.8.1-2
272
273Package: libfltk1
274Status: install ok installed
275Version: 1.0.9-1.1
276
277Package: libfreetype6
278Status: install ok installed
279Version: 2.0.1.20010317-1
280
281Package: libglib1.2
282Status: install ok installed
283Version: 1.2.10-1
284
285Package: libgtk1.2
286Status: install ok installed
287Version: 1.2.10-1
288
289Package: libxaw7
290Status: install ok installed
291Version: 4.0.2-13
292
293Package: madplay
294Status: install ok installed
295Version: 0.0
296
297Package: mixer
298Status: install ok installed
299Version: 0.0
300
301Package: python
302Status: install ok installed
303Version: 0.0
304
305Package: rxvt-aa
306Status: install ok installed
307Version: 1:2.6.3-8
308
309Package: xbase-clients
310Status: install ok installed
311Version: 4.0.2-13
312
313Package: xcalibrate
314Status: install ok installed
315Version: 0.0
316
317Package: xfonts-75dpi
318Status: install ok installed
319Version: 4.0.2-13
320
321Package: xfonts-base
322Status: install ok installed
323Version: 4.0.2-13
324
325Package: xfonts-ttf
326Status: install ok installed
327Version: 0.0
328
329Package: xlibs
330Status: install ok installed
331Version: 4.0.2-13
332
333Package: libdb2
334Status: install ok installed
335Version: 2:2.7.7-3
336
337Package: libjpeg62
338Status: install ok installed
339Version: 6b-1.3
340
341Package: libpng2
342Status: install ok installed
343Version: 1.0.8-1
344
345Package: libungif3g
346Status: install ok installed
347Version: 3.0-3
348
349Package: libxft
350Status: install ok installed
351Version: 0.0
352
353Package: libxrender
354Status: install ok installed
355Version: 0.0
356
357Package: stowaway-h3600
358Status: install ok installed
359Version: 1.0
360
361Package: bash
362Status: install ok installed
363Conffiles: /etc/bash.bashrc 21e4f76f5390e221909e0afaaa41d8ab
364Version: 2.03-6
365
366Package: less
367Status: install ok installed
368Version: 346-7
369
370Package: login
371Status: install ok installed
372Conffiles: /etc/login.defs ef80f19ce81f9fab26602d8398c1b46f
373Essential: yes
374Version: 20000902-3.1
375
376Package: familiar-base
377Status: install ok installed
378Essential: yes
379Version: 0.10
380
381Package: kernel-modules-2.4.3-rmk2-np1
382Status: install ok installed
383Essential: yes
384Version: fam3
385
386Package: util-linux
387Status: install ok installed
388Essential: yes
389Version: 2.11b-2-fam2
390
391Package: pcmcia-modules-2.4.3-rmk2-np1
392Status: install ok installed
393Version: fam3
394
395Package: pcmcia-cs
396Status: install ok installed
397Conffiles: /etc/init.d/pcmcia 2aec30c50530a70e9b530bbe83106062 /etc/pcmcia/cis/3CCFEM556.dat 064309527ab5c6f73f17f99f6b07e471 /etc/pcmcia/cis/3CXEM556.dat 51e99ef0d234ea1b455b0555336f7379 /etc/pcmcia/cis/COMpad2.dat 66748ecad364a24ea2150fccb1adbca0 /etc/pcmcia/cis/COMpad4.dat a1b4e46b220b7ecaec0287875f47e549 /etc/pcmcia/cis/DP83903.dat fb612f42364fd06c46aa936386a79abb /etc/pcmcia/cis/E-CARD.dat 3bd542b30f74fb6066b045436e0c70c6 /etc/pcmcia/cis/LA-PCM.dat bee381e5d148bd073184a5cadfb6c314 /etc/pcmcia/cis/MT5634ZLX.dat 15bc79fe185e6cc00c888ab6e54a0640 /etc/pcmcia/cis/NE2K.dat f6092c8b414a94b96e310654cc5cad04 /etc/pcmcia/cis/PCMLM28.dat bc1d913acfd5b8b70a6694bbd48b5795 /etc/pcmcia/cis/PE-200.dat b779b33a4a692557517a3e6edf343fb2 /etc/pcmcia/cis/PE520.dat fb7b7e2d7664771f0c4a1a39cc2efabf /etc/pcmcia/cis/RS-COM-2P.dat c9dd2f55d05d86f88cdf52f3e1363da2 /etc/pcmcia/config.opts 03b1242472171887224f92ca95ecd40d /etc/pcmcia/config 9f747a17417cfecd7d08f5ddab34935d /etc/pcmcia/ftl.opts c6e0cd4d69e56836a6ff071bba8df4c3 /etc/pcmcia/ftl af805fd6a57f77ace864fe24643a39ed /etc/pcmcia/ide.opts 98f615befe89350382037398ef6cd226 /etc/pcmcia/ide fad802a1eb4cc57656a5dcae090edbb1 /etc/pcmcia/memory.opts bd8486017c46fef68ac2ecf597c8e31b /etc/pcmcia/memory a7a7acf0fa3ea00613ed2649e6b59e8b /etc/pcmcia/network.opts a40e80fb3366f61c8839973f5418e35f /etc/pcmcia/network e4b3d221d57efe4a714fdd5eb5c49224 /etc/pcmcia/parport.opts d7a128b7352b136d60935fca3638a4f6 /etc/pcmcia/parport 89041f80c218454b68c1c0581e29b872 /etc/pcmcia/scsi.opts 6c45330bd15b2db612d1d12d5682face /etc/pcmcia/scsi 983fa0c4829c79222e3f01d690c52897 /etc/pcmcia/serial.opts e26bbd1e4e70571277def2bcac82767e /etc/pcmcia/serial f7f7b6b24f55e7317d684d7f36c6e1f5 /etc/pcmcia/wireless.opts 002a763100acd3ddbd0e1c8283418907 /etc/pcmcia/wireless 64e6cbc2d2fda6b191390536ede71b67 /etc/pcmcia/shared 8b9f0c58f3b9daa43572e5087e97032b
398Version: 0.0-fam3
399
400Package: ipkg
401Status: install ok installed
402Conffiles: /etc/ipkg.conf 5f2dff89026c95afe68ca28b5385525b
403Essential: yes
404Version: 0.4-fam1
405
406Package: blackbox
407Status: install ok installed
408Version: 0.1
409
410Package: xserver-tiny-h3600
411Status: install ok installed
412Version: 0.2
413
414Package: iv
415Status: install ok installed
416Essential: yes
417Version: 0.0
418
diff --git a/noncore/unsupported/oipkg/main.cpp b/noncore/unsupported/oipkg/main.cpp
new file mode 100644
index 0000000..96a5e8d
--- a/dev/null
+++ b/noncore/unsupported/oipkg/main.cpp
@@ -0,0 +1,33 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "packagemanager.h"
22
23#include <qpe/qpeapplication.h>
24
25int main( int argc, char ** argv )
26{
27 QPEApplication a( argc, argv );
28
29 PackageManager mw;
30 a.showMainDocumentWidget( &mw );
31
32 return a.exec();
33}
diff --git a/noncore/unsupported/oipkg/packagemanager.cpp b/noncore/unsupported/oipkg/packagemanager.cpp
new file mode 100644
index 0000000..f3da15d
--- a/dev/null
+++ b/noncore/unsupported/oipkg/packagemanager.cpp
@@ -0,0 +1,897 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "packagemanager.h"
21#include "pkdesc.h"
22#include "pkfind.h"
23#include "pksettings.h"
24
25#include <qpe/process.h>
26#include <qpe/resource.h>
27#include <qpe/stringutil.h>
28#include <qpe/qpeapplication.h>
29#include <qpe/qcopenvelope_qws.h>
30#include <qpe/applnk.h>
31
32#include <qprogressbar.h>
33#include <qcombobox.h>
34#include <qdict.h>
35#include <qfile.h>
36#include <qlineedit.h>
37#include <qpushbutton.h>
38#include <qlistview.h>
39#include <qlistbox.h>
40#include <qmessagebox.h>
41#include <qpainter.h>
42#include <qpixmap.h>
43#include <qregexp.h>
44#include <qtextstream.h>
45#include <qtextview.h>
46#include <qtoolbutton.h>
47
48#include <stdlib.h>
49
50static QPixmap *pm_uninstalled=0;
51static QPixmap *pm_installed=0;
52static QPixmap *pm_uninstall=0;
53static QPixmap *pm_install=0;
54
55
56class PackageItem : public QCheckListItem {
57 bool installed;
58public:
59 PackageItem(QListView* lv, const QString& name, const QString& desc, const QString& size, bool inst ) :
60 QCheckListItem(lv,name,CheckBox), installed(inst)
61 {
62 setText(1,desc);
63 setText(2,size);
64 }
65
66 void paintCell( QPainter *p, const QColorGroup & cg,
67 int column, int width, int alignment )
68 {
69 if ( !p )
70 return;
71
72 p->fillRect( 0, 0, width, height(),
73 isSelected()? cg.highlight() : cg.base() );
74
75 if ( column != 0 ) {
76 // The rest is text
77 QListViewItem::paintCell( p, cg, column, width, alignment );
78 return;
79 }
80
81 QListView *lv = listView();
82 if ( !lv )
83 return;
84 int marg = lv->itemMargin();
85 int r = marg;
86
87 QPixmap pm = statePixmap();
88 p->drawPixmap(marg,(height()-pm.height())/2,pm);
89 r += pm.width()+1;
90
91 p->translate( r, 0 );
92 QListViewItem::paintCell( p, cg, column, width - r, alignment );
93 }
94
95 void paintFocus( QPainter *p, const QColorGroup & cg,
96 const QRect & r )
97 {
98 // Skip QCheckListItem
99 // (makes you wonder what we're getting from QCheckListItem)
100 QListViewItem::paintFocus(p,cg,r);
101 }
102
103 QPixmap statePixmap() const
104 {
105 if ( !isOn() ) {
106 if ( !installed )
107 return *pm_uninstalled;
108 else
109 return *pm_installed;
110 } else {
111 if ( !installed )
112 return *pm_install;
113 else
114 return *pm_uninstall;
115 }
116 }
117
118 QString name() const { return text(0); }
119 QString description() const { return text(1); }
120 bool isInstalled() const { return installed; }
121
122 QString key( int column, bool ascending ) const
123 {
124 if ( column == 2 ) {
125 QString t = text(2);
126 double bytes=t.toDouble();
127 if ( t.contains('M') ) bytes*=1024*1024;
128 else if ( t.contains('K') || t.contains('k') ) bytes*=1024;
129 if ( !ascending ) bytes=999999999-bytes;
130 return QString().sprintf("%09d",(int)bytes);
131 } else {
132 return QListViewItem::key(column,ascending);
133 }
134 }
135};
136
137/*
138 * Constructs a PackageManager which is a child of 'parent', with the
139 * name 'name' and widget flags set to 'f'
140 */
141PackageManager::PackageManager( QWidget* parent, const char* name, WFlags fl )
142 : PackageManagerBase( parent, name, fl )
143{
144 settings = new PackageManagerSettings(this,0,TRUE);
145 connect( settings->newserver, SIGNAL(clicked()), this, SLOT(newServer()) );
146 connect( settings->removeserver, SIGNAL(clicked()), this, SLOT(removeServer()) );
147 connect( settings->servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) );
148 connect( doit, SIGNAL(clicked()), this, SLOT(doIt()) );
149 settings->servername->setEnabled(FALSE);
150 settings->serverurl->setEnabled(FALSE);
151 serverurl.setAutoDelete(TRUE);
152
153 if (!pm_uninstalled) {
154 pm_uninstalled = new QPixmap(Resource::loadPixmap("uninstalled"));
155 pm_installed = new QPixmap(Resource::loadPixmap("installed"));
156 pm_install = new QPixmap(Resource::loadPixmap("install"));
157 pm_uninstall = new QPixmap(Resource::loadPixmap("uninstall"));
158 }
159
160 QFontMetrics fm = fontMetrics();
161 int w0 = fm.width(PackageManagerBase::tr("Package"))+30;
162 int w2 = fm.width("00000")+4;
163 list->setColumnWidth(0,w0);
164 list->setColumnWidth(1,228-w2-w0); // ### screen-biased
165 list->setColumnWidth(2,w2);
166 list->setColumnWidthMode(0,QListView::Manual);
167 list->setColumnWidthMode(1,QListView::Manual);
168 list->setColumnWidthMode(2,QListView::Manual);
169 list->setSelectionMode( QListView::Multi );
170 details = 0;
171 ipkg_old = 0;
172 readSettings();
173 updatePackageList();
174 progress->hide();
175}
176
177
178/*
179 * Destroys the object and frees any allocated resources
180 */
181PackageManager::~PackageManager()
182{
183 // no need to delete child widgets, Qt does it all for us
184}
185
186void PackageManager::newServer()
187{
188 int i = settings->servers->count();
189 if ( settings->servername->isEnabled() || settings->serverurl->text().isEmpty() ) {
190 serverurl.insert(i,new QString("http://"));
191 settings->servers->insertItem(tr("New"));
192 } else {
193 // allows one-level undo
194 serverurl.insert(i,new QString(settings->serverurl->text()));
195 settings->servers->insertItem(settings->servername->text());
196 }
197 settings->servers->setSelected(i,TRUE);
198 editServer(i);
199}
200
201void PackageManager::editServer(int i)
202{
203 if ( settings->servername->isEnabled() ) {
204 disconnect( settings->servername, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)) );
205 disconnect( settings->serverurl, SIGNAL(textChanged(const QString&)), this, SLOT(urlChanged(const QString&)) );
206 } else {
207 settings->servername->setEnabled(TRUE);
208 settings->serverurl->setEnabled(TRUE);
209 }
210
211 settings->servername->setText( settings->servers->text(i) );
212 settings->serverurl->setText( *serverurl[i] );
213
214 editedserver = i;
215
216 connect( settings->servername, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)) );
217 connect( settings->serverurl, SIGNAL(textChanged(const QString&)), this, SLOT(urlChanged(const QString&)) );
218}
219
220void PackageManager::removeServer()
221{
222 disconnect( settings->servername, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)) );
223 disconnect( settings->serverurl, SIGNAL(textChanged(const QString&)), this, SLOT(urlChanged(const QString&)) );
224 settings->servername->setText(settings->servers->text(editedserver));
225 settings->serverurl->setText(*serverurl[editedserver]);
226 disconnect( settings->servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) );
227 settings->servers->removeItem(editedserver);
228 connect( settings->servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) );
229 settings->servername->setEnabled(FALSE);
230 settings->serverurl->setEnabled(FALSE);
231}
232
233void PackageManager::nameChanged(const QString& t)
234{
235 disconnect( settings->servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) );
236 settings->servers->changeItem( t, editedserver );
237 connect( settings->servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) );
238}
239
240void PackageManager::urlChanged(const QString& t)
241{
242 serverurl.replace(editedserver, new QString(t));
243}
244
245static void selectComboItem(QComboBox *cb, const QString s)
246{
247 for (int i=0; i<cb->count(); i++) {
248 if ( cb->text(i) == s ) {
249 cb->setCurrentItem(i);
250 return;
251 }
252 }
253}
254
255void PackageManager::updatePackageList()
256{
257 disconnect(section,SIGNAL(activated(int)),this,SLOT(updatePackageList()));
258 disconnect(subsection,SIGNAL(activated(int)),this,SLOT(updatePackageList()));
259
260 list->clear();
261 QString cursection = section->currentText();
262 QString cursubsection = subsection->currentText();
263 QString all=tr("All");
264 if ( cursection == all ) cursection=QString::null;
265 if ( cursubsection == all ) cursubsection=QString::null;
266 section->clear();
267 subsection->clear();
268
269 QDict<void> sections;
270 QDict<void> subsections;
271 QDict<void> installed;
272
273 QRegExp separatorRegExp( ":[\t ]+" );
274
275 QString status = ipkgStatusOutput();
276 if ( !status.isEmpty() ) {
277 QStringList lines = QStringList::split('\n',status,TRUE);
278 QString name;
279 QString status;
280 for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) {
281 QString line = *it;
282 if ( line.length()<=1 ) {
283 // EOR
284 if ( !name.isEmpty() ) {
285 if ( status.contains(" installed") )
286 installed.replace(name,(void*)1);
287 name="";
288 }
289 status="";
290 } else if ( line[0] == ' ' || line[0] == '\t' ) {
291 // continuation
292 } else {
293 int sep = line.find(separatorRegExp);
294 if ( sep >= 0 ) {
295 QString tag = line.left(sep);
296 if ( tag == "Package" ) {
297 name = line.mid(sep+2).simplifyWhiteSpace();
298 } else if ( tag == "Status" ) {
299 status = line.mid(sep+1);
300 }
301 }
302 }
303 }
304 }
305
306 QString info = ipkgInfoOutput();
307 if ( !info.isEmpty() ) {
308 QStringList lines = QStringList::split('\n',info,TRUE);
309 QString description_short;
310 QString name;
311 QString size;
312 QString sec;
313 for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) {
314 QString line = *it;
315 if ( line.length()<=1 ) {
316 // EOR
317 if ( !name.isEmpty() ) {
318 int sl = sec.find('/');
319 QString s = sl < 0 ? sec : sec.left(sl);
320 QString ss = sl < 0 ? QString::null : sec.mid(sl+1);
321 sections.replace(s,(void*)1);
322 if ( cursection.isNull()
323 || cursection == s
324 && (cursubsection.isNull() || cursubsection == ss) )
325 {
326 if ( !cursection.isNull() && !ss.isNull() )
327 subsections.replace(ss,(void*)1);
328 description_short[0] = description_short[0].upper();
329 if ( description_short.left(4) == "The " )
330 description_short = description_short.mid(4);
331 if ( description_short.left(2) == "A " )
332 description_short = description_short.mid(2);
333 description_short[0] = description_short[0].upper();
334 new PackageItem(list,name,description_short,size,
335 installed.find(name));
336 }
337 installed.remove( name );
338 }
339 name="";
340 size="";
341 sec="main";
342 } else if ( line[0] == ' ' || line[0] == '\t' ) {
343 // continuation
344 } else {
345 int sep = line.find(separatorRegExp);
346 if ( sep >= 0 ) {
347 QString tag = line.left(sep);
348 if ( tag == "Package" ) {
349 name = line.mid(sep+2).simplifyWhiteSpace();
350 } else if ( tag == "Description" ) {
351 description_short = line.mid(sep+2).simplifyWhiteSpace();
352 } else if ( tag == "Installed-Size" ) {
353 size = line.mid(sep+2).simplifyWhiteSpace();
354 } else if ( tag == "Section" ) {
355 sec = line.mid(sep+2).simplifyWhiteSpace();
356 }
357 }
358 }
359 }
360 if ( installed.count() && cursection.isNull() ) {
361 // we have some packages without description
362 QDictIterator<void> it( installed );
363 for( ; it.current(); ++it )
364 new PackageItem( list, it.currentKey(), "", "?" , TRUE );
365 }
366
367 QStringList s;
368 QDictIterator<void> it( sections );
369 for( ; it.current(); ++it )
370 s.append(it.currentKey());
371 s.sort();
372 section->insertItem(all);
373 section->insertStringList(s);
374 selectComboItem(section,cursection.isNull()?all:cursection);
375 if ( cursection.isNull() ) {
376 subsection->setEnabled(FALSE);
377 } else {
378 subsection->setEnabled(TRUE);
379 QStringList s;
380 QDictIterator<void> it( subsections );
381 for( ; it.current(); ++it )
382 s.append(it.currentKey());
383 s.sort();
384 subsection->insertItem(all);
385 subsection->insertStringList(s);
386 selectComboItem(subsection,cursubsection.isNull()?all:cursubsection);
387 }
388 } else {
389 new QListViewItem(list,"ERROR");
390 }
391
392 connect(section,SIGNAL(activated(int)),SLOT(updatePackageList()));
393 connect(subsection,SIGNAL(activated(int)),this,SLOT(updatePackageList()));
394}
395
396PackageItem* PackageManager::current() const
397{
398 return (PackageItem*)list->currentItem();
399}
400
401/*
402 * public slot
403 */
404void PackageManager::doCurrentDetails(bool multi)
405{
406 PackageItem* pit = current();
407 if ( pit ) {
408 if ( !details ) {
409 details = new PackageDetails;
410 connect( details->install, SIGNAL(clicked()),
411 this, SLOT(installCurrent()));
412 connect( details->remove, SIGNAL(clicked()),
413 this, SLOT(removeCurrent()));
414 details->description->setTextFormat(RichText);
415 }
416 if ( multi ) {
417 disconnect( details->ignore, SIGNAL(clicked()),
418 details, SLOT(close()));
419 connect( details->ignore, SIGNAL(clicked()),
420 this, SLOT(doNextDetails()));
421 } else {
422 disconnect( details->ignore, SIGNAL(clicked()),
423 this, SLOT(doNextDetails()));
424 connect( details->ignore, SIGNAL(clicked()),
425 details, SLOT(close()));
426 }
427 pit->setSelected(FALSE);
428 details->setCaption("Package: " + pit->name());
429 details->description->setText(fullDetails(pit->name()));
430 details->install->setEnabled(!pit->isInstalled());
431 details->remove->setEnabled(pit->isInstalled());
432 details->showMaximized();
433 }
434}
435
436void PackageManager::doDetails()
437{
438 doCurrentDetails(FALSE);
439}
440
441void PackageManager::doNextDetails()
442{
443 QListViewItem* i = list->firstChild();
444 for ( ; i; i = i->nextSibling() ) {
445 if ( i->isSelected() )
446 break;
447 }
448 list->setCurrentItem(i);
449 if ( i ) {
450 doCurrentDetails(TRUE);
451 } else if ( details )
452 details->close();
453}
454
455QString PackageManager::fullDetails(const QString& pk)
456{
457 QString status;
458 Process ipkg_status(QStringList() << "ipkg" << "info" << pk);
459 if ( ipkg_status.exec("",status) ) {
460 QStringList lines = QStringList::split('\n',status,TRUE);
461 QString description;
462 for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) {
463 QString line = *it;
464 if ( line == " ." ) {
465 description.append("<p>");
466 } else if ( line[0] == ' ' || line[0] == '\t' ) {
467 // continuation
468 description.append(" ");
469 description.append(Qtopia::escapeString(line));
470 } else {
471 int sep = line.find(QRegExp(":[\t ]+"));
472 if ( sep >= 0 ) {
473 QString tag = line.left(sep);
474 description.append("<br>");
475 description.append("<b>");
476 description.append(Qtopia::escapeString(tag));
477 description.append(":</b> ");
478 description.append(Qtopia::escapeString(line.mid(sep+2)));
479 } else {
480 description.append(" ");
481 description.append(Qtopia::escapeString(line));
482 }
483 }
484 }
485 return description;
486 }
487
488 return QString::null;
489}
490
491void PackageManager::installCurrent()
492{
493 current()->setOn(TRUE);
494 details->close();
495}
496
497void PackageManager::removeCurrent()
498{
499 current()->setOn(TRUE);
500 details->close();
501}
502
503bool PackageManager::readIpkgConfig(const QString& conffile)
504{
505 QFile conf(conffile);
506 if ( conf.open(IO_ReadOnly) ) {
507 QTextStream s(&conf);
508 settings->servers->clear();
509 serverurl.clear();
510 ipkg_old=0;
511 int currentserver=0;
512 while ( !s.atEnd() ) {
513 QString l = s.readLine();
514 QStringList token = QStringList::split(' ', l);
515 if ( token[0] == "src" || token[0] == "#src" ) {
516 currentserver=settings->servers->count();
517 serverurl.insert(settings->servers->count(),new QString(token[2]));
518 int a = token[0] == "src" ? 1 : 0;
519 int i = settings->servers->count();
520 settings->servers->insertItem(token[1]);
521 settings->servers->setSelected(i,a);
522 } else if ( token[0] == "dest" ) {
523 // needs UI
524 } else if ( token[0] == "option" ) {
525 // ### somehow need to use the settings from netsetup
526 // if ( token[1] == "http_proxy" )
527 // settings->http->setText(token[2]);
528 // else if ( token[1] == "ftp_proxy" )
529 // settings->ftp->setText(token[2]);
530 // else if ( token[1] == "proxy_username" )
531 // settings->username->setText(token[2]);
532 // else if ( token[1] == "proxy_password" )
533 // settings->password->setText(token[2]);
534 } else {
535 // Old style?
536 int eq = l.find('=');
537 if ( eq >= 0 ) {
538 QString v = l.mid(eq+1).stripWhiteSpace();
539 if ( v[0] == '"' || v[0] == '\'' ) {
540 int cl=v.find(v[0],1);
541 if ( cl >= 0 )
542 v = v.mid(1,cl-1);
543 }
544 if ( l.left(12) == "IPKG_SOURCE=" ) {
545 ipkg_old=1;
546 currentserver=settings->servers->count();
547 serverurl.insert(settings->servers->count(),new QString(v));
548 settings->servers->insertItem(v);
549 } else if ( l.left(13) == "#IPKG_SOURCE=" ) {
550 serverurl.insert(settings->servers->count(),new QString(v));
551 settings->servers->insertItem(v);
552 } else if ( l.left(10) == "IPKG_ROOT=" ) {
553 // ### no UI
554 // } else if ( l.left(20) == "IPKG_PROXY_USERNAME=" ) {
555 // settings->username->setText(v);
556 // } else if ( l.left(20) == "IPKG_PROXY_PASSWORD=" ) {
557 // settings->password->setText(v);
558 // } else if ( l.left(16) == "IPKG_PROXY_HTTP=" ) {
559 // settings->http->setText(v);
560 // } else if ( l.left(16) == "IPKG_PROXY_FTP=" ) {
561 // settings->ftp->setText(v);
562 }
563 }
564 }
565 }
566 if ( ipkg_old ) {
567 settings->servers->setSelectionMode(QListBox::Single);
568 settings->servers->setSelected(currentserver,TRUE);
569 }
570 return TRUE;
571 } else {
572 return FALSE;
573 }
574}
575
576/*
577 * public slot
578 */
579void PackageManager::doSettings()
580{
581 settings->showMaximized();
582 if ( settings->exec() ) {
583 writeSettings();
584 startRun();
585 runIpkg("update");
586 endRun();
587 updatePackageList();
588 } else {
589 readSettings();
590 }
591}
592
593void PackageManager::readSettings()
594{
595 // read from config file(s)
596 readIpkgConfig("/etc/ipkg.conf");
597}
598
599void PackageManager::writeSettings()
600{
601 QFile conf("/etc/ipkg.conf");
602 if ( conf.open(IO_WriteOnly) ) {
603 QTextStream s(&conf);
604 s << "# Written by Qtopia Package Manager\n";
605 if ( !ipkg_old ) {
606 for (int i=0; i<(int)settings->servers->count(); i++) {
607 QString url = serverurl[i] ? *serverurl[i] : QString("???");
608 if ( !settings->servers->isSelected(i) )
609 s << "#";
610 s << "src " << settings->servers->text(i) << " " << url << "\n";
611 }
612 s << "dest root /\n"; // ### need UI
613 // if ( !settings->username->text().isEmpty() )
614 // s << "option proxy_username " << settings->username->text() << "\n";
615 // if ( !settings->password->text().isEmpty() )
616 // s << "option proxy_password " << settings->password->text() << "\n";
617 // if ( !settings->http->text().isEmpty() )
618 // s << "option http_proxy " << settings->http->text() << "\n";
619 // if ( !settings->ftp->text().isEmpty() )
620 // s << "option ftp_proxy " << settings->ftp->text() << "\n";
621 } else {
622 // Old style
623 bool src_selected=FALSE;
624 for (int i=0; i<(int)settings->servers->count(); i++) {
625 if ( settings->servers->isSelected(i) ) {
626 src_selected=TRUE;
627 } else {
628 s << "#";
629 }
630 s << "IPKG_SOURCE=\"" << settings->servers->text(i) << "\"\n";
631 }
632 if ( !src_selected )
633 s << "IPKG_SOURCE=\"" << settings->servers->currentText() << "\"\n";
634 s << "IPKG_ROOT=/\n"
635 // << "IPKG_PROXY_USERNAME=\"" << settings->username->text() << "\"\n"
636 // << "IPKG_PROXY_PASSWORD=\"" << settings->password->text() << "\"\n"
637 // << "IPKG_PROXY_HTTP=\"" << settings->http->text() << "\"\n"
638 // << "IPKG_PROXY_FTP=\"" << settings->ftp->text() << "\"\n"
639 ;
640 }
641 conf.close();
642 }
643}
644
645/*
646 * public slot
647 */
648void PackageManager::doFind()
649{
650 Search s(this, 0, TRUE);
651 if ( s.exec() ) {
652 QString p = s.pattern->text();
653 if ( p.isEmpty() ) {
654 list->selectAll(FALSE);
655 } else {
656 selectPackages(findPackages(p));
657 doNextDetails();
658 }
659 }
660}
661
662void PackageManager::selectPackages( const QStringList& l )
663{
664 QDict<void> d;
665 for (QStringList::ConstIterator it = l.begin(); it != l.end(); ++it)
666 d.replace(*it,(void*)1);
667 QListViewItem* i;
668 for ( i = list->firstChild(); i; i = i->nextSibling() ) {
669 PackageItem* pit = (PackageItem*)i;
670 i->setSelected( d[pit->name()] );
671 }
672}
673
674QStringList PackageManager::findPackages( const QRegExp& r )
675{
676 QStringList matches;
677
678 QString info = ipkgInfoOutput();
679 if ( !info.isEmpty() ) {
680 QStringList lines = QStringList::split('\n',info,TRUE);
681 QRegExp re = r;
682 QString description="";
683 QString name;
684 for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) {
685 QString line = *it;
686 if ( line.length()<=1 ) {
687 // EOR
688 if ( re.match(description) >= 0 )
689 matches.append(name);
690 description="";
691 name="";
692 } else if ( line[0] == ' ' || line[0] == '\t' ) {
693 // continuation
694 description.append(" ");
695 description.append(Qtopia::escapeString(line));
696 } else {
697 int sep = line.find(QRegExp(":[\t ]+"));
698 if ( sep >= 0 ) {
699 QString tag = line.left(sep);
700 if ( tag == "Package" )
701 name = line.mid(sep+2).simplifyWhiteSpace();
702 if ( !description.isEmpty() )
703 description.append("<br>");
704 description.append("<b>");
705 description.append(Qtopia::escapeString(tag));
706 description.append(":</b> ");
707 description.append(Qtopia::escapeString(line.mid(sep+2)));
708 }
709 }
710 }
711 }
712
713 return matches;
714}
715
716/*
717 * public slot
718 */
719void PackageManager::doUpgrade()
720{
721 startMultiRun(2);
722 runIpkg("update");
723 runIpkg("upgrade");
724 updatePackageList();
725 endRun();
726}
727
728
729void PackageManager::doIt()
730{
731 bool ok = commitWithIpkg();
732 updatePackageList(); // things may have changed
733 if (!ok) qApp->beep();
734}
735
736bool PackageManager::commitWithIpkg()
737{
738 // A full implementation would do the following, but we'll just do
739 // it simply and non-interactively for now.
740 //
741 // setenv IPKG_CONF_DIR for a null $IPKG_CONF_DIR/ipkg.conf
742 // setenv IPKG_SOURCE, IPKG_ROOT, etc.
743 // run ipkg, processing interactivity as dialogs
744 // - "... (Y/I/N/O/D) [default=N] ?" -> ...
745 // - "[Press ENTER to continue]" (if D chosen above)
746 // - "The following packages are marked `Essential'... Install them now [Y/n] ?"
747 // - "The following packages...ready to be installed:... Install them now [Y/n] ?"
748 // return FALSE cancelled
749
750 QStringList to_remove, to_install;
751
752 for ( QListViewItem* i = list->firstChild(); i; i = i->nextSibling() ) {
753 PackageItem* pit = (PackageItem*)i;
754 if ( pit->isOn() ) {
755 if ( pit->isInstalled() )
756 to_remove.append(pit->name());
757 else
758 to_install.append(pit->name());
759 }
760 }
761
762 bool ok=TRUE;
763
764 int jobs = to_remove.count()+to_install.count();
765 if ( jobs ) {
766 startMultiRun(jobs);
767
768 if ( to_remove.count() ) {
769 for (QStringList::ConstIterator it=to_remove.begin(); it!=to_remove.end(); ++it) {
770 if ( runIpkg("remove " + *it) != 0 ) {
771 ok = FALSE;
772 }
773 }
774 }
775 if ( to_install.count() ) {
776 for (QStringList::ConstIterator it=to_install.begin(); it!=to_install.end(); ++it) {
777 if ( runIpkg("install " + *it) != 0 ) {
778 ok = FALSE;
779 }
780 }
781 }
782
783 // ##### If we looked in the list of files, we could send out accurate
784 // ##### messages. But we don't bother yet, and just do an "all".
785 QCopEnvelope e("QPE/System", "linkChanged(QString)");
786 QString lf = QString::null;
787 e << lf;
788
789#if QT_VERSION > 230 // a bug breaks this otherwise
790 if ( !ok )
791 QMessageBox::warning(this, "Error", "<p><tt>ipkg</tt> says something went wrong. Sorry.");
792#endif
793
794 endRun();
795 }
796
797 return ok;
798}
799
800QString PackageManager::ipkgStatusOutput()
801{
802 if ( cachedIpkgStatusOutput.isEmpty() ) {
803 Process ipkg_status( QStringList() << "ipkg" << "status" );
804 ipkg_status.exec( 0, cachedIpkgStatusOutput );
805 }
806 return QString::fromLocal8Bit( cachedIpkgStatusOutput );
807}
808
809QString PackageManager::ipkgInfoOutput()
810{
811 if ( cachedIpkgInfoOutput.isEmpty() ) {
812 Process ipkg_info( QStringList() << "ipkg" << "info" );
813 ipkg_info.exec( 0, cachedIpkgInfoOutput );
814 }
815 return QString::fromLocal8Bit( cachedIpkgInfoOutput );
816}
817
818void PackageManager::setCachedIpkgOutputDirty()
819{
820 cachedIpkgInfoOutput = cachedIpkgStatusOutput = QString::null;
821}
822
823void PackageManager::startMultiRun(int jobs)
824{
825 startRun();
826 progress->setTotalSteps(jobs);
827 progress->setProgress(0);
828}
829
830void PackageManager::startRun()
831{
832 progress->show();
833 doit->hide();
834}
835
836void PackageManager::endRun()
837{
838 doit->show();
839 progress->hide();
840}
841
842int PackageManager::runIpkg(const QString& args)
843{
844 if ( progress->progress() == -1 )
845 startMultiRun(1);
846 else
847 startRun();
848 QString cmd = "ipkg ";
849 if ( ipkg_old )
850 cmd += "</dev/null ";
851 else
852 cmd += "-force-defaults ";
853 int r = system((cmd+args).latin1());
854 progress->setProgress(progress->progress()+1);
855 setCachedIpkgOutputDirty();
856 endRun();
857 return r;
858}
859
860// simple hack to get support for ipkg mimetype
861void PackageManager::maybeInstall( const QString &ipk )
862{
863 int pos = ipk.findRev( "/" );
864 QString package = ipk.mid( pos + 1 );
865 pos = package.find ( "_" );
866 if ( pos != -1 )
867 package = package.left( pos );
868 switch ( QMessageBox::information( 0, tr( "Install Package" ),
869 tr("Are you sure you want to\ninstall package\n\n%1")
870 .arg(package), QMessageBox::Yes,
871 QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, 0 ) ) {
872 case QMessageBox::Yes: {
873 startRun();
874 runIpkg("install " + ipk );
875 QCopEnvelope e("QPE/System", "linkChanged(QString)");
876 QString lf = QString::null;
877 e << lf;
878 endRun();
879 }
880 break;
881 case QMessageBox::No:
882 default:
883 // do nothing
884 break;
885 }
886}
887
888void PackageManager::setDocument(const QString& fileref)
889{
890 if ( fileref.isNull() )
891 return;
892 DocLnk doc( fileref );
893 if ( doc.file().isEmpty() )
894 return;
895 maybeInstall( doc.file() );
896 updatePackageList();
897}
diff --git a/noncore/unsupported/oipkg/packagemanager.h b/noncore/unsupported/oipkg/packagemanager.h
new file mode 100644
index 0000000..a3f89d0
--- a/dev/null
+++ b/noncore/unsupported/oipkg/packagemanager.h
@@ -0,0 +1,94 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef PACKAGEMANAGER_H
21#define PACKAGEMANAGER_H
22#include "packagemanagerbase.h"
23#include <qintdict.h>
24
25class PackageItem;
26class PackageDetails;
27class PackageManagerSettings;
28
29class PackageManager : public PackageManagerBase
30{
31 Q_OBJECT
32
33public:
34 PackageManager( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
35 ~PackageManager();
36
37
38public slots:
39 void doDetails();
40 void doSettings();
41 void doFind();
42 void doUpgrade();
43 void setDocument(const QString& fileref);
44
45protected slots:
46 void doIt();
47
48private slots:
49 void installCurrent();
50 void removeCurrent();
51 void doNextDetails();
52
53 void newServer();
54 void editServer(int);
55 void removeServer();
56 void nameChanged(const QString&);
57 void urlChanged(const QString&);
58 void updatePackageList();
59
60private:
61 void maybeInstall( const QString &ipk );
62 void startRun();
63 void endRun();
64 void startMultiRun(int jobs);
65 int runIpkg(const QString& args);
66 QString fullDetails(const QString& pk);
67
68 bool readIpkgConfig(const QString& conffile);
69
70 void doCurrentDetails(bool);
71 PackageItem* current() const;
72
73 QStringList findPackages( const QRegExp& re );
74 void selectPackages( const QStringList& l );
75
76 bool commitWithIpkg();
77
78 QString ipkgStatusOutput();
79 QString ipkgInfoOutput();
80 void setCachedIpkgOutputDirty();
81
82 PackageManagerSettings* settings;
83 QIntDict<QString> serverurl;
84 int editedserver;
85 int ipkg_old;
86 void writeSettings();
87 void readSettings();
88
89 PackageDetails* details;
90 QCString cachedIpkgStatusOutput;
91 QCString cachedIpkgInfoOutput;
92};
93
94#endif // PACKAGEMANAGER_H
diff --git a/noncore/unsupported/oipkg/packagemanagerbase.ui b/noncore/unsupported/oipkg/packagemanagerbase.ui
new file mode 100644
index 0000000..9d5a178
--- a/dev/null
+++ b/noncore/unsupported/oipkg/packagemanagerbase.ui
@@ -0,0 +1,268 @@
1<!DOCTYPE UI><UI>
2<class>PackageManagerBase</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>Form1</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>257</width>
15 <height>290</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Package Manager</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <grid>
29 <property stdset="1">
30 <name>margin</name>
31 <number>3</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>3</number>
36 </property>
37 <widget row="0" column="0" >
38 <class>QLabel</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>TextLabel1</cstring>
42 </property>
43 <property stdset="1">
44 <name>text</name>
45 <string>Section:</string>
46 </property>
47 </widget>
48 <widget row="2" column="0" rowspan="1" colspan="3" >
49 <class>QLayoutWidget</class>
50 <property stdset="1">
51 <name>name</name>
52 <cstring>Layout1</cstring>
53 </property>
54 <property>
55 <name>layoutSpacing</name>
56 </property>
57 <hbox>
58 <property stdset="1">
59 <name>margin</name>
60 <number>0</number>
61 </property>
62 <property stdset="1">
63 <name>spacing</name>
64 <number>4</number>
65 </property>
66 <widget>
67 <class>QToolButton</class>
68 <property stdset="1">
69 <name>name</name>
70 <cstring>upgrade</cstring>
71 </property>
72 <property stdset="1">
73 <name>text</name>
74 <string>Upgrade all</string>
75 </property>
76 </widget>
77 <widget>
78 <class>QToolButton</class>
79 <property stdset="1">
80 <name>name</name>
81 <cstring>doit</cstring>
82 </property>
83 <property stdset="1">
84 <name>sizePolicy</name>
85 <sizepolicy>
86 <hsizetype>7</hsizetype>
87 <vsizetype>0</vsizetype>
88 </sizepolicy>
89 </property>
90 <property stdset="1">
91 <name>text</name>
92 <string>Do it!</string>
93 </property>
94 </widget>
95 <widget>
96 <class>QProgressBar</class>
97 <property stdset="1">
98 <name>name</name>
99 <cstring>progress</cstring>
100 </property>
101 </widget>
102 <widget>
103 <class>QToolButton</class>
104 <property stdset="1">
105 <name>name</name>
106 <cstring>settings_btn</cstring>
107 </property>
108 <property stdset="1">
109 <name>text</name>
110 <string></string>
111 </property>
112 <property stdset="1">
113 <name>pixmap</name>
114 <pixmap>image0</pixmap>
115 </property>
116 </widget>
117 <widget>
118 <class>QToolButton</class>
119 <property stdset="1">
120 <name>name</name>
121 <cstring>find_btn</cstring>
122 </property>
123 <property stdset="1">
124 <name>text</name>
125 <string></string>
126 </property>
127 <property stdset="1">
128 <name>pixmap</name>
129 <pixmap>image1</pixmap>
130 </property>
131 </widget>
132 <widget>
133 <class>QToolButton</class>
134 <property stdset="1">
135 <name>name</name>
136 <cstring>info_btn</cstring>
137 </property>
138 <property stdset="1">
139 <name>text</name>
140 <string></string>
141 </property>
142 <property stdset="1">
143 <name>pixmap</name>
144 <pixmap>image2</pixmap>
145 </property>
146 </widget>
147 </hbox>
148 </widget>
149 <widget row="0" column="2" >
150 <class>QComboBox</class>
151 <property stdset="1">
152 <name>name</name>
153 <cstring>subsection</cstring>
154 </property>
155 </widget>
156 <widget row="0" column="1" >
157 <class>QComboBox</class>
158 <property stdset="1">
159 <name>name</name>
160 <cstring>section</cstring>
161 </property>
162 </widget>
163 <widget row="1" column="0" rowspan="1" colspan="3" >
164 <class>QListView</class>
165 <column>
166 <property>
167 <name>text</name>
168 <string>Package</string>
169 </property>
170 <property>
171 <name>clickable</name>
172 <bool>true</bool>
173 </property>
174 <property>
175 <name>resizeable</name>
176 <bool>true</bool>
177 </property>
178 </column>
179 <column>
180 <property>
181 <name>text</name>
182 <string>Description</string>
183 </property>
184 <property>
185 <name>clickable</name>
186 <bool>true</bool>
187 </property>
188 <property>
189 <name>resizeable</name>
190 <bool>true</bool>
191 </property>
192 </column>
193 <column>
194 <property>
195 <name>text</name>
196 <string>Size</string>
197 </property>
198 <property>
199 <name>clickable</name>
200 <bool>true</bool>
201 </property>
202 <property>
203 <name>resizeable</name>
204 <bool>true</bool>
205 </property>
206 </column>
207 <property stdset="1">
208 <name>name</name>
209 <cstring>list</cstring>
210 </property>
211 <property stdset="1">
212 <name>allColumnsShowFocus</name>
213 <bool>true</bool>
214 </property>
215 </widget>
216 </grid>
217</widget>
218<images>
219 <image>
220 <name>image0</name>
221 <data format="XPM.GZ" length="1897">789c5dd3c972db381006e0bb9f82e5beb9527fb88baca939387b9c7851363b49e50082a4e445966dc98b3c35ef3e602f4c3cd6e9d3df683420f8f94e7472b41fed3cdf5aadddfad4477eee6ea29df676b1d8fcfcf5f73f5bdb491a2559546751bafd6c6b7bba8e7c74b0bcec0660124031ff0d26cfaec2474c6aaf6e4757bcbe1e9cc4630e7162fd66a3a5be50e7ea925d9969aeae34ff31388dd3d081f373752ec66f4bfd2b766da61b732af547ea4aebdfa8bde4b41a9c2559acf907b3aebf505bbf4fec7a7433ba663b7396b0cfd495fa44adfbe3ed68599f9b33f1f7c17932d6bf16e7b1d64fd5364f6b96fde896edf24aeb63b3e6976add9feecdb9e4fd68c7ebbbc1456a392a711117fcd8b05417da9fefaf70a31bb3d66fd4b59ed79bb5ff5cdd6afddde0322d139defc12c392dd585e61bb3e60bb62b751e9c9a0b39dfcc5cca7ed7ea5a723a339762cb6d3e9e679295added70bb3e62bf144e7c737b3e62fcd938c9daaedbe0e464bff477633a9f57c4e5c59bf2f83ab2c58ea0fcd15f7a735bba96a9df7caacf564ae1a36bfa7dad7addc0f3d9a6bcf39ffffb9dc252e67f37d3bef3ab92ff07e4ddb383ddf9eba9379c0efd1173ed5fc585dfa82f7e3dfdfb7c12de7fc5edba22d6bd98fdf6bdbb5e1c2b99e7fdfaeec529defa3ba54bf63779dd379b3c17dd9757dc9fe2aee53cd3f8fe6f5b4cbeec3373dbb53f792233137b27e7fb4ccffdeace7bb1a2db9f5efe53cd3b57d407068e0d1a2432f196698e3146738c70516b8c41257b896df052bac718b3bdce3019b903c62172fe4cde1155ee30ddee21dde630f1ff011fb38d09e8738c2149fc2b77bf88c2ff81ab26f360b8ec31427f88e1f884396842cfd3d2732e428506212b2fd3fd7715aa12610910b49f2e7bae99a1af2d492474cddffd7514f331434a3399d3edd2f6467744e17b4a04b5ad2155d3fd9ef986e688515ade9364c7bf8f43ee92eacbda707dad023ed6efffbd7d67f2c679e40</data>
222 </image>
223 <image>
224 <name>image1</name>
225 <data format="XPM.GZ" length="1182">789c55d34b739b301007f0bb3f05636e9e0e0181304ca78724b6f3b4e3043b76d2e94148c28f183b7ec7e9f4bb97d52ea4151cf4fbaf249619386b58e37ed76a9cd5b63bb19b494b4ec5c66aa87d9e9f7efefaf1bb56f702abb8796c79f56fb5ba6349abb75a6a9827c5dc76cd008e8801726c18c105ec1225f205e8b965b583840b288901d2368c0a9ac58218211551225320733dc9ccde47a01f33c962200372e613ef91dce50cd82772e4aba1085cdfbc7b0fc91517c00130644184d52b64e88566ef3b918766b126c6589d5734d536304a632f0e804fc038682aacee0ca5283a017e0285145a48e0033265a9a9ce88213200a641445dad916535238a54018740c963afe9037da410d89547d4d8c60752869203af89027947d4d29cec1aaa983753e033326578540b592ebe45aa5099a34e40c59550e6abbb216ae4a5a12eab2ba466c88b923a041e892172020420df2a9abd53a2409e1335726ba8339699bd076288dc130572032c6ac4bc62065c1a662517c40ce938b64885908e1926513a9b4c67735125f6fc6db1c897ab775926729d2ff27c53fcd465924e8a607f387e548938eef3c3f6789a7d259fdbf3e9c565ab6d9749e7eafae6b675b7beef564f17bdf6faa1dd7f7c4acac4e988a2c1ee60f89c94493146e3d1cbabeb255f493192840dfde4dfa48806c1ff09644efdcff7da5f08a60ed0</data>
226 </image>
227 <image>
228 <name>image2</name>
229 <data format="XPM.GZ" length="702">789c7dd1c96ac3301006e0bb9f4224b75092d891b550fa082d3d164a0f238d27abb33a1ba5ef5ecfd89098868e7cd0f75b23c97834501fefaf6a304a0e1554f3a8e20cf66a80c7b2bc7e7ebd7c27bd54abfac9ac4a7b4f496fa8a27adbac0b9e633def8fa5986b66ea783067cccc672ef3cc0d53a77aac659f8310b4d3c03c330d98dc08fb2db1e19c692736b513e652186c6e0373d7d2378c4c37b1e864f1b1617d29e145189c77b2f8da121bae985efbd46be6b665de300863cdc88496be61c5840800c282197430417a17420c10907962c63c9a98334b214688f276cac4820773cf244319192609a5e48f74ea9fa40f21e27d52f016d3d92d99132d80086ec97255ae3744dbbb2ec4dd9e4abc4f0e441576926379c2ce5978be5cbbc9704b84dd1bc29f64d8f43cfcae9fe7e417c79f9e92</data>
230 </image>
231</images>
232<connections>
233 <connection>
234 <sender>settings_btn</sender>
235 <signal>clicked()</signal>
236 <receiver>Form1</receiver>
237 <slot>doSettings()</slot>
238 </connection>
239 <connection>
240 <sender>find_btn</sender>
241 <signal>clicked()</signal>
242 <receiver>Form1</receiver>
243 <slot>doFind()</slot>
244 </connection>
245 <connection>
246 <sender>info_btn</sender>
247 <signal>clicked()</signal>
248 <receiver>Form1</receiver>
249 <slot>doDetails()</slot>
250 </connection>
251 <connection>
252 <sender>list</sender>
253 <signal>doubleClicked(QListViewItem*)</signal>
254 <receiver>Form1</receiver>
255 <slot>doDetails()</slot>
256 </connection>
257 <connection>
258 <sender>upgrade</sender>
259 <signal>clicked()</signal>
260 <receiver>Form1</receiver>
261 <slot>doUpgrade()</slot>
262 </connection>
263 <slot access="public">doFind()</slot>
264 <slot access="public">doDetails()</slot>
265 <slot access="public">doSettings()</slot>
266 <slot access="public">doUpgrade()</slot>
267</connections>
268</UI>
diff --git a/noncore/unsupported/oipkg/pkdesc.ui b/noncore/unsupported/oipkg/pkdesc.ui
new file mode 100644
index 0000000..494d3d6
--- a/dev/null
+++ b/noncore/unsupported/oipkg/pkdesc.ui
@@ -0,0 +1,96 @@
1<!DOCTYPE UI><UI>
2<class>PackageDetails</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>Form7</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>221</width>
15 <height>291</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>(pkgname)</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>6</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>3</number>
36 </property>
37 <widget>
38 <class>QTextView</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>description</cstring>
42 </property>
43 </widget>
44 <widget>
45 <class>QLayoutWidget</class>
46 <property stdset="1">
47 <name>name</name>
48 <cstring>Layout4</cstring>
49 </property>
50 <hbox>
51 <property stdset="1">
52 <name>margin</name>
53 <number>0</number>
54 </property>
55 <property stdset="1">
56 <name>spacing</name>
57 <number>6</number>
58 </property>
59 <widget>
60 <class>QToolButton</class>
61 <property stdset="1">
62 <name>name</name>
63 <cstring>install</cstring>
64 </property>
65 <property stdset="1">
66 <name>text</name>
67 <string>Install</string>
68 </property>
69 </widget>
70 <widget>
71 <class>QToolButton</class>
72 <property stdset="1">
73 <name>name</name>
74 <cstring>remove</cstring>
75 </property>
76 <property stdset="1">
77 <name>text</name>
78 <string>Remove</string>
79 </property>
80 </widget>
81 <widget>
82 <class>QToolButton</class>
83 <property stdset="1">
84 <name>name</name>
85 <cstring>ignore</cstring>
86 </property>
87 <property stdset="1">
88 <name>text</name>
89 <string>Ignore</string>
90 </property>
91 </widget>
92 </hbox>
93 </widget>
94 </vbox>
95</widget>
96</UI>
diff --git a/noncore/unsupported/oipkg/pkfind.ui b/noncore/unsupported/oipkg/pkfind.ui
new file mode 100644
index 0000000..7a24c00
--- a/dev/null
+++ b/noncore/unsupported/oipkg/pkfind.ui
@@ -0,0 +1,51 @@
1<!DOCTYPE UI><UI>
2<class>Search</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>Form5</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>196</width>
15 <height>55</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Search Packages</string>
21 </property>
22 <hbox>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget>
32 <class>QLabel</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>TextLabel4</cstring>
36 </property>
37 <property stdset="1">
38 <name>text</name>
39 <string>Find:</string>
40 </property>
41 </widget>
42 <widget>
43 <class>QLineEdit</class>
44 <property stdset="1">
45 <name>name</name>
46 <cstring>pattern</cstring>
47 </property>
48 </widget>
49 </hbox>
50</widget>
51</UI>
diff --git a/noncore/unsupported/oipkg/pksettings.ui b/noncore/unsupported/oipkg/pksettings.ui
new file mode 100644
index 0000000..f182752
--- a/dev/null
+++ b/noncore/unsupported/oipkg/pksettings.ui
@@ -0,0 +1,176 @@
1<!DOCTYPE UI><UI>
2<class>PackageManagerSettings</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>Form4</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>549</width>
15 <height>683</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Package Servers</string>
21 </property>
22 <grid>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget row="3" column="0" rowspan="1" colspan="2" >
32 <class>QLayoutWidget</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>Layout4</cstring>
36 </property>
37 <grid>
38 <property stdset="1">
39 <name>margin</name>
40 <number>0</number>
41 </property>
42 <property stdset="1">
43 <name>spacing</name>
44 <number>6</number>
45 </property>
46 <widget row="0" column="1" >
47 <class>QLineEdit</class>
48 <property stdset="1">
49 <name>name</name>
50 <cstring>servername</cstring>
51 </property>
52 </widget>
53 <widget row="0" column="0" >
54 <class>QLabel</class>
55 <property stdset="1">
56 <name>name</name>
57 <cstring>TextLabel1_3</cstring>
58 </property>
59 <property stdset="1">
60 <name>text</name>
61 <string>Name:</string>
62 </property>
63 </widget>
64 <widget row="1" column="1" >
65 <class>QLineEdit</class>
66 <property stdset="1">
67 <name>name</name>
68 <cstring>serverurl</cstring>
69 </property>
70 </widget>
71 <widget row="1" column="0" >
72 <class>QLabel</class>
73 <property stdset="1">
74 <name>name</name>
75 <cstring>TextLabel2_3</cstring>
76 </property>
77 <property stdset="1">
78 <name>text</name>
79 <string>URL:</string>
80 </property>
81 </widget>
82 </grid>
83 </widget>
84 <widget row="2" column="0" >
85 <class>QPushButton</class>
86 <property stdset="1">
87 <name>name</name>
88 <cstring>newserver</cstring>
89 </property>
90 <property stdset="1">
91 <name>text</name>
92 <string>New</string>
93 </property>
94 <property stdset="1">
95 <name>autoDefault</name>
96 <bool>false</bool>
97 </property>
98 </widget>
99 <widget row="2" column="1" >
100 <class>QPushButton</class>
101 <property stdset="1">
102 <name>name</name>
103 <cstring>removeserver</cstring>
104 </property>
105 <property stdset="1">
106 <name>text</name>
107 <string>Remove</string>
108 </property>
109 <property stdset="1">
110 <name>autoDefault</name>
111 <bool>false</bool>
112 </property>
113 </widget>
114 <widget row="1" column="0" rowspan="1" colspan="2" >
115 <class>QListBox</class>
116 <property stdset="1">
117 <name>name</name>
118 <cstring>servers</cstring>
119 </property>
120 <property stdset="1">
121 <name>selectionMode</name>
122 <enum>Multi</enum>
123 </property>
124 </widget>
125 <widget row="0" column="0" rowspan="1" colspan="2" >
126 <class>QLayoutWidget</class>
127 <property stdset="1">
128 <name>name</name>
129 <cstring>Layout2</cstring>
130 </property>
131 <hbox>
132 <property stdset="1">
133 <name>margin</name>
134 <number>0</number>
135 </property>
136 <property stdset="1">
137 <name>spacing</name>
138 <number>6</number>
139 </property>
140 <widget>
141 <class>QLabel</class>
142 <property stdset="1">
143 <name>name</name>
144 <cstring>Servers</cstring>
145 </property>
146 <property stdset="1">
147 <name>text</name>
148 <string>Servers</string>
149 </property>
150 </widget>
151 <spacer>
152 <property>
153 <name>name</name>
154 <cstring>Spacer2</cstring>
155 </property>
156 <property stdset="1">
157 <name>orientation</name>
158 <enum>Horizontal</enum>
159 </property>
160 <property stdset="1">
161 <name>sizeType</name>
162 <enum>Expanding</enum>
163 </property>
164 <property>
165 <name>sizeHint</name>
166 <size>
167 <width>20</width>
168 <height>20</height>
169 </size>
170 </property>
171 </spacer>
172 </hbox>
173 </widget>
174 </grid>
175</widget>
176</UI>
diff --git a/noncore/unsupported/oipkg/qipkg.pro b/noncore/unsupported/oipkg/qipkg.pro
new file mode 100644
index 0000000..90d8703
--- a/dev/null
+++ b/noncore/unsupported/oipkg/qipkg.pro
@@ -0,0 +1,13 @@
1 DESTDIR = $(QPEDIR)/bin
2 TEMPLATE= app
3 CONFIG = qt warn_on release
4 HEADERS = packagemanager.h
5 SOURCES = packagemanager.cpp \
6 main.cpp
7INCLUDEPATH += $(QPEDIR)/include
8 DEPENDPATH+= $(QPEDIR)/include
9LIBS += -lqpe
10 INTERFACES= packagemanagerbase.ui pkdesc.ui pkfind.ui pksettings.ui
11 TARGET = qipkg
12
13TRANSLATIONS = ../i18n/de/qipkg.ts
diff --git a/noncore/unsupported/oipkg/qpe-qipkg.control b/noncore/unsupported/oipkg/qpe-qipkg.control
new file mode 100644
index 0000000..3c3e7c8
--- a/dev/null
+++ b/noncore/unsupported/oipkg/qpe-qipkg.control
@@ -0,0 +1,9 @@
1Files: bin/qipkg apps/Settings/qipkg.desktop
2Priority: optional
3Section: qpe/settings
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Package Manager
9 A GUI front-end to ipkg for the Qtopia environment.