~nskaggs/ubuntu-filemanager-app/fix-ap-item-renames

« back to all changes in this revision

Viewing changes to src/plugin/folderlistmodel/dirmodel.cpp

Bug 1347010: UI for only displaying files in MTP directories. For now, "Show all files" is always visible at start and non-MTP directories are not viewable. After clicking "Show all files", all files are shown.

TODO:
 - "Show all files" only when user has set PIN/password, if not all files are automatically shown
 - When "Show all files" clicked query PIN/password from user and if it's valid only then display all files

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
#include <QMetaType>
62
62
#include <QDateTime>
63
63
#include <QMimeType>
 
64
#include <QStandardPaths>
64
65
 
65
66
#if defined(REGRESSION_TEST_FOLDERLISTMODEL)
66
67
# include <QColor>
67
68
# include <QBrush>
68
69
#endif
69
70
 
70
 
 
 
71
#include <array>
71
72
 
72
73
 
73
74
 
80
81
 
81
82
namespace {
82
83
    QHash<QByteArray, int> roleMapping;
 
84
    QList<QString> mtpDirectories;
 
85
 
 
86
    std::array<QStandardPaths::StandardLocation, 5> mtpStandardLocations = {
 
87
        QStandardPaths::DocumentsLocation,
 
88
        QStandardPaths::DownloadLocation,
 
89
        QStandardPaths::MusicLocation,
 
90
        QStandardPaths::PicturesLocation,
 
91
        QStandardPaths::MoviesLocation
 
92
    };
 
93
 
 
94
    void buildMTPDirectories() {
 
95
        mtpDirectories.clear();
 
96
        foreach (const QStandardPaths::StandardLocation &standardLocation, mtpStandardLocations) {
 
97
            QStringList locations = QStandardPaths::standardLocations(standardLocation);
 
98
 
 
99
            foreach (const QString &location, locations) {
 
100
                mtpDirectories << location;
 
101
            }
 
102
        }
 
103
    }
83
104
}
84
105
 
85
106
 
106
127
    , mIsRecursive(false)
107
128
    , mReadsMediaMetadata(false)
108
129
    , mShowHiddenFiles(false)
 
130
    , mShowNonMTPPaths(true)
109
131
    , mSortBy(SortByName)
110
132
    , mSortOrder(SortAscending)
111
133
    , mCompareFunction(0)  
452
474
    }    
453
475
}
454
476
 
 
477
 
 
478
bool DirModel::isMTPPath(const QString &path) const {
 
479
    if (mtpDirectories.isEmpty()) {
 
480
        buildMTPDirectories();
 
481
    }
 
482
    foreach (const QString &mtpDirectory, mtpDirectories) {
 
483
        if (path == mtpDirectory) return true;
 
484
        // Returns true for any file/folder inside MTP directory
 
485
        if (path.startsWith(mtpDirectory + "/")) return true;
 
486
    }
 
487
 
 
488
    return false;
 
489
}
 
490
 
455
491
void DirModel::onItemsAdded(const DirItemInfoList &newFiles)
456
492
{
457
493
#if DEBUG_MESSAGES
474
510
            }
475
511
        }
476
512
 
 
513
        if (!mShowNonMTPPaths) {
 
514
            doAdd = isMTPPath(fi.absoluteFilePath());
 
515
        }
 
516
 
477
517
        if (!doAdd)
478
518
            continue;
479
519
 
990
1030
    }
991
1031
}
992
1032
 
 
1033
bool DirModel::getShowNonMTPPaths() const
 
1034
{
 
1035
    return mShowNonMTPPaths;
 
1036
}
 
1037
 
 
1038
 
 
1039
void DirModel::setShowNonMTPPaths(bool show)
 
1040
{
 
1041
    if (show != mShowNonMTPPaths)
 
1042
    {
 
1043
        mShowNonMTPPaths = show;
 
1044
        refresh();
 
1045
        emit showNonMTPPathsChanged();
 
1046
    }
 
1047
}
 
1048
 
993
1049
 
994
1050
void DirModel::toggleShowDirectories()
995
1051
{