Move code into a subdir(/src)
authorValerio Valerio <vdv100@gmail.com>
Wed, 10 Mar 2010 22:56:55 +0000 (22:56 +0000)
committerValerio Valerio <vdv100@gmail.com>
Wed, 10 Mar 2010 22:56:55 +0000 (22:56 +0000)
12 files changed:
bootscreen.cpp [deleted file]
bootscreen.h [deleted file]
bootscreen.pro
bootscreenR.cpp [deleted file]
bootscreenR.h [deleted file]
main.cpp [deleted file]
src/bootscreen.cpp [new file with mode: 0644]
src/bootscreen.h [new file with mode: 0644]
src/bootscreen.pro [new file with mode: 0644]
src/bootscreenR.cpp [new file with mode: 0644]
src/bootscreenR.h [new file with mode: 0644]
src/main.cpp [new file with mode: 0644]

diff --git a/bootscreen.cpp b/bootscreen.cpp
deleted file mode 100644 (file)
index 0f9fd97..0000000
+++ /dev/null
@@ -1,390 +0,0 @@
-#include "bootscreen.h"
-
-#include <QtMaemo5>
-
-BootScreen::BootScreen(QWidget *parent)
-    : QMainWindow(parent)
-{
-    hildonWelcome = "/etc/hildon-welcome.d/";
-    videosDir = "/opt/bootscreen/media/";
-    settingsDir = "/opt/bootscreen/data/";
-    checkSettings();
-
-    filterGroup = new QActionGroup(this);
-    filterGroup->setExclusive(true);
-    mRandom = new QAction(tr("Random"), filterGroup);
-    mRandom->setCheckable(true);
-    mMultiple = new QAction(tr("Multiple"), filterGroup);
-    mMultiple->setCheckable(true);
-
-    //laod settings
-    if(random)
-        mRandom->setChecked(true);
-    else
-        mMultiple->setChecked(true);
-
-
-    connect(mRandom, SIGNAL(toggled(bool)), this, SLOT(disableSelection(bool)));
-    connect(mMultiple, SIGNAL(toggled(bool)), this, SLOT(selectMultiple(bool)));
-
-    menuBar()->addActions(filterGroup->actions());
-
-    menuBar()->addAction(tr("Add"), this, SLOT(addVideo()));
-    menuBar()->addAction(tr("Remove"), this, SLOT(removeVideos()));
-
-    createList();
-}
-
-void BootScreen::checkSettings()
-{
-    QDir dir(settingsDir);
-    settingsFile.setFileName(dir.filePath("bootscreen.conf"));
-
-    if (!settingsFile.exists())
-        restoreSettings();
-    else{
-         QSettings tempSettings(settingsFile.fileName(),QSettings::IniFormat);
-         random = tempSettings.value("random").toBool();
-    }
-}
-
-void BootScreen::createList()
-{
-    QWidget *central = new QWidget();
-
-    QVBoxLayout *lay = new QVBoxLayout(central);
-    lay->setSpacing(8);
-    lay->setContentsMargins(0, 0, 0, 15);
-
-    list = new QListWidget();
-
-
-    list->setSelectionMode(QAbstractItemView::MultiSelection);
-
-    QDir dirHildon(hildonWelcome);
-    dirHildon.setFilter(QDir::Files | QDir::NoSymLinks);
-    dirHildon.setSorting(QDir::Name);
-
-    QFileInfoList ls = dirHildon.entryInfoList();
-    for (int i = 0; i < ls.size(); ++i) {
-        QFileInfo fileInfo = ls.at(i);
-        QSettings tempSettings(fileInfo.absoluteFilePath(),QSettings::IniFormat);
-        tempSettings.beginGroup("hildon-welcome");
-
-        QFileInfo prettyName(tempSettings.value("filename").toString());
-        list->addItem(QString("%1").arg(prettyName.fileName()));
-        mediaFiles[prettyName.fileName()] = tempSettings.value("filename").toString();
-
-
-        qDebug() << fileInfo.absoluteFilePath() << endl;
-        qDebug() << tempSettings.value("filename") << endl;
-    }
-
-
-    QListWidgetItem *temp;
-    int listSize = list->count();
-    //activate items
-    for(int i = 0; i < listSize; i++){
-        temp = list->item(i);
-        if(temp)
-            temp->setSelected(true);
-    }
-
-    if(random)
-        list->setSelectionMode(QAbstractItemView::NoSelection);
-
-    //Add hands video
-
-    if(!mediaFiles.contains("Hands-v32-h264.avi")){
-        QFileInfo handsTmp("/usr/share/hildon-welcome/media/Hands-v32-h264.avi");
-        if(handsTmp.exists()){
-            mediaFiles[handsTmp.fileName()] = handsTmp.absoluteFilePath();
-            list->addItem(QString("%1").arg(handsTmp.fileName()));
-        }
-    }
-
-    QDir dir(videosDir);
-    dir.setFilter(QDir::Files | QDir::NoSymLinks);
-    dir.setSorting(QDir::Name);
-    //if empty show warning to add a file via menu
-
-    ls = dir.entryInfoList();
-    for (int i = 0; i < ls.size(); ++i) {
-        QFileInfo fileInfo = ls.at(i);
-        if(!mediaFiles.contains(fileInfo.fileName())){
-            mediaFiles[fileInfo.fileName()] = fileInfo.absoluteFilePath();
-            list->addItem(QString("%1").arg(fileInfo.fileName()));
-        }
-        qDebug() << fileInfo.absoluteFilePath() << endl;
-
-    }
-
-   // for(int i =0; i < 8; i++){
-     //  list->addItem("bbr");
-    //}
-
-    lay->addWidget(list);
-
-    QHBoxLayout *layButtons = new QHBoxLayout();
-    up = new QPushButton("Up");
-    down = new QPushButton("Down");
-    save = new QPushButton("Save");
-    save->setEnabled(false);
-
-    if(random){
-        up->setEnabled(false);
-        down->setEnabled(false);
-    }
-
-    layButtons->addWidget(up);
-    layButtons->addWidget(down);
-    layButtons->addSpacing(50);
-    layButtons->addWidget(save);
-    lay->addLayout(layButtons);
-
-    connect(up, SIGNAL(clicked()), this, SLOT(moveUp()));
-    connect(down, SIGNAL(clicked()), this, SLOT(moveDown()));
-    connect(save, SIGNAL(clicked()), this, SLOT(saveConfs()));
-    connect(list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(setPendingChanges(QListWidgetItem*)));
-
-    setCentralWidget(central);
-}
-
-void BootScreen::addVideo()
-{
-    QString filePath = QFileDialog::getOpenFileName(this,
-        tr("Open file"), "/home/user/MyDocs", tr("Video Files (*.avi)"));
-    qDebug() << filePath << endl;
-
-    if(filePath != ""){
-        QFile fileCopy(filePath);
-        QFileInfo fileInfo(filePath);
-        QString fileName = fileInfo.fileName();
-        //boot player can't read files with spaces in the name
-        fileName.replace(QString(" "), QString("_"));
-        QString newFilePath = videosDir + fileName;
-        qDebug() << newFilePath << endl;
-        qDebug() << fileInfo.size() << endl;
-        if(fileInfo.size() > 11100000)
-            QMaemo5InformationBox::information(this, "<font color=black><b>Error:</b> The selected file is too big</font>",
-                                                        QMaemo5InformationBox::DefaultTimeout);
-
-        else{
-            QFile tempTest(newFilePath);
-            if(tempTest.exists())
-                QMaemo5InformationBox::information(this, "<font color=black><b>Error:</b> The file already exists</font>",
-                                                            QMaemo5InformationBox::DefaultTimeout);
-            else{
-                bool result = fileCopy.copy(newFilePath);
-                if(result){
-                    list->addItem(QString("%1").arg(fileName));
-                    save->setEnabled(true);
-                    //autoselect item, if not in random mode
-                    if(!random){
-                        QListWidgetItem *currentItem = list->item(list->count()-1);
-                        currentItem->setSelected(true);
-                    }
-                }
-                else
-                    QMaemo5InformationBox::information(this, "<font color=black>Error copying file</font>",
-                                                                QMaemo5InformationBox::DefaultTimeout);
-            }
-        }
-    }
-
-}
-
-void BootScreen::removeVideos()
-{
-    QListWidgetItem *temp;
-    QList <QListWidgetItem *> selectedItems = list->selectedItems();
-    if(selectedItems.size()>0){
-        QDir vidDir(videosDir);
-        int ret = QMessageBox::information(this, tr("Remove files"), tr("Remove selected file(s) ?"), QMessageBox::Yes | QMessageBox::No);
-
-        if(ret == QMessageBox::Yes){
-            for(int i=0; i< selectedItems.size();i++){
-                temp = selectedItems.at(i);
-                bool result = vidDir.remove(temp->text());
-                qDebug() << result << " :" << temp->text() << endl;
-
-                if(result){
-                    int rw = list->row(temp);
-                    temp = list->takeItem(rw);
-                    delete temp;
-                }
-            }
-            save->setEnabled(true);
-        }
-    }
-
-}
-
-void BootScreen::moveUp()
-{
-    int currentRow = list->currentRow();
-    if (currentRow == 0) return;
-    QListWidgetItem * currentItem = list->takeItem(currentRow);
-    list->insertItem(currentRow - 1, currentItem);
-    list->setCurrentRow(currentRow - 1);
-    save->setEnabled(true);
-}
-
-void BootScreen::moveDown()
-{
-    int currentRow = list->currentRow();
-    if (currentRow >= list->count()-1) return;
-    QListWidgetItem * currentItem = list->takeItem(currentRow);
-    list->insertItem(currentRow + 1, currentItem);
-    list->setCurrentRow(currentRow + 1);
-    save->setEnabled(true);
-}
-
-void BootScreen::disableSelection(bool state)
-{
-    if(state){
-        up->setEnabled(false);
-        down->setEnabled(false);
-        QListWidgetItem *temp;
-        int listSize = list->count();
-        //disable items
-        QTime fixTime(0, 0, 0);
-        qsrand(fixTime.secsTo(QTime::currentTime()));
-        int randomNumb = qrand() % listSize;
-        qDebug() << randomNumb << endl;
-        for(int i = 0; i < listSize; i++){
-            temp = list->item(i);
-            if(temp){
-                if(i == randomNumb)
-                    temp->setSelected(true);
-                else
-                    temp->setSelected(false);
-            }
-        }
-        list->setSelectionMode(QAbstractItemView::NoSelection);
-        QMaemo5InformationBox::information(this, "<font color=black><b>Random mode:</b> Selection disabled</font>",
-                                                    QMaemo5InformationBox::DefaultTimeout);
-    }
-
-    random = true;
-    save->setEnabled(true);
-}
-
-void BootScreen::selectMultiple(bool state)
-{
-    if(state){
-        up->setEnabled(true);
-        down->setEnabled(true);
-        list->setSelectionMode(QAbstractItemView::MultiSelection);
-        random = false;
-    }
-}
-
-void BootScreen::writeSettings()
-{
-    QSettings settings(settingsFile.fileName(),QSettings::IniFormat);
-    settings.setValue("random", random);
-}
-
-void BootScreen::restoreSettings()
-{
-     qDebug() << settingsFile.fileName() << endl;
-
-     if (!settingsFile.open(QIODevice::ReadWrite | QIODevice::Text)){
-        qWarning("Cannot create the settings file"); //abord
-        QMaemo5InformationBox::information(this, "<font color=black><b>Error:</b> Cannot create the settings file</font>",
-                                                    QMaemo5InformationBox::DefaultTimeout);
-     }
-
-     QTextStream out(&settingsFile);
-     out << "random=false" << endl;
-
-     random = false;
-}
-
-void BootScreen::saveConfs(){
-
-    //remove old files
-    QDir dir(hildonWelcome);
-    dir.setFilter(QDir::Files);
-
-    QFileInfoList ls = dir.entryInfoList();
-    for (int i = 0; i < ls.size(); ++i) {
-        QFileInfo fileInfo = ls.at(i);
-        bool result = dir.remove(fileInfo.fileName());
-        qDebug() << result << " :" << fileInfo.fileName() << endl;
-    }
-
-    QListWidgetItem *temp;
-    for(int i=0; i< list->count();i++){
-        temp = list->item(i);
-        if(temp->isSelected())
-            if(random)
-                 createFile(temp->text(), 0);
-            else
-                createFile(temp->text(), i);
-    }
-    save->setEnabled(false);
-}
-
-void BootScreen::createFile(QString filename, int index)
-{
-    QString ind = QString::number(index);
-    if(mediaFiles.contains(filename)){
-        QFile confFile(hildonWelcome + ind + ".conf");
-        qDebug() << confFile.fileName() << endl;
-        if (!confFile.open(QIODevice::ReadWrite | QIODevice::Text)){
-           qWarning("Cannot create the settings file"); //abord
-           QMaemo5InformationBox::information(this, "<font color=black><b>Error:</b> Cannot create the configurations file</font>",
-                                                       QMaemo5InformationBox::DefaultTimeout);
-       }
-        else{
-            QString filePath = mediaFiles.value(filename);
-            QTextStream out(&confFile);
-            out << "[hildon-welcome]" << endl;
-            out << "filename=" << filePath << endl;
-        }
-    }
-    else{
-        qDebug() << filename << endl;
-        qDebug() << "File already exists" << endl;
-    }
-}
-
-void BootScreen::setPendingChanges(QListWidgetItem *item)
-{
-    if(!random)
-        save->setEnabled(true);
-}
-
-void BootScreen::closeEvent(QCloseEvent *event)
-{
-    if(save->isEnabled()){
-        int ret = QMessageBox::information(this, tr("There are pending changes"), tr("Do you want to save your changes?"),
-                                           QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
-
-        if(ret == QMessageBox::Save){
-            saveConfs();
-            writeSettings();
-            event->accept();
-
-        }
-        else if(ret == QMessageBox::Discard){
-            writeSettings();
-            event->accept();
-        }
-        else{
-            event->ignore();
-        }
-    }
-    else{
-        writeSettings();
-        event->accept();
-    }
-}
-
-BootScreen::~BootScreen()
-{
-}
-
-
diff --git a/bootscreen.h b/bootscreen.h
deleted file mode 100644 (file)
index 5b4fa79..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#include <QtGui>
-#include <QMainWindow>
-
-#ifndef BOOTSCREEN_H
-#define BOOTSCREEN_H
-
-
-struct bootConfFile {
-    QFileInfo name;
-    QFileInfo confFile;
-};
-
-class BootScreen : public QMainWindow
-{
-     Q_OBJECT
-
-public:
-    BootScreen(QWidget *parent = 0);
-    virtual ~BootScreen();
-
-protected:
-    void closeEvent(QCloseEvent *event);
-
-private:
-    void checkSettings();
-    void createList();
-    void writeSettings();
-    void restoreSettings();
-    void createFile(QString filename, int index);
-    bool random;
-    QString hildonWelcome;
-    QString settingsPath;
-    QString videosDir;
-    QString settingsDir;
-    QFile settingsFile;
-    QActionGroup *filterGroup;
-    QAction *mRandom;
-    QAction *mMultiple;
-    QHash <QString, QString> mediaFiles;
-    QListWidget *list;
-    QPushButton *up;
-    QPushButton *down;
-    QPushButton *save;
-
-private slots:
-    void addVideo();
-    void removeVideos();
-    void disableSelection(bool state);
-    void selectMultiple(bool state);
-    void moveUp();
-    void moveDown();
-    void saveConfs();
-    void setPendingChanges(QListWidgetItem* item);
-};
-
-#endif // BOOTSCREEN_H
index 5d5de4a..8d4f667 100644 (file)
@@ -1,20 +1,2 @@
-TARGET = bootscreen
-
-HEADERS += bootscreen.h \
-    bootscreenR.h
-SOURCES += bootscreen.cpp \
-    main.cpp \
-    bootscreenR.cpp
-QT += maemo5
-
-
-install_app.commands = $(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)/opt/bootscreen/$(QMAKE_TARGET)
-install_cfg.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET).conf $(DESTDIR)/opt/bootscreen/$(QMAKE_TARGET).conf
-install_dsk.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET).desktop $(DESTDIR)/usr/share/applications/hildon/$(QMAKE_TARGET).desktop
-install_sd.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET).sudoers $(DESTDIR)/etc/sudoers.d/$(QMAKE_TARGET).sudoers
-install_evd.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET) $(DESTDIR)/etc/event.d/$(QMAKE_TARGET)
-install_scr.commands = $(INSTALL_FILE) script/$(QMAKE_TARGET) $(DESTDIR)/usr/bin/$(QMAKE_TARGET)
-install_i48.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET)_48.png $(DESTDIR)/usr/share/icons/hicolor/48x48/apps/$(QMAKE_TARGET).png
-install_i64.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET)_64.png $(DESTDIR)/usr/share/icons/hicolor/64x64/apps/$(QMAKE_TARGET).png
-install.depends = $(TARGET) install_app install_dsk install_sd install_evd install_scr install_i48 install_i64
-QMAKE_EXTRA_TARGETS += install install_app install_dsk install_sd install_evd install_scr install_i48 install_i64
+TEMPLATE = subdirs
+SUBDIRS = src plugin
diff --git a/bootscreenR.cpp b/bootscreenR.cpp
deleted file mode 100644 (file)
index f672b22..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-#include "bootscreenR.h"
-
-#include <QDir>
-#include <QTime>
-#include <QSettings>
-#include <QDebug>
-
-BootScreenR::BootScreenR()
-{
-    settingsDir = "/opt/bootscreen/data/";
-    logFile.setFileName("/opt/bootscreen/data/log.txt");
-
-    if (!logFile.open(QIODevice::ReadWrite | QIODevice::Text))
-        qDebug() << "Can't write log" << endl;
-
-    QTextStream out(&logFile);
-    //out << "log" << endl;
-    QDir dir(settingsDir);
-
-    settingsFile.setFileName(dir.filePath("bootscreen.conf"));
-    if (settingsFile.exists()){
-        QSettings tempSettings(settingsFile.fileName(),QSettings::IniFormat);
-        bool random = tempSettings.value("random").toBool();
-        if(random)
-            selectRandomFile();
-    }
-    else
-       out << "Can't read settings file" << endl;
-}
-
-void BootScreenR::selectRandomFile()
-{
-    QTextStream out(&logFile);
-    //currentFile
-    QSettings settings("/etc/hildon-welcome.d/0.conf",QSettings::IniFormat);
-    if (!settings.isWritable())
-        out << "Can't Write hildon-welcome settings" << endl;
-
-    else{
-        settings.beginGroup("hildon-welcome");
-        QString currentFile = settings.value("filename").toString();
-
-        QDir videosDir("/opt/bootscreen/media");
-        videosDir.setFilter(QDir::Files | QDir::NoSymLinks);
-        videosDir.setSorting(QDir::Name);
-        QFileInfoList ls = videosDir.entryInfoList();
-        for (int i = 0; i < ls.size(); ++i) {
-            QFileInfo fileInfo = ls.at(i);
-            if(fileInfo.absoluteFilePath() != currentFile)
-                files.append(fileInfo.absoluteFilePath());
-        }
-
-        if(files.size()>0){
-            QTime fixTime(0, 0, 0);
-            qsrand(fixTime.secsTo(QTime::currentTime()));
-            int randomNumb = qrand() % files.size();
-            settings.setValue("filename", files.at(randomNumb));
-        }
-        else
-            out << "Can't randomize: Only one file in the media directory." << endl;
-    }
-}
-
-BootScreenR::~BootScreenR()
-{
-}
diff --git a/bootscreenR.h b/bootscreenR.h
deleted file mode 100644 (file)
index b5b2cfd..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#include <QFile>
-#include <QTextStream>
-
-#ifndef BOOTSCREENR_H
-#define BOOTSCREENR_H
-
-class BootScreenR
-{
-
-public:
-    BootScreenR();
-    virtual ~BootScreenR();
-
-private:
-    void selectRandomFile();
-    QString settingsDir;
-    QFile settingsFile;
-    QFile logFile;
-    QList<QString> files;
-};
-
-#endif // BOOTSCREENR_H
diff --git a/main.cpp b/main.cpp
deleted file mode 100644 (file)
index 19e5d29..0000000
--- a/main.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "bootscreen.h"
-#include "bootscreenR.h"
-
-int main(int argc, char *argv[])
-{
-    QString arg = argv[1];
-
-    if (arg == "--random")
-        BootScreenR br;
-    else{
-        QApplication app(argc, argv);
-        BootScreen bs;
-        bs.show();
-        return app.exec();
-    }
-
-}
diff --git a/src/bootscreen.cpp b/src/bootscreen.cpp
new file mode 100644 (file)
index 0000000..0f9fd97
--- /dev/null
@@ -0,0 +1,390 @@
+#include "bootscreen.h"
+
+#include <QtMaemo5>
+
+BootScreen::BootScreen(QWidget *parent)
+    : QMainWindow(parent)
+{
+    hildonWelcome = "/etc/hildon-welcome.d/";
+    videosDir = "/opt/bootscreen/media/";
+    settingsDir = "/opt/bootscreen/data/";
+    checkSettings();
+
+    filterGroup = new QActionGroup(this);
+    filterGroup->setExclusive(true);
+    mRandom = new QAction(tr("Random"), filterGroup);
+    mRandom->setCheckable(true);
+    mMultiple = new QAction(tr("Multiple"), filterGroup);
+    mMultiple->setCheckable(true);
+
+    //laod settings
+    if(random)
+        mRandom->setChecked(true);
+    else
+        mMultiple->setChecked(true);
+
+
+    connect(mRandom, SIGNAL(toggled(bool)), this, SLOT(disableSelection(bool)));
+    connect(mMultiple, SIGNAL(toggled(bool)), this, SLOT(selectMultiple(bool)));
+
+    menuBar()->addActions(filterGroup->actions());
+
+    menuBar()->addAction(tr("Add"), this, SLOT(addVideo()));
+    menuBar()->addAction(tr("Remove"), this, SLOT(removeVideos()));
+
+    createList();
+}
+
+void BootScreen::checkSettings()
+{
+    QDir dir(settingsDir);
+    settingsFile.setFileName(dir.filePath("bootscreen.conf"));
+
+    if (!settingsFile.exists())
+        restoreSettings();
+    else{
+         QSettings tempSettings(settingsFile.fileName(),QSettings::IniFormat);
+         random = tempSettings.value("random").toBool();
+    }
+}
+
+void BootScreen::createList()
+{
+    QWidget *central = new QWidget();
+
+    QVBoxLayout *lay = new QVBoxLayout(central);
+    lay->setSpacing(8);
+    lay->setContentsMargins(0, 0, 0, 15);
+
+    list = new QListWidget();
+
+
+    list->setSelectionMode(QAbstractItemView::MultiSelection);
+
+    QDir dirHildon(hildonWelcome);
+    dirHildon.setFilter(QDir::Files | QDir::NoSymLinks);
+    dirHildon.setSorting(QDir::Name);
+
+    QFileInfoList ls = dirHildon.entryInfoList();
+    for (int i = 0; i < ls.size(); ++i) {
+        QFileInfo fileInfo = ls.at(i);
+        QSettings tempSettings(fileInfo.absoluteFilePath(),QSettings::IniFormat);
+        tempSettings.beginGroup("hildon-welcome");
+
+        QFileInfo prettyName(tempSettings.value("filename").toString());
+        list->addItem(QString("%1").arg(prettyName.fileName()));
+        mediaFiles[prettyName.fileName()] = tempSettings.value("filename").toString();
+
+
+        qDebug() << fileInfo.absoluteFilePath() << endl;
+        qDebug() << tempSettings.value("filename") << endl;
+    }
+
+
+    QListWidgetItem *temp;
+    int listSize = list->count();
+    //activate items
+    for(int i = 0; i < listSize; i++){
+        temp = list->item(i);
+        if(temp)
+            temp->setSelected(true);
+    }
+
+    if(random)
+        list->setSelectionMode(QAbstractItemView::NoSelection);
+
+    //Add hands video
+
+    if(!mediaFiles.contains("Hands-v32-h264.avi")){
+        QFileInfo handsTmp("/usr/share/hildon-welcome/media/Hands-v32-h264.avi");
+        if(handsTmp.exists()){
+            mediaFiles[handsTmp.fileName()] = handsTmp.absoluteFilePath();
+            list->addItem(QString("%1").arg(handsTmp.fileName()));
+        }
+    }
+
+    QDir dir(videosDir);
+    dir.setFilter(QDir::Files | QDir::NoSymLinks);
+    dir.setSorting(QDir::Name);
+    //if empty show warning to add a file via menu
+
+    ls = dir.entryInfoList();
+    for (int i = 0; i < ls.size(); ++i) {
+        QFileInfo fileInfo = ls.at(i);
+        if(!mediaFiles.contains(fileInfo.fileName())){
+            mediaFiles[fileInfo.fileName()] = fileInfo.absoluteFilePath();
+            list->addItem(QString("%1").arg(fileInfo.fileName()));
+        }
+        qDebug() << fileInfo.absoluteFilePath() << endl;
+
+    }
+
+   // for(int i =0; i < 8; i++){
+     //  list->addItem("bbr");
+    //}
+
+    lay->addWidget(list);
+
+    QHBoxLayout *layButtons = new QHBoxLayout();
+    up = new QPushButton("Up");
+    down = new QPushButton("Down");
+    save = new QPushButton("Save");
+    save->setEnabled(false);
+
+    if(random){
+        up->setEnabled(false);
+        down->setEnabled(false);
+    }
+
+    layButtons->addWidget(up);
+    layButtons->addWidget(down);
+    layButtons->addSpacing(50);
+    layButtons->addWidget(save);
+    lay->addLayout(layButtons);
+
+    connect(up, SIGNAL(clicked()), this, SLOT(moveUp()));
+    connect(down, SIGNAL(clicked()), this, SLOT(moveDown()));
+    connect(save, SIGNAL(clicked()), this, SLOT(saveConfs()));
+    connect(list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(setPendingChanges(QListWidgetItem*)));
+
+    setCentralWidget(central);
+}
+
+void BootScreen::addVideo()
+{
+    QString filePath = QFileDialog::getOpenFileName(this,
+        tr("Open file"), "/home/user/MyDocs", tr("Video Files (*.avi)"));
+    qDebug() << filePath << endl;
+
+    if(filePath != ""){
+        QFile fileCopy(filePath);
+        QFileInfo fileInfo(filePath);
+        QString fileName = fileInfo.fileName();
+        //boot player can't read files with spaces in the name
+        fileName.replace(QString(" "), QString("_"));
+        QString newFilePath = videosDir + fileName;
+        qDebug() << newFilePath << endl;
+        qDebug() << fileInfo.size() << endl;
+        if(fileInfo.size() > 11100000)
+            QMaemo5InformationBox::information(this, "<font color=black><b>Error:</b> The selected file is too big</font>",
+                                                        QMaemo5InformationBox::DefaultTimeout);
+
+        else{
+            QFile tempTest(newFilePath);
+            if(tempTest.exists())
+                QMaemo5InformationBox::information(this, "<font color=black><b>Error:</b> The file already exists</font>",
+                                                            QMaemo5InformationBox::DefaultTimeout);
+            else{
+                bool result = fileCopy.copy(newFilePath);
+                if(result){
+                    list->addItem(QString("%1").arg(fileName));
+                    save->setEnabled(true);
+                    //autoselect item, if not in random mode
+                    if(!random){
+                        QListWidgetItem *currentItem = list->item(list->count()-1);
+                        currentItem->setSelected(true);
+                    }
+                }
+                else
+                    QMaemo5InformationBox::information(this, "<font color=black>Error copying file</font>",
+                                                                QMaemo5InformationBox::DefaultTimeout);
+            }
+        }
+    }
+
+}
+
+void BootScreen::removeVideos()
+{
+    QListWidgetItem *temp;
+    QList <QListWidgetItem *> selectedItems = list->selectedItems();
+    if(selectedItems.size()>0){
+        QDir vidDir(videosDir);
+        int ret = QMessageBox::information(this, tr("Remove files"), tr("Remove selected file(s) ?"), QMessageBox::Yes | QMessageBox::No);
+
+        if(ret == QMessageBox::Yes){
+            for(int i=0; i< selectedItems.size();i++){
+                temp = selectedItems.at(i);
+                bool result = vidDir.remove(temp->text());
+                qDebug() << result << " :" << temp->text() << endl;
+
+                if(result){
+                    int rw = list->row(temp);
+                    temp = list->takeItem(rw);
+                    delete temp;
+                }
+            }
+            save->setEnabled(true);
+        }
+    }
+
+}
+
+void BootScreen::moveUp()
+{
+    int currentRow = list->currentRow();
+    if (currentRow == 0) return;
+    QListWidgetItem * currentItem = list->takeItem(currentRow);
+    list->insertItem(currentRow - 1, currentItem);
+    list->setCurrentRow(currentRow - 1);
+    save->setEnabled(true);
+}
+
+void BootScreen::moveDown()
+{
+    int currentRow = list->currentRow();
+    if (currentRow >= list->count()-1) return;
+    QListWidgetItem * currentItem = list->takeItem(currentRow);
+    list->insertItem(currentRow + 1, currentItem);
+    list->setCurrentRow(currentRow + 1);
+    save->setEnabled(true);
+}
+
+void BootScreen::disableSelection(bool state)
+{
+    if(state){
+        up->setEnabled(false);
+        down->setEnabled(false);
+        QListWidgetItem *temp;
+        int listSize = list->count();
+        //disable items
+        QTime fixTime(0, 0, 0);
+        qsrand(fixTime.secsTo(QTime::currentTime()));
+        int randomNumb = qrand() % listSize;
+        qDebug() << randomNumb << endl;
+        for(int i = 0; i < listSize; i++){
+            temp = list->item(i);
+            if(temp){
+                if(i == randomNumb)
+                    temp->setSelected(true);
+                else
+                    temp->setSelected(false);
+            }
+        }
+        list->setSelectionMode(QAbstractItemView::NoSelection);
+        QMaemo5InformationBox::information(this, "<font color=black><b>Random mode:</b> Selection disabled</font>",
+                                                    QMaemo5InformationBox::DefaultTimeout);
+    }
+
+    random = true;
+    save->setEnabled(true);
+}
+
+void BootScreen::selectMultiple(bool state)
+{
+    if(state){
+        up->setEnabled(true);
+        down->setEnabled(true);
+        list->setSelectionMode(QAbstractItemView::MultiSelection);
+        random = false;
+    }
+}
+
+void BootScreen::writeSettings()
+{
+    QSettings settings(settingsFile.fileName(),QSettings::IniFormat);
+    settings.setValue("random", random);
+}
+
+void BootScreen::restoreSettings()
+{
+     qDebug() << settingsFile.fileName() << endl;
+
+     if (!settingsFile.open(QIODevice::ReadWrite | QIODevice::Text)){
+        qWarning("Cannot create the settings file"); //abord
+        QMaemo5InformationBox::information(this, "<font color=black><b>Error:</b> Cannot create the settings file</font>",
+                                                    QMaemo5InformationBox::DefaultTimeout);
+     }
+
+     QTextStream out(&settingsFile);
+     out << "random=false" << endl;
+
+     random = false;
+}
+
+void BootScreen::saveConfs(){
+
+    //remove old files
+    QDir dir(hildonWelcome);
+    dir.setFilter(QDir::Files);
+
+    QFileInfoList ls = dir.entryInfoList();
+    for (int i = 0; i < ls.size(); ++i) {
+        QFileInfo fileInfo = ls.at(i);
+        bool result = dir.remove(fileInfo.fileName());
+        qDebug() << result << " :" << fileInfo.fileName() << endl;
+    }
+
+    QListWidgetItem *temp;
+    for(int i=0; i< list->count();i++){
+        temp = list->item(i);
+        if(temp->isSelected())
+            if(random)
+                 createFile(temp->text(), 0);
+            else
+                createFile(temp->text(), i);
+    }
+    save->setEnabled(false);
+}
+
+void BootScreen::createFile(QString filename, int index)
+{
+    QString ind = QString::number(index);
+    if(mediaFiles.contains(filename)){
+        QFile confFile(hildonWelcome + ind + ".conf");
+        qDebug() << confFile.fileName() << endl;
+        if (!confFile.open(QIODevice::ReadWrite | QIODevice::Text)){
+           qWarning("Cannot create the settings file"); //abord
+           QMaemo5InformationBox::information(this, "<font color=black><b>Error:</b> Cannot create the configurations file</font>",
+                                                       QMaemo5InformationBox::DefaultTimeout);
+       }
+        else{
+            QString filePath = mediaFiles.value(filename);
+            QTextStream out(&confFile);
+            out << "[hildon-welcome]" << endl;
+            out << "filename=" << filePath << endl;
+        }
+    }
+    else{
+        qDebug() << filename << endl;
+        qDebug() << "File already exists" << endl;
+    }
+}
+
+void BootScreen::setPendingChanges(QListWidgetItem *item)
+{
+    if(!random)
+        save->setEnabled(true);
+}
+
+void BootScreen::closeEvent(QCloseEvent *event)
+{
+    if(save->isEnabled()){
+        int ret = QMessageBox::information(this, tr("There are pending changes"), tr("Do you want to save your changes?"),
+                                           QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+
+        if(ret == QMessageBox::Save){
+            saveConfs();
+            writeSettings();
+            event->accept();
+
+        }
+        else if(ret == QMessageBox::Discard){
+            writeSettings();
+            event->accept();
+        }
+        else{
+            event->ignore();
+        }
+    }
+    else{
+        writeSettings();
+        event->accept();
+    }
+}
+
+BootScreen::~BootScreen()
+{
+}
+
+
diff --git a/src/bootscreen.h b/src/bootscreen.h
new file mode 100644 (file)
index 0000000..5b4fa79
--- /dev/null
@@ -0,0 +1,56 @@
+#include <QtGui>
+#include <QMainWindow>
+
+#ifndef BOOTSCREEN_H
+#define BOOTSCREEN_H
+
+
+struct bootConfFile {
+    QFileInfo name;
+    QFileInfo confFile;
+};
+
+class BootScreen : public QMainWindow
+{
+     Q_OBJECT
+
+public:
+    BootScreen(QWidget *parent = 0);
+    virtual ~BootScreen();
+
+protected:
+    void closeEvent(QCloseEvent *event);
+
+private:
+    void checkSettings();
+    void createList();
+    void writeSettings();
+    void restoreSettings();
+    void createFile(QString filename, int index);
+    bool random;
+    QString hildonWelcome;
+    QString settingsPath;
+    QString videosDir;
+    QString settingsDir;
+    QFile settingsFile;
+    QActionGroup *filterGroup;
+    QAction *mRandom;
+    QAction *mMultiple;
+    QHash <QString, QString> mediaFiles;
+    QListWidget *list;
+    QPushButton *up;
+    QPushButton *down;
+    QPushButton *save;
+
+private slots:
+    void addVideo();
+    void removeVideos();
+    void disableSelection(bool state);
+    void selectMultiple(bool state);
+    void moveUp();
+    void moveDown();
+    void saveConfs();
+    void setPendingChanges(QListWidgetItem* item);
+};
+
+#endif // BOOTSCREEN_H
diff --git a/src/bootscreen.pro b/src/bootscreen.pro
new file mode 100644 (file)
index 0000000..5d5de4a
--- /dev/null
@@ -0,0 +1,20 @@
+TARGET = bootscreen
+
+HEADERS += bootscreen.h \
+    bootscreenR.h
+SOURCES += bootscreen.cpp \
+    main.cpp \
+    bootscreenR.cpp
+QT += maemo5
+
+
+install_app.commands = $(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)/opt/bootscreen/$(QMAKE_TARGET)
+install_cfg.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET).conf $(DESTDIR)/opt/bootscreen/$(QMAKE_TARGET).conf
+install_dsk.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET).desktop $(DESTDIR)/usr/share/applications/hildon/$(QMAKE_TARGET).desktop
+install_sd.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET).sudoers $(DESTDIR)/etc/sudoers.d/$(QMAKE_TARGET).sudoers
+install_evd.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET) $(DESTDIR)/etc/event.d/$(QMAKE_TARGET)
+install_scr.commands = $(INSTALL_FILE) script/$(QMAKE_TARGET) $(DESTDIR)/usr/bin/$(QMAKE_TARGET)
+install_i48.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET)_48.png $(DESTDIR)/usr/share/icons/hicolor/48x48/apps/$(QMAKE_TARGET).png
+install_i64.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET)_64.png $(DESTDIR)/usr/share/icons/hicolor/64x64/apps/$(QMAKE_TARGET).png
+install.depends = $(TARGET) install_app install_dsk install_sd install_evd install_scr install_i48 install_i64
+QMAKE_EXTRA_TARGETS += install install_app install_dsk install_sd install_evd install_scr install_i48 install_i64
diff --git a/src/bootscreenR.cpp b/src/bootscreenR.cpp
new file mode 100644 (file)
index 0000000..f672b22
--- /dev/null
@@ -0,0 +1,66 @@
+#include "bootscreenR.h"
+
+#include <QDir>
+#include <QTime>
+#include <QSettings>
+#include <QDebug>
+
+BootScreenR::BootScreenR()
+{
+    settingsDir = "/opt/bootscreen/data/";
+    logFile.setFileName("/opt/bootscreen/data/log.txt");
+
+    if (!logFile.open(QIODevice::ReadWrite | QIODevice::Text))
+        qDebug() << "Can't write log" << endl;
+
+    QTextStream out(&logFile);
+    //out << "log" << endl;
+    QDir dir(settingsDir);
+
+    settingsFile.setFileName(dir.filePath("bootscreen.conf"));
+    if (settingsFile.exists()){
+        QSettings tempSettings(settingsFile.fileName(),QSettings::IniFormat);
+        bool random = tempSettings.value("random").toBool();
+        if(random)
+            selectRandomFile();
+    }
+    else
+       out << "Can't read settings file" << endl;
+}
+
+void BootScreenR::selectRandomFile()
+{
+    QTextStream out(&logFile);
+    //currentFile
+    QSettings settings("/etc/hildon-welcome.d/0.conf",QSettings::IniFormat);
+    if (!settings.isWritable())
+        out << "Can't Write hildon-welcome settings" << endl;
+
+    else{
+        settings.beginGroup("hildon-welcome");
+        QString currentFile = settings.value("filename").toString();
+
+        QDir videosDir("/opt/bootscreen/media");
+        videosDir.setFilter(QDir::Files | QDir::NoSymLinks);
+        videosDir.setSorting(QDir::Name);
+        QFileInfoList ls = videosDir.entryInfoList();
+        for (int i = 0; i < ls.size(); ++i) {
+            QFileInfo fileInfo = ls.at(i);
+            if(fileInfo.absoluteFilePath() != currentFile)
+                files.append(fileInfo.absoluteFilePath());
+        }
+
+        if(files.size()>0){
+            QTime fixTime(0, 0, 0);
+            qsrand(fixTime.secsTo(QTime::currentTime()));
+            int randomNumb = qrand() % files.size();
+            settings.setValue("filename", files.at(randomNumb));
+        }
+        else
+            out << "Can't randomize: Only one file in the media directory." << endl;
+    }
+}
+
+BootScreenR::~BootScreenR()
+{
+}
diff --git a/src/bootscreenR.h b/src/bootscreenR.h
new file mode 100644 (file)
index 0000000..b5b2cfd
--- /dev/null
@@ -0,0 +1,22 @@
+#include <QFile>
+#include <QTextStream>
+
+#ifndef BOOTSCREENR_H
+#define BOOTSCREENR_H
+
+class BootScreenR
+{
+
+public:
+    BootScreenR();
+    virtual ~BootScreenR();
+
+private:
+    void selectRandomFile();
+    QString settingsDir;
+    QFile settingsFile;
+    QFile logFile;
+    QList<QString> files;
+};
+
+#endif // BOOTSCREENR_H
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644 (file)
index 0000000..19e5d29
--- /dev/null
@@ -0,0 +1,17 @@
+#include "bootscreen.h"
+#include "bootscreenR.h"
+
+int main(int argc, char *argv[])
+{
+    QString arg = argv[1];
+
+    if (arg == "--random")
+        BootScreenR br;
+    else{
+        QApplication app(argc, argv);
+        BootScreen bs;
+        bs.show();
+        return app.exec();
+    }
+
+}