summaryrefslogtreecommitdiff
path: root/core
Side-by-side diff
Diffstat (limited to 'core') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp230
-rw-r--r--core/applets/cardmon/cardmon.h52
-rw-r--r--core/applets/cardmon/cardmon.pro23
-rw-r--r--core/applets/cardmon/cardmonimpl.cpp40
-rw-r--r--core/applets/cardmon/cardmonimpl.h19
-rw-r--r--core/applets/cardmon/opie-cardmon.control9
-rwxr-xr-xcore/applets/cardmon/qpe-cardmon.postinst2
-rwxr-xr-xcore/applets/cardmon/qpe-cardmon.postrm2
8 files changed, 377 insertions, 0 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp
new file mode 100644
index 0000000..9522b88
--- a/dev/null
+++ b/core/applets/cardmon/cardmon.cpp
@@ -0,0 +1,230 @@
+/*
+ * cardmon.cpp
+ *
+ * ---------------------
+ *
+ * copyright : (c) 2002 by Maximilian Reiss
+ * email : max.reiss@gmx.de
+ * based on two apps by Devin Butterfield
+ */
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+
+#include "cardmon.h"
+
+#include <qpe/resource.h>
+
+#include <qcopchannel_qws.h>
+#include <qpainter.h>
+#include <qmessagebox.h>
+#include <qpopupmenu.h>
+#include <qfile.h>
+#include <qtextstream.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
+#include <sys/vfs.h>
+#include <mntent.h>
+#endif
+
+CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ),
+ pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) {
+
+ QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this );
+ connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)),
+ this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
+
+ QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this );
+ connect( sdChannel, SIGNAL(received(const QCString &, const QByteArray &)),
+ this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
+
+
+ setFixedSize( pm.size() );
+ hide();
+ getStatusPcmcia();
+}
+
+CardMonitor::~CardMonitor() {
+}
+
+void CardMonitor::mousePressEvent( QMouseEvent * ) {
+ QPopupMenu *menu = new QPopupMenu();
+ QString cmd;
+ int err=0;
+
+ if ( cardInSd ) {
+ menu->insertItem( tr("Eject SD/ MMC card"), 0 );
+ }
+
+ if ( cardInPcmcia0 ) {
+ menu->insertItem( tr("Eject card (0) %1").arg(cardInPcmcia0Name), 1 );
+ }
+
+ if ( cardInPcmcia1 ) {
+ menu->insertItem( tr("Eject card (1) %1").arg(cardInPcmcia1Name), 2 );
+ }
+
+ QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) );
+
+ if ( menu->exec( p, 1 ) == 1 ) {
+
+ cmd = "/sbin/cardctl eject 0";
+ err = system( (const char *) cmd );
+ if ( ( err == 127 ) || ( err < 0 ) ) {
+ qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err);
+ QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"),
+ tr("&OK") );
+ }
+ } else if ( menu->exec( p, 1 ) == 0 ) {
+ cmd = "/etc/sdcontrol compeject";
+ err = system( (const char *) cmd );
+ if ( ( err != 0 ) ) {
+ qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err);
+ QMessageBox::warning( this, tr("CardMonitor"), tr("SD/MMC card eject failed!"),
+ tr("&OK") );
+ }
+ } else if ( menu->exec( p, 1 ) == 2 ) {
+ cmd = "/sbin/cardctl eject 1";
+ err = system( (const char *) cmd );
+ if ( ( err == 127 ) || ( err < 0 ) ) {
+ qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err);
+ QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"),
+ tr("&OK") );
+ }
+ }
+
+ delete menu;
+}
+
+
+void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) {
+ if ( msg == "stabChanged()" ) {
+ if ( getStatusPcmcia() ) {
+ repaint(FALSE);
+ }
+ } else if ( msg == "mtabChanged()" ) {
+ if ( getStatusSd() ) {
+ repaint(FALSE);
+ }
+ }
+}
+
+bool CardMonitor::getStatusPcmcia( void ) {
+
+ bool cardWas0 = cardInPcmcia0; // remember last state
+ bool cardWas1 = cardInPcmcia1;
+
+ QString fileName;
+
+ // one of these 3 files should exist
+ if (QFile::exists("/var/run/stab")) {
+ fileName = "/var/run/stab";
+ } else if (QFile::exists("/var/state/pcmcia/stab")) {
+ fileName="/var/state/pcmcia/stab";
+ } else {
+ fileName="/var/lib/pcmcia/stab";
+ }
+
+ QFile f(fileName);
+
+ if ( f.open(IO_ReadOnly) ) {
+ QStringList list;
+ QTextStream stream ( &f);
+ QString streamIn;
+ streamIn = stream.read();
+ list = QStringList::split("\n", streamIn);
+ for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
+ if( (*line).startsWith("Socket 0:") ){
+ // extendable, maybe read out card name
+ if( (*line).startsWith("Socket 0: empty") && cardInPcmcia0 ){
+ cardInPcmcia0 = FALSE;
+ hide();
+ } else if ( !(*line).startsWith("Socket 0: empty") && !cardInPcmcia0 ){
+ cardInPcmcia0Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 );
+ cardInPcmcia0 = TRUE;
+ show();
+ }
+ }
+ if( (*line).startsWith("Socket 1:") ){
+ if( (*line).startsWith("Socket 1: empty") && cardInPcmcia1 ){
+ cardInPcmcia1 = FALSE;
+ hide();
+ } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){
+ cardInPcmcia1Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 );
+ cardInPcmcia1 = TRUE;
+ show();
+ }
+ }
+ }
+ } else {
+ // no file found
+ qDebug("no file found");
+ cardInPcmcia0 = FALSE;
+ cardInPcmcia1 = FALSE;
+ hide();
+ return FALSE;
+
+ }
+
+ f.close();
+
+ return ((cardWas0 == cardInPcmcia0 || cardWas1 == cardInPcmcia1) ? FALSE : TRUE);
+}
+
+
+bool CardMonitor::getStatusSd( void ) {
+
+ bool cardWas=cardInSd; // remember last state
+ cardInSd=false;
+
+#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
+ struct mntent *me;
+ FILE *mntfp = setmntent( "/etc/mtab", "r" );
+
+ if ( mntfp ) {
+ while ( (me = getmntent( mntfp )) != 0 ) {
+ QString fs = me->mnt_fsname;
+ if ( fs.left(7)=="/dev/sd" || fs.left(9) == "/dev/mmcd" ) {
+ cardInSd=true;
+ }
+ }
+ endmntent( mntfp );
+ if (cardInSd!=cardWas) {
+ if (cardInSd) {
+ show();
+ } else {
+ hide();
+ }
+ }
+ } else {
+ hide();
+ }
+#else
+#error "Not on Linux"
+#endif
+ return ((cardWas == cardInSd) ? FALSE : TRUE);
+}
+
+void CardMonitor::paintEvent( QPaintEvent * ) {
+ QPainter p( this );
+
+ if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) {
+ p.drawPixmap( 0, 0, pm );
+ } else {
+ p.eraseRect( rect() );
+ }
+}
+
+
diff --git a/core/applets/cardmon/cardmon.h b/core/applets/cardmon/cardmon.h
new file mode 100644
index 0000000..2a90c90
--- a/dev/null
+++ b/core/applets/cardmon/cardmon.h
@@ -0,0 +1,52 @@
+/*
+ * cardmon.h
+ *
+ * ---------------------
+ *
+ * copyright : (c) 2002 by Maximilian Reiss
+ * email : max.reiss@gmx.de
+ * based on two apps by Devin Butterfield
+ */
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef CARDMON_H
+#define CARDMON_H
+
+#include <qwidget.h>
+#include <qpixmap.h>
+
+class CardMonitor : public QWidget {
+ Q_OBJECT
+public:
+ CardMonitor( QWidget *parent = 0 );
+ ~CardMonitor();
+ bool getStatusPcmcia( void );
+ bool getStatusSd( void );
+
+private slots:
+ void cardMessage( const QCString &msg, const QByteArray & );
+
+protected:
+ void paintEvent( QPaintEvent* );
+ void mousePressEvent( QMouseEvent * );
+private:
+ QPixmap pm;
+ // pcmcia socket 0
+ bool cardInPcmcia0;
+ QString cardInPcmcia0Name;
+ // pcmcia socket 1
+ bool cardInPcmcia1;
+ QString cardInPcmcia1Name;
+ bool cardInSd;
+
+};
+
+#endif
+
diff --git a/core/applets/cardmon/cardmon.pro b/core/applets/cardmon/cardmon.pro
new file mode 100644
index 0000000..bda051b
--- a/dev/null
+++ b/core/applets/cardmon/cardmon.pro
@@ -0,0 +1,23 @@
+TEMPLATE = lib
+CONFIG += qt warn_on release
+HEADERS = cardmon.h cardmonimpl.h
+SOURCES = cardmon.cpp cardmonimpl.cpp
+TARGET = cardmonapplet
+DESTDIR = $(OPIEDIR)/plugins/applets
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include ../launcher
+LIBS += -lqpe
+VERSION = 1.0.0
+
+TRANSLATIONS = ../i18n/de/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/pt_BR/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/en/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/hu/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/sl/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/pl/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/ja/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/fr/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/ko/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/no/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/zh_CN/libcardmonapplet.ts
+TRANSLATIONS += ../i18n/zh_TW/libcardmonapplet.ts
diff --git a/core/applets/cardmon/cardmonimpl.cpp b/core/applets/cardmon/cardmonimpl.cpp
new file mode 100644
index 0000000..0aa55de
--- a/dev/null
+++ b/core/applets/cardmon/cardmonimpl.cpp
@@ -0,0 +1,40 @@
+#include "cardmon.h"
+#include "cardmonimpl.h"
+
+
+CardMonitorImpl::CardMonitorImpl()
+ : cardMonitor(0), ref(0) {
+}
+
+CardMonitorImpl::~CardMonitorImpl() {
+ delete cardMonitor;
+}
+
+QWidget *CardMonitorImpl::applet( QWidget *parent ) {
+ if ( !cardMonitor ) {
+ cardMonitor = new CardMonitor( parent );
+ }
+ return cardMonitor;
+}
+
+int CardMonitorImpl::position() const {
+ return 7;
+}
+
+QRESULT CardMonitorImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
+ *iface = 0;
+ if ( uuid == IID_QUnknown ) {
+ *iface = this;
+ } else if ( uuid == IID_TaskbarApplet ) {
+ *iface = this;
+ }
+
+ if ( *iface ) {
+ (*iface)->addRef();
+ }
+ return QS_OK;
+}
+
+Q_EXPORT_INTERFACE() {
+ Q_CREATE_INSTANCE( CardMonitorImpl )
+}
diff --git a/core/applets/cardmon/cardmonimpl.h b/core/applets/cardmon/cardmonimpl.h
new file mode 100644
index 0000000..ec2d871
--- a/dev/null
+++ b/core/applets/cardmon/cardmonimpl.h
@@ -0,0 +1,19 @@
+#include <qpe/taskbarappletinterface.h>
+
+class CardMonitor;
+
+class CardMonitorImpl : public TaskbarAppletInterface {
+public:
+ CardMonitorImpl();
+ virtual ~CardMonitorImpl();
+
+ QRESULT queryInterface( const QUuid&, QUnknownInterface** );
+ Q_REFCOUNT
+
+ virtual QWidget *applet( QWidget *parent );
+ virtual int position() const;
+
+private:
+ CardMonitor *cardMonitor;
+ ulong ref;
+};
diff --git a/core/applets/cardmon/opie-cardmon.control b/core/applets/cardmon/opie-cardmon.control
new file mode 100644
index 0000000..9f941f8
--- a/dev/null
+++ b/core/applets/cardmon/opie-cardmon.control
@@ -0,0 +1,9 @@
+Files: plugins/applets/libcardmonapplet.so* pics/cardmon/pcmcia.png
+Priority: optional
+Section: opie/taskbar
+Maintainer: Maximilian Reiß <max.reiss@gmx.de>
+Architecture: arm
+Version: $QPE_VERSION-$SUB_VERSION
+Depends: opie-base ($QPE_VERSION)
+Description: CF/PCMCIA Card Monitor applet
+ SD/MMC/CF/PCMCIA Card Monitor applet for the Opie environment taskbar.
diff --git a/core/applets/cardmon/qpe-cardmon.postinst b/core/applets/cardmon/qpe-cardmon.postinst
new file mode 100755
index 0000000..ba76ffa
--- a/dev/null
+++ b/core/applets/cardmon/qpe-cardmon.postinst
@@ -0,0 +1,2 @@
+#!/bin/sh
+/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()"
diff --git a/core/applets/cardmon/qpe-cardmon.postrm b/core/applets/cardmon/qpe-cardmon.postrm
new file mode 100755
index 0000000..ba76ffa
--- a/dev/null
+++ b/core/applets/cardmon/qpe-cardmon.postrm
@@ -0,0 +1,2 @@
+#!/bin/sh
+/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()"