void PlacesView::activateRow(int type, const QModelIndex& index) { if(!index.parent().isValid()) // ignore root items return; PlacesModelItem* item = static_cast<PlacesModelItem*>(model_->itemFromIndex(index)); if(item) { FmPath* path = item->path(); if(!path) { // check if mounting volumes is needed if(item->type() == PlacesModelItem::Volume) { PlacesModelVolumeItem* volumeItem = static_cast<PlacesModelVolumeItem*>(item); if(!volumeItem->isMounted()) { // Mount the volume GVolume* volume = volumeItem->volume(); MountOperation* op = new MountOperation(true, this); op->mount(volume); // connect(op, SIGNAL(finished(GError*)), SLOT(onMountOperationFinished(GError*))); // blocking here until the mount operation is finished? // FIXME: update status of the volume after mount is finished!! if(!op->wait()) return; path = item->path(); } } } if(path) { Q_EMIT chdirRequested(type, path); } } }
void PlacesView::onEjectButtonClicked(PlacesModelItem* item) { // The eject button is clicked for a device item (volume or mount) if(item->type() == PlacesModelItem::Volume) { PlacesModelVolumeItem* volumeItem = static_cast<PlacesModelVolumeItem*>(item); MountOperation* op = new MountOperation(true, this); if(volumeItem->canEject()) // do eject if applicable op->eject(volumeItem->volume()); else // otherwise, do unmount instead op->unmount(volumeItem->volume()); } else if(item->type() == PlacesModelItem::Mount) { PlacesModelMountItem* mountItem = static_cast<PlacesModelMountItem*>(item); MountOperation* op = new MountOperation(true, this); op->unmount(mountItem->mount()); } qDebug("PlacesView::onEjectButtonClicked"); }
void PlacesView::onEjectVolume() { PlacesModel::ItemAction* action = static_cast<PlacesModel::ItemAction*>(sender()); if(!action->index().isValid()) return; PlacesModelVolumeItem* item = static_cast<PlacesModelVolumeItem*>(model_->itemFromIndex(action->index())); MountOperation* op = new MountOperation(true, this); op->eject(item->volume()); op->wait(); }
PlacesModelVolumeItem* PlacesModel::itemFromVolume(GVolume* volume) { int rowCount = devicesRoot->rowCount(); for(int i = 0; i < rowCount; ++i) { PlacesModelItem* item = static_cast<PlacesModelItem*>(devicesRoot->child(i, 0)); if(item->type() == PlacesModelItem::Volume) { PlacesModelVolumeItem* volumeItem = static_cast<PlacesModelVolumeItem*>(item); if(volumeItem->volume() == volume) return volumeItem; } } return NULL; }