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