• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

kompare

  • sources
  • kde-4.14
  • kdesdk
  • kompare
  • komparepart
komparesaveoptionswidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  komparesaveoptionswidget.cpp
3  ----------------------------
4  begin : Sun Mar 4 2001
5  Copyright 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl>
6  Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
7  Copyright 2007-2011 Kevin Kofler <kevin.kofler@chello.at>
8 ****************************************************************************/
9 
10 /***************************************************************************
11 **
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License as published by
14 ** the Free Software Foundation; either version 2 of the License, or
15 ** (at your option) any later version.
16 **
17 ***************************************************************************/
18 
19 #include "komparesaveoptionswidget.h"
20 
21 #include <QtGui/QCheckBox>
22 #include <QtGui/QLabel>
23 #include <QtGui/QRadioButton>
24 #include <QtGui/QSpinBox>
25 
26 #include <kdebug.h>
27 #include <kfiledialog.h>
28 #include <kurlrequester.h>
29 
30 #include "diffsettings.h"
31 
32 KompareSaveOptionsWidget::KompareSaveOptionsWidget( QString source, QString destination,
33  DiffSettings * settings, QWidget * parent )
34  : KompareSaveOptionsBase( parent )
35  , m_source( source )
36  , m_destination( destination )
37  , m_FormatBG( new QButtonGroup(this) )
38 {
39  setObjectName("save options");
40 
41  m_settings = settings;
42 
43  m_directoryRequester->setMode(
44  KFile::ExistingOnly | KFile::Directory | KFile::LocalOnly );
45 
46  KUrl sourceURL;
47  KUrl destinationURL;
48  sourceURL.setPath( source );
49  destinationURL.setPath( destination );
50 
51  // Find a common root.
52  KUrl root( sourceURL );
53  while( root.isValid() && !root.isParentOf( destinationURL ) && root != root.upUrl() ) {
54  root = root.upUrl();
55  }
56 
57  // If we found a common root, change to that directory and
58  // strip the common part from source and destination.
59  if( root.isValid() && root != root.upUrl() ) {
60  m_directoryRequester->setUrl( root.url() );
61  }
62 
63  connect( m_SmallerChangesCB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
64  connect( m_LargeFilesCB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
65  connect( m_IgnoreCaseCB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
66  connect( m_ExpandTabsCB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
67  connect( m_IgnoreEmptyLinesCB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
68  connect( m_IgnoreWhiteSpaceCB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
69  connect( m_FunctionNamesCB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
70  connect( m_RecursiveCB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
71  connect( m_NewFilesCB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
72  connect( m_ContextRB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
73  connect( m_EdRB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
74  connect( m_NormalRB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
75  connect( m_RCSRB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
76  connect( m_UnifiedRB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
77  connect( m_SideBySideRB, SIGNAL(toggled(bool)), SLOT(updateCommandLine()) );
78  connect( m_ContextLinesSB, SIGNAL(valueChanged(int)), SLOT(updateCommandLine()) );
79  connect( m_directoryRequester, SIGNAL(textChanged(const QString&)), SLOT(updateCommandLine()) );
80 
81  m_FormatBG->setExclusive(true);
82  m_FormatBG->addButton(m_ContextRB, Kompare::Context);
83  m_FormatBG->addButton(m_EdRB, Kompare::Ed);
84  m_FormatBG->addButton(m_NormalRB, Kompare::Normal);
85  m_FormatBG->addButton(m_UnifiedRB, Kompare::Unified);
86  m_FormatBG->addButton(m_RCSRB, Kompare::RCS);
87  m_FormatBG->addButton(m_SideBySideRB, Kompare::SideBySide);
88 
89  loadOptions();
90 }
91 
92 KompareSaveOptionsWidget::~KompareSaveOptionsWidget()
93 {
94 
95 }
96 
97 QString KompareSaveOptionsWidget::directory() const
98 {
99  return KUrl( m_directoryRequester->url() ).toLocalFile();
100 }
101 
102 void KompareSaveOptionsWidget::updateCommandLine()
103 {
104  QString cmdLine = "diff";
105 
106  QString options = "";
107 
108  switch( static_cast<Kompare::Format>( m_FormatBG->checkedId() ) ) {
109  case Kompare::Unified :
110  cmdLine += " -U " + QString::number( m_ContextLinesSB->value() );
111  break;
112  case Kompare::Context :
113  cmdLine += " -C " + QString::number( m_ContextLinesSB->value() );
114  break;
115  case Kompare::RCS :
116  options += 'n';
117  break;
118  case Kompare::Ed :
119  options += 'e';
120  break;
121  case Kompare::SideBySide:
122  options += 'y';
123  break;
124  case Kompare::Normal :
125  case Kompare::UnknownFormat :
126  default:
127  break;
128  }
129 
130  if ( m_SmallerChangesCB->isChecked() ) {
131  options += 'd';
132  }
133 
134  if ( m_LargeFilesCB->isChecked() ) {
135  options += 'H';
136  }
137 
138  if ( m_IgnoreCaseCB->isChecked() ){
139  options += 'i';
140  }
141 
142  if ( m_ExpandTabsCB->isChecked() ) {
143  options += 't';
144  }
145 
146  if ( m_IgnoreEmptyLinesCB->isChecked() ) {
147  options += 'B';
148  }
149 
150  if ( m_IgnoreWhiteSpaceCB->isChecked() ) {
151  options += 'b';
152  }
153 
154  if ( m_FunctionNamesCB->isChecked() ) {
155  options += 'p';
156  }
157 
158 // if ( ) {
159 // cmdLine += " -w";
160 // }
161 
162  if ( m_RecursiveCB->isChecked() ) {
163  options += 'r';
164  }
165 
166  if( m_NewFilesCB->isChecked() ) {
167  options += 'N';
168  }
169 
170 // if( m_AllTextCB->isChecked() ) {
171 // options += 'a';
172 // }
173 
174  if( options.length() > 0 ) {
175  cmdLine += " -" + options;
176  }
177 
178  cmdLine += " -- ";
179  cmdLine += constructRelativePath( m_directoryRequester->url().pathOrUrl(), m_source );
180  cmdLine += ' ';
181  cmdLine += constructRelativePath( m_directoryRequester->url().pathOrUrl(), m_destination );
182 
183  m_CommandLineLabel->setText( cmdLine );
184 }
185 
186 void KompareSaveOptionsWidget::loadOptions()
187 {
188  m_SmallerChangesCB->setChecked ( m_settings->m_createSmallerDiff );
189  m_LargeFilesCB->setChecked ( m_settings->m_largeFiles );
190  m_IgnoreCaseCB->setChecked ( m_settings->m_ignoreChangesInCase );
191  m_ExpandTabsCB->setChecked ( m_settings->m_convertTabsToSpaces );
192  m_IgnoreEmptyLinesCB->setChecked( m_settings->m_ignoreEmptyLines );
193  m_IgnoreWhiteSpaceCB->setChecked( m_settings->m_ignoreWhiteSpace );
194  m_FunctionNamesCB->setChecked ( m_settings->m_showCFunctionChange );
195  m_RecursiveCB->setChecked ( m_settings->m_recursive );
196  m_NewFilesCB->setChecked ( m_settings->m_newFiles );
197 // m_AllTextCB->setChecked ( m_settings->m_allText );
198 
199  m_ContextLinesSB->setValue ( m_settings->m_linesOfContext );
200 
201  m_FormatBG->button(m_settings->m_format)->setChecked(true);
202 
203  updateCommandLine();
204 }
205 
206 void KompareSaveOptionsWidget::saveOptions()
207 {
208  m_settings->m_createSmallerDiff = m_SmallerChangesCB->isChecked();
209  m_settings->m_largeFiles = m_LargeFilesCB->isChecked();
210  m_settings->m_ignoreChangesInCase = m_IgnoreCaseCB->isChecked();
211  m_settings->m_convertTabsToSpaces = m_ExpandTabsCB->isChecked();
212  m_settings->m_ignoreEmptyLines = m_IgnoreEmptyLinesCB->isChecked();
213  m_settings->m_ignoreWhiteSpace = m_IgnoreWhiteSpaceCB->isChecked();
214  m_settings->m_showCFunctionChange = m_FunctionNamesCB->isChecked();
215  m_settings->m_recursive = m_RecursiveCB->isChecked();
216  m_settings->m_newFiles = m_NewFilesCB->isChecked();
217 // m_settings->m_allText = m_AllTextCB->isChecked();
218 
219  m_settings->m_linesOfContext = m_ContextLinesSB->value();
220 
221  m_settings->m_format = static_cast<Kompare::Format>( m_FormatBG->checkedId() );
222 
223 }
224 
225 #include "komparesaveoptionswidget.moc"
KompareSaveOptionsWidget::directory
QString directory() const
Definition: komparesaveoptionswidget.cpp:97
QWidget
QButtonGroup::addButton
void addButton(QAbstractButton *button)
QButtonGroup::button
QAbstractButton * button(int id) const
KompareSaveOptionsWidget::KompareSaveOptionsWidget
KompareSaveOptionsWidget(QString source, QString destination, DiffSettings *settings, QWidget *parent)
Definition: komparesaveoptionswidget.cpp:32
QButtonGroup
KompareSaveOptionsWidget::saveOptions
void saveOptions()
Definition: komparesaveoptionswidget.cpp:206
KompareSaveOptionsWidget::~KompareSaveOptionsWidget
~KompareSaveOptionsWidget()
Definition: komparesaveoptionswidget.cpp:92
QString::number
QString number(int n, int base)
QButtonGroup::setExclusive
void setExclusive(bool)
QObject::setObjectName
void setObjectName(const QString &name)
QString
KompareSaveOptionsWidget::updateCommandLine
void updateCommandLine()
Definition: komparesaveoptionswidget.cpp:102
QAbstractButton::setChecked
void setChecked(bool)
QButtonGroup::checkedId
int checkedId() const
QString::length
int length() const
komparesaveoptionswidget.h
KompareSaveOptionsBase
Definition: komparesaveoptionsbase.h:24
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:01 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kompare

Skip menu "kompare"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal