summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Guthrie <cguthrie@mandriva.org>2010-04-22 00:04:56 +0100
committerColin Guthrie <cguthrie@mandriva.org>2010-04-22 00:04:56 +0100
commit94add670c46806ed821ff52bdbf56d229c3b455d (patch)
tree298972d3a8908442196d9553a83144675471a079
parent95e48d5c9e7d3fa3aa24d6e3b8326145712e33de (diff)
mainwindow: Save/restore window size
-rw-r--r--src/mainwindow.cc57
-rw-r--r--src/mainwindow.h1
2 files changed, 57 insertions, 1 deletions
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::RefPtr<Gnome::Glade:
showSourceType(SOURCE_NO_MONITOR),
eventRoleWidget(NULL),
canRenameDevices(false),
- m_connected(false) {
+ m_connected(false),
+ m_config_filename(NULL) {
x->get_widget("cardsVBox", cardsVBox);
x->get_widget("streamsVBox", streamsVBox);
@@ -109,6 +110,28 @@ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade:
sinkTypeComboBox->signal_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<uint32_t, char*>::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;
};