コード例 #1
0
ファイル: nemo-column-utilities.c プロジェクト: Fantu/nemo
static int
column_compare (NemoColumn *a, NemoColumn *b, char **column_order)
{
	int index_a;
	int index_b;
	char *name;
	
	g_object_get (G_OBJECT (a), "name", &name, NULL);
	index_a = strv_index (column_order, name);
	g_free (name);

	g_object_get (G_OBJECT (b), "name", &name, NULL);
	index_b = strv_index (column_order, name);
	g_free (name);

	if (index_a == index_b) {
		int ret;
		char *label_a;
		char *label_b;
		
		g_object_get (G_OBJECT (a), "label", &label_a, NULL);
		g_object_get (G_OBJECT (b), "label", &label_b, NULL);
		ret = strcmp (label_a, label_b);
		g_free (label_a);
		g_free (label_b);
		
		return ret;
	} else if (index_a == -1) {
		return 1;
	} else if (index_b == -1) {
		return -1;
	} else {
		return index_a - index_b;
	}
}
コード例 #2
0
static int
column_compare (NautilusColumn *a, NautilusColumn *b, char **column_order)
{
	int index_a;
	int index_b;
	char *name_a;
	char *name_b;
	int ret;

	g_object_get (G_OBJECT (a), "name", &name_a, NULL);
	index_a = strv_index (column_order, name_a);

	g_object_get (G_OBJECT (b), "name", &name_b, NULL);
	index_b = strv_index (column_order, name_b);

	if (index_a == index_b) {
		int pos_a;
		int pos_b;

		pos_a = strv_index ((char **)default_column_order, name_a);
		pos_b = strv_index ((char **)default_column_order, name_b);

		if (pos_a == pos_b) {
			char *label_a;
			char *label_b;
		
			g_object_get (G_OBJECT (a), "label", &label_a, NULL);
			g_object_get (G_OBJECT (b), "label", &label_b, NULL);
			ret = strcmp (label_a, label_b);
			g_free (label_a);
			g_free (label_b);
		} else if (pos_a == -1) {
			ret = 1;
		} else if (pos_b == -1) {
			ret = -1;
		} else {
			ret = index_a - index_b;
		}
	} else if (index_a == -1) {
		ret = 1;
	} else if (index_b == -1) {
		ret = -1;
	} else {
		ret = index_a - index_b;
	}

	g_free (name_a);
	g_free (name_b);

	return ret;
}
コード例 #3
0
ファイル: mime-action.c プロジェクト: BwackNinja/spacefm
static void remove_actions( const char* type, GArray* actions )
{   //sfm 0.7.7+ added
    char** removed = NULL;
    gsize n_removed = 0, r;
    int i;

//g_print( "remove_actions( %s )\n", type );
    char* path = g_build_filename( g_get_user_data_dir(),
                                            "applications/mimeapps.list", NULL );
    GKeyFile* file = g_key_file_new();
    if ( g_key_file_load_from_file( file, path, 0, NULL ) )
    {
        removed = g_key_file_get_string_list( file, "Removed Associations",
                                                        type, &n_removed, NULL );
        if ( removed )
        {
            for ( r = 0; r < n_removed; ++r )
            {
                g_strstrip( removed[r] );
//g_print( "    %s\n", removed[r] );
                i = strv_index( (char**)actions->data, removed[r] );
                if ( i != -1 )
{
//g_print(  "        ACTION-REMOVED\n" );
                    g_array_remove_index( actions, i );
}
            }
        }
        g_strfreev( removed );
    }
    g_key_file_free( file );
    g_free( path );
}
コード例 #4
0
ファイル: mime-action.c プロジェクト: BwackNinja/spacefm
/*
 * NOTE:
 * This API is very time consuming, but unfortunately, due to the damn poor design of
 * Freedesktop.org spec, all the insane checks here are necessary.  Sigh...  :-(
 */
gboolean mime_type_has_action( const char* type, const char* desktop_id )
{
    char** actions, **action;
    char *cmd = NULL, *name = NULL;
    gboolean found = FALSE;
    gboolean is_desktop = g_str_has_suffix( desktop_id, ".desktop" );

    if( is_desktop )
    {
        char** types;
        GKeyFile* kf = g_key_file_new();
        char* filename = mime_type_locate_desktop_file( NULL, desktop_id );
        if( filename && g_key_file_load_from_file( kf, filename, 0, NULL ) )
        {
            types = g_key_file_get_string_list( kf, group_desktop, key_mime_type, NULL, NULL );
            if( -1 != strv_index( types, type ) )
            {
                /* our mime-type is already found in the desktop file. no further check is needed */
                found = TRUE;
            }
            g_strfreev( types );

            if( ! found )   /* get the content of desktop file for comparison */
            {
                cmd = g_key_file_get_string( kf, group_desktop, "Exec", NULL );
                name = g_key_file_get_string( kf, group_desktop, "Name", NULL );
            }
        }
        g_free( filename );
        g_key_file_free( kf );
    }
    else
    {
        cmd = (char*)desktop_id;
    }

    actions = mime_type_get_actions( type );
    if( actions )
    {
        for( action = actions; ! found && *action; ++action )
        {
            /* Try to match directly by desktop_id first */
            if( is_desktop && 0 == strcmp( *action, desktop_id ) )
            {
                found = TRUE;
            }
            else /* Then, try to match by "Exec" and "Name" keys */
            {
                char *name2 = NULL, *cmd2 = NULL, *filename = NULL;
                GKeyFile* kf = g_key_file_new();
                filename = mime_type_locate_desktop_file( NULL, *action );
                if( filename && g_key_file_load_from_file( kf, filename, 0, NULL ) )
                {
                    cmd2 = g_key_file_get_string( kf, group_desktop, "Exec", NULL );
                    if( cmd && cmd2 && 0 == strcmp( cmd, cmd2 ) )   /* 2 desktop files have same "Exec" */
                    {
                        if( is_desktop )
                        {
                            name2 = g_key_file_get_string( kf, group_desktop, "Name", NULL );
                            /* Then, check if the "Name" keys of 2 desktop files are the same. */
                            if( name && name2 && 0 == strcmp( name, name2 ) )
                            {
                                /* Both "Exec" and "Name" keys of the 2 desktop files are
                                 *  totally the same. So, despite having different desktop id
                                 *  They actually refer to the same application. */
                                found = TRUE;
                            }
                            g_free( name2 );
                        }
                        else
                            found = TRUE;
                    }
                }
                g_free( filename );
                g_free( cmd2 );
                g_key_file_free( kf );
            }
        }
        g_strfreev( actions );
    }
    if( is_desktop )
    {
        g_free( cmd );
        g_free( name );
    }
    return found;
}
コード例 #5
0
ファイル: mime-action.c プロジェクト: BwackNinja/spacefm
static char* get_actions( const char* dir, const char* type, GArray* actions )
{
//g_print( "get_actions( %s, %s )\n", dir, type );
    GKeyFile* file;
    gboolean opened;
    int n;
    char** apps = NULL;
    char** removed = NULL;
    gboolean is_removed;
    gsize n_removed = 0, r;
    
    char* names[] = { "applications/mimeapps.list", "applications/mimeinfo.cache" };
    char* sections[] = { "Added Associations", "MIME Cache" };
    
    for ( n = 0; n < G_N_ELEMENTS( names ); n++ )
    {
        char* path = g_build_filename( dir, names[n], NULL );
//g_print( "    path = %s\n", path );
        file = g_key_file_new();
        opened = g_key_file_load_from_file( file, path, 0, NULL );
        g_free( path );
        if( G_LIKELY( opened ) )
        {
            gsize n_apps = 0, i;
            apps = g_key_file_get_string_list( file, sections[n], type, &n_apps, NULL );
            if ( n == 0 )
            {
                // get removed associations in this dir
                removed = g_key_file_get_string_list( file, "Removed Associations",
                                                        type, &n_removed, NULL );
            }
            for ( i = 0; i < n_apps; ++i )
            {
                g_strstrip( apps[i] );
//g_print( "        %s\n", apps[i] );
                // check if removed
                is_removed = FALSE;
                if ( removed && n > 0 )
                {
                    for ( r = 0; r < n_removed; ++r )
                    {
                        g_strstrip( removed[r] );
                        if ( !strcmp( removed[r], apps[i] ) )
                        {
//g_print( "            REMOVED\n" );
                            is_removed = TRUE;
                            break;
                        }
                    }
                }
                if( !is_removed && -1 == strv_index( (char**)actions->data, apps[i] ) )
                {
                    /* check for app existence */
                    path = mime_type_locate_desktop_file( NULL, apps[i] );
                    if( G_LIKELY(path) )
                    {
//g_print( "            EXISTS\n");
                        g_array_append_val( actions, apps[i] );
                        g_free( path );
                    }
                    else
                        g_free( apps[i] );
                    apps[i] = NULL; /* steal the string */
                }
                else
                {
                    g_free( apps[i] );
                    apps[i] = NULL;
                }
            }
            g_free( apps ); /* don't call g_strfreev since all strings in the array was stolen. */
        }
        g_key_file_free( file );
    }
    g_strfreev( removed );
    return NULL;    /* return NULL so the for_each operation doesn't stop. */
}