[gnome-mud] Port to GSettings, removing all gconf usage
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mud] Port to GSettings, removing all gconf usage
- Date: Tue, 1 Jan 2019 14:26:12 +0000 (UTC)
commit 4327f2bb6a5c1c3e42ecb0ecc99bd173fe0e4733
Author: Mart Raudsepp <leio gentoo org>
Date: Tue Jan 1 16:08:16 2019 +0200
Port to GSettings, removing all gconf usage
Initial rough port away from gconf to gsettings. There are various
known issues and regressions around dynamic profile/mud/character
create/edit/delete and character icon support, but the basics seem
to work now. Many of the missing pieces will need rewrite/redesign
as part of further porting to gtk3 and refactoring anyway.
No migration of settings from GConf to GSettings is provided, sorry.
Introduces new MudCharacter and MudMud classes, for being able to
bind the settings multiple times - g_settings_bind only supports one
other object binding to the setting properties, so these extra
classes allow to do it multiple times and handle the concepts in
a more object oriented manner in further refactoring, instead of the
direct gconf read-write that was there before.
Triggers/aliases reading from configuration is lost, but the old code
only had reading from gconf - no actual writing out of them, as the
UI for the reworked triggers/aliases backend code is still missing.
The configuration reading will be re-added together with an actual
new UI for them.
Some of the code I touched is reindented to GObject coding style,
including space before opening parenthesis; it is planned to reindent
everything else later. This is the style that gnome-builder uses and
has various formatting helpers for.
Makefile.am | 13 -
configure.ac | 16 +-
data/Makefile.am | 6 +
data/org.gnome.MUD.gschema.xml | 162 +++
gnome-mud.schemas.in | 373 -------
po/POTFILES.in | 3 +-
src/Makefile.am | 4 +
src/gnome-mud.c | 26 +-
src/mud-character.c | 328 ++++++
src/mud-character.h | 52 +
src/mud-connection-view.c | 200 +---
src/mud-connection-view.h | 1 -
src/mud-connections.c | 2200 +++++++++++++++++-----------------------
src/mud-connections.h | 56 +-
src/mud-log.h | 2 -
src/mud-mud.c | 276 +++++
src/mud-mud.h | 46 +
src/mud-parse-alias.c | 16 +-
src/mud-parse-trigger.c | 9 +-
src/mud-profile-manager.c | 579 ++++++++---
src/mud-profile-manager.h | 33 +-
src/mud-profile.c | 795 +++++----------
src/mud-profile.h | 36 +-
src/mud-subwindow.c | 13 +-
src/mud-window-prefs.c | 153 +--
src/mud-window-profile.c | 151 ++-
src/mud-window-profile.h | 1 -
src/mud-window.c | 132 +--
src/mud-window.h | 2 +-
29 files changed, 2747 insertions(+), 2937 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 5c9a913..95ec2be 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,10 +3,6 @@ SUBDIRS = data doc po src ui
@INTLTOOL_SCHEMAS_RULE@
@INTLTOOL_DESKTOP_RULE@
-schemadir = $(GCONF_SCHEMA_FILE_DIR)
-schema_in_files = gnome-mud.schemas.in
-schema_DATA = $(schema_in_files:.schemas.in=.schemas)
-
Applicationsdir = $(datadir)/applications
Applications_in_files = gnome-mud.desktop.in
Applications_DATA = $(Applications_in_files:.desktop.in=.desktop)
@@ -57,13 +53,4 @@ MAINTAINERCLEANFILES = \
DISTCHECK_CONFIGURE_FLAGS = --disable-schemas-install --disable-scrollkeeper
-install-data-local: $(schema_DATA)
-if GCONF_SCHEMAS_INSTALL
- if test -z "$(DESTDIR)"; then \
- for p in $^ ; do \
- GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL)
--makefile-install-rule $$p 2>&1 > /dev/null; \
- done \
- fi
-endif
-
-include $(top_srcdir)/git.mk
diff --git a/configure.ac b/configure.ac
index 054f424..41bdca5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,14 +46,6 @@ GETTEXT_PACKAGE=gnome-mud
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE(GETTEXT_PACKAGE, "gnome-mud", [Gettext domain name])
-dnl gconf tests
-AM_GCONF_SOURCE_2
-AC_PATH_PROG(GCONFTOOL, gconftool-2)
-
-if test x"$GCONFTOOL" = xno; then
- AC_MSG_ERROR([gconftool-2 executable not found in your path - should be installed with GConf])
-fi
-
dnl Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL
@@ -68,15 +60,17 @@ AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS(strings.h)
+dnl gsettings
+GLIB_GSETTINGS
+
dnl pkg-config dep checks
GTK_REQUIRED=2.24.0
-LIBGLIB_REQUIRED=2.36
+LIBGLIB_REQUIRED=2.48
VTE_REQUIRED=0.11.00
PCRE_REQUIRED=6.0.0
-GCONF_REQUIRED=0.20
GSTREAMER_REQUIRED=1.0
-PKG_CHECK_MODULES(GMUD, gtk+-2.0 >= $GTK_REQUIRED vte >= $VTE_REQUIRED libpcre >= $PCRE_REQUIRED gio-2.0 >=
$LIBGLIB_REQUIRED gconf-2.0 >= $GCONF_REQUIRED)
+PKG_CHECK_MODULES(GMUD, gtk+-2.0 >= $GTK_REQUIRED vte >= $VTE_REQUIRED libpcre >= $PCRE_REQUIRED gio-2.0 >=
$LIBGLIB_REQUIRED)
AC_SUBST(GMUD_CFLAGS)
AC_SUBST(GMUD_LIBS)
diff --git a/data/Makefile.am b/data/Makefile.am
index 4b82ae3..8fc2f87 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,3 +1,9 @@
SUBDIRS = icons
+gsettings_SCHEMAS = \
+ org.gnome.MUD.gschema.xml \
+ $(NULL)
+
+@GSETTINGS_RULES@
+
-include $(top_srcdir)/git.mk
diff --git a/data/org.gnome.MUD.gschema.xml b/data/org.gnome.MUD.gschema.xml
new file mode 100644
index 0000000..a5b3b30
--- /dev/null
+++ b/data/org.gnome.MUD.gschema.xml
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist gettext-domain="gnome-mud">
+ <schema path="/org/gnome/MUD/" id="org.gnome.MUD">
+ <key name="schema-version" type="u">
+ <default>1</default>
+ <summary>Settings schema version</summary>
+ </key>
+ <key name="profile-list" type="as">
+ <default>['profile-0']</default>
+ <summary>List of available profiles</summary>
+ </key>
+ <key name="default-profile" type="s">
+ <default>'profile-0'</default>
+ <summary>Default profile</summary>
+ </key>
+ <key name="mud-list" type="as">
+ <default>[]</default>
+ <summary>List of available MUDs</summary>
+ </key>
+ <key name="character-list" type="as">
+ <default>[]</default>
+ <summary>List of available characters</summary>
+ </key>
+ </schema>
+
+ <schema id="org.gnome.MUD.Profile">
+ <!-- UI -->
+ <key name="visible-name" type="s">
+ <default>'Unnamed'</default>
+ <summary>Human-readable name of the profile</summary>
+ </key>
+ <key name="font" type="s">
+ <default>'monospace 12'</default>
+ <summary>A Pango font name and size</summary>
+ </key>
+ <!-- TODO: Add and implement use-system-font boolean setting "Whether to use the system monospace font"
-->
+ <key name="foreground-color" type="s">
+ <default>'#FFFFDD'</default>
+ <summary>Default color of the text</summary>
+ <description>Default color of the text, as a color specification (can be HTML-style hex digits, or a
color name such as “red”).</description>
+ </key>
+ <key name="background-color" type="s">
+ <default>'#000000'</default>
+ <summary>Default color of the background</summary>
+ <description>Default color of the background, as a color specification (can be HTML-style hex digits,
or a color name such as “red”).</description>
+ </key>
+ <key name="palette" type="as">
+ <!-- TODO: Default currently matches "Linux console" - maybe switch to Tango?; add support for builtin
color palettes -->
+ <default>['#000000',
+ '#AA0000',
+ '#00AA00',
+ '#AA5500',
+ '#0000AA',
+ '#AA00AA',
+ '#00AAAA',
+ '#AAAAAA',
+ '#555555',
+ '#FF5555',
+ '#55FF55',
+ '#FFFF55',
+ '#5555FF',
+ '#FF55FF',
+ '#55FFFF',
+ '#FFFFFF']</default>
+ <summary>Color palette</summary>
+ <description>List of the 16 colors that MUDs can use with indexed ANSI color codes.</description>
+ </key>
+ <key name="scrollback-lines" type="u">
+ <default>500</default><!-- TODO: Increase default? -->
+ <summary>Number of lines to keep in scrollback</summary>
+ <description>Number of scrollback lines to keep around. You can scroll back in the terminal by this
number of lines; lines that don’t fit in the scrollback are discarded.</description>
+ <!-- TODO: If “scrollback-unlimited” is true, this value is ignored. --><!-- TODO: Maybe use "mu" for
this? -->
+ </key>
+ <!-- FUNCTIONALITY -->
+ <key name="encoding" type="s">
+ <default>'UTF-8'</default><!-- TODO: Settings provides an encoding list, so we could have an enum type
or choice list, instead of bare string -->
+ <summary>The encoding for the terminal widget.</summary>
+ </key>
+ <key name="remote-encoding" type="b">
+ <default>false</default><!-- TODO: Change to true? -->
+ <summary>Remote encoding</summary>
+ <description>Use Remote Encoding negotiation.</description>
+ </key>
+ <key name="remote-download" type="b">
+ <default>true</default>
+ <summary>Remote download</summary>
+ <description>Enable sound file downloading on MSP enabled MUDs.</description>
+ </key>
+ <key name="command-divider" type="s">
+ <default>';'</default>
+ <summary>Command divider</summary>
+ <description>A character that is used to split commands in a string like “w;w;w;l”, which will be sent
to the MUD as 4 separate commands.</description>
+ </key>
+ <key name="echo" type="b">
+ <default>true</default>
+ <summary>Whether to echo sent text to the connection</summary>
+ <description>If enabled, all the text typed in will be echoed in the terminal, making it easier to
control what is sent.</description>
+ </key>
+ <key name="keep-text" type="b">
+ <default>false</default>
+ <summary>Whether to keep text sent to the connection</summary>
+ <description>If enabled, the text that is sent to the connection will be left as a selection in the
entry box. Otherwise, the text entry box will be cleared after each text input.</description>
+ </key>
+ <key name="scroll-on-output" type="b">
+ <default>false</default>
+ <summary>Whether to scroll to the bottom when there’s new output</summary>
+ <description>If true, whenever there’s new output the terminal will scroll to the bottom.</description>
+ </key>
+ <key name="use-proxy" type="b">
+ <default>false</default>
+ <summary>Use proxy</summary>
+ <description>Whether to use a proxy server to connect to the MUD.</description>
+ </key>
+ <key name="proxy-socks-version" type="s">
+ <choices>
+ <choice value="4"/>
+ <choice value="5"/>
+ </choices>
+ <default>'5'</default>
+ <summary>Proxy version</summary>
+ <description>The SOCKS version to be used.</description>
+ </key>
+ <key name="proxy-hostname" type="s">
+ <default>'127.0.0.1'</default>
+ <summary>Proxy server hostname</summary>
+ <description>The hostname for the SOCKS proxy server.</description>
+ </key>
+ </schema>
+
+ <schema id="org.gnome.MUD.Mud">
+ <key name="name" type="s">
+ <default>''</default>
+ <summary>Visible name of the MUD.</summary>
+ </key>
+ <key name="hostname" type="s">
+ <default>''</default>
+ </key>
+ <key name="port" type="u">
+ <default>23</default>
+ </key>
+ </schema>
+
+ <schema id="org.gnome.MUD.Character">
+ <key name="profile" type="s">
+ <default>''</default>
+ <summary>Profile ID</summary>
+ </key>
+ <key name="mud" type="s">
+ <default>''</default>
+ <summary>MUD ID</summary>
+ </key>
+ <key name="name" type="s">
+ <default>''</default>
+ <summary>Name of the character.</summary>
+ </key>
+ <key name="connect-string" type="s">
+ <default>''</default>
+ <summary>Connect string</summary>
+ <description>Commands to send to MUD upon establishing connection.</description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b6397ef..8c079a0 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,9 +2,8 @@
# List of source files containing translatable strings.
# Please keep this file sorted alphabetically.
gnome-mud.desktop.in
-gnome-mud.schemas.in
+[type: gettext/gsettings]data/org.gnome.MUD.gschema.xml
src/debug-logger.c
-src/gnome-mud.c
src/mud-connections.c
src/mud-connection-view.c
src/mud-log.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 808440e..2a8a60c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,6 +36,8 @@ gnome_mud_SOURCES = \
gnome-mud-builtins.c \
gnome-mud-builtins.h \
gnome-mud-icons.h \
+ mud-character.c \
+ mud-character.h \
mud-connection-view.c \
mud-connections.c \
mud-connections.h \
@@ -46,6 +48,8 @@ gnome_mud_SOURCES = \
mud-line-buffer.h \
mud-log.c \
mud-log.h \
+ mud-mud.c \
+ mud-mud.h \
mud-parse-alias.c \
mud-parse-alias.h \
mud-parse-base.c \
diff --git a/src/gnome-mud.c b/src/gnome-mud.c
index 308f258..cfd0dc9 100644
--- a/src/gnome-mud.c
+++ b/src/gnome-mud.c
@@ -22,8 +22,8 @@
# include "config.h"
#endif
-#include <gconf/gconf-client.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <sys/stat.h>
@@ -43,10 +43,9 @@
gint
main (gint argc, char *argv[])
{
- GConfClient *client;
DebugLogger *logger;
- GError *err = NULL;
GString *dir;
+ GSettings *global_settings;
#ifdef ENABLE_NLS
/* Initialize internationalization */
@@ -55,13 +54,11 @@ main (gint argc, char *argv[])
textdomain(GETTEXT_PACKAGE);
#endif
- /* Initialize the GConf library */
- if (!gconf_init(argc, argv, &err))
- {
- g_error(_("Failed to init GConf: %s"), err->message);
- g_error_free(err);
- return 1;
- }
+ /* Set up schema version */
+ global_settings = g_settings_new("org.gnome.MUD");
+ /* Add any future migration triggers here */
+ g_settings_set_uint(global_settings, "schema-version", 1);
+ g_object_unref(global_settings);
gtk_init(&argc, &argv);
@@ -70,17 +67,13 @@ main (gint argc, char *argv[])
gst_init(&argc, &argv);
#endif
- client = gconf_client_get_default();
- gconf_client_add_dir(client, "/apps/gnome-mud",
- GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
-
dir = g_string_new(NULL);
g_string_printf(dir,
"%s%cgnome-mud%clogs",
g_get_user_data_dir(),
G_DIR_SEPARATOR,
G_DIR_SEPARATOR);
- g_mkdir_with_parents(dir->str, 0755);
+ g_mkdir_with_parents(dir->str, 0755);
g_string_free(dir, TRUE);
dir = g_string_new(NULL);
@@ -115,10 +108,7 @@ main (gint argc, char *argv[])
gtk_main();
- gconf_client_suggest_sync(client, &err);
-
g_object_unref(logger);
- g_object_unref(client);
return 0;
}
diff --git a/src/mud-character.c b/src/mud-character.c
new file mode 100644
index 0000000..cd2f930
--- /dev/null
+++ b/src/mud-character.c
@@ -0,0 +1,328 @@
+/* mud-character.c
+ *
+ * Copyright 2018 Mart Raudsepp <leio gentoo org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "mud-character.h"
+#include "mud-profile.h"
+#include "mud-mud.h"
+
+#include <gio/gio.h>
+
+typedef struct _MudProfile MudProfile;
+typedef struct _MudMud MudMud;
+
+struct _MudCharacter
+{
+ GObject parent_instance;
+
+ gchar *id;
+ MudProfile *profile;
+ MudMud *mud;
+ gchar *name;
+ gchar *connect_string;
+ GSettings *settings;
+};
+
+G_DEFINE_TYPE (MudCharacter, mud_character, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_ID,
+ PROP_PROFILE,
+ PROP_MUD,
+ PROP_NAME,
+ PROP_CONNECT_STRING,
+ N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+MudCharacter *
+mud_character_new (const gchar *id, const MudProfile *profile, const MudMud *mud)
+{
+ return g_object_new (MUD_TYPE_CHARACTER, "id", id, "profile", profile, "mud", mud, NULL);
+}
+
+const gchar *
+mud_character_get_id (MudCharacter *self)
+{
+ g_return_val_if_fail (MUD_IS_CHARACTER (self), NULL);
+
+ return self->id;
+}
+
+const gchar *
+mud_character_get_name (MudCharacter *self)
+{
+ g_return_val_if_fail (MUD_IS_CHARACTER (self), NULL);
+
+ return self->name;
+}
+
+void
+mud_character_set_name (MudCharacter *self, const gchar *name)
+{
+ g_return_if_fail (MUD_IS_CHARACTER (self));
+
+ if (g_strcmp0 (self->name, name) != 0)
+ {
+ g_free (self->name);
+ self->name = g_strdup (name);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NAME]);
+ }
+}
+
+const gchar *
+mud_character_get_connect_string (MudCharacter *self)
+{
+ g_return_val_if_fail (MUD_IS_CHARACTER (self), NULL);
+
+ return self->connect_string;
+}
+
+void
+mud_character_set_connect_string (MudCharacter *self, const gchar *connect_string)
+{
+ g_return_if_fail (MUD_IS_CHARACTER (self));
+
+ if (g_strcmp0 (self->connect_string, connect_string) != 0)
+ {
+ g_free (self->connect_string);
+ self->connect_string = g_strdup (connect_string);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CONNECT_STRING]);
+ }
+}
+
+MudProfile *
+mud_character_get_profile (MudCharacter *self)
+{
+ g_return_val_if_fail (MUD_IS_CHARACTER (self), NULL);
+
+ return self->profile;
+}
+
+MudMud *
+mud_character_get_mud (MudCharacter *self)
+{
+ g_return_val_if_fail (MUD_IS_CHARACTER (self), NULL);
+
+ return self->mud;
+}
+
+const gchar *
+mud_character_get_icon (MudCharacter *self)
+{
+ g_return_val_if_fail (MUD_IS_CHARACTER (self), NULL);
+
+ /* TODO: Implement */
+ return "gnome-mud";
+}
+
+void
+mud_character_set_icon (MudCharacter *self,
+ const gchar *icon_name)
+{
+ g_return_if_fail (MUD_IS_CHARACTER (self));
+ /* TODO: Implement */
+}
+
+int
+mud_character_compare (const MudCharacter *char1, const MudCharacter *char2)
+{
+ return g_strcmp0 (char1->id, char2->id);
+}
+
+static GVariant *
+_set_profile_id_mapping (const GValue *value,
+ const GVariantType *expected_type,
+ gpointer user_data)
+{
+ GVariant *ret;
+ guint64 id = g_value_get_uint64 (value);
+ gchar *profile_id = g_strdup_printf ("profile-%" G_GUINT64_FORMAT, id);
+ ret = g_variant_new_string (profile_id);
+ g_free (profile_id);
+ return ret;
+}
+
+static void
+mud_character_constructed (GObject *object)
+{
+ gchar *character_path;
+ MudCharacter *self = (MudCharacter *)object;
+
+ G_OBJECT_CLASS (mud_character_parent_class)->constructed (object);
+
+ /* TODO: Change ID property to default to G_MAXUINT64 and figure out a new ID to use here, instead of
caller having to do it */
+
+ character_path = g_strdup_printf("/org/gnome/MUD/Characters/%s/", self->id);
+ self->settings = g_settings_new_with_path("org.gnome.MUD.Character", character_path);
+ /* TODO: Reaction to MUD/Profile changes; but maybe this binding to other objects 'id' is enough? */
+ /* FIXME: For now just setting mud/profile names for the benefit of new freshly created characters; think
this through more and maybe do elsewhere, as during load we'd get that value already too and figure it out in
manager */
+ g_settings_bind_with_mapping (self->settings, "profile",
+ self->profile, "id",
+ G_SETTINGS_BIND_SET | G_SETTINGS_BIND_NO_SENSITIVITY,
+ NULL, _set_profile_id_mapping, /* TODO: Get rid of the mapping once we have
converted profile over to use full name instead of integer ID too */
+ NULL, NULL);
+ g_settings_bind (self->settings, "mud",
+ self->mud, "id",
+ G_SETTINGS_BIND_SET | G_SETTINGS_BIND_NO_SENSITIVITY);
+ g_settings_bind (self->settings, "name",
+ self, "name",
+ G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_NO_SENSITIVITY);
+ g_settings_bind (self->settings, "connect-string",
+ self, "connect-string",
+ G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_NO_SENSITIVITY);
+ g_free (character_path);
+}
+
+static void
+mud_character_finalize (GObject *object)
+{
+ MudCharacter *self = (MudCharacter *)object;
+
+ g_object_unref(self->settings); /* TODO: Shouldn't this be done in dispose? */
+
+ G_OBJECT_CLASS (mud_character_parent_class)->finalize (object);
+}
+
+static void
+mud_character_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MudCharacter *self = MUD_CHARACTER (object);
+
+ switch (prop_id)
+ {
+ case PROP_ID:
+ g_value_set_string (value, self->id);
+ break;
+
+ case PROP_PROFILE:
+ g_value_take_object (value, self->profile);
+ break;
+
+ case PROP_MUD:
+ g_value_take_object (value, G_OBJECT (mud_character_get_mud(self)));
+ break;
+
+ case PROP_NAME:
+ g_value_set_string (value, mud_character_get_name (self));
+ break;
+
+ case PROP_CONNECT_STRING:
+ g_value_set_string (value, mud_character_get_connect_string (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+mud_character_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MudCharacter *self = MUD_CHARACTER (object);
+
+ switch (prop_id)
+ {
+ case PROP_ID: /* construct-only */
+ self->id = g_strdup (g_value_get_string (value));
+ break;
+
+ case PROP_PROFILE:
+ self->profile = g_value_get_object (value); /* TODO: setter with notify (once we can change profile
again) */
+ break;
+
+ case PROP_MUD: /* construct-only */
+ self->mud = g_value_get_object (value);
+ break;
+
+ case PROP_NAME:
+ mud_character_set_name (self, g_value_get_string (value));
+ break;
+
+ case PROP_CONNECT_STRING:
+ mud_character_set_connect_string (self, g_value_get_string (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+mud_character_class_init (MudCharacterClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = mud_character_constructed;
+ object_class->finalize = mud_character_finalize;
+ object_class->get_property = mud_character_get_property;
+ object_class->set_property = mud_character_set_property;
+
+ /* Create and Install Properties */
+ properties [PROP_ID] =
+ g_param_spec_string ("id",
+ "ID",
+ "The ID of the MUD character.",
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_PROFILE] =
+ g_param_spec_object ("profile",
+ "Profile",
+ "Profile used by this MUD character.",
+ MUD_TYPE_PROFILE,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS)); /* TODO: Make changing of profile possible again */
+ properties [PROP_MUD] =
+ g_param_spec_object ("mud",
+ "MUD",
+ "The MUD this character is for.",
+ MUD_TYPE_MUD,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+ properties [PROP_NAME] =
+ g_param_spec_string ("name",
+ "Name",
+ "The visible name of the MUD character.",
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); /* TODO:
Debug how things differ with EXPLICIT_NOTIFY vs not and notify_by_pspec call existing or not */
+ properties [PROP_CONNECT_STRING] =
+ g_param_spec_string ("connect-string",
+ "Connect String",
+ "Commands to send to MUD upon establishing connection.",
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); /* TODO:
Debug how things differ with EXPLICIT_NOTIFY vs not and notify_by_pspec call existing or not */
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+mud_character_init (MudCharacter *self)
+{
+}
diff --git a/src/mud-character.h b/src/mud-character.h
new file mode 100644
index 0000000..5384961
--- /dev/null
+++ b/src/mud-character.h
@@ -0,0 +1,52 @@
+/* mud-character.h
+ *
+ * Copyright 2018 Mart Raudsepp <leio gentoo org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct _MudProfile MudProfile;
+typedef struct _MudMud MudMud;
+
+#define MUD_TYPE_CHARACTER (mud_character_get_type())
+
+G_DECLARE_FINAL_TYPE (MudCharacter, mud_character, MUD, CHARACTER, GObject);
+
+MudCharacter *mud_character_new (const char *id,
+ const MudProfile *profile,
+ const MudMud *mud);
+const gchar *mud_character_get_id (MudCharacter *self);
+const gchar *mud_character_get_name (MudCharacter *self);
+void mud_character_set_name (MudCharacter *self,
+ const gchar *name);
+const gchar *mud_character_get_connect_string (MudCharacter *self);
+void mud_character_set_connect_string (MudCharacter *self,
+ const gchar *connect_string);
+MudProfile *mud_character_get_profile (MudCharacter *self);
+MudMud *mud_character_get_mud (MudCharacter *self);
+const gchar *mud_character_get_icon (MudCharacter *self);
+void mud_character_set_icon (MudCharacter *self,
+ const gchar *icon_name);
+int mud_character_compare (const MudCharacter *char1,
+ const MudCharacter *char2);
+
+G_END_DECLS
diff --git a/src/mud-connection-view.c b/src/mud-connection-view.c
index 39ff5dd..5831e70 100644
--- a/src/mud-connection-view.c
+++ b/src/mud-connection-view.c
@@ -1,9 +1,11 @@
-/* GNOME-Mud - A simple Mud CLient
- * Copyright (C) 1998-2006 Robin Ericsson <lobbin localhost nu>
+/* mud-connection-view.c
*
- * This program is free software; you can redistribute it and/or modify
+ * Copyright 1998-2006 Robin Ericsson <lobbin localhost nu>
+ * Copyright 2018 Mart Raudsepp <leio gentoo org>
+ *
+ * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@@ -12,15 +14,15 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include <gconf/gconf-client.h>
#include <glib-object.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
@@ -91,7 +93,6 @@ enum
PROP_PARSE_BASE,
PROP_TELNET,
PROP_WINDOW,
- PROP_PROFILE_NAME,
PROP_LOGGING,
PROP_TERMINAL,
PROP_VBOX
@@ -235,14 +236,6 @@ mud_connection_view_class_init (MudConnectionViewClass *klass)
MUD_TYPE_WINDOW,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property(object_class,
- PROP_PROFILE_NAME,
- g_param_spec_string("profile-name",
- "profile name",
- "the name of the current profile",
- NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
// Setable properties
g_object_class_install_property(object_class,
PROP_REMOTE_ENCODE,
@@ -322,7 +315,7 @@ mud_connection_view_class_init (MudConnectionViewClass *klass)
"profile",
"the mud profile object",
MUD_TYPE_PROFILE,
- G_PARAM_READABLE));
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); /* TODO: Make it changeable again */
g_object_class_install_property(object_class,
PROP_TELNET,
@@ -450,32 +443,15 @@ mud_connection_data_ready_cb(MudConnection *conn, MudConnectionView *self)
static gchar *
mud_connection_view_create_proxy_uri(const MudConnectionView *self)
{
- GConfClient *client;
gchar *uri = NULL;
gchar *host, *str_version;
guint version;
- gchar key[2048];
- gchar extra_path[512] = "";
-
- if (strcmp(self->profile_name, "Default") != 0)
- {
- g_snprintf(extra_path, sizeof(extra_path), "profiles/%s/", self->profile_name);
- }
- client = gconf_client_get_default();
-
- g_snprintf(key, sizeof(key), "/apps/gnome-mud/%s%s", extra_path, "functionality/use_proxy");
- if(!gconf_client_get_bool(client, key, NULL))
- {
- g_object_unref(client);
+ if (!g_settings_get_boolean(self->profile->settings, "use-proxy"))
return NULL;
- }
-
- g_snprintf(key, sizeof(key), "/apps/gnome-mud/%s%s", extra_path, "functionality/proxy_hostname");
- host = gconf_client_get_string(client, key, NULL);
- g_snprintf(key, sizeof(key), "/apps/gnome-mud/%s%s", extra_path, "functionality/proxy_version");
- str_version = gconf_client_get_string(client, key, NULL);
+ host = g_settings_get_string(self->profile->settings, "proxy-hostname");
+ str_version = g_settings_get_string(self->profile->settings, "proxy-socks-version");
if(strcmp(str_version, "4") == 0)
version = 4;
else
@@ -483,7 +459,6 @@ mud_connection_view_create_proxy_uri(const MudConnectionView *self)
uri = g_strdup_printf("socks%d://%s", version, host);
- g_object_unref(client);
g_free(host);
g_free(str_version);
@@ -542,7 +517,7 @@ mud_connection_view_constructor (GType gtype,
/* Create main VBox, VTE, and scrollbar */
box = gtk_vbox_new(FALSE, 0);
self->ui_vbox = GTK_VBOX(box);
- self->terminal = VTE_TERMINAL(vte_terminal_new());
+ self->terminal = VTE_TERMINAL(vte_terminal_new()); /* TODO: Set up autowrap, so things rewrap on resize
(this will be the default once we upgrade VTE to some gtk3 version); make sure none of our own tracking of
things gets messed up from that, though */
self->priv->scrollbar = gtk_vscrollbar_new(NULL);
term_box = gtk_hbox_new(FALSE, 0);
@@ -624,9 +599,8 @@ mud_connection_view_constructor (GType gtype,
"tray", &tray,
NULL);
- profile =
- mud_profile_manager_get_profile_by_name(self->window->profile_manager,
- self->profile_name);
+ profile = self->profile; /* FIXME: Gross workaround to get around set_profile check and early bail-out
after construct_only restructuring; hopefully this can all be cleaned up together with move away from
constructor to constructed override */
+ self->profile = NULL;
mud_connection_view_set_profile(self, profile);
self->tray = tray;
@@ -738,8 +712,10 @@ mud_connection_view_finalize (GObject *object)
g_object_unref(connection_view->parse);
- if(connection_view->profile)
- g_object_unref(connection_view->profile);
+ /* TODO: We don't hold a ref right now - we should, or keep a weakref?
+ * if(connection_view->profile)
+ * g_object_unref(connection_view->profile);
+ */
g_object_unref(connection_view->priv->line_buffer);
@@ -871,6 +847,10 @@ mud_connection_view_set_property(GObject *object,
g_free(new_string);
break;
+ case PROP_PROFILE:
+ self->profile = g_value_get_object (value);
+ break;
+
case PROP_WINDOW:
self->window = MUD_WINDOW(g_value_get_object(value));
break;
@@ -879,23 +859,6 @@ mud_connection_view_set_property(GObject *object,
self->tray = MUD_TRAY(g_value_get_object(value));
break;
- case PROP_PROFILE_NAME:
- new_string = g_value_dup_string(value);
-
- if(!self->profile_name)
- self->profile_name =
- (new_string) ? g_strdup(new_string) : NULL;
- else if( strcmp(self->profile_name, new_string) != 0)
- {
- if(self->profile_name)
- g_free(self->profile_name);
- self->profile_name =
- (new_string) ? g_strdup(new_string) : NULL;
- }
-
- g_free(new_string);
- break;
-
case PROP_LOGGING:
new_boolean = g_value_get_boolean(value);
@@ -989,10 +952,6 @@ mud_connection_view_get_property(GObject *object,
g_value_set_boolean(value, self->logging);
break;
- case PROP_PROFILE_NAME:
- g_value_set_string(value, self->profile_name);
- break;
-
case PROP_TERMINAL:
g_value_take_object(value, self->terminal);
break;
@@ -1076,8 +1035,8 @@ mud_connection_view_popup(MudConnectionView *view, GdkEventButton *event)
GtkWidget *im_menu;
GtkWidget *menu_item;
GtkWidget *profile_menu;
- const GSList *profiles;
- const GSList *profile;
+ GSequence *profiles;
+ GSequenceIter *iter;
GSList *group;
if (view->priv->popup_menu)
@@ -1117,18 +1076,18 @@ mud_connection_view_popup(MudConnectionView *view, GdkEventButton *event)
group = NULL;
profiles = mud_profile_manager_get_profiles(view->window->profile_manager);
- profile = profiles;
- while (profile != NULL)
- {
- MudProfile *prof;
- prof = profile->data;
+ for (iter = g_sequence_get_begin_iter (profiles);
+ !g_sequence_iter_is_end (iter);
+ iter = g_sequence_iter_next (iter))
+ {
+ MudProfile *prof = g_sequence_get (iter);
/* Profiles can go away while the menu is up. */
- g_object_ref(G_OBJECT(prof));
+ g_object_ref(G_OBJECT(prof)); /* TODO: Review reference handling (weakref?) */
menu_item = gtk_radio_menu_item_new_with_label(group,
- prof->name);
+ prof->visible_name);
group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menu_item));
gtk_menu_shell_append(GTK_MENU_SHELL(profile_menu), menu_item);
@@ -1143,7 +1102,6 @@ mud_connection_view_popup(MudConnectionView *view, GdkEventButton *event)
"profile",
prof,
(GDestroyNotify) g_object_unref);
- profile = g_slist_next(profile);
}
menu_item = gtk_separator_menu_item_new();
@@ -1330,33 +1288,8 @@ static GtkWidget*
append_stock_menuitem(GtkWidget *menu, const gchar *text, GCallback callback, gpointer data)
{
GtkWidget *menu_item;
- GtkWidget *image;
- GConfClient *client;
- GError *error;
- gboolean use_image;
menu_item = gtk_image_menu_item_new_from_stock(text, NULL);
- image = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(menu_item));
-
- client = gconf_client_get_default();
- error = NULL;
-
- use_image = gconf_client_get_bool(client,
- "/desktop/gnome/interface/menus_have_icons",
- &error);
- if (error)
- {
- g_printerr(_("There was an error loading config value for whether to use image in menus. (%s)\n"),
- error->message);
- g_error_free(error);
- }
- else
- {
- if (use_image)
- gtk_widget_show(image);
- else
- gtk_widget_hide(image);
- }
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
@@ -1365,8 +1298,6 @@ append_stock_menuitem(GtkWidget *menu, const gchar *text, GCallback callback, gp
"activate",
callback, data);
- g_object_unref(client);
-
return menu_item;
}
@@ -1705,37 +1636,18 @@ mud_connection_view_add_text(MudConnectionView *view, gchar *message, enum MudCo
{
gchar *encoding, *text;
const gchar *local_codeset;
- gchar *profile_name;
- GConfClient *client;
gboolean remote;
gsize bytes_read, bytes_written;
GError *error = NULL;
- gchar key[2048];
- gchar extra_path[512] = "";
-
g_return_if_fail(IS_MUD_CONNECTION_VIEW(view));
- client = gconf_client_get_default();
-
- g_snprintf(key, 2048, "/apps/gnome-mud/%s%s", extra_path, "functionality/remote_encoding");
- remote = gconf_client_get_bool(client, key, NULL);
+ remote = g_settings_get_boolean(view->profile->settings, "remote-encoding");
if(view->remote_encode && remote)
encoding = g_strdup(view->remote_encoding);
else
- {
- g_object_get(view->profile,
- "name", &profile_name, NULL);
-
- if (!g_str_equal(profile_name, "Default"))
- g_snprintf(extra_path, 512, "profiles/%s/", profile_name);
-
- g_snprintf(key, 2048, "/apps/gnome-mud/%s%s", extra_path, "functionality/encoding");
- encoding = gconf_client_get_string(client, key, NULL);
-
- g_free(profile_name);
- }
+ encoding = g_settings_get_string(view->profile->settings, "encoding");
g_get_charset(&local_codeset);
@@ -1779,8 +1691,6 @@ mud_connection_view_add_text(MudConnectionView *view, gchar *message, enum MudCo
if(text != NULL)
g_free(text);
-
- g_object_unref(client);
}
void
@@ -1836,19 +1746,15 @@ mud_connection_view_reconnect(MudConnectionView *view)
void
mud_connection_view_send(MudConnectionView *view, const gchar *data)
{
- GConfClient *client;
MudTelnetZmp *zmp_handler;
GList *commands, *command;
const gchar *local_codeset;
gboolean remote, zmp_enabled;
gsize bytes_read, bytes_written;
- gchar *encoding, *conv_text, *profile_name;
-
- gchar key[2048];
- gchar extra_path[512] = "";
+ gchar *encoding, *conv_text;
GError *error = NULL;
-
+
g_return_if_fail(IS_MUD_CONNECTION_VIEW(view));
if(mud_connection_is_connected(view->conn))
@@ -1877,25 +1783,12 @@ mud_connection_view_send(MudConnectionView *view, const gchar *data)
view->priv->current_history_index = -1;
- client = gconf_client_get_default();
-
- g_snprintf(key, 2048, "/apps/gnome-mud/%s%s", extra_path, "functionality/remote_encoding");
- remote = gconf_client_get_bool(client, key, NULL);
+ remote = g_settings_get_boolean(view->profile->settings, "remote-encoding");
if(view->remote_encode && remote)
encoding = view->remote_encoding;
else
- {
- g_object_get(view->profile, "name", &profile_name, NULL);
-
- if (!g_str_equal(profile_name, "Default"))
- g_snprintf(extra_path, 512, "profiles/%s/", profile_name);
-
- g_snprintf(key, 2048, "/apps/gnome-mud/%s%s", extra_path, "functionality/encoding");
- encoding = gconf_client_get_string(client, key, NULL);
-
- g_free(profile_name);
- }
+ encoding = g_settings_get_string(view->profile->settings, "encoding"); /* FIXME: This appears to
leak */
g_get_charset(&local_codeset);
@@ -1984,7 +1877,6 @@ mud_connection_view_send(MudConnectionView *view, const gchar *data)
}
g_list_free(commands);
- g_object_unref(client);
}
}
@@ -2019,7 +1911,7 @@ mud_connection_view_set_profile(MudConnectionView *view, MudProfile *profile)
{
g_return_if_fail(IS_MUD_CONNECTION_VIEW(view));
- if(profile == view->profile)
+ if(profile == view->profile) /* TODO: This bails out in case we have profile set from CONSTRUCT_ONLY,
but we do want the rest done after terminal widget is ready... */
return;
if (view->profile)
@@ -2110,18 +2002,11 @@ mud_connection_view_queue_download(MudConnectionView *view, gchar *url, gchar *f
{
MudMSPDownloadItem *item;
guint i, size;
- GConfClient *client;
gboolean download;
- gchar key[2048];
- gchar extra_path[512] = "";
-
g_return_if_fail(IS_MUD_CONNECTION_VIEW(view));
- client = gconf_client_get_default();
-
- g_snprintf(key, 2048, "/apps/gnome-mud/%s%s", extra_path, "functionality/remote_download");
- download = gconf_client_get_bool(client, key, NULL);
+ download = g_settings_get_boolean(view->profile->settings, "remote-download");
if(download)
{
@@ -2133,7 +2018,6 @@ mud_connection_view_queue_download(MudConnectionView *view, gchar *url, gchar *f
if(strcmp(item->url, url) == 0)
{
- g_object_unref(client);
return;
}
}
@@ -2151,8 +2035,6 @@ mud_connection_view_queue_download(MudConnectionView *view, gchar *url, gchar *f
if(view->priv->downloading == FALSE)
mud_connection_view_start_download(view);
}
-
- g_object_unref(client);
}
static void
diff --git a/src/mud-connection-view.h b/src/mud-connection-view.h
index 49457aa..11b50eb 100644
--- a/src/mud-connection-view.h
+++ b/src/mud-connection-view.h
@@ -55,7 +55,6 @@ struct _MudConnectionView
gchar *connect_string;
gchar *remote_encoding;
- gchar *profile_name;
gint port;
gchar *mud_name;
diff --git a/src/mud-connections.c b/src/mud-connections.c
index 5cb422b..2f50a59 100644
--- a/src/mud-connections.c
+++ b/src/mud-connections.c
@@ -1,10 +1,11 @@
-/* GNOME-Mud - A simple Mud Client
- * mud-connections.c
- * Copyright (C) 2008-2009 Les Harris <lharris gnome org>
+/* mud-connections.c
*
- * This program is free software; you can redistribute it and/or modify
+ * Copyright 2008-2009 Les Harris <lharris gnome org>
+ * Copyright 2018 Mart Raudsepp <leio gentoo org>
+ *
+ * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@@ -13,775 +14,441 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+/* TODO: Review includes.. */
#include <glib.h>
+#include <gio/gio.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
-#include <gconf/gconf.h>
-#include <gconf/gconf-client.h>
#include <string.h>
#include "gnome-mud.h"
#include "mud-connections.h"
+#include "mud-mud.h"
+#include "mud-character.h"
#include "mud-window.h"
#include "mud-connection-view.h"
#include "mud-tray.h"
#include "mud-profile.h"
#include "utils.h"
-struct _MudConnectionsPrivate
+struct _MudConnections
{
- // Main Window
- GtkWidget *winwidget;
- MudTray *tray;
+ GObject parent_instance;
- GtkWidget *window;
- GtkWidget *iconview;
- GtkWidget *popup;
+ MudWindow *parent_window;
- GtkTreeModel *icon_model;
- GtkTreeModel *profile_model;
+ // Main Window
+ GtkWidget *winwidget;
+ MudTray *tray;
- GtkWidget *qconnect_host_entry;
- GtkWidget *qconnect_port_entry;
- GtkWidget *qconnect_connect_button;
+ GtkWidget *window;
+ GtkWidget *iconview;
+ GtkWidget *popup;
- // Properties Dialog
- GtkWidget *properties_window;
- GtkWidget *name_entry;
- GtkWidget *host_entry;
- GtkWidget *port_entry;
+ GtkTreeModel *icon_model;
+ GtkTreeModel *profile_model;
- GtkWidget *icon_button;
- GtkWidget *icon_image;
+ GtkWidget *qconnect_host_entry;
+ GtkWidget *qconnect_port_entry;
+ GtkWidget *qconnect_connect_button;
- GtkWidget *profile_combo;
- GtkCellRenderer *profile_combo_renderer;
+ // Properties Dialog
+ GtkWidget *properties_window;
+ GtkWidget *name_entry;
+ GtkWidget *host_entry;
+ GtkWidget *port_entry;
- GtkWidget *character_name_entry;
- GtkWidget *logon_textview;
+ GtkWidget *icon_button;
+ GtkWidget *icon_image;
- gboolean changed;
+ GtkWidget *profile_combo;
+ GtkCellRenderer *profile_combo_renderer;
- gchar *original_name;
- gchar *original_char_name;
-
- guint connection;
+ GtkWidget *character_name_entry;
+ GtkWidget *logon_textview;
- // Iconview Dialog
- GtkWidget *icon_dialog;
- GtkWidget *icon_dialog_view;
- GtkTreeModel *icon_dialog_view_model;
- GtkWidget *icon_dialog_chooser;
- gchar *icon_current;
+ gboolean changed;
+
+ // Iconview Dialog
+ GtkWidget *icon_dialog;
+ GtkWidget *icon_dialog_view;
+ GtkTreeModel *icon_dialog_view_model;
+ GtkWidget *icon_dialog_chooser;
+ gchar *icon_current;
};
-typedef enum MudConnectionsModelColumns
-{
- MODEL_COLUMN_STRING,
- MODEL_COLUMN_PIXBUF,
- MODEL_COLUMN_MUDNAME,
- MODEL_COLUMN_CHARNAME,
- MODEL_COLUMN_N
-} MudConnectionsModelColumns;
-
-/* Property Identifiers */
enum
{
- PROP_MUD_CONNECTIONS_0,
- PROP_PARENT_WINDOW
+ MODEL_COLUMN_VISIBLE_NAME,
+ MODEL_COLUMN_PIXBUF,
+ MODEL_COLUMN_MUD_CHARACTER,
+ MODEL_COLUMN_N
};
-/* Create the Type */
-G_DEFINE_TYPE(MudConnections, mud_connections, G_TYPE_OBJECT);
-
-/* Class Functions */
-static void mud_connections_init (MudConnections *conn);
-static void mud_connections_class_init (MudConnectionsClass *klass);
-static void mud_connections_finalize (GObject *object);
-static GObject *mud_connections_constructor (GType gtype,
- guint n_properties,
- GObjectConstructParam *properties);
-static void mud_connections_set_property(GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void mud_connections_get_property(GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-/* Callbacks */
-static gint mud_connections_close_cb(GtkWidget *widget,
- MudConnections *conn);
-static void mud_connections_connect_cb(GtkWidget *widget,
- MudConnections *conn);
-static void mud_connections_add_cb(GtkWidget *widget,
- MudConnections *conn);
-static void mud_connections_delete_cb(GtkWidget *widget,
- MudConnections *conn);
-static void mud_connections_properties_cb(GtkWidget *widget,
- MudConnections *conn);
-static void mud_connections_property_cancel_cb(GtkWidget *widget,
- MudConnections *conn);
-static void mud_connections_property_save_cb(GtkWidget *widget,
- MudConnections *conn);
-static void mud_connections_property_icon_cb(GtkWidget *widget,
- MudConnections *conn);
-static void mud_connections_qconnect_cb(GtkWidget *widget,
- MudConnections *conn);
-static gboolean mud_connections_property_changed_cb(GtkWidget *widget,
- GdkEventKey *event,
- MudConnections *conn);
-static void mud_connections_property_combo_changed_cb(GtkWidget *widget,
- MudConnections *conn);
-static gboolean mud_connections_property_delete_cb(GtkWidget *widget,
- GdkEvent *event,
- MudConnections *conn);
-static gint mud_connections_compare_func(GtkTreeModel *model,
- GtkTreeIter *a,
- GtkTreeIter *b,
- gpointer user_data);
-
-/* Private Methods */
-static void mud_connections_populate_iconview(MudConnections *conn);
-static void mud_connections_show_properties(MudConnections *conn,
- gchar *mud);
-static gboolean mud_connections_property_save(MudConnections *conn);
-static gint mud_connections_property_confirm(void);
-static void mud_connections_property_populate_profiles(
- MudConnections *conn);
-static void mud_connections_property_combo_get_index(MudConnections *conn,
- gchar *profile);
-static void mud_connections_refresh_iconview(MudConnections *conn);
-static gboolean mud_connections_delete_confirm(gchar *name);
-static gboolean mud_connections_button_press_cb(GtkWidget *widget,
- GdkEventButton *event,
- MudConnections *conn);
-static void mud_connections_popup(MudConnections *conn,
- GdkEventButton *event);
-
-/* IconDialog Prototypes */
-static void mud_connections_show_icon_dialog(MudConnections *conn);
-
-/* IconDialog callbacks */
-static void mud_connections_icon_fileset_cb(GtkFileChooserButton *widget,
- MudConnections *conn);
-static void mud_connections_icon_select_cb(GtkIconView *view,
- MudConnections *conn);
-void mud_connections_iconview_activate_cb(GtkIconView *iconview,
- GtkTreePath *path,
- MudConnections *conn);
-void mud_connections_gconf_notify_cb(GConfClient *client,
- guint cnxn_id, GConfEntry *entry,
- gpointer *data);
-
-// MudConnections class functions
-static void
-mud_connections_class_init (MudConnectionsClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- /* Overide base object's finalize */
- object_class->finalize = mud_connections_finalize;
-
- /* Override base object constructor */
- object_class->constructor = mud_connections_constructor;
-
- /* Override base object property methods */
- object_class->set_property = mud_connections_set_property;
- object_class->get_property = mud_connections_get_property;
-
- /* Add private data to class */
- g_type_class_add_private(klass, sizeof(MudConnectionsPrivate));
-
- /* Install Properties */
- g_object_class_install_property(object_class,
- PROP_PARENT_WINDOW,
- g_param_spec_object("parent-window",
- "parent mud window",
- "the mud window the connections is attached to",
- MUD_TYPE_WINDOW,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
-}
-
-static void
-mud_connections_init (MudConnections *conn)
-{
- conn->priv = MUD_CONNECTIONS_GET_PRIVATE(conn);
-
- conn->parent_window = NULL;
-}
-
-static GObject *
-mud_connections_constructor (GType gtype,
- guint n_properties,
- GObjectConstructParam *properties)
+enum
{
- MudConnections *conn;
- GtkBuilder *builder;
- GError *error = NULL;
- GConfClient *client;
- GtkWidget *main_window;
-
- GObject *obj;
- MudConnectionsClass *klass;
- GObjectClass *parent_class;
-
- /* Chain up to parent constructor */
- klass = MUD_CONNECTIONS_CLASS( g_type_class_peek(MUD_TYPE_CONNECTIONS) );
- parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
- obj = parent_class->constructor(gtype, n_properties, properties);
-
- conn = MUD_CONNECTIONS(obj);
-
- if(!conn->parent_window)
- g_error("Tried to instantiate MudConnections without passing parent MudWindow\n");
-
- g_object_get(conn->parent_window,
- "window", &conn->priv->winwidget,
- "tray", &conn->priv->tray,
- NULL);
-
- builder = gtk_builder_new();
- if(gtk_builder_add_from_file(builder, UIDIR "/muds.ui", &error) == 0)
- g_error("Failed to load: %s", error->message);
-
- conn->priv->window = GTK_WIDGET(gtk_builder_get_object(builder, "mudviewwindow"));
- conn->priv->iconview = GTK_WIDGET(gtk_builder_get_object(builder, "iconview"));
-
- conn->priv->qconnect_host_entry =
- GTK_WIDGET(gtk_builder_get_object(builder, "qconnect_host_entry"));
- conn->priv->qconnect_port_entry =
- GTK_WIDGET(gtk_builder_get_object(builder, "qconnect_port_entry"));
- conn->priv->qconnect_connect_button =
- GTK_WIDGET(gtk_builder_get_object(builder, "qconnect_connect_button"));
-
- conn->priv->icon_model =
- GTK_TREE_MODEL(gtk_list_store_new(MODEL_COLUMN_N,
- G_TYPE_STRING,
- GDK_TYPE_PIXBUF,
- G_TYPE_STRING,
- G_TYPE_STRING));
-
- gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(conn->priv->icon_model),
- MODEL_COLUMN_STRING,
- GTK_SORT_ASCENDING);
-
- gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(conn->priv->icon_model),
- MODEL_COLUMN_STRING,
- mud_connections_compare_func,
- NULL,
- NULL);
-
- conn->priv->original_name = NULL;
- conn->priv->original_char_name = NULL;
-
- gtk_icon_view_set_model(GTK_ICON_VIEW(conn->priv->iconview),
- conn->priv->icon_model);
- g_object_unref(conn->priv->icon_model);
-
- gtk_icon_view_set_text_column(GTK_ICON_VIEW(conn->priv->iconview),
- MODEL_COLUMN_STRING);
- gtk_icon_view_set_pixbuf_column(GTK_ICON_VIEW(conn->priv->iconview),
- MODEL_COLUMN_PIXBUF);
-
- client = gconf_client_get_default();
- gconf_client_add_dir(client, "/apps/gnome-mud/muds",
- GCONF_CLIENT_PRELOAD_NONE, NULL);
-
- conn->priv->connection =
- gconf_client_notify_add(client, "/apps/gnome-mud/muds",
- (GConfClientNotifyFunc)
- mud_connections_gconf_notify_cb,
- conn, NULL, NULL);
-
- g_signal_connect(conn->priv->iconview, "item-activated",
- G_CALLBACK(mud_connections_iconview_activate_cb),
- conn);
- g_signal_connect(conn->priv->iconview, "button-press-event",
- G_CALLBACK(mud_connections_button_press_cb),
- conn);
- g_signal_connect(conn->priv->window, "destroy",
- G_CALLBACK(mud_connections_close_cb), conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "connect_button")),
- "clicked", G_CALLBACK(mud_connections_connect_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "add_button")),
- "clicked", G_CALLBACK(mud_connections_add_cb), conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "delete_button")),
- "clicked", G_CALLBACK(mud_connections_delete_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "properties_button")),
- "clicked", G_CALLBACK(mud_connections_properties_cb),
- conn);
- g_signal_connect(conn->priv->qconnect_connect_button, "clicked",
- G_CALLBACK(mud_connections_qconnect_cb), conn);
-
- mud_connections_populate_iconview(conn);
-
- g_object_get(conn->parent_window, "window", &main_window, NULL);
-
- g_object_set(conn->priv->window,
- "transient-for", GTK_WINDOW(main_window),
- NULL);
-
- gtk_widget_show_all(conn->priv->window);
- g_object_unref(builder);
- g_object_unref(client);
-
- return obj;
-}
+ MODEL_ICON_NAME,
+ MODEL_ICON_PIXBUF,
+ MODEL_ICON_N
+};
-static void
-mud_connections_finalize (GObject *object)
+enum
{
- MudConnections *conn;
- GObjectClass *parent_class;
- GConfClient *client = gconf_client_get_default();
-
- conn = MUD_CONNECTIONS(object);
-
- gconf_client_notify_remove(client, conn->priv->connection);
-
- parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
- parent_class->finalize(object);
-
- g_object_unref(client);
-}
+ MODEL_PROFILE_NAME,
+ MODEL_PROFILE_OBJECT, /* TODO: Maybe keep profile id in string here? */
+ MODEL_PROFILE_N
+};
-static void
-mud_connections_set_property(GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+enum
{
- MudConnections *self;
-
- self = MUD_CONNECTIONS(object);
+ PROP_0,
+ PROP_PARENT_WINDOW,
+ N_PROPS
+};
- switch(prop_id)
- {
- case PROP_PARENT_WINDOW:
- self->parent_window = MUD_WINDOW(g_value_get_object(value));
- break;
+static GParamSpec *properties [N_PROPS];
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
+G_DEFINE_TYPE(MudConnections, mud_connections, G_TYPE_OBJECT);
-static void
-mud_connections_get_property(GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MudConnections *self;
+/* Callbacks */
+/* FIXME: Remove most forward decls, we can structure things to not need them */
+static gint mud_connections_close_cb (GtkWidget *widget,
+ MudConnections *self);
+static void mud_connections_connect_cb (GtkWidget *widget,
+ MudConnections *self);
+static void mud_connections_add_cb (GtkWidget *widget,
+ MudConnections *self);
+static void mud_connections_delete_cb (GtkWidget *widget,
+ MudConnections *self);
+static void mud_connections_properties_cb (GtkWidget *widget,
+ MudConnections *self);
+static void mud_connections_property_cancel_cb (GtkWidget *widget,
+ MudConnections *self);
+static void mud_connections_property_save_cb (GtkWidget *widget,
+ MudConnections *self);
+static void mud_connections_property_icon_cb (GtkWidget *widget,
+ MudConnections *self);
+static void mud_connections_qconnect_cb (GtkWidget *widget,
+ MudConnections *self);
+static gboolean mud_connections_property_changed_cb (GtkWidget *widget,
+ GdkEventKey *event,
+ MudConnections *self);
+static void mud_connections_property_combo_changed_cb (GtkWidget *widget,
+ MudConnections *self);
+static gboolean mud_connections_property_delete_cb (GtkWidget *widget,
+ GdkEvent *event,
+ MudConnections *self);
+static gint mud_connections_compare_func (GtkTreeModel *model,
+ GtkTreeIter *a,
+ GtkTreeIter *b,
+ gpointer user_data);
- self = MUD_CONNECTIONS(object);
+/* Private Methods */
+static void mud_connections_populate_iconview (MudConnections *self);
+static void mud_connections_show_properties (MudConnections *self,
+ MudCharacter *character);
+static gboolean mud_connections_property_save (MudConnections *self);
+static gint mud_connections_property_confirm (void);
+static void mud_connections_property_populate_profiles (MudConnections *self);
+static void mud_connections_property_set_profile (MudConnections *self,
+ const MudProfile *profile);
+static void mud_connections_refresh_iconview (MudConnections *self);
+static gboolean mud_connections_delete_confirm (gchar *name);
+static gboolean mud_connections_button_press_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ MudConnections *self);
+static void mud_connections_popup (MudConnections *self,
+ GdkEventButton *event);
- switch(prop_id)
- {
- case PROP_PARENT_WINDOW:
- g_value_take_object(value, self->parent_window);
- break;
+/* IconDialog Prototypes */
+static void mud_connections_show_icon_dialog (MudConnections *self);
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
+/* IconDialog callbacks */
+static void mud_connections_icon_fileset_cb (GtkFileChooserButton *widget,
+ MudConnections *self);
+static void mud_connections_icon_select_cb (GtkIconView *view,
+ MudConnections *self);
+void mud_connections_iconview_activate_cb (GtkIconView *iconview,
+ GtkTreePath *path,
+ MudConnections *self);
// MudConnections Private Methods
static gint
-mud_connections_compare_func(GtkTreeModel *model,
- GtkTreeIter *a,
- GtkTreeIter *b,
- gpointer user_data)
+mud_connections_compare_func (GtkTreeModel *model,
+ GtkTreeIter *a,
+ GtkTreeIter *b,
+ gpointer user_data)
{
- gchar *item_one, *item_two;
- gboolean item_one_haschar, item_two_haschar;
- gint ret = 0;
+ /* TODO: Simplify */
+ gchar *item_one, *item_two;
+ gboolean item_one_haschar, item_two_haschar;
+ gint ret = 0;
- gtk_tree_model_get(model,
- a,
- MODEL_COLUMN_STRING, &item_one,
- -1);
+ gtk_tree_model_get (model,
+ a,
+ MODEL_COLUMN_VISIBLE_NAME, &item_one,
+ -1);
- gtk_tree_model_get(model,
- b,
- MODEL_COLUMN_STRING, &item_two,
- -1);
+ gtk_tree_model_get (model,
+ b,
+ MODEL_COLUMN_VISIBLE_NAME, &item_two,
+ -1);
- item_one_haschar = (g_strrstr(item_one, "\n") != NULL);
- item_two_haschar = (g_strrstr(item_two, "\n") != NULL);
+ item_one_haschar = (g_strrstr (item_one, "\n") != NULL);
+ item_two_haschar = (g_strrstr (item_two, "\n") != NULL);
- if(item_one_haschar && item_two_haschar)
+ if (item_one_haschar && item_two_haschar)
{
- gchar **item_onev, **item_twov;
+ gchar **item_onev, **item_twov;
- item_onev = g_strsplit(item_one, "\n", -1);
- item_twov = g_strsplit(item_two, "\n", -1);
+ item_onev = g_strsplit (item_one, "\n", -1);
+ item_twov = g_strsplit (item_two, "\n", -1);
- ret = strcmp(item_onev[1], item_twov[1]);
+ ret = strcmp (item_onev[1], item_twov[1]);
- g_strfreev(item_onev);
- g_strfreev(item_twov);
+ g_strfreev (item_onev);
+ g_strfreev (item_twov);
}
- else if(item_one_haschar && !item_two_haschar)
- ret = -1;
- else if(!item_one_haschar && item_two_haschar)
- ret = 1;
- else
- ret = strcmp(item_one, item_two);
+ else if (item_one_haschar && !item_two_haschar)
+ ret = -1;
+ else if (!item_one_haschar && item_two_haschar)
+ ret = 1;
+ else
+ ret = strcmp (item_one, item_two);
- g_free(item_one);
- g_free(item_two);
+ g_free (item_one);
+ g_free (item_two);
- return ret;
+ return ret;
}
static gint
-mud_connections_close_cb(GtkWidget *widget, MudConnections *conn)
+mud_connections_close_cb (GtkWidget *widget,
+ MudConnections *self)
{
- g_object_unref(conn);
+ g_object_unref (self);
- return TRUE;
+ return TRUE;
}
static void
-mud_connections_connect_cb(GtkWidget *widget, MudConnections *conn)
+mud_connections_connect_cb (GtkWidget *widget,
+ MudConnections *self)
{
- GList *selected =
- gtk_icon_view_get_selected_items(
- GTK_ICON_VIEW(conn->priv->iconview));
- GtkTreeIter iter;
- gchar *mud_name, *char_name, *key,
- *profile, *host, *logon;
- gint port;
- GConfClient *client = gconf_client_get_default();
- MudConnectionView *view;
-
- if(g_list_length(selected) == 0)
- return;
-
- logon = NULL;
-
- gtk_tree_model_get_iter(conn->priv->icon_model, &iter,
- (GtkTreePath *)selected->data);
- gtk_tree_model_get(conn->priv->icon_model, &iter, MODEL_COLUMN_MUDNAME, &mud_name,
MODEL_COLUMN_CHARNAME, &char_name, -1);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/host", mud_name);
- host = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/profile", mud_name);
- profile = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/port", mud_name);
- port = gconf_client_get_int(client, key, NULL);
- g_free(key);
-
- if(char_name && strlen(char_name) > 0)
- {
- key = g_strdup_printf(
- "/apps/gnome-mud/muds/%s/characters/%s/logon",
- mud_name, char_name);
- logon = gconf_client_get_string(client, key, NULL);
- g_free(key);
- }
+ GtkTreeIter iter;
+ gchar *mud_name, *host, *connect_string;
+ gint port;
+ MudConnectionView *view;
+ MudProfile *profile;
+ MudCharacter *character;
+ MudMud *mud;
+ GList *selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW(self->iconview));
+
+ if (g_list_length (selected) == 0)
+ return;
+
+ gtk_tree_model_get_iter (self->icon_model, &iter,
+ (GtkTreePath *)selected->data);
+ gtk_tree_model_get (self->icon_model, &iter,
+ MODEL_COLUMN_MUD_CHARACTER, &character,
+ -1);
+
+ g_object_get (character,
+ "mud", &mud,
+ "profile", &profile,
+ "connect-string", &connect_string,
+ NULL);
+ g_object_get (mud,
+ "name", &mud_name,
+ "hostname", &host,
+ "port", &port,
+ NULL);
- mud_tray_update_icon(conn->priv->tray, offline);
+ mud_tray_update_icon (self->tray, offline);
- view = g_object_new(MUD_TYPE_CONNECTION_VIEW,
- "hostname", host,
- "port", port,
- "profile-name", profile,
- "mud-name", mud_name,
- "connect-string", (logon && strlen(logon) != 0) ? logon : NULL,
- "window", conn->parent_window,
- NULL);
+ /* TODO: Bind these instead? */
+ view = g_object_new (MUD_TYPE_CONNECTION_VIEW,
+ "hostname", host,
+ "port", port,
+ "profile", profile,
+ "mud-name", mud_name,
+ "connect-string", (connect_string && strlen (connect_string) != 0) ? connect_string :
NULL,
+ "window", self->parent_window,
+ NULL);
- mud_window_add_connection_view(conn->parent_window, G_OBJECT(view), mud_name);
- mud_connection_view_set_profile(view,
-
mud_profile_manager_get_profile_by_name(conn->parent_window->profile_manager,
- profile));
- mud_window_profile_menu_set_active(conn->parent_window, profile);
+ mud_window_add_connection_view (self->parent_window, G_OBJECT(view), mud_name);
+ mud_window_profile_menu_set_active (self->parent_window, profile);
- g_free(mud_name);
- g_free(char_name);
- g_object_unref(client);
+ g_free (host);
+ g_object_unref (profile); /* TODO: was take_object? */
+ g_free (connect_string);
- g_list_foreach(selected, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(selected);
+ g_list_foreach (selected, (GFunc)gtk_tree_path_free, NULL);
+ g_list_free (selected);
- gtk_widget_destroy(conn->priv->window);
+ gtk_widget_destroy (self->window);
}
static void
-mud_connections_qconnect_cb(GtkWidget *widget, MudConnections *conn)
+mud_connections_qconnect_cb (GtkWidget *widget,
+ MudConnections *self)
{
- MudConnectionView *view;
- const gchar *host;
- gint port =
- gtk_spin_button_get_value_as_int(
- GTK_SPIN_BUTTON(conn->priv->qconnect_port_entry));
-
- host = gtk_entry_get_text(GTK_ENTRY(conn->priv->qconnect_host_entry));
+ MudConnectionView *view;
+ const gchar *host = gtk_entry_get_text (GTK_ENTRY (self->qconnect_host_entry));
+ gint port = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (self->qconnect_port_entry));
- if(strlen(host) != 0)
+ if (strlen (host) != 0)
{
-
- mud_tray_update_icon(conn->priv->tray, offline);
- view = g_object_new(MUD_TYPE_CONNECTION_VIEW,
- "hostname", host,
- "port", port,
- "profile-name", "Default",
- "mud-name", (gchar *)host,
- "connect-string", NULL,
- "window", conn->parent_window,
- NULL);
- mud_window_add_connection_view(conn->parent_window, G_OBJECT(view), (gchar *)host);
-
- gtk_widget_destroy(conn->priv->window);
+ mud_tray_update_icon (self->tray, offline);
+ view = g_object_new (MUD_TYPE_CONNECTION_VIEW,
+ "hostname", host,
+ "port", port,
+ "profile-name", "Default",
+ "mud-name", (gchar *)host,
+ "connect-string", NULL,
+ "window", self->parent_window,
+ NULL);
+ mud_window_add_connection_view (self->parent_window, G_OBJECT(view), (gchar *)host);
+
+ gtk_widget_destroy(self->window);
}
}
static void
-mud_connections_add_cb(GtkWidget *widget, MudConnections *conn)
+mud_connections_add_cb (GtkWidget *widget,
+ MudConnections *self)
{
- mud_connections_show_properties(conn, NULL);
+ mud_connections_show_properties (self, NULL);
}
static void
-mud_connections_delete_cb(GtkWidget *widget, MudConnections *conn)
+mud_connections_delete_cb (GtkWidget *widget,
+ MudConnections *self)
{
- GList *selected =
- gtk_icon_view_get_selected_items(
- GTK_ICON_VIEW(conn->priv->iconview));
- GtkTreeIter iter;
- gchar *display_name, *display_mud_name, *mud_name, *key, *char_name;
- GConfClient *client = gconf_client_get_default();
-
- if(g_list_length(selected) == 0)
- return;
-
- gtk_tree_model_get_iter(conn->priv->icon_model, &iter,
- (GtkTreePath *)selected->data);
- gtk_tree_model_get(conn->priv->icon_model, &iter,
- MODEL_COLUMN_STRING, &display_name,
- MODEL_COLUMN_MUDNAME, &mud_name,
- MODEL_COLUMN_CHARNAME, &char_name, -1);
-
- display_mud_name = g_strrstr(display_name, "\n");
- if(display_mud_name)
- ++display_mud_name;
- else
- display_mud_name = display_name;
-
- if(!mud_connections_delete_confirm(display_mud_name))
- {
- g_free(display_name);
- g_free(mud_name);
- g_free(char_name);
-
- g_object_unref(client);
-
- g_list_foreach(selected, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(selected);
-
- return;
- }
+ GtkTreeIter iter;
+ gchar *char_name;
+ MudCharacter *character;
+ MudMud *mud;
+ GList *selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (self->iconview));
+
+ if (g_list_length (selected) == 0)
+ return;
+
+ gtk_tree_model_get_iter (self->icon_model, &iter,
+ (GtkTreePath *)selected->data);
+ gtk_tree_model_get (self->icon_model, &iter,
+ MODEL_COLUMN_MUD_CHARACTER, &character,
+ -1);
+
+ g_object_get (character,
+ "mud", &mud,
+ "name", &char_name,
+ NULL);
- if(char_name && strlen(char_name) > 0)
+ if (mud_connections_delete_confirm (char_name)) /* TODO: Show both mud and charname in confirmation
dialog? */
{
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters/%s",
- mud_name, char_name);
-
- gconf_client_recursive_unset(client, key, 0, NULL);
-
- g_free(key);
-
- gconf_client_suggest_sync(client, NULL);
- } else {
- key = g_strdup_printf("/apps/gnome-mud/muds/%s", mud_name);
- gconf_client_recursive_unset(client, key, 0, NULL);
-
- g_free(key);
-
- gconf_client_suggest_sync(client, NULL);
+ mud_profile_manager_delete_character (self->parent_window->profile_manager, character);
+ /* TODO: Might need to manually repopulate iconview until GSettings aren't hooked up */
}
- g_free(display_name);
- g_free(mud_name);
- g_free(char_name);
- g_object_unref(client);
+ g_free (char_name);
- g_list_foreach(selected, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(selected);
+ g_list_foreach (selected, (GFunc)gtk_tree_path_free, NULL);
+ g_list_free (selected);
}
static void
-mud_connections_properties_cb(GtkWidget *widget, MudConnections *conn)
+mud_connections_properties_cb (GtkWidget *widget,
+ MudConnections *self)
{
- GList *selected =
- gtk_icon_view_get_selected_items(
- GTK_ICON_VIEW(conn->priv->iconview));
- GtkTreeIter iter;
- gchar *buf;
+ GList *selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (self->iconview));
+ GtkTreeIter iter;
+ MudCharacter *character;
- if(g_list_length(selected) == 0)
- return;
+ if (g_list_length (selected) == 0)
+ return;
- gtk_tree_model_get_iter(conn->priv->icon_model, &iter,
- (GtkTreePath *)selected->data);
- gtk_tree_model_get(conn->priv->icon_model, &iter, 0, &buf, -1);
+ gtk_tree_model_get_iter (self->icon_model, &iter,
+ (GtkTreePath *)selected->data);
+ gtk_tree_model_get (self->icon_model, &iter,
+ MODEL_COLUMN_MUD_CHARACTER, &character,
+ -1);
- mud_connections_show_properties(conn, buf);
+ mud_connections_show_properties (self, character);
}
static void
-mud_connections_populate_iconview(MudConnections *conn)
+add_character_to_iconmodel (MudCharacter *character,
+ GtkListStore *model)
{
- GSList *muds, *characters, *mud_entry, *char_entry;
- gchar *key, *mud_name, *char_name, *display_name,
- *name_strip, *char_strip, *buf;
- GConfClient *client = gconf_client_get_default();
- GtkTreeIter iter;
- GdkPixbuf *icon;
-
- key = g_strdup("/apps/gnome-mud/muds");
- muds = gconf_client_all_dirs(client, key, NULL);
- g_free(key);
+ GdkPixbuf *icon;
+ GtkTreeIter iter;
+ MudMud *mud;
+ gchar *visible_name, *char_name;
+ const gchar *mud_name;
+
+ g_object_get (character,
+ "mud", &mud,
+ "name", &char_name,
+ NULL);
+ mud_name = mud_mud_get_name (mud);
- for(mud_entry = muds; mud_entry != NULL;
- mud_entry = g_slist_next(mud_entry))
+ /* TODO: Reimplement icon support */
+#if 0
+ if (icon_name && strcmp (icon_name, "gnome-mud") != 0)
{
- mud_name = g_path_get_basename((gchar *)mud_entry->data);
- name_strip = NULL;
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/name", mud_name);
- name_strip = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters",
- mud_name);
- characters = gconf_client_all_dirs(client, key, NULL);
- g_free(key);
-
- char_entry = characters;
-
- if(char_entry == NULL) // No Characters
- {
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/icon", mud_name);
- buf = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- if(buf && strcmp(buf, "gnome-mud") != 0)
- {
- icon = gdk_pixbuf_new_from_file_at_size(
- buf, 48, 48, NULL);
- g_free(buf);
- }
- else
- icon =
- gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
- "gnome-mud", 48, 0, NULL);
-
- gtk_list_store_append(
- GTK_LIST_STORE(conn->priv->icon_model), &iter);
- gtk_list_store_set(
- GTK_LIST_STORE(conn->priv->icon_model), &iter,
- MODEL_COLUMN_STRING, name_strip,
- MODEL_COLUMN_PIXBUF, icon,
- MODEL_COLUMN_MUDNAME, mud_name,
- MODEL_COLUMN_CHARNAME, NULL,
- -1);
-
- g_object_unref(icon);
- continue;
- }
-
- for(char_entry = characters; char_entry != NULL;
- char_entry = g_slist_next(char_entry))
- {
- char_strip = NULL;
- char_name = g_path_get_basename((gchar *)char_entry->data);
-
- key = g_strdup_printf(
- "/apps/gnome-mud/muds/%s/characters/%s/name",
- mud_name, char_name);
- char_strip = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- display_name = g_strconcat(char_strip, "\n", name_strip, NULL);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/icon", mud_name);
- buf = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- if(buf && strcmp(buf, "gnome-mud") != 0)
- {
- icon = gdk_pixbuf_new_from_file_at_size(
- buf, 48, 48, NULL);
- g_free(buf);
- }
- else
- icon =
- gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
- "gnome-mud", 48, 0, NULL);
-
- gtk_list_store_append(GTK_LIST_STORE(conn->priv->icon_model),
- &iter);
- gtk_list_store_set(GTK_LIST_STORE(conn->priv->icon_model),
- &iter,
- MODEL_COLUMN_STRING, display_name,
- MODEL_COLUMN_PIXBUF, icon,
- MODEL_COLUMN_MUDNAME, mud_name,
- MODEL_COLUMN_CHARNAME, char_name,
- -1);
-
- g_object_unref(icon);
- g_free(char_name);
- g_free(char_strip);
- g_free(display_name);
- }
-
- for(char_entry = characters; char_entry != NULL;
- char_entry = g_slist_next(char_entry))
- g_free(char_entry->data);
-
- if(characters)
- g_slist_free(characters);
-
- g_free(mud_name);
- g_free(name_strip);
+ icon = gdk_pixbuf_new_from_file_at_size (icon_name,
+ 48, 48, NULL);
}
+ else
+ {
+ icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ "gnome-mud", 48, 0, NULL);
+ }
+#endif
+ icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ "gnome-mud", 48, 0, NULL);
+
+ visible_name = g_strdup_printf ("%s\n%s", char_name, mud_name);
+
+ gtk_list_store_append (model, &iter);
+ /* TODO: Handle character going away from under us, to support removal outside this dialog */
+ gtk_list_store_set (model, &iter,
+ MODEL_COLUMN_VISIBLE_NAME, visible_name,
+ MODEL_COLUMN_PIXBUF, icon,
+ MODEL_COLUMN_MUD_CHARACTER, character,
+ -1);
+ g_free (visible_name);
+ g_free (char_name);
+ g_object_unref (icon);
+}
- for(mud_entry = muds; mud_entry != NULL;
- mud_entry = g_slist_next(mud_entry))
- g_free(mud_entry->data);
-
- if(muds)
- g_slist_free(muds);
+static void
+mud_connections_populate_iconview (MudConnections *self)
+{
+ /* TODO: Inline again? */
+ g_sequence_foreach (mud_profile_manager_get_characters (self->parent_window->profile_manager),
+ (GFunc)add_character_to_iconmodel,
+ GTK_LIST_STORE (self->icon_model));
}
+#if 0
+#warning Reimplement iconview refresh
static void
-mud_connections_refresh_iconview(MudConnections *conn)
+mud_connections_refresh_iconview(MudConnections *self)
{
GConfClient *client = gconf_client_get_default();
- gtk_list_store_clear(GTK_LIST_STORE(conn->priv->icon_model));
+ gtk_list_store_clear(GTK_LIST_STORE(self->icon_model));
gconf_client_suggest_sync(client, NULL);
@@ -790,764 +457,741 @@ mud_connections_refresh_iconview(MudConnections *conn)
void
mud_connections_gconf_notify_cb(GConfClient *client, guint cnxn_id,
- GConfEntry *entry, gpointer *conn)
+ GConfEntry *entry, gpointer *self)
{
mud_connections_refresh_iconview((MudConnections *)conn);
}
+#endif
void
-mud_connections_iconview_activate_cb(GtkIconView *iconview,
- GtkTreePath *path,
- MudConnections *conn)
+mud_connections_iconview_activate_cb (GtkIconView *iconview,
+ GtkTreePath *path,
+ MudConnections *self)
{
- mud_connections_connect_cb(GTK_WIDGET(iconview), conn);
+ mud_connections_connect_cb (GTK_WIDGET (iconview), self);
}
static gboolean
-mud_connections_button_press_cb(GtkWidget *widget,
- GdkEventButton *event,
- MudConnections *conn)
+mud_connections_button_press_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ MudConnections *self)
{
- if ((event->button == 3) &&
- !(event->state & (GDK_SHIFT_MASK |
- GDK_CONTROL_MASK |
- GDK_MOD1_MASK)))
+ if ((event->button == 3) &&
+ !(event->state & (GDK_SHIFT_MASK |
+ GDK_CONTROL_MASK |
+ GDK_MOD1_MASK)))
{
- mud_connections_popup(conn, event);
- return TRUE;
+ mud_connections_popup (self, event);
+ return TRUE;
}
- return FALSE;
+ return FALSE;
}
static void
-mud_connections_popup(MudConnections *conn, GdkEventButton *event)
+mud_connections_popup (MudConnections *self,
+ GdkEventButton *event)
{
- GtkBuilder *builder;
- GError *error = NULL;
- GtkWidget *popup;
- GList *selected =
- gtk_icon_view_get_selected_items(
- GTK_ICON_VIEW(conn->priv->iconview));
-
- if(g_list_length(selected) == 0)
- return;
-
- builder = gtk_builder_new();
- if(gtk_builder_add_from_file(builder, UIDIR "/muds.ui", &error) == 0)
- g_error("Failed to load: %s", error->message);
-
- popup = GTK_WIDGET(gtk_builder_get_object(builder, "popupmenu"));
-
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "connect")), "activate",
- G_CALLBACK(mud_connections_connect_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "add")), "activate",
- G_CALLBACK(mud_connections_add_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "delete")), "activate",
- G_CALLBACK(mud_connections_delete_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "properties")), "activate",
- G_CALLBACK(mud_connections_properties_cb),
- conn);
-
- g_object_unref(builder);
-
- gtk_menu_attach_to_widget(GTK_MENU(popup), conn->priv->iconview,
- NULL);
- gtk_widget_show_all(popup);
- gtk_menu_popup(GTK_MENU(popup), NULL, NULL, NULL, NULL,
- event ? event->button : 0,
- event ? event->time : gtk_get_current_event_time());
-
- g_list_foreach(selected, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(selected);
+ GtkBuilder *builder;
+ GError *error = NULL;
+ GtkWidget *popup;
+ GList *selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (self->iconview));
+
+ if (g_list_length(selected) == 0)
+ return;
+
+ builder = gtk_builder_new ();
+ if (gtk_builder_add_from_file (builder, UIDIR "/muds.ui", &error) == 0)
+ g_error ("Failed to load: %s", error->message);
+
+ popup = GTK_WIDGET (gtk_builder_get_object (builder, "popupmenu"));
+
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "connect")),
+ "activate", G_CALLBACK (mud_connections_connect_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "add")),
+ "activate", G_CALLBACK (mud_connections_add_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "delete")),
+ "activate", G_CALLBACK (mud_connections_delete_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "properties")),
+ "activate", G_CALLBACK (mud_connections_properties_cb),
+ self);
+
+ g_object_unref (builder);
+
+ gtk_menu_attach_to_widget (GTK_MENU(popup), self->iconview, NULL);
+ gtk_widget_show_all (popup);
+ gtk_menu_popup (GTK_MENU (popup), NULL, NULL, NULL, NULL,
+ event ? event->button : 0,
+ event ? event->time : gtk_get_current_event_time ());
+
+ g_list_foreach (selected, (GFunc)gtk_tree_path_free, NULL);
+ g_list_free (selected);
}
static gboolean
-mud_connections_delete_confirm(gchar *name)
+mud_connections_delete_confirm (gchar *name)
{
- GtkBuilder *builder;
- GError *error = NULL;
- GtkWidget *dialog;
- GtkWidget *label;
- gint result;
- gchar *message;
- gchar *title;
+ GtkBuilder *builder;
+ GError *error = NULL;
+ GtkWidget *dialog;
+ GtkWidget *label;
+ gint result;
+ gchar *message;
+ gchar *title;
- builder = gtk_builder_new();
- if(gtk_builder_add_from_file(builder, UIDIR "/muds.ui", &error) == 0)
- g_error("Failed to load: %s", error->message);
+ builder = gtk_builder_new ();
+ if(gtk_builder_add_from_file (builder, UIDIR "/muds.ui", &error) == 0)
+ g_error ("Failed to load: %s", error->message);
- dialog = GTK_WIDGET(gtk_builder_get_object(builder, "mudviewdelconfirm"));
- label = GTK_WIDGET(gtk_builder_get_object(builder, "message"));
- g_object_unref(builder);
+ dialog = GTK_WIDGET (gtk_builder_get_object (builder, "mudviewdelconfirm"));
+ label = GTK_WIDGET (gtk_builder_get_object (builder, "message"));
+ g_object_unref (builder);
- message =
- g_strdup_printf(_("Are you sure you want to delete %s?"), name);
- title = g_strdup_printf(_("Delete %s?"), name);
+ message = g_strdup_printf (_("Are you sure you want to delete %s?"), name);
+ title = g_strdup_printf (_("Delete %s?"), name);
- gtk_label_set_text(GTK_LABEL(label), message);
- gtk_window_set_title(GTK_WINDOW(dialog), title);
+ gtk_label_set_text (GTK_LABEL (label), message);
+ gtk_window_set_title (GTK_WINDOW (dialog), title);
- g_free(message);
- g_free(title);
+ g_free (message);
+ g_free (title);
- result = gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
+ result = gtk_dialog_run (GTK_DIALOG(dialog));
+ gtk_widget_destroy (dialog);
- return (result == GTK_RESPONSE_YES);
+ return (result == GTK_RESPONSE_YES);
}
static void
-mud_connections_show_properties(MudConnections *conn, gchar *mud)
+mud_connections_show_properties (MudConnections *self,
+ MudCharacter *character)
{
- GtkBuilder *builder;
- GError *error = NULL;
- GConfClient *client;
- GtkTextBuffer *buffer;
- gchar *key, *buf, *name_strip, *char_strip;
- gint port;
- gchar **mud_tuple;
-
- builder = gtk_builder_new();
- if(gtk_builder_add_from_file(builder, UIDIR "/muds.ui", &error) == 0)
- g_error("Failed to load: %s", error->message);
-
- conn->priv->properties_window =
- GTK_WIDGET(gtk_builder_get_object(builder, "mudviewproperties"));
- conn->priv->name_entry = GTK_WIDGET(gtk_builder_get_object(builder, "name_entry"));
- conn->priv->host_entry = GTK_WIDGET(gtk_builder_get_object(builder, "host_entry"));
- conn->priv->port_entry = GTK_WIDGET(gtk_builder_get_object(builder, "port_entry"));
- conn->priv->icon_button = GTK_WIDGET(gtk_builder_get_object(builder, "icon_button"));
- conn->priv->icon_image = GTK_WIDGET(gtk_builder_get_object(builder, "icon_image"));
- conn->priv->profile_combo =
- GTK_WIDGET(gtk_builder_get_object(builder, "profile_combo"));
- conn->priv->character_name_entry =
- GTK_WIDGET(gtk_builder_get_object(builder, "character_name_entry"));
- conn->priv->logon_textview =
- GTK_WIDGET(gtk_builder_get_object(builder, "character_logon_textview"));
-
- if(conn->priv->icon_current)
- g_free(conn->priv->icon_current);
- conn->priv->icon_current = NULL;
-
- mud_connections_property_populate_profiles(conn);
- gtk_combo_box_set_model(
- GTK_COMBO_BOX(conn->priv->profile_combo),
- conn->priv->profile_model);
- g_object_unref(conn->priv->profile_model);
-
- conn->priv->profile_combo_renderer = gtk_cell_renderer_text_new();
- gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(conn->priv->profile_combo),
- conn->priv->profile_combo_renderer, TRUE);
- gtk_cell_layout_set_attributes(
- GTK_CELL_LAYOUT(conn->priv->profile_combo),
- conn->priv->profile_combo_renderer, "text", 0, NULL);
-
- g_signal_connect(conn->priv->properties_window, "delete-event",
- G_CALLBACK(mud_connections_property_delete_cb), conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "cancel_button")),
- "clicked",
- G_CALLBACK(mud_connections_property_cancel_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "save_button")),
- "clicked",
- G_CALLBACK(mud_connections_property_save_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "icon_button")),
- "clicked",
- G_CALLBACK(mud_connections_property_icon_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "name_entry")),
- "key-press-event",
- G_CALLBACK(mud_connections_property_changed_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "host_entry")),
- "key-press-event",
- G_CALLBACK(mud_connections_property_changed_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "port_entry")),
- "key-press-event",
- G_CALLBACK(mud_connections_property_changed_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "character_name_entry")),
- "key-press-event",
- G_CALLBACK(mud_connections_property_changed_cb),
- conn);
- g_signal_connect(
- GTK_WIDGET(gtk_builder_get_object(builder, "character_logon_textview")),
- "key-press-event",
- G_CALLBACK(mud_connections_property_changed_cb),
- conn);
- g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "profile_combo")),
- "changed",
- G_CALLBACK(mud_connections_property_combo_changed_cb),
- conn);
-
- g_object_unref(builder);
-
- gtk_widget_set_visible(conn->priv->properties_window, TRUE);
-
- if(conn->priv->original_name != NULL)
- g_free(conn->priv->original_name);
- conn->priv->original_name = NULL;
-
- g_free(conn->priv->original_char_name);
- conn->priv->original_char_name = NULL;
-
- if(mud != NULL)
+ GtkBuilder *builder;
+ GError *error = NULL;
+ GtkTextBuffer *buffer;
+ MudMud *mud;
+ const gchar *icon_name, *connect_string;
+
+ builder = gtk_builder_new ();
+ if (gtk_builder_add_from_file (builder, UIDIR "/muds.ui", &error) == 0)
+ g_error ("Failed to load: %s", error->message);
+
+ self->properties_window = GTK_WIDGET (gtk_builder_get_object (builder, "mudviewproperties"));
+ self->name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
+ self->host_entry = GTK_WIDGET (gtk_builder_get_object (builder, "host_entry"));
+ self->port_entry = GTK_WIDGET (gtk_builder_get_object (builder, "port_entry"));
+ self->icon_button = GTK_WIDGET (gtk_builder_get_object (builder, "icon_button"));
+ self->icon_image = GTK_WIDGET (gtk_builder_get_object (builder, "icon_image"));
+ self->profile_combo = GTK_WIDGET (gtk_builder_get_object (builder, "profile_combo"));
+ self->character_name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "character_name_entry"));
+ self->logon_textview = GTK_WIDGET (gtk_builder_get_object (builder, "character_logon_textview"));
+
+ g_clear_pointer (&self->icon_current, g_free);
+
+ mud_connections_property_populate_profiles (self);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (self->profile_combo),
+ self->profile_model);
+ g_object_unref (self->profile_model);
+
+ self->profile_combo_renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self->profile_combo),
+ self->profile_combo_renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self->profile_combo),
+ self->profile_combo_renderer, "text", 0, NULL);
+
+ g_signal_connect (self->properties_window, "delete-event",
+ G_CALLBACK (mud_connections_property_delete_cb), self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "cancel_button")),
+ "clicked",
+ G_CALLBACK (mud_connections_property_cancel_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "save_button")),
+ "clicked",
+ G_CALLBACK (mud_connections_property_save_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object(builder, "icon_button")),
+ "clicked",
+ G_CALLBACK (mud_connections_property_icon_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "name_entry")),
+ "key-press-event",
+ G_CALLBACK(mud_connections_property_changed_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "host_entry")),
+ "key-press-event",
+ G_CALLBACK (mud_connections_property_changed_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "port_entry")),
+ "key-press-event",
+ G_CALLBACK (mud_connections_property_changed_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "character_name_entry")),
+ "key-press-event",
+ G_CALLBACK (mud_connections_property_changed_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "character_logon_textview")),
+ "key-press-event",
+ G_CALLBACK (mud_connections_property_changed_cb),
+ self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object(builder, "profile_combo")),
+ "changed",
+ G_CALLBACK (mud_connections_property_combo_changed_cb),
+ self);
+
+ g_object_unref (builder);
+
+ g_object_set_data (G_OBJECT (self->properties_window), "current-character", character);
+ gtk_widget_set_visible (self->properties_window, TRUE);
+
+ if(character == NULL)
+ return;
+
+ mud = mud_character_get_mud (character);
+
+ gtk_entry_set_text (GTK_ENTRY (self->name_entry),
+ mud_mud_get_name (mud));
+
+ gtk_entry_set_text (GTK_ENTRY (self->character_name_entry),
+ mud_character_get_name (character));
+
+ gtk_entry_set_text (GTK_ENTRY (self->host_entry),
+ mud_mud_get_hostname (mud));
+
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (self->port_entry),
+ mud_mud_get_port (mud));
+
+ mud_connections_property_set_profile (self, mud_character_get_profile (character));
+
+ connect_string = mud_character_get_connect_string (character);
+ icon_name = mud_character_get_icon (character);
+
+ if (icon_name && strcmp (icon_name, "gnome-mud") != 0)
{
- gint len;
- mud_tuple = g_strsplit(mud, "\n", -1);
- g_free(mud);
- len = g_strv_length(mud_tuple);
-
- switch(len)
- {
- case 1:
- conn->priv->original_name = g_strdup(mud_tuple[0]);
- break;
-
- case 2:
- conn->priv->original_char_name = g_strdup(mud_tuple[0]);
- conn->priv->original_name = g_strdup(mud_tuple[1]);
- break;
- }
-
- g_strfreev(mud_tuple);
- } else
- return;
+ GdkPixbuf *icon;
- name_strip = gconf_escape_key(conn->priv->original_name, -1);
+ self->icon_current = g_strdup (icon_name);
- gtk_entry_set_text(
- GTK_ENTRY(conn->priv->name_entry), conn->priv->original_name);
+ icon = gdk_pixbuf_new_from_file_at_size (self->icon_current, 48, 48, NULL);
+ gtk_image_set_from_pixbuf (GTK_IMAGE (self->icon_image), icon);
- if(conn->priv->original_char_name)
- gtk_entry_set_text(GTK_ENTRY(conn->priv->character_name_entry),
- conn->priv->original_char_name);
-
- client = gconf_client_get_default();
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/host", name_strip);
- buf = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- if(buf)
- {
- gtk_entry_set_text(GTK_ENTRY(conn->priv->host_entry), buf);
- g_free(buf);
- }
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/port", name_strip);
- port = gconf_client_get_int(client, key, NULL);
- g_free(key);
-
- if(port != 0)
- gtk_spin_button_set_value(
- GTK_SPIN_BUTTON(conn->priv->port_entry), port);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/profile", name_strip);
- buf = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- if(buf)
- {
- mud_connections_property_combo_get_index(conn, buf);
- g_free(buf);
- }
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/icon", name_strip);
- buf = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- if(buf && strcmp(buf, "gnome-mud") != 0)
- {
- GdkPixbuf *icon;
-
- conn->priv->icon_current = g_strdup(buf);
- g_free(buf);
-
- icon = gdk_pixbuf_new_from_file_at_size(
- conn->priv->icon_current, 48, 48, NULL);
- gtk_image_set_from_pixbuf(GTK_IMAGE(conn->priv->icon_image),
- icon);
-
- g_object_unref(icon);
+ g_object_unref (icon);
}
else
- conn->priv->icon_current = g_strdup("gnome-mud");
-
- if(conn->priv->original_char_name != NULL)
{
- char_strip = gconf_escape_key(conn->priv->original_char_name, -1);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters/%s/logon",
- name_strip, char_strip);
- buf = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- if(buf)
- {
- buffer =
- gtk_text_view_get_buffer(
- GTK_TEXT_VIEW(conn->priv->logon_textview));
- gtk_text_buffer_set_text(buffer, buf, strlen(buf));
- g_free(buf);
- }
-
- g_free(char_strip);
+ self->icon_current = g_strdup ("gnome-mud");
}
- g_free(name_strip);
-
- g_object_unref(client);
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->logon_textview));
+ gtk_text_buffer_set_text (buffer, connect_string, strlen (connect_string));
- conn->priv->changed = FALSE;
+ self->changed = FALSE;
}
static void
-mud_connections_property_cancel_cb(GtkWidget *widget, MudConnections *conn)
+mud_connections_property_cancel_cb (GtkWidget *widget,
+ MudConnections *self)
{
- gtk_widget_destroy(conn->priv->properties_window);
+ gtk_widget_destroy (self->properties_window);
}
static void
-mud_connections_property_save_cb(GtkWidget *widget, MudConnections *conn)
+mud_connections_property_save_cb (GtkWidget *widget,
+ MudConnections *self)
{
- if(mud_connections_property_save(conn))
- gtk_widget_destroy(conn->priv->properties_window);
+ if (mud_connections_property_save (self))
+ gtk_widget_destroy (self->properties_window);
}
+
static void
-mud_connections_property_icon_cb(GtkWidget *widget, MudConnections *conn)
+mud_connections_property_icon_cb (GtkWidget *widget,
+ MudConnections *self)
{
- mud_connections_show_icon_dialog(conn);
+ mud_connections_show_icon_dialog (self);
}
static gboolean
-mud_connections_property_changed_cb(GtkWidget *widget,
- GdkEventKey *event,
- MudConnections *conn)
+mud_connections_property_changed_cb (GtkWidget *widget,
+ GdkEventKey *event,
+ MudConnections *self)
{
- conn->priv->changed = TRUE;
+ self->changed = TRUE;
- return FALSE;
+ return FALSE;
}
static void
-mud_connections_property_combo_changed_cb(GtkWidget *widget,
- MudConnections *conn)
+mud_connections_property_combo_changed_cb (GtkWidget *widget,
+ MudConnections *self)
{
- conn->priv->changed = TRUE;
+ self->changed = TRUE;
}
static gboolean
-mud_connections_property_delete_cb(GtkWidget *widget,
- GdkEvent *event,
- MudConnections *conn)
+mud_connections_property_delete_cb (GtkWidget *widget,
+ GdkEvent *event,
+ MudConnections *self)
{
- if(conn->priv->changed)
- switch(mud_connections_property_confirm())
- {
- case -1:
- return FALSE;
- break;
- case 1:
- return mud_connections_property_save(conn);
- break;
- case 0:
- return TRUE;
- break;
- }
-
- return FALSE;
+ if (self->changed)
+ switch (mud_connections_property_confirm ())
+ {
+ case -1:
+ return FALSE;
+
+ case 1:
+ return mud_connections_property_save (self);
+
+ case 0:
+ return TRUE;
+ }
+
+ return FALSE;
}
static gint
-mud_connections_property_confirm(void)
+mud_connections_property_confirm (void)
{
- GtkBuilder *builder;
- GError *error = NULL;
- GtkWidget *dialog;
- gint result;
+ GtkBuilder *builder;
+ GError *error = NULL;
+ GtkWidget *dialog;
+ gint result;
- builder = gtk_builder_new();
- if(gtk_builder_add_from_file(builder, UIDIR "/muds.ui", &error) == 0)
- g_error("Failed to load: %s", error->message);
+ builder = gtk_builder_new ();
+ if (gtk_builder_add_from_file (builder, UIDIR "/muds.ui", &error) == 0)
+ g_error ("Failed to load: %s", error->message);
- dialog = GTK_WIDGET(gtk_builder_get_object(builder, "mudviewconfirm"));
- g_object_unref(builder);
+ dialog = GTK_WIDGET (gtk_builder_get_object (builder, "mudviewconfirm"));
+ g_object_unref (builder);
- result = gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
+ result = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
- switch(result)
+ switch (result)
{
case GTK_RESPONSE_OK:
- return 1;
- break;
+ return 1;
case GTK_RESPONSE_CLOSE:
- return -1;
- break;
+ return -1;
default:
- return 0;
- break;
+ return 0;
}
}
static gboolean
-mud_connections_property_save(MudConnections *conn)
+mud_connections_property_save (MudConnections *self)
{
- GConfClient *client;
- const gchar *name =
- gtk_entry_get_text(GTK_ENTRY(conn->priv->name_entry));
- const gchar *host =
- gtk_entry_get_text(GTK_ENTRY(conn->priv->host_entry));
- const gchar *character_name
- = gtk_entry_get_text(GTK_ENTRY(conn->priv->character_name_entry));
- gchar *logon, *profile, *key, *buf, *char_name,
- *stripped_name, *strip_name_new;
- GtkTextIter start, end;
- GtkTextBuffer *buffer;
- GtkTreeIter iter;
- GSList *chars, *entry;
-
- buffer =
- gtk_text_view_get_buffer(GTK_TEXT_VIEW(conn->priv->logon_textview));
- gtk_text_buffer_get_bounds(buffer, &start, &end);
- logon = gtk_text_iter_get_text(&start, &end);
-
- if(gtk_combo_box_get_active_iter(
- GTK_COMBO_BOX(conn->priv->profile_combo), &iter))
- gtk_tree_model_get(
- GTK_TREE_MODEL(conn->priv->profile_model),
- &iter, 0, &profile, -1);
- else
- profile = g_strdup("Default");
-
- if(strlen(name) == 0)
+ const gchar *mud_name, *hostname, *character_name;
+ gchar *logon;
+ MudProfile *profile;
+ MudCharacter *character;
+ MudMud *mud;
+ GtkTextIter start, end;
+ GtkTextBuffer *buffer;
+ GtkTreeIter iter;
+ guint port;
+
+ mud_name = gtk_entry_get_text (GTK_ENTRY (self->name_entry));
+
+ if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self->profile_combo), &iter))
{
- utils_error_message(conn->priv->properties_window, _("Error"),
- "%s", _("No MUD name specified."));
-
- g_free(logon);
- g_free(profile);
-
- return FALSE;
+ gtk_tree_model_get (GTK_TREE_MODEL (self->profile_model),
+ &iter, MODEL_PROFILE_OBJECT, &profile, -1);
}
-
- client = gconf_client_get_default();
-
- /* If the user renames the mud we need to
- * transfer over the old character information
- * and do some cleanup */
- if(conn->priv->original_name &&
- strcmp(conn->priv->original_name, name) != 0)
+ else
{
- stripped_name = gconf_escape_key(conn->priv->original_name, -1);
- strip_name_new = gconf_escape_key(name, -1);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters",
- stripped_name);
- chars = gconf_client_all_dirs(client, key, NULL);
- g_free(key);
-
- for(entry = chars; entry != NULL; entry = g_slist_next(entry))
- {
- char_name = g_path_get_basename((gchar *)entry->data);
-
- key = g_strdup_printf(
- "/apps/gnome-mud/muds/%s/characters/%s/logon",
- stripped_name, char_name);
- buf = gconf_client_get_string(client, key, NULL);
- g_free(key);
-
- key = g_strdup_printf(
- "/apps/gnome-mud/muds/%s/characters/%s/logon",
- strip_name_new, char_name);
- gconf_client_set_string(client, key, buf, NULL);
- g_free(key);
-
- g_free(char_name);
- g_free(buf);
- }
-
- for(entry = chars; entry != NULL; entry = g_slist_next(entry))
- g_free(entry->data);
- g_slist_free(chars);
-
- key = g_strdup_printf(
- "/apps/gnome-mud/muds/%s", stripped_name);
- gconf_client_recursive_unset(client, key, 0, NULL);
- g_free(key);
-
- g_free(stripped_name);
- g_free(strip_name_new);
+ utils_error_message (self->properties_window, _("Error"),
+ "%s", _("No profile specified."));
+ return FALSE;
}
- stripped_name = gconf_escape_key(name, -1);
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/name", stripped_name);
- gconf_client_set_string(client, key, name, NULL);
- g_free(key);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/host", stripped_name);
- gconf_client_set_string(client, key, host, NULL);
- g_free(key);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/port", stripped_name);
- gconf_client_set_int(client, key,
- gtk_spin_button_get_value_as_int(
- GTK_SPIN_BUTTON(conn->priv->port_entry)),
- NULL);
- g_free(key);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/icon", stripped_name);
- if(conn->priv->icon_current &&
- strcmp(conn->priv->icon_current, "gnome-mud") != 0)
- gconf_client_set_string(
- client, key, conn->priv->icon_current, NULL);
- else
- gconf_client_set_string(client, key, "gnome-mud", NULL);
- g_free(key);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/profile", stripped_name);
- gconf_client_set_string(client, key, profile, NULL);
- g_free(key);
-
- if(conn->priv->original_char_name &&
- strcmp(conn->priv->original_char_name, character_name) != 0)
+ if (mud_name[0] == '\0')
{
- strip_name_new = gconf_escape_key(conn->priv->original_char_name, -1);
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters/%s",
- stripped_name, strip_name_new);
- gconf_client_recursive_unset(client, key, 0, NULL);
- g_free(key);
- g_free(strip_name_new);
+ utils_error_message (self->properties_window, _("Error"),
+ "%s", _("No MUD name specified."));
+ return FALSE;
}
- strip_name_new = gconf_escape_key(character_name, -1);
+ character = g_object_get_data (G_OBJECT (self->properties_window), "current-character");
+
+ hostname = gtk_entry_get_text (GTK_ENTRY (self->host_entry));
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->logon_textview));
+ gtk_text_buffer_get_bounds (buffer, &start, &end);
+ character_name = gtk_entry_get_text (GTK_ENTRY (self->character_name_entry));
+ logon = gtk_text_iter_get_text (&start, &end);
+ port = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (self->port_entry));
- if(strlen(strip_name_new) > 0)
+ if (character == NULL)
{
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters/%s/logon",
- stripped_name, strip_name_new);
- gconf_client_set_string(client, key, logon, NULL);
- g_free(key);
-
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters/%s/name",
- stripped_name, strip_name_new);
- gconf_client_set_string(client, key, character_name, NULL);
- g_free(key);
+ /* New character */
+ /* TODO: Associate with existing MUD entry if possible (depends on dialog redesign) */
+ mud = mud_profile_manager_add_mud (self->parent_window->profile_manager, mud_name, hostname, port);
+ character = mud_profile_manager_add_character (self->parent_window->profile_manager, profile, mud,
character_name, logon, self->icon_current);
+ }
+ else
+ {
+ g_object_get (character,
+ "mud", &mud,
+ NULL);
+
+ mud_character_set_name (character, character_name);
+ mud_character_set_connect_string (character, logon);
+ mud_character_set_icon (character, self->icon_current);
+ /* TODO: mud_character_set_profile (character, profile); */
+ /* FIXME: These change the MUD for all character, but that's how it worked with gconf too - to be
redesigned */
+ mud_mud_set_name (mud, mud_name);
+ mud_mud_set_hostname (mud, hostname);
+ mud_mud_set_port (mud, port);
}
- g_object_unref(client);
-
- g_free(logon);
- g_free(profile);
+ g_free (logon);
- return TRUE;
+ return TRUE;
}
static void
-mud_connections_property_populate_profiles(MudConnections *conn)
+mud_connections_property_populate_profiles (MudConnections *self)
{
- const GSList *profiles, *entry;
- GtkTreeIter iter;
+ GSequence *profiles;
+ GtkTreeIter iter;
+ GSequenceIter *seqiter;
- profiles = mud_profile_manager_get_profiles(conn->parent_window->profile_manager);
+ profiles = mud_profile_manager_get_profiles (self->parent_window->profile_manager);
- conn->priv->profile_model =
- GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_STRING));
+ self->profile_model = GTK_TREE_MODEL (gtk_list_store_new (MODEL_PROFILE_N, G_TYPE_STRING,
MUD_TYPE_PROFILE));
- for(entry = profiles; entry != NULL; entry = g_slist_next(entry))
+ for (seqiter = g_sequence_get_begin_iter (profiles);
+ !g_sequence_iter_is_end (seqiter);
+ seqiter = g_sequence_iter_next (seqiter))
{
- MudProfile *profile = MUD_PROFILE(entry->data);
- gtk_list_store_append(
- GTK_LIST_STORE(conn->priv->profile_model), &iter);
- gtk_list_store_set(GTK_LIST_STORE(conn->priv->profile_model), &iter,
- 0, profile->name, -1);
+ MudProfile *profile = g_sequence_get (seqiter);
+ gtk_list_store_append (GTK_LIST_STORE (self->profile_model), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (self->profile_model), &iter,
+ MODEL_PROFILE_NAME, profile->visible_name,
+ MODEL_PROFILE_OBJECT, profile, -1);
}
}
static void
-mud_connections_property_combo_get_index(MudConnections *conn,
- gchar *profile)
+mud_connections_property_set_profile (MudConnections *self,
+ const MudProfile *profile)
{
- gchar *buf;
- GtkTreeIter iter;
+ MudProfile *iterated_profile;
+ GtkTreeIter iter;
- gtk_tree_model_get_iter_first(conn->priv->profile_model, &iter);
+ gtk_tree_model_get_iter_first(self->profile_model, &iter);
- do
+ do
{
- gtk_tree_model_get(conn->priv->profile_model, &iter, 0, &buf, -1);
-
- if(strcmp(buf, profile) == 0)
- {
- gtk_combo_box_set_active_iter(
- GTK_COMBO_BOX(conn->priv->profile_combo),
- &iter);
- g_free(buf);
- return;
- }
-
- g_free(buf);
+ gtk_tree_model_get(self->profile_model, &iter, MODEL_PROFILE_OBJECT, &iterated_profile, -1);
+
+ if (iterated_profile == profile)
+ {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self->profile_combo), &iter);
+ return;
+ }
}
- while(gtk_tree_model_iter_next(conn->priv->profile_model, &iter));
+ while (gtk_tree_model_iter_next (self->profile_model, &iter));
}
// Iconview Dialog
static void
-mud_connections_show_icon_dialog(MudConnections *conn)
+mud_connections_show_icon_dialog (MudConnections *self)
{
- GtkBuilder *builder;
- GError *error = NULL;
- gint result;
-
- builder = gtk_builder_new();
- if(gtk_builder_add_from_file(builder, UIDIR "/muds.ui", &error) == 0)
- g_error("Failed to load: %s", error->message);
-
- conn->priv->icon_dialog = GTK_WIDGET(gtk_builder_get_object(builder, "iconselect"));
- conn->priv->icon_dialog_view = GTK_WIDGET(gtk_builder_get_object(builder, "view"));
- conn->priv->icon_dialog_chooser = GTK_WIDGET(gtk_builder_get_object(builder, "chooser"));
- g_object_unref(builder);
-
- conn->priv->icon_dialog_view_model =
- GTK_TREE_MODEL(gtk_list_store_new(MODEL_COLUMN_N,
- G_TYPE_STRING,
- GDK_TYPE_PIXBUF));
-
- gtk_icon_view_set_model(GTK_ICON_VIEW(conn->priv->icon_dialog_view),
- conn->priv->icon_dialog_view_model);
- gtk_icon_view_set_text_column(
- GTK_ICON_VIEW(conn->priv->icon_dialog_view),
- MODEL_COLUMN_STRING);
- gtk_icon_view_set_pixbuf_column(
- GTK_ICON_VIEW(conn->priv->icon_dialog_view),
- MODEL_COLUMN_PIXBUF);
-
- g_free(conn->priv->icon_current);
- conn->priv->icon_current = NULL;
-
- g_signal_connect(
- conn->priv->icon_dialog_chooser, "current-folder-changed",
- G_CALLBACK(mud_connections_icon_fileset_cb),
- conn);
- g_signal_connect(conn->priv->icon_dialog_view, "selection-changed",
- G_CALLBACK(mud_connections_icon_select_cb),
- conn);
-
- g_object_set(conn->priv->icon_dialog_view, "item-width", 64, NULL);
- gtk_file_chooser_set_current_folder(
- GTK_FILE_CHOOSER(conn->priv->icon_dialog_chooser),
- "/usr/share/icons");
-
- result = gtk_dialog_run(GTK_DIALOG(conn->priv->icon_dialog));
- gtk_widget_destroy(conn->priv->icon_dialog);
-
- if(result == GTK_RESPONSE_OK)
+ GtkBuilder *builder;
+ GError *error = NULL;
+ gint result;
+
+ builder = gtk_builder_new ();
+ if (gtk_builder_add_from_file (builder, UIDIR "/muds.ui", &error) == 0)
+ g_error ("Failed to load: %s", error->message);
+
+ self->icon_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "iconselect"));
+ self->icon_dialog_view = GTK_WIDGET (gtk_builder_get_object (builder, "view"));
+ self->icon_dialog_chooser = GTK_WIDGET (gtk_builder_get_object (builder, "chooser"));
+ g_object_unref (builder);
+
+ self->icon_dialog_view_model =
+ GTK_TREE_MODEL (gtk_list_store_new (MODEL_ICON_N,
+ G_TYPE_STRING,
+ GDK_TYPE_PIXBUF));
+
+ gtk_icon_view_set_model (GTK_ICON_VIEW (self->icon_dialog_view),
+ self->icon_dialog_view_model);
+ gtk_icon_view_set_text_column (GTK_ICON_VIEW (self->icon_dialog_view),
+ MODEL_ICON_NAME);
+ gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (self->icon_dialog_view),
+ MODEL_ICON_PIXBUF);
+
+ g_clear_pointer (&self->icon_current, g_free);
+
+ g_signal_connect (self->icon_dialog_chooser, "current-folder-changed",
+ G_CALLBACK (mud_connections_icon_fileset_cb),
+ self);
+ g_signal_connect (self->icon_dialog_view, "selection-changed",
+ G_CALLBACK (mud_connections_icon_select_cb),
+ self);
+
+ g_object_set (self->icon_dialog_view, "item-width", 64, NULL);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (self->icon_dialog_chooser),
+ "/usr/share/icons");
+
+ result = gtk_dialog_run (GTK_DIALOG(self->icon_dialog));
+ gtk_widget_destroy (self->icon_dialog);
+
+ if (result == GTK_RESPONSE_OK)
{
- if(conn->priv->icon_current == NULL)
- return;
-
- GdkPixbuf *icon = gdk_pixbuf_new_from_file_at_size(
- conn->priv->icon_current, 48, 48, NULL);
- gtk_image_set_from_pixbuf(GTK_IMAGE(conn->priv->icon_image),
- icon);
- g_object_unref(icon);
+ if (self->icon_current == NULL)
+ return;
+
+ GdkPixbuf *icon = gdk_pixbuf_new_from_file_at_size (self->icon_current,
+ 48, 48, NULL);
+ gtk_image_set_from_pixbuf (GTK_IMAGE (self->icon_image),
+ icon);
+ g_object_unref(icon);
}
}
void
-mud_connections_icon_fileset_cb(GtkFileChooserButton *chooser,
- MudConnections *conn)
+mud_connections_icon_fileset_cb (GtkFileChooserButton *chooser,
+ MudConnections *self)
{
- const gchar *file;
- gchar *current_folder =
- gtk_file_chooser_get_current_folder(
- GTK_FILE_CHOOSER(conn->priv->icon_dialog_chooser));
- GDir *dir = g_dir_open(current_folder ,0, NULL);
- GPatternSpec *xpm_pattern = g_pattern_spec_new("*.xpm");
- GPatternSpec *svg_pattern = g_pattern_spec_new("*.svg");
- GPatternSpec *bmp_pattern = g_pattern_spec_new("*.bmp");
- GPatternSpec *png_pattern = g_pattern_spec_new("*.png");
-
- gtk_list_store_clear(
- GTK_LIST_STORE(conn->priv->icon_dialog_view_model));
-
- while( (file = g_dir_read_name(dir) ) != NULL)
- if( g_pattern_match_string(xpm_pattern, file) ||
- g_pattern_match_string(svg_pattern, file) ||
- g_pattern_match_string(bmp_pattern, file) ||
- g_pattern_match_string(png_pattern, file))
- {
- gchar *full_path = g_strconcat(current_folder,
- G_DIR_SEPARATOR_S,
- file, NULL);
- GdkPixbuf *icon = gdk_pixbuf_new_from_file_at_size(
- full_path, 48, 48, NULL);
- GtkTreeIter iter;
-
- if(icon)
- {
- gtk_list_store_append(
- GTK_LIST_STORE(conn->priv->icon_dialog_view_model),
- &iter);
- gtk_list_store_set(
- GTK_LIST_STORE(conn->priv->icon_dialog_view_model),
- &iter,
- MODEL_COLUMN_STRING, file,
- MODEL_COLUMN_PIXBUF, icon,
- -1);
-
- g_object_unref(icon);
- }
-
- g_free(full_path);
- }
-
- g_free(current_folder);
- g_dir_close(dir);
- g_pattern_spec_free(xpm_pattern);
- g_pattern_spec_free(svg_pattern);
- g_pattern_spec_free(bmp_pattern);
- g_pattern_spec_free(png_pattern);
+ const gchar *file;
+ gchar *current_folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (self->icon_dialog_chooser));
+ GDir *dir = g_dir_open (current_folder, 0, NULL);
+ GPatternSpec *xpm_pattern = g_pattern_spec_new ("*.xpm");
+ GPatternSpec *svg_pattern = g_pattern_spec_new ("*.svg");
+ GPatternSpec *bmp_pattern = g_pattern_spec_new ("*.bmp");
+ GPatternSpec *png_pattern = g_pattern_spec_new ("*.png");
+
+ gtk_list_store_clear (GTK_LIST_STORE (self->icon_dialog_view_model));
+
+ while ( (file = g_dir_read_name (dir) ) != NULL)
+ if (g_pattern_match_string (xpm_pattern, file) ||
+ g_pattern_match_string (svg_pattern, file) ||
+ g_pattern_match_string (bmp_pattern, file) ||
+ g_pattern_match_string (png_pattern, file))
+ {
+ gchar *full_path = g_strconcat (current_folder, G_DIR_SEPARATOR_S, file, NULL);
+ GdkPixbuf *icon = gdk_pixbuf_new_from_file_at_size (full_path, 48, 48, NULL);
+ GtkTreeIter iter;
+
+ if (icon)
+ {
+ gtk_list_store_append (GTK_LIST_STORE (self->icon_dialog_view_model),
+ &iter);
+ gtk_list_store_set (GTK_LIST_STORE (self->icon_dialog_view_model),
+ &iter,
+ MODEL_ICON_NAME, file,
+ MODEL_ICON_PIXBUF, icon,
+ -1);
+
+ g_object_unref (icon);
+ }
+
+ g_free (full_path);
+ }
+
+ g_free (current_folder);
+ g_dir_close (dir);
+ g_pattern_spec_free (xpm_pattern);
+ g_pattern_spec_free (svg_pattern);
+ g_pattern_spec_free (bmp_pattern);
+ g_pattern_spec_free (png_pattern);
}
static void
-mud_connections_icon_select_cb(GtkIconView *view, MudConnections *conn)
+mud_connections_icon_select_cb (GtkIconView *view,
+ MudConnections *self)
{
- GList *selected =
- gtk_icon_view_get_selected_items(
- GTK_ICON_VIEW(conn->priv->icon_dialog_view));
- GtkTreeIter iter;
- gchar *buf;
+ GList *selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (self->icon_dialog_view));
+ GtkTreeIter iter;
+ gchar *buf;
- if(g_list_length(selected) == 0)
- return;
+ if (g_list_length (selected) == 0)
+ return;
- gtk_tree_model_get_iter(conn->priv->icon_dialog_view_model,
- &iter, (GtkTreePath *)selected->data);
- gtk_tree_model_get(conn->priv->icon_dialog_view_model,
- &iter, 0, &buf, -1);
+ gtk_tree_model_get_iter (self->icon_dialog_view_model,
+ &iter,
+ (GtkTreePath *)selected->data);
+ gtk_tree_model_get (self->icon_dialog_view_model,
+ &iter,
+ MODEL_ICON_NAME, &buf,
+ -1);
- g_free(conn->priv->icon_current);
+ g_free (self->icon_current);
- conn->priv->icon_current = g_strconcat(
- gtk_file_chooser_get_current_folder(
- GTK_FILE_CHOOSER(conn->priv->icon_dialog_chooser)),
- G_DIR_SEPARATOR_S,
- buf, NULL);
+ self->icon_current = g_strconcat (gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER
(self->icon_dialog_chooser)),
+ G_DIR_SEPARATOR_S,
+ buf, NULL);
- g_free(buf);
+ g_free (buf);
- g_list_foreach(selected, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(selected);
+ g_list_foreach (selected, (GFunc)gtk_tree_path_free, NULL);
+ g_list_free (selected);
}
+static void
+mud_connections_constructed (GObject *object)
+{
+ MudConnections *self = (MudConnections *)object;
+
+ GtkBuilder *builder;
+ GError *error = NULL;
+ GtkWidget *main_window;
+
+ G_OBJECT_CLASS (mud_connections_parent_class)->constructed (object);
+
+ g_object_get (self->parent_window,
+ "window", &self->winwidget,
+ "tray", &self->tray,
+ NULL);
+
+ builder = gtk_builder_new ();
+ if (gtk_builder_add_from_file (builder, UIDIR "/muds.ui", &error) == 0)
+ g_error ("Failed to load: %s", error->message);
+
+ self->window = GTK_WIDGET (gtk_builder_get_object (builder, "mudviewwindow"));
+ self->iconview = GTK_WIDGET (gtk_builder_get_object (builder, "iconview"));
+
+ self->qconnect_host_entry =
+ GTK_WIDGET (gtk_builder_get_object (builder, "qconnect_host_entry"));
+ self->qconnect_port_entry =
+ GTK_WIDGET (gtk_builder_get_object (builder, "qconnect_port_entry"));
+ self->qconnect_connect_button =
+ GTK_WIDGET (gtk_builder_get_object (builder, "qconnect_connect_button"));
+
+ self->icon_model = GTK_TREE_MODEL (gtk_list_store_new (MODEL_COLUMN_N,
+ G_TYPE_STRING,
+ GDK_TYPE_PIXBUF,
+ MUD_TYPE_CHARACTER));
+
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self->icon_model),
+ MODEL_COLUMN_VISIBLE_NAME,
+ GTK_SORT_ASCENDING);
+
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self->icon_model),
+ MODEL_COLUMN_VISIBLE_NAME,
+ mud_connections_compare_func,
+ NULL,
+ NULL);
+
+ gtk_icon_view_set_model (GTK_ICON_VIEW (self->iconview), self->icon_model);
+ g_object_unref (self->icon_model);
+
+ gtk_icon_view_set_text_column (GTK_ICON_VIEW(self->iconview), MODEL_COLUMN_VISIBLE_NAME);
+ gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW(self->iconview), MODEL_COLUMN_PIXBUF);
+
+#warning Hook in iconview update watchers
+
+ g_signal_connect (self->iconview, "item-activated",
+ G_CALLBACK (mud_connections_iconview_activate_cb),
+ self);
+ g_signal_connect (self->iconview, "button-press-event",
+ G_CALLBACK (mud_connections_button_press_cb),
+ self);
+ g_signal_connect (self->window, "destroy",
+ G_CALLBACK (mud_connections_close_cb), self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "connect_button")),
+ "clicked", G_CALLBACK (mud_connections_connect_cb), self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "add_button")),
+ "clicked", G_CALLBACK (mud_connections_add_cb), self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "delete_button")),
+ "clicked", G_CALLBACK (mud_connections_delete_cb), self);
+ g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "properties_button")),
+ "clicked", G_CALLBACK (mud_connections_properties_cb), self);
+ g_signal_connect (self->qconnect_connect_button, "clicked",
+ G_CALLBACK (mud_connections_qconnect_cb), self);
+
+ mud_connections_populate_iconview (self);
+
+ g_object_get (self->parent_window, "window", &main_window, NULL);
+
+ g_object_set (self->window,
+ "transient-for", GTK_WINDOW (main_window),
+ NULL);
+
+ gtk_widget_show_all (self->window);
+ g_object_unref (builder);
+}
+
+static void
+mud_connections_finalize (GObject *object)
+{
+ MudConnections *self = (MudConnections *)object;
+
+ /* TODO */
+
+ G_OBJECT_CLASS (mud_connections_parent_class)->finalize (object);
+}
+
+static void
+mud_connections_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MudConnections *self;
+
+ self = MUD_CONNECTIONS (object);
+
+ switch (prop_id)
+ {
+ case PROP_PARENT_WINDOW:
+ g_value_take_object (value, self->parent_window);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+mud_connections_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MudConnections *self = MUD_CONNECTIONS (object);
+
+ switch (prop_id)
+ {
+ case PROP_PARENT_WINDOW:
+ self->parent_window = MUD_WINDOW (g_value_get_object(value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+mud_connections_class_init (MudConnectionsClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = mud_connections_constructed;
+ object_class->finalize = mud_connections_finalize;
+ object_class->get_property = mud_connections_get_property;
+ object_class->set_property = mud_connections_set_property;
+
+ /* TODO: Singleton MudWindow? */
+ properties [PROP_PARENT_WINDOW] =
+ g_param_spec_object("parent-window",
+ "parent mud window",
+ "the mud window the connections is attached to",
+ MUD_TYPE_WINDOW,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+mud_connections_init (MudConnections *self)
+{
+}
diff --git a/src/mud-connections.h b/src/mud-connections.h
index 91408b9..de244e3 100644
--- a/src/mud-connections.h
+++ b/src/mud-connections.h
@@ -1,10 +1,10 @@
-/* GNOME-Mud - A simple Mud Client
- * mud-connections.h
- * Copyright (C) 2008-2009 Les Harris <lharris gnome org>
+/* mud-connections.h
*
- * This program is free software; you can redistribute it and/or modify
+ * Copyright 2018 Mart Raudsepp <leio gentoo org>
+ *
+ * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@@ -13,48 +13,18 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
-#ifndef MUD_CONNECTIONS_H
-#define MUD_CONNECTIONS_H
-
-G_BEGIN_DECLS
-
-#include "mud-window.h"
-
-#define MUD_TYPE_CONNECTIONS (mud_connections_get_type ())
-#define MUD_CONNECTIONS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MUD_TYPE_CONNECTIONS,
MudConnections))
-#define MUD_CONNECTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MUD_TYPE_CONNECTIONS,
MudConnectionsClass))
-#define MUD_IS_CONNECTIONS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MUD_TYPE_CONNECTIONS))
-#define MUD_IS_CONNECTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MUD_TYPE_CONNECTIONS))
-#define MUD_CONNECTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MUD_TYPE_CONNECTIONS,
MudConnectionsClass))
-#define MUD_CONNECTIONS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MUD_TYPE_CONNECTIONS,
MudConnectionsPrivate))
+#pragma once
-typedef struct _MudConnections MudConnections;
-typedef struct _MudConnectionsClass MudConnectionsClass;
-typedef struct _MudConnectionsPrivate MudConnectionsPrivate;
+#include <glib-object.h>
-struct _MudConnectionsClass
-{
- GObjectClass parent_class;
-};
-
-struct _MudConnections
-{
- GObject parent_instance;
-
- /*< private >*/
- MudConnectionsPrivate *priv;
-
- /*< public >*/
- MudWindow *parent_window;
-};
+G_BEGIN_DECLS
-GType mud_connections_get_type (void);
+#define MUD_TYPE_CONNECTIONS (mud_connections_get_type ())
+G_DECLARE_FINAL_TYPE (MudConnections, mud_connections, MUD, CONNECTIONS, GObject); /* TODO: Inherit from the
used widget type instead, to extend it, instead of parallel control of it? */
G_END_DECLS
-
-#endif // MUD_CONNECTIONS_H
-
diff --git a/src/mud-log.h b/src/mud-log.h
index 5df74d4..a25fa54 100644
--- a/src/mud-log.h
+++ b/src/mud-log.h
@@ -22,8 +22,6 @@
G_BEGIN_DECLS
-#include <gconf/gconf-client.h>
-
#define MUD_TYPE_LOG (mud_log_get_type ())
#define MUD_LOG(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MUD_TYPE_LOG, MudLog))
#define MUD_LOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MUD_TYPE_LOG, MudLogClass))
diff --git a/src/mud-mud.c b/src/mud-mud.c
new file mode 100644
index 0000000..5d185e1
--- /dev/null
+++ b/src/mud-mud.c
@@ -0,0 +1,276 @@
+/* mud-mud.c
+ *
+ * Copyright 2018 Mart Raudsepp <leio gentoo org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "mud-mud.h"
+
+#include <gio/gio.h>
+
+struct _MudMud
+{
+ GObject parent_instance;
+
+ gchar *id;
+ gchar *name;
+ gchar *hostname;
+ guint port;
+ GSettings *settings;
+};
+
+G_DEFINE_TYPE (MudMud, mud_mud, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_ID,
+ PROP_NAME,
+ PROP_HOSTNAME,
+ PROP_PORT,
+ N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+MudMud *
+mud_mud_new (const gchar *id)
+{
+ return g_object_new (MUD_TYPE_MUD, "id", id, NULL);
+}
+
+const gchar *
+mud_mud_get_id (MudMud *self)
+{
+ g_return_val_if_fail (MUD_IS_MUD (self), NULL);
+
+ return self->id;
+}
+
+const gchar *
+mud_mud_get_name (MudMud *self)
+{
+ g_return_val_if_fail (MUD_IS_MUD (self), NULL);
+
+ return self->name;
+}
+
+void
+mud_mud_set_name (MudMud *self, const gchar *name)
+{
+ g_return_if_fail (MUD_IS_MUD (self));
+
+ if (g_strcmp0 (self->name, name) != 0)
+ {
+ g_free (self->name);
+ self->name = g_strdup (name);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NAME]);
+ }
+}
+
+const gchar *
+mud_mud_get_hostname (MudMud *self)
+{
+ g_return_val_if_fail (MUD_IS_MUD (self), NULL);
+
+ return self->hostname;
+}
+
+void
+mud_mud_set_hostname (MudMud *self, const gchar *hostname)
+{
+ g_return_if_fail (MUD_IS_MUD (self));
+
+ if (g_strcmp0 (self->hostname, hostname) != 0)
+ {
+ g_free (self->hostname);
+ self->hostname = g_strdup (hostname);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HOSTNAME]);
+ }
+}
+
+const guint
+mud_mud_get_port (MudMud *self)
+{
+ g_return_val_if_fail (MUD_IS_MUD (self), 23);
+
+ return self->port;
+}
+
+void
+mud_mud_set_port (MudMud *self,
+ const guint port)
+{
+ g_return_if_fail (MUD_IS_MUD (self));
+
+ self->port = port;
+}
+
+gint
+mud_mud_compare (const MudMud *mud1, const MudMud *mud2)
+{
+ return g_strcmp0 (mud1->id, mud2->id);
+}
+
+static void
+mud_mud_constructed (GObject *object)
+{
+ gchar *mud_path;
+ MudMud *self = (MudMud *)object;
+
+ G_OBJECT_CLASS (mud_mud_parent_class)->constructed (object);
+
+ /* TODO: Change ID property to default to G_MAXUINT64 and figure out a new ID to use here, instead of
caller having to do it */
+
+ mud_path = g_strdup_printf("/org/gnome/MUD/MUDs/%s/", self->id);
+ self->settings = g_settings_new_with_path("org.gnome.MUD.Mud", mud_path);
+ g_settings_bind(self->settings,
+ "name",
+ self, "name",
+ G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_NO_SENSITIVITY);
+ g_settings_bind(self->settings,
+ "hostname",
+ self, "hostname",
+ G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_NO_SENSITIVITY);
+ g_settings_bind(self->settings,
+ "port",
+ self, "port",
+ G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_NO_SENSITIVITY);
+ g_free (mud_path);
+}
+
+static void
+mud_mud_finalize (GObject *object)
+{
+ MudMud *self = (MudMud *)object;
+
+ g_object_unref(self->settings); /* TODO: Shouldn't this be done in dispose? */
+ g_clear_pointer(&self->name, g_free);
+ g_clear_pointer(&self->hostname, g_free);
+
+ G_OBJECT_CLASS (mud_mud_parent_class)->finalize (object);
+}
+
+static void
+mud_mud_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MudMud *self = MUD_MUD (object);
+
+ switch (prop_id)
+ {
+ case PROP_ID:
+ g_value_set_string (value, mud_mud_get_id (self));
+ break;
+
+ case PROP_NAME:
+ g_value_set_string (value, mud_mud_get_name (self));
+ break;
+
+ case PROP_HOSTNAME:
+ g_value_set_string (value, mud_mud_get_hostname (self));
+ break;
+
+ case PROP_PORT:
+ g_value_set_uint (value, mud_mud_get_port (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+mud_mud_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MudMud *self = MUD_MUD (object);
+
+ switch (prop_id)
+ {
+ case PROP_ID:
+ self->id = g_strdup (g_value_get_string (value));
+ break;
+
+ case PROP_NAME:
+ mud_mud_set_name (self, g_value_get_string (value));
+ break;
+
+ case PROP_HOSTNAME:
+ mud_mud_set_hostname (self, g_value_get_string (value));
+ break;
+
+ case PROP_PORT:
+ mud_mud_set_port (self, g_value_get_uint (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+mud_mud_class_init (MudMudClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = mud_mud_constructed;
+ object_class->finalize = mud_mud_finalize;
+ object_class->get_property = mud_mud_get_property;
+ object_class->set_property = mud_mud_set_property;
+
+ /* Create and Install Properties */
+ properties [PROP_ID] =
+ g_param_spec_string ("id",
+ "ID",
+ "The ID of the MUD.",
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_NAME] =
+ g_param_spec_string ("name",
+ "Name",
+ "The visible name of the MUD.",
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); /* TODO:
Debug how things differ with EXPLICIT_NOTIFY vs not and notify_by_pspec call existing or not */
+ properties [PROP_HOSTNAME] =
+ g_param_spec_string ("hostname",
+ "Hostname",
+ "The hostname of the MUD.",
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); /* TODO:
Debug how things differ with EXPLICIT_NOTIFY vs not and notify_by_pspec call existing or not */
+ properties [PROP_PORT] =
+ g_param_spec_uint ("port",
+ "Port",
+ "The port of the MUD",
+ 0, G_MAXUINT, 23,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+mud_mud_init (MudMud *self)
+{
+}
diff --git a/src/mud-mud.h b/src/mud-mud.h
new file mode 100644
index 0000000..c0a0c61
--- /dev/null
+++ b/src/mud-mud.h
@@ -0,0 +1,46 @@
+/* mud-mud.h
+ *
+ * Copyright 2018 Mart Raudsepp <leio gentoo org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MUD_TYPE_MUD (mud_mud_get_type())
+
+G_DECLARE_FINAL_TYPE (MudMud, mud_mud, MUD, MUD, GObject);
+
+MudMud *mud_mud_new (const gchar *id);
+const gchar *mud_mud_get_id (MudMud *self);
+const gchar *mud_mud_get_name (MudMud *self);
+void mud_mud_set_name (MudMud *self,
+ const gchar *name);
+const gchar *mud_mud_get_hostname (MudMud *self);
+void mud_mud_set_hostname (MudMud *self,
+ const gchar *hostname);
+const guint mud_mud_get_port (MudMud *self);
+void mud_mud_set_port (MudMud *self,
+ const guint port);
+gint mud_mud_compare (const MudMud *mud1,
+ const MudMud *mud2);
+
+
+G_END_DECLS
diff --git a/src/mud-parse-alias.c b/src/mud-parse-alias.c
index 2a95da7..81fb66b 100644
--- a/src/mud-parse-alias.c
+++ b/src/mud-parse-alias.c
@@ -24,7 +24,6 @@
#include <glib-object.h>
#include <glib/gi18n.h>
#include <string.h>
-#include <gconf/gconf-client.h>
#include <glib/gprintf.h>
#include "mud-parse-base.h"
@@ -186,11 +185,9 @@ mud_parse_alias_get_property(GObject *object,
gboolean
mud_parse_alias_do(MudParseAlias *self, gchar *data)
{
- gchar *profile_name;
gchar *actions;
gchar *regexstr;
GSList *aliases, *entry;
- GConfClient *client;
GError *error = NULL;
gchar keyname[2048];
gint enabled;
@@ -202,17 +199,13 @@ mud_parse_alias_do(MudParseAlias *self, gchar *data)
if(!MUD_IS_PARSE_ALIAS(self))
return FALSE;
- client = gconf_client_get_default();
-
g_object_get(self->priv->parent,
"parent-view", &view,
"regex", ®ex,
NULL);
- g_object_get(view,
- "profile-name", &profile_name,
- NULL);
-
+#warning reimplement
+#if 0
g_snprintf(keyname, 2048, "/apps/gnome-mud/profiles/%s/aliases/list", profile_name);
aliases = gconf_client_get_list(client, keyname, GCONF_VALUE_STRING, &error);
@@ -252,10 +245,7 @@ mud_parse_alias_do(MudParseAlias *self, gchar *data)
if(aliases)
g_slist_free(aliases);
-
- g_free(profile_name);
-
- g_object_unref(client);
+#endif
return send_line;
}
diff --git a/src/mud-parse-trigger.c b/src/mud-parse-trigger.c
index dc221c4..de2d20a 100644
--- a/src/mud-parse-trigger.c
+++ b/src/mud-parse-trigger.c
@@ -21,7 +21,6 @@
# include "config.h"
#endif
-#include <gconf/gconf-client.h>
#include <glib-object.h>
#include <glib/gi18n.h>
#include <string.h>
@@ -193,7 +192,6 @@ mud_parse_trigger_do(MudParseTrigger *self, gchar *data)
gchar *regexstr;
gchar *stripped_data;
GSList *triggers, *entry;
- GConfClient *client;
GError *error = NULL;
gchar keyname[2048];
gint enabled;
@@ -206,8 +204,6 @@ mud_parse_trigger_do(MudParseTrigger *self, gchar *data)
if(!MUD_IS_PARSE_TRIGGER(self))
return FALSE;
- client = gconf_client_get_default();
-
g_object_get(self->priv->parent,
"parent-view", &view,
"regex", ®ex,
@@ -217,6 +213,8 @@ mud_parse_trigger_do(MudParseTrigger *self, gchar *data)
"profile-name", &profile_name,
NULL);
+#warning Reimplement
+#if 0
g_snprintf(keyname, 2048, "/apps/gnome-mud/profiles/%s/triggers/list", profile_name);
triggers = gconf_client_get_list(client, keyname, GCONF_VALUE_STRING, &error);
@@ -265,8 +263,7 @@ mud_parse_trigger_do(MudParseTrigger *self, gchar *data)
if(triggers)
g_slist_free(triggers);
-
- g_object_unref(client);
+#endif
g_free(profile_name);
diff --git a/src/mud-profile-manager.c b/src/mud-profile-manager.c
index 4cd20bd..c3864c1 100644
--- a/src/mud-profile-manager.c
+++ b/src/mud-profile-manager.c
@@ -1,6 +1,7 @@
/* GNOME-Mud - A simple Mud Client
* mud-profile-manager.c
* Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ * Copyright (C) 2018 Mart Raudsepp <leio gentoo org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,13 +30,22 @@
#include "mud-window.h"
#include "mud-profile-manager.h"
#include "mud-connection-view.h"
+#include "mud-character.h"
+#include "mud-mud.h"
+/* TODO: This now manages not only profiles, but also the list of known MUDs and characters; so either
rename it all to more appropriate, or at some point refactor it into nicer small structs or singleton objects
*/
+
+/* TODO: Move to G_DEFINE_TYPE and G_DECLARE_FINAL_TYPE (no private if possible) */
struct _MudProfileManagerPrivate
{
- GSList *profiles;
+ GSequence *profiles;
+ GSequence *muds;
+ GSequence *characters;
MudWindow *parent;
};
+static MudProfileManager * manager_singleton = NULL; /* TODO: Just return this if possible in our still to
be created mud_profile_manager_init too */
+
/* Property Identifiers */
enum
{
@@ -64,6 +74,21 @@ static void mud_profile_manager_get_property(GObject *object,
/* Private Methods */
static void mud_profile_manager_load_profiles (MudProfileManager *self);
+static void mud_profile_manager_load_muds (MudProfileManager *self);
+static void mud_profile_manager_load_characters (MudProfileManager *self);
+
+static gint
+mud_profile_compare_func(MudProfile *profile1, MudProfile *profile2, gpointer userdata)
+{
+ if (profile1->id < profile2->id)
+ return -1;
+ else if (profile1->id > profile2->id)
+ return 1;
+ else {
+ g_assert_not_reached();
+ return 0;
+ }
+}
/* MudProfileManager class functions */
static void
@@ -102,35 +127,43 @@ mud_profile_manager_init (MudProfileManager *self)
self->priv = MUD_PROFILE_MANAGER_GET_PRIVATE(self);
/* set private members to defaults */
- self->priv->profiles = NULL;
+ self->priv->profiles = g_sequence_new(g_object_unref);
+ self->priv->muds = g_sequence_new(g_object_unref);
+ self->priv->characters = g_sequence_new(g_object_unref);
}
static GObject *
-mud_profile_manager_constructor (GType gtype,
+mud_profile_manager_constructor (GType type,
guint n_properties,
- GObjectConstructParam *properties)
+ GObjectConstructParam *construct_params)
{
- MudProfileManager *self;
- GObject *obj;
- MudProfileManagerClass *klass;
- GObjectClass *parent_class;
-
- /* Chain up to parent constructor */
- klass = MUD_PROFILE_MANAGER_CLASS( g_type_class_peek(MUD_TYPE_PROFILE_MANAGER) );
- parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
- obj = parent_class->constructor(gtype, n_properties, properties);
-
- self = MUD_PROFILE_MANAGER(obj);
+ GObject *obj;
+ MudProfileManagerClass *klass;
- if(!self->priv->parent)
+ if (manager_singleton == NULL)
{
- g_printf("ERROR: Tried to instantiate MudProfileManager without passing parent MudWindow\n");
- g_error("Tried to instantiate MudProfileManager without passing parent MudWindow");
+ /* Chain up to parent constructor */
+ klass = MUD_PROFILE_MANAGER_CLASS( g_type_class_peek(MUD_TYPE_PROFILE_MANAGER) ); /* TODO: Use
parent_class static after moving to G_DEFINE_TYPE */
+ obj = G_OBJECT_CLASS (g_type_class_peek_parent(klass))->constructor (type, n_properties,
construct_params);
+ manager_singleton = MUD_PROFILE_MANAGER (obj);
+ g_object_add_weak_pointer (G_OBJECT (manager_singleton), (gpointer) &manager_singleton);
+
+ /* TODO: Move everything but singleton handling away from here */
+
+ /* TODO: Make MudWindow a singleton too, otherwise we rely on the singleton to be first requested with
the parent passed via construct properties, and accidentally work without it in subsequent calls (though this
is guaranteed for now) */
+ if(!manager_singleton->priv->parent)
+ {
+ g_printf("ERROR: Tried to instantiate MudProfileManager without passing parent MudWindow\n");
+ g_error("Tried to instantiate MudProfileManager without passing parent MudWindow");
+ }
+
+ mud_profile_manager_load_profiles(manager_singleton);
+ mud_profile_manager_load_muds(manager_singleton);
+ mud_profile_manager_load_characters(manager_singleton);
+ return obj;
}
- mud_profile_manager_load_profiles(self);
-
- return obj;
+ return g_object_ref (manager_singleton);
}
static void
@@ -138,19 +171,12 @@ mud_profile_manager_finalize (GObject *object)
{
MudProfileManager *profile_manager;
GObjectClass *parent_class;
- GSList *entry;
profile_manager = MUD_PROFILE_MANAGER(object);
- entry = profile_manager->priv->profiles;
-
- while(entry)
- {
- MudProfile *profile = MUD_PROFILE(entry->data);
- g_object_unref(profile);
-
- entry = g_slist_next(entry);
- }
+ g_sequence_free(profile_manager->priv->profiles);
+ g_sequence_free(profile_manager->priv->muds);
+ g_sequence_free(profile_manager->priv->characters);
parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
parent_class->finalize(object);
@@ -204,154 +230,317 @@ mud_profile_manager_get_property(GObject *object,
static void
mud_profile_manager_load_profiles (MudProfileManager *self)
{
- GSList *entry;
- GSList *profiles;
- MudProfile *profile;
- GConfClient *client;
+ gchar *default_profile;
+ gchar **profile_list, **i;
+ MudProfile *profile;
+ GSettings *s;
- g_return_if_fail(MUD_IS_PROFILE_MANAGER(self));
- g_return_if_fail(self->priv->profiles == NULL);
+ g_return_if_fail (MUD_IS_PROFILE_MANAGER(self));
- client = gconf_client_get_default();
+ s = g_settings_new ("org.gnome.MUD");
- profiles = gconf_client_all_dirs(client,
- "/apps/gnome-mud/profiles",
- NULL);
+ profile_list = g_settings_get_strv (s, "profile-list");
+ default_profile = g_settings_get_string (s, "default-profile");
- profile = g_object_new(MUD_TYPE_PROFILE,
- "name", "Default",
- "parent", self,
- NULL);
+#warning Do something with the default profile
- self->priv->profiles = g_slist_append(self->priv->profiles,
- profile);
-
- entry = profiles;
-
- while(entry)
+ for (i = profile_list; *i; ++i)
{
- gchar *name = g_path_get_basename((gchar *)entry->data);
+ guint64 res;
+ guint id;
+ gchar *endptr = NULL;
+ gchar *profile_id = *i;
+
+ if (!g_str_has_prefix (profile_id, "profile-") || profile_id[8] == '\0')
+ continue;
+
+ res = g_ascii_strtoull (&profile_id[8], &endptr, 10);
+ if ((res == G_MAXUINT64 && errno == ERANGE) || ((res == 0) && endptr == &profile_id[8]) || (res >=
G_MAXUINT64))
+ continue;
+
+ id = (guint)res; /* TODO: Why downcast? */
+
+ profile = g_object_new (MUD_TYPE_PROFILE,
+ "id", id,
+ "parent", self,
+ NULL);
+ g_sequence_append (self->priv->profiles, profile);
+ }
+ g_sequence_sort (self->priv->profiles, (GCompareDataFunc)mud_profile_compare_func, NULL);
- if(!g_str_equal(name, "Default"))
+ g_free (default_profile);
+ g_strfreev (profile_list);
+ g_object_unref (s);
+}
+
+static MudProfile *
+mud_profile_manager_get_profile_by_id (MudProfileManager *self,
+ const gchar *id)
+{
+ GSequenceIter *iter;
+ MudProfile *profile = NULL;
+ gchar *profile_id = NULL;
+
+ /* FIXME: This complicated lookup suggests we might do better with a
+ * GHashTable instead of GSeqence, afterall, for simple key-based lookup */
+ for (iter = g_sequence_get_begin_iter (self->priv->profiles);
+ !g_sequence_iter_is_end (iter);
+ iter = g_sequence_iter_next (iter))
+ {
+ profile_id = g_strdup_printf ("profile-%" G_GUINT64_FORMAT, ((MudProfile *)g_sequence_get (iter))->id);
+ if (strcmp (id, profile_id) == 0)
{
- profile = g_object_new(MUD_TYPE_PROFILE,
- "name", g_strdup(name),
- "parent", self,
- NULL);
+ g_free (profile_id);
+ profile = g_sequence_get (iter);
+ break;
+ }
+ g_free (profile_id);
+ }
+
+ return profile;
+}
+
+static MudMud *
+mud_profile_manager_get_mud_by_id (MudProfileManager *self,
+ const gchar *id)
+{
+ GSequenceIter *iter;
+ MudMud *mud;
+
+ /* FIXME: This complicated lookup suggests we might do better with a
+ * GHashTable instead of GSeqence, afterall, for simple key-based lookup */
+ for (iter = g_sequence_get_begin_iter (self->priv->muds);
+ !g_sequence_iter_is_end (iter);
+ iter = g_sequence_iter_next (iter))
+ {
+ mud = g_sequence_get (iter);
+ if (strcmp (id, mud_mud_get_id (mud)) == 0)
+ return mud;
+ }
+
+ return NULL;
+}
+
+static void
+mud_profile_manager_load_muds (MudProfileManager *self)
+{
+ GSettings *s;
+ gchar **mud_list, **i;
+
+ g_return_if_fail (MUD_IS_PROFILE_MANAGER(self));
+
+ s = g_settings_new ("org.gnome.MUD");
+ mud_list = g_settings_get_strv (s, "mud-list");
+
+ for (i = mud_list; *i; ++i)
+ g_sequence_append (self->priv->muds, mud_mud_new (*i));
+
+ g_sequence_sort (self->priv->muds, (GCompareDataFunc)mud_mud_compare, NULL);
+
+ g_strfreev (mud_list);
+ g_object_unref (s);
+}
+
+static void
+mud_profile_manager_load_characters (MudProfileManager *self)
+{
+ GSettings *s;
+ gchar **character_list, **i;
+ gchar *character_path, *profile_id, *mud_id;
+ MudProfile *profile;
+ MudMud *mud;
- self->priv->profiles = g_slist_append(self->priv->profiles,
- profile);
+ g_return_if_fail (MUD_IS_PROFILE_MANAGER(self));
+
+ s = g_settings_new ("org.gnome.MUD");
+ character_list = g_settings_get_strv (s, "character-list");
+
+ for (i = character_list; *i; ++i)
+ {
+ /* TODO: Ignore all that don't begin with 'character-' and continue with a guint64 - rest of the code
can't deal with it yet due to relying on GSequence sorting */
+ if (!g_str_has_prefix (*i, "character-") || (*i)[10] == '\0')
+ continue;
+ /* TODO: Not bothering with a guint64 follow-up here, as the restriction should be restricted instead
soon */
+
+ /* TODO: Clean this up somehow (to not need to access GSettings here) by logically moving the
profile/mud binding setup to MudCharacter class? */
+ character_path = g_strdup_printf("/org/gnome/MUD/Characters/%s/", *i);
+ s = g_settings_new_with_path("org.gnome.MUD.Character", character_path);
+ profile_id = g_settings_get_string (s, "profile");
+ g_free (character_path);
+
+ profile = mud_profile_manager_get_profile_by_id (self, profile_id);
+ /* TODO: If profile wasn't found, set it to the default instead of bailing */
+ if (profile == NULL)
+ {
+ g_free (profile_id);
+ continue;
}
+ g_free (profile_id);
- g_free(name);
- g_free(entry->data);
+ mud_id = g_settings_get_string (s, "mud");
+ mud = mud_profile_manager_get_mud_by_id (self, mud_id);
+ if (mud == NULL)
+ {
+ g_free (mud_id);
+ g_object_unref (s);
+ continue;
+ }
+ g_free (mud_id);
- entry = g_slist_next(entry);
+ g_sequence_append (self->priv->characters, mud_character_new (*i, profile, mud));
}
- g_slist_free(profiles);
+ g_sequence_sort (self->priv->characters, (GCompareDataFunc)mud_character_compare, NULL);
- g_object_unref(client);
+ g_strfreev (character_list);
+ g_object_unref (s);
}
/* Public Methods */
-void
-mud_profile_manager_add_profile(MudProfileManager *self,
- const gchar *name)
+MudProfile*
+mud_profile_manager_add_profile (MudProfileManager *self,
+ const gchar *profile_name)
{
- MudProfile *profile, *default_profile;
- gchar *escaped_name;
- GConfClient *client;
-
- g_return_if_fail(MUD_IS_PROFILE_MANAGER(self));
+ MudProfile *profile, *last_profile;
+ guint new_id, i;
+ gchar **profile_list;
+ gchar *profile_id;
+ GSettings *settings;
+ GVariantBuilder builder;
- client = gconf_client_get_default();
- default_profile = mud_profile_manager_get_profile_by_name(self,
- "Default");
+ g_return_val_if_fail (MUD_IS_PROFILE_MANAGER(self), NULL);
- escaped_name = gconf_escape_key(name, -1);
+ last_profile = MUD_PROFILE (g_sequence_get (g_sequence_iter_prev (g_sequence_get_end_iter
(self->priv->profiles))));
+ /* TODO: This can crash if no profiles exist for some reason - make that impossible? */
+ g_return_val_if_fail (last_profile->id < (G_MAXUINT64 - 1), NULL);
+ new_id = last_profile->id + 1;
profile = g_object_new(MUD_TYPE_PROFILE,
- "name", escaped_name,
+ "id", new_id,
+ "name", profile_name,
"parent", self,
NULL);
- g_free(escaped_name);
+ g_sequence_insert_sorted(self->priv->profiles, profile, (GCompareDataFunc)mud_profile_compare_func,
NULL);
- mud_profile_copy_preferences(default_profile, profile);
+ settings = g_settings_new("org.gnome.MUD");
+ profile_list = g_settings_get_strv(settings, "profile-list");
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY);
- gconf_client_suggest_sync(client, NULL);
+ /* TODO: Instead of this, perhaps keep a good list of UUIDs in manager and then just write that out
after the new profile has been added to it?
+ * Alternatively (and perhaps even better), try to bind the available profiles directly with
ProfilesList.list, so that they can come and go via dconf (other processes)?
+ */
+ for (i = 0; profile_list[i]; ++i)
+ g_variant_builder_add(&builder, "s", profile_list[i]);
- self->priv->profiles = g_slist_append(self->priv->profiles,
- profile);
+ profile_id = g_strdup_printf("profile-%u", new_id);
+ g_variant_builder_add(&builder, "s", profile_id);
+ g_free(profile_id);
+ g_settings_set_value(settings, "profile-list", g_variant_builder_end(&builder));
mud_window_populate_profiles_menu(self->priv->parent);
- g_object_unref(client);
+ g_strfreev(profile_list);
+ g_object_unref(settings);
+ return profile;
}
void
mud_profile_manager_delete_profile(MudProfileManager *self,
- const gchar *name)
+ MudProfile *profile)
{
- MudProfile *profile;
- gchar *key, *pname;
- GSList *connections, *entry;
- GConfClient *client;
-
g_return_if_fail(MUD_IS_PROFILE_MANAGER(self));
- client = gconf_client_get_default();
-
- profile = mud_profile_manager_get_profile_by_name(self, name);
-
- if (profile)
+ if (profile) /* TODO: programmer error if not passed? */
{
- self->priv->profiles = g_slist_remove(self->priv->profiles,
- profile);
-
- key = g_strdup_printf("/apps/gnome-mud/profiles/%s", name);
- gconf_client_recursive_unset(client, key, 0, NULL);
- g_free(key);
-
- /* If the user deletes a profile we need to switch
- * any connections using that profile to Default to prevent
- * mass breakage */
- connections = gconf_client_all_dirs(client,
- "/apps/gnome-mud/muds",
- NULL);
-
- entry = connections;
-
- while(entry)
- {
- gchar *base = g_path_get_basename((gchar *)entry->data);
- key = g_strdup_printf("/apps/gnome-mud/muds/%s/profile",
+ GSettings *global_settings;
+ GSettingsSchema *schema;
+ gchar **profile_list, **keys;
+ gchar *profile_to_delete;
+ GVariantBuilder builder;
+ guint i;
+#if 0
+ gchar *key, *pname;
+ GSList *connections, *entry;
+#endif
+
+ g_sequence_remove (g_sequence_lookup (self->priv->profiles,
+ profile,
+ (GCompareDataFunc)mud_profile_compare_func,
+ NULL));
+
+ /* Remove from gsettings profiles list */
+ global_settings = g_settings_new("org.gnome.MUD");
+ profile_list = g_settings_get_strv(global_settings, "profile-list");
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY);
+ profile_to_delete = g_strdup_printf("profile-%" G_GUINT64_FORMAT, profile->id);
+ for (i = 0; profile_list[i]; ++i)
+ if (strcmp(profile_list[i], profile_to_delete) != 0)
+ g_variant_builder_add(&builder, "s", profile_list[i]);
+ g_free (profile_to_delete);
+ g_settings_set_value(global_settings, "list", g_variant_builder_end(&builder));
+ g_strfreev(profile_list);
+ g_object_unref(global_settings);
+
+ /* Reset all keys, effectively removing the custom profile path from GSettings backend */
+ g_object_get(profile->settings, "settings-schema", &schema, NULL);
+ keys = g_settings_schema_list_keys (schema);
+ for (i = 0; keys[i] != NULL; ++i)
+ g_settings_reset (profile->settings, keys[i]);
+
+ g_strfreev(keys);
+ g_object_unref(schema);
+
+
+#warning Reimplement profile updates in connections
+#if 0
+ /* If the user deletes a profile we need to switch
+ * any connections using that profile to Default to prevent
+ * mass breakage */
+ connections = gconf_client_all_dirs(client,
+ "/apps/gnome-mud/muds",
+ NULL);
+
+ entry = connections;
+
+ while(entry)
+ {
+ gchar *base = g_path_get_basename((gchar *)entry->data);
+ key = g_strdup_printf("/apps/gnome-mud/muds/%s/profile",
base);
- g_free(base);
+ g_free(base);
- pname = gconf_client_get_string(client, key, NULL);
+ pname = gconf_client_get_string(client, key, NULL);
- if(g_str_equal(pname, name))
- gconf_client_set_string(client, key, "Default", NULL);
+ if(g_str_equal(pname, name))
+ gconf_client_set_string(client, key, "Default", NULL);
- g_free(key);
- g_free(entry->data);
- entry = g_slist_next(entry);
- }
+ g_free(key);
+ g_free(entry->data);
+ entry = g_slist_next(entry);
+ }
- g_slist_free(connections);
+ g_slist_free(connections);
- gconf_client_suggest_sync(client, NULL);
+ gconf_client_suggest_sync(client, NULL);
+#endif
+ /* Update the profiles menu */
+ mud_window_populate_profiles_menu(self->priv->parent);
- /* Update the profiles menu */
- mud_window_populate_profiles_menu(self->priv->parent);
+ g_object_unref(profile);
}
+}
- g_object_unref(client);
+GSequence *
+mud_profile_manager_get_characters (MudProfileManager *self)
+{
+ if(!MUD_IS_PROFILE_MANAGER(self))
+ return NULL;
+
+ return self->priv->characters;
}
-const GSList*
+GSequence *
mud_profile_manager_get_profiles (MudProfileManager *self)
{
if(!MUD_IS_PROFILE_MANAGER(self))
@@ -360,28 +549,132 @@ mud_profile_manager_get_profiles (MudProfileManager *self)
return self->priv->profiles;
}
-MudProfile*
-mud_profile_manager_get_profile_by_name(MudProfileManager *self,
- const gchar *name)
+void
+mud_profile_manager_delete_character (MudProfileManager *self,
+ MudCharacter *character)
{
- GSList *entry = NULL;
- MudProfile *profile;
-
- if(!MUD_IS_PROFILE_MANAGER(self))
- return NULL;
+ g_return_if_fail (MUD_IS_PROFILE_MANAGER (self));
+ /* TODO: Implement */
+}
- entry = self->priv->profiles;
+static void
+mud_profile_manager_save_mud_list (MudProfileManager *self)
+{
+ GVariantBuilder builder;
+ GSequenceIter *iter;
+ GSettings *settings = g_settings_new("org.gnome.MUD");
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY);
+ for (iter = g_sequence_get_begin_iter (self->priv->muds);
+ !g_sequence_iter_is_end (iter);
+ iter = g_sequence_iter_next (iter))
+ {
+ g_variant_builder_add(&builder, "s", mud_mud_get_id (g_sequence_get (iter)));
+ }
+ g_settings_set_value(settings, "mud-list", g_variant_builder_end(&builder));
+ g_object_unref (settings);
+}
- while(entry)
+static void
+mud_profile_manager_save_character_list (MudProfileManager *self)
+{
+ GVariantBuilder builder;
+ GSequenceIter *iter;
+ GSettings *settings = g_settings_new("org.gnome.MUD");
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY);
+ for (iter = g_sequence_get_begin_iter (self->priv->characters);
+ !g_sequence_iter_is_end (iter);
+ iter = g_sequence_iter_next (iter))
{
- profile = MUD_PROFILE(entry->data);
+ g_variant_builder_add(&builder, "s", mud_character_get_id (g_sequence_get (iter)));
+ }
+ g_settings_set_value(settings, "character-list", g_variant_builder_end(&builder));
+ g_object_unref (settings);
+}
- if(g_str_equal(profile->name, name))
- return profile;
+MudMud *
+mud_profile_manager_add_mud (MudProfileManager *self,
+ const gchar *name,
+ const gchar *hostname,
+ guint port)
+{
+ guint64 id = 0;
+ gchar *new_id;
+ MudMud *mud;
- entry = g_slist_next(entry);
+ /* We currently guarantee that all sequence items start with 'mud-', so
+ * no need to do g_sequence_lookup checks for now */
+ if (!g_sequence_is_empty (self->priv->muds))
+ {
+ gchar *last_id;
+ gchar *endptr = NULL;
+ g_object_get (MUD_PROFILE (g_sequence_get (g_sequence_iter_prev (g_sequence_get_end_iter
(self->priv->muds)))),
+ "id", &last_id,
+ NULL);
+ id = g_ascii_strtoull(last_id + 4, &endptr, 10);
+ g_free (last_id);
+ if ((id == G_MAXUINT64 && errno == ERANGE) || ((id == 0) && endptr == last_id + 4) || (id >=
(G_MAXUINT64 - 1)))
+ return NULL;
+ ++id;
}
- return NULL;
+ new_id = g_strdup_printf ("mud-%" G_GUINT64_FORMAT, id);
+ mud = g_object_new (MUD_TYPE_MUD,
+ "id", new_id,
+ "name", name,
+ "hostname", hostname,
+ "port", port,
+ NULL);
+ /* TODO: If these sequences would be wrapped in an object, we could just bind things and even
g_settings_bind_with_mapping the list? */
+
+ g_sequence_insert_sorted (self->priv->muds, mud, (GCompareDataFunc)mud_mud_compare, NULL);
+ mud_profile_manager_save_mud_list (self);
+
+ g_free (new_id);
+ return mud;
}
+MudCharacter *
+mud_profile_manager_add_character (MudProfileManager *self,
+ MudProfile *profile,
+ MudMud *mud,
+ const gchar *name,
+ const gchar *connect_string,
+ const gchar *icon)
+{
+ guint64 id = 0;
+ gchar *new_id;
+ MudCharacter *character;
+
+ /* We currently guarantee that all sequence items start with 'character-', so
+ * no need to do g_sequence_lookup checks for now */
+ if (!g_sequence_is_empty (self->priv->characters))
+ {
+ gchar *last_id;
+ gchar *endptr = NULL;
+ g_object_get (MUD_PROFILE (g_sequence_get (g_sequence_iter_prev (g_sequence_get_end_iter
(self->priv->characters)))),
+ "id", &last_id,
+ NULL);
+ id = g_ascii_strtoull(last_id + 10, &endptr, 10);
+ g_free (last_id);
+ if ((id == G_MAXUINT64 && errno == ERANGE) || ((id == 0) && endptr == last_id + 10) || (id >=
(G_MAXUINT64 - 1)))
+ return NULL;
+ ++id;
+ }
+
+ new_id = g_strdup_printf ("character-%" G_GUINT64_FORMAT, id);
+ character = g_object_new (MUD_TYPE_CHARACTER,
+ "id", new_id,
+ "profile", profile,
+ "mud", mud,
+ "name", name,
+ "connect-string", connect_string,
+ NULL); /* TODO: icon */
+
+ g_sequence_insert_sorted (self->priv->characters, character, (GCompareDataFunc)mud_character_compare,
NULL);
+ mud_profile_manager_save_character_list (self);
+
+ g_free (new_id);
+ return character;
+}
diff --git a/src/mud-profile-manager.h b/src/mud-profile-manager.h
index 7bff26c..33d80f5 100644
--- a/src/mud-profile-manager.h
+++ b/src/mud-profile-manager.h
@@ -1,6 +1,7 @@
/* GNOME-Mud - A simple Mud Client
* mud-profile-manager.h
- * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ * Copyright 2005-2009 Les Harris <lharris gnome org>
+ * Copyright 2018 Mart Raudsepp <leio gentoo org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,9 +21,13 @@
#ifndef MUD_PROFILE_MANAGER_H
#define MUD_PROFILE_MANAGER_H
+#include <glib.h>
+
G_BEGIN_DECLS
-#include <glib.h>
+typedef struct _MudProfile MudProfile;
+typedef struct _MudMud MudMud;
+typedef struct _MudCharacter MudCharacter;
#define MUD_TYPE_PROFILE_MANAGER (mud_profile_manager_get_type ())
#define MUD_PROFILE_MANAGER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object),
MUD_TYPE_PROFILE_MANAGER, MudProfileManager))
@@ -36,8 +41,6 @@ typedef struct _MudProfileManager MudProfileManager;
typedef struct _MudProfileManagerClass MudProfileManagerClass;
typedef struct _MudProfileManagerPrivate MudProfileManagerPrivate;
-#include "mud-profile.h"
-
struct _MudProfileManagerClass
{
GObjectClass parent_class;
@@ -53,10 +56,24 @@ struct _MudProfileManager
GType mud_profile_manager_get_type (void);
-void mud_profile_manager_add_profile(MudProfileManager *self, const gchar *name);
-void mud_profile_manager_delete_profile(MudProfileManager *self, const gchar *name);
-const GSList* mud_profile_manager_get_profiles (MudProfileManager *self);
-MudProfile* mud_profile_manager_get_profile_by_name(MudProfileManager *self, const gchar *name);
+MudProfile *mud_profile_manager_add_profile (MudProfileManager *self,
+ const gchar *name);
+void mud_profile_manager_delete_profile (MudProfileManager *self,
+ MudProfile *profile);
+GSequence *mud_profile_manager_get_profiles (MudProfileManager *self);
+MudMud *mud_profile_manager_add_mud (MudProfileManager *self,
+ const gchar *name,
+ const gchar *hostname,
+ guint port);
+GSequence *mud_profile_manager_get_characters (MudProfileManager *self);
+MudCharacter *mud_profile_manager_add_character (MudProfileManager *self,
+ MudProfile *profile,
+ MudMud *mud,
+ const gchar *name,
+ const gchar *connect_string,
+ const gchar *icon);
+void mud_profile_manager_delete_character (MudProfileManager *self,
+ MudCharacter *character);
G_END_DECLS
diff --git a/src/mud-profile.c b/src/mud-profile.c
index 8143703..2cf0a06 100644
--- a/src/mud-profile.c
+++ b/src/mud-profile.c
@@ -2,6 +2,7 @@
* mud-profile.c
* Copyright (C) 1998-2005 Robin Ericsson <lobbin localhost nu>
* Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ * Copyright (C) 2018 Mart Raudsepp <leio gentoo org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,9 +25,9 @@
#include <string.h>
-#include <gconf/gconf-client.h>
#include <glib-object.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <sys/stat.h>
@@ -38,12 +39,13 @@
#include "mud-profile.h"
#include "utils.h"
+#define I_(string) g_intern_static_string (string)
+
struct _MudProfilePrivate
{
- GConfClient *gconf_client;
+ guint settings_changed_id;
MudPrefs preferences;
- gint in_notification_count;
guint gconf_signal;
MudProfileManager *parent;
@@ -56,6 +58,7 @@ G_DEFINE_TYPE(MudProfile, mud_profile, G_TYPE_OBJECT);
enum
{
PROP_MUD_PROFILE_0,
+ PROP_ID,
PROP_NAME,
PROP_PARENT
};
@@ -70,8 +73,6 @@ enum
/* Signal Identifier Map */
static guint mud_profile_signal[LAST_SIGNAL] = { 0 };
-#define RETURN_IF_NOTIFYING(profile) if ((profile)->priv->in_notification_count) return
-
/* Class Functions */
static void mud_profile_init (MudProfile *profile);
static void mud_profile_class_init (MudProfileClass *profile);
@@ -89,23 +90,30 @@ static void mud_profile_get_property(GObject *object,
GParamSpec *pspec);
/* Callbacks */
-static void mud_profile_gconf_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data);
+static void mud_profile_settings_changed_cb (GSettings *settings, const char *prop_name, MudProfile
*mud_profile);
/* Profile Set Functions */
static gboolean set_FontName(MudProfile *profile, const gchar *candidate);
static gboolean set_CommDev(MudProfile *profile, const gchar *candidate);
-static gboolean set_Scrollback(MudProfile *profile, const gint candidate);
+static gboolean set_Scrollback(MudProfile *profile, const guint candidate);
static gboolean set_ProxyVersion(MudProfile *profile, const gchar *candidate);
static gboolean set_ProxyHostname(MudProfile *profile, const gchar *candidate);
static gboolean set_Encoding(MudProfile *profile, const gchar *candidate);
static gboolean set_Foreground(MudProfile *profile, const gchar *candidate);
static gboolean set_Background(MudProfile *profile, const gchar *candidate);
-static gboolean set_Colors(MudProfile *profile, const gchar *candidate);
+static gboolean set_Colors(MudProfile *profile, gchar **palette);
+
+const gchar *
+mud_profile_get_name (MudProfile *self)
+{
+ g_return_val_if_fail (IS_MUD_PROFILE (self), NULL);
+
+ return self->visible_name;
+}
/* Private Methods */
static void mud_profile_set_proxy_combo_full(MudProfile *profile, gchar *version);
static void mud_profile_load_preferences(MudProfile *profile);
-static const gchar *mud_profile_gconf_get_key(MudProfile *profile, const gchar *key);
/* MudProfile Class Functions */
static void
@@ -127,13 +135,20 @@ mud_profile_class_init (MudProfileClass *klass)
g_type_class_add_private(klass, sizeof(MudProfilePrivate));
/* Create and Install Properties */
+ g_object_class_install_property(object_class,
+ PROP_ID,
+ g_param_spec_uint64("id", "ID",
+ "The ID of the profile.",
+ 0, G_MAXUINT64, G_MAXUINT64,
+ G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+
g_object_class_install_property(object_class,
PROP_NAME,
g_param_spec_string("name",
"Name",
- "The name of the profile.",
+ "The visible name of the profile.",
NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(object_class,
PROP_PARENT,
@@ -161,12 +176,12 @@ mud_profile_init (MudProfile *profile)
profile->priv = MUD_PROFILE_GET_PRIVATE(profile);
/* Set defaults */
- profile->name = NULL;
+ profile->id = 0;
+ profile->settings = NULL;
profile->priv->parent = NULL;
- profile->priv->in_notification_count = 0;
- profile->priv->gconf_client = gconf_client_get_default();
+ profile->priv->settings_changed_id = 0;
profile->preferences = &profile->priv->preferences;
}
@@ -179,18 +194,20 @@ mud_profile_constructor (GType gtype,
GObject *obj;
MudProfileClass *klass;
GObjectClass *parent_class;
+ gchar *profile_path;
/* Chain up to parent constructor */
klass = MUD_PROFILE_CLASS( g_type_class_peek(MUD_TYPE_PROFILE) );
parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
obj = parent_class->constructor(gtype, n_properties, properties);
+ /* TODO: Move most of this to constucted? */
self = MUD_PROFILE(obj);
- if(!self->name)
+ if(self->id == G_MAXUINT64)
{
- g_printf("ERROR: Tried to instantiate MudProfile without passing name.\n");
- g_error("Tried to instantiate MudProfile without passing name.");
+ g_printf("ERROR: Tried to instantiate MudProfile without passing ID.\n");
+ g_error("Tried to instantiate MudProfile without passing ID.");
}
if(!self->priv->parent || !MUD_IS_PROFILE_MANAGER(self->priv->parent))
@@ -199,29 +216,22 @@ mud_profile_constructor (GType gtype,
g_error("Tried to instantiate MudProfile without passing parent manager.");
}
- mud_profile_load_preferences(self);
+ profile_path = g_strdup_printf("/org/gnome/MUD/Profiles/profile-%" G_GUINT64_FORMAT "/", self->id);
+ self->settings = g_settings_new_with_path("org.gnome.MUD.Profile", profile_path);
+ g_settings_bind(self->settings,
+ "visible-name",
+ self, "name",
+ G_SETTINGS_BIND_DEFAULT);
+ g_free(profile_path);
- if (g_str_equal(self->name, "Default"))
- {
- self->priv->gconf_signal = gconf_client_notify_add(self->priv->gconf_client,
- "/apps/gnome-mud",
- mud_profile_gconf_changed,
- self,
- NULL,
- NULL);
- }
- else
- {
- gchar buf[512];
-
- g_snprintf(buf, 512, "/apps/gnome-mud/profiles/%s", self->name);
- self->priv->gconf_signal = gconf_client_notify_add(self->priv->gconf_client,
- buf,
- mud_profile_gconf_changed,
- self,
- NULL,
- NULL);
- }
+ mud_profile_load_preferences (self); /* Is this necessary at all if mud_profile_settings_changed_cb gets
called? */
+
+ self->priv->settings_changed_id =
+ g_signal_connect(self->settings,
+ "changed",
+ G_CALLBACK (mud_profile_settings_changed_cb),
+ self);
+ mud_profile_settings_changed_cb (self->settings, NULL, self);
return obj;
}
@@ -229,27 +239,23 @@ mud_profile_constructor (GType gtype,
static void
mud_profile_finalize (GObject *object)
{
- MudProfile *profile;
+ MudProfile *self;
GObjectClass *parent_class;
- GConfClient *client = gconf_client_get_default();
-
- profile = MUD_PROFILE(object);
- gconf_client_notify_remove(client, profile->priv->gconf_signal);
+ self = MUD_PROFILE (object);
- g_free(profile->priv->preferences.FontName);
- g_free(profile->priv->preferences.CommDev);
- g_free(profile->priv->preferences.LastLogDir);
- g_free(profile->priv->preferences.Encoding);
- g_free(profile->priv->preferences.ProxyVersion);
- g_free(profile->priv->preferences.ProxyHostname);
+ g_signal_handler_disconnect (self->settings, self->priv->settings_changed_id);
+ self->priv->settings_changed_id = 0;
+ g_object_unref (self->settings);
- g_object_unref(profile->priv->gconf_client);
+ g_free (self->priv->preferences.FontName);
+ g_free (self->priv->preferences.CommDev);
+ g_free (self->priv->preferences.Encoding);
+ g_free (self->priv->preferences.ProxyVersion);
+ g_free (self->priv->preferences.ProxyHostname);
- g_free(profile->name);
-
- parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
- parent_class->finalize(object);
+ parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS(object));
+ parent_class->finalize (object);
}
static void
@@ -259,25 +265,23 @@ mud_profile_set_property(GObject *object,
GParamSpec *pspec)
{
MudProfile *self;
- gchar *new_string;
self = MUD_PROFILE(object);
switch(prop_id)
{
- case PROP_NAME:
- new_string = g_value_dup_string(value);
-
- if(!self->name)
- self->name = g_strdup(new_string);
- else if( !g_str_equal(self->name, new_string) )
- {
- g_free(self->name);
- self->name = g_strdup(new_string);
- }
+ case PROP_ID:
+ self->id = g_value_get_uint64(value);
+ break;
- g_free(new_string);
+ case PROP_NAME:
+ {
+ const gchar *new_string = g_value_get_string(value);
+ /* TODO: Move this to an EXPLICIT_NOTIFY setter with notify_by_pspec only if changed logic */
+ g_free (self->visible_name);
+ self->visible_name = g_strdup (new_string);
break;
+ }
case PROP_PARENT:
self->priv->parent = MUD_PROFILE_MANAGER(g_value_get_object(value));
@@ -301,8 +305,12 @@ mud_profile_get_property(GObject *object,
switch(prop_id)
{
+ case PROP_ID:
+ g_value_set_uint64(value, self->id);
+ break;
+
case PROP_NAME:
- g_value_set_string(value, self->name);
+ g_value_set_string(value, self->visible_name);
break;
case PROP_PARENT:
@@ -319,6 +327,8 @@ mud_profile_get_property(GObject *object,
void
mud_profile_copy_preferences(MudProfile *from, MudProfile *to)
{
+#if 0
+/* TODO: Port and reintroduce for a "clone profile" feature (previously this was mainly used to create new
profile from "Default" */
gint i;
gchar *s;
const gchar *key;
@@ -328,17 +338,12 @@ mud_profile_copy_preferences(MudProfile *from, MudProfile *to)
mud_profile_set_echotext(to, from->preferences->EchoText);
mud_profile_set_keeptext(to, from->preferences->KeepText);
- mud_profile_set_disablekeys(to, from->preferences->DisableKeys);
mud_profile_set_scrolloutput(to, from->preferences->ScrollOnOutput);
mud_profile_set_commdev(to, from->preferences->CommDev);
mud_profile_set_scrollback(to, from->preferences->Scrollback);
mud_profile_set_font(to, from->preferences->FontName);
- mud_profile_set_foreground(to, from->preferences->Foreground.red,
- from->preferences->Foreground.green,
- from->preferences->Foreground.blue);
- mud_profile_set_background(to, from->preferences->Background.red,
- from->preferences->Background.green,
- from->preferences->Background.blue);
+ mud_profile_set_foreground(to, from->preferences->Foreground);
+ mud_profile_set_background(to, from->preferences->Background);
for (i = 0; i < C_MAX; i++)
{
@@ -356,360 +361,117 @@ mud_profile_copy_preferences(MudProfile *from, MudProfile *to)
mud_profile_set_msp_check(to, from->preferences->UseRemoteDownload);
mud_profile_set_proxy_combo_full(to, from->preferences->ProxyVersion);
mud_profile_set_proxy_entry(to, from->preferences->ProxyHostname);
+#endif
}
-/* MudProfile Private Methods */
+/* TODO: Can't we just get rid of this? */
static void
-mud_profile_load_preferences(MudProfile *profile)
+mud_profile_load_preferences (MudProfile *profile)
{
- GConfClient *gconf_client;
- MudPrefs *prefs;
- GdkColor color;
- GdkColor *colors;
- gint n_colors;
- gchar extra_path[512] = "", keyname[2048];
- gchar *p;
- MudProfile *default_profile;
-
- g_return_if_fail(IS_MUD_PROFILE(profile));
-
- gconf_client = gconf_client_get_default();
- prefs = profile->preferences;
-
- if (!g_str_equal(profile->name, "Default"))
- g_snprintf(extra_path, 512, "profiles/%s/", profile->name);
-
- if(!g_str_equal(profile->name, "Default"))
- {
- gchar *key;
- gchar *test_string;
-
- key = g_strdup_printf("/apps/gnome-mud/profiles/%s/functionality/encoding",
- profile->name);
-
- test_string = gconf_client_get_string(gconf_client, key, NULL);
-
- if(!test_string)
- {
- default_profile = mud_profile_manager_get_profile_by_name(profile->priv->parent,
- "Default");
- mud_profile_copy_preferences(default_profile, profile);
-
- }
- else
- g_free(test_string);
- }
-
-#define GCONF_GET_STRING(entry, subdir, variable) \
- if(prefs->variable) g_free(prefs->variable); \
- g_snprintf(keyname, 2048, "/apps/gnome-mud/%s" #subdir "/" #entry, extra_path); \
- p = gconf_client_get_string(gconf_client, keyname, NULL);\
- prefs->variable = g_strdup(p);
-
-#define GCONF_GET_BOOLEAN(entry, subdir, variable) \
- g_snprintf(keyname, 2048, "/apps/gnome-mud/%s" #subdir "/" #entry, extra_path); \
- prefs->variable = gconf_client_get_bool(gconf_client, keyname, NULL);
-
-#define GCONF_GET_INT(entry, subdir, variable) \
- g_snprintf(keyname, 2048, "/apps/gnome-mud/%s" #subdir "/" #entry, extra_path); \
- prefs->variable = gconf_client_get_int(gconf_client, keyname, NULL);
-
-#define GCONF_GET_COLOR(entry, subdir, variable) \
- g_snprintf(keyname, 2048, "/apps/gnome-mud/%s" #subdir "/" #entry, extra_path); \
- p = gconf_client_get_string(gconf_client, keyname, NULL);\
- if (p && gdk_color_parse(p, &color)) \
- { \
- prefs->variable = color; \
- }
-
- GCONF_GET_STRING(font, ui, FontName);
- GCONF_GET_COLOR(foreground_color, ui, Foreground);
- GCONF_GET_COLOR(background_color, ui, Background);
- GCONF_GET_INT(scrollback_lines, ui, Scrollback);
- GCONF_GET_STRING(commdev, functionality, CommDev);
- GCONF_GET_BOOLEAN(echo, functionality, EchoText);
- GCONF_GET_BOOLEAN(keeptext, functionality, KeepText);
- GCONF_GET_BOOLEAN(system_keys, functionality, DisableKeys);
- GCONF_GET_BOOLEAN(scroll_on_output, functionality, ScrollOnOutput);
- GCONF_GET_INT(flush_interval, functionality, FlushInterval);
- GCONF_GET_STRING(encoding, functionality, Encoding);
- GCONF_GET_STRING(proxy_version, functionality, ProxyVersion);
- GCONF_GET_BOOLEAN(use_proxy, functionality, UseProxy);
- GCONF_GET_BOOLEAN(remote_encoding, functionality, UseRemoteEncoding);
- GCONF_GET_STRING(proxy_hostname, functionality, ProxyHostname);
- GCONF_GET_BOOLEAN(remote_download, functionality, UseRemoteDownload);
-
- /* palette */
- g_snprintf(keyname, 2048, "/apps/gnome-mud/%sui/palette", extra_path);
- p = gconf_client_get_string(gconf_client, keyname, NULL);
-
- if (p)
- {
- gtk_color_selection_palette_from_string(p, &colors, &n_colors);
- if (n_colors < C_MAX)
- {
- g_printerr(ngettext("Palette had %d entry instead of %d\n",
- "Palette had %d entries instead of %d\n",
- n_colors),
- n_colors, C_MAX);
- }
- memcpy(prefs->Colors, colors, C_MAX * sizeof(GdkColor));
- g_free(colors);
- }
-
- /* last log dir */
- g_snprintf(keyname, 2048, "/apps/gnome-mud/%sfunctionality/last_log_dir", extra_path);
- p = gconf_client_get_string(gconf_client, keyname, NULL);
-
- if (p == NULL || !g_ascii_strncasecmp(p, "", sizeof("")))
- {
- prefs->LastLogDir = g_strdup(g_get_home_dir());
- }
- else
- {
- prefs->LastLogDir = g_strdup(p);
- }
+ MudPrefs *prefs;
+ gchar *color_string;
+ gchar **color_palette;
+ GdkColor color;
- g_object_unref(gconf_client);
+ /* TODO: Get rid of this - currently needed due to keeping a copy of setting values in
profile->preferences */
+ prefs = profile->preferences;
-#undef GCONF_GET_BOOLEAN
-#undef GCONF_GET_COLOR
-#undef GCONF_GET_INT
-#undef GCONF_GET_STRING
-}
+ /* FIXME: Many of them will get out of sync on first set, as many don't go via setters that update prefs,
just GSettings */
+ prefs->EchoText = g_settings_get_boolean (profile->settings, "echo");
+ prefs->KeepText = g_settings_get_boolean (profile->settings, "keep-text");
+ prefs->ScrollOnOutput = g_settings_get_boolean (profile->settings, "scroll-on-output");
-static gchar *
-color_to_string(const GdkColor *c)
-{
- gchar *s;
- gchar *ptr;
+ prefs->FontName = g_settings_get_string (profile->settings, "font");
+ prefs->CommDev = g_settings_get_string (profile->settings, "command-divider");
+ prefs->Encoding = g_settings_get_string (profile->settings, "encoding");
+ prefs->ProxyVersion = g_settings_get_string (profile->settings, "proxy-socks-version");
+ prefs->ProxyHostname = g_settings_get_string (profile->settings, "proxy-hostname");
- s = g_strdup_printf("#%2X%2X%2X", c->red / 256, c->green / 256, c->blue / 256);
+ prefs->Scrollback = g_settings_get_uint (profile->settings, "scrollback-lines");
- for (ptr = s; *ptr; ptr++)
- if (*ptr == ' ')
- *ptr = '0';
+ color_string = g_settings_get_string (profile->settings, "foreground-color");
+ if (color_string && gdk_color_parse (color_string, &color))
+ prefs->Foreground = color;
+ g_free (color_string);
- return s;
-}
-
-static const gchar *
-mud_profile_gconf_get_key(MudProfile *profile, const gchar *key)
-{
- static gchar buf[2048];
- gchar extra_path[512] = "";
+ color_string = g_settings_get_string (profile->settings, "background-color");
+ if (color_string && gdk_color_parse (color_string, &color))
+ prefs->Background = color;
+ g_free (color_string);
- if (strcmp(profile->name, "Default"))
- g_snprintf(extra_path, 512, "profiles/%s/", profile->name);
+ prefs->UseRemoteEncoding = g_settings_get_boolean (profile->settings, "remote-encoding");
+ prefs->UseProxy = g_settings_get_boolean (profile->settings, "use-proxy");
+ prefs->UseRemoteDownload = g_settings_get_boolean (profile->settings, "remote-download");
- g_snprintf(buf, 2048, "/apps/gnome-mud/%s%s", extra_path, key);
-
- return buf;
+ color_palette = g_settings_get_strv (profile->settings, "palette");
+ set_Colors (profile, color_palette);
+ g_strfreev (color_palette);
}
+/* MudProfile Private Methods */
static void
-mud_profile_gconf_changed(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data)
-{
- MudProfile *profile = MUD_PROFILE(data);
- MudProfileMask mask;
- GConfValue *val;
- gchar *key;
- gchar **path = NULL;
-
- gboolean bool_setting;
- gint int_setting;
- const gchar *string_setting;
-
- path = g_strsplit_set(gconf_entry_get_key(entry), "/", 6);
-
- if (!strcmp(profile->name, "Default") && !strcmp(path[3], "profiles"))
- {
- g_strfreev(path);
- return;
- }
-
- g_strfreev(path);
-
- val = gconf_entry_get_value(entry);
- key = g_path_get_basename(gconf_entry_get_key(entry));
-
- if(strcmp(key, "echo") == 0)
- {
- bool_setting = TRUE;
-
- if(val && val->type == GCONF_VALUE_BOOL)
- bool_setting = gconf_value_get_bool(val);
-
- if(bool_setting != profile->priv->preferences.EchoText)
- {
- mask.EchoText = TRUE;
- profile->priv->preferences.EchoText = bool_setting;
- }
- }
- else if(strcmp(key, "keeptext") == 0)
- {
- bool_setting = FALSE;
-
- if(val && val->type == GCONF_VALUE_BOOL)
- bool_setting = gconf_value_get_bool(val);
-
- if(bool_setting != profile->priv->preferences.KeepText)
- {
- mask.KeepText = TRUE;
- profile->priv->preferences.KeepText = bool_setting;
- }
- }
- else if(strcmp(key, "system_keys") == 0)
- {
- bool_setting = FALSE;
-
- if(val && val->type == GCONF_VALUE_BOOL)
- bool_setting = gconf_value_get_bool(val);
-
- if(bool_setting != profile->priv->preferences.DisableKeys)
- {
- mask.DisableKeys = TRUE;
- profile->priv->preferences.DisableKeys = bool_setting;
- }
- }
- else if(strcmp(key, "scroll_on_output") == 0)
- {
- bool_setting = FALSE;
-
- if(val && val->type == GCONF_VALUE_BOOL)
- bool_setting = gconf_value_get_bool(val);
-
- if(bool_setting != profile->priv->preferences.ScrollOnOutput)
- {
- mask.ScrollOnOutput = TRUE;
- profile->priv->preferences.ScrollOnOutput = bool_setting;
- }
- }
- else if(strcmp(key, "use_proxy") == 0)
- {
- bool_setting = FALSE;
-
- if(val && val->type == GCONF_VALUE_BOOL)
- bool_setting = gconf_value_get_bool(val);
-
- if(bool_setting != profile->priv->preferences.UseProxy)
- {
- mask.UseProxy = TRUE;
- profile->priv->preferences.UseProxy = bool_setting;
- }
- }
- else if(strcmp(key, "remote_encoding") == 0)
- {
- bool_setting = FALSE;
-
- if(val && val->type == GCONF_VALUE_BOOL)
- bool_setting = gconf_value_get_bool(val);
-
- if(bool_setting != profile->priv->preferences.UseRemoteEncoding)
- {
- mask.UseRemoteEncoding = TRUE;
- profile->priv->preferences.UseRemoteEncoding = bool_setting;
- }
- }
- else if(strcmp(key, "remote_download") == 0)
- {
- bool_setting = FALSE;
-
- if(val && val->type == GCONF_VALUE_BOOL)
- bool_setting = gconf_value_get_bool(val);
-
- if(bool_setting != profile->priv->preferences.UseRemoteDownload)
- {
- mask.UseRemoteDownload = TRUE;
- profile->priv->preferences.UseRemoteDownload = bool_setting;
- }
- }
- else if(strcmp(key, "scrollback_lines") == 0)
- {
- int_setting = 500;
-
- if(val && val->type == GCONF_VALUE_INT)
- int_setting = gconf_value_get_int(val);
-
- mask.Scrollback = set_Scrollback(profile, int_setting);
- }
- else if(strcmp(key, "commdev") == 0)
- {
- string_setting = ";";
-
- if(val && val->type == GCONF_VALUE_STRING)
- string_setting = gconf_value_get_string(val);
-
- mask.CommDev = set_CommDev(profile, string_setting);
- }
- else if(strcmp(key, "font") == 0)
- {
- string_setting = "monospace 12";
-
- if(val && val->type == GCONF_VALUE_STRING)
- string_setting = gconf_value_get_string(val);
-
- mask.FontName = set_FontName(profile, string_setting);
- }
- else if(strcmp(key, "foreground_color") == 0)
- {
- string_setting = "#FFFFFF";
-
- if(val && val->type == GCONF_VALUE_STRING)
- string_setting = gconf_value_get_string(val);
-
- mask.Foreground = set_Foreground(profile, string_setting);
- }
- else if(strcmp(key, "background_color") == 0)
- {
- string_setting = "#FFFFFF";
-
- if(val && val->type == GCONF_VALUE_STRING)
- string_setting = gconf_value_get_string(val);
-
- mask.Background = set_Background(profile, string_setting);
- }
- else if(strcmp(key, "palette") == 0)
- {
- string_setting =
-
"#000000:#AA0000:#00AA00:#AA5500:#0000AA:#AA00AA:#00AAAA:#AAAAAA:#555555:#FF5555:#55FF55:#FFFF55:#5555FF:#FF55FF:#55FFFF:#FFFFFF";
- if(val && val->type == GCONF_VALUE_STRING)
- string_setting = gconf_value_get_string(val);
-
- mask.Colors = set_Colors(profile, string_setting);
- }
- else if(strcmp(key, "proxy_version") == 0)
- {
- string_setting = "5";
-
- if(val && val->type == GCONF_VALUE_STRING)
- string_setting = gconf_value_get_string(val);
-
- mask.ProxyVersion = set_ProxyVersion(profile, string_setting);
- }
- else if(strcmp(key, "proxy_hostname") == 0)
- {
- string_setting = "127.0.0.1";
-
- if(val && val->type == GCONF_VALUE_STRING)
- string_setting = gconf_value_get_string(val);
-
- mask.ProxyHostname = set_ProxyHostname(profile, string_setting);
- }
- else if(strcmp(key, "encoding") == 0)
- {
- string_setting = "127.0.0.1";
-
- if(val && val->type == GCONF_VALUE_STRING)
- string_setting = gconf_value_get_string(val);
-
- mask.Encoding = set_Encoding(profile, string_setting);
- }
-
- if(key)
- g_free(key);
-
- g_signal_emit(profile, mud_profile_signal[CHANGED], 0, &mask);
+mud_profile_settings_changed_cb (GSettings *settings,
+ const char *prop_name,
+ MudProfile *profile)
+{
+ MudProfileMask mask = {FALSE, };
+ gboolean bool_setting;
+ gchar *str_setting;
+
+ /* TODO: freeze_notify and thaw? */
+
+#define SETTINGS_STRING(pref, key) \
+ do { if (!prop_name || prop_name == I_(key)) \
+ { \
+ str_setting = g_settings_get_string(settings, key); \
+ mask.pref = set_##pref(profile, str_setting); \
+ g_free (str_setting); \
+ } \
+ } while (0)
+
+#define SETTINGS_BOOLEAN(pref, key) \
+ do { if (!prop_name || prop_name == I_(key)) \
+ { \
+ bool_setting = g_settings_get_boolean(settings, key); \
+ if(bool_setting != profile->priv->preferences.pref) \
+ { \
+ mask.pref = TRUE; \
+ profile->priv->preferences.pref = bool_setting; \
+ } \
+ } \
+ } while (0)
+
+ /* UI */
+ SETTINGS_STRING (FontName, "font");
+ SETTINGS_STRING (Foreground, "foreground-color");
+ SETTINGS_STRING (Background, "background-color");
+
+ if (!prop_name || prop_name == I_("palette"))
+ {
+ gchar **palette = g_settings_get_strv (settings, "palette");
+ mask.Colors = set_Colors(profile, palette);
+ g_strfreev (palette);
+ }
+
+ if (!prop_name || prop_name == I_("scrollback-lines"))
+ mask.Scrollback = set_Scrollback(profile, g_settings_get_uint(settings, "scrollback-lines"));
+
+ /* Functionality */
+ SETTINGS_STRING (Encoding, "encoding");
+ SETTINGS_BOOLEAN (UseRemoteEncoding, "remote-encoding");
+ SETTINGS_BOOLEAN (UseRemoteDownload, "remote-download");
+ SETTINGS_STRING (CommDev, "command-divider");
+ SETTINGS_BOOLEAN (EchoText, "echo");
+ SETTINGS_BOOLEAN (KeepText, "keep-text");
+ SETTINGS_BOOLEAN (ScrollOnOutput, "scroll-on-output");
+ SETTINGS_BOOLEAN (UseProxy, "use-proxy");
+ SETTINGS_STRING (ProxyVersion, "proxy-socks-version");
+ SETTINGS_STRING (ProxyHostname, "proxy-hostname");
+
+#undef SETTINGS_STRING
+#undef SETTINGS_BOOLEAN
+
+ g_signal_emit(profile, mud_profile_signal[CHANGED], 0, &mask);
}
@@ -747,7 +509,7 @@ set_CommDev(MudProfile *profile, const gchar *candidate)
}
static gboolean
-set_Scrollback(MudProfile *profile, const gint candidate)
+set_Scrollback(MudProfile *profile, const guint candidate)
{
if (candidate >= 1 && candidate != profile->priv->preferences.Scrollback)
{
@@ -809,218 +571,119 @@ set_Encoding(MudProfile *profile, const gchar *candidate)
return FALSE;
}
+/* TODO: Remove all this and rely on object/signal bindings, or just set directly in all callers */
void
mud_profile_set_scrolloutput (MudProfile *profile, gboolean value)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/scroll_on_output");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_bool(profile->priv->gconf_client, key, value, NULL);
-}
-
-void
-mud_profile_set_disablekeys (MudProfile *profile, gboolean value)
-{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/system_keys");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_bool(profile->priv->gconf_client, key, value, NULL);
+ g_settings_set_boolean(profile->settings, "scroll-on-output", value);
}
void
mud_profile_set_keeptext (MudProfile *profile, gboolean value)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/keeptext");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_bool(profile->priv->gconf_client, key, value, NULL);
+ g_settings_set_boolean(profile->settings, "keep-text", value);
}
void
mud_profile_set_echotext (MudProfile *profile, gboolean value)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/echo");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_bool(profile->priv->gconf_client, key, value, NULL);
+ g_settings_set_boolean(profile->settings, "echo", value);
}
void
mud_profile_set_commdev (MudProfile *profile, const gchar *value)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/commdev");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_string(profile->priv->gconf_client, key, value, NULL);
+ g_settings_set_string(profile->settings, "command-divider", value);
}
void
-mud_profile_set_terminal (MudProfile *profile, const gchar *value)
+mud_profile_set_encoding_combo(MudProfile *profile, const gchar *value)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/terminal_type");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_string(profile->priv->gconf_client, key, value, NULL);
+ g_settings_set_string(profile->settings, "encoding", value);
}
void
-mud_profile_set_encoding_combo(MudProfile *profile, const gchar *e)
+mud_profile_set_encoding_check (MudProfile *profile, gboolean value)
{
- GError *error = NULL;
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/encoding");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_string(profile->priv->gconf_client, key, e, &error);
+ g_settings_set_boolean(profile->settings, "remote-encoding", value);
}
void
-mud_profile_set_encoding_check (MudProfile *profile, const gint value)
+mud_profile_set_proxy_check (MudProfile *profile, const gboolean value)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/remote_encoding");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_bool(profile->priv->gconf_client, key, value, NULL);
+ g_settings_set_boolean(profile->settings, "use-proxy", value);
}
void
-mud_profile_set_proxy_check (MudProfile *profile, const gint value)
+mud_profile_set_msp_check (MudProfile *profile, const gboolean value)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/use_proxy");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_bool(profile->priv->gconf_client, key, value, NULL);
-}
-
-void
-mud_profile_set_msp_check (MudProfile *profile, const gint value)
-{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/remote_download");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_bool(profile->priv->gconf_client, key, value, NULL);
+ g_settings_set_boolean(profile->settings, "remote-download", value);
}
static void
mud_profile_set_proxy_combo_full(MudProfile *profile, gchar *version)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/proxy_version");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_string(profile->priv->gconf_client, key, version, NULL);
+ g_settings_set_string(profile->settings, "proxy-socks-version", version);
}
void
mud_profile_set_proxy_combo(MudProfile *profile, GtkComboBox *combo)
{
gchar *version = gtk_combo_box_get_active_text(combo);
-
mud_profile_set_proxy_combo_full(profile, version);
}
void
mud_profile_set_proxy_entry (MudProfile *profile, const gchar *value)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/proxy_hostname");
- RETURN_IF_NOTIFYING(profile);
-
if(value)
- gconf_client_set_string(profile->priv->gconf_client, key, value, NULL);
+ g_settings_set_string(profile->settings, "proxy-hostname", value);
else
- gconf_client_set_string(profile->priv->gconf_client, key, "", NULL);
+ g_settings_set_string(profile->settings, "proxy-hostname", "");
}
void
mud_profile_set_font (MudProfile *profile, const gchar *value)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "ui/font");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_string(profile->priv->gconf_client, key, value, NULL);
+ g_settings_set_string(profile->settings, "font", value);
}
void
-mud_profile_set_foreground (MudProfile *profile, guint r, guint g, guint b)
+mud_profile_set_foreground (MudProfile *profile, GdkColor *color)
{
- GdkColor color;
- gchar *s;
- const gchar *key = mud_profile_gconf_get_key(profile, "ui/foreground_color");
-
- RETURN_IF_NOTIFYING(profile);
-
- color.red = r;
- color.green = g;
- color.blue = b;
-
- s = color_to_string(&color);
-
- gconf_client_set_string(profile->priv->gconf_client, key, s, NULL);
+ gchar *s = gdk_color_to_string(color);
+ g_settings_set_string(profile->settings, "foreground-color", s);
g_free(s);
}
void
-mud_profile_set_background (MudProfile *profile, guint r, guint g, guint b)
+mud_profile_set_background (MudProfile *profile, GdkColor *color)
{
- GdkColor color;
- gchar *s;
- const gchar *key = mud_profile_gconf_get_key(profile, "ui/background_color");
-
- RETURN_IF_NOTIFYING(profile);
-
- color.red = r;
- color.green = g;
- color.blue = b;
-
- s = color_to_string(&color);
- gconf_client_set_string(profile->priv->gconf_client, key, s, NULL);
+ gchar *s = gdk_color_to_string(color);
+ g_settings_set_string(profile->settings, "background-color", s);
g_free(s);
}
void
-mud_profile_set_colors (MudProfile *profile, gint nr, guint r, guint g, guint b)
+mud_profile_set_colors (MudProfile *profile,
+ gint nr,
+ GdkColor *color)
{
- GdkColor color[C_MAX];
- gchar *s;
- gint i;
- const gchar *key = mud_profile_gconf_get_key(profile, "ui/palette");
-
- RETURN_IF_NOTIFYING(profile);
+ gchar **value;
+ gchar *s = gdk_color_to_string (color);
+ /* FIXME: Guard against retrieved old value not having 16 entries */
+ value = g_settings_get_strv (profile->settings, "palette");
+ g_free (value[nr]); /* FIXME: Guard against wrong 'nr' value */
+ value[nr] = s;
+ g_settings_set_strv (profile->settings, "palette", (const gchar * const *)value);
- for (i = 0; i < C_MAX; i++)
- {
- if (i == nr)
- {
- color[i].red = r;
- color[i].green = g;
- color[i].blue = b;
- }
- else
- {
- color[i].red = profile->priv->preferences.Colors[i].red;
- color[i].green = profile->priv->preferences.Colors[i].green;
- color[i].blue = profile->priv->preferences.Colors[i].blue;
- }
- }
-
- s = gtk_color_selection_palette_to_string(color, C_MAX);
- gconf_client_set_string(profile->priv->gconf_client, key, s, NULL);
-}
-
-void
-mud_profile_set_history(MudProfile *profile, const gint value)
-{
- const gchar *key = mud_profile_gconf_get_key(profile, "functionality/history_count");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_int(profile->priv->gconf_client, key, value, NULL);
+ g_strfreev(value);
}
void
-mud_profile_set_scrollback(MudProfile *profile, const gint value)
+mud_profile_set_scrollback(MudProfile *profile, const guint value)
{
- const gchar *key = mud_profile_gconf_get_key(profile, "ui/scrollback_lines");
- RETURN_IF_NOTIFYING(profile);
-
- gconf_client_set_int(profile->priv->gconf_client, key, value, NULL);
+ g_settings_set_uint(profile->settings, "scrollback-lines", value);
}
static gboolean
@@ -1064,28 +727,26 @@ set_Background(MudProfile *profile, const gchar *candidate)
}
static gboolean
-set_Colors(MudProfile *profile, const gchar *candidate)
+set_Colors (MudProfile *profile, gchar **palette)
{
- GdkColor *colors;
- gint n_colors;
+ guint n_colors = (palette == NULL) ? 0 : g_strv_length (palette);
+ GdkColor colors[C_MAX];
- if (candidate)
+ if ((palette == NULL) || (n_colors < C_MAX))
{
- gtk_color_selection_palette_from_string(candidate, &colors, &n_colors);
- if (n_colors < C_MAX)
- {
- g_printerr(ngettext("Palette had %d entry instead of %d\n",
- "Palette had %d entries instead of %d\n",
- n_colors),
- n_colors, C_MAX);
+ g_printerr (ngettext ("Palette had %u entry instead of %u\n",
+ "Palette had %u entries instead of %u\n",
+ n_colors),
+ n_colors, C_MAX);
- return FALSE;
- }
- memcpy(profile->priv->preferences.Colors, colors, C_MAX * sizeof(GdkColor));
- g_free(colors);
- return TRUE;
+ return FALSE;
}
- return FALSE;
+ for (gsize i = 0; i < C_MAX; ++i)
+ if (!gdk_color_parse (palette[i], &colors[i]))
+ return FALSE;
+
+ memcpy(profile->priv->preferences.Colors, &colors, C_MAX * sizeof(GdkColor));
+ return TRUE;
}
diff --git a/src/mud-profile.h b/src/mud-profile.h
index fad1deb..65fc00c 100644
--- a/src/mud-profile.h
+++ b/src/mud-profile.h
@@ -45,27 +45,19 @@ struct _MudPrefs
{
gboolean EchoText;
gboolean KeepText;
- gboolean AutoSave;
- gboolean DisableKeys;
gboolean ScrollOnOutput;
gchar *FontName;
gchar *CommDev;
- gchar *LastLogDir;
gchar *Encoding;
gchar *ProxyVersion;
gchar *ProxyHostname;
- gint History;
- gint Scrollback;
- gint FlushInterval;
+ guint Scrollback;
GdkColor Foreground;
GdkColor Background;
- GSList *alias_names;
- GSList *trigger_names;
-
gboolean UseRemoteEncoding;
gboolean UseProxy;
gboolean UseRemoteDownload;
@@ -79,7 +71,9 @@ struct _MudProfile
MudProfilePrivate *priv;
- gchar *name;
+ guint64 id;
+ gchar *visible_name;
+ GSettings *settings;
MudPrefs *preferences;
};
@@ -87,7 +81,6 @@ typedef struct
{
unsigned int EchoText : 1;
unsigned int KeepText : 1;
- unsigned int DisableKeys : 1;
unsigned int CommDev : 1;
unsigned int History : 1;
unsigned int ScrollOnOutput : 1;
@@ -113,26 +106,25 @@ struct _MudProfileClass
GType mud_profile_get_type (void);
+const gchar *mud_profile_get_name (MudProfile *self);
+
void mud_profile_copy_preferences (MudProfile *from, MudProfile *to);
void mud_profile_set_echotext (MudProfile *profile, gboolean value);
void mud_profile_set_keeptext (MudProfile *profile, gboolean value);
-void mud_profile_set_disablekeys (MudProfile *profile, gboolean value);
void mud_profile_set_scrolloutput (MudProfile *profile, gboolean value);
void mud_profile_set_commdev (MudProfile *profile, const gchar *value);
-void mud_profile_set_terminal (MudProfile *profile, const gchar *value);
-void mud_profile_set_history (MudProfile *profile, const gint value);
-void mud_profile_set_scrollback (MudProfile *profile, const gint value);
+void mud_profile_set_scrollback (MudProfile *profile, const guint value);
void mud_profile_set_font (MudProfile *profile, const gchar *value);
-void mud_profile_set_foreground (MudProfile *profile, guint r, guint g, guint b);
-void mud_profile_set_background (MudProfile *profile, guint r, guint g, guint b);
-void mud_profile_set_colors (MudProfile *profile, gint nr, guint r, guint g, guint b);
-void mud_profile_set_encoding_combo(MudProfile *profile, const gchar *e);
-void mud_profile_set_encoding_check (MudProfile *profile, const gint value);
-void mud_profile_set_proxy_check (MudProfile *profile, const gint value);
+void mud_profile_set_foreground (MudProfile *profile, GdkColor *color);
+void mud_profile_set_background (MudProfile *profile, GdkColor *color);
+void mud_profile_set_colors (MudProfile *profile, gint nr, GdkColor *color);
+void mud_profile_set_encoding_combo(MudProfile *profile, const gchar *value);
+void mud_profile_set_encoding_check (MudProfile *profile, gboolean value);
+void mud_profile_set_proxy_check (MudProfile *profile, const gboolean value);
void mud_profile_set_proxy_combo(MudProfile *profile, GtkComboBox *combo);
void mud_profile_set_proxy_entry (MudProfile *profile, const gchar *value);
-void mud_profile_set_msp_check (MudProfile *profile, const gint value);
+void mud_profile_set_msp_check (MudProfile *profile, const gboolean value);
G_END_DECLS
diff --git a/src/mud-subwindow.c b/src/mud-subwindow.c
index 605702d..405f7fc 100644
--- a/src/mud-subwindow.c
+++ b/src/mud-subwindow.c
@@ -24,7 +24,6 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <vte/vte.h>
-#include <gconf/gconf-client.h>
#include <gdk/gdkkeysyms.h>
#include <glib/gprintf.h>
@@ -956,7 +955,6 @@ mud_subwindow_entry_keypress_cb(GtkWidget *widget,
MudSubwindow *self)
{
const gchar *history;
- GConfClient *client = gconf_client_get_default();
if ((event->keyval == GDK_Return || event->keyval == GDK_KP_Enter) &&
(event->state & gtk_accelerator_get_default_mod_mask()) == 0 &&
@@ -986,19 +984,14 @@ mud_subwindow_entry_keypress_cb(GtkWidget *widget,
0,
text);
- if (gconf_client_get_bool(client,
- "/apps/gnome-mud/functionality/keeptext", NULL) == FALSE)
- gtk_entry_set_text(GTK_ENTRY(self->priv->entry), "");
- else
+ if (g_settings_get_boolean(self->priv->parent_view->profile->settings, "keep-text"))
gtk_editable_select_region(GTK_EDITABLE(self->priv->entry), 0, -1);
-
- g_object_unref(client);
+ else
+ gtk_entry_set_text(GTK_ENTRY(self->priv->entry), "");
return TRUE;
}
- g_object_unref(client);
-
if(event->keyval == GDK_Up)
{
history =
diff --git a/src/mud-window-prefs.c b/src/mud-window-prefs.c
index a470c16..11f07ca 100644
--- a/src/mud-window-prefs.c
+++ b/src/mud-window-prefs.c
@@ -1,6 +1,7 @@
/* GNOME-Mud - A simple Mud Client
* mud-window-prefs.c
- * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ * Copyright 2005-2009 Les Harris <lharris gnome org>
+ * Copyright 2018 Mart Raudsepp <leio gentoo org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,9 +24,6 @@
#include <glib.h>
#include <gtk/gtk.h>
-#include <glib/gi18n.h>
-#include <gconf/gconf.h>
-#include <gconf/gconf-client.h>
#include <glib/gprintf.h>
#include "gnome-mud.h"
@@ -37,10 +35,7 @@
struct _MudWindowPrefsPrivate
{
MudWindow *parent;
- MudProfile *profile;
-
- gchar *name;
- gchar *disp_name;
+ MudProfile *mud_profile;
GtkWidget *window;
gulong signal;
@@ -81,7 +76,7 @@ enum
{
PROP_MUD_WINDOW_PREFS_0,
PROP_PARENT,
- PROP_NAME
+ PROP_MUD_PROFILE
};
/* Create the Type */
@@ -147,9 +142,6 @@ static void mud_window_prefs_update_background(MudWindowPrefs *self,
static void mud_window_prefs_update_colors(MudWindowPrefs *self,
MudPrefs *preferences);
-// Set Functions
-
-
// Callbacks
static void mud_window_prefs_echo_cb(GtkWidget *widget,
MudWindowPrefs *window);
@@ -243,11 +235,11 @@ mud_window_prefs_class_init (MudWindowPrefsClass *klass)
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property(object_class,
- PROP_NAME,
- g_param_spec_string("name",
- "Name",
- "The name of the Profile",
- NULL,
+ PROP_MUD_PROFILE,
+ g_param_spec_object("mud-profile",
+ "MudProfile",
+ "The associated MudProfile object.",
+ MUD_TYPE_PROFILE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
}
@@ -285,10 +277,10 @@ mud_window_prefs_constructor (GType gtype,
g_error("Tried to instantiate MudWindowPrefs without passing parent MudWindow");
}
- if(!self->priv->name)
+ if(!self->priv->mud_profile)
{
- g_printf("ERROR: Tried to instantiate MudWindowPrefs without passing profile name.\n");
- g_error("Tried to instantiate MudWindowPrefs without passing parent profile name.");
+ g_printf("ERROR: Tried to instantiate MudWindowPrefs without passing profile.\n");
+ g_error("Tried to instantiate MudWindowPrefs without passing parent profile.");
}
mud_window_prefs_construct_window(self);
@@ -300,13 +292,7 @@ mud_window_prefs_constructor (GType gtype,
mud_window_prefs_construct_timers_tab(self);
mud_window_prefs_construct_keybindings_tab(self);
- self->priv->profile = mud_profile_manager_get_profile_by_name(self->priv->parent->profile_manager,
- self->priv->name);
- if(!self->priv->profile)
- self->priv->profile = mud_profile_manager_get_profile_by_name(self->priv->parent->profile_manager,
- "Default");
-
- self->priv->signal = g_signal_connect(self->priv->profile,
+ self->priv->signal = g_signal_connect(self->priv->mud_profile,
"changed",
G_CALLBACK(mud_window_prefs_changed_cb),
self);
@@ -334,12 +320,9 @@ mud_window_prefs_finalize (GObject *object)
self = MUD_WINDOW_PREFS(object);
- g_signal_handler_disconnect(self->priv->profile,
+ g_signal_handler_disconnect(self->priv->mud_profile,
self->priv->signal);
- g_free(self->priv->name);
- g_free(self->priv->disp_name);
-
parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
parent_class->finalize(object);
}
@@ -351,7 +334,6 @@ mud_window_prefs_set_property(GObject *object,
GParamSpec *pspec)
{
MudWindowPrefs *self;
- gchar *new_string;
self = MUD_WINDOW_PREFS(object);
@@ -362,18 +344,8 @@ mud_window_prefs_set_property(GObject *object,
self->priv->parent = MUD_WINDOW(g_value_get_object(value));
break;
- case PROP_NAME:
- new_string = g_value_dup_string(value);
-
- if(!self->priv->name)
- self->priv->name = g_strdup(new_string);
- else if( !g_str_equal(self->priv->name, new_string) )
- {
- g_free(self->priv->name);
- self->priv->name = g_strdup(new_string);
- }
-
- g_free(new_string);
+ case PROP_MUD_PROFILE:
+ self->priv->mud_profile = MUD_PROFILE(g_value_get_object(value));
break;
default:
@@ -398,8 +370,8 @@ mud_window_prefs_get_property(GObject *object,
g_value_take_object(value, self->priv->parent);
break;
- case PROP_NAME:
- g_value_set_string(value, self->priv->name);
+ case PROP_MUD_PROFILE:
+ g_value_take_object(value, self->priv->mud_profile);
break;
default:
@@ -451,10 +423,8 @@ mud_window_prefs_construct_window(MudWindowPrefs *self)
gtk_window_set_transient_for(GTK_WINDOW(self->priv->window),
GTK_WINDOW(main_window));
- self->priv->disp_name = gconf_unescape_key(self->priv->name, -1);
-
gtk_window_set_title(GTK_WINDOW(self->priv->window),
- self->priv->disp_name);
+ self->priv->mud_profile->visible_name);
g_signal_connect(self->priv->window,
"delete-event",
@@ -517,24 +487,25 @@ mud_window_prefs_changed_cb(MudProfile *profile,
static void
mud_window_prefs_set_preferences(MudWindowPrefs *self)
{
+ /* TODO: Just bind via GSettings instead? */
// Terminal
- mud_window_prefs_update_echotext(self, self->priv->profile->preferences);
- mud_window_prefs_update_keeptext(self, self->priv->profile->preferences);
- mud_window_prefs_update_scrolloutput(self, self->priv->profile->preferences);
- mud_window_prefs_update_commdev(self, self->priv->profile->preferences);
- mud_window_prefs_update_scrollback(self, self->priv->profile->preferences);
- mud_window_prefs_update_font(self, self->priv->profile->preferences);
- mud_window_prefs_update_foreground(self, self->priv->profile->preferences);
- mud_window_prefs_update_background(self, self->priv->profile->preferences);
- mud_window_prefs_update_colors(self, self->priv->profile->preferences);
- mud_window_prefs_update_encoding_combo(self, self->priv->profile->preferences);
+ mud_window_prefs_update_echotext(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_keeptext(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_scrolloutput(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_commdev(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_scrollback(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_font(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_foreground(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_background(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_colors(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_encoding_combo(self, self->priv->mud_profile->preferences);
// Network
- mud_window_prefs_update_proxy_check(self, self->priv->profile->preferences);
- mud_window_prefs_update_proxy_combo(self, self->priv->profile->preferences);
- mud_window_prefs_update_proxy_entry(self, self->priv->profile->preferences);
- mud_window_prefs_update_encoding_check(self, self->priv->profile->preferences);
- mud_window_prefs_update_msp_check(self, self->priv->profile->preferences);
+ mud_window_prefs_update_proxy_check(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_proxy_combo(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_proxy_entry(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_encoding_check(self, self->priv->mud_profile->preferences);
+ mud_window_prefs_update_msp_check(self, self->priv->mud_profile->preferences);
}
/************************ Terminal Tab ************************/
@@ -734,7 +705,7 @@ mud_window_prefs_scrolloutput_cb(GtkWidget *widget,
gboolean value = GTK_TOGGLE_BUTTON(widget)->active ? TRUE : FALSE;
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_scrolloutput(self->priv->profile, value);
+ mud_profile_set_scrolloutput(self->priv->mud_profile, value);
}
static void
@@ -744,7 +715,7 @@ mud_window_prefs_keeptext_cb(GtkWidget *widget,
gboolean value = GTK_TOGGLE_BUTTON(widget)->active ? TRUE : FALSE;
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_keeptext(self->priv->profile, value);
+ mud_profile_set_keeptext(self->priv->mud_profile, value);
}
static void
@@ -754,7 +725,7 @@ mud_window_prefs_echo_cb(GtkWidget *widget,
gboolean value = GTK_TOGGLE_BUTTON(widget)->active ? TRUE : FALSE;
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_echotext(self->priv->profile, value);
+ mud_profile_set_echotext(self->priv->mud_profile, value);
}
static void
@@ -765,7 +736,7 @@ mud_window_prefs_commdev_cb(GtkWidget *widget,
const gchar *s = gtk_entry_get_text(GTK_ENTRY(widget));
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_commdev(self->priv->profile, s);
+ mud_profile_set_commdev(self->priv->mud_profile, s);
}
static void
@@ -775,17 +746,18 @@ mud_window_prefs_encoding_combo_cb(GtkWidget *widget,
const gchar *s = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget));
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_encoding_combo(self->priv->profile, s);
+ mud_profile_set_encoding_combo(self->priv->mud_profile, s);
}
static void
mud_window_prefs_scrollback_cb(GtkWidget *widget,
MudWindowPrefs *self)
{
- const gint value = (gint) gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
+ /* TODO: Looks like a rather risky integer cast */
+ const guint value = (guint) gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_scrollback(self->priv->profile, value);
+ mud_profile_set_scrollback(self->priv->mud_profile, value);
}
static void
@@ -795,7 +767,7 @@ mud_window_prefs_font_cb(GtkWidget *widget,
const gchar *fontname = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget));
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_font(self->priv->profile, fontname);
+ mud_profile_set_font(self->priv->mud_profile, fontname);
}
static void
@@ -807,7 +779,7 @@ mud_window_prefs_foreground_cb(GtkWidget *widget,
RETURN_IF_CHANGING_PROFILES(self);
gtk_color_button_get_color(GTK_COLOR_BUTTON(widget), &color);
- mud_profile_set_foreground(self->priv->profile, color.red, color.green, color.blue);
+ mud_profile_set_foreground(self->priv->mud_profile, &color);
}
static void
@@ -819,7 +791,7 @@ mud_window_prefs_background_cb(GtkWidget *widget,
RETURN_IF_CHANGING_PROFILES(self);
gtk_color_button_get_color(GTK_COLOR_BUTTON(widget), &color);
- mud_profile_set_background(self->priv->profile, color.red, color.green, color.blue);
+ mud_profile_set_background(self->priv->mud_profile, &color);
}
static void
@@ -836,11 +808,7 @@ mud_window_prefs_colors_cb(GtkWidget *widget,
if (widget == self->priv->colors[i])
{
gtk_color_button_get_color(GTK_COLOR_BUTTON(widget), &color);
-
- mud_profile_set_colors(self->priv->profile, i,
- color.red,
- color.green,
- color.blue);
+ mud_profile_set_colors(self->priv->mud_profile, i, &color);
}
}
}
@@ -906,24 +874,11 @@ static void
mud_window_prefs_update_proxy_combo(MudWindowPrefs *self,
MudPrefs *preferences)
{
- gchar *profile_name;
- GConfClient *client;
-
- gchar buf[2048];
- gchar extra_path[512] = "";
gchar *version;
gint active;
gint current;
- g_object_get(self->priv->profile, "name", &profile_name, NULL);
-
- if (!g_str_equal(profile_name, "Default"))
- g_snprintf(extra_path, 512, "profiles/%s/", profile_name);
- g_free(profile_name);
-
- g_snprintf(buf, 2048, "/apps/gnome-mud/%s%s", extra_path, "functionality/proxy_version");
- client = gconf_client_get_default();
- version = gconf_client_get_string(client, buf, NULL);
+ version = g_settings_get_string(self->priv->mud_profile->settings, "proxy-socks-version");
if(version)
{
@@ -941,8 +896,6 @@ mud_window_prefs_update_proxy_combo(MudWindowPrefs *self,
}
g_free(version);
-
- g_object_unref(client);
}
static void
@@ -963,7 +916,7 @@ mud_window_prefs_encoding_check_cb(GtkWidget *widget,
gboolean value = GTK_TOGGLE_BUTTON(widget)->active ? TRUE : FALSE;
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_encoding_check(self->priv->profile, value);
+ mud_profile_set_encoding_check(self->priv->mud_profile, value);
}
static void
@@ -977,7 +930,7 @@ mud_window_prefs_proxy_check_cb(GtkWidget *widget,
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_proxy_check(self->priv->profile, value);
+ mud_profile_set_proxy_check(self->priv->mud_profile, value);
}
static void
@@ -987,7 +940,7 @@ mud_window_prefs_msp_check_cb(GtkWidget *widget,
gboolean value = GTK_TOGGLE_BUTTON(widget)->active ? TRUE : FALSE;
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_msp_check(self->priv->profile, value);
+ mud_profile_set_msp_check(self->priv->mud_profile, value);
}
static void
@@ -996,7 +949,7 @@ mud_window_prefs_proxy_combo_cb(GtkWidget *widget,
{
RETURN_IF_CHANGING_PROFILES(self);
- mud_profile_set_proxy_combo(self->priv->profile, GTK_COMBO_BOX(widget));
+ mud_profile_set_proxy_combo(self->priv->mud_profile, GTK_COMBO_BOX(widget));
}
static void
@@ -1007,7 +960,7 @@ mud_window_prefs_proxy_entry_cb(GtkWidget *widget,
RETURN_IF_CHANGING_PROFILES(self);
if(s)
- mud_profile_set_proxy_entry(self->priv->profile, s);
+ mud_profile_set_proxy_entry(self->priv->mud_profile, s);
}
/************************ Triggers Tab ************************/
diff --git a/src/mud-window-profile.c b/src/mud-window-profile.c
index 00bf3e7..c74b09e 100644
--- a/src/mud-window-profile.c
+++ b/src/mud-window-profile.c
@@ -1,6 +1,7 @@
/* GNOME-Mud - A simple Mud Client
* mud-window-profile.c
- * Copyright (C) 2008-2009 Les Harris <lharris gnome org>
+ * Copyright 2008-2009 Les Harris <lharris gnome org>
+ * Copyright 2018 Mart Raudsepp <leio gentoo org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,7 +22,6 @@
# include "config.h"
#endif
-#include <gconf/gconf-client.h>
#include <glib/gi18n.h>
#include <string.h>
#include <glib/gprintf.h>
@@ -37,24 +37,23 @@
struct _MudProfileWindowPrivate
{
GtkWidget *window;
- GtkWidget *treeview;
+ GtkWidget *treeview; /* TODO: Port to GtkListBox or some other redesign with gtk3 */
GtkWidget *btnAdd;
GtkWidget *btnDelete;
GtkWidget *btnEdit;
- gint CurrSelRow;
- gchar *CurrSelRowText;
+ MudProfile *CurrSelRowProfile; /* TODO: We might lose the pointer while having a pointer stored here;
reference it or add other safeguards (e.g. storing uuid instead and handling it appropriately in the face of
uuid removals) */
- GtkTreeStore *treestore;
+ GtkListStore *liststore;
GtkTreeViewColumn *col;
- GtkCellRenderer *renderer;
};
/* Model Columns */
enum
{
NAME_COLUMN,
+ PROFILE_COLUMN,
N_COLUMNS
};
@@ -150,6 +149,7 @@ mud_profile_window_constructor (GType gtype,
GtkBuilder *builder;
GError *error = NULL;
GtkWindow *main_window;
+ GtkCellRenderer *renderer;
/* Chain up to parent constructor */
klass = MUD_PROFILE_WINDOW_CLASS( g_type_class_peek(MUD_TYPE_PROFILE_WINDOW) );
@@ -175,10 +175,10 @@ mud_profile_window_constructor (GType gtype,
profwin->priv->btnEdit = GTK_WIDGET(gtk_builder_get_object(builder, "btnEdit"));
profwin->priv->treeview = GTK_WIDGET(gtk_builder_get_object(builder, "profilesView"));
- profwin->priv->treestore = GTK_TREE_STORE(gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING));
+ profwin->priv->liststore = GTK_LIST_STORE(gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER));
g_object_set(profwin->priv->treeview,
- "model", GTK_TREE_MODEL(profwin->priv->treestore),
+ "model", GTK_TREE_MODEL(profwin->priv->liststore),
"rules-hint", TRUE,
"headers-visible", FALSE,
NULL);
@@ -188,16 +188,15 @@ mud_profile_window_constructor (GType gtype,
gtk_tree_view_append_column(GTK_TREE_VIEW(profwin->priv->treeview),
profwin->priv->col);
- profwin->priv->renderer = gtk_cell_renderer_text_new();
+ renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(profwin->priv->col,
- profwin->priv->renderer,
- TRUE);
+ renderer,
+ TRUE);
gtk_tree_view_column_add_attribute(profwin->priv->col,
- profwin->priv->renderer,
- "text",
- NAME_COLUMN);
+ renderer,
+ "text", NAME_COLUMN);
gtk_tree_selection_set_select_function(
gtk_tree_view_get_selection(GTK_TREE_VIEW(profwin->priv->treeview)),
@@ -294,9 +293,9 @@ mud_profile_window_add_cb(GtkWidget *widget, MudProfileWindow *profwin)
GError *error = NULL;
GtkWidget *window;
GtkWidget *entry_profile;
- gchar *profile;
+ gchar *profile_name;
gint result;
- MudProfile *def, *prof;
+ MudProfile *prof;
builder = gtk_builder_new();
if(gtk_builder_add_from_file(builder, UIDIR "/prefs.ui", &error) == 0)
@@ -304,9 +303,6 @@ mud_profile_window_add_cb(GtkWidget *widget, MudProfileWindow *profwin)
window = GTK_WIDGET(gtk_builder_get_object(builder, "newprofile_dialog"));
- def = mud_profile_manager_get_profile_by_name(profwin->parent_window->profile_manager,
- "Default");
-
gtk_window_set_transient_for(
GTK_WINDOW(window),
GTK_WINDOW(profwin->priv->window));
@@ -316,22 +312,13 @@ mud_profile_window_add_cb(GtkWidget *widget, MudProfileWindow *profwin)
result = gtk_dialog_run(GTK_DIALOG(window));
if (result == GTK_RESPONSE_OK)
{
- gchar *escaped_name;
- profile = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_profile)));
-
- mud_profile_manager_add_profile(profwin->parent_window->profile_manager,
- profile);
-
- escaped_name = gconf_escape_key(profile, -1);
+ profile_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_profile)));
+ prof = mud_profile_manager_add_profile(profwin->parent_window->profile_manager,
+ profile_name);
- prof = mud_profile_manager_get_profile_by_name(profwin->parent_window->profile_manager,
- escaped_name);
-
- mud_profile_copy_preferences(def, prof);
mud_profile_window_populate_treeview(profwin);
- g_free(profile);
- g_free(escaped_name);
+ g_free(profile_name);
}
gtk_widget_destroy(window);
@@ -341,30 +328,20 @@ mud_profile_window_add_cb(GtkWidget *widget, MudProfileWindow *profwin)
static void
mud_profile_window_del_cb(GtkWidget *widget, MudProfileWindow *profwin)
{
- if(!g_str_equal("Default", profwin->priv->CurrSelRowText))
- {
- gchar *escaped_name = gconf_escape_key(profwin->priv->CurrSelRowText, -1);
-
- mud_profile_manager_delete_profile(profwin->parent_window->profile_manager,
- escaped_name);
+#warning Add safeguards against deleting default or last item
+ mud_profile_manager_delete_profile(profwin->parent_window->profile_manager,
+ profwin->priv->CurrSelRowProfile);
- g_free(escaped_name);
-
- mud_profile_window_populate_treeview(profwin);
- }
+ mud_profile_window_populate_treeview(profwin);
}
static void
-mud_profile_window_edit_cb(GtkWidget *widget, MudProfileWindow *profwin)
+mud_profile_window_edit_cb (GtkWidget *widget, MudProfileWindow *profwin)
{
- gchar *escaped_name = gconf_escape_key(profwin->priv->CurrSelRowText, -1);
-
- g_object_new(MUD_TYPE_WINDOW_PREFS,
- "parent-window", profwin->parent_window,
- "name", escaped_name,
- NULL);
-
- g_free(escaped_name);
+ g_object_new(MUD_TYPE_WINDOW_PREFS,
+ "parent-window", profwin->parent_window,
+ "mud-profile", profwin->priv->CurrSelRowProfile,
+ NULL);
}
static gint
@@ -377,66 +354,66 @@ mud_profile_window_close_cb(GtkWidget *widget, MudProfileWindow *profwin)
static gboolean
mud_profile_window_tree_select_cb(GtkTreeSelection *selection,
- GtkTreeModel *model,
- GtkTreePath *path,
- gboolean path_currently_selected,
- gpointer userdata)
+ GtkTreeModel *model,
+ GtkTreePath *path,
+ gboolean path_currently_selected,
+ gpointer userdata)
{
GtkTreeIter iter;
MudProfileWindow *profwin = (MudProfileWindow *)userdata;
if (gtk_tree_model_get_iter(model, &iter, path))
{
- gtk_tree_model_get(model, &iter, 0, &profwin->priv->CurrSelRowText, -1);
-
- profwin->priv->CurrSelRow = (gtk_tree_path_get_indices(path))[0];
+ gtk_tree_model_get(model, &iter, PROFILE_COLUMN, &profwin->priv->CurrSelRowProfile, -1);
gtk_widget_set_sensitive(profwin->priv->btnEdit, TRUE);
- if(g_str_equal(profwin->priv->CurrSelRowText, "Default"))
- gtk_widget_set_sensitive(profwin->priv->btnDelete, FALSE);
- else
- gtk_widget_set_sensitive(profwin->priv->btnDelete, TRUE);
+ /* TODO: Don't allow deleting default profile (in addition to the last one, which should be the
default too */
+ gtk_widget_set_sensitive(profwin->priv->btnDelete,
gtk_tree_model_iter_n_children(GTK_TREE_MODEL(profwin->priv->liststore), NULL) > 1);
}
+ /* TODO: desensitize btnEdit if selection is removed (ctrl+click on selected item with treeview);
alternative just ensure a selection is always kept, perhaps after GtkListBox or redesign */
return TRUE;
}
/* Private Methods */
static void
-mud_profile_window_populate_treeview(MudProfileWindow *profwin)
+mud_profile_window_populate_treeview (MudProfileWindow *profwin)
{
- const GSList *profiles, *entry;
- GtkTreeStore* store;
- GtkTreeIter iter;
+ GSequence *profiles;
+ MudProfile *profile;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GSequenceIter *seqiter;
- g_return_if_fail(MUD_IS_PROFILE_WINDOW(profwin));
+ g_return_if_fail(MUD_IS_PROFILE_WINDOW(profwin));
- store = GTK_TREE_STORE(profwin->priv->treestore);
+ store = profwin->priv->liststore;
- gtk_tree_store_clear(store);
+ gtk_list_store_clear (store);
- gtk_widget_set_sensitive(profwin->priv->btnDelete, FALSE);
- gtk_widget_set_sensitive(profwin->priv->btnEdit, FALSE);
+ gtk_widget_set_sensitive (profwin->priv->btnDelete, FALSE);
+ gtk_widget_set_sensitive (profwin->priv->btnEdit, FALSE);
- profiles = mud_profile_manager_get_profiles(profwin->parent_window->profile_manager);
+ profiles = mud_profile_manager_get_profiles (profwin->parent_window->profile_manager);
- entry = profiles;
- while(entry)
+ for (seqiter = g_sequence_get_begin_iter (profiles);
+ !g_sequence_iter_is_end (seqiter);
+ seqiter = g_sequence_iter_next (seqiter))
{
- MudProfile *profile = MUD_PROFILE(entry->data);
- gchar *escaped_name;
-
- escaped_name = gconf_unescape_key(profile->name, -1);
-
- gtk_tree_store_append(store, &iter, NULL);
- gtk_tree_store_set(store, &iter,
- NAME_COLUMN, escaped_name,
- -1);
-
- g_free(escaped_name);
+ profile = g_sequence_get (seqiter);
+
+ gtk_list_store_append(store, &iter);
+ gchar *name2;
+ g_object_get (profile,
+ "name", &name2,
+ NULL);
+ g_free (name2);
+ gtk_list_store_set (store, &iter,
+ NAME_COLUMN, profile->visible_name, /* TODO: Handle outside visible-name renames */
+ PROFILE_COLUMN, profile,
+ -1);
- entry = g_slist_next(entry);
}
}
diff --git a/src/mud-window-profile.h b/src/mud-window-profile.h
index 6134d0c..7fe0dc2 100644
--- a/src/mud-window-profile.h
+++ b/src/mud-window-profile.h
@@ -22,7 +22,6 @@
G_BEGIN_DECLS
-#include <gconf/gconf-client.h>
#include "mud-window.h"
#define MUD_TYPE_PROFILE_WINDOW (mud_profile_window_get_type ())
diff --git a/src/mud-window.c b/src/mud-window.c
index 1369429..b376203 100644
--- a/src/mud-window.c
+++ b/src/mud-window.c
@@ -2,6 +2,7 @@
* mud-window.c
* Copyright (C) 1998-2005 Robin Ericsson <lobbin localhost nu>
* Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ * Copyright (C) 2018 Mart Raudsepp <leio gentoo org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -149,7 +150,7 @@ static gboolean mud_window_configure_event(GtkWidget *widget,
gpointer user_data);
static void mud_window_buffer_cb(GtkWidget *widget, MudWindow *self);
static void mud_window_select_profile(GtkWidget *widget, MudWindow *self);
-static void mud_window_profile_menu_set_cb(GtkWidget *widget, gpointer data);
+static void mud_window_profile_menu_set_cb(GtkWidget *widget, gpointer user_data);
static void mud_window_startlog_cb(GtkWidget *widget, MudWindow *self);
static void mud_window_stoplog_cb(GtkWidget *widget, MudWindow *self);
static void mud_window_size_allocate_cb(GtkWidget *widget,
@@ -581,7 +582,6 @@ mud_window_textview_keypress(GtkWidget *widget, GdkEventKey *event, MudWindow *s
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(self->priv->textview));
GtkTextIter start, end;
MudParseBase *base;
- GConfClient *client = gconf_client_get_default();
if ((event->keyval == GDK_Return || event->keyval == GDK_KP_Enter) &&
(event->state & gtk_accelerator_get_default_mod_mask()) == 0)
@@ -605,19 +605,14 @@ mud_window_textview_keypress(GtkWidget *widget, GdkEventKey *event, MudWindow *s
g_free(text);
}
- if (gconf_client_get_bool(client,
- "/apps/gnome-mud/functionality/keeptext", NULL) == FALSE)
- gtk_text_buffer_delete(buffer, &start, &end);
- else
+ if (g_settings_get_boolean(self->priv->current_view->profile->settings, "keep-text"))
gtk_text_buffer_select_range(buffer, &start, &end);
-
- g_object_unref(client);
+ else
+ gtk_text_buffer_delete(buffer, &start, &end);
return TRUE;
}
- g_object_unref(client);
-
if(self->priv->current_view)
{
if(event->keyval == GDK_Up)
@@ -705,7 +700,7 @@ mud_window_notebook_page_change(GtkNotebook *notebook, gpointer page, gint arg,
if (self->priv->nr_of_tabs != 0)
{
mud_window_profile_menu_set_active(self,
- self->priv->current_view->profile->name);
+ self->priv->current_view->profile);
g_object_get(self->priv->current_view,
"connected", &connected,
@@ -769,20 +764,14 @@ mud_window_notebook_page_change(GtkNotebook *notebook, gpointer page, gint arg,
static void
mud_window_preferences_cb(GtkWidget *widget, MudWindow *self)
{
- gchar *profile;
-
- if(self->priv->current_view)
- profile = g_strdup(self->priv->current_view->profile->name);
- else
- profile = g_strdup("Default");
-
-
- g_object_new(MUD_TYPE_WINDOW_PREFS,
- "parent-window", self,
- "name", profile,
- NULL);
-
- g_free(profile);
+ /* TODO: Open default profile if no current_view? */
+ if (self->priv->current_view == NULL)
+ return;
+
+ g_object_new(MUD_TYPE_WINDOW_PREFS,
+ "parent-window", self,
+ "mud-profile", self->priv->current_view->profile, /* TODO: Bind instead and handle live
profile changes properly? */
+ NULL);
}
static void
@@ -963,26 +952,24 @@ mud_window_select_profile(GtkWidget *widget, MudWindow *self)
if (self->priv->current_view)
{
- profile = mud_profile_manager_get_profile_by_name
- (self->profile_manager, gtk_label_get_text(GTK_LABEL(profileLabel)));
-
+ profile = g_object_get_data (G_OBJECT (profileLabel), "profile-object");
if (profile)
mud_connection_view_set_profile(MUD_CONNECTION_VIEW(self->priv->current_view), profile);
}
}
static void
-mud_window_profile_menu_set_cb(GtkWidget *widget, gpointer data)
+mud_window_profile_menu_set_cb(GtkWidget *widget,
+ gpointer user_data)
{
- gchar *name = (gchar *)data;
- GtkWidget *label;
-
- label = gtk_bin_get_child(GTK_BIN(widget));
+ GtkWidget *label;
+ MudProfile *profile = MUD_PROFILE (user_data);
+ label = gtk_bin_get_child (GTK_BIN (widget));
- if (GTK_IS_LABEL(label) && !strcmp(name,gtk_label_get_text(GTK_LABEL(label))))
+ if (GTK_IS_LABEL (label) && g_object_get_data (G_OBJECT (label), "profile-object") == profile)
{
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE);
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), TRUE);
}
}
@@ -1181,70 +1168,56 @@ mud_window_close_current_window(MudWindow *self)
}
void
-mud_window_profile_menu_set_active(MudWindow *self, gchar *name)
+mud_window_profile_menu_set_active (MudWindow *self, MudProfile *profile)
{
- gchar *unescaped_name;
-
- g_return_if_fail(IS_MUD_WINDOW(self));
+ g_return_if_fail (IS_MUD_WINDOW(self));
- unescaped_name = gconf_unescape_key(name, -1);
-
- gtk_container_foreach(GTK_CONTAINER(self->priv->mi_profiles),
- mud_window_profile_menu_set_cb,
- unescaped_name);
+ gtk_container_foreach (GTK_CONTAINER (self->priv->mi_profiles),
+ mud_window_profile_menu_set_cb,
+ profile);
+}
- g_free(unescaped_name);
+static void
+add_profile_to_menu (MudProfile *profile,
+ MudWindow *self)
+{
+ const gchar *profile_name;
+ GtkWidget *profile_item;
+
+ profile_name = mud_profile_get_name (profile);
+ profile_item = gtk_radio_menu_item_new_with_label (self->priv->profile_menu_list,
+ profile_name);
+ g_object_set_data (G_OBJECT (profile_item), "profile-object", profile);
+ gtk_widget_show (profile_item);
+ self->priv->profile_menu_list = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (profile_item));
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (self->priv->mi_profiles), profile_item);
+
+ g_signal_connect (profile_item,
+ "activate",
+ G_CALLBACK (mud_window_select_profile),
+ self);
}
void
mud_window_populate_profiles_menu(MudWindow *self)
{
- const GSList *profiles, *entry;
- GtkWidget *profile;
+ GSequence *profiles;
GtkWidget *sep;
GtkWidget *manage;
GtkWidget *icon;
- MudProfile *prof;
g_return_if_fail(IS_MUD_WINDOW(self));
self->priv->profile_menu_list = NULL;
- profiles = mud_profile_manager_get_profiles(self->profile_manager);
+ profiles = mud_profile_manager_get_profiles (self->profile_manager);
gtk_container_foreach(GTK_CONTAINER(self->priv->mi_profiles),
mud_window_clear_profiles_menu,
NULL);
- entry = profiles;
- while(entry)
- {
- gchar *escaped_name;
-
- prof = MUD_PROFILE(entry->data);
-
- escaped_name = gconf_unescape_key(prof->name, -1);
-
- profile = gtk_radio_menu_item_new_with_label(
- self->priv->profile_menu_list,
- escaped_name);
-
- g_free(escaped_name);
-
- gtk_widget_show(profile);
-
- self->priv->profile_menu_list =
- gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(profile));
-
- gtk_menu_shell_append(GTK_MENU_SHELL(self->priv->mi_profiles), profile);
-
- g_signal_connect(profile,
- "activate",
- G_CALLBACK(mud_window_select_profile),
- self);
-
- entry = g_slist_next(entry);
- }
+ g_sequence_foreach (profiles, (GFunc)add_profile_to_menu, self); /* TODO: Move back to iterating here in
a loop? */
sep = gtk_separator_menu_item_new();
gtk_widget_show(sep);
@@ -1264,7 +1237,8 @@ mud_window_populate_profiles_menu(MudWindow *self)
self);
if(self->priv->current_view)
- mud_window_profile_menu_set_active(self, self->priv->current_view->profile->name);
+ mud_window_profile_menu_set_active(self, self->priv->current_view->profile);
+ /* TODO: Show default profile as the active one if no current_view (yet)? Or least make the direct "Edit
profile" not chooseable until there is no associated view */
}
void
diff --git a/src/mud-window.h b/src/mud-window.h
index 8e8d700..bb34d70 100644
--- a/src/mud-window.h
+++ b/src/mud-window.h
@@ -63,7 +63,7 @@ GType mud_window_get_type (void);
void mud_window_add_connection_view(MudWindow *window, GObject *view, gchar *tabLbl);
void mud_window_populate_profiles_menu(MudWindow *window);
-void mud_window_profile_menu_set_active(MudWindow *window, gchar *name);
+void mud_window_profile_menu_set_active(MudWindow *window, MudProfile *profile);
void mud_window_close_current_window(MudWindow *window);
void mud_window_disconnected(MudWindow *window);
void mud_window_toggle_input_mode(MudWindow *window, MudConnectionView *view);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]