From a17f4ef05bd643e353682472929ec1db99dfa7e1 Mon Sep 17 00:00:00 2001 From: Carlos Bohórquez Date: Thu, 10 Sep 2015 19:54:44 +0200 Subject: Solves issue 11400 The functions to set dates on lumina-FM now use user preferred settings. --- lumina-fm/widgets/DirWidget.cpp | 48 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'lumina-fm/widgets/DirWidget.cpp') diff --git a/lumina-fm/widgets/DirWidget.cpp b/lumina-fm/widgets/DirWidget.cpp index 22879c1b..9d4eef0c 100644 --- a/lumina-fm/widgets/DirWidget.cpp +++ b/lumina-fm/widgets/DirWidget.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,11 @@ #define DEBUG 0 #endif + +const QString sessionsettings_config_file = QDir::homePath() + "/.lumina/LuminaDE/sessionsettings.conf"; + +QString DirWidget::date_format = QString(); + DirWidget::DirWidget(QString objID, QWidget *parent) : QWidget(parent), ui(new Ui::DirWidget){ ui->setupUi(this); //load the designer file ID = objID; @@ -64,6 +70,7 @@ DirWidget::DirWidget(QString objID, QWidget *parent) : QWidget(parent), ui(new U //Now update the rest of the UI canmodify = false; //initial value contextMenu = new QMenu(this); + setDateFormat(); setShowDetails(true); setShowThumbnails(true); UpdateIcons(); @@ -233,6 +240,8 @@ void DirWidget::LoadDir(QString dir, QList list){ if(!watcher->directories().isEmpty()){ watcher->removePaths(watcher->directories()); } 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"); ui->actionStopLoad->setVisible(true); stopload = false; //Clear the display widget (if a new directory) @@ -319,10 +328,10 @@ void DirWidget::LoadDir(QString dir, QList list){ it->setText(t, list[i].mimetype()); break; case DATEMOD: - it->setText(t, list[i].lastModified().toString(Qt::DefaultLocaleShortDate) ); + it->setText(t, list[i].lastModified().toString(getDateFormat()) ); break; case DATECREATE: - it->setText(t, list[i].created().toString(Qt::DefaultLocaleShortDate) ); + it->setText(t, list[i].created().toString(getDateFormat()) ); break; } } @@ -499,8 +508,8 @@ void DirWidget::setupConnections(){ connect(deleteFilesShort, SIGNAL(activated()), this, SLOT( on_tool_act_rm_clicked() ) ); connect(refreshShort, SIGNAL(activated()), this, SLOT( refresh()) ); //Filesystem Watcher - connect(watcher, SIGNAL(directoryChanged(const QString&)), this, SLOT(startSync()) ); - connect(watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(startSync()) ); //just in case + connect(watcher, SIGNAL(directoryChanged(const QString&)), this, SLOT(startSync(const QString &)) ); + connect(watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(startSync(const QString &)) ); //just in case connect(synctimer, SIGNAL(timeout()), this, SLOT(refresh()) ); } @@ -846,7 +855,10 @@ void DirWidget::SelectionChanged(){ ui->tool_act_runwith->setEnabled(hasselection); } -void DirWidget::startSync(){ +void DirWidget::startSync(const QString &file){ + //Update date_format based on user settings + if(file == sessionsettings_config_file) + setDateFormat(); if(synctimer->isActive()){ synctimer->stop(); } synctimer->start(); } @@ -866,3 +878,29 @@ void DirWidget::mouseReleaseEvent(QMouseEvent *ev){ ev->ignore(); //not handled here } } + +//==================== +// STATIC +//==================== + +QString 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"); + 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; +} -- cgit From 9d6c79522dde67a1810d6a040bd40e12f8eaae44 Mon Sep 17 00:00:00 2001 From: Carlos Bohórquez Date: Fri, 11 Sep 2015 14:53:30 +0200 Subject: 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. --- lumina-fm/widgets/DirWidget.cpp | 61 +++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 20 deletions(-) (limited to 'lumina-fm/widgets/DirWidget.cpp') 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 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 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(); } -- cgit From ad713efa6f6232422d9e88095e8313383fed64db Mon Sep 17 00:00:00 2001 From: Carlos Bohórquez Date: Fri, 11 Sep 2015 15:06:27 +0200 Subject: Static variables not needed now --- lumina-fm/widgets/DirWidget.cpp | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'lumina-fm/widgets/DirWidget.cpp') diff --git a/lumina-fm/widgets/DirWidget.cpp b/lumina-fm/widgets/DirWidget.cpp index 7954cc8e..6c1c4553 100644 --- a/lumina-fm/widgets/DirWidget.cpp +++ b/lumina-fm/widgets/DirWidget.cpp @@ -29,8 +29,6 @@ const QString sessionsettings_config_file = QDir::homePath() + "/.lumina/LuminaDE/sessionsettings.conf"; -QStringList DirWidget::date_format = QStringList(); - DirWidget::DirWidget(QString objID, QWidget *parent) : QWidget(parent), ui(new Ui::DirWidget){ ui->setupUi(this); //load the designer file ID = objID; @@ -162,6 +160,23 @@ void DirWidget::setShowCloseButton(bool show){ ui->actionClose_Browser->setVisible(show); } +QStringList DirWidget::getDateFormat() { + return 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() { + if(!date_format.isEmpty()) + date_format.clear(); + QSettings settings("LuminaDE","sessionsettings"); + QString date, time; + // If value doesn't exist or is not setted, empty string is returned + date_format << settings.value("DateFormat").toString(); + date_format << settings.value("TimeFormat").toString(); +} + + // ================ // PUBLIC SLOTS // ================ @@ -905,23 +920,3 @@ void DirWidget::mouseReleaseEvent(QMouseEvent *ev){ ev->ignore(); //not handled here } } - -//==================== -// STATIC -//==================== - -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() { - if(!DirWidget::date_format.isEmpty()) - DirWidget::date_format.clear(); - QSettings settings("LuminaDE","sessionsettings"); - QString 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(); -} -- cgit From f0001106f033b9c2c9602282001f17a148ed29b0 Mon Sep 17 00:00:00 2001 From: Carlos Bohórquez Date: Fri, 11 Sep 2015 15:10:11 +0200 Subject: Forget delete 2 unused variables --- lumina-fm/widgets/DirWidget.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'lumina-fm/widgets/DirWidget.cpp') diff --git a/lumina-fm/widgets/DirWidget.cpp b/lumina-fm/widgets/DirWidget.cpp index 6c1c4553..6e5c3941 100644 --- a/lumina-fm/widgets/DirWidget.cpp +++ b/lumina-fm/widgets/DirWidget.cpp @@ -170,7 +170,6 @@ void DirWidget::setDateFormat() { if(!date_format.isEmpty()) date_format.clear(); QSettings settings("LuminaDE","sessionsettings"); - QString date, time; // If value doesn't exist or is not setted, empty string is returned date_format << settings.value("DateFormat").toString(); date_format << settings.value("TimeFormat").toString(); -- cgit