void StartMenu::UpdateFavs(){ //SYNTAX NOTE: (per-line) "<name>::::[dir/app/<mimetype>]::::<path>" QStringList newfavs = LUtils::listFavorites(); if(favs == newfavs){ return; } //nothing to do - same as before favs = newfavs; ClearScrollArea(ui->scroll_favs); favs.sort(); //Iterate over types of favorites QStringList rest = favs; for(int type = 0; type<3; type++){ QStringList tmp; if(type==0){ tmp = favs.filter("::::app::::"); } //apps first else if(type==1){ tmp = favs.filter("::::dir::::"); } //dirs next else{ tmp = rest; } //everything left over for(int i=0; i<tmp.length(); i++){ if(type<2){ rest.removeAll(tmp[i]); } if(!QFile::exists(tmp[i].section("::::",2,50))){ continue; } //invalid favorite - skip it ItemWidget *it = new ItemWidget(ui->scroll_favs->widget(), tmp[i].section("::::",2,50), tmp[i].section("::::",1,1) ); if(!it->gooditem){ continue; } //invalid for some reason ui->scroll_favs->widget()->layout()->addWidget(it); connect(it, SIGNAL(NewShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); } QApplication::processEvents(); } }
//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(); 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(); cats.sort(); cats.removeAll("All"); for(int c=0; c<cats.length(); c++){ QList<XDGDesktop> apps = sysapps->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()); catlabel->setAlignment(Qt::AlignCenter); ui->scroll_apps->widget()->layout()->addWidget(catlabel); //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 ui->scroll_apps->widget()->layout()->addWidget(it); connect(it, SIGNAL(NewShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); connect(it, SIGNAL(toggleQuickLaunch(QString, bool)), this, SLOT(UpdateQuickLaunch(QString, bool)) ); } } }else if(ui->check_apps_showcats->checkState() == Qt::Checked){
//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) QStringList cats = sysapps->keys(); cats.sort(); cats.removeAll("All"); for(int c=0; c<cats.length(); c++){ QList<XDGDesktop> apps = sysapps->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()); catlabel->setAlignment(Qt::AlignCenter); ui->scroll_apps->widget()->layout()->addWidget(catlabel); //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 ui->scroll_apps->widget()->layout()->addWidget(it); connect(it, SIGNAL(NewShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); } } }
StartMenu::StartMenu(QWidget *parent) : QWidget(parent), ui(new Ui::StartMenu){ ui->setupUi(this); //load the designer file sysapps = LSession::handle()->applicationMenu()->currentAppHash(); connect(LSession::handle()->applicationMenu(), SIGNAL(AppMenuUpdated()), this, SLOT(UpdateApps()) ); UpdateAll(); QTimer::singleShot(10, this,SLOT(UpdateApps())); QTimer::singleShot(10, this, SLOT(UpdateFavs())); }
void StartMenu::UpdateMenu(bool forceall){ if(forceall){ UpdateAll(); } //Quick update routine before the menu is made visible UpdateFavs(); if(ui->stackedWidget->currentWidget() != ui->page_main){ ui->stackedWidget->setCurrentWidget(ui->page_main); //just show the main page }else{ on_stackedWidget_currentChanged(0); //refresh/update the main page every time } }
void StartMenu::UpdateMenu(bool forceall){ //qDebug() << "Update Menu" << forceall; ui->line_search->clear(); if(forceall){ UpdateAll(); } //Quick update routine before the menu is made visible //qDebug() << "update favs"; UpdateFavs(); //qDebug() << "check page"; if(ui->stackedWidget->currentWidget() != ui->page_main){ ui->stackedWidget->setCurrentWidget(ui->page_main); //just show the main page }else{ on_stackedWidget_currentChanged(0); //refresh/update the main page every time } //qDebug() << "done"; }
StartMenu::StartMenu(QWidget *parent) : QWidget(parent), ui(new Ui::StartMenu){ ui->setupUi(this); //load the designer file this->setMouseTracking(true); searchTimer = new QTimer(this); 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(); if(state=="partial"){ui->check_apps_showcats->setCheckState(Qt::PartiallyChecked); } else if(state=="true"){ ui->check_apps_showcats->setCheckState(Qt::Checked); } else{ ui->check_apps_showcats->setCheckState(Qt::Unchecked); } connect(ui->check_apps_showcats, SIGNAL(stateChanged(int)), this, SLOT(catViewChanged()) ); UpdateAll(); QTimer::singleShot(10, this,SLOT(UpdateApps())); QTimer::singleShot(10, this, SLOT(UpdateFavs())); }
void StartMenu::do_search(QString search, bool force){ search = search.simplified(); //remove unneccesary whitespace if(search == CSearch && !force){ //nothing new - just ensure the page is visible if(ui->stackedWidget->currentWidget()!=ui->page_search ){ ui->stackedWidget->setCurrentWidget(ui->page_search); } return; }else if(search.isEmpty()){ CSearch.clear(); if(ui->stackedWidget->currentWidget()==ui->page_search ){ on_tool_back_clicked(); } return; } //Got a search term - check it CSearch = search; //save this for comparison later qDebug() << "Search for term:" << search; ClearScrollArea(ui->scroll_search); topsearch.clear(); //Now find any items which match the search 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"); 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; } //Can add other filters here later if(priority>0){ found << QString::number(priority)+"::::app::::"+apps[i].filePath; } } found.sort(Qt::CaseInsensitive); //sort by priority/type (lower numbers are higher on list) //qDebug() << "Sorted Items:" << found; //Now add the items to the menu in order for(int i=0; i<found.length(); i++){ if( !QFile::exists(found[i].section("::::",2,-1)) ){ continue; } //invalid favorite - skip it 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); } }else{ it = new ItemWidget(ui->scroll_favs->widget(), found[i].section("::::",2,-1), found[i].section("::::",1,1) ); } if(it==0){ continue; } if(!it->gooditem){ it->deleteLater(); continue; } //invalid for some reason ui->scroll_search->widget()->layout()->addWidget(it); connect(it, SIGNAL(NewShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(UpdateFavs()) ); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); connect(it, SIGNAL(toggleQuickLaunch(QString, bool)), this, SLOT(UpdateQuickLaunch(QString, bool)) ); if(i%3==0){ QApplication::processEvents(); if(searchTimer->isActive()){ return; } //search changed - go ahead and stop here } } ui->stackedWidget->setCurrentWidget(ui->page_search); }