summaryrefslogtreecommitdiff
path: root/noncore/applets/notesapplet
authorllornkcor <llornkcor>2002-09-22 00:36:02 (UTC)
committer llornkcor <llornkcor>2002-09-22 00:36:02 (UTC)
commitaf1e2665f9d7b6ad8b10142e6a432fd1e6aa0c9d (patch) (unidiff)
tree1c1f388a8b2ae4f81fc60469688e851d4509312b /noncore/applets/notesapplet
parentd60625b5551f26cdc35f7b2497ab538de859537d (diff)
downloadopie-af1e2665f9d7b6ad8b10142e6a432fd1e6aa0c9d.zip
opie-af1e2665f9d7b6ad8b10142e6a432fd1e6aa0c9d.tar.gz
opie-af1e2665f9d7b6ad8b10142e6a432fd1e6aa0c9d.tar.bz2
opienotes
Diffstat (limited to 'noncore/applets/notesapplet') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/notesapplet/.cvsignore5
-rw-r--r--noncore/applets/notesapplet/notes.cpp363
-rw-r--r--noncore/applets/notesapplet/notes.h85
-rw-r--r--noncore/applets/notesapplet/notesapplet.pro12
-rw-r--r--noncore/applets/notesapplet/notesappletimpl.cpp50
-rw-r--r--noncore/applets/notesapplet/notesappletimpl.h36
-rw-r--r--noncore/applets/notesapplet/opie-notesapplet.control9
7 files changed, 560 insertions, 0 deletions
diff --git a/noncore/applets/notesapplet/.cvsignore b/noncore/applets/notesapplet/.cvsignore
new file mode 100644
index 0000000..7c4a217
--- a/dev/null
+++ b/noncore/applets/notesapplet/.cvsignore
@@ -0,0 +1,5 @@
1moc_*
2*.moc
3Makefile*
4*.~
5opieobj \ No newline at end of file
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
new file mode 100644
index 0000000..64731e3
--- a/dev/null
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -0,0 +1,363 @@
1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org>
3
4** All rights reserved.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14**********************************************************************/
15
16#include "notes.h"
17
18#include <qapplication.h>
19#include <stdlib.h>
20#include <qstringlist.h>
21
22#include <qpe/filemanager.h>
23#include <qpe/resource.h>
24#include <qpe/qpeapplication.h>
25#include <qpe/timestring.h>
26#include <qpe/resource.h>
27#include <qpe/config.h>
28#include <qpe/applnk.h>
29#include <qpe/config.h>
30#include <qsocket.h>
31
32#include <qmultilineedit.h>
33#include <qlistbox.h>
34#include <qpopupmenu.h>
35#include <qmessagebox.h>
36
37#include <qdir.h>
38#include <qpoint.h>
39#include <qpushbutton.h>
40#include <qpainter.h>
41#include <qlayout.h>
42#include <qframe.h>
43#include <qpixmap.h>
44#include <qstring.h>
45#include <qtimer.h>
46
47/* XPM */
48static char * notes_xpm[] = {
49"16 16 11 1",
50" c None",
51". c #000000",
52"+ c #7F7F7F",
53"@ c #BFBFBF",
54"# c #BFC1FF",
55"$ c #FF0000",
56"% c #FFFFFF",
57"& c #00037F",
58"* c #0006FF",
59"= c #0005BF",
60"- c #7F0000",
61" .. ",
62" .. ",
63" ... ",
64" .+ ",
65" .@. ",
66" . .+ ",
67" ..#.@. ",
68" ..###.+.. ",
69" ..###$...##.. ",
70"..###$$$%+$$##&.",
71".*=####$-###&=&.",
72".=**=###==&=&=..",
73" ..=**=#&=&=.. ",
74" ..=*=&=.. ",
75" ..=.. ",
76" . "};
77
78
79NotesControl::NotesControl( QWidget *parent, const char *name )
80 : QFrame( parent, name,/* WDestructiveClose | */WStyle_StaysOnTop )
81// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
82{
83 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
84 loaded=false;
85 edited=false;
86 doPopulate=true;
87 QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" );
88 QHBoxLayout *hbox = new QHBoxLayout( this );
89
90 view = new QMultiLineEdit(this, "OpieNotesView");
91
92 box = new QListBox(this, "OpieNotesBox");
93 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold);
94 box->setFixedHeight(50);
95
96 vbox->setMargin( 6 );
97 vbox->setSpacing( 3 );
98
99 vbox->addWidget( view);
100 vbox->addWidget( box);
101
102 setFixedHeight(180);
103 QWidget *wid = QPEApplication::desktop();
104 setFixedWidth( wid->width()-10 /*200*/);
105
106 setFocusPolicy(QWidget::StrongFocus);
107
108 newButton= new QPushButton( this, "newButton" );
109 newButton->setText(tr("New"));
110 hbox->addWidget( newButton);
111 vbox->addItem(hbox);
112
113 connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)),
114 this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) );
115 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &)));
116 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) );
117
118 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) );
119 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton()));
120 populateBox();
121 load();
122 setCaption("Notes");
123 // parent->setFocus();
124}
125
126void NotesControl::slotDeleteButton() {
127 QString selectedText = box->currentText();
128 qDebug("deleting "+selectedText);
129 Config cfg("Notes");
130 cfg.setGroup("Docs");
131 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
132 QString entryName, entryName2;;
133 for ( int i = 0; i < noOfFiles; i++ ) {
134 entryName.sprintf( "File%i", i + 1 );
135 if(selectedText == cfg.readEntry( entryName )) {
136 qDebug("removing %s, %d", selectedText.latin1(), i);
137 for ( int j = i; j < noOfFiles; j++ ) {
138 entryName.sprintf( "File%i", i + 1 );
139 entryName2.sprintf( "File%i", i + 2 );
140 QString temp = cfg.readEntry(entryName2);
141 qDebug("move "+temp);
142 cfg.writeEntry(entryName, temp);
143 i++;
144 }
145 cfg.writeEntry("NumberOfFiles", noOfFiles-1 );
146 entryName.sprintf( "File%i", noOfFiles );
147 cfg.removeEntry(entryName);
148 cfg.write();
149 DocLnk nf(selectedText);
150 nf.removeFiles();
151 }
152 }
153 populateBox();
154}
155
156void NotesControl::slotNewButton() {
157 if(edited) save();
158 view->clear();
159 view->setFocus();
160}
161
162void NotesControl::boxPressed(int mouse, QListBoxItem *item, const QPoint&) {
163 switch (mouse) {
164 case 1:{
165 }
166 break;
167 case 2:
168 menuTimer.start( 500, TRUE );
169 break;
170 };
171}
172
173void NotesControl::slotBoxSelected(const QString &itemString) {
174 if(edited) {
175 save();
176 }
177 loaded=false;
178 edited=false;
179 load(itemString);
180}
181
182
183void NotesControl::showMenu() {
184 QPopupMenu *m = new QPopupMenu(0);
185
186 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() ));
187
188 m->setFocus();
189 m->exec( QCursor::pos() );
190
191 if(m) delete m;
192
193}
194
195void NotesControl::focusOutEvent ( QFocusEvent * e) {
196 if( e->reason() == QFocusEvent::Popup)
197 save();
198 else {
199 if(!loaded) {
200 populateBox();
201 load();
202 }
203 }
204 QWidget::focusOutEvent(e);
205}
206
207void NotesControl::save() {
208 Config cfg("Notes");
209 cfg.setGroup("Docs");
210 if( edited) {
211 QString rt = view->text();
212 if(!rt.isEmpty()) {
213 QString pt = rt.simplifyWhiteSpace();
214 int i = pt.find( ' ' );
215 QString docname = pt;
216 if ( i > 0 )
217 docname = pt.left( i );
218 // remove "." at the beginning
219 while( docname.startsWith( "." ) )
220 docname = docname.mid( 1 );
221 docname.replace( QRegExp("/"), "_" );
222 // cut the length. filenames longer than that don't make sense
223 // and something goes wrong when they get too long.
224 if ( docname.length() > 40 )
225 docname = docname.left(40);
226 if ( docname.isEmpty() )
227 docname = "Empty Text";
228 qDebug(docname);
229
230 if( oldDocName != docname) {
231 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
232 QString entryName;
233 entryName.sprintf( "File%i", noOfFiles + 1 );
234 cfg.writeEntry( entryName,docname );
235 cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
236 cfg.write();
237 }
238 doc = new DocLnk(docname);
239
240 doc->setType("text/plain");
241 doc->setFile(docname);
242 doc->setName(docname);
243
244 FileManager fm;
245 if ( !fm.saveFile( *doc, rt ) ) {
246 }
247
248 oldDocName=docname;
249 edited=false;
250 }
251 qDebug("save");
252 if (doPopulate)
253 populateBox();
254 }
255 cfg.writeEntry( "LastDoc",oldDocName );
256 cfg.write();
257}
258
259void NotesControl::populateBox() {
260 box->clear();
261 qDebug("populate");
262 Config cfg("Notes");
263 cfg.setGroup("Docs");
264 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
265 QStringList list;
266 QString entryName;
267 for ( int i = 0; i < noOfFiles; i++ ) {
268 entryName.sprintf( "File%i", i + 1 );
269 list.append(cfg.readEntry( entryName ));
270 }
271 list.sort();
272 box->insertStringList(list,-1);
273
274}
275
276void NotesControl::load() {
277
278 Config cfg("Notes");
279 cfg.setGroup("Docs");
280 if(!loaded) {
281 QString lastDoc=cfg.readEntry( "LastDoc","");
282 DocLnk nf;
283 nf.setType("text/plain");
284 nf.setFile(lastDoc);
285
286 loadDoc(nf);
287 loaded=true;
288 oldDocName=lastDoc;
289 }
290 cfg.writeEntry( "LastDoc",oldDocName );
291 cfg.write();
292}
293
294void NotesControl::load(const QString & file) {
295 qDebug("loading "+file);
296 if(!loaded) {
297 DocLnk nf;
298 nf.setType("text/plain");
299 nf.setFile( file);
300
301 loadDoc(nf);
302 loaded=true;
303 }
304// view->setFocus();
305 oldDocName=file;
306 Config cfg("Notes");
307 cfg.setGroup("Docs");
308 cfg.writeEntry( "LastDoc",oldDocName );
309 cfg.write();
310}
311
312void NotesControl::loadDoc( const DocLnk &f) {
313 FileManager fm;
314 QString txt;
315 if ( !fm.loadFile( f, txt ) ) {
316 return;
317 }
318 view->setText(txt);
319}
320
321void NotesControl::slotViewEdited() {
322 if(loaded) {
323 edited=true;
324 }
325}
326
327//===========================================================================
328
329NotesApplet::NotesApplet( QWidget *parent, const char *name )
330 : QWidget( parent, name ) {
331 setFixedHeight( 18 );
332 setFixedWidth( 14 );
333 vc = new NotesControl;
334}
335
336NotesApplet::~NotesApplet() {
337}
338
339void NotesApplet::mousePressEvent( QMouseEvent *) {
340 if( !vc->isHidden()) {
341 vc->doPopulate=false;
342 vc->save();
343 vc->close();
344 } else {
345// vc = new NotesControl;
346// QPoint curPos = mapToGlobal( rect().topLeft() );
347 vc->show();
348 vc->move( 5, 18);
349 vc->doPopulate=true;
350 vc->populateBox();
351 vc->load();
352
353
354 this->setFocus();
355 vc->view->setFocus();
356 }
357}
358
359void NotesApplet::paintEvent( QPaintEvent* ) {
360 QPainter p(this);
361 p.drawPixmap( 0, 1, ( const char** ) notes_xpm );
362}
363
diff --git a/noncore/applets/notesapplet/notes.h b/noncore/applets/notesapplet/notes.h
new file mode 100644
index 0000000..2172d5a
--- a/dev/null
+++ b/noncore/applets/notesapplet/notes.h
@@ -0,0 +1,85 @@
1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com
3** All rights reserved.
4**
5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file.
9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12**
13**********************************************************************/
14
15#ifndef __NOTES_APPLET_H__
16#define __NOTES_APPLET_H__
17
18#include <qwidget.h>
19#include <qframe.h>
20#include <qpixmap.h>
21#include <qguardedptr.h>
22#include <qtimer.h>
23#include <qpe/filemanager.h>
24#include <qstring.h>
25
26class QComboBox;
27class QCheckBox;
28class QSpinBox;
29class QPushButton;
30class QMultiLineEdit;
31class QListBox;
32class QListBoxItem;
33class NotesControl : public QFrame {
34 Q_OBJECT
35public:
36 NotesControl( QWidget *parent=0, const char *name=0 );
37 void performGrab();
38
39 QPixmap notes;
40 QMultiLineEdit *view;
41 QListBox *box;
42 QPushButton *saveButton, *deleteButton, *newButton;
43 QString FileNamePath;
44 bool doPopulate;
45 void save();
46 void populateBox();
47 void load();
48
49private:
50 QTimer menuTimer;
51 DocLnk *doc;
52 bool loaded, edited;
53 QString oldDocName;
54 void focusOutEvent( QFocusEvent * );
55 void load(const QString&);
56private slots:
57 void slotDeleteButton();
58 void slotNewButton();
59 void boxPressed(int, QListBoxItem *, const QPoint&);
60 void showMenu();
61 void loadDoc( const DocLnk &);
62 void slotViewEdited();
63 void slotBoxSelected(const QString &);
64};
65
66class NotesApplet : public QWidget {
67 Q_OBJECT
68public:
69 NotesApplet( QWidget *parent = 0, const char *name=0 );
70 ~NotesApplet();
71 NotesControl *vc;
72public slots:
73private:
74 void mousePressEvent( QMouseEvent * );
75 void paintEvent( QPaintEvent* );
76
77private:
78 QPixmap notesPixmap;
79private slots:
80
81
82};
83
84#endif // __NOTES_APPLET_H__
85
diff --git a/noncore/applets/notesapplet/notesapplet.pro b/noncore/applets/notesapplet/notesapplet.pro
new file mode 100644
index 0000000..4454e97
--- a/dev/null
+++ b/noncore/applets/notesapplet/notesapplet.pro
@@ -0,0 +1,12 @@
1TEMPLATE = lib
2CONFIG += qt warn_on release
3HEADERS = notes.h notesappletimpl.h
4SOURCES = notes.cpp notesappletimpl.cpp
5TARGET = notesapplet
6DESTDIR = $(OPIEDIR)/plugins/applets
7INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += $(OPIEDIR)/include
9LIBS += -lqpe
10VERSION = 1.0.0
11MOC_DIR=opieobj
12OBJECTS_DIR=opieobj
diff --git a/noncore/applets/notesapplet/notesappletimpl.cpp b/noncore/applets/notesapplet/notesappletimpl.cpp
new file mode 100644
index 0000000..93e1e97
--- a/dev/null
+++ b/noncore/applets/notesapplet/notesappletimpl.cpp
@@ -0,0 +1,50 @@
1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org>
3**
4**
5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file.
9**
10**
11**********************************************************************/
12#include "notes.h"
13#include "notesappletimpl.h"
14
15
16NotesAppletImpl::NotesAppletImpl()
17 : notes(0), ref(0) {
18}
19
20NotesAppletImpl::~NotesAppletImpl() {
21 delete notes;
22}
23
24QWidget *NotesAppletImpl::applet( QWidget *parent ) {
25 if ( !notes )
26 notes = new NotesApplet( parent );
27 return notes;
28}
29
30int NotesAppletImpl::position() const {
31 return 6;
32}
33
34QRESULT NotesAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
35 *iface = 0;
36 if ( uuid == IID_QUnknown )
37 *iface = this;
38 else if ( uuid == IID_TaskbarApplet )
39 *iface = this;
40
41 if ( *iface )
42 (*iface)->addRef();
43 return QS_OK;
44}
45
46Q_EXPORT_INTERFACE() {
47 Q_CREATE_INSTANCE( NotesAppletImpl )
48}
49
50
diff --git a/noncore/applets/notesapplet/notesappletimpl.h b/noncore/applets/notesapplet/notesappletimpl.h
new file mode 100644
index 0000000..add9865
--- a/dev/null
+++ b/noncore/applets/notesapplet/notesappletimpl.h
@@ -0,0 +1,36 @@
1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org>
3**
4**
5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file.
9**
10**
11**********************************************************************/
12#ifndef NOTESAPPLETIMPL_H
13#define NOTESAPPLETIMPL_H
14
15#include <qpe/taskbarappletinterface.h>
16
17class NotesApplet;
18
19class NotesAppletImpl : public TaskbarAppletInterface
20{
21public:
22 NotesAppletImpl();
23 virtual ~NotesAppletImpl();
24
25 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
26 Q_REFCOUNT
27
28 virtual QWidget *applet( QWidget *parent );
29 virtual int position() const;
30
31private:
32 NotesApplet *notes;
33 ulong ref;
34};
35
36#endif
diff --git a/noncore/applets/notesapplet/opie-notesapplet.control b/noncore/applets/notesapplet/opie-notesapplet.control
new file mode 100644
index 0000000..4864d7f
--- a/dev/null
+++ b/noncore/applets/notesapplet/opie-notesapplet.control
@@ -0,0 +1,9 @@
1Files: plugins/applets/libnotesapplet.so*
2Priority: optional
3Section: opie/system
4Maintainer: L. J. Potter <ljp@llornkcor.com>
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION.1
7Depends: opie-base ($QPE_VERSION)
8Description: Screenshot Applet
9 A simple taskbar applet for making quick notes.