From ddf397d485ddb2cc391f8e0e7fe74642891d62e9 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 27 Apr 2015 15:05:03 -0400 Subject: Setup the lumina-desktop to use the new favorites system: 1) Convert any old system to the new one on login (0.8.4-devel users will need to wait until 0.8.4-release or 0.8.5-devel - the next change to the session version). 2) Update the User Buton plugin to use the new system and streamline when it actually probes the filesystem for changes (makes it even faster) 3) Update the Desktop Bar plugin to use the new system as well. --- .../panel-plugins/userbutton/UserItemWidget.cpp | 38 +++++++---- .../panel-plugins/userbutton/UserItemWidget.h | 6 +- .../panel-plugins/userbutton/UserWidget.cpp | 75 +++++++++++++--------- .../panel-plugins/userbutton/UserWidget.h | 6 +- 4 files changed, 76 insertions(+), 49 deletions(-) (limited to 'lumina-desktop/panel-plugins/userbutton') diff --git a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp index a04c6e43..5a6a9f09 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp +++ b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp @@ -1,15 +1,16 @@ //=========================================== // Lumina-DE source code -// Copyright (c) 2014, Ken Moore +// Copyright (c) 2014-2015, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== #include "UserItemWidget.h" +#include -UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, bool isDir, bool goback) : QFrame(parent){ +UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, QString type, bool goback) : QFrame(parent){ createWidget(); //Now fill it appropriately - if(itemPath.endsWith(".desktop")){ + if(itemPath.endsWith(".desktop") || type=="app"){ bool ok = false; XDGDesktop item = LXDG::loadDesktopFile(itemPath, ok); if(ok){ @@ -19,7 +20,7 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, bool isDir, bo icon->setPixmap( LXDG::findIcon("unknown","").pixmap(32,32) ); name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, 180) ); } - }else if(isDir){ + }else if(type=="dir"){ if(itemPath.endsWith("/")){ itemPath.chop(1); } if(goback){ icon->setPixmap( LXDG::findIcon("go-previous","").pixmap(32,32) ); @@ -30,14 +31,17 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, bool isDir, bo } }else{ if(itemPath.endsWith("/")){ itemPath.chop(1); } - icon->setPixmap( LXDG::findMimeIcon(itemPath.section("/",-1)).pixmap(32,32) ); + icon->setPixmap( LXDG::findMimeIcon(type).pixmap(32,32) ); name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, 180) ); } - linkPath = QFile::symLinkTarget(itemPath); icon->setWhatsThis(itemPath); - if(isDir && !linkPath.isEmpty()){ isDir = false; } //not a real directory - just a sym link - isDirectory = isDir; //save this for later - isShortcut = itemPath.contains("/home/") && (itemPath.contains("/Desktop/") || itemPath.contains("/.lumina/favorites/") ); + isDirectory = (type=="dir"); //save this for later + if(LUtils::isFavorite(itemPath)){ + linkPath = itemPath; + isShortcut=true; + }else if( itemPath.section("/",0,-2)==QDir::homePath()+"/Desktop" ){ + isShortcut = true; + } //Now setup the button appropriately setupButton(goback); } @@ -45,8 +49,14 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, bool isDir, bo UserItemWidget::UserItemWidget(QWidget *parent, XDGDesktop item) : QFrame(parent){ createWidget(); isDirectory = false; - linkPath = QFile::symLinkTarget(item.filePath); - isShortcut = item.filePath.contains("/home/") && (item.filePath.contains("/Desktop/") || item.filePath.contains("/.lumina/favorites/") ); + if(LUtils::isFavorite(item.filePath)){ + linkPath = item.filePath; + isShortcut=true; + }else if( item.filePath.section("/",0,-2)==QDir::homePath()+"/Desktop" ){ + isShortcut = true; + }else{ + isShortcut = false; + } //Now fill it appropriately icon->setPixmap( LXDG::findIcon(item.icon,"preferences-system-windows-actions").pixmap(32,32) ); name->setText( this->fontMetrics().elidedText(item.name, Qt::ElideRight, 180) ); @@ -98,8 +108,8 @@ void UserItemWidget::setupButton(bool disable){ button->setToolTip(tr("Delete File")); } connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()) ); - }else if( !QFile::exists( QDir::homePath()+"/Desktop/"+icon->whatsThis().section("/",-1) ) && !QFile::exists( QDir::homePath()+"/.lumina/favorites/"+icon->whatsThis().section("/",-1) ) ){ - //This file does not have a desktop shortcut yet -- allow the user to add it + }else if( !QFile::exists( QDir::homePath()+"/Desktop/"+icon->whatsThis().section("/",-1) ) && !LUtils::isFavorite(icon->whatsThis() ) ){ + //This file does not have a shortcut yet -- allow the user to add it button->setWhatsThis("add"); button->setIcon( LXDG::findIcon("bookmark-toolbar","") ); button->setToolTip(tr("Create Shortcut")); @@ -125,4 +135,4 @@ void UserItemWidget::ItemClicked(){ if(!linkPath.isEmpty()){ emit RunItem(linkPath); } else{ emit RunItem(icon->whatsThis()); } -} \ No newline at end of file +} diff --git a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h index 1f428ac4..a65d3e83 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h +++ b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h @@ -1,6 +1,6 @@ //=========================================== // Lumina-DE source code -// Copyright (c) 2014, Ken Moore +// Copyright (c) 2014-2015, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== @@ -25,7 +25,7 @@ class UserItemWidget : public QFrame{ Q_OBJECT public: - UserItemWidget(QWidget *parent=0, QString itemPath="", bool isDir=false, bool goback=false); + UserItemWidget(QWidget *parent=0, QString itemPath="", QString type="unknown", bool goback=false); UserItemWidget(QWidget *parent=0, XDGDesktop item= XDGDesktop()); ~UserItemWidget(); @@ -54,4 +54,4 @@ signals: }; -#endif \ No newline at end of file +#endif diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp index 52d60714..404fcc26 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp +++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp @@ -1,6 +1,6 @@ //=========================================== // Lumina-DE source code -// Copyright (c) 2014, Ken Moore +// Copyright (c) 2014-2015, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== @@ -85,6 +85,7 @@ UserWidget::UserWidget(QWidget* parent) : QTabWidget(parent), ui(new Ui::UserWid ui->tool_qtconfig->setVisible(false); } lastUpdate = QDateTime(); //make sure it refreshes + connect(LSession::handle()->applicationMenu(), SIGNAL(AppMenuUpdated()), this, SLOT(UpdateMenu()) ); QTimer::singleShot(10,this, SLOT(UpdateMenu())); //make sure to load this once after initialization } @@ -147,6 +148,7 @@ void UserWidget::LaunchItem(QString path, bool fix){ void UserWidget::FavChanged(){ //uncheck the current item for a moment + int oldfav = cfav; if(cfav==0){ ui->tool_fav_apps->setChecked(false); } else if(cfav==1){ ui->tool_fav_dirs->setChecked(false); } if(cfav==2){ ui->tool_fav_files->setChecked(false); } @@ -163,31 +165,53 @@ void UserWidget::FavChanged(){ ui->tool_fav_dirs->setChecked(cfav==1); ui->tool_fav_files->setChecked(cfav==2); } - updateFavItems(); + updateFavItems(oldfav!=cfav); } -void UserWidget::updateFavItems(){ - ClearScrollArea(ui->scroll_fav); - QFileInfoList items; - QDir homedir = QDir( QDir::homePath()+"/Desktop"); - QDir favdir = QDir( QDir::homePath()+"/.lumina/favorites"); - if(!favdir.exists()){ favdir.mkpath( QDir::homePath()+"/.lumina/favorites"); } +void UserWidget::updateFavItems(bool newfilter){ + QStringList newfavs = LUtils::listFavorites(); + //qDebug() << "Favorites:" << newfavs; + if(lastHomeUpdate.isNull() || (QFileInfo(QDir::homePath()+"/Desktop").lastModified() > lastHomeUpdate) || newfavs!=favs ){ + favs = newfavs; + + QDir homedir = QDir( QDir::homePath()+"/Desktop"); + homefiles = homedir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); + lastHomeUpdate = QDateTime::currentDateTime(); + }else if(!newfilter){ return; } //nothing new to change - stop now + QStringList favitems; + //Remember for format for favorites: ::::[app/dir/]:::: if(ui->tool_fav_apps->isChecked()){ - items = homedir.entryInfoList(QStringList()<<"*.desktop", QDir::Files | QDir::NoDotAndDotDot, QDir::Name); - items << favdir.entryInfoList(QStringList()<<"*.desktop", QDir::Files | QDir::NoDotAndDotDot, QDir::Name); + favitems = favs.filter("::::app::::"); + for(int i=0; itool_fav_dirs->isChecked()){ - items = homedir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); - items << favdir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); + favitems = favs.filter("::::dir::::"); + for(int i=0; iscroll_fav->widget(), items[i].absoluteFilePath(), ui->tool_fav_dirs->isChecked()); + ClearScrollArea(ui->scroll_fav); + favitems.sort(); //sort them alphabetically + for(int i=0; iscroll_fav->widget(), favitems[i].section("::::",2,50), favitems[i].section("::::",1,1) , ui->tool_fav_dirs->isChecked()); ui->scroll_fav->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) ); @@ -195,15 +219,6 @@ void UserWidget::updateFavItems(){ } static_cast(ui->scroll_fav->widget()->layout())->addStretch(); - //Clean up any broken sym-links in the favorites directory - /*items = favdir.entryInfoList(QDir::System | QDir::NoDotAndDotDot, QDir::Name); - for(int i=0; iscroll_home->widget(), items[i], true, true); } - else{ it = new UserItemWidget(ui->scroll_home->widget(), homedir.absoluteFilePath(items[i]), true, false); } + if(items[i].startsWith("/")){ it = new UserItemWidget(ui->scroll_home->widget(), items[i], "dir", true); } + else{ it = new UserItemWidget(ui->scroll_home->widget(), homedir.absoluteFilePath(items[i]), "dir", false); } ui->scroll_home->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(slotGoToDir(QString)) ); connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) ); @@ -300,4 +315,4 @@ void UserWidget::mouseMoveEvent( QMouseEvent *event){ qDebug() << " - Mouse over tab"; this->setCurrentIndex( wid->tabAt(relpos) ); } -} \ No newline at end of file +} diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.h b/lumina-desktop/panel-plugins/userbutton/UserWidget.h index c7af2a4d..8f5ba852 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserWidget.h +++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.h @@ -42,7 +42,9 @@ public slots: private: Ui::UserWidget *ui; QHash > *sysapps; - QDateTime lastUpdate; + QDateTime lastUpdate, lastHomeUpdate; + QStringList favs; + QFileInfoList homefiles; int cfav; //current favorite category void ClearScrollArea(QScrollArea *area); QIcon rotateIcon(QIcon); @@ -52,7 +54,7 @@ private slots: //Favorites Tab void FavChanged(); //for ensuring radio-button-like behaviour - void updateFavItems(); + void updateFavItems(bool newfilter = true); //if false, will only update if filesystem changes //Apps Tab void updateAppCategories(); -- cgit From 70fff959f4cb8fe4b0aa4dcbbb674237120fc63c Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 27 Apr 2015 16:28:58 -0400 Subject: Oops, forgot to change over the userbutton to use the new favorites system for creating/removing favorites. --- lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lumina-desktop/panel-plugins/userbutton') diff --git a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp index 5a6a9f09..ad1c2fd6 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp +++ b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp @@ -123,10 +123,12 @@ void UserItemWidget::setupButton(bool disable){ void UserItemWidget::buttonClicked(){ button->setVisible(false); if(button->whatsThis()=="add"){ - QFile::link(icon->whatsThis(), QDir::homePath()+"/.lumina/favorites/"+icon->whatsThis().section("/",-1) ); + LUtils::addFavorite(icon->whatsThis()); + //QFile::link(icon->whatsThis(), QDir::homePath()+"/.lumina/favorites/"+icon->whatsThis().section("/",-1) ); emit NewShortcut(); }else if(button->whatsThis()=="remove"){ - QFile::remove(icon->whatsThis()); //never remove the linkPath - since that is the actual file/dir + if(linkPath.isEmpty()){ QFile::remove(icon->whatsThis()); } //This is a desktop file + else{ LUtils::removeFavorite(icon->whatsThis()); } //This is a favorite emit RemovedShortcut(); } } -- cgit From abcb33d72ce3eeabd79cf4a15b7f49476b74cb56 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 28 Apr 2015 08:50:51 -0400 Subject: Add a button to the userbutton "home dir" section for starting a search of the selected directory. Also enable the use of lumina-fileinfo for *any* file within the desktopview plugin. --- .../panel-plugins/userbutton/UserWidget.cpp | 10 +- .../panel-plugins/userbutton/UserWidget.h | 1 + .../panel-plugins/userbutton/UserWidget.ui | 109 +++++++++++++-------- 3 files changed, 76 insertions(+), 44 deletions(-) (limited to 'lumina-desktop/panel-plugins/userbutton') diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp index 404fcc26..9c002109 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp +++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp @@ -35,6 +35,7 @@ UserWidget::UserWidget(QWidget* parent) : QTabWidget(parent), ui(new Ui::UserWid ui->tool_config_screensettings->setIcon( LXDG::findIcon("preferences-other","") ); ui->tool_home_gohome->setIcon( LXDG::findIcon("go-home","") ); ui->tool_home_browse->setIcon( LXDG::findIcon("document-open","") ); + ui->tool_home_search->setIcon( LXDG::findIcon("system-search","") ); ui->tool_config_about->setIcon( LXDG::findIcon("lumina","") ); //Connect the signals/slots connect(ui->tool_desktopsettings, SIGNAL(clicked()), this, SLOT(openDeskSettings()) ); @@ -46,6 +47,7 @@ UserWidget::UserWidget(QWidget* parent) : QTabWidget(parent), ui(new Ui::UserWid connect(ui->combo_app_cats, SIGNAL(currentIndexChanged(int)), this, SLOT(updateApps()) ); connect(ui->tool_home_gohome, SIGNAL(clicked()), this, SLOT(slotGoHome()) ); connect(ui->tool_home_browse, SIGNAL(clicked()), this, SLOT(slotOpenDir()) ); + connect(ui->tool_home_search, SIGNAL(clicked()), this, SLOT(slotOpenSearch()) ); connect(ui->tool_config_about, SIGNAL(clicked()), this, SLOT(openLuminaInfo()) ); //Setup the special buttons @@ -297,7 +299,7 @@ void UserWidget::slotGoToDir(QString dir){ ui->label_home_dir->setWhatsThis(dir); updateHome(); } - + void UserWidget::slotGoHome(){ slotGoToDir(QDir::homePath()); } @@ -305,7 +307,11 @@ void UserWidget::slotGoHome(){ void UserWidget::slotOpenDir(){ LaunchItem(ui->label_home_dir->whatsThis()); } - + +void UserWidget::slotOpenSearch(){ + LaunchItem("lumina-search -dir \""+ui->label_home_dir->whatsThis()+"\"", false); //use command as-is +} + void UserWidget::mouseMoveEvent( QMouseEvent *event){ QTabBar *wid = tabBar(); if(wid==0){ return; } //invalid widget found diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.h b/lumina-desktop/panel-plugins/userbutton/UserWidget.h index 8f5ba852..2dce25b4 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserWidget.h +++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.h @@ -65,6 +65,7 @@ private slots: void slotGoToDir(QString dir); void slotGoHome(); void slotOpenDir(); + void slotOpenSearch(); //Slots for the special buttons void openStore(){ diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.ui b/lumina-desktop/panel-plugins/userbutton/UserWidget.ui index f00daf08..bce684fd 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserWidget.ui +++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.ui @@ -17,7 +17,7 @@ QTabWidget::West - 3 + 2 @@ -170,8 +170,8 @@ 0 0 - 98 - 28 + 260 + 247 @@ -276,8 +276,8 @@ 0 0 - 98 - 28 + 260 + 247 @@ -309,11 +309,61 @@ 1 - - + + + 4 + + 1 - + + + + Search this Directory + + + + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + + 30 + 30 + + + + Open Directory + + + Browse + + + + 20 + 20 + + + + Qt::ToolButtonIconOnly + + + + @@ -338,8 +388,14 @@ - + + + + 0 + 0 + + 0 @@ -376,37 +432,6 @@ - - - - - 0 - 0 - - - - - 90 - 30 - - - - Open Directory - - - Browse - - - - 20 - 20 - - - - Qt::ToolButtonTextBesideIcon - - - @@ -419,8 +444,8 @@ 0 0 - 98 - 28 + 260 + 247 -- cgit