/***************************************************************************
                          dcoptions.cpp  -  description
                             -------------------
    begin                : Sun Feb 24 2002
    copyright            : (C) 2002 by Mathias Küster
    email                : mathen@users.berlios.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <qdir.h>
#include <qdialog.h>
#include <qlineedit.h>
#include <QTextEdit>
#include <qcombobox.h>
#include <QListWidget>
#include <qslider.h>
#include <qtabwidget.h>
#include <qcheckbox.h>
#include <qradiobutton.h>
#include <qpushbutton.h>
#include <QFileDialog>
#include <qlabel.h>
#include <qmessagebox.h>
#include <qspinbox.h>
#include <qstylefactory.h>
#include <qapplication.h>
#include <qinputdialog.h>
#include <qfontdialog.h>
#include <qlayout.h>
#include <qcolordialog.h>
#include <qtoolbutton.h>
#include <qimage.h>
#include <qcursor.h>
#include <qtextcodec.h>
//Added by qt3to4:
#include <QPixmap>
#include <QProcess>
#include <QHeaderView>

#include <dclib/core/cstring.h>
#include <dclib/core/csocket.h>
#include <dclib/core/cdir.h>
#include <dclib/cconfig.h>
#include <dclib/cfilemanager.h>

#include "dcmenuhandler.h"
#include "dciconloader.h"
#include "dctransferview.h"

#include "DCDialogEditSharePath.h"

#include "dcoptions.h"

#include <dclib/dcos.h>
#include <dclib/cutils.h>
#include <math.h>

/* need VERSION for HTTP User-Agent */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/** */
DCOptions::DCOptions() : QDialog()
{
	setupUi(this);
	
	// set default icon
	setIcon( g_pIconLoader->GetPixmap(eiCONFIGURE) );

	InitDocument();
}

/** */
DCOptions::~DCOptions()
{
}

/** */
void DCOptions::InitDocument()
{
	// insert speed
	ComboBox_SPEED->insertItem( "28.8Kbps" );
	ComboBox_SPEED->insertItem( "33.6Kbps" );
	ComboBox_SPEED->insertItem( "56Kbps" );
	ComboBox_SPEED->insertItem( "Modem" );
	ComboBox_SPEED->insertItem( "Satellite" );
	ComboBox_SPEED->insertItem( "ISDN" );
	ComboBox_SPEED->insertItem( "DSL" );
	ComboBox_SPEED->insertItem( "Cable" );
	ComboBox_SPEED->insertItem( "LAN(T1)" );
	ComboBox_SPEED->insertItem( "LAN(T3)" );
	ComboBox_SPEED->insertItem( "Microwave" );
	ComboBox_SPEED->insertItem( "Wireless" );
	ComboBox_SPEED->insertItem( "0.005" );
	ComboBox_SPEED->insertItem( "0.01" );
	ComboBox_SPEED->insertItem( "0.02" );
	ComboBox_SPEED->insertItem( "0.05" );
	ComboBox_SPEED->insertItem( "0.1" );
	ComboBox_SPEED->insertItem( "0.2" );
	ComboBox_SPEED->insertItem( "0.5" );
	ComboBox_SPEED->insertItem( "1" );
	ComboBox_SPEED->insertItem( "2" );
	ComboBox_SPEED->insertItem( "5" );
	ComboBox_SPEED->insertItem( "10" );
	ComboBox_SPEED->insertItem( "20" );
	ComboBox_SPEED->insertItem( "50" );
	ComboBox_SPEED->insertItem( "100" );
	
	ComboBox_REMOTE_ENCODING->insertItem("None");
	ComboBox_REMOTE_ENCODING->insertItem("UTF-8");
	ComboBox_REMOTE_ENCODING->insertItem("WINDOWS-1252");
	ComboBox_REMOTE_ENCODING->insertItem("WINDOWS-1251");
	ComboBox_REMOTE_ENCODING->insertItem("WINDOWS-1256");
	ComboBox_REMOTE_ENCODING->insertItem("WINDOWS-1257");
	ComboBox_REMOTE_ENCODING->insertItem("ISO-8859-1");
	ComboBox_REMOTE_ENCODING->insertItem("ISO-8859-2");
	ComboBox_REMOTE_ENCODING->insertItem("ISO-8859-7");
	ComboBox_REMOTE_ENCODING->insertItem("ISO-8859-8");
	ComboBox_REMOTE_ENCODING->insertItem("ISO-8859-9");
	ComboBox_REMOTE_ENCODING->insertItem("ISO-2022-JP");
	ComboBox_REMOTE_ENCODING->insertItem("SHIFT-JIS");
	ComboBox_REMOTE_ENCODING->insertItem("CP949");
	ComboBox_REMOTE_ENCODING->insertItem("KOI8-R");
	ComboBox_REMOTE_ENCODING->insertItem("GB18030");
	ComboBox_REMOTE_ENCODING->insertItem("TIS-620");
	
	// set width mode
	// QT3 ListView_OPTIONTREE->setColumnWidthMode( 0, Q3ListView::Maximum );
	// hide the column header
	TreeWidget_OPTIONTREE->header()->hide();
	// disable sort
	TreeWidget_OPTIONTREE->setSortingEnabled(FALSE);

	// setup spin boxes
	SpinBox_MAXUPLOADRATE->setMinimum(0.0);
	SpinBox_MAXUPLOADRATE->setMaximum(99999999.0);
	SpinBox_MAXUPLOADRATE->setDecimals(1);
	SpinBox_MAXUPLOADRATE->setSingleStep(0.1);
	SpinBox_MAXDOWNLOADRATE->setMinimum(0.0);
	SpinBox_MAXDOWNLOADRATE->setMaximum(99999999.0);
	SpinBox_MAXDOWNLOADRATE->setDecimals(1);
	SpinBox_MAXDOWNLOADRATE->setSingleStep(0.1);
	SpinBox_AUTOSEARCHINTERVAL->setMinValue(60);     // one minute
	SpinBox_AUTOSEARCHINTERVAL->setMaxValue(604800); // one week
	SpinBox_SMALLFILESIZE->setMinValue(1024);        // 1KiB
	SpinBox_SMALLFILESIZE->setMaxValue(104857600);   // 100MiB
	SpinBox_AUTORESPONSEDELAY->setMinValue(0);
	SpinBox_AUTORESPONSEDELAY->setMaxValue(3600);
	SpinBox_READFILEBUFFERSIZE->setMinValue(4096);		// 4KiB
	SpinBox_READFILEBUFFERSIZE->setMaxValue(20971520);	// 20MiB
	SpinBox_READFILEBUFFERSIZE->setLineStep(1024);

	// set up icons theme lists
	setupIconThemeComboBoxes();

	// setup the option tree
	plviDCGUI = new QTreeWidgetItem( TreeWidget_OPTIONTREE );
	plviDCGUI->setText( 0, tr( "Valknut" ) );
	plviDCGUI->setExpanded( true );
	plviDCGUIIdentify = new QTreeWidgetItem( plviDCGUI );
	plviDCGUIIdentify->setText( 0, tr( "Identify" ) );

	plviTransfer = new QTreeWidgetItem( TreeWidget_OPTIONTREE );
	plviTransfer->setText( 0, tr( "Transfer" ) );
	plviTransfer->setExpanded( true );
	plviTransferFolder = new QTreeWidgetItem( plviTransfer );
	plviTransferFolder->setText( 0, tr( "Folder" ) );
	plviTransferSettings = new QTreeWidgetItem( plviTransfer );
	plviTransferSettings->setText( 0, tr( "Settings" ) );

	plviConnection = new QTreeWidgetItem( TreeWidget_OPTIONTREE );
	plviConnection->setText( 0, tr( "Connection" ) );
	plviConnection->setExpanded( true );
	plviConnectionMode = new QTreeWidgetItem( plviConnection );
	plviConnectionMode->setText( 0, tr( "Mode" ) );
	plviConnectionSettings = new QTreeWidgetItem( plviConnection );
	plviConnectionSettings->setText( 0, tr( "Settings" ) );

	plviGUI = new QTreeWidgetItem( TreeWidget_OPTIONTREE );
	plviGUI->setText( 0, tr( "GUI" ) );
	plviGUI->setExpanded( true );
	plviGUIGeneral = new QTreeWidgetItem( plviGUI );
	plviGUIGeneral->setText( 0, tr( "General" ) );
	plviGUITransfer = new QTreeWidgetItem( plviGUI );
	plviGUITransfer->setText( 0, tr( "Transfer" ) );
	plviGUIChat = new QTreeWidgetItem( plviGUI );
	plviGUIChat->setText( 0, tr( "Chat" ) );
	plviGUICommands = new QTreeWidgetItem( plviGUI );
	plviGUICommands->setText( 0, tr( "Commands" ) );
	plviGUIMenus = new QTreeWidgetItem( plviGUI );
	plviGUIMenus->setText(0, tr( "Menus" ) );
	plviGUIUser = new QTreeWidgetItem( plviGUI );
	plviGUIUser->setText( 0, tr( "User" ) );
	plviGUIIcons =  new QTreeWidgetItem( plviGUI );
	plviGUIIcons->setText(0, tr ( "Icons" ) );
	plviGUIFilelistBrowser = new QTreeWidgetItem( plviGUI );
	plviGUIFilelistBrowser->setText(0, tr( "Filelist browser" ) );

	plviSound = new QTreeWidgetItem( TreeWidget_OPTIONTREE );
	plviSound->setText( 0, tr( "Sound" ) );

	plviLog = new QTreeWidgetItem( TreeWidget_OPTIONTREE );
	plviLog->setText( 0, tr( "Log" ) );

	plviHubLists = new QTreeWidgetItem( TreeWidget_OPTIONTREE );
	plviHubLists->setText( 0, tr( "Hub Lists" ) );

	plviSecurity = new QTreeWidgetItem( TreeWidget_OPTIONTREE );
	plviSecurity->setText( 0, tr( "Security" ) );

	plviAutoResponse = new QTreeWidgetItem( TreeWidget_OPTIONTREE );
	plviAutoResponse->setText(0, tr( "Auto Responses" ) );

	plviOther = new QTreeWidgetItem( TreeWidget_OPTIONTREE );
	plviOther->setText(0, tr( "Other" ) );

	connect( ToolButton_PHOTO, SIGNAL(clicked()), this, SLOT(slotChangePhoto()) );

	connectOptionsTreeWidget();
	
	connect( TabWidget_DCGUI, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetDCGUICurrentChanged(int)) );
	connect( TabWidget_TRANSFER, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetTransferCurrentChanged(int)) );
	connect( TabWidget_CONNECTION, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetConnectionCurrentChanged(int)) );
	connect( TabWidget_GUI, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetGUICurrentChanged(int)) );
	
	connect( TreeWidget_MENU_COMMANDS, SIGNAL(customContextMenuRequested( const QPoint & )), this, SLOT(slotContextMenuUserMenuCommands( const QPoint & )));
	TreeWidget_MENU_COMMANDS->setContextMenuPolicy( Qt::CustomContextMenu );
	
	connect( TreeWidget_CHAT_COMMANDS, SIGNAL(customContextMenuRequested( const QPoint & )), this, SLOT(slotContextMenuUserChatCommands( const QPoint & )));
	TreeWidget_CHAT_COMMANDS->setContextMenuPolicy( Qt::CustomContextMenu );
	connect( CheckBox_SENDUNKNOWNCOMMANDS, SIGNAL(clicked()), this, SLOT(slotSendUnknownCommandsChecked()) );
	
	connect( TreeWidget_AUTO_RESPONSES, SIGNAL(customContextMenuRequested( const QPoint & )), this, SLOT(slotContextMenuAutoResponses( const QPoint & )));
	TreeWidget_AUTO_RESPONSES->setContextMenuPolicy( Qt::CustomContextMenu );
	
	connect( ToolButton_BROWSESOUNDFILECONNECT, SIGNAL(clicked()), this, SLOT(slotBrowseSoundFileConnect()) );
	connect( ToolButton_BROWSESOUNDFILEDISCONNECT, SIGNAL(clicked()), this, SLOT(slotBrowseSoundFileDisconnect()) );
	connect( ToolButton_BROWSESOUNDFILESEND, SIGNAL(clicked()), this, SLOT(slotBrowseSoundFileSend()) );
	connect( ToolButton_BROWSESOUNDFILERECEIVE, SIGNAL(clicked()), this, SLOT(slotBrowseSoundFileReceive()) );
	connect( ToolButton_BROWSESOUNDFILEFIRSTRECEIVE, SIGNAL(clicked()), this, SLOT(slotBrowseSoundFileFirstReceive()) );
	connect( ToolButton_BROWSESOUNDFILENICKMENTIONED, SIGNAL(clicked()), this, SLOT(slotBrowseSoundFileNickMentioned()) );

	connect( ToolButton_PREVIEWSOUNDFILECONNECT, SIGNAL(clicked()), this, SLOT(slotPreviewSoundFileConnect()) );
	connect( ToolButton_PREVIEWSOUNDFILEDISCONNECT, SIGNAL(clicked()), this, SLOT(slotPreviewSoundFileDisconnect()) );
	connect( ToolButton_PREVIEWSOUNDFILESEND, SIGNAL(clicked()), this, SLOT(slotPreviewSoundFileSend()) );
	connect( ToolButton_PREVIEWSOUNDFILERECEIVE, SIGNAL(clicked()), this, SLOT(slotPreviewSoundFileReceive()) );
	connect( ToolButton_PREVIEWSOUNDFILEFIRSTRECEIVE, SIGNAL(clicked()), this, SLOT(slotPreviewSoundFileFirstReceive()) );
	connect( ToolButton_PREVIEWSOUNDFILENICKMENTIONED, SIGNAL(clicked()), this, SLOT(slotPreviewSoundFileNickMentioned()) );

	connect( ToolButton_BROWSESOUNDPLAYER, SIGNAL(clicked()), this, SLOT(slotBrowseSoundPlayer()) );

	// Transfer->Folder
	connect( ToolButton_BROWSEDOWNLOADFOLDER, SIGNAL(clicked()), this, SLOT(slotBrowseDownloadFolder()) );
	connect( ToolButton_BROWSEDOWNLOADFINISHEDFOLDER, SIGNAL(clicked()), this, SLOT(slotBrowseDownloadFinishedFolder()) );

	connect( ToolButton_CREATESHARELIST, SIGNAL(clicked()), this, SLOT(slotCreateShareList()) );
	connect( ToolButton_BROWSEFILELIST, SIGNAL(clicked()), this, SLOT(slotBrowseShareList()) );
	connect( ToolButton_SHARELISTINFO, SIGNAL(clicked()), this, SLOT(slotShareListInfo()) );
	connect( ToolButton_ADDSHAREDFOLDER, SIGNAL(clicked()), this, SLOT(slotAddSharedFolder()) );
	connect( ToolButton_REMOVESHAREDFOLDER, SIGNAL(clicked()), this, SLOT(slotRemoveSharedFolder()) );
	connect( ToolButton_EDITSHAREDFOLDER, SIGNAL(clicked()), this, SLOT(slotEditSharedFolder()) );
	connect( CheckBox_DONTSHAREDOTFILES, SIGNAL(clicked()), this, SLOT(slotDontShareDotFilesChanged()) );

	//
	connect( PushButton_SAVE, SIGNAL(clicked()), this, SLOT(slotSave()) );
	connect( PushButton_CANCEL, SIGNAL(clicked()), this, SLOT(reject()) );
	
	connect( PushButton_TESTHOST, SIGNAL(clicked()), this, SLOT(slotTestHost()) );
	connect( PushButton_GETINTERFACE, SIGNAL(clicked()), this, SLOT(slotGetInterface()) );
	connect( PushButton_GETINTERNETIP, SIGNAL(clicked()), this, SLOT(slotGetInternetIP()) );

	// GUI->General
	connect( ToolButton_BROWSELANGUAGEFILE, SIGNAL(clicked()), this, SLOT(slotBrowseLanguageFile()) );
	connect( ToolButton_SELECTLANGUAGE, SIGNAL(clicked()), this, SLOT(slotSelectLanguage()) );
	connect( PushButton_SETTHEME, SIGNAL(clicked()), this, SLOT(slotSetTheme()) );
	connect( ToolButton_BROWSEAPPFONT, SIGNAL(clicked()), this, SLOT(slotBrowseAppFont()) );
	connect( CheckBox_CUSTOM_FONT, SIGNAL(clicked()), this, SLOT(slotCustomFontChecked()) );
	connect( ToolButton_BROWSEDATAFOLDER, SIGNAL(clicked()), this, SLOT(slotBrowseDataFolder()) );

	// GUI->Chat
	connect( ToolButton_BROWSEBROWSER, SIGNAL(clicked()), this, SLOT(slotBrowseBrowser()) );
	connect( ListBox_CHATCOLOR, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotDoubleClickedChatColor(QListWidgetItem *)) );

	// GUI->Client
	connect( CheckBox_AUTOAWAYMODE, SIGNAL(clicked()), this, SLOT(slotAutoAwayMode()) );

	// LOG->Chat
	connect( CheckBox_LOGCHAT_ENABLELOGGING, SIGNAL(clicked()), this, SLOT(slotLogChatEnableLogging()) );
	connect( CheckBox_LOGCHAT_ENABLENICKNAMEFILTER, SIGNAL(clicked()), this, SLOT(slotLogChatEnableNickNameFilter()) );
	connect( ToolButton_LOGCHAT_NICKNAMEFILTER_ADD, SIGNAL(clicked()), this, SLOT(slotLogChatAddNickNameFilter()) );
	connect( ToolButton_LOGCHAT_NICKNAMEFILTER_DEL, SIGNAL(clicked()), this, SLOT(slotLogChatDelNickNameFilter()) );

	//
	connect( ToolButton_BROWSETRANSFERCERT, SIGNAL(clicked()), this, SLOT(slotBrowseTransferCert()) );
	connect( ToolButton_BROWSETRANSFERKEY, SIGNAL(clicked()), this, SLOT(slotBrowseTransferKey()) );
	connect( ToolButton_BROWSE_DCLIB_PLUGIN_PATH, SIGNAL(clicked()), this, SLOT(slotBrowseDclibPluginFolder()) );

	connect( RadioButton_ACTIVEMODE, SIGNAL(toggled(bool)), this, SLOT(slotModeActiveChange(bool)) );
	connect( RadioButton_PASSIVEMODE, SIGNAL(toggled(bool)), this, SLOT(slotModePassiveChange(bool)) );
	connect( RadioButton_IPHOSTNAME, SIGNAL(toggled(bool)), this, SLOT(slotIPHOSTNAMEChange(bool)) );
	connect( RadioButton_INTERFACE, SIGNAL(toggled(bool)), this, SLOT(slotINTERFACEChange(bool)) );

	// Hub List
	connect( ToolButton_ADDHUBLISTURL, SIGNAL(clicked()), this, SLOT(slotAddHubListUrl()) );
	connect( ToolButton_EDITHUBLISTURL, SIGNAL(clicked()), this, SLOT(slotEditHubListUrl()) );
	connect( ToolButton_REMOVEHUBLISTURL, SIGNAL(clicked()), this, SLOT(slotRemoveHubListUrl()) );

	connect( CheckBox_SOUNDDISABLED, SIGNAL(clicked()), this, SLOT(slotDisableSound()) );
	
	connect( CheckBox_EXTERNALPLAYER, SIGNAL(clicked()), this, SLOT(slotExternalPlayer()) );
	connect( CheckBox_SOUNDPLAYCONNECT, SIGNAL(clicked()), this, SLOT(slotSoundPlayConnect()) );
	connect( CheckBox_SOUNDPLAYDISCONNECT, SIGNAL(clicked()), this, SLOT(slotSoundPlayDisconnect()) );
	connect( CheckBox_SOUNDPLAYSEND, SIGNAL(clicked()), this, SLOT(slotSoundPlaySend()) );
	connect( CheckBox_SOUNDPLAYRECEIVE, SIGNAL(clicked()), this, SLOT(slotSoundPlayRecieve()) );
	connect( CheckBox_SOUNDPLAYFIRSTRECEIVE, SIGNAL(clicked()), this, SLOT(slotSoundPlayFirstReceive()) );
	connect( CheckBox_SOUNDPLAYNICKMENTIONED, SIGNAL(clicked()), this, SLOT(slotSoundPlayNickMentioned()) );

	connect( ToolButton_BROWSELOGFILE, SIGNAL(clicked()), this, SLOT(slotBrowseLogFile()) );
	
	connect( CheckBox_CHATSHOWJOINSANDPARTS, SIGNAL(clicked()), this, SLOT(slotEnableShowJoinsParts()) );
	
	connect( PushButton_GENERATE_CERT, SIGNAL(clicked()), this, SLOT(slotGenerateKeyCert()) );
	
	// style options
	ComboBox_THEME->clear();

	if ( g_pConfig->GetThemeSupport() == TRUE )
	{
		QStringList list = QStyleFactory::keys();

		if ( list.count() > 0 )
		{
			list.sort();
			ComboBox_THEME->insertStringList(list);
			list.clear();
		}
	}
	else
	{
		// disable the theme support
		ComboBox_THEME->setEnabled(FALSE);
		PushButton_SETTHEME->setEnabled(FALSE);
	}
}

/** */
void DCOptions::connectOptionsTreeWidget()
{
	connect( TreeWidget_OPTIONTREE, SIGNAL(currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * )), this, SLOT(slotTreeWidgetOptionTreeCurrentChanged( QTreeWidgetItem *, QTreeWidgetItem * )) );
}

/** */
void DCOptions::disconnectOptionsTreeWidget()
{
	disconnect( TreeWidget_OPTIONTREE, SIGNAL(currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * )), this, SLOT(slotTreeWidgetOptionTreeCurrentChanged( QTreeWidgetItem *, QTreeWidgetItem * )) );
}

/** */
void DCOptions::slotSave()
{
	// check if mode change
	if ( ((RadioButton_ACTIVEMODE->isOn() == TRUE) && (g_pConfig->GetMode(TRUE) == ecmPASSIVE)) ||
	     ((RadioButton_ACTIVEMODE->isOn() == FALSE) && (g_pConfig->GetMode(TRUE) == ecmACTIVE)) )
	{
		QMessageBox::warning( 0, "Valknut",
			QString(tr("You changed the client mode! Please restart Valknut!")));
	}

	if ( LineEdit_DOWNLOADFOLDER->text() == "" )
	{
		QMessageBox::critical( 0, "Valknut",
		QString(tr("You must set a Download Folder!")));
		return;
	}

	if ( LineEdit_DOWNLOADFINISHEDFOLDER->text() == LineEdit_DOWNLOADFOLDER->text() )
	{
		QMessageBox::critical( 0, "Valknut",
		QString(tr("Download Finished Folder and Download Folder must be different!")));
		return;
	}

	// check active mode settings
	if ( RadioButton_ACTIVEMODE->isOn() == TRUE )
	{
		// check fake host
		if ( (RadioButton_IPHOSTNAME->isOn() == TRUE) &&
	     	     (LineEdit_IP->text() == "") )

		{
			QMessageBox::critical( 0, "Valknut",
			QString(tr("You must enter a valid 'Fake Host'!")));
			return;
		}

		// check interface
		if ( (RadioButton_INTERFACE->isOn() == TRUE) &&
	     	     (LineEdit_IP->text() == "") )

		{
			QMessageBox::critical( 0, "Valknut",
			QString(tr("You must enter a valid interface!")));
			return;
		}

#ifndef WIN32
		if ( (SpinBox_TCPLISTENPORT->value() < 1024) || (SpinBox_UDPLISTENPORT->value() < 1024) )
		{
			QMessageBox::critical( 0, "Valknut",
			QString(tr("You have set Valknut to listen on a port < 1024! You can run Valknut only as root in active mode!")));
		}
#endif
	}

	// no nick is given
	if ( LineEdit_NICK->text() == "" )
	{
		QMessageBox::critical( 0, "Valknut",
		QString(tr("You must enter a valid nick!")));
		return;
	}

	// no search nick is given
	if ( (LineEdit_SEARCHNICK->text() == "") || (LineEdit_SEARCHNICK->text() == "nick_search") )
	{
		QMessageBox::critical( 0, "Valknut",
		QString(tr("You must enter a valid search nick!")));
		return;
	}

	if ( CheckBox_CUSTOM_FONT->isChecked() )
	{
		if (LineEdit_APPFONT->text() != "")
		{
			QFont font;
			if (font.fromString(LineEdit_APPFONT->text()) == TRUE)
			{
				QApplication::setFont(font, TRUE);
			}
		}
	}

	accept();
}

/** */
void DCOptions::SetUserPhoto( QString filename )
{
	QImage im;

	if ( filename != "" )
	{
		if ( im.load(filename) == TRUE )
		{
			if ( (im.width() > 32) ||
			     (im.height() > 32) )
			{
				im = im.smoothScale(32,32,Qt::KeepAspectRatio);
			}

			if ( im.depth() > 8 )
				im = im.convertDepth(8);

			if ( im.numColors() > 256 )
				im.setNumColors(256);

			if ( im.save( (g_pConfig->GetConfigPath() + "photo.png").Data(), "PNG", 0 ) == FALSE )
			{
				QMessageBox::critical( 0, "Valknut", QString(tr("Can't save Image!")));
			}
			else
			{
				ToolButton_PHOTO->setIconSet( QIcon(QPixmap::fromImage(im)) );
				// ToolButton_PHOTO->setTextLabel(filename);
				ToolButton_PHOTO->setTextLabel((g_pConfig->GetConfigPath() + "photo.png").Data());
			}
		}
		else
		{
			QMessageBox::critical( 0, "Valknut", QString(tr("Can't load Image!")));
		}
	}
}

/** */
void DCOptions::slotChangePhoto()
{
	QString file;

	file = QFileDialog::getOpenFileName( this, tr("Select a 64x64 Photo"), ToolButton_PHOTO->textLabel() );

	if( file != "" )
	{
		SetUserPhoto(file.toAscii().data());
	}
	else
	{
		ToolButton_PHOTO->setIconSet( QIcon(QPixmap::fromImage(QImage(""))) );
		ToolButton_PHOTO->setTextLabel("");
	}
}

/** */
void DCOptions::slotAutoAwayMode()
{
	Frame_AUTOAWAYTIME->setEnabled(CheckBox_AUTOAWAYMODE->isChecked());
}

/** */
void DCOptions::slotDoubleClickedChatColor( QListWidgetItem * item )
{
	QPixmap p(10,10);
	QColor color(item->icon().pixmap(10,10).toImage().pixel(0,0));
	color = QColorDialog::getColor(color);
	if ( color.isValid() )
	{
		p.fill(color);
		item->setIcon(p);
	}
}

/** */
void DCOptions::slotLogChatEnableLogging()
{
	bool b;

	b = CheckBox_LOGCHAT_ENABLELOGGING->isChecked();

	CheckBox_LOGCHAT_APPENDDATE->setEnabled(b);
	CheckBox_LOGCHAT_APPENDHUBNAME->setEnabled(b);
	CheckBox_LOGCHAT_APPENDHUBHOST->setEnabled(b);
	CheckBox_LOGCHAT_DISABLEPUBLICCHAT->setEnabled(b);
	CheckBox_LOGCHAT_ENABLENICKNAMEFILTER->setEnabled(b);

	b = b & CheckBox_LOGCHAT_ENABLENICKNAMEFILTER->isChecked();

	GroupBox_LOGNICKNAMEFILTER->setEnabled(b);
}

/** */
void DCOptions::slotLogChatEnableNickNameFilter()
{
	bool b;

	b = CheckBox_LOGCHAT_ENABLENICKNAMEFILTER->isChecked();

	GroupBox_LOGNICKNAMEFILTER->setEnabled(b);
}

/** */
void DCOptions::slotLogChatAddNickNameFilter()
{
	bool ok = FALSE;

	QString text = QInputDialog::getText(
		tr("Add new nick name filter"),
		tr("Please enter a nick" ),
		QLineEdit::Normal, "", &ok, this );

	if ( ok && !text.isEmpty() )
	{
		if ( (ListBox_LOGCHAT_NICKNAMEFILTER_LIST->findItems( text, Qt::MatchExactly )).size() == 0 )
		{
			new QListWidgetItem( text, ListBox_LOGCHAT_NICKNAMEFILTER_LIST );
		}
	}
}

/** */
void DCOptions::slotLogChatDelNickNameFilter()
{
	int i;

	i = ListBox_LOGCHAT_NICKNAMEFILTER_LIST->currentRow();

	if ( i >= 0 )
	{
		QListWidgetItem * item = ListBox_LOGCHAT_NICKNAMEFILTER_LIST->takeItem(i);
		
		if ( item != 0 )
		{
			delete item;
		}
	}
}

/** */
void DCOptions::slotIPHOSTNAMEChange( bool )
{
	PushButton_GETINTERFACE->setEnabled(FALSE);
	PushButton_GETINTERNETIP->setEnabled(TRUE);
}

/** */
void DCOptions::slotINTERFACEChange( bool )
{
	PushButton_GETINTERFACE->setEnabled(TRUE);
	PushButton_GETINTERNETIP->setEnabled(FALSE);
}

/** */
void DCOptions::slotModeActiveChange(bool b)
{
	ButtonGroup_ACTIVEMODESETTINGS->setEnabled(b);
	ButtonGroup_PASSIVEMODESETTINGS->setEnabled(!b);
}

/** */
void DCOptions::slotModePassiveChange(bool b)
{
	ButtonGroup_ACTIVEMODESETTINGS->setEnabled(!b);
	ButtonGroup_PASSIVEMODESETTINGS->setEnabled(b);
}

/** */
void DCOptions::slotTestHost()
{
	QString sip="";
	CSocket Socket;
	CString s;

	if ( RadioButton_IPHOSTNAME->isOn() )
	{
		s = LineEdit_IP->text().toAscii().data();
		s = s.Replace(' ',"");
		LineEdit_IP->setText(s.Data());

		if ( s != "" )
		{
			sip = CSocket::GetHostByName(s).Data();
		}

		if ( sip != "" )
		{
			QMessageBox::information( 0, "Valknut", QString(tr("Host IP: "))+sip);
		}
		else
		{
			QMessageBox::critical( 0, "Valknut", QString(tr("Can't get Host IP!")));
		}
	}
	else
	{
		sip = Socket.GetInterfaceIP(LineEdit_IP->text().toAscii().data()).Data();

		if ( sip != "" )
		{
			QMessageBox::information( 0, "Valknut", QString(tr("Interface IP: "))+sip);
		}
		else
		{
			QMessageBox::critical( 0, "Valknut", QString(tr("Can't get interface IP!")));
		}
	}
}

/** */
void DCOptions::slotGetInterface()
{
	CSocket Socket;
	CList<CString> interfacelist;
	CString * s;
	QStringList lst;

	if ( Socket.GetInterfaceList(&interfacelist) > 0 )
	{
		s = 0;

		while( (s=interfacelist.Next(s)) != 0 )
		{
			lst << s->Data();
		}
  
		bool ok = FALSE;

		QString res = QInputDialog::getItem(
				tr( "Interface List" ),
				tr( "Please select an interface" ), lst, 1, TRUE, &ok, this );

		if ( ok )
		{
			LineEdit_IP->setText(res);
		}
	}
	else
	{
		QMessageBox::information( 0, "Valknut", QString(tr("No interfaces found!")));
	}
}

/** */
void DCOptions::slotGetInternetIP()
{
	PushButton_GETINTERNETIP->setEnabled(FALSE);
	
	QHttpRequestHeader header( "GET", "/" );
	header.setValue( "Host", "whatismyip.org" );
	QString useragent = QString("Valknut/") + VERSION;
	//printf("User-Agent=%s\n", useragent.toAscii().data());
	header.setValue( "User-Agent", useragent );
	
	http = new QHttp();
	connect( http, SIGNAL(done(bool)), this, SLOT(slotGotInternetIP(bool)) );
	http->setHost( "whatismyip.org" );
	http->request( header );
}

/** */
void DCOptions::slotGotInternetIP( bool error )
{
	if (error == TRUE)
	{
		QMessageBox mb ( tr("Error getting IP"),
				 http->errorString(),
				 QMessageBox::Warning,
				 QMessageBox::Ok,
				 0,
				 0
		);
		mb.exec();
	}
	else
	{
		LineEdit_IP->setText(QString(http->readAll()));
	}
	
	delete http;
	
	PushButton_GETINTERNETIP->setEnabled(TRUE);
}

/** */
void DCOptions::slotDisableSound()
{
	bool b;

	b = !CheckBox_SOUNDDISABLED->isChecked();

	CheckBox_SOUNDDISABLEDAWAY->setEnabled(b);
	CheckBox_SOUNDPLAYCONNECT->setEnabled(b);
	CheckBox_SOUNDPLAYDISCONNECT->setEnabled(b);
	CheckBox_SOUNDPLAYSEND->setEnabled(b);
	CheckBox_SOUNDPLAYRECEIVE->setEnabled(b);
	CheckBox_SOUNDPLAYFIRSTRECEIVE->setEnabled(b);
	CheckBox_SOUNDPLAYNICKMENTIONED->setEnabled(b);
	CheckBox_EXTERNALPLAYER->setEnabled(b);

	if (!b) {
		LineEdit_EXTERNALPLAYER->setEnabled(b);
		ToolButton_BROWSESOUNDPLAYER->setEnabled(b);
		LineEdit_SOUNDFILECONNECT->setEnabled(b);
		ToolButton_BROWSESOUNDFILECONNECT->setEnabled(b);
		ToolButton_PREVIEWSOUNDFILECONNECT->setEnabled(b);
		LineEdit_SOUNDFILEDISCONNECT->setEnabled(b);
		ToolButton_BROWSESOUNDFILEDISCONNECT->setEnabled(b);
		ToolButton_PREVIEWSOUNDFILEDISCONNECT->setEnabled(b);
		LineEdit_SOUNDFILESEND->setEnabled(b);
		ToolButton_BROWSESOUNDFILESEND->setEnabled(b);
		ToolButton_PREVIEWSOUNDFILESEND->setEnabled(b);
		LineEdit_SOUNDFILERECEIVE->setEnabled(b);
		ToolButton_BROWSESOUNDFILERECEIVE->setEnabled(b);
		ToolButton_PREVIEWSOUNDFILERECEIVE->setEnabled(b);
		LineEdit_SOUNDFILEFIRSTRECEIVE->setEnabled(b);
		ToolButton_BROWSESOUNDFILEFIRSTRECEIVE->setEnabled(b);
		ToolButton_PREVIEWSOUNDFILEFIRSTRECEIVE->setEnabled(b);
		LineEdit_SOUNDFILENICKMENTIONED->setEnabled(b);
		ToolButton_BROWSESOUNDFILENICKMENTIONED->setEnabled(b);
		ToolButton_PREVIEWSOUNDFILENICKMENTIONED->setEnabled(b);
	} else {
		slotExternalPlayer();
		slotSoundPlayConnect();
		slotSoundPlayConnect();
		slotSoundPlayDisconnect();
		slotSoundPlaySend();
		slotSoundPlayRecieve();
		slotSoundPlayFirstReceive();
		slotSoundPlayNickMentioned();
	}
}

/** */
void DCOptions::slotExternalPlayer()
{
	bool b;

	b = CheckBox_EXTERNALPLAYER->isChecked();
	
	LineEdit_EXTERNALPLAYER->setEnabled(b);
	ToolButton_BROWSESOUNDPLAYER->setEnabled(b);
}

/** */
void DCOptions::slotSoundPlayConnect()
{
	bool b;

	b = CheckBox_SOUNDPLAYCONNECT->isChecked();
	
	LineEdit_SOUNDFILECONNECT->setEnabled(b);
	ToolButton_BROWSESOUNDFILECONNECT->setEnabled(b);
	ToolButton_PREVIEWSOUNDFILECONNECT->setEnabled(b);
}

/** */
void DCOptions::slotSoundPlayDisconnect()
{
	bool b;

	b = CheckBox_SOUNDPLAYDISCONNECT->isChecked();
	
	LineEdit_SOUNDFILEDISCONNECT->setEnabled(b);
	ToolButton_BROWSESOUNDFILEDISCONNECT->setEnabled(b);
	ToolButton_PREVIEWSOUNDFILEDISCONNECT->setEnabled(b);
}

/** */
void DCOptions::slotSoundPlaySend()
{
	bool b;

	b = CheckBox_SOUNDPLAYSEND->isChecked();
	
	LineEdit_SOUNDFILESEND->setEnabled(b);
	ToolButton_BROWSESOUNDFILESEND->setEnabled(b);
	ToolButton_PREVIEWSOUNDFILESEND->setEnabled(b);
}

/** */
void DCOptions::slotSoundPlayRecieve()
{
	bool b;

	b = CheckBox_SOUNDPLAYRECEIVE->isChecked();
	
	LineEdit_SOUNDFILERECEIVE->setEnabled(b);
	ToolButton_BROWSESOUNDFILERECEIVE->setEnabled(b);
	ToolButton_PREVIEWSOUNDFILERECEIVE->setEnabled(b);
}

/** */
void DCOptions::slotSoundPlayFirstReceive()
{
	bool b;

	b = CheckBox_SOUNDPLAYFIRSTRECEIVE->isChecked();
	
	LineEdit_SOUNDFILEFIRSTRECEIVE->setEnabled(b);
	ToolButton_BROWSESOUNDFILEFIRSTRECEIVE->setEnabled(b);
	ToolButton_PREVIEWSOUNDFILEFIRSTRECEIVE->setEnabled(b);
}

/** */
void DCOptions::slotSoundPlayNickMentioned()
{
	bool b;
	
	b = CheckBox_SOUNDPLAYNICKMENTIONED->isChecked();
	
	LineEdit_SOUNDFILENICKMENTIONED->setEnabled(b);
	ToolButton_BROWSESOUNDFILENICKMENTIONED->setEnabled(b);
	ToolButton_PREVIEWSOUNDFILENICKMENTIONED->setEnabled(b);
}

/** */
void DCOptions::slotBrowseSoundPlayer()
{
	QString file;

	file = QFileDialog::getOpenFileName( this, tr("Select sound player"), LineEdit_EXTERNALPLAYER->text() );

	if( file != "" )
	{
		LineEdit_EXTERNALPLAYER->setText(file);
	}
}

/** */
void DCOptions::slotBrowseTransferCert()
{
	QString file;

	file = QFileDialog::getSaveFileName( this, tr("Select transfer cert"), LineEdit_TRANSFERCERT->text(), QString(), 0, QFileDialog::DontConfirmOverwrite );

	if( file != "" )
	{
		LineEdit_TRANSFERCERT->setText(file);
	}
}

/** */
void DCOptions::slotBrowseTransferKey()
{
	QString file;

	file = QFileDialog::getSaveFileName( this, tr("Select transfer key"), LineEdit_TRANSFERKEY->text(), QString(), 0, QFileDialog::DontConfirmOverwrite );

	if( file != "" )
	{
		LineEdit_TRANSFERKEY->setText(file);
	}
}

/** */
void DCOptions::slotBrowseDclibPluginFolder()
{
	QString dir;
	
	dir = QFileDialog::getExistingDirectory( LineEdit_DCLIB_PLUGIN_PATH->text(), this, "bdf", tr("Select plugin folder"), TRUE );
	
	if ( dir != "" )
	{
		LineEdit_DCLIB_PLUGIN_PATH->setText(dir);
	}
}

/** */
void DCOptions::slotBrowseBrowser()
{
	QString file;

	file = QFileDialog::getOpenFileName( this, tr("Select a browser"), LineEdit_BROWSER->text() );

	if( file != "" )
	{
		LineEdit_BROWSER->setText(file);
	}
}

/** */
void DCOptions::BrowseSoundFile( eUserSound usersound )
{
	QString file;
	QString filter;
	QString current;

	filter = tr("au")        + " (*.au);;"  +
		 tr("wav")       + " (*.wav);;" +
		 tr("All Files") + " (*)";
	
	switch(usersound)
	{
		case eusCONNECT:
			current = LineEdit_SOUNDFILECONNECT->text();
			break;
		case eusDISCONNECT:
			current = LineEdit_SOUNDFILEDISCONNECT->text();
			break;
		case eusSEND:
			current = LineEdit_SOUNDFILESEND->text();
			break;
		case eusRECEIVE:
			current = LineEdit_SOUNDFILERECEIVE->text();
			break;
		case eusFIRSTRECEIVE:
			current = LineEdit_SOUNDFILEFIRSTRECEIVE->text();
			break;
		case eusNICKMENTIONED:
			current = LineEdit_SOUNDFILENICKMENTIONED->text();
			break;
		default:
			current = "";
			break;
	}

	file = QFileDialog::getOpenFileName( this, tr("Select sound file"), current, filter  );

	if( file != "" )
	{
		switch(usersound)
		{
			case eusCONNECT:
				LineEdit_SOUNDFILECONNECT->setText(file);
				break;
			case eusDISCONNECT:
				LineEdit_SOUNDFILEDISCONNECT->setText(file);
				break;
			case eusSEND:
				LineEdit_SOUNDFILESEND->setText(file);
				break;
			case eusRECEIVE:
				LineEdit_SOUNDFILERECEIVE->setText(file);
				break;
			case eusFIRSTRECEIVE:
				LineEdit_SOUNDFILEFIRSTRECEIVE->setText(file);
				break;
			case eusNICKMENTIONED:
				LineEdit_SOUNDFILENICKMENTIONED->setText(file);
				break;
			default:
				break;
		}
	}
}

/** */
void DCOptions::PreviewSoundFile( eUserSound usersound )
{
	QString file="";

	switch(usersound)
	{
		case eusCONNECT:
			file = LineEdit_SOUNDFILECONNECT->text();
			break;
		case eusDISCONNECT:
			file = LineEdit_SOUNDFILEDISCONNECT->text();
			break;
		case eusSEND:
			file = LineEdit_SOUNDFILESEND->text();
			break;
		case eusRECEIVE:
			file = LineEdit_SOUNDFILERECEIVE->text();
			break;
		case eusFIRSTRECEIVE:
			file = LineEdit_SOUNDFILEFIRSTRECEIVE->text();
			break;
		case eusNICKMENTIONED:
			file = LineEdit_SOUNDFILENICKMENTIONED->text();
			break;
		default:
			break;
	}

	g_pConfig->PlaySound( file.toAscii().data() );
}

/** */
void DCOptions::slotBrowseDownloadFolder()
{
	QString dir;

	dir = QFileDialog::getExistingDirectory ( this, tr("Select download folder"), LineEdit_DOWNLOADFOLDER->text() );

	if(dir!="")
	{
		LineEdit_DOWNLOADFOLDER->setText(dir);
	}
}

/** */
void DCOptions::slotBrowseDownloadFinishedFolder()
{
	QString dir;

	dir = QFileDialog::getExistingDirectory ( this, tr("Select download finished folder"), LineEdit_DOWNLOADFINISHEDFOLDER->text() );

	if(dir!="")
	{
		LineEdit_DOWNLOADFINISHEDFOLDER->setText(dir);
	}
}

/** */
void DCOptions::slotBrowseDataFolder()
{
	QString dir;

	dir = QFileDialog::getExistingDirectory ( this, tr("Select data folder"), LineEdit_DATAFOLDER->text() );

	if( dir != "" )
	{
		LineEdit_DATAFOLDER->setText(dir);
	}
}

/** */
void DCOptions::slotBrowseShareList()
{
	g_pTransferView->NewLocalFileBrowser(TRUE);
}

/** */
void DCOptions::slotBrowseLogFile()
{
	QString logfile;

	logfile = QFileDialog::getSaveFileName ( this, tr("Select log file"), LineEdit_LOGFILENAME->text() );

	if( !logfile.isEmpty() )
	{
		LineEdit_LOGFILENAME->setText(logfile);
	}
}

/** */
void DCOptions::slotAddSharedFolder()
{
	CDir di;
	QString dir;
	CString s;
	int i;

	dir = QFileDialog::getExistingDirectory ( this, tr("Select share folder") );

	if( dir != "" )
	{
		if ( TreeWidget_SHAREDFOLDERS->findItems( dir, Qt::MatchExactly, 0 ).size() == 0 )
		{
			di.SetPath(dir.toAscii().data());
			s = di.Path();
			i = 1;

			while( TreeWidget_SHAREDFOLDERS->findItems( di.DirName().Data(), Qt::MatchExactly, 1 ).size() != 0 )
			{
				di.SetPath( s + CString().setNum(i) );
				i++;
			}

			QTreeWidgetItem * item = new QTreeWidgetItem( TreeWidget_SHAREDFOLDERS );
			item->setText( 0, dir );
			item->setText( 1, di.DirName().Data() );
		}
	}
}

/** */
void DCOptions::slotRemoveSharedFolder()
{
	QTreeWidgetItem * item = TreeWidget_SHAREDFOLDERS->currentItem();

	if ( item )
	{
		TreeWidget_SHAREDFOLDERS->takeTopLevelItem( TreeWidget_SHAREDFOLDERS->indexOfTopLevelItem( item ) );
		delete item;
	}
}

/** */
void DCOptions::slotEditSharedFolder()
{
	QString s;
	QTreeWidgetItem * item = TreeWidget_SHAREDFOLDERS->currentItem();

	if ( item )
	{
		QDialog dlg;
		
		Ui::DCDialogEditSharePath ui;
		ui.setupUi(&dlg);
						
		ui.LineEdit_PATH->setText( item->text(0) );
		ui.LineEdit_ALIAS->setText( item->text(1) );
		
		if ( dlg.exec() == QDialog::Accepted )
		{
			item->setText(0,ui.LineEdit_PATH->text());
			
			s = ui.LineEdit_ALIAS->text();
			s.replace( "\\", "" );
			s.replace( "/", "" );
			item->setText(1,s);
		}
	}
}

/** */
void DCOptions::SetValues()
{
	int i;
	CList<DCConfigShareFolder> list;
	CList<DC_UserMenuCommand> umclist;
	DCConfigShareFolder * csf;
	DC_UserMenuCommand * umc;
	QTreeWidgetItem * qtwitem;
	CList<DC_UserChatCommand> ucclist;
	DC_UserChatCommand * ucc;
	CList<DC_AutoResponseObject> arlist;
	DC_AutoResponseObject * aro = 0;

	// identify
	LineEdit_NICK->setText(g_pConfig->GetNick().Data());
	LineEdit_SEARCHNICK->setText(g_pConfig->GetSearchNick().Data());
	LineEdit_EMAIL->setText(g_pConfig->GetEMail(TRUE).Data());
	CheckBox_ANTISPAM->setChecked(g_pConfig->GetAntiSpam());
	LineEdit_DESCRIPTION->setText(g_pConfig->GetDescription(TRUE).Data());
	CheckBox_DESCRIPTION_TAG->setChecked(g_pConfig->GetDescriptionTag());
	CheckBox_EXT_HUB_COUNT->setChecked(g_pConfig->GetUseExtendedHubCount());
	LineEdit_AWAYPREFIX->setText(g_pConfig->GetAwayPrefix().Data());

	SetUserPhoto(g_pConfig->GetUserPhotoFileName().Data());

	for(i=0;i<ComboBox_SPEED->count();i++)
	{
		if ( ComboBox_SPEED->text(i) == g_pConfig->GetSpeed() )
		{
			ComboBox_SPEED->setCurrentItem(i);
			break;
		}
	}
	
	for(i=0;i<ComboBox_APPLICATION_ICONS->count();i++)
	{
		if ( ComboBox_APPLICATION_ICONS->text(i) == g_pConfig->GetApplicationIconTheme() )
		{
			ComboBox_APPLICATION_ICONS->setCurrentItem(i);
			break;
		}
	}
	
	for(i=0;i<ComboBox_EMOTICONS->count();i++)
	{
		if ( ComboBox_EMOTICONS->text(i) == g_pConfig->GetEmoticonTheme() )
		{
			ComboBox_EMOTICONS->setCurrentItem(i);
			break;
		}
	}
	
	for(i=0;i<ComboBox_USERLIST_ICONS->count();i++)
	{
		if ( ComboBox_USERLIST_ICONS->text(i) == g_pConfig->GetUserListIconTheme() )
		{
			ComboBox_USERLIST_ICONS->setCurrentItem(i);
			break;
		}
	}
	

	TextEdit_AWAYMESSAGE->setText(QString(g_pConfig->GetAwayMessage().Data()).replace( "\r", "" ));

	// transfer->folder
	LineEdit_DOWNLOADFOLDER->setText(g_pConfig->GetDownloadFolder().Data());
	LineEdit_DOWNLOADFINISHEDFOLDER->setText(g_pConfig->GetDownloadFinishedFolder().Data());

	// save shared folders
	TreeWidget_SHAREDFOLDERS->clear();

	g_pConfig->GetSharedFolders(&list);

	csf = 0;
	while( (csf=list.Next(csf)) != 0 )	
	{
		QTreeWidgetItem * item = new QTreeWidgetItem( TreeWidget_SHAREDFOLDERS );
		item->setText( 0, csf->m_sPath.Data() );
		item->setText( 1, csf->m_sAlias.Data() );
	}
	
	g_pConfig->GetUserMenuCommands(&umclist);
	umc = 0;
	while( (umc=umclist.Next(umc)) != 0 )
	{
		qtwitem = new QTreeWidgetItem( TreeWidget_MENU_COMMANDS );
		qtwitem->setText( 0, umc->m_sName.Data() );
		qtwitem->setText( 1, QString().setNum(umc->m_nContext) );
		qtwitem->setText( 2, umc->m_sCommand.Data() );
		qtwitem->setFlags( qtwitem->flags() | Qt::ItemIsEditable );
	}
	
	g_pConfig->GetUserChatCommands(&ucclist);
	ucc = 0;
	while( (ucc=ucclist.Next(ucc)) != 0 )
	{
		qtwitem = new QTreeWidgetItem( TreeWidget_CHAT_COMMANDS );
		qtwitem->setText( 0, ucc->m_sName.Data() );
		qtwitem->setText( 1, ucc->m_sCommand.Data() );
		qtwitem->setFlags( qtwitem->flags() | Qt::ItemIsEditable );
	}
	
	CheckBox_AUTORECREATESHARELIST->setChecked(g_pConfig->GetAutoRecreateShareList());
	CheckBox_DONTSHAREDOTFILES->setChecked(g_pConfig->GetDontShareDotFiles());

	// transfer->settings
	SpinBox_SAVEDOWNLOADQUEUETIME->setValue( g_pConfig->GetDownloadQueueTime() );
	SpinBox_USERUPLOADSLOTS->setValue(g_pConfig->GetUserUploadSlots());
	CheckBox_DYNAMICUPLOADRATE->setChecked(g_pConfig->GetDynamicUploadRate());
	SpinBox_MAXUPLOADRATE->setValue( (g_pConfig->GetMaxUploadRate())/1024.0 );
	SpinBox_MAXDOWNLOADRATE->setValue( (g_pConfig->GetMaxDownloadRate())/1024.0 );
	SpinBox_MAXSIMULTANEOUSUPLOADS->setValue( g_pConfig->GetMaxUpload() );
	SpinBox_TRANSFERRESENDTIMEOUT->setValue(g_pConfig->GetTransferResendTimeout());
	SpinBox_TRANSFERRESPONSETIMEOUT->setValue(g_pConfig->GetTransferResponseTimeout());
	SpinBox_AUTOSEARCHINTERVAL->setValue(g_pConfig->GetAutoSearchInterval());
	SpinBox_SMALLFILESIZE->setValue(g_pConfig->GetSmallFileSize());

	switch ( g_pConfig->GetHubOfflineTransferClose() )
	{
		case ectNONE:
			RadioButton_NONE->setChecked(TRUE);
			break;
		case ectUPLD:
			RadioButton_UPLOAD->setChecked(TRUE);
			break;
		case ectDLD:
			RadioButton_DOWNLOAD->setChecked(TRUE);
			break;
		case ectBOTH:
			RadioButton_BOTH->setChecked(TRUE);
			break;
	}

	CheckBox_TRANSFERAUTOSEARCH->setChecked(g_pConfig->GetTransferAutoSearch());
	CheckBox_DISABLEHASHLIST->setChecked(g_pConfig->GetDisableHashList());
	CheckBox_COMPRESSEDTRANSFERS->setChecked(g_pConfig->GetCompressedTransfers());
	SpinBox_RECREATESHARELISTTIME->setValue(g_pConfig->GetRecreateShareListTime());

	// connection->mode
	if ( g_pConfig->GetMode(TRUE) == ecmPASSIVE )
	{
		RadioButton_PASSIVEMODE->setChecked(TRUE);
		slotModeActiveChange(FALSE);
	}
	else
	{
		RadioButton_ACTIVEMODE->setChecked(TRUE);
		slotModeActiveChange(TRUE);
	}

	if ( g_pConfig->GetExternalIP() == TRUE )
	{
		RadioButton_IPHOSTNAME->setChecked(TRUE);
		slotIPHOSTNAMEChange(TRUE);
	}
	else
	{
		RadioButton_INTERFACE->setChecked(TRUE);
		slotINTERFACEChange(TRUE);
	}

	LineEdit_IP->setText(g_pConfig->GetHost().Data());
	LineEdit_LISTENIP->setText(g_pConfig->GetListenHost().Data());
	SpinBox_TCPLISTENPORT->setValue( g_pConfig->GetTCPListenPort() );
	SpinBox_UDPLISTENPORT->setValue( g_pConfig->GetUDPListenPort() );
	CheckBox_SENDMESSAGEONACTIVEMODEREQUEST->setChecked( g_pConfig->GetSendMessageOnActiveModeRequest() );

	// connection->settings
	SpinBox_RECONNECTCOUNT->setValue(g_pConfig->GetReconnectCount());
	SpinBox_RECONNECTTIMEOUT->setValue(g_pConfig->GetReconnectTimeout());
	CheckBox_FORCEMOVEENABLED->setChecked(g_pConfig->GetForceMoveEnabled());
	CheckBox_CHECKPRIVATEADDRESSSPACE->setChecked(g_pConfig->GetCheckPrivateAddressSpace());

	// gui->general
	LineEdit_LANGUAGEFILE->setText( g_pConfig->GetLanguageFile().Data() );

	for(i=0;i<ComboBox_THEME->count();i++)
	{
		if ( g_pConfig->GetTheme() == CString(ComboBox_THEME->text(i).toAscii().data()) )
		{
			ComboBox_THEME->setCurrentItem(i);
			break;
		}
	}

	// if theme not in list, pick the current theme
	if ( ComboBox_THEME->currentText() != QString(g_pConfig->GetTheme().Data()) )
	{
		i = ComboBox_THEME->findText( qApp->style()->name() );

		if ( i != -1 )
		{
			ComboBox_THEME->setCurrentItem(i);
		}
	}

	switch(g_pConfig->GetUnit())
	{
		case euBYTE:
			RadioButton_UNITBYTE->setChecked(TRUE);
			break;
		case euKBYTE:
			RadioButton_UNITKBYTE->setChecked(TRUE);
			break;
		case euMBYTE:
			RadioButton_UNITMBYTE->setChecked(TRUE);
			break;
		case euGBYTE:
			RadioButton_UNITGBYTE->setChecked(TRUE);
			break;
		default:
			RadioButton_UNITAUTO->setChecked(TRUE);
			break;
	}

	LineEdit_APPFONT->setText( g_pConfig->GetAppFont().Data() );
	CheckBox_CUSTOM_FONT->setChecked( g_pConfig->GetUseCustomFont() );
	slotCustomFontChecked();
	LineEdit_DATAFOLDER->setText(g_pConfig->GetValknutDataPath());
	CheckBox_SHOWSTATUSMESSAGE->setChecked( g_pConfig->GetShowStatusMessage() );
	CheckBox_QUERYONEXIT->setChecked( g_pConfig->GetQueryOnExit() );
	CheckBox_QUERYONFILEDELETE->setChecked( g_pConfig->GetQueryOnFileDelete() );

	// gui->transfer
	CheckBox_TV_PERCENTCHUNK->setChecked(g_pConfig->GetTransferViewOptions(etvoCHUNKPERCENT));
	CheckBox_TV_PERCENTFILE->setChecked(g_pConfig->GetTransferViewOptions(etvoFILEPERCENT));
	CheckBox_TV_CHUNKSIZE->setChecked(g_pConfig->GetTransferViewOptions(etvoCHUNKSIZE));
	CheckBox_TV_FILESIZE->setChecked(g_pConfig->GetTransferViewOptions(etvoFILESIZE));
	CheckBox_TV_DOWNLOADRATESINGLE->setChecked(g_pConfig->GetTransferViewOptions(etvoDOWNLOADRATESINGLE));
	CheckBox_TV_ELAPSEDTIMESINGLE->setChecked(g_pConfig->GetTransferViewOptions(etvoELAPSEDTIMESINGLE));
	CheckBox_TV_DOWNLOADRATEMULTI->setChecked(g_pConfig->GetTransferViewOptions(etvoDOWNLOADRATEMULTI));
	CheckBox_TV_ELAPSEDTIMEMULTI->setChecked(g_pConfig->GetTransferViewOptions(etvoELAPSEDTIMEMULTI));

	// gui->chat
	CheckBox_OPENPRIVATECHATWINDOW->setChecked(g_pConfig->GetOpenPrivateChatWindow());
	CheckBox_SHOWCHATINTAB->setChecked(g_pConfig->GetShowChatInTab());
	CheckBox_SENDHIDEPRIVATECHATTOPUBLICCHAT->setChecked( g_pConfig->GetSendHidePrivateChatToPublicChat());
	CheckBox_EMOTICONS->setChecked(g_pConfig->GetEnableEmoticons());
	CheckBox_SHOWCHATSENDBUTTON->setChecked(g_pConfig->GetShowChatSendButton());
	CheckBox_CHATSHOWJOINSANDPARTS->setChecked(g_pConfig->GetChatShowJoinsAndParts());
	CheckBox_CHATSHOWJOINSANDPARTSONLYFAV->setChecked(g_pConfig->GetChatShowJoinsAndPartsOnlyFav());
	CheckBox_CHATRECVOFFLINEMESSAGES->setChecked(g_pConfig->GetChatRecvOfflineMessages());
	CheckBox_CHATSENDOFFLINEMESSAGES->setChecked(g_pConfig->GetChatSendOfflineMessages());
	SpinBox_CHATMAXPARAGRAPH->setValue(g_pConfig->GetChatMaxParagraph());
	SpinBox_CHATMESSAGEMAXLINES->setValue( g_pConfig->GetChatMessageMaxLines() );
	LineEdit_SUPPRESS_NICKS->setText( g_pConfig->GetSuppressedNicks() );
	CheckBox_SENDUNKNOWNCOMMANDS->setChecked(g_pConfig->GetSendUnknownCommandsAsChat());
	slotSendUnknownCommandsChecked();
	LineEdit_ALLOWED_UNKNOWN_COMMANDS->setText(g_pConfig->GetAllowedUnknownCommands());
	
	for(i=0;i<ComboBox_SENDCHAT->count();i++)
	{
		if ( g_pConfig->GetSendChat() == CString(ComboBox_SENDCHAT->text(i).toAscii().data()) )
		{
			ComboBox_SENDCHAT->setCurrentItem(i);
			break;
		}
	}

	LineEdit_BROWSER->setText(g_pConfig->GetBrowser().Data());

	QColor c;
	QPixmap p(10,10);

	c.setNamedColor(g_pConfig->GetChatColor(eccCHATTIMESTAMP).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Chat Timestamp"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccCHATLOCALNICK).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Chat Local Nick"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccCHATLOCALTEXT).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Chat Local Text"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccCHATREMOTENICK).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Chat Remote Nick"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccCHATREMOTETEXT).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Chat Remote Text"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccCHATSTATUSNICK).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Chat Status Nick"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccCHATSTATUSTEXT).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Chat Status Text"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccPUBLICCHATTIMESTAMP).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Public Chat Timestamp"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccPUBLICCHATLOCALNICK).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Public Chat Local Nick"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccPUBLICCHATLOCALTEXT).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Public Chat Local Text"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccPUBLICCHATREMOTENICK).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Public Chat Remote Nick"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccPUBLICCHATREMOTETEXT).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Public Chat Remote Text"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccPUBLICCHATSTATUSNICK).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Public Chat Status Nick"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccPUBLICCHATSTATUSTEXT).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Public Chat Status Text"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccPUBLICPRIVATECHATNICK).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Public Private Chat Nick"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccPUBLICPRIVATECHATTEXT).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Public Private Chat Text"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccCHATSAY).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Chat Say"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccPUBLICCHATMENICK).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Public Chat ME Nick"), ListBox_CHATCOLOR );
	c.setNamedColor(g_pConfig->GetChatColor(eccOPNICK).Data());
	p.fill(c);
	new QListWidgetItem( QIcon(p), tr("Operator Nick"), ListBox_CHATCOLOR );
	
	// gui->client
	CheckBox_CLIENTWINDOWSMINIMIZED->setChecked(g_pConfig->GetOpenClientWindowsMinimized());
	CheckBox_USERLISTRIGHTALIGNMENT->setChecked(g_pConfig->GetUserListRightAlignment());
	CheckBox_AUTOAWAYMODE->setChecked(g_pConfig->GetAutoAwayMode());
	SpinBox_AUTOAWAYTIME->setValue(g_pConfig->GetAutoAwayTime());
	CheckBox_CLIENTCOLUMNS_COMMENT->setChecked(g_pConfig->GetClientColumn(eclcCOMMENT));
	CheckBox_CLIENTCOLUMNS_TAG->setChecked(g_pConfig->GetClientColumn(eclcTAG));
	CheckBox_CLIENTCOLUMNS_SPEED->setChecked(g_pConfig->GetClientColumn(eclcSPEED));
	CheckBox_CLIENTCOLUMNS_EMAIL->setChecked(g_pConfig->GetClientColumn(eclcEMAIL));
	CheckBox_CLIENTCOLUMNS_SHARE->setChecked(g_pConfig->GetClientColumn(eclcSHARE));
	CheckBox_CLIENTCOLUMNS_IP->setChecked(g_pConfig->GetClientColumn(eclcIP));
	CheckBox_CLIENTCOLUMNS_LOCKPK->setChecked(g_pConfig->GetClientColumn(eclcLOCKPK));
	CheckBox_CLIENTCOLUMNS_SUPPORTS->setChecked(g_pConfig->GetClientColumn(eclcSUPPORTS));
	
	if ( g_pConfig->GetDoubleClickAction() == ComboBox_DOUBLECLICK->text(1) )
	{
		ComboBox_DOUBLECLICK->setCurrentItem(1);
	}
	else
	{
		ComboBox_DOUBLECLICK->setCurrentItem(0);
	}
	
	// sound
	CheckBox_SOUNDDISABLED->setChecked(g_pConfig->GetSoundDisabled());
	CheckBox_SOUNDDISABLEDAWAY->setChecked(g_pConfig->GetSoundDisabledAway());
	CheckBox_EXTERNALPLAYER->setChecked(g_pConfig->GetExternalSoundPlayer());
	LineEdit_EXTERNALPLAYER->setText( g_pConfig->GetExternalPlayer().Data() );
	LineEdit_SOUNDFILECONNECT->setText( g_pConfig->GetSoundFile(eusCONNECT).Data() );
	LineEdit_SOUNDFILEDISCONNECT->setText( g_pConfig->GetSoundFile(eusDISCONNECT).Data() );
	LineEdit_SOUNDFILESEND->setText( g_pConfig->GetSoundFile(eusSEND).Data() );
	LineEdit_SOUNDFILERECEIVE->setText( g_pConfig->GetSoundFile(eusRECEIVE).Data() );
	LineEdit_SOUNDFILEFIRSTRECEIVE->setText( g_pConfig->GetSoundFile(eusFIRSTRECEIVE).Data() );
	LineEdit_SOUNDFILENICKMENTIONED->setText( g_pConfig->GetSoundFile(eusNICKMENTIONED).Data() );
	CheckBox_SOUNDPLAYCONNECT->setChecked(g_pConfig->GetSoundEnabled(eusCONNECT));
	CheckBox_SOUNDPLAYDISCONNECT->setChecked(g_pConfig->GetSoundEnabled(eusDISCONNECT));
	CheckBox_SOUNDPLAYSEND->setChecked(g_pConfig->GetSoundEnabled(eusSEND));
	CheckBox_SOUNDPLAYRECEIVE->setChecked(g_pConfig->GetSoundEnabled(eusRECEIVE));
	CheckBox_SOUNDPLAYFIRSTRECEIVE->setChecked(g_pConfig->GetSoundEnabled(eusFIRSTRECEIVE));
	CheckBox_SOUNDPLAYNICKMENTIONED->setChecked(g_pConfig->GetSoundEnabled(eusNICKMENTIONED));

	// log
	CheckBox_LOGFILE->setChecked(g_pConfig->GetLogFile());
	CheckBox_LOGDOWNLOADS->setChecked(g_pConfig->GetLogFinishedDownloads());
	CheckBox_LOGUPLOADS->setChecked(g_pConfig->GetLogFinishedUploads());
	CheckBox_LOGDETAILS->setChecked(g_pConfig->GetLogDetails());
	LineEdit_LOGFILENAME->setText( g_pConfig->GetLogFileName().Data() );
	CheckBox_TIMESTAMPPRIVATECHAT->setChecked(g_pConfig->GetTimeStamp(etsPRIVATECHAT));
	CheckBox_TIMESTAMPHUBCHAT->setChecked(g_pConfig->GetTimeStamp(etsHUBCHAT));

	CheckBox_LOGCHAT_ENABLELOGGING->setChecked( g_pConfig->GetLogChatOption(elcoENABLELOGGING) );
	CheckBox_LOGCHAT_APPENDDATE->setChecked( g_pConfig->GetLogChatOption(elcoAPPENDDATE) );
	CheckBox_LOGCHAT_APPENDHUBNAME->setChecked( g_pConfig->GetLogChatOption(elcoAPPENDHUBNAME) );
	CheckBox_LOGCHAT_APPENDHUBHOST->setChecked( g_pConfig->GetLogChatOption(elcoAPPENDHUBHOST) );
	CheckBox_LOGCHAT_DISABLEPUBLICCHAT->setChecked( g_pConfig->GetLogChatOption(elcoDISABLEPUBLICCHAT) );
	CheckBox_LOGCHAT_ENABLENICKNAMEFILTER->setChecked( g_pConfig->GetLogChatOption(elcoENABLENICKNAMEFILTER) );
	CheckBox_LOGCHAT_NICKNAMEFILTER_ENABLELOGGING->setChecked( g_pConfig->GetLogChatOption(elcoNICKNAMEFILTER_ENABLELOGGING) );

	CList<CString> nnflist;
	CString * ps = 0;
	g_pConfig->GetLogChatNickNameFilter( &nnflist );

	ListBox_LOGCHAT_NICKNAMEFILTER_LIST->clear();

	while( (ps=nnflist.Next(ps)) != 0 )
	{
		new QListWidgetItem( ps->Data(), ListBox_LOGCHAT_NICKNAMEFILTER_LIST );
	}

	// other
	CheckBox_HUBLISTSTORELOCAL->setChecked(g_pConfig->GetHubListStoreLocal());
	SpinBox_RELOADHUBLISTTIME->setValue(g_pConfig->GetReloadHubListTime());

	DCConfigHubListUrl * hublisturl = 0;

	CList<DCConfigHubListUrl> hublisturllist;
	g_pConfig->GetHubListUrlList(&hublisturllist);

	while( (hublisturl=hublisturllist.Next(hublisturl)) != 0 )
	{
		QListWidgetItem * lwi = new QListWidgetItem( hublisturl->sUrl.Data(), ListWidget_HUBLISTURL );
		if ( hublisturl->bEnabled )
		{
			lwi->setCheckState( Qt::Checked );
		}
		else
		{
			lwi->setCheckState( Qt::Unchecked );
		}
	}

	// security
	SpinBox_FLOODCOUNT->setValue(g_pConfig->GetFloodCount());
	CheckBox_FLOODOPKICK->setChecked(g_pConfig->GetFloodOpKick());
	LineEdit_FLOODOPKICKMESSAGE->setText(QString(g_pConfig->GetFloodOpKickMessage().Data()).replace( "\r", "" ));
	LineEdit_TRANSFERCERT->setText(g_pConfig->GetTransferCert().Data());
	LineEdit_TRANSFERKEY->setText(g_pConfig->GetTransferKey().Data());
	LineEdit_DCLIB_PLUGIN_PATH->setText(g_pConfig->GetDCLibPluginPath().Data());

	// init the sound tab
	slotDisableSound();
	// init log tab
	slotLogChatEnableLogging();
	// init away
	slotAutoAwayMode();
	// init show joins parts only fav enabled/disabled
	slotEnableShowJoinsParts();
	
	// auto response settings
	CheckBox_ENABLE_AUTO_RESPONDER->setChecked(g_pConfig->GetAutoResponderEnabled());
	CheckBox_ENABLE_AUTO_RESPONDER_FOR_PM->setChecked(g_pConfig->GetAutoResponderEnabledForPM());
	SpinBox_AUTORESPONSEDELAY->setValue(g_pConfig->GetAutoResponseDelay());
	LineEdit_AUTO_RESPONSE_IGNORE->setText(g_pConfig->GetAutoResponseIgnores().Data());
	
	// fill auto response list box
	g_pConfig->GetAutoResponses(&arlist);
	aro = 0;
	while( (aro=arlist.Next(aro)) != 0)
	{
		QString cs;
		if (aro->m_bCaseSensitive == TRUE)
		{
			cs = tr("Yes");
		}
		else
		{
			cs = tr("No");
		}
		qtwitem = new QTreeWidgetItem( TreeWidget_AUTO_RESPONSES );
		qtwitem->setText( 0, aro->m_sTrigger.Data() );
		qtwitem->setText( 1, cs );
		qtwitem->setText( 2, aro->m_sResponse.Data() );
		qtwitem->setFlags( qtwitem->flags() | Qt::ItemIsEditable );
	}
	
	ComboBox_REMOTE_ENCODING->setCurrentText( g_pConfig->GetRemoteEncoding().Data() );
	
	CheckBox_FOLDERS_RIGHT_PANE->setChecked(g_pConfig->GetFoldersInRightPane());
	CheckBox_FOLDERS_RIGHT_PANE_ON_TOP->setChecked(g_pConfig->GetFoldersInRightPaneOnTop());
	CheckBox_SIZES_LEFT_PANE->setChecked(g_pConfig->GetFolderSizesInLeftPane());
	
	CheckBox_ENABLE_USERIP2->setChecked(g_pConfig->GetUserIP2Enabled());
	CheckBox_ENABLE_ZLINE->setChecked(g_pConfig->GetZLineEnabled());
	CheckBox_ADJUST_SR->setChecked(g_pConfig->GetAdjustSearchResultHubNames());
	CheckBox_ENABLE_REMOVE_PUBLIC_HUB->setChecked(g_pConfig->GetRemovePublicHubEnabled());
	ComboBox_TAB_COMPLETE_MATCH_MODE->setCurrentIndex(g_pConfig->GetTabCompleteMatchMode());
	CheckBox_TAB_COMPLETE_STRIP_TAGS->setChecked(g_pConfig->GetTabCompleteStripTags());
	
	SpinBox_READFILEBUFFERSIZE->setValue(g_pConfig->GetReadFileBufferSize());
	
	CheckBox_NO_ADCGET_WITHOUT_TTH->setChecked(g_pConfig->GetDisableADCGetWithoutTTH());
	CheckBox_NO_XMLLIST_WITHOUT_TTH->setChecked(g_pConfig->GetDisableXMLListWithoutTTH());
	CheckBox_THREADS_FOR_SHELL_COMMANDS->setChecked(g_pConfig->GetThreadsForShellCommands());
	SpinBox_SHELL_COMMAND_TIMEOUT->setValue(g_pConfig->GetShellCommandTimeout());
	CheckBox_OPEN_FOLDERS_RIGHT_PANE->setChecked(g_pConfig->GetOpenFoldersInRightPane());
}

/** */
void DCOptions::GetValues()
{
	g_pConfig->SetNick(LineEdit_NICK->text().toAscii().data());
	g_pConfig->SetSearchNick(LineEdit_SEARCHNICK->text().toAscii().data());
	g_pConfig->SetAwayMessage(TextEdit_AWAYMESSAGE->text().replace( "\n", "\xd\xa" ).toAscii().data());
	g_pConfig->SetDescription(LineEdit_DESCRIPTION->text().toAscii().data());
	g_pConfig->SetAwayPrefix(LineEdit_AWAYPREFIX->text().toAscii().data());
	g_pConfig->SetDescriptionTag(CheckBox_DESCRIPTION_TAG->isChecked());
	g_pConfig->SetUseExtendedHubCount(CheckBox_EXT_HUB_COUNT->isChecked());
	g_pConfig->SetEMail(LineEdit_EMAIL->text().toAscii().data());
	g_pConfig->SetAntiSpam(CheckBox_ANTISPAM->isChecked());
	g_pConfig->SetCheckPrivateAddressSpace(CheckBox_CHECKPRIVATEADDRESSSPACE->isChecked());
	g_pConfig->SetShowChatSendButton(CheckBox_SHOWCHATSENDBUTTON->isChecked());
	g_pConfig->SetBrowser(LineEdit_BROWSER->text().toAscii().data());
	g_pConfig->SetDynamicUploadRate(CheckBox_DYNAMICUPLOADRATE->isChecked());
	g_pConfig->SetShowChatInTab(CheckBox_SHOWCHATINTAB->isChecked());
	g_pConfig->SetChatMaxParagraph(SpinBox_CHATMAXPARAGRAPH->value());
	g_pConfig->SetTransferAutoSearch(CheckBox_TRANSFERAUTOSEARCH->isChecked());
	g_pConfig->SetDisableHashList(CheckBox_DISABLEHASHLIST->isChecked());
	g_pConfig->SetCompressedTransfers(CheckBox_COMPRESSEDTRANSFERS->isChecked());

	g_pConfig->SetUserPhotoFileName(ToolButton_PHOTO->textLabel().toAscii().data());

	g_pConfig->SetSpeed(ComboBox_SPEED->currentText().toAscii().data());
	g_pConfig->SetDownloadFolder(LineEdit_DOWNLOADFOLDER->text().toAscii().data());
	g_pConfig->SetDownloadFinishedFolder(LineEdit_DOWNLOADFINISHEDFOLDER->text().toAscii().data());
	g_pConfig->SetValknutDataPath(LineEdit_DATAFOLDER->text());
	
	g_pConfig->SetAutoRecreateShareList(CheckBox_AUTORECREATESHARELIST->isChecked());
	g_pConfig->SetDontShareDotFiles(CheckBox_DONTSHAREDOTFILES->isChecked());
	g_pConfig->SetRecreateShareListTime(SpinBox_RECREATESHARELISTTIME->value());

	g_pConfig->SetFloodOpKickMessage(LineEdit_FLOODOPKICKMESSAGE->text().replace( "\n", "\xd\xa" ).toAscii().data());
	g_pConfig->SetFloodCount(SpinBox_FLOODCOUNT->value());
	g_pConfig->SetFloodOpKick(CheckBox_FLOODOPKICK->isChecked());

	g_pConfig->SetTransferCert(LineEdit_TRANSFERCERT->text().toAscii().data());
	g_pConfig->SetTransferKey(LineEdit_TRANSFERKEY->text().toAscii().data());
	g_pConfig->SetDCLibPluginPath(LineEdit_DCLIB_PLUGIN_PATH->text().toAscii().data());

	SaveSharedFolders();
	SaveUserMenuCommands();
	SaveUserChatCommands();

	g_pConfig->SetAutoResponderEnabled(CheckBox_ENABLE_AUTO_RESPONDER->isChecked());
	g_pConfig->SetAutoResponderEnabledForPM(CheckBox_ENABLE_AUTO_RESPONDER_FOR_PM->isChecked());
	g_pConfig->SetAutoResponseDelay(SpinBox_AUTORESPONSEDELAY->value());
	g_pConfig->SetAutoResponseIgnores(LineEdit_AUTO_RESPONSE_IGNORE->text().toAscii().data());
	SaveAutoResponses();

	g_pConfig->SetMaxUpload( SpinBox_MAXSIMULTANEOUSUPLOADS->value() );
	g_pConfig->SetMaxUploadRate( (ULONGLONG) (SpinBox_MAXUPLOADRATE->value()*1024) );
	g_pConfig->SetMaxDownloadRate( (ULONGLONG) (SpinBox_MAXDOWNLOADRATE->value()*1024) );
	g_pConfig->SetDownloadQueueTime(SpinBox_SAVEDOWNLOADQUEUETIME->value());
	g_pConfig->SetAutoSearchInterval(SpinBox_AUTOSEARCHINTERVAL->value());
	g_pConfig->SetSmallFileSize(SpinBox_SMALLFILESIZE->value());

	g_pConfig->SetTCPListenPort(SpinBox_TCPLISTENPORT->value());
	g_pConfig->SetUDPListenPort(SpinBox_UDPLISTENPORT->value());
	g_pConfig->SetExternalIP(RadioButton_IPHOSTNAME->isOn());

	if ( RadioButton_ACTIVEMODE->isOn() )
		g_pConfig->SetMode(ecmACTIVE);
	else
		g_pConfig->SetMode(ecmPASSIVE);

	g_pConfig->SetHost(LineEdit_IP->text().toAscii().data());
	g_pConfig->SetListenHost(LineEdit_LISTENIP->text().toAscii().data());	
	g_pConfig->SetSendMessageOnActiveModeRequest(CheckBox_SENDMESSAGEONACTIVEMODEREQUEST->isChecked());

	// gui settings
	g_pConfig->SetOpenPrivateChatWindow(CheckBox_OPENPRIVATECHATWINDOW->isChecked());
	g_pConfig->SetEnableEmoticons(CheckBox_EMOTICONS->isChecked());

	if ( RadioButton_UNITBYTE->isChecked() )
		g_pConfig->SetUnit(euBYTE);
	else if ( RadioButton_UNITKBYTE->isChecked() )
		g_pConfig->SetUnit(euKBYTE);
	else if ( RadioButton_UNITMBYTE->isChecked() )
		g_pConfig->SetUnit(euMBYTE);
	else if ( RadioButton_UNITGBYTE->isChecked() )
		g_pConfig->SetUnit(euGBYTE);
	else
		g_pConfig->SetUnit(euAUTO);
	
	g_pConfig->SetTheme(ComboBox_THEME->currentText().toAscii().data());
	g_pConfig->SetSendChat(ComboBox_SENDCHAT->currentText().toAscii().data());
	g_pConfig->SetLanguageFile(LineEdit_LANGUAGEFILE->text().toAscii().data());
	g_pConfig->SetShowStatusMessage(CheckBox_SHOWSTATUSMESSAGE->isChecked());
	g_pConfig->SetQueryOnExit(CheckBox_QUERYONEXIT->isChecked());
	g_pConfig->SetQueryOnFileDelete(CheckBox_QUERYONFILEDELETE->isChecked());
	g_pConfig->SetSendHidePrivateChatToPublicChat(CheckBox_SENDHIDEPRIVATECHATTOPUBLICCHAT->isChecked());
	g_pConfig->SetChatSendOfflineMessages(CheckBox_CHATSENDOFFLINEMESSAGES->isChecked());
	g_pConfig->SetChatRecvOfflineMessages(CheckBox_CHATRECVOFFLINEMESSAGES->isChecked());
	g_pConfig->SetChatMessageMaxLines( SpinBox_CHATMESSAGEMAXLINES->value() );
	g_pConfig->SetSuppressedNicks( LineEdit_SUPPRESS_NICKS->text() );
	g_pConfig->SetSendUnknownCommandsAsChat( CheckBox_SENDUNKNOWNCOMMANDS->isChecked() );
	g_pConfig->SetAllowedUnknownCommands( LineEdit_ALLOWED_UNKNOWN_COMMANDS->text() );

	// sound settings
	g_pConfig->SetSoundDisabled(CheckBox_SOUNDDISABLED->isChecked());
	g_pConfig->SetSoundDisabledAway(CheckBox_SOUNDDISABLEDAWAY->isChecked());

	g_pConfig->SetSoundEnabled(eusCONNECT,CheckBox_SOUNDPLAYCONNECT->isChecked());
	g_pConfig->SetSoundEnabled(eusDISCONNECT,CheckBox_SOUNDPLAYDISCONNECT->isChecked());
	g_pConfig->SetSoundEnabled(eusSEND,CheckBox_SOUNDPLAYSEND->isChecked());
	g_pConfig->SetSoundEnabled(eusRECEIVE,CheckBox_SOUNDPLAYRECEIVE->isChecked());
	g_pConfig->SetSoundEnabled(eusFIRSTRECEIVE,CheckBox_SOUNDPLAYFIRSTRECEIVE->isChecked());
	g_pConfig->SetSoundEnabled(eusNICKMENTIONED,CheckBox_SOUNDPLAYNICKMENTIONED->isChecked());

	g_pConfig->SetExternalSoundPlayer(CheckBox_EXTERNALPLAYER->isChecked());
	g_pConfig->SetExternalPlayer(LineEdit_EXTERNALPLAYER->text().toAscii().data());
	g_pConfig->SetSoundFile( eusCONNECT, LineEdit_SOUNDFILECONNECT->text().toAscii().data());
	g_pConfig->SetSoundFile( eusDISCONNECT, LineEdit_SOUNDFILEDISCONNECT->text().toAscii().data());
	g_pConfig->SetSoundFile( eusSEND, LineEdit_SOUNDFILESEND->text().toAscii().data());
	g_pConfig->SetSoundFile( eusRECEIVE, LineEdit_SOUNDFILERECEIVE->text().toAscii().data());
	g_pConfig->SetSoundFile( eusFIRSTRECEIVE, LineEdit_SOUNDFILEFIRSTRECEIVE->text().toAscii().data());
	g_pConfig->SetSoundFile( eusNICKMENTIONED, LineEdit_SOUNDFILENICKMENTIONED->text().toAscii().data());
 
	g_pConfig->SetAppFont(LineEdit_APPFONT->text().toAscii().data());
	g_pConfig->SetUseCustomFont(CheckBox_CUSTOM_FONT->isChecked());

	// gui->chat
	g_pConfig->SetChatShowJoinsAndParts(CheckBox_CHATSHOWJOINSANDPARTS->isChecked());
	g_pConfig->SetChatShowJoinsAndPartsOnlyFav(CheckBox_CHATSHOWJOINSANDPARTSONLYFAV->isChecked());
	
	// gui->client
	g_pConfig->SetOpenClientWindowsMinimized(CheckBox_CLIENTWINDOWSMINIMIZED->isChecked());
	g_pConfig->SetUserListRightAlignment(CheckBox_USERLISTRIGHTALIGNMENT->isChecked());
	g_pConfig->SetAutoAwayMode(CheckBox_AUTOAWAYMODE->isChecked());
	g_pConfig->SetAutoAwayTime(SpinBox_AUTOAWAYTIME->value());
	g_pConfig->SetClientColumn(eclcCOMMENT,CheckBox_CLIENTCOLUMNS_COMMENT->isChecked());
	g_pConfig->SetClientColumn(eclcTAG,CheckBox_CLIENTCOLUMNS_TAG->isChecked());
	g_pConfig->SetClientColumn(eclcSPEED,CheckBox_CLIENTCOLUMNS_SPEED->isChecked());
	g_pConfig->SetClientColumn(eclcEMAIL,CheckBox_CLIENTCOLUMNS_EMAIL->isChecked());
	g_pConfig->SetClientColumn(eclcSHARE,CheckBox_CLIENTCOLUMNS_SHARE->isChecked());
	g_pConfig->SetClientColumn(eclcIP,CheckBox_CLIENTCOLUMNS_IP->isChecked());
	g_pConfig->SetClientColumn(eclcLOCKPK,CheckBox_CLIENTCOLUMNS_LOCKPK->isChecked());
	g_pConfig->SetClientColumn(eclcSUPPORTS,CheckBox_CLIENTCOLUMNS_SUPPORTS->isChecked());
	g_pConfig->SetDoubleClickAction(ComboBox_DOUBLECLICK->currentText());
	
	QString oldemoticons = g_pConfig->GetEmoticonTheme();
	
	// gui->icons
	if ( ComboBox_APPLICATION_ICONS->count() > 0 )
	{
		g_pConfig->SetApplicationIconTheme(ComboBox_APPLICATION_ICONS->currentText());
	}
	if ( ComboBox_EMOTICONS->count() > 0 )
	{
		g_pConfig->SetEmoticonTheme(ComboBox_EMOTICONS->currentText());
	}
	if ( ComboBox_USERLIST_ICONS->count() > 0 )
	{
		g_pConfig->SetUserListIconTheme(ComboBox_USERLIST_ICONS->currentText());
	}
	// reload icons with new theme
	g_pIconLoader->Load();
	// reload emoticons
	if ( g_pConfig->GetEmoticonTheme() != oldemoticons )
	{
		g_pConfig->InitMimeSourceFactory();
	}
	
	// log settings
	g_pConfig->SetLogFile(CheckBox_LOGFILE->isChecked());
	g_pConfig->SetLogFinishedDownloads(CheckBox_LOGDOWNLOADS->isChecked());
	g_pConfig->SetLogFinishedUploads(CheckBox_LOGUPLOADS->isChecked());
	g_pConfig->SetLogDetails(CheckBox_LOGDETAILS->isChecked());
	g_pConfig->SetLogFileName( LineEdit_LOGFILENAME->text().toAscii().data() );
	g_pConfig->SetTimeStamp(etsPRIVATECHAT,CheckBox_TIMESTAMPPRIVATECHAT->isChecked());
	g_pConfig->SetTimeStamp(etsHUBCHAT,CheckBox_TIMESTAMPHUBCHAT->isChecked());

	g_pConfig->SetLogChatOption(elcoENABLELOGGING, CheckBox_LOGCHAT_ENABLELOGGING->isChecked() );
	g_pConfig->SetLogChatOption(elcoAPPENDDATE, CheckBox_LOGCHAT_APPENDDATE->isChecked() );
	g_pConfig->SetLogChatOption(elcoAPPENDHUBNAME, CheckBox_LOGCHAT_APPENDHUBNAME->isChecked() );
	g_pConfig->SetLogChatOption(elcoAPPENDHUBHOST, CheckBox_LOGCHAT_APPENDHUBHOST->isChecked() );
	g_pConfig->SetLogChatOption(elcoDISABLEPUBLICCHAT, CheckBox_LOGCHAT_DISABLEPUBLICCHAT->isChecked() );
	g_pConfig->SetLogChatOption(elcoENABLENICKNAMEFILTER, CheckBox_LOGCHAT_ENABLENICKNAMEFILTER->isChecked() );
	g_pConfig->SetLogChatOption(elcoNICKNAMEFILTER_ENABLELOGGING, CheckBox_LOGCHAT_NICKNAMEFILTER_ENABLELOGGING->isChecked() );

	CList<CString> nnflist;
	uint i = 0;

	for(i=0;i<ListBox_LOGCHAT_NICKNAMEFILTER_LIST->count();i++)
	{
		nnflist.Add( new CString(ListBox_LOGCHAT_NICKNAMEFILTER_LIST->item(i)->text().toAscii().data()) );
	}

	g_pConfig->SetLogChatNickNameFilter( &nnflist );

	// other settings
	g_pConfig->SetHubListStoreLocal(CheckBox_HUBLISTSTORELOCAL->isChecked());
	g_pConfig->SetReconnectCount( SpinBox_RECONNECTCOUNT->value() );
	g_pConfig->SetReconnectTimeout( SpinBox_RECONNECTTIMEOUT->value() );
	g_pConfig->SetTransferResendTimeout(SpinBox_TRANSFERRESENDTIMEOUT->value());
	g_pConfig->SetTransferResponseTimeout(SpinBox_TRANSFERRESPONSETIMEOUT->value());
	g_pConfig->SetForceMoveEnabled(CheckBox_FORCEMOVEENABLED->isChecked());
	g_pConfig->SetReloadHubListTime(SpinBox_RELOADHUBLISTTIME->value());

	// transfer view settings
	g_pConfig->SetTransferViewOptions(etvoCHUNKPERCENT,CheckBox_TV_PERCENTCHUNK->isChecked());
	g_pConfig->SetTransferViewOptions(etvoFILEPERCENT,CheckBox_TV_PERCENTFILE->isChecked());
	g_pConfig->SetTransferViewOptions(etvoCHUNKSIZE,CheckBox_TV_CHUNKSIZE->isChecked());
	g_pConfig->SetTransferViewOptions(etvoFILESIZE,CheckBox_TV_FILESIZE->isChecked());
	g_pConfig->SetTransferViewOptions(etvoDOWNLOADRATESINGLE,CheckBox_TV_DOWNLOADRATESINGLE->isChecked());
	g_pConfig->SetTransferViewOptions(etvoELAPSEDTIMESINGLE,CheckBox_TV_ELAPSEDTIMESINGLE->isChecked());
	g_pConfig->SetTransferViewOptions(etvoDOWNLOADRATEMULTI,CheckBox_TV_DOWNLOADRATEMULTI->isChecked());
	g_pConfig->SetTransferViewOptions(etvoELAPSEDTIMEMULTI,CheckBox_TV_ELAPSEDTIMEMULTI->isChecked());
	g_pConfig->SetUserUploadSlots(SpinBox_USERUPLOADSLOTS->value());

        if ( RadioButton_NONE->isChecked() )
		g_pConfig->SetHubOfflineTransferClose( ectNONE );
	else if ( RadioButton_UPLOAD->isChecked() )
		g_pConfig->SetHubOfflineTransferClose( ectUPLD );
	else if ( RadioButton_DOWNLOAD->isChecked() )
		g_pConfig->SetHubOfflineTransferClose( ectDLD );
	else if ( RadioButton_BOTH->isChecked() )
		g_pConfig->SetHubOfflineTransferClose( ectBOTH );

	CList<DCConfigHubListUrl> hublisturllist;

	for ( i = 0; i < ListWidget_HUBLISTURL->count(); i++ )
	{
		DCConfigHubListUrl * hublisturl = new DCConfigHubListUrl();

		QListWidgetItem * item = ListWidget_HUBLISTURL->item(i);
		hublisturl->sUrl     = item->text();
		hublisturl->bEnabled = (item->checkState() == Qt::Checked);

		hublisturllist.Add(hublisturl);
	}

	g_pConfig->SetHubListUrlList(&hublisturllist);

	i=0;

	g_pConfig->SetChatColor(eccCHATTIMESTAMP,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccCHATLOCALNICK,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccCHATLOCALTEXT,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccCHATREMOTENICK,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccCHATREMOTETEXT,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccCHATSTATUSNICK,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccCHATSTATUSTEXT,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccPUBLICCHATTIMESTAMP,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccPUBLICCHATLOCALNICK,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccPUBLICCHATLOCALTEXT,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccPUBLICCHATREMOTENICK,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccPUBLICCHATREMOTETEXT,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccPUBLICCHATSTATUSNICK,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccPUBLICCHATSTATUSTEXT,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccPUBLICPRIVATECHATNICK,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccPUBLICPRIVATECHATTEXT,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccCHATSAY,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccPUBLICCHATMENICK,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	g_pConfig->SetChatColor(eccOPNICK,QColor(ListBox_CHATCOLOR->item(i++)->icon().pixmap(10,10).toImage().pixel(0,0)).name().toAscii().data());
	
	g_pConfig->SetRemoteEncoding(ComboBox_REMOTE_ENCODING->currentText().toAscii().data());
	
	if ( ComboBox_REMOTE_ENCODING->currentText().lower() == "none" )
	{
		QTextCodec::setCodecForCStrings( QTextCodec::codecForLocale() );
	}
	else
	{
		QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
	}
	
	g_pConfig->SetFoldersInRightPane(CheckBox_FOLDERS_RIGHT_PANE->isChecked());
	g_pConfig->SetFoldersInRightPaneOnTop(CheckBox_FOLDERS_RIGHT_PANE_ON_TOP->isChecked());
	g_pConfig->SetFolderSizesInLeftPane(CheckBox_SIZES_LEFT_PANE->isChecked());
	
	g_pConfig->SetUserIP2Enabled(CheckBox_ENABLE_USERIP2->isChecked());
	g_pConfig->SetZLineEnabled(CheckBox_ENABLE_ZLINE->isChecked());
	g_pConfig->SetAdjustSearchResultHubNames(CheckBox_ADJUST_SR->isChecked());
	
	/* If this has been turned off, we need to save the public hub list now */
	if ( (CheckBox_ENABLE_REMOVE_PUBLIC_HUB->isChecked() == FALSE) && (g_pConfig->GetRemovePublicHubEnabled() == TRUE) )
	{
		g_pConfig->SaveDCPublicHub();
	}
	g_pConfig->SetRemovePublicHubEnabled(CheckBox_ENABLE_REMOVE_PUBLIC_HUB->isChecked());
	
	g_pConfig->SetTabCompleteMatchMode(ComboBox_TAB_COMPLETE_MATCH_MODE->currentIndex());
	g_pConfig->SetTabCompleteStripTags(CheckBox_TAB_COMPLETE_STRIP_TAGS->isChecked());
	
	g_pConfig->SetReadFileBufferSize(SpinBox_READFILEBUFFERSIZE->value());
	
	g_pConfig->SetDisableADCGetWithoutTTH(CheckBox_NO_ADCGET_WITHOUT_TTH->isChecked());
	g_pConfig->SetDisableXMLListWithoutTTH(CheckBox_NO_XMLLIST_WITHOUT_TTH->isChecked());
	g_pConfig->SetThreadsForShellCommands(CheckBox_THREADS_FOR_SHELL_COMMANDS->isChecked());
	g_pConfig->SetShellCommandTimeout(SpinBox_SHELL_COMMAND_TIMEOUT->value());
	g_pConfig->SetOpenFoldersInRightPane(CheckBox_OPEN_FOLDERS_RIGHT_PANE->isChecked());
}

/** */
void DCOptions::SaveSharedFolders()
{
	CList<DCConfigShareFolder> sharedfolders;
	DCConfigShareFolder * csf;

	// save shared folders
	sharedfolders.Clear();

	QTreeWidgetItemIterator it( TreeWidget_SHAREDFOLDERS );

	for ( ; (*it); ++it )
	{
		csf = new DCConfigShareFolder();
		csf->m_sPath  = (*it)->text(0).toAscii().data();
		csf->m_sAlias = (*it)->text(1).toAscii().data();
		sharedfolders.Add(csf);
	}

	g_pConfig->SetSharedFolders( &sharedfolders );
}

void DCOptions::SaveUserMenuCommands()
{
	CList<DC_UserMenuCommand> commands;
	DC_UserMenuCommand * umc;
	
	commands.Clear();
	
	QTreeWidgetItemIterator it( TreeWidget_MENU_COMMANDS );
	
	for ( ; (*it); ++it )
	{
		umc = new DC_UserMenuCommand();
		umc->m_sName    = (*it)->text(0).toAscii().data();
		umc->m_nContext = (*it)->text(1).toInt();
		umc->m_sCommand = (*it)->text(2).toAscii().data();
		commands.Add(umc);
	}
	
	g_pConfig->SetUserMenuCommands( &commands );
}

void DCOptions::SaveUserChatCommands()
{
	CList<DC_UserChatCommand> commands;
	DC_UserChatCommand * ucc;
	
	commands.Clear();
	
	QTreeWidgetItemIterator it( TreeWidget_CHAT_COMMANDS );
	
	for( ; (*it); ++it )
	{
		ucc = new DC_UserChatCommand();
		ucc->m_sName    = (*it)->text(0).toAscii().data();
		ucc->m_sCommand = (*it)->text(1).toAscii().data();
		
		commands.Add(ucc);
	}
	
	g_pConfig->SetUserChatCommands( &commands );
}

void DCOptions::SaveAutoResponses()
{
	CList<DC_AutoResponseObject> autoresponses;
	DC_AutoResponseObject * aro = 0;
	
	autoresponses.Clear();
	
	QTreeWidgetItemIterator it( TreeWidget_AUTO_RESPONSES );
	for ( ; (*it); ++it)
	{
		aro = new DC_AutoResponseObject();
		aro->m_sTrigger = (*it)->text(0).toAscii().data();
		if ( (*it)->text(1) == tr("Yes") )
		{
			aro->m_bCaseSensitive = TRUE;
		}
		else
		{
			aro->m_bCaseSensitive = FALSE;
		}
		aro->m_sResponse = (*it)->text(2).toAscii().data();
		
		autoresponses.Add(aro);
	}
	
	g_pConfig->SetAutoResponses( &autoresponses );
}

/** */
void DCOptions::slotCreateShareList()
{
	SaveSharedFolders();

	if ( CFileManager::Instance() )
	{
		CFileManager::Instance()->CreateShareList();
	}
}

/** */
void DCOptions::slotShareListInfo()
{
	QString s;

	if ( CFileManager::Instance()->GetShareSize() == 0 )
	{
		s = tr("Share list not available");
	}
	else
	{
		s = tr("Compressed list size (HE3/BZ/XML): ") +
			QString().setNum(CFileManager::Instance()->GetShareBufferSize(esbtHE3)) + "/" +
			QString().setNum(CFileManager::Instance()->GetShareBufferSize(esbtBZ)) + "/" +
			QString().setNum(CFileManager::Instance()->GetShareBufferSize(esbtXMLBZ)) + " " +
			tr("bytes") + "\n" +
			tr("Total shared: ") +
			QString(CUtils::GetSizeString(CFileManager::Instance()->GetShareSize(),g_pConfig->GetUnit()).Data());
	}

	QMessageBox::information( this, tr("Share List Info"), s );
}

/** */
void DCOptions::slotSetTheme()
{
	QString s;

	if ( g_pConfig->GetThemeSupport() == TRUE )
	{
		s = ComboBox_THEME->currentText();

		if ( s != "" )
		{
			QApplication::setStyle(s);
		}
	}
}

/** */
void DCOptions::slotBrowseLanguageFile()
{
	QString file;

	file = QFileDialog::getOpenFileName( this, tr("Select language file"), LineEdit_LANGUAGEFILE->text(), "Language File (*.qm)" );

	if( file != "" )
	{
		LineEdit_LANGUAGEFILE->setText(file);
	}
}

/** */
void DCOptions::slotSelectLanguage()
{
	QAction * chosen = 0;
	QMenu * m;
	DCMenuHandler mhandler;
	CString s = "";

	m = new QMenu(this);

	QAction * bosnian = mhandler.addAction( m, emiLANGUAGE_BOSNIAN );
	QAction * brazilian = mhandler.addAction( m, emiLANGUAGE_BRAZILIAN );
	QAction * czech = mhandler.addAction( m, emiLANGUAGE_CZECH );
	QAction * danish = mhandler.addAction( m, emiLANGUAGE_DANISH );
	QAction * dutch = mhandler.addAction( m, emiLANGUAGE_DUTCH );
	QAction * english = mhandler.addAction( m, emiLANGUAGE_ENGLISH );
	QAction * finnish = mhandler.addAction( m, emiLANGUAGE_FINNISH );
	QAction * french = mhandler.addAction( m, emiLANGUAGE_FRENCH );
	QAction * german = mhandler.addAction( m, emiLANGUAGE_GERMAN );
	QAction * greek = mhandler.addAction( m, emiLANGUAGE_GREEK );
	QAction * hungarian = mhandler.addAction( m, emiLANGUAGE_HUNGARIAN );
	QAction * icelandic = mhandler.addAction( m, emiLANGUAGE_ICELANDIC );
	QAction * italian = mhandler.addAction( m, emiLANGUAGE_ITALIAN );
	QAction * latvian = mhandler.addAction( m, emiLANGUAGE_LATVIAN );
	QAction * norwegian = mhandler.addAction( m, emiLANGUAGE_NORWEGIAN );
	QAction * polish = mhandler.addAction( m, emiLANGUAGE_POLISH );
	QAction * romanian = mhandler.addAction( m, emiLANGUAGE_ROMANIAN );
	QAction * russian = mhandler.addAction( m, emiLANGUAGE_RUSSIAN );
	QAction * slovakian = mhandler.addAction( m, emiLANGUAGE_SLOVAKIAN );
	QAction * spanish = mhandler.addAction( m, emiLANGUAGE_SPANISH );
	QAction * swedish = mhandler.addAction( m, emiLANGUAGE_SWEDISH );

	chosen = m->exec(QCursor::pos());

	delete m;

	if ( chosen == bosnian )
		s = "valknut.bs.qm";
	else if ( chosen == brazilian )
		s = "valknut.pt_br.qm";
	else if ( chosen == czech )
		s = "valknut.cs.qm";
	else if ( chosen == danish )
		s = "valknut.da.qm";
	else if ( chosen == dutch )
		s = "valknut.nl.qm";
	else if ( chosen == english )
		s = "";
	else if ( chosen == finnish )
		s = "valknut.fi.qm";
	else if ( chosen == french )
		s = "valknut.fr.qm";
	else if ( chosen == german )
		s = "valknut.de.qm";
	else if ( chosen == greek )
		s = "valknut.el.qm";
	else if ( chosen == hungarian )
		s = "valknut.hu.qm";
	else if ( chosen == icelandic )
		s = "valknut.is.qm";
	else if ( chosen == italian )
		s = "valknut.it.qm";
	else if ( chosen == latvian )
		s = "valknut.lv.qm";
	else if ( chosen == norwegian )
		s = "valknut.nb.qm";
	else if ( chosen == polish )
		s = "valknut.pl.qm";
	else if ( chosen == romanian )
		s = "valknut.ro.qm";
	else if ( chosen == russian )
		s = "valknut.rus.qm";
	else if ( chosen == slovakian )
		s = "valknut.sk.qm";
	else if ( chosen == spanish )
		s = "valknut.es.qm";
	else if ( chosen == swedish )
		s = "valknut.sv.qm";

	if ( s != "" )
	{
		LineEdit_LANGUAGEFILE->setText(LineEdit_DATAFOLDER->text()+QString(DIRSEPARATOR)+QString("translation")+QString(DIRSEPARATOR)+QString(s.Data()));
	}
	else if ( chosen == english )
	{
		LineEdit_LANGUAGEFILE->setText("");
	}
}

/** */
void DCOptions::slotBrowseAppFont()
{
  bool ok;
  QFont font = QFontDialog::getFont(&ok, QApplication::font(), this);
  if (ok == TRUE)
  {
	LineEdit_APPFONT->setText(font.toString());
  }
}

/** */
void DCOptions::slotCustomFontChecked()
{
	LineEdit_APPFONT->setEnabled(CheckBox_CUSTOM_FONT->isChecked());
	ToolButton_BROWSEAPPFONT->setEnabled(CheckBox_CUSTOM_FONT->isChecked());
}

/** */
void DCOptions::slotAddHubListUrl()
{
	bool ok = FALSE;
	QString url;

	url = QInputDialog::getText(
		tr("HubList URL"),
		tr("Please enter a url"),
		QLineEdit::Normal, QString::null, &ok, this );

	if (ok)
	{
		QListWidgetItem * item = new QListWidgetItem( url, ListWidget_HUBLISTURL );
		item->setCheckState( Qt::Checked );
	}
}

/** */
void DCOptions::slotEditHubListUrl()
{
	QListWidgetItem * item = ListWidget_HUBLISTURL->currentItem();

	if ( !item )
		return;

	bool ok = FALSE;
	QString url;

	url = QInputDialog::getText(
		tr("HubList URL"),
		tr("Edit url"),
		QLineEdit::Normal, item->text(), &ok, this );

	if (ok)
	{
		item->setText(url);
	}
}

/** */
void DCOptions::slotRemoveHubListUrl()
{
	QListWidgetItem * item = ListWidget_HUBLISTURL->currentItem();

	if ( item )
	{
		delete item;
	}
}

/** */
void DCOptions::slotTreeWidgetOptionTreeCurrentChanged( QTreeWidgetItem * item, QTreeWidgetItem * /* previous */ )
{
	if ( item == plviDCGUI )
	{
		TabWidget_DCGUI->setCurrentPage(0);
	}
	else if ( item == plviDCGUIIdentify )
	{
		TabWidget_DCGUI->setCurrentPage(0);
	}
	else if ( item == plviTransfer )
	{
		TabWidget_DCGUI->setCurrentPage(1);
		TabWidget_TRANSFER->setCurrentPage(0);
	}
	else if ( item == plviTransferFolder )
	{
		TabWidget_DCGUI->setCurrentPage(1);
		TabWidget_TRANSFER->setCurrentPage(0);
	}
	else if ( item == plviTransferSettings )
	{
		TabWidget_DCGUI->setCurrentPage(1);
		TabWidget_TRANSFER->setCurrentPage(1);
	}
	else if ( item == plviConnection )
	{
		TabWidget_DCGUI->setCurrentPage(2);
		TabWidget_CONNECTION->setCurrentPage(0);
	}
	else if ( item == plviConnectionMode )
	{
		TabWidget_DCGUI->setCurrentPage(2);
		TabWidget_CONNECTION->setCurrentPage(0);
	}
	else if ( item == plviConnectionSettings )
	{
		TabWidget_DCGUI->setCurrentPage(2);
		TabWidget_CONNECTION->setCurrentPage(1);
	}
	else if ( item == plviGUI )
	{
		TabWidget_DCGUI->setCurrentPage(3);
		TabWidget_GUI->setCurrentPage(0);
	}
	else if ( item == plviGUIUser )
	{
		TabWidget_DCGUI->setCurrentPage(3);
		TabWidget_GUI->setCurrentPage(5);
	}
	else if ( item == plviGUIMenus )
	{
		TabWidget_DCGUI->setCurrentPage(3);
		TabWidget_GUI->setCurrentPage(4);
	}
	else if ( item == plviGUIChat )
	{
		TabWidget_DCGUI->setCurrentPage(3);
		TabWidget_GUI->setCurrentPage(2);
	}
	else if (item == plviGUICommands )
	{
		TabWidget_DCGUI->setCurrentPage(3);
		TabWidget_GUI->setCurrentPage(3);
	}
	else if ( item == plviGUITransfer )
	{
		TabWidget_DCGUI->setCurrentPage(3);
		TabWidget_GUI->setCurrentPage(1);
	}
	else if ( item == plviGUIGeneral )
	{
		TabWidget_DCGUI->setCurrentPage(3);
		TabWidget_GUI->setCurrentPage(0);
	}
	else if ( item == plviGUIIcons )
	{
		TabWidget_DCGUI->setCurrentPage(3);
		TabWidget_GUI->setCurrentPage(6);
	}
	else if ( item == plviGUIFilelistBrowser )
	{
		TabWidget_DCGUI->setCurrentPage(3);
		TabWidget_GUI->setCurrentPage(7);
	}
	else if ( item == plviSound )
	{
		TabWidget_DCGUI->setCurrentPage(4);
	}
	else if ( item == plviLog )
	{
		TabWidget_DCGUI->setCurrentPage(5);
	}
	else if ( item == plviHubLists )
	{
		TabWidget_DCGUI->setCurrentPage(6);
	}
	else if ( item == plviSecurity )
	{
		TabWidget_DCGUI->setCurrentPage(7);
	}
	else if ( item == plviAutoResponse )
	{
		TabWidget_DCGUI->setCurrentPage(8);
	}
	else if ( item == plviOther )
	{
		TabWidget_DCGUI->setCurrentPage(9);
	}
}

/** */
void DCOptions::slotTabWidgetDCGUICurrentChanged( int index )
{
	disconnectOptionsTreeWidget();
	
	switch ( index )
	{
		case 0:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviDCGUI);
			break;
		}
		case 1:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviTransfer);
			break;
		}
		case 2:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviConnection);
			break;
		}
		case 3:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviGUI);
			break;
		}
		case 4:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviSound);
			break;
		}
		case 5:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviLog);
			break;
		}
		case 6:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviHubLists);
			break;
		}
		case 7:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviSecurity);
			break;
		}
		case 8:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviAutoResponse);
			break;
		}
		case 9:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviOther);
			break;
		}
		default:
		{
			break;
		}
	}
	
	connectOptionsTreeWidget();
}

/** */
void DCOptions::slotTabWidgetTransferCurrentChanged( int index )
{
	disconnectOptionsTreeWidget();
	
	switch ( index )
	{
		case 0:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviTransferFolder);
			break;
		}
		case 1:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviTransferSettings);
			break;
		}
		default:
		{
			break;
		}
	}
	
	connectOptionsTreeWidget();
}

/** */
void DCOptions::slotTabWidgetConnectionCurrentChanged( int index )
{
	disconnectOptionsTreeWidget();
	
	switch ( index )
	{
		case 0:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviConnectionMode);
			break;
		}
		case 1:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviConnectionSettings);
			break;
		}
		default:
		{
			break;
		}
	}
	
	connectOptionsTreeWidget();
}

/** */
void DCOptions::slotTabWidgetGUICurrentChanged( int index )
{
	disconnectOptionsTreeWidget();
	
	switch ( index )
	{
		case 0:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviGUIGeneral);
			break;
		}
		case 1:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviGUITransfer);
			break;
		}
		case 2:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviGUIChat);
			break;
		}
		case 3:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviGUICommands);
			break;
		}
		case 4:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviGUIMenus);
			break;
		}
		case 5:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviGUIUser);
			break;
		}
		case 6:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviGUIIcons);
			break;
		}
		case 7:
		{
			TreeWidget_OPTIONTREE->setCurrentItem(plviGUIFilelistBrowser);
			break;
		}
		default:
		{
			break;
		}
	}
	
	connectOptionsTreeWidget();
}

/** */
void DCOptions::slotEnableShowJoinsParts()
{
	CheckBox_CHATSHOWJOINSANDPARTSONLYFAV->setEnabled(CheckBox_CHATSHOWJOINSANDPARTS->isChecked());
}

/** */
void DCOptions::slotContextMenuUserMenuCommands( const QPoint & pos )
{
	QMenu * m;
	DCMenuHandler mhandler;
	QTreeWidgetItem * newitem;
	QAction * chosen = 0;
	
	m = new QMenu(this);
	
	QAction * add = mhandler.addAction( m, emiADD );
	QAction * edit = mhandler.addAction( m, emiEDIT );
	QAction * remove = mhandler.addAction( m, emiREMOVE );
	
	chosen = m->exec(QCursor::pos());
	
	delete m;
	
	if ( chosen == 0 )
	{
		return;
	}
	else if ( chosen == add )
	{
		newitem = new QTreeWidgetItem( TreeWidget_MENU_COMMANDS );
		newitem->setText( 0, tr("Say hello") );
		newitem->setText( 1, "1" );
		newitem->setText( 2, tr("<%[myNI]> hello|") );
		newitem->setFlags( newitem->flags() | Qt::ItemIsEditable );
	}
	else if ( chosen == remove )
	{
		if ( TreeWidget_MENU_COMMANDS->currentItem() != 0 )
		{
			delete TreeWidget_MENU_COMMANDS->currentItem();
		}
	}
	else if ( chosen == edit )
	{
		if ( TreeWidget_MENU_COMMANDS->currentItem() != 0 )
		{
			TreeWidget_MENU_COMMANDS->editItem(
				TreeWidget_MENU_COMMANDS->currentItem(),
				TreeWidget_MENU_COMMANDS->columnAt( pos.x() )
			);
		}
	}
}

/** */
void DCOptions::slotContextMenuUserChatCommands( const QPoint & pos )
{
	QMenu * m;
	DCMenuHandler mhandler;
	QTreeWidgetItem * newitem;
	QAction * chosen = 0;
	
	m = new QMenu(this);
	
	QAction * add = mhandler.addAction( m, emiADD );
	QAction * edit = mhandler.addAction( m, emiEDIT );
	QAction * remove = mhandler.addAction( m, emiREMOVE );
	
	chosen = m->exec(QCursor::pos());
	
	delete m;
	
	if ( chosen == 0 )
	{
		return;
	}
	else if ( chosen == add )
	{
		newitem = new QTreeWidgetItem( TreeWidget_CHAT_COMMANDS );
		newitem->setText( 0, "/s" );
		newitem->setText( 1, "/sh somescript.sh" );
		newitem->setFlags( newitem->flags() | Qt::ItemIsEditable );
	}
	else if ( chosen == remove )
	{
		if ( TreeWidget_CHAT_COMMANDS->currentItem() != 0 )
		{
			delete TreeWidget_CHAT_COMMANDS->currentItem();
		}
	}
	else if ( chosen == edit )
	{
		if ( TreeWidget_CHAT_COMMANDS->currentItem() != 0 )
		{
			TreeWidget_CHAT_COMMANDS->editItem(
				TreeWidget_CHAT_COMMANDS->currentItem(),
				TreeWidget_CHAT_COMMANDS->columnAt( pos.x() )
			);
		}
	}
}

/** */
void DCOptions::slotContextMenuAutoResponses( const QPoint & pos )
{
	QMenu * m = 0;
	DCMenuHandler mhandler;
	QTreeWidgetItem * newitem;
	QAction * chosen = 0;
	
	m = new QMenu(this);
	
	QAction * add = mhandler.addAction( m, emiADD );
	QAction * edit = mhandler.addAction( m, emiEDIT );
	QAction * remove = mhandler.addAction( m, emiREMOVE );
	QAction * cs_yes = m->addAction(tr("Case sensitive"));
	QAction * cs_no = m->addAction(tr("Case insensitive"));
	
	chosen = m->exec(QCursor::pos());
	
	delete m;
	
	if ( chosen == 0)
	{
		return;
	}
	else if ( chosen == add )
	{
		newitem = new QTreeWidgetItem( TreeWidget_AUTO_RESPONSES );
		newitem->setText( 0, tr("-trigger") );
		newitem->setText( 1, tr("No") );
		newitem->setText( 2, tr("response") );
		newitem->setFlags( newitem->flags() | Qt::ItemIsEditable );
	}
	else if ( chosen == edit )
	{
		if ( TreeWidget_AUTO_RESPONSES->currentItem() != 0 )
		{
			int column = TreeWidget_AUTO_RESPONSES->columnAt( pos.x() );
			if ( (column == 0) || (column == 2) )
			{
				TreeWidget_AUTO_RESPONSES->editItem(
					TreeWidget_AUTO_RESPONSES->currentItem(),
					column
				);
			}
		}
	}
	else if ( chosen == remove )
	{
		if ( TreeWidget_AUTO_RESPONSES->currentItem() != 0 )
		{
			delete TreeWidget_AUTO_RESPONSES->currentItem();
		}
	}
	else if ( chosen == cs_yes )
	{
		if ( TreeWidget_AUTO_RESPONSES->currentItem() != 0 )
		{
			TreeWidget_AUTO_RESPONSES->currentItem()->setText(1, tr("Yes"));
		}
	}
	else if ( chosen == cs_no )
	{
		if ( TreeWidget_AUTO_RESPONSES->currentItem() != 0 )
		{
			TreeWidget_AUTO_RESPONSES->currentItem()->setText(1, tr("No"));
		}
	}
}

/** */
void DCOptions::setupIconThemeComboBoxes()
{
	QDir appiconsdir, emoticonsdir, usericonsdir;
	QString basedir;
	
	basedir = g_pConfig->GetValknutDataPath();
	
	ComboBox_APPLICATION_ICONS->clear();
	ComboBox_USERLIST_ICONS->clear();
	ComboBox_EMOTICONS->clear();
	
	appiconsdir.setPath( basedir + "/icons/appl/" );
	appiconsdir.setFilter( QDir::Dirs | QDir::Readable | QDir::Executable );
	appiconsdir.setSorting( QDir::Name );
	
	const QFileInfoList applist = appiconsdir.entryInfoList();
	if ( applist.size() > 0 )
	{
		for (int i = 0; i < applist.size(); ++i)
		{
			QFileInfo appfi = applist.at(i);
			
			if ( (appfi.fileName() == ".") || (appfi.fileName() == "..") )
			{
				// skip
			}
			else
			{
				ComboBox_APPLICATION_ICONS->insertItem(appfi.fileName());
			}
		}
	}
	
	emoticonsdir.setPath( basedir + "/icons/emot/" );
	emoticonsdir.setFilter( QDir::Dirs | QDir::Readable | QDir::Executable );
	emoticonsdir.setSorting( QDir::Name );
	
	const QFileInfoList emotlist = emoticonsdir.entryInfoList();
	if ( emotlist.size() > 0 )
	{
		for (int i = 0; i < emotlist.size(); ++i)
		{
			QFileInfo emotfi = emotlist.at(i);
			
			if ( (emotfi.fileName() == ".") || (emotfi.fileName() == "..") )
			{
				// skip
			}
			else
			{ 
				ComboBox_EMOTICONS->insertItem(emotfi.fileName());
			}
		}
	}
	
	usericonsdir.setPath( basedir + "/icons/user/" );
	usericonsdir.setFilter( QDir::Dirs | QDir::Readable | QDir::Executable );
	usericonsdir.setSorting( QDir::Name );
	
	const QFileInfoList usericonslist = usericonsdir.entryInfoList();
	if ( usericonslist.size() > 0 )
	{
		for (int i = 0; i < usericonslist.size(); ++i)
		{
			QFileInfo userfi = usericonslist.at(i);
			
			if ( (userfi.fileName() == ".") || (userfi.fileName() == "..") )
			{
				// skip
			}
			else
			{
				ComboBox_USERLIST_ICONS->insertItem(userfi.fileName());
			}
		}
	}
}

/** Needed so that you don't have to save the dialog before refreshing the list */
void DCOptions::slotDontShareDotFilesChanged()
{
	g_pConfig->SetDontShareDotFiles(CheckBox_DONTSHAREDOTFILES->isChecked());
}

/** */
void DCOptions::slotGenerateKeyCert()
{
	QProcess * proc1 = 0;
	QProcess * proc2 = 0;
	QStringList args1;
	QStringList args2;
	QString keyname = LineEdit_TRANSFERKEY->text();
	QString certname = LineEdit_TRANSFERCERT->text();
	QFile key;
	QFile cert;
	QDir keypath;
	QDir certpath;
	
	PushButton_GENERATE_CERT->setEnabled(FALSE);
	
	if (keyname == "")
	{
		keyname = QString(g_pConfig->GetConfigPath().Data()) + QString("/ssl/valknut.key");
	}
	
	if (certname == "")
	{
		certname = QString(g_pConfig->GetConfigPath().Data()) + QString("/ssl/valknut.cert");
	}
	
	keyname = keyname.replace("//", "/");
	certname = certname.replace("//", "/");
	
	key.setName(keyname);
	cert.setName(certname);
	
	if ( key.exists() || cert.exists() )
	{
		int ret = QMessageBox::question(
			this,
			tr("Overwrite?"),
			tr("Replace existing key/cert?"),
			QMessageBox::Yes,
			QMessageBox::No
		);
		
		if ( ret == QMessageBox::No )
		{
			PushButton_GENERATE_CERT->setEnabled(TRUE);
			return;
		}
	}
	
	keypath.setPath(QFileInfo(keyname).dirPath());
	certpath.setPath(QFileInfo(certname).dirPath());
	
	if ( keypath.isRelative() )
	{
		keyname.prepend(QDir::separator());
		keyname.prepend(QDir::currentPath());
		keypath.setPath(QFileInfo(keyname).dirPath());
	}
	
	if ( certpath.isRelative() )
	{
		certname.prepend(QDir::separator());
		certname.prepend(QDir::currentPath());
		certpath.setPath(QFileInfo(certname).dirPath());
	}
	
	if (keypath.exists() == FALSE)
	{
		if ( keypath.mkdir(keypath.path()) == FALSE )
		{
			QMessageBox::critical(
				this,
				tr("Could not create folder for key"),
				tr("Could not create ") + keypath.path(),
				QMessageBox::Ok,
				QMessageBox::NoButton,
				QMessageBox::NoButton
			);
			PushButton_GENERATE_CERT->setEnabled(TRUE);
			return;
		}
	}
	
	if (certpath.exists() == FALSE)
	{
		if ( certpath.mkdir(certpath.path()) == FALSE )
		{
			QMessageBox::critical(
				this,
				tr("Could not create folder for cert"),
				tr("Could not create ") + certpath.path(),
				QMessageBox::Ok,
				QMessageBox::NoButton,
				QMessageBox::NoButton
			);
			PushButton_GENERATE_CERT->setEnabled(TRUE);
			return;
		}
	}
	
	proc1 = new QProcess();
	proc1->setWorkingDirectory(keypath.path());
	
	args1 << "genrsa";
	args1 << "-out";
	args1 << keyname;
	args1 << "2048";
	
	proc1->start( "openssl", args1 );
	proc1->waitForFinished( 5000 );

	if ( proc1->status() != QProcess::NotRunning )
	{
		proc1->terminate();
		sleep(1);
		if ( proc1->status() != QProcess::NotRunning )
		{
			proc1->kill();
		}
	}
	
	if ( (proc1->exitStatus() == QProcess::CrashExit) || (proc1->exitCode() != 0) )
	{
		QMessageBox::critical(
			this,
			tr("Error occurred while running openssl 1"),
			QString(proc1->readAllStandardError()) + "\n\n" + tr("Make sure the openssl program is in your PATH."),
			QMessageBox::Ok,
			QMessageBox::NoButton,
			QMessageBox::NoButton
		);
		delete proc1;
		PushButton_GENERATE_CERT->setEnabled(TRUE);
		return;
	}
	
	delete proc1;
	
	proc2 = new QProcess(this);
	proc2->setWorkingDirectory(certpath.path());
	
	args2 << "req";
	args2 << "-x509";
	args2 << "-new";
	args2 << "-batch";
	args2 << "-days";
	args2 << "3650";
	args2 << "-key";
	args2 << keyname;
	args2 << "-out";
	args2 << certname;
	args2 << "-subj";
	args2 << QString("/CN=Valknut-") + LineEdit_NICK->text();
	
	proc2->start( "openssl", args2 );
	proc2->waitForFinished( 5000 );
	
	if ( proc2->status() != QProcess::NotRunning )
	{
		proc2->terminate();
		sleep(1);
		if ( proc2->status() != QProcess::NotRunning )
		{
			proc2->kill();
		}
	}
	
	if ( (proc2->exitStatus() == QProcess::CrashExit) || (proc2->exitCode() != 0) )
	{
		QMessageBox::critical(
			this,
			tr("Error occurred while running openssl 2"),
			QString(proc2->readAllStandardError()) + "\n\n" + tr("Make sure the openssl program is in your PATH."),
			QMessageBox::Ok,
			QMessageBox::NoButton,
			QMessageBox::NoButton
		);
		delete proc2;
		PushButton_GENERATE_CERT->setEnabled(TRUE);
		return;
	}
	
	delete proc2;
	
	LineEdit_TRANSFERKEY->setText(keyname);
	LineEdit_TRANSFERCERT->setText(certname);
	
	// set them even if dialog is cancelled since files have been created
	g_pConfig->SetTransferKey(keyname.toAscii().data());
	g_pConfig->SetTransferCert(certname.toAscii().data());
	
	PushButton_GENERATE_CERT->setEnabled(TRUE);
}

/** */
void DCOptions::slotSendUnknownCommandsChecked()
{
	LineEdit_ALLOWED_UNKNOWN_COMMANDS->setEnabled( !CheckBox_SENDUNKNOWNCOMMANDS->isChecked() );
}
