Advertisement
palmerstone

Gtk 5

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