aboutsummaryrefslogtreecommitdiff
path: root/lumina-desktop/panel-plugins/userbutton
diff options
context:
space:
mode:
authorwi <william.os4y@gmail.com>2015-05-01 18:38:55 +0200
committerwi <william.os4y@gmail.com>2015-05-01 18:38:55 +0200
commit2b143927e0363fd41b138a6955f9e9363b71b443 (patch)
tree6366bcbd5842e42e52f1429f4e7232f678778f67 /lumina-desktop/panel-plugins/userbutton
parentuse the termnial application specified by the user as the default-terminal. (diff)
parentFix/Fix a couple important bugs before announcing 0.8.4-release: (diff)
downloadlumina-2b143927e0363fd41b138a6955f9e9363b71b443.tar.gz
lumina-2b143927e0363fd41b138a6955f9e9363b71b443.tar.bz2
lumina-2b143927e0363fd41b138a6955f9e9363b71b443.zip
Merge remote-tracking branch 'upstream/master' into fm-term
Diffstat (limited to 'lumina-desktop/panel-plugins/userbutton')
-rw-r--r--lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp44
-rw-r--r--lumina-desktop/panel-plugins/userbutton/UserItemWidget.h6
-rw-r--r--lumina-desktop/panel-plugins/userbutton/UserWidget.cpp85
-rw-r--r--lumina-desktop/panel-plugins/userbutton/UserWidget.h7
-rw-r--r--lumina-desktop/panel-plugins/userbutton/UserWidget.ui109
5 files changed, 156 insertions, 95 deletions
diff --git a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp
index a04c6e43..ad1c2fd6 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 <LuminaUtils.h>
-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"));
@@ -113,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();
}
}
@@ -125,4 +137,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..9c002109 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
//===========================================
@@ -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
@@ -85,6 +87,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 +150,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 +167,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: <name>::::[app/dir/<mimetype>]::::<full path>
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; i<homefiles.length(); i++){
+ if(homefiles[i].fileName().endsWith(".desktop")){
+ favitems << homefiles[i].fileName()+"::::app::::"+homefiles[i].absoluteFilePath();
+ }
+ }
}else if(ui->tool_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; i<homefiles.length(); i++){
+ if(homefiles[i].isDir()){
+ favitems << homefiles[i].fileName()+"::::dir::::"+homefiles[i].absoluteFilePath();
+ }
+ }
}else{
//Files
- items = homedir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name);
- items << favdir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name);
- for(int i=0; i<items.length(); i++){
- if(items[i].suffix()=="desktop"){ items.removeAt(i); i--; }
+ for(int i=0; i<favs.length(); i++){
+ QString type = favs[i].section("::::",1,1);
+ if(type != "app" && type !="dir"){
+ favitems << favs[i];
+ }
+ }
+ for(int i=0; i<homefiles.length(); i++){
+ if(!homefiles[i].isDir() && !homefiles[i].fileName().endsWith(".desktop") ){
+ favitems << homefiles[i].fileName()+"::::"+LXDG::findAppMimeForFile(homefiles[i].fileName())+"::::"+homefiles[i].absoluteFilePath();
+ }
}
}
- for(int i=0; i<items.length(); i++){
- UserItemWidget *it = new UserItemWidget(ui->scroll_fav->widget(), items[i].absoluteFilePath(), ui->tool_fav_dirs->isChecked());
+ ClearScrollArea(ui->scroll_fav);
+ favitems.sort(); //sort them alphabetically
+ for(int i=0; i<favitems.length(); i++){
+ UserItemWidget *it = new UserItemWidget(ui->scroll_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 +221,6 @@ void UserWidget::updateFavItems(){
}
static_cast<QBoxLayout*>(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; i<items.length(); i++){
- if(items[i].isSymLink() && !items[i].exists()){
- //Broken sym-link - remove it
- QFile::remove(items[i].absoluteFilePath());
- }
- }*/
-
}
//Apps Tab
@@ -268,8 +285,8 @@ void UserWidget::updateHome(){
for(int i=0; i<items.length(); i++){
//qDebug() << "New Home subdir:" << homedir.absoluteFilePath(items[i]);
UserItemWidget *it;
- if(items[i].startsWith("/")){ it = new UserItemWidget(ui->scroll_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()) );
@@ -282,7 +299,7 @@ void UserWidget::slotGoToDir(QString dir){
ui->label_home_dir->setWhatsThis(dir);
updateHome();
}
-
+
void UserWidget::slotGoHome(){
slotGoToDir(QDir::homePath());
}
@@ -290,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
@@ -300,4 +321,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..2dce25b4 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<QString, QList<XDGDesktop> > *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();
@@ -63,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 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
- <number>3</number>
+ <number>2</number>
</property>
<widget class="QWidget" name="tab_fav">
<attribute name="title">
@@ -170,8 +170,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>98</width>
- <height>28</height>
+ <width>260</width>
+ <height>247</height>
</rect>
</property>
</widget>
@@ -276,8 +276,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>98</width>
- <height>28</height>
+ <width>260</width>
+ <height>247</height>
</rect>
</property>
</widget>
@@ -309,11 +309,61 @@
<number>1</number>
</property>
<item>
- <layout class="QHBoxLayout" name="horizontalLayout_3">
- <property name="spacing">
+ <layout class="QGridLayout" name="gridLayout">
+ <property name="horizontalSpacing">
+ <number>4</number>
+ </property>
+ <property name="verticalSpacing">
<number>1</number>
</property>
- <item>
+ <item row="0" column="3">
+ <widget class="QToolButton" name="tool_home_search">
+ <property name="toolTip">
+ <string>Search this Directory</string>
+ </property>
+ <property name="text">
+ <string notr="true"/>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QToolButton" name="tool_home_browse">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="toolTip">
+ <string>Open Directory</string>
+ </property>
+ <property name="text">
+ <string notr="true">Browse</string>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonIconOnly</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
<widget class="QToolButton" name="tool_home_gohome">
<property name="minimumSize">
<size>
@@ -338,8 +388,14 @@
</property>
</widget>
</item>
- <item>
+ <item row="0" column="1">
<widget class="QLabel" name="label_home_dir">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="minimumSize">
<size>
<width>0</width>
@@ -376,37 +432,6 @@
</property>
</widget>
</item>
- <item>
- <widget class="QToolButton" name="tool_home_browse">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>90</width>
- <height>30</height>
- </size>
- </property>
- <property name="toolTip">
- <string>Open Directory</string>
- </property>
- <property name="text">
- <string notr="true">Browse</string>
- </property>
- <property name="iconSize">
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- <property name="toolButtonStyle">
- <enum>Qt::ToolButtonTextBesideIcon</enum>
- </property>
- </widget>
- </item>
</layout>
</item>
<item>
@@ -419,8 +444,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>98</width>
- <height>28</height>
+ <width>260</width>
+ <height>247</height>
</rect>
</property>
</widget>
bgstack15