void LDeskBarPlugin::updateFiles(){ QFileInfoList homefiles = LSession::handle()->DesktopFiles(); QStringList favitems = LUtils::listFavorites(); //Remember for format for favorites: <name>::::[app/dir/<mimetype>]::::<full path> for(int i=0; i<homefiles.length(); i++){ QString type; if(homefiles[i].isDir()){ type="dir"; } else if(homefiles[i].fileName().endsWith(".desktop")){ type="app"; } else{ type=LXDG::findAppMimeForFile(homefiles[i].fileName()); } favitems << homefiles[i].fileName()+"::::"+type+"::::"+homefiles[i].absoluteFilePath(); //qDebug() << "Desktop Item:" << favitems.last(); } favitems.sort(); //sort them alphabetically //Now add the items to the lists appM->clear(); dirM->clear(); audioM->clear(); videoM->clear(); pictureM->clear(); docM->clear(); otherM->clear(); for(int i=0; i<favitems.length(); i++){ QString type = favitems[i].section("::::",1,1); QString name = favitems[i].section("::::",0,0); QString path = favitems[i].section("::::",2,50); if(type=="app"){ //Add it to appM bool ok = false; XDGDesktop df = LXDG::loadDesktopFile(path, ok); if(ok){ if( LXDG::checkValidity(df) && !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 dirM->addAction( newAction(path, name, LXDG::findIcon("folder","")) ); }else if(type.startsWith("audio/")){ //Add it to audioM audioM->addAction( newAction(path, name, LXDG::findMimeIcon(type)) ); }else if(type.startsWith("video/")){ //Add it to videoM videoM->addAction( newAction(path, name, LXDG::findMimeIcon(type)) ); }else if(type.startsWith("image/")){ //Add it to pictureM if(LUtils::imageExtensions().contains(path.section("/",-1).section(".",-1).toLower()) ){ pictureM->addAction( newAction(path, name, QIcon(path)) ); }else{ pictureM->addAction( newAction(path, name, LXDG::findMimeIcon(type)) ); } }else if(type.startsWith("text/")){ //Add it to docM docM->addAction( newAction(path, name, LXDG::findMimeIcon(type)) ); }else{ //Add it to otherM otherM->addAction( newAction(path, name, LXDG::findMimeIcon(type)) ); } } //Now update the file menu as appropriate fileM->clear(); if(!audioM->isEmpty()){ fileM->addMenu(audioM); } if(!docM->isEmpty()){ fileM->addMenu(docM); } if(!pictureM->isEmpty()){ fileM->addMenu(pictureM); } if(!videoM->isEmpty()){ fileM->addMenu(videoM); } if(!otherM->isEmpty()){ fileM->addMenu(otherM); } //Check for a single submenu, and skip the main if need be disconnect(fileB->menu(), SIGNAL(aboutToHide()), this, SIGNAL(MenuClosed()) ); if(fileM->actions().length()==1){ if(!audioM->isEmpty()){ fileB->setMenu(audioM); } else if(!pictureM->isEmpty()){ fileB->setMenu(pictureM); } else if(!videoM->isEmpty()){ fileB->setMenu(videoM); } else if(!docM->isEmpty()){ fileB->setMenu(docM); } else if(!otherM->isEmpty()){ fileB->setMenu(otherM); } }else{ fileB->setMenu(fileM); } connect(fileB->menu(), SIGNAL(aboutToHide()), this, SIGNAL(MenuClosed())); //Setup the visibility of the buttons appB->setVisible( !appM->isEmpty() ); dirB->setVisible( !dirM->isEmpty() ); fileB->setVisible( !fileM->isEmpty() ); }
//============== // PRIVATE SLOTS //============== void LTaskManagerPlugin::UpdateButtons(){ updating = QDateTime::currentDateTime(); //global time stamp QDateTime ctime = updating; //current thread time stamp //Get the current window list QList<WId> winlist = LSession::handle()->XCB->WindowList(); //Do not change the status of the previously active window if it just changed to a non-visible window //WId activeWin = LSession::handle()->XCB->ActiveWindow(); //bool skipActive = !winlist.contains(activeWin); //qDebug() << "Update Buttons:" << winlist; if(updating > ctime){ return; } //another thread kicked off already - stop this one //Now go through all the current buttons first for(int i=0; i<BUTTONS.length(); i++){ //Get the windows managed in this button QList<WId> WI = BUTTONS[i]->windows(); bool updated=false; if(updating > ctime){ return; } //another thread kicked off already - stop this one //Loop over all the windows for this button for(int w=0; w<WI.length(); w++){ if(updating > ctime){ return; } //another thread kicked off already - stop this one if( winlist.contains( WI[w] ) ){ //Still current window - update it later winlist.removeAll(WI[w] ); //remove this window from the list since it is done }else{ //Window was closed - remove it if(WI.length()==1){ //Remove the entire button //qDebug() << "Window Closed: Remove Button" ; this->layout()->takeAt(i); //remove from the layout delete BUTTONS.takeAt(i); i--; updated = true; //prevent updating a removed button break; //break out of the button->window loop }else{ //qDebug() << "Window Closed: Remove from button:" << WI[w].windowID() << "Button:" << w; BUTTONS[i]->rmWindow(WI[w]); // one of the multiple windows for the button WI.removeAt(w); //remove this window from the list w--; } updated=true; //button already changed } if(updating > ctime){ return; } //another thread kicked off already - stop this one } if(!updated){ //qDebug() << "Update Button:" << i; if(updating > ctime){ return; } //another thread kicked off already - stop this one //if(!skipActive || !BUTTONS[i]->isActive()){ QTimer::singleShot(1,BUTTONS[i], SLOT(UpdateButton()) ); //keep moving on //} } } //Now go through the remaining windows for(int i=0; i<winlist.length(); i++){ //New windows, create buttons for each (add grouping later) if(updating > ctime){ return; } //another thread kicked off already - stop this one //Check for a button that this can just be added to QString ctxt = LSession::handle()->XCB->WindowClass(winlist[i]); bool found = false; for(int b=0; b<BUTTONS.length(); b++){ if(updating > ctime){ return; } //another thread kicked off already - stop this one if(BUTTONS[b]->classname()== ctxt && usegroups){ //This adds a window to an existing group found = true; //qDebug() << "Add Window to Button:" << b; BUTTONS[b]->addWindow(winlist[i]); break; } } if(!found){ if(updating > ctime){ return; } //another thread kicked off already - stop this one //No group, create a new button //qDebug() << "New Button"; LTaskButton *but = new LTaskButton(this, usegroups); but->addWindow( winlist[i] ); if(this->layout()->direction()==QBoxLayout::LeftToRight){ but->setIconSize(QSize(this->height(), this->height())); }else{ but->setIconSize(QSize(this->width(), this->width())); } this->layout()->addWidget(but); connect(but, SIGNAL(MenuClosed()), this, SIGNAL(MenuClosed())); BUTTONS << but; } } }
//=========== // PUBLIC SLOTS //=========== void LPanel::UpdatePanel(bool geomonly){ //Create/Update the panel as designated in the Settings file settings->sync(); //make sure to catch external settings changes //First set the geometry of the panel and send the EWMH message to reserve that space if(DEBUG){ qDebug() << "Update Panel: Geometry only=" << geomonly << "Screen Size:" << LSession::handle()->screenGeom(screennum); } hidden = settings->value(PPREFIX+"hidepanel",false).toBool(); QString loc = settings->value(PPREFIX+"location","").toString().toLower(); if(loc.isEmpty() && defaultpanel){ loc="top"; } if(loc=="top" || loc=="bottom"){ horizontal=true; layout->setAlignment(Qt::AlignLeft); layout->setDirection(QBoxLayout::LeftToRight); }else{ horizontal=false; layout->setAlignment(Qt::AlignTop); layout->setDirection(QBoxLayout::TopToBottom); } int ht = settings->value(PPREFIX+"height", 30).toInt(); //this is technically the distance into the screen from the edge if(ht<=1){ ht = 30; } //some kind of error in the saved height - use the default value int hidesize = qRound(ht*0.01); //use 1% of the panel size if(hidesize<2){ hidesize=2; } //minimum of 2 pixels (need space for the mouse to go over it) if(hidden){ viswidth = hidesize; } else{ viswidth = ht; } if(DEBUG){ qDebug() << "Hidden Panel size:" << hidesize << "pixels"; } //qDebug() << " - set Geometry"; int xwid = LSession::handle()->screenGeom(screennum).width(); int xhi = LSession::handle()->screenGeom(screennum).height(); int xloc = LSession::handle()->screenGeom(screennum).x(); double panelPercent = settings->value(PPREFIX+"lengthPercent",100).toInt(); if(panelPercent<1 || panelPercent>100){ panelPercent = 100; } panelPercent = panelPercent/100.0; QString panelPinLoc = settings->value(PPREFIX+"pinLocation","center").toString().toLower(); //[left/right/center] possible values (assume center otherwise) if(DEBUG){ qDebug() << " - Panel settings:" << QString::number(panelPercent)+QString("%") << panelPinLoc << loc; } //xloc=xoffset; if(loc=="top"){ //top of screen QSize sz = QSize(xwid*panelPercent, ht); if(panelPinLoc=="left"){} // no change to xloc else if(panelPinLoc=="right"){ xloc = xloc+xwid-sz.width(); } else{ xloc = xloc+((xwid-sz.width())/2) ; } //centered //qDebug() << " - Panel Sizing:" << xloc << sz; this->setMinimumSize(sz); this->setMaximumSize(sz); this->setGeometry(xloc,0,sz.width(), sz.height()); //qDebug() << " - Reserve Panel Localation"; if(!hidden){ LSession::handle()->XCB->ReserveLocation(this->winId(), this->geometry(), "top"); } else{ LSession::handle()->XCB->ReserveLocation(this->winId(), QRect(xloc, 0, this->width(), hidesize), "top"); hidepoint = QPoint(xloc, hidesize-ht); showpoint = QPoint(xloc, 0); this->move(hidepoint); //Could bleed over onto the screen above } }else if(loc=="bottom"){ //bottom of screen QSize sz = QSize(xwid*panelPercent, ht); if(panelPinLoc=="left"){} // no change to xloc else if(panelPinLoc=="right"){ xloc = xloc+xwid-sz.width(); } else{ xloc = xloc+((xwid-sz.width())/2) ; } //centered this->setMinimumSize(sz); this->setMaximumSize(sz); this->setGeometry(xloc,xhi-ht,sz.width(), ht ); if(!hidden){ LSession::handle()->XCB->ReserveLocation(this->winId(), this->geometry(), "bottom"); } else{ LSession::handle()->XCB->ReserveLocation(this->winId(), QRect(xloc, xhi-hidesize, this->width(), hidesize), "bottom"); hidepoint = QPoint(xloc, xhi-hidesize); showpoint = QPoint(xloc, xhi-ht); this->move(hidepoint); //Could bleed over onto the screen below } }else if(loc=="left"){ //left side of screen QSize sz = QSize(ht, xhi*panelPercent); int yloc = 0; if(panelPinLoc=="left"){} //this is actually the top (left of center in length dimension) else if(panelPinLoc=="right"){ yloc = yloc+xhi-sz.height(); } else{ yloc = yloc+((xhi-sz.height())/2) ; } //centered this->setMinimumSize(sz); this->setMaximumSize(sz); this->setGeometry(xloc,yloc, ht, sz.height()); if(!hidden){ LSession::handle()->XCB->ReserveLocation(this->winId(), this->geometry(), "left"); } else{ LSession::handle()->XCB->ReserveLocation(this->winId(), QRect(xloc, yloc, hidesize, sz.height()), "left"); hidepoint = QPoint(xloc-ht+hidesize, yloc); showpoint = QPoint(xloc, yloc); this->move(hidepoint); //Could bleed over onto the screen left } }else{ //right side of screen QSize sz = QSize(ht, xhi*panelPercent); int yloc = 0; if(panelPinLoc=="left"){} //this is actually the top (left of center in length dimension) else if(panelPinLoc=="right"){ yloc = yloc+xhi-sz.height(); } else{ yloc = yloc+((xhi-sz.height())/2) ; } //centered this->setMinimumSize(sz); this->setMaximumSize(sz); this->setGeometry(xloc+xwid-ht,yloc,ht, sz.height()); if(!hidden){ LSession::handle()->XCB->ReserveLocation(this->winId(), this->geometry(), "right"); } else{ LSession::handle()->XCB->ReserveLocation(this->winId(), QRect(xloc+xwid-hidesize, yloc, hidesize, sz.height()), "right"); hidepoint = QPoint(xloc+xwid-hidesize, yloc); showpoint = QPoint(xloc+xwid-ht, yloc); this->move(hidepoint); //Could bleed over onto the screen right } } //With QT5, we need to make sure to reset window properties on occasion //LSession::handle()->XCB->SetDisableWMActions(this->winId()); //ensure no WM actions //LSession::handle()->XCB->SetAsSticky(this->winId()); if(DEBUG){ qDebug() << " - Done with panel geometry"; } if(geomonly){ return; } //Now update the appearance of the toolbar if(settings->value(PPREFIX+"customcolor", false).toBool()){ QString color = settings->value(PPREFIX+"color", "rgba(255,255,255,160)").toString(); QString style = "QWidget#LuminaPanelColor{ background: %1; border-radius: 3px; border: 1px solid %1; }"; style = style.arg(color); panelArea->setStyleSheet(style); }else{ panelArea->setStyleSheet(""); //clear it and use the one from the theme } //Then go through the plugins and create them as necessary QStringList plugins = settings->value(PPREFIX+"pluginlist", QStringList()).toStringList(); /*if(defaultpanel && plugins.isEmpty()){ plugins << "userbutton" << "taskmanager" << "spacer" << "systemtray" << "clock" << "systemdashboard"; }*/ if(DEBUG){ qDebug() << " - Initialize Plugins: " << plugins; } for(int i=0; i<plugins.length(); i++){ //Ensure this plugin has a unique ID (NOTE: this numbering does not persist between sessions) if(!plugins[i].contains("---")){ int num=1; while( plugins.contains(plugins[i]+"---"+QString::number(screennum)+"."+QString::number(this->number())+"."+QString::number(num)) ){ num++; } plugins[i] = plugins[i]+"---"+QString::number(screennum)+"."+QString::number(this->number())+"."+QString::number(num); //qDebug() << "Adjust Plugin ID:" << plugins[i]; } //See if this plugin is already there or in a different spot bool found = false; for(int p=0; p<PLUGINS.length(); p++){ if(PLUGINS[p]->type()==plugins[i]){ found = true; //already exists //Make sure the plugin layout has the correct orientation if(horizontal){PLUGINS[p]->layout()->setDirection(QBoxLayout::LeftToRight); } else{ PLUGINS[p]->layout()->setDirection(QBoxLayout::TopToBottom); } QTimer::singleShot(0,PLUGINS[p], SLOT( OrientationChange() ) ); //Now check the location of the plugin in the panel if(p!=i){ //wrong place in the panel layout->takeAt(p); //remove the item from the current location layout->insertWidget(i, PLUGINS[p]); //add the item into the correct location PLUGINS.move(p,i); //move the identifier in the list to match } break; } } if(!found){ //New Plugin if(DEBUG){ qDebug() << " -- New Plugin:" << plugins[i] << i; } LPPlugin *plug = NewPP::createPlugin(plugins[i], panelArea, horizontal); if(plug != 0){ PLUGINS.insert(i, plug); layout->insertWidget(i, PLUGINS[i]); connect(plug, SIGNAL(MenuClosed()), this, SLOT(checkPanelFocus())); }else{ //invalid plugin type plugins.removeAt(i); //remove this invalid plugin from the list i--; //make sure we don't miss the next item with the re-order } } LSession::processEvents(); } //Now remove any extra plugins from the end //qDebug() << "plugins:" << plugins; //qDebug() << "PLUGINS length:" << PLUGINS.length(); for(int i=0; i<PLUGINS.length(); i++){ if(plugins.contains(PLUGINS[i]->type())){ continue; } //good plugin - skip it if(DEBUG){ qDebug() << " -- Remove Plugin: " << PLUGINS[i]->type(); } //If this is the system tray - stop it first if( PLUGINS[i]->type().startsWith("systemtray---") ){ static_cast<LSysTray*>(PLUGINS[i])->stop(); } layout->takeAt(i); //remove from the layout delete PLUGINS.takeAt(i); //delete the actual widget LSession::processEvents(); i--; //need to back up one space to not miss another plugin } this->update(); this->show(); //make sure the panel is visible now if(hidden){ this->move(hidepoint); } //Now go through and send the orientation update signal to each plugin for(int i=0; i<PLUGINS.length(); i++){ QTimer::singleShot(0,PLUGINS[i], SLOT(OrientationChange())); } LSession::processEvents(); }