diff options
Diffstat (limited to 'src-qt5/core/lumina-desktop')
17 files changed, 147 insertions, 153 deletions
diff --git a/src-qt5/core/lumina-desktop/AppMenu.cpp b/src-qt5/core/lumina-desktop/AppMenu.cpp index cbf71e62..798d8b6d 100644 --- a/src-qt5/core/lumina-desktop/AppMenu.cpp +++ b/src-qt5/core/lumina-desktop/AppMenu.cpp @@ -11,6 +11,7 @@ AppMenu::AppMenu(QWidget* parent) : QMenu(parent){ appstorelink = LOS::AppStoreShortcut(); //Default application "store" to display (AppCafe in TrueOS) controlpanellink = LOS::ControlPanelShortcut(); //Default control panel + sysApps = new XDGDesktopList(this, true); //have this one automatically keep in sync APPS.clear(); //watcher = new QFileSystemWatcher(this); //connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(watcherUpdate()) ); @@ -24,7 +25,7 @@ AppMenu::~AppMenu(){ } -QHash<QString, QList<XDGDesktop> >* AppMenu::currentAppHash(){ +QHash<QString, QList<XDGDesktop*> >* AppMenu::currentAppHash(){ return &APPS; } @@ -38,8 +39,7 @@ void AppMenu::updateAppList(){ this->setIcon( LXDG::findIcon("system-run","") ); //Now update the lists this->clear(); - APPS.clear(); - XDGDesktopList *sysApps = LXDG:: systemAppsList(); + APPS.clear(); //NOTE: Don't delete these pointers - the pointers are managed by the sysApps class and these are just references to them //qDebug() << "New Apps List:"; if(LSession::handle()->sessionSettings()->value("AutomaticDesktopAppLinks",true).toBool() && !lastHashUpdate.isNull() ){ QString desktop = QDir::homePath()+"/"+tr("Desktop")+"/"; //translated desktop folder @@ -60,8 +60,8 @@ void AppMenu::updateAppList(){ } tmp = sysApps->newApps; for(int i=0; i<tmp.length() && !desktop.isEmpty(); i++){ - XDGDesktop desk = sysApps->files.value(tmp[i]); - if(desk.isHidden || !LXDG::checkValidity(desk, false) ){ continue; } //skip this one + XDGDesktop *desk = sysApps->files.value(tmp[i]); + if(desk->isHidden || !desk->isValid(false) ){ continue; } //skip this one //qDebug() << "New App: " << tmp[i] << desk.filePath << "Hidden:" << desk.isHidden; //Create a new symlink for this file if one does not exist QString filename = tmp[i].section("/",-1); @@ -69,23 +69,22 @@ void AppMenu::updateAppList(){ if(!QFile::exists(desktop+filename) ){ QFile::link(tmp[i], desktop+filename); } } } - QList<XDGDesktop> allfiles = sysApps->apps(false,false); //only valid, non-hidden apps + QList<XDGDesktop*> allfiles = sysApps->apps(false,false); //only valid, non-hidden apps APPS = LXDG::sortDesktopCats(allfiles); APPS.insert("All", LXDG::sortDesktopNames(allfiles)); lastHashUpdate = QDateTime::currentDateTime(); //Now fill the menu - bool ok; //for checking inputs //Add link to the file manager //this->addAction( LXDG::findIcon("user-home", ""), tr("Browse Files"), this, SLOT(launchFileManager()) ); //--Look for the app store - XDGDesktop store = LXDG::loadDesktopFile(appstorelink, ok); - if(ok){ + XDGDesktop store(appstorelink); + if(store.isValid()){ this->addAction( LXDG::findIcon(store.icon, ""), tr("Manage Applications"), this, SLOT(launchStore()) ); } //--Look for the control panel - store = LXDG::loadDesktopFile(controlpanellink, ok); - if(ok){ - this->addAction( LXDG::findIcon(store.icon, ""), tr("Control Panel"), this, SLOT(launchControlPanel()) ); + XDGDesktop controlp(controlpanellink); + if(controlp.isValid()){ + this->addAction( LXDG::findIcon(controlp.icon, ""), tr("Control Panel"), this, SLOT(launchControlPanel()) ); } this->addSeparator(); //--Now create the sub-menus @@ -112,29 +111,29 @@ void AppMenu::updateAppList(){ QMenu *menu = new QMenu(name, this); menu->setIcon(LXDG::findIcon(icon,"")); connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(launchApp(QAction*)) ); - QList<XDGDesktop> appL = APPS.value(cats[i]); + QList<XDGDesktop*> appL = APPS.value(cats[i]); for( int a=0; a<appL.length(); a++){ - if(appL[a].actions.isEmpty()){ + if(appL[a]->actions.isEmpty()){ //Just a single entry point - no extra actions - QAction *act = new QAction(LXDG::findIcon(appL[a].icon, ""), appL[a].name, this); - act->setToolTip(appL[a].comment); - act->setWhatsThis(appL[a].filePath); + QAction *act = new QAction(LXDG::findIcon(appL[a]->icon, ""), appL[a]->name, this); + act->setToolTip(appL[a]->comment); + act->setWhatsThis(appL[a]->filePath); menu->addAction(act); }else{ //This app has additional actions - make this a sub menu // - first the main menu/action - QMenu *submenu = new QMenu(appL[a].name, this); - submenu->setIcon( LXDG::findIcon(appL[a].icon,"") ); + QMenu *submenu = new QMenu(appL[a]->name, this); + submenu->setIcon( LXDG::findIcon(appL[a]->icon,"") ); //This is the normal behavior - not a special sub-action (although it needs to be at the top of the new menu) - QAction *act = new QAction(LXDG::findIcon(appL[a].icon, ""), appL[a].name, this); - act->setToolTip(appL[a].comment); - act->setWhatsThis(appL[a].filePath); + QAction *act = new QAction(LXDG::findIcon(appL[a]->icon, ""), appL[a]->name, this); + act->setToolTip(appL[a]->comment); + act->setWhatsThis(appL[a]->filePath); submenu->addAction(act); //Now add entries for every sub-action listed - for(int sa=0; sa<appL[a].actions.length(); sa++){ - QAction *sact = new QAction(LXDG::findIcon(appL[a].actions[sa].icon, appL[a].icon), appL[a].actions[sa].name, this); - sact->setToolTip(appL[a].comment); - sact->setWhatsThis("-action \""+appL[a].actions[sa].ID+"\" \""+appL[a].filePath+"\""); + for(int sa=0; sa<appL[a]->actions.length(); sa++){ + QAction *sact = new QAction(LXDG::findIcon(appL[a]->actions[sa].icon, appL[a]->icon), appL[a]->actions[sa].name, this); + sact->setToolTip(appL[a]->comment); + sact->setWhatsThis("-action \""+appL[a]->actions[sa].ID+"\" \""+appL[a]->filePath+"\""); submenu->addAction(sact); } menu->addMenu(submenu); @@ -151,7 +150,8 @@ void AppMenu::updateAppList(){ //================= void AppMenu::start(){ //Setup the watcher - connect(LXDG:: systemAppsList(), SIGNAL(appsUpdated()), this, SLOT(watcherUpdate()) ); + connect(sysApps, SIGNAL(appsUpdated()), this, SLOT(watcherUpdate()) ); + sysApps->updateList(); //Now fill the menu the first time updateAppList(); } diff --git a/src-qt5/core/lumina-desktop/AppMenu.h b/src-qt5/core/lumina-desktop/AppMenu.h index 7584de07..5baaab7a 100644 --- a/src-qt5/core/lumina-desktop/AppMenu.h +++ b/src-qt5/core/lumina-desktop/AppMenu.h @@ -31,14 +31,15 @@ public: AppMenu(QWidget *parent = 0); ~AppMenu(); - QHash<QString, QList<XDGDesktop> > *currentAppHash(); + QHash<QString, QList<XDGDesktop*> > *currentAppHash(); QDateTime lastHashUpdate; private: //QFileSystemWatcher *watcher; QString appstorelink, controlpanellink; QList<QMenu> MLIST; - QHash<QString, QList<XDGDesktop> > APPS; + XDGDesktopList *sysApps; + QHash<QString, QList<XDGDesktop*> > APPS; void updateAppList(); //completely update the menu lists diff --git a/src-qt5/core/lumina-desktop/LDesktop.cpp b/src-qt5/core/lumina-desktop/LDesktop.cpp index e3d946d4..f1b73bc0 100644 --- a/src-qt5/core/lumina-desktop/LDesktop.cpp +++ b/src-qt5/core/lumina-desktop/LDesktop.cpp @@ -280,9 +280,8 @@ void LDesktop::UpdateMenu(bool fast){ else if(items[i].startsWith("app::::") && items[i].endsWith(".desktop")){ //Custom *.desktop application QString file = items[i].section("::::",1,1).simplified(); - bool ok = false; - XDGDesktop xdgf = LXDG::loadDesktopFile(file, ok); - if(ok){ + XDGDesktop xdgf(file);// = LXDG::loadDesktopFile(file, ok); + if(xdgf.type!=XDGDesktop::BAD){ deskMenu->addAction( LXDG::findIcon(xdgf.icon,""), xdgf.name)->setWhatsThis(file); }else{ qDebug() << "Could not load application file:" << file; diff --git a/src-qt5/core/lumina-desktop/SettingsMenu.cpp b/src-qt5/core/lumina-desktop/SettingsMenu.cpp index 10ada2cf..80ef3042 100644 --- a/src-qt5/core/lumina-desktop/SettingsMenu.cpp +++ b/src-qt5/core/lumina-desktop/SettingsMenu.cpp @@ -45,9 +45,8 @@ void SettingsMenu::UpdateMenu(){ QString CONTROLPANEL = LOS::ControlPanelShortcut(); if(QFile::exists(CONTROLPANEL) && !CONTROLPANEL.isEmpty()){ //Now load the info - bool ok = false; - XDGDesktop cpan = LXDG::loadDesktopFile(CONTROLPANEL, ok); - if(ok){ + XDGDesktop cpan(CONTROLPANEL); + if(cpan.isValid()){ act = new QAction( LXDG::findIcon(cpan.icon,""), tr("Control Panel"), this); act->setWhatsThis("lumina-open \""+CONTROLPANEL+"\""); this->addAction(act); diff --git a/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp index 8c7af5e9..bd8e79db 100644 --- a/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp +++ b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp @@ -38,8 +38,9 @@ void AppLauncherPlugin::loadButton(){ button->setIconSize( QSize(icosize,icosize) ); QString txt; if(path.endsWith(".desktop") && ok){ - XDGDesktop file = LXDG::loadDesktopFile(path, ok); - if(path.isEmpty() || !QFile::exists(path) || !ok){ + XDGDesktop file(path); + ok = file.isValid(); + if(!ok){ button->setWhatsThis(""); button->setIcon( QIcon(LXDG::findIcon("quickopen-file","").pixmap(QSize(icosize,icosize)).scaledToHeight(icosize, Qt::SmoothTransformation) ) ); txt = tr("Click to Set"); @@ -125,13 +126,13 @@ void AppLauncherPlugin::buttonClicked(){ QString path = button->whatsThis(); if(path.isEmpty() || !QFile::exists(path) ){ //prompt for the user to select an application - QList<XDGDesktop> apps = LXDG::sortDesktopNames( LXDG::systemDesktopFiles() ); + QList<XDGDesktop*> apps = LXDG::sortDesktopNames( LXDG::systemDesktopFiles() ); QStringList names; - for(int i=0; i<apps.length(); i++){ names << apps[i].name; } + for(int i=0; i<apps.length(); i++){ names << apps[i]->name; } bool ok = false; QString app = QInputDialog::getItem(this, tr("Select Application"), tr("Name:"), names, 0, false, &ok); if(!ok || names.indexOf(app)<0){ return; } //cancelled - this->saveSetting("applicationpath", apps[ names.indexOf(app) ].filePath); + this->saveSetting("applicationpath", apps[ names.indexOf(app) ]->filePath); QTimer::singleShot(0,this, SLOT(loadButton())); }else{ LSession::LaunchApplication("lumina-open \""+path+"\""); diff --git a/src-qt5/core/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp b/src-qt5/core/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp index 01e174e9..90f3374b 100644 --- a/src-qt5/core/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp +++ b/src-qt5/core/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp @@ -149,9 +149,8 @@ void DesktopViewPlugin::updateContents(){ it->setIcon( LXDG::findIcon("folder","") ); txt = files[i].fileName(); }else if(files[i].suffix() == "desktop" ){ - bool ok = false; - XDGDesktop desk = LXDG::loadDesktopFile(files[i].absoluteFilePath(), ok); - if(ok){ + XDGDesktop desk(files[i].absoluteFilePath()); + if(desk.isValid()){ it->setIcon( LXDG::findIcon(desk.icon,"unknown") ); if(desk.name.isEmpty()){ txt = files[i].fileName(); diff --git a/src-qt5/core/lumina-desktop/panel-plugins/applauncher/AppLaunchButton.cpp b/src-qt5/core/lumina-desktop/panel-plugins/applauncher/AppLaunchButton.cpp index 321970ed..05b7981f 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/applauncher/AppLaunchButton.cpp +++ b/src-qt5/core/lumina-desktop/panel-plugins/applauncher/AppLaunchButton.cpp @@ -31,9 +31,8 @@ void AppLaunchButtonPlugin::updateButtonVisuals(){ QIcon icon; QString tooltip = tr("Click to assign an application"); if(appfile.endsWith(".desktop")){ - bool ok = false; - XDGDesktop desk = LXDG::loadDesktopFile(appfile,ok); - if(ok){ + XDGDesktop desk(appfile); + if(desk.isValid()){ icon = LXDG::findIcon(desk.icon, "unknown"); tooltip = QString(tr("Launch %1")).arg(desk.name); }else{ @@ -56,13 +55,13 @@ void AppLaunchButtonPlugin::updateButtonVisuals(){ void AppLaunchButtonPlugin::AppClicked(){ if(appfile.isEmpty()){ //No App File selected - QList<XDGDesktop> apps = LSession::handle()->applicationMenu()->currentAppHash()->value("All"); + QList<XDGDesktop*> apps = LSession::handle()->applicationMenu()->currentAppHash()->value("All"); QStringList names; - for(int i=0; i<apps.length(); i++){ names << apps[i].name; } + for(int i=0; i<apps.length(); i++){ names << apps[i]->name; } bool ok = false; QString app = QInputDialog::getItem(this, tr("Select Application"), tr("Name:"), names, 0, false, &ok); if(!ok || names.indexOf(app)<0){ return; } //cancelled - appfile = apps[ names.indexOf(app) ].filePath; + appfile = apps[ names.indexOf(app) ]->filePath; //Still need to find a way to set this value persistently // --- perhaps replace the plugin in the desktop settings file with the new path? // --- "applauncher::broken---<something>" -> "applauncher::fixed---<something>" ? @@ -71,4 +70,3 @@ void AppLaunchButtonPlugin::AppClicked(){ LSession::LaunchApplication("lumina-open \""+appfile+"\""); } } - diff --git a/src-qt5/core/lumina-desktop/panel-plugins/appmenu/LAppMenuPlugin.cpp b/src-qt5/core/lumina-desktop/panel-plugins/appmenu/LAppMenuPlugin.cpp index 5d20e3ec..e3be55c2 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/appmenu/LAppMenuPlugin.cpp +++ b/src-qt5/core/lumina-desktop/panel-plugins/appmenu/LAppMenuPlugin.cpp @@ -62,23 +62,22 @@ void LAppMenuPlugin::LaunchItem(QAction* item){ void LAppMenuPlugin::UpdateMenu(){ mainmenu->clear(); - QHash<QString, QList<XDGDesktop> > *HASH = LSession::handle()->applicationMenu()->currentAppHash(); + QHash<QString, QList<XDGDesktop*> > *HASH = LSession::handle()->applicationMenu()->currentAppHash(); //Now Re-create the menu (orignally copied from the AppMenu class) - bool ok; //for checking inputs //Add link to the file manager QAction *tmpact = mainmenu->addAction( LXDG::findIcon("user-home", ""), tr("Browse Files") ); tmpact->setWhatsThis("\""+QDir::homePath()+"\""); //--Look for the app store - XDGDesktop store = LXDG::loadDesktopFile(LOS::AppStoreShortcut(), ok); - if(ok){ + XDGDesktop store(LOS::AppStoreShortcut()); + if(store.isValid()){ tmpact = mainmenu->addAction( LXDG::findIcon(store.icon, ""), tr("Install Applications") ); tmpact->setWhatsThis("\""+store.filePath+"\""); } //--Look for the control panel - store = LXDG::loadDesktopFile(LOS::ControlPanelShortcut(), ok); - if(ok){ - tmpact = mainmenu->addAction( LXDG::findIcon(store.icon, ""), tr("Control Panel") ); - tmpact->setWhatsThis("\""+store.filePath+"\""); + XDGDesktop controlp(LOS::ControlPanelShortcut()); + if(controlp.isValid()){ + tmpact = mainmenu->addAction( LXDG::findIcon(controlp.icon, ""), tr("Control Panel") ); + tmpact->setWhatsThis("\""+controlp.filePath+"\""); } mainmenu->addSeparator(); //--Now create the sub-menus @@ -104,29 +103,29 @@ void LAppMenuPlugin::UpdateMenu(){ QMenu *menu = new QMenu(name, this); menu->setIcon(LXDG::findIcon(icon,"")); - QList<XDGDesktop> appL = HASH->value(cats[i]); + QList<XDGDesktop*> appL = HASH->value(cats[i]); for( int a=0; a<appL.length(); a++){ - if(appL[a].actions.isEmpty()){ + if(appL[a]->actions.isEmpty()){ //Just a single entry point - no extra actions - QAction *act = new QAction(LXDG::findIcon(appL[a].icon, ""), appL[a].name, menu); - act->setToolTip(appL[a].comment); - act->setWhatsThis("\""+appL[a].filePath+"\""); + QAction *act = new QAction(LXDG::findIcon(appL[a]->icon, ""), appL[a]->name, menu); + act->setToolTip(appL[a]->comment); + act->setWhatsThis("\""+appL[a]->filePath+"\""); menu->addAction(act); }else{ //This app has additional actions - make this a sub menu // - first the main menu/action - QMenu *submenu = new QMenu(appL[a].name, menu); - submenu->setIcon( LXDG::findIcon(appL[a].icon,"") ); + QMenu *submenu = new QMenu(appL[a]->name, menu); + submenu->setIcon( LXDG::findIcon(appL[a]->icon,"") ); //This is the normal behavior - not a special sub-action (although it needs to be at the top of the new menu) - QAction *act = new QAction(LXDG::findIcon(appL[a].icon, ""), appL[a].name, submenu); - act->setToolTip(appL[a].comment); - act->setWhatsThis(appL[a].filePath); + QAction *act = new QAction(LXDG::findIcon(appL[a]->icon, ""), appL[a]->name, submenu); + act->setToolTip(appL[a]->comment); + act->setWhatsThis(appL[a]->filePath); submenu->addAction(act); //Now add entries for every sub-action listed - for(int sa=0; sa<appL[a].actions.length(); sa++){ - QAction *sact = new QAction(LXDG::findIcon(appL[a].actions[sa].icon, appL[a].icon), appL[a].actions[sa].name, this); - sact->setToolTip(appL[a].comment); - sact->setWhatsThis("-action \""+appL[a].actions[sa].ID+"\" \""+appL[a].filePath+"\""); + for(int sa=0; sa<appL[a]->actions.length(); sa++){ + QAction *sact = new QAction(LXDG::findIcon(appL[a]->actions[sa].icon, appL[a]->icon), appL[a]->actions[sa].name, this); + sact->setToolTip(appL[a]->comment); + sact->setWhatsThis("-action \""+appL[a]->actions[sa].ID+"\" \""+appL[a]->filePath+"\""); submenu->addAction(sact); } menu->addMenu(submenu); diff --git a/src-qt5/core/lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp b/src-qt5/core/lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp index 48bbface..9903d4fd 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp +++ b/src-qt5/core/lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp @@ -130,11 +130,9 @@ void LDeskBarPlugin::updateFiles(){ if(type=="app"){ //Add it to appM bool ok = false; - XDGDesktop df = LXDG::loadDesktopFile(path, ok); - if(ok){ - if( LXDG::checkValidity(df) && !df.isHidden ){ + XDGDesktop df(path); + if(df.isValid() && !df.isHidden){ appM->addAction( newAction(df.filePath, df.name, LXDG::findIcon(df.icon, ":/images/default-application.png")) ); - } } }else if(type=="dir"){ //Add it to dirM 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); diff --git a/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp b/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp index 1d32440a..a1dfe956 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp +++ b/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp @@ -15,12 +15,11 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, QString type, bool inHome = type.endsWith("-home"); //internal code if(inHome){ type = type.remove("-home"); } if(itemPath.endsWith(".desktop") || type=="app"){ - bool ok = false; - XDGDesktop item = LXDG::loadDesktopFile(itemPath, ok); - if(ok && LXDG::checkValidity(item) ){ + XDGDesktop item(itemPath); + if( item.isValid() ){ icon->setPixmap( LXDG::findIcon(item.icon, "preferences-system-windows-actions").pixmap(32,32) ); name->setText( this->fontMetrics().elidedText(item.name, Qt::ElideRight, TEXTCUTOFF) ); - setupActions(item); + setupActions(&item); }else{ gooditem = false; return; @@ -63,22 +62,23 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, QString type, setupButton(goback); } -UserItemWidget::UserItemWidget(QWidget *parent, XDGDesktop item) : QFrame(parent){ +UserItemWidget::UserItemWidget(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; } //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, TEXTCUTOFF) ); + icon->setPixmap( LXDG::findIcon(item->icon,"preferences-system-windows-actions").pixmap(32,32) ); + name->setText( this->fontMetrics().elidedText(item->name, Qt::ElideRight, TEXTCUTOFF) ); this->setWhatsThis(name->text()); - icon->setWhatsThis(item.filePath); + icon->setWhatsThis(item->filePath); //Now setup the buttons appropriately setupButton(); setupActions(item); @@ -152,14 +152,14 @@ void UserItemWidget::setupButton(bool disable){ } } -void UserItemWidget::setupActions(XDGDesktop app){ - if(app.actions.isEmpty()){ actButton->setVisible(false); return; } +void UserItemWidget::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*)) ); @@ -201,4 +201,4 @@ void UserItemWidget::actionClicked(QAction *act){ if(!linkPath.isEmpty()){ cmd = cmd.arg(linkPath); } else{ cmd = cmd.arg(icon->whatsThis()); } emit RunItem(cmd); -}
\ No newline at end of file +} diff --git a/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h b/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h index 2251344c..0b212f10 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h +++ b/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h @@ -28,7 +28,7 @@ class UserItemWidget : public QFrame{ Q_OBJECT public: UserItemWidget(QWidget *parent=0, QString itemPath="", QString type="unknown", bool goback=false); - UserItemWidget(QWidget *parent=0, XDGDesktop item= XDGDesktop()); + UserItemWidget(QWidget *parent=0, XDGDesktop *item= 0); ~UserItemWidget(); bool gooditem; @@ -41,7 +41,7 @@ private: void createWidget(); void setupButton(bool disable = false); - void setupActions(XDGDesktop); + void setupActions(XDGDesktop*); private slots: void buttonClicked(); diff --git a/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp b/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp index c7d8109c..fb58c7f6 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp +++ b/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp @@ -130,8 +130,8 @@ void UserWidget::UpdateAll(){ QString APPSTORE = LOS::AppStoreShortcut(); if(QFile::exists(APPSTORE) && !APPSTORE.isEmpty()){ //Now load the info - bool ok = false; - XDGDesktop store = LXDG::loadDesktopFile(APPSTORE, ok); + XDGDesktop store(APPSTORE); + bool ok = store.isValid(); if(ok){ ui->tool_app_store->setIcon( LXDG::findIcon(store.icon, "") ); ui->tool_app_store->setText( store.name ); @@ -143,8 +143,8 @@ void UserWidget::UpdateAll(){ QString CONTROLPANEL = LOS::ControlPanelShortcut(); if(QFile::exists(CONTROLPANEL) && !CONTROLPANEL.isEmpty()){ //Now load the info - bool ok = false; - XDGDesktop cpan = LXDG::loadDesktopFile(CONTROLPANEL, ok); + XDGDesktop cpan(CONTROLPANEL); + bool ok = cpan.isValid(); if(ok){ ui->tool_controlpanel->setIcon( LXDG::findIcon(cpan.icon, "") ); } @@ -307,7 +307,7 @@ void UserWidget::updateAppCategories(){ 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); + 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]); diff --git a/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserWidget.h b/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserWidget.h index af9408dd..8b03c489 100644 --- a/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserWidget.h +++ b/src-qt5/core/lumina-desktop/panel-plugins/userbutton/UserWidget.h @@ -42,7 +42,7 @@ public slots: private: Ui::UserWidget *ui; - QHash<QString, QList<XDGDesktop> > *sysapps; + QHash<QString, QList<XDGDesktop*> > *sysapps; QDateTime lastUpdate, lastHomeUpdate; QStringList favs; QFileInfoList homefiles; |