File indexing completed on 2024-04-21 16:33:14
0001 /* 0002 SPDX-FileCopyrightText: 2003 Csaba Karai <krusader@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef SYNCHRONIZERGUI_H 0009 #define SYNCHRONIZERGUI_H 0010 0011 // QtCore 0012 #include <QMap> 0013 // QtGui 0014 #include <QKeyEvent> 0015 #include <QPixmap> 0016 #include <QResizeEvent> 0017 // QtWidgets 0018 #include <QCheckBox> 0019 #include <QDialog> 0020 #include <QLabel> 0021 #include <QTabWidget> 0022 0023 #include <KCompletion/KComboBox> 0024 #include <utility> 0025 0026 #include "../Filter/filtertabs.h" 0027 #include "../Filter/generalfilter.h" 0028 #include "../GUI/krtreewidget.h" 0029 #include "../GUI/profilemanager.h" 0030 #include "synchronizer.h" 0031 0032 class QSpinBox; 0033 0034 class SynchronizerGUI : public QDialog 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 class SyncViewItem : public QTreeWidgetItem 0040 { 0041 private: 0042 SynchronizerFileItem *syncItemRef; 0043 SyncViewItem *lastItemRef; 0044 0045 public: 0046 SyncViewItem(SynchronizerFileItem *item, 0047 QColor txt, 0048 QColor base, 0049 QTreeWidget *parent, 0050 QTreeWidgetItem *after, 0051 const QString &label1, 0052 const QString &label2 = QString(), 0053 const QString &label3 = QString(), 0054 const QString &label4 = QString(), 0055 const QString &label5 = QString(), 0056 const QString &label6 = QString(), 0057 const QString &label7 = QString(), 0058 const QString &label8 = QString()) 0059 : QTreeWidgetItem(parent, after) 0060 , syncItemRef(item) 0061 , lastItemRef(nullptr) 0062 { 0063 setText(0, label1); 0064 setText(1, label2); 0065 setText(2, label3); 0066 setText(3, label4); 0067 setText(4, label5); 0068 setText(5, label6); 0069 setText(6, label7); 0070 setText(7, label8); 0071 0072 setTextAlignment(1, Qt::AlignRight); 0073 setTextAlignment(3, Qt::AlignHCenter); 0074 setTextAlignment(5, Qt::AlignRight); 0075 item->setUserData((void *)this); 0076 0077 setColors(std::move(txt), std::move(base)); 0078 } 0079 0080 SyncViewItem(SynchronizerFileItem *item, 0081 QColor txt, 0082 QColor base, 0083 QTreeWidgetItem *parent, 0084 QTreeWidgetItem *after, 0085 const QString &label1, 0086 const QString &label2 = QString(), 0087 const QString &label3 = QString(), 0088 const QString &label4 = QString(), 0089 const QString &label5 = QString(), 0090 const QString &label6 = QString(), 0091 const QString &label7 = QString(), 0092 const QString &label8 = QString()) 0093 : QTreeWidgetItem(parent, after) 0094 , syncItemRef(item) 0095 , lastItemRef(nullptr) 0096 { 0097 setText(0, label1); 0098 setText(1, label2); 0099 setText(2, label3); 0100 setText(3, label4); 0101 setText(4, label5); 0102 setText(5, label6); 0103 setText(6, label7); 0104 setText(7, label8); 0105 0106 setTextAlignment(1, Qt::AlignRight); 0107 setTextAlignment(3, Qt::AlignHCenter); 0108 setTextAlignment(5, Qt::AlignRight); 0109 item->setUserData((void *)this); 0110 0111 setColors(std::move(txt), std::move(base)); 0112 } 0113 0114 ~SyncViewItem() override 0115 { 0116 syncItemRef->setUserData(nullptr); 0117 } 0118 0119 inline SynchronizerFileItem *synchronizerItemRef() 0120 { 0121 return syncItemRef; 0122 } 0123 inline SyncViewItem *lastItem() 0124 { 0125 return lastItemRef; 0126 } 0127 inline void setLastItem(SyncViewItem *s) 0128 { 0129 lastItemRef = s; 0130 } 0131 0132 void setColors(const QColor &fore, const QColor &back) 0133 { 0134 QBrush textColor(fore); 0135 QBrush baseColor(back); 0136 0137 for (int i = 0; i != columnCount(); i++) { 0138 if (back.isValid()) 0139 setBackground(i, baseColor); 0140 if (fore.isValid()) 0141 setForeground(i, textColor); 0142 } 0143 } 0144 }; 0145 0146 public: 0147 // if rightDirectory is null, leftDirectory is actually the profile name to load 0148 SynchronizerGUI(QWidget *parent, QUrl leftDirectory, QUrl rightDirectory = QUrl(), QStringList selList = QStringList()); 0149 SynchronizerGUI(QWidget *parent, QString profile); 0150 ~SynchronizerGUI() override; 0151 0152 inline bool wasSynchronization() 0153 { 0154 return wasSync; 0155 } 0156 0157 public slots: 0158 void rightMouseClicked(QTreeWidgetItem *, const QPoint &); 0159 void doubleClicked(QTreeWidgetItem *); 0160 void compare(); 0161 void synchronize(); 0162 void stop(); 0163 void feedToListBox(); 0164 void closeDialog(); 0165 void refresh(); 0166 void swapSides(); 0167 void loadFromProfile(const QString &); 0168 void saveToProfile(const QString &); 0169 0170 protected slots: 0171 void reject() override; 0172 void addFile(SynchronizerFileItem *); 0173 void markChanged(SynchronizerFileItem *, bool); 0174 void setScrolling(bool); 0175 void statusInfo(const QString &); 0176 void subdirsChecked(bool); 0177 void setPanelLabels(); 0178 void setCompletion(); 0179 void checkExcludeURLValidity(QString &text, QString &error); 0180 void connectFilters(const QString &); 0181 0182 private: 0183 void initGUI(const QString &profile, QUrl leftURL, QUrl rightURL, QStringList selList); 0184 0185 QString convertTime(time_t time) const; 0186 void setMarkFlags(); 0187 void disableMarkButtons(); 0188 void enableMarkButtons(); 0189 void copyToClipboard(bool isLeft); 0190 0191 int convertToSeconds(int time, int unit); 0192 void convertFromSeconds(int &time, int &unit, int second); 0193 0194 static QPushButton *createButton(QWidget *parent, 0195 const QString &iconName, 0196 bool checked, 0197 const QKeySequence &shortCut, 0198 const QString &description, 0199 const QString &text = QString(), 0200 bool textAndIcon = false); 0201 0202 protected: 0203 void keyPressEvent(QKeyEvent *) override; 0204 bool eventFilter(QObject *, QEvent *) override; 0205 0206 void executeOperation(SynchronizerFileItem *item, int op); 0207 0208 ProfileManager *profileManager; 0209 FilterTabs *filterTabs; 0210 GeneralFilter *generalFilter; 0211 0212 QTabWidget *synchronizerTabs; 0213 0214 KrHistoryComboBox *leftLocation; 0215 KrHistoryComboBox *rightLocation; 0216 KrHistoryComboBox *fileFilter; 0217 0218 KrTreeWidget *syncList; 0219 Synchronizer synchronizer; 0220 0221 QCheckBox *cbSubdirs; 0222 QCheckBox *cbSymlinks; 0223 QCheckBox *cbByContent; 0224 QCheckBox *cbIgnoreDate; 0225 QCheckBox *cbAsymmetric; 0226 QCheckBox *cbIgnoreCase; 0227 0228 QPushButton *btnSwapSides; 0229 QPushButton *btnCompareDirs; 0230 QPushButton *btnStopComparing; 0231 QPushButton *btnSynchronize; 0232 QPushButton *btnFeedToListBox; 0233 QPushButton *btnScrollResults; 0234 0235 QPushButton *btnLeftToRight; 0236 QPushButton *btnEquals; 0237 QPushButton *btnDifferents; 0238 QPushButton *btnRightToLeft; 0239 QPushButton *btnDeletable; 0240 QPushButton *btnDuplicates; 0241 QPushButton *btnSingles; 0242 0243 QLabel *statusLabel; 0244 QLabel *leftDirLabel; 0245 QLabel *rightDirLabel; 0246 0247 QStringList selectedFiles; 0248 0249 QSpinBox *parallelThreadsSpinBox; 0250 QSpinBox *equalitySpinBox; 0251 QComboBox *equalityUnitCombo; 0252 QSpinBox *timeShiftSpinBox; 0253 QComboBox *timeShiftUnitCombo; 0254 QCheckBox *ignoreHiddenFilesCB; 0255 0256 private: 0257 static QString dirLabel(); // returns translated '<DIR>' 0258 0259 bool isComparing; 0260 bool wasClosed; 0261 bool wasSync; 0262 bool hasSelectedFiles; 0263 SyncViewItem *lastItem; 0264 0265 QColor foreGrounds[TT_MAX]; 0266 QColor backGrounds[TT_MAX]; 0267 }; 0268 0269 #endif /* __SYNCHRONIZERGUI_H__ */