joachim99@8
|
1 /***************************************************************************
|
joachim99@8
|
2 main.cpp - Where everything starts.
|
joachim99@8
|
3 -------------------
|
joachim99@8
|
4 begin : Don Jul 11 12:31:29 CEST 2002
|
joachim99@77
|
5 copyright : (C) 2002-2007 by Joachim Eibl
|
joachim99@69
|
6 email : joachim.eibl at gmx.de
|
joachim99@8
|
7 ***************************************************************************/
|
joachim99@8
|
8
|
joachim99@8
|
9 /***************************************************************************
|
joachim99@8
|
10 * *
|
joachim99@8
|
11 * This program is free software; you can redistribute it and/or modify *
|
joachim99@8
|
12 * it under the terms of the GNU General Public License as published by *
|
joachim99@8
|
13 * the Free Software Foundation; either version 2 of the License, or *
|
joachim99@8
|
14 * (at your option) any later version. *
|
joachim99@8
|
15 * *
|
joachim99@8
|
16 ***************************************************************************/
|
joachim99@8
|
17
|
joachim99@8
|
18 #include <kcmdlineargs.h>
|
joachim99@8
|
19 #include <kaboutdata.h>
|
joachim99@8
|
20 #include <klocale.h>
|
joachim99@40
|
21 #include "kdiff3_shell.h"
|
joachim99@69
|
22 #include <kstandarddirs.h>
|
friseb123@16
|
23 #include "version.h"
|
joachim99@53
|
24 #include <qtextcodec.h>
|
joachim99@69
|
25 #include <qfile.h>
|
joachim99@69
|
26 #include <qtextstream.h>
|
joachim99@70
|
27 #include <QTranslator>
|
joachim99@75
|
28 #include <QLocale>
|
joachim99@80
|
29 #include <QFont>
|
joachim99@69
|
30 #include <vector>
|
joachim99@8
|
31
|
joachim99@66
|
32 #ifdef KREPLACEMENTS_H
|
joachim99@66
|
33 #include "optiondialog.h"
|
joachim99@66
|
34 #endif
|
joachim99@69
|
35 #include "common.h"
|
joachim99@8
|
36
|
joachim99@92
|
37 void initialiseCmdLineArgs( KCmdLineOptions& options )
|
joachim99@92
|
38 {
|
joachim99@92
|
39 QString configFileName = KStandardDirs().findResource("config","kdiff3rc");
|
joachim99@92
|
40 QFile configFile( configFileName );
|
joachim99@92
|
41 QString ignorableOptionsLine = "-u;-query;-html;-abort";
|
joachim99@92
|
42 if ( configFile.open( QIODevice::ReadOnly ) )
|
joachim99@92
|
43 {
|
joachim99@92
|
44 QTextStream ts( &configFile );
|
joachim99@92
|
45 while(!ts.atEnd())
|
joachim99@92
|
46 {
|
joachim99@92
|
47 QString line = ts.readLine();
|
joachim99@92
|
48 if ( line.startsWith("IgnorableCmdLineOptions=") )
|
joachim99@92
|
49 {
|
joachim99@92
|
50 int pos = line.indexOf('=');
|
joachim99@92
|
51 if (pos>=0)
|
joachim99@92
|
52 {
|
joachim99@92
|
53 ignorableOptionsLine = line.mid(pos+1);
|
joachim99@92
|
54 }
|
joachim99@92
|
55 break;
|
joachim99@92
|
56 }
|
joachim99@92
|
57 }
|
joachim99@92
|
58 }
|
joachim99@8
|
59
|
joachim99@92
|
60 #ifdef KREPLACEMENTS_H
|
joachim99@92
|
61 QStringList sl = ignorableOptionsLine.split( '|' );
|
joachim99@92
|
62 #else
|
joachim99@92
|
63 QStringList sl = ignorableOptionsLine.split( ',' );
|
joachim99@92
|
64 #endif
|
joachim99@92
|
65 if (!sl.isEmpty())
|
joachim99@92
|
66 {
|
joachim99@92
|
67 QStringList ignorableOptions = sl.front().split( ';' );
|
joachim99@92
|
68 for (QStringList::iterator i=ignorableOptions.begin(); i!=ignorableOptions.end(); ++i)
|
joachim99@92
|
69 {
|
joachim99@92
|
70 (*i).remove('-');
|
joachim99@92
|
71 if (!(*i).isEmpty())
|
joachim99@92
|
72 {
|
joachim99@92
|
73 if ( i->length()==1 )
|
joachim99@92
|
74 options.add( i->toLatin1() ).add("ignore", ki18n("Ignored. (User defined.)") );
|
joachim99@92
|
75 else
|
joachim99@92
|
76 options.add( i->toLatin1(), ki18n("Ignored. (User defined.)") );
|
joachim99@92
|
77 }
|
joachim99@92
|
78 }
|
joachim99@92
|
79 }
|
joachim99@92
|
80 }
|
joachim99@69
|
81
|
joachim99@8
|
82 #ifdef _WIN32
|
joachim99@8
|
83 #include <process.h>
|
joachim99@8
|
84 // This command checks the comm
|
joachim99@8
|
85 static bool isOptionUsed(const QString& s, int argc, char* argv[])
|
joachim99@8
|
86 {
|
joachim99@8
|
87 for(int j=0; j<argc; ++j )
|
joachim99@8
|
88 {
|
joachim99@8
|
89 if( "-"+s == argv[j] || "--"+s==argv[j] )
|
joachim99@8
|
90 {
|
joachim99@8
|
91 return true;
|
joachim99@8
|
92 }
|
joachim99@8
|
93 }
|
joachim99@8
|
94 return false;
|
joachim99@8
|
95 }
|
joachim99@8
|
96 #endif
|
joachim99@8
|
97
|
joachim99@80
|
98 class ContextFreeTranslator : public QTranslator
|
joachim99@80
|
99 {
|
joachim99@80
|
100 public:
|
joachim99@80
|
101 ContextFreeTranslator( QObject* pParent ) : QTranslator(pParent) {}
|
joachim99@80
|
102 QString translate(const char* context, const char* sourceText, const char* comment ) const
|
joachim99@80
|
103 {
|
joachim99@80
|
104 if ( context != 0 )
|
joachim99@80
|
105 return QTranslator::translate(0,sourceText,comment);
|
joachim99@80
|
106 else
|
joachim99@80
|
107 return QString();
|
joachim99@80
|
108 }
|
joachim99@80
|
109 };
|
joachim99@80
|
110
|
joachim99@8
|
111 int main(int argc, char *argv[])
|
joachim99@8
|
112 {
|
joachim99@8
|
113 #ifdef _WIN32
|
joachim99@8
|
114 /* KDiff3 can be used as replacement for the text-diff and merge tool provided by
|
joachim99@8
|
115 Clearcase. This is experimental and so far has only been tested under Windows.
|
joachim99@8
|
116
|
joachim99@69
|
117 There are two ways to use KDiff3 with clearcase
|
joachim99@69
|
118 - The file lib/mgrs/map contains the list of compare/merge tasks on one side and
|
joachim99@69
|
119 the tool on the other. Originally this contains only clearcase tools, but you can
|
joachim99@69
|
120 edit this file and put kdiff3 there instead. (Recommended method)
|
joachim99@69
|
121 - Exchange the original program with KDiff3: (Hackish, no fine control)
|
joachim99@69
|
122 1. In the Clearcase "bin"-directory rename "cleardiffmrg.exe" to "cleardiffmrg_orig.exe".
|
joachim99@69
|
123 2. Copy kdiff3.exe into that "bin"-directory and rename it to "cleardiffmrg.exe".
|
joachim99@69
|
124 (Also copy the other files that are needed by KDiff3 there.)
|
joachim99@69
|
125 Now when a file comparison or merge is done by Clearcase then of course KDiff3 will be
|
joachim99@69
|
126 run instead.
|
joachim99@69
|
127 If the commandline contains the option "-directory" then KDiff3 can't do it but will
|
joachim99@69
|
128 run "cleardiffmrg_orig.exe" instead.
|
joachim99@8
|
129 */
|
joachim99@8
|
130
|
joachim99@69
|
131 // Write all args into a temporary file. Uncomment this for debugging purposes.
|
joachim99@69
|
132 /*
|
joachim99@80
|
133 FILE* f = fopen(QDir::toNativeSeparators(QDir::homePath()+"//kdiff3_call_args.txt").toLatin1().data(),"w");
|
joachim99@8
|
134 for(int i=0; i< argc; ++i)
|
joachim99@8
|
135 fprintf(f,"Arg %d: %s\n", i, argv[i]);
|
joachim99@80
|
136 fclose(f);
|
joachim99@80
|
137
|
joachim99@69
|
138 // Call orig cleardiffmrg.exe to see what result it returns.
|
joachim99@69
|
139 int result=0;
|
joachim99@69
|
140 result = ::_spawnvp(_P_WAIT , "C:\\Programme\\Rational\\ClearCase\\bin\\cleardiffmrg.exe", argv );
|
joachim99@69
|
141 fprintf(f,"Result: %d\n", result );
|
joachim99@8
|
142 fclose(f);
|
joachim99@69
|
143 return result;
|
joachim99@8
|
144 */
|
joachim99@8
|
145
|
joachim99@8
|
146 // KDiff3 can replace cleardiffmrg from clearcase. But not all functions.
|
joachim99@8
|
147 if ( isOptionUsed( "directory", argc,argv ) )
|
joachim99@8
|
148 {
|
joachim99@8
|
149 return ::_spawnvp(_P_WAIT , "cleardiffmrg_orig", argv );
|
joachim99@8
|
150 }
|
joachim99@69
|
151
|
joachim99@8
|
152 #endif
|
joachim99@95
|
153 #ifdef Q_OS_OS2
|
joachim99@95
|
154 // expand wildcards on the command line
|
joachim99@95
|
155 _wildcard(&argc, &argv);
|
joachim99@95
|
156 #endif
|
joachim99@95
|
157
|
joachim99@69
|
158 //QApplication::setColorSpec( QApplication::ManyColor ); // Grab all 216 colors
|
joachim99@8
|
159
|
joachim99@80
|
160 const QByteArray& appName = QByteArray("kdiff3");
|
joachim99@80
|
161 const QByteArray& appCatalog = appName;
|
joachim99@80
|
162 const KLocalizedString i18nName = ki18n("kdiff3");
|
joachim99@80
|
163 const QByteArray& appVersion = QByteArray( VERSION );
|
joachim99@80
|
164 const KLocalizedString description = ki18n("Tool for Comparison and Merge of Files and Directories");
|
joachim99@103
|
165 const KLocalizedString copyright = ki18n("(c) 2002-2010 Joachim Eibl");
|
joachim99@80
|
166 const QByteArray& homePage = "http://kdiff3.sourceforge.net/";
|
joachim99@80
|
167 const QByteArray& bugsAddress = "joachim.eibl" "@" "gmx.de";
|
joachim99@80
|
168 KAboutData aboutData( appName, appCatalog, i18nName,
|
joachim99@80
|
169 appVersion, description, KAboutData::License_GPL_V2, copyright, description,
|
joachim99@80
|
170 homePage, bugsAddress );
|
joachim99@77
|
171
|
joachim99@80
|
172 aboutData.addAuthor(ki18n("Joachim Eibl"), KLocalizedString(), QByteArray("joachim.eibl" "@" "gmx.de"));
|
joachim99@80
|
173 aboutData.addCredit(ki18n("Eike Sauer"), ki18n("Bugfixes, Debian package maintainer") );
|
joachim99@80
|
174 aboutData.addCredit(ki18n("Sebastien Fricker"), ki18n("Windows installer") );
|
joachim99@80
|
175 aboutData.addCredit(ki18n("Stephan Binner"), ki18n("i18n-help"), QByteArray("binner" "@" "kde.org") );
|
joachim99@80
|
176 aboutData.addCredit(ki18n("Stefan Partheymueller"), ki18n("Clipboard-patch" ));
|
joachim99@80
|
177 aboutData.addCredit(ki18n("David Faure"), ki18n("KIO-Help"), QByteArray("faure" "@" "kde.org" ));
|
joachim99@80
|
178 aboutData.addCredit(ki18n("Bernd Gehrmann"), ki18n("Class CvsIgnoreList from Cervisia" ));
|
joachim99@80
|
179 aboutData.addCredit(ki18n("Andre Woebbeking"), ki18n("Class StringMatcher" ));
|
joachim99@80
|
180 aboutData.addCredit(ki18n("Michael Denio"), ki18n("Directory Equality-Coloring patch"));
|
joachim99@80
|
181 aboutData.addCredit(ki18n("Manfred Koehler"), ki18n("Fix for slow startup on Windows"));
|
joachim99@80
|
182 aboutData.addCredit(ki18n("Sergey Zorin"), ki18n("Diff Ext for Windows"));
|
joachim99@80
|
183 aboutData.addCredit(ki18n("Paul Eggert, Mike Haertel, David Hayes, Richard Stallman, Len Tower"), ki18n("GNU-Diffutils"));
|
joachim99@80
|
184 aboutData.addCredit(ki18n("Tino Boellsterling, Timothy Mee"), ki18n("Intensive test, use and feedback"));
|
joachim99@80
|
185 aboutData.addCredit(ki18n("Michael Schmidt"), ki18n("Mac support"));
|
joachim99@80
|
186 aboutData.addCredit(ki18n("Valentin Rusu"), ki18n("KDE4 porting"), QByteArray("kde" "@" "rusu.info"));
|
joachim99@80
|
187 aboutData.addCredit(ki18n("Albert Astals Cid"), ki18n("KDE4 porting"), QByteArray("aacid" "@" "kde.org"));
|
joachim99@80
|
188
|
joachim99@80
|
189 aboutData.addCredit(ki18n("+ Many thanks to those who reported bugs and contributed ideas!"));
|
joachim99@69
|
190
|
joachim99@8
|
191 KCmdLineArgs::init( argc, argv, &aboutData );
|
joachim99@80
|
192
|
joachim99@80
|
193 KCmdLineOptions options;
|
joachim99@80
|
194 // ignorable command options
|
joachim99@80
|
195 options.add( "m" ).add( "merge", ki18n("Merge the input."));
|
joachim99@80
|
196 options.add( "b" ).add( "base file", ki18n("Explicit base file. For compatibility with certain tools.") );
|
joachim99@80
|
197 options.add( "o" ).add( "output file", ki18n("Output file. Implies -m. E.g.: -o newfile.txt"));
|
joachim99@80
|
198 options.add( "out file", ki18n("Output file, again. (For compatibility with certain tools.)") );
|
joachim99@80
|
199 options.add( "auto", ki18n("No GUI if all conflicts are auto-solvable. (Needs -o file)") );
|
joachim99@80
|
200 options.add( "qall", ki18n("Don't solve conflicts automatically. (For compatibility...)") );
|
joachim99@80
|
201 options.add( "L1 alias1", ki18n("Visible name replacement for input file 1 (base).") );
|
joachim99@80
|
202 options.add( "L2 alias2", ki18n("Visible name replacement for input file 2.") );
|
joachim99@80
|
203 options.add( "L3 alias3", ki18n("Visible name replacement for input file 3.") );
|
joachim99@80
|
204 options.add( "L" ).add( "fname alias", ki18n("Alternative visible name replacement. Supply this once for every input.") );
|
joachim99@80
|
205 options.add( "cs string", ki18n("Override a config setting. Use once for every setting. E.g.: --cs \"AutoAdvance=1\"") );
|
joachim99@80
|
206 options.add( "confighelp", ki18n("Show list of config settings and current values.") );
|
joachim99@80
|
207 options.add( "config file", ki18n("Use a different config file.") );
|
joachim99@80
|
208
|
joachim99@80
|
209 // other command options
|
joachim99@80
|
210 options.add( "+[File1]", ki18n("file1 to open (base, if not specified via --base)") );
|
joachim99@80
|
211 options.add( "+[File2]", ki18n("file2 to open") );
|
joachim99@80
|
212 options.add( "+[File3]", ki18n("file3 to open") );
|
joachim99@80
|
213
|
joachim99@92
|
214 initialiseCmdLineArgs( options );
|
joachim99@92
|
215
|
joachim99@80
|
216 KCmdLineArgs::addCmdLineOptions( options );
|
joachim99@80
|
217
|
joachim99@53
|
218 KApplication app;
|
joachim99@69
|
219
|
joachim99@53
|
220 #ifdef KREPLACEMENTS_H
|
joachim99@66
|
221 QString locale;
|
joachim99@69
|
222
|
joachim99@66
|
223 locale = app.config()->readEntry("Language", "Auto");
|
joachim99@75
|
224 int spacePos = locale.indexOf(' ');
|
joachim99@66
|
225 if (spacePos>0) locale = locale.left(spacePos);
|
joachim99@80
|
226 ContextFreeTranslator kdiff3Translator( 0 );
|
joachim99@53
|
227 QTranslator qtTranslator( 0 );
|
joachim99@66
|
228 if (locale != "en_orig")
|
joachim99@66
|
229 {
|
joachim99@66
|
230 if ( locale == "Auto" || locale.isEmpty() )
|
joachim99@75
|
231 locale = locale = QLocale::system().name().left(2);
|
joachim99@66
|
232
|
joachim99@92
|
233 QString translationDir = getTranslationDir(locale);
|
joachim99@66
|
234 kdiff3Translator.load( QString("kdiff3_")+locale, translationDir );
|
joachim99@66
|
235 app.installTranslator( &kdiff3Translator );
|
joachim99@66
|
236
|
joachim99@66
|
237 qtTranslator.load( QString("qt_")+locale, translationDir );
|
joachim99@66
|
238 app.installTranslator( &qtTranslator );
|
joachim99@66
|
239 }
|
joachim99@53
|
240 #endif
|
joachim99@8
|
241
|
joachim99@80
|
242 if (app.isSessionRestored())
|
joachim99@8
|
243 {
|
joachim99@8
|
244 RESTORE(KDiff3Shell);
|
joachim99@8
|
245 }
|
joachim99@8
|
246 else
|
joachim99@8
|
247 {
|
joachim99@80
|
248 KDiff3Shell* p = new KDiff3Shell();
|
joachim99@80
|
249 p->show();
|
joachim99@8
|
250 }
|
joachim99@80
|
251 //app.installEventFilter( new CFilter );
|
joachim99@69
|
252 int retVal = app.exec();
|
joachim99@69
|
253 return retVal;
|
joachim99@8
|
254 }
|
joachim99@53
|
255
|
joachim99@53
|
256 // Suppress warning with --enable-final
|
joachim99@53
|
257 #undef VERSION
|