~zanneth/somafm-gtk

b20c5dd65514687912e37aabd3b5f03f16594eb3 — Charles Magahern 1 year, 10 months ago 3bdb75c
Save stations sorting preferences
4 files changed, 71 insertions(+), 0 deletions(-)

M CMakeLists.txt
A share/gsettings-schema.xml
M src/app.hpp
A src/prefs.hpp
M CMakeLists.txt => CMakeLists.txt +5 -0
@@ 65,3 65,8 @@ execute_process(
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)
install(FILES img/somafm.png DESTINATION share/icons/hicolor/512x512/apps)
install(FILES share/somafm.desktop DESTINATION share/applications)
install(
        FILES share/gsettings-schema.xml
        RENAME com.zanneth.somafmgtk.gschema.xml
        DESTINATION share/glib-2.0/schemas
)

A share/gsettings-schema.xml => share/gsettings-schema.xml +11 -0
@@ 0,0 1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<schemalist>
    <schema path="/com/zanneth/somafmgtk/" id="com.zanneth.somafmgtk" gettext-domain="somafmgtk">
        <key name="stations-sort-column" type="i">
            <default>0</default>
        </key>
        <key name="stations-sort-type" type="i">
            <default>0</default>
        </key>
    </schema>
</schemalist>

M src/app.hpp => src/app.hpp +18 -0
@@ 15,6 15,7 @@
#include "ini.hpp"
#include "model.hpp"
#include "player.hpp"
#include "prefs.hpp"
#include "service.hpp"

#include "../generated/somafm.png.h"


@@ 145,6 146,9 @@ private:

        // use description column as tooltip column
        _channels_tree_view->set_tooltip_column(3);

        // load sort column and type from preferences
        _list_model->set_sort_column(_prefs.stations_sort_column(), _prefs.stations_sort_type());
    }

    void


@@ 160,6 164,7 @@ private:
        _player.set_error_callback(std::bind(&SomaFM::_show_error, this, std::placeholders::_1));
        _tree_artwork_queue.set_completion_callback(std::bind(&SomaFM::_on_tree_artwork_completed, this, std::placeholders::_1));
        _now_playing_artwork_queue.set_completion_callback(std::bind(&SomaFM::_on_now_playing_artwork_completed, this, std::placeholders::_1));
        _list_model->signal_sort_column_changed().connect(sigc::mem_fun(*this, &SomaFM::_on_stations_sort_column_changed));

        _reload_timeout = Glib::TimeoutSource::create(RELOAD_INTERVAL_SECS * 1000);
        _reload_timeout->connect(sigc::mem_fun(*this, &SomaFM::_on_reload_timeout));


@@ 468,9 473,22 @@ private:
        }
    }

    void
    _on_stations_sort_column_changed()
    {
        int             col_id;
        Gtk::SortType   ty;

        if (_list_model->get_sort_column_id(col_id, ty)) {
            _prefs.set_stations_sort_column(col_id);
            _prefs.set_stations_sort_type(ty);
        }
    }

private:
    const SomaFMService                 _service;
    Player                              _player;
    Prefs                               _prefs;

    Glib::RefPtr<Gtk::Application>      _app;
    Glib::RefPtr<Gtk::Builder>          _builder;

A src/prefs.hpp => src/prefs.hpp +37 -0
@@ 0,0 1,37 @@
#pragma once

#include <iostream>
#include <gtkmm.h>

struct Prefs {
    Prefs() :
        _settings(Gio::Settings::create("com.zanneth.somafmgtk"))
    {}

    int
    stations_sort_column() const
    {
        return _settings->get_int("stations-sort-column");
    }

    void
    set_stations_sort_column(int c)
    {
        _settings->set_int("stations-sort-column", c);
    }

    Gtk::SortType
    stations_sort_type() const
    {
        return (Gtk::SortType)_settings->get_int("stations-sort-type");
    }

    void
    set_stations_sort_type(Gtk::SortType t)
    {
        _settings->set_int("stations-sort-type", (int)t);
    }

private:
    Glib::RefPtr<Gio::Settings> _settings;
};