Logo Search packages:      
Sourcecode: wallpaper-tray version File versions  Download package

bool Wallpapers::SetRandom ( bool  _bImediate  ) 

Set a random wallpaper from the user configured directories.

<Wallpapers::SetRandom>

Parameters:
_bImediate Whether or not the change should wait for user confirmation.
Date:
12-06-2006 GAF Written

Definition at line 96 of file Wallpapers.cc.

References CountDirectoryEntries(), CountStatics(), GetDirectoryEntryAtIndex(), and GetStaticAtIndex().

Referenced by DeleteCurrent(), and SetRandomDelayed().

{
      std::size_t nFileCount(0);
      std::size_t nStaticCount(0);

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

      for(std::list<Glib::ustring>::iterator it = lsWpDir.begin(); it != lsWpDir.end(); ++ it)
      {
            // recurse each path to count wallpapers
            Wallpapers::CountDirectoryEntries(it->c_str(), nFileCount);
      }// end for

      nStaticCount = Wallpapers::CountStatics();

      if(nFileCount == 0 && nStaticCount == 0)
      {
            return false;
      }// end if

      // get random image index
      std::size_t nRandomIndex = (std::rand() % (nFileCount + nStaticCount)) + 1;

      if(nRandomIndex <= nFileCount)
      {
            for(std::list<Glib::ustring>::iterator it = lsWpDir.begin(); it != lsWpDir.end(); ++ it)
            {
                  // recurse each path to get random wallpaper
                  Wallpapers::GetDirectoryEntryAtIndex(it->c_str(), nRandomIndex, m_szFile);
            }// end for
      }// end if
      else
      {
            m_szFile = Wallpapers::GetStaticAtIndex(nRandomIndex % nStaticCount);
      }// end else

      // set new in gconf
      if(m_szFile.length() > 0)
      {
            m_pApplet->RenderThumbnail(m_szFile);

            if(_bImediate == true || m_pGconfClient->get_bool("/apps/wp_tray/b_notifications") == false)
            {
                  m_pGconfClient->set("/desktop/gnome/background/picture_filename", m_szFile);

                  m_pApplet->SetThumbnailOnPanel();
            }// end if
            else
            {
                  m_Notify.WallpaperChanged(m_szFile);
            }// end else
      }// end if
      
      return true;
}// end Wallpapers::set_random


Generated by  Doxygen 1.6.0   Back to index