-rw-r--r-- | noncore/net/mail/taskbarapplet/mailapplet.cpp | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/noncore/net/mail/taskbarapplet/mailapplet.cpp b/noncore/net/mail/taskbarapplet/mailapplet.cpp index 2fc1d01..9c0d32f 100644 --- a/noncore/net/mail/taskbarapplet/mailapplet.cpp +++ b/noncore/net/mail/taskbarapplet/mailapplet.cpp | |||
@@ -1,145 +1,160 @@ | |||
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 */ | ||
16 | #include <signal.h> | ||
17 | |||
15 | using namespace Opie::Core; | 18 | using namespace Opie::Core; |
16 | 19 | ||
17 | MailApplet::MailApplet( QWidget *parent ) | 20 | MailApplet::MailApplet( QWidget *parent ) |
18 | : QWidget( parent ) { | 21 | : QWidget( parent ) { |
19 | 22 | ||
20 | m_config = new Config( "mail" ); | 23 | m_config = new Config( "mail" ); |
21 | m_config->setGroup( "Applet" ); | 24 | m_config->setGroup( "Applet" ); |
22 | 25 | ||
23 | setFixedWidth( AppLnk::smallIconSize() ); | 26 | setFixedWidth( AppLnk::smallIconSize() ); |
24 | setFixedHeight( AppLnk::smallIconSize() ); | 27 | setFixedHeight( AppLnk::smallIconSize() ); |
25 | 28 | ||
26 | hide(); | 29 | hide(); |
27 | 30 | ||
28 | m_newMails = 0; | 31 | m_newMails = 0; |
29 | m_statusMail = 0l; | 32 | m_statusMail = 0l; |
30 | 33 | ||
34 | /* for networking we must block SIGPIPE and Co. */ | ||
35 | struct sigaction blocking_action,temp_action; | ||
36 | blocking_action.sa_handler = SIG_IGN; | ||
37 | sigemptyset(&(blocking_action.sa_mask)); | ||
38 | blocking_action.sa_flags = 0; | ||
39 | sigaction(SIGPIPE,&blocking_action,&temp_action); | ||
40 | |||
31 | if ( !m_config->readBoolEntry( "Disabled", false ) ) { | 41 | if ( !m_config->readBoolEntry( "Disabled", false ) ) { |
32 | // delay 5 sec until the whole mail backend gets started .-) | 42 | // delay 5 sec until the whole mail backend gets started .-) |
33 | QTimer::singleShot( 5000, this, SLOT( startup() ) ); | 43 | QTimer::singleShot( 5000, this, SLOT( startup() ) ); |
34 | } | 44 | } |
35 | repaint( true ); | 45 | repaint( true ); |
36 | } | 46 | } |
37 | 47 | ||
38 | 48 | ||
39 | MailApplet::~MailApplet() { | 49 | MailApplet::~MailApplet() { |
40 | if ( m_statusMail ) | 50 | if ( m_statusMail ) |
41 | delete m_statusMail; | 51 | delete m_statusMail; |
42 | if ( m_config ) | 52 | if ( m_config ) |
43 | delete m_config; | 53 | delete m_config; |
44 | } | 54 | } |
45 | 55 | ||
46 | void MailApplet::paintEvent( QPaintEvent* ) { | 56 | void MailApplet::paintEvent( QPaintEvent* ) { |
47 | QPainter p( this ); | 57 | QPainter p( this ); |
48 | p.drawPixmap( 0, 0, Resource::loadPixmap( "mail/inbox" ) ); | 58 | p.drawPixmap( 0, 0, Resource::loadPixmap( "mail/inbox" ) ); |
49 | QFont f( "vera", AppLnk::smallIconSize() ); | 59 | QFont f( "vera", AppLnk::smallIconSize() ); |
50 | QFontMetrics fm( f ); | 60 | QFontMetrics fm( f ); |
51 | p.setFont( f ); | 61 | p.setFont( f ); |
52 | p.setPen( Qt::blue ); | 62 | p.setPen( Qt::blue ); |
53 | p.drawText( AppLnk::smallIconSize()/3, AppLnk::smallIconSize() - 2, QString::number( m_newMails ) ); | 63 | p.drawText( AppLnk::smallIconSize()/3, AppLnk::smallIconSize() - 2, QString::number( m_newMails ) ); |
54 | return; | 64 | return; |
55 | 65 | ||
56 | } | 66 | } |
57 | 67 | ||
58 | void MailApplet::mouseReleaseEvent( QMouseEvent* e ) { | 68 | void MailApplet::mouseReleaseEvent( QMouseEvent* e ) { |
59 | slotClicked(); | 69 | slotClicked(); |
60 | } | 70 | } |
61 | 71 | ||
62 | void MailApplet::slotClicked() { | 72 | void MailApplet::slotClicked() { |
63 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 73 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
64 | e << QString( "opiemail" ); | 74 | e << QString( "opiemail" ); |
65 | 75 | ||
66 | ODevice *device = ODevice::inst(); | 76 | ODevice *device = ODevice::inst(); |
67 | if ( !device-> ledList().isEmpty() ) { | 77 | if ( !device-> ledList().isEmpty() ) { |
68 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; | 78 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; |
69 | 79 | ||
70 | device->setLedState( led, Led_Off ); | 80 | device->setLedState( led, Led_Off ); |
71 | } | 81 | } |
72 | |||
73 | if (m_statusMail) | 82 | if (m_statusMail) |
74 | m_statusMail->reset_status(); | 83 | m_statusMail->reset_status(); |
75 | |||
76 | hide(); | 84 | hide(); |
77 | } | 85 | } |
78 | 86 | ||
79 | void MailApplet::startup() { | 87 | void MailApplet::startup() |
88 | { | ||
80 | Settings *settings = new Settings(); | 89 | Settings *settings = new Settings(); |
81 | QList<Account> ma = settings->getAccounts(); | 90 | QList<Account> ma = settings->getAccounts(); |
82 | m_statusMail = new StatusMail( ma ); | 91 | m_statusMail = new StatusMail( ma ); |
83 | delete settings; | 92 | delete settings; |
84 | 93 | ||
85 | m_intervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; | 94 | //m_intervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; |
95 | m_intervalMs = 100; | ||
86 | m_intervalTimer = new QTimer(); | 96 | m_intervalTimer = new QTimer(); |
87 | m_intervalTimer->start( m_intervalMs ); | 97 | m_intervalTimer->start( m_intervalMs ); |
88 | connect( m_intervalTimer, SIGNAL( timeout() ), this, SLOT( slotCheck() ) ); | 98 | connect( m_intervalTimer, SIGNAL( timeout() ), this, SLOT( slotCheck() ) ); |
89 | } | 99 | } |
90 | 100 | ||
91 | void MailApplet::slotCheck() { | 101 | void MailApplet::slotCheck() { |
92 | // Check wether the check interval has been changed. | 102 | // Check wether the check interval has been changed. |
103 | odebug << "MailApplet::slotCheck()" << oendl; | ||
93 | int newIntervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; | 104 | int newIntervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; |
94 | if ( newIntervalMs != m_intervalMs ) { | 105 | if ( newIntervalMs != m_intervalMs ) { |
95 | m_intervalTimer->changeInterval( newIntervalMs ); | 106 | m_intervalTimer->changeInterval( newIntervalMs ); |
96 | m_intervalMs = newIntervalMs; | 107 | m_intervalMs = newIntervalMs; |
97 | } | 108 | } |
98 | 109 | ||
99 | if (m_statusMail == 0) { | 110 | if (m_statusMail == 0) { |
100 | return; | 111 | return; |
101 | } | 112 | } |
102 | 113 | ||
103 | folderStat stat; | 114 | folderStat stat; |
104 | m_statusMail->check_current_stat( stat ); | 115 | m_statusMail->check_current_stat( stat ); |
105 | int newMailsOld = m_newMails; | 116 | int newMailsOld = m_newMails; |
106 | m_newMails = stat.message_unseen; | 117 | m_newMails = stat.message_unseen; |
107 | odebug << QString( "test %1" ).arg( m_newMails ) << oendl; | 118 | odebug << QString( "test %1" ).arg( m_newMails ) << oendl; |
108 | if ( m_newMails > 0 && newMailsOld != m_newMails ) { | 119 | if ( m_newMails > 0) { |
109 | ODevice *device = ODevice::inst(); | 120 | if (isHidden()) |
110 | if ( isHidden() ) | ||
111 | show(); | 121 | show(); |
112 | if ( m_config->readBoolEntry( "BlinkLed", true ) ) { | 122 | if (newMailsOld != m_newMails) { |
113 | if ( !device->ledList().isEmpty() ) { | 123 | ODevice *device = ODevice::inst(); |
114 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; | 124 | if ( m_config->readBoolEntry( "BlinkLed", true ) ) { |
115 | device->setLedState( led, device->ledStateList( led ).contains( Led_BlinkSlow ) ? Led_BlinkSlow : Led_On ); | 125 | if ( !device->ledList().isEmpty() ) { |
126 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; | ||
127 | device->setLedState( led, device->ledStateList( led ).contains( Led_BlinkSlow ) ? Led_BlinkSlow : Led_On ); | ||
128 | } | ||
116 | } | 129 | } |
130 | if ( m_config->readBoolEntry( "PlaySound", false ) ) | ||
131 | device->playAlarmSound(); | ||
117 | } | 132 | } |
118 | if ( m_config->readBoolEntry( "PlaySound", false ) ) | ||
119 | device->playAlarmSound(); | ||
120 | |||
121 | Config cfg( "mail" ); | 133 | Config cfg( "mail" ); |
122 | cfg.setGroup( "Status" ); | 134 | cfg.setGroup( "Status" ); |
123 | cfg.writeEntry( "newMails", m_newMails ); | 135 | cfg.writeEntry( "newMails", m_newMails ); |
124 | QCopEnvelope env( "QPE/Pim", "newMails(int)" ); | 136 | { |
125 | env << m_newMails; | 137 | odebug << "QCop abschicken" << oendl; |
138 | QCopEnvelope env( "QPE/Pim", "newMails(int)" ); | ||
139 | env << m_newMails; | ||
140 | } | ||
141 | odebug << "QCop abschicken done" << oendl; | ||
126 | repaint( true ); | 142 | repaint( true ); |
127 | |||
128 | } else { | 143 | } else { |
129 | ODevice *device = ODevice::inst(); | 144 | ODevice *device = ODevice::inst(); |
130 | if ( !isHidden() ) | 145 | if ( !isHidden() ) |
131 | hide(); | 146 | hide(); |
132 | if ( !device->ledList().isEmpty() ) { | 147 | if ( !device->ledList().isEmpty() ) { |
133 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; | 148 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; |
134 | device->setLedState( led, Led_Off ); | 149 | device->setLedState( led, Led_Off ); |
135 | } | 150 | } |
136 | 151 | ||
137 | if ( newMailsOld != m_newMails ) { | 152 | if ( newMailsOld != m_newMails ) { |
138 | Config cfg( "mail" ); | 153 | Config cfg( "mail" ); |
139 | cfg.setGroup( "Status" ); | 154 | cfg.setGroup( "Status" ); |
140 | cfg.writeEntry( "newMails", m_newMails ); | 155 | cfg.writeEntry( "newMails", m_newMails ); |
141 | QCopEnvelope env( "QPE/Pim", "newMails(int)" ); | 156 | QCopEnvelope env( "QPE/Pim", "newMails(int)" ); |
142 | env << m_newMails; | 157 | env << m_newMails; |
143 | } | 158 | } |
144 | } | 159 | } |
145 | } | 160 | } |