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