#include "mb.h"
#include <QProcess>
#include <QFile>
#include <QTextStream>
#include <QDebug>

MPushButton::MPushButton():QPushButton("",0)
{
    QPixmap p(":/eject-button.png");
    setIcon(p);
    setFlat(true);
    connect(this,SIGNAL(clicked()),this,SLOT(slot_cl()));
}

void MPushButton::slot_cl()
{

      FILE* ptr=fopen("/proc/mounts","rt");
      if(!ptr)
      {
            qDebug()<<"couldn't open";
            return;

      }

      char ln[255];
      while(!feof(ptr))
      {
          fgets(ln,254,ptr);
          QString line = ln; 
          if(line.indexOf("CDROM")!=-1)
          {
               QStringList arg;
               arg<<line.split(" ")[0];
               qDebug()<<"Ejecting: "<<arg[0];
               QProcess::startDetached("eject",arg);
         }
      }
      fclose(ptr);
}

