summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/notesapplet/notes.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
index 92fdb0a..90c2550 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -74,32 +74,33 @@ static char * notes_xpm[] = {
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 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
87 loaded=false; 87 loaded=false;
88 edited=false; 88 edited=false;
89 doPopulate=true; 89 doPopulate=true;
90 isNew=false;
90 QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" ); 91 QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" );
91 QHBoxLayout *hbox = new QHBoxLayout( this, 0, -1, "HLayout" ); 92 QHBoxLayout *hbox = new QHBoxLayout( this, 0, -1, "HLayout" );
92 93
93 view = new QMultiLineEdit(this, "OpieNotesView"); 94 view = new QMultiLineEdit(this, "OpieNotesView");
94 95
95 box = new QListBox(this, "OpieNotesBox"); 96 box = new QListBox(this, "OpieNotesBox");
96 97
97 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); 98 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold);
98 99
99 box->setFixedHeight(50); 100 box->setFixedHeight(50);
100 101
101 vbox->setMargin( 6 ); 102 vbox->setMargin( 6 );
102 vbox->setSpacing( 3 ); 103 vbox->setSpacing( 3 );
103 104
104 vbox->addWidget( view); 105 vbox->addWidget( view);
105 vbox->addWidget( box); 106 vbox->addWidget( box);
@@ -174,42 +175,52 @@ void NotesControl::slotDeleteButton() {
174 if(selectedText == cfg.readEntry( entryName )) { 175 if(selectedText == cfg.readEntry( entryName )) {
175 qDebug("removing %s, %d", selectedText.latin1(), i); 176 qDebug("removing %s, %d", selectedText.latin1(), i);
176 for ( int j = i; j < noOfFiles; j++ ) { 177 for ( int j = i; j < noOfFiles; j++ ) {
177 entryName.sprintf( "File%i", i + 1 ); 178 entryName.sprintf( "File%i", i + 1 );
178 entryName2.sprintf( "File%i", i + 2 ); 179 entryName2.sprintf( "File%i", i + 2 );
179 QString temp = cfg.readEntry(entryName2); 180 QString temp = cfg.readEntry(entryName2);
180 qDebug("move "+temp); 181 qDebug("move "+temp);
181 cfg.writeEntry(entryName, temp); 182 cfg.writeEntry(entryName, temp);
182 i++; 183 i++;
183 } 184 }
184 cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); 185 cfg.writeEntry("NumberOfFiles", noOfFiles-1 );
185 entryName.sprintf( "File%i", noOfFiles ); 186 entryName.sprintf( "File%i", noOfFiles );
186 cfg.removeEntry(entryName); 187 cfg.removeEntry(entryName);
187 cfg.write(); 188 cfg.write();
188 DocLnk nf(selectedText); 189 DocLnk nf(selectedText);
189 nf.removeFiles(); 190 nf.removeFiles();
191 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop";
192 qDebug(fi);
193
194 QFile f( fi);
195 if( !f.remove()) qDebug(".desktop file not removed");
196
190 } 197 }
191 } 198 }
199 view->clear();
200
192 populateBox(); 201 populateBox();
193 } 202 }
194} 203}
195 204
196void NotesControl::slotNewButton() { 205void NotesControl::slotNewButton() {
197 if(edited) save(); 206 if(edited) save();
198 view->clear(); 207 view->clear();
199 view->setFocus(); 208 view->setFocus();
209 edited=false;
210 isNew=false;
200} 211}
201 212
202void NotesControl::slotBeamButton() { 213void NotesControl::slotBeamButton() {
203 Ir ir; 214 Ir ir;
204 if(!ir.supported()){ 215 if(!ir.supported()){
205 } else { 216 } else {
206 this->hide(); 217 this->hide();
207 QString selectedText = box->currentText(); 218 QString selectedText = box->currentText();
208 if( !selectedText.isEmpty()) { 219 if( !selectedText.isEmpty()) {
209 QString file = QDir::homeDirPath()+"/"+selectedText; 220 QString file = QDir::homeDirPath()+"/"+selectedText;
210 QFile f(file); 221 QFile f(file);
211 Ir *irFile = new Ir(this, "IR"); 222 Ir *irFile = new Ir(this, "IR");
212 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * ))); 223 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * )));
213 irFile->send( file, "Note", "text/plain" ); 224 irFile->send( file, "Note", "text/plain" );
214 } 225 }
215 } 226 }
@@ -256,67 +267,72 @@ void NotesControl::showMenu() {
256void NotesControl::focusOutEvent ( QFocusEvent * e) { 267void NotesControl::focusOutEvent ( QFocusEvent * e) {
257 if( e->reason() == QFocusEvent::Popup) 268 if( e->reason() == QFocusEvent::Popup)
258 save(); 269 save();
259 else { 270 else {
260 if(!loaded) { 271 if(!loaded) {
261 populateBox(); 272 populateBox();
262 load(); 273 load();
263 } 274 }
264 } 275 }
265 QWidget::focusOutEvent(e); 276 QWidget::focusOutEvent(e);
266} 277}
267 278
268void NotesControl::save() { 279void NotesControl::save() {
269 Config cfg("Notes"); 280 Config cfg("Notes");
270 cfg.setGroup("Docs"); 281 cfg.setGroup("Docs");
271 if( edited) { 282 if( edited) {
283// qDebug("is edited");
272 QString rt = view->text(); 284 QString rt = view->text();
273 if(!rt.isEmpty()) { 285 if( rt.length()>1) {
274 QString pt = rt.simplifyWhiteSpace(); 286 QString pt = rt.simplifyWhiteSpace();
275 int i = pt.find( ' ' ); 287 int i = pt.find( ' ' );
276 QString docname = pt; 288 QString docname = pt;
277 if ( i > 0 ) 289 if ( i > 0 )
278 docname = pt.left( i ); 290 docname = pt.left( i );
279 // remove "." at the beginning 291 // remove "." at the beginning
280 while( docname.startsWith( "." ) ) 292 while( docname.startsWith( "." ) )
281 docname = docname.mid( 1 ); 293 docname = docname.mid( 1 );
282 docname.replace( QRegExp("/"), "_" ); 294 docname.replace( QRegExp("/"), "_" );
283 // cut the length. filenames longer than that don't make sense 295 // cut the length. filenames longer than that don't make sense
284 // and something goes wrong when they get too long. 296 // and something goes wrong when they get too long.
285 if ( docname.length() > 40 ) 297 if ( docname.length() > 40 )
286 docname = docname.left(40); 298 docname = docname.left(40);
287 if ( docname.isEmpty() ) 299 if ( docname.isEmpty() )
288 docname = "Empty Text"; 300 docname = "Empty Text";
289 qDebug(docname); 301// qDebug(docname);
290 302
291 if( oldDocName != docname) { 303 if( oldDocName != docname) {
292 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 304 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
293 QString entryName; 305 QString entryName;
294 entryName.sprintf( "File%i", noOfFiles + 1 ); 306 entryName.sprintf( "File%i", noOfFiles + 1 );
295 cfg.writeEntry( entryName,docname ); 307 cfg.writeEntry( entryName,docname );
296 cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); 308 cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
297 cfg.write(); 309 cfg.write();
298 } 310 }
299 else 311// else
300 qDebug("oldname equals docname"); 312// qDebug("oldname equals docname");
313
314
301 doc = new DocLnk(docname); 315 doc = new DocLnk(docname);
302 316
317 if(QFile(doc->linkFile()).exists())
318 qDebug("puppie");
303 doc->setType("text/plain"); 319 doc->setType("text/plain");
304 doc->setFile(docname); 320 doc->setFile(QDir::homeDirPath()+"/"+docname);
305 doc->setName(docname); 321 doc->setName(docname);
306 322
307 FileManager fm; 323 FileManager fm;
308 if ( !fm.saveFile( *doc, rt ) ) { 324 if ( !fm.saveFile( *doc, rt ) ) {
309 } 325 }
310 326
311 oldDocName=docname; 327 oldDocName=docname;
312 edited=false; 328 edited=false;
313// qDebug("save"); 329// qDebug("save");
314 if (doPopulate) 330 if (doPopulate)
315 populateBox(); 331 populateBox();
316 } 332 }
317 cfg.writeEntry( "LastDoc",oldDocName ); 333 cfg.writeEntry( "LastDoc",oldDocName );
318 cfg.write(); 334 cfg.write();
319 335
320 } 336 }
321} 337}
322 338