Changeset ca9d4b3


Ignore:
Timestamp:
12/06/13 06:47:18 (10 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3
Children:
93032ef
Parents:
15ea961
Message:

Get the Resources functionality finished up in the new EasyPBI module class.

Location:
src-qt4/EasyPBI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/EasyPBI/PBIModule.cpp

    rffa2c7a rca9d4b3  
    218218//      RESOURCES 
    219219// ============= 
    220          
     220QStringList PBIModule::existingResources(){ 
     221  QStringList out = filesInDir(basePath+"/resources"); 
     222  return out;    
     223} 
     224 
     225bool PBIModule::addResource(QString filePath, QString resourcePath){ 
     226  if(resourcePath.isEmpty()){ 
     227    resourcePath = filePath.section("/",-1); //same file name, in the base resources dir 
     228  } 
     229  bool ok = false; 
     230  if(QFile::exists(filePath)){ 
     231    //Create an intermediary directories in the resources dir 
     232    QString rPath = basePath+"/resources/"+resourcePath.left(resourcePath.length() - resourcePath.section("/",-1).length()); 
     233    QDir dir(rPath); 
     234    if(!dir.exists()){  
     235      ok = dir.mkPath(rPath);  
     236      if(!ok){ 
     237        qDebug() << "Error: Could not create directory: "<<rPath; 
     238        return ok; 
     239      } 
     240    } 
     241    //Now check if that file already exists 
     242    if(QFile::exists(basePath+"/resources/"+resourcePath)){ 
     243      ok = QFile::remove(basePath+"/resources/"+resourcePath); //Overwrite existing file 
     244      if(!ok){ 
     245        qDebug() << "Error: Could not remove existing file: "<<basePath+"/resources/"+resourcePath; 
     246        return ok; 
     247      } 
     248    } 
     249    ok = QFile::copy(filePath, basePath+"/resources/"+resourcePath); 
     250  }else{ 
     251    qDebug() << "Error: File to add to resources does not exist: "<<filePath; 
     252  } 
     253  return ok; 
     254} 
     255 
    221256// ============= 
    222257//           XDG 
     
    227262// ============= 
    228263 
    229 // ============= 
    230 //  PRIVATE UTILITIES 
    231 // ============= 
     264// =============== 
     265//  GENERAL UTILITIES 
     266// =============== 
    232267bool PBIModule::createFile(QString fileName, QStringList contents){ 
    233268//fileName = full path to file (I.E. /home/pcbsd/junk/junk.txt) 
     
    307342  return contents; 
    308343} 
     344 
     345QStringList PBIModule::filesInDir(QString dirPath){ 
     346  //This is a recursive function for listing all the files in a directory (or subdirectories) 
     347  QStringList out; 
     348  QDir dir(dirPath); 
     349  if(dir.exists(dirPath)){ 
     350    QStringList subdirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); 
     351    out << dir.entryList(QDir::Files | QDir::NoDotAndDotDot,QDir::Name); 
     352    for(int i=0, i<subdirs.length(); i++){ 
     353      out << filesInDir(dirPath+"/"+subdirs[i]); 
     354    } 
     355  } 
     356  return out;    
     357} 
  • src-qt4/EasyPBI/PBIModule.h

    rffa2c7a rca9d4b3  
    4343         
    4444        //Resources 
    45  
     45        QStringList existingResources(); 
     46        bool addResource(QString, QString); 
     47         
    4648        //XDG files 
    4749         
Note: See TracChangeset for help on using the changeset viewer.