can anyone help me with this code? the bottom two callbacks never fire,
and i have no idea why. i can see the keys change in gconf-editor, its
mighty weird.

here's the code ...

//
/// file:       wallpapers.cc
/// author:     earthworm
/// date:       Sunday, 12 June 2005
/// about:      manage wallpaper collection with boost filesystem
//

// includes //
//
#include <iostream>
#include <cstdlib>
#include "wallpapers.hh"

// definitions //
//
c_wallpapers::c_wallpapers                              ()
{
        // set up the gconf client
        m_ref_gconf_client = Gnome::Conf::Client::get_default_client();

        // seed random number generator
        std::srand(std::time(NULL));

        m_b_follow_symlink      =
m_ref_gconf_client->get_bool("/apps/wp_tray/b_follow_links");
        m_b_image_check         =
m_ref_gconf_client->get_bool("/apps/wp_tray/b_img_check");

        m_regex_image_check = ".jpg|.jpeg|.png|.gif|.bmp|.tiff";

        // set a random wallpaper if we have been told to at logon
        if(m_ref_gconf_client->get_bool("/apps/wp_tray/b_wp_logon") == true)
        {
                c_wallpapers::set_random();
        }// end if

        // create wallpaper change timeout
        if(m_ref_gconf_client->get_bool("/apps/wp_tray/b_timeout") == true)
        {
                // set the wallpaper timeout
                m_sigc_connection =
Glib::signal_timeout().connect(sigc::mem_fun(*this,
&c_wallpapers::set_random), 100000 *
m_ref_gconf_client->get_int("/apps/wp_tray/n_timeout"));
        }// end if

        // listen to changes to our keys
        m_ref_gconf_client->notify_add( "/apps/wp_tray/b_timeout",
                                        sigc::mem_fun(*this, 
&c_wallpapers::regenerate_timeout));
        m_ref_gconf_client->notify_add( "/apps/wp_tray/n_timeout",
                                        sigc::mem_fun(*this, 
&c_wallpapers::regenerate_timeout));

        m_ref_gconf_client->notify_add( "/apps/wp_tray/b_follow_links",
                                        sigc::mem_fun(*this, 
&c_wallpapers::on_follow_symlink_changed));
        m_ref_gconf_client->notify_add( "/apps/wp_tray/b_img_check",
                                        sigc::mem_fun(*this, 
&c_wallpapers::on_image_check_changed));
}// end c_wallpapers::c_wallpapers

c_wallpapers::~c_wallpapers                             ()
{
}// end c_wallpapers::~c_wallpapers

bool
c_wallpapers::set_random                                ()
{
        std::size_t                                     n_file_count(0);
        Glib::ustring                                   sz_file;

        // grab all the directories
        std::list<Glib::ustring> ls_wp_dir =
m_ref_gconf_client->get_string_list("/apps/wp_tray/dir_list");

        for(std::list<Glib::ustring>::iterator it = ls_wp_dir.begin(); it !=
ls_wp_dir.end(); ++ it)
        {
                // recurse each path to count wallpapers
                c_wallpapers::count_directory_entries(it->c_str(), 
n_file_count);
        }// end for

        if(n_file_count == 0)
        {
                return false;
        }// end if

        // get random image index
        n_file_count = (std::rand() % n_file_count) + 1;

        for(std::list<Glib::ustring>::iterator it = ls_wp_dir.begin(); it !=
ls_wp_dir.end(); ++ it)
        {
                // recurse each path to get random wallpaper
                c_wallpapers::get_directory_entry_at_index(it->c_str(), 
n_file_count,
sz_file);
        }// end for

        // set new in gconf
        if(sz_file.length() > 0)
                
m_ref_gconf_client->set("/desktop/gnome/background/picture_filename",
sz_file);
        
        return true;
}// end c_wallpapers::set_random

Glib::ustring
c_wallpapers::get_current                               ()
{
        return
m_ref_gconf_client->get_string("/desktop/gnome/background/picture_filename");
}// end c_wallpapers::get_current

bool
c_wallpapers::delete_curret                             ()
{
        bool b_result(fs::remove(fs::path(c_wallpapers::get_current())));

        c_wallpapers::set_random();

        return b_result;
}// end c_wallpapers::delete_curret

std::size_t
c_wallpapers::count_directory_entries                   (fs::path               
                path_current,
                                                         std::size_t            
                & n_file_count)
{
        fs::directory_iterator end_iter;

        for(fs::directory_iterator dir_itr(path_current); dir_itr != end_iter;
++ dir_itr)
        {
                try
                {
                        if(fs::is_directory(*dir_itr))
                        {
                                if(fs::symbolic_link_exists(*dir_itr))
                                {
                                        if(m_b_follow_symlink == true)
                                        {
                                                // recurse
                                                
c_wallpapers::count_directory_entries(*dir_itr, n_file_count);
                                        }// end if
                                }// end if
                                else
                                {
                                        // recurse
                                        
c_wallpapers::count_directory_entries(*dir_itr, n_file_count);
                                }// end else
                        }// end if
                        else
                        {
                                if(!m_b_image_check || 
boost::regex_match(dir_itr->leaf(),
m_regex_image_check))
                                        ++ n_file_count;
                        }// end else
                }// end try
                catch(const std::exception & ex)
                {
                        std::cerr << 
"c_wallpapers::count_entries_in_directory() : " <<
dir_itr->leaf() << " " << ex.what() << std::endl;
                }// end catch
        }// end for

        return n_file_count;
}// end c_wallpapers::count_directory_entries

void
c_wallpapers::get_directory_entry_at_index              (fs::path               
                path_current,
                                                         std::size_t            
                & n_file_index,
                                                         Glib::ustring          
                & sz_file)
{
        fs::directory_iterator end_iter;

        if(n_file_index == 0)
        {
                return;
        }// end if

        for(fs::directory_iterator dir_itr(path_current); dir_itr != end_iter
&& n_file_index != 0; ++ dir_itr)
        {
                try
                {
                        if(fs::is_directory(*dir_itr))
                        {
                                if(fs::symbolic_link_exists(*dir_itr))
                                {
                                        if(m_b_follow_symlink == true)
                                        {
                                                // recurse
                                                
c_wallpapers::get_directory_entry_at_index(*dir_itr, n_file_index,
sz_file);
                                        }// end if
                                }// end if
                                else
                                {
                                        // recurse
                                        
c_wallpapers::get_directory_entry_at_index(*dir_itr, n_file_index,
sz_file);
                                }// end else
                        }// end if
                        else
                        {
                                if(!m_b_image_check || 
boost::regex_match(dir_itr->leaf(),
m_regex_image_check))
                                {
                                        if(-- n_file_index == 0)
                                        {
                                                sz_file = 
(*dir_itr).native_directory_string();
                                        }// end if
                                }// end if
                        }// end else
                }// end try
                catch(const std::exception & ex)
                {
                        std::cerr << 
"c_wallpapers::count_entries_in_directory() : " <<
dir_itr->leaf() << " " << ex.what() << std::endl;
                }// end catch
        }// end for
}// end c_wallpapers::get_directory_entry_at_index

void
c_wallpapers::regenerate_timeout                        (guint                  
                n_cnxn,
                                                         Gnome::Conf::Entry     
                gconf_entry)
{
        // delete old timeout!
        m_sigc_connection.disconnect();

        // (re)create wallpaper change timeout
        if(m_ref_gconf_client->get_bool("/apps/wp_tray/b_timeout") == true)
        {
                // set the wallpaper timeout
                m_sigc_connection =
Glib::signal_timeout().connect(sigc::mem_fun(*this,
&c_wallpapers::set_random), 100000 *
m_ref_gconf_client->get_int("/apps/wp_tray/n_timeout"));
        }// end if
}// end c_wallpapers::regenerate_timeout

void
c_wallpapers::on_follow_symlink_changed                 (guint                  
                n_cnxn,
                                                         Gnome::Conf::Entry     
                gconf_entry)
{
        m_b_follow_symlink =
m_ref_gconf_client->get_bool("/apps/wp_tray/b_follow_links");
}// end c_wallpapers::on_follow_symlink_changed

void
c_wallpapers::on_image_check_changed                    (guint                  
                n_cnxn,
                                                         Gnome::Conf::Entry     
                gconf_entry)
{
        m_b_image_check =
m_ref_gconf_client->get_bool("/apps/wp_tray/b_img_check");
}// end c_wallpapers::on_image_check_changed


_______________________________________________
gnomemm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gnomemm-list

Reply via email to