summaryrefslogtreecommitdiff
authoralwin <alwin>2005-03-12 23:25:49 (UTC)
committer alwin <alwin>2005-03-12 23:25:49 (UTC)
commit69962e7b69ebf91c01a1354d7870f4ca7a81aa06 (patch) (unidiff)
tree584f0f658f16936c1fa5493d2940651ba4170d5f
parent3cb4c3983ee738f3221ecb4cb154ea1252d69d64 (diff)
downloadopie-69962e7b69ebf91c01a1354d7870f4ca7a81aa06.zip
opie-69962e7b69ebf91c01a1354d7870f4ca7a81aa06.tar.gz
opie-69962e7b69ebf91c01a1354d7870f4ca7a81aa06.tar.bz2
some reworks
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/taskbarapplet/mailapplet.cpp93
-rw-r--r--noncore/net/mail/taskbarapplet/mailapplet.h2
2 files changed, 45 insertions, 50 deletions
diff --git a/noncore/net/mail/taskbarapplet/mailapplet.cpp b/noncore/net/mail/taskbarapplet/mailapplet.cpp
index ce1e7ac..b777ecf 100644
--- a/noncore/net/mail/taskbarapplet/mailapplet.cpp
+++ b/noncore/net/mail/taskbarapplet/mailapplet.cpp
@@ -1,162 +1,157 @@
1#include <qpainter.h> 1#include <qpainter.h>
2#include <qtimer.h> 2#include <qtimer.h>
3 3
4#include <qpe/qcopenvelope_qws.h> 4#include <qpe/qcopenvelope_qws.h>
5#include <qpe/resource.h> 5#include <qpe/resource.h>
6#include <qpe/config.h> 6#include <qpe/config.h>
7#include <qpe/applnk.h> 7#include <qpe/applnk.h>
8#include <opie2/odebug.h> 8#include <opie2/odebug.h>
9#include <opie2/odevice.h> 9#include <opie2/odevice.h>
10 10
11#include <libmailwrapper/settings.h> 11#include <libmailwrapper/settings.h>
12 12
13#include "mailapplet.h" 13#include "mailapplet.h"
14 14
15/* UNIX */ 15/* UNIX */
16#include <signal.h> 16#include <signal.h>
17 17
18using namespace Opie::Core; 18using namespace Opie::Core;
19 19
20MailApplet::MailApplet( QWidget *parent ) 20MailApplet::MailApplet( QWidget *parent )
21: QLabel( parent ) { 21: QLabel( parent ) {
22 22
23 m_config = new Config( "mail" ); 23 setFixedHeight(AppLnk::smallIconSize());
24 m_config->setGroup( "Applet" ); 24 setMinimumWidth(AppLnk::smallIconSize());
25
26 //setFixedWidth( AppLnk::smallIconSize() );
27 setFixedHeight( AppLnk::smallIconSize() );
28 25
29 hide(); 26 hide();
30 27
31 m_newMails = 0; 28 m_newMails = 0;
32 m_statusMail = 0l; 29 m_statusMail = 0l;
33 30
34 /* for networking we must block SIGPIPE and Co. */ 31 /* for networking we must block SIGPIPE and Co. */
35 struct sigaction blocking_action,temp_action; 32 struct sigaction blocking_action,temp_action;
36 blocking_action.sa_handler = SIG_IGN; 33 blocking_action.sa_handler = SIG_IGN;
37 sigemptyset(&(blocking_action.sa_mask)); 34 sigemptyset(&(blocking_action.sa_mask));
38 blocking_action.sa_flags = 0; 35 blocking_action.sa_flags = 0;
39 sigaction(SIGPIPE,&blocking_action,&temp_action); 36 sigaction(SIGPIPE,&blocking_action,&temp_action);
40 37
41 if ( !m_config->readBoolEntry( "Disabled", false ) ) { 38 QTimer::singleShot( 5000, this, SLOT( startup() ) );
42 // delay 5 sec until the whole mail backend gets started .-)
43 QTimer::singleShot( 5000, this, SLOT( startup() ) );
44 }
45 repaint( true );
46} 39}
47 40
48 41
49MailApplet::~MailApplet() { 42MailApplet::~MailApplet() {
50 if ( m_statusMail ) 43 if ( m_statusMail )
51 delete m_statusMail; 44 delete m_statusMail;
52 if ( m_config )
53 delete m_config;
54} 45}
55 46
56void MailApplet::paintEvent( QPaintEvent*ev ) 47void MailApplet::paintEvent( QPaintEvent*ev )
57{ 48{
58 QPainter p( this ); 49 QPainter p( this );
59 p.drawPixmap( 0, 0, Resource::loadPixmap( "mail/inbox" ) ); 50 p.drawPixmap( 0, 0, Resource::loadPixmap( "mail/inbox" ) );
60 QLabel::paintEvent(ev); 51 QLabel::paintEvent(ev);
61#if 0 52#if 0
62 QFont f( "vera", AppLnk::smallIconSize() ); 53 QFont f( "vera", AppLnk::smallIconSize() );
63 QFontMetrics fm( f ); 54 QFontMetrics fm( f );
64 p.setFont( f ); 55 p.setFont( f );
65 p.setPen( Qt::blue ); 56 p.setPen( Qt::blue );
66 p.drawText( AppLnk::smallIconSize()/3, AppLnk::smallIconSize() - 2, QString::number( m_newMails ) ); 57 p.drawText( AppLnk::smallIconSize()/3, AppLnk::smallIconSize() - 2, QString::number( m_newMails ) );
67#endif 58#endif
68 return; 59 return;
69} 60}
70 61
71void MailApplet::mouseReleaseEvent( QMouseEvent* e ) { 62void MailApplet::mouseReleaseEvent( QMouseEvent* e ) {
72 slotClicked(); 63 slotClicked();
73} 64}
74 65
75void MailApplet::slotClicked() { 66void MailApplet::slotClicked()
76 QCopEnvelope e( "QPE/System", "execute(QString)" ); 67{
77 e << QString( "opiemail" ); 68 {
78 69 QCopEnvelope e( "QPE/System", "execute(QString)" );
79 ODevice *device = ODevice::inst(); 70 e << QString( "opiemail" );
80 if ( !device-> ledList().isEmpty() ) {
81 OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0];
82
83 device->setLedState( led, Led_Off );
84 } 71 }
72
73 ledOnOff(false);
85 if (m_statusMail) 74 if (m_statusMail)
86 m_statusMail->reset_status(); 75 m_statusMail->reset_status();
87 hide(); 76 hide();
88} 77}
89 78
90void MailApplet::startup() 79void MailApplet::startup()
91{ 80{
92 Settings *settings = new Settings(); 81 Settings *settings = new Settings();
93 QList<Account> ma = settings->getAccounts(); 82 QList<Account> ma = settings->getAccounts();
94 m_statusMail = new StatusMail( ma ); 83 m_statusMail = new StatusMail( ma );
95 delete settings; 84 delete settings;
96 85
97 //m_intervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; 86 //m_intervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000;
98 m_intervalMs = 100; 87 m_intervalMs = 100;
99 m_intervalTimer = new QTimer(); 88 m_intervalTimer = new QTimer();
100 m_intervalTimer->start( m_intervalMs ); 89 m_intervalTimer->start( m_intervalMs );
101 connect( m_intervalTimer, SIGNAL( timeout() ), this, SLOT( slotCheck() ) ); 90 connect( m_intervalTimer, SIGNAL( timeout() ), this, SLOT( slotCheck() ) );
102} 91}
103 92
93void MailApplet::ledOnOff(bool how)
94{
95 ODevice *device = ODevice::inst();
96 if ( !device->ledList().isEmpty() ) {
97 OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0];
98 device->setLedState( led, (how?(device->ledStateList( led ).contains( Led_BlinkSlow )?Led_BlinkSlow:Led_On):Led_Off) );
99 }
100}
101
104void MailApplet::slotCheck() { 102void MailApplet::slotCheck() {
105 // Check wether the check interval has been changed. 103 // Check wether the check interval has been changed.
106 odebug << "MailApplet::slotCheck()" << oendl; 104 odebug << "MailApplet::slotCheck()" << oendl;
107 int newIntervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; 105 Config m_config( "mail" );
106 m_config.setGroup( "Applet" );
107
108 int newIntervalMs = m_config.readNumEntry( "CheckEvery", 5 ) * 60000;
108 if ( newIntervalMs != m_intervalMs ) { 109 if ( newIntervalMs != m_intervalMs ) {
109 m_intervalTimer->changeInterval( newIntervalMs ); 110 m_intervalTimer->changeInterval( newIntervalMs );
110 m_intervalMs = newIntervalMs; 111 m_intervalMs = newIntervalMs;
111 } 112 }
112 113 if ( m_config.readBoolEntry( "Disabled", false ) ) {
114 hide();
115 ledOnOff(false);
116 odebug << "MailApplet::slotCheck() - disabled" << oendl;
117 return;
118 }
113 if (m_statusMail == 0) { 119 if (m_statusMail == 0) {
120 odebug << "MailApplet::slotCheck() - no mailhandle" << oendl;
114 return; 121 return;
115 } 122 }
116
117 folderStat stat; 123 folderStat stat;
118 m_statusMail->check_current_stat( stat ); 124 m_statusMail->check_current_stat( stat );
119 int newMailsOld = m_newMails; 125 int newMailsOld = m_newMails;
120 m_newMails = stat.message_unseen; 126 m_newMails = stat.message_unseen;
121 odebug << QString( "test %1" ).arg( m_newMails ) << oendl; 127 odebug << QString( "test %1" ).arg( m_newMails ) << oendl;
122 if ( m_newMails > 0) { 128 if ( m_newMails > 0) {
123 if (isHidden()) 129 if (isHidden())
124 show(); 130 show();
125 if (newMailsOld != m_newMails) { 131 if (newMailsOld != m_newMails) {
126 ODevice *device = ODevice::inst(); 132 if ( m_config.readBoolEntry( "BlinkLed", true ) ) {
127 if ( m_config->readBoolEntry( "BlinkLed", true ) ) { 133 ledOnOff(true);
128 if ( !device->ledList().isEmpty() ) {
129 OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0];
130 device->setLedState( led, device->ledStateList( led ).contains( Led_BlinkSlow ) ? Led_BlinkSlow : Led_On );
131 }
132 } 134 }
133 if ( m_config->readBoolEntry( "PlaySound", false ) ) 135 if ( m_config.readBoolEntry( "PlaySound", false ) )
134 device->playAlarmSound(); 136 ODevice::inst()->playAlarmSound();
135 } 137 m_config.setGroup( "Status" );
136 Config cfg( "mail" ); 138 m_config.writeEntry( "newMails", m_newMails );
137 cfg.setGroup( "Status" ); 139 {
138 cfg.writeEntry( "newMails", m_newMails ); 140 QCopEnvelope env( "QPE/Pim", "newMails(int)" );
139 { 141 env << m_newMails;
140 QCopEnvelope env( "QPE/Pim", "newMails(int)" ); 142 }
141 env << m_newMails; 143 setText(QString::number( m_newMails ));
142 } 144 }
143 setText(QString::number( m_newMails ));
144// repaint( true );
145 } else { 145 } else {
146 ODevice *device = ODevice::inst(); 146 ODevice *device = ODevice::inst();
147 if ( !isHidden() ) 147 if ( !isHidden() )
148 hide(); 148 hide();
149 if ( !device->ledList().isEmpty() ) {
150 OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0];
151 device->setLedState( led, Led_Off );
152 }
153
154 if ( newMailsOld != m_newMails ) { 149 if ( newMailsOld != m_newMails ) {
155 Config cfg( "mail" ); 150 ledOnOff(false);
156 cfg.setGroup( "Status" ); 151 m_config.setGroup( "Status" );
157 cfg.writeEntry( "newMails", m_newMails ); 152 m_config.writeEntry( "newMails", m_newMails );
158 QCopEnvelope env( "QPE/Pim", "newMails(int)" ); 153 QCopEnvelope env( "QPE/Pim", "newMails(int)" );
159 env << m_newMails; 154 env << m_newMails;
160 } 155 }
161 } 156 }
162} 157}
diff --git a/noncore/net/mail/taskbarapplet/mailapplet.h b/noncore/net/mail/taskbarapplet/mailapplet.h
index f28f274..f46bf19 100644
--- a/noncore/net/mail/taskbarapplet/mailapplet.h
+++ b/noncore/net/mail/taskbarapplet/mailapplet.h
@@ -1,39 +1,39 @@
1#ifndef MAILAPPLET_H 1#ifndef MAILAPPLET_H
2#define MAILAPPLET_H 2#define MAILAPPLET_H
3 3
4#include <qbutton.h> 4#include <qbutton.h>
5#include <qlabel.h> 5#include <qlabel.h>
6 6
7#include <libmailwrapper/statusmail.h> 7#include <libmailwrapper/statusmail.h>
8 8
9class Config; 9class Config;
10class QTimer; 10class QTimer;
11 11
12class MailApplet : public QLabel { 12class MailApplet : public QLabel {
13 13
14 Q_OBJECT 14 Q_OBJECT
15 15
16public: 16public:
17 MailApplet( QWidget *parent = 0 ); 17 MailApplet( QWidget *parent = 0 );
18 ~MailApplet(); 18 ~MailApplet();
19 19
20protected: 20protected:
21 void gotNewMail(); 21 void gotNewMail();
22 void mouseReleaseEvent( QMouseEvent* ); 22 void mouseReleaseEvent( QMouseEvent* );
23 void paintEvent( QPaintEvent* ); 23 void paintEvent( QPaintEvent* );
24 static void ledOnOff(bool);
24 25
25protected slots: 26protected slots:
26 void startup(); 27 void startup();
27 void slotCheck(); 28 void slotCheck();
28 void slotClicked(); 29 void slotClicked();
29private: 30private:
30 Config *m_config;
31 QTimer *m_intervalTimer; 31 QTimer *m_intervalTimer;
32 int m_intervalMs; 32 int m_intervalMs;
33 StatusMail* m_statusMail; 33 StatusMail* m_statusMail;
34 int m_newMails; 34 int m_newMails;
35 35
36}; 36};
37 37
38#endif 38#endif
39 39