Thread: GTK noob

  1. #1
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    101

    GTK noob

    Hi,

    I am trying to add "recent files" feature to a GTK project. I get the file name correctly but afterwards things do not go on as expected. It the following code , I am working to get first file name so that later I take more and show it File menu , Recent opened files. See:

    Code:
    // Global variables for making implementation easy for now:
    GtkRecentManager recent_files;
    GList gl[21];
    Code:
    // in main() I have:
    /* set up GTK */
        gtk_init (&argc, &argv);
    
    #include "gtk/xboard.h"
        recent_files=*gtk_recent_manager_new(); 
        gtk_recent_manager_set_limit(&recent_files,9);
    Code:
    // After opening a file with GTK_FILE_CHOOSER :
    
        // some code
        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
        // some code
        gboolean added= gtk_recent_manager_add_item (&recent_files, filename); // file uri
        added ? DisplayMessage("Recent ADDED","") : DisplayError("Recent Not Added",1); 
        show_message_dialog(filename); // This shows correct filename
        show_message_dialog("XB1");
    
        gl[0]=*gtk_recent_manager_get_items(&recent_files);
        show_message_dialog("XB2");
        GtkRecentInfo *info=&gl[0]; // cast (GtkRecentInfo *)
        if(info == NULL)
        show_message_dialog("NULL info");
        const gchar * recent_file_name=gtk_recent_info_get_uri(info);
        show_message_dialog(recent_file_name); // shows garbage 
        DisplayNote("Load finished");
        gtk_recent_info_unref (info);
        // some code
    Code:
    // Show dialog function:
    
    void show_message_dialog(const char * const message)
    {
        GtkWidget*  dialog = gtk_message_dialog_new (mainwindow,
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                         GTK_MESSAGE_ERROR,
                                         GTK_BUTTONS_CLOSE,
                                         "Message: %s",
                                         message);
    
        /* Destroy the dialog when the user responds to it (e.g. clicks a button) */
        g_signal_connect_swapped (dialog, "response",
                                  G_CALLBACK (gtk_widget_destroy),
                                  dialog);
        gtk_widget_show_all (dialog);
        return;
    }
    Can you help me overcome this ? A GTK 2 link is here:
    GtkRecentManager

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,064
    Why not like this?
    Code:
    GtkRecentManager *recent_files;
    ///
        recent_files = gtk_recent_manager_new(); 
        gtk_recent_manager_set_limit(recent_files,9);
    > GList gl[21];
    This is wrong as well.
    TBH, read the manual pages again.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help because i am a noob!
    By FruixX in forum C++ Programming
    Replies: 11
    Last Post: 04-26-2013, 01:04 PM
  2. Only a noob would ask this...
    By gratiafide in forum C Programming
    Replies: 31
    Last Post: 12-04-2012, 03:39 AM
  3. noob
    By valthyx in forum C Programming
    Replies: 3
    Last Post: 07-21-2008, 02:23 PM
  4. noob help if /else
    By joker_tony in forum C Programming
    Replies: 2
    Last Post: 03-21-2008, 04:53 PM
  5. Noob needs some help
    By Tubby87 in forum C++ Programming
    Replies: 3
    Last Post: 03-06-2008, 05:11 AM

Tags for this Thread