Advertisement
palmerstone

Gtk 12

Nov 27th, 2011
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LOL Code 22.97 KB | None | 0 0
  1. #include <cairo.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <windows.h>
  5. #include <gtk/gtk.h>
  6. #include <gdk/gdk.h>
  7. #include <gdk/gdkkeysyms.h>
  8. #include <gdk-pixbuf/gdk-pixbuf.h>
  9.  
  10. const int square_size = 30;
  11. const double ratio = 1.150;
  12. int global, ini, total, flag = 0;
  13. int width, height, heightini, zoom_width, zoom_height;
  14. char str[500], str2[500], str3[500], str4[500], str5[500], str6[500], slide[500];
  15. char image_list[5000][100];
  16.  
  17. GtkWindow *window;
  18. GdkPixbuf *windowicon;
  19. GtkWidget *fixed_layout, *img, *dialog, *gbdialog;
  20. GtkButton *openbutton, *closebutton, *nextbutton, *previousbutton, *playbutton, *aboutbutton, *gotofirstbutton, *gotolastbutton, *zoom_in_button, *zoom_out_button, *stopbutton;
  21. GtkTooltips *opentooltip, *closetooltip, *nexttooltip, *previoustooltip, *playtooltip, *abouttooltip, *gotofirsttooltip, *gotolasttooltip, *zoom_in_tooltip, *zoom_out_tooltip, *stoptooltip;
  22.  
  23. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data);
  24. void create_menu();
  25. void create_toolbar();
  26. void show_about();
  27. void open_file();
  28. void start_slide();
  29. void stop_slide();
  30. void get_list(char filename[500]);
  31. void store_list();
  32. gboolean show_next(gpointer userdata);
  33. void show_next2();
  34. void show_previous();
  35. void goto_first();
  36. void goto_last();
  37. void zoom_in();
  38. void zoom_out();
  39. void goodbye_dialog();
  40.  
  41. void create_toolbar()
  42. {
  43.     total = (8 * 30) + (10 * 7);
  44.     ini = (width - total) / 2;
  45.  
  46.     openbutton = gtk_button_new();
  47.     opentooltip = gtk_tooltips_new();
  48.     gtk_widget_set_size_request(GTK_WIDGET(openbutton), square_size, square_size);
  49.     gtk_button_set_image (GTK_BUTTON(openbutton),gtk_image_new_from_stock(GTK_STOCK_ORIENTATION_PORTRAIT, GTK_ICON_SIZE_BUTTON));
  50.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(openbutton), ini, heightini - 40);
  51.     gtk_tooltips_set_tip(opentooltip, GTK_WIDGET(openbutton), "Open   (Ctrl+O)", "Open   (Ctrl+O)");
  52.  
  53.     ini += 40;
  54.     gotofirstbutton = gtk_button_new();
  55.     gotofirsttooltip = gtk_tooltips_new();
  56.     gtk_widget_set_size_request(GTK_WIDGET(gotofirstbutton), square_size, square_size);
  57.     gtk_button_set_image (GTK_BUTTON(gotofirstbutton),gtk_image_new_from_stock(GTK_STOCK_GOTO_FIRST, GTK_ICON_SIZE_BUTTON));
  58.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(gotofirstbutton), ini, heightini - 40);
  59.     gtk_tooltips_set_tip(gotofirsttooltip, GTK_WIDGET(gotofirstbutton), "Go to first image   (Page Up)", "Go to first image   (Page Up)");
  60.  
  61.     ini += 40;
  62.     previousbutton = gtk_button_new();
  63.     previoustooltip = gtk_tooltips_new();
  64.     gtk_widget_set_size_request(GTK_WIDGET(previousbutton), square_size, square_size);
  65.     gtk_button_set_image (GTK_BUTTON(previousbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PREVIOUS, GTK_ICON_SIZE_BUTTON));
  66.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(previousbutton), ini, heightini - 40);
  67.     gtk_tooltips_set_tip(previoustooltip, GTK_WIDGET(previousbutton), "Show Previous   (Left key)", "Show Previous   (Left key)");
  68.  
  69.     ini += 40;
  70.     playbutton = gtk_button_new();
  71.     playtooltip = gtk_tooltips_new();
  72.     gtk_widget_set_size_request(GTK_WIDGET(playbutton), square_size, square_size);
  73.     gtk_button_set_image (GTK_BUTTON(playbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_BUTTON));
  74.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(playbutton), ini, heightini - 40);
  75.     gtk_tooltips_set_tip(playtooltip, GTK_WIDGET(playbutton), "Start Slideshow   (Spacebar)", "Start Slideshow   (Spacebar)");
  76.  
  77.     stopbutton = gtk_button_new();
  78.     stoptooltip = gtk_tooltips_new();
  79.     gtk_widget_set_size_request(GTK_WIDGET(stopbutton), square_size, square_size);
  80.     gtk_button_set_image (GTK_BUTTON(stopbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_BUTTON));
  81.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(stopbutton), ini, heightini - 40);
  82.     gtk_tooltips_set_tip(stoptooltip, GTK_WIDGET(stopbutton), "Stop Slideshow   (Spacebar)", "Stop Slideshow   (Spacebar)");
  83.  
  84.     ini += 40;
  85.     nextbutton = gtk_button_new();
  86.     nexttooltip = gtk_tooltips_new();
  87.     gtk_widget_set_size_request(GTK_WIDGET(nextbutton), square_size, square_size);
  88.     gtk_button_set_image (GTK_BUTTON(nextbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_NEXT, GTK_ICON_SIZE_BUTTON));
  89.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(nextbutton), ini, heightini - 40);
  90.     gtk_tooltips_set_tip(nexttooltip, GTK_WIDGET(nextbutton), "Show Next   (Right Key)", "Show Next   (Right Key)");
  91.  
  92.     ini += 40;
  93.     gotolastbutton = gtk_button_new();
  94.     gotolasttooltip = gtk_tooltips_new();
  95.     gtk_widget_set_size_request(GTK_WIDGET(gotolastbutton), square_size, square_size);
  96.     gtk_button_set_image (GTK_BUTTON(gotolastbutton),gtk_image_new_from_stock(GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON));
  97.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(gotolastbutton), ini, heightini - 40);
  98.     gtk_tooltips_set_tip(gotolasttooltip, GTK_WIDGET(gotolastbutton), "Go to last image   (Page Down)", "Go to last image   (Page Down)");
  99.  
  100.     ini += 40;
  101.     aboutbutton = gtk_button_new();
  102.     abouttooltip = gtk_tooltips_new();
  103.     gtk_widget_set_size_request(GTK_WIDGET(aboutbutton), square_size, square_size);
  104.     gtk_button_set_image (GTK_BUTTON(aboutbutton),gtk_image_new_from_stock(GTK_STOCK_INFO, GTK_ICON_SIZE_BUTTON));
  105.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(aboutbutton), ini, heightini - 40);
  106.     gtk_tooltips_set_tip(abouttooltip, GTK_WIDGET(aboutbutton), "About Us :)", "About Us :)");
  107.  
  108.     ini += 40;
  109.     closebutton = gtk_button_new();
  110.     closetooltip = gtk_tooltips_new();
  111.     gtk_widget_set_size_request(GTK_WIDGET(closebutton), square_size, square_size);
  112.     gtk_button_set_image (GTK_BUTTON(closebutton),gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON));
  113.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(closebutton), ini, heightini - 40);
  114.     gtk_tooltips_set_tip(closetooltip, GTK_WIDGET(closebutton), "Close :(   (Ctrl+Q)", "Close :(   (Ctrl+Q)");
  115.  
  116.     ini = width - 150;
  117.     zoom_in_button = gtk_button_new();
  118.     zoom_in_tooltip = gtk_tooltips_new();
  119.     gtk_widget_set_size_request(GTK_WIDGET(zoom_in_button), square_size, square_size);
  120.     gtk_button_set_image (GTK_BUTTON(zoom_in_button),gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_BUTTON));
  121.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(zoom_in_button), ini, heightini - 40);
  122.     gtk_tooltips_set_tip(zoom_in_tooltip, GTK_WIDGET(zoom_in_button), "Zoom In   (+)", "Zoom In   (+)");
  123.  
  124.     ini -= 40;
  125.     zoom_out_button = gtk_button_new();
  126.     zoom_out_tooltip = gtk_tooltips_new();
  127.     gtk_widget_set_size_request(GTK_WIDGET(zoom_out_button), square_size, square_size);
  128.     gtk_button_set_image (GTK_BUTTON(zoom_out_button),gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_BUTTON));
  129.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(zoom_out_button), ini, heightini - 40);
  130.     gtk_tooltips_set_tip(zoom_out_tooltip, GTK_WIDGET(zoom_out_button), "Zoom Out   (-)", "Zoom Out   (-)");
  131. }
  132.  
  133. void show_about()
  134. {
  135.     GtkWidget *dialog;
  136.     const char copyright[] = "Copyright @ Fireflight TM, 2011. All rights reserved.";
  137.     const char *author[] = {"Scape", "mr.rana", "(And special thanks to Mehedi Hasan and Shadman Shadab)", "", "Contact information: sgtlaugh@gmail.com",NULL};
  138.     dialog = gtk_about_dialog_new();
  139.     gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"Firedlight Image Viewer v1.052 (beta)");
  140.     gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
  141.     gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), copyright);
  142.     gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"A free image viewer :)");
  143.     windowicon = gdk_pixbuf_new_from_file(slide, NULL);
  144.     gtk_window_set_icon(GTK_WINDOW(dialog), windowicon);
  145.     gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS);
  146.     gtk_dialog_run(GTK_DIALOG(dialog));
  147.     gtk_widget_destroy(dialog);
  148. }
  149.  
  150. void open_file()
  151. {
  152.     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);
  153.     if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  154.     {
  155.         char *filename;
  156.         filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  157.         strcpy(slide, filename);
  158.         get_list(filename);
  159.         store_list();
  160.         system(str2);
  161.         gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  162.         img = gtk_image_new_from_file(filename);
  163.         windowicon = gdk_pixbuf_new_from_file(filename, NULL);
  164.         gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  165.         GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  166.         pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  167.         gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  168.         gtk_widget_show(img);
  169.         gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  170.         g_free (filename);
  171.     }
  172.     gtk_widget_destroy (dialog);
  173. }
  174.  
  175. void zoom_in()
  176. {
  177.     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  178.     double x = zoom_width;
  179.     double y = zoom_height;
  180.     x = x * ratio, y = y * ratio;
  181.     zoom_width = x, zoom_height = y;
  182.     pixbuf = gdk_pixbuf_scale_simple(pixbuf, zoom_width, zoom_height, GDK_INTERP_HYPER);
  183.     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  184. }
  185.  
  186. void zoom_out()
  187. {
  188.     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  189.     double x = zoom_width;
  190.     double y = zoom_height;
  191.     double d = (double) 1 / ratio;
  192.     x = x * d, y = y * d;
  193.     zoom_width = x, zoom_height = y;
  194.     pixbuf = gdk_pixbuf_scale_simple(pixbuf, zoom_width, zoom_height, GDK_INTERP_HYPER);
  195.     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  196. }
  197.  
  198. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data)
  199. {
  200.     if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_q || lol->keyval == GDK_KEY_Q))
  201.         goodbye_dialog();
  202.     if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_O || lol->keyval == GDK_KEY_o))
  203.         open_file();
  204.     if (lol->keyval == GDK_KEY_Right)
  205.         show_next2();
  206.     if (lol->keyval == GDK_KEY_Left)
  207.         show_previous();
  208.     if (lol->keyval == GDK_KEY_space)
  209.     {
  210.         if (flag == 0) flag = 1;
  211.         else flag = 0;
  212.         if (flag == 1) start_slide();
  213.         else stop_slide();
  214.     }
  215.     if (lol->keyval == GDK_KEY_Page_Up)
  216.         goto_first();
  217.     if (lol->keyval == GDK_KEY_Page_Down)
  218.         goto_last();
  219.     if (lol->keyval == GDK_KEY_plus)
  220.         zoom_in();
  221.     if (lol->keyval == GDK_KEY_minus)
  222.         zoom_out();
  223.     return TRUE;
  224. }
  225.  
  226.  
  227. void start_slide()
  228. {
  229.     flag = 1;
  230.     gint func_ref = g_timeout_add(3000, show_next, (gpointer)32);
  231.     gtk_widget_hide(GTK_WIDGET(playbutton));
  232.     gtk_widget_hide(GTK_WIDGET(openbutton));
  233.     gtk_widget_hide(GTK_WIDGET(closebutton));
  234.     gtk_widget_hide(GTK_WIDGET(zoom_in_button));
  235.     gtk_widget_hide(GTK_WIDGET(zoom_out_button));
  236.     gtk_widget_hide(GTK_WIDGET(gotofirstbutton));
  237.     gtk_widget_hide(GTK_WIDGET(gotolastbutton));
  238.     gtk_widget_hide(GTK_WIDGET(nextbutton));
  239.     gtk_widget_hide(GTK_WIDGET(previousbutton));
  240.     gtk_widget_hide(GTK_WIDGET(aboutbutton));
  241.     gtk_widget_show(GTK_WIDGET(stopbutton));
  242.  
  243. }
  244.  
  245. void stop_slide()
  246. {
  247.     flag = 0;
  248.     gint func_ref = g_timeout_add(10000000, show_next, (gpointer)32);
  249.     gtk_widget_hide(GTK_WIDGET(stopbutton));
  250.     gtk_widget_show(GTK_WIDGET(playbutton));
  251.     gtk_widget_show(GTK_WIDGET(openbutton));
  252.     gtk_widget_show(GTK_WIDGET(closebutton));
  253.     gtk_widget_show(GTK_WIDGET(zoom_in_button));
  254.     gtk_widget_show(GTK_WIDGET(zoom_out_button));
  255.     gtk_widget_show(GTK_WIDGET(gotofirstbutton));
  256.     gtk_widget_show(GTK_WIDGET(gotolastbutton));
  257.     gtk_widget_show(GTK_WIDGET(nextbutton));
  258.     gtk_widget_show(GTK_WIDGET(previousbutton));
  259.     gtk_widget_show(GTK_WIDGET(aboutbutton));
  260. }
  261.  
  262. void get_list(char filename[500])
  263. {
  264.     int k = 0, j, l = 0, x;
  265.     int len = strlen(filename);
  266.     for (j = len - 1; filename[j] != '\\'; j--) x = 1;
  267.     str[0] = 0;
  268.     strcat(str, "cd /d ");
  269.     for (k = 0; k < j; k++) str4[l++] = filename[k];
  270.     str4[l] = 0;
  271.     str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
  272.     system(str3);
  273.     strcat(str, str4);
  274.     strcpy(str2, str);
  275.     strcat(str, " && dir /b >> dir_listing.txt");
  276.     strcat(str2, " && del dir_listing.txt");
  277.     system(str);
  278.     strcat(str4, "\\dir_listing.txt");
  279. }
  280.  
  281. void store_list()
  282. {
  283.     FILE *input;
  284.     input = fopen(str4, "r");
  285.     for (global = 0; ;global++)
  286.     {
  287.         if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
  288.         fgetc(input);
  289.     }
  290.     fclose(input);
  291. }
  292.  
  293. gboolean show_next(gpointer userdata)
  294. {
  295.     if (flag == 0) return FALSE;
  296.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  297.     for (; ;)
  298.     {
  299.         for (i = 0; i < global; i++)
  300.         {
  301.             strcpy(str3, image_list[i]);
  302.             l = 0, len = strlen(slide);
  303.             str5[0] = 0;
  304.             for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  305.             for (k = 0; k <= j; k++) str5[l++] = slide[k];
  306.             str5[l] = 0, k = 0;
  307.             strcat(str5, str3), len = strlen(str3);
  308.             for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  309.             str6[k] = 0;
  310.             if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  311.             {
  312.                 if (flag2 == 1)
  313.                 {
  314.                     gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  315.                     img = gtk_image_new_from_file(str5);
  316.                     gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  317.                     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  318.                     pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  319.                     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  320.                     windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  321.                     gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  322.                     gtk_widget_show(img);
  323.                     strcpy(slide, str5);
  324.                     flag3 = 1;
  325.                     break;
  326.  
  327.                 }
  328.                 if (strcmp(str5, slide) == 0) flag2 = 1;
  329.             }
  330.         }
  331.         if (flag3 == 1) break;
  332.     }
  333.     return TRUE;
  334. }
  335.  
  336. void show_next2()
  337. {
  338.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  339.     for (; ;)
  340.     {
  341.         for (i = 0; i < global; i++)
  342.         {
  343.             strcpy(str3, image_list[i]);
  344.             l = 0, len = strlen(slide);
  345.             str5[0] = 0;
  346.             for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  347.             for (k = 0; k <= j; k++) str5[l++] = slide[k];
  348.             str5[l] = 0, k = 0;
  349.             strcat(str5, str3), len = strlen(str3);
  350.             for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  351.             str6[k] = 0;
  352.             if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  353.             {
  354.                 if (flag2 == 1)
  355.                 {
  356.                     gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  357.                     img = gtk_image_new_from_file(str5);
  358.                     gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  359.                     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  360.                     pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  361.                     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  362.                     windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  363.                     gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  364.                     gtk_widget_show(img);
  365.                     strcpy(slide, str5);
  366.                     flag3 = 1;
  367.                     break;
  368.  
  369.                 }
  370.                 if (strcmp(str5, slide) == 0) flag2 = 1;
  371.             }
  372.         }
  373.         if (flag3 == 1) break;
  374.     }
  375. }
  376.  
  377. void show_previous()
  378. {
  379.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  380.     for (; ;)
  381.     {
  382.         for (i = global - 1; i >= 0; i--)
  383.         {
  384.             strcpy(str3, image_list[i]);
  385.             l = 0, len = strlen(slide);
  386.             str5[0] = 0;
  387.             for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  388.             for (k = 0; k <= j; k++) str5[l++] = slide[k];
  389.             str5[l] = 0, k = 0;
  390.             strcat(str5, str3), len = strlen(str3);
  391.             for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  392.             str6[k] = 0;
  393.             if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  394.             {
  395.                 if (flag2 == 1)
  396.                 {
  397.                     gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  398.                     img = gtk_image_new_from_file(str5);
  399.                     gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  400.                     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  401.                     pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  402.                     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  403.                     windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  404.                     gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  405.                     gtk_widget_show(img);
  406.                     strcpy(slide, str5);
  407.                     flag3 = 1;
  408.                     break;
  409.  
  410.                 }
  411.                 if (strcmp(str5, slide) == 0) flag2 = 1;
  412.             }
  413.         }
  414.         if (flag3 == 1) break;
  415.     }
  416. }
  417.  
  418. void goto_first()
  419. {
  420.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  421.     for (i = 0; i < global; i++)
  422.     {
  423.         strcpy(str3, image_list[i]);
  424.         l = 0, len = strlen(slide);
  425.         str5[0] = 0;
  426.         for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  427.         for (k = 0; k <= j; k++) str5[l++] = slide[k];
  428.         str5[l] = 0, k = 0;
  429.         strcat(str5, str3), len = strlen(str3);
  430.         for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  431.         str6[k] = 0;
  432.         if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  433.         {
  434.             gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  435.             img = gtk_image_new_from_file(str5);
  436.             gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  437.             GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  438.             pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  439.             gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  440.             windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  441.             gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  442.             gtk_widget_show(img);
  443.             strcpy(slide, str5);
  444.             flag3 = 1;
  445.             break;
  446.         }
  447.     }
  448. }
  449.  
  450. void goto_last()
  451. {
  452.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  453.     for (i = global - 1; i >= 0; i--)
  454.     {
  455.         strcpy(str3, image_list[i]);
  456.         l = 0, len = strlen(slide);
  457.         str5[0] = 0;
  458.         for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  459.         for (k = 0; k <= j; k++) str5[l++] = slide[k];
  460.         str5[l] = 0, k = 0;
  461.         strcat(str5, str3), len = strlen(str3);
  462.         for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  463.         str6[k] = 0;
  464.         if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  465.         {
  466.             gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  467.             img = gtk_image_new_from_file(str5);
  468.             gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  469.             GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  470.             pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  471.             gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  472.             windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  473.             gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  474.             gtk_widget_show(img);
  475.             strcpy(slide, str5);
  476.             flag3 = 1;
  477.             break;
  478.         }
  479.     }
  480. }
  481.  
  482. void goodbye_dialog()
  483. {
  484.     gbdialog = gtk_message_dialog_new (GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Thank you for using this application!\nPlease click below to exit.");
  485.     gtk_window_set_position (GTK_WINDOW (gbdialog), GTK_WIN_POS_CENTER);
  486.     gtk_dialog_run (GTK_DIALOG (gbdialog));
  487.     gtk_widget_destroy (gbdialog);
  488.     gtk_main_quit();
  489. }
  490.  
  491. int main(int argc, char *argv[])
  492. {
  493.     gtk_init(&argc, &argv);
  494.     width = gdk_screen_width();
  495.     height = gdk_screen_height();
  496.     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  497.     gtk_window_set_skip_taskbar_hint (window, TRUE);
  498.     gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
  499.     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
  500.     gtk_widget_set_size_request(GTK_WIDGET(window), width, height);
  501.     gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  502.     heightini = height;
  503.     height = (height * 16) / 17;
  504.     zoom_width = width, zoom_height = height;
  505.  
  506.     fixed_layout = gtk_fixed_new();
  507.     char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg";
  508.     img = gtk_image_new_from_file(picturename);
  509.     windowicon = gdk_pixbuf_new_from_file(picturename, NULL);
  510.     gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  511.     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  512.     pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  513.     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  514.     strcpy(slide, picturename);
  515.     gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  516.     create_toolbar();
  517.     gtk_container_add(GTK_CONTAINER(window), fixed_layout);
  518.     get_list(picturename);
  519.     store_list();
  520.     system(str2);
  521.  
  522.     gtk_window_fullscreen(window);
  523.     g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
  524.     g_signal_connect(G_OBJECT(openbutton), "clicked", G_CALLBACK(open_file), NULL);
  525.     g_signal_connect(G_OBJECT(gotofirstbutton), "clicked", G_CALLBACK(goto_first), NULL);
  526.     g_signal_connect(G_OBJECT(gotolastbutton), "clicked", G_CALLBACK(goto_last), NULL);
  527.     g_signal_connect(G_OBJECT(aboutbutton), "clicked", G_CALLBACK(show_about), NULL);
  528.     g_signal_connect(G_OBJECT(closebutton), "clicked",G_CALLBACK(goodbye_dialog), NULL);
  529.     g_signal_connect(G_OBJECT(playbutton), "clicked",G_CALLBACK(start_slide), NULL);
  530.     g_signal_connect(G_OBJECT(stopbutton), "clicked",G_CALLBACK(stop_slide), NULL);
  531.     g_signal_connect(G_OBJECT(nextbutton), "clicked",G_CALLBACK(show_next2), NULL);
  532.     g_signal_connect(G_OBJECT(previousbutton), "clicked",G_CALLBACK(show_previous), NULL);
  533.     g_signal_connect(G_OBJECT(zoom_in_button), "clicked",G_CALLBACK(zoom_in), NULL);
  534.     g_signal_connect(G_OBJECT(zoom_out_button), "clicked",G_CALLBACK(zoom_out), NULL);
  535.     g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
  536.     gtk_widget_show_all(GTK_WIDGET(window));
  537.     gtk_widget_hide(GTK_WIDGET(stopbutton));
  538.     gtk_main();
  539.  
  540.     return 0x0;
  541. }
  542.  
  543.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement