From 94add670c46806ed821ff52bdbf56d229c3b455d Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Thu, 22 Apr 2010 00:04:56 +0100 Subject: mainwindow: Save/restore window size --- src/mainwindow.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/mainwindow.h | 1 + 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cc b/src/mainwindow.cc index c84ca7f..c7008be 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -74,7 +74,8 @@ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtrget_widget("cardsVBox", cardsVBox); x->get_widget("streamsVBox", streamsVBox); @@ -109,6 +110,28 @@ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtrsignal_changed().connect(sigc::mem_fun(*this, &MainWindow::onSinkTypeComboBoxChanged)); sourceTypeComboBox->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::onSourceTypeComboBoxChanged)); + GKeyFile* config = g_key_file_new(); + g_assert(config); + GKeyFileFlags flags = (GKeyFileFlags)( G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS); + GError *err = NULL; + m_config_filename = g_strconcat(g_get_user_config_dir(), "/pavucontrol.ini", NULL); + + /* Load the GKeyFile from keyfile.conf or return. */ + if (g_key_file_load_from_file (config, m_config_filename, flags, &err)) { + int width = g_key_file_get_integer(config, "window", "width", NULL); + int height = g_key_file_get_integer(config, "window", "height", NULL); + + int default_width, default_height; + get_default_size(default_width, default_height); + if (width >= default_width && height >= default_height) + resize(width, height); + } else { + g_debug(_("Error reading config file %s: %s"), m_config_filename, err->message); + g_error_free(err); + } + g_key_file_free(config); + + /* Hide first and show when we're connected */ notebook->hide(); connectingLabel->show(); @@ -128,6 +151,38 @@ void MainWindow::on_realize() { } MainWindow::~MainWindow() { + GKeyFile* config = g_key_file_new(); + g_assert(config); + + int width, height; + get_size(width, height); + g_key_file_set_integer(config, "window", "width", width); + g_key_file_set_integer(config, "window", "height", height); + + gsize filelen; + GError *err = NULL; + gchar *filedata = g_key_file_to_data(config, &filelen, &err); + if (err) { + show_error(_("Error saving preferences")); + g_error_free(err); + goto finish; + } + + g_file_set_contents(m_config_filename, filedata, filelen, &err); + g_free(filedata); + if (err) { + gchar* msg = g_strconcat(_("Error writing config file %s"), m_config_filename, NULL); + show_error(msg); + g_free(msg); + g_error_free(err); + goto finish; + } + +finish: + + g_key_file_free(config); + g_free(m_config_filename); + while (!clientNames.empty()) { std::map::iterator i = clientNames.begin(); g_free(i->second); diff --git a/src/mainwindow.h b/src/mainwindow.h index 1d2f4b0..2b2dc5c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -101,6 +101,7 @@ protected: private: gboolean m_connected; + gchar* m_config_filename; }; -- cgit