From 6c182b1dbbdea9fed77741cd94567c8c4c58bdc9 Mon Sep 17 00:00:00 2001 From: Valerio Valerio Date: Thu, 25 Feb 2010 23:24:24 +0000 Subject: [PATCH] Initial commit --- Makefile | 236 ++++++++++++++++++++++++++++++++ bootscreen.cpp | 348 +++++++++++++++++++++++++++++++++++++++++++++++ bootscreen.h | 53 ++++++++ bootscreen.pro | 19 +++ bootscreenR.cpp | 69 ++++++++++ bootscreenR.h | 21 +++ data/bootscreen | 9 ++ data/bootscreen.desktop | 9 ++ data/bootscreen.sudoers | 1 + debian/changelog | 5 + debian/compat | 1 + debian/control | 15 ++ debian/copyright | 31 +++++ debian/dirs | 8 ++ debian/files | 1 + debian/postinst | 28 ++++ debian/rules | 73 ++++++++++ main.cpp | 17 +++ script/bootscreen | 25 ++++ 19 files changed, 969 insertions(+) create mode 100644 Makefile create mode 100644 bootscreen.cpp create mode 100644 bootscreen.h create mode 100644 bootscreen.pro create mode 100644 bootscreenR.cpp create mode 100644 bootscreenR.h create mode 100644 data/bootscreen create mode 100644 data/bootscreen.desktop create mode 100644 data/bootscreen.sudoers create mode 100644 debian/changelog create mode 100755 debian/compat create mode 100755 debian/control create mode 100644 debian/copyright create mode 100644 debian/dirs create mode 100644 debian/files create mode 100755 debian/postinst create mode 100755 debian/rules create mode 100644 main.cpp create mode 100755 script/bootscreen diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fbd8afe --- /dev/null +++ b/Makefile @@ -0,0 +1,236 @@ +############################################################################# +# Makefile for building: bootscreen +# Generated by qmake (2.01a) (Qt 4.6.2) on: Mon Feb 22 01:04:53 2010 +# Project: bootscreen.pro +# Template: app +# Command: /opt/qt4-maemo5/bin/qmake-qt4 -unix -o Makefile bootscreen.pro +############################################################################# + +####### Compiler, tools and options + +CC = gcc +CXX = g++ +DEFINES = -DQT_GL_NO_SCISSOR_TEST -DQT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH=1024 -DQT_NO_DEBUG -DQT_MAEMO5_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED +CFLAGS = -pipe -O3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -Wall -W -D_REENTRANT $(DEFINES) +CXXFLAGS = -pipe -O3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -Wall -W -D_REENTRANT $(DEFINES) +INCPATH = -I/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/linux-g++-maemo5 -I. -I/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/include/QtCore -I/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/include/QtGui -I/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/include/QtMaemo5 -I/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/include -I. +LINK = g++ +LFLAGS = -Wl,-rpath-link,/usr/lib -Wl,-O1 -Wl,--hash-style=gnu -Wl,-rpath,/opt/qt4-maemo5/lib +LIBS = $(SUBLIBS) -L/opt/qt4-maemo5/lib -lQtMaemo5 -L/opt/qt4-maemo5/lib -L/usr/X11R6/lib -lQtDBus -lQtXml -lQtGui -lQtCore -lpthread +AR = ar cqs +RANLIB = +QMAKE = /opt/qt4-maemo5/bin/qmake-qt4 +TAR = tar -cf +COMPRESS = gzip -9f +COPY = cp -f +SED = sed +COPY_FILE = $(COPY) +COPY_DIR = $(COPY) -r +STRIP = strip +INSTALL_FILE = install -m 644 -p +INSTALL_DIR = $(COPY_DIR) +INSTALL_PROGRAM = install -m 755 -p +DEL_FILE = rm -f +SYMLINK = ln -f -s +DEL_DIR = rmdir +MOVE = mv -f +CHK_DIR_EXISTS= test -d +MKDIR = mkdir -p + +####### Output directory + +OBJECTS_DIR = ./ + +####### Files + +SOURCES = bootscreen.cpp \ + main.cpp \ + bootscreenR.cpp moc_bootscreen.cpp +OBJECTS = bootscreen.o \ + main.o \ + bootscreenR.o \ + moc_bootscreen.o +DIST = /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/common/unix.conf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/common/linux.conf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/qconfig.pri \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/qt_functions.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/qt_config.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/exclusive_builds.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/default_pre.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/release.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/default_post.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/warn_on.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/qt.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/unix/thread.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/moc.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/resources.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/uic.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/yacc.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/lex.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/include_source_dir.prf \ + bootscreen.pro +QMAKE_TARGET = bootscreen +DESTDIR = +TARGET = bootscreen + +first: all +####### Implicit rules + +.SUFFIXES: .o .c .cpp .cc .cxx .C + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" + +####### Build rules + +all: Makefile $(TARGET) + +$(TARGET): $(OBJECTS) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) + +Makefile: bootscreen.pro /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/linux-g++-maemo5/qmake.conf /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/common/unix.conf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/common/linux.conf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/qconfig.pri \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/qt_functions.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/qt_config.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/exclusive_builds.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/default_pre.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/release.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/default_post.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/warn_on.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/qt.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/unix/thread.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/moc.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/resources.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/uic.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/yacc.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/lex.prf \ + /targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/include_source_dir.prf \ + /opt/qt4-maemo5/lib/libQtMaemo5.prl \ + /opt/qt4-maemo5/lib/libQtDBus.prl \ + /opt/qt4-maemo5/lib/libQtXml.prl \ + /opt/qt4-maemo5/lib/libQtCore.prl \ + /opt/qt4-maemo5/lib/libQtGui.prl + $(QMAKE) -unix -o Makefile bootscreen.pro +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/common/unix.conf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/common/linux.conf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/qconfig.pri: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/qt_functions.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/qt_config.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/exclusive_builds.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/default_pre.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/release.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/default_post.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/warn_on.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/qt.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/unix/thread.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/moc.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/resources.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/uic.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/yacc.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/lex.prf: +/targets/FREMANTLE_ARMEL/opt/qt4-maemo5/mkspecs/features/include_source_dir.prf: +/opt/qt4-maemo5/lib/libQtMaemo5.prl: +/opt/qt4-maemo5/lib/libQtDBus.prl: +/opt/qt4-maemo5/lib/libQtXml.prl: +/opt/qt4-maemo5/lib/libQtCore.prl: +/opt/qt4-maemo5/lib/libQtGui.prl: +qmake: FORCE + @$(QMAKE) -unix -o Makefile bootscreen.pro + +dist: + @$(CHK_DIR_EXISTS) .tmp/bootscreen1.0.0 || $(MKDIR) .tmp/bootscreen1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/bootscreen1.0.0/ && $(COPY_FILE) --parents bootscreen.h bootscreenR.h .tmp/bootscreen1.0.0/ && $(COPY_FILE) --parents bootscreen.cpp main.cpp bootscreenR.cpp .tmp/bootscreen1.0.0/ && (cd `dirname .tmp/bootscreen1.0.0` && $(TAR) bootscreen1.0.0.tar bootscreen1.0.0 && $(COMPRESS) bootscreen1.0.0.tar) && $(MOVE) `dirname .tmp/bootscreen1.0.0`/bootscreen1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/bootscreen1.0.0 + + +clean:compiler_clean + -$(DEL_FILE) $(OBJECTS) + -$(DEL_FILE) *~ core *.core + + +####### Sub-libraries + +distclean: clean + -$(DEL_FILE) $(TARGET) + -$(DEL_FILE) Makefile + + +install: $(TARGET) install_app install_dsk install_sd install_evd install_scr + +install_app: + $(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)/opt/bootscreen/$(QMAKE_TARGET) + +install_dsk: + $(INSTALL_FILE) data/$(QMAKE_TARGET).desktop $(DESTDIR)/usr/share/applications/hildon/$(QMAKE_TARGET).desktop + +install_sd: + $(INSTALL_FILE) data/$(QMAKE_TARGET).sudoers $(DESTDIR)/etc/sudoers.d/$(QMAKE_TARGET).sudoers + +install_evd: + $(INSTALL_FILE) data/$(QMAKE_TARGET) $(DESTDIR)/etc/event.d/$(QMAKE_TARGET) + +install_scr: + $(INSTALL_FILE) script/$(QMAKE_TARGET) $(DESTDIR)/usr/bin/$(QMAKE_TARGET) + +mocclean: compiler_moc_header_clean compiler_moc_source_clean + +mocables: compiler_moc_header_make_all compiler_moc_source_make_all + +compiler_moc_header_make_all: moc_bootscreen.cpp +compiler_moc_header_clean: + -$(DEL_FILE) moc_bootscreen.cpp +moc_bootscreen.cpp: bootscreen.h + /opt/qt4-maemo5/bin/moc $(DEFINES) $(INCPATH) bootscreen.h -o moc_bootscreen.cpp + +compiler_rcc_make_all: +compiler_rcc_clean: +compiler_image_collection_make_all: qmake_image_collection.cpp +compiler_image_collection_clean: + -$(DEL_FILE) qmake_image_collection.cpp +compiler_moc_source_make_all: +compiler_moc_source_clean: +compiler_uic_make_all: +compiler_uic_clean: +compiler_yacc_decl_make_all: +compiler_yacc_decl_clean: +compiler_yacc_impl_make_all: +compiler_yacc_impl_clean: +compiler_lex_make_all: +compiler_lex_clean: +compiler_clean: compiler_moc_header_clean + +####### Compile + +bootscreen.o: bootscreen.cpp bootscreen.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bootscreen.o bootscreen.cpp + +main.o: main.cpp bootscreen.h \ + bootscreenR.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp + +bootscreenR.o: bootscreenR.cpp bootscreenR.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bootscreenR.o bootscreenR.cpp + +moc_bootscreen.o: moc_bootscreen.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_bootscreen.o moc_bootscreen.cpp + +####### Install + +install: FORCE + +uninstall: FORCE + +FORCE: + diff --git a/bootscreen.cpp b/bootscreen.cpp new file mode 100644 index 0000000..fca329f --- /dev/null +++ b/bootscreen.cpp @@ -0,0 +1,348 @@ +#include "bootscreen.h" + +#include + +BootScreen::BootScreen(QWidget *parent) + : QMainWindow(parent) +{ + hildonWelcome = "/etc/hildon-welcome.d/"; + videosDir = "/opt/bootscreen/media/"; + 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("/home/user"); + if (!dir.cd(".bootscreen")) { + qWarning("Cannot find the \".bootscreen/\" directory"); + dir.mkdir(".bootscreen"); + if (!dir.cd(".bootscreen")) { + qWarning("Cannot create the \".bootscreen/\" directory"); + + //terminar applicacao + } + } + settingsFile.setFileName(dir.filePath("settings.ini")); + 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"); + + if(random){ + up->setEnabled(false); + down->setEnabled(false); + } + + layButtons->addWidget(up); + layButtons->addWidget(down); + lay->addLayout(layButtons); + + connect(up, SIGNAL(clicked()), this, SLOT(moveUp())); + connect(down, SIGNAL(clicked()), this, SLOT(moveDown())); + + 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 newFilePath = videosDir + fileInfo.fileName(); + qDebug() << newFilePath << endl; + qDebug() << fileInfo.size() << endl; + if(fileInfo.size() > 11100000) + QMaemo5InformationBox::information(this, "Error: The selected file is too big", + QMaemo5InformationBox::DefaultTimeout); + + else{ + QFile tempTest(newFilePath); + if(tempTest.exists()) + QMaemo5InformationBox::information(this, "Error: The file already exists", + QMaemo5InformationBox::DefaultTimeout); + else{ + bool result = fileCopy.copy(newFilePath); + // tamanho + if(result) + list->addItem(QString("%1").arg(fileInfo.fileName())); + else + QMaemo5InformationBox::information(this, "Error copying file", + QMaemo5InformationBox::DefaultTimeout); + } + } + + //add somewhere + } + +} + +void BootScreen::removeVideos() +{ + QListWidgetItem *temp; + QList selectedItems = list->selectedItems(); + if(selectedItems.size()>0){ + QDir vidDir(videosDir); + QMessageBox msgBox; + 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; + } + } + } + } + +} + +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); +} + +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); +} + +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, "Random mode: Selection disabled", + QMaemo5InformationBox::DefaultTimeout); + } + + random = 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 + + QTextStream out(&settingsFile); + out << "random=false" << endl; + + random = false; +} + +void BootScreen::writeFiles(){ + + //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); + } +} + +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 + + else{ + QString filePath = mediaFiles.value(filename); + QTextStream out(&confFile); + out << "[hildon-welcome]" << endl; + out << "filename=" << filePath << endl; + } + } + else + qDebug() << "print a error" << endl; +} + +void BootScreen::closeEvent(QCloseEvent *event) +{ + writeSettings(); + writeFiles(); + event->accept(); +} + +BootScreen::~BootScreen() +{ +} + + diff --git a/bootscreen.h b/bootscreen.h new file mode 100644 index 0000000..4637fe2 --- /dev/null +++ b/bootscreen.h @@ -0,0 +1,53 @@ +#include +#include + +#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 writeFiles(); + void createFile(QString filename, int index); + bool random; + QString hildonWelcome; + QString settingsPath; + QString videosDir; + QFile settingsFile; + QActionGroup *filterGroup; + QAction *mRandom; + QAction *mMultiple; + QHash mediaFiles; + QListWidget *list; + QPushButton *up; + QPushButton *down; + +private slots: + void addVideo(); + void removeVideos(); + void disableSelection(bool state); + void selectMultiple(bool state); + void moveUp(); + void moveDown(); +}; + +#endif // BOOTSCREEN_H diff --git a/bootscreen.pro b/bootscreen.pro new file mode 100644 index 0000000..9a7573b --- /dev/null +++ b/bootscreen.pro @@ -0,0 +1,19 @@ +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_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_p48.commands = $(INSTALL_FILE) data/$(QMAKE_TARGET)_48.png $(DESTDIR)/usr/share/icons/hicolor/48x48/apps/$(QMAKE_TARGET).png +#install_p64.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 +QMAKE_EXTRA_TARGETS += install install_app install_dsk install_sd install_evd install_scr diff --git a/bootscreenR.cpp b/bootscreenR.cpp new file mode 100644 index 0000000..a00b3e4 --- /dev/null +++ b/bootscreenR.cpp @@ -0,0 +1,69 @@ +#include "bootscreenR.h" + +#include +#include +#include +#include + +BootScreenR::BootScreenR() +{ + logFile.setFileName("/home/user/.bootscreen/log.txt"); + + if (!logFile.open(QIODevice::ReadWrite | QIODevice::Text)) + qDebug() << "Can't write log" << endl; + + QTextStream out(&logFile); + out << "log" << endl; + QDir dir("/home/user/"); + if (dir.cd(".bootscreen")) { + settingsFile.setFileName(dir.filePath("settings.ini")); + if (settingsFile.exists()){ + QSettings tempSettings(settingsFile.fileName(),QSettings::IniFormat); + bool random = tempSettings.value("random").toBool(); + if(random) + selectRandomFile(); + } + else + out << "Can't read settings file1111" << endl; + } + else + out << "Can't read settings file2222" << 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 new file mode 100644 index 0000000..9fa47d3 --- /dev/null +++ b/bootscreenR.h @@ -0,0 +1,21 @@ +#include +#include + +#ifndef BOOTSCREENR_H +#define BOOTSCREENR_H + +class BootScreenR +{ + +public: + BootScreenR(); + virtual ~BootScreenR(); + +private: + void selectRandomFile(); + QFile settingsFile; + QFile logFile; + QList files; +}; + +#endif // BOOTSCREENR_H diff --git a/data/bootscreen b/data/bootscreen new file mode 100644 index 0000000..111d390 --- /dev/null +++ b/data/bootscreen @@ -0,0 +1,9 @@ +description "BootScreen manager - Chooses a random bootscreen file" +author "Valerio Valerio" + +start on XSESSIONS_STARTING + +script + /opt/bootscreen/bootscreen --random +end script + diff --git a/data/bootscreen.desktop b/data/bootscreen.desktop new file mode 100644 index 0000000..5ca28be --- /dev/null +++ b/data/bootscreen.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=0.1 +Type=Application +Name=BootScreen +Exec= sudo /usr/bin/bootscreen +Icon= +MimeType=application/x-example; + diff --git a/data/bootscreen.sudoers b/data/bootscreen.sudoers new file mode 100644 index 0000000..921355f --- /dev/null +++ b/data/bootscreen.sudoers @@ -0,0 +1 @@ +user ALL = NOPASSWD: /usr/bin/bootscreen diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..e9274b2 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +bootscreen (0.1) unstable; urgency=low + + * Initial release. + + -- Valerio Valerio Sun, 21 Feb 2010 21:37:58 +0000 diff --git a/debian/compat b/debian/compat new file mode 100755 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100755 index 0000000..9ea6c6f --- /dev/null +++ b/debian/control @@ -0,0 +1,15 @@ +Source: bootscreen +Section: user/system +Priority: optional +Maintainer: Valerio Valerio +Build-Depends: debhelper (>= 5), libqt4-maemo5-dev +Standards-Version: 3.7.2 + +Package: bootscreen +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: bootscreen manager + Manage the system startup media. Add multiple videos or play a random video on boot. + . +XB-Maemo-Display-Name: BootScreen + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..147fbed --- /dev/null +++ b/debian/copyright @@ -0,0 +1,31 @@ +This package was debianized by Valerio Valerio on +Sun, 21 Feb 2010 22:36:02 +0000. + +It was downloaded from + +Upstream Author :Valerio Valerio + +Copyright: + + Copyright (C) 2010 - Valerio Valerio + +License: + + This package 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 2 of the License, or + (at your option) any later version. + + This package 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 package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +The Debian packaging is (C) 2010, Valerio Valerio and +is licensed under the GPL, see `/usr/share/common-licenses/GPL'. + diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..8806e73 --- /dev/null +++ b/debian/dirs @@ -0,0 +1,8 @@ +usr/bin/ +etc/sudoers.d/ +etc/event.d/ +opt/bootscreen/ +opt/bootscreen/media/ +usr/share/applications/hildon/ +usr/share/icons/hicolor/48x48/apps/ +usr/share/icons/hicolor/64x64/apps/ diff --git a/debian/files b/debian/files new file mode 100644 index 0000000..5c70659 --- /dev/null +++ b/debian/files @@ -0,0 +1 @@ +bootscreen_0.1_armel.deb user/system optional diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..d129b52 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,28 @@ +#! /bin/sh +# +# bootscreen - postinst +# +# Copyright 2010 Valério Valério +# +# +# 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 2 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, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + + + +echo "Updating Sudoers" +update-sudoers || true + +exit 0 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..3261823 --- /dev/null +++ b/debian/rules @@ -0,0 +1,73 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +export DH_VERBOSE=1 + +APPNAME := bootscreen + +configure: configure-stamp +configure-stamp: + dh_testdir + -qmake + -/opt/qt4-maemo5/bin/qmake-qt4 + touch configure-stamp + +build: build-stamp +build-stamp: configure-stamp + dh_testdir + $(MAKE) + touch build-stamp + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + -$(MAKE) clean + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + $(MAKE) DESTDIR=$(CURDIR)/debian/$(APPNAME) install + +binary-indep: build install +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_install + dh_installmenu + dh_installdebconf + dh_installlogrotate + dh_installemacsen + dh_installpam + dh_installmime +# dh_python + dh_installinit + dh_installcron + dh_installinfo + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_perl + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..19e5d29 --- /dev/null +++ b/main.cpp @@ -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(); + } + +} diff --git a/script/bootscreen b/script/bootscreen new file mode 100755 index 0000000..0e2cced --- /dev/null +++ b/script/bootscreen @@ -0,0 +1,25 @@ +#!/bin/sh + +# +# bootscreen +# +# Copyright 2010 Valério Valério +# +# +# 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 2 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, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + + +run-standalone.sh /opt/bootscreen/bootscreen -- 1.7.9.5