Skip to content

Instantly share code, notes, and snippets.

@soimort
Created December 8, 2016 02:02
Show Gist options
  • Save soimort/73c75266d1610ff0af68b40e7b07d939 to your computer and use it in GitHub Desktop.
Save soimort/73c75266d1610ff0af68b40e7b07d939 to your computer and use it in GitHub Desktop.
diff -Naur /home/soimort/abs/caja/src/caja-1.16.1-orig/src/caja-application.c /home/soimort/abs/caja/src/caja-1.16.1/src/caja-application.c
--- /home/soimort/abs/caja/src/caja-1.16.1-orig/src/caja-application.c 2016-10-18 15:36:20.000000000 +0200
+++ /home/soimort/abs/caja/src/caja-1.16.1/src/caja-application.c 2016-12-08 02:47:25.608674396 +0100
@@ -125,7 +125,7 @@
CajaApplication *application);
static void drive_listen_for_eject_button (GDrive *drive,
CajaApplication *application);
-static void caja_application_load_session (CajaApplication *application);
+static gboolean caja_application_load_session (CajaApplication *application);
static char * caja_application_get_session_data (void);
G_DEFINE_TYPE (CajaApplication, caja_application, G_TYPE_OBJECT);
@@ -268,6 +268,24 @@
}
+void
+caja_application_save_session (void)
+{
+ gchar *filename = g_build_filename (caja_get_user_directory (), "last-session", NULL);
+ GFile *file = g_file_new_for_path (filename);
+ GFileOutputStream *output = g_file_replace (file, NULL, FALSE,
+ G_FILE_CREATE_NONE,
+ NULL, NULL);
+ gchar *data = caja_application_get_session_data ();
+ g_output_stream_write (G_OUTPUT_STREAM(output), data, strlen(data), NULL, NULL);
+ g_output_stream_close (G_OUTPUT_STREAM(output), NULL, NULL);
+ g_message ("Current session saved in %s", filename);
+ g_free (data);
+ g_free (filename);
+ g_object_unref (output);
+ g_object_unref (file);
+}
+
static void
smclient_save_state_cb (EggSMClient *client,
GKeyFile *state_file,
@@ -1114,39 +1132,40 @@
/* point to the Unix home folder */
g_timeout_add_seconds (30, (GSourceFunc) desktop_changed_callback_connect, application);
- /* Create the other windows. */
- if (urls != NULL || !no_default_window)
+ /* Load session if available */
+ if (!caja_application_load_session (application))
{
- if (unique_app_is_running (application->unique_app))
+ /* Create the other windows. */
+ if (urls != NULL || !no_default_window)
{
- message = unique_message_data_new ();
- _unique_message_data_set_geometry_and_uris (message, geometry, urls);
- if (browser_window)
+ if (unique_app_is_running (application->unique_app))
{
- unique_app_send_message (application->unique_app,
- COMMAND_OPEN_BROWSER, message);
+ message = unique_message_data_new ();
+ _unique_message_data_set_geometry_and_uris (message, geometry, urls);
+ if (browser_window)
+ {
+ unique_app_send_message (application->unique_app,
+ COMMAND_OPEN_BROWSER, message);
+ }
+ else
+ {
+ unique_app_send_message (application->unique_app,
+ UNIQUE_OPEN, message);
+ }
+ unique_message_data_free (message);
}
else
{
- unique_app_send_message (application->unique_app,
- UNIQUE_OPEN, message);
+ open_windows (application, NULL,
+ urls,
+ gdk_display_get_default_screen (gdk_display_get_default()),
+ // gdk_screen_get_default (),
+ geometry,
+ browser_window);
}
- unique_message_data_free (message);
- }
- else
- {
- open_windows (application, NULL,
- urls,
- gdk_display_get_default_screen (gdk_display_get_default()),
- // gdk_screen_get_default (),
- geometry,
- browser_window);
}
}
- /* Load session info if availible */
- caja_application_load_session (application);
-
/* load accelerator map, and register save callback */
accel_map_filename = caja_get_accel_map_file ();
if (accel_map_filename)
@@ -2149,7 +2168,7 @@
return data;
}
-void
+static gboolean
caja_application_load_session (CajaApplication *application)
{
xmlDocPtr doc;
@@ -2158,24 +2177,41 @@
GKeyFile *state_file;
char *data;
- if (!egg_sm_client_is_resumed (application->smclient))
+ data = malloc (32768); // FIXME: file length >= 32768
+ gchar *filename = g_build_filename (caja_get_user_directory (), "last-session", NULL);
+ GFile *file = g_file_new_for_path (filename);
+ GFileInputStream *input = g_file_read (file, NULL, NULL);
+ gssize bufsize = 0;
+ if (input)
{
- return;
+ bufsize = g_input_stream_read (G_INPUT_STREAM (input), data, 32767, NULL, NULL);
+ g_input_stream_close (G_INPUT_STREAM (input), NULL, NULL);
+ g_object_unref (input);
}
+ g_free (filename);
+ g_object_unref (file);
- state_file = egg_sm_client_get_state_file (application->smclient);
- if (!state_file)
+ if (!bufsize)
{
- return;
- }
+ if (!egg_sm_client_is_resumed (application->smclient))
+ {
+ return FALSE;
+ }
- data = g_key_file_get_string (state_file,
- "Caja",
- "documents",
- NULL);
- if (data == NULL)
- {
- return;
+ state_file = egg_sm_client_get_state_file (application->smclient);
+ if (!state_file)
+ {
+ return FALSE;
+ }
+
+ data = g_key_file_get_string (state_file,
+ "Caja",
+ "documents",
+ NULL);
+ if (data == NULL)
+ {
+ return FALSE;
+ }
}
bail = TRUE;
@@ -2399,7 +2435,10 @@
if (bail)
{
g_message ("failed to load session");
+ return FALSE;
}
+
+ return TRUE;
}
static void
diff -Naur /home/soimort/abs/caja/src/caja-1.16.1-orig/src/caja-application.h /home/soimort/abs/caja/src/caja-1.16.1/src/caja-application.h
--- /home/soimort/abs/caja/src/caja-1.16.1-orig/src/caja-application.h 2016-10-18 15:36:20.000000000 +0200
+++ /home/soimort/abs/caja/src/caja-1.16.1/src/caja-application.h 2016-12-08 02:36:04.792037139 +0100
@@ -107,6 +107,7 @@
void caja_application_open_desktop (CajaApplication *application);
void caja_application_close_desktop (void);
gboolean caja_application_save_accel_map (gpointer data);
+void caja_application_save_session (void);
void caja_application_open_location (CajaApplication *application,
GFile *location,
GFile *selection,
diff -Naur /home/soimort/abs/caja/src/caja-1.16.1-orig/src/caja-main.c /home/soimort/abs/caja/src/caja-1.16.1/src/caja-main.c
--- /home/soimort/abs/caja/src/caja-1.16.1-orig/src/caja-main.c 2016-10-18 15:36:20.000000000 +0200
+++ /home/soimort/abs/caja/src/caja-1.16.1/src/caja-main.c 2016-12-08 02:36:33.738702556 +0100
@@ -117,6 +117,7 @@
void caja_main_event_loop_register (GtkObject *object)
#endif
{
+ g_signal_connect (object, "destroy", G_CALLBACK (caja_application_save_session), NULL);
g_signal_connect (object, "destroy", G_CALLBACK (event_loop_unregister), NULL);
event_loop_registrants = g_slist_prepend (event_loop_registrants, GTK_WIDGET (object));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment