{
imagePath_ = path;
}
+
+QStringList Settings::localImages() const
+{
+ return imageList_;
+}
+
+void Settings::setLocalImages(const QStringList &files)
+{
+ imageList_ = files;
+}
QString imagePath() const;
void setImagePath(const QString &path);
+ QStringList localImages() const;
+ void setLocalImages(const QStringList &files);
+
private:
Settings(QObject *parent = 0);
int pieceCount_;
QPixmap image_;
QString imagePath_;
+ QStringList imageList_;
};
#endif
#include "settingsdialog.h"
#include "settings.h"
#include "defines.h"
+#include "trackerfiles.h"
#include <QRadioButton>
#include <QPushButton>
selectedImageLabel_->setVisible(false);
+ trackerFiles_ = new TrackerFiles(this);
+
setLayout(mainLayout_);
connect(easyButton_, SIGNAL(toggled(bool)), this, SLOT(difficultySelectionChanged(bool)));
//connect(imageCombo_, SIGNAL(currentIndexChanged(QString)), this, SLOT(imageSelectionChanged(QString)));
connect(imageCombo_, SIGNAL(activated(QString)), this, SLOT(imageSelectionChanged(QString)));
connect(applyButton_, SIGNAL(clicked()), this, SLOT(applyClicked()));
+ connect(trackerFiles_, SIGNAL(filesRead(QStringList)), this, SLOT(trackerFilesRead(QStringList)));
}
int SettingsDialog::exec()
void SettingsDialog::imageSelectionChanged(const QString &txt)
{
if(txt == RANDOM_IMAGE_TXT) {
- qDebug() << "Random image selected";
-
- // Get random image from ~/MyDocs/.images/
- //TODO: images from other directories
- QStringList filters;
- filters << "*.jpg" << "*.png" << "*.xpm";
-
- QDir dir(QDir::homePath() + QLatin1String("/MyDocs/.images"));
- //dir.setNameFilters(filters);
-
- QStringList pics = dir.entryList(filters, QDir::Files | QDir::NoSymLinks);
-
- //qDebug() << QString("pics list contains %1 entries").arg(pics.count());
-
- if(!pics.isEmpty()) {
- QString path = QDir::homePath() + QLatin1String("/MyDocs/.images/") + pics.at(qrand() % pics.count());
- Settings::instance()->setImage(QPixmap(path));
- Settings::instance()->setImagePath(path);
+ if(Settings::instance()->localImages().isEmpty()) {
+ trackerFiles_->readFiles();
}
else {
- Settings::instance()->setImage(QPixmap(":/images/default.jpg"));
- Settings::instance()->setImagePath("default");
- }
-
- if(selectedImageLabel_->isVisible()) {
- selectedImageLabel_->setVisible(false);
+ trackerFilesRead(Settings::instance()->localImages());
}
}
else if(txt == SELECT_IMAGE_TXT) {
{
this->done(1);
}
+
+void SettingsDialog::trackerFilesRead(const QStringList &files)
+{
+ if(!files.isEmpty()) {
+ QString path = files.at(qrand() % files.count());
+ path = path.trimmed();
+ Settings::instance()->setImage(QPixmap(path));
+ Settings::instance()->setImagePath(path);
+
+ if(Settings::instance()->localImages().isEmpty()) {
+ Settings::instance()->setLocalImages(files);
+ }
+ }
+ else {
+ Settings::instance()->setImage(QPixmap(":/images/default.jpg"));
+ Settings::instance()->setImagePath("default");
+ }
+
+ if(selectedImageLabel_->isVisible()) {
+ selectedImageLabel_->setVisible(false);
+ }
+}
class QComboBox;
class QLabel;
class QPushButton;
+class TrackerFiles;
class SettingsDialog : public QDialog
{
void difficultySelectionChanged(bool value);
void imageSelectionChanged(const QString &txt);
void applyClicked();
+ void trackerFilesRead(const QStringList &files);
private:
QVBoxLayout *mainLayout_;
QLabel *selectedImageLabel_;
QPushButton *applyButton_;
+
+ TrackerFiles *trackerFiles_;
};
#endif
settingsdialog.h \
aboutdialog.h \
statistics.h \
- statisticsdialog.h
+ statisticsdialog.h \
+ trackerfiles.h
SOURCES += gameview.cpp \
main.cpp \
mainwindow.cpp \
settingsdialog.cpp \
aboutdialog.cpp \
statistics.cpp \
- statisticsdialog.cpp
+ statisticsdialog.cpp \
+ trackerfiles.cpp
RESOURCES += resources.qrc
desktop.files += impuzzle.desktop
desktop.path = /usr/share/applications/hildon/
+/*
+ Image Puzzle - A set your pieces straight game
+ Copyright (C) 2009 Timo Härkönen
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include "statistics.h"
#include "defines.h"
+/*
+ Image Puzzle - A set your pieces straight game
+ Copyright (C) 2009 Timo Härkönen
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifndef STATISTICS_H
#define STATISTICS_H
+/*
+ Image Puzzle - A set your pieces straight game
+ Copyright (C) 2009 Timo Härkönen
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include "statisticsdialog.h"
#include "statistics.h"
+/*
+ Image Puzzle - A set your pieces straight game
+ Copyright (C) 2009 Timo Härkönen
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifndef STATISTICSDIALOG_H
#define STATISTICSDIALOG_H
--- /dev/null
+/*
+ Image Puzzle - A set your pieces straight game
+ Copyright (C) 2009 Timo Härkönen
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "trackerfiles.h"
+
+#include <QDebug>
+
+TrackerFiles::TrackerFiles(QObject *parent) :
+ QObject(parent)
+{
+ tracker_ = new QProcess(this);
+
+ connect(tracker_, SIGNAL(finished(int,QProcess::ExitStatus)),
+ this, SLOT(processFinished(int,QProcess::ExitStatus)));
+}
+
+void TrackerFiles::readFiles()
+{
+ QString program("tracker-files");
+ QStringList args;
+ args << "-m" << "image/png" << "-m" << "image/jpeg";
+ tracker_->start(program, args);
+ // FIXME: this blocks execution
+ tracker_->waitForFinished();
+}
+
+void TrackerFiles::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
+{
+ QStringList files;
+
+ if(exitCode == 0 && exitStatus == QProcess::NormalExit) {
+ QString stdOut = tracker_->readAllStandardOutput();
+ files = stdOut.split("\n");
+ // first row is not a path
+ if(!files.isEmpty()) {
+ files.removeAt(0);
+ }
+
+ files.removeAll("");
+ qDebug() << QString("Found %1 images").arg(files.count());
+ }
+ else {
+ qDebug() << tracker_->errorString();
+ }
+
+ emit filesRead(files);
+}
--- /dev/null
+/*
+ Image Puzzle - A set your pieces straight game
+ Copyright (C) 2009 Timo Härkönen
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TRACKERFILES_H
+#define TRACKERFILES_H
+
+#include <QObject>
+#include <QProcess>
+
+class TrackerFiles : public QObject
+{
+Q_OBJECT
+public:
+ explicit TrackerFiles(QObject *parent = 0);
+
+signals:
+ void filesRead(const QStringList &files);
+
+public slots:
+ void readFiles();
+
+private slots:
+ void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
+
+private:
+ QProcess *tracker_;
+};
+
+#endif // TRACKERFILES_H