author | mickeyl <mickeyl> | 2004-03-01 21:10:13 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-03-01 21:10:13 (UTC) |
commit | 77af6f58d59011e123309c82b684695508a46787 (patch) (unidiff) | |
tree | 1eeb3b323bc14581af7da9fe5b58c4c611b00575 | |
parent | 7b0bdb05e4ae29b2643d73e3b8f20a86a86dcccc (diff) | |
download | opie-77af6f58d59011e123309c82b684695508a46787.zip opie-77af6f58d59011e123309c82b684695508a46787.tar.gz opie-77af6f58d59011e123309c82b684695508a46787.tar.bz2 |
remove boiler plate code in favour of a template
21 files changed, 67 insertions, 354 deletions
diff --git a/noncore/applets/autorotateapplet/autorotate.cpp b/noncore/applets/autorotateapplet/autorotate.cpp index 5152904..94be0ae 100644 --- a/noncore/applets/autorotateapplet/autorotate.cpp +++ b/noncore/applets/autorotateapplet/autorotate.cpp | |||
@@ -1,90 +1,101 @@ | |||
1 | /* | 1 | /* |
2 | * copyright : (c) 2003 by Greg Gilbert | 2 | * copyright : (c) 2003 by Greg Gilbert |
3 | * email : greg@treke.net | 3 | * email : greg@treke.net |
4 | * based on the cardmon applet by Max Reiss | 4 | * based on the cardmon applet by Max Reiss |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * | 7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * | 8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * | 9 | * (at your option) any later version. * |
10 | * * | 10 | * * |
11 | *************************************************************************/ | 11 | *************************************************************************/ |
12 | 12 | ||
13 | #include "autorotate.h" | 13 | #include "autorotate.h" |
14 | 14 | ||
15 | /* OPIE */ | 15 | /* OPIE */ |
16 | #include <opie2/odevice.h> | 16 | #include <opie2/odevice.h> |
17 | #include <opie2/otaskbarapplet.h> | ||
17 | #include <qpe/applnk.h> | 18 | #include <qpe/applnk.h> |
18 | #include <qpe/config.h> | 19 | #include <qpe/config.h> |
19 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
20 | 21 | ||
21 | /* QT */ | 22 | /* QT */ |
22 | #include <qpainter.h> | 23 | #include <qpainter.h> |
23 | 24 | ||
24 | using namespace Opie; | 25 | using namespace Opie; |
25 | 26 | ||
26 | AutoRotate::AutoRotate(QWidget * parent):QWidget(parent) | 27 | AutoRotate::AutoRotate(QWidget * parent):QWidget(parent) |
27 | { | 28 | { |
28 | setFixedWidth( AppLnk::smallIconSize() ); | 29 | setFixedWidth( AppLnk::smallIconSize() ); |
29 | setFixedHeight( AppLnk::smallIconSize() ); | 30 | setFixedHeight( AppLnk::smallIconSize() ); |
30 | 31 | ||
31 | enabledPm.convertFromImage( Resource::loadImage("autorotate/rotate").smoothScale( height(), width() ) ); | 32 | enabledPm.convertFromImage( Resource::loadImage("autorotate/rotate").smoothScale( height(), width() ) ); |
32 | disabledPm.convertFromImage( Resource::loadImage("autorotate/norotate").smoothScale( height(), width() ) ); | 33 | disabledPm.convertFromImage( Resource::loadImage("autorotate/norotate").smoothScale( height(), width() ) ); |
33 | 34 | ||
34 | repaint(true); | 35 | repaint(true); |
35 | popupMenu = 0; | 36 | popupMenu = 0; |
36 | show(); | 37 | show(); |
37 | } | 38 | } |
38 | 39 | ||
39 | AutoRotate::~AutoRotate() | 40 | AutoRotate::~AutoRotate() |
40 | { | 41 | { |
41 | if (popupMenu) { | 42 | if (popupMenu) { |
42 | delete popupMenu; | 43 | delete popupMenu; |
43 | } | 44 | } |
44 | } | 45 | } |
45 | 46 | ||
47 | int AutoRotate::position() | ||
48 | { | ||
49 | return 7; | ||
50 | } | ||
51 | |||
46 | void AutoRotate::mousePressEvent(QMouseEvent *) | 52 | void AutoRotate::mousePressEvent(QMouseEvent *) |
47 | { | 53 | { |
48 | QPopupMenu *menu = new QPopupMenu(this); | 54 | QPopupMenu *menu = new QPopupMenu(this); |
49 | menu->insertItem( isRotateEnabled()? "Disable Rotation" : "Enable Rotation" ,1 ); | 55 | menu->insertItem( isRotateEnabled()? "Disable Rotation" : "Enable Rotation" ,1 ); |
50 | 56 | ||
51 | QPoint p = mapToGlobal(QPoint(0, 0)); | 57 | QPoint p = mapToGlobal(QPoint(0, 0)); |
52 | QSize s = menu->sizeHint(); | 58 | QSize s = menu->sizeHint(); |
53 | int opt = menu->exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), p.y() - s.height()), 0); | 59 | int opt = menu->exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), p.y() - s.height()), 0); |
54 | 60 | ||
55 | if (opt==1) | 61 | if (opt==1) |
56 | { | 62 | { |
57 | setRotateEnabled( !isRotateEnabled() ); | 63 | setRotateEnabled( !isRotateEnabled() ); |
58 | repaint(true); | 64 | repaint(true); |
59 | } | 65 | } |
60 | 66 | ||
61 | delete menu; | 67 | delete menu; |
62 | } | 68 | } |
63 | 69 | ||
64 | void AutoRotate::paintEvent(QPaintEvent *) | 70 | void AutoRotate::paintEvent(QPaintEvent *) |
65 | { | 71 | { |
66 | QPainter p(this); | 72 | QPainter p(this); |
67 | p.drawPixmap( 0, 0, isRotateEnabled()? enabledPm : disabledPm ); | 73 | p.drawPixmap( 0, 0, isRotateEnabled()? enabledPm : disabledPm ); |
68 | } | 74 | } |
69 | 75 | ||
70 | void AutoRotate::setRotateEnabled(bool status) | 76 | void AutoRotate::setRotateEnabled(bool status) |
71 | { | 77 | { |
72 | Config cfg( "qpe" ); | 78 | Config cfg( "qpe" ); |
73 | cfg.setGroup( "Appearance" ); | 79 | cfg.setGroup( "Appearance" ); |
74 | cfg.writeEntry( "rotateEnabled", status ); | 80 | cfg.writeEntry( "rotateEnabled", status ); |
75 | 81 | ||
76 | } | 82 | } |
77 | bool AutoRotate::isRotateEnabled() | 83 | bool AutoRotate::isRotateEnabled() |
78 | { | 84 | { |
79 | Config cfg( "qpe" ); | 85 | Config cfg( "qpe" ); |
80 | cfg.setGroup( "Appearance" ); | 86 | cfg.setGroup( "Appearance" ); |
81 | 87 | ||
82 | bool res = cfg.readBoolEntry( "rotateEnabled" ); | 88 | bool res = cfg.readBoolEntry( "rotateEnabled" ); |
83 | 89 | ||
84 | if (res ) | 90 | if (res ) |
85 | qDebug("Enabled"); | 91 | qDebug("Enabled"); |
86 | else | 92 | else |
87 | qDebug("Disabled"); | 93 | qDebug("Disabled"); |
88 | return res; | 94 | return res; |
89 | } | 95 | } |
90 | 96 | ||
97 | Q_EXPORT_INTERFACE() | ||
98 | { | ||
99 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<AutoRotate> ); | ||
100 | } | ||
101 | |||
diff --git a/noncore/applets/autorotateapplet/autorotate.h b/noncore/applets/autorotateapplet/autorotate.h index e05e7a0..ef322a6 100644 --- a/noncore/applets/autorotateapplet/autorotate.h +++ b/noncore/applets/autorotateapplet/autorotate.h | |||
@@ -1,41 +1,40 @@ | |||
1 | /* | 1 | /* |
2 | * copyright : (c) 2003 by Greg Gilbert | 2 | * copyright : (c) 2003 by Greg Gilbert |
3 | * email : greg@treke.net | 3 | * email : greg@treke.net |
4 | * based on the cardmon applet by Max Reiss | 4 | * based on the cardmon applet by Max Reiss |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * | 7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * | 8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * | 9 | * (at your option) any later version. * |
10 | * * | 10 | * * |
11 | *************************************************************************/ | 11 | *************************************************************************/ |
12 | 12 | ||
13 | #ifndef AUTOROTATE_H | 13 | #ifndef AUTOROTATE_H |
14 | #define AUTOROTATE_H | 14 | #define AUTOROTATE_H |
15 | 15 | ||
16 | #include <qwidget.h> | 16 | #include <qwidget.h> |
17 | #include <qpixmap.h> | 17 | #include <qpixmap.h> |
18 | #include <qpopupmenu.h> | 18 | #include <qpopupmenu.h> |
19 | 19 | ||
20 | class AutoRotate : public QWidget { | 20 | class AutoRotate : public QWidget { |
21 | Q_OBJECT | 21 | Q_OBJECT |
22 | public: | 22 | public: |
23 | AutoRotate( QWidget *parent = 0 ); | 23 | AutoRotate( QWidget *parent = 0 ); |
24 | ~AutoRotate(); | 24 | ~AutoRotate(); |
25 | 25 | static int position(); | |
26 | private slots: | ||
27 | 26 | ||
28 | protected: | 27 | protected: |
29 | void paintEvent( QPaintEvent* ); | 28 | void paintEvent( QPaintEvent* ); |
30 | void mousePressEvent( QMouseEvent * ); | 29 | void mousePressEvent( QMouseEvent * ); |
31 | private: | 30 | private: |
32 | bool isRotateEnabled(); | 31 | bool isRotateEnabled(); |
33 | void setRotateEnabled(bool); | 32 | void setRotateEnabled(bool); |
34 | QPixmap enabledPm; | 33 | QPixmap enabledPm; |
35 | QPixmap disabledPm; | 34 | QPixmap disabledPm; |
36 | void iconShow(); | 35 | void iconShow(); |
37 | QPopupMenu *popupMenu; | 36 | QPopupMenu *popupMenu; |
38 | }; | 37 | }; |
39 | 38 | ||
40 | #endif | 39 | #endif |
41 | 40 | ||
diff --git a/noncore/applets/autorotateapplet/autorotateapplet.pro b/noncore/applets/autorotateapplet/autorotateapplet.pro index 0ccbeba..465b165 100644 --- a/noncore/applets/autorotateapplet/autorotateapplet.pro +++ b/noncore/applets/autorotateapplet/autorotateapplet.pro | |||
@@ -1,13 +1,13 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt plugin warn_on release | 2 | CONFIG += qt plugin warn_on release |
3 | HEADERS = autorotate.h autorotateimpl.h | 3 | HEADERS = autorotate.h |
4 | SOURCES = autorotate.cpp autorotateimpl.cpp | 4 | SOURCES = autorotate.cpp |
5 | TARGET = autorotateapplet | 5 | TARGET = autorotateapplet |
6 | DESTDIR = $(OPIEDIR)/plugins/applets | 6 | DESTDIR = $(OPIEDIR)/plugins/applets |
7 | INCLUDEPATH += $(OPIEDIR)/include | 7 | INCLUDEPATH += $(OPIEDIR)/include |
8 | DEPENDPATH += $(OPIEDIR)/include ../launcher | 8 | DEPENDPATH += $(OPIEDIR)/include ../launcher |
9 | LIBS += -lqpe -lopiecore2 | 9 | LIBS += -lqpe -lopiecore2 |
10 | VERSION = 1.0.0 | 10 | VERSION = 1.0.0 |
11 | 11 | ||
12 | include ( $(OPIEDIR)/include.pro ) | 12 | include ( $(OPIEDIR)/include.pro ) |
13 | target.path = $$prefix/plugins/applets | 13 | target.path = $$prefix/plugins/applets |
diff --git a/noncore/applets/autorotateapplet/autorotateimpl.cpp b/noncore/applets/autorotateapplet/autorotateimpl.cpp deleted file mode 100644 index 305ac50..0000000 --- a/noncore/applets/autorotateapplet/autorotateimpl.cpp +++ b/dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | #include "autorotate.h" | ||
2 | #include "autorotateimpl.h" | ||
3 | |||
4 | |||
5 | AutoRotateImpl::AutoRotateImpl() | ||
6 | : autoRotate(0){ | ||
7 | qDebug ("here"); | ||
8 | } | ||
9 | |||
10 | AutoRotateImpl::~AutoRotateImpl() { | ||
11 | delete autoRotate; | ||
12 | } | ||
13 | |||
14 | QWidget *AutoRotateImpl::applet( QWidget *parent ) { | ||
15 | if ( !autoRotate ) { | ||
16 | autoRotate = new AutoRotate( parent ); | ||
17 | } | ||
18 | return autoRotate; | ||
19 | } | ||
20 | |||
21 | int AutoRotateImpl::position() const { | ||
22 | return 7; | ||
23 | } | ||
24 | |||
25 | QRESULT AutoRotateImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { | ||
26 | *iface = 0; | ||
27 | if ( uuid == IID_QUnknown ) { | ||
28 | *iface = this; | ||
29 | } else if ( uuid == IID_TaskbarApplet ) { | ||
30 | *iface = this; | ||
31 | } else | ||
32 | return QS_FALSE; | ||
33 | |||
34 | if ( *iface ) { | ||
35 | (*iface)->addRef(); | ||
36 | } | ||
37 | return QS_OK; | ||
38 | } | ||
39 | |||
40 | Q_EXPORT_INTERFACE() { | ||
41 | Q_CREATE_INSTANCE( AutoRotateImpl ) | ||
42 | } | ||
diff --git a/noncore/applets/autorotateapplet/autorotateimpl.h b/noncore/applets/autorotateapplet/autorotateimpl.h deleted file mode 100644 index fde23a9..0000000 --- a/noncore/applets/autorotateapplet/autorotateimpl.h +++ b/dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #include <qpe/taskbarappletinterface.h> | ||
2 | |||
3 | class AutoRotate; | ||
4 | |||
5 | class AutoRotateImpl : public TaskbarAppletInterface { | ||
6 | public: | ||
7 | AutoRotateImpl(); | ||
8 | virtual ~AutoRotateImpl(); | ||
9 | |||
10 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); | ||
11 | Q_REFCOUNT | ||
12 | |||
13 | virtual QWidget *applet( QWidget *parent ); | ||
14 | virtual int position() const; | ||
15 | |||
16 | private: | ||
17 | AutoRotate *autoRotate; | ||
18 | }; | ||
diff --git a/noncore/applets/memoryapplet/memoryapplet.pro b/noncore/applets/memoryapplet/memoryapplet.pro index 6031386..3cd7839 100644 --- a/noncore/applets/memoryapplet/memoryapplet.pro +++ b/noncore/applets/memoryapplet/memoryapplet.pro | |||
@@ -1,24 +1,22 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt plugin warn_on release | 2 | CONFIG += qt plugin warn_on release |
3 | HEADERS = ../../settings/sysinfo/graph.h \ | 3 | HEADERS = ../../settings/sysinfo/graph.h \ |
4 | ../../settings/sysinfo/load.h \ | 4 | ../../settings/sysinfo/load.h \ |
5 | ../../settings/sysinfo/memory.h \ | 5 | ../../settings/sysinfo/memory.h \ |
6 | memoryappletimpl.h \ | ||
7 | memorymeter.h \ | 6 | memorymeter.h \ |
8 | memorystatus.h \ | 7 | memorystatus.h \ |
9 | swapfile.h | 8 | swapfile.h |
10 | SOURCES = ../../settings/sysinfo/graph.cpp \ | 9 | SOURCES = ../../settings/sysinfo/graph.cpp \ |
11 | ../../settings/sysinfo/load.cpp \ | 10 | ../../settings/sysinfo/load.cpp \ |
12 | ../../settings/sysinfo/memory.cpp \ | 11 | ../../settings/sysinfo/memory.cpp \ |
13 | memoryappletimpl.cpp \ | ||
14 | memorymeter.cpp \ | 12 | memorymeter.cpp \ |
15 | memorystatus.cpp \ | 13 | memorystatus.cpp \ |
16 | swapfile.cpp | 14 | swapfile.cpp |
17 | TARGET = memoryapplet | 15 | TARGET = memoryapplet |
18 | DESTDIR = $(OPIEDIR)/plugins/applets | 16 | DESTDIR = $(OPIEDIR)/plugins/applets |
19 | INCLUDEPATH += $(OPIEDIR)/include | 17 | INCLUDEPATH += $(OPIEDIR)/include |
20 | DEPENDPATH += ../$(OPIEDIR)/include | 18 | DEPENDPATH += ../$(OPIEDIR)/include |
21 | VERSION = 1.0.0 | 19 | VERSION = 1.0.0 |
22 | LIBS += -lqpe -lopieui2 | 20 | LIBS += -lqpe -lopiecore2 -lopieui2 |
23 | 21 | ||
24 | include ( $(OPIEDIR)/include.pro ) | 22 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/applets/memoryapplet/memoryappletimpl.cpp b/noncore/applets/memoryapplet/memoryappletimpl.cpp deleted file mode 100644 index a117e7f..0000000 --- a/noncore/applets/memoryapplet/memoryappletimpl.cpp +++ b/dev/null | |||
@@ -1,65 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of the Qtopia Environment. | ||
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 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "memorymeter.h" | ||
21 | #include "memoryappletimpl.h" | ||
22 | |||
23 | MemoryAppletImpl::MemoryAppletImpl() | ||
24 | : memory(0) | ||
25 | { | ||
26 | } | ||
27 | |||
28 | MemoryAppletImpl::~MemoryAppletImpl() | ||
29 | { | ||
30 | delete memory; | ||
31 | } | ||
32 | |||
33 | QWidget *MemoryAppletImpl::applet( QWidget *parent ) | ||
34 | { | ||
35 | if ( !memory ) | ||
36 | memory = new MemoryMeter( parent ); | ||
37 | |||
38 | return memory; | ||
39 | } | ||
40 | |||
41 | int MemoryAppletImpl::position() const | ||
42 | { | ||
43 | return 8; | ||
44 | } | ||
45 | |||
46 | QRESULT MemoryAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) | ||
47 | { | ||
48 | *iface = 0; | ||
49 | if ( uuid == IID_QUnknown ) | ||
50 | *iface = this; | ||
51 | else if ( uuid == IID_TaskbarApplet ) | ||
52 | *iface = this; | ||
53 | else | ||
54 | return QS_FALSE; | ||
55 | |||
56 | (*iface)->addRef(); | ||
57 | |||
58 | return QS_OK; | ||
59 | } | ||
60 | |||
61 | Q_EXPORT_INTERFACE() | ||
62 | { | ||
63 | Q_CREATE_INSTANCE( MemoryAppletImpl ) | ||
64 | } | ||
65 | |||
diff --git a/noncore/applets/memoryapplet/memoryappletimpl.h b/noncore/applets/memoryapplet/memoryappletimpl.h deleted file mode 100644 index 2db7dbe..0000000 --- a/noncore/applets/memoryapplet/memoryappletimpl.h +++ b/dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of the Qtopia Environment. | ||
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 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef MEMORYAPPLETIMPL_H | ||
21 | #define MEMORYAPPLETIMPL_H | ||
22 | |||
23 | #include <qtopia/taskbarappletinterface.h> | ||
24 | |||
25 | class MemoryMeter; | ||
26 | |||
27 | class /*QTOPIA_PLUGIN_EXPORT*/ MemoryAppletImpl : public TaskbarAppletInterface | ||
28 | { | ||
29 | public: | ||
30 | MemoryAppletImpl(); | ||
31 | virtual ~MemoryAppletImpl(); | ||
32 | |||
33 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); | ||
34 | Q_REFCOUNT | ||
35 | |||
36 | virtual QWidget *applet( QWidget *parent ); | ||
37 | virtual int position() const; | ||
38 | |||
39 | private: | ||
40 | MemoryMeter *memory; | ||
41 | }; | ||
42 | |||
43 | #endif | ||
diff --git a/noncore/applets/memoryapplet/memorymeter.cpp b/noncore/applets/memoryapplet/memorymeter.cpp index 54b5c52..9299f49 100644 --- a/noncore/applets/memoryapplet/memorymeter.cpp +++ b/noncore/applets/memoryapplet/memorymeter.cpp | |||
@@ -1,239 +1,247 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
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 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "memorymeter.h" | 20 | #include "memorymeter.h" |
21 | #include "memorystatus.h" | 21 | #include "memorystatus.h" |
22 | 22 | ||
23 | #include <opie2/otaskbarapplet.h> | ||
23 | #include <qtopia/power.h> | 24 | #include <qtopia/power.h> |
24 | #include <qtopia/config.h> | 25 | #include <qtopia/config.h> |
25 | |||
26 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | ||
27 | #include <qtopia/qcopenvelope_qws.h> | 26 | #include <qtopia/qcopenvelope_qws.h> |
28 | #endif | ||
29 | 27 | ||
30 | #include <qpainter.h> | 28 | #include <qpainter.h> |
31 | #include <qtimer.h> | 29 | #include <qtimer.h> |
32 | #include <qapplication.h> | 30 | #include <qapplication.h> |
33 | 31 | ||
34 | #include <qtopia/applnk.h> | 32 | #include <qtopia/applnk.h> |
35 | 33 | ||
36 | MemoryMeter::MemoryMeter( QWidget *parent ) | 34 | MemoryMeter::MemoryMeter( QWidget *parent ) |
37 | : QWidget( parent ), memoryView(0) | 35 | : QWidget( parent ), memoryView(0) |
38 | { | 36 | { |
39 | bvsz = QSize(); | 37 | bvsz = QSize(); |
40 | if ( qApp->desktop()->height() >= 300 ) | 38 | if ( qApp->desktop()->height() >= 300 ) |
41 | { | 39 | { |
42 | memoryView = new MemoryStatus( 0, WStyle_StaysOnTop | WType_Popup ); | 40 | memoryView = new MemoryStatus( 0, WStyle_StaysOnTop | WType_Popup ); |
43 | memoryView->setFrameStyle( QFrame::Panel | QFrame::Raised ); | 41 | memoryView->setFrameStyle( QFrame::Panel | QFrame::Raised ); |
44 | } | 42 | } |
45 | else | 43 | else |
46 | { | 44 | { |
47 | memoryView = new MemoryStatus( 0 ); | 45 | memoryView = new MemoryStatus( 0 ); |
48 | memoryView->showMaximized(); | 46 | memoryView->showMaximized(); |
49 | } | 47 | } |
50 | 48 | ||
51 | Config config("MemoryPlugin"); | 49 | Config config("MemoryPlugin"); |
52 | config.setGroup("Warning levels"); | 50 | config.setGroup("Warning levels"); |
53 | low = config.readNumEntry("low", 40); | 51 | low = config.readNumEntry("low", 40); |
54 | critical = config.readNumEntry("critical", 20); | 52 | critical = config.readNumEntry("critical", 20); |
55 | 53 | ||
56 | startTimer( 10000 ); | 54 | startTimer( 10000 ); |
57 | setFixedWidth(10); | 55 | setFixedWidth(10); |
58 | setFixedHeight(AppLnk::smallIconSize()); | 56 | setFixedHeight(AppLnk::smallIconSize()); |
59 | usageTimer = new QTimer( this ); | 57 | usageTimer = new QTimer( this ); |
60 | connect( usageTimer, SIGNAL(timeout()), this, SLOT(usageTimeout()) ); | 58 | connect( usageTimer, SIGNAL(timeout()), this, SLOT(usageTimeout()) ); |
61 | timerEvent(0); | 59 | timerEvent(0); |
62 | } | 60 | } |
63 | 61 | ||
64 | MemoryMeter::~MemoryMeter() | 62 | MemoryMeter::~MemoryMeter() |
65 | { | 63 | { |
66 | delete (QWidget *) memoryView; | 64 | delete (QWidget *) memoryView; |
67 | } | 65 | } |
68 | 66 | ||
67 | int MemoryMeter::position() | ||
68 | { | ||
69 | return 7; | ||
70 | } | ||
71 | |||
69 | QSize MemoryMeter::sizeHint() const | 72 | QSize MemoryMeter::sizeHint() const |
70 | { | 73 | { |
71 | return QSize(10, AppLnk::smallIconSize()); | 74 | return QSize(10, AppLnk::smallIconSize()); |
72 | } | 75 | } |
73 | 76 | ||
74 | bool MemoryMeter::updateMemoryViewGeometry() | 77 | bool MemoryMeter::updateMemoryViewGeometry() |
75 | { | 78 | { |
76 | if (memoryView != 0) | 79 | if (memoryView != 0) |
77 | { | 80 | { |
78 | QSize sz = memoryView->sizeHint(); | 81 | QSize sz = memoryView->sizeHint(); |
79 | if ( sz != bvsz ) | 82 | if ( sz != bvsz ) |
80 | { | 83 | { |
81 | bvsz = sz; | 84 | bvsz = sz; |
82 | QRect r(memoryView->pos(), memoryView->sizeHint()); | 85 | QRect r(memoryView->pos(), memoryView->sizeHint()); |
83 | if ( qApp->desktop()->height() >= 300 ) | 86 | if ( qApp->desktop()->height() >= 300 ) |
84 | { | 87 | { |
85 | QPoint curPos = mapToGlobal( rect().topLeft() ); | 88 | QPoint curPos = mapToGlobal( rect().topLeft() ); |
86 | int lp = qApp->desktop()->width() - memoryView->sizeHint().width(); | 89 | int lp = qApp->desktop()->width() - memoryView->sizeHint().width(); |
87 | r.moveTopLeft( QPoint(lp, curPos.y() - memoryView->sizeHint().height()-1) ); | 90 | r.moveTopLeft( QPoint(lp, curPos.y() - memoryView->sizeHint().height()-1) ); |
88 | } | 91 | } |
89 | memoryView->setGeometry(r); | 92 | memoryView->setGeometry(r); |
90 | return TRUE; | 93 | return TRUE; |
91 | } | 94 | } |
92 | return FALSE; | 95 | return FALSE; |
93 | } | 96 | } |
94 | 97 | ||
95 | return FALSE; | 98 | return FALSE; |
96 | } | 99 | } |
97 | 100 | ||
98 | void MemoryMeter::mousePressEvent( QMouseEvent *) | 101 | void MemoryMeter::mousePressEvent( QMouseEvent *) |
99 | { | 102 | { |
100 | if ( memoryView->isVisible() ) | 103 | if ( memoryView->isVisible() ) |
101 | { | 104 | { |
102 | memoryView->hide(); | 105 | memoryView->hide(); |
103 | } | 106 | } |
104 | else | 107 | else |
105 | { | 108 | { |
106 | bvsz = QSize(); | 109 | bvsz = QSize(); |
107 | updateMemoryViewGeometry(); | 110 | updateMemoryViewGeometry(); |
108 | memoryView->raise(); | 111 | memoryView->raise(); |
109 | memoryView->show(); | 112 | memoryView->show(); |
110 | } | 113 | } |
111 | } | 114 | } |
112 | 115 | ||
113 | void MemoryMeter::timerEvent( QTimerEvent * ) | 116 | void MemoryMeter::timerEvent( QTimerEvent * ) |
114 | { | 117 | { |
115 | if (memoryView != 0) | 118 | if (memoryView != 0) |
116 | { | 119 | { |
117 | // read memory status | 120 | // read memory status |
118 | percent = (memoryView->percent()); | 121 | percent = (memoryView->percent()); |
119 | usageTimer->start( 1000 ); | 122 | usageTimer->start( 1000 ); |
120 | } | 123 | } |
121 | } | 124 | } |
122 | 125 | ||
123 | void MemoryMeter::usageTimeout() | 126 | void MemoryMeter::usageTimeout() |
124 | { | 127 | { |
125 | if (memoryView != 0) | 128 | if (memoryView != 0) |
126 | { | 129 | { |
127 | percent = (memoryView->percent()); | 130 | percent = (memoryView->percent()); |
128 | if (updateMemoryViewGeometry() && memoryView->isVisible()) | 131 | if (updateMemoryViewGeometry() && memoryView->isVisible()) |
129 | { | 132 | { |
130 | memoryView->hide(); | 133 | memoryView->hide(); |
131 | memoryView->show(); | 134 | memoryView->show(); |
132 | } | 135 | } |
133 | 136 | ||
134 | repaint(FALSE); | 137 | repaint(FALSE); |
135 | } | 138 | } |
136 | } | 139 | } |
137 | 140 | ||
138 | void MemoryMeter::paintEvent( QPaintEvent* ) | 141 | void MemoryMeter::paintEvent( QPaintEvent* ) |
139 | { | 142 | { |
140 | QPainter p(this); | 143 | QPainter p(this); |
141 | 144 | ||
142 | QColor c; | 145 | QColor c; |
143 | QColor darkc; | 146 | QColor darkc; |
144 | QColor lightc; | 147 | QColor lightc; |
145 | 148 | ||
146 | if (percent > low) | 149 | if (percent > low) |
147 | c = green; | 150 | c = green; |
148 | else if (percent > critical) | 151 | else if (percent > critical) |
149 | c = yellow.dark(110); | 152 | c = yellow.dark(110); |
150 | else | 153 | else |
151 | c = red; | 154 | c = red; |
152 | 155 | ||
153 | darkc = c.dark(120); | 156 | darkc = c.dark(120); |
154 | lightc = c.light(160); | 157 | lightc = c.light(160); |
155 | 158 | ||
156 | // | 159 | // |
157 | // To simulate a 3-d memory, we use 4 bands of colour. From left | 160 | // To simulate a 3-d memory, we use 4 bands of colour. From left |
158 | // to right, these are: medium, light, medium, dark. To avoid | 161 | // to right, these are: medium, light, medium, dark. To avoid |
159 | // hardcoding values for band "width", figure everything out on the run. | 162 | // hardcoding values for band "width", figure everything out on the run. |
160 | // | 163 | // |
161 | int batt_width; // width of each band | 164 | int batt_width; // width of each band |
162 | int batt_height; // memory height (not including terminal) | 165 | int batt_height; // memory height (not including terminal) |
163 | int used_height; // used amount of memory (scanlines) | 166 | int used_height; // used amount of memory (scanlines) |
164 | 167 | ||
165 | int batt_yoffset; // top of terminal | 168 | int batt_yoffset; // top of terminal |
166 | int batt_xoffset; // left edge of core | 169 | int batt_xoffset; // left edge of core |
167 | 170 | ||
168 | int band_width; // width of colour band | 171 | int band_width; // width of colour band |
169 | 172 | ||
170 | int w = QMIN(height(), width()); | 173 | int w = QMIN(height(), width()); |
171 | band_width = (w-2) / 4; | 174 | band_width = (w-2) / 4; |
172 | if ( band_width < 1 ) | 175 | if ( band_width < 1 ) |
173 | band_width = 1; | 176 | band_width = 1; |
174 | 177 | ||
175 | batt_width = 4 * band_width + 2;// +2 for 1 pixel border on both sides | 178 | batt_width = 4 * band_width + 2;// +2 for 1 pixel border on both sides |
176 | batt_height = height()-2; | 179 | batt_height = height()-2; |
177 | batt_xoffset = (width() - batt_width) / 2; | 180 | batt_xoffset = (width() - batt_width) / 2; |
178 | batt_yoffset = (height() - batt_height) / 2; | 181 | batt_yoffset = (height() - batt_height) / 2; |
179 | 182 | ||
180 | // | 183 | // |
181 | // Memory border. +1 to make space for the terminal at row 0. | 184 | // Memory border. +1 to make space for the terminal at row 0. |
182 | // | 185 | // |
183 | p.setPen(QColor(80, 80, 80)); | 186 | p.setPen(QColor(80, 80, 80)); |
184 | p.drawRect(batt_xoffset, batt_yoffset + 1, batt_width, batt_height); | 187 | p.drawRect(batt_xoffset, batt_yoffset + 1, batt_width, batt_height); |
185 | 188 | ||
186 | // | 189 | // |
187 | // Draw terminal. +1 to take into account the left border. | 190 | // Draw terminal. +1 to take into account the left border. |
188 | // | 191 | // |
189 | //p.drawLine(batt_xoffset + band_width + 1, batt_yoffset, batt_xoffset + 3 * band_width, batt_yoffset); | 192 | //p.drawLine(batt_xoffset + band_width + 1, batt_yoffset, batt_xoffset + 3 * band_width, batt_yoffset); |
190 | 193 | ||
191 | batt_height -= 2;// -2 because we don't want to include border | 194 | batt_height -= 2;// -2 because we don't want to include border |
192 | batt_yoffset += 2; // +2 to account for border and terminal | 195 | batt_yoffset += 2; // +2 to account for border and terminal |
193 | batt_xoffset++; | 196 | batt_xoffset++; |
194 | 197 | ||
195 | // | 198 | // |
196 | // 100 - percent, since percent is amount remaining, and we draw | 199 | // 100 - percent, since percent is amount remaining, and we draw |
197 | // reverse to this. | 200 | // reverse to this. |
198 | // | 201 | // |
199 | used_height = percent * batt_height / 100; | 202 | used_height = percent * batt_height / 100; |
200 | if (used_height < 0) | 203 | if (used_height < 0) |
201 | used_height = 0; | 204 | used_height = 0; |
202 | 205 | ||
203 | // | 206 | // |
204 | // Drained section. | 207 | // Drained section. |
205 | // | 208 | // |
206 | if (used_height != 0) | 209 | if (used_height != 0) |
207 | { | 210 | { |
208 | p.setPen(NoPen); | 211 | p.setPen(NoPen); |
209 | p.setBrush(gray); | 212 | p.setBrush(gray); |
210 | p.drawRect(batt_xoffset, batt_yoffset, band_width, used_height); | 213 | p.drawRect(batt_xoffset, batt_yoffset, band_width, used_height); |
211 | p.drawRect(batt_xoffset + 2 * band_width, batt_yoffset, band_width, used_height); | 214 | p.drawRect(batt_xoffset + 2 * band_width, batt_yoffset, band_width, used_height); |
212 | 215 | ||
213 | p.setBrush(gray/*.light(130)*/); | 216 | p.setBrush(gray/*.light(130)*/); |
214 | p.drawRect(batt_xoffset + band_width, batt_yoffset, band_width, used_height); | 217 | p.drawRect(batt_xoffset + band_width, batt_yoffset, band_width, used_height); |
215 | 218 | ||
216 | p.setBrush(gray/*.dark(120)*/); | 219 | p.setBrush(gray/*.dark(120)*/); |
217 | p.drawRect(batt_xoffset + 3 * band_width, batt_yoffset, band_width, used_height); | 220 | p.drawRect(batt_xoffset + 3 * band_width, batt_yoffset, band_width, used_height); |
218 | } | 221 | } |
219 | 222 | ||
220 | // | 223 | // |
221 | // Unused section. | 224 | // Unused section. |
222 | // | 225 | // |
223 | if ( batt_height - used_height > 0 ) | 226 | if ( batt_height - used_height > 0 ) |
224 | { | 227 | { |
225 | int unused_offset = used_height + batt_yoffset; | 228 | int unused_offset = used_height + batt_yoffset; |
226 | int unused_height = batt_height - used_height; | 229 | int unused_height = batt_height - used_height; |
227 | p.setPen(NoPen); | 230 | p.setPen(NoPen); |
228 | p.setBrush(c); | 231 | p.setBrush(c); |
229 | p.drawRect(batt_xoffset, unused_offset, band_width, unused_height); | 232 | p.drawRect(batt_xoffset, unused_offset, band_width, unused_height); |
230 | p.drawRect(batt_xoffset + 2 * band_width, unused_offset, band_width, unused_height); | 233 | p.drawRect(batt_xoffset + 2 * band_width, unused_offset, band_width, unused_height); |
231 | 234 | ||
232 | p.setBrush(lightc); | 235 | p.setBrush(lightc); |
233 | p.drawRect(batt_xoffset + band_width, unused_offset, band_width, unused_height); | 236 | p.drawRect(batt_xoffset + band_width, unused_offset, band_width, unused_height); |
234 | 237 | ||
235 | p.setBrush(darkc); | 238 | p.setBrush(darkc); |
236 | p.drawRect(batt_xoffset + 3 * band_width, unused_offset, band_width, unused_height); | 239 | p.drawRect(batt_xoffset + 3 * band_width, unused_offset, band_width, unused_height); |
237 | } | 240 | } |
238 | } | 241 | } |
239 | 242 | ||
243 | Q_EXPORT_INTERFACE() | ||
244 | { | ||
245 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<MemoryMeter> ); | ||
246 | } | ||
247 | |||
diff --git a/noncore/applets/memoryapplet/memorymeter.h b/noncore/applets/memoryapplet/memorymeter.h index 0f3cb0b..ed541f0 100644 --- a/noncore/applets/memoryapplet/memorymeter.h +++ b/noncore/applets/memoryapplet/memorymeter.h | |||
@@ -1,53 +1,54 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
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 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef MEMORY_H | 20 | #ifndef MEMORY_H |
21 | #define MEMORY_H | 21 | #define MEMORY_H |
22 | 22 | ||
23 | #include <qwidget.h> | 23 | #include <qwidget.h> |
24 | 24 | ||
25 | class MemoryStatus; | 25 | class MemoryStatus; |
26 | class QTimer; | 26 | class QTimer; |
27 | 27 | ||
28 | class MemoryMeter : public QWidget | 28 | class MemoryMeter : public QWidget |
29 | { | 29 | { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | public: | 31 | public: |
32 | MemoryMeter( QWidget *parent = 0 ); | 32 | MemoryMeter( QWidget *parent = 0 ); |
33 | ~MemoryMeter(); | 33 | ~MemoryMeter(); |
34 | static int position(); | ||
34 | 35 | ||
35 | QSize sizeHint() const; | 36 | QSize sizeHint() const; |
36 | MemoryStatus* memoryView; | 37 | MemoryStatus* memoryView; |
37 | 38 | ||
38 | protected: | 39 | protected: |
39 | void timerEvent( QTimerEvent * ); | 40 | void timerEvent( QTimerEvent * ); |
40 | void paintEvent( QPaintEvent* ); | 41 | void paintEvent( QPaintEvent* ); |
41 | void mousePressEvent( QMouseEvent * ); | 42 | void mousePressEvent( QMouseEvent * ); |
42 | 43 | ||
43 | protected slots: | 44 | protected slots: |
44 | void usageTimeout(); | 45 | void usageTimeout(); |
45 | 46 | ||
46 | protected: | 47 | protected: |
47 | QTimer *usageTimer; | 48 | QTimer *usageTimer; |
48 | int percent, low, critical; | 49 | int percent, low, critical; |
49 | QSize bvsz; | 50 | QSize bvsz; |
50 | bool updateMemoryViewGeometry(); | 51 | bool updateMemoryViewGeometry(); |
51 | }; | 52 | }; |
52 | 53 | ||
53 | #endif | 54 | #endif |
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp index 7b8bdd9..1142028 100644 --- a/noncore/applets/notesapplet/notes.cpp +++ b/noncore/applets/notesapplet/notes.cpp | |||
@@ -1,213 +1,214 @@ | |||
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 <opie2/otaskbarapplet.h> | ||
22 | #include <qpe/filemanager.h> | 23 | #include <qpe/filemanager.h> |
23 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
24 | #include <qpe/timestring.h> | 25 | #include <qpe/timestring.h> |
25 | #include <qpe/applnk.h> | 26 | #include <qpe/applnk.h> |
26 | #include <qpe/ir.h> | 27 | #include <qpe/ir.h> |
27 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
28 | 29 | ||
29 | // #include <qsocket.h> | 30 | // #include <qsocket.h> |
30 | // #include <qclipboard.h> | 31 | // #include <qclipboard.h> |
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 | 36 | ||
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 <qtimer.h> | 46 | #include <qtimer.h> |
46 | 47 | ||
47 | /* XPM */ | 48 | /* XPM */ |
48 | static char * notes_xpm[] = { | 49 | static char * notes_xpm[] = { |
49 | "16 16 11 1", | 50 | "16 16 11 1", |
50 | " c None", | 51 | " c None", |
51 | ". c #000000", | 52 | ". c #000000", |
52 | "+ c #7F7F7F", | 53 | "+ c #7F7F7F", |
53 | "@ c #BFBFBF", | 54 | "@ c #BFBFBF", |
54 | "# c #BFC1FF", | 55 | "# c #BFC1FF", |
55 | "$ c #FF0000", | 56 | "$ c #FF0000", |
56 | "% c #FFFFFF", | 57 | "% c #FFFFFF", |
57 | "& c #00037F", | 58 | "& c #00037F", |
58 | "* c #0006FF", | 59 | "* c #0006FF", |
59 | "= c #0005BF", | 60 | "= c #0005BF", |
60 | "- c #7F0000", | 61 | "- c #7F0000", |
61 | " .. ", | 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 | NotesControl::NotesControl( QWidget *, const char * ) | 80 | NotesControl::NotesControl( QWidget *, const char * ) |
80 | : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop ) | 81 | : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop ) |
81 | // : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) | 82 | // : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) |
82 | { | 83 | { |
83 | QDir d( QDir::homeDirPath()+"/notes"); | 84 | QDir d( QDir::homeDirPath()+"/notes"); |
84 | if( !d.exists()) { | 85 | if( !d.exists()) { |
85 | qDebug("make dir"); | 86 | qDebug("make dir"); |
86 | if(!d.mkdir( QDir::homeDirPath()+"/notes", true)) | 87 | if(!d.mkdir( QDir::homeDirPath()+"/notes", true)) |
87 | qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed"); | 88 | qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed"); |
88 | } | 89 | } |
89 | Config cfg("Notes"); | 90 | Config cfg("Notes"); |
90 | cfg.setGroup("Options"); | 91 | cfg.setGroup("Options"); |
91 | showMax = cfg.readBoolEntry("ShowMax", false); | 92 | showMax = cfg.readBoolEntry("ShowMax", false); |
92 | 93 | ||
93 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 94 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
94 | loaded=false; | 95 | loaded=false; |
95 | edited=false; | 96 | edited=false; |
96 | doPopulate=true; | 97 | doPopulate=true; |
97 | isNew=false; | 98 | isNew=false; |
98 | QVBox *vbox = new QVBox( this, "Vlayout" ); | 99 | QVBox *vbox = new QVBox( this, "Vlayout" ); |
99 | QHBox *hbox = new QHBox( this, "HLayout" ); | 100 | QHBox *hbox = new QHBox( this, "HLayout" ); |
100 | 101 | ||
101 | view = new QMultiLineEdit(vbox, "OpieNotesView"); | 102 | view = new QMultiLineEdit(vbox, "OpieNotesView"); |
102 | 103 | ||
103 | box = new QListBox(vbox, "OpieNotesBox"); | 104 | box = new QListBox(vbox, "OpieNotesBox"); |
104 | 105 | ||
105 | QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); | 106 | QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); |
106 | 107 | ||
107 | box->setFixedHeight(50); | 108 | box->setFixedHeight(50); |
108 | 109 | ||
109 | vbox->setMargin( 6 ); | 110 | vbox->setMargin( 6 ); |
110 | vbox->setSpacing( 3 ); | 111 | vbox->setSpacing( 3 ); |
111 | 112 | ||
112 | 113 | ||
113 | 114 | ||
114 | setFocusPolicy(QWidget::StrongFocus); | 115 | setFocusPolicy(QWidget::StrongFocus); |
115 | 116 | ||
116 | newButton= new QPushButton( hbox, "newButton" ); | 117 | newButton= new QPushButton( hbox, "newButton" ); |
117 | newButton->setText(tr("New")); | 118 | newButton->setText(tr("New")); |
118 | 119 | ||
119 | 120 | ||
120 | saveButton= new QPushButton( hbox, "saveButton" ); | 121 | saveButton= new QPushButton( hbox, "saveButton" ); |
121 | saveButton->setText(tr("Save")); | 122 | saveButton->setText(tr("Save")); |
122 | 123 | ||
123 | 124 | ||
124 | deleteButton= new QPushButton( hbox, "deleteButton" ); | 125 | deleteButton= new QPushButton( hbox, "deleteButton" ); |
125 | deleteButton->setText(tr("Delete")); | 126 | deleteButton->setText(tr("Delete")); |
126 | 127 | ||
127 | 128 | ||
128 | 129 | ||
129 | connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), | 130 | connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), |
130 | this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); | 131 | this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); |
131 | 132 | ||
132 | connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); | 133 | connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); |
133 | 134 | ||
134 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); | 135 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); |
135 | 136 | ||
136 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); | 137 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); |
137 | 138 | ||
138 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); | 139 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); |
139 | connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton())); | 140 | connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton())); |
140 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); | 141 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); |
141 | 142 | ||
142 | populateBox(); | 143 | populateBox(); |
143 | load(); | 144 | load(); |
144 | setCaption("Notes"); | 145 | setCaption("Notes"); |
145 | // parent->setFocus(); | 146 | // parent->setFocus(); |
146 | } | 147 | } |
147 | 148 | ||
148 | void NotesControl::slotSaveButton() { | 149 | void NotesControl::slotSaveButton() { |
149 | slotNewButton(); | 150 | slotNewButton(); |
150 | populateBox(); | 151 | populateBox(); |
151 | } | 152 | } |
152 | 153 | ||
153 | void NotesControl::slotDeleteButtonClicked() { | 154 | void NotesControl::slotDeleteButtonClicked() { |
154 | switch ( QMessageBox::warning(this,tr("Delete?") | 155 | switch ( QMessageBox::warning(this,tr("Delete?") |
155 | ,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 ?") |
156 | ,tr("Yes"),tr("No"),0,1,1) ) { | 157 | ,tr("Yes"),tr("No"),0,1,1) ) { |
157 | case 0: | 158 | case 0: |
158 | slotDeleteButton(); | 159 | slotDeleteButton(); |
159 | break; | 160 | break; |
160 | }; | 161 | }; |
161 | } | 162 | } |
162 | 163 | ||
163 | void NotesControl::slotDeleteButton() { | 164 | void NotesControl::slotDeleteButton() { |
164 | 165 | ||
165 | QString selectedText = box->currentText(); | 166 | QString selectedText = box->currentText(); |
166 | qDebug("deleting "+selectedText); | 167 | qDebug("deleting "+selectedText); |
167 | 168 | ||
168 | if( !selectedText.isEmpty()) { | 169 | if( !selectedText.isEmpty()) { |
169 | 170 | ||
170 | Config cfg("Notes"); | 171 | Config cfg("Notes"); |
171 | cfg.setGroup("Docs"); | 172 | cfg.setGroup("Docs"); |
172 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 173 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
173 | QString entryName, entryName2;; | 174 | QString entryName, entryName2;; |
174 | for ( int i = 0; i < noOfFiles; i++ ) { | 175 | for ( int i = 0; i < noOfFiles; i++ ) { |
175 | entryName.sprintf( "File%i", i + 1 ); | 176 | entryName.sprintf( "File%i", i + 1 ); |
176 | if(selectedText == cfg.readEntry( entryName )) { | 177 | if(selectedText == cfg.readEntry( entryName )) { |
177 | qDebug("removing %s, %d", selectedText.latin1(), i); | 178 | qDebug("removing %s, %d", selectedText.latin1(), i); |
178 | for ( int j = i; j < noOfFiles; j++ ) { | 179 | for ( int j = i; j < noOfFiles; j++ ) { |
179 | entryName.sprintf( "File%i", i + 1 ); | 180 | entryName.sprintf( "File%i", i + 1 ); |
180 | entryName2.sprintf( "File%i", i + 2 ); | 181 | entryName2.sprintf( "File%i", i + 2 ); |
181 | QString temp = cfg.readEntry(entryName2); | 182 | QString temp = cfg.readEntry(entryName2); |
182 | qDebug("move "+temp); | 183 | qDebug("move "+temp); |
183 | cfg.writeEntry(entryName, temp); | 184 | cfg.writeEntry(entryName, temp); |
184 | i++; | 185 | i++; |
185 | } | 186 | } |
186 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); | 187 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); |
187 | entryName.sprintf( "File%i", noOfFiles ); | 188 | entryName.sprintf( "File%i", noOfFiles ); |
188 | cfg.removeEntry(entryName); | 189 | cfg.removeEntry(entryName); |
189 | cfg.write(); | 190 | cfg.write(); |
190 | DocLnk nf(selectedText); | 191 | DocLnk nf(selectedText); |
191 | nf.removeFiles(); | 192 | nf.removeFiles(); |
192 | QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; | 193 | QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; |
193 | qDebug(fi); | 194 | qDebug(fi); |
194 | 195 | ||
195 | QFile f( fi); | 196 | QFile f( fi); |
196 | if( !f.remove()) qDebug(".desktop file not removed"); | 197 | if( !f.remove()) qDebug(".desktop file not removed"); |
197 | 198 | ||
198 | } | 199 | } |
199 | } | 200 | } |
200 | view->clear(); | 201 | view->clear(); |
201 | 202 | ||
202 | populateBox(); | 203 | populateBox(); |
203 | } | 204 | } |
204 | } | 205 | } |
205 | 206 | ||
206 | void NotesControl::slotNewButton() { | 207 | void NotesControl::slotNewButton() { |
207 | if(edited) save(); | 208 | if(edited) save(); |
208 | view->clear(); | 209 | view->clear(); |
209 | view->setFocus(); | 210 | view->setFocus(); |
210 | edited=false; | 211 | edited=false; |
211 | isNew=false; | 212 | isNew=false; |
212 | } | 213 | } |
213 | 214 | ||
@@ -277,228 +278,237 @@ void NotesControl::focusOutEvent ( QFocusEvent * e) { | |||
277 | QWidget::focusOutEvent(e); | 278 | QWidget::focusOutEvent(e); |
278 | } | 279 | } |
279 | 280 | ||
280 | void NotesControl::save() { | 281 | void NotesControl::save() { |
281 | Config cfg("Notes"); | 282 | Config cfg("Notes"); |
282 | cfg.setGroup("Docs"); | 283 | cfg.setGroup("Docs"); |
283 | if( edited) { | 284 | if( edited) { |
284 | // qDebug("is edited"); | 285 | // qDebug("is edited"); |
285 | QString rt = view->text(); | 286 | QString rt = view->text(); |
286 | if( rt.length()>1) { | 287 | if( rt.length()>1) { |
287 | QString pt = rt.simplifyWhiteSpace(); | 288 | QString pt = rt.simplifyWhiteSpace(); |
288 | int i = pt.find( ' ', pt.find( ' ' )+2 ); | 289 | int i = pt.find( ' ', pt.find( ' ' )+2 ); |
289 | QString docname = pt; | 290 | QString docname = pt; |
290 | if ( i > 0 ) | 291 | if ( i > 0 ) |
291 | docname = pt.left(i); | 292 | docname = pt.left(i); |
292 | // remove "." at the beginning | 293 | // remove "." at the beginning |
293 | while( docname.startsWith( "." ) ) | 294 | while( docname.startsWith( "." ) ) |
294 | docname = docname.mid( 1 ); | 295 | docname = docname.mid( 1 ); |
295 | docname.replace( QRegExp("/"), "_" ); | 296 | docname.replace( QRegExp("/"), "_" ); |
296 | // cut the length. filenames longer than that don't make sense | 297 | // cut the length. filenames longer than that don't make sense |
297 | // and something goes wrong when they get too long. | 298 | // and something goes wrong when they get too long. |
298 | if ( docname.length() > 40 ) | 299 | if ( docname.length() > 40 ) |
299 | docname = docname.left(40); | 300 | docname = docname.left(40); |
300 | if ( docname.isEmpty() ) | 301 | if ( docname.isEmpty() ) |
301 | docname = "Empty Text"; | 302 | docname = "Empty Text"; |
302 | // qDebug(docname); | 303 | // qDebug(docname); |
303 | 304 | ||
304 | if( oldDocName != docname) { | 305 | if( oldDocName != docname) { |
305 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 306 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
306 | QString entryName; | 307 | QString entryName; |
307 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 308 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
308 | cfg.writeEntry( entryName,docname ); | 309 | cfg.writeEntry( entryName,docname ); |
309 | cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); | 310 | cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); |
310 | cfg.write(); | 311 | cfg.write(); |
311 | } | 312 | } |
312 | // else | 313 | // else |
313 | // qDebug("oldname equals docname"); | 314 | // qDebug("oldname equals docname"); |
314 | 315 | ||
315 | doc = new DocLnk(docname); | 316 | doc = new DocLnk(docname); |
316 | if(QFile(doc->linkFile()).exists()) | 317 | if(QFile(doc->linkFile()).exists()) |
317 | qDebug("puppie"); | 318 | qDebug("puppie"); |
318 | doc->setType("text/plain"); | 319 | doc->setType("text/plain"); |
319 | doc->setName(docname); | 320 | doc->setName(docname); |
320 | QString temp = docname.replace( QRegExp(" "), "_" ); | 321 | QString temp = docname.replace( QRegExp(" "), "_" ); |
321 | doc->setFile( QDir::homeDirPath()+"/notes/"+temp); | 322 | doc->setFile( QDir::homeDirPath()+"/notes/"+temp); |
322 | FileManager fm; | 323 | FileManager fm; |
323 | if ( !fm.saveFile( *doc, rt ) ) { | 324 | if ( !fm.saveFile( *doc, rt ) ) { |
324 | } | 325 | } |
325 | 326 | ||
326 | oldDocName=docname; | 327 | oldDocName=docname; |
327 | edited=false; | 328 | edited=false; |
328 | // qDebug("save"); | 329 | // qDebug("save"); |
329 | if (doPopulate) | 330 | if (doPopulate) |
330 | populateBox(); | 331 | populateBox(); |
331 | } | 332 | } |
332 | cfg.writeEntry( "LastDoc",oldDocName ); | 333 | cfg.writeEntry( "LastDoc",oldDocName ); |
333 | cfg.write(); | 334 | cfg.write(); |
334 | 335 | ||
335 | } | 336 | } |
336 | } | 337 | } |
337 | 338 | ||
338 | void NotesControl::populateBox() { | 339 | void NotesControl::populateBox() { |
339 | box->clear(); | 340 | box->clear(); |
340 | // qDebug("populate"); | 341 | // qDebug("populate"); |
341 | Config cfg("Notes"); | 342 | Config cfg("Notes"); |
342 | cfg.setGroup("Docs"); | 343 | cfg.setGroup("Docs"); |
343 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 344 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
344 | QStringList list; | 345 | QStringList list; |
345 | QString entryName; | 346 | QString entryName; |
346 | for ( int i = 0; i < noOfFiles; i++ ) { | 347 | for ( int i = 0; i < noOfFiles; i++ ) { |
347 | entryName.sprintf( "File%i", i + 1 ); | 348 | entryName.sprintf( "File%i", i + 1 ); |
348 | list.append(cfg.readEntry( entryName )); | 349 | list.append(cfg.readEntry( entryName )); |
349 | } | 350 | } |
350 | list.sort(); | 351 | list.sort(); |
351 | box->insertStringList(list,-1); | 352 | box->insertStringList(list,-1); |
352 | doPopulate=false; | 353 | doPopulate=false; |
353 | update(); | 354 | update(); |
354 | } | 355 | } |
355 | 356 | ||
356 | void NotesControl::load() { | 357 | void NotesControl::load() { |
357 | 358 | ||
358 | if(!loaded) { | 359 | if(!loaded) { |
359 | Config cfg("Notes"); | 360 | Config cfg("Notes"); |
360 | cfg.setGroup("Docs"); | 361 | cfg.setGroup("Docs"); |
361 | QString lastDoc=cfg.readEntry( "LastDoc","notes"); | 362 | QString lastDoc=cfg.readEntry( "LastDoc","notes"); |
362 | DocLnk nf; | 363 | DocLnk nf; |
363 | nf.setType("text/plain"); | 364 | nf.setType("text/plain"); |
364 | nf.setFile(lastDoc); | 365 | nf.setFile(lastDoc); |
365 | 366 | ||
366 | loadDoc(nf); | 367 | loadDoc(nf); |
367 | loaded=true; | 368 | loaded=true; |
368 | oldDocName=lastDoc; | 369 | oldDocName=lastDoc; |
369 | cfg.writeEntry( "LastDoc",oldDocName ); | 370 | cfg.writeEntry( "LastDoc",oldDocName ); |
370 | cfg.write(); | 371 | cfg.write(); |
371 | } | 372 | } |
372 | } | 373 | } |
373 | 374 | ||
374 | void NotesControl::load(const QString & file) { | 375 | void NotesControl::load(const QString & file) { |
375 | qDebug("loading "+file); | 376 | qDebug("loading "+file); |
376 | QString name = file; | 377 | QString name = file; |
377 | QString temp; | 378 | QString temp; |
378 | if( !QFile( QDir::homeDirPath()+"/"+file).exists() ) | 379 | if( !QFile( QDir::homeDirPath()+"/"+file).exists() ) |
379 | temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" ); | 380 | temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" ); |
380 | else | 381 | else |
381 | temp = name; | 382 | temp = name; |
382 | if(!loaded) { | 383 | if(!loaded) { |
383 | DocLnk nf; | 384 | DocLnk nf; |
384 | nf.setType("text/plain"); | 385 | nf.setType("text/plain"); |
385 | nf.setFile( temp); | 386 | nf.setFile( temp); |
386 | if(!temp.isEmpty()) | 387 | if(!temp.isEmpty()) |
387 | loadDoc(nf); | 388 | loadDoc(nf); |
388 | loaded=true; | 389 | loaded=true; |
389 | } | 390 | } |
390 | // view->setFocus(); | 391 | // view->setFocus(); |
391 | oldDocName=file; | 392 | oldDocName=file; |
392 | Config cfg("Notes"); | 393 | Config cfg("Notes"); |
393 | cfg.setGroup("Docs"); | 394 | cfg.setGroup("Docs"); |
394 | cfg.writeEntry( "LastDoc",oldDocName ); | 395 | cfg.writeEntry( "LastDoc",oldDocName ); |
395 | cfg.write(); | 396 | cfg.write(); |
396 | } | 397 | } |
397 | 398 | ||
398 | void NotesControl::loadDoc( const DocLnk &f) { | 399 | void NotesControl::loadDoc( const DocLnk &f) { |
399 | FileManager fm; | 400 | FileManager fm; |
400 | QString txt; | 401 | QString txt; |
401 | if ( !fm.loadFile( f, txt ) ) { | 402 | if ( !fm.loadFile( f, txt ) ) { |
402 | qDebug("could not load file "+f.file()); | 403 | qDebug("could not load file "+f.file()); |
403 | return; | 404 | return; |
404 | } | 405 | } |
405 | view->setText(txt); | 406 | view->setText(txt); |
406 | } | 407 | } |
407 | 408 | ||
408 | void NotesControl::slotViewEdited() { | 409 | void NotesControl::slotViewEdited() { |
409 | if(loaded) { | 410 | if(loaded) { |
410 | edited=true; | 411 | edited=true; |
411 | } | 412 | } |
412 | } | 413 | } |
413 | 414 | ||
414 | 415 | ||
415 | void NotesControl::slotShowMax() { | 416 | void NotesControl::slotShowMax() { |
416 | Config cfg("Notes"); | 417 | Config cfg("Notes"); |
417 | cfg.setGroup("Options"); | 418 | cfg.setGroup("Options"); |
418 | showMax=!showMax; | 419 | showMax=!showMax; |
419 | cfg.writeEntry("ShowMax", showMax); | 420 | cfg.writeEntry("ShowMax", showMax); |
420 | cfg.write(); | 421 | cfg.write(); |
421 | hide(); | 422 | hide(); |
422 | } | 423 | } |
423 | 424 | ||
424 | void NotesControl::slotSearch() { | 425 | void NotesControl::slotSearch() { |
425 | int boxCount = box->count(); | 426 | int boxCount = box->count(); |
426 | for(int i=0;i< boxCount;i++) { | 427 | for(int i=0;i< boxCount;i++) { |
427 | 428 | ||
428 | } | 429 | } |
429 | } | 430 | } |
430 | 431 | ||
431 | // void NotesControl::keyReleaseEvent( QKeyEvent *e) { | 432 | // void NotesControl::keyReleaseEvent( QKeyEvent *e) { |
432 | 433 | ||
433 | // switch ( e->state() ) { | 434 | // switch ( e->state() ) { |
434 | // case ControlButton: | 435 | // case ControlButton: |
435 | // if(e->key() == Key_C) { //copy | 436 | // if(e->key() == Key_C) { //copy |
436 | // qDebug("copy"); | 437 | // qDebug("copy"); |
437 | // QClipboard *cb = QApplication::clipboard(); | 438 | // QClipboard *cb = QApplication::clipboard(); |
438 | // QString text; | 439 | // QString text; |
439 | 440 | ||
440 | // // Copy text from the clipboard (paste) | 441 | // // Copy text from the clipboard (paste) |
441 | // text = cb->text(); | 442 | // text = cb->text(); |
442 | // } | 443 | // } |
443 | // if(e->key() == Key_X) { //cut | 444 | // if(e->key() == Key_X) { //cut |
444 | // } | 445 | // } |
445 | // if(e->key() == Key_V) { //paste | 446 | // if(e->key() == Key_V) { //paste |
446 | // QClipboard *cb = QApplication::clipboard(); | 447 | // QClipboard *cb = QApplication::clipboard(); |
447 | // QString text; | 448 | // QString text; |
448 | // //view | 449 | // //view |
449 | // cb->setText(); | 450 | // cb->setText(); |
450 | // } | 451 | // } |
451 | // break; | 452 | // break; |
452 | // }; | 453 | // }; |
453 | // QWidget::keyReleaseEvent(e); | 454 | // QWidget::keyReleaseEvent(e); |
454 | // } | 455 | // } |
455 | 456 | ||
456 | //=========================================================================== | 457 | //=========================================================================== |
457 | 458 | ||
458 | NotesApplet::NotesApplet( QWidget *parent, const char *name ) | 459 | NotesApplet::NotesApplet( QWidget *parent, const char *name ) |
459 | : QWidget( parent, name ) { | 460 | : QWidget( parent, name ) { |
460 | setFixedHeight( 18 ); | 461 | setFixedHeight( 18 ); |
461 | setFixedWidth( 14 ); | 462 | setFixedWidth( 14 ); |
462 | vc = new NotesControl; | 463 | vc = new NotesControl; |
463 | } | 464 | } |
464 | 465 | ||
465 | NotesApplet::~NotesApplet() { | 466 | NotesApplet::~NotesApplet() { |
466 | delete vc; | 467 | delete vc; |
467 | } | 468 | } |
468 | 469 | ||
470 | int NotesApplet::position() | ||
471 | { | ||
472 | return 6; | ||
473 | } | ||
474 | |||
469 | void NotesApplet::mousePressEvent( QMouseEvent *) { | 475 | void NotesApplet::mousePressEvent( QMouseEvent *) { |
470 | if( !vc->isHidden()) { | 476 | if( !vc->isHidden()) { |
471 | vc->doPopulate=false; | 477 | vc->doPopulate=false; |
472 | vc->save(); | 478 | vc->save(); |
473 | vc->close(); | 479 | vc->close(); |
474 | } else { | 480 | } else { |
475 | // vc = new NotesControl; | 481 | // vc = new NotesControl; |
476 | // QPoint curPos = mapToGlobal( rect().topLeft() ); | 482 | // QPoint curPos = mapToGlobal( rect().topLeft() ); |
477 | if(vc->showMax) { | 483 | if(vc->showMax) { |
478 | qDebug("show max"); | 484 | qDebug("show max"); |
479 | vc->showMaximized(); | 485 | vc->showMaximized(); |
480 | } else { | 486 | } else { |
481 | qDebug("no show max"); | 487 | qDebug("no show max"); |
482 | QWidget *wid = QPEApplication::desktop(); | 488 | QWidget *wid = QPEApplication::desktop(); |
483 | QRect rect = QApplication::desktop()->geometry(); | 489 | QRect rect = QApplication::desktop()->geometry(); |
484 | vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180); | 490 | vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180); |
485 | vc->move ( (rect.center()/2) - (vc->rect().center()/2)); | 491 | vc->move ( (rect.center()/2) - (vc->rect().center()/2)); |
486 | // vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28); | 492 | // vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28); |
487 | } | 493 | } |
488 | vc->show(); | 494 | vc->show(); |
489 | vc->doPopulate=true; | 495 | vc->doPopulate=true; |
490 | vc->populateBox(); | 496 | vc->populateBox(); |
491 | vc->doPopulate=false; | 497 | vc->doPopulate=false; |
492 | vc->loaded=false; | 498 | vc->loaded=false; |
493 | 499 | ||
494 | vc->load(); | 500 | vc->load(); |
495 | // this->setFocus(); | 501 | // this->setFocus(); |
496 | vc->view->setFocus(); | 502 | vc->view->setFocus(); |
497 | } | 503 | } |
498 | } | 504 | } |
499 | 505 | ||
500 | void NotesApplet::paintEvent( QPaintEvent* ) { | 506 | void NotesApplet::paintEvent( QPaintEvent* ) { |
501 | QPainter p(this); | 507 | QPainter p(this); |
502 | p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); | 508 | p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); |
503 | } | 509 | } |
504 | 510 | ||
511 | Q_EXPORT_INTERFACE() | ||
512 | { | ||
513 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<NotesApplet> ); | ||
514 | } | ||
diff --git a/noncore/applets/notesapplet/notes.h b/noncore/applets/notesapplet/notes.h index 08253cb..ed1f98c 100644 --- a/noncore/applets/notesapplet/notes.h +++ b/noncore/applets/notesapplet/notes.h | |||
@@ -1,93 +1,94 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com | 2 | ** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com |
3 | ** All rights reserved. | 3 | ** All rights reserved. |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | **********************************************************************/ | 13 | **********************************************************************/ |
14 | 14 | ||
15 | #ifndef __NOTES_APPLET_H__ | 15 | #ifndef __NOTES_APPLET_H__ |
16 | #define __NOTES_APPLET_H__ | 16 | #define __NOTES_APPLET_H__ |
17 | 17 | ||
18 | #include <qwidget.h> | 18 | #include <qwidget.h> |
19 | #include <qvbox.h> | 19 | #include <qvbox.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | #include <qguardedptr.h> | 21 | #include <qguardedptr.h> |
22 | #include <qtimer.h> | 22 | #include <qtimer.h> |
23 | #include <qpe/filemanager.h> | 23 | #include <qpe/filemanager.h> |
24 | #include <qpe/ir.h> | 24 | #include <qpe/ir.h> |
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | 26 | ||
27 | class QComboBox; | 27 | class QComboBox; |
28 | class QCheckBox; | 28 | class QCheckBox; |
29 | class QSpinBox; | 29 | class QSpinBox; |
30 | class QPushButton; | 30 | class QPushButton; |
31 | class QMultiLineEdit; | 31 | class QMultiLineEdit; |
32 | class QListBox; | 32 | class QListBox; |
33 | class QListBoxItem; | 33 | class QListBoxItem; |
34 | class NotesControl : public QVBox { | 34 | class NotesControl : public QVBox { |
35 | Q_OBJECT | 35 | Q_OBJECT |
36 | public: | 36 | public: |
37 | NotesControl( QWidget *parent=0, const char *name=0 ); | 37 | NotesControl( QWidget *parent=0, const char *name=0 ); |
38 | 38 | ||
39 | QPixmap notes; | 39 | QPixmap notes; |
40 | QMultiLineEdit *view; | 40 | QMultiLineEdit *view; |
41 | QListBox *box; | 41 | QListBox *box; |
42 | QPushButton *saveButton, *deleteButton, *newButton; | 42 | QPushButton *saveButton, *deleteButton, *newButton; |
43 | QString FileNamePath; | 43 | QString FileNamePath; |
44 | bool loaded, edited, doPopulate, isNew; | 44 | bool loaded, edited, doPopulate, isNew; |
45 | bool showMax; | 45 | bool showMax; |
46 | void save(); | 46 | void save(); |
47 | void populateBox(); | 47 | void populateBox(); |
48 | void load(); | 48 | void load(); |
49 | 49 | ||
50 | private: | 50 | private: |
51 | QTimer menuTimer; | 51 | QTimer menuTimer; |
52 | DocLnk *doc; | 52 | DocLnk *doc; |
53 | QString oldDocName; | 53 | QString oldDocName; |
54 | void focusOutEvent( QFocusEvent * ); | 54 | void focusOutEvent( QFocusEvent * ); |
55 | void load(const QString&); | 55 | void load(const QString&); |
56 | private slots: | 56 | private slots: |
57 | void slotSearch(); | 57 | void slotSearch(); |
58 | void slotShowMax(); | 58 | void slotShowMax(); |
59 | void slotBeamButton(); | 59 | void slotBeamButton(); |
60 | void slotBeamFinished( Ir*); | 60 | void slotBeamFinished( Ir*); |
61 | void slotDeleteButton(); | 61 | void slotDeleteButton(); |
62 | void slotSaveButton(); | 62 | void slotSaveButton(); |
63 | void slotDeleteButtonClicked(); | 63 | void slotDeleteButtonClicked(); |
64 | void slotNewButton(); | 64 | void slotNewButton(); |
65 | void boxPressed(int, QListBoxItem *, const QPoint&); | 65 | void boxPressed(int, QListBoxItem *, const QPoint&); |
66 | void showMenu(); | 66 | void showMenu(); |
67 | void loadDoc( const DocLnk &); | 67 | void loadDoc( const DocLnk &); |
68 | void slotViewEdited(); | 68 | void slotViewEdited(); |
69 | void slotBoxSelected(const QString &); | 69 | void slotBoxSelected(const QString &); |
70 | // void keyReleaseEvent( QKeyEvent *); | 70 | // void keyReleaseEvent( QKeyEvent *); |
71 | 71 | ||
72 | }; | 72 | }; |
73 | 73 | ||
74 | class NotesApplet : public QWidget { | 74 | class NotesApplet : public QWidget { |
75 | Q_OBJECT | 75 | Q_OBJECT |
76 | public: | 76 | public: |
77 | NotesApplet( QWidget *parent = 0, const char *name=0 ); | 77 | NotesApplet( QWidget *parent = 0, const char *name=0 ); |
78 | ~NotesApplet(); | 78 | ~NotesApplet(); |
79 | static int position(); | ||
79 | NotesControl *vc; | 80 | NotesControl *vc; |
80 | public slots: | 81 | public slots: |
81 | private: | 82 | private: |
82 | void mousePressEvent( QMouseEvent * ); | 83 | void mousePressEvent( QMouseEvent * ); |
83 | void paintEvent( QPaintEvent* ); | 84 | void paintEvent( QPaintEvent* ); |
84 | 85 | ||
85 | private: | 86 | private: |
86 | QPixmap notesPixmap; | 87 | QPixmap notesPixmap; |
87 | private slots: | 88 | private slots: |
88 | 89 | ||
89 | 90 | ||
90 | }; | 91 | }; |
91 | 92 | ||
92 | #endif // __NOTES_APPLET_H__ | 93 | #endif // __NOTES_APPLET_H__ |
93 | 94 | ||
diff --git a/noncore/applets/notesapplet/notesapplet.pro b/noncore/applets/notesapplet/notesapplet.pro index 3075948..38ba184 100644 --- a/noncore/applets/notesapplet/notesapplet.pro +++ b/noncore/applets/notesapplet/notesapplet.pro | |||
@@ -1,16 +1,12 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt plugin warn_on release | 2 | CONFIG += qt plugin warn_on release |
3 | HEADERS = notes.h notesappletimpl.h | 3 | HEADERS = notes.h |
4 | SOURCES = notes.cpp notesappletimpl.cpp | 4 | SOURCES = notes.cpp |
5 | TARGET = notesapplet | 5 | TARGET = notesapplet |
6 | DESTDIR = $(OPIEDIR)/plugins/applets | 6 | DESTDIR = $(OPIEDIR)/plugins/applets |
7 | INCLUDEPATH += $(OPIEDIR)/include | 7 | INCLUDEPATH += $(OPIEDIR)/include |
8 | DEPENDPATH += $(OPIEDIR)/include | 8 | DEPENDPATH += $(OPIEDIR)/include |
9 | LIBS += -lqpe | 9 | LIBS += -lqpe |
10 | VERSION = 1.0.0 | 10 | VERSION = 1.0.0 |
11 | MOC_DIR=opieobj | ||
12 | OBJECTS_DIR=opieobj | ||
13 | |||
14 | |||
15 | 11 | ||
16 | include ( $(OPIEDIR)/include.pro ) | 12 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/applets/notesapplet/notesappletimpl.cpp b/noncore/applets/notesapplet/notesappletimpl.cpp deleted file mode 100644 index 8a9da7f..0000000 --- a/noncore/applets/notesapplet/notesappletimpl.cpp +++ b/dev/null | |||
@@ -1,53 +0,0 @@ | |||
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 | |||
16 | NotesAppletImpl::NotesAppletImpl() | ||
17 | : notes(0){ | ||
18 | } | ||
19 | |||
20 | NotesAppletImpl::~NotesAppletImpl() { | ||
21 | // not needed though cause we should have a valid parent | ||
22 | delete notes; | ||
23 | } | ||
24 | |||
25 | QWidget *NotesAppletImpl::applet( QWidget *parent ) { | ||
26 | if ( !notes ) | ||
27 | notes = new NotesApplet( parent ); | ||
28 | return notes; | ||
29 | } | ||
30 | |||
31 | int NotesAppletImpl::position() const { | ||
32 | return 6; | ||
33 | } | ||
34 | |||
35 | QRESULT NotesAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { | ||
36 | *iface = 0; | ||
37 | if ( uuid == IID_QUnknown ) | ||
38 | *iface = this; | ||
39 | else if ( uuid == IID_TaskbarApplet ) | ||
40 | *iface = this; | ||
41 | else | ||
42 | return QS_FALSE; | ||
43 | |||
44 | if ( *iface ) | ||
45 | (*iface)->addRef(); | ||
46 | return QS_OK; | ||
47 | } | ||
48 | |||
49 | Q_EXPORT_INTERFACE() { | ||
50 | Q_CREATE_INSTANCE( NotesAppletImpl ) | ||
51 | } | ||
52 | |||
53 | |||
diff --git a/noncore/applets/notesapplet/notesappletimpl.h b/noncore/applets/notesapplet/notesappletimpl.h deleted file mode 100644 index a87118c..0000000 --- a/noncore/applets/notesapplet/notesappletimpl.h +++ b/dev/null | |||
@@ -1,35 +0,0 @@ | |||
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 | |||
17 | class NotesApplet; | ||
18 | |||
19 | class NotesAppletImpl : public TaskbarAppletInterface | ||
20 | { | ||
21 | public: | ||
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 | |||
31 | private: | ||
32 | NotesApplet *notes; | ||
33 | }; | ||
34 | |||
35 | #endif | ||
diff --git a/noncore/applets/zkbapplet/.cvsignore b/noncore/applets/zkbapplet/.cvsignore new file mode 100644 index 0000000..0f79c04 --- a/dev/null +++ b/noncore/applets/zkbapplet/.cvsignore | |||
@@ -0,0 +1,6 @@ | |||
1 | Makefile* | ||
2 | advancedconfigbase.cpp | ||
3 | advancedconfigbase.h | ||
4 | moc_* | ||
5 | .moc | ||
6 | .obj | ||
diff --git a/noncore/applets/zkbapplet/zkbapplet.cpp b/noncore/applets/zkbapplet/zkbapplet.cpp deleted file mode 100644 index 6c71568..0000000 --- a/noncore/applets/zkbapplet/zkbapplet.cpp +++ b/dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <qlabel.h> | ||
3 | #include <qbutton.h> | ||
4 | #include <qwindowsystem_qws.h> | ||
5 | #include "zkbapplet.h" | ||
6 | #include "zkbwidget.h" | ||
7 | |||
8 | |||
9 | ZkbApplet::ZkbApplet() : app(0){ | ||
10 | } | ||
11 | |||
12 | ZkbApplet::~ZkbApplet() | ||
13 | { | ||
14 | if (app) delete app; | ||
15 | } | ||
16 | |||
17 | QWidget* ZkbApplet::applet(QWidget* parent) { | ||
18 | if (app == 0) { | ||
19 | app = new ZkbWidget(parent); | ||
20 | } | ||
21 | |||
22 | return app; | ||
23 | } | ||
24 | |||
25 | int ZkbApplet::position() const { | ||
26 | return 8; | ||
27 | } | ||
28 | |||
29 | QRESULT ZkbApplet::queryInterface(const QUuid& uuid, QUnknownInterface** iface) { | ||
30 | |||
31 | *iface = 0; | ||
32 | if (uuid == IID_QUnknown) { | ||
33 | *iface = this; | ||
34 | } else if (uuid == IID_TaskbarApplet) { | ||
35 | *iface = this; | ||
36 | } else { | ||
37 | return QS_FALSE; | ||
38 | } | ||
39 | |||
40 | if (*iface) { | ||
41 | (*iface)->addRef(); | ||
42 | } | ||
43 | |||
44 | return QS_OK; | ||
45 | } | ||
46 | |||
47 | Q_EXPORT_INTERFACE() { | ||
48 | Q_CREATE_INSTANCE(ZkbApplet) | ||
49 | } | ||
diff --git a/noncore/applets/zkbapplet/zkbapplet.h b/noncore/applets/zkbapplet/zkbapplet.h deleted file mode 100644 index fcf03b5..0000000 --- a/noncore/applets/zkbapplet/zkbapplet.h +++ b/dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | #include "qpe/taskbarappletinterface.h" | ||
2 | |||
3 | #ifndef ZKBAPPLET_H | ||
4 | #define ZKBAPPLET_H | ||
5 | |||
6 | class ZkbWidget; | ||
7 | |||
8 | class ZkbApplet : public TaskbarAppletInterface { | ||
9 | public: | ||
10 | ZkbApplet(); | ||
11 | virtual ~ZkbApplet(); | ||
12 | |||
13 | QRESULT queryInterface(const QUuid&, QUnknownInterface**); | ||
14 | Q_REFCOUNT | ||
15 | |||
16 | virtual QWidget* applet(QWidget*); | ||
17 | virtual int position() const; | ||
18 | |||
19 | protected: | ||
20 | ZkbWidget* app; | ||
21 | }; | ||
22 | |||
23 | #endif | ||
diff --git a/noncore/applets/zkbapplet/zkbapplet.pro b/noncore/applets/zkbapplet/zkbapplet.pro index 22615d0..8cc1b58 100644 --- a/noncore/applets/zkbapplet/zkbapplet.pro +++ b/noncore/applets/zkbapplet/zkbapplet.pro | |||
@@ -1,22 +1,20 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt plugin warn_on release | 2 | CONFIG += qt plugin warn_on release |
3 | HEADERS = zkbapplet.h\ | 3 | HEADERS = zkbwidget.h \ |
4 | zkbwidget.h \ | ||
5 | ../../apps/keyz-cfg/zkbcfg.h \ | 4 | ../../apps/keyz-cfg/zkbcfg.h \ |
6 | ../../apps/keyz-cfg/zkbnames.h \ | 5 | ../../apps/keyz-cfg/zkbnames.h \ |
7 | ../../apps/keyz-cfg/zkbxml.h \ | 6 | ../../apps/keyz-cfg/zkbxml.h \ |
8 | ../../apps/keyz-cfg/zkb.h | 7 | ../../apps/keyz-cfg/zkb.h |
9 | SOURCES = zkbapplet.cpp \ | 8 | SOURCES = zkbwidget.cpp \ |
10 | zkbwidget.cpp \ | ||
11 | ../../apps/keyz-cfg/zkbcfg.cpp \ | 9 | ../../apps/keyz-cfg/zkbcfg.cpp \ |
12 | ../../apps/keyz-cfg/zkbnames.cpp \ | 10 | ../../apps/keyz-cfg/zkbnames.cpp \ |
13 | ../../apps/keyz-cfg/zkbxml.cpp \ | 11 | ../../apps/keyz-cfg/zkbxml.cpp \ |
14 | ../../apps/keyz-cfg/zkb.cpp | 12 | ../../apps/keyz-cfg/zkb.cpp |
15 | TARGET = zkbapplet | 13 | TARGET = zkbapplet |
16 | DESTDIR = $(OPIEDIR)/plugins/applets | 14 | DESTDIR = $(OPIEDIR)/plugins/applets |
17 | INCLUDEPATH += $(OPIEDIR)/include ../../apps/keyz-cfg | 15 | INCLUDEPATH += $(OPIEDIR)/include ../../apps/keyz-cfg |
18 | DEPENDPATH += ../$(OPIEDIR)/include | 16 | DEPENDPATH += ../$(OPIEDIR)/include |
19 | VERSION = 0.6.0 | 17 | VERSION = 0.6.0 |
20 | LIBS += -lqpe | 18 | LIBS += -lqpe |
21 | 19 | ||
22 | include ( $(OPIEDIR)/include.pro ) | 20 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/applets/zkbapplet/zkbwidget.cpp b/noncore/applets/zkbapplet/zkbwidget.cpp index 05a76e7..0b5ab78 100644 --- a/noncore/applets/zkbapplet/zkbwidget.cpp +++ b/noncore/applets/zkbapplet/zkbwidget.cpp | |||
@@ -1,150 +1,162 @@ | |||
1 | #include <opie2/otaskbarapplet.h> | ||
1 | #include <qpe/qcopenvelope_qws.h> | 2 | #include <qpe/qcopenvelope_qws.h> |
2 | #include <qpe/applnk.h> | 3 | #include <qpe/applnk.h> |
3 | #include <qpe/qpeapplication.h> | 4 | #include <qpe/qpeapplication.h> |
4 | #include <qpe/resource.h> | 5 | #include <qpe/resource.h> |
5 | #include <stdio.h> | 6 | #include <stdio.h> |
6 | #include <unistd.h> | 7 | #include <unistd.h> |
7 | #include "zkbwidget.h" | 8 | #include "zkbwidget.h" |
8 | #include "zkbcfg.h" | 9 | #include "zkbcfg.h" |
9 | 10 | ||
10 | ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), | 11 | ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), |
11 | disabled(Resource::loadPixmap("zkb-disabled")) { | 12 | disabled(Resource::loadPixmap("zkb-disabled")) { |
12 | 13 | ||
13 | labels = new QPopupMenu(); | 14 | labels = new QPopupMenu(); |
14 | connect(labels, SIGNAL(activated(int)), this, | 15 | connect(labels, SIGNAL(activated(int)), this, |
15 | SLOT(labelChanged(int))); | 16 | SLOT(labelChanged(int))); |
16 | 17 | ||
17 | loadKeymap(); | 18 | loadKeymap(); |
18 | 19 | ||
19 | channel = new QCopChannel("QPE/zkb", this); | 20 | channel = new QCopChannel("QPE/zkb", this); |
20 | connect(channel, SIGNAL(received(const QCString&, const QByteArray&)), | 21 | connect(channel, SIGNAL(received(const QCString&, const QByteArray&)), |
21 | this, SLOT(signalReceived(const QCString&, const QByteArray&))); | 22 | this, SLOT(signalReceived(const QCString&, const QByteArray&))); |
22 | setFixedWidth ( AppLnk::smallIconSize() ); | 23 | setFixedWidth ( AppLnk::smallIconSize() ); |
23 | setFixedHeight ( AppLnk::smallIconSize() ); | 24 | setFixedHeight ( AppLnk::smallIconSize() ); |
24 | } | 25 | } |
25 | 26 | ||
26 | ZkbWidget::~ZkbWidget() { | 27 | ZkbWidget::~ZkbWidget() { |
27 | } | 28 | } |
28 | 29 | ||
30 | int ZkbWidget::position() | ||
31 | { | ||
32 | return 8; | ||
33 | } | ||
34 | |||
29 | bool ZkbWidget::loadKeymap() { | 35 | bool ZkbWidget::loadKeymap() { |
30 | ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); | 36 | ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); |
31 | QFontMetrics fm(font()); | 37 | QFontMetrics fm(font()); |
32 | 38 | ||
33 | if (keymap != 0) { | 39 | if (keymap != 0) { |
34 | delete keymap; | 40 | delete keymap; |
35 | keymap = 0; | 41 | keymap = 0; |
36 | } | 42 | } |
37 | 43 | ||
38 | Keymap* km = new Keymap(); | 44 | Keymap* km = new Keymap(); |
39 | 45 | ||
40 | if (!c.load("zkb.xml", *km, "")) { | 46 | if (!c.load("zkb.xml", *km, "")) { |
41 | delete km; | 47 | delete km; |
42 | setPixmap(disabled); | 48 | setPixmap(disabled); |
43 | return false; | 49 | return false; |
44 | } | 50 | } |
45 | 51 | ||
46 | connect(km, SIGNAL(stateChanged(const QString&)), | 52 | connect(km, SIGNAL(stateChanged(const QString&)), |
47 | this, SLOT(stateChanged(const QString&))); | 53 | this, SLOT(stateChanged(const QString&))); |
48 | 54 | ||
49 | qwsServer->setKeyboardFilter(km); | 55 | qwsServer->setKeyboardFilter(km); |
50 | 56 | ||
51 | Keymap* oldkm = keymap; | 57 | Keymap* oldkm = keymap; |
52 | keymap = km; | 58 | keymap = km; |
53 | 59 | ||
54 | if (oldkm != 0) { | 60 | if (oldkm != 0) { |
55 | delete oldkm; | 61 | delete oldkm; |
56 | } | 62 | } |
57 | 63 | ||
58 | setText(keymap->getCurrentLabel()); | 64 | setText(keymap->getCurrentLabel()); |
59 | 65 | ||
60 | labels->clear(); | 66 | labels->clear(); |
61 | QStringList l = keymap->listLabels(); | 67 | QStringList l = keymap->listLabels(); |
62 | labels->insertItem(disabled, 0, 0); | 68 | labels->insertItem(disabled, 0, 0); |
63 | int n = 1; | 69 | int n = 1; |
64 | w = 0; | 70 | w = 0; |
65 | for(QStringList::Iterator it = l.begin(); it != l.end(); | 71 | for(QStringList::Iterator it = l.begin(); it != l.end(); |
66 | ++it, n++) { | 72 | ++it, n++) { |
67 | 73 | ||
68 | // printf("label: %s\n", (const char*) (*it).utf8()); | 74 | // printf("label: %s\n", (const char*) (*it).utf8()); |
69 | 75 | ||
70 | labels->insertItem(*it, n, n); | 76 | labels->insertItem(*it, n, n); |
71 | int lw = fm.width(*it); | 77 | int lw = fm.width(*it); |
72 | if (lw > w) { | 78 | if (lw > w) { |
73 | w = lw; | 79 | w = lw; |
74 | } | 80 | } |
75 | } | 81 | } |
76 | 82 | ||
77 | if (w == 0) { | 83 | if (w == 0) { |
78 | hide(); | 84 | hide(); |
79 | } else { | 85 | } else { |
80 | show(); | 86 | show(); |
81 | } | 87 | } |
82 | return true; | 88 | return true; |
83 | } | 89 | } |
84 | 90 | ||
85 | QSize ZkbWidget::sizeHint() const { | 91 | QSize ZkbWidget::sizeHint() const { |
86 | return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); | 92 | return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); |
87 | } | 93 | } |
88 | 94 | ||
89 | void ZkbWidget::stateChanged(const QString& s) { | 95 | void ZkbWidget::stateChanged(const QString& s) { |
90 | //qDebug("stateChanged: %s\n", (const char*) s.utf8()); | 96 | //qDebug("stateChanged: %s\n", (const char*) s.utf8()); |
91 | setText(s); | 97 | setText(s); |
92 | } | 98 | } |
93 | 99 | ||
94 | void ZkbWidget::labelChanged(int id) { | 100 | void ZkbWidget::labelChanged(int id) { |
95 | if (id == 0) { | 101 | if (id == 0) { |
96 | keymap->disable(); | 102 | keymap->disable(); |
97 | setPixmap(disabled); | 103 | setPixmap(disabled); |
98 | return; | 104 | return; |
99 | } | 105 | } |
100 | 106 | ||
101 | keymap->enable(); | 107 | keymap->enable(); |
102 | 108 | ||
103 | QStringList l = keymap->listLabels(); | 109 | QStringList l = keymap->listLabels(); |
104 | QString lbl = l[id-1]; | 110 | QString lbl = l[id-1]; |
105 | 111 | ||
106 | //printf("labelChanged: %s\n", (const char*) lbl.utf8()); | 112 | //printf("labelChanged: %s\n", (const char*) lbl.utf8()); |
107 | State* state = keymap->getStateByLabel(lbl); | 113 | State* state = keymap->getStateByLabel(lbl); |
108 | if (state != 0) { | 114 | if (state != 0) { |
109 | keymap->setCurrentState(state); | 115 | keymap->setCurrentState(state); |
110 | setText(lbl); | 116 | setText(lbl); |
111 | } | 117 | } |
112 | } | 118 | } |
113 | 119 | ||
114 | void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { | 120 | void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { |
115 | QSize sh = labels->sizeHint(); | 121 | QSize sh = labels->sizeHint(); |
116 | QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); | 122 | QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); |
117 | labels->exec(p); | 123 | labels->exec(p); |
118 | } | 124 | } |
119 | 125 | ||
120 | void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { | 126 | void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { |
121 | QDataStream stream(data, IO_ReadOnly); | 127 | QDataStream stream(data, IO_ReadOnly); |
122 | 128 | ||
123 | if (msg == "enable()") { | 129 | if (msg == "enable()") { |
124 | keymap->enable(); | 130 | keymap->enable(); |
125 | } else if (msg == "disable()") { | 131 | } else if (msg == "disable()") { |
126 | keymap->disable(); | 132 | keymap->disable(); |
127 | } else if (msg == "reload()") { | 133 | } else if (msg == "reload()") { |
128 | QCopEnvelope("QPE/System", "busy()"); | 134 | QCopEnvelope("QPE/System", "busy()"); |
129 | QTimer::singleShot(0, this, SLOT(reload())); | 135 | QTimer::singleShot(0, this, SLOT(reload())); |
130 | } else if (msg == "switch(QString)") { | 136 | } else if (msg == "switch(QString)") { |
131 | QString lbl; | 137 | QString lbl; |
132 | stream >> lbl; | 138 | stream >> lbl; |
133 | 139 | ||
134 | if (keymap != 0) { | 140 | if (keymap != 0) { |
135 | State* state = keymap->getStateByLabel(lbl); | 141 | State* state = keymap->getStateByLabel(lbl); |
136 | if (state != 0) { | 142 | if (state != 0) { |
137 | keymap->setCurrentState(state); | 143 | keymap->setCurrentState(state); |
138 | setText(lbl); | 144 | setText(lbl); |
139 | } | 145 | } |
140 | } | 146 | } |
141 | } else if (msg == "debug(QString)") { | 147 | } else if (msg == "debug(QString)") { |
142 | QString flag; | 148 | QString flag; |
143 | stream >> flag; | 149 | stream >> flag; |
144 | } | 150 | } |
145 | } | 151 | } |
146 | 152 | ||
147 | void ZkbWidget::reload() { | 153 | void ZkbWidget::reload() { |
148 | loadKeymap(); | 154 | loadKeymap(); |
149 | QCopEnvelope("QPE/System", "notBusy()"); | 155 | QCopEnvelope("QPE/System", "notBusy()"); |
150 | } | 156 | } |
157 | |||
158 | Q_EXPORT_INTERFACE() | ||
159 | { | ||
160 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<ZkbWidget> ); | ||
161 | } | ||
162 | |||
diff --git a/noncore/applets/zkbapplet/zkbwidget.h b/noncore/applets/zkbapplet/zkbwidget.h index a943563..7c67794 100644 --- a/noncore/applets/zkbapplet/zkbwidget.h +++ b/noncore/applets/zkbapplet/zkbwidget.h | |||
@@ -1,38 +1,39 @@ | |||
1 | #ifndef ZKBWIDGET_H | 1 | #ifndef ZKBWIDGET_H |
2 | #define ZKBWIDGET_H | 2 | #define ZKBWIDGET_H |
3 | 3 | ||
4 | #include <qwidget.h> | 4 | #include <qwidget.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <qpopupmenu.h> | 6 | #include <qpopupmenu.h> |
7 | #include <qpixmap.h> | 7 | #include <qpixmap.h> |
8 | #include <qcopchannel_qws.h> | 8 | #include <qcopchannel_qws.h> |
9 | 9 | ||
10 | #include "zkb.h" | 10 | #include "zkb.h" |
11 | 11 | ||
12 | class ZkbWidget : public QLabel { | 12 | class ZkbWidget : public QLabel { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
16 | ZkbWidget(QWidget* parent); | 16 | ZkbWidget(QWidget* parent); |
17 | ~ZkbWidget(); | 17 | ~ZkbWidget(); |
18 | static int position(); | ||
18 | 19 | ||
19 | QSize sizeHint() const; | 20 | QSize sizeHint() const; |
20 | 21 | ||
21 | protected: | 22 | protected: |
22 | QLabel* label; | 23 | QLabel* label; |
23 | Keymap* keymap; | 24 | Keymap* keymap; |
24 | QPopupMenu* labels; | 25 | QPopupMenu* labels; |
25 | QCopChannel* channel; | 26 | QCopChannel* channel; |
26 | int w, h; | 27 | int w, h; |
27 | QPixmap disabled; | 28 | QPixmap disabled; |
28 | 29 | ||
29 | bool loadKeymap(); | 30 | bool loadKeymap(); |
30 | void mouseReleaseEvent(QMouseEvent*); | 31 | void mouseReleaseEvent(QMouseEvent*); |
31 | 32 | ||
32 | protected slots: | 33 | protected slots: |
33 | void stateChanged(const QString&); | 34 | void stateChanged(const QString&); |
34 | void labelChanged(int id); | 35 | void labelChanged(int id); |
35 | void signalReceived(const QCString& msg, const QByteArray& data); | 36 | void signalReceived(const QCString& msg, const QByteArray& data); |
36 | void reload(); | 37 | void reload(); |
37 | }; | 38 | }; |
38 | #endif | 39 | #endif |