comparison kdiff3/src-QT4/kreplacements/kreplacements.cpp @ 75:08ea9b86c12c

KDiff3-0.9.91
author joachim99
date Sat, 04 Nov 2006 00:05:00 +0000
parents kdiff3/src/kreplacements/kreplacements.cpp@f7dad0aa6146
children fcd146072e0c
comparison
equal deleted inserted replaced
74:069521efec1a 75:08ea9b86c12c
1 /***************************************************************************
2 kreplacements.cpp - description
3 -------------------
4 begin : Sat Aug 3 2002
5 copyright : (C) 2002-2006 by Joachim Eibl
6 email : joachim.eibl at gmx.de
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
19 #include "kreplacements.h"
20 #include "common.h"
21
22 #include <assert.h>
23
24 #include <qnamespace.h>
25 #include <qmessagebox.h>
26 #include <qmenu.h>
27 #include <qmenubar.h>
28 #include <qpainter.h>
29 #include <qcolordialog.h>
30 #include <qfontdialog.h>
31 #include <qlabel.h>
32 #include <qtextbrowser.h>
33 #include <qtextstream.h>
34 #include <qlayout.h>
35 #include <QTabWidget>
36 #include <QPaintEvent>
37 #include <QPixmap>
38 #include <QProcess>
39
40 #include <QTabWidget>
41 #include <QFileInfo>
42 #include <QFileDialog>
43
44 #include <vector>
45 #include <iostream>
46 #include <algorithm>
47
48
49 static QString s_copyright;
50 static QString s_email;
51 static QString s_description;
52 static QString s_appName;
53 static QString s_version;
54 static QString s_homepage;
55 static KAboutData* s_pAboutData;
56
57
58 #ifdef _WIN32
59 #include <process.h>
60 #include <windows.h>
61 #endif
62
63 static void showHelp()
64 {
65 #ifdef _WIN32
66 char buf[200];
67 int r= SearchPathA( 0, ".", 0, sizeof(buf), buf, 0 );
68
69 QString exePath;
70 if (r!=0) { exePath = buf; }
71 else { exePath = "."; }
72
73 QFileInfo helpFile( exePath + "\\doc\\en\\index.html" );
74 if ( ! helpFile.exists() ) { helpFile.setFile( exePath + "\\..\\doc\\en\\index.html" ); }
75 if ( ! helpFile.exists() ) { helpFile.setFile( exePath + "\\doc\\index.html" ); }
76 if ( ! helpFile.exists() ) { helpFile.setFile( exePath + "\\..\\doc\\index.html" ); }
77 if ( ! helpFile.exists() )
78 {
79 QMessageBox::warning( 0, "KDiff3 documentation not found",
80 "Couldn't find the documentation. \n\n"
81 "The documentation can also be found at the homepage:\n\n "
82 " http://kdiff3.sourceforge.net/");
83 return;
84 }
85
86 HINSTANCE hi = FindExecutableA( helpFile.fileName().toAscii(), helpFile.absolutePath().toAscii(), buf );
87 if ( int(hi)<=32 )
88 {
89 static QTextBrowser* pBrowser = 0;
90 if (pBrowser==0)
91 {
92 pBrowser = new QTextBrowser( 0 );
93 pBrowser->setMinimumSize( 600, 400 );
94 }
95 pBrowser->setSource(helpFile.filePath());
96 pBrowser->show();
97 }
98 else
99 {
100 QFileInfo prog( buf );
101 //_spawnlp( _P_NOWAIT , prog.filePath().toAscii(), prog.fileName().toAscii(), (""+.absFilePath()).toAscii(), NULL );
102 QProcess::startDetached ( prog.filePath() + " \"file:///" + helpFile.absolutePath() + "\"" );
103 }
104
105 #else
106 static QTextBrowser* pBrowser = 0;
107 if (pBrowser==0)
108 {
109 pBrowser = new QTextBrowser( 0 );
110 pBrowser->setMinimumSize( 600, 400 );
111 }
112 pBrowser->setSource(QUrl("file://usr/local/share/doc/kdiff3/en/index.html"));
113 pBrowser->show();
114 #endif
115 }
116
117 QString getTranslationDir()
118 {
119 #ifdef _WIN32
120 char buf[200];
121 int r= SearchPathA( 0, ".", 0, sizeof(buf), buf, 0 );
122
123 QString exePath;
124 if (r!=0) { exePath = buf; }
125 else { exePath = "."; }
126 return exePath+"/translations";
127 #else
128 return ".";
129 #endif
130 }
131
132 // static
133 void KMessageBox::error( QWidget* parent, const QString& text, const QString& caption )
134 {
135 QMessageBox::critical( parent, caption, text );
136 }
137
138 int KMessageBox::warningContinueCancel( QWidget* parent, const QString& text, const QString& caption,
139 const QString& button1 )
140 {
141 return 0 == QMessageBox::warning( parent, caption, text, button1, "Cancel" ) ? Continue : Cancel;
142 }
143
144 void KMessageBox::sorry( QWidget* parent, const QString& text, const QString& caption )
145 {
146 QMessageBox::information( parent, caption, text );
147 }
148
149 void KMessageBox::information( QWidget* parent, const QString& text, const QString& caption )
150 {
151 QMessageBox::information( parent, caption, text );
152 }
153
154 int KMessageBox::warningYesNo( QWidget* parent, const QString& text, const QString& caption,
155 const QString& button1, const QString& button2 )
156 {
157 return 0 == QMessageBox::warning( parent, caption, text, button1, button2, QString::null, 1, 1 ) ? Yes : No;
158 }
159
160 int KMessageBox::warningYesNoCancel( QWidget* parent, const QString& text, const QString& caption,
161 const QString& button1, const QString& button2 )
162 {
163 int val = QMessageBox::warning( parent, caption, text,
164 button1, button2, i18n("Cancel") );
165 if ( val==0 ) return Yes;
166 if ( val==1 ) return No;
167 else return Cancel;
168 }
169
170
171 KDialogBase::KDialogBase( int, const QString& caption, int, int, QWidget* parent, const char* name,
172 bool /*modal*/, bool )
173 : QDialog( parent )
174 {
175 setObjectName(name);
176 setModal(true);
177 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
178 m_pTabWidget = new QTabWidget();
179 pMainLayout->addWidget(m_pTabWidget,1);
180
181 QHBoxLayout* pButtonLayout = new QHBoxLayout();
182 pMainLayout->addLayout( pButtonLayout );
183
184 pButtonLayout->addStretch(1);
185 QPushButton* pOk = new QPushButton( i18n("Ok") );
186 connect( pOk, SIGNAL( clicked() ), this, SLOT(accept()) );
187 pButtonLayout->addWidget( pOk );
188
189 QPushButton* pHelp = new QPushButton( i18n("Help") );
190 connect( pHelp, SIGNAL( clicked() ), this, SLOT(slotHelp()));
191 pButtonLayout->addWidget( pHelp );
192
193 QPushButton* pDefaults = new QPushButton( i18n("Defaults") );
194 connect( pDefaults, SIGNAL( clicked() ), this, SLOT(slotDefault()) );
195 pButtonLayout->addWidget( pDefaults );
196
197 QPushButton* pCancel = new QPushButton( i18n("Cancel") );
198 connect( pCancel, SIGNAL( clicked() ), this, SLOT(reject()));
199 pButtonLayout->addWidget( pCancel );
200
201 setWindowTitle( caption );
202 }
203
204 KDialogBase::~KDialogBase()
205 {
206 }
207
208 void KDialogBase::incInitialSize ( const QSize& )
209 {
210 }
211
212 void KDialogBase::setHelp(const QString&, const QString& )
213 {
214 }
215
216
217 int KDialogBase::BarIcon(const QString& /*iconName*/, int )
218 {
219 return 0; // Not used for replacement.
220 }
221
222
223 QFrame* KDialogBase::addPage( const QString& name, const QString& /*info*/, int )
224 {
225 QFrame* p = new QFrame();
226 p->setObjectName( name );
227 m_pTabWidget->addTab( p, name );
228 return p;
229 }
230
231 int KDialogBase::spacingHint()
232 {
233 return 3;
234 }
235
236 static bool s_inAccept = false;
237 static bool s_bAccepted = false;
238 void KDialogBase::accept()
239 {
240 if( ! s_inAccept )
241 {
242 s_bAccepted = false;
243 s_inAccept = true;
244 slotOk();
245 s_inAccept = false;
246 if ( s_bAccepted )
247 QDialog::accept();
248 }
249 else
250 {
251 s_bAccepted = true;
252 }
253 }
254
255 void KDialogBase::slotDefault( )
256 {
257 }
258 void KDialogBase::slotOk()
259 {
260 }
261 void KDialogBase::slotCancel( )
262 {
263 }
264 void KDialogBase::slotApply( )
265 {
266 emit applyClicked();
267 }
268 void KDialogBase::slotHelp( )
269 {
270 showHelp();
271 }
272
273 KURL KFileDialog::getSaveURL( const QString &startDir,
274 const QString &filter,
275 QWidget *parent, const QString &caption)
276 {
277 QString s = QFileDialog::getSaveFileName(parent, caption, startDir, filter, 0/*, QFileDialog::DontUseNativeDialog*/);
278 return KURL(s);
279 }
280
281 KURL KFileDialog::getOpenURL( const QString & startDir,
282 const QString & filter,
283 QWidget * parent,
284 const QString & caption )
285 {
286 QString s = QFileDialog::getOpenFileName(parent, caption, startDir, filter );
287 return KURL(s);
288 }
289
290 KURL KFileDialog::getExistingURL( const QString & startDir,
291 QWidget * parent,
292 const QString & caption)
293 {
294 QString s = QFileDialog::getExistingDirectory(parent, caption, startDir);
295 return KURL(s);
296 }
297
298 QString KFileDialog::getSaveFileName (const QString &startDir,
299 const QString &filter,
300 QWidget *parent,
301 const QString &caption)
302 {
303 return QFileDialog::getSaveFileName( parent, caption, startDir, filter );
304 }
305
306
307 KToolBar::BarPosition KToolBar::barPos()
308 {
309 if ( m_pMainWindow->toolBarArea(this)==Qt::LeftToolBarArea ) return Left;
310 if ( m_pMainWindow->toolBarArea(this)==Qt::RightToolBarArea ) return Right;
311 if ( m_pMainWindow->toolBarArea(this)==Qt::BottomToolBarArea ) return Bottom;
312 if ( m_pMainWindow->toolBarArea(this)==Qt::TopToolBarArea ) return Top;
313 return Top;
314 }
315
316 void KToolBar::setBarPos(BarPosition bp)
317 {
318 if ( bp == Left ) m_pMainWindow->addToolBar ( Qt::LeftToolBarArea, this );
319 else if ( bp == Right ) m_pMainWindow->addToolBar ( Qt::RightToolBarArea, this );
320 else if ( bp == Bottom ) m_pMainWindow->addToolBar ( Qt::BottomToolBarArea, this );
321 else if ( bp == Top ) m_pMainWindow->addToolBar ( Qt::TopToolBarArea, this );
322 }
323
324 KToolBar::KToolBar( QMainWindow* parent )
325 : QToolBar( parent )
326 {
327 m_pMainWindow = parent;
328 }
329
330
331 KMainWindow::KMainWindow( QWidget* parent, const char* name )
332 : QMainWindow( parent ), m_actionCollection(this)
333 {
334 setObjectName(name);
335 fileMenu = menuBar()->addMenu( i18n("&File") );
336 editMenu = menuBar()->addMenu(i18n("&Edit") );
337 directoryMenu = menuBar()->addMenu(i18n("&Directory") );
338 dirCurrentItemMenu = 0;
339 dirCurrentSyncItemMenu = 0;
340 movementMenu = menuBar()->addMenu(i18n("&Movement") );
341 diffMenu = menuBar()->addMenu(i18n("D&iffview") );
342 mergeMenu = menuBar()->addMenu(i18n("&Merge") );
343 windowsMenu = menuBar()->addMenu(i18n("&Window") );
344 settingsMenu = menuBar()->addMenu(i18n("&Settings") );
345 helpMenu = menuBar()->addMenu(i18n("&Help") );
346
347 m_pToolBar = new KToolBar(this);
348
349 memberList = new QList<KMainWindow*>;
350 memberList->append(this);
351 }
352
353 KToolBar* KMainWindow::toolBar(const QString&)
354 {
355 return m_pToolBar;
356 }
357
358 KActionCollection* KMainWindow::actionCollection()
359 {
360 return &m_actionCollection;
361 }
362
363 void KMainWindow::createGUI()
364 {
365 KStdAction::help(this, SLOT(slotHelp()), actionCollection());
366 KStdAction::about(this, SLOT(slotAbout()), actionCollection());
367 KStdAction::aboutQt(actionCollection());
368 }
369
370 void KMainWindow::slotAbout()
371 {
372 QDialog d;
373 QVBoxLayout* l = new QVBoxLayout( &d );
374 QTabWidget* pTabWidget = new QTabWidget;
375 l->addWidget( pTabWidget );
376
377 QPushButton* pOkButton = new QPushButton(i18n("Ok"));
378 connect( pOkButton, SIGNAL(clicked()), &d, SLOT(accept()));
379 l->addWidget( pOkButton );
380
381 d.setWindowTitle("About " + s_appName);
382 QTextBrowser* tb1 = new QTextBrowser();
383 tb1->setWordWrapMode( QTextOption::NoWrap );
384 tb1->setText(
385 s_appName + " Version " + s_version +
386 "\n\n" + s_description +
387 "\n\n" + s_copyright +
388 "\n\nHomepage: " + s_homepage +
389 "\n\nLicence: GNU GPL Version 2"
390 );
391 pTabWidget->addTab(tb1,i18n("&About"));
392
393 std::list<KAboutData::AboutDataEntry>::iterator i;
394
395 QString s2;
396 for( i=s_pAboutData->m_authorList.begin(); i!=s_pAboutData->m_authorList.end(); ++i )
397 {
398 if ( !i->m_name.isEmpty() ) s2 += i->m_name + "\n";
399 if ( !i->m_task.isEmpty() ) s2 += " " + i->m_task + "\n";
400 if ( !i->m_email.isEmpty() ) s2 += " " + i->m_email + "\n";
401 if ( !i->m_weblink.isEmpty() ) s2 += " " + i->m_weblink + "\n";
402 s2 += "\n";
403 }
404 QTextBrowser* tb2 = new QTextBrowser();
405 tb2->setWordWrapMode( QTextOption::NoWrap );
406 tb2->setText(s2);
407 pTabWidget->addTab(tb2,i18n("A&uthor"));
408
409 QString s3;
410 for( i=s_pAboutData->m_creditList.begin(); i!=s_pAboutData->m_creditList.end(); ++i )
411 {
412 if ( !i->m_name.isEmpty() ) s3 += i->m_name + "\n";
413 if ( !i->m_task.isEmpty() ) s3 += " " + i->m_task + "\n";
414 if ( !i->m_email.isEmpty() ) s3 += " " + i->m_email + "\n";
415 if ( !i->m_weblink.isEmpty() ) s3 += " " + i->m_weblink + "\n";
416 s3 += "\n";
417 }
418 QTextBrowser* tb3 = new QTextBrowser();
419 tb3->setWordWrapMode( QTextOption::NoWrap );
420 tb3->setText(s3);
421 pTabWidget->addTab(tb3,i18n("&Thanks To"));
422
423 d.resize(400,300);
424 d.exec();
425 /*
426 QMessageBox::information(
427 this,
428 "About " + s_appName,
429 s_appName + " Version " + s_version +
430 "\n\n" + s_description +
431 "\n\n" + s_copyright +
432 "\n\nHomepage: " + s_homepage +
433 "\n\nLicence: GNU GPL Version 2"
434 );
435 */
436 }
437
438 void KMainWindow::slotHelp()
439 {
440 showHelp();
441 }
442
443
444 QString KStandardDirs::findResource(const QString& resource, const QString& /*appName*/)
445 {
446 if (resource=="config")
447 {
448 QString home = QDir::homePath();
449 return home + "/.kdiff3rc";
450 }
451 return QString();
452 }
453
454 KConfig::KConfig()
455 {
456 }
457
458 void KConfig::readConfigFile( const QString& configFileName )
459 {
460 if ( !configFileName.isEmpty() )
461 {
462 m_fileName = configFileName;
463 }
464 else
465 {
466 m_fileName = KStandardDirs().findResource("config","kdiff3rc");
467 }
468
469 QFile f( m_fileName );
470 if ( f.open(QIODevice::ReadOnly) )
471 { // file opened successfully
472 QTextStream t( &f ); // use a text stream
473 load(t);
474 f.close();
475 }
476 }
477
478 KConfig::~KConfig()
479 {
480 QFile f(m_fileName);
481 if ( f.open( QIODevice::WriteOnly | QIODevice::Text ) )
482 { // file opened successfully
483 QTextStream t( &f ); // use a text stream
484 save(t);
485 f.close();
486 }
487 }
488
489 void KConfig::setGroup(const QString&)
490 {
491 }
492
493 void KAction::init(QObject* receiver, const char* slot, KActionCollection* actionCollection,
494 const char* name, bool bToggle, bool bMenu)
495 {
496 QString n(name);
497 KMainWindow* p = actionCollection->m_pMainWindow;
498 if( slot!=0 )
499 {
500 if (!bToggle)
501 connect(this, SIGNAL(triggered()), receiver, slot);
502 else
503 {
504 connect(this, SIGNAL(toggled(bool)), receiver, slot);
505 }
506 }
507
508 if (bMenu)
509 {
510 if( n[0]=='g') p->movementMenu->addAction( this );
511 else if( n.left(16)=="dir_current_sync")
512 {
513 if ( p->dirCurrentItemMenu==0 )
514 {
515 p->dirCurrentItemMenu = p->directoryMenu->addMenu( i18n("Current Item Merge Operation") );
516 p->dirCurrentSyncItemMenu = p->directoryMenu->addMenu( i18n("Current Item Sync Operation") );
517 }
518 p->dirCurrentItemMenu->addAction( this );
519 }
520 else if( n.left(11)=="dir_current")
521 {
522 if ( p->dirCurrentItemMenu==0 )
523 {
524 p->dirCurrentItemMenu = p->directoryMenu->addMenu( i18n("Current Item Merge Operation") );
525 p->dirCurrentSyncItemMenu = p->directoryMenu->addMenu( i18n("Current Item Sync Operation") );
526 }
527 p->dirCurrentSyncItemMenu->addAction( this );
528 }
529 else if( n.left(4)=="diff") p->diffMenu->addAction( this );
530 else if( name[0]=='d') p->directoryMenu->addAction( this );
531 else if( name[0]=='f') p->fileMenu->addAction( this );
532 else if( name[0]=='w') p->windowsMenu->addAction( this );
533 else p->mergeMenu->addAction( this );
534 }
535 }
536
537
538 KAction::KAction(const QString& text, const QIcon& icon, int accel,
539 QObject* receiver, const char* slot, KActionCollection* actionCollection,
540 const char* name, bool bToggle, bool bMenu
541 )
542 : QAction ( icon, text, actionCollection->m_pMainWindow )
543 {
544 setObjectName(name);
545 setShortcut( accel );
546 setCheckable( bToggle );
547 KMainWindow* p = actionCollection->m_pMainWindow;
548 if ( !icon.isNull() && p ) p->m_pToolBar->addAction( this );
549
550 init(receiver,slot,actionCollection,name,bToggle,bMenu);
551 }
552
553 KAction::KAction(const QString& text, int accel,
554 QObject* receiver, const char* slot, KActionCollection* actionCollection,
555 const char* name, bool bToggle, bool bMenu
556 )
557 : QAction ( text, actionCollection->m_pMainWindow )
558 {
559 setObjectName(name);
560 setShortcut( accel );
561 setCheckable( bToggle );
562 init(receiver,slot,actionCollection,name,bToggle,bMenu);
563 }
564
565 void KAction::setStatusText(const QString&)
566 {
567 }
568
569 void KAction::plug(QMenu* menu)
570 {
571 menu->addAction( this );
572 }
573
574
575 KToggleAction::KToggleAction(const QString& text, const QIcon& icon, int accel, QObject* receiver, const char* slot, KActionCollection* actionCollection, const char* name, bool bMenu)
576 : KAction( text, icon, accel, receiver, slot, actionCollection, name, true, bMenu)
577 {
578 }
579
580 KToggleAction::KToggleAction(const QString& text, int accel, QObject* receiver, const char* slot, KActionCollection* actionCollection, const char* name, bool bMenu)
581 : KAction( text, accel, receiver, slot, actionCollection, name, true, bMenu)
582 {
583 }
584
585 KToggleAction::KToggleAction(const QString& text, const QIcon& icon, int accel, KActionCollection* actionCollection, const char* name, bool bMenu)
586 : KAction( text, icon, accel, 0, 0, actionCollection, name, true, bMenu)
587 {
588 }
589
590 void KToggleAction::setChecked(bool bChecked)
591 {
592 blockSignals( true );
593 QAction::setChecked( bChecked );
594 blockSignals( false );
595 }
596
597
598 //static
599 KAction* KStdAction::open( QWidget* parent, const char* slot, KActionCollection* actionCollection)
600 {
601 #include "../xpm/fileopen.xpm"
602 KMainWindow* p = actionCollection->m_pMainWindow;
603 KAction* a = new KAction( i18n("Open"), QIcon(QPixmap(fileopen)), Qt::CTRL+Qt::Key_O, parent, slot, actionCollection, "open", false, false);
604 if(p){ p->fileMenu->addAction( a ); }
605 return a;
606 }
607
608 KAction* KStdAction::save( QWidget* parent, const char* slot, KActionCollection* actionCollection )
609 {
610 #include "../xpm/filesave.xpm"
611 KMainWindow* p = actionCollection->m_pMainWindow;
612 KAction* a = new KAction( i18n("Save"), QIcon(QPixmap(filesave)), Qt::CTRL+Qt::Key_S, parent, slot, actionCollection, "save", false, false);
613 if(p){ p->fileMenu->addAction( a ); }
614 return a;
615 }
616
617 KAction* KStdAction::saveAs( QWidget* parent, const char* slot, KActionCollection* actionCollection)
618 {
619 KMainWindow* p = actionCollection->m_pMainWindow;
620 KAction* a = new KAction( i18n("Save As..."), 0, parent, slot, actionCollection, "saveas", false, false);
621 if(p) p->fileMenu->addAction( a );
622 return a;
623 }
624
625 KAction* KStdAction::print( QWidget* parent, const char* slot, KActionCollection* actionCollection)
626 {
627 #include "../xpm/fileprint.xpm"
628 KMainWindow* p = actionCollection->m_pMainWindow;
629 KAction* a = new KAction( i18n("Print..."), QIcon(QPixmap(fileprint)),Qt::CTRL+Qt::Key_P, parent, slot, actionCollection, "print", false, false);
630 if(p) p->fileMenu->addAction( a );
631 return a;
632 }
633
634 KAction* KStdAction::quit( QWidget* parent, const char* slot, KActionCollection* actionCollection)
635 {
636 KMainWindow* p = actionCollection->m_pMainWindow;
637 KAction* a = new KAction( i18n("Quit"), Qt::CTRL+Qt::Key_Q, parent, slot, actionCollection, "quit", false, false);
638 if(p) p->fileMenu->addAction( a );
639 return a;
640 }
641
642 KAction* KStdAction::cut( QWidget* parent, const char* slot, KActionCollection* actionCollection)
643 {
644 KMainWindow* p = actionCollection->m_pMainWindow;
645 KAction* a = new KAction( i18n("Cut"), Qt::CTRL+Qt::Key_X, parent, slot, actionCollection, "cut", false, false );
646 if(p) p->editMenu->addAction( a );
647 return a;
648 }
649
650 KAction* KStdAction::copy( QWidget* parent, const char* slot, KActionCollection* actionCollection)
651 {
652 KMainWindow* p = actionCollection->m_pMainWindow;
653 KAction* a = new KAction( i18n("Copy"), Qt::CTRL+Qt::Key_C, parent, slot, actionCollection, "copy", false, false );
654 if(p) p->editMenu->addAction( a );
655 return a;
656 }
657
658 KAction* KStdAction::paste( QWidget* parent, const char* slot, KActionCollection* actionCollection)
659 {
660 KMainWindow* p = actionCollection->m_pMainWindow;
661 KAction* a = new KAction( i18n("Paste"), Qt::CTRL+Qt::Key_V, parent, slot, actionCollection, "paste", false, false );
662 if(p) p->editMenu->addAction( a );
663 return a;
664 }
665
666 KAction* KStdAction::selectAll( QWidget* parent, const char* slot, KActionCollection* actionCollection)
667 {
668 KMainWindow* p = actionCollection->m_pMainWindow;
669 KAction* a = new KAction( i18n("Select All"), Qt::CTRL+Qt::Key_A, parent, slot, actionCollection, "selectall", false, false );
670 if(p) p->editMenu->addAction( a );
671 return a;
672 }
673
674 KToggleAction* KStdAction::showToolbar( QWidget* parent, const char* slot, KActionCollection* actionCollection)
675 {
676 KMainWindow* p = actionCollection->m_pMainWindow;
677 KToggleAction* a = new KToggleAction( i18n("Show Toolbar"), 0, parent, slot, actionCollection, "showtoolbar", false );
678 if(p) p->settingsMenu->addAction( a );
679 return a;
680 }
681
682 KToggleAction* KStdAction::showStatusbar( QWidget* parent, const char* slot, KActionCollection* actionCollection)
683 {
684 KMainWindow* p = actionCollection->m_pMainWindow;
685 KToggleAction* a = new KToggleAction( i18n("Show &Statusbar"), 0, parent, slot, actionCollection, "showstatusbar", false );
686 if(p) p->settingsMenu->addAction( a );
687 return a;
688 }
689
690 KAction* KStdAction::preferences( QWidget* parent, const char* slot, KActionCollection* actionCollection)
691 {
692 KMainWindow* p = actionCollection->m_pMainWindow;
693 KAction* a = new KAction( i18n("&Configure %1...").arg("KDiff3"), 0, parent, slot, actionCollection, "settings", false, false );
694 if(p) p->settingsMenu->addAction( a );
695 return a;
696 }
697 KAction* KStdAction::keyBindings( QWidget*, const char*, KActionCollection*)
698 {
699 return 0;
700 }
701
702 KAction* KStdAction::about( QWidget* parent, const char* slot, KActionCollection* actionCollection)
703 {
704 KMainWindow* p = actionCollection->m_pMainWindow;
705 KAction* a = new KAction( i18n("About")+" KDiff3", 0, parent, slot, actionCollection, "about_kdiff3", false, false );
706 if(p) p->helpMenu->addAction( a );
707 return a;
708 }
709
710 KAction* KStdAction::aboutQt( KActionCollection* actionCollection )
711 {
712 KMainWindow* p = actionCollection->m_pMainWindow;
713 KAction* a = new KAction( i18n("About")+" Qt", 0, qApp, SLOT(aboutQt()), actionCollection, "about_qt", false, false );
714 if(p) p->helpMenu->addAction( a );
715 return a;
716 }
717
718 KAction* KStdAction::help( QWidget* parent, const char* slot, KActionCollection* actionCollection)
719 {
720 KMainWindow* p = actionCollection->m_pMainWindow;
721 KAction* a = new KAction( i18n("Help"), Qt::Key_F1, parent, slot, actionCollection, "help", false, false );
722 if(p) p->helpMenu->addAction( a );
723 return a;
724 }
725 KAction* KStdAction::find( QWidget* parent, const char* slot, KActionCollection* actionCollection)
726 {
727 KMainWindow* p = actionCollection->m_pMainWindow;
728 KAction* a = new KAction( i18n("Find"), Qt::CTRL+Qt::Key_F, parent, slot, actionCollection, "find", false, false );
729 if(p) p->editMenu->addAction( a );
730 return a;
731 }
732
733 KAction* KStdAction::findNext( QWidget* parent, const char* slot, KActionCollection* actionCollection)
734 {
735 KMainWindow* p = actionCollection->m_pMainWindow;
736 KAction* a = new KAction( i18n("Find Next"), Qt::Key_F3, parent, slot, actionCollection, "findNext", false, false );
737 if(p) p->editMenu->addAction( a );
738 return a;
739 }
740
741
742
743
744 KFontChooser::KFontChooser( QWidget* pParent, const QString& /*name*/, bool, const QStringList&, bool, int )
745 : QWidget(pParent)
746 {
747 m_pParent = pParent;
748 QVBoxLayout* pLayout = new QVBoxLayout( this );
749 m_pSelectFont = new QPushButton(i18n("Select Font"), this );
750 connect(m_pSelectFont, SIGNAL(clicked()), this, SLOT(slotSelectFont()));
751 pLayout->addWidget(m_pSelectFont);
752
753 m_pLabel = new QLabel( "", this );
754 m_pLabel->setFont( m_font );
755 m_pLabel->setMinimumWidth(200);
756 m_pLabel->setText( "The quick brown fox jumps over the river\n"
757 "but the little red hen escapes with a shiver.\n"
758 ":-)");
759 pLayout->addWidget(m_pLabel);
760 }
761
762 QFont KFontChooser::font()
763 {
764 return m_font;//QFont("courier",10);
765 }
766
767 void KFontChooser::setFont( const QFont& font, bool )
768 {
769 m_font = font;
770 m_pLabel->setFont( m_font );
771 //update();
772 }
773
774 void KFontChooser::slotSelectFont()
775 {
776 for(;;)
777 {
778 bool bOk;
779 m_font = QFontDialog::getFont(&bOk, m_font );
780 m_pLabel->setFont( m_font );
781 QFontMetrics fm(m_font);
782
783 // Variable width font.
784 if ( fm.width('W')!=fm.width('i') )
785 {
786 int result = KMessageBox::warningYesNo(m_pParent, i18n(
787 "You selected a variable width font.\n\n"
788 "Because this program doesn't handle variable width fonts\n"
789 "correctly, you might experience problems while editing.\n\n"
790 "Do you want to continue or do you want to select another font."),
791 i18n("Incompatible font."),
792 i18n("Continue at my own risk"), i18n("Select another font"));
793 if (result==KMessageBox::Yes)
794 return;
795 }
796 else
797 return;
798 }
799 }
800
801
802 KColorButton::KColorButton(QWidget* parent)
803 : QPushButton(parent)
804 {
805 connect( this, SIGNAL(clicked()), this, SLOT(slotClicked()));
806 }
807
808 QColor KColorButton::color()
809 {
810 return m_color;
811 }
812
813 void KColorButton::setColor( const QColor& color )
814 {
815 m_color = color;
816 update();
817 }
818
819 void KColorButton::paintEvent( QPaintEvent* e )
820 {
821 QPushButton::paintEvent(e);
822 QPainter p(this);
823
824 int w = width();
825 int h = height();
826 p.fillRect( 10, 5, w-20, h-10, m_color );
827 p.drawRect( 10, 5, w-20, h-10 );
828 }
829
830 void KColorButton::slotClicked()
831 {
832 // Under Windows ChooseColor() should be used. (Nicer if few colors exist.)
833 QColor c = QColorDialog::getColor ( m_color, this );
834 if ( c.isValid() ) m_color = c;
835 update();
836 }
837
838 KPrinter::KPrinter()
839 {
840 }
841 QList<int> KPrinter::pageList()
842 {
843 QList<int> vl;
844 int to = toPage();
845 for(int i=fromPage(); i<=to; ++i)
846 {
847 vl.push_back(i);
848 }
849 return vl;
850 }
851 void KPrinter::setCurrentPage(int)
852 {
853 }
854 void KPrinter::setPageSelection(e_PageSelection)
855 {
856 }
857
858
859 QPixmap KIconLoader::loadIcon( const QString&, int )
860 {
861 return QPixmap();
862 }
863
864 KAboutData::KAboutData( const QString& /*name*/, const QString& appName, const QString& version,
865 const QString& description, int,
866 const QString& copyright, int, const QString& homepage, const QString& email)
867 {
868 s_copyright = copyright;
869 s_email = email;
870 s_appName = appName;
871 s_description = description;
872 s_version = version;
873 s_homepage = homepage;
874 }
875
876 KAboutData::KAboutData( const QString& /*name*/, const QString& /*appName*/, const QString& /*version*/ )
877 {
878 }
879
880 void KAboutData::addAuthor(const char* name, const char* task, const char* email, const char* weblink)
881 {
882 m_authorList.push_back( AboutDataEntry( name, task, email, weblink) );
883 }
884
885 void KAboutData::addCredit(const char* name, const char* task, const char* email, const char* weblink)
886 {
887 m_creditList.push_back( AboutDataEntry( name, task, email, weblink) );
888 }
889
890 /* Option structure: e.g.:
891 { "m", 0, 0 },
892 { "merge", I18N_NOOP("Automatically merge the input."), 0 },
893 { "o", 0, 0 },
894 { "output file", I18N_NOOP("Output file. Implies -m. E.g.: -o newfile.txt"), 0 },
895 { "+[File1]", I18N_NOOP("file1 to open (base)"), 0 },
896 { "+[File2]", I18N_NOOP("file2 to open"), 0 },
897 { "+[File3]", I18N_NOOP("file3 to open"), 0 },
898 */
899 ////////////////
900 static KCmdLineArgs s_cmdLineArgs;
901 static int s_argc;
902 static char** s_argv;
903 static KCmdLineOptions* s_pOptions;
904
905 static std::vector<QCStringList> s_vOption;
906 static std::vector<const char*> s_vArg;
907
908 KCmdLineArgs* KCmdLineArgs::parsedArgs() // static
909 {
910 return &s_cmdLineArgs;
911 }
912
913 void KCmdLineArgs::init( int argc, char**argv, KAboutData* pAboutData ) // static
914 {
915 s_argc = argc;
916 s_argv = argv;
917 s_pAboutData = pAboutData;
918 }
919
920 void KCmdLineArgs::addCmdLineOptions( KCmdLineOptions* options ) // static
921 {
922 s_pOptions = options;
923 }
924
925 int KCmdLineArgs::count()
926 {
927 return s_vArg.size();
928 }
929
930 QString KCmdLineArgs::arg(int idx)
931 {
932 return QString::fromLocal8Bit( s_vArg[idx] );
933 }
934
935 void KCmdLineArgs::clear()
936 {
937 }
938
939 QString KCmdLineArgs::getOption( const QString& s )
940 {
941 // Find the option
942 int j=0;
943 for( j=0; j<(int)s_vOption.size(); ++j )
944 {
945 const char* optName = s_pOptions[j].name;
946 const char* pos = strchr( optName,' ' );
947 int len = pos==0 ? strlen( optName ) : pos - optName;
948
949 if( s == QString::fromLatin1( optName, len ) )
950 {
951 return s_vOption[j].isEmpty() ? QString() : s_vOption[j].last();
952 }
953 }
954 assert(false);
955 return QString();
956 }
957
958 QCStringList KCmdLineArgs::getOptionList( const QString& s )
959 {
960 // Find the option
961 int j=0;
962 for( j=0; j<(int)s_vOption.size(); ++j )
963 {
964 const char* optName = s_pOptions[j].name;
965 const char* pos = strchr( optName,' ' );
966 int len = pos==0 ? strlen( optName ) : pos - optName;
967
968 if( s == QString::fromLatin1( optName, len) )
969 {
970 return s_vOption[j];
971 }
972 }
973
974 assert(false);
975 return QCStringList();
976 }
977
978 bool KCmdLineArgs::isSet(const QString& s)
979 {
980 // Find the option
981 int j=0;
982 for( j=0; j<(int)s_vOption.size(); ++j )
983 {
984 const char* optName = s_pOptions[j].name;
985 if( s == QString( optName ) )
986 {
987 return ! s_vOption[j].isEmpty();
988 }
989 }
990 assert(false);
991 return false;
992 }
993
994 ///////////////////
995 KApplication* kapp;
996
997 KApplication::KApplication()
998 : QApplication( s_argc,s_argv )
999 {
1000 kapp = this;
1001
1002 int nofOptions=0;
1003 int nofArgs=0;
1004 int i=0;
1005 while( s_pOptions[i].name != 0 )
1006 {
1007 if ( s_pOptions[i].name[0]=='[' )
1008 nofArgs++;
1009 else
1010 nofOptions++;
1011
1012 ++i;
1013 }
1014
1015 // First find the option "-config" or "--config" to allow loading of options
1016 QString configFileName;
1017 for( i=1; i<s_argc-1; ++i )
1018 {
1019 QString arg = s_argv[i];
1020 if ( arg == "-config" || arg == "--config" )
1021 {
1022 configFileName = s_argv[i+1];
1023 }
1024 }
1025 m_config.readConfigFile(configFileName);
1026
1027 QStringList ignorableCmdLineOptionsList = m_config.readListEntry("IgnorableCmdLineOptions", QStringList("-u;-query;-html;-abort"), '|');
1028 QString ignorableCmdLineOptions;
1029 if ( !ignorableCmdLineOptionsList.isEmpty() )
1030 ignorableCmdLineOptions = ignorableCmdLineOptionsList.front() + ";";
1031
1032 s_vOption.resize(nofOptions);
1033
1034 for( i=1; i<s_argc; ++i )
1035 {
1036 if ( s_argv[i][0]=='-' ) // An option
1037 {
1038 if ( ignorableCmdLineOptions.contains(QString(s_argv[i])+";") )
1039 continue;
1040 // Find the option
1041 int j=0;
1042 for( j=0; j<nofOptions; ++j )
1043 {
1044 const char* optName = s_pOptions[j].name;
1045 const char* pos = strchr( optName,' ' );
1046 int len = pos==0 ? strlen( optName ) : pos - optName;
1047 int len2 = strlen(s_argv[i]);
1048
1049 if( len>0 && ( s_argv[i][1]=='-' && len2-2==len && memcmp( &s_argv[i][2], optName, len )==0 ||
1050 len2-1==len && memcmp( &s_argv[i][1], optName, len )==0 ))
1051 {
1052 if (s_pOptions[j].description == 0) // alias, because without description.
1053 {
1054 ++j;
1055 optName = s_pOptions[j].name;
1056 pos = strchr( optName,' ' );
1057 }
1058 if (pos!=0){ ++i; s_vOption[j].append(s_argv[i]); } //use param
1059 else { s_vOption[j].append("1"); } //set state
1060 break;
1061 }
1062 }
1063 if (j==nofOptions)
1064 {
1065 QString s;
1066 s = QString("Unknown option: ") + QString(s_argv[i]) + "\n";
1067 s += "If KDiff3 should ignore this option, run KDiff3 normally and edit\n"
1068 "the \"Command line options to ignore\" in the \"Integration Settings\".\n\n";
1069
1070 s += "KDiff3-Usage when starting via commandline: \n";
1071 s += "- Comparing 2 files:\t\tkdiff3 file1 file2\n";
1072 s += "- Merging 2 files: \t\tkdiff3 file1 file2 -o outputfile\n";
1073 s += "- Comparing 3 files:\t\tkdiff3 file1 file2 file3\n";
1074 s += "- Merging 3 files: \t\tkdiff3 file1 file2 file3 -o outputfile\n";
1075 s += " Note that file1 will be treated as base of file2 and file3.\n";
1076 s += "\n";
1077 s += "If you start without arguments, then a dialog will appear\n";
1078 s += "where you can select your files via a filebrowser.\n";
1079 s += "\n";
1080
1081 s += "Options:\n";
1082
1083 j=0;
1084 int pos=s.length();
1085 for( j=0; j<nofOptions; ++j )
1086 {
1087 if ( s_pOptions[j].description!=0 )
1088 {
1089 if (s_pOptions[j].name[0]!='+')
1090 {
1091 s += "-";
1092 if ( strlen(s_pOptions[j].name)>1 ) s += "-";
1093 }
1094 s += s_pOptions[j].name;
1095 s += QString().fill(' ', minMaxLimiter( 20 - ((int)s.length()-pos), 3, 20 ) );
1096 s += s_pOptions[j].description;
1097 s +="\n";
1098 pos=s.length();
1099 }
1100 else
1101 {
1102 s += "-";
1103 if ( strlen(s_pOptions[j].name)>1 ) s += "-";
1104 s += s_pOptions[j].name;
1105 s += ", ";
1106 }
1107 }
1108
1109 s += "\n"+i18n("For more documentation, see the help-menu or the subdirectory doc.")+"\n";
1110 #ifdef _WIN32
1111 // A windows program has no console
1112 if ( 0==QMessageBox::information(0, i18n("KDiff3-Usage"), s, i18n("Ignore"),i18n("Exit") ) )
1113 continue;
1114 #else
1115 std::cerr << s.toLatin1().constData() << std::endl;
1116 #endif
1117
1118 ::exit(-1);
1119 }
1120 }
1121 else
1122 s_vArg.push_back( s_argv[i] );
1123 }
1124 }
1125
1126 KConfig* KApplication::config()
1127 {
1128 return &m_config;
1129 }
1130
1131 bool KApplication::isRestored()
1132 {
1133 return false;
1134 }
1135
1136 KApplication* KApplication::kApplication()
1137 {
1138 return kapp;
1139 }
1140
1141 KIconLoader* KApplication::iconLoader()
1142 {
1143 return &m_iconLoader;
1144 }
1145
1146
1147 namespace KIO
1148 {
1149 SimpleJob* mkdir( KURL ){return 0;}
1150 SimpleJob* rmdir( KURL ){return 0;}
1151 SimpleJob* file_delete( KURL, bool ){return 0;}
1152 FileCopyJob* file_move( KURL, KURL, int, bool, bool, bool ) {return 0;}
1153 FileCopyJob* file_copy( KURL, KURL, int, bool, bool, bool ) {return 0;}
1154 CopyJob* link( KURL, KURL, bool ) {return 0;}
1155 ListJob* listRecursive( KURL, bool, bool ){return 0;}
1156 ListJob* listDir( KURL, bool, bool ){return 0;}
1157 StatJob* stat( KURL, bool, int, bool ){return 0;}
1158 TransferJob* get( KURL, bool, bool ){return (TransferJob*)0;}
1159 TransferJob* put( KURL, int, bool, bool, bool ){return (TransferJob*)0;}
1160 };
1161
1162 KActionCollection* KParts::Part::actionCollection()
1163 {
1164 return 0;
1165 }
1166
1167 KApplication* KParts::Part::instance()
1168 {
1169 return kapp;
1170 }
1171
1172
1173 KLibLoader* KLibLoader::self()
1174 {
1175 static KLibLoader ll;
1176 return &ll;
1177 }
1178
1179 extern "C" void* init_libkdiff3part();
1180 KLibFactory* KLibLoader::factory(QString const&)
1181 {
1182 return (KLibFactory*) init_libkdiff3part();
1183 }
1184
1185 QObject* KLibFactory::create(QObject* pParent, const QString& name, const QString& classname )
1186 {
1187 KParts::Factory* f = dynamic_cast<KParts::Factory*>(this);
1188 if (f!=0)
1189 return f->createPartObject( (QWidget*)pParent, name.toAscii(),
1190 pParent, name.toAscii(),
1191 classname.toAscii(), QStringList() );
1192 else
1193 return 0;
1194 }
1195
1196
1197
1198
1199 #include "kreplacements.moc"