Advertisement
palmerstone

Gtk 14

Nov 28th, 2011
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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, image_flag = 0, image_flag2 = 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. gint offset;
  18. GtkWindow *window;
  19. GdkPixbuf *windowicon, *mypic, *result_pixbuf;
  20. GtkWidget *fixed_layout, *img, *img2, *dialog, *gbdialog, *grayscale, *brightness, *contrast, *negative;
  21. GtkButton *openbutton, *closebutton, *nextbutton, *previousbutton, *playbutton, *aboutbutton, *gotofirstbutton, *gotolastbutton, *zoom_in_button, *zoom_out_button, *stopbutton, *negativebutton, *greyscalebutton, *contrastbutton, *brightnessbutton, *restorebutton1, *restorebutton2;
  22. GtkTooltips *opentooltip, *closetooltip, *nexttooltip, *previoustooltip, *playtooltip, *abouttooltip, *gotofirsttooltip, *gotolasttooltip, *zoom_in_tooltip, *zoom_out_tooltip, *stoptooltip, *negativetooltip, *greyscaletooltip, *contrasttooltip, *brightnesstooltip, *restoretooltip1, *restoretooltip2;
  23.  
  24. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data);
  25. void create_menu();
  26. void create_toolbar();
  27. void show_about();
  28. void open_file();
  29. void start_slide();
  30. void stop_slide();
  31. void get_list(char filename[500]);
  32. void store_list();
  33. gboolean show_next(gpointer userdata);
  34. void show_next2();
  35. void show_previous();
  36. void goto_first();
  37. void goto_last();
  38. void image_negative();
  39. void image_greyscale();
  40. void show_original1();
  41. void show_original2();
  42. void zoom_in();
  43. void zoom_out();
  44. void goodbye_dialog();
  45.  
  46. void create_toolbar()
  47. {
  48.     total = (7 * 30) + (10 * 6);
  49.     ini = (width - total) / 2;
  50.  
  51.     openbutton = gtk_button_new();
  52.     opentooltip = gtk_tooltips_new();
  53.     gtk_widget_set_size_request(GTK_WIDGET(openbutton), square_size, square_size);
  54.     gtk_button_set_image (GTK_BUTTON(openbutton),gtk_image_new_from_stock(GTK_STOCK_ORIENTATION_PORTRAIT, GTK_ICON_SIZE_BUTTON));
  55.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(openbutton), ini, heightini - 40);
  56.     gtk_tooltips_set_tip(opentooltip, GTK_WIDGET(openbutton), "Open   (Ctrl+O)", "Open   (Ctrl+O)");
  57.  
  58.     ini += 40;
  59.     gotofirstbutton = gtk_button_new();
  60.     gotofirsttooltip = gtk_tooltips_new();
  61.     gtk_widget_set_size_request(GTK_WIDGET(gotofirstbutton), square_size, square_size);
  62.     gtk_button_set_image (GTK_BUTTON(gotofirstbutton),gtk_image_new_from_stock(GTK_STOCK_GOTO_FIRST, GTK_ICON_SIZE_BUTTON));
  63.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(gotofirstbutton), ini, heightini - 40);
  64.     gtk_tooltips_set_tip(gotofirsttooltip, GTK_WIDGET(gotofirstbutton), "Go to first image   (Page Up)", "Go to first image   (Page Up)");
  65.  
  66.     ini += 40;
  67.     previousbutton = gtk_button_new();
  68.     previoustooltip = gtk_tooltips_new();
  69.     gtk_widget_set_size_request(GTK_WIDGET(previousbutton), square_size, square_size);
  70.     gtk_button_set_image (GTK_BUTTON(previousbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PREVIOUS, GTK_ICON_SIZE_BUTTON));
  71.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(previousbutton), ini, heightini - 40);
  72.     gtk_tooltips_set_tip(previoustooltip, GTK_WIDGET(previousbutton), "Show Previous   (Left key)", "Show Previous   (Left key)");
  73.  
  74.     ini += 40;
  75.     playbutton = gtk_button_new();
  76.     playtooltip = gtk_tooltips_new();
  77.     gtk_widget_set_size_request(GTK_WIDGET(playbutton), square_size, square_size);
  78.     gtk_button_set_image (GTK_BUTTON(playbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_BUTTON));
  79.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(playbutton), ini, heightini - 40);
  80.     gtk_tooltips_set_tip(playtooltip, GTK_WIDGET(playbutton), "Start Slideshow   (Spacebar)", "Start Slideshow   (Spacebar)");
  81.  
  82.     stopbutton = gtk_button_new();
  83.     stoptooltip = gtk_tooltips_new();
  84.     gtk_widget_set_size_request(GTK_WIDGET(stopbutton), square_size, square_size);
  85.     gtk_button_set_image (GTK_BUTTON(stopbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_BUTTON));
  86.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(stopbutton), ini, heightini - 40);
  87.     gtk_tooltips_set_tip(stoptooltip, GTK_WIDGET(stopbutton), "Stop Slideshow   (Spacebar)", "Stop Slideshow   (Spacebar)");
  88.  
  89.     ini += 40;
  90.     nextbutton = gtk_button_new();
  91.     nexttooltip = gtk_tooltips_new();
  92.     gtk_widget_set_size_request(GTK_WIDGET(nextbutton), square_size, square_size);
  93.     gtk_button_set_image (GTK_BUTTON(nextbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_NEXT, GTK_ICON_SIZE_BUTTON));
  94.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(nextbutton), ini, heightini - 40);
  95.     gtk_tooltips_set_tip(nexttooltip, GTK_WIDGET(nextbutton), "Show Next   (Right Key)", "Show Next   (Right Key)");
  96.  
  97.     ini += 40;
  98.     gotolastbutton = gtk_button_new();
  99.     gotolasttooltip = gtk_tooltips_new();
  100.     gtk_widget_set_size_request(GTK_WIDGET(gotolastbutton), square_size, square_size);
  101.     gtk_button_set_image (GTK_BUTTON(gotolastbutton),gtk_image_new_from_stock(GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON));
  102.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(gotolastbutton), ini, heightini - 40);
  103.     gtk_tooltips_set_tip(gotolasttooltip, GTK_WIDGET(gotolastbutton), "Go to last image   (Page Down)", "Go to last image   (Page Down)");
  104.  
  105.     ini += 40;
  106.     aboutbutton = gtk_button_new();
  107.     abouttooltip = gtk_tooltips_new();
  108.     gtk_widget_set_size_request(GTK_WIDGET(aboutbutton), square_size, square_size);
  109.     gtk_button_set_image (GTK_BUTTON(aboutbutton),gtk_image_new_from_stock(GTK_STOCK_INFO, GTK_ICON_SIZE_BUTTON));
  110.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(aboutbutton), ini, heightini - 40);
  111.     gtk_tooltips_set_tip(abouttooltip, GTK_WIDGET(aboutbutton), "About Us :)", "About Us :)");
  112.  
  113.     ini = width - 40;
  114.     closebutton = gtk_button_new();
  115.     closetooltip = gtk_tooltips_new();
  116.     gtk_widget_set_size_request(GTK_WIDGET(closebutton), square_size, square_size);
  117.     gtk_button_set_image (GTK_BUTTON(closebutton),gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON));
  118.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(closebutton), ini, heightini - 40);
  119.     gtk_tooltips_set_tip(closetooltip, GTK_WIDGET(closebutton), "Close :(   (Ctrl+Q)", "Close :(   (Ctrl+Q)");
  120.  
  121.     ini = 10;
  122.     zoom_out_button = gtk_button_new();
  123.     zoom_out_tooltip = gtk_tooltips_new();
  124.     gtk_widget_set_size_request(GTK_WIDGET(zoom_out_button), square_size, square_size);
  125.     gtk_button_set_image (GTK_BUTTON(zoom_out_button),gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_BUTTON));
  126.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(zoom_out_button), ini, heightini - 40);
  127.     gtk_tooltips_set_tip(zoom_out_tooltip, GTK_WIDGET(zoom_out_button), "Zoom Out   (-)", "Zoom Out   (-)");
  128.  
  129.     ini += 40;
  130.     zoom_in_button = gtk_button_new();
  131.     zoom_in_tooltip = gtk_tooltips_new();
  132.     gtk_widget_set_size_request(GTK_WIDGET(zoom_in_button), square_size, square_size);
  133.     gtk_button_set_image (GTK_BUTTON(zoom_in_button),gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_BUTTON));
  134.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(zoom_in_button), ini, heightini - 40);
  135.     gtk_tooltips_set_tip(zoom_in_tooltip, GTK_WIDGET(zoom_in_button), "Zoom In   (+)", "Zoom In   (+)");
  136.  
  137.     ini += 40;
  138.     negativebutton = gtk_button_new();
  139.     negativetooltip = gtk_tooltips_new();
  140.     gtk_widget_set_size_request(GTK_WIDGET(negativebutton), square_size, square_size);
  141.     gtk_button_set_image (GTK_BUTTON(negativebutton),gtk_image_new_from_stock(GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_BUTTON));
  142.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(negativebutton), ini, heightini - 40);
  143.     gtk_tooltips_set_tip(negativetooltip, GTK_WIDGET(negativebutton), "Show Negative", "Show Negative");
  144.  
  145.     restorebutton1 = gtk_button_new();
  146.     restoretooltip1 = gtk_tooltips_new();
  147.     gtk_widget_set_size_request(GTK_WIDGET(restorebutton1), square_size, square_size);
  148.     gtk_button_set_image (GTK_BUTTON(restorebutton1),gtk_image_new_from_stock(GTK_STOCK_REDO, GTK_ICON_SIZE_BUTTON));
  149.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(restorebutton1), ini, heightini - 40);
  150.     gtk_tooltips_set_tip(restoretooltip1, GTK_WIDGET(restorebutton1), "Show Original", "Show Original");
  151.  
  152.     ini += 40;
  153.     greyscalebutton = gtk_button_new();
  154.     greyscaletooltip = gtk_tooltips_new();
  155.     gtk_widget_set_size_request(GTK_WIDGET(greyscalebutton), square_size, square_size);
  156.     gtk_button_set_image (GTK_BUTTON(greyscalebutton),gtk_image_new_from_stock(GTK_STOCK_CAPS_LOCK_WARNING, GTK_ICON_SIZE_BUTTON));
  157.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(greyscalebutton), ini, heightini - 40);
  158.     gtk_tooltips_set_tip(greyscaletooltip, GTK_WIDGET(greyscalebutton), "Show Greyscale Image", "Show Greyscale Image");
  159.  
  160.     restorebutton2 = gtk_button_new();
  161.     restoretooltip2 = gtk_tooltips_new();
  162.     gtk_widget_set_size_request(GTK_WIDGET(restorebutton2), square_size, square_size);
  163.     gtk_button_set_image (GTK_BUTTON(restorebutton2),gtk_image_new_from_stock(GTK_STOCK_REDO, GTK_ICON_SIZE_BUTTON));
  164.     gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(restorebutton2), ini, heightini - 40);
  165.     gtk_tooltips_set_tip(restoretooltip2, GTK_WIDGET(restorebutton2), "Show Original", "Show Original");
  166. }
  167.  
  168. void show_about()
  169. {
  170.     GtkWidget *dialog;
  171.     const char copyright[] = "Copyright @ Fireflight TM, 2011. All rights reserved.";
  172.     const char *author[] = {"Scape", "mr.rana", "(And special thanks to Mehedi Hasan and Shadman Shadab)", "", "Contact information: sgtlaugh@gmail.com",NULL};
  173.     dialog = gtk_about_dialog_new();
  174.     gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"Firedlight Image Viewer v1.052 (beta)");
  175.     gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
  176.     gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), copyright);
  177.     gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"A free image viewer :)");
  178.     windowicon = gdk_pixbuf_new_from_file(slide, NULL);
  179.     gtk_window_set_icon(GTK_WINDOW(dialog), windowicon);
  180.     gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS);
  181.     gtk_dialog_run(GTK_DIALOG(dialog));
  182.     gtk_widget_destroy(dialog);
  183. }
  184.  
  185. void open_file()
  186. {
  187.     char *filename;
  188.     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);
  189.     if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  190.     {
  191.         image_flag = 0, image_flag2 = 0;
  192.         filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  193.         strcpy(slide, filename);
  194.         get_list(filename);
  195.         store_list();
  196.         system(str2);
  197.         zoom_width = width, zoom_height = height;
  198.         img = gtk_image_new_from_file(filename);
  199.         img2 = gtk_image_new_from_file(filename);
  200.         mypic = gdk_pixbuf_new_from_file(filename, NULL);
  201.         windowicon = gdk_pixbuf_new_from_file(filename, NULL);
  202.         gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  203.         GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  204.         pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  205.         gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  206.         gtk_widget_show(img);
  207.         gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  208.         g_free (filename);
  209.     }
  210.     gtk_widget_destroy (dialog);
  211. }
  212.  
  213. void zoom_in()
  214. {
  215.     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  216.     double x = zoom_width;
  217.     double y = zoom_height;
  218.     x = x * ratio, y = y * ratio;
  219.     zoom_width = x, zoom_height = y;
  220.     pixbuf = gdk_pixbuf_scale_simple(pixbuf, zoom_width, zoom_height, GDK_INTERP_NEAREST);
  221.     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  222. }
  223.  
  224. void image_greyscale()
  225. {
  226.     image_flag = 0;
  227.     GtkWidget *img;
  228.     gtk_widget_hide(GTK_WIDGET(greyscalebutton));
  229.     gtk_widget_show(GTK_WIDGET(restorebutton2));
  230.  
  231.     if (image_flag2 == 0)
  232.     {
  233.         char *sp, *dp;
  234.         int localwidth, localheight, line, result_rowstride, mypic_rowstride, bytes_per_pixel;
  235.  
  236.         result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (mypic),
  237.                                         gdk_pixbuf_get_has_alpha (mypic),
  238.                                         gdk_pixbuf_get_bits_per_sample (mypic),
  239.                                         gdk_pixbuf_get_width (mypic),
  240.                                         gdk_pixbuf_get_height (mypic));
  241.  
  242.         localwidth = gdk_pixbuf_get_width (result_pixbuf);
  243.         localheight = gdk_pixbuf_get_height (result_pixbuf);
  244.         result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
  245.         mypic_rowstride = gdk_pixbuf_get_rowstride (mypic);
  246.         bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;
  247.  
  248.         sp = gdk_pixbuf_get_pixels (mypic);
  249.         dp = gdk_pixbuf_get_pixels (result_pixbuf);
  250.         for (line = 0; line < localheight; line ++)
  251.         {
  252.             char *sq = sp;
  253.             char *dq = dp;
  254.             int i;
  255.  
  256.             for (i = 0; i < localwidth; i ++)
  257.             {
  258.                 dq[0] = (sq[0] + sq[1] + sq[2]) / 10;
  259.                 dq[1] = dq[0];
  260.                 dq[2] = dq[0];
  261.  
  262.                 dq += bytes_per_pixel;
  263.                 sq += bytes_per_pixel;
  264.             }
  265.  
  266.             sp += mypic_rowstride;
  267.             dp += result_rowstride;
  268.         }
  269.     }
  270.     img = gtk_image_new();
  271.     result_pixbuf = gdk_pixbuf_scale_simple(result_pixbuf, width, height, GDK_INTERP_NEAREST);
  272.     gtk_image_set_from_pixbuf(GTK_IMAGE(img), result_pixbuf);
  273.     gtk_widget_show(img);
  274.     gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  275.     image_flag2 = 1;
  276. }
  277.  
  278. void show_original2()
  279. {
  280.     GtkWidget *img3;
  281.     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img2));
  282.     pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  283.     img3 = gtk_image_new();
  284.     gtk_image_set_from_pixbuf(GTK_IMAGE(img3), pixbuf);
  285.     gtk_widget_show(img3);
  286.     gtk_container_add(GTK_CONTAINER(fixed_layout), img3);
  287.     gtk_widget_hide(GTK_WIDGET(restorebutton2));
  288.     gtk_widget_show(GTK_WIDGET(greyscalebutton));
  289. }
  290.  
  291. void image_negative()
  292. {
  293.     image_flag2 = 0;
  294.     GtkWidget *img;
  295.     gtk_widget_hide(GTK_WIDGET(negativebutton));
  296.     gtk_widget_show(GTK_WIDGET(restorebutton1));
  297.  
  298.     if (image_flag == 0)
  299.     {
  300.         char *sp, *dp;
  301.         int localwidth, localheight, line, result_rowstride, mypic_rowstride, bytes_per_pixel;
  302.  
  303.         result_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (mypic),
  304.                                         gdk_pixbuf_get_has_alpha (mypic),
  305.                                         gdk_pixbuf_get_bits_per_sample (mypic),
  306.                                         gdk_pixbuf_get_width (mypic),
  307.                                         gdk_pixbuf_get_height (mypic));
  308.  
  309.         localwidth = gdk_pixbuf_get_width (result_pixbuf);
  310.         localheight = gdk_pixbuf_get_height (result_pixbuf);
  311.         result_rowstride = gdk_pixbuf_get_rowstride (result_pixbuf);
  312.         mypic_rowstride = gdk_pixbuf_get_rowstride (mypic);
  313.         bytes_per_pixel = gdk_pixbuf_get_has_alpha (result_pixbuf) ? 4 : 3;
  314.  
  315.         sp = gdk_pixbuf_get_pixels (mypic);
  316.         dp = gdk_pixbuf_get_pixels (result_pixbuf);
  317.  
  318.         for (line = 0; line < localheight; line++)
  319.         {
  320.             char *sq = sp;
  321.             char *dq = dp;
  322.             int i;
  323.  
  324.             for (i = 0; i < localwidth; i++)
  325.             {
  326.                 dq[0] = 255 - sq[0];
  327.                 dq[1] = 255 - sq[1];
  328.                 dq[2] = 255 - sq[2];
  329.  
  330.                 dq += bytes_per_pixel;
  331.                 sq += bytes_per_pixel;
  332.             }
  333.  
  334.             sp += mypic_rowstride;
  335.             dp += result_rowstride;
  336.         }
  337.     }
  338.     img = gtk_image_new();
  339.     result_pixbuf = gdk_pixbuf_scale_simple(result_pixbuf, width, height, GDK_INTERP_NEAREST);
  340.     gtk_image_set_from_pixbuf(GTK_IMAGE(img), result_pixbuf);
  341.     gtk_widget_show(img);
  342.     gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  343.     image_flag = 1;
  344. }
  345.  
  346. void show_original1()
  347. {
  348.     GtkWidget *img3;
  349.     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img2));
  350.     pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  351.     img3 = gtk_image_new();
  352.     gtk_image_set_from_pixbuf(GTK_IMAGE(img3), pixbuf);
  353.     gtk_widget_show(img3);
  354.     gtk_container_add(GTK_CONTAINER(fixed_layout), img3);
  355.     gtk_widget_hide(GTK_WIDGET(restorebutton1));
  356.     gtk_widget_show(GTK_WIDGET(negativebutton));
  357. }
  358.  
  359. void zoom_out()
  360. {
  361.     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  362.     double x = zoom_width;
  363.     double y = zoom_height;
  364.     double d = (double) 1 / ratio;
  365.     x = x * d, y = y * d;
  366.     zoom_width = x, zoom_height = y;
  367.     pixbuf = gdk_pixbuf_scale_simple(pixbuf, zoom_width, zoom_height, GDK_INTERP_NEAREST);
  368.     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  369. }
  370.  
  371. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data)
  372. {
  373.     if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_q || lol->keyval == GDK_KEY_Q))
  374.         goodbye_dialog();
  375.     if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_O || lol->keyval == GDK_KEY_o))
  376.         open_file();
  377.     if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_N || lol->keyval == GDK_KEY_n))
  378.         image_negative();
  379.     if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_G || lol->keyval == GDK_KEY_g))
  380.         image_greyscale();
  381.     if (lol->keyval == GDK_KEY_Right)
  382.         show_next2();
  383.     if (lol->keyval == GDK_KEY_Left)
  384.         show_previous();
  385.     if (lol->keyval == GDK_KEY_space)
  386.     {
  387.         if (flag == 0) flag = 1;
  388.         else flag = 0;
  389.         if (flag == 1) start_slide();
  390.         else stop_slide();
  391.     }
  392.     if (lol->keyval == GDK_KEY_Page_Up)
  393.         goto_first();
  394.     if (lol->keyval == GDK_KEY_Page_Down)
  395.         goto_last();
  396.     if (lol->keyval == GDK_KEY_plus)
  397.         zoom_in();
  398.     if (lol->keyval == GDK_KEY_minus)
  399.         zoom_out();
  400.     return TRUE;
  401. }
  402.  
  403.  
  404. void start_slide()
  405. {
  406.     flag = 1;
  407.     gint func_ref = g_timeout_add(3000, show_next, (gpointer)32);
  408.     gtk_widget_hide(GTK_WIDGET(playbutton));
  409.     gtk_widget_hide(GTK_WIDGET(openbutton));
  410.     gtk_widget_hide(GTK_WIDGET(closebutton));
  411.     gtk_widget_hide(GTK_WIDGET(zoom_in_button));
  412.     gtk_widget_hide(GTK_WIDGET(zoom_out_button));
  413.     gtk_widget_hide(GTK_WIDGET(gotofirstbutton));
  414.     gtk_widget_hide(GTK_WIDGET(gotolastbutton));
  415.     gtk_widget_hide(GTK_WIDGET(nextbutton));
  416.     gtk_widget_hide(GTK_WIDGET(previousbutton));
  417.     gtk_widget_hide(GTK_WIDGET(aboutbutton));
  418.     gtk_widget_hide(GTK_WIDGET(negativebutton));
  419.     gtk_widget_hide(GTK_WIDGET(restorebutton1));
  420.     gtk_widget_hide(GTK_WIDGET(restorebutton2));
  421.     gtk_widget_hide(GTK_WIDGET(greyscalebutton));
  422.     gtk_widget_show(GTK_WIDGET(stopbutton));
  423.  
  424. }
  425.  
  426. void stop_slide()
  427. {
  428.     flag = 0;
  429.     gint func_ref = g_timeout_add(10000000, show_next, (gpointer)32);
  430.     gtk_widget_hide(GTK_WIDGET(stopbutton));
  431.     gtk_widget_show(GTK_WIDGET(playbutton));
  432.     gtk_widget_show(GTK_WIDGET(openbutton));
  433.     gtk_widget_show(GTK_WIDGET(closebutton));
  434.     gtk_widget_show(GTK_WIDGET(zoom_in_button));
  435.     gtk_widget_show(GTK_WIDGET(zoom_out_button));
  436.     gtk_widget_show(GTK_WIDGET(gotofirstbutton));
  437.     gtk_widget_show(GTK_WIDGET(gotolastbutton));
  438.     gtk_widget_show(GTK_WIDGET(nextbutton));
  439.     gtk_widget_show(GTK_WIDGET(previousbutton));
  440.     gtk_widget_show(GTK_WIDGET(negativebutton));
  441.     gtk_widget_show(GTK_WIDGET(greyscalebutton));
  442.     gtk_widget_show(GTK_WIDGET(aboutbutton));
  443. }
  444.  
  445. void get_list(char filename[500])
  446. {
  447.     int k = 0, j, l = 0, x;
  448.     int len = strlen(filename);
  449.     for (j = len - 1; filename[j] != '\\'; j--) x = 1;
  450.     str[0] = 0;
  451.     strcat(str, "cd /d ");
  452.     for (k = 0; k < j; k++) str4[l++] = filename[k];
  453.     str4[l] = 0;
  454.     str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
  455.     system(str3);
  456.     strcat(str, str4);
  457.     strcpy(str2, str);
  458.     strcat(str, " && dir /b >> dir_listing.txt");
  459.     strcat(str2, " && del dir_listing.txt");
  460.     system(str);
  461.     strcat(str4, "\\dir_listing.txt");
  462. }
  463.  
  464. void store_list()
  465. {
  466.     FILE *input;
  467.     input = fopen(str4, "r");
  468.     for (global = 0; ;global++)
  469.     {
  470.         if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
  471.         fgetc(input);
  472.     }
  473.     fclose(input);
  474. }
  475.  
  476. gboolean show_next(gpointer userdata)
  477. {
  478.     if (flag == 0) return FALSE;
  479.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  480.     for (; ;)
  481.     {
  482.         for (i = 0; i < global; i++)
  483.         {
  484.             strcpy(str3, image_list[i]);
  485.             l = 0, len = strlen(slide);
  486.             str5[0] = 0;
  487.             for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  488.             for (k = 0; k <= j; k++) str5[l++] = slide[k];
  489.             str5[l] = 0, k = 0;
  490.             strcat(str5, str3), len = strlen(str3);
  491.             for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  492.             str6[k] = 0;
  493.             if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  494.             {
  495.                 if (flag2 == 1)
  496.                 {
  497.                     image_flag = 0, image_flag2 = 0;;
  498.                     zoom_width = width, zoom_height = height;
  499.                     img = gtk_image_new_from_file(str5);
  500.                     img2 = gtk_image_new_from_file(str5);
  501.                     mypic = gdk_pixbuf_new_from_file(str5, NULL);
  502.                     gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  503.                     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  504.                     pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  505.                     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  506.                     windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  507.                     gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  508.                     gtk_widget_show(img);
  509.                     strcpy(slide, str5);
  510.                     flag3 = 1;
  511.                     break;
  512.  
  513.                 }
  514.                 if (strcmp(str5, slide) == 0) flag2 = 1;
  515.             }
  516.         }
  517.         if (flag3 == 1) break;
  518.     }
  519.     return TRUE;
  520. }
  521.  
  522. void show_next2()
  523. {
  524.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  525.     for (; ;)
  526.     {
  527.         for (i = 0; i < global; i++)
  528.         {
  529.             strcpy(str3, image_list[i]);
  530.             l = 0, len = strlen(slide);
  531.             str5[0] = 0;
  532.             for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  533.             for (k = 0; k <= j; k++) str5[l++] = slide[k];
  534.             str5[l] = 0, k = 0;
  535.             strcat(str5, str3), len = strlen(str3);
  536.             for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  537.             str6[k] = 0;
  538.             if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  539.             {
  540.                 if (flag2 == 1)
  541.                 {
  542.                     image_flag = 0, image_flag2 = 0;;
  543.                     zoom_width = width, zoom_height = height;
  544.                     img = gtk_image_new_from_file(str5);
  545.                     img2 = gtk_image_new_from_file(str5);
  546.                     mypic = gdk_pixbuf_new_from_file(str5, NULL);
  547.                     gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  548.                     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  549.                     pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  550.                     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  551.                     windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  552.                     gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  553.                     gtk_widget_show(img);
  554.                     strcpy(slide, str5);
  555.                     flag3 = 1;
  556.                     break;
  557.  
  558.                 }
  559.                 if (strcmp(str5, slide) == 0) flag2 = 1;
  560.             }
  561.         }
  562.         if (flag3 == 1) break;
  563.     }
  564. }
  565.  
  566. void show_previous()
  567. {
  568.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  569.     for (; ;)
  570.     {
  571.         for (i = global - 1; i >= 0; i--)
  572.         {
  573.             strcpy(str3, image_list[i]);
  574.             l = 0, len = strlen(slide);
  575.             str5[0] = 0;
  576.             for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  577.             for (k = 0; k <= j; k++) str5[l++] = slide[k];
  578.             str5[l] = 0, k = 0;
  579.             strcat(str5, str3), len = strlen(str3);
  580.             for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  581.             str6[k] = 0;
  582.             if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  583.             {
  584.                 if (flag2 == 1)
  585.                 {
  586.                     image_flag = 0, image_flag2 = 0;;
  587.                     zoom_width = width, zoom_height = height;
  588.                     img = gtk_image_new_from_file(str5);
  589.                     img2 = gtk_image_new_from_file(str5);
  590.                     mypic = gdk_pixbuf_new_from_file(str5, NULL);
  591.                     gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  592.                     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  593.                     pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  594.                     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  595.                     windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  596.                     gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  597.                     gtk_widget_show(img);
  598.                     strcpy(slide, str5);
  599.                     flag3 = 1;
  600.                     break;
  601.  
  602.                 }
  603.                 if (strcmp(str5, slide) == 0) flag2 = 1;
  604.             }
  605.         }
  606.         if (flag3 == 1) break;
  607.     }
  608. }
  609.  
  610. void goto_first()
  611. {
  612.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  613.     for (i = 0; i < global; i++)
  614.     {
  615.         strcpy(str3, image_list[i]);
  616.         l = 0, len = strlen(slide);
  617.         str5[0] = 0;
  618.         for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  619.         for (k = 0; k <= j; k++) str5[l++] = slide[k];
  620.         str5[l] = 0, k = 0;
  621.         strcat(str5, str3), len = strlen(str3);
  622.         for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  623.         str6[k] = 0;
  624.         if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  625.         {
  626.             image_flag = 0, image_flag2 = 0;;
  627.             zoom_width = width, zoom_height = height;
  628.             img = gtk_image_new_from_file(str5);
  629.             img2 = gtk_image_new_from_file(str5);
  630.             mypic = gdk_pixbuf_new_from_file(str5, NULL);
  631.             gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  632.             GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  633.             pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  634.             gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  635.             windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  636.             gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  637.             gtk_widget_show(img);
  638.             strcpy(slide, str5);
  639.             flag3 = 1;
  640.             break;
  641.         }
  642.     }
  643. }
  644.  
  645. void goto_last()
  646. {
  647.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  648.     for (i = global - 1; i >= 0; i--)
  649.     {
  650.         strcpy(str3, image_list[i]);
  651.         l = 0, len = strlen(slide);
  652.         str5[0] = 0;
  653.         for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  654.         for (k = 0; k <= j; k++) str5[l++] = slide[k];
  655.         str5[l] = 0, k = 0;
  656.         strcat(str5, str3), len = strlen(str3);
  657.         for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  658.         str6[k] = 0;
  659.         if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  660.         {
  661.             image_flag = 0, image_flag2 = 0;;
  662.             zoom_width = width, zoom_height = height;
  663.             img = gtk_image_new_from_file(str5);
  664.             img2 = gtk_image_new_from_file(str5);
  665.             mypic = gdk_pixbuf_new_from_file(str5, NULL);
  666.             gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  667.             GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  668.             pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  669.             gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  670.             windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  671.             gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  672.             gtk_widget_show(img);
  673.             strcpy(slide, str5);
  674.             flag3 = 1;
  675.             break;
  676.         }
  677.     }
  678. }
  679.  
  680. void goodbye_dialog()
  681. {
  682.     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 Ok to exit.");
  683.     gtk_window_set_position (GTK_WINDOW (gbdialog), GTK_WIN_POS_CENTER);
  684.     gtk_dialog_run (GTK_DIALOG (gbdialog));
  685.     gtk_widget_destroy (gbdialog);
  686.     gtk_main_quit();
  687. }
  688.  
  689. int main(int argc, char *argv[])
  690. {
  691.     gtk_init(&argc, &argv);
  692.     width = gdk_screen_width();
  693.     height = gdk_screen_height();
  694.     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  695.     gtk_window_set_skip_taskbar_hint (window, TRUE);
  696.     gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
  697.     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
  698.     gtk_widget_set_size_request(GTK_WIDGET(window), width, height);
  699.     gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  700.     heightini = height;
  701.     height = (height * 16) / 17;
  702.     zoom_width = width, zoom_height = height;
  703.  
  704.     fixed_layout = gtk_fixed_new();
  705.     char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg";
  706.     img = gtk_image_new_from_file(picturename);
  707.     img2 = gtk_image_new_from_file(picturename);
  708.     mypic = gdk_pixbuf_new_from_file(picturename, NULL);
  709.     windowicon = gdk_pixbuf_new_from_file(picturename, NULL);
  710.     gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  711.     GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  712.     pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_NEAREST);
  713.     gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  714.     strcpy(slide, picturename);
  715.     gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  716.     create_toolbar();
  717.     gtk_container_add(GTK_CONTAINER(window), fixed_layout);
  718.     get_list(picturename);
  719.     store_list();
  720.     system(str2);
  721.  
  722.     gtk_window_fullscreen(window);
  723.     g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
  724.     g_signal_connect(G_OBJECT(openbutton), "clicked", G_CALLBACK(open_file), NULL);
  725.     g_signal_connect(G_OBJECT(gotofirstbutton), "clicked", G_CALLBACK(goto_first), NULL);
  726.     g_signal_connect(G_OBJECT(gotolastbutton), "clicked", G_CALLBACK(goto_last), NULL);
  727.     g_signal_connect(G_OBJECT(aboutbutton), "clicked", G_CALLBACK(show_about), NULL);
  728.     g_signal_connect(G_OBJECT(closebutton), "clicked",G_CALLBACK(goodbye_dialog), NULL);
  729.     g_signal_connect(G_OBJECT(playbutton), "clicked",G_CALLBACK(start_slide), NULL);
  730.     g_signal_connect(G_OBJECT(stopbutton), "clicked",G_CALLBACK(stop_slide), NULL);
  731.     g_signal_connect(G_OBJECT(nextbutton), "clicked",G_CALLBACK(show_next2), NULL);
  732.     g_signal_connect(G_OBJECT(negativebutton), "clicked",G_CALLBACK(image_negative), NULL);
  733.     g_signal_connect(G_OBJECT(restorebutton1), "clicked",G_CALLBACK(show_original1), NULL);
  734.     g_signal_connect(G_OBJECT(restorebutton2), "clicked",G_CALLBACK(show_original2), NULL);
  735.     g_signal_connect(G_OBJECT(greyscalebutton), "clicked",G_CALLBACK(image_greyscale), NULL);
  736.     g_signal_connect(G_OBJECT(previousbutton), "clicked",G_CALLBACK(show_previous), NULL);
  737.     g_signal_connect(G_OBJECT(zoom_in_button), "clicked",G_CALLBACK(zoom_in), NULL);
  738.     g_signal_connect(G_OBJECT(zoom_out_button), "clicked",G_CALLBACK(zoom_out), NULL);
  739.     g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
  740.     gtk_widget_show_all(GTK_WIDGET(window));
  741.     gtk_widget_hide(GTK_WIDGET(stopbutton)), gtk_widget_hide(GTK_WIDGET(restorebutton1)), gtk_widget_hide(GTK_WIDGET(restorebutton2));
  742.     gtk_main();
  743.  
  744.     return 0x0;
  745. }
  746.  
  747.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement