Get image paths from tracker
[impuzzle] / src / trackerfiles.cpp
1 /*
2   Image Puzzle - A set your pieces straight game
3   Copyright (C) 2009  Timo Härkönen
4
5   This program is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "trackerfiles.h"
20
21 #include <QDebug>
22
23 TrackerFiles::TrackerFiles(QObject *parent) :
24     QObject(parent)
25 {
26     tracker_ = new QProcess(this);
27
28     connect(tracker_, SIGNAL(finished(int,QProcess::ExitStatus)),
29             this, SLOT(processFinished(int,QProcess::ExitStatus)));
30 }
31
32 void TrackerFiles::readFiles()
33 {
34     QString program("tracker-files");
35     QStringList args;
36     args << "-m" << "image/png" << "-m" << "image/jpeg";
37     tracker_->start(program, args);
38     // FIXME: this blocks execution
39     tracker_->waitForFinished();
40 }
41
42 void TrackerFiles::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
43 {
44     QStringList files;
45
46     if(exitCode == 0 && exitStatus == QProcess::NormalExit) {
47         QString stdOut = tracker_->readAllStandardOutput();
48         files = stdOut.split("\n");
49         // first row is not a path
50         if(!files.isEmpty()) {
51             files.removeAt(0);
52         }
53
54         files.removeAll("");
55         qDebug() << QString("Found %1 images").arg(files.count());
56     }
57     else {
58         qDebug() << tracker_->errorString();
59     }
60
61     emit filesRead(files);
62 }