Changeset View
Changeset View
Standalone View
Standalone View
krusader/Synchronizer/feedtolistboxdialog.cpp
Show All 13 Lines | |||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
15 | * GNU General Public License for more details. * | 15 | * GNU General Public License for more details. * | ||
16 | * * | 16 | * * | ||
17 | * You should have received a copy of the GNU General Public License * | 17 | * You should have received a copy of the GNU General Public License * | ||
18 | * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * | 18 | * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * | ||
19 | *****************************************************************************/ | 19 | *****************************************************************************/ | ||
20 | 20 | | |||
21 | #include "feedtolistboxdialog.h" | 21 | #include "feedtolistboxdialog.h" | ||
22 | | ||||
22 | #include "synchronizer.h" | 23 | #include "synchronizer.h" | ||
23 | #include "synchronizergui.h" | 24 | #include "synchronizergui.h" | ||
24 | #include "../FileSystem/filesystem.h" | 25 | #include "../FileSystem/filesystem.h" | ||
25 | #include "../FileSystem/virtualfilesystem.h" | 26 | #include "../FileSystem/virtualfilesystem.h" | ||
26 | #include "../krglobal.h" | 27 | #include "../krglobal.h" | ||
27 | #include "../krusaderview.h" | 28 | #include "../krusaderview.h" | ||
28 | #include "../panelmanager.h" | 29 | #include "../panelmanager.h" | ||
29 | 30 | | |||
30 | // QtWidgets | 31 | // QtWidgets | ||
31 | #include <QCheckBox> | 32 | #include <QCheckBox> | ||
33 | #include <QComboBox> | ||||
32 | #include <QDialogButtonBox> | 34 | #include <QDialogButtonBox> | ||
33 | #include <QLineEdit> | | |||
34 | #include <QLabel> | 35 | #include <QLabel> | ||
35 | #include <QComboBox> | 36 | #include <QLineEdit> | ||
36 | #include <QVBoxLayout> | 37 | #include <QVBoxLayout> | ||
37 | 38 | | |||
38 | #include <KConfigCore/KConfig> | 39 | #include <KConfigCore/KConfig> | ||
39 | #include <KI18n/KLocalizedString> | 40 | #include <KI18n/KLocalizedString> | ||
40 | #include <KWidgetsAddons/KMessageBox> | 41 | #include <KWidgetsAddons/KMessageBox> | ||
41 | 42 | | |||
42 | #define S_LEFT 0 | 43 | #define S_LEFT 0 | ||
43 | #define S_RIGHT 1 | 44 | #define S_RIGHT 1 | ||
44 | #define S_BOTH 2 | 45 | #define S_BOTH 2 | ||
45 | 46 | | |||
46 | FeedToListBoxDialog::FeedToListBoxDialog(QWidget *parent, Synchronizer *sync, | 47 | FeedToListBoxDialog::FeedToListBoxDialog(QWidget *parent, Synchronizer *sync, QTreeWidget *syncL, | ||
47 | QTreeWidget *syncL, bool equOK) : QDialog(parent), | 48 | bool equOK) | ||
48 | synchronizer(sync), syncList(syncL), equalAllowed(equOK), accepted(false) | 49 | : QDialog(parent), synchronizer(sync), syncList(syncL), equalAllowed(equOK), accepted(false) | ||
49 | { | 50 | { | ||
50 | 51 | | |||
51 | setWindowTitle(i18n("Krusader::Feed to listbox")); | 52 | setWindowTitle(i18n("Krusader::Feed to listbox")); | ||
52 | setWindowModality(Qt::WindowModal); | 53 | setWindowModality(Qt::WindowModal); | ||
53 | 54 | | |||
54 | QVBoxLayout *mainLayout = new QVBoxLayout; | 55 | QVBoxLayout *mainLayout = new QVBoxLayout; | ||
55 | setLayout(mainLayout); | 56 | setLayout(mainLayout); | ||
56 | 57 | | |||
57 | // autodetecting the parameters | 58 | // autodetecting the parameters | ||
58 | 59 | | |||
59 | int selectedNum = 0; | 60 | int selectedNum = 0; | ||
60 | int itemNum = 0; | 61 | int itemNum = 0; | ||
61 | int leftExistingNum = 0; | 62 | int leftExistingNum = 0; | ||
62 | int rightExistingNum = 0; | 63 | int rightExistingNum = 0; | ||
63 | 64 | | |||
64 | QTreeWidgetItemIterator it(syncList); | 65 | QTreeWidgetItemIterator it(syncList); | ||
65 | while (*it) { | 66 | while (*it) { | ||
66 | SynchronizerGUI::SyncViewItem *item = (SynchronizerGUI::SyncViewItem *) * it; | 67 | SyncViewItem *item = (SyncViewItem *)*it; | ||
67 | SynchronizerFileItem *syncItem = item->synchronizerItemRef(); | 68 | SynchronizerFileItem *syncItem = item->synchronizerItemRef(); | ||
68 | 69 | | |||
69 | if (syncItem && syncItem->isMarked()) { | 70 | if (syncItem && syncItem->isMarked()) { | ||
70 | if (item->isSelected() || syncItem->task() != TT_EQUALS || equalAllowed) { | 71 | if (item->isSelected() || syncItem->task() != TT_EQUALS || equalAllowed) { | ||
71 | itemNum++; | 72 | itemNum++; | ||
72 | if (item->isSelected()) | 73 | if (item->isSelected()) | ||
73 | selectedNum++; | 74 | selectedNum++; | ||
74 | 75 | | |||
75 | if (syncItem->existsInLeft()) | 76 | if (syncItem->existsLeft()) | ||
76 | leftExistingNum++; | 77 | leftExistingNum++; | ||
77 | if (syncItem->existsInRight()) | 78 | if (syncItem->existsRight()) | ||
78 | rightExistingNum++; | 79 | rightExistingNum++; | ||
79 | } | 80 | } | ||
80 | } | 81 | } | ||
81 | it++; | 82 | it++; | ||
82 | } | 83 | } | ||
83 | 84 | | |||
84 | if (itemNum == 0) { | 85 | if (itemNum == 0) { | ||
85 | hide(); | 86 | hide(); | ||
Show All 21 Lines | |||||
107 | mainLayout->addWidget(label); | 108 | mainLayout->addWidget(label); | ||
108 | 109 | | |||
109 | lineEdit = new QLineEdit(this); | 110 | lineEdit = new QLineEdit(this); | ||
110 | lineEdit->setText(queryName); | 111 | lineEdit->setText(queryName); | ||
111 | lineEdit->setClearButtonEnabled(true); | 112 | lineEdit->setClearButtonEnabled(true); | ||
112 | lineEdit->selectAll(); | 113 | lineEdit->selectAll(); | ||
113 | mainLayout->addWidget(lineEdit); | 114 | mainLayout->addWidget(lineEdit); | ||
114 | 115 | | |||
115 | QHBoxLayout * hbox = new QHBoxLayout; | 116 | QHBoxLayout *hbox = new QHBoxLayout; | ||
116 | 117 | | |||
117 | QLabel *label2 = new QLabel(i18n("Side to feed:"), this); | 118 | QLabel *label2 = new QLabel(i18n("Side to feed:"), this); | ||
118 | label2->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | 119 | label2->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | ||
119 | hbox->addWidget(label2); | 120 | hbox->addWidget(label2); | ||
120 | 121 | | |||
121 | sideCombo = new QComboBox(this); | 122 | sideCombo = new QComboBox(this); | ||
122 | sideCombo->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | 123 | sideCombo->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | ||
123 | sideCombo->addItem(i18n("Left")); | 124 | sideCombo->addItem(i18n("Left")); | ||
Show All 18 Lines | |||||
142 | cbSelected = new QCheckBox(i18n("Selected files only"), this); | 143 | cbSelected = new QCheckBox(i18n("Selected files only"), this); | ||
143 | cbSelected->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | 144 | cbSelected->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | ||
144 | cbSelected->setEnabled(selectedNum != 0); | 145 | cbSelected->setEnabled(selectedNum != 0); | ||
145 | cbSelected->setChecked(selectedNum != 0); | 146 | cbSelected->setChecked(selectedNum != 0); | ||
146 | hbox->addWidget(cbSelected); | 147 | hbox->addWidget(cbSelected); | ||
147 | 148 | | |||
148 | mainLayout->addLayout(hbox); | 149 | mainLayout->addLayout(hbox); | ||
149 | 150 | | |||
150 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); | 151 | QDialogButtonBox *buttonBox = | ||
152 | new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||||
151 | mainLayout->addWidget(buttonBox); | 153 | mainLayout->addWidget(buttonBox); | ||
152 | 154 | | |||
153 | QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | 155 | QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | ||
154 | okButton->setDefault(true); | 156 | okButton->setDefault(true); | ||
155 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | 157 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | ||
156 | 158 | | |||
157 | connect(buttonBox, SIGNAL(accepted()), SLOT(slotOk())); | 159 | connect(buttonBox, SIGNAL(accepted()), SLOT(slotOk())); | ||
158 | connect(buttonBox, SIGNAL(rejected()), SLOT(reject())); | 160 | connect(buttonBox, SIGNAL(rejected()), SLOT(reject())); | ||
159 | 161 | | |||
160 | exec(); | 162 | exec(); | ||
161 | } | 163 | } | ||
162 | 164 | | |||
163 | void FeedToListBoxDialog::slotOk() | 165 | void FeedToListBoxDialog::slotOk() | ||
164 | { | 166 | { | ||
165 | int side = sideCombo->currentIndex(); | 167 | int side = sideCombo->currentIndex(); | ||
166 | bool selected = cbSelected->isChecked(); | 168 | bool selected = cbSelected->isChecked(); | ||
167 | QString name = lineEdit->text(); | 169 | QString name = lineEdit->text(); | ||
168 | QList<QUrl> urlList; | 170 | QList<QUrl> urlList; | ||
169 | 171 | | |||
170 | QTreeWidgetItemIterator it(syncList); | 172 | QTreeWidgetItemIterator it(syncList); | ||
171 | for (;*it; it++) { | 173 | for (; *it; it++) { | ||
172 | SynchronizerGUI::SyncViewItem *item = (SynchronizerGUI::SyncViewItem *) * it; | 174 | SyncViewItem *item = (SyncViewItem *)*it; | ||
173 | SynchronizerFileItem *syncItem = item->synchronizerItemRef(); | 175 | SynchronizerFileItem *syncItem = item->synchronizerItemRef(); | ||
174 | 176 | | |||
175 | if (!syncItem || !syncItem->isMarked()) | 177 | if (!syncItem || !syncItem->isMarked()) | ||
176 | continue; | 178 | continue; | ||
177 | if (selected && !item->isSelected()) | 179 | if (selected && !item->isSelected()) | ||
178 | continue; | 180 | continue; | ||
179 | if (!equalAllowed && syncItem->task() == TT_EQUALS && (!selected || !item->isSelected())) | 181 | if (!equalAllowed && syncItem->task() == TT_EQUALS && (!selected || !item->isSelected())) | ||
180 | continue; | 182 | continue; | ||
181 | 183 | | |||
182 | if ((side == S_BOTH || side == S_LEFT) && syncItem->existsInLeft()) { | 184 | if ((side == S_BOTH || side == S_LEFT) && syncItem->existsLeft()) { | ||
183 | QString leftDirName = syncItem->leftDirectory().isEmpty() ? "" : syncItem->leftDirectory() + '/'; | 185 | QString leftDirName = | ||
184 | QUrl leftURL = Synchronizer::fsUrl(synchronizer->leftBaseDirectory() + leftDirName + syncItem->leftName()); | 186 | syncItem->leftDirectory().isEmpty() ? "" : syncItem->leftDirectory() + '/'; | ||
185 | urlList.push_back(leftURL); | 187 | const QUrl left = Synchronizer::pathAppend(synchronizer->leftBaseDirectory(), | ||
188 | leftDirName, syncItem->leftName()); | ||||
189 | urlList.push_back(left); | ||||
186 | } | 190 | } | ||
187 | 191 | | |||
188 | if ((side == S_BOTH || side == S_RIGHT) && syncItem->existsInRight()) { | 192 | if ((side == S_BOTH || side == S_RIGHT) && syncItem->existsRight()) { | ||
189 | QString rightDirName = syncItem->rightDirectory().isEmpty() ? "" : syncItem->rightDirectory() + '/'; | 193 | QString rightDirName = | ||
190 | QUrl leftURL = Synchronizer::fsUrl(synchronizer->rightBaseDirectory() + rightDirName + syncItem->rightName()); | 194 | syncItem->rightDirectory().isEmpty() ? "" : syncItem->rightDirectory() + '/'; | ||
191 | urlList.push_back(leftURL); | 195 | const QUrl right = Synchronizer::pathAppend(synchronizer->rightBaseDirectory(), | ||
196 | rightDirName, syncItem->rightName()); | ||||
197 | urlList.push_back(right); | ||||
192 | } | 198 | } | ||
193 | } | 199 | } | ||
194 | 200 | | |||
195 | QUrl url = QUrl(QString("virt:/") + name); | 201 | const QUrl url = Synchronizer::pathAppend(QUrl("virt:/"), name); | ||
196 | VirtualFileSystem virtFilesystem; | 202 | VirtualFileSystem virtFilesystem; | ||
197 | if (!virtFilesystem.refresh(url)) { // create directory if it does not exist | 203 | if (!virtFilesystem.refresh(url)) { // create directory if it does not exist | ||
198 | KMessageBox::error(parentWidget(), i18n("Cannot open %1.", url.toDisplayString())); | 204 | KMessageBox::error(parentWidget(), i18n("Cannot open %1.", url.toDisplayString())); | ||
199 | return; | 205 | return; | ||
200 | } | 206 | } | ||
201 | virtFilesystem.addFiles(urlList); | 207 | virtFilesystem.addFiles(urlList); | ||
202 | ACTIVE_MNG->slotNewTab(url); | 208 | ACTIVE_MNG->slotNewTab(url); | ||
203 | accepted = true; | 209 | accepted = true; | ||
204 | accept(); | 210 | accept(); | ||
205 | } | 211 | } | ||
206 | |