~mutse-young/ubuntu-docviewer-app/trunk

« back to all changes in this revision

Viewing changes to src/plugin/file-qml-plugin/documentmodel.cpp

  • Committer: Stefano Verzegnassi
  • Date: 2015-05-13 14:22:36 UTC
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: stefano92.100@gmail.com-20150513142236-izo5bs75a73zdu63
First prototype for sd-card read support

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include "documentmodel.h"
19
19
#include "fswatcher.h"
 
20
#include "qstorageinfo.h"
20
21
 
21
22
#include <QStandardPaths>
22
 
#include <QDirIterator>
23
 
 
24
23
#include <QDir>
25
24
#include <QFileInfo>
26
25
 
83
82
    QMimeDatabase db;
84
83
 
85
84
    QDateTime lastAccess = file.lastRead();
 
85
    QString absolutePath = file.absoluteFilePath();
86
86
 
87
87
    item.name = file.fileName();
88
 
    item.path = file.absoluteFilePath();
 
88
    item.path = absolutePath;
89
89
    item.mimetype = db.mimeTypeForFile(path).name();
90
90
    item.date = lastAccess.toMSecsSinceEpoch();
91
91
    item.size = file.size();
 
92
    item.isFromExternalStorage = absolutePath.startsWith("/media/");
92
93
 
93
94
    qint64 dateDiff = lastAccess.daysTo(now);
94
95
    if (dateDiff == 0)
129
130
    roles[DateRole] = "date";
130
131
    roles[DateDiffRole] = "dateDiff";
131
132
    roles[SizeRole] = "size";
 
133
    roles[IsFromExternalStorage] = "isFromExternalStorage";
132
134
 
133
135
    return roles;
134
136
}
173
175
        return item.dateDiff;
174
176
    case SizeRole:
175
177
        return item.size;
 
178
    case IsFromExternalStorage:
 
179
        return item.isFromExternalStorage;
176
180
    default:
177
181
        return 0;
178
182
    }
216
220
    if (!m_customDir.isEmpty())
217
221
        m_docsMonitor->addDirectory(m_customDir);
218
222
    else
 
223
        this->checkDefaultDirectories();
 
224
}
 
225
 
 
226
void DocumentModel::checkDefaultDirectories() {
 
227
    if (m_customDir.isEmpty()) {
219
228
        m_docsMonitor->addDirectory(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
 
229
 
 
230
        Q_FOREACH(const QStorageInfo &volume, QStorageInfo::mountedVolumes()) {
 
231
            QString rootPath = volume.rootPath();
 
232
 
 
233
            if (rootPath.startsWith("/media/")) {
 
234
                // In a Unix filesystem, names are case sentitive.
 
235
                // For that reason we need to check twice.
 
236
                QDir dir;
 
237
 
 
238
                dir.setPath(rootPath + "/Documents");
 
239
                if (dir.exists())
 
240
                    m_docsMonitor->addDirectory(dir.canonicalPath());
 
241
 
 
242
                dir.setPath(rootPath + "/documents");
 
243
                if (dir.exists())
 
244
                    m_docsMonitor->addDirectory(dir.canonicalPath());
 
245
            }
 
246
        }
 
247
    }
220
248
}
221
249
 
222
250
DocumentModel::~DocumentModel()