Advertisement
palmerstone

Gtk 6

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