summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorb0ric <b0risov.alexandr@rambler.ru>2009-08-03 15:59:50 +0300
committerb0ric <b0risov.alexandr@rambler.ru>2009-08-03 15:59:50 +0300
commit89f0dd1c94c08e6f6d972c23dff1a5e40ba5d0e5 (patch)
treeb05524a9c21701d4c32dba9848a6799a82de272a
parent1d7ffa606ae1a0bbf3539c6eb592bc37c370effd (diff)
WordExtract GUI prototype
-rw-r--r--Makefile15
-rw-r--r--callbacks.c31
-rw-r--r--callbacks.h25
-rw-r--r--interface.c182
-rw-r--r--interface.h24
-rw-r--r--main.c38
6 files changed, 295 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 2798a12..0b69a3c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,19 @@
CC=gcc
-CFLAGS=-Wall -g
+CFLAGS=-Wall -g `pkg-config --cflags gtk+-2.0`
+LDLIBS=`pkg-config --libs gtk+-2.0`
-wordextract: main.o dict.o srt.o engparser.o word.o
- $(CC) main.o dict.o srt.o engparser.o word.o -o wordextract
+wordextract: main.o interface.o callbacks.o dict.o srt.o engparser.o word.o
+ $(CC) $(LDLIBS) main.o interface.o callbacks.o dict.o srt.o engparser.o word.o -o wordextract
-main.o: main.c dict.h srt.h subtitle.h
+main.o: main.c interface.h dict.h srt.h subtitle.h
$(CC) $(CFLAGS) -c main.c
+interface.o: interface.c interface.h
+ $(CC) $(CFLAGS) -c interface.c
+
+callbacks.o: callbacks.c callbacks.h
+ $(CC) $(CFLAGS) -c callbacks.c
+
dict.o: dict.c dict.h
$(CC) $(CFLAGS) -c dict.c
diff --git a/callbacks.c b/callbacks.c
new file mode 100644
index 0000000..3cbb345
--- /dev/null
+++ b/callbacks.c
@@ -0,0 +1,31 @@
+/* This file is a part of WordExtract project
+ *
+ * Copyright (C) 2009 Borisov Alexandr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtk/gtk.h>
+#include "callbacks.h"
+
+gint main_window_close(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+
+return FALSE;
+}
+
+void main_window_destroy(GtkWidget *widget, gpointer data)
+{
+ gtk_main_quit();
+}
diff --git a/callbacks.h b/callbacks.h
new file mode 100644
index 0000000..a41b715
--- /dev/null
+++ b/callbacks.h
@@ -0,0 +1,25 @@
+/* This file is a part of WordExtract project
+ *
+ * Copyright (C) 2009 Borisov Alexandr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CALLBACKS_H
+#define CALLBACKS_H
+
+gint main_window_close(GtkWidget *widget, GdkEvent *event, gpointer data);
+void main_window_destroy(GtkWidget *widget, gpointer data);
+
+#endif /*CALLBACKS_H*/
diff --git a/interface.c b/interface.c
new file mode 100644
index 0000000..d494a1c
--- /dev/null
+++ b/interface.c
@@ -0,0 +1,182 @@
+/* This file is a part of WordExtract project
+ *
+ * Copyright (C) 2009 Borisov Alexandr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtk/gtk.h>
+#include "interface.h"
+#include "callbacks.h"
+
+static GtkWidget *gtk_button_new_with_label_and_image(gchar *img_file, gchar *label);
+
+GtkWidget *create_main_window()
+{
+ GtkWidget *main_window;
+ GtkWidget *vbox;
+ GtkWidget *tool_hbox;
+ GtkWidget *open_btn;
+ GtkWidget *save_btn;
+ GtkWidget *preferences_btn;
+ GtkWidget *dict_btn;
+ GtkWidget *about_btn;
+ GtkWidget *quit_btn;
+ GtkWidget *hpaned;
+ GtkWidget *word_sc_win;
+ GtkWidget *word_list;
+ GtkWidget *sentences_sc_win;
+ GtkWidget *sentences_text;
+ GtkWidget *statusbar;
+
+ main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_size_request(main_window, 640, 480);
+ gtk_container_set_border_width(GTK_CONTAINER(main_window), 2);
+ gtk_window_set_title(GTK_WINDOW(main_window), "WordExtract");
+ gtk_window_set_position(GTK_WINDOW(main_window), GTK_WIN_POS_CENTER);
+ g_signal_connect(G_OBJECT(main_window), "delete_event", G_CALLBACK(main_window_close), NULL);
+ g_signal_connect(G_OBJECT(main_window), "destroy", G_CALLBACK(main_window_destroy), NULL);
+
+ vbox = gtk_vbox_new(FALSE, 0);
+ gtk_widget_show(vbox);
+ gtk_container_add(GTK_CONTAINER(main_window), vbox);
+ gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
+
+ tool_hbox = gtk_hbox_new(FALSE, 0);
+ gtk_widget_show(tool_hbox);
+ gtk_box_pack_start(GTK_BOX(vbox), tool_hbox, FALSE, FALSE, 0);
+
+ open_btn = gtk_button_new_with_label_and_image("gtk-open", "Open");
+ gtk_widget_show(open_btn);
+ gtk_box_pack_start(GTK_BOX(tool_hbox), open_btn, FALSE, FALSE, 0);
+
+ save_btn = gtk_button_new_with_label_and_image("gtk-save-as", "Save");
+ gtk_widget_show(save_btn);
+ gtk_box_pack_start(GTK_BOX(tool_hbox), save_btn, FALSE, FALSE, 0);
+
+ preferences_btn = gtk_button_new_with_label_and_image("gtk-preferences", "Preferences");
+ gtk_widget_show (preferences_btn);
+ gtk_box_pack_start (GTK_BOX (tool_hbox), preferences_btn, FALSE, FALSE, 0);
+
+ dict_btn = gtk_button_new_with_label_and_image("gtk-edit", "Dictionary");
+ gtk_widget_show(dict_btn);
+ gtk_box_pack_start(GTK_BOX(tool_hbox), dict_btn, FALSE, FALSE, 0);
+
+ quit_btn = gtk_button_new_with_label_and_image("gtk-quit", "Quit");
+ gtk_widget_show (quit_btn);
+ gtk_box_pack_end(GTK_BOX(tool_hbox), quit_btn, FALSE, FALSE, 0);
+
+ about_btn = gtk_button_new_with_label_and_image("gtk-about", "About");
+ gtk_widget_show(about_btn);
+ gtk_box_pack_end(GTK_BOX(tool_hbox), about_btn, FALSE, FALSE, 0);
+
+ hpaned = gtk_hpaned_new();
+ gtk_widget_show(hpaned);
+ gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 0);
+ gtk_paned_set_position(GTK_PANED(hpaned), 200);
+
+ word_sc_win = gtk_scrolled_window_new(NULL, NULL);
+ gtk_widget_show(word_sc_win);
+ gtk_paned_add1(GTK_PANED(hpaned), word_sc_win);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(word_sc_win), GTK_SHADOW_IN);
+
+ word_list = gtk_tree_view_new();
+ gtk_widget_show(word_list);
+ gtk_container_add(GTK_CONTAINER(word_sc_win), word_list);
+ gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(word_list), FALSE);
+ gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(word_list), TRUE);
+
+ sentences_sc_win = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_show (sentences_sc_win);
+ gtk_paned_add2(GTK_PANED(hpaned), sentences_sc_win);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sentences_sc_win), GTK_SHADOW_IN);
+
+ sentences_text = gtk_text_view_new();
+ gtk_widget_show(sentences_text);
+ gtk_container_add(GTK_CONTAINER(sentences_sc_win), sentences_text);
+ gtk_text_view_set_editable(GTK_TEXT_VIEW(sentences_text), FALSE);
+
+ statusbar = gtk_statusbar_new();
+ gtk_widget_show(statusbar);
+ gtk_box_pack_start(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
+
+ return main_window;
+}
+
+/*GtkWidget *create_popup_menu(void)
+{
+ GtkWidget *popup_menu;
+ GtkWidget *show_sent_item;
+ GtkWidget *find_image;
+ GtkWidget *add_to_dict_item;
+ GtkWidget *add_image;
+ GtkTooltips *tooltips;
+
+ tooltips = gtk_tooltips_new ();
+
+ popup_menu = gtk_menu_new ();
+
+ show_sent_item = gtk_image_menu_item_new_with_mnemonic (_("Show Sentence"));
+ gtk_widget_show (show_sent_item);
+ gtk_container_add (GTK_CONTAINER (popup_menu), show_sent_item);
+ gtk_tooltips_set_tip (tooltips, show_sent_item, _("Show sentenses word appears in"), NULL);
+
+ find_image = gtk_image_new_from_stock ("gtk-find", GTK_ICON_SIZE_MENU);
+ gtk_widget_show (find_image);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (show_sent_item), find_image);
+
+ add_to_dict_item = gtk_image_menu_item_new_with_mnemonic (_("Add To Dictionary"));
+ gtk_widget_show (add_to_dict_item);
+ gtk_container_add (GTK_CONTAINER (popup_menu), add_to_dict_item);
+ gtk_tooltips_set_tip (tooltips, add_to_dict_item, _("Add word to my dictionary"), NULL);
+
+ add_image = gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_MENU);
+ gtk_widget_show (add_image);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (add_to_dict_item), add_image);
+
+ g_signal_connect ((gpointer) show_sent_item, "activate",
+ G_CALLBACK (on_show_sent_item_activate),
+ NULL);
+ g_signal_connect ((gpointer) add_to_dict_item, "activate",
+ G_CALLBACK (on_add_to_dict_item_activate),
+ NULL);
+
+ return popup_menu;
+}*/
+
+static GtkWidget *gtk_button_new_with_label_and_image(gchar *img_name, gchar *label_text)
+{
+ GtkWidget *button;
+ GtkWidget *box;
+ GtkWidget *label;
+ GtkWidget *image;
+
+ button = gtk_button_new();
+
+ box = gtk_hbox_new(FALSE, 2);
+ gtk_container_add(GTK_CONTAINER(button), box);
+
+ image = gtk_image_new_from_stock(img_name, GTK_ICON_SIZE_BUTTON);
+ gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
+
+ label = gtk_label_new_with_mnemonic(label_text);
+ gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
+
+ gtk_widget_show(image);
+ gtk_widget_show(label);
+ gtk_widget_show(box);
+
+ return button;
+}
+
diff --git a/interface.h b/interface.h
new file mode 100644
index 0000000..2a2cb18
--- /dev/null
+++ b/interface.h
@@ -0,0 +1,24 @@
+/* This file is a part of WordExtract project
+ *
+ * Copyright (C) 2009 Borisov Alexandr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INTERFACE_H
+#define INTERFACE_H
+
+GtkWidget *create_main_window();
+
+#endif /*INTERFACE_H*/
diff --git a/main.c b/main.c
index e944736..349942d 100644
--- a/main.c
+++ b/main.c
@@ -17,9 +17,11 @@
*/
#include <sys/stat.h>
+#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "interface.h"
#include "dict.h"
#include "word.h"
#include "subtitle.h"
@@ -35,21 +37,14 @@ void create_dict_file(char *path);
int main(int argc, char *argv[])
{
+ GtkWidget *main_window;
FILE *subtitle;
FILE *fdict;
char optpath[PATH_LENGTH] = {0};
char dictfile[PATH_LENGTH] = {0};
- if (argc == 2) {
- if (!(subtitle = fopen(argv[1], "r"))) {
- perror(argv[1]);
- exit(1);
- }
- }
- else {
- printf("Usage: %s <subtitle filename>\n", argv[0]);
- exit(1);
- }
+ gtk_init(&argc, &argv);
+
strcpy(optpath, getenv("HOME"));
strcat(optpath, OPT_FOLDER);
strcat(dictfile, optpath);
@@ -63,12 +58,23 @@ int main(int argc, char *argv[])
}
}
dict = load_dict(fdict);
+ lang = ENG;
+
+ main_window = create_main_window();
+ gtk_widget_show(main_window);
+
+ /*main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(main_window), "WordExtract");
+ gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
+ gtk_window_set_position(GTK_WINDOW(main_window), GTK_WIN_POS_CENTER);
+ gtk_widget_show(main_window);*/
+
+ gtk_main();
//TODO: process subtitle extension to detect format
- lang = ENG;
- process_srt(subtitle);
- print_words(words);
- fclose(subtitle);
+ //process_srt(subtitle);
+ //print_words(words);
+ //fclose(subtitle);
free_words(dict);
fclose(fdict);
return 0;
@@ -82,7 +88,7 @@ void create_dict_file(char *path)
char file[PATH_LENGTH] = {0};
if (stat(path, &st)) {
- fprintf(stdout, "%s: Creating directory\n", path);
+ fprintf(stderr, "%s: Creating directory\n", path);
if (mkdir(path, mode_0755)) {
perror(path);
exit(1);
@@ -90,7 +96,7 @@ void create_dict_file(char *path)
}
strcat(file, path);
strcat(file, DICT_FILE);
- fprintf(stdout, "%s: Creating blank dictionary file\n", file);
+ fprintf(stderr, "%s: Creating blank dictionary file\n", file);
if (!(fdict = fopen(file, "w"))) {
perror(file);
exit(1);