/* This is a somewhat hacky way to get FTP to almost work. The proper way to * get FTP to _really_ work involves hacking GIO to have APIs to handle * canoncial URLs. */ static GFile * webkit_soup_request_file_ensure_file_ftp (SoupURI *uri, GCancellable *cancellable, GError **error) { SoupURI *host; char *s; GFile *file, *result; GMount *mount; host = soup_uri_copy_host (uri); s = soup_uri_to_string (host, FALSE); file = g_file_new_for_uri (s); soup_uri_free (host); g_free (s); mount = g_file_find_enclosing_mount (file, cancellable, error); if (mount == NULL && g_file_supports_thread_contexts (file)) { GMainContext *context = g_main_context_new (); GMainLoop *loop = g_main_loop_new (context, FALSE); g_clear_error (error); g_main_context_push_thread_default (context); g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE, NULL, /* FIXME! */ cancellable, webkit_soup_request_file_ftp_main_loop_quit, loop); g_main_loop_run (loop); g_main_context_pop_thread_default (context); g_main_loop_unref (loop); g_main_context_unref (context); mount = g_file_find_enclosing_mount (file, cancellable, error); } if (mount == NULL) return NULL; g_object_unref (file); file = g_mount_get_default_location (mount); g_object_unref (mount); s = g_strdup (uri->path); if (strchr (s, ';')) *strchr (s, ';') = 0; result = g_file_resolve_relative_path (file, s); g_free (s); g_object_unref (file); return result; }
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; }
static void unmount (GFile *file) { GMount *mount; GError *error = NULL; GMountOperation *mount_op; GMountUnmountFlags flags; if (file == NULL) return; mount = g_file_find_enclosing_mount (file, NULL, &error); if (mount == NULL) { g_printerr (_("Error finding enclosing mount: %s\n"), error->message); success = FALSE; return; } mount_op = new_mount_op (); flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE; g_mount_unmount_with_operation (mount, flags, mount_op, NULL, unmount_done_cb, NULL); g_object_unref (mount_op); outstanding_mounts++; }
static void eject (GFile *file) { GMount *mount; GError *error = NULL; GMountOperation *mount_op; GMountUnmountFlags flags; if (file == NULL) return; mount = g_file_find_enclosing_mount (file, NULL, &error); if (mount == NULL) { print_file_error (file, error->message); success = FALSE; g_error_free (error); return; } mount_op = new_mount_op (); flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE; g_mount_eject_with_operation (mount, flags, mount_op, NULL, eject_done_cb, g_object_ref (file)); g_object_unref (mount_op); outstanding_mounts++; }
/** * gedit_utils_location_get_dirname_for_display * @file: the location * * Returns a string suitable to be displayed in the UI indicating * the name of the directory where the file is located. * For remote files it may also contain the hostname etc. * For local files it tries to replace the home dir with ~. * * Returns: a string to display the dirname */ gchar * gedit_utils_location_get_dirname_for_display (GFile *location) { gchar *uri; gchar *res; GMount *mount; g_return_val_if_fail (location != NULL, NULL); /* we use the parse name, that is either the local path * or an uri but which is utf8 safe */ uri = g_file_get_parse_name (location); /* FIXME: this is sync... is it a problem? */ mount = g_file_find_enclosing_mount (location, NULL, NULL); if (mount != NULL) { gchar *mount_name; gchar *path; mount_name = g_mount_get_name (mount); g_object_unref (mount); /* obtain the "path" patrt of the uri */ if (gedit_utils_decode_uri (uri, NULL, NULL, NULL, NULL, &path)) { gchar *dirname; dirname = gedit_utils_uri_get_dirname (path); res = g_strdup_printf ("%s %s", mount_name, dirname); g_free (path); g_free (dirname); g_free (mount_name); } else { res = mount_name; } } else { /* fallback for local files or uris without mounts */ res = gedit_utils_uri_get_dirname (uri); } g_free (uri); return res; }
int main (int argc, char *argv[]) { GVolumeMonitor *monitor; GFile *file; GMount *mount; bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init (&argc, &argv); if (argc != 2) { goto out; } /* instantiate monitor so we get the "unmounted" signal properly */ monitor = g_volume_monitor_get (); if (monitor == NULL) { goto out; } file = g_file_new_for_commandline_arg (argv[1]); if (file == NULL) { g_object_unref (monitor); goto out; } mount = g_file_find_enclosing_mount (file, NULL, NULL); if (mount == NULL) { g_object_unref (file); g_object_unref (monitor); goto out; } present_autorun_for_software_dialog (mount); g_object_unref (file); g_object_unref (monitor); g_object_unref (mount); out: return 0; }
int main (int argc, char *argv[]) { g_autoptr (GVolumeMonitor) monitor = NULL; g_autoptr (GFile) file = NULL; g_autoptr (GMount) mount = NULL; g_autoptr (GError) error = NULL; bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init (&argc, &argv); if (argc != 2) { g_print ("Usage: %s mount-uri\n", argv[0]); goto out; } /* instantiate monitor so we get the "unmounted" signal properly */ monitor = g_volume_monitor_get (); if (monitor == NULL) { g_warning ("Unable to connect to the volume monitor"); goto out; } file = g_file_new_for_commandline_arg (argv[1]); if (file == NULL) { g_warning ("Unable to parse mount URI"); goto out; } mount = g_file_find_enclosing_mount (file, NULL, &error); if (mount == NULL) { g_warning ("Unable to find device for URI: %s", error->message); goto out; } present_autorun_for_software_dialog (mount); out: return 0; }
/** * eog_util_file_is_persistent: * @file: a #GFile * * Checks whether @file is a non-removable local mount. * * Returns: %TRUE if @file is in a non-removable mount, * %FALSE otherwise or when it is remote. **/ gboolean eog_util_file_is_persistent (GFile *file) { GMount *mount; if (!g_file_is_native (file)) return FALSE; mount = g_file_find_enclosing_mount (file, NULL, NULL); if (mount) { if (g_mount_can_unmount (mount)) { return FALSE; } } return TRUE; }
GMount *_cd_find_mount_from_uri (const gchar *cURI, gchar **cTargetURI) { cd_message ("%s (%s)", __func__, cURI); gchar *_cTargetURI = _cd_find_target_uri (cURI); GMount *pMount = NULL; if (_cTargetURI != NULL) { cd_message (" pointe sur %s", _cTargetURI); GFile *file = g_file_new_for_uri (_cTargetURI); pMount = g_file_find_enclosing_mount (file, NULL, NULL); g_object_unref (file); } if (cTargetURI != NULL) *cTargetURI = _cTargetURI; else g_free (_cTargetURI); return pMount; }
static void unmount (GFile *file) { GMount *mount; GError *error = NULL; if (file == NULL) return; mount = g_file_find_enclosing_mount (file, NULL, &error); if (mount == NULL) { g_print ("Error finding enclosing mount: %s\n", error->message); return; } g_mount_unmount (mount, 0, NULL, unmount_done_cb, NULL); outstanding_mounts++; }
static GMount * totem_get_mount_for_uri (const char *path) { GMount *mount; GFile *file; file = g_file_new_for_path (path); mount = g_file_find_enclosing_mount (file, NULL, NULL); g_object_unref (file); if (mount == NULL) return NULL; /* FIXME: We used to explicitly check whether it was a CD/DVD */ if (g_mount_can_eject (mount) == TRUE) { g_object_unref (mount); return NULL; } return mount; }
static void eject (GFile *file) { GMount *mount; GError *error = NULL; GMountOperation *mount_op; if (file == NULL) return; mount = g_file_find_enclosing_mount (file, NULL, &error); if (mount == NULL) { g_printerr (_("Error finding enclosing mount: %s\n"), error->message); return; } mount_op = new_mount_op (); g_mount_eject_with_operation (mount, 0, mount_op, NULL, eject_done_cb, NULL); g_object_unref (mount_op); outstanding_mounts++; }
void GioLister::DeviceInfo::ReadMountInfo(GMount* mount) { // Get basic information this->mount.reset_without_add(mount); if (!mount) return; mount_name = ConvertAndFree(g_mount_get_name(mount)); // Get the icon name(s) mount_icon_names.clear(); GIcon* icon = g_mount_get_icon(mount); if (G_IS_THEMED_ICON(icon)) { const char* const * icons = g_themed_icon_get_names(G_THEMED_ICON(icon)); for (const char* const * p = icons ; *p ; ++p) { mount_icon_names << QString::fromUtf8(*p); } } g_object_unref(icon); GFile* root = g_mount_get_root(mount); // Get the mount path mount_path = ConvertAndFree(g_file_get_path(root)); mount_uri = ConvertAndFree(g_file_get_uri(root)); // Do a sanity check to make sure the root is actually this mount - when a // device is unmounted GIO sends a changed signal before the removed signal, // and we end up reading information about the / filesystem by mistake. GError* error = NULL; GMount* actual_mount = g_file_find_enclosing_mount(root, NULL, &error); if (error || !actual_mount) { g_error_free(error); invalid_enclosing_mount = true; } else if (actual_mount) { g_object_unref(actual_mount); } // Query the filesystem info for size, free space, and type error = NULL; GFileInfo* info = g_file_query_filesystem_info(root, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE "," G_FILE_ATTRIBUTE_FILESYSTEM_FREE "," G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, NULL, &error); if (error) { qLog(Warning) << error->message; g_error_free(error); } else { filesystem_size = g_file_info_get_attribute_uint64( info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); filesystem_free = g_file_info_get_attribute_uint64( info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE); filesystem_type = QString::fromUtf8(g_file_info_get_attribute_string( info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE)); g_object_unref(info); } // Query the file's info for a filesystem ID // Only afc devices (that I know of) give reliably unique IDs if (filesystem_type == "afc") { error = NULL; info = g_file_query_info(root, G_FILE_ATTRIBUTE_ID_FILESYSTEM, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error) { qLog(Warning) << error->message; g_error_free(error); } else { mount_uuid = QString::fromUtf8(g_file_info_get_attribute_string( info, G_FILE_ATTRIBUTE_ID_FILESYSTEM)); g_object_unref(info); } } g_object_unref(root); }
static void print_completions (const char *arg) { GFile *f; GFile *parent; char *basename; char *unescaped, *t; unescaped = g_shell_unquote (arg, NULL); if (unescaped == NULL) unescaped = g_strdup (arg); if (*unescaped == '~') { t = unescaped; unescaped = g_strconcat (g_get_home_dir(), t+1, NULL); g_free (t); } f = g_file_new_for_commandline_arg (unescaped); if (g_str_has_suffix (arg, "/") || *arg == 0) { parent = g_object_ref (f); basename = g_strdup (""); } else { parent = g_file_get_parent (f); basename = g_file_get_basename (f); } if (parent == NULL || strchr (arg, '/') == NULL || !g_file_query_exists (parent, NULL)) { GMount *mount; mount = g_file_find_enclosing_mount (f, NULL, NULL); if (mount == NULL) print_mounts (unescaped); else g_object_unref (mount); } if (parent != NULL) { GFileEnumerator *enumerator; enumerator = g_file_enumerate_children (parent, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE, nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS : 0, NULL, NULL); if (enumerator != NULL) { GFileInfo *info; while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) { const char *name; GFileType type; name = g_file_info_get_name (info); type = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE); if (name != NULL && g_str_has_prefix (name, basename)) { GFile *entry; entry = g_file_get_child (parent, name); show_completed_file (entry, type == G_FILE_TYPE_DIRECTORY, arg); g_object_unref (entry); } g_object_unref (info); } g_file_enumerator_close (enumerator, NULL, NULL); } g_object_unref (parent); } g_object_unref (f); g_free (basename); g_free (unescaped); }
void vfs_backend_get_file_info (const gchar *cBaseURI, gchar **cName, gchar **cURI, gchar **cIconName, gboolean *bIsDirectory, int *iVolumeID, double *fOrder, CairoDockFMSortType iSortType) { g_return_if_fail (cBaseURI != NULL); GError *erreur = NULL; cd_message ("%s (%s)", __func__, cBaseURI); gchar *cFullURI; if (strncmp (cBaseURI, "x-nautilus-desktop://", 21) == 0) { gchar *cNautilusFile = g_strdup (cBaseURI+14); memcpy (cNautilusFile, "file", 4); if (g_str_has_suffix (cBaseURI, ".volume")) { cNautilusFile[strlen(cNautilusFile)-7] = '\0'; } else if (g_str_has_suffix (cBaseURI, ".drive")) { cNautilusFile[strlen(cNautilusFile)-6] = '\0'; } cFullURI = g_filename_from_uri (cNautilusFile, NULL, &erreur); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); return ; } gchar *cVolumeName = cFullURI + 1; // on saute le '/'. cd_message ("cVolumeName : %s", cVolumeName); GMount *pMount = NULL; _cd_find_mount_from_volume_name (cVolumeName, &pMount, cURI, cIconName); g_return_if_fail (pMount != NULL); *cName = g_strdup (cVolumeName); *bIsDirectory = TRUE; *iVolumeID = 1; *fOrder = 0; //g_object_unref (pMount); g_free (cFullURI); //g_free (cNautilusFile); return; } else { if (*cBaseURI == '/') cFullURI = g_filename_to_uri (cBaseURI, NULL, NULL); else cFullURI = g_strdup (cBaseURI); } cd_message (" -> cFullURI : %s", cFullURI); GFile *pFile = g_file_new_for_uri (cFullURI); const gchar *cQuery = G_FILE_ATTRIBUTE_STANDARD_TYPE"," G_FILE_ATTRIBUTE_STANDARD_SIZE"," G_FILE_ATTRIBUTE_TIME_MODIFIED"," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE"," G_FILE_ATTRIBUTE_STANDARD_NAME"," G_FILE_ATTRIBUTE_STANDARD_ICON"," G_FILE_ATTRIBUTE_STANDARD_TARGET_URI"," G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE; GFileInfo *pFileInfo = g_file_query_info (pFile, cQuery, G_FILE_QUERY_INFO_NONE, /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS NULL, &erreur); //g_object_unref (pFile); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); return ; } *cURI = cFullURI; const gchar *cFileName = g_file_info_get_name (pFileInfo); const gchar *cMimeType = g_file_info_get_content_type (pFileInfo); GFileType iFileType = g_file_info_get_file_type (pFileInfo); if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE) { GTimeVal t; g_file_info_get_modification_time (pFileInfo, &t); *fOrder = t.tv_sec; } else if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE) *fOrder = g_file_info_get_size (pFileInfo); else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE) *fOrder = (cMimeType != NULL ? *((int *) cMimeType) : 0); else *fOrder = 0; *bIsDirectory = (iFileType == G_FILE_TYPE_DIRECTORY); cd_message (" => '%s' (mime:%s ; bIsDirectory:%d)", cFileName, cMimeType, *bIsDirectory); if (iFileType == G_FILE_TYPE_MOUNTABLE) { *cName = NULL; *iVolumeID = 1; const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); cd_message (" cTargetURI:%s", cTargetURI); GMount *pMount = NULL; if (cTargetURI != NULL) { GFile *file = g_file_new_for_uri (cTargetURI); pMount = g_file_find_enclosing_mount (file, NULL, NULL); //g_object_unref (file); } if (pMount != NULL) { *cName = g_mount_get_name (pMount); cd_message ("un GMount existe (%s)",* cName); } else { gchar *cMountName = g_strdup (cFileName); gchar *str = strrchr (cMountName, '.'); // on vire l'extension ".volume" ou ".drive". if (str != NULL) { *str = '\0'; if (strcmp (str+1, "link") == 0) // pour les liens, on prend le nom du lien. { if (strcmp (cMountName, "root") == 0) // on remplace 'root' par un nom plus parlant, sinon on prendra le nom du lien. { *cName = g_strdup ("/"); } } else if (strcmp (str+1, "drive") == 0) // on cherche un nom plus parlant si possible. { gchar *cVolumeName = _cd_find_volume_name_from_drive_name (cMountName); if (cVolumeName != NULL) { *cName = cVolumeName; } } } if (*cName == NULL) *cName = cMountName; //else //g_free (cMountName); } if (*cName == NULL) *cName = g_strdup (cFileName); } else { *iVolumeID = 0; *cName = g_strdup (cFileName); } *cIconName = NULL; if (cMimeType != NULL && strncmp (cMimeType, "image", 5) == 0) { gchar *cHostname = NULL; GError *erreur = NULL; gchar *cFilePath = g_filename_from_uri (cBaseURI, &cHostname, &erreur); if (erreur != NULL) { g_error_free (erreur); } else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0) // on ne recupere la vignette que sur les fichiers locaux. { *cIconName = g_strdup (cFilePath); cairo_dock_remove_html_spaces (*cIconName); } //g_free (cHostname); } if (*cIconName == NULL) { GIcon *pSystemIcon = g_file_info_get_icon (pFileInfo); if (pSystemIcon != NULL) { *cIconName = _cd_get_icon_path (pSystemIcon); } } cd_message ("cIconName : %s", *cIconName); //*iVolumeID = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE); //cd_message ("ID : %d\n", *iVolumeID); //g_object_unref (pFileInfo); }
GList *vfs_backend_list_directory (const gchar *cBaseURI, CairoDockFMSortType iSortType, int iNewIconsType, gboolean bListHiddenFiles, gchar **cFullURI) { g_return_val_if_fail (cBaseURI != NULL, NULL); cd_message ("%s (%s)", __func__, cBaseURI); gchar *cURI; gboolean bAddHome = FALSE; if (strcmp (cBaseURI, CAIRO_DOCK_FM_VFS_ROOT) == 0) { cURI = g_strdup ("computer://"); bAddHome = TRUE; ///*cFullURI = cURI; ///return vfs_backend_list_volumes (); //vfs_backend_list_volumes (); } else if (strcmp (cBaseURI, CAIRO_DOCK_FM_NETWORK) == 0) cURI = g_strdup ("network://"); else cURI = (*cBaseURI == '/' ? g_strconcat ("file://", cBaseURI, NULL) : g_strdup (cBaseURI)); *cFullURI = cURI; GFile *pFile = g_file_new_for_uri (cURI); GError *erreur = NULL; const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TYPE"," G_FILE_ATTRIBUTE_STANDARD_SIZE"," G_FILE_ATTRIBUTE_TIME_MODIFIED"," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE"," G_FILE_ATTRIBUTE_STANDARD_NAME"," G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN"," G_FILE_ATTRIBUTE_STANDARD_ICON"," G_FILE_ATTRIBUTE_STANDARD_TARGET_URI"," G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE; GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile, cAttributes, G_FILE_QUERY_INFO_NONE, /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS NULL, &erreur); //g_object_unref (pFile); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); return NULL; } int iOrder = 0; GList *pIconList = NULL; Icon *icon; GFileInfo *pFileInfo; do { pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); erreur = NULL; continue; } if (pFileInfo == NULL) break ; gboolean bIsHidden = g_file_info_get_is_hidden (pFileInfo); if (bListHiddenFiles || ! bIsHidden) { GFileType iFileType = g_file_info_get_file_type (pFileInfo); GIcon *pFileIcon = g_file_info_get_icon (pFileInfo); if (pFileIcon == NULL) { cd_message ("AUCUNE ICONE"); continue; } const gchar *cFileName = g_file_info_get_name (pFileInfo); const gchar *cMimeType = g_file_info_get_content_type (pFileInfo); gchar *cName = NULL; icon = g_new0 (Icon, 1); icon->iType = iNewIconsType; icon->cBaseURI = g_strconcat (*cFullURI, "/", cFileName, NULL); cd_message ("+ %s (mime:%s)", icon->cBaseURI, cMimeType); if (iFileType == G_FILE_TYPE_MOUNTABLE) { const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); cd_message (" c'est un point de montage correspondant a %s", cTargetURI); GMount *pMount = NULL; if (cTargetURI != NULL) { icon->acCommand = g_strdup (cTargetURI); GFile *file = g_file_new_for_uri (cTargetURI); pMount = g_file_find_enclosing_mount (file, NULL, NULL); //g_object_unref (file); } if (pMount != NULL) { cName = g_mount_get_name (pMount); cd_message ("un GMount existe (%s)", cName); GVolume *volume = g_mount_get_volume (pMount); if (volume) cd_message (" volume associe : %s", g_volume_get_name (volume)); GDrive *drive = g_mount_get_drive (pMount); if (drive) cd_message (" disque associe : %s", g_drive_get_name (drive)); ///pFileIcon = g_mount_get_icon (pMount); } else { cName = g_strdup (cFileName); gchar *str = strrchr (cName, '.'); // on vire l'extension ".volume" ou ".drive". if (str != NULL) { *str = '\0'; if (strcmp (str+1, "link") == 0) { if (strcmp (cName, "root") == 0) { g_free (cName); cName = g_strdup ("/"); } } else if (strcmp (str+1, "drive") == 0) // on cherche un nom plus parlant si possible. { gchar *cVolumeName = _cd_find_volume_name_from_drive_name (cName); if (cVolumeName != NULL) { g_free (cName); g_free (cVolumeName); continue; /// apparemment il n'est plus necessaire d'afficher les .drives qui ont 1 (ou plusieurs ?) volumes, car ces derniers sont dans la liste, donc ca fait redondant. /**if (strcmp (cVolumeName, "discard") == 0) continue; g_free (cName); cName = cVolumeName;*/ } } } } icon->iVolumeID = 1; cd_message ("le nom de ce volume est : %s", cName); } else cName = g_strdup (cFileName); if (icon->acCommand == NULL) icon->acCommand = g_strdup (icon->cBaseURI); icon->acName = cName; icon->acFileName = NULL; if (cMimeType != NULL && strncmp (cMimeType, "image", 5) == 0) { gchar *cHostname = NULL; gchar *cFilePath = g_filename_from_uri (icon->cBaseURI, &cHostname, &erreur); if (erreur != NULL) { g_error_free (erreur); erreur = NULL; } else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0) // on ne recupere la vignette que sur les fichiers locaux. { icon->acFileName = g_strdup (cFilePath); cairo_dock_remove_html_spaces (icon->acFileName); } g_free (cHostname); g_free (cFilePath); } if (icon->acFileName == NULL) { icon->acFileName = _cd_get_icon_path (pFileIcon); cd_message ("icon->acFileName : %s", icon->acFileName); } if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE) icon->fOrder = g_file_info_get_size (pFileInfo); else if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE) { GTimeVal t; g_file_info_get_modification_time (pFileInfo, &t); icon->fOrder = t.tv_sec; } else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE) icon->fOrder = (cMimeType != NULL ? *((int *) cMimeType) : 0); if (icon->fOrder == 0) // un peu moyen mais mieux que rien non ? icon->fOrder = iOrder; pIconList = g_list_insert_sorted (pIconList, icon, (GCompareFunc) cairo_dock_compare_icons_order); //g_list_prepend (pIconList, icon); iOrder ++; } } while (TRUE); // 'g_file_enumerator_close' est appelee lors du dernier 'g_file_enumerator_next_file'. if (bAddHome && pIconList != NULL) { icon = g_new0 (Icon, 1); icon->iType = iNewIconsType; icon->cBaseURI = g_strdup_printf ("file://%s", "/home"); icon->acCommand = g_strdup ("/home"); //icon->acCommand = g_strdup (icon->cBaseURI); icon->iVolumeID = 0; icon->acName = g_strdup ("home"); Icon *pRootIcon = cairo_dock_get_icon_with_name (pIconList, "/"); if (pRootIcon == NULL) { pRootIcon = cairo_dock_get_first_icon (pIconList); g_print ("domage ! (%s:%s)\n", pRootIcon->acCommand, pRootIcon->acName); } icon->acFileName = g_strdup (pRootIcon->acFileName); icon->fOrder = iOrder++; pIconList = g_list_insert_sorted (pIconList, icon, (GCompareFunc) cairo_dock_compare_icons_order); } if (iSortType == CAIRO_DOCK_FM_SORT_BY_NAME) pIconList = cairo_dock_sort_icons_by_name (pIconList); else pIconList = cairo_dock_sort_icons_by_order (pIconList); return pIconList; }
static void _cd_find_mount_from_volume_name (const gchar *cVolumeName, GMount **pFoundMount, gchar **cURI, gchar **cIconName) { g_return_if_fail (cVolumeName != NULL); cd_message ("%s (%s)", __func__, cVolumeName); GFile *pFile = g_file_new_for_uri ("computer://"); GError *erreur = NULL; const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TYPE"," G_FILE_ATTRIBUTE_STANDARD_NAME"," G_FILE_ATTRIBUTE_STANDARD_ICON"," G_FILE_ATTRIBUTE_STANDARD_TARGET_URI"," G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE; GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile, cAttributes, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &erreur); //g_object_unref (pFile); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); return ; } GList *pIconList = NULL; Icon *icon; GFileInfo *pFileInfo; do { pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); erreur = NULL; } else { if (pFileInfo == NULL) break ; GFileType iFileType = g_file_info_get_file_type (pFileInfo); if (iFileType == G_FILE_TYPE_MOUNTABLE) { const gchar *cFileName = g_file_info_get_name (pFileInfo); cd_message (" test de %s...", cFileName); const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); GMount *pMount = NULL; if (cTargetURI != NULL) { GFile *file = g_file_new_for_uri (cTargetURI); pMount = g_file_find_enclosing_mount (file, NULL, NULL); //g_object_unref (file); } if (pMount != NULL) { gchar *cName = g_mount_get_name (pMount); cd_message (" mount : %s", cName); if (cName != NULL && strcmp (cName, cVolumeName) == 0) { cd_message ("TROUVE"); *pFoundMount = pMount; *cURI = g_strconcat ("computer:///", cFileName, NULL); GIcon *pSystemIcon = g_mount_get_icon (pMount); *cIconName = _cd_get_icon_path (pSystemIcon); g_free (cName); break ; } g_free (cName); } } } } while (TRUE); //g_object_unref (pFileEnum); }
static int dt_film_import_blocking(const char *dirname, const int blocking) { int rc; sqlite3_stmt *stmt; /* intialize a film object*/ dt_film_t *film = (dt_film_t *)malloc(sizeof(dt_film_t)); dt_film_init(film); film->id = -1; /* lookup if film exists and reuse id */ DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select id from film_rolls where folder = ?1", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, dirname, strlen(dirname), SQLITE_STATIC); if(sqlite3_step(stmt) == SQLITE_ROW) film->id = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); /* if we didnt find a id, lets instansiate a new filmroll */ if(film->id <= 0) { char datetime[20]; dt_gettime(datetime); #if 0 /* Should we use one for the whole app? */ GVolumeMonitor *gv_monitor; gv_monitor = g_volume_monitor_get (); GList *mounts; mounts = g_volume_monitor_get_mounts(gv_monitor); gchar *mount_name = NULL; if (mounts != NULL) { GFile *mount_gfile; GMount *filmroll_mount; GError *error = NULL; gchar *filmroll_path; GFile *gdirname = g_file_new_for_path(dirname); filmroll_mount = g_file_find_enclosing_mount(gdirname, NULL, &error); g_object_unref(gdirname); if (!error) /* We are considering that the only error is that there is no mount * because the filmroll added is in a local drive */ { filmroll_path = g_file_get_path((g_mount_get_default_location(filmroll_mount))); for (int i=0; i < g_list_length (mounts); i++) { gchar *p; mount_gfile = g_mount_get_default_location((GMount *)g_list_nth_data(mounts, i)); p = g_file_get_path(mount_gfile); if (g_strcmp0(p, filmroll_path)) { mount_name = g_mount_get_name(g_list_nth_data(mounts, i)); break; } g_free(p); g_object_unref (mount_gfile); } g_free (filmroll_path); } if (filmroll_mount != NULL) g_object_unref (filmroll_mount); /* We haven't found the device in the list of connected devices. Let's suppose it is local */ if (mount_name == NULL) mount_name = g_strdup("Local"); } else mount_name = g_strdup("Local"); #endif /* insert a new film roll into database */ DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), // "insert into film_rolls (id, datetime_accessed, folder, external_drive) values " // "(null, ?1, ?2, ?3)", -1, &stmt, NULL); "insert into film_rolls (id, datetime_accessed, folder) values " "(null, ?1, ?2)", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, datetime, strlen(datetime), SQLITE_STATIC); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, dirname, strlen(dirname), SQLITE_STATIC); // DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 3, mount_name, strlen(mount_name), // SQLITE_STATIC); rc = sqlite3_step(stmt); if(rc != SQLITE_DONE) fprintf(stderr, "[film_import] failed to insert film roll! %s\n", sqlite3_errmsg(dt_database_get(darktable.db))); sqlite3_finalize(stmt); // if (mount_name != NULL) g_free (mount_name); /* requery for filmroll and fetch new id */ DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select id from film_rolls where folder=?1", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, dirname, strlen(dirname), SQLITE_STATIC); if(sqlite3_step(stmt) == SQLITE_ROW) film->id = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); } /* bail out if we got troubles */ if(film->id <= 0) { dt_film_cleanup(film); free(film); return 0; } /* at last put import film job on queue */ dt_job_t j; film->last_loaded = 0; g_strlcpy(film->dirname, dirname, 512); film->dir = g_dir_open(film->dirname, 0, NULL); dt_film_import1_init(&j, film); dt_control_add_job(darktable.control, &j); return film->id; }