Commit 44acd771 authored by Ignacio Casal Quinteiro's avatar Ignacio Casal Quinteiro Committed by Paolo Borelli

Die smclient die

parent ccd79419
......@@ -358,20 +358,6 @@ GEDIT_LIBS="$GEDIT_LIBS $X11_LIBS $UNIX_LIBS"
AC_SUBST(GEDIT_CFLAGS)
AC_SUBST(GEDIT_LIBS)
if test "$os_osx" = "no" &&
test "$os_win32" = "no"; then
PKG_CHECK_MODULES(EGG_SMCLIENT, [
sm >= 1.0.0
ice
])
else
EGG_SMCLIENT_CFLAGS=
EGG_SMCLIENT_LIBS=
fi
AC_SUBST(EGG_SMCLIENT_CFLAGS)
AC_SUBST(EGG_SMCLIENT_LIBS)
dnl ================================================================
dnl GSettings stuff
dnl ================================================================
......@@ -452,7 +438,6 @@ data/org.gnome.gedit.gschema.xml.in
data/Makefile
docs/Makefile
docs/reference/Makefile
gedit/smclient/Makefile
gedit/theatrics/Makefile
gedit/Makefile
help/Makefile
......
## Process this file with automake to produce Makefile.in
SUBDIRS = smclient theatrics
SUBDIRS = theatrics
bin_PROGRAMS = gedit
......@@ -10,7 +10,6 @@ pkglib_LTLIBRARIES = libgedit-private.la
INCLUDES = \
-I$(top_srcdir) \
-I$(srcdir) \
-I$(srcdir)/smclient \
$(GEDIT_CFLAGS) \
$(GTK_MAC_CFLAGS) \
$(WARN_CFLAGS) \
......@@ -27,7 +26,6 @@ gedit_LDADD = \
libgedit-private.la \
$(GEDIT_LIBS) \
$(GTK_MAC_LIBS) \
$(EGG_SMCLIENT_LIBS) \
$(INTROSPECTION_LIBS)
if PLATFORM_WIN32
......@@ -39,7 +37,6 @@ endif
libgedit_la_LDFLAGS = -export-dynamic -no-undefined -export-symbols-regex "^[[^_]].*"
libgedit_la_LIBADD = \
smclient/libeggsmclient.la \
theatrics/libtheatrics.la
# GEDIT_LIBS must be the last to ensure correct order on some platforms
......@@ -126,7 +123,6 @@ NOINST_H_FILES = \
gedit-print-job.h \
gedit-print-preview.h \
gedit-replace-dialog.h \
gedit-session.h \
gedit-settings.h \
gedit-status-combo-box.h \
gedit-tab-label.h \
......@@ -216,7 +212,6 @@ libgedit_c_files = \
gedit-print-preview.c \
gedit-progress-info-bar.c \
gedit-replace-dialog.c \
gedit-session.c \
gedit-settings.c \
gedit-statusbar.c \
gedit-status-combo-box.c \
......
......@@ -21,7 +21,6 @@
*/
#include "gedit-app-x11.h"
#include "eggdesktopfile.h"
#define GEDIT_APP_X11_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_APP_X11, GeditAppX11Private))
......@@ -44,7 +43,6 @@ gedit_app_x11_class_init (GeditAppX11Class *klass)
static void
gedit_app_x11_init (GeditAppX11 *self)
{
egg_set_desktop_file (DATADIR "/applications/gedit.desktop");
}
/* ex:set ts=8 noet: */
......@@ -761,64 +761,6 @@ gen_role (void)
g_get_host_name ());
}
static GeditWindow *
gedit_app_create_window_real (GeditApp *app,
gboolean set_geometry,
const gchar *role)
{
GeditWindow *window;
window = GEDIT_APP_GET_CLASS (app)->create_window (app);
if (role != NULL)
{
gtk_window_set_role (GTK_WINDOW (window), role);
}
else
{
gchar *newrole;
newrole = gen_role ();
gtk_window_set_role (GTK_WINDOW (window), newrole);
g_free (newrole);
}
if (set_geometry)
{
GdkWindowState state;
gint w, h;
state = g_settings_get_int (app->priv->window_settings,
GEDIT_SETTINGS_WINDOW_STATE);
g_settings_get (app->priv->window_settings,
GEDIT_SETTINGS_WINDOW_SIZE,
"(ii)", &w, &h);
gtk_window_set_default_size (GTK_WINDOW (window), w, h);
if ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0)
{
gtk_window_maximize (GTK_WINDOW (window));
}
else
{
gtk_window_unmaximize (GTK_WINDOW (window));
}
if ((state & GDK_WINDOW_STATE_STICKY ) != 0)
{
gtk_window_stick (GTK_WINDOW (window));
}
else
{
gtk_window_unstick (GTK_WINDOW (window));
}
}
return window;
}
/**
* gedit_app_create_window:
* @app: the #GeditApp
......@@ -833,32 +775,49 @@ gedit_app_create_window (GeditApp *app,
GdkScreen *screen)
{
GeditWindow *window;
gchar *role;
GdkWindowState state;
gint w, h;
gedit_debug (DEBUG_APP);
window = gedit_app_create_window_real (app, TRUE, NULL);
window = GEDIT_APP_GET_CLASS (app)->create_window (app);
if (screen != NULL)
{
gtk_window_set_screen (GTK_WINDOW (window), screen);
}
return window;
}
role = gen_role ();
gtk_window_set_role (GTK_WINDOW (window), role);
g_free (role);
/*
* Same as _create_window, but doesn't set the geometry.
* The session manager takes care of it. Used in gnome-session.
*/
GeditWindow *
_gedit_app_restore_window (GeditApp *app,
const gchar *role)
{
GeditWindow *window;
state = g_settings_get_int (app->priv->window_settings,
GEDIT_SETTINGS_WINDOW_STATE);
gedit_debug (DEBUG_APP);
g_settings_get (app->priv->window_settings,
GEDIT_SETTINGS_WINDOW_SIZE,
"(ii)", &w, &h);
gtk_window_set_default_size (GTK_WINDOW (window), w, h);
window = gedit_app_create_window_real (app, FALSE, role);
if ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0)
{
gtk_window_maximize (GTK_WINDOW (window));
}
else
{
gtk_window_unmaximize (GTK_WINDOW (window));
}
if ((state & GDK_WINDOW_STATE_STICKY ) != 0)
{
gtk_window_stick (GTK_WINDOW (window));
}
else
{
gtk_window_unstick (GTK_WINDOW (window));
}
return window;
}
......
......@@ -132,8 +132,6 @@ gboolean gedit_app_process_window_event (GeditApp *app,
GdkEvent *event);
/* Non exported functions */
GeditWindow *_gedit_app_restore_window (GeditApp *app,
const gchar *role);
GeditWindow *_gedit_app_get_window_in_viewport (GeditApp *app,
GdkScreen *screen,
gint workspace,
......
......@@ -37,7 +37,6 @@
#endif
#include "gedit-command-line.h"
#include "eggsmclient.h"
#define GEDIT_COMMAND_LINE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_COMMAND_LINE, GeditCommandLinePrivate))
......@@ -334,7 +333,6 @@ gedit_command_line_parse (GeditCommandLine *command_line,
context = g_option_context_new (_("- Edit text files"));
g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
g_option_context_add_group (context, egg_sm_client_get_option_group ());
#ifdef ENABLE_INTROSPECTION
g_option_context_add_group (context, g_irepository_get_option_group ());
......
/*
* gedit-session.c - Basic session management for gedit
* This file is part of gedit
*
* Copyright (C) 2002 Ximian, Inc.
* Copyright (C) 2005 - Paolo Maggi
*
* Author: Federico Mena-Quintero <federico@ximian.com>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the gedit Team, 2002-2005. See the AUTHORS file for a
* list of people on the gedit Team.
* See the ChangeLog files for a list of changes.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <unistd.h>
#include <string.h>
#include <libxml/tree.h>
#include <libxml/xmlwriter.h>
#include "gedit-session.h"
#include "gedit-debug.h"
#include "gedit-plugins-engine.h"
#include "gedit-metadata-manager.h"
#include "gedit-window.h"
#include "gedit-app.h"
#include "gedit-commands.h"
#include "gedit-close-confirmation-dialog.h"
#include "smclient/eggsmclient.h"
/* The master client we use for SM */
static EggSMClient *master_client = NULL;
/* global var used during quit_requested */
static GSList *window_dirty_list;
static void ask_next_confirmation (void);
#define GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE "gedit-session-list-of-docs-to-save-key"
static void
save_window_session (GKeyFile *state_file,
const gchar *group_name,
GeditWindow *window)
{
const gchar *role;
int width, height;
GeditPanel *panel;
GList *docs, *l;
GPtrArray *doc_array;
GeditDocument *active_document;
gchar *uri = NULL;
gedit_debug (DEBUG_SESSION);
role = gtk_window_get_role (GTK_WINDOW (window));
g_key_file_set_string (state_file, group_name, "role", role);
gtk_window_get_size (GTK_WINDOW (window), &width, &height);
g_key_file_set_integer (state_file, group_name, "width", width);
g_key_file_set_integer (state_file, group_name, "height", height);
panel = gedit_window_get_side_panel (window);
g_key_file_set_boolean (state_file, group_name, "side-panel-visible",
gtk_widget_get_visible (GTK_WIDGET (panel)));
panel = gedit_window_get_bottom_panel (window);
g_key_file_set_boolean (state_file, group_name, "bottom-panel-visible",
gtk_widget_get_visible (GTK_WIDGET (panel)));
active_document = gedit_window_get_active_document (window);
if (active_document)
{
GFile *location;
location = gedit_document_get_location (active_document);
if (location)
{
uri = g_file_get_uri (location);
g_object_unref (location);
}
g_key_file_set_string (state_file, group_name,
"active-document", uri);
g_free (uri);
}
docs = gedit_window_get_documents (window);
doc_array = g_ptr_array_new ();
for (l = docs; l != NULL; l = g_list_next (l))
{
GFile *location;
location = gedit_document_get_location (GEDIT_DOCUMENT (l->data));
if (location)
{
uri = g_file_get_uri (location);
g_object_unref (location);
}
if (uri != NULL)
g_ptr_array_add (doc_array, uri);
}
g_list_free (docs);
if (doc_array->len)
{
g_key_file_set_string_list (state_file, group_name,
"documents",
(const char **)doc_array->pdata,
doc_array->len);
g_ptr_array_foreach (doc_array, (GFunc) g_free, NULL);
}
g_ptr_array_free (doc_array, TRUE);
}
static void
client_save_state_cb (EggSMClient *client,
GKeyFile *state_file,
gpointer user_data)
{
const GList *windows;
gchar *group_name;
int n;
windows = gedit_app_get_windows (gedit_app_get_default ());
n = 1;
while (windows != NULL)
{
group_name = g_strdup_printf ("gedit window %d", n);
save_window_session (state_file,
group_name,
GEDIT_WINDOW (windows->data));
g_free (group_name);
windows = g_list_next (windows);
n++;
}
}
static void
window_handled (GeditWindow *window)
{
window_dirty_list = g_slist_remove (window_dirty_list, window);
/* whee... we made it! */
if (window_dirty_list == NULL)
egg_sm_client_will_quit (master_client, TRUE);
else
ask_next_confirmation ();
}
static void
window_state_change (GeditWindow *window,
GParamSpec *pspec,
gpointer data)
{
GeditWindowState state;
GList *unsaved_docs;
GList *docs_to_save;
GList *l;
gboolean done = TRUE;
state = gedit_window_get_state (window);
/* we are still saving */
if (state & GEDIT_WINDOW_STATE_SAVING)
return;
unsaved_docs = gedit_window_get_unsaved_documents (window);
docs_to_save = g_object_get_data (G_OBJECT (window),
GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE);
for (l = docs_to_save; l != NULL; l = l->next)
{
if (g_list_find (unsaved_docs, l->data))
{
done = FALSE;
break;
}
}
if (done)
{
g_signal_handlers_disconnect_by_func (window, window_state_change, data);
g_list_free (docs_to_save);
g_object_set_data (G_OBJECT (window),
GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE,
NULL);
window_handled (window);
}
g_list_free (unsaved_docs);
}
static void
close_confirmation_dialog_response_handler (GeditCloseConfirmationDialog *dlg,
gint response_id,
GeditWindow *window)
{
GList *selected_documents;
GSList *l;
gedit_debug (DEBUG_COMMANDS);
switch (response_id)
{
case GTK_RESPONSE_YES:
/* save selected docs */
g_signal_connect (window,
"notify::state",
G_CALLBACK (window_state_change),
NULL);
selected_documents = gedit_close_confirmation_dialog_get_selected_documents (dlg);
g_return_if_fail (g_object_get_data (G_OBJECT (window),
GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE) == NULL);
g_object_set_data (G_OBJECT (window),
GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE,
selected_documents);
_gedit_cmd_file_save_documents_list (window, selected_documents);
/* FIXME: also need to lock the window to prevent further changes... */
break;
case GTK_RESPONSE_NO:
/* dont save */
window_handled (window);
break;
default:
/* disconnect window_state_changed where needed */
for (l = window_dirty_list; l != NULL; l = l->next)
{
g_signal_handlers_disconnect_by_func (window,
window_state_change, NULL);
}
g_slist_free (window_dirty_list);
window_dirty_list = NULL;
/* cancel shutdown */
egg_sm_client_will_quit (master_client, FALSE);
break;
}
gtk_widget_destroy (GTK_WIDGET (dlg));
}
static void
show_confirmation_dialog (GeditWindow *window)
{
GList *unsaved_docs;
GtkWidget *dlg;
gedit_debug (DEBUG_SESSION);
unsaved_docs = gedit_window_get_unsaved_documents (window);
g_return_if_fail (unsaved_docs != NULL);
if (unsaved_docs->next == NULL)
{
/* There is only one unsaved document */
GeditTab *tab;
GeditDocument *doc;
doc = GEDIT_DOCUMENT (unsaved_docs->data);
tab = gedit_tab_get_from_document (doc);
g_return_if_fail (tab != NULL);
gedit_window_set_active_tab (window, tab);
dlg = gedit_close_confirmation_dialog_new_single (
GTK_WINDOW (window),
doc,
TRUE);
}
else
{
dlg = gedit_close_confirmation_dialog_new (GTK_WINDOW (window),
unsaved_docs,
TRUE);
}
g_list_free (unsaved_docs);
g_signal_connect (dlg,
"response",
G_CALLBACK (close_confirmation_dialog_response_handler),
window);
gtk_widget_show (dlg);
}
static void
ask_next_confirmation (void)
{
g_return_if_fail (window_dirty_list != NULL);
/* pop up the confirmation dialog for the first window
* in the dirty list. The next confirmation is asked once
* this one has been handled.
*/
show_confirmation_dialog (GEDIT_WINDOW (window_dirty_list->data));
}
/* quit_requested handler for the master client */
static void
client_quit_requested_cb (EggSMClient *client,
gpointer data)
{
GeditApp *app;
const GList *l;
gedit_debug (DEBUG_SESSION);
app = gedit_app_get_default ();
if (window_dirty_list != NULL)
{
g_critical ("global variable window_dirty_list not NULL");
window_dirty_list = NULL;
}
for (l = gedit_app_get_windows (app); l != NULL; l = l->next)
{
if (gedit_window_get_unsaved_documents (GEDIT_WINDOW (l->data)) != NULL)
{
window_dirty_list = g_slist_prepend (window_dirty_list, l->data);
}
}
/* no modified docs */
if (window_dirty_list == NULL)
{
egg_sm_client_will_quit (client, TRUE);
return;
}
ask_next_confirmation ();
gedit_debug_message (DEBUG_SESSION, "END");
}
/* quit handler for the master client */
static void
client_quit_cb (EggSMClient *client,
gpointer data)
{
gtk_main_quit ();
}
/**
* gedit_session_init:
*
* Initializes session management support. This function should be called near
* the beginning of the program.
**/
void
gedit_session_init (void)
{
gedit_debug (DEBUG_SESSION);
if (master_client)
return;
master_client = egg_sm_client_get ();
g_signal_connect (master_client,
"save_state",
G_CALLBACK (client_save_state_cb),
NULL);
g_signal_connect (master_client,
"quit_requested",
G_CALLBACK (client_quit_requested_cb),
NULL);
g_signal_connect (master_client,
"quit",
G_CALLBACK (client_quit_cb),
NULL);
}
/**
* gedit_session_is_restored:
*
* Returns whether this gedit is running from a restarted session.
*
* Return value: TRUE if the session manager restarted us, FALSE otherwise.
* This should be used to determine whether to pay attention to command line
* arguments in case the session was not restored.
**/
gboolean
gedit_session_is_restored (void)
{
gboolean restored;
gedit_debug (DEBUG_SESSION);
if (!master_client)
return FALSE;
restored = egg_sm_client_is_resumed (master_client);
gedit_debug_message (DEBUG_SESSION, restored ? "RESTORED" : "NOT RESTORED");
return restored;
}
static void
parse_window (GKeyFile *state_file,
const gchar *group_name)
{
GeditWindow *window;
gchar *role, *active_document, **documents;
int width, height;
gboolean visible;
GeditPanel *panel;
GError *error = NULL;
role = g_key_file_get_string (state_file, group_name, "role", NULL);
gedit_debug_message (DEBUG_SESSION, "Window role: %s", role);
window = _gedit_app_restore_window (gedit_app_get_default (), (gchar *) role);
g_free (role);
if (window == NULL)
{
g_warning ("Couldn't restore window");
return;
}
width = g_key_file_get_integer (state_file, group_name,
"width", &error);
if (error)
{
g_clear_error (&error);
width = -1;
}
height = g_key_file_get_integer (state_file, group_name,
"height", &error);
if (error)
{
g_clear_error (&error);
height = -1;
}
gtk_window_set_default_size (GTK_WINDOW (window), width, height);
visible = g_key_file_get_boolean (state_file, group_name,
"side-panel-visible", &error);
if (error)
{
g_clear_error (&error);
visible = FALSE;
}
panel = gedit_window_get_side_panel (window);
gtk_widget_set_visible (GTK_WIDGET (panel), visible);
if (visible)
{
gedit_debug_message (DEBUG_SESSION, "Side panel visible");
}
else
{
gedit_debug_message (DEBUG_SESSION, "Side panel _NOT_ visible");
}
visible = g_key_file_get_boolean (state_file, group_name,
"bottom-panel-visible", &error);
if (error)
{
g_clear_error (&error);
visible = FALSE;
}
panel = gedit_window_get_bottom_panel (window);
gtk_widget_set_visible (GTK_WIDGET (panel), visible);
gedit_debug_message (DEBUG_SESSION, "Bottom panel %svisible",