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
@@ -1,470 +1,508 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org> 2** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org>
3 3
4** All rights reserved. 4** All rights reserved.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#include "notes.h" 16#include "notes.h"
17 17
18#include <qapplication.h> 18#include <qapplication.h>
19#include <stdlib.h> 19#include <stdlib.h>
20#include <qstringlist.h> 20#include <qstringlist.h>
21 21
22#include <qpe/filemanager.h> 22#include <qpe/filemanager.h>
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/timestring.h> 25#include <qpe/timestring.h>
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#include <qpe/applnk.h> 28#include <qpe/applnk.h>
29#include <qpe/config.h> 29#include <qpe/config.h>
30#include <qpe/ir.h> 30#include <qpe/ir.h>
31 31
32// #include <qsocket.h> 32// #include <qsocket.h>
33// #include <qclipboard.h> 33// #include <qclipboard.h>
34#include <qmultilineedit.h> 34#include <qmultilineedit.h>
35#include <qlistbox.h> 35#include <qlistbox.h>
36#include <qpopupmenu.h> 36#include <qpopupmenu.h>
37#include <qmessagebox.h> 37#include <qmessagebox.h>
38 38
39#include <qdir.h> 39#include <qdir.h>
40#include <qfile.h> 40#include <qfile.h>
41#include <qpoint.h> 41#include <qpoint.h>
42#include <qpushbutton.h> 42#include <qpushbutton.h>
43#include <qpainter.h> 43#include <qpainter.h>
44#include <qlayout.h> 44#include <qlayout.h>
45#include <qframe.h> 45#include <qframe.h>
46#include <qpixmap.h> 46#include <qpixmap.h>
47#include <qstring.h> 47#include <qstring.h>
48#include <qtimer.h> 48#include <qtimer.h>
49 49
50/* XPM */ 50/* XPM */
51static char * notes_xpm[] = { 51static char * notes_xpm[] = {
52"16 16 11 1", 52"16 16 11 1",
53" c None", 53" c None",
54". c #000000", 54". c #000000",
55"+ c #7F7F7F", 55"+ c #7F7F7F",
56"@ c #BFBFBF", 56"@ c #BFBFBF",
57"# c #BFC1FF", 57"# c #BFC1FF",
58"$ c #FF0000", 58"$ c #FF0000",
59"% c #FFFFFF", 59"% c #FFFFFF",
60"& c #00037F", 60"& c #00037F",
61"* c #0006FF", 61"* c #0006FF",
62"= c #0005BF", 62"= c #0005BF",
63"- c #7F0000", 63"- c #7F0000",
64" .. ", 64" .. ",
65" .. ", 65" .. ",
66" ... ", 66" ... ",
67" .+ ", 67" .+ ",
68" .@. ", 68" .@. ",
69" . .+ ", 69" . .+ ",
70" ..#.@. ", 70" ..#.@. ",
71" ..###.+.. ", 71" ..###.+.. ",
72" ..###$...##.. ", 72" ..###$...##.. ",
73"..###$$$%+$$##&.", 73"..###$$$%+$$##&.",
74".*=####$-###&=&.", 74".*=####$-###&=&.",
75".=**=###==&=&=..", 75".=**=###==&=&=..",
76" ..=**=#&=&=.. ", 76" ..=**=#&=&=.. ",
77" ..=*=&=.. ", 77" ..=*=&=.. ",
78" ..=.. ", 78" ..=.. ",
79" . "}; 79" . "};
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" );
93 103
94 view = new QMultiLineEdit(this, "OpieNotesView"); 104 view = new QMultiLineEdit(this, "OpieNotesView");
95 105
96 box = new QListBox(this, "OpieNotesBox"); 106 box = new QListBox(this, "OpieNotesBox");
97 107
98 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); 108 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold);
99 109
100 box->setFixedHeight(50); 110 box->setFixedHeight(50);
101 111
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
118 saveButton= new QPushButton( this, "saveButton" ); 124 saveButton= new QPushButton( this, "saveButton" );
119 saveButton->setText(tr("Save")); 125 saveButton->setText(tr("Save"));
120 hbox->addWidget( saveButton); 126 hbox->addWidget( saveButton);
121 127
122 deleteButton= new QPushButton( this, "deleteButton" ); 128 deleteButton= new QPushButton( this, "deleteButton" );
123 deleteButton->setText(tr("Delete")); 129 deleteButton->setText(tr("Delete"));
124 hbox->addWidget( deleteButton); 130 hbox->addWidget( deleteButton);
125 131
126 vbox->addItem(hbox); 132 vbox->addItem(hbox);
127 133
128 connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), 134 connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)),
129 this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); 135 this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) );
130 136
131 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); 137 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &)));
132 138
133 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); 139 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) );
134 140
135 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); 141 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) );
136 142
137 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); 143 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton()));
138 connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton())); 144 connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton()));
139 connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); 145 connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked()));
140 146
141 populateBox(); 147 populateBox();
142 load(); 148 load();
143 setCaption("Notes"); 149 setCaption("Notes");
144 // parent->setFocus(); 150 // parent->setFocus();
145} 151}
146 152
147void NotesControl::slotSaveButton() { 153void NotesControl::slotSaveButton() {
148 slotNewButton(); 154 slotNewButton();
149 populateBox(); 155 populateBox();
150} 156}
151 157
152void NotesControl::slotDeleteButtonClicked() { 158void NotesControl::slotDeleteButtonClicked() {
153 switch ( QMessageBox::warning(this,tr("Delete?") 159 switch ( QMessageBox::warning(this,tr("Delete?")
154 ,tr("Do you really want to<BR><B> delete</B> this note ?") 160 ,tr("Do you really want to<BR><B> delete</B> this note ?")
155 ,tr("Yes"),tr("No"),0,1,1) ) { 161 ,tr("Yes"),tr("No"),0,1,1) ) {
156 case 0: 162 case 0:
157 slotDeleteButton(); 163 slotDeleteButton();
158 break; 164 break;
159 }; 165 };
160} 166}
161 167
162void NotesControl::slotDeleteButton() { 168void NotesControl::slotDeleteButton() {
163 169
164 QString selectedText = box->currentText(); 170 QString selectedText = box->currentText();
165 qDebug("deleting "+selectedText); 171 qDebug("deleting "+selectedText);
166 172
167 if( !selectedText.isEmpty()) { 173 if( !selectedText.isEmpty()) {
168 174
169 Config cfg("Notes"); 175 Config cfg("Notes");
170 cfg.setGroup("Docs"); 176 cfg.setGroup("Docs");
171 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 177 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
172 QString entryName, entryName2;; 178 QString entryName, entryName2;;
173 for ( int i = 0; i < noOfFiles; i++ ) { 179 for ( int i = 0; i < noOfFiles; i++ ) {
174 entryName.sprintf( "File%i", i + 1 ); 180 entryName.sprintf( "File%i", i + 1 );
175 if(selectedText == cfg.readEntry( entryName )) { 181 if(selectedText == cfg.readEntry( entryName )) {
176 qDebug("removing %s, %d", selectedText.latin1(), i); 182 qDebug("removing %s, %d", selectedText.latin1(), i);
177 for ( int j = i; j < noOfFiles; j++ ) { 183 for ( int j = i; j < noOfFiles; j++ ) {
178 entryName.sprintf( "File%i", i + 1 ); 184 entryName.sprintf( "File%i", i + 1 );
179 entryName2.sprintf( "File%i", i + 2 ); 185 entryName2.sprintf( "File%i", i + 2 );
180 QString temp = cfg.readEntry(entryName2); 186 QString temp = cfg.readEntry(entryName2);
181 qDebug("move "+temp); 187 qDebug("move "+temp);
182 cfg.writeEntry(entryName, temp); 188 cfg.writeEntry(entryName, temp);
183 i++; 189 i++;
184 } 190 }
185 cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); 191 cfg.writeEntry("NumberOfFiles", noOfFiles-1 );
186 entryName.sprintf( "File%i", noOfFiles ); 192 entryName.sprintf( "File%i", noOfFiles );
187 cfg.removeEntry(entryName); 193 cfg.removeEntry(entryName);
188 cfg.write(); 194 cfg.write();
189 DocLnk nf(selectedText); 195 DocLnk nf(selectedText);
190 nf.removeFiles(); 196 nf.removeFiles();
191 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; 197 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop";
192 qDebug(fi); 198 qDebug(fi);
193 199
194 QFile f( fi); 200 QFile f( fi);
195 if( !f.remove()) qDebug(".desktop file not removed"); 201 if( !f.remove()) qDebug(".desktop file not removed");
196 202
197 } 203 }
198 } 204 }
199 view->clear(); 205 view->clear();
200 206
201 populateBox(); 207 populateBox();
202 } 208 }
203} 209}
204 210
205void NotesControl::slotNewButton() { 211void NotesControl::slotNewButton() {
206 if(edited) save(); 212 if(edited) save();
207 view->clear(); 213 view->clear();
208 view->setFocus(); 214 view->setFocus();
209 edited=false; 215 edited=false;
210 isNew=false; 216 isNew=false;
211} 217}
212 218
213void NotesControl::slotBeamButton() { 219void NotesControl::slotBeamButton() {
214 Ir ir; 220 Ir ir;
215 if(!ir.supported()){ 221 if(!ir.supported()){
216 } else { 222 } else {
217 this->hide(); 223 this->hide();
218 QString selectedText = box->currentText(); 224 QString selectedText = box->currentText();
219 if( !selectedText.isEmpty()) { 225 if( !selectedText.isEmpty()) {
220 QString file = QDir::homeDirPath()+"/"+selectedText; 226 QString file = QDir::homeDirPath()+"/"+selectedText;
221 QFile f(file); 227 QFile f(file);
222 Ir *irFile = new Ir(this, "IR"); 228 Ir *irFile = new Ir(this, "IR");
223 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * ))); 229 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * )));
224 irFile->send( file, "Note", "text/plain" ); 230 irFile->send( file, "Note", "text/plain" );
225 } 231 }
226 } 232 }
227} 233}
228 234
229void NotesControl::slotBeamFinished(Ir *) { 235void NotesControl::slotBeamFinished(Ir *) {
230 this->show(); 236 this->show();
231} 237}
232 238
233void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) { 239void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) {
234 switch (mouse) { 240 switch (mouse) {
235 case 1:{ 241 case 1:{
236 } 242 }
237 break; 243 break;
238 case 2: 244 case 2:
239 menuTimer.start( 500, TRUE ); 245 menuTimer.start( 500, TRUE );
240 break; 246 break;
241 }; 247 };
242} 248}
243 249
244void NotesControl::slotBoxSelected(const QString &itemString) { 250void NotesControl::slotBoxSelected(const QString &itemString) {
245 if(edited) { 251 if(edited) {
246 save(); 252 save();
247 } 253 }
248 loaded=false; 254 loaded=false;
249 edited=false; 255 edited=false;
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 {
271 if(!loaded) { 277 if(!loaded) {
272 populateBox(); 278 populateBox();
273 load(); 279 load();
274 } 280 }
275 } 281 }
276 QWidget::focusOutEvent(e); 282 QWidget::focusOutEvent(e);
277} 283}
278 284
279void NotesControl::save() { 285void NotesControl::save() {
280 Config cfg("Notes"); 286 Config cfg("Notes");
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.
297 if ( docname.length() > 40 ) 303 if ( docname.length() > 40 )
298 docname = docname.left(40); 304 docname = docname.left(40);
299 if ( docname.isEmpty() ) 305 if ( docname.isEmpty() )
300 docname = "Empty Text"; 306 docname = "Empty Text";
301// qDebug(docname); 307// qDebug(docname);
302 308
303 if( oldDocName != docname) { 309 if( oldDocName != docname) {
304 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 310 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
305 QString entryName; 311 QString entryName;
306 entryName.sprintf( "File%i", noOfFiles + 1 ); 312 entryName.sprintf( "File%i", noOfFiles + 1 );
307 cfg.writeEntry( entryName,docname ); 313 cfg.writeEntry( entryName,docname );
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;
329// qDebug("save"); 333// qDebug("save");
330 if (doPopulate) 334 if (doPopulate)
331 populateBox(); 335 populateBox();
332 } 336 }
333 cfg.writeEntry( "LastDoc",oldDocName ); 337 cfg.writeEntry( "LastDoc",oldDocName );
334 cfg.write(); 338 cfg.write();
335 339
336 } 340 }
337} 341}
338 342
339void NotesControl::populateBox() { 343void NotesControl::populateBox() {
340 box->clear(); 344 box->clear();
341// qDebug("populate"); 345// qDebug("populate");
342 Config cfg("Notes"); 346 Config cfg("Notes");
343 cfg.setGroup("Docs"); 347 cfg.setGroup("Docs");
344 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 348 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
345 QStringList list; 349 QStringList list;
346 QString entryName; 350 QString entryName;
347 for ( int i = 0; i < noOfFiles; i++ ) { 351 for ( int i = 0; i < noOfFiles; i++ ) {
348 entryName.sprintf( "File%i", i + 1 ); 352 entryName.sprintf( "File%i", i + 1 );
349 list.append(cfg.readEntry( entryName )); 353 list.append(cfg.readEntry( entryName ));
350 } 354 }
351 list.sort(); 355 list.sort();
352 box->insertStringList(list,-1); 356 box->insertStringList(list,-1);
353 doPopulate=false; 357 doPopulate=false;
354 update(); 358 update();
355} 359}
356 360
357void NotesControl::load() { 361void NotesControl::load() {
358 362
359 if(!loaded) { 363 if(!loaded) {
360 Config cfg("Notes"); 364 Config cfg("Notes");
361 cfg.setGroup("Docs"); 365 cfg.setGroup("Docs");
362 QString lastDoc=cfg.readEntry( "LastDoc",""); 366 QString lastDoc=cfg.readEntry( "LastDoc","");
363 DocLnk nf; 367 DocLnk nf;
364 nf.setType("text/plain"); 368 nf.setType("text/plain");
365 nf.setFile(lastDoc); 369 nf.setFile(lastDoc);
366 370
367 loadDoc(nf); 371 loadDoc(nf);
368 loaded=true; 372 loaded=true;
369 oldDocName=lastDoc; 373 oldDocName=lastDoc;
370 cfg.writeEntry( "LastDoc",oldDocName ); 374 cfg.writeEntry( "LastDoc",oldDocName );
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;
387 Config cfg("Notes"); 397 Config cfg("Notes");
388 cfg.setGroup("Docs"); 398 cfg.setGroup("Docs");
389 cfg.writeEntry( "LastDoc",oldDocName ); 399 cfg.writeEntry( "LastDoc",oldDocName );
390 cfg.write(); 400 cfg.write();
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");
414// QClipboard *cb = QApplication::clipboard(); 442// QClipboard *cb = QApplication::clipboard();
415// QString text; 443// QString text;
416 444
417// // Copy text from the clipboard (paste) 445// // Copy text from the clipboard (paste)
418// text = cb->text(); 446// text = cb->text();
419// } 447// }
420// if(e->key() == Key_X) { //cut 448// if(e->key() == Key_X) { //cut
421// } 449// }
422// if(e->key() == Key_V) { //paste 450// if(e->key() == Key_V) { //paste
423// QClipboard *cb = QApplication::clipboard(); 451// QClipboard *cb = QApplication::clipboard();
424// QString text; 452// QString text;
425// //view 453// //view
426// cb->setText(); 454// cb->setText();
427// } 455// }
428// break; 456// break;
429// }; 457// };
430// QWidget::keyReleaseEvent(e); 458// QWidget::keyReleaseEvent(e);
431// } 459// }
432 460
433//=========================================================================== 461//===========================================================================
434 462
435NotesApplet::NotesApplet( QWidget *parent, const char *name ) 463NotesApplet::NotesApplet( QWidget *parent, const char *name )
436 : QWidget( parent, name ) { 464 : QWidget( parent, name ) {
437 setFixedHeight( 18 ); 465 setFixedHeight( 18 );
438 setFixedWidth( 14 ); 466 setFixedWidth( 14 );
439 vc = new NotesControl; 467 vc = new NotesControl;
440} 468}
441 469
442NotesApplet::~NotesApplet() { 470NotesApplet::~NotesApplet() {
443} 471}
444 472
445void NotesApplet::mousePressEvent( QMouseEvent *) { 473void NotesApplet::mousePressEvent( QMouseEvent *) {
446 if( !vc->isHidden()) { 474 if( !vc->isHidden()) {
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();
461// this->setFocus(); 499// this->setFocus();
462 vc->view->setFocus(); 500 vc->view->setFocus();
463 } 501 }
464} 502}
465 503
466void NotesApplet::paintEvent( QPaintEvent* ) { 504void NotesApplet::paintEvent( QPaintEvent* ) {
467 QPainter p(this); 505 QPainter p(this);
468 p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); 506 p.drawPixmap( 0, 1, ( const char** ) notes_xpm );
469} 507}
470 508
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
@@ -1,90 +1,93 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com 2** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com
3** All rights reserved. 3** All rights reserved.
4** 4**
5** This file may be distributed and/or modified under the terms of the 5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software 6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file. 8** packaging of this file.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12** 12**
13**********************************************************************/ 13**********************************************************************/
14 14
15#ifndef __NOTES_APPLET_H__ 15#ifndef __NOTES_APPLET_H__
16#define __NOTES_APPLET_H__ 16#define __NOTES_APPLET_H__
17 17
18#include <qwidget.h> 18#include <qwidget.h>
19#include <qframe.h> 19#include <qframe.h>
20#include <qpixmap.h> 20#include <qpixmap.h>
21#include <qguardedptr.h> 21#include <qguardedptr.h>
22#include <qtimer.h> 22#include <qtimer.h>
23#include <qpe/filemanager.h> 23#include <qpe/filemanager.h>
24#include <qpe/ir.h> 24#include <qpe/ir.h>
25#include <qstring.h> 25#include <qstring.h>
26 26
27class QComboBox; 27class QComboBox;
28class QCheckBox; 28class QCheckBox;
29class QSpinBox; 29class QSpinBox;
30class QPushButton; 30class QPushButton;
31class QMultiLineEdit; 31class QMultiLineEdit;
32class QListBox; 32class QListBox;
33class QListBoxItem; 33class QListBoxItem;
34class NotesControl : public QFrame { 34class NotesControl : public QFrame {
35 Q_OBJECT 35 Q_OBJECT
36public: 36public:
37 NotesControl( QWidget *parent=0, const char *name=0 ); 37 NotesControl( QWidget *parent=0, const char *name=0 );
38 38
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();
62 void boxPressed(int, QListBoxItem *, const QPoint&); 65 void boxPressed(int, QListBoxItem *, const QPoint&);
63 void showMenu(); 66 void showMenu();
64 void loadDoc( const DocLnk &); 67 void loadDoc( const DocLnk &);
65 void slotViewEdited(); 68 void slotViewEdited();
66 void slotBoxSelected(const QString &); 69 void slotBoxSelected(const QString &);
67// void keyReleaseEvent( QKeyEvent *); 70// void keyReleaseEvent( QKeyEvent *);
68 71
69}; 72};
70 73
71class NotesApplet : public QWidget { 74class NotesApplet : public QWidget {
72 Q_OBJECT 75 Q_OBJECT
73public: 76public:
74 NotesApplet( QWidget *parent = 0, const char *name=0 ); 77 NotesApplet( QWidget *parent = 0, const char *name=0 );
75 ~NotesApplet(); 78 ~NotesApplet();
76 NotesControl *vc; 79 NotesControl *vc;
77public slots: 80public slots:
78private: 81private:
79 void mousePressEvent( QMouseEvent * ); 82 void mousePressEvent( QMouseEvent * );
80 void paintEvent( QPaintEvent* ); 83 void paintEvent( QPaintEvent* );
81 84
82private: 85private:
83 QPixmap notesPixmap; 86 QPixmap notesPixmap;
84private slots: 87private slots:
85 88
86 89
87}; 90};
88 91
89#endif // __NOTES_APPLET_H__ 92#endif // __NOTES_APPLET_H__
90 93