diff options
author | Ken Moore <ken@pcbsd.org> | 2016-09-22 16:41:42 -0400 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2016-09-22 16:41:42 -0400 |
commit | 82ebebfb8a5867b400c1df726a478bdcb9d7c005 (patch) | |
tree | 6c799a122fba9dc9068695f95e967e417f6b1636 /src-qt5/core/lumina-desktop/panel-plugins/systemstart | |
parent | Merge remote-tracking branch 'origin/master' (diff) | |
download | lumina-82ebebfb8a5867b400c1df726a478bdcb9d7c005.tar.gz lumina-82ebebfb8a5867b400c1df726a478bdcb9d7c005.tar.bz2 lumina-82ebebfb8a5867b400c1df726a478bdcb9d7c005.zip |
Large update to how XDGDesktop files are created/used.
This impacts almost all tools/utilities within Lumina - please test (passed internal tests so far).
This cleans up a lot of the backend XDG compliance class, moving lots of functionality into child functions of the XDGDesktop class and ensuring that they get cleaned up more regularly/properly. This *seems* to make the desktop startup a lot faster, even if the overall memory savings are slight (so far).
Diffstat (limited to 'src-qt5/core/lumina-desktop/panel-plugins/systemstart')
4 files changed, 51 insertions, 51 deletions
diff --git a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/ItemWidget.cpp b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/ItemWidget.cpp index 3a0493a3..48d9623a 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/ItemWidget.cpp +++ b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/ItemWidget.cpp @@ -16,8 +16,8 @@ ItemWidget::ItemWidget(QWidget *parent, QString itemPath, QString type, bool gob bool inHome = type.endsWith("-home"); //internal code if(inHome){ type = type.remove("-home"); } if(itemPath.endsWith(".desktop") || type=="app"){ - XDGDesktop item = LXDG::loadDesktopFile(itemPath, gooditem); - if(gooditem){ gooditem = LXDG::checkValidity(item); } + XDGDesktop item(itemPath, this); + gooditem = item.isValid(); //qDebug() << "Good Item:" << gooditem << itemPath; if(gooditem){ icon->setPixmap( LXDG::findIcon(item.icon, "preferences-system-windows-actions").pixmap(32,32) ); @@ -26,7 +26,7 @@ ItemWidget::ItemWidget(QWidget *parent, QString itemPath, QString type, bool gob if(!item.genericName.isEmpty() && item.name!=item.genericName){ text.append("<br><i> -- "+item.genericName+"</i>"); } name->setText(text); name->setToolTip(item.comment); - setupActions(item); + setupActions(&item); }else{ return; } @@ -89,13 +89,14 @@ ItemWidget::ItemWidget(QWidget *parent, QString itemPath, QString type, bool gob } // - Application constructor -ItemWidget::ItemWidget(QWidget *parent, XDGDesktop item) : QFrame(parent){ +ItemWidget::ItemWidget(QWidget *parent, XDGDesktop *item) : QFrame(parent){ + if(item==0){ return; } createWidget(); isDirectory = false; - if(LUtils::isFavorite(item.filePath)){ - linkPath = item.filePath; + if(LUtils::isFavorite(item->filePath)){ + linkPath = item->filePath; isShortcut=true; - }else if( item.filePath.section("/",0,-2)==QDir::homePath()+"/Desktop" ){ + }else if( item->filePath.section("/",0,-2)==QDir::homePath()+"/Desktop" ){ isShortcut = true; }else{ isShortcut = false; @@ -104,14 +105,14 @@ ItemWidget::ItemWidget(QWidget *parent, XDGDesktop item) : QFrame(parent){ name->setToolTip(icon->whatsThis()); //also allow the user to see the full shortcut path } //Now fill it appropriately - icon->setPixmap( LXDG::findIcon(item.icon,"preferences-system-windows-actions").pixmap(64,64) ); - text = item.name; - if(!item.genericName.isEmpty() && item.name!=item.genericName){ text.append("<br><i> -- "+item.genericName+"</i>"); } + icon->setPixmap( LXDG::findIcon(item->icon,"preferences-system-windows-actions").pixmap(64,64) ); + text = item->name; + if(!item->genericName.isEmpty() && item->name!=item->genericName){ text.append("<br><i> -- "+item->genericName+"</i>"); } name->setText(text); - name->setToolTip(item.comment); - this->setWhatsThis(item.name); - icon->setWhatsThis(item.filePath); - iconPath = item.icon; + name->setToolTip(item->comment); + this->setWhatsThis(item->name); + icon->setWhatsThis(item->filePath); + iconPath = item->icon; //Now setup the buttons appropriately setupContextMenu(); setupActions(item); @@ -176,14 +177,14 @@ void ItemWidget::setupContextMenu(){ } } -void ItemWidget::setupActions(XDGDesktop app){ - if(app.actions.isEmpty()){ actButton->setVisible(false); return; } +void ItemWidget::setupActions(XDGDesktop *app){ + if(app==0 || app->actions.isEmpty()){ actButton->setVisible(false); return; } //Actions Available - go ahead and list them all actButton->setMenu( new QMenu(this) ); - for(int i=0; i<app.actions.length(); i++){ - QAction *act = new QAction(LXDG::findIcon(app.actions[i].icon, app.icon), app.actions[i].name, this); - act->setToolTip(app.actions[i].ID); - act->setWhatsThis(app.actions[i].ID); + for(int i=0; i<app->actions.length(); i++){ + QAction *act = new QAction(LXDG::findIcon(app->actions[i].icon, app->icon), app->actions[i].name, this); + act->setToolTip(app->actions[i].ID); + act->setWhatsThis(app->actions[i].ID); actButton->menu()->addAction(act); } connect(actButton->menu(), SIGNAL(triggered(QAction*)), this, SLOT(actionClicked(QAction*)) ); diff --git a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/ItemWidget.h b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/ItemWidget.h index 8190de43..365b434f 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/ItemWidget.h +++ b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/ItemWidget.h @@ -32,7 +32,7 @@ public: // - Favorites (path/type) ItemWidget(QWidget *parent=0, QString itemPath="", QString type="unknown", bool goback=false); // - Generic Apps - ItemWidget(QWidget *parent=0, XDGDesktop item= XDGDesktop()); + ItemWidget(QWidget *parent=0, XDGDesktop *item= 0); // - Categories //ItemWidget(QWidget *parent=0, QString cat=""); @@ -53,7 +53,7 @@ private: void createWidget(); //void setupButton(bool disable = false); void setupContextMenu(); - void setupActions(XDGDesktop); + void setupActions(XDGDesktop*); void updateItems(); //update the text/icon to match sizes diff --git a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp index 60a313e8..ae61760b 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp +++ b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp @@ -23,7 +23,6 @@ StartMenu::StartMenu(QWidget *parent) : QWidget(parent), ui(new Ui::StartMenu){ searchTimer->setInterval(300); //~1/3 second searchTimer->setSingleShot(true); connect(searchTimer, SIGNAL(timeout()), this, SLOT(startSearch()) ); - sysapps = LSession::handle()->applicationMenu()->currentAppHash(); connect(LSession::handle()->applicationMenu(), SIGNAL(AppMenuUpdated()), this, SLOT(UpdateApps()) ); //Need to load the last used setting of the application list QString state = LSession::handle()->DesktopPluginSettings()->value("panelPlugs/systemstart/showcategories", "partial").toString(); @@ -72,9 +71,8 @@ void StartMenu::UpdateAll(){ if(QFile::exists(tmp)){ ui->tool_launch_controlpanel->setWhatsThis(tmp); //Now read the file to see which icon to use - bool ok = false; - XDGDesktop desk = LXDG::loadDesktopFile(tmp, ok); - if(ok && LXDG::checkValidity(desk)){ + XDGDesktop desk(tmp); + if(desk.isValid()){ ui->tool_launch_controlpanel->setIcon(LXDG::findIcon(desk.icon,"preferences-other")); }else{ ui->tool_launch_controlpanel->setVisible(false); } }else{ ui->tool_launch_controlpanel->setVisible(false); } @@ -83,9 +81,8 @@ void StartMenu::UpdateAll(){ if(QFile::exists(tmp)){ ui->tool_launch_store->setWhatsThis(tmp); //Now read the file to see which icon to use - bool ok = false; - XDGDesktop desk = LXDG::loadDesktopFile(tmp, ok); - if(ok && LXDG::checkValidity(desk)){ + XDGDesktop desk(tmp); + if(desk.isValid()){ ui->tool_launch_store->setIcon(LXDG::findIcon(desk.icon,"utilities-file-archiver")); }else{ ui->tool_launch_store->setVisible(false); } }else{ ui->tool_launch_store->setVisible(false); } @@ -158,8 +155,14 @@ void StartMenu::UpdateQuickLaunch(QString path, bool keep){ // ========================== // PRIVATE FUNCTIONS // ========================== +void StartMenu::deleteChildren(QObject *obj){ +for(int i=0; i<obj->children().count(); i++){ obj->children().at(i)->deleteLater(); } +} + void StartMenu::ClearScrollArea(QScrollArea *area){ - area->takeWidget()->deleteLater(); + QWidget *old = area->takeWidget(); + deleteChildren(old); //make sure we *fully* delete these items to save memory + old->deleteLater(); area->setWidget( new QWidget() ); //create a new widget in the scroll area area->widget()->setContentsMargins(0,0,0,0); QVBoxLayout *layout = new QVBoxLayout; @@ -216,18 +219,18 @@ void StartMenu::do_search(QString search, bool force){ QStringList found; //syntax: [<sorter>::::<mimetype>::::<filepath>] QString tmp = search; if(LUtils::isValidBinary(tmp)){ found << "0::::application/x-executable::::"+tmp; } - QList<XDGDesktop> apps = sysapps->value("All"); + QList<XDGDesktop*> apps = LSession::handle()->applicationMenu()->currentAppHash()->value("All"); for(int i=0; i<apps.length(); i++){ int priority = -1; - if(apps[i].name.toLower()==search.toLower()){ priority = 10; } - else if(apps[i].name.startsWith(search, Qt::CaseInsensitive)){ priority = 15; } - else if(apps[i].name.contains(search, Qt::CaseInsensitive)){ priority = 19; } - else if(apps[i].genericName.contains(search, Qt::CaseInsensitive)){ priority = 20; } - else if(apps[i].comment.contains(search, Qt::CaseInsensitive)){ priority = 30; } + if(apps[i]->name.toLower()==search.toLower()){ priority = 10; } + else if(apps[i]->name.startsWith(search, Qt::CaseInsensitive)){ priority = 15; } + else if(apps[i]->name.contains(search, Qt::CaseInsensitive)){ priority = 19; } + else if(apps[i]->genericName.contains(search, Qt::CaseInsensitive)){ priority = 20; } + else if(apps[i]->comment.contains(search, Qt::CaseInsensitive)){ priority = 30; } //Can add other filters here later if(priority>0){ - found << QString::number(priority)+"::::app::::"+apps[i].filePath; + found << QString::number(priority)+"::::app::::"+apps[i]->filePath; } } found.sort(Qt::CaseInsensitive); //sort by priority/type (lower numbers are higher on list) @@ -238,10 +241,8 @@ void StartMenu::do_search(QString search, bool force){ if(topsearch.isEmpty()){ topsearch = found[i].section("::::",2,-1); } ItemWidget *it = 0; if( found[i].section("::::",2,-1).endsWith(".desktop")){ - bool ok = false; - XDGDesktop item = LXDG::loadDesktopFile(found[i].section("::::",2,-1), ok); - if(ok){ ok = LXDG::checkValidity(item); } - if(ok){ it = new ItemWidget(ui->scroll_favs->widget(), item); } + XDGDesktop item(found[i].section("::::",2,-1)); + if(item.isValid()){ it = new ItemWidget(ui->scroll_favs->widget(), &item); } }else{ it = new ItemWidget(ui->scroll_favs->widget(), found[i].section("::::",2,-1), found[i].section("::::",1,1) ); } @@ -308,11 +309,11 @@ void StartMenu::UpdateApps(){ //qDebug() << " - Partially Checked"; //Show a single page of apps, but still divided up by categories CCat.clear(); - QStringList cats = sysapps->keys(); + QStringList cats = LSession::handle()->applicationMenu()->currentAppHash()->keys(); cats.sort(); cats.removeAll("All"); for(int c=0; c<cats.length(); c++){ - QList<XDGDesktop> apps = sysapps->value(cats[c]); + QList<XDGDesktop*> apps = LSession::handle()->applicationMenu()->currentAppHash()->value(cats[c]); if(apps.isEmpty()){ continue; } //Add the category label to the scroll QLabel *catlabel = new QLabel("<b>"+cats[c]+"</b>",ui->scroll_apps->widget()); @@ -335,7 +336,7 @@ void StartMenu::UpdateApps(){ //Only show categories to start with - and have the user click-into a cat to see apps if(CCat.isEmpty()){ //No cat selected yet - show cats only - QStringList cats = sysapps->keys(); + QStringList cats = LSession::handle()->applicationMenu()->currentAppHash()->keys(); cats.sort(); cats.removeAll("All"); //This is not a "real" category for(int c=0; c<cats.length(); c++){ @@ -352,7 +353,7 @@ void StartMenu::UpdateApps(){ ui->scroll_apps->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); //Show apps for this cat - QList<XDGDesktop> apps = sysapps->value(CCat); + QList<XDGDesktop*> apps = LSession::handle()->applicationMenu()->currentAppHash()->value(CCat); for(int i=0; i<apps.length(); i++){ //qDebug() << " - App:" << apps[i].name; ItemWidget *it = new ItemWidget(ui->scroll_apps->widget(), apps[i] ); @@ -368,7 +369,7 @@ void StartMenu::UpdateApps(){ }else{ //qDebug() << " - Not Checked"; //No categories at all - just alphabetize all the apps - QList<XDGDesktop> apps = sysapps->value("All"); + QList<XDGDesktop*> apps = LSession::handle()->applicationMenu()->currentAppHash()->value("All"); CCat.clear(); //Now add all the apps for this category for(int i=0; i<apps.length(); i++){ @@ -431,10 +432,8 @@ void StartMenu::UpdateFavs(){ if( !QFile::exists(tmp[i].section("::::",2,-1)) ){ continue; } //invalid favorite - skip it ItemWidget *it = 0; if( tmp[i].section("::::",2,-1).endsWith(".desktop")){ - bool ok = false; - XDGDesktop item = LXDG::loadDesktopFile(tmp[i].section("::::",2,-1), ok); - if(ok){ ok = LXDG::checkValidity(item); } - if(ok){ it = new ItemWidget(ui->scroll_favs->widget(), item); } + XDGDesktop item(tmp[i].section("::::",2,-1)); + if(item.isValid()){ it = new ItemWidget(ui->scroll_favs->widget(), &item); } }else{ it = new ItemWidget(ui->scroll_favs->widget(), tmp[i].section("::::",2,-1), tmp[i].section("::::",1,1) ); } diff --git a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.h b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.h index 9a629cc2..af7bd136 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.h +++ b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.h @@ -32,12 +32,12 @@ public slots: private: Ui::StartMenu *ui; - QHash<QString, QList<XDGDesktop> > *sysapps; QStringList favs; QString CCat, CSearch, topsearch; //current category/search QTimer *searchTimer; //Simple utility functions + void deleteChildren(QObject *obj); //recursive function void ClearScrollArea(QScrollArea *area); void SortScrollArea(QScrollArea *area); void do_search(QString search, bool force); |