Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kdiroperator.cpp
Show All 22 Lines | |||||
23 | #include <kiconloader.h> | 23 | #include <kiconloader.h> | ||
24 | #include "kdirmodel.h" | 24 | #include "kdirmodel.h" | ||
25 | #include "kdiroperatordetailview_p.h" | 25 | #include "kdiroperatordetailview_p.h" | ||
26 | #include "kdirsortfilterproxymodel.h" | 26 | #include "kdirsortfilterproxymodel.h" | ||
27 | #include "kfileitem.h" | 27 | #include "kfileitem.h" | ||
28 | #include "kfilemetapreview_p.h" | 28 | #include "kfilemetapreview_p.h" | ||
29 | #include "kpreviewwidgetbase.h" | 29 | #include "kpreviewwidgetbase.h" | ||
30 | #include "knewfilemenu.h" | 30 | #include "knewfilemenu.h" | ||
31 | #include <kurlmimedata.h> | ||||
31 | #include "../pathhelpers_p.h" | 32 | #include "../pathhelpers_p.h" | ||
32 | 33 | | |||
33 | #include <config-kiofilewidgets.h> | 34 | #include <config-kiofilewidgets.h> | ||
34 | #include <defaults-kfile.h> // ConfigGroup, DefaultShowHidden, DefaultDirsFirst, DefaultSortReversed | 35 | #include <defaults-kfile.h> // ConfigGroup, DefaultShowHidden, DefaultDirsFirst, DefaultSortReversed | ||
35 | 36 | | |||
36 | #include <QApplication> | 37 | #include <QApplication> | ||
37 | #include <QHeaderView> | 38 | #include <QHeaderView> | ||
38 | #include <QListView> | 39 | #include <QListView> | ||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Line(s) | 175 | public: | |||
189 | Qt::SortOrder sortOrder() const; | 190 | Qt::SortOrder sortOrder() const; | ||
190 | void updateSorting(QDir::SortFlags sort); | 191 | void updateSorting(QDir::SortFlags sort); | ||
191 | 192 | | |||
192 | static bool isReadable(const QUrl &url); | 193 | static bool isReadable(const QUrl &url); | ||
193 | bool isSchemeSupported(const QString &scheme) const; | 194 | bool isSchemeSupported(const QString &scheme) const; | ||
194 | 195 | | |||
195 | KFile::FileView allViews(); | 196 | KFile::FileView allViews(); | ||
196 | 197 | | |||
198 | QMetaObject::Connection m_connection; | ||||
199 | | ||||
197 | // private slots | 200 | // private slots | ||
198 | void _k_slotDetailedView(); | 201 | void _k_slotDetailedView(); | ||
199 | void _k_slotSimpleView(); | 202 | void _k_slotSimpleView(); | ||
200 | void _k_slotTreeView(); | 203 | void _k_slotTreeView(); | ||
201 | void _k_slotDetailedTreeView(); | 204 | void _k_slotDetailedTreeView(); | ||
202 | void _k_slotToggleHidden(bool); | 205 | void _k_slotToggleHidden(bool); | ||
203 | void _k_togglePreview(bool); | 206 | void _k_togglePreview(bool); | ||
204 | void _k_toggleInlinePreviews(bool); | 207 | void _k_toggleInlinePreviews(bool); | ||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Line(s) | 363 | { | |||
409 | // action stuff | 412 | // action stuff | ||
410 | setupActions(); | 413 | setupActions(); | ||
411 | setupMenu(); | 414 | setupMenu(); | ||
412 | 415 | | |||
413 | d->sorting = QDir::NoSort; //so updateSorting() doesn't think nothing has changed | 416 | d->sorting = QDir::NoSort; //so updateSorting() doesn't think nothing has changed | ||
414 | d->updateSorting(QDir::Name | QDir::DirsFirst); | 417 | d->updateSorting(QDir::Name | QDir::DirsFirst); | ||
415 | 418 | | |||
416 | setFocusPolicy(Qt::WheelFocus); | 419 | setFocusPolicy(Qt::WheelFocus); | ||
420 | setAcceptDrops(true); | ||||
apol: This default change should be documented. | |||||
meven: Not sure I have done this correctly. | |||||
ngraham: Yep, I'd say so now. | |||||
meven: Any idea where I should add this information ?
An example would suffice. | |||||
You already did, in the inline function documentation in src/filewidgets/kdiroperator.h ngraham: You already did, in the inline function documentation in `src/filewidgets/kdiroperator.h` | |||||
417 | } | 421 | } | ||
418 | 422 | | |||
419 | KDirOperator::~KDirOperator() | 423 | KDirOperator::~KDirOperator() | ||
420 | { | 424 | { | ||
421 | resetCursor(); | 425 | resetCursor(); | ||
422 | disconnect(d->dirLister, nullptr, this, nullptr); | 426 | disconnect(d->dirLister, nullptr, this, nullptr); | ||
423 | delete d; | 427 | delete d; | ||
424 | } | 428 | } | ||
▲ Show 20 Lines • Show All 949 Lines • ▼ Show 20 Line(s) | 1377 | if (evt->delta() > 0) { | |||
1374 | setIconsZoom(d->iconsZoom + 10); | 1378 | setIconsZoom(d->iconsZoom + 10); | ||
1375 | } else { | 1379 | } else { | ||
1376 | setIconsZoom(d->iconsZoom - 10); | 1380 | setIconsZoom(d->iconsZoom - 10); | ||
1377 | } | 1381 | } | ||
1378 | return true; | 1382 | return true; | ||
1379 | } | 1383 | } | ||
1380 | } | 1384 | } | ||
1381 | break; | 1385 | break; | ||
1386 | case QEvent::DragEnter: { | ||||
1387 | // Accepts drops of one file or folder only | ||||
1388 | QDragEnterEvent *evt = static_cast<QDragEnterEvent *>(event); | ||||
1389 | const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(evt->mimeData()); | ||||
1390 | // only one file/folder can be dropped at the moment | ||||
1391 | event->setAccepted(urls.size() == 1); | ||||
1392 | } | ||||
1393 | break; | ||||
1394 | case QEvent::Drop: { | ||||
1395 | QDropEvent *evt = static_cast<QDropEvent *>(event); | ||||
1396 | const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(evt->mimeData(), KUrlMimeData::DecodeOptions::PreferLocalUrls); | ||||
1397 | | ||||
1398 | const QUrl url = urls.constFirst(); | ||||
1399 | | ||||
1400 | // stat the url to get details | ||||
1401 | KIO::StatJob *job = KIO::stat(url, KIO::HideProgressInfo); | ||||
1402 | job->exec(); | ||||
1403 | | ||||
apol: .constFirst() maybe reads better? | |||||
1404 | this->setFocus(); | ||||
ngraham: `this->` not needed | |||||
1405 | | ||||
elvisangelaccio: Please use descriptive variable names also here. | |||||
1406 | KIO::UDSEntry entry = job->statResult(); | ||||
1407 | | ||||
QRegExp should be avoid in new code, can you try to use QRegularExpression instead? elvisangelaccio: QRegExp should be avoid in new code, can you try to use QRegularExpression instead? | |||||
1408 | if (entry.isDir()) { | ||||
1409 | // if this was a directory | ||||
1410 | setUrl(url, false); | ||||
1411 | } else { | ||||
1412 | // if the current url is not known | ||||
ngraham: Comment seems unnecessary; the code is clear enough | |||||
1413 | if (d->dirLister->findByUrl(url).isNull()) { | ||||
1414 | setUrl(url.adjusted(QUrl::RemoveFilename), false); | ||||
1415 | | ||||
1416 | // Will set the current item once loading has finished | ||||
1417 | auto urlSetterClosure = [this, url](){ | ||||
1418 | this->setCurrentItem(url); | ||||
ngraham: `this->` not needed | |||||
1419 | QObject::disconnect(d->m_connection); | ||||
1420 | }; | ||||
1421 | d->m_connection = connect(this, &KDirOperator::finishedLoading, this, urlSetterClosure); | ||||
apol: maybe call the function urlSetter? | |||||
1422 | } else { | ||||
1423 | this->setCurrentItem(url); | ||||
ngraham: `this->` not needed | |||||
1424 | } | ||||
1425 | } | ||||
1426 | evt->accept(); | ||||
1427 | } | ||||
1428 | break; | ||||
1382 | default: | 1429 | default: | ||
1383 | break; | 1430 | break; | ||
1384 | } | 1431 | } | ||
1385 | 1432 | | |||
1386 | return QWidget::eventFilter(watched, event); | 1433 | return QWidget::eventFilter(watched, event); | ||
1387 | } | 1434 | } | ||
1388 | 1435 | | |||
1389 | bool KDirOperator::Private::checkPreviewInternal() const | 1436 | bool KDirOperator::Private::checkPreviewInternal() const | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 1500 | if (KFile::isDetailView(viewKind) || KFile::isTreeView(viewKind) || KFile::isDetailTreeView(viewKind)) { | |||
1456 | itemView = detailView; | 1503 | itemView = detailView; | ||
1457 | } else { | 1504 | } else { | ||
1458 | itemView = new KDirOperatorIconView(this, parent); | 1505 | itemView = new KDirOperatorIconView(this, parent); | ||
1459 | } | 1506 | } | ||
1460 | 1507 | | |||
1461 | return itemView; | 1508 | return itemView; | ||
1462 | } | 1509 | } | ||
1463 | 1510 | | |||
1464 | void KDirOperator::setAcceptDrops(bool b) | 1511 | void KDirOperator::setAcceptDrops(bool acceptsDrops) | ||
1465 | { | 1512 | { | ||
1466 | // TODO: | 1513 | QWidget::setAcceptDrops(acceptsDrops); | ||
1467 | //if (d->fileView) | 1514 | if (view()) { | ||
1468 | // d->fileView->widget()->setAcceptDrops(b); | 1515 | view()->setAcceptDrops(acceptsDrops); | ||
1469 | QWidget::setAcceptDrops(b); | 1516 | if (acceptsDrops) { | ||
1517 | view()->installEventFilter(this); | ||||
apol: Initial this-> isn't necessary, just `view()`.
| |||||
1518 | } else { | ||||
1519 | view()->removeEventFilter(this); | ||||
1520 | } | ||||
1521 | } | ||||
1470 | } | 1522 | } | ||
1471 | 1523 | | |||
1472 | void KDirOperator::setDropOptions(int options) | 1524 | void KDirOperator::setDropOptions(int options) | ||
1473 | { | 1525 | { | ||
1474 | d->dropOptions = options; | 1526 | d->dropOptions = options; | ||
1475 | // TODO: | 1527 | // TODO: | ||
1476 | //if (d->fileView) | 1528 | //if (d->fileView) | ||
1477 | // d->fileView->setDropOptions(options); | 1529 | // d->fileView->setDropOptions(options); | ||
Show All 20 Lines | 1533 | { | |||
1498 | } | 1550 | } | ||
1499 | 1551 | | |||
1500 | d->viewKind = static_cast<int>(viewKind); | 1552 | d->viewKind = static_cast<int>(viewKind); | ||
1501 | viewKind = static_cast<KFile::FileView>(d->viewKind); | 1553 | viewKind = static_cast<KFile::FileView>(d->viewKind); | ||
1502 | 1554 | | |||
1503 | QAbstractItemView *newView = createView(this, viewKind); | 1555 | QAbstractItemView *newView = createView(this, viewKind); | ||
1504 | setView(newView); | 1556 | setView(newView); | ||
1505 | 1557 | | |||
1558 | if (this->acceptDrops()) { | ||||
ngraham: `this->` not needed | |||||
1559 | newView->setAcceptDrops(true); | ||||
1560 | newView->installEventFilter(this); | ||||
1561 | } | ||||
1562 | | ||||
1506 | d->_k_togglePreview(preview); | 1563 | d->_k_togglePreview(preview); | ||
1507 | } | 1564 | } | ||
1508 | 1565 | | |||
1509 | KFile::FileView KDirOperator::viewMode() const | 1566 | KFile::FileView KDirOperator::viewMode() const | ||
1510 | { | 1567 | { | ||
1511 | return static_cast<KFile::FileView>(d->viewKind); | 1568 | return static_cast<KFile::FileView>(d->viewKind); | ||
1512 | } | 1569 | } | ||
1513 | 1570 | | |||
▲ Show 20 Lines • Show All 1171 Lines • Show Last 20 Lines |
This default change should be documented.