Diffstat (limited to 'noncore/applets/notesapplet/notes.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/notesapplet/notes.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp index 1142028..9b5e475 100644 --- a/noncore/applets/notesapplet/notes.cpp +++ b/noncore/applets/notesapplet/notes.cpp | |||
@@ -34,288 +34,288 @@ | |||
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 <qfile.h> | 38 | #include <qfile.h> |
39 | #include <qpoint.h> | 39 | #include <qpoint.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qpainter.h> | 41 | #include <qpainter.h> |
42 | #include <qlayout.h> | 42 | #include <qlayout.h> |
43 | #include <qframe.h> | 43 | #include <qframe.h> |
44 | #include <qpixmap.h> | 44 | #include <qpixmap.h> |
45 | #include <qstring.h> | 45 | #include <qstring.h> |
46 | #include <qtimer.h> | 46 | #include <qtimer.h> |
47 | 47 | ||
48 | /* XPM */ | 48 | /* XPM */ |
49 | static char * notes_xpm[] = { | 49 | static char * notes_xpm[] = { |
50 | "16 16 11 1", | 50 | "16 16 11 1", |
51 | " c None", | 51 | " c None", |
52 | ". c #000000", | 52 | ". c #000000", |
53 | "+ c #7F7F7F", | 53 | "+ c #7F7F7F", |
54 | "@ c #BFBFBF", | 54 | "@ c #BFBFBF", |
55 | "# c #BFC1FF", | 55 | "# c #BFC1FF", |
56 | "$ c #FF0000", | 56 | "$ c #FF0000", |
57 | "% c #FFFFFF", | 57 | "% c #FFFFFF", |
58 | "& c #00037F", | 58 | "& c #00037F", |
59 | "* c #0006FF", | 59 | "* c #0006FF", |
60 | "= c #0005BF", | 60 | "= c #0005BF", |
61 | "- c #7F0000", | 61 | "- c #7F0000", |
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 | 79 | ||
80 | NotesControl::NotesControl( QWidget *, const char * ) | 80 | NotesControl::NotesControl( QWidget *, const char * ) |
81 | : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop ) | 81 | : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop ) |
82 | // : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) | 82 | // : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) |
83 | { | 83 | { |
84 | QDir d( QDir::homeDirPath()+"/notes"); | 84 | QDir d( QDir::homeDirPath()+"/notes"); |
85 | if( !d.exists()) { | 85 | if( !d.exists()) { |
86 | qDebug("make dir"); | 86 | qDebug("make dir"); |
87 | if(!d.mkdir( QDir::homeDirPath()+"/notes", true)) | 87 | if(!d.mkdir( QDir::homeDirPath()+"/notes", true)) |
88 | qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed"); | 88 | qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed"); |
89 | } | 89 | } |
90 | Config cfg("Notes"); | 90 | Config cfg("Notes"); |
91 | cfg.setGroup("Options"); | 91 | cfg.setGroup("Options"); |
92 | showMax = cfg.readBoolEntry("ShowMax", false); | 92 | showMax = cfg.readBoolEntry("ShowMax", false); |
93 | 93 | ||
94 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 94 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
95 | loaded=false; | 95 | loaded=false; |
96 | edited=false; | 96 | edited=false; |
97 | doPopulate=true; | 97 | doPopulate=true; |
98 | isNew=false; | 98 | isNew=false; |
99 | QVBox *vbox = new QVBox( this, "Vlayout" ); | 99 | QVBox *vbox = new QVBox( this, "Vlayout" ); |
100 | QHBox *hbox = new QHBox( this, "HLayout" ); | 100 | QHBox *hbox = new QHBox( this, "HLayout" ); |
101 | 101 | ||
102 | view = new QMultiLineEdit(vbox, "OpieNotesView"); | 102 | view = new QMultiLineEdit(vbox, "OpieNotesView"); |
103 | 103 | ||
104 | box = new QListBox(vbox, "OpieNotesBox"); | 104 | box = new QListBox(vbox, "OpieNotesBox"); |
105 | 105 | ||
106 | QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); | 106 | QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); |
107 | 107 | ||
108 | box->setFixedHeight(50); | 108 | box->setFixedHeight(50); |
109 | 109 | ||
110 | vbox->setMargin( 6 ); | 110 | vbox->setMargin( 6 ); |
111 | vbox->setSpacing( 3 ); | 111 | vbox->setSpacing( 3 ); |
112 | 112 | ||
113 | 113 | ||
114 | 114 | ||
115 | setFocusPolicy(QWidget::StrongFocus); | 115 | setFocusPolicy(QWidget::StrongFocus); |
116 | 116 | ||
117 | newButton= new QPushButton( hbox, "newButton" ); | 117 | newButton= new QPushButton( hbox, "newButton" ); |
118 | newButton->setText(tr("New")); | 118 | newButton->setText(tr("New")); |
119 | 119 | ||
120 | 120 | ||
121 | saveButton= new QPushButton( hbox, "saveButton" ); | 121 | saveButton= new QPushButton( hbox, "saveButton" ); |
122 | saveButton->setText(tr("Save")); | 122 | saveButton->setText(tr("Save")); |
123 | 123 | ||
124 | 124 | ||
125 | deleteButton= new QPushButton( hbox, "deleteButton" ); | 125 | deleteButton= new QPushButton( hbox, "deleteButton" ); |
126 | deleteButton->setText(tr("Delete")); | 126 | deleteButton->setText(tr("Delete")); |
127 | 127 | ||
128 | 128 | ||
129 | 129 | ||
130 | connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), | 130 | connect( box, SIGNAL( mouseButtonPressed(int,QListBoxItem*,const QPoint&)), |
131 | this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); | 131 | this,SLOT( boxPressed(int,QListBoxItem*,const QPoint&)) ); |
132 | 132 | ||
133 | connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); | 133 | connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString&))); |
134 | 134 | ||
135 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); | 135 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); |
136 | 136 | ||
137 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); | 137 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); |
138 | 138 | ||
139 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); | 139 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); |
140 | connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton())); | 140 | connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton())); |
141 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); | 141 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); |
142 | 142 | ||
143 | populateBox(); | 143 | populateBox(); |
144 | load(); | 144 | load(); |
145 | setCaption("Notes"); | 145 | setCaption("Notes"); |
146 | // parent->setFocus(); | 146 | // parent->setFocus(); |
147 | } | 147 | } |
148 | 148 | ||
149 | void NotesControl::slotSaveButton() { | 149 | void NotesControl::slotSaveButton() { |
150 | slotNewButton(); | 150 | slotNewButton(); |
151 | populateBox(); | 151 | populateBox(); |
152 | } | 152 | } |
153 | 153 | ||
154 | void NotesControl::slotDeleteButtonClicked() { | 154 | void NotesControl::slotDeleteButtonClicked() { |
155 | switch ( QMessageBox::warning(this,tr("Delete?") | 155 | switch ( QMessageBox::warning(this,tr("Delete?") |
156 | ,tr("Do you really want to<BR><B> delete</B> this note ?") | 156 | ,tr("Do you really want to<BR><B> delete</B> this note ?") |
157 | ,tr("Yes"),tr("No"),0,1,1) ) { | 157 | ,tr("Yes"),tr("No"),0,1,1) ) { |
158 | case 0: | 158 | case 0: |
159 | slotDeleteButton(); | 159 | slotDeleteButton(); |
160 | break; | 160 | break; |
161 | }; | 161 | }; |
162 | } | 162 | } |
163 | 163 | ||
164 | void NotesControl::slotDeleteButton() { | 164 | void NotesControl::slotDeleteButton() { |
165 | 165 | ||
166 | QString selectedText = box->currentText(); | 166 | QString selectedText = box->currentText(); |
167 | qDebug("deleting "+selectedText); | 167 | qDebug("deleting "+selectedText); |
168 | 168 | ||
169 | if( !selectedText.isEmpty()) { | 169 | if( !selectedText.isEmpty()) { |
170 | 170 | ||
171 | Config cfg("Notes"); | 171 | Config cfg("Notes"); |
172 | cfg.setGroup("Docs"); | 172 | cfg.setGroup("Docs"); |
173 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 173 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
174 | QString entryName, entryName2;; | 174 | QString entryName, entryName2;; |
175 | for ( int i = 0; i < noOfFiles; i++ ) { | 175 | for ( int i = 0; i < noOfFiles; i++ ) { |
176 | entryName.sprintf( "File%i", i + 1 ); | 176 | entryName.sprintf( "File%i", i + 1 ); |
177 | if(selectedText == cfg.readEntry( entryName )) { | 177 | if(selectedText == cfg.readEntry( entryName )) { |
178 | qDebug("removing %s, %d", selectedText.latin1(), i); | 178 | qDebug("removing %s, %d", selectedText.latin1(), i); |
179 | for ( int j = i; j < noOfFiles; j++ ) { | 179 | for ( int j = i; j < noOfFiles; j++ ) { |
180 | entryName.sprintf( "File%i", i + 1 ); | 180 | entryName.sprintf( "File%i", i + 1 ); |
181 | entryName2.sprintf( "File%i", i + 2 ); | 181 | entryName2.sprintf( "File%i", i + 2 ); |
182 | QString temp = cfg.readEntry(entryName2); | 182 | QString temp = cfg.readEntry(entryName2); |
183 | qDebug("move "+temp); | 183 | qDebug("move "+temp); |
184 | cfg.writeEntry(entryName, temp); | 184 | cfg.writeEntry(entryName, temp); |
185 | i++; | 185 | i++; |
186 | } | 186 | } |
187 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); | 187 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); |
188 | entryName.sprintf( "File%i", noOfFiles ); | 188 | entryName.sprintf( "File%i", noOfFiles ); |
189 | cfg.removeEntry(entryName); | 189 | cfg.removeEntry(entryName); |
190 | cfg.write(); | 190 | cfg.write(); |
191 | DocLnk nf(selectedText); | 191 | DocLnk nf(selectedText); |
192 | nf.removeFiles(); | 192 | nf.removeFiles(); |
193 | QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; | 193 | QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; |
194 | qDebug(fi); | 194 | qDebug(fi); |
195 | 195 | ||
196 | QFile f( fi); | 196 | QFile f( fi); |
197 | if( !f.remove()) qDebug(".desktop file not removed"); | 197 | if( !f.remove()) qDebug(".desktop file not removed"); |
198 | 198 | ||
199 | } | 199 | } |
200 | } | 200 | } |
201 | view->clear(); | 201 | view->clear(); |
202 | 202 | ||
203 | populateBox(); | 203 | populateBox(); |
204 | } | 204 | } |
205 | } | 205 | } |
206 | 206 | ||
207 | void NotesControl::slotNewButton() { | 207 | void NotesControl::slotNewButton() { |
208 | if(edited) save(); | 208 | if(edited) save(); |
209 | view->clear(); | 209 | view->clear(); |
210 | view->setFocus(); | 210 | view->setFocus(); |
211 | edited=false; | 211 | edited=false; |
212 | isNew=false; | 212 | isNew=false; |
213 | } | 213 | } |
214 | 214 | ||
215 | void NotesControl::slotBeamButton() { | 215 | void NotesControl::slotBeamButton() { |
216 | Ir ir; | 216 | Ir ir; |
217 | if(!ir.supported()){ | 217 | if(!ir.supported()){ |
218 | } else { | 218 | } else { |
219 | this->hide(); | 219 | this->hide(); |
220 | QString selectedText = box->currentText(); | 220 | QString selectedText = box->currentText(); |
221 | if( !selectedText.isEmpty()) { | 221 | if( !selectedText.isEmpty()) { |
222 | QString file = QDir::homeDirPath()+"/"+selectedText; | 222 | QString file = QDir::homeDirPath()+"/"+selectedText; |
223 | QFile f(file); | 223 | QFile f(file); |
224 | Ir *irFile = new Ir(this, "IR"); | 224 | Ir *irFile = new Ir(this, "IR"); |
225 | connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * ))); | 225 | connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished(Ir*))); |
226 | irFile->send( file, "Note", "text/plain" ); | 226 | irFile->send( file, "Note", "text/plain" ); |
227 | } | 227 | } |
228 | } | 228 | } |
229 | } | 229 | } |
230 | 230 | ||
231 | void NotesControl::slotBeamFinished(Ir *) { | 231 | void NotesControl::slotBeamFinished(Ir *) { |
232 | this->show(); | 232 | this->show(); |
233 | } | 233 | } |
234 | 234 | ||
235 | void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) { | 235 | void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) { |
236 | switch (mouse) { | 236 | switch (mouse) { |
237 | case 1:{ | 237 | case 1:{ |
238 | } | 238 | } |
239 | break; | 239 | break; |
240 | case 2: | 240 | case 2: |
241 | menuTimer.start( 500, TRUE ); | 241 | menuTimer.start( 500, TRUE ); |
242 | break; | 242 | break; |
243 | }; | 243 | }; |
244 | } | 244 | } |
245 | 245 | ||
246 | void NotesControl::slotBoxSelected(const QString &itemString) { | 246 | void NotesControl::slotBoxSelected(const QString &itemString) { |
247 | if(edited) { | 247 | if(edited) { |
248 | save(); | 248 | save(); |
249 | } | 249 | } |
250 | loaded=false; | 250 | loaded=false; |
251 | edited=false; | 251 | edited=false; |
252 | load(itemString); | 252 | load(itemString); |
253 | } | 253 | } |
254 | 254 | ||
255 | 255 | ||
256 | void NotesControl::showMenu() { | 256 | void NotesControl::showMenu() { |
257 | QPopupMenu *m = new QPopupMenu(0); | 257 | QPopupMenu *m = new QPopupMenu(0); |
258 | m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() )); | 258 | m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() )); |
259 | m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() )); | 259 | m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() )); |
260 | m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() )); | 260 | m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() )); |
261 | m->insertSeparator(); | 261 | m->insertSeparator(); |
262 | m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); | 262 | m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); |
263 | m->setFocus(); | 263 | m->setFocus(); |
264 | m->exec( QCursor::pos() ); | 264 | m->exec( QCursor::pos() ); |
265 | 265 | ||
266 | if(m) delete m; | 266 | if(m) delete m; |
267 | } | 267 | } |
268 | 268 | ||
269 | void NotesControl::focusOutEvent ( QFocusEvent * e) { | 269 | void NotesControl::focusOutEvent ( QFocusEvent * e) { |
270 | if( e->reason() == QFocusEvent::Popup) | 270 | if( e->reason() == QFocusEvent::Popup) |
271 | save(); | 271 | save(); |
272 | else { | 272 | else { |
273 | if(!loaded) { | 273 | if(!loaded) { |
274 | populateBox(); | 274 | populateBox(); |
275 | load(); | 275 | load(); |
276 | } | 276 | } |
277 | } | 277 | } |
278 | QWidget::focusOutEvent(e); | 278 | QWidget::focusOutEvent(e); |
279 | } | 279 | } |
280 | 280 | ||
281 | void NotesControl::save() { | 281 | void NotesControl::save() { |
282 | Config cfg("Notes"); | 282 | Config cfg("Notes"); |
283 | cfg.setGroup("Docs"); | 283 | cfg.setGroup("Docs"); |
284 | if( edited) { | 284 | if( edited) { |
285 | // qDebug("is edited"); | 285 | // qDebug("is edited"); |
286 | QString rt = view->text(); | 286 | QString rt = view->text(); |
287 | if( rt.length()>1) { | 287 | if( rt.length()>1) { |
288 | QString pt = rt.simplifyWhiteSpace(); | 288 | QString pt = rt.simplifyWhiteSpace(); |
289 | int i = pt.find( ' ', pt.find( ' ' )+2 ); | 289 | int i = pt.find( ' ', pt.find( ' ' )+2 ); |
290 | QString docname = pt; | 290 | QString docname = pt; |
291 | if ( i > 0 ) | 291 | if ( i > 0 ) |
292 | docname = pt.left(i); | 292 | docname = pt.left(i); |
293 | // remove "." at the beginning | 293 | // remove "." at the beginning |
294 | while( docname.startsWith( "." ) ) | 294 | while( docname.startsWith( "." ) ) |
295 | docname = docname.mid( 1 ); | 295 | docname = docname.mid( 1 ); |
296 | docname.replace( QRegExp("/"), "_" ); | 296 | docname.replace( QRegExp("/"), "_" ); |
297 | // cut the length. filenames longer than that don't make sense | 297 | // cut the length. filenames longer than that don't make sense |
298 | // and something goes wrong when they get too long. | 298 | // and something goes wrong when they get too long. |
299 | if ( docname.length() > 40 ) | 299 | if ( docname.length() > 40 ) |
300 | docname = docname.left(40); | 300 | docname = docname.left(40); |
301 | if ( docname.isEmpty() ) | 301 | if ( docname.isEmpty() ) |
302 | docname = "Empty Text"; | 302 | docname = "Empty Text"; |
303 | // qDebug(docname); | 303 | // qDebug(docname); |
304 | 304 | ||
305 | if( oldDocName != docname) { | 305 | if( oldDocName != docname) { |
306 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 306 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
307 | QString entryName; | 307 | QString entryName; |
308 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 308 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
309 | cfg.writeEntry( entryName,docname ); | 309 | cfg.writeEntry( entryName,docname ); |
310 | cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); | 310 | cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); |
311 | cfg.write(); | 311 | cfg.write(); |
312 | } | 312 | } |
313 | // else | 313 | // else |
314 | // qDebug("oldname equals docname"); | 314 | // qDebug("oldname equals docname"); |
315 | 315 | ||
316 | doc = new DocLnk(docname); | 316 | doc = new DocLnk(docname); |
317 | if(QFile(doc->linkFile()).exists()) | 317 | if(QFile(doc->linkFile()).exists()) |
318 | qDebug("puppie"); | 318 | qDebug("puppie"); |
319 | doc->setType("text/plain"); | 319 | doc->setType("text/plain"); |
320 | doc->setName(docname); | 320 | doc->setName(docname); |
321 | QString temp = docname.replace( QRegExp(" "), "_" ); | 321 | QString temp = docname.replace( QRegExp(" "), "_" ); |