-rw-r--r-- | noncore/applets/notesapplet/notes.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp index a4aa093..cc5245c 100644 --- a/noncore/applets/notesapplet/notes.cpp +++ b/noncore/applets/notesapplet/notes.cpp | |||
@@ -76,65 +76,74 @@ static char * notes_xpm[] = { | |||
76 | " . "}; | 76 | " . "}; |
77 | 77 | ||
78 | 78 | ||
79 | NotesControl::NotesControl( QWidget *parent, const char *name ) | 79 | NotesControl::NotesControl( QWidget *parent, const char *name ) |
80 | : QFrame( parent, name,/* WDestructiveClose | */WStyle_StaysOnTop ) | 80 | : QFrame( parent, name,/* WDestructiveClose | */WStyle_StaysOnTop ) |
81 | // : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) | 81 | // : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) |
82 | { | 82 | { |
83 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 83 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
84 | loaded=false; | 84 | loaded=false; |
85 | edited=false; | 85 | edited=false; |
86 | doPopulate=true; | 86 | doPopulate=true; |
87 | QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" ); | 87 | QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" ); |
88 | QHBoxLayout *hbox = new QHBoxLayout( this ); | 88 | QHBoxLayout *hbox = new QHBoxLayout( this, 0, -1, "HLayout" ); |
89 | 89 | ||
90 | view = new QMultiLineEdit(this, "OpieNotesView"); | 90 | view = new QMultiLineEdit(this, "OpieNotesView"); |
91 | 91 | ||
92 | box = new QListBox(this, "OpieNotesBox"); | 92 | box = new QListBox(this, "OpieNotesBox"); |
93 | QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); | 93 | QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); |
94 | box->setFixedHeight(50); | 94 | box->setFixedHeight(50); |
95 | 95 | ||
96 | vbox->setMargin( 6 ); | 96 | vbox->setMargin( 6 ); |
97 | vbox->setSpacing( 3 ); | 97 | vbox->setSpacing( 3 ); |
98 | 98 | ||
99 | vbox->addWidget( view); | 99 | vbox->addWidget( view); |
100 | vbox->addWidget( box); | 100 | vbox->addWidget( box); |
101 | 101 | ||
102 | setFixedHeight(180); | 102 | setFixedHeight(180); |
103 | QWidget *wid = QPEApplication::desktop(); | 103 | QWidget *wid = QPEApplication::desktop(); |
104 | setFixedWidth( wid->width()-10 /*200*/); | 104 | setFixedWidth( wid->width()-10 /*200*/); |
105 | 105 | ||
106 | setFocusPolicy(QWidget::StrongFocus); | 106 | setFocusPolicy(QWidget::StrongFocus); |
107 | 107 | ||
108 | newButton= new QPushButton( this, "newButton" ); | 108 | newButton= new QPushButton( this, "newButton" ); |
109 | newButton->setText(tr("New")); | 109 | newButton->setText(tr("New")); |
110 | hbox->addWidget( newButton); | 110 | hbox->addWidget( newButton); |
111 | |||
112 | deleteButton= new QPushButton( this, "deleteButton" ); | ||
113 | deleteButton->setText(tr("Delete")); | ||
114 | hbox->addWidget( deleteButton); | ||
115 | |||
111 | vbox->addItem(hbox); | 116 | vbox->addItem(hbox); |
112 | 117 | ||
113 | connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), | 118 | connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), |
114 | this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); | 119 | this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); |
115 | connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); | 120 | connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); |
116 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); | 121 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); |
117 | 122 | ||
118 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); | 123 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); |
119 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); | 124 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); |
125 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButton())); | ||
120 | populateBox(); | 126 | populateBox(); |
121 | load(); | 127 | load(); |
122 | setCaption("Notes"); | 128 | setCaption("Notes"); |
123 | // parent->setFocus(); | 129 | // parent->setFocus(); |
124 | } | 130 | } |
125 | 131 | ||
126 | void NotesControl::slotDeleteButton() { | 132 | void NotesControl::slotDeleteButton() { |
133 | |||
127 | QString selectedText = box->currentText(); | 134 | QString selectedText = box->currentText(); |
128 | qDebug("deleting "+selectedText); | 135 | qDebug("deleting "+selectedText); |
136 | |||
137 | if( !selectedText.isEmpty()) { | ||
129 | Config cfg("Notes"); | 138 | Config cfg("Notes"); |
130 | cfg.setGroup("Docs"); | 139 | cfg.setGroup("Docs"); |
131 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 140 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
132 | QString entryName, entryName2;; | 141 | QString entryName, entryName2;; |
133 | for ( int i = 0; i < noOfFiles; i++ ) { | 142 | for ( int i = 0; i < noOfFiles; i++ ) { |
134 | entryName.sprintf( "File%i", i + 1 ); | 143 | entryName.sprintf( "File%i", i + 1 ); |
135 | if(selectedText == cfg.readEntry( entryName )) { | 144 | if(selectedText == cfg.readEntry( entryName )) { |
136 | qDebug("removing %s, %d", selectedText.latin1(), i); | 145 | qDebug("removing %s, %d", selectedText.latin1(), i); |
137 | for ( int j = i; j < noOfFiles; j++ ) { | 146 | for ( int j = i; j < noOfFiles; j++ ) { |
138 | entryName.sprintf( "File%i", i + 1 ); | 147 | entryName.sprintf( "File%i", i + 1 ); |
139 | entryName2.sprintf( "File%i", i + 2 ); | 148 | entryName2.sprintf( "File%i", i + 2 ); |
140 | QString temp = cfg.readEntry(entryName2); | 149 | QString temp = cfg.readEntry(entryName2); |
@@ -142,24 +151,25 @@ void NotesControl::slotDeleteButton() { | |||
142 | cfg.writeEntry(entryName, temp); | 151 | cfg.writeEntry(entryName, temp); |
143 | i++; | 152 | i++; |
144 | } | 153 | } |
145 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); | 154 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); |
146 | entryName.sprintf( "File%i", noOfFiles ); | 155 | entryName.sprintf( "File%i", noOfFiles ); |
147 | cfg.removeEntry(entryName); | 156 | cfg.removeEntry(entryName); |
148 | cfg.write(); | 157 | cfg.write(); |
149 | DocLnk nf(selectedText); | 158 | DocLnk nf(selectedText); |
150 | nf.removeFiles(); | 159 | nf.removeFiles(); |
151 | } | 160 | } |
152 | } | 161 | } |
153 | populateBox(); | 162 | populateBox(); |
163 | } | ||
154 | } | 164 | } |
155 | 165 | ||
156 | void NotesControl::slotNewButton() { | 166 | void NotesControl::slotNewButton() { |
157 | if(edited) save(); | 167 | if(edited) save(); |
158 | view->clear(); | 168 | view->clear(); |
159 | view->setFocus(); | 169 | view->setFocus(); |
160 | } | 170 | } |
161 | 171 | ||
162 | void NotesControl::boxPressed(int mouse, QListBoxItem *item, const QPoint&) { | 172 | void NotesControl::boxPressed(int mouse, QListBoxItem *item, const QPoint&) { |
163 | switch (mouse) { | 173 | switch (mouse) { |
164 | case 1:{ | 174 | case 1:{ |
165 | } | 175 | } |
@@ -238,66 +248,67 @@ void NotesControl::save() { | |||
238 | doc = new DocLnk(docname); | 248 | doc = new DocLnk(docname); |
239 | 249 | ||
240 | doc->setType("text/plain"); | 250 | doc->setType("text/plain"); |
241 | doc->setFile(docname); | 251 | doc->setFile(docname); |
242 | doc->setName(docname); | 252 | doc->setName(docname); |
243 | 253 | ||
244 | FileManager fm; | 254 | FileManager fm; |
245 | if ( !fm.saveFile( *doc, rt ) ) { | 255 | if ( !fm.saveFile( *doc, rt ) ) { |
246 | } | 256 | } |
247 | 257 | ||
248 | oldDocName=docname; | 258 | oldDocName=docname; |
249 | edited=false; | 259 | edited=false; |
260 | qDebug("save"); | ||
261 | if (doPopulate) | ||
262 | populateBox(); | ||
250 | } | 263 | } |
251 | qDebug("save"); | ||
252 | if (doPopulate) | ||
253 | populateBox(); | ||
254 | } | ||
255 | cfg.writeEntry( "LastDoc",oldDocName ); | 264 | cfg.writeEntry( "LastDoc",oldDocName ); |
256 | cfg.write(); | 265 | cfg.write(); |
266 | |||
267 | } | ||
257 | } | 268 | } |
258 | 269 | ||
259 | void NotesControl::populateBox() { | 270 | void NotesControl::populateBox() { |
260 | box->clear(); | 271 | box->clear(); |
261 | qDebug("populate"); | 272 | qDebug("populate"); |
262 | Config cfg("Notes"); | 273 | Config cfg("Notes"); |
263 | cfg.setGroup("Docs"); | 274 | cfg.setGroup("Docs"); |
264 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 275 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
265 | QStringList list; | 276 | QStringList list; |
266 | QString entryName; | 277 | QString entryName; |
267 | for ( int i = 0; i < noOfFiles; i++ ) { | 278 | for ( int i = 0; i < noOfFiles; i++ ) { |
268 | entryName.sprintf( "File%i", i + 1 ); | 279 | entryName.sprintf( "File%i", i + 1 ); |
269 | list.append(cfg.readEntry( entryName )); | 280 | list.append(cfg.readEntry( entryName )); |
270 | } | 281 | } |
271 | list.sort(); | 282 | list.sort(); |
272 | box->insertStringList(list,-1); | 283 | box->insertStringList(list,-1); |
273 | doPopulate=false; | 284 | doPopulate=false; |
274 | } | 285 | } |
275 | 286 | ||
276 | void NotesControl::load() { | 287 | void NotesControl::load() { |
277 | 288 | ||
278 | Config cfg("Notes"); | ||
279 | cfg.setGroup("Docs"); | ||
280 | if(!loaded) { | 289 | if(!loaded) { |
290 | Config cfg("Notes"); | ||
291 | cfg.setGroup("Docs"); | ||
281 | QString lastDoc=cfg.readEntry( "LastDoc",""); | 292 | QString lastDoc=cfg.readEntry( "LastDoc",""); |
282 | DocLnk nf; | 293 | DocLnk nf; |
283 | nf.setType("text/plain"); | 294 | nf.setType("text/plain"); |
284 | nf.setFile(lastDoc); | 295 | nf.setFile(lastDoc); |
285 | 296 | ||
286 | loadDoc(nf); | 297 | loadDoc(nf); |
287 | loaded=true; | 298 | loaded=true; |
288 | oldDocName=lastDoc; | 299 | oldDocName=lastDoc; |
289 | } | 300 | cfg.writeEntry( "LastDoc",oldDocName ); |
290 | cfg.writeEntry( "LastDoc",oldDocName ); | 301 | cfg.write(); |
291 | cfg.write(); | 302 | } |
292 | } | 303 | } |
293 | 304 | ||
294 | void NotesControl::load(const QString & file) { | 305 | void NotesControl::load(const QString & file) { |
295 | qDebug("loading "+file); | 306 | qDebug("loading "+file); |
296 | if(!loaded) { | 307 | if(!loaded) { |
297 | DocLnk nf; | 308 | DocLnk nf; |
298 | nf.setType("text/plain"); | 309 | nf.setType("text/plain"); |
299 | nf.setFile( file); | 310 | nf.setFile( file); |
300 | 311 | ||
301 | loadDoc(nf); | 312 | loadDoc(nf); |
302 | loaded=true; | 313 | loaded=true; |
303 | } | 314 | } |
@@ -340,24 +351,25 @@ void NotesApplet::mousePressEvent( QMouseEvent *) { | |||
340 | if( !vc->isHidden()) { | 351 | if( !vc->isHidden()) { |
341 | vc->doPopulate=false; | 352 | vc->doPopulate=false; |
342 | vc->save(); | 353 | vc->save(); |
343 | vc->close(); | 354 | vc->close(); |
344 | } else { | 355 | } else { |
345 | // vc = new NotesControl; | 356 | // vc = new NotesControl; |
346 | // QPoint curPos = mapToGlobal( rect().topLeft() ); | 357 | // QPoint curPos = mapToGlobal( rect().topLeft() ); |
347 | vc->show(); | 358 | vc->show(); |
348 | vc->move( 5, 18); | 359 | vc->move( 5, 18); |
349 | vc->doPopulate=true; | 360 | vc->doPopulate=true; |
350 | vc->populateBox(); | 361 | vc->populateBox(); |
351 | vc->doPopulate=false; | 362 | vc->doPopulate=false; |
363 | vc->loaded=false; | ||
352 | 364 | ||
353 | vc->load(); | 365 | vc->load(); |
354 | // this->setFocus(); | 366 | // this->setFocus(); |
355 | vc->view->setFocus(); | 367 | vc->view->setFocus(); |
356 | } | 368 | } |
357 | } | 369 | } |
358 | 370 | ||
359 | void NotesApplet::paintEvent( QPaintEvent* ) { | 371 | void NotesApplet::paintEvent( QPaintEvent* ) { |
360 | QPainter p(this); | 372 | QPainter p(this); |
361 | p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); | 373 | p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); |
362 | } | 374 | } |
363 | 375 | ||