Advertisement
palmerstone

Gtk 10

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