summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/notesapplet/notes.cpp70
-rw-r--r--noncore/applets/notesapplet/notes.h3
2 files changed, 57 insertions, 16 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
index 90c2550..2b25476 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -80,13 +80,23 @@ static char * notes_xpm[] = {
80 80
81 81
82NotesControl::NotesControl( QWidget *parent, const char *name ) 82NotesControl::NotesControl( QWidget *parent, const char *name )
83 : QFrame( parent, name,/* WDestructiveClose | */WStyle_StaysOnTop ) 83 : QFrame( parent, name,/* WDestructiveClose | */WStyle_StaysOnTop )
84// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 84// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
85{ 85{
86 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 86 QDir d( QDir::homeDirPath()+"/notes");
87 if( !d.exists()) {
88 qDebug("make dir");
89 if(!d.mkdir( QDir::homeDirPath()+"/notes", true))
90 qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed");
91 }
92 Config cfg("Notes");
93 cfg.setGroup("Options");
94 showMax = cfg.readBoolEntry("ShowMax", false);
95
96 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
87 loaded=false; 97 loaded=false;
88 edited=false; 98 edited=false;
89 doPopulate=true; 99 doPopulate=true;
90 isNew=false; 100 isNew=false;
91 QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" ); 101 QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" );
92 QHBoxLayout *hbox = new QHBoxLayout( this, 0, -1, "HLayout" ); 102 QHBoxLayout *hbox = new QHBoxLayout( this, 0, -1, "HLayout" );
@@ -102,16 +112,12 @@ NotesControl::NotesControl( QWidget *parent, const char *name )
102 vbox->setMargin( 6 ); 112 vbox->setMargin( 6 );
103 vbox->setSpacing( 3 ); 113 vbox->setSpacing( 3 );
104 114
105 vbox->addWidget( view); 115 vbox->addWidget( view);
106 vbox->addWidget( box); 116 vbox->addWidget( box);
107 117
108 setFixedHeight(180);
109 QWidget *wid = QPEApplication::desktop();
110 setFixedWidth( wid->width()-10 /*200*/);
111
112 setFocusPolicy(QWidget::StrongFocus); 118 setFocusPolicy(QWidget::StrongFocus);
113 119
114 newButton= new QPushButton( this, "newButton" ); 120 newButton= new QPushButton( this, "newButton" );
115 newButton->setText(tr("New")); 121 newButton->setText(tr("New"));
116 hbox->addWidget( newButton); 122 hbox->addWidget( newButton);
117 123
@@ -250,21 +256,21 @@ void NotesControl::slotBoxSelected(const QString &itemString) {
250 load(itemString); 256 load(itemString);
251} 257}
252 258
253 259
254void NotesControl::showMenu() { 260void NotesControl::showMenu() {
255 QPopupMenu *m = new QPopupMenu(0); 261 QPopupMenu *m = new QPopupMenu(0);
256
257 m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() )); 262 m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() ));
263 m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() ));
264 m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() ));
258 m->insertSeparator(); 265 m->insertSeparator();
259 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); 266 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() ));
260 m->setFocus(); 267 m->setFocus();
261 m->exec( QCursor::pos() ); 268 m->exec( QCursor::pos() );
262 269
263 if(m) delete m; 270 if(m) delete m;
264
265} 271}
266 272
267void NotesControl::focusOutEvent ( QFocusEvent * e) { 273void NotesControl::focusOutEvent ( QFocusEvent * e) {
268 if( e->reason() == QFocusEvent::Popup) 274 if( e->reason() == QFocusEvent::Popup)
269 save(); 275 save();
270 else { 276 else {
@@ -281,16 +287,16 @@ void NotesControl::save() {
281 cfg.setGroup("Docs"); 287 cfg.setGroup("Docs");
282 if( edited) { 288 if( edited) {
283// qDebug("is edited"); 289// qDebug("is edited");
284 QString rt = view->text(); 290 QString rt = view->text();
285 if( rt.length()>1) { 291 if( rt.length()>1) {
286 QString pt = rt.simplifyWhiteSpace(); 292 QString pt = rt.simplifyWhiteSpace();
287 int i = pt.find( ' ' ); 293 int i = pt.find( ' ', pt.find( ' ' )+2 );
288 QString docname = pt; 294 QString docname = pt;
289 if ( i > 0 ) 295 if ( i > 0 )
290 docname = pt.left( i ); 296 docname = pt.left(i);
291 // remove "." at the beginning 297 // remove "." at the beginning
292 while( docname.startsWith( "." ) ) 298 while( docname.startsWith( "." ) )
293 docname = docname.mid( 1 ); 299 docname = docname.mid( 1 );
294 docname.replace( QRegExp("/"), "_" ); 300 docname.replace( QRegExp("/"), "_" );
295 // cut the length. filenames longer than that don't make sense 301 // cut the length. filenames longer than that don't make sense
296 // and something goes wrong when they get too long. 302 // and something goes wrong when they get too long.
@@ -308,21 +314,19 @@ void NotesControl::save() {
308 cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); 314 cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
309 cfg.write(); 315 cfg.write();
310 } 316 }
311// else 317// else
312// qDebug("oldname equals docname"); 318// qDebug("oldname equals docname");
313 319
314
315 doc = new DocLnk(docname); 320 doc = new DocLnk(docname);
316
317 if(QFile(doc->linkFile()).exists()) 321 if(QFile(doc->linkFile()).exists())
318 qDebug("puppie"); 322 qDebug("puppie");
319 doc->setType("text/plain"); 323 doc->setType("text/plain");
320 doc->setFile(QDir::homeDirPath()+"/"+docname);
321 doc->setName(docname); 324 doc->setName(docname);
322 325 QString temp = docname.replace( QRegExp(" "), "_" );
326 doc->setFile( QDir::homeDirPath()+"/notes/"+temp);
323 FileManager fm; 327 FileManager fm;
324 if ( !fm.saveFile( *doc, rt ) ) { 328 if ( !fm.saveFile( *doc, rt ) ) {
325 } 329 }
326 330
327 oldDocName=docname; 331 oldDocName=docname;
328 edited=false; 332 edited=false;
@@ -371,16 +375,22 @@ void NotesControl::load() {
371 cfg.write(); 375 cfg.write();
372 } 376 }
373} 377}
374 378
375void NotesControl::load(const QString & file) { 379void NotesControl::load(const QString & file) {
376 qDebug("loading "+file); 380 qDebug("loading "+file);
377 if(!loaded) { 381 QString name = file;
382 QString temp;
383 if( !QFile( QDir::homeDirPath()+"/"+file).exists() )
384 temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" );
385 else
386 temp = name;
387 if(!loaded) {
378 DocLnk nf; 388 DocLnk nf;
379 nf.setType("text/plain"); 389 nf.setType("text/plain");
380 nf.setFile( file); 390 nf.setFile( temp);
381 391
382 loadDoc(nf); 392 loadDoc(nf);
383 loaded=true; 393 loaded=true;
384 } 394 }
385// view->setFocus(); 395// view->setFocus();
386 oldDocName=file; 396 oldDocName=file;
@@ -391,23 +401,41 @@ void NotesControl::load(const QString & file) {
391} 401}
392 402
393void NotesControl::loadDoc( const DocLnk &f) { 403void NotesControl::loadDoc( const DocLnk &f) {
394 FileManager fm; 404 FileManager fm;
395 QString txt; 405 QString txt;
396 if ( !fm.loadFile( f, txt ) ) { 406 if ( !fm.loadFile( f, txt ) ) {
407 qDebug("could not load file "+f.file());
397 return; 408 return;
398 } 409 }
399 view->setText(txt); 410 view->setText(txt);
400} 411}
401 412
402void NotesControl::slotViewEdited() { 413void NotesControl::slotViewEdited() {
403 if(loaded) { 414 if(loaded) {
404 edited=true; 415 edited=true;
405 } 416 }
406} 417}
407 418
419
420void NotesControl::slotShowMax() {
421 Config cfg("Notes");
422 cfg.setGroup("Options");
423 showMax=!showMax;
424 cfg.writeEntry("ShowMax", showMax);
425 cfg.write();
426 hide();
427}
428
429void NotesControl::slotSearch() {
430 int boxCount = box->count();
431 for(int i=0;i< boxCount;i++) {
432
433 }
434}
435
408// void NotesControl::keyReleaseEvent( QKeyEvent *e) { 436// void NotesControl::keyReleaseEvent( QKeyEvent *e) {
409 437
410// switch ( e->state() ) { 438// switch ( e->state() ) {
411// case ControlButton: 439// case ControlButton:
412// if(e->key() == Key_C) { //copy 440// if(e->key() == Key_C) { //copy
413// qDebug("copy"); 441// qDebug("copy");
@@ -447,14 +475,24 @@ void NotesApplet::mousePressEvent( QMouseEvent *) {
447 vc->doPopulate=false; 475 vc->doPopulate=false;
448 vc->save(); 476 vc->save();
449 vc->close(); 477 vc->close();
450 } else { 478 } else {
451// vc = new NotesControl; 479// vc = new NotesControl;
452// QPoint curPos = mapToGlobal( rect().topLeft() ); 480// QPoint curPos = mapToGlobal( rect().topLeft() );
481 if(vc->showMax) {
482 qDebug("show max");
483 vc->showMaximized();
484 } else {
485 qDebug("no show max");
486 QWidget *wid = QPEApplication::desktop();
487 QRect rect = QApplication::desktop()->geometry();
488 vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180);
489 vc->move ( (rect.center()/2) - (vc->rect().center()/2));
490// vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28);
491 }
453 vc->show(); 492 vc->show();
454 vc->move( 2, 28);
455 vc->doPopulate=true; 493 vc->doPopulate=true;
456 vc->populateBox(); 494 vc->populateBox();
457 vc->doPopulate=false; 495 vc->doPopulate=false;
458 vc->loaded=false; 496 vc->loaded=false;
459 497
460 vc->load(); 498 vc->load();
diff --git a/noncore/applets/notesapplet/notes.h b/noncore/applets/notesapplet/notes.h
index 381dc80..c428efe 100644
--- a/noncore/applets/notesapplet/notes.h
+++ b/noncore/applets/notesapplet/notes.h
@@ -39,23 +39,26 @@ public:
39 QPixmap notes; 39 QPixmap notes;
40 QMultiLineEdit *view; 40 QMultiLineEdit *view;
41 QListBox *box; 41 QListBox *box;
42 QPushButton *saveButton, *deleteButton, *newButton; 42 QPushButton *saveButton, *deleteButton, *newButton;
43 QString FileNamePath; 43 QString FileNamePath;
44 bool loaded, edited, doPopulate, isNew; 44 bool loaded, edited, doPopulate, isNew;
45 bool showMax;
45 void save(); 46 void save();
46 void populateBox(); 47 void populateBox();
47 void load(); 48 void load();
48 49
49private: 50private:
50 QTimer menuTimer; 51 QTimer menuTimer;
51 DocLnk *doc; 52 DocLnk *doc;
52 QString oldDocName; 53 QString oldDocName;
53 void focusOutEvent( QFocusEvent * ); 54 void focusOutEvent( QFocusEvent * );
54 void load(const QString&); 55 void load(const QString&);
55private slots: 56private slots:
57 void slotSearch();
58 void slotShowMax();
56 void slotBeamButton(); 59 void slotBeamButton();
57 void slotBeamFinished( Ir*); 60 void slotBeamFinished( Ir*);
58 void slotDeleteButton(); 61 void slotDeleteButton();
59 void slotSaveButton(); 62 void slotSaveButton();
60 void slotDeleteButtonClicked(); 63 void slotDeleteButtonClicked();
61 void slotNewButton(); 64 void slotNewButton();