aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
diff options
context:
space:
mode:
authorKen Moore <ken@pcbsd.org>2016-09-27 16:34:15 -0400
committerKen Moore <ken@pcbsd.org>2016-09-27 16:34:15 -0400
commit4f90da22cb075252d9cbb0e797a656ed8cd065bd (patch)
treef679e15dcb3e6272cb6a007e32174b3de9fc24a8 /src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
parentMerge branch 'master' of github.com:trueos/lumina (diff)
downloadlumina-4f90da22cb075252d9cbb0e797a656ed8cd065bd.tar.gz
lumina-4f90da22cb075252d9cbb0e797a656ed8cd065bd.tar.bz2
lumina-4f90da22cb075252d9cbb0e797a656ed8cd065bd.zip
More work on the new backend: still disabled for now.
Diffstat (limited to 'src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp')
-rw-r--r--src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp124
1 files changed, 114 insertions, 10 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
index e6017e77..bec99667 100644
--- a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
@@ -8,11 +8,15 @@
#include <QVBoxLayout>
#include <QTimer>
+#include <QSettings>
+
+#include <LuminaUtils.h>
BrowserWidget::BrowserWidget(QString objID, QWidget *parent) : QWidget(parent){
//Setup the Widget/UI
this->setLayout( new QVBoxLayout(this) );
- this->setWhatsThis(objID);
+ ID = objID;
+ //this->setWhatsThis(objID);
//Setup the backend browser object
BROWSER = new Browser(this);
connect(BROWSER, SIGNAL(clearItems()), this, SLOT(clearItems()) );
@@ -22,6 +26,7 @@ BrowserWidget::BrowserWidget(QString objID, QWidget *parent) : QWidget(parent){
connect(this, SIGNAL(dirChange(QString)), BROWSER, SLOT(loadDirectory(QString)) );
listWidget = 0;
treeWidget = 0;
+ readDateFormat();
}
BrowserWidget::~BrowserWidget(){
@@ -47,6 +52,7 @@ void BrowserWidget::showDetails(bool show){
if(show && treeWidget == 0){
treeWidget = new DDTreeWidget(this);
this->layout()->addWidget(treeWidget);
+ retranslate();
if(!BROWSER->currentDirectory().isEmpty()){ emit dirChange(""); }
}else if(!show && listWidget==0){
listWidget = new DDListWidget(this);
@@ -59,6 +65,74 @@ bool BrowserWidget::hasDetails(){
return (treeWidget!=0);
}
+void BrowserWidget::setThumbnailSize(int px){
+ bool larger = true;
+ if(listWidget!=0){
+ larger = listWidget->iconSize().height() < px;
+ listWidget->setIconSize(QSize(px,px));
+ }else if(treeWidget!=0){
+ larger = treeWidget->iconSize().height() < px;
+ treeWidget->setIconSize(QSize(px,px));
+ }
+ if(BROWSER->currentDirectory().isEmpty() || !larger ){ return; } //don't need to reload icons unless the new size is larger
+ emit dirChange("");
+}
+
+QStringList BrowserWidget::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 BrowserWidget::readDateFormat() {
+ if(!date_format.isEmpty())
+ date_format.clear();
+ QSettings settings("lumina-desktop","sessionsettings");
+ // 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
+// =================
+void BrowserWidget::retranslate(){
+ if(listWidget!=0){
+
+ }else if(treeWidget!=0){
+ QTreeWidgetItem *it = new QTreeWidgetItem();
+ it->setText(0,tr("Name"));
+ it->setText(1,tr("Size"));
+ it->setText(2, tr("Type"));
+ it->setText(3, tr("Date Modified") );
+ it->setText(4, tr("Date Created") );
+ treeWidget->setHeaderItem(it);
+ //Now reset the sorting (alphabetically, dirs first)
+ treeWidget->sortItems(0, Qt::AscendingOrder); // sort by name
+ treeWidget->sortItems(1, Qt::AscendingOrder); //sort by type
+ }
+}
+
+// =================
+// PRIVATE
+// =================
+QString BrowserWidget::DTtoString(QDateTime dt){
+ QStringList fmt = getDateFormat();
+ if(fmt.isEmpty() || fmt.length()!=2 || (fmt[0].isEmpty() && fmt[1].isEmpty()) ){
+ //Default formatting
+ return dt.toString(Qt::DefaultLocaleShortDate);
+ }else if(fmt[0].isEmpty()){
+ //Time format only
+ return (dt.date().toString(Qt::DefaultLocaleShortDate)+" "+dt.time().toString(fmt[1]));
+ }else if(fmt[1].isEmpty()){
+ //Date format only
+ return (dt.date().toString(fmt[0])+" "+dt.time().toString(Qt::DefaultLocaleShortDate));
+ }else{
+ //both date/time formats set
+ return dt.toString(fmt.join(" "));
+ }
+}
+
// =================
// PRIVATE SLOTS
// =================
@@ -68,23 +142,53 @@ void BrowserWidget::clearItems(){
this->setEnabled(false);
}
-void BrowserWidget::itemUpdated(QString item){
- if(treeWidget==0){ return; } //only used for the tree widget/details
- qDebug() << "item updated" << item;
- QList<QTreeWidgetItem*> found = treeWidget->findItems(item.section("/",-1), Qt::MatchExactly, 0); //look for exact name match
- if(found.isEmpty()){ return; } //no match
- QTreeWidgetItem *it = found[0]; //only update the first match (should only ever be one - duplicate file names are disallowed)
- //it->setText(
+void BrowserWidget::itemRemoved(QString item){
+ //qDebug() << "item removed" << item;
+ if(treeWidget!=0){
+ QList<QTreeWidgetItem*> found = treeWidget->findItems(item.section("/",-1), Qt::MatchExactly, 0); //look for exact name match
+ if(found.isEmpty()){ return; } //no match
+ delete found[0];
+ }else if(listWidget!=0){
+ QList<QListWidgetItem*> found = listWidget->findItems(item.section("/",-1), Qt::MatchExactly); //look for exact name match
+ if(found.isEmpty()){ return; }
+ delete found[0];
+ }
}
void BrowserWidget::itemDataAvailable(QIcon ico, LFileInfo info){
qDebug() << "Item Data Available:" << info.fileName();
int num = 0;
if(listWidget!=0){
- listWidget->addItem( new QListWidgetItem(ico, info.fileName(), listWidget) );
+ //LIST WIDGET - name and icon only
+ if(!listWidget->findItems(info.fileName(), Qt::MatchExactly).isEmpty()){
+ //Update existing item
+ QListWidgetItem *it = listWidget->findItems(info.fileName(), Qt::MatchExactly).first();
+ it->setText(info.fileName());
+ it->setWhatsThis(info.absoluteFilePath());
+ it->setIcon(ico);
+ }else{
+ //New item
+ listWidget->addItem( new QListWidgetItem(ico, info.fileName(), listWidget) );
+ }
num = listWidget->count();
}else if(treeWidget!=0){
- //TODO
+ QTreeWidgetItem *it = 0;
+ if( ! treeWidget->findItems(info.fileName(), Qt::MatchExactly, 0).isEmpty() ){ it = treeWidget->findItems(info.fileName(), Qt::MatchExactly, 0).first(); }
+ else{
+ it = new CQTreeWidgetItem(treeWidget);
+ it->setText(0, info.fileName() ); //name (0)
+ treeWidget->addTopLevelItem(it);
+ }
+ //Now set/update all the data
+ it->setText(1, LUtils::BytesToDisplaySize(info.size()) ); //size (1)
+ it->setText(2, info.mimetype() ); //type (2)
+ it->setText(3, DTtoString(info.lastModified() )); //modification date (3)
+ it->setText(4, DTtoString(info.created()) ); //creation date (4)
+ //Now all the hidden data
+ it->setWhatsThis(0, info.absoluteFilePath());
+ it->setWhatsThis(3, info.lastModified().toString("yyyyMMddhhmmsszzz") ); //sorts by this actually
+ it->setWhatsThis(4, info.created().toString("yyyyMMddhhmmsszzz") ); //sorts by this actually
+ num = treeWidget->topLevelItemCount();
}
if(num < numItems){
//Still loading items
bgstack15