Hola mis hermanos del Mediterraneo,
os dejo un simple código que, usando las funciones externas de la libreria
libgio-2.0, cuando se pasa el ratón sobre los íconos de archivo en el Escritorio, devuelve información sobre estos archivos.
Hace falta activar el Componente
gb.desktop .
(No se si en la ruta de la Constante "PERCORSO" la palabra "Escritorio" está bien)
Código:
Public Struct IconaFileDesktop
nome As String
x As Short
y As Short
rt As Rect
End Struct
Private icone As New IconaFileDesktop[]
Private PERCORSO As String = User.home &/ "Escritorio"
Private T As Timer
Public Sub Form_Open()
Dim nomefile, s As String
Dim ifd As IconaFileDesktop
' Carica tutti i file corrispondenti alle icone presenti sulla Scrivania:
For Each nomefile In Dir(PERCORSO, "*", gb.File)
' Usa con "Extern" alcune funzioni esterne della libreria "libgio-2.0":
s = EstraeInfo(PERCORSO &/ nomefile)
If IsNull(s) Then Continue
' Carica nella "Struttura" i dati utili del file individuato dalla funzione "Dir()":
With ifd = New IconaFileDesktop
.nome = nomefile
.x = Val(Scan(s, "*,*")[0])
.y = Val(Scan(s, "*,*")[1])
' Stabilisce un'area quadrata standard di 48 pixel per ciascuna icona di file individuato:
.rt = New Rect(.x, .y, 48, 48)
End With
icone.Push(ifd)
Next
T = New Timer As "Tmr"
T.Delay = 50
T.Start
End
Public Sub Tmr_Timer()
Dim c As Short
TextArea1.Clear
For c = 0 To icone.Max
' Se le coordinate x,y in pixel correnti in cui si trova il puntatore del mouse rientrano in un'area quadrata caricata, va a vedere a quale icona e file appartiene:
If icone[c].rt.Contains(Mouse.ScreenX, Mouse.ScreenY) Then
' Mostra alcune caratteristiche del file al quale corrisponde l'icona sorvolata dal puntatore del mouse:
TextArea1.Text = "== Características del archivo ==\n" &
"\nRuta: " & Stat(PERCORSO &/ icone[c].nome).Path &
"\nTamaño: " & Stat(PERCORSO &/ icone[c].nome).Size & " Byte" &
"\nÚltimo acceso: " & Stat(PERCORSO &/ icone[c].nome).LastAccess &
"\nÚltima modificación: " & Stat(PERCORSO &/ icone[c].nome).LastModified &
"\nPermisos: " & Stat(PERCORSO &/ icone[c].nome).Auth &
"\nUsuario: " & Stat(PERCORSO &/ icone[c].nome).User &
"\nGrupo: " & Stat(PERCORSO &/ icone[c].nome).Group &
"\nMimetype icono: " & DesktopMime.FromFile(Stat(PERCORSO &/ icone[c].nome).Path).Type
Endif
Next
End
Library "libgio-2.0"
' GFile * g_file_new_for_commandline_arg (const char *arg)
' Creates a GFile with the given argument from the command line.
Private Extern g_file_new_for_commandline_arg(arg As String) As Pointer
' GFileInfo * g_file_query_info (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error )
' Gets the requested information about specified file.
Private Extern g_file_query_info(gfile As Pointer, attributes As String, flags As Integer, cancellable As Pointer, gerror As Pointer) As Pointer
' char ** g_file_info_list_attributes (GFileInfo *info, const char *name_space)
' Lists the file info structure's attributes.
Private Extern g_file_info_list_attributes(info As Pointer, name_space As String) As Pointer
' char * g_file_info_get_attribute_as_string (GFileInfo *info, const char *attribute)
' Gets the value of a attribute, formatted as a string.
Private Extern g_file_info_get_attribute_as_string(info As Pointer, attribute As String) As Pointer
' void g_object_unref (gpointer object)
' Decreases the reference count of object.
Private Extern g_object_unref(gobject As Pointer)
Private Function EstraeInfo(percfile As String) As String
Dim fl, info As Pointer
fl = g_file_new_for_commandline_arg(percfile)
If fl == 0 Then Error.Raise("Errore !")
info = g_file_query_info(fl, "*", 0, Null, Null)
If info == 0 Then Error.Raise("Errore !")
percfile = EstraeAttributi(info)
g_object_unref(info)
g_object_unref(fl)
Return percfile
End
Private Function EstraeAttributi(inf As Pointer) As String
Dim attr, p As Pointer
Dim i As Integer = -1
Dim s As String
attr = g_file_info_list_attributes(inf, Null)
Repeat
Inc i
s = String@(Pointer@(attr + (i * SizeOf(gb.Pointer))))
p = g_file_info_get_attribute_as_string(inf, s)
Until s == Trim("metadata::nemo-icon-position")
Return String@(p)
End