Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kfileplacesview.cpp
Show All 15 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | 18 | | |||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "kfileplacesview.h" | 21 | #include "kfileplacesview.h" | ||
22 | #include "kfileplacesview_p.h" | 22 | #include "kfileplacesview_p.h" | ||
23 | 23 | | |||
24 | #include <QDir> | ||||
24 | #include <QTimeLine> | 25 | #include <QTimeLine> | ||
25 | #include <QTimer> | 26 | #include <QTimer> | ||
26 | #include <QPainter> | 27 | #include <QPainter> | ||
27 | #include <QAbstractItemDelegate> | 28 | #include <QAbstractItemDelegate> | ||
28 | #include <QKeyEvent> | 29 | #include <QKeyEvent> | ||
29 | #include <QApplication> | 30 | #include <QApplication> | ||
30 | #include <QMenu> | 31 | #include <QMenu> | ||
31 | #include <QScrollBar> | 32 | #include <QScrollBar> | ||
32 | 33 | | |||
shubham: Move this header up | |||||
33 | #include <QDebug> | 34 | #include <QDebug> | ||
34 | 35 | | |||
35 | #include <kconfig.h> | 36 | #include <kconfig.h> | ||
36 | #include <kconfiggroup.h> | 37 | #include <kconfiggroup.h> | ||
37 | #include <kdirnotify.h> | 38 | #include <kdirnotify.h> | ||
38 | #include <klocalizedstring.h> | 39 | #include <klocalizedstring.h> | ||
39 | #include <kmessagebox.h> | 40 | #include <kmessagebox.h> | ||
41 | #include <kmountpoint.h> | ||||
40 | #include <kpropertiesdialog.h> | 42 | #include <kpropertiesdialog.h> | ||
41 | #include <kio/emptytrashjob.h> | 43 | #include <kio/emptytrashjob.h> | ||
42 | #include <kio/jobuidelegate.h> | 44 | #include <kio/jobuidelegate.h> | ||
43 | #include <kjob.h> | 45 | #include <kjob.h> | ||
44 | #include <kjobwidgets.h> | 46 | #include <kjobwidgets.h> | ||
45 | #include <kcapacitybar.h> | 47 | #include <kcapacitybar.h> | ||
46 | #include <kdiskfreespaceinfo.h> | 48 | #include <kdiskfreespaceinfo.h> | ||
47 | #include <solid/storageaccess.h> | 49 | #include <solid/storageaccess.h> | ||
48 | #include <solid/storagedrive.h> | 50 | #include <solid/storagedrive.h> | ||
49 | #include <solid/storagevolume.h> | 51 | #include <solid/storagevolume.h> | ||
50 | #include <solid/opticaldrive.h> | 52 | #include <solid/opticaldrive.h> | ||
51 | #include <solid/opticaldisc.h> | 53 | #include <solid/opticaldisc.h> | ||
52 | 54 | | |||
shubham: Move the header up, to its appropriate position letter wise. | |||||
53 | #include "kfileplaceeditdialog_p.h" | 55 | #include "kfileplaceeditdialog_p.h" | ||
54 | #include "kfileplacesmodel.h" | 56 | #include "kfileplacesmodel.h" | ||
55 | 57 | | |||
56 | #define LATERAL_MARGIN 4 | 58 | #define LATERAL_MARGIN 4 | ||
57 | #define CAPACITYBAR_HEIGHT 6 | 59 | #define CAPACITYBAR_HEIGHT 6 | ||
58 | 60 | | |||
59 | class KFilePlacesViewDelegate : public QAbstractItemDelegate | 61 | class KFilePlacesViewDelegate : public QAbstractItemDelegate | ||
60 | { | 62 | { | ||
▲ Show 20 Lines • Show All 665 Lines • ▼ Show 20 Line(s) | 725 | { | |||
726 | if (!placesModel) { | 728 | if (!placesModel) { | ||
727 | return; | 729 | return; | ||
728 | } | 730 | } | ||
729 | 731 | | |||
730 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | 732 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | ||
731 | 733 | | |||
732 | QModelIndex index = indexAt(event->pos()); | 734 | QModelIndex index = indexAt(event->pos()); | ||
733 | const QString label = placesModel->text(index).replace(QLatin1Char('&'), QLatin1String("&&")); | 735 | const QString label = placesModel->text(index).replace(QLatin1Char('&'), QLatin1String("&&")); | ||
736 | const QUrl placeUrl = placesModel->url(index); | ||||
734 | 737 | | |||
735 | QMenu menu; | 738 | QMenu menu; | ||
736 | 739 | | |||
737 | QAction *edit = nullptr; | 740 | QAction *edit = nullptr; | ||
738 | QAction *hide = nullptr; | 741 | QAction *hide = nullptr; | ||
739 | QAction *emptyTrash = nullptr; | 742 | QAction *emptyTrash = nullptr; | ||
740 | QAction *eject = nullptr; | 743 | QAction *eject = nullptr; | ||
741 | QAction *teardown = nullptr; | 744 | QAction *teardown = nullptr; | ||
742 | QAction *add = nullptr; | 745 | QAction *add = nullptr; | ||
743 | QAction *mainSeparator = nullptr; | 746 | QAction *mainSeparator = nullptr; | ||
744 | QAction *hideSection = nullptr; | 747 | QAction *hideSection = nullptr; | ||
745 | QAction *properties = nullptr; | 748 | QAction *properties = nullptr; | ||
746 | QAction *mount = nullptr; | 749 | QAction *mount = nullptr; | ||
747 | 750 | | |||
748 | const bool clickOverHeader = delegate->pointIsHeaderArea(event->pos()); | 751 | const bool clickOverHeader = delegate->pointIsHeaderArea(event->pos()); | ||
749 | if (clickOverHeader) { | 752 | if (clickOverHeader) { | ||
750 | const KFilePlacesModel::GroupType type = placesModel->groupType(index); | 753 | const KFilePlacesModel::GroupType type = placesModel->groupType(index); | ||
751 | hideSection = menu.addAction(QIcon::fromTheme(QStringLiteral("hint")), i18n("Hide Section")); | 754 | hideSection = menu.addAction(QIcon::fromTheme(QStringLiteral("hint")), i18n("Hide Section")); | ||
752 | hideSection->setCheckable(true); | 755 | hideSection->setCheckable(true); | ||
753 | hideSection->setChecked(placesModel->isGroupHidden(type)); | 756 | hideSection->setChecked(placesModel->isGroupHidden(type)); | ||
754 | } | 757 | } | ||
755 | else if (index.isValid()) { | 758 | else if (index.isValid()) { | ||
756 | if (!placesModel->isDevice(index)) { | 759 | if (!placesModel->isDevice(index)) { | ||
757 | if (placesModel->url(index).toString() == QLatin1String("trash:/")) { | 760 | if (placeUrl.toString() == QLatin1String("trash:/")) { | ||
758 | emptyTrash = menu.addAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash")); | 761 | emptyTrash = menu.addAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash")); | ||
759 | KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); | 762 | KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); | ||
760 | emptyTrash->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); | 763 | emptyTrash->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); | ||
761 | menu.addSeparator(); | 764 | menu.addSeparator(); | ||
762 | } | 765 | } | ||
763 | add = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("Add Entry...")); | 766 | add = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("Add Entry...")); | ||
764 | mainSeparator = menu.addSeparator(); | 767 | mainSeparator = menu.addSeparator(); | ||
765 | } else { | 768 | } else { | ||
766 | eject = placesModel->ejectActionForIndex(index); | 769 | eject = placesModel->ejectActionForIndex(index); | ||
767 | if (eject != nullptr) { | 770 | if (eject != nullptr) { | ||
768 | eject->setParent(&menu); | 771 | eject->setParent(&menu); | ||
769 | menu.addAction(eject); | 772 | menu.addAction(eject); | ||
770 | } | 773 | } | ||
771 | 774 | | |||
772 | teardown = placesModel->teardownActionForIndex(index); | 775 | teardown = placesModel->teardownActionForIndex(index); | ||
773 | if (teardown != nullptr) { | 776 | if (teardown != nullptr) { | ||
777 | // Disable teardown option for root and home partitions | ||||
778 | bool teardownEnabled = placeUrl != QUrl::fromLocalFile(QDir::rootPath()); | ||||
779 | if (teardownEnabled) { | ||||
780 | KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(QDir::homePath()); | ||||
781 | if (mountPoint && placeUrl == QUrl::fromLocalFile(mountPoint->mountPoint())) { | ||||
782 | teardownEnabled = false; | ||||
783 | } | ||||
784 | } | ||||
785 | teardown->setEnabled(teardownEnabled); | ||||
786 | | ||||
774 | teardown->setParent(&menu); | 787 | teardown->setParent(&menu); | ||
775 | menu.addAction(teardown); | 788 | menu.addAction(teardown); | ||
776 | } | 789 | } | ||
777 | 790 | | |||
778 | if (placesModel->setupNeeded(index)) { | 791 | if (placesModel->setupNeeded(index)) { | ||
779 | mount = menu.addAction(QIcon::fromTheme(QStringLiteral("media-mount")), i18nc("@action:inmenu", "Mount")); | 792 | mount = menu.addAction(QIcon::fromTheme(QStringLiteral("media-mount")), i18nc("@action:inmenu", "Mount")); | ||
780 | } | 793 | } | ||
781 | 794 | | |||
782 | if (teardown != nullptr || eject != nullptr || mount != nullptr) { | 795 | if (teardown != nullptr || eject != nullptr || mount != nullptr) { | ||
783 | mainSeparator = menu.addSeparator(); | 796 | mainSeparator = menu.addSeparator(); | ||
784 | } | 797 | } | ||
785 | } | 798 | } | ||
786 | if (add == nullptr) { | 799 | if (add == nullptr) { | ||
787 | add = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("Add Entry...")); | 800 | add = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("Add Entry...")); | ||
788 | } | 801 | } | ||
789 | if (placesModel->url(index).isLocalFile()) { | 802 | if (placeUrl.isLocalFile()) { | ||
790 | properties = menu.addAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18n("Properties")); | 803 | properties = menu.addAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18n("Properties")); | ||
791 | } | 804 | } | ||
792 | if (!placesModel->isDevice(index)) { | 805 | if (!placesModel->isDevice(index)) { | ||
793 | edit = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-entry")), i18n("&Edit Entry '%1'...", label)); | 806 | edit = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-entry")), i18n("&Edit Entry '%1'...", label)); | ||
794 | } | 807 | } | ||
795 | 808 | | |||
796 | hide = menu.addAction(QIcon::fromTheme(QStringLiteral("hint")), i18n("&Hide Entry '%1'", label)); | 809 | hide = menu.addAction(QIcon::fromTheme(QStringLiteral("hint")), i18n("&Hide Entry '%1'", label)); | ||
797 | hide->setCheckable(true); | 810 | hide->setCheckable(true); | ||
Show All 34 Lines | 843 | if (emptyTrash && (result == emptyTrash)) { | |||
832 | KIO::JobUiDelegate uiDelegate; | 845 | KIO::JobUiDelegate uiDelegate; | ||
833 | uiDelegate.setWindow(window()); | 846 | uiDelegate.setWindow(window()); | ||
834 | if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { | 847 | if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { | ||
835 | KIO::Job* job = KIO::emptyTrash(); | 848 | KIO::Job* job = KIO::emptyTrash(); | ||
836 | KJobWidgets::setWindow(job, window()); | 849 | KJobWidgets::setWindow(job, window()); | ||
837 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | 850 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | ||
838 | } | 851 | } | ||
839 | } else if (properties && (result == properties)) { | 852 | } else if (properties && (result == properties)) { | ||
840 | KPropertiesDialog::showDialog(placesModel->url(index), this); | 853 | KPropertiesDialog::showDialog(placeUrl, this); | ||
841 | } else if (edit && (result == edit)) { | 854 | } else if (edit && (result == edit)) { | ||
842 | KBookmark bookmark = placesModel->bookmarkForIndex(index); | 855 | KBookmark bookmark = placesModel->bookmarkForIndex(index); | ||
843 | QUrl url = bookmark.url(); | 856 | QUrl url = bookmark.url(); | ||
844 | QString label = bookmark.text(); | 857 | QString label = bookmark.text(); | ||
845 | QString iconName = bookmark.icon(); | 858 | QString iconName = bookmark.icon(); | ||
846 | bool appLocal = !bookmark.metaDataItem(QStringLiteral("OnlyInApp")).isEmpty(); | 859 | bool appLocal = !bookmark.metaDataItem(QStringLiteral("OnlyInApp")).isEmpty(); | ||
847 | 860 | | |||
848 | if (KFilePlaceEditDialog::getInformation(true, url, label, | 861 | if (KFilePlaceEditDialog::getInformation(true, url, label, | ||
▲ Show 20 Lines • Show All 618 Lines • Show Last 20 Lines |
Move this header up