Added application config. Moved application data from /tmp to ~/.someplayer
authorNikolay Tischenko <niktischenko@gmail.com>
Wed, 22 Sep 2010 13:05:03 +0000 (20:05 +0700)
committerNikolay Tischenko <niktischenko@gmail.com>
Wed, 22 Sep 2010 13:05:03 +0000 (20:05 +0700)
12 files changed:
resources/random_active.png
resources/random_inactive.png
resources/repeat_active.png
someplayer.pro
src/config.cpp [new file with mode: 0644]
src/config.h [new file with mode: 0644]
src/library.h
src/mainwindow.cpp
src/player/player.cpp
src/player/player.h
src/someplayer.h
src/trackrenderer.cpp

index 5a8c319..aae80aa 100644 (file)
Binary files a/resources/random_active.png and b/resources/random_active.png differ
index 7b4ba32..746bcaf 100644 (file)
Binary files a/resources/random_inactive.png and b/resources/random_inactive.png differ
index 6a20a83..f574f11 100644 (file)
Binary files a/resources/repeat_active.png and b/resources/repeat_active.png differ
index ef5b1f1..a803c35 100644 (file)
@@ -24,7 +24,8 @@ SOURCES += src/main.cpp\
     src/playerform.cpp \
     src/libraryform.cpp \
     src/busywidget.cpp \
-    src/trackrenderer.cpp
+    src/trackrenderer.cpp \
+    src/config.cpp
 
 HEADERS  += src/mainwindow.h \
                src/player/player.h \
@@ -41,7 +42,8 @@ HEADERS  += src/mainwindow.h \
     src/playerform.h \
     src/libraryform.h \
     src/busywidget.h \
-    src/trackrenderer.h
+    src/trackrenderer.h \
+    src/config.h
 
 FORMS    += src/ui/mainwindow.ui \
     src/ui/playerform.ui \
diff --git a/src/config.cpp b/src/config.cpp
new file mode 100644 (file)
index 0000000..422e294
--- /dev/null
@@ -0,0 +1,31 @@
+#include "config.h"
+#include <QString>
+#include <QDir>
+
+using namespace SomePlayer::Storage;
+
+Config::Config()
+{
+       _settings = new QSettings(QString(applicationDir())+"/settings.ini", QSettings::IniFormat);
+}
+
+Config::~Config() {
+       delete _settings;
+}
+
+QString Config::applicationDir() {
+       QString path = QDir::homePath()+"/.someplayer";
+       QDir appdir(path);
+       if (!appdir.exists(path)) {
+               appdir.mkdir(path);
+       }
+       return path;
+}
+
+QVariant Config::getValue(QString key) {
+       return _settings->value(key);
+}
+
+void Config::setValue(QString key, QVariant value) {
+       _settings->setValue(key, value);
+}
diff --git a/src/config.h b/src/config.h
new file mode 100644 (file)
index 0000000..b1d98ed
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#include <QSettings>
+
+namespace SomePlayer {
+       namespace Storage {
+               class Config
+               {
+               public:
+                   Config();
+                   ~Config();
+                   QString applicationDir();
+                   QVariant getValue(QString key);
+                   void setValue(QString key, QVariant value);
+               private:
+                   QSettings *_settings;
+               };
+       };
+};
+
+#endif // CONFIG_H
index 6f69661..b7e674b 100644 (file)
@@ -28,9 +28,6 @@
 #include "mediascanner.h"
 #include "tagresolver.h"
 
-#define _DATABASE_PATH_ "/tmp"
-#define _PLAYLISTS_PATH_ "/tmp"
-
 // represents media library: tracks, playlists
 // it uses different media storages for tracks and playlists
 // but dynamic playlits will be stored with tracks into the same storage
index 6347ae8..0570563 100644 (file)
 #include "library.h"
 
 using namespace SomePlayer::DataObjects;
+using namespace SomePlayer::Storage;
 
 MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
 {
-       _library = new Library(_DATABASE_PATH_, _PLAYLISTS_PATH_);
+       Config config;
+       _library = new Library(config.applicationDir(), config.applicationDir());
        ui->setupUi(this);
        connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
        connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
index 6f8ebb2..0181fc6 100644 (file)
@@ -22,6 +22,7 @@
 
 using namespace SomePlayer::Playback;
 using namespace SomePlayer::DataObjects;
+using namespace SomePlayer::Storage;
 
 Player::Player(QObject *parent) :
     QObject(parent)
@@ -34,8 +35,8 @@ Player::Player(QObject *parent) :
        Phonon::createPath(_player, _output);
        int seed = reinterpret_cast<int> (_player);
        qsrand(seed);
-       _random = false;
-       _repeat = false;
+       _random = _config.getValue("playback/random").toBool();
+       _repeat = _config.getValue("playback/repeat").toBool();
        _current = -1;
 }
 
@@ -111,7 +112,7 @@ void Player::prev() {
        play();
 }
 
-void Player::_stateChanged(Phonon::State newState, Phonon::State oldState) {
+void Player::_stateChanged(Phonon::State newState, Phonon::State /*oldState*/) {
        switch (newState) {
        case Phonon::PlayingState:
                if (_state == PLAYER_LOADING) {
@@ -174,3 +175,14 @@ void Player::play() {
 void Player::enqueue(int id) {
        _queue.enqueue(id);
 }
+
+void Player::toggleRandom() {
+       _random = !_random;
+       _config.setValue("playback/random", _random);
+}
+
+void Player::toggleRepeat() {
+       _repeat = !_repeat;
+       _config.setValue("playback/repeat", _repeat);
+}
+
index a2fdbf7..cf45026 100644 (file)
@@ -16,6 +16,7 @@
 using SomePlayer::DataObjects::Track;
 using SomePlayer::DataObjects::TrackMetadata;
 using SomePlayer::DataObjects::Playlist;
+using SomePlayer::Storage::Config;
 
 namespace SomePlayer {
        namespace Playback {
@@ -47,8 +48,8 @@ namespace SomePlayer {
                        void next();
                        void prev();
                        void setPlaylist(Playlist);
-                       void toggleRandom() {_random = !_random;}
-                       void toggleRepeat() {_repeat = !_repeat;}
+                       void toggleRandom();
+                       void toggleRepeat();
                        void seek(int);
                private slots:
                        void _stateChanged(Phonon::State, Phonon::State);
@@ -65,6 +66,7 @@ namespace SomePlayer {
                        Phonon::MediaObject *_player;
                        Phonon::AudioOutput *_output;
                        PlayerState _state;
+                       Config _config;
 
                        void _set_source();
 
index 44e5bda..6ecab29 100644 (file)
@@ -44,6 +44,7 @@ namespace SomePlayer {
 #include <QList>
 #include <QMap>
 #include <QUrl>
+#include "config.h"
 
 #define _DYNAMIC_PLAYLIST_MAX_COUNT_ 50
 
index e1a92d9..f3c0b8e 100644 (file)
@@ -70,7 +70,7 @@ void TrackRenderer::paint(QPainter *painter, const QStyleOptionViewItem &option,
 }
 
 QSize TrackRenderer::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const {
-       return QSize(option.rect.width(), option.rect.height()/3);
+       return QSize(option.rect.width(), 80);
 }
 
 void TrackRenderer::setActiveRow(int r) {