aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp')
-rw-r--r--src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp195
1 files changed, 184 insertions, 11 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
index bec99667..e007b974 100644
--- a/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/BrowserWidget.cpp
@@ -11,22 +11,25 @@
#include <QSettings>
#include <LuminaUtils.h>
+#include <LuminaOS.h>
BrowserWidget::BrowserWidget(QString objID, QWidget *parent) : QWidget(parent){
//Setup the Widget/UI
this->setLayout( new QVBoxLayout(this) );
ID = objID;
- //this->setWhatsThis(objID);
//Setup the backend browser object
BROWSER = new Browser(this);
connect(BROWSER, SIGNAL(clearItems()), this, SLOT(clearItems()) );
- connect(BROWSER, SIGNAL(itemUpdated(QString)), this, SLOT(itemUpdated(QString)) );
+ connect(BROWSER, SIGNAL(itemRemoved(QString)), this, SLOT(itemRemoved(QString)) );
connect(BROWSER, SIGNAL(itemDataAvailable(QIcon, LFileInfo)), this, SLOT(itemDataAvailable(QIcon, LFileInfo)) );
connect(BROWSER, SIGNAL(itemsLoading(int)), this, SLOT(itemsLoading(int)) );
connect(this, SIGNAL(dirChange(QString)), BROWSER, SLOT(loadDirectory(QString)) );
listWidget = 0;
treeWidget = 0;
readDateFormat();
+ freshload = true; //nothing loaded yet
+ numItems = 0;
+
}
BrowserWidget::~BrowserWidget(){
@@ -34,37 +37,75 @@ BrowserWidget::~BrowserWidget(){
}
void BrowserWidget::changeDirectory(QString dir){
+ qDebug() << "Change Directory:" << dir << historyList;
if(BROWSER->currentDirectory()==dir){ return; } //already on this directory
+
+ if( !dir.contains("/.zfs/snapshot/") ){
+ if(historyList.isEmpty() || !dir.isEmpty()){ historyList << dir; }
+ }else{
+ //Need to remove the zfs snapshot first and ensure that it is not the same dir (just a diff snapshot)
+ QString cleaned = dir.replace( QRegExp("/\\.zfs/snapshot/(.)+/"), "/" );
+ if( (historyList.isEmpty() || historyList.last()!=cleaned) && !cleaned.isEmpty() ){ historyList << cleaned; }
+ }
+ qDebug() << "History:" << historyList;
emit dirChange(dir);
}
void BrowserWidget::showDetails(bool show){
//Clean up widgets first
+ QSize iconsize;
if(show && listWidget!=0){
//Clean up list widget
+ iconsize = listWidget->iconSize();
+ this->layout()->removeWidget(listWidget);
listWidget->deleteLater();
listWidget = 0;
}else if(!show && treeWidget!=0){
+ iconsize = treeWidget->iconSize();
+ this->layout()->removeWidget(treeWidget);
treeWidget->deleteLater();
treeWidget = 0;
}
+ qDebug() << "Create Widget: details:" << show;
//Now create any new widgets
if(show && treeWidget == 0){
treeWidget = new DDTreeWidget(this);
+ treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
+ if(!iconsize.isNull()){ treeWidget->setIconSize(iconsize); }
this->layout()->addWidget(treeWidget);
+ connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SIGNAL(itemsActivated()) );
+ connect(treeWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SIGNAL(contextMenuRequested()) );
+ connect(treeWidget, SIGNAL(DataDropped(QString, QStringList)), this, SIGNAL(DataDropped(QString, QStringList)) );
+ connect(treeWidget, SIGNAL(GotFocus()), this, SLOT(selectionChanged()) );
retranslate();
+ treeWidget->sortItems(0, Qt::AscendingOrder);
if(!BROWSER->currentDirectory().isEmpty()){ emit dirChange(""); }
}else if(!show && listWidget==0){
listWidget = new DDListWidget(this);
+ listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
+ if(!iconsize.isNull()){ listWidget->setIconSize(iconsize); }
this->layout()->addWidget(listWidget);
+ connect(listWidget, SIGNAL(itemActivated(QListWidgetItem*)), this, SIGNAL(itemsActivated()) );
+ connect(listWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SIGNAL(contextMenuRequested()) );
+ connect(listWidget, SIGNAL(DataDropped(QString, QStringList)), this, SIGNAL(DataDropped(QString, QStringList)) );
+ connect(listWidget, SIGNAL(GotFocus()), this, SLOT(selectionChanged()) );
if(!BROWSER->currentDirectory().isEmpty()){ emit dirChange(""); }
}
+ qDebug() << " Done making widget";
}
bool BrowserWidget::hasDetails(){
return (treeWidget!=0);
}
+void BrowserWidget::showHiddenFiles(bool show){
+ BROWSER->showHiddenFiles(show);
+}
+
+bool BrowserWidget::hasHiddenFiles(){
+ return BROWSER->showingHiddenFiles();
+}
+
void BrowserWidget::setThumbnailSize(int px){
bool larger = true;
if(listWidget!=0){
@@ -74,12 +115,31 @@ void BrowserWidget::setThumbnailSize(int px){
larger = treeWidget->iconSize().height() < px;
treeWidget->setIconSize(QSize(px,px));
}
+ //qDebug() << "Changing Icon Size:" << px << larger;
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;
+int BrowserWidget::thumbnailSize(){
+ if(listWidget!=0){ return listWidget->iconSize().height(); }
+ else if(treeWidget!=0){ return treeWidget->iconSize().height(); }
+ return 0;
+}
+
+void BrowserWidget::setHistory(QStringList paths){
+ //NOTE: later items are used first
+ historyList = paths;
+}
+
+QStringList BrowserWidget::history(){
+ return historyList;
+}
+
+void BrowserWidget::setShowActive(bool show){
+ if(!show){ this->setStyleSheet("QAbstractScrollArea{ background-color: rgba(10,10,10,10); }"); }
+ else{
+ this->setStyleSheet( "QAbstractScrollArea{ background-color: white; }");
+ }
}
// This function is only called if user changes sessionsettings. By doing so, operations like sorting by date
@@ -93,6 +153,51 @@ void BrowserWidget::readDateFormat() {
date_format << settings.value("TimeFormat").toString();
}
+
+QStringList BrowserWidget::currentSelection(){
+ QStringList out;
+ if(listWidget!=0){
+ QList<QListWidgetItem*> sel = listWidget->selectedItems();
+ //qDebug() << "Selection number:" << sel.length();
+ //if(sel.isEmpty() && listWidget->currentItem()!=0){ sel << listWidget->currentItem(); }
+ //qDebug() << "Selection number:" << sel.length();
+ for(int i=0; i<sel.length(); i++){ out << sel[i]->whatsThis(); qDebug() << "Selection:" << sel[i]->text() << sel[i]->whatsThis(); }
+ }else if(treeWidget!=0){
+ QList<QTreeWidgetItem*> sel = treeWidget->selectedItems();
+ //if(sel.isEmpty() && treeWidget->currentItem()!=0){ sel << treeWidget->currentItem(); }
+ for(int i=0; i<sel.length(); i++){ out << sel[i]->whatsThis(0); }
+ }
+ out.removeDuplicates(); //just in case - tree widgets sometimes "select" each column as an individual item
+ return out;
+}
+
+QStringList BrowserWidget::currentItems(int type){
+ //type: 0=all, -1=files, +1=dirs
+ QStringList paths;
+ if(listWidget!=0){
+ for(int i=0; i<listWidget->count(); i++){
+ if(i<0 && (listWidget->item(i)->data(Qt::UserRole).toString()=="file") ){ //FILES
+ paths << listWidget->item(i)->whatsThis();
+ }else if(i>0 && (listWidget->item(i)->data(Qt::UserRole).toString()=="dir")){ //DIRS
+ paths << listWidget->item(i)->whatsThis();
+ }else if(i==0){ //ALL
+ paths << listWidget->item(i)->whatsThis();
+ }
+ }
+ }else if(treeWidget!=0){
+ for(int i=0; i<treeWidget->topLevelItemCount(); i++){
+ if(i<0 && !treeWidget->topLevelItem(i)->text(1).isEmpty()){ //FILES
+ paths << treeWidget->topLevelItem(i)->whatsThis(0);
+ }else if(i>0 && treeWidget->topLevelItem(i)->text(1).isEmpty()){ //DIRS
+ paths << treeWidget->topLevelItem(i)->whatsThis(0);
+ }else if(i==0){ //ALL
+ paths << treeWidget->topLevelItem(i)->whatsThis(0);
+ }
+ }
+ }
+ return paths;
+}
+
// =================
// PUBLIC SLOTS
// =================
@@ -117,7 +222,7 @@ void BrowserWidget::retranslate(){
// PRIVATE
// =================
QString BrowserWidget::DTtoString(QDateTime dt){
- QStringList fmt = getDateFormat();
+ QStringList fmt = date_format;
if(fmt.isEmpty() || fmt.length()!=2 || (fmt[0].isEmpty() && fmt[1].isEmpty()) ){
//Default formatting
return dt.toString(Qt::DefaultLocaleShortDate);
@@ -137,9 +242,10 @@ QString BrowserWidget::DTtoString(QDateTime dt){
// PRIVATE SLOTS
// =================
void BrowserWidget::clearItems(){
+ //qDebug() << "Clear Items";
if(listWidget!=0){ listWidget->clear(); }
else if(treeWidget!=0){ treeWidget->clear(); }
- this->setEnabled(false);
+ freshload = true;
}
void BrowserWidget::itemRemoved(QString item){
@@ -156,7 +262,7 @@ void BrowserWidget::itemRemoved(QString item){
}
void BrowserWidget::itemDataAvailable(QIcon ico, LFileInfo info){
- qDebug() << "Item Data Available:" << info.fileName();
+ //qDebug() << "Item Data Available:" << info.fileName();
int num = 0;
if(listWidget!=0){
//LIST WIDGET - name and icon only
@@ -168,7 +274,10 @@ void BrowserWidget::itemDataAvailable(QIcon ico, LFileInfo info){
it->setIcon(ico);
}else{
//New item
- listWidget->addItem( new QListWidgetItem(ico, info.fileName(), listWidget) );
+ QListWidgetItem *it = new CQListWidgetItem(ico, info.fileName(), listWidget);
+ it->setWhatsThis(info.absoluteFilePath());
+ it->setData(Qt::UserRole, (info.isDir() ? "dir" : "file")); //used for sorting
+ listWidget->addItem(it);
}
num = listWidget->count();
}else if(treeWidget!=0){
@@ -180,7 +289,8 @@ void BrowserWidget::itemDataAvailable(QIcon ico, LFileInfo info){
treeWidget->addTopLevelItem(it);
}
//Now set/update all the data
- it->setText(1, LUtils::BytesToDisplaySize(info.size()) ); //size (1)
+ it->setIcon(0, ico);
+ it->setText(1, info.isDir() ? "" : 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)
@@ -194,11 +304,74 @@ void BrowserWidget::itemDataAvailable(QIcon ico, LFileInfo info){
//Still loading items
//this->setEnabled(false);
}else{
+ if(freshload && treeWidget!=0){
+ //qDebug() << "Resize Tree Widget Contents";
+ for(int i=0; i<treeWidget->columnCount(); i++){ treeWidget->resizeColumnToContents(i); }
+ }
+ freshload = false; //any further changes are updates - not a fresh load of a dir
//Done loading items
- this->setEnabled(true);
- }
+ //this->setEnabled(true);
+ //Assemble any status message
+ QString stats = QString(tr("Capacity: %1")).arg(LOS::FileSystemCapacity(BROWSER->currentDirectory()));
+ int nF, nD;
+ double bytes = 0;
+ nF = nD = 0;
+ if(listWidget!=0){
+ bytes = -1; //not supported for this widget
+ for(int i=0; i<listWidget->count(); i++){
+ if(listWidget->item(i)->data(Qt::UserRole).toString()=="dir"){ nD++; } //directory
+ else{ nF++; } //file
+ }
+ }else if(treeWidget!=0){
+ for(int i=0; i<treeWidget->topLevelItemCount(); i++){
+ if(treeWidget->topLevelItem(i)->text(1).isEmpty()){
+ nD++; //directory
+ }else{
+ nF++; //file
+ bytes+=LUtils::DisplaySizeToBytes(treeWidget->topLevelItem(i)->text(1));
+ }
+ }
+ }
+
+ if( (nF+nD) >0){
+ stats.prepend("\t");
+ if(nF>0){
+ //Has Files
+ if(bytes>0){
+ stats.prepend( QString(tr("Files: %1 (%2)")).arg(QString::number(nF), LUtils::BytesToDisplaySize(bytes)) );
+ }else{
+ stats.prepend( QString(tr("Files: %1")).arg(QString::number(nF)) );
+ }
+ }
+ if(nD > 0){
+ //Has Dirs
+ if(nF>0){ stats.prepend(" / "); }//has files output already
+ stats.prepend( QString(tr("Dirs: %1")).arg(QString::number(nD)) );
+ }
+ }
+ emit updateDirectoryStatus( stats.simplified() );
+ statustip = stats.simplified(); //save for later
+ }//end check for finished loading items
}
void BrowserWidget::itemsLoading(int total){
+ //qDebug() << "Got number of items loading:" << total;
numItems = total; //save this for later
+ if(total<1){
+ emit updateDirectoryStatus( tr("No Directory Contents") );
+ this->setEnabled(true);
+ }
+}
+
+void BrowserWidget::selectionChanged(){
+ emit hasFocus(ID); //let the parent know the widget is "active" with the user
+}
+
+void BrowserWidget::resizeEvent(QResizeEvent *ev){
+ QWidget::resizeEvent(ev); //do the normal processing first
+ //The list widget needs to be poked to rearrange the items to fit the new size
+ // tree widget does this fine at the moment.
+ if(listWidget!=0){
+ listWidget->sortItems(Qt::AscendingOrder);
+ }
}
bgstack15