cervisiapart.cpp 50.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qtextstream.h>
#include <kaboutdata.h>
#include <kaction.h>
#include <kapp.h>
#include <kfiledialog.h>
#include <kinstance.h>
#include <klocale.h>
#include <kstdaction.h>
#include <kxmlgui.h>

#include "logdlg.h"
#include "loglist.h"
#include "diffdlg.h"
#include "resolvedlg.h"
#include "annotatedlg.h"
#include "commitdlg.h"
#include "updatedlg.h"
#include "checkoutdlg.h"
#include "tagdlg.h"
#include "mergedlg.h"
#include "historydlg.h"
#include "updateview.h"
#include "protocolview.h"
#include "cvsprogressdlg.h"
#include "repositorydlg.h"
#include "settingsdlg.h"
#include "changelogdlg.h"
#include "misc.h"

#include "cervisiapart.h"
#include "version.h"
#include "cervisiapart.moc"

#define COMMIT_SPLIT_CHAR '\r'

extern "C"
{
    /**
     * This function is the 'main' function of this part.  It takes
     * the form 'void *init_lib<library name>()  It always returns a
     * new factory object
     */
    void *init_libcervisia()
    {
        return new CervisiaFactory;
    }
};

KInstance *CervisiaFactory::s_instance = 0L;

CervisiaFactory::CervisiaFactory()
{
  // Nothing to do
}

CervisiaFactory::~CervisiaFactory()
{
    if ( s_instance ) {
      delete s_instance->aboutData();
      delete s_instance;
    }

    s_instance = 0;
}

68 69 70 71
KParts::Part *CervisiaFactory::createPartObject( QWidget *parentWidget, const char *widgetName,
                                                 QObject* parent, const char* name,
				                 const char * /*classname*/,
				                 const QStringList & /*args*/ )
72
{
73
    KParts::Part *obj = new CervisiaPart( parentWidget, widgetName, parent, name );
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    return obj;
}

KInstance *CervisiaFactory::instance()
{
    if ( !s_instance )
        s_instance = new KInstance( aboutData() );
    return s_instance;
}

KAboutData *CervisiaFactory::aboutData()
{
    return new KAboutData( "cervisia", I18N_NOOP("Cervisia"),
			   CERVISIA_VERSION,
			   I18N_NOOP("A CVS frontend"),
			   KAboutData::License_QPL,
			   I18N_NOOP("(c) 1999-2001 Bernd Gehrmann"));
}

93 94
CervisiaPart::CervisiaPart( QWidget *parentWidget, const char *widgetName,
                            QObject *parent, const char *name )
95 96 97 98 99 100 101 102 103
    : KParts::ReadOnlyPart( parent, name )
{
    hasRunningJob = false;
    setInstance( CervisiaFactory::instance() );
    new CervisiaBrowserExtension( this );

    // Create UI
    KConfig *conf = config();
    conf->setGroup("LookAndFeel");
Laurent Montel's avatar
Laurent Montel committed
104 105
    bool splitHorz = conf->readBoolEntry("SplitHorizontally",true);

106 107
    splitter = new QSplitter(splitHorz? QSplitter::Vertical : QSplitter::Horizontal, 
                             parentWidget, widgetName);
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

    update = new UpdateView(splitter);
    update->setFocusPolicy( QWidget::StrongFocus );
    update->setFocus();

    connect( update, SIGNAL(contextMenu()),
             this, SLOT(popupRequested()) );
    connect( update, SIGNAL(fileOpened(QString)),
             this, SLOT(openFile(QString)) );

    protocol = new ProtocolView(splitter);
    protocol->setFocusPolicy( QWidget::StrongFocus );

    setWidget(splitter);
    setupActions();
    connect( update, SIGNAL( selectionChanged() ), this, SLOT( updateActions() ) );

    setXMLFile( "cervisiaui.rc" );
}

CervisiaPart::~CervisiaPart()
{

}

KConfig *CervisiaPart::config()
{
    return CervisiaFactory::instance()->config();
}

bool CervisiaPart::openURL( const KURL &u )
{
    slotOpenSandbox( u );
    return true;
}

void CervisiaPart::setupActions()
{
    KAction *action;
    QString hint;

    actionCollection()->setHighlightingEnabled(true);

    //
    // File Menu
    //
    action = new KAction( i18n("O&pen Sandbox..."), "fileopen", 0,
Laurent Montel's avatar
Laurent Montel committed
155
			  this, SLOT( slotOpenSandbox() ),
156 157 158 159 160 161 162 163 164 165 166 167 168
			  actionCollection(), "file_open" );
    hint = i18n("Opens a CVS working directory in the main window");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Insert ChangeLog Entry..."), 0,
			  this, SLOT( slotChangeLog() ),
			  actionCollection(), "insert_changelog_entry" );
    hint = i18n("Inserts a new intro into the file ChangeLog in the toplevel directory");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Update"), "down", CTRL+Key_U,
Laurent Montel's avatar
Laurent Montel committed
169
			  this, SLOT( slotUpdate() ),
170 171 172 173 174 175
			  actionCollection(), "file_update" );
    hint = i18n("Updates (cvs update) the selected files and directories");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Status"), Key_F5,
Laurent Montel's avatar
Laurent Montel committed
176
			  this, SLOT( slotStatus() ),
177 178 179 180 181 182
			  actionCollection(), "file_status" );
    hint = i18n("Updates the status (cvs -n update) of the selected files and directories");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Edit"), 0,
Laurent Montel's avatar
Laurent Montel committed
183
			  this, SLOT( slotOpen() ),
184 185 186 187 188 189
			  actionCollection(), "file_edit" );
    hint = i18n("Opens the marked file for editing");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("Reso&lve"), 0,
Laurent Montel's avatar
Laurent Montel committed
190
			  this, SLOT( slotResolve() ),
191 192 193 194 195 196
			  actionCollection(), "file_resolve" );
    hint = i18n("Opens the resolve dialog with the selected file");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Commit..."), "up", Key_NumberSign,
Laurent Montel's avatar
Laurent Montel committed
197
			  this, SLOT( slotCommit() ),
198 199 200 201 202 203
			  actionCollection(), "file_commit" );
    hint = i18n("Commits the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Add To Repository..."), Key_Plus,
Laurent Montel's avatar
Laurent Montel committed
204
			  this, SLOT( slotAdd() ),
205 206 207 208 209 210
			  actionCollection(), "file_add" );
    hint = i18n("Adds (cvs add) the selected files to the repository");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("Add &Binary..."), 0,
Laurent Montel's avatar
Laurent Montel committed
211
			  this, SLOT( slotAddBinary() ),
212 213 214 215 216 217
			  actionCollection(), "file_add_binary" );
    hint = i18n("Adds (cvs -kb add) the selected files as binaries to the repository");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Remove From Repository..."), Key_Minus,
Laurent Montel's avatar
Laurent Montel committed
218
			  this, SLOT( slotRemove() ),
219 220 221 222 223 224
			  actionCollection(), "file_remove" );
    hint = i18n("Removes (cvs remove) the selected files from the repository");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("Rever&t"), 0,
Laurent Montel's avatar
Laurent Montel committed
225
			  this, SLOT( slotRevert() ),
226 227 228 229 230 231 232 233 234
			  actionCollection(), "file_revert_local_changes" );
    hint = i18n("Reverts (cvs update -C) the selected files (only cvs 1.11)");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    //
    // View Menu
    //
    action = new KAction( i18n("Stop"), "stop", Key_Escape,
Laurent Montel's avatar
Laurent Montel committed
235
			  protocol, SLOT(cancelJob()),
236 237 238 239
			  actionCollection(), "stop_job" );
    action->setEnabled( false );

    action = new KAction( i18n("Browse &Log..."), CTRL+Key_L,
Laurent Montel's avatar
Laurent Montel committed
240
			  this, SLOT(slotBrowseLog()),
241 242 243 244 245 246 247
			  actionCollection(), "view_log" );
    hint = i18n("Shows the revision tree of the selected file");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

#if 0
    action = new KAction( i18n("Browse Multi-File Log..."), 0,
Laurent Montel's avatar
Laurent Montel committed
248
			  this, SLOT(slotBrowseMultiLog()),
249 250 251 252 253 254 255 256 257 258
			  actionCollection() );
#endif
    action = new KAction( i18n("&Annotate..."), CTRL+Key_A,
			  this, SLOT(slotAnnotate()),
			  actionCollection(), "view_annotate" );
    hint = i18n("Shows a blame-annotated view of the selected file");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Difference To Repository..."), CTRL+Key_D,
Laurent Montel's avatar
Laurent Montel committed
259
			  this, SLOT(slotDiff()),
260 261 262 263 264 265
			  actionCollection(), "view_diff" );
    hint = i18n("Shows the differences of the selected file to the BASE version");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("Last &Change..."), 0,
Laurent Montel's avatar
Laurent Montel committed
266
			  this, SLOT(slotLastChange()),
267 268 269 270 271 272
			  actionCollection(), "view_last_change" );
    hint = i18n("Shows the differences between the last two revisions of the selected file");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&History..."), 0,
Laurent Montel's avatar
Laurent Montel committed
273
			  this, SLOT(slotHistory()),
274 275 276 277 278 279
			  actionCollection(), "view_history" );
    hint = i18n("Shows the CVS history as reported by the server");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Unfold File Tree"), 0,
Laurent Montel's avatar
Laurent Montel committed
280
			  update, SLOT(unfoldTree()),
281 282 283 284 285 286
			  actionCollection(), "view_unfold_tree" );
    hint = i18n("Opens all branches of the file tree");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Fold File Tree"), 0,
Laurent Montel's avatar
Laurent Montel committed
287
			  update, SLOT(foldTree()),
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
			  actionCollection(), "view_fold_tree" );
    hint = i18n("Closes all branches of the file tree");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    //
    // Advanced Menu
    //
    action = new KAction( i18n("&Tag/Branch..."), 0,
			  this, SLOT(slotCreateTag()),
			  actionCollection(), "create_tag" );
    hint = i18n("Creates a tag or branch for the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Delete Tag..."), 0,
			  this, SLOT(slotDeleteTag()),
			  actionCollection(), "delete_tag" );
    hint = i18n("Deletes a tag from the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Update To Tag/Date..."), 0,
			  this, SLOT(slotUpdateToTag()),
			  actionCollection(), "update_to_tag" );
    hint = i18n("Updates the selected files to a given tag, branch or date");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("Update To &HEAD"), 0,
			  this, SLOT(slotUpdateToHead()),
			  actionCollection(), "update_to_head" );
    hint = i18n("Updates the selected files to the HEAD revision");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Merge..."), 0,
			  this, SLOT(slotMerge()),
			  actionCollection(), "merge" );
    hint = i18n("Merges a branch or a set of modifications into the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Add Watch..."), 0,
			  this, SLOT(slotAddWatch()),
			  actionCollection(), "add_watch" );
    hint = i18n("Adds a watch for the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Remove Watch..."), 0,
			  this, SLOT(slotRemoveWatch()),
			  actionCollection(), "remove_watch" );
    hint = i18n("Removes a watch from the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("Show &Watchers"), 0,
			  this, SLOT(slotShowWatchers()),
			  actionCollection(), "show_watchers" );
    hint = i18n("Shows the watchers of the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("Ed&it Files"), 0,
			  this, SLOT(slotEdit()),
			  actionCollection(), "edit_files" );
    hint = i18n("Edits (cvs edit) the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("U&nedit Files"), 0,
			  this, SLOT(slotUnedit()),
			  actionCollection(), "unedit_files" );
    hint = i18n("Unedits (cvs unedit) the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("Show &Editors"), 0,
			  this, SLOT(slotShowEditors()),
			  actionCollection(), "show_editors" );
    hint = i18n("Shows the editors of the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );
Laurent Montel's avatar
Laurent Montel committed
372

373 374 375 376 377 378 379 380 381 382 383 384 385
    action = new KAction( i18n("&Lock Files"), 0,
			  this, SLOT(slotLock()),
			  actionCollection(), "lock_files" );
    hint = i18n("Locks the selected files, so that others can't modify them");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("Unl&ock Files"), 0,
			  this, SLOT(slotUnlock()),
			  actionCollection(), "unlock_files" );
    hint = i18n("Unlocks the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );
Laurent Montel's avatar
Laurent Montel committed
386

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
    action = new KAction( i18n("Create &Patch Against Repository"), 0,
			  this, SLOT(slotMakePatch()),
			  actionCollection(), "make_patch" );
    hint = i18n("Creates a patch from the modifications in your sandbox");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    //
    // Repository Menu
    //
    action = new KAction( i18n("&Checkout..."), 0,
			  this, SLOT(slotCheckout()),
			  actionCollection(), "repository_checkout" );
    hint = i18n("Allows you to checkout a module from a repository");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Import..."), 0,
			  this, SLOT(slotImport()),
			  actionCollection(), "repository_import" );
    hint = i18n("Allows you to import a module into a repository");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("&Repositories..."), 0,
			  this, SLOT(slotRepositories()),
			  actionCollection(), "show_repositories" );
    hint = i18n("Configures a list of repositories you regularly use");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    //
    // Settings menu
    //
    action = new KToggleAction( i18n("Hide All &Files"), 0,
				this, SLOT(slotHideFiles()),
				actionCollection(), "settings_hide_files" );
    hint = i18n("Determines whether only directories are shown");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KToggleAction( i18n("Hide Up-&To-Date Files"), 0,
Laurent Montel's avatar
Laurent Montel committed
429
				this, SLOT(slotHideUpToDate()),
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
				actionCollection(), "settings_hide_uptodate" );
    hint = i18n("Determines whether up-to-date files are hidden");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KToggleAction( i18n("Hide Removed Files"), 0,
				this, SLOT(slotHideRemoved()),
				actionCollection(), "settings_hide_removed" );
    hint = i18n("Determines whether removed files are hidden");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KToggleAction( i18n("Create &Directories On Update"), 0,
				this, SLOT(slotCreateDirs()),
				actionCollection(), "settings_create_dirs" );
    hint = i18n("Determines whether updates create directories");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KToggleAction( i18n("&Prune Empty Directories On Update"), 0,
				this, SLOT(slotPruneDirs()),
				actionCollection(), "settings_prune_dirs" );
    hint = i18n("Determines whether updates remove empty directories");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KToggleAction( i18n("&Update Recursively"), 0,
				this, SLOT(slotUpdateRecursive()),
				actionCollection(), "settings_update_recursively" );
    hint = i18n("Determines whether updates are recursive");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KToggleAction( i18n("C&ommit And Remove Recursively"), 0,
				this, SLOT(slotCommitRecursive()),
				actionCollection(), "settings_commit_recursively" );
    hint = i18n("Determines whether commits and removes are recursive");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KToggleAction( i18n("Do cvs &edit Automatically When Necessary"), 0,
				this, SLOT(slotDoCVSEdit()),
				actionCollection(), "settings_do_cvs_edit" );
    hint = i18n("Determines whether automatical cvs edit is active");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = new KAction( i18n("Configure Cervisia..."), "configure", 0,
			  this, SLOT(slotConfigure()),
			  actionCollection(), "configure_cervisia" );
    hint = i18n("Allows you to configure the Cervisia KPart");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    //
    // Help Menu
    //
    action = KStdAction::help( this, SLOT(slotHelp()),
			       actionCollection() );

    action = new KAction( i18n("CVS &Manual"), 0,
			  this, SLOT(slotCVSInfo()),
			  actionCollection(), "help_cvs_manual" );
    hint = i18n("Opens the help browser with the CVS documentation");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

Laurent Montel's avatar
Laurent Montel committed
497 498
    //action = KStdAction::aboutApp( this, SLOT(aboutCervisia()),
    //			   actionCollection(), "help_about_cervisia" );
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
}

void CervisiaPart::popupRequested()
{
    QPopupMenu *pop = static_cast<QPopupMenu *>( factory()->container("context_popup", this) );
    if (!pop) {
	qWarning( "CervisiaPart: Missing XML definition for context_popup\n" );
	return;
    }
    pop->exec(QCursor::pos());
}

void CervisiaPart::updateActions()
{
    bool single = update->hasSingleSelection();

    actionCollection()->action( "file_edit" )->setEnabled( single );
    actionCollection()->action( "file_resolve" )->setEnabled( single );
    actionCollection()->action( "view_log" )->setEnabled( single );
    actionCollection()->action( "view_annotate" )->setEnabled( single );
    actionCollection()->action( "view_diff" )->setEnabled( single );
    actionCollection()->action( "view_last_change" )->setEnabled( single );

    //    bool nojob = !( actionCollection()->action( "stop_job" )->isEnabled() );
    bool nojob = !hasRunningJob;

    actionCollection()->action( "file_update" )->setEnabled( nojob );
    actionCollection()->action( "file_status" )->setEnabled( nojob );
    actionCollection()->action( "file_commit" )->setEnabled( nojob );
    actionCollection()->action( "file_add" )->setEnabled( nojob );
    actionCollection()->action( "file_add_binary" )->setEnabled( nojob );
    actionCollection()->action( "file_remove" )->setEnabled( nojob );
    actionCollection()->action( "file_revert_local_changes" )->setEnabled( nojob );

    actionCollection()->action( "create_tag" )->setEnabled( nojob );
    actionCollection()->action( "delete_tag" )->setEnabled( nojob );
    actionCollection()->action( "update_to_tag" )->setEnabled( nojob );
    actionCollection()->action( "update_to_head" )->setEnabled( nojob );
    actionCollection()->action( "merge" )->setEnabled( nojob );
    actionCollection()->action( "add_watch" )->setEnabled( nojob );
    actionCollection()->action( "remove_watch" )->setEnabled( nojob );
    actionCollection()->action( "show_watchers" )->setEnabled( nojob );
    actionCollection()->action( "edit_files" )->setEnabled( nojob );
    actionCollection()->action( "unedit_files" )->setEnabled( nojob );
    actionCollection()->action( "show_editors" )->setEnabled( nojob );
    actionCollection()->action( "lock_files" )->setEnabled( nojob );
    actionCollection()->action( "unlock_files" )->setEnabled( nojob );

    actionCollection()->action( "repository_checkout" )->setEnabled( nojob );
    actionCollection()->action( "repository_import" )->setEnabled( nojob );
}


void CervisiaPart::aboutCervisia()
{
    QString aboutstr(i18n("Cervisia %1\n"
                          "(Using KDE %2)\n"
                          "\n"
                          "Copyright (C) 1999-2001\n"
                          "Bernd Gehrmann <bernd@physik.hu-berlin.de>\n"
                          "\n"
                          "This program may be distributed under the terms of the Q Public\n"
                          "License as defined by Trolltech AS of Norway and appearing in the\n"
                          "file LICENSE.QPL included in the packaging of this file.\n\n"
                          "This program is distributed in the hope that it will be useful,\n"
                          "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
                          "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."));
Laurent Montel's avatar
Laurent Montel committed
566
    QMessageBox::about(0, i18n("About Cervisia"),
567 568 569 570 571 572 573
		       aboutstr.arg(CERVISIA_VERSION).arg(KDE_VERSION_STRING));
}


void CervisiaPart::slotOpenSandbox()
{
    QString dirname = KFileDialog::getExistingDirectory(QDir::homeDirPath(), widget(),
Laurent Montel's avatar
Laurent Montel committed
574
                                                        i18n("Open Sandbox"));
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
    if (dirname.isEmpty())
        return;

    openSandbox(dirname);
}


void CervisiaPart::slotOpenSandbox( const KURL &url )
{
    openSandbox( url.path() );
}

void CervisiaPart::slotChangeLog()
{
    // Modal dialog
    ChangeLogDialog *l = new ChangeLogDialog();
    if (l->readFile(sandbox + "/ChangeLog"))
        {
            if (l->exec())
                changelogstr = l->message();
        }
Laurent Montel's avatar
Laurent Montel committed
596

597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
    delete l;
}


void CervisiaPart::slotOpen()
{
    QStringList filenames = update->fileSelection();
    if (filenames.isEmpty())
        return;
    openFiles(filenames);
}


void CervisiaPart::openFile(QString filename)
{
    QStringList files;
    files << filename;
    openFiles(files);
}


void CervisiaPart::openFiles(const QStringList &filenames)
{
    // First check the cvs edit stuff
    if (opt_doCVSEdit)
        {
            CvsProgressDialog l("Edit", widget() );
            l.setCaption("CVS Edit");
            QString cmdline = cvsClient(repository) + " edit ";

            bool doit = false;
            for ( QStringList::ConstIterator it = filenames.begin();
                  it != filenames.end(); ++it )
                {
                    if (!QFileInfo(*it).isWritable())
                        {
                            doit = true;
                            break;
                        }
Laurent Montel's avatar
Laurent Montel committed
636

637 638 639
                    cmdline += " ";
                    cmdline += KShellProcess::quote(*it);
                }
Laurent Montel's avatar
Laurent Montel committed
640

641 642 643 644
            if (doit)
                if (!l.execCommand(sandbox, repository, cmdline, "edit"))
                    return;
        }
Laurent Montel's avatar
Laurent Montel committed
645

646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
    // Now open the files by starting a new instance of kwrite...
    KConfig *conf = config();
    conf->setGroup("Communication");
    KShellProcess proc("/bin/sh");
    proc << conf->readEntry("Editor", "kwrite");

    for ( QStringList::ConstIterator it = filenames.begin();
          it != filenames.end(); ++it )
        proc << KShellProcess::quote(*it);
    proc.start(KProcess::DontCare);
}


void CervisiaPart::slotResolve()
{
    QString filename;
    update->getSingleSelection(&filename);
    if (filename.isEmpty())
        return;

    // Non-modal dialog
    ResolveDialog *l = new ResolveDialog();
    if (l->parseFile(filename))
        l->show();
    else
        delete l;
}


void CervisiaPart::slotUpdate()
{
    updateOrStatus(false, "");
}


void CervisiaPart::slotStatus()
{
    updateOrStatus(true, "");
}


void CervisiaPart::slotUpdateToTag()
{
    UpdateDialog *l = new UpdateDialog(sandbox, repository, widget() );
Laurent Montel's avatar
Laurent Montel committed
690

691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
    if (l->exec())
        {
            QString tagopt;
            if (l->byTag())
                {
                    tagopt = "-r ";
                    tagopt += l->tag();
                }
            else
                {
                    tagopt = "-D ";
                    tagopt += KShellProcess::quote(l->date());
                }
            tagopt += " ";
            updateOrStatus(false, tagopt);
        }
    delete l;
}


void CervisiaPart::slotUpdateToHead()
{
    updateOrStatus(false, "-A ");
}


void CervisiaPart::slotRevert()
{
    updateOrStatus(false, "-C ");
}


void CervisiaPart::slotMerge()
{
    MergeDialog *l = new MergeDialog(sandbox, repository, widget() );

    if (l->exec())
        {
            QString tagopt;
            if (l->byBranch())
                {
                    tagopt = "-j ";
                    tagopt += l->branch();
                }
            else
                {
                    tagopt = "-j ";
                    tagopt += l->tag1();
                    tagopt += " -j ";
                    tagopt += l->tag2();
                }
            tagopt += " ";
            updateOrStatus(false, tagopt);
        }
    delete l;
}


void CervisiaPart::slotCommit()
{
    commitOrAddOrRemove(CommitDialog::Commit);
}


void CervisiaPart::slotAdd()
{
    commitOrAddOrRemove(CommitDialog::Add);
}


void CervisiaPart::slotAddBinary()
{
    commitOrAddOrRemove(CommitDialog::AddBinary);
}


void CervisiaPart::slotRemove()
{
    commitOrAddOrRemove(CommitDialog::Remove);
}


void CervisiaPart::updateOrStatus(bool noact, const QString &extraopt)
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;
Laurent Montel's avatar
Laurent Montel committed
778

779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
    update->prepareJob(opt_updateRecursive,
                       noact? UpdateView::UpdateNoAct : UpdateView::Update);

    QString cmdline;
    if (noact)
        cmdline = cvsClient(repository) + " -n update ";
    else
        cmdline = cvsClient(repository) + " update ";
    if (opt_updateRecursive)
        cmdline += "-R ";
    else
        cmdline += "-l ";
    if (opt_createDirs)
        cmdline += "-d ";
    if (opt_pruneDirs)
        cmdline += "-P ";
    cmdline += extraopt;
    cmdline += joinLine(list);
    cmdline += " 2>&1";
Laurent Montel's avatar
Laurent Montel committed
798

799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
    if (protocol->startJob(sandbox, repository, cmdline))
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(receivedLine(QString)), update, SLOT(processUpdateLine(QString)) );
            connect( protocol, SIGNAL(jobFinished(bool)), update, SLOT(finishJob(bool)) );
            connect( protocol, SIGNAL(jobFinished(bool)), this, SLOT(slotJobFinished(bool)) );
        }
}


void CervisiaPart::commitOrAddOrRemove(CommitDialog::ActionType action)
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;
Laurent Montel's avatar
Laurent Montel committed
814

815 816 817 818 819 820 821 822
    // modal dialog
    CommitDialog *l = new CommitDialog(action, widget());
    if (action == CommitDialog::Commit)
    {
        l->setLogMessage(changelogstr);
        l->setLogHistory(sandbox, repository, recentCommits);
    }
    l->setFileList(list);
Laurent Montel's avatar
Laurent Montel committed
823

824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
    if (l->exec())
    {
        QString cmdline;
        switch (action)
        {
            case CommitDialog::Commit:
            {
                QString msg = l->logMessage();
                if( !recentCommits.contains( msg ) )
                {
                    recentCommits.prepend( msg );
                    while (recentCommits.count() > 50)
                        recentCommits.remove( recentCommits.last() );

                    KConfig* conf = config();
                    conf->setGroup( "CommitLogs" );
                    conf->writeEntry( sandbox, recentCommits, COMMIT_SPLIT_CHAR );
                }

                update->prepareJob(opt_commitRecursive, UpdateView::Commit);
                cmdline = cvsClient(repository) + " commit ";
                if (opt_commitRecursive)
                    cmdline += "-R ";
                else
                    cmdline += "-l ";
                cmdline += "-m ";
                cmdline += KShellProcess::quote(l->logMessage());
                cmdline += " ";
            }
            break;

            case CommitDialog::Add:
                update->prepareJob(false, UpdateView::Add);
                cmdline = cvsClient(repository) + " add ";
            break;

            case CommitDialog::AddBinary:
                update->prepareJob(false, UpdateView::Add);
                cmdline = cvsClient(repository) + " add -kb ";
            break;

            case CommitDialog::Remove:
                update->prepareJob(opt_commitRecursive, UpdateView::Remove);
                cmdline = cvsClient(repository) + " remove -f ";
                if (opt_commitRecursive)
                    cmdline += "-R ";
                else
                    cmdline += "-l ";
            break;
        }

        cmdline += joinLine(list);
        cmdline += " 2>&1";
Laurent Montel's avatar
Laurent Montel committed
877

878 879 880 881 882 883 884 885 886
        if (protocol->startJob(sandbox, repository, cmdline))
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool)),
                     update, SLOT(finishJob(bool)) );
            connect( protocol, SIGNAL(jobFinished(bool)),
                     this, SLOT(slotJobFinished(bool)) );
        }
    }
Laurent Montel's avatar
Laurent Montel committed
887

888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
    delete l;
}

void CervisiaPart::slotBrowseLog()
{
    QString filename;
    update->getSingleSelection(&filename);
    if (filename.isEmpty())
        return;

    // Non-modal dialog
    LogDialog *l = new LogDialog();
    if (l->parseCvsLog(sandbox, repository, filename))
        l->show();
    else
        delete l;
}


#if 0
void CervisiaPart::slotBrowseMultiLog()
{
    QStrList list = update->multipleSelection();
    if (!list.isEmpty())
        {
            // Non-modal dialog
            MultiLogDialog *l = new MultiLogDialog();
            if (l->parseCvsLog(".", list))
                l->show();
            else
                delete l;
        }
}
#endif


void CervisiaPart::slotAnnotate()
{
    QString filename;
    update->getSingleSelection(&filename);
Laurent Montel's avatar
Laurent Montel committed
928

929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
    if (filename.isEmpty())
        return;

    // Non-modal dialog
    AnnotateDialog *l = new AnnotateDialog();
    if (l->parseCvsAnnotate(sandbox, repository, filename, ""))
        l->show();
    else
        delete l;
}


void CervisiaPart::slotDiff()
{
    QString filename;
    update->getSingleSelection(&filename);
Laurent Montel's avatar
Laurent Montel committed
945

946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
    if (filename.isEmpty())
        return;

    // Non-modal dialog
    DiffDialog *l = new DiffDialog();
    if (l->parseCvsDiff(sandbox, repository, filename, "", ""))
        l->show();
    else
        delete l;
}


void CervisiaPart::slotAddWatch()
{
    addOrRemoveWatch(WatchDialog::Add);
}


void CervisiaPart::slotRemoveWatch()
{
    addOrRemoveWatch(WatchDialog::Remove);
}


void CervisiaPart::addOrRemoveWatch(WatchDialog::ActionType action)
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    WatchDialog *l = new WatchDialog(action, widget());

    if (l->exec() && l->events() != WatchDialog::None)
        {
            QString cmdline = cvsClient(repository);
            cmdline += " watch ";
            if (action == WatchDialog::Add)
                cmdline += "add ";
            else
                cmdline += "remove ";
Laurent Montel's avatar
Laurent Montel committed
986

987 988 989 990 991 992 993 994 995 996
            WatchDialog::Events events = l->events();
            if (events != WatchDialog::All)
                {
                    if (events & WatchDialog::Commits)
                        cmdline += "-a commit ";
                    if (events & WatchDialog::Edits)
                        cmdline += "-a edit ";
                    if (events & WatchDialog::Unedits)
                        cmdline += "-a unedit ";
                }
Laurent Montel's avatar
Laurent Montel committed
997

998
            cmdline += joinLine(list);
Laurent Montel's avatar
Laurent Montel committed
999

1000 1001 1002 1003 1004 1005
            if (protocol->startJob(sandbox, repository, cmdline))
                {
                    showJobStart(cmdline);
                    connect( protocol, SIGNAL(jobFinished(bool)), this, SLOT(slotJobFinished(bool)) );
                }
        }
Laurent Montel's avatar
Laurent Montel committed
1006

1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
    delete l;
}


void CervisiaPart::slotShowWatchers()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QString cmdline = cvsClient(repository);
    cmdline += " watchers ";
    cmdline += joinLine(list);
Laurent Montel's avatar
Laurent Montel committed
1020

1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
    if (protocol->startJob(sandbox, repository, cmdline))
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool)), this, SLOT(slotJobFinished(bool)) );
        }
}


void CervisiaPart::slotEdit()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QString cmdline = cvsClient(repository);
    cmdline += " edit ";
    cmdline += joinLine(list);
Laurent Montel's avatar
Laurent Montel committed
1038

1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
    if (protocol->startJob(sandbox, repository, cmdline))
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool)), this, SLOT(slotJobFinished(bool)) );
        }
}


void CervisiaPart::slotUnedit()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QString cmdline = "echo y | ";
    cmdline += cvsClient(repository);
    cmdline += " unedit ";
    cmdline += joinLine(list);
Laurent Montel's avatar
Laurent Montel committed
1057

1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
    if (protocol->startJob(sandbox, repository, cmdline))
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool)), this, SLOT(slotJobFinished(bool)) );
        }
}


void CervisiaPart::slotLock()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QString cmdline = cvsClient(repository);
    cmdline += " admin -l ";
    cmdline += joinLine(list);
Laurent Montel's avatar
Laurent Montel committed
1075

1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
    if (protocol->startJob(sandbox, repository, cmdline))
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool)), this, SLOT(slotJobFinished(bool)) );
        }
}


void CervisiaPart::slotUnlock()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QString cmdline = cvsClient(repository);
    cmdline += " admin -u ";
    cmdline += joinLine(list);
Laurent Montel's avatar
Laurent Montel committed
1093

1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
    if (protocol->startJob(sandbox, repository, cmdline))
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool)), this, SLOT(slotJobFinished(bool)) );
        }
}


void CervisiaPart::slotShowEditors()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QString cmdline = cvsClient(repository);
    cmdline += " editors ";
    cmdline += joinLine(list);
Laurent Montel's avatar
Laurent Montel committed
1111

1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
    if (protocol->startJob(sandbox, repository, cmdline))
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool)), this, SLOT(slotJobFinished(bool)) );
        }
}


void CervisiaPart::slotMakePatch()
{
    CvsProgressDialog l("Diff", widget());
    l.setCaption("CVS Diff");

    QString cmdline = cvsClient(repository);
    cmdline += " diff -uR";
    if (!l.execCommand(sandbox, repository, cmdline, ""))
        return;

    QString filename = KFileDialog::getSaveFileName();
    if (filename.isEmpty())
        return;

    QFile f(filename);
    if (!f.open(IO_WriteOnly))
        {
            QMessageBox::information(widget(), "Cervisia",
                                     i18n("Could not open file for writing."));
            return;
        }
    QTextStream t(&f);
    QCString line;
    while (l.getOneLine(&line))
        t << line << '\n';

    f.close();
}


void CervisiaPart::slotImport()
{
    importOrCheckout(CheckoutDialog::Import);
}


void CervisiaPart::slotCheckout()
{
    importOrCheckout(CheckoutDialog::Checkout);
}


void CervisiaPart::importOrCheckout(CheckoutDialog::ActionType action)
{
    CheckoutDialog *l = new CheckoutDialog(action, widget());

    if (l->exec())
        {
            QString cmdline = "cd ";
            cmdline += l->workingDirectory();
            cmdline += " && ";
            cmdline += cvsClient(repository);
            cmdline += " -d ";
            cmdline += l->repository();
            if (action == CheckoutDialog::Checkout)
                {
                    cmdline += " checkout ";
                    if (opt_pruneDirs)
                        cmdline += "-P ";
                    cmdline += l->module();
                }
            else
                {
                    cmdline += " import";
                    if (l->importBinary())
                        cmdline += " -kb";
                    QString ignore = l->ignoreFiles().stripWhiteSpace();
                    if (!ignore.isEmpty())
                        {
                            cmdline += " -I ";
                            cmdline += KShellProcess::quote(ignore);
                        }
                    cmdline += " -m ";
                    cmdline += (QString("\"") + "" + "\" "); // log message?
                    cmdline += l->module();
                    cmdline += " ";
                    cmdline += l->vendorTag();
                    cmdline += " ";
                    cmdline += l->releaseTag();
                }
Laurent Montel's avatar
Laurent Montel committed
1200

1201 1202 1203 1204 1205 1206
            if (protocol->startJob(sandbox, repository, cmdline))
                {
                    showJobStart(cmdline);
                    connect( protocol, SIGNAL(jobFinished(bool)), this, SLOT(slotJobFinished(bool)) );
                }
        }
Laurent Montel's avatar
Laurent Montel committed
1207

1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
    delete l;
}


void CervisiaPart::slotRepositories()
{
    RepositoryDialog *l = new RepositoryDialog(widget());
    l->show();
}


void CervisiaPart::slotCreateTag()
{
    createOrDeleteTag(TagDialog::Create);
}


void CervisiaPart::slotDeleteTag()
{
    createOrDeleteTag(TagDialog::Delete);
}


void CervisiaPart::createOrDeleteTag(TagDialog::ActionType action)
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    TagDialog *l = new TagDialog(action, sandbox, repository, widget());

    if (l->exec())
        {
            QString cmdline = cvsClient(repository);
            cmdline += " tag ";
            if (action == TagDialog::Delete)
                cmdline += "-d ";
Bernd Gehrmann's avatar
Bernd Gehrmann committed
1245
            if (l->branchTag())
1246
                cmdline += "-b ";
Bernd Gehrmann's avatar
Bernd Gehrmann committed
1247 1248
	    if (l->forceTag())
		cmdline += "-F ";
1249 1250 1251
            cmdline += l->tag();
            cmdline += " ";
            cmdline += joinLine(list);
Laurent Montel's avatar
Laurent Montel committed
1252

1253 1254 1255 1256 1257 1258
            if (protocol->startJob(sandbox, repository, cmdline))
                {
                    showJobStart(cmdline);
                    connect( protocol, SIGNAL(jobFinished(bool)), this, SLOT(slotJobFinished(bool)) );
                }
        }
Laurent Montel's avatar
Laurent Montel committed
1259

1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
    delete l;
}



void CervisiaPart::slotLastChange()
{
    QString filename, revA, revB;
    update->getSingleSelection(&filename, &revA);
    if (filename.isEmpty())
        return;
Laurent Montel's avatar
Laurent Montel committed
1271

1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364
    int pos, lastnumber;
    bool ok;
    if ( (pos = revA.findRev('.')) == -1
         || (lastnumber=revA.right(revA.length()-pos-1).toUInt(&ok), !ok) )
        {
            QMessageBox::information(widget(), "Cervisia", i18n("The revision looks invalid."));
            return;
        }
    if (lastnumber == 0)
        {
            QMessageBox::information(widget(), "Cervisia", i18n("The is the first revision on the branch."));
            return;
        }
    revB = revA.left(pos+1);
    revB += QString::number(lastnumber-1);

    // Non-modal dialog
    DiffDialog *l = new DiffDialog();
    if (l->parseCvsDiff(sandbox, repository, filename, revB, revA))
        l->show();
    else
        delete l;
}


void CervisiaPart::slotHistory()
{
    // Non-modal dialog
    HistoryDialog *l = new HistoryDialog();
    if (l->parseHistory(sandbox, repository))
        l->show();
    else
        delete l;
}


void CervisiaPart::slotHideFiles()
{
    opt_hideFiles = !opt_hideFiles;
    setFilter();
}


void CervisiaPart::slotHideUpToDate()
{
    opt_hideUpToDate = !opt_hideUpToDate;
    setFilter();
}


void CervisiaPart::slotHideRemoved()
{
    opt_hideRemoved = !opt_hideRemoved;
    setFilter();
}


void CervisiaPart::slotCreateDirs()
{
    opt_createDirs = !opt_createDirs;
}


void CervisiaPart::slotPruneDirs()
{
    opt_pruneDirs = !opt_pruneDirs;
}


void CervisiaPart::slotUpdateRecursive()
{
    opt_updateRecursive = !opt_updateRecursive;
}


void CervisiaPart::slotCommitRecursive()
{
    opt_commitRecursive = !opt_commitRecursive;
}


void CervisiaPart::slotDoCVSEdit()
{
    opt_doCVSEdit = !opt_doCVSEdit;
}

void CervisiaPart::slotConfigure()
{
    KConfig *conf = config();
    SettingsDialog *l = new SettingsDialog( conf, widget() );
    l->exec();

    conf->setGroup("LookAndFeel");
Laurent Montel's avatar
Laurent Montel committed
1365 1366
    bool splitHorz = conf->readBoolEntry("SplitHorizontally",true);
    splitter->setOrientation(splitHorz? QSplitter::Vertical :QSplitter::Horizontal);
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424
}

void CervisiaPart::slotHelp()
{
    emit setStatusBarText( i18n("Invoking help on Cervisia") );
    // TODO: invokes the wrong help
    kapp->invokeHelp();
}


void CervisiaPart::slotCVSInfo()
{
    emit setStatusBarText( i18n("Invoking help on CVS") );
    KApplication::startServiceByDesktopName("khelpcenter", QString("info:/cvs/Top"));
}


void CervisiaPart::showJobStart(const QString &cmdline)
{
    hasRunningJob = true;
    actionCollection()->action( "stop_job" )->setEnabled( true );

    emit setStatusBarText( cmdline );
    updateActions();
}


void CervisiaPart::slotJobFinished(bool)
{
    actionCollection()->action( "stop_job" )->setEnabled( false );
    hasRunningJob = false;
    emit setStatusBarText( i18n("Done") );
    updateActions();
}


void CervisiaPart::openSandbox(const QString &dirname)
{
    QFileInfo fi1(dirname);
    QString sandboxpath = fi1.absFilePath();

    // Nice side-effect of this: Deleted sandboxes are removed
    //    recent->removeURL( KURL(sandboxpath) ); // TODO: Recent for parts

    QFileInfo fi2(sandboxpath + "/CVS");
    if (!fi2.exists() || !fi2.isDir())
    {
        QMessageBox::information(widget(), "Cervisia", i18n("This is not a CVS directory."));
        return;
    }

    //    recent->addURL( KURL(sandboxpath) ); // TODO: Recent for parts

    changelogstr = "";
    sandbox = sandboxpath;
    repository = "";

    QFile f(sandbox + "/CVS/Root");
Laurent Montel's avatar
Laurent Montel committed
1425
    if (f.open(IO_ReadOnly))
1426 1427 1428 1429 1430
    {
        QTextStream t(&f);
        repository = t.readLine();
    }
    f.close();
Laurent Montel's avatar
Laurent Montel committed
1431

1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463

    emit setWindowCaption(sandbox + "(" + repository + ")");
    QDir::setCurrent(sandbox);
    update->openDirectory(sandbox);

    KConfig *conf = config();
    conf->setGroup("General");
    bool dostatus = conf->readBoolEntry(repository.contains(":")?
                                          "StatusForRemoteRepos" : "StatusForLocalRepos", false);
    if (dostatus)
    {
        update->setSelected(update->firstChild(), true);
        updateOrStatus(true, "");
    }

    //load the recentCommits for this app from the KConfig app
    conf->setGroup( "CommitLogs" );
    recentCommits = conf->readListEntry( sandbox, COMMIT_SPLIT_CHAR );

}


void CervisiaPart::setFilter()
{
    UpdateView::Filter filter = UpdateView::Filter(0);
    if (opt_hideFiles)
        filter = UpdateView::Filter(filter | UpdateView::OnlyDirectories);
    if (opt_hideUpToDate)
        filter = UpdateView::Filter(filter | UpdateView::NoUpToDate);
    if (opt_hideRemoved)
        filter = UpdateView::Filter(filter | UpdateView::NoRemoved);
    update->setFilter(filter);
Laurent Montel's avatar
Laurent Montel committed
1464

1465 1466 1467 1468 1469 1470 1471 1472 1473 1474
    QString str;
    if (opt_hideFiles)
        str = "F";
    else
        {
            if (opt_hideUpToDate)
                str += "N";
            if (opt_hideRemoved)
                str += "R";
        }
Laurent Montel's avatar
Laurent Montel committed
1475

1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
    // TODO: Find a new way to handle the status items as you can't do this with KParts yet
    //    filterLabel->setText(str);
}


#if 0
void CervisiaPart::parseStatus(QString pathname, QStrList list)
{
    char buf[512];
    QString command;
    QString dirpath;
    QString name, statusstr, version;
    enum { Begin, File, FileSep, WorkRev, FinalSep } state;

    QString line = joinLine(list);
Laurent Montel's avatar
Laurent Montel committed
1491

1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716
    command = "cd ";
    command += pathname;
    command += " && " + cvsClient(repository) + " status -l ";
    command += line;
    //    command += " 2>&1";

    FILE *f = popen(command, "r");
    if (!f)
        return;

    state = Begin;
    while (fgets(buf, sizeof buf, f))
        {
            QCString line = buf;
            chomp(&line);
            //            DEBUGOUT( "Line: " << line );
            switch (state)
                {
                case Begin:
                    if (line.left(22) == "cvs status: Examining ")
                        dirpath = line.right(line.length()-22);
                    state = File;
                    //                    DEBUGOUT( "state = file" );
                    break;
                case File:
                    if (line.length() > 32 &&
                        line.left(6) == "File: " &&
                        line.mid(24, 8) == "Status: ")
                        {
                            name = line.mid(6, 18).stripWhiteSpace();
                            if (dirpath != ".")
                                name.prepend("/").prepend(dirpath);
                            statusstr = line.right(line.length()-32)
                                .stripWhiteSpace();
                            state = FileSep;
                            //                            DEBUGOUT( "state = FileSep" );
                        }
                    break;
                case FileSep:
                    if (!line.isEmpty()) ; // Error
                    state = WorkRev;
                    //                    DEBUGOUT( "state = WorkRev" );
                    break;
                case WorkRev:
                    if (line.left(21) == "   Working revision:\t")
                        {
                            int pos;
                            version = line.right(line.length()-21);
                            if ( (pos = version.find(" ")) != -1 )
                                version.truncate(pos);
                            state = FinalSep;
                            //                            DEBUGOUT( "state = FinalSep" );
                        }
                    break;
                case FinalSep:
                    if (line == "")
                        {
                            //                            DEBUGOUT( "Adding: " << name <<
                            //                                      "Status: " << statusstr << "Version: " << version );
                            UpdateView::Status status = UpdateView::Unknown;
                            if (statusstr == "Up-to-date")
                                status = UpdateView::UpToDate;
                            else if (statusstr == "Locally Modified")
                                status = UpdateView::LocallyModified;
                            else if (statusstr == "Locally Added")
                                status = UpdateView::LocallyAdded;
                            else if (statusstr == "Locally Removed")
                                status = UpdateView::LocallyRemoved;
                            else if (statusstr == "Needs Checkout")
                                status = UpdateView::NeedsUpdate;
                            else if (statusstr == "Needs Patch")
                                status = UpdateView::NeedsPatch;
                            else if (statusstr == "Needs Merge")
                                status = UpdateView::NeedsMerge;
                            else if (statusstr == "File had conflicts on merge")
                                status = UpdateView::Conflict;
                            //                            update->addEntry(status, name /*, version*/);
                            state = Begin;
                            //                            DEBUGOUT( "state = Begin" );
                        }
                }
        }
    pclose(f);
}
#endif


void CervisiaPart::readProperties(KConfig *config)
{
    // Unfortunately, the KConfig systems sucks and we have to live
    // with all entries in one group for session management.

    opt_createDirs = config->readBoolEntry("Create Dirs", true);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_create_dirs" )))
	->setChecked( opt_createDirs );

    opt_pruneDirs = config->readBoolEntry("Prune Dirs", true);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_prune_dirs" )))
	->setChecked( opt_pruneDirs );

    opt_updateRecursive = config->readBoolEntry("Update Recursive", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_update_recursively" )))
	->setChecked( opt_updateRecursive );

    opt_commitRecursive = config->readBoolEntry("Commit Recursive", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_commit_recursively" )))
	->setChecked( opt_commitRecursive );

    opt_doCVSEdit = config->readBoolEntry("Do cvs edit", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_do_cvs_edit" )))
	->setChecked( opt_doCVSEdit );

    opt_hideFiles = config->readBoolEntry("Hide Files", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_hide_files" )))
	->setChecked( opt_hideFiles );

    opt_hideUpToDate = config->readBoolEntry("Hide UpToDate Files", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_hide_uptodate" )))
	->setChecked( opt_hideUpToDate );

    opt_hideRemoved = config->readBoolEntry("Hide Removed Files", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_hide_removed" )))
	->setChecked( opt_hideRemoved );

    setFilter();

    int splitterpos1 = config->readNumEntry("Splitter Pos 1", 0);
    int splitterpos2 = config->readNumEntry("Splitter Pos 2", 0);
    if (splitterpos1)
        {
            QValueList<int> sizes;
            sizes << splitterpos1;
            sizes << splitterpos2;
            splitter->setSizes(sizes);
        }
}


void CervisiaPart::saveProperties( KConfig *config )
{
    config->writeEntry("Create Dirs", opt_createDirs);
    config->writeEntry("Prune Dirs", opt_pruneDirs);
    config->writeEntry("Update Recursive", opt_updateRecursive);
    config->writeEntry("Commit Recursive", opt_commitRecursive);
    config->writeEntry("Do cvs edit", opt_doCVSEdit);
    config->writeEntry("Hide Files", opt_hideFiles);
    config->writeEntry("Hide UpToDate Files", opt_hideUpToDate);
    config->writeEntry("Hide Removed Files", opt_hideRemoved);
    QValueList<int> sizes = splitter->sizes();
    config->writeEntry("Splitter Pos 1", sizes[0]);
    config->writeEntry("Splitter Pos 2", sizes[1]);
}


void CervisiaPart::readDialogProperties( KConfig *config )
{
    config->setGroup("Diff dialog");
    DiffDialog::loadOptions(config);
    config->setGroup("Log dialog");
    LogDialog::loadOptions(config);
    config->setGroup("LogList view");
    LogListView::loadOptions(config);
    config->setGroup("Resolve dialog");
    ResolveDialog::loadOptions(config);
    config->setGroup("Resolve edit dialog");
    ResolveEditorDialog::loadOptions(config);
    config->setGroup("Commmit dialog");
    CommitDialog::loadOptions(config);
    config->setGroup("ChangeLog dialog");
    ChangeLogDialog::loadOptions(config);
    config->setGroup("Annotate dialog");
    AnnotateDialog::loadOptions(config);
    config->setGroup("Checkout dialog");
    CheckoutDialog::loadOptions(config);
    config->setGroup("History dialog");
    HistoryDialog::loadOptions(config);
    config->setGroup("Repository dialog");
    RepositoryDialog::loadOptions(config);
    config->setGroup("AddRepository dialog");
    AddRepositoryDialog::loadOptions(config);
}


void CervisiaPart::saveDialogProperties( KConfig *config )
{
    config->setGroup("Diff dialog");
    DiffDialog::saveOptions(config);
    config->setGroup("Log dialog");
    LogDialog::saveOptions(config);
    config->setGroup("LogList view");
    LogListView::saveOptions(config);
    config->setGroup("Resolve dialog");
    ResolveDialog::saveOptions(config);
    config->setGroup("Resolve edit dialog");
    ResolveEditorDialog::saveOptions(config);
    config->setGroup("Commit dialog");
    CommitDialog::saveOptions(config);
    config->setGroup("ChangeLog dialog");
    ChangeLogDialog::saveOptions(config);
    config->setGroup("Annotate dialog");
    AnnotateDialog::saveOptions(config);
    config->setGroup("Checkout dialog");
    CheckoutDialog::saveOptions(config);
    config->setGroup("History dialog");
    HistoryDialog::saveOptions(config);
    config->setGroup("Repository dialog");
    RepositoryDialog::saveOptions(config);
    config->setGroup("AddRepository dialog");
    AddRepositoryDialog::saveOptions(config);
}

CervisiaBrowserExtension::CervisiaBrowserExtension( CervisiaPart *p )
    : KParts::BrowserExtension( p, "CervisiaBrowserExtension" )
{

}

CervisiaBrowserExtension::~CervisiaBrowserExtension()
{

}

// Local Variables:
// c-basic-offset: 4
// End: