Exemplo n.º 1
0
void PlacesModel::onMountAdded(GVolumeMonitor* monitor, GMount* mount, PlacesModel* pThis) {
  GVolume* vol = g_mount_get_volume(mount);
  if(vol) { // mount-added is also emitted when a volume is newly mounted.
    PlacesModelVolumeItem* item = pThis->itemFromVolume(vol);
    if(item && !item->path()) {
      // update the mounted volume and show a button for eject.
      GFile* gf = g_mount_get_root(mount);
      FmPath* path = fm_path_new_for_gfile(gf);
      g_object_unref(gf);
      item->setPath(path);
      if(path)
        fm_path_unref(path);
      // update the mount indicator (eject button)
      QStandardItem* ejectBtn = item->parent()->child(item->row(), 1);
      Q_ASSERT(ejectBtn);
      ejectBtn->setIcon(pThis->ejectIcon_);
    }
    g_object_unref(vol);
  }
  else { // network mounts and others
    PlacesModelMountItem* item = pThis->itemFromMount(mount);
    /* for some unknown reasons, sometimes we get repeated mount-added
     * signals and added a device more than one. So, make a sanity check here. */
    if(!item) {
      item = new PlacesModelMountItem(mount);
      QStandardItem* eject_btn = new QStandardItem(pThis->ejectIcon_, "");
      pThis->devicesRoot->appendRow(QList<QStandardItem*>() << item << eject_btn);
    }
  }
}
Exemplo n.º 2
0
void PlacesModel::onVolumeChanged(GVolumeMonitor* monitor, GVolume* volume, PlacesModel* pThis) {
  PlacesModelVolumeItem* item = pThis->itemFromVolume(volume);
  if(item) {
    item->update();
    if(!item->isMounted()) { // the volume is unmounted, remove the eject button if needed
      // remove the eject button for the volume (at column 1 of the same row)
      QStandardItem* ejectBtn = item->parent()->child(item->row(), 1);
      Q_ASSERT(ejectBtn);
      ejectBtn->setIcon(QIcon());
    }
  }
}