Diffstat (limited to 'core/applets/cardmon/cardmon.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp index ac2aea2..3dd9f54 100644 --- a/core/applets/cardmon/cardmon.cpp +++ b/core/applets/cardmon/cardmon.cpp | |||
@@ -24,9 +24,9 @@ | |||
24 | #include <qcopchannel_qws.h> | 24 | #include <qcopchannel_qws.h> |
25 | #include <qpainter.h> | 25 | #include <qpainter.h> |
26 | #include <qmessagebox.h> | 26 | #include <qmessagebox.h> |
27 | #include <qpopupmenu.h> | ||
28 | #include <qfile.h> | 27 | #include <qfile.h> |
29 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #include <qtimer.h> | ||
30 | 30 | ||
31 | #include <stdio.h> | 31 | #include <stdio.h> |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
@@ -54,11 +54,39 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), | |||
54 | getStatusPcmcia(TRUE); | 54 | getStatusPcmcia(TRUE); |
55 | getStatusSd(TRUE); | 55 | getStatusSd(TRUE); |
56 | repaint(FALSE); | 56 | repaint(FALSE); |
57 | popUpMenu = 0; | ||
58 | popUpMenuTimer = 0; | ||
57 | } | 59 | } |
58 | 60 | ||
59 | CardMonitor::~CardMonitor() { | 61 | CardMonitor::~CardMonitor() { |
60 | } | 62 | } |
61 | 63 | ||
64 | void CardMonitor::popUp(QString message) { | ||
65 | if ( ! popUpMenu ) { | ||
66 | popUpMenu = new QPopupMenu(); | ||
67 | } | ||
68 | popUpMenu->clear(); | ||
69 | popUpMenu->insertItem( message, 0 ); | ||
70 | |||
71 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); | ||
72 | QSize s = popUpMenu->sizeHint ( ); | ||
73 | popUpMenu->popup( QPoint ( | ||
74 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), | ||
75 | p. y ( ) - s. height ( ) ), 0); | ||
76 | |||
77 | if ( ! popUpMenuTimer ) { | ||
78 | popUpMenuTimer = new QTimer( this ); | ||
79 | connect( popUpMenuTimer, SIGNAL(timeout()), this, SLOT(popUpTimeout()) ); | ||
80 | } | ||
81 | timerEvent(0); | ||
82 | popUpMenuTimer->start( 2000 ); | ||
83 | } | ||
84 | |||
85 | void CardMonitor::popUpTimeout() { | ||
86 | popUpMenu->hide(); | ||
87 | popUpMenuTimer->stop(); | ||
88 | } | ||
89 | |||
62 | void CardMonitor::mousePressEvent( QMouseEvent * ) { | 90 | void CardMonitor::mousePressEvent( QMouseEvent * ) { |
63 | QPopupMenu *menu = new QPopupMenu(); | 91 | QPopupMenu *menu = new QPopupMenu(); |
64 | QString cmd; | 92 | QString cmd; |
@@ -88,24 +116,21 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) { | |||
88 | err = system( (const char *) cmd ); | 116 | err = system( (const char *) cmd ); |
89 | if ( ( err == 127 ) || ( err < 0 ) ) { | 117 | if ( ( err == 127 ) || ( err < 0 ) ) { |
90 | qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err); | 118 | qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err); |
91 | QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"), | 119 | popUp( tr("CF/PCMCIA card eject failed!")); |
92 | tr("&OK") ); | ||
93 | } | 120 | } |
94 | } else if ( opt == 0 ) { | 121 | } else if ( opt == 0 ) { |
95 | cmd = "/etc/sdcontrol compeject"; | 122 | cmd = "/etc/sdcontrol compeject"; |
96 | err = system( (const char *) cmd ); | 123 | err = system( (const char *) cmd ); |
97 | if ( ( err != 0 ) ) { | 124 | if ( ( err != 0 ) ) { |
98 | qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); | 125 | qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); |
99 | QMessageBox::warning( this, tr("CardMonitor"), tr("SD/MMC card eject failed!"), | 126 | popUp( tr("SD/MMC card eject failed!")); |
100 | tr("&OK") ); | ||
101 | } | 127 | } |
102 | } else if ( opt == 2 ) { | 128 | } else if ( opt == 2 ) { |
103 | cmd = "/sbin/cardctl eject 1"; | 129 | cmd = "/sbin/cardctl eject 1"; |
104 | err = system( (const char *) cmd ); | 130 | err = system( (const char *) cmd ); |
105 | if ( ( err == 127 ) || ( err < 0 ) ) { | 131 | if ( ( err == 127 ) || ( err < 0 ) ) { |
106 | qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err); | 132 | qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err); |
107 | QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"), | 133 | popUp( tr("CF/PCMCIA card eject failed!")); |
108 | tr("&OK") ); | ||
109 | } | 134 | } |
110 | } | 135 | } |
111 | 136 | ||
@@ -201,8 +226,7 @@ bool CardMonitor::getStatusPcmcia( int showPopUp = FALSE ) { | |||
201 | else { text += tr("Ejected: "); } | 226 | else { text += tr("Ejected: "); } |
202 | text += cardInPcmcia1Name; | 227 | text += cardInPcmcia1Name; |
203 | } | 228 | } |
204 | QMessageBox::warning( this, tr("CardMonitor"), text, | 229 | popUp( text ); |
205 | tr("&OK") ); | ||
206 | } | 230 | } |
207 | 231 | ||
208 | f.close(); | 232 | f.close(); |
@@ -233,8 +257,7 @@ bool CardMonitor::getStatusSd( int showPopUp = FALSE ) { | |||
233 | QString text = ""; | 257 | QString text = ""; |
234 | if(cardInSd) { text += "SD Inserted"; } | 258 | if(cardInSd) { text += "SD Inserted"; } |
235 | else { text += "SD Removed"; } | 259 | else { text += "SD Removed"; } |
236 | QMessageBox::warning( this, tr("CardMonitor"), text, | 260 | popUp( text ); |
237 | tr("&OK") ); | ||
238 | } | 261 | } |
239 | 262 | ||
240 | #else | 263 | #else |