void PlacesView::onUnmountMount() { PlacesModel::ItemAction* action = static_cast<PlacesModel::ItemAction*>(sender()); if(!action->index().isValid()) return; PlacesModelMountItem* item = static_cast<PlacesModelMountItem*>(model_->itemFromIndex(action->index())); GMount* mount = item->mount(); MountOperation* op = new MountOperation(true, this); op->unmount(mount); op->wait(); }
PlacesModelMountItem* PlacesModel::itemFromMount(GMount* mount) { int rowCount = devicesRoot->rowCount(); for(int i = 0; i < rowCount; ++i) { PlacesModelItem* item = static_cast<PlacesModelItem*>(devicesRoot->child(i, 0)); if(item->type() == PlacesModelItem::Mount) { PlacesModelMountItem* mountItem = static_cast<PlacesModelMountItem*>(item); if(mountItem->mount() == mount) return mountItem; } } return NULL; }
void PlacesModel::onMountRemoved(GVolumeMonitor* monitor, GMount* mount, PlacesModel* pThis) { GVolume* vol = g_mount_get_volume(mount); qDebug() << "volume umounted: " << vol; if(vol) { // a volume is unmounted g_object_unref(vol); } else { // network mounts and others PlacesModelMountItem* item = pThis->itemFromMount(mount); if(item) { pThis->devicesRoot->removeRow(item->row()); } } }
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 PlacesModel::onMountChanged(GVolumeMonitor* monitor, GMount* mount, PlacesModel* pThis) { PlacesModelMountItem* item = pThis->itemFromMount(mount); if(item) item->update(); }