Advertisement
palmerstone

Gtk 9

Nov 26th, 2011
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.06 KB | None | 0 0
  1. #include <time.h>
  2. #include <cairo.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <windows.h>
  6. #include <gtk/gtk.h>
  7. #include <gdk/gdk.h>
  8. #include <gdk/gdkkeysyms.h>
  9. #include <gdk-pixbuf/gdk-pixbuf.h>
  10.  
  11. const int square_size = 30;
  12. int global, ini = 20, total;
  13. int width, height, heightini;
  14. char str[500], str2[500], str3[500], str4[500], str5[500], str6[500], slide[500];
  15. char image_list[5000][100];
  16.  
  17. GtkWidget *fixed_layout;
  18. GtkWindow *window;
  19. GtkWidget *img;
  20. GtkWidget *dialog;
  21. GtkRequisition *allocator;
  22. GdkScreen *screen;
  23. GtkButton *openbutton, *closebutton, *nextbutton, *previousbutton, *playbutton, *aboutbutton, *gotofirstbutton, *gotolastbutton;
  24. GtkTooltips *opentooltip, *closetooltip, *nexttooltip, *previoustooltip, *playtooltip, *abouttooltip, *gotofirsttooltip, *gotolasttooltip;
  25.  
  26. void wait(double seconds);
  27. void create_menu();
  28. void create_toolbar();
  29. void show_about();
  30. void open_file();
  31. void start_slide();
  32. void get_list(char filename[500]);
  33. void store_list();
  34. void show_next();
  35. void show_previous();
  36. void goto_first();
  37. void goto_last();
  38. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data);
  39.  
  40. void goto_first()
  41. {
  42. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  43. for (i = 0; i < global; i++)
  44. {
  45. strcpy(str3, image_list[i]);
  46. l = 0, len = strlen(slide);
  47. str5[0] = 0;
  48. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  49. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  50. str5[l] = 0, k = 0;
  51. strcat(str5, str3), len = strlen(str3);
  52. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  53. str6[k] = 0;
  54. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  55. {
  56. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  57. img = gtk_image_new_from_file(str5);
  58. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  59. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  60. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  61. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  62. gtk_widget_show(img);
  63. strcpy(slide, str5);
  64. flag3 = 1;
  65. break;
  66. }
  67. }
  68. }
  69.  
  70. void goto_last()
  71. {
  72. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  73. for (i = global - 1; i >= 0; i--)
  74. {
  75. strcpy(str3, image_list[i]);
  76. l = 0, len = strlen(slide);
  77. str5[0] = 0;
  78. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  79. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  80. str5[l] = 0, k = 0;
  81. strcat(str5, str3), len = strlen(str3);
  82. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  83. str6[k] = 0;
  84. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  85. {
  86. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  87. img = gtk_image_new_from_file(str5);
  88. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  89. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  90. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  91. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  92. gtk_widget_show(img);
  93. strcpy(slide, str5);
  94. flag3 = 1;
  95. break;
  96. }
  97. }
  98. }
  99.  
  100. void create_toolbar()
  101. {
  102. total = (8 * 30) + (10 * 7);
  103. ini = (width - total) / 2;
  104.  
  105. openbutton = gtk_button_new();
  106. opentooltip = gtk_tooltips_new();
  107. gtk_widget_set_size_request(GTK_WIDGET(openbutton), square_size, square_size);
  108. gtk_button_set_image (GTK_BUTTON(openbutton),gtk_image_new_from_stock(GTK_STOCK_ORIENTATION_PORTRAIT, GTK_ICON_SIZE_BUTTON));
  109. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(openbutton), ini, heightini - 40);
  110. gtk_tooltips_set_tip(opentooltip, GTK_WIDGET(openbutton), "Open (Ctrl+O)", "Open (Ctrl+O)");
  111.  
  112. ini += 40;
  113. gotofirstbutton = gtk_button_new();
  114. gotofirsttooltip = gtk_tooltips_new();
  115. gtk_widget_set_size_request(GTK_WIDGET(gotofirstbutton), square_size, square_size);
  116. gtk_button_set_image (GTK_BUTTON(gotofirstbutton),gtk_image_new_from_stock(GTK_STOCK_GOTO_FIRST, GTK_ICON_SIZE_BUTTON));
  117. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(gotofirstbutton), ini, heightini - 40);
  118. gtk_tooltips_set_tip(gotofirsttooltip, GTK_WIDGET(gotofirstbutton), "Go to first image (Page Up)", "Go to first image (Page Up)");
  119.  
  120. ini += 40;
  121. previousbutton = gtk_button_new();
  122. previoustooltip = gtk_tooltips_new();
  123. gtk_widget_set_size_request(GTK_WIDGET(previousbutton), square_size, square_size);
  124. gtk_button_set_image (GTK_BUTTON(previousbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PREVIOUS, GTK_ICON_SIZE_BUTTON));
  125. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(previousbutton), ini, heightini - 40);
  126. gtk_tooltips_set_tip(previoustooltip, GTK_WIDGET(previousbutton), "Show Previous (Left key)", "Show Previous (Left key)");
  127.  
  128. ini += 40;
  129. playbutton = gtk_button_new();
  130. playtooltip = gtk_tooltips_new();
  131. gtk_widget_set_size_request(GTK_WIDGET(playbutton), square_size, square_size);
  132. gtk_button_set_image (GTK_BUTTON(playbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_BUTTON));
  133. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(playbutton), ini, heightini - 40);
  134. gtk_tooltips_set_tip(playtooltip, GTK_WIDGET(playbutton), "Start Slideshow (Spacebar)", "Start Slideshow (Spacebar)");
  135.  
  136. ini += 40;
  137. nextbutton = gtk_button_new();
  138. nexttooltip = gtk_tooltips_new();
  139. gtk_widget_set_size_request(GTK_WIDGET(nextbutton), square_size, square_size);
  140. gtk_button_set_image (GTK_BUTTON(nextbutton),gtk_image_new_from_stock(GTK_STOCK_MEDIA_NEXT, GTK_ICON_SIZE_BUTTON));
  141. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(nextbutton), ini, heightini - 40);
  142. gtk_tooltips_set_tip(nexttooltip, GTK_WIDGET(nextbutton), "Show Next (Right Key)", "Show Next (Right Key)");
  143.  
  144. ini += 40;
  145. gotolastbutton = gtk_button_new();
  146. gotolasttooltip = gtk_tooltips_new();
  147. gtk_widget_set_size_request(GTK_WIDGET(gotolastbutton), square_size, square_size);
  148. gtk_button_set_image (GTK_BUTTON(gotolastbutton),gtk_image_new_from_stock(GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON));
  149. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(gotolastbutton), ini, heightini - 40);
  150. gtk_tooltips_set_tip(gotolasttooltip, GTK_WIDGET(gotolastbutton), "Go to last image (Page Down)", "Go to last image (Page Down)");
  151.  
  152. ini += 40;
  153. aboutbutton = gtk_button_new();
  154. abouttooltip = gtk_tooltips_new();
  155. gtk_widget_set_size_request(GTK_WIDGET(aboutbutton), square_size, square_size);
  156. gtk_button_set_image (GTK_BUTTON(aboutbutton),gtk_image_new_from_stock(GTK_STOCK_INFO, GTK_ICON_SIZE_BUTTON));
  157. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(aboutbutton), ini, heightini - 40);
  158. gtk_tooltips_set_tip(abouttooltip, GTK_WIDGET(aboutbutton), "About Us :)", "About Us :)");
  159.  
  160. ini += 40;
  161. closebutton = gtk_button_new();
  162. closetooltip = gtk_tooltips_new();
  163. gtk_widget_set_size_request(GTK_WIDGET(closebutton), square_size, square_size);
  164. gtk_button_set_image (GTK_BUTTON(closebutton),gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON));
  165. gtk_fixed_put(GTK_FIXED(fixed_layout), GTK_WIDGET(closebutton), ini, heightini - 40);
  166. gtk_tooltips_set_tip(closetooltip, GTK_WIDGET(closebutton), "Close :( (Ctrl+Q)", "Close :( (Ctrl+Q)");
  167. }
  168.  
  169. void wait(double seconds)
  170. {
  171. clock_t lol;
  172. lol = clock() + (seconds * CLOCKS_PER_SEC);
  173. while(clock() < lol)
  174. {
  175. if (clock() % 100 == 0) gtk_widget_show(img);
  176. }
  177. }
  178.  
  179. void show_about()
  180. {
  181. GtkWidget *dialog;
  182. const char copyright[] = "Copyright Fireflight TM, 2011-Present. All rights reserved.";
  183. const char *author[] = {"Scape", "mr.rana", "(And special thanks to Mehedi Hasan and Shadman Shadab)", "", "Contact information: sgtlaugh@gmail.com",NULL};
  184. dialog = gtk_about_dialog_new();
  185. gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"Firedlight Image Viewer v1.052 (beta)");
  186. gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
  187. gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), copyright);
  188. gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"A free image viewer :)");
  189. gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS);
  190. gtk_dialog_run(GTK_DIALOG(dialog));
  191. gtk_widget_destroy(dialog);
  192. }
  193.  
  194. void open_file()
  195. {
  196. 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);
  197. if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  198. {
  199. char *filename;
  200. filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  201. strcpy(slide, filename);
  202. get_list(filename);
  203. store_list();
  204. system(str2);
  205. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  206. img = gtk_image_new_from_file(filename);
  207. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  208. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  209. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  210. gtk_widget_show(img);
  211. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  212. g_free (filename);
  213. }
  214. gtk_widget_destroy (dialog);
  215. }
  216.  
  217. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data)
  218. {
  219. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_q || lol->keyval == GDK_KEY_Q))
  220. exit (0x0);
  221. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_O || lol->keyval == GDK_KEY_o))
  222. open_file();
  223. if (lol->keyval == GDK_KEY_Right)
  224. show_next();
  225. if (lol->keyval == GDK_KEY_Left)
  226. show_previous();
  227. if (lol->keyval == GDK_KEY_space)
  228. start_slide();
  229. if (lol->keyval == GDK_KEY_Page_Up)
  230. goto_first();
  231. if (lol->keyval == GDK_KEY_Page_Down)
  232. goto_last();
  233. return TRUE;
  234. }
  235.  
  236.  
  237. void start_slide()
  238. {
  239.  
  240. }
  241.  
  242. void get_list(char filename[500])
  243. {
  244. int k = 0, j, l = 0, x;
  245. int len = strlen(filename);
  246. for (j = len - 1; filename[j] != '\\'; j--) x = 1;
  247. str[0] = 0;
  248. strcat(str, "cd /d ");
  249. for (k = 0; k < j; k++) str4[l++] = filename[k];
  250. str4[l] = 0;
  251. str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
  252. system(str3);
  253. strcat(str, str4);
  254. strcpy(str2, str);
  255. strcat(str, " && dir /b >> dir_listing.txt");
  256. strcat(str2, " && del dir_listing.txt");
  257. system(str);
  258. strcat(str4, "\\dir_listing.txt");
  259. }
  260.  
  261. void store_list()
  262. {
  263. FILE *input;
  264. input = fopen(str4, "r");
  265. for (global = 0; ;global++)
  266. {
  267. if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
  268. fgetc(input);
  269. }
  270. fclose(input);
  271. }
  272.  
  273. void show_next()
  274. {
  275. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  276. for (; ;)
  277. {
  278. for (i = 0; i < global; i++)
  279. {
  280. strcpy(str3, image_list[i]);
  281. l = 0, len = strlen(slide);
  282. str5[0] = 0;
  283. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  284. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  285. str5[l] = 0, k = 0;
  286. strcat(str5, str3), len = strlen(str3);
  287. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  288. str6[k] = 0;
  289. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  290. {
  291. if (flag2 == 1)
  292. {
  293. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  294. img = gtk_image_new_from_file(str5);
  295. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  296. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  297. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  298. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  299. gtk_widget_show(img);
  300. strcpy(slide, str5);
  301. flag3 = 1;
  302. break;
  303.  
  304. }
  305. if (strcmp(str5, slide) == 0) flag2 = 1;
  306. }
  307. }
  308. if (flag3 == 1) break;
  309. }
  310. }
  311.  
  312. void show_previous()
  313. {
  314. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  315. for (; ;)
  316. {
  317. for (i = global - 1; i >= 0; i--)
  318. {
  319. strcpy(str3, image_list[i]);
  320. l = 0, len = strlen(slide);
  321. str5[0] = 0;
  322. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  323. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  324. str5[l] = 0, k = 0;
  325. strcat(str5, str3), len = strlen(str3);
  326. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  327. str6[k] = 0;
  328. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  329. {
  330. if (flag2 == 1)
  331. {
  332. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  333. img = gtk_image_new_from_file(str5);
  334. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  335. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  336. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  337. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  338. gtk_widget_show(img);
  339. strcpy(slide, str5);
  340. flag3 = 1;
  341. break;
  342.  
  343. }
  344. if (strcmp(str5, slide) == 0) flag2 = 1;
  345. }
  346. }
  347. if (flag3 == 1) break;
  348. }
  349. }
  350.  
  351. int main(int argc, char *argv[])
  352. {
  353. gtk_init(&argc, &argv);
  354. width = gdk_screen_width();
  355. height = gdk_screen_height();
  356.  
  357. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  358. gtk_window_set_skip_taskbar_hint (window, TRUE);
  359. gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
  360. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
  361. gtk_widget_set_size_request(GTK_WIDGET(window), width, height);
  362. gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  363. heightini = height;
  364. height = (height * 16) / 17;
  365.  
  366. fixed_layout = gtk_fixed_new();
  367. char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg";
  368. img = gtk_image_new_from_file(picturename);
  369. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  370. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  371. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  372. strcpy(slide, picturename);
  373. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  374. create_toolbar();
  375. gtk_container_add(GTK_CONTAINER(window), fixed_layout);
  376. get_list(picturename);
  377. store_list();
  378. system(str2);
  379.  
  380. gtk_window_fullscreen(window);
  381. //gtk_window_set_skip_taskbar_hint(window, 1);
  382.  
  383. g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
  384. g_signal_connect(G_OBJECT(openbutton), "clicked", G_CALLBACK(open_file), NULL);
  385. g_signal_connect(G_OBJECT(gotofirstbutton), "clicked", G_CALLBACK(goto_first), NULL);
  386. g_signal_connect(G_OBJECT(gotolastbutton), "clicked", G_CALLBACK(goto_last), NULL);
  387. g_signal_connect(G_OBJECT(aboutbutton), "clicked", G_CALLBACK(show_about), NULL);
  388. g_signal_connect(G_OBJECT(closebutton), "clicked",G_CALLBACK(gtk_main_quit), NULL);
  389. g_signal_connect(G_OBJECT(playbutton), "clicked",G_CALLBACK(start_slide), NULL);
  390. g_signal_connect(G_OBJECT(nextbutton), "clicked",G_CALLBACK(show_next), NULL);
  391. g_signal_connect(G_OBJECT(previousbutton), "clicked",G_CALLBACK(show_previous), NULL);
  392. g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
  393. gtk_widget_show_all(GTK_WIDGET(window));
  394. gtk_main();
  395.  
  396. return 0x0;
  397. }
  398.  
  399.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement