Author Topic: Detect Sd Card Mount  (Read 4997 times)

bam

  • Hero Member
  • *****
  • Posts: 1213
    • View Profile
    • http://thegrinder.ws
Detect Sd Card Mount
« on: August 13, 2005, 06:09:37 pm »
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.
SL-C3100 current: Stock/Tetsu 18h
Socket BT CF Card
Linksys WCF-12 802.11b/Cheapie USB Ethernet

The Grinder

boosalis

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
    • http://
Detect Sd Card Mount
« Reply #1 on: September 23, 2005, 02:47:26 pm »
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
Zaurus 6000 with expansion jacket

chrget

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Detect Sd Card Mount
« Reply #2 on: September 24, 2005, 03:07:41 am »
Quote
QCOP is your friend here. [...][div align=\"right\"][a href=\"index.php?act=findpost&pid=96816\"][{POST_SNAPBACK}][/a][/div]
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.
SL-5500G running a modified 3.13 Sharp ROM
Extrememory 1GB SD / Netgear MA701 WLAN
Audiovox RTM-8000 GSM/GPRS CF Card

boosalis

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
    • http://
Detect Sd Card Mount
« Reply #3 on: September 28, 2005, 02:25:33 am »
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:k,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:k,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
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
[div align=\"right\"][a href=\"index.php?act=findpost&pid=96816\"][{POST_SNAPBACK}][/a][/div]
Zaurus 6000 with expansion jacket