Example #1
0
static void
handle_quit (SimuQuit reason, GError *err, gpointer data)
{
        gdk_threads_enter ();

        debug ("handle quit was called\n");
        switch (reason) {
                case SIMU_EOF:
                        echo ("*** Connection closed by server ***\n");
                        break;

                case SIMU_ERROR:
                        if (err != NULL) {
                                echo_f ("*** Disconnected from server"
						" due to an error %d: %s ***\n",
						err->code, err->message);
                        } else {
                                echo ("*** Disconnected from server due to an "
                                                "unknown error ***\n");
                        }
                        break;

                case SIMU_QUIT:
                        echo ("*** Conection closed ***\n");
                        break;

                default:
                        g_assert_not_reached ();
        }

	g_free (connection);
        connection = NULL;

        if (warlock_quit) {
		warlock_exit ();
        }

        gdk_threads_leave ();
}
Example #2
0
// to be called at program start and anytime the value of auto-log changes
static void
log_toggle (void)
{
	char *key;
	gboolean autolog;

	key = preferences_get_key (PREF_AUTO_LOG);
	autolog = preferences_get_bool (key);
	g_free (key);

	if (autolog && log_file == NULL) {
		GError *err;
		char *filename, *name, *path, *path_key;

		path_key = preferences_get_key (PREF_LOG_PATH);
		path = preferences_get_string (path_key);
		g_free (path_key);

		name = warlock_log_get_name ();

		filename = g_build_filename (path, name, NULL);

		g_free (name);
		g_free (path);

		err = NULL;
		log_file = g_io_channel_new_file (filename, "a", &err);
		if (log_file == NULL) {
			echo_f ("Error: \"%s\" for file \"%s\".\n",
					err->message, filename);
		}
	} else if (!autolog && log_file != NULL) {
		g_io_channel_close (log_file);
		g_io_channel_unref (log_file);
		log_file = NULL;
	}
}