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