Ottenere informazioni sulle icone presenti sulla Scrivania: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
| (7 versioni intermedie di uno stesso utente non sono mostrate) | |||
| Riga 1: | Riga 1: | ||
In via generale, per ottenere informazioni sui file e anche sulle icone a essi correlate, si potranno usare alcune funzioni esterne della libreria "libgio-2.0". | In via generale, per ottenere informazioni sui file e anche sulle icone a essi correlate, si potranno usare alcune funzioni esterne della libreria: "''libgio-2.0.so.0.8000.5'' ". | ||
Library "libgio-2.0" | Mostriamo un semplice codice, con il quale si conosceranno varie informazioni su un file e sulla sua icona correlata: | ||
Library "libgio-2.0:0.8400.1" | |||
<FONT Color=gray>' ''GFile * g_file_new_for_commandline_arg (const char *arg)'' | <FONT Color=gray>' ''GFile * g_file_new_for_commandline_arg (const char *arg)'' | ||
| Riga 24: | Riga 25: | ||
Public Sub Main() | |||
Dim percorso As String | Dim percorso As String | ||
Dim fl, info As Pointer | Dim fl, info As Pointer | ||
percorso = "<FONT Color= | percorso = "<FONT Color=darkgreen>''/percorso/del/file''</font>" | ||
fl = g_file_new_for_commandline_arg(percorso) | fl = g_file_new_for_commandline_arg(percorso) | ||
| Riga 42: | Riga 43: | ||
g_object_unref(fl) | g_object_unref(fl) | ||
End | |||
Private Procedure MostraAttributi(inf As Pointer) | |||
Dim attr, p As Pointer | Dim attr, p As Pointer | ||
| Riga 63: | Riga 64: | ||
Until IsNull(s) | Until IsNull(s) | ||
End | |||
| Riga 80: | Riga 81: | ||
Public Sub Form_Open() | |||
Dim nomefile, s As String | Dim nomefile, s As String | ||
| Riga 95: | Riga 96: | ||
.x = Val(Scan(s, "*,*")[0]) | .x = Val(Scan(s, "*,*")[0]) | ||
.y = Val(Scan(s, "*,*")[1]) | .y = Val(Scan(s, "*,*")[1]) | ||
<FONT Color=gray>' ''Stabilisce un'area quadrata standard di | <FONT Color=gray>' ''Stabilisce un'area quadrata standard di 48x48 pixel per ciascuna icona di file individuato:''</font> | ||
.rt = New Rect(.x, .y, 48, 48) | .rt = New Rect(.x, .y, 48, 48) | ||
End With | End With | ||
| Riga 106: | Riga 107: | ||
End With | End With | ||
End | |||
Public Sub Timer1_Timer() | |||
Dim c As Short | Dim c As Short | ||
| Riga 131: | Riga 132: | ||
Next | Next | ||
End | |||
Library "libgio-2.0" | Library "libgio-2.0:0.8400.1" | ||
<FONT Color=gray>' ''GFile * g_file_new_for_commandline_arg (const char *arg)'' | <FONT Color=gray>' ''GFile * g_file_new_for_commandline_arg (const char *arg)'' | ||
| Riga 157: | Riga 158: | ||
Private Function LeggeInfo(percfile As String) As String | |||
Dim fl, info As Pointer | Dim fl, info As Pointer | ||
| Riga 174: | Riga 175: | ||
Return percfile | Return percfile | ||
End | |||
Private Function EstraeAttributi(inf As Pointer) As String | |||
Dim attr, p As Pointer | Dim attr, p As Pointer | ||
| Riga 193: | Riga 194: | ||
Return String@(p) | Return String@(p) | ||
End | |||
Versione attuale delle 17:46, 22 apr 2025
In via generale, per ottenere informazioni sui file e anche sulle icone a essi correlate, si potranno usare alcune funzioni esterne della libreria: "libgio-2.0.so.0.8000.5 ".
Mostriamo un semplice codice, con il quale si conosceranno varie informazioni su un file e sulla sua icona correlata:
Library "libgio-2.0:0.8400.1"
' 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)
Public Sub Main()
Dim percorso As String
Dim fl, info As Pointer
percorso = "/percorso/del/file"
fl = g_file_new_for_commandline_arg(percorso)
If fl == 0 Then Error.Raise("Errore !")
info = g_file_query_info(fl, "*", 0, Null, Null)
If info == 0 Then Error.Raise("Errore !")
MostraAttributi(info)
g_object_unref(info)
g_object_unref(fl)
End
Private Procedure MostraAttributi(inf As Pointer)
Dim attr, p As Pointer
Dim i As Integer
Dim s As String
attr = g_file_info_list_attributes(inf, Null)
Print "ATTRIBUTI:\n"
s = String@(Pointer@(attr + (i * 8)))
Repeat
p = g_file_info_get_attribute_as_string(inf, s)
Print String@(Pointer@(attr + (i * 8))); ": \e[31m"; String@(p); "\e[0m"
Inc i
Wait 0.1
s = String@(Pointer@(attr + (i * 8)))
Until IsNull(s)
End
Individuare le icone poste sulla Scrivania passandoci sopra con il puntatore del mouse
Mostriamo di seguito un codice che, utilizzando nuovamente le già viste funzioni esterne della libreria "libgio-2.0", permette di individuare le icone poste sulla Scrivania, mentre si sorvola su di esse con il puntatore del mouse, e di ottenere informazioni sulle icone stesse e sui file, ai quali esse sono collegate.
E' necessario attivare anche il Componente "gb.desktop".
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 = Desktop.GetDirectory("DESKTOP")
Private TImer1 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 alcune funzioni esterne della libreria "libgio-2.0":
s = LeggeInfo(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 48x48 pixel per ciascuna icona di file individuato:
.rt = New Rect(.x, .y, 48, 48)
End With
icone.Push(ifd)
Next
With timer1 = New Timer As "Timer1"
.Delay = 50
.Start
End With
End
Public Sub Timer1_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 = "== Caratteristiche del file ==\n" &
"\nPercorso: " & Stat(PERCORSO &/ icone[c].nome).Path &
"\nDimensione: " & Stat(PERCORSO &/ icone[c].nome).Size & " Byte" &
"\nUltimo Accesso: " & Stat(PERCORSO &/ icone[c].nome).LastAccess &
"\nUltima modifica: " & Stat(PERCORSO &/ icone[c].nome).LastModified &
"\nPermessi: " & Stat(PERCORSO &/ icone[c].nome).Auth &
"\nUtente: " & Stat(PERCORSO &/ icone[c].nome).User &
"\nGruppo: " & Stat(PERCORSO &/ icone[c].nome).Group &
"\nMimetype icona: " & DesktopMime.FromFile(Stat(PERCORSO &/ icone[c].nome).Path).Type
Endif
Next
End
Library "libgio-2.0:0.8400.1"
' 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 LeggeInfo(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