diff options
-rw-r--r-- | lumina-fm/widgets/DirWidget.cpp | 48 | ||||
-rw-r--r-- | lumina-fm/widgets/DirWidget.h | 11 |
2 files changed, 51 insertions, 8 deletions
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 <QTimer> #include <QInputDialog> #include <QScrollBar> +#include <QSettings> #include <LuminaOS.h> #include <LuminaXDG.h> @@ -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<LFileInfo> 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<LFileInfo> 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; +} diff --git a/lumina-fm/widgets/DirWidget.h b/lumina-fm/widgets/DirWidget.h index 514b3e7f..474531f3 100644 --- a/lumina-fm/widgets/DirWidget.h +++ b/lumina-fm/widgets/DirWidget.h @@ -52,6 +52,10 @@ public: void setDetails(QList<DETAILTYPES> list); //Which details to show and in which order (L->R) void setThumbnailSize(int px); void setShowCloseButton(bool show); + + //Date format for show items + static QString getDateFormat(); + static void setDateFormat(); public slots: void LoadDir(QString dir, LFileInfoList list); @@ -94,6 +98,7 @@ private: //Functions for internal use void setupConnections(); QStringList currentSelection(); + static QString date_format; private slots: //UI BUTTONS/Actions @@ -132,7 +137,7 @@ private slots: //Browser Functions void OpenContextMenu(); void SelectionChanged(); - void startSync(); //used internally to collect/pause before updating the dir + void startSync(const QString &file); //used internally to collect/pause before updating the dir signals: //Directory loading/finding signals @@ -184,8 +189,8 @@ public: // 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); + 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; |