Advertisement
palmerstone

Gtk 8

Nov 26th, 2011
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.07 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. int global;
  12. int width, height;
  13. char str[500], str2[500], str3[500], str4[500], str5[500], str6[500], slide[500];
  14. char image_list[5000][100];
  15.  
  16. GtkWidget *fixed_layout;
  17. GtkWindow *window;
  18. GtkWidget *vbox;
  19. GtkWidget *menubar, *filemenu, *help, *helpmenu;
  20. GtkWidget *file, *quit, *open, *save, *about, *slideshow, *shownext, *showprevious;
  21. GtkWidget *img, *img2;
  22. GtkWidget *dialog;
  23. GtkRequisition *allocator;
  24. GdkScreen *screen;
  25.  
  26. void wait(double seconds);
  27. void create_menu();
  28. void show_about();
  29. void open_file();
  30. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data);
  31. void start_slide();
  32. void get_list(char filename[500]);
  33. void store_list();
  34. void show_next();
  35. void show_previous();
  36.  
  37. void wait(double seconds)
  38. {
  39. clock_t lol;
  40. lol = clock() + (seconds * CLOCKS_PER_SEC);
  41. while(clock() < lol)
  42. {
  43. if (clock() % 100 == 0) gtk_widget_show(img);
  44. }
  45. }
  46.  
  47. void create_menu()
  48. {
  49. vbox = gtk_vbox_new(FALSE, 0);
  50. fixed_layout = gtk_fixed_new();
  51. gtk_container_add(GTK_CONTAINER(fixed_layout), vbox);
  52. menubar = gtk_menu_bar_new();
  53. filemenu = gtk_menu_new();
  54.  
  55. file = gtk_menu_item_new_with_label("File");
  56. quit = gtk_menu_item_new_with_label("Quit Ctrl + Q");
  57. open = gtk_menu_item_new_with_label("Open Ctrl + O");
  58. save = gtk_menu_item_new_with_label("Save");
  59. slideshow = gtk_menu_item_new_with_label("Start Slide");
  60. showprevious = gtk_menu_item_new_with_label("Show Previous");
  61. shownext = gtk_menu_item_new_with_label("Show Next");
  62.  
  63. gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
  64. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
  65. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save);
  66. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), slideshow);
  67. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), showprevious);
  68. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), shownext);
  69. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
  70. gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
  71.  
  72. helpmenu = gtk_menu_new();
  73. about = gtk_menu_item_new_with_label("About");
  74. help = gtk_menu_item_new_with_label("Help");
  75. gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), helpmenu);
  76. gtk_menu_shell_append(GTK_MENU_SHELL(helpmenu), about);
  77. gtk_menu_shell_append(GTK_MENU_SHELL(menubar), help);
  78. gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
  79. }
  80.  
  81. void show_about()
  82. {
  83. GtkWidget *dialog;
  84. const char copyright[] = "Copyright Fireflight TM, 2011-Present. All rights reserved.";
  85. const char *author[] = {"Scape", "mr.rana", "(And special thanks to Mehedi Hasan and Shadman Shadab)", "", "Contact information: sgtlaugh@gmail.com",NULL};
  86. dialog = gtk_about_dialog_new();
  87. gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"Firedlight Image Viewer v1.052 (beta)");
  88. gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
  89. gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), copyright);
  90. gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"A free image viewer :)");
  91. gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS);
  92. gtk_dialog_run(GTK_DIALOG(dialog));
  93. gtk_widget_destroy(dialog);
  94. }
  95.  
  96. void open_file()
  97. {
  98. 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);
  99. if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  100. {
  101. char *filename;
  102. filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  103. strcpy(slide, filename);
  104. get_list(filename);
  105. store_list();
  106. system(str2);
  107. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  108. img = gtk_image_new_from_file(filename);
  109. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  110. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  111. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  112. gtk_widget_show(img);
  113. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  114. g_free (filename);
  115. }
  116. gtk_widget_destroy (dialog);
  117. }
  118.  
  119. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data)
  120. {
  121. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_q || lol->keyval == GDK_KEY_Q))
  122. exit (0x0);
  123. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_O || lol->keyval == GDK_KEY_o))
  124. open_file();
  125. if (lol->keyval == GDK_KEY_Right)
  126. show_next();
  127. if (lol->keyval == GDK_KEY_Left)
  128. show_previous();
  129. if (lol->keyval == GDK_KEY_space)
  130. start_slide();
  131. return TRUE;
  132. }
  133.  
  134.  
  135. void start_slide()
  136. {
  137. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  138. for (; ;)
  139. {
  140. for (i = 0; i < global; i++)
  141. {
  142. strcpy(str3, image_list[i]);
  143. l = 0, len = strlen(slide);
  144. str5[0] = 0;
  145. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  146. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  147. str5[l] = 0, k = 0;
  148. strcat(str5, str3), len = strlen(str3);
  149. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  150. str6[k] = 0;
  151. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  152. {
  153. if (flag2 == 1)
  154. {
  155. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  156. img = gtk_image_new_from_file(str5);
  157. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  158. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  159. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  160. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  161. gtk_widget_show(img);
  162. wait(2.0);
  163. strcpy(slide, str5);
  164. flag3 = 1;
  165. }
  166. if (strcmp(str5, slide) == 0) flag2 = 1;
  167. }
  168. }
  169. if (flag3 == 1) break;
  170. }
  171. }
  172.  
  173. void get_list(char filename[500])
  174. {
  175. int k = 0, j, l = 0, x;
  176. int len = strlen(filename);
  177. for (j = len - 1; filename[j] != '\\'; j--) x = 1;
  178. str[0] = 0;
  179. strcat(str, "cd /d ");
  180. for (k = 0; k < j; k++) str4[l++] = filename[k];
  181. str4[l] = 0;
  182. str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
  183. system(str3);
  184. strcat(str, str4);
  185. strcpy(str2, str);
  186. strcat(str, " && dir /b >> dir_listing.txt");
  187. strcat(str2, " && del dir_listing.txt");
  188. system(str);
  189. strcat(str4, "\\dir_listing.txt");
  190. }
  191.  
  192. void store_list()
  193. {
  194. FILE *input;
  195. input = fopen(str4, "r");
  196. for (global = 0; ;global++)
  197. {
  198. if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
  199. fgetc(input);
  200. }
  201. fclose(input);
  202. }
  203.  
  204. void show_next()
  205. {
  206. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  207. for (; ;)
  208. {
  209. for (i = 0; i < global; i++)
  210. {
  211. strcpy(str3, image_list[i]);
  212. l = 0, len = strlen(slide);
  213. str5[0] = 0;
  214. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  215. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  216. str5[l] = 0, k = 0;
  217. strcat(str5, str3), len = strlen(str3);
  218. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  219. str6[k] = 0;
  220. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  221. {
  222. if (flag2 == 1)
  223. {
  224. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  225. img = gtk_image_new_from_file(str5);
  226. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  227. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  228. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  229. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  230. gtk_widget_show(img);
  231. strcpy(slide, str5);
  232. flag3 = 1;
  233. break;
  234.  
  235. }
  236. if (strcmp(str5, slide) == 0) flag2 = 1;
  237. }
  238. }
  239. if (flag3 == 1) break;
  240. }
  241. }
  242.  
  243. void show_previous()
  244. {
  245. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  246. for (; ;)
  247. {
  248. for (i = global - 1; i >= 0; i--)
  249. {
  250. strcpy(str3, image_list[i]);
  251. l = 0, len = strlen(slide);
  252. str5[0] = 0;
  253. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  254. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  255. str5[l] = 0, k = 0;
  256. strcat(str5, str3), len = strlen(str3);
  257. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  258. str6[k] = 0;
  259. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  260. {
  261. if (flag2 == 1)
  262. {
  263. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  264. img = gtk_image_new_from_file(str5);
  265. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  266. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  267. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  268. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  269. gtk_widget_show(img);
  270. strcpy(slide, str5);
  271. flag3 = 1;
  272. break;
  273.  
  274. }
  275. if (strcmp(str5, slide) == 0) flag2 = 1;
  276. }
  277. }
  278. if (flag3 == 1) break;
  279. }
  280. }
  281.  
  282. int main(int argc, char *argv[])
  283. {
  284. gtk_init(&argc, &argv);
  285. width = gdk_screen_width();
  286. height = gdk_screen_height();
  287. width = (width * 2) / 3;
  288. height = (height * 2) / 3;
  289.  
  290. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  291. gtk_window_set_skip_taskbar_hint (window, TRUE);
  292. gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
  293. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
  294. gtk_widget_set_size_request(GTK_WIDGET(window), width, height);
  295. gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  296.  
  297. create_menu();
  298. char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg";
  299. img = gtk_image_new_from_file(picturename);
  300. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  301. pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  302. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  303. strcpy(slide, picturename);
  304. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  305. gtk_container_add(GTK_CONTAINER(window), fixed_layout);
  306. get_list(picturename);
  307. store_list();
  308. system(str2);
  309.  
  310. //gtk_window_fullscreen(window);
  311. //gtk_window_set_skip_taskbar_hint(window, 1);
  312.  
  313. g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
  314. g_signal_connect(G_OBJECT(open), "activate", G_CALLBACK(open_file), NULL);
  315. g_signal_connect(G_OBJECT(about), "activate", G_CALLBACK(show_about), NULL);
  316. g_signal_connect(G_OBJECT(quit), "activate",G_CALLBACK(gtk_main_quit), NULL);
  317. g_signal_connect(G_OBJECT(slideshow), "activate",G_CALLBACK(start_slide), NULL);
  318. g_signal_connect(G_OBJECT(shownext), "activate",G_CALLBACK(show_next), NULL);
  319. g_signal_connect(G_OBJECT(showprevious), "activate",G_CALLBACK(show_previous), NULL);
  320. g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
  321. gtk_widget_show_all(GTK_WIDGET(window));
  322. gtk_main();
  323.  
  324. return 0x0;
  325. }
  326.  
  327.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement