comparison kdiff3/src/kreplacements/kreplacements.cpp @ 8:86d21651c8db

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