Beispiel #1
0
int menu()
{
	int user_choice;
	
	printf("1.Print Database\r\n");
	printf("2.Add part to database\r\n");
	printf("3.Remove part from database\r\n");
	printf("4.Search Database\r\n");
	printf("5.Exit Database\r\n");
	
	while( scanf("%d%*c",&user_choice) != 1)
	{
		fflush(stdin);
	}
	
	if(user_choice == 1){ print_database(); }
	if(user_choice == 2){ add_parts_to_database();}
	if(user_choice == 3){ remove_parts_from_database();}
	if(user_choice == 4){ search_database();}
	if(user_choice == 5){ exit_program();}
	else
	{
		printf("Please enter a proper value\r\n");
		menu();
	}
	
	return 0;
}
Beispiel #2
0
int menu()
{
    int user_choice;

    printf("1.Print Database\r\n");
    printf("2.Search Database\r\n");
    printf("3.Exit Database\r\n");

    while( scanf("%d",&user_choice) != 1)
    {
        fflush(stdin);
    }

    if(user_choice == 1) {
        print_database();
    }
    if(user_choice == 2) {
        search_database();
    }
    if(user_choice == 3) {
        exit_program();
    }
    else
    {
        printf("Please enter a proper value\r\n");
        menu();
    }

    return 0;
}
Beispiel #3
0
GList* get_deepin_categories(GDesktopAppInfo* info)
{
    char* basename = g_path_get_basename(g_desktop_app_info_get_filename(info));
    GList* categories = NULL;
    char* sql = g_strdup_printf("select first_category_name "
                                "from desktop "
                                "where desktop_name like \"%s\";", basename);
    g_debug("[%s] app: %s", __func__, basename);
    g_free(basename);
    search_database(get_category_name_db_path(), sql,
                    (SQLEXEC_CB)_get_all_possible_categories,
                    &categories);
    g_free(sql);

    return categories;
}
Beispiel #4
0
PRIVATE
void _load_category_info(GPtrArray* category_infos)
{
    const char* sql_category_info = "select distinct first_category_name from desktop;";
    if (!search_database(get_category_name_db_path(), sql_category_info,
                         (SQLEXEC_CB)_fill_category_info, category_infos)) {
        const char* const category_names[] = {
            INTERNET, MULTIMEDIA, GAMES, GRAPHICS, PRODUCTIVITY,
            INDUSTRY, EDUCATION, DEVELOPMENT, SYSTEM, UTILITIES,
        };
        int category_num = G_N_ELEMENTS(category_names);
        for (int i = 0; i < category_num; ++i)
            g_ptr_array_add(category_infos, g_strdup(category_names[i]));
    }

    /* add this for apps which cannot be categoried */
    g_ptr_array_add(category_infos, g_strdup(OTHER));
}
Beispiel #5
0
int find_category_id(const char* category_name)
{
    static GHashTable* _category_info = NULL;

    if (_category_info == NULL) {
        _category_info = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
        char const* sql = "select distinct first_category_name, first_category_index from category_name;";
        search_database(get_category_index_db_path(), sql,
                        (SQLEXEC_CB)_get_category_name_index_map, _category_info);

        for (gsize i = 0; i < X_CATEGORY_NUM; ++i)
            g_hash_table_insert(_category_info, g_strdup(_(x_category_name_index_map[i].name)),
                                GINT_TO_POINTER(x_category_name_index_map[i].index));
    }

    int id = OTHER_CATEGORY_ID;
    char* key = g_utf8_casefold(category_name, -1);
    gpointer tmp;
    if (g_hash_table_lookup_extended(_category_info, key, NULL, &tmp))
        id = GPOINTER_TO_INT(tmp);
    g_debug("[%s] category:%s:%d", __func__, key, id);
    g_free(key);
    return id;
}