/***************************************************************************
                        kglookfeel.cpp  -  description
                             -------------------
    copyright            : (C) 2003 by Csaba Karai
    e-mail               : krusader@users.sourceforge.net
    web site             : http://krusader.sourceforge.net
 ---------------------------------------------------------------------------
  Description
 ***************************************************************************

  A

     db   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.
     88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D
     88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'
     88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b
     88 `88. 88 `88. 88b  d88 db   8D 88   88 88  .8D 88.     88 `88.
     YP   YD 88   YD ~Y8888P' `8888Y' YP   YP Y8888D' Y88888P 88   YD

                                                     S o u r c e    F i l e

 ***************************************************************************
 *                                                                         *
 *   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 "kglookfeel.h"
#include "../krusader.h"
#include "../defaults.h"
#include "../Dialogs/krdialogs.h"
#include <qtabwidget.h>
#include <QFrame>
#include <QGridLayout>
#include <QLabel>
#include <QVBoxLayout>
#include <klocale.h>
#include <qvalidator.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include "../GUI/krtreewidget.h"
#include "../Panel/krselectionmode.h"
#include "../Panel/listpanel.h"
#include "../Panel/krview.h"
#include "../Panel/krviewfactory.h"

#define PAGE_OPERATION     0
#define PAGE_PANEL         1
#define PAGE_PANELTOOLBAR  2
#define PAGE_MOUSE  3

KgLookFeel::KgLookFeel( bool first, QWidget* parent ) :
      KonfiguratorPage( first, parent )
{
  QWidget *innerWidget = this;
  QGridLayout *kgLookAndFeelLayout = new QGridLayout( innerWidget );
  kgLookAndFeelLayout->setSpacing( 6 );

  tabWidget = new QTabWidget( innerWidget );

  setupOperationTab();
  setupPanelTab();
  setupPanelToolbarTab();
  setupMouseModeTab();

  kgLookAndFeelLayout->addWidget( tabWidget, 0, 0 );
}

// ---------------------------------------------------------------------------------------
//  ---------------------------- OPERATION TAB -------------------------------------
// ---------------------------------------------------------------------------------------
void KgLookFeel::setupOperationTab() {
  QScrollArea *scrollArea = new QScrollArea( tabWidget );
  QWidget *tab = new QWidget( scrollArea );
  scrollArea->setFrameStyle( QFrame::NoFrame );
  scrollArea->setWidget( tab );
  scrollArea->setWidgetResizable( true );
  tabWidget->addTab( scrollArea, i18n( "Operation" ) );

  QGridLayout *lookAndFeelLayout = new QGridLayout( tab );
  lookAndFeelLayout->setSpacing( 6 );
  lookAndFeelLayout->setContentsMargins( 11, 11, 11, 11 );

  // -------------- General -----------------
  QGroupBox *lookFeelGrp = createFrame( i18n( "Look && Feel" ), tab );
  QGridLayout *lookFeelGrid = createGridLayout( lookFeelGrp );

  KONFIGURATOR_CHECKBOX_PARAM settings[] =
    { //   cfg_class  cfg_name                default             text                              restart tooltip
     {"Look&Feel","Warn On Exit",         _WarnOnExit,        i18n( "Warn on exit" ),           false,  i18n( "Display a warning when trying to close the main window." ) }, // KDE4: move warn on exit to the other confirmations
     {"Look&Feel","Minimize To Tray",     _MinimizeToTray,    i18n( "Minimize to tray" ),       false,  i18n( "The icon will appear in the system tray instead of the taskbar, when Krusader is minimized." ) },
     {"Look&Feel","Mark Dirs",            _MarkDirs,          i18n( "Autoselect directories" ),   false,  i18n( "When matching the select criteria, not only files will be selected, but also directories." ) },
     {"Look&Feel","Rename Selects Extension",true,          i18n( "Rename selects extension" ),   false,  i18n( "When renaming a file, the whole text is selected. If you want Total-Commander like renaming of just the name, without extension, uncheck this option." ) },
     {"Look&Feel","Fullpath Tab Names",   _FullPathTabNames,  i18n( "Use full path tab names" ), true ,  i18n( "Display the full path in the folder tabs. By default only the last part of the path is displayed." ) },
     {"Look&Feel","Fullscreen Terminal Emulator", false, i18n( "Fullscreen terminal (mc-style)"  ), false,  i18n( "Terminal is shown instead of the Krusader window (full screen).") },
    };

  cbs = createCheckBoxGroup( 2, 0, settings, 6 /*count*/, lookFeelGrp, PAGE_OPERATION );
  lookFeelGrid->addWidget( cbs, 0, 0 );

  lookAndFeelLayout->addWidget( lookFeelGrp, 0, 0 );

  // -------------- Quicksearch -----------------
  QGroupBox *quicksearchGroup = createFrame( i18n( "Quicksearch" ), tab );
  QGridLayout *quicksearchGrid = createGridLayout( quicksearchGroup );

  KONFIGURATOR_CHECKBOX_PARAM quicksearch[] =
   { //   cfg_class  cfg_name                default             text                              restart tooltip
     {"Look&Feel","New Style Quicksearch",  _NewStyleQuicksearch, i18n( "New style quicksearch" ), false,  i18n( "Opens a quick search dialog box." ) },
     {"Look&Feel","Case Sensitive Quicksearch",  _CaseSensitiveQuicksearch, i18n( "Case sensitive quicksearch" ), false,  i18n( "All files beginning with capital letters appear before files beginning with non-capital letters (UNIX default)." ) },
    };

  quicksearchCheckboxes = createCheckBoxGroup( 2, 0, quicksearch, 2 /*count*/, quicksearchGroup, PAGE_OPERATION );
  quicksearchGrid->addWidget( quicksearchCheckboxes, 0, 0 );
  connect( quicksearchCheckboxes->find( "New Style Quicksearch" ), SIGNAL( stateChanged( int ) ), this, SLOT( slotDisable() ) );
  slotDisable();

  lookAndFeelLayout->addWidget( quicksearchGroup, 1, 0 );
}

// ----------------------------------------------------------------------------------
//  ---------------------------- PANEL TAB -------------------------------------
// ----------------------------------------------------------------------------------
void KgLookFeel::setupPanelTab() {
  QScrollArea *scrollArea = new QScrollArea( tabWidget );
  QWidget *tab_panel = new QWidget( scrollArea );
  scrollArea->setFrameStyle( QFrame::NoFrame );
  scrollArea->setWidget( tab_panel );
  scrollArea->setWidgetResizable( true );
  tabWidget->addTab( scrollArea, i18n( "Panel" ) );

  QGridLayout *panelLayout = new QGridLayout( tab_panel );
  panelLayout->setSpacing( 6 );
  panelLayout->setContentsMargins( 11, 11, 11, 11 );
  QGroupBox *panelGrp = createFrame( i18n( "Panel settings" ), tab_panel );
  QGridLayout *panelGrid = createGridLayout( panelGrp );

  QWidget *hboxWidget = new QWidget( panelGrp );
  QHBoxLayout * hbox = new QHBoxLayout( hboxWidget );

// ----------------------------------------------------------------------------------
//  ---------------------------- DEFAULT PANEL TYPE -------------------------------------
// ----------------------------------------------------------------------------------
  
  QWidget *hboxWidget3 = new QWidget( panelGrp );
  QHBoxLayout * hbox3 = new QHBoxLayout( hboxWidget3 );

  QLabel *lbl3 = new QLabel( i18n( "Default panel type:" ), hboxWidget );
  hbox3->addWidget( lbl3 );

  QList<KrViewInstance *> views = KrViewFactory::registeredViews();
  KONFIGURATOR_NAME_VALUE_PAIR panelTypes[ views.count() ];

  QString defType = "0";

  for( int i=0; i != views.count(); i++ ) {
    KrViewInstance * inst = views[ i ];
    panelTypes[ i ].text = i18n( inst->description().toUtf8() );
    panelTypes[ i ].text.replace( "&", "" );
    panelTypes[ i ].value = QString( "%1" ).arg( inst->id() );
    if( inst->id() == KrViewFactory::defaultViewId() )
      defType = QString( "%1" ).arg( inst->id() );
  }

  KonfiguratorComboBox * cmb3 = createComboBox( "Look&Feel", "Default Panel Type", defType, panelTypes, views.count(), hboxWidget3, false, false, PAGE_PANEL );
  hbox3->addWidget( cmb3 );
  QWidget * spcr3 = createSpacer ( hboxWidget3 );
  hbox3->addWidget( spcr3 );

  panelGrid->addWidget( hboxWidget3, 0, 0 );

  QLabel *lbl = new QLabel( i18n( "Panel font:" ), hboxWidget );
  hbox->addWidget( lbl );

  KonfiguratorFontChooser * chsr = createFontChooser( "Look&Feel", "Filelist Font", _FilelistFont, hboxWidget, true, PAGE_PANEL );
  hbox->addWidget( chsr );

  QWidget *spcr = createSpacer ( hboxWidget );
  hbox->addWidget( spcr );

  panelGrid->addWidget( hboxWidget, 1, 0 );

  QWidget *hboxWidget2 = new QWidget( panelGrp );
  QHBoxLayout * hbox2 = new QHBoxLayout( hboxWidget2 );

  QLabel *lbl1 = new QLabel( i18n( "Filelist icon size:" ), hboxWidget2 );
  lbl1->setMinimumWidth( 230 );
  hbox2->addWidget( lbl1 );

  KONFIGURATOR_NAME_VALUE_PAIR iconSizes[] =
    {{ i18n( "12" ),  "12" },
     { i18n( "16" ),  "16" },
     { i18n( "22" ),  "22" },
     { i18n( "32" ),  "32" },
     { i18n( "48" ),  "48" }};
  KonfiguratorComboBox *iconCombo = createComboBox( "Look&Feel", "Filelist Icon Size", _FilelistIconSize, iconSizes, 5, hboxWidget2, true, true, PAGE_PANEL );
  iconCombo->lineEdit()->setValidator( new QRegExpValidator( QRegExp( "[1-9]\\d{0,1}" ), iconCombo ) );
  hbox2->addWidget( iconCombo );

  QWidget * spcr2 = createSpacer ( hboxWidget2 );
  hbox2->addWidget( spcr2 );

  panelGrid->addWidget( hboxWidget2, 2, 0 );

  panelGrid->addWidget( createLine( panelGrp ), 3, 0 );

  KONFIGURATOR_CHECKBOX_PARAM panelSettings[] =
  //   cfg_class  cfg_name                default text                                  restart tooltip
    {
	 {"Look&Feel","With Icons",                     _WithIcons,              i18n( "Use icons in the filenames" ), true ,  i18n( "Show the icons for filenames and folders." ) },
	 {"Look&Feel","Load User Defined Folder Icons", _UserDefinedFolderIcons, i18n( "Load the user defined folder icons" ), true ,  i18n( "Load the user defined folder icons (can cause decrease in performance)." ) },
	 {"Look&Feel","Human Readable Size",            _HumanReadableSize,      i18n( "Use human-readable file size" ), true ,  i18n( "File sizes are displayed in B, KB, MB and GB, not just in bytes." ) },
	 {"Look&Feel","Show Hidden",                    _ShowHidden,             i18n( "Show hidden files" ),      false,  i18n( "Display files beginning with a dot." ) },
	 {"Look&Feel","Numeric permissions",            _NumericPermissions,     i18n( "Numeric Permissions"  ), true,  i18n( "Show octal numbers (0755) instead of the standard permissions (rwxr-xr-x) in the permission column.") },
    };

  KonfiguratorCheckBoxGroup *panelSett = createCheckBoxGroup( 2, 0, panelSettings, 5 /*count*/, panelGrp, PAGE_PANEL );
  
  panelGrid->addWidget( panelSett, 4, 0, 1, 2 );
  

// ----------------------------------------------------------------------------------
//  ---------------------------- SORT METHOD ----------------------------------------
// ----------------------------------------------------------------------------------
  panelGrid->addWidget( createLine( panelGrp ), 5, 0 );
  
  QWidget *hboxWidget4 = new QWidget( panelGrp );
  QHBoxLayout *hbox4 = new QHBoxLayout( hboxWidget4 );
  QLabel *lbl4 = new QLabel( i18n( "Sort method:" ), hboxWidget4 );
  hbox4->addWidget( lbl4 );

  KONFIGURATOR_NAME_VALUE_PAIR sortMethods[] =
    {{ i18n( "Alphabetical" ),                QString::number( KrViewProperties::Alphabetical ) },
     { i18n( "Alphabetical and numbers" ),    QString::number( KrViewProperties::AlphabeticalNumbers ) },
     { i18n( "Character code" ),              QString::number( KrViewProperties::CharacterCode ) },
     { i18n( "Character code and numbers" ),  QString::number( KrViewProperties::CharacterCodeNumbers ) },
     { i18n( "Krusader" ),                    QString::number( KrViewProperties::Krusader ) } };
  KonfiguratorComboBox *sortMethodCombo = createComboBox( "Look&Feel", "Sort method",
     QString::number( _DefaultSortMethod ), sortMethods, 5, hboxWidget4, true, false, PAGE_PANEL );
  hbox4->addWidget( sortMethodCombo);
  QWidget * spcr4 = createSpacer ( hboxWidget4 );
  hbox4->addWidget( spcr4 );
  panelGrid->addWidget( hboxWidget4, 6, 0 );

  KONFIGURATOR_CHECKBOX_PARAM sortSettings[] =
  //   cfg_class  cfg_name                default text                                  restart tooltip
    {
	 {"Look&Feel","Case Sensative Sort",            _CaseSensativeSort,      i18n( "Case sensitive sorting" ), true ,  i18n( "All files beginning with capital letters appear before files beginning with non-capital letters (UNIX default)." ) },
	 {"Look&Feel","Always sort dirs by name",       false,                   i18n( "Always sort dirs by name"  ), true,  i18n( "Directories are sorted by name, regardless of the sort column.") },
    };

  KonfiguratorCheckBoxGroup *sortSett = createCheckBoxGroup( 2, 0, sortSettings,
     2 /*count*/, panelGrp, PAGE_PANEL );
  
  panelGrid->addWidget( sortSett, 7, 0, 1, 2 );

  panelLayout->addWidget( panelGrp, 0, 0 );
}

// -----------------------------------------------------------------------------------
//  -------------------------- Panel Toolbar TAB ----------------------------------
// -----------------------------------------------------------------------------------
void KgLookFeel::setupPanelToolbarTab() {
  QScrollArea *scrollArea = new QScrollArea( tabWidget );
  QWidget *tab_4 = new QWidget( scrollArea );
  scrollArea->setFrameStyle( QFrame::NoFrame );
  scrollArea->setWidget( tab_4 );
  scrollArea->setWidgetResizable( true );
  tabWidget->addTab( scrollArea, i18n( "Panel Toolbar" ) );

  QBoxLayout * panelToolbarVLayout = new QVBoxLayout( tab_4 );
  panelToolbarVLayout->setSpacing( 6 );
  panelToolbarVLayout->setContentsMargins( 11, 11, 11, 11 );

  KONFIGURATOR_CHECKBOX_PARAM panelToolbarActiveCheckbox[] = 
  //   cfg_class    cfg_name                default        text                          restart tooltip
    {{"Look&Feel", "Panel Toolbar visible", _PanelToolBar, i18n( "Show Panel Toolbar" ), true,   i18n( "The panel toolbar will be visible." ) }
  };

  panelToolbarActive = createCheckBoxGroup( 1, 0, panelToolbarActiveCheckbox, 1, tab_4, PAGE_PANELTOOLBAR);
  connect( panelToolbarActive->find( "Panel Toolbar visible" ), SIGNAL( stateChanged( int ) ), this, SLOT( slotEnablePanelToolbar() ) );
    
  QGroupBox * panelToolbarGrp = createFrame( i18n( "Visible Panel Toolbar buttons" ), tab_4 );
  QGridLayout * panelToolbarGrid = createGridLayout( panelToolbarGrp );

  KONFIGURATOR_CHECKBOX_PARAM panelToolbarCheckboxes[] = 
    {
  //   cfg_class    cfg_name                default             text                       restart tooltip
     {"Look&Feel",  "Open Button Visible",  _Open,      i18n( "Open button" ),     true ,  i18n( "Opens the directory browser." ) },
     {"Look&Feel",  "Equal Button Visible", _cdOther,   i18n( "Equal button (=)" ),true ,  i18n( "Changes the panel directory to the other panel directory." ) },
     {"Look&Feel",  "Up Button Visible",    _cdUp,      i18n( "Up button (..)" ),  true ,  i18n( "Changes the panel directory to the parent directory." ) },
     {"Look&Feel",  "Home Button Visible",  _cdHome,    i18n( "Home button (~)" ), true ,  i18n( "Changes the panel directory to the home directory." ) },
     {"Look&Feel",  "Root Button Visible",  _cdRoot,    i18n( "Root button (/)" ), true ,  i18n( "Changes the panel directory to the root directory." ) },
     {"Look&Feel",  "SyncBrowse Button Visible",  _syncBrowseButton,    i18n( "Toggle-button for sync-browsing" ), true ,  i18n( "Each directory change in the panel is also performed in the other panel." ) },
    };
  
  
  pnlcbs = createCheckBoxGroup(1, 0, panelToolbarCheckboxes,
                                     sizeof(panelToolbarCheckboxes)/sizeof(*panelToolbarCheckboxes),
                                       panelToolbarGrp, PAGE_PANELTOOLBAR);
  
  panelToolbarVLayout->addWidget( panelToolbarActive, 0, 0 );
  panelToolbarGrid->addWidget( pnlcbs, 0, 0 );
  panelToolbarVLayout->addWidget( panelToolbarGrp,    1, 0 );

  // Enable panel toolbar checkboxes
  slotEnablePanelToolbar();
}

// ---------------------------------------------------------------------------
//  -------------------------- Mouse TAB ----------------------------------
// ---------------------------------------------------------------------------
void KgLookFeel::setupMouseModeTab() {
  QScrollArea *scrollArea = new QScrollArea( tabWidget );
  QWidget *tab_mouse = new QWidget( scrollArea );
  scrollArea->setFrameStyle( QFrame::NoFrame );
  scrollArea->setWidget( tab_mouse );
  scrollArea->setWidgetResizable( true );
  tabWidget->addTab( scrollArea, i18n( "Selection Mode" ) );
  QGridLayout *mouseLayout = new QGridLayout( tab_mouse );
  mouseLayout->setSpacing( 6 );
  mouseLayout->setContentsMargins( 11, 11, 11, 11 );

  // -------------- General -----------------
  QGroupBox *mouseGeneralGroup = createFrame( i18n( "General" ), tab_mouse );
  QGridLayout *mouseGeneralGrid = createGridLayout( mouseGeneralGroup );
  mouseGeneralGrid->setSpacing( 0 );
  mouseGeneralGrid->setContentsMargins( 5, 5, 5, 5 );

  KONFIGURATOR_NAME_VALUE_TIP mouseSelection[] =
    {
    	//     name           value          tooltip
    	{ i18n( "Krusader Mode" ), "0", i18n( "Both keys allow selecting files. To select more than one file, hold the Ctrl key and click the left mouse button. Right-click menu is invoked using a short click on the right mouse button." ) },
     	{ i18n( "Konqueror Mode" ), "1", i18n( "Pressing the left mouse button selects files - you can click and select multiple files. Right-click menu is invoked using a short click on the right mouse button." ) },
     	{ i18n( "Total-Commander Mode" ), "2", i18n( "The left mouse button does not select, but sets the current file without affecting the current selection. The right mouse button selects multiple files and the right-click menu is invoked by pressing and holding the right mouse button." ) },
    	{ i18n( "Ergonomic Mode" ), "4", i18n( "The left mouse button does not select, but sets the current file without affecting the current selection. The right mouse button invokes the context-menu. You can select with Ctrl key and the left button." ) },
     	{ i18n( "Custom Selection Mode" ), "3", i18n( "Design your own selection mode!" ) }
     };
  mouseRadio = createRadioButtonGroup( "Look&Feel", "Mouse Selection", "0", 1, 5, mouseSelection, 5, mouseGeneralGroup, true, PAGE_MOUSE );
  mouseRadio->layout()->setContentsMargins( 0, 0, 0, 0 );
  mouseGeneralGrid->addWidget( mouseRadio, 0, 0 );

  for( int i = 0; i != mouseRadio->count(); i++ )
    connect( mouseRadio->find( i ), SIGNAL( clicked() ), SLOT( slotSelectionModeChanged() ) );

  mouseLayout->addWidget( mouseGeneralGroup, 0, 0 );

  // -------------- Details -----------------
  QGroupBox *mouseDetailGroup = createFrame( i18n( "Details" ), tab_mouse );
  QGridLayout *mouseDetailGrid = createGridLayout( mouseDetailGroup );
  mouseDetailGrid->setSpacing( 0 );
  mouseDetailGrid->setContentsMargins( 5, 5, 5, 5 );

   KONFIGURATOR_NAME_VALUE_TIP singleOrDoubleClick[] =
    {
    	//          name            value            tooltip
    	{ i18n( "Double-click selects (classic)" ), "0", i18n( "A single click on a file will select and focus, a double click opens the file or steps into the directory." ) },
    	{ i18n( "Obey KDE's global selection policy" ), "1", i18n( "<p>Use KDE's global setting:</p><p><i>KDE Control Center -> Peripherals -> Mouse</i></p>" ) }
    };
  KonfiguratorRadioButtons *clickRadio = createRadioButtonGroup( "Look&Feel", "Single Click Selects", "0", 1, 0, singleOrDoubleClick, 2, mouseDetailGroup, true, PAGE_MOUSE );
  clickRadio->layout()->setContentsMargins( 0, 0, 0, 0 );
  mouseDetailGrid->addWidget( clickRadio, 0, 0 );
  
  KONFIGURATOR_CHECKBOX_PARAM mouseCheckboxesParam[] = 
    {
     // {cfg_class,   cfg_name,   default
     // 	text,  restart,
     // 	tooltip }
     {"Custom Selection Mode",  "QT Selection",  _QtSelection,
     	i18n( "Based on KDE's selection mode" ), true,
     	i18n( "If checked, use a mode based on KDE's style." ) },
     {"Custom Selection Mode",  "Left Selects",  _LeftSelects,
     	i18n( "Left mouse button selects" ), true,
     	i18n( "If checked, left clicking an item will select it." ) },
     {"Custom Selection Mode",  "Left Preserves", _LeftPreserves,
     	i18n( "Left mouse button preserves selection" ), true,
     	i18n( "If checked, left clicking an item will select it, but will not unselect other, already selected items." ) },
     {"Custom Selection Mode",  "ShiftCtrl Left Selects",  _ShiftCtrlLeft,
     	i18n( "Shift/Ctrl-Left mouse button selects" ), true,
     	i18n( "If checked, shift/ctrl left clicking will select items. \nNote: This is meaningless if 'Left Button Selects' is checked." ) },
     {"Custom Selection Mode",  "Right Selects",  _RightSelects,
     	i18n( "Right mouse button selects" ), true,
     	i18n( "If checked, right clicking an item will select it." ) },
     {"Custom Selection Mode",  "Right Preserves",  _RightPreserves,
     	i18n( "Right mouse button preserves selection" ), true,
     	i18n( "If checked, right clicking an item will select it, but will not unselect other, already selected items." ) },
     {"Custom Selection Mode",  "ShiftCtrl Right Selects",  _ShiftCtrlRight,
     	i18n( "Shift/Ctrl-Right mouse button selects" ), true,
     	i18n( "If checked, shift/ctrl right clicking will select items. \nNote: This is meaningless if 'Right Button Selects' is checked." ) },
     {"Custom Selection Mode",  "Space Moves Down",  _SpaceMovesDown,
     	i18n( "Spacebar moves down" ), true,
     	i18n( "If checked, pressing the spacebar will select the current item and move down. \nOtherwise, current item is selected, but remains the current item." ) },
     {"Custom Selection Mode",  "Space Calc Space",  _SpaceCalcSpace,
     	i18n( "Spacebar calculates disk space" ), true,
     	i18n( "If checked, pressing the spacebar while the current item is a folder, will (except from selecting the folder) \ncalculate space occupied by the folder (recursively)." ) },
     {"Custom Selection Mode",  "Insert Moves Down",  _InsertMovesDown,
     	i18n( "Insert moves down" ), true,
     	i18n( "If checked, pressing INSERT will select the current item, and move down to the next item. \nOtherwise, current item is not changed." ) },
     {"Custom Selection Mode",  "Immediate Context Menu",  _ImmediateContextMenu,
     	i18n( "Right clicking pops context menu immediately" ), true,
     	i18n( "If checked, right clicking will result in an immediate showing of the context menu. \nOtherwise, user needs to click and hold the right mouse button for 500ms." ) },
    };
  
  
  mouseCheckboxes = createCheckBoxGroup(1, 0, mouseCheckboxesParam, 11 /*count*/, mouseDetailGroup, PAGE_MOUSE);
  mouseDetailGrid->addWidget( mouseCheckboxes, 1, 0 );

  for ( int i = 0; i < mouseCheckboxes->count(); i++ )
     connect( mouseCheckboxes->find( i ), SIGNAL( clicked() ), SLOT( slotMouseCheckBoxChanged() ) );

  mouseLayout->addWidget( mouseDetailGroup, 0, 1, 2, 1 );

  // Disable the details-button if not in custom-mode
  slotSelectionModeChanged();

  // -------------- Preview -----------------
  QGroupBox *mousePreviewGroup = createFrame( i18n( "Preview" ), tab_mouse );
  QGridLayout *mousePreviewGrid = createGridLayout( mousePreviewGroup );
  // TODO preview
  mousePreview = new KrTreeWidget( mousePreviewGroup );
  mousePreviewGrid->addWidget( mousePreview, 0 ,0 );
  mousePreviewGroup->setEnabled(false); // TODO re-enable once the preview is implemented
  // ------------------------------------------
  mouseLayout->addWidget( mousePreviewGroup, 1, 0  );
}

void KgLookFeel::slotDisable()
{
  bool isNewStyleQuickSearch = quicksearchCheckboxes->find( "New Style Quicksearch" )->isChecked();
  quicksearchCheckboxes->find( "Case Sensitive Quicksearch" )->setEnabled( isNewStyleQuickSearch );
}

void KgLookFeel::slotEnablePanelToolbar()
{
  bool enableTB = panelToolbarActive->find("Panel Toolbar visible")->isChecked();
  pnlcbs->find( "Root Button Visible"     )->setEnabled(enableTB);
  pnlcbs->find( "Home Button Visible"     )->setEnabled(enableTB);
  pnlcbs->find( "Up Button Visible"       )->setEnabled(enableTB);
  pnlcbs->find( "Equal Button Visible"    )->setEnabled(enableTB);
  pnlcbs->find( "Open Button Visible"     )->setEnabled(enableTB);  
  pnlcbs->find("SyncBrowse Button Visible")->setEnabled(enableTB);  
}

void KgLookFeel::slotSelectionModeChanged() {
  KrSelectionMode *selectionMode =
      KrSelectionMode::getSelectionHandlerForMode( mouseRadio->selectedValue() );
  if ( selectionMode == NULL ) //User mode
    return;
  selectionMode->init();
  mouseCheckboxes->find( "QT Selection" )->setChecked( selectionMode->useQTSelection() );
  mouseCheckboxes->find( "Left Selects" )->setChecked( selectionMode->leftButtonSelects() );
  mouseCheckboxes->find( "Left Preserves" )->setChecked( selectionMode->leftButtonPreservesSelection() );
  mouseCheckboxes->find( "ShiftCtrl Left Selects" )->setChecked( selectionMode->shiftCtrlLeftButtonSelects() );
  mouseCheckboxes->find( "Right Selects" )->setChecked( selectionMode->rightButtonSelects() );
  mouseCheckboxes->find( "Right Preserves" )->setChecked( selectionMode->rightButtonPreservesSelection() );
  mouseCheckboxes->find( "ShiftCtrl Right Selects" )->setChecked( selectionMode->shiftCtrlRightButtonSelects() );
  mouseCheckboxes->find( "Space Moves Down" )->setChecked( selectionMode->spaceMovesDown() );
  mouseCheckboxes->find( "Space Calc Space" )->setChecked( selectionMode->spaceCalculatesDiskSpace() );
  mouseCheckboxes->find( "Insert Moves Down" )->setChecked( selectionMode->insertMovesDown() );
  mouseCheckboxes->find( "Immediate Context Menu" )->setChecked( selectionMode->showContextMenu() == -1 );
}

void KgLookFeel::slotMouseCheckBoxChanged()
{
  mouseRadio->selectButton( "3" );  //custom selection mode
}

int KgLookFeel::activeSubPage() {
	return tabWidget->currentIndex();
}

#include "kglookfeel.moc"

