~zanneth/somafm-gtk

e68b2b75a5335fa78cc4dfeacb03ed797918165a — Charles Magahern 1 year, 8 months ago b20c5dd
Save window settings to preferences
3 files changed, 54 insertions(+), 0 deletions(-)

M share/gsettings-schema.xml
M src/app.hpp
M src/prefs.hpp
M share/gsettings-schema.xml => share/gsettings-schema.xml +9 -0
@@ 7,5 7,14 @@
        <key name="stations-sort-type" type="i">
            <default>0</default>
        </key>
        <key name="app-window-width" type="i">
            <default>800</default>
        </key>
        <key name="app-window-height" type="i">
            <default>600</default>
        </key>
        <key name="app-window-is-maximized" type="b">
            <default>false</default>
        </key>
    </schema>
</schemalist>

M src/app.hpp => src/app.hpp +19 -0
@@ 91,6 91,15 @@ private:
        _window->set_icon(icon_pixbuf);
        _window->set_title("soma fm");

        // restore preferences
        int window_width, window_height;
        _prefs.window_size(window_width, window_height);
        _window->set_default_size(window_width, window_height);

        if (_prefs.window_is_maximized()) {
            _window->maximize();
        }

        // load placeholder artwork
        _tree_artwork_placeholder = _pixbuf_from_data(
            ::img_station_artwork_png,


@@ 154,6 163,7 @@ private:
    void
    _connect_signals()
    {
        _window->signal_size_allocate().connect(sigc::mem_fun(*this, &SomaFM::_on_window_size_allocate));
        _channels_tree_view->signal_row_activated().connect(sigc::mem_fun(*this, &SomaFM::_on_channel_row_activated));
        _play_pause_button->signal_clicked().connect(sigc::mem_fun(*this, &SomaFM::_on_play_pause_button_clicked));
        _volume_button->signal_value_changed().connect(sigc::mem_fun(*this, &SomaFM::_on_volume_value_changed));


@@ 360,6 370,15 @@ private:
    }

    void
    _on_window_size_allocate(const Gtk::Allocation &rect)
    {
        int w, h;
        _window->get_size(w, h);
        _prefs.set_window_size(w, h);
        _prefs.set_window_is_maximized(_window->is_maximized());
    }

    void
    _on_channel_row_activated(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *)
    {
        std::optional<Channel> selected_channel;

M src/prefs.hpp => src/prefs.hpp +26 -0
@@ 32,6 32,32 @@ struct Prefs {
        _settings->set_int("stations-sort-type", (int)t);
    }

    void
    window_size(int &w, int &h) const
    {
        w = _settings->get_int("app-window-width");
        h = _settings->get_int("app-window-height");
    }

    void
    set_window_size(int w, int h)
    {
        _settings->set_int("app-window-width", w);
        _settings->set_int("app-window-height", h);
    }

    bool
    window_is_maximized() const
    {
        return _settings->get_boolean("app-window-is-maximized");
    }

    void
    set_window_is_maximized(bool m)
    {
        _settings->set_boolean("app-window-is-maximized", m);
    }

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