/*******************************************************************************
*                         Goggles Music Manager                                *
********************************************************************************
*           Copyright (C) 2006-2010 by Sander Jansen. All Rights Reserved      *
*                               ---                                            *
* This program is free software: you can redistribute it and/or modify         *
* it under the terms of the GNU General Public License as published by         *
* the Free Software Foundation, either version 3 of the License, or            *
* (at your option) any later version.                                          *
*                                                                              *
* This program is distributed in the hope that it will be useful,              *
* but WITHOUT ANY WARRANTY; without even the implied warranty of               *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                *
* GNU General Public License for more details.                                 *
*                                                                              *
* You should have received a copy of the GNU General Public License            *
* along with this program.  If not, see http://www.gnu.org/licenses.           *
********************************************************************************/
#include "gmdefs.h"
#include "gmutils.h"
#include "GMIconTheme.h"
#include "GMApp.h"
#include "icons.h"

#include <FXPNGImage.h>
#include <FXPNGIcon.h>
#include <FXJPGImage.h>
#include <FXJPGIcon.h>

#define SMALL_SIZE 16
#define MEDIUM_SIZE 22
#define LARGE_SIZE 48

/// We need this to allow reading ini files with long lines.
class GMSettings : public FXSettings {
  FXDECLARE(GMSettings)
#if FOXVERSION < FXVERSION(1,7,0)
public:
  FXbool parseFile(const FXString & filename,FXbool mark);
#endif
  };


FXIMPLEMENT(GMSettings,FXSettings,NULL,0);

#if FOXVERSION < FXVERSION(1,7,0)
// Parse filename
FXbool GMSettings::parseFile(const FXString& filename,FXbool mrk){
  FXFile file(filename,FXIO::Reading);
  if(file.isOpen()){

    // Prepare buffer string
    FXString string('\0',file.size());

    // Load file
    if(file.readBlock((void*)string.text(),string.length())==string.length()){
      FXStringDict *group=NULL;
      FXint lineno=1,p=0,b,e;
      FXString name;
      FXString value;

      // Skip BOM, if any
      if(string[p]=='\xef' && string[p+1]=='\xbb' && string[p+2]=='\xbf') p+=3;

      // Parse one line at a time
      while(string[p]){

        // Skip leading blanks
        while(Ascii::isBlank(string[p])) p++;

        // Non-comment
        if(string[p] && string[p]!='\n' && string[p]!='\r' && string[p]!='#' && string[p]!=';'){

          // Parse section name
          if(string[p]=='['){

            b=++p;

            // Scan section name
            while(string[p] && string[p]!=']' && string[p]!='\n' && string[p]!='\r' && !Ascii::isControl(string[p])) p++;

            // Check errors
            if(string[p]!=']'){ fxwarning("%s:%d: illegal section name.\n",filename.text(),lineno); goto next; }

            e=p++;

            // Grab name
            name=string.mid(b,e-b);

            // Add new section dict
            group=insert(name.text());
            }

          // Parse name-value pair
          else{

            // Should have seen section prior to this
            if(!group){ fxwarning("%s:%d: settings entry should follow a section.\n",filename.text(),lineno); goto next; }

            b=p;

            // Scan key name
            while(string[p] && string[p]!='=' && string[p]!='\n' && string[p]!='\r' && !Ascii::isControl(string[p])) p++;

            // Check errors
            if(string[p]!='='){ fxwarning("%s:%d: expected '=' to follow key.\n",filename.text(),lineno); goto next; }

            e=p++;

            // Remove trailing spaces after name
            while(b<e && Ascii::isBlank(string[e-1])) e--;

            // Grab name
            name=string.mid(b,e-b);

            // Skip leading spaces
            while(Ascii::isBlank(string[p])) p++;

            // Mark value
            b=p;

            // Scan value
            while(string[p] && string[p]!='\n' && string[p]!='\r' && !Ascii::isControl(string[p])) p++;

            e=p;

            // Remove trailing spaces after value
            while(b<e && Ascii::isBlank(string[e-1])) e--;

            // Grab the unescaped value
            value=dequote((FXchar*)string.mid(b,e-b).text());

            // Add entry to current section
            group->replace(name.text(),value.text(),mrk);
            }
          }

        // Skip to end of line
next:   while(string[p] && string[p]!='\n') p++;

        // End of line
        if(string[p]=='\n'){
          lineno++;
          p++;
          }
        }
      return true;
      }
    }
  return false;
  }
#endif





void GMIconSet::save(FXStream & store) {
  store << (FXint)medium.no();
  for (FXint i=0;i<medium.no();i++) {
    store << medium[i];
    }
  store << (FXint)small.no();
  for (FXint i=0;i<small.no();i++) {
    store << small[i];
    }
  store << (FXint)large.no();
  for (FXint i=0;i<large.no();i++) {
    store << large[i];
    }
  store << name;
  store << dir;
  store << mediumsize;
  store << smallsize;
  store << largesize;
  }


void GMIconSet::load(FXStream & store) {
  FXint n;

  store >> n;
  medium.no(n);
  for (FXint i=0;i<medium.no();i++) {
    store >> medium[i];
    }

  store >> n;
  small.no(n);
  for (FXint i=0;i<small.no();i++) {
    store >> small[i];
    }

  store >> n;
  large.no(n);
  for (FXint i=0;i<large.no();i++) {
    store >> large[i];
    }

  store >> name;
  store >> dir;
  store >> mediumsize;
  store >> smallsize;
  store >> largesize;
  }



void gm_set_application_icon(FXWindow * window) {
  FXPNGImage * image = new FXPNGImage(FXApp::instance(),x32_apps_musicmanager_png,0,0);
  ewmh_set_window_icon(window,image);
  delete image;
  }



static const FXuint CACHE_FILE_VERSION = 20100420;
static const FXchar CACHE_FILE_NAME[]  = PATHSEPSTRING "icontheme.cache";

void GMIconTheme::save_cache() {
  FXString theme_dir          = app->reg().readStringEntry("user-interface","icon-theme-dir",DEFAULT_ICON_PATH);
  FXuint   cache_file_version = CACHE_FILE_VERSION;

  FXFileStream store;
  if (store.open(GMApp::getCacheDirectory(true)+CACHE_FILE_NAME,FXStreamSave)) {
    store << cache_file_version;
    store << theme_dir;
    store << (FXint)iconsets.no();
    for (FXint i=0;i<iconsets.no();i++) {
      iconsets[i].save(store);
      }
    }
 }


FXbool GMIconTheme::load_cache() {
  FXString theme_dir = app->reg().readStringEntry("user-interface","icon-theme-dir",DEFAULT_ICON_PATH);
  FXString cache_file = GMApp::getCacheDirectory()+CACHE_FILE_NAME;
  FXString cache_dir;
  FXint n;
  FXuint cache_file_version;
  FXTime theme_dir_date=FXStat::modified(theme_dir);
  FXTime cache_dir_date=FXStat::modified(cache_file);

  FXFileStream store;

  if (theme_dir_date==0 || cache_dir_date==0 || theme_dir_date>cache_dir_date)
    return false;

  if (store.open(GMApp::getCacheDirectory()+PATHSEPSTRING+"icontheme.cache",FXStreamLoad)) {

    store >> cache_file_version;
    if (cache_file_version!=CACHE_FILE_VERSION)
      return false;

    store >> cache_dir;

    if (theme_dir!=cache_dir)
      return false;

    store >> n;
    iconsets.no(n);
    for (FXint i=0;i<iconsets.no();i++){
      iconsets[i].load(store);
      }
    return true;
    }




  return false;
  }


#if 0
static debug_iconsets(const GMIconSetList & iconsets){
  for (FXint i=0;i<iconsets.no();i++){
    fxmessage("----------------------------------------------\n");
    fxmessage("Set %d\n",i);
    fxmessage("\tname: %s\n",iconsets[i].name.text());
    fxmessage("\tdir: %s\n",iconsets[i].dir.text());
    fxmessage("\tSmall: %d\n",iconsets[i].smallsize);
    for (FXint j=0;j<iconsets[i].small.no();j++){
      fxmessage("\t\t%s\n",iconsets[i].small[j].text());
      }
    fxmessage("\tMedium: %d\n",iconsets[i].mediumsize);
    for (FXint j=0;j<iconsets[i].medium.no();j++){
      fxmessage("\t\t%s\n",iconsets[i].medium[j].text());
      }
    fxmessage("\tLarge: %d\n",iconsets[i].largesize);
    for (FXint j=0;j<iconsets[i].large.no();j++){
      fxmessage("\t\t%s\n",iconsets[i].large[j].text());
      }
    }
  }
#endif


GMIconTheme * GMIconTheme::me=NULL;

GMIconTheme::GMIconTheme(FXApp * application) : app(application), set(-1) {
  FXASSERT(me==NULL);
  me=this;

  cursor_hand=new FXGIFCursor(app,cursor_hand_gif,5,0);
  cursor_hand->create();

  const FXchar * theme = app->reg().readStringEntry("user-interface","icon-theme","Tango");
  if (!load_cache()) {
    listThemes();
    save_cache();
    }

  if (theme) {
    for (FXint i=0;i<iconsets.no();i++){
      if (compare(iconsets[i].dir,theme)==0) {
        set=i;
        break;
        }
      }
    }
  if (set==-1 && iconsets.no())
    setCurrentTheme(0);
  }


GMIconTheme::~GMIconTheme() {
  }

GMIconTheme * GMIconTheme::instance(){
  return me;
  }

void GMIconTheme::listThemes() {
  FXString root           = app->reg().readStringEntry("user-interface","icon-theme-dir",DEFAULT_ICON_PATH);
  FXint    desired_small  = app->reg().readIntEntry("user-interface","icon-theme-small-size",SMALL_SIZE);
  FXint    desired_medium = app->reg().readIntEntry("user-interface","icon-theme-big-size",MEDIUM_SIZE);
  FXint    desired_large  = app->reg().readIntEntry("user-interface","icon-theme-large-size",LARGE_SIZE);

  FXString * subdirs=NULL;
  FXint s;
  FXString base;
  FXString themedir;
  FXString themesubdirs;
  FXString subdir;
  FXString list;
  GMSettings * settings=NULL;
  FXDict ts;

  FXint size,threshold;
  const FXchar * sizetype;

  FXint current,set;
  FXint minsize,maxsize;
  FXint smallsize;
  FXint mediumsize;
  FXint largesize;

  FXint no = FXDir::listFiles(subdirs,root,"*",FXDir::AllDirs|FXDir::NoParent|FXDir::NoFiles);
  if (no) {

    settings=new GMSettings[no];

    for (FXint i=0;i<no;i++) {
      settings[i].parseFile(root+PATHSEPSTRING+subdirs[i]+PATHSEPSTRING+"index.theme",true);
      ts.insert(subdirs[i].text(),(void*)(FXival)(i+1));
      }

    for (FXint i=0;i<no;i++) {
      if (FXStat::isLink(root+PATHSEPSTRING+subdirs[i])) continue;
      if (settings[i].readBoolEntry("Icon Theme","Hidden",false)) continue;


      smallsize=desired_small;
      mediumsize=desired_medium;
      largesize=desired_large;

      FXint min_small_dist=1000;
      FXint min_medium_dist=1000;
      FXint min_large_dist=1000;

      themesubdirs = settings[i].readStringEntry("Icon Theme","Directories",NULL);
      if (themesubdirs.empty()) continue;

      minsize=-1;maxsize=-1;
      for (s=0;;s++){
        subdir = themesubdirs.section(',',s);
        if (subdir.empty()) break;

        sizetype = settings[i].readStringEntry(subdir.text(),"Type","Threshold");
        if (comparecase(sizetype,"scalable")==0)
          continue;

        size = settings[i].readIntEntry(subdir.text(),"Size",0);

        if (size<minsize || minsize<0) minsize=size;
        if (size>maxsize || maxsize<0) maxsize=size;
        if (comparecase(sizetype,"fixed")==0) {
          if (FXABS(desired_small-size)<min_small_dist){
            min_small_dist = FXABS(desired_small-size);
            smallsize=size;
            }
          if (FXABS(desired_medium-size)<min_medium_dist){
            min_medium_dist = FXABS(desired_medium-size);
            mediumsize=size;
            }
          if (FXABS(desired_large-size)<min_large_dist){
            min_large_dist = FXABS(desired_large-size);
            largesize=size;
            }
          }
        }

      if (minsize<=0 || maxsize<=0) continue;

      current=iconsets.no();
      iconsets.no(current+1);
      iconsets[current].name      = settings[i].readStringEntry("Icon Theme","Name",subdirs[i].text());
      iconsets[current].inherits.insert(iconsets[current].name.text(),(void*)(FXival)1,true);
      iconsets[current].largesize   = largesize;
      iconsets[current].mediumsize  = mediumsize;
      iconsets[current].smallsize   = smallsize;
      iconsets[current].dir         = subdirs[i];

      set=i;
      do {
        /// Add subdirectories
        for (s=0;;s++){
          subdir = themesubdirs.section(',',s);
          if (subdir.empty()) break;

          /// Type of Icons in directory
          sizetype  = settings[set].readStringEntry(subdir.text(),"Type","Threshold");
          if (comparecase(sizetype,"scalable")==0)
            continue;

          size = settings[set].readIntEntry(subdir.text(),"Size",0);

          if (comparecase(sizetype,"fixed")==0 || comparecase(sizetype,"scalable")==0) {
            if (size==smallsize)
              iconsets[current].small.append(root+PATHSEPSTRING+subdirs[set]+PATHSEPSTRING+subdir);
            else if (size==mediumsize)
              iconsets[current].medium.append(root+PATHSEPSTRING+subdirs[set]+PATHSEPSTRING+subdir);
            else if (size==largesize)
              iconsets[current].large.append(root+PATHSEPSTRING+subdirs[set]+PATHSEPSTRING+subdir);
            }
          else {
            threshold = settings[set].readIntEntry(subdir.text(),"Threshold",2);
            if (FXABS(smallsize-size)<=threshold)
              iconsets[current].small.append(root+PATHSEPSTRING+subdirs[set]+PATHSEPSTRING+subdir);
            else if (FXABS(mediumsize-size)<=threshold)
              iconsets[current].medium.append(root+PATHSEPSTRING+subdirs[set]+PATHSEPSTRING+subdir);
            else if (FXABS(largesize-size)<=threshold)
              iconsets[current].large.append(root+PATHSEPSTRING+subdirs[set]+PATHSEPSTRING+subdir);
            }
          }

        list = settings[set].readStringEntry("Icon Theme","Inherits",NULL);
        if (list.empty()) break;

        for (s=0,set=-1;set<0;s++) {

          /// Get Icon Set Name
          base = list.section(',',s);

          /// Check for empty or duplicate set
          if (base.empty() ||  iconsets[current].inherits.find(base.text()) )
            break;

          set = (FXint)(FXival)ts.find(base.text());
          set-=1;
          }

        if (set>=0) {
          themesubdirs = settings[set].readStringEntry("Icon Theme","Directories",NULL);
          if (themesubdirs.empty()) break;
          iconsets[current].inherits.insert(base.text(),(void*)(FXival)1);
          }
        }
      while (set>=0);
      }
    delete [] settings;
    delete [] subdirs;
    }
  }


FXint GMIconTheme::getSmallSize() const {
  if (set>=0 && iconsets.no())
    return iconsets[set].smallsize;
  else
    return SMALL_SIZE;
  }

FXint GMIconTheme::getMediumSize() const {
  if (set>=0 && iconsets.no())
    return iconsets[set].mediumsize;
  else
    return MEDIUM_SIZE;
  }

FXint GMIconTheme::getLargeSize() const {
  if (set>=0 && iconsets.no())
    return iconsets[set].mediumsize;
  else
    return LARGE_SIZE;
  }


FXImage * GMIconTheme::loadImage(const FXString & filename) {
  FXImage * img=NULL;
  const FXString ext = FXPath::extension(filename);
  FXFileStream store;
  if(store.open(filename,FXStreamLoad,65536)){
    if(comparecase(FXPNGImage::fileExt,ext)==0){
      img=new FXPNGImage(app);
      }
    else if(comparecase(FXJPGImage::fileExt,ext)==0 || comparecase("jpeg",ext)==0){
      img=new FXJPGImage(app);
      }
    else if(comparecase(FXBMPIcon::fileExt,ext)==0){
      img=new FXBMPImage(app);
      }
    else if(comparecase(FXGIFIcon::fileExt,ext)==0){
      img=new FXGIFImage(app);
      }
    else {
      img=NULL;
      }
    if(img){
      if(img->loadPixels(store)) return img;
      delete img;
      img=NULL;
      }
    }
  return NULL;
  }


FXIcon * GMIconTheme::loadIcon(const FXString & filename) {
  FXIcon * icon=NULL;
  const FXString ext = FXPath::extension(filename);
  FXFileStream store;
  if(store.open(filename,FXStreamLoad,65536)){
    if(comparecase(FXPNGImage::fileExt,ext)==0){
      icon=new FXPNGIcon(app);
      }
    else if(comparecase(FXJPGImage::fileExt,ext)==0 || comparecase("jpeg",ext)==0){
      icon=new FXJPGIcon(app);
      }
    else if(comparecase(FXBMPIcon::fileExt,ext)==0){
      icon=new FXBMPIcon(app);
      }
    else if(comparecase(FXGIFIcon::fileExt,ext)==0){
      icon=new FXGIFIcon(app);
      }
    else if(comparecase(FXICOIcon::fileExt,ext)==0 || comparecase("cur",ext)==0){
      icon=new FXICOIcon(app);
      }
    else {
      icon=NULL;
      }
    if(icon){
      icon->setOptions(IMAGE_SHMI|IMAGE_SHMP);
      if(icon->loadPixels(store)) return icon;
      delete icon;
      icon=NULL;
      }
    }
  return NULL;
  }



void GMIconTheme::loadIcon(FXIconPtr & icon,const FXStringList & pathlist,FXint size,const FXchar * value,const FXColor blendcolor) {
  FXIcon * ic=NULL;
  if (pathlist.no()) {
    for (FXint i=0;(ic==NULL) && (i<pathlist.no());i++) {
      ic=loadIcon(pathlist[i]+PATHSEPSTRING+value);
      }
    }

  if (ic==NULL)
    ic = new FXIcon(app,NULL,0,IMAGE_OWNED,size,size);

  if (icon) {
    icon->destroy();
    icon->setData(ic->getData(),ic->getOptions(),ic->getWidth(),ic->getHeight());
    FXImageOwner::clear(ic);
    delete ic;
    }
  else {
    icon=ic;
    }

  icon->blend(blendcolor);
  FXIconThreshold::set(icon);
  icon->create();
  }

void GMIconTheme::loadSmall(FXIconPtr & icon,const FXchar * value,const FXColor blendcolor){
  if (iconsets.no())
    loadIcon(icon,iconsets[set].small,iconsets[set].smallsize,value,blendcolor);
  else
    loadIcon(icon,0,SMALL_SIZE,value,blendcolor);
  }

void GMIconTheme::loadMedium(FXIconPtr & icon,const FXchar * value,const FXColor blendcolor){
  if (iconsets.no())
    loadIcon(icon,iconsets[set].medium,iconsets[set].mediumsize,value,blendcolor);
  else
    loadIcon(icon,0,MEDIUM_SIZE,value,blendcolor);
  }

void GMIconTheme::loadLarge(FXIconPtr & icon,const FXchar * value,const FXColor blendcolor){
  if (iconsets.no())
    loadIcon(icon,iconsets[set].large,iconsets[set].largesize,value,blendcolor);
  else
    loadIcon(icon,0,LARGE_SIZE,value,blendcolor);
  }

void GMIconTheme::loadResource(FXIconPtr & icon,const unsigned char * data,const char * type) {
  FXIconSource source(app);
  FXIcon * newicon = source.loadIconData(data,type);
  FXASSERT(newicon);
  if (icon) {
    icon->destroy();
    icon->setData(newicon->getData(),newicon->getOptions(),newicon->getWidth(),newicon->getHeight());
    FXImageOwner::clear(newicon);
    delete newicon;
    }
  else {
    icon=newicon;
    }
  }

/*
FXImage* GMIconTheme::loadLarge(const char * value) {
  FXImage * image = NULL;
  if (iconsets.no()) {
    FXASSERT(set>=0 && set<iconsets.no());
    for (FXint i=0;i<iconsets[set].large.no() && image==NULL;i++) {
      image = source.loadImageFile(iconsets[set].large[i]+PATHSEPSTRING+value);
      }
    }
  return image;
  }
*/

FXImage* GMIconTheme::loadMedium(const char * value) {
  FXImage * image = NULL;
  if (iconsets.no()) {
    for (FXint i=0;i<iconsets[set].medium.no() && (image==NULL);i++) {
      image = loadImage(iconsets[set].medium[i]+PATHSEPSTRING+value);
      }
    }
  return image;
  }



  /*

FXImage* GMIconTheme::loadSmall(const char * value,FXint & size) {
  FXImage * image = NULL;
  if (iconsets.no()) {
    FXASSERT(set>=0 && set<iconsets.no());
    for (FXint i=0;i<iconsets[set].small.no() && image==NULL;i++) {
      size = iconsets[set].smallsize;
      image = source.loadImageFile(iconsets[set].small[i]+PATHSEPSTRING+value);
      }
    }
  return image;
  }
*/


void GMIconTheme::load() {
  const FXColor basecolor = app->getBaseColor();
  const FXColor backcolor = app->getBackColor();

  loadSmall(icon_copy,"edit-copy.png",basecolor);
  loadSmall(icon_cut,"edit-cut.png",basecolor);
  loadSmall(icon_paste,"edit-paste.png",basecolor);
  loadSmall(icon_delete,"edit-delete.png",basecolor);
  loadSmall(icon_undo,"edit-undo.png",basecolor);
  loadSmall(icon_play,"media-playback-start.png",basecolor);
  loadSmall(icon_pause,"media-playback-pause.png",basecolor);
  loadSmall(icon_next,"media-skip-forward.png",basecolor);
  loadSmall(icon_prev,"media-skip-backward.png",basecolor);
  loadSmall(icon_stop,"media-playback-stop.png",basecolor);

  loadSmall(icon_import,"folder.png",basecolor);
  loadSmall(icon_importfile,"document-open.png",basecolor);
  loadSmall(icon_exit,"exit.png",basecolor);
  loadSmall(icon_close,"window-close.png",basecolor);
  loadSmall(icon_find,"edit-find.png",basecolor);
  loadSmall(icon_sync,"view-refresh.png",basecolor);
  loadSmall(icon_album,"media-optical.png",basecolor);
  loadSmall(icon_artist,"system-users.png",basecolor);
  loadSmall(icon_genre,"bookmark-new.png",basecolor);
  loadSmall(icon_export,"document-save.png",basecolor);
  loadSmall(icon_homepage,"applications-internet.png",basecolor);
  loadSmall(icon_info,"help-browser.png",basecolor);

  loadSmall(icon_fullscreen,"window-fullscreen.png",backcolor);


  loadMedium(icon_source_library,"user-home.png",backcolor);
  loadMedium(icon_source_internetradio,"applications-internet.png",backcolor);
  loadMedium(icon_source_playlist,"user-bookmarks.png",backcolor);

  loadSmall(icon_playlist,"user-bookmarks.png",basecolor);
  loadSmall(icon_settings,"preferences-desktop.png",basecolor);
  loadSmall(icon_edit,"accessories-text-editor.png",basecolor);
  loadSmall(icon_sort,"view-sort-descending.png",basecolor);

  loadResource(icon_applogo,x32_apps_musicmanager_png,"png");
  loadResource(icon_applogo_small,x16_apps_musicmanager_png,"png");

  loadLarge(icon_nocover,"media-optical.png",backcolor);

  loadMedium(icon_audio_volume_high,"audio-volume-high.png",basecolor);
  loadMedium(icon_audio_volume_medium,"audio-volume-medium.png",basecolor);
  loadMedium(icon_audio_volume_low,"audio-volume-low.png",basecolor);
  loadMedium(icon_audio_volume_muted,"audio-volume-muted.png",basecolor);
  loadMedium(icon_play_toolbar,"media-playback-start.png",basecolor);
  loadMedium(icon_pause_toolbar,"media-playback-pause.png",basecolor);
  loadMedium(icon_next_toolbar,"media-skip-forward.png",basecolor);
  loadMedium(icon_prev_toolbar,"media-skip-backward.png",basecolor);
  loadMedium(icon_stop_toolbar,"media-playback-stop.png",basecolor);


  icon_applogo->blend(basecolor);
  icon_applogo_small->blend(basecolor);
  icon_applogo->create();
  icon_applogo_small->create();
  }


FXint GMIconTheme::getNumThemes() const{
  return iconsets.no();
  }

void GMIconTheme::setCurrentTheme(FXint s) {
  set=s;
  if (set>=0 && iconsets.no())
    app->reg().writeStringEntry("user-interface","icon-theme",iconsets[set].dir.text());
  else
    app->reg().writeStringEntry("user-interface","icon-theme","");
  }

FXint GMIconTheme::getCurrentTheme() const {
  return set;
  }

FXString GMIconTheme::getThemeName(FXint i){
  FXASSERT(i>=0 && i<iconsets.no());
  return iconsets[i].name;
  }




