Logo Search packages:      
Sourcecode: q4wine version File versions  Download package

QString corelib::getMountedImages ( QString  cdrom_mount  ) 

This function gets mouted image or media.

Parameters:
crom_mount Mount point path.
Returns:
Return an list of cdrom devices.

Definition at line 607 of file q4wine-lib.cpp.

References getSetting().

Referenced by umountImage().

                                                        {

        if (cdrom_mount.right(1)=="/"){
            cdrom_mount=cdrom_mount.left(cdrom_mount.length()-1);
        }

            QString image="";
            QStringList arguments;

#ifdef DEBUG
        qDebug()<<"corelib::getMountedImages("<<cdrom_mount<<")";
#endif


#ifdef _OS_LINUX_
        QString filename="/etc/mtab";
        QFile file(filename);
        if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
            QTextStream in(&file);
            while (!in.atEnd()) {
                QString line = in.readLine();
#ifdef DEBUG
                qDebug()<<"corelib::/etc/mtab:line"<<line;
#endif
                if (line.contains(cdrom_mount)){
                    image = line.split(" ").first();
                    if (image.contains("fuseiso") || image.contains("q4wine-mount")){
#ifdef DEBUG
                        qDebug()<<"corelib::fuseiso image found: "<<image;
#endif
                        filename=QDir::homePath();
                        filename.append("/.mtab.fuseiso");
                        QFile file(filename);
                        if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
                            QTextStream in(&file);
                            while (!in.atEnd()) {
                                QString line = in.readLine();
#ifdef DEBUG
                                qDebug()<<"corelib::getMountedImages:line"<<line;
#endif
                                if (line.contains(cdrom_mount))
                                    return line.split(" ").first().split("/").last();
                            }
                        } else {
#ifdef DEBUG
                            qDebug()<<"corelib::fuseiso cant read mtab.fuseiso"<<image;
#endif
                            return QString("cant read %1").arg(filename);
                        }
                    } else if (image.contains("loop")){
                        arguments << "losetup" << image;
                        QProcess myProcess;
                        myProcess.start(this->getSetting("system", "sudo").toString(), arguments);
                        if (!myProcess.waitForFinished()){
                            qDebug() << "Make failed:" << myProcess.errorString();
                            return QString("can't run %1").arg(arguments.at(0));
                        } else {
                            image = myProcess.readAll();
                            qDebug()<<"www"<<arguments;
                            return image.split("/").last().mid(0, image.split("/").last().length()-2);
                        }

                    } else {
                        return image;
                    }
                }
            }
        } else {
            return "cant read /etc/mtab";
        }

        return "none";
#endif
#ifdef _OS_FREEBSD_
        arguments << "-c" << QString("%1 | grep \"%2\"").arg(this->getSetting("system", "mount").toString()).arg(cdrom_mount);

            QProcess myProcess;
            myProcess.start(this->getSetting("system", "sh").toString(), arguments);
            if (!myProcess.waitForFinished()){
                  qDebug() << "Make failed:" << myProcess.errorString();
                  return QString();
            }

            image = myProcess.readAll();

#ifdef DEBUG
        qDebug()<<"corelib::getMountedImages:image"<<image;
#endif

            if (!image.isEmpty()){
                  image = image.split(" ").first();
                  if (!image.isEmpty()){
                              if (image.contains("md")){
                                    myProcess.close ();
                                    arguments.clear();
                                    arguments << "mdconfig" <<  "-l" << QString("-u%1").arg(image.mid(7));
                                    myProcess.start(this->getSetting("system", "sudo").toString(), arguments);
                                    if (!myProcess.waitForFinished()){
                                          qDebug() << "Make failed:" << myProcess.errorString();
                                          return QString();
                                    } else {
                                          image = myProcess.readAll();
                                          image = image.split("/").last().mid(0, image.split("/").last().length()-1);
                                    }
                              } else if (image.contains("fuseiso") || image.contains("q4wine-mount")){
#ifdef DEBUG
        qDebug()<<"corelib::getMountedImages fuseiso sub"<<image;
#endif
                                    QString filename;
                                    filename=QDir::homePath();
                                    filename.append("/.mtab.fuseiso");
                                    QFile file(filename);
                                    if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
                                          QTextStream in(&file);
                                          while (!in.atEnd()) {
                                                QString line = in.readLine();
#ifdef DEBUG
        qDebug()<<"corelib::getMountedImages:line"<<line;
#endif
                                                if (line.contains(cdrom_mount))
                                                      image = line.split(" ").first().split("/").last();
                                          }
                                    } else {
                                          image = "fuseiso [cant read $HOME/.mtab.fuseiso]";
                                    }
                              }
                        } else {
                              image = "none";
                        }
                  } else {
                        image = "none";
                  }
#endif

            return image;
            }


Generated by  Doxygen 1.6.0   Back to index