1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

Ticket #81: use_app_directory.patch

File use_app_directory.patch, 2.8 KB (added by kvangend, 4 years ago)

This patch shows a (naive) solution to ticket:81

  • src/view/ImageStore.cpp

     
    2424 
    2525#include <QFile> 
    2626#include <QPainter> 
     27#include <QApplication> 
    2728 
     29 
    2830static ImageStore* theImageStorePtr = NULL; 
    2931 
    3032static const char* NOTFOUND="NotFound"; 
     
    6062QString ImageStore::getFilePath(const QString& anImageName, const QString& anExtension) const 
    6163{ 
    6264        // let's try to find the file and create the renderer... 
    63         QStringList mySearchPath = QString(".:images").split(":",QString::SkipEmptyParts); 
     65        QString myPwd = qApp->applicationDirPath(); 
     66        QStringList mySearchPath = (QString("%1:%1/images").arg(myPwd).arg(myPwd)) 
     67                                                           .split(":",QString::SkipEmptyParts); 
    6468        // add the local directory of the level file to the search path - at the beginning... 
    6569        mySearchPath.push_front(Level::getPathToLevelFile()); 
    6670        QStringList::iterator i; 
  • src/view/DrawWorld.cpp

     
    461461// FIXME: hardcoded path here! 
    462462DrawWorld::CongratDeathMessage::CongratDeathMessage( 
    463463                const QString& aMessage, 
    464                 DrawWorld* aScenePtr) : QGraphicsSvgItem("images/congrat-death-border.svg") 
     464                DrawWorld* aScenePtr) 
     465                : QGraphicsSvgItem(qApp->applicationDirPath() + "/images/congrat-death-border.svg") 
    465466{ 
    466467        // the image is put in scene coordinates 
    467468        QRectF myImageBounds = boundingRect(); 
  • src/view/ChooseLevel.cpp

     
    3636{ 
    3737    m_ui->setupUi(this); 
    3838        // TODO/FIXME: hardcoded file name here 
    39         readLevels("levels/levels.xml"); 
     39        readLevels( qApp->applicationDirPath() + "/levels/levels.xml" ); 
    4040        show(); 
    4141} 
    4242 
     
    119119        if (qName == "level") 
    120120        { 
    121121                // remove any starting/trailing whitespace and add the path name 
    122                 currentText = "levels/" + currentText.trimmed(); 
     122                currentText = qApp->applicationDirPath() + "/levels/" + currentText.trimmed(); 
    123123 
    124124                QTreeWidgetItem* item = new QTreeWidgetItem(theTreeWidget); 
    125125                item->setText(NR_COLUMN, QString::number(++theNr)); 
  • src/view/MainWindow.cpp

     
    8080        else 
    8181        { 
    8282                // TODO: fixme: hardcoded path here! 
    83                 QGraphicsSvgItem* myTitlePagePtr = new SplashScreen("images/title_page.svg"); 
     83                QGraphicsSvgItem* myTitlePagePtr = new SplashScreen( 
     84                                QString("%1/images/title_page.svg").arg(qApp->applicationDirPath()) ); 
    8485                QGraphicsScene* mySplashScenePtr = new QGraphicsScene(NULL); 
    8586 
    8687                mySplashScenePtr->addItem(myTitlePagePtr);