summaryrefslogtreecommitdiff
authorerik <erik>2007-01-26 20:18:07 (UTC)
committer erik <erik>2007-01-26 20:18:07 (UTC)
commit152a8fe978851aea8dac6ae5cb11f73540746b83 (patch) (unidiff)
tree60f2fc2eb9a711e9aab91b9d743fd3730d5642e7
parent644780047090442429342addb3fa97ec95bdc670 (diff)
downloadopie-152a8fe978851aea8dac6ae5cb11f73540746b83.zip
opie-152a8fe978851aea8dac6ae5cb11f73540746b83.tar.gz
opie-152a8fe978851aea8dac6ae5cb11f73540746b83.tar.bz2
Both files in this commit exhibit use after free errors.
One of them was introduced in my memory leak fixing (whoops). I was freeing a structure of stock data before one last call to it. So switching the free to after that call fixed it. The kcheckers.cpp fix is one where the game board could be deleted and then a new one is not created because someone attempted to request a game board type that is not supported. This is fixed by using the default directive for one of the game board types in the switch statement. Which means it could default to Russian boards. Score one for the Russians!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/kcheckers/kcheckers.cpp1
-rw-r--r--noncore/todayplugins/stockticker/libstocks/currency.c7
2 files changed, 4 insertions, 4 deletions
diff --git a/noncore/games/kcheckers/kcheckers.cpp b/noncore/games/kcheckers/kcheckers.cpp
index a27dd18..433c68f 100644
--- a/noncore/games/kcheckers/kcheckers.cpp
+++ b/noncore/games/kcheckers/kcheckers.cpp
@@ -1,586 +1,587 @@
1 1
2#include <qimage.h> 2#include <qimage.h>
3#include <qlayout.h> 3#include <qlayout.h>
4#include <qmenubar.h> 4#include <qmenubar.h>
5#include <qtoolbar.h> 5#include <qtoolbar.h>
6#include <qpe/config.h> 6#include <qpe/config.h>
7#include <qwhatsthis.h> 7#include <qwhatsthis.h>
8#include <qtoolbutton.h> 8#include <qtoolbutton.h>
9#include <qmessagebox.h> 9#include <qmessagebox.h>
10#include <qapplication.h> 10#include <qapplication.h>
11 11
12#include "kcheckers.h" 12#include "kcheckers.h"
13#include "echeckers.h" 13#include "echeckers.h"
14#include "rcheckers.h" 14#include "rcheckers.h"
15 15
16#include "pics/logo.xpm" 16#include "pics/logo.xpm"
17#include "pics/undo.xpm" 17#include "pics/undo.xpm"
18#include "pics/exit.xpm" 18#include "pics/exit.xpm"
19#include "pics/help.xpm" 19#include "pics/help.xpm"
20#include "pics/wood1.xpm" 20#include "pics/wood1.xpm"
21#include "pics/wood2.xpm" 21#include "pics/wood2.xpm"
22#include "pics/wood3.xpm" 22#include "pics/wood3.xpm"
23#include "pics/green1.xpm" 23#include "pics/green1.xpm"
24#include "pics/green2.xpm" 24#include "pics/green2.xpm"
25#include "pics/green3.xpm" 25#include "pics/green3.xpm"
26#include "pics/marble1.xpm" 26#include "pics/marble1.xpm"
27#include "pics/marble2.xpm" 27#include "pics/marble2.xpm"
28#include "pics/marble3.xpm" 28#include "pics/marble3.xpm"
29#include "pics/biglogo.xpm" 29#include "pics/biglogo.xpm"
30#include "pics/man_black.xpm" 30#include "pics/man_black.xpm"
31#include "pics/man_white.xpm" 31#include "pics/man_white.xpm"
32#include "pics/king_black.xpm" 32#include "pics/king_black.xpm"
33#include "pics/king_white.xpm" 33#include "pics/king_white.xpm"
34#include "pics/contexthelp.xpm" 34#include "pics/contexthelp.xpm"
35 35
36 36
37QString KCheckers::enNumeration="1 2 3 4 5 6 7 8 9 1011121314151617181920212223242526272829303132"; 37QString KCheckers::enNumeration="1 2 3 4 5 6 7 8 9 1011121314151617181920212223242526272829303132";
38QString KCheckers::ruNumeration="B8D8F8H8A7C7E7G7B6D6F6H6A5C5E5G5B4D4F4H4A3C3E3G3B2D2F2H2A1C1E1G1"; 38QString KCheckers::ruNumeration="B8D8F8H8A7C7E7G7B6D6F6H6A5C5E5G5B4D4F4H4A3C3E3G3B2D2F2H2A1C1E1G1";
39 39
40const int KCheckers::t[]={6,7,8,9,11,12,13,14,17,18,19,20,22,23, 40const int KCheckers::t[]={6,7,8,9,11,12,13,14,17,18,19,20,22,23,
41 24,25,28,29,30,31,33,34,35,36,39,40,41,42,44,45,46,47}; 41 24,25,28,29,30,31,33,34,35,36,39,40,41,42,44,45,46,47};
42 42
43 43
44KCheckers::KCheckers(QWidget *p, const char* n, WFlags ) 44KCheckers::KCheckers(QWidget *p, const char* n, WFlags )
45 :QMainWindow(p,n,WStyle_DialogBorder) 45 :QMainWindow(p,n,WStyle_DialogBorder)
46{ 46{
47 setCaption(tr("KCheckers") ); 47 setCaption(tr("KCheckers") );
48 setIcon(QPixmap(biglogo_xpm)); 48 setIcon(QPixmap(biglogo_xpm));
49 49
50 setToolBarsMovable(false); 50 setToolBarsMovable(false);
51 51
52 // Make a menubar 52 // Make a menubar
53 53
54 gameMenu=new QPopupMenu; 54 gameMenu=new QPopupMenu;
55 CHECK_PTR(gameMenu); 55 CHECK_PTR(gameMenu);
56 56
57 gameMenu->insertItem(QPixmap(logo_xpm),tr("&New"),this,SLOT(newGame()),CTRL+Key_N); 57 gameMenu->insertItem(QPixmap(logo_xpm),tr("&New"),this,SLOT(newGame()),CTRL+Key_N);
58 gameMenu->insertSeparator(); 58 gameMenu->insertSeparator();
59 undoID=gameMenu->insertItem(QPixmap(undo_xpm),tr("&Undo Move"),this,SLOT(undoMove()),CTRL+Key_Z); 59 undoID=gameMenu->insertItem(QPixmap(undo_xpm),tr("&Undo Move"),this,SLOT(undoMove()),CTRL+Key_Z);
60 gameMenu->insertSeparator(); 60 gameMenu->insertSeparator();
61 gameMenu->insertItem(QPixmap(exit_xpm),tr("&Quit"),qApp,SLOT(closeAllWindows()),CTRL+Key_Q); 61 gameMenu->insertItem(QPixmap(exit_xpm),tr("&Quit"),qApp,SLOT(closeAllWindows()),CTRL+Key_Q);
62 62
63 skillMenu=new QPopupMenu; 63 skillMenu=new QPopupMenu;
64 CHECK_PTR(skillMenu); 64 CHECK_PTR(skillMenu);
65 65
66 skillMenu->insertItem(tr("&Beginner"),this,SLOT(setSkillBeginner()),CTRL+Key_1,BEGINNER); 66 skillMenu->insertItem(tr("&Beginner"),this,SLOT(setSkillBeginner()),CTRL+Key_1,BEGINNER);
67 skillMenu->insertItem(tr("&Novice"), this,SLOT(setSkillNovice()), CTRL+Key_2,NOVICE); 67 skillMenu->insertItem(tr("&Novice"), this,SLOT(setSkillNovice()), CTRL+Key_2,NOVICE);
68 skillMenu->insertItem(tr("&Average"), this,SLOT(setSkillAverage()), CTRL+Key_3,AVERAGE); 68 skillMenu->insertItem(tr("&Average"), this,SLOT(setSkillAverage()), CTRL+Key_3,AVERAGE);
69 skillMenu->insertItem(tr("&Good"), this,SLOT(setSkillGood()), CTRL+Key_4,GOOD); 69 skillMenu->insertItem(tr("&Good"), this,SLOT(setSkillGood()), CTRL+Key_4,GOOD);
70 skillMenu->insertItem(tr("&Expert"), this,SLOT(setSkillExpert()), CTRL+Key_5,EXPERT); 70 skillMenu->insertItem(tr("&Expert"), this,SLOT(setSkillExpert()), CTRL+Key_5,EXPERT);
71 skillMenu->insertItem(tr("&Master"), this,SLOT(setSkillMaster()), CTRL+Key_6,MASTER); 71 skillMenu->insertItem(tr("&Master"), this,SLOT(setSkillMaster()), CTRL+Key_6,MASTER);
72 72
73 optionsMenu=new QPopupMenu; 73 optionsMenu=new QPopupMenu;
74 CHECK_PTR(optionsMenu); 74 CHECK_PTR(optionsMenu);
75 75
76 numID=optionsMenu->insertItem(tr("&Show Numeration"),this,SLOT(showNumeration())); 76 numID=optionsMenu->insertItem(tr("&Show Numeration"),this,SLOT(showNumeration()));
77 optionsMenu->insertSeparator(); 77 optionsMenu->insertSeparator();
78 optionsMenu->insertItem(tr("&English Rules"),this,SLOT(setRulesEnglish()),0,ENGLISH); 78 optionsMenu->insertItem(tr("&English Rules"),this,SLOT(setRulesEnglish()),0,ENGLISH);
79 optionsMenu->insertItem(tr("&Russian Rules"),this,SLOT(setRulesRussian()),0,RUSSIAN); 79 optionsMenu->insertItem(tr("&Russian Rules"),this,SLOT(setRulesRussian()),0,RUSSIAN);
80 optionsMenu->insertSeparator(); 80 optionsMenu->insertSeparator();
81 optionsMenu->insertItem(tr("&Green Board"), this,SLOT(setPatternGreen()), 0,GREEN); 81 optionsMenu->insertItem(tr("&Green Board"), this,SLOT(setPatternGreen()), 0,GREEN);
82 optionsMenu->insertItem(tr("&Marble Board"),this,SLOT(setPatternMarble()),0,MARBLE); 82 optionsMenu->insertItem(tr("&Marble Board"),this,SLOT(setPatternMarble()),0,MARBLE);
83 optionsMenu->insertItem(tr("&Wooden Board"),this,SLOT(setPatternWooden()),0,WOODEN); 83 optionsMenu->insertItem(tr("&Wooden Board"),this,SLOT(setPatternWooden()),0,WOODEN);
84 84
85 QPopupMenu* helpMenu=new QPopupMenu; 85 QPopupMenu* helpMenu=new QPopupMenu;
86 CHECK_PTR(helpMenu); 86 CHECK_PTR(helpMenu);
87 87
88 helpMenu->insertItem(QPixmap(contexthelp_xpm),tr("What's This"),this,SLOT(whatsThis()),SHIFT+Key_F1); 88 helpMenu->insertItem(QPixmap(contexthelp_xpm),tr("What's This"),this,SLOT(whatsThis()),SHIFT+Key_F1);
89 helpMenu->insertItem(QPixmap(help_xpm),tr("&Rules of Play"),this,SLOT(help()),Key_F1); 89 helpMenu->insertItem(QPixmap(help_xpm),tr("&Rules of Play"),this,SLOT(help()),Key_F1);
90 helpMenu->insertSeparator(); 90 helpMenu->insertSeparator();
91 helpMenu->insertItem(QPixmap(logo_xpm),tr("&About KCheckers"),this,SLOT(about())); 91 helpMenu->insertItem(QPixmap(logo_xpm),tr("&About KCheckers"),this,SLOT(about()));
92 helpMenu->insertItem(tr("About &Qt"),this,SLOT(aboutQt())); 92 helpMenu->insertItem(tr("About &Qt"),this,SLOT(aboutQt()));
93 93
94 QToolBar* menuToolBar=new QToolBar(this); 94 QToolBar* menuToolBar=new QToolBar(this);
95 CHECK_PTR(menuToolBar); 95 CHECK_PTR(menuToolBar);
96 QMenuBar* menuBar=new QMenuBar(menuToolBar); 96 QMenuBar* menuBar=new QMenuBar(menuToolBar);
97 CHECK_PTR(menuBar); 97 CHECK_PTR(menuBar);
98 98
99 menuBar->insertItem(tr("&Game"), gameMenu); 99 menuBar->insertItem(tr("&Game"), gameMenu);
100 menuBar->insertItem(tr("&Skill"), skillMenu); 100 menuBar->insertItem(tr("&Skill"), skillMenu);
101 menuBar->insertItem(tr("&Options"),optionsMenu); 101 menuBar->insertItem(tr("&Options"),optionsMenu);
102 menuBar->insertItem(tr("&Help"), helpMenu); 102 menuBar->insertItem(tr("&Help"), helpMenu);
103 103
104 // Restore a settings 104 // Restore a settings
105 105
106 readConfig(); 106 readConfig();
107 107
108 skillMenu->setItemChecked(skill,true); 108 skillMenu->setItemChecked(skill,true);
109 optionsMenu->setItemChecked(rules,true); 109 optionsMenu->setItemChecked(rules,true);
110 optionsMenu->setItemChecked(numID,false); 110 optionsMenu->setItemChecked(numID,false);
111 111
112 // Make a toolbar 112 // Make a toolbar
113 113
114 QToolBar* emptyToolBar=new QToolBar(this); 114 QToolBar* emptyToolBar=new QToolBar(this);
115 emptyToolBar->setHorizontalStretchable(true); 115 emptyToolBar->setHorizontalStretchable(true);
116 116
117 QToolBar* toolBar=new QToolBar(this); 117 QToolBar* toolBar=new QToolBar(this);
118 CHECK_PTR(toolBar); 118 CHECK_PTR(toolBar);
119 119
120 QSize buttonSize(24,24); 120 QSize buttonSize(24,24);
121 121
122 QToolButton* gameButton=new QToolButton(QPixmap(logo_xpm),tr(" New Game ") ,"",this,SLOT(newGame()),toolBar); 122 QToolButton* gameButton=new QToolButton(QPixmap(logo_xpm),tr(" New Game ") ,"",this,SLOT(newGame()),toolBar);
123 CHECK_PTR(gameButton); 123 CHECK_PTR(gameButton);
124 gameButton->setMinimumSize(buttonSize); 124 gameButton->setMinimumSize(buttonSize);
125 125
126 undoButton=new QToolButton(QPixmap(undo_xpm),tr(" Undo Move "),"",this,SLOT(undoMove()),toolBar); 126 undoButton=new QToolButton(QPixmap(undo_xpm),tr(" Undo Move "),"",this,SLOT(undoMove()),toolBar);
127 CHECK_PTR(undoButton); 127 CHECK_PTR(undoButton);
128 undoButton->setMinimumSize(buttonSize); 128 undoButton->setMinimumSize(buttonSize);
129 129
130 QToolButton* helpButton=new QToolButton(QPixmap(help_xpm),tr(" Rules of Play "),"",this,SLOT(help()),toolBar); 130 QToolButton* helpButton=new QToolButton(QPixmap(help_xpm),tr(" Rules of Play "),"",this,SLOT(help()),toolBar);
131 CHECK_PTR(helpButton); 131 CHECK_PTR(helpButton);
132 helpButton->setMinimumSize(buttonSize); 132 helpButton->setMinimumSize(buttonSize);
133 133
134 // Make a checkers board 134 // Make a checkers board
135 135
136 imageMan1=new QImage(man_black_xpm); CHECK_PTR(imageMan1); 136 imageMan1=new QImage(man_black_xpm); CHECK_PTR(imageMan1);
137 imageMan2=new QImage(man_white_xpm); CHECK_PTR(imageMan2); 137 imageMan2=new QImage(man_white_xpm); CHECK_PTR(imageMan2);
138 imageKing1=new QImage(king_black_xpm); CHECK_PTR(imageKing1); 138 imageKing1=new QImage(king_black_xpm); CHECK_PTR(imageKing1);
139 imageKing2=new QImage(king_white_xpm); CHECK_PTR(imageKing2); 139 imageKing2=new QImage(king_white_xpm); CHECK_PTR(imageKing2);
140 140
141 imageWood1=new QImage(wood1_xpm); CHECK_PTR(imageWood1); 141 imageWood1=new QImage(wood1_xpm); CHECK_PTR(imageWood1);
142 imageWood2=new QImage(wood2_xpm); CHECK_PTR(imageWood2); 142 imageWood2=new QImage(wood2_xpm); CHECK_PTR(imageWood2);
143 imageWood3=new QImage(wood3_xpm); CHECK_PTR(imageWood3); 143 imageWood3=new QImage(wood3_xpm); CHECK_PTR(imageWood3);
144 imageGreen1=new QImage(green1_xpm); CHECK_PTR(imageGreen1); 144 imageGreen1=new QImage(green1_xpm); CHECK_PTR(imageGreen1);
145 imageGreen2=new QImage(green2_xpm); CHECK_PTR(imageGreen2); 145 imageGreen2=new QImage(green2_xpm); CHECK_PTR(imageGreen2);
146 imageGreen3=new QImage(green3_xpm); CHECK_PTR(imageGreen3); 146 imageGreen3=new QImage(green3_xpm); CHECK_PTR(imageGreen3);
147 imageMarble1=new QImage(marble1_xpm); CHECK_PTR(imageMarble1); 147 imageMarble1=new QImage(marble1_xpm); CHECK_PTR(imageMarble1);
148 imageMarble2=new QImage(marble2_xpm); CHECK_PTR(imageMarble2); 148 imageMarble2=new QImage(marble2_xpm); CHECK_PTR(imageMarble2);
149 imageMarble3=new QImage(marble3_xpm); CHECK_PTR(imageMarble3); 149 imageMarble3=new QImage(marble3_xpm); CHECK_PTR(imageMarble3);
150 150
151 QWidget* centralWidget=new QWidget(this); 151 QWidget* centralWidget=new QWidget(this);
152 setCentralWidget(centralWidget); 152 setCentralWidget(centralWidget);
153 153
154 QFrame* frame=new QFrame(centralWidget); 154 QFrame* frame=new QFrame(centralWidget);
155 CHECK_PTR(frame); 155 CHECK_PTR(frame);
156 frame->setFrameStyle(QFrame::Box|QFrame::Plain); 156 frame->setFrameStyle(QFrame::Box|QFrame::Plain);
157 frame->setFixedSize(SIZE*8+2,SIZE*8+2); 157 frame->setFixedSize(SIZE*8+2,SIZE*8+2);
158 158
159 statusLabel = new QLabel(centralWidget); 159 statusLabel = new QLabel(centralWidget);
160 statusLabel->setAlignment(Qt::AlignHCenter); 160 statusLabel->setAlignment(Qt::AlignHCenter);
161 161
162 QVBoxLayout* vlayout=new QVBoxLayout(centralWidget); 162 QVBoxLayout* vlayout=new QVBoxLayout(centralWidget);
163 163
164 vlayout->addStretch(); 164 vlayout->addStretch();
165 vlayout->addWidget(frame); 165 vlayout->addWidget(frame);
166 vlayout->addStretch(); 166 vlayout->addStretch();
167 vlayout->addWidget(statusLabel); 167 vlayout->addWidget(statusLabel);
168 vlayout->addStretch(); 168 vlayout->addStretch();
169 169
170 for(int i=0;i<64;i++) 170 for(int i=0;i<64;i++)
171 { 171 {
172 field[i]=new Field(frame,i); 172 field[i]=new Field(frame,i);
173 CHECK_PTR(field[i]); 173 CHECK_PTR(field[i]);
174 } 174 }
175 175
176 QGridLayout* grid=new QGridLayout(frame,8,8,1,0); 176 QGridLayout* grid=new QGridLayout(frame,8,8,1,0);
177 CHECK_PTR(grid); 177 CHECK_PTR(grid);
178 178
179 for(int i=0;i<4;i++) 179 for(int i=0;i<4;i++)
180 { 180 {
181 for(int k=0;k<4;k++) 181 for(int k=0;k<4;k++)
182 { 182 {
183 grid->addWidget(field[i*8+k+32],i*2, k*2 ); 183 grid->addWidget(field[i*8+k+32],i*2, k*2 );
184 grid->addWidget(field[i*8+k ],i*2, k*2+1); 184 grid->addWidget(field[i*8+k ],i*2, k*2+1);
185 grid->addWidget(field[i*8+k+4 ],i*2+1,k*2 ); 185 grid->addWidget(field[i*8+k+4 ],i*2+1,k*2 );
186 grid->addWidget(field[i*8+k+36],i*2+1,k*2+1); 186 grid->addWidget(field[i*8+k+36],i*2+1,k*2+1);
187 } 187 }
188 } 188 }
189 189
190 for(int i=0;i<32;i++) 190 for(int i=0;i<32;i++)
191 connect(field[i],SIGNAL(click(int)),this,SLOT(click(int))); 191 connect(field[i],SIGNAL(click(int)),this,SLOT(click(int)));
192 192
193 selected=false; 193 selected=false;
194 194
195 setPattern(pattern); 195 setPattern(pattern);
196 196
197 QWhatsThis::add(frame,"A checkers board"); 197 QWhatsThis::add(frame,"A checkers board");
198 198
199 userFirst=false; 199 userFirst=false;
200 200
201 game=NULL; 201 game=NULL;
202 newGame(); 202 newGame();
203} 203}
204 204
205 205
206void KCheckers::readConfig() 206void KCheckers::readConfig()
207{ 207{
208 Config config("KCheckers"); 208 Config config("KCheckers");
209 config.setGroup("KCheckers"); 209 config.setGroup("KCheckers");
210 QString entry; 210 QString entry;
211 211
212 entry=config.readEntry("skill","novice"); 212 entry=config.readEntry("skill","novice");
213 if(entry=="beginner") skill=BEGINNER; 213 if(entry=="beginner") skill=BEGINNER;
214 else if(entry=="average") skill=AVERAGE; 214 else if(entry=="average") skill=AVERAGE;
215 else if(entry=="good") skill=GOOD; 215 else if(entry=="good") skill=GOOD;
216 else if(entry=="expert") skill=EXPERT; 216 else if(entry=="expert") skill=EXPERT;
217 else if(entry=="master") skill=MASTER; 217 else if(entry=="master") skill=MASTER;
218 else skill=NOVICE; 218 else skill=NOVICE;
219 219
220 entry=config.readEntry("rules","english"); 220 entry=config.readEntry("rules","english");
221 if(entry=="russian") rules=RUSSIAN; 221 if(entry=="russian") rules=RUSSIAN;
222 else rules=ENGLISH; 222 else rules=ENGLISH;
223 223
224 entry=config.readEntry("theme","wooden"); 224 entry=config.readEntry("theme","wooden");
225 if(entry=="green") pattern=GREEN; 225 if(entry=="green") pattern=GREEN;
226 else if(entry=="marble") pattern=MARBLE; 226 else if(entry=="marble") pattern=MARBLE;
227 else pattern=WOODEN; 227 else pattern=WOODEN;
228} 228}
229 229
230 230
231void KCheckers::closeEvent(QCloseEvent* event) 231void KCheckers::closeEvent(QCloseEvent* event)
232{ 232{
233 Config config("KCheckers"); 233 Config config("KCheckers");
234 config.setGroup("KCheckers"); 234 config.setGroup("KCheckers");
235 QString entry; 235 QString entry;
236 236
237 if(skill==BEGINNER) entry="beginner"; 237 if(skill==BEGINNER) entry="beginner";
238 if(skill==NOVICE) entry="novice"; 238 if(skill==NOVICE) entry="novice";
239 if(skill==AVERAGE) entry="average"; 239 if(skill==AVERAGE) entry="average";
240 if(skill==GOOD) entry="good"; 240 if(skill==GOOD) entry="good";
241 if(skill==EXPERT) entry="expert"; 241 if(skill==EXPERT) entry="expert";
242 if(skill==MASTER) entry="master"; 242 if(skill==MASTER) entry="master";
243 config.writeEntry("skill",entry); 243 config.writeEntry("skill",entry);
244 244
245 if(rules==ENGLISH) entry="english"; 245 if(rules==ENGLISH) entry="english";
246 if(rules==RUSSIAN) entry="russian"; 246 if(rules==RUSSIAN) entry="russian";
247 config.writeEntry("rules",entry); 247 config.writeEntry("rules",entry);
248 248
249 if(pattern==GREEN) entry="green"; 249 if(pattern==GREEN) entry="green";
250 if(pattern==MARBLE) entry="marble"; 250 if(pattern==MARBLE) entry="marble";
251 if(pattern==WOODEN) entry="wooden"; 251 if(pattern==WOODEN) entry="wooden";
252 config.writeEntry("theme",entry); 252 config.writeEntry("theme",entry);
253 253
254 event->accept(); 254 event->accept();
255} 255}
256 256
257 257
258void KCheckers::setSkill(int set) 258void KCheckers::setSkill(int set)
259{ 259{
260 skillMenu->setItemChecked(skill,false); 260 skillMenu->setItemChecked(skill,false);
261 261
262 skill=set; 262 skill=set;
263 skillMenu->setItemChecked(skill,true); 263 skillMenu->setItemChecked(skill,true);
264 264
265 game->setLevel(skill); 265 game->setLevel(skill);
266} 266}
267 267
268 268
269void KCheckers::setRules(int set) 269void KCheckers::setRules(int set)
270{ 270{
271 optionsMenu->setItemChecked(rules,false); 271 optionsMenu->setItemChecked(rules,false);
272 272
273 rules=set; 273 rules=set;
274 optionsMenu->setItemChecked(rules,true); 274 optionsMenu->setItemChecked(rules,true);
275 275
276 colorChange(); 276 colorChange();
277 newGame(); 277 newGame();
278} 278}
279 279
280 280
281void KCheckers::setPattern(int set) 281void KCheckers::setPattern(int set)
282{ 282{
283 optionsMenu->setItemChecked(pattern,false); 283 optionsMenu->setItemChecked(pattern,false);
284 284
285 pattern=set; 285 pattern=set;
286 optionsMenu->setItemChecked(pattern,true); 286 optionsMenu->setItemChecked(pattern,true);
287 287
288 switch(pattern) 288 switch(pattern)
289 { 289 {
290 case GREEN: 290 case GREEN:
291 imagePat1=imageGreen1; 291 imagePat1=imageGreen1;
292 imagePat2=imageGreen2; 292 imagePat2=imageGreen2;
293 imageFrame=imageGreen3; 293 imageFrame=imageGreen3;
294 break; 294 break;
295 case MARBLE: 295 case MARBLE:
296 imagePat1=imageMarble1; 296 imagePat1=imageMarble1;
297 imagePat2=imageMarble2; 297 imagePat2=imageMarble2;
298 imageFrame=imageMarble3; 298 imageFrame=imageMarble3;
299 break; 299 break;
300 case WOODEN: 300 case WOODEN:
301 imagePat1=imageWood1; 301 imagePat1=imageWood1;
302 imagePat2=imageWood2; 302 imagePat2=imageWood2;
303 imageFrame=imageWood3; 303 imageFrame=imageWood3;
304 } 304 }
305 305
306 for(int i=0; i<32;i++) field[i]->setPattern(imagePat2); 306 for(int i=0; i<32;i++) field[i]->setPattern(imagePat2);
307 for(int i=32;i<64;i++) field[i]->setPattern(imagePat1); 307 for(int i=32;i<64;i++) field[i]->setPattern(imagePat1);
308 308
309 if(selected) field[from]->setFrame(imageFrame); 309 if(selected) field[from]->setFrame(imageFrame);
310} 310}
311 311
312 312
313void KCheckers::showNumeration() 313void KCheckers::showNumeration()
314{ 314{
315 if(optionsMenu->isItemChecked(numID)) 315 if(optionsMenu->isItemChecked(numID))
316 { 316 {
317 optionsMenu->setItemChecked(numID,false); 317 optionsMenu->setItemChecked(numID,false);
318 for(int i=0;i<32;i++) field[i]->setLabel(""); 318 for(int i=0;i<32;i++) field[i]->setLabel("");
319 } 319 }
320 else 320 else
321 { 321 {
322 optionsMenu->setItemChecked(numID,true); 322 optionsMenu->setItemChecked(numID,true);
323 drawNumeration(); 323 drawNumeration();
324 } 324 }
325} 325}
326 326
327 327
328void KCheckers::drawNumeration() 328void KCheckers::drawNumeration()
329{ 329{
330 if(rules==ENGLISH) 330 if(rules==ENGLISH)
331 { 331 {
332 if(userFirst) 332 if(userFirst)
333 for(int i=0;i<32;i++) 333 for(int i=0;i<32;i++)
334 field[i]->setLabel(enNumeration.mid(i*2,2)); 334 field[i]->setLabel(enNumeration.mid(i*2,2));
335 else 335 else
336 for(int i=0;i<32;i++) 336 for(int i=0;i<32;i++)
337 field[i]->setLabel(enNumeration.mid(62-i*2,2)); 337 field[i]->setLabel(enNumeration.mid(62-i*2,2));
338 } 338 }
339 else 339 else
340 { 340 {
341 if(userFirst) 341 if(userFirst)
342 for(int i=0;i<32;i++) 342 for(int i=0;i<32;i++)
343 field[i]->setLabel(ruNumeration.mid(i*2,2)); 343 field[i]->setLabel(ruNumeration.mid(i*2,2));
344 else 344 else
345 for(int i=0;i<32;i++) 345 for(int i=0;i<32;i++)
346 field[i]->setLabel(ruNumeration.mid(62-i*2,2)); 346 field[i]->setLabel(ruNumeration.mid(62-i*2,2));
347 } 347 }
348} 348}
349 349
350 350
351void KCheckers::drawBoard(int i) 351void KCheckers::drawBoard(int i)
352{ 352{
353 switch(game->board[t[i]]) 353 switch(game->board[t[i]])
354 { 354 {
355 case MAN1: 355 case MAN1:
356 field[i]->setPicture(imageMan1); 356 field[i]->setPicture(imageMan1);
357 break; 357 break;
358 case MAN2: 358 case MAN2:
359 field[i]->setPicture(imageMan2); 359 field[i]->setPicture(imageMan2);
360 break; 360 break;
361 case KING1: 361 case KING1:
362 field[i]->setPicture(imageKing1); 362 field[i]->setPicture(imageKing1);
363 break; 363 break;
364 case KING2: 364 case KING2:
365 field[i]->setPicture(imageKing2); 365 field[i]->setPicture(imageKing2);
366 break; 366 break;
367 default: 367 default:
368 field[i]->setPicture(NULL); 368 field[i]->setPicture(NULL);
369 } 369 }
370} 370}
371 371
372 372
373void KCheckers::help() 373void KCheckers::help()
374{ 374{
375 QMessageBox::information(this,"Rules of Play", 375 QMessageBox::information(this,"Rules of Play",
376 "In the beginning of game you have\n" 376 "In the beginning of game you have\n"
377 "12 checkers (men).\n" 377 "12 checkers (men).\n"
378 "The men move forward only.\n" 378 "The men move forward only.\n"
379 "The men can capture:\n" 379 "The men can capture:\n"
380 "- by jumping forward only (english\n" 380 "- by jumping forward only (english\n"
381 " rules);\n" 381 " rules);\n"
382 "- by jumping forward or backward\n" 382 "- by jumping forward or backward\n"
383 " (russian rules).\n" 383 " (russian rules).\n"
384 "A man which reaches the far side of\n" 384 "A man which reaches the far side of\n"
385 "the board becomes a king.\n" 385 "the board becomes a king.\n"
386 "The kings move forward or\n" 386 "The kings move forward or\n"
387 "backward:\n" 387 "backward:\n"
388 "- to one square only (english rules);\n" 388 "- to one square only (english rules);\n"
389 "- to any number of squares (russian\n" 389 "- to any number of squares (russian\n"
390 " rules).\n" 390 " rules).\n"
391 "The kings capture by jumping\n" 391 "The kings capture by jumping\n"
392 "forward or backward.\n" 392 "forward or backward.\n"
393 "Whenever a player is able to make a\n" 393 "Whenever a player is able to make a\n"
394 "capture he must do so.", 394 "capture he must do so.",
395 QMessageBox::Ok|QMessageBox::Default); 395 QMessageBox::Ok|QMessageBox::Default);
396} 396}
397 397
398 398
399void KCheckers::about() 399void KCheckers::about()
400{ 400{
401 QMessageBox::about(this,"About KCheckers", 401 QMessageBox::about(this,"About KCheckers",
402 "KCheckers, a board game. Ver 0.3\n" 402 "KCheckers, a board game. Ver 0.3\n"
403 "(C) 2002, A. Peredri <andi@ukr.net>\n\n" 403 "(C) 2002, A. Peredri <andi@ukr.net>\n\n"
404 "http://kcheckers.tuxfamily.org\n\n" 404 "http://kcheckers.tuxfamily.org\n\n"
405 "Contributors:\n" 405 "Contributors:\n"
406 "S. Rosen <srosen@erols.com>\n\n" 406 "S. Rosen <srosen@erols.com>\n\n"
407 "Qtopia version: S.Prud'homme\n" 407 "Qtopia version: S.Prud'homme\n"
408 "<prudhomme@laposte.net>\n\n" 408 "<prudhomme@laposte.net>\n\n"
409 "This program is distributed under the\n" 409 "This program is distributed under the\n"
410 "terms of the GNU General Public\n" 410 "terms of the GNU General Public\n"
411 "License."); 411 "License.");
412} 412}
413 413
414 414
415void KCheckers::aboutQt() 415void KCheckers::aboutQt()
416{ 416{
417 QMessageBox::aboutQt(this); 417 QMessageBox::aboutQt(this);
418} 418}
419 419
420 420
421void KCheckers::newGame() 421void KCheckers::newGame()
422{ 422{
423 if(game) delete game; 423 if(game) delete game;
424 424
425 switch(rules) 425 switch(rules)
426 { 426 {
427 case ENGLISH: 427 case ENGLISH:
428 game=new ECheckers(skill); 428 game=new ECheckers(skill);
429 CHECK_PTR(game); 429 CHECK_PTR(game);
430 break; 430 break;
431 431
432 case RUSSIAN: 432 case RUSSIAN:
433 default:
433 game=new RCheckers(skill); 434 game=new RCheckers(skill);
434 CHECK_PTR(game); 435 CHECK_PTR(game);
435 } 436 }
436 437
437 unselect(); 438 unselect();
438 gameOver=false; 439 gameOver=false;
439 440
440 gameMenu->setItemEnabled(undoID,false); 441 gameMenu->setItemEnabled(undoID,false);
441 undoButton->setEnabled(false); 442 undoButton->setEnabled(false);
442 443
443 colorChange(); 444 colorChange();
444 445
445 for(int i=0;i<32;i++) drawBoard(i); 446 for(int i=0;i<32;i++) drawBoard(i);
446 if(optionsMenu->isItemChecked(numID)) drawNumeration(); 447 if(optionsMenu->isItemChecked(numID)) drawNumeration();
447 448
448 if(!userFirst) compGo(); 449 if(!userFirst) compGo();
449 450
450 statusLabel->setText(tr("Go!")); 451 statusLabel->setText(tr("Go!"));
451} 452}
452 453
453 454
454// Undo the last computer and user moves 455// Undo the last computer and user moves
455 456
456void KCheckers::undoMove() 457void KCheckers::undoMove()
457{ 458{
458 for(int i=0;i<32;i++) 459 for(int i=0;i<32;i++)
459 { 460 {
460 game->board[t[i]]=undoBoard[i]; 461 game->board[t[i]]=undoBoard[i];
461 drawBoard(i); 462 drawBoard(i);
462 } 463 }
463 464
464 unselect(); 465 unselect();
465 gameOver=false; 466 gameOver=false;
466 467
467 gameMenu->setItemEnabled(undoID,false); 468 gameMenu->setItemEnabled(undoID,false);
468 undoButton->setEnabled(false); 469 undoButton->setEnabled(false);
469 470
470 statusLabel->setText(tr("Go!")); 471 statusLabel->setText(tr("Go!"));
471} 472}
472 473
473 474
474void KCheckers::colorChange() 475void KCheckers::colorChange()
475{ 476{
476 userFirst=!userFirst; 477 userFirst=!userFirst;
477 478
478 QImage* image; 479 QImage* image;
479 image=imageMan1; 480 image=imageMan1;
480 imageMan1=imageMan2; 481 imageMan1=imageMan2;
481 imageMan2=image; 482 imageMan2=image;
482 image=imageKing1; 483 image=imageKing1;
483 imageKing1=imageKing2; 484 imageKing1=imageKing2;
484 imageKing2=image; 485 imageKing2=image;
485} 486}
486 487
487 488
488void KCheckers::unselect() 489void KCheckers::unselect()
489{ 490{
490 if(selected) field[from]->setFrame(NULL); 491 if(selected) field[from]->setFrame(NULL);
491 selected=false; 492 selected=false;
492} 493}
493 494
494 495
495void KCheckers::click(int fieldNumber) 496void KCheckers::click(int fieldNumber)
496{ 497{
497 if(gameOver) return; 498 if(gameOver) return;
498 switch(game->board[t[fieldNumber]]) 499 switch(game->board[t[fieldNumber]])
499 { 500 {
500 case MAN1: 501 case MAN1:
501 case KING1: 502 case KING1:
502 // User selected 503 // User selected
503 if(!selected) 504 if(!selected)
504 { 505 {
505 from=fieldNumber; 506 from=fieldNumber;
506 selected=true; 507 selected=true;
507 field[fieldNumber]->setFrame(imageFrame); 508 field[fieldNumber]->setFrame(imageFrame);
508 return; 509 return;
509 } 510 }
510 // User reselected 511 // User reselected
511 else 512 else
512 { 513 {
513 field[from]->setFrame(NULL); 514 field[from]->setFrame(NULL);
514 from=fieldNumber; 515 from=fieldNumber;
515 field[fieldNumber]->setFrame(imageFrame); 516 field[fieldNumber]->setFrame(imageFrame);
516 return; 517 return;
517 } 518 }
518 case FREE: 519 case FREE:
519 if(!selected) return; 520 if(!selected) return;
520 521
521 if(!userGo(fieldNumber)) return; 522 if(!userGo(fieldNumber)) return;
522 523
523 unselect(); 524 unselect();
524 525
525 if(!(game->checkMove2() || game->checkCapture2())) 526 if(!(game->checkMove2() || game->checkCapture2()))
526 { 527 {
527 gameOver=true; 528 gameOver=true;
528 statusLabel->setText(tr("Congratulation! You have won!")); 529 statusLabel->setText(tr("Congratulation! You have won!"));
529 return; 530 return;
530 } 531 }
531 532
532 statusLabel->setText(tr("Please wait...")); 533 statusLabel->setText(tr("Please wait..."));
533 qApp->processEvents(); 534 qApp->processEvents();
534 535
535 compGo(); 536 compGo();
536 if(!(game->checkMove1() || game->checkCapture1())) 537 if(!(game->checkMove1() || game->checkCapture1()))
537 { 538 {
538 gameOver=true; 539 gameOver=true;
539 statusLabel->setText(tr("You have lost. Game over.")); 540 statusLabel->setText(tr("You have lost. Game over."));
540 return; 541 return;
541 } 542 }
542 statusLabel->setText(tr("Go!")); 543 statusLabel->setText(tr("Go!"));
543 } 544 }
544} 545}
545 546
546 547
547void KCheckers::compGo() 548void KCheckers::compGo()
548{ 549{
549 int save[32]; 550 int save[32];
550 for(int i=0;i<32;i++) save[i]=game->board[t[i]]; 551 for(int i=0;i<32;i++) save[i]=game->board[t[i]];
551 552
552 game->go2(); 553 game->go2();
553 554
554 for(int i=0;i<32;i++) 555 for(int i=0;i<32;i++)
555 { 556 {
556 if(game->board[t[i]]==save[i]) continue; 557 if(game->board[t[i]]==save[i]) continue;
557 drawBoard(i); 558 drawBoard(i);
558 } 559 }
559} 560}
560 561
561 562
562bool KCheckers::userGo(int to) 563bool KCheckers::userGo(int to)
563{ 564{
564 int save[32]; 565 int save[32];
565 for(int i=0;i<32;i++) save[i]=game->board[t[i]]; 566 for(int i=0;i<32;i++) save[i]=game->board[t[i]];
566 567
567 if(!game->go1(t[from],t[to])) 568 if(!game->go1(t[from],t[to]))
568 { 569 {
569 statusLabel->setText(tr("Incorrect course.")); 570 statusLabel->setText(tr("Incorrect course."));
570 return false; 571 return false;
571 } 572 }
572 573
573 for(int i=0;i<32;i++) undoBoard[i]=save[i]; 574 for(int i=0;i<32;i++) undoBoard[i]=save[i];
574 gameMenu->setItemEnabled(undoID,true); 575 gameMenu->setItemEnabled(undoID,true);
575 undoButton->setEnabled(true); 576 undoButton->setEnabled(true);
576 577
577 for(int i=0;i<32;i++) 578 for(int i=0;i<32;i++)
578 { 579 {
579 if(game->board[t[i]]==save[i]) continue; 580 if(game->board[t[i]]==save[i]) continue;
580 drawBoard(i); 581 drawBoard(i);
581 } 582 }
582 583
583 return true; 584 return true;
584} 585}
585 586
586 587
diff --git a/noncore/todayplugins/stockticker/libstocks/currency.c b/noncore/todayplugins/stockticker/libstocks/currency.c
index e0090e2..82cd654 100644
--- a/noncore/todayplugins/stockticker/libstocks/currency.c
+++ b/noncore/todayplugins/stockticker/libstocks/currency.c
@@ -1,67 +1,66 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance 1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 * 2 *
3 * Copyright (C) 2000 Eric Laeuffer 3 * Copyright (C) 2000 Eric Laeuffer
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public 15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the 16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA. 18 * Boston, MA 02111-1307, USA.
19 */ 19 */
20 20
21#define __CURRENCY_C__ 21#define __CURRENCY_C__
22 22
23 23
24#include <stdio.h> 24#include <stdio.h>
25#include <string.h> 25#include <string.h>
26#include <malloc.h> 26#include <malloc.h>
27#include <stdlib.h> 27#include <stdlib.h>
28 28
29#include "stocks.h" 29#include "stocks.h"
30 30
31/*****************************************************************************/ 31/*****************************************************************************/
32/* returns the currency exchange rate of "from" currency into */ 32/* returns the currency exchange rate of "from" currency into */
33/* "into" currency. */ 33/* "into" currency. */
34/*****************************************************************************/ 34/*****************************************************************************/
35libstocks_return_code get_currency_exchange(char *from, 35libstocks_return_code get_currency_exchange(char *from,
36 char *into, 36 char *into,
37 float *exchange) 37 float *exchange)
38{ 38{
39 char *symbol; 39 char *symbol;
40 stock *data; 40 stock *data;
41 libstocks_return_code error; 41 libstocks_return_code error;
42 42
43 if((symbol = (char *)malloc(strlen(from)+strlen(into)+3))==NULL) 43 if((symbol = (char *)malloc(strlen(from)+strlen(into)+3))==NULL)
44 { 44 {
45 fprintf(stderr,"Memory allocating error (%s line %d)\n" 45 fprintf(stderr,"Memory allocating error (%s line %d)\n"
46 ,__FILE__, __LINE__); 46 ,__FILE__, __LINE__);
47 exit(1); 47 exit(1);
48 } 48 }
49 49
50 strcpy(symbol, from); 50 strcpy(symbol, from);
51 strcat(symbol, into); 51 strcat(symbol, into);
52 strcat(symbol, "=X"); 52 strcat(symbol, "=X");
53 53
54 error = get_stocks(symbol, &data); 54 error = get_stocks(symbol, &data);
55 free(symbol); 55 free(symbol);
56 if (error) 56 if (error)
57 { 57 {
58 *exchange = 0; 58 *exchange = 0;
59 return(error); 59 return error;
60 } 60 }
61 61
62 free_stocks(data);
63
64 *exchange = data->CurrentPrice; 62 *exchange = data->CurrentPrice;
65 return(error); 63 free_stocks(data);
64 return error;
66 65
67} 66}