author | llornkcor <llornkcor> | 2002-09-24 01:53:27 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-09-24 01:53:27 (UTC) |
commit | ef40f0d781c904723d7842fc8be8f7dbad0614da (patch) (unidiff) | |
tree | 3c90068d73e19cf1fea43de570d7cd08c7ef6c33 | |
parent | a2c7b045c9a3ff9e275858b66e7fe29bdf4d8e31 (diff) | |
download | opie-ef40f0d781c904723d7842fc8be8f7dbad0614da.zip opie-ef40f0d781c904723d7842fc8be8f7dbad0614da.tar.gz opie-ef40f0d781c904723d7842fc8be8f7dbad0614da.tar.bz2 |
added delete confirm to button
-rw-r--r-- | noncore/applets/notesapplet/notes.cpp | 61 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notes.h | 1 |
2 files changed, 37 insertions, 25 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp index cc5245c..81864c6 100644 --- a/noncore/applets/notesapplet/notes.cpp +++ b/noncore/applets/notesapplet/notes.cpp | |||
@@ -1,375 +1,386 @@ | |||
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 <qsocket.h> | 30 | #include <qsocket.h> |
31 | 31 | ||
32 | #include <qmultilineedit.h> | 32 | #include <qmultilineedit.h> |
33 | #include <qlistbox.h> | 33 | #include <qlistbox.h> |
34 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
35 | #include <qmessagebox.h> | 35 | #include <qmessagebox.h> |
36 | 36 | ||
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qpoint.h> | 38 | #include <qpoint.h> |
39 | #include <qpushbutton.h> | 39 | #include <qpushbutton.h> |
40 | #include <qpainter.h> | 40 | #include <qpainter.h> |
41 | #include <qlayout.h> | 41 | #include <qlayout.h> |
42 | #include <qframe.h> | 42 | #include <qframe.h> |
43 | #include <qpixmap.h> | 43 | #include <qpixmap.h> |
44 | #include <qstring.h> | 44 | #include <qstring.h> |
45 | #include <qtimer.h> | 45 | #include <qtimer.h> |
46 | 46 | ||
47 | /* XPM */ | 47 | /* XPM */ |
48 | static char * notes_xpm[] = { | 48 | static char * notes_xpm[] = { |
49 | "16 16 11 1", | 49 | "16 16 11 1", |
50 | " c None", | 50 | " c None", |
51 | ". c #000000", | 51 | ". c #000000", |
52 | "+ c #7F7F7F", | 52 | "+ c #7F7F7F", |
53 | "@ c #BFBFBF", | 53 | "@ c #BFBFBF", |
54 | "# c #BFC1FF", | 54 | "# c #BFC1FF", |
55 | "$ c #FF0000", | 55 | "$ c #FF0000", |
56 | "% c #FFFFFF", | 56 | "% c #FFFFFF", |
57 | "& c #00037F", | 57 | "& c #00037F", |
58 | "* c #0006FF", | 58 | "* c #0006FF", |
59 | "= c #0005BF", | 59 | "= c #0005BF", |
60 | "- c #7F0000", | 60 | "- c #7F0000", |
61 | " .. ", | 61 | " .. ", |
62 | " .. ", | 62 | " .. ", |
63 | " ... ", | 63 | " ... ", |
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 | 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, 0, -1, "HLayout" ); | 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 | 111 | ||
112 | deleteButton= new QPushButton( this, "deleteButton" ); | 112 | deleteButton= new QPushButton( this, "deleteButton" ); |
113 | deleteButton->setText(tr("Delete")); | 113 | deleteButton->setText(tr("Delete")); |
114 | hbox->addWidget( deleteButton); | 114 | hbox->addWidget( deleteButton); |
115 | 115 | ||
116 | vbox->addItem(hbox); | 116 | vbox->addItem(hbox); |
117 | 117 | ||
118 | connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), | 118 | connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), |
119 | this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); | 119 | this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); |
120 | connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); | 120 | connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); |
121 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); | 121 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); |
122 | 122 | ||
123 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); | 123 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); |
124 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); | 124 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); |
125 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButton())); | 125 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); |
126 | |||
126 | populateBox(); | 127 | populateBox(); |
127 | load(); | 128 | load(); |
128 | setCaption("Notes"); | 129 | setCaption("Notes"); |
129 | // parent->setFocus(); | 130 | // parent->setFocus(); |
130 | } | 131 | } |
131 | 132 | ||
133 | void NotesControl::slotDeleteButtonClicked() { | ||
134 | switch ( QMessageBox::warning(this,tr("Delete?"),tr("Do you really want to<BR><B> delete</B> this note ?") | ||
135 | ,tr("Yes"),tr("No"),0,1,1) ) { | ||
136 | case 0: | ||
137 | slotDeleteButton(); | ||
138 | break; | ||
139 | }; | ||
140 | } | ||
141 | |||
132 | void NotesControl::slotDeleteButton() { | 142 | void NotesControl::slotDeleteButton() { |
133 | 143 | ||
134 | QString selectedText = box->currentText(); | 144 | QString selectedText = box->currentText(); |
135 | qDebug("deleting "+selectedText); | 145 | qDebug("deleting "+selectedText); |
136 | 146 | ||
137 | if( !selectedText.isEmpty()) { | 147 | if( !selectedText.isEmpty()) { |
138 | Config cfg("Notes"); | 148 | |
139 | cfg.setGroup("Docs"); | 149 | Config cfg("Notes"); |
140 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 150 | cfg.setGroup("Docs"); |
141 | QString entryName, entryName2;; | 151 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
142 | for ( int i = 0; i < noOfFiles; i++ ) { | 152 | QString entryName, entryName2;; |
143 | entryName.sprintf( "File%i", i + 1 ); | 153 | for ( int i = 0; i < noOfFiles; i++ ) { |
144 | if(selectedText == cfg.readEntry( entryName )) { | 154 | entryName.sprintf( "File%i", i + 1 ); |
145 | qDebug("removing %s, %d", selectedText.latin1(), i); | 155 | if(selectedText == cfg.readEntry( entryName )) { |
146 | for ( int j = i; j < noOfFiles; j++ ) { | 156 | qDebug("removing %s, %d", selectedText.latin1(), i); |
147 | entryName.sprintf( "File%i", i + 1 ); | 157 | for ( int j = i; j < noOfFiles; j++ ) { |
148 | entryName2.sprintf( "File%i", i + 2 ); | 158 | entryName.sprintf( "File%i", i + 1 ); |
149 | QString temp = cfg.readEntry(entryName2); | 159 | entryName2.sprintf( "File%i", i + 2 ); |
150 | qDebug("move "+temp); | 160 | QString temp = cfg.readEntry(entryName2); |
151 | cfg.writeEntry(entryName, temp); | 161 | qDebug("move "+temp); |
152 | i++; | 162 | cfg.writeEntry(entryName, temp); |
163 | i++; | ||
164 | } | ||
165 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); | ||
166 | entryName.sprintf( "File%i", noOfFiles ); | ||
167 | cfg.removeEntry(entryName); | ||
168 | cfg.write(); | ||
169 | DocLnk nf(selectedText); | ||
170 | nf.removeFiles(); | ||
153 | } | 171 | } |
154 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); | ||
155 | entryName.sprintf( "File%i", noOfFiles ); | ||
156 | cfg.removeEntry(entryName); | ||
157 | cfg.write(); | ||
158 | DocLnk nf(selectedText); | ||
159 | nf.removeFiles(); | ||
160 | } | 172 | } |
161 | } | 173 | populateBox(); |
162 | populateBox(); | ||
163 | } | 174 | } |
164 | } | 175 | } |
165 | 176 | ||
166 | void NotesControl::slotNewButton() { | 177 | void NotesControl::slotNewButton() { |
167 | if(edited) save(); | 178 | if(edited) save(); |
168 | view->clear(); | 179 | view->clear(); |
169 | view->setFocus(); | 180 | view->setFocus(); |
170 | } | 181 | } |
171 | 182 | ||
172 | void NotesControl::boxPressed(int mouse, QListBoxItem *item, const QPoint&) { | 183 | void NotesControl::boxPressed(int mouse, QListBoxItem *item, const QPoint&) { |
173 | switch (mouse) { | 184 | switch (mouse) { |
174 | case 1:{ | 185 | case 1:{ |
175 | } | 186 | } |
176 | break; | 187 | break; |
177 | case 2: | 188 | case 2: |
178 | menuTimer.start( 500, TRUE ); | 189 | menuTimer.start( 500, TRUE ); |
179 | break; | 190 | break; |
180 | }; | 191 | }; |
181 | } | 192 | } |
182 | 193 | ||
183 | void NotesControl::slotBoxSelected(const QString &itemString) { | 194 | void NotesControl::slotBoxSelected(const QString &itemString) { |
184 | if(edited) { | 195 | if(edited) { |
185 | save(); | 196 | save(); |
186 | } | 197 | } |
187 | loaded=false; | 198 | loaded=false; |
188 | edited=false; | 199 | edited=false; |
189 | load(itemString); | 200 | load(itemString); |
190 | } | 201 | } |
191 | 202 | ||
192 | 203 | ||
193 | void NotesControl::showMenu() { | 204 | void NotesControl::showMenu() { |
194 | QPopupMenu *m = new QPopupMenu(0); | 205 | QPopupMenu *m = new QPopupMenu(0); |
195 | 206 | ||
196 | m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); | 207 | m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); |
197 | 208 | ||
198 | m->setFocus(); | 209 | m->setFocus(); |
199 | m->exec( QCursor::pos() ); | 210 | m->exec( QCursor::pos() ); |
200 | 211 | ||
201 | if(m) delete m; | 212 | if(m) delete m; |
202 | 213 | ||
203 | } | 214 | } |
204 | 215 | ||
205 | void NotesControl::focusOutEvent ( QFocusEvent * e) { | 216 | void NotesControl::focusOutEvent ( QFocusEvent * e) { |
206 | if( e->reason() == QFocusEvent::Popup) | 217 | if( e->reason() == QFocusEvent::Popup) |
207 | save(); | 218 | save(); |
208 | else { | 219 | else { |
209 | if(!loaded) { | 220 | if(!loaded) { |
210 | populateBox(); | 221 | populateBox(); |
211 | load(); | 222 | load(); |
212 | } | 223 | } |
213 | } | 224 | } |
214 | QWidget::focusOutEvent(e); | 225 | QWidget::focusOutEvent(e); |
215 | } | 226 | } |
216 | 227 | ||
217 | void NotesControl::save() { | 228 | void NotesControl::save() { |
218 | Config cfg("Notes"); | 229 | Config cfg("Notes"); |
219 | cfg.setGroup("Docs"); | 230 | cfg.setGroup("Docs"); |
220 | if( edited) { | 231 | if( edited) { |
221 | QString rt = view->text(); | 232 | QString rt = view->text(); |
222 | if(!rt.isEmpty()) { | 233 | if(!rt.isEmpty()) { |
223 | QString pt = rt.simplifyWhiteSpace(); | 234 | QString pt = rt.simplifyWhiteSpace(); |
224 | int i = pt.find( ' ' ); | 235 | int i = pt.find( ' ' ); |
225 | QString docname = pt; | 236 | QString docname = pt; |
226 | if ( i > 0 ) | 237 | if ( i > 0 ) |
227 | docname = pt.left( i ); | 238 | docname = pt.left( i ); |
228 | // remove "." at the beginning | 239 | // remove "." at the beginning |
229 | while( docname.startsWith( "." ) ) | 240 | while( docname.startsWith( "." ) ) |
230 | docname = docname.mid( 1 ); | 241 | docname = docname.mid( 1 ); |
231 | docname.replace( QRegExp("/"), "_" ); | 242 | docname.replace( QRegExp("/"), "_" ); |
232 | // cut the length. filenames longer than that don't make sense | 243 | // cut the length. filenames longer than that don't make sense |
233 | // and something goes wrong when they get too long. | 244 | // and something goes wrong when they get too long. |
234 | if ( docname.length() > 40 ) | 245 | if ( docname.length() > 40 ) |
235 | docname = docname.left(40); | 246 | docname = docname.left(40); |
236 | if ( docname.isEmpty() ) | 247 | if ( docname.isEmpty() ) |
237 | docname = "Empty Text"; | 248 | docname = "Empty Text"; |
238 | qDebug(docname); | 249 | qDebug(docname); |
239 | 250 | ||
240 | if( oldDocName != docname) { | 251 | if( oldDocName != docname) { |
241 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 252 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
242 | QString entryName; | 253 | QString entryName; |
243 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 254 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
244 | cfg.writeEntry( entryName,docname ); | 255 | cfg.writeEntry( entryName,docname ); |
245 | cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); | 256 | cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); |
246 | cfg.write(); | 257 | cfg.write(); |
247 | } | 258 | } |
248 | doc = new DocLnk(docname); | 259 | doc = new DocLnk(docname); |
249 | 260 | ||
250 | doc->setType("text/plain"); | 261 | doc->setType("text/plain"); |
251 | doc->setFile(docname); | 262 | doc->setFile(docname); |
252 | doc->setName(docname); | 263 | doc->setName(docname); |
253 | 264 | ||
254 | FileManager fm; | 265 | FileManager fm; |
255 | if ( !fm.saveFile( *doc, rt ) ) { | 266 | if ( !fm.saveFile( *doc, rt ) ) { |
256 | } | 267 | } |
257 | 268 | ||
258 | oldDocName=docname; | 269 | oldDocName=docname; |
259 | edited=false; | 270 | edited=false; |
260 | qDebug("save"); | 271 | qDebug("save"); |
261 | if (doPopulate) | 272 | if (doPopulate) |
262 | populateBox(); | 273 | populateBox(); |
263 | } | 274 | } |
264 | cfg.writeEntry( "LastDoc",oldDocName ); | 275 | cfg.writeEntry( "LastDoc",oldDocName ); |
265 | cfg.write(); | 276 | cfg.write(); |
266 | 277 | ||
267 | } | 278 | } |
268 | } | 279 | } |
269 | 280 | ||
270 | void NotesControl::populateBox() { | 281 | void NotesControl::populateBox() { |
271 | box->clear(); | 282 | box->clear(); |
272 | qDebug("populate"); | 283 | qDebug("populate"); |
273 | Config cfg("Notes"); | 284 | Config cfg("Notes"); |
274 | cfg.setGroup("Docs"); | 285 | cfg.setGroup("Docs"); |
275 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 286 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
276 | QStringList list; | 287 | QStringList list; |
277 | QString entryName; | 288 | QString entryName; |
278 | for ( int i = 0; i < noOfFiles; i++ ) { | 289 | for ( int i = 0; i < noOfFiles; i++ ) { |
279 | entryName.sprintf( "File%i", i + 1 ); | 290 | entryName.sprintf( "File%i", i + 1 ); |
280 | list.append(cfg.readEntry( entryName )); | 291 | list.append(cfg.readEntry( entryName )); |
281 | } | 292 | } |
282 | list.sort(); | 293 | list.sort(); |
283 | box->insertStringList(list,-1); | 294 | box->insertStringList(list,-1); |
284 | doPopulate=false; | 295 | doPopulate=false; |
285 | } | 296 | } |
286 | 297 | ||
287 | void NotesControl::load() { | 298 | void NotesControl::load() { |
288 | 299 | ||
289 | if(!loaded) { | 300 | if(!loaded) { |
290 | Config cfg("Notes"); | 301 | Config cfg("Notes"); |
291 | cfg.setGroup("Docs"); | 302 | cfg.setGroup("Docs"); |
292 | QString lastDoc=cfg.readEntry( "LastDoc",""); | 303 | QString lastDoc=cfg.readEntry( "LastDoc",""); |
293 | DocLnk nf; | 304 | DocLnk nf; |
294 | nf.setType("text/plain"); | 305 | nf.setType("text/plain"); |
295 | nf.setFile(lastDoc); | 306 | nf.setFile(lastDoc); |
296 | 307 | ||
297 | loadDoc(nf); | 308 | loadDoc(nf); |
298 | loaded=true; | 309 | loaded=true; |
299 | oldDocName=lastDoc; | 310 | oldDocName=lastDoc; |
300 | cfg.writeEntry( "LastDoc",oldDocName ); | 311 | cfg.writeEntry( "LastDoc",oldDocName ); |
301 | cfg.write(); | 312 | cfg.write(); |
302 | } | 313 | } |
303 | } | 314 | } |
304 | 315 | ||
305 | void NotesControl::load(const QString & file) { | 316 | void NotesControl::load(const QString & file) { |
306 | qDebug("loading "+file); | 317 | qDebug("loading "+file); |
307 | if(!loaded) { | 318 | if(!loaded) { |
308 | DocLnk nf; | 319 | DocLnk nf; |
309 | nf.setType("text/plain"); | 320 | nf.setType("text/plain"); |
310 | nf.setFile( file); | 321 | nf.setFile( file); |
311 | 322 | ||
312 | loadDoc(nf); | 323 | loadDoc(nf); |
313 | loaded=true; | 324 | loaded=true; |
314 | } | 325 | } |
315 | // view->setFocus(); | 326 | // view->setFocus(); |
316 | oldDocName=file; | 327 | oldDocName=file; |
317 | Config cfg("Notes"); | 328 | Config cfg("Notes"); |
318 | cfg.setGroup("Docs"); | 329 | cfg.setGroup("Docs"); |
319 | cfg.writeEntry( "LastDoc",oldDocName ); | 330 | cfg.writeEntry( "LastDoc",oldDocName ); |
320 | cfg.write(); | 331 | cfg.write(); |
321 | } | 332 | } |
322 | 333 | ||
323 | void NotesControl::loadDoc( const DocLnk &f) { | 334 | void NotesControl::loadDoc( const DocLnk &f) { |
324 | FileManager fm; | 335 | FileManager fm; |
325 | QString txt; | 336 | QString txt; |
326 | if ( !fm.loadFile( f, txt ) ) { | 337 | if ( !fm.loadFile( f, txt ) ) { |
327 | return; | 338 | return; |
328 | } | 339 | } |
329 | view->setText(txt); | 340 | view->setText(txt); |
330 | } | 341 | } |
331 | 342 | ||
332 | void NotesControl::slotViewEdited() { | 343 | void NotesControl::slotViewEdited() { |
333 | if(loaded) { | 344 | if(loaded) { |
334 | edited=true; | 345 | edited=true; |
335 | } | 346 | } |
336 | } | 347 | } |
337 | 348 | ||
338 | //=========================================================================== | 349 | //=========================================================================== |
339 | 350 | ||
340 | NotesApplet::NotesApplet( QWidget *parent, const char *name ) | 351 | NotesApplet::NotesApplet( QWidget *parent, const char *name ) |
341 | : QWidget( parent, name ) { | 352 | : QWidget( parent, name ) { |
342 | setFixedHeight( 18 ); | 353 | setFixedHeight( 18 ); |
343 | setFixedWidth( 14 ); | 354 | setFixedWidth( 14 ); |
344 | vc = new NotesControl; | 355 | vc = new NotesControl; |
345 | } | 356 | } |
346 | 357 | ||
347 | NotesApplet::~NotesApplet() { | 358 | NotesApplet::~NotesApplet() { |
348 | } | 359 | } |
349 | 360 | ||
350 | void NotesApplet::mousePressEvent( QMouseEvent *) { | 361 | void NotesApplet::mousePressEvent( QMouseEvent *) { |
351 | if( !vc->isHidden()) { | 362 | if( !vc->isHidden()) { |
352 | vc->doPopulate=false; | 363 | vc->doPopulate=false; |
353 | vc->save(); | 364 | vc->save(); |
354 | vc->close(); | 365 | vc->close(); |
355 | } else { | 366 | } else { |
356 | // vc = new NotesControl; | 367 | // vc = new NotesControl; |
357 | // QPoint curPos = mapToGlobal( rect().topLeft() ); | 368 | // QPoint curPos = mapToGlobal( rect().topLeft() ); |
358 | vc->show(); | 369 | vc->show(); |
359 | vc->move( 5, 18); | 370 | vc->move( 5, 18); |
360 | vc->doPopulate=true; | 371 | vc->doPopulate=true; |
361 | vc->populateBox(); | 372 | vc->populateBox(); |
362 | vc->doPopulate=false; | 373 | vc->doPopulate=false; |
363 | vc->loaded=false; | 374 | vc->loaded=false; |
364 | 375 | ||
365 | vc->load(); | 376 | vc->load(); |
366 | // this->setFocus(); | 377 | // this->setFocus(); |
367 | vc->view->setFocus(); | 378 | vc->view->setFocus(); |
368 | } | 379 | } |
369 | } | 380 | } |
370 | 381 | ||
371 | void NotesApplet::paintEvent( QPaintEvent* ) { | 382 | void NotesApplet::paintEvent( QPaintEvent* ) { |
372 | QPainter p(this); | 383 | QPainter p(this); |
373 | p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); | 384 | p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); |
374 | } | 385 | } |
375 | 386 | ||
diff --git a/noncore/applets/notesapplet/notes.h b/noncore/applets/notesapplet/notes.h index c589f81..473a89a 100644 --- a/noncore/applets/notesapplet/notes.h +++ b/noncore/applets/notesapplet/notes.h | |||
@@ -1,84 +1,85 @@ | |||
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 <qstring.h> | 24 | #include <qstring.h> |
25 | 25 | ||
26 | class QComboBox; | 26 | class QComboBox; |
27 | class QCheckBox; | 27 | class QCheckBox; |
28 | class QSpinBox; | 28 | class QSpinBox; |
29 | class QPushButton; | 29 | class QPushButton; |
30 | class QMultiLineEdit; | 30 | class QMultiLineEdit; |
31 | class QListBox; | 31 | class QListBox; |
32 | class QListBoxItem; | 32 | class QListBoxItem; |
33 | class NotesControl : public QFrame { | 33 | class NotesControl : public QFrame { |
34 | Q_OBJECT | 34 | Q_OBJECT |
35 | public: | 35 | public: |
36 | NotesControl( QWidget *parent=0, const char *name=0 ); | 36 | NotesControl( QWidget *parent=0, const char *name=0 ); |
37 | void performGrab(); | 37 | void performGrab(); |
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; | 44 | bool loaded, edited, doPopulate; |
45 | void save(); | 45 | void save(); |
46 | void populateBox(); | 46 | void populateBox(); |
47 | void load(); | 47 | void load(); |
48 | 48 | ||
49 | private: | 49 | private: |
50 | QTimer menuTimer; | 50 | QTimer menuTimer; |
51 | DocLnk *doc; | 51 | DocLnk *doc; |
52 | QString oldDocName; | 52 | QString oldDocName; |
53 | void focusOutEvent( QFocusEvent * ); | 53 | void focusOutEvent( QFocusEvent * ); |
54 | void load(const QString&); | 54 | void load(const QString&); |
55 | private slots: | 55 | private slots: |
56 | void slotDeleteButton(); | 56 | void slotDeleteButton(); |
57 | void slotDeleteButtonClicked(); | ||
57 | void slotNewButton(); | 58 | void slotNewButton(); |
58 | void boxPressed(int, QListBoxItem *, const QPoint&); | 59 | void boxPressed(int, QListBoxItem *, const QPoint&); |
59 | void showMenu(); | 60 | void showMenu(); |
60 | void loadDoc( const DocLnk &); | 61 | void loadDoc( const DocLnk &); |
61 | void slotViewEdited(); | 62 | void slotViewEdited(); |
62 | void slotBoxSelected(const QString &); | 63 | void slotBoxSelected(const QString &); |
63 | }; | 64 | }; |
64 | 65 | ||
65 | class NotesApplet : public QWidget { | 66 | class NotesApplet : public QWidget { |
66 | Q_OBJECT | 67 | Q_OBJECT |
67 | public: | 68 | public: |
68 | NotesApplet( QWidget *parent = 0, const char *name=0 ); | 69 | NotesApplet( QWidget *parent = 0, const char *name=0 ); |
69 | ~NotesApplet(); | 70 | ~NotesApplet(); |
70 | NotesControl *vc; | 71 | NotesControl *vc; |
71 | public slots: | 72 | public slots: |
72 | private: | 73 | private: |
73 | void mousePressEvent( QMouseEvent * ); | 74 | void mousePressEvent( QMouseEvent * ); |
74 | void paintEvent( QPaintEvent* ); | 75 | void paintEvent( QPaintEvent* ); |
75 | 76 | ||
76 | private: | 77 | private: |
77 | QPixmap notesPixmap; | 78 | QPixmap notesPixmap; |
78 | private slots: | 79 | private slots: |
79 | 80 | ||
80 | 81 | ||
81 | }; | 82 | }; |
82 | 83 | ||
83 | #endif // __NOTES_APPLET_H__ | 84 | #endif // __NOTES_APPLET_H__ |
84 | 85 | ||