Changeset 49640df


Ignore:
Timestamp:
Apr 16, 2014 12:02:04 PM (4 days ago)
Author:
Ken Moore <ken@…>
Branches:
master
Children:
4ffefb1
Parents:
554eae8
Message:

Add the settings file watcher to the LDesktop class for background changes.

Location:
lumina/lumina-desktop
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lumina/lumina-desktop/LDesktop.cpp

    r214f3d5 r49640df  
    2121  //Setup the internal variables 
    2222  settings = new QSettings(QSettings::UserScope, "LuminaDE","desktopsettings", this); 
     23  //qDebug() << " - Desktop Settings File:" << settings->fileName(); 
     24  if(!QFile::exists(settings->fileName())){ settings->setValue(DPREFIX+"background/filelist",QStringList()<<"default"<<"sample"); settings->sync(); } 
    2325  bgtimer = new QTimer(this); 
    2426    bgtimer->setSingleShot(true); 
     27  watcher = new QFileSystemWatcher(this); 
     28    connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(UpdateBackground()) ); 
     29    watcher->addPath(settings->fileName()); 
    2530  
    2631  bgWindow = new QWidget(0); 
     
    121126void LDesktop::UpdateBackground(){ 
    122127  //Get the current Background 
    123   QString cbg = settings->value(DPREFIX+"background/current", "").toString(); 
     128  qDebug() << " - Update Background"; 
    124129  //Get the list of background(s) to show 
    125130  QStringList bgL = settings->value(DPREFIX+"background/filelist", "").toStringList(); 
     131  //qDebug() << " - List:" << bgL << CBG; 
    126132    //Remove any invalid files 
    127133    for(int i=0; i<bgL.length(); i++){  
    128       if( !QFile::exists(bgL[i]) || bgL[i].isEmpty()){ bgL.removeAt(i); i--; }  
     134      if( (!QFile::exists(bgL[i]) && bgL[i]!="default") || bgL[i].isEmpty()){ bgL.removeAt(i); i--; }  
    129135    } 
    130136  //Determine which background to use next 
    131   int index = bgL.indexOf(cbg); 
     137  int index = bgL.indexOf(CBG); 
    132138  if( (index < 0) || (index >= bgL.length()-1) ){ index = 0; } //use the first file 
    133139  else{ index++; } //use the next file in the list 
    134140  QString bgFile; 
    135   if( bgL.isEmpty() && cbg.isEmpty()){ bgFile = "default"; } 
    136   else if( bgL.isEmpty() && QFile::exists(cbg) ){ bgFile = cbg; } 
     141  if( bgL.isEmpty() && CBG.isEmpty()){ bgFile = "default"; } 
     142  else if( bgL.isEmpty() && QFile::exists(CBG) ){ bgFile = CBG; } 
    137143  else if( bgL.isEmpty() ){ bgFile = "default"; } 
    138144  else{ bgFile = bgL[index]; } 
    139145  //Save this file as the current background 
    140   settings->setValue(DPREFIX+"background/current", bgFile); 
     146  CBG = bgFile; 
     147  //qDebug() << " - Set Background to:" << CBG << index << bgL; 
    141148  if( (bgFile.toLower()=="default")){ bgFile = "/usr/local/share/Lumina-DE/desktop-background.jpg"; } 
    142149  //Now set this file as the current background 
    143   //QString display = QString( getenv("DISPLAY") ); 
    144   //display = display.section(".",0,0)+"."+desktopnumber; //only the current screen 
    145150  QString style = "QWidget#bgWindow{ border-image:url(%1) stretch;}"; 
    146151  style = style.arg(bgFile); 
    147152  bgWindow->setStyleSheet(style); 
    148153  bgWindow->show(); 
    149   //QString cmd = "xv +24 -maxp -rmode 5 -quit \""+bgFile+"\""; 
    150   //QProcess::startDetached(cmd); 
    151154  //Now reset the timer for the next change (if appropriate) 
    152155  if(bgL.length() > 1){ 
  • lumina/lumina-desktop/LDesktop.h

    r214f3d5 r49640df  
    1616#include <QDebug> 
    1717#include <QTimer> 
     18#include <QFileSystemWatcher> 
     19 
    1820 
    1921#include <LuminaXDG.h> 
     
    5052        AppMenu *appmenu; 
    5153        QList<LDPlugin*> PLUGINS; 
     54        QFileSystemWatcher *watcher; 
     55        QString CBG; //current background 
    5256         
    5357private slots: 
Note: See TracChangeset for help on using the changeset viewer.