/***************************************************************************
 *   Copyright (C) 2004 by Judd Baileys                                    *
 *   jbaileys@bigpond.net.au                                               *
 *                                                                         *
 *   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 2 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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "configuration.h"
#include <klocale.h>
#include <kconfig.h>
#include <kmessagebox.h>
#include <kapplication.h>
#include <assert.h>
//#include "kdslconfig.h"
//#include "runtests.h"
#include "prefdialog.h"
#include "docking.h"
#include "devices.h"


extern DockWidget *dock_widget;

Configuration gpppdata;

Configuration::Configuration()
  :  config(0L),
     highcount(-1),
     themehighcount(-1),
     taskhighcount(-1),
     cthemeaccount(-1),
     caccount(-1),
     ctaskname( -1),
     suidprocessid(-1),
     pppdisrunning(false),
     pppderror(0)
{
}

//
//open configuration file
//
bool Configuration::open() {

  config = kapp->config();

//sconfig setForceGloba= kapp->config(dirConfig);
  if (config->getConfigState() == KConfig::NoAccess) {
  KMessageBox::error(0L,
                       i18n("The application-specific config file could not "
                       "be opened in either read-write or read-only mode.\n"
                       "The superuser might have to change its ownership "
                       "by issuing the following command in your home directory:\n"
                       "chown {YourUsername} .kde/share/config/kdslrc"),
			 kapp->name());
    return false;
  }

  // don't expand shell variables
  config->setDollarExpansion(false);

  highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1;
  themehighcount = readNumConfig(GENERAL_GRP, NUMTHEMES_KEY, 0) -1;
  taskhighcount = readNumConfig(GENERAL_GRP, NUMTASKS_KEY, 0) -1;
  
  if (highcount > MAX_ACCOUNTS)
    highcount = MAX_ACCOUNTS;

  if (themehighcount > MAX_THEMES)
    themehighcount = MAX_THEMES;
  
  if(highcount >= 0 && defaultAccount().isEmpty()) {
    setAccountbyIndex(0);
    setDefaultAccount(accname());
  } else if(!setAccount(defaultAccount()))
    setDefaultAccount(accname());

  if(themehighcount >= 0 && defaultTheme().isEmpty()) {
    setThemebyIndex(0);
    setDefaultTheme(themename());
  } else if(!setTheme(defaultTheme()))
    setDefaultTheme(themename());
 
  // start out with internal debugging disabled
  // the user is still free to specify `debug' on his own
 // setPPPDebug(false);

 // ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch);

  return true;
}

//
// save configuration
//
void Configuration::save() {

  if (config) {
    writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count());
    writeConfig(GENERAL_GRP, NUMTHEMES_KEY, themecount());
    writeConfig(GENERAL_GRP, NUMTASKS_KEY, taskcount());
//    config->copyTo("/opt/kde/share/config/test");
//    config->setGroup(accname);
    config->sync();
  }

}
//
// cancel changes
//
void Configuration::cancel() {

  if (config) {
    config->rollback();
    config->reparseConfiguration();
  }

}

// currently differentiates between READWRITE and NONE only
int Configuration::access() const {

  return config->getConfigState();
}

// functions to read/write date to configuration file
QString Configuration::readConfig(const QString &group, const QString &key,
                            const QString &defvalue = "")
{
  if (config) {
    config->setGroup(group);
    return config->readEntry(key, defvalue);
  } else
    return defvalue;
}

QColor Configuration::readColorConfig(const QString &group, const QString &key, const QColor *b) {
  if (config) {
    config->setGroup(group);
    return config->readColorEntry(key, b);
  } else
    return *b;

}

int Configuration::readNumConfig(const QString &group, const QString &key,
			   int defvalue) {
  if (config) {
    config->setGroup(group);
    return config->readNumEntry(key, defvalue);
  } else
    return defvalue;

}


bool Configuration::readListConfig(const QString &group, const QString &key,
                             QStringList &list, char sep) {
  list.clear();
  if (config) {
    config->setGroup(group);
    list = config->readListEntry(key, sep);
    return true;
  } else
    return false;
}


void Configuration::writeConfig(const QString &group, const QString &key,
			  const QString &value) {
  if (config) {
    config->setGroup(group);
    config->writeEntry(key, value);
  }
}


void Configuration::writeConfig(const QString &group, const QString &key, int value) {
  if (config) {
    config->setGroup(group);
    config->writeEntry(key, value);
  }
}


void Configuration::writeListConfig(const QString &group, const QString &key,
                              QStringList &list, char sep) {
  if (config) {
    config->setGroup(group);
    config->writeEntry(key, list, sep);
  }
}

void Configuration::writeConfig(const QString &group, const QString &key, const QColor &value) {
   if (config) {
      config->setGroup(group);
      config->writeEntry(key, value);
      }
}

bool Configuration::quit_on_disconnect() {
  return (bool) readNumConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, false);
}


void Configuration::set_quit_on_disconnect(bool set) {
  writeConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, (int) set);
}

bool Configuration::get_show_log_window() {
  return (bool) readNumConfig (GENERAL_GRP, SHOWLOGWIN_KEY, false);
}

void Configuration::set_show_log_window(bool set) {
  writeConfig(GENERAL_GRP, SHOWLOGWIN_KEY, (int) set);
}





//
// functions to set/return general information
//

QString Configuration::password() const {
  return passwd;
}

void Configuration::setPassword(const QString &pw) {
  passwd = pw;
}

const QString Configuration::defaultAccount() {
  return readConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY);
}

const QString Configuration::defaultTheme() {
  return readConfig(GENERAL_GRP, DEFAULTTHEME_KEY);
}

void Configuration::setDefaultAccount(const QString &n) {
  writeConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY, n);

  //now set the current account index to the default account
  setAccount(defaultAccount());
}

void Configuration::setDefaultTheme(const QString &n) {
  writeConfig(GENERAL_GRP, DEFAULTTHEME_KEY, n);
  setTheme(defaultTheme());
}

QString Configuration::pppdVersion() {
  return QString("%1.%2.%3").arg(pppdVer).arg(pppdMod).arg(pppdPatch);
}

bool Configuration::pppdVersionMin(int ver, int mod, int patch) {
  // check if pppd version fulfills minimum requirement
  return (pppdVer > ver
          || (pppdVer == ver && pppdMod > mod)
          || (pppdVer == ver && pppdMod == mod && pppdPatch >= patch));
}

int Configuration::idleTimeout() {
return readNumConfig(cgroup, IDLE_KEY, IDLE_TIMEOUT);
}

void Configuration::setIIdleTimeout(int n) {
  writeConfig(cgroup, IDLE_KEY, n);
  }


int Configuration::pppdTimeout() {
  return readNumConfig(cgroup, PPPDTIMEOUT_KEY, PPPD_TIMEOUT);
}


void Configuration::setpppdTimeout(int n) {
  writeConfig(cgroup, PPPDTIMEOUT_KEY, n);
}

int Configuration::authMethod() {
    return readNumConfig(cgroup, AUTH_KEY, 0);
}

void Configuration::setAuthMethod(int value) {
  writeConfig(cgroup, AUTH_KEY, value);
}

const QString Configuration::command_before_connect() {
  return readConfig(cgroup, BEFORE_CONNECT_KEY);
}


void Configuration::setCommand_before_connect(const QString &n) {
  writeConfig(cgroup, BEFORE_CONNECT_KEY, n);
}

const QString Configuration::command_on_connect() {
  return readConfig(cgroup, COMMAND_KEY);
}


void Configuration::setCommand_on_connect(const QString &n) {
  writeConfig(cgroup, COMMAND_KEY, n);
  }

const QString Configuration::command_on_disconnect() {
  return readConfig(cgroup, DISCONNECT_COMMAND_KEY);
}


void Configuration::setCommand_on_disconnect(const QString &n) {
  writeConfig(cgroup, DISCONNECT_COMMAND_KEY, n);
}


const QString Configuration::command_before_disconnect() {
  return readConfig(cgroup, BEFORE_DISCONNECT_KEY);
}


void Configuration::setCommand_before_disconnect(const QString &n) {
  writeConfig(cgroup, BEFORE_DISCONNECT_KEY, n);
}

const QString Configuration::modemDevice() {
  return readConfig (cgroup, MODEMDEV_KEY);
}


void Configuration::setModemDevice(const QString &n) {
  writeConfig(cgroup, MODEMDEV_KEY, n);
}

const QString Configuration::flowControl() {
  return readConfig (cgroup, FLOWCONTROL_KEY);
}

void Configuration::setFlowControl(const QString &n) {
  writeConfig(cgroup, FLOWCONTROL_KEY, n);
}

const QString Configuration::speedControl() {
  return readConfig (cgroup, STORED_SPEEDCONTROL_KEY);
}

void Configuration::setSpeedControl(const QString &n) {
  writeConfig (cgroup, STORED_SPEEDCONTROL_KEY, n);
}

//
// functions to set/return account information
//

//returns number of accounts
int Configuration::count() const {
  return highcount + 1;
}

int Configuration::themecount() const {
  return themehighcount +1;
}

bool Configuration::setTheme(const QString & tname) {
  for(int i = 0; i <= themehighcount; i++) {
    setThemebyIndex(i);
    if(themename() == tname) {
      cthemeaccount = i;

      return true;
    }
  }
  return false;
}

int Configuration::taskcount() const {
  return taskhighcount +1;
}

bool Configuration::setTask(const QString & taname) {
   for(int i = 0; i <= taskhighcount; i++) {
     setTaskbyIndex(i);
     if(taskname() == taname) {
       ctaskname = i;
       
       return true;
     }
   }
   return false;
}

bool Configuration::setAccount(const QString &aname) {
  for(int i = 0; i <= highcount; i++) {
    setAccountbyIndex(i);
    if(accname() == aname) {
      caccount = i;
      return true;
    }
  }
  return false;
}

bool Configuration::setThemebyIndex(int i) {
  if(i >=0 && i <= themehighcount) {
    cthemeaccount = i;
    tgroup.sprintf("%s%i", THEME_GRP, i);
    return true;
  }
  return false;
}

bool Configuration::setTaskbyIndex(int i) {
  if(i >=0 && i <= taskhighcount) {
  ctaskname = i;
  tagroup.sprintf("%s%i", TASK_GRP, i);
  return true;
 }
 return false;
}

bool Configuration::setAccountbyIndex(int i) {
  if(i >= 0 && i <= highcount) {
    caccount = i;
    cgroup.sprintf("%s%i", ACCOUNT_GRP, i);
    return true;
  }
  return false;
}

bool Configuration::isUniqueThemename(const QString &n) {
  int current = cthemeaccount;
  for(int i=0; i <= themehighcount; i++) {
    setThemebyIndex(i);
    if(themename() == n && i != current) {
      setThemebyIndex(current);
      return false;
    }
  }
  setThemebyIndex(current);
  return true;
}

bool Configuration::isUniqueAccname(const QString &n) {
  int current = caccount;
  for(int i=0; i <= highcount; i++) {
    setAccountbyIndex(i);
    if(accname() == n && i != current) {
      setAccountbyIndex(current);
      return false;
    }
  }
  setAccountbyIndex(current);
  return true;
}

bool Configuration::deleteTheme() {
  if(cthemeaccount < 0)
    return false;

  QMap <QString, QString> map;
  QMap <QString, QString>::Iterator it;

  // set all entries of the current account to ""
  map = config->entryMap(tgroup);
  it = map.begin();
  while (it != map.end()) {
    config->writeEntry(it.key(), "");
    it++;
  }

  // shift the succeeding accounts
  for(int i = cthemeaccount+1; i <= themehighcount; i++) {
    setThemebyIndex(i);
    map = config->entryMap(tgroup);
    it = map.begin();
    setThemebyIndex(i-1);
    config->setGroup(tgroup);
    while (it != map.end()) {
      config->writeEntry(it.key(), *it);
      it++;
    }
  }

  // make sure the top account is cleared
  setThemebyIndex(themehighcount);
  map = config->entryMap(tgroup);
  it = map.begin();
  config->setGroup(tgroup);
  while (it.key() != QString::null) {
    config->writeEntry(it.key(), "");
    it++;
  }

  themehighcount--;
  if(cthemeaccount > themehighcount)
    cthemeaccount = themehighcount;

  setThemebyIndex(cthemeaccount);

  return true;
}

bool Configuration::deleteTask() {
  if(ctaskname < 0)
    return false;

  QMap <QString, QString> map;
  QMap <QString, QString>::Iterator it;

  // set all entries of the current account to ""
  map = config->entryMap(tagroup);
  it = map.begin();
  while (it != map.end()) {
    config->writeEntry(it.key(), "");
    it++;
  }

  // shift the succeeding accounts
  for(int i = ctaskname+1; i <= taskhighcount; i++) {
    setTaskbyIndex(i);
    map = config->entryMap(tagroup);
    it = map.begin();
    setTaskbyIndex(i-1);
    config->setGroup(tagroup);
    while (it != map.end()) {
      config->writeEntry(it.key(), *it);
      it++;
    }
  }

  // make sure the top account is cleared
  setTaskbyIndex(taskhighcount);
  map = config->entryMap(tagroup);
  it = map.begin();
  config->setGroup(tagroup);
  while (it.key() != QString::null) {
    config->writeEntry(it.key(), "");
    it++;
  }

  taskhighcount--;
  if(ctaskname > taskhighcount)
    ctaskname = taskhighcount;

  setTaskbyIndex(ctaskname);

  return true;
}

bool Configuration::deleteAccount() {
  if(caccount < 0)
    return false;

  QMap <QString, QString> map;
  QMap <QString, QString>::Iterator it;

  // set all entries of the current account to ""
  map = config->entryMap(cgroup);
  it = map.begin();
  while (it != map.end()) {
    config->writeEntry(it.key(), "");
    it++;

  }

  // shift the succeeding accounts
  for(int i = caccount+1; i <= highcount; i++) {
    setAccountbyIndex(i);
    map = config->entryMap(cgroup);
    it = map.begin();
    setAccountbyIndex(i-1);
    config->setGroup(cgroup);
    while (it != map.end()) {
      config->writeEntry(it.key(), *it);
      it++;
    }
  }

  // make sure the top account is cleared
  setAccountbyIndex(highcount);
  map = config->entryMap(cgroup);
  it = map.begin();
  config->setGroup(cgroup);
  while (it.key() != QString::null) {
    config->writeEntry(it.key(), "");
    it++;
  }

  highcount--;
  if(caccount > highcount)
    caccount = highcount;

  setAccountbyIndex(caccount);

  return true;
}

bool Configuration::deleteTheme(const QString &tname) {
  if(!setTheme(tname))
    return false;

    deleteTheme();

    return true;
}

bool Configuration::deleteTask(const QString & taname) {
   if(!setTask(taname))
      return false;
      
      deleteTask();
      
      return true;
}

bool Configuration::deleteAccount(const QString &aname) {
  if(!setAccount(aname))
    return false;

  deleteAccount();
  //  QFile deleteacc;
    QFile deleteacc("/etc/ppp/kdsl/Accounts/"+aname);
    deleteacc.remove();
  return true;
}

int Configuration::newtheme() {

  if(!config || themehighcount >=MAX_THEMES)
    return -1;

    themehighcount++;
    setThemebyIndex(themehighcount);

    return cthemeaccount;
}

int Configuration::newtask() {
   taskhighcount++;
   setTaskbyIndex(taskhighcount);
   
   return ctaskname;
}

int Configuration::newaccount() {

  if(!config || highcount >= MAX_ACCOUNTS)
    return -1;

  highcount++;
  setAccountbyIndex(highcount);

 // setpppdArgumentDefaults();

  return caccount;
}

int Configuration::copyaccount(int i) {

  if(highcount >= MAX_ACCOUNTS)
    return -1;

  setAccountbyIndex(i);

  QMap <QString, QString> map = config->entryMap(cgroup);
  QMap <QString, QString>::ConstIterator it = map.begin();

  QString newname = i18n("%1_copy").arg(accname());

  newaccount();

  while (it != map.end()) {
    config->writeEntry(it.key(), *it);
    it++;
  }

  setAccname(newname);

  return caccount;
}

const QString Configuration::themename() {
  return readConfig(tgroup, ICON_NAME_KEY);
}

void Configuration::setThemename(const QString &n) {
  if(!tgroup.isNull()) {
    bool def = themename() == defaultTheme();
    writeConfig(tgroup, ICON_NAME_KEY, n);
    if (def)
      setDefaultTheme(n);
    }
}


const QString Configuration::taskname() {
   return readConfig(tagroup, TASK_NAME_KEY);
}

void Configuration::setTaskname(const QString &n) {
   if(!tagroup.isNull()) 
      writeConfig(tagroup, TASK_NAME_KEY, n);
}

const QString Configuration::accname() {
  return readConfig(cgroup, NAME_KEY);
}

void Configuration::setAccname(const QString &n) {
  if(!cgroup.isNull()) {
    // are we manipulating the default account's name ? then change it, too.
    bool def = accname() == defaultAccount();
    writeConfig(cgroup, NAME_KEY, n);
    if (def)
      setDefaultAccount(n);
  }
}
  
  const QString Configuration::accountIconName() {
   return readConfig(cgroup, ACCOUNT_ICON_KEY,"");
   }
   
   void Configuration::setAccountIconName(const QString &b) {
     writeConfig(cgroup, ACCOUNT_ICON_KEY,b);
     }

const QString Configuration::storedTaskStartTime() {
   return readConfig(tagroup, TASK_START_TIME_KEY, "");
   }
   
 void Configuration::setStoredTaskStartTime(const QString &b) {
   writeConfig(tagroup, TASK_START_TIME_KEY,b);
   }
   
const QString Configuration::storedTaskStartDate() {
   return readConfig(tagroup, TASK_START_DATE_KEY, "");
   }
   
  void Configuration::setStoredTaskStartDate(const QString &b) {
    writeConfig(tagroup, TASK_START_DATE_KEY,b);
    }
    
const QString Configuration::storedTaskEndTime() {
   return readConfig(tagroup, TASK_END_TIME_KEY, "");
   }
   
 void Configuration::setStoredTaskEndTime(const QString &b) {
   writeConfig(tagroup, TASK_END_TIME_KEY,b);
   }
   
const QString Configuration::storedTaskEndDate() {
   return readConfig(tagroup, TASK_END_DATE_KEY, "");
   }
   
  void Configuration::setStoredTaskEndDate(const QString &b) {
    writeConfig(tagroup, TASK_END_DATE_KEY,b);     
  }
 
 const QString Configuration::storedTaskFrequency() {
   return readConfig(tagroup, TASK_FREQUENCY_KEY, "");
   }
   
   void Configuration::setStoredTaskFrequency(const QString &b) {
    writeConfig(tagroup, TASK_FREQUENCY_KEY, b);
    }
     
const QString  Configuration::pluginname() {
   return readConfig(GENERAL_GRP, PLUGIN_KEY, "");
   }

void Configuration:: setPluginName(const QString &b) {
   writeConfig(GENERAL_GRP, PLUGIN_KEY,b);
   }
  
 const QString Configuration::browserURL() {
   return readConfig(cgroup, BROWSER_KEY, "");
   }  
   
 void Configuration::setBrowserURL(const QString &b) {
   writeConfig(cgroup, BROWSER_KEY,b);
   }  
   
  bool Configuration::storeBrowserUsage() {
  return (bool)readNumConfig(cgroup, USE_BROWSER_KEY, 1);
}  

void Configuration::setStoreNotifyColors(bool b) {
   writeConfig(GENERAL_GRP, USE_COLORS_KEY, (int)b);
}

bool Configuration::storeNotifyColors() {
  return (bool)readNumConfig(GENERAL_GRP, USE_COLORS_KEY, 1);
  }
  
const QString Configuration::notifyBgColor(){
   return readConfig(GENERAL_GRP, BACKGROUND_COLOR_KEY, "");
}

// void Configuration::setNotifyBgColor(int a, int b, int c) {
//    writeConfig(GENERAL_GRP, BACKGROUND_COLOR_KEY, (int)a,(int) b, (int)c);
//   }

void Configuration::setNotifyBgColor(QColor &b) {
   writeConfig(GENERAL_GRP, BACKGROUND_COLOR_KEY,b);
   }

  
//  const QColor notifyTextColor();
//  void setNotifyTextColor(const QColor *);   
   
void Configuration::setLockModem(bool b) {
  writeConfig(cgroup, LOCK_MODEM_KEY, (int)b);
}

bool Configuration::lockModem() {
  return (bool)readNumConfig(cgroup, LOCK_MODEM_KEY, 1);
}

void Configuration::setStoreBrowserUsage(bool b) {
writeConfig(cgroup, USE_BROWSER_KEY, (int)b);
}

const QString Configuration::protocol() {
   return readConfig(cgroup, PROTOCOL_KEY, "");
}

void Configuration::setProtocol(const QString &b) {
   writeConfig(cgroup, PROTOCOL_KEY,b);
   }

const QString Configuration::phoneNumber() {
   return readConfig(cgroup, PHONE_NUMBER_KEY, "");
}   

void Configuration::setPhoneNumber(const QString &b) {
   writeConfig(cgroup, PHONE_NUMBER_KEY,b);
   }   
   
const QString Configuration::usageURL() {
   return readConfig(cgroup, STORED_USAGE_KEY, "");
   }

void Configuration::setUsageURL(const QString &b) {
   writeConfig(cgroup, STORED_USAGE_KEY,b);
   }
   
const QString Configuration::autoStartTime() {
   return readConfig(GENERAL_GRP, AUTO_START_TIME_KEY, "");
   }
   
void Configuration::setAutoStartTime(const QString &b) {
   writeConfig(GENERAL_GRP, AUTO_START_TIME_KEY,b);
   }
   
const QString Configuration::autoStopTime() {
   return readConfig(GENERAL_GRP, AUTO_STOP_TIME_KEY, "");
   }
   
void Configuration::setAutoStopTime(const QString &b) {
   writeConfig(GENERAL_GRP, AUTO_STOP_TIME_KEY,b);
   }
    
 bool Configuration::storeUsage() {
  return (bool)readNumConfig(cgroup, STORE_USAGE_KEY, 1);
}

void Configuration::setStoreUsage(bool b) {
writeConfig(cgroup, STORE_USAGE_KEY, (int)b);
}
   
bool  Configuration::storeScheduler() {
  return (bool)readNumConfig(GENERAL_GRP, USE_SCHEDULER_KEY, 1);
  }
  
void Configuration::setStoreScheduler(bool b) {
  writeConfig(GENERAL_GRP, USE_SCHEDULER_KEY, (int)b);
}

bool Configuration::storeAutoStartScheduler() {
  return (bool)readNumConfig(GENERAL_GRP, AUTO_START_KEY, 1);
  }
  
void Configuration::setStoreAutoStartScheduler(bool b) {
  writeConfig(GENERAL_GRP, AUTO_START_KEY, (int)b);
}

bool Configuration::storeAutoStopScheduler() {
  return (bool)readNumConfig(GENERAL_GRP, AUTO_STOP_KEY, 1);
  }
  
void Configuration::setStoreAutoStopScheduler(bool b) {
  writeConfig(GENERAL_GRP, AUTO_STOP_KEY, (int)b);
}



     int Configuration::pos_x(){
   return readNumConfig(GENERAL_GRP, POS_X_KEY, POS_X_VALUE);
   }
   
void Configuration::setPos_x(int b) {
   writeConfig(GENERAL_GRP, POS_X_KEY, b);
   }
   
  int Configuration::pos_y(){
   return readNumConfig(GENERAL_GRP, POS_Y_KEY, POS_Y_VALUE);
   }
   
void Configuration::setPos_y(int b) {
   writeConfig(GENERAL_GRP, POS_Y_KEY,b);
   }  

bool Configuration::storeUsePlugin() {
  return (bool)readNumConfig(cgroup, USE_PLUGIN_KEY, 1);
}

void Configuration::setStoreUsePlugin(bool b) {
  writeConfig(cgroup, USE_PLUGIN_KEY, (int)b);
}
   
  bool Configuration::storeConnect() {
  return (bool)readNumConfig(GENERAL_GRP, CONNECT_KEY, 1);
}

void Configuration::setStoreConnect(bool b) {
  writeConfig(GENERAL_GRP, CONNECT_KEY, (int)b);
}

  void Configuration::setStoreEnableSound(bool b) {
  writeConfig(GENERAL_GRP, SOUND_KEY, (int)b);
  }

  bool Configuration::storeEnableSound() {
  return (bool)readNumConfig(GENERAL_GRP, SOUND_KEY, 1);
  }

  void Configuration::setStoreDefaultRoute(bool b) {
    writeConfig(cgroup,DEFAULTROUTE_KEY, (int)b);
  }
  
  bool Configuration::storeDefaultRoute() {
    return (bool)readNumConfig(cgroup, DEFAULTROUTE_KEY, 1);
  }
  
  void Configuration::setStoreClock(bool b) {
  writeConfig(GENERAL_GRP, CLOCK_KEY, (int)b);
  }

  bool Configuration::storeClock() {
  return (bool)readNumConfig(GENERAL_GRP, CLOCK_KEY, 1);
  }  
  
  void Configuration::set_usb(bool b) {
  writeConfig(GENERAL_GRP,USB_KEY, (int)b);
  }
  
  bool Configuration::get_usb() {
  return (bool)readNumConfig(GENERAL_GRP, USB_KEY, 1);
  }
  
   void Configuration::setStoreEnableNotify(bool b) {
  writeConfig(GENERAL_GRP, NOTIFY_KEY, (int)b);
  }

  bool Configuration::storeEnableNotify() {
  return (bool)readNumConfig(GENERAL_GRP, NOTIFY_KEY, 1);
  }
  
  void Configuration::setStoreEnableRoot(bool b) {
  writeConfig(cgroup,ALLOW_ROOT_KEY,(int)b);
  }
  
  bool Configuration::storeEnableRoot(){
  return (bool)readNumConfig(cgroup, ALLOW_ROOT_KEY, 1);
  }
  
const QString  Configuration::storedUsername() {
  return readConfig(cgroup, STORED_USERNAME_KEY, "");
}

void Configuration::setStoredUsername(const QString &b) {
  writeConfig(cgroup, STORED_USERNAME_KEY, b);
}

const QString  Configuration::storedEthDevice() {
  return readConfig(cgroup, STORED_ETH_DEVICE_KEY, "");
}

void Configuration::setStoredEthDevice(const QString &b) {
  writeConfig(cgroup, STORED_ETH_DEVICE_KEY, b);
}

const QString Configuration::storedModemVolume() {
  return readConfig(cgroup, MODEMVOL_KEY,"");
  }
  
void Configuration::setStoredModemVolume(const QString &b) {
  writeConfig(cgroup, MODEMVOL_KEY,b);
  }

const QString Configuration::storedAccType() {
  return readConfig(cgroup, STORED_ACC_TYPE_KEY, "");
}

void Configuration::setStoredAccType(const QString &b) {
  writeConfig(cgroup, STORED_ACC_TYPE_KEY, b);
}

const QString  Configuration::storedPassword() {
  return readConfig(cgroup, STORED_PASSWORD_KEY, "");
}

void Configuration::setStoredPassword(const QString &b) {
  writeConfig(cgroup, STORED_PASSWORD_KEY, b);
}

bool Configuration::storePassword() {
  return (bool)readNumConfig(cgroup, STORE_PASSWORD_KEY, 1);
}

void Configuration::setStorePassword(bool b) {
  writeConfig(cgroup, STORE_PASSWORD_KEY, (int)b);
}

const QString Configuration::ipaddr() {
  return readConfig(cgroup, IPADDR_KEY);
}


void Configuration::setIpaddr(const QString &n) {
  writeConfig(cgroup, IPADDR_KEY, n);
}

bool Configuration::autoDNS() {
  return (bool) readNumConfig(cgroup, AUTODNS_KEY, 1);
//  return (set && gpppdata.pppdVersionMin(2, 3, 7));
}

void Configuration::setAutoDNS(bool set) {
  writeConfig(cgroup, AUTODNS_KEY, (int) set);
}

QStringList &Configuration::dns() {
  static QStringList dnslist;

  readListConfig(cgroup, DNS_KEY, dnslist);
  while(dnslist.count() > MAX_DNS_ENTRIES)
    dnslist.remove(dnslist.last());

  return dnslist;
}

void Configuration::setDns(QStringList &list) {
  writeListConfig(cgroup, DNS_KEY, list);
}

//
//functions to change/set the child pppd process info
//
bool Configuration::storeAutostart() {
  return (bool)readNumConfig(GENERAL_GRP, AUTOSTART_KEY, 1);
}

void Configuration::setStoreAutostart(bool b) {
  writeConfig(GENERAL_GRP, AUTOSTART_KEY, (int)b);
}


bool Configuration::storeHideIP() {
  return (bool)readNumConfig(GENERAL_GRP, HIDE_IP_KEY, 1);
}

void Configuration::setStoreHideIP(bool b) {
  writeConfig(GENERAL_GRP, HIDE_IP_KEY, (int)b);
}

bool Configuration::pppdRunning() const {
  return pppdisrunning;
}

void Configuration::setpppdRunning(bool set) {
  pppdisrunning = set;
}

int Configuration::pppdError() const {
  return pppderror;
}

void Configuration::setpppdError(int err) {
  pppderror = err;
}

int Configuration::pppdErrorMsg() {
  return pppderrormsg;
}

void Configuration::setpppdErrorMsg(int err) {
  pppderrormsg = err;
}

void Configuration::winPosStatWin(int& p_x, int& p_y) {
  p_x = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_X, QApplication::desktop()->width()/2-160);
  p_y = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_Y, QApplication::desktop()->height()/2-55);
}

void Configuration::setWinPosStatWin(int p_x, int p_y) {
  writeConfig(WINPOS_GRP, WINPOS_STATWIN_X, p_x);
  writeConfig(WINPOS_GRP, WINPOS_STATWIN_Y, p_y);
}
