Advertisement
palmerstone

Gtk 4

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