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