Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <cairo.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #include <gtk/gtk.h>
- #include <gdk/gdk.h>
- #include <gdk/gdkkeysyms.h>
- #include <gdk-pixbuf/gdk-pixbuf.h>
- int global;
- char str[500], str2[500], str3[500], str4[500], str5[500], str6[500], slide[500];
- char image_list[5000][100];
- GtkContainer *box;
- GtkWindow *window;
- GtkWidget *vbox;
- GtkWidget *menubar, *filemenu, *help, *helpmenu;
- GtkWidget *file, *quit, *open, *save, *properties, *about, *slideshow, *shownext, *showprevious;
- GtkWidget *img, *img2;
- GtkWidget *dialog;
- GtkRequisition *allocator;
- void wait(double seconds);
- void create_menu();
- void show_about();
- void open_file();
- void show_properties();
- static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data);
- void start_slide();
- void get_list(char filename[500]);
- void store_list();
- void show_next();
- void show_previous();
- void wait(double seconds)
- {
- clock_t lol;
- lol = clock() + (seconds * CLOCKS_PER_SEC);
- while(clock() < lol) {}
- }
- void create_menu()
- {
- vbox = gtk_vbox_new(FALSE, 0);
- box = gtk_vbox_new(FALSE, 0);
- gtk_box_pack_start(GTK_BOX(box), vbox, TRUE, TRUE, 0);
- menubar = gtk_menu_bar_new();
- filemenu = gtk_menu_new();
- file = gtk_menu_item_new_with_label("File");
- quit = gtk_menu_item_new_with_label("Quit Ctrl + Q");
- open = gtk_menu_item_new_with_label("Open Ctrl + O");
- save = gtk_menu_item_new_with_label("Save");
- slideshow = gtk_menu_item_new_with_label("Start Slide");
- showprevious = gtk_menu_item_new_with_label("Show Previous");
- shownext = gtk_menu_item_new_with_label("Show Next");
- properties = gtk_menu_item_new_with_label("Properties Ctrl + P");
- gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
- gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
- gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save);
- gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), slideshow);
- gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), showprevious);
- gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), shownext);
- gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), properties);
- gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
- gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
- helpmenu = gtk_menu_new();
- about = gtk_menu_item_new_with_label("About");
- help = gtk_menu_item_new_with_label("Help");
- gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), helpmenu);
- gtk_menu_shell_append(GTK_MENU_SHELL(helpmenu), about);
- gtk_menu_shell_append(GTK_MENU_SHELL(menubar), help);
- gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
- }
- void show_about()
- {
- GtkWidget *dialog;
- const char *author[] = {"None yet\n(However, Special thanks to Mehedi Hasan and\nShadman Shadab :-) )",NULL};
- dialog = gtk_about_dialog_new();
- gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"You just clicked about!");
- gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
- gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"Good job and go to hell!!");
- gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
- gtk_dialog_run(GTK_DIALOG(dialog));
- }
- void open_file()
- {
- dialog = gtk_file_chooser_dialog_new ("Open File",window,GTK_FILE_CHOOSER_ACTION_OPEN,GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,NULL);
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
- {
- char *filename;
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- strcpy(slide, filename);
- get_list(filename);
- store_list();
- system(str2);
- gtk_container_remove(GTK_CONTAINER(box), img);
- img = gtk_image_new_from_file(filename);
- gtk_widget_show(img);
- gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
- g_free (filename);
- }
- gtk_widget_destroy (dialog);
- }
- void show_properties()
- {
- }
- static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data)
- {
- if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_q || lol->keyval == GDK_KEY_Q))
- exit (0x0);
- if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_O || lol->keyval == GDK_KEY_o))
- open_file();
- if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_P || lol->keyval == GDK_KEY_p))
- show_properties();
- if (lol->keyval == GDK_KEY_Right)
- show_next();
- if (lol->keyval == GDK_KEY_Left)
- show_previous();
- return TRUE;
- }
- void start_slide()
- {
- }
- void get_list(char filename[500])
- {
- puts(filename);
- int k = 0, j, l = 0, x;
- int len = strlen(filename);
- for (j = len - 1; filename[j] != '\\'; j--) x = 1;
- str[0] = 0;
- strcat(str, "cd /d ");
- for (k = 0; k < j; k++) str4[l++] = filename[k];
- str4[l] = 0;
- str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
- system(str3);
- strcat(str, str4);
- strcpy(str2, str);
- strcat(str, " && dir /b >> dir_listing.txt");
- strcat(str2, " && del dir_listing.txt");
- system(str);
- strcat(str4, "\\dir_listing.txt");
- }
- void store_list()
- {
- FILE *input;
- input = fopen(str4, "r");
- for (global = 0; ;global++)
- {
- if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
- fgetc(input);
- }
- fclose(input);
- }
- void show_next()
- {
- int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
- for (; ;)
- {
- for (i = 0; i < global; i++)
- {
- strcpy(str3, image_list[i]);
- l = 0, len = strlen(slide);
- str5[0] = 0;
- for (j = len - 1; slide[j] != '\\'; j--) k = 1;
- for (k = 0; k <= j; k++) str5[l++] = slide[k];
- str5[l] = 0, k = 0;
- strcat(str5, str3), len = strlen(str3);
- for (l = len - 4; l < len; l++) str6[k++] = str3[l];
- str6[k] = 0;
- if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
- {
- if (flag2 == 1)
- {
- gtk_container_remove(GTK_CONTAINER(box), img);
- img = gtk_image_new_from_file(str5);
- gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
- gtk_widget_show(img);
- strcpy(slide, str5);
- flag3 = 1;
- break;
- }
- if (strcmp(str5, slide) == 0) flag2 = 1;
- }
- }
- if (flag3 == 1) break;
- }
- }
- void show_previous()
- {
- int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
- for (; ;)
- {
- for (i = global - 1; i >= 0; i--)
- {
- strcpy(str3, image_list[i]);
- l = 0, len = strlen(slide);
- str5[0] = 0;
- for (j = len - 1; slide[j] != '\\'; j--) k = 1;
- for (k = 0; k <= j; k++) str5[l++] = slide[k];
- str5[l] = 0, k = 0;
- strcat(str5, str3), len = strlen(str3);
- for (l = len - 4; l < len; l++) str6[k++] = str3[l];
- str6[k] = 0;
- if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
- {
- if (flag2 == 1)
- {
- gtk_container_remove(GTK_CONTAINER(box), img);
- img = gtk_image_new_from_file(str5);
- gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
- gtk_widget_show(img);
- strcpy(slide, str5);
- flag3 = 1;
- break;
- }
- if (strcmp(str5, slide) == 0) flag2 = 1;
- }
- }
- if (flag3 == 1) break;
- }
- }
- int main(int argc, char *argv[])
- {
- GdkScreen *screen;
- gtk_init(&argc, &argv);
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- //gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
- gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
- gtk_window_set_default_size(GTK_WINDOW(window), 800, 500);
- gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
- create_menu();
- char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg";
- img = gtk_image_new_from_file(picturename);
- strcpy(slide, picturename);
- gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
- gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(box));
- get_list(picturename);
- store_list();
- system(str2);
- g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
- g_signal_connect(G_OBJECT(open), "activate", G_CALLBACK(open_file), NULL);
- g_signal_connect(G_OBJECT(properties), "activate", G_CALLBACK(show_properties), NULL);
- g_signal_connect(G_OBJECT(about), "activate", G_CALLBACK(show_about), NULL);
- g_signal_connect(G_OBJECT(quit), "activate",G_CALLBACK(gtk_main_quit), NULL);
- g_signal_connect(G_OBJECT(slideshow), "activate",G_CALLBACK(start_slide), NULL);
- g_signal_connect(G_OBJECT(shownext), "activate",G_CALLBACK(show_next), NULL);
- g_signal_connect(G_OBJECT(showprevious), "activate",G_CALLBACK(show_previous), NULL);
- g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
- gtk_widget_show_all(GTK_WIDGET(window));
- gtk_main();
- return 0x0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement