DRun Check if filename ends in .desktop.

This commit is contained in:
Dave Davenport 2016-08-30 17:41:30 +02:00
parent ef509865fb
commit 0d9d4d6c55
1 changed files with 18 additions and 15 deletions

View File

@ -212,9 +212,9 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
{ {
// Create ID on stack. // Create ID on stack.
// We know strlen (path ) > strlen(root)+1 // We know strlen (path ) > strlen(root)+1
const ssize_t id_len = strlen(path)-strlen(root) -1; const ssize_t id_len = strlen ( path ) - strlen ( root ) - 1;
char id[id_len]; char id[id_len];
g_strlcpy (id, &( path[strlen ( root ) + 1] ), id_len ); g_strlcpy ( id, &( path[strlen ( root ) + 1] ), id_len );
for ( int index = 0; index < id_len; index++ ) { for ( int index = 0; index < id_len; index++ ) {
if ( id[index] == '/' ) { if ( id[index] == '/' ) {
id[index] = '-'; id[index] = '-';
@ -231,47 +231,47 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
g_key_file_load_from_file ( kf, path, 0, &error ); g_key_file_load_from_file ( kf, path, 0, &error );
// If error, skip to next entry // If error, skip to next entry
if ( error != NULL ) { if ( error != NULL ) {
g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Failed to parse desktop file: %s because: %s", path, error->message); g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Failed to parse desktop file: %s because: %s", path, error->message );
g_error_free ( error ); g_error_free ( error );
g_key_file_free ( kf ); g_key_file_free ( kf );
return; return;
} }
// Skip non Application entries. // Skip non Application entries.
gchar *key = g_key_file_get_string ( kf, "Desktop Entry", "Type", NULL ); gchar *key = g_key_file_get_string ( kf, "Desktop Entry", "Type", NULL );
if (key == NULL ) { if ( key == NULL ) {
// No type? ignore. // No type? ignore.
g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Skipping desktop file: %s because: No type indicated", path); g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Skipping desktop file: %s because: No type indicated", path );
g_key_file_free ( kf ); g_key_file_free ( kf );
return; return;
} }
if ( g_strcmp0 ( key, "Application" ) ) { if ( g_strcmp0 ( key, "Application" ) ) {
g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Skipping desktop file: %s because: Not of type application (%s)", path, key); g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Skipping desktop file: %s because: Not of type application (%s)", path, key );
g_free ( key ); g_free ( key );
g_key_file_free ( kf ); g_key_file_free ( kf );
return; return;
} }
g_free(key); g_free ( key );
// Skip hidden entries. // Skip hidden entries.
if ( g_key_file_get_boolean ( kf, "Desktop Entry", "Hidden", NULL ) ) { if ( g_key_file_get_boolean ( kf, "Desktop Entry", "Hidden", NULL ) ) {
g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Skipping desktop file: %s because: Hidden", path); g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Skipping desktop file: %s because: Hidden", path );
g_key_file_free ( kf ); g_key_file_free ( kf );
return; return;
} }
// Skip entries that have NoDisplay set. // Skip entries that have NoDisplay set.
if ( g_key_file_get_boolean ( kf, "Desktop Entry", "NoDisplay", NULL ) ) { if ( g_key_file_get_boolean ( kf, "Desktop Entry", "NoDisplay", NULL ) ) {
g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Skipping desktop file: %s because: NoDisplay", path); g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Skipping desktop file: %s because: NoDisplay", path );
g_key_file_free ( kf ); g_key_file_free ( kf );
return; return;
} }
// Name key is required. // Name key is required.
if ( !g_key_file_has_key ( kf, "Desktop Entry", "Name", NULL ) ) { if ( !g_key_file_has_key ( kf, "Desktop Entry", "Name", NULL ) ) {
g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Invalid DesktopFile: '%s', no 'Name' key present.\n", path ); g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Invalid DesktopFile: '%s', no 'Name' key present.\n", path );
g_key_file_free ( kf ); g_key_file_free ( kf );
return; return;
} }
// We need Exec, don't support DBusActivatable // We need Exec, don't support DBusActivatable
if ( !g_key_file_has_key ( kf, "Desktop Entry", "Exec", NULL ) ) { if ( !g_key_file_has_key ( kf, "Desktop Entry", "Exec", NULL ) ) {
g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Unsupported DesktopFile: '%s', no 'Exec' key present.\n", path ); g_log ( "Dialogs.DRun", G_LOG_LEVEL_DEBUG, "Unsupported DesktopFile: '%s', no 'Exec' key present.\n", path );
g_key_file_free ( kf ); g_key_file_free ( kf );
return; return;
} }
@ -286,7 +286,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
pd->entry_list[pd->cmd_list_length].name = n; pd->entry_list[pd->cmd_list_length].name = n;
gchar *gn = g_key_file_get_locale_string ( kf, "Desktop Entry", "GenericName", NULL, NULL ); gchar *gn = g_key_file_get_locale_string ( kf, "Desktop Entry", "GenericName", NULL, NULL );
pd->entry_list[pd->cmd_list_length].generic_name = gn; pd->entry_list[pd->cmd_list_length].generic_name = gn;
pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, "Desktop Entry", "Exec", NULL ); pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, "Desktop Entry", "Exec", NULL );
if ( g_key_file_has_key ( kf, "Desktop Entry", "Terminal", NULL ) ) { if ( g_key_file_has_key ( kf, "Desktop Entry", "Terminal", NULL ) ) {
pd->entry_list[pd->cmd_list_length].terminal = g_key_file_get_boolean ( kf, "Desktop Entry", "Terminal", NULL ); pd->entry_list[pd->cmd_list_length].terminal = g_key_file_get_boolean ( kf, "Desktop Entry", "Terminal", NULL );
} }
@ -315,7 +315,10 @@ static void walk_dir ( DRunModePrivateData *pd, const char *root, const char *di
if ( file->d_name[0] == '.' ) { if ( file->d_name[0] == '.' ) {
continue; continue;
} }
// Skip files not ending on .desktop.
if ( !g_str_has_suffix ( file->d_name, ".desktop" ) ) {
continue;
}
switch ( file->d_type ) switch ( file->d_type )
{ {
case DT_LNK: case DT_LNK: