code: def get_kde_home_dir ():
      
      if os.environ.get("KDEHOME"):
          kde_home = os.path.abspath(os.environ["KDEHOME"])
      else:
          home = os.environ.get("HOME")
          if not home:
              # $HOME is not set
              return
          kde3_home = os.path.join(home, ".kde")
          kde4_home = os.path.join(home, ".kde4")
          if fileutil.find_executable("kde4-config"):
              # kde4
              kde3_file = kde_home_to_config(kde3_home)
              kde4_file = kde_home_to_config(kde4_home)
              if os.path.exists(kde4_file) and os.path.exists(kde3_file):
                  if fileutil.get_mtime(kde4_file) >= fileutil.get_mtime(kde3_file):
                      kde_home = kde4_home
                  else:
                      kde_home = kde3_home
              else:
                  kde_home = kde4_home
          else:
              # kde3
              kde_home = kde3_home
      return kde_home if os.path.exists(kde_home) else None
docs: Return KDE home directory or None if not found.