summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/notesapplet/notes.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
index f2dbabf..92fdb0a 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -185,269 +185,269 @@ void NotesControl::slotDeleteButton() {
185 entryName.sprintf( "File%i", noOfFiles ); 185 entryName.sprintf( "File%i", noOfFiles );
186 cfg.removeEntry(entryName); 186 cfg.removeEntry(entryName);
187 cfg.write(); 187 cfg.write();
188 DocLnk nf(selectedText); 188 DocLnk nf(selectedText);
189 nf.removeFiles(); 189 nf.removeFiles();
190 } 190 }
191 } 191 }
192 populateBox(); 192 populateBox();
193 } 193 }
194} 194}
195 195
196void NotesControl::slotNewButton() { 196void NotesControl::slotNewButton() {
197 if(edited) save(); 197 if(edited) save();
198 view->clear(); 198 view->clear();
199 view->setFocus(); 199 view->setFocus();
200} 200}
201 201
202void NotesControl::slotBeamButton() { 202void NotesControl::slotBeamButton() {
203 Ir ir; 203 Ir ir;
204 if(!ir.supported()){ 204 if(!ir.supported()){
205 } else { 205 } else {
206 this->hide(); 206 this->hide();
207 QString selectedText = box->currentText(); 207 QString selectedText = box->currentText();
208 if( !selectedText.isEmpty()) { 208 if( !selectedText.isEmpty()) {
209 QString file = QDir::homeDirPath()+"/"+selectedText; 209 QString file = QDir::homeDirPath()+"/"+selectedText;
210 QFile f(file); 210 QFile f(file);
211 Ir *irFile = new Ir(this, "IR"); 211 Ir *irFile = new Ir(this, "IR");
212 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * ))); 212 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * )));
213 irFile->send( file, "Note", "text/plain" ); 213 irFile->send( file, "Note", "text/plain" );
214 } 214 }
215 } 215 }
216} 216}
217 217
218void NotesControl::slotBeamFinished(Ir *) { 218void NotesControl::slotBeamFinished(Ir *) {
219 this->show(); 219 this->show();
220} 220}
221 221
222void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) { 222void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) {
223 switch (mouse) { 223 switch (mouse) {
224 case 1:{ 224 case 1:{
225 } 225 }
226 break; 226 break;
227 case 2: 227 case 2:
228 menuTimer.start( 500, TRUE ); 228 menuTimer.start( 500, TRUE );
229 break; 229 break;
230 }; 230 };
231} 231}
232 232
233void NotesControl::slotBoxSelected(const QString &itemString) { 233void NotesControl::slotBoxSelected(const QString &itemString) {
234 if(edited) { 234 if(edited) {
235 save(); 235 save();
236 } 236 }
237 loaded=false; 237 loaded=false;
238 edited=false; 238 edited=false;
239 load(itemString); 239 load(itemString);
240} 240}
241 241
242 242
243void NotesControl::showMenu() { 243void NotesControl::showMenu() {
244 QPopupMenu *m = new QPopupMenu(0); 244 QPopupMenu *m = new QPopupMenu(0);
245 245
246 m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() )); 246 m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() ));
247 m->insertSeparator(); 247 m->insertSeparator();
248 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); 248 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() ));
249 m->setFocus(); 249 m->setFocus();
250 m->exec( QCursor::pos() ); 250 m->exec( QCursor::pos() );
251 251
252 if(m) delete m; 252 if(m) delete m;
253 253
254} 254}
255 255
256void NotesControl::focusOutEvent ( QFocusEvent * e) { 256void NotesControl::focusOutEvent ( QFocusEvent * e) {
257 if( e->reason() == QFocusEvent::Popup) 257 if( e->reason() == QFocusEvent::Popup)
258 save(); 258 save();
259 else { 259 else {
260 if(!loaded) { 260 if(!loaded) {
261 populateBox(); 261 populateBox();
262 load(); 262 load();
263 } 263 }
264 } 264 }
265 QWidget::focusOutEvent(e); 265 QWidget::focusOutEvent(e);
266} 266}
267 267
268void NotesControl::save() { 268void NotesControl::save() {
269 Config cfg("Notes"); 269 Config cfg("Notes");
270 cfg.setGroup("Docs"); 270 cfg.setGroup("Docs");
271 if( edited) { 271 if( edited) {
272 QString rt = view->text(); 272 QString rt = view->text();
273 if(!rt.isEmpty()) { 273 if(!rt.isEmpty()) {
274 QString pt = rt.simplifyWhiteSpace(); 274 QString pt = rt.simplifyWhiteSpace();
275 int i = pt.find( ' ' ); 275 int i = pt.find( ' ' );
276 QString docname = pt; 276 QString docname = pt;
277 if ( i > 0 ) 277 if ( i > 0 )
278 docname = pt.left( i ); 278 docname = pt.left( i );
279 // remove "." at the beginning 279 // remove "." at the beginning
280 while( docname.startsWith( "." ) ) 280 while( docname.startsWith( "." ) )
281 docname = docname.mid( 1 ); 281 docname = docname.mid( 1 );
282 docname.replace( QRegExp("/"), "_" ); 282 docname.replace( QRegExp("/"), "_" );
283 // cut the length. filenames longer than that don't make sense 283 // cut the length. filenames longer than that don't make sense
284 // and something goes wrong when they get too long. 284 // and something goes wrong when they get too long.
285 if ( docname.length() > 40 ) 285 if ( docname.length() > 40 )
286 docname = docname.left(40); 286 docname = docname.left(40);
287 if ( docname.isEmpty() ) 287 if ( docname.isEmpty() )
288 docname = "Empty Text"; 288 docname = "Empty Text";
289 qDebug(docname); 289 qDebug(docname);
290 290
291 if( oldDocName != docname) { 291 if( oldDocName != docname) {
292 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 292 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
293 QString entryName; 293 QString entryName;
294 entryName.sprintf( "File%i", noOfFiles + 1 ); 294 entryName.sprintf( "File%i", noOfFiles + 1 );
295 cfg.writeEntry( entryName,docname ); 295 cfg.writeEntry( entryName,docname );
296 cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); 296 cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
297 cfg.write(); 297 cfg.write();
298 } 298 }
299 else 299 else
300 qDebug("oldname equals docname"); 300 qDebug("oldname equals docname");
301 doc = new DocLnk(docname); 301 doc = new DocLnk(docname);
302 302
303 doc->setType("text/plain"); 303 doc->setType("text/plain");
304 doc->setFile(docname); 304 doc->setFile(docname);
305 doc->setName(docname); 305 doc->setName(docname);
306 306
307 FileManager fm; 307 FileManager fm;
308 if ( !fm.saveFile( *doc, rt ) ) { 308 if ( !fm.saveFile( *doc, rt ) ) {
309 } 309 }
310 310
311 oldDocName=docname; 311 oldDocName=docname;
312 edited=false; 312 edited=false;
313 qDebug("save"); 313// qDebug("save");
314 if (doPopulate) 314 if (doPopulate)
315 populateBox(); 315 populateBox();
316 } 316 }
317 cfg.writeEntry( "LastDoc",oldDocName ); 317 cfg.writeEntry( "LastDoc",oldDocName );
318 cfg.write(); 318 cfg.write();
319 319
320 } 320 }
321} 321}
322 322
323void NotesControl::populateBox() { 323void NotesControl::populateBox() {
324 box->clear(); 324 box->clear();
325 qDebug("populate"); 325// qDebug("populate");
326 Config cfg("Notes"); 326 Config cfg("Notes");
327 cfg.setGroup("Docs"); 327 cfg.setGroup("Docs");
328 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 328 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
329 QStringList list; 329 QStringList list;
330 QString entryName; 330 QString entryName;
331 for ( int i = 0; i < noOfFiles; i++ ) { 331 for ( int i = 0; i < noOfFiles; i++ ) {
332 entryName.sprintf( "File%i", i + 1 ); 332 entryName.sprintf( "File%i", i + 1 );
333 list.append(cfg.readEntry( entryName )); 333 list.append(cfg.readEntry( entryName ));
334 } 334 }
335 list.sort(); 335 list.sort();
336 box->insertStringList(list,-1); 336 box->insertStringList(list,-1);
337 doPopulate=false; 337 doPopulate=false;
338 update(); 338 update();
339} 339}
340 340
341void NotesControl::load() { 341void NotesControl::load() {
342 342
343 if(!loaded) { 343 if(!loaded) {
344 Config cfg("Notes"); 344 Config cfg("Notes");
345 cfg.setGroup("Docs"); 345 cfg.setGroup("Docs");
346 QString lastDoc=cfg.readEntry( "LastDoc",""); 346 QString lastDoc=cfg.readEntry( "LastDoc","");
347 DocLnk nf; 347 DocLnk nf;
348 nf.setType("text/plain"); 348 nf.setType("text/plain");
349 nf.setFile(lastDoc); 349 nf.setFile(lastDoc);
350 350
351 loadDoc(nf); 351 loadDoc(nf);
352 loaded=true; 352 loaded=true;
353 oldDocName=lastDoc; 353 oldDocName=lastDoc;
354 cfg.writeEntry( "LastDoc",oldDocName ); 354 cfg.writeEntry( "LastDoc",oldDocName );
355 cfg.write(); 355 cfg.write();
356 } 356 }
357} 357}
358 358
359void NotesControl::load(const QString & file) { 359void NotesControl::load(const QString & file) {
360 qDebug("loading "+file); 360 qDebug("loading "+file);
361 if(!loaded) { 361 if(!loaded) {
362 DocLnk nf; 362 DocLnk nf;
363 nf.setType("text/plain"); 363 nf.setType("text/plain");
364 nf.setFile( file); 364 nf.setFile( file);
365 365
366 loadDoc(nf); 366 loadDoc(nf);
367 loaded=true; 367 loaded=true;
368 } 368 }
369// view->setFocus(); 369// view->setFocus();
370 oldDocName=file; 370 oldDocName=file;
371 Config cfg("Notes"); 371 Config cfg("Notes");
372 cfg.setGroup("Docs"); 372 cfg.setGroup("Docs");
373 cfg.writeEntry( "LastDoc",oldDocName ); 373 cfg.writeEntry( "LastDoc",oldDocName );
374 cfg.write(); 374 cfg.write();
375} 375}
376 376
377void NotesControl::loadDoc( const DocLnk &f) { 377void NotesControl::loadDoc( const DocLnk &f) {
378 FileManager fm; 378 FileManager fm;
379 QString txt; 379 QString txt;
380 if ( !fm.loadFile( f, txt ) ) { 380 if ( !fm.loadFile( f, txt ) ) {
381 return; 381 return;
382 } 382 }
383 view->setText(txt); 383 view->setText(txt);
384} 384}
385 385
386void NotesControl::slotViewEdited() { 386void NotesControl::slotViewEdited() {
387 if(loaded) { 387 if(loaded) {
388 edited=true; 388 edited=true;
389 } 389 }
390} 390}
391 391
392// void NotesControl::keyReleaseEvent( QKeyEvent *e) { 392// void NotesControl::keyReleaseEvent( QKeyEvent *e) {
393 393
394// switch ( e->state() ) { 394// switch ( e->state() ) {
395// case ControlButton: 395// case ControlButton:
396// if(e->key() == Key_C) { //copy 396// if(e->key() == Key_C) { //copy
397// qDebug("copy"); 397// qDebug("copy");
398// QClipboard *cb = QApplication::clipboard(); 398// QClipboard *cb = QApplication::clipboard();
399// QString text; 399// QString text;
400 400
401// // Copy text from the clipboard (paste) 401// // Copy text from the clipboard (paste)
402// text = cb->text(); 402// text = cb->text();
403// } 403// }
404// if(e->key() == Key_X) { //cut 404// if(e->key() == Key_X) { //cut
405// } 405// }
406// if(e->key() == Key_V) { //paste 406// if(e->key() == Key_V) { //paste
407// QClipboard *cb = QApplication::clipboard(); 407// QClipboard *cb = QApplication::clipboard();
408// QString text; 408// QString text;
409// //view 409// //view
410// cb->setText(); 410// cb->setText();
411// } 411// }
412// break; 412// break;
413// }; 413// };
414// QWidget::keyReleaseEvent(e); 414// QWidget::keyReleaseEvent(e);
415// } 415// }
416 416
417//=========================================================================== 417//===========================================================================
418 418
419NotesApplet::NotesApplet( QWidget *parent, const char *name ) 419NotesApplet::NotesApplet( QWidget *parent, const char *name )
420 : QWidget( parent, name ) { 420 : QWidget( parent, name ) {
421 setFixedHeight( 18 ); 421 setFixedHeight( 18 );
422 setFixedWidth( 14 ); 422 setFixedWidth( 14 );
423 vc = new NotesControl; 423 vc = new NotesControl;
424} 424}
425 425
426NotesApplet::~NotesApplet() { 426NotesApplet::~NotesApplet() {
427} 427}
428 428
429void NotesApplet::mousePressEvent( QMouseEvent *) { 429void NotesApplet::mousePressEvent( QMouseEvent *) {
430 if( !vc->isHidden()) { 430 if( !vc->isHidden()) {
431 vc->doPopulate=false; 431 vc->doPopulate=false;
432 vc->save(); 432 vc->save();
433 vc->close(); 433 vc->close();
434 } else { 434 } else {
435// vc = new NotesControl; 435// vc = new NotesControl;
436// QPoint curPos = mapToGlobal( rect().topLeft() ); 436// QPoint curPos = mapToGlobal( rect().topLeft() );
437 vc->show(); 437 vc->show();
438 vc->move( 2, 28); 438 vc->move( 2, 28);
439 vc->doPopulate=true; 439 vc->doPopulate=true;
440 vc->populateBox(); 440 vc->populateBox();
441 vc->doPopulate=false; 441 vc->doPopulate=false;
442 vc->loaded=false; 442 vc->loaded=false;
443 443
444 vc->load(); 444 vc->load();
445// this->setFocus(); 445// this->setFocus();
446 vc->view->setFocus(); 446 vc->view->setFocus();
447 } 447 }
448} 448}
449 449
450void NotesApplet::paintEvent( QPaintEvent* ) { 450void NotesApplet::paintEvent( QPaintEvent* ) {
451 QPainter p(this); 451 QPainter p(this);
452 p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); 452 p.drawPixmap( 0, 1, ( const char** ) notes_xpm );
453} 453}