-rw-r--r-- | noncore/applets/notesapplet/notes.cpp | 76 |
1 files changed, 23 insertions, 53 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp index b3e72a7..d06672a 100644 --- a/noncore/applets/notesapplet/notes.cpp +++ b/noncore/applets/notesapplet/notes.cpp | |||
@@ -1,123 +1,92 @@ | |||
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 | /* OPIE */ | 18 | /* OPIE */ |
19 | #include <opie2/odebug.h> | 19 | #include <opie2/odebug.h> |
20 | #include <opie2/otaskbarapplet.h> | 20 | #include <opie2/otaskbarapplet.h> |
21 | #include <qpe/filemanager.h> | 21 | #include <qpe/filemanager.h> |
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #include <qpe/timestring.h> | 23 | #include <qpe/timestring.h> |
24 | #include <qpe/applnk.h> | 24 | #include <qpe/applnk.h> |
25 | #include <qpe/ir.h> | 25 | #include <qpe/ir.h> |
26 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
27 | #include <qpe/resource.h> | ||
27 | using namespace Opie::Core; | 28 | using namespace Opie::Core; |
28 | using namespace Opie::Ui; | 29 | using namespace Opie::Ui; |
29 | 30 | ||
30 | /* QT */ | 31 | /* QT */ |
31 | #include <qmultilineedit.h> | 32 | #include <qmultilineedit.h> |
32 | #include <qlistbox.h> | 33 | #include <qlistbox.h> |
33 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
34 | #include <qmessagebox.h> | 35 | #include <qmessagebox.h> |
35 | #include <qapplication.h> | 36 | #include <qapplication.h> |
36 | #include <qdir.h> | 37 | #include <qdir.h> |
37 | #include <qfile.h> | 38 | #include <qfile.h> |
38 | #include <qpoint.h> | 39 | #include <qpoint.h> |
39 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
40 | #include <qpainter.h> | 41 | #include <qpainter.h> |
41 | #include <qlayout.h> | 42 | #include <qlayout.h> |
42 | #include <qframe.h> | 43 | #include <qframe.h> |
43 | #include <qpixmap.h> | 44 | #include <qpixmap.h> |
44 | #include <qstring.h> | 45 | #include <qstring.h> |
45 | #include <qstringlist.h> | 46 | #include <qstringlist.h> |
46 | #include <qtimer.h> | 47 | #include <qtimer.h> |
47 | 48 | ||
48 | /* STD */ | 49 | /* STD */ |
49 | #include <stdlib.h> | 50 | #include <stdlib.h> |
50 | 51 | ||
51 | /* XPM */ | ||
52 | static char * notes_xpm[] = { | ||
53 | "16 16 11 1", | ||
54 | " c None", | ||
55 | ". c #000000", | ||
56 | "+ c #7F7F7F", | ||
57 | "@ c #BFBFBF", | ||
58 | "# c #BFC1FF", | ||
59 | "$ c #FF0000", | ||
60 | "% c #FFFFFF", | ||
61 | "& c #00037F", | ||
62 | "* c #0006FF", | ||
63 | "= c #0005BF", | ||
64 | "- c #7F0000", | ||
65 | " .. ", | ||
66 | " .. ", | ||
67 | " ... ", | ||
68 | " .+ ", | ||
69 | " .@. ", | ||
70 | " . .+ ", | ||
71 | " ..#.@. ", | ||
72 | " ..###.+.. ", | ||
73 | " ..###$...##.. ", | ||
74 | "..###$$$%+$$##&.", | ||
75 | ".*=####$-###&=&.", | ||
76 | ".=**=###==&=&=..", | ||
77 | " ..=**=#&=&=.. ", | ||
78 | " ..=*=&=.. ", | ||
79 | " ..=.. ", | ||
80 | " . "}; | ||
81 | |||
82 | |||
83 | NotesControl::NotesControl( QWidget *, const char * ) | 52 | NotesControl::NotesControl( QWidget *, const char * ) |
84 | : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop ) | 53 | : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop ) |
85 | // : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) | 54 | // : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) |
86 | { | 55 | { |
87 | QDir d( QDir::homeDirPath()+"/notes"); | 56 | QDir d( QDir::homeDirPath()+"/notes"); |
88 | if( !d.exists()) { | 57 | if( !d.exists()) { |
89 | odebug << "make dir" << oendl; | 58 | odebug << "make dir" << oendl; |
90 | if(!d.mkdir( QDir::homeDirPath()+"/notes", true)) | 59 | if(!d.mkdir( QDir::homeDirPath()+"/notes", true)) |
91 | odebug << "<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed" << oendl; | 60 | odebug << "<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed" << oendl; |
92 | } | 61 | } |
93 | Config cfg("Notes"); | 62 | Config cfg("Notes"); |
94 | cfg.setGroup("Options"); | 63 | cfg.setGroup("Options"); |
95 | showMax = cfg.readBoolEntry("ShowMax", false); | 64 | showMax = cfg.readBoolEntry("ShowMax", false); |
96 | 65 | ||
97 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 66 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
98 | loaded=false; | 67 | loaded=false; |
99 | edited=false; | 68 | edited=false; |
100 | doPopulate=true; | 69 | doPopulate=true; |
101 | isNew=false; | 70 | isNew=false; |
102 | QVBox *vbox = new QVBox( this, "Vlayout" ); | 71 | QVBox *vbox = new QVBox( this, "Vlayout" ); |
103 | QHBox *hbox = new QHBox( this, "HLayout" ); | 72 | QHBox *hbox = new QHBox( this, "HLayout" ); |
104 | 73 | ||
105 | view = new QMultiLineEdit(vbox, "OpieNotesView"); | 74 | view = new QMultiLineEdit(vbox, "OpieNotesView"); |
106 | 75 | ||
107 | box = new QListBox(vbox, "OpieNotesBox"); | 76 | box = new QListBox(vbox, "OpieNotesBox"); |
108 | 77 | ||
109 | QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); | 78 | QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); |
110 | 79 | ||
111 | box->setFixedHeight(50); | 80 | box->setFixedHeight(50); |
112 | 81 | ||
113 | vbox->setMargin( 6 ); | 82 | vbox->setMargin( 6 ); |
114 | vbox->setSpacing( 3 ); | 83 | vbox->setSpacing( 3 ); |
115 | 84 | ||
116 | 85 | ||
117 | 86 | ||
118 | setFocusPolicy(QWidget::StrongFocus); | 87 | setFocusPolicy(QWidget::StrongFocus); |
119 | 88 | ||
120 | newButton= new QPushButton( hbox, "newButton" ); | 89 | newButton= new QPushButton( hbox, "newButton" ); |
121 | newButton->setText(tr("New")); | 90 | newButton->setText(tr("New")); |
122 | 91 | ||
123 | 92 | ||
@@ -138,95 +107,95 @@ NotesControl::NotesControl( QWidget *, const char * ) | |||
138 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); | 107 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); |
139 | 108 | ||
140 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); | 109 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); |
141 | 110 | ||
142 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); | 111 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); |
143 | connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton())); | 112 | connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton())); |
144 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); | 113 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); |
145 | 114 | ||
146 | populateBox(); | 115 | populateBox(); |
147 | load(); | 116 | load(); |
148 | setCaption("Notes"); | 117 | setCaption("Notes"); |
149 | // parent->setFocus(); | 118 | // parent->setFocus(); |
150 | } | 119 | } |
151 | 120 | ||
152 | void NotesControl::slotSaveButton() { | 121 | void NotesControl::slotSaveButton() { |
153 | slotNewButton(); | 122 | slotNewButton(); |
154 | populateBox(); | 123 | populateBox(); |
155 | } | 124 | } |
156 | 125 | ||
157 | void NotesControl::slotDeleteButtonClicked() { | 126 | void NotesControl::slotDeleteButtonClicked() { |
158 | switch ( QMessageBox::warning(this,tr("Delete?") | 127 | switch ( QMessageBox::warning(this,tr("Delete?") |
159 | ,tr("Do you really want to<BR><B> delete</B> this note ?") | 128 | ,tr("Do you really want to<BR><B> delete</B> this note ?") |
160 | ,tr("Yes"),tr("No"),0,1,1) ) { | 129 | ,tr("Yes"),tr("No"),0,1,1) ) { |
161 | case 0: | 130 | case 0: |
162 | slotDeleteButton(); | 131 | slotDeleteButton(); |
163 | break; | 132 | break; |
164 | }; | 133 | }; |
165 | } | 134 | } |
166 | 135 | ||
167 | void NotesControl::slotDeleteButton() { | 136 | void NotesControl::slotDeleteButton() { |
168 | 137 | ||
169 | QString selectedText = box->currentText(); | 138 | QString selectedText = box->currentText(); |
170 | odebug << "deleting "+selectedText << oendl; | 139 | odebug << "deleting "+selectedText << oendl; |
171 | 140 | ||
172 | if( !selectedText.isEmpty()) { | 141 | if( !selectedText.isEmpty()) { |
173 | 142 | ||
174 | Config cfg("Notes"); | 143 | Config cfg("Notes"); |
175 | cfg.setGroup("Docs"); | 144 | cfg.setGroup("Docs"); |
176 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 145 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
177 | QString entryName, entryName2;; | 146 | QString entryName, entryName2;; |
178 | for ( int i = 0; i < noOfFiles; i++ ) { | 147 | for ( int i = 0; i < noOfFiles; i++ ) { |
179 | entryName.sprintf( "File%i", i + 1 ); | 148 | entryName.sprintf( "File%i", i + 1 ); |
180 | if(selectedText == cfg.readEntry( entryName )) { | 149 | if(selectedText == cfg.readEntry( entryName )) { |
181 | odebug << "removing " << selectedText.latin1() << ", " << i << "" << oendl; | 150 | odebug << "removing " << selectedText.latin1() << ", " << i << "" << oendl; |
182 | for ( int j = i; j < noOfFiles; j++ ) { | 151 | for ( int j = i; j < noOfFiles; j++ ) { |
183 | entryName.sprintf( "File%i", i + 1 ); | 152 | entryName.sprintf( "File%i", i + 1 ); |
184 | entryName2.sprintf( "File%i", i + 2 ); | 153 | entryName2.sprintf( "File%i", i + 2 ); |
185 | QString temp = cfg.readEntry(entryName2); | 154 | QString temp = cfg.readEntry(entryName2); |
186 | odebug << "move "+temp << oendl; | 155 | odebug << "move "+temp << oendl; |
187 | cfg.writeEntry(entryName, temp); | 156 | cfg.writeEntry(entryName, temp); |
188 | i++; | 157 | i++; |
189 | } | 158 | } |
190 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); | 159 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); |
191 | entryName.sprintf( "File%i", noOfFiles ); | 160 | entryName.sprintf( "File%i", noOfFiles ); |
192 | cfg.removeEntry(entryName); | 161 | cfg.removeEntry(entryName); |
193 | cfg.write(); | 162 | cfg.write(); |
194 | DocLnk nf(selectedText); | 163 | DocLnk nf(selectedText); |
195 | nf.removeFiles(); | 164 | nf.removeFiles(); |
196 | QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; | 165 | QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; |
197 | odebug << fi << oendl; | 166 | odebug << fi << oendl; |
198 | 167 | ||
199 | QFile f( fi); | 168 | QFile f( fi); |
200 | if( !f.remove()) odebug << ".desktop file not removed" << oendl; | 169 | if( !f.remove()) odebug << ".desktop file not removed" << oendl; |
201 | 170 | ||
202 | } | 171 | } |
203 | } | 172 | } |
204 | view->clear(); | 173 | view->clear(); |
205 | 174 | ||
206 | populateBox(); | 175 | populateBox(); |
207 | } | 176 | } |
208 | } | 177 | } |
209 | 178 | ||
210 | void NotesControl::slotNewButton() { | 179 | void NotesControl::slotNewButton() { |
211 | if(edited) save(); | 180 | if(edited) save(); |
212 | view->clear(); | 181 | view->clear(); |
213 | view->setFocus(); | 182 | view->setFocus(); |
214 | edited=false; | 183 | edited=false; |
215 | isNew=false; | 184 | isNew=false; |
216 | } | 185 | } |
217 | 186 | ||
218 | void NotesControl::slotBeamButton() { | 187 | void NotesControl::slotBeamButton() { |
219 | Ir ir; | 188 | Ir ir; |
220 | if(!ir.supported()){ | 189 | if(!ir.supported()){ |
221 | } else { | 190 | } else { |
222 | this->hide(); | 191 | this->hide(); |
223 | QString selectedText = box->currentText(); | 192 | QString selectedText = box->currentText(); |
224 | if( !selectedText.isEmpty()) { | 193 | if( !selectedText.isEmpty()) { |
225 | QString file = QDir::homeDirPath()+"/"+selectedText; | 194 | QString file = QDir::homeDirPath()+"/"+selectedText; |
226 | QFile f(file); | 195 | QFile f(file); |
227 | Ir *irFile = new Ir(this, "IR"); | 196 | Ir *irFile = new Ir(this, "IR"); |
228 | connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished(Ir*))); | 197 | connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished(Ir*))); |
229 | irFile->send( file, "Note", "text/plain" ); | 198 | irFile->send( file, "Note", "text/plain" ); |
230 | } | 199 | } |
231 | } | 200 | } |
232 | } | 201 | } |
@@ -256,261 +225,262 @@ void NotesControl::slotBoxSelected(const QString &itemString) { | |||
256 | } | 225 | } |
257 | 226 | ||
258 | 227 | ||
259 | void NotesControl::showMenu() { | 228 | void NotesControl::showMenu() { |
260 | QPopupMenu *m = new QPopupMenu(0); | 229 | QPopupMenu *m = new QPopupMenu(0); |
261 | m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() )); | 230 | m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() )); |
262 | m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() )); | 231 | m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() )); |
263 | m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() )); | 232 | m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() )); |
264 | m->insertSeparator(); | 233 | m->insertSeparator(); |
265 | m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); | 234 | m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); |
266 | m->setFocus(); | 235 | m->setFocus(); |
267 | m->exec( QCursor::pos() ); | 236 | m->exec( QCursor::pos() ); |
268 | 237 | ||
269 | if(m) delete m; | 238 | if(m) delete m; |
270 | } | 239 | } |
271 | 240 | ||
272 | void NotesControl::focusOutEvent ( QFocusEvent * e) { | 241 | void NotesControl::focusOutEvent ( QFocusEvent * e) { |
273 | if( e->reason() == QFocusEvent::Popup) | 242 | if( e->reason() == QFocusEvent::Popup) |
274 | save(); | 243 | save(); |
275 | else { | 244 | else { |
276 | if(!loaded) { | 245 | if(!loaded) { |
277 | populateBox(); | 246 | populateBox(); |
278 | load(); | 247 | load(); |
279 | } | 248 | } |
280 | } | 249 | } |
281 | QWidget::focusOutEvent(e); | 250 | QWidget::focusOutEvent(e); |
282 | } | 251 | } |
283 | 252 | ||
284 | void NotesControl::save() { | 253 | void NotesControl::save() { |
285 | Config cfg("Notes"); | 254 | Config cfg("Notes"); |
286 | cfg.setGroup("Docs"); | 255 | cfg.setGroup("Docs"); |
287 | if( edited) { | 256 | if( edited) { |
288 | // odebug << "is edited" << oendl; | 257 | // odebug << "is edited" << oendl; |
289 | QString rt = view->text(); | 258 | QString rt = view->text(); |
290 | if( rt.length()>1) { | 259 | if( rt.length()>1) { |
291 | QString pt = rt.simplifyWhiteSpace(); | 260 | QString pt = rt.simplifyWhiteSpace(); |
292 | int i = pt.find( ' ', pt.find( ' ' )+2 ); | 261 | int i = pt.find( ' ', pt.find( ' ' )+2 ); |
293 | QString docname = pt; | 262 | QString docname = pt; |
294 | if ( i > 0 ) | 263 | if ( i > 0 ) |
295 | docname = pt.left(i); | 264 | docname = pt.left(i); |
296 | // remove "." at the beginning | 265 | // remove "." at the beginning |
297 | while( docname.startsWith( "." ) ) | 266 | while( docname.startsWith( "." ) ) |
298 | docname = docname.mid( 1 ); | 267 | docname = docname.mid( 1 ); |
299 | docname.replace( QRegExp("/"), "_" ); | 268 | docname.replace( QRegExp("/"), "_" ); |
300 | // cut the length. filenames longer than that don't make sense | 269 | // cut the length. filenames longer than that don't make sense |
301 | // and something goes wrong when they get too long. | 270 | // and something goes wrong when they get too long. |
302 | if ( docname.length() > 40 ) | 271 | if ( docname.length() > 40 ) |
303 | docname = docname.left(40); | 272 | docname = docname.left(40); |
304 | if ( docname.isEmpty() ) | 273 | if ( docname.isEmpty() ) |
305 | docname = "Empty Text"; | 274 | docname = "Empty Text"; |
306 | // odebug << docname << oendl; | 275 | // odebug << docname << oendl; |
307 | 276 | ||
308 | if( oldDocName != docname) { | 277 | if( oldDocName != docname) { |
309 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 278 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
310 | QString entryName; | 279 | QString entryName; |
311 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 280 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
312 | cfg.writeEntry( entryName,docname ); | 281 | cfg.writeEntry( entryName,docname ); |
313 | cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); | 282 | cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); |
314 | cfg.write(); | 283 | cfg.write(); |
315 | } | 284 | } |
316 | // else | 285 | // else |
317 | // odebug << "oldname equals docname" << oendl; | 286 | // odebug << "oldname equals docname" << oendl; |
318 | 287 | ||
319 | doc = new DocLnk(docname); | 288 | doc = new DocLnk(docname); |
320 | if(QFile(doc->linkFile()).exists()) | 289 | if(QFile(doc->linkFile()).exists()) |
321 | odebug << "puppie" << oendl; | 290 | odebug << "puppie" << oendl; |
322 | doc->setType("text/plain"); | 291 | doc->setType("text/plain"); |
323 | doc->setName(docname); | 292 | doc->setName(docname); |
324 | QString temp = docname.replace( QRegExp(" "), "_" ); | 293 | QString temp = docname.replace( QRegExp(" "), "_" ); |
325 | doc->setFile( QDir::homeDirPath()+"/notes/"+temp); | 294 | doc->setFile( QDir::homeDirPath()+"/notes/"+temp); |
326 | FileManager fm; | 295 | FileManager fm; |
327 | if ( !fm.saveFile( *doc, rt ) ) { | 296 | if ( !fm.saveFile( *doc, rt ) ) { |
328 | } | 297 | } |
329 | 298 | ||
330 | oldDocName=docname; | 299 | oldDocName=docname; |
331 | edited=false; | 300 | edited=false; |
332 | // odebug << "save" << oendl; | 301 | // odebug << "save" << oendl; |
333 | if (doPopulate) | 302 | if (doPopulate) |
334 | populateBox(); | 303 | populateBox(); |
335 | } | 304 | } |
336 | cfg.writeEntry( "LastDoc",oldDocName ); | 305 | cfg.writeEntry( "LastDoc",oldDocName ); |
337 | cfg.write(); | 306 | cfg.write(); |
338 | 307 | ||
339 | } | 308 | } |
340 | } | 309 | } |
341 | 310 | ||
342 | void NotesControl::populateBox() { | 311 | void NotesControl::populateBox() { |
343 | box->clear(); | 312 | box->clear(); |
344 | // odebug << "populate" << oendl; | 313 | // odebug << "populate" << oendl; |
345 | Config cfg("Notes"); | 314 | Config cfg("Notes"); |
346 | cfg.setGroup("Docs"); | 315 | cfg.setGroup("Docs"); |
347 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 316 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
348 | QStringList list; | 317 | QStringList list; |
349 | QString entryName; | 318 | QString entryName; |
350 | for ( int i = 0; i < noOfFiles; i++ ) { | 319 | for ( int i = 0; i < noOfFiles; i++ ) { |
351 | entryName.sprintf( "File%i", i + 1 ); | 320 | entryName.sprintf( "File%i", i + 1 ); |
352 | list.append(cfg.readEntry( entryName )); | 321 | list.append(cfg.readEntry( entryName )); |
353 | } | 322 | } |
354 | list.sort(); | 323 | list.sort(); |
355 | box->insertStringList(list,-1); | 324 | box->insertStringList(list,-1); |
356 | doPopulate=false; | 325 | doPopulate=false; |
357 | update(); | 326 | update(); |
358 | } | 327 | } |
359 | 328 | ||
360 | void NotesControl::load() { | 329 | void NotesControl::load() { |
361 | 330 | ||
362 | if(!loaded) { | 331 | if(!loaded) { |
363 | Config cfg("Notes"); | 332 | Config cfg("Notes"); |
364 | cfg.setGroup("Docs"); | 333 | cfg.setGroup("Docs"); |
365 | QString lastDoc=cfg.readEntry( "LastDoc","notes"); | 334 | QString lastDoc=cfg.readEntry( "LastDoc","notes"); |
366 | DocLnk nf; | 335 | DocLnk nf; |
367 | nf.setType("text/plain"); | 336 | nf.setType("text/plain"); |
368 | nf.setFile(lastDoc); | 337 | nf.setFile(lastDoc); |
369 | 338 | ||
370 | loadDoc(nf); | 339 | loadDoc(nf); |
371 | loaded=true; | 340 | loaded=true; |
372 | oldDocName=lastDoc; | 341 | oldDocName=lastDoc; |
373 | cfg.writeEntry( "LastDoc",oldDocName ); | 342 | cfg.writeEntry( "LastDoc",oldDocName ); |
374 | cfg.write(); | 343 | cfg.write(); |
375 | } | 344 | } |
376 | } | 345 | } |
377 | 346 | ||
378 | void NotesControl::load(const QString & file) { | 347 | void NotesControl::load(const QString & file) { |
379 | odebug << "loading "+file << oendl; | 348 | odebug << "loading "+file << oendl; |
380 | QString name = file; | 349 | QString name = file; |
381 | QString temp; | 350 | QString temp; |
382 | if( !QFile( QDir::homeDirPath()+"/"+file).exists() ) | 351 | if( !QFile( QDir::homeDirPath()+"/"+file).exists() ) |
383 | temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" ); | 352 | temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" ); |
384 | else | 353 | else |
385 | temp = name; | 354 | temp = name; |
386 | if(!loaded) { | 355 | if(!loaded) { |
387 | DocLnk nf; | 356 | DocLnk nf; |
388 | nf.setType("text/plain"); | 357 | nf.setType("text/plain"); |
389 | nf.setFile( temp); | 358 | nf.setFile( temp); |
390 | if(!temp.isEmpty()) | 359 | if(!temp.isEmpty()) |
391 | loadDoc(nf); | 360 | loadDoc(nf); |
392 | loaded=true; | 361 | loaded=true; |
393 | } | 362 | } |
394 | // view->setFocus(); | 363 | // view->setFocus(); |
395 | oldDocName=file; | 364 | oldDocName=file; |
396 | Config cfg("Notes"); | 365 | Config cfg("Notes"); |
397 | cfg.setGroup("Docs"); | 366 | cfg.setGroup("Docs"); |
398 | cfg.writeEntry( "LastDoc",oldDocName ); | 367 | cfg.writeEntry( "LastDoc",oldDocName ); |
399 | cfg.write(); | 368 | cfg.write(); |
400 | } | 369 | } |
401 | 370 | ||
402 | void NotesControl::loadDoc( const DocLnk &f) { | 371 | void NotesControl::loadDoc( const DocLnk &f) { |
403 | FileManager fm; | 372 | FileManager fm; |
404 | QString txt; | 373 | QString txt; |
405 | if ( !fm.loadFile( f, txt ) ) { | 374 | if ( !fm.loadFile( f, txt ) ) { |
406 | odebug << "could not load file "+f.file() << oendl; | 375 | odebug << "could not load file "+f.file() << oendl; |
407 | return; | 376 | return; |
408 | } | 377 | } |
409 | view->setText(txt); | 378 | view->setText(txt); |
410 | } | 379 | } |
411 | 380 | ||
412 | void NotesControl::slotViewEdited() { | 381 | void NotesControl::slotViewEdited() { |
413 | if(loaded) { | 382 | if(loaded) { |
414 | edited=true; | 383 | edited=true; |
415 | } | 384 | } |
416 | } | 385 | } |
417 | 386 | ||
418 | 387 | ||
419 | void NotesControl::slotShowMax() { | 388 | void NotesControl::slotShowMax() { |
420 | Config cfg("Notes"); | 389 | Config cfg("Notes"); |
421 | cfg.setGroup("Options"); | 390 | cfg.setGroup("Options"); |
422 | showMax=!showMax; | 391 | showMax=!showMax; |
423 | cfg.writeEntry("ShowMax", showMax); | 392 | cfg.writeEntry("ShowMax", showMax); |
424 | cfg.write(); | 393 | cfg.write(); |
425 | hide(); | 394 | hide(); |
426 | } | 395 | } |
427 | 396 | ||
428 | void NotesControl::slotSearch() { | 397 | void NotesControl::slotSearch() { |
429 | int boxCount = box->count(); | 398 | int boxCount = box->count(); |
430 | for(int i=0;i< boxCount;i++) { | 399 | for(int i=0;i< boxCount;i++) { |
431 | 400 | ||
432 | } | 401 | } |
433 | } | 402 | } |
434 | 403 | ||
435 | // void NotesControl::keyReleaseEvent( QKeyEvent *e) { | 404 | // void NotesControl::keyReleaseEvent( QKeyEvent *e) { |
436 | 405 | ||
437 | // switch ( e->state() ) { | 406 | // switch ( e->state() ) { |
438 | // case ControlButton: | 407 | // case ControlButton: |
439 | // if(e->key() == Key_C) { //copy | 408 | // if(e->key() == Key_C) { //copy |
440 | // odebug << "copy" << oendl; | 409 | // odebug << "copy" << oendl; |
441 | // QClipboard *cb = QApplication::clipboard(); | 410 | // QClipboard *cb = QApplication::clipboard(); |
442 | // QString text; | 411 | // QString text; |
443 | 412 | ||
444 | // // Copy text from the clipboard (paste) | 413 | // // Copy text from the clipboard (paste) |
445 | // text = cb->text(); | 414 | // text = cb->text(); |
446 | // } | 415 | // } |
447 | // if(e->key() == Key_X) { //cut | 416 | // if(e->key() == Key_X) { //cut |
448 | // } | 417 | // } |
449 | // if(e->key() == Key_V) { //paste | 418 | // if(e->key() == Key_V) { //paste |
450 | // QClipboard *cb = QApplication::clipboard(); | 419 | // QClipboard *cb = QApplication::clipboard(); |
451 | // QString text; | 420 | // QString text; |
452 | // //view | 421 | // //view |
453 | // cb->setText(); | 422 | // cb->setText(); |
454 | // } | 423 | // } |
455 | // break; | 424 | // break; |
456 | // }; | 425 | // }; |
457 | // QWidget::keyReleaseEvent(e); | 426 | // QWidget::keyReleaseEvent(e); |
458 | // } | 427 | // } |
459 | 428 | ||
460 | //=========================================================================== | 429 | //=========================================================================== |
461 | 430 | ||
462 | NotesApplet::NotesApplet( QWidget *parent, const char *name ) | 431 | NotesApplet::NotesApplet( QWidget *parent, const char *name ) |
463 | : QWidget( parent, name ) { | 432 | : QWidget( parent, name ) { |
464 | setFixedHeight( 18 ); | 433 | setFixedHeight( AppLnk::smallIconSize() ); |
465 | setFixedWidth( 14 ); | 434 | setFixedWidth( AppLnk::smallIconSize() ); |
435 | notesPixmap.convertFromImage( Resource::loadImage( "edit" ).smoothScale( height(), width() ) ); | ||
466 | vc = new NotesControl; | 436 | vc = new NotesControl; |
467 | } | 437 | } |
468 | 438 | ||
469 | NotesApplet::~NotesApplet() { | 439 | NotesApplet::~NotesApplet() { |
470 | delete vc; | 440 | delete vc; |
471 | } | 441 | } |
472 | 442 | ||
473 | int NotesApplet::position() | 443 | int NotesApplet::position() |
474 | { | 444 | { |
475 | return 6; | 445 | return 6; |
476 | } | 446 | } |
477 | 447 | ||
478 | void NotesApplet::mousePressEvent( QMouseEvent *) { | 448 | void NotesApplet::mousePressEvent( QMouseEvent *) { |
479 | if( !vc->isHidden()) { | 449 | if( !vc->isHidden()) { |
480 | vc->doPopulate=false; | 450 | vc->doPopulate=false; |
481 | vc->save(); | 451 | vc->save(); |
482 | vc->close(); | 452 | vc->close(); |
483 | } else { | 453 | } else { |
484 | // vc = new NotesControl; | 454 | // vc = new NotesControl; |
485 | // QPoint curPos = mapToGlobal( rect().topLeft() ); | 455 | // QPoint curPos = mapToGlobal( rect().topLeft() ); |
486 | if(vc->showMax) { | 456 | if(vc->showMax) { |
487 | odebug << "show max" << oendl; | 457 | odebug << "show max" << oendl; |
488 | vc->showMaximized(); | 458 | vc->showMaximized(); |
489 | } else { | 459 | } else { |
490 | odebug << "no show max" << oendl; | 460 | odebug << "no show max" << oendl; |
491 | QWidget *wid = QPEApplication::desktop(); | 461 | QWidget *wid = QPEApplication::desktop(); |
492 | QRect rect = QApplication::desktop()->geometry(); | 462 | QRect rect = QApplication::desktop()->geometry(); |
493 | vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180); | 463 | vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180); |
494 | vc->move ( (rect.center()/2) - (vc->rect().center()/2)); | 464 | vc->move ( (rect.center()/2) - (vc->rect().center()/2)); |
495 | // vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28); | 465 | // vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28); |
496 | } | 466 | } |
497 | vc->show(); | 467 | vc->show(); |
498 | vc->doPopulate=true; | 468 | vc->doPopulate=true; |
499 | vc->populateBox(); | 469 | vc->populateBox(); |
500 | vc->doPopulate=false; | 470 | vc->doPopulate=false; |
501 | vc->loaded=false; | 471 | vc->loaded=false; |
502 | 472 | ||
503 | vc->load(); | 473 | vc->load(); |
504 | // this->setFocus(); | 474 | // this->setFocus(); |
505 | vc->view->setFocus(); | 475 | vc->view->setFocus(); |
506 | } | 476 | } |
507 | } | 477 | } |
508 | 478 | ||
509 | void NotesApplet::paintEvent( QPaintEvent* ) { | 479 | void NotesApplet::paintEvent( QPaintEvent* ) { |
510 | QPainter p(this); | 480 | QPainter p(this); |
511 | p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); | 481 | p.drawPixmap( 0, 2, notesPixmap ); |
512 | } | 482 | } |
513 | 483 | ||
514 | 484 | ||
515 | EXPORT_OPIE_APPLET_v1( NotesApplet ) | 485 | EXPORT_OPIE_APPLET_v1( NotesApplet ) |
516 | 486 | ||