Changeset View
Changeset View
Standalone View
Standalone View
plugins/fsview/fsview_part.cpp
Show All 26 Lines | |||||
27 | #include <QClipboard> | 27 | #include <QClipboard> | ||
28 | #include <QTimer> | 28 | #include <QTimer> | ||
29 | #include <QStyle> | 29 | #include <QStyle> | ||
30 | 30 | | |||
31 | #include <kfileitem.h> | 31 | #include <kfileitem.h> | ||
32 | #include <kpluginfactory.h> | 32 | #include <kpluginfactory.h> | ||
33 | #include <kaboutdata.h> | 33 | #include <kaboutdata.h> | ||
34 | 34 | | |||
35 | #include <kglobalsettings.h> | | |||
36 | #include <kprotocolmanager.h> | 35 | #include <kprotocolmanager.h> | ||
37 | #include <kio/copyjob.h> | 36 | #include <kio/copyjob.h> | ||
38 | #include <kio/deletejob.h> | 37 | #include <kio/deletejob.h> | ||
39 | #include <kio/paste.h> | 38 | #include <kio/paste.h> | ||
40 | #include <kmessagebox.h> | 39 | #include <kmessagebox.h> | ||
41 | #include <kactionmenu.h> | 40 | #include <kactionmenu.h> | ||
42 | #include <kactioncollection.h> | 41 | #include <kactioncollection.h> | ||
43 | #include <kpropertiesdialog.h> | 42 | #include <kpropertiesdialog.h> | ||
44 | #include <KMimeTypeEditor> | 43 | #include <KMimeTypeEditor> | ||
45 | #include <kio/jobuidelegate.h> | 44 | #include <kio/jobuidelegate.h> | ||
46 | #include <KIO/FileUndoManager> | 45 | #include <KIO/FileUndoManager> | ||
47 | #include <KJobWidgets> | 46 | #include <KJobWidgets> | ||
48 | #include <ktoolinvocation.h> | 47 | #include <ktoolinvocation.h> | ||
48 | #include <kconfig.h> | ||||
49 | #include <kconfiggroup.h> | 49 | #include <kconfiggroup.h> | ||
50 | #include <KDebug> | 50 | #include <ksharedconfig.h> | ||
51 | | ||||
52 | #include <KLocalizedString> | 51 | #include <KLocalizedString> | ||
53 | 52 | | |||
54 | #include <QApplication> | 53 | #include <QApplication> | ||
55 | #include <QMimeData> | 54 | #include <QMimeData> | ||
56 | 55 | | |||
56 | #include "fsviewdebug.h" | ||||
57 | | ||||
57 | K_PLUGIN_FACTORY(FSViewPartFactory, registerPlugin<FSViewPart>();) | 58 | K_PLUGIN_FACTORY(FSViewPartFactory, registerPlugin<FSViewPart>();) | ||
58 | 59 | | |||
59 | // FSJob, for progress | 60 | // FSJob, for progress | ||
60 | 61 | | |||
61 | FSJob::FSJob(FSView *v) | 62 | FSJob::FSJob(FSView *v) | ||
62 | : KIO::Job() | 63 | : KIO::Job() | ||
63 | { | 64 | { | ||
64 | _view = v; | 65 | _view = v; | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | 142 | QObject::connect(_visMenu->menu(), SIGNAL(aboutToShow()), | |||
142 | SLOT(slotShowVisMenu())); | 143 | SLOT(slotShowVisMenu())); | ||
143 | QObject::connect(_areaMenu->menu(), SIGNAL(aboutToShow()), | 144 | QObject::connect(_areaMenu->menu(), SIGNAL(aboutToShow()), | ||
144 | SLOT(slotShowAreaMenu())); | 145 | SLOT(slotShowAreaMenu())); | ||
145 | QObject::connect(_depthMenu->menu(), SIGNAL(aboutToShow()), | 146 | QObject::connect(_depthMenu->menu(), SIGNAL(aboutToShow()), | ||
146 | SLOT(slotShowDepthMenu())); | 147 | SLOT(slotShowDepthMenu())); | ||
147 | QObject::connect(_colorMenu->menu(), SIGNAL(aboutToShow()), | 148 | QObject::connect(_colorMenu->menu(), SIGNAL(aboutToShow()), | ||
148 | SLOT(slotShowColorMenu())); | 149 | SLOT(slotShowColorMenu())); | ||
149 | 150 | | |||
150 | slotSettingsChanged(KGlobalSettings::SETTINGS_MOUSE); | 151 | // Both of these click signals are connected. Whether a single or | ||
dfaure: I thought there was an activated() signal to encapsulate this logic? | |||||
For QAbstractItemView and derived, yes, The item view here though is completely custom, though, so either TreeMapWidget or FSJob would need to look at the style option anyway. Trying to change the code as little as possible for the moment, although I agree that it would be cleaner to look at the option and emit a single activated() signal in TreeMapWidget. marten: For QAbstractItemView and derived, yes, The item view here though is completely custom… | |||||
151 | connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), | 152 | // double click activates an item is checked against the current | ||
152 | SLOT(slotSettingsChanged(int))); | 153 | // style setting when the click happens. | ||
154 | QObject::connect(_view, SIGNAL(clicked(TreeMapItem*)), | ||||
155 | _ext, SLOT(itemSingleClicked(TreeMapItem*))); | ||||
156 | QObject::connect(_view, SIGNAL(doubleClicked(TreeMapItem*)), | ||||
157 | _ext, SLOT(itemDoubleClicked(TreeMapItem*))); | ||||
153 | 158 | | |||
154 | QObject::connect(_view, SIGNAL(returnPressed(TreeMapItem*)), | 159 | QObject::connect(_view, SIGNAL(returnPressed(TreeMapItem*)), | ||
155 | _ext, SLOT(selected(TreeMapItem*))); | 160 | _ext, SLOT(selected(TreeMapItem*))); | ||
156 | QObject::connect(_view, SIGNAL(selectionChanged()), | 161 | QObject::connect(_view, SIGNAL(selectionChanged()), | ||
157 | this, SLOT(updateActions())); | 162 | this, SLOT(updateActions())); | ||
158 | QObject::connect(_view, | 163 | QObject::connect(_view, | ||
159 | SIGNAL(contextMenuRequested(TreeMapItem*,QPoint)), | 164 | SIGNAL(contextMenuRequested(TreeMapItem*,QPoint)), | ||
160 | this, | 165 | this, | ||
Show All 11 Lines | |||||
172 | //QAction* renameAction = m_actionCollection->addAction("rename"); | 177 | //QAction* renameAction = m_actionCollection->addAction("rename"); | ||
173 | //rename->setText(i18nc("@action:inmenu Edit", "Rename...")); | 178 | //rename->setText(i18nc("@action:inmenu Edit", "Rename...")); | ||
174 | //rename->setShortcut(Qt::Key_F2); | 179 | //rename->setShortcut(Qt::Key_F2); | ||
175 | 180 | | |||
176 | QAction *moveToTrashAction = actionCollection()->addAction(QStringLiteral("move_to_trash")); | 181 | QAction *moveToTrashAction = actionCollection()->addAction(QStringLiteral("move_to_trash")); | ||
177 | moveToTrashAction->setText(i18nc("@action:inmenu File", "Move to Trash")); | 182 | moveToTrashAction->setText(i18nc("@action:inmenu File", "Move to Trash")); | ||
178 | moveToTrashAction->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); | 183 | moveToTrashAction->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); | ||
179 | actionCollection()->setDefaultShortcut(moveToTrashAction, QKeySequence(QKeySequence::Delete)); | 184 | actionCollection()->setDefaultShortcut(moveToTrashAction, QKeySequence(QKeySequence::Delete)); | ||
180 | connect(moveToTrashAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), | 185 | connect(moveToTrashAction, SIGNAL(triggered()), _ext, SLOT(trash())); | ||
181 | _ext, SLOT(trash(Qt::MouseButtons,Qt::KeyboardModifiers))); | | |||
182 | 186 | | |||
183 | QAction *deleteAction = actionCollection()->addAction(QStringLiteral("delete")); | 187 | QAction *deleteAction = actionCollection()->addAction(QStringLiteral("delete")); | ||
184 | deleteAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete"))); | 188 | deleteAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete"))); | ||
185 | deleteAction->setText(i18nc("@action:inmenu File", "Delete")); | 189 | deleteAction->setText(i18nc("@action:inmenu File", "Delete")); | ||
186 | actionCollection()->setDefaultShortcut(deleteAction, QKeySequence(Qt::SHIFT | Qt::Key_Delete)); | 190 | actionCollection()->setDefaultShortcut(deleteAction, QKeySequence(Qt::SHIFT | Qt::Key_Delete)); | ||
187 | connect(deleteAction, SIGNAL(triggered()), _ext, SLOT(del())); | 191 | connect(deleteAction, SIGNAL(triggered()), _ext, SLOT(del())); | ||
188 | 192 | | |||
189 | QAction *editMimeTypeAction = actionCollection()->addAction(QStringLiteral("editMimeType")); | 193 | QAction *editMimeTypeAction = actionCollection()->addAction(QStringLiteral("editMimeType")); | ||
Show All 10 Lines | |||||
200 | 204 | | |||
201 | updateActions(); | 205 | updateActions(); | ||
202 | 206 | | |||
203 | setXMLFile(QStringLiteral("fsview_part.rc")); | 207 | setXMLFile(QStringLiteral("fsview_part.rc")); | ||
204 | } | 208 | } | ||
205 | 209 | | |||
206 | FSViewPart::~FSViewPart() | 210 | FSViewPart::~FSViewPart() | ||
207 | { | 211 | { | ||
208 | kDebug(90100) << "FSViewPart Destructor"; | 212 | qCDebug(FSVIEWLOG); | ||
209 | 213 | | |||
210 | delete _job; | 214 | delete _job; | ||
211 | _view->saveFSOptions(); | 215 | _view->saveFSOptions(); | ||
212 | } | 216 | } | ||
213 | 217 | | |||
214 | void FSViewPart::slotSettingsChanged(int category) | | |||
215 | { | | |||
216 | if (category != KGlobalSettings::SETTINGS_MOUSE) { | | |||
217 | return; | | |||
218 | } | | |||
219 | | ||||
220 | QObject::disconnect(_view, SIGNAL(clicked(TreeMapItem*)), | | |||
221 | _ext, SLOT(selected(TreeMapItem*))); | | |||
222 | QObject::disconnect(_view, SIGNAL(doubleClicked(TreeMapItem*)), | | |||
223 | _ext, SLOT(selected(TreeMapItem*))); | | |||
224 | | ||||
225 | if (_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) | | |||
226 | QObject::connect(_view, SIGNAL(clicked(TreeMapItem*)), | | |||
227 | _ext, SLOT(selected(TreeMapItem*))); | | |||
228 | else | | |||
229 | QObject::connect(_view, SIGNAL(doubleClicked(TreeMapItem*)), | | |||
230 | _ext, SLOT(selected(TreeMapItem*))); | | |||
231 | } | | |||
232 | | ||||
233 | void FSViewPart::showInfo() | 218 | void FSViewPart::showInfo() | ||
234 | { | 219 | { | ||
235 | QString info; | 220 | QString info; | ||
236 | info = i18n("FSView intentionally does not support automatic updates " | 221 | info = i18n("FSView intentionally does not support automatic updates " | ||
237 | "when changes are made to files or directories, " | 222 | "when changes are made to files or directories, " | ||
238 | "currently visible in FSView, from the outside.\n" | 223 | "currently visible in FSView, from the outside.\n" | ||
239 | "For details, see the 'Help/FSView Manual'."); | 224 | "For details, see the 'Help/FSView Manual'."); | ||
240 | 225 | | |||
Show All 16 Lines | |||||
257 | void FSViewPart::completedSlot(int dirs) | 242 | void FSViewPart::completedSlot(int dirs) | ||
258 | { | 243 | { | ||
259 | if (_job) { | 244 | if (_job) { | ||
260 | _job->progressSlot(100, dirs, QString()); | 245 | _job->progressSlot(100, dirs, QString()); | ||
261 | delete _job; | 246 | delete _job; | ||
262 | _job = nullptr; | 247 | _job = nullptr; | ||
263 | } | 248 | } | ||
264 | 249 | | |||
265 | KConfigGroup cconfig(_view->config(), "MetricCache"); | 250 | KConfigGroup cconfig = _view->config()->group("MetricCache"); | ||
266 | _view->saveMetric(&cconfig); | 251 | _view->saveMetric(&cconfig); | ||
267 | 252 | | |||
268 | emit completed(); | 253 | emit completed(); | ||
269 | } | 254 | } | ||
270 | 255 | | |||
271 | void FSViewPart::slotShowVisMenu() | 256 | void FSViewPart::slotShowVisMenu() | ||
272 | { | 257 | { | ||
273 | _visMenu->menu()->clear(); | 258 | _visMenu->menu()->clear(); | ||
Show All 15 Lines | |||||
289 | void FSViewPart::slotShowColorMenu() | 274 | void FSViewPart::slotShowColorMenu() | ||
290 | { | 275 | { | ||
291 | _colorMenu->menu()->clear(); | 276 | _colorMenu->menu()->clear(); | ||
292 | _view->addColorItems(_colorMenu->menu(), 1401); | 277 | _view->addColorItems(_colorMenu->menu(), 1401); | ||
293 | } | 278 | } | ||
294 | 279 | | |||
295 | bool FSViewPart::openFile() // never called since openUrl is reimplemented | 280 | bool FSViewPart::openFile() // never called since openUrl is reimplemented | ||
296 | { | 281 | { | ||
297 | kDebug(90100) << "FSViewPart::openFile " << localFilePath(); | 282 | qCDebug(FSVIEWLOG) << localFilePath(); | ||
298 | _view->setPath(localFilePath()); | 283 | _view->setPath(localFilePath()); | ||
299 | 284 | | |||
300 | return true; | 285 | return true; | ||
301 | } | 286 | } | ||
302 | 287 | | |||
303 | bool FSViewPart::openUrl(const QUrl &url) | 288 | bool FSViewPart::openUrl(const QUrl &url) | ||
304 | { | 289 | { | ||
305 | kDebug(90100) << "FSViewPart::openUrl " << url.path(); | 290 | qCDebug(FSVIEWLOG) << url.path(); | ||
306 | 291 | | |||
307 | if (!url.isValid()) { | 292 | if (!url.isValid()) { | ||
308 | return false; | 293 | return false; | ||
309 | } | 294 | } | ||
310 | if (!url.isLocalFile()) { | 295 | if (!url.isLocalFile()) { | ||
311 | return false; | 296 | return false; | ||
312 | } | 297 | } | ||
313 | 298 | | |||
314 | setUrl(url); | 299 | setUrl(url); | ||
315 | emit setWindowCaption(this->url().toDisplayString(QUrl::PreferLocalFile)); | 300 | emit setWindowCaption(this->url().toDisplayString(QUrl::PreferLocalFile)); | ||
316 | 301 | | |||
317 | _view->setPath(this->url().path()); | 302 | _view->setPath(this->url().path()); | ||
318 | 303 | | |||
319 | return true; | 304 | return true; | ||
320 | } | 305 | } | ||
321 | 306 | | |||
322 | bool FSViewPart::closeUrl() | 307 | bool FSViewPart::closeUrl() | ||
323 | { | 308 | { | ||
324 | kDebug(90100) << "FSViewPart::closeUrl "; | 309 | qCDebug(FSVIEWLOG); | ||
325 | 310 | | |||
326 | _view->stop(); | 311 | _view->stop(); | ||
327 | 312 | | |||
328 | return true; | 313 | return true; | ||
329 | } | 314 | } | ||
330 | 315 | | |||
331 | void FSViewPart::setNonStandardActionEnabled(const char *actionName, bool enabled) | 316 | void FSViewPart::setNonStandardActionEnabled(const char *actionName, bool enabled) | ||
332 | { | 317 | { | ||
Show All 31 Lines | 323 | { | |||
364 | emit _ext->selectionInfo(urls); | 349 | emit _ext->selectionInfo(urls); | ||
365 | 350 | | |||
366 | if (canCopy > 0) { | 351 | if (canCopy > 0) { | ||
367 | stateChanged(QStringLiteral("has_selection")); | 352 | stateChanged(QStringLiteral("has_selection")); | ||
368 | } else { | 353 | } else { | ||
369 | stateChanged(QStringLiteral("has_no_selection")); | 354 | stateChanged(QStringLiteral("has_no_selection")); | ||
370 | } | 355 | } | ||
371 | 356 | | |||
372 | kDebug(90100) << "FSViewPart::updateActions, deletable " << canDel; | 357 | qCDebug(FSVIEWLOG) << "deletable" << canDel; | ||
373 | } | 358 | } | ||
374 | 359 | | |||
375 | void FSViewPart::contextMenu(TreeMapItem * /*item*/, const QPoint &p) | 360 | void FSViewPart::contextMenu(TreeMapItem * /*item*/, const QPoint &p) | ||
376 | { | 361 | { | ||
377 | int canDel = 0, canCopy = 0, canMove = 0; | 362 | int canDel = 0, canCopy = 0, canMove = 0; | ||
378 | KFileItemList items; | 363 | KFileItemList items; | ||
379 | 364 | | |||
380 | foreach (TreeMapItem *i, _view->selection()) { | 365 | foreach (TreeMapItem *i, _view->selection()) { | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 454 | if (uiDelegate.askDeleteConfirmation(urls, | |||
471 | KIO::Job *job = KIO::del(urls); | 456 | KIO::Job *job = KIO::del(urls); | ||
472 | KJobWidgets::setWindow(job, _view); | 457 | KJobWidgets::setWindow(job, _view); | ||
473 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | 458 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | ||
474 | connect(job, SIGNAL(result(KJob*)), | 459 | connect(job, SIGNAL(result(KJob*)), | ||
475 | this, SLOT(refresh())); | 460 | this, SLOT(refresh())); | ||
476 | } | 461 | } | ||
477 | } | 462 | } | ||
478 | 463 | | |||
479 | void FSViewBrowserExtension::trash(Qt::MouseButtons, Qt::KeyboardModifiers modifiers) | 464 | void FSViewBrowserExtension::trash() | ||
480 | { | 465 | { | ||
481 | bool deleteNotTrash = ((modifiers & Qt::ShiftModifier) != 0); | 466 | bool deleteNotTrash = ((QGuiApplication::keyboardModifiers() & Qt::ShiftModifier) != 0); | ||
482 | if (deleteNotTrash) { | 467 | if (deleteNotTrash) { | ||
483 | del(); | 468 | del(); | ||
484 | } else { | 469 | } else { | ||
485 | KIO::JobUiDelegate uiDelegate; | 470 | KIO::JobUiDelegate uiDelegate; | ||
486 | uiDelegate.setWindow(_view); | 471 | uiDelegate.setWindow(_view); | ||
487 | const QList<QUrl> urls = _view->selectedUrls(); | 472 | const QList<QUrl> urls = _view->selectedUrls(); | ||
488 | if (uiDelegate.askDeleteConfirmation(urls, | 473 | if (uiDelegate.askDeleteConfirmation(urls, | ||
489 | KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { | 474 | KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { | ||
Show All 35 Lines | 503 | { | |||
525 | /* if commonParent is a file, update parent directory */ | 510 | /* if commonParent is a file, update parent directory */ | ||
526 | if (!((Inode *)commonParent)->isDir()) { | 511 | if (!((Inode *)commonParent)->isDir()) { | ||
527 | commonParent = commonParent->parent(); | 512 | commonParent = commonParent->parent(); | ||
528 | if (!commonParent) { | 513 | if (!commonParent) { | ||
529 | return; | 514 | return; | ||
530 | } | 515 | } | ||
531 | } | 516 | } | ||
532 | 517 | | |||
533 | kDebug(90100) << "FSViewPart::refreshing " | 518 | qCDebug(FSVIEWLOG) << "refreshing" | ||
534 | << ((Inode *)commonParent)->path() << endl; | 519 | << ((Inode *)commonParent)->path() << endl; | ||
535 | 520 | | |||
536 | _view->requestUpdate((Inode *)commonParent); | 521 | _view->requestUpdate((Inode *)commonParent); | ||
537 | } | 522 | } | ||
538 | 523 | | |||
524 | void FSViewBrowserExtension::itemSingleClicked(TreeMapItem *i) | ||||
525 | { | ||||
526 | if (_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) { | ||||
527 | selected(i); | ||||
528 | } | ||||
529 | } | ||||
530 | | ||||
531 | | ||||
532 | void FSViewBrowserExtension::itemDoubleClicked(TreeMapItem *i) | ||||
533 | { | ||||
534 | if (!_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) { | ||||
535 | selected(i); | ||||
536 | } | ||||
537 | } | ||||
538 | | ||||
539 | void FSViewBrowserExtension::selected(TreeMapItem *i) | 539 | void FSViewBrowserExtension::selected(TreeMapItem *i) | ||
540 | { | 540 | { | ||
541 | if (!i) { | 541 | if (!i) { | ||
542 | return; | 542 | return; | ||
543 | } | 543 | } | ||
544 | 544 | | |||
545 | QUrl url = QUrl::fromLocalFile(((Inode *)i)->path()); | 545 | QUrl url = QUrl::fromLocalFile(((Inode *)i)->path()); | ||
546 | emit openUrlRequest(url); | 546 | emit openUrlRequest(url); | ||
547 | } | 547 | } | ||
548 | 548 | | |||
549 | #include "fsview_part.moc" | 549 | #include "fsview_part.moc" |
I thought there was an activated() signal to encapsulate this logic?