author | harlekin <harlekin> | 2004-01-05 17:42:58 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2004-01-05 17:42:58 (UTC) |
commit | 3804209658d051d197526a28561bbd2e31b6f439 (patch) (unidiff) | |
tree | a584208303908ca31f6ab039ac00e9fe6fcd606a | |
parent | 642fd965cca78fe4398cbe12afcd15cd2f2257ad (diff) | |
download | opie-3804209658d051d197526a28561bbd2e31b6f439.zip opie-3804209658d051d197526a28561bbd2e31b6f439.tar.gz opie-3804209658d051d197526a28561bbd2e31b6f439.tar.bz2 |
inherit from qwidget instead of qbutton
-rw-r--r-- | noncore/net/mail/taskbarapplet/mailapplet.cpp | 69 | ||||
-rw-r--r-- | noncore/net/mail/taskbarapplet/mailapplet.h | 9 |
2 files changed, 40 insertions, 38 deletions
diff --git a/noncore/net/mail/taskbarapplet/mailapplet.cpp b/noncore/net/mail/taskbarapplet/mailapplet.cpp index 31d5bfe..5d98783 100644 --- a/noncore/net/mail/taskbarapplet/mailapplet.cpp +++ b/noncore/net/mail/taskbarapplet/mailapplet.cpp | |||
@@ -1,16 +1,12 @@ | |||
1 | #include <qlayout.h> | 1 | #include <qpainter.h> |
2 | #include <qpixmap.h> | ||
3 | #include <qlabel.h> | ||
4 | #include <qsound.h> | ||
5 | #include <qtimer.h> | 2 | #include <qtimer.h> |
6 | #include <qdir.h> | ||
7 | 3 | ||
8 | #include <qpe/qcopenvelope_qws.h> | 4 | #include <qpe/qcopenvelope_qws.h> |
9 | #include <qpe/resource.h> | 5 | #include <qpe/resource.h> |
10 | #include <qpe/config.h> | 6 | #include <qpe/config.h> |
7 | #include <qpe/applnk.h> | ||
11 | 8 | ||
12 | #include <opie/odevice.h> | 9 | #include <opie/odevice.h> |
13 | #include <qlist.h> | ||
14 | 10 | ||
15 | #include <libmailwrapper/settings.h> | 11 | #include <libmailwrapper/settings.h> |
16 | 12 | ||
@@ -18,44 +14,47 @@ | |||
18 | 14 | ||
19 | using namespace Opie; | 15 | using namespace Opie; |
20 | 16 | ||
21 | MailApplet::MailApplet( QWidget *parent, const char *name, WFlags fl ) | 17 | MailApplet::MailApplet( QWidget *parent ) |
22 | : QButton( parent, name, fl ) { | 18 | : QWidget( parent ) { |
23 | 19 | ||
24 | m_config = new Config( "mail" ); | 20 | m_config = new Config( "mail" ); |
25 | m_config->setGroup( "Applet" ); | 21 | m_config->setGroup( "Applet" ); |
26 | 22 | ||
27 | QVBoxLayout *layout = new QVBoxLayout( this ); | 23 | setFixedWidth( AppLnk::smallIconSize() ); |
28 | layout->addItem( new QSpacerItem( 0,0 ) ); | 24 | setFixedHeight( AppLnk::smallIconSize() ); |
29 | |||
30 | QLabel *pixmap = new QLabel( this ); | ||
31 | pixmap->setPixmap( Resource::loadPixmap( "mail/mailchecker" ) ); | ||
32 | layout->addWidget( pixmap ); | ||
33 | |||
34 | layout->addItem( new QSpacerItem( 0,0 ) ); | ||
35 | 25 | ||
36 | hide(); | 26 | hide(); |
37 | 27 | ||
38 | m_statusMail = 0; | 28 | m_newMails = 0; |
39 | 29 | m_statusMail = 0l; | |
40 | connect( this, SIGNAL( clicked() ), SLOT( slotClicked() ) ); | ||
41 | 30 | ||
42 | if ( !m_config->readBoolEntry( "Disabled", false ) ) { | 31 | if ( !m_config->readBoolEntry( "Disabled", false ) ) { |
43 | m_intervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; | ||
44 | m_intervalTimer = new QTimer(); | ||
45 | m_intervalTimer->start( m_intervalMs ); | ||
46 | connect( m_intervalTimer, SIGNAL(timeout() ), SLOT( slotCheck() ) ); | ||
47 | |||
48 | // delay 5 sec until the whole mail backend gets started .-) | 32 | // delay 5 sec until the whole mail backend gets started .-) |
49 | QTimer::singleShot( 5000, this, SLOT( startup() ) ); | 33 | QTimer::singleShot( 5000, this, SLOT( startup() ) ); |
50 | } | 34 | } |
35 | repaint( true ); | ||
51 | } | 36 | } |
52 | 37 | ||
38 | |||
53 | MailApplet::~MailApplet() { | 39 | MailApplet::~MailApplet() { |
54 | if (m_statusMail) delete m_statusMail; | 40 | if (m_statusMail) delete m_statusMail; |
41 | if (m_config) delete m_config; | ||
55 | } | 42 | } |
56 | 43 | ||
57 | void MailApplet::drawButton(QPainter *) { } | 44 | void MailApplet::paintEvent( QPaintEvent* ) { |
58 | void MailApplet::drawButtonText(QPainter *) { } | 45 | QPainter p(this); |
46 | p.drawPixmap( 0, 0, Resource::loadPixmap( "mail/mailchecker" ) ); | ||
47 | QFont f( "Fixed", AppLnk::smallIconSize() ); | ||
48 | QFontMetrics fm( f ); | ||
49 | p.setFont( f ); | ||
50 | p.drawText( AppLnk::smallIconSize()/2, AppLnk::smallIconSize()/2, QString::number( m_newMails ) ); | ||
51 | return; | ||
52 | |||
53 | } | ||
54 | |||
55 | void MailApplet::mouseReleaseEvent( QMouseEvent* e) { | ||
56 | slotClicked(); | ||
57 | } | ||
59 | 58 | ||
60 | void MailApplet::slotClicked() { | 59 | void MailApplet::slotClicked() { |
61 | qDebug( " CLICKED" ); | 60 | qDebug( " CLICKED" ); |
@@ -77,6 +76,12 @@ void MailApplet::startup() { | |||
77 | QList<Account> ma = settings->getAccounts(); | 76 | QList<Account> ma = settings->getAccounts(); |
78 | StatusMail m_statusMail = StatusMail( ma ); | 77 | StatusMail m_statusMail = StatusMail( ma ); |
79 | delete settings; | 78 | delete settings; |
79 | |||
80 | m_intervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; | ||
81 | m_intervalTimer = new QTimer(); | ||
82 | m_intervalTimer->start( m_intervalMs ); | ||
83 | connect( m_intervalTimer, SIGNAL(timeout() ), this, SLOT( slotCheck() ) ); | ||
84 | |||
80 | } | 85 | } |
81 | 86 | ||
82 | void MailApplet::slotCheck() { | 87 | void MailApplet::slotCheck() { |
@@ -90,9 +95,9 @@ void MailApplet::slotCheck() { | |||
90 | 95 | ||
91 | folderStat stat; | 96 | folderStat stat; |
92 | m_statusMail->check_current_stat( stat ); | 97 | m_statusMail->check_current_stat( stat ); |
93 | 98 | m_newMails = stat.message_unseen; | |
94 | qDebug( QString( "test %1" ).arg( stat.message_unseen ) ); | 99 | qDebug( QString( "test %1" ).arg( stat.message_unseen ) ); |
95 | if ( stat.message_unseen > 0 ) { | 100 | if ( m_newMails > 0 ) { |
96 | ODevice *device = ODevice::inst(); | 101 | ODevice *device = ODevice::inst(); |
97 | if ( isHidden() ) show(); | 102 | if ( isHidden() ) show(); |
98 | if ( m_config->readBoolEntry( "BlinkLed", true ) ) { | 103 | if ( m_config->readBoolEntry( "BlinkLed", true ) ) { |
@@ -104,13 +109,12 @@ void MailApplet::slotCheck() { | |||
104 | if ( m_config->readBoolEntry( "PlaySound", false ) ) | 109 | if ( m_config->readBoolEntry( "PlaySound", false ) ) |
105 | device->alarmSound(); | 110 | device->alarmSound(); |
106 | 111 | ||
107 | qDebug( QString( "test %1" ).arg( stat.message_unseen ) ); | ||
108 | |||
109 | Config cfg( "mail" ); | 112 | Config cfg( "mail" ); |
110 | cfg.setGroup( "Status" ); | 113 | cfg.setGroup( "Status" ); |
111 | cfg.writeEntry( "NewMails", ( int )stat.message_unseen ); | 114 | cfg.writeEntry( "NewMails", m_newMails ); |
112 | QCopEnvelope env( "QPE/Pim", "newMails(int)" ); | 115 | QCopEnvelope env( "QPE/Pim", "newMails(int)" ); |
113 | env << stat.message_unseen; | 116 | env << stat.message_unseen; |
117 | repaint( true ); | ||
114 | 118 | ||
115 | } else { | 119 | } else { |
116 | ODevice *device = ODevice::inst(); | 120 | ODevice *device = ODevice::inst(); |
@@ -120,7 +124,4 @@ void MailApplet::slotCheck() { | |||
120 | device->setLedState( led, Led_Off ); | 124 | device->setLedState( led, Led_Off ); |
121 | } | 125 | } |
122 | } | 126 | } |
123 | |||
124 | // go trough accounts and check here | ||
125 | // also trigger qcop call and save status to config | ||
126 | } | 127 | } |
diff --git a/noncore/net/mail/taskbarapplet/mailapplet.h b/noncore/net/mail/taskbarapplet/mailapplet.h index 8369176..25f0652 100644 --- a/noncore/net/mail/taskbarapplet/mailapplet.h +++ b/noncore/net/mail/taskbarapplet/mailapplet.h | |||
@@ -8,18 +8,18 @@ | |||
8 | class Config; | 8 | class Config; |
9 | class QTimer; | 9 | class QTimer; |
10 | 10 | ||
11 | class MailApplet : public QButton { | 11 | class MailApplet : public QWidget { |
12 | 12 | ||
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
16 | MailApplet( QWidget *parent = 0, const char *name = 0, WFlags fl = 0 ); | 16 | MailApplet( QWidget *parent = 0 ); |
17 | ~MailApplet(); | 17 | ~MailApplet(); |
18 | 18 | ||
19 | protected: | 19 | protected: |
20 | void drawButton(QPainter *); | ||
21 | void drawButtonText(QPainter *); | ||
22 | void gotNewMail(); | 20 | void gotNewMail(); |
21 | void mouseReleaseEvent( QMouseEvent* ); | ||
22 | void paintEvent( QPaintEvent* ); | ||
23 | 23 | ||
24 | protected slots: | 24 | protected slots: |
25 | void startup(); | 25 | void startup(); |
@@ -30,6 +30,7 @@ private: | |||
30 | QTimer *m_intervalTimer; | 30 | QTimer *m_intervalTimer; |
31 | int m_intervalMs; | 31 | int m_intervalMs; |
32 | StatusMail* m_statusMail; | 32 | StatusMail* m_statusMail; |
33 | int m_newMails; | ||
33 | 34 | ||
34 | }; | 35 | }; |
35 | 36 | ||