Advertisement
palmerstone

Gtk 11

Nov 27th, 2011
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.86 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. start_slide();
  210. if (lol->keyval == GDK_KEY_Page_Up)
  211. goto_first();
  212. if (lol->keyval == GDK_KEY_Page_Down)
  213. goto_last();
  214. if (lol->keyval == GDK_KEY_plus)
  215. zoom_in();
  216. if (lol->keyval == GDK_KEY_minus)
  217. zoom_out();
  218. return TRUE;
  219. }
  220.  
  221.  
  222. void start_slide()
  223. {
  224. flag = 1;
  225. gint func_ref = g_timeout_add(3000, show_next, (gpointer)32);
  226. gtk_widget_hide(GTK_WIDGET(playbutton));
  227. gtk_widget_hide(GTK_WIDGET(openbutton));
  228. gtk_widget_hide(GTK_WIDGET(closebutton));
  229. gtk_widget_hide(GTK_WIDGET(zoom_in_button));
  230. gtk_widget_hide(GTK_WIDGET(zoom_out_button));
  231. gtk_widget_hide(GTK_WIDGET(gotofirstbutton));
  232. gtk_widget_hide(GTK_WIDGET(gotolastbutton));
  233. gtk_widget_hide(GTK_WIDGET(nextbutton));
  234. gtk_widget_hide(GTK_WIDGET(previousbutton));
  235. gtk_widget_hide(GTK_WIDGET(aboutbutton));
  236. gtk_widget_show(GTK_WIDGET(stopbutton));
  237.  
  238. }
  239.  
  240. void stop_slide()
  241. {
  242. flag = 0;
  243. gint func_ref = g_timeout_add(10000000, show_next, (gpointer)32);
  244. gtk_widget_hide(GTK_WIDGET(stopbutton));
  245. gtk_widget_show(GTK_WIDGET(playbutton));
  246. gtk_widget_show(GTK_WIDGET(openbutton));
  247. gtk_widget_show(GTK_WIDGET(closebutton));
  248. gtk_widget_show(GTK_WIDGET(zoom_in_button));
  249. gtk_widget_show(GTK_WIDGET(zoom_out_button));
  250. gtk_widget_show(GTK_WIDGET(gotofirstbutton));
  251. gtk_widget_show(GTK_WIDGET(gotolastbutton));
  252. gtk_widget_show(GTK_WIDGET(nextbutton));
  253. gtk_widget_show(GTK_WIDGET(previousbutton));
  254. gtk_widget_show(GTK_WIDGET(aboutbutton));
  255. }
  256.  
  257. void get_list(char filename[500])
  258. {
  259. int k = 0, j, l = 0, x;
  260. int len = strlen(filename);
  261. for (j = len - 1; filename[j] != '\\'; j--) x = 1;
  262. str[0] = 0;
  263. strcat(str, "cd /d ");
  264. for (k = 0; k < j; k++) str4[l++] = filename[k];
  265. str4[l] = 0;
  266. str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
  267. system(str3);
  268. strcat(str, str4);
  269. strcpy(str2, str);
  270. strcat(str, " && dir /b >> dir_listing.txt");
  271. strcat(str2, " && del dir_listing.txt");
  272. system(str);
  273. strcat(str4, "\\dir_listing.txt");
  274. }
  275.  
  276. void store_list()
  277. {
  278. FILE *input;
  279. input = fopen(str4, "r");
  280. for (global = 0; ;global++)
  281. {
  282. if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
  283. fgetc(input);
  284. }
  285. fclose(input);
  286. }
  287.  
  288. gboolean show_next(gpointer userdata)
  289. {
  290. if (flag == 0) return FALSE;
  291. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  292. for (; ;)
  293. {
  294. for (i = 0; i < global; i++)
  295. {
  296. strcpy(str3, image_list[i]);
  297. l = 0, len = strlen(slide);
  298. str5[0] = 0;
  299. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  300. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  301. str5[l] = 0, k = 0;
  302. strcat(str5, str3), len = strlen(str3);
  303. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  304. str6[k] = 0;
  305. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  306. {
  307. if (flag2 == 1)
  308. {
  309. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  310. img = gtk_image_new_from_file(str5);
  311. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  312. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  313. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  314. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  315. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  316. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  317. gtk_widget_show(img);
  318. strcpy(slide, str5);
  319. flag3 = 1;
  320. break;
  321.  
  322. }
  323. if (strcmp(str5, slide) == 0) flag2 = 1;
  324. }
  325. }
  326. if (flag3 == 1) break;
  327. }
  328. return TRUE;
  329. }
  330.  
  331. void show_next2()
  332. {
  333. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  334. for (; ;)
  335. {
  336. for (i = 0; i < global; i++)
  337. {
  338. strcpy(str3, image_list[i]);
  339. l = 0, len = strlen(slide);
  340. str5[0] = 0;
  341. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  342. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  343. str5[l] = 0, k = 0;
  344. strcat(str5, str3), len = strlen(str3);
  345. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  346. str6[k] = 0;
  347. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  348. {
  349. if (flag2 == 1)
  350. {
  351. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  352. img = gtk_image_new_from_file(str5);
  353. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  354. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  355. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  356. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  357. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  358. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  359. gtk_widget_show(img);
  360. strcpy(slide, str5);
  361. flag3 = 1;
  362. break;
  363.  
  364. }
  365. if (strcmp(str5, slide) == 0) flag2 = 1;
  366. }
  367. }
  368. if (flag3 == 1) break;
  369. }
  370. }
  371.  
  372. void show_previous()
  373. {
  374. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  375. for (; ;)
  376. {
  377. for (i = global - 1; i >= 0; i--)
  378. {
  379. strcpy(str3, image_list[i]);
  380. l = 0, len = strlen(slide);
  381. str5[0] = 0;
  382. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  383. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  384. str5[l] = 0, k = 0;
  385. strcat(str5, str3), len = strlen(str3);
  386. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  387. str6[k] = 0;
  388. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  389. {
  390. if (flag2 == 1)
  391. {
  392. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  393. img = gtk_image_new_from_file(str5);
  394. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  395. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  396. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  397. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  398. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  399. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  400. gtk_widget_show(img);
  401. strcpy(slide, str5);
  402. flag3 = 1;
  403. break;
  404.  
  405. }
  406. if (strcmp(str5, slide) == 0) flag2 = 1;
  407. }
  408. }
  409. if (flag3 == 1) break;
  410. }
  411. }
  412.  
  413. void goto_first()
  414. {
  415. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  416. for (i = 0; i < global; i++)
  417. {
  418. strcpy(str3, image_list[i]);
  419. l = 0, len = strlen(slide);
  420. str5[0] = 0;
  421. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  422. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  423. str5[l] = 0, k = 0;
  424. strcat(str5, str3), len = strlen(str3);
  425. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  426. str6[k] = 0;
  427. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  428. {
  429. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  430. img = gtk_image_new_from_file(str5);
  431. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  432. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  433. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  434. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  435. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  436. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  437. gtk_widget_show(img);
  438. strcpy(slide, str5);
  439. flag3 = 1;
  440. break;
  441. }
  442. }
  443. }
  444.  
  445. void goto_last()
  446. {
  447. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  448. for (i = global - 1; i >= 0; i--)
  449. {
  450. strcpy(str3, image_list[i]);
  451. l = 0, len = strlen(slide);
  452. str5[0] = 0;
  453. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  454. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  455. str5[l] = 0, k = 0;
  456. strcat(str5, str3), len = strlen(str3);
  457. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  458. str6[k] = 0;
  459. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  460. {
  461. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  462. img = gtk_image_new_from_file(str5);
  463. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  464. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  465. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  466. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  467. windowicon = gdk_pixbuf_new_from_file(str5, NULL);
  468. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  469. gtk_widget_show(img);
  470. strcpy(slide, str5);
  471. flag3 = 1;
  472. break;
  473. }
  474. }
  475. }
  476.  
  477. void goodbye_dialog()
  478. {
  479. 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.");
  480. gtk_window_set_position (GTK_WINDOW (gbdialog), GTK_WIN_POS_CENTER);
  481. gtk_dialog_run (GTK_DIALOG (gbdialog));
  482. gtk_widget_destroy (gbdialog);
  483. gtk_main_quit();
  484. }
  485.  
  486. int main(int argc, char *argv[])
  487. {
  488. gtk_init(&argc, &argv);
  489. width = gdk_screen_width();
  490. height = gdk_screen_height();
  491. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  492. gtk_window_set_skip_taskbar_hint (window, TRUE);
  493. gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
  494. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
  495. gtk_widget_set_size_request(GTK_WIDGET(window), width, height);
  496. gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  497. heightini = height;
  498. height = (height * 16) / 17;
  499. zoom_width = width, zoom_height = height;
  500.  
  501. fixed_layout = gtk_fixed_new();
  502. char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg";
  503. img = gtk_image_new_from_file(picturename);
  504. windowicon = gdk_pixbuf_new_from_file(picturename, NULL);
  505. gtk_window_set_icon(GTK_WINDOW(window), windowicon);
  506. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  507. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  508. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  509. strcpy(slide, picturename);
  510. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  511. create_toolbar();
  512. gtk_container_add(GTK_CONTAINER(window), fixed_layout);
  513. get_list(picturename);
  514. store_list();
  515. system(str2);
  516.  
  517. gtk_window_fullscreen(window);
  518. g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
  519. g_signal_connect(G_OBJECT(openbutton), "clicked", G_CALLBACK(open_file), NULL);
  520. g_signal_connect(G_OBJECT(gotofirstbutton), "clicked", G_CALLBACK(goto_first), NULL);
  521. g_signal_connect(G_OBJECT(gotolastbutton), "clicked", G_CALLBACK(goto_last), NULL);
  522. g_signal_connect(G_OBJECT(aboutbutton), "clicked", G_CALLBACK(show_about), NULL);
  523. g_signal_connect(G_OBJECT(closebutton), "clicked",G_CALLBACK(goodbye_dialog), NULL);
  524. g_signal_connect(G_OBJECT(playbutton), "clicked",G_CALLBACK(start_slide), NULL);
  525. g_signal_connect(G_OBJECT(stopbutton), "clicked",G_CALLBACK(stop_slide), NULL);
  526. g_signal_connect(G_OBJECT(nextbutton), "clicked",G_CALLBACK(show_next2), NULL);
  527. g_signal_connect(G_OBJECT(previousbutton), "clicked",G_CALLBACK(show_previous), NULL);
  528. g_signal_connect(G_OBJECT(zoom_in_button), "clicked",G_CALLBACK(zoom_in), NULL);
  529. g_signal_connect(G_OBJECT(zoom_out_button), "clicked",G_CALLBACK(zoom_out), NULL);
  530. g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
  531. gtk_widget_show_all(GTK_WIDGET(window));
  532. gtk_widget_hide(GTK_WIDGET(stopbutton));
  533. gtk_main();
  534.  
  535. return 0x0;
  536. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement