Re: RecentManager



2012-10-31 17:20, g4hx skrev:
On 10/31/2012 04:50 PM, Kjell Ahlstedt wrote:
RecentManager::get_default() gets a RecentManager where all programs can
save recently used files. Usually it's not empty. Word processors, text
editors and all kinds of programs may have saved names of recently used
files there. The information is saved in a file, on my PC in file
~/.local/share/recently-used.xbel. I don't think there's any guarantee
that your newly saved file name will be the first one in the vector that
RecentManager::get_items() returns, but it should be somewhere in that
vector.

I'm don't know why you don't find your file name in a FileChooserDialog.
Do you use a filter that hides it? Have you looked through the whole
list of files in the dialog, and not just the first few entries?

Kjell

2012-10-31 14:51, g4hx skrev:
Hello all,

I am trying to include a RecentManager in my program but so far I am
utterly failing to do it. I have the following code to add a file
obtained by a FileChooserDialog to the recent files list:

    Glib::RefPtr<RecentManager> mgr = RecentManager::get_default();

    if(!mgr->add_item(dialog.get_uri()))
      g_warning("Could not add item to recent files");

If I understand correctly, then a subsequent statement of the type

    g_warning("%s", mgr->get_items()[0]->get_uri().raw().c_str());

should return the URI that I passed to the RecentManager. Only this
is not the case, instead the warning prints another file to the
terminal. Also the file does not show up in any FileChooserDialog.
What am I doing wrong?

g4hx


Well, I have a filter in all my dialogs which permits only xml files.
I removed the recently-used.xbel. After that the call to mgr->get_items
results in a SEGFAULT, since there are no entries at all.

How can I set up a RecentManager for my application only?

g4hx

Gtk::RecentManager::add_item() calls the gtk+ function gtk_recent_manager_add_item(). That function always returns true, and does most of its job asynchronosly, meaning that when the function returns, its job has probably not been finished. If you call get_items() immediately after add_item(), the newly added item might not be included in the returned vector. It's much safer to connect to signal_changed() and call get_items() in your signal handler.

The documentation does not mention that add_item() works asynchonously, neither the documentation in gtk+ nor in gtkmm.

To set up a RecentManager for your application only, you need to create your own RecentManager, i.e. call Gtk::RecentManager::create() instead of get_default(). You must set a filename, where your RecentManager shall save its information, or else it will use the default file that most other programs use. BUT, that does not seem to be possible, using Gtk::RecentManager. There is a property_filename(), but it's read-only. The property 'filename' in the gtk+ class GtkRecentManager is construct-only, meaning it can only be given a value when the object is constructed. I think something is missing in gtkmm. Gtk::RecentManager::create() should have a 'filename' parameter.

Kjell


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