Help - Search - Members - Calendar
Full Version: Detect Sd Card Mount
OESF Forums > Distros, Development, and Model Specific Forums > Everything Development > Qt/Qtopia
bam
need to know what mechanism triggers when you in sert the sd card, I want to auto move some *.pdb fils made by JPluckX from my sd card to my Documents directory.
boosalis
bam

QCOP is your friend here. Don't have the code in front of me, but when I get home will try to post here at this forum the Qtopia event you register and listen for to get media mounts/dismounts
chrget
QUOTE(boosalis @ Sep 23 2005, 08:47 PM)
QCOP is your friend here. [...]
*
Uhm, sounds like aiming a huge gun at a really tiny target.

I'd simply write a script that performs the task in question and would call that from /etc/sdcontrol when handling the insert action ...

Best regards,
Chris.
boosalis
Bam - sorry for the delay in getting back to you with the source code. That is if you are still interested in capturing a event from inside your QT/Qtopia program/

channel = new QCopChannel( "QPE/Card", this );
connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
this, SLOT(mediaAlert(const QCString&, const QByteArray&)) );

Hope the above signal/slot work, its been a while and I had it commented out in my code but recall it working at one time. The hard part I had was in figuring out what media device was loaded/unloaded. I did something crude like:

(sorry for this hack, but hope it gets the point home)
/**********************************************************/
void AllTracker::mediaAlert(const QCString & cstr, const QByteArray& ba)
{
bool mounted;
int status;
QByteArray cs;
QCString cs1;
QDir workDir("/mnt/card");
qDebug("MEDIA ALERT...");

mediaNotice = new
QMessageBox(tr("Media ALERT"),
cstr,
QMessageBox::Warning ,
QMessageBox:ohmy.gifk,0,0,
this,0,TRUE);
mediaNotice->exec();
delete mediaNotice;


if (cstr.contains("mtabChanged") != TRUE)
return;

// For some reason I could not do a read on /proc/mount so
// had to cat it to a normal file then read it
system("cat /proc/mounts > /tmp/mounts");
QFile mntFile("/tmp/mounts");
if (mntFile.exists() != TRUE) {
qWarning("Can't find /proc/mounts");
return;
}
status = mntFile.open(IO_ReadOnly );
if (status != TRUE) {
qWarning("Can't open /tmp/mounts");
return;
}
cs = mntFile.readAll();
if (cs.size() < 1) {
qWarning("No data in /tmp/mounts");
return;
}
cs1 = cs;
if (cs1.contains("card")) {
qDebug("Found mnt");
mounted = TRUE;
}
else {
qDebug("Media Not found");
mounted = FALSE;
}
if (mounted == FALSE) {
if (run == 0)
return;
qDebug("work dir == 0");
mediaNotice = new
QMessageBox(tr("Media Removal Warning"),
tr("Save transactions before\nremoving media"),
QMessageBox::Warning ,
QMessageBox:ohmy.gifk,0,0,
this,0,TRUE);
mediaNotice->exec();
delete mediaNotice;
mediaNotice = 0;
}
else { // is mounted
QApplication::beep();
if (run == 0) {
loadData();
return;
}

if (turnOffMedia != TRUE) {
mediaNotice = new
QMessageBox(tr("Medial Alert"),
tr("Reload Data from Media"),
QMessageBox::Information ,
QMessageBox::Yes,
QMessageBox::No,0,
this,0,TRUE);
status = mediaNotice->exec();
delete mediaNotice;
mediaNotice = 0;
qDebug("status =f media dialog = %d",status);
turnOffMedia = FALSE;
}

}
}




QUOTE(boosalis @ Sep 23 2005, 10:47 AM)
bam

QCOP is your friend here.  Don't have the code in front of me, but when I get home will try to post here at this forum the Qtopia event you register and listen for to get media mounts/dismounts
*
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.