added input directory and files scan
This commit is contained in:
88
main.c
88
main.c
@@ -1,32 +1,98 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
int *check_dir(int *arr, DIR *d, char *directory){
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
// char label[100];
|
||||||
|
// DIR *d;
|
||||||
|
struct dirent *dir;
|
||||||
|
d = opendir(directory);
|
||||||
|
printf("dirrrr %s %s\n", d);
|
||||||
|
if (d) {
|
||||||
|
while ((dir = readdir(d)) != NULL){
|
||||||
|
char *name = dir->d_name;
|
||||||
|
printf("%s\n", name);
|
||||||
|
if (*name == '.'){
|
||||||
|
printf("directory starts with .\n");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
i += 1;
|
||||||
|
if(i - 10 == 0){
|
||||||
|
i = 0;
|
||||||
|
j += 1;
|
||||||
|
}
|
||||||
|
// printf("%i %i \n",i,j);
|
||||||
|
// printf("%s\n", dir->d_name);
|
||||||
|
// sprintf(label, "%d" ,dir->d_name);
|
||||||
|
// char *lll = label;
|
||||||
|
// return lll;
|
||||||
|
arr[0] = i;
|
||||||
|
arr[1] = j;
|
||||||
|
// printf("%i %i\n", i,j);
|
||||||
|
// printf("%i %i\n",arr[0],arr[1]);
|
||||||
|
}
|
||||||
|
// closedir(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void app_activate (GtkApplication *app, gpointer *user_data){
|
static void app_activate (GtkApplication *app, gpointer *user_data){
|
||||||
|
int p[2];
|
||||||
|
int g;
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
DIR *d;
|
||||||
|
struct dirent *dir;
|
||||||
|
char directory[100];
|
||||||
|
scanf("%100[^\n]", &directory);
|
||||||
|
d = opendir(directory);
|
||||||
GtkWidget *window = gtk_application_window_new (GTK_APPLICATION(app));
|
GtkWidget *window = gtk_application_window_new (GTK_APPLICATION(app));
|
||||||
gtk_window_set_title (GTK_WINDOW (window), "File Manager");
|
gtk_window_set_title (GTK_WINDOW (window), "File Manager");
|
||||||
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
|
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
|
||||||
gtk_window_set_application(GTK_WINDOW(window),app);
|
gtk_window_set_application(GTK_WINDOW(window),app);
|
||||||
|
|
||||||
GtkWidget* grid = gtk_grid_new();
|
GtkWidget* grid = gtk_grid_new();
|
||||||
|
check_dir(p, d, directory);
|
||||||
for (int i = 0; i<2;i++){
|
printf("%i %i\n",p[0],p[1]);
|
||||||
for (int j = 0; j<10;j++){
|
g = 10;
|
||||||
|
while ((dir = readdir(d)) != NULL && i <=p[1] && j < g){
|
||||||
|
if (d) {
|
||||||
|
printf("directory names\n");
|
||||||
|
char *name = dir->d_name;
|
||||||
|
printf("%s\n", name);
|
||||||
|
if (*name == '.'){
|
||||||
|
printf("directory starts with .\n");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (i == p[1]){
|
||||||
|
printf("i=10 g=p[0]\n");
|
||||||
|
g = p[0];
|
||||||
|
}
|
||||||
|
// char lablell[100];
|
||||||
|
printf("set directory label\n");
|
||||||
GtkWidget* btn = gtk_button_new();
|
GtkWidget* btn = gtk_button_new();
|
||||||
gtk_grid_set_row_spacing(GTK_GRID (grid), 10);
|
gtk_grid_set_row_spacing(GTK_GRID (grid), 10);
|
||||||
gtk_grid_set_column_spacing(GTK_GRID (grid), 10);
|
gtk_grid_set_column_spacing(GTK_GRID (grid), 10);
|
||||||
gtk_grid_set_column_homogeneous(GTK_GRID (grid), TRUE);
|
gtk_grid_set_column_homogeneous(GTK_GRID (grid), TRUE);
|
||||||
gtk_grid_set_row_homogeneous(GTK_GRID (grid), TRUE);
|
gtk_grid_set_row_homogeneous(GTK_GRID (grid), TRUE);
|
||||||
char *label = "waht";
|
// sprintf(lablell, "" ,check_dir());
|
||||||
gtk_button_set_label(GTK_BUTTON(btn),label);
|
gtk_button_set_label(GTK_BUTTON(btn),name);
|
||||||
gtk_grid_attach (GTK_GRID(grid), btn, j, i, 1,1);
|
gtk_grid_attach (GTK_GRID(grid), btn, j, i, 1,1);
|
||||||
gtk_widget_set_halign(btn, GTK_ALIGN_CENTER);
|
gtk_widget_set_halign(btn, GTK_ALIGN_CENTER);
|
||||||
gtk_widget_set_valign(btn, GTK_ALIGN_CENTER);
|
gtk_widget_set_valign(btn, GTK_ALIGN_CENTER);
|
||||||
|
j++;
|
||||||
|
if (j >= 9){
|
||||||
|
j = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(d);
|
||||||
|
printf("set child and present window");
|
||||||
gtk_window_set_child(GTK_WINDOW(window),grid);
|
gtk_window_set_child(GTK_WINDOW(window),grid);
|
||||||
printf("%i %i \n ",i,j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_window_present(GTK_WINDOW(window));
|
gtk_window_present(GTK_WINDOW(window));
|
||||||
g_print("Started\n");
|
g_print("Started\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user