/* * buzz.c * * License: GPL * Author Charles Nofsinger */ #include #include #include #include #include #include #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #include #include #include #include #include #include static GtkWidget *topwindow; static GtkWidget *findwindow; static GtkWidget *notewindow; static GtkWidget *finder; static GtkWidget *editwindow; static GtkWidget *editor; extern xmlSAXHandlerPtr SAXHandler; static GtkWidget *tree; static int casesensitive = 0; static char *lastdelete; static char *lastfile = NULL; static char *homefile; static char *cwd; static int modified = 0; static char *lastdeletewrapper; static char *lasttype; static char *currentfindstr; static int currentfind; static int findcount = 1; static char *currentfilename; static char *cwd; static char *fontname; static char *fontsize; static float scrolledright = 0.0; static GdkFont *f; static GtkCTreeNode *nodestack[1000]; static GtkCTreeNode *root; static GtkCTreeNode *finding; static GtkCTreeNode *lastfoundroot; static GtkCTreeNode *editting; static int topofstack = 0; static GtkStyle *attrstyle; static GtkStyle *datastyle; static GtkStyle *nodestyle; static GtkStyle *leafstyle; /* Utilities */ char * copyStr (char *src) { char *copy; /* points to copy string */ int len; /* length of string */ /* Check we have a real string to copy */ if (src == NULL) return NULL; /* Get the source string length */ len = strlen (src); /* Allocate memory for the copy */ copy = (char *) malloc (sizeof (char) * (len + 1)); if (copy == NULL) return NULL; /* Copy the source and return the new string */ strcpy (copy, src); return copy; } char * joinStr (char *string1, char *string2) { char *result; result = calloc (strlen (string1) + strlen (string2) + 2, sizeof (char)); if (!result) return; strcpy (result, string1); strcat (result, string2); return (result); } /* XML section */ /************************************************************************ * * * Handlers * * * ************************************************************************/ /** * resolveEntity: * @ctxt: An XML parser context * @publicId: The public ID of the entity * @systemId: The system ID of the entity * * Special entity resolver, better left to the parser, it has * more context than the application layer. * The default behaviour is to NOT resolve the entities, in that case * the ENTITY_REF nodes are built in the structure (and the parameter * values). * * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. */ xmlParserInputPtr resolveEntity (void *ctx ATTRIBUTE_UNUSED, const xmlChar * publicId, const xmlChar * systemId) { /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ return (NULL); } /** * getEntity: * @ctxt: An XML parser context * @name: The entity name * * Get an entity by name * * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. */ xmlEntityPtr getEntity (void *ctx ATTRIBUTE_UNUSED, const xmlChar * name) { return (NULL); } /** * startElement: * @ctxt: An XML parser context * @name: The element name * * called when an opening tag has been processed. */ void startElement (void *ctx ATTRIBUTE_UNUSED, const xmlChar * name, const xmlChar ** atts) { int i; gchar *titles[1]; gchar *data; GtkCTreeNode *id; lasttype = (char *) name; if (!strcmp (lasttype, "outline")) { if (atts != NULL) { for (i = 0; (atts[i] != NULL); i++) { if (!strcmp (atts[i++], "text")) { titles[0] = (gchar *) atts[i]; id = gtk_ctree_insert_node (GTK_CTREE (tree), nodestack[topofstack], NULL, (char **) titles, 1, NULL, NULL, NULL, NULL, FALSE, FALSE); if (!topofstack) root = id; gtk_ctree_node_set_row_data (GTK_CTREE (tree), id, (gpointer) copyStr ("__outline")); topofstack++; nodestack[topofstack] = id; break; } else i++; } } if (atts != NULL) { for (i = 0; (atts[i] != NULL); i++) { if (strcmp (atts[i], "text")) { data = calloc (strlen (atts[i]) + strlen (atts[i + 1]) + 4, sizeof (char)); strcpy (data, atts[i++]); strcat (data, "="); strcat (data, atts[i]); titles[0] = data; id = gtk_ctree_insert_node (GTK_CTREE (tree), nodestack[topofstack], NULL, (char **) titles, 1, NULL, NULL, NULL, NULL, TRUE, FALSE); free (data); gtk_ctree_node_set_row_data (GTK_CTREE (tree), id, (gpointer) copyStr ("__att")); } else i++; } } } else { titles[0] = (gchar *) name; id = gtk_ctree_insert_node (GTK_CTREE (tree), nodestack[topofstack], NULL, (char **) titles, 1, NULL, NULL, NULL, NULL, FALSE, FALSE); if (!topofstack) root = id; gtk_ctree_node_set_row_data (GTK_CTREE (tree), id, (gpointer) copyStr ((char *) name)); topofstack++; nodestack[topofstack] = id; if (atts != NULL) { for (i = 0; (atts[i] != NULL); i++) { data = calloc (strlen (atts[i]) + strlen (atts[i + 1]) + 4, sizeof (char)); strcpy (data, atts[i++]); strcat (data, "="); strcat (data, atts[i]); titles[0] = data; /* strcat (strcat ((gchar *) atts[i - 1], "="), (gchar *) atts[i]); */ id = gtk_ctree_insert_node (GTK_CTREE (tree), nodestack[topofstack], NULL, (char **) titles, 1, NULL, NULL, NULL, NULL, FALSE, TRUE); free (data); gtk_ctree_node_set_row_data (GTK_CTREE (tree), id, (gpointer) copyStr ("__att")); } } } } /** * endElement: * @ctxt: An XML parser context * @name: The element name * * called when the end of an element has been detected. */ void endElement (void *ctx ATTRIBUTE_UNUSED, const xmlChar * name) { topofstack--; lasttype = "__end"; } /** * characters: * @ctxt: An XML parser context * @ch: a xmlChar string * @len: the number of xmlChar * * receiving some chars from the parser. * Question: how much at a time ??? */ void characters (void *ctx ATTRIBUTE_UNUSED, const xmlChar * ch, int len) { char *data; GtkCTreeNode *id; gchar *titles[1]; data = calloc (len + 1, sizeof (char)); strncpy (data, ch, len); if ((len == 1) && (!strcmp (data, "\n"))) return; titles[0] = data; id = gtk_ctree_insert_node (GTK_CTREE (tree), nodestack[topofstack], NULL, (char **) titles, 1, NULL, NULL, NULL, NULL, TRUE, FALSE); gtk_ctree_node_set_row_data (GTK_CTREE (tree), id, (gpointer) copyStr ("__data")); } /** * warning: * @ctxt: An XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display * * Display and format a warning messages, gives file, line, position and * extra parameters. */ void warning (void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { printf("%s\n",msg); /* va_list args; va_start (args, msg); va_end (args); */ } /** * error: * @ctxt: An XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display * * Display and format a error messages, gives file, line, position and * extra parameters. */ static void error (void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { printf("%s\n",msg); } /** * fatalError: * @ctxt: An XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display * * Display and format a fatalError messages, gives file, line, position and * extra parameters. */ static void fatalError (void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { printf("%s\n",msg); /* va_list args; va_start (args, msg); va_end (args); */ } xmlSAXHandler SAXHandlerStruct = { NULL, NULL, NULL, NULL, resolveEntity, getEntity, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, startElement, endElement, NULL, characters, NULL, NULL, NULL, warning, error, fatalError, NULL, NULL, NULL, 1 }; xmlSAXHandlerPtr SAXHandler = &SAXHandlerStruct; /************************************************************************ * * * * * * ************************************************************************/ static int expand_to_root (GtkCTreeNode * item) { gtk_ctree_expand (GTK_CTREE (tree), item); if (GTK_CTREE_ROW (item)->parent) { expand_to_root (GTK_CTREE_ROW (item)->parent); } } static void loadtree (char *filename) { int res; FILE *f; f = fopen (filename, "r"); if (f != NULL) { int ret; char chars[10]; xmlParserCtxtPtr ctxt; ret = fread (chars, 1, 4, f); if (ret > 0) { ctxt = xmlCreatePushParserCtxt (SAXHandler, NULL, chars, ret, filename); while ((ret = fread (chars, 1, 3, f)) > 0) { xmlParseChunk (ctxt, chars, ret, 0); } xmlParseChunk (ctxt, chars, 0, 1); xmlFreeParserCtxt (ctxt); } fclose (f); } else { printf("Cannot read file %s\n", filename); exit(0); } } static int item_editted (GtkWidget * localtree, GdkEventKey * event, gpointer data) { char *text; text = gtk_editable_get_chars ((GtkEditable *) editor, 0, -1); gtk_ctree_node_set_text (GTK_CTREE (tree), editting, 0, text); modified = 1; gtk_widget_destroy (editwindow); } static int edit_item (GtkCTreeNode * selection) { gchar *text[1]; guint8 spacing; GdkPixmap *pix_cl, *pix_op; GdkBitmap *mask_cl, *mask_op; gboolean is_leaf, expanded; expand_to_root (selection); editting = selection; gtk_ctree_node_moveto (GTK_CTREE (tree), selection, 0, 0.3, 0.0); gtk_ctree_get_node_info (GTK_CTREE (tree), selection, text, &spacing, &pix_cl, &mask_cl, &pix_op, &mask_op, &is_leaf, &expanded); editwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); editor = gtk_entry_new (); gtk_container_add (GTK_CONTAINER (editwindow), editor); gtk_widget_show (editor); gtk_entry_set_text ((GtkEntry *) editor, text[0]); gtk_widget_set_usize (editwindow, 180, 20); gtk_widget_grab_focus (editor); gtk_widget_show (editwindow); gtk_grab_add (editwindow); gtk_signal_connect (GTK_OBJECT (editor), "activate", GTK_SIGNAL_FUNC (item_editted), NULL); } static gint message (char *message) { GtkWidget *button; GtkWidget *vbox; notewindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_name (notewindow, message); vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (notewindow), vbox); button = gtk_button_new_with_label (message); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_widget_show (button); gtk_widget_show (vbox); gtk_widget_grab_focus (button); gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (notewindow)); gtk_grab_add (notewindow); gtk_widget_show (notewindow); } int button_pressed (GtkWidget * localtree, GdkEventButton * event) { GtkCTreeNode *selection; GtkCTreeNode *id; GtkCTreeNode *node; char *filename; GtkCTreeNode **selections; GtkCList *clist = GTK_CLIST (localtree); GtkCTreeNode *sib; char *url[1]; guint8 spacing; GdkPixmap *pix_cl, *pix_op; GdkBitmap *mask_cl, *mask_op; gboolean is_leaf, expanded; GtkWidget *vbox; gchar key[100]; char *titles[1]; char *offset; if (event->type == GDK_2BUTTON_PRESS) { titles[0] = ""; if (clist->selection) { selection = GTK_CTREE_NODE (clist->selection->data); } else { return FALSE; } if (modified) { message ("File was Modified (M to clear)"); return; } node = GTK_CTREE_ROW (selection)->children; while (node) { gtk_ctree_get_node_info (GTK_CTREE (tree), node, url, &spacing, &pix_cl, &mask_cl, &pix_op, &mask_op, &is_leaf, &expanded); if (strcasestr (url[0], "url=")) { selection = node; offset = strrchr (url[0], '.'); filename = strchr (url[0], '='); filename++; /* (foo,extension)=os.path.splitext(url); (cwd,foo)=os.path.split(filename); */ if (!strcmp (offset, ".opml") || !strcmp (offset, ".OPML")) { filename = joinStr (cwd, filename); file_open (filename); return TRUE; } else { if (!strchr (url[0], ':')) { filename = joinStr (cwd, filename); } filename = joinStr ("dillo ", filename); filename = joinStr (filename, " &"); system (filename); return TRUE; } } if (strcasestr (url[0], "xlink=")) { filename = strchr (url[0], '='); filename++; FollowXlink (copyStr (filename)); return TRUE; } node = GTK_CTREE_ROW (node)->sibling; } return TRUE; } else if ((event->type==GDK_BUTTON_PRESS) && (event->button == 3)) { if (modified) { message ("File was Modified! (M to clear)"); return FALSE; } if (lastfile) { file_open (lastfile); } return TRUE; } return FALSE; } static GtkCTreeNode * FindInModel (GtkCTreeNode * item, char *needle, int casesensitive) { gchar *text[1]; guint8 spacing; GdkPixmap *pix_cl, *pix_op; GdkBitmap *mask_cl, *mask_op; gboolean is_leaf, expanded; GtkCTreeNode *found; GtkCTreeNode *node; char *data; gtk_ctree_get_node_info (GTK_CTREE (tree), item, text, &spacing, &pix_cl, &mask_cl, &pix_op, &mask_op, &is_leaf, &expanded); if (strcasestr ((char *) text[0], needle)) { currentfind = currentfind + 1; if (currentfind == findcount) return (item); } node = GTK_CTREE_ROW (item)->children; while (node) { found = FindInModel (node, needle, casesensitive); if (found) return (found); node = GTK_CTREE_ROW (node)->sibling; } return (NULL); } /* int lowercase(char *string) { int i = 0; while ( string[i] ) { string[i] = tolower(string[i]); i++; } return; } */ void ctree_set_focus_row (GtkWidget * localtree, GtkCTreeNode * node) { GtkCList *clist = GTK_CLIST (localtree); int row = g_list_position (clist->row_list, (GList *) node); clist->focus_row = row; /* GTK_CLIST_CLASS (GTK_OBJECT (clist)->klass)->refresh (clist); */ } static int find_item (GtkWidget * localtree, GdkEventKey * event, gpointer data) { char *text; char *findstr; static GtkCTreeNode *findroot; static GtkCTreeNode *founditem; text = gtk_editable_get_chars ((GtkEditable *) finder, 0, -1); if (text) { findstr = text; if ((!strcasecmp (currentfindstr, findstr)) && lastfoundroot) { findroot = lastfoundroot; findcount = findcount + 1; } else { findroot = finding; findcount = 1; currentfindstr = findstr; } currentfind = 0; founditem = FindInModel (findroot, currentfindstr, casesensitive); if (founditem) { gtk_ctree_select (GTK_CTREE (tree), founditem); expand_to_root (founditem); gtk_ctree_node_moveto (GTK_CTREE (tree), founditem, 0, 0.5, 0.0); ctree_set_focus_row (tree, founditem); lastfoundroot = findroot; } else { message ("Not Found!"); lastfoundroot = NULL; findcount = 1; } } gtk_widget_destroy (findwindow); } int repeat_find () { GtkCTreeNode *founditem; GtkCTreeNode *findroot; if (currentfindstr && lastfoundroot) { findroot = lastfoundroot; findcount = findcount + 1; currentfind = 0; founditem = FindInModel (findroot, currentfindstr, casesensitive); if (founditem) { expand_to_root (founditem); gtk_ctree_node_moveto (GTK_CTREE (tree), founditem, 0, 0.5, 0.0); gtk_ctree_select (GTK_CTREE (tree), founditem); ctree_set_focus_row(tree,founditem); lastfoundroot = findroot; } else { message ("Not Found!"); lastfoundroot = NULL; findcount = 1; } } } GtkCTreeNode * Xpath (GtkCTreeNode * root, char *xpath) { char *buzzid; char *endid; GtkCTreeNode *targetattr; char *oldfindstr; if (strstr (xpath, "//*[@buzzid=")) { lastfoundroot = NULL; findcount = 1; oldfindstr = currentfindstr; buzzid = strchr (xpath, '='); while (!isdigit (*buzzid)) buzzid++; endid = buzzid; while (isdigit (*endid) || (*endid == '.')) endid++; *endid = '\0'; currentfindstr = joinStr ("buzzid=", buzzid); currentfind = 0; targetattr = FindInModel (root, currentfindstr, 0); free (currentfindstr); currentfindstr = oldfindstr; if (targetattr) { return (GTK_CTREE_ROW (targetattr)->parent); } else { return NULL; } } } int FollowXlink (char *xlink) { char *xpath; char *url; char *filename; GtkCTreeNode *curritem; xpath = strchr (xlink, '#'); *xpath = '\0'; xpath++; url = xlink; filename = url; if (modified) { message ("File was Modified!(M to clear)"); return; } if (strstr (filename, "cloud:")) { filename = strchr (filename, ':'); filename++; filename = joinStr (cwd, filename); } else { filename = joinStr (cwd, filename); } if (strcmp (filename, currentfilename)) { file_open (filename); } curritem = Xpath (root, xpath); if (curritem) { expand_to_root (curritem); gtk_ctree_node_moveto (GTK_CTREE (tree), curritem, 0, 0.0, 0.0); gtk_ctree_select (GTK_CTREE (tree), curritem); ctree_set_focus_row (tree, curritem); return 1; } else { message ("Target doesn't exist"); return 0; } } static int key_pressed (GtkWidget * localtree, GdkEventKey * event, gpointer data) { GtkCTreeNode *selection; GtkCTreeNode *id; GtkCTreeNode *node; char *filename; GtkCTreeNode **selections; GtkCList *clist = GTK_CLIST (localtree); GtkCTreeNode *sib; char *url[1]; guint8 spacing; GdkPixmap *pix_cl, *pix_op; GdkBitmap *mask_cl, *mask_op; gboolean is_leaf, expanded; GtkWidget *vbox; gchar key[100]; char *titles[1]; char *offset; titles[0] = ""; if (!event) return; if (clist->selection) { selection = GTK_CTREE_NODE (clist->selection->data); } else { selection = NULL; } switch (event->keyval) { case GDK_t: case GDK_T: { if (selection) { gtk_ctree_toggle_expansion_recursive (GTK_CTREE (tree), selection); gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); } break; } case 269025049: case GDK_r: { if (selection) { if (scrolledright == 0.0) { scrolledright = 0.1; } else if (scrolledright < 1.0) { scrolledright = scrolledright + 0.1; } } gtk_ctree_node_moveto (GTK_CTREE (tree), selection, 0, 0.5, scrolledright); gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break; } case GDK_l: case 2809: { if (selection) { scrolledright = 0.0; gtk_ctree_node_moveto (GTK_CTREE (tree), selection, 0, 0.5, 0.0); } gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break; } case GDK_z: case GDK_Z: { if (selection) { gtk_ctree_expand (GTK_CTREE (tree), selection); } gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break; } /* case GDK_i: case GDK_e: case GDK_E: case GDK_a: { if (selection) { edit_item (selection); } gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break; } case GDK_o: case GDK_O: case GDK_Return: { if (selection) { if (GTK_CTREE_ROW (selection)->sibling) sib = GTK_CTREE_ROW (selection)->sibling; else sib = NULL; id = gtk_ctree_insert_node (GTK_CTREE (tree), GTK_CTREE_ROW (selection)->parent, sib, (char **) titles, 1, NULL, NULL, NULL, NULL, FALSE, FALSE); gtk_ctree_node_set_row_data (GTK_CTREE (tree), id, (gpointer) copyStr ("__outline")); gtk_ctree_select (GTK_CTREE (tree), id); ctree_set_focus_row (tree, id); edit_item (id); modified = 1; gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); } break; } case GDK_c: case GDK_C: { { if (selection) { sib = NULL; id = gtk_ctree_insert_node (GTK_CTREE (tree), selection, sib, (char **) titles, 1, NULL, NULL, NULL, NULL, FALSE, FALSE); gtk_ctree_node_set_row_data (GTK_CTREE (tree), id, (gpointer) copyStr ("__outline")); gtk_ctree_select (GTK_CTREE (tree), id); ctree_set_focus_row (tree, id); edit_item (id); modified = 1; } } gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break; } */ /* elif event.keyval==GDK_p or event.keyval==GDK_P { if selection and lastdelete { if selection.sibling { sib=selection.sibling; }else { sib=None; selection = tree.insert_node(selection.parent,sib,[lastdelete],is_leaf=0); tree.node_set_row_data(selection,lastdeletewrapper); tree.select(selection); elif event.keyval==GDK_period { if selection { sib=None; selection = tree.insert_node(selection,sib,[''],is_leaf=0); tree.node_set_row_style(selection,datastyle); tree.node_set_row_data(selection,ElementWrapper("__data")); tree.select(selection); edit_item(selection); tree.emit_stop_by_name("key-press-event"); elif event.keyval==GDK_at { if selection { sib=None; selection = tree.insert_node(selection,sib,['attribute=value'],is_leaf=1); tree.node_set_row_style(selection,attrstyle); tree.node_set_row_data(selection,ElementWrapper("__data")); tree.select(selection); edit_item(selection); tree.emit_stop_by_name("key-press-event"); elif event.keyval==GDK_u or event.keyval==GDK_U { if selection { modified=1; prev=prev(selection.parent,selection); if prev { selection = tree.move(selection,selection.parent,prev); tree.emit_stop_by_name("key-press-event"); elif event.keyval==GDK_d or event.keyval==GDK_D { if selection { nextsib= selection.sibling.sibling; selection = tree.move(selection,selection.parent,nextsib); modified=1; tree.emit_stop_by_name("key-press-event"); elif event.keyval==GDK_l or event.keyval==GDK_L { if selection.parent.parent { nextparent=selection.parent.sibling; selection = tree.move(selection,selection.parent.parent,nextparent); modified=1; tree.emit_stop_by_name("key-press-event"); */ case GDK_slash: case GDK_N: case GDK_n: { repeat_find (); gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break; } /* elif event.keyval==GDK_r or event.keyval==GDK_R { if selection { childprev=prev(selection.parent,selection); if childprev { selection = tree.move(selection,childprev,None); modified=1; tree.emit_stop_by_name("key-press-event"); elif event.keyval==GDK_x or event.keyval==GDK_X { if selection { (lastdelete,a,b,c,d,e,f,g)=tree.get_node_info(selection); lastdeletewrapper=tree.node_get_row_data(selection); tree.remove_node(selection); modified=1; tree.emit_stop_by_name("key-press-event"); elif event.keyval==GDK_S or event.keyval==269025056 { file_save(filename); tree.emit_stop_by_name("key-press-event"); elif event.keyval==GDK__4 { if selection { tree.expand_to_depth(selection,4); elif event.keyval==GDK_A { file_selector=GtkFileSelection("Choose a file name"); file_selector.set_usize(200,200); file_selector.ok_button.connect("clicked",save_as); file_selector.show_all(); tree.emit_stop_by_name("key-press-event"); */ case GDK_f: case GDK_F: { finding = root; findwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (findwindow), "Find"); finder = gtk_entry_new (); gtk_container_add (GTK_CONTAINER (findwindow), finder); gtk_widget_show (finder); gtk_entry_set_text ((GtkEntry *) finder, currentfindstr); gtk_widget_grab_focus (finder); gtk_grab_add (findwindow); gtk_widget_set_usize (findwindow, 180, 20); gtk_widget_show (findwindow); gtk_signal_connect (GTK_OBJECT (finder), "activate", GTK_SIGNAL_FUNC (find_item), NULL); gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break; } /* case GDK_M: case GDK_m: { modified = 0; message ("Modified status Cleared!"); gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break; } */ case GDK_H: case GDK_h: { if (modified) { message ("File was Modified! (M to clear)"); return; } file_open (homefile); gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break; } case GDK_b: case GDK_B: { if (modified) { message ("File was Modified! (M to clear)"); return; } if (lastfile) { file_open (lastfile); } gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break; } case GDK_space: case 65421: { if (modified) { message ("File was Modified (M to clear)"); return; } if (!selection) return; node = GTK_CTREE_ROW (selection)->children; while (node) { gtk_ctree_get_node_info (GTK_CTREE (tree), node, url, &spacing, &pix_cl, &mask_cl, &pix_op, &mask_op, &is_leaf, &expanded); if (strcasestr (url[0], "url=")) { selection = node; offset = strrchr (url[0], '.'); filename = strchr (url[0], '='); filename++; if (!strcmp (offset, ".opml") || !strcmp (offset, ".OPML")) { filename = joinStr (cwd, filename); file_open (filename); return; } else { if (!strchr (url[0], ':')) { filename = joinStr (cwd, filename); } filename = joinStr ("dillo ", filename); filename = joinStr (filename, " &"); return system (filename); return TRUE; } } if (strcasestr (url[0], "xlink=")) { filename = strchr (url[0], '='); filename++; FollowXlink (copyStr (filename)); return TRUE; break; } node = GTK_CTREE_ROW (node)->sibling; } return FALSE; } /* if (event->keyval == GDK_space) { if selection { tree.toggle_expansion (selection); tree. emit_stop_by_name ("key-press-event");} else { file_selector = GtkFileSelection ("Choose a file name"); file_selector.set_usize (200, 200); file_selector.ok_button. connect ("clicked", open_file); file_selector.cancel_button. connect ("clicked", cancel_file); file_selector.show_all (); break;} if (strcasestr ((char *) url[0], "xlink=")) { return FollowXlink (url + 6); break;} node = GTK_CTREE_ROW (node)->sibling;} gtk_signal_emit_stop_by_name (GTK_OBJECT (tree), "key-press-event"); break;} */ } } static gint my_delete_event (GtkWidget * widget, GdkEventButton * event) { if (modified) { message ("File was Modified!(M to clear)"); return 1; } gtk_exit (0); return 0; } static int __init__XMLTree (char *filename) { PangoFontDescription *f; char *fullfontname=calloc(200,sizeof(char)); tree = gtk_ctree_new (1, 0); gtk_clist_set_selection_mode(GTK_CLIST(tree),GTK_SELECTION_BROWSE); gtk_ctree_set_indent(GTK_CTREE(tree),6); casesensitive = 0; lastdelete = NULL; lastfile = NULL; modified = 0; lastdeletewrapper = NULL; lastfoundroot = NULL; currentfindstr = ""; currentfind = 0; findcount = 1; currentfilename = NULL; /* (cwd,foo)=os.path.split(filename); tree.set_expander_style(CTREE_EXPANDER_CIRCULAR); tree.set_line_style(CTREE_LINES_DOTTED); tree.set_indent(4); tree.set_column_auto_resize(0,1); */ root = NULL; scrolledright = 0; gtk_signal_connect (GTK_OBJECT (tree), "key-press-event", GTK_SIGNAL_FUNC (key_pressed), NULL); gtk_signal_connect (GTK_OBJECT (tree), "button-press-event", GTK_SIGNAL_FUNC (button_pressed), NULL); nodestack[0] = root; topofstack = 0; attrstyle = gtk_style_copy (gtk_widget_get_style (tree)); datastyle = gtk_style_copy (gtk_widget_get_style (tree)); nodestyle = gtk_style_copy (gtk_widget_get_style (tree)); leafstyle = gtk_style_copy (gtk_widget_get_style (tree)); sprintf(fullfontname,"%s bold italic %s",fontname,fontsize); f = pango_font_description_from_string (fullfontname); if (!f) { printf("Font bold italic %s %s not available\n",fontname,fontsize); exit(0); } datastyle->font_desc = f; sprintf(fullfontname,"%s bold %s",fontname,fontsize); f = pango_font_description_from_string (fullfontname); if (!f) { printf("Font bold %s %s not available\n",fontname,fontsize); exit(0); } nodestyle->font_desc = f; sprintf(fullfontname,"%s italic %s",fontname,fontsize); f = pango_font_description_from_string(fullfontname); if (!f) { printf("Font medium italic %s %s not available\n",fontname,fontsize); exit(0); } attrstyle->font_desc = f; sprintf(fullfontname,"%s %s",fontname,fontsize); f = pango_font_description_from_string (fullfontname); if (!f) { printf("Font medium %s %s not available\n",fontname,fontsize); exit(0); } leafstyle->font_desc = f; } int expand_body () { GtkCTreeNode *node; GtkCTreeNode *lastnode = NULL; gtk_ctree_expand (GTK_CTREE (tree), root); node = GTK_CTREE_ROW (root)->children; while (node) { lastnode = node; node = GTK_CTREE_ROW (node)->sibling; } if (lastnode) gtk_ctree_expand (GTK_CTREE (tree), lastnode); } int Highlight (GtkCTreeNode * item, int depth) { GtkCTreeNode *node; char *elttype; node = GTK_CTREE_ROW (item)->children; if (node) { gtk_ctree_node_set_row_style (GTK_CTREE(tree),item, nodestyle); } else { elttype = (char *) gtk_ctree_node_get_row_data (GTK_CTREE (tree), item); if (!strcmp (elttype, "__data")) { gtk_ctree_node_set_row_style (GTK_CTREE (tree), item, datastyle); } else if (!strcmp (elttype, "__att")) { gtk_ctree_node_set_row_style (GTK_CTREE (tree), item, attrstyle); } else { gtk_ctree_node_set_row_style (GTK_CTREE (tree), item, leafstyle); } return; } while (node) { Highlight (node, depth + 1); node = GTK_CTREE_ROW (node)->sibling; } } int file_open (char *loadfilename) { char *path; char *file; path = calloc (strlen (loadfilename), sizeof (char)); file = calloc (strlen (loadfilename), sizeof (char)); lastfile = currentfilename; currentfilename = loadfilename; gtk_clist_freeze (GTK_CLIST (tree)); if (root) { gtk_ctree_remove_node (GTK_CTREE (tree), root); } root = NULL; topofstack = 0; loadtree (loadfilename); expand_body (); Highlight (root, 0); gtk_clist_thaw (GTK_CLIST (tree)); splitpath (loadfilename, path, file); gtk_window_set_title (GTK_WINDOW (topwindow), file); xmlCleanupParser (); xmlMemoryDump (); } int splitpath (char *path, char *path_part, char *file_part) { int i = 0; int last_slash = -1; int length; int path_length, file_length; length = strlen (path); if (length == 0) return 0; for (i = 0; i < length; i++) { if (path[i] == '/') { last_slash = i; } } if (last_slash == -1) { path_length = 0; file_length = length; } else if (last_slash == 0) { path_length = 0; file_length = length - 1; } else if (last_slash == length - 1) { path_length = length - 1; file_length = 0; } else { path_length = last_slash; file_length = length - last_slash - 1; } strncpy (path_part, path, path_length); strncpy (file_part, &path[last_slash + 1], file_length); path_part[path_length] = '\0'; file_part[file_length] = '\0'; return 1; } int main (int argc, char **argv) { int i; int files = 0; char *file; GtkWidget *drawing_area; GtkWidget *button; GtkWidget *sw; if (argc < 2) { fprintf (stdout, "Usage: buzzlite [font size] \n"); return; } if (argc == 2) homefile = copyStr (argv[1]); if (argc > 2) { fontname=copyStr(argv[1]); fontsize=copyStr(argv[2]); homefile = copyStr (argv[3]); } else { #ifdef ARM fontname=copyStr("lucida"); fontsize=copyStr("12"); #endif #ifndef ARM fontname=copyStr("Arial"); fontsize=copyStr("12"); #endif } gtk_init (&argc, &argv); topwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_name (topwindow, "BuzzLite"); #ifdef ARM gtk_widget_set_usize (topwindow, 300, 235); #endif #ifndef ARM gtk_widget_set_usize (topwindow, 500, 500); #endif sw = gtk_scrolled_window_new (NULL, NULL); __init__XMLTree (""); gtk_container_add (GTK_CONTAINER (sw), tree); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); gtk_container_add (GTK_CONTAINER (topwindow), sw); gtk_widget_show (sw); gtk_widget_show (tree); cwd = calloc (strlen (homefile), sizeof (char)); file = calloc (strlen (homefile), sizeof (char)); splitpath (homefile, cwd, file); cwd = joinStr (cwd, "/"); file_open (homefile); gtk_signal_connect (GTK_OBJECT (topwindow), "delete_event", GTK_SIGNAL_FUNC (my_delete_event), NULL); gtk_widget_show (topwindow); gtk_main (); return (0); }