optiondialog.cpp 80.1 KB
Newer Older
Joachim Eibl's avatar
Joachim Eibl committed
1 2
/*
 *   kdiff3 - Text Diff And Merge Tool
Joachim Eibl's avatar
Joachim Eibl committed
3
 *   Copyright (C) 2002-2009  Joachim Eibl, joachim.eibl at gmx.de
Joachim Eibl's avatar
Joachim Eibl committed
4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
Joachim Eibl's avatar
Joachim Eibl committed
17
 *   Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.
Joachim Eibl's avatar
Joachim Eibl committed
18 19
 *
 */
20

Joachim Eibl's avatar
Joachim Eibl committed
21 22
#include <QCheckBox>
#include <QComboBox>
23
#include <QDialogButtonBox>
Joachim Eibl's avatar
Joachim Eibl committed
24 25
#include <QLabel>
#include <QLayout>
26
#include <QLineEdit> 
Joachim Eibl's avatar
Joachim Eibl committed
27
#include <QToolTip>
Ragnar Thomsen's avatar
Ragnar Thomsen committed
28
#include <QPlainTextEdit>
Joachim Eibl's avatar
Joachim Eibl committed
29 30 31
#include <QRadioButton>
#include <QGroupBox>
#include <QTextCodec>
Joachim Eibl's avatar
Joachim Eibl committed
32
#include <QDir>
Joachim Eibl's avatar
Joachim Eibl committed
33 34
#include <QSettings>
#include <QLocale>
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
35 36 37
#include <QGridLayout>
#include <QPixmap>
#include <QFrame>
Michael Reeves's avatar
Michael Reeves committed
38
#include <QFontDialog>
39 40 41
#include <QPushButton>
#include <QApplication>
#include <QFontDatabase>
Joachim Eibl's avatar
Joachim Eibl committed
42

43
#include <KConfigGroup>
44 45 46 47
#include <KColorButton>
#include <KSharedConfig>
#include <KMessageBox>
#include <KToolBar>
Michael Reeves's avatar
Michael Reeves committed
48
#include <KHelpClient>
49
#include <KLocalizedString>
Joachim Eibl's avatar
Joachim Eibl committed
50
#include <map>
Joachim Eibl's avatar
Joachim Eibl committed
51 52 53

#include "optiondialog.h"
#include "diff.h"
Joachim Eibl's avatar
Joachim Eibl committed
54
#include "smalldialogs.h"
Joachim Eibl's avatar
0.9.86  
Joachim Eibl committed
55

Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
56 57
#define KDIFF3_CONFIG_GROUP "KDiff3 Options"

Joachim Eibl's avatar
Joachim Eibl committed
58 59 60 61 62
static QString s_historyEntryStartRegExpToolTip;
static QString s_historyEntryStartSortKeyOrderToolTip;
static QString s_autoMergeRegExpToolTip;
static QString s_historyStartRegExpToolTip;

63 64 65
void OptionDialog::addOptionItem(OptionItem* p)
{
   m_optionItemList.push_back(p);
Joachim Eibl's avatar
Joachim Eibl committed
66 67
}

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
class OptionItem
{
public:
   OptionItem( OptionDialog* pOptionDialog, const QString& saveName )
   {
      assert(pOptionDialog!=0);
      pOptionDialog->addOptionItem( this );
      m_saveName = saveName;
      m_bPreserved = false;
   }
   virtual ~OptionItem(){}
   virtual void setToDefault()=0;
   virtual void setToCurrent()=0;
   virtual void apply()=0;
   virtual void write(ValueMap*)=0;
   virtual void read(ValueMap*)=0;
   void doPreserve(){ if (!m_bPreserved){ m_bPreserved=true; preserve(); } }
   void doUnpreserve(){ if( m_bPreserved ){ unpreserve(); } }
   QString getSaveName(){return m_saveName;}
protected:
   virtual void preserve()=0;
   virtual void unpreserve()=0;
   bool m_bPreserved;
   QString m_saveName;
Joachim Eibl's avatar
Joachim Eibl committed
92 93
};

94
template <class T>
95 96 97 98 99 100 101 102 103 104 105 106 107
class OptionItemT : public OptionItem
{
public:
  OptionItemT( OptionDialog* pOptionDialog, const QString& saveName ) 
  : OptionItem(pOptionDialog,saveName ) 
  {}
  
protected:
   virtual void preserve(){ m_preservedVal = *m_pVar; }
   virtual void unpreserve(){ *m_pVar = m_preservedVal; }
   T* m_pVar;
   T m_preservedVal;
   T m_defaultVal;
108 109
};

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
class OptionCheckBox : public QCheckBox, public OptionItemT<bool>
{
public:
   OptionCheckBox( QString text, bool bDefaultVal, const QString& saveName, bool* pbVar,
                   QWidget* pParent, OptionDialog* pOD )
   : QCheckBox( text, pParent ), OptionItemT<bool>( pOD, saveName )
   {
      m_pVar = pbVar;
      m_defaultVal = bDefaultVal;
   }
   void setToDefault(){ setChecked( m_defaultVal );      }
   void setToCurrent(){ setChecked( *m_pVar );           }
   void apply()       { *m_pVar = isChecked();                              }
   void write(ValueMap* config){ config->writeEntry(m_saveName, *m_pVar );   }
   void read (ValueMap* config){ *m_pVar = config->readBoolEntry( m_saveName, *m_pVar ); }
private:
   OptionCheckBox( const OptionCheckBox& ); // private copy constructor without implementation
Joachim Eibl's avatar
Joachim Eibl committed
127 128
};

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
class OptionRadioButton : public QRadioButton, public OptionItemT<bool>
{
public:
   OptionRadioButton( QString text, bool bDefaultVal, const QString& saveName, bool* pbVar,
                   QWidget* pParent, OptionDialog* pOD )
   : QRadioButton( text, pParent ), OptionItemT<bool>( pOD, saveName )
   {
      m_pVar = pbVar;
      m_defaultVal = bDefaultVal;
   }
   void setToDefault(){ setChecked( m_defaultVal );      }
   void setToCurrent(){ setChecked( *m_pVar );           }
   void apply()       { *m_pVar = isChecked();                              }
   void write(ValueMap* config){ config->writeEntry(m_saveName, *m_pVar );   }
   void read (ValueMap* config){ *m_pVar = config->readBoolEntry( m_saveName, *m_pVar ); }
private:
   OptionRadioButton( const OptionRadioButton& ); // private copy constructor without implementation
Joachim Eibl's avatar
0.9.86  
Joachim Eibl committed
146 147
};

Joachim Eibl's avatar
Joachim Eibl committed
148 149

template<class T>
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
class OptionT : public OptionItemT<T>
{
public:
   OptionT( const T& defaultVal, const QString& saveName, T* pVar, OptionDialog* pOD )
   : OptionItemT<T>( pOD, saveName )
   {
      this->m_pVar = pVar;
      *this->m_pVar = defaultVal;
   }
   OptionT( const QString& saveName, T* pVar, OptionDialog* pOD )
   : OptionItemT<T>( pOD, saveName )
   {
      this->m_pVar = pVar;
   }
   void setToDefault(){}
   void setToCurrent(){}
   void apply()       {}
   void write(ValueMap* vm){ writeEntry( vm, this->m_saveName, *this->m_pVar ); }
   void read (ValueMap* vm){ *this->m_pVar = vm->readEntry ( this->m_saveName, *this->m_pVar ); }
private:
   OptionT( const OptionT& ); // private copy constructor without implementation
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
171 172
};

Michael Reeves's avatar
Michael Reeves committed
173 174 175 176
template <class T> void writeEntry( ValueMap* vm, const QString& saveName, const T& v ) {
    vm->writeEntry( saveName, v );
}
static void writeEntry( ValueMap* vm, const QString& saveName, const QStringList& v )   {
177
    vm->writeEntry( saveName, v);
Michael Reeves's avatar
Michael Reeves committed
178
}
Joachim Eibl's avatar
Joachim Eibl committed
179

Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
180 181 182 183 184
//static void readEntry(ValueMap* vm, const QString& saveName, bool& v )       {   v = vm->readBoolEntry( saveName, v ); }
//static void readEntry(ValueMap* vm, const QString& saveName, int&  v )       {   v = vm->readNumEntry( saveName, v ); }
//static void readEntry(ValueMap* vm, const QString& saveName, QSize& v )      {   v = vm->readSizeEntry( saveName, &v ); }
//static void readEntry(ValueMap* vm, const QString& saveName, QPoint& v )     {   v = vm->readPointEntry( saveName, &v ); }
//static void readEntry(ValueMap* vm, const QString& saveName, QStringList& v ){   v = vm->readListEntry( saveName, QStringList(), '|' ); }
Joachim Eibl's avatar
Joachim Eibl committed
185 186 187 188 189 190 191

typedef OptionT<bool> OptionToggleAction;
typedef OptionT<int>  OptionNum;
typedef OptionT<QPoint> OptionPoint;
typedef OptionT<QSize> OptionSize;
typedef OptionT<QStringList> OptionStringList;

Michael Reeves's avatar
Michael Reeves committed
192 193 194 195

FontChooser::FontChooser( QWidget* pParent )
: QGroupBox(pParent)
{
Ragnar Thomsen's avatar
Ragnar Thomsen committed
196 197 198
   QVBoxLayout* pLayout = new QVBoxLayout(this);
   m_pLabel = new QLabel(QString(), this);
   pLayout->addWidget(m_pLabel);
Michael Reeves's avatar
Michael Reeves committed
199 200 201

   QChar visualTab(0x2192);
   QChar visualSpace((ushort)0xb7);
Ragnar Thomsen's avatar
Ragnar Thomsen committed
202 203 204 205 206 207 208 209 210 211 212 213
   m_pExampleTextEdit = new QPlainTextEdit(QString("The quick brown fox jumps over the river\n"
                                                   "but the little red hen escapes with a shiver.\n"
                                                   ":-)")+visualTab+visualSpace, this);
   m_pExampleTextEdit->setFont(m_font);
   m_pExampleTextEdit->setReadOnly(true);
   pLayout->addWidget(m_pExampleTextEdit);

   m_pSelectFont = new QPushButton(i18n("Change Font"), this);
   m_pSelectFont->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
   connect(m_pSelectFont, SIGNAL(clicked()), this, SLOT(slotSelectFont()));
   pLayout->addWidget(m_pSelectFont);
   pLayout->setAlignment(m_pSelectFont, Qt::AlignRight);
Michael Reeves's avatar
Michael Reeves committed
214 215 216 217 218 219 220 221 222 223
}

QFont FontChooser::font()
{
   return m_font;//QFont("courier",10);
}

void FontChooser::setFont( const QFont& font, bool )
{
   m_font = font;
Ragnar Thomsen's avatar
Ragnar Thomsen committed
224 225 226
   m_pExampleTextEdit->setFont( m_font );
   m_pLabel->setText(i18n("Font: %1, %2, %3\n\nExample:", m_font.family(), m_font.styleName(), m_font.pointSize()));

Michael Reeves's avatar
Michael Reeves committed
227 228 229 230 231 232 233
   //update();
}

void FontChooser::slotSelectFont()
{
   bool bOk;
   m_font = QFontDialog::getFont(&bOk, m_font );
Ragnar Thomsen's avatar
Ragnar Thomsen committed
234 235
   m_pExampleTextEdit->setFont( m_font );
   m_pLabel->setText(i18n("Font: %1, %2, %3\n\nExample:", m_font.family(), m_font.styleName(), m_font.pointSize()));
Michael Reeves's avatar
Michael Reeves committed
236 237 238 239
}


class OptionFontChooser : public FontChooser, public OptionItemT<QFont>
240 241 242
{
public:
   OptionFontChooser( const QFont& defaultVal, const QString& saveName, QFont* pVar, QWidget* pParent, OptionDialog* pOD ) :
Michael Reeves's avatar
Michael Reeves committed
243
       FontChooser( pParent ),
244 245 246 247 248 249 250 251 252 253 254 255 256
       OptionItemT<QFont>( pOD, saveName )
   {
      m_pVar = pVar;
      *m_pVar = defaultVal;
      m_defaultVal = defaultVal;
   }
   void setToDefault(){ setFont( m_defaultVal, false ); }
   void setToCurrent(){ setFont( *m_pVar, false ); }
   void apply()       { *m_pVar = font();}
   void write(ValueMap* config){ config->writeEntry(m_saveName, *m_pVar );   }
   void read (ValueMap* config){ *m_pVar = config->readFontEntry( m_saveName, m_pVar ); }
private:
   OptionFontChooser( const OptionToggleAction& ); // private copy constructor without implementation
Joachim Eibl's avatar
Joachim Eibl committed
257
};
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
258

259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
class OptionColorButton : public KColorButton, public OptionItemT<QColor>
{
public:
   OptionColorButton( QColor defaultVal, const QString& saveName, QColor* pVar, QWidget* pParent, OptionDialog* pOD )
   : KColorButton( pParent ), OptionItemT<QColor>( pOD, saveName )
   {
      m_pVar = pVar;
      m_defaultVal = defaultVal;
   }
   void setToDefault(){ setColor( m_defaultVal );      }
   void setToCurrent(){ setColor( *m_pVar );           }
   void apply()       { *m_pVar = color();                              }
   void write(ValueMap* config){ config->writeEntry(m_saveName, *m_pVar );   }
   void read (ValueMap* config){ *m_pVar = config->readColorEntry( m_saveName, m_pVar ); }
private:
   OptionColorButton( const OptionColorButton& ); // private copy constructor without implementation
Joachim Eibl's avatar
Joachim Eibl committed
275 276
};

Michael Reeves's avatar
Michael Reeves committed
277 278
class OptionLineEdit : public QComboBox, public OptionItemT<QString>
{
Michael Reeves's avatar
Michael Reeves committed
279 280 281
    public:
        OptionLineEdit( const QString& defaultVal, const QString& saveName, QString* pVar,
                        QWidget* pParent, OptionDialog* pOD )
282 283 284 285
            : QComboBox( pParent ), OptionItemT<QString>( pOD, saveName )
        {
            setMinimumWidth(50);
            setEditable(true);
Michael Reeves's avatar
Michael Reeves committed
286 287
            m_pVar = pVar;
            m_defaultVal = defaultVal;
288
            m_list.push_back(defaultVal);
Michael Reeves's avatar
Michael Reeves committed
289 290
            insertText();
        }
291 292
        void setToDefault()
        {
Michael Reeves's avatar
Michael Reeves committed
293 294
            setEditText( m_defaultVal );
        }
295 296
        void setToCurrent()
        {
Michael Reeves's avatar
Michael Reeves committed
297 298
            setEditText( *m_pVar );
        }
299 300
        void apply()
        {
Michael Reeves's avatar
Michael Reeves committed
301 302 303
            *m_pVar = currentText();
            insertText();
        }
304 305
        void write(ValueMap* config)
        {
306
            config->writeEntry( m_saveName, m_list );
Michael Reeves's avatar
Michael Reeves committed
307
        }
308 309
        void read(ValueMap* config)
        {
310
            m_list = config->readListEntry( m_saveName, QStringList( m_defaultVal ) );
Michael Reeves's avatar
Michael Reeves committed
311 312
            if( !m_list.empty() ) *m_pVar = m_list.front();
            clear();
313
            insertItems(0,m_list);
Michael Reeves's avatar
Michael Reeves committed
314 315
        }
    private:
316
        void insertText()
Michael Reeves's avatar
Michael Reeves committed
317
        {  // Check if the text exists. If yes remove it and push it in as first element
Michael Reeves's avatar
Michael Reeves committed
318 319 320 321
            QString current = currentText();
            m_list.removeAll( current );
            m_list.push_front( current );
            clear();
322 323 324
            if( m_list.size()>10 )
                m_list.erase( m_list.begin()+10, m_list.end() );
            insertItems(0,m_list);
Michael Reeves's avatar
Michael Reeves committed
325 326 327
        }
        OptionLineEdit( const OptionLineEdit& ); // private copy constructor without implementation
        QStringList m_list;
Joachim Eibl's avatar
Joachim Eibl committed
328 329 330 331 332
};

#if defined QT_NO_VALIDATOR
#error No validator
#endif
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
class OptionIntEdit : public QLineEdit, public OptionItemT<int>
{
public:
   OptionIntEdit( int defaultVal, const QString& saveName, int* pVar, int rangeMin, int rangeMax,
                   QWidget* pParent, OptionDialog* pOD )
   : QLineEdit( pParent ), OptionItemT<int>( pOD, saveName )
   {
      m_pVar = pVar;
      m_defaultVal = defaultVal;
      QIntValidator* v = new QIntValidator(this);
      v->setRange( rangeMin, rangeMax );
      setValidator( v );
   }
   void setToDefault(){ QString s;  s.setNum(m_defaultVal); setText( s );  }
   void setToCurrent(){ QString s;  s.setNum(*m_pVar);      setText( s );  }
   void apply()       { const QIntValidator* v=static_cast<const QIntValidator*>(validator());
                        *m_pVar = minMaxLimiter( text().toInt(), v->bottom(), v->top());
                        setText( QString::number(*m_pVar) );  }
   void write(ValueMap* config){ config->writeEntry(m_saveName, *m_pVar );   }
   void read (ValueMap* config){ *m_pVar = config->readNumEntry( m_saveName, *m_pVar ); }
private:
   OptionIntEdit( const OptionIntEdit& ); // private copy constructor without implementation
Joachim Eibl's avatar
Joachim Eibl committed
355 356
};

357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
class OptionComboBox : public QComboBox, public OptionItem
{
public:
   OptionComboBox( int defaultVal, const QString& saveName, int* pVarNum,
                   QWidget* pParent, OptionDialog* pOD )
   : QComboBox( pParent ), OptionItem( pOD, saveName )
   {
      setMinimumWidth(50);
      m_pVarNum = pVarNum;
      m_pVarStr = 0;
      m_defaultVal = defaultVal;
      setEditable(false);
   }
   OptionComboBox( int defaultVal, const QString& saveName, QString* pVarStr,
                   QWidget* pParent, OptionDialog* pOD )
   : QComboBox( pParent ), OptionItem( pOD, saveName )
   {
      m_pVarNum = 0;
      m_pVarStr = pVarStr;
      m_defaultVal = defaultVal;
      setEditable(false);
   }
   void setToDefault()
   { 
      setCurrentIndex( m_defaultVal ); 
      if (m_pVarStr!=0){ *m_pVarStr=currentText(); } 
   }
   void setToCurrent()
   { 
      if (m_pVarNum!=0) setCurrentIndex( *m_pVarNum );
      else              setText( *m_pVarStr );
   }
   void apply()
   { 
      if (m_pVarNum!=0){ *m_pVarNum = currentIndex(); }
      else             { *m_pVarStr = currentText(); }
   }
   void write(ValueMap* config)
   { 
      if (m_pVarStr!=0) config->writeEntry(m_saveName, *m_pVarStr );
      else              config->writeEntry(m_saveName, *m_pVarNum );   
   }
   void read (ValueMap* config)
   {
      if (m_pVarStr!=0)  setText( config->readEntry( m_saveName, currentText() ) );
      else               *m_pVarNum = config->readNumEntry( m_saveName, *m_pVarNum ); 
   }
   void preserve()
   {
      if (m_pVarStr!=0)  { m_preservedStrVal = *m_pVarStr; }
      else               { m_preservedNumVal = *m_pVarNum; }
   }
   void unpreserve()
   {
      if (m_pVarStr!=0)  { *m_pVarStr = m_preservedStrVal; }
      else               { *m_pVarNum = m_preservedNumVal; }
   }
private:
   OptionComboBox( const OptionIntEdit& ); // private copy constructor without implementation
   int* m_pVarNum;
   int m_preservedNumVal;
   QString* m_pVarStr;
   QString m_preservedStrVal;
   int m_defaultVal;
   
   void setText(const QString& s)
   {
      // Find the string in the combobox-list, don't change the value if nothing fits.
      for( int i=0; i<count(); ++i )
      {
         if ( itemText(i)==s )
         {
            if (m_pVarNum!=0) *m_pVarNum = i;
            if (m_pVarStr!=0) *m_pVarStr = s;
            setCurrentIndex(i);
            return;
         }
      }
   }
Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
436
};
Joachim Eibl's avatar
Joachim Eibl committed
437

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
class OptionEncodingComboBox : public QComboBox, public OptionItem
{
   Q_OBJECT
   QVector<QTextCodec*> m_codecVec;
   QTextCodec** m_ppVarCodec;
public:
   OptionEncodingComboBox( const QString& saveName, QTextCodec** ppVarCodec,
                   QWidget* pParent, OptionDialog* pOD )
   : QComboBox( pParent ), OptionItem( pOD, saveName )
   {
      m_ppVarCodec = ppVarCodec;
      insertCodec( i18n("Unicode, 8 bit"),  QTextCodec::codecForName("UTF-8") );
      insertCodec( i18n("Unicode"), QTextCodec::codecForName("iso-10646-UCS-2") );
      insertCodec( i18n("Latin1"), QTextCodec::codecForName("iso 8859-1") );

      // First sort codec names:
      std::map<QString, QTextCodec*> names;
      QList<int> mibs = QTextCodec::availableMibs();
      foreach(int i, mibs)
      {
         QTextCodec* c = QTextCodec::codecForMib(i);
         if ( c!=0 )
            names[QString(c->name()).toUpper()]=c;
      }

      std::map<QString, QTextCodec*>::iterator it;
      for(it=names.begin();it!=names.end();++it)
      {
         insertCodec( "", it->second );
      }

      this->setToolTip( i18n(
         "Change this if non-ASCII characters are not displayed correctly."
         ));
   }
   void insertCodec( const QString& visibleCodecName, QTextCodec* c )
   {
      if (c!=0)
      {
         for( int i=0; i<m_codecVec.size(); ++i )
         {
            if ( c==m_codecVec[i] )
               return;  // don't insert any codec twice
         }
         addItem( visibleCodecName.isEmpty() ? QString(c->name()) : visibleCodecName+" ("+c->name()+")", (int)m_codecVec.size() );
         m_codecVec.push_back( c );
      }
   }
   void setToDefault()
   {
      QString defaultName = QTextCodec::codecForLocale()->name();
      for(int i=0;i<count();++i)
      {
         if (defaultName==itemText(i) &&
             m_codecVec[i]==QTextCodec::codecForLocale())
         {
            setCurrentIndex(i);
            if (m_ppVarCodec!=0){ *m_ppVarCodec=m_codecVec[i]; }
            return;
         }
      }

      setCurrentIndex( 0 );
      if (m_ppVarCodec!=0){ *m_ppVarCodec=m_codecVec[0]; }
   }
   void setToCurrent()
   {
      if (m_ppVarCodec!=0)
      {
         for( int i=0; i<m_codecVec.size(); ++i)
         {
            if ( *m_ppVarCodec==m_codecVec[i] )
            {
               setCurrentIndex( i );
               break;
Michael Reeves's avatar
Michael Reeves committed
513
            }
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
         }
      }
   }
   void apply()
   {
      if (m_ppVarCodec!=0){ *m_ppVarCodec = m_codecVec[ currentIndex() ]; }
   }
   void write(ValueMap* config)
   {
      if (m_ppVarCodec!=0) config->writeEntry(m_saveName, QString((*m_ppVarCodec)->name()) );
   }
   void read (ValueMap* config)
   {
      QString codecName = config->readEntry( m_saveName, QString(m_codecVec[ currentIndex() ]->name()) );
      for( int i=0; i<m_codecVec.size(); ++i)
      {
         if ( codecName == m_codecVec[i]->name() )
         {
            setCurrentIndex( i );
            if (m_ppVarCodec!=0) *m_ppVarCodec = m_codecVec[i];
            break;
         }
      }
   }
protected:
   void preserve()   { m_preservedVal = currentIndex(); }
   void unpreserve() { setCurrentIndex( m_preservedVal ); }
   int m_preservedVal;
Joachim Eibl's avatar
Joachim Eibl committed
542 543 544
};


545
OptionDialog::OptionDialog( bool bShowDirMergeSettings, QWidget *parent, char *name ) : 
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
546 547
//    KPageDialog( IconList, i18n("Configure"), Help|Default|Apply|Ok|Cancel,
//                 Ok, parent, name, true /*modal*/, true )
548 549 550 551
    KPageDialog( parent )
{
   setFaceType( List );
   setWindowTitle( i18n("Configure") );
552 553
   setStandardButtons( QDialogButtonBox::Help | QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Apply | QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
   // TODO KF5 necessary?  setDefaultButton( Ok );
554 555
   setObjectName( name );
   setModal( true  );
Michael Reeves's avatar
Michael Reeves committed
556

557
   //showButtonSeparator( true );01bc7c9af262353e7623bc02e5277fd59180183b
Michael Reeves's avatar
Michael Reeves committed
558
   //setHelp( "kdiff3/index.html", QString::null );
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576

   setupFontPage();
   setupColorPage();
   setupEditPage();
   setupDiffPage();
   setupMergePage();
   setupOtherOptions();
   if (bShowDirMergeSettings)
      setupDirectoryMergePage();

   setupRegionalPage();
   setupIntegrationPage();

   //setupKeysPage();

   // Initialize all values in the dialog
   resetToDefaults();
   slotApply();
577 578 579 580 581
   connect(button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &OptionDialog::slotApply);
   connect(button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &OptionDialog::slotOk);
   connect(button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, &OptionDialog::slotDefault);
   connect(button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &QDialog::reject);
   connect(button(QDialogButtonBox::Help), &QPushButton::clicked, this, &OptionDialog::helpRequested); 
582 583 584
   //connect(this, &OptionDialog::applyClicked, this, &OptionDialog::slotApply);
   //helpClicked() is connected in KDiff3App::KDiff3App -- Really where?
   //connect(this, &OptionDialog::defaultClicked, this, &OptionDialog::slotDefault);
Michael Reeves's avatar
Michael Reeves committed
585 586 587 588
}


void OptionDialog::helpRequested() {
589
    KHelpClient::invokeHelp( QStringLiteral( "kdiff3/index.html" ), QString());
Joachim Eibl's avatar
Joachim Eibl committed
590 591
}

592 593
OptionDialog::~OptionDialog( void )
{
Joachim Eibl's avatar
Joachim Eibl committed
594 595
}

596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
void OptionDialog::setupOtherOptions()
{
   new OptionToggleAction( false, "AutoAdvance", &m_options.m_bAutoAdvance, this );
   new OptionToggleAction( true,  "ShowWhiteSpaceCharacters", &m_options.m_bShowWhiteSpaceCharacters, this );
   new OptionToggleAction( true,  "ShowWhiteSpace", &m_options.m_bShowWhiteSpace, this );
   new OptionToggleAction( false, "ShowLineNumbers", &m_options.m_bShowLineNumbers, this );
   new OptionToggleAction( true,  "HorizDiffWindowSplitting", &m_options.m_bHorizDiffWindowSplitting, this );
   new OptionToggleAction( false, "WordWrap", &m_options.m_bWordWrap, this );

   new OptionToggleAction( true,  "ShowIdenticalFiles", &m_options.m_bDmShowIdenticalFiles, this );

   new OptionToggleAction( true,  "Show Toolbar", &m_options.m_bShowToolBar, this );
   new OptionToggleAction( true,  "Show Statusbar", &m_options.m_bShowStatusBar, this );

/*
   TODO manage toolbar positioning
   new OptionNum( (int)KToolBar::Top, "ToolBarPos", &m_toolBarPos, this );
*/
   new OptionSize( QSize(600,400),"Geometry", &m_options.m_geometry, this );
   new OptionPoint( QPoint(0,22), "Position", &m_options.m_position, this );
   new OptionToggleAction( false, "WindowStateMaximised", &m_options.m_bMaximised, this );

   new OptionStringList( "RecentAFiles", &m_options.m_recentAFiles, this );
   new OptionStringList( "RecentBFiles", &m_options.m_recentBFiles, this );
   new OptionStringList( "RecentCFiles", &m_options.m_recentCFiles, this );
   new OptionStringList( "RecentOutputFiles", &m_options.m_recentOutputFiles, this );
   new OptionStringList( "RecentEncodings", &m_options.m_recentEncodings, this );
623

Joachim Eibl's avatar
0.9.80  
Joachim Eibl committed
624
}
Joachim Eibl's avatar
Joachim Eibl committed
625

626 627 628 629
void OptionDialog::setupFontPage( void )
{
    QFrame* page = new QFrame();
    KPageWidgetItem *pageItem = new KPageWidgetItem( page, i18n("Font") );
630
    
631
    pageItem->setHeader( i18n("Editor & Diff Output Font") );
632
    pageItem->setIcon( QIcon::fromTheme(QStringLiteral("preferences-desktop-font")) );
Michael Reeves's avatar
Michael Reeves committed
633
    addPage( pageItem );
Joachim Eibl's avatar
Joachim Eibl committed
634

Michael Reeves's avatar
Michael Reeves committed
635 636
    QVBoxLayout *topLayout = new QVBoxLayout( page );
    topLayout->setMargin( 5 );
637
    
638
    
639
    //requires QT 5.2 or later.
640 641 642 643 644
    static const QFont  defaultFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);;
    static QFont defaultAppFont = QApplication::font();

    OptionFontChooser* pAppFontChooser = new OptionFontChooser( defaultAppFont, "ApplicationFont", &m_options.m_appFont, page, this );
    topLayout->addWidget( pAppFontChooser );
645
    
Michael Reeves's avatar
Michael Reeves committed
646 647
    OptionFontChooser* pFontChooser = new OptionFontChooser( defaultFont, "Font", &m_options.m_font, page, this );
    topLayout->addWidget( pFontChooser );
Michael Reeves's avatar
Michael Reeves committed
648
    pFontChooser->setTitle(i18n("File view font"));
Joachim Eibl's avatar
Joachim Eibl committed
649

650 651
    QGridLayout *gbox = new QGridLayout();
    topLayout->addLayout( gbox );
Michael Reeves's avatar
Michael Reeves committed
652 653 654 655 656 657 658 659 660
   //int line=0;

   // This currently does not work (see rendering in class DiffTextWindow)
   //OptionCheckBox* pItalicDeltas = new OptionCheckBox( i18n("Italic font for deltas"), false, "ItalicForDeltas", &m_options.m_bItalicForDeltas, page, this );
   //gbox->addWidget( pItalicDeltas, line, 0, 1, 2 );
   //pItalicDeltas->setToolTip( i18n(
   //   "Selects the italic version of the font for differences.\n"
   //   "If the font doesn't support italic characters, then this does nothing.")
   //   );
Joachim Eibl's avatar
Joachim Eibl committed
661 662 663
}


664 665
void OptionDialog::setupColorPage( void )
{
Michael Reeves's avatar
Michael Reeves committed
666
    QFrame* page = new QFrame();
667 668
    KPageWidgetItem* pageItem = new KPageWidgetItem( page, i18n("Color") );
    pageItem->setHeader( i18n("Colors Settings") );
669
    pageItem->setIcon( QIcon::fromTheme(QStringLiteral("colormanagement")) );
Michael Reeves's avatar
Michael Reeves committed
670 671 672 673 674 675
    addPage( pageItem );

    QVBoxLayout *topLayout = new QVBoxLayout( page );
    topLayout->setMargin( 5 );

    QGridLayout *gbox = new QGridLayout();
676 677
    gbox->setColumnStretch(1,5);
    topLayout->addLayout(gbox);
Michael Reeves's avatar
Michael Reeves committed
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807

    QLabel* label;
    int line = 0;

    int depth = QPixmap::defaultDepth();
    bool bLowColor = depth <= 8;

    label = new QLabel( i18n( "Editor and Diff Views:" ), page );
    gbox->addWidget( label, line, 0 );
    QFont f( label->font() );
    f.setBold( true );
    label->setFont( f );
    ++line;

    OptionColorButton* pFgColor = new OptionColorButton( Qt::black, "FgColor", &m_options.m_fgColor, page, this );
    label = new QLabel( i18n( "Foreground color:" ), page );
    label->setBuddy( pFgColor );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pFgColor, line, 1 );
    ++line;

    OptionColorButton* pBgColor = new OptionColorButton( Qt::white, "BgColor", &m_options.m_bgColor, page, this );
    label = new QLabel( i18n( "Background color:" ), page );
    label->setBuddy( pBgColor );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pBgColor, line, 1 );

    ++line;

    OptionColorButton* pDiffBgColor = new OptionColorButton(
        bLowColor ? QColor( Qt::lightGray ) : qRgb( 224, 224, 224 ), "DiffBgColor", &m_options.m_diffBgColor, page, this );
    label = new QLabel( i18n( "Diff background color:" ), page );
    label->setBuddy( pDiffBgColor );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pDiffBgColor, line, 1 );
    ++line;

    OptionColorButton* pColorA = new OptionColorButton(
        bLowColor ? qRgb( 0, 0, 255 ) : qRgb( 0, 0, 200 )/*blue*/, "ColorA", &m_options.m_colorA, page, this );
    label = new QLabel( i18n( "Color A:" ), page );
    label->setBuddy( pColorA );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColorA, line, 1 );
    ++line;

    OptionColorButton* pColorB = new OptionColorButton(
        bLowColor ? qRgb( 0, 128, 0 ) : qRgb( 0, 150, 0 )/*green*/, "ColorB", &m_options.m_colorB, page, this );
    label = new QLabel( i18n( "Color B:" ), page );
    label->setBuddy( pColorB );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColorB, line, 1 );
    ++line;

    OptionColorButton* pColorC = new OptionColorButton(
        bLowColor ? qRgb( 128, 0, 128 ) : qRgb( 150, 0, 150 )/*magenta*/, "ColorC", &m_options.m_colorC, page, this );
    label = new QLabel( i18n( "Color C:" ), page );
    label->setBuddy( pColorC );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColorC, line, 1 );
    ++line;

    OptionColorButton* pColorForConflict = new OptionColorButton( Qt::red, "ColorForConflict", &m_options.m_colorForConflict, page, this );
    label = new QLabel( i18n( "Conflict color:" ), page );
    label->setBuddy( pColorForConflict );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColorForConflict, line, 1 );
    ++line;

    OptionColorButton* pColor = new OptionColorButton(
        bLowColor ? qRgb( 192, 192, 192 ) : qRgb( 220, 220, 100 ), "CurrentRangeBgColor", &m_options.m_currentRangeBgColor, page, this );
    label = new QLabel( i18n( "Current range background color:" ), page );
    label->setBuddy( pColor );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColor, line, 1 );
    ++line;

    pColor = new OptionColorButton(
        bLowColor ? qRgb( 255, 255, 0 ) : qRgb( 255, 255, 150 ), "CurrentRangeDiffBgColor", &m_options.m_currentRangeDiffBgColor, page, this );
    label = new QLabel( i18n( "Current range diff background color:" ), page );
    label->setBuddy( pColor );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColor, line, 1 );
    ++line;

    pColor = new OptionColorButton( qRgb( 0xff, 0xd0, 0x80 ), "ManualAlignmentRangeColor", &m_options.m_manualHelpRangeColor, page, this );
    label = new QLabel( i18n( "Color for manually aligned difference ranges:" ), page );
    label->setBuddy( pColor );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColor, line, 1 );
    ++line;

    label = new QLabel( i18n( "Directory Comparison View:" ), page );
    gbox->addWidget( label, line, 0 );
    label->setFont( f );
    ++line;

    pColor = new OptionColorButton( qRgb( 0, 0xd0, 0 ), "NewestFileColor", &m_options.m_newestFileColor, page, this );
    label = new QLabel( i18n( "Newest file color:" ), page );
    label->setBuddy( pColor );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColor, line, 1 );
    QString dirColorTip = i18n( "Changing this color will only be effective when starting the next directory comparison." );
    label->setToolTip( dirColorTip );
    ++line;

    pColor = new OptionColorButton( qRgb( 0xf0, 0, 0 ), "OldestFileColor", &m_options.m_oldestFileColor, page, this );
    label = new QLabel( i18n( "Oldest file color:" ), page );
    label->setBuddy( pColor );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColor, line, 1 );
    label->setToolTip( dirColorTip );
    ++line;

    pColor = new OptionColorButton( qRgb( 0xc0, 0xc0, 0 ), "MidAgeFileColor", &m_options.m_midAgeFileColor, page, this );
    label = new QLabel( i18n( "Middle age file color:" ), page );
    label->setBuddy( pColor );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColor, line, 1 );
    label->setToolTip( dirColorTip );
    ++line;

    pColor = new OptionColorButton( qRgb( 0, 0, 0 ), "MissingFileColor", &m_options.m_missingFileColor, page, this );
    label = new QLabel( i18n( "Color for missing files:" ), page );
    label->setBuddy( pColor );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pColor, line, 1 );
    label->setToolTip( dirColorTip );
    ++line;

    topLayout->addStretch( 10 );
Joachim Eibl's avatar
Joachim Eibl committed
808 809 810
}


Michael Reeves's avatar
Michael Reeves committed
811 812
void OptionDialog::setupEditPage( void )
{
Michael Reeves's avatar
Michael Reeves committed
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
    QFrame* page = new QFrame();
    KPageWidgetItem* pageItem = new KPageWidgetItem( page, i18n( "Editor" ) );
    pageItem->setHeader( i18n( "Editor Behavior" ) );
    pageItem->setIcon( QIcon::fromTheme( QStringLiteral( "accessories-text-editor" ) ) );
    addPage( pageItem );

    QVBoxLayout *topLayout = new QVBoxLayout( page );
    topLayout->setMargin( 5 );

    QGridLayout *gbox = new QGridLayout();
    gbox->setColumnStretch( 1, 5 );
    topLayout->addLayout( gbox );
    QLabel* label;
    int line = 0;

    OptionCheckBox* pReplaceTabs = new OptionCheckBox( i18n( "Tab inserts spaces" ), false, "ReplaceTabs", &m_options.m_bReplaceTabs, page, this );
    gbox->addWidget( pReplaceTabs, line, 0, 1, 2 );
    pReplaceTabs->setToolTip( i18n(
                                  "On: Pressing tab generates the appropriate number of spaces.\n"
                                  "Off: A tab character will be inserted." )
                            );
    ++line;

    OptionIntEdit* pTabSize = new OptionIntEdit( 8, "TabSize", &m_options.m_tabSize, 1, 100, page, this );
    label = new QLabel( i18n( "Tab size:" ), page );
    label->setBuddy( pTabSize );
    gbox->addWidget( label, line, 0 );
    gbox->addWidget( pTabSize, line, 1 );
    ++line;

    OptionCheckBox* pAutoIndentation = new OptionCheckBox( i18n( "Auto indentation" ), true, "AutoIndentation", &m_options.m_bAutoIndentation, page, this );
    gbox->addWidget( pAutoIndentation, line, 0, 1, 2 );
    pAutoIndentation->setToolTip( i18n(
                                      "On: The indentation of the previous line is used for a new line.\n"
                                  ) );
    ++line;

    OptionCheckBox* pAutoCopySelection = new OptionCheckBox( i18n( "Auto copy selection" ), false, "AutoCopySelection", &m_options.m_bAutoCopySelection, page, this );
    gbox->addWidget( pAutoCopySelection, line, 0, 1, 2 );
    pAutoCopySelection->setToolTip( i18n(
                                        "On: Any selection is immediately written to the clipboard.\n"
                                        "Off: You must explicitely copy e.g. via Ctrl-C."
                                    ) );
    ++line;

    label = new QLabel( i18n( "Line end style:" ), page );
    gbox->addWidget( label, line, 0 );

    OptionComboBox* pLineEndStyle = new OptionComboBox( eLineEndStyleAutoDetect, "LineEndStyle", &m_options.m_lineEndStyle, page, this );
    gbox->addWidget( pLineEndStyle, line, 1 );
    pLineEndStyle->insertItem( eLineEndStyleUnix, "Unix" );
    pLineEndStyle->insertItem( eLineEndStyleDos, "Dos/Windows" );
    pLineEndStyle->insertItem( eLineEndStyleAutoDetect, "Autodetect" );

    label->setToolTip( i18n(
                           "Sets the line endings for when an edited file is saved.\n"
                           "DOS/Windows: CR+LF; UNIX: LF; with CR=0D, LF=0A" )
                     );
    ++line;

    topLayout->addStretch( 10 );
Joachim Eibl's avatar
Joachim Eibl committed
874 875 876
}


Michael Reeves's avatar
Michael Reeves committed
877 878
void OptionDialog::setupDiffPage( void )
{
Michael Reeves's avatar
Michael Reeves committed
879 880 881
    QFrame* page = new QFrame();
    KPageWidgetItem* pageItem = new KPageWidgetItem( page, i18n( "Diff" ) );
    pageItem->setHeader( i18n( "Diff Settings" ) );
882
    pageItem->setIcon( QIcon::fromTheme( QStringLiteral( "text-x-patch" ) ) );
Michael Reeves's avatar
Michael Reeves committed
883 884 885 886 887 888 889 890 891 892 893 894 895 896
    addPage( pageItem );


    QVBoxLayout *topLayout = new QVBoxLayout( page );
    topLayout->setMargin( 5 );

    QGridLayout *gbox = new QGridLayout();
    gbox->setColumnStretch( 1, 5 );
    topLayout->addLayout( gbox );
    int line = 0;

    QLabel* label = 0;

    m_options.m_bPreserveCarriageReturn = false;
Michael Reeves's avatar
Michael Reeves committed
897
/*
898 899 900 901 902 903 904
    OptionCheckBox* pPreserveCarriageReturn = new OptionCheckBox( i18n("Preserve carriage return"), false, "PreserveCarriageReturn", &m_options.m_bPreserveCarriageReturn, page, this );
    gbox->addWidget( pPreserveCarriageReturn, line, 0, 1, 2 );
    pPreserveCarriageReturn->setToolTip( i18n(
       "Show carriage return characters '\\r' if they exist.\n"
       "Helps to compare files that were modified under different operating systems.")
       );
    ++line;
Michael Reeves's avatar
Michael Reeves committed
905
*/
Michael Reeves's avatar
Michael Reeves committed
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
    QString treatAsWhiteSpace = " (" + i18n( "Treat as white space." ) + ")";

    OptionCheckBox* pIgnoreNumbers = new OptionCheckBox( i18n( "Ignore numbers" ) + treatAsWhiteSpace, false, "IgnoreNumbers", &m_options.m_bIgnoreNumbers, page, this );
    gbox->addWidget( pIgnoreNumbers, line, 0, 1, 2 );
    pIgnoreNumbers->setToolTip( i18n(
                                    "Ignore number characters during line matching phase. (Similar to Ignore white space.)\n"
                                    "Might help to compare files with numeric data." )
                              );
    ++line;

    OptionCheckBox* pIgnoreComments = new OptionCheckBox( i18n( "Ignore C/C++ comments" ) + treatAsWhiteSpace, false, "IgnoreComments", &m_options.m_bIgnoreComments, page, this );
    gbox->addWidget( pIgnoreComments, line, 0, 1, 2 );
    pIgnoreComments->setToolTip( i18n( "Treat C/C++ comments like white space." )
                               );
    ++line;

    OptionCheckBox* pIgnoreCase = new OptionCheckBox( i18n( "Ignore case" ) + treatAsWhiteSpace, false, "IgnoreCase", &m_options.m_bIgnoreCase, page, this );
    gbox->addWidget( pIgnoreCase, line, 0, 1, 2 );
    pIgnoreCase->setToolTip( i18n(
                                 "Treat case differences like white space changes. ('a'<=>'A')" )
                           );
    ++line;

    label = new QLabel( i18n( "Preprocessor command:" ), page );
    gbox->addWidget( label, line, 0 );
    OptionLineEdit* pLE = new OptionLineEdit( "", "PreProcessorCmd", &m_options.m_PreProcessorCmd, page, this );
    gbox->addWidget( pLE, line, 1 );
    label->setToolTip( i18n( "User defined pre-processing. (See the docs for details.)" ) );
    ++line;

    label = new QLabel( i18n( "Line-matching preprocessor command:" ), page );
    gbox->addWidget( label, line, 0 );
    pLE = new OptionLineEdit( "", "LineMatchingPreProcessorCmd", &m_options.m_LineMatchingPreProcessorCmd, page, this );
    gbox->addWidget( pLE, line, 1 );
    label->setToolTip( i18n( "This pre-processor is only used during line matching.\n(See the docs for details.)" ) );
    ++line;

    OptionCheckBox* pTryHard = new OptionCheckBox( i18n( "Try hard (slower)" ), true, "TryHard", &m_options.m_bTryHard, page, this );
    gbox->addWidget( pTryHard, line, 0, 1, 2 );
    pTryHard->setToolTip( i18n(
                              "Enables the --minimal option for the external diff.\n"
                              "The analysis of big files will be much slower." )
                        );
    ++line;

    OptionCheckBox* pDiff3AlignBC = new OptionCheckBox( i18n( "Align B and C for 3 input files" ), false, "Diff3AlignBC", &m_options.m_bDiff3AlignBC, page, this );
    gbox->addWidget( pDiff3AlignBC, line, 0, 1, 2 );
    pDiff3AlignBC->setToolTip( i18n(
                                   "Try to align B and C when comparing or merging three input files.\n"
                                   "Not recommended for merging because merge might get more complicated.\n"
                                   "(Default is off.)" )
                             );
    ++line;

    topLayout->addStretch( 10 );
Joachim Eibl's avatar
Joachim Eibl committed
961 962
}

Michael Reeves's avatar
Michael Reeves committed
963 964
void OptionDialog::setupMergePage( void )
{
Michael Reeves's avatar
Michael Reeves committed
965 966 967
    QFrame* page = new QFrame();
    KPageWidgetItem* pageItem = new KPageWidgetItem( page, i18n( "Merge" ) );
    pageItem->setHeader( i18n( "Merge Settings" ) );
968
    pageItem->setIcon( QIcon::fromTheme( QStringLiteral( "merge" ) ) );
Michael Reeves's avatar
Michael Reeves committed
969 970 971 972
    addPage( pageItem );

    QVBoxLayout *topLayout = new QVBoxLayout( page );
    topLayout->setMargin( 5 );
973
    
Michael Reeves's avatar
Michael Reeves committed
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
    QGridLayout *gbox = new QGridLayout();
    gbox->setColumnStretch( 1, 5 );
    topLayout->addLayout( gbox );
    int line = 0;

    QLabel* label = 0;

    label = new QLabel( i18n( "Auto advance delay (ms):" ), page );
    gbox->addWidget( label, line, 0 );
    OptionIntEdit* pAutoAdvanceDelay = new OptionIntEdit( 500, "AutoAdvanceDelay", &m_options.m_autoAdvanceDelay, 0, 2000, page, this );
    gbox->addWidget( pAutoAdvanceDelay, line, 1 );
    label->setToolTip( i18n(
                           "When in Auto-Advance mode the result of the current selection is shown \n"
                           "for the specified time, before jumping to the next conflict. Range: 0-2000 ms" )
                     );
    ++line;

    OptionCheckBox* pShowInfoDialogs = new OptionCheckBox( i18n( "Show info dialogs" ), true, "ShowInfoDialogs", &m_options.m_bShowInfoDialogs, page, this );
    gbox->addWidget( pShowInfoDialogs, line, 0, 1, 2 );
    pShowInfoDialogs->setToolTip( i18n( "Show a dialog with information about the number of conflicts." ) );
    ++line;

    label = new QLabel( i18n( "White space 2-file merge default:" ), page );
    gbox->addWidget( label, line, 0 );
    OptionComboBox* pWhiteSpace2FileMergeDefault = new OptionComboBox( 0, "WhiteSpace2FileMergeDefault", &m_options.m_whiteSpace2FileMergeDefault, page, this );
    gbox->addWidget( pWhiteSpace2FileMergeDefault, line, 1 );
    pWhiteSpace2FileMergeDefault->insertItem( 0, i18n( "Manual Choice" ) );
    pWhiteSpace2FileMergeDefault->insertItem( 1, "A" );
    pWhiteSpace2FileMergeDefault->insertItem( 2, "B" );
    label->setToolTip( i18n(
                           "Allow the merge algorithm to automatically select an input for "
                           "white-space-only changes." )
                     );
    ++line;

    label = new QLabel( i18n( "White space 3-file merge default:" ), page );
    gbox->addWidget( label, line, 0 );
    OptionComboBox* pWhiteSpace3FileMergeDefault = new OptionComboBox( 0, "WhiteSpace3FileMergeDefault", &m_options.m_whiteSpace3FileMergeDefault, page, this );
    gbox->addWidget( pWhiteSpace3FileMergeDefault, line, 1 );
    pWhiteSpace3FileMergeDefault->insertItem( 0, i18n( "Manual Choice" ) );
    pWhiteSpace3FileMergeDefault->insertItem( 1, "A" );
    pWhiteSpace3FileMergeDefault->insertItem( 2, "B" );
    pWhiteSpace3FileMergeDefault->insertItem( 3, "C" );
    label->setToolTip( i18n(
                           "Allow the merge algorithm to automatically select an input for "
                           "white-space-only changes." )
                     );
    ++line;

    QGroupBox* pGroupBox = new QGroupBox( i18n( "Automatic Merge Regular Expression" ) );
    gbox->addWidget( pGroupBox, line, 0, 1, 2 );
    ++line;
    {
        QGridLayout* gbox = new QGridLayout( pGroupBox );
        gbox->setColumnStretch( 1, 10 );
        int line = 0;

        label = new QLabel( i18n( "Auto merge regular expression:" ), page );
        gbox->addWidget( label, line, 0 );
        m_pAutoMergeRegExpLineEdit = new OptionLineEdit( ".*\\$(Version|Header|Date|Author).*\\$.*", "AutoMergeRegExp", &m_options.m_autoMergeRegExp, page, this );
        gbox->addWidget( m_pAutoMergeRegExpLineEdit, line, 1 );
        s_autoMergeRegExpToolTip = i18n( "Regular expression for lines where KDiff3 should automatically choose one source.\n"
                                         "When a line with a conflict matches the regular expression then\n"
                                         "- if available - C, otherwise B will be chosen." );
        label->setToolTip( s_autoMergeRegExpToolTip );
        ++line;

        OptionCheckBox* pAutoMergeRegExp = new OptionCheckBox( i18n( "Run regular expression auto merge on merge start" ), false, "RunRegExpAutoMergeOnMergeStart", &m_options.m_bRunRegExpAutoMergeOnMergeStart, page, this );
        gbox->addWidget( pAutoMergeRegExp, line, 0, 1, 2 );
        pAutoMergeRegExp->setToolTip( i18n( "Run the merge for auto merge regular expressions\n"
                                            "immediately when a merge starts.\n" ) );
        ++line;
    }
Joachim Eibl's avatar
Joachim Eibl committed
1047

Michael Reeves's avatar
Michael Reeves committed
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
    pGroupBox = new QGroupBox( i18n( "Version Control History Merging" ) );
    gbox->addWidget( pGroupBox, line, 0, 1, 2 );
    ++line;
    {
        QGridLayout* gbox = new QGridLayout( pGroupBox );
        gbox->setColumnStretch( 1, 10 );
        int line = 0;

        label = new QLabel( i18n( "History start regular expression:" ), page );
        gbox->addWidget( label, line, 0 );
        m_pHistoryStartRegExpLineEdit = new OptionLineEdit( ".*\\$Log.*\\$.*", "HistoryStartRegExp", &m_options.m_historyStartRegExp, page, this );
        gbox->addWidget( m_pHistoryStartRegExpLineEdit, line, 1 );
        s_historyStartRegExpToolTip = i18n( "Regular expression for the start of the version control history entry.\n"
                                            "Usually this line contains the \"$Log$\" keyword.\n"
                                            "Default value: \".*\\$Log.*\\$.*\"" );
        label->setToolTip( s_historyStartRegExpToolTip );
        ++line;

        label = new QLabel( i18n( "History entry start regular expression:" ), page );
        gbox->addWidget( label, line, 0 );
        // Example line:  "** \main\rolle_fsp_dev_008\1   17 Aug 2001 10:45:44   rolle"
        QString historyEntryStartDefault =
Joachim Eibl's avatar
Joachim Eibl committed
1070 1071 1072 1073 1074
            "\\s*\\\\main\\\\(\\S+)\\s+"  // Start with  "\main\"
            "([0-9]+) "          // day
            "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) " //month
            "([0-9][0-9][0-9][0-9]) " // year
            "([0-9][0-9]:[0-9][0-9]:[0-9][0-9])\\s+(.*)";  // time, name
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
   
      m_pHistoryEntryStartRegExpLineEdit = new OptionLineEdit( historyEntryStartDefault, "HistoryEntryStartRegExp", &m_options.m_historyEntryStartRegExp, page, this );
      gbox->addWidget( m_pHistoryEntryStartRegExpLineEdit, line, 1 );
      s_historyEntryStartRegExpToolTip = i18n("A version control history entry consists of several lines.\n"
            "Specify the regular expression to detect the first line (without the leading comment).\n"
            "Use parentheses to group the keys you want to use for sorting.\n"
            "If left empty, then KDiff3 assumes that empty lines separate history entries.\n"
            "See the documentation for details.");
      label->setToolTip( s_historyEntryStartRegExpToolTip );
      ++line;
   
      m_pHistoryMergeSorting = new OptionCheckBox( i18n("History merge sorting"), false, "HistoryMergeSorting", &m_options.m_bHistoryMergeSorting, page, this );
      gbox->addWidget( m_pHistoryMergeSorting, line, 0, 1, 2 );
      m_pHistoryMergeSorting->setToolTip( i18n("Sort version control history by a key.") );
      ++line;
            //QString branch = newHistoryEntry.cap(1);
            //int day    = newHistoryEntry.cap(2).toInt();
            //int month  = QString("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec").find(newHistoryEntry.cap(3))/4 + 1;
            //int year   = newHistoryEntry.cap(4).toInt();
            //QString time = newHistoryEntry.cap(5);
            //QString name = newHistoryEntry.cap(6);
      QString defaultSortKeyOrder = "4,3,2,5,1,6"; //QDate(year,month,day).toString(Qt::ISODate) +" "+ time + " " + branch + " " + name;

      label = new QLabel( i18n("History entry start sort key order:"), page );
      gbox->addWidget( label, line, 0 );
      m_pHistorySortKeyOrderLineEdit = new OptionLineEdit( defaultSortKeyOrder, "HistoryEntryStartSortKeyOrder", &m_options.m_historyEntryStartSortKeyOrder, page, this );
      gbox->addWidget( m_pHistorySortKeyOrderLineEdit, line, 1 );
      s_historyEntryStartSortKeyOrderToolTip = i18n("Each pair of parentheses used in the regular expression for the history start entry\n"
            "groups a key that can be used for sorting.\n"
            "Specify the list of keys (that are numbered in order of occurrence\n"
            "starting with 1) using ',' as separator (e.g. \"4,5,6,1,2,3,7\").\n"
            "If left empty, then no sorting will be done.\n"
            "See the documentation for details.");
      label->setToolTip( s_historyEntryStartSortKeyOrderToolTip );
      m_pHistorySortKeyOrderLineEdit->setEnabled(false);
      connect(m_pHistoryMergeSorting, &OptionCheckBox::toggled, m_pHistorySortKeyOrderLineEdit, &OptionLineEdit::setEnabled);
      ++line;

      m_pHistoryAutoMerge = new OptionCheckBox( i18n("Merge version control history on merge start"), false, "RunHistoryAutoMergeOnMergeStart", &m_options.m_bRunHistoryAutoMergeOnMergeStart, page, this );
      gbox->addWidget( m_pHistoryAutoMerge, line, 0, 1, 2 );
      m_pHistoryAutoMerge->setToolTip( i18n("Run version control history automerge on merge start.") );
      ++line;

      OptionIntEdit* pMaxNofHistoryEntries = new OptionIntEdit( -1, "MaxNofHistoryEntries", &m_options.m_maxNofHistoryEntries, -1, 1000, page, this );
      label = new QLabel( i18n("Max number of history entries:"), page );
      gbox->addWidget( label, line, 0 );
      gbox->addWidget( pMaxNofHistoryEntries, line, 1 );
      pMaxNofHistoryEntries->setToolTip( i18n("Cut off after specified number. Use -1 for infinite number of entries.") );
      ++line;
   }
Joachim Eibl's avatar
Joachim Eibl committed
1125

1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
   QPushButton* pButton = new QPushButton( i18n("Test your regular expressions"), page );
   gbox->addWidget( pButton, line, 0 );
   connect(pButton, &QPushButton::clicked, this, &OptionDialog::slotHistoryMergeRegExpTester);
   ++line;

   label = new QLabel( i18n("Irrelevant merge command:"), page );
   gbox->addWidget( label, line, 0 );
   OptionLineEdit* pLE = new OptionLineEdit( "", "IrrelevantMergeCmd", &m_options.m_IrrelevantMergeCmd, page, this );
   gbox->addWidget( pLE, line, 1 );
   label->setToolTip( i18n("If specified this script is run after automerge\n"
         "when no other relevant changes were detected.\n"
         "Called with the parameters: filename1 filename2 filename3") );
   ++line;


   OptionCheckBox* pAutoSaveAndQuit = new OptionCheckBox( i18n("Auto save and quit on merge without conflicts"), false,
      "AutoSaveAndQuitOnMergeWithoutConflicts", &m_options.m_bAutoSaveAndQuitOnMergeWithoutConflicts, page, this );
   gbox->addWidget( pAutoSaveAndQuit, line, 0, 1, 2 );
   pAutoSaveAndQuit->setToolTip( i18n("If KDiff3 was started for a file-merge from the command line and all\n"
                                         "conflicts are solvable without user interaction then automatically save and quit.\n"
                                         "(Similar to command line option \"--auto\".)") );
   ++line;

   topLayout->addStretch(10);
Joachim Eibl's avatar
Joachim Eibl committed
1150 1151
}

Michael Reeves's avatar
Michael Reeves committed
1152 1153
void OptionDialog::setupDirectoryMergePage( void )
{
Michael Reeves's avatar
Michael Reeves committed
1154 1155 1156
    QFrame* page = new QFrame();
    KPageWidgetItem* pageItem = new KPageWidgetItem( page, i18n( "Directory" ) );
    pageItem->setHeader( i18n( "Directory" ) );
1157
    pageItem->setIcon( QIcon::fromTheme( QStringLiteral( "inode-directory" ) ) );
Michael Reeves's avatar
Michael Reeves committed
1158 1159 1160 1161
    addPage( pageItem );

    QVBoxLayout *topLayout = new QVBoxLayout( page );
    topLayout->setMargin( 5 );
1162
    
Michael Reeves's avatar
Michael Reeves committed
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
    QGridLayout *gbox = new QGridLayout();
    gbox->setColumnStretch( 1, 5 );
    topLayout->addLayout( gbox );
    int line = 0;

    OptionCheckBox* pRecursiveDirs = new OptionCheckBox( i18n( "Recursive directories" ), true, "RecursiveDirs", &m_options.m_bDmRecursiveDirs, page, this );
    gbox->addWidget( pRecursiveDirs, line, 0, 1, 2 );
    pRecursiveDirs->setToolTip( i18n( "Whether to analyze subdirectories or not." ) );
    ++line;
    QLabel* label = new QLabel( i18n( "File pattern(s):" ), page );
    gbox->addWidget( label, line, 0 );
    OptionLineEdit* pFilePattern = new OptionLineEdit( "*", "FilePattern", &m_options.m_DmFilePattern, page, this );
    gbox->addWidget( pFilePattern, line, 1 );
    label->setToolTip( i18n(
                           "Pattern(s) of files to be analyzed. \n"
                           "Wildcards: '*' and '?'\n"
                           "Several Patterns can be specified by using the separator: ';'"
                       ) );
    ++line;

    label = new QLabel( i18n( "File-anti-pattern(s):" ), page );
    gbox->addWidget( label, line, 0 );
    OptionLineEdit* pFileAntiPattern = new OptionLineEdit( "*.orig;*.o;*.obj;*.rej;*.bak", "FileAntiPattern", &m_options.m_DmFileAntiPattern, page, this );
    gbox->addWidget( pFileAntiPattern, line, 1 );
    label->setToolTip( i18n(
                           "Pattern(s) of files to be excluded from analysis. \n"
                           "Wildcards: '*' and '?'\n"
                           "Several Patterns can be specified by using the separator: ';'"
                       ) );
    ++line;

    label = new QLabel( i18n( "Dir-anti-pattern(s):" ), page );
    gbox->addWidget( label, line, 0 );
    OptionLineEdit* pDirAntiPattern = new OptionLineEdit( "CVS;.deps;.svn;.hg;.git", "DirAntiPattern", &m_options.m_DmDirAntiPattern, page, this );
    gbox->addWidget( pDirAntiPattern, line, 1 );
    label->setToolTip( i18n(
                           "Pattern(s) of directories to be excluded from analysis. \n"
                           "Wildcards: '*' and '?'\n"
                           "Several Patterns can be specified by using the separator: ';'"
                       ) );
    ++line;

    OptionCheckBox* pUseCvsIgnore = new OptionCheckBox( i18n( "Use .cvsignore" ), false, "UseCvsIgnore", &m_options.m_bDmUseCvsIgnore, page, this );
    gbox->addWidget( pUseCvsIgnore, line, 0, 1, 2 );
    pUseCvsIgnore->setToolTip( i18n(
                                   "Extends the antipattern to anything that would be ignored by CVS.\n"
                                   "Via local \".cvsignore\" files this can be directory specific."
                               ) );
    ++line;

    OptionCheckBox* pFindHidden = new OptionCheckBox( i18n( "Find hidden files and directories" ), true, "FindHidden", &m_options.m_bDmFindHidden, page, this );
    gbox->addWidget( pFindHidden, line, 0, 1, 2 );
Joachim Eibl's avatar
Joachim Eibl committed
1215
#if defined(_WIN32) || defined(Q_OS_OS2)
1216
   pFindHidden->setToolTip( i18n("Finds files and directories with the hidden attribute.") );
Joachim Eibl's avatar
Joachim Eibl committed
1217
#else
1218
   pFindHidden->setToolTip( i18n("Finds files and directories starting with '.'.") );
Joachim Eibl's avatar
Joachim Eibl committed
1219
#endif
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
   ++line;

   OptionCheckBox* pFollowFileLinks = new OptionCheckBox( i18n("Follow file links"), false, "FollowFileLinks", &m_options.m_bDmFollowFileLinks, page, this );
   gbox->addWidget( pFollowFileLinks, line, 0, 1, 2 );
   pFollowFileLinks->setToolTip( i18n(
      "On: Compare the file the link points to.\n"
      "Off: Compare the links."
      ));
   ++line;

   OptionCheckBox* pFollowDirLinks = new OptionCheckBox( i18n("Follow directory links"), false, "FollowDirLinks", &m_options.m_bDmFollowDirLinks, page, this );
   gbox->addWidget( pFollowDirLinks, line, 0, 1, 2 );
   pFollowDirLinks->setToolTip(    i18n(
      "On: Compare the directory the link points to.\n"
      "Off: Compare the links."
      ));
   ++line;

   //OptionCheckBox* pShowOnlyDeltas = new OptionCheckBox( i18n("List only deltas"),false,"ListOnlyDeltas", &m_options.m_bDmShowOnlyDeltas, page, this );
   //gbox->addWidget( pShowOnlyDeltas, line, 0, 1, 2 );
   //pShowOnlyDeltas->setToolTip( i18n(
   //              "Files and directories without change will not appear in the list."));
   //++line;
Joachim Eibl's avatar
Joachim Eibl committed
1243

Joachim Eibl's avatar
Joachim Eibl committed
1244
#if defined(_WIN32) || defined(Q_OS_OS2)
1245
   bool bCaseSensitiveFilenameComparison = false;
Joachim Eibl's avatar
Joachim Eibl committed
1246
#else
1247
   bool bCaseSensitiveFilenameComparison = true;
Joachim Eibl's avatar
Joachim Eibl committed
1248
#endif
Michael Reeves's avatar
Michael Reeves committed
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
    OptionCheckBox* pCaseSensitiveFileNames = new OptionCheckBox( i18n( "Case sensitive filename comparison" ), bCaseSensitiveFilenameComparison, "CaseSensitiveFilenameComparison", &m_options.m_bDmCaseSensitiveFilenameComparison, page, this );
    gbox->addWidget( pCaseSensitiveFileNames, line, 0, 1, 2 );
    pCaseSensitiveFileNames->setToolTip( i18n(
            "The directory comparison will compare files or directories when their names match.\n"
            "Set this option if the case of the names must match. (Default for Windows is off, otherwise on.)" ) );
    ++line;

    OptionCheckBox* pUnfoldSubdirs = new OptionCheckBox( i18n( "Unfold all subdirectories on load" ), false, "UnfoldSubdirs", &m_options.m_bDmUnfoldSubdirs, page, this );
    gbox->addWidget( pUnfoldSubdirs, line, 0, 1, 2 );
    pUnfoldSubdirs->setToolTip( i18n(
                                    "On: Unfold all subdirectories when starting a directory diff.\n"
                                    "Off: Leave subdirectories folded."
                                ) );
    ++line;

    OptionCheckBox* pSkipDirStatus = new OptionCheckBox( i18n( "Skip directory status report" ), false, "SkipDirStatus", &m_options.m_bDmSkipDirStatus, page, this );
    gbox->addWidget( pSkipDirStatus, line, 0, 1, 2 );
    pSkipDirStatus->setToolTip( i18n(
                                    "On: Do not show the Directory Comparison Status.\n"
                                    "Off: Show the status dialog on start."
                                ) );
    ++line;

    QGroupBox* pBG = new QGroupBox( i18n( "File Comparison Mode" ) );
    gbox->addWidget( pBG, line, 0, 1, 2 );

    QVBoxLayout* pBGLayout = new QVBoxLayout( pBG );
1276
    
Michael Reeves's avatar
Michael Reeves committed
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
    OptionRadioButton* pBinaryComparison = new OptionRadioButton( i18n( "Binary comparison" ), true, "BinaryComparison", &m_options.m_bDmBinaryComparison, pBG, this );
    pBinaryComparison->setToolTip( i18n( "Binary comparison of each file. (Default)" ) );
    pBGLayout->addWidget( pBinaryComparison );

    OptionRadioButton* pFullAnalysis = new OptionRadioButton( i18n( "Full analysis" ), false, "FullAnalysis", &m_options.m_bDmFullAnalysis, pBG, this );
    pFullAnalysis->setToolTip( i18n( "Do a full analysis and show statistics information in extra columns.\n"
                                     "(Slower than a binary comparison, much slower for binary files.)" ) );
    pBGLayout->addWidget( pFullAnalysis );

    OptionRadioButton* pTrustDate = new OptionRadioButton( i18n( "Trust the size and modification date (unsafe)" ), false, "TrustDate", &m_options.m_bDmTrustDate, pBG, this );
    pTrustDate->setToolTip( i18n( "Assume that files are equal if the modification date and file length are equal.\n"
                                  "Files with equal contents but different modification dates will appear as different.\n"
                                  "Useful for big directories or slow networks." ) );
    pBGLayout->addWidget( pTrustDate );

    OptionRadioButton* pTrustDateFallbackToBinary = new OptionRadioButton( i18n( "Trust the size and date, but use binary comparison if date does not match (unsafe)" ), false, "TrustDateFallbackToBinary", &m_options.m_bDmTrustDateFallbackToBinary, pBG, this );
    pTrustDateFallbackToBinary->setToolTip( i18n( "Assume that files are equal if the modification date and file length are equal.\n"
                                            "If the dates are not equal but the sizes are, use binary comparison.\n"
                                            "Useful for big directories or slow networks." ) );
    pBGLayout->addWidget( pTrustDateFallbackToBinary );

    OptionRadioButton* pTrustSize = new OptionRadioButton( i18n( "Trust the size (unsafe)" ), false, "TrustSize", &m_options.m_bDmTrustSize, pBG, this );
    pTrustSize->setToolTip( i18n( "Assume that files are equal if their file lengths are equal.\n"
                                  "Useful for big directories or slow networks when the date is modified during download." ) );
    pBGLayout->addWidget( pTrustSize );

    ++line;


    // Some two Dir-options: Affects only the default actions.
    OptionCheckBox* pSyncMode = new OptionCheckBox( i18n( "Synchronize directories" ), false, "SyncMode", &m_options.m_bDmSyncMode, page, this );
    gbox->addWidget( pSyncMode, line, 0, 1, 2 );
    pSyncMode->setToolTip( i18n(
                               "Offers to store files in both directories so that\n"
                               "both directories are the same afterwards.\n"
                               "Works only when comparing two directories without specifying a destination." ) );
    ++line;

    // Allow white-space only differences to be considered equal
    OptionCheckBox* pWhiteSpaceDiffsEqual = new OptionCheckBox( i18n( "White space differences considered equal" ), true, "WhiteSpaceEqual", &m_options.m_bDmWhiteSpaceEqual, page, this );
    gbox->addWidget( pWhiteSpaceDiffsEqual, line, 0, 1, 2 );
    pWhiteSpaceDiffsEqual->setToolTip( i18n(
                                           "If files differ only by white space consider them equal.\n"
                                           "This is only active when full analysis is chosen." ) );
    connect( pFullAnalysis, &OptionRadioButton::toggled, pWhiteSpaceDiffsEqual, &OptionCheckBox::setEnabled );
    pWhiteSpaceDiffsEqual->setEnabled( false );
    ++line;

    OptionCheckBox* pCopyNewer = new OptionCheckBox( i18n( "Copy newer instead of merging (unsafe)" ), false, "CopyNewer", &m_options.m_bDmCopyNewer, page, this );
    gbox->addWidget( pCopyNewer, line, 0, 1, 2 );
    pCopyNewer->setToolTip( i18n(
                                "Don't look inside, just take the newer file.\n"
                                "(Use this only if you know what you are doing!)\n"
                                "Only effective when comparing two directories." ) );
    ++line;

    OptionCheckBox* pCreateBakFiles = new OptionCheckBox( i18n( "Backup files (.orig)" ), true, "CreateBakFiles", &m_options.m_bDmCreateBakFiles, page, this );
    gbox->addWidget( pCreateBakFiles, line, 0, 1, 2 );
    pCreateBakFiles->setToolTip( i18n(
                                     "If a file would be saved over an old file, then the old file\n"
                                     "will be renamed with a '.orig' extension instead of being deleted." ) );
    ++line;

    topLayout->addStretch( 10 );
Joachim Eibl's avatar
Joachim Eibl committed
1341
}
Joachim Eibl's avatar
0.9.86  
Joachim Eibl committed
1342
/*
Joachim Eibl's avatar
Joachim Eibl committed
1343 1344 1345 1346 1347 1348 1349
static void insertCodecs(OptionComboBox* p)
{
   std::multimap<QString,QString> m;  // Using the multimap for case-insensitive sorting.
   int i;
   for(i=0;;++i)
   {
      QTextCodec* pCodec = QTextCodec::codecForIndex ( i );
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
1350
      if ( pCodec != 0 )  m.insert( std::make_pair( QString(pCodec->mimeName()).toUpper(), pCodec->mimeName()) );
Joachim Eibl's avatar
Joachim Eibl committed
1351 1352
      else                break;
   }
1353
   
Joachim Eibl's avatar
Joachim Eibl committed
1354 1355 1356 1357 1358
   p->insertItem( i18n("Auto"), 0 );
   std::multimap<QString,QString>::iterator mi;
   for(mi=m.begin(), i=0; mi!=m.end(); ++mi, ++i)
      p->insertItem(mi->second, i+1);
}
Joachim Eibl's avatar
0.9.86  
Joachim Eibl committed
1359
*/
Joachim Eibl's avatar
Joachim Eibl committed
1360

Joachim Eibl's avatar
Joachim Eibl committed
1361
// UTF8-Codec that saves a BOM
Joachim Eibl's avatar
Joachim Eibl committed
1362
// UTF8-Codec that saves a BOM
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401
class Utf8BOMCodec : public QTextCodec
{
   QTextCodec* m_pUtf8Codec;
   class PublicTextCodec : public QTextCodec
   {
   public:
      QString publicConvertToUnicode ( const char * p, int len, ConverterState* pState ) const
      {
         return convertToUnicode( p, len, pState );
      }
      QByteArray publicConvertFromUnicode ( const QChar * input, int number, ConverterState * pState ) const
      {
         return convertFromUnicode( input, number, pState );
      }
   };
public:
   Utf8BOMCodec()
   {
      m_pUtf8Codec = QTextCodec::codecForName("UTF-8");
   }
   QByteArray name () const { return "UTF-8-BOM"; }
   int mibEnum () const { return 2123; }
   QByteArray convertFromUnicode ( const QChar * input, int number, ConverterState * pState ) const
   {
      QByteArray r;
      if ( pState && pState->state_data[2]==0)  // state_data[2] not used by QUtf8::convertFromUnicode (see qutfcodec.cpp)
      {
        r += "\xEF\xBB\xBF";
        pState->state_data[2]=1;
        pState->flags |= QTextCodec::IgnoreHeader;
      }

      r += ((PublicTextCodec*)m_pUtf8Codec)->publicConvertFromUnicode( input, number, pState );
      return r;
   }
   QString convertToUnicode ( const char * p, int len, ConverterState* pState ) const
   {
      return ((PublicTextCodec*)m_pUtf8Codec)->publicConvertToUnicode( p, len, pState );
   }
Joachim Eibl's avatar
Joachim Eibl committed
1402 1403
};

1404 1405 1406
void OptionDialog::setupRegionalPage( void )
{
   new Utf8BOMCodec();
Joachim Eibl's avatar
Joachim Eibl committed
1407

1408 1409 1410
   QFrame* page = new QFrame();
   KPageWidgetItem* pageItem = new KPageWidgetItem( page, i18n("Regional Settings") );
   pageItem->setHeader( i18n("Regional Settings") );
1411
   pageItem->setIcon( QIcon::fromTheme(QStringLiteral("preferences-desktop-locale")) );
1412
   addPage( pageItem );
Joachim Eibl's avatar
0.9.93  
Joachim Eibl committed
1413

Michael Reeves's avatar
Michael Reeves committed
1414 1415
    QVBoxLayout *topLayout = new QVBoxLayout( page );
    topLayout->setMargin( 5 );
1416
    
Michael Reeves's avatar
Michael Reeves committed
1417 1418 1419 1420
    QGridLayout *gbox = new QGridLayout();
    gbox->setColumnStretch( 1, 5 );
    topLayout->addLayout( gbox );
    int line = 0;
Joachim Eibl's avatar
Joachim Eibl committed
1421

1422
   QLabel* label;
Joachim Eibl's avatar
Joachim Eibl committed
1423

Joachim Eibl's avatar
Joachim Eibl committed
1424
#ifdef KREPLACEMENTS_H
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492