diff options
Diffstat (limited to 'src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp')
-rw-r--r-- | src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp | 119 |
1 files changed, 72 insertions, 47 deletions
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..d05ba22f 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp +++ b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/StartMenu.cpp @@ -23,8 +23,8 @@ 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()) ); + connect(LSession::handle(), SIGNAL(FavoritesChanged()), this, SLOT(UpdateFavs()) ); //Need to load the last used setting of the application list QString state = LSession::handle()->DesktopPluginSettings()->value("panelPlugs/systemstart/showcategories", "partial").toString(); if(state=="partial"){ui->check_apps_showcats->setCheckState(Qt::PartiallyChecked); } @@ -72,9 +72,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 +82,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); } @@ -131,7 +129,7 @@ void StartMenu::UpdateMenu(bool forceall){ if(forceall){ UpdateAll(); } //Quick update routine before the menu is made visible //qDebug() << "update favs"; - UpdateFavs(); + //UpdateFavs(); //qDebug() << "check page"; if(ui->stackedWidget->currentWidget() != ui->page_main){ ui->stackedWidget->setCurrentWidget(ui->page_main); //just show the main page @@ -158,16 +156,45 @@ void StartMenu::UpdateQuickLaunch(QString path, bool keep){ // ========================== // PRIVATE FUNCTIONS // ========================== +/*void StartMenu::deleteChildren(QWidget *obj){ + if(obj->layout()==0){ + for(int i=0; i<obj->children().count(); i++){ + obj->children().at(i)->deleteLater(); + } + }else{ + + } +}*/ + void StartMenu::ClearScrollArea(QScrollArea *area){ - area->takeWidget()->deleteLater(); - area->setWidget( new QWidget() ); //create a new widget in the scroll area - area->widget()->setContentsMargins(0,0,0,0); - QVBoxLayout *layout = new QVBoxLayout; + //QWidget *old = area->takeWidget(); + //qDebug() << "Clear Scroll Area:"; + //if(old->layout()!=0){ qDebug() << " - Number of items in layout:" << old->layout()->count(); } + //qDebug() << " - Number of Children:" << old->children().count(); + //deleteChildren(old); //make sure we *fully* delete these items to save memory + //old->deleteLater(); + if(area == ui->scroll_favs){ + area->takeWidget()->deleteLater(); + } + if(area->widget()==0){ + area->setWidget( new QWidget(area) ); //create a new widget in the scroll area + } + if(area->widget()->layout()==0){ + QVBoxLayout *layout = new QVBoxLayout(area->widget()); layout->setSpacing(2); layout->setContentsMargins(3,1,3,1); layout->setDirection(QBoxLayout::TopToBottom); layout->setAlignment(Qt::AlignTop); + area->widget()->setContentsMargins(0,0,0,0); area->widget()->setLayout(layout); + } + //Now clear the items in the layout + while( area->widget()->layout()->count() >0 ){ + QLayoutItem *it = area->widget()->layout()->takeAt(0); + //Need to delete both the widget and the layout item + if(it->widget()!=0){ it->widget()->deleteLater(); } + delete it; + } } void StartMenu::SortScrollArea(QScrollArea *area){ @@ -216,18 +243,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 +265,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) ); } @@ -302,17 +327,17 @@ void StartMenu::ChangeCategory(QString cat){ //Listing Update routines void StartMenu::UpdateApps(){ ClearScrollArea(ui->scroll_apps); - //Now assemble the apps list (note: this normally happens in the background - not when it is visible/open) - //qDebug() << "Update Apps:" << CCat << ui->check_apps_showcats->checkState(); + //Now assemble the apps list + //qDebug() << "Update Apps:";// << CCat << ui->check_apps_showcats->checkState(); if(ui->check_apps_showcats->checkState() == Qt::PartiallyChecked){ //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()); @@ -321,7 +346,7 @@ void StartMenu::UpdateApps(){ //Now add all the apps for this category for(int i=0; i<apps.length(); i++){ ItemWidget *it = new ItemWidget(ui->scroll_apps->widget(), apps[i] ); - if(!it->gooditem){ continue; } //invalid for some reason + if(!it->gooditem){ qDebug() << "Invalid Item:"; it->deleteLater(); continue; } //invalid for some reason ui->scroll_apps->widget()->layout()->addWidget(it); connect(it, SIGNAL(NewShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(UpdateFavs()) ); @@ -335,12 +360,12 @@ 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++){ ItemWidget *it = new ItemWidget(ui->scroll_apps->widget(), cats[c], "chcat::::"+cats[c] ); - if(!it->gooditem){ continue; } //invalid for some reason + if(!it->gooditem){ qDebug() << "Invalid Item:";it->deleteLater(); continue; } //invalid for some reason ui->scroll_apps->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); } @@ -352,11 +377,11 @@ 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] ); - if(!it->gooditem){ continue; } //invalid for some reason + if(!it->gooditem){ qDebug() << "Invalid Item:"; it->deleteLater(); continue; } //invalid for some reason ui->scroll_apps->widget()->layout()->addWidget(it); connect(it, SIGNAL(NewShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(UpdateFavs()) ); @@ -368,12 +393,12 @@ 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++){ + for(int i=0; i<apps.length(); i++){ ItemWidget *it = new ItemWidget(ui->scroll_apps->widget(), apps[i] ); - if(!it->gooditem){ continue; } //invalid for some reason + if(!it->gooditem){ it->deleteLater(); continue; } //invalid for some reason ui->scroll_apps->widget()->layout()->addWidget(it); connect(it, SIGNAL(NewShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(UpdateFavs()) ); @@ -387,7 +412,7 @@ void StartMenu::UpdateApps(){ void StartMenu::UpdateFavs(){ //SYNTAX NOTE: (per-line) "<name>::::[dir/app/<mimetype>]::::<path>" - QStringList newfavs = LUtils::listFavorites(); + QStringList newfavs = LDesktopUtils::listFavorites(); if(favs == newfavs){ return; } //nothing to do - same as before favs = newfavs; ClearScrollArea(ui->scroll_favs); @@ -400,10 +425,11 @@ void StartMenu::UpdateFavs(){ else if(type==1){ tmp = favs.filter("::::dir::::"); } //dirs next else{ tmp = rest; } //everything left over if(type==1){ + SortScrollArea(ui->scroll_favs); //Need to run a special routine for sorting the apps (already in the widget) //qDebug() << "Sort App Widgets..."; // Since each app actually might have a different name listed within the file - QLayout *lay = ui->scroll_favs->widget()->layout(); + /*QLayout *lay = ui->scroll_favs->widget()->layout(); QStringList items; for(int i=0; i<lay->count(); i++){ items << lay->itemAt(i)->widget()->whatsThis().toLower(); @@ -423,7 +449,8 @@ void StartMenu::UpdateFavs(){ break; } } - } + }*/ + }//end of special app sorting routine tmp.sort(); //Sort alphabetically by name (dirs/files) for(int i=0; i<tmp.length(); i++){ @@ -431,10 +458,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) ); } @@ -448,6 +473,7 @@ void StartMenu::UpdateFavs(){ } //QApplication::processEvents(); } //end loop over types + ui->scroll_favs->update(); //qDebug() << "End updateFavs"; } @@ -463,11 +489,10 @@ void StartMenu::on_stackedWidget_currentChanged(int val){ //Battery available - update the status button int charge = LOS::batteryCharge(); QString TT, ICON; - if(charge < 10){ ICON="-low"; } - else if(charge<20){ ICON="-caution"; } - else if(charge<40){ ICON="-040"; } - else if(charge<60){ ICON="-060"; } - else if(charge<80){ ICON="-080"; } + if(charge<=5){ ICON="-caution"; } + else if(charge<=20){ ICON="-040"; } + else if(charge<=70){ ICON="-060"; } + else if(charge<=90){ ICON="-080"; } else{ ICON="-100"; } if(LOS::batteryIsCharging()){ if(charge>=80){ ICON.clear(); } //for charging, there is no suffix to the icon name over 80% |