[gnome-love] need help!!!



Hi, list

I am adding a new menu item to the "Nautilus" menu.
When the menu item
is activated, a dialog window is supposed to pop up.
The dialog has one label
and one entry. The user is required to enter certain
search word into the text entry. Then the Nautilus
window
is supposed to display the search result of certain 
search engine with these words as key words.(ie, the
URL of the html page should be something like 
"http://www.google.com//search?hl=en&ie=UTF8
&btnG=Google+Search&q=textEntry".


I have successfully created the menu item and dialog
window. But whenever I enter one word
(I only try one word) into the text entry and click
OK, then the whole Nautilus window disappears.
But if I only have sentence
"nautilus_window_go_web_search (window);" in
"if(result==0)" block, it works well. 
There maybe some translation from user-typed URI to
formatted URI. But how? I list my code(is added into
nautilus-window-menu.c) 
and useful functions(extract from nautilus-window.c)
below. 
I feel so frustrated on this problem. I am appreciated
if someone can 
help me with it. Thanks...


__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com


/*------------------my code--------------------------------*/
/*-------- following is the callback to the new menu item --*/
/* -------it is added into 'nautilus-window-menu.c'-------- */

static void
mycode_customize_callback (BonoboUIComponent *component, 
                               gpointer user_data, 
                               const char *verb)
{
        NautilusWindow *window;
        GtkWidget *dialog;
        GtkWidget *label;
        GtkWidget *entry;
        /* string displayed on label */
        const gchar str[50]="Enter your search keyword:"; 

        /*this is the button number of dialog*/
        int result;  

        window = NAUTILUS_WINDOW (user_data);
                

        /* create dialog */
        dialog = gnome_dialog_new("Entry dialog",
                                  GNOME_STOCK_BUTTON_OK,
                                  GNOME_STOCK_BUTTON_CANCEL,
                                  NULL);

        /* create and add label into dialog*/
        label = gtk_label_new (str);
        gtk_widget_show (label);
        gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),
                           label,
                           FALSE,FALSE,0);

        /* create and add entry  into dialog*/
        entry = gtk_entry_new ();
        gtk_widget_show (entry);
        gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),
                           entry,
                           FALSE,FALSE,0);

        /*set feature to dialog and show it */
        gnome_dialog_set_close(GNOME_DIALOG(dialog),TRUE);  
        gtk_widget_show(dialog);

        /*  run the dialog in modal mode */
        result = gnome_dialog_run(GNOME_DIALOG(dialog));

        /* when ok button in dialog is clicked, ie result=0 */

        if(result == 0) {
        
                /*if only have this sentence in this block. it works well */
                /* nautilus_window_go_web_search (window);  */
        


                gchar *search_web_uri;

                /*set to switchable navigation to location mode*/
                nautilus_window_set_search_mode (window, FALSE); 

                /*get customrized search engine from preference*/
                search_web_uri = eel_preferences_get 
                        (NAUTILUS_PREFERENCES_SEARCH_WEB_URI);

                /*attach search word to form whole URL*/
/* I have tried without these two strcat() sentences. the system works well
But with these two sentences, the Nautilus window will disappear. */
        
                strcat(search_web_uri,"/search?hl=en&ie=UTF-8&btnG=Google+Search&q=");
                strcat(search_web_uri,gtk_entry_get_text(GTK_ENTRY(entry)));


                g_assert (search_web_uri != NULL);
        
                nautilus_window_go_to (window, search_web_uri); 


                g_free (search_web_uri); 


        }
}

/*------------functions in nautilus-window.c ----------------*/

void
nautilus_window_go_to (NautilusWindow *window, const char *uri)
{
        nautilus_window_open_location (window, uri);
}


void
nautilus_window_set_search_mode (NautilusWindow *window,
                                 gboolean search_mode)
{
        nautilus_switchable_navigation_bar_set_mode
                (NAUTILUS_SWITCHABLE_NAVIGATION_BAR (window->navigation_bar),
                 search_mode
                 ? NAUTILUS_SWITCHABLE_NAVIGATION_BAR_MODE_SEARCH
                 : NAUTILUS_SWITCHABLE_NAVIGATION_BAR_MODE_LOCATION);

        
}

void
nautilus_window_go_web_search (NautilusWindow *window)
{
        char *search_web_uri;

        nautilus_window_set_search_mode (window, FALSE);

        search_web_uri = eel_preferences_get 
(NAUTILUS_PREFERENCES_SEARCH_WEB_URI);
        g_assert (search_web_uri != NULL);
        
        nautilus_window_go_to (window, search_web_uri);
        g_free (search_web_uri);
}

/*-----------------------the end------------------------*/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]