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
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
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 const auto _filters = m_mergeFilters ? QStringList() << this->filters << FMStatic::FILTER_LIST[static_cast<FMStatic::FILTER_TYPE>(this->filterType)] : this->filters.isEmpty() ? FMStatic::FILTER_LIST[static_cast<FMStatic::FILTER_TYPE>(this->filterType)] : this->filters;
215 this->fm->getPathContent(this->path, this->hidden, this->onlyDirs, _filters);
216 }
217 break; // ASYNC
218 }
219 }
220}
221
222void FMList::setMergeFilters(bool value)
223{
224 if(value == m_mergeFilters)
225 return;
226
227 m_mergeFilters = value;
228 Q_EMIT mergeFiltersChanged();
229}
230
231bool FMList::mergeFilters() const
232{
233 return m_mergeFilters;
234}
235
236void FMList::reset()
237{
238 this->setList();
239}
240
242{
243 return this->list;
244}
245
246FMList::SORTBY FMList::getSortBy() const
247{
248 return this->sort;
249}
250
251void FMList::setSortBy(const FMList::SORTBY &key)
252{
253 if (this->sort == key)
254 return;
255
256 this->sort = key;
257 Q_EMIT this->sortByChanged();
258}
259
260void FMList::sortList()
261{
262 const FMH::MODEL_KEY key = static_cast<FMH::MODEL_KEY>(this->sort);
263 auto it = this->list.begin();
264
265 const auto sortFunc = [key](const FMH::MODEL &e1, const FMH::MODEL &e2) -> bool
266 {
267 switch (key) {
268 case FMH::MODEL_KEY::SIZE: {
269 if (e1[key].toDouble() > e2[key].toDouble())
270 return true;
271 break;
272 }
273
274 case FMH::MODEL_KEY::ADDDATE:
275 case FMH::MODEL_KEY::MODIFIED:
276 case FMH::MODEL_KEY::DATE: {
277 auto currentTime = QDateTime::currentDateTime();
278
279 auto date1 = QDateTime::fromString(e1[key], Qt::TextDate);
280 auto date2 = QDateTime::fromString(e2[key], Qt::TextDate);
281
282 if (date1.secsTo(currentTime) < date2.secsTo(currentTime))
283 return true;
284
285 break;
286 }
287
288 case FMH::MODEL_KEY::MIME:
289 case FMH::MODEL_KEY::LABEL: {
290 const auto str1 = QString(e1[key]).toLower();
291 const auto str2 = QString(e2[key]).toLower();
292
293 if (str1 < str2)
294 return true;
295 break;
296 }
297
298 default:
299 if (e1[key] < e2[key])
300 return true;
301 }
302
303 return false;
304 };
305
306 if (this->foldersFirst) {
307
308 it = std::partition(this->list.begin(),
309 this->list.end(),
310 [](const FMH::MODEL &e1) -> bool {
311 return e1[FMH::MODEL_KEY::MIME] == QStringLiteral("inode/directory");
312 });
313
314 if(this->list.begin() != it)
315 {
316 std::sort(this->list.begin(), it, sortFunc);
317 }
318 }
319
320 if(it != this->list.end())
321 {
322 std::sort(it, this->list.end(), sortFunc);
323 }
324}
325
326QString FMList::getPathName() const
327{
328 return this->pathName;
329}
330
331QString FMList::getPath() const
332{
333 return this->path.toString();
334}
335
336void FMList::setPath(const QString &path)
337{
339
340 if (this->path == path_)
341 return;
342
343 this->path = path_;
344 m_navHistory.appendPath(this->path);
345
346 this->setStatus({PathStatus::STATUS_CODE::LOADING, i18n("Loading content"), i18n("Almost ready!"), QStringLiteral("view-refresh"), true, false});
347
348 const auto __scheme = this->path.scheme();
349 this->pathName = QDir(this->path.toLocalFile()).dirName();
350
352 this->pathType = FMList::PATHTYPE::CLOUD_PATH;
353
355 this->pathType = FMList::PATHTYPE::APPS_PATH;
356
358 this->pathType = FMList::PATHTYPE::TAGS_PATH;
359 this->pathName = this->path.path();
360
362 this->pathType = FMList::PATHTYPE::TRASH_PATH;
363 this->pathName = QStringLiteral("Trash");
364
366 this->pathType = FMList::PATHTYPE::PLACES_PATH;
367
369 this->pathType = FMList::PATHTYPE::MTP_PATH;
370
372 this->pathType = FMList::PATHTYPE::FISH_PATH;
373
375 this->pathType = FMList::PATHTYPE::REMOTE_PATH;
376
378 this->pathType = FMList::PATHTYPE::DRIVES_PATH;
379 } else {
380 this->pathType = FMList::PATHTYPE::OTHER_PATH;
381 }
382
383 Q_EMIT this->pathNameChanged();
384 Q_EMIT this->pathTypeChanged();
385 Q_EMIT this->pathChanged();
386}
387
388FMList::PATHTYPE FMList::getPathType() const
389{
390 return this->pathType;
391}
392
393QStringList FMList::getFilters() const
394{
395 return this->filters;
396}
397
398void FMList::setFilters(const QStringList &filters)
399{
400 if (this->filters == filters)
401 return;
402
403 this->filters = filters;
404
405 Q_EMIT this->filtersChanged();
406}
407
408void FMList::resetFilters()
409{
410 this->setFilters(QStringList());
411}
412
413FMList::FILTER FMList::getFilterType() const
414{
415 return this->filterType;
416}
417
418void FMList::setFilterType(const FMList::FILTER &type)
419{
420 if (this->filterType == type)
421 return;
422
423 this->filterType = type;
424
425 Q_EMIT this->filterTypeChanged();
426}
427
428void FMList::resetFilterType()
429{
430 this->setFilterType(FMList::FILTER::NONE);
431}
432
433bool FMList::getHidden() const
434{
435 return this->hidden;
436}
437
438void FMList::setHidden(const bool &state)
439{
440 if (this->hidden == state)
441 return;
442
443 this->hidden = state;
444 Q_EMIT this->hiddenChanged();
445}
446
447bool FMList::getOnlyDirs() const
448{
449 return this->onlyDirs;
450}
451
452void FMList::setOnlyDirs(const bool &state)
453{
454 if (this->onlyDirs == state)
455 return;
456
457 this->onlyDirs = state;
458
459 Q_EMIT this->onlyDirsChanged();
460}
461
463{
464 Q_EMIT this->pathChanged();
465}
466
467void FMList::createDir(const QString &name)
468{
469 if(m_readOnly)
470 return;
471
472 if (this->pathType == FMList::PATHTYPE::CLOUD_PATH) {
473#ifdef COMPONENT_SYNCING
474 this->fm->createCloudDir(QString(this->path.toString()).replace(FMStatic::PATHTYPE_SCHEME[FMStatic::PATHTYPE_KEY::CLOUD_PATH] + "/" + this->fm->sync->getUser(), ""), name);
475#endif
476 } else {
477 FMStatic::createDir(this->path, name);
478 }
479}
480
482{
483 if(m_readOnly)
484 return;
485
486 FMStatic::createFile(this->path, name);
487}
488
489void FMList::renameFile(const QString& url, const QString& newName)
490{
491 if(m_readOnly)
492 return;
493
494 FMStatic::rename(QUrl(url), newName);
495}
496
498{
499 if(m_readOnly)
500 return;
501
503}
504
506{
507 if(m_readOnly)
508 return;
509
511}
512
514{
515 if(m_readOnly)
516 return;
517
518 FMStatic::createSymlink(QUrl(url), this->path);
519}
520
521bool FMList::saveImageFile(const QImage& image)
522{
523 QString fileName = QString(QStringLiteral("%1/pasted_image-0.%2")).arg(path.toLocalFile(), QStringLiteral("png"));
524
525 int idx = 1;
526 while ( QFile::exists( fileName ) )
527 {
528 fileName = QString(QStringLiteral("%1/pasted_image-%2.%3")).arg(path.toLocalFile(), QString::number(idx), QStringLiteral("png"));
529 idx++;
530 }
531
532 return image.save(fileName);
533}
534
535bool FMList::saveTextFile(const QString& data, const QString &format)
536{
537 QString fileName = QString(QStringLiteral("%1/pasted_text-0.%2")).arg(path.toLocalFile(), format);
538
539 int idx = 1;
540 while ( QFile::exists( fileName ) )
541 {
542 fileName = QString(QStringLiteral("%1/pasted_text-%2.%3")).arg(path.toLocalFile(), QString::number(idx), format);
543 idx++;
544 }
545
546 QFile file(fileName);
547
548 if (file.open(QIODevice::ReadWrite))
549 {
550 QTextStream out(&file);
551 out << data;
552 file.close();
553 return true;
554 }
555
556 return false;
557}
558
560{
561 if(m_readOnly)
562 return;
563
564 const QClipboard *clipboard = QGuiApplication::clipboard();
565 const QMimeData *mimeData = clipboard->mimeData();
566
567 if(!mimeData)
568 {
569 qWarning() << "Could not get mime data from the clipboard";
570 return;
571 }
572
573 if (mimeData->hasImage())
574 {
575 saveImageFile(qvariant_cast<QImage>(mimeData->imageData()));
576 } else if (mimeData->hasUrls())
577 {
578 const QByteArray a = mimeData->data(QStringLiteral("application/x-kde-cutselection"));
579 const bool cut = (!a.isEmpty() && a.at(0) == '1');
580
581 if(cut)
582 {
583 cutInto(QUrl::toStringList(mimeData->urls()));
584 // mimeData->clear();
585 }else
586 {
587 copyInto(QUrl::toStringList(mimeData->urls()));
588 }
589
590 } else if (mimeData->hasText())
591 {
592 saveTextFile(mimeData->text(), QStringLiteral("txt"));
593 } else
594 {
595 qWarning() << "Unexpected mime type from clipboard content for performing a paste";
596 }
597}
598
600{
601 const QClipboard *clipboard = QGuiApplication::clipboard();
602 const QMimeData *mimeData = clipboard->mimeData();
603
604 if(!mimeData)
605 {
606 qWarning() << "Could not get mime data from the clipboard";
607 return false;
608 }
609
610 return mimeData->hasUrls() || mimeData->hasImage() || mimeData->hasText();
611}
612
613
615{
616 if(m_readOnly)
617 return;
618
619 this->fm->copy(QUrl::fromStringList(urls), this->path);
620}
621
623{
624 if(m_readOnly)
625 return;
626
627 this->fm->cut(QUrl::fromStringList(urls), this->path);
628}
629
630void FMList::setDirIcon(const int &index, const QString &iconName)
631{
632 if (index >= this->list.size() || index < 0)
633 return;
634
635 const auto path = QUrl(this->list.at(index)[FMH::MODEL_KEY::PATH]);
636
637 if (!FMStatic::isDir(path))
638 return;
639
640 FMStatic::setDirConf(QUrl(path.toString() + QStringLiteral("/.directory")), QStringLiteral("Desktop Entry"), QStringLiteral("Icon"), iconName);
641
642 this->list[index][FMH::MODEL_KEY::ICON] = iconName;
643 Q_EMIT this->updateModel(index, QVector<int> {FMH::MODEL_KEY::ICON});
644}
645
646const QUrl FMList::getParentPath()
647{
648 switch (this->pathType)
649 {
650 case FMList::PATHTYPE::PLACES_PATH:
651 return FMStatic::parentDir(this->path);
652 default:
653 return this->previousPath();
654 }
655}
656
658{
659 const auto url = m_navHistory.getPosteriorPath();
660
661 if (url.isEmpty())
662 return this->path;
663
664 return url;
665}
666
668{
669 const auto url = m_navHistory.getPreviousPath();
670
671 if (url.isEmpty())
672 return this->path;
673
674 return url;
675}
676
677bool FMList::getFoldersFirst() const
678{
679 return this->foldersFirst;
680}
681
682void FMList::setFoldersFirst(const bool &value)
683{
684 if (this->foldersFirst == value)
685 return;
686
687 Q_EMIT this->preListChanged();
688
689 this->foldersFirst = value;
690
691 Q_EMIT this->foldersFirstChanged();
692
693 this->sortList();
694
695 Q_EMIT this->postListChanged();
696 Q_EMIT this->countChanged();
697}
698
699void FMList::componentComplete()
700{
701 connect(this, &FMList::pathChanged, this, &FMList::setList);
702 connect(this, &FMList::filtersChanged, this, &FMList::setList);
703 connect(this, &FMList::filterTypeChanged, this, &FMList::setList);
704 connect(this, &FMList::hiddenChanged, this, &FMList::setList);
705 connect(this, &FMList::onlyDirsChanged, this, &FMList::setList);
706
707 connect(this, &FMList::sortByChanged, [this]()
708 {
709 if(this->list.size() > 0)
710 {
711 Q_EMIT this->preListChanged();
712 this->sortList();
713 Q_EMIT this->postListChanged();
714 Q_EMIT this->countChanged();
715 }
716 });
717
718 if(!this->path.isEmpty() && this->path.isValid())
719 {
720 this->setList();
721 }
722}
723
724void FMList::search(const QString &query, bool recursive)
725{
726 if(this->path.isEmpty())
727 {
728 this->setStatus({PathStatus::ERROR, i18n("Error"), i18n("No path to perform the search"), QStringLiteral("document-info"), true, false});
729 }
730
731 qDebug() << "SEARCHING FOR" << query << this->path;
732
733 if (!this->path.isLocalFile() || !recursive)
734 { //if the path is not local then search will not be performed and instead will be filtered
735 qWarning() << "URL recived is not a local file. So search will only filter the content" << this->path;
736 this->filterContent(query, this->path);
737 return;
738 }
739
742 const auto res = watcher->future().result();
743
744 this->assignList(res.content);
745 watcher->deleteLater();
746 });
747
750 res.path = path;
751 res.content = FMStatic::search(query, this->path, this->hidden, this->onlyDirs, this->filters);
752 return res;
753 });
754 watcher->setFuture(t1);
755}
756
757void FMList::filterContent(const QString &query, const QUrl &path)
758{
759 if (this->list.isEmpty()) {
760 qDebug() << "Can not filter content. List is empty";
761 return;
762 }
763
766 const auto res = watcher->future().result();
767
768 this->assignList(res.content);
769 watcher->deleteLater();
770 });
771
773 FMH::MODEL_LIST m_content;
775
776 for (const auto &item : std::as_const(this->list))
777 {
778 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)) {
779 m_content << item;
780 }
781 }
782
783 res.path = path;
784 res.content = m_content;
785 return res;
786 });
787 watcher->setFuture(t1);
788}
789
790int FMList::getCloudDepth() const
791{
792 return this->cloudDepth;
793}
794
795void FMList::setCloudDepth(const int &value)
796{
797 if (this->cloudDepth == value)
798 return;
799
800 this->cloudDepth = value;
801
802 Q_EMIT this->cloudDepthChanged();
803}
804
805PathStatus FMList::getStatus() const
806{
807 return this->m_status;
808}
809
810void FMList::setStatus(const PathStatus &status)
811{
812 this->m_status = status;
813 Q_EMIT this->statusChanged();
814}
815
816void FMList::remove(const int &index)
817{
818 if (index >= this->list.size() || index < 0)
819 return;
820
821 Q_EMIT this->preItemRemoved(index);
822 this->list.remove(index);
823 Q_EMIT this->postItemRemoved();
824 Q_EMIT this->countChanged();
825}
826
828{
829 const auto it = std::find_if(this->items().constBegin(), this->items().constEnd(), [query](const FMH::MODEL &item) -> bool {
830 return item[FMH::MODEL_KEY::LABEL].startsWith(query, Qt::CaseInsensitive);
831 });
832
833 if (it != this->items().constEnd())
834 return (std::distance(this->items().constBegin(), it));
835 else
836 return -1;
837}
838
839bool FMList::getAutoLoad() const
840{
841 return m_autoLoad;
842}
843
844void FMList::setAutoLoad(bool value)
845{
846 if(value == m_autoLoad)
847 {
848 return;
849 }
850
851 m_autoLoad = value;
852 Q_EMIT autoLoadChanged();
853}
854
855bool FMList::readOnly() const
856{
857 return m_readOnly;
858}
859
860void FMList::setReadOnly(bool value)
861{
862 if(m_readOnly == value)
863 return;
864
865 m_readOnly = value;
866 Q_EMIT readOnlyChanged();
867}
868
869int FMList::indexOfFile(const QString& url)
870{
871 const auto it = std::find_if(this->items().constBegin(), this->items().constEnd(), [url](const FMH::MODEL &item) -> bool {
872 return item[FMH::MODEL_KEY::URL] == url;
873 });
874
875 if (it != this->items().constEnd())
876 return (std::distance(this->items().constBegin(), it));
877 else
878 return -1;
879}
880
881
882
PATHTYPE
The different location or places types.
Definition fmlist.h:325
int indexOfName(const QString &query)
Given a file-name-query, check if it exists in the current location.
Definition fmlist.cpp:827
const FMH::MODEL_LIST & items() const final override
items
Definition fmlist.cpp:241
void moveToTrash(const QStringList &urls)
Remove and move to the trash the provided set of file URLs.
Definition fmlist.cpp:497
QString path
The URL to location path to proceed listing all of its file entries.
Definition fmlist.h:161
FMList(QObject *parent=nullptr)
FMList.
Definition fmlist.cpp:37
void createFile(const QString &name)
Create a new file.
Definition fmlist.cpp:481
void removeFiles(const QStringList &urls)
Completely remove the set of file URLs provided.
Definition fmlist.cpp:505
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:489
bool readOnly
Whether destructive actions or modifications can be done to the current location contents,...
Definition fmlist.h:210
bool onlyDirs
Whether only directories should be listed.
Definition fmlist.h:173
void search(const QString &query, bool recursive=true)
Start a search - starting from the current location - for a given name query.
Definition fmlist.cpp:724
QStringList filters
The list of string values to filter the listing.
Definition fmlist.h:192
bool foldersFirst
Whether the folders should be sorted first and then the files.
Definition fmlist.h:179
const QUrl previousPath()
The immediate previous path location that was navigated.
Definition fmlist.cpp:667
const QUrl posteriorPath()
The immediate posterior path location that was navigated.
Definition fmlist.cpp:657
bool clipboardHasContent() const
Whether the clipboard has a supported type of content.
Definition fmlist.cpp:599
FMList::FILTER filterType
A convenient way to filter the location contents by a file type (mimetype).
Definition fmlist.h:198
void createSymlink(const QString &url)
Create a symbolic link to the given URL in the current location.
Definition fmlist.cpp:513
PathStatus status
The current status of the location contents listing.
Definition fmlist.h:226
SORTBY
The possible values to sort the location contents.
Definition fmlist.h:243
void paste()
Handle the paste action.
Definition fmlist.cpp:559
void refresh()
Refresh the model for new changes.
Definition fmlist.cpp:462
bool mergeFilters
Merge the name filters and mimetype filters together for filtering the requested location contentent'...
Definition fmlist.h:237
int cloudDepth
When the location if a remote cloud directory, this allows to define the depth of the levels for list...
Definition fmlist.h:186
QString pathName
The title name of the current location.
Definition fmlist.h:216
FMList::PATHTYPE pathType
The known type of the current location.
Definition fmlist.h:221
FILTER
The possible values to filter the a location content by a mime-type.
Definition fmlist.h:279
@ NONE
Any file type.
Definition fmlist.h:318
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:630
void createDir(const QString &name)
Create a new directory within the current directory.
Definition fmlist.cpp:467
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:622
void remove(const int &index)
Remove an item from the model, this does not remove the file from the file system.
Definition fmlist.cpp:816
bool hidden
Whether to list the hidden entries.
Definition fmlist.h:167
void copyInto(const QStringList &urls)
Copy a list of file URLs into the current directory.
Definition fmlist.cpp:614
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:333
static QHash< FILTER_TYPE, QStringList > FILTER_LIST
Convenient map set of file type extensions.
Definition fmstatic.h:214
static bool createSymlink(const QUrl &path, const QUrl &where)
Creates a symbolic link to a given file URL.
Definition fmstatic.cpp:394
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:296
static const FMH::MODEL getFileInfoModel(const QUrl &path)
getFileInfoModel
Definition fmstatic.cpp:560
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:371
static bool rename(const QUrl &url, const QString &name)
Rename a file.
Definition fmstatic.cpp:366
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:464
static void moveToTrash(const QList< QUrl > &urls)
Moves to the trashcan the provided file URLs.
Definition fmstatic.cpp:323
FILTER_TYPE
The common file types for filtering.
Definition fmstatic.h:46
static bool createFile(const QUrl &path, const QString &name)
Creates a file given the base directory path and a file name.
Definition fmstatic.cpp:382
@ REMOTE_PATH
Remote locations, such as servers accessed via SSH or FTP.
Definition fmstatic.h:261
@ FISH_PATH
A remote SHH or FTP.
Definition fmstatic.h:306
@ APPS_PATH
The applications location.
Definition fmstatic.h:286
@ TAGS_PATH
A tag location.
Definition fmstatic.h:276
@ DRIVES_PATH
Hard drives locations.
Definition fmstatic.h:266
@ MTP_PATH
MTP path.
Definition fmstatic.h:311
@ CLOUD_PATH
A remote cloud server path.
Definition fmstatic.h:301
@ TRASH_PATH
The trash location.
Definition fmstatic.h:291
@ PLACES_PATH
Local paths, such as the Downloads, Pictures, etc.
Definition fmstatic.h:256
The FM class stands for File Management, and exposes methods for file listing, browsing and handling,...
Definition fm.h:104
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:448
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:350
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:443
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:400
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:366
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
void urlTagged(QString url, QString tag)
Emitted when a tag has been assigened to a file URL.
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
void tagRemoved(QString tag)
Emitted when a tag has been removed.
void tagged(QVariantMap tag)
Emitted when a new tag has been created.
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:238
FMH::MODEL_LIST content
The contents of the location.
Definition fmstatic.h:248
QUrl path
The location URL holding all of the contents.
Definition fmstatic.h:243
Represents the status of a directory listing, be it non existence location, loading or empty.
Definition fmlist.h:39
@ LOADING
The content is still loading its contents.
Definition fmlist.h:81
@ READY
The listing has finished successfully.
Definition fmlist.h:91
@ ERROR
The listing of the contents has failed.
Definition fmlist.h:86
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:49:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.