summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-09-22 01:21:48 (UTC)
committer llornkcor <llornkcor>2002-09-22 01:21:48 (UTC)
commit4ad2edeaf52db70042ba27a97e16733cbc6a8cc0 (patch) (unidiff)
treeab2adb51887a5a1ceece5b2ba4b1131c13cc36d7
parentad9e290551c610e4ccaafb20b72699b39b55d079 (diff)
downloadopie-4ad2edeaf52db70042ba27a97e16733cbc6a8cc0.zip
opie-4ad2edeaf52db70042ba27a97e16733cbc6a8cc0.tar.gz
opie-4ad2edeaf52db70042ba27a97e16733cbc6a8cc0.tar.bz2
fix race
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/notesapplet/notes.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
index 64731e3..a4aa093 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -177,187 +177,187 @@ void NotesControl::slotBoxSelected(const QString &itemString) {
177 loaded=false; 177 loaded=false;
178 edited=false; 178 edited=false;
179 load(itemString); 179 load(itemString);
180} 180}
181 181
182 182
183void NotesControl::showMenu() { 183void NotesControl::showMenu() {
184 QPopupMenu *m = new QPopupMenu(0); 184 QPopupMenu *m = new QPopupMenu(0);
185 185
186 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); 186 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() ));
187 187
188 m->setFocus(); 188 m->setFocus();
189 m->exec( QCursor::pos() ); 189 m->exec( QCursor::pos() );
190 190
191 if(m) delete m; 191 if(m) delete m;
192 192
193} 193}
194 194
195void NotesControl::focusOutEvent ( QFocusEvent * e) { 195void NotesControl::focusOutEvent ( QFocusEvent * e) {
196 if( e->reason() == QFocusEvent::Popup) 196 if( e->reason() == QFocusEvent::Popup)
197 save(); 197 save();
198 else { 198 else {
199 if(!loaded) { 199 if(!loaded) {
200 populateBox(); 200 populateBox();
201 load(); 201 load();
202 } 202 }
203 } 203 }
204 QWidget::focusOutEvent(e); 204 QWidget::focusOutEvent(e);
205} 205}
206 206
207void NotesControl::save() { 207void NotesControl::save() {
208 Config cfg("Notes"); 208 Config cfg("Notes");
209 cfg.setGroup("Docs"); 209 cfg.setGroup("Docs");
210 if( edited) { 210 if( edited) {
211 QString rt = view->text(); 211 QString rt = view->text();
212 if(!rt.isEmpty()) { 212 if(!rt.isEmpty()) {
213 QString pt = rt.simplifyWhiteSpace(); 213 QString pt = rt.simplifyWhiteSpace();
214 int i = pt.find( ' ' ); 214 int i = pt.find( ' ' );
215 QString docname = pt; 215 QString docname = pt;
216 if ( i > 0 ) 216 if ( i > 0 )
217 docname = pt.left( i ); 217 docname = pt.left( i );
218 // remove "." at the beginning 218 // remove "." at the beginning
219 while( docname.startsWith( "." ) ) 219 while( docname.startsWith( "." ) )
220 docname = docname.mid( 1 ); 220 docname = docname.mid( 1 );
221 docname.replace( QRegExp("/"), "_" ); 221 docname.replace( QRegExp("/"), "_" );
222 // cut the length. filenames longer than that don't make sense 222 // cut the length. filenames longer than that don't make sense
223 // and something goes wrong when they get too long. 223 // and something goes wrong when they get too long.
224 if ( docname.length() > 40 ) 224 if ( docname.length() > 40 )
225 docname = docname.left(40); 225 docname = docname.left(40);
226 if ( docname.isEmpty() ) 226 if ( docname.isEmpty() )
227 docname = "Empty Text"; 227 docname = "Empty Text";
228 qDebug(docname); 228 qDebug(docname);
229 229
230 if( oldDocName != docname) { 230 if( oldDocName != docname) {
231 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 231 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
232 QString entryName; 232 QString entryName;
233 entryName.sprintf( "File%i", noOfFiles + 1 ); 233 entryName.sprintf( "File%i", noOfFiles + 1 );
234 cfg.writeEntry( entryName,docname ); 234 cfg.writeEntry( entryName,docname );
235 cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); 235 cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
236 cfg.write(); 236 cfg.write();
237 } 237 }
238 doc = new DocLnk(docname); 238 doc = new DocLnk(docname);
239 239
240 doc->setType("text/plain"); 240 doc->setType("text/plain");
241 doc->setFile(docname); 241 doc->setFile(docname);
242 doc->setName(docname); 242 doc->setName(docname);
243 243
244 FileManager fm; 244 FileManager fm;
245 if ( !fm.saveFile( *doc, rt ) ) { 245 if ( !fm.saveFile( *doc, rt ) ) {
246 } 246 }
247 247
248 oldDocName=docname; 248 oldDocName=docname;
249 edited=false; 249 edited=false;
250 } 250 }
251 qDebug("save"); 251 qDebug("save");
252 if (doPopulate) 252 if (doPopulate)
253 populateBox(); 253 populateBox();
254 } 254 }
255 cfg.writeEntry( "LastDoc",oldDocName ); 255 cfg.writeEntry( "LastDoc",oldDocName );
256 cfg.write(); 256 cfg.write();
257} 257}
258 258
259void NotesControl::populateBox() { 259void NotesControl::populateBox() {
260 box->clear(); 260 box->clear();
261 qDebug("populate"); 261 qDebug("populate");
262 Config cfg("Notes"); 262 Config cfg("Notes");
263 cfg.setGroup("Docs"); 263 cfg.setGroup("Docs");
264 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 264 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
265 QStringList list; 265 QStringList list;
266 QString entryName; 266 QString entryName;
267 for ( int i = 0; i < noOfFiles; i++ ) { 267 for ( int i = 0; i < noOfFiles; i++ ) {
268 entryName.sprintf( "File%i", i + 1 ); 268 entryName.sprintf( "File%i", i + 1 );
269 list.append(cfg.readEntry( entryName )); 269 list.append(cfg.readEntry( entryName ));
270 } 270 }
271 list.sort(); 271 list.sort();
272 box->insertStringList(list,-1); 272 box->insertStringList(list,-1);
273 273 doPopulate=false;
274} 274}
275 275
276void NotesControl::load() { 276void NotesControl::load() {
277 277
278 Config cfg("Notes"); 278 Config cfg("Notes");
279 cfg.setGroup("Docs"); 279 cfg.setGroup("Docs");
280 if(!loaded) { 280 if(!loaded) {
281 QString lastDoc=cfg.readEntry( "LastDoc",""); 281 QString lastDoc=cfg.readEntry( "LastDoc","");
282 DocLnk nf; 282 DocLnk nf;
283 nf.setType("text/plain"); 283 nf.setType("text/plain");
284 nf.setFile(lastDoc); 284 nf.setFile(lastDoc);
285 285
286 loadDoc(nf); 286 loadDoc(nf);
287 loaded=true; 287 loaded=true;
288 oldDocName=lastDoc; 288 oldDocName=lastDoc;
289 } 289 }
290 cfg.writeEntry( "LastDoc",oldDocName ); 290 cfg.writeEntry( "LastDoc",oldDocName );
291 cfg.write(); 291 cfg.write();
292} 292}
293 293
294void NotesControl::load(const QString & file) { 294void NotesControl::load(const QString & file) {
295 qDebug("loading "+file); 295 qDebug("loading "+file);
296 if(!loaded) { 296 if(!loaded) {
297 DocLnk nf; 297 DocLnk nf;
298 nf.setType("text/plain"); 298 nf.setType("text/plain");
299 nf.setFile( file); 299 nf.setFile( file);
300 300
301 loadDoc(nf); 301 loadDoc(nf);
302 loaded=true; 302 loaded=true;
303 } 303 }
304// view->setFocus(); 304// view->setFocus();
305 oldDocName=file; 305 oldDocName=file;
306 Config cfg("Notes"); 306 Config cfg("Notes");
307 cfg.setGroup("Docs"); 307 cfg.setGroup("Docs");
308 cfg.writeEntry( "LastDoc",oldDocName ); 308 cfg.writeEntry( "LastDoc",oldDocName );
309 cfg.write(); 309 cfg.write();
310} 310}
311 311
312void NotesControl::loadDoc( const DocLnk &f) { 312void NotesControl::loadDoc( const DocLnk &f) {
313 FileManager fm; 313 FileManager fm;
314 QString txt; 314 QString txt;
315 if ( !fm.loadFile( f, txt ) ) { 315 if ( !fm.loadFile( f, txt ) ) {
316 return; 316 return;
317 } 317 }
318 view->setText(txt); 318 view->setText(txt);
319} 319}
320 320
321void NotesControl::slotViewEdited() { 321void NotesControl::slotViewEdited() {
322 if(loaded) { 322 if(loaded) {
323 edited=true; 323 edited=true;
324 } 324 }
325} 325}
326 326
327//=========================================================================== 327//===========================================================================
328 328
329NotesApplet::NotesApplet( QWidget *parent, const char *name ) 329NotesApplet::NotesApplet( QWidget *parent, const char *name )
330 : QWidget( parent, name ) { 330 : QWidget( parent, name ) {
331 setFixedHeight( 18 ); 331 setFixedHeight( 18 );
332 setFixedWidth( 14 ); 332 setFixedWidth( 14 );
333 vc = new NotesControl; 333 vc = new NotesControl;
334} 334}
335 335
336NotesApplet::~NotesApplet() { 336NotesApplet::~NotesApplet() {
337} 337}
338 338
339void NotesApplet::mousePressEvent( QMouseEvent *) { 339void NotesApplet::mousePressEvent( QMouseEvent *) {
340 if( !vc->isHidden()) { 340 if( !vc->isHidden()) {
341 vc->doPopulate=false; 341 vc->doPopulate=false;
342 vc->save(); 342 vc->save();
343 vc->close(); 343 vc->close();
344 } else { 344 } else {
345// vc = new NotesControl; 345// vc = new NotesControl;
346// QPoint curPos = mapToGlobal( rect().topLeft() ); 346// QPoint curPos = mapToGlobal( rect().topLeft() );
347 vc->show(); 347 vc->show();
348 vc->move( 5, 18); 348 vc->move( 5, 18);
349 vc->doPopulate=true; 349 vc->doPopulate=true;
350 vc->populateBox(); 350 vc->populateBox();
351 vc->load(); 351 vc->doPopulate=false;
352 352
353 353 vc->load();
354 this->setFocus(); 354// this->setFocus();
355 vc->view->setFocus(); 355 vc->view->setFocus();
356 } 356 }
357} 357}
358 358
359void NotesApplet::paintEvent( QPaintEvent* ) { 359void NotesApplet::paintEvent( QPaintEvent* ) {
360 QPainter p(this); 360 QPainter p(this);
361 p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); 361 p.drawPixmap( 0, 1, ( const char** ) notes_xpm );
362} 362}
363 363