aboutsummaryrefslogtreecommitdiff
path: root/lumina-fm/widgets/DirWidget.h
diff options
context:
space:
mode:
Diffstat (limited to 'lumina-fm/widgets/DirWidget.h')
-rw-r--r--lumina-fm/widgets/DirWidget.h66
1 files changed, 65 insertions, 1 deletions
diff --git a/lumina-fm/widgets/DirWidget.h b/lumina-fm/widgets/DirWidget.h
index 2c971fd8..514b3e7f 100644
--- a/lumina-fm/widgets/DirWidget.h
+++ b/lumina-fm/widgets/DirWidget.h
@@ -22,6 +22,10 @@
#define ZSNAPDIR QString("/.zfs/snapshot/")
+#ifndef DEBUG
+#define DEBUG 0
+#endif
+
namespace Ui{
class DirWidget;
};
@@ -154,4 +158,64 @@ protected:
void mouseReleaseEvent(QMouseEvent *);
};
-#endif \ No newline at end of file
+
+/*
+ * Virtual class for managing the sort of folders/files items. The problem with base class is that it only manages texts fields and
+ * we have dates and sizes.
+ *
+ * On this class, we overwrite the function operator<.
+ */
+
+class CQTreeWidgetItem : public QTreeWidgetItem {
+public:
+ CQTreeWidgetItem(int type = Type) : QTreeWidgetItem(type) {}
+ CQTreeWidgetItem(const QStringList & strings, int type = Type) : QTreeWidgetItem(strings, type) {}
+ CQTreeWidgetItem(QTreeWidget * parent, int type = Type) : QTreeWidgetItem(parent, type) {}
+ CQTreeWidgetItem(QTreeWidget * parent, const QStringList & strings, int type = Type) : QTreeWidgetItem(parent, strings, type) {}
+ CQTreeWidgetItem(QTreeWidget * parent, QTreeWidgetItem * preceding, int type = Type) : QTreeWidgetItem(parent, preceding, type) {}
+ CQTreeWidgetItem(QTreeWidgetItem * parent, int type = Type) : QTreeWidgetItem(parent, type) {}
+ CQTreeWidgetItem(QTreeWidgetItem * parent, const QStringList & strings, int type = Type) : QTreeWidgetItem(parent, strings, type) {}
+ CQTreeWidgetItem(QTreeWidgetItem * parent, QTreeWidgetItem * preceding, int type = Type) : QTreeWidgetItem(parent, preceding, type) {}
+ virtual ~CQTreeWidgetItem() {}
+ inline virtual bool operator<(const QTreeWidgetItem &tmp) const {
+ int column = this->treeWidget()->sortColumn();
+ // We are in date text
+ if(column == DirWidget::DATEMOD || column == DirWidget::DATECREATE) {
+ // Get the stored text and try to convert to QDateTime
+ QString text = this->text(column);
+ QString text_tmp = tmp.text(column);
+ QDateTime date_time = QDateTime::fromString(text, Qt::DefaultLocaleShortDate);
+ QDateTime date_time_tmp = QDateTime::fromString(text_tmp, Qt::DefaultLocaleShortDate);
+ // If the conversion are ok in both objects, compare them
+ if(date_time.isValid() && date_time_tmp.isValid())
+ return date_time < date_time_tmp;
+ // If some of the dates are invalid, use the base class implementation (order by string)
+ else {
+ if(DEBUG)
+ qDebug() << "Cannot convert the date. Texts arrived are " << text << " and " << text_tmp;
+ return QTreeWidgetItem::operator <(tmp);
+ }
+ }
+ // We are in size text
+ else if(column == DirWidget::SIZE) {
+ QString text = this->text(column);
+ QString text_tmp = tmp.text(column);
+ double filesize, filesize_tmp;
+ // On folders, text is empty so we check for that
+ // In case we are in folders, we put -1 for differentiate of regular files with 0 bytes.
+ // Doing so, all folders we'll be together instead of mixing with files with 0 bytes.
+ if(text.isEmpty())
+ filesize = -1;
+ else
+ filesize = LUtils::DisplaySizeToBytes(text);
+ if(text_tmp.isEmpty())
+ filesize_tmp = -1;
+ else
+ filesize_tmp = LUtils::DisplaySizeToBytes(text_tmp);
+ return filesize < filesize_tmp;
+ }
+ // In other cases, we trust base class implementation
+ return QTreeWidgetItem::operator<(tmp);
+ }
+};
+#endif
bgstack15