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 2b25476..4e98b31 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -1,508 +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 QDir d( QDir::homeDirPath()+"/notes"); 86 QDir d( QDir::homeDirPath()+"/notes");
87 if( !d.exists()) { 87 if( !d.exists()) {
88 qDebug("make dir"); 88 qDebug("make dir");
89 if(!d.mkdir( QDir::homeDirPath()+"/notes", true)) 89 if(!d.mkdir( QDir::homeDirPath()+"/notes", true))
90 qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed"); 90 qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed");
91 } 91 }
92 Config cfg("Notes"); 92 Config cfg("Notes");
93 cfg.setGroup("Options"); 93 cfg.setGroup("Options");
94 showMax = cfg.readBoolEntry("ShowMax", false); 94 showMax = cfg.readBoolEntry("ShowMax", false);
95 95
96 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 96 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
97 loaded=false; 97 loaded=false;
98 edited=false; 98 edited=false;
99 doPopulate=true; 99 doPopulate=true;
100 isNew=false; 100 isNew=false;
101 QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" ); 101 QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" );
102 QHBoxLayout *hbox = new QHBoxLayout( this, 0, -1, "HLayout" ); 102 QHBoxLayout *hbox = new QHBoxLayout( this, 0, -1, "HLayout" );
103 103
104 view = new QMultiLineEdit(this, "OpieNotesView"); 104 view = new QMultiLineEdit(this, "OpieNotesView");
105 105
106 box = new QListBox(this, "OpieNotesBox"); 106 box = new QListBox(this, "OpieNotesBox");
107 107
108 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); 108 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold);
109 109
110 box->setFixedHeight(50); 110 box->setFixedHeight(50);
111 111
112 vbox->setMargin( 6 ); 112 vbox->setMargin( 6 );
113 vbox->setSpacing( 3 ); 113 vbox->setSpacing( 3 );
114 114
115 vbox->addWidget( view); 115 vbox->addWidget( view);
116 vbox->addWidget( box); 116 vbox->addWidget( box);
117 117
118 setFocusPolicy(QWidget::StrongFocus); 118 setFocusPolicy(QWidget::StrongFocus);
119 119
120 newButton= new QPushButton( this, "newButton" ); 120 newButton= new QPushButton( this, "newButton" );
121 newButton->setText(tr("New")); 121 newButton->setText(tr("New"));
122 hbox->addWidget( newButton); 122 hbox->addWidget( newButton);
123 123
124 saveButton= new QPushButton( this, "saveButton" ); 124 saveButton= new QPushButton( this, "saveButton" );
125 saveButton->setText(tr("Save")); 125 saveButton->setText(tr("Save"));
126 hbox->addWidget( saveButton); 126 hbox->addWidget( saveButton);
127 127
128 deleteButton= new QPushButton( this, "deleteButton" ); 128 deleteButton= new QPushButton( this, "deleteButton" );
129 deleteButton->setText(tr("Delete")); 129 deleteButton->setText(tr("Delete"));
130 hbox->addWidget( deleteButton); 130 hbox->addWidget( deleteButton);
131 131
132 vbox->addItem(hbox); 132 vbox->addItem(hbox);
133 133
134 connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), 134 connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)),
135 this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); 135 this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) );
136 136
137 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); 137 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &)));
138 138
139 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); 139 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) );
140 140
141 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); 141 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) );
142 142
143 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); 143 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton()));
144 connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton())); 144 connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton()));
145 connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); 145 connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked()));
146 146
147 populateBox(); 147 populateBox();
148 load(); 148 load();
149 setCaption("Notes"); 149 setCaption("Notes");
150 // parent->setFocus(); 150 // parent->setFocus();
151} 151}
152 152
153void NotesControl::slotSaveButton() { 153void NotesControl::slotSaveButton() {
154 slotNewButton(); 154 slotNewButton();
155 populateBox(); 155 populateBox();
156} 156}
157 157
158void NotesControl::slotDeleteButtonClicked() { 158void NotesControl::slotDeleteButtonClicked() {
159 switch ( QMessageBox::warning(this,tr("Delete?") 159 switch ( QMessageBox::warning(this,tr("Delete?")
160 ,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 ?")
161 ,tr("Yes"),tr("No"),0,1,1) ) { 161 ,tr("Yes"),tr("No"),0,1,1) ) {
162 case 0: 162 case 0:
163 slotDeleteButton(); 163 slotDeleteButton();
164 break; 164 break;
165 }; 165 };
166} 166}
167 167
168void NotesControl::slotDeleteButton() { 168void NotesControl::slotDeleteButton() {
169 169
170 QString selectedText = box->currentText(); 170 QString selectedText = box->currentText();
171 qDebug("deleting "+selectedText); 171 qDebug("deleting "+selectedText);
172 172
173 if( !selectedText.isEmpty()) { 173 if( !selectedText.isEmpty()) {
174 174
175 Config cfg("Notes"); 175 Config cfg("Notes");
176 cfg.setGroup("Docs"); 176 cfg.setGroup("Docs");
177 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 177 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
178 QString entryName, entryName2;; 178 QString entryName, entryName2;;
179 for ( int i = 0; i < noOfFiles; i++ ) { 179 for ( int i = 0; i < noOfFiles; i++ ) {
180 entryName.sprintf( "File%i", i + 1 ); 180 entryName.sprintf( "File%i", i + 1 );
181 if(selectedText == cfg.readEntry( entryName )) { 181 if(selectedText == cfg.readEntry( entryName )) {
182 qDebug("removing %s, %d", selectedText.latin1(), i); 182 qDebug("removing %s, %d", selectedText.latin1(), i);
183 for ( int j = i; j < noOfFiles; j++ ) { 183 for ( int j = i; j < noOfFiles; j++ ) {
184 entryName.sprintf( "File%i", i + 1 ); 184 entryName.sprintf( "File%i", i + 1 );
185 entryName2.sprintf( "File%i", i + 2 ); 185 entryName2.sprintf( "File%i", i + 2 );
186 QString temp = cfg.readEntry(entryName2); 186 QString temp = cfg.readEntry(entryName2);
187 qDebug("move "+temp); 187 qDebug("move "+temp);
188 cfg.writeEntry(entryName, temp); 188 cfg.writeEntry(entryName, temp);
189 i++; 189 i++;
190 } 190 }
191 cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); 191 cfg.writeEntry("NumberOfFiles", noOfFiles-1 );
192 entryName.sprintf( "File%i", noOfFiles ); 192 entryName.sprintf( "File%i", noOfFiles );
193 cfg.removeEntry(entryName); 193 cfg.removeEntry(entryName);
194 cfg.write(); 194 cfg.write();
195 DocLnk nf(selectedText); 195 DocLnk nf(selectedText);
196 nf.removeFiles(); 196 nf.removeFiles();
197 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; 197 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop";
198 qDebug(fi); 198 qDebug(fi);
199 199
200 QFile f( fi); 200 QFile f( fi);
201 if( !f.remove()) qDebug(".desktop file not removed"); 201 if( !f.remove()) qDebug(".desktop file not removed");
202 202
203 } 203 }
204 } 204 }
205 view->clear(); 205 view->clear();
206 206
207 populateBox(); 207 populateBox();
208 } 208 }
209} 209}
210 210
211void NotesControl::slotNewButton() { 211void NotesControl::slotNewButton() {
212 if(edited) save(); 212 if(edited) save();
213 view->clear(); 213 view->clear();
214 view->setFocus(); 214 view->setFocus();
215 edited=false; 215 edited=false;
216 isNew=false; 216 isNew=false;
217} 217}
218 218
219void NotesControl::slotBeamButton() { 219void NotesControl::slotBeamButton() {
220 Ir ir; 220 Ir ir;
221 if(!ir.supported()){ 221 if(!ir.supported()){
222 } else { 222 } else {
223 this->hide(); 223 this->hide();
224 QString selectedText = box->currentText(); 224 QString selectedText = box->currentText();
225 if( !selectedText.isEmpty()) { 225 if( !selectedText.isEmpty()) {
226 QString file = QDir::homeDirPath()+"/"+selectedText; 226 QString file = QDir::homeDirPath()+"/"+selectedText;
227 QFile f(file); 227 QFile f(file);
228 Ir *irFile = new Ir(this, "IR"); 228 Ir *irFile = new Ir(this, "IR");
229 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * ))); 229 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * )));
230 irFile->send( file, "Note", "text/plain" ); 230 irFile->send( file, "Note", "text/plain" );
231 } 231 }
232 } 232 }
233} 233}
234 234
235void NotesControl::slotBeamFinished(Ir *) { 235void NotesControl::slotBeamFinished(Ir *) {
236 this->show(); 236 this->show();
237} 237}
238 238
239void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) { 239void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) {
240 switch (mouse) { 240 switch (mouse) {
241 case 1:{ 241 case 1:{
242 } 242 }
243 break; 243 break;
244 case 2: 244 case 2:
245 menuTimer.start( 500, TRUE ); 245 menuTimer.start( 500, TRUE );
246 break; 246 break;
247 }; 247 };
248} 248}
249 249
250void NotesControl::slotBoxSelected(const QString &itemString) { 250void NotesControl::slotBoxSelected(const QString &itemString) {
251 if(edited) { 251 if(edited) {
252 save(); 252 save();
253 } 253 }
254 loaded=false; 254 loaded=false;
255 edited=false; 255 edited=false;
256 load(itemString); 256 load(itemString);
257} 257}
258 258
259 259
260void NotesControl::showMenu() { 260void NotesControl::showMenu() {
261 QPopupMenu *m = new QPopupMenu(0); 261 QPopupMenu *m = new QPopupMenu(0);
262 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() )); 263 m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() ));
264 m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() )); 264 m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() ));
265 m->insertSeparator(); 265 m->insertSeparator();
266 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); 266 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() ));
267 m->setFocus(); 267 m->setFocus();
268 m->exec( QCursor::pos() ); 268 m->exec( QCursor::pos() );
269 269
270 if(m) delete m; 270 if(m) delete m;
271} 271}
272 272
273void NotesControl::focusOutEvent ( QFocusEvent * e) { 273void NotesControl::focusOutEvent ( QFocusEvent * e) {
274 if( e->reason() == QFocusEvent::Popup) 274 if( e->reason() == QFocusEvent::Popup)
275 save(); 275 save();
276 else { 276 else {
277 if(!loaded) { 277 if(!loaded) {
278 populateBox(); 278 populateBox();
279 load(); 279 load();
280 } 280 }
281 } 281 }
282 QWidget::focusOutEvent(e); 282 QWidget::focusOutEvent(e);
283} 283}
284 284
285void NotesControl::save() { 285void NotesControl::save() {
286 Config cfg("Notes"); 286 Config cfg("Notes");
287 cfg.setGroup("Docs"); 287 cfg.setGroup("Docs");
288 if( edited) { 288 if( edited) {
289// qDebug("is edited"); 289// qDebug("is edited");
290 QString rt = view->text(); 290 QString rt = view->text();
291 if( rt.length()>1) { 291 if( rt.length()>1) {
292 QString pt = rt.simplifyWhiteSpace(); 292 QString pt = rt.simplifyWhiteSpace();
293 int i = pt.find( ' ', pt.find( ' ' )+2 ); 293 int i = pt.find( ' ', pt.find( ' ' )+2 );
294 QString docname = pt; 294 QString docname = pt;
295 if ( i > 0 ) 295 if ( i > 0 )
296 docname = pt.left(i); 296 docname = pt.left(i);
297 // remove "." at the beginning 297 // remove "." at the beginning
298 while( docname.startsWith( "." ) ) 298 while( docname.startsWith( "." ) )
299 docname = docname.mid( 1 ); 299 docname = docname.mid( 1 );
300 docname.replace( QRegExp("/"), "_" ); 300 docname.replace( QRegExp("/"), "_" );
301 // cut the length. filenames longer than that don't make sense 301 // cut the length. filenames longer than that don't make sense
302 // and something goes wrong when they get too long. 302 // and something goes wrong when they get too long.
303 if ( docname.length() > 40 ) 303 if ( docname.length() > 40 )
304 docname = docname.left(40); 304 docname = docname.left(40);
305 if ( docname.isEmpty() ) 305 if ( docname.isEmpty() )
306 docname = "Empty Text"; 306 docname = "Empty Text";
307// qDebug(docname); 307// qDebug(docname);
308 308
309 if( oldDocName != docname) { 309 if( oldDocName != docname) {
310 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 310 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
311 QString entryName; 311 QString entryName;
312 entryName.sprintf( "File%i", noOfFiles + 1 ); 312 entryName.sprintf( "File%i", noOfFiles + 1 );
313 cfg.writeEntry( entryName,docname ); 313 cfg.writeEntry( entryName,docname );
314 cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); 314 cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
315 cfg.write(); 315 cfg.write();
316 } 316 }
317// else 317// else
318// qDebug("oldname equals docname"); 318// qDebug("oldname equals docname");
319 319
320 doc = new DocLnk(docname); 320 doc = new DocLnk(docname);
321 if(QFile(doc->linkFile()).exists()) 321 if(QFile(doc->linkFile()).exists())
322 qDebug("puppie"); 322 qDebug("puppie");
323 doc->setType("text/plain"); 323 doc->setType("text/plain");
324 doc->setName(docname); 324 doc->setName(docname);
325 QString temp = docname.replace( QRegExp(" "), "_" ); 325 QString temp = docname.replace( QRegExp(" "), "_" );
326 doc->setFile( QDir::homeDirPath()+"/notes/"+temp); 326 doc->setFile( QDir::homeDirPath()+"/notes/"+temp);
327 FileManager fm; 327 FileManager fm;
328 if ( !fm.saveFile( *doc, rt ) ) { 328 if ( !fm.saveFile( *doc, rt ) ) {
329 } 329 }
330 330
331 oldDocName=docname; 331 oldDocName=docname;
332 edited=false; 332 edited=false;
333// qDebug("save"); 333// qDebug("save");
334 if (doPopulate) 334 if (doPopulate)
335 populateBox(); 335 populateBox();
336 } 336 }
337 cfg.writeEntry( "LastDoc",oldDocName ); 337 cfg.writeEntry( "LastDoc",oldDocName );
338 cfg.write(); 338 cfg.write();
339 339
340 } 340 }
341} 341}
342 342
343void NotesControl::populateBox() { 343void NotesControl::populateBox() {
344 box->clear(); 344 box->clear();
345// qDebug("populate"); 345// qDebug("populate");
346 Config cfg("Notes"); 346 Config cfg("Notes");
347 cfg.setGroup("Docs"); 347 cfg.setGroup("Docs");
348 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 348 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
349 QStringList list; 349 QStringList list;
350 QString entryName; 350 QString entryName;
351 for ( int i = 0; i < noOfFiles; i++ ) { 351 for ( int i = 0; i < noOfFiles; i++ ) {
352 entryName.sprintf( "File%i", i + 1 ); 352 entryName.sprintf( "File%i", i + 1 );
353 list.append(cfg.readEntry( entryName )); 353 list.append(cfg.readEntry( entryName ));
354 } 354 }
355 list.sort(); 355 list.sort();
356 box->insertStringList(list,-1); 356 box->insertStringList(list,-1);
357 doPopulate=false; 357 doPopulate=false;
358 update(); 358 update();
359} 359}
360 360
361void NotesControl::load() { 361void NotesControl::load() {
362 362
363 if(!loaded) { 363 if(!loaded) {
364 Config cfg("Notes"); 364 Config cfg("Notes");
365 cfg.setGroup("Docs"); 365 cfg.setGroup("Docs");
366 QString lastDoc=cfg.readEntry( "LastDoc",""); 366 QString lastDoc=cfg.readEntry( "LastDoc","notes");
367 DocLnk nf; 367 DocLnk nf;
368 nf.setType("text/plain"); 368 nf.setType("text/plain");
369 nf.setFile(lastDoc); 369 nf.setFile(lastDoc);
370 370
371 loadDoc(nf); 371 loadDoc(nf);
372 loaded=true; 372 loaded=true;
373 oldDocName=lastDoc; 373 oldDocName=lastDoc;
374 cfg.writeEntry( "LastDoc",oldDocName ); 374 cfg.writeEntry( "LastDoc",oldDocName );
375 cfg.write(); 375 cfg.write();
376 } 376 }
377} 377}
378 378
379void NotesControl::load(const QString & file) { 379void NotesControl::load(const QString & file) {
380 qDebug("loading "+file); 380 qDebug("loading "+file);
381 QString name = file; 381 QString name = file;
382 QString temp; 382 QString temp;
383 if( !QFile( QDir::homeDirPath()+"/"+file).exists() ) 383 if( !QFile( QDir::homeDirPath()+"/"+file).exists() )
384 temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" ); 384 temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" );
385 else 385 else
386 temp = name; 386 temp = name;
387 if(!loaded) { 387 if(!loaded) {
388 DocLnk nf; 388 DocLnk nf;
389 nf.setType("text/plain"); 389 nf.setType("text/plain");
390 nf.setFile( temp); 390 nf.setFile( temp);
391 391 if(!temp.isEmpty())
392 loadDoc(nf); 392 loadDoc(nf);
393 loaded=true; 393 loaded=true;
394 } 394 }
395// view->setFocus(); 395// view->setFocus();
396 oldDocName=file; 396 oldDocName=file;
397 Config cfg("Notes"); 397 Config cfg("Notes");
398 cfg.setGroup("Docs"); 398 cfg.setGroup("Docs");
399 cfg.writeEntry( "LastDoc",oldDocName ); 399 cfg.writeEntry( "LastDoc",oldDocName );
400 cfg.write(); 400 cfg.write();
401} 401}
402 402
403void NotesControl::loadDoc( const DocLnk &f) { 403void NotesControl::loadDoc( const DocLnk &f) {
404 FileManager fm; 404 FileManager fm;
405 QString txt; 405 QString txt;
406 if ( !fm.loadFile( f, txt ) ) { 406 if ( !fm.loadFile( f, txt ) ) {
407 qDebug("could not load file "+f.file()); 407 qDebug("could not load file "+f.file());
408 return; 408 return;
409 } 409 }
410 view->setText(txt); 410 view->setText(txt);
411} 411}
412 412
413void NotesControl::slotViewEdited() { 413void NotesControl::slotViewEdited() {
414 if(loaded) { 414 if(loaded) {
415 edited=true; 415 edited=true;
416 } 416 }
417} 417}
418 418
419 419
420void NotesControl::slotShowMax() { 420void NotesControl::slotShowMax() {
421 Config cfg("Notes"); 421 Config cfg("Notes");
422 cfg.setGroup("Options"); 422 cfg.setGroup("Options");
423 showMax=!showMax; 423 showMax=!showMax;
424 cfg.writeEntry("ShowMax", showMax); 424 cfg.writeEntry("ShowMax", showMax);
425 cfg.write(); 425 cfg.write();
426 hide(); 426 hide();
427} 427}
428 428
429void NotesControl::slotSearch() { 429void NotesControl::slotSearch() {
430 int boxCount = box->count(); 430 int boxCount = box->count();
431 for(int i=0;i< boxCount;i++) { 431 for(int i=0;i< boxCount;i++) {
432 432
433 } 433 }
434} 434}
435 435
436// void NotesControl::keyReleaseEvent( QKeyEvent *e) { 436// void NotesControl::keyReleaseEvent( QKeyEvent *e) {
437 437
438// switch ( e->state() ) { 438// switch ( e->state() ) {
439// case ControlButton: 439// case ControlButton:
440// if(e->key() == Key_C) { //copy 440// if(e->key() == Key_C) { //copy
441// qDebug("copy"); 441// qDebug("copy");
442// QClipboard *cb = QApplication::clipboard(); 442// QClipboard *cb = QApplication::clipboard();
443// QString text; 443// QString text;
444 444
445// // Copy text from the clipboard (paste) 445// // Copy text from the clipboard (paste)
446// text = cb->text(); 446// text = cb->text();
447// } 447// }
448// if(e->key() == Key_X) { //cut 448// if(e->key() == Key_X) { //cut
449// } 449// }
450// if(e->key() == Key_V) { //paste 450// if(e->key() == Key_V) { //paste
451// QClipboard *cb = QApplication::clipboard(); 451// QClipboard *cb = QApplication::clipboard();
452// QString text; 452// QString text;
453// //view 453// //view
454// cb->setText(); 454// cb->setText();
455// } 455// }
456// break; 456// break;
457// }; 457// };
458// QWidget::keyReleaseEvent(e); 458// QWidget::keyReleaseEvent(e);
459// } 459// }
460 460
461//=========================================================================== 461//===========================================================================
462 462
463NotesApplet::NotesApplet( QWidget *parent, const char *name ) 463NotesApplet::NotesApplet( QWidget *parent, const char *name )
464 : QWidget( parent, name ) { 464 : QWidget( parent, name ) {
465 setFixedHeight( 18 ); 465 setFixedHeight( 18 );
466 setFixedWidth( 14 ); 466 setFixedWidth( 14 );
467 vc = new NotesControl; 467 vc = new NotesControl;
468} 468}
469 469
470NotesApplet::~NotesApplet() { 470NotesApplet::~NotesApplet() {
471} 471}
472 472
473void NotesApplet::mousePressEvent( QMouseEvent *) { 473void NotesApplet::mousePressEvent( QMouseEvent *) {
474 if( !vc->isHidden()) { 474 if( !vc->isHidden()) {
475 vc->doPopulate=false; 475 vc->doPopulate=false;
476 vc->save(); 476 vc->save();
477 vc->close(); 477 vc->close();
478 } else { 478 } else {
479// vc = new NotesControl; 479// vc = new NotesControl;
480// QPoint curPos = mapToGlobal( rect().topLeft() ); 480// QPoint curPos = mapToGlobal( rect().topLeft() );
481 if(vc->showMax) { 481 if(vc->showMax) {
482 qDebug("show max"); 482 qDebug("show max");
483 vc->showMaximized(); 483 vc->showMaximized();
484 } else { 484 } else {
485 qDebug("no show max"); 485 qDebug("no show max");
486 QWidget *wid = QPEApplication::desktop(); 486 QWidget *wid = QPEApplication::desktop();
487 QRect rect = QApplication::desktop()->geometry(); 487 QRect rect = QApplication::desktop()->geometry();
488 vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180); 488 vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180);
489 vc->move ( (rect.center()/2) - (vc->rect().center()/2)); 489 vc->move ( (rect.center()/2) - (vc->rect().center()/2));
490// vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28); 490// vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28);
491 } 491 }
492 vc->show(); 492 vc->show();
493 vc->doPopulate=true; 493 vc->doPopulate=true;
494 vc->populateBox(); 494 vc->populateBox();
495 vc->doPopulate=false; 495 vc->doPopulate=false;
496 vc->loaded=false; 496 vc->loaded=false;
497 497
498 vc->load(); 498 vc->load();
499// this->setFocus(); 499// this->setFocus();
500 vc->view->setFocus(); 500 vc->view->setFocus();
501 } 501 }
502} 502}
503 503
504void NotesApplet::paintEvent( QPaintEvent* ) { 504void NotesApplet::paintEvent( QPaintEvent* ) {
505 QPainter p(this); 505 QPainter p(this);
506 p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); 506 p.drawPixmap( 0, 1, ( const char** ) notes_xpm );
507} 507}
508 508