annotate kdiff3/src-QT4/kreplacements/kreplacements.cpp @ 113:7bca1f1340f6 tip

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