Advertisement
palmerstone

Gtk 7

Nov 24th, 2011
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.59 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, width, height;
  12. char str[500], str2[500], str3[500], str4[500], str5[500], str6[500], slide[500];
  13. char image_list[5000][100];
  14. GtkWidget *fixed_layout;
  15. GtkWindow *window;
  16. GtkWidget *vbox;
  17. GtkWidget *menubar, *filemenu, *help, *helpmenu;
  18. GtkWidget *file, *quit, *open, *save, *properties, *about, *slideshow, *shownext, *showprevious;
  19. GtkWidget *img, *img2;
  20. GtkWidget *dialog;
  21. GtkRequisition *allocator;
  22. GdkScreen *screen;
  23.  
  24. void wait(double seconds);
  25. void create_menu();
  26. void show_about();
  27. void open_file();
  28. void show_properties();
  29. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data);
  30. void start_slide();
  31. void get_list(char filename[500]);
  32. void store_list();
  33. void show_next();
  34. void show_previous();
  35.  
  36. void wait(double seconds)
  37. {
  38. clock_t lol;
  39. lol = clock() + (seconds * CLOCKS_PER_SEC);
  40. while(clock() < lol) {}
  41. }
  42.  
  43. void create_menu()
  44. {
  45. vbox = gtk_vbox_new(FALSE, 0);
  46. fixed_layout = gtk_fixed_new();
  47. gtk_container_add(GTK_CONTAINER(fixed_layout), vbox);
  48. menubar = gtk_menu_bar_new();
  49. filemenu = gtk_menu_new();
  50.  
  51. file = gtk_menu_item_new_with_label("File");
  52. quit = gtk_menu_item_new_with_label("Quit Ctrl + Q");
  53. open = gtk_menu_item_new_with_label("Open Ctrl + O");
  54. save = gtk_menu_item_new_with_label("Save");
  55. slideshow = gtk_menu_item_new_with_label("Start Slide");
  56. showprevious = gtk_menu_item_new_with_label("Show Previous");
  57. shownext = gtk_menu_item_new_with_label("Show Next");
  58. properties = gtk_menu_item_new_with_label("Properties Ctrl + P");
  59.  
  60. gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
  61. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
  62. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save);
  63. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), slideshow);
  64. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), showprevious);
  65. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), shownext);
  66. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), properties);
  67. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
  68. gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
  69.  
  70. helpmenu = gtk_menu_new();
  71. about = gtk_menu_item_new_with_label("About");
  72. help = gtk_menu_item_new_with_label("Help");
  73. gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), helpmenu);
  74. gtk_menu_shell_append(GTK_MENU_SHELL(helpmenu), about);
  75. gtk_menu_shell_append(GTK_MENU_SHELL(menubar), help);
  76. gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
  77. }
  78.  
  79. void show_about()
  80. {
  81. GtkWidget *dialog;
  82. const char *author[] = {"None yet\n(However, Special thanks to Mehedi Hasan and\nShadman Shadab :-) )",NULL};
  83. dialog = gtk_about_dialog_new();
  84. gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"You just clicked about!");
  85. gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
  86. gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"Good job and go to hell!!");
  87. gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
  88. gtk_dialog_run(GTK_DIALOG(dialog));
  89. }
  90.  
  91. void open_file()
  92. {
  93. 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);
  94. if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  95. {
  96. char *filename;
  97. filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  98. strcpy(slide, filename);
  99. get_list(filename);
  100. store_list();
  101. system(str2);
  102. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  103. img = gtk_image_new_from_file(filename);
  104. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  105. pixbuf = gdk_pixbuf_scale_simple(pixbuf, 1024, 768, GDK_INTERP_BILINEAR);
  106. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  107. gtk_widget_show(img);
  108. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  109. g_free (filename);
  110. }
  111. gtk_widget_destroy (dialog);
  112. }
  113.  
  114. void show_properties()
  115. {
  116.  
  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->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_P || lol->keyval == GDK_KEY_p))
  126. show_properties();
  127. if (lol->keyval == GDK_KEY_Right)
  128. show_next();
  129. if (lol->keyval == GDK_KEY_Left)
  130. show_previous();
  131. return TRUE;
  132. }
  133.  
  134.  
  135. void start_slide()
  136. {
  137.  
  138. }
  139.  
  140. void get_list(char filename[500])
  141. {
  142. int k = 0, j, l = 0, x;
  143. int len = strlen(filename);
  144. for (j = len - 1; filename[j] != '\\'; j--) x = 1;
  145. str[0] = 0;
  146. strcat(str, "cd /d ");
  147. for (k = 0; k < j; k++) str4[l++] = filename[k];
  148. str4[l] = 0;
  149. str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
  150. system(str3);
  151. strcat(str, str4);
  152. strcpy(str2, str);
  153. strcat(str, " && dir /b >> dir_listing.txt");
  154. strcat(str2, " && del dir_listing.txt");
  155. system(str);
  156. strcat(str4, "\\dir_listing.txt");
  157. }
  158.  
  159. void store_list()
  160. {
  161. FILE *input;
  162. input = fopen(str4, "r");
  163. for (global = 0; ;global++)
  164. {
  165. if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
  166. fgetc(input);
  167. }
  168. fclose(input);
  169. }
  170.  
  171. void show_next()
  172. {
  173. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  174. for (; ;)
  175. {
  176. for (i = 0; i < global; i++)
  177. {
  178. strcpy(str3, image_list[i]);
  179. l = 0, len = strlen(slide);
  180. str5[0] = 0;
  181. for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  182. for (k = 0; k <= j; k++) str5[l++] = slide[k];
  183. str5[l] = 0, k = 0;
  184. strcat(str5, str3), len = strlen(str3);
  185. for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  186. str6[k] = 0;
  187. if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  188. {
  189. if (flag2 == 1)
  190. {
  191. gtk_container_remove(GTK_CONTAINER(fixed_layout), img);
  192. img = gtk_image_new_from_file(str5);
  193. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  194. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  195. pixbuf = gdk_pixbuf_scale_simple(pixbuf, 1024, 768, GDK_INTERP_BILINEAR);
  196. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  197. gtk_widget_show(img);
  198. strcpy(slide, str5);
  199. flag3 = 1;
  200. break;
  201.  
  202. }
  203. if (strcmp(str5, slide) == 0) flag2 = 1;
  204. }
  205. }
  206. if (flag3 == 1) break;
  207. }
  208. }
  209.  
  210. void show_previous()
  211. {
  212. int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  213. for (; ;)
  214. {
  215. for (i = global - 1; i >= 0; 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, 1024, 768, 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. int main(int argc, char *argv[])
  250. {
  251. gtk_init(&argc, &argv);
  252. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  253. gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
  254. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  255. //gtk_window_set_default_size(GTK_WINDOW(window), 800, 800);
  256. gtk_widget_set_size_request(GTK_WIDGET(window), 1024, 768);
  257. gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  258. GdkScreen *screen;
  259. //screen = gdk_screen_get_default();
  260. //printf("%d %d\n", screen->width, screen->height);
  261.  
  262. create_menu();
  263. char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg";
  264. img = gtk_image_new_from_file(picturename);
  265. GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img));
  266. pixbuf = gdk_pixbuf_scale_simple(pixbuf, 1024, 768, GDK_INTERP_BILINEAR);
  267. gtk_image_set_from_pixbuf(GTK_IMAGE(img), pixbuf);
  268. strcpy(slide, picturename);
  269. gtk_container_add(GTK_CONTAINER(fixed_layout), img);
  270. gtk_container_add(GTK_CONTAINER(window), fixed_layout);
  271. get_list(picturename);
  272. store_list();
  273. system(str2);
  274.  
  275. g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
  276. g_signal_connect(G_OBJECT(open), "activate", G_CALLBACK(open_file), NULL);
  277. g_signal_connect(G_OBJECT(properties), "activate", G_CALLBACK(show_properties), NULL);
  278. g_signal_connect(G_OBJECT(about), "activate", G_CALLBACK(show_about), NULL);
  279. g_signal_connect(G_OBJECT(quit), "activate",G_CALLBACK(gtk_main_quit), NULL);
  280. g_signal_connect(G_OBJECT(slideshow), "activate",G_CALLBACK(start_slide), NULL);
  281. g_signal_connect(G_OBJECT(shownext), "activate",G_CALLBACK(show_next), NULL);
  282. g_signal_connect(G_OBJECT(showprevious), "activate",G_CALLBACK(show_previous), NULL);
  283. g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
  284. gtk_widget_show_all(GTK_WIDGET(window));
  285. gtk_main();
  286.  
  287. return 0x0;
  288. }
  289.  
  290.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement