author | llornkcor <llornkcor> | 2002-09-22 00:36:02 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-09-22 00:36:02 (UTC) |
commit | af1e2665f9d7b6ad8b10142e6a432fd1e6aa0c9d (patch) (side-by-side diff) | |
tree | 1c1f388a8b2ae4f81fc60469688e851d4509312b | |
parent | d60625b5551f26cdc35f7b2497ab538de859537d (diff) | |
download | opie-af1e2665f9d7b6ad8b10142e6a432fd1e6aa0c9d.zip opie-af1e2665f9d7b6ad8b10142e6a432fd1e6aa0c9d.tar.gz opie-af1e2665f9d7b6ad8b10142e6a432fd1e6aa0c9d.tar.bz2 |
opienotes
-rw-r--r-- | noncore/applets/notesapplet/.cvsignore | 5 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notes.cpp | 363 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notes.h | 85 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notesapplet.pro | 12 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notesappletimpl.cpp | 50 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notesappletimpl.h | 36 | ||||
-rw-r--r-- | noncore/applets/notesapplet/opie-notesapplet.control | 9 |
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 @@ +moc_* +*.moc +Makefile* +*.~ +opieobj
\ 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 @@ +/********************************************************************** +** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org> + +** All rights reserved. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#include "notes.h" + +#include <qapplication.h> +#include <stdlib.h> +#include <qstringlist.h> + +#include <qpe/filemanager.h> +#include <qpe/resource.h> +#include <qpe/qpeapplication.h> +#include <qpe/timestring.h> +#include <qpe/resource.h> +#include <qpe/config.h> +#include <qpe/applnk.h> +#include <qpe/config.h> +#include <qsocket.h> + +#include <qmultilineedit.h> +#include <qlistbox.h> +#include <qpopupmenu.h> +#include <qmessagebox.h> + +#include <qdir.h> +#include <qpoint.h> +#include <qpushbutton.h> +#include <qpainter.h> +#include <qlayout.h> +#include <qframe.h> +#include <qpixmap.h> +#include <qstring.h> +#include <qtimer.h> + +/* XPM */ +static char * notes_xpm[] = { +"16 16 11 1", +" c None", +". c #000000", +"+ c #7F7F7F", +"@ c #BFBFBF", +"# c #BFC1FF", +"$ c #FF0000", +"% c #FFFFFF", +"& c #00037F", +"* c #0006FF", +"= c #0005BF", +"- c #7F0000", +" .. ", +" .. ", +" ... ", +" .+ ", +" .@. ", +" . .+ ", +" ..#.@. ", +" ..###.+.. ", +" ..###$...##.. ", +"..###$$$%+$$##&.", +".*=####$-###&=&.", +".=**=###==&=&=..", +" ..=**=#&=&=.. ", +" ..=*=&=.. ", +" ..=.. ", +" . "}; + + +NotesControl::NotesControl( QWidget *parent, const char *name ) + : QFrame( parent, name,/* WDestructiveClose | */WStyle_StaysOnTop ) +// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) +{ + setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); + loaded=false; + edited=false; + doPopulate=true; + QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" ); + QHBoxLayout *hbox = new QHBoxLayout( this ); + + view = new QMultiLineEdit(this, "OpieNotesView"); + + box = new QListBox(this, "OpieNotesBox"); + QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); + box->setFixedHeight(50); + + vbox->setMargin( 6 ); + vbox->setSpacing( 3 ); + + vbox->addWidget( view); + vbox->addWidget( box); + + setFixedHeight(180); + QWidget *wid = QPEApplication::desktop(); + setFixedWidth( wid->width()-10 /*200*/); + + setFocusPolicy(QWidget::StrongFocus); + + newButton= new QPushButton( this, "newButton" ); + newButton->setText(tr("New")); + hbox->addWidget( newButton); + vbox->addItem(hbox); + + connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), + this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); + connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); + connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); + + connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); + connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); + populateBox(); + load(); + setCaption("Notes"); + // parent->setFocus(); +} + +void NotesControl::slotDeleteButton() { + QString selectedText = box->currentText(); + qDebug("deleting "+selectedText); + Config cfg("Notes"); + cfg.setGroup("Docs"); + int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); + QString entryName, entryName2;; + for ( int i = 0; i < noOfFiles; i++ ) { + entryName.sprintf( "File%i", i + 1 ); + if(selectedText == cfg.readEntry( entryName )) { + qDebug("removing %s, %d", selectedText.latin1(), i); + for ( int j = i; j < noOfFiles; j++ ) { + entryName.sprintf( "File%i", i + 1 ); + entryName2.sprintf( "File%i", i + 2 ); + QString temp = cfg.readEntry(entryName2); + qDebug("move "+temp); + cfg.writeEntry(entryName, temp); + i++; + } + cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); + entryName.sprintf( "File%i", noOfFiles ); + cfg.removeEntry(entryName); + cfg.write(); + DocLnk nf(selectedText); + nf.removeFiles(); + } + } + populateBox(); +} + +void NotesControl::slotNewButton() { + if(edited) save(); + view->clear(); + view->setFocus(); +} + +void NotesControl::boxPressed(int mouse, QListBoxItem *item, const QPoint&) { + switch (mouse) { + case 1:{ + } + break; + case 2: + menuTimer.start( 500, TRUE ); + break; + }; +} + +void NotesControl::slotBoxSelected(const QString &itemString) { + if(edited) { + save(); + } + loaded=false; + edited=false; + load(itemString); +} + + +void NotesControl::showMenu() { + QPopupMenu *m = new QPopupMenu(0); + + m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); + + m->setFocus(); + m->exec( QCursor::pos() ); + + if(m) delete m; + +} + +void NotesControl::focusOutEvent ( QFocusEvent * e) { + if( e->reason() == QFocusEvent::Popup) + save(); + else { + if(!loaded) { + populateBox(); + load(); + } + } + QWidget::focusOutEvent(e); +} + +void NotesControl::save() { + Config cfg("Notes"); + cfg.setGroup("Docs"); + if( edited) { + QString rt = view->text(); + if(!rt.isEmpty()) { + QString pt = rt.simplifyWhiteSpace(); + int i = pt.find( ' ' ); + QString docname = pt; + if ( i > 0 ) + docname = pt.left( i ); + // remove "." at the beginning + while( docname.startsWith( "." ) ) + docname = docname.mid( 1 ); + docname.replace( QRegExp("/"), "_" ); + // cut the length. filenames longer than that don't make sense + // and something goes wrong when they get too long. + if ( docname.length() > 40 ) + docname = docname.left(40); + if ( docname.isEmpty() ) + docname = "Empty Text"; + qDebug(docname); + + if( oldDocName != docname) { + int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); + QString entryName; + entryName.sprintf( "File%i", noOfFiles + 1 ); + cfg.writeEntry( entryName,docname ); + cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); + cfg.write(); + } + doc = new DocLnk(docname); + + doc->setType("text/plain"); + doc->setFile(docname); + doc->setName(docname); + + FileManager fm; + if ( !fm.saveFile( *doc, rt ) ) { + } + + oldDocName=docname; + edited=false; + } + qDebug("save"); + if (doPopulate) + populateBox(); + } + cfg.writeEntry( "LastDoc",oldDocName ); + cfg.write(); +} + +void NotesControl::populateBox() { + box->clear(); + qDebug("populate"); + Config cfg("Notes"); + cfg.setGroup("Docs"); + int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); + QStringList list; + QString entryName; + for ( int i = 0; i < noOfFiles; i++ ) { + entryName.sprintf( "File%i", i + 1 ); + list.append(cfg.readEntry( entryName )); + } + list.sort(); + box->insertStringList(list,-1); + +} + +void NotesControl::load() { + + Config cfg("Notes"); + cfg.setGroup("Docs"); + if(!loaded) { + QString lastDoc=cfg.readEntry( "LastDoc",""); + DocLnk nf; + nf.setType("text/plain"); + nf.setFile(lastDoc); + + loadDoc(nf); + loaded=true; + oldDocName=lastDoc; + } + cfg.writeEntry( "LastDoc",oldDocName ); + cfg.write(); +} + +void NotesControl::load(const QString & file) { + qDebug("loading "+file); + if(!loaded) { + DocLnk nf; + nf.setType("text/plain"); + nf.setFile( file); + + loadDoc(nf); + loaded=true; + } +// view->setFocus(); + oldDocName=file; + Config cfg("Notes"); + cfg.setGroup("Docs"); + cfg.writeEntry( "LastDoc",oldDocName ); + cfg.write(); +} + +void NotesControl::loadDoc( const DocLnk &f) { + FileManager fm; + QString txt; + if ( !fm.loadFile( f, txt ) ) { + return; + } + view->setText(txt); +} + +void NotesControl::slotViewEdited() { + if(loaded) { + edited=true; + } +} + +//=========================================================================== + +NotesApplet::NotesApplet( QWidget *parent, const char *name ) + : QWidget( parent, name ) { + setFixedHeight( 18 ); + setFixedWidth( 14 ); + vc = new NotesControl; +} + +NotesApplet::~NotesApplet() { +} + +void NotesApplet::mousePressEvent( QMouseEvent *) { + if( !vc->isHidden()) { + vc->doPopulate=false; + vc->save(); + vc->close(); + } else { +// vc = new NotesControl; +// QPoint curPos = mapToGlobal( rect().topLeft() ); + vc->show(); + vc->move( 5, 18); + vc->doPopulate=true; + vc->populateBox(); + vc->load(); + + + this->setFocus(); + vc->view->setFocus(); + } +} + +void NotesApplet::paintEvent( QPaintEvent* ) { + QPainter p(this); + p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); +} + 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 @@ +/********************************************************************** +** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com +** All rights reserved. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#ifndef __NOTES_APPLET_H__ +#define __NOTES_APPLET_H__ + +#include <qwidget.h> +#include <qframe.h> +#include <qpixmap.h> +#include <qguardedptr.h> +#include <qtimer.h> +#include <qpe/filemanager.h> +#include <qstring.h> + +class QComboBox; +class QCheckBox; +class QSpinBox; +class QPushButton; +class QMultiLineEdit; +class QListBox; +class QListBoxItem; +class NotesControl : public QFrame { + Q_OBJECT +public: + NotesControl( QWidget *parent=0, const char *name=0 ); + void performGrab(); + + QPixmap notes; + QMultiLineEdit *view; + QListBox *box; + QPushButton *saveButton, *deleteButton, *newButton; + QString FileNamePath; + bool doPopulate; + void save(); + void populateBox(); + void load(); + +private: + QTimer menuTimer; + DocLnk *doc; + bool loaded, edited; + QString oldDocName; + void focusOutEvent( QFocusEvent * ); + void load(const QString&); +private slots: + void slotDeleteButton(); + void slotNewButton(); + void boxPressed(int, QListBoxItem *, const QPoint&); + void showMenu(); + void loadDoc( const DocLnk &); + void slotViewEdited(); + void slotBoxSelected(const QString &); +}; + +class NotesApplet : public QWidget { + Q_OBJECT +public: + NotesApplet( QWidget *parent = 0, const char *name=0 ); + ~NotesApplet(); + NotesControl *vc; +public slots: +private: + void mousePressEvent( QMouseEvent * ); + void paintEvent( QPaintEvent* ); + +private: + QPixmap notesPixmap; +private slots: + + +}; + +#endif // __NOTES_APPLET_H__ + 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 @@ +TEMPLATE = lib +CONFIG += qt warn_on release +HEADERS = notes.h notesappletimpl.h +SOURCES = notes.cpp notesappletimpl.cpp +TARGET = notesapplet +DESTDIR = $(OPIEDIR)/plugins/applets +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include +LIBS += -lqpe +VERSION = 1.0.0 +MOC_DIR=opieobj +OBJECTS_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 @@ +/********************************************************************** +** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org> +** +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** +**********************************************************************/ +#include "notes.h" +#include "notesappletimpl.h" + + +NotesAppletImpl::NotesAppletImpl() + : notes(0), ref(0) { +} + +NotesAppletImpl::~NotesAppletImpl() { + delete notes; +} + +QWidget *NotesAppletImpl::applet( QWidget *parent ) { + if ( !notes ) + notes = new NotesApplet( parent ); + return notes; +} + +int NotesAppletImpl::position() const { + return 6; +} + +QRESULT NotesAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = this; + else if ( uuid == IID_TaskbarApplet ) + *iface = this; + + if ( *iface ) + (*iface)->addRef(); + return QS_OK; +} + +Q_EXPORT_INTERFACE() { + Q_CREATE_INSTANCE( NotesAppletImpl ) +} + + 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 @@ +/********************************************************************** +** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org> +** +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** +**********************************************************************/ +#ifndef NOTESAPPLETIMPL_H +#define NOTESAPPLETIMPL_H + +#include <qpe/taskbarappletinterface.h> + +class NotesApplet; + +class NotesAppletImpl : public TaskbarAppletInterface +{ +public: + NotesAppletImpl(); + virtual ~NotesAppletImpl(); + + QRESULT queryInterface( const QUuid&, QUnknownInterface** ); + Q_REFCOUNT + + virtual QWidget *applet( QWidget *parent ); + virtual int position() const; + +private: + NotesApplet *notes; + ulong ref; +}; + +#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 @@ +Files: plugins/applets/libnotesapplet.so* +Priority: optional +Section: opie/system +Maintainer: L. J. Potter <ljp@llornkcor.com> +Architecture: arm +Version: $QPE_VERSION-$SUB_VERSION.1 +Depends: opie-base ($QPE_VERSION) +Description: Screenshot Applet + A simple taskbar applet for making quick notes. |