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

kompare

  • sources
  • kde-4.12
  • kdesdk
  • kompare
main.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  main.cpp
3  --------
4  begin : Sun Mar 4 2001
5  Copyright 2001-2005,2009 Otto Bruggeman <bruggie@gmail.com>
6  Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
7  Copyright 2007-2012 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 ***************************************************************************/
27 #include <kaboutdata.h>
28 #include <kcmdlineargs.h>
29 #include <kdebug.h>
30 #include <kfile.h>
31 #include <klocale.h>
32 #include <kmessagebox.h>
33 #include <kdialog.h>
34 
35 #include "kompare_part.h"
36 #include "kompare_shell.h"
37 #include "kompareurldialog.h"
38 
42 static const char description[] =
43  I18N_NOOP("A program to view the differences between files and optionally generate a diff" );
44 
48 static const char version[] = "4.1.3";
49 
57 int main(int argc, char *argv[])
58 {
59  KAboutData aboutData( "kompare", 0, ki18n("Kompare"), version, ki18n(description),
60  KAboutData::License_GPL,
61  ki18n("(c) 2001-2004 John Firebaugh, (c) 2001-2005,2009 Otto Bruggeman, (c) 2004-2005 Jeff Snyder, (c) 2007-2012 Kevin Kofler") );
62  aboutData.addAuthor( ki18n("John Firebaugh"), ki18n("Author"), "jfirebaugh@kde.org" );
63  aboutData.addAuthor( ki18n("Otto Bruggeman"), ki18n("Author"), "bruggie@gmail.com" );
64  aboutData.addAuthor( ki18n("Jeff Snyder"), ki18n("Developer"), "jeff@caffeinated.me.uk" );
65  aboutData.addCredit( ki18n("Kevin Kofler"), ki18n("Maintainer"), "kevin.kofler@chello.at" );
66  aboutData.addCredit( ki18n("Chris Luetchford"), ki18n("Kompare icon artist"), "chris@os11.com" );
67  aboutData.addCredit( ki18n("Malte Starostik"), ki18n("A lot of good advice"), "malte@kde.org" );
68  aboutData.addCredit( ki18n("Bernd Gehrmann"), ki18n("Cervisia diff viewer"), "bernd@physik.hu-berlin.de" );
69 
70  KCmdLineArgs::init(argc, argv, &aboutData);
71 
72  KCmdLineOptions options;
73  options.add("c", ki18n( "This will compare URL1 with URL2" ));
74  options.add("o", ki18n( "This will open URL1 and expect it to be diff output. URL1 can also be a '-' and then it will read from standard input. Can be used for instance for cvs diff | kompare -o -. Kompare will do a check to see if it can find the original file(s) and then blend the original file(s) into the diffoutput and show that in the viewer. -n disables the check." ));
75  options.add("b", ki18n( "This will blend URL2 into URL1, URL2 is expected to be diff output and URL1 the file or folder that the diffoutput needs to be blended into. " ));
76  options.add("n", ki18n( "Disables the check for automatically finding the original file(s) when using '-' as URL with the -o option." ));
77  options.add("e <encoding>", ki18n( "Use this to specify the encoding when calling it from the command line. It will default to the local encoding if not specified." ));
78  options.add("+[URL1 [URL2]]");
79  options.add("+-");
80  KCmdLineArgs::addCmdLineOptions( options );
81  KApplication kompare;
82  bool difault = false;
83 
84  KompareShell* ks;
85 
86  // see if we are starting with session management
87  if (kompare.isSessionRestored())
88  {
89  RESTORE(KompareShell)
90  }
91  else
92  {
93  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
94 
95  ks = new KompareShell();
96  ks->setObjectName( "FirstKompareShell" );
97 
98  kDebug( 8100 ) << "Arg Count = " << args->count() << endl;
99  for ( int i=0; i < args->count(); i++ )
100  {
101  kDebug( 8100 ) << "Argument " << (i+1) << ": " << args->arg( i ) << endl;
102  }
103 
104  if ( args->isSet( "e" ) )
105  {
106  // Encoding given...
107  // FIXME: Need to implement this...
108  }
109 
110  if ( args->isSet( "o" ) )
111  {
112  kDebug( 8100 ) << "Option -o is set" << endl;
113  if ( args->count() != 1 )
114  {
115  difault = true;
116  }
117  else
118  {
119  ks->show();
120  kDebug( 8100 ) << "OpenDiff..." << endl;
121  if ( args->arg(0) == QLatin1String("-") )
122  ks->openStdin();
123  else
124  ks->openDiff( args->url( 0 ) );
125  difault = false;
126  }
127  }
128  else if ( args->isSet( "c" ) )
129  {
130  kDebug( 8100 ) << "Option -c is set" << endl;
131  if ( args->count() != 2 )
132  {
133  KCmdLineArgs::usage( "kompare" );
134  difault = true;
135  }
136  else
137  {
138  ks->show();
139  KUrl url0 = args->url( 0 );
140  kDebug( 8100 ) << "URL0 = " << url0.url() << endl;
141  KUrl url1 = args->url( 1 );
142  kDebug( 8100 ) << "URL1 = " << url1.url() << endl;
143  ks->compare( url0, url1 );
144  difault = false;
145  }
146  }
147  else if ( args->isSet( "b" ) )
148  {
149  kDebug( 8100 ) << "Option -b is set" << endl;
150  if ( args->count() != 2 )
151  {
152  KCmdLineArgs::usage( "kompare" );
153  difault = true;
154  }
155  else
156  {
157  ks->show();
158  kDebug( 8100 ) << "blend..." << endl;
159  KUrl url0 = args->url( 0 );
160  kDebug( 8100 ) << "URL0 = " << url0.url() << endl;
161  KUrl url1 = args->url( 1 );
162  kDebug( 8100 ) << "URL1 = " << url1.url() << endl;
163  ks->blend( url0, url1 );
164  difault = false;
165  }
166  }
167  else if ( args->count() == 1 )
168  {
169  ks->show();
170 
171  kDebug( 8100 ) << "Single file. so openDiff/openStdin is only possible..." << endl;
172  if ( args->arg(0) == QLatin1String("-") )
173  ks->openStdin();
174  else
175  ks->openDiff( args->url( 0 ) );
176 
177  difault = false;
178  }
179  else if ( args->count() == 2 )
180  {
181  // In this case we are assuming you want to compare files/dirs
182  // and not blending because that is almost impossible to detect
183  ks->show();
184  kDebug( 8100 ) << "Dunno, we'll have to figure it out later, trying compare for now..." << endl;
185  KUrl url0 = args->url( 0 );
186  kDebug( 8100 ) << "URL0 = " << url0.url() << endl;
187  KUrl url1 = args->url( 1 );
188  kDebug( 8100 ) << "URL1 = " << url1.url() << endl;
189  ks->compare( url0, url1 );
190  difault = false;
191  }
192  else if ( args->count() == 0 ) // no options and no args
193  {
194  difault = true;
195  }
196 
197  if ( difault )
198  {
199  KompareURLDialog dialog( 0 );
200 
201  dialog.setCaption( i18n("Compare Files or Folders") );
202  dialog.setFirstGroupBoxTitle( i18n( "Source" ) );
203  dialog.setSecondGroupBoxTitle( i18n( "Destination" ) );
204 
205  KGuiItem compareGuiItem( i18n( "Compare" ), QString(), i18n( "Compare these files or folder" ), i18n( "If you have entered 2 filenames or 2 folders in the fields in this dialog then this button will be enabled and pressing it will start a comparison of the entered files or folders. " ) );
206  dialog.setButtonGuiItem( KDialog::Ok, compareGuiItem );
207 
208  dialog.setGroup( "Recent Compare Files" );
209 
210  dialog.setFirstURLRequesterMode( KFile::File|KFile::Directory|KFile::ExistingOnly );
211  dialog.setSecondURLRequesterMode( KFile::File|KFile::Directory|KFile::ExistingOnly );
212 
213  if( dialog.exec() == QDialog::Accepted )
214  {
215  ks->show();
216  ks->viewPart()->setEncoding( dialog.encoding() );
217  ks->compare( dialog.getFirstURL(), dialog.getSecondURL() );
218  }
219  else
220  {
221  return -1;
222  }
223  }
224 
225  args->clear();
226  }
227 
228  return kompare.exec();
229 }
230 
231 /* vim: set ts=4 sw=4 noet: */
232 
KompareURLDialog::encoding
QString encoding() const
Returns the encoding.
Definition: kompareurldialog.cpp:157
KompareURLDialog
Definition of class KompareURLDialog.
Definition: kompareurldialog.h:38
KompareURLDialog::getFirstURL
KUrl getFirstURL() const
Returns the first URL, which was entered.
Definition: kompareurldialog.cpp:139
KompareInterface::setEncoding
virtual void setEncoding(const QString &encoding)
This will set the encoding to use for all files that are read or for the diffoutput.
Definition: kompareinterface.cpp:72
KompareShell::blend
void blend(const KUrl &url1, const KUrl &diff)
Use this method to blend diff into url1 (file or directory)
Definition: kompare_shell.cpp:187
kompare_part.h
KompareURLDialog::getSecondURL
KUrl getSecondURL() const
Returns the second URL, which was entered.
Definition: kompareurldialog.cpp:148
KompareShell::openStdin
void openStdin()
Use this method to load the diff from stdin.
Definition: kompare_shell.cpp:164
kompare_shell.h
KompareURLDialog::setSecondURLRequesterMode
void setSecondURLRequesterMode(unsigned int mode)
Definition: kompareurldialog.cpp:184
kompareurldialog.h
KompareURLDialog::setSecondGroupBoxTitle
void setSecondGroupBoxTitle(const QString &title)
Definition: kompareurldialog.cpp:167
KompareURLDialog::setFirstGroupBoxTitle
void setFirstGroupBoxTitle(const QString &title)
Definition: kompareurldialog.cpp:162
KompareURLDialog::setFirstURLRequesterMode
void setFirstURLRequesterMode(unsigned int mode)
Definition: kompareurldialog.cpp:179
KompareShell::viewPart
KompareInterface * viewPart() const
Definition: kompare_shell.cpp:463
KompareShell::compare
void compare(const KUrl &source, const KUrl &destination)
Use this method to compare 2 URLs (files or directories)
Definition: kompare_shell.cpp:179
aboutData
static KAboutData aboutData()
Definition: komparenavtreepart.cpp:767
description
static const char description[]
Program description.
Definition: main.cpp:42
KompareURLDialog::setGroup
void setGroup(const QString &groupName)
Definition: kompareurldialog.cpp:172
KompareShell::openDiff
void openDiff(const KUrl &url)
Use this method to load whatever file/URL you have.
Definition: kompare_shell.cpp:157
main
int main(int argc, char *argv[])
Setting up the KAboutData structure.
Definition: main.cpp:57
KompareShell
This is the application "Shell".
Definition: kompare_shell.h:55
version
static const char version[]
Version number.
Definition: main.cpp:48
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:39 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
  • okteta
  • 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