-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowmenutest.c
56 lines (46 loc) · 1.82 KB
/
showmenutest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "parser.h"
/* For testers, move the files in desktop_files folder in the current git repo to wherever and modify the above string */
GPtrArray* showmenu(GPtrArray *desktop_files_array);
int main()
{
gsize i;
GPtrArray *desktop_files_array = g_ptr_array_new();
gchar *desktop_files_array_entry = NULL;
GPtrArray *valid_actions = NULL;
GDir *desktop_files_folder = NULL;
gchar *dir_entry;
GError *error = NULL;
gchar *user_config_dir = (gchar *)g_get_user_config_dir();
gchar *app_name = "GSOC";
gchar *desktop_files_path = g_build_path("/", user_config_dir, app_name, NULL);
//printf("User Config Dir = \"%s\"\n", user_config_dir);
//printf("Desktop files path = \"%s\"\n", desktop_files_path);
desktop_files_folder = g_dir_open(desktop_files_path, 0, &error);
if(desktop_files_folder == NULL){
fprintf(stderr, "%s\n", error->message);
g_error_free(error);
return -1;
}
/* Lookup the desktop_files_folder for .desktop files, and put the names in the desktop_files_array */
while((dir_entry = (gchar *)g_dir_read_name(desktop_files_folder)) != NULL){
if(g_str_has_suffix(dir_entry, ".desktop") == FALSE) continue;
desktop_files_array_entry = g_build_path("/", desktop_files_path, dir_entry, NULL);
//printf("%s\n", desktop_files_array_entry);
g_ptr_array_add(desktop_files_array, desktop_files_array_entry);
}
g_dir_close(desktop_files_folder);
/* Now pass on the array to showmenu() */
valid_actions = showmenu(desktop_files_array);
for(i=0;i<valid_actions->len;++i){
printf("%s is a valid action\n", (gchar *)(((FmActionEntry *)g_ptr_array_index(valid_actions, i))->id));
}
g_ptr_array_free(desktop_files_array, TRUE);
g_ptr_array_free(valid_actions, TRUE);
g_free(user_config_dir);
g_free(desktop_files_path);
return 0;
}