📄 synchronizergui.cpp
字号:
QString rightDirName = item->rightDirectory().isEmpty() ? "" : item->rightDirectory() + "/"; KURL leftURL = vfs::fromPathOrURL( synchronizer.leftBaseDirectory() + leftDirName + item->leftName() ); KURL rightURL = vfs::fromPathOrURL( synchronizer.rightBaseDirectory() + rightDirName + item->rightName() ); // create the menu KPopupMenu popup; popup.insertTitle(i18n("Synchronize Directories")); popup.insertItem(i18n("E&xclude"),EXCLUDE_ID); popup.setItemEnabled(EXCLUDE_ID, true ); popup.insertItem(i18n("Restore ori&ginal operation"),RESTORE_ID); popup.setItemEnabled(RESTORE_ID, true ); popup.insertItem(i18n("Re&verse direction"),REVERSE_DIR_ID); popup.setItemEnabled(REVERSE_DIR_ID, true ); popup.insertItem(i18n("Copy from &right to left"),COPY_TO_LEFT_ID); popup.setItemEnabled(COPY_TO_LEFT_ID, true ); popup.insertItem(i18n("Copy from &left to right"),COPY_TO_RIGHT_ID); popup.setItemEnabled(COPY_TO_RIGHT_ID, true ); popup.insertItem(i18n("&Delete (left single)"),DELETE_ID); popup.setItemEnabled(DELETE_ID, true ); popup.insertSeparator(); popup.insertItem(i18n("V&iew left file"),VIEW_LEFT_FILE_ID); popup.setItemEnabled(VIEW_LEFT_FILE_ID, !isDir && item->existsInLeft() ); popup.insertItem(i18n("Vi&ew right file"),VIEW_RIGHT_FILE_ID); popup.setItemEnabled(VIEW_RIGHT_FILE_ID, !isDir && item->existsInRight() ); popup.insertItem(i18n("&Compare Files"),COMPARE_FILES_ID); popup.setItemEnabled(COMPARE_FILES_ID, !isDir && isDuplicate ); popup.insertSeparator(); popup.insertItem(i18n("C&opy selected to clipboard (left)"),COPY_CLPBD_LEFT_ID); popup.insertItem(i18n("Co&py selected to clipboard (right)"),COPY_CLPBD_RIGHT_ID); popup.insertSeparator(); popup.insertItem(i18n("&Select items"),SELECT_ITEMS_ID); popup.setItemEnabled(SELECT_ITEMS_ID, true ); popup.insertItem(i18n("Deselec&t items"),DESELECT_ITEMS_ID); popup.setItemEnabled(DESELECT_ITEMS_ID, true ); popup.insertItem(i18n("I&nvert selection"),INVERT_SELECTION_ID); popup.setItemEnabled(INVERT_SELECTION_ID, true ); KURL leftBDir = vfs::fromPathOrURL( synchronizer.leftBaseDirectory() ); KURL rightBDir = vfs::fromPathOrURL( synchronizer.rightBaseDirectory() ); if( KrServices::cmdExist( "kget" ) && ( ( !leftBDir.isLocalFile() && rightBDir.isLocalFile() && btnLeftToRight->isOn() ) || ( leftBDir.isLocalFile() && !rightBDir.isLocalFile() && btnRightToLeft->isOn() ) ) ) { popup.insertSeparator(); popup.insertItem(i18n("Synchronize with &KGet"),SYNCH_WITH_KGET_ID); popup.setItemEnabled(SYNCH_WITH_KGET_ID, true ); } int result=popup.exec(QCursor::pos()); // check out the user's option switch (result) { case EXCLUDE_ID: case RESTORE_ID: case COPY_TO_LEFT_ID: case COPY_TO_RIGHT_ID: case REVERSE_DIR_ID: case DELETE_ID: { unsigned ndx = 0; SynchronizerFileItem *currentItem; while( ( currentItem = synchronizer.getItemAt( ndx++ ) ) != 0 ) { SyncViewItem *viewItem = (SyncViewItem *)currentItem->userData(); if( !viewItem || !viewItem->isSelected() || !viewItem->isVisible() ) continue; switch( result ) { case EXCLUDE_ID: synchronizer.exclude( viewItem->synchronizerItemRef() ); break; case RESTORE_ID: synchronizer.restore( viewItem->synchronizerItemRef() ); break; case REVERSE_DIR_ID: synchronizer.reverseDirection( viewItem->synchronizerItemRef() ); break; case COPY_TO_LEFT_ID: synchronizer.copyToLeft( viewItem->synchronizerItemRef() ); break; case COPY_TO_RIGHT_ID: synchronizer.copyToRight( viewItem->synchronizerItemRef() ); break; case DELETE_ID: synchronizer.deleteLeft( viewItem->synchronizerItemRef() ); break; } } refresh(); } break; case VIEW_LEFT_FILE_ID: KrViewer::view( leftURL, this ); // view the file break; case VIEW_RIGHT_FILE_ID: KrViewer::view( rightURL, this ); // view the file break; case COMPARE_FILES_ID: SLOTS->compareContent( leftURL, rightURL ); break; case SELECT_ITEMS_ID: case DESELECT_ITEMS_ID: { KRQuery query = KRSpWidgets::getMask( ( result == SELECT_ITEMS_ID ? i18n("Select items") : i18n( "Deselect items" ) ), true ); if( query.isNull() ) break; unsigned ndx = 0; SynchronizerFileItem *currentItem; while( ( currentItem = synchronizer.getItemAt( ndx++ ) ) != 0 ) { SyncViewItem *viewItem = (SyncViewItem *)currentItem->userData(); if( !viewItem || !viewItem->isVisible() ) continue; if( query.match( currentItem->leftName() ) || query.match( currentItem->rightName() ) ) syncList->setSelected( viewItem, result == SELECT_ITEMS_ID ); } } break; case INVERT_SELECTION_ID: syncList->invertSelection(); break; case SYNCH_WITH_KGET_ID: synchronizer.synchronizeWithKGet(); closeDialog(); break; case COPY_CLPBD_LEFT_ID: copyToClipboard( true ); break; case COPY_CLPBD_RIGHT_ID: copyToClipboard( false ); break; case -1 : return; // the user clicked outside of the menu }}void SynchronizerGUI::closeDialog(){ if( isComparing ) { stop(); wasClosed = true; return; } QStringList list = leftLocation->historyItems(); krConfig->setGroup("Synchronize"); krConfig->writeEntry("Left Directory History", list); list = rightLocation->historyItems(); krConfig->writeEntry("Right Directory History", list); list = fileFilter->historyItems(); krConfig->writeEntry("File Filter", list); krConfig->writeEntry("Recurse Subdirectories", cbSubdirs->isChecked() ); krConfig->writeEntry("Follow Symlinks", cbSymlinks->isChecked() ); krConfig->writeEntry("Compare By Content", cbByContent->isChecked() ); krConfig->writeEntry("Ignore Date", cbIgnoreDate->isChecked() ); krConfig->writeEntry("Asymmetric", cbAsymmetric->isChecked() ); krConfig->writeEntry("Ignore Case", cbIgnoreCase->isChecked() ); krConfig->writeEntry("LeftToRight Button", btnLeftToRight->isOn() ); krConfig->writeEntry("Equals Button", btnEquals->isOn() ); krConfig->writeEntry("Differents Button", btnDifferents->isOn() ); krConfig->writeEntry("RightToLeft Button", btnRightToLeft->isOn() ); krConfig->writeEntry("Deletable Button", btnDeletable->isOn() ); krConfig->writeEntry("Duplicates Button", btnDuplicates->isOn() ); krConfig->writeEntry("Singles Button", btnSingles->isOn() ); krConfig->writeEntry("Scroll Results", btnScrollResults->isOn() ); krConfig->writeEntry("Parallel Threads", parallelThreadsSpinBox->value() ); krConfig->writeEntry("Window Width", sizeX ); krConfig->writeEntry("Window Height", sizeY ); krConfig->writeEntry("Window Maximized", isMaximized() ); krConfig->writeEntry("Left Name Width", syncList->columnWidth( 0 ) ); krConfig->writeEntry("Left Size Width", syncList->columnWidth( 1 ) ); krConfig->writeEntry("Left Date Width", syncList->columnWidth( 2 ) ); krConfig->writeEntry("Task Type Width", syncList->columnWidth( 3 ) ); krConfig->writeEntry("Right Date Width", syncList->columnWidth( 4 ) ); krConfig->writeEntry("Right Size Width", syncList->columnWidth( 5 ) ); krConfig->writeEntry("Right Name Width", syncList->columnWidth( 6 ) ); QDialog::reject(); this->deleteLater(); if( wasSync ) { ListPanel *p=ACTIVE_PANEL; MAIN_VIEW->left->func->refresh(); MAIN_VIEW->right->func->refresh(); p->slotFocusOnMe(); }}void SynchronizerGUI::compare(){ KRQuery query; if( !filterTabs->fillQuery( &query ) ) return; query.setNameFilter( fileFilter->currentText(), query.isCaseSensitive() ); synchronizerTabs->setCurrentPage(0); syncList->clear(); lastItem = 0; leftLocation->addToHistory(leftLocation->currentText()); rightLocation->addToHistory(rightLocation->currentText()); fileFilter->addToHistory(fileFilter->currentText()); setMarkFlags(); btnCompareDirs->setEnabled( false ); profileManager->setEnabled( false ); btnSwapSides->setEnabled( false ); btnStopComparing->setEnabled( isComparing = true ); btnStopComparing->show(); btnFeedToListBox->setEnabled( false ); btnFeedToListBox->hide(); btnSynchronize->setEnabled( false ); btnCompareDirs->hide(); btnScrollResults->show(); disableMarkButtons(); int fileCount = synchronizer.compare(leftLocation->currentText(), rightLocation->currentText(), &query, cbSubdirs->isChecked(), cbSymlinks->isChecked(), cbIgnoreDate->isChecked(), cbAsymmetric->isChecked(), cbByContent->isChecked(), cbIgnoreCase->isChecked(), btnScrollResults->isOn(), selectedFiles, convertToSeconds( equalitySpinBox->value(), equalityUnitCombo->currentItem() ), convertToSeconds( timeShiftSpinBox->value(), timeShiftUnitCombo->currentItem() ), parallelThreadsSpinBox->value(), ignoreHiddenFilesCB->isChecked() ); enableMarkButtons(); btnStopComparing->setEnabled( isComparing = false ); btnStopComparing->hide(); btnFeedToListBox->show(); btnCompareDirs->setEnabled( true ); profileManager->setEnabled( true ); btnSwapSides->setEnabled( true ); btnCompareDirs->show(); btnScrollResults->hide(); if( fileCount ) { btnSynchronize->setEnabled( true ); btnFeedToListBox->setEnabled( true ); } syncList->setFocus(); if( wasClosed ) closeDialog();}void SynchronizerGUI::stop(){ synchronizer.stop();}void SynchronizerGUI::feedToListBox(){ FeedToListBoxDialog listBox( this, "feedToListBoxDialog", &synchronizer, syncList, btnEquals->isOn() ); if( listBox.isAccepted() ) closeDialog();}void SynchronizerGUI::reject(){ closeDialog();}void SynchronizerGUI::addFile( SynchronizerFileItem *item ){ QString leftName="", rightName="", leftDate="", rightDate="", leftSize="", rightSize=""; bool isDir = item->isDir(); QColor textColor = foreGrounds[ item->task() ]; QColor baseColor = backGrounds[ item->task() ]; if( item->existsInLeft() ) { leftName = item->leftName(); leftSize = isDir ? i18n("<DIR>")+" " : KRpermHandler::parseSize( item->leftSize() ); leftDate = SynchronizerGUI::convertTime( item->leftDate() ); } if( item->existsInRight() ) { rightName = item->rightName(); rightSize = isDir ? i18n("<DIR>")+" " : KRpermHandler::parseSize( item->rightSize() ); rightDate = SynchronizerGUI::convertTime( item->rightDate() ); } SyncViewItem *listItem = 0; SyncViewItem *dirItem; if( item->parent() == 0 ) { listItem = new SyncViewItem(item, textColor, baseColor, syncList, lastItem, leftName, leftSize, leftDate, Synchronizer::getTaskTypeName( item->task() ), rightDate, rightSize, rightName ); lastItem = listItem; } else { dirItem = (SyncViewItem *)item->parent()->userData(); if( dirItem ) { dirItem->setOpen( true ); listItem = new SyncViewItem(item, textColor, baseColor, dirItem, dirItem->lastItem(), leftName, leftSize, leftDate, Synchronizer::getTaskTypeName( item->task() ), rightDate, rightSize, rightName ); dirItem->setLastItem( listItem ); } } if( listItem ) { listItem->setPixmap(0, isDir ? folderIcon : fileIcon); if( !item->isMarked() ) listItem->setVisible( false ); else syncList->ensureItemVisible( listItem ); }}void SynchronizerGUI::markChanged( SynchronizerFileItem *item, bool ensureVisible ){ SyncViewItem *listItem = (SyncViewItem *)item->userData(); if( listItem ) { if( !item->isMarked() ) { listItem->setVisible( false ); } else { QString leftName="", rightName="", leftDate="", rightDate="", leftSize="", rightSize=""; bool isDir = item->isDir(); if( item->existsInLeft() ) { leftName = item->leftName(); leftSize = isDir ? i18n("<DIR>")+" " : KRpermHandler::parseSize( item->leftSize() ); leftDate = SynchronizerGUI::convertTime( item->leftDate() ); } if( item->existsInRight() ) { rightName = item->rightName(); rightSize = isDir ? i18n("<DIR>")+" " : KRpermHandler::parseSize( item->rightSize() ); rightDate = SynchronizerGUI::convertTime( item->rightDate() ); } listItem->setVisible( true ); listItem->setText( 0, leftName ); listItem->setText( 1, leftSize ); listItem->setText( 2, leftDate ); listItem->setColors( foreGrounds[ item->task() ], backGrounds[ item->task() ] ); listItem->setText( 3, Synchronizer::getTaskTypeName( item->task() ) ); listItem->setText( 4, rightDate ); listItem->setText( 5, rightSize ); listItem->setText( 6, rightName ); if( ensureVisible ) syncList->ensureItemVisible( listItem ); } }}void SynchronizerGUI::subdirsChecked( bool isOn ){ cbSymlinks->setEnabled( isOn );}void SynchronizerGUI::disableMarkButtons(){ btnLeftToRight->setEnabled( false ); btnEquals->setEnabled( false ); btnDifferents->setEnabled( false ); btnRightToLeft->setEnabled( false ); btnDeletable->setEnabled( false ); btnDuplicates->setEnabled( false ); btnSingles->setEnabled( false );}void SynchronizerGUI::enableMarkButtons(){ btnLeftToRight->setEnabled( true ); btnEquals->setEnabled( true ); btnDifferents->setEnabled( true ); btnRightToLeft->setEnabled( true ); btnDeletable->setEnabled( true ); btnDuplicates->setEnabled( true ); btnSingles->setEnabled( true );}QString SynchronizerGUI::convertTime(time_t time) const{ // convert the time_t to struct tm struct tm* t=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -