Esempio n. 1
0
QString KDesktopFile::readURL() const
{
    if(hasDeviceType())
    {
        QString device = readDevice();
        KMountPoint::List mountPoints = KMountPoint::possibleMountPoints();

        for(KMountPoint::List::ConstIterator it = mountPoints.begin(); it != mountPoints.end(); ++it)
        {
            KMountPoint *mp = *it;
            if(mp->mountedFrom() == device)
            {
                KURL u;
                u.setPath(mp->mountPoint());
                return u.url();
            }
        }
        return QString::null;
    }
    else
    {
        QString url = readPathEntry("URL");
        if(!url.isEmpty() && !QDir::isRelativePath(url))
        {
            // Handle absolute paths as such (i.e. we need to escape them)
            KURL u;
            u.setPath(url);
            return u.url();
        }
        return url;
    }
}
void ImageImporter::slotUpdateMountStatus() {
    QString str = m_cmbSourceDevice->currentText();

    QString mntDev = getCurrentMountDevice();

    m_bCurrentDeviceMounted = false;
    //find out if the current selection is mounted
    const KMountPoint::List lst = KMountPoint::currentMountPoints();
    for ( KMountPoint::List::ConstIterator it = lst.begin() ; it != lst.end() ; ++it ) {
        if ((*it)->mountedFrom() == mntDev) {
            m_bCurrentDeviceMounted = true;
            break;
        }
    }
    m_btnMountDevice->setEnabled(true);
    m_btnMountDevice->setOn(m_bCurrentDeviceMounted);

    if (m_bCurrentDeviceMounted) {
        insertItemTo(m_cmbSourceFolder, getCurrentMountPoint());
        m_cmbSourceFolder->setCurrentText(getCurrentMountPoint());
    } else {
        for (int i = 0; i < m_cmbSourceFolder->count(); ++i) {
            if (m_cmbSourceFolder->text(i) == getCurrentMountPoint()) {
                m_cmbSourceFolder->removeItem( i );
                ///@todo set the Settings::blubb item current, if available
                break;
            }
        }
    }
}
Esempio n. 3
0
void TrashImpl::scanTrashDirectories() const
{
    const KMountPoint::List lst = KMountPoint::currentMountPoints();
    for ( KMountPoint::List::ConstIterator it = lst.begin() ; it != lst.end() ; ++it ) {
        const TQCString str = (*it)->mountType().latin1();
        // Skip pseudo-filesystems, there's no chance we'll find a .Trash on them :)
        // ## Maybe we should also skip readonly filesystems
        if ( str != "proc" && str != "devfs" && str != "usbdevfs" &&
             str != "sysfs" && str != "devpts" && str != "subfs" /* #96259 */ &&
             str != "autofs" /* #101116 */ ) {
            TQString topdir = (*it)->mountPoint();
            TQString trashDir = trashForMountPoint( topdir, false );
            if ( !trashDir.isEmpty() ) {
                // OK, trashDir is a valid trash directory. Ensure it's registered.
                int trashId = idForTrashDirectory( trashDir );
                if ( trashId == -1 ) {
                    // new trash dir found, register it
                    m_trashDirectories.insert( ++m_lastId, trashDir );
                    kdDebug() << k_funcinfo << "found " << trashDir << " gave it id " << m_lastId << endl;
                    if ( !topdir.endsWith( "/" ) )
                        topdir += '/';
                    m_topDirectories.insert( m_lastId, topdir );
                }
            }
        }
    }
    m_trashDirectoriesScanned = true;
}
void ImageImporter::initData() {
    const KMountPoint::List lst = KMountPoint::possibleMountPoints(KMountPoint::NeedMountOptions);
    for ( KMountPoint::List::ConstIterator it = lst.begin() ; it != lst.end() ; ++it ) {
        //so, I only show devices that are mountable by a user
        if (getuid() == 0 || (*it)->mountOptions().grep("user").size() > 0) {
            QString x = QString("%1 (%2)").arg((*it)->mountedFrom()).arg((*it)->mountPoint());
            m_cmbSourceDevice->insertItem(x);
        }
    }
    //after adding all available mountpoints, check the status of the current
    slotUpdateMountStatus();

    m_cmbSourceFolder->insertItem(Settings::imageImporterSourceFolder());
    m_cmbSourceFolder->setCurrentText(Settings::imageImporterSourceFolder());
    m_cmbSourceDevice->setCurrentText(Settings::imageImporterSourceDevice());
    m_txtSourceFilename->setText(Settings::imageImporterSourceFilenameRegexp());
    m_chkIgnoreCase->setChecked(Settings::imageImporterFilenameIgnoreCase());
    m_chkSrcIncludeSubfolders->setChecked(Settings::imageImporterSourceIncludeSubfolders());
    m_chkSrcRemoveFilesFromSrc->setChecked(Settings::imageImporterSourceRemoveAfterTransfer());

    m_groupArchive->setChecked(Settings::imageImporterArchiveImages());
    m_txtArchiveBaseFolder->setText(Settings::imageImporterArchiveBaseFolder());
    m_txtArchiveSubfolders->setText(Settings::imageImporterArchiveSubfolders());
    m_txtArchiveFilename->setText(Settings::imageImporterArchiveFilename());
    m_chkArchiveLowercase->setChecked(Settings::imageImporterArchiveLowercaseFilenames());

    //add all dirs from the album to the list of target folders
    Folder* sourceDir;
    for (
          sourceDir = m_photobook->engine()->sourceDirs()->first();
          sourceDir;
          sourceDir = m_photobook->engine()->sourceDirs()->next()
        )
    {
        m_cmbDestBasefolder->insertItem(sourceDir->dir()->absPath());
    }

	if (m_cmbDestBasefolder->count() == 0) {
		QMessageBox::information( this, "No Folders Available",
                                  "There are no Folders in your album!<br>"
                                  "Either create a new album and add Folders to "
                                  "it, or open another available album." );
		
	}
    //m_cmbDestBasefolder->insertItem(Settings::imageImporterDestBaseFolder());
	
    m_cmbDestBasefolder->setCurrentText(Settings::imageImporterDestBaseFolder());
    m_txtDestSubfolders->setText(Settings::imageImporterDestSubfolders());
    m_txtDestFilename->setText(Settings::imageImporterDestFilenames());
    m_chkDestLowercase->setChecked(Settings::imageImporterDestLowercaseFilenames());

}
Esempio n. 5
0
void FreeSpaceWidget::slotTimeout()
{
    KMountPoint::List list = KMountPoint::currentMountPoints();

    foreach(const QString& path, d->paths)
    {
        KMountPoint::Ptr mp = list.findByPath(path);

        if (mp)
        {
            KDiskFreeSpace* const job = new KDiskFreeSpace(this);

            connect(job, SIGNAL(foundMountPoint(QString,quint64,quint64,quint64)),
                    this, SLOT(slotAvailableFreeSpace(QString,quint64,quint64,quint64)));

            job->readDF(mp->mountPoint());
        }
    }
}
Esempio n. 6
0
void RemovableBackend::handleMtabChange()
{
    QStringList new_mtabIds;
    KMountPoint::List mtab = KMountPoint::currentMountPoints();

    KMountPoint::List::iterator it = mtab.begin();
    KMountPoint::List::iterator end = mtab.end();

    for(; it != end; ++it)
    {
        QString dev = (*it)->mountedFrom();
        QString mp = (*it)->mountPoint();
        QString fs = (*it)->mountType();

        QString id = generateId(dev);
        new_mtabIds += id;

        if(!m_mtabIds.contains(id) && m_removableIds.contains(id))
        {
            m_mediaList.changeMediumState(id, dev, mp, fs, true, false, "media/removable_mounted");
        }
    }

    QStringList::iterator it2 = m_mtabIds.begin();
    QStringList::iterator end2 = m_mtabIds.end();

    for(; it2 != end2; ++it2)
    {
        if(!new_mtabIds.contains(*it2) && m_removableIds.contains(*it2))
        {
            m_mediaList.changeMediumState(*it2, false, false, "media/removable_unmounted");
        }
    }

    m_mtabIds = new_mtabIds;
}
Esempio n. 7
0
KMountPoint::List KMountPoint::currentMountPoints(int infoNeeded)
{
  KMountPoint::List result;

#ifdef HAVE_GETMNTINFO

#ifdef GETMNTINFO_USES_STATVFS
    struct statvfs *mounted;
#else
    struct statfs *mounted;
#endif

    int num_fs = getmntinfo(&mounted, MNT_NOWAIT);

    for (int i=0;i<num_fs;i++) 
    {
      KMountPoint *mp = new KMountPoint();
      mp->m_mountedFrom = TQFile::decodeName(mounted[i].f_mntfromname);
      mp->m_mountPoint = TQFile::decodeName(mounted[i].f_mntonname);

#ifdef __osf__
      mp->m_mountType = TQFile::decodeName(mnt_names[mounted[i].f_type]);
#else
      mp->m_mountType = TQFile::decodeName(mounted[i].f_fstypename);
#endif      

      if (infoNeeded & NeedMountOptions)
      {
         struct fstab *ft = getfsfile(mounted[i].f_mntonname);
         TQString options = TQFile::decodeName(ft->fs_mntops);
         mp->m_mountOptions = TQStringList::split(',', options);
      }

      if (infoNeeded & NeedRealDeviceName)
      {
         if (mp->m_mountedFrom.startsWith("/"))
            mp->m_device = TDEStandardDirs::realPath(mp->m_mountedFrom);
      }
      // TODO: Strip trailing '/' ?
      result.append(mp);
   }

#elif defined(_AIX)

    struct vmount *mntctl_buffer;
    struct vmount *vm;
    char *mountedfrom;
    char *mountedto;
    int fsname_len, num;
    int buf_sz = 4096;

    mntctl_buffer = (struct vmount*)malloc(buf_sz);
    num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
    if (num == 0)
    {
	buf_sz = *(int*)mntctl_buffer;
	free(mntctl_buffer);
	mntctl_buffer = (struct vmount*)malloc(buf_sz);
	num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
    }

    if (num > 0)
    {
        /* iterate through items in the vmount structure: */
        vm = (struct vmount *)mntctl_buffer;
        for ( ; num > 0; num-- )
        {
            /* get the name of the mounted file systems: */
            fsname_len = vmt2datasize(vm, VMT_STUB);
            mountedto     = (char*)malloc(fsname_len + 1);
	    mountedto[fsname_len] = '\0';
            strncpy(mountedto, (char *)vmt2dataptr(vm, VMT_STUB), fsname_len);

            fsname_len = vmt2datasize(vm, VMT_OBJECT);
            mountedfrom     = (char*)malloc(fsname_len + 1);
	    mountedfrom[fsname_len] = '\0';
            strncpy(mountedfrom, (char *)vmt2dataptr(vm, VMT_OBJECT), fsname_len);

	    /* Look up the string for the file system type,
             * as listed in /etc/vfs.
             * ex.: nfs,jfs,afs,cdrfs,sfs,cachefs,nfs3,autofs
             */
            struct vfs_ent* ent = getvfsbytype(vm->vmt_gfstype);

            KMountPoint *mp = new KMountPoint();
            mp->m_mountedFrom = TQFile::decodeName(mountedfrom);
            mp->m_mountPoint = TQFile::decodeName(mountedto);
            mp->m_mountType = TQFile::decodeName(ent->vfsent_name);

            free(mountedfrom);
            free(mountedto);

            if (infoNeeded & NeedMountOptions)
            {
              // TODO
            }

            if (infoNeeded & NeedRealDeviceName)
            {
               if (mp->m_mountedFrom.startsWith("/"))
                  mp->m_device = TDEStandardDirs::realPath(mp->m_mountedFrom);
            }
            
            result.append(mp);

            /* goto the next vmount structure: */
            vm = (struct vmount *)((char *)vm + vm->vmt_length);
        }

	endvfsent( );
    }

    free( mntctl_buffer );
#elif defined(Q_WS_WIN)
    //TODO?
#else
   STRUCT_SETMNTENT mnttab;
   if ((mnttab = SETMNTENT(MNTTAB, "r")) == 0)
      return result;

   STRUCT_MNTENT fe;
   while (GETMNTENT(mnttab, fe))
   {
      KMountPoint *mp = new KMountPoint();
      mp->m_mountedFrom = TQFile::decodeName(FSNAME(fe));
         
      mp->m_mountPoint = TQFile::decodeName(MOUNTPOINT(fe));
      mp->m_mountType = TQFile::decodeName(MOUNTTYPE(fe));
      
      //Devices using supermount have their device names in the mount options
      //instead of the device field. That's why we need to read the mount options 
      if (infoNeeded & NeedMountOptions || (mp->m_mountType == "supermount"))
      {
         TQString options = TQFile::decodeName(MOUNTOPTIONS(fe));
         mp->m_mountOptions = TQStringList::split(',', options);
      }

      if (mp->m_mountType == "supermount")
         mp->m_mountedFrom = devNameFromOptions(mp->m_mountOptions);

      if (infoNeeded & NeedRealDeviceName)
      {
         if (mp->m_mountedFrom.startsWith("/"))
            mp->m_device = TDEStandardDirs::realPath(mp->m_mountedFrom);
      }
      // TODO: Strip trailing '/' ?
      result.append(mp);
   }
   ENDMNTENT(mnttab);
#endif
   return result;
}
Esempio n. 8
0
KMountPoint::List KMountPoint::possibleMountPoints(int infoNeeded)
{
  KMountPoint::List result;
  
#ifdef HAVE_SETMNTENT
   STRUCT_SETMNTENT fstab;
   if ((fstab = SETMNTENT(FSTAB, "r")) == 0)
      return result;

   STRUCT_MNTENT fe;
   while (GETMNTENT(fstab, fe))
   {
      KMountPoint *mp = new KMountPoint();
      mp->m_mountedFrom = TQFile::decodeName(FSNAME(fe));
         
      mp->m_mountPoint = TQFile::decodeName(MOUNTPOINT(fe));
      mp->m_mountType = TQFile::decodeName(MOUNTTYPE(fe));

      //Devices using supermount have their device names in the mount options
      //instead of the device field. That's why we need to read the mount options
      if (infoNeeded & NeedMountOptions || (mp->m_mountType == "supermount"))
      {
         TQString options = TQFile::decodeName(MOUNTOPTIONS(fe));
         mp->m_mountOptions = TQStringList::split(',', options);
      }

      if(mp->m_mountType == "supermount")
         mp->m_mountedFrom = devNameFromOptions(mp->m_mountOptions);
 
      if (infoNeeded & NeedRealDeviceName)
      {
         if (mp->m_mountedFrom.startsWith("/"))
            mp->m_device = TDEStandardDirs::realPath(mp->m_mountedFrom);
      }
      // TODO: Strip trailing '/' ?
      result.append(mp);
   }
   ENDMNTENT(fstab);
#else
   TQFile f(FSTAB);
   if ( !f.open(IO_ReadOnly) )
      return result;
     
   TQTextStream t (&f);
   TQString s;

   while (! t.eof()) 
   {
      s=t.readLine().simplifyWhiteSpace();
      if ( s.isEmpty() || (s[0] == '#'))
          continue;

      // not empty or commented out by '#'
      TQStringList item = TQStringList::split(' ', s);
        
#ifdef _OS_SOLARIS_
      if (item.count() < 5)
         continue;
#else
      if (item.count() < 4)
         continue;
#endif

      KMountPoint *mp = new KMountPoint();

      int i = 0;
      mp->m_mountedFrom = item[i++];
#ifdef _OS_SOLARIS_
      //device to fsck
      i++;
#endif
      mp->m_mountPoint = item[i++];
      mp->m_mountType = item[i++];
      TQString options = item[i++];

      if (infoNeeded & NeedMountOptions)
      {
         mp->m_mountOptions = TQStringList::split(',', options);
      }

      if (infoNeeded & NeedRealDeviceName)
      {
         if (mp->m_mountedFrom.startsWith("/"))
            mp->m_device = TDEStandardDirs::realPath(mp->m_mountedFrom);
      }
      // TODO: Strip trailing '/' ?
      result.append(mp);
   } //while

   f.close();
#endif
   return result;
}