aboutsummaryrefslogtreecommitdiff
path: root/lumina-fm
diff options
context:
space:
mode:
authorCarlos Bohórquez <carlos@kernelmap.com>2015-09-11 14:53:30 +0200
committerCarlos Bohórquez <carlos@kernelmap.com>2015-09-11 14:53:30 +0200
commit9d6c79522dde67a1810d6a040bd40e12f8eaae44 (patch)
tree7b8ad7ac7c90260f086f34d9d16a9dbf22ea38d3 /lumina-fm
parentSolves issue 11400 (diff)
downloadlumina-9d6c79522dde67a1810d6a040bd40e12f8eaae44.tar.gz
lumina-9d6c79522dde67a1810d6a040bd40e12f8eaae44.tar.bz2
lumina-9d6c79522dde67a1810d6a040bd40e12f8eaae44.zip
Several changes
Use the global variable sessionsettings_config_file in all places that must be used. QSettings::setPath was already setted so it's not needed. Deleted. Instead using variable for date and time format in case user settings aren't setted, now we go to Qt::DefaultLocaleShortDate. To perform this operation, we must work with Date and Time separately. Now DirWidget::date_format is an QStringList, first item for date and second for time. The QDateTime with format "yyyyMMddhhmmsszzz" is stored on whatsThis variable for being used in sort operations. CQTreeWidgetItem operator< function has been simplified. Now, to check dates, we used the value stored in whatsThis.
Diffstat (limited to 'lumina-fm')
-rw-r--r--lumina-fm/widgets/DirWidget.cpp61
-rw-r--r--lumina-fm/widgets/DirWidget.h22
2 files changed, 45 insertions, 38 deletions
diff --git a/lumina-fm/widgets/DirWidget.cpp b/lumina-fm/widgets/DirWidget.cpp
index 9d4eef0c..7954cc8e 100644
--- a/lumina-fm/widgets/DirWidget.cpp
+++ b/lumina-fm/widgets/DirWidget.cpp
@@ -29,7 +29,7 @@
const QString sessionsettings_config_file = QDir::homePath() + "/.lumina/LuminaDE/sessionsettings.conf";
-QString DirWidget::date_format = QString();
+QStringList DirWidget::date_format = QStringList();
DirWidget::DirWidget(QString objID, QWidget *parent) : QWidget(parent), ui(new Ui::DirWidget){
ui->setupUi(this); //load the designer file
@@ -241,7 +241,7 @@ void DirWidget::LoadDir(QString dir, QList<LFileInfo> list){
if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); }
watcher->addPath(CDIR);
// add sessionsettings to watcher so date_format can be update based on user settings
- watcher->addPath(QDir::homePath() + "/.lumina/LuminaDE/sessionsettings.conf");
+ watcher->addPath(sessionsettings_config_file);
ui->actionStopLoad->setVisible(true);
stopload = false;
//Clear the display widget (if a new directory)
@@ -327,12 +327,39 @@ void DirWidget::LoadDir(QString dir, QList<LFileInfo> list){
case TYPE:
it->setText(t, list[i].mimetype());
break;
- case DATEMOD:
- it->setText(t, list[i].lastModified().toString(getDateFormat()) );
- break;
- case DATECREATE:
- it->setText(t, list[i].created().toString(getDateFormat()) );
- break;
+ case DATEMOD:
+ {
+ QStringList datetime_format = getDateFormat();
+ // Save datetime in WhatThis value. Lately will be used by CQTreeWidgetItem for sorting by date
+ it->setWhatsThis(DATEMOD, list[i].lastModified().toString("yyyyMMddhhmmsszzz"));
+ // Default configurition. Fallback to Qt::DefaultLocaleShortDate for formats
+ if(datetime_format.at(0).isEmpty() && datetime_format.at(1).isEmpty())
+ it->setText(t, list[i].lastModified().toString(Qt::DefaultLocaleShortDate) );
+ // Date is setted but time not. Time goes to default
+ else if(!datetime_format.at(0).isEmpty() && datetime_format.at(1).isEmpty())
+ it->setText(t, list[i].lastModified().date().toString(datetime_format.at(0)) + " " + list[i].lastModified().time().toString(Qt::DefaultLocaleShortDate));
+ // Time is setted but date not. Date goes to default
+ else if(datetime_format.at(0).isEmpty() && !datetime_format.at(1).isEmpty())
+ it->setText(t, list[i].lastModified().date().toString(Qt::DefaultLocaleShortDate) + " " + list[i].lastModified().time().toString(datetime_format.at(1)));
+ // Both time and date setted.
+ else
+ it->setText(t, list[i].lastModified().date().toString(datetime_format.at(0)) + " " + list[i].lastModified().time().toString(datetime_format.at(1)));
+ break;
+ }
+ case DATECREATE:
+ {
+ QStringList datetime_format = getDateFormat();
+ it->setWhatsThis(DATECREATE, list[i].lastModified().toString("yyyyMMddhhmmsszzz"));
+ if(datetime_format.at(0).isEmpty() && datetime_format.at(1).isEmpty())
+ it->setText(t, list[i].lastModified().toString(Qt::DefaultLocaleShortDate) );
+ else if(!datetime_format.at(0).isEmpty() && datetime_format.at(1).isEmpty())
+ it->setText(t, list[i].lastModified().date().toString(datetime_format.at(0)) + " " + list[i].lastModified().time().toString(Qt::DefaultLocaleShortDate));
+ else if(datetime_format.at(0).isEmpty() && !datetime_format.at(1).isEmpty())
+ it->setText(t, list[i].lastModified().date().toString(Qt::DefaultLocaleShortDate) + " " + list[i].lastModified().time().toString(datetime_format.at(1)));
+ else
+ it->setText(t, list[i].lastModified().date().toString(datetime_format.at(0)) + " " + list[i].lastModified().time().toString(datetime_format.at(1)));
+ break;
+ }
}
}
if(addnew){ treeWidget->addTopLevelItem(it); }
@@ -883,24 +910,18 @@ void DirWidget::mouseReleaseEvent(QMouseEvent *ev){
// STATIC
//====================
-QString DirWidget::getDateFormat() {
+QStringList DirWidget::getDateFormat() {
return DirWidget::date_format;
}
// This function is only called if user changes sessionsettings. By doing so, operations like sorting by date
// are faster because the date format is already stored in DirWidget::date_format static variable
void DirWidget::setDateFormat() {
- const QString default_date_format = "dddd, d MMMM yyyy";
- const QString default_hour_format = "h:mm";
- QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homePath()+"/.lumina");
+ if(!DirWidget::date_format.isEmpty())
+ DirWidget::date_format.clear();
QSettings settings("LuminaDE","sessionsettings");
QString date, time;
- // If DateFormat/TimeFormat don't exist or are empty, default values are setted
- date = settings.value("DateFormat", default_date_format).toString();
- time = settings.value("TimeFormat", default_hour_format).toString();
- if(date.isEmpty())
- date = default_date_format;
- if(time.isEmpty())
- time = default_hour_format;
- DirWidget::date_format = date + " " + time;
+ // If value doesn't exist or is not setted, empty string is returned
+ DirWidget::date_format << settings.value("DateFormat").toString();
+ DirWidget::date_format << settings.value("TimeFormat").toString();
}
diff --git a/lumina-fm/widgets/DirWidget.h b/lumina-fm/widgets/DirWidget.h
index 474531f3..6f0e3d8b 100644
--- a/lumina-fm/widgets/DirWidget.h
+++ b/lumina-fm/widgets/DirWidget.h
@@ -54,7 +54,7 @@ public:
void setShowCloseButton(bool show);
//Date format for show items
- static QString getDateFormat();
+ static QStringList getDateFormat();
static void setDateFormat();
public slots:
@@ -98,7 +98,7 @@ private:
//Functions for internal use
void setupConnections();
QStringList currentSelection();
- static QString date_format;
+ static QStringList date_format;
private slots:
//UI BUTTONS/Actions
@@ -185,22 +185,8 @@ public:
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, DirWidget::getDateFormat());
- QDateTime date_time_tmp = QDateTime::fromString(text_tmp, DirWidget::getDateFormat());
- // 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);
- }
- }
+ if(column == DirWidget::DATEMOD || column == DirWidget::DATECREATE)
+ return this->whatsThis(column) < tmp.whatsThis(column);
// We are in size text
else if(column == DirWidget::SIZE) {
QString text = this->text(column);
bgstack15