//Home Tab void UserWidget::updateHome(){ ClearScrollArea(ui->scroll_home); QDir homedir(ui->label_home_dir->whatsThis()); QStringList items; if(QDir::homePath() == homedir.absolutePath()){ ui->label_home_dir->setText(tr("Home")); ui->tool_home_gohome->setVisible(false); }else{ ui->tool_home_gohome->setVisible(true); ui->label_home_dir->setText( this->fontMetrics().elidedText(homedir.dirName(), Qt::ElideRight, ui->label_home_dir->width())); //Now make sure to put a "go back" button at the top of the list QString dir = ui->label_home_dir->whatsThis(); if(dir.endsWith("/")){ dir.chop(1); } dir.chop( dir.section("/",-1).length() ); items << dir; } ui->label_home_dir->setToolTip(ui->label_home_dir->whatsThis()); items << homedir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); 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); } ui->scroll_home->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(slotGoToDir(QString)) ); connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) ); } static_cast<QBoxLayout*>(ui->scroll_home->widget()->layout())->addStretch(); }
//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)) ); } } }
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"); } 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); }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); }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<items.length(); i++){ UserItemWidget *it = new UserItemWidget(ui->scroll_fav->widget(), items[i].absoluteFilePath(), 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()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) ); } static_cast<QBoxLayout*>(ui->scroll_fav->widget()->layout())->addStretch(); }
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(); } }
//Home Tab void UserWidget::updateHome(){ ClearScrollArea(ui->scroll_home); QDir homedir(ui->label_home_dir->whatsThis()); QStringList items; if(QDir::homePath() == homedir.absolutePath()){ ui->label_home_dir->setText(tr("Home")); ui->tool_home_gohome->setVisible(false); }else{ ui->tool_home_gohome->setVisible(true); ui->label_home_dir->setText( this->fontMetrics().elidedText(homedir.dirName(), Qt::ElideRight, ui->label_home_dir->width())); //Now make sure to put a "go back" button at the top of the list QString dir = ui->label_home_dir->whatsThis(); if(dir.endsWith("/")){ dir.chop(1); } dir.chop( dir.section("/",-1).length() ); items << dir; } ui->label_home_dir->setToolTip(ui->label_home_dir->whatsThis()); items << homedir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::DirsFirst); QString type = ""; if(homedir.absolutePath() == QDir::homePath()+"/Desktop"){ type.append("-home"); }//internal code 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], "dir", true); } //go-back button else{ it = new UserItemWidget(ui->scroll_home->widget(), homedir.absoluteFilePath(items[i]), type, false); } ui->scroll_home->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(slotGoToDir(QString)) ); connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) ); QApplication::processEvents(); //keep the UI snappy - may be a lot of these to load } }
void UserWidget::updateFavItems(bool newfilter){ if(updatingfavs){ return; } updatingfavs = true; //qDebug() << "Updating User Favorite Items"; QStringList newfavs = LUtils::listFavorites(); //qDebug() << "Favorites:" << newfavs; if(lastHomeUpdate.isNull() || (QFileInfo(QDir::homePath()+"/Desktop").lastModified() > lastHomeUpdate) || newfavs!=favs ){ favs = newfavs; homefiles = LSession::handle()->DesktopFiles(); lastHomeUpdate = QDateTime::currentDateTime(); }else if(!newfilter){ updatingfavs = false; return; } //nothing new to change - stop now //qDebug() << " - Passed Smoke Test..."; QStringList favitems; //Remember for format for favorites: <name>::::[app/dir/<mimetype>]::::<full path> if(ui->tool_fav_apps->isChecked()){ favitems = favs.filter("::::app::::"); for(int i=0; i<homefiles.length(); i++){ if(homefiles[i].fileName().endsWith(".desktop")){ favitems << homefiles[i].fileName()+"::::app-home::::"+homefiles[i].absoluteFilePath(); } } }else if(ui->tool_fav_dirs->isChecked()){ favitems = favs.filter("::::dir::::"); for(int i=0; i<homefiles.length(); i++){ if(homefiles[i].isDir()){ favitems << homefiles[i].fileName()+"::::dir-home::::"+homefiles[i].absoluteFilePath(); } } }else{ //Files 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())+"-home::::"+homefiles[i].absoluteFilePath(); } } } ClearScrollArea(ui->scroll_fav); //qDebug() << " - Sorting Items"; favitems.sort(); //sort them alphabetically //qDebug() << " - Creating Items:" << favitems; 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) ); if(!it->gooditem){ continue; } ui->scroll_fav->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) ); QApplication::processEvents(); //keep the UI snappy - might be a number of these } SortScrollArea(ui->scroll_fav); updatingfavs = false; //qDebug() << " - Done"; }
//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){
void UserItemWidget::buttonClicked(){ button->setVisible(false); if(button->whatsThis()=="add"){ 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 emit RemovedShortcut(); } }
//Home Tab void UserWidget::updateHome(){ ClearScrollArea(ui->scroll_home); QDir homedir = QDir::home(); QStringList items = homedir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); for(int i=0; i<items.length(); i++){ //qDebug() << "New Home subdir:" << homedir.absoluteFilePath(items[i]); UserItemWidget *it = new UserItemWidget(ui->scroll_home->widget(), homedir.absoluteFilePath(items[i]), true); ui->scroll_home->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) ); } static_cast<QBoxLayout*>(ui->scroll_home->widget()->layout())->addStretch(); }
void UserWidget::updateApps(){ if(ui->combo_app_cats->currentIndex() < 0){ return; } //no cat QString cat = ui->combo_app_cats->itemData( ui->combo_app_cats->currentIndex() ).toString(); QList<XDGDesktop> items = sysapps->value(cat); ClearScrollArea(ui->scroll_apps); for(int i=0; i<items.length(); i++){ UserItemWidget *it = new UserItemWidget(ui->scroll_apps->widget(), items[i]); ui->scroll_apps->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) ); } static_cast<QBoxLayout*>(ui->scroll_apps->widget()->layout())->addStretch(); }
void UserWidget::updateApps(){ if(ui->combo_app_cats->currentIndex() < 0){ return; } //no cat QString cat = ui->combo_app_cats->itemData( ui->combo_app_cats->currentIndex() ).toString(); QList<XDGDesktop> items = sysapps->value(cat); ClearScrollArea(ui->scroll_apps); for(int i=0; i<items.length(); i++){ UserItemWidget *it = new UserItemWidget(ui->scroll_apps->widget(), items[i]); ui->scroll_apps->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) ); connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) ); QApplication::processEvents(); //keep the UI snappy - might be a number of these } }
void ItemWidget::RemoveFavorite(){ LUtils::removeFavorite(icon->whatsThis()); linkPath.clear(); emit RemovedShortcut(); }
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); }