예제 #1
0
static gboolean
ignore_mount (GMount *mount)
{
  GFile *root;
  GVolume *volume;
  gboolean ret = TRUE;

  root = g_mount_get_root (mount);

  if (g_file_has_uri_scheme (root, "burn") != FALSE || g_file_has_uri_scheme (root, "cdda") != FALSE) {
    /* We don't add Audio CDs, or blank media */
    g_object_unref (root);
    GRL_DEBUG ("%s: Not adding mount %s as is burn or cdda", __FUNCTION__,
               g_mount_get_name (mount));
    return TRUE;
  }
  g_object_unref (root);

  volume = g_mount_get_volume (mount);
  if (volume == NULL)
    return ret;

  ret = ignore_volume (volume);
  g_object_unref (volume);

  return ret;
}
예제 #2
0
static gboolean
rb_ipod_db_load (RbIpodDb *ipod_db, GMount *mount)
{
	GFile *mount_root;
	char *mount_path;
	const Itdb_IpodInfo *info;
	RbIpodDbPrivate *priv = IPOD_DB_GET_PRIVATE (ipod_db);

	mount_root = g_mount_get_root (mount);
	if (mount_root == NULL) {
		return FALSE;
	}
	mount_path = g_file_get_path (mount_root);
	g_object_unref (mount_root);

 	priv->itdb = itdb_parse (mount_path, NULL);
	g_free (mount_path);

        if (priv->itdb == NULL) {
		return FALSE;
        }

	info = itdb_device_get_ipod_info (priv->itdb->device);
	if (info->ipod_generation == ITDB_IPOD_GENERATION_UNKNOWN ||
	    info->ipod_generation == ITDB_IPOD_GENERATION_SHUFFLE_1 ||
	    info->ipod_generation == ITDB_IPOD_GENERATION_SHUFFLE_2 ||
	    info->ipod_generation == ITDB_IPOD_GENERATION_SHUFFLE_3) {
		priv->needs_shuffle_db = TRUE;
	} else {
		priv->needs_shuffle_db = FALSE;
	}

        return TRUE;
}
예제 #3
0
static void
device_chooser_changed_cb (GtkWidget  *widget,
			   DialogData *data)
{
	GtkTreeIter  iter;
	GMount      *mount;

	if (! gtk_combo_box_get_active_iter (GTK_COMBO_BOX (data->device_chooser), &iter)) {
		_g_clear_object (&data->source);
		_g_clear_object (&data->last_source);
		gth_file_list_clear (GTH_FILE_LIST (data->file_list), _("(Empty)"));
		return;
	}

	gtk_tree_model_get (GTK_TREE_MODEL (data->device_list_store), &iter,
			    SOURCE_LIST_COLUMN_MOUNT, &mount,
			    -1);

	if (mount == NULL) {
		_g_clear_object (&data->source);
		_g_clear_object (&data->last_source);
		gth_file_list_clear (GTH_FILE_LIST (data->file_list), _("Empty"));
		return;
	}

	_g_object_unref (data->source);
	data->source = g_mount_get_root (mount);
	load_file_list (data);

	g_object_unref (mount);
}
예제 #4
0
static GtkWidget *
panel_menu_item_mount_new (GMount *mount)
{
	GtkWidget *item;
	GFile     *root;
	GIcon     *icon;
	char      *display_name;
	char      *activation_uri;

	icon = g_mount_get_icon (mount);
	display_name = g_mount_get_name (mount);

	root = g_mount_get_root (mount);
	activation_uri = g_file_get_uri (root);
	g_object_unref (root);

	item = panel_menu_item_uri_new (activation_uri, NULL, icon,
					display_name,
					display_name, //FIXME tooltip
					G_CALLBACK (activate_uri));

	g_object_unref (icon);
	g_free (display_name);
	g_free (activation_uri);

	return item;
}
예제 #5
0
void GioLister::UpdateDeviceFreeSpace(const QString& id) {
  {
    QMutexLocker l(&mutex_);
    if (!devices_.contains(id))
      return;

    DeviceInfo& device_info = devices_[id];

    GFile* root = g_mount_get_root(device_info.mount);

    GError* error = NULL;
    GFileInfo* info = g_file_query_filesystem_info(
        root, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, &error);
    if (error) {
      qLog(Warning) << error->message;
      g_error_free(error);
    } else {
      device_info.filesystem_free = g_file_info_get_attribute_uint64(
          info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
      g_object_unref(info);
    }

    g_object_unref(root);
  }

  emit DeviceChanged(id);
}
예제 #6
0
static char *
shell_util_get_file_display_name_if_mount (GFile *file)
{
  GFile *compare;
  GVolumeMonitor *monitor;
  GList *mounts, *l;
  char *ret;

  ret = NULL;

  /* compare with all mounts */
  monitor = g_volume_monitor_get ();
  mounts = g_volume_monitor_get_mounts (monitor);
  for (l = mounts; l != NULL; l = l->next)
    {
      GMount *mount;
      mount = G_MOUNT(l->data);
      compare = g_mount_get_root (mount);
      if (!ret && g_file_equal (file, compare))
        ret = g_mount_get_name (mount);
      g_object_unref (mount);
    }
  g_list_free (mounts);
  g_object_unref (monitor);

  return ret;
}
예제 #7
0
static gboolean
bookmark_location_mounted_callback (NemoBookmark *bookmark,
                                    GFile *location,
                                    NemoBookmarkList *bookmarks)
{
    gboolean ret = FALSE;

    GList *volumes = g_volume_monitor_get_mounts (bookmarks->volume_monitor);
    GList *iter = volumes;

    while (iter != NULL) {
        GMount *mount = G_MOUNT (iter->data);
        GFile *mount_location = g_mount_get_root (mount);

        gchar *mount_root_uri = g_file_get_uri (mount_location);
        gchar *location_uri = g_file_get_uri (location);

        ret = g_str_has_prefix (location_uri, mount_root_uri);

        g_free (mount_root_uri);
        g_free (location_uri);

        g_object_unref (mount_location);

        if (ret == TRUE)
            break;

        iter = iter->next;
    }

    g_list_free_full (volumes, (GDestroyNotify) g_object_unref);

    return ret;
}
gchar *
rb_uri_get_mount_point (const char *uri)
{
	GFile *file;
	GMount *mount;
	char *mountpoint;
	GError *error = NULL;

	file = g_file_new_for_uri (uri);
	mount = g_file_find_enclosing_mount (file, NULL, &error);
	if (error != NULL) {
		if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) == FALSE) {
			rb_debug ("finding mount for %s: %s", uri, error->message);
		}
		g_error_free (error);
		mountpoint = NULL;
	} else {
		GFile *root;
		root = g_mount_get_root (mount);
		mountpoint = g_file_get_uri (root);
		g_object_unref (root);
		g_object_unref (mount);
	}

	g_object_unref (file);
	return mountpoint;
}
예제 #9
0
파일: gvfs-ls.c 프로젝트: snnw/gvfs
static void
print_mounts (const char *prefix)
{
  GList *l;
  GList *mounts;
  GVolumeMonitor *volume_monitor;

  volume_monitor = g_volume_monitor_get ();
  
  mounts = g_volume_monitor_get_mounts (volume_monitor);
  if (mounts != NULL)
    {
      for (l = mounts; l != NULL; l = l->next)
        {
          GMount *mount = l->data;
          GFile *mount_root;
          char *uri;
          
          mount_root = g_mount_get_root (mount);
          uri = g_file_get_uri (mount_root);
          if (prefix == NULL ||
              g_str_has_prefix (uri, prefix))
            g_print ("%s\n", uri);
          g_free (uri);
          g_object_unref (mount_root);
          g_object_unref (mount);
        }
      g_list_free (mounts);
    }
  g_object_unref (volume_monitor);

  if (prefix == NULL || g_str_has_prefix ("file:///", prefix))
    g_print ("file:///\n");
}
예제 #10
0
void on_mount_added(GVolumeMonitor* vm, GMount* mount, gpointer user_data)
{
    FmPlacesModel* model = FM_PLACES_MODEL(user_data);
    GVolume* vol = g_mount_get_volume(mount);
    if(vol)
    {
        FmPlaceItem *item;
        GtkTreeIter it;
        item = find_vol(model, vol, &it);
        if(item && item->type == FM_PLACES_ITEM_VOL && !item->fi->path)
        {
            GtkTreePath* tp;
            GFile* gf = g_mount_get_root(mount);
            FmPath* path = fm_path_new_for_gfile(gf);
            g_debug("mount path: %s", path->name);
            g_object_unref(gf);
            fm_file_info_set_path(item->fi, path);
            if(path)
                fm_path_unref(path);
            item->vol_mounted = TRUE;

            /* inform the view to update mount indicator */
            tp = gtk_tree_model_get_path(GTK_TREE_MODEL(model), &it);
            gtk_tree_model_row_changed(GTK_TREE_MODEL(model), tp, &it);
            gtk_tree_path_free(tp);
        }
        g_object_unref(vol);
    }
}
예제 #11
0
static guint
impl_want_uri (RBSource *source, const char *uri)
{
	GVolume *volume;
	GMount *mount;
	GFile *file;
	int retval;

	retval = 0;

	file = g_file_new_for_uri (uri);
	if (g_file_has_uri_scheme (file, "cdda") == FALSE) {
		g_object_unref (file);
		return 0;
	}

	g_object_get (G_OBJECT (source),
		      "volume", &volume,
		      NULL);
	if (volume == NULL)
		return 0;

	mount = g_volume_get_mount (volume);
	if (mount) {
		GFile *root;

		root = g_mount_get_root (mount);
		retval = g_file_equal (root, file) ? 100 : 0;
		g_object_unref (mount);
		g_object_unref (root);
	}
	g_object_unref (file);

	return retval;
}
예제 #12
0
파일: main.c 프로젝트: Remmy/afterstep
static gboolean
check_audio_cd (GVolume *volume)
{
	GFile *file;
	char *activation_uri;
	GMount *mount;

	if (!volume)
		return FALSE;

	mount = g_volume_get_mount (volume);
	if (!mount)
	    return FALSE;

	file = g_mount_get_root (mount);
	g_object_unref (mount);

	if (!file)
		return FALSE;

	activation_uri = g_file_get_uri (file);

	g_object_unref (file);

	/* we have an audioCD if the activation URI starts by 'cdda://' */
	gboolean result = (strncmp ("cdda://", activation_uri, 7) == 0);
	g_free (activation_uri);
	return result;
}
예제 #13
0
static void
panel_menu_item_append_mount (GtkWidget *menu,
			      GMount    *mount)
{
	GFile  *root;
	GIcon  *icon;
	char   *display_name;
	char   *activation_uri;

	icon = g_mount_get_icon (mount);
	display_name = g_mount_get_name (mount);

	root = g_mount_get_root (mount);
	activation_uri = g_file_get_uri (root);
	g_object_unref (root);

	panel_menu_items_append_place_item (NULL, icon,
					    display_name,
					    display_name, //FIXME tooltip
					    menu,
					    G_CALLBACK (activate_uri),
					    activation_uri);

	g_object_unref (icon);
	g_free (display_name);
	g_free (activation_uri);
}
예제 #14
0
static gboolean
can_delete_directory (RBAndroidSource *source, GFile *dir)
{
	GMount *mount;
	GFile *root;
	char *path;
	int i;
	int c;

	g_object_get (source, "mount", &mount, NULL);
	root = g_mount_get_root (mount);
	g_object_unref (mount);

	/*
	 * path here will be sdcard/Music/something for anything we want to delete
	 */
	path = g_file_get_relative_path (root, dir);
	c = 0;
	for (i = 0; path[i] != '\0'; i++) {
		if (path[i] == '/')
			c++;
	}

	g_free (path);
	return (c > 1);
}
예제 #15
0
static void
unmount_all_with_scheme (const char *scheme)
{
  GVolumeMonitor *volume_monitor;
  GList *mounts;
  GList *l;

  volume_monitor = g_volume_monitor_get();

  /* populate gvfs network mounts */
  iterate_gmain();

  mounts = g_volume_monitor_get_mounts (volume_monitor);
  for (l = mounts; l != NULL; l = l->next) {
    GMount *mount = G_MOUNT (l->data);
    GFile *root;

    root = g_mount_get_root (mount);
    if (g_file_has_uri_scheme (root, scheme)) {
            unmount (root);
    }
    g_object_unref (root);
  }
  g_list_foreach (mounts, (GFunc)g_object_unref, NULL);
  g_list_free (mounts);

  g_object_unref (volume_monitor);
}
예제 #16
0
static void on_dlg_response(GtkDialog* dlg, int res, gpointer user_data)
{
    AutoRun* data = (AutoRun*)user_data;

    /* stop the detection */
    g_cancellable_cancel(data->cancel);

    if(res == GTK_RESPONSE_OK)
    {
        GtkTreeModel* model;
        GtkTreeSelection* sel = gtk_tree_view_get_selection(data->view);
        GtkTreeIter it;
        if( gtk_tree_selection_get_selected(sel, &model, &it) )
        {
            GAppInfo* app;
            gtk_tree_model_get(model, &it, 2, &app, -1);
            if(app)
            {
                GFile* gf = g_mount_get_root(data->mount);
                GList* filelist = g_list_prepend(NULL, gf);
                g_app_info_launch(app, filelist, NULL, NULL);
                g_list_free(filelist);
                g_object_unref(gf);
                g_object_unref(app);
            }
            else
            {
                GFile* gf = g_mount_get_root(data->mount);
                FmPath* path = fm_path_new_for_gfile(gf);
                fm_main_win_add_win(NULL, path);
                fm_path_unref(path);
                g_object_unref(gf);
            }
        }
    }
    g_signal_handlers_disconnect_by_func(dlg, on_dlg_response, data);
    g_signal_handlers_disconnect_by_func(data->view, on_row_activated, data);
    g_signal_handlers_disconnect_by_func(data->mount, on_unmount, data);
    gtk_widget_destroy(GTK_WIDGET(dlg));

    g_object_unref(data->cancel);
    g_object_unref(data->store);
    g_object_unref(data->mount);
    g_slice_free(AutoRun, data);

    pcmanfm_unref();
}
static void
rb_removable_media_manager_add_mount (RBRemovableMediaManager *mgr, GMount *mount)
{
	RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (mgr);
	RBSource *source = NULL;
	GVolume *volume;
	GFile *mount_root;
	char *mountpoint;
	MPIDDevice *device_info;

	g_assert (mount != NULL);

	if (g_hash_table_lookup (priv->mount_mapping, mount) != NULL) {
		return;
	}
	if (g_mount_is_shadowed (mount) != FALSE) {
		return;
	}
	volume = g_mount_get_volume (mount);
	if (volume == NULL) {
		rb_debug ("Unhandled media, no volume for mount");
		return;
	}

	/* if we've already created a source for the volume,
	 * don't do anything with the mount.
	 */
	if (g_hash_table_lookup (priv->volume_mapping, volume) != NULL) {
		rb_debug ("already created a source for the volume, so ignoring the mount");
		g_object_unref (volume);
		return;
	}

	dump_volume_identifiers (volume);
	g_object_unref (volume);

	/* look the device up in the device info database */
	mount_root = g_mount_get_root (mount);
	if (mount_root == NULL) {
		rb_debug ("unable to get mount root, can't create a source for this mount");
		return;
	}
	mountpoint = g_file_get_path (mount_root);
	g_object_unref (mount_root);

	device_info = mpid_device_new (mountpoint);
	g_free (mountpoint);

	g_signal_emit (G_OBJECT (mgr), rb_removable_media_manager_signals[CREATE_SOURCE_MOUNT], 0, mount, device_info, &source);

	if (source) {
		g_hash_table_insert (priv->mount_mapping, mount, source);
		rb_removable_media_manager_append_media_source (mgr, source);
	} else {
		rb_debug ("Unhandled media");
	}

	g_object_unref (device_info);
}
예제 #18
0
gboolean
rb_ipod_helpers_is_ipod (GMount *mount, MPIDDevice *device_info)
{
	GFile *root;
	gboolean result = FALSE;
	char **protocols;

	/* if we have specific information about the device, use it.
	 * otherwise, check if the device has an ipod device directory on it.
	 */
	g_object_get (device_info, "access-protocols", &protocols, NULL);
	if (protocols != NULL && g_strv_length (protocols) > 0) {
		int i;

		for (i = 0; protocols[i] != NULL; i++) {
			if (g_str_equal (protocols[i], "ipod")) {
				result = TRUE;
				break;
			}
		}
	} else {
		root = g_mount_get_root (mount);
		if (root != NULL) {
			gchar *device_dir;

			if (g_file_has_uri_scheme (root, "afc") != FALSE) {
				gchar *uri;
				uri = g_file_get_uri (root);
				/* afc://<40 chars>:stuff */
				g_assert (strlen (uri) >= 46);
				if (uri[6 + 40] == ':' &&
				    uri[6 + 40 + 1] != '1') {
					result = FALSE;
				} else {
					result = TRUE;
				}
				g_free (uri);
			} else {
				gchar *mount_point;
				mount_point = g_file_get_path (root);
				if (mount_point != NULL) {
					device_dir = itdb_get_device_dir (mount_point);
					if (device_dir != NULL)  {
						result = g_file_test (device_dir,
								      G_FILE_TEST_IS_DIR);
						g_free (device_dir);
					}
				}

				g_free (mount_point);
			}
			g_object_unref (root);
		}
	}

	g_strfreev (protocols);
	return result;
}
예제 #19
0
static GList *
add_volume (GList *media_list,
            GVolume *volume,
            GDrive *drive,
            GrlOpticalMediaSource *source)
{
  char *name, *icon_uri;
  GIcon *icon;
  char *device_path, *id;
  GrlMedia * media;
  GMount *mount;

  device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
  if (device_path == NULL)
    return media_list;

  /* Is it an audio CD or a blank media */
  mount = g_volume_get_mount (volume);
  if (mount != NULL) {
    GFile *root;

    root = g_mount_get_root (mount);
    g_object_unref (mount);

    if (g_file_has_uri_scheme (root, "burn") != FALSE || g_file_has_uri_scheme (root, "cdda") != FALSE) {
      /* We don't add Audio CDs, or blank media */
      g_object_unref (root);
      g_free (device_path);
      return media_list;
    }
    g_object_unref (root);
  }

  media = grl_media_video_new ();

  id = g_filename_to_uri (device_path, NULL, NULL);
  g_free (device_path);

  grl_media_set_id (media, id);
  g_free (id);

  /* Work out an icon to display */
  icon = g_volume_get_icon (volume);
  icon_uri = get_uri_for_gicon (icon);
  g_object_unref (icon);
  grl_media_set_thumbnail (media, icon_uri);
  g_free (icon_uri);

  /* Get the volume's pretty name for the menu label */
  name = g_volume_get_name (volume);
  g_strstrip (name);
  grl_media_set_title (media, name);
  g_free (name);

  grl_media_set_mime (media, "x-special/device-block");

  return g_list_prepend (media_list, media);
}
예제 #20
0
static GFile* get_volume_root(GVolume* volume) {
	GFile* root = NULL;
	if (is_sdb(volume)) {
		GMount* mount = g_volume_get_mount(volume);
		root = g_mount_get_root(mount);
		g_object_unref(mount);
	}
	return root;
}
예제 #21
0
// -------------------------------------------------------------------------------- //
void guGIO_VolumeMonitor::OnMountAdded( GMount * mount )
{
    guLogMessage( wxT( "Mount Added..." ) );
    if( FindMount( mount ) == wxNOT_FOUND )
    {
        if( g_mount_is_shadowed( mount ) )
        {
            //g_object_unref( mount );
            guLogMessage( wxT( "ignored shadowed mount" ) );
            return;
        }

        GVolume * Volume = g_mount_get_volume( mount );
        if( !Volume )
        {
            guLogMessage( wxT( "mount without volume?" ) );
            //g_object_unref( mount );
            return;
        }
        g_object_unref( Volume );

        GFile * MountRoot = g_mount_get_root( mount );
        if( MountRoot )
        {
            char * mount_path = g_file_get_path( MountRoot );
            if( mount_path )
            {
                wxString MountPath = wxString( mount_path, wxConvUTF8 );
                guGIO_Mount * Mount = new guGIO_Mount( mount, MountPath );
                if( Mount )
                {
                    m_MountedVolumes->Add( Mount );

                    wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, ID_VOLUMEMANAGER_MOUNT_CHANGED );
                    event.SetInt( 1 );
                    wxPostEvent( m_MainFrame, event );
                }

                g_free( mount_path );
            }

            g_object_unref( MountRoot );
        }
        else
        {
            guLogMessage( wxT( "ignored mount without mount root" ) );
            g_object_unref( mount );
            return;
        }
    }
    else
    {
        guLogMessage( wxT( "Mount already added?" ) );
    }
}
static GObject *
impl_constructor (GType type,
		  guint n_construct_properties,
		  GObjectConstructParam *construct_properties)
{
	RBGenericPlayerSource *source;
	RBGenericPlayerSourcePrivate *priv;
	GMount *mount;
	char *mount_name;
	RBShell *shell;
	GFile *root;
	GFileInfo *info;
	GError *error = NULL;

	source = RB_GENERIC_PLAYER_SOURCE (G_OBJECT_CLASS (rb_generic_player_source_parent_class)->
					   constructor (type, n_construct_properties, construct_properties));

	priv = GENERIC_PLAYER_SOURCE_GET_PRIVATE (source);

	g_object_get (source, "shell", &shell, NULL);

	g_object_get (shell, "db", &priv->db, NULL);
	
	priv->import_errors = rb_import_errors_source_new (shell, priv->error_type);

	g_object_unref (shell);

	g_object_get (source, "mount", &mount, NULL);

	root = g_mount_get_root (mount);
	mount_name = g_mount_get_name (mount);

	info = g_file_query_filesystem_info (root, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, NULL, &error);
	if (error != NULL) {
		rb_debug ("error querying filesystem info for %s: %s", mount_name, error->message);
		g_error_free (error);
		priv->read_only = FALSE;
	} else {
		priv->read_only = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY);
		g_object_unref (info);
	}

	g_free (mount_name);
	g_object_unref (root);
	g_object_unref (mount);

	priv->folder_depth = -1;	/* 0 is a possible value, I guess */
	priv->playlist_format_unknown = TRUE;

	get_device_info (source);

	load_songs (source);

	return G_OBJECT (source);
}
예제 #23
0
static void update_vol(FmPlacesModel* model, FmPlaceItem* item, GtkTreeIter* it, FmFileInfoJob* job)
{
    FmIcon* icon;
    GIcon* gicon;
    char* name;
    GdkPixbuf* pix;
    GMount* mount;
    FmPath* path;

    name = g_volume_get_name(item->vol);
    if(item->fi->icon)
        fm_icon_unref(item->fi->icon);
    gicon = g_volume_get_icon(item->vol);
    icon = fm_icon_from_gicon(gicon);
    item->fi->icon = icon;
    g_object_unref(gicon);

    mount = g_volume_get_mount(item->vol);
    if(mount)
    {
        GFile* gf = g_mount_get_root(mount);
        path = fm_path_new_for_gfile(gf);
        g_object_unref(gf);
        g_object_unref(mount);
        item->vol_mounted = TRUE;
    }
    else
    {
        path = NULL;
        item->vol_mounted = FALSE;
    }

    if(!fm_path_equal(item->fi->path, path))
    {
        fm_file_info_set_path(item->fi, path);
        if(path)
        {
            if(job)
                fm_file_info_job_add(job, path);
            else
            {
                job = fm_file_info_job_new(NULL, FM_FILE_INFO_JOB_FOLLOW_SYMLINK);
                model->jobs = g_slist_prepend(model->jobs, job);
                g_signal_connect(job, "finished", G_CALLBACK(on_file_info_job_finished), model);
                fm_job_run_async(FM_JOB(job));
            }
            fm_path_unref(path);
        }
    }

    pix = fm_icon_get_pixbuf(item->fi->icon, fm_config->pane_icon_size);
    gtk_list_store_set(GTK_LIST_STORE(model), it, FM_PLACES_MODEL_COL_ICON, pix, FM_PLACES_MODEL_COL_LABEL, name, -1);
    g_object_unref(pix);
    g_free(name);
}
예제 #24
0
static char *
create_mount_id (GMount *mount)
{
  GFile *root;
  char *uri;

  root = g_mount_get_root (mount);
  uri = g_file_get_uri (root);
  g_object_unref (root);

  return uri;
}
예제 #25
0
void activate_row(FmPlacesView* view, guint button, GtkTreePath* tree_path)
{
    GtkTreeIter it;
    if(gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &it, tree_path))
    {
        FmPlaceItem* item;
        FmPath* path;
        gtk_tree_model_get(GTK_TREE_MODEL(model), &it, FM_PLACES_MODEL_COL_INFO, &item, -1);
        if(!item)
            return;
        switch(item->type)
        {
        case FM_PLACES_ITEM_PATH:
            path = fm_path_ref(item->fi->path);
            break;
        case FM_PLACES_ITEM_VOL:
        {
            GFile* gf;
            GMount* mnt = g_volume_get_mount(item->vol);
            if(!mnt)
            {
                GtkWindow* parent = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view)));
                if(!fm_mount_volume(parent, item->vol, TRUE))
                    return;
                mnt = g_volume_get_mount(item->vol);
                if(!mnt)
                {
                    g_debug("GMount is invalid after successful g_volume_mount().\nThis is quite possibly a gvfs bug.\nSee https://bugzilla.gnome.org/show_bug.cgi?id=552168");
                    return;
                }
            }
            gf = g_mount_get_root(mnt);
            g_object_unref(mnt);
            if(gf)
            {
                path = fm_path_new_for_gfile(gf);
                g_object_unref(gf);
            }
            else
                path = NULL;
            break;
        }
        default:
            return;
        }

        if(path)
        {
            g_signal_emit(view, signals[CHDIR], 0, button, path);
            fm_path_unref(path);
        }
    }
}
예제 #26
0
int32_t dt_camera_import_backup_job_run(dt_job_t *job)
{
  // copy sourcefile to each found destination
  dt_camera_import_backup_t *t = (dt_camera_import_backup_t *)job->param;
  GVolumeMonitor *vmgr= g_volume_monitor_get();
  GList *mounts=g_volume_monitor_get_mounts(vmgr);
  GMount *mount=NULL;
  GFile *root=NULL;
  if( mounts !=NULL )
    do
    {
      mount=G_MOUNT(mounts->data);
      if( ( root=g_mount_get_root( mount ) ) != NULL )
      {
        // Got the mount point lets check for backup folder
        gchar *backuppath=NULL;
        gchar *rootpath=g_file_get_path(root);
        backuppath=g_build_path(G_DIR_SEPARATOR_S,rootpath,dt_conf_get_string("plugins/capture/backup/foldername"),(char *)NULL);
        g_free(rootpath);

        if( g_file_test(backuppath,G_FILE_TEST_EXISTS)==TRUE)
        {
          // Found a backup storage, lets copy file here..
          gchar *destinationfile=g_build_filename(G_DIR_SEPARATOR_S,backuppath,t->destinationfile,(char *)NULL);
          if( g_mkdir_with_parents(g_path_get_dirname(destinationfile),0755) >= 0 )
          {
            gchar *content;
            gsize size;
            if( g_file_get_contents(t->sourcefile,&content,&size,NULL) == TRUE )
            {
              GError *err=NULL;
              if( g_file_set_contents(destinationfile,content,size,&err) != TRUE)
              {
                fprintf(stderr,"Failed to set content of file with reason: %s\n",err->message);
                g_error_free(err);
              }
              g_free(content);
            }
          }
          g_free(destinationfile);
        }

        g_free(backuppath);
      }
    }
    while( (mounts=g_list_next(mounts)) !=NULL);

  // Release volume manager
  g_object_unref(vmgr);
  return 0;
}
예제 #27
0
static gboolean
ensure_loaded (RBAndroidSource *source)
{
	RBAndroidSourcePrivate *priv = GET_PRIVATE (source);
	RBSourceLoadStatus status;
	RhythmDBEntryType *entry_type;
	GMount *mount;
	GFile *root;
	RBTaskList *tasklist;
	RBShell *shell;
	char *name;
	char *label;

	if (priv->loaded) {
		g_object_get (source, "load-status", &status, NULL);
		return (status == RB_SOURCE_LOAD_STATUS_LOADED);
	}

	priv->loaded = TRUE;
	rb_media_player_source_load (RB_MEDIA_PLAYER_SOURCE (source));

	/* identify storage containers and find music dirs within them */
	g_object_get (source, "mount", &mount, "entry-type", &entry_type, NULL);
	root = g_mount_get_root (mount);
	g_object_unref (mount);

	priv->cancel = g_cancellable_new ();
	priv->import_job = rhythmdb_import_job_new (priv->db, entry_type, priv->ignore_type, priv->error_type);
	g_signal_connect_object (priv->import_job, "complete", G_CALLBACK (import_complete_cb), source, 0);

	priv->scanned = 0;
	g_queue_init (&priv->to_scan);
	g_queue_push_tail (&priv->to_scan, root);
	g_object_unref (entry_type);

	find_music_dirs (RB_ANDROID_SOURCE (source));

	g_object_get (source, "name", &name, "shell", &shell, NULL);
	label = g_strdup_printf (_("Scanning %s"), name);
	g_object_set (priv->import_job, "task-label", label, NULL);

	g_object_get (shell, "task-list", &tasklist, NULL);
	rb_task_list_add_task (tasklist, RB_TASK_PROGRESS (priv->import_job));
	g_object_unref (tasklist);
	g_object_unref (shell);

	g_free (label);
	g_free (name);
	return FALSE;
}
예제 #28
0
static GFile *
find_music_dir (GMount *mount)
{
    GFile *root;
    GFile *music_dir = NULL;

    root = g_mount_get_root (mount);
    if (root != NULL) {
        music_dir = find_dir_no_case (root, TRUE);
        /* FIXME create directories if they don't exist */
        g_object_unref (root);
    }

    return music_dir;
}
예제 #29
0
파일: fm-gtk-utils.c 프로젝트: lxde/libfm
static void prepare_unmount(GMount* mount)
{
    /* ensure that CWD is not on the mounted filesystem. */
    char* cwd_str = g_get_current_dir();
    GFile* cwd = g_file_new_for_path(cwd_str);
    GFile* root = g_mount_get_root(mount);
    g_free(cwd_str);
    /* FIXME: This cannot cover 100% cases since symlinks are not checked.
     * There may be other cases that cwd is actually under mount root
     * but checking prefix is not enough. We already did our best, though. */
    if(g_file_has_prefix(cwd, root))
        g_chdir("/");
    g_object_unref(cwd);
    g_object_unref(root);
}
예제 #30
0
static void on_mount_added(GObject* vm, GMount* mount, GtkWidget* window) {
	GFile* usb_root;
	GVolume* volume = g_mount_get_volume(mount);
	if (is_sdb(volume)) {
		usb_root = g_mount_get_root(mount);
		printf("USB drive plugged in.\n");
	}
	g_object_unref(volume);
	if (usb_root != NULL) {
		g_signal_handlers_disconnect_by_func(vm, G_CALLBACK(on_mount_added), NULL);
		g_signal_connect(vm, "mount-removed", G_CALLBACK(on_mount_removed), NULL);
		gtk_window_close(GTK_WINDOW(window));
		start_gui(usb_root);
	}
}