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