a00b3e4673f7c5cff1a79955e070bffecaad500c
[bootcreen] / bootscreenR.cpp
1 #include "bootscreenR.h"
2
3 #include <QDir>
4 #include <QTime>
5 #include <QSettings>
6 #include <QDebug>
7
8 BootScreenR::BootScreenR()
9 {
10     logFile.setFileName("/home/user/.bootscreen/log.txt");
11
12     if (!logFile.open(QIODevice::ReadWrite | QIODevice::Text))
13         qDebug() << "Can't write log" << endl;
14
15     QTextStream out(&logFile);
16     out << "log" << endl;
17     QDir dir("/home/user/");
18     if (dir.cd(".bootscreen")) {
19         settingsFile.setFileName(dir.filePath("settings.ini"));
20         if (settingsFile.exists()){
21             QSettings tempSettings(settingsFile.fileName(),QSettings::IniFormat);
22             bool random = tempSettings.value("random").toBool();
23             if(random)
24                 selectRandomFile();
25         }
26         else
27            out << "Can't read settings file1111" << endl;
28      }
29      else
30         out << "Can't read settings file2222" << endl;
31
32 }
33
34 void BootScreenR::selectRandomFile()
35 {
36     QTextStream out(&logFile);
37     //currentFile
38     QSettings settings("/etc/hildon-welcome.d/0.conf",QSettings::IniFormat);
39     if (!settings.isWritable())
40         out << "Can't Write hildon-welcome settings" << endl;
41
42     else{
43         settings.beginGroup("hildon-welcome");
44         QString currentFile = settings.value("filename").toString();
45
46         QDir videosDir("/opt/bootscreen/media");
47         videosDir.setFilter(QDir::Files | QDir::NoSymLinks);
48         videosDir.setSorting(QDir::Name);
49         QFileInfoList ls = videosDir.entryInfoList();
50         for (int i = 0; i < ls.size(); ++i) {
51             QFileInfo fileInfo = ls.at(i);
52             if(fileInfo.absoluteFilePath() != currentFile)
53                 files.append(fileInfo.absoluteFilePath());
54         }
55
56         if(files.size()>0){
57             QTime fixTime(0, 0, 0);
58             qsrand(fixTime.secsTo(QTime::currentTime()));
59             int randomNumb = qrand() % files.size();
60             settings.setValue("filename", files.at(randomNumb));
61         }
62         else
63             out << "Can't randomize: Only one file in the media directory." << endl;
64     }
65 }
66
67 BootScreenR::~BootScreenR()
68 {
69 }