📄 synchronizergui.cpp
字号:
btnDeletable = new QPushButton( showOptions, "btnDeletable" ); btnDeletable->setText( "" ); btnDeletable->setPixmap( showDeletable ); btnDeletable->setToggleButton( true ); btnDeletable->setOn( krConfig->readBoolEntry( "Deletable Button", _BtnDeletable ) ); btnDeletable->setAccel( CTRL + Key_T ); QWhatsThis::add( btnDeletable, i18n( "Show files marked to delete. (CTRL+T)" ) ); showOptionsLayout->addWidget( btnDeletable, 0, 4); btnDuplicates = new QPushButton( showOptions, "btnDuplicates" ); btnDuplicates->setText( i18n("Duplicates") ); btnDuplicates->setMinimumHeight( btnLeftToRight->height() ); btnDuplicates->setToggleButton( true ); btnDuplicates->setOn( krConfig->readBoolEntry( "Duplicates Button", _BtnDuplicates ) ); QWhatsThis::add( btnDuplicates, i18n( "Show files that exist on both sides." ) ); showOptionsLayout->addWidget( btnDuplicates, 0, 5); btnSingles = new QPushButton( showOptions, "btnSingles" ); btnSingles->setText( i18n("Singles") ); btnSingles->setMinimumHeight( btnLeftToRight->height() ); btnSingles->setToggleButton( true ); btnSingles->setOn( krConfig->readBoolEntry( "Singles Button", _BtnSingles ) ); QWhatsThis::add( btnSingles, i18n( "Show files that exist on one side only." ) ); showOptionsLayout->addWidget( btnSingles, 0, 6); grid->addMultiCellWidget( optionBox, 2, 2, 0, 2 ); synchronizerGrid->addWidget( compareDirs, 0, 0 ); /* ========================= Synchronization list view ========================== */ syncList=new SynchronizerListView( &synchronizer, synchronizerTab ); // create the main container QWhatsThis::add( syncList, i18n( "The compare results of the synchronizer (CTRL+M)." ) ); krConfig->setGroup("Look&Feel"); syncList->setFont(krConfig->readFontEntry("Filelist Font",_FilelistFont)); syncList->setAllColumnsShowFocus(true); syncList->setMultiSelection(true); syncList->setSelectionMode(QListView::Extended); syncList->setVScrollBarMode(QScrollView::Auto); syncList->setHScrollBarMode(QScrollView::Auto); syncList->setShowSortIndicator(false); syncList->setSorting(-1); syncList->setRootIsDecorated( true ); syncList->setTreeStepSize( 10 ); int i=QFontMetrics(syncList->font()).width("W"); int j=QFontMetrics(syncList->font()).width("0"); j=(i>j ? i : j); int typeWidth = j*7/2; krConfig->setGroup("Synchronize"); int leftNameWidth = krConfig->readNumEntry("Left Name Width", 9*typeWidth/2 ); int leftSizeWidth = krConfig->readNumEntry("Left Size Width", 2*typeWidth ); int leftDateWidth = krConfig->readNumEntry("Left Date Width", 3*typeWidth ); int taskTypeWidth = krConfig->readNumEntry("Task Type Width", typeWidth ); int rightDateWidth = krConfig->readNumEntry("Right Date Width", 3*typeWidth ); int rightSizeWidth = krConfig->readNumEntry("Right Size Width", 2*typeWidth ); int rightNameWidth = krConfig->readNumEntry("Right Name Width", 4*typeWidth ); syncList->addColumn(i18n("Name"),leftNameWidth); syncList->addColumn(i18n("Size"),leftSizeWidth); syncList->addColumn(i18n("Date"),leftDateWidth); syncList->addColumn(i18n("<=>") ,taskTypeWidth); syncList->addColumn(i18n("Date"),rightDateWidth); syncList->addColumn(i18n("Size"),rightSizeWidth); syncList->addColumn(i18n("Name"),rightNameWidth); syncList->setColumnWidthMode(0,QListView::Manual); syncList->setColumnWidthMode(1,QListView::Manual); syncList->setColumnWidthMode(2,QListView::Manual); syncList->setColumnWidthMode(3,QListView::Manual); syncList->setColumnWidthMode(4,QListView::Manual); syncList->setColumnWidthMode(5,QListView::Manual); syncList->setColumnWidthMode(6,QListView::Manual); syncList->setColumnAlignment(1, Qt::AlignRight ); syncList->setColumnAlignment(3, Qt::AlignHCenter ); syncList->setColumnAlignment(5, Qt::AlignRight ); syncList->header()->setStretchEnabled( true, 0 ); synchronizerGrid->addWidget(syncList,1,0); synchronizerTabs->insertTab( synchronizerTab, i18n( "&Synchronizer" ) ); synchGrid->addWidget( synchronizerTabs, 0, 0 ); filterTabs = FilterTabs::addTo( synchronizerTabs, FilterTabs::HasDontSearchIn ); generalFilter = (GeneralFilter *)filterTabs->get( "GeneralFilter" ); generalFilter->searchFor->setEditText( fileFilter->currentText() ); generalFilter->searchForCase->setChecked( true ); // creating the time shift, equality threshold, hidden files options QGroupBox *optionsGroup = new QGroupBox( generalFilter, "options" ); optionsGroup->setTitle( i18n( "&Options" ) ); optionsGroup->setColumnLayout(0, Qt::Vertical ); optionsGroup->layout()->setSpacing( 0 ); optionsGroup->layout()->setMargin( 0 ); QGridLayout *optionsLayout = new QGridLayout( optionsGroup->layout() ); optionsLayout->setAlignment( Qt::AlignTop ); optionsLayout->setSpacing( 6 ); optionsLayout->setMargin( 11 ); QLabel * parallelThreadsLabel = new QLabel( i18n( "Parallel threads:" ), optionsGroup ); optionsLayout->addWidget( parallelThreadsLabel, 0, 0 ); parallelThreadsSpinBox = new QSpinBox( optionsGroup, "parallelThreadsSpinBox" ); parallelThreadsSpinBox->setMinValue( 1 ); parallelThreadsSpinBox->setMaxValue( 15 ); krConfig->setGroup( "Synchronize" ); int parThreads = krConfig->readNumEntry( "Parallel Threads", 1 ); parallelThreadsSpinBox->setValue( parThreads ); optionsLayout->addWidget( parallelThreadsSpinBox, 0, 1 ); QLabel * equalityLabel = new QLabel( i18n( "Equality threshold:" ), optionsGroup ); optionsLayout->addWidget( equalityLabel, 1, 0 ); equalitySpinBox = new QSpinBox( optionsGroup, "equalitySpinBox" ); equalitySpinBox->setMaxValue( 9999 ); optionsLayout->addWidget( equalitySpinBox, 1, 1 ); equalityUnitCombo = new QComboBox( optionsGroup, "equalityUnitCombo" ); equalityUnitCombo->insertItem( i18n( "sec" ) ); equalityUnitCombo->insertItem( i18n( "min" ) ); equalityUnitCombo->insertItem( i18n( "hour" ) ); equalityUnitCombo->insertItem( i18n( "day" ) ); optionsLayout->addWidget( equalityUnitCombo, 1, 2 ); QLabel * timeShiftLabel = new QLabel( i18n( "Time shift (right-left):" ), optionsGroup ); optionsLayout->addWidget( timeShiftLabel, 2, 0 ); timeShiftSpinBox = new QSpinBox( optionsGroup, "timeShiftSpinBox" ); timeShiftSpinBox->setMinValue( -9999 ); timeShiftSpinBox->setMaxValue( 9999 ); optionsLayout->addWidget( timeShiftSpinBox, 2, 1 ); timeShiftUnitCombo = new QComboBox( optionsGroup, "timeShiftUnitCombo" ); timeShiftUnitCombo->insertItem( i18n( "sec" ) ); timeShiftUnitCombo->insertItem( i18n( "min" ) ); timeShiftUnitCombo->insertItem( i18n( "hour" ) ); timeShiftUnitCombo->insertItem( i18n( "day" ) ); optionsLayout->addWidget( timeShiftUnitCombo, 2, 2 ); QFrame *line = new QFrame( optionsGroup ); line->setFrameStyle( QFrame::HLine | QFrame::Sunken ); optionsLayout->addMultiCellWidget( line, 3, 3, 0, 2 ); ignoreHiddenFilesCB = new QCheckBox( i18n( "Ignore hidden files" ), optionsGroup ); optionsLayout->addMultiCellWidget( ignoreHiddenFilesCB, 4, 4, 0, 2 ); generalFilter->middleLayout->addWidget( optionsGroup ); /* ================================== Buttons =================================== */ QHBoxLayout *buttons = new QHBoxLayout; buttons->setSpacing( 6 ); buttons->setMargin( 0 ); profileManager = new ProfileManager( "SynchronizerProfile", this, "profileManager" ); profileManager->setAccel( CTRL + Key_P ); QWhatsThis::add( profileManager, i18n( "Profile manager (Ctrl+P)." ) ); buttons->addWidget( profileManager ); QPixmap swapSides( ( const char** ) swap_sides_data ); btnSwapSides = new QPushButton( this, "btnSwapSides" ); btnSwapSides->setPixmap( swapSides ); btnSwapSides->setAccel( CTRL + Key_S ); QWhatsThis::add( btnSwapSides, i18n( "Swap sides (Ctrl+S)." ) ); buttons->addWidget( btnSwapSides ); statusLabel = new QLabel( this, "statusLabel" ); buttons->addWidget( statusLabel ); QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); buttons->addItem( spacer ); btnCompareDirs = new QPushButton( this, "btnCompareDirs" ); btnCompareDirs->setText( i18n( "Compare" ) ); btnCompareDirs->setDefault(true); buttons->addWidget( btnCompareDirs ); krConfig->setGroup("Synchronize"); btnScrollResults = new QPushButton( this, "btnSynchronize" ); btnScrollResults->setToggleButton( true ); btnScrollResults->setOn( krConfig->readBoolEntry( "Scroll Results", _ScrollResults ) ); btnScrollResults->hide(); if( btnScrollResults->isOn() ) btnScrollResults->setText( i18n( "Quiet" ) ); else btnScrollResults->setText( i18n( "Scroll Results" ) ); buttons->addWidget( btnScrollResults ); btnStopComparing = new QPushButton( this, "btnStopComparing" ); btnStopComparing->setText( i18n( "Stop" ) ); btnStopComparing->setEnabled(false); buttons->addWidget( btnStopComparing ); btnFeedToListBox = new QPushButton( this, "btnFeedToListBox" ); btnFeedToListBox->setText( i18n( "Feed to listbox" ) ); btnFeedToListBox->setEnabled(false); btnFeedToListBox->hide(); buttons->addWidget( btnFeedToListBox ); btnSynchronize = new QPushButton( this, "btnSynchronize" ); btnSynchronize->setText( i18n( "Synchronize" ) ); btnSynchronize->setEnabled(false); buttons->addWidget( btnSynchronize ); QPushButton *btnCloseSync = new QPushButton( this, "btnCloseSync" ); btnCloseSync->setText( i18n( "Close" ) ); buttons->addWidget( btnCloseSync ); synchGrid->addLayout( buttons, 1, 0 ); /* =============================== Connect table ================================ */ connect( syncList,SIGNAL(rightButtonPressed(QListViewItem *, const QPoint &, int)), this, SLOT(rightMouseClicked(QListViewItem *))); connect( syncList,SIGNAL(doubleClicked(QListViewItem *, const QPoint &, int)), this, SLOT(doubleClicked(QListViewItem *))); connect( syncList,SIGNAL(contextMenuRequested(QListViewItem *, const QPoint &, int)), this, SLOT(rightMouseClicked(QListViewItem *))); connect( profileManager, SIGNAL( loadFromProfile( QString ) ), this, SLOT( loadFromProfile( QString ) ) ); connect( profileManager, SIGNAL( saveToProfile( QString ) ), this, SLOT( saveToProfile( QString ) ) ); connect( btnSwapSides, SIGNAL( clicked() ), this, SLOT( swapSides() ) ); connect( btnCompareDirs, SIGNAL( clicked() ), this, SLOT( compare() ) ); connect( btnStopComparing, SIGNAL( clicked() ), this, SLOT( stop() ) ); connect( btnFeedToListBox, SIGNAL( clicked() ), this, SLOT( feedToListBox() ) ); connect( btnSynchronize, SIGNAL( clicked() ), this, SLOT( synchronize() ) ); connect( btnScrollResults, SIGNAL( toggled(bool) ), this, SLOT( setScrolling(bool) ) ); connect( btnCloseSync, SIGNAL( clicked() ), this, SLOT( closeDialog() ) ); connect( cbSubdirs, SIGNAL( toggled(bool) ), this, SLOT( subdirsChecked( bool ) ) ); connect( cbAsymmetric, SIGNAL( toggled(bool) ), this, SLOT( setPanelLabels() ) ); connect( &synchronizer, SIGNAL( comparedFileData( SynchronizerFileItem * ) ), this, SLOT( addFile( SynchronizerFileItem * ) ) ); connect( &synchronizer, SIGNAL( markChanged( SynchronizerFileItem *, bool ) ), this, SLOT( markChanged( SynchronizerFileItem *, bool ) ) ); connect( &synchronizer, SIGNAL( statusInfo( QString ) ), this, SLOT( statusInfo( QString ) ) ); connect( btnLeftToRight, SIGNAL( toggled(bool) ), this, SLOT( refresh() ) ); connect( btnEquals, SIGNAL( toggled(bool) ), this, SLOT( refresh() ) ); connect( btnDifferents, SIGNAL( toggled(bool) ), this, SLOT( refresh() ) ); connect( btnRightToLeft, SIGNAL( toggled(bool) ), this, SLOT( refresh() ) ); connect( btnDeletable, SIGNAL( toggled(bool) ), this, SLOT( refresh() ) ); connect( btnDuplicates, SIGNAL( toggled(bool) ), this, SLOT( refresh() ) ); connect( btnSingles, SIGNAL( toggled(bool) ), this, SLOT( refresh() ) ); connect( fileFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( connectFilters( const QString & ) ) ); connect( generalFilter->searchFor, SIGNAL( textChanged( const QString & ) ), this, SLOT( connectFilters( const QString & ) ) ); connect( generalFilter->searchFor, SIGNAL( textChanged( const QString & ) ), this, SLOT( setCompletion() ) ); connect( generalFilter->dontSearchIn, SIGNAL( checkValidity( QString &, QString & ) ), this, SLOT( checkExcludeURLValidity( QString &, QString & ) ) ); connect( profileManager, SIGNAL( loadFromProfile( QString ) ), filterTabs, SLOT( loadFromProfile( QString ) ) ); connect( profileManager, SIGNAL( saveToProfile( QString ) ), filterTabs, SLOT( saveToProfile( QString ) ) ); setPanelLabels(); setCompletion(); /* =============================== Loading the colors ================================ */ krConfig->setGroup("Colors"); DECLARE_COLOR_NAME_ARRAY; DECLARE_BACKGROUND_DFLTS; DECLARE_FOREGROUND_DFLTS; for( int clr = 0; clr != TT_MAX; clr ++ ) { QString foreEntry = QString( "Synchronizer " ) + COLOR_NAMES[ clr ] + QString( " Foreground" ); QString bckgEntry = QString( "Synchronizer " ) + COLOR_NAMES[ clr ] + QString( " Background" ); if( krConfig->readEntry( foreEntry ) == "KDE default" ) foreGrounds[ clr ] = QColor(); else foreGrounds[ clr ] = krConfig->readColorEntry( foreEntry, &FORE_DFLTS[ clr ] ); if( krConfig->readEntry( bckgEntry ) == "KDE default" ) backGrounds[ clr ] = QColor(); else backGrounds[ clr ] = krConfig->readColorEntry( bckgEntry, &BCKG_DFLTS[ clr ] ); } if( backGrounds[ TT_EQUALS ].isValid() ) syncList->setPaletteBackgroundColor( backGrounds[ TT_EQUALS ] ); krConfig->setGroup("Synchronize"); int sx = krConfig->readNumEntry( "Window Width", -1 ); int sy = krConfig->readNumEntry( "Window Height", -1 ); if( sx != -1 && sy != -1 ) resize( sx, sy ); if( krConfig->readBoolEntry( "Window Maximized", false ) ) showMaximized(); else show(); if( !profileName.isNull() ) profileManager->loadProfile( profileName ); synchronizer.setParentWidget( this );}SynchronizerGUI::~SynchronizerGUI(){ syncList->clear(); // for sanity: deletes the references to the synchronizer list}void SynchronizerGUI::setPanelLabels(){ if( hasSelectedFiles && cbAsymmetric->isChecked() ) { leftDirLabel->setText( i18n( "Selected files from targ&et directory:" ) ); rightDirLabel->setText( i18n( "Selected files from sou&rce directory:" ) ); } else if( hasSelectedFiles && !cbAsymmetric->isChecked() ) { leftDirLabel->setText( i18n( "Selected files from &left directory:" ) ); rightDirLabel->setText( i18n( "Selected files from &right directory:" ) ); } else if( cbAsymmetric->isChecked() ) { leftDirLabel->setText( i18n( "Targ&et directory:" ) ); rightDirLabel->setText( i18n( "Sou&rce directory:" ) ); } else { leftDirLabel->setText( i18n( "&Left directory:" ) ); rightDirLabel->setText( i18n( "&Right directory:" ) ); }}void SynchronizerGUI::setCompletion(){ generalFilter->dontSearchIn->setCompletionDir( rightLocation->currentText() );}void SynchronizerGUI::checkExcludeURLValidity( QString &text, QString &error ){ KURL url = vfs::fromPathOrURL( text ); if( KURL::isRelativeURL( url.url() ) ) return; QString leftBase = leftLocation->currentText(); if( !leftBase.endsWith( "/" ) ) leftBase += "/"; KURL leftBaseURL = vfs::fromPathOrURL( leftBase ); if( leftBaseURL.isParentOf( url ) && !url.isParentOf( leftBaseURL) ) { text = KURL::relativeURL( leftBaseURL, url ); return; } QString rightBase = rightLocation->currentText(); if( !rightBase.endsWith( "/" ) ) rightBase += "/"; KURL rightBaseURL = vfs::fromPathOrURL( rightBase ); if( rightBaseURL.isParentOf( url ) && !url.isParentOf( rightBaseURL ) ) { text = KURL::relativeURL( rightBaseURL, url ); return; } error = i18n("URL must be the descendant of either the left or the right base URL!");}void SynchronizerGUI::doubleClicked(QListViewItem *itemIn){ if (!itemIn) return; SyncViewItem *syncItem = (SyncViewItem *)itemIn; SynchronizerFileItem *item = syncItem->synchronizerItemRef(); if( item && item->existsInLeft() && item->existsInRight() && !item->isDir() ) { QString leftDirName = item->leftDirectory().isEmpty() ? "" : item->leftDirectory() + "/"; 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() ); SLOTS->compareContent( leftURL, rightURL ); }}void SynchronizerGUI::rightMouseClicked(QListViewItem *itemIn){ // these are the values that will exist in the menu #define EXCLUDE_ID 90 #define RESTORE_ID 91 #define COPY_TO_LEFT_ID 92 #define COPY_TO_RIGHT_ID 93 #define REVERSE_DIR_ID 94 #define DELETE_ID 95 #define VIEW_LEFT_FILE_ID 96 #define VIEW_RIGHT_FILE_ID 97 #define COMPARE_FILES_ID 98 #define SELECT_ITEMS_ID 99 #define DESELECT_ITEMS_ID 100 #define INVERT_SELECTION_ID 101 #define SYNCH_WITH_KGET_ID 102 #define COPY_CLPBD_LEFT_ID 103 #define COPY_CLPBD_RIGHT_ID 104 ////////////////////////////////////////////////////////// if (!itemIn) return; SyncViewItem *syncItem = (SyncViewItem *)itemIn; if( syncItem == 0 ) return; SynchronizerFileItem *item = syncItem->synchronizerItemRef(); bool isDuplicate = item->existsInLeft() && item->existsInRight(); bool isDir = item->isDir(); QString leftDirName = item->leftDirectory().isEmpty() ? "" : item->leftDirectory() + "/";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -