MauiKit File Browsing

fmlist.cpp
1/*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2018 camilo higuita <milo.h@aol.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "fmlist.h"
20#include "fm.h"
21#include "tagging.h"
22
23#ifdef COMPONENT_SYNCING
24#include "syncing.h"
25#endif
26
27#include <QFuture>
28#include <QThread>
29#include <QtConcurrent/QtConcurrentRun>
30#include <QtConcurrent>
31
32#include <QClipboard>
33#include <QGuiApplication>
34
35#include <KLocalizedString>
36
38 : MauiList(parent)
39 , fm(new FM(this))
40{
41 qRegisterMetaType<FMList *>("const FMList*"); // this is needed for QML to know of FMList in the search method
43 if (this->path == res.path) {
44 this->assignList(res.content);
45 }
46 });
47
48 connect(this->fm, &FM::pathContentReady, [this](QUrl) {
49 Q_EMIT this->preListChanged();
50 this->sortList();
51 this->setStatus({PathStatus::STATUS_CODE::READY, this->list.isEmpty() ? i18n("Nothing here!") : QStringLiteral(""), this->list.isEmpty() ? i18n("This place seems to be empty") : QStringLiteral(""), this->list.isEmpty() ? QStringLiteral("folder-add") : QStringLiteral(""), this->list.isEmpty(), true});
52 Q_EMIT this->postListChanged();
53 Q_EMIT this->countChanged();
54 });
55
56 connect(this->fm, &FM::pathContentItemsChanged, [this](QVector<QPair<FMH::MODEL, FMH::MODEL>> res) {
57 for (const auto &item : std::as_const(res)) {
58 const auto index = this->indexOf(FMH::MODEL_KEY::PATH, item.first[FMH::MODEL_KEY::PATH]);
59
60 if (index >= this->list.size() || index < 0)
61 return;
62
63 this->list[index] = item.second;
64 Q_EMIT this->updateModel(index, FMH::modelRoles(item.second));
65 }
66 });
67
69 if (res.path != this->path)
70 return;
71
72 this->appendToList(res.content);
73 });
74
76 if (res.path != this->path)
77 return;
78
79 if (!FMH::fileExists(res.path)) {
80 this->setStatus({PathStatus::STATUS_CODE::ERROR, i18n("Error"), i18n("This URL cannot be listed"), QStringLiteral("documentinfo"), true, false});
81 return;
82 }
83
84 for (const auto &item : std::as_const(res.content)) {
85 const auto index = this->indexOf(FMH::MODEL_KEY::PATH, item[FMH::MODEL_KEY::PATH]);
86 qDebug() << "SUPOSSED TO REMOVED THIS FORM THE LIST" << index << this->list.count() << item[FMH::MODEL_KEY::PATH];
87
88 this->remove(index);
89 }
90
91 this->setStatus({PathStatus::STATUS_CODE::READY, this->list.isEmpty() ? i18n("Nothing here!") : QStringLiteral(""), this->list.isEmpty() ? i18n("This place seems to be empty") : QStringLiteral(""), this->list.isEmpty() ? QStringLiteral("folder-add") : QStringLiteral(""), this->list.isEmpty(), true});
92 });
93
94 connect(this->fm, &FM::warningMessage, [this](const QString &message) {
95 Q_EMIT this->warning(message);
96 });
97
98 connect(this->fm, &FM::loadProgress, [this](const int &percent) {
99 Q_EMIT this->progress(percent);
100 });
101
102 connect(this->fm, &FM::pathContentChanged, [this](const QUrl &path) {
103 qDebug() << "FOLDER PATH CHANGED" << path;
104 if (path != this->path)
105 return;
106 this->sortList();
107 });
108
109 connect(this->fm, &FM::newItem, [this](const FMH::MODEL &item, const QUrl &url) {
110 if (this->path == url) {
111 Q_EMIT this->preItemAppended();
112 this->list << item;
113 Q_EMIT this->postItemAppended();
114 Q_EMIT this->countChanged();
115 }
116 });
117
118 connect(Tagging::getInstance(), &Tagging::urlTagged, [this](QString, QString tag)
119 {
120 if(this->getPathType() == FMList::PATHTYPE::TAGS_PATH)
121 {
122 const auto url = this->path.toString();
123 if(url.endsWith(tag))
124 {
125 this->refresh();
126 }
127 }
128 });
129
130 connect(Tagging::getInstance(), &Tagging::tagged, [this](QVariantMap)
131 {
132 if(this->pathType == PATHTYPE::TAGS_PATH)
133 {
134 this->refresh();
135 }
136 });
137
138 connect(Tagging::getInstance(), &Tagging::tagRemoved, [this](QString)
139 {
140 if(this->pathType == PATHTYPE::TAGS_PATH)
141 {
142 this->refresh();
143 }
144 });
145}
146
147void FMList::assignList(const FMH::MODEL_LIST &list)
148{
149 Q_EMIT this->preListChanged();
150 this->list = list;
151 this->sortList();
152 this->setStatus({PathStatus::STATUS_CODE::READY, this->list.isEmpty() ? i18n("Nothing here!") : QStringLiteral(""), this->list.isEmpty() ? i18n("This place seems to be empty") : QStringLiteral(""), this->list.isEmpty() ? QStringLiteral("folder-add") : QStringLiteral(""), this->list.isEmpty(), true});
153 Q_EMIT this->postListChanged();
154 Q_EMIT this->countChanged();
155}
156
157void FMList::appendToList(const FMH::MODEL_LIST &list)
158{
159 Q_EMIT this->preItemsAppended(list.size());
160 this->list << list;
161 Q_EMIT this->postItemAppended();
162 Q_EMIT this->countChanged();
163}
164
165void FMList::clear()
166{
167 Q_EMIT this->preListChanged();
168 this->list.clear();
169 Q_EMIT this->postListChanged();
170 Q_EMIT this->countChanged();
171}
172
173FMH::MODEL_LIST FMList::getTagContent(const QString &tag, const QStringList &filters)
174{
175 if (tag.isEmpty()) {
176 return Tagging::getInstance()->getTags();
177 } else {
178 FMH::MODEL_LIST content;
179 const auto urls = Tagging::getInstance()->getTagUrls(tag, filters, false);
180 for (const auto &url : urls) {
181 content << FMStatic::getFileInfoModel(url);
182 }
183
184 return content;
185 }
186}
187
188void FMList::setList()
189{
190 qDebug() << "PATHTYPE FOR URL" << pathType << this->path.toString() << this->filters << this;
191
192 if(this->path.isEmpty() || !m_autoLoad)
193 {
194 return;
195 }
196
197 this->clear();
198
199 switch (this->pathType)
200 {
201 case FMList::PATHTYPE::TAGS_PATH:
202 this->assignList(getTagContent(this->path.fileName(), QStringList() << this->filters << FMStatic::FILTER_LIST[static_cast<FMStatic::FILTER_TYPE>(this->filterType)]));
203 break; // SYNC
204
205 case FMList::PATHTYPE::CLOUD_PATH:
206 this->fm->getCloudServerContent(this->path, this->filters, this->cloudDepth);
207 break; // ASYNC
208
209 default: {
210 const bool exists = this->path.isLocalFile() ? FMH::fileExists(this->path) : true;
211 if (!exists)
212 this->setStatus({PathStatus::STATUS_CODE::ERROR, i18n("Error"), i18n("This URL cannot be listed"), QStringLiteral("documentinfo"), this->list.isEmpty(), exists});
213 else {
214 this->fm->getPathContent(this->path, this->hidden, this->onlyDirs, QStringList() << this->filters << FMStatic::FILTER_LIST[static_cast<FMStatic::FILTER_TYPE>(this->filterType)]);
215 }
216 break; // ASYNC
217 }
218 }
219}
220
221void FMList::reset()
222{
223 this->setList();
224}
225
227{
228 return this->list;
229}
230
231FMList::SORTBY FMList::getSortBy() const
232{
233 return this->sort;
234}
235
236void FMList::setSortBy(const FMList::SORTBY &key)
237{
238 if (this->sort == key)
239 return;
240
241 this->sort = key;
242 Q_EMIT this->sortByChanged();
243}
244
245void FMList::sortList()
246{
247 const FMH::MODEL_KEY key = static_cast<FMH::MODEL_KEY>(this->sort);
248 auto it = this->list.begin();
249
250 const auto sortFunc = [key](const FMH::MODEL &e1, const FMH::MODEL &e2) -> bool
251 {
252 switch (key) {
253 case FMH::MODEL_KEY::SIZE: {
254 if (e1[key].toDouble() > e2[key].toDouble())
255 return true;
256 break;
257 }
258
259 case FMH::MODEL_KEY::ADDDATE:
260 case FMH::MODEL_KEY::MODIFIED:
261 case FMH::MODEL_KEY::DATE: {
262 auto currentTime = QDateTime::currentDateTime();
263
264 auto date1 = QDateTime::fromString(e1[key], Qt::TextDate);
265 auto date2 = QDateTime::fromString(e2[key], Qt::TextDate);
266
267 if (date1.secsTo(currentTime) < date2.secsTo(currentTime))
268 return true;
269
270 break;
271 }
272
273 case FMH::MODEL_KEY::MIME:
274 case FMH::MODEL_KEY::LABEL: {
275 const auto str1 = QString(e1[key]).toLower();
276 const auto str2 = QString(e2[key]).toLower();
277
278 if (str1 < str2)
279 return true;
280 break;
281 }
282
283 default:
284 if (e1[key] < e2[key])
285 return true;
286 }
287
288 return false;
289 };
290
291 if (this->foldersFirst) {
292
293 it = std::partition(this->list.begin(),
294 this->list.end(),
295 [](const FMH::MODEL &e1) -> bool {
296 return e1[FMH::MODEL_KEY::MIME] == QStringLiteral("inode/directory");
297 });
298
299 if(this->list.begin() != it)
300 {
301 std::sort(this->list.begin(), it, sortFunc);
302 }
303 }
304
305 if(it != this->list.end())
306 {
307 std::sort(it, this->list.end(), sortFunc);
308 }
309}
310
311QString FMList::getPathName() const
312{
313 return this->pathName;
314}
315
316QString FMList::getPath() const
317{
318 return this->path.toString();
319}
320
321void FMList::setPath(const QString &path)
322{
324
325 if (this->path == path_)
326 return;
327
328 this->path = path_;
329 m_navHistory.appendPath(this->path);
330
331 this->setStatus({PathStatus::STATUS_CODE::LOADING, i18n("Loading content"), i18n("Almost ready!"), QStringLiteral("view-refresh"), true, false});
332
333 const auto __scheme = this->path.scheme();
334 this->pathName = QDir(this->path.toLocalFile()).dirName();
335
337 this->pathType = FMList::PATHTYPE::CLOUD_PATH;
338
340 this->pathType = FMList::PATHTYPE::APPS_PATH;
341
343 this->pathType = FMList::PATHTYPE::TAGS_PATH;
344 this->pathName = this->path.path();
345
347 this->pathType = FMList::PATHTYPE::TRASH_PATH;
348 this->pathName = QStringLiteral("Trash");
349
351 this->pathType = FMList::PATHTYPE::PLACES_PATH;
352
354 this->pathType = FMList::PATHTYPE::MTP_PATH;
355
357 this->pathType = FMList::PATHTYPE::FISH_PATH;
358
360 this->pathType = FMList::PATHTYPE::REMOTE_PATH;
361
363 this->pathType = FMList::PATHTYPE::DRIVES_PATH;
364 } else {
365 this->pathType = FMList::PATHTYPE::OTHER_PATH;
366 }
367
368 Q_EMIT this->pathNameChanged();
369 Q_EMIT this->pathTypeChanged();
370 Q_EMIT this->pathChanged();
371}
372
373FMList::PATHTYPE FMList::getPathType() const
374{
375 return this->pathType;
376}
377
378QStringList FMList::getFilters() const
379{
380 return this->filters;
381}
382
383void FMList::setFilters(const QStringList &filters)
384{
385 if (this->filters == filters)
386 return;
387
388 this->filters = filters;
389
390 Q_EMIT this->filtersChanged();
391}
392
393void FMList::resetFilters()
394{
395 this->setFilters(QStringList());
396}
397
398FMList::FILTER FMList::getFilterType() const
399{
400 return this->filterType;
401}
402
403void FMList::setFilterType(const FMList::FILTER &type)
404{
405 if (this->filterType == type)
406 return;
407
408 this->filterType = type;
409
410 Q_EMIT this->filterTypeChanged();
411}
412
413void FMList::resetFilterType()
414{
415 this->setFilterType(FMList::FILTER::NONE);
416}
417
418bool FMList::getHidden() const
419{
420 return this->hidden;
421}
422
423void FMList::setHidden(const bool &state)
424{
425 if (this->hidden == state)
426 return;
427
428 this->hidden = state;
429 Q_EMIT this->hiddenChanged();
430}
431
432bool FMList::getOnlyDirs() const
433{
434 return this->onlyDirs;
435}
436
437void FMList::setOnlyDirs(const bool &state)
438{
439 if (this->onlyDirs == state)
440 return;
441
442 this->onlyDirs = state;
443
444 Q_EMIT this->onlyDirsChanged();
445}
446
448{
449 Q_EMIT this->pathChanged();
450}
451
452void FMList::createDir(const QString &name)
453{
454 if(m_readOnly)
455 return;
456
457 if (this->pathType == FMList::PATHTYPE::CLOUD_PATH) {
458#ifdef COMPONENT_SYNCING
459 this->fm->createCloudDir(QString(this->path.toString()).replace(FMStatic::PATHTYPE_SCHEME[FMStatic::PATHTYPE_KEY::CLOUD_PATH] + "/" + this->fm->sync->getUser(), ""), name);
460#endif
461 } else {
462 FMStatic::createDir(this->path, name);
463 }
464}
465
467{
468 if(m_readOnly)
469 return;
470
471 FMStatic::createFile(this->path, name);
472}
473
474void FMList::renameFile(const QString& url, const QString& newName)
475{
476 if(m_readOnly)
477 return;
478
479 FMStatic::rename(QUrl(url), newName);
480}
481
483{
484 if(m_readOnly)
485 return;
486
488}
489
491{
492 if(m_readOnly)
493 return;
494
496}
497
499{
500 if(m_readOnly)
501 return;
502
503 FMStatic::createSymlink(QUrl(url), this->path);
504}
505
506bool FMList::saveImageFile(const QImage& image)
507{
508 QString fileName = QString(QStringLiteral("%1/pasted_image-0.%2")).arg(path.toLocalFile(), QStringLiteral("png"));
509
510 int idx = 1;
511 while ( QFile::exists( fileName ) )
512 {
513 fileName = QString(QStringLiteral("%1/pasted_image-%2.%3")).arg(path.toLocalFile(), QString::number(idx), QStringLiteral("png"));
514 idx++;
515 }
516
517 return image.save(fileName);
518}
519
520bool FMList::saveTextFile(const QString& data, const QString &format)
521{
522 QString fileName = QString(QStringLiteral("%1/pasted_text-0.%2")).arg(path.toLocalFile(), format);
523
524 int idx = 1;
525 while ( QFile::exists( fileName ) )
526 {
527 fileName = QString(QStringLiteral("%1/pasted_text-%2.%3")).arg(path.toLocalFile(), QString::number(idx), format);
528 idx++;
529 }
530
531 QFile file(fileName);
532
533 if (file.open(QIODevice::ReadWrite))
534 {
535 QTextStream out(&file);
536 out << data;
537 file.close();
538 return true;
539 }
540
541 return false;
542}
543
545{
546 if(m_readOnly)
547 return;
548
549 const QClipboard *clipboard = QGuiApplication::clipboard();
550 const QMimeData *mimeData = clipboard->mimeData();
551
552 if(!mimeData)
553 {
554 qWarning() << "Could not get mime data from the clipboard";
555 return;
556 }
557
558 if (mimeData->hasImage())
559 {
560 saveImageFile(qvariant_cast<QImage>(mimeData->imageData()));
561 } else if (mimeData->hasUrls())
562 {
563 const QByteArray a = mimeData->data(QStringLiteral("application/x-kde-cutselection"));
564 const bool cut = (!a.isEmpty() && a.at(0) == '1');
565
566 if(cut)
567 {
568 cutInto(QUrl::toStringList(mimeData->urls()));
569 // mimeData->clear();
570 }else
571 {
572 copyInto(QUrl::toStringList(mimeData->urls()));
573 }
574
575 } else if (mimeData->hasText())
576 {
577 saveTextFile(mimeData->text(), QStringLiteral("txt"));
578 } else
579 {
580 qWarning() << "Unexpected mime type from clipboard content for performing a paste";
581 }
582}
583
585{
586 const QClipboard *clipboard = QGuiApplication::clipboard();
587 const QMimeData *mimeData = clipboard->mimeData();
588
589 if(!mimeData)
590 {
591 qWarning() << "Could not get mime data from the clipboard";
592 return false;
593 }
594
595 return mimeData->hasUrls() || mimeData->hasImage() || mimeData->hasText();
596}
597
598
600{
601 if(m_readOnly)
602 return;
603
604 this->fm->copy(QUrl::fromStringList(urls), this->path);
605}
606
608{
609 if(m_readOnly)
610 return;
611
612 this->fm->cut(QUrl::fromStringList(urls), this->path);
613}
614
615void FMList::setDirIcon(const int &index, const QString &iconName)
616{
617 if (index >= this->list.size() || index < 0)
618 return;
619
620 const auto path = QUrl(this->list.at(index)[FMH::MODEL_KEY::PATH]);
621
622 if (!FMStatic::isDir(path))
623 return;
624
625 FMStatic::setDirConf(QUrl(path.toString() + QStringLiteral("/.directory")), QStringLiteral("Desktop Entry"), QStringLiteral("Icon"), iconName);
626
627 this->list[index][FMH::MODEL_KEY::ICON] = iconName;
628 Q_EMIT this->updateModel(index, QVector<int> {FMH::MODEL_KEY::ICON});
629}
630
631const QUrl FMList::getParentPath()
632{
633 switch (this->pathType)
634 {
635 case FMList::PATHTYPE::PLACES_PATH:
636 return FMStatic::parentDir(this->path);
637 default:
638 return this->previousPath();
639 }
640}
641
643{
644 const auto url = m_navHistory.getPosteriorPath();
645
646 if (url.isEmpty())
647 return this->path;
648
649 return url;
650}
651
653{
654 const auto url = m_navHistory.getPreviousPath();
655
656 if (url.isEmpty())
657 return this->path;
658
659 return url;
660}
661
662bool FMList::getFoldersFirst() const
663{
664 return this->foldersFirst;
665}
666
667void FMList::setFoldersFirst(const bool &value)
668{
669 if (this->foldersFirst == value)
670 return;
671
672 Q_EMIT this->preListChanged();
673
674 this->foldersFirst = value;
675
676 Q_EMIT this->foldersFirstChanged();
677
678 this->sortList();
679
680 Q_EMIT this->postListChanged();
681 Q_EMIT this->countChanged();
682}
683
684void FMList::componentComplete()
685{
686 connect(this, &FMList::pathChanged, this, &FMList::setList);
687 connect(this, &FMList::filtersChanged, this, &FMList::setList);
688 connect(this, &FMList::filterTypeChanged, this, &FMList::setList);
689 connect(this, &FMList::hiddenChanged, this, &FMList::setList);
690 connect(this, &FMList::onlyDirsChanged, this, &FMList::setList);
691
692 connect(this, &FMList::sortByChanged, [this]()
693 {
694 if(this->list.size() > 0)
695 {
696 Q_EMIT this->preListChanged();
697 this->sortList();
698 Q_EMIT this->postListChanged();
699 Q_EMIT this->countChanged();
700 }
701 });
702
703 if(!this->path.isEmpty() && this->path.isValid())
704 {
705 this->setList();
706 }
707}
708
709void FMList::search(const QString &query, bool recursive)
710{
711 if(this->path.isEmpty())
712 {
713 this->setStatus({PathStatus::ERROR, i18n("Error"), i18n("No path to perform the search"), QStringLiteral("document-info"), true, false});
714 }
715
716 qDebug() << "SEARCHING FOR" << query << this->path;
717
718 if (!this->path.isLocalFile() || !recursive)
719 { //if the path is not local then search will not be performed and instead will be filtered
720 qWarning() << "URL recived is not a local file. So search will only filter the content" << this->path;
721 this->filterContent(query, this->path);
722 return;
723 }
724
727 const auto res = watcher->future().result();
728
729 this->assignList(res.content);
730 watcher->deleteLater();
731 });
732
735 res.path = path;
736 res.content = FMStatic::search(query, this->path, this->hidden, this->onlyDirs, this->filters);
737 return res;
738 });
739 watcher->setFuture(t1);
740}
741
742void FMList::filterContent(const QString &query, const QUrl &path)
743{
744 if (this->list.isEmpty()) {
745 qDebug() << "Can not filter content. List is empty";
746 return;
747 }
748
751 const auto res = watcher->future().result();
752
753 this->assignList(res.content);
754 watcher->deleteLater();
755 });
756
758 FMH::MODEL_LIST m_content;
760
761 for (const auto &item : std::as_const(this->list))
762 {
763 if (item[FMH::MODEL_KEY::LABEL].contains(query, Qt::CaseInsensitive) || item[FMH::MODEL_KEY::SUFFIX].contains(query, Qt::CaseInsensitive) || item[FMH::MODEL_KEY::MIME].contains(query, Qt::CaseInsensitive)) {
764 m_content << item;
765 }
766 }
767
768 res.path = path;
769 res.content = m_content;
770 return res;
771 });
772 watcher->setFuture(t1);
773}
774
775int FMList::getCloudDepth() const
776{
777 return this->cloudDepth;
778}
779
780void FMList::setCloudDepth(const int &value)
781{
782 if (this->cloudDepth == value)
783 return;
784
785 this->cloudDepth = value;
786
787 Q_EMIT this->cloudDepthChanged();
788}
789
790PathStatus FMList::getStatus() const
791{
792 return this->m_status;
793}
794
795void FMList::setStatus(const PathStatus &status)
796{
797 this->m_status = status;
798 Q_EMIT this->statusChanged();
799}
800
801void FMList::remove(const int &index)
802{
803 if (index >= this->list.size() || index < 0)
804 return;
805
806 Q_EMIT this->preItemRemoved(index);
807 this->list.remove(index);
808 Q_EMIT this->postItemRemoved();
809 Q_EMIT this->countChanged();
810}
811
813{
814 const auto it = std::find_if(this->items().constBegin(), this->items().constEnd(), [query](const FMH::MODEL &item) -> bool {
815 return item[FMH::MODEL_KEY::LABEL].startsWith(query, Qt::CaseInsensitive);
816 });
817
818 if (it != this->items().constEnd())
819 return (std::distance(this->items().constBegin(), it));
820 else
821 return -1;
822}
823
824bool FMList::getAutoLoad() const
825{
826 return m_autoLoad;
827}
828
829void FMList::setAutoLoad(bool value)
830{
831 if(value == m_autoLoad)
832 {
833 return;
834 }
835
836 m_autoLoad = value;
837 Q_EMIT autoLoadChanged();
838}
839
840bool FMList::readOnly() const
841{
842 return m_readOnly;
843}
844
845void FMList::setReadOnly(bool value)
846{
847 if(m_readOnly == value)
848 return;
849
850 m_readOnly = value;
851 Q_EMIT readOnlyChanged();
852}
853
854int FMList::indexOfFile(const QString& url)
855{
856 const auto it = std::find_if(this->items().constBegin(), this->items().constEnd(), [url](const FMH::MODEL &item) -> bool {
857 return item[FMH::MODEL_KEY::URL] == url;
858 });
859
860 if (it != this->items().constEnd())
861 return (std::distance(this->items().constBegin(), it));
862 else
863 return -1;
864}
865
866
867
PATHTYPE
The different location or places types.
Definition fmlist.h:323
int indexOfName(const QString &query)
Given a file name query find if it exists in the current location.
Definition fmlist.cpp:812
const FMH::MODEL_LIST & items() const final override
items
Definition fmlist.cpp:226
void moveToTrash(const QStringList &urls)
Remove and move to the trash the provided set of file URLs.
Definition fmlist.cpp:482
QString path
The URL to location path to proceed listing all of its file entries.
Definition fmlist.h:165
FMList(QObject *parent=nullptr)
FMList.
Definition fmlist.cpp:37
void createFile(const QString &name)
Create a new file.
Definition fmlist.cpp:466
void removeFiles(const QStringList &urls)
Completely remove the set of file URLs provided.
Definition fmlist.cpp:490
void renameFile(const QString &url, const QString &newName)
Rename a file with from a given URL to the a new name provided.
Definition fmlist.cpp:474
bool readOnly
Whether destructive actions or modifications can be done to the current location contents,...
Definition fmlist.h:214
bool onlyDirs
Whether only directories should be listed.
Definition fmlist.h:177
void search(const QString &query, bool recursive=true)
Start a search - starting from the current location - for a given name query.
Definition fmlist.cpp:709
QStringList filters
The list of string values to filter the listing.
Definition fmlist.h:196
bool foldersFirst
Whether the folders should be sorted first and then the files.
Definition fmlist.h:183
const QUrl previousPath()
The immediate previous path location that was navigated.
Definition fmlist.cpp:652
const QUrl posteriorPath()
The immediate posterior path location that was navigated.
Definition fmlist.cpp:642
bool clipboardHasContent() const
Whether the clipboard has a supported type of content.
Definition fmlist.cpp:584
FMList::FILTER filterType
A convenient way to filter the location contents by a file type (mimetype).
Definition fmlist.h:202
void createSymlink(const QString &url)
Create a symbolic link to the given URL in the current location.
Definition fmlist.cpp:498
PathStatus status
The current status of the location contents listing.
Definition fmlist.h:230
SORTBY
The possible values to sort the location contents.
Definition fmlist.h:241
void paste()
Handle the paste action.
Definition fmlist.cpp:544
void refresh()
Refresh the model for new changes.
Definition fmlist.cpp:447
int cloudDepth
When the location if a remote cloud directory, this allows to define the depth of the levels for list...
Definition fmlist.h:190
QString pathName
The title name of the current location.
Definition fmlist.h:220
FMList::PATHTYPE pathType
The known type of the current location.
Definition fmlist.h:225
FILTER
The possible values to filter the a location content by a mime-type.
Definition fmlist.h:277
@ NONE
Any file type.
Definition fmlist.h:316
void progress(int percent)
Emitted while the file listing is still in progress.
void setDirIcon(const int &index, const QString &iconName)
Changes the icon of a directory by making use of the directory config file.
Definition fmlist.cpp:615
void createDir(const QString &name)
Create a new directory within the current directory.
Definition fmlist.cpp:452
void warning(QString message)
Emitted when the listing process has any error message that needs to be notified.
void cutInto(const QStringList &urls)
Cut/move a list of file URLs to the current directory.
Definition fmlist.cpp:607
void remove(const int &index)
Remove an item from the model, this does not remove the file from the file system.
Definition fmlist.cpp:801
bool hidden
Whether to list the hidden entries.
Definition fmlist.h:171
void copyInto(const QStringList &urls)
Copy a list of file URLs into the current directory.
Definition fmlist.cpp:599
static FMH::MODEL_LIST search(const QString &query, const QUrl &path, const bool &hidden=false, const bool &onlyDirs=false, const QStringList &filters=QStringList())
Search for files in a path using name filters.
Definition fmstatic.cpp:79
static const QHash< PATHTYPE_KEY, QString > PATHTYPE_SCHEME
The map of the PATH_TYPE to its associated protocol scheme.
Definition fmstatic.h:339
static QHash< FILTER_TYPE, QStringList > FILTER_LIST
Convenient map set of file type extensions.
Definition fmstatic.h:220
static bool createSymlink(const QUrl &path, const QUrl &where)
Creates a symbolic link to a given file URL.
Definition fmstatic.cpp:393
static QUrl parentDir(const QUrl &path)
Given a file URL return its parent directory.
Definition fmstatic.cpp:127
static bool removeFiles(const QList< QUrl > &urls)
List of files to be removed completely.
Definition fmstatic.cpp:295
static const FMH::MODEL getFileInfoModel(const QUrl &path)
getFileInfoModel
Definition fmstatic.cpp:559
static bool isDir(const QUrl &path)
Whether a local file URL is a directory.
Definition fmstatic.cpp:139
static bool createDir(const QUrl &path, const QString &name)
Creates a new directory given a base path and a name.
Definition fmstatic.cpp:370
static bool rename(const QUrl &url, const QString &name)
Rename a file.
Definition fmstatic.cpp:365
static void setDirConf(const QUrl &path, const QString &group, const QString &key, const QVariant &value)
Write a configuration key-value entry to the directory conf file.
Definition fmstatic.cpp:463
static void moveToTrash(const QList< QUrl > &urls)
Moves to the trashcan the provided file URLs.
Definition fmstatic.cpp:322
FILTER_TYPE
The common file types for filtering.
Definition fmstatic.h:51
static bool createFile(const QUrl &path, const QString &name)
Creates a file given the base directory path and a file name.
Definition fmstatic.cpp:381
@ REMOTE_PATH
Remote locations, such as servers accessed via SSH or FTP.
Definition fmstatic.h:267
@ FISH_PATH
A remote SHH or FTP.
Definition fmstatic.h:312
@ APPS_PATH
The applications location.
Definition fmstatic.h:292
@ TAGS_PATH
A tag location.
Definition fmstatic.h:282
@ DRIVES_PATH
Hard drives locations.
Definition fmstatic.h:272
@ MTP_PATH
MTP path.
Definition fmstatic.h:317
@ CLOUD_PATH
A remote cloud server path.
Definition fmstatic.h:307
@ TRASH_PATH
The trash location.
Definition fmstatic.h:297
@ PLACES_PATH
Local paths, such as the Downloads, Pictures, etc.
Definition fmstatic.h:262
The FM class stands for File Management, and exposes methods for file listing, browsing and handling,...
Definition fm.h:102
void warningMessage(QString message)
Emitted when there is an error.
void cloudServerContentReady(FMStatic::PATH_CONTENT list)
Emitted once the requested contents of the server are ready.
bool copy(const QList< QUrl > &urls, const QUrl &where)
Copy a set of file URLs to a new destination.
Definition fm.cpp:447
void getPathContent(const QUrl &path, const bool &hidden=false, const bool &onlyDirs=false, const QStringList &filters=QStringList(), const QDirIterator::IteratorFlags &iteratorFlags=QDirIterator::NoIteratorFlags)
Given a path URL retrieve the contents information packaged as a model.
Definition fm.cpp:347
void newItem(FMH::MODEL item, QUrl path)
Emitted when a new item is available in the remote server in the current location.
void pathContentItemsRemoved(FMStatic::PATH_CONTENT list)
Emitted when a set of entries in the current location have been removed.
bool cut(const QList< QUrl > &urls, const QUrl &where)
Cut a set of file URLs to a new destination.
Definition fm.cpp:442
void loadProgress(int percent)
Emitted with the progress of the listing.
void pathContentReady(QUrl path)
Emitted once the contents of the current location are ready and the listing has finished.
void pathContentItemsChanged(QVector< QPair< FMH::MODEL, FMH::MODEL > > items)
Emitted when the current location entries have changed.
void pathContentItemsReady(FMStatic::PATH_CONTENT list)
Emitted when a set of entries for the current location are ready.
Q_INVOKABLE void createCloudDir(const QString &path, const QString &name)
Creates a directory in the server.
Definition fm.cpp:399
void pathContentChanged(QUrl path)
Emitted when the contents of the current location has changed, either by some new entries being added...
bool getCloudServerContent(const QUrl &server, const QStringList &filters=QStringList(), const int &depth=0)
Given a server URL address retrieve its contents.
Definition fm.cpp:364
void preItemAppended()
void countChanged()
void updateModel(int index, QVector< int > roles)
void postItemAppended()
void preItemRemoved(int index)
void preItemsAppended(uint count)
void preListChanged()
void postListChanged()
void postItemRemoved()
int indexOf(const FMH::MODEL_KEY &key, const QString &value) const
bool exists(const FMH::MODEL_KEY &key, const QString &value) const
QList< QUrl > getTagUrls(const QString &tag, const QStringList &filters, const bool &strict=false, const int &limit=9999, const QString &mime=QStringLiteral(""))
Shortcut for getting a list of file URLs associated to a tag, the resulting list of URLs can be filte...
Definition tagging.cpp:348
FMH::MODEL_LIST getTags(const int &limit=5)
Get all the tags available with detailed information packaged as a FMH::MODEL_LIST.
Definition tagging.cpp:374
static Tagging * getInstance()
Returns an instance to the tagging object.
Definition tagging.cpp:70
QString i18n(const char *text, const TYPE &arg...)
const QVector< int > modelRoles(const MODEL &model)
bool fileExists(const QUrl &path)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
char at(qsizetype i) const const
bool isEmpty() const const
const QMimeData * mimeData(Mode mode) const const
QDateTime currentDateTime()
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
QString dirName() const const
bool exists() const const
QFuture< T > future() const const
void setFuture(const QFuture< T > &future)
QClipboard * clipboard()
bool save(QIODevice *device, const char *format, int quality) const const
const_reference at(qsizetype i) const const
iterator begin()
void clear()
qsizetype count() const const
iterator end()
bool isEmpty() const const
void remove(qsizetype i, qsizetype n)
qsizetype size() const const
QByteArray data(const QString &mimeType) const const
bool hasImage() const const
bool hasText() const const
bool hasUrls() const const
QVariant imageData() const const
QString text() const const
QList< QUrl > urls() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
QString arg(Args &&... args) const const
bool isEmpty() const const
QString number(double n, char format, int precision)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString simplified() const const
QString toLower() const const
CaseInsensitive
TextDate
QFuture< T > run(Function function,...)
PreferLocalFile
AssumeLocalFile
QUrl adjusted(FormattingOptions options) const const
QList< QUrl > fromStringList(const QStringList &urls, ParsingMode mode)
QUrl fromUserInput(const QString &userInput, const QString &workingDirectory, UserInputResolutionOptions options)
QString path(ComponentFormattingOptions options) const const
QString toString(FormattingOptions options) const const
QStringList toStringList(const QList< QUrl > &urls, FormattingOptions options)
A location contents structured for convenience.
Definition fmstatic.h:244
FMH::MODEL_LIST content
The contents of the location.
Definition fmstatic.h:254
QUrl path
The location URL holding all of the contents.
Definition fmstatic.h:249
Represents the status of a directory listing, be it non existence location, loading or empty.
Definition fmlist.h:43
@ LOADING
The content is still loading its contents.
Definition fmlist.h:85
@ READY
The listing has finished successfully.
Definition fmlist.h:95
@ ERROR
The listing of the contents has failed.
Definition fmlist.h:90
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:51:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.