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>
- const int square_size = 30;
- int global, ini = 20, total;
- int width, height, heightini;
- char str[500], str2[500], str3[500], str4[500], str5[500], str6[500], slide[500];
- char image_list[5000][100];
- GtkWidget *fixed_layout;
- GtkWindow *window;
- GtkWidget *img;
- GtkWidget *dialog;
- GtkRequisition *allocator;
- GdkScreen *screen;
- GtkButton *openbutton, *closebutton, *nextbutton, *previousbutton, *playbutton, *aboutbutton, *gotofirstbutton, *gotolastbutton;
- GtkTooltips *opentooltip, *closetooltip, *nexttooltip, *previoustooltip, *playtooltip, *abouttooltip, *gotofirsttooltip, *gotolasttooltip;
- void wait(double seconds);
- void create_menu();
- void create_toolbar();
- void show_about();
- void open_file();
- void start_slide();
- void get_list(char filename[500]);
- void store_list();
- void show_next();
- void show_previous();
- void goto_first();
- void goto_last();
- static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data);
- void goto_first()
- {
- int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
- 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)
- {
- gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
- img = gtk_image_new_from_file(str5);
- gtk_container_add(GTK_CONTAINER(fixed_layout), img);
- GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
- pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
- gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
- gtk_widget_show(img);
- strcpy(slide, str5);
- flag3 = 1;
- break;
- }
- }
- }
- void goto_last()
- {
- int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
- 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)
- {
- gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
- img = gtk_image_new_from_file(str5);
- gtk_container_add(GTK_CONTAINER(fixed_layout), img);
- GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
- pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
- gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
- gtk_widget_show(img);
- strcpy(slide, str5);
- flag3 = 1;
- break;
- }
- }
- }
- void create_toolbar()
- {
- total = (8 * 30) + (10 * 7);
- ini = (width - total) / 2;
- openbutton = gtk_button_new();
- opentooltip = gtk_tooltips_new();
- gtk_widget_set_size_request(GTK_WIDGET(openbutton), square_size, square_size);
- gtk_button_set_image (GTK_BUTTON(openbutton),gtk_image_new_from_stock(GTK_STOCK_ORIENTATION_PORTRAIT, GTK_ICON_SIZE_BUTTON));
- gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(openbutton), ini, heightini - 40);
- gtk_tooltips_set_tip(opentooltip, GTK_WIDGET(openbutton), "Open (Ctrl+O)", "Open (Ctrl+O)");
- ini += 40;
- gotofirstbutton = gtk_button_new();
- gotofirsttooltip = gtk_tooltips_new();
- gtk_widget_set_size_request(GTK_WIDGET(gotofirstbutton), square_size, square_size);
- gtk_button_set_image (GTK_BUTTON(gotofirstbutton),gtk_image_new_from_stock(GTK_STOCK_GOTO_FIRST, GTK_ICON_SIZE_BUTTON));
- gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(gotofirstbutton), ini, heightini - 40);
- gtk_tooltips_set_tip(gotofirsttooltip, GTK_WIDGET(gotofirstbutton), "Go to first image (Page Up)", "Go to first image (Page Up)");
- ini += 40;
- previousbutton = gtk_button_new();
- previoustooltip = gtk_tooltips_new();
- gtk_widget_set_size_request(GTK_WIDGET(previousbutton), square_size, square_size);
- gtk_button_set_image (GTK_BUTTON(previousbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PREVIOUS, GTK_ICON_SIZE_BUTTON));
- gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(previousbutton), ini, heightini - 40);
- gtk_tooltips_set_tip(previoustooltip, GTK_WIDGET(previousbutton), "Show Previous (Left key)", "Show Previous (Left key)");
- ini += 40;
- playbutton = gtk_button_new();
- playtooltip = gtk_tooltips_new();
- gtk_widget_set_size_request(GTK_WIDGET(playbutton), square_size, square_size);
- gtk_button_set_image (GTK_BUTTON(playbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_BUTTON));
- gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(playbutton), ini, heightini - 40);
- gtk_tooltips_set_tip(playtooltip, GTK_WIDGET(playbutton), "Start Slideshow (Spacebar)", "Start Slideshow (Spacebar)");
- ini += 40;
- nextbutton = gtk_button_new();
- nexttooltip = gtk_tooltips_new();
- gtk_widget_set_size_request(GTK_WIDGET(nextbutton), square_size, square_size);
- gtk_button_set_image (GTK_BUTTON(nextbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_NEXT, GTK_ICON_SIZE_BUTTON));
- gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(nextbutton), ini, heightini - 40);
- gtk_tooltips_set_tip(nexttooltip, GTK_WIDGET(nextbutton), "Show Next (Right Key)", "Show Next (Right Key)");
- ini += 40;
- gotolastbutton = gtk_button_new();
- gotolasttooltip = gtk_tooltips_new();
- gtk_widget_set_size_request(GTK_WIDGET(gotolastbutton), square_size, square_size);
- gtk_button_set_image (GTK_BUTTON(gotolastbutton),gtk_image_new_from_stock(GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON));
- gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(gotolastbutton), ini, heightini - 40);
- gtk_tooltips_set_tip(gotolasttooltip, GTK_WIDGET(gotolastbutton), "Go to last image (Page Down)", "Go to last image (Page Down)");
- ini += 40;
- aboutbutton = gtk_button_new();
- abouttooltip = gtk_tooltips_new();
- gtk_widget_set_size_request(GTK_WIDGET(aboutbutton), square_size, square_size);
- gtk_button_set_image (GTK_BUTTON(aboutbutton),gtk_image_new_from_stock(GTK_STOCK_INFO, GTK_ICON_SIZE_BUTTON));
- gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(aboutbutton), ini, heightini - 40);
- gtk_tooltips_set_tip(abouttooltip, GTK_WIDGET(aboutbutton), "About Us :)", "About Us :)");
- ini += 40;
- closebutton = gtk_button_new();
- closetooltip = gtk_tooltips_new();
- gtk_widget_set_size_request(GTK_WIDGET(closebutton), square_size, square_size);
- gtk_button_set_image (GTK_BUTTON(closebutton),gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON));
- gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(closebutton), ini, heightini - 40);
- gtk_tooltips_set_tip(closetooltip, GTK_WIDGET(closebutton), "Close :( (Ctrl+Q)", "Close :( (Ctrl+Q)");
- }
- void wait(double seconds)
- {
- clock_t lol;
- lol = clock() + (seconds * CLOCKS_PER_SEC);
- while(clock() < lol)
- {
- if (clock() % 100 == 0) gtk_widget_show(img);
- }
- }
- void show_about()
- {
- GtkWidget *dialog;
- const char copyright[] = "Copyright Fireflight TM, 2011-Present. All rights reserved.";
- const char *author[] = {"Scape", "mr.rana", "(And special thanks to Mehedi Hasan and Shadman Shadab)", "", "Contact information: sgtlaugh@gmail.com",NULL};
- dialog = gtk_about_dialog_new();
- gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"Firedlight Image Viewer v1.052 (beta)");
- gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
- gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), copyright);
- gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"A free image viewer :)");
- gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS);
- gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(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(fixed_layout), img);
- img = gtk_image_new_from_file(filename);
- GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
- pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
- gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
- gtk_widget_show(img);
- gtk_container_add(GTK_CONTAINER(fixed_layout), img);
- g_free (filename);
- }
- gtk_widget_destroy (dialog);
- }
- 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->keyval == GDK_KEY_Right)
- show_next();
- if (lol->keyval == GDK_KEY_Left)
- show_previous();
- if (lol->keyval == GDK_KEY_space)
- start_slide();
- if (lol->keyval == GDK_KEY_Page_Up)
- goto_first();
- if (lol->keyval == GDK_KEY_Page_Down)
- goto_last();
- return TRUE;
- }
- void start_slide()
- {
- }
- void get_list(char filename[500])
- {
- 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(fixed_layout), img);
- img = gtk_image_new_from_file(str5);
- gtk_container_add(GTK_CONTAINER(fixed_layout), img);
- GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
- pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
- gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
- 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(fixed_layout), img);
- img = gtk_image_new_from_file(str5);
- gtk_container_add(GTK_CONTAINER(fixed_layout), img);
- GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
- pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
- gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
- 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[])
- {
- gtk_init(&argc, &argv);
- width = gdk_screen_width();
- height = gdk_screen_height();
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_skip_taskbar_hint (window, TRUE);
- gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
- gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
- gtk_widget_set_size_request(GTK_WIDGET(window), width, height);
- gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
- heightini = height;
- height = (height * 16) / 17;
- fixed_layout = gtk_fixed_new();
- char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg";
- img = gtk_image_new_from_file(picturename);
- GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
- pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
- gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
- strcpy(slide, picturename);
- gtk_container_add(GTK_CONTAINER(fixed_layout), img);
- create_toolbar();
- gtk_container_add(GTK_CONTAINER(window), fixed_layout);
- get_list(picturename);
- store_list();
- system(str2);
- gtk_window_fullscreen(window);
- //gtk_window_set_skip_taskbar_hint(window, 1);
- g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
- g_signal_connect(G_OBJECT(openbutton), "clicked", G_CALLBACK(open_file), NULL);
- g_signal_connect(G_OBJECT(gotofirstbutton), "clicked", G_CALLBACK(goto_first), NULL);
- g_signal_connect(G_OBJECT(gotolastbutton), "clicked", G_CALLBACK(goto_last), NULL);
- g_signal_connect(G_OBJECT(aboutbutton), "clicked", G_CALLBACK(show_about), NULL);
- g_signal_connect(G_OBJECT(closebutton), "clicked",G_CALLBACK(gtk_main_quit), NULL);
- g_signal_connect(G_OBJECT(playbutton), "clicked",G_CALLBACK(start_slide), NULL);
- g_signal_connect(G_OBJECT(nextbutton), "clicked",G_CALLBACK(show_next), NULL);
- g_signal_connect(G_OBJECT(previousbutton), "clicked",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